浏览代码

feat:消息增加子分类列表查询

fuwencai 1 年之前
父节点
当前提交
56a2f86912

+ 1 - 1
.gitignore

@@ -1,2 +1,2 @@
 /.output/
-.idea/
+.idea

+ 6 - 1
.idea/MessageCenter.iml

@@ -2,7 +2,12 @@
 <module type="WEB_MODULE" version="4">
   <component name="Go" enabled="true" />
   <component name="NewModuleRootManager">
-    <content url="file://$MODULE_DIR$" />
+    <content url="file://$MODULE_DIR$">
+      <excludeFolder url="file://$MODULE_DIR$/.idea/httpRequests" />
+      <excludeFolder url="file://$MODULE_DIR$/api/logs" />
+      <excludeFolder url="file://$MODULE_DIR$/rpc/logs" />
+      <excludeFolder url="file://$MODULE_DIR$/.output" />
+    </content>
     <orderEntry type="inheritedJdk" />
     <orderEntry type="sourceFolder" forTests="false" />
   </component>

+ 1 - 1
api/internal/logic/messagelistlogic.go

@@ -99,7 +99,7 @@ func (l *MessageListLogic) MessageList(req *types.MessageListReq) (resp *types.M
 				"img":            vs.Img,
 				"msg_type":       vs.MsgType,
 				"unreadMessages": vs.UnreadMessages,
-				"IsClassSearch":  vs.IsClassSearch,
+				"isClassSearch":  vs.IsClassSearch,
 			}
 			var cn []map[string]interface{}
 			for _, v := range vs.Data {

+ 4 - 3
entity/message.go

@@ -19,11 +19,12 @@ var GmailAuth []*mail.GmailAuth
 var SurvivalTime int
 var RollingTiming int64
 var SaveConcurrencyChan chan int //  定义保存消息并发
-var ClassSearchMap map[int64]map[int64]MsgClass
+var ClassSearchMap map[int64][]MsgClass
 
 type MsgClass struct {
-	Name string `json:"name"`
-	Img  string `json:"img"`
+	MsgType int64  `json:"msgType"`
+	Name    string `json:"name"`
+	Img     string `json:"img"`
 }
 type Message struct {
 	Id            string    `xorm:"id" form:"id" json:"id"`

+ 8 - 7
rpc/internal/common/messageClass.go

@@ -10,7 +10,7 @@ import (
 
 // InitClassSearchMap 初始化需要展示细化分类的消息分类信息
 func InitClassSearchMap() {
-	entity.ClassSearchMap = map[int64]map[int64]entity.MsgClass{}
+	entity.ClassSearchMap = map[int64][]entity.MsgClass{}
 	// 初始化需要展示消息细化分类的groupid 和对应的class信息
 	if config.ConfigJson.ClassSearchList != nil && len(config.ConfigJson.ClassSearchList) > 0 {
 		groupIDs := config.ConfigJson.ClassSearchList
@@ -19,7 +19,7 @@ func InitClassSearchMap() {
 			qArr = append(qArr, fmt.Sprintf("%d", groupIDs[i]))
 		}
 		// 查库
-		q := "SELECT * FROM message_class where group_id in (" + strings.Join(qArr, ",") + ");"
+		q := "SELECT * FROM message_class where group_id in (" + strings.Join(qArr, ",") + ") order by msg_type;"
 		rs := entity.Mysql.SelectBySql(q)
 		if rs != nil && len(*rs) > 0 {
 			for i := 0; i < len(*rs); i++ {
@@ -29,12 +29,13 @@ func InitClassSearchMap() {
 				img := common.ObjToString((*rs)[i]["img"])
 				// 处理成map
 				if _, ok := entity.ClassSearchMap[groupID]; !ok {
-					entity.ClassSearchMap[groupID] = map[int64]entity.MsgClass{}
-				}
-				entity.ClassSearchMap[groupID][msgType] = entity.MsgClass{
-					Name: msgName,
-					Img:  img,
+					entity.ClassSearchMap[groupID] = []entity.MsgClass{}
 				}
+				entity.ClassSearchMap[groupID] = append(entity.ClassSearchMap[groupID], entity.MsgClass{
+					MsgType: msgType,
+					Name:    msgName,
+					Img:     img,
+				})
 			}
 		}
 	}

+ 15 - 10
rpc/internal/common/messageService.go

@@ -109,19 +109,24 @@ func (service *MessageService) CountClassUnread(userId string, groupId int64) (c
 	if _, ok := entity.ClassSearchMap[groupId]; !ok {
 		return
 	}
-	for classMsgType_, _ := range entity.ClassSearchMap[groupId] {
-		key := fmt.Sprintf(MsgClassCountKey, userId, classMsgType_)
-		if exists, _ := redis.Exists(MsgClassCountKey, key); exists {
-			ct := util.Int64All(redis.GetInt(MsgClassCountKey, key))
-			data[fmt.Sprintf("%d", classMsgType_)] = ct
+	for i := 0; i < len(entity.ClassSearchMap[groupId]); i++ {
+		msgClass := entity.ClassSearchMap[groupId][i]
+		key := fmt.Sprintf(MsgClassCountKey, userId, msgClass.MsgType)
+		if exists, _ := redis.Exists(redisModule, key); exists {
+			ct := util.Int64All(redis.GetInt(redisModule, key))
+			data[fmt.Sprintf("%d", msgClass.MsgType)] = ct
 			count += ct
 		} else {
-			// todo
-			entity.Mysql.CountBySql("select * ")
-			//key := fmt.Sprintf(MsgClassCountKey, userId,classMsgType_)
-			//redis.Put(redisModule, key, , -1)
+			q := "select count(*) from message where receive_userid=? and isdel=1 and msg_type=?"
+			classCount := entity.Mysql.CountBySql(q, userId, msgClass.MsgType)
+			if classCount != -1 {
+				redis.Put(redisModule, key, classCount, -1)
+				data[fmt.Sprintf("%d", msgClass.MsgType)] = classCount
+				count += classCount
+			} else {
+				log.Println("查询classCount失败:", classCount, q)
+			}
 		}
-
 	}
 
 	return data, count

+ 13 - 12
rpc/internal/common/sendMsg.go

@@ -133,12 +133,13 @@ func UserMsgList(this *message.UserMsgListReq) *message.UserMsgList {
 	if this.IsColumnNewMsg && this.SortSize > 0 {
 		var sortData *[]map[string]interface{}
 		if this.IsClassSearch { // p436 增加
-			sortData = entity.Mysql.SelectBySql(fmt.Sprintf(`SELECT title,createtime,msg_type as group_id ,id FROM (
+			sortDataQ := fmt.Sprintf(`SELECT title,createtime,msg_type as group_id ,id FROM (
   			SELECT title,createtime,msg_type,id, ROW_NUMBER() OVER (PARTITION BY msg_type, receive_userid ORDER BY createtime DESC) AS row_num
   			FROM message
-  			WHERE receive_userid = '%s' and isdel = 1 and  appid = %s and nd group_id=%d
+  			WHERE receive_userid = '%s' and isdel = 1 and  appid = %s and  group_id=%d
 		) AS message_ranked
-		WHERE row_num <=%d;`, this.UserId, this.Appid, this.MsgType, this.SortSize))
+		WHERE row_num <=%d;`, this.UserId, this.Appid, this.MsgType, this.SortSize)
+			sortData = entity.Mysql.SelectBySql(sortDataQ)
 		} else {
 			sortData = entity.Mysql.SelectBySql(fmt.Sprintf(`SELECT title,createtime,group_id,id FROM (
   			SELECT title,createtime,group_id,id, ROW_NUMBER() OVER (PARTITION BY group_id, receive_userid ORDER BY createtime DESC) AS row_num
@@ -170,17 +171,17 @@ func UserMsgList(this *message.UserMsgListReq) *message.UserMsgList {
 	var columnData []*message.AllSortData
 	if this.IsColumn && this.MsgType > 0 && this.IsClassSearch {
 		// p436 处理消息细分分类要返回的数据
-		// 类别
-		// todo 获取所有分类未读数 不初始化
-		sortUnread, _ := m.CountUnread(this.UserId, false)
+		// 获取小分类下的未读数
+		sortUnread, _ := m.CountClassUnread(this.UserId, this.MsgType)
 		columnMap := entity.ClassSearchMap[this.MsgType]
-		for k, v := range columnMap {
+		for i := 0; i < len(columnMap); i++ {
+			tmp := columnMap[i]
 			var column message.AllSortData
-			column.Name = v.Name
-			column.Img = fmt.Sprintf("/common-module/msgCenter/%s.png", v.Img)
-			column.MsgType = k
-			// todo 消息未读数
-			msgType := common.InterfaceToStr(k)
+			column.Name = tmp.Name
+			column.Img = fmt.Sprintf("/common-module/msgCenter/%s.png", tmp.Img)
+			column.MsgType = tmp.MsgType
+			// 消息未读数
+			msgType := common.InterfaceToStr(tmp.MsgType)
 			column.UnreadMessages = sortUnread[msgType]
 			unread += sortUnread[msgType]
 			column.Data = sData[msgType]