Selaa lähdekoodia

fix 重新接入会话保持上下文聊天记录

zoujiajian 1 vuosi sitten
vanhempi
sitoutus
77f8c3977f

+ 7 - 1
netflix-dao/src/main/java/com/cyksj/model/entity/CorpKfServicerSessionRecord.java

@@ -1,5 +1,6 @@
 package com.cyksj.model.entity;
 
+import com.cyksj.model.BaseEntity;
 import lombok.Getter;
 import lombok.Setter;
 
@@ -58,4 +59,9 @@ public class CorpKfServicerSessionRecord extends BaseEntity{
 	 * 会话关闭时间
 	 */
 	private Date closeTime;
-}
+
+	/**
+	 * 是否自动关闭会话 默认false
+	 */
+	private Boolean isAutoClose;
+}

+ 29 - 12
netflix-service/src/main/java/com/cyksj/service/corp/impl/CorpServiceImpl.java

@@ -724,18 +724,35 @@ public class CorpServiceImpl implements CorpService {
 		String msgCode = wxCpKfMsgItem.getEvent().getMsgCode();
 		//1-从接待池接入会话 4-重新接入已结束/已转接会话
 		if (changeType == 1 || changeType == 4) {
-			CorpKfServicerSessionRecord newSession = new CorpKfServicerSessionRecord();
-			newSession.setOpenKfId(openKfId);
-			newSession.setServicerUserid(newServicerUserId);
-			newSession.setExternalUserid(externalUserId);
-			newSession.setChangeType(changeType);
-			newSession.setServiceState(0);
-			newSession.setStartTime(sendDate);
-			newSession.setMsgid(msgId);
-			corpKfServicerSessionRecordMapper.insert(newSession);
-			//等待用户删除
-			delQueueUser(openKfId, externalUserId, sendDate);
-			syncUserChatSession(newSession.getId(), externalUserId);
+			CorpKfServicerSessionRecord beforeRecord = null;
+			//重新接入会话 看之前是否有自动关闭的会话 保持上下文聊天记录
+			if (changeType == 4 && StrUtil.isNotBlank(newServicerUserId)) {
+				beforeRecord = corpKfServicerSessionRecordMapper.selectOne(Wrappers.lambdaQuery(CorpKfServicerSessionRecord.class)
+						.eq(CorpKfServicerSessionRecord::getServicerUserid, newServicerUserId)
+						.eq(CorpKfServicerSessionRecord::getExternalUserid, externalUserId)
+						.eq(CorpKfServicerSessionRecord::getServiceState, 1)
+						.eq(CorpKfServicerSessionRecord::getIsAutoClose, 1)
+						.orderByDesc(CorpKfServicerSessionRecord::getId)
+						.last("limit 1"));
+				if (beforeRecord != null) {
+					beforeRecord.setServiceState(0);
+					corpKfServicerSessionRecordMapper.updateById(beforeRecord);
+				}
+			}
+			if (beforeRecord == null) {
+				CorpKfServicerSessionRecord newSession = new CorpKfServicerSessionRecord();
+				newSession.setOpenKfId(openKfId);
+				newSession.setServicerUserid(newServicerUserId);
+				newSession.setExternalUserid(externalUserId);
+				newSession.setChangeType(changeType);
+				newSession.setServiceState(0);
+				newSession.setStartTime(sendDate);
+				newSession.setMsgid(msgId);
+				corpKfServicerSessionRecordMapper.insert(newSession);
+				//等待用户删除
+				delQueueUser(openKfId, externalUserId, sendDate);
+				syncUserChatSession(newSession.getId(), externalUserId);
+			}
 		}
 		//2-转接会话
 		if (changeType == 2) {