Переглянути джерело

1.规避alarm-schedule 中 bool类型错误问题,以及long类型数据问题

wanghs 2 роки тому
батько
коміт
9db2e950d5

+ 2 - 2
schedule-job/alarm-schedule/src/main/java/com/gyee/wisdom/alarm/schedule/biz/EarlyReportBiz.java

@@ -72,7 +72,7 @@ public class EarlyReportBiz {
      * @date 2022/8/23
      **/
 
-    public List<AlarmSnap> getAlarmSnap(String stationId,List<String> alertValueList, String type) {
+    public List<AlarmSnap> getAlarmSnap(String stationId,List<Integer> alertValueList, String type) {
         List<AlarmSnap> list = alarmSnapService.list(new QueryWrapper<AlarmSnap>().in("ALERTVALUE", alertValueList).eq("CATEGORY1", type).eq("STATIONID",stationId));
         return list;
     }
@@ -87,7 +87,7 @@ public class EarlyReportBiz {
      * @date 2022/8/23
      **/
     public List<AlarmCount> getAlarmCount(List<Long> snapIdList, Date startTime, Date endTime) {
-        List<String> snapIdStringList = snapIdList.stream().map(s -> String.valueOf(s)).collect(Collectors.toList());
+        List<Long> snapIdStringList = snapIdList.stream().map(s ->s).collect(Collectors.toList());
         List<AlarmCount> list = alarmCountService.getAlarmCount(snapIdStringList, startTime, endTime);
         return list;
     }

+ 2 - 2
schedule-job/alarm-schedule/src/main/java/com/gyee/wisdom/alarm/schedule/biz/EarlyReportTask.java

@@ -111,7 +111,7 @@ public class EarlyReportTask implements Callable<TaskResult> {
 
         List<AlertRule2> alertRule2List = earlyReportBiz.getAlertRule2(reportParam.getCustomRuleId());
 
-        List<AlarmSnap> customAlarmSnapList = earlyReportBiz.getAlarmSnap(stationId,alertRule2List.stream().map(s -> String.valueOf(s.getEdnaValue())).collect(Collectors.toList()), "custom");
+        List<AlarmSnap> customAlarmSnapList = earlyReportBiz.getAlarmSnap(stationId,alertRule2List.stream().map(s -> s.getEdnaValue()).collect(Collectors.toList()), "custom");
 
         List<AlarmCount> customAlarmCountList = earlyReportBiz.getAlarmCount(customAlarmSnapList.stream().map(s -> s.getId()).collect(Collectors.toList()), statStartTime, statEndTime);
 
@@ -217,7 +217,7 @@ public class EarlyReportTask implements Callable<TaskResult> {
             reportAlarmList.addAll(s.getAlarmInfoList());
         });
         List<AlertRule2> alertRule2List = earlyReportBiz.getAlertRule2(reportAlarmList.stream().map(s -> s.getRuleId()).collect(Collectors.toList()));
-        List<AlarmSnap> customAlarmSnapList = earlyReportBiz.getAlarmSnap(stationId,alertRule2List.stream().map(s -> String.valueOf(s.getEdnaValue())).collect(Collectors.toList()), "custom");
+        List<AlarmSnap> customAlarmSnapList = earlyReportBiz.getAlarmSnap(stationId,alertRule2List.stream().map(s -> s.getEdnaValue()).collect(Collectors.toList()), "custom");
         List<AlarmCount> customAlarmCountList = earlyReportBiz.getAlarmCount(customAlarmSnapList.stream().map(s -> s.getId()).collect(Collectors.toList()), startTime, endTime);
         Map<String, List<AlarmCount>> windturbineAlarmCountMap = customAlarmCountList.stream().filter(s -> windturbineIdList.contains(s.getWindturbineId())).collect(Collectors.groupingBy(AlarmCount::getWindturbineId));
 

+ 3 - 3
schedule-job/alarm-schedule/src/main/java/com/gyee/wisdom/alarm/schedule/entity/AlertRule2.java

@@ -36,10 +36,10 @@ public class AlertRule2 implements Serializable {
     @ChineseDes("报警级别")
     @TableField("rank")
     private String rank;
-    @Setter(AccessLevel.NONE)
-   // @Getter(AccessLevel.NONE)
+   // @Setter(AccessLevel.NONE)
+   @Getter(AccessLevel.NONE)
     @ChineseDes("是否启用")
-   // @TableField("enabled")
+    @TableField("enabled")
     private int enabled;
     @ChineseDes("风机类型")
     @TableField("modelId")

+ 24 - 34
schedule-job/alarm-schedule/src/main/java/com/gyee/wisdom/alarm/schedule/job/EarlyReportHandler.java

@@ -46,25 +46,25 @@ public class EarlyReportHandler {
      * @author Wanghs
      * @description 生成风机诊断报告方法
      * xxl-job参数为json格式
-     *
+     * <p>
      * {
-     *     "reportName":"主轴隐患感知",
-     *     "windturbineParts":"CLX",
-     *     "interval": 7,
-     *     "customRuleId":
-     *     [
-     *         "ZX051NSSUP82",
-     *         "ZX534NSSUP82",
-     *         "ZX085NSSUP82"
-     *     ],
-     *     "windturbineRuleId":
-     *     [],
-     *     "resultLimit": 3,
-     *     "stationId": "NSS_FDC",
-     *     "model": "UP82"
+     * "reportName":"主轴隐患感知",
+     * "windturbineParts":"CLX",
+     * "interval": 7,
+     * "customRuleId":
+     * [
+     * "ZX051NSSUP82",
+     * "ZX534NSSUP82",
+     * "ZX085NSSUP82"
+     * ],
+     * "windturbineRuleId":
+     * [],
+     * "resultLimit": 3,
+     * "stationId": "NSS_FDC",
+     * "model": "UP82"
      * }
-     *
-     *
+     * <p>
+     * <p>
      * customRuleId为自定义报警规则id 对应alertrule2
      * windturbineRuleId风机报警id 对应warning2
      * interval 为分析时间区间,执行时以当天0点,前推相应天数
@@ -73,13 +73,9 @@ public class EarlyReportHandler {
      * @date 2022/7/26
      **/
     @XxlJob("earlyReport")
-    public ReturnT<String> alarmCountStat() throws InterruptedException {
-
+    public void alarmCountStat() {
         String param = XxlJobHelper.getJobParam();
-
         EarlyReportParam reportParam = JSON.parseObject(param, EarlyReportParam.class);
-        ReturnT t = null;
-
         try {
             TaskResult result = null;
             EarlyReportTask task = new EarlyReportTask(reportParam);
@@ -87,20 +83,14 @@ public class EarlyReportHandler {
             new Thread(ft).start();
             result = ft.get();
             if (result.isSuccess()) {
-                t = new ReturnT<String>(ReturnT.SUCCESS_CODE, "执行成功");
-                t.setContent(result);
+                XxlJobHelper.log("诊断报告调度任务执行成功");
+                XxlJobHelper.handleFail("诊断报告调度任务执行成功");
             } else {
-                t = new ReturnT<String>(ReturnT.FAIL_CODE, "执行失败");
-                t.setContent(result);
-            }
-        } catch (ExecutionException e) {
-            t = new ReturnT<String>(ReturnT.FAIL_CODE, "执行失败");
-            t.setContent(e.getStackTrace());
-            e.printStackTrace();
-        } finally {
-            XxlJobHelper.log(JSON.toJSONString(t));
-            return t;
 
+                XxlJobHelper.handleFail(JSON.toJSONString(result.getMsg()));
+            }
+        } catch (Exception e) {
+            XxlJobHelper.handleFail(JSON.toJSONString(e.getStackTrace()));
         }
 
 

+ 34 - 12
schedule-job/alarm-schedule/src/main/java/com/gyee/wisdom/alarm/schedule/job/MyJobHandler.java

@@ -9,7 +9,7 @@ import org.springframework.stereotype.Component;
 
 import java.util.List;
 
-import static com.xxl.job.core.biz.model.ReturnT.SUCCESS;
+import static com.xxl.job.core.biz.model.ReturnT.*;
 
 /**
  * @description:
@@ -18,7 +18,7 @@ import static com.xxl.job.core.biz.model.ReturnT.SUCCESS;
  */
 
 @Component
-public class MyJobHandler  {
+public class MyJobHandler {
 
 
     @XxlJob("MyJobHandler")
@@ -30,24 +30,46 @@ public class MyJobHandler  {
                 "默认目录格式为:/data/applogs/xxl-job/jobhandler/“格式化日期”/“数据库调度日志记录的主键ID.log”。" +
                 "执行日志可以通过xxl-job-admin进行查看");
 
-        AlarmHistory doResult=new AlarmHistory();
+        AlarmHistory doResult = new AlarmHistory();
 
-        ReturnT<AlarmHistory> returnT=new ReturnT<>(doResult);
-        returnT.setCode(ReturnT.SUCCESS_CODE);
+        ReturnT<AlarmHistory> returnT = new ReturnT<>(doResult);
+        returnT.setCode(SUCCESS_CODE);
         returnT.setMsg("执行结果描述(异常,成功,失败等)");
-        return  returnT;
+        return returnT;
     }
 
     @XxlJob("MyJobHandler2")
-    public ReturnT<String> demoJobHandler2(String param) throws Exception {
+    public ReturnT<String> demoJobHandler2() throws Exception {
         String command = XxlJobHelper.getJobParam();
+
+
         long id = Thread.currentThread().getId();
-        System.out.println("xxl.job测试2-参数:"+command+",jobID:"+XxlJobHelper.getJobId()+"thread-id:"+id);
-       //Thread.sleep(2000);
-       System.out.println("thread-id:"+id+"执行完毕");
-        XxlJobHelper.log("xxl.job测试2-参数:"+command+"执行成功,jobID:"+XxlJobHelper.getJobId()+"thread-id:"+id);
+        System.out.println("xxl.job测试2-参数:" + command + ",jobID:" + XxlJobHelper.getJobId() + "thread-id:" + id);
+        //Thread.sleep(2000);
+        System.out.println("thread-id:" + id + "执行完毕");
+        XxlJobHelper.log("xxl.job测试2-参数:" + command + "执行成功,jobID:" + XxlJobHelper.getJobId() + "thread-id:" + id);
+
+
+        Integer v = Integer.valueOf(command);
+        if (v > 10) {
+            XxlJobHelper.handleSuccess("调度成功");
+            return new ReturnT(SUCCESS_CODE, "调度成功111");
+
+        } else {
+            ReturnT t = null;
+            try {
+                int ii = v / 0;
+
+            } catch (Exception e) {
+              t=  new ReturnT(FAIL_CODE, "调度失败111"+e);
+                XxlJobHelper.handleFail("调度失败"+e);
+            } finally {
+                return t;
+            }
+
+
+        }
 
-        return SUCCESS;
     }
 
 }

+ 1 - 1
schedule-job/alarm-schedule/src/main/java/com/gyee/wisdom/alarm/schedule/mapper/AlarmCountMapper.java

@@ -58,5 +58,5 @@ public interface AlarmCountMapper extends BaseMapper<AlarmCount> {
     List<AlarmCountInfo> getAlarmCountInfo(@Param("windturbineid")String wtId,
                                            @Param("currentDate") Date currentDate);
 
-    List<AlarmCount> getAlarmCountBySnapIdList(@Param("snapIdList")List<String> snapIdList, @Param("startTime")Date startTime, @Param("endTime")Date endTime);
+    List<AlarmCount> getAlarmCountBySnapIdList(@Param("snapIdList")List<Long> snapIdList, @Param("startTime")Date startTime, @Param("endTime")Date endTime);
 }

+ 4 - 4
schedule-job/alarm-schedule/src/main/java/com/gyee/wisdom/alarm/schedule/service/AlarmCountService.java

@@ -19,7 +19,7 @@ import java.util.List;
 @Service
 public class AlarmCountService extends ServiceImpl<AlarmCountMapper, AlarmCount> {
 
-    public List<AlarmCount> getAlarmCount(List<String> snapIdList, Date startTime, Date endTime) {
+    public List<AlarmCount> getAlarmCount(List<Long> snapIdList, Date startTime, Date endTime) {
 
         List<AlarmCount> resultList = new ArrayList<>();
 
@@ -29,20 +29,20 @@ public class AlarmCountService extends ServiceImpl<AlarmCountMapper, AlarmCount>
             int remainder = snapIdList.size() % 1000;
             if (remainder == 0) {
                 for (int i = 0; i < selectCount; i++) {
-                    List<String> subSnapIdList = snapIdList.subList(1000 * i, 1000 * (i + 1));
+                    List<Long> subSnapIdList = snapIdList.subList(1000 * i, 1000 * (i + 1));
                     List<AlarmCount> subList = baseMapper.getAlarmCountBySnapIdList(subSnapIdList, startTime, endTime);
                     resultList.addAll(subList);
                 }
             } else {
 
                 for (int i = 0; i < selectCount; i++) {
-                    List<String> subSnapIdList = snapIdList.subList(1000 * i, 1000 * (i + 1));
+                    List<Long> subSnapIdList = snapIdList.subList(1000 * i, 1000 * (i + 1));
                     List<AlarmCount> subList = baseMapper.getAlarmCountBySnapIdList(subSnapIdList, startTime, endTime);
                     resultList.addAll(subList);
                 }
                 //将数组剩余元素进行查询
 
-                List<String> lastSnapIdList = snapIdList.subList(snapIdList.size() - remainder, snapIdList.size());
+                List<Long> lastSnapIdList = snapIdList.subList(snapIdList.size() - remainder, snapIdList.size());
                 List<AlarmCount> lastSubList = baseMapper.getAlarmCountBySnapIdList(lastSnapIdList, startTime, endTime);
                 resultList.addAll(lastSubList);
             }