|
@@ -238,16 +238,16 @@ public class CorpServiceImpl implements CorpService {
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
.end()
|
|
.end()
|
|
|
-// //企业微信客服 用户进入会话事件
|
|
|
|
|
-// .rule().async(false).msgType("event").event("kf_msg_or_event")
|
|
|
|
|
-// .handler(new CorpMessageHandler() {
|
|
|
|
|
-// @Override
|
|
|
|
|
-// public CorpXmlOutMessage handle(CorpXmlMessage message, Map<String, Object> context, CorpService corpService) throws Exception {
|
|
|
|
|
-// //
|
|
|
|
|
-// return kfMsgOrEvent(message, context);
|
|
|
|
|
-// }
|
|
|
|
|
-// })
|
|
|
|
|
-// .end()
|
|
|
|
|
|
|
+ //企业微信客服 用户进入会话事件
|
|
|
|
|
+ .rule().async(false).msgType("event").event("kf_msg_or_event")
|
|
|
|
|
+ .handler(new CorpMessageHandler() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public CorpXmlOutMessage handle(CorpXmlMessage message, Map<String, Object> context, CorpService corpService) throws Exception {
|
|
|
|
|
+ //
|
|
|
|
|
+ return kfMsgOrEvent(message, context);
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ .end()
|
|
|
;
|
|
;
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -559,10 +559,6 @@ public class CorpServiceImpl implements CorpService {
|
|
|
String token = message.getToken();
|
|
String token = message.getToken();
|
|
|
syncCorpKfMsg(corpKfAccount, corpKfAccountSessionConfig, corpId, cursor, token, null, corpKfAccountSyncMsgProgress);
|
|
syncCorpKfMsg(corpKfAccount, corpKfAccountSessionConfig, corpId, cursor, token, null, corpKfAccountSyncMsgProgress);
|
|
|
corpKfAccountSyncMsgProgress.setOpenKfId(openKfId);
|
|
corpKfAccountSyncMsgProgress.setOpenKfId(openKfId);
|
|
|
- //同步记录
|
|
|
|
|
- if (corpKfAccountSyncMsgProgress.getId() == null) {
|
|
|
|
|
- corpKfAccountSyncMsgProgressMapper.insert(corpKfAccountSyncMsgProgress);
|
|
|
|
|
- } else corpKfAccountSyncMsgProgressMapper.updateById(corpKfAccountSyncMsgProgress);
|
|
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
log.error("企业微信客服 事件消息回调 错误,e:{}", StringUtil.getErrorText(e));
|
|
log.error("企业微信客服 事件消息回调 错误,e:{}", StringUtil.getErrorText(e));
|
|
|
}
|
|
}
|
|
@@ -572,6 +568,15 @@ public class CorpServiceImpl implements CorpService {
|
|
|
private void syncCorpKfMsg(CorpKfAccount corpKfAccount, CorpKfAccountSessionConfig corpKfAccountSessionConfig, String corpId, String cursor, String token, Integer limit, CorpKfAccountSyncMsgProgress corpKfAccountSyncMsgProgress) throws Exception {
|
|
private void syncCorpKfMsg(CorpKfAccount corpKfAccount, CorpKfAccountSessionConfig corpKfAccountSessionConfig, String corpId, String cursor, String token, Integer limit, CorpKfAccountSyncMsgProgress corpKfAccountSyncMsgProgress) throws Exception {
|
|
|
String openKfId = corpKfAccount.getOpenKfId();
|
|
String openKfId = corpKfAccount.getOpenKfId();
|
|
|
WxCpKfMsgListResp wxCpKfMsgListResp = wxCorpOps.syncMsg(corpId, cursor, token, limit, openKfId);
|
|
WxCpKfMsgListResp wxCpKfMsgListResp = wxCorpOps.syncMsg(corpId, cursor, token, limit, openKfId);
|
|
|
|
|
+ cursor = wxCpKfMsgListResp.getNextCursor();
|
|
|
|
|
+ corpKfAccountSyncMsgProgress.setNextCursor(cursor);
|
|
|
|
|
+ //同步记录
|
|
|
|
|
+ if (corpKfAccountSyncMsgProgress.getId() == null) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ corpKfAccountSyncMsgProgressMapper.insert(corpKfAccountSyncMsgProgress);
|
|
|
|
|
+ } catch (DuplicateKeyException e) {
|
|
|
|
|
+ }
|
|
|
|
|
+ } else corpKfAccountSyncMsgProgressMapper.updateById(corpKfAccountSyncMsgProgress);
|
|
|
List<WxCpKfMsgListResp.WxCpKfMsgItem> msgList = wxCpKfMsgListResp.getMsgList();
|
|
List<WxCpKfMsgListResp.WxCpKfMsgItem> msgList = wxCpKfMsgListResp.getMsgList();
|
|
|
for (WxCpKfMsgListResp.WxCpKfMsgItem item : msgList) {
|
|
for (WxCpKfMsgListResp.WxCpKfMsgItem item : msgList) {
|
|
|
if (item.getEvent() != null) {
|
|
if (item.getEvent() != null) {
|
|
@@ -589,12 +594,6 @@ public class CorpServiceImpl implements CorpService {
|
|
|
//同步微信客服账号信息
|
|
//同步微信客服账号信息
|
|
|
syncKfChatMsg(corpId, openKfId, corpKfAccountSessionConfig, item);
|
|
syncKfChatMsg(corpId, openKfId, corpKfAccountSessionConfig, item);
|
|
|
}
|
|
}
|
|
|
- cursor = wxCpKfMsgListResp.getNextCursor();
|
|
|
|
|
- corpKfAccountSyncMsgProgress.setNextCursor(cursor);
|
|
|
|
|
- //同步信息
|
|
|
|
|
-// while (wxCpKfMsgListResp.getHasMore() == 1) {
|
|
|
|
|
-// syncCorpKfMsg(corpKfAccount, corpKfAccountSessionConfig, corpId, wxCpKfMsgListResp.getNextCursor(), token, limit, corpKfAccountSyncMsgProgress);
|
|
|
|
|
-// }
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void syncKfChatMsg(String corpId, String openKfId, CorpKfAccountSessionConfig corpKfAccountSessionConfig, WxCpKfMsgListResp.WxCpKfMsgItem item) throws Exception {
|
|
private void syncKfChatMsg(String corpId, String openKfId, CorpKfAccountSessionConfig corpKfAccountSessionConfig, WxCpKfMsgListResp.WxCpKfMsgItem item) throws Exception {
|
|
@@ -656,13 +655,13 @@ public class CorpServiceImpl implements CorpService {
|
|
|
corpKfAccountSessionChat.setMsgType(msgType);
|
|
corpKfAccountSessionChat.setMsgType(msgType);
|
|
|
corpKfAccountSessionChat.setSendTime(sendTime);
|
|
corpKfAccountSessionChat.setSendTime(sendTime);
|
|
|
corpKfAccountSessionChat.setSendDate(DateTime.of(sendTime * 1000));
|
|
corpKfAccountSessionChat.setSendDate(DateTime.of(sendTime * 1000));
|
|
|
- saveChatMsg(corpKfAccountSessionChat);
|
|
|
|
|
-
|
|
|
|
|
- if (StrUtil.isNotEmpty(externalUserId)) {
|
|
|
|
|
- //会话状态为待处理 则分配接待人员
|
|
|
|
|
- assignKfSession(corpId, openKfId, externalUserId, corpKfAccountSessionConfig, corpKfAccountSessionChat.getSendDate(), msgId);
|
|
|
|
|
|
|
+ if (saveChatMsg(corpKfAccountSessionChat)) {
|
|
|
|
|
+ if (StrUtil.isNotEmpty(externalUserId)) {
|
|
|
|
|
+ //会话状态为待处理 则分配接待人员
|
|
|
|
|
+ assignKfSession(corpId, openKfId, externalUserId, corpKfAccountSessionConfig, corpKfAccountSessionChat.getSendDate(), msgId);
|
|
|
|
|
+ }
|
|
|
|
|
+ syncSessionSatisfaction(item);
|
|
|
}
|
|
}
|
|
|
- syncSessionSatisfaction(item);
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -863,10 +862,6 @@ public class CorpServiceImpl implements CorpService {
|
|
|
* 会话状态为待处理 则分配接待人员
|
|
* 会话状态为待处理 则分配接待人员
|
|
|
*/
|
|
*/
|
|
|
public void assignKfSession(String corpId, String openKfId, String externalUserid, CorpKfAccountSessionConfig corpKfAccountSessionConfig, Date sendDate, String msgid) throws Exception {
|
|
public void assignKfSession(String corpId, String openKfId, String externalUserid, CorpKfAccountSessionConfig corpKfAccountSessionConfig, Date sendDate, String msgid) throws Exception {
|
|
|
- //超过15分钟 进入会话时间不处理
|
|
|
|
|
- if (sendDate.compareTo(DateUtil.offsetMinute(DateTime.now(), -15)) <= 0) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
//查询用户会话状态 0待处理 1智能助手接待
|
|
//查询用户会话状态 0待处理 1智能助手接待
|
|
|
ServiceStateResponse serviceStateResponse = wxCorpOps.getCorpKfSessionStatus(corpId, openKfId, externalUserid);
|
|
ServiceStateResponse serviceStateResponse = wxCorpOps.getCorpKfSessionStatus(corpId, openKfId, externalUserid);
|
|
|
Integer state = serviceStateResponse.getService_state();
|
|
Integer state = serviceStateResponse.getService_state();
|
|
@@ -966,7 +961,7 @@ public class CorpServiceImpl implements CorpService {
|
|
|
/**
|
|
/**
|
|
|
* 新增记录
|
|
* 新增记录
|
|
|
*/
|
|
*/
|
|
|
- public void saveChatMsg(CorpKfAccountSessionChat chat) {
|
|
|
|
|
|
|
+ public Boolean saveChatMsg(CorpKfAccountSessionChat chat) {
|
|
|
CorpKfServicerSessionRecord corpKfServicerSessionRecord = corpKfServicerSessionRecordMapper.selectOne(Wrappers.lambdaQuery(CorpKfServicerSessionRecord.class)
|
|
CorpKfServicerSessionRecord corpKfServicerSessionRecord = corpKfServicerSessionRecordMapper.selectOne(Wrappers.lambdaQuery(CorpKfServicerSessionRecord.class)
|
|
|
.eq(CorpKfServicerSessionRecord::getOpenKfId, chat.getOpenKfId())
|
|
.eq(CorpKfServicerSessionRecord::getOpenKfId, chat.getOpenKfId())
|
|
|
.eq(CorpKfServicerSessionRecord::getExternalUserid, chat.getExternalUserid())
|
|
.eq(CorpKfServicerSessionRecord::getExternalUserid, chat.getExternalUserid())
|
|
@@ -974,7 +969,12 @@ public class CorpServiceImpl implements CorpService {
|
|
|
.eq(CorpKfServicerSessionRecord::getServiceState, 0)
|
|
.eq(CorpKfServicerSessionRecord::getServiceState, 0)
|
|
|
.last("limit 1"));
|
|
.last("limit 1"));
|
|
|
if (corpKfServicerSessionRecord != null) chat.setSessionId(corpKfServicerSessionRecord.getId());
|
|
if (corpKfServicerSessionRecord != null) chat.setSessionId(corpKfServicerSessionRecord.getId());
|
|
|
- corpKfAccountSessionChatMapper.insert(chat);
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ corpKfAccountSessionChatMapper.insert(chat);
|
|
|
|
|
+ return true;
|
|
|
|
|
+ } catch (DuplicateKeyException e) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|