|
@@ -2,7 +2,6 @@ package com.fs.qw.service.impl;
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.http.HttpRequest;
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
@@ -13,10 +12,8 @@ import com.fs.his.config.FsSysConfig;
|
|
|
import com.fs.his.utils.ConfigUtil;
|
|
|
import com.fs.qw.Bean.MsgBean;
|
|
|
import com.fs.qw.domain.*;
|
|
|
-import com.fs.qw.mapper.QwExternalContactMapper;
|
|
|
-import com.fs.qw.mapper.QwMsgMapper;
|
|
|
-import com.fs.qw.mapper.QwSessionMapper;
|
|
|
-import com.fs.qw.mapper.QwUserMapper;
|
|
|
+import com.fs.qw.enums.MsgType;
|
|
|
+import com.fs.qw.mapper.*;
|
|
|
import com.fs.qw.param.QwMsgSendParam;
|
|
|
import com.fs.qw.param.QwSessionParam;
|
|
|
import com.fs.qw.service.IQwMsgService;
|
|
@@ -50,6 +47,8 @@ public class QwMsgServiceImpl extends ServiceImpl<QwMsgMapper, QwMsg> implements
|
|
|
private QwExternalContactMapper qwExternalContactMapper;
|
|
|
@Autowired
|
|
|
private QwUserMapper qwUserMapper;
|
|
|
+ @Autowired
|
|
|
+ private QwCompanyMapper qwCompanyMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private ConfigUtil configUtil;
|
|
@@ -296,8 +295,9 @@ public class QwMsgServiceImpl extends ServiceImpl<QwMsgMapper, QwMsg> implements
|
|
|
long sendUserId = listWxWorkResponseDTO.getData().get(0).getUser_id();
|
|
|
String msgJson;
|
|
|
|
|
|
+ MsgType msgType = MsgType.getMsgType(param.getMsgType());
|
|
|
// 发送消息 文本
|
|
|
- if (param.getMsgType() == 1) {
|
|
|
+ if (MsgType.TEXT == msgType) {
|
|
|
WxWorkSendTextMsgDTO textMsgDTO = new WxWorkSendTextMsgDTO();
|
|
|
textMsgDTO.setUuid(uuid);
|
|
|
textMsgDTO.setSend_userid(sendUserId);
|
|
@@ -312,7 +312,7 @@ public class QwMsgServiceImpl extends ServiceImpl<QwMsgMapper, QwMsg> implements
|
|
|
}
|
|
|
|
|
|
// 图片
|
|
|
- else if (param.getMsgType() == 2) {
|
|
|
+ else if (MsgType.IMAGE == msgType) {
|
|
|
WxCdnUploadImgLinkDTO linkDTO = new WxCdnUploadImgLinkDTO();
|
|
|
linkDTO.setUuid(uuid);
|
|
|
linkDTO.setUrl(param.getContent());
|
|
@@ -338,41 +338,51 @@ public class QwMsgServiceImpl extends ServiceImpl<QwMsgMapper, QwMsg> implements
|
|
|
msgJson = JSONObject.toJSONString(imgMsgDTO);
|
|
|
}
|
|
|
// 小程序
|
|
|
- else if (param.getMsgType() == 5) {
|
|
|
- JSONObject json = JSON.parseObject(param.getContent());
|
|
|
- String appid = json.getString("appid");
|
|
|
- String page = json.getString("pagepath");
|
|
|
- String title = json.getString("title");
|
|
|
- String thumbnail = json.getString("thumbnail");
|
|
|
-
|
|
|
- // 上传cdn
|
|
|
- WxCdnUploadImgLinkDTO linkDTO = new WxCdnUploadImgLinkDTO();
|
|
|
- linkDTO.setUuid(uuid);
|
|
|
- linkDTO.setUrl(thumbnail);
|
|
|
- WxWorkResponseDTO<WxCdnUploadImgLinkResp> imgLinkResp = wxWorkService.cdnUploadImgLink(linkDTO, serverId);
|
|
|
- if (imgLinkResp.getErrcode() != 0) {
|
|
|
- return R.error(imgLinkResp.getErrmsg());
|
|
|
+ else if (MsgType.MINI_PROGRAM == msgType) {
|
|
|
+ QwCompany qwCompany = qwCompanyMapper.selectQwCompanyByCorpId(qwUser.getCorpId());
|
|
|
+ if (Objects.isNull(qwCompany)) {
|
|
|
+ return R.error("企微主体不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ String miniAppParam = qwCompany.getMiniAppParam();
|
|
|
+ if (StringUtils.isBlank(miniAppParam)) {
|
|
|
+ return R.error("配置信息不存在");
|
|
|
}
|
|
|
- WxCdnUploadImgLinkResp data = imgLinkResp.getData();
|
|
|
+
|
|
|
+ String pagepath = param.getContent();
|
|
|
+ JSONObject paramJson = JSONObject.parseObject(miniAppParam);
|
|
|
|
|
|
// 发送小程序消息
|
|
|
WxWorkSendAppMsgDTO appMsgDTO = new WxWorkSendAppMsgDTO();
|
|
|
appMsgDTO.setUuid(uuid);
|
|
|
- appMsgDTO.setSendUserid(sendUserId);
|
|
|
- appMsgDTO.setTitle(title);
|
|
|
- appMsgDTO.setPagepath(page);
|
|
|
- appMsgDTO.setAppid(appid);
|
|
|
- appMsgDTO.setCdnkey(data.getCdn_key());
|
|
|
- appMsgDTO.setMd5(data.getThumb_file_md5());
|
|
|
- appMsgDTO.setAeskey(data.getAes_key());
|
|
|
- appMsgDTO.setFileSize(data.getThumb_file_size());
|
|
|
+ appMsgDTO.setSend_userid(sendUserId);
|
|
|
+ appMsgDTO.setDesc(paramJson.getString("title"));
|
|
|
+ appMsgDTO.setTitle(paramJson.getString("appName"));
|
|
|
+ appMsgDTO.setWeappIconUrl(paramJson.getString("weappIconUrl"));
|
|
|
+ appMsgDTO.setPagepath(pagepath);
|
|
|
+ appMsgDTO.setUsername(paramJson.getString("username"));
|
|
|
+ appMsgDTO.setAppid(paramJson.getString("appid"));
|
|
|
+ appMsgDTO.setCdnkey(paramJson.getString("cdnkey"));
|
|
|
+ appMsgDTO.setMd5(paramJson.getString("md5"));
|
|
|
+ appMsgDTO.setAeskey(paramJson.getString("aeskey"));
|
|
|
+ appMsgDTO.setFileSize(paramJson.getInteger("fileSize"));
|
|
|
appMsgDTO.setIsRoom(false);
|
|
|
WxWorkResponseDTO<WxWorkSendAppMsgRespDTO> appMsgResp = wxWorkService.SendAppMsg(appMsgDTO, serverId);
|
|
|
if (appMsgResp.getErrcode() != 0) {
|
|
|
return R.error(appMsgResp.getErrmsg());
|
|
|
}
|
|
|
|
|
|
- msgJson = param.getContent();
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
+ json.put("appid", paramJson.getString("appid"));
|
|
|
+ json.put("appName", paramJson.getString("appName"));
|
|
|
+ json.put("weappIconUrl", paramJson.getString("weappIconUrl"));
|
|
|
+ json.put("desc", paramJson.getString("desc"));
|
|
|
+ json.put("pagepath", pagepath);
|
|
|
+ json.put("title", paramJson.getString("title"));
|
|
|
+ json.put("thumbnail", paramJson.getString("thumbnail"));
|
|
|
+
|
|
|
+ msgJson = json.toJSONString();
|
|
|
+ param.setContent(msgJson);
|
|
|
} else {
|
|
|
return R.error("暂不支持的消息类型");
|
|
|
}
|
|
@@ -400,16 +410,7 @@ public class QwMsgServiceImpl extends ServiceImpl<QwMsgMapper, QwMsg> implements
|
|
|
qwFromUser.setId(Long.parseLong(qwMsg.getQwUserId()));
|
|
|
qwFromUser.setDisplayName(qwUser.getQwUserName());
|
|
|
qwFromUser.setAvatar("https://cos.his.cdwjyyh.com/fs/20241231/22a765a96da247d1b83ea94fef438a41.png");
|
|
|
-
|
|
|
- String type = "text";
|
|
|
- if (param.getMsgType() == 2) {
|
|
|
- type = "image";
|
|
|
- } else if (param.getMsgType() == 3) {
|
|
|
- type = "emotionDynamic";
|
|
|
- } else if (param.getMsgType() == 5) {
|
|
|
- type = "miniprogram";
|
|
|
- }
|
|
|
- listVO.setType(type);
|
|
|
+ listVO.setType(msgType.getValue());
|
|
|
listVO.setStatus("succeed");
|
|
|
listVO.setFromUser(qwFromUser);
|
|
|
listVO.setSendTime(qwMsg.getCreateTime().getTime());
|
|
@@ -465,6 +466,7 @@ public class QwMsgServiceImpl extends ServiceImpl<QwMsgMapper, QwMsg> implements
|
|
|
for (QwSession qwSession : qwSessions) {
|
|
|
QwContactListVO listVO = new QwContactListVO();
|
|
|
listVO.setId(userId);
|
|
|
+ listVO.setExtId(qwSession.getQwExtId());
|
|
|
listVO.setAvatar(qwSession.getAvatar());
|
|
|
listVO.setConversationId(qwSession.getSessionId().toString());
|
|
|
listVO.setDisplayName(qwSession.getNickName());
|
|
@@ -522,14 +524,9 @@ public class QwMsgServiceImpl extends ServiceImpl<QwMsgMapper, QwMsg> implements
|
|
|
for (QwMsg record : list) {
|
|
|
QwMessageListVO listVO = new QwMessageListVO();
|
|
|
String type = "text";
|
|
|
- if (record.getMsgType() == 2) {
|
|
|
- type = "image";
|
|
|
- } else if (record.getMsgType() == 3) {
|
|
|
- type = "emotionDynamic";
|
|
|
- } else if (record.getMsgType() == 4) {
|
|
|
- type = "voice";
|
|
|
- } else if (record.getMsgType() == 5) {
|
|
|
- type = "miniprogram";
|
|
|
+ MsgType msgType = MsgType.getMsgType(record.getMsgType());
|
|
|
+ if (Objects.nonNull(record.getMsgType())) {
|
|
|
+ type = msgType.getValue();
|
|
|
}
|
|
|
listVO.setType(type);
|
|
|
listVO.setStatus("succeed");
|