|
@@ -2,8 +2,10 @@ package entity
|
|
|
|
|
|
import (
|
|
|
"app.yhyue.com/moapp/jybase/go-xweb/httpsession"
|
|
|
+ "database/sql"
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
+ "github.com/gogf/gf/v2/util/gconv"
|
|
|
"jy/src/jfw/modules/bigmember/src/config"
|
|
|
"jy/src/jfw/modules/bigmember/src/db"
|
|
|
"jy/src/jfw/modules/bigmember/src/util"
|
|
@@ -15,7 +17,6 @@ import (
|
|
|
qutil "app.yhyue.com/moapp/jybase/common"
|
|
|
. "app.yhyue.com/moapp/jybase/date"
|
|
|
elastic "app.yhyue.com/moapp/jybase/es"
|
|
|
- "app.yhyue.com/moapp/jybase/mongodb"
|
|
|
"app.yhyue.com/moapp/jybase/redis"
|
|
|
"app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
|
|
|
)
|
|
@@ -87,19 +88,28 @@ func (this *EntFollow) GetAssociationEnt(entName string) ([]map[string]interface
|
|
|
// EntFollowedShow 详情页查询是否关注企业
|
|
|
// followed 是否已关注
|
|
|
// showFollow 是否展示关注(检索库存在相关企业信息时展示)
|
|
|
-func (this *EntFollow) EntFollowedShow(entId string) (followed, showFollow bool, err error) {
|
|
|
+func (this *EntFollow) EntFollowedShow(entId string) (followed, showFollow bool, followedGroup string, err error) {
|
|
|
if entId == "" {
|
|
|
err = errors.New("未查询到企业")
|
|
|
return
|
|
|
}
|
|
|
- query := map[string]interface{}{"s_entId": entId, "s_userid": this.UserId}
|
|
|
- fRes := db.Base.FindOne(this.SaveTable, query, "i_apppushunread", "")
|
|
|
+ //query := map[string]interface{}{"s_entId": entId, "s_userid": this.UserId}
|
|
|
+ //fRes := db.Base.FindOne(this.SaveTable, query, "i_apppushunread", "")
|
|
|
+ fRes := db.Base.SelectBySql(fmt.Sprintf(`SELECT a.i_apppushunread,c.s_name FROM %s a
|
|
|
+INNER JOIN follow_ent_monitor_relationship b on (a.s_entId = b.s_entId)
|
|
|
+INNER JOIN follow_ent_monitor_group c on (b.s_groupId = c.id and a.s_userid = c.s_userid)
|
|
|
+WHERE a.s_entId = '%s' and a.s_userid = '%s'`, this.SaveTable, entId, this.UserId))
|
|
|
followed = false
|
|
|
- if fRes != nil {
|
|
|
+ if fRes != nil && len(*fRes) > 0 {
|
|
|
followed = true
|
|
|
+ var names []string
|
|
|
+ for _, m := range *fRes {
|
|
|
+ names = append(names, qutil.ObjToString(m["s_name"]))
|
|
|
+ }
|
|
|
+ followedGroup = strings.Join(names, ",")
|
|
|
//已关注,并且有未读标示
|
|
|
- if qutil.IntAll((*fRes)["i_apppushunread"]) > 0 {
|
|
|
- go db.Base.Update(this.SaveTable, query, map[string]interface{}{
|
|
|
+ if qutil.IntAll((*fRes)[0]["i_apppushunread"]) > 0 {
|
|
|
+ go db.Base.Update(this.SaveTable, map[string]interface{}{"s_entId": entId, "s_userid": this.UserId}, map[string]interface{}{
|
|
|
"i_apppushunread": 0,
|
|
|
})
|
|
|
}
|
|
@@ -117,11 +127,22 @@ func (this *EntFollow) EntFollowedShow(entId string) (followed, showFollow bool,
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+type EntFollowGroup struct {
|
|
|
+ Id string `json:"id"`
|
|
|
+ Name string `json:"name"`
|
|
|
+ IsPut int `json:"isPut"`
|
|
|
+ Count int `json:"count"`
|
|
|
+}
|
|
|
+
|
|
|
// GetEntFollowList 我关注的企业列表
|
|
|
// param A默认分组 B竞争对手 C合作伙伴 逗号分隔
|
|
|
// db 0||nil 默认分组、1 竞争对手、2 合作伙伴、3 竞争对手和合作伙伴
|
|
|
-func (this *EntFollow) GetEntFollowList(pNum, pSize int, match, group string) (followData []map[string]interface{}, hasNext bool, count, total int, err error) {
|
|
|
- flistSql := fmt.Sprintf(`SELECT id,f_capital,i_apppushunread,l_establishdate,l_lastpushtime,s_area,s_city,s_employeeno,s_entId,s_entname,i_group,s_phone FROM follow_ent_monitor WHERE s_userid="%s" ORDER BY l_lastpushtime DESC,l_createtime DESC LIMIT %d,%d`, this.UserId, 0, this.MaxNum)
|
|
|
+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, true)
|
|
|
+ if groupErr != nil {
|
|
|
+ return nil, false, -1, -1, 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)
|
|
|
res := db.Base.SelectBySql(flistSql)
|
|
|
if res == nil || len(*res) == 0 {
|
|
@@ -130,8 +151,11 @@ func (this *EntFollow) GetEntFollowList(pNum, pSize int, match, group string) (f
|
|
|
}
|
|
|
log.Print("我关注的企业列表查询结束")
|
|
|
count = len(*res)
|
|
|
+ //获取用户分组列表
|
|
|
+ var (
|
|
|
+ followDataAll []map[string]interface{}
|
|
|
+ )
|
|
|
|
|
|
- var followDataAll []map[string]interface{}
|
|
|
for _, item := range *res {
|
|
|
//兼容从大会员变成免费用户时筛选条件数据错乱问题 取数据全部取出后在进行筛选过滤
|
|
|
if match != "" {
|
|
@@ -139,21 +163,28 @@ func (this *EntFollow) GetEntFollowList(pNum, pSize int, match, group string) (f
|
|
|
continue
|
|
|
}
|
|
|
}
|
|
|
- if group != "" {
|
|
|
- var iGroup bool
|
|
|
- if strings.Contains(group, "A") && (qutil.IntAll(item["i_group"]) == 0) {
|
|
|
- iGroup = true
|
|
|
- }
|
|
|
- if !iGroup && strings.Contains(group, "B") && (qutil.IntAll(item["i_group"]) == 1 || qutil.IntAll(item["i_group"]) == 3) {
|
|
|
- iGroup = true
|
|
|
- }
|
|
|
- if !iGroup && strings.Contains(group, "C") && (qutil.IntAll(item["i_group"]) == 2 || qutil.IntAll(item["i_group"]) == 3) {
|
|
|
- iGroup = true
|
|
|
- }
|
|
|
- if !iGroup {
|
|
|
- continue
|
|
|
+
|
|
|
+ var (
|
|
|
+ enCodeGroups []string
|
|
|
+ has = true
|
|
|
+ )
|
|
|
+ if len(groupIds) > 0 {
|
|
|
+ has = false
|
|
|
+ var (
|
|
|
+ groups = strings.Split(gconv.String(item["gs"]), ",")
|
|
|
+ )
|
|
|
+ for _, group := range groups {
|
|
|
+ if group != "" {
|
|
|
+ enCodeGroups = append(enCodeGroups, util.EncodeId(group))
|
|
|
+ if !has && groupIds[gconv.Int(group)] {
|
|
|
+ has = true
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ if !has {
|
|
|
+ continue
|
|
|
+ }
|
|
|
entId := qutil.ObjToString(item["s_entId"])
|
|
|
if entId == "" { //dev3.6.2 前关注企业未存入企业id
|
|
|
//查询企业entid
|
|
@@ -172,10 +203,11 @@ func (this *EntFollow) GetEntFollowList(pNum, pSize int, match, group string) (f
|
|
|
"s_phone": item["s_phone"],
|
|
|
"i_apppushunread": item["i_apppushunread"],
|
|
|
"l_lastpushtime": item["l_lastpushtime"],
|
|
|
- "s_group": parseGroupStr(qutil.IntAll(item["i_group"])),
|
|
|
+ "s_grousp": strings.Join(enCodeGroups, ","),
|
|
|
}
|
|
|
followDataAll = append(followDataAll, rowMap)
|
|
|
}
|
|
|
+
|
|
|
total = len(followDataAll)
|
|
|
//分页
|
|
|
if total > 0 {
|
|
@@ -272,8 +304,11 @@ func (this *EntFollow) updateFollowed(follow map[string]interface{}) string {
|
|
|
}
|
|
|
|
|
|
// AddFollowEnt 添加关注企业
|
|
|
-func (this *EntFollow) AddFollowEnt(entId, group string, getOldData ...bool) error {
|
|
|
- groupFlag := getGroup(group)
|
|
|
+func (this *EntFollow) AddFollowEnt(entId, groups string, getOldData ...bool) error {
|
|
|
+ groupIds, groupErr := checkGroup(this.UserId, groups)
|
|
|
+ if groupErr != nil {
|
|
|
+ return fmt.Errorf("分组不存在")
|
|
|
+ }
|
|
|
//if this.HasPower {
|
|
|
if db.Base.Count(this.SaveTable, map[string]interface{}{"s_userid": this.UserId, "s_entId": entId}) > 0 {
|
|
|
return errors.New("已关注此企业")
|
|
@@ -286,7 +321,7 @@ func (this *EntFollow) AddFollowEnt(entId, group string, getOldData ...bool) err
|
|
|
return errors.New("查找企业异常")
|
|
|
}
|
|
|
followData := map[string]interface{}{
|
|
|
- "s_entId": mongodb.BsonIdToSId((*res)["_id"]), //dev3.6.2 企业画像根据entId查询
|
|
|
+ "s_entId": entId, //dev3.6.2 企业画像根据entId查询
|
|
|
"s_entname": (*res)["company_name"],
|
|
|
"s_area": qutil.If((*res)["company_area"] == nil, "", (*res)["company_area"]),
|
|
|
"s_city": qutil.If((*res)["company_city"] == nil, "", (*res)["company_city"]),
|
|
@@ -313,14 +348,25 @@ func (this *EntFollow) AddFollowEnt(entId, group string, getOldData ...bool) err
|
|
|
followData["l_establishdate"] = t.Unix()
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- //设置分组
|
|
|
- if groupFlag > -1 {
|
|
|
- followData["i_group"] = groupFlag
|
|
|
- }
|
|
|
- followId := db.Base.Insert(this.SaveTable, followData)
|
|
|
- if followId == -1 {
|
|
|
- return errors.New("保存关注企业异常")
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ for groupId, _ := range groupIds {
|
|
|
+ if db.Base.InsertByTx(tx, "follow_ent_monitor_relationship", map[string]interface{}{
|
|
|
+ "s_entId": entId,
|
|
|
+ "s_groupId": groupId,
|
|
|
+ }) <= 0 {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true
|
|
|
+ }) {
|
|
|
+ return fmt.Errorf("企业关注存储异常")
|
|
|
}
|
|
|
go func(userId string) {
|
|
|
//首页潜在竞争对手缓存
|
|
@@ -357,6 +403,58 @@ func getGroup(groupStr string) (s int) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+// checkGroup 校验分组是否存在
|
|
|
+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 {
|
|
|
+ //新用户插入分组
|
|
|
+ if _, err := db.Base.ExecBySql(fmt.Sprintf(`INSERT INTO follow_ent_monitor_group (s_name, s_userid, create_time, update_time, isPut, isdefGoup) VALUES
|
|
|
+ ('默认分组', '%s', '2025-01-03 12:00:00', '2025-01-13 12:00:00', 0, 1),
|
|
|
+ ('竞争对手', '%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);`, userId, userId, userId)); err != nil {
|
|
|
+ log.Printf("新用户 %s创建分组异常", userId)
|
|
|
+ }
|
|
|
+ return nil, nil
|
|
|
+ }
|
|
|
+ var (
|
|
|
+ hasGroupId = map[int]bool{}
|
|
|
+ rMap = map[int]bool{}
|
|
|
+ deafultMap = map[int]bool{}
|
|
|
+ )
|
|
|
+ for _, m := range *rData {
|
|
|
+ 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))
|
|
|
+ if tId <= 0 {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if hasGroupId[tId] {
|
|
|
+ rMap[tId] = true
|
|
|
+ } else {
|
|
|
+ return nil, fmt.Errorf("未知标签")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return rMap, nil
|
|
|
+}
|
|
|
+
|
|
|
// 格式化分组字段
|
|
|
func parseGroupStr(gFlag int) string {
|
|
|
switch gFlag {
|
|
@@ -372,12 +470,59 @@ func parseGroupStr(gFlag int) string {
|
|
|
}
|
|
|
|
|
|
// ChangeFollowGroup 更换关注企业分组
|
|
|
-func (this *EntFollow) ChangeFollowGroup(fid, group string) error {
|
|
|
- groupValue := getGroup(group)
|
|
|
- if groupValue == -1 {
|
|
|
- groupValue = 0
|
|
|
- }
|
|
|
- if !db.Base.Update(this.SaveTable, map[string]interface{}{"id": fid}, map[string]interface{}{"i_group": groupValue}) {
|
|
|
+func (this *EntFollow) ChangeFollowGroup(entId, groupStr string) error {
|
|
|
+ groupMap, groupErr := checkGroup(this.UserId, groupStr)
|
|
|
+ if groupErr != nil {
|
|
|
+ return fmt.Errorf("分组不存在")
|
|
|
+ }
|
|
|
+ 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 {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ var (
|
|
|
+ remove []int
|
|
|
+ )
|
|
|
+ for _, m := range *rData {
|
|
|
+ var (
|
|
|
+ releaseId = gconv.Int(m["id"])
|
|
|
+ groupId = gconv.Int(m["s_groupId"])
|
|
|
+ has = false
|
|
|
+ )
|
|
|
+
|
|
|
+ for newGroupId, _ := range groupMap {
|
|
|
+ if groupId == newGroupId {
|
|
|
+ has = true
|
|
|
+ groupMap[groupId] = false
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if !has {
|
|
|
+ remove = append(remove, releaseId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for _, id := range remove {
|
|
|
+ if !db.Base.DeleteByTx(tx, "follow_ent_monitor_relationship", map[string]interface{}{
|
|
|
+ "id": id,
|
|
|
+ }) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for groupId, ok := range groupMap {
|
|
|
+ if ok {
|
|
|
+ if db.Base.Insert("follow_ent_monitor_relationship", map[string]interface{}{
|
|
|
+ "s_entId": entId,
|
|
|
+ "s_groupId": groupId,
|
|
|
+ }) <= 0 {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true
|
|
|
+ }) {
|
|
|
return fmt.Errorf("设置分组失败")
|
|
|
}
|
|
|
return nil
|
|
@@ -398,7 +543,23 @@ func (this *EntFollow) DelFollowEnt(entId, fid string) error {
|
|
|
query["id"] = fid
|
|
|
}
|
|
|
data := db.Base.FindOne(this.SaveTable, query, "id,s_entId,s_entname,s_area,s_city,s_phone,f_capital,s_employeeno,l_createtime,s_userid,l_lastpushtime", "")
|
|
|
- if data != nil && db.Base.Delete(this.SaveTable, query) {
|
|
|
+ if data != nil {
|
|
|
+ db.Base.ExecTx("取消关注", func(tx *sql.Tx) bool {
|
|
|
+ if !db.Base.DeleteByTx(tx, this.SaveTable, query) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ //查询关联的标签
|
|
|
+ rData := db.Base.Query("SELECT r.id 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 {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ for _, m := range *rData {
|
|
|
+ if !db.Base.DeleteByTx(tx, "follow_ent_monitor_relationship", map[string]interface{}{"id": gconv.String(m["id"])}) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true
|
|
|
+ })
|
|
|
(*data)["s_followid"] = (*data)["id"]
|
|
|
delete(*data, "id")
|
|
|
db.Mgo.Save("jylab_followent_back", data)
|
|
@@ -544,3 +705,198 @@ func (this *EntFollow) GetFollowEntInfo() (used int64, surplus int64) {
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+func (this *EntFollow) GetLabelGroup() *[]map[string]interface{} {
|
|
|
+ defIdMap := make(map[int]bool)
|
|
|
+ //检测默认分组 初始化
|
|
|
+ count := db.Base.Count("follow_ent_monitor_group", map[string]interface{}{
|
|
|
+ "s_userid": this.UserId,
|
|
|
+ "isdefGoup": 1,
|
|
|
+ })
|
|
|
+ if count == 0 { //初始化默认分组
|
|
|
+ db.Base.SelectBySql(fmt.Sprintf(`INSERT INTO follow_ent_monitor_group (s_name, s_userid, create_time, update_time, isPut, isdefGoup) VALUES
|
|
|
+('默认分组', '%s', '2025-01-03 12:00:00', '2025-01-13 12:00:00', 0, 1),
|
|
|
+('竞争对手', '%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 {
|
|
|
+ //获取最近一次关注的分组
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 {
|
|
|
+ switch { //最近一次分组
|
|
|
+ case len(defIdMap) == 0 && m["s_name"] == "默认分组": //最近没有关注 分配到默认分组
|
|
|
+ m["isSelect"] = true
|
|
|
+ case defIdMap[qutil.IntAll(m["id"])]:
|
|
|
+ m["isSelect"] = true
|
|
|
+ default:
|
|
|
+ m["isSelect"] = false
|
|
|
+ }
|
|
|
+ m["id"] = util.EncodeId(qutil.InterfaceToStr(m["id"]))
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return data
|
|
|
+}
|
|
|
+
|
|
|
+func (this *EntFollow) AddLabelGroup(name string) error {
|
|
|
+ //检测默认分组 初始花
|
|
|
+ DefaultGroupInit(this.UserId)
|
|
|
+ if db.Base.Count("follow_ent_monitor_group", map[string]interface{}{
|
|
|
+ "user_id": this.UserId,
|
|
|
+ "s_name": name,
|
|
|
+ }) > 0 { //是否重名
|
|
|
+ return errors.New("分组名称已存在")
|
|
|
+ }
|
|
|
+ db.Base.Insert("follow_ent_monitor_group", map[string]interface{}{
|
|
|
+ "s_name": name,
|
|
|
+ "s_userid": this.UserId,
|
|
|
+ "create_time": time.Now(),
|
|
|
+ "update_time": time.Now(),
|
|
|
+ "isPut": 1,
|
|
|
+ "isdefGoup": 0,
|
|
|
+ })
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+func (this *EntFollow) PutLabelGroup(name string, groupId string) error {
|
|
|
+ if db.Base.Count("follow_ent_monitor_group", map[string]interface{}{
|
|
|
+ "s_userid": this.UserId,
|
|
|
+ "s_name": name,
|
|
|
+ }) > 0 { //是否重名
|
|
|
+ return errors.New("分组名称已存在")
|
|
|
+ }
|
|
|
+ db.Base.Update("follow_ent_monitor_group", map[string]interface{}{
|
|
|
+ "s_userid": this.UserId,
|
|
|
+ "id": groupId,
|
|
|
+ }, map[string]interface{}{"s_name": name})
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+// DelLabelGroup删除分组 -删除分组:如果删除完分组对应企业没分组了,放到默认分组里,如果企业还有其他分组,就还在其他分组里
|
|
|
+func (this *EntFollow) DelLabelGroup(groupId string) error {
|
|
|
+ var err error
|
|
|
+ if !db.Base.ExecTx("删除分组", func(tx *sql.Tx) bool {
|
|
|
+ var (
|
|
|
+ needMoveDefault []string
|
|
|
+ )
|
|
|
+ //查询当前分组内所有数据
|
|
|
+ rData := db.Base.Query("SELECT r.s_entId,GROUP_CONCAT(g.id SEPARATOR ',') as gs FROM follow_ent_monitor_relationship r inner join follow_ent_monitor_group g on ( r.s_groupId = g.id ) WHERE g.s_userid =? GROUP BY r.s_entId HAVING FIND_IN_SET(?, gs) > 0;", this.UserId, groupId)
|
|
|
+ if rData != nil && len(*rData) > 0 {
|
|
|
+ for _, m := range *rData {
|
|
|
+ var (
|
|
|
+ s_entId = gconv.String(m["s_entId"])
|
|
|
+ groups = gconv.String(m["gs"])
|
|
|
+ hasOtherGroup = false //是否存在其他标签
|
|
|
+ )
|
|
|
+ for _, s := range strings.Split(groups, ",") {
|
|
|
+ if s == "" {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if s != groupId {
|
|
|
+ hasOtherGroup = true
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if !hasOtherGroup {
|
|
|
+ needMoveDefault = append(needMoveDefault, s_entId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(needMoveDefault) > 0 {
|
|
|
+ //查询默认分组id
|
|
|
+ rMap := db.Base.FindOne("follow_ent_monitor_group", map[string]interface{}{
|
|
|
+ "s_name": "默认分组",
|
|
|
+ "s_userid": this.UserId,
|
|
|
+ }, "", "")
|
|
|
+ if rMap == nil || len(*rMap) == 0 {
|
|
|
+ err = fmt.Errorf("未知默认分组")
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ var defaultGroupId = gconv.Int((*rMap)["id"])
|
|
|
+ for _, entId := range needMoveDefault {
|
|
|
+ if db.Base.InsertByTx(tx, "follow_ent_monitor_relationship", map[string]interface{}{
|
|
|
+ "s_groupId": defaultGroupId,
|
|
|
+ "s_entId": entId,
|
|
|
+ }) <= 0 {
|
|
|
+ err = fmt.Errorf("企业数据迁移异常")
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //删除当前标签
|
|
|
+ if !db.Base.DeleteByTx(tx, "follow_ent_monitor_group", map[string]interface{}{
|
|
|
+ "s_userid": this.UserId,
|
|
|
+ "id": groupId,
|
|
|
+ }) {
|
|
|
+ err = fmt.Errorf("未知分组")
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ return true
|
|
|
+ }) && err == nil {
|
|
|
+ err = fmt.Errorf("删除分组异常")
|
|
|
+ }
|
|
|
+ return err
|
|
|
+}
|
|
|
+
|
|
|
+func (this *EntFollow) GetFollowGroupList() (groupUserArr []EntFollowGroup, err error) {
|
|
|
+ groupMap := make(map[int]int)
|
|
|
+ DefaultGroupInit(this.UserId)
|
|
|
+ flistSql := fmt.Sprintf(`SELECT m.s_entId,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 {
|
|
|
+ for _, m := range *res {
|
|
|
+ for _, gId := range strings.Split(gconv.String(m["gs"]), ",") {
|
|
|
+ if groupId := gconv.Int(gId); groupId > 0 {
|
|
|
+ groupMap[groupId]++
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ data := db.Base.SelectBySql(fmt.Sprintf(`SELECT
|
|
|
+ a.id,
|
|
|
+ a.isPut,
|
|
|
+ a.s_name
|
|
|
+FROM
|
|
|
+ follow_ent_monitor_group a
|
|
|
+WHERE
|
|
|
+ a.s_userid = '%s'
|
|
|
+ORDER BY
|
|
|
+ a.isdefGoup DESC,
|
|
|
+ a.create_time DESC`, this.UserId))
|
|
|
+ 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"]),
|
|
|
+ qutil.IntAll(m["isPut"]),
|
|
|
+ groupMap[qutil.IntAll(m["id"])],
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func DefaultGroupInit(userId string) {
|
|
|
+ if db.Base.Count("follow_ent_monitor_group", map[string]interface{}{
|
|
|
+ "user_id": userId,
|
|
|
+ "isdefGoup": 1,
|
|
|
+ }) == 0 { //初始化默认分组
|
|
|
+ db.Base.SelectBySql(fmt.Sprintf(`INSERT INTO follow_ent_monitor_group (s_name, s_userid, create_time, update_time, isPut, isdefGoup) VALUES
|
|
|
+('默认分组', '%s', '2025-01-03 12:00:00', '2025-01-13 12:00:00', 0, 1),
|
|
|
+('竞争对手', '%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);`, userId, userId, userId))
|
|
|
+ }
|
|
|
+}
|