Sfoglia il codice sorgente

Merge branch 'dev/v1.2.6_wh' of SocialPlatform/messageCenter into feature/v1.2.6

zhangxinlei1996 2 anni fa
parent
commit
fcf97179a5
3 ha cambiato i file con 96 aggiunte e 76 eliminazioni
  1. 1 0
      entity/util.go
  2. BIN
      rpc/messagecenter/messagecenter_rpc
  3. 95 76
      service/message_mail_box.go

+ 1 - 0
entity/util.go

@@ -29,6 +29,7 @@ const (
 	ENTNICHE_DELETE                 = "entniche_delete"
 	SOCIALIZE_APPRAISE              = "socialize_message_appraise"
 	SOCIALIZE_SUMMARY               = "socialize_summary"
+	SOCIALIZE_CUSTOMER_SERVICE_USER = "socialize_customer_service_user"
 	Socialize_summary               = "socialize_summary"
 	Socialize_customer_service_user = "socialize_customer_service_user"
 )

BIN
rpc/messagecenter/messagecenter_rpc


+ 95 - 76
service/message_mail_box.go

@@ -392,52 +392,50 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
 	var customer_service_id, userid, entid, message_id int64
 	nowForm := time.Now().Local()
 	create_time := nowForm.Format(util.Date_Full_Layout)
