sendMsg.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. package common
  2. import (
  3. "fmt"
  4. "log"
  5. "strconv"
  6. "strings"
  7. "sync"
  8. "time"
  9. "app.yhyue.com/moapp/MessageCenter/entity"
  10. "app.yhyue.com/moapp/MessageCenter/rpc/type/message"
  11. "app.yhyue.com/moapp/MessageCenter/util"
  12. "app.yhyue.com/moapp/jybase/common"
  13. "app.yhyue.com/moapp/jybase/redis"
  14. "github.com/zeromicro/go-zero/core/logx"
  15. )
  16. // 类型的顺序
  17. const order = "1,4"
  18. const MsgCountKey = "count_%s_%d" //redis 消息未读数量 Count.用户id.消息类型=数量
  19. const MsgClassCountKey = "msg_class_count_%s_%d" //redis 用户消息class分类消息数量
  20. const redisModule = "msgCount"
  21. func FindUserMsg(this message.FindUserMsgReq, isClean bool) message.FindUserMsgRes {
  22. var err error
  23. var count int64
  24. cquery := map[string]interface{}{
  25. "receive_userid": this.UserId,
  26. "isdel": 1,
  27. "appid": this.Appid,
  28. }
  29. if this.MsgType > 0 {
  30. cquery["group_id"] = this.MsgType
  31. }
  32. if this.Read != -1 {
  33. cquery["isRead"] = this.Read
  34. }
  35. count = entity.Mysql.Count("message", cquery)
  36. data := message.FindUserMsgRes{}
  37. if this.PageSize == 5 {
  38. //从缓存里边取数据
  39. pc_a, err := entity.GetData(this.UserId)
  40. if err == nil && pc_a != nil {
  41. // 缓存有值
  42. if !isClean {
  43. data.Code = 1
  44. data.Message = "查询成功"
  45. data.Data = pc_a.Data
  46. data.Count = pc_a.Count
  47. return data
  48. }
  49. }
  50. }
  51. count = entity.Mysql.Count("message", cquery)
  52. if count > 0 {
  53. res := entity.Mysql.Find("message", cquery, "", "createtime desc", (int(this.OffSet)-1)*int(this.PageSize), int(this.PageSize))
  54. //log.Println("数据:", res)
  55. if res != nil && len(*res) > 0 {
  56. for _, v := range *res {
  57. _id := util.Int64All(v["id"])
  58. id := strconv.FormatInt(_id, 10)
  59. data.Data = append(data.Data, &message.Messages{
  60. Id: id,
  61. Appid: util.ObjToString(v["appId"]),
  62. ReceiveUserId: util.ObjToString(v["receive_userid"]),
  63. ReceiveName: util.ObjToString(v["receive_name"]),
  64. SendUserId: util.ObjToString(v["send_userid"]),
  65. SendName: util.ObjToString(v["send_name"]),
  66. Createtime: util.ObjToString(v["createtime"]),
  67. Title: util.ObjToString(v["title"]),
  68. MsgType: int64(util.IntAll(v["group_id"])),
  69. Link: util.ObjToString(v["link"]),
  70. CiteId: util.Int64All(v["cite_id"]),
  71. Content: util.ObjToString(v["content"]),
  72. IsRead: util.Int64All(v["isRead"]),
  73. MsgLogId: util.Int64All(v["msg_log_id"]),
  74. })
  75. }
  76. }
  77. }
  78. data.Count = count
  79. if this.PageSize == 5 {
  80. redisData := map[string]interface{}{
  81. "count": count,
  82. "data": data.Data,
  83. }
  84. entity.SetData(this.UserId, redisData, entity.SurvivalTime)
  85. }
  86. if err != nil {
  87. data.Code = 0
  88. data.Message = "查询失败"
  89. } else {
  90. data.Code = 1
  91. data.Message = "查询成功"
  92. }
  93. return data
  94. }
  95. func UserMsgList(this *message.UserMsgListReq) *message.UserMsgList {
  96. var (
  97. unread, count int64
  98. )
  99. m := &MessageService{}
  100. data := new(message.UserMsgList)
  101. if !this.IsMsgList && !this.IsColumnNewMsg && !this.IsColumn { //消息未读数统计
  102. //获取总未读数 初始化
  103. _, unread = m.CountUnread(this.UserId, true)
  104. if this.IsContainLetter { //私信统计
  105. unread += unreadMsg(this)
  106. }
  107. data.Unread = unread
  108. return data
  109. }
  110. cquery := map[string]interface{}{
  111. "receive_userid": this.UserId,
  112. "isdel": 1,
  113. "appid": this.Appid,
  114. }
  115. // p436 细化分类时需要用msg_type 进行查询
  116. if this.MsgType > 0 && this.IsClassSearch {
  117. cquery["msg_type"] = this.MsgType
  118. } else if this.MsgType > 0 {
  119. cquery["group_id"] = this.MsgType
  120. }
  121. if this.Read != -1 {
  122. cquery["isRead"] = this.Read
  123. }
  124. //获取栏目下的数据
  125. sData := make(map[string][]*message.Messages)
  126. t := time.Now()
  127. if this.IsColumnNewMsg && this.SortSize > 0 {
  128. var sortData *[]map[string]interface{}
  129. if this.IsClassSearch { // p436 增加
  130. sortDataQ := fmt.Sprintf(`SELECT title,createtime,msg_type as group_id ,id FROM (
  131. SELECT title,createtime,msg_type,id, ROW_NUMBER() OVER (PARTITION BY msg_type, receive_userid ORDER BY createtime DESC) AS row_num
  132. FROM message
  133. WHERE receive_userid = '%s' and isdel = 1 and appid = %s and group_id=%d
  134. ) AS message_ranked
  135. WHERE row_num <=%d;`, this.UserId, this.Appid, this.MsgType, this.SortSize)
  136. sortData = entity.Mysql.SelectBySql(sortDataQ)
  137. } else {
  138. sortData = entity.Mysql.SelectBySql(fmt.Sprintf(`SELECT title,createtime,group_id,id FROM (
  139. SELECT title,createtime,group_id,id, ROW_NUMBER() OVER (PARTITION BY group_id, receive_userid ORDER BY createtime DESC) AS row_num
  140. FROM message
  141. WHERE receive_userid = '%s' and isdel = 1 and appid = %s
  142. ) AS message_ranked
  143. WHERE row_num <=%d;`, this.UserId, this.Appid, this.SortSize))
  144. }
  145. log.Println("消息列表耗时1:", time.Since(t))
  146. if sortData != nil {
  147. for _, v := range *sortData {
  148. _id := util.Int64All(v["id"])
  149. id := strconv.FormatInt(_id, 10)
  150. var msg = message.Messages{
  151. Id: id,
  152. Createtime: common.InterfaceToStr(v["createtime"]),
  153. Title: common.InterfaceToStr(v["title"]),
  154. MsgType: int64(util.IntAll(v["group_id"])),
  155. }
  156. if sData[common.InterfaceToStr(v["group_id"])] == nil {
  157. sData[common.InterfaceToStr(v["group_id"])] = []*message.Messages{&msg}
  158. } else {
  159. sData[common.InterfaceToStr(v["group_id"])] = append(sData[common.InterfaceToStr(v["group_id"])], &msg)
  160. }
  161. }
  162. }
  163. }
  164. // 消息栏目下的最新消息
  165. var columnData []*message.AllSortData
  166. if this.IsColumn && this.MsgType > 0 && this.IsClassSearch {
  167. // p436 处理消息细分分类要返回的数据
  168. // 获取小分类下的未读数
  169. sortUnread, _ := m.CountClassUnread(this.UserId, this.MsgType)
  170. columnArr := []entity.MsgClass{}
  171. if !this.IsColumnNewMsg { // 用于区分分类列表页和分类详情页 根据不同情况
  172. columnArr = append(columnArr, entity.ClassMap[this.MsgType])
  173. } else {
  174. columnArr = entity.ClassSearchMap[this.MsgType]
  175. }
  176. for i := 0; i < len(columnArr); i++ {
  177. tmp := columnArr[i]
  178. var column message.AllSortData
  179. column.Name = tmp.Name
  180. column.Img = fmt.Sprintf("/common-module/msgCenter/%s.png", tmp.Img)
  181. column.MsgType = tmp.MsgType
  182. // 消息未读数
  183. msgType := common.InterfaceToStr(tmp.MsgType)
  184. column.UnreadMessages = sortUnread[msgType]
  185. unread += sortUnread[msgType]
  186. column.Data = sData[msgType]
  187. column.IsClassSearch = true
  188. columnData = append(columnData, &column)
  189. }
  190. // 未读数量
  191. } else if this.IsColumn {
  192. //获取所有分类未读数 不初始化
  193. sortUnread, _ := m.CountUnread(this.UserId, false)
  194. for _, v := range entity.MessageColumn {
  195. var column message.AllSortData
  196. column.Name = common.InterfaceToStr(v["name"])
  197. column.Img = fmt.Sprintf("/common-module/msgCenter/%s.png", common.InterfaceToStr(v["img"]))
  198. column.MsgType = common.Int64All(v["group_id"])
  199. if column.Name == "私信" {
  200. column.UnreadMessages = unreadMsg(this)
  201. } else if common.IntAll(v["group_id"]) > 0 {
  202. //消息未读数
  203. msgType := common.InterfaceToStr(v["group_id"])
  204. column.UnreadMessages = sortUnread[msgType]
  205. unread += sortUnread[msgType]
  206. column.Data = sData[msgType]
  207. }
  208. // p436 该groupId属于展示细化分类的 如待办 点击待办进入到待参加会议、待处理任务中间列表页等
  209. // 该返回值用于前端后续传参使用
  210. if _, ok := entity.ClassSearchMap[column.MsgType]; ok {
  211. column.IsClassSearch = true
  212. }
  213. columnData = append(columnData, &column)
  214. }
  215. }
  216. data.SortData = columnData
  217. count = entity.Mysql.Count("message", cquery)
  218. if this.IsMsgList {
  219. if count > 0 {
  220. if this.OffSet <= 0 {
  221. this.OffSet = 1
  222. }
  223. res := entity.Mysql.Find("message", cquery, "", "createtime desc", (int(this.OffSet)-1)*int(this.PageSize), int(this.PageSize))
  224. log.Println("消息列表耗时3:", time.Since(t))
  225. if res != nil && len(*res) > 0 {
  226. for _, v := range *res {
  227. _id := util.Int64All(v["id"])
  228. id := strconv.FormatInt(_id, 10)
  229. tmpMsg := &message.Messages{
  230. Id: id,
  231. Appid: common.InterfaceToStr(v["appId"]),
  232. ReceiveUserId: common.InterfaceToStr(v["receive_userid"]),
  233. ReceiveName: common.InterfaceToStr(v["receive_name"]),
  234. SendUserId: common.InterfaceToStr(v["send_userid"]),
  235. SendName: common.InterfaceToStr(v["send_name"]),
  236. Createtime: common.InterfaceToStr(v["createtime"]),
  237. Title: common.InterfaceToStr(v["title"]),
  238. MsgType: int64(util.IntAll(v["group_id"])),
  239. Link: common.InterfaceToStr(v["link"]),
  240. CiteId: util.Int64All(v["cite_id"]),
  241. Content: common.InterfaceToStr(v["content"]),
  242. IsRead: util.Int64All(v["isRead"]),
  243. MsgLogId: util.Int64All(v["msg_log_id"]),
  244. }
  245. if this.IsClassSearch {
  246. tmpMsg.MsgType = int64(util.IntAll(v["msg_type"]))
  247. }
  248. data.Data = append(data.Data, tmpMsg)
  249. }
  250. }
  251. }
  252. }
  253. data.Count = count
  254. if this.Read == 0 {
  255. unread = count
  256. if this.IsContainLetter { //是否需要统计私信未读数
  257. unread += unreadMsg(this)
  258. }
  259. }
  260. data.Unread = unread
  261. return data
  262. }
  263. func unreadMsg(this *message.UserMsgListReq) int64 {
  264. if this.PositionId <= 0 {
  265. return 0
  266. }
  267. querySql := fmt.Sprintf("SELECT b.*,(SELECT SUM( a.unread) FROM %s a "+
  268. "LEFT JOIN %s b ON a.message_id = b.id "+
  269. "WHERE a.unread > 0 "+
  270. "AND ( a.my_position_id = %d OR a.user_id = %d )) AS unread "+
  271. "FROM %s a "+
  272. "LEFT JOIN %s b ON a.message_id = b.id "+
  273. "WHERE a.unread > 0 "+
  274. "AND ( a.my_position_id = %d OR a.user_id = %d ) "+
  275. "ORDER BY a.TIMESTAMP DESC LIMIT 0,1", "socialize_summary", "socialize_message", this.PositionId, this.NewUserId,
  276. "socialize_summary", "socialize_message", this.PositionId, this.NewUserId)
  277. log.Println("查询sql", querySql)
  278. msgUnread := entity.BaseMysql.SelectBySql(querySql)
  279. if msgUnread != nil && len(*msgUnread) > 0 {
  280. return common.Int64All((*msgUnread)[0]["unread"])
  281. }
  282. return 0
  283. }
  284. func UserUnreadMsgList(this *message.UserUnreadMsgListReq) (int64, []*message.Messages) {
  285. count := 0
  286. data := []*message.Messages{}
  287. types := entity.Mysql.Find("message_group", map[string]interface{}{}, `"group_id"`, "", -1, -1)
  288. if types != nil && len(*types) > 0 {
  289. for _, v := range *types {
  290. key := fmt.Sprintf(MsgCountKey, this.UserId, util.IntAll(v["group_id"]))
  291. if exists, _ := redis.Exists(redisModule, key); exists {
  292. count += redis.GetInt(redisModule, key)
  293. }
  294. }
  295. }
  296. if this.IsNeedData == 1 && count > 0 {
  297. query := map[string]interface{}{
  298. "receive_userid": this.UserId,
  299. "isdel": 1,
  300. "appid": this.Appid,
  301. "isRead": 0,
  302. }
  303. res := entity.Mysql.Find("message", query, "", "createtime desc", (int(this.OffSet)-1)*int(this.PageSize), int(this.PageSize))
  304. if res != nil && len(*res) > 0 {
  305. for _, val := range *res {
  306. _id := util.Int64All(val["id"])
  307. id := strconv.FormatInt(_id, 10)
  308. links4 := common.InterfaceToStr(val["link"])
  309. link4, androidUrl4, iosUrl4, weChatUrl4 := util.LinkSplit(links4)
  310. url := map[string]string{
  311. "androidUrl": androidUrl4,
  312. "iosUrl": iosUrl4,
  313. "weChatUrl": weChatUrl4,
  314. }
  315. data = append(data, &message.Messages{
  316. Id: id,
  317. Appid: common.InterfaceToStr(val["appid"]),
  318. ReceiveUserId: common.InterfaceToStr(val["receive_userid"]),
  319. ReceiveName: common.InterfaceToStr(val["receive_name"]),
  320. SendUserId: common.InterfaceToStr(val["send_userid"]),
  321. SendName: common.InterfaceToStr(val["send_name"]),
  322. Createtime: common.InterfaceToStr(val["createtime"]),
  323. Title: common.InterfaceToStr(val["title"]),
  324. MsgType: common.Int64All(val["group_id"]),
  325. Link: link4,
  326. CiteId: common.Int64All(val["cite_id"]),
  327. Content: common.InterfaceToStr(val["content"]),
  328. IsRead: common.Int64All(val["isRead"]),
  329. MsgLogId: common.Int64All(val["msg_log_id"]),
  330. Url: url,
  331. })
  332. }
  333. }
  334. }
  335. return util.Int64All(count), data
  336. }
  337. func MessageGetLast(this *message.UserMsgListReq) *message.Messages {
  338. if !this.IsMsgList && !this.IsColumnNewMsg && !this.IsColumn {
  339. return nil
  340. }
  341. query := map[string]interface{}{
  342. "receive_userid": this.UserId,
  343. "isdel": 1,
  344. "appid": this.Appid,
  345. "isRead": 0,
  346. "group_id": 1,
  347. }
  348. lastMsg := entity.Mysql.FindOne("message", query, "", "createtime desc")
  349. if lastMsg != nil && len(*lastMsg) > 0 {
  350. _id := util.Int64All((*lastMsg)["id"])
  351. id := strconv.FormatInt(_id, 10)
  352. msg := message.Messages{
  353. Id: id,
  354. Appid: common.InterfaceToStr((*lastMsg)["appid"]),
  355. ReceiveUserId: common.InterfaceToStr((*lastMsg)["receive_userid"]),
  356. ReceiveName: common.InterfaceToStr((*lastMsg)["receive_name"]),
  357. SendUserId: common.InterfaceToStr((*lastMsg)["send_userid"]),
  358. SendName: common.InterfaceToStr((*lastMsg)["send_name"]),
  359. Createtime: common.InterfaceToStr((*lastMsg)["createtime"]),
  360. Title: common.InterfaceToStr((*lastMsg)["title"]),
  361. MsgType: common.Int64All((*lastMsg)["group_id"]),
  362. Link: common.InterfaceToStr((*lastMsg)["link"]),
  363. CiteId: common.Int64All((*lastMsg)["cite_id"]),
  364. Content: common.InterfaceToStr((*lastMsg)["content"]),
  365. IsRead: common.Int64All((*lastMsg)["isRead"]),
  366. MsgLogId: common.Int64All((*lastMsg)["msg_log_id"]),
  367. }
  368. return &msg
  369. }
  370. return nil
  371. }
  372. // MsgCountAdd 消息未读数量加1
  373. func MsgCountAdd(userId, appId string, msgType int64, msgClassType int64) bool {
  374. keyString := fmt.Sprintf(MsgCountKey, userId, msgType)
  375. classKeyString := fmt.Sprintf(MsgClassCountKey, userId, msgClassType)
  376. if exist, _ := redis.Exists(redisModule, classKeyString); exist {
  377. redis.Incr(redisModule, classKeyString)
  378. }
  379. exists, _ := redis.Exists(redisModule, keyString)
  380. if exists {
  381. in := redis.Incr(redisModule, keyString)
  382. FindUserMsg(message.FindUserMsgReq{
  383. UserId: userId,
  384. Appid: appId,
  385. OffSet: 1,
  386. PageSize: 5,
  387. MsgType: -1,
  388. Read: 0,
  389. }, true)
  390. return in > 0
  391. }
  392. return true
  393. }
  394. // MsgCountMinusOne 根据消息类型未读消息数量减1
  395. func MsgCountMinusOne(userId, appId string, msgType int64, msgClassType int64) bool {
  396. classKeyString := fmt.Sprintf(MsgClassCountKey, userId, msgClassType)
  397. if exist, _ := redis.Exists(redisModule, classKeyString); exist {
  398. if redis.GetInt(redisModule, classKeyString) > 0 {
  399. redis.Decrby(redisModule, classKeyString, 1)
  400. }
  401. }
  402. keyString := fmt.Sprintf(MsgCountKey, userId, msgType)
  403. exists, _ := redis.Exists(redisModule, keyString)
  404. if exists {
  405. FindUserMsg(message.FindUserMsgReq{
  406. UserId: userId,
  407. Appid: appId,
  408. OffSet: 1,
  409. PageSize: 5,
  410. MsgType: -1,
  411. Read: 0,
  412. }, true)
  413. if redis.GetInt(redisModule, keyString) <= 0 {
  414. return true
  415. }
  416. in := redis.Decrby(redisModule, keyString, 1)
  417. return in > 0
  418. }
  419. return true
  420. }
  421. // MsgCountZero 把该消息类型未读数量置0
  422. func MsgCountZero(userId, appId string, msgType int64) bool {
  423. if msgType > 0 && msgType < 999 { //全部私信不统计
  424. keyString := fmt.Sprintf(MsgCountKey, userId, msgType)
  425. fool := redis.Put(redisModule, keyString, 0, -1)
  426. FindUserMsg(message.FindUserMsgReq{
  427. UserId: userId,
  428. Appid: appId,
  429. OffSet: 1,
  430. PageSize: 5,
  431. MsgType: -1,
  432. Read: 0,
  433. }, true)
  434. return fool
  435. }
  436. return true
  437. }
  438. func MultSave(this message.MultipleSaveMsgReq) (int64, string) {
  439. userIdArr := strings.Split(this.UserIds, ",")
  440. userNameArr := strings.Split(this.UserNames, ",")
  441. positionIdArr := strings.Split(this.PositionIds, ",")
  442. if len(userIdArr) == 0 {
  443. return 0, "无效的用户id"
  444. }
  445. wg := &sync.WaitGroup{}
  446. var group_id int
  447. class := entity.Mysql.FindOne("message_class", map[string]interface{}{"msg_type": this.MsgType}, "group_id", "")
  448. if class != nil && len(*class) > 0 {
  449. group_id = util.IntAll((*class)["group_id"])
  450. }
  451. for i := 0; i < len(userIdArr); i++ {
  452. if userIdArr[i] == "" {
  453. continue
  454. }
  455. name := userNameArr[i]
  456. wg.Add(1)
  457. entity.SaveConcurrencyChan <- 1
  458. var positionId int64
  459. if len(positionIdArr) == len(userIdArr) {
  460. positionId = common.Int64All(positionIdArr[i])
  461. }
  462. go func(v, userName string, positionId int64) {
  463. defer func() {
  464. <-entity.SaveConcurrencyChan
  465. wg.Done()
  466. }()
  467. //消息数组
  468. nTime := time.Now().Format("2006-01-02 15:04:05")
  469. //c := entity.Mysql.Count("conversation", map[string]interface{}{"receive_id": v, "send_id": this.SendUserId})
  470. 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,group_id,position_id) values ("%s",'%s','%s','%s','%s','%s','%s',%d,'%s',0,'%s',0,1,%d,%d,'%s',%d,?);`
  471. sql3 = fmt.Sprintf(sql3, this.Appid, v, userName, this.SendUserId, this.SendName, this.Title, this.Content, this.MsgType, this.Link, nTime, this.MsgLogId, this.ShowBuoy, this.ShowContent, group_id)
  472. var in int64
  473. /*if c <= 0 {
  474. 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');`
  475. sql1 = fmt.Sprintf(sql1, this.Appid, this.SendUserId, v, userName, this.SendUserId, this.SendName, nTime)
  476. //插入会话表
  477. in1 := entity.Mysql.InsertBySql(sql1)
  478. sql2 := `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');`
  479. sql2 = fmt.Sprintf(sql2, this.Appid, v, this.SendUserId, this.SendName, v, userName, nTime)
  480. in2 := entity.Mysql.InsertBySql(sql2)
  481. //插入消息表
  482. in = entity.Mysql.InsertBySql(sql3, common.If(positionId != 0, positionId, nil))
  483. logx.Info(in1, in2, in)
  484. if in1 > -1 && in2 > -1 && in > -1 {
  485. ok1 := MsgCountAdd(v, this.Appid, this.MsgType)
  486. if !ok1 {
  487. log.Println("存redis:", ok1, v)
  488. }
  489. }
  490. } else {*/
  491. in = entity.Mysql.InsertBySql(sql3, common.If(positionId != 0, positionId, nil))
  492. logx.Info("插入消息返回 in1 id:", in, "消息类型:", this.MsgType, "用户id:", v)
  493. if in > -1 {
  494. ok := MsgCountAdd(v, this.Appid, util.Int64All(group_id), this.MsgType)
  495. if !ok {
  496. log.Println("存redis:", ok, v)
  497. }
  498. }
  499. //}
  500. if in > -1 {
  501. //发送消息成功,推送微信、app
  502. pushConfig, err := GetWxTmplConfig(this.MsgType)
  503. if err != nil {
  504. logx.Error(fmt.Sprintf("SendWxTmplMsg uId %s Error %s", v, err.Error()))
  505. }
  506. p := &WxTmplPush{
  507. Config: pushConfig,
  508. CustomWxTpl: this.CustomWxTpl,
  509. }
  510. p.MgoId = v
  511. if this.MsgType == 10 {
  512. this.Title = this.ProductName
  513. this.Content = this.OrderId
  514. nTime = this.OrderMoney
  515. }
  516. // 消息模版 工单类型 {{thing19.DATA}} 工单标题 {{thing6.DATA}} 项目名称 {{thing13.DATA}} 服务时间 {{time25.DATA}} 服务地址 {{thing26.DATA}}
  517. if this.MsgType != 1 && this.MsgType != 10 {
  518. err = p.SendMsg(this.WxPushUrl, this.Title, this.Content, nTime, this.Row4)
  519. if err != nil {
  520. logx.Error(fmt.Sprintf("SendWxTmplMsg uId %s Error %s", v, err.Error()))
  521. } else {
  522. logx.Infof("SendWxTmplMsg uId success %s ", v)
  523. }
  524. }
  525. if this.MsgType == 1 {
  526. mst := new(WxTmplConfig)
  527. mst.Switch = AppPushMsgType[group_id]
  528. p.Config = mst
  529. }
  530. //app推送
  531. if this.MsgType != 10 {
  532. uData := p.GetUserPushInfo()
  533. category := ""
  534. if this.SendUserId == "cbgl" {
  535. category = "服务通知_工作事项"
  536. }
  537. if err = AppPushMsg(uData, AppPushMsgType[group_id], this.AppPushUrl, this.Title, this.Content, this.MsgType, category); err != nil {
  538. logx.Error(fmt.Sprintf("SendAppMsg uId %s Error %s", v, err.Error()))
  539. }
  540. }
  541. }
  542. }(userIdArr[i], name, positionId)
  543. }
  544. wg.Wait()
  545. return 0, ""
  546. }