Forráskód Böngészése

fix:分组管理提交

duxin 6 hónapja
szülő
commit
2776ee68e7

+ 53 - 16
src/jfw/modules/bigmember/src/entity/followEnterprise.go

@@ -127,13 +127,19 @@ WHERE a.s_entId = '%s' and a.s_userid = '%s'`, this.SaveTable, entId, this.UserI
 	return
 }
 
+type EntFollowGroup struct {
+	Id    string `json:"id"`
+	Name  string `json:"name"`
+	Count int    `json:"count"`
+}
+
 // GetEntFollowList 我关注的企业列表
 // param A默认分组 B竞争对手 C合作伙伴 逗号分隔
 // db  0||nil 默认分组、1 竞争对手、2 合作伙伴、3 竞争对手和合作伙伴
-func (this *EntFollow) GetEntFollowList(pNum, pSize int, match, groups string) (followData []map[string]interface{}, hasNext bool, count, total int, err error) {
+func (this *EntFollow) GetEntFollowList(pNum, pSize int, match, groups string) (followData []map[string]interface{}, hasNext bool, count, total int, groupUserArr []EntFollowGroup, err error) {
 	groupIds, groupErr := checkGroup(this.UserId, groups, true)
 	if groupErr != nil {
-		return nil, false, -1, -1, fmt.Errorf("分组不存在")
+		return nil, false, -1, -1, nil, fmt.Errorf("分组不存在")
 	}
 	flistSql := fmt.Sprintf(`SELECT  m.*,GROUP_CONCAT(g.id SEPARATOR ',') as gs  from follow_ent_monitor m inner join follow_ent_monitor_group g on(m.s_userid =g.s_userid and g.s_userid ='%s') INNER JOIN follow_ent_monitor_relationship r  on ( g.id=r.s_groupId and m.s_entId=r.s_entId ) GROUP BY s_entId  ORDER BY m.l_lastpushtime DESC,m.l_createtime DESC LIMIT %d,%d`, this.UserId, 0, this.MaxNum)
 	log.Print("我关注的企业列表开始查询:", flistSql)
@@ -144,8 +150,18 @@ func (this *EntFollow) GetEntFollowList(pNum, pSize int, match, groups string) (
 	}
 	log.Print("我关注的企业列表查询结束")
 	count = len(*res)
+	//获取用户分组列表
+	var (
+		followDataAll []map[string]interface{}
+	)
+	groupMap := make(map[string]int)
+	data := db.Base.SelectBySql(fmt.Sprintf(`SELECT id,s_name FROM follow_ent_monitor_group WHERE s_userid = '%s' ORDER BY isdefGoup desc, create_time desc`, this.UserId))
+	if data != nil && len(*data) > 0 {
+		for _, m := range *data {
+			groupMap[qutil.InterfaceToStr(m["id"])] = 0
+		}
+	}
 
-	var followDataAll []map[string]interface{}
 	for _, item := range *res {
 		//兼容从大会员变成免费用户时筛选条件数据错乱问题 取数据全部取出后在进行筛选过滤
 		if match != "" {
@@ -153,12 +169,20 @@ func (this *EntFollow) GetEntFollowList(pNum, pSize int, match, groups string) (
 				continue
 			}
 		}
-		var enCodeGroups []string
 
+		var (
+			enCodeGroups []string
+			groups       = strings.Split(gconv.String(item["gs"]), ",")
+		)
+		//数据存在于哪个分组中 计数
+		for _, group := range groups {
+			if _, ok := groupMap[group]; ok {
+				groupMap[qutil.InterfaceToStr(group)]++
+			}
+		}
 		if len(groupIds) > 0 {
 			var (
-				groups = strings.Split(gconv.String(item["gs"]), ",")
-				has    = false
+				has = false
 			)
 			for _, group := range groups {
 				if group != "" {
@@ -194,6 +218,17 @@ func (this *EntFollow) GetEntFollowList(pNum, pSize int, match, groups string) (
 		}
 		followDataAll = append(followDataAll, rowMap)
 	}
+
+	if data != nil && len(*data) > 0 {
+		for _, m := range *data {
+			groupUserArr = append(groupUserArr, EntFollowGroup{
+				util.EncodeId(qutil.InterfaceToStr(m["id"])),
+				qutil.InterfaceToStr(m["s_name"]),
+				groupMap[qutil.InterfaceToStr(m["id"])],
+			})
+		}
+	}
+
 	total = len(followDataAll)
 	//分页
 	if total > 0 {
@@ -697,12 +732,14 @@ func (this *EntFollow) GetLabelGroup() *[]map[string]interface{} {
 ('竞争对手', '%s',  '2024-01-02 12:00:00', '2025-01-13 12:00:00', 1, 0),
 ('合作伙伴', '%s',  '2024-01-01 12:00:00', '2025-01-13 12:00:00', 1, 0);`, this.UserId, this.UserId, this.UserId))
 	} else {
-		data := db.Base.SelectBySql(fmt.Sprintf(`SELECT b.s_groupId FROM follow_ent_monitor a
-INNER  JOIN  follow_ent_monitor_relationship b on (a.s_entId = b.s_entId)
-WHERE a.s_userid = '%s'
-ORDER BY a.l_createtime desc`, this.UserId))
-		if data != nil && len(*data) > 0 {
-			for _, m := range *data {
+		//获取最近一次关注的分组
+		groupIdData := db.Base.SelectBySql(fmt.Sprintf(fmt.Sprintf(`SELECT b.s_groupId FROM follow_ent_monitor_relationship b
+INNER JOIN (
+SELECT s_entId FROM follow_ent_monitor  WHERE s_userid = '%s' ORDER BY l_createtime desc limit 1
+) a on a.s_entId = b.s_entId
+INNER  JOIN  follow_ent_monitor_group c on c.s_userid = '%s' and c.id = b.s_groupId`, this.UserId, this.UserId)))
+		if groupIdData != nil && len(*groupIdData) > 0 {
+			for _, m := range *groupIdData {
 				defIdMap[qutil.IntAll(m["s_groupId"])] = true
 			}
 		}
@@ -711,12 +748,12 @@ ORDER BY a.l_createtime desc`, this.UserId))
 	data := db.Base.SelectBySql(fmt.Sprintf(`SELECT id,s_name,isPut from follow_ent_monitor_group  WHERE s_userid = '%s'  ORDER BY isdefGoup desc , create_time desc`, this.UserId))
 	if data != nil && len(*data) > 0 {
 		for _, m := range *data {
-			//最近一次分组
-			if len(defIdMap) == 0 && m["s_name"] == "默认分组" {
+			switch { //最近一次分组
+			case len(defIdMap) == 0 && m["s_name"] == "默认分组": //最近没有关注 分配到默认分组
 				m["isSelect"] = true
-			} else if defIdMap[qutil.IntAll(m["id"])] {
+			case defIdMap[qutil.IntAll(m["id"])]:
 				m["isSelect"] = true
-			} else {
+			default:
 				m["isSelect"] = false
 			}
 			m["id"] = util.EncodeId(qutil.InterfaceToStr(m["id"]))

+ 9 - 7
src/jfw/modules/bigmember/src/service/follow/enterprise.go

@@ -96,7 +96,7 @@ func (this *FollowEnt) List() {
 		if pSize == 0 || pSize > 100 {          //默认一页50条数据
 			pSize = 50
 		}
-		entList, hasNext, count, total, err := followEntManager.GetEntFollowList(pNum, pSize, this.GetString("match"), this.GetString("group"))
+		entList, hasNext, count, total, groupUserArr, err := followEntManager.GetEntFollowList(pNum, pSize, this.GetString("match"), this.GetString("group"))
 		if err != nil {
 			return nil, err
 		}
@@ -104,11 +104,12 @@ func (this *FollowEnt) List() {
 			entList = []map[string]interface{}{}
 		}
 		return map[string]interface{}{
-			"count":     count,                   //已关注数量
-			"total":     total,                   //筛选总数
-			"hasNext":   hasNext,                 //是否有下一页
-			"list":      entList,                 //我关注的企业信息
-			"followMax": followEntManager.MaxNum, //最多关注企业数量
+			"count":        count,                   //已关注数量
+			"total":        total,                   //筛选总数
+			"hasNext":      hasNext,                 //是否有下一页
+			"list":         entList,                 //我关注的企业信息
+			"followMax":    followEntManager.MaxNum, //最多关注企业数量
+			"groupUserArr": groupUserArr,            //关注分组列表
 		}, nil
 	}()
 	if errMsg != nil {
@@ -272,7 +273,8 @@ func (this *FollowEnt) LabelGroup() {
 			return nil, err
 		}
 		switch request {
-		case "get": //获取列表
+		case "get":
+			//获取列表
 			// 获取剩余数量信息
 			_, surplus := followEntManager.GetFollowEntInfo()
 			if surplus == 0 {