|
|
@@ -648,6 +648,10 @@ public class CorpServiceImpl implements CorpService {
|
|
|
String msgType = item.getMsgType();
|
|
|
corpKfAccountSessionChat.setOpenKfId(openKfid);
|
|
|
corpKfAccountSessionChat.setMsgid(msgId);
|
|
|
+ if (StrUtil.isEmpty(servicerUserId)) {
|
|
|
+ ServiceStateResponse corpKfSessionStatus = wxCorpOps.getCorpKfSessionStatus(corpId, openKfId, externalUserId);
|
|
|
+ servicerUserId = corpKfSessionStatus.getServicer_userid();
|
|
|
+ }
|
|
|
corpKfAccountSessionChat.setServicerUserid(servicerUserId);
|
|
|
corpKfAccountSessionChat.setExternalUserid(externalUserId);
|
|
|
corpKfAccountSessionChat.setOrign(origin);
|
|
|
@@ -660,32 +664,37 @@ public class CorpServiceImpl implements CorpService {
|
|
|
//会话状态为待处理 则分配接待人员
|
|
|
assignKfSession(corpId, openKfId, externalUserId, corpKfAccountSessionConfig);
|
|
|
}
|
|
|
- syncSessionSatisfaction(openKfId, item);
|
|
|
+ syncSessionSatisfaction(item);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void syncSessionSatisfaction(String openKfId, WxCpKfMsgListResp.WxCpKfMsgItem item) throws Exception {
|
|
|
+ private void syncSessionSatisfaction(WxCpKfMsgListResp.WxCpKfMsgItem item) throws Exception {
|
|
|
Integer satisfaction = null;
|
|
|
WxCorpTextMsg text = item.getText();
|
|
|
//自定义菜单id
|
|
|
if (text.getMenu_id() != null) {
|
|
|
+ String[] split = text.getMenu_id().split("-");
|
|
|
+ if (split.length < 2) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String menuId = split[0];
|
|
|
+ String sessionId = split[1];
|
|
|
//满意
|
|
|
- if ("101".equals(text.getMenu_id())) {
|
|
|
+ if ("101".equals(menuId)) {
|
|
|
satisfaction = 1;
|
|
|
}
|
|
|
//一般
|
|
|
- if ("102".equals(text.getMenu_id())) {
|
|
|
+ if ("102".equals(menuId)) {
|
|
|
satisfaction = 2;
|
|
|
}
|
|
|
//不满意
|
|
|
- if ("103".equals(text.getMenu_id())) {
|
|
|
+ if ("103".equals(menuId)) {
|
|
|
satisfaction = 3;
|
|
|
}
|
|
|
if (satisfaction != null) {
|
|
|
corpKfServicerSessionRecordMapper.update(null, Wrappers.lambdaUpdate(CorpKfServicerSessionRecord.class)
|
|
|
.set(CorpKfServicerSessionRecord::getSatisfaction, satisfaction)
|
|
|
- .eq(CorpKfServicerSessionRecord::getOpenKfId, openKfId)
|
|
|
- .eq(CorpKfServicerSessionRecord::getMsgId, item.getMsgId()));
|
|
|
+ .eq(CorpKfServicerSessionRecord::getId, sessionId));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -705,7 +714,6 @@ public class CorpServiceImpl implements CorpService {
|
|
|
newSession.setExternalUserid(externalUserId);
|
|
|
newSession.setChangeType(changeType);
|
|
|
newSession.setServiceState(0);
|
|
|
- newSession.setMsgId(msgId);
|
|
|
corpKfServicerSessionRecordMapper.insert(newSession);
|
|
|
//等待用户删除
|
|
|
delQueueUser(openKfId, externalUserId);
|
|
|
@@ -716,7 +724,7 @@ public class CorpServiceImpl implements CorpService {
|
|
|
setDbSessionState(openKfId, externalUserId, sendTime);
|
|
|
//记录新的客服会话
|
|
|
String newServicerUserid = wxCpKfMsgItem.getNewServicerUserid();
|
|
|
- transCorpKfSessionToServicer(corpId, openKfId, newServicerUserid, externalUserId, changeType, 3);
|
|
|
+ transCorpKfSessionToServicer(corpId, openKfId, newServicerUserid, externalUserId, changeType, 3, DateTime.of(sendTime * 1000));
|
|
|
}
|
|
|
//3-结束会话 4-重新接入已结束/已转接会话
|
|
|
if (changeType == 3 || changeType == 4) {
|
|
|
@@ -758,9 +766,8 @@ public class CorpServiceImpl implements CorpService {
|
|
|
/**
|
|
|
* 变更用户会话状态
|
|
|
* serviceState 0未处理 1由智能助手接待 2待接入池排队中 3由人工接待 4 已结束/未开始
|
|
|
- *
|
|
|
*/
|
|
|
- private void transCorpKfSessionToServicer(String corpId, String openKfId, String userid, String externalUserId, Integer changeType, Integer serviceState) throws Exception {
|
|
|
+ private void transCorpKfSessionToServicer(String corpId, String openKfId, String userid, String externalUserId, Integer changeType, Integer serviceState, Date sendTime) throws Exception {
|
|
|
//记录接待人员会话
|
|
|
CorpKfServicerSessionRecord corpKfServicerSessionRecord = new CorpKfServicerSessionRecord();
|
|
|
corpKfServicerSessionRecord.setOpenKfId(openKfId);
|
|
|
@@ -768,6 +775,7 @@ public class CorpServiceImpl implements CorpService {
|
|
|
corpKfServicerSessionRecord.setServicerUserid(userid);
|
|
|
corpKfServicerSessionRecord.setExternalUserid(externalUserId);
|
|
|
corpKfServicerSessionRecord.setChangeType(changeType);
|
|
|
+ corpKfServicerSessionRecord.setStartTime(sendTime);
|
|
|
corpKfServicerSessionRecordMapper.insert(corpKfServicerSessionRecord);
|
|
|
//调用微信客服接口 变更会话状态
|
|
|
wxCorpOps.transCorpKfSessionToServicer(corpId, openKfId, userid, externalUserId, serviceState);
|
|
|
@@ -783,7 +791,8 @@ public class CorpServiceImpl implements CorpService {
|
|
|
return;
|
|
|
}
|
|
|
//查询会话状态
|
|
|
- Integer state = wxCorpOps.getCorpKfSessionStatus(corpId, openKfId, externalUserid);
|
|
|
+ ServiceStateResponse serviceStateResponse = wxCorpOps.getCorpKfSessionStatus(corpId, openKfId, externalUserid);
|
|
|
+ Integer state = serviceStateResponse.getService_state();
|
|
|
//0.未处理 1.人工智能接待 可调用api发送消息
|
|
|
if (state == null || state != 0 || state != 1) {
|
|
|
log.info("目前openKfId:{}用户eid:{}会话处于状态中state:{},无法发送消息", openKfId, externalUserid, state);
|
|
|
@@ -804,8 +813,9 @@ public class CorpServiceImpl implements CorpService {
|
|
|
*/
|
|
|
public void assignKfSession(String corpId, String openKfId, String externalUserid, CorpKfAccountSessionConfig corpKfAccountSessionConfig) throws Exception {
|
|
|
//查询用户会话状态 0待处理就进行处理
|
|
|
- Integer sessionStatus = wxCorpOps.getCorpKfSessionStatus(corpId, openKfId, externalUserid);
|
|
|
- if (sessionStatus != 0) {
|
|
|
+ ServiceStateResponse serviceStateResponse = wxCorpOps.getCorpKfSessionStatus(corpId, openKfId, externalUserid);
|
|
|
+ Integer state = serviceStateResponse.getService_state();
|
|
|
+ if (state != 0) {
|
|
|
return;
|
|
|
}
|
|
|
//用户是否已有会话
|
|
|
@@ -864,7 +874,7 @@ public class CorpServiceImpl implements CorpService {
|
|
|
//随机分配一个客服
|
|
|
CorpKfServicerResp.CorpKfServicer corpKfServicer = corpKfServicers.get(RandomUtil.randomInt(corpKfServicers.size()));
|
|
|
//变更会话状态
|
|
|
- transCorpKfSessionToServicer(corpId, openKfId, corpKfServicer.getUserid(), externalUserid, null, 3);
|
|
|
+ transCorpKfSessionToServicer(corpId, openKfId, corpKfServicer.getUserid(), externalUserid, null, 3, DateTime.now());
|
|
|
return;
|
|
|
}
|
|
|
//筛选符合条件的客服
|
|
|
@@ -883,7 +893,7 @@ public class CorpServiceImpl implements CorpService {
|
|
|
//选择第一个分配接待
|
|
|
CorpKfServicerDto corpKfServicerDto = filterKfCs.get(0);
|
|
|
//变更会话状态
|
|
|
- transCorpKfSessionToServicer(corpId, openKfId, corpKfServicerDto.getServicerUserid(), externalUserid, null, 3);
|
|
|
+ transCorpKfSessionToServicer(corpId, openKfId, corpKfServicerDto.getServicerUserid(), externalUserid, null, 3, DateTime.now());
|
|
|
}
|
|
|
|
|
|
private void moveWaitingQueue(String corpId, String openKfId, String externalUserId) throws Exception {
|
|
|
@@ -925,7 +935,7 @@ public class CorpServiceImpl implements CorpService {
|
|
|
if (corpKfServicerSessionRecord != null) {
|
|
|
corpKfServicerSessionRecord.setCloseTime(DateTime.of(sendTime * 1000));
|
|
|
corpKfServicerSessionRecord.setServiceState(1);
|
|
|
- wxCorpOps.sendSatisfactionMsg(corpKfServicerSessionRecord.getMsgId());
|
|
|
+ wxCorpOps.sendSatisfactionMsg(corpKfServicerSessionRecord.getId(), openKfId, externalUserId);
|
|
|
corpKfServicerSessionRecord.setSendSatisfaction(true);
|
|
|
corpKfServicerSessionRecordMapper.updateById(corpKfServicerSessionRecord);
|
|
|
}
|