瀏覽代碼

feat:多条会话

wangshan 1 年之前
父節點
當前提交
72ea257c41
共有 2 個文件被更改,包括 33 次插入21 次删除
  1. 4 0
      rpc/messagecenter/logs/access.log
  2. 29 21
      service/message_mail_box.go

+ 4 - 0
rpc/messagecenter/logs/access.log

@@ -146,3 +146,7 @@
 {"@timestamp":"2023-04-19T13:24:25.952+08:00","caller":"init/init.go:44","content":"error--日志记录","level":"info"}
 {"@timestamp":"2023-04-19T13:24:42.678+08:00","caller":"init/init.go:76","content":"--初始化 redis--","level":"info"}
 {"@timestamp":"2023-04-19T13:24:42.678+08:00","caller":"init/init.go:80","content":"--初始化 mongodb--","level":"info"}
+{"@timestamp":"2023-09-15T11:34:56.243+08:00","caller":"init/init.go:44","content":"info--日志记录","level":"info"}
+{"@timestamp":"2023-09-15T11:34:56.243+08:00","caller":"init/init.go:44","content":"error--日志记录","level":"info"}
+{"@timestamp":"2023-09-15T11:34:56.396+08:00","caller":"init/init.go:76","content":"--初始化 redis--","level":"info"}
+{"@timestamp":"2023-09-15T11:34:56.397+08:00","caller":"init/init.go:80","content":"--初始化 mongodb--","level":"info"}

+ 29 - 21
service/message_mail_box.go

