zoujiajian 1 год назад
Родитель
Сommit
93ed1b5f29

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

@@ -17,5 +17,5 @@ public class CorpKfAccountSyncMsgProgress extends BaseEntity{
 	/**
 	 * 上一次调用时返回的next_cursor
 	 */
-	private String cursor;
+	private String nextCursor;
 }

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

@@ -548,8 +548,8 @@ public class CorpServiceImpl implements CorpService {
 					.eq(CorpKfAccountSyncMsgProgress::getOpenKfId, openKfId)
 					.last("limit 1"))).orElse(new CorpKfAccountSyncMsgProgress());
 			String cursor = null;
-			if (corpKfAccountSyncMsgProgress.getCursor() != null) {
-				cursor = corpKfAccountSyncMsgProgress.getCursor();
+			if (corpKfAccountSyncMsgProgress.getNextCursor() != null) {
+				cursor = corpKfAccountSyncMsgProgress.getNextCursor();
 			}
 			String corpId = message.getToUserName();
 			String token = message.getToken();
@@ -560,7 +560,7 @@ public class CorpServiceImpl implements CorpService {
 				corpKfAccountSyncMsgProgressMapper.insert(corpKfAccountSyncMsgProgress);
 			} else corpKfAccountSyncMsgProgressMapper.updateById(corpKfAccountSyncMsgProgress);
 		} catch (Exception e) {
-			log.error("企业微信客服 事件消息回调 错误");
+			log.error("企业微信客服 事件消息回调 错误,e:{}", StringUtil.getErrorText(e));
 			throw BusinessRuntimeException.getInstance(StringUtil.getErrorMsg(e));
 		}
 		return null;
@@ -603,9 +603,13 @@ public class CorpServiceImpl implements CorpService {
 				mergedMsgs.add(mergedMsg);
 			}
 			if (StrUtil.equals("text", item.getMsgType())) {
+				if (textList == null) {
+					textList = new ArrayList<>();
+				}
 				textList.add(item);
 			}
 		}
+		cursor = wxCpKfMsgListResp.getNextCursor();
 		//进入会话事件
 		enterSessionEvent(corpKfAccount, corpKfAccountSessionConfig, corpId, enterSessionList);
 		//会话更变事件
