Selaa lähdekoodia

1.规避postgresql alarmhistory流水表 自动建表问题
2.规避 postgresql limit offset 问题

wanghs 1 vuosi sitten
vanhempi
commit
79bf55c7cf

+ 3 - 1
schedule-job/alarm-schedule/build.gradle

@@ -20,6 +20,9 @@ apply plugin: "io.spring.dependency-management"
 
 dependencies {
     implementation fileTree(dir: "src/main/lib", include: "*.jar")
+    // implementation ("mysql:mysql-connector-java:$mysqlConnectorVersion")
+    implementation ("org.postgresql:postgresql:$postgresqlDriverVersion")
+
     implementation project(":common:utils")
     implementation("$bootGroup:spring-boot-starter-web")
     implementation("$bootGroup:spring-boot-starter-undertow")
@@ -28,7 +31,6 @@ dependencies {
     implementation("org.apache.logging.log4j:log4j-jul:$log4jVersion")
     implementation("org.apache.logging.log4j:log4j-api:$log4jVersion")
     implementation("org.apache.logging.log4j:log4j-slf4j-impl:$log4jVersion")
-  //  implementation ("mysql:mysql-connector-java:$mysqlConnectorVersion")
     implementation ("com.alibaba:druid:$alibabaDruidVersion")
     implementation ("com.alibaba:fastjson:$fastjsonVersion")
 

+ 50 - 8
schedule-job/alarm-schedule/src/main/java/com/gyee/wisdom/alarm/schedule/controller/EarlyReportController.java

@@ -1,20 +1,27 @@
 package com.gyee.wisdom.alarm.schedule.controller;
 
-import com.gyee.wisdom.alarm.schedule.entity.AlarmCount;
-import com.gyee.wisdom.alarm.schedule.entity.EarlyReport;
+import com.gyee.wisdom.alarm.schedule.biz.EarlyReportBiz;
+import com.gyee.wisdom.alarm.schedule.biz.EarlyReportTask;
+import com.gyee.wisdom.alarm.schedule.entity.*;
+import com.gyee.wisdom.alarm.schedule.job.AlarmCountHandler;
+import com.gyee.wisdom.alarm.schedule.job.EarlyReportHandler;
+import com.gyee.wisdom.alarm.schedule.job.TablesManagerHandler;
 import com.gyee.wisdom.alarm.schedule.mapper.AlarmCountMapper;
 import com.gyee.wisdom.alarm.schedule.mapper.EarlyReportMapper;
+import com.gyee.wisdom.alarm.schedule.model.EarlyReportParam;
+import com.gyee.wisdom.alarm.schedule.model.TaskResult;
 import com.gyee.wisdom.alarm.schedule.service.AlarmCountService;
 import com.gyee.wisdom.alarm.schedule.service.AlarmSnapService;
+import com.gyee.wisdom.alarm.schedule.service.TestService;
+import com.gyee.wisdom.alarm.schedule.util.SpringContextUtils;
 import com.gyee.wisdom.common.utils.DateUtil;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import java.util.Arrays;
 import java.util.Date;
 import java.util.List;
+import java.util.concurrent.FutureTask;
 
 /**
  * @description:
@@ -47,9 +54,44 @@ public class EarlyReportController {
     }
     @GetMapping("/test")
     public List<AlarmCount> getAlarmCountTest() {
-        List<String> longs = Arrays.asList("964545037092659206", "697500304987389955");
-        List<AlarmCount> alarmCount = alarmCountService.getAlarmCount(longs, null, null);
 
-        return alarmCount;
+        EarlyReportBiz bean = SpringContextUtils.getBean(EarlyReportBiz.class);
+        List<AlertRule2> alertRule2 = bean.getAlertRule2(Arrays.asList("JN2165", "JN2148","JN2137"));
+        return null;
+    }
+
+    @GetMapping("/test2")
+    public List<Test> postgresqlTest() {
+
+        EarlyReportBiz bean1 = SpringContextUtils.getBean(EarlyReportBiz.class);
+        bean1.getAlertRule2(Arrays.asList("HD01","HD02"));
+
+        TestService bean2 = SpringContextUtils.getBean(TestService.class);
+        List<Test> list = bean2.list();
+
+        return list;
+    }
+    @PostMapping("/stat")
+    public String alarmCountStat(@RequestBody EarlyReportParam reportParam){
+       // AlarmCountHandler bean = SpringContextUtils.getBean(AlarmCountHandler.class);
+        // bean.alarmCountStat();
+
+        EarlyReportTask task = new EarlyReportTask(reportParam);
+        FutureTask<TaskResult> ft = new FutureTask<>(task);
+        new Thread(ft).start();
+
+
+        return "123";
+    }
+
+    @GetMapping("/addTable")
+    public String addTable(){
+        TablesManagerHandler bean = SpringContextUtils.getBean(TablesManagerHandler.class);
+        bean.AddAlarmHistoryTable();
+
+
+
+
+        return "123";
     }
 }

+ 114 - 0
schedule-job/alarm-schedule/src/main/java/com/gyee/wisdom/alarm/schedule/entity/Test.java

@@ -0,0 +1,114 @@
+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 com.gyee.wisdom.common.utils.StringUtil;
+import lombok.Data;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.io.Serializable;
+
+/**
+ * @description:
+ * @auther: Wanghs
+ * @date: 2022-10-25
+ */
+@TableName("c_test")
+public class Test implements Serializable {
+
+    @Getter
+    @Setter
+    @TableId
+    private int id;
+
+//
+//    @Getter
+//    @TableField("cbool")
+//    private Integer cBool;
+//
+//    @Getter
+//    @TableField("cint")
+//    private Integer cInt;
+//
+//    public void setcBool(Object obj) {
+//        if (obj == null) {
+//            this.cBool = null;
+//            return;
+//        }
+//        if (obj instanceof Boolean) {
+//            Boolean b = Boolean.valueOf(String.valueOf(obj));
+//            this.cBool = b ? 1 : 0;
+//
+//        } else {
+//            this.cBool = Integer.valueOf(String.valueOf(obj));
+//        }
+//    }
+//
+//    public void setcInt(Object obj) {
+//        if(obj==null){
+//            this.cInt=0;
+//            return;
+//        }
+//
+//        if (obj instanceof Boolean) {
+//            Boolean b = Boolean.valueOf(String.valueOf(obj));
+//            this.cInt = b ? 1 : 0;
+//
+//        } else {
+//            this.cInt = Integer.valueOf(String.valueOf(obj));
+//        }
+//    }
+
+
+    @Getter
+    @TableField("cbool")
+    private boolean cBool;
+
+    @Getter
+    @TableField("cint")
+    private boolean cInt;
+
+    public void setcBool(Object obj) {
+
+        if (obj == null) {
+            this.cBool = false;
+            return;
+        }
+        if (obj instanceof Boolean) {
+            this.cBool = (Boolean) obj;
+        } else {
+            String objStr = String.valueOf(obj);
+            if (objStr.length() > 0 && objStr.trim() != "0") {
+                this.cBool = true;
+
+            } else {
+                this.cBool = false;
+            }
+
+        }
+    }
+
+    public void setcInt(Object obj) {
+
+        if (obj == null) {
+            this.cInt = false;
+            return;
+        }
+        if (obj instanceof Boolean) {
+            this.cInt = (Boolean) obj;
+        } else {
+            String objStr = String.valueOf(obj);
+            if (objStr.length() > 0 && !objStr.trim().equals("0")) {
+                this.cInt = true;
+
+            } else {
+                this.cInt = false;
+            }
+
+        }
+    }
+
+
+}

+ 2 - 1
schedule-job/alarm-schedule/src/main/java/com/gyee/wisdom/alarm/schedule/job/AlarmCountHandler.java

@@ -105,7 +105,8 @@ public class AlarmCountHandler {
 
         } catch (Exception ex) {
             log.error(ex.getMessage());
-            log.error("执行调度任务失败{}",ex.getStackTrace());
+            log.error("执行调度任务失败{}",ex.getCause());
+            log.error("错误信息",ex);
             return false;
         }
 

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

@@ -31,7 +31,7 @@ public class TablesManagerHandler {
     public void AddAlarmHistoryTable(){
         Calendar instance = Calendar.getInstance();
         //查看当前时间的下月是否有表,没有就创建
-        //instance.add(Calendar.MONTH,1);
+        instance.add(Calendar.MONTH,1);
         String yearmonth=null;
         int year=instance.get(Calendar.YEAR);
         int month=instance.get(Calendar.MONTH)+1;

+ 14 - 0
schedule-job/alarm-schedule/src/main/java/com/gyee/wisdom/alarm/schedule/mapper/TestMapper.java

@@ -0,0 +1,14 @@
+package com.gyee.wisdom.alarm.schedule.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.gyee.wisdom.alarm.schedule.entity.Test;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * @description:
+ * @auther: Wanghs
+ * @date: 2022-10-25
+ */
+@Mapper
+public interface TestMapper extends BaseMapper<Test> {
+}

+ 15 - 0
schedule-job/alarm-schedule/src/main/java/com/gyee/wisdom/alarm/schedule/service/TestService.java

@@ -0,0 +1,15 @@
+package com.gyee.wisdom.alarm.schedule.service;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.gyee.wisdom.alarm.schedule.entity.Test;
+import com.gyee.wisdom.alarm.schedule.mapper.TestMapper;
+import org.springframework.stereotype.Service;
+
+/**
+ * @description:
+ * @auther: Wanghs
+ * @date: 2022-10-25
+ */
+@Service
+public class TestService extends ServiceImpl<TestMapper, Test> {
+}

+ 11 - 6
schedule-job/alarm-schedule/src/main/resources/application.yaml

@@ -9,9 +9,14 @@ spring:
   application:
     name: alarm-schedule
   datasource:
-    driver-class-name: com.mysql.jdbc.Driver
-    url: jdbc:mysql://123.60.219.66/wisdom_cs?useUnicode=true&characterEncoding=UTF-8
-    username: root
+#    driver-class-name: com.mysql.jdbc.Driver
+#    url: jdbc:mysql://123.60.219.66/wisdom_cs?useUnicode=true&characterEncoding=UTF-8
+#    username: root
+#    password: gyeepd@123
+
+    driver-class-name: org.postgresql.Driver
+    url: jdbc:postgresql://123.60.219.66:5432/wisdom_cs
+    username: postgres
     password: gyeepd@123
 #    driver-class-name: oracle.jdbc.OracleDriver
 #    url: jdbc:oracle:thin:@123.60.213.70:1521:gdnxfd
@@ -36,7 +41,7 @@ spring:
 
 mybatis-plus:
   typeAliasesPackage: com.gyee.wisdom.alarm.schedule.entity
-  mapper-locations: classpath:mappers/*.xml
+  mapper-locations: classpath:mappers-postgresql/*.xml
   global-config:
     #主键类型  0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID";
     id-type: 3
@@ -84,7 +89,7 @@ count:
   custom: true
   fault: false
 
-stationname: MHS,XS,NSS,QS,SBQ,DWK,HZJ,MCH,PL,XH,XS,BY
+stationname: MHS,XS,NSS,QS,SBQ,DWK,HZJ,MCH,PL,XH,XS
 #tablespace: TS_GDSJ_DATA
 tablespace: TS_NXFD_DATA
 
@@ -109,7 +114,7 @@ knife4j:
 xxl:
   job:
     admin:
-      addresses: http://localhost:8080/xxl-job-admin
+      addresses: http://localhost:8081/xxl-job-admin
     accessToken:
     executor:
       appname: alarm-schedule

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

@@ -198,8 +198,8 @@
         )
     </update>
     <update id="timedAlterTable">
-        alter table alarmhistory_${stationname}_${yearmonth}
-        owner to gdprod
+<!--        postgresql不需要关联表空间因此不做操作-->
+<!--        alter table alarmhistory_${stationname}_${yearmonth}-->
     </update>
     <update id="timedCreatAlerttimeIndex">
         create index IX_AH_${stationname}_${yearmonth}_alerttime on alarmhistory_${stationname}_${yearmonth} ("alerttime")
@@ -209,7 +209,7 @@
     </update>
     <select id="isHasTable" resultType="java.lang.Integer">
         select count(*) from information_schema.tables where table_schema='public' and table_type='BASE TABLE' and
-            table_name=LOWER('alarmhistory_{stationname}_${yearmonth}');
+            table_name=LOWER('alarmhistory_${stationname}_${yearmonth}');
     </select>
 
 </mapper>