|
|
@@ -9,6 +9,7 @@ import com.fs.common.utils.uuid.IdUtils;
|
|
|
import com.fs.fastGpt.domain.FastGptRole;
|
|
|
import com.fs.fastGpt.service.AiHookService;
|
|
|
import com.fs.fastGpt.service.IFastGptRoleService;
|
|
|
+import com.fs.framework.datasource.TenantDataSourceUtil;
|
|
|
import com.fs.his.domain.FsStoreOrder;
|
|
|
import com.fs.his.dto.ExpressInfoDTO;
|
|
|
import com.fs.his.dto.TracesDTO;
|
|
|
@@ -27,6 +28,7 @@ import com.fs.qw.service.IQwUserVoiceLogService;
|
|
|
import com.fs.sop.mapper.QwSopLogsMapper;
|
|
|
import com.fs.sop.mapper.SopUserLogsInfoMapper;
|
|
|
import com.fs.sop.params.GetQwSopLogsByJsApiParam;
|
|
|
+import com.fs.tenant.service.TenantInfoService;
|
|
|
import com.fs.voice.utils.StringUtil;
|
|
|
import com.fs.wxwork.dto.*;
|
|
|
import com.fs.wxwork.service.WxWorkService;
|
|
|
@@ -34,6 +36,8 @@ import io.swagger.annotations.Api;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.json.JSONObject;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.util.*;
|
|
|
@@ -50,7 +54,8 @@ import static com.fs.his.utils.PhoneUtil.decryptPhone;
|
|
|
@Slf4j
|
|
|
public class QwMsgController {
|
|
|
@Autowired
|
|
|
- RedisCache redisCache;
|
|
|
+ @Qualifier("redisTemplate")
|
|
|
+ RedisTemplate<Object, Object> redisForObject;
|
|
|
@Autowired
|
|
|
AiHookService aiHookService;
|
|
|
@Autowired
|
|
|
@@ -80,11 +85,15 @@ public class QwMsgController {
|
|
|
@Autowired
|
|
|
private IFsStoreOrderService storeOrderService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private TenantDataSourceUtil tenantDataSourceUtil;
|
|
|
+
|
|
|
+
|
|
|
@GetMapping("/sendExpressInfo/{orderId}")
|
|
|
public R sendExpressInfo(@PathVariable Long orderId){
|
|
|
- String isSend = redisCache.getCacheObject("fs:express:info:send:" +orderId);
|
|
|
+ Object isSend = redisForObject.opsForValue().get("fs:express:info:send:" +orderId);
|
|
|
if(isSend == null){
|
|
|
- redisCache.setCacheObject("fs:express:info:send:" +orderId, "1",2, TimeUnit.MINUTES);
|
|
|
+ redisForObject.opsForValue().set("fs:express:info:send:" +orderId, "1",2, TimeUnit.MINUTES);
|
|
|
FsStoreOrder order = fsStoreOrderService.selectFsStoreOrderByOrderId(orderId);
|
|
|
if(order != null && order.getUserId() != null){
|
|
|
List<QwExternalContact> qwExternalContact = externalContactService.selectQwExternalContactByFsUserIdAndCompany(order.getUserId(),order.getCompanyUserId());
|
|
|
@@ -195,256 +204,257 @@ public class QwMsgController {
|
|
|
return expressInfoDTO;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- @PostMapping("/callback/{serverId}")
|
|
|
+ @PostMapping("/callback/{serverId}/{tenantId}")
|
|
|
@ResponseBody
|
|
|
- public Map<String,String> callback(@RequestBody String json,@PathVariable Long serverId ){
|
|
|
- // System.out.println(json);
|
|
|
+ public Map<String,String> callback(@RequestBody String json,@PathVariable Long serverId ,@PathVariable Long tenantId){
|
|
|
+
|
|
|
+ // System.out.println(json);
|
|
|
WxWorkMsgResp wxWorkMsgResp = JSON.parseObject(json, WxWorkMsgResp.class);
|
|
|
Integer type = wxWorkMsgResp.getType();
|
|
|
HashMap<String, String> map = new HashMap<>();
|
|
|
map.put("errorcode","0");
|
|
|
map.put("errmsg","ok");
|
|
|
- Long id = redisCache.getCacheObject("qrCode:uuid:"+wxWorkMsgResp.getUuid());
|
|
|
- if (id==null){
|
|
|
- return map;
|
|
|
- }
|
|
|
- switch (type){
|
|
|
- case 100001:
|
|
|
- log.info("id:{}, 扫码返回", id);
|
|
|
- break;
|
|
|
- case 100002:
|
|
|
- log.info("id:{}, 取消扫码", id);
|
|
|
- // redisCache.setCacheObject("qrCodeUid:"+wxWorkMsgResp.getUuid(),100002,10, TimeUnit.MINUTES);
|
|
|
- break;
|
|
|
- case 100003:
|
|
|
- log.info("id:{}, 确认扫码返回", id);
|
|
|
-
|
|
|
- break;
|
|
|
- case 104001:
|
|
|
- log.info("id:{}, 登录成功", id);
|
|
|
-
|
|
|
- JSONObject jsonObject = new JSONObject(wxWorkMsgResp.getJson());
|
|
|
- QwUser qu = qwUserMapper.selectQwUserById(id);
|
|
|
- Long corpId = jsonObject.getLong("Corpid");
|
|
|
- log.info("id:{}, 回调中的"+corpId, id);
|
|
|
- String sCorpId = wxWorkService.getCorpId(wxWorkMsgResp.getUuid(), corpId,serverId);
|
|
|
- if (sCorpId==null&& sCorpId.isEmpty()){
|
|
|
- break;
|
|
|
- }
|
|
|
- if (!qu.getCorpId().equals(sCorpId)){
|
|
|
- redisCache.setCacheObject("qrCodeUid:"+wxWorkMsgResp.getUuid(),22,10, TimeUnit.MINUTES);
|
|
|
- log.info("id:{}, 公司不匹配不给登录", id);
|
|
|
- WxWorkGetQrCodeDTO wxWorkGetQrCodeDTO = new WxWorkGetQrCodeDTO();
|
|
|
- wxWorkGetQrCodeDTO.setUuid(wxWorkMsgResp.getUuid());
|
|
|
- wxWorkService.LoginOut(wxWorkGetQrCodeDTO,serverId);
|
|
|
- log.info("id:{}, 调用退出登录", id);
|
|
|
- break;
|
|
|
- }
|
|
|
- if (!qu.getQwUserId().equals(jsonObject.get("acctid"))){
|
|
|
- redisCache.setCacheObject("qrCodeUid:"+wxWorkMsgResp.getUuid(),23,10, TimeUnit.MINUTES);
|
|
|
- log.info("id:{}, 账号不匹配不给登录", id);
|
|
|
- WxWorkGetQrCodeDTO wxWorkGetQrCodeDTO = new WxWorkGetQrCodeDTO();
|
|
|
- wxWorkGetQrCodeDTO.setUuid(wxWorkMsgResp.getUuid());
|
|
|
- wxWorkService.LoginOut(wxWorkGetQrCodeDTO,serverId);
|
|
|
- log.info("id:{}, 调用退出登录", id);
|
|
|
+ tenantDataSourceUtil.execute(tenantId , () -> {
|
|
|
+ Object o = redisForObject.opsForValue().get("qrCode:uuid:" + wxWorkMsgResp.getUuid());
|
|
|
+ Long id = (Long) o;
|
|
|
+ if (id==null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ switch (type){
|
|
|
+ case 100001:
|
|
|
+ log.info("id:{}, 扫码返回", id);
|
|
|
break;
|
|
|
- }
|
|
|
- QwUser qwUser = new QwUser();
|
|
|
- qwUser.setId(id);
|
|
|
- qwUser.setVid(jsonObject.get("Vid").toString());
|
|
|
- qwUser.setIpadStatus(1);
|
|
|
- qwUserMapper.updateQwUser(qwUser);
|
|
|
- log.info("id:{}, 存Vid", id);
|
|
|
- redisCache.setCacheObject("qrCodeUid:"+wxWorkMsgResp.getUuid(),104001,10, TimeUnit.MINUTES);
|
|
|
- break;
|
|
|
- case 100006:
|
|
|
-
|
|
|
- break;
|
|
|
- case 100004:
|
|
|
- log.info("id:{}, 需要验证二维码消息", id);
|
|
|
- redisCache.setCacheObject("qrCodeUid:"+wxWorkMsgResp.getUuid(),100004,10, TimeUnit.MINUTES);
|
|
|
- break;
|
|
|
- case 100012:
|
|
|
- log.info("id:{}, 需要二次验证:"+wxWorkMsgResp.getJson(), id);
|
|
|
-
|
|
|
- redisCache.setCacheObject("qrCodeUid:"+wxWorkMsgResp.getUuid(),100012,10, TimeUnit.MINUTES);
|
|
|
-
|
|
|
- break;
|
|
|
- case 100005:
|
|
|
-
|
|
|
- log.info("id:{}, 手机端结束登录:"+wxWorkMsgResp.getJson(), id);
|
|
|
- JSONObject jsonObject1 = new JSONObject(wxWorkMsgResp.getJson());
|
|
|
- qwUserStatus(wxWorkMsgResp.getUuid(),0, jsonObject1.getString("msg"));
|
|
|
- break;
|
|
|
- case 100008:
|
|
|
- QwUser vidUser = qwUserMapper.selectQwUserById(id);
|
|
|
- if (vidUser.getUid().equals(wxWorkMsgResp.getUuid())){
|
|
|
- log.info("id:{}, 当前账号在其他设备登录:"+wxWorkMsgResp.getJson(), id);
|
|
|
- JSONObject jsonObject2 = new JSONObject(wxWorkMsgResp.getJson());
|
|
|
- qwUserStatus(wxWorkMsgResp.getUuid(),0, jsonObject2.getString("msg"));
|
|
|
- }
|
|
|
- log.info("id:{}, 当前账号重新登录:"+wxWorkMsgResp.getJson(), id);
|
|
|
- break;
|
|
|
- case 100007:
|
|
|
- log.info("id:{}, 异常断开:"+wxWorkMsgResp.getJson(), id);
|
|
|
- JSONObject jsonObject3 = new JSONObject(wxWorkMsgResp.getJson());
|
|
|
- qwUserStatus(wxWorkMsgResp.getUuid(),0, "异常断开 - " + jsonObject3.getString("msg"));
|
|
|
- break;
|
|
|
- case 100009:
|
|
|
- log.info("id:{}, 二次验证:"+wxWorkMsgResp.getJson(), id);
|
|
|
- JSONObject jsonObject4 = new JSONObject(wxWorkMsgResp.getJson());
|
|
|
- qwUserStatus(wxWorkMsgResp.getUuid(),0, "二次验证 - " + jsonObject4.getString("msg"));
|
|
|
- break;
|
|
|
- case 102001:
|
|
|
- case 102002:
|
|
|
- WxWorkMessageDTO wxWorkMessageDTO1 = JSON.parseObject(wxWorkMsgResp.getJson(), WxWorkMessageDTO.class);
|
|
|
- handleSopBlockOrDel(id,wxWorkMessageDTO1,wxWorkMsgResp.getUuid(),5);
|
|
|
- break;
|
|
|
- case 102000:
|
|
|
- WxWorkMessageDTO wxWorkMessageDTO = JSON.parseObject(wxWorkMsgResp.getJson(), WxWorkMessageDTO.class);
|
|
|
- if (wxWorkMessageDTO.getIs_room()!=0){
|
|
|
+ case 100002:
|
|
|
+ log.info("id:{}, 取消扫码", id);
|
|
|
+ // redisCache.setCacheObject("qrCodeUid:"+wxWorkMsgResp.getUuid(),100002,10, TimeUnit.MINUTES);
|
|
|
break;
|
|
|
- }
|
|
|
- if (wxWorkMessageDTO.getReferid()!=0){
|
|
|
+ case 100003:
|
|
|
+ log.info("id:{}, 确认扫码返回", id);
|
|
|
+
|
|
|
break;
|
|
|
- }
|
|
|
- if (wxWorkMessageDTO.getMsgtype()==2||wxWorkMessageDTO.getMsgtype()==0||wxWorkMessageDTO.getMsgtype()==16||wxWorkMessageDTO.getMsgtype() == 101||wxWorkMessageDTO.getMsgtype() == 104){
|
|
|
-
|
|
|
- String content = wxWorkMessageDTO.getContent();
|
|
|
- log.info("id:{}, 接收人:"+wxWorkMessageDTO.getReceiver(), id);
|
|
|
- log.info("id:{}, 发送人:"+wxWorkMessageDTO.getSender(), id);
|
|
|
- log.info("id:{}, 内容:"+content, id);
|
|
|
- Long receiver = wxWorkMessageDTO.getReceiver();
|
|
|
- Long sender = wxWorkMessageDTO.getSender();
|
|
|
- if(wxWorkMessageDTO.getMsgtype()==16){
|
|
|
- WxwSpeechToTextEntityDTO ste = new WxwSpeechToTextEntityDTO();
|
|
|
- ste.setMsgid(wxWorkMessageDTO.getMsg_id());
|
|
|
- ste.setUuid(wxWorkMsgResp.getUuid());
|
|
|
- WxWorkResponseDTO<WxwSpeechToTextEntityRespDTO> dto = wxWorkService.SpeechToTextEntity(ste, serverId);
|
|
|
- System.out.println(dto);
|
|
|
- if(dto.getErrcode() != 0 || Objects.isNull(dto.getData()) || StringUtils.isBlank(dto.getData().getText())){
|
|
|
- try {
|
|
|
- TimeUnit.SECONDS.sleep(2); // 阻塞2秒
|
|
|
- } catch (InterruptedException e) {
|
|
|
- Thread.currentThread().interrupt(); // 处理中断异常
|
|
|
- log.info("id:{}, 第一次语音转换失败", id);
|
|
|
- }
|
|
|
- dto = wxWorkService.SpeechToTextEntity(ste, serverId);
|
|
|
- }
|
|
|
- WxwSpeechToTextEntityRespDTO data = dto.getData();
|
|
|
- content = data.getText();
|
|
|
- if(content == null || content.isEmpty()){
|
|
|
- content = "==语音转换失败==";
|
|
|
- }
|
|
|
- log.info("id:{}, 语音消息"+content, id);
|
|
|
+ case 104001:
|
|
|
+ log.info("id:{}, 登录成功", id);
|
|
|
+
|
|
|
+ JSONObject jsonObject = new JSONObject(wxWorkMsgResp.getJson());
|
|
|
+ QwUser qu = qwUserMapper.selectQwUserById(id);
|
|
|
+ Long corpId = jsonObject.getLong("Corpid");
|
|
|
+ log.info("id:{}, 回调中的"+corpId, id);
|
|
|
+ String sCorpId = wxWorkService.getCorpId(wxWorkMsgResp.getUuid(), corpId,serverId);
|
|
|
+ if (sCorpId==null&& sCorpId.isEmpty()){
|
|
|
+ break;
|
|
|
}
|
|
|
- else if (wxWorkMessageDTO.getMsgtype() == 101){
|
|
|
- content = processImageMessage(serverId, wxWorkMessageDTO, wxWorkMsgResp);
|
|
|
- log.info("id:{}, 用户发送图片"+content, id);
|
|
|
+ if (!qu.getCorpId().equals(sCorpId)){
|
|
|
+ redisForObject.opsForValue().set("qrCodeUid:"+wxWorkMsgResp.getUuid(),22,10, TimeUnit.MINUTES);
|
|
|
+ log.info("id:{}, 公司不匹配不给登录", id);
|
|
|
+ WxWorkGetQrCodeDTO wxWorkGetQrCodeDTO = new WxWorkGetQrCodeDTO();
|
|
|
+ wxWorkGetQrCodeDTO.setUuid(wxWorkMsgResp.getUuid());
|
|
|
+ wxWorkService.LoginOut(wxWorkGetQrCodeDTO,serverId);
|
|
|
+ log.info("id:{}, 调用退出登录", id);
|
|
|
+ break;
|
|
|
}
|
|
|
- // gif 表情消息
|
|
|
- else if (wxWorkMessageDTO.getMsgtype() == 104){
|
|
|
- content = wxWorkMessageDTO.getUrl();
|
|
|
- log.info("id:{}, 用户发送表情"+content, id);
|
|
|
- }//视频号
|
|
|
-
|
|
|
- if (2000000000000000L-receiver>0){
|
|
|
- log.info("id:{}, 客户发送", id);
|
|
|
- aiHookService.qwHookNotifyAiReply(id,sender,content,wxWorkMsgResp.getUuid(),wxWorkMessageDTO.getMsgtype());
|
|
|
- }else {
|
|
|
- log.info("销售发送");
|
|
|
- aiHookService.qwHookNotifyAddMsgNew(id,receiver,content,wxWorkMsgResp.getUuid(),1);
|
|
|
+ if (!qu.getQwUserId().equals(jsonObject.get("acctid"))){
|
|
|
+ redisForObject.opsForValue().set("qrCodeUid:"+wxWorkMsgResp.getUuid(),23,10, TimeUnit.MINUTES);
|
|
|
+ log.info("id:{}, 账号不匹配不给登录", id);
|
|
|
+ WxWorkGetQrCodeDTO wxWorkGetQrCodeDTO = new WxWorkGetQrCodeDTO();
|
|
|
+ wxWorkGetQrCodeDTO.setUuid(wxWorkMsgResp.getUuid());
|
|
|
+ wxWorkService.LoginOut(wxWorkGetQrCodeDTO,serverId);
|
|
|
+ log.info("id:{}, 调用退出登录", id);
|
|
|
+ break;
|
|
|
}
|
|
|
+ QwUser qwUser = new QwUser();
|
|
|
+ qwUser.setId(id);
|
|
|
+ qwUser.setVid(jsonObject.get("Vid").toString());
|
|
|
+ qwUser.setIpadStatus(1);
|
|
|
+ qwUserMapper.updateQwUser(qwUser);
|
|
|
+ log.info("id:{}, 存Vid", id);
|
|
|
+ redisForObject.opsForValue().set("qrCodeUid:"+wxWorkMsgResp.getUuid(),104001,10, TimeUnit.MINUTES);
|
|
|
+ break;
|
|
|
+ case 100006:
|
|
|
|
|
|
- }
|
|
|
- //视频号
|
|
|
- if (wxWorkMessageDTO.getMsgtype()==141){
|
|
|
- QwUser qwUserByAppKey = qwUserMapper.selectQwUserById(id);
|
|
|
- log.info("进入到视频号:{}",qwUserByAppKey);
|
|
|
-
|
|
|
- if(qwUserByAppKey.getVideoGetStatus() != null && qwUserByAppKey.getVideoGetStatus() == 1){
|
|
|
- QwUserVideo qwUserVideo = qwUserVideoService.selectByObjectId(wxWorkMessageDTO.getObjectId(), qwUserByAppKey.getId());
|
|
|
- if(qwUserVideo == null){
|
|
|
- QwUserVideo userVideo=new QwUserVideo();
|
|
|
- userVideo.setSenderName(wxWorkMessageDTO.getSender_name());
|
|
|
- userVideo.setAppKey(qwUserByAppKey.getAppKey());
|
|
|
- userVideo.setNickName(wxWorkMessageDTO.getNickname());
|
|
|
- userVideo.setObjectId(wxWorkMessageDTO.getObjectId());
|
|
|
- userVideo.setCoverUrl(wxWorkMessageDTO.getCover_url());
|
|
|
- userVideo.setThumbUrl(wxWorkMessageDTO.getThumb_url());
|
|
|
- userVideo.setAvatar(wxWorkMessageDTO.getAvatar());
|
|
|
- userVideo.setDesc(wxWorkMessageDTO.getDesc());
|
|
|
- userVideo.setUrl(wxWorkMessageDTO.getUrl());
|
|
|
- userVideo.setExtras(wxWorkMessageDTO.getExtras());
|
|
|
- userVideo.setObjectNonceId(wxWorkMessageDTO.getObjectNonceId());
|
|
|
- userVideo.setQwUserId(qwUserByAppKey.getId());
|
|
|
- userVideo.setCompanyUserId(qwUserByAppKey.getCompanyUserId());
|
|
|
- userVideo.setCompanyId(qwUserByAppKey.getCompanyId());
|
|
|
- qwUserVideoService.insertQwUserVideo(userVideo);
|
|
|
- log.info("存储完成:userVideo={}",userVideo);
|
|
|
- }
|
|
|
+ break;
|
|
|
+ case 100004:
|
|
|
+ log.info("id:{}, 需要验证二维码消息", id);
|
|
|
+ redisForObject.opsForValue().set("qrCodeUid:"+wxWorkMsgResp.getUuid(),100004,10, TimeUnit.MINUTES);
|
|
|
+ break;
|
|
|
+ case 100012:
|
|
|
+ log.info("id:{}, 需要二次验证:"+wxWorkMsgResp.getJson(), id);
|
|
|
+
|
|
|
+ redisForObject.opsForValue().set("qrCodeUid:"+wxWorkMsgResp.getUuid(),100012,10, TimeUnit.MINUTES);
|
|
|
+
|
|
|
+ break;
|
|
|
+ case 100005:
|
|
|
+
|
|
|
+ log.info("id:{}, 手机端结束登录:"+wxWorkMsgResp.getJson(), id);
|
|
|
+ JSONObject jsonObject1 = new JSONObject(wxWorkMsgResp.getJson());
|
|
|
+ qwUserStatus(wxWorkMsgResp.getUuid(),0, jsonObject1.getString("msg"));
|
|
|
+ break;
|
|
|
+ case 100008:
|
|
|
+ QwUser vidUser = qwUserMapper.selectQwUserById(id);
|
|
|
+ if (vidUser.getUid().equals(wxWorkMsgResp.getUuid())){
|
|
|
+ log.info("id:{}, 当前账号在其他设备登录:"+wxWorkMsgResp.getJson(), id);
|
|
|
+ JSONObject jsonObject2 = new JSONObject(wxWorkMsgResp.getJson());
|
|
|
+ qwUserStatus(wxWorkMsgResp.getUuid(),0, jsonObject2.getString("msg"));
|
|
|
}
|
|
|
- }
|
|
|
- //语音通话
|
|
|
- if (wxWorkMessageDTO.getMsgtype()==40){
|
|
|
- if (wxWorkMessageDTO.getRecordtype()==null){
|
|
|
+ log.info("id:{}, 当前账号重新登录:"+wxWorkMsgResp.getJson(), id);
|
|
|
+ break;
|
|
|
+ case 100007:
|
|
|
+ log.info("id:{}, 异常断开:"+wxWorkMsgResp.getJson(), id);
|
|
|
+ JSONObject jsonObject3 = new JSONObject(wxWorkMsgResp.getJson());
|
|
|
+ qwUserStatus(wxWorkMsgResp.getUuid(),0, "异常断开 - " + jsonObject3.getString("msg"));
|
|
|
+ break;
|
|
|
+ case 100009:
|
|
|
+ log.info("id:{}, 二次验证:"+wxWorkMsgResp.getJson(), id);
|
|
|
+ JSONObject jsonObject4 = new JSONObject(wxWorkMsgResp.getJson());
|
|
|
+ qwUserStatus(wxWorkMsgResp.getUuid(),0, "二次验证 - " + jsonObject4.getString("msg"));
|
|
|
+ break;
|
|
|
+ case 102001:
|
|
|
+ case 102002:
|
|
|
+ WxWorkMessageDTO wxWorkMessageDTO1 = JSON.parseObject(wxWorkMsgResp.getJson(), WxWorkMessageDTO.class);
|
|
|
+ handleSopBlockOrDel(id,wxWorkMessageDTO1,wxWorkMsgResp.getUuid(),5);
|
|
|
+ break;
|
|
|
+ case 102000:
|
|
|
+ WxWorkMessageDTO wxWorkMessageDTO = JSON.parseObject(wxWorkMsgResp.getJson(), WxWorkMessageDTO.class);
|
|
|
+ if (wxWorkMessageDTO.getIs_room()!=0){
|
|
|
break;
|
|
|
}
|
|
|
- Long receiver = wxWorkMessageDTO.getReceiver();
|
|
|
- Long extId=null;
|
|
|
- long totalSeconds=0L;
|
|
|
- if (2000000000000000L-receiver>0){
|
|
|
- extId = wxWorkMessageDTO.getSender();
|
|
|
- log.info("id:{}, 客户发起", id);
|
|
|
- }else {
|
|
|
- log.info("id:{}, 销售发起", id);
|
|
|
- extId = wxWorkMessageDTO.getReceiver();
|
|
|
+ if (wxWorkMessageDTO.getReferid()!=0){
|
|
|
+ break;
|
|
|
}
|
|
|
- Integer recordType = wxWorkMessageDTO.getRecordtype();
|
|
|
- if (recordType==5){
|
|
|
- String recordwording = wxWorkMessageDTO.getRecordwording();
|
|
|
- //String recordwording = "通话时长01:20:07";
|
|
|
- if (recordwording != null && !recordwording.isEmpty()){
|
|
|
- // 同时匹配 "HH:mm:ss" 和 "mm:ss" 格式
|
|
|
- Pattern pattern = Pattern.compile("(\\d+):(\\d+)(?::(\\d+))?");
|
|
|
- Matcher matcher = pattern.matcher(recordwording);
|
|
|
- if (matcher.find()) {
|
|
|
- int hours = 0;
|
|
|
- int minutes;
|
|
|
- int seconds;
|
|
|
-
|
|
|
- // 如果有小时部分(匹配到3个组)
|
|
|
- if (matcher.group(3) != null) {
|
|
|
- hours = Integer.parseInt(matcher.group(1));
|
|
|
- minutes = Integer.parseInt(matcher.group(2));
|
|
|
- seconds = Integer.parseInt(matcher.group(3));
|
|
|
- }
|
|
|
- else {// 只有分钟和秒(匹配到2个组)
|
|
|
- minutes = Integer.parseInt(matcher.group(1));
|
|
|
- seconds = Integer.parseInt(matcher.group(2));
|
|
|
+ if (wxWorkMessageDTO.getMsgtype()==2||wxWorkMessageDTO.getMsgtype()==0||wxWorkMessageDTO.getMsgtype()==16||wxWorkMessageDTO.getMsgtype() == 101||wxWorkMessageDTO.getMsgtype() == 104){
|
|
|
+
|
|
|
+ String content = wxWorkMessageDTO.getContent();
|
|
|
+ log.info("id:{}, 接收人:"+wxWorkMessageDTO.getReceiver(), id);
|
|
|
+ log.info("id:{}, 发送人:"+wxWorkMessageDTO.getSender(), id);
|
|
|
+ log.info("id:{}, 内容:"+content, id);
|
|
|
+ Long receiver = wxWorkMessageDTO.getReceiver();
|
|
|
+ Long sender = wxWorkMessageDTO.getSender();
|
|
|
+ if(wxWorkMessageDTO.getMsgtype()==16){
|
|
|
+ WxwSpeechToTextEntityDTO ste = new WxwSpeechToTextEntityDTO();
|
|
|
+ ste.setMsgid(wxWorkMessageDTO.getMsg_id());
|
|
|
+ ste.setUuid(wxWorkMsgResp.getUuid());
|
|
|
+ WxWorkResponseDTO<WxwSpeechToTextEntityRespDTO> dto = wxWorkService.SpeechToTextEntity(ste, serverId);
|
|
|
+ System.out.println(dto);
|
|
|
+ if(dto.getErrcode() != 0 || Objects.isNull(dto.getData()) || StringUtils.isBlank(dto.getData().getText())){
|
|
|
+ try {
|
|
|
+ TimeUnit.SECONDS.sleep(2); // 阻塞2秒
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ Thread.currentThread().interrupt(); // 处理中断异常
|
|
|
+ log.info("id:{}, 第一次语音转换失败", id);
|
|
|
}
|
|
|
- totalSeconds = hours * 3600L + minutes * 60L + seconds;
|
|
|
- log.info("id:{}, 总通话秒数: " + totalSeconds, id);
|
|
|
+ dto = wxWorkService.SpeechToTextEntity(ste, serverId);
|
|
|
}
|
|
|
+ WxwSpeechToTextEntityRespDTO data = dto.getData();
|
|
|
+ content = data.getText();
|
|
|
+ if(content == null || content.isEmpty()){
|
|
|
+ content = "==语音转换失败==";
|
|
|
+ }
|
|
|
+ log.info("id:{}, 语音消息"+content, id);
|
|
|
+ }
|
|
|
+ else if (wxWorkMessageDTO.getMsgtype() == 101){
|
|
|
+ content = processImageMessage(serverId, wxWorkMessageDTO, wxWorkMsgResp);
|
|
|
+ log.info("id:{}, 用户发送图片"+content, id);
|
|
|
+ }
|
|
|
+ // gif 表情消息
|
|
|
+ else if (wxWorkMessageDTO.getMsgtype() == 104){
|
|
|
+ content = wxWorkMessageDTO.getUrl();
|
|
|
+ log.info("id:{}, 用户发送表情"+content, id);
|
|
|
+ }//视频号
|
|
|
+
|
|
|
+ final String finalContent = content;
|
|
|
+ if (2000000000000000L-receiver>0){
|
|
|
+ log.info("id:{}, 客户发送", id);
|
|
|
+ aiHookService.qwHookNotifyAiReply(id,sender,finalContent,wxWorkMsgResp.getUuid(),wxWorkMessageDTO.getMsgtype(),tenantId);
|
|
|
+ }else {
|
|
|
+ log.info("销售发送");
|
|
|
+ aiHookService.qwHookNotifyAddMsgNew(id,receiver,content,wxWorkMsgResp.getUuid(),1);
|
|
|
}
|
|
|
- } else if (recordType==2){
|
|
|
- log.info("id:{}, 通话挂断", id);
|
|
|
- }else if (recordType==3){
|
|
|
- log.info("通话未接听");
|
|
|
- }else {
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- qwUserVoiceLogService.addQuUserVoiceByIpadCallback(id,extId,recordType,totalSeconds,wxWorkMsgResp.getUuid());
|
|
|
- }
|
|
|
-
|
|
|
- break;
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
+ //视频号
|
|
|
+ if (wxWorkMessageDTO.getMsgtype()==141){
|
|
|
+ QwUser qwUserByAppKey = qwUserMapper.selectQwUserById(id);
|
|
|
+ log.info("进入到视频号:{}",qwUserByAppKey);
|
|
|
+
|
|
|
+ if(qwUserByAppKey.getVideoGetStatus() != null && qwUserByAppKey.getVideoGetStatus() == 1){
|
|
|
+ QwUserVideo qwUserVideo = qwUserVideoService.selectByObjectId(wxWorkMessageDTO.getObjectId(), qwUserByAppKey.getId());
|
|
|
+ if(qwUserVideo == null){
|
|
|
+ QwUserVideo userVideo=new QwUserVideo();
|
|
|
+ userVideo.setSenderName(wxWorkMessageDTO.getSender_name());
|
|
|
+ userVideo.setAppKey(qwUserByAppKey.getAppKey());
|
|
|
+ userVideo.setNickName(wxWorkMessageDTO.getNickname());
|
|
|
+ userVideo.setObjectId(wxWorkMessageDTO.getObjectId());
|
|
|
+ userVideo.setCoverUrl(wxWorkMessageDTO.getCover_url());
|
|
|
+ userVideo.setThumbUrl(wxWorkMessageDTO.getThumb_url());
|
|
|
+ userVideo.setAvatar(wxWorkMessageDTO.getAvatar());
|
|
|
+ userVideo.setDesc(wxWorkMessageDTO.getDesc());
|
|
|
+ userVideo.setUrl(wxWorkMessageDTO.getUrl());
|
|
|
+ userVideo.setExtras(wxWorkMessageDTO.getExtras());
|
|
|
+ userVideo.setObjectNonceId(wxWorkMessageDTO.getObjectNonceId());
|
|
|
+ userVideo.setQwUserId(qwUserByAppKey.getId());
|
|
|
+ userVideo.setCompanyUserId(qwUserByAppKey.getCompanyUserId());
|
|
|
+ userVideo.setCompanyId(qwUserByAppKey.getCompanyId());
|
|
|
+ qwUserVideoService.insertQwUserVideo(userVideo);
|
|
|
+ log.info("存储完成:userVideo={}",userVideo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //语音通话
|
|
|
+ if (wxWorkMessageDTO.getMsgtype()==40){
|
|
|
+ if (wxWorkMessageDTO.getRecordtype()==null){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ Long receiver = wxWorkMessageDTO.getReceiver();
|
|
|
+ Long extId=null;
|
|
|
+ long totalSeconds=0L;
|
|
|
+ if (2000000000000000L-receiver>0){
|
|
|
+ extId = wxWorkMessageDTO.getSender();
|
|
|
+ log.info("id:{}, 客户发起", id);
|
|
|
+ }else {
|
|
|
+ log.info("id:{}, 销售发起", id);
|
|
|
+ extId = wxWorkMessageDTO.getReceiver();
|
|
|
+ }
|
|
|
+ Integer recordType = wxWorkMessageDTO.getRecordtype();
|
|
|
+ if (recordType==5){
|
|
|
+ String recordwording = wxWorkMessageDTO.getRecordwording();
|
|
|
+ //String recordwording = "通话时长01:20:07";
|
|
|
+ if (recordwording != null && !recordwording.isEmpty()){
|
|
|
+ // 同时匹配 "HH:mm:ss" 和 "mm:ss" 格式
|
|
|
+ Pattern pattern = Pattern.compile("(\\d+):(\\d+)(?::(\\d+))?");
|
|
|
+ Matcher matcher = pattern.matcher(recordwording);
|
|
|
+ if (matcher.find()) {
|
|
|
+ int hours = 0;
|
|
|
+ int minutes;
|
|
|
+ int seconds;
|
|
|
+
|
|
|
+ // 如果有小时部分(匹配到3个组)
|
|
|
+ if (matcher.group(3) != null) {
|
|
|
+ hours = Integer.parseInt(matcher.group(1));
|
|
|
+ minutes = Integer.parseInt(matcher.group(2));
|
|
|
+ seconds = Integer.parseInt(matcher.group(3));
|
|
|
+ }
|
|
|
+ else {// 只有分钟和秒(匹配到2个组)
|
|
|
+ minutes = Integer.parseInt(matcher.group(1));
|
|
|
+ seconds = Integer.parseInt(matcher.group(2));
|
|
|
+ }
|
|
|
+ totalSeconds = hours * 3600L + minutes * 60L + seconds;
|
|
|
+ log.info("id:{}, 总通话秒数: " + totalSeconds, id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (recordType==2){
|
|
|
+ log.info("id:{}, 通话挂断", id);
|
|
|
+ }else if (recordType==3){
|
|
|
+ log.info("通话未接听");
|
|
|
+ }else {
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
+ qwUserVoiceLogService.addQuUserVoiceByIpadCallback(id,extId,recordType,totalSeconds,wxWorkMsgResp.getUuid());
|
|
|
+ }
|
|
|
|
|
|
+ break;
|
|
|
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
return map;
|
|
|
}
|
|
|
@@ -551,7 +561,8 @@ public class QwMsgController {
|
|
|
|
|
|
|
|
|
void qwUserStatus(String uid, Integer status, String msg){
|
|
|
- Long id = redisCache.getCacheObject("qrCode:uuid:"+uid);
|
|
|
+ Object idOld = redisForObject.opsForValue().get("qrCode:uuid:" + uid);
|
|
|
+ Long id = (Long) idOld;
|
|
|
QwUser qwUser = new QwUser();
|
|
|
qwUser.setId(id);
|
|
|
qwUser.setRemark(msg);
|