feat: 手机端消息跳转

This commit is contained in:
2024-09-18 15:59:58 +08:00
parent 19da42192f
commit 1480e5526c
5 changed files with 42 additions and 20 deletions
@@ -1,16 +1,15 @@
package com.jero.modules.docking.hiwork.service.impl;
import cn.hutool.core.annotation.Link;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jero.common.api.vo.ResultCommon;
import com.jero.common.exception.JeroBootException;
import com.jero.common.system.vo.LoginUser;
import com.jero.modules.docking.hiwork.entity.HiworkDingDingMsg;
import com.jero.modules.docking.hiwork.entity.HiworkSystemMsg;
import com.jero.modules.docking.hiwork.service.IHiworkMsgService;
import com.jero.modules.docking.hiwork.util.HiworkPostUtil;
import com.jero.common.api.vo.ResultCommon;
import com.jero.modules.system.entity.SysUser;
import com.jero.modules.system.service.ISysUserService;
import lombok.extern.slf4j.Slf4j;
@@ -18,6 +17,7 @@ import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.HashMap;
@@ -39,11 +39,16 @@ public class HiworkMsgServiceImpl implements IHiworkMsgService {
@Autowired
private ISysUserService sysUserService;
@Value("${hiwork.appUrl}")
private String appUrl;
private final static String TEXT = "text"; // 消息类型-文本
private final static String TITLE = "title"; // 消息类型-文本
private final static String LINK = "link"; // 消息类型-文本
private final static String MSG_TYPE = "msgtype"; // 消息类型
private final static String CONTENT = "content"; // 消息内容
private final static String MESSAGE_URL = "messageUrl"; // 消息内容
private final static String PC_SLIDE = "pc_slide"; // 消息内容
/**
* @Author: liao
@@ -74,12 +79,23 @@ public class HiworkMsgServiceImpl implements IHiworkMsgService {
// 消息体
JSONObject msgJsonObject = new JSONObject();
msgJsonObject.put(MSG_TYPE, TEXT);
JSONObject textJsonObject = new JSONObject();
textJsonObject.put(CONTENT, content);
msgJsonObject.put(TEXT, textJsonObject);
hiworkDingDingMsg.setMsg(msgJsonObject);
if (StrUtil.isBlank(messageUrl)) {
msgJsonObject.put(MSG_TYPE, TEXT);
JSONObject textJsonObject = new JSONObject();
textJsonObject.put(CONTENT, content);
msgJsonObject.put(TEXT, textJsonObject);
hiworkDingDingMsg.setMsg(msgJsonObject);
} else {
// 动态消息有手机端跳转链接
msgJsonObject.put(MSG_TYPE, LINK);
JSONObject linkJsonObject = new JSONObject();
String url = appUrl + messageUrl;
linkJsonObject.put(MESSAGE_URL, url);
linkJsonObject.put(TITLE, "【标准法规】动态消息");
linkJsonObject.put(TEXT, content);
msgJsonObject.put(LINK, linkJsonObject);
hiworkDingDingMsg.setMsg(msgJsonObject);
}
log.info("发送Hiwork钉钉消息: {}", JSONObject.toJSONString(hiworkDingDingMsg));
hiworkPostUtil.postDingDingMsg(hiworkDingDingMsg);
@@ -38,6 +38,8 @@ public class SendMessageServiceImpl implements SendMessageAPI {
private Boolean isSend;
@Value("${hiwork.hiworkUrlPrefix}")
private String hiworkUrlPrefix;
@Value("")
private String phoneUrl;
/**
* @Author: liao
@@ -63,6 +65,7 @@ public class SendMessageServiceImpl implements SendMessageAPI {
String openType = sysMessageTemplate.getOpenType();
String openPage = sysMessageTemplate.getOpenPage();
String hiworkPhoneUrl = "";
try {
// 替换模板内容
@@ -78,6 +81,9 @@ public class SendMessageServiceImpl implements SendMessageAPI {
if (null != map.get("openPage")) {
openPage = map.get("openPage");
}
if (null != map.get("hiworkPhoneUrl")) {
hiworkPhoneUrl = map.get("hiworkPhoneUrl");
}
}
List<String> typeList = Arrays.asList(sysMessageTemplate.getTemplateType().split(","));
@@ -92,6 +98,7 @@ public class SendMessageServiceImpl implements SendMessageAPI {
}
String finalOpenType = openType;
String finalOpenPage = openPage;
String finalHiworkPhoneUrl = hiworkPhoneUrl;
typeList.forEach(type -> {
log.info("消息标题:{},消息内容:{},消息类型:{}", sysMessageTemplate.getTemplateName(), sysMessageTemplate.getTemplateContent(), type);
ISendMsgHandle sendMsgHandle;
@@ -99,7 +106,7 @@ public class SendMessageServiceImpl implements SendMessageAPI {
// Hiwork钉钉消息
sendMsgHandle = new DingDingSendMsgHandle();
if (isSend) {
sendMsgHandle.SendMsg(sendMessageDTO.getToUserId(), sysMessageTemplate.getTemplateName(), sysMessageTemplate.getTemplateContent(), null, null);
sendMsgHandle.SendMsg(sendMessageDTO.getToUserId(), sysMessageTemplate.getTemplateName(), sysMessageTemplate.getTemplateContent(), null, finalHiworkPhoneUrl);
}
} else if ("6".equals(type)) {
// Hiwork系统消息