|
@@ -1,7 +1,13 @@
|
|
package service
|
|
package service
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
+<<<<<<< HEAD
|
|
"app.yhyue.com/moapp/MessageCenter/rpc/messageclient"
|
|
"app.yhyue.com/moapp/MessageCenter/rpc/messageclient"
|
|
|
|
+=======
|
|
|
|
+ "app.yhyue.com/moapp/MessageCenter/entity"
|
|
|
|
+ "app.yhyue.com/moapp/MessageCenter/rpc/message"
|
|
|
|
+ "app.yhyue.com/moapp/MessageCenter/util"
|
|
|
|
+>>>>>>> master
|
|
"app.yhyue.com/moapp/jybase/redis"
|
|
"app.yhyue.com/moapp/jybase/redis"
|
|
"database/sql"
|
|
"database/sql"
|
|
"fmt"
|
|
"fmt"
|
|
@@ -10,9 +16,12 @@ import (
|
|
"strconv"
|
|
"strconv"
|
|
"strings"
|
|
"strings"
|
|
"time"
|
|
"time"
|
|
|
|
+<<<<<<< HEAD
|
|
|
|
|
|
"app.yhyue.com/moapp/MessageCenter/entity"
|
|
"app.yhyue.com/moapp/MessageCenter/entity"
|
|
"app.yhyue.com/moapp/MessageCenter/util"
|
|
"app.yhyue.com/moapp/MessageCenter/util"
|
|
|
|
+=======
|
|
|
|
+>>>>>>> master
|
|
)
|
|
)
|
|
|
|
|
|
// 类型的顺序
|
|
// 类型的顺序
|
|
@@ -20,6 +29,7 @@ const order = "1,4"
|
|
const MsgCountKey = "count_%s_%s" //redis 消息未读数量 Count.用户id.消息类型=数量
|
|
const MsgCountKey = "count_%s_%s" //redis 消息未读数量 Count.用户id.消息类型=数量
|
|
const redisModule = "msgCount"
|
|
const redisModule = "msgCount"
|
|
|
|
|
|
|
|
+<<<<<<< HEAD
|
|
/*var (
|
|
/*var (
|
|
UserLockMap = map[string]*sync.Mutex{}
|
|
UserLockMap = map[string]*sync.Mutex{}
|
|
//MainLock = sync.Mutex{}
|
|
//MainLock = sync.Mutex{}
|
|
@@ -27,6 +37,9 @@ const redisModule = "msgCount"
|
|
|
|
|
|
func SendMsg(this messageclient.SendMsgRequest) (int64, string) {
|
|
func SendMsg(this messageclient.SendMsgRequest) (int64, string) {
|
|
|
|
|
|
|
|
+=======
|
|
|
|
+func SendMsg(this message.SendMsgRequest) (int64, string) {
|
|
|
|
+>>>>>>> master
|
|
r, err := entity.Mysql11.Query("select count(*) as c from conversation where receive_id = ? and send_id = ? ", this.ReceiveUserId, this.SendUserId)
|
|
r, err := entity.Mysql11.Query("select count(*) as c from conversation where receive_id = ? and send_id = ? ", this.ReceiveUserId, this.SendUserId)
|
|
c := 0
|
|
c := 0
|
|
for r.Next() {
|
|
for r.Next() {
|
|
@@ -65,15 +78,19 @@ func SendMsg(this messageclient.SendMsgRequest) (int64, string) {
|
|
}
|
|
}
|
|
_, err = entity.Mysql11.Exec(sql3)
|
|
_, err = entity.Mysql11.Exec(sql3)
|
|
if err == nil {
|
|
if err == nil {
|
|
- MsgCountAdd(this.ReceiveUserId, strconv.Itoa(int(this.MsgType)))
|
|
|
|
|
|
+ MsgCountAdd(this.ReceiveUserId, strconv.Itoa(int(this.MsgType)), this.Appid)
|
|
return 1, "消息发送成功"
|
|
return 1, "消息发送成功"
|
|
}
|
|
}
|
|
return 0, "消息发送失败"
|
|
return 0, "消息发送失败"
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+<<<<<<< HEAD
|
|
func FindUserMsg(this messageclient.FindUserMsgReq) messageclient.FindUserMsgRes {
|
|
func FindUserMsg(this messageclient.FindUserMsgReq) messageclient.FindUserMsgRes {
|
|
//orm := entity.Engine
|
|
//orm := entity.Engine
|
|
//var messages []*entity.Message
|
|
//var messages []*entity.Message
|
|
|
|
+=======
|
|
|
|
+func FindUserMsg(this message.FindUserMsgReq, isClean bool) message.FindUserMsgRes {
|
|
|
|
+>>>>>>> master
|
|
var err error
|
|
var err error
|
|
var count int64
|
|
var count int64
|
|
cquery := map[string]interface{}{
|
|
cquery := map[string]interface{}{
|
|
@@ -87,9 +104,28 @@ func FindUserMsg(this messageclient.FindUserMsgReq) messageclient.FindUserMsgRes
|
|
if this.Read != -1 {
|
|
if this.Read != -1 {
|
|
cquery["isRead"] = this.Read
|
|
cquery["isRead"] = this.Read
|
|
}
|
|
}
|
|
|
|
+<<<<<<< HEAD
|
|
count = entity.Mysql.Count("message", cquery)
|
|
count = entity.Mysql.Count("message", cquery)
|
|
//count, err = orm.Table("message").Where("((receive_userid = ? and send_userid = ?) or (receive_userid = ? and send_userid = ?)) and isdel = ? and appid = ?"+q, this.UserId, this.ReceiveUserId, this.ReceiveUserId, this.UserId, 1, this.Appid).Count()
|
|
//count, err = orm.Table("message").Where("((receive_userid = ? and send_userid = ?) or (receive_userid = ? and send_userid = ?)) and isdel = ? and appid = ?"+q, this.UserId, this.ReceiveUserId, this.ReceiveUserId, this.UserId, 1, this.Appid).Count()
|
|
data := messageclient.FindUserMsgRes{}
|
|
data := messageclient.FindUserMsgRes{}
|
|
|
|
+=======
|
|
|
|
+ data := message.FindUserMsgRes{}
|
|
|
|
+ if this.PageSize == 5 {
|
|
|
|
+ //从缓存里边取数据
|
|
|
|
+ pc_a, err := entity.GetData(this.UserId)
|
|
|
|
+ if err == nil && pc_a != nil {
|
|
|
|
+ // 缓存有值
|
|
|
|
+ if !isClean {
|
|
|
|
+ data.Code = 1
|
|
|
|
+ data.Message = "查询成功"
|
|
|
|
+ data.Data = pc_a.Data
|
|
|
|
+ data.Count = pc_a.Count
|
|
|
|
+ return data
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ count = entity.Mysql.Count("message", cquery)
|
|
|
|
+>>>>>>> master
|
|
if count > 0 {
|
|
if count > 0 {
|
|
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("数据:", res)
|
|
//log.Println("数据:", res)
|
|
@@ -117,6 +153,13 @@ func FindUserMsg(this messageclient.FindUserMsgReq) messageclient.FindUserMsgRes
|
|
}
|
|
}
|
|
}
|
|
}
|
|
data.Count = count
|
|
data.Count = count
|
|
|
|
+ if this.PageSize == 5 {
|
|
|
|
+ redisData := map[string]interface{}{
|
|
|
|
+ "count": count,
|
|
|
|
+ "data": data.Data,
|
|
|
|
+ }
|
|
|
|
+ entity.SetData(this.UserId, redisData, entity.SurvivalTime)
|
|
|
|
+ }
|
|
if err != nil {
|
|
if err != nil {
|
|
data.Code = 0
|
|
data.Code = 0
|
|
data.Message = "查询失败"
|
|
data.Message = "查询失败"
|
|
@@ -141,15 +184,31 @@ func ClassCountUnread(msgType int, userId string, appId string) (int64, string,
|
|
}
|
|
}
|
|
|
|
|
|
// MsgCountAdd 消息未读数量加1
|
|
// MsgCountAdd 消息未读数量加1
|
|
-func MsgCountAdd(userId, msgType string) bool {
|
|
|
|
|
|
+func MsgCountAdd(userId, msgType, appId string) bool {
|
|
keyString := fmt.Sprintf(MsgCountKey, userId, msgType)
|
|
keyString := fmt.Sprintf(MsgCountKey, userId, msgType)
|
|
in := redis.Incr(redisModule, keyString)
|
|
in := redis.Incr(redisModule, keyString)
|
|
|
|
+ FindUserMsg(message.FindUserMsgReq{
|
|
|
|
+ UserId: userId,
|
|
|
|
+ Appid: appId,
|
|
|
|
+ OffSet: 1,
|
|
|
|
+ PageSize: 5,
|
|
|
|
+ MsgType: -1,
|
|
|
|
+ Read: 0,
|
|
|
|
+ }, true)
|
|
return in > 0
|
|
return in > 0
|
|
}
|
|
}
|
|
|
|
|
|
// MsgCountMinusOne 根据消息类型未读消息数量减1
|
|
// MsgCountMinusOne 根据消息类型未读消息数量减1
|
|
-func MsgCountMinusOne(userId, msgType string) bool {
|
|
|
|
|
|
+func MsgCountMinusOne(userId, msgType, appId string) bool {
|
|
keyString := fmt.Sprintf(MsgCountKey, userId, msgType)
|
|
keyString := fmt.Sprintf(MsgCountKey, userId, msgType)
|
|
|
|
+ FindUserMsg(message.FindUserMsgReq{
|
|
|
|
+ UserId: userId,
|
|
|
|
+ Appid: appId,
|
|
|
|
+ OffSet: 1,
|
|
|
|
+ PageSize: 5,
|
|
|
|
+ MsgType: -1,
|
|
|
|
+ Read: 0,
|
|
|
|
+ }, true)
|
|
if redis.GetInt(redisModule, keyString) <= 0 {
|
|
if redis.GetInt(redisModule, keyString) <= 0 {
|
|
return redis.Put(redisModule, keyString, 0, -1)
|
|
return redis.Put(redisModule, keyString, 0, -1)
|
|
}
|
|
}
|
|
@@ -158,9 +217,18 @@ func MsgCountMinusOne(userId, msgType string) bool {
|
|
}
|
|
}
|
|
|
|
|
|
// MsgCountZero 把该消息类型未读数量置0
|
|
// MsgCountZero 把该消息类型未读数量置0
|
|
-func MsgCountZero(userId, msgType string) bool {
|
|
|
|
|
|
+func MsgCountZero(userId, msgType, appId string) bool {
|
|
keyString := fmt.Sprintf(MsgCountKey, userId, msgType)
|
|
keyString := fmt.Sprintf(MsgCountKey, userId, msgType)
|
|
- return redis.Put(redisModule, keyString, 0, -1)
|
|
|
|
|
|
+ fool := redis.Put(redisModule, keyString, 0, -1)
|
|
|
|
+ FindUserMsg(message.FindUserMsgReq{
|
|
|
|
+ UserId: userId,
|
|
|
|
+ Appid: appId,
|
|
|
|
+ OffSet: 1,
|
|
|
|
+ PageSize: 5,
|
|
|
|
+ MsgType: -1,
|
|
|
|
+ Read: 0,
|
|
|
|
+ }, true)
|
|
|
|
+ return fool
|
|
}
|
|
}
|
|
|
|
|
|
func MultSave(this messageclient.MultipleSaveMsgReq) (int64, string) {
|
|
func MultSave(this messageclient.MultipleSaveMsgReq) (int64, string) {
|
|
@@ -197,13 +265,13 @@ func MultSave(this messageclient.MultipleSaveMsgReq) (int64, string) {
|
|
errCount++
|
|
errCount++
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
- ok1 := MsgCountAdd(v, strconv.Itoa(int(this.MsgType)))
|
|
|
|
|
|
+ ok1 := MsgCountAdd(v, strconv.Itoa(int(this.MsgType)), this.Appid)
|
|
log.Println("存redis:", ok1)
|
|
log.Println("存redis:", ok1)
|
|
} else {
|
|
} else {
|
|
in := entity.Mysql.InsertBySql(sql3)
|
|
in := entity.Mysql.InsertBySql(sql3)
|
|
logx.Info("插入消息返回 in1 id:", in)
|
|
logx.Info("插入消息返回 in1 id:", in)
|
|
if in > -1 {
|
|
if in > -1 {
|
|
- ok := MsgCountAdd(v, strconv.Itoa(int(this.MsgType)))
|
|
|
|
|
|
+ ok := MsgCountAdd(v, strconv.Itoa(int(this.MsgType)), this.Appid)
|
|
log.Println("存redis:", ok)
|
|
log.Println("存redis:", ok)
|
|
} else {
|
|
} else {
|
|
errCount++
|
|
errCount++
|