Эх сурвалжийг харах

wip:企业关注分组自测提交

wkyuer 6 сар өмнө
parent
commit
996a5a2ce2

+ 32 - 11
src/jfw/modules/bigmember/src/entity/followEnterprise.go

@@ -122,11 +122,11 @@ func (this *EntFollow) EntFollowedShow(entId string) (followed, showFollow bool,
 // 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) {
-	groupIds, groupErr := checkGroup(this.UserId, groups)
+	groupIds, groupErr := checkGroup(this.UserId, groups, true)
 	if groupErr != nil {
 		return nil, false, -1, -1, fmt.Errorf("分组不存在")
 	}
-	flistSql := fmt.Sprintf(`SELECT  m.*,GROUP_CONCAT(g.id SEPARATOR ',') as groups  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)
+	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)
 	res := db.Base.SelectBySql(flistSql)
 	if res == nil || len(*res) == 0 {
@@ -148,7 +148,7 @@ func (this *EntFollow) GetEntFollowList(pNum, pSize int, match, groups string) (
 
 		if len(groupIds) > 0 {
 			var (
-				groups = strings.Split(gconv.String(item["i_group"]), ",")
+				groups = strings.Split(gconv.String(item["gs"]), ",")
 				has    = false
 			)
 			for _, group := range groups {
@@ -326,6 +326,9 @@ func (this *EntFollow) AddFollowEnt(entId, groups string, getOldData ...bool) er
 		}
 	}
 	if !db.Base.ExecTx("企业关注", func(tx *sql.Tx) bool {
+		if len(groupIds) == 0 {
+			return false
+		}
 		followId := db.Base.InsertByTx(tx, this.SaveTable, followData)
 		if followId == -1 {
 			return false
@@ -378,17 +381,35 @@ func getGroup(groupStr string) (s int) {
 }
 
 // checkGroup 校验分组是否存在
-func checkGroup(userId, groupStr string) (map[int]bool, error) {
-	rData := db.Base.Query("SELECT id FROM follow_ent_monitor_group WHERE s_userid=?", userId)
+func checkGroup(userId, groupStr string, defaultGetAll ...bool) (map[int]bool, error) {
+	rData := db.Base.Query("SELECT id,s_name FROM follow_ent_monitor_group WHERE s_userid=?", userId)
 	if rData == nil || len(*rData) == 0 {
 		return nil, fmt.Errorf("未查询到标签")
 	}
 	var (
-		hasGroupId map[int]bool
-		rMap       map[int]bool
+		hasGroupId = map[int]bool{}
+		rMap       = map[int]bool{}
+		deafultMap = map[int]bool{}
 	)
 	for _, m := range *rData {
-		hasGroupId[gconv.Int(m["id"])] = true
+		var (
+			name = gconv.String(m["s_name"])
+			gId  = gconv.Int(m["id"])
+		)
+		hasGroupId[gId] = true
+		if name == "默认分组" {
+			deafultMap[gId] = true
+		}
+	}
+
+	if strings.TrimSpace(groupStr) == "" {
+		if len(defaultGetAll) > 0 && defaultGetAll[0] {
+			//仅仅返回全部分组
+			return hasGroupId, nil
+		} else {
+			//仅仅返回默认分组
+			return deafultMap, nil
+		}
 	}
 	for _, gId := range strings.Split(groupStr, ",") {
 		tId := gconv.Int(util.DecodeId(gId))
@@ -424,7 +445,7 @@ func (this *EntFollow) ChangeFollowGroup(entId, groupStr string) error {
 	if groupErr != nil {
 		return fmt.Errorf("分组不存在")
 	}
-	if db.Base.ExecTx("更换关注分组", func(tx *sql.Tx) bool {
+	if !db.Base.ExecTx("更换关注分组", func(tx *sql.Tx) bool {
 		//查询关联的标签
 		rData := db.Base.Query("SELECT r.id,r.s_groupId FROM follow_ent_monitor_group g inner join follow_ent_monitor_relationship r on (g.id = r.s_groupId ) WHERE g.s_userid=? AND r.s_entId=?", this.UserId, entId)
 		if rData == nil || len(*rData) == 0 {
@@ -665,7 +686,7 @@ 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))
 	}
-	data := db.Base.SelectBySql(fmt.Sprintf(`SELECT id,s_name,isPut from follow_ent_monitor_group  WHERE s_userid = '%s'  ORDER BY isDefGroup desc , create_time 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 {
 			m["id"] = util.EncodeId(qutil.InterfaceToStr(m["id"]))
@@ -767,7 +788,7 @@ func (this *EntFollow) DelLabelGroup(groupId string) error {
 			}
 		}
 		//删除当前标签
-		if db.Base.DeleteByTx(tx, "follow_ent_monitor_group", map[string]interface{}{
+		if !db.Base.DeleteByTx(tx, "follow_ent_monitor_group", map[string]interface{}{
 			"s_userid": this.UserId,
 			"id":       groupId,
 		}) {

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

@@ -249,8 +249,7 @@ func (this *FollowEnt) ChangeGroup() {
 			return nil, err
 		}
 		groups := this.GetString("groups")
-		followId := util.DecodeId(this.GetString("fid"))
-		err = cepm.ChangeFollowGroup(followId, groups)
+		err = cepm.ChangeFollowGroup(util.DecodeId(this.GetString("entId")), groups)
 		if err != nil {
 			return nil, err
 		}
@@ -265,7 +264,7 @@ func (this *FollowEnt) ChangeGroup() {
 // LabelGroup 关注企业标签分组
 func (this *FollowEnt) LabelGroup() {
 	userId := qutil.ObjToString(this.GetSession("userId"))
-	request := this.GetString("request")
+	request := this.GetString("type")
 	rData, errMsg := func() (interface{}, error) {
 		followEntManager, err := entity.CreateEntFollowManager(this.Session())
 		if err != nil {
@@ -279,17 +278,18 @@ func (this *FollowEnt) LabelGroup() {
 			err = followEntManager.AddLabelGroup(this.GetString("name"))
 			return nil, err
 		case "put": //
-			err = followEntManager.PutLabelGroup(this.GetString("name"), util.DecodeId(this.GetString("id")))
+			err = followEntManager.PutLabelGroup(this.GetString("name"), util.DecodeId(this.GetString("groupId")))
 			return nil, err
 		case "del":
 			err = followEntManager.DelLabelGroup(util.DecodeId(this.GetString("groupId")))
+			return nil, err
 		default:
 			return nil, errors.New("错误参数")
 		}
 		return nil, errors.New("错误参数")
 	}()
 	if errMsg != nil {
-		log.Printf("%s 关注企业-更换分组出错:%s\n", userId, errMsg.Error())
+		log.Printf("%s 关注企业-关注企业标签分组:%s\n", userId, errMsg.Error())
 	}
 	this.ServeJson(NewResult(rData, errMsg))
 }