|
|
@@ -13,6 +13,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.cyksj.common.constant.Constant;
|
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
import com.cyksj.common.task.GlobalThreadPoolTaskExecutor;
|
|
|
+import com.cyksj.common.util.Jsons;
|
|
|
import com.cyksj.common.util.StringUtil;
|
|
|
import com.cyksj.common.util.Xmls;
|
|
|
import com.cyksj.common.util.corp.WxCryptUtil;
|
|
|
@@ -573,7 +574,6 @@ public class CorpServiceImpl implements CorpService {
|
|
|
List<WxCpKfMsgListResp.WxCpKfMsgItem> enterSessionList = null;
|
|
|
List<WxCpKfMsgListResp.WxCpKfMsgItem> sessionStatusChanges = null;
|
|
|
List<WxCorpChatMsg> mergedMsgs = null;
|
|
|
- List<WxCpKfMsgListResp.WxCpKfMsgItem> textList = null;
|
|
|
for (WxCpKfMsgListResp.WxCpKfMsgItem item : msgList) {
|
|
|
if (item.getEvent() != null && item.getEvent().getEventType().equals("enter_session")) {
|
|
|
//会话事件
|
|
|
@@ -591,23 +591,8 @@ public class CorpServiceImpl implements CorpService {
|
|
|
sessionStatusChanges.add(item);
|
|
|
}
|
|
|
}
|
|
|
- if (item.getMergedMsg() != null) {
|
|
|
- if (mergedMsgs == null) {
|
|
|
- mergedMsgs = new ArrayList<>();
|
|
|
- }
|
|
|
- WxCorpChatMsg mergedMsg = item.getMergedMsg();
|
|
|
- mergedMsg.setServicer_userid(item.getServicerUserId());
|
|
|
- mergedMsg.setExternal_userid(item.getExternalUserId());
|
|
|
- mergedMsg.setMsgid(item.getMsgId());
|
|
|
- mergedMsg.setOrigin(item.getOrigin());
|
|
|
- mergedMsgs.add(mergedMsg);
|
|
|
- }
|
|
|
- if (StrUtil.equals("text", item.getMsgType())) {
|
|
|
- if (textList == null) {
|
|
|
- textList = new ArrayList<>();
|
|
|
- }
|
|
|
- textList.add(item);
|
|
|
- }
|
|
|
+ //同步客户聊天记录
|
|
|
+ syncKfChatMsg(item);
|
|
|
}
|
|
|
cursor = wxCpKfMsgListResp.getNextCursor();
|
|
|
//进入会话事件
|
|
|
@@ -617,7 +602,7 @@ public class CorpServiceImpl implements CorpService {
|
|
|
//同步客服聊天记录
|
|
|
syncChatMsg(openKfId, mergedMsgs);
|
|
|
//同步满意度
|
|
|
- syncSessionSatisfaction(openKfId, textList, corpId, corpKfAccountSessionConfig);
|
|
|
+ syncSessionText(openKfId, textList, corpId, corpKfAccountSessionConfig);
|
|
|
corpKfAccountSyncMsgProgress.setNextCursor(cursor);
|
|
|
//同步信息
|
|
|
while (wxCpKfMsgListResp.getHasMore() == 1) {
|
|
|
@@ -625,6 +610,59 @@ public class CorpServiceImpl implements CorpService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void syncKfChatMsg(WxCpKfMsgListResp.WxCpKfMsgItem item) throws Exception {
|
|
|
+ String openKfid = item.getOpenKfid();
|
|
|
+ //客户id
|
|
|
+ String externalUserId = item.getExternalUserId();
|
|
|
+ //接待人员id
|
|
|
+ String servicerUserId = item.getServicerUserId();
|
|
|
+ //消息来源。3-微信客户发送的消息 4-系统推送的事件消息 5-接待人员在企业微信客户端发送的消息
|
|
|
+ Integer origin = item.getOrigin();
|
|
|
+ //发送时间
|
|
|
+ Long sendTime = item.getSendTime();
|
|
|
+ //消息id
|
|
|
+ String msgId = item.getMsgId();
|
|
|
+ //消息类型
|
|
|
+ String msgType = item.getMsgType();
|
|
|
+ CorpKfAccountSessionChat corpKfAccountSessionChat = new CorpKfAccountSessionChat();
|
|
|
+ corpKfAccountSessionChat.setOpenKfId(openKfid);
|
|
|
+ corpKfAccountSessionChat.setMsgid(msgId);
|
|
|
+ corpKfAccountSessionChat.setServicerUserid(servicerUserId);
|
|
|
+ corpKfAccountSessionChat.setExternalUserid(externalUserId);
|
|
|
+ corpKfAccountSessionChat.setOrign(origin);
|
|
|
+ corpKfAccountSessionChat.setMsgType(msgType);
|
|
|
+ corpKfAccountSessionChat.setSendTime(sendTime);
|
|
|
+ corpKfAccountSessionChat.setSendDate(DateTime.of(sendTime * 1000));
|
|
|
+ //文本
|
|
|
+ if (item.getText() != null) {
|
|
|
+ corpKfAccountSessionChat.setMsgContent(item.getText().getContent());
|
|
|
+ } else if (item.getMergedMsg() != null) {
|
|
|
+ //聊天记录 转发
|
|
|
+ corpKfAccountSessionChat.setMsgContent(Jsons.toJson(item.getMergedMsg().getItem()));
|
|
|
+ } else if (item.getVideo() != null) {
|
|
|
+ //视频记录
|
|
|
+ setMediaUrl(corpKfAccountSessionChat, item.getVideo().getMedia_id());
|
|
|
+ } else if (item.getFile() != null) {
|
|
|
+ //文件
|
|
|
+ setMediaUrl(corpKfAccountSessionChat, item.getFile().getMedia_id());
|
|
|
+ } else if (item.getImage() != null) {
|
|
|
+ //图片
|
|
|
+ setMediaUrl(corpKfAccountSessionChat, item.getImage().getMedia_id());
|
|
|
+ } else if (item.getLink() != null) {
|
|
|
+ //链接
|
|
|
+ WxCorpLinkMsg link = item.getLink();
|
|
|
+ corpKfAccountSessionChat.setLinkTitle(link.getTitle());
|
|
|
+ corpKfAccountSessionChat.setLinkDesc(link.getDesc());
|
|
|
+ corpKfAccountSessionChat.setLinkUrl(link.getUrl());
|
|
|
+ corpKfAccountSessionChat.setLinkPicUrl(link.getPic_url());
|
|
|
+ } else if (item.getMsgmenu() != null) {
|
|
|
+ //菜单 结束语统计
|
|
|
+
|
|
|
+ }
|
|
|
+ //新增
|
|
|
+ saveChatMsg(corpKfAccountSessionChat);
|
|
|
+ }
|
|
|
+
|
|
|
private void syncSessionSatisfaction(String openKfId, List<WxCpKfMsgListResp.WxCpKfMsgItem> textList, String corpId, CorpKfAccountSessionConfig corpKfAccountSessionConfig) throws Exception {
|
|
|
if (textList == null) {
|
|
|
return;
|
|
|
@@ -738,7 +776,7 @@ public class CorpServiceImpl implements CorpService {
|
|
|
if (selectCount == 0) {
|
|
|
if (corpKfAccountSessionConfig != null) {
|
|
|
Integer maxNum = corpKfServicerSessionRecordMapper.selectCount(Wrappers.lambdaQuery(CorpKfServicerSessionRecord.class)
|
|
|
- .eq(CorpKfServicerSessionRecord::getServicerUserId, servicerUserid)
|
|
|
+ .eq(CorpKfServicerSessionRecord::getServicerUserid, servicerUserid)
|
|
|
.eq(CorpKfServicerSessionRecord::getServiceState, 0));
|
|
|
if (maxNum < corpKfAccountSessionConfig.getMaxNum()) {
|
|
|
//记录新的客服会话
|
|
|
@@ -756,6 +794,7 @@ public class CorpServiceImpl implements CorpService {
|
|
|
String openKfId = corpKfAccount.getOpenKfId();
|
|
|
if (enterSessionList != null && enterSessionList.size() > 0) {
|
|
|
WxCpKfMsgListResp.WxCpKfMsgItem wxCpKfMsgItem = enterSessionList.get(enterSessionList.size() - 1);
|
|
|
+ DateTime sendTime = DateTime.of(wxCpKfMsgItem.getSendTime() * 1000);
|
|
|
WxCpKfEventMsg event = wxCpKfMsgItem.getEvent();
|
|
|
String welcomeCode = event.getWelcomeCode();
|
|
|
//如果满足发送欢迎语条件(条件为:用户在过去48小时里未收过欢迎语,且未向客服发过消息),会返回该字段。
|
|
|
@@ -870,7 +909,7 @@ public class CorpServiceImpl implements CorpService {
|
|
|
CorpKfServicerSessionRecord corpKfServicerSessionRecord = new CorpKfServicerSessionRecord();
|
|
|
corpKfServicerSessionRecord.setOpenKfId(openKfId);
|
|
|
corpKfServicerSessionRecord.setServiceState(0);
|
|
|
- corpKfServicerSessionRecord.setServicerUserId(userid);
|
|
|
+ corpKfServicerSessionRecord.setServicerUserid(userid);
|
|
|
corpKfServicerSessionRecord.setExternalUserid(externalUserId);
|
|
|
corpKfServicerSessionRecord.setChangeType(changeType);
|
|
|
corpKfServicerSessionRecordMapper.insert(corpKfServicerSessionRecord);
|
|
|
@@ -917,4 +956,19 @@ public class CorpServiceImpl implements CorpService {
|
|
|
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置临时素材url
|
|
|
+ */
|
|
|
+ private void setMediaUrl(CorpKfAccountSessionChat corpKfAccountSessionChat, String mediaId) throws Exception {
|
|
|
+ String url = wxCorpOps.getMedia(null, mediaId);
|
|
|
+ corpKfAccountSessionChat.setUrl(url);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增记录
|
|
|
+ */
|
|
|
+ public void saveChatMsg(CorpKfAccountSessionChat chat) {
|
|
|
+ corpKfAccountSessionChatMapper.insert(chat);
|
|
|
+ }
|
|
|
}
|