|
@@ -30,7 +30,7 @@ func FindUserMsg(this message.FindUserMsgReq, isClean bool) message.FindUserMsgR
|
|
"appid": this.Appid,
|
|
"appid": this.Appid,
|
|
}
|
|
}
|
|
if this.MsgType != -1 {
|
|
if this.MsgType != -1 {
|
|
- cquery["msg_type"] = this.MsgType
|
|
|
|
|
|
+ cquery["group_id"] = this.MsgType
|
|
}
|
|
}
|
|
if this.Read != -1 {
|
|
if this.Read != -1 {
|
|
cquery["isRead"] = this.Read
|
|
cquery["isRead"] = this.Read
|
|
@@ -68,7 +68,7 @@ func FindUserMsg(this message.FindUserMsgReq, isClean bool) message.FindUserMsgR
|
|
SendName: util.ObjToString(v["send_name"]),
|
|
SendName: util.ObjToString(v["send_name"]),
|
|
Createtime: util.ObjToString(v["createtime"]),
|
|
Createtime: util.ObjToString(v["createtime"]),
|
|
Title: util.ObjToString(v["title"]),
|
|
Title: util.ObjToString(v["title"]),
|
|
- MsgType: int64(util.IntAll(v["msg_type"])),
|
|
|
|
|
|
+ MsgType: int64(util.IntAll(v["group_id"])),
|
|
Link: util.ObjToString(v["link"]),
|
|
Link: util.ObjToString(v["link"]),
|
|
CiteId: util.Int64All(v["cite_id"]),
|
|
CiteId: util.Int64All(v["cite_id"]),
|
|
Content: util.ObjToString(v["content"]),
|
|
Content: util.ObjToString(v["content"]),
|
|
@@ -106,7 +106,7 @@ func UserMsgList(this *message.UserMsgListReq) *message.UserMsgList {
|
|
"appid": this.Appid,
|
|
"appid": this.Appid,
|
|
}
|
|
}
|
|
if this.MsgType > 0 {
|
|
if this.MsgType > 0 {
|
|
- cquery["msg_type"] = this.MsgType
|
|
|
|
|
|
+ cquery["group_id"] = this.MsgType
|
|
}
|
|
}
|
|
if this.Read != -1 {
|
|
if this.Read != -1 {
|
|
cquery["isRead"] = this.Read
|
|
cquery["isRead"] = this.Read
|
|
@@ -114,13 +114,15 @@ func UserMsgList(this *message.UserMsgListReq) *message.UserMsgList {
|
|
data := new(message.UserMsgList)
|
|
data := new(message.UserMsgList)
|
|
//获取栏目下的数据
|
|
//获取栏目下的数据
|
|
sData := make(map[string][]*message.Messages)
|
|
sData := make(map[string][]*message.Messages)
|
|
|
|
+ t := time.Now()
|
|
if this.IsColumnNewMsg && this.SortSize > 0 {
|
|
if this.IsColumnNewMsg && this.SortSize > 0 {
|
|
sortData := entity.Mysql.SelectBySql(fmt.Sprintf(`SELECT * FROM (
|
|
sortData := entity.Mysql.SelectBySql(fmt.Sprintf(`SELECT * FROM (
|
|
- SELECT *, ROW_NUMBER() OVER (PARTITION BY msg_type, receive_userid ORDER BY createtime DESC) AS row_num
|
|
|
|
|
|
+ SELECT *, ROW_NUMBER() OVER (PARTITION BY group_id, receive_userid ORDER BY createtime DESC) AS row_num
|
|
FROM message
|
|
FROM message
|
|
WHERE receive_userid = '%s' and isdel = 1 and appid = %s
|
|
WHERE receive_userid = '%s' and isdel = 1 and appid = %s
|
|
) AS message_ranked
|
|
) AS message_ranked
|
|
WHERE row_num <=%d;`, this.UserId, this.Appid, this.SortSize))
|
|
WHERE row_num <=%d;`, this.UserId, this.Appid, this.SortSize))
|
|
|
|
+ log.Println("消息列表耗时1:", time.Since(t))
|
|
if sortData != nil {
|
|
if sortData != nil {
|
|
for _, v := range *sortData {
|
|
for _, v := range *sortData {
|
|
_id := util.Int64All(v["id"])
|
|
_id := util.Int64All(v["id"])
|
|
@@ -134,17 +136,17 @@ func UserMsgList(this *message.UserMsgListReq) *message.UserMsgList {
|
|
SendName: common.InterfaceToStr(v["send_name"]),
|
|
SendName: common.InterfaceToStr(v["send_name"]),
|
|
Createtime: common.InterfaceToStr(v["createtime"]),
|
|
Createtime: common.InterfaceToStr(v["createtime"]),
|
|
Title: common.InterfaceToStr(v["title"]),
|
|
Title: common.InterfaceToStr(v["title"]),
|
|
- MsgType: int64(util.IntAll(v["msg_type"])),
|
|
|
|
|
|
+ MsgType: int64(util.IntAll(v["group_id"])),
|
|
Link: common.InterfaceToStr(v["link"]),
|
|
Link: common.InterfaceToStr(v["link"]),
|
|
CiteId: util.Int64All(v["cite_id"]),
|
|
CiteId: util.Int64All(v["cite_id"]),
|
|
Content: common.InterfaceToStr(v["content"]),
|
|
Content: common.InterfaceToStr(v["content"]),
|
|
IsRead: util.Int64All(v["isRead"]),
|
|
IsRead: util.Int64All(v["isRead"]),
|
|
MsgLogId: util.Int64All(v["msg_log_id"]),
|
|
MsgLogId: util.Int64All(v["msg_log_id"]),
|
|
}
|
|
}
|
|
- if sData[common.InterfaceToStr(v["msg_type"])] == nil {
|
|
|
|
- sData[common.InterfaceToStr(v["msg_type"])] = []*message.Messages{&msg}
|
|
|
|
|
|
+ if sData[common.InterfaceToStr(v["group_id"])] == nil {
|
|
|
|
+ sData[common.InterfaceToStr(v["group_id"])] = []*message.Messages{&msg}
|
|
} else {
|
|
} else {
|
|
- sData[common.InterfaceToStr(v["msg_type"])] = append(sData[common.InterfaceToStr(v["msg_type"])], &msg)
|
|
|
|
|
|
+ sData[common.InterfaceToStr(v["group_id"])] = append(sData[common.InterfaceToStr(v["group_id"])], &msg)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -154,28 +156,29 @@ func UserMsgList(this *message.UserMsgListReq) *message.UserMsgList {
|
|
var columnData []*message.AllSortData
|
|
var columnData []*message.AllSortData
|
|
var msgTypes []string
|
|
var msgTypes []string
|
|
for _, v := range entity.MessageColumn {
|
|
for _, v := range entity.MessageColumn {
|
|
- if common.IntAll(v["msg_type"]) > 0 {
|
|
|
|
- msgTypes = append(msgTypes, fmt.Sprintf(`"%s"`, common.InterfaceToStr(v["msg_type"])))
|
|
|
|
|
|
+ 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)
|
|
columnUnread := make(map[string]int64)
|
|
- query := entity.Mysql.SelectBySql(fmt.Sprintf("SELECT msg_type,COUNT(CASE WHEN isRead=0 THEN 1 END) as count FROM message where receive_userid=? and isdel=1 and appid=? GROUP BY msg_type ORDER BY FIELD(`msg_type`,%s)", strings.Join(msgTypes, ",")), this.UserId, this.Appid)
|
|
|
|
|
|
+ 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 {
|
|
if query != nil && len(*query) > 0 {
|
|
for _, v := range *query {
|
|
for _, v := range *query {
|
|
- columnUnread[common.InterfaceToStr(v["msg_type"])] = common.Int64All(v["count"])
|
|
|
|
|
|
+ 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"])
|
|
column.Img = fmt.Sprintf("/common-module/msgCenter/%s.png", common.InterfaceToStr(v["img"]))
|
|
column.Img = fmt.Sprintf("/common-module/msgCenter/%s.png", common.InterfaceToStr(v["img"]))
|
|
- column.MsgType = common.Int64All(v["msg_type"])
|
|
|
|
|
|
+ column.MsgType = common.Int64All(v["group_id"])
|
|
if column.Name == "私信" {
|
|
if column.Name == "私信" {
|
|
column.UnreadMessages = unreadMsg(this)
|
|
column.UnreadMessages = unreadMsg(this)
|
|
} else {
|
|
} else {
|
|
//消息未读数
|
|
//消息未读数
|
|
- msgType := common.InterfaceToStr(v["msg_type"])
|
|
|
|
|
|
+ msgType := common.InterfaceToStr(v["group_id"])
|
|
column.UnreadMessages = columnUnread[msgType]
|
|
column.UnreadMessages = columnUnread[msgType]
|
|
column.Data = sData[msgType]
|
|
column.Data = sData[msgType]
|
|
}
|
|
}
|
|
@@ -191,6 +194,7 @@ func UserMsgList(this *message.UserMsgListReq) *message.UserMsgList {
|
|
this.OffSet = 1
|
|
this.OffSet = 1
|
|
}
|
|
}
|
|
res := entity.Mysql.Find("message", cquery, "", "createtime desc", (int(this.OffSet)-1)*int(this.PageSize), int(this.PageSize))
|
|
res := entity.Mysql.Find("message", cquery, "", "createtime desc", (int(this.OffSet)-1)*int(this.PageSize), int(this.PageSize))
|
|
|
|
+ log.Println("消息列表耗时3:", time.Since(t))
|
|
if res != nil && len(*res) > 0 {
|
|
if res != nil && len(*res) > 0 {
|
|
for _, v := range *res {
|
|
for _, v := range *res {
|
|
_id := util.Int64All(v["id"])
|
|
_id := util.Int64All(v["id"])
|
|
@@ -204,7 +208,7 @@ func UserMsgList(this *message.UserMsgListReq) *message.UserMsgList {
|
|
SendName: common.InterfaceToStr(v["send_name"]),
|
|
SendName: common.InterfaceToStr(v["send_name"]),
|
|
Createtime: common.InterfaceToStr(v["createtime"]),
|
|
Createtime: common.InterfaceToStr(v["createtime"]),
|
|
Title: common.InterfaceToStr(v["title"]),
|
|
Title: common.InterfaceToStr(v["title"]),
|
|
- MsgType: int64(util.IntAll(v["msg_type"])),
|
|
|
|
|
|
+ MsgType: int64(util.IntAll(v["group_id"])),
|
|
Link: common.InterfaceToStr(v["link"]),
|
|
Link: common.InterfaceToStr(v["link"]),
|
|
CiteId: util.Int64All(v["cite_id"]),
|
|
CiteId: util.Int64All(v["cite_id"]),
|
|
Content: common.InterfaceToStr(v["content"]),
|
|
Content: common.InterfaceToStr(v["content"]),
|
|
@@ -251,10 +255,10 @@ func unreadMsg(this *message.UserMsgListReq) int64 {
|
|
func UserUnreadMsgList(this *message.UserUnreadMsgListReq) (int64, []*message.Messages) {
|
|
func UserUnreadMsgList(this *message.UserUnreadMsgListReq) (int64, []*message.Messages) {
|
|
count := 0
|
|
count := 0
|
|
data := []*message.Messages{}
|
|
data := []*message.Messages{}
|
|
- types := entity.Mysql.Find("message_column", map[string]interface{}{}, `"msg_type"`, "", -1, -1)
|
|
|
|
|
|
+ types := entity.Mysql.Find("message_group", map[string]interface{}{}, `"group_id"`, "", -1, -1)
|
|
if types != nil && len(*types) > 0 {
|
|
if types != nil && len(*types) > 0 {
|
|
for _, v := range *types {
|
|
for _, v := range *types {
|
|
- key := fmt.Sprintf(MsgCountKey, this.UserId, util.IntAll(v["msg_type"]))
|
|
|
|
|
|
+ key := fmt.Sprintf(MsgCountKey, this.UserId, util.IntAll(v["group_id"]))
|
|
if exists, _ := redis.Exists(redisModule, key); exists {
|
|
if exists, _ := redis.Exists(redisModule, key); exists {
|
|
count += redis.GetInt(redisModule, key)
|
|
count += redis.GetInt(redisModule, key)
|
|
}
|
|
}
|
|
@@ -289,7 +293,7 @@ func UserUnreadMsgList(this *message.UserUnreadMsgListReq) (int64, []*message.Me
|
|
SendName: common.InterfaceToStr(val["send_name"]),
|
|
SendName: common.InterfaceToStr(val["send_name"]),
|
|
Createtime: common.InterfaceToStr(val["createtime"]),
|
|
Createtime: common.InterfaceToStr(val["createtime"]),
|
|
Title: common.InterfaceToStr(val["title"]),
|
|
Title: common.InterfaceToStr(val["title"]),
|
|
- MsgType: common.Int64All(val["msg_type"]),
|
|
|
|
|
|
+ MsgType: common.Int64All(val["group_id"]),
|
|
Link: link4,
|
|
Link: link4,
|
|
CiteId: common.Int64All(val["cite_id"]),
|
|
CiteId: common.Int64All(val["cite_id"]),
|
|
Content: common.InterfaceToStr(val["content"]),
|
|
Content: common.InterfaceToStr(val["content"]),
|
|
@@ -309,7 +313,7 @@ func MessageGetLast(this *message.UserMsgListReq) *message.Messages {
|
|
"isdel": 1,
|
|
"isdel": 1,
|
|
"appid": this.Appid,
|
|
"appid": this.Appid,
|
|
"isRead": 0,
|
|
"isRead": 0,
|
|
- "msg_type": 1,
|
|
|
|
|
|
+ "group_id": 1,
|
|
}
|
|
}
|
|
lastMsg := entity.Mysql.FindOne("message", query, "", "createtime desc")
|
|
lastMsg := entity.Mysql.FindOne("message", query, "", "createtime desc")
|
|
if lastMsg != nil && len(*lastMsg) > 0 {
|
|
if lastMsg != nil && len(*lastMsg) > 0 {
|
|
@@ -324,7 +328,7 @@ func MessageGetLast(this *message.UserMsgListReq) *message.Messages {
|
|
SendName: common.InterfaceToStr((*lastMsg)["send_name"]),
|
|
SendName: common.InterfaceToStr((*lastMsg)["send_name"]),
|
|
Createtime: common.InterfaceToStr((*lastMsg)["createtime"]),
|
|
Createtime: common.InterfaceToStr((*lastMsg)["createtime"]),
|
|
Title: common.InterfaceToStr((*lastMsg)["title"]),
|
|
Title: common.InterfaceToStr((*lastMsg)["title"]),
|
|
- MsgType: common.Int64All((*lastMsg)["msg_type"]),
|
|
|
|
|
|
+ MsgType: common.Int64All((*lastMsg)["group_id"]),
|
|
Link: common.InterfaceToStr((*lastMsg)["link"]),
|
|
Link: common.InterfaceToStr((*lastMsg)["link"]),
|
|
CiteId: common.Int64All((*lastMsg)["cite_id"]),
|
|
CiteId: common.Int64All((*lastMsg)["cite_id"]),
|
|
Content: common.InterfaceToStr((*lastMsg)["content"]),
|
|
Content: common.InterfaceToStr((*lastMsg)["content"]),
|
|
@@ -393,6 +397,11 @@ func MultSave(this message.MultipleSaveMsgReq) (int64, string) {
|
|
return 0, "无效的用户id"
|
|
return 0, "无效的用户id"
|
|
}
|
|
}
|
|
wg := &sync.WaitGroup{}
|
|
wg := &sync.WaitGroup{}
|
|
|
|
+ var group_id int
|
|
|
|
+ class := entity.Mysql.FindOne("message_class", map[string]interface{}{"msg_type": this.MsgType}, "group_id", "")
|
|
|
|
+ if class != nil && len(*class) > 0 {
|
|
|
|
+ group_id = util.IntAll((*class)["group_id"])
|
|
|
|
+ }
|
|
for i := 0; i < len(userIdArr); i++ {
|
|
for i := 0; i < len(userIdArr); i++ {
|
|
if userIdArr[i] == "" {
|
|
if userIdArr[i] == "" {
|
|
continue
|
|
continue
|
|
@@ -404,6 +413,7 @@ func MultSave(this message.MultipleSaveMsgReq) (int64, string) {
|
|
if len(positionIdArr) == len(userIdArr) {
|
|
if len(positionIdArr) == len(userIdArr) {
|
|
positionId = common.Int64All(positionIdArr[i])
|
|
positionId = common.Int64All(positionIdArr[i])
|
|
}
|
|
}
|
|
|
|
+
|
|
go func(v, userName string, positionId int64) {
|
|
go func(v, userName string, positionId int64) {
|
|
defer func() {
|
|
defer func() {
|
|
<-entity.SaveConcurrencyChan
|
|
<-entity.SaveConcurrencyChan
|
|
@@ -411,8 +421,8 @@ func MultSave(this message.MultipleSaveMsgReq) (int64, string) {
|
|
}()
|
|
}()
|
|
//消息数组
|
|
//消息数组
|
|
c := entity.Mysql.Count("conversation", map[string]interface{}{"receive_id": v, "send_id": this.SendUserId})
|
|
c := entity.Mysql.Count("conversation", map[string]interface{}{"receive_id": v, "send_id": this.SendUserId})
|
|
- sql3 := `INSERT INTO message(appid,receive_userid,receive_name,send_userid,send_name,title,content,msg_type,link,cite_id,createtime,isRead,isdel,msg_log_id,show_buoy,show_content,position_id) values ("%s",'%s','%s','%s','%s','%s','%s',%d,'%s',0,'%s',0,1,%d,%d,'%s',?);`
|
|
|
|
- sql3 = fmt.Sprintf(sql3, this.Appid, v, userName, this.SendUserId, this.SendName, this.Title, this.Content, this.MsgType, this.Link, time.Now().Format("2006-01-02 15:04:05"), this.MsgLogId, this.ShowBuoy, this.ShowContent)
|
|
|
|
|
|
+ sql3 := `INSERT INTO message(appid,receive_userid,receive_name,send_userid,send_name,title,content,msg_type,link,cite_id,createtime,isRead,isdel,msg_log_id,show_buoy,show_content,position_id,group_id) values ("%s",'%s','%s','%s','%s','%s','%s',%d,'%s',0,'%s',0,1,%d,%d,'%s',%d,?);`
|
|
|
|
+ sql3 = fmt.Sprintf(sql3, this.Appid, v, userName, this.SendUserId, this.SendName, this.Title, this.Content, this.MsgType, this.Link, time.Now().Format("2006-01-02 15:04:05"), this.MsgLogId, this.ShowBuoy, this.ShowContent, group_id)
|
|
if c <= 0 {
|
|
if c <= 0 {
|
|
sql1 := `INSERT INTO conversation(appid,secret_key,user_id,receive_id,receive_name,send_id,send_name,sort,createtime) values ('%s','','%s','%s','%s','%s','%s',0,'%s');`
|
|
sql1 := `INSERT INTO conversation(appid,secret_key,user_id,receive_id,receive_name,send_id,send_name,sort,createtime) values ('%s','','%s','%s','%s','%s','%s',0,'%s');`
|
|
sql1 = fmt.Sprintf(sql1, this.Appid, this.SendUserId, v, userName, this.SendUserId, this.SendName, time.Now().Format("2006-01-02 15:04:05"))
|
|
sql1 = fmt.Sprintf(sql1, this.Appid, this.SendUserId, v, userName, this.SendUserId, this.SendName, time.Now().Format("2006-01-02 15:04:05"))
|