-	if in.ItemType != 2 {
-		userId := int64(0)
-		sessionId := int64(0)
-		switch in.ItemType {
-		case 4, 5, 8:
-			if in.OwnType == 1 {
-				sessionId = in.ReceiveId
-				userId = in.NewUserId
-			} else {
-				sessionId = in.SendId
-				userId = in.ReceiveId
-				if in.ItemType == 4 || in.ItemType == 8 {
-					userId = in.NewUserId
-				}
-			}
-			break
-		case 6:
-			if in.OwnType == 1 {
-				sessionId = in.ReceiveId
-				userId = in.NewUserId
-			} else if in.OwnType == 2 {
-				sessionId = in.SendId
-				userId = in.ReceiveId
-			} else {
-				sessionId = in.ReceiveId
+	userId := int64(0)
+	sessionId := int64(0)
+	switch in.ItemType {
+	case 4, 5, 8:
+		if in.OwnType == 1 {
+			sessionId = in.ReceiveId
+			userId = in.NewUserId
+		} else {
+			sessionId = in.SendId
+			userId = in.ReceiveId
+			if in.ItemType == 4 || in.ItemType == 8 {
 				userId = in.NewUserId
 			}
-			break
 		}
-		//查找会话信息
-		chatJson := IC.BaseMysql.FindOne(util.SOCIALIZE_CHAT_SESSION, map[string]interface{}{"id": sessionId}, "user_id,ent_id,customer_service_id", "")
-		if chatJson == nil {
-			return false, "会话标识不存在", "", 0, nowForm.Unix()
+		break
+	case 6:
+		if in.OwnType == 1 {
+			sessionId = in.ReceiveId
+			userId = in.NewUserId
+		} else if in.OwnType == 2 {
+			sessionId = in.SendId
+			userId = in.ReceiveId
 		} else {
-			if userId != quitl.Int64All((*chatJson)["user_id"]) {
-				return false, "会话标识不属于此用户", "", 0, nowForm.Unix()
-			}
+			sessionId = in.ReceiveId
+			userId = in.NewUserId
 		}
-		customer_service_id = quitl.Int64All((*chatJson)["customer_service_id"])
-		entid = quitl.Int64All((*chatJson)["ent_id"])
-		userid = userId
+		break
 	}
+	//查找会话信息
+	chatJson := IC.BaseMysql.FindOne(util.SOCIALIZE_CHAT_SESSION, map[string]interface{}{"id": sessionId}, "user_id,ent_id,customer_service_id", "")
+	if chatJson == nil {
+		return false, "会话标识不存在", "", 0, nowForm.Unix()
+	} else {
+		if userId != quitl.Int64All((*chatJson)["user_id"]) {
+			return false, "会话标识不属于此用户", "", 0, nowForm.Unix()
+		}
+	}
+	customer_service_id = quitl.Int64All((*chatJson)["customer_service_id"])
+	entid = quitl.Int64All((*chatJson)["ent_id"])
+	userid = userId
+	userType := int64(1)
+	//客服相关信息保存
 	fool = IC.BaseMysql.ExecTx("聊天信息保存", func(tx *sql.Tx) bool {
 		//先插入信息表
-		userType := int64(1)
-		userId := int64(0)
 		message := map[string]interface{}{
 			"appid":         in.Appid,
 			"title":         in.Title,
@@ -540,7 +538,6 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
 					messageMailBox["read_time"] = nowForm.Format(util.Date_Full_Layout)
 				}
 				userType = 2
-
 			}
 		} else {
 			messageMailBox["own_type"] = 2
@@ -555,9 +552,9 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
 		receiveOk = IC.BaseMysql.InsertByTx(tx, util.SOCIALIZE_MESSAGE_MAILBOX, messageMailBox)
 		messageMailBox = map[string]interface{}{
 			"appid":         in.Appid,
-			"messag_id":     ok,
 			"type":          in.ItemType,
 			"create_time":   nowForm.Format(util.Date_Full_Layout),
+			"messag_id":     ok,
 			"read_time":     nowForm.Format(util.Date_Full_Layout),
 			"isread":        1,
 			"send_isdel":    0,
@@ -596,52 +593,67 @@ func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (fool bool
 			messageMailBox["receive_user_id"] = in.ReceiveId
 		}
 		receiveOk = IC.BaseMysql.InsertByTx(tx, util.SOCIALIZE_MESSAGE_MAILBOX, messageMailBox)
-		if ok > 1 && receiveOk > 1 {
-			pc_a, err := util.GetData(userType, userId)
-			count := 1
-			if err == nil && pc_a != nil {
-				count += pc_a.Count
-			}
-			util.SetData(userType, userId, map[string]interface{}{"data": data, "count": count}, IC.SurvivalTime)
-		}
 		return ok > 1 && receiveOk > 1
 	})
-	if fool && in.ItemType != 2 && in.ItemType != 3 {
-		go UserSynchronousList(customer_service_id, userid, entid, message_id, create_time)
+	if fool {
+		go UserSynchronousList(customer_service_id, userid, entid, message_id, create_time, quitl.Int64All(quitl.If(userType == 1, 2, 1)))
 	}
 	return fool, "", in.Content, messageId, nowForm.Unix()
 }
 
 // 客服 用户聊天消息列表同步
-func UserSynchronousList(customerServiceId, userId, entId, messageId int64, createTime string) {
+//sendUserType 发送人类型 1客服 2用户
+func UserSynchronousList(customerServiceId, userId, entId, messageId int64, createTime string, sendUserType int64) {
 	log.Printf("同步最后消息参数customerServiceId:%d,userId:%d,entId%d,messageId:%d", customerServiceId, userId, entId, messageId)
-	rwLock.Lock()
-	defer rwLock.Unlock()
-	if IC.BaseMysql.Count(util.User_message_list, map[string]interface{}{"user_id": userId, "ent_id": entId}) > 0 {
-		upData := map[string]interface{}{
-			"message_id":  messageId,
-			"update_time": createTime,
+	/*	rwLock.Lock()
+		defer rwLock.Unlock()*/
+	nowForm := time.Now().Local()
+	create_time := nowForm.Format(util.Date_Full_Layout)
+	//查看汇总表
+	log.Println(IC.BaseMysql.Count(util.SOCIALIZE_SUMMARY, map[string]interface{}{"user_id": userId, "ent_id": entId}))
+	if IC.BaseMysql.Count(util.SOCIALIZE_SUMMARY, map[string]interface{}{"user_id": userId, "ent_id": entId}) > 0 {
+		//更新汇总表
+		ok := int64(0)
+		if sendUserType == 1 {
+			ok = IC.BaseMysql.UpdateOrDeleteBySql(fmt.Sprintf("UPDATE  socialize_summary SET message_id = %d, unread = unread+1, customer_service_access = %d WHERE user_id = %d and ent_id= %d", messageId, quitl.If(customerServiceId > 0, 0, 1), userId, entId))
+		} else {
+			ok = IC.BaseMysql.UpdateOrDeleteBySql(fmt.Sprintf("UPDATE  socialize_summary SET message_id = %d, customer_service_access = %d WHERE user_id = %d and ent_id= %d", messageId, quitl.If(customerServiceId > 0, 0, 1), 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))
+				}
+			} 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),
+				})
+			}
 		}
-		//判断是否机器人聊天
-		if customerServiceId > 0 && IC.BaseMysql.Count(util.User_message_list, map[string]interface{}{"user_id": userId, "ent_id": entId, "customer_service_id": 0}) > 0 {
-			//将机器人列表更新成用户
-			upData["customer_service_id"] = customerServiceId
-			//转人工 机器人聊天类型修改
-			upData["type"] = 1
+	} 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),
+			})
 		}
