Commit 5deb2e7a authored by 耿迪迪's avatar 耿迪迪

燃气设备上报

parents
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
/*
* Copyright 2007-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.net.*;
import java.io.*;
import java.nio.channels.*;
import java.util.Properties;
public class MavenWrapperDownloader {
private static final String WRAPPER_VERSION = "0.5.6";
/**
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
*/
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
/**
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
* use instead of the default one.
*/
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
".mvn/wrapper/maven-wrapper.properties";
/**
* Path where the maven-wrapper.jar will be saved to.
*/
private static final String MAVEN_WRAPPER_JAR_PATH =
".mvn/wrapper/maven-wrapper.jar";
/**
* Name of the property which should be used to override the default download url for the wrapper.
*/
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
public static void main(String args[]) {
System.out.println("- Downloader started");
File baseDirectory = new File(args[0]);
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
// If the maven-wrapper.properties exists, read it and check if it contains a custom
// wrapperUrl parameter.
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
String url = DEFAULT_DOWNLOAD_URL;
if(mavenWrapperPropertyFile.exists()) {
FileInputStream mavenWrapperPropertyFileInputStream = null;
try {
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
Properties mavenWrapperProperties = new Properties();
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
} catch (IOException e) {
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
} finally {
try {
if(mavenWrapperPropertyFileInputStream != null) {
mavenWrapperPropertyFileInputStream.close();
}
} catch (IOException e) {
// Ignore ...
}
}
}
System.out.println("- Downloading from: " + url);
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
if(!outputFile.getParentFile().exists()) {
if(!outputFile.getParentFile().mkdirs()) {
System.out.println(
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
}
}
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
try {
downloadFileFromURL(url, outputFile);
System.out.println("Done");
System.exit(0);
} catch (Throwable e) {
System.out.println("- Error downloading");
e.printStackTrace();
System.exit(1);
}
}
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
String username = System.getenv("MVNW_USERNAME");
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
}
URL website = new URL(urlString);
ReadableByteChannel rbc;
rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(destination);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
rbc.close();
}
}
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.1/apache-maven-3.8.1-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
This diff is collapsed.
@REM ----------------------------------------------------------------------------
@REM Licensed to the Apache Software Foundation (ASF) under one
@REM or more contributor license agreements. See the NOTICE file
@REM distributed with this work for additional information
@REM regarding copyright ownership. The ASF licenses this file
@REM to you under the Apache License, Version 2.0 (the
@REM "License"); you may not use this file except in compliance
@REM with the License. You may obtain a copy of the License at
@REM
@REM https://www.apache.org/licenses/LICENSE-2.0
@REM
@REM Unless required by applicable law or agreed to in writing,
@REM software distributed under the License is distributed on an
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@REM KIND, either express or implied. See the License for the
@REM specific language governing permissions and limitations
@REM under the License.
@REM ----------------------------------------------------------------------------
@REM ----------------------------------------------------------------------------
@REM Maven Start Up Batch script
@REM
@REM Required ENV vars:
@REM JAVA_HOME - location of a JDK home dir
@REM
@REM Optional ENV vars
@REM M2_HOME - location of maven2's installed home dir
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
@REM e.g. to debug Maven itself, use
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
@REM ----------------------------------------------------------------------------
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
@echo off
@REM set title of command window
title %0
@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on'
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
@REM set %HOME% to equivalent of $HOME
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
@REM Execute a user defined script before this one
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
:skipRcPre
@setlocal
set ERROR_CODE=0
@REM To isolate internal variables from possible post scripts, we use another setlocal
@setlocal
@REM ==== START VALIDATION ====
if not "%JAVA_HOME%" == "" goto OkJHome
echo.
echo Error: JAVA_HOME not found in your environment. >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
:OkJHome
if exist "%JAVA_HOME%\bin\java.exe" goto init
echo.
echo Error: JAVA_HOME is set to an invalid directory. >&2
echo JAVA_HOME = "%JAVA_HOME%" >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
@REM ==== END VALIDATION ====
:init
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
@REM Fallback to current working directory if not found.
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
set EXEC_DIR=%CD%
set WDIR=%EXEC_DIR%
:findBaseDir
IF EXIST "%WDIR%"\.mvn goto baseDirFound
cd ..
IF "%WDIR%"=="%CD%" goto baseDirNotFound
set WDIR=%CD%
goto findBaseDir
:baseDirFound
set MAVEN_PROJECTBASEDIR=%WDIR%
cd "%EXEC_DIR%"
goto endDetectBaseDir
:baseDirNotFound
set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
cd "%EXEC_DIR%"
:endDetectBaseDir
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
@setlocal EnableExtensions EnableDelayedExpansion
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
:endReadAdditionalConfig
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
)
@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
if exist %WRAPPER_JAR% (
if "%MVNW_VERBOSE%" == "true" (
echo Found %WRAPPER_JAR%
)
) else (
if not "%MVNW_REPOURL%" == "" (
SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
)
if "%MVNW_VERBOSE%" == "true" (
echo Couldn't find %WRAPPER_JAR%, downloading it ...
echo Downloading from: %DOWNLOAD_URL%
)
powershell -Command "&{"^
"$webclient = new-object System.Net.WebClient;"^
"if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^
"$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^
"}"^
"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^
"}"
if "%MVNW_VERBOSE%" == "true" (
echo Finished downloading %WRAPPER_JAR%
)
)
@REM End of extension
@REM Provide a "standardized" way to retrieve the CLI args that will
@REM work with both Windows and non-Windows executions.
set MAVEN_CMD_LINE_ARGS=%*
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
if ERRORLEVEL 1 goto error
goto end
:error
set ERROR_CODE=1
:end
@endlocal & set ERROR_CODE=%ERROR_CODE%
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
@REM check for post script, once with legacy .bat ending and once with .cmd ending
if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
:skipRcPost
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
if "%MAVEN_BATCH_PAUSE%" == "on" pause
if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
exit /B %ERROR_CODE%
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.zehong</groupId>
<artifactId>gass-device-report</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>gass-device-report</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--集成redis-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!--lombok-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.10</version>
</dependency>
<!--mysql数据库驱动-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!--mybatis-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.0</version>
</dependency>
<!--常用工具类 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<!-- JSONObject对象依赖的jar包 -->
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.3</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>net.sf.ezmorph</groupId>
<artifactId>ezmorph</artifactId>
<version>1.0.6</version>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.2.3</version>
<classifier>jdk15</classifier><!-- jdk版本 -->
</dependency>
<!-- Json依赖架包下载 -->
<!--httpclient-->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>
<!--netty-->
<!--<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.36.Final</version>
</dependency>-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.7</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
package com.zehong.gassdevicereport;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@MapperScan("com.zehong.gassdevicereport.dao")
public class GassDeviceReportApplication /*implements CommandLineRunner*/{
public static void main(String[] args) {
SpringApplication.run(GassDeviceReportApplication.class, args);
}
}
package com.zehong.gassdevicereport.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.gassdevicereport.config;
import com.zehong.gassdevicereport.dao.SysScheduledCronRepository;
import com.zehong.gassdevicereport.entity.SysScheduledCron;
import com.zehong.gassdevicereport.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.gassdevicereport.constant;
public class Constant {
/**
* redis存储设备上报信息key
*/
public final static String DEVICE_REDIS_KEY = "deviceCode";
}
package com.zehong.gassdevicereport.dao;
import com.zehong.gassdevicereport.entity.SysDictData;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 字典表 数据层
*
* @author zehong
*/
public interface SysDictDataDao {
/**
* 根据条件分页查询字典数据
*
* @param dictData 字典数据信息
* @return 字典数据集合信息
*/
List<SysDictData> selectDictDataList(SysDictData dictData);
/**
* 根据字典类型查询字典数据
*
* @param dictType 字典类型
* @return 字典数据集合信息
*/
List<SysDictData> selectDictDataByType(String dictType);
/**
* 根据字典类型和字典键值查询字典数据信息
*
* @param dictType 字典类型
* @param dictValue 字典键值
* @return 字典标签
*/
String selectDictLabel(@Param("dictType") String dictType, @Param("dictValue") String dictValue);
/**
* 根据字典数据ID查询信息
*
* @param dictCode 字典数据ID
* @return 字典数据
*/
SysDictData selectDictDataById(Long dictCode);
/**
* 查询字典数据
*
* @param dictType 字典类型
* @return 字典数据
*/
int countDictDataByType(String dictType);
/**
* 通过字典ID删除字典数据信息
*
* @param dictCode 字典数据ID
* @return 结果
*/
int deleteDictDataById(Long dictCode);
/**
* 批量删除字典数据信息
*
* @param dictCodes 需要删除的字典数据ID
* @return 结果
*/
int deleteDictDataByIds(Long[] dictCodes);
/**
* 新增字典数据信息
*
* @param dictData 字典数据信息
* @return 结果
*/
int insertDictData(SysDictData dictData);
/**
* 修改字典数据信息
*
* @param dictData 字典数据信息
* @return 结果
*/
int updateDictData(SysDictData dictData);
/**
* 同步修改字典类型
*
* @param oldDictType 旧字典类型
* @param newDictType 新旧字典类型
* @return 结果
*/
int updateDictDataType(@Param("oldDictType") String oldDictType, @Param("newDictType") String newDictType);
}
package com.zehong.gassdevicereport.dao;
import com.zehong.gassdevicereport.entity.SysDictType;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* 字典表 数据层
*
* @author zehong
*/
@Mapper
public interface SysDictTypeDao {
/**
* 根据条件分页查询字典类型
*
* @param dictType 字典类型信息
* @return 字典类型集合信息
*/
List<SysDictType> selectDictTypeList(SysDictType dictType);
/**
* 根据所有字典类型
*
* @return 字典类型集合信息
*/
List<SysDictType> selectDictTypeAll();
/**
* 根据字典类型ID查询信息
*
* @param dictId 字典类型ID
* @return 字典类型
*/
SysDictType selectDictTypeById(Long dictId);
/**
* 根据字典类型查询信息
*
* @param dictType 字典类型
* @return 字典类型
*/
SysDictType selectDictTypeByType(String dictType);
/**
* 通过字典ID删除字典信息
*
* @param dictId 字典ID
* @return 结果
*/
int deleteDictTypeById(Long dictId);
/**
* 批量删除字典类型信息
*
* @param dictIds 需要删除的字典ID
* @return 结果
*/
int deleteDictTypeByIds(Long[] dictIds);
/**
* 新增字典类型信息
*
* @param dictType 字典类型信息
* @return 结果
*/
int insertDictType(SysDictType dictType);
/**
* 修改字典类型信息
*
* @param dictType 字典类型信息
* @return 结果
*/
int updateDictType(SysDictType dictType);
/**
* 校验字典类型称是否唯一
*
* @param dictType 字典类型
* @return 结果
*/
SysDictType checkDictTypeUnique(String dictType);
}
package com.zehong.gassdevicereport.dao;
import com.zehong.gassdevicereport.entity.SysScheduledCron;
import org.apache.ibatis.annotations.Mapper;
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.gassdevicereport.dao;
import com.zehong.gassdevicereport.entity.TDeviceAlarm;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* 报警信息Mapper接口
*
* @author zehong
* @date 2021-08-03
*/
public interface TDeviceAlarmDao
{
/**
* 查询报警信息
*
* @param alarmId 报警信息ID
* @return 报警信息
*/
TDeviceAlarm selectTDeviceAlarmById(Long alarmId);
/**
* 查询报警信息列表
*
* @param tDeviceAlarm 报警信息
* @return 报警信息集合
*/
List<TDeviceAlarm> selectTDeviceAlarmList(TDeviceAlarm tDeviceAlarm);
/**
* 新增报警信息
*
* @param tDeviceAlarm 报警信息
* @return 结果
*/
int insertTDeviceAlarm(TDeviceAlarm tDeviceAlarm);
/**
* 修改报警信息
*
* @param tDeviceAlarm 报警信息
* @return 结果
*/
int updateTDeviceAlarm(TDeviceAlarm tDeviceAlarm);
/**
* 删除报警信息
*
* @param alarmId 报警信息ID
* @return 结果
*/
int deleteTDeviceAlarmById(Long alarmId);
/**
* 批量删除报警信息
*
* @param alarmIds 需要删除的数据ID
* @return 结果
*/
int deleteTDeviceAlarmByIds(Long[] alarmIds);
/**
* 根据设备id查询报警信息
* @param deviceId
* @return
*/
TDeviceAlarm selectTDeviceAlarmByDeviceId(Long deviceId);
}
package com.zehong.gassdevicereport.dao;
import com.zehong.gassdevicereport.entity.TDeviceReportData;
import java.util.List;
/**
* 设备监控Mapper接口
*
* @author zehong
* @date 2021-08-09
*/
public interface TDeviceReportDataDao {
/**
* 查询设备监控
*
* @param deviceReportDataId 设备监控ID
* @return 设备监控
*/
TDeviceReportData selectTDeviceReportDataById(Long deviceReportDataId);
/**
* 查询设备监控列表
*
* @param tDeviceReportData 设备监控
* @return 设备监控集合
*/
List<TDeviceReportData> selectTDeviceReportDataList(TDeviceReportData tDeviceReportData);
/**
* 新增设备监控
*
* @param tDeviceReportData 设备监控
* @return 结果
*/
int insertTDeviceReportData(TDeviceReportData tDeviceReportData);
/**
* 修改设备监控
*
* @param tDeviceReportData 设备监控
* @return 结果
*/
int updateTDeviceReportData(TDeviceReportData tDeviceReportData);
/**
* 删除设备监控
*
* @param deviceReportDataId 设备监控ID
* @return 结果
*/
int deleteTDeviceReportDataById(Long deviceReportDataId);
/**
* 批量删除设备监控
*
* @param deviceReportDataIds 需要删除的数据ID
* @return 结果
*/
int deleteTDeviceReportDataByIds(Long[] deviceReportDataIds);
}
package com.zehong.gassdevicereport.dao;
import com.zehong.gassdevicereport.entity.TMonitorDevice;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* 设备监控Mapper接口
*
* @author zehong
* @date 2021-08-03
*/
public interface TMonitorDeviceDao
{
/**
* 查询设备监控
*
* @param monitorId 设备监控ID
* @return 设备监控
*/
TMonitorDevice selectTMonitorDeviceById(Long monitorId);
/**
* 查询设备监控列表
*
* @param tMonitorDevice 设备监控
* @return 设备监控集合
*/
List<TMonitorDevice> selectTMonitorDeviceList(TMonitorDevice tMonitorDevice);
/**
* 新增设备监控
*
* @param tMonitorDevice 设备监控
* @return 结果
*/
int insertTMonitorDevice(TMonitorDevice tMonitorDevice);
/**
* 修改设备监控
*
* @param tMonitorDevice 设备监控
* @return 结果
*/
int updateTMonitorDevice(TMonitorDevice tMonitorDevice);
/**
* 删除设备监控
*
* @param monitorId 设备监控ID
* @return 结果
*/
int deleteTMonitorDeviceById(Long monitorId);
/**
* 批量删除设备监控
*
* @param monitorIds 需要删除的数据ID
* @return 结果
*/
int deleteTMonitorDeviceByIds(Long[] monitorIds);
/**
* 通过物联网编号获取设备监控信息
* @param iotNo 物联网编号
* @return
*/
List<TMonitorDevice> getDeviceInfosByIotNo(String iotNo);
}
package com.zehong.gassdevicereport.entity;
import lombok.Data;
import java.math.BigDecimal;
@Data
public class ReciveReportData {
/** 设备编号*/
private String deviceCode;
/** 设备状态*/
private String deviceStatus;
/** 设备浓度*/
private BigDecimal potency;
/** 设备类型*/
private String deviceType;
private String DeviceDescribe;
}
package com.zehong.gassdevicereport.entity;
import lombok.Data;
import java.util.Date;
/**
* 字典数据表 sys_dict_data
*
* @author zehong
*/
@Data
public class SysDictData{
private static final long serialVersionUID = 1L;
/** 字典编码 */
private Long dictCode;
/** 字典排序 */
private Long dictSort;
/** 字典标签 */
private String dictLabel;
/** 字典键值 */
private String dictValue;
/** 字典类型 */
private String dictType;
/** 样式属性(其他样式扩展) */
private String cssClass;
/** 表格字典样式 */
private String listClass;
/** 是否默认(Y是 N否) */
private String isDefault;
/** 状态(0正常 1停用) */
private String status;
private String createBy;
private String remark;
private Date createTime;
}
package com.zehong.gassdevicereport.entity;
import lombok.Data;
/**
* 字典类型表 sys_dict_type
*
* @author zehong
*/
@Data
public class SysDictType {
/** 字典主键 */
private Long dictId;
/** 字典名称 */
private String dictName;
/** 字典类型 */
private String dictType;
/** 状态(0正常 1停用) */
private String status;
}
package com.zehong.gassdevicereport.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.gassdevicereport.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.util.Date;
/**
* 报警信息对象 t_device_alarm
*
* @author zehong
* @date 2021-08-03
*/
@Data
public class TDeviceAlarm
{
private static final long serialVersionUID = 1L;
/** $column.columnComment */
private Long alarmId;
/** 设备id */
private Long deviceId;
private String deviceType;
/** 工单id */
private String orderId;
/** 报警类型 */
private String alarmType;
/** 报警值(报警信息) */
private String alarmValue;
/** 报警开始时间 */
private Date startTime;
/** 报警结束时间 */
private Date endTime;
/**
处理状态(1不需处理,2已处理完成,3未处理完成) */
private String dealStatus;
/** 创建时间 */
private Date createTime;
/** 更新时间 */
private Date updateTime;
}
package com.zehong.gassdevicereport.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.math.BigDecimal;
import java.util.Date;
/**
* 设备监控对象 t_device_report_data
*
* @author zehong
* @date 2021-08-09
*/
@Data
public class TDeviceReportData {
private static final long serialVersionUID = 1L;
/** 设备上报id */
private Long deviceReportDataId;
/** 设备id */
private Long deviceNum;
/** 标况累计量 */
private BigDecimal standardConditionAccumulation;
/** 工况累计量 */
private BigDecimal workingConditionAccumulation;
/** 剩余量 */
private BigDecimal residualQuantity;
/** 标况流量 */
private BigDecimal standardConditionFlow;
/** 工况流量 */
private BigDecimal workingConditionFlow;
/** 温度 */
private BigDecimal temperature;
/** 压力 */
private BigDecimal pressure;
/** 上报时间 */
@JsonFormat(pattern = "yyyy-MM-dd")
private Date reportTime;
/** 通讯状态 */
private String communicationStatus;
/** 设备状态 */
private String deviceStatus;
/** 创建时间 */
private Date createTime;
/** 更新时间 */
private Date updateTime;
}
package com.zehong.gassdevicereport.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.math.BigDecimal;
import java.util.Date;
/**
* 设备监控对象 t_monitor_device
*
* @author zehong
* @date 2021-08-03
*/
@Data
public class TMonitorDevice
{
private static final long serialVersionUID = 1L;
/** 设备监控id */
private Long monitorId;
/** 设备id */
private Long deviceId;
/** 物联网编号 */
private String IotNo;
/** 设备阈值 */
private BigDecimal deviceThreshold;
/** 关联管道id */
private Long relationPipeId;
/** 关联管道阈值 */
private BigDecimal relationPipeThreshold;
/** 关联设备id */
private Long relationDeviceId;
/** 关联设备物联网编号 */
private String relationIotNo;
/** 关联设备阈值 */
private BigDecimal relationDeviceThreshold;
/** 创建时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
/** 更新时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;
}
package com.zehong.gassdevicereport.enums;
public enum AlarmDealStatusEnum {
NOT_DEAL("1"),SOLVE_DEAL("2"),WAIT_DEAL("3");
private String dealStatus;
AlarmDealStatusEnum(String dealStatus) {
this.dealStatus = dealStatus;
}
public String getDealStatus() {
return dealStatus;
}
}
package com.zehong.gassdevicereport.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.gassdevicereport.netty;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
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 NettyStart {
private Logger logger = LoggerFactory.getLogger(NettyStart.class);
@Resource
private ServerHandler serverHandler;
private EventLoopGroup bossGroup = new NioEventLoopGroup();
private EventLoopGroup workGroup = new NioEventLoopGroup();
@Value("${netty.ports}")
private int[] ports;
/**
* 启动netty服务
* @throws InterruptedException
*/
@PostConstruct
public void start() throws InterruptedException {
ServerBootstrap b=new ServerBootstrap();
b.group(bossGroup,workGroup)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_BACKLOG,128)
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel socketChannel) throws Exception {
socketChannel.pipeline().addLast(serverHandler);
}
});
//开启需要监听 的端口
for(int port : ports){
ChannelFuture future = b.bind(port).sync();
if (future.isSuccess()) {
logger.info("启动 "+ port +" 成功");
}
}
}
/**
* 销毁
*/
@PreDestroy
public void destroy() {
bossGroup.shutdownGracefully().syncUninterruptibly();
workGroup.shutdownGracefully().syncUninterruptibly();
logger.info("关闭 Netty 成功");
}
}
package com.zehong.gassdevicereport.netty;
import com.alibaba.fastjson.JSONObject;
import com.zehong.gassdevicereport.constant.Constant;
import com.zehong.gassdevicereport.entity.ReciveReportData;
import com.zehong.gassdevicereport.service.ITDeviceReportDataService;
import com.zehong.gassdevicereport.utils.RedisUtil;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.socket.SocketChannel;
import io.netty.util.CharsetUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.util.Date;
/**
* 物联网 开启检测端口 并写入数据库
*/
@Component
@Sharable
public class ServerHandler extends ChannelInboundHandlerAdapter {
private Logger logger = LoggerFactory.getLogger(ServerHandler.class);
@Autowired
private RedisUtil redisUtil;
@Autowired
private ITDeviceReportDataService itDeviceReportDataService;
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
SocketChannel channel = (SocketChannel) ctx.channel();
logger.info("链接报告开始");
logger.info("链接报告信息:有一客户端链接到本服务端");
logger.info("链接报告IP:{}", channel.localAddress().getHostString());
logger.info("链接报告Port:{}", channel.localAddress().getPort());
logger.info("链接报告完毕");
//通知客户端链接建立成功
String str = "通知客户端链接建立成功" + " " + new Date() + " " + channel.localAddress().getHostString() + "\r\n";
ctx.writeAndFlush(str);
}
/**
* 当客户端主动断开服务端的链接后,这个通道就是不活跃的。也就是说客户端与服务端的关闭了通信通道并且不可以传输数据
*/
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
logger.info("客户端断开链接{}", ctx.channel().localAddress().toString());
}
/**
* 获取数据
* @param ctx 上下文
* @param msg 获取的数据
* @throws UnsupportedEncodingException
*/
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws UnsupportedEncodingException{
//msg为接收到的客户端传递的数据 个人这边直接传的json 数据
ByteBuf readMessage= (ByteBuf) msg;
//解析客户端json 数据
String a = readMessage.toString(CharsetUtil.UTF_8);
ReciveReportData reciveReportData = JSONObject.parseObject(a,ReciveReportData.class);
System.out.println("接收到的数据"+readMessage.toString(CharsetUtil.UTF_8));
//设备请求的 服务器端的地址 用作监听设备请求的那个端口
SocketChannel channel=(SocketChannel)ctx.channel();
int port = channel.localAddress().getPort();
if(7397 == port){
reciveReportData.setDeviceType("4");
reciveReportData.setDeviceDescribe("压力异常");
redisUtil.set(Constant.DEVICE_REDIS_KEY+reciveReportData.getDeviceCode(),reciveReportData);
}else{
redisUtil.set(Constant.DEVICE_REDIS_KEY+reciveReportData.getDeviceCode(),reciveReportData);
}
//更新redis中设备最新信息
//TDeviceReportData tDeviceReportData = new TDeviceReportData();
//设备上报数据入库
// itDeviceReportDataService.insertTDeviceReportData(tDeviceReportData);
//判断端口如果客户端请求的端口号为9898 就是写入第一张表 这样可以实现 设备传递数据参数不一致
String rmsg="0";//返回失败的信息
ByteBuf message= Unpooled.copiedBuffer(rmsg.getBytes());//处理返回的信息
//ctx.write(in2);//返回信息
ctx.writeAndFlush(message);//返回信息
//刷新缓存区
ctx.flush();
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
cause.printStackTrace();
ctx.close();
}
}
package com.zehong.gassdevicereport.result;
import java.io.Serializable;
public class Result implements Serializable{
private String code;
private String msg;
private Object data;
public Result(String code, String msg, Object data) {
this.code = code;
this.msg = msg;
this.data = data;
}
public Result(String code, String msg) {
this.code = code;
this.msg = msg;
}
public Result(ResultEnum resultEnum){
this.code = resultEnum.getCode();
this.msg = resultEnum.getMsg();
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
}
package com.zehong.gassdevicereport.result;
public enum ResultEnum {
/**
* 请求成功
*/
SUCCESS("0","接口请求成功!"),BUSSINESS_FAIL("1","业务异常!"),FAIL("2","接口请求失败!"),SYSTEM_EXCEPTION("3","系统异常!")
,NOT_IN_IPWHITE("4","当前IP不在白名单中,请联系管理员"),SECRETKRY_ERROR("5","secretKey不存在或秘钥不正确!")
,VALIDATA_ERROR("6","");
private String code;
private String msg;
ResultEnum(String code, String msg) {
this.code = code;
this.msg = msg;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
}
package com.zehong.gassdevicereport.service;
import com.zehong.gassdevicereport.entity.SysDictData;
import java.util.List;
/**
* 字典 业务层
*
* @author zehong
*/
public interface ISysDictDataService
{
/**
* 根据条件分页查询字典数据
*
* @param dictData 字典数据信息
* @return 字典数据集合信息
*/
List<SysDictData> selectDictDataList(SysDictData dictData);
/**
* 根据字典类型和字典键值查询字典数据信息
*
* @param dictType 字典类型
* @param dictValue 字典键值
* @return 字典标签
*/
String selectDictLabel(String dictType, String dictValue);
/**
* 根据字典数据ID查询信息
*
* @param dictCode 字典数据ID
* @return 字典数据
*/
SysDictData selectDictDataById(Long dictCode);
/**
* 批量删除字典数据信息
*
* @param dictCodes 需要删除的字典数据ID
* @return 结果
*/
void deleteDictDataByIds(Long[] dictCodes);
/**
* 新增保存字典数据信息
*
* @param dictData 字典数据信息
* @return 结果
*/
int insertDictData(SysDictData dictData);
/**
* 修改保存字典数据信息
*
* @param dictData 字典数据信息
* @return 结果
*/
int updateDictData(SysDictData dictData);
}
package com.zehong.gassdevicereport.service;
import com.zehong.gassdevicereport.entity.SysDictData;
import com.zehong.gassdevicereport.entity.SysDictType;
import java.util.List;
/**
* 字典 业务层
*
* @author zehong
*/
public interface ISysDictTypeService
{
/**
* 根据条件分页查询字典类型
*
* @param dictType 字典类型信息
* @return 字典类型集合信息
*/
List<SysDictType> selectDictTypeList(SysDictType dictType);
/**
* 根据所有字典类型
*
* @return 字典类型集合信息
*/
List<SysDictType> selectDictTypeAll();
/**
* 根据字典类型查询字典数据
*
* @param dictType 字典类型
* @return 字典数据集合信息
*/
List<SysDictData> selectDictDataByType(String dictType);
/**
* 根据字典类型ID查询信息
*
* @param dictId 字典类型ID
* @return 字典类型
*/
SysDictType selectDictTypeById(Long dictId);
/**
* 根据字典类型查询信息
*
* @param dictType 字典类型
* @return 字典类型
*/
SysDictType selectDictTypeByType(String dictType);
/**
* 批量删除字典信息
*
* @param dictIds 需要删除的字典ID
* @return 结果
*/
void deleteDictTypeByIds(Long[] dictIds);
}
package com.zehong.gassdevicereport.service;
import com.zehong.gassdevicereport.entity.TDeviceAlarm;
import java.util.List;
/**
* 报警信息Service接口
*
* @author zehong
* @date 2021-08-03
*/
public interface ITDeviceAlarmService
{
/**
* 查询报警信息
*
* @param alarmId 报警信息ID
* @return 报警信息
*/
TDeviceAlarm selectTDeviceAlarmById(Long alarmId);
/**
* 查询报警信息列表
*
* @param tDeviceAlarm 报警信息
* @return 报警信息集合
*/
List<TDeviceAlarm> selectTDeviceAlarmList(TDeviceAlarm tDeviceAlarm);
/**
* 新增报警信息
*
* @param tDeviceAlarm 报警信息
* @return 结果
*/
int insertTDeviceAlarm(TDeviceAlarm tDeviceAlarm);
/**
* 修改报警信息
*
* @param tDeviceAlarm 报警信息
* @return 结果
*/
int updateTDeviceAlarm(TDeviceAlarm tDeviceAlarm);
/**
* 批量删除报警信息
*
* @param alarmIds 需要删除的报警信息ID
* @return 结果
*/
int deleteTDeviceAlarmByIds(Long[] alarmIds);
/**
* 删除报警信息信息
*
* @param alarmId 报警信息ID
* @return 结果
*/
int deleteTDeviceAlarmById(Long alarmId);
/**
* 根据设备id查询报警信息
* @param deviceId
* @return
*/
TDeviceAlarm selectTDeviceAlarmByDeviceId(Long deviceId);
}
package com.zehong.gassdevicereport.service;
import com.zehong.gassdevicereport.entity.TDeviceReportData;
import java.util.List;
/**
* 设备监控Service接口
*
* @author zehong
* @date 2021-08-09
*/
public interface ITDeviceReportDataService {
/**
* 查询设备监控
*
* @param deviceReportDataId 设备监控ID
* @return 设备监控
*/
TDeviceReportData selectTDeviceReportDataById(Long deviceReportDataId);
/**
* 查询设备监控列表
*
* @param tDeviceReportData 设备监控
* @return 设备监控集合
*/
List<TDeviceReportData> selectTDeviceReportDataList(TDeviceReportData tDeviceReportData);
/**
* 新增设备监控
*
* @param tDeviceReportData 设备监控
* @return 结果
*/
int insertTDeviceReportData(TDeviceReportData tDeviceReportData);
/**
* 修改设备监控
*
* @param tDeviceReportData 设备监控
* @return 结果
*/
int updateTDeviceReportData(TDeviceReportData tDeviceReportData);
/**
* 批量删除设备监控
*
* @param deviceReportDataIds 需要删除的设备监控ID
* @return 结果
*/
int deleteTDeviceReportDataByIds(Long[] deviceReportDataIds);
/**
* 删除设备监控信息
*
* @param deviceReportDataId 设备监控ID
* @return 结果
*/
int deleteTDeviceReportDataById(Long deviceReportDataId);
}
package com.zehong.gassdevicereport.service;
import com.zehong.gassdevicereport.entity.TMonitorDevice;
import java.util.List;
/**
* 设备监控Service接口
*
* @author zehong
* @date 2021-08-03
*/
public interface ITMonitorDeviceService
{
/**
* 查询设备监控
*
* @param monitorId 设备监控ID
* @return 设备监控
*/
TMonitorDevice selectTMonitorDeviceById(Long monitorId);
/**
* 查询设备监控列表
*
* @param tMonitorDevice 设备监控
* @return 设备监控集合
*/
List<TMonitorDevice> selectTMonitorDeviceList(TMonitorDevice tMonitorDevice);
/**
* 新增设备监控
*
* @param tMonitorDevice 设备监控
* @return 结果
*/
int insertTMonitorDevice(TMonitorDevice tMonitorDevice);
/**
* 修改设备监控
*
* @param tMonitorDevice 设备监控
* @return 结果
*/
int updateTMonitorDevice(TMonitorDevice tMonitorDevice);
/**
* 批量删除设备监控
*
* @param monitorIds 需要删除的设备监控ID
* @return 结果
*/
int deleteTMonitorDeviceByIds(Long[] monitorIds);
/**
* 删除设备监控信息
*
* @param monitorId 设备监控ID
* @return 结果
*/
int deleteTMonitorDeviceById(Long monitorId);
List<TMonitorDevice> getDeviceInfosByIotNo(String iotNo);
}
package com.zehong.gassdevicereport.service.impl;
import com.zehong.gassdevicereport.dao.SysDictDataDao;
import com.zehong.gassdevicereport.entity.SysDictData;
import com.zehong.gassdevicereport.service.ISysDictDataService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
* 字典 业务层处理
*
* @author zehong
*/
@Service
public class SysDictDataServiceImpl implements ISysDictDataService
{
@Resource
private SysDictDataDao sysDictDataDao;
/**
* 根据条件分页查询字典数据
*
* @param dictData 字典数据信息
* @return 字典数据集合信息
*/
@Override
public List<SysDictData> selectDictDataList(SysDictData dictData)
{
return sysDictDataDao.selectDictDataList(dictData);
}
/**
* 根据字典类型和字典键值查询字典数据信息
*
* @param dictType 字典类型
* @param dictValue 字典键值
* @return 字典标签
*/
@Override
public String selectDictLabel(String dictType, String dictValue)
{
return sysDictDataDao.selectDictLabel(dictType, dictValue);
}
/**
* 根据字典数据ID查询信息
*
* @param dictCode 字典数据ID
* @return 字典数据
*/
@Override
public SysDictData selectDictDataById(Long dictCode)
{
return sysDictDataDao.selectDictDataById(dictCode);
}
/**
* 批量删除字典数据信息
*
* @param dictCodes 需要删除的字典数据ID
* @return 结果
*/
@Override
public void deleteDictDataByIds(Long[] dictCodes)
{
for (Long dictCode : dictCodes)
{
sysDictDataDao.deleteDictDataById(dictCode);
}
}
/**
* 新增保存字典数据信息
*
* @param data 字典数据信息
* @return 结果
*/
@Override
public int insertDictData(SysDictData data)
{
int row = sysDictDataDao.insertDictData(data);
return row;
}
/**
* 修改保存字典数据信息
*
* @param data 字典数据信息
* @return 结果
*/
@Override
public int updateDictData(SysDictData data)
{
int row = sysDictDataDao.updateDictData(data);
return row;
}
}
package com.zehong.gassdevicereport.service.impl;
import com.zehong.gassdevicereport.dao.SysDictDataDao;
import com.zehong.gassdevicereport.dao.SysDictTypeDao;
import com.zehong.gassdevicereport.entity.SysDictData;
import com.zehong.gassdevicereport.entity.SysDictType;
import com.zehong.gassdevicereport.service.ISysDictTypeService;
import com.zehong.gassdevicereport.utils.RedisUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
* 字典 业务层处理
*
* @author zehong
*/
@Service
public class SysDictTypeServiceImpl implements ISysDictTypeService
{
@Resource
private SysDictTypeDao sysDictTypeDao;
@Resource
private SysDictDataDao sysDictDataDao;
@Resource
private RedisUtil redisUtil;
/**
* 根据条件分页查询字典类型
*
* @param dictType 字典类型信息
* @return 字典类型集合信息
*/
@Override
public List<SysDictType> selectDictTypeList(SysDictType dictType)
{
return sysDictTypeDao.selectDictTypeList(dictType);
}
/**
* 根据所有字典类型
*
* @return 字典类型集合信息
*/
@Override
public List<SysDictType> selectDictTypeAll()
{
return sysDictTypeDao.selectDictTypeAll();
}
/**
* 根据字典类型查询字典数据
*
* @param dictType 字典类型
* @return 字典数据集合信息
*/
@Override
public List<SysDictData> selectDictDataByType(String dictType)
{
List<SysDictData> dictDatas = (List<SysDictData>) redisUtil.get("dictDatas" + dictType);
if(null != dictDatas && !dictDatas.isEmpty()){
return dictDatas;
}
dictDatas = sysDictDataDao.selectDictDataByType(dictType);
if(null != dictDatas && !dictDatas.isEmpty()){
redisUtil.set("dictDatas" + dictType,dictDatas,1000 * 3600 * 6);
}
return dictDatas;
}
/**
* 根据字典类型ID查询信息
*
* @param dictId 字典类型ID
* @return 字典类型
*/
@Override
public SysDictType selectDictTypeById(Long dictId)
{
return sysDictTypeDao.selectDictTypeById(dictId);
}
/**
* 根据字典类型查询信息
*
* @param dictType 字典类型
* @return 字典类型
*/
@Override
public SysDictType selectDictTypeByType(String dictType)
{
return sysDictTypeDao.selectDictTypeByType(dictType);
}
/**
* 批量删除字典类型信息
*
* @param dictIds 需要删除的字典ID
* @return 结果
*/
@Override
public void deleteDictTypeByIds(Long[] dictIds)
{
for (Long dictId : dictIds)
{
sysDictTypeDao.deleteDictTypeById(dictId);
}
}
}
package com.zehong.gassdevicereport.service.impl;
import com.zehong.gassdevicereport.dao.TDeviceAlarmDao;
import com.zehong.gassdevicereport.entity.TDeviceAlarm;
import com.zehong.gassdevicereport.service.ITDeviceAlarmService;
import com.zehong.gassdevicereport.utils.DateUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
/**
* 报警信息Service业务层处理
*
* @author zehong
* @date 2021-08-03
*/
@Service
public class TDeviceAlarmServiceImpl implements ITDeviceAlarmService
{
@Resource
private TDeviceAlarmDao tDeviceAlarmDao;
/**
* 查询报警信息
*
* @param alarmId 报警信息ID
* @return 报警信息
*/
@Override
public TDeviceAlarm selectTDeviceAlarmById(Long alarmId)
{
return tDeviceAlarmDao.selectTDeviceAlarmById(alarmId);
}
/**
* 查询报警信息列表
*
* @param tDeviceAlarm 报警信息
* @return 报警信息
*/
@Override
public List<TDeviceAlarm> selectTDeviceAlarmList(TDeviceAlarm tDeviceAlarm)
{
return tDeviceAlarmDao.selectTDeviceAlarmList(tDeviceAlarm);
}
/**
* 新增报警信息
*
* @param tDeviceAlarm 报警信息
* @return 结果
*/
@Override
public int insertTDeviceAlarm(TDeviceAlarm tDeviceAlarm)
{
tDeviceAlarm.setCreateTime(new Date());
return tDeviceAlarmDao.insertTDeviceAlarm(tDeviceAlarm);
}
/**
* 修改报警信息
*
* @param tDeviceAlarm 报警信息
* @return 结果
*/
@Override
public int updateTDeviceAlarm(TDeviceAlarm tDeviceAlarm)
{
tDeviceAlarm.setUpdateTime(DateUtils.getNowDate());
return tDeviceAlarmDao.updateTDeviceAlarm(tDeviceAlarm);
}
/**
* 批量删除报警信息
*
* @param alarmIds 需要删除的报警信息ID
* @return 结果
*/
@Override
public int deleteTDeviceAlarmByIds(Long[] alarmIds)
{
return tDeviceAlarmDao.deleteTDeviceAlarmByIds(alarmIds);
}
/**
* 删除报警信息信息
*
* @param alarmId 报警信息ID
* @return 结果
*/
@Override
public int deleteTDeviceAlarmById(Long alarmId)
{
return tDeviceAlarmDao.deleteTDeviceAlarmById(alarmId);
}
/**
* 根据设备id查询报警信息
* @param deviceId
* @return
*/
@Override
public TDeviceAlarm selectTDeviceAlarmByDeviceId(Long deviceId){
return tDeviceAlarmDao.selectTDeviceAlarmByDeviceId(deviceId);
}
}
package com.zehong.gassdevicereport.service.impl;
import com.zehong.gassdevicereport.dao.TDeviceReportDataDao;
import com.zehong.gassdevicereport.entity.TDeviceReportData;
import com.zehong.gassdevicereport.service.ITDeviceReportDataService;
import com.zehong.gassdevicereport.utils.DateUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
* 设备监控Service业务层处理
*
* @author zehong
* @date 2021-08-09
*/
@Service
public class TDeviceReportDataServiceImpl implements ITDeviceReportDataService {
@Resource
private TDeviceReportDataDao tDeviceReportDataDao;
/**
* 查询设备监控
*
* @param deviceReportDataId 设备监控ID
* @return 设备监控
*/
@Override
public TDeviceReportData selectTDeviceReportDataById(Long deviceReportDataId)
{
return tDeviceReportDataDao.selectTDeviceReportDataById(deviceReportDataId);
}
/**
* 查询设备监控列表
*
* @param tDeviceReportData 设备监控
* @return 设备监控
*/
@Override
public List<TDeviceReportData> selectTDeviceReportDataList(TDeviceReportData tDeviceReportData)
{
return tDeviceReportDataDao.selectTDeviceReportDataList(tDeviceReportData);
}
/**
* 新增设备监控
*
* @param tDeviceReportData 设备监控
* @return 结果
*/
@Override
public int insertTDeviceReportData(TDeviceReportData tDeviceReportData)
{
tDeviceReportData.setCreateTime(DateUtils.getNowDate());
return tDeviceReportDataDao.insertTDeviceReportData(tDeviceReportData);
}
/**
* 修改设备监控
*
* @param tDeviceReportData 设备监控
* @return 结果
*/
@Override
public int updateTDeviceReportData(TDeviceReportData tDeviceReportData)
{
tDeviceReportData.setUpdateTime(DateUtils.getNowDate());
return tDeviceReportDataDao.updateTDeviceReportData(tDeviceReportData);
}
/**
* 批量删除设备监控
*
* @param deviceReportDataIds 需要删除的设备监控ID
* @return 结果
*/
@Override
public int deleteTDeviceReportDataByIds(Long[] deviceReportDataIds)
{
return tDeviceReportDataDao.deleteTDeviceReportDataByIds(deviceReportDataIds);
}
/**
* 删除设备监控信息
*
* @param deviceReportDataId 设备监控ID
* @return 结果
*/
@Override
public int deleteTDeviceReportDataById(Long deviceReportDataId)
{
return tDeviceReportDataDao.deleteTDeviceReportDataById(deviceReportDataId);
}
}
package com.zehong.gassdevicereport.service.impl;
import com.zehong.gassdevicereport.dao.TMonitorDeviceDao;
import com.zehong.gassdevicereport.entity.TMonitorDevice;
import com.zehong.gassdevicereport.service.ITMonitorDeviceService;
import com.zehong.gassdevicereport.utils.DateUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
* 设备监控Service业务层处理
*
* @author zehong
* @date 2021-08-03
*/
@Service
public class TMonitorDeviceServiceImpl implements ITMonitorDeviceService
{
@Resource
private TMonitorDeviceDao tMonitorDeviceDao;
/**
* 查询设备监控
*
* @param monitorId 设备监控ID
* @return 设备监控
*/
@Override
public TMonitorDevice selectTMonitorDeviceById(Long monitorId)
{
return tMonitorDeviceDao.selectTMonitorDeviceById(monitorId);
}
/**
* 查询设备监控列表
*
* @param tMonitorDevice 设备监控
* @return 设备监控
*/
@Override
public List<TMonitorDevice> selectTMonitorDeviceList(TMonitorDevice tMonitorDevice)
{
return tMonitorDeviceDao.selectTMonitorDeviceList(tMonitorDevice);
}
/**
* 新增设备监控
*
* @param tMonitorDevice 设备监控
* @return 结果
*/
@Override
public int insertTMonitorDevice(TMonitorDevice tMonitorDevice)
{
tMonitorDevice.setCreateTime(DateUtils.getNowDate());
return tMonitorDeviceDao.insertTMonitorDevice(tMonitorDevice);
}
/**
* 修改设备监控
*
* @param tMonitorDevice 设备监控
* @return 结果
*/
@Override
public int updateTMonitorDevice(TMonitorDevice tMonitorDevice)
{
tMonitorDevice.setUpdateTime(DateUtils.getNowDate());
return tMonitorDeviceDao.updateTMonitorDevice(tMonitorDevice);
}
/**
* 批量删除设备监控
*
* @param monitorIds 需要删除的设备监控ID
* @return 结果
*/
@Override
public int deleteTMonitorDeviceByIds(Long[] monitorIds)
{
return tMonitorDeviceDao.deleteTMonitorDeviceByIds(monitorIds);
}
/**
* 删除设备监控信息
*
* @param monitorId 设备监控ID
* @return 结果
*/
@Override
public int deleteTMonitorDeviceById(Long monitorId)
{
return tMonitorDeviceDao.deleteTMonitorDeviceById(monitorId);
}
@Override
public List<TMonitorDevice> getDeviceInfosByIotNo(String iotNo){
return tMonitorDeviceDao.getDeviceInfosByIotNo(iotNo);
}
}
package com.zehong.gassdevicereport.task;
import com.zehong.gassdevicereport.dao.SysScheduledCronRepository;
import com.zehong.gassdevicereport.entity.SysScheduledCron;
import com.zehong.gassdevicereport.enums.SysScheduledStatusEnum;
import com.zehong.gassdevicereport.utils.SpringUtil;
/**
* 实现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.gassdevicereport.task.impl;
import com.zehong.gassdevicereport.constant.Constant;
import com.zehong.gassdevicereport.entity.ReciveReportData;
import com.zehong.gassdevicereport.entity.TDeviceAlarm;
import com.zehong.gassdevicereport.entity.TMonitorDevice;
import com.zehong.gassdevicereport.service.ISysDictTypeService;
import com.zehong.gassdevicereport.service.ITDeviceAlarmService;
import com.zehong.gassdevicereport.service.ITMonitorDeviceService;
import com.zehong.gassdevicereport.task.ScheduledOfTask;
import com.zehong.gassdevicereport.utils.DateUtils;
import com.zehong.gassdevicereport.utils.HttpUtil;
import com.zehong.gassdevicereport.utils.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
/**
* 处理接收数据并发送报警信息
*/
@Component
@Slf4j
public class DealWithAndSendRecevieDataTask implements ScheduledOfTask {
@Autowired
private RedisUtil redisUtil;
@Autowired
private ITMonitorDeviceService itMonitorDeviceService;
@Autowired
private ITDeviceAlarmService itDeviceAlarmService;
@Value("${webSocektUrl}")
private String webSocektUrl;
@Autowired
private ISysDictTypeService iSysDictTypeService;
@Override
public void execute() {
//获取设备监控信息
List<TMonitorDevice> monitorDevices = itMonitorDeviceService.selectTMonitorDeviceList(new TMonitorDevice());
for(TMonitorDevice monitorDevice : monitorDevices){
ReciveReportData deviceInfo = (ReciveReportData) redisUtil.get(Constant.DEVICE_REDIS_KEY+monitorDevice.getIotNo());
if(null == deviceInfo){
return;
}
//查询设备在报警表中信息
insertAlarmInfo(monitorDevice.getDeviceId(),monitorDevice.getDeviceThreshold(), deviceInfo);
//获取关联设备阈值
if(StringUtils.isNotBlank(monitorDevice.getRelationIotNo())){
ReciveReportData relationDeviceInfo = (ReciveReportData) redisUtil.get(Constant.DEVICE_REDIS_KEY+monitorDevice.getRelationIotNo());
if(null == relationDeviceInfo){
return;
}
//关联设备
insertAlarmInfo(monitorDevice.getRelationDeviceId(),monitorDevice.getRelationDeviceThreshold(), relationDeviceInfo);
//关联管道
ReciveReportData pipe = new ReciveReportData();
pipe.setPotency(deviceInfo.getPotency().subtract(relationDeviceInfo.getPotency()));
pipe.setDeviceType("0");
pipe.setDeviceStatus("1");
pipe.setDeviceDescribe(iSysDictTypeService.selectDictDataByType("t_alarm_pipe_describe").get(0).getDictLabel());
insertAlarmInfo(monitorDevice.getRelationPipeId(),monitorDevice.getRelationPipeThreshold(),pipe);
}
}
}
/**
*插入报警信息
* @param deviceId 设备编号
* @param deviceThreshold 设备浓度
* @param deviceInfo 设备上报信息
*/
private void insertAlarmInfo(Long deviceId,BigDecimal deviceThreshold, ReciveReportData deviceInfo) {
TDeviceAlarm alarm = itDeviceAlarmService.selectTDeviceAlarmByDeviceId(deviceId);
//比较设备上报信息及阈值信息
if(deviceThreshold.compareTo(deviceInfo.getPotency()) == -1){
//判断报警表中是否有该设备报警信息:无新增报警信息、有更新报警信息
if(null != alarm){
//TODO 添加更新字段
alarm.setCreateTime(DateUtils.getNowDate());
itDeviceAlarmService.updateTDeviceAlarm(alarm);
}else{
TDeviceAlarm alarmInsert = new TDeviceAlarm();
alarmInsert.setDeviceId(deviceId);
alarmInsert.setAlarmType(deviceInfo.getDeviceStatus());
alarmInsert.setDeviceType(deviceInfo.getDeviceType());
alarmInsert.setStartTime(new Date());
alarmInsert.setAlarmValue(deviceInfo.getDeviceDescribe());
itDeviceAlarmService.insertTDeviceAlarm(alarmInsert);
pushWedSocket(alarmInsert.getAlarmId());
}
}else {
if(null != alarm){
if(null == alarm.getEndTime()){
alarm.setEndTime(DateUtils.getNowDate());
itDeviceAlarmService.updateTDeviceAlarm(alarm);
pushWedSocket(alarm.getAlarmId());
}
}
}
}
/**
* 推送报警信息
* @param alarmId 报警id
*/
private void pushWedSocket(Long alarmId){
//推送信息至websocket
StringBuilder url = new StringBuilder(webSocektUrl)
.append("?")
.append("alarmId=")
.append(alarmId);
try {
HttpUtil.doGet(url.toString());
} catch (IOException e) {
log.error("websocket推送失败:"+e);
}
}
}
package com.zehong.gassdevicereport.utils;
import org.apache.commons.lang3.time.DateFormatUtils;
import java.lang.management.ManagementFactory;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* 时间工具类
*
* @author zehong
*/
public class DateUtils extends org.apache.commons.lang3.time.DateUtils
{
public static String YYYY = "yyyy";
public static String YYYY_MM = "yyyy-MM";
public static String YYYY_MM_DD = "yyyy-MM-dd";
public static String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
private static String[] parsePatterns = {
"yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM",
"yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM",
"yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM"};
/**
* 获取当前Date型日期
*
* @return Date() 当前日期
*/
public static Date getNowDate()
{
return new Date();
}
/**
* 获取当前日期, 默认格式为yyyy-MM-dd
*
* @return String
*/
public static String getDate()
{
return dateTimeNow(YYYY_MM_DD);
}
public static final String getTime()
{
return dateTimeNow(YYYY_MM_DD_HH_MM_SS);
}
public static final String dateTimeNow()
{
return dateTimeNow(YYYYMMDDHHMMSS);
}
public static final String dateTimeNow(final String format)
{
return parseDateToStr(format, new Date());
}
public static final String dateTime(final Date date)
{
return parseDateToStr(YYYY_MM_DD, date);
}
public static final String parseDateToStr(final String format, final Date date)
{
return new SimpleDateFormat(format).format(date);
}
public static final Date dateTime(final String format, final String ts)
{
try
{
return new SimpleDateFormat(format).parse(ts);
}
catch (ParseException e)
{
throw new RuntimeException(e);
}
}
/**
* 日期路径 即年/月/日 如2018/08/08
*/
public static final String datePath()
{
Date now = new Date();
return DateFormatUtils.format(now, "yyyy/MM/dd");
}
/**
* 日期路径 即年/月/日 如20180808
*/
public static final String dateTime()
{
Date now = new Date();
return DateFormatUtils.format(now, "yyyyMMdd");
}
/**
* 日期型字符串转化为日期 格式
*/
public static Date parseDate(Object str)
{
if (str == null)
{
return null;
}
try
{
return parseDate(str.toString(), parsePatterns);
}
catch (ParseException e)
{
return null;
}
}
/**
* 获取服务器启动时间
*/
public static Date getServerStartDate()
{
long time = ManagementFactory.getRuntimeMXBean().getStartTime();
return new Date(time);
}
/**
* 计算两个时间差
*/
public static String getDatePoor(Date endDate, Date nowDate)
{
long nd = 1000 * 24 * 60 * 60;
long nh = 1000 * 60 * 60;
long nm = 1000 * 60;
// long ns = 1000;
// 获得两个时间的毫秒时间差异
long diff = endDate.getTime() - nowDate.getTime();
// 计算差多少天
long day = diff / nd;
// 计算差多少小时
long hour = diff % nd / nh;
// 计算差多少分钟
long min = diff % nd % nh / nm;
// 计算差多少秒//输出结果
// long sec = diff % nd % nh % nm / ns;
return day + "天" + hour + "小时" + min + "分钟";
}
}
package com.zehong.gassdevicereport.utils;
import com.zehong.gassdevicereport.result.Result;
import com.zehong.gassdevicereport.result.ResultEnum;
import org.apache.http.*;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
public class HttpUtil {
/**
* get请求
* @return
*/
public static Result doGet(String url) throws IOException {
HttpClient client = new DefaultHttpClient();
//发送get请求
HttpGet request = new HttpGet(url);
HttpResponse response = client.execute(request);
/**请求发送成功,并得到响应**/
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
/**读取服务器返回过来的json字符串数据**/
String strResult = EntityUtils.toString(response.getEntity());
return new Result(ResultEnum.SUCCESS.getCode(),strResult);
}
return new Result(ResultEnum.FAIL.getCode(),EntityUtils.toString(response.getEntity()));
}
/**
* post请求(用于key-value格式的参数)
* @param url
* @param params
* @return
*/
public static Result doPost(String url, Map params) throws IOException, URISyntaxException {
// 定义HttpClient
HttpClient client = new DefaultHttpClient();
// 实例化HTTP方法
HttpPost request = new HttpPost();
request.setURI(new URI(url));
//设置参数
List<NameValuePair> nvps = new ArrayList<>();
for (Iterator iter = params.keySet().iterator(); iter.hasNext();) {
String name = (String) iter.next();
String value = String.valueOf(params.get(name));
nvps.add(new BasicNameValuePair(name, value));
}
request.setEntity(new UrlEncodedFormEntity(nvps,HTTP.UTF_8));
HttpResponse response = client.execute(request);
int code = response.getStatusLine().getStatusCode();
BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity()
.getContent(),"utf-8"));
StringBuffer sb = new StringBuffer("");
String line = "";
String NL = System.getProperty("line.separator");
while ((line = in.readLine()) != null) {
sb.append(line + NL);
}
in.close();
//请求成功
if(code == 200){
return new Result(ResultEnum.SUCCESS.getCode(),sb.toString());
}
return new Result(ResultEnum.FAIL.getCode(),sb.toString());
}
/**
* post请求(用于请求json格式的参数)
* @param url
* @param params
* @return
*/
public static Result doPost(String url, String params) throws Exception {
CloseableHttpClient httpclient = HttpClients.createDefault();
// 创建httpPost
HttpPost httpPost = new HttpPost(url);
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-Type", "application/json");
String charSet = "UTF-8";
StringEntity entity = new StringEntity(params, charSet);
httpPost.setEntity(entity);
CloseableHttpResponse response = null;
try {
response = httpclient.execute(httpPost);
StatusLine status = response.getStatusLine();
int state = status.getStatusCode();
HttpEntity responseEntity = response.getEntity();
String jsonString = EntityUtils.toString(responseEntity);
if (state == HttpStatus.SC_OK) {
return new Result(ResultEnum.SUCCESS.getCode(),jsonString);
}
return new Result(ResultEnum.FAIL.getCode(),jsonString);
}finally {
if (response != null) {
response.close();
}
httpclient.close();
}
}
}
This diff is collapsed.
package com.zehong.gassdevicereport.utils;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import java.util.Map;
/**
* Spring ApplicationContext 工具类
*/
@SuppressWarnings("unchecked")
@Component
public class SpringUtil implements ApplicationContextAware {
private static ApplicationContext applicationContext;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
SpringUtil.applicationContext = applicationContext;
}
public static <T> T getBean(String beanName) {
if(applicationContext.containsBean(beanName)){
return (T) applicationContext.getBean(beanName);
}else{
return null;
}
}
public static <T> T getBean(Class beanClass) {
return (T) applicationContext.getBean(beanClass);
}
public static <T> Map<String, T> getBeansOfType(Class<T> baseType){
return applicationContext.getBeansOfType(baseType);
}
}
# 开发环境配置
server:
# 服务器的HTTP端口,默认为8080
port: 8904
servlet:
# 应用的访问路径
context-path: /gassDeviceReport
tomcat:
# tomcat的URI编码
uri-encoding: UTF-8
# tomcat最大线程数,默认为200
max-threads: 800
# Tomcat启动初始化的线程数,默认值25
min-spare-threads: 30
# redis 配置
redis:
# 地址
host: localhost
# 端口,默认为6379
port: 6379
# 数据库索引
database: 6
# 密码
password:
# 连接超时时间
timeout: 10s
lettuce:
pool:
# 连接池中的最小空闲连接
min-idle: 0
# 连接池中的最大空闲连接
max-idle: 8
# 连接池的最大数据库连接数
max-active: 8
# #连接池最大阻塞等待时间(使用负值表示没有限制)
max-wait: -1ms
#mysql
spring:
datasource:
username: root
password: root@123
url: jdbc:mysql://36.148.23.59:3306/gas_db?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
driver-class-name: com.mysql.jdbc.Driver
#mybatis的相关配置
mybatis:
#mapper配置文件
mapper-locations: classpath:mapper/*.xml
type-aliases-package: com.zehong.gassdevicereport.entity
#开启驼峰命名
configuration:
map-underscore-to-camel-case: true
# 日志配置
logging:
level:
com.zehong: debug
org.springframework: warn
#webSocektUrl
webSocektUrl: http://localhost:8903/gassafety/websocket/send
netty:
ports: 7397,7398
<?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.gassdevicereport.dao.SysDictDataDao">
<resultMap type="SysDictData" id="SysDictDataResult">
<id property="dictCode" column="dict_code" />
<result property="dictSort" column="dict_sort" />
<result property="dictLabel" column="dict_label" />
<result property="dictValue" column="dict_value" />
<result property="dictType" column="dict_type" />
<result property="cssClass" column="css_class" />
<result property="listClass" column="list_class" />
<result property="isDefault" column="is_default" />
<result property="status" column="status" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
</resultMap>
<sql id="selectDictDataVo">
select dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, status, create_by, create_time, remark
from sys_dict_data
</sql>
<select id="selectDictDataList" parameterType="SysDictData" resultMap="SysDictDataResult">
<include refid="selectDictDataVo"/>
<where>
<if test="dictType != null and dictType != ''">
AND dict_type = #{dictType}
</if>
<if test="dictLabel != null and dictLabel != ''">
AND dict_label like concat('%', #{dictLabel}, '%')
</if>
<if test="status != null and status != ''">
AND status = #{status}
</if>
</where>
order by dict_sort asc
</select>
<select id="selectDictDataByType" parameterType="SysDictData" resultMap="SysDictDataResult">
<include refid="selectDictDataVo"/>
where status = '0' and dict_type = #{dictType} order by dict_sort asc
</select>
<select id="selectDictLabel" resultType="String">
select dict_label from sys_dict_data
where dict_type = #{dictType} and dict_value = #{dictValue}
</select>
<select id="selectDictDataById" parameterType="Long" resultMap="SysDictDataResult">
<include refid="selectDictDataVo"/>
where dict_code = #{dictCode}
</select>
<select id="countDictDataByType" resultType="Integer">
select count(1) from sys_dict_data where dict_type=#{dictType}
</select>
<delete id="deleteDictDataById" parameterType="Long">
delete from sys_dict_data where dict_code = #{dictCode}
</delete>
<delete id="deleteDictDataByIds" parameterType="Long">
delete from sys_dict_data where dict_code in
<foreach collection="array" item="dictCode" open="(" separator="," close=")">
#{dictCode}
</foreach>
</delete>
<update id="updateDictData" parameterType="SysDictData">
update sys_dict_data
<set>
<if test="dictSort != null">dict_sort = #{dictSort},</if>
<if test="dictLabel != null and dictLabel != ''">dict_label = #{dictLabel},</if>
<if test="dictValue != null and dictValue != ''">dict_value = #{dictValue},</if>
<if test="dictType != null and dictType != ''">dict_type = #{dictType},</if>
<if test="cssClass != null">css_class = #{cssClass},</if>
<if test="listClass != null">list_class = #{listClass},</if>
<if test="isDefault != null and isDefault != ''">is_default = #{isDefault},</if>
<if test="status != null">status = #{status},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
update_time = sysdate()
</set>
where dict_code = #{dictCode}
</update>
<update id="updateDictDataType" parameterType="String">
update sys_dict_data set dict_type = #{newDictType} where dict_type = #{oldDictType}
</update>
<insert id="insertDictData" parameterType="SysDictData">
insert into sys_dict_data(
<if test="dictSort != null">dict_sort,</if>
<if test="dictLabel != null and dictLabel != ''">dict_label,</if>
<if test="dictValue != null and dictValue != ''">dict_value,</if>
<if test="dictType != null and dictType != ''">dict_type,</if>
<if test="cssClass != null and cssClass != ''">css_class,</if>
<if test="listClass != null and listClass != ''">list_class,</if>
<if test="isDefault != null and isDefault != ''">is_default,</if>
<if test="status != null">status,</if>
<if test="remark != null and remark != ''">remark,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
create_time
)values(
<if test="dictSort != null">#{dictSort},</if>
<if test="dictLabel != null and dictLabel != ''">#{dictLabel},</if>
<if test="dictValue != null and dictValue != ''">#{dictValue},</if>
<if test="dictType != null and dictType != ''">#{dictType},</if>
<if test="cssClass != null and cssClass != ''">#{cssClass},</if>
<if test="listClass != null and listClass != ''">#{listClass},</if>
<if test="isDefault != null and isDefault != ''">#{isDefault},</if>
<if test="status != null">#{status},</if>
<if test="remark != null and remark != ''">#{remark},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
sysdate()
)
</insert>
</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.gassdevicereport.dao.SysDictTypeDao">
<resultMap type="SysDictType" id="SysDictTypeResult">
<id property="dictId" column="dict_id" />
<result property="dictName" column="dict_name" />
<result property="dictType" column="dict_type" />
<result property="status" column="status" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
</resultMap>
<sql id="selectDictTypeVo">
select dict_id, dict_name, dict_type, status, create_by, create_time, remark
from sys_dict_type
</sql>
<select id="selectDictTypeList" parameterType="SysDictType" resultMap="SysDictTypeResult">
<include refid="selectDictTypeVo"/>
<where>
<if test="dictName != null and dictName != ''">
AND dict_name like concat('%', #{dictName}, '%')
</if>
<if test="status != null and status != ''">
AND status = #{status}
</if>
<if test="dictType != null and dictType != ''">
AND dict_type like concat('%', #{dictType}, '%')
</if>
<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
and date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
</if>
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
and date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
</if>
</where>
</select>
<select id="selectDictTypeAll" resultMap="SysDictTypeResult">
<include refid="selectDictTypeVo"/>
</select>
<select id="selectDictTypeById" parameterType="Long" resultMap="SysDictTypeResult">
<include refid="selectDictTypeVo"/>
where dict_id = #{dictId}
</select>
<select id="selectDictTypeByType" parameterType="String" resultMap="SysDictTypeResult">
<include refid="selectDictTypeVo"/>
where dict_type = #{dictType}
</select>
<select id="checkDictTypeUnique" parameterType="String" resultMap="SysDictTypeResult">
<include refid="selectDictTypeVo"/>
where dict_type = #{dictType} limit 1
</select>
<delete id="deleteDictTypeById" parameterType="Long">
delete from sys_dict_type where dict_id = #{dictId}
</delete>
<delete id="deleteDictTypeByIds" parameterType="Long">
delete from sys_dict_type where dict_id in
<foreach collection="array" item="dictId" open="(" separator="," close=")">
#{dictId}
</foreach>
</delete>
<update id="updateDictType" parameterType="SysDictType">
update sys_dict_type
<set>
<if test="dictName != null and dictName != ''">dict_name = #{dictName},</if>
<if test="dictType != null and dictType != ''">dict_type = #{dictType},</if>
<if test="status != null">status = #{status},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
update_time = sysdate()
</set>
where dict_id = #{dictId}
</update>
<insert id="insertDictType" parameterType="SysDictType">
insert into sys_dict_type(
<if test="dictName != null and dictName != ''">dict_name,</if>
<if test="dictType != null and dictType != ''">dict_type,</if>
<if test="status != null">status,</if>
<if test="remark != null and remark != ''">remark,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
create_time
)values(
<if test="dictName != null and dictName != ''">#{dictName},</if>
<if test="dictType != null and dictType != ''">#{dictType},</if>
<if test="status != null">#{status},</if>
<if test="remark != null and remark != ''">#{remark},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
sysdate()
)
</insert>
</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.gassdevicereport.dao.SysScheduledCronRepository">
<select id="findAll" resultType="com.zehong.gassdevicereport.entity.SysScheduledCron">
select * from t_scheduled_cron;
</select>
<select id="findByCronKey" parameterType="java.lang.String" resultType="com.zehong.gassdevicereport.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.gassdevicereport.dao.TDeviceAlarmDao">
<resultMap type="TDeviceAlarm" id="TDeviceAlarmResult">
<result property="alarmId" column="alarm_id" />
<result property="deviceId" column="device_id" />
<result property="deviceType" column="device_Type" />
<result property="orderId" column="order_id" />
<result property="alarmType" column="alarm_type" />
<result property="alarmValue" column="alarm_value" />
<result property="startTime" column="start_time" />
<result property="endTime" column="end_time" />
<result property="dealStatus" column="deal_status" />
<result property="updateTime" column="update_time" />
<result property="createTime" column="create_time" />
</resultMap>
<sql id="selectTDeviceAlarmVo">
select alarm_id, device_id, device_Type, order_id, alarm_type, alarm_value, start_time, end_time, deal_status, update_time, create_time from t_device_alarm
</sql>
<select id="selectTDeviceAlarmList" parameterType="TDeviceAlarm" resultMap="TDeviceAlarmResult">
<include refid="selectTDeviceAlarmVo"/>
<where>
<if test="deviceId != null and deviceId != ''"> and device_id = #{deviceId}</if>
<if test="deviceType != null and deviceType != ''"> and device_Type = #{deviceType}</if>
<if test="orderId != null and orderId != ''"> and order_id = #{orderId}</if>
<if test="alarmType != null and alarmType != ''"> and alarm_type = #{alarmType}</if>
<if test="alarmValue != null and alarmValue != ''"> and alarm_value = #{alarmValue}</if>
<if test="startTime != null "> and start_time = #{startTime}</if>
<if test="endTime != null "> and end_time = #{endTime}</if>
<if test="dealStatus != null and dealStatus != ''"> and deal_status = #{dealStatus}</if>
</where>
</select>
<select id="selectTDeviceAlarmById" parameterType="Long" resultMap="TDeviceAlarmResult">
<include refid="selectTDeviceAlarmVo"/>
where alarm_id = #{alarmId}
</select>
<insert id="insertTDeviceAlarm" parameterType="TDeviceAlarm" useGeneratedKeys="true" keyProperty="alarmId">
insert into t_device_alarm
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="deviceId != null">device_id,</if>
<if test="deviceType != null">device_Type,</if>
<if test="orderId != null">order_id,</if>
<if test="alarmType != null">alarm_type,</if>
<if test="alarmValue != null">alarm_value,</if>
<if test="startTime != null">start_time,</if>
<if test="endTime != null">end_time,</if>
<if test="dealStatus != null">deal_status,</if>
<if test="updateTime != null">update_time,</if>
<if test="createTime != null">create_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="deviceId != null">#{deviceId},</if>
<if test="deviceType != null">#{deviceType},</if>
<if test="orderId != null">#{orderId},</if>
<if test="alarmType != null">#{alarmType},</if>
<if test="alarmValue != null">#{alarmValue},</if>
<if test="startTime != null">#{startTime},</if>
<if test="endTime != null">#{endTime},</if>
<if test="dealStatus != null">#{dealStatus},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="createTime != null">#{createTime},</if>
</trim>
</insert>
<update id="updateTDeviceAlarm" parameterType="TDeviceAlarm">
update t_device_alarm
<trim prefix="SET" suffixOverrides=",">
<if test="deviceId != null">device_id = #{deviceId},</if>
<if test="deviceType != null">device_Type = #{deviceType},</if>
<if test="orderId != null">order_id = #{orderId},</if>
<if test="alarmType != null">alarm_type = #{alarmType},</if>
<if test="alarmValue != null">alarm_value = #{alarmValue},</if>
<if test="startTime != null">start_time = #{startTime},</if>
<if test="endTime != null">end_time = #{endTime},</if>
<if test="dealStatus != null">deal_status = #{dealStatus},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="createTime != null">create_time = #{createTime},</if>
</trim>
where alarm_id = #{alarmId}
</update>
<delete id="deleteTDeviceAlarmById" parameterType="Long">
delete from t_device_alarm where alarm_id = #{alarmId}
</delete>
<delete id="deleteTDeviceAlarmByIds" parameterType="String">
delete from t_device_alarm where alarm_id in
<foreach item="alarmId" collection="array" open="(" separator="," close=")">
#{alarmId}
</foreach>
</delete>
<select id="selectTDeviceAlarmByDeviceId" parameterType="Long" resultMap="TDeviceAlarmResult">
<include refid="selectTDeviceAlarmVo"/>
where device_id = #{deviceId} AND end_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.gassdevicereport.dao.TDeviceReportDataDao">
<resultMap type="TDeviceReportData" id="TDeviceReportDataResult">
<result property="deviceReportDataId" column="device_report_data_id" />
<result property="deviceNum" column="device_num" />
<result property="standardConditionAccumulation" column="standard_condition_accumulation" />
<result property="workingConditionAccumulation" column="working_condition_accumulation" />
<result property="residualQuantity" column="residual_quantity" />
<result property="standardConditionFlow" column="standard_condition_flow" />
<result property="workingConditionFlow" column="working_condition_flow" />
<result property="temperature" column="temperature" />
<result property="pressure" column="pressure" />
<result property="reportTime" column="report_time" />
<result property="communicationStatus" column="communication_status" />
<result property="deviceStatus" column="device_status" />
<result property="createTime" column="create_time" />
<result property="updateTime" column="update_time" />
</resultMap>
<sql id="selectTDeviceReportDataVo">
select device_report_data_id, device_num, standard_condition_accumulation, working_condition_accumulation, residual_quantity, standard_condition_flow, working_condition_flow, temperature, pressure, report_time, communication_status, device_status, create_time, update_time from t_device_report_data
</sql>
<select id="selectTDeviceReportDataList" parameterType="TDeviceReportData" resultMap="TDeviceReportDataResult">
<include refid="selectTDeviceReportDataVo"/>
<where>
<if test="deviceNum != null "> and device_num = #{deviceNum}</if>
<if test="standardConditionAccumulation != null "> and standard_condition_accumulation = #{standardConditionAccumulation}</if>
<if test="workingConditionAccumulation != null "> and working_condition_accumulation = #{workingConditionAccumulation}</if>
<if test="residualQuantity != null "> and residual_quantity = #{residualQuantity}</if>
<if test="standardConditionFlow != null "> and standard_condition_flow = #{standardConditionFlow}</if>
<if test="workingConditionFlow != null "> and working_condition_flow = #{workingConditionFlow}</if>
<if test="temperature != null "> and temperature = #{temperature}</if>
<if test="pressure != null "> and pressure = #{pressure}</if>
<if test="reportTime != null "> and report_time = #{reportTime}</if>
<if test="communicationStatus != null and communicationStatus != ''"> and communication_status = #{communicationStatus}</if>
<if test="deviceStatus != null and deviceStatus != ''"> and device_status = #{deviceStatus}</if>
</where>
</select>
<select id="selectTDeviceReportDataById" parameterType="Long" resultMap="TDeviceReportDataResult">
<include refid="selectTDeviceReportDataVo"/>
where device_report_data_id = #{deviceReportDataId}
</select>
<insert id="insertTDeviceReportData" parameterType="TDeviceReportData" useGeneratedKeys="true" keyProperty="deviceReportDataId">
insert into t_device_report_data
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="deviceNum != null">device_num,</if>
<if test="standardConditionAccumulation != null">standard_condition_accumulation,</if>
<if test="workingConditionAccumulation != null">working_condition_accumulation,</if>
<if test="residualQuantity != null">residual_quantity,</if>
<if test="standardConditionFlow != null">standard_condition_flow,</if>
<if test="workingConditionFlow != null">working_condition_flow,</if>
<if test="temperature != null">temperature,</if>
<if test="pressure != null">pressure,</if>
<if test="reportTime != null">report_time,</if>
<if test="communicationStatus != null">communication_status,</if>
<if test="deviceStatus != null">device_status,</if>
<if test="createTime != null">create_time,</if>
<if test="updateTime != null">update_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="deviceNum != null">#{deviceNum},</if>
<if test="standardConditionAccumulation != null">#{standardConditionAccumulation},</if>
<if test="workingConditionAccumulation != null">#{workingConditionAccumulation},</if>
<if test="residualQuantity != null">#{residualQuantity},</if>
<if test="standardConditionFlow != null">#{standardConditionFlow},</if>
<if test="workingConditionFlow != null">#{workingConditionFlow},</if>
<if test="temperature != null">#{temperature},</if>
<if test="pressure != null">#{pressure},</if>
<if test="reportTime != null">#{reportTime},</if>
<if test="communicationStatus != null">#{communicationStatus},</if>
<if test="deviceStatus != null">#{deviceStatus},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateTime != null">#{updateTime},</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="standardConditionAccumulation != null">standard_condition_accumulation = #{standardConditionAccumulation},</if>
<if test="workingConditionAccumulation != null">working_condition_accumulation = #{workingConditionAccumulation},</if>
<if test="residualQuantity != null">residual_quantity = #{residualQuantity},</if>
<if test="standardConditionFlow != null">standard_condition_flow = #{standardConditionFlow},</if>
<if test="workingConditionFlow != null">working_condition_flow = #{workingConditionFlow},</if>
<if test="temperature != null">temperature = #{temperature},</if>
<if test="pressure != null">pressure = #{pressure},</if>
<if test="reportTime != null">report_time = #{reportTime},</if>
<if test="communicationStatus != null">communication_status = #{communicationStatus},</if>
<if test="deviceStatus != null">device_status = #{deviceStatus},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
</trim>
where device_report_data_id = #{deviceReportDataId}
</update>
<delete id="deleteTDeviceReportDataById" parameterType="Long">
delete from t_device_report_data where device_report_data_id = #{deviceReportDataId}
</delete>
<delete id="deleteTDeviceReportDataByIds" parameterType="String">
delete from t_device_report_data where device_report_data_id in
<foreach item="deviceReportDataId" collection="array" open="(" separator="," close=")">
#{deviceReportDataId}
</foreach>
</delete>
</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.gassdevicereport.dao.TMonitorDeviceDao">
<resultMap type="TMonitorDevice" id="TMonitorDeviceResult">
<result property="monitorId" column="monitor_id" />
<result property="deviceId" column="device_id" />
<result property="deviceThreshold" column="device_threshold" />
<result property="relationPipeId" column="relation_pipe_id" />
<result property="relationPipeThreshold" column="relation_pipe_threshold" />
<result property="relationDeviceId" column="relation_device_id" />
<result property="relationDeviceThreshold" column="relation_device_threshold" />
<result property="createTime" column="create_time" />
<result property="updateTime" column="update_time" />
</resultMap>
<sql id="selectTMonitorDeviceVo">
select monitor_id, device_id, device_threshold, relation_pipe_id, relation_pipe_threshold, relation_device_id, relation_device_threshold, create_time, update_time from t_monitor_device
</sql>
<select id="selectTMonitorDeviceList" parameterType="TMonitorDevice" resultMap="TMonitorDeviceResult">
SELECT
t.monitor_id,
t.device_id,
(
SELECT device.iot_no FROM t_device_info device WHERE device.device_id = t.device_id) AS IotNo,
t.device_threshold,
t.relation_pipe_id,
t.relation_pipe_threshold,
t.relation_device_id,
(SELECT device.iot_no FROM t_device_info device WHERE device.device_id = t.relation_device_id) AS relationIotNo,
t.relation_device_threshold,
t.create_time,
t.update_time
FROM
t_monitor_device t
<where>
<if test="deviceId != null "> and t.device_id = #{deviceId}</if>
<if test="deviceThreshold != null "> and t.device_threshold = #{deviceThreshold}</if>
<if test="relationPipeId != null "> and t.relation_pipe_id = #{relationPipeId}</if>
<if test="relationPipeThreshold != null "> and t.relation_pipe_threshold = #{relationPipeThreshold}</if>
<if test="relationDeviceId != null "> and t.relation_device_id = #{relationDeviceId}</if>
<if test="relationDeviceThreshold != null "> and t.relation_device_threshold = #{relationDeviceThreshold}</if>
</where>
</select>
<select id="selectTMonitorDeviceById" parameterType="Long" resultMap="TMonitorDeviceResult">
<include refid="selectTMonitorDeviceVo"/>
where monitor_id = #{monitorId}
</select>
<insert id="insertTMonitorDevice" parameterType="TMonitorDevice" useGeneratedKeys="true" keyProperty="monitorId">
insert into t_monitor_device
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="deviceId != null">device_id,</if>
<if test="deviceThreshold != null">device_threshold,</if>
<if test="relationPipeId != null">relation_pipe_id,</if>
<if test="relationPipeThreshold != null">relation_pipe_threshold,</if>
<if test="relationDeviceId != null">relation_device_id,</if>
<if test="relationDeviceThreshold != null">relation_device_threshold,</if>
<if test="createTime != null">create_time,</if>
<if test="updateTime != null">update_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="deviceId != null">#{deviceId},</if>
<if test="deviceThreshold != null">#{deviceThreshold},</if>
<if test="relationPipeId != null">#{relationPipeId},</if>
<if test="relationPipeThreshold != null">#{relationPipeThreshold},</if>
<if test="relationDeviceId != null">#{relationDeviceId},</if>
<if test="relationDeviceThreshold != null">#{relationDeviceThreshold},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateTime != null">#{updateTime},</if>
</trim>
</insert>
<update id="updateTMonitorDevice" parameterType="TMonitorDevice">
update t_monitor_device
<trim prefix="SET" suffixOverrides=",">
<if test="deviceId != null">device_id = #{deviceId},</if>
<if test="deviceThreshold != null">device_threshold = #{deviceThreshold},</if>
<if test="relationPipeId != null">relation_pipe_id = #{relationPipeId},</if>
<if test="relationPipeThreshold != null">relation_pipe_threshold = #{relationPipeThreshold},</if>
<if test="relationDeviceId != null">relation_device_id = #{relationDeviceId},</if>
<if test="relationDeviceThreshold != null">relation_device_threshold = #{relationDeviceThreshold},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
</trim>
where monitor_id = #{monitorId}
</update>
<delete id="deleteTMonitorDeviceById" parameterType="Long">
delete from t_monitor_device where monitor_id = #{monitorId}
</delete>
<delete id="deleteTMonitorDeviceByIds" parameterType="String">
delete from t_monitor_device where monitor_id in
<foreach item="monitorId" collection="array" open="(" separator="," close=")">
#{monitorId}
</foreach>
</delete>
<select id="getDeviceInfosByIotNo" parameterType="java.lang.String" resultMap="TMonitorDeviceResult">
SELECT
monitor.*
FROM
t_monitor_device monitor,t_device_info device
where device.iot_no = #{iotNo}
</select>
</mapper>
\ No newline at end of file
package com.zehong.gassdevicereport;
import com.zehong.gassdevicereport.utils.RedisUtil;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.ArrayList;
import java.util.List;
@SpringBootTest
class GassDeviceReportApplicationTests {
@Autowired
private RedisUtil redisUtil;
@Test
void redisTest(){
List<String> list = new ArrayList<>();
list.add("haha");
list.add("hihi");
list.add("heihei");
redisUtil.set("test",list);
System.out.println(redisUtil.get("test"));
}
public static void main(String[] args) {
try {
Class<?> clazz = Class.forName("com.zehong.gassdevicereport.service.impl.DynamicTask");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
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