|
@@ -3,6 +3,7 @@ package common
|
|
import (
|
|
import (
|
|
"app.yhyue.com/moapp/MessageCenter/entity"
|
|
"app.yhyue.com/moapp/MessageCenter/entity"
|
|
"app.yhyue.com/moapp/MessageCenter/rpc/type/message"
|
|
"app.yhyue.com/moapp/MessageCenter/rpc/type/message"
|
|
|
|
+ "app.yhyue.com/moapp/MessageCenter/util"
|
|
qutil "app.yhyue.com/moapp/jybase/common"
|
|
qutil "app.yhyue.com/moapp/jybase/common"
|
|
"app.yhyue.com/moapp/jybase/redis"
|
|
"app.yhyue.com/moapp/jybase/redis"
|
|
"errors"
|
|
"errors"
|
|
@@ -60,27 +61,41 @@ func (service *MessageService) DeleteMessage(id []string, appId string) (int64,
|
|
return 1, "删除消息成功"
|
|
return 1, "删除消息成功"
|
|
}
|
|
}
|
|
|
|
|
|
-// 未读消息合计
|
|
|
|
-func (service *MessageService) CountUnread(userId string) int64 {
|
|
|
|
- var count int64
|
|
|
|
- var msgTypes []string
|
|
|
|
|
|
+// 未读消息合计 isRedis 是否需要初始化redis
|
|
|
|
+func (service *MessageService) CountUnread(userId string, isRedis bool) (map[string]int64, int64) {
|
|
|
|
+ var (
|
|
|
|
+ count int64
|
|
|
|
+ msgTypes []string
|
|
|
|
+ )
|
|
|
|
+ data := make(map[string]int64)
|
|
for _, v := range entity.MessageColumn {
|
|
for _, v := range entity.MessageColumn {
|
|
- if qutil.IntAll(v["group_id"]) > 0 && qutil.IntAll(v["group_id"]) < 999 {
|
|
|
|
|
|
+ if util.IntAll(v["group_id"]) > 0 && util.IntAll(v["group_id"]) < 999 {
|
|
|
|
+ //去除全部与私信
|
|
msgTypes = append(msgTypes, fmt.Sprintf(`"%s"`, qutil.InterfaceToStr(v["group_id"])))
|
|
msgTypes = append(msgTypes, fmt.Sprintf(`"%s"`, qutil.InterfaceToStr(v["group_id"])))
|
|
|
|
+ key := fmt.Sprintf(MsgCountKey, userId, util.IntAll(v["group_id"]))
|
|
|
|
+ if exists, _ := redis.Exists(redisModule, key); exists {
|
|
|
|
+ ct := util.Int64All(redis.GetInt(redisModule, key))
|
|
|
|
+ data[qutil.InterfaceToStr(v["group_id"])] = ct
|
|
|
|
+ count += ct
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if len(msgTypes) > 0 {
|
|
|
|
|
|
+ if len(msgTypes) > 0 && len(msgTypes) != len(data) {
|
|
|
|
+ count = 0
|
|
query := entity.Mysql.SelectBySql(fmt.Sprintf("SELECT group_id,COUNT(CASE WHEN isRead=0 THEN 1 END) as count FROM message where receive_userid=? and isdel=1 and group_id IS NOT NULL GROUP BY group_id ORDER BY FIELD(`group_id`,%s)", strings.Join(msgTypes, ",")), userId)
|
|
query := entity.Mysql.SelectBySql(fmt.Sprintf("SELECT group_id,COUNT(CASE WHEN isRead=0 THEN 1 END) as count FROM message where receive_userid=? and isdel=1 and group_id IS NOT NULL GROUP BY group_id ORDER BY FIELD(`group_id`,%s)", strings.Join(msgTypes, ",")), userId)
|
|
if query != nil && len(*query) > 0 {
|
|
if query != nil && len(*query) > 0 {
|
|
for _, v := range *query {
|
|
for _, v := range *query {
|
|
|
|
+ data[qutil.InterfaceToStr(v["group_id"])] = qutil.Int64All(v["count"])
|
|
count += qutil.Int64All(v["count"])
|
|
count += qutil.Int64All(v["count"])
|
|
- key := fmt.Sprintf(MsgCountKey, userId, qutil.IntAll(v["group_id"]))
|
|
|
|
- redis.Put(redisModule, key, qutil.Int64All(v["count"]), -1)
|
|
|
|
|
|
+ if isRedis {
|
|
|
|
+ key := fmt.Sprintf(MsgCountKey, userId, qutil.IntAll(v["group_id"]))
|
|
|
|
+ redis.Put(redisModule, key, qutil.Int64All(v["count"]), -1)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- return count
|
|
|
|
|
|
+ return data, count
|
|
}
|
|
}
|
|
|
|
|
|
// 查询消息详情
|
|
// 查询消息详情
|