|
@@ -100,6 +100,26 @@ func UserMsgList(this *message.UserMsgListReq) *message.UserMsgList {
|
|
var (
|
|
var (
|
|
unread, count int64
|
|
unread, count int64
|
|
)
|
|
)
|
|
|
|
+ data := new(message.UserMsgList)
|
|
|
|
+ if !this.IsMsgList && !this.IsColumnNewMsg && !this.IsColumn { //消息未读数统计
|
|
|
|
+ var isUnread int
|
|
|
|
+ for _, v := range entity.MessageColumn {
|
|
|
|
+ key := fmt.Sprintf(MsgCountKey, this.UserId, util.IntAll(v["group_id"]))
|
|
|
|
+ if exists, _ := redis.Exists(redisModule, key); exists {
|
|
|
|
+ isUnread++
|
|
|
|
+ unread += util.Int64All(redis.GetInt(redisModule, key))
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if isUnread != len(entity.MessageColumn) {
|
|
|
|
+ m := &MessageService{}
|
|
|
|
+ unread = m.CountUnread(this.UserId)
|
|
|
|
+ }
|
|
|
|
+ if this.IsContainLetter { //私信统计
|
|
|
|
+ unread += unreadMsg(this)
|
|
|
|
+ }
|
|
|
|
+ data.Unread = unread
|
|
|
|
+ return data
|
|
|
|
+ }
|
|
cquery := map[string]interface{}{
|
|
cquery := map[string]interface{}{
|
|
"receive_userid": this.UserId,
|
|
"receive_userid": this.UserId,
|
|
"isdel": 1,
|
|
"isdel": 1,
|
|
@@ -111,7 +131,7 @@ func UserMsgList(this *message.UserMsgListReq) *message.UserMsgList {
|
|
if this.Read != -1 {
|
|
if this.Read != -1 {
|
|
cquery["isRead"] = this.Read
|
|
cquery["isRead"] = this.Read
|
|
}
|
|
}
|
|
- data := new(message.UserMsgList)
|
|
|
|
|
|
+
|
|
//获取栏目下的数据
|
|
//获取栏目下的数据
|
|
sData := make(map[string][]*message.Messages)
|
|
sData := make(map[string][]*message.Messages)
|
|
t := time.Now()
|
|
t := time.Now()
|
|
@@ -151,24 +171,9 @@ func UserMsgList(this *message.UserMsgListReq) *message.UserMsgList {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
//消息栏目下的最新消息
|
|
//消息栏目下的最新消息
|
|
var columnData []*message.AllSortData
|
|
var columnData []*message.AllSortData
|
|
- var msgTypes []string
|
|
|
|
- for _, v := range entity.MessageColumn {
|
|
|
|
- if common.IntAll(v["group_id"]) > 0 {
|
|
|
|
- msgTypes = append(msgTypes, fmt.Sprintf(`"%s"`, common.InterfaceToStr(v["group_id"])))
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
if this.IsColumn {
|
|
if this.IsColumn {
|
|
- columnUnread := make(map[string]int64)
|
|
|
|
- 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 appid=? GROUP BY group_id ORDER BY FIELD(`group_id`,%s)", strings.Join(msgTypes, ",")), this.UserId, this.Appid)
|
|
|
|
- log.Println("消息列表耗时2:", time.Since(t))
|
|
|
|
- if query != nil && len(*query) > 0 {
|
|
|
|
- for _, v := range *query {
|
|
|
|
- columnUnread[common.InterfaceToStr(v["group_id"])] = common.Int64All(v["count"])
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
for _, v := range entity.MessageColumn {
|
|
for _, v := range entity.MessageColumn {
|
|
var column message.AllSortData
|
|
var column message.AllSortData
|
|
column.Name = common.InterfaceToStr(v["name"])
|
|
column.Name = common.InterfaceToStr(v["name"])
|
|
@@ -179,7 +184,7 @@ func UserMsgList(this *message.UserMsgListReq) *message.UserMsgList {
|
|
} else {
|
|
} else {
|
|
//消息未读数
|
|
//消息未读数
|
|
msgType := common.InterfaceToStr(v["group_id"])
|
|
msgType := common.InterfaceToStr(v["group_id"])
|
|
- column.UnreadMessages = columnUnread[msgType]
|
|
|
|
|
|
+ column.UnreadMessages = util.Int64All(redis.GetInt(redisModule, fmt.Sprintf(MsgCountKey, this.UserId, util.IntAll(msgType))))
|
|
column.Data = sData[msgType]
|
|
column.Data = sData[msgType]
|
|
}
|
|
}
|
|
unread += column.UnreadMessages
|
|
unread += column.UnreadMessages
|
|
@@ -271,7 +276,6 @@ func UserUnreadMsgList(this *message.UserUnreadMsgListReq) (int64, []*message.Me
|
|
"appid": this.Appid,
|
|
"appid": this.Appid,
|
|
"isRead": 0,
|
|
"isRead": 0,
|
|
}
|
|
}
|
|
- log.Println(query)
|
|
|
|
res := entity.Mysql.Find("message", query, "", "createtime desc", (int(this.OffSet)-1)*int(this.PageSize), int(this.PageSize))
|
|
res := entity.Mysql.Find("message", query, "", "createtime desc", (int(this.OffSet)-1)*int(this.PageSize), int(this.PageSize))
|
|
if res != nil && len(*res) > 0 {
|
|
if res != nil && len(*res) > 0 {
|
|
for _, val := range *res {
|
|
for _, val := range *res {
|
|
@@ -308,6 +312,9 @@ func UserUnreadMsgList(this *message.UserUnreadMsgListReq) (int64, []*message.Me
|
|
}
|
|
}
|
|
|
|
|
|
func MessageGetLast(this *message.UserMsgListReq) *message.Messages {
|
|
func MessageGetLast(this *message.UserMsgListReq) *message.Messages {
|
|
|
|
+ if !this.IsMsgList && !this.IsColumnNewMsg && !this.IsColumn {
|
|
|
|
+ return nil
|
|
|
|
+ }
|
|
query := map[string]interface{}{
|
|
query := map[string]interface{}{
|
|
"receive_userid": this.UserId,
|
|
"receive_userid": this.UserId,
|
|
"isdel": 1,
|
|
"isdel": 1,
|
|
@@ -368,7 +375,7 @@ func MsgCountMinusOne(userId, appId string, msgType int64) bool {
|
|
Read: 0,
|
|
Read: 0,
|
|
}, true)
|
|
}, true)
|
|
if redis.GetInt(redisModule, keyString) <= 0 {
|
|
if redis.GetInt(redisModule, keyString) <= 0 {
|
|
- return redis.Put(redisModule, keyString, 0, -1)
|
|
|
|
|
|
+ return true
|
|
}
|
|
}
|
|
in := redis.Decrby(redisModule, keyString, 1)
|
|
in := redis.Decrby(redisModule, keyString, 1)
|
|
return in > 0
|
|
return in > 0
|
|
@@ -440,7 +447,7 @@ func MultSave(this message.MultipleSaveMsgReq) (int64, string) {
|
|
})
|
|
})
|
|
logx.Info("执行事务是否成功:", ok)
|
|
logx.Info("执行事务是否成功:", ok)
|
|
if ok {
|
|
if ok {
|
|
- ok1 := MsgCountAdd(v, this.Appid, this.MsgType)
|
|
|
|
|
|
+ ok1 := MsgCountAdd(v, this.Appid, util.Int64All(group_id))
|
|
if !ok1 {
|
|
if !ok1 {
|
|
log.Println("存redis:", ok1, v)
|
|
log.Println("存redis:", ok1, v)
|
|
}
|
|
}
|
|
@@ -449,7 +456,7 @@ func MultSave(this message.MultipleSaveMsgReq) (int64, string) {
|
|
in := entity.Mysql.InsertBySql(sql3, common.If(positionId != 0, positionId, nil))
|
|
in := entity.Mysql.InsertBySql(sql3, common.If(positionId != 0, positionId, nil))
|
|
logx.Info("插入消息返回 in1 id:", in)
|
|
logx.Info("插入消息返回 in1 id:", in)
|
|
if in > -1 {
|
|
if in > -1 {
|
|
- ok := MsgCountAdd(v, this.Appid, this.MsgType)
|
|
|
|
|
|
+ ok := MsgCountAdd(v, this.Appid, util.Int64All(group_id))
|
|
if !ok {
|
|
if !ok {
|
|
log.Println("存redis:", ok, v)
|
|
log.Println("存redis:", ok, v)
|
|
}
|
|
}
|