-		//已于人工客服联系过 只同步最后消息
-		IC.BaseMysql.Update(util.User_message_list, map[string]interface{}{"user_id": userId, "ent_id": entId}, upData)
-		return
 	}
-	//不存在消息列表 创建
-	IC.BaseMysql.Insert(util.User_message_list, map[string]interface{}{
-		"ent_id":              entId,
-		"user_id":             userId,
-		"message_id":          messageId,
-		"update_time":         createTime,
-		"customer_service_id": customerServiceId,
-		"type":                quitl.If(customerServiceId == 0, 0, 1),
-	})
 }
 
 // 历史信息查询
@@ -878,13 +890,20 @@ func (b *MessaggeService) SaveAutoReplyMsg(userType, entId, entUserId, userId in
 		sessionId := IC.BaseMysql.InsertBySqlByTx(tx, `insert into socialize_chat_session (appid,type,ent_id,customer_service_id,customer_service_name,user_id,start_time,end_time) values (?,?,?,?,?,?,?,?)`, appId, 1, entId, entUserId, entUserName, userId, nowFormat, nowFormat)
 		ok := false
 		if userType == 0 {
+			//客服给用户发送,归属客服已读
 			ok1 := IC.BaseMysql.InsertBySqlByTx(tx, `insert into socialize_message_mailbox (appid,messag_id,type,send_user_id,send_user_type,receive_user_id,receive_user_type,own_id,own_type,create_time,isread,read_time) values (?,?,?,?,?,?,?,?,?,?,?,?)`, appId, messageId, 7, sessionId, 1, userId, 2, sessionId, 1, nowFormat, 1, nowFormat) > 0
+			//客服给用户发送,归属用户未读
 			ok2 := IC.BaseMysql.InsertBySqlByTx(tx, `insert into socialize_message_mailbox (appid,messag_id,type,send_user_id,send_user_type,receive_user_id,receive_user_type,own_id,own_type,create_time) values (?,?,?,?,?,?,?,?,?,?)`, appId, messageId, 7, sessionId, 1, userId, 2, userId, 2, nowFormat) > 0
 			ok = ok1 && ok2
+			userType = 1
 		} else if userType == 1 {
+			// 客服给用户发送 客服接受已读系统信息
 			ok = IC.BaseMysql.InsertBySqlByTx(tx, `insert into socialize_message_mailbox (appid,messag_id,type,send_user_id,send_user_type,receive_user_id,receive_user_type,own_id,own_type,create_time,isread,read_time) values (?,?,?,?,?,?,?,?,?,?,?,?)`, appId, messageId, 7, sessionId, 1, userId, 2, sessionId, 1, nowFormat, 1, nowFormat) > 0
+			userType = 2
 		} else if userType == 2 {
+			//客服给用户发送消息 用户接受未读读系统信息
 			ok = IC.BaseMysql.InsertBySqlByTx(tx, `insert into socialize_message_mailbox (appid,messag_id,type,send_user_id,send_user_type,receive_user_id,receive_user_type,own_id,own_type,create_time) values (?,?,?,?,?,?,?,?,?,?)`, appId, messageId, 7, sessionId, 1, userId, 2, userId, 2, nowFormat) > 0
+			userType = 1
 		}
 		message_id = messageId
 		return messageId > 0 && sessionId > 0 && ok
@@ -893,7 +912,7 @@ func (b *MessaggeService) SaveAutoReplyMsg(userType, entId, entUserId, userId in
 		customer_service_id = entUserId
 		userid = userId
 		entid = entId
-		go UserSynchronousList(customer_service_id, userid, entid, message_id, nowFormat)
+		go UserSynchronousList(customer_service_id, userid, entid, message_id, nowFormat, userType)
 	}
 	return ok1, messageId
 }