Commit abbcda52 authored by 耿迪迪's avatar 耿迪迪

危化数据监控

parents
######################################################################
# Build Tools
.gradle
/build/
!gradle/wrapper/gradle-wrapper.jar
target/
!.mvn/wrapper/maven-wrapper.jar
######################################################################
# IDE
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
/target/
*.class
*.jar
*.log
/logs/*
/target/*
.settings*
### NetBeans ###
nbproject/private/
build/*
nbbuild/
dist/
nbdist/
.nb-gradle/
######################################################################
# Others
*.log
*.xml.versionsBackup
*.swp
!*/build/*.java
!*/build/*.html
!*/build/*.xml
.DS_Store
node_modules
/dist
# local env files
.env.local
.env.*.local
# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>dangerousenterprise-device-report</groupId>
<artifactId>dangerousenterprise-device-report</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<!--SpringBoot版本-->
<version>2.5.2</version>
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!-- spring-boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- mysql-connector -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!-- netty -->
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.65.Final</version>
</dependency>
<!--mybatis-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.0</version>
</dependency>
<!-- hutool -->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.3.10</version>
</dependency>
<!--lombok-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.10</version>
</dependency>
<!--集成redis-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!-- pool 对象池 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>
</dependencies>
<build>
<finalName>dangerousenterprise-device-report-${project.version}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<excludes>
<!--<exclude>*</exclude>-->
<!--<exclude>*.sh</exclude>-->
<!--<exclude>*.bat</exclude>-->
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/dangerousenterprise-device-report-${project.version}/lib
</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-config</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<encoding>UTF-8</encoding>
<outputDirectory>${project.build.directory}/dangerousenterprise-device-report-${project.version}/conf</outputDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.yml</include>
<include>**/logback.xml</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-sh</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<encoding>UTF-8</encoding>
<outputDirectory>${project.build.directory}/dangerousenterprise-device-report-${project.version}/bin</outputDirectory>
<resources>
<resource>
<directory>src/main/bin</directory>
<includes>
<include>*.sh</include>
<include>*.bat</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-dist-jar</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<encoding>UTF-8</encoding>
<outputDirectory>${project.build.directory}/dangerousenterprise-device-report-${project.version}/lib</outputDirectory>
<resources>
<resource>
<directory>target</directory>
<includes>
<include>*.jar</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
#!/bin/bash
cd `dirname $0`
cd ..
DEPLOY_DIR=`pwd`
CONF_DIR=$DEPLOY_DIR/conf
LOGS_DIR=$DEPLOY_DIR/logs
#部署需修改
APP_MAINCLASS=com.zehong.dangerousdevicereport.DangerousDeviceReportApplication
PIDS=`ps -ef | grep -v grep | grep "$CONF_DIR" |awk '{print $2}'`
if [ -n "$PIDS" ]; then
echo "ERROR: already started!"
echo "PID: $PIDS"
exit 1
fi
if [ ! -d $LOGS_DIR ]; then
mkdir $LOGS_DIR
fi
STDOUT_FILE=$LOGS_DIR/stdout.log
CLOG_FILE=$LOGS_DIR/gc.logli
#SYS_FILE=$LOGS_DIR/dangerousdevicereport.log
LIB_DIR=$DEPLOY_DIR/lib
LIB_JARS=`ls $LIB_DIR|grep .jar|awk '{print "'$LIB_DIR'/"$0}'| xargs | sed "s/ /:/g"`
JAVA_OPTS=" -Djava.awt.headless=true"
JAVA_DEBUG_OPTS=""
if [ "$1" = "debug" ]; then
JAVA_DEBUG_OPTS=" -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n "
fi
JAVA_JMX_OPTS=""
if [ "$1" = "jmx" ]; then
JAVA_JMX_OPTS=" -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false "
fi
JAVA_MEM_OPTS="-server -Xms2048M -Xmx2048M -Xmn1024M"
#JAVA_MEM_OPTS="-server -Xms5120M -Xmx5120M -Xmn1024M -Xnoclassgc -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:+CMSParallelRemarkEnabled -XX:CMSInitiatingOccupancyFraction=80 -XX:SoftRefLRUPolicyMSPerMB=0 -XX:+PrintClassHistogram -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintHeapAtGC -Xloggc:$CLOG_FILE"
echo -e "Starting the DangerousDeviceReportApplication ...\c"
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$DEPLOY_DIR/libs/linux_64
nohup java -Dlog.path=$LOGS_DIR -Dapp.home=$DEPLOY_DIR $JAVA_OPTS $JAVA_MEM_OPTS $JAVA_DEBUG_OPTS $JAVA_JMX_OPTS -classpath $CONF_DIR:$LIB_JARS $APP_MAINCLASS >/dev/null 2>&1 &
sleep 1
echo "started"
PIDS=`ps -ef | grep java | grep "$DEPLOY_DIR" | awk '{print $2}'`
echo "PID: $PIDS"
#!/bin/bash
cd `dirname $0`
BIN_DIR=`pwd`
cd ..
DEPLOY_DIR=`pwd`
LOGS_DIR=$DEPLOY_DIR/logs
if [ ! -d $LOGS_DIR ]; then
mkdir $LOGS_DIR
fi
STDOUT_FILE=$LOGS_DIR/stdout.log
PID=`ps -ef | grep -v grep | grep "$DEPLOY_DIR/conf" | awk '{print $2}'`
echo "PID: $PID"
if [ -z "$PID" ]; then
echo "ERROR: The Application does not started!"
exit 1
fi
echo -e "Stopping the Application ...\c"
kill $PID > $STDOUT_FILE 2>&1
COUNT=0
while [ $COUNT -lt 1 ]; do
echo -e ".\c"
sleep 1
COUNT=1
PID_EXIST=`ps -f -p $PID | grep java`
if [ -n "$PID_EXIST" ]; then
COUNT=0
fi
done
echo "stopped"
echo "PID: $PID"
package com.zehong.dangerousdevicereport;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@MapperScan("com.zehong.dangerousdevicereport.dao")
@ComponentScan(basePackages={"cn.hutool.extra.spring","com.zehong.dangerousdevicereport"})
public class DangerousDeviceReportApplication {
public static void main(String[] args) {
SpringApplication.run(DangerousDeviceReportApplication.class, args);
}
}
package com.zehong.dangerousdevicereport.config;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.*;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
@Configuration
@EnableCaching //开启注解
public class RedisConfig extends CachingConfigurerSupport {
/**
* retemplate相关配置
* @param factory
* @return
*/
@Bean
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
RedisTemplate<String, Object> template = new RedisTemplate<>();
// 配置连接工厂
template.setConnectionFactory(factory);
//使用Jackson2JsonRedisSerializer来序列化和反序列化redis的value值(默认使用JDK的序列化方式)
Jackson2JsonRedisSerializer jacksonSeial = new Jackson2JsonRedisSerializer(Object.class);
ObjectMapper om = new ObjectMapper();
// 指定要序列化的域,field,get和set,以及修饰符范围,ANY是都有包括private和public
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
// 指定序列化输入的类型,类必须是非final修饰的,final修饰的类,比如String,Integer等会跑出异常
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
jacksonSeial.setObjectMapper(om);
// 值采用json序列化
template.setValueSerializer(jacksonSeial);
//使用StringRedisSerializer来序列化和反序列化redis的key值
template.setKeySerializer(new StringRedisSerializer());
// 设置hash key 和value序列化模式
template.setHashKeySerializer(new StringRedisSerializer());
template.setHashValueSerializer(jacksonSeial);
template.afterPropertiesSet();
return template;
}
/**
* 对hash类型的数据操作
*
* @param redisTemplate
* @return
*/
@Bean
public HashOperations<String, String, Object> hashOperations(RedisTemplate<String, Object> redisTemplate) {
return redisTemplate.opsForHash();
}
/**
* 对redis字符串类型数据操作
*
* @param redisTemplate
* @return
*/
@Bean
public ValueOperations<String, Object> valueOperations(RedisTemplate<String, Object> redisTemplate) {
return redisTemplate.opsForValue();
}
/**
* 对链表类型的数据操作
*
* @param redisTemplate
* @return
*/
@Bean
public ListOperations<String, Object> listOperations(RedisTemplate<String, Object> redisTemplate) {
return redisTemplate.opsForList();
}
/**
* 对无序集合类型的数据操作
*
* @param redisTemplate
* @return
*/
@Bean
public SetOperations<String, Object> setOperations(RedisTemplate<String, Object> redisTemplate) {
return redisTemplate.opsForSet();
}
/**
* 对有序集合类型的数据操作
*
* @param redisTemplate
* @return
*/
@Bean
public ZSetOperations<String, Object> zSetOperations(RedisTemplate<String, Object> redisTemplate) {
return redisTemplate.opsForZSet();
}
}
package com.zehong.dangerousdevicereport.config;
import com.zehong.dangerousdevicereport.dao.SysScheduledCronRepository;
import com.zehong.dangerousdevicereport.entity.SysScheduledCron;
import com.zehong.dangerousdevicereport.task.ScheduledOfTask;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.scheduling.support.CronTrigger;
import org.springframework.util.Assert;
import javax.annotation.Resource;
/**
* 定时任务配置类
*/
@Configuration
@EnableScheduling
public class ScheduledConfig implements SchedulingConfigurer {
@Autowired
private ApplicationContext context;
@Resource
private SysScheduledCronRepository cronRepository;
@Override
public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
for (SysScheduledCron sysScheduledCron : cronRepository.findAll()) {
Class<?> clazz;
Object task;
try {
clazz = Class.forName(sysScheduledCron.getCronKey());
task = context.getBean(clazz);
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException("t_scheduled_cron表数据" + sysScheduledCron.getCronKey() + "有误", e);
} catch (BeansException e) {
throw new IllegalArgumentException(sysScheduledCron.getCronKey() + "未纳入到spring管理", e);
}
Assert.isAssignable(ScheduledOfTask.class, task.getClass(), "定时任务类必须实现ScheduledOfTask接口");
// 可以通过改变数据库数据进而实现动态改变执行周期
scheduledTaskRegistrar.addTriggerTask(((Runnable) task),
triggerContext -> {
String cronExpression = cronRepository.findByCronKey(sysScheduledCron.getCronKey()).getCronExpression();
return new CronTrigger(cronExpression).nextExecutionTime(triggerContext);
}
);
}
}
}
package com.zehong.dangerousdevicereport.dao;
import com.zehong.dangerousdevicereport.entity.SafetyDeviceInfo;
import java.util.List;
/**
* 企业安全监测设备dao接口
*
* @author zehong
* @date 2022-04-12
*/
public interface SafetyDeviceInfoDao {
/**
* 查询企业安全监测设备
*
* @param id 企业安全监测设备ID
* @return 企业安全监测设备
*/
SafetyDeviceInfo selectSafetyDeviceInfoById(String id);
/**
* 查询企业安全监测设备列表
*
* @param safetyDeviceInfo 企业安全监测设备
* @return 企业安全监测设备集合
*/
List<SafetyDeviceInfo> selectSafetyDeviceInfoList(SafetyDeviceInfo safetyDeviceInfo);
/**
* 新增企业安全监测设备
*
* @param safetyDeviceInfo 企业安全监测设备
* @return 结果
*/
int insertSafetyDeviceInfo(SafetyDeviceInfo safetyDeviceInfo);
/**
* 修改企业安全监测设备
*
* @param safetyDeviceInfo 企业安全监测设备
* @return 结果
*/
int updateSafetyDeviceInfo(SafetyDeviceInfo safetyDeviceInfo);
/**
* 删除企业安全监测设备
*
* @param id 企业安全监测设备ID
* @return 结果
*/
int deleteSafetyDeviceInfoById(String id);
/**
* 批量删除企业安全监测设备
*
* @param ids 需要删除的数据ID
* @return 结果
*/
int deleteSafetyDeviceInfoByIds(String[] ids);
}
package com.zehong.dangerousdevicereport.dao;
import com.zehong.dangerousdevicereport.entity.SysScheduledCron;
import java.util.List;
/**
* 定时任务 Repository
*/
public interface SysScheduledCronRepository {
/**
* 获取所有定时任务
* @return
*/
List<SysScheduledCron> findAll();
/**
* 根据定时名称获取定时
* @param cronKey
* @return
*/
SysScheduledCron findByCronKey(String cronKey);
/**
* 更新定时任务cron表达式
*
* @param newCron
* @param cronKey
* @return
*/
int updateCronExpressionByCronKey(String newCron, String cronKey);
/**
* 更新定时任务状态
*
* @param status
* @param cronKey
* @return
*/
int updateTaskStatusByCronKey(Integer status, String cronKey);
}
package com.zehong.dangerousdevicereport.dao;
import java.util.List;
import com.zehong.dangerousdevicereport.entity.TAlarmInfo;
/**
* 【报警】Mapper接口
*
* @author zehong
* @date 2022-04-12
*/
public interface TAlarmInfoDao {
/**
* 查询【报警】
*
* @param id 【报警】ID
* @return 【报警】
*/
TAlarmInfo selectTAlarmInfoById(String id);
/**
* 查询【报警】列表
*
* @param tAlarmInfo 【报警】
* @return 【报警】集合
*/
List<TAlarmInfo> selectTAlarmInfoList(TAlarmInfo tAlarmInfo);
/**
* 新增【报警】
*
* @param tAlarmInfo 【报警】
* @return 结果
*/
int insertTAlarmInfo(TAlarmInfo tAlarmInfo);
/**
* 修改【报警】
*
* @param tAlarmInfo 【报警】
* @return 结果
*/
int updateTAlarmInfo(TAlarmInfo tAlarmInfo);
/**
* 删除【报警】
*
* @param id 【报警】ID
* @return 结果
*/
int deleteTAlarmInfoById(String id);
/**
* 批量删除【报警】
*
* @param ids 需要删除的数据ID
* @return 结果
*/
int deleteTAlarmInfoByIds(String[] ids);
/**
* 根据设备编号查询报警信息
* @param deviceNum 设备编号
* @return
*/
TAlarmInfo selectAlarmInfoByDeviceNum(String deviceNum);
}
package com.zehong.dangerousdevicereport.dao;
import java.util.List;
import com.zehong.dangerousdevicereport.entity.TDeviceReportData;
/**
* 设备信息上报Mapper接口
*
* @author zehong
* @date 2022-04-11
*/
public interface TDeviceReportDataDao {
/**
* 查询设备信息上报
*
* @param reportId 设备信息上报ID
* @return 设备信息上报
*/
TDeviceReportData selectTDeviceReportDataById(String reportId);
/**
* 查询设备信息上报列表
*
* @param tDeviceReportData 设备信息上报
* @return 设备信息上报集合
*/
List<TDeviceReportData> selectTDeviceReportDataList(TDeviceReportData tDeviceReportData);
/**
* 新增设备信息上报
*
* @param tDeviceReportData 设备信息上报
* @return 结果
*/
int insertTDeviceReportData(TDeviceReportData tDeviceReportData);
/**
* 修改设备信息上报
*
* @param tDeviceReportData 设备信息上报
* @return 结果
*/
int updateTDeviceReportData(TDeviceReportData tDeviceReportData);
/**
* 删除设备信息上报
*
* @param reportId 设备信息上报ID
* @return 结果
*/
int deleteTDeviceReportDataById(String reportId);
/**
* 批量删除设备信息上报
*
* @param reportIds 需要删除的数据ID
* @return 结果
*/
int deleteTDeviceReportDataByIds(String[] reportIds);
/**
* 清楚历史数据
* @param reportTime 上报时间
* @return
*/
int clearHistoryReportedData(String reportTime);
}
package com.zehong.dangerousdevicereport.entity;
import java.math.BigDecimal;
import java.util.Date;
import lombok.Data;
/**
* 企业安全监测设备对象 safety_device_info
*
* @author zehong
* @date 2022-04-12
*/
@Data
public class SafetyDeviceInfo {
private static final long serialVersionUID = 1L;
/** $column.columnComment */
private String id;
/** 企业id */
private String enterpriseId;
/** 物品id */
private String goodsId;
/** 数据类型,1视频监控,2传感器 */
private String dataType;
/** 编号 */
private String deviceNumber;
/** 设备简号 */
private String shortNum;
/** 设备名称 */
private String deviceName;
/** 介绍 */
private String deviceInfo;
/** 设备ip */
private String deviceIp;
/** 设备登录密码 */
private String deviceLoginName;
/** 设备登录密码 */
private String deviceLoginPwd;
/** 设备登录端口 */
private String deviceLoginPort;
/** 类型 */
private String category;
/** 是否是重大危险源,0否,1是 */
private String isBigDanger;
/** 联系人 */
private String contacts;
/** 联系电话 */
private String phone;
/** 状态,0正常,1离线 */
private String status;
/** 危险等级 */
private String dangerGrade;
/** 所在厂区位置 */
private String factoryLocation;
/** 经度 */
private BigDecimal longitude;
/** 纬度 */
private BigDecimal latitude;
/** 是否删除,0正常,1已删除 */
private String isDel;
/** 创建人id */
private String createUserId;
/** 更新人id */
private String updateUserId;
/** 创建时间 */
private Date createTime;
/** 更新时间 */
private Date updateTime;
}
package com.zehong.dangerousdevicereport.entity;
import lombok.Data;
@Data
public class SysScheduledCron {
/**
*主键
*/
private String cronId;
/**
*定时任务完整类名
*/
private String cronKey;
/**
*cron表达式
*/
private String cronExpression;
/**
*任务描述
*/
private String taskExplain;
/**
*状态: {1:正常,2:停用}
*/
private Integer status;
}
package com.zehong.dangerousdevicereport.entity;
import java.util.Date;
import lombok.Data;
/**
* 【报警】对象 t_alarm_info
*
* @author zehong
* @date 2022-04-12
*/
@Data
public class TAlarmInfo {
private static final long serialVersionUID = 1L;
/** id */
private String id;
/** 企业id */
private String enterpriseId;
/** 设备id */
private String deviceId;
/** 报警类型 */
private String alarmType;
/** 报警信息 */
private String alarmInfo;
/** 上报数值 */
private String reportValue;
/** 报警时间 */
private Date alarmTime;
/** 状态,0预警中,1已处理 */
private String alarmStatus;
/** 处理类型,0未处理,1自动消警,2手动消警 */
private String handleType;
/** 处理时间 */
private Date handleTime;
/** 处理人id */
private String handleUserId;
/** 是否派发处理,0否,1是 */
private String isSend;
/** 是否下发 */
private Date sendTime;
/** 处理结果 */
private String handResult;
/** 备注信息 */
private String remarks;
/** 创建时间 */
private Date createTime;
}
package com.zehong.dangerousdevicereport.entity;
import lombok.Data;
import java.util.Date;
/**
* 设备信息上报对象 t_device_report_data
*
* @author zehong
* @date 2022-04-11
*/
@Data
public class TDeviceReportData {
private static final long serialVersionUID = 1L;
/** id */
private String reportId;
/** 设备名称 */
private String deviceNum;
/** 设备状态 */
private String deviceStatus;
/** 设备状态描述 */
private String deviceStatusDescribe;
/** 设备浓度 */
private String devicePotency;
/** 上报时间 */
private Date reportTime;
}
package com.zehong.dangerousdevicereport.enums;
public enum DeviceStatusEnum {
PREHEAT("0","预热"),
NORMAL("1","正常"),
ERROR("2","错误"),
SENSORFAILURE("3","传感器故障"),
ALARM("4","报警"),
LOWER("5","低报"),
HEIGHT("6","高报"),
COMMUNICATIONFAILURE("7","通信故障"),
OVERRANGE("8","超量程"),
OUT("9","离线"),
LOWBATTERY("10","电池电量低"),
MAINPOWERBAD("11","控制器主电源故障"),
STANDBYPOWERBAD("12","控制器备电源故障"),
NOSTEP("13","控制器无此节点"),
LOWVOTAGE("14","低电压"),
DEVICEDOWN("15","设备故障");
private String code;
private String status;
DeviceStatusEnum(String code,String status) {
this.code = code;
this.status = status;
}
public String getCode() {
return code;
}
public String getStatus(){
return status;
}
}
package com.zehong.dangerousdevicereport.enums;
public enum SysScheduledStatusEnum {
/**
* 开启
* */
ENABLED(1),
/**
* 关闭
* */
DISABLED(2),
;
private Integer code;
SysScheduledStatusEnum(int code) {
this.code = code;
}
public Integer getCode() {
return code;
}
}
package com.zehong.dangerousdevicereport.netty;
import com.zehong.dangerousdevicereport.netty.handler.UDPServerHandler;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioDatagramChannel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;
/**
* 物联网 开启检测 并写入数据库
*/
@Component
public class NettyUDPStart {
private Logger logger = LoggerFactory.getLogger(NettyUDPStart.class);
@Resource
private UDPServerHandler UDPServerHandler;
private EventLoopGroup bossGroup = new NioEventLoopGroup();
@Value("${UDPNetty.ports}")
private int[] ports;
/**
* 启动netty服务
* @throws InterruptedException
*/
@PostConstruct
public void start() throws InterruptedException {
Bootstrap b=new Bootstrap ();
b.group(bossGroup)
.channel(NioDatagramChannel.class)
.option(ChannelOption.SO_BACKLOG,128)
.handler(UDPServerHandler);
//开启需要监听 的端口
for(int port : ports){
ChannelFuture future = b.bind(port).sync();
if (future.isSuccess()) {
logger.info("UDP server启动 "+ port +" 成功");
}
}
}
/**
* 销毁
*/
@PreDestroy
public void destroy() {
bossGroup.shutdownGracefully().syncUninterruptibly();
logger.info("UDP server关闭 Netty 成功");
}
}
package com.zehong.dangerousdevicereport.netty.handler;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.zehong.dangerousdevicereport.entity.SafetyDeviceInfo;
import com.zehong.dangerousdevicereport.entity.TAlarmInfo;
import com.zehong.dangerousdevicereport.entity.TDeviceReportData;
import com.zehong.dangerousdevicereport.enums.DeviceStatusEnum;
import com.zehong.dangerousdevicereport.service.ISafetyDeviceInfoService;
import com.zehong.dangerousdevicereport.service.ITAlarmInfoService;
import com.zehong.dangerousdevicereport.service.ITDeviceReportDataService;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.socket.DatagramPacket;
import io.netty.util.CharsetUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
@Component
@Sharable
public class UDPServerHandler extends SimpleChannelInboundHandler<DatagramPacket> {
private Logger logger = LoggerFactory.getLogger(UDPServerHandler.class);
@Resource
private ITDeviceReportDataService tDeviceReportDataService;
@Resource
private ITAlarmInfoService itAlarmInfoService;
@Resource
private ISafetyDeviceInfoService safetyDeviceInfoService;
/**
* msg格式为:设备编号/设备状态/设备浓度/
*多组数据,以@分割
* @param ctx
* @param msg 上报数据
* @throws Exception
*/
@Override
protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception {
//接收上传数据
ByteBuf byteBuf = msg.content();
String bufStr = byteBuf.toString(CharsetUtil.UTF_8);
//校验设备上传数据
if(StrUtil.isEmpty(bufStr) && !bufStr.contains("/")){
logger.error("接收数据异常!");
throw new Exception("接收数据异常,请联系管理员查看设备上传数据!");
}
logger.info("udp接收上传数据:" + bufStr);
//上传数据入库并处理报警信息
List<TDeviceReportData> dataList = saveReportDataAndDealAlarmInfo(bufStr);
//报警信息处理
for(TDeviceReportData data : dataList){
dealAlarmInfo(data);
}
//数据上报市局
//数据上报省厅
}
/**
* 上报数据入库
* @param bufStr 上报数据
*/
private List<TDeviceReportData> saveReportDataAndDealAlarmInfo(String bufStr) {
List<TDeviceReportData> datas = new ArrayList<>();
//单组数据上报
if(!bufStr.contains("@")){
TDeviceReportData param = assembleSaveInfo(bufStr);
tDeviceReportDataService.insertTDeviceReportData(param);
datas.add(param);
return datas;
}
//多组数据上报
String[] reportDataInfos = bufStr.split("@");
for(String data : reportDataInfos){
TDeviceReportData param = assembleSaveInfo(data);
tDeviceReportDataService.insertTDeviceReportData(param);
datas.add(param);
}
return datas;
}
/**
* 处理报警信息
* @param data 报警信息
*/
private void dealAlarmInfo(TDeviceReportData data){
//查询报警信息是否存在
TAlarmInfo tAlarmInfo = itAlarmInfoService.selectAlarmInfoByDeviceNum(data.getDeviceNum());
if(null != tAlarmInfo){
if(DeviceStatusEnum.PREHEAT.getCode().equals(data.getDeviceStatus()) || DeviceStatusEnum.NORMAL.getCode().equals(data.getDeviceStatus())){
tAlarmInfo.setHandleTime(DateUtil.date());
tAlarmInfo.setHandleType("1");
itAlarmInfoService.updateTAlarmInfo(tAlarmInfo);
return;
}
//设备报警信息未正常更新报警信息
if(!tAlarmInfo.getAlarmInfo().equals(data.getDeviceStatus())){
tAlarmInfo.setAlarmInfo(data.getDeviceStatusDescribe());
tAlarmInfo.setReportValue(data.getDevicePotency());
tAlarmInfo.setAlarmTime(DateUtil.date());
itAlarmInfoService.updateTAlarmInfo(tAlarmInfo);
return;
}
return;
}
//新增报警信息
if(!DeviceStatusEnum.PREHEAT.getCode().equals(data.getDeviceStatus()) && !DeviceStatusEnum.NORMAL.getCode().equals(data.getDeviceStatus())){
insertAlarmInfo(data);
}
}
/**
* 新增报警信息
* @param data 上报数据
*/
private void insertAlarmInfo(TDeviceReportData data){
try{
SafetyDeviceInfo safetyDeviceInfo = getSafeDeviceInfo(data.getDeviceNum());
TAlarmInfo alarmInfo = new TAlarmInfo();
alarmInfo.setId(IdUtil.simpleUUID());
alarmInfo.setEnterpriseId(safetyDeviceInfo.getEnterpriseId());
alarmInfo.setDeviceId(safetyDeviceInfo.getId());
alarmInfo.setAlarmInfo(data.getDeviceStatusDescribe());
alarmInfo.setReportValue(data.getDevicePotency());
alarmInfo.setAlarmTime(DateUtil.date());
itAlarmInfoService.insertTAlarmInfo(alarmInfo);
}catch (Exception e){
logger.error("报警信息新增失败:"+e);
}
}
/**
* 获取设备信息
* @param deviceNum 设备编号
* @return SafetyDeviceInfo 设备信息
* @throws Exception
*/
private SafetyDeviceInfo getSafeDeviceInfo(String deviceNum) throws Exception {
SafetyDeviceInfo safetyDeviceInfo = new SafetyDeviceInfo();
safetyDeviceInfo.setDeviceNumber(deviceNum);
List<SafetyDeviceInfo> safetyDeviceInfos = safetyDeviceInfoService.selectSafetyDeviceInfoList(safetyDeviceInfo);
if(null == safetyDeviceInfos || safetyDeviceInfos.size()==0 || safetyDeviceInfos.size()>1){
throw new Exception("通知管理员设备不存在设备编号重复,请核对!");
}
return safetyDeviceInfos.get(0);
}
/**
* 拼装上报数据入库参数
* @param reportData 上报数据
* @return TDeviceReportData
*/
private TDeviceReportData assembleSaveInfo(String reportData){
String[] data = reportData.split("/");
TDeviceReportData tDeviceReportData = new TDeviceReportData();
tDeviceReportData.setDeviceNum(data[0]);
tDeviceReportData.setDeviceStatus(data[1]);
tDeviceReportData.setDeviceStatusDescribe(deviceStatus(data[1]));
tDeviceReportData.setDevicePotency(data[2]);
return tDeviceReportData;
}
/**
* 获取设备状态
* @param code 设备状态编码
* @return String
*/
private String deviceStatus(String code){
DeviceStatusEnum[] value = DeviceStatusEnum.values();
for(DeviceStatusEnum deviceStatusEnum : value){
if(deviceStatusEnum.getCode().equals(code)){
return deviceStatusEnum.getStatus();
}
}
return "";
}
}
package com.zehong.dangerousdevicereport.service;
import com.zehong.dangerousdevicereport.entity.SafetyDeviceInfo;
import java.util.List;
/**
* 企业安全监测设备Service接口
*
* @author zehong
* @date 2022-04-12
*/
public interface ISafetyDeviceInfoService {
/**
* 查询企业安全监测设备
*
* @param id 企业安全监测设备ID
* @return 企业安全监测设备
*/
SafetyDeviceInfo selectSafetyDeviceInfoById(String id);
/**
* 查询企业安全监测设备列表
*
* @param safetyDeviceInfo 企业安全监测设备
* @return 企业安全监测设备集合
*/
List<SafetyDeviceInfo> selectSafetyDeviceInfoList(SafetyDeviceInfo safetyDeviceInfo);
/**
* 新增企业安全监测设备
*
* @param safetyDeviceInfo 企业安全监测设备
* @return 结果
*/
int insertSafetyDeviceInfo(SafetyDeviceInfo safetyDeviceInfo);
/**
* 修改企业安全监测设备
*
* @param safetyDeviceInfo 企业安全监测设备
* @return 结果
*/
int updateSafetyDeviceInfo(SafetyDeviceInfo safetyDeviceInfo);
/**
* 批量删除企业安全监测设备
*
* @param ids 需要删除的企业安全监测设备ID
* @return 结果
*/
int deleteSafetyDeviceInfoByIds(String[] ids);
/**
* 删除企业安全监测设备信息
*
* @param id 企业安全监测设备ID
* @return 结果
*/
int deleteSafetyDeviceInfoById(String id);
}
package com.zehong.dangerousdevicereport.service;
import java.util.List;
import com.zehong.dangerousdevicereport.entity.TAlarmInfo;
/**
* 【报警】Service接口
*
* @author zehong
* @date 2022-04-12
*/
public interface ITAlarmInfoService {
/**
* 查询【报警】
*
* @param id 【报警】ID
* @return 【报警】
*/
TAlarmInfo selectTAlarmInfoById(String id);
/**
* 查询【报警】列表
*
* @param tAlarmInfo 【报警】
* @return 【报警】集合
*/
List<TAlarmInfo> selectTAlarmInfoList(TAlarmInfo tAlarmInfo);
/**
* 新增【报警】
*
* @param tAlarmInfo 【报警】
* @return 结果
*/
int insertTAlarmInfo(TAlarmInfo tAlarmInfo);
/**
* 修改【报警】
*
* @param tAlarmInfo 【报警】
* @return 结果
*/
int updateTAlarmInfo(TAlarmInfo tAlarmInfo);
/**
* 批量删除【报警】
*
* @param ids 需要删除的【报警】ID
* @return 结果
*/
int deleteTAlarmInfoByIds(String[] ids);
/**
* 删除【报警】信息
*
* @param id 【报警】ID
* @return 结果
*/
int deleteTAlarmInfoById(String id);
/**
* 根据设备编号查询报警信息
* @param deviceNum 设备编号
* @return
*/
TAlarmInfo selectAlarmInfoByDeviceNum(String deviceNum);
}
package com.zehong.dangerousdevicereport.service;
import java.util.List;
import com.zehong.dangerousdevicereport.entity.TDeviceReportData;
/**
* 设备信息上报Service接口
*
* @author zehong
* @date 2022-04-11
*/
public interface ITDeviceReportDataService {
/**
* 查询设备信息上报
*
* @param reportId 设备信息上报ID
* @return 设备信息上报
*/
TDeviceReportData selectTDeviceReportDataById(String reportId);
/**
* 查询设备信息上报列表
*
* @param tDeviceReportData 设备信息上报
* @return 设备信息上报集合
*/
List<TDeviceReportData> selectTDeviceReportDataList(TDeviceReportData tDeviceReportData);
/**
* 新增设备信息上报
*
* @param tDeviceReportData 设备信息上报
* @return 结果
*/
int insertTDeviceReportData(TDeviceReportData tDeviceReportData);
/**
* 修改设备信息上报
*
* @param tDeviceReportData 设备信息上报
* @return 结果
*/
int updateTDeviceReportData(TDeviceReportData tDeviceReportData);
/**
* 批量删除设备信息上报
*
* @param reportIds 需要删除的设备信息上报ID
* @return 结果
*/
int deleteTDeviceReportDataByIds(String[] reportIds);
/**
* 删除设备信息上报信息
*
* @param reportId 设备信息上报ID
* @return 结果
*/
int deleteTDeviceReportDataById(String reportId);
/**
* 清楚历史数据
* @param reportTime 上报时间
* @return
*/
int clearHistoryReportedData(String reportTime);
}
package com.zehong.dangerousdevicereport.service.impl;
import cn.hutool.core.date.DateUtil;
import com.zehong.dangerousdevicereport.dao.SafetyDeviceInfoDao;
import com.zehong.dangerousdevicereport.entity.SafetyDeviceInfo;
import com.zehong.dangerousdevicereport.service.ISafetyDeviceInfoService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
* 企业安全监测设备Service业务层处理
*
* @author zehong
* @date 2022-04-12
*/
@Service
public class SafetyDeviceInfoServiceImpl implements ISafetyDeviceInfoService {
@Resource
private SafetyDeviceInfoDao safetyDeviceInfoDao;
/**
* 查询企业安全监测设备
*
* @param id 企业安全监测设备ID
* @return 企业安全监测设备
*/
@Override
public SafetyDeviceInfo selectSafetyDeviceInfoById(String id){
return safetyDeviceInfoDao.selectSafetyDeviceInfoById(id);
}
/**
* 查询企业安全监测设备列表
*
* @param safetyDeviceInfo 企业安全监测设备
* @return 企业安全监测设备
*/
@Override
public List<SafetyDeviceInfo> selectSafetyDeviceInfoList(SafetyDeviceInfo safetyDeviceInfo){
return safetyDeviceInfoDao.selectSafetyDeviceInfoList(safetyDeviceInfo);
}
/**
* 新增企业安全监测设备
*
* @param safetyDeviceInfo 企业安全监测设备
* @return 结果
*/
@Override
public int insertSafetyDeviceInfo(SafetyDeviceInfo safetyDeviceInfo){
safetyDeviceInfo.setCreateTime(DateUtil.date());
return safetyDeviceInfoDao.insertSafetyDeviceInfo(safetyDeviceInfo);
}
/**
* 修改企业安全监测设备
*
* @param safetyDeviceInfo 企业安全监测设备
* @return 结果
*/
@Override
public int updateSafetyDeviceInfo(SafetyDeviceInfo safetyDeviceInfo){
safetyDeviceInfo.setUpdateTime(DateUtil.date());
return safetyDeviceInfoDao.updateSafetyDeviceInfo(safetyDeviceInfo);
}
/**
* 批量删除企业安全监测设备
*
* @param ids 需要删除的企业安全监测设备ID
* @return 结果
*/
@Override
public int deleteSafetyDeviceInfoByIds(String[] ids){
return safetyDeviceInfoDao.deleteSafetyDeviceInfoByIds(ids);
}
/**
* 删除企业安全监测设备信息
*
* @param id 企业安全监测设备ID
* @return 结果
*/
@Override
public int deleteSafetyDeviceInfoById(String id){
return safetyDeviceInfoDao.deleteSafetyDeviceInfoById(id);
}
}
package com.zehong.dangerousdevicereport.service.impl;
import cn.hutool.core.date.DateUtil;
import com.zehong.dangerousdevicereport.dao.TAlarmInfoDao;
import com.zehong.dangerousdevicereport.entity.TAlarmInfo;
import com.zehong.dangerousdevicereport.service.ITAlarmInfoService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
* 【报警】Service业务层处理
*
* @author zehong
* @date 2022-04-12
*/
@Service
public class TAlarmInfoServiceImpl implements ITAlarmInfoService {
@Resource
private TAlarmInfoDao tAlarmInfoDao;
/**
* 查询【报警】
*
* @param id 【报警】ID
* @return 【报警】
*/
@Override
public TAlarmInfo selectTAlarmInfoById(String id){
return tAlarmInfoDao.selectTAlarmInfoById(id);
}
/**
* 查询【报警】列表
*
* @param tAlarmInfo 【报警】
* @return 【报警】
*/
@Override
public List<TAlarmInfo> selectTAlarmInfoList(TAlarmInfo tAlarmInfo){
return tAlarmInfoDao.selectTAlarmInfoList(tAlarmInfo);
}
/**
* 新增【报警】
*
* @param tAlarmInfo 【报警】
* @return 结果
*/
@Override
public int insertTAlarmInfo(TAlarmInfo tAlarmInfo){
tAlarmInfo.setCreateTime(DateUtil.date());
return tAlarmInfoDao.insertTAlarmInfo(tAlarmInfo);
}
/**
* 修改【报警】
*
* @param tAlarmInfo 【报警】
* @return 结果
*/
@Override
public int updateTAlarmInfo(TAlarmInfo tAlarmInfo){
return tAlarmInfoDao.updateTAlarmInfo(tAlarmInfo);
}
/**
* 批量删除【报警】
*
* @param ids 需要删除的【报警】ID
* @return 结果
*/
@Override
public int deleteTAlarmInfoByIds(String[] ids){
return tAlarmInfoDao.deleteTAlarmInfoByIds(ids);
}
/**
* 删除【报警】信息
*
* @param id 【报警】ID
* @return 结果
*/
@Override
public int deleteTAlarmInfoById(String id){
return tAlarmInfoDao.deleteTAlarmInfoById(id);
}
/**
* 根据设备编号查询报警信息
* @param deviceNum 设备编号
* @return
*/
@Override
public TAlarmInfo selectAlarmInfoByDeviceNum(String deviceNum){
return tAlarmInfoDao.selectAlarmInfoByDeviceNum(deviceNum);
}
}
package com.zehong.dangerousdevicereport.service.impl;
import java.util.Date;
import java.util.List;
import com.zehong.dangerousdevicereport.dao.TDeviceReportDataDao;
import com.zehong.dangerousdevicereport.entity.TDeviceReportData;
import com.zehong.dangerousdevicereport.service.ITDeviceReportDataService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
/**
* 设备信息上报Service业务层处理
*
* @author zehong
* @date 2022-04-11
*/
@Service
public class TDeviceReportDataServiceImpl implements ITDeviceReportDataService {
@Resource
private TDeviceReportDataDao tDeviceReportDataDao;
/**
* 查询设备信息上报
*
* @param reportId 设备信息上报ID
* @return 设备信息上报
*/
@Override
public TDeviceReportData selectTDeviceReportDataById(String reportId){
return tDeviceReportDataDao.selectTDeviceReportDataById(reportId);
}
/**
* 查询设备信息上报列表
*
* @param tDeviceReportData 设备信息上报
* @return 设备信息上报
*/
@Override
public List<TDeviceReportData> selectTDeviceReportDataList(TDeviceReportData tDeviceReportData){
return tDeviceReportDataDao.selectTDeviceReportDataList(tDeviceReportData);
}
/**
* 新增设备信息上报
*
* @param tDeviceReportData 设备信息上报
* @return 结果
*/
@Override
public int insertTDeviceReportData(TDeviceReportData tDeviceReportData){
tDeviceReportData.setReportTime(new Date());
return tDeviceReportDataDao.insertTDeviceReportData(tDeviceReportData);
}
/**
* 修改设备信息上报
*
* @param tDeviceReportData 设备信息上报
* @return 结果
*/
@Override
public int updateTDeviceReportData(TDeviceReportData tDeviceReportData){
return tDeviceReportDataDao.updateTDeviceReportData(tDeviceReportData);
}
/**
* 批量删除设备信息上报
*
* @param reportIds 需要删除的设备信息上报ID
* @return 结果
*/
@Override
public int deleteTDeviceReportDataByIds(String[] reportIds){
return tDeviceReportDataDao.deleteTDeviceReportDataByIds(reportIds);
}
/**
* 删除设备信息上报信息
*
* @param reportId 设备信息上报ID
* @return 结果
*/
@Override
public int deleteTDeviceReportDataById(String reportId){
return tDeviceReportDataDao.deleteTDeviceReportDataById(reportId);
}
/**
* 清楚历史数据
* @param reportTime 上报时间
* @return
*/
@Override
public int clearHistoryReportedData(String reportTime){
return tDeviceReportDataDao.clearHistoryReportedData(reportTime);
}
}
package com.zehong.dangerousdevicereport.task;
import cn.hutool.extra.spring.SpringUtil;
import com.zehong.dangerousdevicereport.dao.SysScheduledCronRepository;
import com.zehong.dangerousdevicereport.entity.SysScheduledCron;
import com.zehong.dangerousdevicereport.enums.SysScheduledStatusEnum;
/**
* 实现Runnable接口
*/
public interface ScheduledOfTask extends Runnable {
/**
* 定时任务方法
*/
void execute();
/**
* 实现控制定时任务启用或禁用的功能
*/
@Override
default void run() {
SysScheduledCronRepository repository = SpringUtil.getBean(SysScheduledCronRepository.class);
SysScheduledCron scheduledCron = repository.findByCronKey(this.getClass().getName());
if (SysScheduledStatusEnum.DISABLED.getCode().equals(scheduledCron.getStatus())) {
// 任务是禁用状态
return;
}
execute();
}
}
package com.zehong.dangerousdevicereport.task.impl;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateUtil;
import com.zehong.dangerousdevicereport.service.ITDeviceReportDataService;
import com.zehong.dangerousdevicereport.task.ScheduledOfTask;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.Date;
/**
* 清除历史上报数据
*/
@Component
@Slf4j
public class ClearHistoryReportedData implements ScheduledOfTask {
private Logger logger = LoggerFactory.getLogger(ClearHistoryReportedData.class);
@Autowired
private ITDeviceReportDataService itDeviceReportDataService;
@Value("${timeinterval}")
private int timeInterval;
@Override
public void execute() {
Date date = DateUtil.date();
Date date1 = DateUtil.offset(date, DateField.DAY_OF_MONTH, timeInterval);
itDeviceReportDataService.clearHistoryReportedData(DateUtil.formatDateTime(date1));
logger.info("历史数据已删除");
}
}
#mysql
spring:
datasource:
username: root
password: root@123
url: jdbc:mysql://36.148.23.59:3306/whpjg?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
driver-class-name: com.mysql.jdbc.Driver
# redis 配置
redis:
# 地址
host: 36.148.23.59
# 端口,默认为6379
port: 6379
# 数据库索引
database: 6
# 密码
password: 1qaz2wsx3edc
# 连接超时时间
timeout: 10s
lettuce:
pool:
# 连接池中的最小空闲连接
min-idle: 0
# 连接池中的最大空闲连接
max-idle: 8
# 连接池的最大数据库连接数
max-active: 8
# #连接池最大阻塞等待时间(使用负值表示没有限制)
max-wait: -1ms
UDPNetty:
ports: 65013
timeinterval: -2
\ No newline at end of file
#mysql
spring:
datasource:
username: root
password: root@123
url: jdbc:mysql://36.148.23.59:3306/whpjg?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
driver-class-name: com.mysql.jdbc.Driver
# redis 配置
redis:
# 地址
host: 36.148.23.59
# 端口,默认为6379
port: 6379
# 数据库索引
database: 6
# 密码
password: 1qaz2wsx3edc
# 连接超时时间
timeout: 10s
lettuce:
pool:
# 连接池中的最小空闲连接
min-idle: 0
# 连接池中的最大空闲连接
max-idle: 8
# 连接池的最大数据库连接数
max-active: 8
# #连接池最大阻塞等待时间(使用负值表示没有限制)
max-wait: -1ms
UDPNetty:
ports: 65013
timeinterval: -2
\ No newline at end of file
#mysql
spring:
datasource:
username: root
password: root@123
url: jdbc:mysql://36.148.23.59:3306/whpjg?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
driver-class-name: com.mysql.jdbc.Driver
# redis 配置
redis:
# 地址
host: 36.148.23.59
# 端口,默认为6379
port: 6379
# 数据库索引
database: 6
# 密码
password: 1qaz2wsx3edc
# 连接超时时间
timeout: 10s
lettuce:
pool:
# 连接池中的最小空闲连接
min-idle: 0
# 连接池中的最大空闲连接
max-idle: 8
# 连接池的最大数据库连接数
max-active: 8
# #连接池最大阻塞等待时间(使用负值表示没有限制)
max-wait: -1ms
UDPNetty:
ports: 65013
timeinterval: -2
\ No newline at end of file
# 开发环境配置
server:
# 服务器的HTTP端口,默认为8080
port: 8904
servlet:
# 应用的访问路径
context-path: /dangerousEnterpriseDeviceReport
tomcat:
# tomcat的URI编码
uri-encoding: UTF-8
# tomcat最大线程数,默认为200
max-threads: 800
# Tomcat启动初始化的线程数,默认值25
min-spare-threads: 30
spring:
profiles:
active: test
#mybatis的相关配置
mybatis:
#mapper配置文件
mapper-locations: classpath:mapper/*.xml
type-aliases-package: com.zehong.dangerousdevicereport.entity
#开启驼峰命名
configuration:
map-underscore-to-camel-case: true
# 日志配置
logging:
level:
com.zehong: debug
org.springframework: warn
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- 日志存放路径 -->
<property name="root" value="${log.path}" />
<!-- 日志输出格式 -->
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n" />
<!-- 控制台输出 -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
</appender>
<!-- 按照每天生成日志文件 -->
<appender name="logfile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${root}/dangerousenterprise-device-report.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!--日志文件输出的文件名-->
<fileNamePattern>${root}/log%d{yyyy-MM-dd}-%i.log.zip
</fileNamePattern>
<maxHistory>60</maxHistory>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>50 MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
<pattern>${log.pattern}</pattern>
</encoder>
</appender>
<!-- 系统日志输出 -->
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${root}/sys-info.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${root}/sys-info.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤的级别 -->
<level>INFO</level>
<!-- 匹配时的操作:接收(记录) -->
<onMatch>ACCEPT</onMatch>
<!-- 不匹配时的操作:拒绝(不记录) -->
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${root}/sys-error.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${root}/sys-error.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤的级别 -->
<level>ERROR</level>
<!-- 匹配时的操作:接收(记录) -->
<onMatch>ACCEPT</onMatch>
<!-- 不匹配时的操作:拒绝(不记录) -->
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- 全部系统日志 -->
<root level="DEBUG">
<appender-ref ref="logfile" />
</root>
<!-- 系统模块日志级别控制 -->
<logger name="com.zehong" level="info" />
<!-- Spring日志级别控制 -->
<logger name="org.springframework" level="warn" />
<root level="info">
<appender-ref ref="console" />
</root>
<!--系统操作日志-->
<root level="info">
<appender-ref ref="file_info" />
<appender-ref ref="file_error" />
</root>
</configuration>
\ No newline at end of file
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zehong.dangerousdevicereport.dao.SysScheduledCronRepository">
<select id="findAll" resultType="com.zehong.dangerousdevicereport.entity.SysScheduledCron">
select * from t_scheduled_cron;
</select>
<select id="findByCronKey" parameterType="java.lang.String" resultType="com.zehong.dangerousdevicereport.entity.SysScheduledCron">
select * from t_scheduled_cron where cron_key = #{cronKey}
</select>
<update id="updateCronExpressionByCronKey" parameterType="java.lang.String">
update sys_task_cron set cron_expression= #{newCron} where cron_key= #{cronKey}
</update>
<update id="updateTaskStatusByCronKey" parameterType="java.lang.String">
update sys_task_cron set task_status= #{status} where cron_key= #{cronKey}
</update>
</mapper>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zehong.dangerousdevicereport.dao.TAlarmInfoDao">
<resultMap type="TAlarmInfo" id="TAlarmInfoResult">
<result property="id" column="id" />
<result property="enterpriseId" column="enterprise_id" />
<result property="deviceId" column="device_id" />
<result property="alarmType" column="alarm_type" />
<result property="alarmInfo" column="alarm_info" />
<result property="reportValue" column="report_value" />
<result property="alarmTime" column="alarm_time" />
<result property="alarmStatus" column="alarm_status" />
<result property="handleType" column="handle_type" />
<result property="handleTime" column="handle_time" />
<result property="handleUserId" column="handle_user_id" />
<result property="isSend" column="is_send" />
<result property="sendTime" column="send_time" />
<result property="handResult" column="hand_result" />
<result property="remarks" column="remarks" />
<result property="createTime" column="create_time" />
</resultMap>
<sql id="selectTAlarmInfoVo">
select id, enterprise_id, device_id, alarm_type, alarm_info, report_value, alarm_time, alarm_status, handle_type, handle_time, handle_user_id, is_send, send_time, hand_result, remarks, create_time from t_alarm_info
</sql>
<select id="selectTAlarmInfoList" parameterType="TAlarmInfo" resultMap="TAlarmInfoResult">
<include refid="selectTAlarmInfoVo"/>
<where>
<if test="enterpriseId != null and enterpriseId != ''"> and enterprise_id = #{enterpriseId}</if>
<if test="deviceId != null and deviceId != ''"> and device_id = #{deviceId}</if>
<if test="alarmType != null and alarmType != ''"> and alarm_type = #{alarmType}</if>
<if test="alarmInfo != null and alarmInfo != ''"> and alarm_info = #{alarmInfo}</if>
<if test="reportValue != null and reportValue != ''"> and report_value = #{reportValue}</if>
<if test="alarmTime != null "> and alarm_time = #{alarmTime}</if>
<if test="alarmStatus != null and alarmStatus != ''"> and alarm_status = #{alarmStatus}</if>
<if test="handleType != null and handleType != ''"> and handle_type = #{handleType}</if>
<if test="handleTime != null "> and handle_time = #{handleTime}</if>
<if test="handleUserId != null and handleUserId != ''"> and handle_user_id = #{handleUserId}</if>
<if test="isSend != null and isSend != ''"> and is_send = #{isSend}</if>
<if test="sendTime != null "> and send_time = #{sendTime}</if>
<if test="handResult != null and handResult != ''"> and hand_result = #{handResult}</if>
<if test="remarks != null and remarks != ''"> and remarks = #{remarks}</if>
</where>
</select>
<select id="selectTAlarmInfoById" parameterType="String" resultMap="TAlarmInfoResult">
<include refid="selectTAlarmInfoVo"/>
where id = #{id}
</select>
<insert id="insertTAlarmInfo" parameterType="TAlarmInfo">
insert into t_alarm_info
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="enterpriseId != null">enterprise_id,</if>
<if test="deviceId != null">device_id,</if>
<if test="alarmType != null">alarm_type,</if>
<if test="alarmInfo != null">alarm_info,</if>
<if test="reportValue != null">report_value,</if>
<if test="alarmTime != null">alarm_time,</if>
<if test="alarmStatus != null">alarm_status,</if>
<if test="handleType != null">handle_type,</if>
<if test="handleTime != null">handle_time,</if>
<if test="handleUserId != null">handle_user_id,</if>
<if test="isSend != null">is_send,</if>
<if test="sendTime != null">send_time,</if>
<if test="handResult != null">hand_result,</if>
<if test="remarks != null">remarks,</if>
<if test="createTime != null">create_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
<if test="enterpriseId != null">#{enterpriseId},</if>
<if test="deviceId != null">#{deviceId},</if>
<if test="alarmType != null">#{alarmType},</if>
<if test="alarmInfo != null">#{alarmInfo},</if>
<if test="reportValue != null">#{reportValue},</if>
<if test="alarmTime != null">#{alarmTime},</if>
<if test="alarmStatus != null">#{alarmStatus},</if>
<if test="handleType != null">#{handleType},</if>
<if test="handleTime != null">#{handleTime},</if>
<if test="handleUserId != null">#{handleUserId},</if>
<if test="isSend != null">#{isSend},</if>
<if test="sendTime != null">#{sendTime},</if>
<if test="handResult != null">#{handResult},</if>
<if test="remarks != null">#{remarks},</if>
<if test="createTime != null">#{createTime},</if>
</trim>
</insert>
<update id="updateTAlarmInfo" parameterType="TAlarmInfo">
update t_alarm_info
<trim prefix="SET" suffixOverrides=",">
<if test="enterpriseId != null">enterprise_id = #{enterpriseId},</if>
<if test="deviceId != null">device_id = #{deviceId},</if>
<if test="alarmType != null">alarm_type = #{alarmType},</if>
<if test="alarmInfo != null">alarm_info = #{alarmInfo},</if>
<if test="reportValue != null">report_value = #{reportValue},</if>
<if test="alarmTime != null">alarm_time = #{alarmTime},</if>
<if test="alarmStatus != null">alarm_status = #{alarmStatus},</if>
<if test="handleType != null">handle_type = #{handleType},</if>
<if test="handleTime != null">handle_time = #{handleTime},</if>
<if test="handleUserId != null">handle_user_id = #{handleUserId},</if>
<if test="isSend != null">is_send = #{isSend},</if>
<if test="sendTime != null">send_time = #{sendTime},</if>
<if test="handResult != null">hand_result = #{handResult},</if>
<if test="remarks != null">remarks = #{remarks},</if>
<if test="createTime != null">create_time = #{createTime},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteTAlarmInfoById" parameterType="String">
delete from t_alarm_info where id = #{id}
</delete>
<delete id="deleteTAlarmInfoByIds" parameterType="String">
delete from t_alarm_info where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<select id="selectAlarmInfoByDeviceNum" parameterType="String" resultMap="TAlarmInfoResult">
SELECT
alarm.id,
alarm.enterprise_id,
alarm.device_id,
alarm.alarm_type,
alarm.alarm_info,
alarm.report_value,
alarm.alarm_time,
alarm.alarm_status,
alarm.handle_type,
alarm.handle_time,
alarm.handle_user_id,
alarm.is_send,
alarm.send_time,
alarm.hand_result,
alarm.remarks,
alarm.create_time
FROM
t_alarm_info alarm
LEFT JOIN safety_device_info device ON device.id = alarm.device_id
WHERE device.device_number = #{deviceNum}
AND alarm.handle_time IS NULL
</select>
</mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zehong.dangerousdevicereport.dao.TDeviceReportDataDao">
<resultMap type="TDeviceReportData" id="TDeviceReportDataResult">
<result property="reportId" column="report_id" />
<result property="deviceNum" column="device_num" />
<result property="deviceStatus" column="device_status" />
<result property="deviceStatusDescribe" column="device_status_describe" />
<result property="devicePotency" column="device_potency" />
<result property="reportTime" column="report_time" />
</resultMap>
<sql id="selectTDeviceReportDataVo">
select report_id, device_num, device_status, device_status_describe, device_potency, report_time from t_device_report_data
</sql>
<select id="selectTDeviceReportDataList" parameterType="TDeviceReportData" resultMap="TDeviceReportDataResult">
<include refid="selectTDeviceReportDataVo"/>
<where>
<if test="deviceNum != null and deviceNum != ''"> and device_num = #{deviceNum}</if>
<if test="deviceStatus != null and deviceStatus != ''"> and device_status = #{deviceStatus}</if>
<if test="deviceStatusDescribe != null and deviceStatusDescribe != ''"> and device_status_describe = #{deviceStatusDescribe}</if>
<if test="devicePotency != null and devicePotency != ''"> and device_potency = #{devicePotency}</if>
<if test="reportTime != null "> and report_time = #{reportTime}</if>
</where>
</select>
<select id="selectTDeviceReportDataById" parameterType="String" resultMap="TDeviceReportDataResult">
<include refid="selectTDeviceReportDataVo"/>
where report_id = #{reportId}
</select>
<insert id="insertTDeviceReportData" parameterType="TDeviceReportData">
insert into t_device_report_data
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="deviceNum != null">device_num,</if>
<if test="deviceStatus != null">device_status,</if>
<if test="deviceStatusDescribe != null">device_status_describe,</if>
<if test="devicePotency != null">device_potency,</if>
<if test="reportTime != null">report_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="deviceNum != null">#{deviceNum},</if>
<if test="deviceStatus != null">#{deviceStatus},</if>
<if test="deviceStatusDescribe != null">#{deviceStatusDescribe},</if>
<if test="devicePotency != null">#{devicePotency},</if>
<if test="reportTime != null">#{reportTime},</if>
</trim>
</insert>
<update id="updateTDeviceReportData" parameterType="TDeviceReportData">
update t_device_report_data
<trim prefix="SET" suffixOverrides=",">
<if test="deviceNum != null">device_num = #{deviceNum},</if>
<if test="deviceStatus != null">device_status = #{deviceStatus},</if>
<if test="deviceStatusDescribe != null">device_status_describe = #{deviceStatusDescribe},</if>
<if test="devicePotency != null">device_potency = #{devicePotency},</if>
<if test="reportTime != null">report_time = #{reportTime},</if>
</trim>
where report_id = #{reportId}
</update>
<delete id="deleteTDeviceReportDataById" parameterType="String">
delete from t_device_report_data where report_id = #{reportId}
</delete>
<delete id="deleteTDeviceReportDataByIds" parameterType="String">
delete from t_device_report_data where report_id in
<foreach item="reportId" collection="array" open="(" separator="," close=")">
#{reportId}
</foreach>
</delete>
<delete id="clearHistoryReportedData" parameterType="String">
delete from t_device_report_data where report_time &lt;= #{reportTime}
</delete>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment