package common import ( "app.yhyue.com/moapp/MessageCenter/entity" "app.yhyue.com/moapp/MessageCenter/rpc/type/message" "app.yhyue.com/moapp/MessageCenter/util" qutil "app.yhyue.com/moapp/jybase/common" "app.yhyue.com/moapp/jybase/redis" "context" "fmt" "log" "strconv" "strings" ) func FindUserBuoyMsg(this *message.FindUserBuoyMsgReq) *message.FindUserBuoyMsgRes { var err error data := message.FindUserBuoyMsgRes{} 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))) //log.Println("数据:", res) if res != nil && len(*res) > 0 { for _, v := range *res { _id := util.Int64All(v["id"]) id := strconv.FormatInt(_id, 10) links2 := util.ObjToString((v["link"])) link2, androidUrl2, iosUrl2, weChatUrl2 := LinkSplit(links2) data.Data = append(data.Data, &message.BuoyMessages{ Id: id, BuoyDetail: util.ObjToString(v["show_content"]), PcUrl: link2, AndroidUrl: androidUrl2, IosUrl: iosUrl2, WeChatUrl: weChatUrl2, }) } } if err == nil { data.Code = 0 data.Message = "查询成功" } else { data.Code = 1 data.Message = "查询失败" } return &data } func LinkSplit(url string) (link, androidUrl, iosUrl, weChatUrl string) { if url != "" { arr := strings.Split(url, ",") if len(arr) == 4 { link = arr[0] androidUrl = arr[1] iosUrl = arr[2] weChatUrl = arr[3] } else { if len(arr) > 0 { link = arr[0] } else { link = "" } androidUrl = "" iosUrl = "" weChatUrl = "" } } return link, androidUrl, iosUrl, weChatUrl } func ClearUnreadMsg(in *message.ClearUnreadMsgReq) error { if in.Userid != "" { //更新用户未读消息bitmap sql := fmt.Sprintf(`alter table message_user_summary UPDATE readMsg = bitmapOr(allMsg,readMsg) where userId = '%s'`, in.Userid) err1 := entity.ClickhouseConn.Exec(context.Background(), sql) if err1 != nil { return err1 } //清缓存 for _, v := range entity.MessageColumn { keyString := fmt.Sprintf(MsgCountKey, in.Userid, qutil.Int64All(v["group_id"])) redis.Put(redisModule, keyString, 0, -1) } // p436 清空消息时 "msg_class_count_%s_%d" 下的消息数量也清空 for _, classes := range entity.ClassSearchMap { for i := 0; i < len(classes); i++ { classKeyString := fmt.Sprintf(MsgClassCountKey, in.Userid, classes[i].MsgType) redis.Put(redisModule, classKeyString, 0, -1) } } redis.Del(redisModule, fmt.Sprintf(UserWorkDeskKey, in.Userid)) redis.Del(redisModule, fmt.Sprintf(UserMsgSummery, in.Userid)) redis.Del(redisModule, fmt.Sprintf(UserClassMapKey, in.Userid)) } //更新私信未读数 if in.PositionId > 0 { sQuery := map[string]interface{}{ "my_position_id": in.PositionId, //"ent_id": in.EntId, } if !entity.BaseMysql.Update("socialize_summary", sQuery, map[string]interface{}{"unread": 0}) { log.Println("更新用户聊天未读数失败") } } if in.NewUserId > 0 { sQuery := map[string]interface{}{ "user_id": in.NewUserId, //"ent_id": in.EntId, } if !entity.BaseMysql.Update("socialize_summary", sQuery, map[string]interface{}{"unread": 0}) { log.Println("更新客服私信未读数失败") } } return nil }