jenkins
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package cn.van.business.controller.jd;
|
||||
|
||||
import cn.van.business.mq.MessageProducerService;
|
||||
import cn.van.business.util.JDUtils;
|
||||
import cn.van.business.util.JDUtil;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
@@ -21,7 +21,7 @@ public class OrderController {
|
||||
|
||||
public static String TOKEN = "cc0313";
|
||||
@Resource
|
||||
private JDUtils jdUtils;
|
||||
private JDUtil jdUtils;
|
||||
@Resource
|
||||
private MessageProducerService messageProducerService;
|
||||
|
||||
|
||||
@@ -3,12 +3,14 @@ package cn.van.business.mq;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.van.business.util.WxtsUtil;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.google.common.util.concurrent.RateLimiter;
|
||||
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
|
||||
import org.apache.rocketmq.spring.core.RocketMQListener;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -24,13 +26,16 @@ import static cn.van.business.util.WXUtil.WX_BASE_URL;
|
||||
* @description:
|
||||
*/
|
||||
@Service
|
||||
@RocketMQMessageListener(topic = "wx-message", consumerGroup = "${rocketmq.consumer.group}",nameServer = "${rocketmq.name-server}")
|
||||
@RocketMQMessageListener(topic = "wx-message", consumerGroup = "${rocketmq.consumer.group}", nameServer = "${rocketmq.name-server}")
|
||||
public class MessageConsumerService implements RocketMQListener<JSONObject> {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(MessageConsumerService.class);
|
||||
|
||||
@Autowired
|
||||
private WxtsUtil wxtsUtil;
|
||||
// create a rate limiter of 1 qps
|
||||
RateLimiter rateLimiter = RateLimiter.create(0.5);
|
||||
|
||||
@Override
|
||||
public void onMessage(JSONObject jsonObject) {
|
||||
// 处理消息
|
||||
@@ -50,10 +55,12 @@ public class MessageConsumerService implements RocketMQListener<JSONObject> {
|
||||
JSONObject response = JSONObject.parseObject(responseStr);
|
||||
if (response.getInteger("code") != 200) {
|
||||
// TODO: 如果需要处理错误,您可以在这里添加逻辑
|
||||
wxtsUtil.sendNofity("消息发送失败: " + responseStr);
|
||||
throw new RuntimeException("消息发送失败: " + responseStr);
|
||||
}
|
||||
//logger.info("消息成功发送并得到响应:{}", response);
|
||||
} else {
|
||||
wxtsUtil.sendNofity("消息发送失败,没有收到响应");
|
||||
throw new RuntimeException("消息发送失败,没有收到响应");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -42,7 +42,7 @@ import static cn.van.business.util.WXUtil.super_admins;
|
||||
* @description:
|
||||
*/
|
||||
@Component
|
||||
public class JDUtils {
|
||||
public class JDUtil {
|
||||
/**
|
||||
* 密钥配置
|
||||
*/
|
||||
@@ -67,7 +67,7 @@ public class JDUtils {
|
||||
//accessToken
|
||||
private static final String ACCESS_TOKEN = "";
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(JDUtils.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(JDUtil.class);
|
||||
|
||||
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
private final StringRedisTemplate redisTemplate;
|
||||
@@ -77,7 +77,7 @@ public class JDUtils {
|
||||
|
||||
// 通过构造函数注入所有依赖项,Spring将自动注入这些依赖
|
||||
@Autowired // @Autowired 在构造函数上可以省略,如果类只有一个构造函数
|
||||
public JDUtils(StringRedisTemplate redisTemplate, OrderRowRepository orderRowRepository, WXUtil wxUtil, OrderUtil orderUtil) {
|
||||
public JDUtil(StringRedisTemplate redisTemplate, OrderRowRepository orderRowRepository, WXUtil wxUtil, OrderUtil orderUtil) {
|
||||
this.redisTemplate = redisTemplate;
|
||||
this.orderRowRepository = orderRowRepository;
|
||||
this.wxUtil = wxUtil;
|
||||
@@ -61,14 +61,14 @@ public class WxMessageConsumer {
|
||||
private final WxMessageDataForChatRepository wxMessageDataForChatRepository;
|
||||
private final WxUserRepository wxUserRepository;
|
||||
private final SettingRepository settingRepository;
|
||||
private final JDUtils jdUtils;
|
||||
private final JDUtil jdUtils;
|
||||
|
||||
@Autowired
|
||||
public WxMessageConsumer(WXUtil wxUtil, QLUtil qlUtil,
|
||||
@Lazy WxMessageDataForChatRepository wxMessageDataForChatService,
|
||||
@Lazy WxUserRepository wxUserRepository,
|
||||
@Lazy SettingRepository settingRepository,
|
||||
@Lazy JDUtils jdUtils) {
|
||||
@Lazy JDUtil jdUtils) {
|
||||
this.wxUtil = wxUtil;
|
||||
this.qlUtil = qlUtil;
|
||||
this.wxMessageDataForChatRepository = wxMessageDataForChatService;
|
||||
|
||||
39
src/main/java/cn/van/business/util/WxtsUtil.java
Normal file
39
src/main/java/cn/van/business/util/WxtsUtil.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package cn.van.business.util;
|
||||
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* @author Leo
|
||||
* @version 1.0
|
||||
* @create 2025/1/22 10:20
|
||||
* @description: 企业微信推送工具类
|
||||
*/
|
||||
public class WxtsUtil {
|
||||
private static final Logger logger = LoggerFactory.getLogger(WxtsUtil.class);
|
||||
public static final String TOKEN = "super_token_b62190c26";
|
||||
private static final String SERVER_URL = "https://wxts.van333.cn";
|
||||
|
||||
|
||||
public void sendNofity(String content) {
|
||||
try {
|
||||
String url = SERVER_URL + "/send/jd?vanToken=" + TOKEN + "&source=XZJ_UBUNTU";
|
||||
HashMap<String, Object> paramMap = new HashMap<>();
|
||||
paramMap.put("title", "JD机器人微信推送");
|
||||
content = content.replaceAll("\\n", "<br>");
|
||||
String common = "192.168.8.88 (微信机器人),发出告警信息 : ";
|
||||
content = common + content + "<br><br>";
|
||||
paramMap.put("text", content);
|
||||
String post = HttpUtil.post(url, paramMap);
|
||||
logger.info("企业微信推送结果:{}", post);
|
||||
} catch (Exception e) {
|
||||
logger.error("企业微信推送失败:{}", e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user