getBuoyMsg.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. package common
  2. import (
  3. "app.yhyue.com/moapp/MessageCenter/entity"
  4. "app.yhyue.com/moapp/MessageCenter/rpc/type/message"
  5. "app.yhyue.com/moapp/MessageCenter/util"
  6. qutil "app.yhyue.com/moapp/jybase/common"
  7. "app.yhyue.com/moapp/jybase/redis"
  8. "context"
  9. "fmt"
  10. "log"
  11. "strconv"
  12. "strings"
  13. )
  14. func FindUserBuoyMsg(this *message.FindUserBuoyMsgReq) *message.FindUserBuoyMsgRes {
  15. var err error
  16. data := message.FindUserBuoyMsgRes{}
  17. res := entity.Mysql.SelectBySql(fmt.Sprintf(`SELECT * FROM message WHERE receive_userid = "%s" and isdel = 1 and appid = %s and isRead =0 and show_buoy = 1 and show_content != "" ORDER BY createtime DESC LIMIT 0,%d`, this.UserId, this.Appid, int(this.PageSize)))
  18. //log.Println("数据:", res)
  19. if res != nil && len(*res) > 0 {
  20. for _, v := range *res {
  21. _id := util.Int64All(v["id"])
  22. id := strconv.FormatInt(_id, 10)
  23. links2 := util.ObjToString((v["link"]))
  24. link2, androidUrl2, iosUrl2, weChatUrl2 := LinkSplit(links2)
  25. data.Data = append(data.Data, &message.BuoyMessages{
  26. Id: id,
  27. BuoyDetail: util.ObjToString(v["show_content"]),
  28. PcUrl: link2,
  29. AndroidUrl: androidUrl2,
  30. IosUrl: iosUrl2,
  31. WeChatUrl: weChatUrl2,
  32. })
  33. }
  34. }
  35. if err == nil {
  36. data.Code = 0
  37. data.Message = "查询成功"
  38. } else {
  39. data.Code = 1
  40. data.Message = "查询失败"
  41. }
  42. return &data
  43. }
  44. func LinkSplit(url string) (link, androidUrl, iosUrl, weChatUrl string) {
  45. if url != "" {
  46. arr := strings.Split(url, ",")
  47. if len(arr) == 4 {
  48. link = arr[0]
  49. androidUrl = arr[1]
  50. iosUrl = arr[2]
  51. weChatUrl = arr[3]
  52. } else {
  53. if len(arr) > 0 {
  54. link = arr[0]
  55. } else {
  56. link = ""
  57. }
  58. androidUrl = ""
  59. iosUrl = ""
  60. weChatUrl = ""
  61. }
  62. }
  63. return link, androidUrl, iosUrl, weChatUrl
  64. }
  65. func ClearUnreadMsg(in *message.ClearUnreadMsgReq) error {
  66. if in.Userid != "" {
  67. //更新用户未读消息bitmap
  68. sql := fmt.Sprintf(`alter table message_user_summary UPDATE readMsg = bitmapOr(allMsg,readMsg) where userId = '%s'`, in.Userid)
  69. err1 := entity.ClickhouseConn.Exec(context.Background(), sql)
  70. if err1 != nil {
  71. return err1
  72. }
  73. //清缓存
  74. for _, v := range entity.MessageColumn {
  75. keyString := fmt.Sprintf(MsgCountKey, in.Userid, qutil.Int64All(v["group_id"]))
  76. redis.Put(redisModule, keyString, 0, -1)
  77. }
  78. // p436 清空消息时 "msg_class_count_%s_%d" 下的消息数量也清空
  79. for _, classes := range entity.ClassSearchMap {
  80. for i := 0; i < len(classes); i++ {
  81. classKeyString := fmt.Sprintf(MsgClassCountKey, in.Userid, classes[i].MsgType)
  82. redis.Put(redisModule, classKeyString, 0, -1)
  83. }
  84. }
  85. }
  86. //更新私信未读数
  87. if in.PositionId > 0 {
  88. sQuery := map[string]interface{}{
  89. "my_position_id": in.PositionId,
  90. //"ent_id": in.EntId,
  91. }
  92. if !entity.BaseMysql.Update("socialize_summary", sQuery, map[string]interface{}{"unread": 0}) {
  93. log.Println("更新用户聊天未读数失败")
  94. }
  95. }
  96. if in.NewUserId > 0 {
  97. sQuery := map[string]interface{}{
  98. "user_id": in.NewUserId,
  99. //"ent_id": in.EntId,
  100. }
  101. if !entity.BaseMysql.Update("socialize_summary", sQuery, map[string]interface{}{"unread": 0}) {
  102. log.Println("更新客服私信未读数失败")
  103. }
  104. }
  105. return nil
  106. }