消息初步修改

This commit is contained in:
CD
2022-10-25 14:01:49 +08:00
parent 01603d5f8a
commit 70e016fd1f
7 changed files with 240 additions and 67 deletions
@@ -0,0 +1,41 @@
package com.jero.common.constant.enums;
public enum MessageType2Enum {
SUBSCRIPTION_NOTIFICATION("Subscription Notification","订阅通知"),
SHARE_FORWARD("Share Forward","转发推送"),
REGULATION_EARLY_WARNING("Regulation Early Warning","法规预警"),
REGULATION_LIST_CONFIRMATION("Regulation List Confirmation","法规清单确认"),
REGULATION_TASK_CONFIRMATION("Regulation Task Confirmation","法规任务确认"),
DESIGN_COMPLIANCE_CONFIRMATION("Design Compliance Confirmation","设计符合性确认"),
PRE_HOMO_CONFIRMATION("Pre-Homo Confirmation","Pre-Homo确认"),
VALIDATION_COMPLIANCE_CONFIRMATION("Validation Compliance Confirmation","验证符合性确认"),
REGULATION_OPINION_COLLECTION("Regulation Opinion Collection","法规意见收集"),
REGULATION_TECHNICAL_ASSESSMENT("Regulation Technical Assessment","法规技术评估"),
HOMO_PARAMETER_COLLECTION("Homo Parameter Collection","认证参数收集");
String en;
String cn;
MessageType2Enum(String en, String cn) {
this.en = en;
this.cn = cn;
}
public String getEn() {
return en;
}
public void setEn(String en) {
this.en = en;
}
public String getCn() {
return cn;
}
public void setCn(String cn) {
this.cn = cn;
}
}
@@ -0,0 +1,32 @@
package com.jero.common.constant.enums;
public enum MsgColorEnum {
GREEN("其他","green"),
RED("任务被拒绝","red"),
YELLOW("任务预期","yellow");
String label;
String value;
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
MsgColorEnum(String label, String value) {
this.label = label;
this.value = value;
}
}
@@ -147,7 +147,7 @@
select tmp_tb.* from(
select
plb.id as project_id,
concat(pni.project_name,'-',pyni.year_name,' ',target_market) as project_name
concat(pni.project_name,'-',pyni.year_name,'-',target_market,'-',project_version) as project_name
from project_library_base plb
left join project_name_info as pni on plb.project_name_id = pni.id
left join project_year_name_info as pyni on plb.year_name_id = pyni.id
@@ -11,10 +11,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.jero.common.constant.CommonConstant;
import com.jero.common.constant.WebsocketConst;
import com.jero.common.constant.enums.CutEnum;
import com.jero.common.constant.enums.MessageTypeEnum;
import com.jero.common.constant.enums.ModuleEnum;
import com.jero.common.constant.enums.YesOrNoEnum;
import com.jero.common.constant.enums.*;
import com.jero.common.exception.JeroBootException;
import com.jero.common.system.query.QueryGenerator;
import com.jero.common.system.vo.LoginUser;
@@ -40,6 +37,7 @@ import com.jero.modules.cert.template.enums.ParamsIsMustEnum;
import com.jero.modules.cert.template.service.ICertCategoryParamsInfoPublishEOService;
import com.jero.modules.cert.template.service.IParamsInfoPublishEOService;
import com.jero.modules.feishu.service.IFeishuService;
import com.jero.modules.feishu.vo.FeishuMsg2Vo;
import com.jero.modules.feishu.vo.FeishuMsgVo;
import com.jero.modules.message.websocket.WebSocket;
import com.jero.modules.ocr.service.WebSocketServer;
@@ -1512,7 +1510,7 @@ public class ParamsCollectManifestEOServiceImpl extends ServiceImpl<ParamsCollec
List<ParamsCollectManifestEO> paramsCollectManifestEOList = listByIds(Arrays.asList(paramsCollectManifestIdStr));
paramsCollectManifestEOList = paramsCollectManifestEOList.stream().sorted(Comparator.comparing(ParamsCollectManifestBaseEO::getNioNumber)).collect(Collectors.toList()); // 按NIO编号升序
for (ParamsCollectManifestEO paramsCollectManifestEO : paramsCollectManifestEOList) {
for (ParamsCollectManifestEO paramsCollectManifestEO : paramsCollectManifestEOList) {
// 判断参数项状态
if (CollectManifestStateEnum.WAIT_COLLECT.getValue().equals(paramsCollectManifestEO.getState())
|| CollectManifestStateEnum.SDT_BACK.getValue().equals(paramsCollectManifestEO.getState())
@@ -1543,19 +1541,19 @@ public class ParamsCollectManifestEOServiceImpl extends ServiceImpl<ParamsCollec
}
boolean isSuccess = updateBatchById(updateEOList);
if (isSuccess) {
// 消息内容
List<ParamsCollectManifestEO> afterUpdateEOList = listByIds(updateEOIdList);
List<String> sdtList = afterUpdateEOList.stream()
.map(ParamsCollectManifestEO::getSdt)
.distinct()
.collect(Collectors.toList());
if (CollectionUtil.isEmpty(sdtList)) {
throw new JeroBootException("没有可下发的工程接口人!");
}
for (String sdt : sdtList) {
if (isSuccess) {
// 消息内容
List<ParamsCollectManifestEO> afterUpdateEOList = listByIds(updateEOIdList);
List<String> sdtList = afterUpdateEOList.stream()
.map(ParamsCollectManifestEO::getSdt)
.distinct()
.collect(Collectors.toList());
if (CollectionUtil.isEmpty(sdtList)) {
throw new JeroBootException("没有可下发的工程接口人!");
}
for (String sdt : sdtList) {
StringBuilder connectBuilder = new StringBuilder();
/* StringBuilder connectBuilder = new StringBuilder();
connectBuilder.append("You are required to fill in ");
for (int i = 0; i < afterUpdateEOList.size(); i++) {
ParamsCollectManifestEO paramsCollectManifestEO = afterUpdateEOList.get(i);
@@ -1563,19 +1561,19 @@ public class ParamsCollectManifestEOServiceImpl extends ServiceImpl<ParamsCollec
connectBuilder.append(paramsCollectManifestEO.getNioNumber()).append("-").append(paramsCollectManifestEO.getParamsName()).append(",");
}
}
String content = connectBuilder.substring(0, connectBuilder.toString().length() - 1) + " and other parameter items, please enter the link to handle it.";
String content = connectBuilder.substring(0, connectBuilder.toString().length() - 1) + " and other parameter items, please enter the link to handle it.";*/
SysUser sysUser = sysUserService.getUserByName(sdt);
String[] thirdIds = new String[1];
thirdIds[0] = sysUser.getThirdId();
String urlParamsStr = parseUrlParams(paramsManifestEO);
String hrefFeishu = backUrl + "/ParameterItemCollection" + urlParamsStr;
String href = "<a href='/ParameterItemCollection" + urlParamsStr + "'" + " target='_blank'>the link</a>,";
String contentInfo = connectBuilder.substring(0, connectBuilder.toString().length() - 1) + " and other parameter items, please enter " + href + " and fill in the relevant information.";
String msgTitle = projectInfo.getProjectName() + ": You have a homo parameter task to complete";
SysUser sysUser = sysUserService.getUserByName(sdt);
String[] thirdIds = new String[1];
thirdIds[0] = sysUser.getThirdId();
String urlParamsStr = parseUrlParams(paramsManifestEO);
String hrefFeishu = backUrl + "/ParameterItemCollection" + urlParamsStr;
//String href = "<a href='/ParameterItemCollection" + urlParamsStr + "'" + " target='_blank'>the link</a>,";
//String contentInfo = connectBuilder.substring(0, connectBuilder.toString().length() - 1) + " and other parameter items, please enter " + href + " and fill in the relevant information.";
//String msgTitle = projectInfo.getProjectName() + ": You have a homo parameter task to complete";
// 发送系统消息
SysAnnouncement sysAnnouncement = new SysAnnouncement();
// 发送系统消息
/* SysAnnouncement sysAnnouncement = new SysAnnouncement();
sysAnnouncement.setDelFlag("0");
sysAnnouncement.setSendStatus("0");
sysAnnouncement.setSendTime(new Date());
@@ -1592,24 +1590,12 @@ public class ParamsCollectManifestEOServiceImpl extends ServiceImpl<ParamsCollec
obj.put(WebsocketConst.MSG_CMD, WebsocketConst.CMD_TOPIC);
obj.put(WebsocketConst.MSG_ID, paramsManifestId);
obj.put(WebsocketConst.MSG_TXT, contentInfo);
webSocket.sendMessage(obj.toJSONString());
webSocket.sendMessage(obj.toJSONString());*/
// 发送飞书消息
try {
FeishuMsgVo feishuMsgVo = new FeishuMsgVo();
feishuMsgVo.setTitle(MessageTypeEnum.HOMO_TASK.getName());
feishuMsgVo.setContent(content);
feishuMsgVo.setUrl(hrefFeishu);
feishuMsgVo.setTaskType(MessageTypeEnum.HOMO_TASK.getName());
feishuMsgVo.setProject(projectInfo.getProjectName()); // 车型-年款 区域
feishuMsgVo.setInitiator(currentUser.getUsername());
feishuMsgVo.setDueDate(sdf.format(deadline)); // 最早时间
feishuService.sendCardMsg(thirdIds, feishuMsgVo);
} catch (IOException e) {
log.error("飞书消息推送失败");
}
}
}
// 发送飞书消息
sendFeishuMsg(deadline, currentUser, projectInfo, sdf, thirdIds, hrefFeishu);
}
}
return getMsgOfIssueCollection(msgMapList, cut, "1");
}
@@ -1685,7 +1671,7 @@ public class ParamsCollectManifestEOServiceImpl extends ServiceImpl<ParamsCollec
}
for (String sdt : sdtList) {
StringBuilder connectBuilder = new StringBuilder();
/*StringBuilder connectBuilder = new StringBuilder();
connectBuilder.append("You are required to fill in ");
for (int i = 0; i < afterUpdateEOList.size(); i++) {
ParamsCollectManifestEO paramsCollectManifestEO = afterUpdateEOList.get(i);
@@ -1693,8 +1679,7 @@ public class ParamsCollectManifestEOServiceImpl extends ServiceImpl<ParamsCollec
connectBuilder.append(paramsCollectManifestEO.getNioNumber()).append("-").append(paramsCollectManifestEO.getParamsName()).append(",");
}
}
String content = connectBuilder.substring(0, connectBuilder.toString().length() - 1) + " and other parameter items, please enter the link to handle it.";
String content = connectBuilder.substring(0, connectBuilder.toString().length() - 1) + " and other parameter items, please enter the link to handle it.";*/
SysUser sysUser = sysUserService.getUserByName(sdt);
if(sysUser == null){
continue;
@@ -1704,12 +1689,12 @@ public class ParamsCollectManifestEOServiceImpl extends ServiceImpl<ParamsCollec
thirdIds[0] = sysUser.getThirdId();
String urlParamsStr = parseUrlParams(paramsManifestEO);
String hrefFeishu = backUrl + "/ParameterItemCollection" + urlParamsStr;
String href = "<a href='/ParameterItemCollection" + urlParamsStr + "'" + " target='_blank'>the link</a>,";
String contentInfo = connectBuilder.substring(0, connectBuilder.toString().length() - 1) + " and other parameter items, please enter " + href + " and fill in the relevant information.";
String msgTitle = projectInfo.getProjectName() + ": You have a homo parameter task to complete";
//String href = "<a href='/ParameterItemCollection" + urlParamsStr + "'" + " target='_blank'>the link</a>,";
//String contentInfo = connectBuilder.substring(0, connectBuilder.toString().length() - 1) + " and other parameter items, please enter " + href + " and fill in the relevant information.";
//String msgTitle = projectInfo.getProjectName() + ": You have a homo parameter task to complete";
// 发送系统消息
SysAnnouncement sysAnnouncement = new SysAnnouncement();
/*SysAnnouncement sysAnnouncement = new SysAnnouncement();
sysAnnouncement.setDelFlag("0");
sysAnnouncement.setSendStatus("0");
sysAnnouncement.setSendTime(new Date());
@@ -1726,28 +1711,36 @@ public class ParamsCollectManifestEOServiceImpl extends ServiceImpl<ParamsCollec
obj.put(WebsocketConst.MSG_CMD, WebsocketConst.CMD_TOPIC);
obj.put(WebsocketConst.MSG_ID, paramsManifestId);
obj.put(WebsocketConst.MSG_TXT, contentInfo);
webSocket.sendMessage(obj.toJSONString());
webSocket.sendMessage(obj.toJSONString());*/
// 发送飞书消息
try {
FeishuMsgVo feishuMsgVo = new FeishuMsgVo();
feishuMsgVo.setTitle(MessageTypeEnum.HOMO_TASK.getName());
feishuMsgVo.setContent(content);
feishuMsgVo.setUrl(hrefFeishu);
feishuMsgVo.setTaskType(MessageTypeEnum.HOMO_TASK.getName());
feishuMsgVo.setProject(projectInfo.getProjectName()); // 车型-年款 区域
feishuMsgVo.setInitiator(currentUser.getUsername());
feishuMsgVo.setDueDate(sdf.format(deadline));
feishuService.sendCardMsg(thirdIds, feishuMsgVo);
} catch (IOException e) {
log.error("飞书消息推送失败");
}
sendFeishuMsg(deadline, currentUser, projectInfo, sdf, thirdIds, hrefFeishu);
}
}
return getMsgOfIssueCollection(msgMapList, cut, "1");
}
private void sendFeishuMsg(Date deadline, LoginUser currentUser, ParamsManifestVO projectInfo, SimpleDateFormat sdf, String[] thirdIds, String hrefFeishu) {
try {
FeishuMsg2Vo feishuMsgVo = new FeishuMsg2Vo();
feishuMsgVo.setTitle(MessageType2Enum.HOMO_PARAMETER_COLLECTION.getCn() + "/" + MessageType2Enum.HOMO_PARAMETER_COLLECTION.getEn());
feishuMsgVo.setCnContentUpper("您好,请及时分配参数填写人");
feishuMsgVo.setCnContentLower("项目: " + projectInfo.getProjectName() +
"\n发起人: " + currentUser.getUsername() +
"\n截止时间: " + sdf.format(deadline));
feishuMsgVo.setEnContentUpper("Hello! Please assign the task of filling in Homo Parameter in a timely manner");
feishuMsgVo.setEnContentLower("Project: " + projectInfo.getProjectName() +
"\nInitiator: " + currentUser.getUsername() +
"\nDue Date: " + sdf.format(deadline));
feishuMsgVo.setUrl(hrefFeishu);
feishuMsgVo.setColor(MsgColorEnum.GREEN.getValue()); // 颜色
feishuService.sendCard(thirdIds, feishuMsgVo);
} catch (IOException e) {
log.error("飞书消息推送失败");
}
}
private List<String> getMsgOfIssueCollection(List<Map<String, String>> msgMapList, String cut, String operation) {
List<String> msgList = new ArrayList<>();
Map<String,String> collectManifestStateEnumMap = CollectManifestStateEnum.toMap(cut);
@@ -1,6 +1,7 @@
package com.jero.modules.feishu.service;
import com.alibaba.fastjson.JSONObject;
import com.jero.modules.feishu.vo.FeishuMsg2Vo;
import com.jero.modules.feishu.vo.FeishuMsgVo;
import java.io.IOException;
@@ -62,4 +63,7 @@ public interface IFeishuService {
* @param split
*/
void sendKnowledgeBaseTypeChargePersonCard(String[] split);
void sendCard(String[] thirdIds, FeishuMsg2Vo feishuMsgVo) throws IOException;
}
@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jero.modules.feishu.service.IFeishuService;
import com.jero.modules.feishu.vo.FeishuMsg2Vo;
import com.jero.modules.feishu.vo.FeishuMsgVo;
import com.jero.modules.problemKnowledgeBase.entity.ProblemKnowledgeBaseClassifyEO;
import com.jero.modules.problemKnowledgeBase.entity.ProblemKnowledgeBaseEO;
@@ -674,4 +675,86 @@ public class FeishuServiceImpl implements IFeishuService {
}
}
/**
* 发送消息
* @param thirdIds
* @param feishuMsgVo
*/
@Override
public void sendCard(String[] thirdIds, FeishuMsg2Vo feishuMsgVo) throws IOException {
String token = getTenantAccessToken();
// 设置请求头
Map<String, String> headerMap = new HashMap<>();
headerMap.put("Authorization", "Bearer " + token);
headerMap.put("Content-Type", "application/json; charset=utf-8");
String sendJson = "{\n" +
" \"config\": {\n" +
" \"wide_screen_mode\": true\n" +
" },\n" +
" \"elements\": [\n" +
" {\n" +
" \"tag\": \"markdown\",\n" +
" \"content\": \"" + feishuMsgVo.getCnContentUpper() + "\"\n" +
" },\n" +
" {\n" +
" \"tag\": \"markdown\",\n" +
" \"content\": \"" + feishuMsgVo.getCnContentLower() + "\"\n" +
" },\n" +
" {\n" +
" \"tag\": \"hr\"\n" +
" },\n" +
" {\n" +
" \"tag\": \"markdown\",\n" +
" \"content\": \"" + feishuMsgVo.getEnContentUpper() + "\"\n" +
" },\n" +
" {\n" +
" \"tag\": \"markdown\",\n" +
" \"content\": \"" + feishuMsgVo.getEnContentLower() + "\"\n" +
" },\n" +
" {\n" +
" \"actions\": [\n" +
" {\n" +
" \"tag\": \"button\",\n" +
" \"text\": {\n" +
" \"content\": \"View\",\n" +
" \"tag\": \"plain_text\"\n" +
" },\n" +
" \"type\": \"primary\",\n" +
" \"url\": \"" + feishuMsgVo.getUrl() + "\"\n" +
" }\n" +
" ],\n" +
" \"tag\": \"action\"\n" +
" }\n" +
" ],\n" +
" \"header\": {\n" +
" \"template\": \"" + feishuMsgVo.getColor() + "\",\n" +
" \"title\": {\n" +
" \"content\": \"" + feishuMsgVo.getTitle() + "\",\n" +
" \"tag\": \"plain_text\"\n" +
" }\n" +
" }\n" +
"}";
JSONObject jsonObject = JSONObject.parseObject(sendJson.toString());
// 设置请求参数
JSONObject paramsMap = new JSONObject();
paramsMap.put("user_ids", thirdIds);
paramsMap.put("msg_type", "interactive");
paramsMap.put("card", jsonObject);
// 发送请求给飞书
String response = HttpRequestUtil.getResponseOfPOST(batchSendMessageUrl, headerMap, paramsMap.toJSONString());
// 获取返回结果
JSONObject tokenJson = JSONObject.parseObject(response);
if (!tokenJson.get("code").toString().equals("0")) {
log.error("请求出现异常:" + tokenJson.get("msg") + " " + tokenJson);
}
}
}
@@ -0,0 +1,20 @@
package com.jero.modules.feishu.vo;
import lombok.Data;
@Data
public class FeishuMsg2Vo {
private String title; //标题
private String color; //颜色
private String enContentUpper; //英文内容上部
private String enContentLower; //英文内容下部
private String cnContentUpper; //中文内容上部
private String cnContentLower; //中文内容下部
private String url; //回调的网址
}