|
@@ -11,6 +11,7 @@ import (
|
|
|
"log"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
+ "sync"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
@@ -207,13 +208,24 @@ func MsgCountZero(userId, msgType, appId string) bool {
|
|
|
func MultSave(this message.MultipleSaveMsgReq) (int64, string) {
|
|
|
userIdArr := strings.Split(this.UserIds, ",")
|
|
|
userNameArr := strings.Split(this.UserNames, ",")
|
|
|
- if len(userIdArr) > 0 {
|
|
|
- var errCount int64
|
|
|
- for k, v := range userIdArr {
|
|
|
- if v == "" {
|
|
|
- return errCount, "调用结束"
|
|
|
- }
|
|
|
- userName := userNameArr[k]
|
|
|
+ if len(userIdArr) == 0 {
|
|
|
+ return 0, "无效的用户id"
|
|
|
+ }
|
|
|
+ wg := &sync.WaitGroup{}
|
|
|
+ for i := 0; i < len(userIdArr); i++ {
|
|
|
+
|
|
|
+ v := userIdArr[i]
|
|
|
+ if v == "" {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ userName := userNameArr[i]
|
|
|
+ wg.Add(1)
|
|
|
+ entity.SaveConcurrencyChan <- 1
|
|
|
+ go func() {
|
|
|
+ defer func() {
|
|
|
+ <-entity.SaveConcurrencyChan
|
|
|
+ wg.Done()
|
|
|
+ }()
|
|
|
//消息数组
|
|
|
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) values ("%s",'%s','%s','%s','%s','%s','%s',%d,'%s',0,'%s',0,1,%d,%d,'%s');`
|
|
@@ -234,24 +246,22 @@ func MultSave(this message.MultipleSaveMsgReq) (int64, string) {
|
|
|
return in1 > -1 && in2 > -1 && in3 > -1
|
|
|
})
|
|
|
logx.Info("执行事务是否成功:", ok)
|
|
|
- if !ok {
|
|
|
- errCount++
|
|
|
- continue
|
|
|
+ if ok {
|
|
|
+ ok1 := MsgCountAdd(v, strconv.Itoa(int(this.MsgType)), this.Appid)
|
|
|
+ log.Println("存redis:", ok1)
|
|
|
}
|
|
|
- ok1 := MsgCountAdd(v, strconv.Itoa(int(this.MsgType)), this.Appid)
|
|
|
- log.Println("存redis:", ok1)
|
|
|
} else {
|
|
|
in := entity.Mysql.InsertBySql(sql3)
|
|
|
logx.Info("插入消息返回 in1 id:", in)
|
|
|
if in > -1 {
|
|
|
ok := MsgCountAdd(v, strconv.Itoa(int(this.MsgType)), this.Appid)
|
|
|
log.Println("存redis:", ok)
|
|
|
- } else {
|
|
|
- errCount++
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- return errCount, "发送成功"
|
|
|
+ }()
|
|
|
+
|
|
|
}
|
|
|
- return 0, "没有要发送的用户"
|
|
|
+ wg.Wait()
|
|
|
+ return 0, ""
|
|
|
+
|
|
|
}
|