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
}

type ResearchUserVarietyTagRelationItem struct {
	VarietyTagId int    `json:"variety_tag_id" description:"标签ID"`
	UserId       int    `description:"用户ID"`
	UserName     string `description:"用户名称"`
	AdminId      int    `description:"管理员ID"`
	AdminName    string `description:"管理员姓名"`
	OpenId       string `description:"openid"`
}

// GetResearchUserVarietyTagRelationList 获取研究方向分组关系列表(JOIN wx_user)
func GetResearchUserVarietyTagRelationList() (list []*ResearchUserVarietyTagRelationItem, 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, b.open_id, c.user_id, c.real_name AS user_name").
		Joins("INNER JOIN admin AS b ON a.admin_id = b.admin_id").
		Joins("INNER JOIN wx_user AS c ON b.mobile = c.mobile").
		Where("b.enabled = 1").
		Order("a.variety_tag_id ASC, a.admin_id ASC").
		Find(&list).Error
	return
}
