|
@@ -81,11 +81,28 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
|
|
|
tm := time.Now()
|
|
|
if in.UserType == 2 {
|
|
|
var (
|
|
|
- allSql string
|
|
|
- sqlArr []string
|
|
|
+ allSql, positionIdArr, oneNameSql, serviceNameSql string
|
|
|
+ sqlArr []string
|
|
|
)
|
|
|
+ GroupNameSql := `(SELECT *,"" as groupMember FROM socialize_chat_group)`
|
|
|
+ if in.NameSearch != "" {
|
|
|
+ positionIdArr = NameToPositionIdp(in.NameSearch, in.EntId)
|
|
|
+ if positionIdArr != "" {
|
|
|
+ oneNameSql = " AND find_in_set(b.id,'" + positionIdArr + "')"
|
|
|
+ serviceNameSql = " AND b.nickname like '%" + in.NameSearch + "%"
|
|
|
+ GroupNameSql = fmt.Sprintf(` (
|
|
|
+ SELECT a.chat_group_id as id,
|
|
|
+ b.name,
|
|
|
+ b.isdismiss,
|
|
|
+ GROUP_CONCAT(b.position_id) as groupMember
|
|
|
+ FROM socialize_chat_group_person a
|
|
|
+ INNER JOIN socialize_chat_group b ON a.position_id=%d
|
|
|
+ INNER JOIN socialize_chat_group_person c a.chat_group_id =c.chat_group_id AND c.position_id IN (%s)
|
|
|
+ GROUP BY a.chat_group_id)`, in.PositionId, positionIdArr)
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- //一对一
|
|
|
+ //1v1
|
|
|
oneSql := fmt.Sprintf(`(SELECT
|
|
|
a.your_position_id AS id,
|
|
|
1 AS userType,
|
|
@@ -96,12 +113,15 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
|
|
|
d.create_time,
|
|
|
a.unread as number,
|
|
|
a.timestamp,
|
|
|
- c.phone
|
|
|
+ c.phone,
|
|
|
+ "" as groupMember
|
|
|
FROM
|
|
|
socialize_summary a
|
|
|
- INNER JOIN base_position b ON ( a.my_position_id = %d AND a.your_position_id = b.id )
|
|
|
+ INNER JOIN base_position b ON ( a.my_position_id = %d %s 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 ))`, in.PositionId)
|
|
|
+ LEFT JOIN socialize_message d ON ( a.message_id = d.id )
|
|
|
+ LIMIT 0,500
|
|
|
+ )`, in.PositionId, oneNameSql)
|
|
|
//客服列表
|
|
|
serviceSql := fmt.Sprintf(` (
|
|
|
SELECT
|
|
@@ -114,12 +134,14 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
|
|
|
c.create_time,
|
|
|
a.unread as number,
|
|
|
a.timestamp,
|
|
|
- "" as phone
|
|
|
+ "" as phone,
|
|
|
+ "" as groupMember
|
|
|
FROM
|
|
|
socialize_summary a
|
|
|
- INNER JOIN socialize_tenant_robot b ON ( a.user_id = %d AND a.ent_id = b.ent_id)
|
|
|
+ INNER JOIN socialize_tenant_robot b ON ( a.user_id = %d AND a.ent_id = b.ent_id %s )
|
|
|
LEFT JOIN socialize_message c ON ( a.message_id = c.id )
|
|
|
- ) `, in.NewUserId)
|
|
|
+ LIMIT 0,500
|
|
|
+ ) `, in.NewUserId, serviceNameSql)
|
|
|
//群列表
|
|
|
groupSql := fmt.Sprintf(` (
|
|
|
SELECT
|
|
@@ -133,23 +155,24 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
|
|
|
a.unread as number,
|
|
|
c.timestamp,
|
|
|
"" as phone
|
|
|
+ b.groupMember
|
|
|
FROM
|
|
|
socialize_chat_group_person a
|
|
|
- INNER JOIN socialize_chat_group b ON ( a.position_id = %d AND a.chat_group_id = b.id AND b.isdismiss = 0)
|
|
|
+ INNER JOIN %s b ON ( a.position_id = %d 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 )
|
|
|
- ) `, in.PositionId)
|
|
|
+ LIMIT 0,500
|
|
|
+ ) `, GroupNameSql, in.PositionId)
|
|
|
switch in.QueryType {
|
|
|
case 1: //分享列表
|
|
|
allSql = strings.Join(append(sqlArr, oneSql, groupSql), " UNION ALL ")
|
|
|
case 2: //历史会话列表
|
|
|
allSql = strings.Join(append(sqlArr, oneSql, groupSql, serviceSql), " UNION ALL ")
|
|
|
}
|
|
|
-
|
|
|
sqlStr = fmt.Sprintf(`SELECT * FROM
|
|
|
(
|
|
|
%s
|
|
|
- ) a
|
|
|
+ ) a LIMIT 0,500
|
|
|
a.ORDER BY a.timestamp DESC`, allSql)
|
|
|
} else {
|
|
|
var timeSql, phoneSql, filtrationSql string
|
|
@@ -247,28 +270,52 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
|
|
|
data = IC.BaseMysql.SelectBySql(sqlStr)
|
|
|
if data != nil && len(*data) > 0 {
|
|
|
count = quitl.Int64All(len(*data))
|
|
|
- log.Println("查询列表耗时2:", time.Since(tm), count)
|
|
|
- if in.UserType != 2 {
|
|
|
+ log.Println("查询列表耗时2:", time.Since(tm), in.QueryType, count)
|
|
|
+ switch in.UserType { //客服查询结果分页
|
|
|
+ case 1:
|
|
|
if in.Page*in.Size >= count {
|
|
|
dataSize = (*data)[(in.Page-1)*in.Size:]
|
|
|
} else {
|
|
|
dataSize = (*data)[(in.Page-1)*in.Size : in.Page*in.Size]
|
|
|
}
|
|
|
- } else {
|
|
|
- phoneMap, _, _ := EntPerson(in.EntId, false)
|
|
|
+ return &dataSize, count, err
|
|
|
+ case 2: //用户查询结果
|
|
|
+ phoneMap, _, positionMap := EntPerson(in.EntId, true) //获取企业架构人员名称
|
|
|
for _, v := range *data {
|
|
|
- if name, ok := phoneMap[quitl.InterfaceToStr(v["phone"])]; ok && quitl.IntAll(v["userType"]) == 1 {
|
|
|
- v["name"] = name
|
|
|
- }
|
|
|
- if in.NameSearch != "" && !strings.Contains(quitl.InterfaceToStr(v["name"]), in.NameSearch) {
|
|
|
- continue
|
|
|
+ if quitl.IntAll(v["userType"]) == 1 {
|
|
|
+ v["name"] = phoneMap[quitl.InterfaceToStr(v["phone"])]
|
|
|
+ } else if quitl.IntAll(v["userType"]) == 3 {
|
|
|
+ var names []string
|
|
|
+ if quitl.InterfaceToStr(v["groupMember"]) != "" {
|
|
|
+ for i, id := range strings.Split(quitl.InterfaceToStr(v["groupMember"]), ",") {
|
|
|
+ if i < 5 {
|
|
|
+ names = append(names, positionMap[quitl.IntAll(id)])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ v["groupMember"] = names
|
|
|
}
|
|
|
- dataSize = append(dataSize, v)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- return &dataSize, count, err
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func GroupMember(ids []string, name string, phoneMap map[string]string) map[int][]string {
|
|
|
+ req := make(map[int][]string)
|
|
|
+ data := IC.BaseMysql.SelectBySql(fmt.Sprintf("SELECT b.phone,a.chat_group_id FROM socialize_chat_group_person a "+
|
|
|
+ "INNER JOIN base_position b ON (a.id in (%s) AND b.id = a.position_id) ", strings.Join(ids, ",")))
|
|
|
+ if data != nil && len(*data) > 0 {
|
|
|
+ for _, v := range *data {
|
|
|
+ if n, ok := phoneMap[quitl.InterfaceToStr(v["phone"])]; ok && strings.Contains(n, name) {
|
|
|
+ if len(req[quitl.IntAll(v["chat_group_id"])]) < 5 {
|
|
|
+ req[quitl.IntAll(v["chat_group_id"])] = append(req[quitl.IntAll(v["chat_group_id"])], n)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return req
|
|
|
}
|
|
|
|
|
|
// 客服会话列表
|
|
@@ -888,7 +935,7 @@ func (b MessaggeService) WithdrawMessage(in *messagecenter.ReadWithdrawReq) bool
|
|
|
// 撤回消息同步信息
|
|
|
func SynchronousInfo(sender, recipient, conversationType, messageId, userType, entId, chatGroupId int64) {
|
|
|
switch conversationType {
|
|
|
- case 1: //一对一用户聊天
|
|
|
+ case 1: //1v1用户聊天
|
|
|
if IC.BaseMysql.Count(util.SOCIALIZE_MESSAGE, map[string]interface{}{"id": messageId, "own_id": recipient, "isread": 0}) > 0 {
|
|
|
IC.BaseMysql.SelectBySql(fmt.Sprintf("update %s set unread=CASE WHEN unread > 0 and my_position_id = %d and your_position_id = %d THEN unread-1 ELSE 0 END;", util.Socialize_summary, recipient, sender))
|
|
|
}
|