Ver código fonte

1.alertrule2 实体规避数据库 int 以及bool数据转换问题

wanghs 2 anos atrás
pai
commit
de65d2b3ee

+ 25 - 1
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,8 +36,10 @@ public class AlertRule2 implements Serializable {
     @ChineseDes("报警级别")
     @TableField("rank")
     private String rank;
+    @Setter(AccessLevel.NONE)
+   // @Getter(AccessLevel.NONE)
     @ChineseDes("是否启用")
-    @TableField("enabled")
+   // @TableField("enabled")
     private int enabled;
     @ChineseDes("风机类型")
     @TableField("modelId")
@@ -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;
         }