|
|
@@ -562,7 +562,6 @@ public class CorpServiceImpl implements CorpService {
|
|
|
} else corpKfAccountSyncMsgProgressMapper.updateById(corpKfAccountSyncMsgProgress);
|
|
|
} catch (Exception e) {
|
|
|
log.error("企业微信客服 事件消息回调 错误,e:{}", StringUtil.getErrorText(e));
|
|
|
- throw BusinessRuntimeException.getInstance(StringUtil.getErrorMsg(e));
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
@@ -653,7 +652,7 @@ public class CorpServiceImpl implements CorpService {
|
|
|
CorpKfServicerSessionRecord corpKfServicerSessionRecord = corpKfServicerSessionRecordMapper.selectOne(Wrappers.lambdaQuery(CorpKfServicerSessionRecord.class)
|
|
|
.eq(CorpKfServicerSessionRecord::getOpenKfId, openKfId)
|
|
|
.eq(CorpKfServicerSessionRecord::getExternalUserid, externalUserId)
|
|
|
- .le(CorpKfServicerSessionRecord::getStartTime, sendTime)
|
|
|
+ .and(qr -> qr.le(CorpKfServicerSessionRecord::getStartTime, sendTime).or().ge(CorpKfServicerSessionRecord::getCloseTime, sendTime))
|
|
|
.orderByDesc(CorpKfServicerSessionRecord::getId)
|
|
|
.last("limit 1"));
|
|
|
if (corpKfServicerSessionRecord != null) {
|
|
|
@@ -670,7 +669,7 @@ public class CorpServiceImpl implements CorpService {
|
|
|
|
|
|
if (StrUtil.isNotEmpty(externalUserId)) {
|
|
|
//会话状态为待处理 则分配接待人员
|
|
|
- assignKfSession(corpId, openKfId, externalUserId, corpKfAccountSessionConfig, corpKfAccountSessionChat.getSendDate());
|
|
|
+ assignKfSession(corpId, openKfId, externalUserId, corpKfAccountSessionConfig, corpKfAccountSessionChat.getSendDate(), msgId);
|
|
|
}
|
|
|
syncSessionSatisfaction(item);
|
|
|
}
|
|
|
@@ -680,13 +679,13 @@ public class CorpServiceImpl implements CorpService {
|
|
|
Integer satisfaction = null;
|
|
|
WxCorpTextMsg text = item.getText();
|
|
|
//自定义菜单id
|
|
|
- if (text.getMenu_id() != null) {
|
|
|
+ if (text != null && text.getMenu_id() != null) {
|
|
|
String[] split = text.getMenu_id().split("-");
|
|
|
if (split.length < 2) {
|
|
|
return;
|
|
|
}
|
|
|
String menuId = split[0];
|
|
|
- String sessionId = split[1];
|
|
|
+ String msgid = split[1];
|
|
|
//满意
|
|
|
if ("101".equals(menuId)) {
|
|
|
satisfaction = 1;
|
|
|
@@ -702,7 +701,7 @@ public class CorpServiceImpl implements CorpService {
|
|
|
if (satisfaction != null) {
|
|
|
corpKfServicerSessionRecordMapper.update(null, Wrappers.lambdaUpdate(CorpKfServicerSessionRecord.class)
|
|
|
.set(CorpKfServicerSessionRecord::getSatisfaction, satisfaction)
|
|
|
- .eq(CorpKfServicerSessionRecord::getId, sessionId));
|
|
|
+ .eq(CorpKfServicerSessionRecord::getMsgid, msgid));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -710,34 +709,38 @@ public class CorpServiceImpl implements CorpService {
|
|
|
private void sessionStatusChange(String corpId, String openKfId, WxCpKfMsgListResp.WxCpKfMsgItem wxCpKfMsgItem, CorpKfAccountSessionConfig corpKfAccountSessionConfig) throws Exception {
|
|
|
WxCpKfEventMsg event = wxCpKfMsgItem.getEvent();
|
|
|
Integer changeType = event.getChangeType();
|
|
|
- String servicerUserId = event.getServicerUserId();
|
|
|
String externalUserId = event.getExternalUserId();
|
|
|
Long sendTime = wxCpKfMsgItem.getSendTime();
|
|
|
DateTime sendDate = DateTime.of(sendTime * 1000);
|
|
|
//1-从接待池接入会话 2-转接会话 3-结束会话 4-重新接入已结束/已转接会话
|
|
|
+ String oldServicerUserId = event.getOldServicerUserId();
|
|
|
+ String newServicerUserId = event.getNewServicerUserId();
|
|
|
+ String msgId = wxCpKfMsgItem.getMsgId();
|
|
|
+ String msgCode = wxCpKfMsgItem.getEvent().getMsgCode();
|
|
|
if (changeType == 1) {
|
|
|
CorpKfServicerSessionRecord newSession = new CorpKfServicerSessionRecord();
|
|
|
newSession.setOpenKfId(openKfId);
|
|
|
- newSession.setServicerUserid(servicerUserId);
|
|
|
+ newSession.setServicerUserid(newServicerUserId);
|
|
|
newSession.setExternalUserid(externalUserId);
|
|
|
newSession.setChangeType(changeType);
|
|
|
newSession.setServiceState(0);
|
|
|
newSession.setStartTime(sendDate);
|
|
|
+ newSession.setMsgid(msgId);
|
|
|
corpKfServicerSessionRecordMapper.insert(newSession);
|
|
|
//等待用户删除
|
|
|
- delQueueUser(openKfId, externalUserId);
|
|
|
+ delQueueUser(openKfId, externalUserId, sendDate);
|
|
|
}
|
|
|
//2-转接会话
|
|
|
if (changeType == 2) {
|
|
|
//设置表中会话状态
|
|
|
- setDbSessionState(openKfId, externalUserId, sendDate);
|
|
|
+ setDbSessionState(openKfId, oldServicerUserId, externalUserId, sendDate, changeType, msgId, msgCode);
|
|
|
//记录新的客服会话
|
|
|
String newServicerUserid = wxCpKfMsgItem.getNewServicerUserid();
|
|
|
- transCorpKfSessionToServicer(corpId, openKfId, newServicerUserid, externalUserId, changeType, 3, sendDate);
|
|
|
+ transCorpKfSessionToServicer(corpId, openKfId, oldServicerUserId, newServicerUserid, externalUserId, changeType, 3, sendDate, msgId);
|
|
|
}
|
|
|
//3-结束会话 4-重新接入已结束/已转接会话
|
|
|
if (changeType == 3 || changeType == 4) {
|
|
|
- setDbSessionState(openKfId, externalUserId, sendDate);
|
|
|
+ setDbSessionState(openKfId, oldServicerUserId, externalUserId, sendDate, changeType, msgId, msgCode);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -749,6 +752,7 @@ public class CorpServiceImpl implements CorpService {
|
|
|
DateTime sendDate = DateTime.of(wxCpKfMsgItem.getSendTime() * 1000);
|
|
|
WxCpKfEventMsg event = wxCpKfMsgItem.getEvent();
|
|
|
String welcomeCode = event.getWelcomeCode();
|
|
|
+ String msgid = wxCpKfMsgItem.getMsgId();
|
|
|
//如果满足发送欢迎语条件(条件为:用户在过去48小时里未收过欢迎语,且未向客服发过消息),会返回该字段。
|
|
|
//可用该welcome_code调用发送事件响应消息接口给客户发送欢迎语。
|
|
|
if (StrUtil.isNotEmpty(welcomeCode)) {
|
|
|
@@ -769,27 +773,29 @@ public class CorpServiceImpl implements CorpService {
|
|
|
}
|
|
|
}
|
|
|
//分配接待人员
|
|
|
- assignKfSession(corpId, openKfId, event.getExternalUserId(), corpKfAccountSessionConfig, sendDate);
|
|
|
+ assignKfSession(corpId, openKfId, event.getExternalUserId(), corpKfAccountSessionConfig, sendDate, msgid);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 变更用户会话状态
|
|
|
* serviceState 0未处理 1由智能助手接待 2待接入池排队中 3由人工接待 4 已结束/未开始
|
|
|
*/
|
|
|
- private void transCorpKfSessionToServicer(String corpId, String openKfId, String userid, String externalUserId, Integer changeType, Integer serviceState, Date sendTime) throws Exception {
|
|
|
+ private void transCorpKfSessionToServicer(String corpId, String openKfId, String oldServicerUserId, String userid, String externalUserId, Integer changeType, Integer serviceState, Date sendTime, String msgid) throws Exception {
|
|
|
//记录接待人员会话
|
|
|
CorpKfServicerSessionRecord corpKfServicerSessionRecord = new CorpKfServicerSessionRecord();
|
|
|
corpKfServicerSessionRecord.setOpenKfId(openKfId);
|
|
|
corpKfServicerSessionRecord.setServiceState(0);
|
|
|
+ corpKfServicerSessionRecord.setFromUserid(oldServicerUserId);
|
|
|
corpKfServicerSessionRecord.setServicerUserid(userid);
|
|
|
corpKfServicerSessionRecord.setExternalUserid(externalUserId);
|
|
|
corpKfServicerSessionRecord.setChangeType(changeType);
|
|
|
corpKfServicerSessionRecord.setStartTime(sendTime);
|
|
|
+ corpKfServicerSessionRecord.setMsgid(msgid);
|
|
|
corpKfServicerSessionRecordMapper.insert(corpKfServicerSessionRecord);
|
|
|
//调用微信客服接口 变更会话状态
|
|
|
wxCorpOps.transCorpKfSessionToServicer(corpId, openKfId, userid, externalUserId, serviceState);
|
|
|
//等待用户删除
|
|
|
- delQueueUser(openKfId, externalUserId);
|
|
|
+ delQueueUser(openKfId, externalUserId, sendTime);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -820,7 +826,7 @@ public class CorpServiceImpl implements CorpService {
|
|
|
/**
|
|
|
* 会话状态为待处理 则分配接待人员
|
|
|
*/
|
|
|
- public void assignKfSession(String corpId, String openKfId, String externalUserid, CorpKfAccountSessionConfig corpKfAccountSessionConfig, Date sendDate) throws Exception {
|
|
|
+ public void assignKfSession(String corpId, String openKfId, String externalUserid, CorpKfAccountSessionConfig corpKfAccountSessionConfig, Date sendDate, String msgid) throws Exception {
|
|
|
//查询用户会话状态 0待处理就进行处理
|
|
|
ServiceStateResponse serviceStateResponse = wxCorpOps.getCorpKfSessionStatus(corpId, openKfId, externalUserid);
|
|
|
Integer state = serviceStateResponse.getService_state();
|
|
|
@@ -883,7 +889,7 @@ public class CorpServiceImpl implements CorpService {
|
|
|
//随机分配一个客服
|
|
|
CorpKfServicerResp.CorpKfServicer corpKfServicer = corpKfServicers.get(RandomUtil.randomInt(corpKfServicers.size()));
|
|
|
//变更会话状态
|
|
|
- transCorpKfSessionToServicer(corpId, openKfId, corpKfServicer.getUserid(), externalUserid, null, 3, sendDate);
|
|
|
+ transCorpKfSessionToServicer(corpId, openKfId, null, corpKfServicer.getUserid(), externalUserid, null, 3, sendDate, msgid);
|
|
|
return;
|
|
|
}
|
|
|
//筛选符合条件的客服
|
|
|
@@ -902,7 +908,7 @@ public class CorpServiceImpl implements CorpService {
|
|
|
//选择第一个分配接待
|
|
|
CorpKfServicerDto corpKfServicerDto = filterKfCs.get(0);
|
|
|
//变更会话状态
|
|
|
- transCorpKfSessionToServicer(corpId, openKfId, corpKfServicerDto.getServicerUserid(), externalUserid, null, 3, sendDate);
|
|
|
+ transCorpKfSessionToServicer(corpId, openKfId, null, corpKfServicerDto.getServicerUserid(), externalUserid, null, 3, sendDate, msgid);
|
|
|
}
|
|
|
|
|
|
private void moveWaitingQueue(String corpId, String openKfId, String externalUserId) throws Exception {
|
|
|
@@ -936,30 +942,47 @@ public class CorpServiceImpl implements CorpService {
|
|
|
/**
|
|
|
* 设置会话记录状态
|
|
|
*/
|
|
|
- public void setDbSessionState(String openKfId, String externalUserId, Date sendDate) throws Exception {
|
|
|
+ public void setDbSessionState(String openKfId, String servicerUserid, String externalUserId, Date sendDate, Integer changeType, String msgid, String msgCode) throws Exception {
|
|
|
CorpKfServicerSessionRecord corpKfServicerSessionRecord = corpKfServicerSessionRecordMapper.selectOne(Wrappers.lambdaQuery(CorpKfServicerSessionRecord.class)
|
|
|
.eq(CorpKfServicerSessionRecord::getOpenKfId, openKfId)
|
|
|
+ .eq(CorpKfServicerSessionRecord::getServicerUserid, servicerUserid)
|
|
|
.eq(CorpKfServicerSessionRecord::getExternalUserid, externalUserId)
|
|
|
.last("limit 1"));
|
|
|
if (corpKfServicerSessionRecord != null) {
|
|
|
corpKfServicerSessionRecord.setCloseTime(sendDate);
|
|
|
- corpKfServicerSessionRecord.setServiceState(1);
|
|
|
- wxCorpOps.sendSatisfactionMsg(corpKfServicerSessionRecord.getId(), openKfId, externalUserId);
|
|
|
- corpKfServicerSessionRecord.setSendSatisfaction(true);
|
|
|
+ corpKfServicerSessionRecord.setServiceState(changeType);
|
|
|
+ if (changeType != 2) {
|
|
|
+ try {
|
|
|
+ wxCorpOps.sendSatisfactionMsg(corpKfServicerSessionRecord.getMsgid(), openKfId, externalUserId, msgCode);
|
|
|
+ corpKfServicerSessionRecord.setSendSatisfaction(true);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("发送满意度调查内容错误:{}", StringUtil.getErrorText(e));
|
|
|
+ }
|
|
|
+ }
|
|
|
corpKfServicerSessionRecordMapper.updateById(corpKfServicerSessionRecord);
|
|
|
+ } else {
|
|
|
+ corpKfServicerSessionRecord = new CorpKfServicerSessionRecord();
|
|
|
+ corpKfServicerSessionRecord.setServicerUserid(servicerUserid);
|
|
|
+ corpKfServicerSessionRecord.setExternalUserid(externalUserId);
|
|
|
+ corpKfServicerSessionRecord.setServiceState(changeType);
|
|
|
+ corpKfServicerSessionRecord.setMsgid(msgid);
|
|
|
+ corpKfServicerSessionRecord.setCloseTime(sendDate);
|
|
|
+ corpKfServicerSessionRecordMapper.insert(corpKfServicerSessionRecord);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除等待池中用户
|
|
|
+ *
|
|
|
* @param openKfId
|
|
|
* @param externalUserid
|
|
|
*/
|
|
|
- public void delQueueUser(String openKfId, String externalUserid) {
|
|
|
+ public void delQueueUser(String openKfId, String externalUserid, Date sendDate) {
|
|
|
//等待用户删除
|
|
|
Optional.ofNullable(corpKfWaitingQueueUserMapper.selectOne(Wrappers.lambdaQuery(CorpKfWaitingQueueUser.class)
|
|
|
.eq(CorpKfWaitingQueueUser::getOpenKfId, openKfId)
|
|
|
.eq(CorpKfWaitingQueueUser::getExternalUserid, externalUserid)
|
|
|
+ .le(CorpKfWaitingQueueUser::getCreatedTime, sendDate)
|
|
|
.last("limit 1"))).ifPresent(queueUser -> corpKfWaitingQueueUserMapper.deleteById(queueUser.getId()));
|
|
|
}
|
|
|
}
|