@@ -614,7 +618,7 @@ public class CorpServiceImpl implements CorpService {
 		syncChatMsg(openKfId, mergedMsgs);
 		//同步满意度
 		syncSessionSatisfaction(openKfId, textList);
-		corpKfAccountSyncMsgProgress.setCursor(cursor);
+		corpKfAccountSyncMsgProgress.setNextCursor(cursor);
 		//同步信息
 		while (wxCpKfMsgListResp.getHasMore() == 1) {
 			syncCorpKfMsg(corpKfAccount, corpKfAccountSessionConfig, corpId, wxCpKfMsgListResp.getNextCursor(), token, limit, corpKfAccountSyncMsgProgress);
@@ -622,6 +626,9 @@ public class CorpServiceImpl implements CorpService {
 	}
 
 	private void syncSessionSatisfaction(String openKfId, List<WxCpKfMsgListResp.WxCpKfMsgItem> textList) {
+		if (textList == null) {
+			return;
+		}
 		Integer satisfaction = null;
 		for (WxCpKfMsgListResp.WxCpKfMsgItem item : textList) {
 			WxCorpTextMsg text = item.getText();
@@ -650,6 +657,9 @@ public class CorpServiceImpl implements CorpService {
 	}
 
 	private void syncChatMsg(String openKfId, List<WxCorpChatMsg> mergedMsgs) {
+		if (mergedMsgs == null) {
+			return;
+		}
 		CorpKfAccountSessionChat corpKfAccountSessionChat = null;
 		for (WxCorpChatMsg mergedMsg : mergedMsgs) {
 			String servicerUserid = mergedMsg.getServicer_userid();
@@ -728,14 +738,10 @@ public class CorpServiceImpl implements CorpService {
 	 */
 	public void enterSessionEvent(CorpKfAccount corpKfAccount, CorpKfAccountSessionConfig corpKfAccountSessionConfig, String corpId, List<WxCpKfMsgListResp.WxCpKfMsgItem> enterSessionList) throws Exception {
 		String openKfId = corpKfAccount.getOpenKfId();
-		if (enterSessionList.size() > 0) {
+		if (enterSessionList != null && enterSessionList.size() > 0) {
 			WxCpKfMsgListResp.WxCpKfMsgItem wxCpKfMsgItem = enterSessionList.get(enterSessionList.size() - 1);
 			WxCpKfEventMsg event = wxCpKfMsgItem.getEvent();
 			String welcomeCode = event.getWelcomeCode();
-			if (corpKfAccountSessionConfig == null) {
-				log.info("openKfId:{}未设置会话设置", openKfId);
-				return;
-			}
 			//如果满足发送欢迎语条件(条件为:用户在过去48小时里未收过欢迎语,且未向客服发过消息),会返回该字段。
 			//可用该welcome_code调用发送事件响应消息接口给客户发送欢迎语。
 			if (StrUtil.isNotEmpty(welcomeCode)) {
@@ -743,26 +749,23 @@ public class CorpServiceImpl implements CorpService {
 				wxCpKfMsgSendRequest.setMsgType("text");
 				wxCpKfMsgSendRequest.setCode(welcomeCode);
 				WxCorpKfMsgSendRequest.WxCpKfTextMsg textMsg = new WxCorpKfMsgSendRequest.WxCpKfTextMsg();
-				if (StrUtil.isEmpty(corpKfAccountSessionConfig.getWelcomeContent())) {
-					log.info("openKfId:{}未设置会话欢迎语设置", openKfId);
-					return;
-				}
-				textMsg.setContent(corpKfAccountSessionConfig.getWelcomeContent());
-				wxCpKfMsgSendRequest.setText(textMsg);
-				wxCpKfMsgSendRequest.setToUser(welcomeCode);
-				wxCpKfMsgSendRequest.setOpenKfid(event.getOpenKfid());
-				wxCorpOps.sendMsgOnEvent(corpId, wxCpKfMsgSendRequest);
-			} else {
-				//用户是否已有会话
-				Integer selectCount = corpKfServicerSessionRecordMapper.selectCount(Wrappers.lambdaQuery(CorpKfServicerSessionRecord.class)
-						.eq(CorpKfServicerSessionRecord::getOpenKfId, openKfId)
-						.eq(CorpKfServicerSessionRecord::getExternalUserid, event.getExternalUserId())
-						.eq(CorpKfServicerSessionRecord::getServiceState, 0));
-				if (selectCount > 0) {
-					log.info("external_userid:{}已有未结束的会话,无需分配", event.getExternalUserId());
-					return;
+				if (corpKfAccountSessionConfig != null && StrUtil.isNotEmpty(corpKfAccountSessionConfig.getWelcomeContent())) {
+					textMsg.setContent(corpKfAccountSessionConfig.getWelcomeContent());
+					wxCpKfMsgSendRequest.setText(textMsg);
+					wxCpKfMsgSendRequest.setToUser(welcomeCode);
+					wxCpKfMsgSendRequest.setOpenKfid(event.getOpenKfid());
+					wxCorpOps.sendMsgOnEvent(corpId, wxCpKfMsgSendRequest);
 				}
 			}
+			//用户是否已有会话
+			Integer selectCount = corpKfServicerSessionRecordMapper.selectCount(Wrappers.lambdaQuery(CorpKfServicerSessionRecord.class)
+					.eq(CorpKfServicerSessionRecord::getOpenKfId, openKfId)
+					.eq(CorpKfServicerSessionRecord::getExternalUserid, event.getExternalUserId())
+					.eq(CorpKfServicerSessionRecord::getServiceState, 0));
+			if (selectCount > 0) {
+				log.info("external_userid:{}已有未结束的会话,无需分配", event.getExternalUserId());
+				return;
+			}
 			//是否设置非值班提示
 			if (corpKfAccountSessionConfig != null && StrUtil.isNotEmpty(corpKfAccountSessionConfig.getNoDutyTips())) {
 				DateTime now = DateTime.now();
@@ -801,8 +804,10 @@ public class CorpServiceImpl implements CorpService {
 			//没有值班人员 接入等待池
 			if (CollUtil.isEmpty(corpKfServicers)) {
 				moveWaitingQueue(corpId, openKfId, event.getExternalUserId());
-				String queueTips = corpKfAccountSessionConfig.getQueueTips();
-				sendCorpKfTextTips(corpId, event.getExternalUserId(), openKfId, queueTips);
+				if (corpKfAccountSessionConfig != null) {
+					String queueTips = corpKfAccountSessionConfig.getQueueTips();
+					sendCorpKfTextTips(corpId, event.getExternalUserId(), openKfId, queueTips);
+				}
 				return;
 			}
 			//是否有空闲接待人员