|
@@ -404,6 +404,32 @@ func FindUserClassUnreadAndClassAllMsg(userId string) (classUnreadCountMap map[i
|
|
|
classAllMsgMap[int(v.GroupId)] = Uint32ArrToIntArr(v.ClassAll)
|
|
|
}
|
|
|
}
|
|
|
+ rdata, _ := redis.GetBytes(redisModule, fmt.Sprintf(UserClearUnread, userId))
|
|
|
+ rdataArr := []uint32{}
|
|
|
+ if rdata != nil {
|
|
|
+ if json.Unmarshal(*rdata, &rdataArr); err != nil {
|
|
|
+ return classUnreadCountMap, classUnreadMsgMap, classAllMsgMap, err
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /*userUnreadArr := []uint32{}
|
|
|
+ if len(rdataArr) > 0 {
|
|
|
+ if len(userUnreadMsg) > 0 {
|
|
|
+ for _, v := range userUnreadMsg {
|
|
|
+ isExist := false
|
|
|
+ for _, v1 := range rdataArr {
|
|
|
+ if v == v1 {
|
|
|
+ isExist = true
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if !isExist {
|
|
|
+ userUnreadArr = append(userUnreadArr, v)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ userReadMsg = append(userReadMsg, rdataArr...)
|
|
|
+ }*/
|
|
|
+
|
|
|
sql := fmt.Sprintf(`select a2.group_id,bitmapToArray(bitmapAnd(a1.unreadArr,a2.msg_bitmap)) as unreadArr,bitmapToArray(bitmapAnd(a1.allMsg,a2.msg_bitmap)) as classMsgArr from
|
|
|
(SELECT bitmapAndnot(mus.allMsg,mus.readMsg) unreadArr,mus.allMsg FROM message_user_summary mus WHERE mus.userId = '%s') a1,
|
|
|
(select msg_bitmap,group_id from message_summary ms where 1=1 limit 10) a2`, userId)
|
|
@@ -420,46 +446,42 @@ func FindUserClassUnreadAndClassAllMsg(userId string) (classUnreadCountMap map[i
|
|
|
log.Println("获取各分类读取分类数据出错:", err)
|
|
|
return
|
|
|
}
|
|
|
+ //处理已读
|
|
|
+ unreadArr := []uint32{}
|
|
|
+ if len(rdataArr) > 0 {
|
|
|
+ if len(group.ClassUnread) > 0 {
|
|
|
+ for _, v := range rdataArr {
|
|
|
+ isExist := false
|
|
|
+ for _, v1 := range group.ClassUnread {
|
|
|
+ if v == v1 {
|
|
|
+ isExist = true
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if !isExist {
|
|
|
+ unreadArr = append(unreadArr, v)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ group.ClassUnread = unreadArr
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
findRes = append(findRes, group)
|
|
|
//log.Println("========", len(group.ClassUnread))
|
|
|
- classUnreadCountMap[int(group.GroupId)] = len(group.ClassUnread)
|
|
|
- classUnreadMsgMap[int(group.GroupId)] = Uint32ArrToIntArr(group.ClassUnread)
|
|
|
- //classAllCountMap[int(group.GroupId)] = len(group.ClassAll)
|
|
|
- classAllMsgMap[int(group.GroupId)] = Uint32ArrToIntArr(group.ClassAll)
|
|
|
+
|
|
|
}
|
|
|
if findRes != nil && len(findRes) > 0 { //缓存
|
|
|
+ for _, val := range findRes {
|
|
|
+ classUnreadCountMap[int(val.GroupId)] = len(val.ClassUnread)
|
|
|
+ classUnreadMsgMap[int(val.GroupId)] = Uint32ArrToIntArr(val.ClassUnread)
|
|
|
+ //classAllCountMap[int(group.GroupId)] = len(group.ClassAll)
|
|
|
+ classAllMsgMap[int(val.GroupId)] = Uint32ArrToIntArr(val.ClassAll)
|
|
|
+ }
|
|
|
redis.Put(redisModule, redisKey, findRes, config.ConfigJson.RedisFailureTime)
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-//FindUserClassMsg 查询用户分类所有消息id
|
|
|
-/*func FindUserClassMsg(userId string) (map[int]int, map[int][]int) {
|
|
|
- sql := fmt.Sprintf(`select a2.group_id,bitmapToArray(bitmapAnd(a1.allMsg,a2.msg_bitmap)) as unreadArr from
|
|
|
- (SELECT mus.allMsg as allMsg FROM message_user_summary mus WHERE mus.userId = '%s') a1,
|
|
|
- (select msg_bitmap,group_id from message_summary ms where 1=1 limit 10) a2`, userId)
|
|
|
- fmt.Println("FindUserClassMsg", sql)
|
|
|
- rows, err := entity.ClickhouseConn.Query(context.Background(), sql)
|
|
|
- if err != nil {
|
|
|
- log.Println("获取各分类未读消息数组出错:", err)
|
|
|
- return nil, nil
|
|
|
- }
|
|
|
- classCountMap := map[int]int{}
|
|
|
- classMsgMap := map[int][]int{}
|
|
|
- for rows.Next() {
|
|
|
- group := UserClassSummary{}
|
|
|
- err = rows.ScanStruct(&group)
|
|
|
- if err != nil {
|
|
|
- log.Println("获取各分类读取分类数据出错:", err)
|
|
|
- return nil, nil
|
|
|
- }
|
|
|
- //fmt.Println(int(group.GroupId), len(group.UnreadArr))
|
|
|
- classCountMap[int(group.GroupId)] = len(group.UnreadArr)
|
|
|
- classMsgMap[int(group.GroupId)] = Uint32ArrToIntArr(group.UnreadArr)
|
|
|
- }
|
|
|
- return classCountMap, classMsgMap
|
|
|
-}*/
|
|
|
-
|
|
|
// GetUserMsgSummary 从用户消息汇总表取数据
|
|
|
func GetUserMsgSummary(userId string, isfilterActive bool) (userAllMsg, userReadMsg, userUnreadMsg []uint32, err error) {
|
|
|
userAllMsg = []uint32{}
|
|
@@ -492,6 +514,31 @@ func GetUserMsgSummary(userId string, isfilterActive bool) (userAllMsg, userRead
|
|
|
log.Println("此用户暂无数据:", err)
|
|
|
return userAllMsg, userReadMsg, userUnreadMsg, err
|
|
|
}
|
|
|
+ rdata, _ := redis.GetBytes(redisModule, fmt.Sprintf(UserClearUnread, userId))
|
|
|
+ rdataArr := []uint32{}
|
|
|
+ if rdata != nil {
|
|
|
+ if json.Unmarshal(*rdata, &rdataArr); err != nil {
|
|
|
+ return nil, nil, nil, err
|
|
|
+ }
|
|
|
+ }
|
|
|
+ userUnreadArr := []uint32{}
|
|
|
+ if len(rdataArr) > 0 {
|
|
|
+ if len(userUnreadMsg) > 0 {
|
|
|
+ for _, v := range userUnreadMsg {
|
|
|
+ isExist := false
|
|
|
+ for _, v1 := range rdataArr {
|
|
|
+ if v == v1 {
|
|
|
+ isExist = true
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if !isExist {
|
|
|
+ userUnreadArr = append(userUnreadArr, v)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ userReadMsg = append(userReadMsg, rdataArr...)
|
|
|
+ }
|
|
|
//缓存
|
|
|
redis.Put(redisModule, key, map[string][]uint32{
|
|
|
"userAllMsg": userAllMsg,
|
|
@@ -660,23 +707,3 @@ func GetMsgInfo(msgId int, userId string) map[string]interface{} {
|
|
|
}
|
|
|
return msg
|
|
|
}
|
|
|
-
|
|
|
-// PutRedisUserAllMsg 加载用户的所有消息
|
|
|
-/*func PutRedisUserAllMsg(userId string, allMsgBitmap *roaring.Bitmap) (rData []map[string]interface{}) {
|
|
|
- str := ""
|
|
|
- for i, v := range allMsgBitmap.ToArray() {
|
|
|
- if i < len(allMsgBitmap.ToArray())-1 {
|
|
|
- str += common.InterfaceToStr(v) + ","
|
|
|
- } else {
|
|
|
- str += common.InterfaceToStr(v)
|
|
|
- }
|
|
|
- }
|
|
|
- //查询用户所有消息
|
|
|
- key := fmt.Sprintf(BitmapUserMsg, userId)
|
|
|
- m := entity.Mysql.SelectBySql("SELECT id,msg_type,title,content,send_time,link,menu_name,group_id FROM message_send_log WHERE send_status = 4 AND isdel = 1 AND id in (?) ORDER BY send_time DESC", str)
|
|
|
- if m != nil && len(*m) > 0 {
|
|
|
- rData = *m
|
|
|
- redis.Put(redisModule, key, rData, -1)
|
|
|
- }
|
|
|
- return rData
|
|
|
-}*/
|