Ver código fonte

Merge remote-tracking branch 'origin/master'

‘xugp 2 anos atrás
pai
commit
b5af5e5833

+ 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));
 

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

@@ -5,7 +5,10 @@ import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.gyee.wisdom.alarm.schedule.util.ChineseDes;
+import lombok.AccessLevel;
 import lombok.Data;
+import lombok.Getter;
+import lombok.Setter;
 
 import java.io.Serializable;
 import java.util.Date;
@@ -33,6 +36,8 @@ public class AlertRule2 implements Serializable {
     @ChineseDes("报警级别")
     @TableField("rank")
     private String rank;
+   // @Setter(AccessLevel.NONE)
+   @Getter(AccessLevel.NONE)
     @ChineseDes("是否启用")
     @TableField("enabled")
     private int enabled;
@@ -75,4 +80,23 @@ public class AlertRule2 implements Serializable {
     @TableField("createtime")
     private Date createtime;//操作时间
 
+
+//    public int getEnabled() {
+//        return enabled;
+//    }
+//
+    public void setEnabled(Object enabled) {
+        if (enabled == null) {
+            this.enabled = 0;
+            return;
+        }
+        if (enabled instanceof Boolean) {
+            Boolean b =(Boolean)enabled;
+            this.enabled = b ? 1 : 0;
+
+        } else {
+            this.enabled = Integer.valueOf(String.valueOf(enabled));
+        }
+    }
+
 }

+ 30 - 0
schedule-job/alarm-schedule/src/main/java/com/gyee/wisdom/alarm/schedule/entity/Warning2.java

@@ -3,7 +3,10 @@ package com.gyee.wisdom.alarm.schedule.entity;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.AccessLevel;
 import lombok.Data;
+import lombok.Getter;
+import lombok.Setter;
 
 import java.io.Serializable;
 
@@ -51,4 +54,31 @@ public class Warning2 implements Serializable {
 
     @TableField(exist = false)
     private String userName;//操作人
+
+
+    @Getter(AccessLevel.NONE)
+    @Setter(AccessLevel.NONE)
+    @TableField("ENABLED")
+    private int enabled;
+
+
+    public int getEnabled() {
+        return enabled;
+    }
+
+
+    public void setEnabled(Object enabled) {
+        if (enabled == null) {
+            this.enabled = 0;
+            return;
+        }
+        if (enabled instanceof Boolean) {
+            Boolean b =(Boolean)enabled;
+            this.enabled = b ? 1 : 0;
+
+        } else {
+            this.enabled = Integer.valueOf(String.valueOf(enabled));
+        }
+    }
+
 }

+ 16 - 12
schedule-job/alarm-schedule/src/main/java/com/gyee/wisdom/alarm/schedule/job/AlarmCountHandler.java

@@ -10,6 +10,7 @@ import com.gyee.wisdom.alarm.schedule.service.TableNameService;
 import com.gyee.wisdom.alarm.schedule.util.SnowflakeGenerator;
 import com.gyee.wisdom.common.utils.DateUtil;
 import com.xxl.job.core.handler.annotation.XxlJob;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
@@ -17,8 +18,10 @@ import org.springframework.stereotype.Component;
 import java.text.DecimalFormat;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Date;
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * @description: 报警统计,每天计算后写入alarmcount表 sharding-mysql2中AlarmCountService中startCount方法移植
@@ -26,6 +29,7 @@ import java.util.List;
  * @date: 2022-03-16
  */
 @Component
+@Slf4j
 public class AlarmCountHandler {
 
     @Autowired
@@ -40,7 +44,7 @@ public class AlarmCountHandler {
     @Autowired
     private TableNameService tableNameService;
 
-   // @Scheduled(cron = "0 30 0 ? * *")
+    // @Scheduled(cron = "0 30 0 ? * *")
     @XxlJob("alarmCountStat")
     public boolean alarmCountStat() {
 
@@ -48,7 +52,7 @@ public class AlarmCountHandler {
         try {
             List<AlarmSnap> snapList = alarmSnapService.queryAll(null, null, "custom", null, null, null, null, null, null, null);
             SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
-            String strDate = sdf.format(DateUtil.addDays(new Date(),-1));
+            String strDate = sdf.format(DateUtil.addDays(new Date(), -1));
             Date dtStart = sdf.parse(strDate);
             Date dtEnd = DateUtil.addDays(dtStart, 1);
             Date dtNow = new Date();
@@ -71,24 +75,24 @@ public class AlarmCountHandler {
                         Date alertTimebegin = null;
                         Date alertTimeend = null;
                         Double minall = 0.0;
-                        for(AlarmHistory alarmHistory:alarmHistories){
+                        for (AlarmHistory alarmHistory : alarmHistories) {
                             int messageType = alarmHistory.getMessageType();
-                            if(!(messageType==1^bool)){
-                                if(bool) {
+                            if (!(messageType == 1 ^ bool)) {
+                                if (bool) {
                                     alertTimebegin = alarmHistory.getAlertTime();
                                 }
-                                if(!bool){
+                                if (!bool) {
                                     alertTimeend = alarmHistory.getAlertTime();
-                                    Double min = Double.parseDouble((alertTimeend.getTime()-alertTimebegin.getTime())+"")/1000/60;
+                                    Double min = Double.parseDouble((alertTimeend.getTime() - alertTimebegin.getTime()) + "") / 1000 / 60;
                                     minall = minall + min;
                                     bool = true;
-                                }else {
+                                } else {
                                     bool = false;
                                 }
                             }
                         }
                         DecimalFormat df = new DecimalFormat("0.000");
-                        ac.setTime(Double.parseDouble(df.format(minall+1)));
+                        ac.setTime(Double.parseDouble(df.format(minall + 1)));
                         acList.add(ac);
                     }
                 }
@@ -99,9 +103,9 @@ public class AlarmCountHandler {
                 dtEnd = DateUtil.addDays(dtStart, 1);
             }
 
-        } catch(Exception ex){
-           // log.error(ex.getMessage());
-           // log.error(ex.getStackTrace().toString());
+        } catch (Exception ex) {
+            log.error(ex.getMessage());
+            log.error("执行调度任务失败{}",ex.getStackTrace());
             return false;
         }
 

+ 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.handleSuccess("诊断报告调度任务执行成功");
             } 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);
             }

+ 3 - 5
schedule-job/alarm-schedule/src/main/resources/mappers-postgresql/AlarmCountMapper.xml

@@ -15,20 +15,18 @@
     <insert id="singleInsert" >
         insert into alarmcount (id, alarmdate, snapid, count)
         values
-        (#{item.id}, #{item.alarmdate}, #{item.snapId}, #{item.count})
+        (#{item.id}, cast(#{item.alarmDate} as  timestamp), #{item.snapId}, #{item.count})
     </insert>
 
     <insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys="false">
         insert into alarmcount ( ID, alarmdate, snapid, count,time )
         <foreach collection="list" item="item" index="index" separator="union all" >
             ( select
-            #{item.id}, #{item.alarmDate}, #{item.snapId}, #{item.count} ,#{item.time}
-            from dual )
+            #{item.id}, cast(#{item.alarmDate} as  timestamp), #{item.snapId}, #{item.count} ,#{item.time}
+            )
         </foreach>
     </insert>
 
-
-
     <select id="selectAlarmHistoryBySnapid" parameterType="java.util.Map" resultType="com.gyee.wisdom.alarm.schedule.entity.AlarmHistory"  >
              select * from ${alarmhistory} where snapid = #{snapid}
              and alerttime &gt;= #{startdate,jdbcType=DATE} and alerttime &lt; #{enddate,jdbcType=DATE} order by alerttime asc

+ 1 - 1
warning-web/src/main/java/com/gyee/wisdom/alarm/sharding/service/AlarmCountService.java

@@ -395,7 +395,7 @@ public class AlarmCountService extends ServiceImpl<AlarmCountMapper, AlarmCount>
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
         Date begindate = sdf.parse(startDate);
         Date enddate = sdf.parse(endDate);
-        AlarmSnap alarmSnap = alarmSnapService.getById(snapId);
+        AlarmSnap alarmSnap = alarmSnapService.getById(Long.valueOf(snapId));
         if (alarmSnap == null)
             return new HashMap<>();