lvzhiqiang 2 yıl önce
ebeveyn
işleme
8742b19ddf

+ 0 - 1
src/main/java/top/lvzhiqiang/config/InitRunner.java

@@ -36,7 +36,6 @@ public class InitRunner implements ApplicationRunner {
 
     @Override
     public void run(ApplicationArguments args) {
-
         if (!"dev".equals(env)) {
             coinService.monitorJob();
         }

+ 4 - 4
src/main/java/top/lvzhiqiang/config/WebLogAspect.java

@@ -28,15 +28,15 @@ public class WebLogAspect {
     @Before("webLog()")
     public void doBefore(JoinPoint joinPoint) throws Throwable {
         // 接收到请求,记录请求内容
-        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
-        HttpServletRequest request = attributes.getRequest();
+        /*ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
+        HttpServletRequest request = attributes.getRequest();*/
         // 记录下请求内容
-        log.debug("REQUEST : URL={},HTTP_METHOD={},IP={}", request.getRequestURL().toString(), request.getMethod(), request.getRemoteAddr());
+        /*log.debug("REQUEST : URL={},HTTP_METHOD={},IP={}", request.getRequestURL().toString(), request.getMethod(), request.getRemoteAddr());
         Enumeration<String> enu = request.getParameterNames();
         while (enu.hasMoreElements()) {
             String name = enu.nextElement();
             log.debug("name:{},value:{}", name, request.getParameter(name));
-        }
+        }*/
     }
 
     @AfterReturning(returning = "ret", pointcut = "webLog()")

+ 110 - 0
src/main/java/top/lvzhiqiang/config/WorkWeixinAlarmConfigEnum.java

@@ -0,0 +1,110 @@
+package top.lvzhiqiang.config;
+
+import top.lvzhiqiang.service.impl.CoinServiceImpl;
+
+/**
+ * xxl-job告警企业微信配置枚举类
+ *
+ * @author ziyan.li
+ * @since 14:40 2022/12/29
+ */
+public enum WorkWeixinAlarmConfigEnum {
+
+    /**
+     * 任务告警方式
+     */
+    JOB_ALARM_MODE(CoinServiceImpl.JOB_ALARM_MODE_APP_TEXT_CARD),
+
+    /**
+     * 文本卡片标题
+     */
+    TEXT_CARD_MESSAGE_TITLE("${jobconf_monitor_detail}"),
+
+    /**
+     * 文本卡片消息内容
+     */
+    TEXT_CARD_MESSAGE_CONTENT(
+            "<div class=\"gray\">${jobconf_trigger_admin_adress}:${adminAddress}</div>" +
+                    "<div class=\"gray\">${joblog_field_triggerTime}:${jobLogTriggerTime?string('yyyy-MM-dd HH:mm:ss')}</div>" +
+                    "<div>${jobinfo_field_id}:${jobInfoId}</div>" +
+                    "<div>${jobinfo_field_jobdesc}:${jobInfoDesc}</div>" +
+                    "<div>${jobinfo_field_jobgroup}:${jobGroupTitle}</div>" +
+                    "<div>${joblog_field_executorAddress}:${executorAddress}</div>" +
+                    "<div class=\"highlight\">${jobconf_monitor_alarm_title}:${jobconf_monitor_alarm_type}</div>" +
+                    "<div class=\"gray\">LogId=${jobLogId},HandleCode=${jobLogHandleCode}</div>"
+    ),
+
+    /**
+     * 文本卡片详情地址-任务日志
+     */
+    TEXT_CARD_DETAIL_LOG_URL("https://fk.riskraider.com/job/joblog/logDetailPage?id=${jobLogId}"),
+
+    /**
+     * 文本卡片详情按钮文本
+     */
+    TEXT_CARD_DETAIL_BTN_TXT("日志详情"),
+
+    /**
+     * 所有任务告警时都包含的userid
+     */
+    ALWAYS_INCLUDED_USER_ID(""),
+
+    /**
+     * 所有任务告警时都包含的partyId
+     */
+    ALWAYS_INCLUDED_PARTY_ID(""),
+
+    /**
+     * 所有任务告警时都包含的tagId
+     */
+    ALWAYS_INCLUDED_TAG_ID(""),
+
+    /**
+     * 文本消息内容
+     */
+    TEXT_MESSAGE_CONTENT(
+            "${jobconf_trigger_admin_adress}:${adminAddress}\n" +
+                    "${joblog_field_triggerTime}:${jobLogTriggerTime?string('yyyy-MM-dd HH:mm:ss')}\n" +
+                    "${jobinfo_field_id}:${jobInfoId}\n" +
+                    "${jobinfo_field_jobdesc}:${jobInfoDesc}\n" +
+                    "${jobinfo_field_jobgroup}:${jobGroupTitle}\n" +
+                    "${joblog_field_executorAddress}:${executorAddress}\n" +
+                    "${jobconf_monitor_alarm_title}:${jobconf_monitor_alarm_type}\n" +
+                    "LogId=${jobLogId},HandleCode=${jobLogHandleCode}"
+    ),
+
+    /**
+     * 群聊机器人webhook协议的发送地址
+     */
+    CHAT_BOT_WEBHOOK_SEND_URL("https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=a1481375-1130-4144-b57c-ead75826b8e2"),
+
+    ;
+
+    /**
+     * 默认值,当表中未配置时使用
+     */
+    private final String defaultValue;
+
+    public String getDefaultValue() {
+        return defaultValue;
+    }
+
+    WorkWeixinAlarmConfigEnum(String defaultValue) {
+        this.defaultValue = defaultValue;
+    }
+
+    /* 构建初始化SQL */
+    private String buildSql() {
+        return String.format(
+                "insert into xxl_job.xxl_job_alarm_work_weixin_config(code_key, code_desc, code_value, create_time)" +
+                        " values('%s', '', '%s', current_timestamp);",
+                name(), getDefaultValue()
+        );
+    }
+
+    public static void main(String[] args) {
+        for (WorkWeixinAlarmConfigEnum configEnum : values()) {
+            System.out.println(configEnum.buildSql());
+        }
+    }
+}

+ 51 - 0
src/main/java/top/lvzhiqiang/config/WorkWeixinPropertyEnum.java

@@ -0,0 +1,51 @@
+package top.lvzhiqiang.config;
+
+import java.util.function.Function;
+
+/**
+ * 工作微信配置项枚举类
+ *
+ * @author liziyan
+ * @since 09:52 2023/4/25
+ */
+public enum WorkWeixinPropertyEnum {
+    ENABLED("enabled", "是否启用企业微信告警", WorkWeixinProperties::isEnabled),
+    CORP_ID("corp-id", "企业ID", WorkWeixinProperties::getCorpId),
+    AGENT_ID("agent-id", "应用ID", WorkWeixinProperties::getAgentId),
+    SECRET("secret", "应用密钥", WorkWeixinProperties::getSecret),
+
+    ;
+
+    /**
+     * 键名称
+     */
+    private final String keyName;
+
+    /**
+     * 键描述
+     */
+    private final String keyDesc;
+
+    /**
+     * 获取配置项的方法
+     */
+    private final Function<WorkWeixinProperties, Object> function;
+
+    public String getKeyName() {
+        return keyName;
+    }
+
+    public String getKeyDesc() {
+        return keyDesc;
+    }
+
+    public Function<WorkWeixinProperties, Object> getFunction() {
+        return function;
+    }
+
+    WorkWeixinPropertyEnum(String keyName, String keyDesc, Function<WorkWeixinProperties, Object> function) {
+        this.keyName = keyName;
+        this.keyDesc = keyDesc;
+        this.function = function;
+    }
+}

+ 18 - 17
src/main/java/top/lvzhiqiang/service/impl/CoinServiceImpl.java

@@ -22,6 +22,7 @@ import top.lvzhiqiang.service.CoinService;
 import top.lvzhiqiang.util.CheckSign4Bitget;
 import top.lvzhiqiang.util.DateUtils;
 import top.lvzhiqiang.util.JsoupUtil;
+import top.lvzhiqiang.util.SpringUtils;
 
 import javax.annotation.Resource;
 import java.io.UnsupportedEncodingException;
@@ -45,6 +46,17 @@ import java.util.stream.Collectors;
 @Service
 @Slf4j
 public class CoinServiceImpl implements CoinService {
+
+    /**
+     * 任务告警方式-应用文本卡片
+     */
+    public static final String JOB_ALARM_MODE_APP_TEXT_CARD = "1";
+
+    /**
+     * 任务告警方式-群聊机器人
+     */
+    public static final String JOB_ALARM_MODE_CHAT_BOT = "2";
+
     // 所有REST请求的header都必须包含以下key:
     private static final Map<String, String> basicHeaderMap = new HashMap<>();
     // 主域名 URL
@@ -109,22 +121,23 @@ public class CoinServiceImpl implements CoinService {
         JSONArray orderList = response.getJSONObject("data").getJSONArray("orderList");
         if (orderList.size() > 0) {
             coinMapper.insertHistoryOrderList(JSONArray.parseArray(orderList.toJSONString(), CoinHistoryOrder.class));
+            log.warn("syncData->insertHistoryOrderList,startTime={},endTime={},size={}", startTime, endTime, orderList.size());
         }
     }
 
 
     @Override
-    @Async("coinTaskExecutor")
     public String monitorJob() {
         Timer timer = new Timer();
         timer.scheduleAtFixedRate(new TimerTask() {
             @Override
             public void run() {
+                LocalDateTime endTime = LocalDateTime.now();
                 // 全部历史委托监控
                 Map<String, String> paramMap = new LinkedHashMap<>();
                 paramMap.put("productType", "umcbl");
-                paramMap.put("startTime", String.valueOf(DateUtils.localDateTimeToMilliseconds(LocalDateTime.now().minusSeconds(10))));
-                paramMap.put("endTime", String.valueOf(System.currentTimeMillis()));
+                paramMap.put("startTime", String.valueOf(DateUtils.localDateTimeToMilliseconds(endTime.minusSeconds(10))));
+                paramMap.put("endTime", String.valueOf(DateUtils.localDateTimeToMilliseconds(endTime)));
                 paramMap.put("pageSize", "100");
 
                 String signQueryString = paramMap.entrySet().stream().map(e -> e.getKey() + "=" + e.getValue()).collect(Collectors.joining("&"));
@@ -135,9 +148,9 @@ public class CoinServiceImpl implements CoinService {
                     JSONObject order = orderList.getJSONObject(i);
                     LocalDateTime cTime = DateUtils.longToLocalDateTime(order.getLong("cTime"));
                     String orderId = order.getString("orderId");
-                    if (Duration.between(cTime, LocalDateTime.now()).getSeconds() < 5 && !orderMap.containsKey(order.getString("orderId"))) {
+                    if (Duration.between(cTime, endTime).getSeconds() < 5 && !orderMap.containsKey(orderId)) {
                         orderMap.put(orderId, "1");
-                        monitorAlarm(order);
+                        SpringUtils.getBean(CoinServiceImpl.class).monitorAlarm(order);
                     }
                 }
             }
@@ -279,16 +292,4 @@ public class CoinServiceImpl implements CoinService {
             jsonObject.put("symbol", "<strong style=\"background-color:#F1B90d;\"><font color=\"#242A30\">" + symbol + "</font></strong>USDT_UMCBL");
         }
     }
-
-    public static void main(String[] args) {
-        CoinServiceImpl coinService = new CoinServiceImpl();
-        JSONObject params = new JSONObject();
-        /*params.put("nameEn", "allPositionv2");
-        params.put("url", "/api/mix/v1/position/allPosition-v2");*/
-
-        /*params.put("nameEn", "orderMarginCoinCurrent");
-        params.put("url", "/api/mix/v1/order/marginCoinCurrent");*/
-
-        System.out.println(coinService.mainSearch(params));
-    }
 }

+ 65 - 0
src/main/java/top/lvzhiqiang/util/SpringUtils.java

@@ -0,0 +1,65 @@
+package top.lvzhiqiang.util;
+
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.stereotype.Component;
+
+/**
+ * Spring工具类
+ *
+ * @author shiyong
+ * 2020/2/13 11:31
+ */
+@Component
+public class SpringUtils implements ApplicationContextAware {
+
+    private static ApplicationContext applicationContext;
+
+
+    @Override
+    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
+        if (SpringUtils.applicationContext == null) {
+            SpringUtils.applicationContext = applicationContext;
+        }
+    }
+
+    public static ApplicationContext getApplicationContext() { return applicationContext; }
+
+    /**
+    * 根据实例名称获取实例
+    *
+    * @param name 实例名称
+    * @return java.lang.Object
+    * @author shiyong
+    * 2020/2/13 12:09
+    */
+    /*public static Object getBean(Class<?> name) {
+        return getApplicationContext().getBean(name);
+    }*/
+
+    /**
+    * 根据对象类型获取实例
+    *
+    * @param clazz 对象类型
+    * @return T
+    * @author shiyong
+    * 2020/2/13 12:12
+    */
+    public static <T> T getBean(Class<T> clazz) {
+        return getApplicationContext().getBean(clazz);
+    }
+
+    /**
+    * 根据对象名称和类型获取实例
+    *
+    * @param name 对象名称
+    * @param clazz 对象类型
+    * @return T
+    * @author shiyong
+    * 2020/2/13 12:12
+    */
+    public static <T> T getBean(String name, Class<T> clazz) {
+        return getApplicationContext().getBean(name, clazz);
+    }
+}

+ 4 - 34
src/test/java/Test4.java

@@ -18,46 +18,16 @@
  * 3、刷票。很多投票的网页一个IP只允许投票一次,如果我们借助大量代理IP去投票,结果可想而知....
  */
 
-import me.chanjar.weixin.common.error.WxErrorException;
-import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
-import me.chanjar.weixin.cp.bean.message.WxCpMessage;
-import me.chanjar.weixin.cp.bean.message.WxCpMessageSendResult;
-import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;
-import top.lvzhiqiang.util.DateUtils;
-
+import java.time.Duration;
 import java.time.LocalDateTime;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.stream.Collectors;
 
 /**
  * 爬取网上免费代理IP,搭建自己的Ip池
  */
 public class Test4 {
     public static void main(String[] args) {
-        String title = "监控告警明细";
-        String content = "LEVERUSDT 上穿(Crossing Up) 0.001550";
-        String logUrl = "";
-        String btnTxt = "日志详情";
-
-        WxCpMessage wxCpMessage = WxCpMessage.TEXTCARD().agentId(1000002)
-                .toUser("LvZhiQiang")
-                .toParty("")
-                .toTag("")
-                .title(title).description(content)
-                .url("https://lvzhiqiang.top").btnTxt(btnTxt)
-                .build();
-
-        WxCpDefaultConfigImpl wxCpDefaultConfig = new WxCpDefaultConfigImpl();
-        wxCpDefaultConfig.setCorpId("ww95a4adba56acb55f");
-        wxCpDefaultConfig.setAgentId(1000002);
-        wxCpDefaultConfig.setCorpSecret("tqWepGSe91U2Cc2SDf2EGt6M2KaEy2PbvdEauGWywxs");
-        WxCpServiceImpl wxCpService = new WxCpServiceImpl();
-        wxCpService.setWxCpConfigStorage(wxCpDefaultConfig);
-        try {
-            WxCpMessageSendResult sendResult = wxCpService.getMessageService().send(wxCpMessage);
-            System.out.println(sendResult);
-        } catch (WxErrorException e) {
-        }
+        LocalDateTime cTime = LocalDateTime.now().minusSeconds(3);
+        LocalDateTime endTime =  LocalDateTime.now();
+        System.out.println(Duration.between(cTime, endTime).getSeconds());
     }
 }