diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..50f4a19 --- /dev/null +++ b/pom.xml @@ -0,0 +1,161 @@ + + + 4.0.0 + + com.casic + smartwell-demos + 1.0-SNAPSHOT + + + + + jdk-1.8 + + true + 1.8 + + + 1.8 + 1.8 + 1.8 + + + + + + + + + + org.springframework.boot + spring-boot-starter + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-tomcat + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-web + 2.4.5 + + + + + org.springframework.boot + spring-boot-starter-jdbc + 2.4.5 + + + + mysql + mysql-connector-java + 8.0.16 + compile + + + + com.baomidou + mybatis-plus-boot-starter + 3.4.3 + + + + org.projectlombok + lombok + 1.18.20 + + + + + com.alibaba + druid + 1.2.6 + + + + com.alibaba + fastjson + 1.2.73 + + + + commons-codec + commons-codec + 1.14 + + + + redis.clients + jedis + 3.1.0 + jar + + + + org.springframework.data + spring-data-redis + 2.4.8 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.3.RELEASE + + true + + com.casic.CasicApplication + exec + + + + + repackage + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + false + + + + + + + + src/main/resources + + + /config/*/* + /config/*-*.yml + + true + + + src/main/resources + + **/*.xml + + true + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..50f4a19 --- /dev/null +++ b/pom.xml @@ -0,0 +1,161 @@ + + + 4.0.0 + + com.casic + smartwell-demos + 1.0-SNAPSHOT + + + + + jdk-1.8 + + true + 1.8 + + + 1.8 + 1.8 + 1.8 + + + + + + + + + + org.springframework.boot + spring-boot-starter + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-tomcat + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-web + 2.4.5 + + + + + org.springframework.boot + spring-boot-starter-jdbc + 2.4.5 + + + + mysql + mysql-connector-java + 8.0.16 + compile + + + + com.baomidou + mybatis-plus-boot-starter + 3.4.3 + + + + org.projectlombok + lombok + 1.18.20 + + + + + com.alibaba + druid + 1.2.6 + + + + com.alibaba + fastjson + 1.2.73 + + + + commons-codec + commons-codec + 1.14 + + + + redis.clients + jedis + 3.1.0 + jar + + + + org.springframework.data + spring-data-redis + 2.4.8 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.3.RELEASE + + true + + com.casic.CasicApplication + exec + + + + + repackage + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + false + + + + + + + + src/main/resources + + + /config/*/* + /config/*-*.yml + + true + + + src/main/resources + + **/*.xml + + true + + + + + \ No newline at end of file diff --git a/src/main/java/com/casic/CasicApplication.java b/src/main/java/com/casic/CasicApplication.java new file mode 100644 index 0000000..9afd0b9 --- /dev/null +++ b/src/main/java/com/casic/CasicApplication.java @@ -0,0 +1,28 @@ +package com.casic; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.transaction.annotation.EnableTransactionManagement; + + +/** + * SpringBoot方式启动类 + * + * @author cz + * @Date 2022/09/08 14:28 + */ + +@Slf4j +@ComponentScan(basePackages= "com.casic.**") +@SpringBootApplication +public class CasicApplication { + public static void main(String[] args) { + log.info("CasicApplication is success!"); + SpringApplication.run(CasicApplication.class, args); + } +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..50f4a19 --- /dev/null +++ b/pom.xml @@ -0,0 +1,161 @@ + + + 4.0.0 + + com.casic + smartwell-demos + 1.0-SNAPSHOT + + + + + jdk-1.8 + + true + 1.8 + + + 1.8 + 1.8 + 1.8 + + + + + + + + + + org.springframework.boot + spring-boot-starter + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-tomcat + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-web + 2.4.5 + + + + + org.springframework.boot + spring-boot-starter-jdbc + 2.4.5 + + + + mysql + mysql-connector-java + 8.0.16 + compile + + + + com.baomidou + mybatis-plus-boot-starter + 3.4.3 + + + + org.projectlombok + lombok + 1.18.20 + + + + + com.alibaba + druid + 1.2.6 + + + + com.alibaba + fastjson + 1.2.73 + + + + commons-codec + commons-codec + 1.14 + + + + redis.clients + jedis + 3.1.0 + jar + + + + org.springframework.data + spring-data-redis + 2.4.8 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.3.RELEASE + + true + + com.casic.CasicApplication + exec + + + + + repackage + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + false + + + + + + + + src/main/resources + + + /config/*/* + /config/*-*.yml + + true + + + src/main/resources + + **/*.xml + + true + + + + + \ No newline at end of file diff --git a/src/main/java/com/casic/CasicApplication.java b/src/main/java/com/casic/CasicApplication.java new file mode 100644 index 0000000..9afd0b9 --- /dev/null +++ b/src/main/java/com/casic/CasicApplication.java @@ -0,0 +1,28 @@ +package com.casic; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.transaction.annotation.EnableTransactionManagement; + + +/** + * SpringBoot方式启动类 + * + * @author cz + * @Date 2022/09/08 14:28 + */ + +@Slf4j +@ComponentScan(basePackages= "com.casic.**") +@SpringBootApplication +public class CasicApplication { + public static void main(String[] args) { + log.info("CasicApplication is success!"); + SpringApplication.run(CasicApplication.class, args); + } +} diff --git a/src/main/java/com/casic/config/CorsConfig.java b/src/main/java/com/casic/config/CorsConfig.java new file mode 100644 index 0000000..7d19680 --- /dev/null +++ b/src/main/java/com/casic/config/CorsConfig.java @@ -0,0 +1,31 @@ +package com.casic.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +/** + * 基础框架 - 跨域请求配置 + */ +@Configuration +public class CorsConfig { + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", buildConfig()); + return new CorsFilter(source); + } + + private CorsConfiguration buildConfig() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + // 1允许任何域名使用 + corsConfiguration.addAllowedOrigin("*"); + // 2允许任何头 + corsConfiguration.addAllowedHeader("*"); + // 3允许任何方法(post、get等) + corsConfiguration.addAllowedMethod("*"); + return corsConfiguration; + } +} \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..50f4a19 --- /dev/null +++ b/pom.xml @@ -0,0 +1,161 @@ + + + 4.0.0 + + com.casic + smartwell-demos + 1.0-SNAPSHOT + + + + + jdk-1.8 + + true + 1.8 + + + 1.8 + 1.8 + 1.8 + + + + + + + + + + org.springframework.boot + spring-boot-starter + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-tomcat + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-web + 2.4.5 + + + + + org.springframework.boot + spring-boot-starter-jdbc + 2.4.5 + + + + mysql + mysql-connector-java + 8.0.16 + compile + + + + com.baomidou + mybatis-plus-boot-starter + 3.4.3 + + + + org.projectlombok + lombok + 1.18.20 + + + + + com.alibaba + druid + 1.2.6 + + + + com.alibaba + fastjson + 1.2.73 + + + + commons-codec + commons-codec + 1.14 + + + + redis.clients + jedis + 3.1.0 + jar + + + + org.springframework.data + spring-data-redis + 2.4.8 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.3.RELEASE + + true + + com.casic.CasicApplication + exec + + + + + repackage + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + false + + + + + + + + src/main/resources + + + /config/*/* + /config/*-*.yml + + true + + + src/main/resources + + **/*.xml + + true + + + + + \ No newline at end of file diff --git a/src/main/java/com/casic/CasicApplication.java b/src/main/java/com/casic/CasicApplication.java new file mode 100644 index 0000000..9afd0b9 --- /dev/null +++ b/src/main/java/com/casic/CasicApplication.java @@ -0,0 +1,28 @@ +package com.casic; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.transaction.annotation.EnableTransactionManagement; + + +/** + * SpringBoot方式启动类 + * + * @author cz + * @Date 2022/09/08 14:28 + */ + +@Slf4j +@ComponentScan(basePackages= "com.casic.**") +@SpringBootApplication +public class CasicApplication { + public static void main(String[] args) { + log.info("CasicApplication is success!"); + SpringApplication.run(CasicApplication.class, args); + } +} diff --git a/src/main/java/com/casic/config/CorsConfig.java b/src/main/java/com/casic/config/CorsConfig.java new file mode 100644 index 0000000..7d19680 --- /dev/null +++ b/src/main/java/com/casic/config/CorsConfig.java @@ -0,0 +1,31 @@ +package com.casic.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +/** + * 基础框架 - 跨域请求配置 + */ +@Configuration +public class CorsConfig { + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", buildConfig()); + return new CorsFilter(source); + } + + private CorsConfiguration buildConfig() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + // 1允许任何域名使用 + corsConfiguration.addAllowedOrigin("*"); + // 2允许任何头 + corsConfiguration.addAllowedHeader("*"); + // 3允许任何方法(post、get等) + corsConfiguration.addAllowedMethod("*"); + return corsConfiguration; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/controller/AlarmController.java b/src/main/java/com/casic/controller/AlarmController.java new file mode 100644 index 0000000..957fc36 --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.model.AlarmConfigParam; +import com.casic.service.AlarmService; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/alarm") +public class AlarmController { + + private final AlarmService alarmService; + + public AlarmController(AlarmService alarmService) { + this.alarmService = alarmService; + } + + @RequestMapping("/records") + public Object getAlarmRecord(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "devcode",required =false) String devcode, + @RequestParam(value = "pageSize", required = true) Integer pageSize) { + return alarmService.getAlarmRecord(deviceType,currentIndex,pageSize,devcode); + } + + @RequestMapping("/batch/cancel") + public Object excuteAlramBatchCancel(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "devcode",required =false) String devcode) { + return alarmService.excuteAlramBatchCancel(deviceType,devcode); + } + + @RequestMapping("/config/add") + public Object addAlarmConfig(@RequestBody AlarmConfigParam alarmConfigParam) { + return alarmService.addAlarmConfig(alarmConfigParam); + } +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..50f4a19 --- /dev/null +++ b/pom.xml @@ -0,0 +1,161 @@ + + + 4.0.0 + + com.casic + smartwell-demos + 1.0-SNAPSHOT + + + + + jdk-1.8 + + true + 1.8 + + + 1.8 + 1.8 + 1.8 + + + + + + + + + + org.springframework.boot + spring-boot-starter + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-tomcat + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-web + 2.4.5 + + + + + org.springframework.boot + spring-boot-starter-jdbc + 2.4.5 + + + + mysql + mysql-connector-java + 8.0.16 + compile + + + + com.baomidou + mybatis-plus-boot-starter + 3.4.3 + + + + org.projectlombok + lombok + 1.18.20 + + + + + com.alibaba + druid + 1.2.6 + + + + com.alibaba + fastjson + 1.2.73 + + + + commons-codec + commons-codec + 1.14 + + + + redis.clients + jedis + 3.1.0 + jar + + + + org.springframework.data + spring-data-redis + 2.4.8 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.3.RELEASE + + true + + com.casic.CasicApplication + exec + + + + + repackage + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + false + + + + + + + + src/main/resources + + + /config/*/* + /config/*-*.yml + + true + + + src/main/resources + + **/*.xml + + true + + + + + \ No newline at end of file diff --git a/src/main/java/com/casic/CasicApplication.java b/src/main/java/com/casic/CasicApplication.java new file mode 100644 index 0000000..9afd0b9 --- /dev/null +++ b/src/main/java/com/casic/CasicApplication.java @@ -0,0 +1,28 @@ +package com.casic; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.transaction.annotation.EnableTransactionManagement; + + +/** + * SpringBoot方式启动类 + * + * @author cz + * @Date 2022/09/08 14:28 + */ + +@Slf4j +@ComponentScan(basePackages= "com.casic.**") +@SpringBootApplication +public class CasicApplication { + public static void main(String[] args) { + log.info("CasicApplication is success!"); + SpringApplication.run(CasicApplication.class, args); + } +} diff --git a/src/main/java/com/casic/config/CorsConfig.java b/src/main/java/com/casic/config/CorsConfig.java new file mode 100644 index 0000000..7d19680 --- /dev/null +++ b/src/main/java/com/casic/config/CorsConfig.java @@ -0,0 +1,31 @@ +package com.casic.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +/** + * 基础框架 - 跨域请求配置 + */ +@Configuration +public class CorsConfig { + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", buildConfig()); + return new CorsFilter(source); + } + + private CorsConfiguration buildConfig() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + // 1允许任何域名使用 + corsConfiguration.addAllowedOrigin("*"); + // 2允许任何头 + corsConfiguration.addAllowedHeader("*"); + // 3允许任何方法(post、get等) + corsConfiguration.addAllowedMethod("*"); + return corsConfiguration; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/controller/AlarmController.java b/src/main/java/com/casic/controller/AlarmController.java new file mode 100644 index 0000000..957fc36 --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.model.AlarmConfigParam; +import com.casic.service.AlarmService; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/alarm") +public class AlarmController { + + private final AlarmService alarmService; + + public AlarmController(AlarmService alarmService) { + this.alarmService = alarmService; + } + + @RequestMapping("/records") + public Object getAlarmRecord(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "devcode",required =false) String devcode, + @RequestParam(value = "pageSize", required = true) Integer pageSize) { + return alarmService.getAlarmRecord(deviceType,currentIndex,pageSize,devcode); + } + + @RequestMapping("/batch/cancel") + public Object excuteAlramBatchCancel(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "devcode",required =false) String devcode) { + return alarmService.excuteAlramBatchCancel(deviceType,devcode); + } + + @RequestMapping("/config/add") + public Object addAlarmConfig(@RequestBody AlarmConfigParam alarmConfigParam) { + return alarmService.addAlarmConfig(alarmConfigParam); + } +} diff --git a/src/main/java/com/casic/controller/DeviceDataController.java b/src/main/java/com/casic/controller/DeviceDataController.java new file mode 100644 index 0000000..3498b04 --- /dev/null +++ b/src/main/java/com/casic/controller/DeviceDataController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.service.DeviceDataService; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/device") +public class DeviceDataController { + private final DeviceDataService deviceDataService; + + public DeviceDataController(DeviceDataService deviceDataService) { + this.deviceDataService = deviceDataService; + } + + @RequestMapping("/recent-data") + public Object getDeviceRecentData(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "recentNum", required = true) String recentNum, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceRecentData(deviceType, recentNum, devcode); + } + + @RequestMapping("/data/list-page") + public Object getDeviceListPage(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "pageSize", required = true) Integer pageSize, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceListPage(deviceType, currentIndex, pageSize, devcode); + } + + @RequestMapping("/level/{deviceType}") + public Object getLevelList(@PathVariable("deviceType")String deviceType) { + return deviceDataService.getLevel(deviceType); + } + +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..50f4a19 --- /dev/null +++ b/pom.xml @@ -0,0 +1,161 @@ + + + 4.0.0 + + com.casic + smartwell-demos + 1.0-SNAPSHOT + + + + + jdk-1.8 + + true + 1.8 + + + 1.8 + 1.8 + 1.8 + + + + + + + + + + org.springframework.boot + spring-boot-starter + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-tomcat + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-web + 2.4.5 + + + + + org.springframework.boot + spring-boot-starter-jdbc + 2.4.5 + + + + mysql + mysql-connector-java + 8.0.16 + compile + + + + com.baomidou + mybatis-plus-boot-starter + 3.4.3 + + + + org.projectlombok + lombok + 1.18.20 + + + + + com.alibaba + druid + 1.2.6 + + + + com.alibaba + fastjson + 1.2.73 + + + + commons-codec + commons-codec + 1.14 + + + + redis.clients + jedis + 3.1.0 + jar + + + + org.springframework.data + spring-data-redis + 2.4.8 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.3.RELEASE + + true + + com.casic.CasicApplication + exec + + + + + repackage + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + false + + + + + + + + src/main/resources + + + /config/*/* + /config/*-*.yml + + true + + + src/main/resources + + **/*.xml + + true + + + + + \ No newline at end of file diff --git a/src/main/java/com/casic/CasicApplication.java b/src/main/java/com/casic/CasicApplication.java new file mode 100644 index 0000000..9afd0b9 --- /dev/null +++ b/src/main/java/com/casic/CasicApplication.java @@ -0,0 +1,28 @@ +package com.casic; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.transaction.annotation.EnableTransactionManagement; + + +/** + * SpringBoot方式启动类 + * + * @author cz + * @Date 2022/09/08 14:28 + */ + +@Slf4j +@ComponentScan(basePackages= "com.casic.**") +@SpringBootApplication +public class CasicApplication { + public static void main(String[] args) { + log.info("CasicApplication is success!"); + SpringApplication.run(CasicApplication.class, args); + } +} diff --git a/src/main/java/com/casic/config/CorsConfig.java b/src/main/java/com/casic/config/CorsConfig.java new file mode 100644 index 0000000..7d19680 --- /dev/null +++ b/src/main/java/com/casic/config/CorsConfig.java @@ -0,0 +1,31 @@ +package com.casic.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +/** + * 基础框架 - 跨域请求配置 + */ +@Configuration +public class CorsConfig { + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", buildConfig()); + return new CorsFilter(source); + } + + private CorsConfiguration buildConfig() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + // 1允许任何域名使用 + corsConfiguration.addAllowedOrigin("*"); + // 2允许任何头 + corsConfiguration.addAllowedHeader("*"); + // 3允许任何方法(post、get等) + corsConfiguration.addAllowedMethod("*"); + return corsConfiguration; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/controller/AlarmController.java b/src/main/java/com/casic/controller/AlarmController.java new file mode 100644 index 0000000..957fc36 --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.model.AlarmConfigParam; +import com.casic.service.AlarmService; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/alarm") +public class AlarmController { + + private final AlarmService alarmService; + + public AlarmController(AlarmService alarmService) { + this.alarmService = alarmService; + } + + @RequestMapping("/records") + public Object getAlarmRecord(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "devcode",required =false) String devcode, + @RequestParam(value = "pageSize", required = true) Integer pageSize) { + return alarmService.getAlarmRecord(deviceType,currentIndex,pageSize,devcode); + } + + @RequestMapping("/batch/cancel") + public Object excuteAlramBatchCancel(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "devcode",required =false) String devcode) { + return alarmService.excuteAlramBatchCancel(deviceType,devcode); + } + + @RequestMapping("/config/add") + public Object addAlarmConfig(@RequestBody AlarmConfigParam alarmConfigParam) { + return alarmService.addAlarmConfig(alarmConfigParam); + } +} diff --git a/src/main/java/com/casic/controller/DeviceDataController.java b/src/main/java/com/casic/controller/DeviceDataController.java new file mode 100644 index 0000000..3498b04 --- /dev/null +++ b/src/main/java/com/casic/controller/DeviceDataController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.service.DeviceDataService; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/device") +public class DeviceDataController { + private final DeviceDataService deviceDataService; + + public DeviceDataController(DeviceDataService deviceDataService) { + this.deviceDataService = deviceDataService; + } + + @RequestMapping("/recent-data") + public Object getDeviceRecentData(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "recentNum", required = true) String recentNum, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceRecentData(deviceType, recentNum, devcode); + } + + @RequestMapping("/data/list-page") + public Object getDeviceListPage(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "pageSize", required = true) Integer pageSize, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceListPage(deviceType, currentIndex, pageSize, devcode); + } + + @RequestMapping("/level/{deviceType}") + public Object getLevelList(@PathVariable("deviceType")String deviceType) { + return deviceDataService.getLevel(deviceType); + } + +} diff --git a/src/main/java/com/casic/controller/ThirdDataController.java b/src/main/java/com/casic/controller/ThirdDataController.java new file mode 100644 index 0000000..b9b2b42 --- /dev/null +++ b/src/main/java/com/casic/controller/ThirdDataController.java @@ -0,0 +1,28 @@ +package com.casic.controller; + +import com.casic.model.PressureDataParam; +import com.casic.service.ThirdDataService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +@RestController +@RequestMapping("/push") +@Slf4j +public class ThirdDataController { + + private final ThirdDataService thirdDataService; + + public ThirdDataController(ThirdDataService thirdDataService) { + this.thirdDataService = thirdDataService; + } + + @RequestMapping("/pressure/data") + public Object getDeviceRecentData(@RequestBody PressureDataParam pressureData) { + return thirdDataService.getDeviceRecentData(pressureData); + } + +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..50f4a19 --- /dev/null +++ b/pom.xml @@ -0,0 +1,161 @@ + + + 4.0.0 + + com.casic + smartwell-demos + 1.0-SNAPSHOT + + + + + jdk-1.8 + + true + 1.8 + + + 1.8 + 1.8 + 1.8 + + + + + + + + + + org.springframework.boot + spring-boot-starter + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-tomcat + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-web + 2.4.5 + + + + + org.springframework.boot + spring-boot-starter-jdbc + 2.4.5 + + + + mysql + mysql-connector-java + 8.0.16 + compile + + + + com.baomidou + mybatis-plus-boot-starter + 3.4.3 + + + + org.projectlombok + lombok + 1.18.20 + + + + + com.alibaba + druid + 1.2.6 + + + + com.alibaba + fastjson + 1.2.73 + + + + commons-codec + commons-codec + 1.14 + + + + redis.clients + jedis + 3.1.0 + jar + + + + org.springframework.data + spring-data-redis + 2.4.8 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.3.RELEASE + + true + + com.casic.CasicApplication + exec + + + + + repackage + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + false + + + + + + + + src/main/resources + + + /config/*/* + /config/*-*.yml + + true + + + src/main/resources + + **/*.xml + + true + + + + + \ No newline at end of file diff --git a/src/main/java/com/casic/CasicApplication.java b/src/main/java/com/casic/CasicApplication.java new file mode 100644 index 0000000..9afd0b9 --- /dev/null +++ b/src/main/java/com/casic/CasicApplication.java @@ -0,0 +1,28 @@ +package com.casic; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.transaction.annotation.EnableTransactionManagement; + + +/** + * SpringBoot方式启动类 + * + * @author cz + * @Date 2022/09/08 14:28 + */ + +@Slf4j +@ComponentScan(basePackages= "com.casic.**") +@SpringBootApplication +public class CasicApplication { + public static void main(String[] args) { + log.info("CasicApplication is success!"); + SpringApplication.run(CasicApplication.class, args); + } +} diff --git a/src/main/java/com/casic/config/CorsConfig.java b/src/main/java/com/casic/config/CorsConfig.java new file mode 100644 index 0000000..7d19680 --- /dev/null +++ b/src/main/java/com/casic/config/CorsConfig.java @@ -0,0 +1,31 @@ +package com.casic.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +/** + * 基础框架 - 跨域请求配置 + */ +@Configuration +public class CorsConfig { + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", buildConfig()); + return new CorsFilter(source); + } + + private CorsConfiguration buildConfig() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + // 1允许任何域名使用 + corsConfiguration.addAllowedOrigin("*"); + // 2允许任何头 + corsConfiguration.addAllowedHeader("*"); + // 3允许任何方法(post、get等) + corsConfiguration.addAllowedMethod("*"); + return corsConfiguration; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/controller/AlarmController.java b/src/main/java/com/casic/controller/AlarmController.java new file mode 100644 index 0000000..957fc36 --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.model.AlarmConfigParam; +import com.casic.service.AlarmService; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/alarm") +public class AlarmController { + + private final AlarmService alarmService; + + public AlarmController(AlarmService alarmService) { + this.alarmService = alarmService; + } + + @RequestMapping("/records") + public Object getAlarmRecord(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "devcode",required =false) String devcode, + @RequestParam(value = "pageSize", required = true) Integer pageSize) { + return alarmService.getAlarmRecord(deviceType,currentIndex,pageSize,devcode); + } + + @RequestMapping("/batch/cancel") + public Object excuteAlramBatchCancel(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "devcode",required =false) String devcode) { + return alarmService.excuteAlramBatchCancel(deviceType,devcode); + } + + @RequestMapping("/config/add") + public Object addAlarmConfig(@RequestBody AlarmConfigParam alarmConfigParam) { + return alarmService.addAlarmConfig(alarmConfigParam); + } +} diff --git a/src/main/java/com/casic/controller/DeviceDataController.java b/src/main/java/com/casic/controller/DeviceDataController.java new file mode 100644 index 0000000..3498b04 --- /dev/null +++ b/src/main/java/com/casic/controller/DeviceDataController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.service.DeviceDataService; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/device") +public class DeviceDataController { + private final DeviceDataService deviceDataService; + + public DeviceDataController(DeviceDataService deviceDataService) { + this.deviceDataService = deviceDataService; + } + + @RequestMapping("/recent-data") + public Object getDeviceRecentData(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "recentNum", required = true) String recentNum, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceRecentData(deviceType, recentNum, devcode); + } + + @RequestMapping("/data/list-page") + public Object getDeviceListPage(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "pageSize", required = true) Integer pageSize, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceListPage(deviceType, currentIndex, pageSize, devcode); + } + + @RequestMapping("/level/{deviceType}") + public Object getLevelList(@PathVariable("deviceType")String deviceType) { + return deviceDataService.getLevel(deviceType); + } + +} diff --git a/src/main/java/com/casic/controller/ThirdDataController.java b/src/main/java/com/casic/controller/ThirdDataController.java new file mode 100644 index 0000000..b9b2b42 --- /dev/null +++ b/src/main/java/com/casic/controller/ThirdDataController.java @@ -0,0 +1,28 @@ +package com.casic.controller; + +import com.casic.model.PressureDataParam; +import com.casic.service.ThirdDataService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +@RestController +@RequestMapping("/push") +@Slf4j +public class ThirdDataController { + + private final ThirdDataService thirdDataService; + + public ThirdDataController(ThirdDataService thirdDataService) { + this.thirdDataService = thirdDataService; + } + + @RequestMapping("/pressure/data") + public Object getDeviceRecentData(@RequestBody PressureDataParam pressureData) { + return thirdDataService.getDeviceRecentData(pressureData); + } + +} diff --git a/src/main/java/com/casic/dao/AlarmMapper.java b/src/main/java/com/casic/dao/AlarmMapper.java new file mode 100644 index 0000000..a442e3a --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmMapper.java @@ -0,0 +1,28 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmLevel; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + +@Mapper +public interface AlarmMapper extends BaseMapper { + + List> getAlarmRecord(@Param("deviceType") String deviceType, + @Param("devcode") String devcode, + @Param("currentIndex") Integer currentIndex, @Param("pageSize") Integer pageSize); + + Integer getAlarmTotalRecord(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteAlramBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteJobBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + String getDeviceDevcode(@Param("deviceType") String deviceType); + + String getDeviceByDevcode(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..50f4a19 --- /dev/null +++ b/pom.xml @@ -0,0 +1,161 @@ + + + 4.0.0 + + com.casic + smartwell-demos + 1.0-SNAPSHOT + + + + + jdk-1.8 + + true + 1.8 + + + 1.8 + 1.8 + 1.8 + + + + + + + + + + org.springframework.boot + spring-boot-starter + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-tomcat + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-web + 2.4.5 + + + + + org.springframework.boot + spring-boot-starter-jdbc + 2.4.5 + + + + mysql + mysql-connector-java + 8.0.16 + compile + + + + com.baomidou + mybatis-plus-boot-starter + 3.4.3 + + + + org.projectlombok + lombok + 1.18.20 + + + + + com.alibaba + druid + 1.2.6 + + + + com.alibaba + fastjson + 1.2.73 + + + + commons-codec + commons-codec + 1.14 + + + + redis.clients + jedis + 3.1.0 + jar + + + + org.springframework.data + spring-data-redis + 2.4.8 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.3.RELEASE + + true + + com.casic.CasicApplication + exec + + + + + repackage + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + false + + + + + + + + src/main/resources + + + /config/*/* + /config/*-*.yml + + true + + + src/main/resources + + **/*.xml + + true + + + + + \ No newline at end of file diff --git a/src/main/java/com/casic/CasicApplication.java b/src/main/java/com/casic/CasicApplication.java new file mode 100644 index 0000000..9afd0b9 --- /dev/null +++ b/src/main/java/com/casic/CasicApplication.java @@ -0,0 +1,28 @@ +package com.casic; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.transaction.annotation.EnableTransactionManagement; + + +/** + * SpringBoot方式启动类 + * + * @author cz + * @Date 2022/09/08 14:28 + */ + +@Slf4j +@ComponentScan(basePackages= "com.casic.**") +@SpringBootApplication +public class CasicApplication { + public static void main(String[] args) { + log.info("CasicApplication is success!"); + SpringApplication.run(CasicApplication.class, args); + } +} diff --git a/src/main/java/com/casic/config/CorsConfig.java b/src/main/java/com/casic/config/CorsConfig.java new file mode 100644 index 0000000..7d19680 --- /dev/null +++ b/src/main/java/com/casic/config/CorsConfig.java @@ -0,0 +1,31 @@ +package com.casic.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +/** + * 基础框架 - 跨域请求配置 + */ +@Configuration +public class CorsConfig { + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", buildConfig()); + return new CorsFilter(source); + } + + private CorsConfiguration buildConfig() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + // 1允许任何域名使用 + corsConfiguration.addAllowedOrigin("*"); + // 2允许任何头 + corsConfiguration.addAllowedHeader("*"); + // 3允许任何方法(post、get等) + corsConfiguration.addAllowedMethod("*"); + return corsConfiguration; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/controller/AlarmController.java b/src/main/java/com/casic/controller/AlarmController.java new file mode 100644 index 0000000..957fc36 --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.model.AlarmConfigParam; +import com.casic.service.AlarmService; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/alarm") +public class AlarmController { + + private final AlarmService alarmService; + + public AlarmController(AlarmService alarmService) { + this.alarmService = alarmService; + } + + @RequestMapping("/records") + public Object getAlarmRecord(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "devcode",required =false) String devcode, + @RequestParam(value = "pageSize", required = true) Integer pageSize) { + return alarmService.getAlarmRecord(deviceType,currentIndex,pageSize,devcode); + } + + @RequestMapping("/batch/cancel") + public Object excuteAlramBatchCancel(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "devcode",required =false) String devcode) { + return alarmService.excuteAlramBatchCancel(deviceType,devcode); + } + + @RequestMapping("/config/add") + public Object addAlarmConfig(@RequestBody AlarmConfigParam alarmConfigParam) { + return alarmService.addAlarmConfig(alarmConfigParam); + } +} diff --git a/src/main/java/com/casic/controller/DeviceDataController.java b/src/main/java/com/casic/controller/DeviceDataController.java new file mode 100644 index 0000000..3498b04 --- /dev/null +++ b/src/main/java/com/casic/controller/DeviceDataController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.service.DeviceDataService; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/device") +public class DeviceDataController { + private final DeviceDataService deviceDataService; + + public DeviceDataController(DeviceDataService deviceDataService) { + this.deviceDataService = deviceDataService; + } + + @RequestMapping("/recent-data") + public Object getDeviceRecentData(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "recentNum", required = true) String recentNum, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceRecentData(deviceType, recentNum, devcode); + } + + @RequestMapping("/data/list-page") + public Object getDeviceListPage(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "pageSize", required = true) Integer pageSize, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceListPage(deviceType, currentIndex, pageSize, devcode); + } + + @RequestMapping("/level/{deviceType}") + public Object getLevelList(@PathVariable("deviceType")String deviceType) { + return deviceDataService.getLevel(deviceType); + } + +} diff --git a/src/main/java/com/casic/controller/ThirdDataController.java b/src/main/java/com/casic/controller/ThirdDataController.java new file mode 100644 index 0000000..b9b2b42 --- /dev/null +++ b/src/main/java/com/casic/controller/ThirdDataController.java @@ -0,0 +1,28 @@ +package com.casic.controller; + +import com.casic.model.PressureDataParam; +import com.casic.service.ThirdDataService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +@RestController +@RequestMapping("/push") +@Slf4j +public class ThirdDataController { + + private final ThirdDataService thirdDataService; + + public ThirdDataController(ThirdDataService thirdDataService) { + this.thirdDataService = thirdDataService; + } + + @RequestMapping("/pressure/data") + public Object getDeviceRecentData(@RequestBody PressureDataParam pressureData) { + return thirdDataService.getDeviceRecentData(pressureData); + } + +} diff --git a/src/main/java/com/casic/dao/AlarmMapper.java b/src/main/java/com/casic/dao/AlarmMapper.java new file mode 100644 index 0000000..a442e3a --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmMapper.java @@ -0,0 +1,28 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmLevel; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + +@Mapper +public interface AlarmMapper extends BaseMapper { + + List> getAlarmRecord(@Param("deviceType") String deviceType, + @Param("devcode") String devcode, + @Param("currentIndex") Integer currentIndex, @Param("pageSize") Integer pageSize); + + Integer getAlarmTotalRecord(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteAlramBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteJobBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + String getDeviceDevcode(@Param("deviceType") String deviceType); + + String getDeviceByDevcode(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + +} diff --git a/src/main/java/com/casic/dao/BusConfigMapper.java b/src/main/java/com/casic/dao/BusConfigMapper.java new file mode 100644 index 0000000..ccf76da --- /dev/null +++ b/src/main/java/com/casic/dao/BusConfigMapper.java @@ -0,0 +1,9 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.BusConfig; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface BusConfigMapper extends BaseMapper { +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..50f4a19 --- /dev/null +++ b/pom.xml @@ -0,0 +1,161 @@ + + + 4.0.0 + + com.casic + smartwell-demos + 1.0-SNAPSHOT + + + + + jdk-1.8 + + true + 1.8 + + + 1.8 + 1.8 + 1.8 + + + + + + + + + + org.springframework.boot + spring-boot-starter + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-tomcat + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-web + 2.4.5 + + + + + org.springframework.boot + spring-boot-starter-jdbc + 2.4.5 + + + + mysql + mysql-connector-java + 8.0.16 + compile + + + + com.baomidou + mybatis-plus-boot-starter + 3.4.3 + + + + org.projectlombok + lombok + 1.18.20 + + + + + com.alibaba + druid + 1.2.6 + + + + com.alibaba + fastjson + 1.2.73 + + + + commons-codec + commons-codec + 1.14 + + + + redis.clients + jedis + 3.1.0 + jar + + + + org.springframework.data + spring-data-redis + 2.4.8 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.3.RELEASE + + true + + com.casic.CasicApplication + exec + + + + + repackage + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + false + + + + + + + + src/main/resources + + + /config/*/* + /config/*-*.yml + + true + + + src/main/resources + + **/*.xml + + true + + + + + \ No newline at end of file diff --git a/src/main/java/com/casic/CasicApplication.java b/src/main/java/com/casic/CasicApplication.java new file mode 100644 index 0000000..9afd0b9 --- /dev/null +++ b/src/main/java/com/casic/CasicApplication.java @@ -0,0 +1,28 @@ +package com.casic; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.transaction.annotation.EnableTransactionManagement; + + +/** + * SpringBoot方式启动类 + * + * @author cz + * @Date 2022/09/08 14:28 + */ + +@Slf4j +@ComponentScan(basePackages= "com.casic.**") +@SpringBootApplication +public class CasicApplication { + public static void main(String[] args) { + log.info("CasicApplication is success!"); + SpringApplication.run(CasicApplication.class, args); + } +} diff --git a/src/main/java/com/casic/config/CorsConfig.java b/src/main/java/com/casic/config/CorsConfig.java new file mode 100644 index 0000000..7d19680 --- /dev/null +++ b/src/main/java/com/casic/config/CorsConfig.java @@ -0,0 +1,31 @@ +package com.casic.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +/** + * 基础框架 - 跨域请求配置 + */ +@Configuration +public class CorsConfig { + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", buildConfig()); + return new CorsFilter(source); + } + + private CorsConfiguration buildConfig() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + // 1允许任何域名使用 + corsConfiguration.addAllowedOrigin("*"); + // 2允许任何头 + corsConfiguration.addAllowedHeader("*"); + // 3允许任何方法(post、get等) + corsConfiguration.addAllowedMethod("*"); + return corsConfiguration; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/controller/AlarmController.java b/src/main/java/com/casic/controller/AlarmController.java new file mode 100644 index 0000000..957fc36 --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.model.AlarmConfigParam; +import com.casic.service.AlarmService; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/alarm") +public class AlarmController { + + private final AlarmService alarmService; + + public AlarmController(AlarmService alarmService) { + this.alarmService = alarmService; + } + + @RequestMapping("/records") + public Object getAlarmRecord(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "devcode",required =false) String devcode, + @RequestParam(value = "pageSize", required = true) Integer pageSize) { + return alarmService.getAlarmRecord(deviceType,currentIndex,pageSize,devcode); + } + + @RequestMapping("/batch/cancel") + public Object excuteAlramBatchCancel(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "devcode",required =false) String devcode) { + return alarmService.excuteAlramBatchCancel(deviceType,devcode); + } + + @RequestMapping("/config/add") + public Object addAlarmConfig(@RequestBody AlarmConfigParam alarmConfigParam) { + return alarmService.addAlarmConfig(alarmConfigParam); + } +} diff --git a/src/main/java/com/casic/controller/DeviceDataController.java b/src/main/java/com/casic/controller/DeviceDataController.java new file mode 100644 index 0000000..3498b04 --- /dev/null +++ b/src/main/java/com/casic/controller/DeviceDataController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.service.DeviceDataService; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/device") +public class DeviceDataController { + private final DeviceDataService deviceDataService; + + public DeviceDataController(DeviceDataService deviceDataService) { + this.deviceDataService = deviceDataService; + } + + @RequestMapping("/recent-data") + public Object getDeviceRecentData(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "recentNum", required = true) String recentNum, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceRecentData(deviceType, recentNum, devcode); + } + + @RequestMapping("/data/list-page") + public Object getDeviceListPage(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "pageSize", required = true) Integer pageSize, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceListPage(deviceType, currentIndex, pageSize, devcode); + } + + @RequestMapping("/level/{deviceType}") + public Object getLevelList(@PathVariable("deviceType")String deviceType) { + return deviceDataService.getLevel(deviceType); + } + +} diff --git a/src/main/java/com/casic/controller/ThirdDataController.java b/src/main/java/com/casic/controller/ThirdDataController.java new file mode 100644 index 0000000..b9b2b42 --- /dev/null +++ b/src/main/java/com/casic/controller/ThirdDataController.java @@ -0,0 +1,28 @@ +package com.casic.controller; + +import com.casic.model.PressureDataParam; +import com.casic.service.ThirdDataService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +@RestController +@RequestMapping("/push") +@Slf4j +public class ThirdDataController { + + private final ThirdDataService thirdDataService; + + public ThirdDataController(ThirdDataService thirdDataService) { + this.thirdDataService = thirdDataService; + } + + @RequestMapping("/pressure/data") + public Object getDeviceRecentData(@RequestBody PressureDataParam pressureData) { + return thirdDataService.getDeviceRecentData(pressureData); + } + +} diff --git a/src/main/java/com/casic/dao/AlarmMapper.java b/src/main/java/com/casic/dao/AlarmMapper.java new file mode 100644 index 0000000..a442e3a --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmMapper.java @@ -0,0 +1,28 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmLevel; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + +@Mapper +public interface AlarmMapper extends BaseMapper { + + List> getAlarmRecord(@Param("deviceType") String deviceType, + @Param("devcode") String devcode, + @Param("currentIndex") Integer currentIndex, @Param("pageSize") Integer pageSize); + + Integer getAlarmTotalRecord(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteAlramBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteJobBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + String getDeviceDevcode(@Param("deviceType") String deviceType); + + String getDeviceByDevcode(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + +} diff --git a/src/main/java/com/casic/dao/BusConfigMapper.java b/src/main/java/com/casic/dao/BusConfigMapper.java new file mode 100644 index 0000000..ccf76da --- /dev/null +++ b/src/main/java/com/casic/dao/BusConfigMapper.java @@ -0,0 +1,9 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.BusConfig; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface BusConfigMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/dao/DataPressureMapper.java b/src/main/java/com/casic/dao/DataPressureMapper.java new file mode 100644 index 0000000..05f4329 --- /dev/null +++ b/src/main/java/com/casic/dao/DataPressureMapper.java @@ -0,0 +1,19 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.DataPressure; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.Date; + +@Mapper +public interface DataPressureMapper extends BaseMapper { + + String getWellCode(@Param("devcode") String devcode); + + Float getRuleValue(@Param("deviceType") String deviceType); + + void saveRecords(@Param("reValue") String reValue, @Param("alarmTime") Date alarmTime); + +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..50f4a19 --- /dev/null +++ b/pom.xml @@ -0,0 +1,161 @@ + + + 4.0.0 + + com.casic + smartwell-demos + 1.0-SNAPSHOT + + + + + jdk-1.8 + + true + 1.8 + + + 1.8 + 1.8 + 1.8 + + + + + + + + + + org.springframework.boot + spring-boot-starter + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-tomcat + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-web + 2.4.5 + + + + + org.springframework.boot + spring-boot-starter-jdbc + 2.4.5 + + + + mysql + mysql-connector-java + 8.0.16 + compile + + + + com.baomidou + mybatis-plus-boot-starter + 3.4.3 + + + + org.projectlombok + lombok + 1.18.20 + + + + + com.alibaba + druid + 1.2.6 + + + + com.alibaba + fastjson + 1.2.73 + + + + commons-codec + commons-codec + 1.14 + + + + redis.clients + jedis + 3.1.0 + jar + + + + org.springframework.data + spring-data-redis + 2.4.8 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.3.RELEASE + + true + + com.casic.CasicApplication + exec + + + + + repackage + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + false + + + + + + + + src/main/resources + + + /config/*/* + /config/*-*.yml + + true + + + src/main/resources + + **/*.xml + + true + + + + + \ No newline at end of file diff --git a/src/main/java/com/casic/CasicApplication.java b/src/main/java/com/casic/CasicApplication.java new file mode 100644 index 0000000..9afd0b9 --- /dev/null +++ b/src/main/java/com/casic/CasicApplication.java @@ -0,0 +1,28 @@ +package com.casic; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.transaction.annotation.EnableTransactionManagement; + + +/** + * SpringBoot方式启动类 + * + * @author cz + * @Date 2022/09/08 14:28 + */ + +@Slf4j +@ComponentScan(basePackages= "com.casic.**") +@SpringBootApplication +public class CasicApplication { + public static void main(String[] args) { + log.info("CasicApplication is success!"); + SpringApplication.run(CasicApplication.class, args); + } +} diff --git a/src/main/java/com/casic/config/CorsConfig.java b/src/main/java/com/casic/config/CorsConfig.java new file mode 100644 index 0000000..7d19680 --- /dev/null +++ b/src/main/java/com/casic/config/CorsConfig.java @@ -0,0 +1,31 @@ +package com.casic.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +/** + * 基础框架 - 跨域请求配置 + */ +@Configuration +public class CorsConfig { + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", buildConfig()); + return new CorsFilter(source); + } + + private CorsConfiguration buildConfig() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + // 1允许任何域名使用 + corsConfiguration.addAllowedOrigin("*"); + // 2允许任何头 + corsConfiguration.addAllowedHeader("*"); + // 3允许任何方法(post、get等) + corsConfiguration.addAllowedMethod("*"); + return corsConfiguration; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/controller/AlarmController.java b/src/main/java/com/casic/controller/AlarmController.java new file mode 100644 index 0000000..957fc36 --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.model.AlarmConfigParam; +import com.casic.service.AlarmService; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/alarm") +public class AlarmController { + + private final AlarmService alarmService; + + public AlarmController(AlarmService alarmService) { + this.alarmService = alarmService; + } + + @RequestMapping("/records") + public Object getAlarmRecord(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "devcode",required =false) String devcode, + @RequestParam(value = "pageSize", required = true) Integer pageSize) { + return alarmService.getAlarmRecord(deviceType,currentIndex,pageSize,devcode); + } + + @RequestMapping("/batch/cancel") + public Object excuteAlramBatchCancel(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "devcode",required =false) String devcode) { + return alarmService.excuteAlramBatchCancel(deviceType,devcode); + } + + @RequestMapping("/config/add") + public Object addAlarmConfig(@RequestBody AlarmConfigParam alarmConfigParam) { + return alarmService.addAlarmConfig(alarmConfigParam); + } +} diff --git a/src/main/java/com/casic/controller/DeviceDataController.java b/src/main/java/com/casic/controller/DeviceDataController.java new file mode 100644 index 0000000..3498b04 --- /dev/null +++ b/src/main/java/com/casic/controller/DeviceDataController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.service.DeviceDataService; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/device") +public class DeviceDataController { + private final DeviceDataService deviceDataService; + + public DeviceDataController(DeviceDataService deviceDataService) { + this.deviceDataService = deviceDataService; + } + + @RequestMapping("/recent-data") + public Object getDeviceRecentData(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "recentNum", required = true) String recentNum, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceRecentData(deviceType, recentNum, devcode); + } + + @RequestMapping("/data/list-page") + public Object getDeviceListPage(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "pageSize", required = true) Integer pageSize, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceListPage(deviceType, currentIndex, pageSize, devcode); + } + + @RequestMapping("/level/{deviceType}") + public Object getLevelList(@PathVariable("deviceType")String deviceType) { + return deviceDataService.getLevel(deviceType); + } + +} diff --git a/src/main/java/com/casic/controller/ThirdDataController.java b/src/main/java/com/casic/controller/ThirdDataController.java new file mode 100644 index 0000000..b9b2b42 --- /dev/null +++ b/src/main/java/com/casic/controller/ThirdDataController.java @@ -0,0 +1,28 @@ +package com.casic.controller; + +import com.casic.model.PressureDataParam; +import com.casic.service.ThirdDataService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +@RestController +@RequestMapping("/push") +@Slf4j +public class ThirdDataController { + + private final ThirdDataService thirdDataService; + + public ThirdDataController(ThirdDataService thirdDataService) { + this.thirdDataService = thirdDataService; + } + + @RequestMapping("/pressure/data") + public Object getDeviceRecentData(@RequestBody PressureDataParam pressureData) { + return thirdDataService.getDeviceRecentData(pressureData); + } + +} diff --git a/src/main/java/com/casic/dao/AlarmMapper.java b/src/main/java/com/casic/dao/AlarmMapper.java new file mode 100644 index 0000000..a442e3a --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmMapper.java @@ -0,0 +1,28 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmLevel; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + +@Mapper +public interface AlarmMapper extends BaseMapper { + + List> getAlarmRecord(@Param("deviceType") String deviceType, + @Param("devcode") String devcode, + @Param("currentIndex") Integer currentIndex, @Param("pageSize") Integer pageSize); + + Integer getAlarmTotalRecord(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteAlramBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteJobBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + String getDeviceDevcode(@Param("deviceType") String deviceType); + + String getDeviceByDevcode(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + +} diff --git a/src/main/java/com/casic/dao/BusConfigMapper.java b/src/main/java/com/casic/dao/BusConfigMapper.java new file mode 100644 index 0000000..ccf76da --- /dev/null +++ b/src/main/java/com/casic/dao/BusConfigMapper.java @@ -0,0 +1,9 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.BusConfig; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface BusConfigMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/dao/DataPressureMapper.java b/src/main/java/com/casic/dao/DataPressureMapper.java new file mode 100644 index 0000000..05f4329 --- /dev/null +++ b/src/main/java/com/casic/dao/DataPressureMapper.java @@ -0,0 +1,19 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.DataPressure; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.Date; + +@Mapper +public interface DataPressureMapper extends BaseMapper { + + String getWellCode(@Param("devcode") String devcode); + + Float getRuleValue(@Param("deviceType") String deviceType); + + void saveRecords(@Param("reValue") String reValue, @Param("alarmTime") Date alarmTime); + +} diff --git a/src/main/java/com/casic/dao/DeviceDataMapper.java b/src/main/java/com/casic/dao/DeviceDataMapper.java new file mode 100644 index 0000000..d9e18a0 --- /dev/null +++ b/src/main/java/com/casic/dao/DeviceDataMapper.java @@ -0,0 +1,27 @@ +package com.casic.dao; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + + +@Mapper +public interface DeviceDataMapper { + + List> getDeviceRecentData(@Param("tableName") String tableName, + @Param("recentNum") String recentNum, + @Param("fields") String fields, + @Param("devcode") String devcode); + + Integer getDeviceDataTotal(@Param("tableName") String tableName, @Param("devcode") String devcode); + + List> getDeviceDataListPage(@Param("tableName") String tableName, + @Param("currentIndex") Integer currentIndex, + @Param("fields") String fields, + @Param("pageSize") Integer pageSize, + @Param("devcode") String devcode); + + String getLevelByType(@Param("deviceType")String deviceType); +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..50f4a19 --- /dev/null +++ b/pom.xml @@ -0,0 +1,161 @@ + + + 4.0.0 + + com.casic + smartwell-demos + 1.0-SNAPSHOT + + + + + jdk-1.8 + + true + 1.8 + + + 1.8 + 1.8 + 1.8 + + + + + + + + + + org.springframework.boot + spring-boot-starter + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-tomcat + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-web + 2.4.5 + + + + + org.springframework.boot + spring-boot-starter-jdbc + 2.4.5 + + + + mysql + mysql-connector-java + 8.0.16 + compile + + + + com.baomidou + mybatis-plus-boot-starter + 3.4.3 + + + + org.projectlombok + lombok + 1.18.20 + + + + + com.alibaba + druid + 1.2.6 + + + + com.alibaba + fastjson + 1.2.73 + + + + commons-codec + commons-codec + 1.14 + + + + redis.clients + jedis + 3.1.0 + jar + + + + org.springframework.data + spring-data-redis + 2.4.8 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.3.RELEASE + + true + + com.casic.CasicApplication + exec + + + + + repackage + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + false + + + + + + + + src/main/resources + + + /config/*/* + /config/*-*.yml + + true + + + src/main/resources + + **/*.xml + + true + + + + + \ No newline at end of file diff --git a/src/main/java/com/casic/CasicApplication.java b/src/main/java/com/casic/CasicApplication.java new file mode 100644 index 0000000..9afd0b9 --- /dev/null +++ b/src/main/java/com/casic/CasicApplication.java @@ -0,0 +1,28 @@ +package com.casic; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.transaction.annotation.EnableTransactionManagement; + + +/** + * SpringBoot方式启动类 + * + * @author cz + * @Date 2022/09/08 14:28 + */ + +@Slf4j +@ComponentScan(basePackages= "com.casic.**") +@SpringBootApplication +public class CasicApplication { + public static void main(String[] args) { + log.info("CasicApplication is success!"); + SpringApplication.run(CasicApplication.class, args); + } +} diff --git a/src/main/java/com/casic/config/CorsConfig.java b/src/main/java/com/casic/config/CorsConfig.java new file mode 100644 index 0000000..7d19680 --- /dev/null +++ b/src/main/java/com/casic/config/CorsConfig.java @@ -0,0 +1,31 @@ +package com.casic.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +/** + * 基础框架 - 跨域请求配置 + */ +@Configuration +public class CorsConfig { + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", buildConfig()); + return new CorsFilter(source); + } + + private CorsConfiguration buildConfig() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + // 1允许任何域名使用 + corsConfiguration.addAllowedOrigin("*"); + // 2允许任何头 + corsConfiguration.addAllowedHeader("*"); + // 3允许任何方法(post、get等) + corsConfiguration.addAllowedMethod("*"); + return corsConfiguration; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/controller/AlarmController.java b/src/main/java/com/casic/controller/AlarmController.java new file mode 100644 index 0000000..957fc36 --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.model.AlarmConfigParam; +import com.casic.service.AlarmService; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/alarm") +public class AlarmController { + + private final AlarmService alarmService; + + public AlarmController(AlarmService alarmService) { + this.alarmService = alarmService; + } + + @RequestMapping("/records") + public Object getAlarmRecord(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "devcode",required =false) String devcode, + @RequestParam(value = "pageSize", required = true) Integer pageSize) { + return alarmService.getAlarmRecord(deviceType,currentIndex,pageSize,devcode); + } + + @RequestMapping("/batch/cancel") + public Object excuteAlramBatchCancel(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "devcode",required =false) String devcode) { + return alarmService.excuteAlramBatchCancel(deviceType,devcode); + } + + @RequestMapping("/config/add") + public Object addAlarmConfig(@RequestBody AlarmConfigParam alarmConfigParam) { + return alarmService.addAlarmConfig(alarmConfigParam); + } +} diff --git a/src/main/java/com/casic/controller/DeviceDataController.java b/src/main/java/com/casic/controller/DeviceDataController.java new file mode 100644 index 0000000..3498b04 --- /dev/null +++ b/src/main/java/com/casic/controller/DeviceDataController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.service.DeviceDataService; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/device") +public class DeviceDataController { + private final DeviceDataService deviceDataService; + + public DeviceDataController(DeviceDataService deviceDataService) { + this.deviceDataService = deviceDataService; + } + + @RequestMapping("/recent-data") + public Object getDeviceRecentData(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "recentNum", required = true) String recentNum, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceRecentData(deviceType, recentNum, devcode); + } + + @RequestMapping("/data/list-page") + public Object getDeviceListPage(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "pageSize", required = true) Integer pageSize, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceListPage(deviceType, currentIndex, pageSize, devcode); + } + + @RequestMapping("/level/{deviceType}") + public Object getLevelList(@PathVariable("deviceType")String deviceType) { + return deviceDataService.getLevel(deviceType); + } + +} diff --git a/src/main/java/com/casic/controller/ThirdDataController.java b/src/main/java/com/casic/controller/ThirdDataController.java new file mode 100644 index 0000000..b9b2b42 --- /dev/null +++ b/src/main/java/com/casic/controller/ThirdDataController.java @@ -0,0 +1,28 @@ +package com.casic.controller; + +import com.casic.model.PressureDataParam; +import com.casic.service.ThirdDataService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +@RestController +@RequestMapping("/push") +@Slf4j +public class ThirdDataController { + + private final ThirdDataService thirdDataService; + + public ThirdDataController(ThirdDataService thirdDataService) { + this.thirdDataService = thirdDataService; + } + + @RequestMapping("/pressure/data") + public Object getDeviceRecentData(@RequestBody PressureDataParam pressureData) { + return thirdDataService.getDeviceRecentData(pressureData); + } + +} diff --git a/src/main/java/com/casic/dao/AlarmMapper.java b/src/main/java/com/casic/dao/AlarmMapper.java new file mode 100644 index 0000000..a442e3a --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmMapper.java @@ -0,0 +1,28 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmLevel; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + +@Mapper +public interface AlarmMapper extends BaseMapper { + + List> getAlarmRecord(@Param("deviceType") String deviceType, + @Param("devcode") String devcode, + @Param("currentIndex") Integer currentIndex, @Param("pageSize") Integer pageSize); + + Integer getAlarmTotalRecord(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteAlramBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteJobBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + String getDeviceDevcode(@Param("deviceType") String deviceType); + + String getDeviceByDevcode(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + +} diff --git a/src/main/java/com/casic/dao/BusConfigMapper.java b/src/main/java/com/casic/dao/BusConfigMapper.java new file mode 100644 index 0000000..ccf76da --- /dev/null +++ b/src/main/java/com/casic/dao/BusConfigMapper.java @@ -0,0 +1,9 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.BusConfig; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface BusConfigMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/dao/DataPressureMapper.java b/src/main/java/com/casic/dao/DataPressureMapper.java new file mode 100644 index 0000000..05f4329 --- /dev/null +++ b/src/main/java/com/casic/dao/DataPressureMapper.java @@ -0,0 +1,19 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.DataPressure; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.Date; + +@Mapper +public interface DataPressureMapper extends BaseMapper { + + String getWellCode(@Param("devcode") String devcode); + + Float getRuleValue(@Param("deviceType") String deviceType); + + void saveRecords(@Param("reValue") String reValue, @Param("alarmTime") Date alarmTime); + +} diff --git a/src/main/java/com/casic/dao/DeviceDataMapper.java b/src/main/java/com/casic/dao/DeviceDataMapper.java new file mode 100644 index 0000000..d9e18a0 --- /dev/null +++ b/src/main/java/com/casic/dao/DeviceDataMapper.java @@ -0,0 +1,27 @@ +package com.casic.dao; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + + +@Mapper +public interface DeviceDataMapper { + + List> getDeviceRecentData(@Param("tableName") String tableName, + @Param("recentNum") String recentNum, + @Param("fields") String fields, + @Param("devcode") String devcode); + + Integer getDeviceDataTotal(@Param("tableName") String tableName, @Param("devcode") String devcode); + + List> getDeviceDataListPage(@Param("tableName") String tableName, + @Param("currentIndex") Integer currentIndex, + @Param("fields") String fields, + @Param("pageSize") Integer pageSize, + @Param("devcode") String devcode); + + String getLevelByType(@Param("deviceType")String deviceType); +} diff --git a/src/main/java/com/casic/model/AlarmConfigParam.java b/src/main/java/com/casic/model/AlarmConfigParam.java new file mode 100644 index 0000000..28150d6 --- /dev/null +++ b/src/main/java/com/casic/model/AlarmConfigParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class AlarmConfigParam { + private String deviceType; + private String thresholdVol; + private String collectInterval; + private String uploadCycle; + private String retryNum; + private String ip; + private String port; + private String devcode; +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..50f4a19 --- /dev/null +++ b/pom.xml @@ -0,0 +1,161 @@ + + + 4.0.0 + + com.casic + smartwell-demos + 1.0-SNAPSHOT + + + + + jdk-1.8 + + true + 1.8 + + + 1.8 + 1.8 + 1.8 + + + + + + + + + + org.springframework.boot + spring-boot-starter + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-tomcat + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-web + 2.4.5 + + + + + org.springframework.boot + spring-boot-starter-jdbc + 2.4.5 + + + + mysql + mysql-connector-java + 8.0.16 + compile + + + + com.baomidou + mybatis-plus-boot-starter + 3.4.3 + + + + org.projectlombok + lombok + 1.18.20 + + + + + com.alibaba + druid + 1.2.6 + + + + com.alibaba + fastjson + 1.2.73 + + + + commons-codec + commons-codec + 1.14 + + + + redis.clients + jedis + 3.1.0 + jar + + + + org.springframework.data + spring-data-redis + 2.4.8 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.3.RELEASE + + true + + com.casic.CasicApplication + exec + + + + + repackage + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + false + + + + + + + + src/main/resources + + + /config/*/* + /config/*-*.yml + + true + + + src/main/resources + + **/*.xml + + true + + + + + \ No newline at end of file diff --git a/src/main/java/com/casic/CasicApplication.java b/src/main/java/com/casic/CasicApplication.java new file mode 100644 index 0000000..9afd0b9 --- /dev/null +++ b/src/main/java/com/casic/CasicApplication.java @@ -0,0 +1,28 @@ +package com.casic; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.transaction.annotation.EnableTransactionManagement; + + +/** + * SpringBoot方式启动类 + * + * @author cz + * @Date 2022/09/08 14:28 + */ + +@Slf4j +@ComponentScan(basePackages= "com.casic.**") +@SpringBootApplication +public class CasicApplication { + public static void main(String[] args) { + log.info("CasicApplication is success!"); + SpringApplication.run(CasicApplication.class, args); + } +} diff --git a/src/main/java/com/casic/config/CorsConfig.java b/src/main/java/com/casic/config/CorsConfig.java new file mode 100644 index 0000000..7d19680 --- /dev/null +++ b/src/main/java/com/casic/config/CorsConfig.java @@ -0,0 +1,31 @@ +package com.casic.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +/** + * 基础框架 - 跨域请求配置 + */ +@Configuration +public class CorsConfig { + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", buildConfig()); + return new CorsFilter(source); + } + + private CorsConfiguration buildConfig() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + // 1允许任何域名使用 + corsConfiguration.addAllowedOrigin("*"); + // 2允许任何头 + corsConfiguration.addAllowedHeader("*"); + // 3允许任何方法(post、get等) + corsConfiguration.addAllowedMethod("*"); + return corsConfiguration; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/controller/AlarmController.java b/src/main/java/com/casic/controller/AlarmController.java new file mode 100644 index 0000000..957fc36 --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.model.AlarmConfigParam; +import com.casic.service.AlarmService; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/alarm") +public class AlarmController { + + private final AlarmService alarmService; + + public AlarmController(AlarmService alarmService) { + this.alarmService = alarmService; + } + + @RequestMapping("/records") + public Object getAlarmRecord(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "devcode",required =false) String devcode, + @RequestParam(value = "pageSize", required = true) Integer pageSize) { + return alarmService.getAlarmRecord(deviceType,currentIndex,pageSize,devcode); + } + + @RequestMapping("/batch/cancel") + public Object excuteAlramBatchCancel(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "devcode",required =false) String devcode) { + return alarmService.excuteAlramBatchCancel(deviceType,devcode); + } + + @RequestMapping("/config/add") + public Object addAlarmConfig(@RequestBody AlarmConfigParam alarmConfigParam) { + return alarmService.addAlarmConfig(alarmConfigParam); + } +} diff --git a/src/main/java/com/casic/controller/DeviceDataController.java b/src/main/java/com/casic/controller/DeviceDataController.java new file mode 100644 index 0000000..3498b04 --- /dev/null +++ b/src/main/java/com/casic/controller/DeviceDataController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.service.DeviceDataService; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/device") +public class DeviceDataController { + private final DeviceDataService deviceDataService; + + public DeviceDataController(DeviceDataService deviceDataService) { + this.deviceDataService = deviceDataService; + } + + @RequestMapping("/recent-data") + public Object getDeviceRecentData(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "recentNum", required = true) String recentNum, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceRecentData(deviceType, recentNum, devcode); + } + + @RequestMapping("/data/list-page") + public Object getDeviceListPage(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "pageSize", required = true) Integer pageSize, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceListPage(deviceType, currentIndex, pageSize, devcode); + } + + @RequestMapping("/level/{deviceType}") + public Object getLevelList(@PathVariable("deviceType")String deviceType) { + return deviceDataService.getLevel(deviceType); + } + +} diff --git a/src/main/java/com/casic/controller/ThirdDataController.java b/src/main/java/com/casic/controller/ThirdDataController.java new file mode 100644 index 0000000..b9b2b42 --- /dev/null +++ b/src/main/java/com/casic/controller/ThirdDataController.java @@ -0,0 +1,28 @@ +package com.casic.controller; + +import com.casic.model.PressureDataParam; +import com.casic.service.ThirdDataService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +@RestController +@RequestMapping("/push") +@Slf4j +public class ThirdDataController { + + private final ThirdDataService thirdDataService; + + public ThirdDataController(ThirdDataService thirdDataService) { + this.thirdDataService = thirdDataService; + } + + @RequestMapping("/pressure/data") + public Object getDeviceRecentData(@RequestBody PressureDataParam pressureData) { + return thirdDataService.getDeviceRecentData(pressureData); + } + +} diff --git a/src/main/java/com/casic/dao/AlarmMapper.java b/src/main/java/com/casic/dao/AlarmMapper.java new file mode 100644 index 0000000..a442e3a --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmMapper.java @@ -0,0 +1,28 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmLevel; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + +@Mapper +public interface AlarmMapper extends BaseMapper { + + List> getAlarmRecord(@Param("deviceType") String deviceType, + @Param("devcode") String devcode, + @Param("currentIndex") Integer currentIndex, @Param("pageSize") Integer pageSize); + + Integer getAlarmTotalRecord(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteAlramBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteJobBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + String getDeviceDevcode(@Param("deviceType") String deviceType); + + String getDeviceByDevcode(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + +} diff --git a/src/main/java/com/casic/dao/BusConfigMapper.java b/src/main/java/com/casic/dao/BusConfigMapper.java new file mode 100644 index 0000000..ccf76da --- /dev/null +++ b/src/main/java/com/casic/dao/BusConfigMapper.java @@ -0,0 +1,9 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.BusConfig; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface BusConfigMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/dao/DataPressureMapper.java b/src/main/java/com/casic/dao/DataPressureMapper.java new file mode 100644 index 0000000..05f4329 --- /dev/null +++ b/src/main/java/com/casic/dao/DataPressureMapper.java @@ -0,0 +1,19 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.DataPressure; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.Date; + +@Mapper +public interface DataPressureMapper extends BaseMapper { + + String getWellCode(@Param("devcode") String devcode); + + Float getRuleValue(@Param("deviceType") String deviceType); + + void saveRecords(@Param("reValue") String reValue, @Param("alarmTime") Date alarmTime); + +} diff --git a/src/main/java/com/casic/dao/DeviceDataMapper.java b/src/main/java/com/casic/dao/DeviceDataMapper.java new file mode 100644 index 0000000..d9e18a0 --- /dev/null +++ b/src/main/java/com/casic/dao/DeviceDataMapper.java @@ -0,0 +1,27 @@ +package com.casic.dao; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + + +@Mapper +public interface DeviceDataMapper { + + List> getDeviceRecentData(@Param("tableName") String tableName, + @Param("recentNum") String recentNum, + @Param("fields") String fields, + @Param("devcode") String devcode); + + Integer getDeviceDataTotal(@Param("tableName") String tableName, @Param("devcode") String devcode); + + List> getDeviceDataListPage(@Param("tableName") String tableName, + @Param("currentIndex") Integer currentIndex, + @Param("fields") String fields, + @Param("pageSize") Integer pageSize, + @Param("devcode") String devcode); + + String getLevelByType(@Param("deviceType")String deviceType); +} diff --git a/src/main/java/com/casic/model/AlarmConfigParam.java b/src/main/java/com/casic/model/AlarmConfigParam.java new file mode 100644 index 0000000..28150d6 --- /dev/null +++ b/src/main/java/com/casic/model/AlarmConfigParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class AlarmConfigParam { + private String deviceType; + private String thresholdVol; + private String collectInterval; + private String uploadCycle; + private String retryNum; + private String ip; + private String port; + private String devcode; +} diff --git a/src/main/java/com/casic/model/AlarmLevel.java b/src/main/java/com/casic/model/AlarmLevel.java new file mode 100644 index 0000000..d0909af --- /dev/null +++ b/src/main/java/com/casic/model/AlarmLevel.java @@ -0,0 +1,26 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("alarm_level") +public class AlarmLevel{ + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + private String name; + private String deviceType; + private Integer level; + private Float lowValue; + private Float highValue; + private String openAlarm; + private String openJob; + private Date ts; + private String tenantId; + +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..50f4a19 --- /dev/null +++ b/pom.xml @@ -0,0 +1,161 @@ + + + 4.0.0 + + com.casic + smartwell-demos + 1.0-SNAPSHOT + + + + + jdk-1.8 + + true + 1.8 + + + 1.8 + 1.8 + 1.8 + + + + + + + + + + org.springframework.boot + spring-boot-starter + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-tomcat + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-web + 2.4.5 + + + + + org.springframework.boot + spring-boot-starter-jdbc + 2.4.5 + + + + mysql + mysql-connector-java + 8.0.16 + compile + + + + com.baomidou + mybatis-plus-boot-starter + 3.4.3 + + + + org.projectlombok + lombok + 1.18.20 + + + + + com.alibaba + druid + 1.2.6 + + + + com.alibaba + fastjson + 1.2.73 + + + + commons-codec + commons-codec + 1.14 + + + + redis.clients + jedis + 3.1.0 + jar + + + + org.springframework.data + spring-data-redis + 2.4.8 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.3.RELEASE + + true + + com.casic.CasicApplication + exec + + + + + repackage + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + false + + + + + + + + src/main/resources + + + /config/*/* + /config/*-*.yml + + true + + + src/main/resources + + **/*.xml + + true + + + + + \ No newline at end of file diff --git a/src/main/java/com/casic/CasicApplication.java b/src/main/java/com/casic/CasicApplication.java new file mode 100644 index 0000000..9afd0b9 --- /dev/null +++ b/src/main/java/com/casic/CasicApplication.java @@ -0,0 +1,28 @@ +package com.casic; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.transaction.annotation.EnableTransactionManagement; + + +/** + * SpringBoot方式启动类 + * + * @author cz + * @Date 2022/09/08 14:28 + */ + +@Slf4j +@ComponentScan(basePackages= "com.casic.**") +@SpringBootApplication +public class CasicApplication { + public static void main(String[] args) { + log.info("CasicApplication is success!"); + SpringApplication.run(CasicApplication.class, args); + } +} diff --git a/src/main/java/com/casic/config/CorsConfig.java b/src/main/java/com/casic/config/CorsConfig.java new file mode 100644 index 0000000..7d19680 --- /dev/null +++ b/src/main/java/com/casic/config/CorsConfig.java @@ -0,0 +1,31 @@ +package com.casic.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +/** + * 基础框架 - 跨域请求配置 + */ +@Configuration +public class CorsConfig { + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", buildConfig()); + return new CorsFilter(source); + } + + private CorsConfiguration buildConfig() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + // 1允许任何域名使用 + corsConfiguration.addAllowedOrigin("*"); + // 2允许任何头 + corsConfiguration.addAllowedHeader("*"); + // 3允许任何方法(post、get等) + corsConfiguration.addAllowedMethod("*"); + return corsConfiguration; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/controller/AlarmController.java b/src/main/java/com/casic/controller/AlarmController.java new file mode 100644 index 0000000..957fc36 --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.model.AlarmConfigParam; +import com.casic.service.AlarmService; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/alarm") +public class AlarmController { + + private final AlarmService alarmService; + + public AlarmController(AlarmService alarmService) { + this.alarmService = alarmService; + } + + @RequestMapping("/records") + public Object getAlarmRecord(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "devcode",required =false) String devcode, + @RequestParam(value = "pageSize", required = true) Integer pageSize) { + return alarmService.getAlarmRecord(deviceType,currentIndex,pageSize,devcode); + } + + @RequestMapping("/batch/cancel") + public Object excuteAlramBatchCancel(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "devcode",required =false) String devcode) { + return alarmService.excuteAlramBatchCancel(deviceType,devcode); + } + + @RequestMapping("/config/add") + public Object addAlarmConfig(@RequestBody AlarmConfigParam alarmConfigParam) { + return alarmService.addAlarmConfig(alarmConfigParam); + } +} diff --git a/src/main/java/com/casic/controller/DeviceDataController.java b/src/main/java/com/casic/controller/DeviceDataController.java new file mode 100644 index 0000000..3498b04 --- /dev/null +++ b/src/main/java/com/casic/controller/DeviceDataController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.service.DeviceDataService; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/device") +public class DeviceDataController { + private final DeviceDataService deviceDataService; + + public DeviceDataController(DeviceDataService deviceDataService) { + this.deviceDataService = deviceDataService; + } + + @RequestMapping("/recent-data") + public Object getDeviceRecentData(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "recentNum", required = true) String recentNum, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceRecentData(deviceType, recentNum, devcode); + } + + @RequestMapping("/data/list-page") + public Object getDeviceListPage(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "pageSize", required = true) Integer pageSize, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceListPage(deviceType, currentIndex, pageSize, devcode); + } + + @RequestMapping("/level/{deviceType}") + public Object getLevelList(@PathVariable("deviceType")String deviceType) { + return deviceDataService.getLevel(deviceType); + } + +} diff --git a/src/main/java/com/casic/controller/ThirdDataController.java b/src/main/java/com/casic/controller/ThirdDataController.java new file mode 100644 index 0000000..b9b2b42 --- /dev/null +++ b/src/main/java/com/casic/controller/ThirdDataController.java @@ -0,0 +1,28 @@ +package com.casic.controller; + +import com.casic.model.PressureDataParam; +import com.casic.service.ThirdDataService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +@RestController +@RequestMapping("/push") +@Slf4j +public class ThirdDataController { + + private final ThirdDataService thirdDataService; + + public ThirdDataController(ThirdDataService thirdDataService) { + this.thirdDataService = thirdDataService; + } + + @RequestMapping("/pressure/data") + public Object getDeviceRecentData(@RequestBody PressureDataParam pressureData) { + return thirdDataService.getDeviceRecentData(pressureData); + } + +} diff --git a/src/main/java/com/casic/dao/AlarmMapper.java b/src/main/java/com/casic/dao/AlarmMapper.java new file mode 100644 index 0000000..a442e3a --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmMapper.java @@ -0,0 +1,28 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmLevel; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + +@Mapper +public interface AlarmMapper extends BaseMapper { + + List> getAlarmRecord(@Param("deviceType") String deviceType, + @Param("devcode") String devcode, + @Param("currentIndex") Integer currentIndex, @Param("pageSize") Integer pageSize); + + Integer getAlarmTotalRecord(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteAlramBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteJobBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + String getDeviceDevcode(@Param("deviceType") String deviceType); + + String getDeviceByDevcode(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + +} diff --git a/src/main/java/com/casic/dao/BusConfigMapper.java b/src/main/java/com/casic/dao/BusConfigMapper.java new file mode 100644 index 0000000..ccf76da --- /dev/null +++ b/src/main/java/com/casic/dao/BusConfigMapper.java @@ -0,0 +1,9 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.BusConfig; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface BusConfigMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/dao/DataPressureMapper.java b/src/main/java/com/casic/dao/DataPressureMapper.java new file mode 100644 index 0000000..05f4329 --- /dev/null +++ b/src/main/java/com/casic/dao/DataPressureMapper.java @@ -0,0 +1,19 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.DataPressure; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.Date; + +@Mapper +public interface DataPressureMapper extends BaseMapper { + + String getWellCode(@Param("devcode") String devcode); + + Float getRuleValue(@Param("deviceType") String deviceType); + + void saveRecords(@Param("reValue") String reValue, @Param("alarmTime") Date alarmTime); + +} diff --git a/src/main/java/com/casic/dao/DeviceDataMapper.java b/src/main/java/com/casic/dao/DeviceDataMapper.java new file mode 100644 index 0000000..d9e18a0 --- /dev/null +++ b/src/main/java/com/casic/dao/DeviceDataMapper.java @@ -0,0 +1,27 @@ +package com.casic.dao; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + + +@Mapper +public interface DeviceDataMapper { + + List> getDeviceRecentData(@Param("tableName") String tableName, + @Param("recentNum") String recentNum, + @Param("fields") String fields, + @Param("devcode") String devcode); + + Integer getDeviceDataTotal(@Param("tableName") String tableName, @Param("devcode") String devcode); + + List> getDeviceDataListPage(@Param("tableName") String tableName, + @Param("currentIndex") Integer currentIndex, + @Param("fields") String fields, + @Param("pageSize") Integer pageSize, + @Param("devcode") String devcode); + + String getLevelByType(@Param("deviceType")String deviceType); +} diff --git a/src/main/java/com/casic/model/AlarmConfigParam.java b/src/main/java/com/casic/model/AlarmConfigParam.java new file mode 100644 index 0000000..28150d6 --- /dev/null +++ b/src/main/java/com/casic/model/AlarmConfigParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class AlarmConfigParam { + private String deviceType; + private String thresholdVol; + private String collectInterval; + private String uploadCycle; + private String retryNum; + private String ip; + private String port; + private String devcode; +} diff --git a/src/main/java/com/casic/model/AlarmLevel.java b/src/main/java/com/casic/model/AlarmLevel.java new file mode 100644 index 0000000..d0909af --- /dev/null +++ b/src/main/java/com/casic/model/AlarmLevel.java @@ -0,0 +1,26 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("alarm_level") +public class AlarmLevel{ + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + private String name; + private String deviceType; + private Integer level; + private Float lowValue; + private Float highValue; + private String openAlarm; + private String openJob; + private Date ts; + private String tenantId; + +} diff --git a/src/main/java/com/casic/model/BusConfig.java b/src/main/java/com/casic/model/BusConfig.java new file mode 100644 index 0000000..c6b7b50 --- /dev/null +++ b/src/main/java/com/casic/model/BusConfig.java @@ -0,0 +1,27 @@ +package com.casic.model; + + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +import java.util.Date; + +@Data +public class BusConfig { + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + + private String deviceId; + private String framecontent; + private String sensorid; + private String sensorcode; + + private String status; + private Integer attemptsmax; + private Integer attemptscurrent; + private Date sendtime; + private Date writetime; + +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..50f4a19 --- /dev/null +++ b/pom.xml @@ -0,0 +1,161 @@ + + + 4.0.0 + + com.casic + smartwell-demos + 1.0-SNAPSHOT + + + + + jdk-1.8 + + true + 1.8 + + + 1.8 + 1.8 + 1.8 + + + + + + + + + + org.springframework.boot + spring-boot-starter + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-tomcat + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-web + 2.4.5 + + + + + org.springframework.boot + spring-boot-starter-jdbc + 2.4.5 + + + + mysql + mysql-connector-java + 8.0.16 + compile + + + + com.baomidou + mybatis-plus-boot-starter + 3.4.3 + + + + org.projectlombok + lombok + 1.18.20 + + + + + com.alibaba + druid + 1.2.6 + + + + com.alibaba + fastjson + 1.2.73 + + + + commons-codec + commons-codec + 1.14 + + + + redis.clients + jedis + 3.1.0 + jar + + + + org.springframework.data + spring-data-redis + 2.4.8 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.3.RELEASE + + true + + com.casic.CasicApplication + exec + + + + + repackage + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + false + + + + + + + + src/main/resources + + + /config/*/* + /config/*-*.yml + + true + + + src/main/resources + + **/*.xml + + true + + + + + \ No newline at end of file diff --git a/src/main/java/com/casic/CasicApplication.java b/src/main/java/com/casic/CasicApplication.java new file mode 100644 index 0000000..9afd0b9 --- /dev/null +++ b/src/main/java/com/casic/CasicApplication.java @@ -0,0 +1,28 @@ +package com.casic; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.transaction.annotation.EnableTransactionManagement; + + +/** + * SpringBoot方式启动类 + * + * @author cz + * @Date 2022/09/08 14:28 + */ + +@Slf4j +@ComponentScan(basePackages= "com.casic.**") +@SpringBootApplication +public class CasicApplication { + public static void main(String[] args) { + log.info("CasicApplication is success!"); + SpringApplication.run(CasicApplication.class, args); + } +} diff --git a/src/main/java/com/casic/config/CorsConfig.java b/src/main/java/com/casic/config/CorsConfig.java new file mode 100644 index 0000000..7d19680 --- /dev/null +++ b/src/main/java/com/casic/config/CorsConfig.java @@ -0,0 +1,31 @@ +package com.casic.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +/** + * 基础框架 - 跨域请求配置 + */ +@Configuration +public class CorsConfig { + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", buildConfig()); + return new CorsFilter(source); + } + + private CorsConfiguration buildConfig() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + // 1允许任何域名使用 + corsConfiguration.addAllowedOrigin("*"); + // 2允许任何头 + corsConfiguration.addAllowedHeader("*"); + // 3允许任何方法(post、get等) + corsConfiguration.addAllowedMethod("*"); + return corsConfiguration; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/controller/AlarmController.java b/src/main/java/com/casic/controller/AlarmController.java new file mode 100644 index 0000000..957fc36 --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.model.AlarmConfigParam; +import com.casic.service.AlarmService; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/alarm") +public class AlarmController { + + private final AlarmService alarmService; + + public AlarmController(AlarmService alarmService) { + this.alarmService = alarmService; + } + + @RequestMapping("/records") + public Object getAlarmRecord(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "devcode",required =false) String devcode, + @RequestParam(value = "pageSize", required = true) Integer pageSize) { + return alarmService.getAlarmRecord(deviceType,currentIndex,pageSize,devcode); + } + + @RequestMapping("/batch/cancel") + public Object excuteAlramBatchCancel(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "devcode",required =false) String devcode) { + return alarmService.excuteAlramBatchCancel(deviceType,devcode); + } + + @RequestMapping("/config/add") + public Object addAlarmConfig(@RequestBody AlarmConfigParam alarmConfigParam) { + return alarmService.addAlarmConfig(alarmConfigParam); + } +} diff --git a/src/main/java/com/casic/controller/DeviceDataController.java b/src/main/java/com/casic/controller/DeviceDataController.java new file mode 100644 index 0000000..3498b04 --- /dev/null +++ b/src/main/java/com/casic/controller/DeviceDataController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.service.DeviceDataService; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/device") +public class DeviceDataController { + private final DeviceDataService deviceDataService; + + public DeviceDataController(DeviceDataService deviceDataService) { + this.deviceDataService = deviceDataService; + } + + @RequestMapping("/recent-data") + public Object getDeviceRecentData(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "recentNum", required = true) String recentNum, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceRecentData(deviceType, recentNum, devcode); + } + + @RequestMapping("/data/list-page") + public Object getDeviceListPage(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "pageSize", required = true) Integer pageSize, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceListPage(deviceType, currentIndex, pageSize, devcode); + } + + @RequestMapping("/level/{deviceType}") + public Object getLevelList(@PathVariable("deviceType")String deviceType) { + return deviceDataService.getLevel(deviceType); + } + +} diff --git a/src/main/java/com/casic/controller/ThirdDataController.java b/src/main/java/com/casic/controller/ThirdDataController.java new file mode 100644 index 0000000..b9b2b42 --- /dev/null +++ b/src/main/java/com/casic/controller/ThirdDataController.java @@ -0,0 +1,28 @@ +package com.casic.controller; + +import com.casic.model.PressureDataParam; +import com.casic.service.ThirdDataService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +@RestController +@RequestMapping("/push") +@Slf4j +public class ThirdDataController { + + private final ThirdDataService thirdDataService; + + public ThirdDataController(ThirdDataService thirdDataService) { + this.thirdDataService = thirdDataService; + } + + @RequestMapping("/pressure/data") + public Object getDeviceRecentData(@RequestBody PressureDataParam pressureData) { + return thirdDataService.getDeviceRecentData(pressureData); + } + +} diff --git a/src/main/java/com/casic/dao/AlarmMapper.java b/src/main/java/com/casic/dao/AlarmMapper.java new file mode 100644 index 0000000..a442e3a --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmMapper.java @@ -0,0 +1,28 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmLevel; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + +@Mapper +public interface AlarmMapper extends BaseMapper { + + List> getAlarmRecord(@Param("deviceType") String deviceType, + @Param("devcode") String devcode, + @Param("currentIndex") Integer currentIndex, @Param("pageSize") Integer pageSize); + + Integer getAlarmTotalRecord(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteAlramBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteJobBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + String getDeviceDevcode(@Param("deviceType") String deviceType); + + String getDeviceByDevcode(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + +} diff --git a/src/main/java/com/casic/dao/BusConfigMapper.java b/src/main/java/com/casic/dao/BusConfigMapper.java new file mode 100644 index 0000000..ccf76da --- /dev/null +++ b/src/main/java/com/casic/dao/BusConfigMapper.java @@ -0,0 +1,9 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.BusConfig; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface BusConfigMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/dao/DataPressureMapper.java b/src/main/java/com/casic/dao/DataPressureMapper.java new file mode 100644 index 0000000..05f4329 --- /dev/null +++ b/src/main/java/com/casic/dao/DataPressureMapper.java @@ -0,0 +1,19 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.DataPressure; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.Date; + +@Mapper +public interface DataPressureMapper extends BaseMapper { + + String getWellCode(@Param("devcode") String devcode); + + Float getRuleValue(@Param("deviceType") String deviceType); + + void saveRecords(@Param("reValue") String reValue, @Param("alarmTime") Date alarmTime); + +} diff --git a/src/main/java/com/casic/dao/DeviceDataMapper.java b/src/main/java/com/casic/dao/DeviceDataMapper.java new file mode 100644 index 0000000..d9e18a0 --- /dev/null +++ b/src/main/java/com/casic/dao/DeviceDataMapper.java @@ -0,0 +1,27 @@ +package com.casic.dao; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + + +@Mapper +public interface DeviceDataMapper { + + List> getDeviceRecentData(@Param("tableName") String tableName, + @Param("recentNum") String recentNum, + @Param("fields") String fields, + @Param("devcode") String devcode); + + Integer getDeviceDataTotal(@Param("tableName") String tableName, @Param("devcode") String devcode); + + List> getDeviceDataListPage(@Param("tableName") String tableName, + @Param("currentIndex") Integer currentIndex, + @Param("fields") String fields, + @Param("pageSize") Integer pageSize, + @Param("devcode") String devcode); + + String getLevelByType(@Param("deviceType")String deviceType); +} diff --git a/src/main/java/com/casic/model/AlarmConfigParam.java b/src/main/java/com/casic/model/AlarmConfigParam.java new file mode 100644 index 0000000..28150d6 --- /dev/null +++ b/src/main/java/com/casic/model/AlarmConfigParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class AlarmConfigParam { + private String deviceType; + private String thresholdVol; + private String collectInterval; + private String uploadCycle; + private String retryNum; + private String ip; + private String port; + private String devcode; +} diff --git a/src/main/java/com/casic/model/AlarmLevel.java b/src/main/java/com/casic/model/AlarmLevel.java new file mode 100644 index 0000000..d0909af --- /dev/null +++ b/src/main/java/com/casic/model/AlarmLevel.java @@ -0,0 +1,26 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("alarm_level") +public class AlarmLevel{ + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + private String name; + private String deviceType; + private Integer level; + private Float lowValue; + private Float highValue; + private String openAlarm; + private String openJob; + private Date ts; + private String tenantId; + +} diff --git a/src/main/java/com/casic/model/BusConfig.java b/src/main/java/com/casic/model/BusConfig.java new file mode 100644 index 0000000..c6b7b50 --- /dev/null +++ b/src/main/java/com/casic/model/BusConfig.java @@ -0,0 +1,27 @@ +package com.casic.model; + + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +import java.util.Date; + +@Data +public class BusConfig { + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + + private String deviceId; + private String framecontent; + private String sensorid; + private String sensorcode; + + private String status; + private Integer attemptsmax; + private Integer attemptscurrent; + private Date sendtime; + private Date writetime; + +} diff --git a/src/main/java/com/casic/model/CommConfigDTO.java b/src/main/java/com/casic/model/CommConfigDTO.java new file mode 100644 index 0000000..7da699c --- /dev/null +++ b/src/main/java/com/casic/model/CommConfigDTO.java @@ -0,0 +1,41 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class CommConfigDTO { + private String acqStart;//采集开始时间 + private Long interval;//采集时间间隔(分钟) + private Long period;//上传周期 + private Long times;//采集次数 + private Long repeat;//重传次数 + private String ip; + private Long port; + private Float thresh; + private Float height; + private String collect; + private String MultiCollect; + private String acqCycle; + private String upCycle; + private String sleepStartTime; + + private String acqStartFlow ; //流量采集开始时间 + private Long intervalFlow; //流量采集采集间隔(分) + private Long acqTimesFlow ;//流量采集次数 + private String upStartFlow; //流量上报开始时间 + private Long upTimesFlow; //流量上传次数 + private String acqStartNoise; //噪声采集开始时间 + private Long intervalNoise; //噪声采集采集间隔(分) + private Long acqTimesNoise;//噪声采集次数 + private String upStartNoise; //噪声上报开始时间 + private Long upTimesNoise ;//噪声上传次数 + private String acqStartPressure; //压力采集开始时间 + private Long intervalPressure;//压力采集采集间隔(分) + private Long acqTimesPressure; //压力采集次数 + private String upStartPressure; //压力上报开始时间 + private Long upTimesPressure; //压力上传次数 + private Float lowerLimitPressure; //压力报警下限 + private Float upperLimitPressure ;//压力报警下限 + private Long limitDig ;//开挖阈值 + private Float threshold ;//开挖阈值 +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..50f4a19 --- /dev/null +++ b/pom.xml @@ -0,0 +1,161 @@ + + + 4.0.0 + + com.casic + smartwell-demos + 1.0-SNAPSHOT + + + + + jdk-1.8 + + true + 1.8 + + + 1.8 + 1.8 + 1.8 + + + + + + + + + + org.springframework.boot + spring-boot-starter + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-tomcat + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-web + 2.4.5 + + + + + org.springframework.boot + spring-boot-starter-jdbc + 2.4.5 + + + + mysql + mysql-connector-java + 8.0.16 + compile + + + + com.baomidou + mybatis-plus-boot-starter + 3.4.3 + + + + org.projectlombok + lombok + 1.18.20 + + + + + com.alibaba + druid + 1.2.6 + + + + com.alibaba + fastjson + 1.2.73 + + + + commons-codec + commons-codec + 1.14 + + + + redis.clients + jedis + 3.1.0 + jar + + + + org.springframework.data + spring-data-redis + 2.4.8 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.3.RELEASE + + true + + com.casic.CasicApplication + exec + + + + + repackage + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + false + + + + + + + + src/main/resources + + + /config/*/* + /config/*-*.yml + + true + + + src/main/resources + + **/*.xml + + true + + + + + \ No newline at end of file diff --git a/src/main/java/com/casic/CasicApplication.java b/src/main/java/com/casic/CasicApplication.java new file mode 100644 index 0000000..9afd0b9 --- /dev/null +++ b/src/main/java/com/casic/CasicApplication.java @@ -0,0 +1,28 @@ +package com.casic; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.transaction.annotation.EnableTransactionManagement; + + +/** + * SpringBoot方式启动类 + * + * @author cz + * @Date 2022/09/08 14:28 + */ + +@Slf4j +@ComponentScan(basePackages= "com.casic.**") +@SpringBootApplication +public class CasicApplication { + public static void main(String[] args) { + log.info("CasicApplication is success!"); + SpringApplication.run(CasicApplication.class, args); + } +} diff --git a/src/main/java/com/casic/config/CorsConfig.java b/src/main/java/com/casic/config/CorsConfig.java new file mode 100644 index 0000000..7d19680 --- /dev/null +++ b/src/main/java/com/casic/config/CorsConfig.java @@ -0,0 +1,31 @@ +package com.casic.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +/** + * 基础框架 - 跨域请求配置 + */ +@Configuration +public class CorsConfig { + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", buildConfig()); + return new CorsFilter(source); + } + + private CorsConfiguration buildConfig() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + // 1允许任何域名使用 + corsConfiguration.addAllowedOrigin("*"); + // 2允许任何头 + corsConfiguration.addAllowedHeader("*"); + // 3允许任何方法(post、get等) + corsConfiguration.addAllowedMethod("*"); + return corsConfiguration; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/controller/AlarmController.java b/src/main/java/com/casic/controller/AlarmController.java new file mode 100644 index 0000000..957fc36 --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.model.AlarmConfigParam; +import com.casic.service.AlarmService; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/alarm") +public class AlarmController { + + private final AlarmService alarmService; + + public AlarmController(AlarmService alarmService) { + this.alarmService = alarmService; + } + + @RequestMapping("/records") + public Object getAlarmRecord(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "devcode",required =false) String devcode, + @RequestParam(value = "pageSize", required = true) Integer pageSize) { + return alarmService.getAlarmRecord(deviceType,currentIndex,pageSize,devcode); + } + + @RequestMapping("/batch/cancel") + public Object excuteAlramBatchCancel(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "devcode",required =false) String devcode) { + return alarmService.excuteAlramBatchCancel(deviceType,devcode); + } + + @RequestMapping("/config/add") + public Object addAlarmConfig(@RequestBody AlarmConfigParam alarmConfigParam) { + return alarmService.addAlarmConfig(alarmConfigParam); + } +} diff --git a/src/main/java/com/casic/controller/DeviceDataController.java b/src/main/java/com/casic/controller/DeviceDataController.java new file mode 100644 index 0000000..3498b04 --- /dev/null +++ b/src/main/java/com/casic/controller/DeviceDataController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.service.DeviceDataService; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/device") +public class DeviceDataController { + private final DeviceDataService deviceDataService; + + public DeviceDataController(DeviceDataService deviceDataService) { + this.deviceDataService = deviceDataService; + } + + @RequestMapping("/recent-data") + public Object getDeviceRecentData(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "recentNum", required = true) String recentNum, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceRecentData(deviceType, recentNum, devcode); + } + + @RequestMapping("/data/list-page") + public Object getDeviceListPage(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "pageSize", required = true) Integer pageSize, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceListPage(deviceType, currentIndex, pageSize, devcode); + } + + @RequestMapping("/level/{deviceType}") + public Object getLevelList(@PathVariable("deviceType")String deviceType) { + return deviceDataService.getLevel(deviceType); + } + +} diff --git a/src/main/java/com/casic/controller/ThirdDataController.java b/src/main/java/com/casic/controller/ThirdDataController.java new file mode 100644 index 0000000..b9b2b42 --- /dev/null +++ b/src/main/java/com/casic/controller/ThirdDataController.java @@ -0,0 +1,28 @@ +package com.casic.controller; + +import com.casic.model.PressureDataParam; +import com.casic.service.ThirdDataService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +@RestController +@RequestMapping("/push") +@Slf4j +public class ThirdDataController { + + private final ThirdDataService thirdDataService; + + public ThirdDataController(ThirdDataService thirdDataService) { + this.thirdDataService = thirdDataService; + } + + @RequestMapping("/pressure/data") + public Object getDeviceRecentData(@RequestBody PressureDataParam pressureData) { + return thirdDataService.getDeviceRecentData(pressureData); + } + +} diff --git a/src/main/java/com/casic/dao/AlarmMapper.java b/src/main/java/com/casic/dao/AlarmMapper.java new file mode 100644 index 0000000..a442e3a --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmMapper.java @@ -0,0 +1,28 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmLevel; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + +@Mapper +public interface AlarmMapper extends BaseMapper { + + List> getAlarmRecord(@Param("deviceType") String deviceType, + @Param("devcode") String devcode, + @Param("currentIndex") Integer currentIndex, @Param("pageSize") Integer pageSize); + + Integer getAlarmTotalRecord(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteAlramBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteJobBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + String getDeviceDevcode(@Param("deviceType") String deviceType); + + String getDeviceByDevcode(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + +} diff --git a/src/main/java/com/casic/dao/BusConfigMapper.java b/src/main/java/com/casic/dao/BusConfigMapper.java new file mode 100644 index 0000000..ccf76da --- /dev/null +++ b/src/main/java/com/casic/dao/BusConfigMapper.java @@ -0,0 +1,9 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.BusConfig; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface BusConfigMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/dao/DataPressureMapper.java b/src/main/java/com/casic/dao/DataPressureMapper.java new file mode 100644 index 0000000..05f4329 --- /dev/null +++ b/src/main/java/com/casic/dao/DataPressureMapper.java @@ -0,0 +1,19 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.DataPressure; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.Date; + +@Mapper +public interface DataPressureMapper extends BaseMapper { + + String getWellCode(@Param("devcode") String devcode); + + Float getRuleValue(@Param("deviceType") String deviceType); + + void saveRecords(@Param("reValue") String reValue, @Param("alarmTime") Date alarmTime); + +} diff --git a/src/main/java/com/casic/dao/DeviceDataMapper.java b/src/main/java/com/casic/dao/DeviceDataMapper.java new file mode 100644 index 0000000..d9e18a0 --- /dev/null +++ b/src/main/java/com/casic/dao/DeviceDataMapper.java @@ -0,0 +1,27 @@ +package com.casic.dao; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + + +@Mapper +public interface DeviceDataMapper { + + List> getDeviceRecentData(@Param("tableName") String tableName, + @Param("recentNum") String recentNum, + @Param("fields") String fields, + @Param("devcode") String devcode); + + Integer getDeviceDataTotal(@Param("tableName") String tableName, @Param("devcode") String devcode); + + List> getDeviceDataListPage(@Param("tableName") String tableName, + @Param("currentIndex") Integer currentIndex, + @Param("fields") String fields, + @Param("pageSize") Integer pageSize, + @Param("devcode") String devcode); + + String getLevelByType(@Param("deviceType")String deviceType); +} diff --git a/src/main/java/com/casic/model/AlarmConfigParam.java b/src/main/java/com/casic/model/AlarmConfigParam.java new file mode 100644 index 0000000..28150d6 --- /dev/null +++ b/src/main/java/com/casic/model/AlarmConfigParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class AlarmConfigParam { + private String deviceType; + private String thresholdVol; + private String collectInterval; + private String uploadCycle; + private String retryNum; + private String ip; + private String port; + private String devcode; +} diff --git a/src/main/java/com/casic/model/AlarmLevel.java b/src/main/java/com/casic/model/AlarmLevel.java new file mode 100644 index 0000000..d0909af --- /dev/null +++ b/src/main/java/com/casic/model/AlarmLevel.java @@ -0,0 +1,26 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("alarm_level") +public class AlarmLevel{ + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + private String name; + private String deviceType; + private Integer level; + private Float lowValue; + private Float highValue; + private String openAlarm; + private String openJob; + private Date ts; + private String tenantId; + +} diff --git a/src/main/java/com/casic/model/BusConfig.java b/src/main/java/com/casic/model/BusConfig.java new file mode 100644 index 0000000..c6b7b50 --- /dev/null +++ b/src/main/java/com/casic/model/BusConfig.java @@ -0,0 +1,27 @@ +package com.casic.model; + + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +import java.util.Date; + +@Data +public class BusConfig { + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + + private String deviceId; + private String framecontent; + private String sensorid; + private String sensorcode; + + private String status; + private Integer attemptsmax; + private Integer attemptscurrent; + private Date sendtime; + private Date writetime; + +} diff --git a/src/main/java/com/casic/model/CommConfigDTO.java b/src/main/java/com/casic/model/CommConfigDTO.java new file mode 100644 index 0000000..7da699c --- /dev/null +++ b/src/main/java/com/casic/model/CommConfigDTO.java @@ -0,0 +1,41 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class CommConfigDTO { + private String acqStart;//采集开始时间 + private Long interval;//采集时间间隔(分钟) + private Long period;//上传周期 + private Long times;//采集次数 + private Long repeat;//重传次数 + private String ip; + private Long port; + private Float thresh; + private Float height; + private String collect; + private String MultiCollect; + private String acqCycle; + private String upCycle; + private String sleepStartTime; + + private String acqStartFlow ; //流量采集开始时间 + private Long intervalFlow; //流量采集采集间隔(分) + private Long acqTimesFlow ;//流量采集次数 + private String upStartFlow; //流量上报开始时间 + private Long upTimesFlow; //流量上传次数 + private String acqStartNoise; //噪声采集开始时间 + private Long intervalNoise; //噪声采集采集间隔(分) + private Long acqTimesNoise;//噪声采集次数 + private String upStartNoise; //噪声上报开始时间 + private Long upTimesNoise ;//噪声上传次数 + private String acqStartPressure; //压力采集开始时间 + private Long intervalPressure;//压力采集采集间隔(分) + private Long acqTimesPressure; //压力采集次数 + private String upStartPressure; //压力上报开始时间 + private Long upTimesPressure; //压力上传次数 + private Float lowerLimitPressure; //压力报警下限 + private Float upperLimitPressure ;//压力报警下限 + private Long limitDig ;//开挖阈值 + private Float threshold ;//开挖阈值 +} diff --git a/src/main/java/com/casic/model/DataPressure.java b/src/main/java/com/casic/model/DataPressure.java new file mode 100644 index 0000000..8270c70 --- /dev/null +++ b/src/main/java/com/casic/model/DataPressure.java @@ -0,0 +1,33 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("data_temp_press") +public class DataPressure { + + @TableId(value = "ID", type = IdType.AUTO) + private String id; + private String wellCode; + private String devcode; + private Float cell; + private String temperature; + + private String press; + private String descn; + private String uptime; + private String logtime; + /** + * 信号强度 + */ + private String pci; + + private String rsrp; + private String snr; + +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..50f4a19 --- /dev/null +++ b/pom.xml @@ -0,0 +1,161 @@ + + + 4.0.0 + + com.casic + smartwell-demos + 1.0-SNAPSHOT + + + + + jdk-1.8 + + true + 1.8 + + + 1.8 + 1.8 + 1.8 + + + + + + + + + + org.springframework.boot + spring-boot-starter + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-tomcat + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-web + 2.4.5 + + + + + org.springframework.boot + spring-boot-starter-jdbc + 2.4.5 + + + + mysql + mysql-connector-java + 8.0.16 + compile + + + + com.baomidou + mybatis-plus-boot-starter + 3.4.3 + + + + org.projectlombok + lombok + 1.18.20 + + + + + com.alibaba + druid + 1.2.6 + + + + com.alibaba + fastjson + 1.2.73 + + + + commons-codec + commons-codec + 1.14 + + + + redis.clients + jedis + 3.1.0 + jar + + + + org.springframework.data + spring-data-redis + 2.4.8 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.3.RELEASE + + true + + com.casic.CasicApplication + exec + + + + + repackage + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + false + + + + + + + + src/main/resources + + + /config/*/* + /config/*-*.yml + + true + + + src/main/resources + + **/*.xml + + true + + + + + \ No newline at end of file diff --git a/src/main/java/com/casic/CasicApplication.java b/src/main/java/com/casic/CasicApplication.java new file mode 100644 index 0000000..9afd0b9 --- /dev/null +++ b/src/main/java/com/casic/CasicApplication.java @@ -0,0 +1,28 @@ +package com.casic; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.transaction.annotation.EnableTransactionManagement; + + +/** + * SpringBoot方式启动类 + * + * @author cz + * @Date 2022/09/08 14:28 + */ + +@Slf4j +@ComponentScan(basePackages= "com.casic.**") +@SpringBootApplication +public class CasicApplication { + public static void main(String[] args) { + log.info("CasicApplication is success!"); + SpringApplication.run(CasicApplication.class, args); + } +} diff --git a/src/main/java/com/casic/config/CorsConfig.java b/src/main/java/com/casic/config/CorsConfig.java new file mode 100644 index 0000000..7d19680 --- /dev/null +++ b/src/main/java/com/casic/config/CorsConfig.java @@ -0,0 +1,31 @@ +package com.casic.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +/** + * 基础框架 - 跨域请求配置 + */ +@Configuration +public class CorsConfig { + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", buildConfig()); + return new CorsFilter(source); + } + + private CorsConfiguration buildConfig() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + // 1允许任何域名使用 + corsConfiguration.addAllowedOrigin("*"); + // 2允许任何头 + corsConfiguration.addAllowedHeader("*"); + // 3允许任何方法(post、get等) + corsConfiguration.addAllowedMethod("*"); + return corsConfiguration; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/controller/AlarmController.java b/src/main/java/com/casic/controller/AlarmController.java new file mode 100644 index 0000000..957fc36 --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.model.AlarmConfigParam; +import com.casic.service.AlarmService; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/alarm") +public class AlarmController { + + private final AlarmService alarmService; + + public AlarmController(AlarmService alarmService) { + this.alarmService = alarmService; + } + + @RequestMapping("/records") + public Object getAlarmRecord(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "devcode",required =false) String devcode, + @RequestParam(value = "pageSize", required = true) Integer pageSize) { + return alarmService.getAlarmRecord(deviceType,currentIndex,pageSize,devcode); + } + + @RequestMapping("/batch/cancel") + public Object excuteAlramBatchCancel(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "devcode",required =false) String devcode) { + return alarmService.excuteAlramBatchCancel(deviceType,devcode); + } + + @RequestMapping("/config/add") + public Object addAlarmConfig(@RequestBody AlarmConfigParam alarmConfigParam) { + return alarmService.addAlarmConfig(alarmConfigParam); + } +} diff --git a/src/main/java/com/casic/controller/DeviceDataController.java b/src/main/java/com/casic/controller/DeviceDataController.java new file mode 100644 index 0000000..3498b04 --- /dev/null +++ b/src/main/java/com/casic/controller/DeviceDataController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.service.DeviceDataService; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/device") +public class DeviceDataController { + private final DeviceDataService deviceDataService; + + public DeviceDataController(DeviceDataService deviceDataService) { + this.deviceDataService = deviceDataService; + } + + @RequestMapping("/recent-data") + public Object getDeviceRecentData(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "recentNum", required = true) String recentNum, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceRecentData(deviceType, recentNum, devcode); + } + + @RequestMapping("/data/list-page") + public Object getDeviceListPage(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "pageSize", required = true) Integer pageSize, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceListPage(deviceType, currentIndex, pageSize, devcode); + } + + @RequestMapping("/level/{deviceType}") + public Object getLevelList(@PathVariable("deviceType")String deviceType) { + return deviceDataService.getLevel(deviceType); + } + +} diff --git a/src/main/java/com/casic/controller/ThirdDataController.java b/src/main/java/com/casic/controller/ThirdDataController.java new file mode 100644 index 0000000..b9b2b42 --- /dev/null +++ b/src/main/java/com/casic/controller/ThirdDataController.java @@ -0,0 +1,28 @@ +package com.casic.controller; + +import com.casic.model.PressureDataParam; +import com.casic.service.ThirdDataService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +@RestController +@RequestMapping("/push") +@Slf4j +public class ThirdDataController { + + private final ThirdDataService thirdDataService; + + public ThirdDataController(ThirdDataService thirdDataService) { + this.thirdDataService = thirdDataService; + } + + @RequestMapping("/pressure/data") + public Object getDeviceRecentData(@RequestBody PressureDataParam pressureData) { + return thirdDataService.getDeviceRecentData(pressureData); + } + +} diff --git a/src/main/java/com/casic/dao/AlarmMapper.java b/src/main/java/com/casic/dao/AlarmMapper.java new file mode 100644 index 0000000..a442e3a --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmMapper.java @@ -0,0 +1,28 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmLevel; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + +@Mapper +public interface AlarmMapper extends BaseMapper { + + List> getAlarmRecord(@Param("deviceType") String deviceType, + @Param("devcode") String devcode, + @Param("currentIndex") Integer currentIndex, @Param("pageSize") Integer pageSize); + + Integer getAlarmTotalRecord(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteAlramBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteJobBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + String getDeviceDevcode(@Param("deviceType") String deviceType); + + String getDeviceByDevcode(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + +} diff --git a/src/main/java/com/casic/dao/BusConfigMapper.java b/src/main/java/com/casic/dao/BusConfigMapper.java new file mode 100644 index 0000000..ccf76da --- /dev/null +++ b/src/main/java/com/casic/dao/BusConfigMapper.java @@ -0,0 +1,9 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.BusConfig; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface BusConfigMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/dao/DataPressureMapper.java b/src/main/java/com/casic/dao/DataPressureMapper.java new file mode 100644 index 0000000..05f4329 --- /dev/null +++ b/src/main/java/com/casic/dao/DataPressureMapper.java @@ -0,0 +1,19 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.DataPressure; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.Date; + +@Mapper +public interface DataPressureMapper extends BaseMapper { + + String getWellCode(@Param("devcode") String devcode); + + Float getRuleValue(@Param("deviceType") String deviceType); + + void saveRecords(@Param("reValue") String reValue, @Param("alarmTime") Date alarmTime); + +} diff --git a/src/main/java/com/casic/dao/DeviceDataMapper.java b/src/main/java/com/casic/dao/DeviceDataMapper.java new file mode 100644 index 0000000..d9e18a0 --- /dev/null +++ b/src/main/java/com/casic/dao/DeviceDataMapper.java @@ -0,0 +1,27 @@ +package com.casic.dao; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + + +@Mapper +public interface DeviceDataMapper { + + List> getDeviceRecentData(@Param("tableName") String tableName, + @Param("recentNum") String recentNum, + @Param("fields") String fields, + @Param("devcode") String devcode); + + Integer getDeviceDataTotal(@Param("tableName") String tableName, @Param("devcode") String devcode); + + List> getDeviceDataListPage(@Param("tableName") String tableName, + @Param("currentIndex") Integer currentIndex, + @Param("fields") String fields, + @Param("pageSize") Integer pageSize, + @Param("devcode") String devcode); + + String getLevelByType(@Param("deviceType")String deviceType); +} diff --git a/src/main/java/com/casic/model/AlarmConfigParam.java b/src/main/java/com/casic/model/AlarmConfigParam.java new file mode 100644 index 0000000..28150d6 --- /dev/null +++ b/src/main/java/com/casic/model/AlarmConfigParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class AlarmConfigParam { + private String deviceType; + private String thresholdVol; + private String collectInterval; + private String uploadCycle; + private String retryNum; + private String ip; + private String port; + private String devcode; +} diff --git a/src/main/java/com/casic/model/AlarmLevel.java b/src/main/java/com/casic/model/AlarmLevel.java new file mode 100644 index 0000000..d0909af --- /dev/null +++ b/src/main/java/com/casic/model/AlarmLevel.java @@ -0,0 +1,26 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("alarm_level") +public class AlarmLevel{ + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + private String name; + private String deviceType; + private Integer level; + private Float lowValue; + private Float highValue; + private String openAlarm; + private String openJob; + private Date ts; + private String tenantId; + +} diff --git a/src/main/java/com/casic/model/BusConfig.java b/src/main/java/com/casic/model/BusConfig.java new file mode 100644 index 0000000..c6b7b50 --- /dev/null +++ b/src/main/java/com/casic/model/BusConfig.java @@ -0,0 +1,27 @@ +package com.casic.model; + + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +import java.util.Date; + +@Data +public class BusConfig { + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + + private String deviceId; + private String framecontent; + private String sensorid; + private String sensorcode; + + private String status; + private Integer attemptsmax; + private Integer attemptscurrent; + private Date sendtime; + private Date writetime; + +} diff --git a/src/main/java/com/casic/model/CommConfigDTO.java b/src/main/java/com/casic/model/CommConfigDTO.java new file mode 100644 index 0000000..7da699c --- /dev/null +++ b/src/main/java/com/casic/model/CommConfigDTO.java @@ -0,0 +1,41 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class CommConfigDTO { + private String acqStart;//采集开始时间 + private Long interval;//采集时间间隔(分钟) + private Long period;//上传周期 + private Long times;//采集次数 + private Long repeat;//重传次数 + private String ip; + private Long port; + private Float thresh; + private Float height; + private String collect; + private String MultiCollect; + private String acqCycle; + private String upCycle; + private String sleepStartTime; + + private String acqStartFlow ; //流量采集开始时间 + private Long intervalFlow; //流量采集采集间隔(分) + private Long acqTimesFlow ;//流量采集次数 + private String upStartFlow; //流量上报开始时间 + private Long upTimesFlow; //流量上传次数 + private String acqStartNoise; //噪声采集开始时间 + private Long intervalNoise; //噪声采集采集间隔(分) + private Long acqTimesNoise;//噪声采集次数 + private String upStartNoise; //噪声上报开始时间 + private Long upTimesNoise ;//噪声上传次数 + private String acqStartPressure; //压力采集开始时间 + private Long intervalPressure;//压力采集采集间隔(分) + private Long acqTimesPressure; //压力采集次数 + private String upStartPressure; //压力上报开始时间 + private Long upTimesPressure; //压力上传次数 + private Float lowerLimitPressure; //压力报警下限 + private Float upperLimitPressure ;//压力报警下限 + private Long limitDig ;//开挖阈值 + private Float threshold ;//开挖阈值 +} diff --git a/src/main/java/com/casic/model/DataPressure.java b/src/main/java/com/casic/model/DataPressure.java new file mode 100644 index 0000000..8270c70 --- /dev/null +++ b/src/main/java/com/casic/model/DataPressure.java @@ -0,0 +1,33 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("data_temp_press") +public class DataPressure { + + @TableId(value = "ID", type = IdType.AUTO) + private String id; + private String wellCode; + private String devcode; + private Float cell; + private String temperature; + + private String press; + private String descn; + private String uptime; + private String logtime; + /** + * 信号强度 + */ + private String pci; + + private String rsrp; + private String snr; + +} diff --git a/src/main/java/com/casic/model/PressureDataParam.java b/src/main/java/com/casic/model/PressureDataParam.java new file mode 100644 index 0000000..f42770d --- /dev/null +++ b/src/main/java/com/casic/model/PressureDataParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class PressureDataParam { + private String flag; + private String deviceUserid; + private String parentUserId; + private Object sensorsDates; + private String time; + private String rawData; + private String deviceId; +} + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..50f4a19 --- /dev/null +++ b/pom.xml @@ -0,0 +1,161 @@ + + + 4.0.0 + + com.casic + smartwell-demos + 1.0-SNAPSHOT + + + + + jdk-1.8 + + true + 1.8 + + + 1.8 + 1.8 + 1.8 + + + + + + + + + + org.springframework.boot + spring-boot-starter + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-tomcat + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-web + 2.4.5 + + + + + org.springframework.boot + spring-boot-starter-jdbc + 2.4.5 + + + + mysql + mysql-connector-java + 8.0.16 + compile + + + + com.baomidou + mybatis-plus-boot-starter + 3.4.3 + + + + org.projectlombok + lombok + 1.18.20 + + + + + com.alibaba + druid + 1.2.6 + + + + com.alibaba + fastjson + 1.2.73 + + + + commons-codec + commons-codec + 1.14 + + + + redis.clients + jedis + 3.1.0 + jar + + + + org.springframework.data + spring-data-redis + 2.4.8 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.3.RELEASE + + true + + com.casic.CasicApplication + exec + + + + + repackage + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + false + + + + + + + + src/main/resources + + + /config/*/* + /config/*-*.yml + + true + + + src/main/resources + + **/*.xml + + true + + + + + \ No newline at end of file diff --git a/src/main/java/com/casic/CasicApplication.java b/src/main/java/com/casic/CasicApplication.java new file mode 100644 index 0000000..9afd0b9 --- /dev/null +++ b/src/main/java/com/casic/CasicApplication.java @@ -0,0 +1,28 @@ +package com.casic; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.transaction.annotation.EnableTransactionManagement; + + +/** + * SpringBoot方式启动类 + * + * @author cz + * @Date 2022/09/08 14:28 + */ + +@Slf4j +@ComponentScan(basePackages= "com.casic.**") +@SpringBootApplication +public class CasicApplication { + public static void main(String[] args) { + log.info("CasicApplication is success!"); + SpringApplication.run(CasicApplication.class, args); + } +} diff --git a/src/main/java/com/casic/config/CorsConfig.java b/src/main/java/com/casic/config/CorsConfig.java new file mode 100644 index 0000000..7d19680 --- /dev/null +++ b/src/main/java/com/casic/config/CorsConfig.java @@ -0,0 +1,31 @@ +package com.casic.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +/** + * 基础框架 - 跨域请求配置 + */ +@Configuration +public class CorsConfig { + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", buildConfig()); + return new CorsFilter(source); + } + + private CorsConfiguration buildConfig() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + // 1允许任何域名使用 + corsConfiguration.addAllowedOrigin("*"); + // 2允许任何头 + corsConfiguration.addAllowedHeader("*"); + // 3允许任何方法(post、get等) + corsConfiguration.addAllowedMethod("*"); + return corsConfiguration; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/controller/AlarmController.java b/src/main/java/com/casic/controller/AlarmController.java new file mode 100644 index 0000000..957fc36 --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.model.AlarmConfigParam; +import com.casic.service.AlarmService; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/alarm") +public class AlarmController { + + private final AlarmService alarmService; + + public AlarmController(AlarmService alarmService) { + this.alarmService = alarmService; + } + + @RequestMapping("/records") + public Object getAlarmRecord(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "devcode",required =false) String devcode, + @RequestParam(value = "pageSize", required = true) Integer pageSize) { + return alarmService.getAlarmRecord(deviceType,currentIndex,pageSize,devcode); + } + + @RequestMapping("/batch/cancel") + public Object excuteAlramBatchCancel(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "devcode",required =false) String devcode) { + return alarmService.excuteAlramBatchCancel(deviceType,devcode); + } + + @RequestMapping("/config/add") + public Object addAlarmConfig(@RequestBody AlarmConfigParam alarmConfigParam) { + return alarmService.addAlarmConfig(alarmConfigParam); + } +} diff --git a/src/main/java/com/casic/controller/DeviceDataController.java b/src/main/java/com/casic/controller/DeviceDataController.java new file mode 100644 index 0000000..3498b04 --- /dev/null +++ b/src/main/java/com/casic/controller/DeviceDataController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.service.DeviceDataService; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/device") +public class DeviceDataController { + private final DeviceDataService deviceDataService; + + public DeviceDataController(DeviceDataService deviceDataService) { + this.deviceDataService = deviceDataService; + } + + @RequestMapping("/recent-data") + public Object getDeviceRecentData(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "recentNum", required = true) String recentNum, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceRecentData(deviceType, recentNum, devcode); + } + + @RequestMapping("/data/list-page") + public Object getDeviceListPage(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "pageSize", required = true) Integer pageSize, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceListPage(deviceType, currentIndex, pageSize, devcode); + } + + @RequestMapping("/level/{deviceType}") + public Object getLevelList(@PathVariable("deviceType")String deviceType) { + return deviceDataService.getLevel(deviceType); + } + +} diff --git a/src/main/java/com/casic/controller/ThirdDataController.java b/src/main/java/com/casic/controller/ThirdDataController.java new file mode 100644 index 0000000..b9b2b42 --- /dev/null +++ b/src/main/java/com/casic/controller/ThirdDataController.java @@ -0,0 +1,28 @@ +package com.casic.controller; + +import com.casic.model.PressureDataParam; +import com.casic.service.ThirdDataService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +@RestController +@RequestMapping("/push") +@Slf4j +public class ThirdDataController { + + private final ThirdDataService thirdDataService; + + public ThirdDataController(ThirdDataService thirdDataService) { + this.thirdDataService = thirdDataService; + } + + @RequestMapping("/pressure/data") + public Object getDeviceRecentData(@RequestBody PressureDataParam pressureData) { + return thirdDataService.getDeviceRecentData(pressureData); + } + +} diff --git a/src/main/java/com/casic/dao/AlarmMapper.java b/src/main/java/com/casic/dao/AlarmMapper.java new file mode 100644 index 0000000..a442e3a --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmMapper.java @@ -0,0 +1,28 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmLevel; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + +@Mapper +public interface AlarmMapper extends BaseMapper { + + List> getAlarmRecord(@Param("deviceType") String deviceType, + @Param("devcode") String devcode, + @Param("currentIndex") Integer currentIndex, @Param("pageSize") Integer pageSize); + + Integer getAlarmTotalRecord(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteAlramBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteJobBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + String getDeviceDevcode(@Param("deviceType") String deviceType); + + String getDeviceByDevcode(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + +} diff --git a/src/main/java/com/casic/dao/BusConfigMapper.java b/src/main/java/com/casic/dao/BusConfigMapper.java new file mode 100644 index 0000000..ccf76da --- /dev/null +++ b/src/main/java/com/casic/dao/BusConfigMapper.java @@ -0,0 +1,9 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.BusConfig; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface BusConfigMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/dao/DataPressureMapper.java b/src/main/java/com/casic/dao/DataPressureMapper.java new file mode 100644 index 0000000..05f4329 --- /dev/null +++ b/src/main/java/com/casic/dao/DataPressureMapper.java @@ -0,0 +1,19 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.DataPressure; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.Date; + +@Mapper +public interface DataPressureMapper extends BaseMapper { + + String getWellCode(@Param("devcode") String devcode); + + Float getRuleValue(@Param("deviceType") String deviceType); + + void saveRecords(@Param("reValue") String reValue, @Param("alarmTime") Date alarmTime); + +} diff --git a/src/main/java/com/casic/dao/DeviceDataMapper.java b/src/main/java/com/casic/dao/DeviceDataMapper.java new file mode 100644 index 0000000..d9e18a0 --- /dev/null +++ b/src/main/java/com/casic/dao/DeviceDataMapper.java @@ -0,0 +1,27 @@ +package com.casic.dao; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + + +@Mapper +public interface DeviceDataMapper { + + List> getDeviceRecentData(@Param("tableName") String tableName, + @Param("recentNum") String recentNum, + @Param("fields") String fields, + @Param("devcode") String devcode); + + Integer getDeviceDataTotal(@Param("tableName") String tableName, @Param("devcode") String devcode); + + List> getDeviceDataListPage(@Param("tableName") String tableName, + @Param("currentIndex") Integer currentIndex, + @Param("fields") String fields, + @Param("pageSize") Integer pageSize, + @Param("devcode") String devcode); + + String getLevelByType(@Param("deviceType")String deviceType); +} diff --git a/src/main/java/com/casic/model/AlarmConfigParam.java b/src/main/java/com/casic/model/AlarmConfigParam.java new file mode 100644 index 0000000..28150d6 --- /dev/null +++ b/src/main/java/com/casic/model/AlarmConfigParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class AlarmConfigParam { + private String deviceType; + private String thresholdVol; + private String collectInterval; + private String uploadCycle; + private String retryNum; + private String ip; + private String port; + private String devcode; +} diff --git a/src/main/java/com/casic/model/AlarmLevel.java b/src/main/java/com/casic/model/AlarmLevel.java new file mode 100644 index 0000000..d0909af --- /dev/null +++ b/src/main/java/com/casic/model/AlarmLevel.java @@ -0,0 +1,26 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("alarm_level") +public class AlarmLevel{ + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + private String name; + private String deviceType; + private Integer level; + private Float lowValue; + private Float highValue; + private String openAlarm; + private String openJob; + private Date ts; + private String tenantId; + +} diff --git a/src/main/java/com/casic/model/BusConfig.java b/src/main/java/com/casic/model/BusConfig.java new file mode 100644 index 0000000..c6b7b50 --- /dev/null +++ b/src/main/java/com/casic/model/BusConfig.java @@ -0,0 +1,27 @@ +package com.casic.model; + + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +import java.util.Date; + +@Data +public class BusConfig { + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + + private String deviceId; + private String framecontent; + private String sensorid; + private String sensorcode; + + private String status; + private Integer attemptsmax; + private Integer attemptscurrent; + private Date sendtime; + private Date writetime; + +} diff --git a/src/main/java/com/casic/model/CommConfigDTO.java b/src/main/java/com/casic/model/CommConfigDTO.java new file mode 100644 index 0000000..7da699c --- /dev/null +++ b/src/main/java/com/casic/model/CommConfigDTO.java @@ -0,0 +1,41 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class CommConfigDTO { + private String acqStart;//采集开始时间 + private Long interval;//采集时间间隔(分钟) + private Long period;//上传周期 + private Long times;//采集次数 + private Long repeat;//重传次数 + private String ip; + private Long port; + private Float thresh; + private Float height; + private String collect; + private String MultiCollect; + private String acqCycle; + private String upCycle; + private String sleepStartTime; + + private String acqStartFlow ; //流量采集开始时间 + private Long intervalFlow; //流量采集采集间隔(分) + private Long acqTimesFlow ;//流量采集次数 + private String upStartFlow; //流量上报开始时间 + private Long upTimesFlow; //流量上传次数 + private String acqStartNoise; //噪声采集开始时间 + private Long intervalNoise; //噪声采集采集间隔(分) + private Long acqTimesNoise;//噪声采集次数 + private String upStartNoise; //噪声上报开始时间 + private Long upTimesNoise ;//噪声上传次数 + private String acqStartPressure; //压力采集开始时间 + private Long intervalPressure;//压力采集采集间隔(分) + private Long acqTimesPressure; //压力采集次数 + private String upStartPressure; //压力上报开始时间 + private Long upTimesPressure; //压力上传次数 + private Float lowerLimitPressure; //压力报警下限 + private Float upperLimitPressure ;//压力报警下限 + private Long limitDig ;//开挖阈值 + private Float threshold ;//开挖阈值 +} diff --git a/src/main/java/com/casic/model/DataPressure.java b/src/main/java/com/casic/model/DataPressure.java new file mode 100644 index 0000000..8270c70 --- /dev/null +++ b/src/main/java/com/casic/model/DataPressure.java @@ -0,0 +1,33 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("data_temp_press") +public class DataPressure { + + @TableId(value = "ID", type = IdType.AUTO) + private String id; + private String wellCode; + private String devcode; + private Float cell; + private String temperature; + + private String press; + private String descn; + private String uptime; + private String logtime; + /** + * 信号强度 + */ + private String pci; + + private String rsrp; + private String snr; + +} diff --git a/src/main/java/com/casic/model/PressureDataParam.java b/src/main/java/com/casic/model/PressureDataParam.java new file mode 100644 index 0000000..f42770d --- /dev/null +++ b/src/main/java/com/casic/model/PressureDataParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class PressureDataParam { + private String flag; + private String deviceUserid; + private String parentUserId; + private Object sensorsDates; + private String time; + private String rawData; + private String deviceId; +} + diff --git a/src/main/java/com/casic/model/ResponseData.java b/src/main/java/com/casic/model/ResponseData.java new file mode 100644 index 0000000..245ab04 --- /dev/null +++ b/src/main/java/com/casic/model/ResponseData.java @@ -0,0 +1,18 @@ +package com.casic.model; + +import lombok.Data; + +/** + * @author cz + * @date 2022-8-12 + */ +@Data +public class ResponseData { + public static final String DEFAULT_SUCCESS_MESSAGE = "请求成功"; + public static final String DEFAULT_ERROR_MESSAGE = "网络异常"; + public static final Integer DEFAULT_SUCCESS_CODE = 200; + public static final Integer DEFAULT_ERROR_CODE = 500; + private Integer code; + private String message; + private Object data; +} \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..50f4a19 --- /dev/null +++ b/pom.xml @@ -0,0 +1,161 @@ + + + 4.0.0 + + com.casic + smartwell-demos + 1.0-SNAPSHOT + + + + + jdk-1.8 + + true + 1.8 + + + 1.8 + 1.8 + 1.8 + + + + + + + + + + org.springframework.boot + spring-boot-starter + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-tomcat + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-web + 2.4.5 + + + + + org.springframework.boot + spring-boot-starter-jdbc + 2.4.5 + + + + mysql + mysql-connector-java + 8.0.16 + compile + + + + com.baomidou + mybatis-plus-boot-starter + 3.4.3 + + + + org.projectlombok + lombok + 1.18.20 + + + + + com.alibaba + druid + 1.2.6 + + + + com.alibaba + fastjson + 1.2.73 + + + + commons-codec + commons-codec + 1.14 + + + + redis.clients + jedis + 3.1.0 + jar + + + + org.springframework.data + spring-data-redis + 2.4.8 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.3.RELEASE + + true + + com.casic.CasicApplication + exec + + + + + repackage + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + false + + + + + + + + src/main/resources + + + /config/*/* + /config/*-*.yml + + true + + + src/main/resources + + **/*.xml + + true + + + + + \ No newline at end of file diff --git a/src/main/java/com/casic/CasicApplication.java b/src/main/java/com/casic/CasicApplication.java new file mode 100644 index 0000000..9afd0b9 --- /dev/null +++ b/src/main/java/com/casic/CasicApplication.java @@ -0,0 +1,28 @@ +package com.casic; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.transaction.annotation.EnableTransactionManagement; + + +/** + * SpringBoot方式启动类 + * + * @author cz + * @Date 2022/09/08 14:28 + */ + +@Slf4j +@ComponentScan(basePackages= "com.casic.**") +@SpringBootApplication +public class CasicApplication { + public static void main(String[] args) { + log.info("CasicApplication is success!"); + SpringApplication.run(CasicApplication.class, args); + } +} diff --git a/src/main/java/com/casic/config/CorsConfig.java b/src/main/java/com/casic/config/CorsConfig.java new file mode 100644 index 0000000..7d19680 --- /dev/null +++ b/src/main/java/com/casic/config/CorsConfig.java @@ -0,0 +1,31 @@ +package com.casic.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +/** + * 基础框架 - 跨域请求配置 + */ +@Configuration +public class CorsConfig { + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", buildConfig()); + return new CorsFilter(source); + } + + private CorsConfiguration buildConfig() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + // 1允许任何域名使用 + corsConfiguration.addAllowedOrigin("*"); + // 2允许任何头 + corsConfiguration.addAllowedHeader("*"); + // 3允许任何方法(post、get等) + corsConfiguration.addAllowedMethod("*"); + return corsConfiguration; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/controller/AlarmController.java b/src/main/java/com/casic/controller/AlarmController.java new file mode 100644 index 0000000..957fc36 --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.model.AlarmConfigParam; +import com.casic.service.AlarmService; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/alarm") +public class AlarmController { + + private final AlarmService alarmService; + + public AlarmController(AlarmService alarmService) { + this.alarmService = alarmService; + } + + @RequestMapping("/records") + public Object getAlarmRecord(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "devcode",required =false) String devcode, + @RequestParam(value = "pageSize", required = true) Integer pageSize) { + return alarmService.getAlarmRecord(deviceType,currentIndex,pageSize,devcode); + } + + @RequestMapping("/batch/cancel") + public Object excuteAlramBatchCancel(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "devcode",required =false) String devcode) { + return alarmService.excuteAlramBatchCancel(deviceType,devcode); + } + + @RequestMapping("/config/add") + public Object addAlarmConfig(@RequestBody AlarmConfigParam alarmConfigParam) { + return alarmService.addAlarmConfig(alarmConfigParam); + } +} diff --git a/src/main/java/com/casic/controller/DeviceDataController.java b/src/main/java/com/casic/controller/DeviceDataController.java new file mode 100644 index 0000000..3498b04 --- /dev/null +++ b/src/main/java/com/casic/controller/DeviceDataController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.service.DeviceDataService; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/device") +public class DeviceDataController { + private final DeviceDataService deviceDataService; + + public DeviceDataController(DeviceDataService deviceDataService) { + this.deviceDataService = deviceDataService; + } + + @RequestMapping("/recent-data") + public Object getDeviceRecentData(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "recentNum", required = true) String recentNum, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceRecentData(deviceType, recentNum, devcode); + } + + @RequestMapping("/data/list-page") + public Object getDeviceListPage(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "pageSize", required = true) Integer pageSize, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceListPage(deviceType, currentIndex, pageSize, devcode); + } + + @RequestMapping("/level/{deviceType}") + public Object getLevelList(@PathVariable("deviceType")String deviceType) { + return deviceDataService.getLevel(deviceType); + } + +} diff --git a/src/main/java/com/casic/controller/ThirdDataController.java b/src/main/java/com/casic/controller/ThirdDataController.java new file mode 100644 index 0000000..b9b2b42 --- /dev/null +++ b/src/main/java/com/casic/controller/ThirdDataController.java @@ -0,0 +1,28 @@ +package com.casic.controller; + +import com.casic.model.PressureDataParam; +import com.casic.service.ThirdDataService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +@RestController +@RequestMapping("/push") +@Slf4j +public class ThirdDataController { + + private final ThirdDataService thirdDataService; + + public ThirdDataController(ThirdDataService thirdDataService) { + this.thirdDataService = thirdDataService; + } + + @RequestMapping("/pressure/data") + public Object getDeviceRecentData(@RequestBody PressureDataParam pressureData) { + return thirdDataService.getDeviceRecentData(pressureData); + } + +} diff --git a/src/main/java/com/casic/dao/AlarmMapper.java b/src/main/java/com/casic/dao/AlarmMapper.java new file mode 100644 index 0000000..a442e3a --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmMapper.java @@ -0,0 +1,28 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmLevel; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + +@Mapper +public interface AlarmMapper extends BaseMapper { + + List> getAlarmRecord(@Param("deviceType") String deviceType, + @Param("devcode") String devcode, + @Param("currentIndex") Integer currentIndex, @Param("pageSize") Integer pageSize); + + Integer getAlarmTotalRecord(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteAlramBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteJobBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + String getDeviceDevcode(@Param("deviceType") String deviceType); + + String getDeviceByDevcode(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + +} diff --git a/src/main/java/com/casic/dao/BusConfigMapper.java b/src/main/java/com/casic/dao/BusConfigMapper.java new file mode 100644 index 0000000..ccf76da --- /dev/null +++ b/src/main/java/com/casic/dao/BusConfigMapper.java @@ -0,0 +1,9 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.BusConfig; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface BusConfigMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/dao/DataPressureMapper.java b/src/main/java/com/casic/dao/DataPressureMapper.java new file mode 100644 index 0000000..05f4329 --- /dev/null +++ b/src/main/java/com/casic/dao/DataPressureMapper.java @@ -0,0 +1,19 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.DataPressure; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.Date; + +@Mapper +public interface DataPressureMapper extends BaseMapper { + + String getWellCode(@Param("devcode") String devcode); + + Float getRuleValue(@Param("deviceType") String deviceType); + + void saveRecords(@Param("reValue") String reValue, @Param("alarmTime") Date alarmTime); + +} diff --git a/src/main/java/com/casic/dao/DeviceDataMapper.java b/src/main/java/com/casic/dao/DeviceDataMapper.java new file mode 100644 index 0000000..d9e18a0 --- /dev/null +++ b/src/main/java/com/casic/dao/DeviceDataMapper.java @@ -0,0 +1,27 @@ +package com.casic.dao; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + + +@Mapper +public interface DeviceDataMapper { + + List> getDeviceRecentData(@Param("tableName") String tableName, + @Param("recentNum") String recentNum, + @Param("fields") String fields, + @Param("devcode") String devcode); + + Integer getDeviceDataTotal(@Param("tableName") String tableName, @Param("devcode") String devcode); + + List> getDeviceDataListPage(@Param("tableName") String tableName, + @Param("currentIndex") Integer currentIndex, + @Param("fields") String fields, + @Param("pageSize") Integer pageSize, + @Param("devcode") String devcode); + + String getLevelByType(@Param("deviceType")String deviceType); +} diff --git a/src/main/java/com/casic/model/AlarmConfigParam.java b/src/main/java/com/casic/model/AlarmConfigParam.java new file mode 100644 index 0000000..28150d6 --- /dev/null +++ b/src/main/java/com/casic/model/AlarmConfigParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class AlarmConfigParam { + private String deviceType; + private String thresholdVol; + private String collectInterval; + private String uploadCycle; + private String retryNum; + private String ip; + private String port; + private String devcode; +} diff --git a/src/main/java/com/casic/model/AlarmLevel.java b/src/main/java/com/casic/model/AlarmLevel.java new file mode 100644 index 0000000..d0909af --- /dev/null +++ b/src/main/java/com/casic/model/AlarmLevel.java @@ -0,0 +1,26 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("alarm_level") +public class AlarmLevel{ + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + private String name; + private String deviceType; + private Integer level; + private Float lowValue; + private Float highValue; + private String openAlarm; + private String openJob; + private Date ts; + private String tenantId; + +} diff --git a/src/main/java/com/casic/model/BusConfig.java b/src/main/java/com/casic/model/BusConfig.java new file mode 100644 index 0000000..c6b7b50 --- /dev/null +++ b/src/main/java/com/casic/model/BusConfig.java @@ -0,0 +1,27 @@ +package com.casic.model; + + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +import java.util.Date; + +@Data +public class BusConfig { + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + + private String deviceId; + private String framecontent; + private String sensorid; + private String sensorcode; + + private String status; + private Integer attemptsmax; + private Integer attemptscurrent; + private Date sendtime; + private Date writetime; + +} diff --git a/src/main/java/com/casic/model/CommConfigDTO.java b/src/main/java/com/casic/model/CommConfigDTO.java new file mode 100644 index 0000000..7da699c --- /dev/null +++ b/src/main/java/com/casic/model/CommConfigDTO.java @@ -0,0 +1,41 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class CommConfigDTO { + private String acqStart;//采集开始时间 + private Long interval;//采集时间间隔(分钟) + private Long period;//上传周期 + private Long times;//采集次数 + private Long repeat;//重传次数 + private String ip; + private Long port; + private Float thresh; + private Float height; + private String collect; + private String MultiCollect; + private String acqCycle; + private String upCycle; + private String sleepStartTime; + + private String acqStartFlow ; //流量采集开始时间 + private Long intervalFlow; //流量采集采集间隔(分) + private Long acqTimesFlow ;//流量采集次数 + private String upStartFlow; //流量上报开始时间 + private Long upTimesFlow; //流量上传次数 + private String acqStartNoise; //噪声采集开始时间 + private Long intervalNoise; //噪声采集采集间隔(分) + private Long acqTimesNoise;//噪声采集次数 + private String upStartNoise; //噪声上报开始时间 + private Long upTimesNoise ;//噪声上传次数 + private String acqStartPressure; //压力采集开始时间 + private Long intervalPressure;//压力采集采集间隔(分) + private Long acqTimesPressure; //压力采集次数 + private String upStartPressure; //压力上报开始时间 + private Long upTimesPressure; //压力上传次数 + private Float lowerLimitPressure; //压力报警下限 + private Float upperLimitPressure ;//压力报警下限 + private Long limitDig ;//开挖阈值 + private Float threshold ;//开挖阈值 +} diff --git a/src/main/java/com/casic/model/DataPressure.java b/src/main/java/com/casic/model/DataPressure.java new file mode 100644 index 0000000..8270c70 --- /dev/null +++ b/src/main/java/com/casic/model/DataPressure.java @@ -0,0 +1,33 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("data_temp_press") +public class DataPressure { + + @TableId(value = "ID", type = IdType.AUTO) + private String id; + private String wellCode; + private String devcode; + private Float cell; + private String temperature; + + private String press; + private String descn; + private String uptime; + private String logtime; + /** + * 信号强度 + */ + private String pci; + + private String rsrp; + private String snr; + +} diff --git a/src/main/java/com/casic/model/PressureDataParam.java b/src/main/java/com/casic/model/PressureDataParam.java new file mode 100644 index 0000000..f42770d --- /dev/null +++ b/src/main/java/com/casic/model/PressureDataParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class PressureDataParam { + private String flag; + private String deviceUserid; + private String parentUserId; + private Object sensorsDates; + private String time; + private String rawData; + private String deviceId; +} + diff --git a/src/main/java/com/casic/model/ResponseData.java b/src/main/java/com/casic/model/ResponseData.java new file mode 100644 index 0000000..245ab04 --- /dev/null +++ b/src/main/java/com/casic/model/ResponseData.java @@ -0,0 +1,18 @@ +package com.casic.model; + +import lombok.Data; + +/** + * @author cz + * @date 2022-8-12 + */ +@Data +public class ResponseData { + public static final String DEFAULT_SUCCESS_MESSAGE = "请求成功"; + public static final String DEFAULT_ERROR_MESSAGE = "网络异常"; + public static final Integer DEFAULT_SUCCESS_CODE = 200; + public static final Integer DEFAULT_ERROR_CODE = 500; + private Integer code; + private String message; + private Object data; +} \ No newline at end of file diff --git a/src/main/java/com/casic/service/AlarmService.java b/src/main/java/com/casic/service/AlarmService.java new file mode 100644 index 0000000..8516b41 --- /dev/null +++ b/src/main/java/com/casic/service/AlarmService.java @@ -0,0 +1,12 @@ +package com.casic.service; + +import com.casic.model.AlarmConfigParam; + +public interface AlarmService { + + Object getAlarmRecord(String deviceType,Integer currentIndex,Integer pageSize,String devcode); + + Object excuteAlramBatchCancel(String deviceType,String devcode); + + Object addAlarmConfig(AlarmConfigParam alarmConfig); +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..50f4a19 --- /dev/null +++ b/pom.xml @@ -0,0 +1,161 @@ + + + 4.0.0 + + com.casic + smartwell-demos + 1.0-SNAPSHOT + + + + + jdk-1.8 + + true + 1.8 + + + 1.8 + 1.8 + 1.8 + + + + + + + + + + org.springframework.boot + spring-boot-starter + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-tomcat + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-web + 2.4.5 + + + + + org.springframework.boot + spring-boot-starter-jdbc + 2.4.5 + + + + mysql + mysql-connector-java + 8.0.16 + compile + + + + com.baomidou + mybatis-plus-boot-starter + 3.4.3 + + + + org.projectlombok + lombok + 1.18.20 + + + + + com.alibaba + druid + 1.2.6 + + + + com.alibaba + fastjson + 1.2.73 + + + + commons-codec + commons-codec + 1.14 + + + + redis.clients + jedis + 3.1.0 + jar + + + + org.springframework.data + spring-data-redis + 2.4.8 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.3.RELEASE + + true + + com.casic.CasicApplication + exec + + + + + repackage + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + false + + + + + + + + src/main/resources + + + /config/*/* + /config/*-*.yml + + true + + + src/main/resources + + **/*.xml + + true + + + + + \ No newline at end of file diff --git a/src/main/java/com/casic/CasicApplication.java b/src/main/java/com/casic/CasicApplication.java new file mode 100644 index 0000000..9afd0b9 --- /dev/null +++ b/src/main/java/com/casic/CasicApplication.java @@ -0,0 +1,28 @@ +package com.casic; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.transaction.annotation.EnableTransactionManagement; + + +/** + * SpringBoot方式启动类 + * + * @author cz + * @Date 2022/09/08 14:28 + */ + +@Slf4j +@ComponentScan(basePackages= "com.casic.**") +@SpringBootApplication +public class CasicApplication { + public static void main(String[] args) { + log.info("CasicApplication is success!"); + SpringApplication.run(CasicApplication.class, args); + } +} diff --git a/src/main/java/com/casic/config/CorsConfig.java b/src/main/java/com/casic/config/CorsConfig.java new file mode 100644 index 0000000..7d19680 --- /dev/null +++ b/src/main/java/com/casic/config/CorsConfig.java @@ -0,0 +1,31 @@ +package com.casic.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +/** + * 基础框架 - 跨域请求配置 + */ +@Configuration +public class CorsConfig { + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", buildConfig()); + return new CorsFilter(source); + } + + private CorsConfiguration buildConfig() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + // 1允许任何域名使用 + corsConfiguration.addAllowedOrigin("*"); + // 2允许任何头 + corsConfiguration.addAllowedHeader("*"); + // 3允许任何方法(post、get等) + corsConfiguration.addAllowedMethod("*"); + return corsConfiguration; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/controller/AlarmController.java b/src/main/java/com/casic/controller/AlarmController.java new file mode 100644 index 0000000..957fc36 --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.model.AlarmConfigParam; +import com.casic.service.AlarmService; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/alarm") +public class AlarmController { + + private final AlarmService alarmService; + + public AlarmController(AlarmService alarmService) { + this.alarmService = alarmService; + } + + @RequestMapping("/records") + public Object getAlarmRecord(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "devcode",required =false) String devcode, + @RequestParam(value = "pageSize", required = true) Integer pageSize) { + return alarmService.getAlarmRecord(deviceType,currentIndex,pageSize,devcode); + } + + @RequestMapping("/batch/cancel") + public Object excuteAlramBatchCancel(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "devcode",required =false) String devcode) { + return alarmService.excuteAlramBatchCancel(deviceType,devcode); + } + + @RequestMapping("/config/add") + public Object addAlarmConfig(@RequestBody AlarmConfigParam alarmConfigParam) { + return alarmService.addAlarmConfig(alarmConfigParam); + } +} diff --git a/src/main/java/com/casic/controller/DeviceDataController.java b/src/main/java/com/casic/controller/DeviceDataController.java new file mode 100644 index 0000000..3498b04 --- /dev/null +++ b/src/main/java/com/casic/controller/DeviceDataController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.service.DeviceDataService; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/device") +public class DeviceDataController { + private final DeviceDataService deviceDataService; + + public DeviceDataController(DeviceDataService deviceDataService) { + this.deviceDataService = deviceDataService; + } + + @RequestMapping("/recent-data") + public Object getDeviceRecentData(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "recentNum", required = true) String recentNum, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceRecentData(deviceType, recentNum, devcode); + } + + @RequestMapping("/data/list-page") + public Object getDeviceListPage(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "pageSize", required = true) Integer pageSize, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceListPage(deviceType, currentIndex, pageSize, devcode); + } + + @RequestMapping("/level/{deviceType}") + public Object getLevelList(@PathVariable("deviceType")String deviceType) { + return deviceDataService.getLevel(deviceType); + } + +} diff --git a/src/main/java/com/casic/controller/ThirdDataController.java b/src/main/java/com/casic/controller/ThirdDataController.java new file mode 100644 index 0000000..b9b2b42 --- /dev/null +++ b/src/main/java/com/casic/controller/ThirdDataController.java @@ -0,0 +1,28 @@ +package com.casic.controller; + +import com.casic.model.PressureDataParam; +import com.casic.service.ThirdDataService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +@RestController +@RequestMapping("/push") +@Slf4j +public class ThirdDataController { + + private final ThirdDataService thirdDataService; + + public ThirdDataController(ThirdDataService thirdDataService) { + this.thirdDataService = thirdDataService; + } + + @RequestMapping("/pressure/data") + public Object getDeviceRecentData(@RequestBody PressureDataParam pressureData) { + return thirdDataService.getDeviceRecentData(pressureData); + } + +} diff --git a/src/main/java/com/casic/dao/AlarmMapper.java b/src/main/java/com/casic/dao/AlarmMapper.java new file mode 100644 index 0000000..a442e3a --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmMapper.java @@ -0,0 +1,28 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmLevel; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + +@Mapper +public interface AlarmMapper extends BaseMapper { + + List> getAlarmRecord(@Param("deviceType") String deviceType, + @Param("devcode") String devcode, + @Param("currentIndex") Integer currentIndex, @Param("pageSize") Integer pageSize); + + Integer getAlarmTotalRecord(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteAlramBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteJobBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + String getDeviceDevcode(@Param("deviceType") String deviceType); + + String getDeviceByDevcode(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + +} diff --git a/src/main/java/com/casic/dao/BusConfigMapper.java b/src/main/java/com/casic/dao/BusConfigMapper.java new file mode 100644 index 0000000..ccf76da --- /dev/null +++ b/src/main/java/com/casic/dao/BusConfigMapper.java @@ -0,0 +1,9 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.BusConfig; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface BusConfigMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/dao/DataPressureMapper.java b/src/main/java/com/casic/dao/DataPressureMapper.java new file mode 100644 index 0000000..05f4329 --- /dev/null +++ b/src/main/java/com/casic/dao/DataPressureMapper.java @@ -0,0 +1,19 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.DataPressure; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.Date; + +@Mapper +public interface DataPressureMapper extends BaseMapper { + + String getWellCode(@Param("devcode") String devcode); + + Float getRuleValue(@Param("deviceType") String deviceType); + + void saveRecords(@Param("reValue") String reValue, @Param("alarmTime") Date alarmTime); + +} diff --git a/src/main/java/com/casic/dao/DeviceDataMapper.java b/src/main/java/com/casic/dao/DeviceDataMapper.java new file mode 100644 index 0000000..d9e18a0 --- /dev/null +++ b/src/main/java/com/casic/dao/DeviceDataMapper.java @@ -0,0 +1,27 @@ +package com.casic.dao; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + + +@Mapper +public interface DeviceDataMapper { + + List> getDeviceRecentData(@Param("tableName") String tableName, + @Param("recentNum") String recentNum, + @Param("fields") String fields, + @Param("devcode") String devcode); + + Integer getDeviceDataTotal(@Param("tableName") String tableName, @Param("devcode") String devcode); + + List> getDeviceDataListPage(@Param("tableName") String tableName, + @Param("currentIndex") Integer currentIndex, + @Param("fields") String fields, + @Param("pageSize") Integer pageSize, + @Param("devcode") String devcode); + + String getLevelByType(@Param("deviceType")String deviceType); +} diff --git a/src/main/java/com/casic/model/AlarmConfigParam.java b/src/main/java/com/casic/model/AlarmConfigParam.java new file mode 100644 index 0000000..28150d6 --- /dev/null +++ b/src/main/java/com/casic/model/AlarmConfigParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class AlarmConfigParam { + private String deviceType; + private String thresholdVol; + private String collectInterval; + private String uploadCycle; + private String retryNum; + private String ip; + private String port; + private String devcode; +} diff --git a/src/main/java/com/casic/model/AlarmLevel.java b/src/main/java/com/casic/model/AlarmLevel.java new file mode 100644 index 0000000..d0909af --- /dev/null +++ b/src/main/java/com/casic/model/AlarmLevel.java @@ -0,0 +1,26 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("alarm_level") +public class AlarmLevel{ + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + private String name; + private String deviceType; + private Integer level; + private Float lowValue; + private Float highValue; + private String openAlarm; + private String openJob; + private Date ts; + private String tenantId; + +} diff --git a/src/main/java/com/casic/model/BusConfig.java b/src/main/java/com/casic/model/BusConfig.java new file mode 100644 index 0000000..c6b7b50 --- /dev/null +++ b/src/main/java/com/casic/model/BusConfig.java @@ -0,0 +1,27 @@ +package com.casic.model; + + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +import java.util.Date; + +@Data +public class BusConfig { + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + + private String deviceId; + private String framecontent; + private String sensorid; + private String sensorcode; + + private String status; + private Integer attemptsmax; + private Integer attemptscurrent; + private Date sendtime; + private Date writetime; + +} diff --git a/src/main/java/com/casic/model/CommConfigDTO.java b/src/main/java/com/casic/model/CommConfigDTO.java new file mode 100644 index 0000000..7da699c --- /dev/null +++ b/src/main/java/com/casic/model/CommConfigDTO.java @@ -0,0 +1,41 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class CommConfigDTO { + private String acqStart;//采集开始时间 + private Long interval;//采集时间间隔(分钟) + private Long period;//上传周期 + private Long times;//采集次数 + private Long repeat;//重传次数 + private String ip; + private Long port; + private Float thresh; + private Float height; + private String collect; + private String MultiCollect; + private String acqCycle; + private String upCycle; + private String sleepStartTime; + + private String acqStartFlow ; //流量采集开始时间 + private Long intervalFlow; //流量采集采集间隔(分) + private Long acqTimesFlow ;//流量采集次数 + private String upStartFlow; //流量上报开始时间 + private Long upTimesFlow; //流量上传次数 + private String acqStartNoise; //噪声采集开始时间 + private Long intervalNoise; //噪声采集采集间隔(分) + private Long acqTimesNoise;//噪声采集次数 + private String upStartNoise; //噪声上报开始时间 + private Long upTimesNoise ;//噪声上传次数 + private String acqStartPressure; //压力采集开始时间 + private Long intervalPressure;//压力采集采集间隔(分) + private Long acqTimesPressure; //压力采集次数 + private String upStartPressure; //压力上报开始时间 + private Long upTimesPressure; //压力上传次数 + private Float lowerLimitPressure; //压力报警下限 + private Float upperLimitPressure ;//压力报警下限 + private Long limitDig ;//开挖阈值 + private Float threshold ;//开挖阈值 +} diff --git a/src/main/java/com/casic/model/DataPressure.java b/src/main/java/com/casic/model/DataPressure.java new file mode 100644 index 0000000..8270c70 --- /dev/null +++ b/src/main/java/com/casic/model/DataPressure.java @@ -0,0 +1,33 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("data_temp_press") +public class DataPressure { + + @TableId(value = "ID", type = IdType.AUTO) + private String id; + private String wellCode; + private String devcode; + private Float cell; + private String temperature; + + private String press; + private String descn; + private String uptime; + private String logtime; + /** + * 信号强度 + */ + private String pci; + + private String rsrp; + private String snr; + +} diff --git a/src/main/java/com/casic/model/PressureDataParam.java b/src/main/java/com/casic/model/PressureDataParam.java new file mode 100644 index 0000000..f42770d --- /dev/null +++ b/src/main/java/com/casic/model/PressureDataParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class PressureDataParam { + private String flag; + private String deviceUserid; + private String parentUserId; + private Object sensorsDates; + private String time; + private String rawData; + private String deviceId; +} + diff --git a/src/main/java/com/casic/model/ResponseData.java b/src/main/java/com/casic/model/ResponseData.java new file mode 100644 index 0000000..245ab04 --- /dev/null +++ b/src/main/java/com/casic/model/ResponseData.java @@ -0,0 +1,18 @@ +package com.casic.model; + +import lombok.Data; + +/** + * @author cz + * @date 2022-8-12 + */ +@Data +public class ResponseData { + public static final String DEFAULT_SUCCESS_MESSAGE = "请求成功"; + public static final String DEFAULT_ERROR_MESSAGE = "网络异常"; + public static final Integer DEFAULT_SUCCESS_CODE = 200; + public static final Integer DEFAULT_ERROR_CODE = 500; + private Integer code; + private String message; + private Object data; +} \ No newline at end of file diff --git a/src/main/java/com/casic/service/AlarmService.java b/src/main/java/com/casic/service/AlarmService.java new file mode 100644 index 0000000..8516b41 --- /dev/null +++ b/src/main/java/com/casic/service/AlarmService.java @@ -0,0 +1,12 @@ +package com.casic.service; + +import com.casic.model.AlarmConfigParam; + +public interface AlarmService { + + Object getAlarmRecord(String deviceType,Integer currentIndex,Integer pageSize,String devcode); + + Object excuteAlramBatchCancel(String deviceType,String devcode); + + Object addAlarmConfig(AlarmConfigParam alarmConfig); +} diff --git a/src/main/java/com/casic/service/DeviceDataService.java b/src/main/java/com/casic/service/DeviceDataService.java new file mode 100644 index 0000000..db656c1 --- /dev/null +++ b/src/main/java/com/casic/service/DeviceDataService.java @@ -0,0 +1,10 @@ +package com.casic.service; + +public interface DeviceDataService { + + Object getDeviceRecentData(String deviceType, String recentNum, String devcode); + + Object getDeviceListPage(String deviceType, Integer currentIndex, Integer pageSize, String devcode); + + Object getLevel(String deviceType); +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..50f4a19 --- /dev/null +++ b/pom.xml @@ -0,0 +1,161 @@ + + + 4.0.0 + + com.casic + smartwell-demos + 1.0-SNAPSHOT + + + + + jdk-1.8 + + true + 1.8 + + + 1.8 + 1.8 + 1.8 + + + + + + + + + + org.springframework.boot + spring-boot-starter + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-tomcat + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-web + 2.4.5 + + + + + org.springframework.boot + spring-boot-starter-jdbc + 2.4.5 + + + + mysql + mysql-connector-java + 8.0.16 + compile + + + + com.baomidou + mybatis-plus-boot-starter + 3.4.3 + + + + org.projectlombok + lombok + 1.18.20 + + + + + com.alibaba + druid + 1.2.6 + + + + com.alibaba + fastjson + 1.2.73 + + + + commons-codec + commons-codec + 1.14 + + + + redis.clients + jedis + 3.1.0 + jar + + + + org.springframework.data + spring-data-redis + 2.4.8 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.3.RELEASE + + true + + com.casic.CasicApplication + exec + + + + + repackage + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + false + + + + + + + + src/main/resources + + + /config/*/* + /config/*-*.yml + + true + + + src/main/resources + + **/*.xml + + true + + + + + \ No newline at end of file diff --git a/src/main/java/com/casic/CasicApplication.java b/src/main/java/com/casic/CasicApplication.java new file mode 100644 index 0000000..9afd0b9 --- /dev/null +++ b/src/main/java/com/casic/CasicApplication.java @@ -0,0 +1,28 @@ +package com.casic; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.transaction.annotation.EnableTransactionManagement; + + +/** + * SpringBoot方式启动类 + * + * @author cz + * @Date 2022/09/08 14:28 + */ + +@Slf4j +@ComponentScan(basePackages= "com.casic.**") +@SpringBootApplication +public class CasicApplication { + public static void main(String[] args) { + log.info("CasicApplication is success!"); + SpringApplication.run(CasicApplication.class, args); + } +} diff --git a/src/main/java/com/casic/config/CorsConfig.java b/src/main/java/com/casic/config/CorsConfig.java new file mode 100644 index 0000000..7d19680 --- /dev/null +++ b/src/main/java/com/casic/config/CorsConfig.java @@ -0,0 +1,31 @@ +package com.casic.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +/** + * 基础框架 - 跨域请求配置 + */ +@Configuration +public class CorsConfig { + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", buildConfig()); + return new CorsFilter(source); + } + + private CorsConfiguration buildConfig() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + // 1允许任何域名使用 + corsConfiguration.addAllowedOrigin("*"); + // 2允许任何头 + corsConfiguration.addAllowedHeader("*"); + // 3允许任何方法(post、get等) + corsConfiguration.addAllowedMethod("*"); + return corsConfiguration; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/controller/AlarmController.java b/src/main/java/com/casic/controller/AlarmController.java new file mode 100644 index 0000000..957fc36 --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.model.AlarmConfigParam; +import com.casic.service.AlarmService; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/alarm") +public class AlarmController { + + private final AlarmService alarmService; + + public AlarmController(AlarmService alarmService) { + this.alarmService = alarmService; + } + + @RequestMapping("/records") + public Object getAlarmRecord(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "devcode",required =false) String devcode, + @RequestParam(value = "pageSize", required = true) Integer pageSize) { + return alarmService.getAlarmRecord(deviceType,currentIndex,pageSize,devcode); + } + + @RequestMapping("/batch/cancel") + public Object excuteAlramBatchCancel(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "devcode",required =false) String devcode) { + return alarmService.excuteAlramBatchCancel(deviceType,devcode); + } + + @RequestMapping("/config/add") + public Object addAlarmConfig(@RequestBody AlarmConfigParam alarmConfigParam) { + return alarmService.addAlarmConfig(alarmConfigParam); + } +} diff --git a/src/main/java/com/casic/controller/DeviceDataController.java b/src/main/java/com/casic/controller/DeviceDataController.java new file mode 100644 index 0000000..3498b04 --- /dev/null +++ b/src/main/java/com/casic/controller/DeviceDataController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.service.DeviceDataService; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/device") +public class DeviceDataController { + private final DeviceDataService deviceDataService; + + public DeviceDataController(DeviceDataService deviceDataService) { + this.deviceDataService = deviceDataService; + } + + @RequestMapping("/recent-data") + public Object getDeviceRecentData(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "recentNum", required = true) String recentNum, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceRecentData(deviceType, recentNum, devcode); + } + + @RequestMapping("/data/list-page") + public Object getDeviceListPage(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "pageSize", required = true) Integer pageSize, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceListPage(deviceType, currentIndex, pageSize, devcode); + } + + @RequestMapping("/level/{deviceType}") + public Object getLevelList(@PathVariable("deviceType")String deviceType) { + return deviceDataService.getLevel(deviceType); + } + +} diff --git a/src/main/java/com/casic/controller/ThirdDataController.java b/src/main/java/com/casic/controller/ThirdDataController.java new file mode 100644 index 0000000..b9b2b42 --- /dev/null +++ b/src/main/java/com/casic/controller/ThirdDataController.java @@ -0,0 +1,28 @@ +package com.casic.controller; + +import com.casic.model.PressureDataParam; +import com.casic.service.ThirdDataService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +@RestController +@RequestMapping("/push") +@Slf4j +public class ThirdDataController { + + private final ThirdDataService thirdDataService; + + public ThirdDataController(ThirdDataService thirdDataService) { + this.thirdDataService = thirdDataService; + } + + @RequestMapping("/pressure/data") + public Object getDeviceRecentData(@RequestBody PressureDataParam pressureData) { + return thirdDataService.getDeviceRecentData(pressureData); + } + +} diff --git a/src/main/java/com/casic/dao/AlarmMapper.java b/src/main/java/com/casic/dao/AlarmMapper.java new file mode 100644 index 0000000..a442e3a --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmMapper.java @@ -0,0 +1,28 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmLevel; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + +@Mapper +public interface AlarmMapper extends BaseMapper { + + List> getAlarmRecord(@Param("deviceType") String deviceType, + @Param("devcode") String devcode, + @Param("currentIndex") Integer currentIndex, @Param("pageSize") Integer pageSize); + + Integer getAlarmTotalRecord(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteAlramBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteJobBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + String getDeviceDevcode(@Param("deviceType") String deviceType); + + String getDeviceByDevcode(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + +} diff --git a/src/main/java/com/casic/dao/BusConfigMapper.java b/src/main/java/com/casic/dao/BusConfigMapper.java new file mode 100644 index 0000000..ccf76da --- /dev/null +++ b/src/main/java/com/casic/dao/BusConfigMapper.java @@ -0,0 +1,9 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.BusConfig; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface BusConfigMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/dao/DataPressureMapper.java b/src/main/java/com/casic/dao/DataPressureMapper.java new file mode 100644 index 0000000..05f4329 --- /dev/null +++ b/src/main/java/com/casic/dao/DataPressureMapper.java @@ -0,0 +1,19 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.DataPressure; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.Date; + +@Mapper +public interface DataPressureMapper extends BaseMapper { + + String getWellCode(@Param("devcode") String devcode); + + Float getRuleValue(@Param("deviceType") String deviceType); + + void saveRecords(@Param("reValue") String reValue, @Param("alarmTime") Date alarmTime); + +} diff --git a/src/main/java/com/casic/dao/DeviceDataMapper.java b/src/main/java/com/casic/dao/DeviceDataMapper.java new file mode 100644 index 0000000..d9e18a0 --- /dev/null +++ b/src/main/java/com/casic/dao/DeviceDataMapper.java @@ -0,0 +1,27 @@ +package com.casic.dao; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + + +@Mapper +public interface DeviceDataMapper { + + List> getDeviceRecentData(@Param("tableName") String tableName, + @Param("recentNum") String recentNum, + @Param("fields") String fields, + @Param("devcode") String devcode); + + Integer getDeviceDataTotal(@Param("tableName") String tableName, @Param("devcode") String devcode); + + List> getDeviceDataListPage(@Param("tableName") String tableName, + @Param("currentIndex") Integer currentIndex, + @Param("fields") String fields, + @Param("pageSize") Integer pageSize, + @Param("devcode") String devcode); + + String getLevelByType(@Param("deviceType")String deviceType); +} diff --git a/src/main/java/com/casic/model/AlarmConfigParam.java b/src/main/java/com/casic/model/AlarmConfigParam.java new file mode 100644 index 0000000..28150d6 --- /dev/null +++ b/src/main/java/com/casic/model/AlarmConfigParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class AlarmConfigParam { + private String deviceType; + private String thresholdVol; + private String collectInterval; + private String uploadCycle; + private String retryNum; + private String ip; + private String port; + private String devcode; +} diff --git a/src/main/java/com/casic/model/AlarmLevel.java b/src/main/java/com/casic/model/AlarmLevel.java new file mode 100644 index 0000000..d0909af --- /dev/null +++ b/src/main/java/com/casic/model/AlarmLevel.java @@ -0,0 +1,26 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("alarm_level") +public class AlarmLevel{ + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + private String name; + private String deviceType; + private Integer level; + private Float lowValue; + private Float highValue; + private String openAlarm; + private String openJob; + private Date ts; + private String tenantId; + +} diff --git a/src/main/java/com/casic/model/BusConfig.java b/src/main/java/com/casic/model/BusConfig.java new file mode 100644 index 0000000..c6b7b50 --- /dev/null +++ b/src/main/java/com/casic/model/BusConfig.java @@ -0,0 +1,27 @@ +package com.casic.model; + + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +import java.util.Date; + +@Data +public class BusConfig { + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + + private String deviceId; + private String framecontent; + private String sensorid; + private String sensorcode; + + private String status; + private Integer attemptsmax; + private Integer attemptscurrent; + private Date sendtime; + private Date writetime; + +} diff --git a/src/main/java/com/casic/model/CommConfigDTO.java b/src/main/java/com/casic/model/CommConfigDTO.java new file mode 100644 index 0000000..7da699c --- /dev/null +++ b/src/main/java/com/casic/model/CommConfigDTO.java @@ -0,0 +1,41 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class CommConfigDTO { + private String acqStart;//采集开始时间 + private Long interval;//采集时间间隔(分钟) + private Long period;//上传周期 + private Long times;//采集次数 + private Long repeat;//重传次数 + private String ip; + private Long port; + private Float thresh; + private Float height; + private String collect; + private String MultiCollect; + private String acqCycle; + private String upCycle; + private String sleepStartTime; + + private String acqStartFlow ; //流量采集开始时间 + private Long intervalFlow; //流量采集采集间隔(分) + private Long acqTimesFlow ;//流量采集次数 + private String upStartFlow; //流量上报开始时间 + private Long upTimesFlow; //流量上传次数 + private String acqStartNoise; //噪声采集开始时间 + private Long intervalNoise; //噪声采集采集间隔(分) + private Long acqTimesNoise;//噪声采集次数 + private String upStartNoise; //噪声上报开始时间 + private Long upTimesNoise ;//噪声上传次数 + private String acqStartPressure; //压力采集开始时间 + private Long intervalPressure;//压力采集采集间隔(分) + private Long acqTimesPressure; //压力采集次数 + private String upStartPressure; //压力上报开始时间 + private Long upTimesPressure; //压力上传次数 + private Float lowerLimitPressure; //压力报警下限 + private Float upperLimitPressure ;//压力报警下限 + private Long limitDig ;//开挖阈值 + private Float threshold ;//开挖阈值 +} diff --git a/src/main/java/com/casic/model/DataPressure.java b/src/main/java/com/casic/model/DataPressure.java new file mode 100644 index 0000000..8270c70 --- /dev/null +++ b/src/main/java/com/casic/model/DataPressure.java @@ -0,0 +1,33 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("data_temp_press") +public class DataPressure { + + @TableId(value = "ID", type = IdType.AUTO) + private String id; + private String wellCode; + private String devcode; + private Float cell; + private String temperature; + + private String press; + private String descn; + private String uptime; + private String logtime; + /** + * 信号强度 + */ + private String pci; + + private String rsrp; + private String snr; + +} diff --git a/src/main/java/com/casic/model/PressureDataParam.java b/src/main/java/com/casic/model/PressureDataParam.java new file mode 100644 index 0000000..f42770d --- /dev/null +++ b/src/main/java/com/casic/model/PressureDataParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class PressureDataParam { + private String flag; + private String deviceUserid; + private String parentUserId; + private Object sensorsDates; + private String time; + private String rawData; + private String deviceId; +} + diff --git a/src/main/java/com/casic/model/ResponseData.java b/src/main/java/com/casic/model/ResponseData.java new file mode 100644 index 0000000..245ab04 --- /dev/null +++ b/src/main/java/com/casic/model/ResponseData.java @@ -0,0 +1,18 @@ +package com.casic.model; + +import lombok.Data; + +/** + * @author cz + * @date 2022-8-12 + */ +@Data +public class ResponseData { + public static final String DEFAULT_SUCCESS_MESSAGE = "请求成功"; + public static final String DEFAULT_ERROR_MESSAGE = "网络异常"; + public static final Integer DEFAULT_SUCCESS_CODE = 200; + public static final Integer DEFAULT_ERROR_CODE = 500; + private Integer code; + private String message; + private Object data; +} \ No newline at end of file diff --git a/src/main/java/com/casic/service/AlarmService.java b/src/main/java/com/casic/service/AlarmService.java new file mode 100644 index 0000000..8516b41 --- /dev/null +++ b/src/main/java/com/casic/service/AlarmService.java @@ -0,0 +1,12 @@ +package com.casic.service; + +import com.casic.model.AlarmConfigParam; + +public interface AlarmService { + + Object getAlarmRecord(String deviceType,Integer currentIndex,Integer pageSize,String devcode); + + Object excuteAlramBatchCancel(String deviceType,String devcode); + + Object addAlarmConfig(AlarmConfigParam alarmConfig); +} diff --git a/src/main/java/com/casic/service/DeviceDataService.java b/src/main/java/com/casic/service/DeviceDataService.java new file mode 100644 index 0000000..db656c1 --- /dev/null +++ b/src/main/java/com/casic/service/DeviceDataService.java @@ -0,0 +1,10 @@ +package com.casic.service; + +public interface DeviceDataService { + + Object getDeviceRecentData(String deviceType, String recentNum, String devcode); + + Object getDeviceListPage(String deviceType, Integer currentIndex, Integer pageSize, String devcode); + + Object getLevel(String deviceType); +} diff --git a/src/main/java/com/casic/service/ThirdDataService.java b/src/main/java/com/casic/service/ThirdDataService.java new file mode 100644 index 0000000..795e0b2 --- /dev/null +++ b/src/main/java/com/casic/service/ThirdDataService.java @@ -0,0 +1,8 @@ +package com.casic.service; + +import com.casic.model.PressureDataParam; + +public interface ThirdDataService { + + Object getDeviceRecentData(PressureDataParam pressureData); +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..50f4a19 --- /dev/null +++ b/pom.xml @@ -0,0 +1,161 @@ + + + 4.0.0 + + com.casic + smartwell-demos + 1.0-SNAPSHOT + + + + + jdk-1.8 + + true + 1.8 + + + 1.8 + 1.8 + 1.8 + + + + + + + + + + org.springframework.boot + spring-boot-starter + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-tomcat + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-web + 2.4.5 + + + + + org.springframework.boot + spring-boot-starter-jdbc + 2.4.5 + + + + mysql + mysql-connector-java + 8.0.16 + compile + + + + com.baomidou + mybatis-plus-boot-starter + 3.4.3 + + + + org.projectlombok + lombok + 1.18.20 + + + + + com.alibaba + druid + 1.2.6 + + + + com.alibaba + fastjson + 1.2.73 + + + + commons-codec + commons-codec + 1.14 + + + + redis.clients + jedis + 3.1.0 + jar + + + + org.springframework.data + spring-data-redis + 2.4.8 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.3.RELEASE + + true + + com.casic.CasicApplication + exec + + + + + repackage + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + false + + + + + + + + src/main/resources + + + /config/*/* + /config/*-*.yml + + true + + + src/main/resources + + **/*.xml + + true + + + + + \ No newline at end of file diff --git a/src/main/java/com/casic/CasicApplication.java b/src/main/java/com/casic/CasicApplication.java new file mode 100644 index 0000000..9afd0b9 --- /dev/null +++ b/src/main/java/com/casic/CasicApplication.java @@ -0,0 +1,28 @@ +package com.casic; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.transaction.annotation.EnableTransactionManagement; + + +/** + * SpringBoot方式启动类 + * + * @author cz + * @Date 2022/09/08 14:28 + */ + +@Slf4j +@ComponentScan(basePackages= "com.casic.**") +@SpringBootApplication +public class CasicApplication { + public static void main(String[] args) { + log.info("CasicApplication is success!"); + SpringApplication.run(CasicApplication.class, args); + } +} diff --git a/src/main/java/com/casic/config/CorsConfig.java b/src/main/java/com/casic/config/CorsConfig.java new file mode 100644 index 0000000..7d19680 --- /dev/null +++ b/src/main/java/com/casic/config/CorsConfig.java @@ -0,0 +1,31 @@ +package com.casic.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +/** + * 基础框架 - 跨域请求配置 + */ +@Configuration +public class CorsConfig { + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", buildConfig()); + return new CorsFilter(source); + } + + private CorsConfiguration buildConfig() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + // 1允许任何域名使用 + corsConfiguration.addAllowedOrigin("*"); + // 2允许任何头 + corsConfiguration.addAllowedHeader("*"); + // 3允许任何方法(post、get等) + corsConfiguration.addAllowedMethod("*"); + return corsConfiguration; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/controller/AlarmController.java b/src/main/java/com/casic/controller/AlarmController.java new file mode 100644 index 0000000..957fc36 --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.model.AlarmConfigParam; +import com.casic.service.AlarmService; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/alarm") +public class AlarmController { + + private final AlarmService alarmService; + + public AlarmController(AlarmService alarmService) { + this.alarmService = alarmService; + } + + @RequestMapping("/records") + public Object getAlarmRecord(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "devcode",required =false) String devcode, + @RequestParam(value = "pageSize", required = true) Integer pageSize) { + return alarmService.getAlarmRecord(deviceType,currentIndex,pageSize,devcode); + } + + @RequestMapping("/batch/cancel") + public Object excuteAlramBatchCancel(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "devcode",required =false) String devcode) { + return alarmService.excuteAlramBatchCancel(deviceType,devcode); + } + + @RequestMapping("/config/add") + public Object addAlarmConfig(@RequestBody AlarmConfigParam alarmConfigParam) { + return alarmService.addAlarmConfig(alarmConfigParam); + } +} diff --git a/src/main/java/com/casic/controller/DeviceDataController.java b/src/main/java/com/casic/controller/DeviceDataController.java new file mode 100644 index 0000000..3498b04 --- /dev/null +++ b/src/main/java/com/casic/controller/DeviceDataController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.service.DeviceDataService; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/device") +public class DeviceDataController { + private final DeviceDataService deviceDataService; + + public DeviceDataController(DeviceDataService deviceDataService) { + this.deviceDataService = deviceDataService; + } + + @RequestMapping("/recent-data") + public Object getDeviceRecentData(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "recentNum", required = true) String recentNum, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceRecentData(deviceType, recentNum, devcode); + } + + @RequestMapping("/data/list-page") + public Object getDeviceListPage(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "pageSize", required = true) Integer pageSize, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceListPage(deviceType, currentIndex, pageSize, devcode); + } + + @RequestMapping("/level/{deviceType}") + public Object getLevelList(@PathVariable("deviceType")String deviceType) { + return deviceDataService.getLevel(deviceType); + } + +} diff --git a/src/main/java/com/casic/controller/ThirdDataController.java b/src/main/java/com/casic/controller/ThirdDataController.java new file mode 100644 index 0000000..b9b2b42 --- /dev/null +++ b/src/main/java/com/casic/controller/ThirdDataController.java @@ -0,0 +1,28 @@ +package com.casic.controller; + +import com.casic.model.PressureDataParam; +import com.casic.service.ThirdDataService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +@RestController +@RequestMapping("/push") +@Slf4j +public class ThirdDataController { + + private final ThirdDataService thirdDataService; + + public ThirdDataController(ThirdDataService thirdDataService) { + this.thirdDataService = thirdDataService; + } + + @RequestMapping("/pressure/data") + public Object getDeviceRecentData(@RequestBody PressureDataParam pressureData) { + return thirdDataService.getDeviceRecentData(pressureData); + } + +} diff --git a/src/main/java/com/casic/dao/AlarmMapper.java b/src/main/java/com/casic/dao/AlarmMapper.java new file mode 100644 index 0000000..a442e3a --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmMapper.java @@ -0,0 +1,28 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmLevel; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + +@Mapper +public interface AlarmMapper extends BaseMapper { + + List> getAlarmRecord(@Param("deviceType") String deviceType, + @Param("devcode") String devcode, + @Param("currentIndex") Integer currentIndex, @Param("pageSize") Integer pageSize); + + Integer getAlarmTotalRecord(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteAlramBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteJobBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + String getDeviceDevcode(@Param("deviceType") String deviceType); + + String getDeviceByDevcode(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + +} diff --git a/src/main/java/com/casic/dao/BusConfigMapper.java b/src/main/java/com/casic/dao/BusConfigMapper.java new file mode 100644 index 0000000..ccf76da --- /dev/null +++ b/src/main/java/com/casic/dao/BusConfigMapper.java @@ -0,0 +1,9 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.BusConfig; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface BusConfigMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/dao/DataPressureMapper.java b/src/main/java/com/casic/dao/DataPressureMapper.java new file mode 100644 index 0000000..05f4329 --- /dev/null +++ b/src/main/java/com/casic/dao/DataPressureMapper.java @@ -0,0 +1,19 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.DataPressure; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.Date; + +@Mapper +public interface DataPressureMapper extends BaseMapper { + + String getWellCode(@Param("devcode") String devcode); + + Float getRuleValue(@Param("deviceType") String deviceType); + + void saveRecords(@Param("reValue") String reValue, @Param("alarmTime") Date alarmTime); + +} diff --git a/src/main/java/com/casic/dao/DeviceDataMapper.java b/src/main/java/com/casic/dao/DeviceDataMapper.java new file mode 100644 index 0000000..d9e18a0 --- /dev/null +++ b/src/main/java/com/casic/dao/DeviceDataMapper.java @@ -0,0 +1,27 @@ +package com.casic.dao; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + + +@Mapper +public interface DeviceDataMapper { + + List> getDeviceRecentData(@Param("tableName") String tableName, + @Param("recentNum") String recentNum, + @Param("fields") String fields, + @Param("devcode") String devcode); + + Integer getDeviceDataTotal(@Param("tableName") String tableName, @Param("devcode") String devcode); + + List> getDeviceDataListPage(@Param("tableName") String tableName, + @Param("currentIndex") Integer currentIndex, + @Param("fields") String fields, + @Param("pageSize") Integer pageSize, + @Param("devcode") String devcode); + + String getLevelByType(@Param("deviceType")String deviceType); +} diff --git a/src/main/java/com/casic/model/AlarmConfigParam.java b/src/main/java/com/casic/model/AlarmConfigParam.java new file mode 100644 index 0000000..28150d6 --- /dev/null +++ b/src/main/java/com/casic/model/AlarmConfigParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class AlarmConfigParam { + private String deviceType; + private String thresholdVol; + private String collectInterval; + private String uploadCycle; + private String retryNum; + private String ip; + private String port; + private String devcode; +} diff --git a/src/main/java/com/casic/model/AlarmLevel.java b/src/main/java/com/casic/model/AlarmLevel.java new file mode 100644 index 0000000..d0909af --- /dev/null +++ b/src/main/java/com/casic/model/AlarmLevel.java @@ -0,0 +1,26 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("alarm_level") +public class AlarmLevel{ + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + private String name; + private String deviceType; + private Integer level; + private Float lowValue; + private Float highValue; + private String openAlarm; + private String openJob; + private Date ts; + private String tenantId; + +} diff --git a/src/main/java/com/casic/model/BusConfig.java b/src/main/java/com/casic/model/BusConfig.java new file mode 100644 index 0000000..c6b7b50 --- /dev/null +++ b/src/main/java/com/casic/model/BusConfig.java @@ -0,0 +1,27 @@ +package com.casic.model; + + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +import java.util.Date; + +@Data +public class BusConfig { + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + + private String deviceId; + private String framecontent; + private String sensorid; + private String sensorcode; + + private String status; + private Integer attemptsmax; + private Integer attemptscurrent; + private Date sendtime; + private Date writetime; + +} diff --git a/src/main/java/com/casic/model/CommConfigDTO.java b/src/main/java/com/casic/model/CommConfigDTO.java new file mode 100644 index 0000000..7da699c --- /dev/null +++ b/src/main/java/com/casic/model/CommConfigDTO.java @@ -0,0 +1,41 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class CommConfigDTO { + private String acqStart;//采集开始时间 + private Long interval;//采集时间间隔(分钟) + private Long period;//上传周期 + private Long times;//采集次数 + private Long repeat;//重传次数 + private String ip; + private Long port; + private Float thresh; + private Float height; + private String collect; + private String MultiCollect; + private String acqCycle; + private String upCycle; + private String sleepStartTime; + + private String acqStartFlow ; //流量采集开始时间 + private Long intervalFlow; //流量采集采集间隔(分) + private Long acqTimesFlow ;//流量采集次数 + private String upStartFlow; //流量上报开始时间 + private Long upTimesFlow; //流量上传次数 + private String acqStartNoise; //噪声采集开始时间 + private Long intervalNoise; //噪声采集采集间隔(分) + private Long acqTimesNoise;//噪声采集次数 + private String upStartNoise; //噪声上报开始时间 + private Long upTimesNoise ;//噪声上传次数 + private String acqStartPressure; //压力采集开始时间 + private Long intervalPressure;//压力采集采集间隔(分) + private Long acqTimesPressure; //压力采集次数 + private String upStartPressure; //压力上报开始时间 + private Long upTimesPressure; //压力上传次数 + private Float lowerLimitPressure; //压力报警下限 + private Float upperLimitPressure ;//压力报警下限 + private Long limitDig ;//开挖阈值 + private Float threshold ;//开挖阈值 +} diff --git a/src/main/java/com/casic/model/DataPressure.java b/src/main/java/com/casic/model/DataPressure.java new file mode 100644 index 0000000..8270c70 --- /dev/null +++ b/src/main/java/com/casic/model/DataPressure.java @@ -0,0 +1,33 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("data_temp_press") +public class DataPressure { + + @TableId(value = "ID", type = IdType.AUTO) + private String id; + private String wellCode; + private String devcode; + private Float cell; + private String temperature; + + private String press; + private String descn; + private String uptime; + private String logtime; + /** + * 信号强度 + */ + private String pci; + + private String rsrp; + private String snr; + +} diff --git a/src/main/java/com/casic/model/PressureDataParam.java b/src/main/java/com/casic/model/PressureDataParam.java new file mode 100644 index 0000000..f42770d --- /dev/null +++ b/src/main/java/com/casic/model/PressureDataParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class PressureDataParam { + private String flag; + private String deviceUserid; + private String parentUserId; + private Object sensorsDates; + private String time; + private String rawData; + private String deviceId; +} + diff --git a/src/main/java/com/casic/model/ResponseData.java b/src/main/java/com/casic/model/ResponseData.java new file mode 100644 index 0000000..245ab04 --- /dev/null +++ b/src/main/java/com/casic/model/ResponseData.java @@ -0,0 +1,18 @@ +package com.casic.model; + +import lombok.Data; + +/** + * @author cz + * @date 2022-8-12 + */ +@Data +public class ResponseData { + public static final String DEFAULT_SUCCESS_MESSAGE = "请求成功"; + public static final String DEFAULT_ERROR_MESSAGE = "网络异常"; + public static final Integer DEFAULT_SUCCESS_CODE = 200; + public static final Integer DEFAULT_ERROR_CODE = 500; + private Integer code; + private String message; + private Object data; +} \ No newline at end of file diff --git a/src/main/java/com/casic/service/AlarmService.java b/src/main/java/com/casic/service/AlarmService.java new file mode 100644 index 0000000..8516b41 --- /dev/null +++ b/src/main/java/com/casic/service/AlarmService.java @@ -0,0 +1,12 @@ +package com.casic.service; + +import com.casic.model.AlarmConfigParam; + +public interface AlarmService { + + Object getAlarmRecord(String deviceType,Integer currentIndex,Integer pageSize,String devcode); + + Object excuteAlramBatchCancel(String deviceType,String devcode); + + Object addAlarmConfig(AlarmConfigParam alarmConfig); +} diff --git a/src/main/java/com/casic/service/DeviceDataService.java b/src/main/java/com/casic/service/DeviceDataService.java new file mode 100644 index 0000000..db656c1 --- /dev/null +++ b/src/main/java/com/casic/service/DeviceDataService.java @@ -0,0 +1,10 @@ +package com.casic.service; + +public interface DeviceDataService { + + Object getDeviceRecentData(String deviceType, String recentNum, String devcode); + + Object getDeviceListPage(String deviceType, Integer currentIndex, Integer pageSize, String devcode); + + Object getLevel(String deviceType); +} diff --git a/src/main/java/com/casic/service/ThirdDataService.java b/src/main/java/com/casic/service/ThirdDataService.java new file mode 100644 index 0000000..795e0b2 --- /dev/null +++ b/src/main/java/com/casic/service/ThirdDataService.java @@ -0,0 +1,8 @@ +package com.casic.service; + +import com.casic.model.PressureDataParam; + +public interface ThirdDataService { + + Object getDeviceRecentData(PressureDataParam pressureData); +} diff --git a/src/main/java/com/casic/service/impl/AlarmServiceImple.java b/src/main/java/com/casic/service/impl/AlarmServiceImple.java new file mode 100644 index 0000000..a675207 --- /dev/null +++ b/src/main/java/com/casic/service/impl/AlarmServiceImple.java @@ -0,0 +1,127 @@ +package com.casic.service.impl; + +import com.alibaba.druid.util.StringUtils; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.dao.AlarmMapper; +import com.casic.dao.BusConfigMapper; +import com.casic.model.*; +import com.casic.service.AlarmService; +import com.casic.util.DeviceDataTableEnum; +import com.casic.util.RedisCommonUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Slf4j +@Service +public class AlarmServiceImple extends ServiceImpl implements AlarmService { + + @Resource + private BusConfigMapper busConfigMapper; + @Resource + private RedisCommonUtil redisCommonUtil; + + public Object getAlarmRecord(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { + ResponseData responseData = new ResponseData(); + try { + Map page = new HashMap(); + page.put("total", this.baseMapper.getAlarmTotalRecord(deviceType, devcode)); + List> alarmRecordList = this.baseMapper.getAlarmRecord(deviceType, devcode, pageSize * (currentIndex - 1), pageSize); + page.put("rows", alarmRecordList); + responseData.setData(alarmRecordList); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},异常信息{}", deviceType, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + @Transactional + public Object excuteAlramBatchCancel(String deviceType, String devcode) { + ResponseData responseData = new ResponseData(); + try { + this.baseMapper.excuteAlramBatchCancel(deviceType, devcode); + this.baseMapper.excuteJobBatchCancel(deviceType, devcode); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("批量消警异常,设备类型{},异常信息{}", deviceType, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + + @Transactional + public Object addAlarmConfig(AlarmConfigParam alarmConfigParam) { + ResponseData responseData = new ResponseData(); + try { + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + addBusConfig(alarmConfigParam); + addRuleConfig(alarmConfigParam); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("风险配置异常,异常信息{}", dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + private void addRuleConfig(AlarmConfigParam alarmConfigParam) { + Map alarmRuleMap = new HashMap(); + alarmRuleMap.put("DEVICE_TYPE", alarmConfigParam.getDeviceType()); + this.baseMapper.deleteByMap(alarmRuleMap); + AlarmLevel alarmRule = new AlarmLevel(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap() + .get(Integer.valueOf(alarmConfigParam.getDeviceType())); + alarmRule.setName(deviceDataTableEnum.getTypeName()); + alarmRule.setHighValue(Float.valueOf(alarmConfigParam.getThresholdVol())); + alarmRule.setTs(new Date()); + alarmRule.setLevel(1); + alarmRule.setDeviceType(alarmConfigParam.getDeviceType()); + this.baseMapper.insert(alarmRule); + } + + private void addBusConfig(AlarmConfigParam alarmConfigParam) { + String devcode = StringUtils.isEmpty(alarmConfigParam.getDevcode()) ? this.baseMapper.getDeviceDevcode(alarmConfigParam.getDeviceType()) : alarmConfigParam.getDevcode(); + sendBusConfig(alarmConfigParam, devcode); + String devcideId = this.baseMapper.getDeviceByDevcode(alarmConfigParam.getDeviceType(), devcode); + BusConfig busConfig = new BusConfig(); + busConfig.setDeviceId(devcideId); + busConfig.setFramecontent("3," + alarmConfigParam.getCollectInterval() + "," + alarmConfigParam.getCollectInterval() + + "," + alarmConfigParam.getRetryNum() + "," + alarmConfigParam.getIp() + "," + alarmConfigParam.getPort()); + busConfig.setSensorid(""); + busConfig.setStatus("0"); + busConfig.setAttemptscurrent(0); + busConfig.setWritetime(new Date()); + busConfig.setAttemptsmax(3); + busConfigMapper.insert(busConfig); + } + + private void sendBusConfig(AlarmConfigParam alarmConfigParam, String devcode) { + CommConfigDTO commConfigDTO = new CommConfigDTO(); + commConfigDTO.setInterval(StringUtils.isEmpty(alarmConfigParam.getCollectInterval()) ? 300 : Long.valueOf(alarmConfigParam.getCollectInterval())); + commConfigDTO.setRepeat(StringUtils.isEmpty(alarmConfigParam.getRetryNum()) ? 300 : Long.valueOf(alarmConfigParam.getRetryNum())); + commConfigDTO.setTimes(Long.valueOf(1)); +// commConfigDTO.setIp(alarmConfigParam.getIp()); +// commConfigDTO.setPort(StringUtils.isEmpty(alarmConfigParam.getPort()) ? 8080 : Long.valueOf(alarmConfigParam.getPort())); + commConfigDTO.setPeriod(StringUtils.isEmpty(alarmConfigParam.getUploadCycle()) ? 300 : Long.valueOf(alarmConfigParam.getUploadCycle())); +// commConfigDTO.setThresh(); + commConfigDTO.setThresh(StringUtils.isEmpty(alarmConfigParam.getThresholdVol()) ? 50: Float.valueOf(alarmConfigParam.getThresholdVol())); + redisCommonUtil.send(commConfigDTO, devcode); + } + + +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..50f4a19 --- /dev/null +++ b/pom.xml @@ -0,0 +1,161 @@ + + + 4.0.0 + + com.casic + smartwell-demos + 1.0-SNAPSHOT + + + + + jdk-1.8 + + true + 1.8 + + + 1.8 + 1.8 + 1.8 + + + + + + + + + + org.springframework.boot + spring-boot-starter + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-tomcat + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-web + 2.4.5 + + + + + org.springframework.boot + spring-boot-starter-jdbc + 2.4.5 + + + + mysql + mysql-connector-java + 8.0.16 + compile + + + + com.baomidou + mybatis-plus-boot-starter + 3.4.3 + + + + org.projectlombok + lombok + 1.18.20 + + + + + com.alibaba + druid + 1.2.6 + + + + com.alibaba + fastjson + 1.2.73 + + + + commons-codec + commons-codec + 1.14 + + + + redis.clients + jedis + 3.1.0 + jar + + + + org.springframework.data + spring-data-redis + 2.4.8 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.3.RELEASE + + true + + com.casic.CasicApplication + exec + + + + + repackage + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + false + + + + + + + + src/main/resources + + + /config/*/* + /config/*-*.yml + + true + + + src/main/resources + + **/*.xml + + true + + + + + \ No newline at end of file diff --git a/src/main/java/com/casic/CasicApplication.java b/src/main/java/com/casic/CasicApplication.java new file mode 100644 index 0000000..9afd0b9 --- /dev/null +++ b/src/main/java/com/casic/CasicApplication.java @@ -0,0 +1,28 @@ +package com.casic; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.transaction.annotation.EnableTransactionManagement; + + +/** + * SpringBoot方式启动类 + * + * @author cz + * @Date 2022/09/08 14:28 + */ + +@Slf4j +@ComponentScan(basePackages= "com.casic.**") +@SpringBootApplication +public class CasicApplication { + public static void main(String[] args) { + log.info("CasicApplication is success!"); + SpringApplication.run(CasicApplication.class, args); + } +} diff --git a/src/main/java/com/casic/config/CorsConfig.java b/src/main/java/com/casic/config/CorsConfig.java new file mode 100644 index 0000000..7d19680 --- /dev/null +++ b/src/main/java/com/casic/config/CorsConfig.java @@ -0,0 +1,31 @@ +package com.casic.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +/** + * 基础框架 - 跨域请求配置 + */ +@Configuration +public class CorsConfig { + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", buildConfig()); + return new CorsFilter(source); + } + + private CorsConfiguration buildConfig() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + // 1允许任何域名使用 + corsConfiguration.addAllowedOrigin("*"); + // 2允许任何头 + corsConfiguration.addAllowedHeader("*"); + // 3允许任何方法(post、get等) + corsConfiguration.addAllowedMethod("*"); + return corsConfiguration; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/controller/AlarmController.java b/src/main/java/com/casic/controller/AlarmController.java new file mode 100644 index 0000000..957fc36 --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.model.AlarmConfigParam; +import com.casic.service.AlarmService; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/alarm") +public class AlarmController { + + private final AlarmService alarmService; + + public AlarmController(AlarmService alarmService) { + this.alarmService = alarmService; + } + + @RequestMapping("/records") + public Object getAlarmRecord(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "devcode",required =false) String devcode, + @RequestParam(value = "pageSize", required = true) Integer pageSize) { + return alarmService.getAlarmRecord(deviceType,currentIndex,pageSize,devcode); + } + + @RequestMapping("/batch/cancel") + public Object excuteAlramBatchCancel(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "devcode",required =false) String devcode) { + return alarmService.excuteAlramBatchCancel(deviceType,devcode); + } + + @RequestMapping("/config/add") + public Object addAlarmConfig(@RequestBody AlarmConfigParam alarmConfigParam) { + return alarmService.addAlarmConfig(alarmConfigParam); + } +} diff --git a/src/main/java/com/casic/controller/DeviceDataController.java b/src/main/java/com/casic/controller/DeviceDataController.java new file mode 100644 index 0000000..3498b04 --- /dev/null +++ b/src/main/java/com/casic/controller/DeviceDataController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.service.DeviceDataService; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/device") +public class DeviceDataController { + private final DeviceDataService deviceDataService; + + public DeviceDataController(DeviceDataService deviceDataService) { + this.deviceDataService = deviceDataService; + } + + @RequestMapping("/recent-data") + public Object getDeviceRecentData(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "recentNum", required = true) String recentNum, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceRecentData(deviceType, recentNum, devcode); + } + + @RequestMapping("/data/list-page") + public Object getDeviceListPage(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "pageSize", required = true) Integer pageSize, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceListPage(deviceType, currentIndex, pageSize, devcode); + } + + @RequestMapping("/level/{deviceType}") + public Object getLevelList(@PathVariable("deviceType")String deviceType) { + return deviceDataService.getLevel(deviceType); + } + +} diff --git a/src/main/java/com/casic/controller/ThirdDataController.java b/src/main/java/com/casic/controller/ThirdDataController.java new file mode 100644 index 0000000..b9b2b42 --- /dev/null +++ b/src/main/java/com/casic/controller/ThirdDataController.java @@ -0,0 +1,28 @@ +package com.casic.controller; + +import com.casic.model.PressureDataParam; +import com.casic.service.ThirdDataService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +@RestController +@RequestMapping("/push") +@Slf4j +public class ThirdDataController { + + private final ThirdDataService thirdDataService; + + public ThirdDataController(ThirdDataService thirdDataService) { + this.thirdDataService = thirdDataService; + } + + @RequestMapping("/pressure/data") + public Object getDeviceRecentData(@RequestBody PressureDataParam pressureData) { + return thirdDataService.getDeviceRecentData(pressureData); + } + +} diff --git a/src/main/java/com/casic/dao/AlarmMapper.java b/src/main/java/com/casic/dao/AlarmMapper.java new file mode 100644 index 0000000..a442e3a --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmMapper.java @@ -0,0 +1,28 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmLevel; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + +@Mapper +public interface AlarmMapper extends BaseMapper { + + List> getAlarmRecord(@Param("deviceType") String deviceType, + @Param("devcode") String devcode, + @Param("currentIndex") Integer currentIndex, @Param("pageSize") Integer pageSize); + + Integer getAlarmTotalRecord(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteAlramBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteJobBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + String getDeviceDevcode(@Param("deviceType") String deviceType); + + String getDeviceByDevcode(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + +} diff --git a/src/main/java/com/casic/dao/BusConfigMapper.java b/src/main/java/com/casic/dao/BusConfigMapper.java new file mode 100644 index 0000000..ccf76da --- /dev/null +++ b/src/main/java/com/casic/dao/BusConfigMapper.java @@ -0,0 +1,9 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.BusConfig; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface BusConfigMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/dao/DataPressureMapper.java b/src/main/java/com/casic/dao/DataPressureMapper.java new file mode 100644 index 0000000..05f4329 --- /dev/null +++ b/src/main/java/com/casic/dao/DataPressureMapper.java @@ -0,0 +1,19 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.DataPressure; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.Date; + +@Mapper +public interface DataPressureMapper extends BaseMapper { + + String getWellCode(@Param("devcode") String devcode); + + Float getRuleValue(@Param("deviceType") String deviceType); + + void saveRecords(@Param("reValue") String reValue, @Param("alarmTime") Date alarmTime); + +} diff --git a/src/main/java/com/casic/dao/DeviceDataMapper.java b/src/main/java/com/casic/dao/DeviceDataMapper.java new file mode 100644 index 0000000..d9e18a0 --- /dev/null +++ b/src/main/java/com/casic/dao/DeviceDataMapper.java @@ -0,0 +1,27 @@ +package com.casic.dao; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + + +@Mapper +public interface DeviceDataMapper { + + List> getDeviceRecentData(@Param("tableName") String tableName, + @Param("recentNum") String recentNum, + @Param("fields") String fields, + @Param("devcode") String devcode); + + Integer getDeviceDataTotal(@Param("tableName") String tableName, @Param("devcode") String devcode); + + List> getDeviceDataListPage(@Param("tableName") String tableName, + @Param("currentIndex") Integer currentIndex, + @Param("fields") String fields, + @Param("pageSize") Integer pageSize, + @Param("devcode") String devcode); + + String getLevelByType(@Param("deviceType")String deviceType); +} diff --git a/src/main/java/com/casic/model/AlarmConfigParam.java b/src/main/java/com/casic/model/AlarmConfigParam.java new file mode 100644 index 0000000..28150d6 --- /dev/null +++ b/src/main/java/com/casic/model/AlarmConfigParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class AlarmConfigParam { + private String deviceType; + private String thresholdVol; + private String collectInterval; + private String uploadCycle; + private String retryNum; + private String ip; + private String port; + private String devcode; +} diff --git a/src/main/java/com/casic/model/AlarmLevel.java b/src/main/java/com/casic/model/AlarmLevel.java new file mode 100644 index 0000000..d0909af --- /dev/null +++ b/src/main/java/com/casic/model/AlarmLevel.java @@ -0,0 +1,26 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("alarm_level") +public class AlarmLevel{ + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + private String name; + private String deviceType; + private Integer level; + private Float lowValue; + private Float highValue; + private String openAlarm; + private String openJob; + private Date ts; + private String tenantId; + +} diff --git a/src/main/java/com/casic/model/BusConfig.java b/src/main/java/com/casic/model/BusConfig.java new file mode 100644 index 0000000..c6b7b50 --- /dev/null +++ b/src/main/java/com/casic/model/BusConfig.java @@ -0,0 +1,27 @@ +package com.casic.model; + + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +import java.util.Date; + +@Data +public class BusConfig { + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + + private String deviceId; + private String framecontent; + private String sensorid; + private String sensorcode; + + private String status; + private Integer attemptsmax; + private Integer attemptscurrent; + private Date sendtime; + private Date writetime; + +} diff --git a/src/main/java/com/casic/model/CommConfigDTO.java b/src/main/java/com/casic/model/CommConfigDTO.java new file mode 100644 index 0000000..7da699c --- /dev/null +++ b/src/main/java/com/casic/model/CommConfigDTO.java @@ -0,0 +1,41 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class CommConfigDTO { + private String acqStart;//采集开始时间 + private Long interval;//采集时间间隔(分钟) + private Long period;//上传周期 + private Long times;//采集次数 + private Long repeat;//重传次数 + private String ip; + private Long port; + private Float thresh; + private Float height; + private String collect; + private String MultiCollect; + private String acqCycle; + private String upCycle; + private String sleepStartTime; + + private String acqStartFlow ; //流量采集开始时间 + private Long intervalFlow; //流量采集采集间隔(分) + private Long acqTimesFlow ;//流量采集次数 + private String upStartFlow; //流量上报开始时间 + private Long upTimesFlow; //流量上传次数 + private String acqStartNoise; //噪声采集开始时间 + private Long intervalNoise; //噪声采集采集间隔(分) + private Long acqTimesNoise;//噪声采集次数 + private String upStartNoise; //噪声上报开始时间 + private Long upTimesNoise ;//噪声上传次数 + private String acqStartPressure; //压力采集开始时间 + private Long intervalPressure;//压力采集采集间隔(分) + private Long acqTimesPressure; //压力采集次数 + private String upStartPressure; //压力上报开始时间 + private Long upTimesPressure; //压力上传次数 + private Float lowerLimitPressure; //压力报警下限 + private Float upperLimitPressure ;//压力报警下限 + private Long limitDig ;//开挖阈值 + private Float threshold ;//开挖阈值 +} diff --git a/src/main/java/com/casic/model/DataPressure.java b/src/main/java/com/casic/model/DataPressure.java new file mode 100644 index 0000000..8270c70 --- /dev/null +++ b/src/main/java/com/casic/model/DataPressure.java @@ -0,0 +1,33 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("data_temp_press") +public class DataPressure { + + @TableId(value = "ID", type = IdType.AUTO) + private String id; + private String wellCode; + private String devcode; + private Float cell; + private String temperature; + + private String press; + private String descn; + private String uptime; + private String logtime; + /** + * 信号强度 + */ + private String pci; + + private String rsrp; + private String snr; + +} diff --git a/src/main/java/com/casic/model/PressureDataParam.java b/src/main/java/com/casic/model/PressureDataParam.java new file mode 100644 index 0000000..f42770d --- /dev/null +++ b/src/main/java/com/casic/model/PressureDataParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class PressureDataParam { + private String flag; + private String deviceUserid; + private String parentUserId; + private Object sensorsDates; + private String time; + private String rawData; + private String deviceId; +} + diff --git a/src/main/java/com/casic/model/ResponseData.java b/src/main/java/com/casic/model/ResponseData.java new file mode 100644 index 0000000..245ab04 --- /dev/null +++ b/src/main/java/com/casic/model/ResponseData.java @@ -0,0 +1,18 @@ +package com.casic.model; + +import lombok.Data; + +/** + * @author cz + * @date 2022-8-12 + */ +@Data +public class ResponseData { + public static final String DEFAULT_SUCCESS_MESSAGE = "请求成功"; + public static final String DEFAULT_ERROR_MESSAGE = "网络异常"; + public static final Integer DEFAULT_SUCCESS_CODE = 200; + public static final Integer DEFAULT_ERROR_CODE = 500; + private Integer code; + private String message; + private Object data; +} \ No newline at end of file diff --git a/src/main/java/com/casic/service/AlarmService.java b/src/main/java/com/casic/service/AlarmService.java new file mode 100644 index 0000000..8516b41 --- /dev/null +++ b/src/main/java/com/casic/service/AlarmService.java @@ -0,0 +1,12 @@ +package com.casic.service; + +import com.casic.model.AlarmConfigParam; + +public interface AlarmService { + + Object getAlarmRecord(String deviceType,Integer currentIndex,Integer pageSize,String devcode); + + Object excuteAlramBatchCancel(String deviceType,String devcode); + + Object addAlarmConfig(AlarmConfigParam alarmConfig); +} diff --git a/src/main/java/com/casic/service/DeviceDataService.java b/src/main/java/com/casic/service/DeviceDataService.java new file mode 100644 index 0000000..db656c1 --- /dev/null +++ b/src/main/java/com/casic/service/DeviceDataService.java @@ -0,0 +1,10 @@ +package com.casic.service; + +public interface DeviceDataService { + + Object getDeviceRecentData(String deviceType, String recentNum, String devcode); + + Object getDeviceListPage(String deviceType, Integer currentIndex, Integer pageSize, String devcode); + + Object getLevel(String deviceType); +} diff --git a/src/main/java/com/casic/service/ThirdDataService.java b/src/main/java/com/casic/service/ThirdDataService.java new file mode 100644 index 0000000..795e0b2 --- /dev/null +++ b/src/main/java/com/casic/service/ThirdDataService.java @@ -0,0 +1,8 @@ +package com.casic.service; + +import com.casic.model.PressureDataParam; + +public interface ThirdDataService { + + Object getDeviceRecentData(PressureDataParam pressureData); +} diff --git a/src/main/java/com/casic/service/impl/AlarmServiceImple.java b/src/main/java/com/casic/service/impl/AlarmServiceImple.java new file mode 100644 index 0000000..a675207 --- /dev/null +++ b/src/main/java/com/casic/service/impl/AlarmServiceImple.java @@ -0,0 +1,127 @@ +package com.casic.service.impl; + +import com.alibaba.druid.util.StringUtils; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.dao.AlarmMapper; +import com.casic.dao.BusConfigMapper; +import com.casic.model.*; +import com.casic.service.AlarmService; +import com.casic.util.DeviceDataTableEnum; +import com.casic.util.RedisCommonUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Slf4j +@Service +public class AlarmServiceImple extends ServiceImpl implements AlarmService { + + @Resource + private BusConfigMapper busConfigMapper; + @Resource + private RedisCommonUtil redisCommonUtil; + + public Object getAlarmRecord(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { + ResponseData responseData = new ResponseData(); + try { + Map page = new HashMap(); + page.put("total", this.baseMapper.getAlarmTotalRecord(deviceType, devcode)); + List> alarmRecordList = this.baseMapper.getAlarmRecord(deviceType, devcode, pageSize * (currentIndex - 1), pageSize); + page.put("rows", alarmRecordList); + responseData.setData(alarmRecordList); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},异常信息{}", deviceType, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + @Transactional + public Object excuteAlramBatchCancel(String deviceType, String devcode) { + ResponseData responseData = new ResponseData(); + try { + this.baseMapper.excuteAlramBatchCancel(deviceType, devcode); + this.baseMapper.excuteJobBatchCancel(deviceType, devcode); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("批量消警异常,设备类型{},异常信息{}", deviceType, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + + @Transactional + public Object addAlarmConfig(AlarmConfigParam alarmConfigParam) { + ResponseData responseData = new ResponseData(); + try { + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + addBusConfig(alarmConfigParam); + addRuleConfig(alarmConfigParam); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("风险配置异常,异常信息{}", dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + private void addRuleConfig(AlarmConfigParam alarmConfigParam) { + Map alarmRuleMap = new HashMap(); + alarmRuleMap.put("DEVICE_TYPE", alarmConfigParam.getDeviceType()); + this.baseMapper.deleteByMap(alarmRuleMap); + AlarmLevel alarmRule = new AlarmLevel(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap() + .get(Integer.valueOf(alarmConfigParam.getDeviceType())); + alarmRule.setName(deviceDataTableEnum.getTypeName()); + alarmRule.setHighValue(Float.valueOf(alarmConfigParam.getThresholdVol())); + alarmRule.setTs(new Date()); + alarmRule.setLevel(1); + alarmRule.setDeviceType(alarmConfigParam.getDeviceType()); + this.baseMapper.insert(alarmRule); + } + + private void addBusConfig(AlarmConfigParam alarmConfigParam) { + String devcode = StringUtils.isEmpty(alarmConfigParam.getDevcode()) ? this.baseMapper.getDeviceDevcode(alarmConfigParam.getDeviceType()) : alarmConfigParam.getDevcode(); + sendBusConfig(alarmConfigParam, devcode); + String devcideId = this.baseMapper.getDeviceByDevcode(alarmConfigParam.getDeviceType(), devcode); + BusConfig busConfig = new BusConfig(); + busConfig.setDeviceId(devcideId); + busConfig.setFramecontent("3," + alarmConfigParam.getCollectInterval() + "," + alarmConfigParam.getCollectInterval() + + "," + alarmConfigParam.getRetryNum() + "," + alarmConfigParam.getIp() + "," + alarmConfigParam.getPort()); + busConfig.setSensorid(""); + busConfig.setStatus("0"); + busConfig.setAttemptscurrent(0); + busConfig.setWritetime(new Date()); + busConfig.setAttemptsmax(3); + busConfigMapper.insert(busConfig); + } + + private void sendBusConfig(AlarmConfigParam alarmConfigParam, String devcode) { + CommConfigDTO commConfigDTO = new CommConfigDTO(); + commConfigDTO.setInterval(StringUtils.isEmpty(alarmConfigParam.getCollectInterval()) ? 300 : Long.valueOf(alarmConfigParam.getCollectInterval())); + commConfigDTO.setRepeat(StringUtils.isEmpty(alarmConfigParam.getRetryNum()) ? 300 : Long.valueOf(alarmConfigParam.getRetryNum())); + commConfigDTO.setTimes(Long.valueOf(1)); +// commConfigDTO.setIp(alarmConfigParam.getIp()); +// commConfigDTO.setPort(StringUtils.isEmpty(alarmConfigParam.getPort()) ? 8080 : Long.valueOf(alarmConfigParam.getPort())); + commConfigDTO.setPeriod(StringUtils.isEmpty(alarmConfigParam.getUploadCycle()) ? 300 : Long.valueOf(alarmConfigParam.getUploadCycle())); +// commConfigDTO.setThresh(); + commConfigDTO.setThresh(StringUtils.isEmpty(alarmConfigParam.getThresholdVol()) ? 50: Float.valueOf(alarmConfigParam.getThresholdVol())); + redisCommonUtil.send(commConfigDTO, devcode); + } + + +} diff --git a/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java new file mode 100644 index 0000000..3de704b --- /dev/null +++ b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java @@ -0,0 +1,80 @@ +package com.casic.service.impl; + +import com.casic.dao.DeviceDataMapper; +import com.casic.model.ResponseData; +import com.casic.service.DeviceDataService; +import com.casic.util.DeviceDataFieldTableEnum; +import com.casic.util.DeviceDataTableEnum; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Service +@Slf4j +public class DeviceDataServiceImpl implements DeviceDataService { + + private final DeviceDataMapper deviceDataMapper; + + public DeviceDataServiceImpl(DeviceDataMapper deviceDataMapper) { + this.deviceDataMapper = deviceDataMapper; + } + + public Object getDeviceRecentData(String deviceType, String recentNum, String devcode) { + ResponseData responseData = new ResponseData(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); + try { + String tableName = deviceDataTableEnum.getTableName(); + String fields = DeviceDataFieldTableEnum.TABLE_FIELD.getTableFieldMap().get(tableName); + List> recentDataList = deviceDataMapper.getDeviceRecentData(tableName, recentNum, fields, devcode); + responseData.setData(recentDataList); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备最近数据查询异常,设备类型{},查询数目{},异常信息{}", deviceType, recentNum, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + public Object getDeviceListPage(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { + ResponseData responseData = new ResponseData(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); + try { + String tableName = deviceDataTableEnum.getTableName(); + String fields = DeviceDataFieldTableEnum.TABLE_FIELD.getTableFieldMap().get(tableName); + Map page = new HashMap(); + page.put("total", deviceDataMapper.getDeviceDataTotal(tableName, devcode)); + List> recentDataList = deviceDataMapper.getDeviceDataListPage(tableName, pageSize * (currentIndex - 1), fields, pageSize, devcode); + page.put("rows", recentDataList); + responseData.setData(page); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},当前页{},页大小{},异常信息{}", deviceType, currentIndex, pageSize, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + public Object getLevel(String deviceType) { + ResponseData responseData = new ResponseData(); + try { + String highValue = deviceDataMapper.getLevelByType(deviceType); + responseData.setData(highValue); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},当前页{},页大小{},异常信息{}"); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..50f4a19 --- /dev/null +++ b/pom.xml @@ -0,0 +1,161 @@ + + + 4.0.0 + + com.casic + smartwell-demos + 1.0-SNAPSHOT + + + + + jdk-1.8 + + true + 1.8 + + + 1.8 + 1.8 + 1.8 + + + + + + + + + + org.springframework.boot + spring-boot-starter + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-tomcat + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-web + 2.4.5 + + + + + org.springframework.boot + spring-boot-starter-jdbc + 2.4.5 + + + + mysql + mysql-connector-java + 8.0.16 + compile + + + + com.baomidou + mybatis-plus-boot-starter + 3.4.3 + + + + org.projectlombok + lombok + 1.18.20 + + + + + com.alibaba + druid + 1.2.6 + + + + com.alibaba + fastjson + 1.2.73 + + + + commons-codec + commons-codec + 1.14 + + + + redis.clients + jedis + 3.1.0 + jar + + + + org.springframework.data + spring-data-redis + 2.4.8 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.3.RELEASE + + true + + com.casic.CasicApplication + exec + + + + + repackage + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + false + + + + + + + + src/main/resources + + + /config/*/* + /config/*-*.yml + + true + + + src/main/resources + + **/*.xml + + true + + + + + \ No newline at end of file diff --git a/src/main/java/com/casic/CasicApplication.java b/src/main/java/com/casic/CasicApplication.java new file mode 100644 index 0000000..9afd0b9 --- /dev/null +++ b/src/main/java/com/casic/CasicApplication.java @@ -0,0 +1,28 @@ +package com.casic; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.transaction.annotation.EnableTransactionManagement; + + +/** + * SpringBoot方式启动类 + * + * @author cz + * @Date 2022/09/08 14:28 + */ + +@Slf4j +@ComponentScan(basePackages= "com.casic.**") +@SpringBootApplication +public class CasicApplication { + public static void main(String[] args) { + log.info("CasicApplication is success!"); + SpringApplication.run(CasicApplication.class, args); + } +} diff --git a/src/main/java/com/casic/config/CorsConfig.java b/src/main/java/com/casic/config/CorsConfig.java new file mode 100644 index 0000000..7d19680 --- /dev/null +++ b/src/main/java/com/casic/config/CorsConfig.java @@ -0,0 +1,31 @@ +package com.casic.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +/** + * 基础框架 - 跨域请求配置 + */ +@Configuration +public class CorsConfig { + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", buildConfig()); + return new CorsFilter(source); + } + + private CorsConfiguration buildConfig() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + // 1允许任何域名使用 + corsConfiguration.addAllowedOrigin("*"); + // 2允许任何头 + corsConfiguration.addAllowedHeader("*"); + // 3允许任何方法(post、get等) + corsConfiguration.addAllowedMethod("*"); + return corsConfiguration; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/controller/AlarmController.java b/src/main/java/com/casic/controller/AlarmController.java new file mode 100644 index 0000000..957fc36 --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.model.AlarmConfigParam; +import com.casic.service.AlarmService; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/alarm") +public class AlarmController { + + private final AlarmService alarmService; + + public AlarmController(AlarmService alarmService) { + this.alarmService = alarmService; + } + + @RequestMapping("/records") + public Object getAlarmRecord(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "devcode",required =false) String devcode, + @RequestParam(value = "pageSize", required = true) Integer pageSize) { + return alarmService.getAlarmRecord(deviceType,currentIndex,pageSize,devcode); + } + + @RequestMapping("/batch/cancel") + public Object excuteAlramBatchCancel(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "devcode",required =false) String devcode) { + return alarmService.excuteAlramBatchCancel(deviceType,devcode); + } + + @RequestMapping("/config/add") + public Object addAlarmConfig(@RequestBody AlarmConfigParam alarmConfigParam) { + return alarmService.addAlarmConfig(alarmConfigParam); + } +} diff --git a/src/main/java/com/casic/controller/DeviceDataController.java b/src/main/java/com/casic/controller/DeviceDataController.java new file mode 100644 index 0000000..3498b04 --- /dev/null +++ b/src/main/java/com/casic/controller/DeviceDataController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.service.DeviceDataService; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/device") +public class DeviceDataController { + private final DeviceDataService deviceDataService; + + public DeviceDataController(DeviceDataService deviceDataService) { + this.deviceDataService = deviceDataService; + } + + @RequestMapping("/recent-data") + public Object getDeviceRecentData(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "recentNum", required = true) String recentNum, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceRecentData(deviceType, recentNum, devcode); + } + + @RequestMapping("/data/list-page") + public Object getDeviceListPage(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "pageSize", required = true) Integer pageSize, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceListPage(deviceType, currentIndex, pageSize, devcode); + } + + @RequestMapping("/level/{deviceType}") + public Object getLevelList(@PathVariable("deviceType")String deviceType) { + return deviceDataService.getLevel(deviceType); + } + +} diff --git a/src/main/java/com/casic/controller/ThirdDataController.java b/src/main/java/com/casic/controller/ThirdDataController.java new file mode 100644 index 0000000..b9b2b42 --- /dev/null +++ b/src/main/java/com/casic/controller/ThirdDataController.java @@ -0,0 +1,28 @@ +package com.casic.controller; + +import com.casic.model.PressureDataParam; +import com.casic.service.ThirdDataService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +@RestController +@RequestMapping("/push") +@Slf4j +public class ThirdDataController { + + private final ThirdDataService thirdDataService; + + public ThirdDataController(ThirdDataService thirdDataService) { + this.thirdDataService = thirdDataService; + } + + @RequestMapping("/pressure/data") + public Object getDeviceRecentData(@RequestBody PressureDataParam pressureData) { + return thirdDataService.getDeviceRecentData(pressureData); + } + +} diff --git a/src/main/java/com/casic/dao/AlarmMapper.java b/src/main/java/com/casic/dao/AlarmMapper.java new file mode 100644 index 0000000..a442e3a --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmMapper.java @@ -0,0 +1,28 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmLevel; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + +@Mapper +public interface AlarmMapper extends BaseMapper { + + List> getAlarmRecord(@Param("deviceType") String deviceType, + @Param("devcode") String devcode, + @Param("currentIndex") Integer currentIndex, @Param("pageSize") Integer pageSize); + + Integer getAlarmTotalRecord(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteAlramBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteJobBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + String getDeviceDevcode(@Param("deviceType") String deviceType); + + String getDeviceByDevcode(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + +} diff --git a/src/main/java/com/casic/dao/BusConfigMapper.java b/src/main/java/com/casic/dao/BusConfigMapper.java new file mode 100644 index 0000000..ccf76da --- /dev/null +++ b/src/main/java/com/casic/dao/BusConfigMapper.java @@ -0,0 +1,9 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.BusConfig; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface BusConfigMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/dao/DataPressureMapper.java b/src/main/java/com/casic/dao/DataPressureMapper.java new file mode 100644 index 0000000..05f4329 --- /dev/null +++ b/src/main/java/com/casic/dao/DataPressureMapper.java @@ -0,0 +1,19 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.DataPressure; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.Date; + +@Mapper +public interface DataPressureMapper extends BaseMapper { + + String getWellCode(@Param("devcode") String devcode); + + Float getRuleValue(@Param("deviceType") String deviceType); + + void saveRecords(@Param("reValue") String reValue, @Param("alarmTime") Date alarmTime); + +} diff --git a/src/main/java/com/casic/dao/DeviceDataMapper.java b/src/main/java/com/casic/dao/DeviceDataMapper.java new file mode 100644 index 0000000..d9e18a0 --- /dev/null +++ b/src/main/java/com/casic/dao/DeviceDataMapper.java @@ -0,0 +1,27 @@ +package com.casic.dao; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + + +@Mapper +public interface DeviceDataMapper { + + List> getDeviceRecentData(@Param("tableName") String tableName, + @Param("recentNum") String recentNum, + @Param("fields") String fields, + @Param("devcode") String devcode); + + Integer getDeviceDataTotal(@Param("tableName") String tableName, @Param("devcode") String devcode); + + List> getDeviceDataListPage(@Param("tableName") String tableName, + @Param("currentIndex") Integer currentIndex, + @Param("fields") String fields, + @Param("pageSize") Integer pageSize, + @Param("devcode") String devcode); + + String getLevelByType(@Param("deviceType")String deviceType); +} diff --git a/src/main/java/com/casic/model/AlarmConfigParam.java b/src/main/java/com/casic/model/AlarmConfigParam.java new file mode 100644 index 0000000..28150d6 --- /dev/null +++ b/src/main/java/com/casic/model/AlarmConfigParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class AlarmConfigParam { + private String deviceType; + private String thresholdVol; + private String collectInterval; + private String uploadCycle; + private String retryNum; + private String ip; + private String port; + private String devcode; +} diff --git a/src/main/java/com/casic/model/AlarmLevel.java b/src/main/java/com/casic/model/AlarmLevel.java new file mode 100644 index 0000000..d0909af --- /dev/null +++ b/src/main/java/com/casic/model/AlarmLevel.java @@ -0,0 +1,26 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("alarm_level") +public class AlarmLevel{ + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + private String name; + private String deviceType; + private Integer level; + private Float lowValue; + private Float highValue; + private String openAlarm; + private String openJob; + private Date ts; + private String tenantId; + +} diff --git a/src/main/java/com/casic/model/BusConfig.java b/src/main/java/com/casic/model/BusConfig.java new file mode 100644 index 0000000..c6b7b50 --- /dev/null +++ b/src/main/java/com/casic/model/BusConfig.java @@ -0,0 +1,27 @@ +package com.casic.model; + + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +import java.util.Date; + +@Data +public class BusConfig { + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + + private String deviceId; + private String framecontent; + private String sensorid; + private String sensorcode; + + private String status; + private Integer attemptsmax; + private Integer attemptscurrent; + private Date sendtime; + private Date writetime; + +} diff --git a/src/main/java/com/casic/model/CommConfigDTO.java b/src/main/java/com/casic/model/CommConfigDTO.java new file mode 100644 index 0000000..7da699c --- /dev/null +++ b/src/main/java/com/casic/model/CommConfigDTO.java @@ -0,0 +1,41 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class CommConfigDTO { + private String acqStart;//采集开始时间 + private Long interval;//采集时间间隔(分钟) + private Long period;//上传周期 + private Long times;//采集次数 + private Long repeat;//重传次数 + private String ip; + private Long port; + private Float thresh; + private Float height; + private String collect; + private String MultiCollect; + private String acqCycle; + private String upCycle; + private String sleepStartTime; + + private String acqStartFlow ; //流量采集开始时间 + private Long intervalFlow; //流量采集采集间隔(分) + private Long acqTimesFlow ;//流量采集次数 + private String upStartFlow; //流量上报开始时间 + private Long upTimesFlow; //流量上传次数 + private String acqStartNoise; //噪声采集开始时间 + private Long intervalNoise; //噪声采集采集间隔(分) + private Long acqTimesNoise;//噪声采集次数 + private String upStartNoise; //噪声上报开始时间 + private Long upTimesNoise ;//噪声上传次数 + private String acqStartPressure; //压力采集开始时间 + private Long intervalPressure;//压力采集采集间隔(分) + private Long acqTimesPressure; //压力采集次数 + private String upStartPressure; //压力上报开始时间 + private Long upTimesPressure; //压力上传次数 + private Float lowerLimitPressure; //压力报警下限 + private Float upperLimitPressure ;//压力报警下限 + private Long limitDig ;//开挖阈值 + private Float threshold ;//开挖阈值 +} diff --git a/src/main/java/com/casic/model/DataPressure.java b/src/main/java/com/casic/model/DataPressure.java new file mode 100644 index 0000000..8270c70 --- /dev/null +++ b/src/main/java/com/casic/model/DataPressure.java @@ -0,0 +1,33 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("data_temp_press") +public class DataPressure { + + @TableId(value = "ID", type = IdType.AUTO) + private String id; + private String wellCode; + private String devcode; + private Float cell; + private String temperature; + + private String press; + private String descn; + private String uptime; + private String logtime; + /** + * 信号强度 + */ + private String pci; + + private String rsrp; + private String snr; + +} diff --git a/src/main/java/com/casic/model/PressureDataParam.java b/src/main/java/com/casic/model/PressureDataParam.java new file mode 100644 index 0000000..f42770d --- /dev/null +++ b/src/main/java/com/casic/model/PressureDataParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class PressureDataParam { + private String flag; + private String deviceUserid; + private String parentUserId; + private Object sensorsDates; + private String time; + private String rawData; + private String deviceId; +} + diff --git a/src/main/java/com/casic/model/ResponseData.java b/src/main/java/com/casic/model/ResponseData.java new file mode 100644 index 0000000..245ab04 --- /dev/null +++ b/src/main/java/com/casic/model/ResponseData.java @@ -0,0 +1,18 @@ +package com.casic.model; + +import lombok.Data; + +/** + * @author cz + * @date 2022-8-12 + */ +@Data +public class ResponseData { + public static final String DEFAULT_SUCCESS_MESSAGE = "请求成功"; + public static final String DEFAULT_ERROR_MESSAGE = "网络异常"; + public static final Integer DEFAULT_SUCCESS_CODE = 200; + public static final Integer DEFAULT_ERROR_CODE = 500; + private Integer code; + private String message; + private Object data; +} \ No newline at end of file diff --git a/src/main/java/com/casic/service/AlarmService.java b/src/main/java/com/casic/service/AlarmService.java new file mode 100644 index 0000000..8516b41 --- /dev/null +++ b/src/main/java/com/casic/service/AlarmService.java @@ -0,0 +1,12 @@ +package com.casic.service; + +import com.casic.model.AlarmConfigParam; + +public interface AlarmService { + + Object getAlarmRecord(String deviceType,Integer currentIndex,Integer pageSize,String devcode); + + Object excuteAlramBatchCancel(String deviceType,String devcode); + + Object addAlarmConfig(AlarmConfigParam alarmConfig); +} diff --git a/src/main/java/com/casic/service/DeviceDataService.java b/src/main/java/com/casic/service/DeviceDataService.java new file mode 100644 index 0000000..db656c1 --- /dev/null +++ b/src/main/java/com/casic/service/DeviceDataService.java @@ -0,0 +1,10 @@ +package com.casic.service; + +public interface DeviceDataService { + + Object getDeviceRecentData(String deviceType, String recentNum, String devcode); + + Object getDeviceListPage(String deviceType, Integer currentIndex, Integer pageSize, String devcode); + + Object getLevel(String deviceType); +} diff --git a/src/main/java/com/casic/service/ThirdDataService.java b/src/main/java/com/casic/service/ThirdDataService.java new file mode 100644 index 0000000..795e0b2 --- /dev/null +++ b/src/main/java/com/casic/service/ThirdDataService.java @@ -0,0 +1,8 @@ +package com.casic.service; + +import com.casic.model.PressureDataParam; + +public interface ThirdDataService { + + Object getDeviceRecentData(PressureDataParam pressureData); +} diff --git a/src/main/java/com/casic/service/impl/AlarmServiceImple.java b/src/main/java/com/casic/service/impl/AlarmServiceImple.java new file mode 100644 index 0000000..a675207 --- /dev/null +++ b/src/main/java/com/casic/service/impl/AlarmServiceImple.java @@ -0,0 +1,127 @@ +package com.casic.service.impl; + +import com.alibaba.druid.util.StringUtils; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.dao.AlarmMapper; +import com.casic.dao.BusConfigMapper; +import com.casic.model.*; +import com.casic.service.AlarmService; +import com.casic.util.DeviceDataTableEnum; +import com.casic.util.RedisCommonUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Slf4j +@Service +public class AlarmServiceImple extends ServiceImpl implements AlarmService { + + @Resource + private BusConfigMapper busConfigMapper; + @Resource + private RedisCommonUtil redisCommonUtil; + + public Object getAlarmRecord(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { + ResponseData responseData = new ResponseData(); + try { + Map page = new HashMap(); + page.put("total", this.baseMapper.getAlarmTotalRecord(deviceType, devcode)); + List> alarmRecordList = this.baseMapper.getAlarmRecord(deviceType, devcode, pageSize * (currentIndex - 1), pageSize); + page.put("rows", alarmRecordList); + responseData.setData(alarmRecordList); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},异常信息{}", deviceType, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + @Transactional + public Object excuteAlramBatchCancel(String deviceType, String devcode) { + ResponseData responseData = new ResponseData(); + try { + this.baseMapper.excuteAlramBatchCancel(deviceType, devcode); + this.baseMapper.excuteJobBatchCancel(deviceType, devcode); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("批量消警异常,设备类型{},异常信息{}", deviceType, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + + @Transactional + public Object addAlarmConfig(AlarmConfigParam alarmConfigParam) { + ResponseData responseData = new ResponseData(); + try { + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + addBusConfig(alarmConfigParam); + addRuleConfig(alarmConfigParam); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("风险配置异常,异常信息{}", dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + private void addRuleConfig(AlarmConfigParam alarmConfigParam) { + Map alarmRuleMap = new HashMap(); + alarmRuleMap.put("DEVICE_TYPE", alarmConfigParam.getDeviceType()); + this.baseMapper.deleteByMap(alarmRuleMap); + AlarmLevel alarmRule = new AlarmLevel(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap() + .get(Integer.valueOf(alarmConfigParam.getDeviceType())); + alarmRule.setName(deviceDataTableEnum.getTypeName()); + alarmRule.setHighValue(Float.valueOf(alarmConfigParam.getThresholdVol())); + alarmRule.setTs(new Date()); + alarmRule.setLevel(1); + alarmRule.setDeviceType(alarmConfigParam.getDeviceType()); + this.baseMapper.insert(alarmRule); + } + + private void addBusConfig(AlarmConfigParam alarmConfigParam) { + String devcode = StringUtils.isEmpty(alarmConfigParam.getDevcode()) ? this.baseMapper.getDeviceDevcode(alarmConfigParam.getDeviceType()) : alarmConfigParam.getDevcode(); + sendBusConfig(alarmConfigParam, devcode); + String devcideId = this.baseMapper.getDeviceByDevcode(alarmConfigParam.getDeviceType(), devcode); + BusConfig busConfig = new BusConfig(); + busConfig.setDeviceId(devcideId); + busConfig.setFramecontent("3," + alarmConfigParam.getCollectInterval() + "," + alarmConfigParam.getCollectInterval() + + "," + alarmConfigParam.getRetryNum() + "," + alarmConfigParam.getIp() + "," + alarmConfigParam.getPort()); + busConfig.setSensorid(""); + busConfig.setStatus("0"); + busConfig.setAttemptscurrent(0); + busConfig.setWritetime(new Date()); + busConfig.setAttemptsmax(3); + busConfigMapper.insert(busConfig); + } + + private void sendBusConfig(AlarmConfigParam alarmConfigParam, String devcode) { + CommConfigDTO commConfigDTO = new CommConfigDTO(); + commConfigDTO.setInterval(StringUtils.isEmpty(alarmConfigParam.getCollectInterval()) ? 300 : Long.valueOf(alarmConfigParam.getCollectInterval())); + commConfigDTO.setRepeat(StringUtils.isEmpty(alarmConfigParam.getRetryNum()) ? 300 : Long.valueOf(alarmConfigParam.getRetryNum())); + commConfigDTO.setTimes(Long.valueOf(1)); +// commConfigDTO.setIp(alarmConfigParam.getIp()); +// commConfigDTO.setPort(StringUtils.isEmpty(alarmConfigParam.getPort()) ? 8080 : Long.valueOf(alarmConfigParam.getPort())); + commConfigDTO.setPeriod(StringUtils.isEmpty(alarmConfigParam.getUploadCycle()) ? 300 : Long.valueOf(alarmConfigParam.getUploadCycle())); +// commConfigDTO.setThresh(); + commConfigDTO.setThresh(StringUtils.isEmpty(alarmConfigParam.getThresholdVol()) ? 50: Float.valueOf(alarmConfigParam.getThresholdVol())); + redisCommonUtil.send(commConfigDTO, devcode); + } + + +} diff --git a/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java new file mode 100644 index 0000000..3de704b --- /dev/null +++ b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java @@ -0,0 +1,80 @@ +package com.casic.service.impl; + +import com.casic.dao.DeviceDataMapper; +import com.casic.model.ResponseData; +import com.casic.service.DeviceDataService; +import com.casic.util.DeviceDataFieldTableEnum; +import com.casic.util.DeviceDataTableEnum; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Service +@Slf4j +public class DeviceDataServiceImpl implements DeviceDataService { + + private final DeviceDataMapper deviceDataMapper; + + public DeviceDataServiceImpl(DeviceDataMapper deviceDataMapper) { + this.deviceDataMapper = deviceDataMapper; + } + + public Object getDeviceRecentData(String deviceType, String recentNum, String devcode) { + ResponseData responseData = new ResponseData(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); + try { + String tableName = deviceDataTableEnum.getTableName(); + String fields = DeviceDataFieldTableEnum.TABLE_FIELD.getTableFieldMap().get(tableName); + List> recentDataList = deviceDataMapper.getDeviceRecentData(tableName, recentNum, fields, devcode); + responseData.setData(recentDataList); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备最近数据查询异常,设备类型{},查询数目{},异常信息{}", deviceType, recentNum, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + public Object getDeviceListPage(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { + ResponseData responseData = new ResponseData(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); + try { + String tableName = deviceDataTableEnum.getTableName(); + String fields = DeviceDataFieldTableEnum.TABLE_FIELD.getTableFieldMap().get(tableName); + Map page = new HashMap(); + page.put("total", deviceDataMapper.getDeviceDataTotal(tableName, devcode)); + List> recentDataList = deviceDataMapper.getDeviceDataListPage(tableName, pageSize * (currentIndex - 1), fields, pageSize, devcode); + page.put("rows", recentDataList); + responseData.setData(page); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},当前页{},页大小{},异常信息{}", deviceType, currentIndex, pageSize, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + public Object getLevel(String deviceType) { + ResponseData responseData = new ResponseData(); + try { + String highValue = deviceDataMapper.getLevelByType(deviceType); + responseData.setData(highValue); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},当前页{},页大小{},异常信息{}"); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + +} diff --git a/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java new file mode 100644 index 0000000..6b23451 --- /dev/null +++ b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java @@ -0,0 +1,92 @@ +package com.casic.service.impl; + +import com.alibaba.druid.util.StringUtils; +import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.dao.DataPressureMapper; +import com.casic.model.DataPressure; +import com.casic.model.PressureDataParam; +import com.casic.model.ResponseData; +import com.casic.service.ThirdDataService; +import com.casic.util.CacheUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.stream.Collectors; + +@Service +@Slf4j +public class ThirdDataServiceImpl extends ServiceImpl implements ThirdDataService { + + private final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA); + + public Object getDeviceRecentData(PressureDataParam pressureDataParam) { + ResponseData responseData = new ResponseData(); + try { + batchSave(pressureDataParam); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备最近数据查询异常,设备类型{},异常信息{}", dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + private void batchSave(PressureDataParam pressureDataParam) { + String pressureDataJson = pressureDataParam.getRawData(); + log.info("----" + pressureDataJson); + Map pressureDataMap = JSON.parseObject(pressureDataJson, HashMap.class); + Date uptime = null; + try { + uptime = dateFormat.parse(String.valueOf(pressureDataMap.get("times"))); + } catch (Exception e) { + log.error("主题,采集时间解析异常,异常信息{}", e.getMessage()); + } + List> pressureDataList = (List>) pressureDataMap.get("sensorDatas"); + DataPressure dataPressure = initPrssureData(pressureDataList, uptime); + if (dataPressure == null) { + return; + } + checkAlarm(dataPressure); + } + + private DataPressure initPrssureData(List> pressureDataList, Date uptime) { + DataPressure dataPressure = new DataPressure(); + String devcode = pressureDataList.get(pressureDataList.size() - 1).get("str"); + Map pressureDataMap = pressureDataList.stream().collect( + Collectors.toMap(e -> String.valueOf(e.get("flag")), e -> String.valueOf(e.get("value"))) + ); +// if (CacheUtil.serialBuf.get(devcode)!=null&&CacheUtil.serialBuf.get(devcode).equals(pressureDataMap.get("F"))) { +// return null; +// } + String wellCode = this.baseMapper.getWellCode(devcode); + dataPressure.setWellCode(wellCode); + dataPressure.setDevcode(devcode); + dataPressure.setPci(pressureDataMap.get("Q")); + dataPressure.setCell(Float.valueOf(pressureDataMap.get("V"))); + dataPressure.setTemperature(pressureDataMap.get("T")); + dataPressure.setPress(pressureDataMap.get("F")); + dataPressure.setUptime(dateFormat.format(uptime)); + dataPressure.setLogtime(dateFormat.format(new Date())); + this.baseMapper.insert(dataPressure); +// CacheUtil.serialBuf.put(devcode, pressureDataMap.get("F")); + return dataPressure; + } + + private void checkAlarm(DataPressure dataPressure) { + final Float ruleValue = this.baseMapper.getRuleValue("24"); + if (ruleValue == null) return; + if (!StringUtils.isEmpty(dataPressure.getTemperature()) && !dataPressure.getTemperature().equals("null")) { + if (Float.valueOf(dataPressure.getTemperature()) > ruleValue) { + this.baseMapper.saveRecords(dataPressure.getTemperature(), new Date()); + } + } + } + +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..50f4a19 --- /dev/null +++ b/pom.xml @@ -0,0 +1,161 @@ + + + 4.0.0 + + com.casic + smartwell-demos + 1.0-SNAPSHOT + + + + + jdk-1.8 + + true + 1.8 + + + 1.8 + 1.8 + 1.8 + + + + + + + + + + org.springframework.boot + spring-boot-starter + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-tomcat + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-web + 2.4.5 + + + + + org.springframework.boot + spring-boot-starter-jdbc + 2.4.5 + + + + mysql + mysql-connector-java + 8.0.16 + compile + + + + com.baomidou + mybatis-plus-boot-starter + 3.4.3 + + + + org.projectlombok + lombok + 1.18.20 + + + + + com.alibaba + druid + 1.2.6 + + + + com.alibaba + fastjson + 1.2.73 + + + + commons-codec + commons-codec + 1.14 + + + + redis.clients + jedis + 3.1.0 + jar + + + + org.springframework.data + spring-data-redis + 2.4.8 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.3.RELEASE + + true + + com.casic.CasicApplication + exec + + + + + repackage + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + false + + + + + + + + src/main/resources + + + /config/*/* + /config/*-*.yml + + true + + + src/main/resources + + **/*.xml + + true + + + + + \ No newline at end of file diff --git a/src/main/java/com/casic/CasicApplication.java b/src/main/java/com/casic/CasicApplication.java new file mode 100644 index 0000000..9afd0b9 --- /dev/null +++ b/src/main/java/com/casic/CasicApplication.java @@ -0,0 +1,28 @@ +package com.casic; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.transaction.annotation.EnableTransactionManagement; + + +/** + * SpringBoot方式启动类 + * + * @author cz + * @Date 2022/09/08 14:28 + */ + +@Slf4j +@ComponentScan(basePackages= "com.casic.**") +@SpringBootApplication +public class CasicApplication { + public static void main(String[] args) { + log.info("CasicApplication is success!"); + SpringApplication.run(CasicApplication.class, args); + } +} diff --git a/src/main/java/com/casic/config/CorsConfig.java b/src/main/java/com/casic/config/CorsConfig.java new file mode 100644 index 0000000..7d19680 --- /dev/null +++ b/src/main/java/com/casic/config/CorsConfig.java @@ -0,0 +1,31 @@ +package com.casic.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +/** + * 基础框架 - 跨域请求配置 + */ +@Configuration +public class CorsConfig { + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", buildConfig()); + return new CorsFilter(source); + } + + private CorsConfiguration buildConfig() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + // 1允许任何域名使用 + corsConfiguration.addAllowedOrigin("*"); + // 2允许任何头 + corsConfiguration.addAllowedHeader("*"); + // 3允许任何方法(post、get等) + corsConfiguration.addAllowedMethod("*"); + return corsConfiguration; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/controller/AlarmController.java b/src/main/java/com/casic/controller/AlarmController.java new file mode 100644 index 0000000..957fc36 --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.model.AlarmConfigParam; +import com.casic.service.AlarmService; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/alarm") +public class AlarmController { + + private final AlarmService alarmService; + + public AlarmController(AlarmService alarmService) { + this.alarmService = alarmService; + } + + @RequestMapping("/records") + public Object getAlarmRecord(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "devcode",required =false) String devcode, + @RequestParam(value = "pageSize", required = true) Integer pageSize) { + return alarmService.getAlarmRecord(deviceType,currentIndex,pageSize,devcode); + } + + @RequestMapping("/batch/cancel") + public Object excuteAlramBatchCancel(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "devcode",required =false) String devcode) { + return alarmService.excuteAlramBatchCancel(deviceType,devcode); + } + + @RequestMapping("/config/add") + public Object addAlarmConfig(@RequestBody AlarmConfigParam alarmConfigParam) { + return alarmService.addAlarmConfig(alarmConfigParam); + } +} diff --git a/src/main/java/com/casic/controller/DeviceDataController.java b/src/main/java/com/casic/controller/DeviceDataController.java new file mode 100644 index 0000000..3498b04 --- /dev/null +++ b/src/main/java/com/casic/controller/DeviceDataController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.service.DeviceDataService; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/device") +public class DeviceDataController { + private final DeviceDataService deviceDataService; + + public DeviceDataController(DeviceDataService deviceDataService) { + this.deviceDataService = deviceDataService; + } + + @RequestMapping("/recent-data") + public Object getDeviceRecentData(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "recentNum", required = true) String recentNum, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceRecentData(deviceType, recentNum, devcode); + } + + @RequestMapping("/data/list-page") + public Object getDeviceListPage(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "pageSize", required = true) Integer pageSize, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceListPage(deviceType, currentIndex, pageSize, devcode); + } + + @RequestMapping("/level/{deviceType}") + public Object getLevelList(@PathVariable("deviceType")String deviceType) { + return deviceDataService.getLevel(deviceType); + } + +} diff --git a/src/main/java/com/casic/controller/ThirdDataController.java b/src/main/java/com/casic/controller/ThirdDataController.java new file mode 100644 index 0000000..b9b2b42 --- /dev/null +++ b/src/main/java/com/casic/controller/ThirdDataController.java @@ -0,0 +1,28 @@ +package com.casic.controller; + +import com.casic.model.PressureDataParam; +import com.casic.service.ThirdDataService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +@RestController +@RequestMapping("/push") +@Slf4j +public class ThirdDataController { + + private final ThirdDataService thirdDataService; + + public ThirdDataController(ThirdDataService thirdDataService) { + this.thirdDataService = thirdDataService; + } + + @RequestMapping("/pressure/data") + public Object getDeviceRecentData(@RequestBody PressureDataParam pressureData) { + return thirdDataService.getDeviceRecentData(pressureData); + } + +} diff --git a/src/main/java/com/casic/dao/AlarmMapper.java b/src/main/java/com/casic/dao/AlarmMapper.java new file mode 100644 index 0000000..a442e3a --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmMapper.java @@ -0,0 +1,28 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmLevel; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + +@Mapper +public interface AlarmMapper extends BaseMapper { + + List> getAlarmRecord(@Param("deviceType") String deviceType, + @Param("devcode") String devcode, + @Param("currentIndex") Integer currentIndex, @Param("pageSize") Integer pageSize); + + Integer getAlarmTotalRecord(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteAlramBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteJobBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + String getDeviceDevcode(@Param("deviceType") String deviceType); + + String getDeviceByDevcode(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + +} diff --git a/src/main/java/com/casic/dao/BusConfigMapper.java b/src/main/java/com/casic/dao/BusConfigMapper.java new file mode 100644 index 0000000..ccf76da --- /dev/null +++ b/src/main/java/com/casic/dao/BusConfigMapper.java @@ -0,0 +1,9 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.BusConfig; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface BusConfigMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/dao/DataPressureMapper.java b/src/main/java/com/casic/dao/DataPressureMapper.java new file mode 100644 index 0000000..05f4329 --- /dev/null +++ b/src/main/java/com/casic/dao/DataPressureMapper.java @@ -0,0 +1,19 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.DataPressure; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.Date; + +@Mapper +public interface DataPressureMapper extends BaseMapper { + + String getWellCode(@Param("devcode") String devcode); + + Float getRuleValue(@Param("deviceType") String deviceType); + + void saveRecords(@Param("reValue") String reValue, @Param("alarmTime") Date alarmTime); + +} diff --git a/src/main/java/com/casic/dao/DeviceDataMapper.java b/src/main/java/com/casic/dao/DeviceDataMapper.java new file mode 100644 index 0000000..d9e18a0 --- /dev/null +++ b/src/main/java/com/casic/dao/DeviceDataMapper.java @@ -0,0 +1,27 @@ +package com.casic.dao; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + + +@Mapper +public interface DeviceDataMapper { + + List> getDeviceRecentData(@Param("tableName") String tableName, + @Param("recentNum") String recentNum, + @Param("fields") String fields, + @Param("devcode") String devcode); + + Integer getDeviceDataTotal(@Param("tableName") String tableName, @Param("devcode") String devcode); + + List> getDeviceDataListPage(@Param("tableName") String tableName, + @Param("currentIndex") Integer currentIndex, + @Param("fields") String fields, + @Param("pageSize") Integer pageSize, + @Param("devcode") String devcode); + + String getLevelByType(@Param("deviceType")String deviceType); +} diff --git a/src/main/java/com/casic/model/AlarmConfigParam.java b/src/main/java/com/casic/model/AlarmConfigParam.java new file mode 100644 index 0000000..28150d6 --- /dev/null +++ b/src/main/java/com/casic/model/AlarmConfigParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class AlarmConfigParam { + private String deviceType; + private String thresholdVol; + private String collectInterval; + private String uploadCycle; + private String retryNum; + private String ip; + private String port; + private String devcode; +} diff --git a/src/main/java/com/casic/model/AlarmLevel.java b/src/main/java/com/casic/model/AlarmLevel.java new file mode 100644 index 0000000..d0909af --- /dev/null +++ b/src/main/java/com/casic/model/AlarmLevel.java @@ -0,0 +1,26 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("alarm_level") +public class AlarmLevel{ + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + private String name; + private String deviceType; + private Integer level; + private Float lowValue; + private Float highValue; + private String openAlarm; + private String openJob; + private Date ts; + private String tenantId; + +} diff --git a/src/main/java/com/casic/model/BusConfig.java b/src/main/java/com/casic/model/BusConfig.java new file mode 100644 index 0000000..c6b7b50 --- /dev/null +++ b/src/main/java/com/casic/model/BusConfig.java @@ -0,0 +1,27 @@ +package com.casic.model; + + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +import java.util.Date; + +@Data +public class BusConfig { + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + + private String deviceId; + private String framecontent; + private String sensorid; + private String sensorcode; + + private String status; + private Integer attemptsmax; + private Integer attemptscurrent; + private Date sendtime; + private Date writetime; + +} diff --git a/src/main/java/com/casic/model/CommConfigDTO.java b/src/main/java/com/casic/model/CommConfigDTO.java new file mode 100644 index 0000000..7da699c --- /dev/null +++ b/src/main/java/com/casic/model/CommConfigDTO.java @@ -0,0 +1,41 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class CommConfigDTO { + private String acqStart;//采集开始时间 + private Long interval;//采集时间间隔(分钟) + private Long period;//上传周期 + private Long times;//采集次数 + private Long repeat;//重传次数 + private String ip; + private Long port; + private Float thresh; + private Float height; + private String collect; + private String MultiCollect; + private String acqCycle; + private String upCycle; + private String sleepStartTime; + + private String acqStartFlow ; //流量采集开始时间 + private Long intervalFlow; //流量采集采集间隔(分) + private Long acqTimesFlow ;//流量采集次数 + private String upStartFlow; //流量上报开始时间 + private Long upTimesFlow; //流量上传次数 + private String acqStartNoise; //噪声采集开始时间 + private Long intervalNoise; //噪声采集采集间隔(分) + private Long acqTimesNoise;//噪声采集次数 + private String upStartNoise; //噪声上报开始时间 + private Long upTimesNoise ;//噪声上传次数 + private String acqStartPressure; //压力采集开始时间 + private Long intervalPressure;//压力采集采集间隔(分) + private Long acqTimesPressure; //压力采集次数 + private String upStartPressure; //压力上报开始时间 + private Long upTimesPressure; //压力上传次数 + private Float lowerLimitPressure; //压力报警下限 + private Float upperLimitPressure ;//压力报警下限 + private Long limitDig ;//开挖阈值 + private Float threshold ;//开挖阈值 +} diff --git a/src/main/java/com/casic/model/DataPressure.java b/src/main/java/com/casic/model/DataPressure.java new file mode 100644 index 0000000..8270c70 --- /dev/null +++ b/src/main/java/com/casic/model/DataPressure.java @@ -0,0 +1,33 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("data_temp_press") +public class DataPressure { + + @TableId(value = "ID", type = IdType.AUTO) + private String id; + private String wellCode; + private String devcode; + private Float cell; + private String temperature; + + private String press; + private String descn; + private String uptime; + private String logtime; + /** + * 信号强度 + */ + private String pci; + + private String rsrp; + private String snr; + +} diff --git a/src/main/java/com/casic/model/PressureDataParam.java b/src/main/java/com/casic/model/PressureDataParam.java new file mode 100644 index 0000000..f42770d --- /dev/null +++ b/src/main/java/com/casic/model/PressureDataParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class PressureDataParam { + private String flag; + private String deviceUserid; + private String parentUserId; + private Object sensorsDates; + private String time; + private String rawData; + private String deviceId; +} + diff --git a/src/main/java/com/casic/model/ResponseData.java b/src/main/java/com/casic/model/ResponseData.java new file mode 100644 index 0000000..245ab04 --- /dev/null +++ b/src/main/java/com/casic/model/ResponseData.java @@ -0,0 +1,18 @@ +package com.casic.model; + +import lombok.Data; + +/** + * @author cz + * @date 2022-8-12 + */ +@Data +public class ResponseData { + public static final String DEFAULT_SUCCESS_MESSAGE = "请求成功"; + public static final String DEFAULT_ERROR_MESSAGE = "网络异常"; + public static final Integer DEFAULT_SUCCESS_CODE = 200; + public static final Integer DEFAULT_ERROR_CODE = 500; + private Integer code; + private String message; + private Object data; +} \ No newline at end of file diff --git a/src/main/java/com/casic/service/AlarmService.java b/src/main/java/com/casic/service/AlarmService.java new file mode 100644 index 0000000..8516b41 --- /dev/null +++ b/src/main/java/com/casic/service/AlarmService.java @@ -0,0 +1,12 @@ +package com.casic.service; + +import com.casic.model.AlarmConfigParam; + +public interface AlarmService { + + Object getAlarmRecord(String deviceType,Integer currentIndex,Integer pageSize,String devcode); + + Object excuteAlramBatchCancel(String deviceType,String devcode); + + Object addAlarmConfig(AlarmConfigParam alarmConfig); +} diff --git a/src/main/java/com/casic/service/DeviceDataService.java b/src/main/java/com/casic/service/DeviceDataService.java new file mode 100644 index 0000000..db656c1 --- /dev/null +++ b/src/main/java/com/casic/service/DeviceDataService.java @@ -0,0 +1,10 @@ +package com.casic.service; + +public interface DeviceDataService { + + Object getDeviceRecentData(String deviceType, String recentNum, String devcode); + + Object getDeviceListPage(String deviceType, Integer currentIndex, Integer pageSize, String devcode); + + Object getLevel(String deviceType); +} diff --git a/src/main/java/com/casic/service/ThirdDataService.java b/src/main/java/com/casic/service/ThirdDataService.java new file mode 100644 index 0000000..795e0b2 --- /dev/null +++ b/src/main/java/com/casic/service/ThirdDataService.java @@ -0,0 +1,8 @@ +package com.casic.service; + +import com.casic.model.PressureDataParam; + +public interface ThirdDataService { + + Object getDeviceRecentData(PressureDataParam pressureData); +} diff --git a/src/main/java/com/casic/service/impl/AlarmServiceImple.java b/src/main/java/com/casic/service/impl/AlarmServiceImple.java new file mode 100644 index 0000000..a675207 --- /dev/null +++ b/src/main/java/com/casic/service/impl/AlarmServiceImple.java @@ -0,0 +1,127 @@ +package com.casic.service.impl; + +import com.alibaba.druid.util.StringUtils; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.dao.AlarmMapper; +import com.casic.dao.BusConfigMapper; +import com.casic.model.*; +import com.casic.service.AlarmService; +import com.casic.util.DeviceDataTableEnum; +import com.casic.util.RedisCommonUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Slf4j +@Service +public class AlarmServiceImple extends ServiceImpl implements AlarmService { + + @Resource + private BusConfigMapper busConfigMapper; + @Resource + private RedisCommonUtil redisCommonUtil; + + public Object getAlarmRecord(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { + ResponseData responseData = new ResponseData(); + try { + Map page = new HashMap(); + page.put("total", this.baseMapper.getAlarmTotalRecord(deviceType, devcode)); + List> alarmRecordList = this.baseMapper.getAlarmRecord(deviceType, devcode, pageSize * (currentIndex - 1), pageSize); + page.put("rows", alarmRecordList); + responseData.setData(alarmRecordList); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},异常信息{}", deviceType, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + @Transactional + public Object excuteAlramBatchCancel(String deviceType, String devcode) { + ResponseData responseData = new ResponseData(); + try { + this.baseMapper.excuteAlramBatchCancel(deviceType, devcode); + this.baseMapper.excuteJobBatchCancel(deviceType, devcode); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("批量消警异常,设备类型{},异常信息{}", deviceType, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + + @Transactional + public Object addAlarmConfig(AlarmConfigParam alarmConfigParam) { + ResponseData responseData = new ResponseData(); + try { + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + addBusConfig(alarmConfigParam); + addRuleConfig(alarmConfigParam); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("风险配置异常,异常信息{}", dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + private void addRuleConfig(AlarmConfigParam alarmConfigParam) { + Map alarmRuleMap = new HashMap(); + alarmRuleMap.put("DEVICE_TYPE", alarmConfigParam.getDeviceType()); + this.baseMapper.deleteByMap(alarmRuleMap); + AlarmLevel alarmRule = new AlarmLevel(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap() + .get(Integer.valueOf(alarmConfigParam.getDeviceType())); + alarmRule.setName(deviceDataTableEnum.getTypeName()); + alarmRule.setHighValue(Float.valueOf(alarmConfigParam.getThresholdVol())); + alarmRule.setTs(new Date()); + alarmRule.setLevel(1); + alarmRule.setDeviceType(alarmConfigParam.getDeviceType()); + this.baseMapper.insert(alarmRule); + } + + private void addBusConfig(AlarmConfigParam alarmConfigParam) { + String devcode = StringUtils.isEmpty(alarmConfigParam.getDevcode()) ? this.baseMapper.getDeviceDevcode(alarmConfigParam.getDeviceType()) : alarmConfigParam.getDevcode(); + sendBusConfig(alarmConfigParam, devcode); + String devcideId = this.baseMapper.getDeviceByDevcode(alarmConfigParam.getDeviceType(), devcode); + BusConfig busConfig = new BusConfig(); + busConfig.setDeviceId(devcideId); + busConfig.setFramecontent("3," + alarmConfigParam.getCollectInterval() + "," + alarmConfigParam.getCollectInterval() + + "," + alarmConfigParam.getRetryNum() + "," + alarmConfigParam.getIp() + "," + alarmConfigParam.getPort()); + busConfig.setSensorid(""); + busConfig.setStatus("0"); + busConfig.setAttemptscurrent(0); + busConfig.setWritetime(new Date()); + busConfig.setAttemptsmax(3); + busConfigMapper.insert(busConfig); + } + + private void sendBusConfig(AlarmConfigParam alarmConfigParam, String devcode) { + CommConfigDTO commConfigDTO = new CommConfigDTO(); + commConfigDTO.setInterval(StringUtils.isEmpty(alarmConfigParam.getCollectInterval()) ? 300 : Long.valueOf(alarmConfigParam.getCollectInterval())); + commConfigDTO.setRepeat(StringUtils.isEmpty(alarmConfigParam.getRetryNum()) ? 300 : Long.valueOf(alarmConfigParam.getRetryNum())); + commConfigDTO.setTimes(Long.valueOf(1)); +// commConfigDTO.setIp(alarmConfigParam.getIp()); +// commConfigDTO.setPort(StringUtils.isEmpty(alarmConfigParam.getPort()) ? 8080 : Long.valueOf(alarmConfigParam.getPort())); + commConfigDTO.setPeriod(StringUtils.isEmpty(alarmConfigParam.getUploadCycle()) ? 300 : Long.valueOf(alarmConfigParam.getUploadCycle())); +// commConfigDTO.setThresh(); + commConfigDTO.setThresh(StringUtils.isEmpty(alarmConfigParam.getThresholdVol()) ? 50: Float.valueOf(alarmConfigParam.getThresholdVol())); + redisCommonUtil.send(commConfigDTO, devcode); + } + + +} diff --git a/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java new file mode 100644 index 0000000..3de704b --- /dev/null +++ b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java @@ -0,0 +1,80 @@ +package com.casic.service.impl; + +import com.casic.dao.DeviceDataMapper; +import com.casic.model.ResponseData; +import com.casic.service.DeviceDataService; +import com.casic.util.DeviceDataFieldTableEnum; +import com.casic.util.DeviceDataTableEnum; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Service +@Slf4j +public class DeviceDataServiceImpl implements DeviceDataService { + + private final DeviceDataMapper deviceDataMapper; + + public DeviceDataServiceImpl(DeviceDataMapper deviceDataMapper) { + this.deviceDataMapper = deviceDataMapper; + } + + public Object getDeviceRecentData(String deviceType, String recentNum, String devcode) { + ResponseData responseData = new ResponseData(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); + try { + String tableName = deviceDataTableEnum.getTableName(); + String fields = DeviceDataFieldTableEnum.TABLE_FIELD.getTableFieldMap().get(tableName); + List> recentDataList = deviceDataMapper.getDeviceRecentData(tableName, recentNum, fields, devcode); + responseData.setData(recentDataList); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备最近数据查询异常,设备类型{},查询数目{},异常信息{}", deviceType, recentNum, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + public Object getDeviceListPage(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { + ResponseData responseData = new ResponseData(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); + try { + String tableName = deviceDataTableEnum.getTableName(); + String fields = DeviceDataFieldTableEnum.TABLE_FIELD.getTableFieldMap().get(tableName); + Map page = new HashMap(); + page.put("total", deviceDataMapper.getDeviceDataTotal(tableName, devcode)); + List> recentDataList = deviceDataMapper.getDeviceDataListPage(tableName, pageSize * (currentIndex - 1), fields, pageSize, devcode); + page.put("rows", recentDataList); + responseData.setData(page); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},当前页{},页大小{},异常信息{}", deviceType, currentIndex, pageSize, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + public Object getLevel(String deviceType) { + ResponseData responseData = new ResponseData(); + try { + String highValue = deviceDataMapper.getLevelByType(deviceType); + responseData.setData(highValue); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},当前页{},页大小{},异常信息{}"); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + +} diff --git a/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java new file mode 100644 index 0000000..6b23451 --- /dev/null +++ b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java @@ -0,0 +1,92 @@ +package com.casic.service.impl; + +import com.alibaba.druid.util.StringUtils; +import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.dao.DataPressureMapper; +import com.casic.model.DataPressure; +import com.casic.model.PressureDataParam; +import com.casic.model.ResponseData; +import com.casic.service.ThirdDataService; +import com.casic.util.CacheUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.stream.Collectors; + +@Service +@Slf4j +public class ThirdDataServiceImpl extends ServiceImpl implements ThirdDataService { + + private final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA); + + public Object getDeviceRecentData(PressureDataParam pressureDataParam) { + ResponseData responseData = new ResponseData(); + try { + batchSave(pressureDataParam); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备最近数据查询异常,设备类型{},异常信息{}", dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + private void batchSave(PressureDataParam pressureDataParam) { + String pressureDataJson = pressureDataParam.getRawData(); + log.info("----" + pressureDataJson); + Map pressureDataMap = JSON.parseObject(pressureDataJson, HashMap.class); + Date uptime = null; + try { + uptime = dateFormat.parse(String.valueOf(pressureDataMap.get("times"))); + } catch (Exception e) { + log.error("主题,采集时间解析异常,异常信息{}", e.getMessage()); + } + List> pressureDataList = (List>) pressureDataMap.get("sensorDatas"); + DataPressure dataPressure = initPrssureData(pressureDataList, uptime); + if (dataPressure == null) { + return; + } + checkAlarm(dataPressure); + } + + private DataPressure initPrssureData(List> pressureDataList, Date uptime) { + DataPressure dataPressure = new DataPressure(); + String devcode = pressureDataList.get(pressureDataList.size() - 1).get("str"); + Map pressureDataMap = pressureDataList.stream().collect( + Collectors.toMap(e -> String.valueOf(e.get("flag")), e -> String.valueOf(e.get("value"))) + ); +// if (CacheUtil.serialBuf.get(devcode)!=null&&CacheUtil.serialBuf.get(devcode).equals(pressureDataMap.get("F"))) { +// return null; +// } + String wellCode = this.baseMapper.getWellCode(devcode); + dataPressure.setWellCode(wellCode); + dataPressure.setDevcode(devcode); + dataPressure.setPci(pressureDataMap.get("Q")); + dataPressure.setCell(Float.valueOf(pressureDataMap.get("V"))); + dataPressure.setTemperature(pressureDataMap.get("T")); + dataPressure.setPress(pressureDataMap.get("F")); + dataPressure.setUptime(dateFormat.format(uptime)); + dataPressure.setLogtime(dateFormat.format(new Date())); + this.baseMapper.insert(dataPressure); +// CacheUtil.serialBuf.put(devcode, pressureDataMap.get("F")); + return dataPressure; + } + + private void checkAlarm(DataPressure dataPressure) { + final Float ruleValue = this.baseMapper.getRuleValue("24"); + if (ruleValue == null) return; + if (!StringUtils.isEmpty(dataPressure.getTemperature()) && !dataPressure.getTemperature().equals("null")) { + if (Float.valueOf(dataPressure.getTemperature()) > ruleValue) { + this.baseMapper.saveRecords(dataPressure.getTemperature(), new Date()); + } + } + } + +} diff --git a/src/main/java/com/casic/util/CacheUtil.java b/src/main/java/com/casic/util/CacheUtil.java new file mode 100644 index 0000000..5b89300 --- /dev/null +++ b/src/main/java/com/casic/util/CacheUtil.java @@ -0,0 +1,16 @@ +package com.casic.util; + +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import java.util.HashMap; +import java.util.Map; + +@Component +public class CacheUtil { + public static volatile Map serialBuf; + @PostConstruct + public void init() { + serialBuf = new HashMap<>(); + } +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..50f4a19 --- /dev/null +++ b/pom.xml @@ -0,0 +1,161 @@ + + + 4.0.0 + + com.casic + smartwell-demos + 1.0-SNAPSHOT + + + + + jdk-1.8 + + true + 1.8 + + + 1.8 + 1.8 + 1.8 + + + + + + + + + + org.springframework.boot + spring-boot-starter + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-tomcat + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-web + 2.4.5 + + + + + org.springframework.boot + spring-boot-starter-jdbc + 2.4.5 + + + + mysql + mysql-connector-java + 8.0.16 + compile + + + + com.baomidou + mybatis-plus-boot-starter + 3.4.3 + + + + org.projectlombok + lombok + 1.18.20 + + + + + com.alibaba + druid + 1.2.6 + + + + com.alibaba + fastjson + 1.2.73 + + + + commons-codec + commons-codec + 1.14 + + + + redis.clients + jedis + 3.1.0 + jar + + + + org.springframework.data + spring-data-redis + 2.4.8 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.3.RELEASE + + true + + com.casic.CasicApplication + exec + + + + + repackage + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + false + + + + + + + + src/main/resources + + + /config/*/* + /config/*-*.yml + + true + + + src/main/resources + + **/*.xml + + true + + + + + \ No newline at end of file diff --git a/src/main/java/com/casic/CasicApplication.java b/src/main/java/com/casic/CasicApplication.java new file mode 100644 index 0000000..9afd0b9 --- /dev/null +++ b/src/main/java/com/casic/CasicApplication.java @@ -0,0 +1,28 @@ +package com.casic; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.transaction.annotation.EnableTransactionManagement; + + +/** + * SpringBoot方式启动类 + * + * @author cz + * @Date 2022/09/08 14:28 + */ + +@Slf4j +@ComponentScan(basePackages= "com.casic.**") +@SpringBootApplication +public class CasicApplication { + public static void main(String[] args) { + log.info("CasicApplication is success!"); + SpringApplication.run(CasicApplication.class, args); + } +} diff --git a/src/main/java/com/casic/config/CorsConfig.java b/src/main/java/com/casic/config/CorsConfig.java new file mode 100644 index 0000000..7d19680 --- /dev/null +++ b/src/main/java/com/casic/config/CorsConfig.java @@ -0,0 +1,31 @@ +package com.casic.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +/** + * 基础框架 - 跨域请求配置 + */ +@Configuration +public class CorsConfig { + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", buildConfig()); + return new CorsFilter(source); + } + + private CorsConfiguration buildConfig() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + // 1允许任何域名使用 + corsConfiguration.addAllowedOrigin("*"); + // 2允许任何头 + corsConfiguration.addAllowedHeader("*"); + // 3允许任何方法(post、get等) + corsConfiguration.addAllowedMethod("*"); + return corsConfiguration; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/controller/AlarmController.java b/src/main/java/com/casic/controller/AlarmController.java new file mode 100644 index 0000000..957fc36 --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.model.AlarmConfigParam; +import com.casic.service.AlarmService; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/alarm") +public class AlarmController { + + private final AlarmService alarmService; + + public AlarmController(AlarmService alarmService) { + this.alarmService = alarmService; + } + + @RequestMapping("/records") + public Object getAlarmRecord(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "devcode",required =false) String devcode, + @RequestParam(value = "pageSize", required = true) Integer pageSize) { + return alarmService.getAlarmRecord(deviceType,currentIndex,pageSize,devcode); + } + + @RequestMapping("/batch/cancel") + public Object excuteAlramBatchCancel(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "devcode",required =false) String devcode) { + return alarmService.excuteAlramBatchCancel(deviceType,devcode); + } + + @RequestMapping("/config/add") + public Object addAlarmConfig(@RequestBody AlarmConfigParam alarmConfigParam) { + return alarmService.addAlarmConfig(alarmConfigParam); + } +} diff --git a/src/main/java/com/casic/controller/DeviceDataController.java b/src/main/java/com/casic/controller/DeviceDataController.java new file mode 100644 index 0000000..3498b04 --- /dev/null +++ b/src/main/java/com/casic/controller/DeviceDataController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.service.DeviceDataService; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/device") +public class DeviceDataController { + private final DeviceDataService deviceDataService; + + public DeviceDataController(DeviceDataService deviceDataService) { + this.deviceDataService = deviceDataService; + } + + @RequestMapping("/recent-data") + public Object getDeviceRecentData(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "recentNum", required = true) String recentNum, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceRecentData(deviceType, recentNum, devcode); + } + + @RequestMapping("/data/list-page") + public Object getDeviceListPage(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "pageSize", required = true) Integer pageSize, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceListPage(deviceType, currentIndex, pageSize, devcode); + } + + @RequestMapping("/level/{deviceType}") + public Object getLevelList(@PathVariable("deviceType")String deviceType) { + return deviceDataService.getLevel(deviceType); + } + +} diff --git a/src/main/java/com/casic/controller/ThirdDataController.java b/src/main/java/com/casic/controller/ThirdDataController.java new file mode 100644 index 0000000..b9b2b42 --- /dev/null +++ b/src/main/java/com/casic/controller/ThirdDataController.java @@ -0,0 +1,28 @@ +package com.casic.controller; + +import com.casic.model.PressureDataParam; +import com.casic.service.ThirdDataService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +@RestController +@RequestMapping("/push") +@Slf4j +public class ThirdDataController { + + private final ThirdDataService thirdDataService; + + public ThirdDataController(ThirdDataService thirdDataService) { + this.thirdDataService = thirdDataService; + } + + @RequestMapping("/pressure/data") + public Object getDeviceRecentData(@RequestBody PressureDataParam pressureData) { + return thirdDataService.getDeviceRecentData(pressureData); + } + +} diff --git a/src/main/java/com/casic/dao/AlarmMapper.java b/src/main/java/com/casic/dao/AlarmMapper.java new file mode 100644 index 0000000..a442e3a --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmMapper.java @@ -0,0 +1,28 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmLevel; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + +@Mapper +public interface AlarmMapper extends BaseMapper { + + List> getAlarmRecord(@Param("deviceType") String deviceType, + @Param("devcode") String devcode, + @Param("currentIndex") Integer currentIndex, @Param("pageSize") Integer pageSize); + + Integer getAlarmTotalRecord(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteAlramBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteJobBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + String getDeviceDevcode(@Param("deviceType") String deviceType); + + String getDeviceByDevcode(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + +} diff --git a/src/main/java/com/casic/dao/BusConfigMapper.java b/src/main/java/com/casic/dao/BusConfigMapper.java new file mode 100644 index 0000000..ccf76da --- /dev/null +++ b/src/main/java/com/casic/dao/BusConfigMapper.java @@ -0,0 +1,9 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.BusConfig; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface BusConfigMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/dao/DataPressureMapper.java b/src/main/java/com/casic/dao/DataPressureMapper.java new file mode 100644 index 0000000..05f4329 --- /dev/null +++ b/src/main/java/com/casic/dao/DataPressureMapper.java @@ -0,0 +1,19 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.DataPressure; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.Date; + +@Mapper +public interface DataPressureMapper extends BaseMapper { + + String getWellCode(@Param("devcode") String devcode); + + Float getRuleValue(@Param("deviceType") String deviceType); + + void saveRecords(@Param("reValue") String reValue, @Param("alarmTime") Date alarmTime); + +} diff --git a/src/main/java/com/casic/dao/DeviceDataMapper.java b/src/main/java/com/casic/dao/DeviceDataMapper.java new file mode 100644 index 0000000..d9e18a0 --- /dev/null +++ b/src/main/java/com/casic/dao/DeviceDataMapper.java @@ -0,0 +1,27 @@ +package com.casic.dao; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + + +@Mapper +public interface DeviceDataMapper { + + List> getDeviceRecentData(@Param("tableName") String tableName, + @Param("recentNum") String recentNum, + @Param("fields") String fields, + @Param("devcode") String devcode); + + Integer getDeviceDataTotal(@Param("tableName") String tableName, @Param("devcode") String devcode); + + List> getDeviceDataListPage(@Param("tableName") String tableName, + @Param("currentIndex") Integer currentIndex, + @Param("fields") String fields, + @Param("pageSize") Integer pageSize, + @Param("devcode") String devcode); + + String getLevelByType(@Param("deviceType")String deviceType); +} diff --git a/src/main/java/com/casic/model/AlarmConfigParam.java b/src/main/java/com/casic/model/AlarmConfigParam.java new file mode 100644 index 0000000..28150d6 --- /dev/null +++ b/src/main/java/com/casic/model/AlarmConfigParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class AlarmConfigParam { + private String deviceType; + private String thresholdVol; + private String collectInterval; + private String uploadCycle; + private String retryNum; + private String ip; + private String port; + private String devcode; +} diff --git a/src/main/java/com/casic/model/AlarmLevel.java b/src/main/java/com/casic/model/AlarmLevel.java new file mode 100644 index 0000000..d0909af --- /dev/null +++ b/src/main/java/com/casic/model/AlarmLevel.java @@ -0,0 +1,26 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("alarm_level") +public class AlarmLevel{ + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + private String name; + private String deviceType; + private Integer level; + private Float lowValue; + private Float highValue; + private String openAlarm; + private String openJob; + private Date ts; + private String tenantId; + +} diff --git a/src/main/java/com/casic/model/BusConfig.java b/src/main/java/com/casic/model/BusConfig.java new file mode 100644 index 0000000..c6b7b50 --- /dev/null +++ b/src/main/java/com/casic/model/BusConfig.java @@ -0,0 +1,27 @@ +package com.casic.model; + + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +import java.util.Date; + +@Data +public class BusConfig { + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + + private String deviceId; + private String framecontent; + private String sensorid; + private String sensorcode; + + private String status; + private Integer attemptsmax; + private Integer attemptscurrent; + private Date sendtime; + private Date writetime; + +} diff --git a/src/main/java/com/casic/model/CommConfigDTO.java b/src/main/java/com/casic/model/CommConfigDTO.java new file mode 100644 index 0000000..7da699c --- /dev/null +++ b/src/main/java/com/casic/model/CommConfigDTO.java @@ -0,0 +1,41 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class CommConfigDTO { + private String acqStart;//采集开始时间 + private Long interval;//采集时间间隔(分钟) + private Long period;//上传周期 + private Long times;//采集次数 + private Long repeat;//重传次数 + private String ip; + private Long port; + private Float thresh; + private Float height; + private String collect; + private String MultiCollect; + private String acqCycle; + private String upCycle; + private String sleepStartTime; + + private String acqStartFlow ; //流量采集开始时间 + private Long intervalFlow; //流量采集采集间隔(分) + private Long acqTimesFlow ;//流量采集次数 + private String upStartFlow; //流量上报开始时间 + private Long upTimesFlow; //流量上传次数 + private String acqStartNoise; //噪声采集开始时间 + private Long intervalNoise; //噪声采集采集间隔(分) + private Long acqTimesNoise;//噪声采集次数 + private String upStartNoise; //噪声上报开始时间 + private Long upTimesNoise ;//噪声上传次数 + private String acqStartPressure; //压力采集开始时间 + private Long intervalPressure;//压力采集采集间隔(分) + private Long acqTimesPressure; //压力采集次数 + private String upStartPressure; //压力上报开始时间 + private Long upTimesPressure; //压力上传次数 + private Float lowerLimitPressure; //压力报警下限 + private Float upperLimitPressure ;//压力报警下限 + private Long limitDig ;//开挖阈值 + private Float threshold ;//开挖阈值 +} diff --git a/src/main/java/com/casic/model/DataPressure.java b/src/main/java/com/casic/model/DataPressure.java new file mode 100644 index 0000000..8270c70 --- /dev/null +++ b/src/main/java/com/casic/model/DataPressure.java @@ -0,0 +1,33 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("data_temp_press") +public class DataPressure { + + @TableId(value = "ID", type = IdType.AUTO) + private String id; + private String wellCode; + private String devcode; + private Float cell; + private String temperature; + + private String press; + private String descn; + private String uptime; + private String logtime; + /** + * 信号强度 + */ + private String pci; + + private String rsrp; + private String snr; + +} diff --git a/src/main/java/com/casic/model/PressureDataParam.java b/src/main/java/com/casic/model/PressureDataParam.java new file mode 100644 index 0000000..f42770d --- /dev/null +++ b/src/main/java/com/casic/model/PressureDataParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class PressureDataParam { + private String flag; + private String deviceUserid; + private String parentUserId; + private Object sensorsDates; + private String time; + private String rawData; + private String deviceId; +} + diff --git a/src/main/java/com/casic/model/ResponseData.java b/src/main/java/com/casic/model/ResponseData.java new file mode 100644 index 0000000..245ab04 --- /dev/null +++ b/src/main/java/com/casic/model/ResponseData.java @@ -0,0 +1,18 @@ +package com.casic.model; + +import lombok.Data; + +/** + * @author cz + * @date 2022-8-12 + */ +@Data +public class ResponseData { + public static final String DEFAULT_SUCCESS_MESSAGE = "请求成功"; + public static final String DEFAULT_ERROR_MESSAGE = "网络异常"; + public static final Integer DEFAULT_SUCCESS_CODE = 200; + public static final Integer DEFAULT_ERROR_CODE = 500; + private Integer code; + private String message; + private Object data; +} \ No newline at end of file diff --git a/src/main/java/com/casic/service/AlarmService.java b/src/main/java/com/casic/service/AlarmService.java new file mode 100644 index 0000000..8516b41 --- /dev/null +++ b/src/main/java/com/casic/service/AlarmService.java @@ -0,0 +1,12 @@ +package com.casic.service; + +import com.casic.model.AlarmConfigParam; + +public interface AlarmService { + + Object getAlarmRecord(String deviceType,Integer currentIndex,Integer pageSize,String devcode); + + Object excuteAlramBatchCancel(String deviceType,String devcode); + + Object addAlarmConfig(AlarmConfigParam alarmConfig); +} diff --git a/src/main/java/com/casic/service/DeviceDataService.java b/src/main/java/com/casic/service/DeviceDataService.java new file mode 100644 index 0000000..db656c1 --- /dev/null +++ b/src/main/java/com/casic/service/DeviceDataService.java @@ -0,0 +1,10 @@ +package com.casic.service; + +public interface DeviceDataService { + + Object getDeviceRecentData(String deviceType, String recentNum, String devcode); + + Object getDeviceListPage(String deviceType, Integer currentIndex, Integer pageSize, String devcode); + + Object getLevel(String deviceType); +} diff --git a/src/main/java/com/casic/service/ThirdDataService.java b/src/main/java/com/casic/service/ThirdDataService.java new file mode 100644 index 0000000..795e0b2 --- /dev/null +++ b/src/main/java/com/casic/service/ThirdDataService.java @@ -0,0 +1,8 @@ +package com.casic.service; + +import com.casic.model.PressureDataParam; + +public interface ThirdDataService { + + Object getDeviceRecentData(PressureDataParam pressureData); +} diff --git a/src/main/java/com/casic/service/impl/AlarmServiceImple.java b/src/main/java/com/casic/service/impl/AlarmServiceImple.java new file mode 100644 index 0000000..a675207 --- /dev/null +++ b/src/main/java/com/casic/service/impl/AlarmServiceImple.java @@ -0,0 +1,127 @@ +package com.casic.service.impl; + +import com.alibaba.druid.util.StringUtils; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.dao.AlarmMapper; +import com.casic.dao.BusConfigMapper; +import com.casic.model.*; +import com.casic.service.AlarmService; +import com.casic.util.DeviceDataTableEnum; +import com.casic.util.RedisCommonUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Slf4j +@Service +public class AlarmServiceImple extends ServiceImpl implements AlarmService { + + @Resource + private BusConfigMapper busConfigMapper; + @Resource + private RedisCommonUtil redisCommonUtil; + + public Object getAlarmRecord(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { + ResponseData responseData = new ResponseData(); + try { + Map page = new HashMap(); + page.put("total", this.baseMapper.getAlarmTotalRecord(deviceType, devcode)); + List> alarmRecordList = this.baseMapper.getAlarmRecord(deviceType, devcode, pageSize * (currentIndex - 1), pageSize); + page.put("rows", alarmRecordList); + responseData.setData(alarmRecordList); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},异常信息{}", deviceType, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + @Transactional + public Object excuteAlramBatchCancel(String deviceType, String devcode) { + ResponseData responseData = new ResponseData(); + try { + this.baseMapper.excuteAlramBatchCancel(deviceType, devcode); + this.baseMapper.excuteJobBatchCancel(deviceType, devcode); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("批量消警异常,设备类型{},异常信息{}", deviceType, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + + @Transactional + public Object addAlarmConfig(AlarmConfigParam alarmConfigParam) { + ResponseData responseData = new ResponseData(); + try { + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + addBusConfig(alarmConfigParam); + addRuleConfig(alarmConfigParam); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("风险配置异常,异常信息{}", dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + private void addRuleConfig(AlarmConfigParam alarmConfigParam) { + Map alarmRuleMap = new HashMap(); + alarmRuleMap.put("DEVICE_TYPE", alarmConfigParam.getDeviceType()); + this.baseMapper.deleteByMap(alarmRuleMap); + AlarmLevel alarmRule = new AlarmLevel(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap() + .get(Integer.valueOf(alarmConfigParam.getDeviceType())); + alarmRule.setName(deviceDataTableEnum.getTypeName()); + alarmRule.setHighValue(Float.valueOf(alarmConfigParam.getThresholdVol())); + alarmRule.setTs(new Date()); + alarmRule.setLevel(1); + alarmRule.setDeviceType(alarmConfigParam.getDeviceType()); + this.baseMapper.insert(alarmRule); + } + + private void addBusConfig(AlarmConfigParam alarmConfigParam) { + String devcode = StringUtils.isEmpty(alarmConfigParam.getDevcode()) ? this.baseMapper.getDeviceDevcode(alarmConfigParam.getDeviceType()) : alarmConfigParam.getDevcode(); + sendBusConfig(alarmConfigParam, devcode); + String devcideId = this.baseMapper.getDeviceByDevcode(alarmConfigParam.getDeviceType(), devcode); + BusConfig busConfig = new BusConfig(); + busConfig.setDeviceId(devcideId); + busConfig.setFramecontent("3," + alarmConfigParam.getCollectInterval() + "," + alarmConfigParam.getCollectInterval() + + "," + alarmConfigParam.getRetryNum() + "," + alarmConfigParam.getIp() + "," + alarmConfigParam.getPort()); + busConfig.setSensorid(""); + busConfig.setStatus("0"); + busConfig.setAttemptscurrent(0); + busConfig.setWritetime(new Date()); + busConfig.setAttemptsmax(3); + busConfigMapper.insert(busConfig); + } + + private void sendBusConfig(AlarmConfigParam alarmConfigParam, String devcode) { + CommConfigDTO commConfigDTO = new CommConfigDTO(); + commConfigDTO.setInterval(StringUtils.isEmpty(alarmConfigParam.getCollectInterval()) ? 300 : Long.valueOf(alarmConfigParam.getCollectInterval())); + commConfigDTO.setRepeat(StringUtils.isEmpty(alarmConfigParam.getRetryNum()) ? 300 : Long.valueOf(alarmConfigParam.getRetryNum())); + commConfigDTO.setTimes(Long.valueOf(1)); +// commConfigDTO.setIp(alarmConfigParam.getIp()); +// commConfigDTO.setPort(StringUtils.isEmpty(alarmConfigParam.getPort()) ? 8080 : Long.valueOf(alarmConfigParam.getPort())); + commConfigDTO.setPeriod(StringUtils.isEmpty(alarmConfigParam.getUploadCycle()) ? 300 : Long.valueOf(alarmConfigParam.getUploadCycle())); +// commConfigDTO.setThresh(); + commConfigDTO.setThresh(StringUtils.isEmpty(alarmConfigParam.getThresholdVol()) ? 50: Float.valueOf(alarmConfigParam.getThresholdVol())); + redisCommonUtil.send(commConfigDTO, devcode); + } + + +} diff --git a/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java new file mode 100644 index 0000000..3de704b --- /dev/null +++ b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java @@ -0,0 +1,80 @@ +package com.casic.service.impl; + +import com.casic.dao.DeviceDataMapper; +import com.casic.model.ResponseData; +import com.casic.service.DeviceDataService; +import com.casic.util.DeviceDataFieldTableEnum; +import com.casic.util.DeviceDataTableEnum; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Service +@Slf4j +public class DeviceDataServiceImpl implements DeviceDataService { + + private final DeviceDataMapper deviceDataMapper; + + public DeviceDataServiceImpl(DeviceDataMapper deviceDataMapper) { + this.deviceDataMapper = deviceDataMapper; + } + + public Object getDeviceRecentData(String deviceType, String recentNum, String devcode) { + ResponseData responseData = new ResponseData(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); + try { + String tableName = deviceDataTableEnum.getTableName(); + String fields = DeviceDataFieldTableEnum.TABLE_FIELD.getTableFieldMap().get(tableName); + List> recentDataList = deviceDataMapper.getDeviceRecentData(tableName, recentNum, fields, devcode); + responseData.setData(recentDataList); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备最近数据查询异常,设备类型{},查询数目{},异常信息{}", deviceType, recentNum, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + public Object getDeviceListPage(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { + ResponseData responseData = new ResponseData(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); + try { + String tableName = deviceDataTableEnum.getTableName(); + String fields = DeviceDataFieldTableEnum.TABLE_FIELD.getTableFieldMap().get(tableName); + Map page = new HashMap(); + page.put("total", deviceDataMapper.getDeviceDataTotal(tableName, devcode)); + List> recentDataList = deviceDataMapper.getDeviceDataListPage(tableName, pageSize * (currentIndex - 1), fields, pageSize, devcode); + page.put("rows", recentDataList); + responseData.setData(page); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},当前页{},页大小{},异常信息{}", deviceType, currentIndex, pageSize, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + public Object getLevel(String deviceType) { + ResponseData responseData = new ResponseData(); + try { + String highValue = deviceDataMapper.getLevelByType(deviceType); + responseData.setData(highValue); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},当前页{},页大小{},异常信息{}"); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + +} diff --git a/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java new file mode 100644 index 0000000..6b23451 --- /dev/null +++ b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java @@ -0,0 +1,92 @@ +package com.casic.service.impl; + +import com.alibaba.druid.util.StringUtils; +import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.dao.DataPressureMapper; +import com.casic.model.DataPressure; +import com.casic.model.PressureDataParam; +import com.casic.model.ResponseData; +import com.casic.service.ThirdDataService; +import com.casic.util.CacheUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.stream.Collectors; + +@Service +@Slf4j +public class ThirdDataServiceImpl extends ServiceImpl implements ThirdDataService { + + private final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA); + + public Object getDeviceRecentData(PressureDataParam pressureDataParam) { + ResponseData responseData = new ResponseData(); + try { + batchSave(pressureDataParam); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备最近数据查询异常,设备类型{},异常信息{}", dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + private void batchSave(PressureDataParam pressureDataParam) { + String pressureDataJson = pressureDataParam.getRawData(); + log.info("----" + pressureDataJson); + Map pressureDataMap = JSON.parseObject(pressureDataJson, HashMap.class); + Date uptime = null; + try { + uptime = dateFormat.parse(String.valueOf(pressureDataMap.get("times"))); + } catch (Exception e) { + log.error("主题,采集时间解析异常,异常信息{}", e.getMessage()); + } + List> pressureDataList = (List>) pressureDataMap.get("sensorDatas"); + DataPressure dataPressure = initPrssureData(pressureDataList, uptime); + if (dataPressure == null) { + return; + } + checkAlarm(dataPressure); + } + + private DataPressure initPrssureData(List> pressureDataList, Date uptime) { + DataPressure dataPressure = new DataPressure(); + String devcode = pressureDataList.get(pressureDataList.size() - 1).get("str"); + Map pressureDataMap = pressureDataList.stream().collect( + Collectors.toMap(e -> String.valueOf(e.get("flag")), e -> String.valueOf(e.get("value"))) + ); +// if (CacheUtil.serialBuf.get(devcode)!=null&&CacheUtil.serialBuf.get(devcode).equals(pressureDataMap.get("F"))) { +// return null; +// } + String wellCode = this.baseMapper.getWellCode(devcode); + dataPressure.setWellCode(wellCode); + dataPressure.setDevcode(devcode); + dataPressure.setPci(pressureDataMap.get("Q")); + dataPressure.setCell(Float.valueOf(pressureDataMap.get("V"))); + dataPressure.setTemperature(pressureDataMap.get("T")); + dataPressure.setPress(pressureDataMap.get("F")); + dataPressure.setUptime(dateFormat.format(uptime)); + dataPressure.setLogtime(dateFormat.format(new Date())); + this.baseMapper.insert(dataPressure); +// CacheUtil.serialBuf.put(devcode, pressureDataMap.get("F")); + return dataPressure; + } + + private void checkAlarm(DataPressure dataPressure) { + final Float ruleValue = this.baseMapper.getRuleValue("24"); + if (ruleValue == null) return; + if (!StringUtils.isEmpty(dataPressure.getTemperature()) && !dataPressure.getTemperature().equals("null")) { + if (Float.valueOf(dataPressure.getTemperature()) > ruleValue) { + this.baseMapper.saveRecords(dataPressure.getTemperature(), new Date()); + } + } + } + +} diff --git a/src/main/java/com/casic/util/CacheUtil.java b/src/main/java/com/casic/util/CacheUtil.java new file mode 100644 index 0000000..5b89300 --- /dev/null +++ b/src/main/java/com/casic/util/CacheUtil.java @@ -0,0 +1,16 @@ +package com.casic.util; + +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import java.util.HashMap; +import java.util.Map; + +@Component +public class CacheUtil { + public static volatile Map serialBuf; + @PostConstruct + public void init() { + serialBuf = new HashMap<>(); + } +} diff --git a/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java b/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java new file mode 100644 index 0000000..085c7c3 --- /dev/null +++ b/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java @@ -0,0 +1,39 @@ +package com.casic.util; + +import java.util.HashMap; +import java.util.Map; + +public enum DeviceDataFieldTableEnum { + + TABLE_FIELD(new HashMap() { + { + put("data_dig", "ddata AS dataValue,devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gas", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gasliquid_gas", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gasliquid_liquid", "liquiddata AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gas_dector", "gas_sample_value AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_harmful_gas", "CONCAT(CO, ', ', CH4, ', ', H2S, ', ', O2) AS dataValue,devcode AS devcode,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_hydrant", "0 AS dataValue,devcode AS devcode,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_liquid", "liquiddata AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_noise", "ddata AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_temp_hum", "CONCAT(TEMPERATURE, ', ', HUMIDITY) AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_tube", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_wellcover", "descn AS dataValue,devcode AS devcode,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_temp_press", "press AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_pantilt", "concentration AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_wellcover_loca", "0 AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_wellplus", "0 AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_h2s", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_pressure", "re_val AS dataValue,devcode AS devcode,'' AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + } + }); + public Map tableNameMap; + + DeviceDataFieldTableEnum(Map tableNameMap) { + this.tableNameMap = tableNameMap; + } + + public Map getTableFieldMap() { + return tableNameMap; + } +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..50f4a19 --- /dev/null +++ b/pom.xml @@ -0,0 +1,161 @@ + + + 4.0.0 + + com.casic + smartwell-demos + 1.0-SNAPSHOT + + + + + jdk-1.8 + + true + 1.8 + + + 1.8 + 1.8 + 1.8 + + + + + + + + + + org.springframework.boot + spring-boot-starter + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-tomcat + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-web + 2.4.5 + + + + + org.springframework.boot + spring-boot-starter-jdbc + 2.4.5 + + + + mysql + mysql-connector-java + 8.0.16 + compile + + + + com.baomidou + mybatis-plus-boot-starter + 3.4.3 + + + + org.projectlombok + lombok + 1.18.20 + + + + + com.alibaba + druid + 1.2.6 + + + + com.alibaba + fastjson + 1.2.73 + + + + commons-codec + commons-codec + 1.14 + + + + redis.clients + jedis + 3.1.0 + jar + + + + org.springframework.data + spring-data-redis + 2.4.8 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.3.RELEASE + + true + + com.casic.CasicApplication + exec + + + + + repackage + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + false + + + + + + + + src/main/resources + + + /config/*/* + /config/*-*.yml + + true + + + src/main/resources + + **/*.xml + + true + + + + + \ No newline at end of file diff --git a/src/main/java/com/casic/CasicApplication.java b/src/main/java/com/casic/CasicApplication.java new file mode 100644 index 0000000..9afd0b9 --- /dev/null +++ b/src/main/java/com/casic/CasicApplication.java @@ -0,0 +1,28 @@ +package com.casic; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.transaction.annotation.EnableTransactionManagement; + + +/** + * SpringBoot方式启动类 + * + * @author cz + * @Date 2022/09/08 14:28 + */ + +@Slf4j +@ComponentScan(basePackages= "com.casic.**") +@SpringBootApplication +public class CasicApplication { + public static void main(String[] args) { + log.info("CasicApplication is success!"); + SpringApplication.run(CasicApplication.class, args); + } +} diff --git a/src/main/java/com/casic/config/CorsConfig.java b/src/main/java/com/casic/config/CorsConfig.java new file mode 100644 index 0000000..7d19680 --- /dev/null +++ b/src/main/java/com/casic/config/CorsConfig.java @@ -0,0 +1,31 @@ +package com.casic.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +/** + * 基础框架 - 跨域请求配置 + */ +@Configuration +public class CorsConfig { + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", buildConfig()); + return new CorsFilter(source); + } + + private CorsConfiguration buildConfig() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + // 1允许任何域名使用 + corsConfiguration.addAllowedOrigin("*"); + // 2允许任何头 + corsConfiguration.addAllowedHeader("*"); + // 3允许任何方法(post、get等) + corsConfiguration.addAllowedMethod("*"); + return corsConfiguration; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/controller/AlarmController.java b/src/main/java/com/casic/controller/AlarmController.java new file mode 100644 index 0000000..957fc36 --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.model.AlarmConfigParam; +import com.casic.service.AlarmService; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/alarm") +public class AlarmController { + + private final AlarmService alarmService; + + public AlarmController(AlarmService alarmService) { + this.alarmService = alarmService; + } + + @RequestMapping("/records") + public Object getAlarmRecord(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "devcode",required =false) String devcode, + @RequestParam(value = "pageSize", required = true) Integer pageSize) { + return alarmService.getAlarmRecord(deviceType,currentIndex,pageSize,devcode); + } + + @RequestMapping("/batch/cancel") + public Object excuteAlramBatchCancel(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "devcode",required =false) String devcode) { + return alarmService.excuteAlramBatchCancel(deviceType,devcode); + } + + @RequestMapping("/config/add") + public Object addAlarmConfig(@RequestBody AlarmConfigParam alarmConfigParam) { + return alarmService.addAlarmConfig(alarmConfigParam); + } +} diff --git a/src/main/java/com/casic/controller/DeviceDataController.java b/src/main/java/com/casic/controller/DeviceDataController.java new file mode 100644 index 0000000..3498b04 --- /dev/null +++ b/src/main/java/com/casic/controller/DeviceDataController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.service.DeviceDataService; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/device") +public class DeviceDataController { + private final DeviceDataService deviceDataService; + + public DeviceDataController(DeviceDataService deviceDataService) { + this.deviceDataService = deviceDataService; + } + + @RequestMapping("/recent-data") + public Object getDeviceRecentData(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "recentNum", required = true) String recentNum, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceRecentData(deviceType, recentNum, devcode); + } + + @RequestMapping("/data/list-page") + public Object getDeviceListPage(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "pageSize", required = true) Integer pageSize, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceListPage(deviceType, currentIndex, pageSize, devcode); + } + + @RequestMapping("/level/{deviceType}") + public Object getLevelList(@PathVariable("deviceType")String deviceType) { + return deviceDataService.getLevel(deviceType); + } + +} diff --git a/src/main/java/com/casic/controller/ThirdDataController.java b/src/main/java/com/casic/controller/ThirdDataController.java new file mode 100644 index 0000000..b9b2b42 --- /dev/null +++ b/src/main/java/com/casic/controller/ThirdDataController.java @@ -0,0 +1,28 @@ +package com.casic.controller; + +import com.casic.model.PressureDataParam; +import com.casic.service.ThirdDataService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +@RestController +@RequestMapping("/push") +@Slf4j +public class ThirdDataController { + + private final ThirdDataService thirdDataService; + + public ThirdDataController(ThirdDataService thirdDataService) { + this.thirdDataService = thirdDataService; + } + + @RequestMapping("/pressure/data") + public Object getDeviceRecentData(@RequestBody PressureDataParam pressureData) { + return thirdDataService.getDeviceRecentData(pressureData); + } + +} diff --git a/src/main/java/com/casic/dao/AlarmMapper.java b/src/main/java/com/casic/dao/AlarmMapper.java new file mode 100644 index 0000000..a442e3a --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmMapper.java @@ -0,0 +1,28 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmLevel; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + +@Mapper +public interface AlarmMapper extends BaseMapper { + + List> getAlarmRecord(@Param("deviceType") String deviceType, + @Param("devcode") String devcode, + @Param("currentIndex") Integer currentIndex, @Param("pageSize") Integer pageSize); + + Integer getAlarmTotalRecord(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteAlramBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteJobBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + String getDeviceDevcode(@Param("deviceType") String deviceType); + + String getDeviceByDevcode(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + +} diff --git a/src/main/java/com/casic/dao/BusConfigMapper.java b/src/main/java/com/casic/dao/BusConfigMapper.java new file mode 100644 index 0000000..ccf76da --- /dev/null +++ b/src/main/java/com/casic/dao/BusConfigMapper.java @@ -0,0 +1,9 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.BusConfig; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface BusConfigMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/dao/DataPressureMapper.java b/src/main/java/com/casic/dao/DataPressureMapper.java new file mode 100644 index 0000000..05f4329 --- /dev/null +++ b/src/main/java/com/casic/dao/DataPressureMapper.java @@ -0,0 +1,19 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.DataPressure; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.Date; + +@Mapper +public interface DataPressureMapper extends BaseMapper { + + String getWellCode(@Param("devcode") String devcode); + + Float getRuleValue(@Param("deviceType") String deviceType); + + void saveRecords(@Param("reValue") String reValue, @Param("alarmTime") Date alarmTime); + +} diff --git a/src/main/java/com/casic/dao/DeviceDataMapper.java b/src/main/java/com/casic/dao/DeviceDataMapper.java new file mode 100644 index 0000000..d9e18a0 --- /dev/null +++ b/src/main/java/com/casic/dao/DeviceDataMapper.java @@ -0,0 +1,27 @@ +package com.casic.dao; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + + +@Mapper +public interface DeviceDataMapper { + + List> getDeviceRecentData(@Param("tableName") String tableName, + @Param("recentNum") String recentNum, + @Param("fields") String fields, + @Param("devcode") String devcode); + + Integer getDeviceDataTotal(@Param("tableName") String tableName, @Param("devcode") String devcode); + + List> getDeviceDataListPage(@Param("tableName") String tableName, + @Param("currentIndex") Integer currentIndex, + @Param("fields") String fields, + @Param("pageSize") Integer pageSize, + @Param("devcode") String devcode); + + String getLevelByType(@Param("deviceType")String deviceType); +} diff --git a/src/main/java/com/casic/model/AlarmConfigParam.java b/src/main/java/com/casic/model/AlarmConfigParam.java new file mode 100644 index 0000000..28150d6 --- /dev/null +++ b/src/main/java/com/casic/model/AlarmConfigParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class AlarmConfigParam { + private String deviceType; + private String thresholdVol; + private String collectInterval; + private String uploadCycle; + private String retryNum; + private String ip; + private String port; + private String devcode; +} diff --git a/src/main/java/com/casic/model/AlarmLevel.java b/src/main/java/com/casic/model/AlarmLevel.java new file mode 100644 index 0000000..d0909af --- /dev/null +++ b/src/main/java/com/casic/model/AlarmLevel.java @@ -0,0 +1,26 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("alarm_level") +public class AlarmLevel{ + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + private String name; + private String deviceType; + private Integer level; + private Float lowValue; + private Float highValue; + private String openAlarm; + private String openJob; + private Date ts; + private String tenantId; + +} diff --git a/src/main/java/com/casic/model/BusConfig.java b/src/main/java/com/casic/model/BusConfig.java new file mode 100644 index 0000000..c6b7b50 --- /dev/null +++ b/src/main/java/com/casic/model/BusConfig.java @@ -0,0 +1,27 @@ +package com.casic.model; + + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +import java.util.Date; + +@Data +public class BusConfig { + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + + private String deviceId; + private String framecontent; + private String sensorid; + private String sensorcode; + + private String status; + private Integer attemptsmax; + private Integer attemptscurrent; + private Date sendtime; + private Date writetime; + +} diff --git a/src/main/java/com/casic/model/CommConfigDTO.java b/src/main/java/com/casic/model/CommConfigDTO.java new file mode 100644 index 0000000..7da699c --- /dev/null +++ b/src/main/java/com/casic/model/CommConfigDTO.java @@ -0,0 +1,41 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class CommConfigDTO { + private String acqStart;//采集开始时间 + private Long interval;//采集时间间隔(分钟) + private Long period;//上传周期 + private Long times;//采集次数 + private Long repeat;//重传次数 + private String ip; + private Long port; + private Float thresh; + private Float height; + private String collect; + private String MultiCollect; + private String acqCycle; + private String upCycle; + private String sleepStartTime; + + private String acqStartFlow ; //流量采集开始时间 + private Long intervalFlow; //流量采集采集间隔(分) + private Long acqTimesFlow ;//流量采集次数 + private String upStartFlow; //流量上报开始时间 + private Long upTimesFlow; //流量上传次数 + private String acqStartNoise; //噪声采集开始时间 + private Long intervalNoise; //噪声采集采集间隔(分) + private Long acqTimesNoise;//噪声采集次数 + private String upStartNoise; //噪声上报开始时间 + private Long upTimesNoise ;//噪声上传次数 + private String acqStartPressure; //压力采集开始时间 + private Long intervalPressure;//压力采集采集间隔(分) + private Long acqTimesPressure; //压力采集次数 + private String upStartPressure; //压力上报开始时间 + private Long upTimesPressure; //压力上传次数 + private Float lowerLimitPressure; //压力报警下限 + private Float upperLimitPressure ;//压力报警下限 + private Long limitDig ;//开挖阈值 + private Float threshold ;//开挖阈值 +} diff --git a/src/main/java/com/casic/model/DataPressure.java b/src/main/java/com/casic/model/DataPressure.java new file mode 100644 index 0000000..8270c70 --- /dev/null +++ b/src/main/java/com/casic/model/DataPressure.java @@ -0,0 +1,33 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("data_temp_press") +public class DataPressure { + + @TableId(value = "ID", type = IdType.AUTO) + private String id; + private String wellCode; + private String devcode; + private Float cell; + private String temperature; + + private String press; + private String descn; + private String uptime; + private String logtime; + /** + * 信号强度 + */ + private String pci; + + private String rsrp; + private String snr; + +} diff --git a/src/main/java/com/casic/model/PressureDataParam.java b/src/main/java/com/casic/model/PressureDataParam.java new file mode 100644 index 0000000..f42770d --- /dev/null +++ b/src/main/java/com/casic/model/PressureDataParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class PressureDataParam { + private String flag; + private String deviceUserid; + private String parentUserId; + private Object sensorsDates; + private String time; + private String rawData; + private String deviceId; +} + diff --git a/src/main/java/com/casic/model/ResponseData.java b/src/main/java/com/casic/model/ResponseData.java new file mode 100644 index 0000000..245ab04 --- /dev/null +++ b/src/main/java/com/casic/model/ResponseData.java @@ -0,0 +1,18 @@ +package com.casic.model; + +import lombok.Data; + +/** + * @author cz + * @date 2022-8-12 + */ +@Data +public class ResponseData { + public static final String DEFAULT_SUCCESS_MESSAGE = "请求成功"; + public static final String DEFAULT_ERROR_MESSAGE = "网络异常"; + public static final Integer DEFAULT_SUCCESS_CODE = 200; + public static final Integer DEFAULT_ERROR_CODE = 500; + private Integer code; + private String message; + private Object data; +} \ No newline at end of file diff --git a/src/main/java/com/casic/service/AlarmService.java b/src/main/java/com/casic/service/AlarmService.java new file mode 100644 index 0000000..8516b41 --- /dev/null +++ b/src/main/java/com/casic/service/AlarmService.java @@ -0,0 +1,12 @@ +package com.casic.service; + +import com.casic.model.AlarmConfigParam; + +public interface AlarmService { + + Object getAlarmRecord(String deviceType,Integer currentIndex,Integer pageSize,String devcode); + + Object excuteAlramBatchCancel(String deviceType,String devcode); + + Object addAlarmConfig(AlarmConfigParam alarmConfig); +} diff --git a/src/main/java/com/casic/service/DeviceDataService.java b/src/main/java/com/casic/service/DeviceDataService.java new file mode 100644 index 0000000..db656c1 --- /dev/null +++ b/src/main/java/com/casic/service/DeviceDataService.java @@ -0,0 +1,10 @@ +package com.casic.service; + +public interface DeviceDataService { + + Object getDeviceRecentData(String deviceType, String recentNum, String devcode); + + Object getDeviceListPage(String deviceType, Integer currentIndex, Integer pageSize, String devcode); + + Object getLevel(String deviceType); +} diff --git a/src/main/java/com/casic/service/ThirdDataService.java b/src/main/java/com/casic/service/ThirdDataService.java new file mode 100644 index 0000000..795e0b2 --- /dev/null +++ b/src/main/java/com/casic/service/ThirdDataService.java @@ -0,0 +1,8 @@ +package com.casic.service; + +import com.casic.model.PressureDataParam; + +public interface ThirdDataService { + + Object getDeviceRecentData(PressureDataParam pressureData); +} diff --git a/src/main/java/com/casic/service/impl/AlarmServiceImple.java b/src/main/java/com/casic/service/impl/AlarmServiceImple.java new file mode 100644 index 0000000..a675207 --- /dev/null +++ b/src/main/java/com/casic/service/impl/AlarmServiceImple.java @@ -0,0 +1,127 @@ +package com.casic.service.impl; + +import com.alibaba.druid.util.StringUtils; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.dao.AlarmMapper; +import com.casic.dao.BusConfigMapper; +import com.casic.model.*; +import com.casic.service.AlarmService; +import com.casic.util.DeviceDataTableEnum; +import com.casic.util.RedisCommonUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Slf4j +@Service +public class AlarmServiceImple extends ServiceImpl implements AlarmService { + + @Resource + private BusConfigMapper busConfigMapper; + @Resource + private RedisCommonUtil redisCommonUtil; + + public Object getAlarmRecord(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { + ResponseData responseData = new ResponseData(); + try { + Map page = new HashMap(); + page.put("total", this.baseMapper.getAlarmTotalRecord(deviceType, devcode)); + List> alarmRecordList = this.baseMapper.getAlarmRecord(deviceType, devcode, pageSize * (currentIndex - 1), pageSize); + page.put("rows", alarmRecordList); + responseData.setData(alarmRecordList); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},异常信息{}", deviceType, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + @Transactional + public Object excuteAlramBatchCancel(String deviceType, String devcode) { + ResponseData responseData = new ResponseData(); + try { + this.baseMapper.excuteAlramBatchCancel(deviceType, devcode); + this.baseMapper.excuteJobBatchCancel(deviceType, devcode); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("批量消警异常,设备类型{},异常信息{}", deviceType, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + + @Transactional + public Object addAlarmConfig(AlarmConfigParam alarmConfigParam) { + ResponseData responseData = new ResponseData(); + try { + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + addBusConfig(alarmConfigParam); + addRuleConfig(alarmConfigParam); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("风险配置异常,异常信息{}", dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + private void addRuleConfig(AlarmConfigParam alarmConfigParam) { + Map alarmRuleMap = new HashMap(); + alarmRuleMap.put("DEVICE_TYPE", alarmConfigParam.getDeviceType()); + this.baseMapper.deleteByMap(alarmRuleMap); + AlarmLevel alarmRule = new AlarmLevel(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap() + .get(Integer.valueOf(alarmConfigParam.getDeviceType())); + alarmRule.setName(deviceDataTableEnum.getTypeName()); + alarmRule.setHighValue(Float.valueOf(alarmConfigParam.getThresholdVol())); + alarmRule.setTs(new Date()); + alarmRule.setLevel(1); + alarmRule.setDeviceType(alarmConfigParam.getDeviceType()); + this.baseMapper.insert(alarmRule); + } + + private void addBusConfig(AlarmConfigParam alarmConfigParam) { + String devcode = StringUtils.isEmpty(alarmConfigParam.getDevcode()) ? this.baseMapper.getDeviceDevcode(alarmConfigParam.getDeviceType()) : alarmConfigParam.getDevcode(); + sendBusConfig(alarmConfigParam, devcode); + String devcideId = this.baseMapper.getDeviceByDevcode(alarmConfigParam.getDeviceType(), devcode); + BusConfig busConfig = new BusConfig(); + busConfig.setDeviceId(devcideId); + busConfig.setFramecontent("3," + alarmConfigParam.getCollectInterval() + "," + alarmConfigParam.getCollectInterval() + + "," + alarmConfigParam.getRetryNum() + "," + alarmConfigParam.getIp() + "," + alarmConfigParam.getPort()); + busConfig.setSensorid(""); + busConfig.setStatus("0"); + busConfig.setAttemptscurrent(0); + busConfig.setWritetime(new Date()); + busConfig.setAttemptsmax(3); + busConfigMapper.insert(busConfig); + } + + private void sendBusConfig(AlarmConfigParam alarmConfigParam, String devcode) { + CommConfigDTO commConfigDTO = new CommConfigDTO(); + commConfigDTO.setInterval(StringUtils.isEmpty(alarmConfigParam.getCollectInterval()) ? 300 : Long.valueOf(alarmConfigParam.getCollectInterval())); + commConfigDTO.setRepeat(StringUtils.isEmpty(alarmConfigParam.getRetryNum()) ? 300 : Long.valueOf(alarmConfigParam.getRetryNum())); + commConfigDTO.setTimes(Long.valueOf(1)); +// commConfigDTO.setIp(alarmConfigParam.getIp()); +// commConfigDTO.setPort(StringUtils.isEmpty(alarmConfigParam.getPort()) ? 8080 : Long.valueOf(alarmConfigParam.getPort())); + commConfigDTO.setPeriod(StringUtils.isEmpty(alarmConfigParam.getUploadCycle()) ? 300 : Long.valueOf(alarmConfigParam.getUploadCycle())); +// commConfigDTO.setThresh(); + commConfigDTO.setThresh(StringUtils.isEmpty(alarmConfigParam.getThresholdVol()) ? 50: Float.valueOf(alarmConfigParam.getThresholdVol())); + redisCommonUtil.send(commConfigDTO, devcode); + } + + +} diff --git a/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java new file mode 100644 index 0000000..3de704b --- /dev/null +++ b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java @@ -0,0 +1,80 @@ +package com.casic.service.impl; + +import com.casic.dao.DeviceDataMapper; +import com.casic.model.ResponseData; +import com.casic.service.DeviceDataService; +import com.casic.util.DeviceDataFieldTableEnum; +import com.casic.util.DeviceDataTableEnum; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Service +@Slf4j +public class DeviceDataServiceImpl implements DeviceDataService { + + private final DeviceDataMapper deviceDataMapper; + + public DeviceDataServiceImpl(DeviceDataMapper deviceDataMapper) { + this.deviceDataMapper = deviceDataMapper; + } + + public Object getDeviceRecentData(String deviceType, String recentNum, String devcode) { + ResponseData responseData = new ResponseData(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); + try { + String tableName = deviceDataTableEnum.getTableName(); + String fields = DeviceDataFieldTableEnum.TABLE_FIELD.getTableFieldMap().get(tableName); + List> recentDataList = deviceDataMapper.getDeviceRecentData(tableName, recentNum, fields, devcode); + responseData.setData(recentDataList); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备最近数据查询异常,设备类型{},查询数目{},异常信息{}", deviceType, recentNum, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + public Object getDeviceListPage(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { + ResponseData responseData = new ResponseData(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); + try { + String tableName = deviceDataTableEnum.getTableName(); + String fields = DeviceDataFieldTableEnum.TABLE_FIELD.getTableFieldMap().get(tableName); + Map page = new HashMap(); + page.put("total", deviceDataMapper.getDeviceDataTotal(tableName, devcode)); + List> recentDataList = deviceDataMapper.getDeviceDataListPage(tableName, pageSize * (currentIndex - 1), fields, pageSize, devcode); + page.put("rows", recentDataList); + responseData.setData(page); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},当前页{},页大小{},异常信息{}", deviceType, currentIndex, pageSize, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + public Object getLevel(String deviceType) { + ResponseData responseData = new ResponseData(); + try { + String highValue = deviceDataMapper.getLevelByType(deviceType); + responseData.setData(highValue); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},当前页{},页大小{},异常信息{}"); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + +} diff --git a/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java new file mode 100644 index 0000000..6b23451 --- /dev/null +++ b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java @@ -0,0 +1,92 @@ +package com.casic.service.impl; + +import com.alibaba.druid.util.StringUtils; +import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.dao.DataPressureMapper; +import com.casic.model.DataPressure; +import com.casic.model.PressureDataParam; +import com.casic.model.ResponseData; +import com.casic.service.ThirdDataService; +import com.casic.util.CacheUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.stream.Collectors; + +@Service +@Slf4j +public class ThirdDataServiceImpl extends ServiceImpl implements ThirdDataService { + + private final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA); + + public Object getDeviceRecentData(PressureDataParam pressureDataParam) { + ResponseData responseData = new ResponseData(); + try { + batchSave(pressureDataParam); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备最近数据查询异常,设备类型{},异常信息{}", dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + private void batchSave(PressureDataParam pressureDataParam) { + String pressureDataJson = pressureDataParam.getRawData(); + log.info("----" + pressureDataJson); + Map pressureDataMap = JSON.parseObject(pressureDataJson, HashMap.class); + Date uptime = null; + try { + uptime = dateFormat.parse(String.valueOf(pressureDataMap.get("times"))); + } catch (Exception e) { + log.error("主题,采集时间解析异常,异常信息{}", e.getMessage()); + } + List> pressureDataList = (List>) pressureDataMap.get("sensorDatas"); + DataPressure dataPressure = initPrssureData(pressureDataList, uptime); + if (dataPressure == null) { + return; + } + checkAlarm(dataPressure); + } + + private DataPressure initPrssureData(List> pressureDataList, Date uptime) { + DataPressure dataPressure = new DataPressure(); + String devcode = pressureDataList.get(pressureDataList.size() - 1).get("str"); + Map pressureDataMap = pressureDataList.stream().collect( + Collectors.toMap(e -> String.valueOf(e.get("flag")), e -> String.valueOf(e.get("value"))) + ); +// if (CacheUtil.serialBuf.get(devcode)!=null&&CacheUtil.serialBuf.get(devcode).equals(pressureDataMap.get("F"))) { +// return null; +// } + String wellCode = this.baseMapper.getWellCode(devcode); + dataPressure.setWellCode(wellCode); + dataPressure.setDevcode(devcode); + dataPressure.setPci(pressureDataMap.get("Q")); + dataPressure.setCell(Float.valueOf(pressureDataMap.get("V"))); + dataPressure.setTemperature(pressureDataMap.get("T")); + dataPressure.setPress(pressureDataMap.get("F")); + dataPressure.setUptime(dateFormat.format(uptime)); + dataPressure.setLogtime(dateFormat.format(new Date())); + this.baseMapper.insert(dataPressure); +// CacheUtil.serialBuf.put(devcode, pressureDataMap.get("F")); + return dataPressure; + } + + private void checkAlarm(DataPressure dataPressure) { + final Float ruleValue = this.baseMapper.getRuleValue("24"); + if (ruleValue == null) return; + if (!StringUtils.isEmpty(dataPressure.getTemperature()) && !dataPressure.getTemperature().equals("null")) { + if (Float.valueOf(dataPressure.getTemperature()) > ruleValue) { + this.baseMapper.saveRecords(dataPressure.getTemperature(), new Date()); + } + } + } + +} diff --git a/src/main/java/com/casic/util/CacheUtil.java b/src/main/java/com/casic/util/CacheUtil.java new file mode 100644 index 0000000..5b89300 --- /dev/null +++ b/src/main/java/com/casic/util/CacheUtil.java @@ -0,0 +1,16 @@ +package com.casic.util; + +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import java.util.HashMap; +import java.util.Map; + +@Component +public class CacheUtil { + public static volatile Map serialBuf; + @PostConstruct + public void init() { + serialBuf = new HashMap<>(); + } +} diff --git a/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java b/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java new file mode 100644 index 0000000..085c7c3 --- /dev/null +++ b/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java @@ -0,0 +1,39 @@ +package com.casic.util; + +import java.util.HashMap; +import java.util.Map; + +public enum DeviceDataFieldTableEnum { + + TABLE_FIELD(new HashMap() { + { + put("data_dig", "ddata AS dataValue,devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gas", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gasliquid_gas", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gasliquid_liquid", "liquiddata AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gas_dector", "gas_sample_value AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_harmful_gas", "CONCAT(CO, ', ', CH4, ', ', H2S, ', ', O2) AS dataValue,devcode AS devcode,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_hydrant", "0 AS dataValue,devcode AS devcode,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_liquid", "liquiddata AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_noise", "ddata AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_temp_hum", "CONCAT(TEMPERATURE, ', ', HUMIDITY) AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_tube", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_wellcover", "descn AS dataValue,devcode AS devcode,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_temp_press", "press AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_pantilt", "concentration AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_wellcover_loca", "0 AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_wellplus", "0 AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_h2s", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_pressure", "re_val AS dataValue,devcode AS devcode,'' AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + } + }); + public Map tableNameMap; + + DeviceDataFieldTableEnum(Map tableNameMap) { + this.tableNameMap = tableNameMap; + } + + public Map getTableFieldMap() { + return tableNameMap; + } +} diff --git a/src/main/java/com/casic/util/DeviceDataTableEnum.java b/src/main/java/com/casic/util/DeviceDataTableEnum.java new file mode 100644 index 0000000..9698487 --- /dev/null +++ b/src/main/java/com/casic/util/DeviceDataTableEnum.java @@ -0,0 +1,81 @@ +package com.casic.util; + +import java.util.HashMap; + +/** + * @author cz + * @date 2022-7-15 + * 上传数据总记录数 + */ +public enum DeviceDataTableEnum { + + DATA_DIG("data_dig", "开挖监测仪"), + DATA_GAS("data_gas", "燃气智能监测终端"), + DATA_GASLIQUID("data_gasliquid_gas,data_gasliquid_liquid", "燃气智能监测终端(一体化)"), + DATA_GAS_DECTOR("data_gas_dector", "燃气探测仪"), + DATA_HARMFUL_GAS("data_harmful_gas", "有害气体监测仪"), + DATA_HYDRANT("data_hydrant", "消防栓防盗水监测仪"), + DATA_LIQUID("data_liquid", "液位监测仪"), + DATA_NOISE("data_noise", "噪声记录仪"), + DATA_PANTILT("data_pantilt", "激光甲烷云台"), + DATA_TEMP_HUM("data_temp_hum", "温湿度监测仪"), + DATA_TUBE("data_tube", "管盯"), + DATA_WELLCOVER("data_wellcover", "井盖状态监测仪"), + DATA_TEMP_PRESS("data_temp_press", "压力温度检测仪"), + DATA_WELLCOVER_LOCA("data_wellcover_loca", "井盖定位监测仪"), + DATA_WELLPLUS("data_wellplus", "井盖液位一体机"), + DATA_H2S("data_h2s", "硫化氢检测终端"), + DATA_PRESSURE("data_pressure", "压力检测终端"), + DEVICE_TYPE_TABLE(new HashMap() { + { + put(1, DATA_WELLCOVER); + put(2, DATA_LIQUID); + put(3, DATA_HARMFUL_GAS); + put(4, DATA_GAS); + put(5, DATA_TEMP_HUM); + put(6, DATA_DIG); + put(7, DATA_WELLCOVER_LOCA); + put(8, DATA_NOISE); + put(9, DATA_TEMP_PRESS); + put(10, DATA_GASLIQUID); + put(11, DATA_HYDRANT); + put(12, DATA_TUBE); + put(13, DATA_WELLPLUS); + put(14, DATA_H2S); + put(21, DATA_PANTILT); + put(22, DATA_H2S); + put(23, DATA_GAS); + put(24, DATA_TEMP_PRESS); + put(101, DATA_GAS_DECTOR); + } + }); + + String typeName; + String tableName; + + DeviceDataTableEnum(String tableName, String typeName) { + this.typeName = typeName; + this.tableName = tableName; + } + + public String getTypeName() { + return typeName; + } + + public String getTableName() { + return tableName; + } + + + public HashMap tableNameMap; + + DeviceDataTableEnum(HashMap tableNameMap) { + this.tableNameMap = tableNameMap; + } + + public HashMap getTableNameMap() { + return tableNameMap; + } + + +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..50f4a19 --- /dev/null +++ b/pom.xml @@ -0,0 +1,161 @@ + + + 4.0.0 + + com.casic + smartwell-demos + 1.0-SNAPSHOT + + + + + jdk-1.8 + + true + 1.8 + + + 1.8 + 1.8 + 1.8 + + + + + + + + + + org.springframework.boot + spring-boot-starter + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-tomcat + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-web + 2.4.5 + + + + + org.springframework.boot + spring-boot-starter-jdbc + 2.4.5 + + + + mysql + mysql-connector-java + 8.0.16 + compile + + + + com.baomidou + mybatis-plus-boot-starter + 3.4.3 + + + + org.projectlombok + lombok + 1.18.20 + + + + + com.alibaba + druid + 1.2.6 + + + + com.alibaba + fastjson + 1.2.73 + + + + commons-codec + commons-codec + 1.14 + + + + redis.clients + jedis + 3.1.0 + jar + + + + org.springframework.data + spring-data-redis + 2.4.8 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.3.RELEASE + + true + + com.casic.CasicApplication + exec + + + + + repackage + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + false + + + + + + + + src/main/resources + + + /config/*/* + /config/*-*.yml + + true + + + src/main/resources + + **/*.xml + + true + + + + + \ No newline at end of file diff --git a/src/main/java/com/casic/CasicApplication.java b/src/main/java/com/casic/CasicApplication.java new file mode 100644 index 0000000..9afd0b9 --- /dev/null +++ b/src/main/java/com/casic/CasicApplication.java @@ -0,0 +1,28 @@ +package com.casic; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.transaction.annotation.EnableTransactionManagement; + + +/** + * SpringBoot方式启动类 + * + * @author cz + * @Date 2022/09/08 14:28 + */ + +@Slf4j +@ComponentScan(basePackages= "com.casic.**") +@SpringBootApplication +public class CasicApplication { + public static void main(String[] args) { + log.info("CasicApplication is success!"); + SpringApplication.run(CasicApplication.class, args); + } +} diff --git a/src/main/java/com/casic/config/CorsConfig.java b/src/main/java/com/casic/config/CorsConfig.java new file mode 100644 index 0000000..7d19680 --- /dev/null +++ b/src/main/java/com/casic/config/CorsConfig.java @@ -0,0 +1,31 @@ +package com.casic.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +/** + * 基础框架 - 跨域请求配置 + */ +@Configuration +public class CorsConfig { + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", buildConfig()); + return new CorsFilter(source); + } + + private CorsConfiguration buildConfig() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + // 1允许任何域名使用 + corsConfiguration.addAllowedOrigin("*"); + // 2允许任何头 + corsConfiguration.addAllowedHeader("*"); + // 3允许任何方法(post、get等) + corsConfiguration.addAllowedMethod("*"); + return corsConfiguration; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/controller/AlarmController.java b/src/main/java/com/casic/controller/AlarmController.java new file mode 100644 index 0000000..957fc36 --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.model.AlarmConfigParam; +import com.casic.service.AlarmService; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/alarm") +public class AlarmController { + + private final AlarmService alarmService; + + public AlarmController(AlarmService alarmService) { + this.alarmService = alarmService; + } + + @RequestMapping("/records") + public Object getAlarmRecord(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "devcode",required =false) String devcode, + @RequestParam(value = "pageSize", required = true) Integer pageSize) { + return alarmService.getAlarmRecord(deviceType,currentIndex,pageSize,devcode); + } + + @RequestMapping("/batch/cancel") + public Object excuteAlramBatchCancel(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "devcode",required =false) String devcode) { + return alarmService.excuteAlramBatchCancel(deviceType,devcode); + } + + @RequestMapping("/config/add") + public Object addAlarmConfig(@RequestBody AlarmConfigParam alarmConfigParam) { + return alarmService.addAlarmConfig(alarmConfigParam); + } +} diff --git a/src/main/java/com/casic/controller/DeviceDataController.java b/src/main/java/com/casic/controller/DeviceDataController.java new file mode 100644 index 0000000..3498b04 --- /dev/null +++ b/src/main/java/com/casic/controller/DeviceDataController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.service.DeviceDataService; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/device") +public class DeviceDataController { + private final DeviceDataService deviceDataService; + + public DeviceDataController(DeviceDataService deviceDataService) { + this.deviceDataService = deviceDataService; + } + + @RequestMapping("/recent-data") + public Object getDeviceRecentData(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "recentNum", required = true) String recentNum, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceRecentData(deviceType, recentNum, devcode); + } + + @RequestMapping("/data/list-page") + public Object getDeviceListPage(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "pageSize", required = true) Integer pageSize, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceListPage(deviceType, currentIndex, pageSize, devcode); + } + + @RequestMapping("/level/{deviceType}") + public Object getLevelList(@PathVariable("deviceType")String deviceType) { + return deviceDataService.getLevel(deviceType); + } + +} diff --git a/src/main/java/com/casic/controller/ThirdDataController.java b/src/main/java/com/casic/controller/ThirdDataController.java new file mode 100644 index 0000000..b9b2b42 --- /dev/null +++ b/src/main/java/com/casic/controller/ThirdDataController.java @@ -0,0 +1,28 @@ +package com.casic.controller; + +import com.casic.model.PressureDataParam; +import com.casic.service.ThirdDataService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +@RestController +@RequestMapping("/push") +@Slf4j +public class ThirdDataController { + + private final ThirdDataService thirdDataService; + + public ThirdDataController(ThirdDataService thirdDataService) { + this.thirdDataService = thirdDataService; + } + + @RequestMapping("/pressure/data") + public Object getDeviceRecentData(@RequestBody PressureDataParam pressureData) { + return thirdDataService.getDeviceRecentData(pressureData); + } + +} diff --git a/src/main/java/com/casic/dao/AlarmMapper.java b/src/main/java/com/casic/dao/AlarmMapper.java new file mode 100644 index 0000000..a442e3a --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmMapper.java @@ -0,0 +1,28 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmLevel; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + +@Mapper +public interface AlarmMapper extends BaseMapper { + + List> getAlarmRecord(@Param("deviceType") String deviceType, + @Param("devcode") String devcode, + @Param("currentIndex") Integer currentIndex, @Param("pageSize") Integer pageSize); + + Integer getAlarmTotalRecord(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteAlramBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteJobBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + String getDeviceDevcode(@Param("deviceType") String deviceType); + + String getDeviceByDevcode(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + +} diff --git a/src/main/java/com/casic/dao/BusConfigMapper.java b/src/main/java/com/casic/dao/BusConfigMapper.java new file mode 100644 index 0000000..ccf76da --- /dev/null +++ b/src/main/java/com/casic/dao/BusConfigMapper.java @@ -0,0 +1,9 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.BusConfig; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface BusConfigMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/dao/DataPressureMapper.java b/src/main/java/com/casic/dao/DataPressureMapper.java new file mode 100644 index 0000000..05f4329 --- /dev/null +++ b/src/main/java/com/casic/dao/DataPressureMapper.java @@ -0,0 +1,19 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.DataPressure; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.Date; + +@Mapper +public interface DataPressureMapper extends BaseMapper { + + String getWellCode(@Param("devcode") String devcode); + + Float getRuleValue(@Param("deviceType") String deviceType); + + void saveRecords(@Param("reValue") String reValue, @Param("alarmTime") Date alarmTime); + +} diff --git a/src/main/java/com/casic/dao/DeviceDataMapper.java b/src/main/java/com/casic/dao/DeviceDataMapper.java new file mode 100644 index 0000000..d9e18a0 --- /dev/null +++ b/src/main/java/com/casic/dao/DeviceDataMapper.java @@ -0,0 +1,27 @@ +package com.casic.dao; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + + +@Mapper +public interface DeviceDataMapper { + + List> getDeviceRecentData(@Param("tableName") String tableName, + @Param("recentNum") String recentNum, + @Param("fields") String fields, + @Param("devcode") String devcode); + + Integer getDeviceDataTotal(@Param("tableName") String tableName, @Param("devcode") String devcode); + + List> getDeviceDataListPage(@Param("tableName") String tableName, + @Param("currentIndex") Integer currentIndex, + @Param("fields") String fields, + @Param("pageSize") Integer pageSize, + @Param("devcode") String devcode); + + String getLevelByType(@Param("deviceType")String deviceType); +} diff --git a/src/main/java/com/casic/model/AlarmConfigParam.java b/src/main/java/com/casic/model/AlarmConfigParam.java new file mode 100644 index 0000000..28150d6 --- /dev/null +++ b/src/main/java/com/casic/model/AlarmConfigParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class AlarmConfigParam { + private String deviceType; + private String thresholdVol; + private String collectInterval; + private String uploadCycle; + private String retryNum; + private String ip; + private String port; + private String devcode; +} diff --git a/src/main/java/com/casic/model/AlarmLevel.java b/src/main/java/com/casic/model/AlarmLevel.java new file mode 100644 index 0000000..d0909af --- /dev/null +++ b/src/main/java/com/casic/model/AlarmLevel.java @@ -0,0 +1,26 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("alarm_level") +public class AlarmLevel{ + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + private String name; + private String deviceType; + private Integer level; + private Float lowValue; + private Float highValue; + private String openAlarm; + private String openJob; + private Date ts; + private String tenantId; + +} diff --git a/src/main/java/com/casic/model/BusConfig.java b/src/main/java/com/casic/model/BusConfig.java new file mode 100644 index 0000000..c6b7b50 --- /dev/null +++ b/src/main/java/com/casic/model/BusConfig.java @@ -0,0 +1,27 @@ +package com.casic.model; + + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +import java.util.Date; + +@Data +public class BusConfig { + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + + private String deviceId; + private String framecontent; + private String sensorid; + private String sensorcode; + + private String status; + private Integer attemptsmax; + private Integer attemptscurrent; + private Date sendtime; + private Date writetime; + +} diff --git a/src/main/java/com/casic/model/CommConfigDTO.java b/src/main/java/com/casic/model/CommConfigDTO.java new file mode 100644 index 0000000..7da699c --- /dev/null +++ b/src/main/java/com/casic/model/CommConfigDTO.java @@ -0,0 +1,41 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class CommConfigDTO { + private String acqStart;//采集开始时间 + private Long interval;//采集时间间隔(分钟) + private Long period;//上传周期 + private Long times;//采集次数 + private Long repeat;//重传次数 + private String ip; + private Long port; + private Float thresh; + private Float height; + private String collect; + private String MultiCollect; + private String acqCycle; + private String upCycle; + private String sleepStartTime; + + private String acqStartFlow ; //流量采集开始时间 + private Long intervalFlow; //流量采集采集间隔(分) + private Long acqTimesFlow ;//流量采集次数 + private String upStartFlow; //流量上报开始时间 + private Long upTimesFlow; //流量上传次数 + private String acqStartNoise; //噪声采集开始时间 + private Long intervalNoise; //噪声采集采集间隔(分) + private Long acqTimesNoise;//噪声采集次数 + private String upStartNoise; //噪声上报开始时间 + private Long upTimesNoise ;//噪声上传次数 + private String acqStartPressure; //压力采集开始时间 + private Long intervalPressure;//压力采集采集间隔(分) + private Long acqTimesPressure; //压力采集次数 + private String upStartPressure; //压力上报开始时间 + private Long upTimesPressure; //压力上传次数 + private Float lowerLimitPressure; //压力报警下限 + private Float upperLimitPressure ;//压力报警下限 + private Long limitDig ;//开挖阈值 + private Float threshold ;//开挖阈值 +} diff --git a/src/main/java/com/casic/model/DataPressure.java b/src/main/java/com/casic/model/DataPressure.java new file mode 100644 index 0000000..8270c70 --- /dev/null +++ b/src/main/java/com/casic/model/DataPressure.java @@ -0,0 +1,33 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("data_temp_press") +public class DataPressure { + + @TableId(value = "ID", type = IdType.AUTO) + private String id; + private String wellCode; + private String devcode; + private Float cell; + private String temperature; + + private String press; + private String descn; + private String uptime; + private String logtime; + /** + * 信号强度 + */ + private String pci; + + private String rsrp; + private String snr; + +} diff --git a/src/main/java/com/casic/model/PressureDataParam.java b/src/main/java/com/casic/model/PressureDataParam.java new file mode 100644 index 0000000..f42770d --- /dev/null +++ b/src/main/java/com/casic/model/PressureDataParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class PressureDataParam { + private String flag; + private String deviceUserid; + private String parentUserId; + private Object sensorsDates; + private String time; + private String rawData; + private String deviceId; +} + diff --git a/src/main/java/com/casic/model/ResponseData.java b/src/main/java/com/casic/model/ResponseData.java new file mode 100644 index 0000000..245ab04 --- /dev/null +++ b/src/main/java/com/casic/model/ResponseData.java @@ -0,0 +1,18 @@ +package com.casic.model; + +import lombok.Data; + +/** + * @author cz + * @date 2022-8-12 + */ +@Data +public class ResponseData { + public static final String DEFAULT_SUCCESS_MESSAGE = "请求成功"; + public static final String DEFAULT_ERROR_MESSAGE = "网络异常"; + public static final Integer DEFAULT_SUCCESS_CODE = 200; + public static final Integer DEFAULT_ERROR_CODE = 500; + private Integer code; + private String message; + private Object data; +} \ No newline at end of file diff --git a/src/main/java/com/casic/service/AlarmService.java b/src/main/java/com/casic/service/AlarmService.java new file mode 100644 index 0000000..8516b41 --- /dev/null +++ b/src/main/java/com/casic/service/AlarmService.java @@ -0,0 +1,12 @@ +package com.casic.service; + +import com.casic.model.AlarmConfigParam; + +public interface AlarmService { + + Object getAlarmRecord(String deviceType,Integer currentIndex,Integer pageSize,String devcode); + + Object excuteAlramBatchCancel(String deviceType,String devcode); + + Object addAlarmConfig(AlarmConfigParam alarmConfig); +} diff --git a/src/main/java/com/casic/service/DeviceDataService.java b/src/main/java/com/casic/service/DeviceDataService.java new file mode 100644 index 0000000..db656c1 --- /dev/null +++ b/src/main/java/com/casic/service/DeviceDataService.java @@ -0,0 +1,10 @@ +package com.casic.service; + +public interface DeviceDataService { + + Object getDeviceRecentData(String deviceType, String recentNum, String devcode); + + Object getDeviceListPage(String deviceType, Integer currentIndex, Integer pageSize, String devcode); + + Object getLevel(String deviceType); +} diff --git a/src/main/java/com/casic/service/ThirdDataService.java b/src/main/java/com/casic/service/ThirdDataService.java new file mode 100644 index 0000000..795e0b2 --- /dev/null +++ b/src/main/java/com/casic/service/ThirdDataService.java @@ -0,0 +1,8 @@ +package com.casic.service; + +import com.casic.model.PressureDataParam; + +public interface ThirdDataService { + + Object getDeviceRecentData(PressureDataParam pressureData); +} diff --git a/src/main/java/com/casic/service/impl/AlarmServiceImple.java b/src/main/java/com/casic/service/impl/AlarmServiceImple.java new file mode 100644 index 0000000..a675207 --- /dev/null +++ b/src/main/java/com/casic/service/impl/AlarmServiceImple.java @@ -0,0 +1,127 @@ +package com.casic.service.impl; + +import com.alibaba.druid.util.StringUtils; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.dao.AlarmMapper; +import com.casic.dao.BusConfigMapper; +import com.casic.model.*; +import com.casic.service.AlarmService; +import com.casic.util.DeviceDataTableEnum; +import com.casic.util.RedisCommonUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Slf4j +@Service +public class AlarmServiceImple extends ServiceImpl implements AlarmService { + + @Resource + private BusConfigMapper busConfigMapper; + @Resource + private RedisCommonUtil redisCommonUtil; + + public Object getAlarmRecord(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { + ResponseData responseData = new ResponseData(); + try { + Map page = new HashMap(); + page.put("total", this.baseMapper.getAlarmTotalRecord(deviceType, devcode)); + List> alarmRecordList = this.baseMapper.getAlarmRecord(deviceType, devcode, pageSize * (currentIndex - 1), pageSize); + page.put("rows", alarmRecordList); + responseData.setData(alarmRecordList); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},异常信息{}", deviceType, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + @Transactional + public Object excuteAlramBatchCancel(String deviceType, String devcode) { + ResponseData responseData = new ResponseData(); + try { + this.baseMapper.excuteAlramBatchCancel(deviceType, devcode); + this.baseMapper.excuteJobBatchCancel(deviceType, devcode); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("批量消警异常,设备类型{},异常信息{}", deviceType, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + + @Transactional + public Object addAlarmConfig(AlarmConfigParam alarmConfigParam) { + ResponseData responseData = new ResponseData(); + try { + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + addBusConfig(alarmConfigParam); + addRuleConfig(alarmConfigParam); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("风险配置异常,异常信息{}", dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + private void addRuleConfig(AlarmConfigParam alarmConfigParam) { + Map alarmRuleMap = new HashMap(); + alarmRuleMap.put("DEVICE_TYPE", alarmConfigParam.getDeviceType()); + this.baseMapper.deleteByMap(alarmRuleMap); + AlarmLevel alarmRule = new AlarmLevel(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap() + .get(Integer.valueOf(alarmConfigParam.getDeviceType())); + alarmRule.setName(deviceDataTableEnum.getTypeName()); + alarmRule.setHighValue(Float.valueOf(alarmConfigParam.getThresholdVol())); + alarmRule.setTs(new Date()); + alarmRule.setLevel(1); + alarmRule.setDeviceType(alarmConfigParam.getDeviceType()); + this.baseMapper.insert(alarmRule); + } + + private void addBusConfig(AlarmConfigParam alarmConfigParam) { + String devcode = StringUtils.isEmpty(alarmConfigParam.getDevcode()) ? this.baseMapper.getDeviceDevcode(alarmConfigParam.getDeviceType()) : alarmConfigParam.getDevcode(); + sendBusConfig(alarmConfigParam, devcode); + String devcideId = this.baseMapper.getDeviceByDevcode(alarmConfigParam.getDeviceType(), devcode); + BusConfig busConfig = new BusConfig(); + busConfig.setDeviceId(devcideId); + busConfig.setFramecontent("3," + alarmConfigParam.getCollectInterval() + "," + alarmConfigParam.getCollectInterval() + + "," + alarmConfigParam.getRetryNum() + "," + alarmConfigParam.getIp() + "," + alarmConfigParam.getPort()); + busConfig.setSensorid(""); + busConfig.setStatus("0"); + busConfig.setAttemptscurrent(0); + busConfig.setWritetime(new Date()); + busConfig.setAttemptsmax(3); + busConfigMapper.insert(busConfig); + } + + private void sendBusConfig(AlarmConfigParam alarmConfigParam, String devcode) { + CommConfigDTO commConfigDTO = new CommConfigDTO(); + commConfigDTO.setInterval(StringUtils.isEmpty(alarmConfigParam.getCollectInterval()) ? 300 : Long.valueOf(alarmConfigParam.getCollectInterval())); + commConfigDTO.setRepeat(StringUtils.isEmpty(alarmConfigParam.getRetryNum()) ? 300 : Long.valueOf(alarmConfigParam.getRetryNum())); + commConfigDTO.setTimes(Long.valueOf(1)); +// commConfigDTO.setIp(alarmConfigParam.getIp()); +// commConfigDTO.setPort(StringUtils.isEmpty(alarmConfigParam.getPort()) ? 8080 : Long.valueOf(alarmConfigParam.getPort())); + commConfigDTO.setPeriod(StringUtils.isEmpty(alarmConfigParam.getUploadCycle()) ? 300 : Long.valueOf(alarmConfigParam.getUploadCycle())); +// commConfigDTO.setThresh(); + commConfigDTO.setThresh(StringUtils.isEmpty(alarmConfigParam.getThresholdVol()) ? 50: Float.valueOf(alarmConfigParam.getThresholdVol())); + redisCommonUtil.send(commConfigDTO, devcode); + } + + +} diff --git a/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java new file mode 100644 index 0000000..3de704b --- /dev/null +++ b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java @@ -0,0 +1,80 @@ +package com.casic.service.impl; + +import com.casic.dao.DeviceDataMapper; +import com.casic.model.ResponseData; +import com.casic.service.DeviceDataService; +import com.casic.util.DeviceDataFieldTableEnum; +import com.casic.util.DeviceDataTableEnum; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Service +@Slf4j +public class DeviceDataServiceImpl implements DeviceDataService { + + private final DeviceDataMapper deviceDataMapper; + + public DeviceDataServiceImpl(DeviceDataMapper deviceDataMapper) { + this.deviceDataMapper = deviceDataMapper; + } + + public Object getDeviceRecentData(String deviceType, String recentNum, String devcode) { + ResponseData responseData = new ResponseData(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); + try { + String tableName = deviceDataTableEnum.getTableName(); + String fields = DeviceDataFieldTableEnum.TABLE_FIELD.getTableFieldMap().get(tableName); + List> recentDataList = deviceDataMapper.getDeviceRecentData(tableName, recentNum, fields, devcode); + responseData.setData(recentDataList); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备最近数据查询异常,设备类型{},查询数目{},异常信息{}", deviceType, recentNum, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + public Object getDeviceListPage(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { + ResponseData responseData = new ResponseData(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); + try { + String tableName = deviceDataTableEnum.getTableName(); + String fields = DeviceDataFieldTableEnum.TABLE_FIELD.getTableFieldMap().get(tableName); + Map page = new HashMap(); + page.put("total", deviceDataMapper.getDeviceDataTotal(tableName, devcode)); + List> recentDataList = deviceDataMapper.getDeviceDataListPage(tableName, pageSize * (currentIndex - 1), fields, pageSize, devcode); + page.put("rows", recentDataList); + responseData.setData(page); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},当前页{},页大小{},异常信息{}", deviceType, currentIndex, pageSize, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + public Object getLevel(String deviceType) { + ResponseData responseData = new ResponseData(); + try { + String highValue = deviceDataMapper.getLevelByType(deviceType); + responseData.setData(highValue); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},当前页{},页大小{},异常信息{}"); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + +} diff --git a/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java new file mode 100644 index 0000000..6b23451 --- /dev/null +++ b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java @@ -0,0 +1,92 @@ +package com.casic.service.impl; + +import com.alibaba.druid.util.StringUtils; +import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.dao.DataPressureMapper; +import com.casic.model.DataPressure; +import com.casic.model.PressureDataParam; +import com.casic.model.ResponseData; +import com.casic.service.ThirdDataService; +import com.casic.util.CacheUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.stream.Collectors; + +@Service +@Slf4j +public class ThirdDataServiceImpl extends ServiceImpl implements ThirdDataService { + + private final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA); + + public Object getDeviceRecentData(PressureDataParam pressureDataParam) { + ResponseData responseData = new ResponseData(); + try { + batchSave(pressureDataParam); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备最近数据查询异常,设备类型{},异常信息{}", dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + private void batchSave(PressureDataParam pressureDataParam) { + String pressureDataJson = pressureDataParam.getRawData(); + log.info("----" + pressureDataJson); + Map pressureDataMap = JSON.parseObject(pressureDataJson, HashMap.class); + Date uptime = null; + try { + uptime = dateFormat.parse(String.valueOf(pressureDataMap.get("times"))); + } catch (Exception e) { + log.error("主题,采集时间解析异常,异常信息{}", e.getMessage()); + } + List> pressureDataList = (List>) pressureDataMap.get("sensorDatas"); + DataPressure dataPressure = initPrssureData(pressureDataList, uptime); + if (dataPressure == null) { + return; + } + checkAlarm(dataPressure); + } + + private DataPressure initPrssureData(List> pressureDataList, Date uptime) { + DataPressure dataPressure = new DataPressure(); + String devcode = pressureDataList.get(pressureDataList.size() - 1).get("str"); + Map pressureDataMap = pressureDataList.stream().collect( + Collectors.toMap(e -> String.valueOf(e.get("flag")), e -> String.valueOf(e.get("value"))) + ); +// if (CacheUtil.serialBuf.get(devcode)!=null&&CacheUtil.serialBuf.get(devcode).equals(pressureDataMap.get("F"))) { +// return null; +// } + String wellCode = this.baseMapper.getWellCode(devcode); + dataPressure.setWellCode(wellCode); + dataPressure.setDevcode(devcode); + dataPressure.setPci(pressureDataMap.get("Q")); + dataPressure.setCell(Float.valueOf(pressureDataMap.get("V"))); + dataPressure.setTemperature(pressureDataMap.get("T")); + dataPressure.setPress(pressureDataMap.get("F")); + dataPressure.setUptime(dateFormat.format(uptime)); + dataPressure.setLogtime(dateFormat.format(new Date())); + this.baseMapper.insert(dataPressure); +// CacheUtil.serialBuf.put(devcode, pressureDataMap.get("F")); + return dataPressure; + } + + private void checkAlarm(DataPressure dataPressure) { + final Float ruleValue = this.baseMapper.getRuleValue("24"); + if (ruleValue == null) return; + if (!StringUtils.isEmpty(dataPressure.getTemperature()) && !dataPressure.getTemperature().equals("null")) { + if (Float.valueOf(dataPressure.getTemperature()) > ruleValue) { + this.baseMapper.saveRecords(dataPressure.getTemperature(), new Date()); + } + } + } + +} diff --git a/src/main/java/com/casic/util/CacheUtil.java b/src/main/java/com/casic/util/CacheUtil.java new file mode 100644 index 0000000..5b89300 --- /dev/null +++ b/src/main/java/com/casic/util/CacheUtil.java @@ -0,0 +1,16 @@ +package com.casic.util; + +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import java.util.HashMap; +import java.util.Map; + +@Component +public class CacheUtil { + public static volatile Map serialBuf; + @PostConstruct + public void init() { + serialBuf = new HashMap<>(); + } +} diff --git a/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java b/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java new file mode 100644 index 0000000..085c7c3 --- /dev/null +++ b/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java @@ -0,0 +1,39 @@ +package com.casic.util; + +import java.util.HashMap; +import java.util.Map; + +public enum DeviceDataFieldTableEnum { + + TABLE_FIELD(new HashMap() { + { + put("data_dig", "ddata AS dataValue,devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gas", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gasliquid_gas", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gasliquid_liquid", "liquiddata AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gas_dector", "gas_sample_value AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_harmful_gas", "CONCAT(CO, ', ', CH4, ', ', H2S, ', ', O2) AS dataValue,devcode AS devcode,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_hydrant", "0 AS dataValue,devcode AS devcode,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_liquid", "liquiddata AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_noise", "ddata AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_temp_hum", "CONCAT(TEMPERATURE, ', ', HUMIDITY) AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_tube", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_wellcover", "descn AS dataValue,devcode AS devcode,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_temp_press", "press AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_pantilt", "concentration AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_wellcover_loca", "0 AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_wellplus", "0 AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_h2s", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_pressure", "re_val AS dataValue,devcode AS devcode,'' AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + } + }); + public Map tableNameMap; + + DeviceDataFieldTableEnum(Map tableNameMap) { + this.tableNameMap = tableNameMap; + } + + public Map getTableFieldMap() { + return tableNameMap; + } +} diff --git a/src/main/java/com/casic/util/DeviceDataTableEnum.java b/src/main/java/com/casic/util/DeviceDataTableEnum.java new file mode 100644 index 0000000..9698487 --- /dev/null +++ b/src/main/java/com/casic/util/DeviceDataTableEnum.java @@ -0,0 +1,81 @@ +package com.casic.util; + +import java.util.HashMap; + +/** + * @author cz + * @date 2022-7-15 + * 上传数据总记录数 + */ +public enum DeviceDataTableEnum { + + DATA_DIG("data_dig", "开挖监测仪"), + DATA_GAS("data_gas", "燃气智能监测终端"), + DATA_GASLIQUID("data_gasliquid_gas,data_gasliquid_liquid", "燃气智能监测终端(一体化)"), + DATA_GAS_DECTOR("data_gas_dector", "燃气探测仪"), + DATA_HARMFUL_GAS("data_harmful_gas", "有害气体监测仪"), + DATA_HYDRANT("data_hydrant", "消防栓防盗水监测仪"), + DATA_LIQUID("data_liquid", "液位监测仪"), + DATA_NOISE("data_noise", "噪声记录仪"), + DATA_PANTILT("data_pantilt", "激光甲烷云台"), + DATA_TEMP_HUM("data_temp_hum", "温湿度监测仪"), + DATA_TUBE("data_tube", "管盯"), + DATA_WELLCOVER("data_wellcover", "井盖状态监测仪"), + DATA_TEMP_PRESS("data_temp_press", "压力温度检测仪"), + DATA_WELLCOVER_LOCA("data_wellcover_loca", "井盖定位监测仪"), + DATA_WELLPLUS("data_wellplus", "井盖液位一体机"), + DATA_H2S("data_h2s", "硫化氢检测终端"), + DATA_PRESSURE("data_pressure", "压力检测终端"), + DEVICE_TYPE_TABLE(new HashMap() { + { + put(1, DATA_WELLCOVER); + put(2, DATA_LIQUID); + put(3, DATA_HARMFUL_GAS); + put(4, DATA_GAS); + put(5, DATA_TEMP_HUM); + put(6, DATA_DIG); + put(7, DATA_WELLCOVER_LOCA); + put(8, DATA_NOISE); + put(9, DATA_TEMP_PRESS); + put(10, DATA_GASLIQUID); + put(11, DATA_HYDRANT); + put(12, DATA_TUBE); + put(13, DATA_WELLPLUS); + put(14, DATA_H2S); + put(21, DATA_PANTILT); + put(22, DATA_H2S); + put(23, DATA_GAS); + put(24, DATA_TEMP_PRESS); + put(101, DATA_GAS_DECTOR); + } + }); + + String typeName; + String tableName; + + DeviceDataTableEnum(String tableName, String typeName) { + this.typeName = typeName; + this.tableName = tableName; + } + + public String getTypeName() { + return typeName; + } + + public String getTableName() { + return tableName; + } + + + public HashMap tableNameMap; + + DeviceDataTableEnum(HashMap tableNameMap) { + this.tableNameMap = tableNameMap; + } + + public HashMap getTableNameMap() { + return tableNameMap; + } + + +} diff --git a/src/main/java/com/casic/util/RedisCommonUtil.java b/src/main/java/com/casic/util/RedisCommonUtil.java new file mode 100644 index 0000000..a6ce9cf --- /dev/null +++ b/src/main/java/com/casic/util/RedisCommonUtil.java @@ -0,0 +1,29 @@ +package com.casic.util; + +import com.alibaba.fastjson.JSON; +import com.casic.model.CommConfigDTO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; + +import java.util.concurrent.TimeUnit; + +@Component +public class RedisCommonUtil { + + @Value("${casic.device.redis.invalid-time}") + private String invalidTime; + @Value("${casic.device.redis.config-prefix}") + private String configPrefix; + + @Autowired + private RedisTemplate redisTemplate; + + public void send(CommConfigDTO commConfigDTO,String devCode) { + redisTemplate.opsForValue().set(configPrefix+ devCode, + JSON.toJSONString(commConfigDTO), + Integer.valueOf(invalidTime), + TimeUnit.SECONDS); + } +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..50f4a19 --- /dev/null +++ b/pom.xml @@ -0,0 +1,161 @@ + + + 4.0.0 + + com.casic + smartwell-demos + 1.0-SNAPSHOT + + + + + jdk-1.8 + + true + 1.8 + + + 1.8 + 1.8 + 1.8 + + + + + + + + + + org.springframework.boot + spring-boot-starter + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-tomcat + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-web + 2.4.5 + + + + + org.springframework.boot + spring-boot-starter-jdbc + 2.4.5 + + + + mysql + mysql-connector-java + 8.0.16 + compile + + + + com.baomidou + mybatis-plus-boot-starter + 3.4.3 + + + + org.projectlombok + lombok + 1.18.20 + + + + + com.alibaba + druid + 1.2.6 + + + + com.alibaba + fastjson + 1.2.73 + + + + commons-codec + commons-codec + 1.14 + + + + redis.clients + jedis + 3.1.0 + jar + + + + org.springframework.data + spring-data-redis + 2.4.8 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.3.RELEASE + + true + + com.casic.CasicApplication + exec + + + + + repackage + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + false + + + + + + + + src/main/resources + + + /config/*/* + /config/*-*.yml + + true + + + src/main/resources + + **/*.xml + + true + + + + + \ No newline at end of file diff --git a/src/main/java/com/casic/CasicApplication.java b/src/main/java/com/casic/CasicApplication.java new file mode 100644 index 0000000..9afd0b9 --- /dev/null +++ b/src/main/java/com/casic/CasicApplication.java @@ -0,0 +1,28 @@ +package com.casic; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.transaction.annotation.EnableTransactionManagement; + + +/** + * SpringBoot方式启动类 + * + * @author cz + * @Date 2022/09/08 14:28 + */ + +@Slf4j +@ComponentScan(basePackages= "com.casic.**") +@SpringBootApplication +public class CasicApplication { + public static void main(String[] args) { + log.info("CasicApplication is success!"); + SpringApplication.run(CasicApplication.class, args); + } +} diff --git a/src/main/java/com/casic/config/CorsConfig.java b/src/main/java/com/casic/config/CorsConfig.java new file mode 100644 index 0000000..7d19680 --- /dev/null +++ b/src/main/java/com/casic/config/CorsConfig.java @@ -0,0 +1,31 @@ +package com.casic.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +/** + * 基础框架 - 跨域请求配置 + */ +@Configuration +public class CorsConfig { + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", buildConfig()); + return new CorsFilter(source); + } + + private CorsConfiguration buildConfig() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + // 1允许任何域名使用 + corsConfiguration.addAllowedOrigin("*"); + // 2允许任何头 + corsConfiguration.addAllowedHeader("*"); + // 3允许任何方法(post、get等) + corsConfiguration.addAllowedMethod("*"); + return corsConfiguration; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/controller/AlarmController.java b/src/main/java/com/casic/controller/AlarmController.java new file mode 100644 index 0000000..957fc36 --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.model.AlarmConfigParam; +import com.casic.service.AlarmService; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/alarm") +public class AlarmController { + + private final AlarmService alarmService; + + public AlarmController(AlarmService alarmService) { + this.alarmService = alarmService; + } + + @RequestMapping("/records") + public Object getAlarmRecord(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "devcode",required =false) String devcode, + @RequestParam(value = "pageSize", required = true) Integer pageSize) { + return alarmService.getAlarmRecord(deviceType,currentIndex,pageSize,devcode); + } + + @RequestMapping("/batch/cancel") + public Object excuteAlramBatchCancel(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "devcode",required =false) String devcode) { + return alarmService.excuteAlramBatchCancel(deviceType,devcode); + } + + @RequestMapping("/config/add") + public Object addAlarmConfig(@RequestBody AlarmConfigParam alarmConfigParam) { + return alarmService.addAlarmConfig(alarmConfigParam); + } +} diff --git a/src/main/java/com/casic/controller/DeviceDataController.java b/src/main/java/com/casic/controller/DeviceDataController.java new file mode 100644 index 0000000..3498b04 --- /dev/null +++ b/src/main/java/com/casic/controller/DeviceDataController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.service.DeviceDataService; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/device") +public class DeviceDataController { + private final DeviceDataService deviceDataService; + + public DeviceDataController(DeviceDataService deviceDataService) { + this.deviceDataService = deviceDataService; + } + + @RequestMapping("/recent-data") + public Object getDeviceRecentData(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "recentNum", required = true) String recentNum, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceRecentData(deviceType, recentNum, devcode); + } + + @RequestMapping("/data/list-page") + public Object getDeviceListPage(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "pageSize", required = true) Integer pageSize, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceListPage(deviceType, currentIndex, pageSize, devcode); + } + + @RequestMapping("/level/{deviceType}") + public Object getLevelList(@PathVariable("deviceType")String deviceType) { + return deviceDataService.getLevel(deviceType); + } + +} diff --git a/src/main/java/com/casic/controller/ThirdDataController.java b/src/main/java/com/casic/controller/ThirdDataController.java new file mode 100644 index 0000000..b9b2b42 --- /dev/null +++ b/src/main/java/com/casic/controller/ThirdDataController.java @@ -0,0 +1,28 @@ +package com.casic.controller; + +import com.casic.model.PressureDataParam; +import com.casic.service.ThirdDataService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +@RestController +@RequestMapping("/push") +@Slf4j +public class ThirdDataController { + + private final ThirdDataService thirdDataService; + + public ThirdDataController(ThirdDataService thirdDataService) { + this.thirdDataService = thirdDataService; + } + + @RequestMapping("/pressure/data") + public Object getDeviceRecentData(@RequestBody PressureDataParam pressureData) { + return thirdDataService.getDeviceRecentData(pressureData); + } + +} diff --git a/src/main/java/com/casic/dao/AlarmMapper.java b/src/main/java/com/casic/dao/AlarmMapper.java new file mode 100644 index 0000000..a442e3a --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmMapper.java @@ -0,0 +1,28 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmLevel; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + +@Mapper +public interface AlarmMapper extends BaseMapper { + + List> getAlarmRecord(@Param("deviceType") String deviceType, + @Param("devcode") String devcode, + @Param("currentIndex") Integer currentIndex, @Param("pageSize") Integer pageSize); + + Integer getAlarmTotalRecord(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteAlramBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteJobBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + String getDeviceDevcode(@Param("deviceType") String deviceType); + + String getDeviceByDevcode(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + +} diff --git a/src/main/java/com/casic/dao/BusConfigMapper.java b/src/main/java/com/casic/dao/BusConfigMapper.java new file mode 100644 index 0000000..ccf76da --- /dev/null +++ b/src/main/java/com/casic/dao/BusConfigMapper.java @@ -0,0 +1,9 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.BusConfig; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface BusConfigMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/dao/DataPressureMapper.java b/src/main/java/com/casic/dao/DataPressureMapper.java new file mode 100644 index 0000000..05f4329 --- /dev/null +++ b/src/main/java/com/casic/dao/DataPressureMapper.java @@ -0,0 +1,19 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.DataPressure; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.Date; + +@Mapper +public interface DataPressureMapper extends BaseMapper { + + String getWellCode(@Param("devcode") String devcode); + + Float getRuleValue(@Param("deviceType") String deviceType); + + void saveRecords(@Param("reValue") String reValue, @Param("alarmTime") Date alarmTime); + +} diff --git a/src/main/java/com/casic/dao/DeviceDataMapper.java b/src/main/java/com/casic/dao/DeviceDataMapper.java new file mode 100644 index 0000000..d9e18a0 --- /dev/null +++ b/src/main/java/com/casic/dao/DeviceDataMapper.java @@ -0,0 +1,27 @@ +package com.casic.dao; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + + +@Mapper +public interface DeviceDataMapper { + + List> getDeviceRecentData(@Param("tableName") String tableName, + @Param("recentNum") String recentNum, + @Param("fields") String fields, + @Param("devcode") String devcode); + + Integer getDeviceDataTotal(@Param("tableName") String tableName, @Param("devcode") String devcode); + + List> getDeviceDataListPage(@Param("tableName") String tableName, + @Param("currentIndex") Integer currentIndex, + @Param("fields") String fields, + @Param("pageSize") Integer pageSize, + @Param("devcode") String devcode); + + String getLevelByType(@Param("deviceType")String deviceType); +} diff --git a/src/main/java/com/casic/model/AlarmConfigParam.java b/src/main/java/com/casic/model/AlarmConfigParam.java new file mode 100644 index 0000000..28150d6 --- /dev/null +++ b/src/main/java/com/casic/model/AlarmConfigParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class AlarmConfigParam { + private String deviceType; + private String thresholdVol; + private String collectInterval; + private String uploadCycle; + private String retryNum; + private String ip; + private String port; + private String devcode; +} diff --git a/src/main/java/com/casic/model/AlarmLevel.java b/src/main/java/com/casic/model/AlarmLevel.java new file mode 100644 index 0000000..d0909af --- /dev/null +++ b/src/main/java/com/casic/model/AlarmLevel.java @@ -0,0 +1,26 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("alarm_level") +public class AlarmLevel{ + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + private String name; + private String deviceType; + private Integer level; + private Float lowValue; + private Float highValue; + private String openAlarm; + private String openJob; + private Date ts; + private String tenantId; + +} diff --git a/src/main/java/com/casic/model/BusConfig.java b/src/main/java/com/casic/model/BusConfig.java new file mode 100644 index 0000000..c6b7b50 --- /dev/null +++ b/src/main/java/com/casic/model/BusConfig.java @@ -0,0 +1,27 @@ +package com.casic.model; + + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +import java.util.Date; + +@Data +public class BusConfig { + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + + private String deviceId; + private String framecontent; + private String sensorid; + private String sensorcode; + + private String status; + private Integer attemptsmax; + private Integer attemptscurrent; + private Date sendtime; + private Date writetime; + +} diff --git a/src/main/java/com/casic/model/CommConfigDTO.java b/src/main/java/com/casic/model/CommConfigDTO.java new file mode 100644 index 0000000..7da699c --- /dev/null +++ b/src/main/java/com/casic/model/CommConfigDTO.java @@ -0,0 +1,41 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class CommConfigDTO { + private String acqStart;//采集开始时间 + private Long interval;//采集时间间隔(分钟) + private Long period;//上传周期 + private Long times;//采集次数 + private Long repeat;//重传次数 + private String ip; + private Long port; + private Float thresh; + private Float height; + private String collect; + private String MultiCollect; + private String acqCycle; + private String upCycle; + private String sleepStartTime; + + private String acqStartFlow ; //流量采集开始时间 + private Long intervalFlow; //流量采集采集间隔(分) + private Long acqTimesFlow ;//流量采集次数 + private String upStartFlow; //流量上报开始时间 + private Long upTimesFlow; //流量上传次数 + private String acqStartNoise; //噪声采集开始时间 + private Long intervalNoise; //噪声采集采集间隔(分) + private Long acqTimesNoise;//噪声采集次数 + private String upStartNoise; //噪声上报开始时间 + private Long upTimesNoise ;//噪声上传次数 + private String acqStartPressure; //压力采集开始时间 + private Long intervalPressure;//压力采集采集间隔(分) + private Long acqTimesPressure; //压力采集次数 + private String upStartPressure; //压力上报开始时间 + private Long upTimesPressure; //压力上传次数 + private Float lowerLimitPressure; //压力报警下限 + private Float upperLimitPressure ;//压力报警下限 + private Long limitDig ;//开挖阈值 + private Float threshold ;//开挖阈值 +} diff --git a/src/main/java/com/casic/model/DataPressure.java b/src/main/java/com/casic/model/DataPressure.java new file mode 100644 index 0000000..8270c70 --- /dev/null +++ b/src/main/java/com/casic/model/DataPressure.java @@ -0,0 +1,33 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("data_temp_press") +public class DataPressure { + + @TableId(value = "ID", type = IdType.AUTO) + private String id; + private String wellCode; + private String devcode; + private Float cell; + private String temperature; + + private String press; + private String descn; + private String uptime; + private String logtime; + /** + * 信号强度 + */ + private String pci; + + private String rsrp; + private String snr; + +} diff --git a/src/main/java/com/casic/model/PressureDataParam.java b/src/main/java/com/casic/model/PressureDataParam.java new file mode 100644 index 0000000..f42770d --- /dev/null +++ b/src/main/java/com/casic/model/PressureDataParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class PressureDataParam { + private String flag; + private String deviceUserid; + private String parentUserId; + private Object sensorsDates; + private String time; + private String rawData; + private String deviceId; +} + diff --git a/src/main/java/com/casic/model/ResponseData.java b/src/main/java/com/casic/model/ResponseData.java new file mode 100644 index 0000000..245ab04 --- /dev/null +++ b/src/main/java/com/casic/model/ResponseData.java @@ -0,0 +1,18 @@ +package com.casic.model; + +import lombok.Data; + +/** + * @author cz + * @date 2022-8-12 + */ +@Data +public class ResponseData { + public static final String DEFAULT_SUCCESS_MESSAGE = "请求成功"; + public static final String DEFAULT_ERROR_MESSAGE = "网络异常"; + public static final Integer DEFAULT_SUCCESS_CODE = 200; + public static final Integer DEFAULT_ERROR_CODE = 500; + private Integer code; + private String message; + private Object data; +} \ No newline at end of file diff --git a/src/main/java/com/casic/service/AlarmService.java b/src/main/java/com/casic/service/AlarmService.java new file mode 100644 index 0000000..8516b41 --- /dev/null +++ b/src/main/java/com/casic/service/AlarmService.java @@ -0,0 +1,12 @@ +package com.casic.service; + +import com.casic.model.AlarmConfigParam; + +public interface AlarmService { + + Object getAlarmRecord(String deviceType,Integer currentIndex,Integer pageSize,String devcode); + + Object excuteAlramBatchCancel(String deviceType,String devcode); + + Object addAlarmConfig(AlarmConfigParam alarmConfig); +} diff --git a/src/main/java/com/casic/service/DeviceDataService.java b/src/main/java/com/casic/service/DeviceDataService.java new file mode 100644 index 0000000..db656c1 --- /dev/null +++ b/src/main/java/com/casic/service/DeviceDataService.java @@ -0,0 +1,10 @@ +package com.casic.service; + +public interface DeviceDataService { + + Object getDeviceRecentData(String deviceType, String recentNum, String devcode); + + Object getDeviceListPage(String deviceType, Integer currentIndex, Integer pageSize, String devcode); + + Object getLevel(String deviceType); +} diff --git a/src/main/java/com/casic/service/ThirdDataService.java b/src/main/java/com/casic/service/ThirdDataService.java new file mode 100644 index 0000000..795e0b2 --- /dev/null +++ b/src/main/java/com/casic/service/ThirdDataService.java @@ -0,0 +1,8 @@ +package com.casic.service; + +import com.casic.model.PressureDataParam; + +public interface ThirdDataService { + + Object getDeviceRecentData(PressureDataParam pressureData); +} diff --git a/src/main/java/com/casic/service/impl/AlarmServiceImple.java b/src/main/java/com/casic/service/impl/AlarmServiceImple.java new file mode 100644 index 0000000..a675207 --- /dev/null +++ b/src/main/java/com/casic/service/impl/AlarmServiceImple.java @@ -0,0 +1,127 @@ +package com.casic.service.impl; + +import com.alibaba.druid.util.StringUtils; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.dao.AlarmMapper; +import com.casic.dao.BusConfigMapper; +import com.casic.model.*; +import com.casic.service.AlarmService; +import com.casic.util.DeviceDataTableEnum; +import com.casic.util.RedisCommonUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Slf4j +@Service +public class AlarmServiceImple extends ServiceImpl implements AlarmService { + + @Resource + private BusConfigMapper busConfigMapper; + @Resource + private RedisCommonUtil redisCommonUtil; + + public Object getAlarmRecord(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { + ResponseData responseData = new ResponseData(); + try { + Map page = new HashMap(); + page.put("total", this.baseMapper.getAlarmTotalRecord(deviceType, devcode)); + List> alarmRecordList = this.baseMapper.getAlarmRecord(deviceType, devcode, pageSize * (currentIndex - 1), pageSize); + page.put("rows", alarmRecordList); + responseData.setData(alarmRecordList); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},异常信息{}", deviceType, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + @Transactional + public Object excuteAlramBatchCancel(String deviceType, String devcode) { + ResponseData responseData = new ResponseData(); + try { + this.baseMapper.excuteAlramBatchCancel(deviceType, devcode); + this.baseMapper.excuteJobBatchCancel(deviceType, devcode); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("批量消警异常,设备类型{},异常信息{}", deviceType, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + + @Transactional + public Object addAlarmConfig(AlarmConfigParam alarmConfigParam) { + ResponseData responseData = new ResponseData(); + try { + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + addBusConfig(alarmConfigParam); + addRuleConfig(alarmConfigParam); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("风险配置异常,异常信息{}", dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + private void addRuleConfig(AlarmConfigParam alarmConfigParam) { + Map alarmRuleMap = new HashMap(); + alarmRuleMap.put("DEVICE_TYPE", alarmConfigParam.getDeviceType()); + this.baseMapper.deleteByMap(alarmRuleMap); + AlarmLevel alarmRule = new AlarmLevel(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap() + .get(Integer.valueOf(alarmConfigParam.getDeviceType())); + alarmRule.setName(deviceDataTableEnum.getTypeName()); + alarmRule.setHighValue(Float.valueOf(alarmConfigParam.getThresholdVol())); + alarmRule.setTs(new Date()); + alarmRule.setLevel(1); + alarmRule.setDeviceType(alarmConfigParam.getDeviceType()); + this.baseMapper.insert(alarmRule); + } + + private void addBusConfig(AlarmConfigParam alarmConfigParam) { + String devcode = StringUtils.isEmpty(alarmConfigParam.getDevcode()) ? this.baseMapper.getDeviceDevcode(alarmConfigParam.getDeviceType()) : alarmConfigParam.getDevcode(); + sendBusConfig(alarmConfigParam, devcode); + String devcideId = this.baseMapper.getDeviceByDevcode(alarmConfigParam.getDeviceType(), devcode); + BusConfig busConfig = new BusConfig(); + busConfig.setDeviceId(devcideId); + busConfig.setFramecontent("3," + alarmConfigParam.getCollectInterval() + "," + alarmConfigParam.getCollectInterval() + + "," + alarmConfigParam.getRetryNum() + "," + alarmConfigParam.getIp() + "," + alarmConfigParam.getPort()); + busConfig.setSensorid(""); + busConfig.setStatus("0"); + busConfig.setAttemptscurrent(0); + busConfig.setWritetime(new Date()); + busConfig.setAttemptsmax(3); + busConfigMapper.insert(busConfig); + } + + private void sendBusConfig(AlarmConfigParam alarmConfigParam, String devcode) { + CommConfigDTO commConfigDTO = new CommConfigDTO(); + commConfigDTO.setInterval(StringUtils.isEmpty(alarmConfigParam.getCollectInterval()) ? 300 : Long.valueOf(alarmConfigParam.getCollectInterval())); + commConfigDTO.setRepeat(StringUtils.isEmpty(alarmConfigParam.getRetryNum()) ? 300 : Long.valueOf(alarmConfigParam.getRetryNum())); + commConfigDTO.setTimes(Long.valueOf(1)); +// commConfigDTO.setIp(alarmConfigParam.getIp()); +// commConfigDTO.setPort(StringUtils.isEmpty(alarmConfigParam.getPort()) ? 8080 : Long.valueOf(alarmConfigParam.getPort())); + commConfigDTO.setPeriod(StringUtils.isEmpty(alarmConfigParam.getUploadCycle()) ? 300 : Long.valueOf(alarmConfigParam.getUploadCycle())); +// commConfigDTO.setThresh(); + commConfigDTO.setThresh(StringUtils.isEmpty(alarmConfigParam.getThresholdVol()) ? 50: Float.valueOf(alarmConfigParam.getThresholdVol())); + redisCommonUtil.send(commConfigDTO, devcode); + } + + +} diff --git a/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java new file mode 100644 index 0000000..3de704b --- /dev/null +++ b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java @@ -0,0 +1,80 @@ +package com.casic.service.impl; + +import com.casic.dao.DeviceDataMapper; +import com.casic.model.ResponseData; +import com.casic.service.DeviceDataService; +import com.casic.util.DeviceDataFieldTableEnum; +import com.casic.util.DeviceDataTableEnum; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Service +@Slf4j +public class DeviceDataServiceImpl implements DeviceDataService { + + private final DeviceDataMapper deviceDataMapper; + + public DeviceDataServiceImpl(DeviceDataMapper deviceDataMapper) { + this.deviceDataMapper = deviceDataMapper; + } + + public Object getDeviceRecentData(String deviceType, String recentNum, String devcode) { + ResponseData responseData = new ResponseData(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); + try { + String tableName = deviceDataTableEnum.getTableName(); + String fields = DeviceDataFieldTableEnum.TABLE_FIELD.getTableFieldMap().get(tableName); + List> recentDataList = deviceDataMapper.getDeviceRecentData(tableName, recentNum, fields, devcode); + responseData.setData(recentDataList); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备最近数据查询异常,设备类型{},查询数目{},异常信息{}", deviceType, recentNum, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + public Object getDeviceListPage(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { + ResponseData responseData = new ResponseData(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); + try { + String tableName = deviceDataTableEnum.getTableName(); + String fields = DeviceDataFieldTableEnum.TABLE_FIELD.getTableFieldMap().get(tableName); + Map page = new HashMap(); + page.put("total", deviceDataMapper.getDeviceDataTotal(tableName, devcode)); + List> recentDataList = deviceDataMapper.getDeviceDataListPage(tableName, pageSize * (currentIndex - 1), fields, pageSize, devcode); + page.put("rows", recentDataList); + responseData.setData(page); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},当前页{},页大小{},异常信息{}", deviceType, currentIndex, pageSize, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + public Object getLevel(String deviceType) { + ResponseData responseData = new ResponseData(); + try { + String highValue = deviceDataMapper.getLevelByType(deviceType); + responseData.setData(highValue); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},当前页{},页大小{},异常信息{}"); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + +} diff --git a/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java new file mode 100644 index 0000000..6b23451 --- /dev/null +++ b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java @@ -0,0 +1,92 @@ +package com.casic.service.impl; + +import com.alibaba.druid.util.StringUtils; +import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.dao.DataPressureMapper; +import com.casic.model.DataPressure; +import com.casic.model.PressureDataParam; +import com.casic.model.ResponseData; +import com.casic.service.ThirdDataService; +import com.casic.util.CacheUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.stream.Collectors; + +@Service +@Slf4j +public class ThirdDataServiceImpl extends ServiceImpl implements ThirdDataService { + + private final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA); + + public Object getDeviceRecentData(PressureDataParam pressureDataParam) { + ResponseData responseData = new ResponseData(); + try { + batchSave(pressureDataParam); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备最近数据查询异常,设备类型{},异常信息{}", dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + private void batchSave(PressureDataParam pressureDataParam) { + String pressureDataJson = pressureDataParam.getRawData(); + log.info("----" + pressureDataJson); + Map pressureDataMap = JSON.parseObject(pressureDataJson, HashMap.class); + Date uptime = null; + try { + uptime = dateFormat.parse(String.valueOf(pressureDataMap.get("times"))); + } catch (Exception e) { + log.error("主题,采集时间解析异常,异常信息{}", e.getMessage()); + } + List> pressureDataList = (List>) pressureDataMap.get("sensorDatas"); + DataPressure dataPressure = initPrssureData(pressureDataList, uptime); + if (dataPressure == null) { + return; + } + checkAlarm(dataPressure); + } + + private DataPressure initPrssureData(List> pressureDataList, Date uptime) { + DataPressure dataPressure = new DataPressure(); + String devcode = pressureDataList.get(pressureDataList.size() - 1).get("str"); + Map pressureDataMap = pressureDataList.stream().collect( + Collectors.toMap(e -> String.valueOf(e.get("flag")), e -> String.valueOf(e.get("value"))) + ); +// if (CacheUtil.serialBuf.get(devcode)!=null&&CacheUtil.serialBuf.get(devcode).equals(pressureDataMap.get("F"))) { +// return null; +// } + String wellCode = this.baseMapper.getWellCode(devcode); + dataPressure.setWellCode(wellCode); + dataPressure.setDevcode(devcode); + dataPressure.setPci(pressureDataMap.get("Q")); + dataPressure.setCell(Float.valueOf(pressureDataMap.get("V"))); + dataPressure.setTemperature(pressureDataMap.get("T")); + dataPressure.setPress(pressureDataMap.get("F")); + dataPressure.setUptime(dateFormat.format(uptime)); + dataPressure.setLogtime(dateFormat.format(new Date())); + this.baseMapper.insert(dataPressure); +// CacheUtil.serialBuf.put(devcode, pressureDataMap.get("F")); + return dataPressure; + } + + private void checkAlarm(DataPressure dataPressure) { + final Float ruleValue = this.baseMapper.getRuleValue("24"); + if (ruleValue == null) return; + if (!StringUtils.isEmpty(dataPressure.getTemperature()) && !dataPressure.getTemperature().equals("null")) { + if (Float.valueOf(dataPressure.getTemperature()) > ruleValue) { + this.baseMapper.saveRecords(dataPressure.getTemperature(), new Date()); + } + } + } + +} diff --git a/src/main/java/com/casic/util/CacheUtil.java b/src/main/java/com/casic/util/CacheUtil.java new file mode 100644 index 0000000..5b89300 --- /dev/null +++ b/src/main/java/com/casic/util/CacheUtil.java @@ -0,0 +1,16 @@ +package com.casic.util; + +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import java.util.HashMap; +import java.util.Map; + +@Component +public class CacheUtil { + public static volatile Map serialBuf; + @PostConstruct + public void init() { + serialBuf = new HashMap<>(); + } +} diff --git a/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java b/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java new file mode 100644 index 0000000..085c7c3 --- /dev/null +++ b/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java @@ -0,0 +1,39 @@ +package com.casic.util; + +import java.util.HashMap; +import java.util.Map; + +public enum DeviceDataFieldTableEnum { + + TABLE_FIELD(new HashMap() { + { + put("data_dig", "ddata AS dataValue,devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gas", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gasliquid_gas", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gasliquid_liquid", "liquiddata AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gas_dector", "gas_sample_value AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_harmful_gas", "CONCAT(CO, ', ', CH4, ', ', H2S, ', ', O2) AS dataValue,devcode AS devcode,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_hydrant", "0 AS dataValue,devcode AS devcode,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_liquid", "liquiddata AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_noise", "ddata AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_temp_hum", "CONCAT(TEMPERATURE, ', ', HUMIDITY) AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_tube", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_wellcover", "descn AS dataValue,devcode AS devcode,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_temp_press", "press AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_pantilt", "concentration AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_wellcover_loca", "0 AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_wellplus", "0 AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_h2s", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_pressure", "re_val AS dataValue,devcode AS devcode,'' AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + } + }); + public Map tableNameMap; + + DeviceDataFieldTableEnum(Map tableNameMap) { + this.tableNameMap = tableNameMap; + } + + public Map getTableFieldMap() { + return tableNameMap; + } +} diff --git a/src/main/java/com/casic/util/DeviceDataTableEnum.java b/src/main/java/com/casic/util/DeviceDataTableEnum.java new file mode 100644 index 0000000..9698487 --- /dev/null +++ b/src/main/java/com/casic/util/DeviceDataTableEnum.java @@ -0,0 +1,81 @@ +package com.casic.util; + +import java.util.HashMap; + +/** + * @author cz + * @date 2022-7-15 + * 上传数据总记录数 + */ +public enum DeviceDataTableEnum { + + DATA_DIG("data_dig", "开挖监测仪"), + DATA_GAS("data_gas", "燃气智能监测终端"), + DATA_GASLIQUID("data_gasliquid_gas,data_gasliquid_liquid", "燃气智能监测终端(一体化)"), + DATA_GAS_DECTOR("data_gas_dector", "燃气探测仪"), + DATA_HARMFUL_GAS("data_harmful_gas", "有害气体监测仪"), + DATA_HYDRANT("data_hydrant", "消防栓防盗水监测仪"), + DATA_LIQUID("data_liquid", "液位监测仪"), + DATA_NOISE("data_noise", "噪声记录仪"), + DATA_PANTILT("data_pantilt", "激光甲烷云台"), + DATA_TEMP_HUM("data_temp_hum", "温湿度监测仪"), + DATA_TUBE("data_tube", "管盯"), + DATA_WELLCOVER("data_wellcover", "井盖状态监测仪"), + DATA_TEMP_PRESS("data_temp_press", "压力温度检测仪"), + DATA_WELLCOVER_LOCA("data_wellcover_loca", "井盖定位监测仪"), + DATA_WELLPLUS("data_wellplus", "井盖液位一体机"), + DATA_H2S("data_h2s", "硫化氢检测终端"), + DATA_PRESSURE("data_pressure", "压力检测终端"), + DEVICE_TYPE_TABLE(new HashMap() { + { + put(1, DATA_WELLCOVER); + put(2, DATA_LIQUID); + put(3, DATA_HARMFUL_GAS); + put(4, DATA_GAS); + put(5, DATA_TEMP_HUM); + put(6, DATA_DIG); + put(7, DATA_WELLCOVER_LOCA); + put(8, DATA_NOISE); + put(9, DATA_TEMP_PRESS); + put(10, DATA_GASLIQUID); + put(11, DATA_HYDRANT); + put(12, DATA_TUBE); + put(13, DATA_WELLPLUS); + put(14, DATA_H2S); + put(21, DATA_PANTILT); + put(22, DATA_H2S); + put(23, DATA_GAS); + put(24, DATA_TEMP_PRESS); + put(101, DATA_GAS_DECTOR); + } + }); + + String typeName; + String tableName; + + DeviceDataTableEnum(String tableName, String typeName) { + this.typeName = typeName; + this.tableName = tableName; + } + + public String getTypeName() { + return typeName; + } + + public String getTableName() { + return tableName; + } + + + public HashMap tableNameMap; + + DeviceDataTableEnum(HashMap tableNameMap) { + this.tableNameMap = tableNameMap; + } + + public HashMap getTableNameMap() { + return tableNameMap; + } + + +} diff --git a/src/main/java/com/casic/util/RedisCommonUtil.java b/src/main/java/com/casic/util/RedisCommonUtil.java new file mode 100644 index 0000000..a6ce9cf --- /dev/null +++ b/src/main/java/com/casic/util/RedisCommonUtil.java @@ -0,0 +1,29 @@ +package com.casic.util; + +import com.alibaba.fastjson.JSON; +import com.casic.model.CommConfigDTO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; + +import java.util.concurrent.TimeUnit; + +@Component +public class RedisCommonUtil { + + @Value("${casic.device.redis.invalid-time}") + private String invalidTime; + @Value("${casic.device.redis.config-prefix}") + private String configPrefix; + + @Autowired + private RedisTemplate redisTemplate; + + public void send(CommConfigDTO commConfigDTO,String devCode) { + redisTemplate.opsForValue().set(configPrefix+ devCode, + JSON.toJSONString(commConfigDTO), + Integer.valueOf(invalidTime), + TimeUnit.SECONDS); + } +} diff --git a/src/main/java/com/casic/util/SensorIdEum.java b/src/main/java/com/casic/util/SensorIdEum.java new file mode 100644 index 0000000..86b61db --- /dev/null +++ b/src/main/java/com/casic/util/SensorIdEum.java @@ -0,0 +1,30 @@ +package com.casic.util; + +import java.util.HashMap; +import java.util.Map; + +public enum SensorIdEum { + + SENSOR_MAP(new HashMap() { + { + put("燃气智能监测终端", "000044"); + put("有害气体监测仪", "000035"); + put("开挖监测仪", "000064"); + put("温湿度监测仪", "000055"); + put("噪声记录仪", "000032"); + put("液位监测仪", "000034"); + put("燃气智能监测终端(一体化)", "000065"); + put("管盯", "000080"); + } + }); + public Map sensorMap; + + SensorIdEum(Map sensorMap) { + this.sensorMap = sensorMap; + } + + public Map getSensorMap() { + return sensorMap; + } + +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..50f4a19 --- /dev/null +++ b/pom.xml @@ -0,0 +1,161 @@ + + + 4.0.0 + + com.casic + smartwell-demos + 1.0-SNAPSHOT + + + + + jdk-1.8 + + true + 1.8 + + + 1.8 + 1.8 + 1.8 + + + + + + + + + + org.springframework.boot + spring-boot-starter + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-tomcat + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-web + 2.4.5 + + + + + org.springframework.boot + spring-boot-starter-jdbc + 2.4.5 + + + + mysql + mysql-connector-java + 8.0.16 + compile + + + + com.baomidou + mybatis-plus-boot-starter + 3.4.3 + + + + org.projectlombok + lombok + 1.18.20 + + + + + com.alibaba + druid + 1.2.6 + + + + com.alibaba + fastjson + 1.2.73 + + + + commons-codec + commons-codec + 1.14 + + + + redis.clients + jedis + 3.1.0 + jar + + + + org.springframework.data + spring-data-redis + 2.4.8 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.3.RELEASE + + true + + com.casic.CasicApplication + exec + + + + + repackage + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + false + + + + + + + + src/main/resources + + + /config/*/* + /config/*-*.yml + + true + + + src/main/resources + + **/*.xml + + true + + + + + \ No newline at end of file diff --git a/src/main/java/com/casic/CasicApplication.java b/src/main/java/com/casic/CasicApplication.java new file mode 100644 index 0000000..9afd0b9 --- /dev/null +++ b/src/main/java/com/casic/CasicApplication.java @@ -0,0 +1,28 @@ +package com.casic; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.transaction.annotation.EnableTransactionManagement; + + +/** + * SpringBoot方式启动类 + * + * @author cz + * @Date 2022/09/08 14:28 + */ + +@Slf4j +@ComponentScan(basePackages= "com.casic.**") +@SpringBootApplication +public class CasicApplication { + public static void main(String[] args) { + log.info("CasicApplication is success!"); + SpringApplication.run(CasicApplication.class, args); + } +} diff --git a/src/main/java/com/casic/config/CorsConfig.java b/src/main/java/com/casic/config/CorsConfig.java new file mode 100644 index 0000000..7d19680 --- /dev/null +++ b/src/main/java/com/casic/config/CorsConfig.java @@ -0,0 +1,31 @@ +package com.casic.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +/** + * 基础框架 - 跨域请求配置 + */ +@Configuration +public class CorsConfig { + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", buildConfig()); + return new CorsFilter(source); + } + + private CorsConfiguration buildConfig() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + // 1允许任何域名使用 + corsConfiguration.addAllowedOrigin("*"); + // 2允许任何头 + corsConfiguration.addAllowedHeader("*"); + // 3允许任何方法(post、get等) + corsConfiguration.addAllowedMethod("*"); + return corsConfiguration; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/controller/AlarmController.java b/src/main/java/com/casic/controller/AlarmController.java new file mode 100644 index 0000000..957fc36 --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.model.AlarmConfigParam; +import com.casic.service.AlarmService; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/alarm") +public class AlarmController { + + private final AlarmService alarmService; + + public AlarmController(AlarmService alarmService) { + this.alarmService = alarmService; + } + + @RequestMapping("/records") + public Object getAlarmRecord(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "devcode",required =false) String devcode, + @RequestParam(value = "pageSize", required = true) Integer pageSize) { + return alarmService.getAlarmRecord(deviceType,currentIndex,pageSize,devcode); + } + + @RequestMapping("/batch/cancel") + public Object excuteAlramBatchCancel(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "devcode",required =false) String devcode) { + return alarmService.excuteAlramBatchCancel(deviceType,devcode); + } + + @RequestMapping("/config/add") + public Object addAlarmConfig(@RequestBody AlarmConfigParam alarmConfigParam) { + return alarmService.addAlarmConfig(alarmConfigParam); + } +} diff --git a/src/main/java/com/casic/controller/DeviceDataController.java b/src/main/java/com/casic/controller/DeviceDataController.java new file mode 100644 index 0000000..3498b04 --- /dev/null +++ b/src/main/java/com/casic/controller/DeviceDataController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.service.DeviceDataService; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/device") +public class DeviceDataController { + private final DeviceDataService deviceDataService; + + public DeviceDataController(DeviceDataService deviceDataService) { + this.deviceDataService = deviceDataService; + } + + @RequestMapping("/recent-data") + public Object getDeviceRecentData(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "recentNum", required = true) String recentNum, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceRecentData(deviceType, recentNum, devcode); + } + + @RequestMapping("/data/list-page") + public Object getDeviceListPage(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "pageSize", required = true) Integer pageSize, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceListPage(deviceType, currentIndex, pageSize, devcode); + } + + @RequestMapping("/level/{deviceType}") + public Object getLevelList(@PathVariable("deviceType")String deviceType) { + return deviceDataService.getLevel(deviceType); + } + +} diff --git a/src/main/java/com/casic/controller/ThirdDataController.java b/src/main/java/com/casic/controller/ThirdDataController.java new file mode 100644 index 0000000..b9b2b42 --- /dev/null +++ b/src/main/java/com/casic/controller/ThirdDataController.java @@ -0,0 +1,28 @@ +package com.casic.controller; + +import com.casic.model.PressureDataParam; +import com.casic.service.ThirdDataService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +@RestController +@RequestMapping("/push") +@Slf4j +public class ThirdDataController { + + private final ThirdDataService thirdDataService; + + public ThirdDataController(ThirdDataService thirdDataService) { + this.thirdDataService = thirdDataService; + } + + @RequestMapping("/pressure/data") + public Object getDeviceRecentData(@RequestBody PressureDataParam pressureData) { + return thirdDataService.getDeviceRecentData(pressureData); + } + +} diff --git a/src/main/java/com/casic/dao/AlarmMapper.java b/src/main/java/com/casic/dao/AlarmMapper.java new file mode 100644 index 0000000..a442e3a --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmMapper.java @@ -0,0 +1,28 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmLevel; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + +@Mapper +public interface AlarmMapper extends BaseMapper { + + List> getAlarmRecord(@Param("deviceType") String deviceType, + @Param("devcode") String devcode, + @Param("currentIndex") Integer currentIndex, @Param("pageSize") Integer pageSize); + + Integer getAlarmTotalRecord(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteAlramBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteJobBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + String getDeviceDevcode(@Param("deviceType") String deviceType); + + String getDeviceByDevcode(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + +} diff --git a/src/main/java/com/casic/dao/BusConfigMapper.java b/src/main/java/com/casic/dao/BusConfigMapper.java new file mode 100644 index 0000000..ccf76da --- /dev/null +++ b/src/main/java/com/casic/dao/BusConfigMapper.java @@ -0,0 +1,9 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.BusConfig; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface BusConfigMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/dao/DataPressureMapper.java b/src/main/java/com/casic/dao/DataPressureMapper.java new file mode 100644 index 0000000..05f4329 --- /dev/null +++ b/src/main/java/com/casic/dao/DataPressureMapper.java @@ -0,0 +1,19 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.DataPressure; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.Date; + +@Mapper +public interface DataPressureMapper extends BaseMapper { + + String getWellCode(@Param("devcode") String devcode); + + Float getRuleValue(@Param("deviceType") String deviceType); + + void saveRecords(@Param("reValue") String reValue, @Param("alarmTime") Date alarmTime); + +} diff --git a/src/main/java/com/casic/dao/DeviceDataMapper.java b/src/main/java/com/casic/dao/DeviceDataMapper.java new file mode 100644 index 0000000..d9e18a0 --- /dev/null +++ b/src/main/java/com/casic/dao/DeviceDataMapper.java @@ -0,0 +1,27 @@ +package com.casic.dao; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + + +@Mapper +public interface DeviceDataMapper { + + List> getDeviceRecentData(@Param("tableName") String tableName, + @Param("recentNum") String recentNum, + @Param("fields") String fields, + @Param("devcode") String devcode); + + Integer getDeviceDataTotal(@Param("tableName") String tableName, @Param("devcode") String devcode); + + List> getDeviceDataListPage(@Param("tableName") String tableName, + @Param("currentIndex") Integer currentIndex, + @Param("fields") String fields, + @Param("pageSize") Integer pageSize, + @Param("devcode") String devcode); + + String getLevelByType(@Param("deviceType")String deviceType); +} diff --git a/src/main/java/com/casic/model/AlarmConfigParam.java b/src/main/java/com/casic/model/AlarmConfigParam.java new file mode 100644 index 0000000..28150d6 --- /dev/null +++ b/src/main/java/com/casic/model/AlarmConfigParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class AlarmConfigParam { + private String deviceType; + private String thresholdVol; + private String collectInterval; + private String uploadCycle; + private String retryNum; + private String ip; + private String port; + private String devcode; +} diff --git a/src/main/java/com/casic/model/AlarmLevel.java b/src/main/java/com/casic/model/AlarmLevel.java new file mode 100644 index 0000000..d0909af --- /dev/null +++ b/src/main/java/com/casic/model/AlarmLevel.java @@ -0,0 +1,26 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("alarm_level") +public class AlarmLevel{ + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + private String name; + private String deviceType; + private Integer level; + private Float lowValue; + private Float highValue; + private String openAlarm; + private String openJob; + private Date ts; + private String tenantId; + +} diff --git a/src/main/java/com/casic/model/BusConfig.java b/src/main/java/com/casic/model/BusConfig.java new file mode 100644 index 0000000..c6b7b50 --- /dev/null +++ b/src/main/java/com/casic/model/BusConfig.java @@ -0,0 +1,27 @@ +package com.casic.model; + + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +import java.util.Date; + +@Data +public class BusConfig { + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + + private String deviceId; + private String framecontent; + private String sensorid; + private String sensorcode; + + private String status; + private Integer attemptsmax; + private Integer attemptscurrent; + private Date sendtime; + private Date writetime; + +} diff --git a/src/main/java/com/casic/model/CommConfigDTO.java b/src/main/java/com/casic/model/CommConfigDTO.java new file mode 100644 index 0000000..7da699c --- /dev/null +++ b/src/main/java/com/casic/model/CommConfigDTO.java @@ -0,0 +1,41 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class CommConfigDTO { + private String acqStart;//采集开始时间 + private Long interval;//采集时间间隔(分钟) + private Long period;//上传周期 + private Long times;//采集次数 + private Long repeat;//重传次数 + private String ip; + private Long port; + private Float thresh; + private Float height; + private String collect; + private String MultiCollect; + private String acqCycle; + private String upCycle; + private String sleepStartTime; + + private String acqStartFlow ; //流量采集开始时间 + private Long intervalFlow; //流量采集采集间隔(分) + private Long acqTimesFlow ;//流量采集次数 + private String upStartFlow; //流量上报开始时间 + private Long upTimesFlow; //流量上传次数 + private String acqStartNoise; //噪声采集开始时间 + private Long intervalNoise; //噪声采集采集间隔(分) + private Long acqTimesNoise;//噪声采集次数 + private String upStartNoise; //噪声上报开始时间 + private Long upTimesNoise ;//噪声上传次数 + private String acqStartPressure; //压力采集开始时间 + private Long intervalPressure;//压力采集采集间隔(分) + private Long acqTimesPressure; //压力采集次数 + private String upStartPressure; //压力上报开始时间 + private Long upTimesPressure; //压力上传次数 + private Float lowerLimitPressure; //压力报警下限 + private Float upperLimitPressure ;//压力报警下限 + private Long limitDig ;//开挖阈值 + private Float threshold ;//开挖阈值 +} diff --git a/src/main/java/com/casic/model/DataPressure.java b/src/main/java/com/casic/model/DataPressure.java new file mode 100644 index 0000000..8270c70 --- /dev/null +++ b/src/main/java/com/casic/model/DataPressure.java @@ -0,0 +1,33 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("data_temp_press") +public class DataPressure { + + @TableId(value = "ID", type = IdType.AUTO) + private String id; + private String wellCode; + private String devcode; + private Float cell; + private String temperature; + + private String press; + private String descn; + private String uptime; + private String logtime; + /** + * 信号强度 + */ + private String pci; + + private String rsrp; + private String snr; + +} diff --git a/src/main/java/com/casic/model/PressureDataParam.java b/src/main/java/com/casic/model/PressureDataParam.java new file mode 100644 index 0000000..f42770d --- /dev/null +++ b/src/main/java/com/casic/model/PressureDataParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class PressureDataParam { + private String flag; + private String deviceUserid; + private String parentUserId; + private Object sensorsDates; + private String time; + private String rawData; + private String deviceId; +} + diff --git a/src/main/java/com/casic/model/ResponseData.java b/src/main/java/com/casic/model/ResponseData.java new file mode 100644 index 0000000..245ab04 --- /dev/null +++ b/src/main/java/com/casic/model/ResponseData.java @@ -0,0 +1,18 @@ +package com.casic.model; + +import lombok.Data; + +/** + * @author cz + * @date 2022-8-12 + */ +@Data +public class ResponseData { + public static final String DEFAULT_SUCCESS_MESSAGE = "请求成功"; + public static final String DEFAULT_ERROR_MESSAGE = "网络异常"; + public static final Integer DEFAULT_SUCCESS_CODE = 200; + public static final Integer DEFAULT_ERROR_CODE = 500; + private Integer code; + private String message; + private Object data; +} \ No newline at end of file diff --git a/src/main/java/com/casic/service/AlarmService.java b/src/main/java/com/casic/service/AlarmService.java new file mode 100644 index 0000000..8516b41 --- /dev/null +++ b/src/main/java/com/casic/service/AlarmService.java @@ -0,0 +1,12 @@ +package com.casic.service; + +import com.casic.model.AlarmConfigParam; + +public interface AlarmService { + + Object getAlarmRecord(String deviceType,Integer currentIndex,Integer pageSize,String devcode); + + Object excuteAlramBatchCancel(String deviceType,String devcode); + + Object addAlarmConfig(AlarmConfigParam alarmConfig); +} diff --git a/src/main/java/com/casic/service/DeviceDataService.java b/src/main/java/com/casic/service/DeviceDataService.java new file mode 100644 index 0000000..db656c1 --- /dev/null +++ b/src/main/java/com/casic/service/DeviceDataService.java @@ -0,0 +1,10 @@ +package com.casic.service; + +public interface DeviceDataService { + + Object getDeviceRecentData(String deviceType, String recentNum, String devcode); + + Object getDeviceListPage(String deviceType, Integer currentIndex, Integer pageSize, String devcode); + + Object getLevel(String deviceType); +} diff --git a/src/main/java/com/casic/service/ThirdDataService.java b/src/main/java/com/casic/service/ThirdDataService.java new file mode 100644 index 0000000..795e0b2 --- /dev/null +++ b/src/main/java/com/casic/service/ThirdDataService.java @@ -0,0 +1,8 @@ +package com.casic.service; + +import com.casic.model.PressureDataParam; + +public interface ThirdDataService { + + Object getDeviceRecentData(PressureDataParam pressureData); +} diff --git a/src/main/java/com/casic/service/impl/AlarmServiceImple.java b/src/main/java/com/casic/service/impl/AlarmServiceImple.java new file mode 100644 index 0000000..a675207 --- /dev/null +++ b/src/main/java/com/casic/service/impl/AlarmServiceImple.java @@ -0,0 +1,127 @@ +package com.casic.service.impl; + +import com.alibaba.druid.util.StringUtils; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.dao.AlarmMapper; +import com.casic.dao.BusConfigMapper; +import com.casic.model.*; +import com.casic.service.AlarmService; +import com.casic.util.DeviceDataTableEnum; +import com.casic.util.RedisCommonUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Slf4j +@Service +public class AlarmServiceImple extends ServiceImpl implements AlarmService { + + @Resource + private BusConfigMapper busConfigMapper; + @Resource + private RedisCommonUtil redisCommonUtil; + + public Object getAlarmRecord(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { + ResponseData responseData = new ResponseData(); + try { + Map page = new HashMap(); + page.put("total", this.baseMapper.getAlarmTotalRecord(deviceType, devcode)); + List> alarmRecordList = this.baseMapper.getAlarmRecord(deviceType, devcode, pageSize * (currentIndex - 1), pageSize); + page.put("rows", alarmRecordList); + responseData.setData(alarmRecordList); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},异常信息{}", deviceType, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + @Transactional + public Object excuteAlramBatchCancel(String deviceType, String devcode) { + ResponseData responseData = new ResponseData(); + try { + this.baseMapper.excuteAlramBatchCancel(deviceType, devcode); + this.baseMapper.excuteJobBatchCancel(deviceType, devcode); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("批量消警异常,设备类型{},异常信息{}", deviceType, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + + @Transactional + public Object addAlarmConfig(AlarmConfigParam alarmConfigParam) { + ResponseData responseData = new ResponseData(); + try { + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + addBusConfig(alarmConfigParam); + addRuleConfig(alarmConfigParam); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("风险配置异常,异常信息{}", dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + private void addRuleConfig(AlarmConfigParam alarmConfigParam) { + Map alarmRuleMap = new HashMap(); + alarmRuleMap.put("DEVICE_TYPE", alarmConfigParam.getDeviceType()); + this.baseMapper.deleteByMap(alarmRuleMap); + AlarmLevel alarmRule = new AlarmLevel(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap() + .get(Integer.valueOf(alarmConfigParam.getDeviceType())); + alarmRule.setName(deviceDataTableEnum.getTypeName()); + alarmRule.setHighValue(Float.valueOf(alarmConfigParam.getThresholdVol())); + alarmRule.setTs(new Date()); + alarmRule.setLevel(1); + alarmRule.setDeviceType(alarmConfigParam.getDeviceType()); + this.baseMapper.insert(alarmRule); + } + + private void addBusConfig(AlarmConfigParam alarmConfigParam) { + String devcode = StringUtils.isEmpty(alarmConfigParam.getDevcode()) ? this.baseMapper.getDeviceDevcode(alarmConfigParam.getDeviceType()) : alarmConfigParam.getDevcode(); + sendBusConfig(alarmConfigParam, devcode); + String devcideId = this.baseMapper.getDeviceByDevcode(alarmConfigParam.getDeviceType(), devcode); + BusConfig busConfig = new BusConfig(); + busConfig.setDeviceId(devcideId); + busConfig.setFramecontent("3," + alarmConfigParam.getCollectInterval() + "," + alarmConfigParam.getCollectInterval() + + "," + alarmConfigParam.getRetryNum() + "," + alarmConfigParam.getIp() + "," + alarmConfigParam.getPort()); + busConfig.setSensorid(""); + busConfig.setStatus("0"); + busConfig.setAttemptscurrent(0); + busConfig.setWritetime(new Date()); + busConfig.setAttemptsmax(3); + busConfigMapper.insert(busConfig); + } + + private void sendBusConfig(AlarmConfigParam alarmConfigParam, String devcode) { + CommConfigDTO commConfigDTO = new CommConfigDTO(); + commConfigDTO.setInterval(StringUtils.isEmpty(alarmConfigParam.getCollectInterval()) ? 300 : Long.valueOf(alarmConfigParam.getCollectInterval())); + commConfigDTO.setRepeat(StringUtils.isEmpty(alarmConfigParam.getRetryNum()) ? 300 : Long.valueOf(alarmConfigParam.getRetryNum())); + commConfigDTO.setTimes(Long.valueOf(1)); +// commConfigDTO.setIp(alarmConfigParam.getIp()); +// commConfigDTO.setPort(StringUtils.isEmpty(alarmConfigParam.getPort()) ? 8080 : Long.valueOf(alarmConfigParam.getPort())); + commConfigDTO.setPeriod(StringUtils.isEmpty(alarmConfigParam.getUploadCycle()) ? 300 : Long.valueOf(alarmConfigParam.getUploadCycle())); +// commConfigDTO.setThresh(); + commConfigDTO.setThresh(StringUtils.isEmpty(alarmConfigParam.getThresholdVol()) ? 50: Float.valueOf(alarmConfigParam.getThresholdVol())); + redisCommonUtil.send(commConfigDTO, devcode); + } + + +} diff --git a/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java new file mode 100644 index 0000000..3de704b --- /dev/null +++ b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java @@ -0,0 +1,80 @@ +package com.casic.service.impl; + +import com.casic.dao.DeviceDataMapper; +import com.casic.model.ResponseData; +import com.casic.service.DeviceDataService; +import com.casic.util.DeviceDataFieldTableEnum; +import com.casic.util.DeviceDataTableEnum; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Service +@Slf4j +public class DeviceDataServiceImpl implements DeviceDataService { + + private final DeviceDataMapper deviceDataMapper; + + public DeviceDataServiceImpl(DeviceDataMapper deviceDataMapper) { + this.deviceDataMapper = deviceDataMapper; + } + + public Object getDeviceRecentData(String deviceType, String recentNum, String devcode) { + ResponseData responseData = new ResponseData(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); + try { + String tableName = deviceDataTableEnum.getTableName(); + String fields = DeviceDataFieldTableEnum.TABLE_FIELD.getTableFieldMap().get(tableName); + List> recentDataList = deviceDataMapper.getDeviceRecentData(tableName, recentNum, fields, devcode); + responseData.setData(recentDataList); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备最近数据查询异常,设备类型{},查询数目{},异常信息{}", deviceType, recentNum, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + public Object getDeviceListPage(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { + ResponseData responseData = new ResponseData(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); + try { + String tableName = deviceDataTableEnum.getTableName(); + String fields = DeviceDataFieldTableEnum.TABLE_FIELD.getTableFieldMap().get(tableName); + Map page = new HashMap(); + page.put("total", deviceDataMapper.getDeviceDataTotal(tableName, devcode)); + List> recentDataList = deviceDataMapper.getDeviceDataListPage(tableName, pageSize * (currentIndex - 1), fields, pageSize, devcode); + page.put("rows", recentDataList); + responseData.setData(page); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},当前页{},页大小{},异常信息{}", deviceType, currentIndex, pageSize, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + public Object getLevel(String deviceType) { + ResponseData responseData = new ResponseData(); + try { + String highValue = deviceDataMapper.getLevelByType(deviceType); + responseData.setData(highValue); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},当前页{},页大小{},异常信息{}"); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + +} diff --git a/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java new file mode 100644 index 0000000..6b23451 --- /dev/null +++ b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java @@ -0,0 +1,92 @@ +package com.casic.service.impl; + +import com.alibaba.druid.util.StringUtils; +import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.dao.DataPressureMapper; +import com.casic.model.DataPressure; +import com.casic.model.PressureDataParam; +import com.casic.model.ResponseData; +import com.casic.service.ThirdDataService; +import com.casic.util.CacheUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.stream.Collectors; + +@Service +@Slf4j +public class ThirdDataServiceImpl extends ServiceImpl implements ThirdDataService { + + private final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA); + + public Object getDeviceRecentData(PressureDataParam pressureDataParam) { + ResponseData responseData = new ResponseData(); + try { + batchSave(pressureDataParam); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备最近数据查询异常,设备类型{},异常信息{}", dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + private void batchSave(PressureDataParam pressureDataParam) { + String pressureDataJson = pressureDataParam.getRawData(); + log.info("----" + pressureDataJson); + Map pressureDataMap = JSON.parseObject(pressureDataJson, HashMap.class); + Date uptime = null; + try { + uptime = dateFormat.parse(String.valueOf(pressureDataMap.get("times"))); + } catch (Exception e) { + log.error("主题,采集时间解析异常,异常信息{}", e.getMessage()); + } + List> pressureDataList = (List>) pressureDataMap.get("sensorDatas"); + DataPressure dataPressure = initPrssureData(pressureDataList, uptime); + if (dataPressure == null) { + return; + } + checkAlarm(dataPressure); + } + + private DataPressure initPrssureData(List> pressureDataList, Date uptime) { + DataPressure dataPressure = new DataPressure(); + String devcode = pressureDataList.get(pressureDataList.size() - 1).get("str"); + Map pressureDataMap = pressureDataList.stream().collect( + Collectors.toMap(e -> String.valueOf(e.get("flag")), e -> String.valueOf(e.get("value"))) + ); +// if (CacheUtil.serialBuf.get(devcode)!=null&&CacheUtil.serialBuf.get(devcode).equals(pressureDataMap.get("F"))) { +// return null; +// } + String wellCode = this.baseMapper.getWellCode(devcode); + dataPressure.setWellCode(wellCode); + dataPressure.setDevcode(devcode); + dataPressure.setPci(pressureDataMap.get("Q")); + dataPressure.setCell(Float.valueOf(pressureDataMap.get("V"))); + dataPressure.setTemperature(pressureDataMap.get("T")); + dataPressure.setPress(pressureDataMap.get("F")); + dataPressure.setUptime(dateFormat.format(uptime)); + dataPressure.setLogtime(dateFormat.format(new Date())); + this.baseMapper.insert(dataPressure); +// CacheUtil.serialBuf.put(devcode, pressureDataMap.get("F")); + return dataPressure; + } + + private void checkAlarm(DataPressure dataPressure) { + final Float ruleValue = this.baseMapper.getRuleValue("24"); + if (ruleValue == null) return; + if (!StringUtils.isEmpty(dataPressure.getTemperature()) && !dataPressure.getTemperature().equals("null")) { + if (Float.valueOf(dataPressure.getTemperature()) > ruleValue) { + this.baseMapper.saveRecords(dataPressure.getTemperature(), new Date()); + } + } + } + +} diff --git a/src/main/java/com/casic/util/CacheUtil.java b/src/main/java/com/casic/util/CacheUtil.java new file mode 100644 index 0000000..5b89300 --- /dev/null +++ b/src/main/java/com/casic/util/CacheUtil.java @@ -0,0 +1,16 @@ +package com.casic.util; + +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import java.util.HashMap; +import java.util.Map; + +@Component +public class CacheUtil { + public static volatile Map serialBuf; + @PostConstruct + public void init() { + serialBuf = new HashMap<>(); + } +} diff --git a/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java b/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java new file mode 100644 index 0000000..085c7c3 --- /dev/null +++ b/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java @@ -0,0 +1,39 @@ +package com.casic.util; + +import java.util.HashMap; +import java.util.Map; + +public enum DeviceDataFieldTableEnum { + + TABLE_FIELD(new HashMap() { + { + put("data_dig", "ddata AS dataValue,devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gas", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gasliquid_gas", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gasliquid_liquid", "liquiddata AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gas_dector", "gas_sample_value AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_harmful_gas", "CONCAT(CO, ', ', CH4, ', ', H2S, ', ', O2) AS dataValue,devcode AS devcode,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_hydrant", "0 AS dataValue,devcode AS devcode,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_liquid", "liquiddata AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_noise", "ddata AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_temp_hum", "CONCAT(TEMPERATURE, ', ', HUMIDITY) AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_tube", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_wellcover", "descn AS dataValue,devcode AS devcode,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_temp_press", "press AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_pantilt", "concentration AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_wellcover_loca", "0 AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_wellplus", "0 AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_h2s", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_pressure", "re_val AS dataValue,devcode AS devcode,'' AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + } + }); + public Map tableNameMap; + + DeviceDataFieldTableEnum(Map tableNameMap) { + this.tableNameMap = tableNameMap; + } + + public Map getTableFieldMap() { + return tableNameMap; + } +} diff --git a/src/main/java/com/casic/util/DeviceDataTableEnum.java b/src/main/java/com/casic/util/DeviceDataTableEnum.java new file mode 100644 index 0000000..9698487 --- /dev/null +++ b/src/main/java/com/casic/util/DeviceDataTableEnum.java @@ -0,0 +1,81 @@ +package com.casic.util; + +import java.util.HashMap; + +/** + * @author cz + * @date 2022-7-15 + * 上传数据总记录数 + */ +public enum DeviceDataTableEnum { + + DATA_DIG("data_dig", "开挖监测仪"), + DATA_GAS("data_gas", "燃气智能监测终端"), + DATA_GASLIQUID("data_gasliquid_gas,data_gasliquid_liquid", "燃气智能监测终端(一体化)"), + DATA_GAS_DECTOR("data_gas_dector", "燃气探测仪"), + DATA_HARMFUL_GAS("data_harmful_gas", "有害气体监测仪"), + DATA_HYDRANT("data_hydrant", "消防栓防盗水监测仪"), + DATA_LIQUID("data_liquid", "液位监测仪"), + DATA_NOISE("data_noise", "噪声记录仪"), + DATA_PANTILT("data_pantilt", "激光甲烷云台"), + DATA_TEMP_HUM("data_temp_hum", "温湿度监测仪"), + DATA_TUBE("data_tube", "管盯"), + DATA_WELLCOVER("data_wellcover", "井盖状态监测仪"), + DATA_TEMP_PRESS("data_temp_press", "压力温度检测仪"), + DATA_WELLCOVER_LOCA("data_wellcover_loca", "井盖定位监测仪"), + DATA_WELLPLUS("data_wellplus", "井盖液位一体机"), + DATA_H2S("data_h2s", "硫化氢检测终端"), + DATA_PRESSURE("data_pressure", "压力检测终端"), + DEVICE_TYPE_TABLE(new HashMap() { + { + put(1, DATA_WELLCOVER); + put(2, DATA_LIQUID); + put(3, DATA_HARMFUL_GAS); + put(4, DATA_GAS); + put(5, DATA_TEMP_HUM); + put(6, DATA_DIG); + put(7, DATA_WELLCOVER_LOCA); + put(8, DATA_NOISE); + put(9, DATA_TEMP_PRESS); + put(10, DATA_GASLIQUID); + put(11, DATA_HYDRANT); + put(12, DATA_TUBE); + put(13, DATA_WELLPLUS); + put(14, DATA_H2S); + put(21, DATA_PANTILT); + put(22, DATA_H2S); + put(23, DATA_GAS); + put(24, DATA_TEMP_PRESS); + put(101, DATA_GAS_DECTOR); + } + }); + + String typeName; + String tableName; + + DeviceDataTableEnum(String tableName, String typeName) { + this.typeName = typeName; + this.tableName = tableName; + } + + public String getTypeName() { + return typeName; + } + + public String getTableName() { + return tableName; + } + + + public HashMap tableNameMap; + + DeviceDataTableEnum(HashMap tableNameMap) { + this.tableNameMap = tableNameMap; + } + + public HashMap getTableNameMap() { + return tableNameMap; + } + + +} diff --git a/src/main/java/com/casic/util/RedisCommonUtil.java b/src/main/java/com/casic/util/RedisCommonUtil.java new file mode 100644 index 0000000..a6ce9cf --- /dev/null +++ b/src/main/java/com/casic/util/RedisCommonUtil.java @@ -0,0 +1,29 @@ +package com.casic.util; + +import com.alibaba.fastjson.JSON; +import com.casic.model.CommConfigDTO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; + +import java.util.concurrent.TimeUnit; + +@Component +public class RedisCommonUtil { + + @Value("${casic.device.redis.invalid-time}") + private String invalidTime; + @Value("${casic.device.redis.config-prefix}") + private String configPrefix; + + @Autowired + private RedisTemplate redisTemplate; + + public void send(CommConfigDTO commConfigDTO,String devCode) { + redisTemplate.opsForValue().set(configPrefix+ devCode, + JSON.toJSONString(commConfigDTO), + Integer.valueOf(invalidTime), + TimeUnit.SECONDS); + } +} diff --git a/src/main/java/com/casic/util/SensorIdEum.java b/src/main/java/com/casic/util/SensorIdEum.java new file mode 100644 index 0000000..86b61db --- /dev/null +++ b/src/main/java/com/casic/util/SensorIdEum.java @@ -0,0 +1,30 @@ +package com.casic.util; + +import java.util.HashMap; +import java.util.Map; + +public enum SensorIdEum { + + SENSOR_MAP(new HashMap() { + { + put("燃气智能监测终端", "000044"); + put("有害气体监测仪", "000035"); + put("开挖监测仪", "000064"); + put("温湿度监测仪", "000055"); + put("噪声记录仪", "000032"); + put("液位监测仪", "000034"); + put("燃气智能监测终端(一体化)", "000065"); + put("管盯", "000080"); + } + }); + public Map sensorMap; + + SensorIdEum(Map sensorMap) { + this.sensorMap = sensorMap; + } + + public Map getSensorMap() { + return sensorMap; + } + +} diff --git a/src/main/java/com/casic/util/VerifyConstantUtil.java b/src/main/java/com/casic/util/VerifyConstantUtil.java new file mode 100644 index 0000000..90ee071 --- /dev/null +++ b/src/main/java/com/casic/util/VerifyConstantUtil.java @@ -0,0 +1,11 @@ +package com.casic.util; + +public class VerifyConstantUtil { + + public final static String DEVICE_TYPES = "22,23,24"; + + public static Boolean checkDeviceType(String devcieType) { + return DEVICE_TYPES.contains(devcieType) ? true : false; + } + +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..50f4a19 --- /dev/null +++ b/pom.xml @@ -0,0 +1,161 @@ + + + 4.0.0 + + com.casic + smartwell-demos + 1.0-SNAPSHOT + + + + + jdk-1.8 + + true + 1.8 + + + 1.8 + 1.8 + 1.8 + + + + + + + + + + org.springframework.boot + spring-boot-starter + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-tomcat + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-web + 2.4.5 + + + + + org.springframework.boot + spring-boot-starter-jdbc + 2.4.5 + + + + mysql + mysql-connector-java + 8.0.16 + compile + + + + com.baomidou + mybatis-plus-boot-starter + 3.4.3 + + + + org.projectlombok + lombok + 1.18.20 + + + + + com.alibaba + druid + 1.2.6 + + + + com.alibaba + fastjson + 1.2.73 + + + + commons-codec + commons-codec + 1.14 + + + + redis.clients + jedis + 3.1.0 + jar + + + + org.springframework.data + spring-data-redis + 2.4.8 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.3.RELEASE + + true + + com.casic.CasicApplication + exec + + + + + repackage + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + false + + + + + + + + src/main/resources + + + /config/*/* + /config/*-*.yml + + true + + + src/main/resources + + **/*.xml + + true + + + + + \ No newline at end of file diff --git a/src/main/java/com/casic/CasicApplication.java b/src/main/java/com/casic/CasicApplication.java new file mode 100644 index 0000000..9afd0b9 --- /dev/null +++ b/src/main/java/com/casic/CasicApplication.java @@ -0,0 +1,28 @@ +package com.casic; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.transaction.annotation.EnableTransactionManagement; + + +/** + * SpringBoot方式启动类 + * + * @author cz + * @Date 2022/09/08 14:28 + */ + +@Slf4j +@ComponentScan(basePackages= "com.casic.**") +@SpringBootApplication +public class CasicApplication { + public static void main(String[] args) { + log.info("CasicApplication is success!"); + SpringApplication.run(CasicApplication.class, args); + } +} diff --git a/src/main/java/com/casic/config/CorsConfig.java b/src/main/java/com/casic/config/CorsConfig.java new file mode 100644 index 0000000..7d19680 --- /dev/null +++ b/src/main/java/com/casic/config/CorsConfig.java @@ -0,0 +1,31 @@ +package com.casic.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +/** + * 基础框架 - 跨域请求配置 + */ +@Configuration +public class CorsConfig { + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", buildConfig()); + return new CorsFilter(source); + } + + private CorsConfiguration buildConfig() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + // 1允许任何域名使用 + corsConfiguration.addAllowedOrigin("*"); + // 2允许任何头 + corsConfiguration.addAllowedHeader("*"); + // 3允许任何方法(post、get等) + corsConfiguration.addAllowedMethod("*"); + return corsConfiguration; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/controller/AlarmController.java b/src/main/java/com/casic/controller/AlarmController.java new file mode 100644 index 0000000..957fc36 --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.model.AlarmConfigParam; +import com.casic.service.AlarmService; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/alarm") +public class AlarmController { + + private final AlarmService alarmService; + + public AlarmController(AlarmService alarmService) { + this.alarmService = alarmService; + } + + @RequestMapping("/records") + public Object getAlarmRecord(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "devcode",required =false) String devcode, + @RequestParam(value = "pageSize", required = true) Integer pageSize) { + return alarmService.getAlarmRecord(deviceType,currentIndex,pageSize,devcode); + } + + @RequestMapping("/batch/cancel") + public Object excuteAlramBatchCancel(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "devcode",required =false) String devcode) { + return alarmService.excuteAlramBatchCancel(deviceType,devcode); + } + + @RequestMapping("/config/add") + public Object addAlarmConfig(@RequestBody AlarmConfigParam alarmConfigParam) { + return alarmService.addAlarmConfig(alarmConfigParam); + } +} diff --git a/src/main/java/com/casic/controller/DeviceDataController.java b/src/main/java/com/casic/controller/DeviceDataController.java new file mode 100644 index 0000000..3498b04 --- /dev/null +++ b/src/main/java/com/casic/controller/DeviceDataController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.service.DeviceDataService; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/device") +public class DeviceDataController { + private final DeviceDataService deviceDataService; + + public DeviceDataController(DeviceDataService deviceDataService) { + this.deviceDataService = deviceDataService; + } + + @RequestMapping("/recent-data") + public Object getDeviceRecentData(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "recentNum", required = true) String recentNum, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceRecentData(deviceType, recentNum, devcode); + } + + @RequestMapping("/data/list-page") + public Object getDeviceListPage(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "pageSize", required = true) Integer pageSize, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceListPage(deviceType, currentIndex, pageSize, devcode); + } + + @RequestMapping("/level/{deviceType}") + public Object getLevelList(@PathVariable("deviceType")String deviceType) { + return deviceDataService.getLevel(deviceType); + } + +} diff --git a/src/main/java/com/casic/controller/ThirdDataController.java b/src/main/java/com/casic/controller/ThirdDataController.java new file mode 100644 index 0000000..b9b2b42 --- /dev/null +++ b/src/main/java/com/casic/controller/ThirdDataController.java @@ -0,0 +1,28 @@ +package com.casic.controller; + +import com.casic.model.PressureDataParam; +import com.casic.service.ThirdDataService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +@RestController +@RequestMapping("/push") +@Slf4j +public class ThirdDataController { + + private final ThirdDataService thirdDataService; + + public ThirdDataController(ThirdDataService thirdDataService) { + this.thirdDataService = thirdDataService; + } + + @RequestMapping("/pressure/data") + public Object getDeviceRecentData(@RequestBody PressureDataParam pressureData) { + return thirdDataService.getDeviceRecentData(pressureData); + } + +} diff --git a/src/main/java/com/casic/dao/AlarmMapper.java b/src/main/java/com/casic/dao/AlarmMapper.java new file mode 100644 index 0000000..a442e3a --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmMapper.java @@ -0,0 +1,28 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmLevel; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + +@Mapper +public interface AlarmMapper extends BaseMapper { + + List> getAlarmRecord(@Param("deviceType") String deviceType, + @Param("devcode") String devcode, + @Param("currentIndex") Integer currentIndex, @Param("pageSize") Integer pageSize); + + Integer getAlarmTotalRecord(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteAlramBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteJobBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + String getDeviceDevcode(@Param("deviceType") String deviceType); + + String getDeviceByDevcode(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + +} diff --git a/src/main/java/com/casic/dao/BusConfigMapper.java b/src/main/java/com/casic/dao/BusConfigMapper.java new file mode 100644 index 0000000..ccf76da --- /dev/null +++ b/src/main/java/com/casic/dao/BusConfigMapper.java @@ -0,0 +1,9 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.BusConfig; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface BusConfigMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/dao/DataPressureMapper.java b/src/main/java/com/casic/dao/DataPressureMapper.java new file mode 100644 index 0000000..05f4329 --- /dev/null +++ b/src/main/java/com/casic/dao/DataPressureMapper.java @@ -0,0 +1,19 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.DataPressure; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.Date; + +@Mapper +public interface DataPressureMapper extends BaseMapper { + + String getWellCode(@Param("devcode") String devcode); + + Float getRuleValue(@Param("deviceType") String deviceType); + + void saveRecords(@Param("reValue") String reValue, @Param("alarmTime") Date alarmTime); + +} diff --git a/src/main/java/com/casic/dao/DeviceDataMapper.java b/src/main/java/com/casic/dao/DeviceDataMapper.java new file mode 100644 index 0000000..d9e18a0 --- /dev/null +++ b/src/main/java/com/casic/dao/DeviceDataMapper.java @@ -0,0 +1,27 @@ +package com.casic.dao; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + + +@Mapper +public interface DeviceDataMapper { + + List> getDeviceRecentData(@Param("tableName") String tableName, + @Param("recentNum") String recentNum, + @Param("fields") String fields, + @Param("devcode") String devcode); + + Integer getDeviceDataTotal(@Param("tableName") String tableName, @Param("devcode") String devcode); + + List> getDeviceDataListPage(@Param("tableName") String tableName, + @Param("currentIndex") Integer currentIndex, + @Param("fields") String fields, + @Param("pageSize") Integer pageSize, + @Param("devcode") String devcode); + + String getLevelByType(@Param("deviceType")String deviceType); +} diff --git a/src/main/java/com/casic/model/AlarmConfigParam.java b/src/main/java/com/casic/model/AlarmConfigParam.java new file mode 100644 index 0000000..28150d6 --- /dev/null +++ b/src/main/java/com/casic/model/AlarmConfigParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class AlarmConfigParam { + private String deviceType; + private String thresholdVol; + private String collectInterval; + private String uploadCycle; + private String retryNum; + private String ip; + private String port; + private String devcode; +} diff --git a/src/main/java/com/casic/model/AlarmLevel.java b/src/main/java/com/casic/model/AlarmLevel.java new file mode 100644 index 0000000..d0909af --- /dev/null +++ b/src/main/java/com/casic/model/AlarmLevel.java @@ -0,0 +1,26 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("alarm_level") +public class AlarmLevel{ + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + private String name; + private String deviceType; + private Integer level; + private Float lowValue; + private Float highValue; + private String openAlarm; + private String openJob; + private Date ts; + private String tenantId; + +} diff --git a/src/main/java/com/casic/model/BusConfig.java b/src/main/java/com/casic/model/BusConfig.java new file mode 100644 index 0000000..c6b7b50 --- /dev/null +++ b/src/main/java/com/casic/model/BusConfig.java @@ -0,0 +1,27 @@ +package com.casic.model; + + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +import java.util.Date; + +@Data +public class BusConfig { + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + + private String deviceId; + private String framecontent; + private String sensorid; + private String sensorcode; + + private String status; + private Integer attemptsmax; + private Integer attemptscurrent; + private Date sendtime; + private Date writetime; + +} diff --git a/src/main/java/com/casic/model/CommConfigDTO.java b/src/main/java/com/casic/model/CommConfigDTO.java new file mode 100644 index 0000000..7da699c --- /dev/null +++ b/src/main/java/com/casic/model/CommConfigDTO.java @@ -0,0 +1,41 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class CommConfigDTO { + private String acqStart;//采集开始时间 + private Long interval;//采集时间间隔(分钟) + private Long period;//上传周期 + private Long times;//采集次数 + private Long repeat;//重传次数 + private String ip; + private Long port; + private Float thresh; + private Float height; + private String collect; + private String MultiCollect; + private String acqCycle; + private String upCycle; + private String sleepStartTime; + + private String acqStartFlow ; //流量采集开始时间 + private Long intervalFlow; //流量采集采集间隔(分) + private Long acqTimesFlow ;//流量采集次数 + private String upStartFlow; //流量上报开始时间 + private Long upTimesFlow; //流量上传次数 + private String acqStartNoise; //噪声采集开始时间 + private Long intervalNoise; //噪声采集采集间隔(分) + private Long acqTimesNoise;//噪声采集次数 + private String upStartNoise; //噪声上报开始时间 + private Long upTimesNoise ;//噪声上传次数 + private String acqStartPressure; //压力采集开始时间 + private Long intervalPressure;//压力采集采集间隔(分) + private Long acqTimesPressure; //压力采集次数 + private String upStartPressure; //压力上报开始时间 + private Long upTimesPressure; //压力上传次数 + private Float lowerLimitPressure; //压力报警下限 + private Float upperLimitPressure ;//压力报警下限 + private Long limitDig ;//开挖阈值 + private Float threshold ;//开挖阈值 +} diff --git a/src/main/java/com/casic/model/DataPressure.java b/src/main/java/com/casic/model/DataPressure.java new file mode 100644 index 0000000..8270c70 --- /dev/null +++ b/src/main/java/com/casic/model/DataPressure.java @@ -0,0 +1,33 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("data_temp_press") +public class DataPressure { + + @TableId(value = "ID", type = IdType.AUTO) + private String id; + private String wellCode; + private String devcode; + private Float cell; + private String temperature; + + private String press; + private String descn; + private String uptime; + private String logtime; + /** + * 信号强度 + */ + private String pci; + + private String rsrp; + private String snr; + +} diff --git a/src/main/java/com/casic/model/PressureDataParam.java b/src/main/java/com/casic/model/PressureDataParam.java new file mode 100644 index 0000000..f42770d --- /dev/null +++ b/src/main/java/com/casic/model/PressureDataParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class PressureDataParam { + private String flag; + private String deviceUserid; + private String parentUserId; + private Object sensorsDates; + private String time; + private String rawData; + private String deviceId; +} + diff --git a/src/main/java/com/casic/model/ResponseData.java b/src/main/java/com/casic/model/ResponseData.java new file mode 100644 index 0000000..245ab04 --- /dev/null +++ b/src/main/java/com/casic/model/ResponseData.java @@ -0,0 +1,18 @@ +package com.casic.model; + +import lombok.Data; + +/** + * @author cz + * @date 2022-8-12 + */ +@Data +public class ResponseData { + public static final String DEFAULT_SUCCESS_MESSAGE = "请求成功"; + public static final String DEFAULT_ERROR_MESSAGE = "网络异常"; + public static final Integer DEFAULT_SUCCESS_CODE = 200; + public static final Integer DEFAULT_ERROR_CODE = 500; + private Integer code; + private String message; + private Object data; +} \ No newline at end of file diff --git a/src/main/java/com/casic/service/AlarmService.java b/src/main/java/com/casic/service/AlarmService.java new file mode 100644 index 0000000..8516b41 --- /dev/null +++ b/src/main/java/com/casic/service/AlarmService.java @@ -0,0 +1,12 @@ +package com.casic.service; + +import com.casic.model.AlarmConfigParam; + +public interface AlarmService { + + Object getAlarmRecord(String deviceType,Integer currentIndex,Integer pageSize,String devcode); + + Object excuteAlramBatchCancel(String deviceType,String devcode); + + Object addAlarmConfig(AlarmConfigParam alarmConfig); +} diff --git a/src/main/java/com/casic/service/DeviceDataService.java b/src/main/java/com/casic/service/DeviceDataService.java new file mode 100644 index 0000000..db656c1 --- /dev/null +++ b/src/main/java/com/casic/service/DeviceDataService.java @@ -0,0 +1,10 @@ +package com.casic.service; + +public interface DeviceDataService { + + Object getDeviceRecentData(String deviceType, String recentNum, String devcode); + + Object getDeviceListPage(String deviceType, Integer currentIndex, Integer pageSize, String devcode); + + Object getLevel(String deviceType); +} diff --git a/src/main/java/com/casic/service/ThirdDataService.java b/src/main/java/com/casic/service/ThirdDataService.java new file mode 100644 index 0000000..795e0b2 --- /dev/null +++ b/src/main/java/com/casic/service/ThirdDataService.java @@ -0,0 +1,8 @@ +package com.casic.service; + +import com.casic.model.PressureDataParam; + +public interface ThirdDataService { + + Object getDeviceRecentData(PressureDataParam pressureData); +} diff --git a/src/main/java/com/casic/service/impl/AlarmServiceImple.java b/src/main/java/com/casic/service/impl/AlarmServiceImple.java new file mode 100644 index 0000000..a675207 --- /dev/null +++ b/src/main/java/com/casic/service/impl/AlarmServiceImple.java @@ -0,0 +1,127 @@ +package com.casic.service.impl; + +import com.alibaba.druid.util.StringUtils; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.dao.AlarmMapper; +import com.casic.dao.BusConfigMapper; +import com.casic.model.*; +import com.casic.service.AlarmService; +import com.casic.util.DeviceDataTableEnum; +import com.casic.util.RedisCommonUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Slf4j +@Service +public class AlarmServiceImple extends ServiceImpl implements AlarmService { + + @Resource + private BusConfigMapper busConfigMapper; + @Resource + private RedisCommonUtil redisCommonUtil; + + public Object getAlarmRecord(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { + ResponseData responseData = new ResponseData(); + try { + Map page = new HashMap(); + page.put("total", this.baseMapper.getAlarmTotalRecord(deviceType, devcode)); + List> alarmRecordList = this.baseMapper.getAlarmRecord(deviceType, devcode, pageSize * (currentIndex - 1), pageSize); + page.put("rows", alarmRecordList); + responseData.setData(alarmRecordList); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},异常信息{}", deviceType, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + @Transactional + public Object excuteAlramBatchCancel(String deviceType, String devcode) { + ResponseData responseData = new ResponseData(); + try { + this.baseMapper.excuteAlramBatchCancel(deviceType, devcode); + this.baseMapper.excuteJobBatchCancel(deviceType, devcode); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("批量消警异常,设备类型{},异常信息{}", deviceType, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + + @Transactional + public Object addAlarmConfig(AlarmConfigParam alarmConfigParam) { + ResponseData responseData = new ResponseData(); + try { + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + addBusConfig(alarmConfigParam); + addRuleConfig(alarmConfigParam); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("风险配置异常,异常信息{}", dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + private void addRuleConfig(AlarmConfigParam alarmConfigParam) { + Map alarmRuleMap = new HashMap(); + alarmRuleMap.put("DEVICE_TYPE", alarmConfigParam.getDeviceType()); + this.baseMapper.deleteByMap(alarmRuleMap); + AlarmLevel alarmRule = new AlarmLevel(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap() + .get(Integer.valueOf(alarmConfigParam.getDeviceType())); + alarmRule.setName(deviceDataTableEnum.getTypeName()); + alarmRule.setHighValue(Float.valueOf(alarmConfigParam.getThresholdVol())); + alarmRule.setTs(new Date()); + alarmRule.setLevel(1); + alarmRule.setDeviceType(alarmConfigParam.getDeviceType()); + this.baseMapper.insert(alarmRule); + } + + private void addBusConfig(AlarmConfigParam alarmConfigParam) { + String devcode = StringUtils.isEmpty(alarmConfigParam.getDevcode()) ? this.baseMapper.getDeviceDevcode(alarmConfigParam.getDeviceType()) : alarmConfigParam.getDevcode(); + sendBusConfig(alarmConfigParam, devcode); + String devcideId = this.baseMapper.getDeviceByDevcode(alarmConfigParam.getDeviceType(), devcode); + BusConfig busConfig = new BusConfig(); + busConfig.setDeviceId(devcideId); + busConfig.setFramecontent("3," + alarmConfigParam.getCollectInterval() + "," + alarmConfigParam.getCollectInterval() + + "," + alarmConfigParam.getRetryNum() + "," + alarmConfigParam.getIp() + "," + alarmConfigParam.getPort()); + busConfig.setSensorid(""); + busConfig.setStatus("0"); + busConfig.setAttemptscurrent(0); + busConfig.setWritetime(new Date()); + busConfig.setAttemptsmax(3); + busConfigMapper.insert(busConfig); + } + + private void sendBusConfig(AlarmConfigParam alarmConfigParam, String devcode) { + CommConfigDTO commConfigDTO = new CommConfigDTO(); + commConfigDTO.setInterval(StringUtils.isEmpty(alarmConfigParam.getCollectInterval()) ? 300 : Long.valueOf(alarmConfigParam.getCollectInterval())); + commConfigDTO.setRepeat(StringUtils.isEmpty(alarmConfigParam.getRetryNum()) ? 300 : Long.valueOf(alarmConfigParam.getRetryNum())); + commConfigDTO.setTimes(Long.valueOf(1)); +// commConfigDTO.setIp(alarmConfigParam.getIp()); +// commConfigDTO.setPort(StringUtils.isEmpty(alarmConfigParam.getPort()) ? 8080 : Long.valueOf(alarmConfigParam.getPort())); + commConfigDTO.setPeriod(StringUtils.isEmpty(alarmConfigParam.getUploadCycle()) ? 300 : Long.valueOf(alarmConfigParam.getUploadCycle())); +// commConfigDTO.setThresh(); + commConfigDTO.setThresh(StringUtils.isEmpty(alarmConfigParam.getThresholdVol()) ? 50: Float.valueOf(alarmConfigParam.getThresholdVol())); + redisCommonUtil.send(commConfigDTO, devcode); + } + + +} diff --git a/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java new file mode 100644 index 0000000..3de704b --- /dev/null +++ b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java @@ -0,0 +1,80 @@ +package com.casic.service.impl; + +import com.casic.dao.DeviceDataMapper; +import com.casic.model.ResponseData; +import com.casic.service.DeviceDataService; +import com.casic.util.DeviceDataFieldTableEnum; +import com.casic.util.DeviceDataTableEnum; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Service +@Slf4j +public class DeviceDataServiceImpl implements DeviceDataService { + + private final DeviceDataMapper deviceDataMapper; + + public DeviceDataServiceImpl(DeviceDataMapper deviceDataMapper) { + this.deviceDataMapper = deviceDataMapper; + } + + public Object getDeviceRecentData(String deviceType, String recentNum, String devcode) { + ResponseData responseData = new ResponseData(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); + try { + String tableName = deviceDataTableEnum.getTableName(); + String fields = DeviceDataFieldTableEnum.TABLE_FIELD.getTableFieldMap().get(tableName); + List> recentDataList = deviceDataMapper.getDeviceRecentData(tableName, recentNum, fields, devcode); + responseData.setData(recentDataList); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备最近数据查询异常,设备类型{},查询数目{},异常信息{}", deviceType, recentNum, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + public Object getDeviceListPage(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { + ResponseData responseData = new ResponseData(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); + try { + String tableName = deviceDataTableEnum.getTableName(); + String fields = DeviceDataFieldTableEnum.TABLE_FIELD.getTableFieldMap().get(tableName); + Map page = new HashMap(); + page.put("total", deviceDataMapper.getDeviceDataTotal(tableName, devcode)); + List> recentDataList = deviceDataMapper.getDeviceDataListPage(tableName, pageSize * (currentIndex - 1), fields, pageSize, devcode); + page.put("rows", recentDataList); + responseData.setData(page); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},当前页{},页大小{},异常信息{}", deviceType, currentIndex, pageSize, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + public Object getLevel(String deviceType) { + ResponseData responseData = new ResponseData(); + try { + String highValue = deviceDataMapper.getLevelByType(deviceType); + responseData.setData(highValue); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},当前页{},页大小{},异常信息{}"); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + +} diff --git a/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java new file mode 100644 index 0000000..6b23451 --- /dev/null +++ b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java @@ -0,0 +1,92 @@ +package com.casic.service.impl; + +import com.alibaba.druid.util.StringUtils; +import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.dao.DataPressureMapper; +import com.casic.model.DataPressure; +import com.casic.model.PressureDataParam; +import com.casic.model.ResponseData; +import com.casic.service.ThirdDataService; +import com.casic.util.CacheUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.stream.Collectors; + +@Service +@Slf4j +public class ThirdDataServiceImpl extends ServiceImpl implements ThirdDataService { + + private final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA); + + public Object getDeviceRecentData(PressureDataParam pressureDataParam) { + ResponseData responseData = new ResponseData(); + try { + batchSave(pressureDataParam); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备最近数据查询异常,设备类型{},异常信息{}", dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + private void batchSave(PressureDataParam pressureDataParam) { + String pressureDataJson = pressureDataParam.getRawData(); + log.info("----" + pressureDataJson); + Map pressureDataMap = JSON.parseObject(pressureDataJson, HashMap.class); + Date uptime = null; + try { + uptime = dateFormat.parse(String.valueOf(pressureDataMap.get("times"))); + } catch (Exception e) { + log.error("主题,采集时间解析异常,异常信息{}", e.getMessage()); + } + List> pressureDataList = (List>) pressureDataMap.get("sensorDatas"); + DataPressure dataPressure = initPrssureData(pressureDataList, uptime); + if (dataPressure == null) { + return; + } + checkAlarm(dataPressure); + } + + private DataPressure initPrssureData(List> pressureDataList, Date uptime) { + DataPressure dataPressure = new DataPressure(); + String devcode = pressureDataList.get(pressureDataList.size() - 1).get("str"); + Map pressureDataMap = pressureDataList.stream().collect( + Collectors.toMap(e -> String.valueOf(e.get("flag")), e -> String.valueOf(e.get("value"))) + ); +// if (CacheUtil.serialBuf.get(devcode)!=null&&CacheUtil.serialBuf.get(devcode).equals(pressureDataMap.get("F"))) { +// return null; +// } + String wellCode = this.baseMapper.getWellCode(devcode); + dataPressure.setWellCode(wellCode); + dataPressure.setDevcode(devcode); + dataPressure.setPci(pressureDataMap.get("Q")); + dataPressure.setCell(Float.valueOf(pressureDataMap.get("V"))); + dataPressure.setTemperature(pressureDataMap.get("T")); + dataPressure.setPress(pressureDataMap.get("F")); + dataPressure.setUptime(dateFormat.format(uptime)); + dataPressure.setLogtime(dateFormat.format(new Date())); + this.baseMapper.insert(dataPressure); +// CacheUtil.serialBuf.put(devcode, pressureDataMap.get("F")); + return dataPressure; + } + + private void checkAlarm(DataPressure dataPressure) { + final Float ruleValue = this.baseMapper.getRuleValue("24"); + if (ruleValue == null) return; + if (!StringUtils.isEmpty(dataPressure.getTemperature()) && !dataPressure.getTemperature().equals("null")) { + if (Float.valueOf(dataPressure.getTemperature()) > ruleValue) { + this.baseMapper.saveRecords(dataPressure.getTemperature(), new Date()); + } + } + } + +} diff --git a/src/main/java/com/casic/util/CacheUtil.java b/src/main/java/com/casic/util/CacheUtil.java new file mode 100644 index 0000000..5b89300 --- /dev/null +++ b/src/main/java/com/casic/util/CacheUtil.java @@ -0,0 +1,16 @@ +package com.casic.util; + +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import java.util.HashMap; +import java.util.Map; + +@Component +public class CacheUtil { + public static volatile Map serialBuf; + @PostConstruct + public void init() { + serialBuf = new HashMap<>(); + } +} diff --git a/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java b/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java new file mode 100644 index 0000000..085c7c3 --- /dev/null +++ b/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java @@ -0,0 +1,39 @@ +package com.casic.util; + +import java.util.HashMap; +import java.util.Map; + +public enum DeviceDataFieldTableEnum { + + TABLE_FIELD(new HashMap() { + { + put("data_dig", "ddata AS dataValue,devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gas", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gasliquid_gas", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gasliquid_liquid", "liquiddata AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gas_dector", "gas_sample_value AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_harmful_gas", "CONCAT(CO, ', ', CH4, ', ', H2S, ', ', O2) AS dataValue,devcode AS devcode,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_hydrant", "0 AS dataValue,devcode AS devcode,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_liquid", "liquiddata AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_noise", "ddata AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_temp_hum", "CONCAT(TEMPERATURE, ', ', HUMIDITY) AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_tube", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_wellcover", "descn AS dataValue,devcode AS devcode,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_temp_press", "press AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_pantilt", "concentration AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_wellcover_loca", "0 AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_wellplus", "0 AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_h2s", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_pressure", "re_val AS dataValue,devcode AS devcode,'' AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + } + }); + public Map tableNameMap; + + DeviceDataFieldTableEnum(Map tableNameMap) { + this.tableNameMap = tableNameMap; + } + + public Map getTableFieldMap() { + return tableNameMap; + } +} diff --git a/src/main/java/com/casic/util/DeviceDataTableEnum.java b/src/main/java/com/casic/util/DeviceDataTableEnum.java new file mode 100644 index 0000000..9698487 --- /dev/null +++ b/src/main/java/com/casic/util/DeviceDataTableEnum.java @@ -0,0 +1,81 @@ +package com.casic.util; + +import java.util.HashMap; + +/** + * @author cz + * @date 2022-7-15 + * 上传数据总记录数 + */ +public enum DeviceDataTableEnum { + + DATA_DIG("data_dig", "开挖监测仪"), + DATA_GAS("data_gas", "燃气智能监测终端"), + DATA_GASLIQUID("data_gasliquid_gas,data_gasliquid_liquid", "燃气智能监测终端(一体化)"), + DATA_GAS_DECTOR("data_gas_dector", "燃气探测仪"), + DATA_HARMFUL_GAS("data_harmful_gas", "有害气体监测仪"), + DATA_HYDRANT("data_hydrant", "消防栓防盗水监测仪"), + DATA_LIQUID("data_liquid", "液位监测仪"), + DATA_NOISE("data_noise", "噪声记录仪"), + DATA_PANTILT("data_pantilt", "激光甲烷云台"), + DATA_TEMP_HUM("data_temp_hum", "温湿度监测仪"), + DATA_TUBE("data_tube", "管盯"), + DATA_WELLCOVER("data_wellcover", "井盖状态监测仪"), + DATA_TEMP_PRESS("data_temp_press", "压力温度检测仪"), + DATA_WELLCOVER_LOCA("data_wellcover_loca", "井盖定位监测仪"), + DATA_WELLPLUS("data_wellplus", "井盖液位一体机"), + DATA_H2S("data_h2s", "硫化氢检测终端"), + DATA_PRESSURE("data_pressure", "压力检测终端"), + DEVICE_TYPE_TABLE(new HashMap() { + { + put(1, DATA_WELLCOVER); + put(2, DATA_LIQUID); + put(3, DATA_HARMFUL_GAS); + put(4, DATA_GAS); + put(5, DATA_TEMP_HUM); + put(6, DATA_DIG); + put(7, DATA_WELLCOVER_LOCA); + put(8, DATA_NOISE); + put(9, DATA_TEMP_PRESS); + put(10, DATA_GASLIQUID); + put(11, DATA_HYDRANT); + put(12, DATA_TUBE); + put(13, DATA_WELLPLUS); + put(14, DATA_H2S); + put(21, DATA_PANTILT); + put(22, DATA_H2S); + put(23, DATA_GAS); + put(24, DATA_TEMP_PRESS); + put(101, DATA_GAS_DECTOR); + } + }); + + String typeName; + String tableName; + + DeviceDataTableEnum(String tableName, String typeName) { + this.typeName = typeName; + this.tableName = tableName; + } + + public String getTypeName() { + return typeName; + } + + public String getTableName() { + return tableName; + } + + + public HashMap tableNameMap; + + DeviceDataTableEnum(HashMap tableNameMap) { + this.tableNameMap = tableNameMap; + } + + public HashMap getTableNameMap() { + return tableNameMap; + } + + +} diff --git a/src/main/java/com/casic/util/RedisCommonUtil.java b/src/main/java/com/casic/util/RedisCommonUtil.java new file mode 100644 index 0000000..a6ce9cf --- /dev/null +++ b/src/main/java/com/casic/util/RedisCommonUtil.java @@ -0,0 +1,29 @@ +package com.casic.util; + +import com.alibaba.fastjson.JSON; +import com.casic.model.CommConfigDTO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; + +import java.util.concurrent.TimeUnit; + +@Component +public class RedisCommonUtil { + + @Value("${casic.device.redis.invalid-time}") + private String invalidTime; + @Value("${casic.device.redis.config-prefix}") + private String configPrefix; + + @Autowired + private RedisTemplate redisTemplate; + + public void send(CommConfigDTO commConfigDTO,String devCode) { + redisTemplate.opsForValue().set(configPrefix+ devCode, + JSON.toJSONString(commConfigDTO), + Integer.valueOf(invalidTime), + TimeUnit.SECONDS); + } +} diff --git a/src/main/java/com/casic/util/SensorIdEum.java b/src/main/java/com/casic/util/SensorIdEum.java new file mode 100644 index 0000000..86b61db --- /dev/null +++ b/src/main/java/com/casic/util/SensorIdEum.java @@ -0,0 +1,30 @@ +package com.casic.util; + +import java.util.HashMap; +import java.util.Map; + +public enum SensorIdEum { + + SENSOR_MAP(new HashMap() { + { + put("燃气智能监测终端", "000044"); + put("有害气体监测仪", "000035"); + put("开挖监测仪", "000064"); + put("温湿度监测仪", "000055"); + put("噪声记录仪", "000032"); + put("液位监测仪", "000034"); + put("燃气智能监测终端(一体化)", "000065"); + put("管盯", "000080"); + } + }); + public Map sensorMap; + + SensorIdEum(Map sensorMap) { + this.sensorMap = sensorMap; + } + + public Map getSensorMap() { + return sensorMap; + } + +} diff --git a/src/main/java/com/casic/util/VerifyConstantUtil.java b/src/main/java/com/casic/util/VerifyConstantUtil.java new file mode 100644 index 0000000..90ee071 --- /dev/null +++ b/src/main/java/com/casic/util/VerifyConstantUtil.java @@ -0,0 +1,11 @@ +package com.casic.util; + +public class VerifyConstantUtil { + + public final static String DEVICE_TYPES = "22,23,24"; + + public static Boolean checkDeviceType(String devcieType) { + return DEVICE_TYPES.contains(devcieType) ? true : false; + } + +} diff --git a/src/main/resources/config/application-dev.yml b/src/main/resources/config/application-dev.yml new file mode 100644 index 0000000..e948b83 --- /dev/null +++ b/src/main/resources/config/application-dev.yml @@ -0,0 +1,32 @@ +server: + port: 11315 +################### spring配置 ################### +spring: + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://111.198.10.15:11102/smartwell_demos?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&serverTimezone=UTC&&allowMultiQueries=true&&useSSL=true + username: root + password: Casic203! + session: + store-type: redis + redis: + host: 111.198.10.15 + port: 11412 + password: ew5T4K3#203lwh + redisValueSerializer: org.springframework.data.redis.serializer.JdkSerializationRedisSerializer + # session: + # store-type: redis +#flowable数据源和多数据源配置 +casic: + kaptcha-open: false #是否开启登录时验证码 (true/false) + #kaptcha-open: false #是否开启登录时验证码 (true/false) + db: + init: + enable: false + spring-session-open: false #开启spring session +logging: + level.root: error + level.com.casic: info + file: + path: logs/ + name: missiles.log \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..50f4a19 --- /dev/null +++ b/pom.xml @@ -0,0 +1,161 @@ + + + 4.0.0 + + com.casic + smartwell-demos + 1.0-SNAPSHOT + + + + + jdk-1.8 + + true + 1.8 + + + 1.8 + 1.8 + 1.8 + + + + + + + + + + org.springframework.boot + spring-boot-starter + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-tomcat + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-web + 2.4.5 + + + + + org.springframework.boot + spring-boot-starter-jdbc + 2.4.5 + + + + mysql + mysql-connector-java + 8.0.16 + compile + + + + com.baomidou + mybatis-plus-boot-starter + 3.4.3 + + + + org.projectlombok + lombok + 1.18.20 + + + + + com.alibaba + druid + 1.2.6 + + + + com.alibaba + fastjson + 1.2.73 + + + + commons-codec + commons-codec + 1.14 + + + + redis.clients + jedis + 3.1.0 + jar + + + + org.springframework.data + spring-data-redis + 2.4.8 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.3.RELEASE + + true + + com.casic.CasicApplication + exec + + + + + repackage + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + false + + + + + + + + src/main/resources + + + /config/*/* + /config/*-*.yml + + true + + + src/main/resources + + **/*.xml + + true + + + + + \ No newline at end of file diff --git a/src/main/java/com/casic/CasicApplication.java b/src/main/java/com/casic/CasicApplication.java new file mode 100644 index 0000000..9afd0b9 --- /dev/null +++ b/src/main/java/com/casic/CasicApplication.java @@ -0,0 +1,28 @@ +package com.casic; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.transaction.annotation.EnableTransactionManagement; + + +/** + * SpringBoot方式启动类 + * + * @author cz + * @Date 2022/09/08 14:28 + */ + +@Slf4j +@ComponentScan(basePackages= "com.casic.**") +@SpringBootApplication +public class CasicApplication { + public static void main(String[] args) { + log.info("CasicApplication is success!"); + SpringApplication.run(CasicApplication.class, args); + } +} diff --git a/src/main/java/com/casic/config/CorsConfig.java b/src/main/java/com/casic/config/CorsConfig.java new file mode 100644 index 0000000..7d19680 --- /dev/null +++ b/src/main/java/com/casic/config/CorsConfig.java @@ -0,0 +1,31 @@ +package com.casic.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +/** + * 基础框架 - 跨域请求配置 + */ +@Configuration +public class CorsConfig { + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", buildConfig()); + return new CorsFilter(source); + } + + private CorsConfiguration buildConfig() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + // 1允许任何域名使用 + corsConfiguration.addAllowedOrigin("*"); + // 2允许任何头 + corsConfiguration.addAllowedHeader("*"); + // 3允许任何方法(post、get等) + corsConfiguration.addAllowedMethod("*"); + return corsConfiguration; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/controller/AlarmController.java b/src/main/java/com/casic/controller/AlarmController.java new file mode 100644 index 0000000..957fc36 --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.model.AlarmConfigParam; +import com.casic.service.AlarmService; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/alarm") +public class AlarmController { + + private final AlarmService alarmService; + + public AlarmController(AlarmService alarmService) { + this.alarmService = alarmService; + } + + @RequestMapping("/records") + public Object getAlarmRecord(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "devcode",required =false) String devcode, + @RequestParam(value = "pageSize", required = true) Integer pageSize) { + return alarmService.getAlarmRecord(deviceType,currentIndex,pageSize,devcode); + } + + @RequestMapping("/batch/cancel") + public Object excuteAlramBatchCancel(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "devcode",required =false) String devcode) { + return alarmService.excuteAlramBatchCancel(deviceType,devcode); + } + + @RequestMapping("/config/add") + public Object addAlarmConfig(@RequestBody AlarmConfigParam alarmConfigParam) { + return alarmService.addAlarmConfig(alarmConfigParam); + } +} diff --git a/src/main/java/com/casic/controller/DeviceDataController.java b/src/main/java/com/casic/controller/DeviceDataController.java new file mode 100644 index 0000000..3498b04 --- /dev/null +++ b/src/main/java/com/casic/controller/DeviceDataController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.service.DeviceDataService; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/device") +public class DeviceDataController { + private final DeviceDataService deviceDataService; + + public DeviceDataController(DeviceDataService deviceDataService) { + this.deviceDataService = deviceDataService; + } + + @RequestMapping("/recent-data") + public Object getDeviceRecentData(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "recentNum", required = true) String recentNum, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceRecentData(deviceType, recentNum, devcode); + } + + @RequestMapping("/data/list-page") + public Object getDeviceListPage(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "pageSize", required = true) Integer pageSize, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceListPage(deviceType, currentIndex, pageSize, devcode); + } + + @RequestMapping("/level/{deviceType}") + public Object getLevelList(@PathVariable("deviceType")String deviceType) { + return deviceDataService.getLevel(deviceType); + } + +} diff --git a/src/main/java/com/casic/controller/ThirdDataController.java b/src/main/java/com/casic/controller/ThirdDataController.java new file mode 100644 index 0000000..b9b2b42 --- /dev/null +++ b/src/main/java/com/casic/controller/ThirdDataController.java @@ -0,0 +1,28 @@ +package com.casic.controller; + +import com.casic.model.PressureDataParam; +import com.casic.service.ThirdDataService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +@RestController +@RequestMapping("/push") +@Slf4j +public class ThirdDataController { + + private final ThirdDataService thirdDataService; + + public ThirdDataController(ThirdDataService thirdDataService) { + this.thirdDataService = thirdDataService; + } + + @RequestMapping("/pressure/data") + public Object getDeviceRecentData(@RequestBody PressureDataParam pressureData) { + return thirdDataService.getDeviceRecentData(pressureData); + } + +} diff --git a/src/main/java/com/casic/dao/AlarmMapper.java b/src/main/java/com/casic/dao/AlarmMapper.java new file mode 100644 index 0000000..a442e3a --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmMapper.java @@ -0,0 +1,28 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmLevel; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + +@Mapper +public interface AlarmMapper extends BaseMapper { + + List> getAlarmRecord(@Param("deviceType") String deviceType, + @Param("devcode") String devcode, + @Param("currentIndex") Integer currentIndex, @Param("pageSize") Integer pageSize); + + Integer getAlarmTotalRecord(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteAlramBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteJobBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + String getDeviceDevcode(@Param("deviceType") String deviceType); + + String getDeviceByDevcode(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + +} diff --git a/src/main/java/com/casic/dao/BusConfigMapper.java b/src/main/java/com/casic/dao/BusConfigMapper.java new file mode 100644 index 0000000..ccf76da --- /dev/null +++ b/src/main/java/com/casic/dao/BusConfigMapper.java @@ -0,0 +1,9 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.BusConfig; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface BusConfigMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/dao/DataPressureMapper.java b/src/main/java/com/casic/dao/DataPressureMapper.java new file mode 100644 index 0000000..05f4329 --- /dev/null +++ b/src/main/java/com/casic/dao/DataPressureMapper.java @@ -0,0 +1,19 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.DataPressure; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.Date; + +@Mapper +public interface DataPressureMapper extends BaseMapper { + + String getWellCode(@Param("devcode") String devcode); + + Float getRuleValue(@Param("deviceType") String deviceType); + + void saveRecords(@Param("reValue") String reValue, @Param("alarmTime") Date alarmTime); + +} diff --git a/src/main/java/com/casic/dao/DeviceDataMapper.java b/src/main/java/com/casic/dao/DeviceDataMapper.java new file mode 100644 index 0000000..d9e18a0 --- /dev/null +++ b/src/main/java/com/casic/dao/DeviceDataMapper.java @@ -0,0 +1,27 @@ +package com.casic.dao; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + + +@Mapper +public interface DeviceDataMapper { + + List> getDeviceRecentData(@Param("tableName") String tableName, + @Param("recentNum") String recentNum, + @Param("fields") String fields, + @Param("devcode") String devcode); + + Integer getDeviceDataTotal(@Param("tableName") String tableName, @Param("devcode") String devcode); + + List> getDeviceDataListPage(@Param("tableName") String tableName, + @Param("currentIndex") Integer currentIndex, + @Param("fields") String fields, + @Param("pageSize") Integer pageSize, + @Param("devcode") String devcode); + + String getLevelByType(@Param("deviceType")String deviceType); +} diff --git a/src/main/java/com/casic/model/AlarmConfigParam.java b/src/main/java/com/casic/model/AlarmConfigParam.java new file mode 100644 index 0000000..28150d6 --- /dev/null +++ b/src/main/java/com/casic/model/AlarmConfigParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class AlarmConfigParam { + private String deviceType; + private String thresholdVol; + private String collectInterval; + private String uploadCycle; + private String retryNum; + private String ip; + private String port; + private String devcode; +} diff --git a/src/main/java/com/casic/model/AlarmLevel.java b/src/main/java/com/casic/model/AlarmLevel.java new file mode 100644 index 0000000..d0909af --- /dev/null +++ b/src/main/java/com/casic/model/AlarmLevel.java @@ -0,0 +1,26 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("alarm_level") +public class AlarmLevel{ + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + private String name; + private String deviceType; + private Integer level; + private Float lowValue; + private Float highValue; + private String openAlarm; + private String openJob; + private Date ts; + private String tenantId; + +} diff --git a/src/main/java/com/casic/model/BusConfig.java b/src/main/java/com/casic/model/BusConfig.java new file mode 100644 index 0000000..c6b7b50 --- /dev/null +++ b/src/main/java/com/casic/model/BusConfig.java @@ -0,0 +1,27 @@ +package com.casic.model; + + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +import java.util.Date; + +@Data +public class BusConfig { + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + + private String deviceId; + private String framecontent; + private String sensorid; + private String sensorcode; + + private String status; + private Integer attemptsmax; + private Integer attemptscurrent; + private Date sendtime; + private Date writetime; + +} diff --git a/src/main/java/com/casic/model/CommConfigDTO.java b/src/main/java/com/casic/model/CommConfigDTO.java new file mode 100644 index 0000000..7da699c --- /dev/null +++ b/src/main/java/com/casic/model/CommConfigDTO.java @@ -0,0 +1,41 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class CommConfigDTO { + private String acqStart;//采集开始时间 + private Long interval;//采集时间间隔(分钟) + private Long period;//上传周期 + private Long times;//采集次数 + private Long repeat;//重传次数 + private String ip; + private Long port; + private Float thresh; + private Float height; + private String collect; + private String MultiCollect; + private String acqCycle; + private String upCycle; + private String sleepStartTime; + + private String acqStartFlow ; //流量采集开始时间 + private Long intervalFlow; //流量采集采集间隔(分) + private Long acqTimesFlow ;//流量采集次数 + private String upStartFlow; //流量上报开始时间 + private Long upTimesFlow; //流量上传次数 + private String acqStartNoise; //噪声采集开始时间 + private Long intervalNoise; //噪声采集采集间隔(分) + private Long acqTimesNoise;//噪声采集次数 + private String upStartNoise; //噪声上报开始时间 + private Long upTimesNoise ;//噪声上传次数 + private String acqStartPressure; //压力采集开始时间 + private Long intervalPressure;//压力采集采集间隔(分) + private Long acqTimesPressure; //压力采集次数 + private String upStartPressure; //压力上报开始时间 + private Long upTimesPressure; //压力上传次数 + private Float lowerLimitPressure; //压力报警下限 + private Float upperLimitPressure ;//压力报警下限 + private Long limitDig ;//开挖阈值 + private Float threshold ;//开挖阈值 +} diff --git a/src/main/java/com/casic/model/DataPressure.java b/src/main/java/com/casic/model/DataPressure.java new file mode 100644 index 0000000..8270c70 --- /dev/null +++ b/src/main/java/com/casic/model/DataPressure.java @@ -0,0 +1,33 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("data_temp_press") +public class DataPressure { + + @TableId(value = "ID", type = IdType.AUTO) + private String id; + private String wellCode; + private String devcode; + private Float cell; + private String temperature; + + private String press; + private String descn; + private String uptime; + private String logtime; + /** + * 信号强度 + */ + private String pci; + + private String rsrp; + private String snr; + +} diff --git a/src/main/java/com/casic/model/PressureDataParam.java b/src/main/java/com/casic/model/PressureDataParam.java new file mode 100644 index 0000000..f42770d --- /dev/null +++ b/src/main/java/com/casic/model/PressureDataParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class PressureDataParam { + private String flag; + private String deviceUserid; + private String parentUserId; + private Object sensorsDates; + private String time; + private String rawData; + private String deviceId; +} + diff --git a/src/main/java/com/casic/model/ResponseData.java b/src/main/java/com/casic/model/ResponseData.java new file mode 100644 index 0000000..245ab04 --- /dev/null +++ b/src/main/java/com/casic/model/ResponseData.java @@ -0,0 +1,18 @@ +package com.casic.model; + +import lombok.Data; + +/** + * @author cz + * @date 2022-8-12 + */ +@Data +public class ResponseData { + public static final String DEFAULT_SUCCESS_MESSAGE = "请求成功"; + public static final String DEFAULT_ERROR_MESSAGE = "网络异常"; + public static final Integer DEFAULT_SUCCESS_CODE = 200; + public static final Integer DEFAULT_ERROR_CODE = 500; + private Integer code; + private String message; + private Object data; +} \ No newline at end of file diff --git a/src/main/java/com/casic/service/AlarmService.java b/src/main/java/com/casic/service/AlarmService.java new file mode 100644 index 0000000..8516b41 --- /dev/null +++ b/src/main/java/com/casic/service/AlarmService.java @@ -0,0 +1,12 @@ +package com.casic.service; + +import com.casic.model.AlarmConfigParam; + +public interface AlarmService { + + Object getAlarmRecord(String deviceType,Integer currentIndex,Integer pageSize,String devcode); + + Object excuteAlramBatchCancel(String deviceType,String devcode); + + Object addAlarmConfig(AlarmConfigParam alarmConfig); +} diff --git a/src/main/java/com/casic/service/DeviceDataService.java b/src/main/java/com/casic/service/DeviceDataService.java new file mode 100644 index 0000000..db656c1 --- /dev/null +++ b/src/main/java/com/casic/service/DeviceDataService.java @@ -0,0 +1,10 @@ +package com.casic.service; + +public interface DeviceDataService { + + Object getDeviceRecentData(String deviceType, String recentNum, String devcode); + + Object getDeviceListPage(String deviceType, Integer currentIndex, Integer pageSize, String devcode); + + Object getLevel(String deviceType); +} diff --git a/src/main/java/com/casic/service/ThirdDataService.java b/src/main/java/com/casic/service/ThirdDataService.java new file mode 100644 index 0000000..795e0b2 --- /dev/null +++ b/src/main/java/com/casic/service/ThirdDataService.java @@ -0,0 +1,8 @@ +package com.casic.service; + +import com.casic.model.PressureDataParam; + +public interface ThirdDataService { + + Object getDeviceRecentData(PressureDataParam pressureData); +} diff --git a/src/main/java/com/casic/service/impl/AlarmServiceImple.java b/src/main/java/com/casic/service/impl/AlarmServiceImple.java new file mode 100644 index 0000000..a675207 --- /dev/null +++ b/src/main/java/com/casic/service/impl/AlarmServiceImple.java @@ -0,0 +1,127 @@ +package com.casic.service.impl; + +import com.alibaba.druid.util.StringUtils; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.dao.AlarmMapper; +import com.casic.dao.BusConfigMapper; +import com.casic.model.*; +import com.casic.service.AlarmService; +import com.casic.util.DeviceDataTableEnum; +import com.casic.util.RedisCommonUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Slf4j +@Service +public class AlarmServiceImple extends ServiceImpl implements AlarmService { + + @Resource + private BusConfigMapper busConfigMapper; + @Resource + private RedisCommonUtil redisCommonUtil; + + public Object getAlarmRecord(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { + ResponseData responseData = new ResponseData(); + try { + Map page = new HashMap(); + page.put("total", this.baseMapper.getAlarmTotalRecord(deviceType, devcode)); + List> alarmRecordList = this.baseMapper.getAlarmRecord(deviceType, devcode, pageSize * (currentIndex - 1), pageSize); + page.put("rows", alarmRecordList); + responseData.setData(alarmRecordList); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},异常信息{}", deviceType, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + @Transactional + public Object excuteAlramBatchCancel(String deviceType, String devcode) { + ResponseData responseData = new ResponseData(); + try { + this.baseMapper.excuteAlramBatchCancel(deviceType, devcode); + this.baseMapper.excuteJobBatchCancel(deviceType, devcode); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("批量消警异常,设备类型{},异常信息{}", deviceType, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + + @Transactional + public Object addAlarmConfig(AlarmConfigParam alarmConfigParam) { + ResponseData responseData = new ResponseData(); + try { + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + addBusConfig(alarmConfigParam); + addRuleConfig(alarmConfigParam); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("风险配置异常,异常信息{}", dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + private void addRuleConfig(AlarmConfigParam alarmConfigParam) { + Map alarmRuleMap = new HashMap(); + alarmRuleMap.put("DEVICE_TYPE", alarmConfigParam.getDeviceType()); + this.baseMapper.deleteByMap(alarmRuleMap); + AlarmLevel alarmRule = new AlarmLevel(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap() + .get(Integer.valueOf(alarmConfigParam.getDeviceType())); + alarmRule.setName(deviceDataTableEnum.getTypeName()); + alarmRule.setHighValue(Float.valueOf(alarmConfigParam.getThresholdVol())); + alarmRule.setTs(new Date()); + alarmRule.setLevel(1); + alarmRule.setDeviceType(alarmConfigParam.getDeviceType()); + this.baseMapper.insert(alarmRule); + } + + private void addBusConfig(AlarmConfigParam alarmConfigParam) { + String devcode = StringUtils.isEmpty(alarmConfigParam.getDevcode()) ? this.baseMapper.getDeviceDevcode(alarmConfigParam.getDeviceType()) : alarmConfigParam.getDevcode(); + sendBusConfig(alarmConfigParam, devcode); + String devcideId = this.baseMapper.getDeviceByDevcode(alarmConfigParam.getDeviceType(), devcode); + BusConfig busConfig = new BusConfig(); + busConfig.setDeviceId(devcideId); + busConfig.setFramecontent("3," + alarmConfigParam.getCollectInterval() + "," + alarmConfigParam.getCollectInterval() + + "," + alarmConfigParam.getRetryNum() + "," + alarmConfigParam.getIp() + "," + alarmConfigParam.getPort()); + busConfig.setSensorid(""); + busConfig.setStatus("0"); + busConfig.setAttemptscurrent(0); + busConfig.setWritetime(new Date()); + busConfig.setAttemptsmax(3); + busConfigMapper.insert(busConfig); + } + + private void sendBusConfig(AlarmConfigParam alarmConfigParam, String devcode) { + CommConfigDTO commConfigDTO = new CommConfigDTO(); + commConfigDTO.setInterval(StringUtils.isEmpty(alarmConfigParam.getCollectInterval()) ? 300 : Long.valueOf(alarmConfigParam.getCollectInterval())); + commConfigDTO.setRepeat(StringUtils.isEmpty(alarmConfigParam.getRetryNum()) ? 300 : Long.valueOf(alarmConfigParam.getRetryNum())); + commConfigDTO.setTimes(Long.valueOf(1)); +// commConfigDTO.setIp(alarmConfigParam.getIp()); +// commConfigDTO.setPort(StringUtils.isEmpty(alarmConfigParam.getPort()) ? 8080 : Long.valueOf(alarmConfigParam.getPort())); + commConfigDTO.setPeriod(StringUtils.isEmpty(alarmConfigParam.getUploadCycle()) ? 300 : Long.valueOf(alarmConfigParam.getUploadCycle())); +// commConfigDTO.setThresh(); + commConfigDTO.setThresh(StringUtils.isEmpty(alarmConfigParam.getThresholdVol()) ? 50: Float.valueOf(alarmConfigParam.getThresholdVol())); + redisCommonUtil.send(commConfigDTO, devcode); + } + + +} diff --git a/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java new file mode 100644 index 0000000..3de704b --- /dev/null +++ b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java @@ -0,0 +1,80 @@ +package com.casic.service.impl; + +import com.casic.dao.DeviceDataMapper; +import com.casic.model.ResponseData; +import com.casic.service.DeviceDataService; +import com.casic.util.DeviceDataFieldTableEnum; +import com.casic.util.DeviceDataTableEnum; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Service +@Slf4j +public class DeviceDataServiceImpl implements DeviceDataService { + + private final DeviceDataMapper deviceDataMapper; + + public DeviceDataServiceImpl(DeviceDataMapper deviceDataMapper) { + this.deviceDataMapper = deviceDataMapper; + } + + public Object getDeviceRecentData(String deviceType, String recentNum, String devcode) { + ResponseData responseData = new ResponseData(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); + try { + String tableName = deviceDataTableEnum.getTableName(); + String fields = DeviceDataFieldTableEnum.TABLE_FIELD.getTableFieldMap().get(tableName); + List> recentDataList = deviceDataMapper.getDeviceRecentData(tableName, recentNum, fields, devcode); + responseData.setData(recentDataList); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备最近数据查询异常,设备类型{},查询数目{},异常信息{}", deviceType, recentNum, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + public Object getDeviceListPage(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { + ResponseData responseData = new ResponseData(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); + try { + String tableName = deviceDataTableEnum.getTableName(); + String fields = DeviceDataFieldTableEnum.TABLE_FIELD.getTableFieldMap().get(tableName); + Map page = new HashMap(); + page.put("total", deviceDataMapper.getDeviceDataTotal(tableName, devcode)); + List> recentDataList = deviceDataMapper.getDeviceDataListPage(tableName, pageSize * (currentIndex - 1), fields, pageSize, devcode); + page.put("rows", recentDataList); + responseData.setData(page); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},当前页{},页大小{},异常信息{}", deviceType, currentIndex, pageSize, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + public Object getLevel(String deviceType) { + ResponseData responseData = new ResponseData(); + try { + String highValue = deviceDataMapper.getLevelByType(deviceType); + responseData.setData(highValue); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},当前页{},页大小{},异常信息{}"); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + +} diff --git a/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java new file mode 100644 index 0000000..6b23451 --- /dev/null +++ b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java @@ -0,0 +1,92 @@ +package com.casic.service.impl; + +import com.alibaba.druid.util.StringUtils; +import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.dao.DataPressureMapper; +import com.casic.model.DataPressure; +import com.casic.model.PressureDataParam; +import com.casic.model.ResponseData; +import com.casic.service.ThirdDataService; +import com.casic.util.CacheUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.stream.Collectors; + +@Service +@Slf4j +public class ThirdDataServiceImpl extends ServiceImpl implements ThirdDataService { + + private final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA); + + public Object getDeviceRecentData(PressureDataParam pressureDataParam) { + ResponseData responseData = new ResponseData(); + try { + batchSave(pressureDataParam); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备最近数据查询异常,设备类型{},异常信息{}", dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + private void batchSave(PressureDataParam pressureDataParam) { + String pressureDataJson = pressureDataParam.getRawData(); + log.info("----" + pressureDataJson); + Map pressureDataMap = JSON.parseObject(pressureDataJson, HashMap.class); + Date uptime = null; + try { + uptime = dateFormat.parse(String.valueOf(pressureDataMap.get("times"))); + } catch (Exception e) { + log.error("主题,采集时间解析异常,异常信息{}", e.getMessage()); + } + List> pressureDataList = (List>) pressureDataMap.get("sensorDatas"); + DataPressure dataPressure = initPrssureData(pressureDataList, uptime); + if (dataPressure == null) { + return; + } + checkAlarm(dataPressure); + } + + private DataPressure initPrssureData(List> pressureDataList, Date uptime) { + DataPressure dataPressure = new DataPressure(); + String devcode = pressureDataList.get(pressureDataList.size() - 1).get("str"); + Map pressureDataMap = pressureDataList.stream().collect( + Collectors.toMap(e -> String.valueOf(e.get("flag")), e -> String.valueOf(e.get("value"))) + ); +// if (CacheUtil.serialBuf.get(devcode)!=null&&CacheUtil.serialBuf.get(devcode).equals(pressureDataMap.get("F"))) { +// return null; +// } + String wellCode = this.baseMapper.getWellCode(devcode); + dataPressure.setWellCode(wellCode); + dataPressure.setDevcode(devcode); + dataPressure.setPci(pressureDataMap.get("Q")); + dataPressure.setCell(Float.valueOf(pressureDataMap.get("V"))); + dataPressure.setTemperature(pressureDataMap.get("T")); + dataPressure.setPress(pressureDataMap.get("F")); + dataPressure.setUptime(dateFormat.format(uptime)); + dataPressure.setLogtime(dateFormat.format(new Date())); + this.baseMapper.insert(dataPressure); +// CacheUtil.serialBuf.put(devcode, pressureDataMap.get("F")); + return dataPressure; + } + + private void checkAlarm(DataPressure dataPressure) { + final Float ruleValue = this.baseMapper.getRuleValue("24"); + if (ruleValue == null) return; + if (!StringUtils.isEmpty(dataPressure.getTemperature()) && !dataPressure.getTemperature().equals("null")) { + if (Float.valueOf(dataPressure.getTemperature()) > ruleValue) { + this.baseMapper.saveRecords(dataPressure.getTemperature(), new Date()); + } + } + } + +} diff --git a/src/main/java/com/casic/util/CacheUtil.java b/src/main/java/com/casic/util/CacheUtil.java new file mode 100644 index 0000000..5b89300 --- /dev/null +++ b/src/main/java/com/casic/util/CacheUtil.java @@ -0,0 +1,16 @@ +package com.casic.util; + +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import java.util.HashMap; +import java.util.Map; + +@Component +public class CacheUtil { + public static volatile Map serialBuf; + @PostConstruct + public void init() { + serialBuf = new HashMap<>(); + } +} diff --git a/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java b/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java new file mode 100644 index 0000000..085c7c3 --- /dev/null +++ b/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java @@ -0,0 +1,39 @@ +package com.casic.util; + +import java.util.HashMap; +import java.util.Map; + +public enum DeviceDataFieldTableEnum { + + TABLE_FIELD(new HashMap() { + { + put("data_dig", "ddata AS dataValue,devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gas", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gasliquid_gas", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gasliquid_liquid", "liquiddata AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gas_dector", "gas_sample_value AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_harmful_gas", "CONCAT(CO, ', ', CH4, ', ', H2S, ', ', O2) AS dataValue,devcode AS devcode,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_hydrant", "0 AS dataValue,devcode AS devcode,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_liquid", "liquiddata AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_noise", "ddata AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_temp_hum", "CONCAT(TEMPERATURE, ', ', HUMIDITY) AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_tube", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_wellcover", "descn AS dataValue,devcode AS devcode,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_temp_press", "press AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_pantilt", "concentration AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_wellcover_loca", "0 AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_wellplus", "0 AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_h2s", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_pressure", "re_val AS dataValue,devcode AS devcode,'' AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + } + }); + public Map tableNameMap; + + DeviceDataFieldTableEnum(Map tableNameMap) { + this.tableNameMap = tableNameMap; + } + + public Map getTableFieldMap() { + return tableNameMap; + } +} diff --git a/src/main/java/com/casic/util/DeviceDataTableEnum.java b/src/main/java/com/casic/util/DeviceDataTableEnum.java new file mode 100644 index 0000000..9698487 --- /dev/null +++ b/src/main/java/com/casic/util/DeviceDataTableEnum.java @@ -0,0 +1,81 @@ +package com.casic.util; + +import java.util.HashMap; + +/** + * @author cz + * @date 2022-7-15 + * 上传数据总记录数 + */ +public enum DeviceDataTableEnum { + + DATA_DIG("data_dig", "开挖监测仪"), + DATA_GAS("data_gas", "燃气智能监测终端"), + DATA_GASLIQUID("data_gasliquid_gas,data_gasliquid_liquid", "燃气智能监测终端(一体化)"), + DATA_GAS_DECTOR("data_gas_dector", "燃气探测仪"), + DATA_HARMFUL_GAS("data_harmful_gas", "有害气体监测仪"), + DATA_HYDRANT("data_hydrant", "消防栓防盗水监测仪"), + DATA_LIQUID("data_liquid", "液位监测仪"), + DATA_NOISE("data_noise", "噪声记录仪"), + DATA_PANTILT("data_pantilt", "激光甲烷云台"), + DATA_TEMP_HUM("data_temp_hum", "温湿度监测仪"), + DATA_TUBE("data_tube", "管盯"), + DATA_WELLCOVER("data_wellcover", "井盖状态监测仪"), + DATA_TEMP_PRESS("data_temp_press", "压力温度检测仪"), + DATA_WELLCOVER_LOCA("data_wellcover_loca", "井盖定位监测仪"), + DATA_WELLPLUS("data_wellplus", "井盖液位一体机"), + DATA_H2S("data_h2s", "硫化氢检测终端"), + DATA_PRESSURE("data_pressure", "压力检测终端"), + DEVICE_TYPE_TABLE(new HashMap() { + { + put(1, DATA_WELLCOVER); + put(2, DATA_LIQUID); + put(3, DATA_HARMFUL_GAS); + put(4, DATA_GAS); + put(5, DATA_TEMP_HUM); + put(6, DATA_DIG); + put(7, DATA_WELLCOVER_LOCA); + put(8, DATA_NOISE); + put(9, DATA_TEMP_PRESS); + put(10, DATA_GASLIQUID); + put(11, DATA_HYDRANT); + put(12, DATA_TUBE); + put(13, DATA_WELLPLUS); + put(14, DATA_H2S); + put(21, DATA_PANTILT); + put(22, DATA_H2S); + put(23, DATA_GAS); + put(24, DATA_TEMP_PRESS); + put(101, DATA_GAS_DECTOR); + } + }); + + String typeName; + String tableName; + + DeviceDataTableEnum(String tableName, String typeName) { + this.typeName = typeName; + this.tableName = tableName; + } + + public String getTypeName() { + return typeName; + } + + public String getTableName() { + return tableName; + } + + + public HashMap tableNameMap; + + DeviceDataTableEnum(HashMap tableNameMap) { + this.tableNameMap = tableNameMap; + } + + public HashMap getTableNameMap() { + return tableNameMap; + } + + +} diff --git a/src/main/java/com/casic/util/RedisCommonUtil.java b/src/main/java/com/casic/util/RedisCommonUtil.java new file mode 100644 index 0000000..a6ce9cf --- /dev/null +++ b/src/main/java/com/casic/util/RedisCommonUtil.java @@ -0,0 +1,29 @@ +package com.casic.util; + +import com.alibaba.fastjson.JSON; +import com.casic.model.CommConfigDTO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; + +import java.util.concurrent.TimeUnit; + +@Component +public class RedisCommonUtil { + + @Value("${casic.device.redis.invalid-time}") + private String invalidTime; + @Value("${casic.device.redis.config-prefix}") + private String configPrefix; + + @Autowired + private RedisTemplate redisTemplate; + + public void send(CommConfigDTO commConfigDTO,String devCode) { + redisTemplate.opsForValue().set(configPrefix+ devCode, + JSON.toJSONString(commConfigDTO), + Integer.valueOf(invalidTime), + TimeUnit.SECONDS); + } +} diff --git a/src/main/java/com/casic/util/SensorIdEum.java b/src/main/java/com/casic/util/SensorIdEum.java new file mode 100644 index 0000000..86b61db --- /dev/null +++ b/src/main/java/com/casic/util/SensorIdEum.java @@ -0,0 +1,30 @@ +package com.casic.util; + +import java.util.HashMap; +import java.util.Map; + +public enum SensorIdEum { + + SENSOR_MAP(new HashMap() { + { + put("燃气智能监测终端", "000044"); + put("有害气体监测仪", "000035"); + put("开挖监测仪", "000064"); + put("温湿度监测仪", "000055"); + put("噪声记录仪", "000032"); + put("液位监测仪", "000034"); + put("燃气智能监测终端(一体化)", "000065"); + put("管盯", "000080"); + } + }); + public Map sensorMap; + + SensorIdEum(Map sensorMap) { + this.sensorMap = sensorMap; + } + + public Map getSensorMap() { + return sensorMap; + } + +} diff --git a/src/main/java/com/casic/util/VerifyConstantUtil.java b/src/main/java/com/casic/util/VerifyConstantUtil.java new file mode 100644 index 0000000..90ee071 --- /dev/null +++ b/src/main/java/com/casic/util/VerifyConstantUtil.java @@ -0,0 +1,11 @@ +package com.casic.util; + +public class VerifyConstantUtil { + + public final static String DEVICE_TYPES = "22,23,24"; + + public static Boolean checkDeviceType(String devcieType) { + return DEVICE_TYPES.contains(devcieType) ? true : false; + } + +} diff --git a/src/main/resources/config/application-dev.yml b/src/main/resources/config/application-dev.yml new file mode 100644 index 0000000..e948b83 --- /dev/null +++ b/src/main/resources/config/application-dev.yml @@ -0,0 +1,32 @@ +server: + port: 11315 +################### spring配置 ################### +spring: + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://111.198.10.15:11102/smartwell_demos?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&serverTimezone=UTC&&allowMultiQueries=true&&useSSL=true + username: root + password: Casic203! + session: + store-type: redis + redis: + host: 111.198.10.15 + port: 11412 + password: ew5T4K3#203lwh + redisValueSerializer: org.springframework.data.redis.serializer.JdkSerializationRedisSerializer + # session: + # store-type: redis +#flowable数据源和多数据源配置 +casic: + kaptcha-open: false #是否开启登录时验证码 (true/false) + #kaptcha-open: false #是否开启登录时验证码 (true/false) + db: + init: + enable: false + spring-session-open: false #开启spring session +logging: + level.root: error + level.com.casic: info + file: + path: logs/ + name: missiles.log \ No newline at end of file diff --git a/src/main/resources/config/application-prod.yml b/src/main/resources/config/application-prod.yml new file mode 100644 index 0000000..4fee268 --- /dev/null +++ b/src/main/resources/config/application-prod.yml @@ -0,0 +1,43 @@ +server: + port: 11312 +################### spring配置 ################### +spring: + datasource: + smartwell: + driver-class-name: org.postgresql.Driver + url: jdbc:postgresql://111.198.10.15:11209/smartwell + username: postgres + password: Casic203 + cms: + driver-class-name: org.postgresql.Driver + url: jdbc:postgresql://111.198.10.15:11209/smartwell_cms + username: postgres + password: Casic203 + span_tilt: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://111.198.10.15:11102/casic_span_tilt?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&serverTimezone=UTC&&allowMultiQueries=true&&useSSL=true + username: root + password: Casic203! + session: + store-type: redis + redis: + host: 111.198.10.15 + port: 11412 + password: ew5T4K3#203lwh + redisValueSerializer: org.springframework.data.redis.serializer.JdkSerializationRedisSerializer + # session: + # store-type: redis +#flowable数据源和多数据源配置 +casic: + kaptcha-open: false #是否开启登录时验证码 (true/false) + #kaptcha-open: false #是否开启登录时验证码 (true/false) + db: + init: + enable: false + spring-session-open: false #开启spring session +logging: + level.root: error + level.com.casic: error + file: + path: logs/ + name: missiles.log \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..50f4a19 --- /dev/null +++ b/pom.xml @@ -0,0 +1,161 @@ + + + 4.0.0 + + com.casic + smartwell-demos + 1.0-SNAPSHOT + + + + + jdk-1.8 + + true + 1.8 + + + 1.8 + 1.8 + 1.8 + + + + + + + + + + org.springframework.boot + spring-boot-starter + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-tomcat + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-web + 2.4.5 + + + + + org.springframework.boot + spring-boot-starter-jdbc + 2.4.5 + + + + mysql + mysql-connector-java + 8.0.16 + compile + + + + com.baomidou + mybatis-plus-boot-starter + 3.4.3 + + + + org.projectlombok + lombok + 1.18.20 + + + + + com.alibaba + druid + 1.2.6 + + + + com.alibaba + fastjson + 1.2.73 + + + + commons-codec + commons-codec + 1.14 + + + + redis.clients + jedis + 3.1.0 + jar + + + + org.springframework.data + spring-data-redis + 2.4.8 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.3.RELEASE + + true + + com.casic.CasicApplication + exec + + + + + repackage + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + false + + + + + + + + src/main/resources + + + /config/*/* + /config/*-*.yml + + true + + + src/main/resources + + **/*.xml + + true + + + + + \ No newline at end of file diff --git a/src/main/java/com/casic/CasicApplication.java b/src/main/java/com/casic/CasicApplication.java new file mode 100644 index 0000000..9afd0b9 --- /dev/null +++ b/src/main/java/com/casic/CasicApplication.java @@ -0,0 +1,28 @@ +package com.casic; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.transaction.annotation.EnableTransactionManagement; + + +/** + * SpringBoot方式启动类 + * + * @author cz + * @Date 2022/09/08 14:28 + */ + +@Slf4j +@ComponentScan(basePackages= "com.casic.**") +@SpringBootApplication +public class CasicApplication { + public static void main(String[] args) { + log.info("CasicApplication is success!"); + SpringApplication.run(CasicApplication.class, args); + } +} diff --git a/src/main/java/com/casic/config/CorsConfig.java b/src/main/java/com/casic/config/CorsConfig.java new file mode 100644 index 0000000..7d19680 --- /dev/null +++ b/src/main/java/com/casic/config/CorsConfig.java @@ -0,0 +1,31 @@ +package com.casic.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +/** + * 基础框架 - 跨域请求配置 + */ +@Configuration +public class CorsConfig { + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", buildConfig()); + return new CorsFilter(source); + } + + private CorsConfiguration buildConfig() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + // 1允许任何域名使用 + corsConfiguration.addAllowedOrigin("*"); + // 2允许任何头 + corsConfiguration.addAllowedHeader("*"); + // 3允许任何方法(post、get等) + corsConfiguration.addAllowedMethod("*"); + return corsConfiguration; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/controller/AlarmController.java b/src/main/java/com/casic/controller/AlarmController.java new file mode 100644 index 0000000..957fc36 --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.model.AlarmConfigParam; +import com.casic.service.AlarmService; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/alarm") +public class AlarmController { + + private final AlarmService alarmService; + + public AlarmController(AlarmService alarmService) { + this.alarmService = alarmService; + } + + @RequestMapping("/records") + public Object getAlarmRecord(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "devcode",required =false) String devcode, + @RequestParam(value = "pageSize", required = true) Integer pageSize) { + return alarmService.getAlarmRecord(deviceType,currentIndex,pageSize,devcode); + } + + @RequestMapping("/batch/cancel") + public Object excuteAlramBatchCancel(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "devcode",required =false) String devcode) { + return alarmService.excuteAlramBatchCancel(deviceType,devcode); + } + + @RequestMapping("/config/add") + public Object addAlarmConfig(@RequestBody AlarmConfigParam alarmConfigParam) { + return alarmService.addAlarmConfig(alarmConfigParam); + } +} diff --git a/src/main/java/com/casic/controller/DeviceDataController.java b/src/main/java/com/casic/controller/DeviceDataController.java new file mode 100644 index 0000000..3498b04 --- /dev/null +++ b/src/main/java/com/casic/controller/DeviceDataController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.service.DeviceDataService; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/device") +public class DeviceDataController { + private final DeviceDataService deviceDataService; + + public DeviceDataController(DeviceDataService deviceDataService) { + this.deviceDataService = deviceDataService; + } + + @RequestMapping("/recent-data") + public Object getDeviceRecentData(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "recentNum", required = true) String recentNum, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceRecentData(deviceType, recentNum, devcode); + } + + @RequestMapping("/data/list-page") + public Object getDeviceListPage(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "pageSize", required = true) Integer pageSize, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceListPage(deviceType, currentIndex, pageSize, devcode); + } + + @RequestMapping("/level/{deviceType}") + public Object getLevelList(@PathVariable("deviceType")String deviceType) { + return deviceDataService.getLevel(deviceType); + } + +} diff --git a/src/main/java/com/casic/controller/ThirdDataController.java b/src/main/java/com/casic/controller/ThirdDataController.java new file mode 100644 index 0000000..b9b2b42 --- /dev/null +++ b/src/main/java/com/casic/controller/ThirdDataController.java @@ -0,0 +1,28 @@ +package com.casic.controller; + +import com.casic.model.PressureDataParam; +import com.casic.service.ThirdDataService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +@RestController +@RequestMapping("/push") +@Slf4j +public class ThirdDataController { + + private final ThirdDataService thirdDataService; + + public ThirdDataController(ThirdDataService thirdDataService) { + this.thirdDataService = thirdDataService; + } + + @RequestMapping("/pressure/data") + public Object getDeviceRecentData(@RequestBody PressureDataParam pressureData) { + return thirdDataService.getDeviceRecentData(pressureData); + } + +} diff --git a/src/main/java/com/casic/dao/AlarmMapper.java b/src/main/java/com/casic/dao/AlarmMapper.java new file mode 100644 index 0000000..a442e3a --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmMapper.java @@ -0,0 +1,28 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmLevel; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + +@Mapper +public interface AlarmMapper extends BaseMapper { + + List> getAlarmRecord(@Param("deviceType") String deviceType, + @Param("devcode") String devcode, + @Param("currentIndex") Integer currentIndex, @Param("pageSize") Integer pageSize); + + Integer getAlarmTotalRecord(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteAlramBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteJobBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + String getDeviceDevcode(@Param("deviceType") String deviceType); + + String getDeviceByDevcode(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + +} diff --git a/src/main/java/com/casic/dao/BusConfigMapper.java b/src/main/java/com/casic/dao/BusConfigMapper.java new file mode 100644 index 0000000..ccf76da --- /dev/null +++ b/src/main/java/com/casic/dao/BusConfigMapper.java @@ -0,0 +1,9 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.BusConfig; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface BusConfigMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/dao/DataPressureMapper.java b/src/main/java/com/casic/dao/DataPressureMapper.java new file mode 100644 index 0000000..05f4329 --- /dev/null +++ b/src/main/java/com/casic/dao/DataPressureMapper.java @@ -0,0 +1,19 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.DataPressure; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.Date; + +@Mapper +public interface DataPressureMapper extends BaseMapper { + + String getWellCode(@Param("devcode") String devcode); + + Float getRuleValue(@Param("deviceType") String deviceType); + + void saveRecords(@Param("reValue") String reValue, @Param("alarmTime") Date alarmTime); + +} diff --git a/src/main/java/com/casic/dao/DeviceDataMapper.java b/src/main/java/com/casic/dao/DeviceDataMapper.java new file mode 100644 index 0000000..d9e18a0 --- /dev/null +++ b/src/main/java/com/casic/dao/DeviceDataMapper.java @@ -0,0 +1,27 @@ +package com.casic.dao; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + + +@Mapper +public interface DeviceDataMapper { + + List> getDeviceRecentData(@Param("tableName") String tableName, + @Param("recentNum") String recentNum, + @Param("fields") String fields, + @Param("devcode") String devcode); + + Integer getDeviceDataTotal(@Param("tableName") String tableName, @Param("devcode") String devcode); + + List> getDeviceDataListPage(@Param("tableName") String tableName, + @Param("currentIndex") Integer currentIndex, + @Param("fields") String fields, + @Param("pageSize") Integer pageSize, + @Param("devcode") String devcode); + + String getLevelByType(@Param("deviceType")String deviceType); +} diff --git a/src/main/java/com/casic/model/AlarmConfigParam.java b/src/main/java/com/casic/model/AlarmConfigParam.java new file mode 100644 index 0000000..28150d6 --- /dev/null +++ b/src/main/java/com/casic/model/AlarmConfigParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class AlarmConfigParam { + private String deviceType; + private String thresholdVol; + private String collectInterval; + private String uploadCycle; + private String retryNum; + private String ip; + private String port; + private String devcode; +} diff --git a/src/main/java/com/casic/model/AlarmLevel.java b/src/main/java/com/casic/model/AlarmLevel.java new file mode 100644 index 0000000..d0909af --- /dev/null +++ b/src/main/java/com/casic/model/AlarmLevel.java @@ -0,0 +1,26 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("alarm_level") +public class AlarmLevel{ + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + private String name; + private String deviceType; + private Integer level; + private Float lowValue; + private Float highValue; + private String openAlarm; + private String openJob; + private Date ts; + private String tenantId; + +} diff --git a/src/main/java/com/casic/model/BusConfig.java b/src/main/java/com/casic/model/BusConfig.java new file mode 100644 index 0000000..c6b7b50 --- /dev/null +++ b/src/main/java/com/casic/model/BusConfig.java @@ -0,0 +1,27 @@ +package com.casic.model; + + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +import java.util.Date; + +@Data +public class BusConfig { + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + + private String deviceId; + private String framecontent; + private String sensorid; + private String sensorcode; + + private String status; + private Integer attemptsmax; + private Integer attemptscurrent; + private Date sendtime; + private Date writetime; + +} diff --git a/src/main/java/com/casic/model/CommConfigDTO.java b/src/main/java/com/casic/model/CommConfigDTO.java new file mode 100644 index 0000000..7da699c --- /dev/null +++ b/src/main/java/com/casic/model/CommConfigDTO.java @@ -0,0 +1,41 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class CommConfigDTO { + private String acqStart;//采集开始时间 + private Long interval;//采集时间间隔(分钟) + private Long period;//上传周期 + private Long times;//采集次数 + private Long repeat;//重传次数 + private String ip; + private Long port; + private Float thresh; + private Float height; + private String collect; + private String MultiCollect; + private String acqCycle; + private String upCycle; + private String sleepStartTime; + + private String acqStartFlow ; //流量采集开始时间 + private Long intervalFlow; //流量采集采集间隔(分) + private Long acqTimesFlow ;//流量采集次数 + private String upStartFlow; //流量上报开始时间 + private Long upTimesFlow; //流量上传次数 + private String acqStartNoise; //噪声采集开始时间 + private Long intervalNoise; //噪声采集采集间隔(分) + private Long acqTimesNoise;//噪声采集次数 + private String upStartNoise; //噪声上报开始时间 + private Long upTimesNoise ;//噪声上传次数 + private String acqStartPressure; //压力采集开始时间 + private Long intervalPressure;//压力采集采集间隔(分) + private Long acqTimesPressure; //压力采集次数 + private String upStartPressure; //压力上报开始时间 + private Long upTimesPressure; //压力上传次数 + private Float lowerLimitPressure; //压力报警下限 + private Float upperLimitPressure ;//压力报警下限 + private Long limitDig ;//开挖阈值 + private Float threshold ;//开挖阈值 +} diff --git a/src/main/java/com/casic/model/DataPressure.java b/src/main/java/com/casic/model/DataPressure.java new file mode 100644 index 0000000..8270c70 --- /dev/null +++ b/src/main/java/com/casic/model/DataPressure.java @@ -0,0 +1,33 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("data_temp_press") +public class DataPressure { + + @TableId(value = "ID", type = IdType.AUTO) + private String id; + private String wellCode; + private String devcode; + private Float cell; + private String temperature; + + private String press; + private String descn; + private String uptime; + private String logtime; + /** + * 信号强度 + */ + private String pci; + + private String rsrp; + private String snr; + +} diff --git a/src/main/java/com/casic/model/PressureDataParam.java b/src/main/java/com/casic/model/PressureDataParam.java new file mode 100644 index 0000000..f42770d --- /dev/null +++ b/src/main/java/com/casic/model/PressureDataParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class PressureDataParam { + private String flag; + private String deviceUserid; + private String parentUserId; + private Object sensorsDates; + private String time; + private String rawData; + private String deviceId; +} + diff --git a/src/main/java/com/casic/model/ResponseData.java b/src/main/java/com/casic/model/ResponseData.java new file mode 100644 index 0000000..245ab04 --- /dev/null +++ b/src/main/java/com/casic/model/ResponseData.java @@ -0,0 +1,18 @@ +package com.casic.model; + +import lombok.Data; + +/** + * @author cz + * @date 2022-8-12 + */ +@Data +public class ResponseData { + public static final String DEFAULT_SUCCESS_MESSAGE = "请求成功"; + public static final String DEFAULT_ERROR_MESSAGE = "网络异常"; + public static final Integer DEFAULT_SUCCESS_CODE = 200; + public static final Integer DEFAULT_ERROR_CODE = 500; + private Integer code; + private String message; + private Object data; +} \ No newline at end of file diff --git a/src/main/java/com/casic/service/AlarmService.java b/src/main/java/com/casic/service/AlarmService.java new file mode 100644 index 0000000..8516b41 --- /dev/null +++ b/src/main/java/com/casic/service/AlarmService.java @@ -0,0 +1,12 @@ +package com.casic.service; + +import com.casic.model.AlarmConfigParam; + +public interface AlarmService { + + Object getAlarmRecord(String deviceType,Integer currentIndex,Integer pageSize,String devcode); + + Object excuteAlramBatchCancel(String deviceType,String devcode); + + Object addAlarmConfig(AlarmConfigParam alarmConfig); +} diff --git a/src/main/java/com/casic/service/DeviceDataService.java b/src/main/java/com/casic/service/DeviceDataService.java new file mode 100644 index 0000000..db656c1 --- /dev/null +++ b/src/main/java/com/casic/service/DeviceDataService.java @@ -0,0 +1,10 @@ +package com.casic.service; + +public interface DeviceDataService { + + Object getDeviceRecentData(String deviceType, String recentNum, String devcode); + + Object getDeviceListPage(String deviceType, Integer currentIndex, Integer pageSize, String devcode); + + Object getLevel(String deviceType); +} diff --git a/src/main/java/com/casic/service/ThirdDataService.java b/src/main/java/com/casic/service/ThirdDataService.java new file mode 100644 index 0000000..795e0b2 --- /dev/null +++ b/src/main/java/com/casic/service/ThirdDataService.java @@ -0,0 +1,8 @@ +package com.casic.service; + +import com.casic.model.PressureDataParam; + +public interface ThirdDataService { + + Object getDeviceRecentData(PressureDataParam pressureData); +} diff --git a/src/main/java/com/casic/service/impl/AlarmServiceImple.java b/src/main/java/com/casic/service/impl/AlarmServiceImple.java new file mode 100644 index 0000000..a675207 --- /dev/null +++ b/src/main/java/com/casic/service/impl/AlarmServiceImple.java @@ -0,0 +1,127 @@ +package com.casic.service.impl; + +import com.alibaba.druid.util.StringUtils; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.dao.AlarmMapper; +import com.casic.dao.BusConfigMapper; +import com.casic.model.*; +import com.casic.service.AlarmService; +import com.casic.util.DeviceDataTableEnum; +import com.casic.util.RedisCommonUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Slf4j +@Service +public class AlarmServiceImple extends ServiceImpl implements AlarmService { + + @Resource + private BusConfigMapper busConfigMapper; + @Resource + private RedisCommonUtil redisCommonUtil; + + public Object getAlarmRecord(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { + ResponseData responseData = new ResponseData(); + try { + Map page = new HashMap(); + page.put("total", this.baseMapper.getAlarmTotalRecord(deviceType, devcode)); + List> alarmRecordList = this.baseMapper.getAlarmRecord(deviceType, devcode, pageSize * (currentIndex - 1), pageSize); + page.put("rows", alarmRecordList); + responseData.setData(alarmRecordList); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},异常信息{}", deviceType, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + @Transactional + public Object excuteAlramBatchCancel(String deviceType, String devcode) { + ResponseData responseData = new ResponseData(); + try { + this.baseMapper.excuteAlramBatchCancel(deviceType, devcode); + this.baseMapper.excuteJobBatchCancel(deviceType, devcode); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("批量消警异常,设备类型{},异常信息{}", deviceType, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + + @Transactional + public Object addAlarmConfig(AlarmConfigParam alarmConfigParam) { + ResponseData responseData = new ResponseData(); + try { + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + addBusConfig(alarmConfigParam); + addRuleConfig(alarmConfigParam); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("风险配置异常,异常信息{}", dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + private void addRuleConfig(AlarmConfigParam alarmConfigParam) { + Map alarmRuleMap = new HashMap(); + alarmRuleMap.put("DEVICE_TYPE", alarmConfigParam.getDeviceType()); + this.baseMapper.deleteByMap(alarmRuleMap); + AlarmLevel alarmRule = new AlarmLevel(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap() + .get(Integer.valueOf(alarmConfigParam.getDeviceType())); + alarmRule.setName(deviceDataTableEnum.getTypeName()); + alarmRule.setHighValue(Float.valueOf(alarmConfigParam.getThresholdVol())); + alarmRule.setTs(new Date()); + alarmRule.setLevel(1); + alarmRule.setDeviceType(alarmConfigParam.getDeviceType()); + this.baseMapper.insert(alarmRule); + } + + private void addBusConfig(AlarmConfigParam alarmConfigParam) { + String devcode = StringUtils.isEmpty(alarmConfigParam.getDevcode()) ? this.baseMapper.getDeviceDevcode(alarmConfigParam.getDeviceType()) : alarmConfigParam.getDevcode(); + sendBusConfig(alarmConfigParam, devcode); + String devcideId = this.baseMapper.getDeviceByDevcode(alarmConfigParam.getDeviceType(), devcode); + BusConfig busConfig = new BusConfig(); + busConfig.setDeviceId(devcideId); + busConfig.setFramecontent("3," + alarmConfigParam.getCollectInterval() + "," + alarmConfigParam.getCollectInterval() + + "," + alarmConfigParam.getRetryNum() + "," + alarmConfigParam.getIp() + "," + alarmConfigParam.getPort()); + busConfig.setSensorid(""); + busConfig.setStatus("0"); + busConfig.setAttemptscurrent(0); + busConfig.setWritetime(new Date()); + busConfig.setAttemptsmax(3); + busConfigMapper.insert(busConfig); + } + + private void sendBusConfig(AlarmConfigParam alarmConfigParam, String devcode) { + CommConfigDTO commConfigDTO = new CommConfigDTO(); + commConfigDTO.setInterval(StringUtils.isEmpty(alarmConfigParam.getCollectInterval()) ? 300 : Long.valueOf(alarmConfigParam.getCollectInterval())); + commConfigDTO.setRepeat(StringUtils.isEmpty(alarmConfigParam.getRetryNum()) ? 300 : Long.valueOf(alarmConfigParam.getRetryNum())); + commConfigDTO.setTimes(Long.valueOf(1)); +// commConfigDTO.setIp(alarmConfigParam.getIp()); +// commConfigDTO.setPort(StringUtils.isEmpty(alarmConfigParam.getPort()) ? 8080 : Long.valueOf(alarmConfigParam.getPort())); + commConfigDTO.setPeriod(StringUtils.isEmpty(alarmConfigParam.getUploadCycle()) ? 300 : Long.valueOf(alarmConfigParam.getUploadCycle())); +// commConfigDTO.setThresh(); + commConfigDTO.setThresh(StringUtils.isEmpty(alarmConfigParam.getThresholdVol()) ? 50: Float.valueOf(alarmConfigParam.getThresholdVol())); + redisCommonUtil.send(commConfigDTO, devcode); + } + + +} diff --git a/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java new file mode 100644 index 0000000..3de704b --- /dev/null +++ b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java @@ -0,0 +1,80 @@ +package com.casic.service.impl; + +import com.casic.dao.DeviceDataMapper; +import com.casic.model.ResponseData; +import com.casic.service.DeviceDataService; +import com.casic.util.DeviceDataFieldTableEnum; +import com.casic.util.DeviceDataTableEnum; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Service +@Slf4j +public class DeviceDataServiceImpl implements DeviceDataService { + + private final DeviceDataMapper deviceDataMapper; + + public DeviceDataServiceImpl(DeviceDataMapper deviceDataMapper) { + this.deviceDataMapper = deviceDataMapper; + } + + public Object getDeviceRecentData(String deviceType, String recentNum, String devcode) { + ResponseData responseData = new ResponseData(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); + try { + String tableName = deviceDataTableEnum.getTableName(); + String fields = DeviceDataFieldTableEnum.TABLE_FIELD.getTableFieldMap().get(tableName); + List> recentDataList = deviceDataMapper.getDeviceRecentData(tableName, recentNum, fields, devcode); + responseData.setData(recentDataList); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备最近数据查询异常,设备类型{},查询数目{},异常信息{}", deviceType, recentNum, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + public Object getDeviceListPage(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { + ResponseData responseData = new ResponseData(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); + try { + String tableName = deviceDataTableEnum.getTableName(); + String fields = DeviceDataFieldTableEnum.TABLE_FIELD.getTableFieldMap().get(tableName); + Map page = new HashMap(); + page.put("total", deviceDataMapper.getDeviceDataTotal(tableName, devcode)); + List> recentDataList = deviceDataMapper.getDeviceDataListPage(tableName, pageSize * (currentIndex - 1), fields, pageSize, devcode); + page.put("rows", recentDataList); + responseData.setData(page); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},当前页{},页大小{},异常信息{}", deviceType, currentIndex, pageSize, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + public Object getLevel(String deviceType) { + ResponseData responseData = new ResponseData(); + try { + String highValue = deviceDataMapper.getLevelByType(deviceType); + responseData.setData(highValue); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},当前页{},页大小{},异常信息{}"); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + +} diff --git a/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java new file mode 100644 index 0000000..6b23451 --- /dev/null +++ b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java @@ -0,0 +1,92 @@ +package com.casic.service.impl; + +import com.alibaba.druid.util.StringUtils; +import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.dao.DataPressureMapper; +import com.casic.model.DataPressure; +import com.casic.model.PressureDataParam; +import com.casic.model.ResponseData; +import com.casic.service.ThirdDataService; +import com.casic.util.CacheUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.stream.Collectors; + +@Service +@Slf4j +public class ThirdDataServiceImpl extends ServiceImpl implements ThirdDataService { + + private final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA); + + public Object getDeviceRecentData(PressureDataParam pressureDataParam) { + ResponseData responseData = new ResponseData(); + try { + batchSave(pressureDataParam); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备最近数据查询异常,设备类型{},异常信息{}", dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + private void batchSave(PressureDataParam pressureDataParam) { + String pressureDataJson = pressureDataParam.getRawData(); + log.info("----" + pressureDataJson); + Map pressureDataMap = JSON.parseObject(pressureDataJson, HashMap.class); + Date uptime = null; + try { + uptime = dateFormat.parse(String.valueOf(pressureDataMap.get("times"))); + } catch (Exception e) { + log.error("主题,采集时间解析异常,异常信息{}", e.getMessage()); + } + List> pressureDataList = (List>) pressureDataMap.get("sensorDatas"); + DataPressure dataPressure = initPrssureData(pressureDataList, uptime); + if (dataPressure == null) { + return; + } + checkAlarm(dataPressure); + } + + private DataPressure initPrssureData(List> pressureDataList, Date uptime) { + DataPressure dataPressure = new DataPressure(); + String devcode = pressureDataList.get(pressureDataList.size() - 1).get("str"); + Map pressureDataMap = pressureDataList.stream().collect( + Collectors.toMap(e -> String.valueOf(e.get("flag")), e -> String.valueOf(e.get("value"))) + ); +// if (CacheUtil.serialBuf.get(devcode)!=null&&CacheUtil.serialBuf.get(devcode).equals(pressureDataMap.get("F"))) { +// return null; +// } + String wellCode = this.baseMapper.getWellCode(devcode); + dataPressure.setWellCode(wellCode); + dataPressure.setDevcode(devcode); + dataPressure.setPci(pressureDataMap.get("Q")); + dataPressure.setCell(Float.valueOf(pressureDataMap.get("V"))); + dataPressure.setTemperature(pressureDataMap.get("T")); + dataPressure.setPress(pressureDataMap.get("F")); + dataPressure.setUptime(dateFormat.format(uptime)); + dataPressure.setLogtime(dateFormat.format(new Date())); + this.baseMapper.insert(dataPressure); +// CacheUtil.serialBuf.put(devcode, pressureDataMap.get("F")); + return dataPressure; + } + + private void checkAlarm(DataPressure dataPressure) { + final Float ruleValue = this.baseMapper.getRuleValue("24"); + if (ruleValue == null) return; + if (!StringUtils.isEmpty(dataPressure.getTemperature()) && !dataPressure.getTemperature().equals("null")) { + if (Float.valueOf(dataPressure.getTemperature()) > ruleValue) { + this.baseMapper.saveRecords(dataPressure.getTemperature(), new Date()); + } + } + } + +} diff --git a/src/main/java/com/casic/util/CacheUtil.java b/src/main/java/com/casic/util/CacheUtil.java new file mode 100644 index 0000000..5b89300 --- /dev/null +++ b/src/main/java/com/casic/util/CacheUtil.java @@ -0,0 +1,16 @@ +package com.casic.util; + +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import java.util.HashMap; +import java.util.Map; + +@Component +public class CacheUtil { + public static volatile Map serialBuf; + @PostConstruct + public void init() { + serialBuf = new HashMap<>(); + } +} diff --git a/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java b/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java new file mode 100644 index 0000000..085c7c3 --- /dev/null +++ b/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java @@ -0,0 +1,39 @@ +package com.casic.util; + +import java.util.HashMap; +import java.util.Map; + +public enum DeviceDataFieldTableEnum { + + TABLE_FIELD(new HashMap() { + { + put("data_dig", "ddata AS dataValue,devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gas", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gasliquid_gas", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gasliquid_liquid", "liquiddata AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gas_dector", "gas_sample_value AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_harmful_gas", "CONCAT(CO, ', ', CH4, ', ', H2S, ', ', O2) AS dataValue,devcode AS devcode,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_hydrant", "0 AS dataValue,devcode AS devcode,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_liquid", "liquiddata AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_noise", "ddata AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_temp_hum", "CONCAT(TEMPERATURE, ', ', HUMIDITY) AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_tube", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_wellcover", "descn AS dataValue,devcode AS devcode,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_temp_press", "press AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_pantilt", "concentration AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_wellcover_loca", "0 AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_wellplus", "0 AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_h2s", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_pressure", "re_val AS dataValue,devcode AS devcode,'' AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + } + }); + public Map tableNameMap; + + DeviceDataFieldTableEnum(Map tableNameMap) { + this.tableNameMap = tableNameMap; + } + + public Map getTableFieldMap() { + return tableNameMap; + } +} diff --git a/src/main/java/com/casic/util/DeviceDataTableEnum.java b/src/main/java/com/casic/util/DeviceDataTableEnum.java new file mode 100644 index 0000000..9698487 --- /dev/null +++ b/src/main/java/com/casic/util/DeviceDataTableEnum.java @@ -0,0 +1,81 @@ +package com.casic.util; + +import java.util.HashMap; + +/** + * @author cz + * @date 2022-7-15 + * 上传数据总记录数 + */ +public enum DeviceDataTableEnum { + + DATA_DIG("data_dig", "开挖监测仪"), + DATA_GAS("data_gas", "燃气智能监测终端"), + DATA_GASLIQUID("data_gasliquid_gas,data_gasliquid_liquid", "燃气智能监测终端(一体化)"), + DATA_GAS_DECTOR("data_gas_dector", "燃气探测仪"), + DATA_HARMFUL_GAS("data_harmful_gas", "有害气体监测仪"), + DATA_HYDRANT("data_hydrant", "消防栓防盗水监测仪"), + DATA_LIQUID("data_liquid", "液位监测仪"), + DATA_NOISE("data_noise", "噪声记录仪"), + DATA_PANTILT("data_pantilt", "激光甲烷云台"), + DATA_TEMP_HUM("data_temp_hum", "温湿度监测仪"), + DATA_TUBE("data_tube", "管盯"), + DATA_WELLCOVER("data_wellcover", "井盖状态监测仪"), + DATA_TEMP_PRESS("data_temp_press", "压力温度检测仪"), + DATA_WELLCOVER_LOCA("data_wellcover_loca", "井盖定位监测仪"), + DATA_WELLPLUS("data_wellplus", "井盖液位一体机"), + DATA_H2S("data_h2s", "硫化氢检测终端"), + DATA_PRESSURE("data_pressure", "压力检测终端"), + DEVICE_TYPE_TABLE(new HashMap() { + { + put(1, DATA_WELLCOVER); + put(2, DATA_LIQUID); + put(3, DATA_HARMFUL_GAS); + put(4, DATA_GAS); + put(5, DATA_TEMP_HUM); + put(6, DATA_DIG); + put(7, DATA_WELLCOVER_LOCA); + put(8, DATA_NOISE); + put(9, DATA_TEMP_PRESS); + put(10, DATA_GASLIQUID); + put(11, DATA_HYDRANT); + put(12, DATA_TUBE); + put(13, DATA_WELLPLUS); + put(14, DATA_H2S); + put(21, DATA_PANTILT); + put(22, DATA_H2S); + put(23, DATA_GAS); + put(24, DATA_TEMP_PRESS); + put(101, DATA_GAS_DECTOR); + } + }); + + String typeName; + String tableName; + + DeviceDataTableEnum(String tableName, String typeName) { + this.typeName = typeName; + this.tableName = tableName; + } + + public String getTypeName() { + return typeName; + } + + public String getTableName() { + return tableName; + } + + + public HashMap tableNameMap; + + DeviceDataTableEnum(HashMap tableNameMap) { + this.tableNameMap = tableNameMap; + } + + public HashMap getTableNameMap() { + return tableNameMap; + } + + +} diff --git a/src/main/java/com/casic/util/RedisCommonUtil.java b/src/main/java/com/casic/util/RedisCommonUtil.java new file mode 100644 index 0000000..a6ce9cf --- /dev/null +++ b/src/main/java/com/casic/util/RedisCommonUtil.java @@ -0,0 +1,29 @@ +package com.casic.util; + +import com.alibaba.fastjson.JSON; +import com.casic.model.CommConfigDTO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; + +import java.util.concurrent.TimeUnit; + +@Component +public class RedisCommonUtil { + + @Value("${casic.device.redis.invalid-time}") + private String invalidTime; + @Value("${casic.device.redis.config-prefix}") + private String configPrefix; + + @Autowired + private RedisTemplate redisTemplate; + + public void send(CommConfigDTO commConfigDTO,String devCode) { + redisTemplate.opsForValue().set(configPrefix+ devCode, + JSON.toJSONString(commConfigDTO), + Integer.valueOf(invalidTime), + TimeUnit.SECONDS); + } +} diff --git a/src/main/java/com/casic/util/SensorIdEum.java b/src/main/java/com/casic/util/SensorIdEum.java new file mode 100644 index 0000000..86b61db --- /dev/null +++ b/src/main/java/com/casic/util/SensorIdEum.java @@ -0,0 +1,30 @@ +package com.casic.util; + +import java.util.HashMap; +import java.util.Map; + +public enum SensorIdEum { + + SENSOR_MAP(new HashMap() { + { + put("燃气智能监测终端", "000044"); + put("有害气体监测仪", "000035"); + put("开挖监测仪", "000064"); + put("温湿度监测仪", "000055"); + put("噪声记录仪", "000032"); + put("液位监测仪", "000034"); + put("燃气智能监测终端(一体化)", "000065"); + put("管盯", "000080"); + } + }); + public Map sensorMap; + + SensorIdEum(Map sensorMap) { + this.sensorMap = sensorMap; + } + + public Map getSensorMap() { + return sensorMap; + } + +} diff --git a/src/main/java/com/casic/util/VerifyConstantUtil.java b/src/main/java/com/casic/util/VerifyConstantUtil.java new file mode 100644 index 0000000..90ee071 --- /dev/null +++ b/src/main/java/com/casic/util/VerifyConstantUtil.java @@ -0,0 +1,11 @@ +package com.casic.util; + +public class VerifyConstantUtil { + + public final static String DEVICE_TYPES = "22,23,24"; + + public static Boolean checkDeviceType(String devcieType) { + return DEVICE_TYPES.contains(devcieType) ? true : false; + } + +} diff --git a/src/main/resources/config/application-dev.yml b/src/main/resources/config/application-dev.yml new file mode 100644 index 0000000..e948b83 --- /dev/null +++ b/src/main/resources/config/application-dev.yml @@ -0,0 +1,32 @@ +server: + port: 11315 +################### spring配置 ################### +spring: + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://111.198.10.15:11102/smartwell_demos?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&serverTimezone=UTC&&allowMultiQueries=true&&useSSL=true + username: root + password: Casic203! + session: + store-type: redis + redis: + host: 111.198.10.15 + port: 11412 + password: ew5T4K3#203lwh + redisValueSerializer: org.springframework.data.redis.serializer.JdkSerializationRedisSerializer + # session: + # store-type: redis +#flowable数据源和多数据源配置 +casic: + kaptcha-open: false #是否开启登录时验证码 (true/false) + #kaptcha-open: false #是否开启登录时验证码 (true/false) + db: + init: + enable: false + spring-session-open: false #开启spring session +logging: + level.root: error + level.com.casic: info + file: + path: logs/ + name: missiles.log \ No newline at end of file diff --git a/src/main/resources/config/application-prod.yml b/src/main/resources/config/application-prod.yml new file mode 100644 index 0000000..4fee268 --- /dev/null +++ b/src/main/resources/config/application-prod.yml @@ -0,0 +1,43 @@ +server: + port: 11312 +################### spring配置 ################### +spring: + datasource: + smartwell: + driver-class-name: org.postgresql.Driver + url: jdbc:postgresql://111.198.10.15:11209/smartwell + username: postgres + password: Casic203 + cms: + driver-class-name: org.postgresql.Driver + url: jdbc:postgresql://111.198.10.15:11209/smartwell_cms + username: postgres + password: Casic203 + span_tilt: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://111.198.10.15:11102/casic_span_tilt?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&serverTimezone=UTC&&allowMultiQueries=true&&useSSL=true + username: root + password: Casic203! + session: + store-type: redis + redis: + host: 111.198.10.15 + port: 11412 + password: ew5T4K3#203lwh + redisValueSerializer: org.springframework.data.redis.serializer.JdkSerializationRedisSerializer + # session: + # store-type: redis +#flowable数据源和多数据源配置 +casic: + kaptcha-open: false #是否开启登录时验证码 (true/false) + #kaptcha-open: false #是否开启登录时验证码 (true/false) + db: + init: + enable: false + spring-session-open: false #开启spring session +logging: + level.root: error + level.com.casic: error + file: + path: logs/ + name: missiles.log \ No newline at end of file diff --git a/src/main/resources/config/application.yml b/src/main/resources/config/application.yml new file mode 100644 index 0000000..4930753 --- /dev/null +++ b/src/main/resources/config/application.yml @@ -0,0 +1,41 @@ +########################################################## +spring: + profiles: + active: dev + servlet: + multipart: + max-file-size: 50MB + max-request-size: 80MB +mybatis-plus: + global-config: + enable-sql-runner: true + configuration: + # 配置结果集属性为空时 是否映射返回结果 + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl #打印sql语句,调试用 + mapper-locations: classpath:mapper/*.xml +mybatis: + mapper-locations: classpath:mapper/*.xml +#mybatis-plus: +# sql-injector: com.baomidou.mybatisplus.mapper.LogicSqlInjector +################### mybatis-plus配置 ################### +################### casic配置 ################### +flowable: + checkProcessDefinitions: false #不校验process文件 +casic: + swagger-open: false #是否开启swagger (true/false) + kaptcha-open: false #是否开启登录时验证码 (true/false) + muti-datasource-open: false #是否开启多数据源(true/false) + spring-session-open: false #是否开启spring session,如果是多机环境需要开启(true/false) + session-invalidate-time: 86400 #session失效时间(只在单机环境下生效,,多机环境在SpringSessionConfig类中配置) 单位:秒 + session-validation-interval: 900 #多久检测一次失效的session(只在单机环境下生效) 单位:秒 + extUrl: sys + device: + redis: + invalid-time: 86400 + host: 127.0.0.1 + port: 6379 + password: ew5T4K3#203lwh + config-prefix: 'Casic:' + config: + export-path: D:\java\boot\guns-web-1.0.0-SNAPSHOT\export\ + config-path: E:\Develop\IdeaProject\smartcity\casic-smartcity-dcms\casic-web\src\main\resources\config\ \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..50f4a19 --- /dev/null +++ b/pom.xml @@ -0,0 +1,161 @@ + + + 4.0.0 + + com.casic + smartwell-demos + 1.0-SNAPSHOT + + + + + jdk-1.8 + + true + 1.8 + + + 1.8 + 1.8 + 1.8 + + + + + + + + + + org.springframework.boot + spring-boot-starter + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-tomcat + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-web + 2.4.5 + + + + + org.springframework.boot + spring-boot-starter-jdbc + 2.4.5 + + + + mysql + mysql-connector-java + 8.0.16 + compile + + + + com.baomidou + mybatis-plus-boot-starter + 3.4.3 + + + + org.projectlombok + lombok + 1.18.20 + + + + + com.alibaba + druid + 1.2.6 + + + + com.alibaba + fastjson + 1.2.73 + + + + commons-codec + commons-codec + 1.14 + + + + redis.clients + jedis + 3.1.0 + jar + + + + org.springframework.data + spring-data-redis + 2.4.8 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.3.RELEASE + + true + + com.casic.CasicApplication + exec + + + + + repackage + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + false + + + + + + + + src/main/resources + + + /config/*/* + /config/*-*.yml + + true + + + src/main/resources + + **/*.xml + + true + + + + + \ No newline at end of file diff --git a/src/main/java/com/casic/CasicApplication.java b/src/main/java/com/casic/CasicApplication.java new file mode 100644 index 0000000..9afd0b9 --- /dev/null +++ b/src/main/java/com/casic/CasicApplication.java @@ -0,0 +1,28 @@ +package com.casic; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.transaction.annotation.EnableTransactionManagement; + + +/** + * SpringBoot方式启动类 + * + * @author cz + * @Date 2022/09/08 14:28 + */ + +@Slf4j +@ComponentScan(basePackages= "com.casic.**") +@SpringBootApplication +public class CasicApplication { + public static void main(String[] args) { + log.info("CasicApplication is success!"); + SpringApplication.run(CasicApplication.class, args); + } +} diff --git a/src/main/java/com/casic/config/CorsConfig.java b/src/main/java/com/casic/config/CorsConfig.java new file mode 100644 index 0000000..7d19680 --- /dev/null +++ b/src/main/java/com/casic/config/CorsConfig.java @@ -0,0 +1,31 @@ +package com.casic.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +/** + * 基础框架 - 跨域请求配置 + */ +@Configuration +public class CorsConfig { + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", buildConfig()); + return new CorsFilter(source); + } + + private CorsConfiguration buildConfig() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + // 1允许任何域名使用 + corsConfiguration.addAllowedOrigin("*"); + // 2允许任何头 + corsConfiguration.addAllowedHeader("*"); + // 3允许任何方法(post、get等) + corsConfiguration.addAllowedMethod("*"); + return corsConfiguration; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/controller/AlarmController.java b/src/main/java/com/casic/controller/AlarmController.java new file mode 100644 index 0000000..957fc36 --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.model.AlarmConfigParam; +import com.casic.service.AlarmService; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/alarm") +public class AlarmController { + + private final AlarmService alarmService; + + public AlarmController(AlarmService alarmService) { + this.alarmService = alarmService; + } + + @RequestMapping("/records") + public Object getAlarmRecord(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "devcode",required =false) String devcode, + @RequestParam(value = "pageSize", required = true) Integer pageSize) { + return alarmService.getAlarmRecord(deviceType,currentIndex,pageSize,devcode); + } + + @RequestMapping("/batch/cancel") + public Object excuteAlramBatchCancel(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "devcode",required =false) String devcode) { + return alarmService.excuteAlramBatchCancel(deviceType,devcode); + } + + @RequestMapping("/config/add") + public Object addAlarmConfig(@RequestBody AlarmConfigParam alarmConfigParam) { + return alarmService.addAlarmConfig(alarmConfigParam); + } +} diff --git a/src/main/java/com/casic/controller/DeviceDataController.java b/src/main/java/com/casic/controller/DeviceDataController.java new file mode 100644 index 0000000..3498b04 --- /dev/null +++ b/src/main/java/com/casic/controller/DeviceDataController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.service.DeviceDataService; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/device") +public class DeviceDataController { + private final DeviceDataService deviceDataService; + + public DeviceDataController(DeviceDataService deviceDataService) { + this.deviceDataService = deviceDataService; + } + + @RequestMapping("/recent-data") + public Object getDeviceRecentData(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "recentNum", required = true) String recentNum, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceRecentData(deviceType, recentNum, devcode); + } + + @RequestMapping("/data/list-page") + public Object getDeviceListPage(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "pageSize", required = true) Integer pageSize, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceListPage(deviceType, currentIndex, pageSize, devcode); + } + + @RequestMapping("/level/{deviceType}") + public Object getLevelList(@PathVariable("deviceType")String deviceType) { + return deviceDataService.getLevel(deviceType); + } + +} diff --git a/src/main/java/com/casic/controller/ThirdDataController.java b/src/main/java/com/casic/controller/ThirdDataController.java new file mode 100644 index 0000000..b9b2b42 --- /dev/null +++ b/src/main/java/com/casic/controller/ThirdDataController.java @@ -0,0 +1,28 @@ +package com.casic.controller; + +import com.casic.model.PressureDataParam; +import com.casic.service.ThirdDataService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +@RestController +@RequestMapping("/push") +@Slf4j +public class ThirdDataController { + + private final ThirdDataService thirdDataService; + + public ThirdDataController(ThirdDataService thirdDataService) { + this.thirdDataService = thirdDataService; + } + + @RequestMapping("/pressure/data") + public Object getDeviceRecentData(@RequestBody PressureDataParam pressureData) { + return thirdDataService.getDeviceRecentData(pressureData); + } + +} diff --git a/src/main/java/com/casic/dao/AlarmMapper.java b/src/main/java/com/casic/dao/AlarmMapper.java new file mode 100644 index 0000000..a442e3a --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmMapper.java @@ -0,0 +1,28 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmLevel; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + +@Mapper +public interface AlarmMapper extends BaseMapper { + + List> getAlarmRecord(@Param("deviceType") String deviceType, + @Param("devcode") String devcode, + @Param("currentIndex") Integer currentIndex, @Param("pageSize") Integer pageSize); + + Integer getAlarmTotalRecord(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteAlramBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteJobBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + String getDeviceDevcode(@Param("deviceType") String deviceType); + + String getDeviceByDevcode(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + +} diff --git a/src/main/java/com/casic/dao/BusConfigMapper.java b/src/main/java/com/casic/dao/BusConfigMapper.java new file mode 100644 index 0000000..ccf76da --- /dev/null +++ b/src/main/java/com/casic/dao/BusConfigMapper.java @@ -0,0 +1,9 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.BusConfig; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface BusConfigMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/dao/DataPressureMapper.java b/src/main/java/com/casic/dao/DataPressureMapper.java new file mode 100644 index 0000000..05f4329 --- /dev/null +++ b/src/main/java/com/casic/dao/DataPressureMapper.java @@ -0,0 +1,19 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.DataPressure; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.Date; + +@Mapper +public interface DataPressureMapper extends BaseMapper { + + String getWellCode(@Param("devcode") String devcode); + + Float getRuleValue(@Param("deviceType") String deviceType); + + void saveRecords(@Param("reValue") String reValue, @Param("alarmTime") Date alarmTime); + +} diff --git a/src/main/java/com/casic/dao/DeviceDataMapper.java b/src/main/java/com/casic/dao/DeviceDataMapper.java new file mode 100644 index 0000000..d9e18a0 --- /dev/null +++ b/src/main/java/com/casic/dao/DeviceDataMapper.java @@ -0,0 +1,27 @@ +package com.casic.dao; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + + +@Mapper +public interface DeviceDataMapper { + + List> getDeviceRecentData(@Param("tableName") String tableName, + @Param("recentNum") String recentNum, + @Param("fields") String fields, + @Param("devcode") String devcode); + + Integer getDeviceDataTotal(@Param("tableName") String tableName, @Param("devcode") String devcode); + + List> getDeviceDataListPage(@Param("tableName") String tableName, + @Param("currentIndex") Integer currentIndex, + @Param("fields") String fields, + @Param("pageSize") Integer pageSize, + @Param("devcode") String devcode); + + String getLevelByType(@Param("deviceType")String deviceType); +} diff --git a/src/main/java/com/casic/model/AlarmConfigParam.java b/src/main/java/com/casic/model/AlarmConfigParam.java new file mode 100644 index 0000000..28150d6 --- /dev/null +++ b/src/main/java/com/casic/model/AlarmConfigParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class AlarmConfigParam { + private String deviceType; + private String thresholdVol; + private String collectInterval; + private String uploadCycle; + private String retryNum; + private String ip; + private String port; + private String devcode; +} diff --git a/src/main/java/com/casic/model/AlarmLevel.java b/src/main/java/com/casic/model/AlarmLevel.java new file mode 100644 index 0000000..d0909af --- /dev/null +++ b/src/main/java/com/casic/model/AlarmLevel.java @@ -0,0 +1,26 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("alarm_level") +public class AlarmLevel{ + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + private String name; + private String deviceType; + private Integer level; + private Float lowValue; + private Float highValue; + private String openAlarm; + private String openJob; + private Date ts; + private String tenantId; + +} diff --git a/src/main/java/com/casic/model/BusConfig.java b/src/main/java/com/casic/model/BusConfig.java new file mode 100644 index 0000000..c6b7b50 --- /dev/null +++ b/src/main/java/com/casic/model/BusConfig.java @@ -0,0 +1,27 @@ +package com.casic.model; + + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +import java.util.Date; + +@Data +public class BusConfig { + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + + private String deviceId; + private String framecontent; + private String sensorid; + private String sensorcode; + + private String status; + private Integer attemptsmax; + private Integer attemptscurrent; + private Date sendtime; + private Date writetime; + +} diff --git a/src/main/java/com/casic/model/CommConfigDTO.java b/src/main/java/com/casic/model/CommConfigDTO.java new file mode 100644 index 0000000..7da699c --- /dev/null +++ b/src/main/java/com/casic/model/CommConfigDTO.java @@ -0,0 +1,41 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class CommConfigDTO { + private String acqStart;//采集开始时间 + private Long interval;//采集时间间隔(分钟) + private Long period;//上传周期 + private Long times;//采集次数 + private Long repeat;//重传次数 + private String ip; + private Long port; + private Float thresh; + private Float height; + private String collect; + private String MultiCollect; + private String acqCycle; + private String upCycle; + private String sleepStartTime; + + private String acqStartFlow ; //流量采集开始时间 + private Long intervalFlow; //流量采集采集间隔(分) + private Long acqTimesFlow ;//流量采集次数 + private String upStartFlow; //流量上报开始时间 + private Long upTimesFlow; //流量上传次数 + private String acqStartNoise; //噪声采集开始时间 + private Long intervalNoise; //噪声采集采集间隔(分) + private Long acqTimesNoise;//噪声采集次数 + private String upStartNoise; //噪声上报开始时间 + private Long upTimesNoise ;//噪声上传次数 + private String acqStartPressure; //压力采集开始时间 + private Long intervalPressure;//压力采集采集间隔(分) + private Long acqTimesPressure; //压力采集次数 + private String upStartPressure; //压力上报开始时间 + private Long upTimesPressure; //压力上传次数 + private Float lowerLimitPressure; //压力报警下限 + private Float upperLimitPressure ;//压力报警下限 + private Long limitDig ;//开挖阈值 + private Float threshold ;//开挖阈值 +} diff --git a/src/main/java/com/casic/model/DataPressure.java b/src/main/java/com/casic/model/DataPressure.java new file mode 100644 index 0000000..8270c70 --- /dev/null +++ b/src/main/java/com/casic/model/DataPressure.java @@ -0,0 +1,33 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("data_temp_press") +public class DataPressure { + + @TableId(value = "ID", type = IdType.AUTO) + private String id; + private String wellCode; + private String devcode; + private Float cell; + private String temperature; + + private String press; + private String descn; + private String uptime; + private String logtime; + /** + * 信号强度 + */ + private String pci; + + private String rsrp; + private String snr; + +} diff --git a/src/main/java/com/casic/model/PressureDataParam.java b/src/main/java/com/casic/model/PressureDataParam.java new file mode 100644 index 0000000..f42770d --- /dev/null +++ b/src/main/java/com/casic/model/PressureDataParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class PressureDataParam { + private String flag; + private String deviceUserid; + private String parentUserId; + private Object sensorsDates; + private String time; + private String rawData; + private String deviceId; +} + diff --git a/src/main/java/com/casic/model/ResponseData.java b/src/main/java/com/casic/model/ResponseData.java new file mode 100644 index 0000000..245ab04 --- /dev/null +++ b/src/main/java/com/casic/model/ResponseData.java @@ -0,0 +1,18 @@ +package com.casic.model; + +import lombok.Data; + +/** + * @author cz + * @date 2022-8-12 + */ +@Data +public class ResponseData { + public static final String DEFAULT_SUCCESS_MESSAGE = "请求成功"; + public static final String DEFAULT_ERROR_MESSAGE = "网络异常"; + public static final Integer DEFAULT_SUCCESS_CODE = 200; + public static final Integer DEFAULT_ERROR_CODE = 500; + private Integer code; + private String message; + private Object data; +} \ No newline at end of file diff --git a/src/main/java/com/casic/service/AlarmService.java b/src/main/java/com/casic/service/AlarmService.java new file mode 100644 index 0000000..8516b41 --- /dev/null +++ b/src/main/java/com/casic/service/AlarmService.java @@ -0,0 +1,12 @@ +package com.casic.service; + +import com.casic.model.AlarmConfigParam; + +public interface AlarmService { + + Object getAlarmRecord(String deviceType,Integer currentIndex,Integer pageSize,String devcode); + + Object excuteAlramBatchCancel(String deviceType,String devcode); + + Object addAlarmConfig(AlarmConfigParam alarmConfig); +} diff --git a/src/main/java/com/casic/service/DeviceDataService.java b/src/main/java/com/casic/service/DeviceDataService.java new file mode 100644 index 0000000..db656c1 --- /dev/null +++ b/src/main/java/com/casic/service/DeviceDataService.java @@ -0,0 +1,10 @@ +package com.casic.service; + +public interface DeviceDataService { + + Object getDeviceRecentData(String deviceType, String recentNum, String devcode); + + Object getDeviceListPage(String deviceType, Integer currentIndex, Integer pageSize, String devcode); + + Object getLevel(String deviceType); +} diff --git a/src/main/java/com/casic/service/ThirdDataService.java b/src/main/java/com/casic/service/ThirdDataService.java new file mode 100644 index 0000000..795e0b2 --- /dev/null +++ b/src/main/java/com/casic/service/ThirdDataService.java @@ -0,0 +1,8 @@ +package com.casic.service; + +import com.casic.model.PressureDataParam; + +public interface ThirdDataService { + + Object getDeviceRecentData(PressureDataParam pressureData); +} diff --git a/src/main/java/com/casic/service/impl/AlarmServiceImple.java b/src/main/java/com/casic/service/impl/AlarmServiceImple.java new file mode 100644 index 0000000..a675207 --- /dev/null +++ b/src/main/java/com/casic/service/impl/AlarmServiceImple.java @@ -0,0 +1,127 @@ +package com.casic.service.impl; + +import com.alibaba.druid.util.StringUtils; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.dao.AlarmMapper; +import com.casic.dao.BusConfigMapper; +import com.casic.model.*; +import com.casic.service.AlarmService; +import com.casic.util.DeviceDataTableEnum; +import com.casic.util.RedisCommonUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Slf4j +@Service +public class AlarmServiceImple extends ServiceImpl implements AlarmService { + + @Resource + private BusConfigMapper busConfigMapper; + @Resource + private RedisCommonUtil redisCommonUtil; + + public Object getAlarmRecord(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { + ResponseData responseData = new ResponseData(); + try { + Map page = new HashMap(); + page.put("total", this.baseMapper.getAlarmTotalRecord(deviceType, devcode)); + List> alarmRecordList = this.baseMapper.getAlarmRecord(deviceType, devcode, pageSize * (currentIndex - 1), pageSize); + page.put("rows", alarmRecordList); + responseData.setData(alarmRecordList); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},异常信息{}", deviceType, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + @Transactional + public Object excuteAlramBatchCancel(String deviceType, String devcode) { + ResponseData responseData = new ResponseData(); + try { + this.baseMapper.excuteAlramBatchCancel(deviceType, devcode); + this.baseMapper.excuteJobBatchCancel(deviceType, devcode); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("批量消警异常,设备类型{},异常信息{}", deviceType, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + + @Transactional + public Object addAlarmConfig(AlarmConfigParam alarmConfigParam) { + ResponseData responseData = new ResponseData(); + try { + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + addBusConfig(alarmConfigParam); + addRuleConfig(alarmConfigParam); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("风险配置异常,异常信息{}", dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + private void addRuleConfig(AlarmConfigParam alarmConfigParam) { + Map alarmRuleMap = new HashMap(); + alarmRuleMap.put("DEVICE_TYPE", alarmConfigParam.getDeviceType()); + this.baseMapper.deleteByMap(alarmRuleMap); + AlarmLevel alarmRule = new AlarmLevel(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap() + .get(Integer.valueOf(alarmConfigParam.getDeviceType())); + alarmRule.setName(deviceDataTableEnum.getTypeName()); + alarmRule.setHighValue(Float.valueOf(alarmConfigParam.getThresholdVol())); + alarmRule.setTs(new Date()); + alarmRule.setLevel(1); + alarmRule.setDeviceType(alarmConfigParam.getDeviceType()); + this.baseMapper.insert(alarmRule); + } + + private void addBusConfig(AlarmConfigParam alarmConfigParam) { + String devcode = StringUtils.isEmpty(alarmConfigParam.getDevcode()) ? this.baseMapper.getDeviceDevcode(alarmConfigParam.getDeviceType()) : alarmConfigParam.getDevcode(); + sendBusConfig(alarmConfigParam, devcode); + String devcideId = this.baseMapper.getDeviceByDevcode(alarmConfigParam.getDeviceType(), devcode); + BusConfig busConfig = new BusConfig(); + busConfig.setDeviceId(devcideId); + busConfig.setFramecontent("3," + alarmConfigParam.getCollectInterval() + "," + alarmConfigParam.getCollectInterval() + + "," + alarmConfigParam.getRetryNum() + "," + alarmConfigParam.getIp() + "," + alarmConfigParam.getPort()); + busConfig.setSensorid(""); + busConfig.setStatus("0"); + busConfig.setAttemptscurrent(0); + busConfig.setWritetime(new Date()); + busConfig.setAttemptsmax(3); + busConfigMapper.insert(busConfig); + } + + private void sendBusConfig(AlarmConfigParam alarmConfigParam, String devcode) { + CommConfigDTO commConfigDTO = new CommConfigDTO(); + commConfigDTO.setInterval(StringUtils.isEmpty(alarmConfigParam.getCollectInterval()) ? 300 : Long.valueOf(alarmConfigParam.getCollectInterval())); + commConfigDTO.setRepeat(StringUtils.isEmpty(alarmConfigParam.getRetryNum()) ? 300 : Long.valueOf(alarmConfigParam.getRetryNum())); + commConfigDTO.setTimes(Long.valueOf(1)); +// commConfigDTO.setIp(alarmConfigParam.getIp()); +// commConfigDTO.setPort(StringUtils.isEmpty(alarmConfigParam.getPort()) ? 8080 : Long.valueOf(alarmConfigParam.getPort())); + commConfigDTO.setPeriod(StringUtils.isEmpty(alarmConfigParam.getUploadCycle()) ? 300 : Long.valueOf(alarmConfigParam.getUploadCycle())); +// commConfigDTO.setThresh(); + commConfigDTO.setThresh(StringUtils.isEmpty(alarmConfigParam.getThresholdVol()) ? 50: Float.valueOf(alarmConfigParam.getThresholdVol())); + redisCommonUtil.send(commConfigDTO, devcode); + } + + +} diff --git a/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java new file mode 100644 index 0000000..3de704b --- /dev/null +++ b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java @@ -0,0 +1,80 @@ +package com.casic.service.impl; + +import com.casic.dao.DeviceDataMapper; +import com.casic.model.ResponseData; +import com.casic.service.DeviceDataService; +import com.casic.util.DeviceDataFieldTableEnum; +import com.casic.util.DeviceDataTableEnum; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Service +@Slf4j +public class DeviceDataServiceImpl implements DeviceDataService { + + private final DeviceDataMapper deviceDataMapper; + + public DeviceDataServiceImpl(DeviceDataMapper deviceDataMapper) { + this.deviceDataMapper = deviceDataMapper; + } + + public Object getDeviceRecentData(String deviceType, String recentNum, String devcode) { + ResponseData responseData = new ResponseData(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); + try { + String tableName = deviceDataTableEnum.getTableName(); + String fields = DeviceDataFieldTableEnum.TABLE_FIELD.getTableFieldMap().get(tableName); + List> recentDataList = deviceDataMapper.getDeviceRecentData(tableName, recentNum, fields, devcode); + responseData.setData(recentDataList); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备最近数据查询异常,设备类型{},查询数目{},异常信息{}", deviceType, recentNum, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + public Object getDeviceListPage(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { + ResponseData responseData = new ResponseData(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); + try { + String tableName = deviceDataTableEnum.getTableName(); + String fields = DeviceDataFieldTableEnum.TABLE_FIELD.getTableFieldMap().get(tableName); + Map page = new HashMap(); + page.put("total", deviceDataMapper.getDeviceDataTotal(tableName, devcode)); + List> recentDataList = deviceDataMapper.getDeviceDataListPage(tableName, pageSize * (currentIndex - 1), fields, pageSize, devcode); + page.put("rows", recentDataList); + responseData.setData(page); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},当前页{},页大小{},异常信息{}", deviceType, currentIndex, pageSize, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + public Object getLevel(String deviceType) { + ResponseData responseData = new ResponseData(); + try { + String highValue = deviceDataMapper.getLevelByType(deviceType); + responseData.setData(highValue); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},当前页{},页大小{},异常信息{}"); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + +} diff --git a/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java new file mode 100644 index 0000000..6b23451 --- /dev/null +++ b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java @@ -0,0 +1,92 @@ +package com.casic.service.impl; + +import com.alibaba.druid.util.StringUtils; +import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.dao.DataPressureMapper; +import com.casic.model.DataPressure; +import com.casic.model.PressureDataParam; +import com.casic.model.ResponseData; +import com.casic.service.ThirdDataService; +import com.casic.util.CacheUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.stream.Collectors; + +@Service +@Slf4j +public class ThirdDataServiceImpl extends ServiceImpl implements ThirdDataService { + + private final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA); + + public Object getDeviceRecentData(PressureDataParam pressureDataParam) { + ResponseData responseData = new ResponseData(); + try { + batchSave(pressureDataParam); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备最近数据查询异常,设备类型{},异常信息{}", dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + private void batchSave(PressureDataParam pressureDataParam) { + String pressureDataJson = pressureDataParam.getRawData(); + log.info("----" + pressureDataJson); + Map pressureDataMap = JSON.parseObject(pressureDataJson, HashMap.class); + Date uptime = null; + try { + uptime = dateFormat.parse(String.valueOf(pressureDataMap.get("times"))); + } catch (Exception e) { + log.error("主题,采集时间解析异常,异常信息{}", e.getMessage()); + } + List> pressureDataList = (List>) pressureDataMap.get("sensorDatas"); + DataPressure dataPressure = initPrssureData(pressureDataList, uptime); + if (dataPressure == null) { + return; + } + checkAlarm(dataPressure); + } + + private DataPressure initPrssureData(List> pressureDataList, Date uptime) { + DataPressure dataPressure = new DataPressure(); + String devcode = pressureDataList.get(pressureDataList.size() - 1).get("str"); + Map pressureDataMap = pressureDataList.stream().collect( + Collectors.toMap(e -> String.valueOf(e.get("flag")), e -> String.valueOf(e.get("value"))) + ); +// if (CacheUtil.serialBuf.get(devcode)!=null&&CacheUtil.serialBuf.get(devcode).equals(pressureDataMap.get("F"))) { +// return null; +// } + String wellCode = this.baseMapper.getWellCode(devcode); + dataPressure.setWellCode(wellCode); + dataPressure.setDevcode(devcode); + dataPressure.setPci(pressureDataMap.get("Q")); + dataPressure.setCell(Float.valueOf(pressureDataMap.get("V"))); + dataPressure.setTemperature(pressureDataMap.get("T")); + dataPressure.setPress(pressureDataMap.get("F")); + dataPressure.setUptime(dateFormat.format(uptime)); + dataPressure.setLogtime(dateFormat.format(new Date())); + this.baseMapper.insert(dataPressure); +// CacheUtil.serialBuf.put(devcode, pressureDataMap.get("F")); + return dataPressure; + } + + private void checkAlarm(DataPressure dataPressure) { + final Float ruleValue = this.baseMapper.getRuleValue("24"); + if (ruleValue == null) return; + if (!StringUtils.isEmpty(dataPressure.getTemperature()) && !dataPressure.getTemperature().equals("null")) { + if (Float.valueOf(dataPressure.getTemperature()) > ruleValue) { + this.baseMapper.saveRecords(dataPressure.getTemperature(), new Date()); + } + } + } + +} diff --git a/src/main/java/com/casic/util/CacheUtil.java b/src/main/java/com/casic/util/CacheUtil.java new file mode 100644 index 0000000..5b89300 --- /dev/null +++ b/src/main/java/com/casic/util/CacheUtil.java @@ -0,0 +1,16 @@ +package com.casic.util; + +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import java.util.HashMap; +import java.util.Map; + +@Component +public class CacheUtil { + public static volatile Map serialBuf; + @PostConstruct + public void init() { + serialBuf = new HashMap<>(); + } +} diff --git a/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java b/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java new file mode 100644 index 0000000..085c7c3 --- /dev/null +++ b/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java @@ -0,0 +1,39 @@ +package com.casic.util; + +import java.util.HashMap; +import java.util.Map; + +public enum DeviceDataFieldTableEnum { + + TABLE_FIELD(new HashMap() { + { + put("data_dig", "ddata AS dataValue,devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gas", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gasliquid_gas", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gasliquid_liquid", "liquiddata AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gas_dector", "gas_sample_value AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_harmful_gas", "CONCAT(CO, ', ', CH4, ', ', H2S, ', ', O2) AS dataValue,devcode AS devcode,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_hydrant", "0 AS dataValue,devcode AS devcode,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_liquid", "liquiddata AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_noise", "ddata AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_temp_hum", "CONCAT(TEMPERATURE, ', ', HUMIDITY) AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_tube", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_wellcover", "descn AS dataValue,devcode AS devcode,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_temp_press", "press AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_pantilt", "concentration AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_wellcover_loca", "0 AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_wellplus", "0 AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_h2s", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_pressure", "re_val AS dataValue,devcode AS devcode,'' AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + } + }); + public Map tableNameMap; + + DeviceDataFieldTableEnum(Map tableNameMap) { + this.tableNameMap = tableNameMap; + } + + public Map getTableFieldMap() { + return tableNameMap; + } +} diff --git a/src/main/java/com/casic/util/DeviceDataTableEnum.java b/src/main/java/com/casic/util/DeviceDataTableEnum.java new file mode 100644 index 0000000..9698487 --- /dev/null +++ b/src/main/java/com/casic/util/DeviceDataTableEnum.java @@ -0,0 +1,81 @@ +package com.casic.util; + +import java.util.HashMap; + +/** + * @author cz + * @date 2022-7-15 + * 上传数据总记录数 + */ +public enum DeviceDataTableEnum { + + DATA_DIG("data_dig", "开挖监测仪"), + DATA_GAS("data_gas", "燃气智能监测终端"), + DATA_GASLIQUID("data_gasliquid_gas,data_gasliquid_liquid", "燃气智能监测终端(一体化)"), + DATA_GAS_DECTOR("data_gas_dector", "燃气探测仪"), + DATA_HARMFUL_GAS("data_harmful_gas", "有害气体监测仪"), + DATA_HYDRANT("data_hydrant", "消防栓防盗水监测仪"), + DATA_LIQUID("data_liquid", "液位监测仪"), + DATA_NOISE("data_noise", "噪声记录仪"), + DATA_PANTILT("data_pantilt", "激光甲烷云台"), + DATA_TEMP_HUM("data_temp_hum", "温湿度监测仪"), + DATA_TUBE("data_tube", "管盯"), + DATA_WELLCOVER("data_wellcover", "井盖状态监测仪"), + DATA_TEMP_PRESS("data_temp_press", "压力温度检测仪"), + DATA_WELLCOVER_LOCA("data_wellcover_loca", "井盖定位监测仪"), + DATA_WELLPLUS("data_wellplus", "井盖液位一体机"), + DATA_H2S("data_h2s", "硫化氢检测终端"), + DATA_PRESSURE("data_pressure", "压力检测终端"), + DEVICE_TYPE_TABLE(new HashMap() { + { + put(1, DATA_WELLCOVER); + put(2, DATA_LIQUID); + put(3, DATA_HARMFUL_GAS); + put(4, DATA_GAS); + put(5, DATA_TEMP_HUM); + put(6, DATA_DIG); + put(7, DATA_WELLCOVER_LOCA); + put(8, DATA_NOISE); + put(9, DATA_TEMP_PRESS); + put(10, DATA_GASLIQUID); + put(11, DATA_HYDRANT); + put(12, DATA_TUBE); + put(13, DATA_WELLPLUS); + put(14, DATA_H2S); + put(21, DATA_PANTILT); + put(22, DATA_H2S); + put(23, DATA_GAS); + put(24, DATA_TEMP_PRESS); + put(101, DATA_GAS_DECTOR); + } + }); + + String typeName; + String tableName; + + DeviceDataTableEnum(String tableName, String typeName) { + this.typeName = typeName; + this.tableName = tableName; + } + + public String getTypeName() { + return typeName; + } + + public String getTableName() { + return tableName; + } + + + public HashMap tableNameMap; + + DeviceDataTableEnum(HashMap tableNameMap) { + this.tableNameMap = tableNameMap; + } + + public HashMap getTableNameMap() { + return tableNameMap; + } + + +} diff --git a/src/main/java/com/casic/util/RedisCommonUtil.java b/src/main/java/com/casic/util/RedisCommonUtil.java new file mode 100644 index 0000000..a6ce9cf --- /dev/null +++ b/src/main/java/com/casic/util/RedisCommonUtil.java @@ -0,0 +1,29 @@ +package com.casic.util; + +import com.alibaba.fastjson.JSON; +import com.casic.model.CommConfigDTO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; + +import java.util.concurrent.TimeUnit; + +@Component +public class RedisCommonUtil { + + @Value("${casic.device.redis.invalid-time}") + private String invalidTime; + @Value("${casic.device.redis.config-prefix}") + private String configPrefix; + + @Autowired + private RedisTemplate redisTemplate; + + public void send(CommConfigDTO commConfigDTO,String devCode) { + redisTemplate.opsForValue().set(configPrefix+ devCode, + JSON.toJSONString(commConfigDTO), + Integer.valueOf(invalidTime), + TimeUnit.SECONDS); + } +} diff --git a/src/main/java/com/casic/util/SensorIdEum.java b/src/main/java/com/casic/util/SensorIdEum.java new file mode 100644 index 0000000..86b61db --- /dev/null +++ b/src/main/java/com/casic/util/SensorIdEum.java @@ -0,0 +1,30 @@ +package com.casic.util; + +import java.util.HashMap; +import java.util.Map; + +public enum SensorIdEum { + + SENSOR_MAP(new HashMap() { + { + put("燃气智能监测终端", "000044"); + put("有害气体监测仪", "000035"); + put("开挖监测仪", "000064"); + put("温湿度监测仪", "000055"); + put("噪声记录仪", "000032"); + put("液位监测仪", "000034"); + put("燃气智能监测终端(一体化)", "000065"); + put("管盯", "000080"); + } + }); + public Map sensorMap; + + SensorIdEum(Map sensorMap) { + this.sensorMap = sensorMap; + } + + public Map getSensorMap() { + return sensorMap; + } + +} diff --git a/src/main/java/com/casic/util/VerifyConstantUtil.java b/src/main/java/com/casic/util/VerifyConstantUtil.java new file mode 100644 index 0000000..90ee071 --- /dev/null +++ b/src/main/java/com/casic/util/VerifyConstantUtil.java @@ -0,0 +1,11 @@ +package com.casic.util; + +public class VerifyConstantUtil { + + public final static String DEVICE_TYPES = "22,23,24"; + + public static Boolean checkDeviceType(String devcieType) { + return DEVICE_TYPES.contains(devcieType) ? true : false; + } + +} diff --git a/src/main/resources/config/application-dev.yml b/src/main/resources/config/application-dev.yml new file mode 100644 index 0000000..e948b83 --- /dev/null +++ b/src/main/resources/config/application-dev.yml @@ -0,0 +1,32 @@ +server: + port: 11315 +################### spring配置 ################### +spring: + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://111.198.10.15:11102/smartwell_demos?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&serverTimezone=UTC&&allowMultiQueries=true&&useSSL=true + username: root + password: Casic203! + session: + store-type: redis + redis: + host: 111.198.10.15 + port: 11412 + password: ew5T4K3#203lwh + redisValueSerializer: org.springframework.data.redis.serializer.JdkSerializationRedisSerializer + # session: + # store-type: redis +#flowable数据源和多数据源配置 +casic: + kaptcha-open: false #是否开启登录时验证码 (true/false) + #kaptcha-open: false #是否开启登录时验证码 (true/false) + db: + init: + enable: false + spring-session-open: false #开启spring session +logging: + level.root: error + level.com.casic: info + file: + path: logs/ + name: missiles.log \ No newline at end of file diff --git a/src/main/resources/config/application-prod.yml b/src/main/resources/config/application-prod.yml new file mode 100644 index 0000000..4fee268 --- /dev/null +++ b/src/main/resources/config/application-prod.yml @@ -0,0 +1,43 @@ +server: + port: 11312 +################### spring配置 ################### +spring: + datasource: + smartwell: + driver-class-name: org.postgresql.Driver + url: jdbc:postgresql://111.198.10.15:11209/smartwell + username: postgres + password: Casic203 + cms: + driver-class-name: org.postgresql.Driver + url: jdbc:postgresql://111.198.10.15:11209/smartwell_cms + username: postgres + password: Casic203 + span_tilt: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://111.198.10.15:11102/casic_span_tilt?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&serverTimezone=UTC&&allowMultiQueries=true&&useSSL=true + username: root + password: Casic203! + session: + store-type: redis + redis: + host: 111.198.10.15 + port: 11412 + password: ew5T4K3#203lwh + redisValueSerializer: org.springframework.data.redis.serializer.JdkSerializationRedisSerializer + # session: + # store-type: redis +#flowable数据源和多数据源配置 +casic: + kaptcha-open: false #是否开启登录时验证码 (true/false) + #kaptcha-open: false #是否开启登录时验证码 (true/false) + db: + init: + enable: false + spring-session-open: false #开启spring session +logging: + level.root: error + level.com.casic: error + file: + path: logs/ + name: missiles.log \ No newline at end of file diff --git a/src/main/resources/config/application.yml b/src/main/resources/config/application.yml new file mode 100644 index 0000000..4930753 --- /dev/null +++ b/src/main/resources/config/application.yml @@ -0,0 +1,41 @@ +########################################################## +spring: + profiles: + active: dev + servlet: + multipart: + max-file-size: 50MB + max-request-size: 80MB +mybatis-plus: + global-config: + enable-sql-runner: true + configuration: + # 配置结果集属性为空时 是否映射返回结果 + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl #打印sql语句,调试用 + mapper-locations: classpath:mapper/*.xml +mybatis: + mapper-locations: classpath:mapper/*.xml +#mybatis-plus: +# sql-injector: com.baomidou.mybatisplus.mapper.LogicSqlInjector +################### mybatis-plus配置 ################### +################### casic配置 ################### +flowable: + checkProcessDefinitions: false #不校验process文件 +casic: + swagger-open: false #是否开启swagger (true/false) + kaptcha-open: false #是否开启登录时验证码 (true/false) + muti-datasource-open: false #是否开启多数据源(true/false) + spring-session-open: false #是否开启spring session,如果是多机环境需要开启(true/false) + session-invalidate-time: 86400 #session失效时间(只在单机环境下生效,,多机环境在SpringSessionConfig类中配置) 单位:秒 + session-validation-interval: 900 #多久检测一次失效的session(只在单机环境下生效) 单位:秒 + extUrl: sys + device: + redis: + invalid-time: 86400 + host: 127.0.0.1 + port: 6379 + password: ew5T4K3#203lwh + config-prefix: 'Casic:' + config: + export-path: D:\java\boot\guns-web-1.0.0-SNAPSHOT\export\ + config-path: E:\Develop\IdeaProject\smartcity\casic-smartcity-dcms\casic-web\src\main\resources\config\ \ No newline at end of file diff --git a/src/main/resources/mapper/AlarmMapper.xml b/src/main/resources/mapper/AlarmMapper.xml new file mode 100644 index 0000000..2a1c28d --- /dev/null +++ b/src/main/resources/mapper/AlarmMapper.xml @@ -0,0 +1,75 @@ + + + + + + + + + + update alarm_records + set status='2' + WHERE devcode in ( + SELECT devcode + FROM bus_device + WHERE DEVICE_TYPE=#{deviceType} + + and devcode = #{devcode} + + ) + + + + update alarm_job + set JOB_STATUS='4' + WHERE devcode in( + SELECT devcode + FROM bus_device + WHERE DEVICE_TYPE=#{deviceType} + + and devcode = #{devcode} + + ) + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..50f4a19 --- /dev/null +++ b/pom.xml @@ -0,0 +1,161 @@ + + + 4.0.0 + + com.casic + smartwell-demos + 1.0-SNAPSHOT + + + + + jdk-1.8 + + true + 1.8 + + + 1.8 + 1.8 + 1.8 + + + + + + + + + + org.springframework.boot + spring-boot-starter + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-tomcat + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-web + 2.4.5 + + + + + org.springframework.boot + spring-boot-starter-jdbc + 2.4.5 + + + + mysql + mysql-connector-java + 8.0.16 + compile + + + + com.baomidou + mybatis-plus-boot-starter + 3.4.3 + + + + org.projectlombok + lombok + 1.18.20 + + + + + com.alibaba + druid + 1.2.6 + + + + com.alibaba + fastjson + 1.2.73 + + + + commons-codec + commons-codec + 1.14 + + + + redis.clients + jedis + 3.1.0 + jar + + + + org.springframework.data + spring-data-redis + 2.4.8 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.3.RELEASE + + true + + com.casic.CasicApplication + exec + + + + + repackage + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + false + + + + + + + + src/main/resources + + + /config/*/* + /config/*-*.yml + + true + + + src/main/resources + + **/*.xml + + true + + + + + \ No newline at end of file diff --git a/src/main/java/com/casic/CasicApplication.java b/src/main/java/com/casic/CasicApplication.java new file mode 100644 index 0000000..9afd0b9 --- /dev/null +++ b/src/main/java/com/casic/CasicApplication.java @@ -0,0 +1,28 @@ +package com.casic; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.transaction.annotation.EnableTransactionManagement; + + +/** + * SpringBoot方式启动类 + * + * @author cz + * @Date 2022/09/08 14:28 + */ + +@Slf4j +@ComponentScan(basePackages= "com.casic.**") +@SpringBootApplication +public class CasicApplication { + public static void main(String[] args) { + log.info("CasicApplication is success!"); + SpringApplication.run(CasicApplication.class, args); + } +} diff --git a/src/main/java/com/casic/config/CorsConfig.java b/src/main/java/com/casic/config/CorsConfig.java new file mode 100644 index 0000000..7d19680 --- /dev/null +++ b/src/main/java/com/casic/config/CorsConfig.java @@ -0,0 +1,31 @@ +package com.casic.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +/** + * 基础框架 - 跨域请求配置 + */ +@Configuration +public class CorsConfig { + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", buildConfig()); + return new CorsFilter(source); + } + + private CorsConfiguration buildConfig() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + // 1允许任何域名使用 + corsConfiguration.addAllowedOrigin("*"); + // 2允许任何头 + corsConfiguration.addAllowedHeader("*"); + // 3允许任何方法(post、get等) + corsConfiguration.addAllowedMethod("*"); + return corsConfiguration; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/controller/AlarmController.java b/src/main/java/com/casic/controller/AlarmController.java new file mode 100644 index 0000000..957fc36 --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.model.AlarmConfigParam; +import com.casic.service.AlarmService; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/alarm") +public class AlarmController { + + private final AlarmService alarmService; + + public AlarmController(AlarmService alarmService) { + this.alarmService = alarmService; + } + + @RequestMapping("/records") + public Object getAlarmRecord(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "devcode",required =false) String devcode, + @RequestParam(value = "pageSize", required = true) Integer pageSize) { + return alarmService.getAlarmRecord(deviceType,currentIndex,pageSize,devcode); + } + + @RequestMapping("/batch/cancel") + public Object excuteAlramBatchCancel(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "devcode",required =false) String devcode) { + return alarmService.excuteAlramBatchCancel(deviceType,devcode); + } + + @RequestMapping("/config/add") + public Object addAlarmConfig(@RequestBody AlarmConfigParam alarmConfigParam) { + return alarmService.addAlarmConfig(alarmConfigParam); + } +} diff --git a/src/main/java/com/casic/controller/DeviceDataController.java b/src/main/java/com/casic/controller/DeviceDataController.java new file mode 100644 index 0000000..3498b04 --- /dev/null +++ b/src/main/java/com/casic/controller/DeviceDataController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.service.DeviceDataService; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/device") +public class DeviceDataController { + private final DeviceDataService deviceDataService; + + public DeviceDataController(DeviceDataService deviceDataService) { + this.deviceDataService = deviceDataService; + } + + @RequestMapping("/recent-data") + public Object getDeviceRecentData(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "recentNum", required = true) String recentNum, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceRecentData(deviceType, recentNum, devcode); + } + + @RequestMapping("/data/list-page") + public Object getDeviceListPage(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "pageSize", required = true) Integer pageSize, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceListPage(deviceType, currentIndex, pageSize, devcode); + } + + @RequestMapping("/level/{deviceType}") + public Object getLevelList(@PathVariable("deviceType")String deviceType) { + return deviceDataService.getLevel(deviceType); + } + +} diff --git a/src/main/java/com/casic/controller/ThirdDataController.java b/src/main/java/com/casic/controller/ThirdDataController.java new file mode 100644 index 0000000..b9b2b42 --- /dev/null +++ b/src/main/java/com/casic/controller/ThirdDataController.java @@ -0,0 +1,28 @@ +package com.casic.controller; + +import com.casic.model.PressureDataParam; +import com.casic.service.ThirdDataService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +@RestController +@RequestMapping("/push") +@Slf4j +public class ThirdDataController { + + private final ThirdDataService thirdDataService; + + public ThirdDataController(ThirdDataService thirdDataService) { + this.thirdDataService = thirdDataService; + } + + @RequestMapping("/pressure/data") + public Object getDeviceRecentData(@RequestBody PressureDataParam pressureData) { + return thirdDataService.getDeviceRecentData(pressureData); + } + +} diff --git a/src/main/java/com/casic/dao/AlarmMapper.java b/src/main/java/com/casic/dao/AlarmMapper.java new file mode 100644 index 0000000..a442e3a --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmMapper.java @@ -0,0 +1,28 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmLevel; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + +@Mapper +public interface AlarmMapper extends BaseMapper { + + List> getAlarmRecord(@Param("deviceType") String deviceType, + @Param("devcode") String devcode, + @Param("currentIndex") Integer currentIndex, @Param("pageSize") Integer pageSize); + + Integer getAlarmTotalRecord(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteAlramBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteJobBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + String getDeviceDevcode(@Param("deviceType") String deviceType); + + String getDeviceByDevcode(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + +} diff --git a/src/main/java/com/casic/dao/BusConfigMapper.java b/src/main/java/com/casic/dao/BusConfigMapper.java new file mode 100644 index 0000000..ccf76da --- /dev/null +++ b/src/main/java/com/casic/dao/BusConfigMapper.java @@ -0,0 +1,9 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.BusConfig; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface BusConfigMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/dao/DataPressureMapper.java b/src/main/java/com/casic/dao/DataPressureMapper.java new file mode 100644 index 0000000..05f4329 --- /dev/null +++ b/src/main/java/com/casic/dao/DataPressureMapper.java @@ -0,0 +1,19 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.DataPressure; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.Date; + +@Mapper +public interface DataPressureMapper extends BaseMapper { + + String getWellCode(@Param("devcode") String devcode); + + Float getRuleValue(@Param("deviceType") String deviceType); + + void saveRecords(@Param("reValue") String reValue, @Param("alarmTime") Date alarmTime); + +} diff --git a/src/main/java/com/casic/dao/DeviceDataMapper.java b/src/main/java/com/casic/dao/DeviceDataMapper.java new file mode 100644 index 0000000..d9e18a0 --- /dev/null +++ b/src/main/java/com/casic/dao/DeviceDataMapper.java @@ -0,0 +1,27 @@ +package com.casic.dao; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + + +@Mapper +public interface DeviceDataMapper { + + List> getDeviceRecentData(@Param("tableName") String tableName, + @Param("recentNum") String recentNum, + @Param("fields") String fields, + @Param("devcode") String devcode); + + Integer getDeviceDataTotal(@Param("tableName") String tableName, @Param("devcode") String devcode); + + List> getDeviceDataListPage(@Param("tableName") String tableName, + @Param("currentIndex") Integer currentIndex, + @Param("fields") String fields, + @Param("pageSize") Integer pageSize, + @Param("devcode") String devcode); + + String getLevelByType(@Param("deviceType")String deviceType); +} diff --git a/src/main/java/com/casic/model/AlarmConfigParam.java b/src/main/java/com/casic/model/AlarmConfigParam.java new file mode 100644 index 0000000..28150d6 --- /dev/null +++ b/src/main/java/com/casic/model/AlarmConfigParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class AlarmConfigParam { + private String deviceType; + private String thresholdVol; + private String collectInterval; + private String uploadCycle; + private String retryNum; + private String ip; + private String port; + private String devcode; +} diff --git a/src/main/java/com/casic/model/AlarmLevel.java b/src/main/java/com/casic/model/AlarmLevel.java new file mode 100644 index 0000000..d0909af --- /dev/null +++ b/src/main/java/com/casic/model/AlarmLevel.java @@ -0,0 +1,26 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("alarm_level") +public class AlarmLevel{ + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + private String name; + private String deviceType; + private Integer level; + private Float lowValue; + private Float highValue; + private String openAlarm; + private String openJob; + private Date ts; + private String tenantId; + +} diff --git a/src/main/java/com/casic/model/BusConfig.java b/src/main/java/com/casic/model/BusConfig.java new file mode 100644 index 0000000..c6b7b50 --- /dev/null +++ b/src/main/java/com/casic/model/BusConfig.java @@ -0,0 +1,27 @@ +package com.casic.model; + + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +import java.util.Date; + +@Data +public class BusConfig { + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + + private String deviceId; + private String framecontent; + private String sensorid; + private String sensorcode; + + private String status; + private Integer attemptsmax; + private Integer attemptscurrent; + private Date sendtime; + private Date writetime; + +} diff --git a/src/main/java/com/casic/model/CommConfigDTO.java b/src/main/java/com/casic/model/CommConfigDTO.java new file mode 100644 index 0000000..7da699c --- /dev/null +++ b/src/main/java/com/casic/model/CommConfigDTO.java @@ -0,0 +1,41 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class CommConfigDTO { + private String acqStart;//采集开始时间 + private Long interval;//采集时间间隔(分钟) + private Long period;//上传周期 + private Long times;//采集次数 + private Long repeat;//重传次数 + private String ip; + private Long port; + private Float thresh; + private Float height; + private String collect; + private String MultiCollect; + private String acqCycle; + private String upCycle; + private String sleepStartTime; + + private String acqStartFlow ; //流量采集开始时间 + private Long intervalFlow; //流量采集采集间隔(分) + private Long acqTimesFlow ;//流量采集次数 + private String upStartFlow; //流量上报开始时间 + private Long upTimesFlow; //流量上传次数 + private String acqStartNoise; //噪声采集开始时间 + private Long intervalNoise; //噪声采集采集间隔(分) + private Long acqTimesNoise;//噪声采集次数 + private String upStartNoise; //噪声上报开始时间 + private Long upTimesNoise ;//噪声上传次数 + private String acqStartPressure; //压力采集开始时间 + private Long intervalPressure;//压力采集采集间隔(分) + private Long acqTimesPressure; //压力采集次数 + private String upStartPressure; //压力上报开始时间 + private Long upTimesPressure; //压力上传次数 + private Float lowerLimitPressure; //压力报警下限 + private Float upperLimitPressure ;//压力报警下限 + private Long limitDig ;//开挖阈值 + private Float threshold ;//开挖阈值 +} diff --git a/src/main/java/com/casic/model/DataPressure.java b/src/main/java/com/casic/model/DataPressure.java new file mode 100644 index 0000000..8270c70 --- /dev/null +++ b/src/main/java/com/casic/model/DataPressure.java @@ -0,0 +1,33 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("data_temp_press") +public class DataPressure { + + @TableId(value = "ID", type = IdType.AUTO) + private String id; + private String wellCode; + private String devcode; + private Float cell; + private String temperature; + + private String press; + private String descn; + private String uptime; + private String logtime; + /** + * 信号强度 + */ + private String pci; + + private String rsrp; + private String snr; + +} diff --git a/src/main/java/com/casic/model/PressureDataParam.java b/src/main/java/com/casic/model/PressureDataParam.java new file mode 100644 index 0000000..f42770d --- /dev/null +++ b/src/main/java/com/casic/model/PressureDataParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class PressureDataParam { + private String flag; + private String deviceUserid; + private String parentUserId; + private Object sensorsDates; + private String time; + private String rawData; + private String deviceId; +} + diff --git a/src/main/java/com/casic/model/ResponseData.java b/src/main/java/com/casic/model/ResponseData.java new file mode 100644 index 0000000..245ab04 --- /dev/null +++ b/src/main/java/com/casic/model/ResponseData.java @@ -0,0 +1,18 @@ +package com.casic.model; + +import lombok.Data; + +/** + * @author cz + * @date 2022-8-12 + */ +@Data +public class ResponseData { + public static final String DEFAULT_SUCCESS_MESSAGE = "请求成功"; + public static final String DEFAULT_ERROR_MESSAGE = "网络异常"; + public static final Integer DEFAULT_SUCCESS_CODE = 200; + public static final Integer DEFAULT_ERROR_CODE = 500; + private Integer code; + private String message; + private Object data; +} \ No newline at end of file diff --git a/src/main/java/com/casic/service/AlarmService.java b/src/main/java/com/casic/service/AlarmService.java new file mode 100644 index 0000000..8516b41 --- /dev/null +++ b/src/main/java/com/casic/service/AlarmService.java @@ -0,0 +1,12 @@ +package com.casic.service; + +import com.casic.model.AlarmConfigParam; + +public interface AlarmService { + + Object getAlarmRecord(String deviceType,Integer currentIndex,Integer pageSize,String devcode); + + Object excuteAlramBatchCancel(String deviceType,String devcode); + + Object addAlarmConfig(AlarmConfigParam alarmConfig); +} diff --git a/src/main/java/com/casic/service/DeviceDataService.java b/src/main/java/com/casic/service/DeviceDataService.java new file mode 100644 index 0000000..db656c1 --- /dev/null +++ b/src/main/java/com/casic/service/DeviceDataService.java @@ -0,0 +1,10 @@ +package com.casic.service; + +public interface DeviceDataService { + + Object getDeviceRecentData(String deviceType, String recentNum, String devcode); + + Object getDeviceListPage(String deviceType, Integer currentIndex, Integer pageSize, String devcode); + + Object getLevel(String deviceType); +} diff --git a/src/main/java/com/casic/service/ThirdDataService.java b/src/main/java/com/casic/service/ThirdDataService.java new file mode 100644 index 0000000..795e0b2 --- /dev/null +++ b/src/main/java/com/casic/service/ThirdDataService.java @@ -0,0 +1,8 @@ +package com.casic.service; + +import com.casic.model.PressureDataParam; + +public interface ThirdDataService { + + Object getDeviceRecentData(PressureDataParam pressureData); +} diff --git a/src/main/java/com/casic/service/impl/AlarmServiceImple.java b/src/main/java/com/casic/service/impl/AlarmServiceImple.java new file mode 100644 index 0000000..a675207 --- /dev/null +++ b/src/main/java/com/casic/service/impl/AlarmServiceImple.java @@ -0,0 +1,127 @@ +package com.casic.service.impl; + +import com.alibaba.druid.util.StringUtils; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.dao.AlarmMapper; +import com.casic.dao.BusConfigMapper; +import com.casic.model.*; +import com.casic.service.AlarmService; +import com.casic.util.DeviceDataTableEnum; +import com.casic.util.RedisCommonUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Slf4j +@Service +public class AlarmServiceImple extends ServiceImpl implements AlarmService { + + @Resource + private BusConfigMapper busConfigMapper; + @Resource + private RedisCommonUtil redisCommonUtil; + + public Object getAlarmRecord(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { + ResponseData responseData = new ResponseData(); + try { + Map page = new HashMap(); + page.put("total", this.baseMapper.getAlarmTotalRecord(deviceType, devcode)); + List> alarmRecordList = this.baseMapper.getAlarmRecord(deviceType, devcode, pageSize * (currentIndex - 1), pageSize); + page.put("rows", alarmRecordList); + responseData.setData(alarmRecordList); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},异常信息{}", deviceType, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + @Transactional + public Object excuteAlramBatchCancel(String deviceType, String devcode) { + ResponseData responseData = new ResponseData(); + try { + this.baseMapper.excuteAlramBatchCancel(deviceType, devcode); + this.baseMapper.excuteJobBatchCancel(deviceType, devcode); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("批量消警异常,设备类型{},异常信息{}", deviceType, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + + @Transactional + public Object addAlarmConfig(AlarmConfigParam alarmConfigParam) { + ResponseData responseData = new ResponseData(); + try { + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + addBusConfig(alarmConfigParam); + addRuleConfig(alarmConfigParam); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("风险配置异常,异常信息{}", dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + private void addRuleConfig(AlarmConfigParam alarmConfigParam) { + Map alarmRuleMap = new HashMap(); + alarmRuleMap.put("DEVICE_TYPE", alarmConfigParam.getDeviceType()); + this.baseMapper.deleteByMap(alarmRuleMap); + AlarmLevel alarmRule = new AlarmLevel(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap() + .get(Integer.valueOf(alarmConfigParam.getDeviceType())); + alarmRule.setName(deviceDataTableEnum.getTypeName()); + alarmRule.setHighValue(Float.valueOf(alarmConfigParam.getThresholdVol())); + alarmRule.setTs(new Date()); + alarmRule.setLevel(1); + alarmRule.setDeviceType(alarmConfigParam.getDeviceType()); + this.baseMapper.insert(alarmRule); + } + + private void addBusConfig(AlarmConfigParam alarmConfigParam) { + String devcode = StringUtils.isEmpty(alarmConfigParam.getDevcode()) ? this.baseMapper.getDeviceDevcode(alarmConfigParam.getDeviceType()) : alarmConfigParam.getDevcode(); + sendBusConfig(alarmConfigParam, devcode); + String devcideId = this.baseMapper.getDeviceByDevcode(alarmConfigParam.getDeviceType(), devcode); + BusConfig busConfig = new BusConfig(); + busConfig.setDeviceId(devcideId); + busConfig.setFramecontent("3," + alarmConfigParam.getCollectInterval() + "," + alarmConfigParam.getCollectInterval() + + "," + alarmConfigParam.getRetryNum() + "," + alarmConfigParam.getIp() + "," + alarmConfigParam.getPort()); + busConfig.setSensorid(""); + busConfig.setStatus("0"); + busConfig.setAttemptscurrent(0); + busConfig.setWritetime(new Date()); + busConfig.setAttemptsmax(3); + busConfigMapper.insert(busConfig); + } + + private void sendBusConfig(AlarmConfigParam alarmConfigParam, String devcode) { + CommConfigDTO commConfigDTO = new CommConfigDTO(); + commConfigDTO.setInterval(StringUtils.isEmpty(alarmConfigParam.getCollectInterval()) ? 300 : Long.valueOf(alarmConfigParam.getCollectInterval())); + commConfigDTO.setRepeat(StringUtils.isEmpty(alarmConfigParam.getRetryNum()) ? 300 : Long.valueOf(alarmConfigParam.getRetryNum())); + commConfigDTO.setTimes(Long.valueOf(1)); +// commConfigDTO.setIp(alarmConfigParam.getIp()); +// commConfigDTO.setPort(StringUtils.isEmpty(alarmConfigParam.getPort()) ? 8080 : Long.valueOf(alarmConfigParam.getPort())); + commConfigDTO.setPeriod(StringUtils.isEmpty(alarmConfigParam.getUploadCycle()) ? 300 : Long.valueOf(alarmConfigParam.getUploadCycle())); +// commConfigDTO.setThresh(); + commConfigDTO.setThresh(StringUtils.isEmpty(alarmConfigParam.getThresholdVol()) ? 50: Float.valueOf(alarmConfigParam.getThresholdVol())); + redisCommonUtil.send(commConfigDTO, devcode); + } + + +} diff --git a/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java new file mode 100644 index 0000000..3de704b --- /dev/null +++ b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java @@ -0,0 +1,80 @@ +package com.casic.service.impl; + +import com.casic.dao.DeviceDataMapper; +import com.casic.model.ResponseData; +import com.casic.service.DeviceDataService; +import com.casic.util.DeviceDataFieldTableEnum; +import com.casic.util.DeviceDataTableEnum; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Service +@Slf4j +public class DeviceDataServiceImpl implements DeviceDataService { + + private final DeviceDataMapper deviceDataMapper; + + public DeviceDataServiceImpl(DeviceDataMapper deviceDataMapper) { + this.deviceDataMapper = deviceDataMapper; + } + + public Object getDeviceRecentData(String deviceType, String recentNum, String devcode) { + ResponseData responseData = new ResponseData(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); + try { + String tableName = deviceDataTableEnum.getTableName(); + String fields = DeviceDataFieldTableEnum.TABLE_FIELD.getTableFieldMap().get(tableName); + List> recentDataList = deviceDataMapper.getDeviceRecentData(tableName, recentNum, fields, devcode); + responseData.setData(recentDataList); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备最近数据查询异常,设备类型{},查询数目{},异常信息{}", deviceType, recentNum, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + public Object getDeviceListPage(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { + ResponseData responseData = new ResponseData(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); + try { + String tableName = deviceDataTableEnum.getTableName(); + String fields = DeviceDataFieldTableEnum.TABLE_FIELD.getTableFieldMap().get(tableName); + Map page = new HashMap(); + page.put("total", deviceDataMapper.getDeviceDataTotal(tableName, devcode)); + List> recentDataList = deviceDataMapper.getDeviceDataListPage(tableName, pageSize * (currentIndex - 1), fields, pageSize, devcode); + page.put("rows", recentDataList); + responseData.setData(page); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},当前页{},页大小{},异常信息{}", deviceType, currentIndex, pageSize, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + public Object getLevel(String deviceType) { + ResponseData responseData = new ResponseData(); + try { + String highValue = deviceDataMapper.getLevelByType(deviceType); + responseData.setData(highValue); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},当前页{},页大小{},异常信息{}"); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + +} diff --git a/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java new file mode 100644 index 0000000..6b23451 --- /dev/null +++ b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java @@ -0,0 +1,92 @@ +package com.casic.service.impl; + +import com.alibaba.druid.util.StringUtils; +import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.dao.DataPressureMapper; +import com.casic.model.DataPressure; +import com.casic.model.PressureDataParam; +import com.casic.model.ResponseData; +import com.casic.service.ThirdDataService; +import com.casic.util.CacheUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.stream.Collectors; + +@Service +@Slf4j +public class ThirdDataServiceImpl extends ServiceImpl implements ThirdDataService { + + private final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA); + + public Object getDeviceRecentData(PressureDataParam pressureDataParam) { + ResponseData responseData = new ResponseData(); + try { + batchSave(pressureDataParam); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备最近数据查询异常,设备类型{},异常信息{}", dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + private void batchSave(PressureDataParam pressureDataParam) { + String pressureDataJson = pressureDataParam.getRawData(); + log.info("----" + pressureDataJson); + Map pressureDataMap = JSON.parseObject(pressureDataJson, HashMap.class); + Date uptime = null; + try { + uptime = dateFormat.parse(String.valueOf(pressureDataMap.get("times"))); + } catch (Exception e) { + log.error("主题,采集时间解析异常,异常信息{}", e.getMessage()); + } + List> pressureDataList = (List>) pressureDataMap.get("sensorDatas"); + DataPressure dataPressure = initPrssureData(pressureDataList, uptime); + if (dataPressure == null) { + return; + } + checkAlarm(dataPressure); + } + + private DataPressure initPrssureData(List> pressureDataList, Date uptime) { + DataPressure dataPressure = new DataPressure(); + String devcode = pressureDataList.get(pressureDataList.size() - 1).get("str"); + Map pressureDataMap = pressureDataList.stream().collect( + Collectors.toMap(e -> String.valueOf(e.get("flag")), e -> String.valueOf(e.get("value"))) + ); +// if (CacheUtil.serialBuf.get(devcode)!=null&&CacheUtil.serialBuf.get(devcode).equals(pressureDataMap.get("F"))) { +// return null; +// } + String wellCode = this.baseMapper.getWellCode(devcode); + dataPressure.setWellCode(wellCode); + dataPressure.setDevcode(devcode); + dataPressure.setPci(pressureDataMap.get("Q")); + dataPressure.setCell(Float.valueOf(pressureDataMap.get("V"))); + dataPressure.setTemperature(pressureDataMap.get("T")); + dataPressure.setPress(pressureDataMap.get("F")); + dataPressure.setUptime(dateFormat.format(uptime)); + dataPressure.setLogtime(dateFormat.format(new Date())); + this.baseMapper.insert(dataPressure); +// CacheUtil.serialBuf.put(devcode, pressureDataMap.get("F")); + return dataPressure; + } + + private void checkAlarm(DataPressure dataPressure) { + final Float ruleValue = this.baseMapper.getRuleValue("24"); + if (ruleValue == null) return; + if (!StringUtils.isEmpty(dataPressure.getTemperature()) && !dataPressure.getTemperature().equals("null")) { + if (Float.valueOf(dataPressure.getTemperature()) > ruleValue) { + this.baseMapper.saveRecords(dataPressure.getTemperature(), new Date()); + } + } + } + +} diff --git a/src/main/java/com/casic/util/CacheUtil.java b/src/main/java/com/casic/util/CacheUtil.java new file mode 100644 index 0000000..5b89300 --- /dev/null +++ b/src/main/java/com/casic/util/CacheUtil.java @@ -0,0 +1,16 @@ +package com.casic.util; + +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import java.util.HashMap; +import java.util.Map; + +@Component +public class CacheUtil { + public static volatile Map serialBuf; + @PostConstruct + public void init() { + serialBuf = new HashMap<>(); + } +} diff --git a/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java b/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java new file mode 100644 index 0000000..085c7c3 --- /dev/null +++ b/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java @@ -0,0 +1,39 @@ +package com.casic.util; + +import java.util.HashMap; +import java.util.Map; + +public enum DeviceDataFieldTableEnum { + + TABLE_FIELD(new HashMap() { + { + put("data_dig", "ddata AS dataValue,devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gas", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gasliquid_gas", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gasliquid_liquid", "liquiddata AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gas_dector", "gas_sample_value AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_harmful_gas", "CONCAT(CO, ', ', CH4, ', ', H2S, ', ', O2) AS dataValue,devcode AS devcode,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_hydrant", "0 AS dataValue,devcode AS devcode,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_liquid", "liquiddata AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_noise", "ddata AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_temp_hum", "CONCAT(TEMPERATURE, ', ', HUMIDITY) AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_tube", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_wellcover", "descn AS dataValue,devcode AS devcode,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_temp_press", "press AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_pantilt", "concentration AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_wellcover_loca", "0 AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_wellplus", "0 AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_h2s", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_pressure", "re_val AS dataValue,devcode AS devcode,'' AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + } + }); + public Map tableNameMap; + + DeviceDataFieldTableEnum(Map tableNameMap) { + this.tableNameMap = tableNameMap; + } + + public Map getTableFieldMap() { + return tableNameMap; + } +} diff --git a/src/main/java/com/casic/util/DeviceDataTableEnum.java b/src/main/java/com/casic/util/DeviceDataTableEnum.java new file mode 100644 index 0000000..9698487 --- /dev/null +++ b/src/main/java/com/casic/util/DeviceDataTableEnum.java @@ -0,0 +1,81 @@ +package com.casic.util; + +import java.util.HashMap; + +/** + * @author cz + * @date 2022-7-15 + * 上传数据总记录数 + */ +public enum DeviceDataTableEnum { + + DATA_DIG("data_dig", "开挖监测仪"), + DATA_GAS("data_gas", "燃气智能监测终端"), + DATA_GASLIQUID("data_gasliquid_gas,data_gasliquid_liquid", "燃气智能监测终端(一体化)"), + DATA_GAS_DECTOR("data_gas_dector", "燃气探测仪"), + DATA_HARMFUL_GAS("data_harmful_gas", "有害气体监测仪"), + DATA_HYDRANT("data_hydrant", "消防栓防盗水监测仪"), + DATA_LIQUID("data_liquid", "液位监测仪"), + DATA_NOISE("data_noise", "噪声记录仪"), + DATA_PANTILT("data_pantilt", "激光甲烷云台"), + DATA_TEMP_HUM("data_temp_hum", "温湿度监测仪"), + DATA_TUBE("data_tube", "管盯"), + DATA_WELLCOVER("data_wellcover", "井盖状态监测仪"), + DATA_TEMP_PRESS("data_temp_press", "压力温度检测仪"), + DATA_WELLCOVER_LOCA("data_wellcover_loca", "井盖定位监测仪"), + DATA_WELLPLUS("data_wellplus", "井盖液位一体机"), + DATA_H2S("data_h2s", "硫化氢检测终端"), + DATA_PRESSURE("data_pressure", "压力检测终端"), + DEVICE_TYPE_TABLE(new HashMap() { + { + put(1, DATA_WELLCOVER); + put(2, DATA_LIQUID); + put(3, DATA_HARMFUL_GAS); + put(4, DATA_GAS); + put(5, DATA_TEMP_HUM); + put(6, DATA_DIG); + put(7, DATA_WELLCOVER_LOCA); + put(8, DATA_NOISE); + put(9, DATA_TEMP_PRESS); + put(10, DATA_GASLIQUID); + put(11, DATA_HYDRANT); + put(12, DATA_TUBE); + put(13, DATA_WELLPLUS); + put(14, DATA_H2S); + put(21, DATA_PANTILT); + put(22, DATA_H2S); + put(23, DATA_GAS); + put(24, DATA_TEMP_PRESS); + put(101, DATA_GAS_DECTOR); + } + }); + + String typeName; + String tableName; + + DeviceDataTableEnum(String tableName, String typeName) { + this.typeName = typeName; + this.tableName = tableName; + } + + public String getTypeName() { + return typeName; + } + + public String getTableName() { + return tableName; + } + + + public HashMap tableNameMap; + + DeviceDataTableEnum(HashMap tableNameMap) { + this.tableNameMap = tableNameMap; + } + + public HashMap getTableNameMap() { + return tableNameMap; + } + + +} diff --git a/src/main/java/com/casic/util/RedisCommonUtil.java b/src/main/java/com/casic/util/RedisCommonUtil.java new file mode 100644 index 0000000..a6ce9cf --- /dev/null +++ b/src/main/java/com/casic/util/RedisCommonUtil.java @@ -0,0 +1,29 @@ +package com.casic.util; + +import com.alibaba.fastjson.JSON; +import com.casic.model.CommConfigDTO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; + +import java.util.concurrent.TimeUnit; + +@Component +public class RedisCommonUtil { + + @Value("${casic.device.redis.invalid-time}") + private String invalidTime; + @Value("${casic.device.redis.config-prefix}") + private String configPrefix; + + @Autowired + private RedisTemplate redisTemplate; + + public void send(CommConfigDTO commConfigDTO,String devCode) { + redisTemplate.opsForValue().set(configPrefix+ devCode, + JSON.toJSONString(commConfigDTO), + Integer.valueOf(invalidTime), + TimeUnit.SECONDS); + } +} diff --git a/src/main/java/com/casic/util/SensorIdEum.java b/src/main/java/com/casic/util/SensorIdEum.java new file mode 100644 index 0000000..86b61db --- /dev/null +++ b/src/main/java/com/casic/util/SensorIdEum.java @@ -0,0 +1,30 @@ +package com.casic.util; + +import java.util.HashMap; +import java.util.Map; + +public enum SensorIdEum { + + SENSOR_MAP(new HashMap() { + { + put("燃气智能监测终端", "000044"); + put("有害气体监测仪", "000035"); + put("开挖监测仪", "000064"); + put("温湿度监测仪", "000055"); + put("噪声记录仪", "000032"); + put("液位监测仪", "000034"); + put("燃气智能监测终端(一体化)", "000065"); + put("管盯", "000080"); + } + }); + public Map sensorMap; + + SensorIdEum(Map sensorMap) { + this.sensorMap = sensorMap; + } + + public Map getSensorMap() { + return sensorMap; + } + +} diff --git a/src/main/java/com/casic/util/VerifyConstantUtil.java b/src/main/java/com/casic/util/VerifyConstantUtil.java new file mode 100644 index 0000000..90ee071 --- /dev/null +++ b/src/main/java/com/casic/util/VerifyConstantUtil.java @@ -0,0 +1,11 @@ +package com.casic.util; + +public class VerifyConstantUtil { + + public final static String DEVICE_TYPES = "22,23,24"; + + public static Boolean checkDeviceType(String devcieType) { + return DEVICE_TYPES.contains(devcieType) ? true : false; + } + +} diff --git a/src/main/resources/config/application-dev.yml b/src/main/resources/config/application-dev.yml new file mode 100644 index 0000000..e948b83 --- /dev/null +++ b/src/main/resources/config/application-dev.yml @@ -0,0 +1,32 @@ +server: + port: 11315 +################### spring配置 ################### +spring: + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://111.198.10.15:11102/smartwell_demos?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&serverTimezone=UTC&&allowMultiQueries=true&&useSSL=true + username: root + password: Casic203! + session: + store-type: redis + redis: + host: 111.198.10.15 + port: 11412 + password: ew5T4K3#203lwh + redisValueSerializer: org.springframework.data.redis.serializer.JdkSerializationRedisSerializer + # session: + # store-type: redis +#flowable数据源和多数据源配置 +casic: + kaptcha-open: false #是否开启登录时验证码 (true/false) + #kaptcha-open: false #是否开启登录时验证码 (true/false) + db: + init: + enable: false + spring-session-open: false #开启spring session +logging: + level.root: error + level.com.casic: info + file: + path: logs/ + name: missiles.log \ No newline at end of file diff --git a/src/main/resources/config/application-prod.yml b/src/main/resources/config/application-prod.yml new file mode 100644 index 0000000..4fee268 --- /dev/null +++ b/src/main/resources/config/application-prod.yml @@ -0,0 +1,43 @@ +server: + port: 11312 +################### spring配置 ################### +spring: + datasource: + smartwell: + driver-class-name: org.postgresql.Driver + url: jdbc:postgresql://111.198.10.15:11209/smartwell + username: postgres + password: Casic203 + cms: + driver-class-name: org.postgresql.Driver + url: jdbc:postgresql://111.198.10.15:11209/smartwell_cms + username: postgres + password: Casic203 + span_tilt: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://111.198.10.15:11102/casic_span_tilt?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&serverTimezone=UTC&&allowMultiQueries=true&&useSSL=true + username: root + password: Casic203! + session: + store-type: redis + redis: + host: 111.198.10.15 + port: 11412 + password: ew5T4K3#203lwh + redisValueSerializer: org.springframework.data.redis.serializer.JdkSerializationRedisSerializer + # session: + # store-type: redis +#flowable数据源和多数据源配置 +casic: + kaptcha-open: false #是否开启登录时验证码 (true/false) + #kaptcha-open: false #是否开启登录时验证码 (true/false) + db: + init: + enable: false + spring-session-open: false #开启spring session +logging: + level.root: error + level.com.casic: error + file: + path: logs/ + name: missiles.log \ No newline at end of file diff --git a/src/main/resources/config/application.yml b/src/main/resources/config/application.yml new file mode 100644 index 0000000..4930753 --- /dev/null +++ b/src/main/resources/config/application.yml @@ -0,0 +1,41 @@ +########################################################## +spring: + profiles: + active: dev + servlet: + multipart: + max-file-size: 50MB + max-request-size: 80MB +mybatis-plus: + global-config: + enable-sql-runner: true + configuration: + # 配置结果集属性为空时 是否映射返回结果 + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl #打印sql语句,调试用 + mapper-locations: classpath:mapper/*.xml +mybatis: + mapper-locations: classpath:mapper/*.xml +#mybatis-plus: +# sql-injector: com.baomidou.mybatisplus.mapper.LogicSqlInjector +################### mybatis-plus配置 ################### +################### casic配置 ################### +flowable: + checkProcessDefinitions: false #不校验process文件 +casic: + swagger-open: false #是否开启swagger (true/false) + kaptcha-open: false #是否开启登录时验证码 (true/false) + muti-datasource-open: false #是否开启多数据源(true/false) + spring-session-open: false #是否开启spring session,如果是多机环境需要开启(true/false) + session-invalidate-time: 86400 #session失效时间(只在单机环境下生效,,多机环境在SpringSessionConfig类中配置) 单位:秒 + session-validation-interval: 900 #多久检测一次失效的session(只在单机环境下生效) 单位:秒 + extUrl: sys + device: + redis: + invalid-time: 86400 + host: 127.0.0.1 + port: 6379 + password: ew5T4K3#203lwh + config-prefix: 'Casic:' + config: + export-path: D:\java\boot\guns-web-1.0.0-SNAPSHOT\export\ + config-path: E:\Develop\IdeaProject\smartcity\casic-smartcity-dcms\casic-web\src\main\resources\config\ \ No newline at end of file diff --git a/src/main/resources/mapper/AlarmMapper.xml b/src/main/resources/mapper/AlarmMapper.xml new file mode 100644 index 0000000..2a1c28d --- /dev/null +++ b/src/main/resources/mapper/AlarmMapper.xml @@ -0,0 +1,75 @@ + + + + + + + + + + update alarm_records + set status='2' + WHERE devcode in ( + SELECT devcode + FROM bus_device + WHERE DEVICE_TYPE=#{deviceType} + + and devcode = #{devcode} + + ) + + + + update alarm_job + set JOB_STATUS='4' + WHERE devcode in( + SELECT devcode + FROM bus_device + WHERE DEVICE_TYPE=#{deviceType} + + and devcode = #{devcode} + + ) + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/mapper/DataPressureMapper.xml b/src/main/resources/mapper/DataPressureMapper.xml new file mode 100644 index 0000000..0cca911 --- /dev/null +++ b/src/main/resources/mapper/DataPressureMapper.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + INSERT INTO ALARM_RECORDS(DEVICE_ID, DEVCODE, WELL_CODE, ALARM_TYPE,ALARM_CONTENT,ALARM_VALUE,ALARM_TIME,ALARM_MSG,STATUS ) + VALUES ( '1', '89860423192180035458', 'test003', '1', '压力超标',#{reValue},#{alarmTime},'压力超标','1') + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..50f4a19 --- /dev/null +++ b/pom.xml @@ -0,0 +1,161 @@ + + + 4.0.0 + + com.casic + smartwell-demos + 1.0-SNAPSHOT + + + + + jdk-1.8 + + true + 1.8 + + + 1.8 + 1.8 + 1.8 + + + + + + + + + + org.springframework.boot + spring-boot-starter + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-tomcat + 2.4.5 + + + + org.springframework.boot + spring-boot-starter-web + 2.4.5 + + + + + org.springframework.boot + spring-boot-starter-jdbc + 2.4.5 + + + + mysql + mysql-connector-java + 8.0.16 + compile + + + + com.baomidou + mybatis-plus-boot-starter + 3.4.3 + + + + org.projectlombok + lombok + 1.18.20 + + + + + com.alibaba + druid + 1.2.6 + + + + com.alibaba + fastjson + 1.2.73 + + + + commons-codec + commons-codec + 1.14 + + + + redis.clients + jedis + 3.1.0 + jar + + + + org.springframework.data + spring-data-redis + 2.4.8 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.3.RELEASE + + true + + com.casic.CasicApplication + exec + + + + + repackage + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + false + + + + + + + + src/main/resources + + + /config/*/* + /config/*-*.yml + + true + + + src/main/resources + + **/*.xml + + true + + + + + \ No newline at end of file diff --git a/src/main/java/com/casic/CasicApplication.java b/src/main/java/com/casic/CasicApplication.java new file mode 100644 index 0000000..9afd0b9 --- /dev/null +++ b/src/main/java/com/casic/CasicApplication.java @@ -0,0 +1,28 @@ +package com.casic; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.transaction.annotation.EnableTransactionManagement; + + +/** + * SpringBoot方式启动类 + * + * @author cz + * @Date 2022/09/08 14:28 + */ + +@Slf4j +@ComponentScan(basePackages= "com.casic.**") +@SpringBootApplication +public class CasicApplication { + public static void main(String[] args) { + log.info("CasicApplication is success!"); + SpringApplication.run(CasicApplication.class, args); + } +} diff --git a/src/main/java/com/casic/config/CorsConfig.java b/src/main/java/com/casic/config/CorsConfig.java new file mode 100644 index 0000000..7d19680 --- /dev/null +++ b/src/main/java/com/casic/config/CorsConfig.java @@ -0,0 +1,31 @@ +package com.casic.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +/** + * 基础框架 - 跨域请求配置 + */ +@Configuration +public class CorsConfig { + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", buildConfig()); + return new CorsFilter(source); + } + + private CorsConfiguration buildConfig() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + // 1允许任何域名使用 + corsConfiguration.addAllowedOrigin("*"); + // 2允许任何头 + corsConfiguration.addAllowedHeader("*"); + // 3允许任何方法(post、get等) + corsConfiguration.addAllowedMethod("*"); + return corsConfiguration; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/controller/AlarmController.java b/src/main/java/com/casic/controller/AlarmController.java new file mode 100644 index 0000000..957fc36 --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.model.AlarmConfigParam; +import com.casic.service.AlarmService; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/alarm") +public class AlarmController { + + private final AlarmService alarmService; + + public AlarmController(AlarmService alarmService) { + this.alarmService = alarmService; + } + + @RequestMapping("/records") + public Object getAlarmRecord(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "devcode",required =false) String devcode, + @RequestParam(value = "pageSize", required = true) Integer pageSize) { + return alarmService.getAlarmRecord(deviceType,currentIndex,pageSize,devcode); + } + + @RequestMapping("/batch/cancel") + public Object excuteAlramBatchCancel(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "devcode",required =false) String devcode) { + return alarmService.excuteAlramBatchCancel(deviceType,devcode); + } + + @RequestMapping("/config/add") + public Object addAlarmConfig(@RequestBody AlarmConfigParam alarmConfigParam) { + return alarmService.addAlarmConfig(alarmConfigParam); + } +} diff --git a/src/main/java/com/casic/controller/DeviceDataController.java b/src/main/java/com/casic/controller/DeviceDataController.java new file mode 100644 index 0000000..3498b04 --- /dev/null +++ b/src/main/java/com/casic/controller/DeviceDataController.java @@ -0,0 +1,38 @@ +package com.casic.controller; + +import com.casic.service.DeviceDataService; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/device") +public class DeviceDataController { + private final DeviceDataService deviceDataService; + + public DeviceDataController(DeviceDataService deviceDataService) { + this.deviceDataService = deviceDataService; + } + + @RequestMapping("/recent-data") + public Object getDeviceRecentData(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "recentNum", required = true) String recentNum, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceRecentData(deviceType, recentNum, devcode); + } + + @RequestMapping("/data/list-page") + public Object getDeviceListPage(@RequestParam(value = "deviceType", required = true) String deviceType, + @RequestParam(value = "currentIndex", required = true) Integer currentIndex, + @RequestParam(value = "pageSize", required = true) Integer pageSize, + @RequestParam(value = "devcode", required = false) String devcode) { + return deviceDataService.getDeviceListPage(deviceType, currentIndex, pageSize, devcode); + } + + @RequestMapping("/level/{deviceType}") + public Object getLevelList(@PathVariable("deviceType")String deviceType) { + return deviceDataService.getLevel(deviceType); + } + +} diff --git a/src/main/java/com/casic/controller/ThirdDataController.java b/src/main/java/com/casic/controller/ThirdDataController.java new file mode 100644 index 0000000..b9b2b42 --- /dev/null +++ b/src/main/java/com/casic/controller/ThirdDataController.java @@ -0,0 +1,28 @@ +package com.casic.controller; + +import com.casic.model.PressureDataParam; +import com.casic.service.ThirdDataService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +@RestController +@RequestMapping("/push") +@Slf4j +public class ThirdDataController { + + private final ThirdDataService thirdDataService; + + public ThirdDataController(ThirdDataService thirdDataService) { + this.thirdDataService = thirdDataService; + } + + @RequestMapping("/pressure/data") + public Object getDeviceRecentData(@RequestBody PressureDataParam pressureData) { + return thirdDataService.getDeviceRecentData(pressureData); + } + +} diff --git a/src/main/java/com/casic/dao/AlarmMapper.java b/src/main/java/com/casic/dao/AlarmMapper.java new file mode 100644 index 0000000..a442e3a --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmMapper.java @@ -0,0 +1,28 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmLevel; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + +@Mapper +public interface AlarmMapper extends BaseMapper { + + List> getAlarmRecord(@Param("deviceType") String deviceType, + @Param("devcode") String devcode, + @Param("currentIndex") Integer currentIndex, @Param("pageSize") Integer pageSize); + + Integer getAlarmTotalRecord(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteAlramBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + void excuteJobBatchCancel(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + + String getDeviceDevcode(@Param("deviceType") String deviceType); + + String getDeviceByDevcode(@Param("deviceType") String deviceType, @Param("devcode") String devcode); + +} diff --git a/src/main/java/com/casic/dao/BusConfigMapper.java b/src/main/java/com/casic/dao/BusConfigMapper.java new file mode 100644 index 0000000..ccf76da --- /dev/null +++ b/src/main/java/com/casic/dao/BusConfigMapper.java @@ -0,0 +1,9 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.BusConfig; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface BusConfigMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/dao/DataPressureMapper.java b/src/main/java/com/casic/dao/DataPressureMapper.java new file mode 100644 index 0000000..05f4329 --- /dev/null +++ b/src/main/java/com/casic/dao/DataPressureMapper.java @@ -0,0 +1,19 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.DataPressure; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.Date; + +@Mapper +public interface DataPressureMapper extends BaseMapper { + + String getWellCode(@Param("devcode") String devcode); + + Float getRuleValue(@Param("deviceType") String deviceType); + + void saveRecords(@Param("reValue") String reValue, @Param("alarmTime") Date alarmTime); + +} diff --git a/src/main/java/com/casic/dao/DeviceDataMapper.java b/src/main/java/com/casic/dao/DeviceDataMapper.java new file mode 100644 index 0000000..d9e18a0 --- /dev/null +++ b/src/main/java/com/casic/dao/DeviceDataMapper.java @@ -0,0 +1,27 @@ +package com.casic.dao; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + + +@Mapper +public interface DeviceDataMapper { + + List> getDeviceRecentData(@Param("tableName") String tableName, + @Param("recentNum") String recentNum, + @Param("fields") String fields, + @Param("devcode") String devcode); + + Integer getDeviceDataTotal(@Param("tableName") String tableName, @Param("devcode") String devcode); + + List> getDeviceDataListPage(@Param("tableName") String tableName, + @Param("currentIndex") Integer currentIndex, + @Param("fields") String fields, + @Param("pageSize") Integer pageSize, + @Param("devcode") String devcode); + + String getLevelByType(@Param("deviceType")String deviceType); +} diff --git a/src/main/java/com/casic/model/AlarmConfigParam.java b/src/main/java/com/casic/model/AlarmConfigParam.java new file mode 100644 index 0000000..28150d6 --- /dev/null +++ b/src/main/java/com/casic/model/AlarmConfigParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class AlarmConfigParam { + private String deviceType; + private String thresholdVol; + private String collectInterval; + private String uploadCycle; + private String retryNum; + private String ip; + private String port; + private String devcode; +} diff --git a/src/main/java/com/casic/model/AlarmLevel.java b/src/main/java/com/casic/model/AlarmLevel.java new file mode 100644 index 0000000..d0909af --- /dev/null +++ b/src/main/java/com/casic/model/AlarmLevel.java @@ -0,0 +1,26 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("alarm_level") +public class AlarmLevel{ + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + private String name; + private String deviceType; + private Integer level; + private Float lowValue; + private Float highValue; + private String openAlarm; + private String openJob; + private Date ts; + private String tenantId; + +} diff --git a/src/main/java/com/casic/model/BusConfig.java b/src/main/java/com/casic/model/BusConfig.java new file mode 100644 index 0000000..c6b7b50 --- /dev/null +++ b/src/main/java/com/casic/model/BusConfig.java @@ -0,0 +1,27 @@ +package com.casic.model; + + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +import java.util.Date; + +@Data +public class BusConfig { + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + + private String deviceId; + private String framecontent; + private String sensorid; + private String sensorcode; + + private String status; + private Integer attemptsmax; + private Integer attemptscurrent; + private Date sendtime; + private Date writetime; + +} diff --git a/src/main/java/com/casic/model/CommConfigDTO.java b/src/main/java/com/casic/model/CommConfigDTO.java new file mode 100644 index 0000000..7da699c --- /dev/null +++ b/src/main/java/com/casic/model/CommConfigDTO.java @@ -0,0 +1,41 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class CommConfigDTO { + private String acqStart;//采集开始时间 + private Long interval;//采集时间间隔(分钟) + private Long period;//上传周期 + private Long times;//采集次数 + private Long repeat;//重传次数 + private String ip; + private Long port; + private Float thresh; + private Float height; + private String collect; + private String MultiCollect; + private String acqCycle; + private String upCycle; + private String sleepStartTime; + + private String acqStartFlow ; //流量采集开始时间 + private Long intervalFlow; //流量采集采集间隔(分) + private Long acqTimesFlow ;//流量采集次数 + private String upStartFlow; //流量上报开始时间 + private Long upTimesFlow; //流量上传次数 + private String acqStartNoise; //噪声采集开始时间 + private Long intervalNoise; //噪声采集采集间隔(分) + private Long acqTimesNoise;//噪声采集次数 + private String upStartNoise; //噪声上报开始时间 + private Long upTimesNoise ;//噪声上传次数 + private String acqStartPressure; //压力采集开始时间 + private Long intervalPressure;//压力采集采集间隔(分) + private Long acqTimesPressure; //压力采集次数 + private String upStartPressure; //压力上报开始时间 + private Long upTimesPressure; //压力上传次数 + private Float lowerLimitPressure; //压力报警下限 + private Float upperLimitPressure ;//压力报警下限 + private Long limitDig ;//开挖阈值 + private Float threshold ;//开挖阈值 +} diff --git a/src/main/java/com/casic/model/DataPressure.java b/src/main/java/com/casic/model/DataPressure.java new file mode 100644 index 0000000..8270c70 --- /dev/null +++ b/src/main/java/com/casic/model/DataPressure.java @@ -0,0 +1,33 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("data_temp_press") +public class DataPressure { + + @TableId(value = "ID", type = IdType.AUTO) + private String id; + private String wellCode; + private String devcode; + private Float cell; + private String temperature; + + private String press; + private String descn; + private String uptime; + private String logtime; + /** + * 信号强度 + */ + private String pci; + + private String rsrp; + private String snr; + +} diff --git a/src/main/java/com/casic/model/PressureDataParam.java b/src/main/java/com/casic/model/PressureDataParam.java new file mode 100644 index 0000000..f42770d --- /dev/null +++ b/src/main/java/com/casic/model/PressureDataParam.java @@ -0,0 +1,15 @@ +package com.casic.model; + +import lombok.Data; + +@Data +public class PressureDataParam { + private String flag; + private String deviceUserid; + private String parentUserId; + private Object sensorsDates; + private String time; + private String rawData; + private String deviceId; +} + diff --git a/src/main/java/com/casic/model/ResponseData.java b/src/main/java/com/casic/model/ResponseData.java new file mode 100644 index 0000000..245ab04 --- /dev/null +++ b/src/main/java/com/casic/model/ResponseData.java @@ -0,0 +1,18 @@ +package com.casic.model; + +import lombok.Data; + +/** + * @author cz + * @date 2022-8-12 + */ +@Data +public class ResponseData { + public static final String DEFAULT_SUCCESS_MESSAGE = "请求成功"; + public static final String DEFAULT_ERROR_MESSAGE = "网络异常"; + public static final Integer DEFAULT_SUCCESS_CODE = 200; + public static final Integer DEFAULT_ERROR_CODE = 500; + private Integer code; + private String message; + private Object data; +} \ No newline at end of file diff --git a/src/main/java/com/casic/service/AlarmService.java b/src/main/java/com/casic/service/AlarmService.java new file mode 100644 index 0000000..8516b41 --- /dev/null +++ b/src/main/java/com/casic/service/AlarmService.java @@ -0,0 +1,12 @@ +package com.casic.service; + +import com.casic.model.AlarmConfigParam; + +public interface AlarmService { + + Object getAlarmRecord(String deviceType,Integer currentIndex,Integer pageSize,String devcode); + + Object excuteAlramBatchCancel(String deviceType,String devcode); + + Object addAlarmConfig(AlarmConfigParam alarmConfig); +} diff --git a/src/main/java/com/casic/service/DeviceDataService.java b/src/main/java/com/casic/service/DeviceDataService.java new file mode 100644 index 0000000..db656c1 --- /dev/null +++ b/src/main/java/com/casic/service/DeviceDataService.java @@ -0,0 +1,10 @@ +package com.casic.service; + +public interface DeviceDataService { + + Object getDeviceRecentData(String deviceType, String recentNum, String devcode); + + Object getDeviceListPage(String deviceType, Integer currentIndex, Integer pageSize, String devcode); + + Object getLevel(String deviceType); +} diff --git a/src/main/java/com/casic/service/ThirdDataService.java b/src/main/java/com/casic/service/ThirdDataService.java new file mode 100644 index 0000000..795e0b2 --- /dev/null +++ b/src/main/java/com/casic/service/ThirdDataService.java @@ -0,0 +1,8 @@ +package com.casic.service; + +import com.casic.model.PressureDataParam; + +public interface ThirdDataService { + + Object getDeviceRecentData(PressureDataParam pressureData); +} diff --git a/src/main/java/com/casic/service/impl/AlarmServiceImple.java b/src/main/java/com/casic/service/impl/AlarmServiceImple.java new file mode 100644 index 0000000..a675207 --- /dev/null +++ b/src/main/java/com/casic/service/impl/AlarmServiceImple.java @@ -0,0 +1,127 @@ +package com.casic.service.impl; + +import com.alibaba.druid.util.StringUtils; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.dao.AlarmMapper; +import com.casic.dao.BusConfigMapper; +import com.casic.model.*; +import com.casic.service.AlarmService; +import com.casic.util.DeviceDataTableEnum; +import com.casic.util.RedisCommonUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Slf4j +@Service +public class AlarmServiceImple extends ServiceImpl implements AlarmService { + + @Resource + private BusConfigMapper busConfigMapper; + @Resource + private RedisCommonUtil redisCommonUtil; + + public Object getAlarmRecord(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { + ResponseData responseData = new ResponseData(); + try { + Map page = new HashMap(); + page.put("total", this.baseMapper.getAlarmTotalRecord(deviceType, devcode)); + List> alarmRecordList = this.baseMapper.getAlarmRecord(deviceType, devcode, pageSize * (currentIndex - 1), pageSize); + page.put("rows", alarmRecordList); + responseData.setData(alarmRecordList); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},异常信息{}", deviceType, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + @Transactional + public Object excuteAlramBatchCancel(String deviceType, String devcode) { + ResponseData responseData = new ResponseData(); + try { + this.baseMapper.excuteAlramBatchCancel(deviceType, devcode); + this.baseMapper.excuteJobBatchCancel(deviceType, devcode); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("批量消警异常,设备类型{},异常信息{}", deviceType, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + + @Transactional + public Object addAlarmConfig(AlarmConfigParam alarmConfigParam) { + ResponseData responseData = new ResponseData(); + try { + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + addBusConfig(alarmConfigParam); + addRuleConfig(alarmConfigParam); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("风险配置异常,异常信息{}", dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + private void addRuleConfig(AlarmConfigParam alarmConfigParam) { + Map alarmRuleMap = new HashMap(); + alarmRuleMap.put("DEVICE_TYPE", alarmConfigParam.getDeviceType()); + this.baseMapper.deleteByMap(alarmRuleMap); + AlarmLevel alarmRule = new AlarmLevel(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap() + .get(Integer.valueOf(alarmConfigParam.getDeviceType())); + alarmRule.setName(deviceDataTableEnum.getTypeName()); + alarmRule.setHighValue(Float.valueOf(alarmConfigParam.getThresholdVol())); + alarmRule.setTs(new Date()); + alarmRule.setLevel(1); + alarmRule.setDeviceType(alarmConfigParam.getDeviceType()); + this.baseMapper.insert(alarmRule); + } + + private void addBusConfig(AlarmConfigParam alarmConfigParam) { + String devcode = StringUtils.isEmpty(alarmConfigParam.getDevcode()) ? this.baseMapper.getDeviceDevcode(alarmConfigParam.getDeviceType()) : alarmConfigParam.getDevcode(); + sendBusConfig(alarmConfigParam, devcode); + String devcideId = this.baseMapper.getDeviceByDevcode(alarmConfigParam.getDeviceType(), devcode); + BusConfig busConfig = new BusConfig(); + busConfig.setDeviceId(devcideId); + busConfig.setFramecontent("3," + alarmConfigParam.getCollectInterval() + "," + alarmConfigParam.getCollectInterval() + + "," + alarmConfigParam.getRetryNum() + "," + alarmConfigParam.getIp() + "," + alarmConfigParam.getPort()); + busConfig.setSensorid(""); + busConfig.setStatus("0"); + busConfig.setAttemptscurrent(0); + busConfig.setWritetime(new Date()); + busConfig.setAttemptsmax(3); + busConfigMapper.insert(busConfig); + } + + private void sendBusConfig(AlarmConfigParam alarmConfigParam, String devcode) { + CommConfigDTO commConfigDTO = new CommConfigDTO(); + commConfigDTO.setInterval(StringUtils.isEmpty(alarmConfigParam.getCollectInterval()) ? 300 : Long.valueOf(alarmConfigParam.getCollectInterval())); + commConfigDTO.setRepeat(StringUtils.isEmpty(alarmConfigParam.getRetryNum()) ? 300 : Long.valueOf(alarmConfigParam.getRetryNum())); + commConfigDTO.setTimes(Long.valueOf(1)); +// commConfigDTO.setIp(alarmConfigParam.getIp()); +// commConfigDTO.setPort(StringUtils.isEmpty(alarmConfigParam.getPort()) ? 8080 : Long.valueOf(alarmConfigParam.getPort())); + commConfigDTO.setPeriod(StringUtils.isEmpty(alarmConfigParam.getUploadCycle()) ? 300 : Long.valueOf(alarmConfigParam.getUploadCycle())); +// commConfigDTO.setThresh(); + commConfigDTO.setThresh(StringUtils.isEmpty(alarmConfigParam.getThresholdVol()) ? 50: Float.valueOf(alarmConfigParam.getThresholdVol())); + redisCommonUtil.send(commConfigDTO, devcode); + } + + +} diff --git a/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java new file mode 100644 index 0000000..3de704b --- /dev/null +++ b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java @@ -0,0 +1,80 @@ +package com.casic.service.impl; + +import com.casic.dao.DeviceDataMapper; +import com.casic.model.ResponseData; +import com.casic.service.DeviceDataService; +import com.casic.util.DeviceDataFieldTableEnum; +import com.casic.util.DeviceDataTableEnum; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Service +@Slf4j +public class DeviceDataServiceImpl implements DeviceDataService { + + private final DeviceDataMapper deviceDataMapper; + + public DeviceDataServiceImpl(DeviceDataMapper deviceDataMapper) { + this.deviceDataMapper = deviceDataMapper; + } + + public Object getDeviceRecentData(String deviceType, String recentNum, String devcode) { + ResponseData responseData = new ResponseData(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); + try { + String tableName = deviceDataTableEnum.getTableName(); + String fields = DeviceDataFieldTableEnum.TABLE_FIELD.getTableFieldMap().get(tableName); + List> recentDataList = deviceDataMapper.getDeviceRecentData(tableName, recentNum, fields, devcode); + responseData.setData(recentDataList); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备最近数据查询异常,设备类型{},查询数目{},异常信息{}", deviceType, recentNum, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + public Object getDeviceListPage(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { + ResponseData responseData = new ResponseData(); + DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); + try { + String tableName = deviceDataTableEnum.getTableName(); + String fields = DeviceDataFieldTableEnum.TABLE_FIELD.getTableFieldMap().get(tableName); + Map page = new HashMap(); + page.put("total", deviceDataMapper.getDeviceDataTotal(tableName, devcode)); + List> recentDataList = deviceDataMapper.getDeviceDataListPage(tableName, pageSize * (currentIndex - 1), fields, pageSize, devcode); + page.put("rows", recentDataList); + responseData.setData(page); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},当前页{},页大小{},异常信息{}", deviceType, currentIndex, pageSize, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + public Object getLevel(String deviceType) { + ResponseData responseData = new ResponseData(); + try { + String highValue = deviceDataMapper.getLevelByType(deviceType); + responseData.setData(highValue); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备数据查询异常,设备类型{},当前页{},页大小{},异常信息{}"); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + +} diff --git a/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java new file mode 100644 index 0000000..6b23451 --- /dev/null +++ b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java @@ -0,0 +1,92 @@ +package com.casic.service.impl; + +import com.alibaba.druid.util.StringUtils; +import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.dao.DataPressureMapper; +import com.casic.model.DataPressure; +import com.casic.model.PressureDataParam; +import com.casic.model.ResponseData; +import com.casic.service.ThirdDataService; +import com.casic.util.CacheUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.stream.Collectors; + +@Service +@Slf4j +public class ThirdDataServiceImpl extends ServiceImpl implements ThirdDataService { + + private final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA); + + public Object getDeviceRecentData(PressureDataParam pressureDataParam) { + ResponseData responseData = new ResponseData(); + try { + batchSave(pressureDataParam); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("设备最近数据查询异常,设备类型{},异常信息{}", dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + private void batchSave(PressureDataParam pressureDataParam) { + String pressureDataJson = pressureDataParam.getRawData(); + log.info("----" + pressureDataJson); + Map pressureDataMap = JSON.parseObject(pressureDataJson, HashMap.class); + Date uptime = null; + try { + uptime = dateFormat.parse(String.valueOf(pressureDataMap.get("times"))); + } catch (Exception e) { + log.error("主题,采集时间解析异常,异常信息{}", e.getMessage()); + } + List> pressureDataList = (List>) pressureDataMap.get("sensorDatas"); + DataPressure dataPressure = initPrssureData(pressureDataList, uptime); + if (dataPressure == null) { + return; + } + checkAlarm(dataPressure); + } + + private DataPressure initPrssureData(List> pressureDataList, Date uptime) { + DataPressure dataPressure = new DataPressure(); + String devcode = pressureDataList.get(pressureDataList.size() - 1).get("str"); + Map pressureDataMap = pressureDataList.stream().collect( + Collectors.toMap(e -> String.valueOf(e.get("flag")), e -> String.valueOf(e.get("value"))) + ); +// if (CacheUtil.serialBuf.get(devcode)!=null&&CacheUtil.serialBuf.get(devcode).equals(pressureDataMap.get("F"))) { +// return null; +// } + String wellCode = this.baseMapper.getWellCode(devcode); + dataPressure.setWellCode(wellCode); + dataPressure.setDevcode(devcode); + dataPressure.setPci(pressureDataMap.get("Q")); + dataPressure.setCell(Float.valueOf(pressureDataMap.get("V"))); + dataPressure.setTemperature(pressureDataMap.get("T")); + dataPressure.setPress(pressureDataMap.get("F")); + dataPressure.setUptime(dateFormat.format(uptime)); + dataPressure.setLogtime(dateFormat.format(new Date())); + this.baseMapper.insert(dataPressure); +// CacheUtil.serialBuf.put(devcode, pressureDataMap.get("F")); + return dataPressure; + } + + private void checkAlarm(DataPressure dataPressure) { + final Float ruleValue = this.baseMapper.getRuleValue("24"); + if (ruleValue == null) return; + if (!StringUtils.isEmpty(dataPressure.getTemperature()) && !dataPressure.getTemperature().equals("null")) { + if (Float.valueOf(dataPressure.getTemperature()) > ruleValue) { + this.baseMapper.saveRecords(dataPressure.getTemperature(), new Date()); + } + } + } + +} diff --git a/src/main/java/com/casic/util/CacheUtil.java b/src/main/java/com/casic/util/CacheUtil.java new file mode 100644 index 0000000..5b89300 --- /dev/null +++ b/src/main/java/com/casic/util/CacheUtil.java @@ -0,0 +1,16 @@ +package com.casic.util; + +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import java.util.HashMap; +import java.util.Map; + +@Component +public class CacheUtil { + public static volatile Map serialBuf; + @PostConstruct + public void init() { + serialBuf = new HashMap<>(); + } +} diff --git a/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java b/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java new file mode 100644 index 0000000..085c7c3 --- /dev/null +++ b/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java @@ -0,0 +1,39 @@ +package com.casic.util; + +import java.util.HashMap; +import java.util.Map; + +public enum DeviceDataFieldTableEnum { + + TABLE_FIELD(new HashMap() { + { + put("data_dig", "ddata AS dataValue,devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gas", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gasliquid_gas", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gasliquid_liquid", "liquiddata AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_gas_dector", "gas_sample_value AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_harmful_gas", "CONCAT(CO, ', ', CH4, ', ', H2S, ', ', O2) AS dataValue,devcode AS devcode,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_hydrant", "0 AS dataValue,devcode AS devcode,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_liquid", "liquiddata AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_noise", "ddata AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_temp_hum", "CONCAT(TEMPERATURE, ', ', HUMIDITY) AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_tube", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_wellcover", "descn AS dataValue,devcode AS devcode,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_temp_press", "press AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_pantilt", "concentration AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_wellcover_loca", "0 AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_wellplus", "0 AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_h2s", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_pressure", "re_val AS dataValue,devcode AS devcode,'' AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + } + }); + public Map tableNameMap; + + DeviceDataFieldTableEnum(Map tableNameMap) { + this.tableNameMap = tableNameMap; + } + + public Map getTableFieldMap() { + return tableNameMap; + } +} diff --git a/src/main/java/com/casic/util/DeviceDataTableEnum.java b/src/main/java/com/casic/util/DeviceDataTableEnum.java new file mode 100644 index 0000000..9698487 --- /dev/null +++ b/src/main/java/com/casic/util/DeviceDataTableEnum.java @@ -0,0 +1,81 @@ +package com.casic.util; + +import java.util.HashMap; + +/** + * @author cz + * @date 2022-7-15 + * 上传数据总记录数 + */ +public enum DeviceDataTableEnum { + + DATA_DIG("data_dig", "开挖监测仪"), + DATA_GAS("data_gas", "燃气智能监测终端"), + DATA_GASLIQUID("data_gasliquid_gas,data_gasliquid_liquid", "燃气智能监测终端(一体化)"), + DATA_GAS_DECTOR("data_gas_dector", "燃气探测仪"), + DATA_HARMFUL_GAS("data_harmful_gas", "有害气体监测仪"), + DATA_HYDRANT("data_hydrant", "消防栓防盗水监测仪"), + DATA_LIQUID("data_liquid", "液位监测仪"), + DATA_NOISE("data_noise", "噪声记录仪"), + DATA_PANTILT("data_pantilt", "激光甲烷云台"), + DATA_TEMP_HUM("data_temp_hum", "温湿度监测仪"), + DATA_TUBE("data_tube", "管盯"), + DATA_WELLCOVER("data_wellcover", "井盖状态监测仪"), + DATA_TEMP_PRESS("data_temp_press", "压力温度检测仪"), + DATA_WELLCOVER_LOCA("data_wellcover_loca", "井盖定位监测仪"), + DATA_WELLPLUS("data_wellplus", "井盖液位一体机"), + DATA_H2S("data_h2s", "硫化氢检测终端"), + DATA_PRESSURE("data_pressure", "压力检测终端"), + DEVICE_TYPE_TABLE(new HashMap() { + { + put(1, DATA_WELLCOVER); + put(2, DATA_LIQUID); + put(3, DATA_HARMFUL_GAS); + put(4, DATA_GAS); + put(5, DATA_TEMP_HUM); + put(6, DATA_DIG); + put(7, DATA_WELLCOVER_LOCA); + put(8, DATA_NOISE); + put(9, DATA_TEMP_PRESS); + put(10, DATA_GASLIQUID); + put(11, DATA_HYDRANT); + put(12, DATA_TUBE); + put(13, DATA_WELLPLUS); + put(14, DATA_H2S); + put(21, DATA_PANTILT); + put(22, DATA_H2S); + put(23, DATA_GAS); + put(24, DATA_TEMP_PRESS); + put(101, DATA_GAS_DECTOR); + } + }); + + String typeName; + String tableName; + + DeviceDataTableEnum(String tableName, String typeName) { + this.typeName = typeName; + this.tableName = tableName; + } + + public String getTypeName() { + return typeName; + } + + public String getTableName() { + return tableName; + } + + + public HashMap tableNameMap; + + DeviceDataTableEnum(HashMap tableNameMap) { + this.tableNameMap = tableNameMap; + } + + public HashMap getTableNameMap() { + return tableNameMap; + } + + +} diff --git a/src/main/java/com/casic/util/RedisCommonUtil.java b/src/main/java/com/casic/util/RedisCommonUtil.java new file mode 100644 index 0000000..a6ce9cf --- /dev/null +++ b/src/main/java/com/casic/util/RedisCommonUtil.java @@ -0,0 +1,29 @@ +package com.casic.util; + +import com.alibaba.fastjson.JSON; +import com.casic.model.CommConfigDTO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; + +import java.util.concurrent.TimeUnit; + +@Component +public class RedisCommonUtil { + + @Value("${casic.device.redis.invalid-time}") + private String invalidTime; + @Value("${casic.device.redis.config-prefix}") + private String configPrefix; + + @Autowired + private RedisTemplate redisTemplate; + + public void send(CommConfigDTO commConfigDTO,String devCode) { + redisTemplate.opsForValue().set(configPrefix+ devCode, + JSON.toJSONString(commConfigDTO), + Integer.valueOf(invalidTime), + TimeUnit.SECONDS); + } +} diff --git a/src/main/java/com/casic/util/SensorIdEum.java b/src/main/java/com/casic/util/SensorIdEum.java new file mode 100644 index 0000000..86b61db --- /dev/null +++ b/src/main/java/com/casic/util/SensorIdEum.java @@ -0,0 +1,30 @@ +package com.casic.util; + +import java.util.HashMap; +import java.util.Map; + +public enum SensorIdEum { + + SENSOR_MAP(new HashMap() { + { + put("燃气智能监测终端", "000044"); + put("有害气体监测仪", "000035"); + put("开挖监测仪", "000064"); + put("温湿度监测仪", "000055"); + put("噪声记录仪", "000032"); + put("液位监测仪", "000034"); + put("燃气智能监测终端(一体化)", "000065"); + put("管盯", "000080"); + } + }); + public Map sensorMap; + + SensorIdEum(Map sensorMap) { + this.sensorMap = sensorMap; + } + + public Map getSensorMap() { + return sensorMap; + } + +} diff --git a/src/main/java/com/casic/util/VerifyConstantUtil.java b/src/main/java/com/casic/util/VerifyConstantUtil.java new file mode 100644 index 0000000..90ee071 --- /dev/null +++ b/src/main/java/com/casic/util/VerifyConstantUtil.java @@ -0,0 +1,11 @@ +package com.casic.util; + +public class VerifyConstantUtil { + + public final static String DEVICE_TYPES = "22,23,24"; + + public static Boolean checkDeviceType(String devcieType) { + return DEVICE_TYPES.contains(devcieType) ? true : false; + } + +} diff --git a/src/main/resources/config/application-dev.yml b/src/main/resources/config/application-dev.yml new file mode 100644 index 0000000..e948b83 --- /dev/null +++ b/src/main/resources/config/application-dev.yml @@ -0,0 +1,32 @@ +server: + port: 11315 +################### spring配置 ################### +spring: + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://111.198.10.15:11102/smartwell_demos?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&serverTimezone=UTC&&allowMultiQueries=true&&useSSL=true + username: root + password: Casic203! + session: + store-type: redis + redis: + host: 111.198.10.15 + port: 11412 + password: ew5T4K3#203lwh + redisValueSerializer: org.springframework.data.redis.serializer.JdkSerializationRedisSerializer + # session: + # store-type: redis +#flowable数据源和多数据源配置 +casic: + kaptcha-open: false #是否开启登录时验证码 (true/false) + #kaptcha-open: false #是否开启登录时验证码 (true/false) + db: + init: + enable: false + spring-session-open: false #开启spring session +logging: + level.root: error + level.com.casic: info + file: + path: logs/ + name: missiles.log \ No newline at end of file diff --git a/src/main/resources/config/application-prod.yml b/src/main/resources/config/application-prod.yml new file mode 100644 index 0000000..4fee268 --- /dev/null +++ b/src/main/resources/config/application-prod.yml @@ -0,0 +1,43 @@ +server: + port: 11312 +################### spring配置 ################### +spring: + datasource: + smartwell: + driver-class-name: org.postgresql.Driver + url: jdbc:postgresql://111.198.10.15:11209/smartwell + username: postgres + password: Casic203 + cms: + driver-class-name: org.postgresql.Driver + url: jdbc:postgresql://111.198.10.15:11209/smartwell_cms + username: postgres + password: Casic203 + span_tilt: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://111.198.10.15:11102/casic_span_tilt?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&serverTimezone=UTC&&allowMultiQueries=true&&useSSL=true + username: root + password: Casic203! + session: + store-type: redis + redis: + host: 111.198.10.15 + port: 11412 + password: ew5T4K3#203lwh + redisValueSerializer: org.springframework.data.redis.serializer.JdkSerializationRedisSerializer + # session: + # store-type: redis +#flowable数据源和多数据源配置 +casic: + kaptcha-open: false #是否开启登录时验证码 (true/false) + #kaptcha-open: false #是否开启登录时验证码 (true/false) + db: + init: + enable: false + spring-session-open: false #开启spring session +logging: + level.root: error + level.com.casic: error + file: + path: logs/ + name: missiles.log \ No newline at end of file diff --git a/src/main/resources/config/application.yml b/src/main/resources/config/application.yml new file mode 100644 index 0000000..4930753 --- /dev/null +++ b/src/main/resources/config/application.yml @@ -0,0 +1,41 @@ +########################################################## +spring: + profiles: + active: dev + servlet: + multipart: + max-file-size: 50MB + max-request-size: 80MB +mybatis-plus: + global-config: + enable-sql-runner: true + configuration: + # 配置结果集属性为空时 是否映射返回结果 + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl #打印sql语句,调试用 + mapper-locations: classpath:mapper/*.xml +mybatis: + mapper-locations: classpath:mapper/*.xml +#mybatis-plus: +# sql-injector: com.baomidou.mybatisplus.mapper.LogicSqlInjector +################### mybatis-plus配置 ################### +################### casic配置 ################### +flowable: + checkProcessDefinitions: false #不校验process文件 +casic: + swagger-open: false #是否开启swagger (true/false) + kaptcha-open: false #是否开启登录时验证码 (true/false) + muti-datasource-open: false #是否开启多数据源(true/false) + spring-session-open: false #是否开启spring session,如果是多机环境需要开启(true/false) + session-invalidate-time: 86400 #session失效时间(只在单机环境下生效,,多机环境在SpringSessionConfig类中配置) 单位:秒 + session-validation-interval: 900 #多久检测一次失效的session(只在单机环境下生效) 单位:秒 + extUrl: sys + device: + redis: + invalid-time: 86400 + host: 127.0.0.1 + port: 6379 + password: ew5T4K3#203lwh + config-prefix: 'Casic:' + config: + export-path: D:\java\boot\guns-web-1.0.0-SNAPSHOT\export\ + config-path: E:\Develop\IdeaProject\smartcity\casic-smartcity-dcms\casic-web\src\main\resources\config\ \ No newline at end of file diff --git a/src/main/resources/mapper/AlarmMapper.xml b/src/main/resources/mapper/AlarmMapper.xml new file mode 100644 index 0000000..2a1c28d --- /dev/null +++ b/src/main/resources/mapper/AlarmMapper.xml @@ -0,0 +1,75 @@ + + + + + + + + + + update alarm_records + set status='2' + WHERE devcode in ( + SELECT devcode + FROM bus_device + WHERE DEVICE_TYPE=#{deviceType} + + and devcode = #{devcode} + + ) + + + + update alarm_job + set JOB_STATUS='4' + WHERE devcode in( + SELECT devcode + FROM bus_device + WHERE DEVICE_TYPE=#{deviceType} + + and devcode = #{devcode} + + ) + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/mapper/DataPressureMapper.xml b/src/main/resources/mapper/DataPressureMapper.xml new file mode 100644 index 0000000..0cca911 --- /dev/null +++ b/src/main/resources/mapper/DataPressureMapper.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + INSERT INTO ALARM_RECORDS(DEVICE_ID, DEVCODE, WELL_CODE, ALARM_TYPE,ALARM_CONTENT,ALARM_VALUE,ALARM_TIME,ALARM_MSG,STATUS ) + VALUES ( '1', '89860423192180035458', 'test003', '1', '压力超标',#{reValue},#{alarmTime},'压力超标','1') + + + \ No newline at end of file diff --git a/src/main/resources/mapper/DeviceDataMapper.xml b/src/main/resources/mapper/DeviceDataMapper.xml new file mode 100644 index 0000000..56d23d2 --- /dev/null +++ b/src/main/resources/mapper/DeviceDataMapper.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + \ No newline at end of file