|
@@ -1,12 +1,22 @@
|
|
|
package com.fs.app.controller;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.core.redis.RedisCache;
|
|
|
import com.fs.common.utils.uuid.IdUtils;
|
|
|
import com.fs.fastGpt.service.AiHookService;
|
|
|
+import com.fs.his.domain.FsStoreOrder;
|
|
|
+import com.fs.his.service.IFsStoreOrderService;
|
|
|
+import com.fs.qw.domain.QwExternalContact;
|
|
|
import com.fs.qw.domain.QwUser;
|
|
|
+import com.fs.qw.mapper.QwExternalContactMapper;
|
|
|
import com.fs.qw.mapper.QwUserMapper;
|
|
|
+import com.fs.qw.service.IQwExternalContactService;
|
|
|
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.voice.utils.StringUtil;
|
|
|
import com.fs.wxwork.dto.*;
|
|
|
import com.fs.wxwork.service.WxWorkService;
|
|
|
import io.swagger.annotations.Api;
|
|
@@ -15,8 +25,7 @@ import org.json.JSONObject;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
@@ -37,6 +46,70 @@ public class QwMsgController {
|
|
|
WxWorkService wxWorkService;
|
|
|
@Autowired
|
|
|
IQwUserVoiceLogService qwUserVoiceLogService;
|
|
|
+ @Autowired
|
|
|
+ IFsStoreOrderService fsStoreOrderService;
|
|
|
+ @Autowired
|
|
|
+ IQwExternalContactService externalContactService;
|
|
|
+ @Autowired
|
|
|
+ QwExternalContactMapper qwExternalContactMapper;
|
|
|
+ @Autowired
|
|
|
+ SopUserLogsInfoMapper sopUserLogsInfoMapper;
|
|
|
+ @Autowired
|
|
|
+ QwSopLogsMapper qwSopLogsMapper;
|
|
|
+
|
|
|
+ @GetMapping("/sendExpressInfo/{orderId}")
|
|
|
+ public R sendExpressInfo(@PathVariable Long orderId){
|
|
|
+ FsStoreOrder order = fsStoreOrderService.selectFsStoreOrderByOrderId(orderId);
|
|
|
+ if(order != null && order.getUserId() != null){
|
|
|
+ List<QwExternalContact> qwExternalContact = externalContactService.selectQwExternalContactByFsUserId(order.getUserId());
|
|
|
+ if(qwExternalContact != null && !qwExternalContact.isEmpty()){
|
|
|
+ for (QwExternalContact externalContact : qwExternalContact) {
|
|
|
+ Long qwUserId = externalContact.getQwUserId();
|
|
|
+ if(qwUserId != null ){
|
|
|
+ QwUser qwUser = qwUserMapper.selectQwUserById(qwUserId);
|
|
|
+ if(qwUser != null && qwUser.getUid() != null && qwUser.getServerId() != null && qwUser.getServerStatus() == 1 && qwUser.getIpadStatus() == 1){
|
|
|
+ WxWorkUserId2VidDTO wxWorkUserId2VidDTO = new WxWorkUserId2VidDTO();
|
|
|
+ wxWorkUserId2VidDTO.setOpenid(Collections.singletonList(externalContact.getExternalUserId()));
|
|
|
+ wxWorkUserId2VidDTO.setUuid(qwUser.getUid());
|
|
|
+ WxWorkResponseDTO<List<WxWorkVid2UserIdRespDTO>> WxWorkVid2UserIdRespDTO = wxWorkService.UserId2Vid(wxWorkUserId2VidDTO,qwUser.getServerId());
|
|
|
+ List<WxWorkVid2UserIdRespDTO> data = WxWorkVid2UserIdRespDTO.getData();
|
|
|
+ StringBuilder sBuilder = new StringBuilder();
|
|
|
+ if(data != null && !data.isEmpty()){
|
|
|
+ Long sendId = data.get(0).getUser_id();
|
|
|
+ switch (order.getStatus())
|
|
|
+ {
|
|
|
+ case -1:
|
|
|
+ case -2:
|
|
|
+ case 1:
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ sBuilder.append("您好,您购买的").append(order.getPackageName()).append("正在准备发货,请耐心等待;\n").append("\uD83C\uDF39\uD83C\uDF39\uD83C\uDF39");
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ case 4:
|
|
|
+ case 5:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if(!"".contentEquals(sBuilder)){
|
|
|
+ //2.发送模板中的文字内容
|
|
|
+ String content = sBuilder.toString();
|
|
|
+ WxWorkSendTextMsgDTO wxWorkSendTextMsgDTO = new WxWorkSendTextMsgDTO();
|
|
|
+ wxWorkSendTextMsgDTO.setSend_userid(sendId);
|
|
|
+ wxWorkSendTextMsgDTO.setUuid(qwUser.getUid());
|
|
|
+ wxWorkSendTextMsgDTO.setContent(content);
|
|
|
+ wxWorkSendTextMsgDTO.setIsRoom(false);
|
|
|
+ wxWorkService.SendTextMsg(wxWorkSendTextMsgDTO,qwUser.getServerId());
|
|
|
+ }
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
@PostMapping("/callback/{serverId}")
|
|
|
@ResponseBody
|
|
@@ -80,7 +153,7 @@ public class QwMsgController {
|
|
|
WxWorkGetQrCodeDTO wxWorkGetQrCodeDTO = new WxWorkGetQrCodeDTO();
|
|
|
wxWorkGetQrCodeDTO.setUuid(wxWorkMsgResp.getUuid());
|
|
|
wxWorkService.LoginOut(wxWorkGetQrCodeDTO,serverId);
|
|
|
- System.out.println("调用退出登录");
|
|
|
+ log.info("调用退出登录");
|
|
|
break;
|
|
|
}
|
|
|
if (!qu.getQwUserId().equals(jsonObject.get("acctid"))){
|
|
@@ -89,7 +162,7 @@ public class QwMsgController {
|
|
|
WxWorkGetQrCodeDTO wxWorkGetQrCodeDTO = new WxWorkGetQrCodeDTO();
|
|
|
wxWorkGetQrCodeDTO.setUuid(wxWorkMsgResp.getUuid());
|
|
|
wxWorkService.LoginOut(wxWorkGetQrCodeDTO,serverId);
|
|
|
- System.out.println("调用退出登录");
|
|
|
+ log.info("调用退出登录");
|
|
|
break;
|
|
|
}
|
|
|
QwUser qwUser = new QwUser();
|
|
@@ -101,39 +174,45 @@ public class QwMsgController {
|
|
|
redisCache.setCacheObject("qrCodeUid:"+wxWorkMsgResp.getUuid(),104001,10, TimeUnit.MINUTES);
|
|
|
break;
|
|
|
case 100006:
|
|
|
- System.out.println("企业切换");
|
|
|
+
|
|
|
break;
|
|
|
case 100004:
|
|
|
System.out.println("需要验证二维码消息");
|
|
|
redisCache.setCacheObject("qrCodeUid:"+wxWorkMsgResp.getUuid(),100004,10, TimeUnit.MINUTES);
|
|
|
break;
|
|
|
case 100012:
|
|
|
- System.out.println("需要二次验证");
|
|
|
+ log.info("需要二次验证:"+wxWorkMsgResp.getJson());
|
|
|
+
|
|
|
redisCache.setCacheObject("qrCodeUid:"+wxWorkMsgResp.getUuid(),100012,10, TimeUnit.MINUTES);
|
|
|
|
|
|
break;
|
|
|
case 100005:
|
|
|
- System.out.println("手机端结束登录");
|
|
|
+
|
|
|
log.info("手机端结束登录:"+wxWorkMsgResp.getJson());
|
|
|
qwUserStatus(wxWorkMsgResp.getUuid(),0);
|
|
|
break;
|
|
|
case 100008:
|
|
|
- System.out.println("当前账号在其他设备登录");
|
|
|
- log.info("当前账号在其他设备登录:"+wxWorkMsgResp.getJson());
|
|
|
- qwUserStatus(wxWorkMsgResp.getUuid(),0);
|
|
|
+ QwUser vidUser = qwUserMapper.selectQwUserById(id);
|
|
|
+ if (vidUser.getUid().equals(wxWorkMsgResp.getUuid())){
|
|
|
+ log.info("当前账号在其他设备登录:"+wxWorkMsgResp.getJson());
|
|
|
+ qwUserStatus(wxWorkMsgResp.getUuid(),0);
|
|
|
+ }
|
|
|
+ log.info("当前账号重新登录:"+wxWorkMsgResp.getJson());
|
|
|
break;
|
|
|
case 100007:
|
|
|
- System.out.println("异常断开");
|
|
|
log.info("异常断开:"+wxWorkMsgResp.getJson());
|
|
|
qwUserStatus(wxWorkMsgResp.getUuid(),0);
|
|
|
break;
|
|
|
case 100009:
|
|
|
- System.out.println("二次验证");
|
|
|
log.info("二次验证:"+wxWorkMsgResp.getJson());
|
|
|
qwUserStatus(wxWorkMsgResp.getUuid(),0);
|
|
|
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;
|
|
@@ -155,6 +234,15 @@ public class QwMsgController {
|
|
|
ste.setUuid(wxWorkMsgResp.getUuid());
|
|
|
WxWorkResponseDTO<WxwSpeechToTextEntityRespDTO> dto = wxWorkService.SpeechToTextEntity(ste, serverId);
|
|
|
System.out.println(dto);
|
|
|
+ if(dto.getErrcode() != 0){
|
|
|
+ try {
|
|
|
+ TimeUnit.SECONDS.sleep(1); // 阻塞1秒
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ Thread.currentThread().interrupt(); // 处理中断异常
|
|
|
+ System.out.println("第一次语音转换失败");
|
|
|
+ }
|
|
|
+ dto = wxWorkService.SpeechToTextEntity(ste, serverId);
|
|
|
+ }
|
|
|
WxwSpeechToTextEntityRespDTO data = dto.getData();
|
|
|
content = data.getText();
|
|
|
System.out.println("语音消息"+content);
|
|
@@ -239,6 +327,87 @@ public class QwMsgController {
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 处理被拉黑的用户
|
|
|
+ * @param qwUserId
|
|
|
+ * @param wxWorkMessageDTO
|
|
|
+ * @param uuid
|
|
|
+ * @param status
|
|
|
+ */
|
|
|
+ private void handleSopBlockOrDel(Long qwUserId,WxWorkMessageDTO wxWorkMessageDTO,String uuid, Integer status){
|
|
|
+ QwUser user = qwUserMapper.selectQwUserById(qwUserId);
|
|
|
+ //查询接收人
|
|
|
+ if(user==null){
|
|
|
+ System.out.println("查询接收人为空");
|
|
|
+ }
|
|
|
+ if(user.getFastGptRoleId()==null){
|
|
|
+ System.out.println("未绑定角色");
|
|
|
+ }
|
|
|
+ Long serverId = user.getServerId();
|
|
|
+ System.out.println("服务器id"+serverId);
|
|
|
+ if (serverId == null) {
|
|
|
+ System.out.println("服务id为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ WxWorkVid2UserIdDTO wxWorkVid2UserIdDTO = new WxWorkVid2UserIdDTO();
|
|
|
+ wxWorkVid2UserIdDTO.setUser_id(Arrays.asList(wxWorkMessageDTO.getReceiver()));
|
|
|
+ wxWorkVid2UserIdDTO.setUuid(uuid);
|
|
|
+ //下面的方法是返回当前对象
|
|
|
+ WxWorkResponseDTO<List<WxWorkVid2UserIdRespDTO>> WxWorkVid2UserIdRespDTO = wxWorkService.Vid2UserId(wxWorkVid2UserIdDTO,serverId);
|
|
|
+ List<WxWorkVid2UserIdRespDTO> data = WxWorkVid2UserIdRespDTO.getData();
|
|
|
+ if (data==null|| data.isEmpty()){
|
|
|
+
|
|
|
+ System.out.println("未获取到extId"+wxWorkVid2UserIdDTO);
|
|
|
+ }
|
|
|
+ com.fs.wxwork.dto.WxWorkVid2UserIdRespDTO dto = data.get(0);
|
|
|
+
|
|
|
+ QwExternalContact qwExternalContacts = qwExternalContactMapper.selectQwExternalContactByExternalUserIdAndQwUserId(dto.getOpenid(), user.getCorpId(),user.getQwUserId());
|
|
|
+ if (qwExternalContacts==null){
|
|
|
+ System.out.println("没有外部联系人");
|
|
|
+ }
|
|
|
+
|
|
|
+ //处理拉黑的
|
|
|
+ String appKey = user.getAppKey();
|
|
|
+ //客户编号
|
|
|
+ String receiverOpenid = qwExternalContacts.getExternalUserId();
|
|
|
+
|
|
|
+ if (StringUtil.strIsNullOrEmpty(appKey) || StringUtil.strIsNullOrEmpty(receiverOpenid)){
|
|
|
+ log.error("删除或拉黑-处理营期失败数据不对:"+appKey+"|"+receiverOpenid);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ QwUser qwUser = qwUserMapper.selectQwUserByAppKey(appKey);
|
|
|
+ if (qwUser!=null){
|
|
|
+
|
|
|
+ //修改客户状态
|
|
|
+ QwExternalContact contact=new QwExternalContact();
|
|
|
+ contact.setStatus(status);
|
|
|
+ contact.setUserId(qwUser.getQwUserId());
|
|
|
+ contact.setCorpId(qwUser.getCorpId());
|
|
|
+ contact.setExternalUserId(receiverOpenid);
|
|
|
+ qwExternalContactMapper.updateQwExternalContactByUseridBlock(contact);
|
|
|
+
|
|
|
+
|
|
|
+ log.info("删除或拉黑-处理营期-"+qwUser.getQwUserId()+"|"+qwUser.getCorpId()+"|"+receiverOpenid);
|
|
|
+
|
|
|
+ //删除营期
|
|
|
+ sopUserLogsInfoMapper.deleteByQwUserIdAndCorpIdToContactId(qwUser.getQwUserId(),qwUser.getCorpId(),receiverOpenid);
|
|
|
+
|
|
|
+ //删除待发送记录
|
|
|
+ GetQwSopLogsByJsApiParam apiParam=new GetQwSopLogsByJsApiParam();
|
|
|
+ apiParam.setQwUserId(qwUser.getQwUserId());
|
|
|
+ apiParam.setCorpId(qwUser.getCorpId());
|
|
|
+ apiParam.setExternalUserId(receiverOpenid);
|
|
|
+ qwSopLogsMapper.deleteQwSopLogsByJsApi(apiParam);
|
|
|
+ }
|
|
|
+
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("删除或拉黑-处理营期失败:"+appKey+"|"+receiverOpenid+"|"+e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 处理图片消息
|
|
|
* @param serverId 服务器ID
|