Переглянути джерело

fix: 自动分配首个人

hsun 2 роки тому
батько
коміт
d27ab2e776

+ 22 - 0
models/tables/research_variety_tag_relation/model.go

@@ -26,3 +26,25 @@ func GetResearchVarietyTagRelationList() (list []*ResearchVarietyTagRelationItem
 		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
+}

+ 17 - 23
services/community/question.go

@@ -681,7 +681,7 @@ func GetFirstResearcherByVarietyTagId(tagId int) (researcher *admin.ResearcherAd
 	researcher = new(admin.ResearcherAdminAndUser)
 
 	// 获取标签研究员关系组
-	relationList, e := research_variety_tag_relation.GetResearchVarietyTagRelationList()
+	relationList, e := research_variety_tag_relation.GetResearchUserVarietyTagRelationList()
 	if e != nil {
 		err = errors.New("获取研究员分组失败, Err: " + e.Error())
 		return
@@ -692,32 +692,26 @@ func GetFirstResearcherByVarietyTagId(tagId int) (researcher *admin.ResearcherAd
 	}
 
 	// 从当前组取出有效的研究员信息
-	for i := range relationList {
-		if relationList[i].VarietyTagId == tagId {
-			item, e := admin.GetResearcherAdminAndWxUserByAdminId(relationList[i].AdminId)
-			if e != nil && e != utils.ErrNoRow {
-				err = errors.New("获取研究员成员信息失败, Err: " + e.Error())
-				return
-			}
-			if item != nil && item.UserId > 0 && item.AdminId > 0 && item.OpenId != "" {
-				researcher = item
-				break
-			}
+	for _, v := range relationList {
+		if v.VarietyTagId == tagId && v.AdminId > 0 && v.UserId > 0 && v.OpenId != "" {
+			researcher.UserId = v.UserId
+			researcher.UserName = v.UserName
+			researcher.AdminId = v.AdminId
+			researcher.AdminName = v.AdminName
+			researcher.OpenId = v.OpenId
+			return
 		}
 	}
 	// 未在当前组找到有效的研究员信息, 去其他组找
 	if researcher.UserId == 0 || researcher.AdminId == 0 || researcher.OpenId == "" {
-		for i := range relationList {
-			if relationList[i].VarietyTagId != tagId {
-				item, e := admin.GetResearcherAdminAndWxUserByAdminId(relationList[i].AdminId)
-				if e != nil && e != utils.ErrNoRow {
-					err = errors.New("获取其他组研究员成员信息失败, Err: " + e.Error())
-					return
-				}
-				if item != nil && item.UserId > 0 && item.AdminId > 0 && item.OpenId != "" {
-					researcher = item
-					break
-				}
+		for _, v := range relationList {
+			if v.VarietyTagId != tagId && v.AdminId > 0 && v.UserId > 0 && v.OpenId != "" {
+				researcher.UserId = v.UserId
+				researcher.UserName = v.UserName
+				researcher.AdminId = v.AdminId
+				researcher.AdminName = v.AdminName
+				researcher.OpenId = v.OpenId
+				return
 			}
 		}
 	}

+ 5 - 3
services/wechat/template_msg.go

@@ -558,9 +558,6 @@ func SendQuestionCommentToAdmin(commentId, adminId int, adminOpenId string, comm
 
 // SendQuestionToResearcher 推送研报小程序模板消息-用户提问时,通知到研究员
 func SendQuestionToResearcher(questionId int, adminOpenId, questionTitle, remark string) (err error) {
-	if adminOpenId == "" {
-		return
-	}
 	var errMsg string
 	defer func() {
 		if err != nil {
@@ -568,6 +565,11 @@ func SendQuestionToResearcher(questionId int, adminOpenId, questionTitle, remark
 			go alarm_msg.SendAlarmMsg(alarmMsg, 3)
 		}
 	}()
+	if adminOpenId == "" {
+		err = errors.New("研究员openid为空")
+		errMsg = "研究员openid为空"
+		return
+	}
 
 	openIdList := make([]*OpenIdList, 0)
 	openIdList = append(openIdList, &OpenIdList{