|
|
@@ -649,8 +649,16 @@ public class CorpServiceImpl implements CorpService {
|
|
|
corpKfAccountSessionChat.setOpenKfId(openKfid);
|
|
|
corpKfAccountSessionChat.setMsgid(msgId);
|
|
|
if (StrUtil.isEmpty(servicerUserId)) {
|
|
|
- ServiceStateResponse corpKfSessionStatus = wxCorpOps.getCorpKfSessionStatus(corpId, openKfId, externalUserId);
|
|
|
- servicerUserId = corpKfSessionStatus.getServicer_userid();
|
|
|
+ //寻找产生最近的接待记录
|
|
|
+ CorpKfServicerSessionRecord corpKfServicerSessionRecord = corpKfServicerSessionRecordMapper.selectOne(Wrappers.lambdaQuery(CorpKfServicerSessionRecord.class)
|
|
|
+ .eq(CorpKfServicerSessionRecord::getOpenKfId, openKfId)
|
|
|
+ .eq(CorpKfServicerSessionRecord::getExternalUserid, externalUserId)
|
|
|
+ .le(CorpKfServicerSessionRecord::getStartTime, sendTime)
|
|
|
+ .orderByDesc(CorpKfServicerSessionRecord::getId)
|
|
|
+ .last("limit 1"));
|
|
|
+ if (corpKfServicerSessionRecord != null) {
|
|
|
+ servicerUserId = corpKfServicerSessionRecord.getServicerUserid();
|
|
|
+ }
|
|
|
}
|
|
|
corpKfAccountSessionChat.setServicerUserid(servicerUserId);
|
|
|
corpKfAccountSessionChat.setExternalUserid(externalUserId);
|
|
|
@@ -662,7 +670,7 @@ public class CorpServiceImpl implements CorpService {
|
|
|
|
|
|
if (StrUtil.isNotEmpty(externalUserId)) {
|
|
|
//会话状态为待处理 则分配接待人员
|
|
|
- assignKfSession(corpId, openKfId, externalUserId, corpKfAccountSessionConfig);
|
|
|
+ assignKfSession(corpId, openKfId, externalUserId, corpKfAccountSessionConfig, corpKfAccountSessionChat.getSendDate());
|
|
|
}
|
|
|
syncSessionSatisfaction(item);
|
|
|
}
|
|
|
@@ -704,8 +712,8 @@ public class CorpServiceImpl implements CorpService {
|
|
|
Integer changeType = event.getChangeType();
|
|
|
String servicerUserId = event.getServicerUserId();
|
|
|
String externalUserId = event.getExternalUserId();
|
|
|
- String msgId = wxCpKfMsgItem.getMsgId();
|
|
|
Long sendTime = wxCpKfMsgItem.getSendTime();
|
|
|
+ DateTime sendDate = DateTime.of(sendTime * 1000);
|
|
|
//1-从接待池接入会话 2-转接会话 3-结束会话 4-重新接入已结束/已转接会话
|
|
|
if (changeType == 1) {
|
|
|
CorpKfServicerSessionRecord newSession = new CorpKfServicerSessionRecord();
|
|
|
@@ -714,6 +722,7 @@ public class CorpServiceImpl implements CorpService {
|
|
|
newSession.setExternalUserid(externalUserId);
|
|
|
newSession.setChangeType(changeType);
|
|
|
newSession.setServiceState(0);
|
|
|
+ newSession.setStartTime(sendDate);
|
|
|
corpKfServicerSessionRecordMapper.insert(newSession);
|
|
|
//等待用户删除
|
|
|
delQueueUser(openKfId, externalUserId);
|
|
|
@@ -721,14 +730,14 @@ public class CorpServiceImpl implements CorpService {
|
|
|
//2-转接会话
|
|
|
if (changeType == 2) {
|
|
|
//设置表中会话状态
|
|
|
- setDbSessionState(openKfId, externalUserId, sendTime);
|
|
|
+ setDbSessionState(openKfId, externalUserId, sendDate);
|
|
|
//记录新的客服会话
|
|
|
String newServicerUserid = wxCpKfMsgItem.getNewServicerUserid();
|
|
|
- transCorpKfSessionToServicer(corpId, openKfId, newServicerUserid, externalUserId, changeType, 3, DateTime.of(sendTime * 1000));
|
|
|
+ transCorpKfSessionToServicer(corpId, openKfId, newServicerUserid, externalUserId, changeType, 3, sendDate);
|
|
|
}
|
|
|
//3-结束会话 4-重新接入已结束/已转接会话
|
|
|
if (changeType == 3 || changeType == 4) {
|
|
|
- setDbSessionState(openKfId, externalUserId, sendTime);
|
|
|
+ setDbSessionState(openKfId, externalUserId, sendDate);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -737,7 +746,7 @@ public class CorpServiceImpl implements CorpService {
|
|
|
*/
|
|
|
public void enterSessionEvent(CorpKfAccount corpKfAccount, CorpKfAccountSessionConfig corpKfAccountSessionConfig, String corpId, WxCpKfMsgListResp.WxCpKfMsgItem wxCpKfMsgItem) throws Exception {
|
|
|
String openKfId = corpKfAccount.getOpenKfId();
|
|
|
- DateTime sendTime = DateTime.of(wxCpKfMsgItem.getSendTime() * 1000);
|
|
|
+ DateTime sendDate = DateTime.of(wxCpKfMsgItem.getSendTime() * 1000);
|
|
|
WxCpKfEventMsg event = wxCpKfMsgItem.getEvent();
|
|
|
String welcomeCode = event.getWelcomeCode();
|
|
|
//如果满足发送欢迎语条件(条件为:用户在过去48小时里未收过欢迎语,且未向客服发过消息),会返回该字段。
|
|
|
@@ -760,7 +769,7 @@ public class CorpServiceImpl implements CorpService {
|
|
|
}
|
|
|
}
|
|
|
//分配接待人员
|
|
|
- assignKfSession(corpId, openKfId, event.getExternalUserId(), corpKfAccountSessionConfig);
|
|
|
+ assignKfSession(corpId, openKfId, event.getExternalUserId(), corpKfAccountSessionConfig, sendDate);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -811,7 +820,7 @@ public class CorpServiceImpl implements CorpService {
|
|
|
/**
|
|
|
* 会话状态为待处理 则分配接待人员
|
|
|
*/
|
|
|
- public void assignKfSession(String corpId, String openKfId, String externalUserid, CorpKfAccountSessionConfig corpKfAccountSessionConfig) throws Exception {
|
|
|
+ public void assignKfSession(String corpId, String openKfId, String externalUserid, CorpKfAccountSessionConfig corpKfAccountSessionConfig, Date sendDate) throws Exception {
|
|
|
//查询用户会话状态 0待处理就进行处理
|
|
|
ServiceStateResponse serviceStateResponse = wxCorpOps.getCorpKfSessionStatus(corpId, openKfId, externalUserid);
|
|
|
Integer state = serviceStateResponse.getService_state();
|
|
|
@@ -874,7 +883,7 @@ public class CorpServiceImpl implements CorpService {
|
|
|
//随机分配一个客服
|
|
|
CorpKfServicerResp.CorpKfServicer corpKfServicer = corpKfServicers.get(RandomUtil.randomInt(corpKfServicers.size()));
|
|
|
//变更会话状态
|
|
|
- transCorpKfSessionToServicer(corpId, openKfId, corpKfServicer.getUserid(), externalUserid, null, 3, DateTime.now());
|
|
|
+ transCorpKfSessionToServicer(corpId, openKfId, corpKfServicer.getUserid(), externalUserid, null, 3, sendDate);
|
|
|
return;
|
|
|
}
|
|
|
//筛选符合条件的客服
|
|
|
@@ -893,7 +902,7 @@ public class CorpServiceImpl implements CorpService {
|
|
|
//选择第一个分配接待
|
|
|
CorpKfServicerDto corpKfServicerDto = filterKfCs.get(0);
|
|
|
//变更会话状态
|
|
|
- transCorpKfSessionToServicer(corpId, openKfId, corpKfServicerDto.getServicerUserid(), externalUserid, null, 3, DateTime.now());
|
|
|
+ transCorpKfSessionToServicer(corpId, openKfId, corpKfServicerDto.getServicerUserid(), externalUserid, null, 3, sendDate);
|
|
|
}
|
|
|
|
|
|
private void moveWaitingQueue(String corpId, String openKfId, String externalUserId) throws Exception {
|
|
|
@@ -927,13 +936,13 @@ public class CorpServiceImpl implements CorpService {
|
|
|
/**
|
|
|
* 设置会话记录状态
|
|
|
*/
|
|
|
- public void setDbSessionState(String openKfId, String externalUserId, Long sendTime) throws Exception {
|
|
|
+ public void setDbSessionState(String openKfId, String externalUserId, Date sendDate) throws Exception {
|
|
|
CorpKfServicerSessionRecord corpKfServicerSessionRecord = corpKfServicerSessionRecordMapper.selectOne(Wrappers.lambdaQuery(CorpKfServicerSessionRecord.class)
|
|
|
.eq(CorpKfServicerSessionRecord::getOpenKfId, openKfId)
|
|
|
.eq(CorpKfServicerSessionRecord::getExternalUserid, externalUserId)
|
|
|
.last("limit 1"));
|
|
|
if (corpKfServicerSessionRecord != null) {
|
|
|
- corpKfServicerSessionRecord.setCloseTime(DateTime.of(sendTime * 1000));
|
|
|
+ corpKfServicerSessionRecord.setCloseTime(sendDate);
|
|
|
corpKfServicerSessionRecord.setServiceState(1);
|
|
|
wxCorpOps.sendSatisfactionMsg(corpKfServicerSessionRecord.getId(), openKfId, externalUserId);
|
|
|
corpKfServicerSessionRecord.setSendSatisfaction(true);
|