@@ -20,7 +20,10 @@ import (
 
 type MessaggeService struct{}
 
-var rwLock = new(sync.RWMutex)
+var (
+	//rwLock     = new(sync.RWMutex)
+	InsertLock = new(sync.Mutex)
+)
 
 // Count 未读消息查询
 func (b MessaggeService) Count(newUserId, positionId int64) (last map[string]interface{}, count int) {
@@ -103,7 +106,7 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
 		//客服列表
 		serviceSql := fmt.Sprintf(` (
 						SELECT
-							a.ent_id AS id,
+							DISTINCT(a.ent_id) AS id,
 							1 AS userType,
 							b.nickname AS name,
 							b.headimage as headimg,
@@ -591,12 +594,14 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
 // 客服 用户聊天消息列表同步
 // sendUserType 发送人类型 1客服 2用户
 func UserSynchronousList(customerServiceId, userId, entId, messageId int64, createTime string, sendUserType, itemType int64) {
+	InsertLock.Lock()
+	defer InsertLock.Unlock()
 	log.Printf("同步最后消息参数customerServiceId:%d,userId:%d,entId%d,messageId:%d", customerServiceId, userId, entId, messageId)
-	nowForm := time.Now().Local()
-	create_time := nowForm.Format(util.Date_Full_Layout)
+	//nowForm := time.Now().Local()
+	//create_time := nowForm.Format(util.Date_Full_Layout)
 	//查看汇总表
 	IC.BaseMysql.ExecTx("更新汇总表", func(tx *sql.Tx) bool {
-		data := IC.BaseMysql.SelectBySqlByTx(tx, "select customer_service_access from socialize_summary where  ent_id=? and   user_id=? for  update ", entId, userId)
+		data := IC.BaseMysql.SelectBySqlByTx(tx, "select customer_service_access from socialize_summary where  ent_id=? and   user_id=? ", entId, userId)
 		//data := FindOne(util.SOCIALIZE_SUMMARY, map[string]interface{}{"user_id": userId, "ent_id": entId}, "customer_service_access", "")
 		customer_service_access := 0
 		if data != nil && len(*data) > 0 {
@@ -611,26 +616,28 @@ func UserSynchronousList(customerServiceId, userId, entId, messageId int64, crea
 			if sendUserType == 1 {
 				if itemType == 4 {
 					//机器人消息保存处理
-					ok = IC.BaseMysql.UpdateOrDeleteBySqlByTx(tx, fmt.Sprintf("UPDATE  socialize_summary SET message_id = %d  ,timestamp = '%s' WHERE user_id = %d and ent_id= %d", messageId, create_time, userId, entId))
+					ok = IC.BaseMysql.UpdateOrDeleteBySqlByTx(tx, fmt.Sprintf("UPDATE  socialize_summary SET message_id = %d  ,timestamp = '%s' WHERE user_id = %d and ent_id= %d", messageId, createTime, userId, entId))
 				} else {
-					ok = IC.BaseMysql.UpdateOrDeleteBySqlByTx(tx, fmt.Sprintf("UPDATE  socialize_summary SET message_id = %d ,timestamp = '%s', unread = unread+1, customer_service_access = %d WHERE user_id = %d and ent_id= %d", messageId, create_time, customer_service_access, userId, entId))
+					ok = IC.BaseMysql.UpdateOrDeleteBySqlByTx(tx, fmt.Sprintf("UPDATE  socialize_summary SET message_id = %d ,timestamp = '%s', unread = unread+1, customer_service_access = %d WHERE user_id = %d and ent_id= %d", messageId, createTime, customer_service_access, userId, entId))
 				}
 			} else {
-				ok = IC.BaseMysql.UpdateOrDeleteBySqlByTx(tx, fmt.Sprintf("UPDATE  socialize_summary SET message_id = %d ,timestamp = '%s', customer_service_access = %d WHERE user_id = %d and ent_id= %d", messageId, create_time, customer_service_access, userId, entId))
+				ok = IC.BaseMysql.UpdateOrDeleteBySqlByTx(tx, fmt.Sprintf("UPDATE  socialize_summary SET message_id = %d ,timestamp = '%s', customer_service_access = %d WHERE user_id = %d and ent_id= %d", messageId, createTime, customer_service_access, userId, entId))
 			}
-			if ok > 0 && customerServiceId > 0 {
-				//判断客服用户表是否存在
-				if IC.BaseMysql.Count(util.Socialize_customer_service_user, map[string]interface{}{"user_id": userId, "ent_id": entId, "customer_service_id": customerServiceId}) > 0 {
-					if sendUserType == 2 {
-						IC.BaseMysql.UpdateOrDeleteBySqlByTx(tx, fmt.Sprintf("UPDATE  socialize_customer_service_user SET  unread = unread+1 WHERE user_id = %d and customer_service_id= %d", userId, customerServiceId))
+			if ok > 0 {
+				if customerServiceId > 0 {
+					//判断客服用户表是否存在
+					if IC.BaseMysql.Count(util.Socialize_customer_service_user, map[string]interface{}{"user_id": userId, "ent_id": entId, "customer_service_id": customerServiceId}) > 0 {
+						if sendUserType == 2 {
+							IC.BaseMysql.UpdateOrDeleteBySqlByTx(tx, fmt.Sprintf("UPDATE  socialize_customer_service_user SET  unread = unread+1 WHERE user_id = %d and customer_service_id= %d", userId, customerServiceId))
+						}
+					} else {
+						IC.BaseMysql.Insert(util.SOCIALIZE_CUSTOMER_SERVICE_USER, map[string]interface{}{
+							"user_id":             userId,
+							"ent_id":              entId,
+							"customer_service_id": customerServiceId,
+							"unread":              quitl.If(sendUserType == 1, 0, 1),
+						})
 					}
-				} else {
-					IC.BaseMysql.Insert(util.SOCIALIZE_CUSTOMER_SERVICE_USER, map[string]interface{}{
-						"user_id":             userId,
-						"ent_id":              entId,
-						"customer_service_id": customerServiceId,
-						"unread":              quitl.If(sendUserType == 1, 0, 1),
-					})
 				}
 			}
 		} else {
@@ -639,10 +646,11 @@ func UserSynchronousList(customerServiceId, userId, entId, messageId int64, crea
 				"user_id":                 userId,
 				"ent_id":                  entId,
 				"customer_service_access": quitl.If(customerServiceId > 0, 1, 0),
-				"timestamp":               create_time,
+				"timestamp":               createTime,
 				"unread":                  quitl.If(sendUserType == 1, 0, 1),
 				"message_id":              messageId,
 			})
+			log.Println(ok, "---", userId, "---", messageId, "---", entId, "------add summary log:")
 			//新增客服用户表
 			if ok > 0 {
 				if customerServiceId > 0 {