|
@@ -609,7 +609,7 @@ public class CorpServiceImpl implements CorpService {
|
|
|
//进入会话事件
|
|
//进入会话事件
|
|
|
enterSessionEvent(corpKfAccount, corpKfAccountSessionConfig, corpId, enterSessionList);
|
|
enterSessionEvent(corpKfAccount, corpKfAccountSessionConfig, corpId, enterSessionList);
|
|
|
//会话更变事件
|
|
//会话更变事件
|
|
|
- sessionStatusChange(corpId, openKfId, sessionStatusChanges);
|
|
|
|
|
|
|
+ sessionStatusChange(corpId, openKfId, sessionStatusChanges, corpKfAccountSessionConfig);
|
|
|
//同步客服聊天记录
|
|
//同步客服聊天记录
|
|
|
syncChatMsg(openKfId, mergedMsgs);
|
|
syncChatMsg(openKfId, mergedMsgs);
|
|
|
//同步满意度
|
|
//同步满意度
|
|
@@ -670,31 +670,55 @@ public class CorpServiceImpl implements CorpService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private void sessionStatusChange(String corpId, String openKfId, List<WxCpKfMsgListResp.WxCpKfMsgItem> sessionStatusChanges) throws Exception {
|
|
|
|
|
|
|
+ private void sessionStatusChange(String corpId, String openKfId, List<WxCpKfMsgListResp.WxCpKfMsgItem> sessionStatusChanges, CorpKfAccountSessionConfig corpKfAccountSessionConfig) throws Exception {
|
|
|
if (CollUtil.isNotEmpty(sessionStatusChanges)) {
|
|
if (CollUtil.isNotEmpty(sessionStatusChanges)) {
|
|
|
WxCpKfMsgListResp.WxCpKfMsgItem wxCpKfMsgItem = sessionStatusChanges.get(sessionStatusChanges.size() - 1);
|
|
WxCpKfMsgListResp.WxCpKfMsgItem wxCpKfMsgItem = sessionStatusChanges.get(sessionStatusChanges.size() - 1);
|
|
|
- String externalUserId = wxCpKfMsgItem.getExternalUserId();
|
|
|
|
|
- String oldServicerUserid = wxCpKfMsgItem.getOldServicerUserid();
|
|
|
|
|
CorpKfServicerSessionRecord corpKfServicerSessionRecord = corpKfServicerSessionRecordMapper.selectOne(Wrappers.lambdaQuery(CorpKfServicerSessionRecord.class)
|
|
CorpKfServicerSessionRecord corpKfServicerSessionRecord = corpKfServicerSessionRecordMapper.selectOne(Wrappers.lambdaQuery(CorpKfServicerSessionRecord.class)
|
|
|
.eq(CorpKfServicerSessionRecord::getOpenKfId, openKfId)
|
|
.eq(CorpKfServicerSessionRecord::getOpenKfId, openKfId)
|
|
|
- .eq(CorpKfServicerSessionRecord::getServicerUserId, oldServicerUserid)
|
|
|
|
|
- .eq(CorpKfServicerSessionRecord::getExternalUserid, externalUserId)
|
|
|
|
|
|
|
+ .eq(CorpKfServicerSessionRecord::getMsgId, wxCpKfMsgItem.getMsgId())
|
|
|
.last("limit 1"));
|
|
.last("limit 1"));
|
|
|
|
|
+ Integer changeType = null;
|
|
|
if (corpKfServicerSessionRecord != null) {
|
|
if (corpKfServicerSessionRecord != null) {
|
|
|
- corpKfServicerSessionRecord.setServiceState(2);
|
|
|
|
|
- corpKfServicerSessionRecordMapper.updateById(corpKfServicerSessionRecord);
|
|
|
|
|
|
|
+ WxCpKfEventMsg event = wxCpKfMsgItem.getEvent();
|
|
|
|
|
+ //变更类型,均为接待人员在企业微信客户端操作触发。1-从接待池接入会话 2-转接会话 3-结束会话 4-重新接入已结束/已转接会话
|
|
|
|
|
+ changeType = event.getChangeType();
|
|
|
|
|
+ //老会话已结束
|
|
|
|
|
+ if (changeType != 1) {
|
|
|
|
|
+ corpKfServicerSessionRecord.setServiceState(changeType == 3 ? 1 : 2);
|
|
|
|
|
+ corpKfServicerSessionRecordMapper.updateById(corpKfServicerSessionRecord);
|
|
|
|
|
+ //优先分配等待池中的用户
|
|
|
|
|
+ assignWaitingQueueUser(corpId, openKfId, wxCpKfMsgItem.getServicerUserId(), corpKfAccountSessionConfig);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+ //转接会话
|
|
|
String newServicerUserid = wxCpKfMsgItem.getNewServicerUserid();
|
|
String newServicerUserid = wxCpKfMsgItem.getNewServicerUserid();
|
|
|
-
|
|
|
|
|
- CorpKfServicerSessionRecord corpKfServicerSessionRecord1 = corpKfServicerSessionRecordMapper.selectOne(Wrappers.lambdaQuery(CorpKfServicerSessionRecord.class)
|
|
|
|
|
- .eq(CorpKfServicerSessionRecord::getOpenKfId, openKfId)
|
|
|
|
|
- .eq(CorpKfServicerSessionRecord::getServicerUserId, newServicerUserid)
|
|
|
|
|
- .eq(CorpKfServicerSessionRecord::getExternalUserid, externalUserId)
|
|
|
|
|
- .eq(CorpKfServicerSessionRecord::getServiceState, 0)
|
|
|
|
|
- .last("limit 1"));
|
|
|
|
|
- if (corpKfServicerSessionRecord1 == null) {
|
|
|
|
|
|
|
+ if (StrUtil.isNotEmpty(newServicerUserid)) {
|
|
|
//记录新的客服会话
|
|
//记录新的客服会话
|
|
|
- transCorpKfSessionToServicer(corpId, openKfId, newServicerUserid, externalUserId);
|
|
|
|
|
|
|
+ transCorpKfSessionToServicer(corpId, openKfId, newServicerUserid, wxCpKfMsgItem.getExternalUserId(), changeType);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Transactional(rollbackFor = Throwable.class)
|
|
|
|
|
+ public void assignWaitingQueueUser(String corpId, String openKfId, String servicerUserid, CorpKfAccountSessionConfig corpKfAccountSessionConfig) throws Exception {
|
|
|
|
|
+ CorpKfWaitingQueueUser corpKfWaitingQueueUser = corpKfWaitingQueueUserMapper.selectOne(Wrappers.lambdaQuery(CorpKfWaitingQueueUser.class)
|
|
|
|
|
+ .last("limit 1"));
|
|
|
|
|
+ if (corpKfWaitingQueueUser == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ String externalUserid = corpKfWaitingQueueUser.getExternalUserid();
|
|
|
|
|
+ Integer selectCount = corpKfServicerSessionRecordMapper.selectCount(Wrappers.lambdaQuery(CorpKfServicerSessionRecord.class)
|
|
|
|
|
+ .eq(CorpKfServicerSessionRecord::getExternalUserid, corpKfWaitingQueueUser.getExternalUserid()));
|
|
|
|
|
+ if (selectCount == 0) {
|
|
|
|
|
+ if (corpKfAccountSessionConfig != null) {
|
|
|
|
|
+ Integer maxNum = corpKfServicerSessionRecordMapper.selectCount(Wrappers.lambdaQuery(CorpKfServicerSessionRecord.class)
|
|
|
|
|
+ .eq(CorpKfServicerSessionRecord::getServicerUserId, servicerUserid)
|
|
|
|
|
+ .eq(CorpKfServicerSessionRecord::getServiceState, 0));
|
|
|
|
|
+ if (maxNum < corpKfAccountSessionConfig.getMaxNum()) {
|
|
|
|
|
+ //记录新的客服会话
|
|
|
|
|
+ transCorpKfSessionToServicer(corpId, openKfId, servicerUserid, externalUserid, null);
|
|
|
|
|
+ corpKfWaitingQueueUserMapper.deleteById(corpKfWaitingQueueUser.getId());
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -788,7 +812,7 @@ public class CorpServiceImpl implements CorpService {
|
|
|
//随机分配一个客服
|
|
//随机分配一个客服
|
|
|
CorpKfServicerResp.CorpKfServicer corpKfServicer = corpKfServicers.get(RandomUtil.randomInt(corpKfServicers.size()));
|
|
CorpKfServicerResp.CorpKfServicer corpKfServicer = corpKfServicers.get(RandomUtil.randomInt(corpKfServicers.size()));
|
|
|
//变更会话状态
|
|
//变更会话状态
|
|
|
- transCorpKfSessionToServicer(corpId, openKfId, corpKfServicer.getUserid(), event.getExternalUserId());
|
|
|
|
|
|
|
+ transCorpKfSessionToServicer(corpId, openKfId, corpKfServicer.getUserid(), event.getExternalUserId(), null);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
//筛选符合条件的客服
|
|
//筛选符合条件的客服
|
|
@@ -806,23 +830,28 @@ public class CorpServiceImpl implements CorpService {
|
|
|
//选择第一个分配接待
|
|
//选择第一个分配接待
|
|
|
CorpKfServicerDto corpKfServicerDto = filterKfCs.get(0);
|
|
CorpKfServicerDto corpKfServicerDto = filterKfCs.get(0);
|
|
|
//变更会话状态
|
|
//变更会话状态
|
|
|
- transCorpKfSessionToServicer(corpId, openKfId, corpKfServicerDto.getServicerUserid(), event.getExternalUserId());
|
|
|
|
|
|
|
+ transCorpKfSessionToServicer(corpId, openKfId, corpKfServicerDto.getServicerUserid(), event.getExternalUserId(), null);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 变更用户会话状态
|
|
* 变更用户会话状态
|
|
|
*/
|
|
*/
|
|
|
- private void transCorpKfSessionToServicer(String corpId, String openKfId, String userid, String externalUserId) throws Exception {
|
|
|
|
|
- //记录接待人员会话
|
|
|
|
|
- CorpKfServicerSessionRecord corpKfServicerSessionRecord = new CorpKfServicerSessionRecord();
|
|
|
|
|
- corpKfServicerSessionRecord.setOpenKfId(openKfId);
|
|
|
|
|
- corpKfServicerSessionRecord.setServiceState(0);
|
|
|
|
|
- corpKfServicerSessionRecord.setServicerUserId(userid);
|
|
|
|
|
- corpKfServicerSessionRecord.setExternalUserid(externalUserId);
|
|
|
|
|
- corpKfServicerSessionRecordMapper.insert(corpKfServicerSessionRecord);
|
|
|
|
|
- //调用微信客服接口 变更会话状态
|
|
|
|
|
- wxCorpOps.transCorpKfSessionToServicer(corpId, openKfId, userid, externalUserId);
|
|
|
|
|
|
|
+ private void transCorpKfSessionToServicer(String corpId, String openKfId, String userid, String externalUserId, Integer changeType) throws Exception {
|
|
|
|
|
+ try {
|
|
|
|
|
+ //记录接待人员会话
|
|
|
|
|
+ CorpKfServicerSessionRecord corpKfServicerSessionRecord = new CorpKfServicerSessionRecord();
|
|
|
|
|
+ corpKfServicerSessionRecord.setOpenKfId(openKfId);
|
|
|
|
|
+ corpKfServicerSessionRecord.setServiceState(0);
|
|
|
|
|
+ corpKfServicerSessionRecord.setServicerUserId(userid);
|
|
|
|
|
+ corpKfServicerSessionRecord.setExternalUserid(externalUserId);
|
|
|
|
|
+ corpKfServicerSessionRecord.setChangeType(changeType);
|
|
|
|
|
+ corpKfServicerSessionRecordMapper.insert(corpKfServicerSessionRecord);
|
|
|
|
|
+ //调用微信客服接口 变更会话状态
|
|
|
|
|
+ wxCorpOps.transCorpKfSessionToServicer(corpId, openKfId, userid, externalUserId);
|
|
|
|
|
+ } catch (DuplicateKeyException e) {
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|