Ver Fonte

数据聊天

WH01243 há 2 anos atrás
pai
commit
9ea846f95b
1 ficheiros alterados com 52 adições e 47 exclusões
  1. 52 47
      service/message_mail_box.go

+ 52 - 47
service/message_mail_box.go

@@ -591,67 +591,72 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
 // sendUserType 发送人类型 1客服 2用户
 func UserSynchronousList(customerServiceId, userId, entId, messageId int64, createTime string, sendUserType, itemType int64) {
 	log.Printf("同步最后消息参数customerServiceId:%d,userId:%d,entId%d,messageId:%d", customerServiceId, userId, entId, messageId)
-	/*	rwLock.Lock()
-		defer rwLock.Unlock()*/
 	nowForm := time.Now().Local()
 	create_time := nowForm.Format(util.Date_Full_Layout)
 	//查看汇总表
-	data := IC.BaseMysql.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 {
-		if quitl.IntAll((*data)["customer_service_access"]) == 0 && customerServiceId > 0 {
-			customer_service_access = 1
-		} else {
-			customer_service_access = quitl.IntAll((*data)["customer_service_access"])
-		}
-		log.Println(customer_service_access, "customer_service_access打印", (*data)["customer_service_access"], customerServiceId, quitl.IntAll((*data)["customer_service_access"]) == 0 && customerServiceId > 0)
-		//更新汇总表
-		ok := int64(0)
-		if sendUserType == 1 {
-			if itemType == 4 {
-				//机器人消息保存处理
-				ok = IC.BaseMysql.UpdateOrDeleteBySql(fmt.Sprintf("UPDATE  socialize_summary SET message_id = %d  ,timestamp = '%s' WHERE user_id = %d and ent_id= %d", messageId, create_time, userId, entId))
+	IC.BaseMysql.ExecTx("更新汇总表", func(tx *sql.Tx) bool {
+		data := IC.BaseMysql.SelectBySqlByTx(tx, "select * from customer_service_access where  ent_id=? and   user_id=? for  update ", 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 {
+			if quitl.IntAll((*data)[0]["customer_service_access"]) == 0 && customerServiceId > 0 {
+				customer_service_access = 1
 			} else {
-				ok = IC.BaseMysql.UpdateOrDeleteBySql(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))
+				customer_service_access = quitl.IntAll((*data)[0]["customer_service_access"])
 			}
-		} else {
-			ok = IC.BaseMysql.UpdateOrDeleteBySql(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))
-		}
-		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.UpdateOrDeleteBySql(fmt.Sprintf("UPDATE  socialize_customer_service_user SET  unread = unread+1 WHERE user_id = %d and customer_service_id= %d", userId, customerServiceId))
+			log.Println(customer_service_access, "customer_service_access打印", (*data)[0]["customer_service_access"], customerServiceId, quitl.IntAll((*data)["customer_service_access"]) == 0 && customerServiceId > 0)
+			//更新汇总表
+			ok := int64(0)
+			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))
+				} 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))
 				}
 			} else {
-				IC.BaseMysql.Insert(util.SOCIALIZE_CUSTOMER_SERVICE_USER, map[string]interface{}{
+				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))
+			}
+			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))
+					}
+				} 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 {
+			//新增汇总表
+			ok := IC.BaseMysql.InsertByTx(tx, util.SOCIALIZE_SUMMARY, map[string]interface{}{
+				"user_id":                 userId,
+				"ent_id":                  entId,
+				"customer_service_access": quitl.If(customerServiceId > 0, 1, 0),
+				"timestamp":               create_time,
+				"unread":                  quitl.If(sendUserType == 1, 0, 1),
+				"message_id":              messageId,
+			})
+			//新增客服用户表
+			if ok > 0 && customerServiceId > 0 {
+				IC.BaseMysql.InsertByTx(tx, 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 {
+				return false
 			}
+
 		}
-	} else {
-		//新增汇总表
-		ok := IC.BaseMysql.Insert(util.SOCIALIZE_SUMMARY, map[string]interface{}{
-			"user_id":                 userId,
-			"ent_id":                  entId,
-			"customer_service_access": quitl.If(customerServiceId > 0, 1, 0),
-			"timestamp":               create_time,
-			"unread":                  quitl.If(sendUserType == 1, 0, 1),
-			"message_id":              messageId,
-		})
-		//新增客服用户表
-		if ok > 0 && customerServiceId > 0 {
-			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),
-			})
-		}
-	}
+		return true
+	})
 }
 
 // 历史信息查询