|
@@ -25,68 +25,10 @@ var rwLock = new(sync.RWMutex)
|
|
|
// Count 未读消息查询
|
|
|
func (b MessaggeService) Count(newUserId int64) (count int, last map[string]interface{}, err error) {
|
|
|
//导航右上角未读消息总量 1v1聊天+群组消息+客服消息
|
|
|
- //v := make([]interface{}, 0)
|
|
|
- var (
|
|
|
- allSql string
|
|
|
- sqlArr []string
|
|
|
- )
|
|
|
- //一对一
|
|
|
- oneSql := fmt.Sprintf(`(SELECT
|
|
|
- a.your_position_id AS id,
|
|
|
- 1 AS userType,
|
|
|
- c.nickname AS name,
|
|
|
- c.headimg,
|
|
|
- d.content,
|
|
|
- d.type,
|
|
|
- d.create_time,
|
|
|
- a.unread as number,
|
|
|
- a.timestamp
|
|
|
- FROM
|
|
|
- socialize_summary a
|
|
|
- INNER JOIN base_position b ON ( a.my_position_id = %d AND a.unread > 0 AND a.your_position_id = b.id )
|
|
|
- INNER JOIN base_user c ON ( b.user_id = c.id )
|
|
|
- LEFT JOIN socialize_message d ON ( a.message_id = d.id ))`, newUserId)
|
|
|
- //客服列表
|
|
|
- serviceSql := fmt.Sprintf(` (
|
|
|
- SELECT
|
|
|
- a.ent_id AS id,
|
|
|
- 2 AS userType,
|
|
|
- b.nickname AS name,
|
|
|
- b.headimage as headimg,
|
|
|
- c.content,
|
|
|
- c.type,
|
|
|
- c.create_time,
|
|
|
- a.unread as number,
|
|
|
- a.timestamp
|
|
|
- FROM
|
|
|
- socialize_summary a
|
|
|
- INNER JOIN socialize_tenant_robot b ON ( a.user_id = %d AND a.unread > 0 AND a.ent_id = b.ent_id )
|
|
|
- LEFT JOIN socialize_message c ON ( a.message_id = c.id )
|
|
|
- ) `, newUserId)
|
|
|
- //群列表
|
|
|
- groupSql := fmt.Sprintf(` (
|
|
|
- SELECT
|
|
|
- b.id,
|
|
|
- 3 AS userType,
|
|
|
- b.name,
|
|
|
- '' AS headimg,
|
|
|
- d.content,
|
|
|
- d.type,
|
|
|
- d.create_time,
|
|
|
- a.unread as number,
|
|
|
- c.timestamp
|
|
|
- FROM
|
|
|
- socialize_chat_group_person a
|
|
|
- INNER JOIN socialize_chat_group b ON ( a.position_id = %d AND a.unread > 0 AND a.chat_group_id = b.id AND b.isdismiss = 0)
|
|
|
- INNER JOIN socialize_summary c ON ( b.id = c.chat_group_id )
|
|
|
- LEFT JOIN socialize_message d ON ( c.message_id = d.id )
|
|
|
- ) `, newUserId)
|
|
|
-
|
|
|
- allSql = strings.Join(append(sqlArr, oneSql, groupSql, serviceSql), " union ")
|
|
|
|
|
|
- log.Println("查询sql", allSql)
|
|
|
- data := IC.BaseMysql.SelectBySql(allSql)
|
|
|
- log.Println("查询数据:", data)
|
|
|
+ //log.Println("查询sql", allSql)
|
|
|
+ //data := IC.BaseMysql.SelectBySql(allSql)
|
|
|
+ //log.Println("查询数据:", data)
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -687,8 +629,8 @@ func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) *[]map[string
|
|
|
case 3: //群聊天
|
|
|
|
|
|
sqlStr = fmt.Sprintf("SELECT a.messag_id AS messageId,b.*,"+
|
|
|
- "IF ( a.own_id = a.receive_user_id, 1, 2 ) AS fool,"+
|
|
|
- "IF ( a.own_id = a.receive_user_id, 0, a.receive_user_id ) AS receive_position_id,"+
|
|
|
+ "IF ( a.own_id = a.send_user_id, 1, 2 ) AS fool,"+
|
|
|
+ "IF ( a.own_id = a.send_user_id, 0, a.send_user_id ) AS send_position_id,"+
|
|
|
"a.send_user_type,a.type AS itemType FROM %s a "+
|
|
|
"LEFT JOIN %s b ON a.messag_id = b.id "+
|
|
|
"WHERE a.own_type = 2 AND a.own_id = %d "+
|
|
@@ -709,28 +651,28 @@ func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) *[]map[string
|
|
|
"WHERE a.own_type = 1 and a.iswithdraw = 0 "+
|
|
|
"AND (a.type = 5 or a.type=4 or a.type=6 or a.type=7 or a.type=8 ) "+
|
|
|
"AND c.ent_id = %d "+
|
|
|
- "AND c.user_id in (%s) %s "+
|
|
|
- "ORDER BY a.create_time desc ,a.id asc "+
|
|
|
+ "AND c.user_id = %d %s "+
|
|
|
+ "ORDER BY a.create_time desc ,a.id asc "+
|
|
|
"limit 0 , %d ",
|
|
|
util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_MESSAGE, util.SOCIALIZE_CHAT_SESSION,
|
|
|
- in.EntId, positionStr, lastStr, in.PageSize)
|
|
|
+ in.EntId, in.SendId, lastStr, in.PageSize)
|
|
|
} else {
|
|
|
//用户聊天记录查看
|
|
|
sqlStr = fmt.Sprintf("SELECT a.messag_id as messageId,e.appraise as appraise, b.*, IF ( a.own_id = a.send_user_id, 1, 2 ) AS fool , a.send_user_type, a.type as itemType, d.nickname as robotName, d.headimage as robotImg, c.customer_service_name as setName "+
|
|
|
"FROM %s a "+
|
|
|
"LEFT JOIN %s b ON a.messag_id = b.id "+
|
|
|
- "LEFT JOIN %s c ON IF ( a.send_user_type = 1, a.send_user_id, a.receive_user_id ) = c.id AND c.user_id in (%s) "+
|
|
|
- "LEFT JOIN %s d on c.ent_id=d.ent_id "+
|
|
|
- "LEFT JOIN %s e on b.id=e.messag_id "+
|
|
|
- "WHERE a.own_type = 2 "+
|
|
|
- "AND a.own_id in (%s) "+
|
|
|
- //"AND c.ent_id = %d "+
|
|
|
- "AND c.user_id in (%s) "+
|
|
|
- "AND ( a.type = 4 OR a.type = 5 or a.type=6 or a.type=7) %s "+
|
|
|
- "ORDER BY a.create_time desc ,a.id asc "+
|
|
|
+ "LEFT JOIN %s c ON IF ( a.send_user_type = 1, a.send_user_id, a.receive_user_id ) = c.id AND c.ent_id = %d AND c.user_id = %d "+
|
|
|
+ "LEFT JOIN %s d on c.ent_id=d.ent_id "+
|
|
|
+ "LEFT JOIN %s e on e.messag_id=b.id "+
|
|
|
+ "WHERE a.own_type = 2 and a.iswithdraw = 0 "+
|
|
|
+ "AND a.own_id = %d "+
|
|
|
+ "AND c.ent_id = %d "+
|
|
|
+ "AND c.user_id = %d "+
|
|
|
+ "AND ( a.type = 4 OR a.type = 5 or a.type=6 or a.type=7 or a.type=8) %s "+
|
|
|
+ "ORDER BY a.create_time desc,a.id asc "+
|
|
|
"limit 0 , %d ",
|
|
|
- util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_MESSAGE, util.SOCIALIZE_CHAT_SESSION, positionStr, util.SOCIALIZE_TENANT_ROBOT,
|
|
|
- util.SOCIALIZE_APPRAISE, positionStr, positionStr, lastStr, in.PageSize)
|
|
|
+ util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_MESSAGE, util.SOCIALIZE_CHAT_SESSION, in.SendId, in.NewUserId, util.SOCIALIZE_TENANT_ROBOT, util.SOCIALIZE_APPRAISE,
|
|
|
+ in.NewUserId, in.SendId, in.NewUserId, lastStr, in.PageSize)
|
|
|
}
|
|
|
break
|
|
|
}
|
|
@@ -751,7 +693,7 @@ func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) *[]map[string
|
|
|
if (in.MsgType == 3 || in.MsgType == 2) && data != nil && len(*data) > 0 {
|
|
|
_, _, positionData := EntPerson(in.EntId, true)
|
|
|
for _, v := range *data {
|
|
|
- positionId := quitl.IntAll(v["receive_position_id"])
|
|
|
+ positionId := quitl.IntAll(v["send_position_id"])
|
|
|
if positionId != 0 {
|
|
|
v["userName"] = positionData[positionId]
|
|
|
log.Println(v["userName"], positionData[positionId])
|