Browse Source

Merge branch 'feature/v1.2.6' into dev/v1.2.6_rjj

renjiaojiao 2 years ago
parent
commit
32ec069b82
1 changed files with 40 additions and 37 deletions
  1. 40 37
      service/message_mail_box.go

+ 40 - 37
service/message_mail_box.go

@@ -20,6 +20,8 @@ import (
 
 
 type MessaggeService struct{}
 type MessaggeService struct{}
 
 
+var rwLock = new(sync.RWMutex)
+
 // 未读消息查询
 // 未读消息查询
 func (b MessaggeService) Count(newUserId, userType, entUserId int64, isClean bool) (count int, last map[string]interface{}, err error) {
 func (b MessaggeService) Count(newUserId, userType, entUserId int64, isClean bool) (count int, last map[string]interface{}, err error) {
 	log.Printf("用户id:%d,userType:%d,entUserId:%d,isClean:%v", newUserId, userType, entUserId, isClean)
 	log.Printf("用户id:%d,userType:%d,entUserId:%d,isClean:%v", newUserId, userType, entUserId, isClean)
@@ -78,15 +80,31 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
 	sqlStr := ""
 	sqlStr := ""
 	tm := time.Now()
 	tm := time.Now()
 	if in.UserType == 2 {
 	if in.UserType == 2 {
-		var serviceSql, nameSql string
-		order := "ASC"
+		var (
+			allSql, nameSql string
+			sqlArr          []string
+		)
 		if in.NameSearch != "" {
 		if in.NameSearch != "" {
 			nameSql = " WHERE a.name  like '%" + in.NameSearch + "%"
 			nameSql = " WHERE a.name  like '%" + in.NameSearch + "%"
 		}
 		}
-		//判断是分页列表还是聊天列表 聊天列表需要展示客服信息
-		if in.QueryType == 1 {
-			serviceSql = fmt.Sprintf(`UNION
-						(
+		//一对一
+		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.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.NewUserId)
+		//客服列表
+		serviceSql := fmt.Sprintf(` (
 						SELECT
 						SELECT
 							a.ent_id AS id,
 							a.ent_id AS id,
 							2 AS userType,
 							2 AS userType,
@@ -102,30 +120,8 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
 							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  )
 							LEFT JOIN socialize_message c ON ( a.message_id = c.id ) 
 							LEFT JOIN socialize_message c ON ( a.message_id = c.id ) 
 						) `, in.NewUserId)
 						) `, in.NewUserId)
-			order = "DESC"
-		}
-		sqlStr = fmt.Sprintf(`SELECT * FROM
-					(
-						(
-						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.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 )
-						) 
-						%s
-						UNION
-						(
+		//群列表
+		groupSql := fmt.Sprintf(` (
 						SELECT
 						SELECT
 							b.id,
 							b.id,
 							3 AS userType,
 							3 AS userType,
@@ -141,10 +137,19 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
 							INNER JOIN socialize_chat_group b ON ( a.position_id = %d AND a.chat_group_id = b.id AND b.isdismiss = 0)
 							INNER JOIN socialize_chat_group 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 )
 							INNER JOIN socialize_summary c ON ( b.id = c.chat_group_id )
 							LEFT JOIN socialize_message d ON ( c.message_id = d.id ) 
 							LEFT JOIN socialize_message d ON ( c.message_id = d.id ) 
-						) 
+						) `, in.NewUserId)
+		switch in.QueryType {
+		case 1: //分享列表
+			allSql = strings.Join(append(sqlArr, oneSql, groupSql), " union ")
+		case 2: //历史会话列表
+			allSql = strings.Join(append(sqlArr, oneSql, groupSql, serviceSql), " union ")
+		}
+
+		sqlStr = fmt.Sprintf(`SELECT * FROM
+					(
+						%s
 					) a %s
 					) a %s
-				ORDER BY
-				a.timestamp %s`, in.NewUserId, serviceSql, in.NewUserId, nameSql, order)
+				a.ORDER BY a.timestamp DESC`, allSql, nameSql)
 	} else {
 	} else {
 		var timeSql, phoneSql, filtrationSql string
 		var timeSql, phoneSql, filtrationSql string
 		if in.StartTime != "" {
 		if in.StartTime != "" {
@@ -512,8 +517,6 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
 	return fool, "", in.Content, messageId, nowForm.Unix()
 	return fool, "", in.Content, messageId, nowForm.Unix()
 }
 }
 
 
-var rwLock = new(sync.RWMutex)
-
 // 客服 用户聊天消息列表同步
 // 客服 用户聊天消息列表同步
 func UserSynchronousList(customerServiceId, userId, entId, messageId int64, createTime string) {
 func UserSynchronousList(customerServiceId, userId, entId, messageId int64, createTime string) {
 	log.Printf("同步最后消息参数customerServiceId:%d,userId:%d,entId%d,messageId:%d", customerServiceId, userId, entId, messageId)
 	log.Printf("同步最后消息参数customerServiceId:%d,userId:%d,entId%d,messageId:%d", customerServiceId, userId, entId, messageId)
@@ -1032,7 +1035,7 @@ func GetUserByGroupId(tx *sql.Tx, groupId, sendId int64) []int64 {
 	return arr
 	return arr
 }
 }
 
 
-//最后一次聊天存储
+// 最后一次聊天存储
 func SocializeSummaryAdd(tx *sql.Tx, args []interface{}) (int64, int64) {
 func SocializeSummaryAdd(tx *sql.Tx, args []interface{}) (int64, int64) {
 	fieids := []string{"my_position_id", "your_position_id", "ent_id", "chat_group_id", "message_id", "unread", "customer_service_access", "timestamp"}
 	fieids := []string{"my_position_id", "your_position_id", "ent_id", "chat_group_id", "message_id", "unread", "customer_service_access", "timestamp"}
 
 
@@ -1043,7 +1046,7 @@ func SocializeSummaryAdd(tx *sql.Tx, args []interface{}) (int64, int64) {
 	return length, lastId
 	return length, lastId
 }
 }
 
 
-//群组人员未读消息更新
+// 群组人员未读消息更新
 func GroupUserUnReadUpdate(tx *sql.Tx, ids []int64) bool {
 func GroupUserUnReadUpdate(tx *sql.Tx, ids []int64) bool {
 	whs := []string{}
 	whs := []string{}
 	for i := 0; i < len(ids); i++ {
 	for i := 0; i < len(ids); i++ {