package research_group_relation

import "hongze/hongze_yb/global"

// GetResearchGroupRelationByAdminId 获取研究员研究方向分组
func GetResearchGroupRelationByAdminId(adminId int) (items []*ResearchGroupRelation, err error) {
	err = global.DEFAULT_MYSQL.Model(ResearchGroupRelation{}).Where("admin_id = ?", adminId).Scan(&items).Error
	return
}

// ResearchGroupRelation 研究方向分组关系表
type ResearchGroupRelationItem struct {
	ResearchGroupId int    `json:"research_group_id" description:"研究方向分组ID"`
	AdminId         int    `json:"admin_id" description:"研究员ID"`
	AdminName       string `json:"admin_name" description:"研究员姓名"`
}

// GetResearchGroupRelationList 获取研究方向分组关系列表
func GetResearchGroupRelationList() (list []*ResearchGroupRelationItem, err error) {
	err = global.DEFAULT_MYSQL.
		Table("research_group_relation AS a ").
		Select("a.research_group_id, a.admin_id, b.real_name AS admin_name").
		Joins("INNER JOIN admin AS b ON a.admin_id = b.admin_id").
		Where("b.enabled = 1").
		Order("a.research_group_id ASC, a.admin_id ASC").
		Find(&list).Error
	return
}
