lianbingjie %!s(int64=2) %!d(string=hai) anos
pai
achega
5d5ccc6701
Modificáronse 2 ficheiros con 6 adicións e 8 borrados
  1. 0 1
      README.md
  2. 6 7
      service/messageService.go

+ 0 - 1
README.md

@@ -1,5 +1,4 @@
 消息中台
-
 goctl rpc proto -src message.proto -dir .
 goctl api go -api message.api -dir .
 

+ 6 - 7
service/messageService.go

@@ -75,17 +75,16 @@ func (service *MessageService) CountUnread(userId string, appId string) (int64,
 
 // 获取指定用户指定分类最新一条消息
 func (service *MessageService) LastMessage(userId string, appId string, msgType int64, isRead int64) (*message.Messages, error) {
-	sql := "SELECT * FROM message receive_userid=? and isdel=1 and appid=?  and msg_type=?"
-	valueList := []interface{}{userId, appId, msgType}
-	if isRead != -1 {
-		sql = sql + " and isRead=?"
-		valueList = append(valueList, isRead)
-	}
 	query := map[string]interface{}{
 		"receive_userid": userId,
 		"isdel":          1,
 		"appid":          appId,
-		"msg_type":       msgType,
+	}
+	if isRead != -1 {
+		query["isRead"] = isRead
+	}
+	if msgType != -1 {
+		query["msg_type"] = msgType
 	}
 	lastMsg := entity.Mysql.FindOne("message", query, "", "createtime desc")
 	if lastMsg != nil && len(*lastMsg) > 0 {