package research_variety_tag_relation

import "hongze/hongze_yb/global"

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

// ResearchVarietyTagRelationItem 研究员标签关系
type ResearchVarietyTagRelationItem struct {
	VarietyTagId int    `json:"variety_tag_id" description:"标签ID"`
	AdminId      int    `json:"admin_id" description:"研究员ID"`
	AdminName    string `json:"admin_name" description:"研究员姓名"`
}

// GetResearchVarietyTagRelationList 获取研究方向分组关系列表
func GetResearchVarietyTagRelationList() (list []*ResearchVarietyTagRelationItem, err error) {
	err = global.DEFAULT_MYSQL.
		Table("research_variety_tag_relation AS a ").
		Select("a.variety_tag_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.variety_tag_id ASC, a.admin_id ASC").
		Find(&list).Error
	return
}
