|
@@ -3,11 +3,14 @@ package com.fs.fastGpt.service.impl;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
-import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
|
+import com.fs.common.annotation.DataSource;
|
|
|
import com.fs.common.annotation.Excel;
|
|
import com.fs.common.annotation.Excel;
|
|
|
-import com.fs.common.config.FSConfig;
|
|
|
|
|
import com.fs.common.core.domain.R;
|
|
import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.core.redis.RedisCache;
|
|
import com.fs.common.core.redis.RedisCache;
|
|
|
|
|
+import com.fs.common.enums.DataSourceType;
|
|
|
|
|
+import com.fs.common.utils.PinYinUtil;
|
|
|
|
|
+import com.fs.common.utils.http.HttpUtils;
|
|
|
import com.fs.company.domain.CompanyConfig;
|
|
import com.fs.company.domain.CompanyConfig;
|
|
|
import com.fs.company.mapper.CompanyConfigMapper;
|
|
import com.fs.company.mapper.CompanyConfigMapper;
|
|
|
import com.fs.config.ai.AiHostProper;
|
|
import com.fs.config.ai.AiHostProper;
|
|
@@ -38,16 +41,17 @@ import com.fs.his.domain.FsStoreOrder;
|
|
|
import com.fs.his.dto.ExpressInfoDTO;
|
|
import com.fs.his.dto.ExpressInfoDTO;
|
|
|
import com.fs.his.dto.TracesDTO;
|
|
import com.fs.his.dto.TracesDTO;
|
|
|
import com.fs.his.enums.ShipperCodeEnum;
|
|
import com.fs.his.enums.ShipperCodeEnum;
|
|
|
-import com.fs.his.mapper.FsStoreMapper;
|
|
|
|
|
import com.fs.his.mapper.FsStoreOrderMapper;
|
|
import com.fs.his.mapper.FsStoreOrderMapper;
|
|
|
import com.fs.his.service.IFsExpressService;
|
|
import com.fs.his.service.IFsExpressService;
|
|
|
import com.fs.his.service.IFsStoreOrderService;
|
|
import com.fs.his.service.IFsStoreOrderService;
|
|
|
-import com.fs.im.dto.OpenImMsgDTO;
|
|
|
|
|
import com.fs.im.vo.OpenImMsgCallBackVO;
|
|
import com.fs.im.vo.OpenImMsgCallBackVO;
|
|
|
import com.fs.qw.domain.*;
|
|
import com.fs.qw.domain.*;
|
|
|
|
|
+import com.fs.qw.dto.QwImUserDTO;
|
|
|
|
|
+import com.fs.qw.enums.MsgType;
|
|
|
import com.fs.qw.mapper.*;
|
|
import com.fs.qw.mapper.*;
|
|
|
import com.fs.qw.param.QwAutoTagsRulesTags;
|
|
import com.fs.qw.param.QwAutoTagsRulesTags;
|
|
|
import com.fs.qw.service.*;
|
|
import com.fs.qw.service.*;
|
|
|
|
|
+import com.fs.qw.vo.QwMessageListVO;
|
|
|
import com.fs.qwApi.domain.QwResult;
|
|
import com.fs.qwApi.domain.QwResult;
|
|
|
import com.fs.qwApi.param.QwEditUserTagParam;
|
|
import com.fs.qwApi.param.QwEditUserTagParam;
|
|
|
import com.fs.qwApi.param.QwSendMsgParam;
|
|
import com.fs.qwApi.param.QwSendMsgParam;
|
|
@@ -63,9 +67,11 @@ import com.fs.wxwork.dto.*;
|
|
|
import com.fs.wxwork.service.WxWorkService;
|
|
import com.fs.wxwork.service.WxWorkService;
|
|
|
import com.vdurmont.emoji.EmojiParser;
|
|
import com.vdurmont.emoji.EmojiParser;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.commons.lang3.ObjectUtils;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.jetbrains.annotations.Nullable;
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
|
+import org.json.JSONObject;
|
|
|
|
|
+import org.redisson.api.RLock;
|
|
|
|
|
+import org.redisson.api.RedissonClient;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
import org.springframework.scheduling.annotation.Async;
|
|
@@ -77,7 +83,7 @@ import java.time.LocalDate;
|
|
|
import java.time.LocalTime;
|
|
import java.time.LocalTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
+import java.util.concurrent.*;
|
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
import java.util.regex.Pattern;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
@@ -165,10 +171,33 @@ public class AiHookServiceImpl implements AiHookService {
|
|
|
private IFastGptChatReplaceTextService fastGptChatReplaceTextService;
|
|
private IFastGptChatReplaceTextService fastGptChatReplaceTextService;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private ICrmMsgService crmMsgService;
|
|
private ICrmMsgService crmMsgService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private QwSessionMapper qwSessionMapper;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private QwMsgMapper qwMsgMapper;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private QwGroupChatMapper qwGroupChatMapper;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private RedissonClient redissonClient;
|
|
|
|
|
|
|
|
private static final String AI_REPLY = "AI_REPLY:";
|
|
private static final String AI_REPLY = "AI_REPLY:";
|
|
|
private static final String AI_REPLY_TAG = "AI_REPLY_TAG:";
|
|
private static final String AI_REPLY_TAG = "AI_REPLY_TAG:";
|
|
|
|
|
|
|
|
|
|
+ private final ExecutorService executor = new ThreadPoolExecutor(
|
|
|
|
|
+ 8, 32, 60L, TimeUnit.SECONDS,
|
|
|
|
|
+ new LinkedBlockingQueue<>(1000),
|
|
|
|
|
+ new ThreadFactory() {
|
|
|
|
|
+ private final ThreadFactory defaultFactory = Executors.defaultThreadFactory();
|
|
|
|
|
+ private int count = 1;
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Thread newThread(Runnable r) {
|
|
|
|
|
+ Thread thread = defaultFactory.newThread(r);
|
|
|
|
|
+ thread.setName("ai-im-exec-" + count++);
|
|
|
|
|
+ return thread;
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ new ThreadPoolExecutor.CallerRunsPolicy() // 拒绝策略
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
/** Ai半小时未回复提醒 **/
|
|
/** Ai半小时未回复提醒 **/
|
|
|
/**
|
|
/**
|
|
@@ -288,7 +317,7 @@ public class AiHookServiceImpl implements AiHookService {
|
|
|
if (result.isLongText()){
|
|
if (result.isLongText()){
|
|
|
//新增用户信息
|
|
//新增用户信息
|
|
|
addUserInfo(contentKh, qwExternalContacts.getId(),fastGptChatSession);
|
|
addUserInfo(contentKh, qwExternalContacts.getId(),fastGptChatSession);
|
|
|
- sendAiMsg(content,sender,uid,serverId);
|
|
|
|
|
|
|
+ sendAiMsg(content,sender,uid,serverId, user.getId(), qwExternalContacts.getExternalUserId());
|
|
|
|
|
|
|
|
}else {
|
|
}else {
|
|
|
String sa = contentKh.replaceAll("】\n", "】").replaceAll("\n【", "【");
|
|
String sa = contentKh.replaceAll("】\n", "】").replaceAll("\n【", "【");
|
|
@@ -302,7 +331,7 @@ public class AiHookServiceImpl implements AiHookService {
|
|
|
//新增用户信息
|
|
//新增用户信息
|
|
|
addUserInfo(contentKh, qwExternalContacts.getId(),fastGptChatSession);
|
|
addUserInfo(contentKh, qwExternalContacts.getId(),fastGptChatSession);
|
|
|
for (String msg : countList) {
|
|
for (String msg : countList) {
|
|
|
- sendAiMsg(msg,sender,uid,serverId);
|
|
|
|
|
|
|
+ sendAiMsg(msg,sender,uid,serverId, user.getId(), qwExternalContacts.getExternalUserId());
|
|
|
try {
|
|
try {
|
|
|
Thread.sleep(10000);
|
|
Thread.sleep(10000);
|
|
|
} catch (InterruptedException e) {
|
|
} catch (InterruptedException e) {
|
|
@@ -564,9 +593,9 @@ public class AiHookServiceImpl implements AiHookService {
|
|
|
//新增用户信息
|
|
//新增用户信息
|
|
|
addUserInfo(contentKh, qwExternalContacts.getId(),fastGptChatSession);
|
|
addUserInfo(contentKh, qwExternalContacts.getId(),fastGptChatSession);
|
|
|
if (type==16){
|
|
if (type==16){
|
|
|
- sendAiVoiceMsg(content,sender,uid,serverId,user);
|
|
|
|
|
|
|
+ sendAiVoiceMsg(content,sender,uid,serverId,user, qwExternalContacts.getExternalUserId());
|
|
|
}else {
|
|
}else {
|
|
|
- sendAiMsg(content,sender,uid,serverId);
|
|
|
|
|
|
|
+ sendAiMsg(content,sender,uid,serverId, user.getId(), qwExternalContacts.getExternalUserId());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}else {
|
|
}else {
|
|
@@ -583,9 +612,9 @@ public class AiHookServiceImpl implements AiHookService {
|
|
|
addUserInfo(contentKh, qwExternalContacts.getId(),fastGptChatSession);
|
|
addUserInfo(contentKh, qwExternalContacts.getId(),fastGptChatSession);
|
|
|
for (String msg : countList) {
|
|
for (String msg : countList) {
|
|
|
if (type==16){
|
|
if (type==16){
|
|
|
- sendAiVoiceMsg(msg,sender,uid,serverId,user);
|
|
|
|
|
|
|
+ sendAiVoiceMsg(msg,sender,uid,serverId,user, qwExternalContacts.getExternalUserId());
|
|
|
}else {
|
|
}else {
|
|
|
- sendAiMsg(msg,sender,uid,serverId);
|
|
|
|
|
|
|
+ sendAiMsg(msg,sender,uid,serverId, user.getId(), qwExternalContacts.getExternalUserId());
|
|
|
}
|
|
}
|
|
|
try {
|
|
try {
|
|
|
Thread.sleep(10000);
|
|
Thread.sleep(10000);
|
|
@@ -950,7 +979,7 @@ public class AiHookServiceImpl implements AiHookService {
|
|
|
return maskedContent;
|
|
return maskedContent;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private void sendAiVoiceMsg(String content, Long sendId , String uuid,Long serverId,QwUser user) {
|
|
|
|
|
|
|
+ private void sendAiVoiceMsg(String content, Long sendId , String uuid,Long serverId,QwUser user, String extUserId) {
|
|
|
if (content == null || content.trim().isEmpty()){
|
|
if (content == null || content.trim().isEmpty()){
|
|
|
System.out.println("输出为空格");
|
|
System.out.println("输出为空格");
|
|
|
return;
|
|
return;
|
|
@@ -989,11 +1018,37 @@ public class AiHookServiceImpl implements AiHookService {
|
|
|
WxWorkResponseDTO<WxwSendCDNVoiceMsgRespDTO> wxwSendCDNVoiceMsgRespDTOWxWorkResponseDTO = wxWorkService.SendCDNVoiceMsg(wxwSendCDNVoiceMsgDTO, serverId);
|
|
WxWorkResponseDTO<WxwSendCDNVoiceMsgRespDTO> wxwSendCDNVoiceMsgRespDTOWxWorkResponseDTO = wxWorkService.SendCDNVoiceMsg(wxwSendCDNVoiceMsgDTO, serverId);
|
|
|
System.out.println(wxwSendCDNVoiceMsgRespDTOWxWorkResponseDTO);
|
|
System.out.println(wxwSendCDNVoiceMsgRespDTOWxWorkResponseDTO);
|
|
|
|
|
|
|
|
|
|
+ if (wxwSendCDNVoiceMsgRespDTOWxWorkResponseDTO.getErrcode() == 0) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ WxwSendCDNVoiceMsgRespDTO dtoData = wxwSendCDNVoiceMsgRespDTOWxWorkResponseDTO.getData();
|
|
|
|
|
+
|
|
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
|
|
+ json.put("url", data.getUrl());
|
|
|
|
|
+ json.put("content", content);
|
|
|
|
|
+
|
|
|
|
|
+ // 保存聊天消息
|
|
|
|
|
+ QwMessageListVO message = this.saveQwMsg(user.getId(), extUserId, json.toString(), 4, false, dtoData.getMsg_id(), dtoData.getApp_info());
|
|
|
|
|
+ if (message == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 发送webSocket
|
|
|
|
|
+ executor.execute(() -> {
|
|
|
|
|
+ try {
|
|
|
|
|
+ HttpUtils.doPost(aiHostProper.getIpadUrl() + "/msg/sendQwImMsg", JSON.toJSONString(message));
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("转发ai回复消息失败 err: {}", e.getMessage(), e);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("保存ai回复消息失败 err: {}", e.getMessage(), e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
QwSopLogsMapper qwSopLogsMapper;
|
|
QwSopLogsMapper qwSopLogsMapper;
|
|
|
- private void sendAiMsg(String content, Long sendId , String uuid,Long serverId) {
|
|
|
|
|
|
|
+ private void sendAiMsg(String content, Long sendId , String uuid,Long serverId, Long qwUserId, String extUserId) {
|
|
|
if (content == null || content.trim().isEmpty()){
|
|
if (content == null || content.trim().isEmpty()){
|
|
|
System.out.println("输出为空格");
|
|
System.out.println("输出为空格");
|
|
|
return;
|
|
return;
|
|
@@ -1006,6 +1061,27 @@ public class AiHookServiceImpl implements AiHookService {
|
|
|
WxWorkResponseDTO<WxWorkSendTextMsgRespDTO> wxWorkSendTextMsgRespDTOWxWorkResponseDTO = wxWorkService.SendTextMsg(wxWorkSendTextMsgDTO,serverId);
|
|
WxWorkResponseDTO<WxWorkSendTextMsgRespDTO> wxWorkSendTextMsgRespDTOWxWorkResponseDTO = wxWorkService.SendTextMsg(wxWorkSendTextMsgDTO,serverId);
|
|
|
WxWorkSendTextMsgRespDTO data = wxWorkSendTextMsgRespDTOWxWorkResponseDTO.getData();
|
|
WxWorkSendTextMsgRespDTO data = wxWorkSendTextMsgRespDTOWxWorkResponseDTO.getData();
|
|
|
|
|
|
|
|
|
|
+ if (wxWorkSendTextMsgRespDTOWxWorkResponseDTO.getErrcode() == 0) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ WxWorkSendTextMsgRespDTO dtoData = wxWorkSendTextMsgRespDTOWxWorkResponseDTO.getData();
|
|
|
|
|
+
|
|
|
|
|
+ // 保存聊天消息
|
|
|
|
|
+ QwMessageListVO message = this.saveQwMsg(qwUserId, extUserId, content, 1, false, dtoData.getMsg_id(), dtoData.getApp_info());
|
|
|
|
|
+ if (message == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 发送webSocket
|
|
|
|
|
+ executor.execute(() -> {
|
|
|
|
|
+ try {
|
|
|
|
|
+ HttpUtils.doPost(aiHostProper.getIpadUrl() + "/msg/sendQwImMsg", JSON.toJSONString(message));
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("转发ai回复消息失败 err: {}", e.getMessage(), e);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("保存ai回复消息失败 err: {}", e.getMessage(), e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
/**
|
|
/**
|
|
@@ -2117,4 +2193,486 @@ public class AiHookServiceImpl implements AiHookService {
|
|
|
return wxWorkService.downloadWeChatFile(weChatFileDTO, serverId);
|
|
return wxWorkService.downloadWeChatFile(weChatFileDTO, serverId);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取文件地址
|
|
|
|
|
+ * @param uuid uuid
|
|
|
|
|
+ * @param fileId fileId
|
|
|
|
|
+ * @param aesKey aesKey
|
|
|
|
|
+ * @param fileType fileType
|
|
|
|
|
+ * @param fileName fileName
|
|
|
|
|
+ * @param fileSize fileSize
|
|
|
|
|
+ * @param serverId serverId
|
|
|
|
|
+ * @return WxWorkResponseDTO
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public WxWorkResponseDTO<String> getFileUrl(String uuid, String fileId, String aesKey, Integer fileType, String fileName, Integer fileSize, Long serverId) {
|
|
|
|
|
+ WxDownloadFileDTO downloadFileDTO = new WxDownloadFileDTO();
|
|
|
|
|
+ downloadFileDTO.setUuid(uuid);
|
|
|
|
|
+ downloadFileDTO.setFileid(fileId);
|
|
|
|
|
+ downloadFileDTO.setAes_key(aesKey);
|
|
|
|
|
+ downloadFileDTO.setFiletype(fileType);
|
|
|
|
|
+ downloadFileDTO.setFile_name(fileName);
|
|
|
|
|
+ downloadFileDTO.setSize(fileSize);
|
|
|
|
|
+ return wxWorkService.downloadFile(downloadFileDTO, serverId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 保存企微聊天信息
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param qwUserId 企微用户ID
|
|
|
|
|
+ * @param senderVid 消息发送者ID
|
|
|
|
|
+ * @param receiverVid 消息接收者ID
|
|
|
|
|
+ * @param serverId 服务器ID
|
|
|
|
|
+ * @param content 聊天内容
|
|
|
|
|
+ * @param uuid UUID
|
|
|
|
|
+ * @param json 消息json
|
|
|
|
|
+ * @param msgType 消息类型 1文本 2图片 3动态表情 4语音 5小程序
|
|
|
|
|
+ * @param isRoom 是否群聊
|
|
|
|
|
+ * @param chatId 会话ID(群聊才有)
|
|
|
|
|
+ * @param chatAvatar 群头像(群聊才有)
|
|
|
|
|
+ * @param qwMsgId 企微消息ID
|
|
|
|
|
+ * @param qwAppInfo 企微appInfo
|
|
|
|
|
+ */
|
|
|
|
|
+ @DataSource(DataSourceType.SHARDING)
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public QwMessageListVO saveQwMsg(Long qwUserId, Long senderVid, Long receiverVid, Long serverId, String content, String uuid, String json, int msgType, boolean isRoom, String chatId, String chatAvatar, Long qwMsgId, String qwAppInfo) {
|
|
|
|
|
+ // 查询企微用户
|
|
|
|
|
+ QwUser qwUser = qwUserService.selectQwUserById(qwUserId);
|
|
|
|
|
+ if (Objects.isNull(qwUser)) {
|
|
|
|
|
+ log.warn("企微用户不存在 qwUserId: {}", qwUserId);
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (qwUser.getCompanyUserId() == null) {
|
|
|
|
|
+ log.warn("企微用户未归属销售 qwUserId: {}", qwUserId);
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 获取发送人
|
|
|
|
|
+ QwImUserDTO sender = getUserByVid(senderVid, uuid, serverId, qwUser.getCorpId(), qwUser.getQwUserId());
|
|
|
|
|
+ if (Objects.isNull(sender)) {
|
|
|
|
|
+ log.warn("sender用户不存在 senderVid: {}", senderVid);
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 获取接收者
|
|
|
|
|
+ QwImUserDTO receiver = getUserByVid(receiverVid, uuid, serverId, qwUser.getCorpId(), qwUser.getQwUserId());
|
|
|
|
|
+
|
|
|
|
|
+ // 查询会话
|
|
|
|
|
+ QwSession qwSession = null;
|
|
|
|
|
+ if (isRoom) {
|
|
|
|
|
+ qwSession = getGroupQwSession(chatId, chatAvatar, qwUser);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ QwImUserDTO extUser = null;
|
|
|
|
|
+ Long extWxId = null;
|
|
|
|
|
+
|
|
|
|
|
+ // 获取外部联系人
|
|
|
|
|
+ if (sender.getUserType() == 1) {
|
|
|
|
|
+ extUser = sender;
|
|
|
|
|
+ extWxId = senderVid;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (receiver != null && receiver.getUserType() == 1) {
|
|
|
|
|
+ extUser = receiver;
|
|
|
|
|
+ extWxId = receiverVid;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (extUser != null) {
|
|
|
|
|
+ qwSession = getQwSession(extUser, qwUser, extWxId);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (qwSession == null) {
|
|
|
|
|
+ log.warn("获取session失败 senderVid: {}, receiverVid: {}", senderVid, receiverVid);
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 保存聊天消息
|
|
|
|
|
+ QwMsg qwMsg = new QwMsg();
|
|
|
|
|
+ qwMsg.setContent(content);
|
|
|
|
|
+ qwMsg.setSessionId(qwSession.getSessionId());
|
|
|
|
|
+ qwMsg.setSendType(sender.getUserType());
|
|
|
|
|
+ qwMsg.setCompanyId(qwUser.getCompanyId());
|
|
|
|
|
+ qwMsg.setCompanyUserId(qwUser.getCompanyUserId());
|
|
|
|
|
+ qwMsg.setMsgType(msgType);
|
|
|
|
|
+ qwMsg.setMsgJson(json);
|
|
|
|
|
+ qwMsg.setStatus(0);
|
|
|
|
|
+ qwMsg.setQwUserId(qwSession.getQwUserId());
|
|
|
|
|
+ qwMsg.setCreateTime(new Date());
|
|
|
|
|
+ if (sender.getUserType() == 1) {
|
|
|
|
|
+ qwMsg.setQwExtId(sender.getUserId().toString());
|
|
|
|
|
+ }
|
|
|
|
|
+ qwMsg.setAvatar(sender.getAvatar());
|
|
|
|
|
+ qwMsg.setNickName(sender.getUserName());
|
|
|
|
|
+ qwMsg.setQwMsgId(qwMsgId);
|
|
|
|
|
+ qwMsg.setQwAppInfo(qwAppInfo);
|
|
|
|
|
+ qwMsgMapper.insertQwMsg(qwMsg);
|
|
|
|
|
+ log.debug("保存企微聊天记录 msgId: {}", qwMsg.getMsgId());
|
|
|
|
|
+
|
|
|
|
|
+ String type = "text";
|
|
|
|
|
+ MsgType messageType = MsgType.getMsgType(msgType);
|
|
|
|
|
+ if (Objects.nonNull(messageType)){
|
|
|
|
|
+ type = messageType.getValue();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ qwSession.setLastMsgId(qwMsg.getMsgId());
|
|
|
|
|
+ qwSession.setLastMsgType(type);
|
|
|
|
|
+ qwSession.setLastSendTime(qwMsg.getCreateTime().getTime());
|
|
|
|
|
+ qwSession.setLastContent(qwMsg.getContent());
|
|
|
|
|
+ qwSessionMapper.updateQwSession(qwSession);
|
|
|
|
|
+
|
|
|
|
|
+ // 组装返回消息结构
|
|
|
|
|
+ QwMessageListVO listVO = new QwMessageListVO();
|
|
|
|
|
+ QWFromUser qwFromUser = new QWFromUser();
|
|
|
|
|
+ qwFromUser.setId(sender.getUserId());
|
|
|
|
|
+ qwFromUser.setAvatar(sender.getAvatar());
|
|
|
|
|
+ qwFromUser.setDisplayName(sender.getUserName());
|
|
|
|
|
+
|
|
|
|
|
+ listVO.setCompanyUserId(qwUser.getCompanyUserId());
|
|
|
|
|
+ listVO.setType(type);
|
|
|
|
|
+ listVO.setStatus("succeed");
|
|
|
|
|
+ listVO.setExtId(qwMsg.getQwExtId());
|
|
|
|
|
+ listVO.setFromUser(qwFromUser);
|
|
|
|
|
+ listVO.setSendTime(qwMsg.getCreateTime().getTime());
|
|
|
|
|
+ listVO.setId(qwMsg.getMsgId().toString());
|
|
|
|
|
+ listVO.setContent(qwMsg.getContent());
|
|
|
|
|
+ listVO.setToContactId(String.valueOf(qwSession.getSessionId()));
|
|
|
|
|
+ listVO.setAppKey(qwUser.getAppKey());
|
|
|
|
|
+ return listVO;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 保存企微聊天信息
|
|
|
|
|
+ */
|
|
|
|
|
+ @DataSource(DataSourceType.SHARDING)
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public QwMessageListVO saveQwMsg(Long qwUserId, String exId, String content, int msgType, boolean isRoom, Long qwMsgId, String qwAppInfo) {
|
|
|
|
|
+ QwUser qwUser = qwUserService.selectQwUserById(qwUserId);
|
|
|
|
|
+ if (Objects.isNull(qwUser)) {
|
|
|
|
|
+ log.warn("企微用户不存在 qwUserId: {}", qwUserId);
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 查询会话
|
|
|
|
|
+ QwSession qwSession;
|
|
|
|
|
+ if (isRoom) {
|
|
|
|
|
+ qwSession = qwSessionMapper.selectQwSessionByChatIdAndQwUserId(exId, qwUser.getId());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ QwExternalContact externalContact = qwExternalContactMapper.selectQwExternalContactByExternalUserIdAndQwUserId(exId, qwUser.getCorpId(), qwUser.getQwUserId());
|
|
|
|
|
+ if (Objects.isNull(externalContact)) {
|
|
|
|
|
+ log.warn("企微外部联系人不存在 extId: {}", exId);
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ qwSession = qwSessionMapper.selectQwSessionByExtIdAndQwUserId(externalContact.getId(), qwUser.getId());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (qwSession == null) {
|
|
|
|
|
+ log.warn("获取session失败 qwUserId: {}, extId: {}", qwUserId, exId);
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 保存聊天消息
|
|
|
|
|
+ QwMsg qwMsg = new QwMsg();
|
|
|
|
|
+ qwMsg.setContent(content);
|
|
|
|
|
+ qwMsg.setSessionId(qwSession.getSessionId());
|
|
|
|
|
+ qwMsg.setSendType(2);
|
|
|
|
|
+ qwMsg.setCompanyId(qwUser.getCompanyId());
|
|
|
|
|
+ qwMsg.setCompanyUserId(qwUser.getCompanyUserId());
|
|
|
|
|
+ qwMsg.setMsgType(msgType);
|
|
|
|
|
+ qwMsg.setMsgJson(content);
|
|
|
|
|
+ qwMsg.setStatus(0);
|
|
|
|
|
+ qwMsg.setQwUserId(qwSession.getQwUserId());
|
|
|
|
|
+ qwMsg.setCreateTime(new Date());
|
|
|
|
|
+ qwMsg.setAvatar(qwUser.getAvatar());
|
|
|
|
|
+ qwMsg.setNickName(qwUser.getQwUserName());
|
|
|
|
|
+ qwMsg.setQwMsgId(qwMsgId);
|
|
|
|
|
+ qwMsg.setQwAppInfo(qwAppInfo);
|
|
|
|
|
+ qwMsgMapper.insertQwMsg(qwMsg);
|
|
|
|
|
+ log.debug("保存企微聊天记录 msgId: {}", qwMsg.getMsgId());
|
|
|
|
|
+
|
|
|
|
|
+ String type = "text";
|
|
|
|
|
+ MsgType messageType = MsgType.getMsgType(msgType);
|
|
|
|
|
+ if (Objects.nonNull(messageType)){
|
|
|
|
|
+ type = messageType.getValue();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ qwSession.setLastMsgId(qwMsg.getMsgId());
|
|
|
|
|
+ qwSession.setLastMsgType(type);
|
|
|
|
|
+ qwSession.setLastSendTime(qwMsg.getCreateTime().getTime());
|
|
|
|
|
+ qwSession.setLastContent(qwMsg.getContent());
|
|
|
|
|
+ qwSessionMapper.updateQwSession(qwSession);
|
|
|
|
|
+
|
|
|
|
|
+ // 组装返回消息结构
|
|
|
|
|
+ QwMessageListVO listVO = new QwMessageListVO();
|
|
|
|
|
+ QWFromUser qwFromUser = new QWFromUser();
|
|
|
|
|
+ qwFromUser.setId(qwUser.getId());
|
|
|
|
|
+ qwFromUser.setAvatar(qwUser.getAvatar());
|
|
|
|
|
+ qwFromUser.setDisplayName(qwUser.getQwUserName());
|
|
|
|
|
+
|
|
|
|
|
+ listVO.setCompanyUserId(qwUser.getCompanyUserId());
|
|
|
|
|
+ listVO.setType(type);
|
|
|
|
|
+ listVO.setStatus("succeed");
|
|
|
|
|
+ listVO.setExtId(qwMsg.getQwExtId());
|
|
|
|
|
+ listVO.setFromUser(qwFromUser);
|
|
|
|
|
+ listVO.setSendTime(qwMsg.getCreateTime().getTime());
|
|
|
|
|
+ listVO.setId(qwMsg.getMsgId().toString());
|
|
|
|
|
+ listVO.setContent(qwMsg.getContent());
|
|
|
|
|
+ listVO.setToContactId(String.valueOf(qwSession.getSessionId()));
|
|
|
|
|
+ listVO.setAppKey(qwUser.getAppKey());
|
|
|
|
|
+ return listVO;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取单聊session
|
|
|
|
|
+ */
|
|
|
|
|
+ private QwSession getQwSession(QwImUserDTO extUser, QwUser qwUser, Long extWxId) {
|
|
|
|
|
+ QwSession qwSession;
|
|
|
|
|
+ qwSession = qwSessionMapper.selectQwSessionByExtIdAndQwUserId(extUser.getUserId(), qwUser.getId());
|
|
|
|
|
+ String firstLetter = PinYinUtil.getFirstLetter(extUser.getUserName());
|
|
|
|
|
+ if (qwSession == null) {
|
|
|
|
|
+
|
|
|
|
|
+ RLock lock = redissonClient.getLock("addSession:" + extUser.getUserId() + ":" + qwUser.getId());
|
|
|
|
|
+ try {
|
|
|
|
|
+ boolean tryLock = lock.tryLock(2, 3, TimeUnit.SECONDS);
|
|
|
|
|
+ if (!tryLock) {
|
|
|
|
|
+ log.warn("添加单聊Session获取锁失败");
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ qwSession = qwSessionMapper.selectQwSessionByExtIdAndQwUserId(extUser.getUserId(), qwUser.getId());
|
|
|
|
|
+ if (qwSession == null) {
|
|
|
|
|
+ qwSession = new QwSession();
|
|
|
|
|
+ String chatId = UUID.randomUUID().toString();
|
|
|
|
|
+ qwSession.setChatId(chatId);
|
|
|
|
|
+ qwSession.setCorpId(qwUser.getCorpId());
|
|
|
|
|
+ qwSession.setQwExtWxId(String.valueOf(extWxId));
|
|
|
|
|
+ qwSession.setQwExtId(extUser.getUserId().toString());
|
|
|
|
|
+ qwSession.setQwUserId(qwUser.getId().toString());
|
|
|
|
|
+ qwSession.setStatus(1);
|
|
|
|
|
+ qwSession.setAvatar(extUser.getAvatar());
|
|
|
|
|
+ qwSession.setNickName(extUser.getUserName());
|
|
|
|
|
+ qwSession.setCompanyId(qwUser.getCompanyId());
|
|
|
|
|
+ qwSession.setCompanyUserId(qwUser.getCompanyUserId());
|
|
|
|
|
+ qwSession.setCreateTime(new Date());
|
|
|
|
|
+ qwSession.setUpdateTime(new Date());
|
|
|
|
|
+ qwSession.setIsRoom(0);
|
|
|
|
|
+ qwSession.setFirstLetter(firstLetter);
|
|
|
|
|
+ qwSessionMapper.insertQwSession(qwSession);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
|
+ log.warn("获取锁失败 err: {}", e.getMessage(), e);
|
|
|
|
|
+ return null;
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ lock.unlock();
|
|
|
|
|
+ }
|
|
|
|
|
+ }else {
|
|
|
|
|
+ qwSession.setUpdateTime(new Date());
|
|
|
|
|
+ qwSession.setNickName(extUser.getUserName());
|
|
|
|
|
+ qwSession.setFirstLetter(firstLetter);
|
|
|
|
|
+ qwSessionMapper.updateQwSession(qwSession);
|
|
|
|
|
+ }
|
|
|
|
|
+ return qwSession;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取群聊session
|
|
|
|
|
+ */
|
|
|
|
|
+ private QwSession getGroupQwSession(String chatId, String chatAvatar, QwUser qwUser) {
|
|
|
|
|
+ QwSession qwSession;
|
|
|
|
|
+ QwGroupChat qwGroupChat = qwGroupChatMapper.selectQwGroupChatByChatId(chatId);
|
|
|
|
|
+ if (Objects.isNull(qwGroupChat)){
|
|
|
|
|
+ log.warn("群聊不存在 serverId: {}, corpId: {}, qwUserId: {}, chatId: {}", qwUser.getServerId(), qwUser.getCorpId(), qwUser.getQwUserId(), chatId);
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ qwSession = qwSessionMapper.selectQwSessionByChatIdAndQwUserId(chatId, qwUser.getId());
|
|
|
|
|
+ String firstLetter = PinYinUtil.getFirstLetter(qwGroupChat.getName());
|
|
|
|
|
+ if (qwSession == null) {
|
|
|
|
|
+ RLock lock = redissonClient.getLock("addSession:" + qwGroupChat.getChatId() + ":" + qwUser.getId());
|
|
|
|
|
+ try {
|
|
|
|
|
+ boolean tryLock = lock.tryLock(2, 3, TimeUnit.SECONDS);
|
|
|
|
|
+ if (!tryLock) {
|
|
|
|
|
+ log.warn("添加群聊Session获取锁失败");
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ qwSession = qwSessionMapper.selectQwSessionByChatIdAndQwUserId(chatId, qwUser.getId());
|
|
|
|
|
+ if (qwSession == null) {
|
|
|
|
|
+ qwSession = new QwSession();
|
|
|
|
|
+ qwSession.setChatId(chatId);
|
|
|
|
|
+ qwSession.setCorpId(qwGroupChat.getCorpId());
|
|
|
|
|
+ qwSession.setQwUserId(qwUser.getId().toString());
|
|
|
|
|
+ qwSession.setStatus(1);
|
|
|
|
|
+ qwSession.setAvatar(chatAvatar);
|
|
|
|
|
+ qwSession.setNickName(qwGroupChat.getName());
|
|
|
|
|
+ qwSession.setCompanyId(qwUser.getCompanyId());
|
|
|
|
|
+ qwSession.setCreateTime(new Date());
|
|
|
|
|
+ qwSession.setUpdateTime(new Date());
|
|
|
|
|
+ qwSession.setIsRoom(1);
|
|
|
|
|
+ qwSession.setFirstLetter(firstLetter);
|
|
|
|
|
+ qwSessionMapper.insertQwSession(qwSession);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
|
+ log.warn("获取锁失败 err: {}", e.getMessage(), e);
|
|
|
|
|
+ return null;
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ lock.unlock();
|
|
|
|
|
+ }
|
|
|
|
|
+ }else {
|
|
|
|
|
+ qwSession.setUpdateTime(new Date());
|
|
|
|
|
+ qwSession.setQwUserId(qwUser.getId().toString());
|
|
|
|
|
+ qwSession.setNickName(qwGroupChat.getName());
|
|
|
|
|
+ qwSession.setAvatar(chatAvatar);
|
|
|
|
|
+ qwSession.setFirstLetter(firstLetter);
|
|
|
|
|
+ qwSessionMapper.updateQwSession(qwSession);
|
|
|
|
|
+ }
|
|
|
|
|
+ return qwSession;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 查询外部联系人
|
|
|
|
|
+ * @param userId 用户ID
|
|
|
|
|
+ * @param uuid UUID
|
|
|
|
|
+ * @param serverId 服务ID
|
|
|
|
|
+ * @param corpId 企微ID
|
|
|
|
|
+ * @param qwUserId 企微用户ID
|
|
|
|
|
+ * @return QwExternalContact
|
|
|
|
|
+ */
|
|
|
|
|
+ private QwExternalContact getExternalContact(Long userId, String uuid, Long serverId, String corpId, String qwUserId) {
|
|
|
|
|
+ return qwExternalContactMapper.selectQwExternalContactByExternalUserIdAndQwUserId(getExtId(userId, uuid, serverId), corpId, qwUserId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 根据vid获取用户信息
|
|
|
|
|
+ */
|
|
|
|
|
+ private QwImUserDTO getUserByVid(Long vid, String uuid, Long serverId, String corpId, String qwUserId) {
|
|
|
|
|
+ if (vid == 0) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 外部联系人
|
|
|
|
|
+ if (vid > 2000000000000000L) {
|
|
|
|
|
+ QwExternalContact qwExternalContact = getExternalContact(vid, uuid, serverId, corpId, qwUserId);
|
|
|
|
|
+ if (Objects.isNull(qwExternalContact)) {
|
|
|
|
|
+ log.warn("外部联系人不存在 vid: {}, uuid: {}, serverId: {}, corpId: {}, qwUserId: {}", vid, uuid, serverId, corpId, qwUserId);
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ QwImUserDTO userDTO = new QwImUserDTO();
|
|
|
|
|
+ userDTO.setUserId(qwExternalContact.getId());
|
|
|
|
|
+ userDTO.setUserName(qwExternalContact.getName());
|
|
|
|
|
+ userDTO.setAvatar(qwExternalContact.getAvatar());
|
|
|
|
|
+ userDTO.setUserType(1);
|
|
|
|
|
+ return userDTO;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 企微用户
|
|
|
|
|
+ else {
|
|
|
|
|
+ QwUser qwUser = qwUserService.selectQwUserByVid(vid);
|
|
|
|
|
+ if (Objects.isNull(qwUser)){
|
|
|
|
|
+ log.warn("企微用户不存在 vid: {}", vid);
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ QwImUserDTO userDTO = new QwImUserDTO();
|
|
|
|
|
+ userDTO.setUserId(qwUser.getId());
|
|
|
|
|
+ userDTO.setUserName(qwUser.getQwUserName());
|
|
|
|
|
+ userDTO.setAvatar(qwUser.getAvatar());
|
|
|
|
|
+ userDTO.setUserType(2);
|
|
|
|
|
+ return userDTO;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 修改消息
|
|
|
|
|
+ */
|
|
|
|
|
+ @DataSource(DataSourceType.SHARDING)
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public QwMessageListVO updateQwMsg(Long qwUserId, Long senderVid, Long receiverVid, Long serverId, String uuid, boolean isRoom, String chatId, String qwAppInfo) {
|
|
|
|
|
+ QwUser qwUser = qwUserService.selectQwUserById(qwUserId);
|
|
|
|
|
+ if (Objects.isNull(qwUser)) {
|
|
|
|
|
+ log.warn("企微用户不存在 qwUserId: {}", qwUserId);
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 获取发送人
|
|
|
|
|
+ QwImUserDTO sender = getUserByVid(senderVid, uuid, serverId, qwUser.getCorpId(), qwUser.getQwUserId());
|
|
|
|
|
+ if (Objects.isNull(sender)) {
|
|
|
|
|
+ log.warn("sender用户不存在 senderVid: {}", senderVid);
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 获取接收者
|
|
|
|
|
+ QwImUserDTO receiver = getUserByVid(receiverVid, uuid, serverId, qwUser.getCorpId(), qwUser.getQwUserId());
|
|
|
|
|
+
|
|
|
|
|
+ // 查询会话
|
|
|
|
|
+ QwSession qwSession = null;
|
|
|
|
|
+ if (isRoom) {
|
|
|
|
|
+ QwGroupChat qwGroupChat = qwGroupChatMapper.selectQwGroupChatByChatId(chatId);
|
|
|
|
|
+ if (Objects.isNull(qwGroupChat)){
|
|
|
|
|
+ log.warn("群聊不存在 serverId: {}, corpId: {}, qwUserId: {}, chatId: {}", qwUser.getServerId(), qwUser.getCorpId(), qwUser.getQwUserId(), chatId);
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ qwSession = qwSessionMapper.selectQwSessionByChatIdAndQwUserId(chatId, qwUser.getId());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ QwImUserDTO extUser = null;
|
|
|
|
|
+
|
|
|
|
|
+ // 获取外部联系人
|
|
|
|
|
+ if (sender.getUserType() == 1) {
|
|
|
|
|
+ extUser = sender;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (receiver != null && receiver.getUserType() == 1) {
|
|
|
|
|
+ extUser = receiver;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (extUser != null) {
|
|
|
|
|
+ qwSession = qwSessionMapper.selectQwSessionByExtIdAndQwUserId(extUser.getUserId(), qwUser.getId());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (qwSession == null) {
|
|
|
|
|
+ log.warn("获取session失败 senderVid: {}, receiverVid: {}", senderVid, receiverVid);
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ QwMsg qwMsg = qwMsgMapper.selectQwMsgBySessionIdAndQwAppInfo(qwSession.getSessionId(), qwAppInfo);
|
|
|
|
|
+ if (qwMsg == null) {
|
|
|
|
|
+ log.warn("消息不存在 sessionId: {}, appInfo: {}", qwSession.getSessionId(), qwAppInfo);
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ qwMsg.setMsgType(6);
|
|
|
|
|
+ qwMsg.setSessionId(null);
|
|
|
|
|
+ qwMsgMapper.updateQwMsg(qwMsg);
|
|
|
|
|
+
|
|
|
|
|
+ String type = "text";
|
|
|
|
|
+ MsgType messageType = MsgType.getMsgType(qwMsg.getMsgType());
|
|
|
|
|
+ if (Objects.nonNull(messageType)){
|
|
|
|
|
+ type = messageType.getValue();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ qwSession.setLastMsgId(qwMsg.getMsgId());
|
|
|
|
|
+ qwSession.setLastMsgType(type);
|
|
|
|
|
+ qwSession.setLastSendTime(qwMsg.getCreateTime().getTime());
|
|
|
|
|
+ qwSession.setLastContent("");
|
|
|
|
|
+ qwSessionMapper.updateQwSession(qwSession);
|
|
|
|
|
+
|
|
|
|
|
+ // 组装返回消息结构
|
|
|
|
|
+ QwMessageListVO listVO = new QwMessageListVO();
|
|
|
|
|
+ QWFromUser qwFromUser = new QWFromUser();
|
|
|
|
|
+ qwFromUser.setId(sender.getUserId());
|
|
|
|
|
+ qwFromUser.setAvatar(sender.getAvatar());
|
|
|
|
|
+ qwFromUser.setDisplayName(sender.getUserName());
|
|
|
|
|
+
|
|
|
|
|
+ listVO.setCompanyUserId(qwUser.getCompanyUserId());
|
|
|
|
|
+ listVO.setType(type);
|
|
|
|
|
+ listVO.setStatus("succeed");
|
|
|
|
|
+ listVO.setExtId(qwMsg.getQwExtId());
|
|
|
|
|
+ listVO.setFromUser(qwFromUser);
|
|
|
|
|
+ listVO.setSendTime(qwMsg.getCreateTime().getTime());
|
|
|
|
|
+ listVO.setId(qwMsg.getMsgId().toString());
|
|
|
|
|
+ listVO.setContent(qwMsg.getContent());
|
|
|
|
|
+ listVO.setToContactId(String.valueOf(qwSession.getSessionId()));
|
|
|
|
|
+ listVO.setAppKey(qwUser.getAppKey());
|
|
|
|
|
+ return listVO;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|