Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
S
supplyheatdevicedatacollection
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
耿迪迪
supplyheatdevicedatacollection
Commits
86fbb808
Commit
86fbb808
authored
May 17, 2022
by
耿迪迪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
供热设备数据接收
parents
Hide whitespace changes
Inline
Side-by-side
Showing
37 changed files
with
3387 additions
and
0 deletions
+3387
-0
.gitignore
.gitignore
+76
-0
pom.xml
pom.xml
+112
-0
SupplyHeatDeviceDataCollectionApplication.java
...com/zehong/SupplyHeatDeviceDataCollectionApplication.java
+20
-0
NettyClientConfig.java
src/main/java/com/zehong/config/NettyClientConfig.java
+22
-0
RedisConfig.java
src/main/java/com/zehong/config/RedisConfig.java
+115
-0
TControllerValuesDataDao.java
src/main/java/com/zehong/dao/TControllerValuesDataDao.java
+60
-0
THeatDataDao.java
src/main/java/com/zehong/dao/THeatDataDao.java
+60
-0
TControllerValuesData.java
src/main/java/com/zehong/entity/TControllerValuesData.java
+99
-0
THeatData.java
src/main/java/com/zehong/entity/THeatData.java
+96
-0
InformationTypeEnum.java
src/main/java/com/zehong/enums/InformationTypeEnum.java
+68
-0
MessageTypeEnum.java
src/main/java/com/zehong/enums/MessageTypeEnum.java
+57
-0
NettyTcpStart.java
src/main/java/com/zehong/netty/NettyTcpStart.java
+70
-0
CauseDecode.java
src/main/java/com/zehong/netty/decode/CauseDecode.java
+39
-0
DateTimeDecode.java
src/main/java/com/zehong/netty/decode/DateTimeDecode.java
+39
-0
ErrorDataEquipmentIdListsDecode.java
.../zehong/netty/decode/ErrorDataEquipmentIdListsDecode.java
+71
-0
HeatMeterDataListDecode.java
...java/com/zehong/netty/decode/HeatMeterDataListDecode.java
+255
-0
InformationDecode.java
src/main/java/com/zehong/netty/decode/InformationDecode.java
+41
-0
MsgDecode.java
src/main/java/com/zehong/netty/decode/MsgDecode.java
+90
-0
PackageInformationDecode.java
...ava/com/zehong/netty/decode/PackageInformationDecode.java
+140
-0
ValveDataListsDecode.java
...in/java/com/zehong/netty/decode/ValveDataListsDecode.java
+177
-0
TcpServerHandler.java
src/main/java/com/zehong/netty/handler/TcpServerHandler.java
+88
-0
ITControllerValuesDataService.java
...ava/com/zehong/service/ITControllerValuesDataService.java
+69
-0
ITHeatDataService.java
src/main/java/com/zehong/service/ITHeatDataService.java
+70
-0
TControllerValuesDataServiceImpl.java
...zehong/service/impl/TControllerValuesDataServiceImpl.java
+101
-0
THeatDataServiceImpl.java
...in/java/com/zehong/service/impl/THeatDataServiceImpl.java
+103
-0
DateTimeValueUtil.java
src/main/java/com/zehong/utils/DateTimeValueUtil.java
+25
-0
HexUtils.java
src/main/java/com/zehong/utils/HexUtils.java
+101
-0
NettyClient.java
src/main/java/com/zehong/utils/NettyClient.java
+61
-0
RedisUtil.java
src/main/java/com/zehong/utils/RedisUtil.java
+543
-0
SpringUtil.java
src/main/java/com/zehong/utils/SpringUtil.java
+39
-0
NettyClientHandler.java
...main/java/com/zehong/utils/client/NettyClientHandler.java
+37
-0
application-prd.yml
src/main/resources/application-prd.yml
+0
-0
application-test.yml
src/main/resources/application-test.yml
+42
-0
application.yml
src/main/resources/application.yml
+8
-0
logback-spring.xml
src/main/resources/logback-spring.xml
+36
-0
TControllerValuesDataMapper.xml
src/main/resources/mapper/TControllerValuesDataMapper.xml
+181
-0
THeatDataMapper.xml
src/main/resources/mapper/THeatDataMapper.xml
+176
-0
No files found.
.gitignore
0 → 100644
View file @
86fbb808
######################################################################
# Build Tools
.gradle
/build/
!gradle/wrapper/gradle-wrapper.jar
target/
!.mvn/wrapper/maven-wrapper.jar
######################################################################
# IDE
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
/target/
*.class
*.jar
*.log
/logs/*
/target/*
.settings*
### NetBeans ###
nbproject/private/
build/*
nbbuild/
dist/
nbdist/
.nb-gradle/
######################################################################
# Others
*.log
*.xml.versionsBackup
*.swp
!*/build/*.java
!*/build/*.html
!*/build/*.xml
.DS_Store
node_modules
/dist
# local env files
.env.local
.env.*.local
# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
pom.xml
0 → 100644
View file @
86fbb808
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
com.zehong
</groupId>
<artifactId>
supplyheatdevicedatacollection
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<parent>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-parent
</artifactId>
<version>
2.5.3
</version>
</parent>
<dependencies>
<!-- spring-boot-start-web -->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<!-- spring-boot-start-test -->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
</dependency>
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
<version>
4.12
</version>
<scope>
test
</scope>
</dependency>
<!-- hutool -->
<dependency>
<groupId>
cn.hutool
</groupId>
<artifactId>
hutool-all
</artifactId>
<version>
5.7.19
</version>
</dependency>
<!--netty-->
<dependency>
<groupId>
io.netty
</groupId>
<artifactId>
netty-all
</artifactId>
<version>
4.1.65.Final
</version>
</dependency>
<!--集成redis-->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-redis
</artifactId>
</dependency>
<!-- pool 对象池 -->
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-pool2
</artifactId>
</dependency>
<!--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>
<!-- pagehelper 分页插件 -->
<dependency>
<groupId>
com.github.pagehelper
</groupId>
<artifactId>
pagehelper-spring-boot-starter
</artifactId>
<version>
1.3.0
</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-compiler-plugin
</artifactId>
<configuration>
<source>
1.8
</source>
<target>
1.8
</target>
</configuration>
</plugin>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
src/main/java/com/zehong/SupplyHeatDeviceDataCollectionApplication.java
0 → 100644
View file @
86fbb808
package
com
.
zehong
;
import
org.mybatis.spring.annotation.MapperScan
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
/**
* @author gengd
* 供热设备数据收集系统
*/
@SpringBootApplication
@MapperScan
(
"com.zehong.dao"
)
public
class
SupplyHeatDeviceDataCollectionApplication
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
SupplyHeatDeviceDataCollectionApplication
.
class
,
args
);
}
}
src/main/java/com/zehong/config/NettyClientConfig.java
0 → 100644
View file @
86fbb808
package
com
.
zehong
.
config
;
import
lombok.Data
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Configuration
;
@Configuration
@Data
public
class
NettyClientConfig
{
/**
* netty 客户端服务器地址
*/
@Value
(
"confirmClient.host"
)
private
String
host
;
/**
* netty 客户端端口
*/
@Value
(
"${confirmClient.port}"
)
private
int
port
;
}
src/main/java/com/zehong/config/RedisConfig.java
0 → 100644
View file @
86fbb808
package
com
.
zehong
.
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
;
/**
* @author gengd
* 缓存配置
*/
@Configuration
@EnableCaching
public
class
RedisConfig
extends
CachingConfigurerSupport
{
/**
* retemplate相关配置
* @param factory 连接工厂
* @return RedisTemplate
*/
@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
();
}
}
src/main/java/com/zehong/dao/TControllerValuesDataDao.java
0 → 100644
View file @
86fbb808
package
com
.
zehong
.
dao
;
import
com.zehong.entity.TControllerValuesData
;
import
java.util.List
;
/**
* 阀控数据Mapper接口
*
* @author zehong
* @date 2022-05-07
*/
public
interface
TControllerValuesDataDao
{
/**
* 查询阀控数据
*
* @param controllerValueId 阀控数据ID
* @return 阀控数据
*/
TControllerValuesData
selectTControllerValuesDataById
(
Long
controllerValueId
);
/**
* 查询阀控数据列表
*
* @param tControllerValuesData 阀控数据
* @return 阀控数据集合
*/
List
<
TControllerValuesData
>
selectTControllerValuesDataList
(
TControllerValuesData
tControllerValuesData
);
/**
* 新增阀控数据
*
* @param tControllerValuesData 阀控数据
* @return 结果
*/
int
insertTControllerValuesData
(
TControllerValuesData
tControllerValuesData
);
/**
* 修改阀控数据
*
* @param tControllerValuesData 阀控数据
* @return 结果
*/
int
updateTControllerValuesData
(
TControllerValuesData
tControllerValuesData
);
/**
* 删除阀控数据
*
* @param controllerValueId 阀控数据ID
* @return 结果
*/
int
deleteTControllerValuesDataById
(
Long
controllerValueId
);
/**
* 批量删除阀控数据
*
* @param controllerValueIds 需要删除的数据ID
* @return 结果
*/
int
deleteTControllerValuesDataByIds
(
Long
[]
controllerValueIds
);
}
src/main/java/com/zehong/dao/THeatDataDao.java
0 → 100644
View file @
86fbb808
package
com
.
zehong
.
dao
;
import
com.zehong.entity.THeatData
;
import
java.util.List
;
/**
* 热量数据Mapper接口
*
* @author zehong
* @date 2022-05-07
*/
public
interface
THeatDataDao
{
/**
* 查询热量数据
*
* @param heatId 热量数据ID
* @return 热量数据
*/
THeatData
selectTHeatDataById
(
Long
heatId
);
/**
* 查询热量数据列表
*
* @param tHeatData 热量数据
* @return 热量数据集合
*/
List
<
THeatData
>
selectTHeatDataList
(
THeatData
tHeatData
);
/**
* 新增热量数据
*
* @param tHeatData 热量数据
* @return 结果
*/
int
insertTHeatData
(
THeatData
tHeatData
);
/**
* 修改热量数据
*
* @param tHeatData 热量数据
* @return 结果
*/
int
updateTHeatData
(
THeatData
tHeatData
);
/**
* 删除热量数据
*
* @param heatId 热量数据ID
* @return 结果
*/
int
deleteTHeatDataById
(
Long
heatId
);
/**
* 批量删除热量数据
*
* @param heatIds 需要删除的数据ID
* @return 结果
*/
int
deleteTHeatDataByIds
(
Long
[]
heatIds
);
}
src/main/java/com/zehong/entity/TControllerValuesData.java
0 → 100644
View file @
86fbb808
package
com
.
zehong
.
entity
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
lombok.Data
;
import
java.math.BigDecimal
;
import
java.util.Date
;
/**
* 阀控数据对象 t_controller_values_data
*
* @author zehong
* @date 2022-05-07
*/
@Data
public
class
TControllerValuesData
{
/** 阀控id */
private
Long
controllerValueId
;
/** 厂商编号 */
private
String
manufacturersId
;
/** 阀控类型 */
private
String
equipmentTypeValue
;
/** 阀控编号 */
private
String
valueId
;
/** 阀控协议类型:保留,目前未使用,全FF表示数据无效 */
private
String
protocolType
;
/** 阀门操作类型,十六进制,0:温控,1:常开,2:常关,3:自由温控;4:强制;5:用户控制;6:固定温控 */
private
String
valveOperateType
;
/** 温度下限 */
private
BigDecimal
lowControlTemperatureRange
;
/** 温度上限 */
private
BigDecimal
highControlTemperatureRange
;
/** 室内温控器向阀门上报室温最大时间周期,单位分钟,范围1到30,全FF表示数据无效 */
private
String
indoorTemperatureReportMaxTimer
;
/** 温控温度 */
private
BigDecimal
controlTemperature
;
/** 室内温度 */
private
BigDecimal
indoorTemperature
;
/** 当前阀门开关状态 0:关闭;100:打开;对于开度阀0、10、…100对应0~10挡位 */
private
String
openedPercent
;
/** 阀门关机防冻标记,0:关闭关机防冻功能;1:打开关机防冻功能 */
private
String
preventFrozenFlag
;
/** 阀门控制器与室内温控器通信方式,0:无线;1:有线 */
private
String
communicateType
;
/** 阀门控制器供电方式,0:市电;1:电池 */
private
String
valvePowerStyle
;
/** 允许的最大挡位,十六进制数,0、10、… 100对应0~10挡位 */
private
String
panelPowerTyle
;
/** 对码状态,十六进制数,0:未对码;1:已对码 */
private
String
pairingStatus
;
/** 阀门累计开时间,单位秒 */
private
String
cumulativeOpenedTime
;
/** 阀门累计工作时间,单位秒 */
private
String
cumulativeWorkingTime
;
/** 实时时间 */
@JsonFormat
(
pattern
=
"yyyy-MM-dd"
)
private
Date
dateTimeValue
;
/** 十六进制,高字节为阀门控制器状态,低字节为室内温控器状态 */
private
String
status
;
/** 累计阀开/关次数 */
private
String
cumulativeOpenAndCloseTimes
;
/** 累计室温*时间(分钟) */
private
String
cumulativeIndoorTempMultiplySecond
;
/** 软件版本,十六进制数,高位为主版本号;低位为次版本号 */
private
String
softwareVersion
;
/** 频点,十六进制数,全FF表示数据无效 */
private
String
freq
;
/** Snum,十六进制数,全FF表示数据无效 */
private
String
snum
;
/** 创建时间 */
private
Date
createTime
;
}
src/main/java/com/zehong/entity/THeatData.java
0 → 100644
View file @
86fbb808
package
com
.
zehong
.
entity
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
lombok.Data
;
import
java.math.BigDecimal
;
import
java.util.Date
;
/**
* 热量数据对象 t_heat_data
*
* @author zehong
* @date 2022-05-07
*/
@Data
public
class
THeatData
{
/** 热量id */
private
Long
heatId
;
/** 厂商编号 */
private
String
manufacturersId
;
/** 表类型 */
private
String
equipmentTypeValue
;
/** 热量表编号 */
private
String
heatMeterId
;
/** 表协议类型:保留,目前未使用 */
private
String
protocolType
;
/** 累计冷量 */
private
BigDecimal
cumulativeCool
;
/** 累计冷量单位,单位最高位为0表示累计冷量为正;最高位为1表示累计冷量为负 */
private
String
cumulativeCoolUnit
;
/** 累积热量 */
private
BigDecimal
cumulativeHeat
;
/** 累积热量单位,单位最高位为0表示累计热量为正;最高位为1表示累计热量为负 */
private
String
cumulativeHeatUnit
;
/** 瞬时功率 */
private
BigDecimal
theCurrentThermalPower
;
/** 瞬时功率单位,单位最高位为0表示瞬时功率为正;最高位为1表示瞬时功率为负 */
private
String
theCurrentThermalPowerUnit
;
/** 瞬时流量 */
private
BigDecimal
currentFlow
;
/** 瞬时流量单位,单位最高位为0表示瞬时流量为正;最高位为1表示瞬时流量为负 */
private
String
currentFlowUnit
;
/** 累积流量 */
private
BigDecimal
cumulativeFlow
;
/** 累积流量单位,单位最高位为0表示累计流量为正;最高位为1表示累计流量为负 */
private
String
cumulativeFlowUnit
;
/** 当前供水温度 */
private
BigDecimal
theCurrentWaterTemperature
;
/** 当前回水温度 */
private
BigDecimal
currentReturnTemperature
;
/** 累积工作时间,单位小时 */
private
String
cumulativeWorkingTime
;
/** 热量表实时时间 */
@JsonFormat
(
pattern
=
"yyyy-MM-dd"
)
private
Date
dateTimeValue
;
/** 回水累计流量 */
private
BigDecimal
cumulativeReturnFlow
;
/** 回水累计流量单位,单位最高位为0表示回水累计流量为正;最高位为1表示回水累计流量为负 */
private
String
cumulativeReturnFlowUnit
;
/** 累计流量差 */
private
BigDecimal
cumulativeFlowDifference
;
/** 累计流量差单位,单位最高位为0表示累计流量差为正;最高位为1表示累计流量差为负 */
private
String
cumulativeFlowDifferenceUnit
;
/** 有效标志(是否支持回水累计流量、累计流量差),十六进制,高位在前、低位在后0x0000:无效;0x0001:有效 */
private
String
returnFlowFlag
;
/** 状态ST */
private
String
stStatus
;
/** 创建时间 */
private
Date
createTime
;
}
src/main/java/com/zehong/enums/InformationTypeEnum.java
0 → 100644
View file @
86fbb808
package
com
.
zehong
.
enums
;
/**
* @author gengd
* 信息单元类型
*/
public
enum
InformationTypeEnum
{
/** (原因值)*/
CAUSE
(
"01"
),
/**(日期时间) */
DATE_TIME
(
"02"
),
/** (分包信息)*/
PACKET_INFORMATION
(
"03"
),
/**(程序版本) */
PROGRAM_VERSION
(
"11"
),
/** (集中器网络参数)*/
CONCENTRATOR_NETWORK
(
"12"
),
/** (集中器上报数据时间)*/
CONCENTRATOR_REPORTED_TIME
(
"13"
),
/** (集中器参数)*/
CONCENTRATOR_PARAMETER
(
"14"
),
/** (设备ID列表)*/
EQUIPMENT_ID_LISTS
(
"16"
),
/**(读数据失败设备列表) */
ERROR_DATA_EQUIPMENT_ID_LISTS
(
"20"
),
/** (热量表数据)*/
HEAT_METER_DATA
(
"21"
),
/** (热量表数据列表)*/
HEAT_METER_DATA_LISTS
(
"22"
),
/** (阀门数据)*/
VALVE_DATA
(
"31"
),
/** (阀门数据列表)*/
VALVE_DATA_LISTS
(
"32"
),
/**(阀门操作列表) */
VALVE_OPERATE_LISTS
(
"33"
),
/** (阀门操作原因值)*/
VALVE_OPERATE_CAUSE
(
"34"
),
/** (阀门操作)*/
VALVE_OPERATE
(
"35"
),
/**(集中器中历史数据日期列表) */
HISTORY_DATE_LISTS
(
"50"
),
/**(设备类型) */
EQUIPMENT_TYPE
(
"61"
),
/** (设备ID)*/
EQUIPMENT_ID
(
"62"
),
/**(分包确认指示) */
MULTI_PACKET_CONFIRM_INDICATION
(
"A1"
),
/** (集中器告警)*/
CONCENTRATOR_ALARM
(
"A3"
),
/**(自由温控控制温度) */
FREE_CONTROL_TEMPERATURE
(
"C1"
),
/** (温控温度范围)*/
CONTROL_TEMPERATURE_RANGE
(
"C2"
),
/** (室温上报最大时间间隔)*/
INDOOR_TEMPERATURE_REPORT_MAX_TIMER
(
"C3"
),
/** (长关模式下防冻)*/
PREVENT_FROZEN_UNDER_CLOSED_MODE
(
"C4"
),
/**(对码标记) */
PAIRING_FLAG
(
"CA"
),
/**(启动时阀门动作延时) */
VALVE_OPERATE_DELAY_ON_START_UP
(
"CB"
);
public
String
value
;
InformationTypeEnum
(
String
value
){
this
.
value
=
value
;
}
}
src/main/java/com/zehong/enums/MessageTypeEnum.java
0 → 100644
View file @
86fbb808
package
com
.
zehong
.
enums
;
/**
* @author gengd
* 消息类型
*/
public
enum
MessageTypeEnum
{
/**(集中器注册请求)*/
CONCENTRATOR_REGISTRATION_REQUEST
(
"01"
),
/**(集中器注册响应)*/
CONCENTRATOR_REGISTRATION_RESPONSE
(
"02"
),
/** (心跳)*/
HEARTBEAT
(
"03"
),
/** (集中器校时)*/
CONCENTRATOR_CALIBRATION
(
"05"
),
/** (获取集中器数据上报时间的请求)*/
GET_CONCENTRATOR_REPORTED_TIME_REQUEST
(
"13"
),
/** (获取集中器数据上报时间的响应)*/
GET_CONCENTRATOR_REPORTED_TIME_RESPONSE
(
"14"
),
/**(设置集中器数据上报时间的请求) */
SET_CONCENTRATOR_REPORTED_TIME_REQUEST
(
"23"
),
/**(设置集中器数据上报时间的响应) */
SET_CONCENTRATOR_REPORTED_TIME_RESPONSE
(
"24"
),
/** (获取集中器下设备ID的请求)*/
GET_EQUIPMENT_ID_REQUEST
(
"31"
),
/** (获取集中器下设备ID的响应)*/
GET_EQUIPMENT_ID_RESPONSE
(
"32"
),
/**(设置集中器下设备ID的请求) */
SET_EQUIPMENT_ID_REQUEST
(
"33"
),
/** (设置集中器下设备ID的响应)*/
SET_EQUIPMENT_ID_RESPONSE
(
"34"
),
/** (定时维护数据上传通知)*/
MAINTENANCE_DATA_NOTIFY
(
"51"
),
/** (定时维护数据接收完成确认)*/
MAINTENANCE_DATA_CONFIRM
(
"52"
),
/** (读取定时维护数据的请求)*/
READ_DATA_REQUEST
(
"53"
),
/** (读取定时维护数据的响应)*/
READ_DATA_RESPONSE
(
"54"
),
/**(读取集中器中存储的历史抄表数据时间的请求) */
GET_MAINTENANCE_HISTORY_DATE_REQUEST
(
"61"
),
/**(读取集中器中存储的历史抄表数据时间的响应) */
GET_MAINTENANCE_HISTORY_DATE_RESPONSE
(
"62"
),
/** (实时读表阀的请求)*/
EQUIPMENT_REAL_DATA_REQUEST
(
"67"
),
/**(指定阀门进行操作) */
EQUIPMENT_REAL_DATA_RESPONSE
(
"68"
),
/**(指定阀门进行操作) */
VALVE_OPERATE_REQUEST
(
"71"
),
/** (阀门操作结果) */
VALVE_OPERATE_RESPONSE
(
"75"
);
public
String
value
;
MessageTypeEnum
(
String
value
){
this
.
value
=
value
;
}
}
src/main/java/com/zehong/netty/NettyTcpStart.java
0 → 100644
View file @
86fbb808
package
com
.
zehong
.
netty
;
import
com.zehong.netty.handler.TcpServerHandler
;
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
NettyTcpStart
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
NettyTcpStart
.
class
);
@Resource
private
TcpServerHandler
TcpServerHandler
;
private
EventLoopGroup
bossGroup
=
new
NioEventLoopGroup
();
private
EventLoopGroup
workGroup
=
new
NioEventLoopGroup
();
@Value
(
"${TCPNetty.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
(
TcpServerHandler
);
}
});
//开启需要监听 的端口
for
(
int
port
:
ports
){
ChannelFuture
future
=
b
.
bind
(
port
).
sync
();
if
(
future
.
isSuccess
())
{
logger
.
info
(
"TCP server启动 "
+
port
+
" 成功"
);
}
}
}
/**
* 销毁
*/
@PreDestroy
public
void
destroy
()
{
bossGroup
.
shutdownGracefully
().
syncUninterruptibly
();
workGroup
.
shutdownGracefully
().
syncUninterruptibly
();
logger
.
info
(
"TCP server关闭 Netty 成功"
);
}
}
src/main/java/com/zehong/netty/decode/CauseDecode.java
0 → 100644
View file @
86fbb808
package
com
.
zehong
.
netty
.
decode
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
* @author gengd
* 信息单元原因解析
*/
public
class
CauseDecode
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
CauseDecode
.
class
);
/**
* 解析消息
*/
private
MsgDecode
decode
;
/**
* 原因
*/
private
String
cause
;
public
CauseDecode
(
MsgDecode
decode
){
this
.
decode
=
decode
;
this
.
cause
=
decode
.
getMsgInfo
().
substring
(
0
,
8
);
}
/**
* 解析原因
*/
public
void
decodeCause
(){
//信息单元类型
String
ieType
=
this
.
cause
.
substring
(
0
,
2
);
//长度
String
length
=
this
.
cause
.
substring
(
2
,
6
);
//原因值
String
causeValue
=
this
.
cause
.
substring
(
6
,
8
);
logger
.
info
(
"transmissionId:"
+
decode
.
getTransmissionId
()
+
"原因: 信息单元类型:"
+
ieType
+
" 长度:"
+
length
+
"原因值:"
+
causeValue
);
}
}
src/main/java/com/zehong/netty/decode/DateTimeDecode.java
0 → 100644
View file @
86fbb808
package
com
.
zehong
.
netty
.
decode
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
com.zehong.utils.DateTimeValueUtil
;
/**
* @author gengd
* 信息单元时间日期解析
*/
public
class
DateTimeDecode
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
CauseDecode
.
class
);
private
MsgDecode
decode
;
/**
* 日期时间
*/
private
String
dateTime
;
public
DateTimeDecode
(
MsgDecode
decode
){
this
.
dateTime
=
decode
.
getMsgInfo
().
substring
(
8
,
28
);
}
public
void
decodeDateTime
(){
//信息单元类型
String
ieType
=
dateTime
.
substring
(
0
,
2
);
//长度
String
length
=
dateTime
.
substring
(
2
,
6
);
//日期时间
String
dateTimeStr
=
DateTimeValueUtil
.
getDateTimeStr
(
dateTime
.
substring
(
6
,
20
));
logger
.
info
(
"transmissionId:"
+
decode
.
getTransmissionId
()
+
"时间日期: 信息单元类型:"
+
ieType
+
" 长度:"
+
length
+
"原因值:"
+
dateTimeStr
);
}
}
src/main/java/com/zehong/netty/decode/ErrorDataEquipmentIdListsDecode.java
0 → 100644
View file @
86fbb808
package
com
.
zehong
.
netty
.
decode
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* @author gengd
* 读取数据失败ID列表
*/
public
class
ErrorDataEquipmentIdListsDecode
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
ErrorDataEquipmentIdListsDecode
.
class
);
private
MsgDecode
decode
;
/**
* 设备类型
*/
private
Map
<
String
,
String
>
equipmentTypeValueMap
=
new
HashMap
<>();
{
equipmentTypeValueMap
.
put
(
"00"
,
"所有设备"
);
equipmentTypeValueMap
.
put
(
"10"
,
"水表"
);
equipmentTypeValueMap
.
put
(
"20"
,
"热量表"
);
equipmentTypeValueMap
.
put
(
"70"
,
"阀门"
);
}
/**
* 读取数据失败ID列表数据
*/
private
String
errorDataEquipmentIdLists
;
public
ErrorDataEquipmentIdListsDecode
(
MsgDecode
decode
,
int
startLength
){
this
.
decode
=
decode
;
this
.
errorDataEquipmentIdLists
=
decode
.
getMsgInfo
().
substring
(
42
+
startLength
*
2
,
decode
.
getMsgInfo
().
length
());
}
public
void
decodeErrorDataEquipmentIdLists
(){
//信息单元类型
String
ieType
=
this
.
errorDataEquipmentIdLists
.
substring
(
0
,
2
);
//长度
String
length
=
this
.
errorDataEquipmentIdLists
.
substring
(
2
,
6
);
//设备ID数量
String
errorDataEquipmentIdCount
=
this
.
errorDataEquipmentIdLists
.
substring
(
6
,
10
);
deocdeErrorDataEquipmentIdList
(
Integer
.
parseInt
(
errorDataEquipmentIdCount
,
16
));
logger
.
info
(
"transmissionId:"
+
decode
.
getTransmissionId
()
+
"读取数据失败ID列表数据: 信息单元类型:"
+
ieType
+
" 长度:"
+
length
+
"读取数据失败ID列表数据:"
+
errorDataEquipmentIdLists
.
substring
(
10
,
Integer
.
parseInt
(
errorDataEquipmentIdCount
,
16
)*
16
));
}
/**
* 数据解析
* @param errorDataEquipmentIdCount 设备数量
*/
public
void
deocdeErrorDataEquipmentIdList
(
int
errorDataEquipmentIdCount
){
String
errorDataEquipmentIds
=
errorDataEquipmentIdLists
.
substring
(
10
,
errorDataEquipmentIdLists
.
length
());
for
(
int
i
=
1
;
i
<
errorDataEquipmentIdCount
+
1
;
i
++){
String
errorDataEquipmentId
=
errorDataEquipmentIds
.
substring
((
i
-
1
)*
16
,
i
*
16
);
//厂商ID,BCD码
String
manufacturersId
=
errorDataEquipmentId
.
substring
(
0
,
4
);
//设备类型
String
equipmentTypeValue
=
errorDataEquipmentId
.
substring
(
4
,
6
);
String
equipmentType
=
equipmentTypeValueMap
.
get
(
equipmentTypeValue
);
//设备编号
String
equipmentId
=
errorDataEquipmentId
.
substring
(
6
,
16
);
logger
.
info
(
"transmissionId:"
+
decode
.
getTransmissionId
()
+
"读取数据失败ID列表数据:"
+
"厂商Id:"
+
manufacturersId
+
"设备类型:"
+
equipmentType
+
"设备编号:"
+
equipmentId
);
}
}
}
src/main/java/com/zehong/netty/decode/HeatMeterDataListDecode.java
0 → 100644
View file @
86fbb808
package
com
.
zehong
.
netty
.
decode
;
import
com.zehong.entity.THeatData
;
import
com.zehong.service.ITHeatDataService
;
import
com.zehong.utils.DateTimeValueUtil
;
import
com.zehong.utils.HexUtils
;
import
com.zehong.utils.SpringUtil
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.math.BigDecimal
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* @author gengd
* 信息单元热量表数据解析
*/
public
class
HeatMeterDataListDecode
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
HeatMeterDataListDecode
.
class
);
private
MsgDecode
decode
;
/**
* 累计冷量单位,单位最高位为0表示累计冷量为正;最高位为1表示累计冷量为负
*/
private
Map
<
String
,
String
>
cumulativeCoolUnitMap
=
new
HashMap
<>();
{
//焦耳
cumulativeCoolUnitMap
.
put
(
"01"
,
"J"
);
//千焦
cumulativeCoolUnitMap
.
put
(
"0b"
,
"KJ"
);
//兆焦
cumulativeCoolUnitMap
.
put
(
"0e"
,
"MJ"
);
//G焦
cumulativeCoolUnitMap
.
put
(
"11"
,
"GJ"
);
//G焦 * 100
cumulativeCoolUnitMap
.
put
(
"13"
,
"GJ*100"
);
//瓦时
cumulativeCoolUnitMap
.
put
(
"02"
,
"Wh"
);
//千瓦时
cumulativeCoolUnitMap
.
put
(
"05"
,
"kWh"
);
//兆瓦时
cumulativeCoolUnitMap
.
put
(
"08"
,
"MWh"
);
//兆瓦时 * 100
cumulativeCoolUnitMap
.
put
(
"0a"
,
"MWH*100"
);
}
/**
* 瞬时功率单位
*/
private
Map
<
String
,
String
>
theCurrentThermalPowerUnitMap
=
new
HashMap
<>();
{
//瓦
theCurrentThermalPowerUnitMap
.
put
(
"14"
,
"W"
);
//千瓦
theCurrentThermalPowerUnitMap
.
put
(
"17"
,
"kW"
);
//兆瓦
theCurrentThermalPowerUnitMap
.
put
(
"1a"
,
"MW"
);
}
/**
* 瞬时流量单位
*/
private
Map
<
String
,
String
>
currentFlowUnitMap
=
new
HashMap
<>();
{
//升/小时
currentFlowUnitMap
.
put
(
"32"
,
"L/h"
);
//立方米/小时
currentFlowUnitMap
.
put
(
"35"
,
"m³/h"
);
}
/**
* 累计流量单位
*/
private
Map
<
String
,
String
>
cumulativeFlowUnitMap
=
new
HashMap
<>();
{
//升
cumulativeFlowUnitMap
.
put
(
"29"
,
"L"
);
//立方米
cumulativeFlowUnitMap
.
put
(
"2c"
,
"m³"
);
}
/**
* 热量表数据
*/
private
String
heatMeterDataList
;
/**
* 热量表数据所占字节数
*/
public
int
getHeatMeterDataListLength
;
public
HeatMeterDataListDecode
(
MsgDecode
decode
){
heatMeterDataList
=
decode
.
getMsgInfo
().
substring
(
42
,
decode
.
getMsgInfo
().
length
());
}
/**
* 解析热量表数据
*/
public
void
decodeHeatMeterDataList
(){
//信息单元类型
String
ieType
=
this
.
heatMeterDataList
.
substring
(
0
,
2
);
//长度
String
length
=
this
.
heatMeterDataList
.
substring
(
2
,
6
);
//热量表数量
String
heatMeterDataCount
=
this
.
heatMeterDataList
.
substring
(
6
,
10
);
//热量表数据所占字节数
this
.
getHeatMeterDataListLength
=
Integer
.
parseInt
(
heatMeterDataCount
,
16
)
*
63
+
5
;
//热量表数据
decodeHeatMeterData
(
Integer
.
parseInt
(
heatMeterDataCount
,
16
));
logger
.
info
(
"transmissionId:"
+
decode
.
getTransmissionId
()
+
"热量表数据: 信息单元类型:"
+
ieType
+
" 长度:"
+
length
+
"热量表数量:"
+
heatMeterDataCount
+
"热量表数据:"
+
heatMeterDataList
.
substring
(
10
,
Integer
.
parseInt
(
heatMeterDataCount
,
16
)*
126
));
}
/**
* 解析热量表数据
* @param count 热量表数量
*/
private
void
decodeHeatMeterData
(
int
count
){
String
heatMeterDatas
=
heatMeterDataList
.
substring
(
10
,
heatMeterDataList
.
length
());
for
(
int
i
=
1
;
i
<
count
+
1
;
i
++){
String
heatMeterData
=
heatMeterDatas
.
substring
((
i
-
1
)*
126
,
i
*
126
);
saveHeatMeterData
(
heatMeterData
);
}
}
/**
* 保存热量表信息
* @param heatMeterData 热量表数据
*/
private
void
saveHeatMeterData
(
String
heatMeterData
){
ITHeatDataService
itHeatDataService
=
SpringUtil
.
getBean
(
ITHeatDataService
.
class
);
THeatData
tHeatData
=
decodeHeatMeterData
(
heatMeterData
);
itHeatDataService
.
insertTHeatData
(
tHeatData
);
}
/**
* 解析流量表数据
* @param heatMeterData 流量表数据
* @return THeatData
*/
private
THeatData
decodeHeatMeterData
(
String
heatMeterData
){
THeatData
tHeatData
=
new
THeatData
();
//厂家编号
String
manufacturersId
=
heatMeterData
.
substring
(
0
,
4
);
tHeatData
.
setManufacturersId
(
manufacturersId
);
//表类型
String
equipmentTypeValue
=
heatMeterData
.
substring
(
4
,
6
);
tHeatData
.
setEquipmentTypeValue
(
equipmentTypeValue
);
//热量表编号
String
heatMeterId
=
heatMeterData
.
substring
(
6
,
16
);
tHeatData
.
setHeatMeterId
(
heatMeterId
);
//累计冷量
String
cumulativeCool
=
heatMeterData
.
substring
(
18
,
26
);
tHeatData
.
setCumulativeCool
(
new
BigDecimal
(
Integer
.
parseInt
(
cumulativeCool
,
16
)/
100
));
//累计冷量单位
String
cumulativeCoolUnit
=
heatMeterData
.
substring
(
26
,
28
);
if
(
cumulativeCool
.
substring
(
0
).
equals
(
"1"
)){
tHeatData
.
setCumulativeCoolUnit
(
"-"
+
cumulativeCoolUnitMap
.
get
(
cumulativeCoolUnit
));
}
else
{
tHeatData
.
setCumulativeCoolUnit
(
cumulativeCoolUnitMap
.
get
(
cumulativeCoolUnit
));
}
//累积热量
String
cumulativeHeat
=
heatMeterData
.
substring
(
28
,
36
);
tHeatData
.
setCumulativeHeat
(
new
BigDecimal
(
Integer
.
parseInt
(
cumulativeHeat
,
16
)/
100
));
//累计热量单位
String
cumulativeHeatUnit
=
heatMeterData
.
substring
(
36
,
38
);
if
(
cumulativeHeatUnit
.
substring
(
0
).
equals
(
"1"
)){
tHeatData
.
setCumulativeHeatUnit
(
"-"
+
cumulativeCoolUnitMap
.
get
(
cumulativeCoolUnit
));
}
else
{
tHeatData
.
setCumulativeHeatUnit
(
cumulativeCoolUnitMap
.
get
(
cumulativeCoolUnit
));
}
//瞬时功率
String
theCurrentThermalPower
=
heatMeterData
.
substring
(
38
,
46
);
tHeatData
.
setTheCurrentThermalPower
(
new
BigDecimal
(
Integer
.
parseInt
(
theCurrentThermalPower
,
16
)/
100
));
//瞬时功率单位
String
theCurrentThermalPowerUnit
=
heatMeterData
.
substring
(
46
,
48
);
if
(
theCurrentThermalPowerUnit
.
substring
(
0
).
equals
(
"1"
)){
tHeatData
.
setTheCurrentThermalPowerUnit
(
"-"
+
theCurrentThermalPowerUnitMap
.
get
(
theCurrentThermalPower
));
}
else
{
tHeatData
.
setTheCurrentThermalPowerUnit
(
theCurrentThermalPowerUnitMap
.
get
(
theCurrentThermalPower
));
}
//瞬时流量
String
currentFlow
=
heatMeterData
.
substring
(
48
,
56
);
tHeatData
.
setCurrentFlow
(
new
BigDecimal
(
Integer
.
parseInt
(
currentFlow
,
16
)/
100
));
//瞬时流量单位
String
currentFlowUnit
=
heatMeterData
.
substring
(
56
,
58
);
if
(
currentFlowUnit
.
substring
(
0
).
equals
(
"1"
)){
tHeatData
.
setCurrentFlowUnit
(
"-"
+
currentFlowUnitMap
.
get
(
currentFlowUnit
));
}
else
{
tHeatData
.
setCurrentFlowUnit
(
currentFlowUnitMap
.
get
(
currentFlowUnit
));
}
//累计流量
String
cumulativeFlow
=
heatMeterData
.
substring
(
58
,
66
);
tHeatData
.
setCumulativeFlow
(
new
BigDecimal
(
Integer
.
parseInt
(
cumulativeFlow
,
16
)/
100
));
//累计流量单位
String
cumulativeFlowUnit
=
heatMeterData
.
substring
(
66
,
68
);
if
(
cumulativeFlowUnit
.
substring
(
0
).
equals
(
"1"
)){
tHeatData
.
setCumulativeFlowUnit
(
"-"
+
currentFlowUnitMap
.
get
(
cumulativeFlowUnit
));
}
else
{
tHeatData
.
setCumulativeFlowUnit
(
cumulativeFlowUnitMap
.
get
(
cumulativeFlowUnit
));
}
//当前供水温度
String
theCurrentWaterTemperature
=
heatMeterData
.
substring
(
68
,
72
);
tHeatData
.
setTheCurrentWaterTemperature
(
new
BigDecimal
(
Integer
.
parseInt
(
theCurrentWaterTemperature
,
16
)/
100
));
//当前回水温度
String
currentReturnTemperature
=
heatMeterData
.
substring
(
72
,
76
);
tHeatData
.
setCurrentReturnTemperature
(
new
BigDecimal
(
Integer
.
parseInt
(
currentReturnTemperature
,
16
)/
100
));
//累积工作时间 单位小时
String
cumulativeWorkingTime
=
heatMeterData
.
substring
(
76
,
84
);
tHeatData
.
setCumulativeWorkingTime
(
String
.
valueOf
(
Integer
.
parseInt
(
cumulativeWorkingTime
,
16
)));
//热量表实时时间
String
dateTimeValue
=
heatMeterData
.
substring
(
84
,
98
);
try
{
tHeatData
.
setDateTimeValue
(
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
).
parse
(
DateTimeValueUtil
.
getDateTimeStr
(
dateTimeValue
)));
}
catch
(
ParseException
e
)
{
logger
.
error
(
"热量表实时时间获取失败"
);
}
//回水累计流量
String
cumulativeReturnFlow
=
heatMeterData
.
substring
(
98
,
106
);
tHeatData
.
setCumulativeReturnFlow
(
new
BigDecimal
(
Integer
.
parseInt
(
cumulativeReturnFlow
,
16
)/
100
));
//回水累计流量单位
String
cumulativeReturnFlowUnit
=
heatMeterData
.
substring
(
106
,
108
);
if
(
cumulativeReturnFlowUnit
.
substring
(
0
).
equals
(
"1"
)){
tHeatData
.
setCumulativeReturnFlowUnit
(
"-"
+
currentFlowUnitMap
.
get
(
cumulativeReturnFlowUnit
));
}
else
{
tHeatData
.
setCumulativeReturnFlowUnit
(
cumulativeFlowUnitMap
.
get
(
cumulativeReturnFlowUnit
));
}
//累计流量差
String
cumulativeFlowDifference
=
heatMeterData
.
substring
(
108
,
116
);
tHeatData
.
setCumulativeFlowDifference
(
new
BigDecimal
(
Integer
.
parseInt
(
cumulativeFlowDifference
,
16
)/
100
));
//累计流量差单位
String
cumulativeFlowDifferenceUnit
=
heatMeterData
.
substring
(
116
,
118
);
if
(
cumulativeFlowDifferenceUnit
.
substring
(
0
).
equals
(
"1"
)){
tHeatData
.
setCumulativeFlowDifferenceUnit
(
"-"
+
currentFlowUnitMap
.
get
(
cumulativeFlowDifferenceUnit
));
}
else
{
tHeatData
.
setCumulativeFlowDifferenceUnit
(
cumulativeFlowUnitMap
.
get
(
cumulativeFlowDifferenceUnit
));
}
//有效标识
String
returnFlowFlag
=
heatMeterData
.
substring
(
118
,
122
);
tHeatData
.
setReturnFlowFlag
(
String
.
valueOf
(
Integer
.
parseInt
(
returnFlowFlag
,
16
)));
//stStutas
String
stStatus
=
heatMeterData
.
substring
(
122
,
124
);
tHeatData
.
setStStatus
(
HexUtils
.
hexToBinary
(
stStatus
));
logger
.
info
(
"transmissionId:"
+
decode
.
getTransmissionId
()
+
"设备数据:"
+
tHeatData
.
toString
());
return
tHeatData
;
}
}
src/main/java/com/zehong/netty/decode/InformationDecode.java
0 → 100644
View file @
86fbb808
package
com
.
zehong
.
netty
.
decode
;
/**
* @author gengd
* 信息单元解析
*/
public
class
InformationDecode
{
/**
* 信息单元
*/
private
MsgDecode
decode
;
public
InformationDecode
(
MsgDecode
decode
){
this
.
decode
=
decode
;
}
public
void
infoMsgDecode
(){
//原因值
new
CauseDecode
(
decode
).
decodeCause
();
//日期时间
new
DateTimeDecode
(
decode
).
decodeDateTime
();
//分包信息
PackageInformationDecode
packageInformationDecode
=
new
PackageInformationDecode
(
decode
);
packageInformationDecode
.
decodePakageInformation
();
if
(
packageInformationDecode
.
isNotSaveCurrentIndex
){
//热量表数据列表
HeatMeterDataListDecode
heatMeterDataListDecode
=
new
HeatMeterDataListDecode
(
decode
);
heatMeterDataListDecode
.
decodeHeatMeterDataList
();
int
heatMeterDataListLength
=
heatMeterDataListDecode
.
getHeatMeterDataListLength
;
//阀控数据列表
ValveDataListsDecode
valveDataListsDecode
=
new
ValveDataListsDecode
(
decode
,
heatMeterDataListLength
);
valveDataListsDecode
.
decodeValueDataLists
();
int
valueDataListsLength
=
valveDataListsDecode
.
valueDataListsLength
;
//读取数据失败ID列表
new
ErrorDataEquipmentIdListsDecode
(
decode
,
heatMeterDataListLength
+
valueDataListsLength
).
decodeErrorDataEquipmentIdLists
();
}
}
}
src/main/java/com/zehong/netty/decode/MsgDecode.java
0 → 100644
View file @
86fbb808
package
com
.
zehong
.
netty
.
decode
;
import
java.util.zip.CRC32
;
/**
* @author gengd
* 16进制消息串解析
*/
public
class
MsgDecode
{
/**
* 16进制消息串
*/
private
String
msgStr
;
/** 消息头
* Fixed Preamble 前导码:0x49 0x4f 0x54 0x40 4个字节
* Length 长度:指示后续数据的长度,高位在前、低位在后 2个字节
* Transmission ID 传输ID 1个字节
* Concentrator ID 集中器ID,高位在前、低位在后 4个字节
* Message Type 消息类型 1个字节
*/
private
String
msgHead
;
/** 信息单元 */
private
String
msgInfo
;
/** 消息尾
* CRC32 Check 校验码 4个字节
* Terminator 结束符 2个字节
*/
private
String
msgTail
;
public
MsgDecode
(
String
msgStr
){
this
.
msgStr
=
msgStr
;
this
.
msgHead
=
msgStr
.
substring
(
0
,
24
);
this
.
msgInfo
=
msgStr
.
substring
(
24
,
msgStr
.
length
()-
12
);
this
.
msgTail
=
msgStr
.
substring
(
msgStr
.
length
()-
12
,
msgStr
.
length
());
}
/**
* 获取传输id
* @return String
*/
public
String
getTransmissionId
(){
return
this
.
msgHead
.
substring
(
12
,
14
);
}
/**
* 获取集中器id
* @return
*/
public
String
getConcentratorId
(){
return
this
.
msgHead
.
substring
(
14
,
22
);
}
/**
* 获取消息类型
* @return
*/
public
String
getMessageType
(){
return
this
.
msgHead
.
substring
(
22
,
24
);
}
/**
* crc32校验
* @return boolean
*/
public
boolean
checkCRC32Code
(){
String
checkStr
=
this
.
msgStr
.
substring
(
8
,
this
.
msgStr
.
length
()-
12
);
CRC32
crc32
=
new
CRC32
();
crc32
.
update
(
checkStr
.
getBytes
());
String
checkCode
=
Long
.
toHexString
(
crc32
.
getValue
());
String
crc32Code
=
this
.
msgTail
.
substring
(
0
,
8
);
return
checkCode
.
equals
(
crc32Code
);
}
public
String
getMsgStr
()
{
return
msgStr
;
}
public
String
getMsgHead
()
{
return
msgHead
;
}
public
String
getMsgInfo
()
{
return
msgInfo
;
}
public
String
getMsgTail
()
{
return
msgTail
;
}
}
src/main/java/com/zehong/netty/decode/PackageInformationDecode.java
0 → 100644
View file @
86fbb808
package
com
.
zehong
.
netty
.
decode
;
import
cn.hutool.core.date.DateUtil
;
import
com.zehong.config.NettyClientConfig
;
import
com.zehong.utils.HexUtils
;
import
com.zehong.utils.NettyClient
;
import
com.zehong.utils.RedisUtil
;
import
com.zehong.utils.SpringUtil
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.zip.CRC32
;
/**
* @author gengd
* 信息单元分包信息解析
*/
public
class
PackageInformationDecode
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
PackageInformationDecode
.
class
);
/**
* 上传信息解析数据
*/
private
MsgDecode
decode
;
/**
* 分包信息
*/
private
String
packageInformation
;
/**
* 总包数
*/
private
String
totalPackageCount
;
/**
* 当前包数
*/
private
String
currentPackageIndex
;
/**
* 当前包是否发送过
*/
public
boolean
isNotSaveCurrentIndex
;
public
PackageInformationDecode
(
MsgDecode
decode
){
this
.
decode
=
decode
;
this
.
packageInformation
=
decode
.
getMsgInfo
().
substring
(
28
,
42
);
}
public
void
decodePakageInformation
(){
//信息单元类型
String
ieType
=
this
.
packageInformation
.
substring
(
0
,
2
);
//长度
String
length
=
this
.
packageInformation
.
substring
(
2
,
6
);
//总包数
this
.
totalPackageCount
=
this
.
packageInformation
.
substring
(
6
,
10
);
//当前包数
this
.
currentPackageIndex
=
this
.
packageInformation
.
substring
(
10
,
14
);
logger
.
info
(
"transmissionId:"
+
decode
.
getTransmissionId
()
+
"分包信息: 信息单元类型:"
+
ieType
+
" 长度:"
+
length
+
"总包数:"
+
totalPackageCount
+
"当前包数"
+
currentPackageIndex
);
//缓存分包信息
packageInformationCash
();
}
/**
* 缓存分包信息
*/
private
void
packageInformationCash
(){
RedisUtil
redisUtil
=
SpringUtil
.
getBean
(
RedisUtil
.
class
);
List
<
String
>
cashInfo
=
(
List
<
String
>)
redisUtil
.
get
(
decode
.
getTransmissionId
());
//缓存信息不为空
if
(
null
!=
cashInfo
&&
!
cashInfo
.
isEmpty
()){
if
(
cashInfo
.
contains
(
currentPackageIndex
)){
return
;
}
cashInfo
.
add
(
currentPackageIndex
);
isNotSaveCurrentIndex
=
true
;
//如接受到所有分包信息,移除分包缓存
if
(
Integer
.
parseInt
(
totalPackageCount
,
16
)
==
cashInfo
.
size
()){
//确认消息
confirmInformation
();
//移除分包缓存
redisUtil
.
del
(
decode
.
getTransmissionId
());
return
;
}
// 缓存分包信息
redisUtil
.
set
(
decode
.
getTransmissionId
(),
cashInfo
,
60
*
60
*
6
);
return
;
}
isNotSaveCurrentIndex
=
true
;
List
<
String
>
packageInfoCash
=
new
ArrayList
<>();
packageInfoCash
.
add
(
currentPackageIndex
);
redisUtil
.
set
(
decode
.
getTransmissionId
(),
packageInfoCash
,
60
*
60
*
6
);
}
/**
* 确认成功接收消息
*/
public
void
confirmInformation
(){
String
head
=
decode
.
getMsgHead
();
String
tail
=
decode
.
getMsgTail
();
String
dateTime
=
getDateTimeHex
();
CRC32
crc32
=
new
CRC32
();
crc32
.
update
((
head
.
substring
(
8
,
head
.
length
())+
dateTime
).
getBytes
());
String
checkCode
=
Long
.
toHexString
(
crc32
.
getValue
());
StringBuilder
reqMsg
=
new
StringBuilder
(
head
);
reqMsg
.
append
(
dateTime
)
.
append
(
checkCode
)
.
append
(
tail
.
substring
(
8
,
12
));
NettyClientConfig
config
=
SpringUtil
.
getBean
(
NettyClientConfig
.
class
);
String
msg
=
NettyClient
.
nettyConnection
(
reqMsg
.
toString
(),
config
.
getHost
(),
config
.
getPort
());
logger
.
info
(
"transmissionId:"
+
decode
.
getTransmissionId
()
+
"消息确认服务器回复消息:"
+
msg
);
}
/**
* 拼接信息单元
* @return String
*/
private
static
String
getDateTimeHex
(){
String
now
=
DateUtil
.
now
();
String
[]
date
=
now
.
split
(
" "
);
//年月日
String
[]
yearDate
=
date
[
0
].
split
(
"-"
);
//时分秒
String
[]
time
=
date
[
1
].
split
(
":"
);
System
.
out
.
println
(
"年:"
+
HexUtils
.
bytesToHex
(
yearDate
[
0
].
substring
(
0
,
2
).
getBytes
())
+
" 时:"
+
time
.
toString
());
StringBuilder
dateTime
=
new
StringBuilder
(
""
);
dateTime
.
append
(
String
.
format
(
"%02x"
,
Integer
.
parseInt
(
yearDate
[
0
].
substring
(
0
,
2
))))
.
append
(
String
.
format
(
"%02x"
,
Integer
.
parseInt
(
yearDate
[
0
].
substring
(
2
,
4
))))
.
append
(
String
.
format
(
"%02x"
,
Integer
.
parseInt
(
yearDate
[
1
])))
.
append
(
String
.
format
(
"%02x"
,
Integer
.
parseInt
(
yearDate
[
2
])))
.
append
(
String
.
format
(
"%02x"
,
Integer
.
parseInt
(
time
[
0
])))
.
append
(
String
.
format
(
"%02x"
,
Integer
.
parseInt
(
time
[
1
])))
.
append
(
String
.
format
(
"%02x"
,
Integer
.
parseInt
(
time
[
2
])));
return
dateTime
.
toString
();
}
}
src/main/java/com/zehong/netty/decode/ValveDataListsDecode.java
0 → 100644
View file @
86fbb808
package
com
.
zehong
.
netty
.
decode
;
import
com.zehong.entity.TControllerValuesData
;
import
com.zehong.service.ITControllerValuesDataService
;
import
com.zehong.utils.DateTimeValueUtil
;
import
com.zehong.utils.HexUtils
;
import
com.zehong.utils.SpringUtil
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.util.StringUtils
;
import
java.math.BigDecimal
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
/**
* @gengd
* 阀控数据解析
*/
public
class
ValveDataListsDecode
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
ValveDataListsDecode
.
class
);
private
MsgDecode
decode
;
/**
* 阀控list数据
*/
private
String
valueDataLists
;
/**
* 阀控数据长度
*/
public
int
valueDataListsLength
;
public
ValveDataListsDecode
(
MsgDecode
decode
,
int
startLength
){
this
.
decode
=
decode
;
this
.
valueDataLists
=
decode
.
getMsgInfo
().
substring
(
42
+
startLength
*
2
,
decode
.
getMsgInfo
().
length
());
}
/**
* 解析阀控数据
*/
public
void
decodeValueDataLists
(){
//信息单元类型
String
ieType
=
this
.
valueDataLists
.
substring
(
0
,
2
);
//长度
String
length
=
this
.
valueDataLists
.
substring
(
2
,
6
);
//阀控数量
String
valueDataCount
=
this
.
valueDataLists
.
substring
(
6
,
10
);
//热量表数据所占字节数
this
.
valueDataListsLength
=
Integer
.
parseInt
(
valueDataCount
,
16
)
*
54
+
5
;
//热量表数据
decodeValueData
(
Integer
.
parseInt
(
valueDataCount
,
16
));
logger
.
info
(
"transmissionId:"
+
decode
.
getTransmissionId
()
+
"阀控数据: 信息单元类型:"
+
ieType
+
" 长度:"
+
length
+
"阀控数量:"
+
valueDataListsLength
+
"阀控数据:"
+
valueDataLists
.
substring
(
10
,
Integer
.
parseInt
(
valueDataCount
,
16
)*
108
));
}
/**
* 解析阀控数据
* @param count 数量
*/
private
void
decodeValueData
(
int
count
){
String
heatMeterDatas
=
valueDataLists
.
substring
(
10
,
valueDataLists
.
length
());
for
(
int
i
=
1
;
i
<
count
+
1
;
i
++){
String
valueData
=
heatMeterDatas
.
substring
((
i
-
1
)*
108
,
i
*
108
);
saveValusData
(
valueData
);
}
}
/**
* 保存阀控数据
* @param valueData 阀控数据
*/
private
void
saveValusData
(
String
valueData
){
ITControllerValuesDataService
itControllerValuesDataService
=
SpringUtil
.
getBean
(
ITControllerValuesDataService
.
class
);
TControllerValuesData
tControllerValuesData
=
decodeValueData
(
valueData
);
itControllerValuesDataService
.
insertTControllerValuesData
(
tControllerValuesData
);
}
/**
* 解析阀控表数据
* @param valueData 阀控数据
* @return TControllerValuesData
*/
private
TControllerValuesData
decodeValueData
(
String
valueData
){
TControllerValuesData
tControllerValuesData
=
new
TControllerValuesData
();
//厂商编号
String
manufacturersId
=
valueData
.
substring
(
0
,
4
);
tControllerValuesData
.
setManufacturersId
(
manufacturersId
);
//阀控类型
String
equipmentTypeValue
=
valueData
.
substring
(
4
,
6
);
tControllerValuesData
.
setEquipmentTypeValue
(
equipmentTypeValue
);
//阀控编号
String
valveId
=
valueData
.
substring
(
6
,
16
);
tControllerValuesData
.
setValueId
(
valveId
);
//阀门操作类型
String
valveOperateType
=
valueData
.
substring
(
18
,
20
);
tControllerValuesData
.
setValveOperateType
(
String
.
valueOf
(
Integer
.
parseInt
(
valveOperateType
,
16
)));
/**
* 十六进制数,高位在前、低位在后,两位小数,单位℃
* 小于20000表示温控温度范围下限,例如01 02表示0x0102除100,即2.58℃。
* 大于20000表示回水温度,例如4F 22,0x4F22=20258,(20258-20000)/100=2.58℃
* 全FF表示数据无效
*/
String
lowControlTemperatureRange
=
valueData
.
substring
(
20
,
24
);
int
lowControlTemperatureRangeInt
=
Integer
.
parseInt
(
lowControlTemperatureRange
,
16
);
if
(
lowControlTemperatureRangeInt
>
2000
){
tControllerValuesData
.
setLowControlTemperatureRange
(
new
BigDecimal
((
lowControlTemperatureRangeInt
-
2000
)/
100
));
}
else
{
tControllerValuesData
.
setLowControlTemperatureRange
(
new
BigDecimal
(
lowControlTemperatureRangeInt
/
100
));
}
//温控温度范围上限
String
highControlTemperatureRange
=
valueData
.
substring
(
24
,
28
);
tControllerValuesData
.
setHighControlTemperatureRange
(
new
BigDecimal
(
Integer
.
parseInt
(
highControlTemperatureRange
,
16
)/
100
));
//室内温控器向阀门上报室温最大时间周期,单位分钟,范围1到30
String
indoortemperaturereportMaxTimer
=
valueData
.
substring
(
28
,
30
);
tControllerValuesData
.
setIndoorTemperatureReportMaxTimer
(
String
.
valueOf
(
Integer
.
parseInt
(
indoortemperaturereportMaxTimer
,
16
)));
//温控温度
String
controlTemperature
=
valueData
.
substring
(
30
,
34
);
tControllerValuesData
.
setControlTemperature
(
new
BigDecimal
(
Integer
.
parseInt
(
controlTemperature
,
16
)/
100
));
//室内温度
String
indoorTemperature
=
valueData
.
substring
(
34
,
38
);
tControllerValuesData
.
setIndoorTemperature
(
new
BigDecimal
(
Integer
.
parseInt
(
indoorTemperature
,
16
)/
100
));
//当前阀门开关状态
String
openedPercent
=
valueData
.
substring
(
38
,
40
);
tControllerValuesData
.
setOpenedPercent
(
String
.
valueOf
(
Integer
.
parseInt
(
openedPercent
,
16
)));
//阀门关机防冻标记
String
preventFrozenFlag
=
valueData
.
substring
(
40
,
42
);
tControllerValuesData
.
setPreventFrozenFlag
(
String
.
valueOf
(
Integer
.
parseInt
(
preventFrozenFlag
,
16
)));
//阀门控制器与室内温控器通信方式
String
communicateType
=
valueData
.
substring
(
42
,
44
);
tControllerValuesData
.
setCommunicateType
(
String
.
valueOf
(
Integer
.
parseInt
(
communicateType
,
16
)));
//阀门控制器供电方式
String
valvePowerStyle
=
valueData
.
substring
(
44
,
46
);
tControllerValuesData
.
setValvePowerStyle
(
String
.
valueOf
(
Integer
.
parseInt
(
valvePowerStyle
,
16
)));
//允许的最大挡位
String
panelPowerStyle
=
valueData
.
substring
(
46
,
48
);
tControllerValuesData
.
setPanelPowerTyle
(
String
.
valueOf
(
Integer
.
parseInt
(
panelPowerStyle
,
16
)));
//对码状态
String
pairingStatus
=
valueData
.
substring
(
48
,
50
);
tControllerValuesData
.
setPairingStatus
(
String
.
valueOf
(
Integer
.
parseInt
(
pairingStatus
,
16
)));
//阀门累计开时间 单位秒
String
cumulativeOpenedTime
=
valueData
.
substring
(
50
,
58
);
tControllerValuesData
.
setCumulativeOpenedTime
(
String
.
valueOf
(
Integer
.
parseInt
(
cumulativeOpenedTime
,
16
)));
//阀门累计工作时间 单位秒
String
cumulativeWorkingTime
=
valueData
.
substring
(
58
,
66
);
tControllerValuesData
.
setCumulativeWorkingTime
(
String
.
valueOf
(
Integer
.
parseInt
(
cumulativeWorkingTime
,
16
)));
//实时时间
String
dateTimeValue
=
valueData
.
substring
(
66
,
80
);
try
{
tControllerValuesData
.
setDateTimeValue
(
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
).
parse
(
DateTimeValueUtil
.
getDateTimeStr
(
dateTimeValue
)));
}
catch
(
ParseException
e
)
{
logger
.
error
(
"阀控数据时间解析失败!"
);
}
//状态
String
status
=
valueData
.
substring
(
80
,
84
);
tControllerValuesData
.
setStatus
(
"高位:"
+
HexUtils
.
hexToBinary
(
status
.
substring
(
0
,
2
))+
" 低位:"
+
HexUtils
.
hexToBinary
(
status
.
substring
(
2
,
4
)));
//累计阀开/关次数
String
cumulativeOpenSndCloseTimes
=
valueData
.
substring
(
84
,
92
);
tControllerValuesData
.
setCumulativeOpenAndCloseTimes
(
String
.
valueOf
(
Integer
.
parseInt
(
cumulativeOpenSndCloseTimes
,
16
)));
//累计室温*时间(分钟)
String
cumulativeIndoorTempMultiplySecond
=
valueData
.
substring
(
92
,
100
);
tControllerValuesData
.
setCumulativeIndoorTempMultiplySecond
(
String
.
valueOf
(
Integer
.
parseInt
(
cumulativeIndoorTempMultiplySecond
,
16
)));
//软件版本
String
softwareVersion
=
valueData
.
substring
(
100
,
104
);
tControllerValuesData
.
setSoftwareVersion
(
softwareVersion
);
//频点
String
freq
=
valueData
.
substring
(
104
,
106
);
tControllerValuesData
.
setFreq
(
freq
);
String
snum
=
valueData
.
substring
(
106
,
108
);
tControllerValuesData
.
setSnum
(
snum
);
return
tControllerValuesData
;
}
}
src/main/java/com/zehong/netty/handler/TcpServerHandler.java
0 → 100644
View file @
86fbb808
package
com
.
zehong
.
netty
.
handler
;
import
com.zehong.enums.MessageTypeEnum
;
import
com.zehong.netty.decode.InformationDecode
;
import
com.zehong.netty.decode.MsgDecode
;
import
com.zehong.utils.HexUtils
;
import
com.zehong.utils.RedisUtil
;
import
io.netty.buffer.ByteBuf
;
import
io.netty.channel.ChannelHandler.Sharable
;
import
io.netty.channel.ChannelHandlerContext
;
import
io.netty.channel.ChannelInboundHandlerAdapter
;
import
io.netty.channel.socket.SocketChannel
;
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.util.Date
;
/**
* @author gengd
* 物联网 开启检测端口 并写入数据库
*/
@Component
@Sharable
public
class
TcpServerHandler
extends
ChannelInboundHandlerAdapter
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
TcpServerHandler
.
class
);
@Autowired
private
RedisUtil
redisUtil
;
@Override
public
void
channelActive
(
ChannelHandlerContext
ctx
)
{
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
){
logger
.
info
(
"客户端断开链接{}"
,
ctx
.
channel
().
localAddress
().
toString
());
}
/**
* 获取数据
* @param ctx 上下文
* @param msg 获取的数据
* @throws UnsupportedEncodingException
*/
@Override
public
void
channelRead
(
ChannelHandlerContext
ctx
,
Object
msg
){
ByteBuf
buf
=
(
ByteBuf
)
msg
;
byte
[]
msgBytes
=
new
byte
[
buf
.
readableBytes
()];
buf
.
readBytes
(
msgBytes
);
//16进制消息字符串
String
msgStr
=
HexUtils
.
bytesToHex
(
msgBytes
);
logger
.
info
(
"tcp上传数据为:"
+
msgStr
);
//解析上传数据
MsgDecode
decode
=
new
MsgDecode
(
msgStr
);
if
(!
MessageTypeEnum
.
READ_DATA_RESPONSE
.
value
.
equals
(
decode
.
getMessageType
())){
logger
.
info
(
"此消息类型不做处理!"
);
return
;
}
if
(!
decode
.
checkCRC32Code
()){
logger
.
error
(
"上传数据校验失败!"
);
return
;
}
//解析信息单元
new
InformationDecode
(
decode
).
infoMsgDecode
();
}
@Override
public
void
exceptionCaught
(
ChannelHandlerContext
ctx
,
Throwable
cause
)
{
logger
.
error
(
"tcp连接报错"
,
cause
);
cause
.
printStackTrace
();
ctx
.
close
();
}
}
src/main/java/com/zehong/service/ITControllerValuesDataService.java
0 → 100644
View file @
86fbb808
package
com
.
zehong
.
service
;
import
com.github.pagehelper.PageInfo
;
import
com.zehong.entity.TControllerValuesData
;
import
java.util.List
;
/**
* 阀控数据Service接口
*
* @author zehong
* @date 2022-05-07
*/
public
interface
ITControllerValuesDataService
{
/**
* 查询阀控数据
*
* @param controllerValueId 阀控数据ID
* @return 阀控数据
*/
TControllerValuesData
selectTControllerValuesDataById
(
Long
controllerValueId
);
/**
* 查询阀控数据列表
*
* @param tControllerValuesData 阀控数据
* @return 阀控数据集合
*/
List
<
TControllerValuesData
>
selectTControllerValuesDataList
(
TControllerValuesData
tControllerValuesData
);
/**
* 查询阀控数据分页列表
*
* @param tControllerValuesData 阀控数据
* @return 阀控数据分页集合
*/
PageInfo
<
TControllerValuesData
>
selectTControllerValuesDataPage
(
TControllerValuesData
tControllerValuesData
);
/**
* 新增阀控数据
*
* @param tControllerValuesData 阀控数据
* @return 结果
*/
int
insertTControllerValuesData
(
TControllerValuesData
tControllerValuesData
);
/**
* 修改阀控数据
*
* @param tControllerValuesData 阀控数据
* @return 结果
*/
int
updateTControllerValuesData
(
TControllerValuesData
tControllerValuesData
);
/**
* 批量删除阀控数据
*
* @param controllerValueIds 需要删除的阀控数据ID
* @return 结果
*/
int
deleteTControllerValuesDataByIds
(
Long
[]
controllerValueIds
);
/**
* 删除阀控数据信息
*
* @param controllerValueId 阀控数据ID
* @return 结果
*/
int
deleteTControllerValuesDataById
(
Long
controllerValueId
);
}
src/main/java/com/zehong/service/ITHeatDataService.java
0 → 100644
View file @
86fbb808
package
com
.
zehong
.
service
;
import
com.zehong.entity.THeatData
;
import
com.github.pagehelper.PageInfo
;
import
java.util.List
;
/**
* 热量数据Service接口
*
* @author zehong
* @date 2022-05-07
*/
public
interface
ITHeatDataService
{
/**
* 查询热量数据
*
* @param heatId 热量数据ID
* @return 热量数据
*/
THeatData
selectTHeatDataById
(
Long
heatId
);
/**
* 查询热量数据列表
*
* @param tHeatData 热量数据
* @return 热量数据集合
*/
List
<
THeatData
>
selectTHeatDataList
(
THeatData
tHeatData
);
/**
* 查询热量数据分页列表
*
* @param tHeatData 热量数据
* @return 热量数据分页集合
*/
PageInfo
<
THeatData
>
selectTHeatDataPage
(
THeatData
tHeatData
);
/**
* 新增热量数据
*
* @param tHeatData 热量数据
* @return 结果
*/
int
insertTHeatData
(
THeatData
tHeatData
);
/**
* 修改热量数据
*
* @param tHeatData 热量数据
* @return 结果
*/
int
updateTHeatData
(
THeatData
tHeatData
);
/**
* 批量删除热量数据
*
* @param heatIds 需要删除的热量数据ID
* @return 结果
*/
int
deleteTHeatDataByIds
(
Long
[]
heatIds
);
/**
* 删除热量数据信息
*
* @param heatId 热量数据ID
* @return 结果
*/
int
deleteTHeatDataById
(
Long
heatId
);
}
src/main/java/com/zehong/service/impl/TControllerValuesDataServiceImpl.java
0 → 100644
View file @
86fbb808
package
com
.
zehong
.
service
.
impl
;
import
cn.hutool.core.date.DateUtil
;
import
com.github.pagehelper.PageInfo
;
import
com.zehong.dao.TControllerValuesDataDao
;
import
com.zehong.entity.TControllerValuesData
;
import
com.zehong.service.ITControllerValuesDataService
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.util.List
;
/**
* 阀控数据Service业务层处理
*
* @author zehong
* @date 2022-05-07
*/
@Service
public
class
TControllerValuesDataServiceImpl
implements
ITControllerValuesDataService
{
@Resource
private
TControllerValuesDataDao
tControllerValuesDataDao
;
/**
* 查询阀控数据
*
* @param controllerValueId 阀控数据ID
* @return 阀控数据
*/
@Override
public
TControllerValuesData
selectTControllerValuesDataById
(
Long
controllerValueId
){
return
tControllerValuesDataDao
.
selectTControllerValuesDataById
(
controllerValueId
);
}
/**
* 查询阀控数据列表
*
* @param tControllerValuesData 阀控数据
* @return 阀控数据
*/
@Override
public
List
<
TControllerValuesData
>
selectTControllerValuesDataList
(
TControllerValuesData
tControllerValuesData
)
{
return
tControllerValuesDataDao
.
selectTControllerValuesDataList
(
tControllerValuesData
);
}
/**
* 查询阀控数据分页列表
*
* @param tControllerValuesData 阀控数据
* @return 阀控数据
*/
@Override
public
PageInfo
<
TControllerValuesData
>
selectTControllerValuesDataPage
(
TControllerValuesData
tControllerValuesData
)
{
return
new
PageInfo
(
tControllerValuesDataDao
.
selectTControllerValuesDataList
(
tControllerValuesData
));
}
/**
* 新增阀控数据
*
* @param tControllerValuesData 阀控数据
* @return 结果
*/
@Override
public
int
insertTControllerValuesData
(
TControllerValuesData
tControllerValuesData
){
tControllerValuesData
.
setCreateTime
(
DateUtil
.
date
());
return
tControllerValuesDataDao
.
insertTControllerValuesData
(
tControllerValuesData
);
}
/**
* 修改阀控数据
*
* @param tControllerValuesData 阀控数据
* @return 结果
*/
@Override
public
int
updateTControllerValuesData
(
TControllerValuesData
tControllerValuesData
){
return
tControllerValuesDataDao
.
updateTControllerValuesData
(
tControllerValuesData
);
}
/**
* 批量删除阀控数据
*
* @param controllerValueIds 需要删除的阀控数据ID
* @return 结果
*/
@Override
public
int
deleteTControllerValuesDataByIds
(
Long
[]
controllerValueIds
){
return
tControllerValuesDataDao
.
deleteTControllerValuesDataByIds
(
controllerValueIds
);
}
/**
* 删除阀控数据信息
*
* @param controllerValueId 阀控数据ID
* @return 结果
*/
@Override
public
int
deleteTControllerValuesDataById
(
Long
controllerValueId
){
return
tControllerValuesDataDao
.
deleteTControllerValuesDataById
(
controllerValueId
);
}
}
src/main/java/com/zehong/service/impl/THeatDataServiceImpl.java
0 → 100644
View file @
86fbb808
package
com
.
zehong
.
service
.
impl
;
import
cn.hutool.core.date.DateUtil
;
import
com.github.pagehelper.PageInfo
;
import
com.zehong.dao.THeatDataDao
;
import
com.zehong.entity.THeatData
;
import
com.zehong.service.ITHeatDataService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.util.List
;
/**
* 热量数据Service业务层处理
*
* @author zehong
* @date 2022-05-07
*/
@Service
public
class
THeatDataServiceImpl
implements
ITHeatDataService
{
@Resource
private
THeatDataDao
tHeatDataDao
;
/**
* 查询热量数据
*
* @param heatId 热量数据ID
* @return 热量数据
*/
@Override
public
THeatData
selectTHeatDataById
(
Long
heatId
){
return
tHeatDataDao
.
selectTHeatDataById
(
heatId
);
}
/**
* 查询热量数据列表
*
* @param tHeatData 热量数据
* @return 热量数据
*/
@Override
public
List
<
THeatData
>
selectTHeatDataList
(
THeatData
tHeatData
){
return
tHeatDataDao
.
selectTHeatDataList
(
tHeatData
);
}
/**
* 查询热量数据分页列表
*
* @param tHeatData 热量数据
* @return 热量数据
*/
@Override
public
PageInfo
<
THeatData
>
selectTHeatDataPage
(
THeatData
tHeatData
)
{
return
new
PageInfo
(
tHeatDataDao
.
selectTHeatDataList
(
tHeatData
));
}
/**
* 新增热量数据
*
* @param tHeatData 热量数据
* @return 结果
*/
@Override
public
int
insertTHeatData
(
THeatData
tHeatData
){
tHeatData
.
setCreateTime
(
DateUtil
.
date
());
return
tHeatDataDao
.
insertTHeatData
(
tHeatData
);
}
/**
* 修改热量数据
*
* @param tHeatData 热量数据
* @return 结果
*/
@Override
public
int
updateTHeatData
(
THeatData
tHeatData
){
return
tHeatDataDao
.
updateTHeatData
(
tHeatData
);
}
/**
* 批量删除热量数据
*
* @param heatIds 需要删除的热量数据ID
* @return 结果
*/
@Override
public
int
deleteTHeatDataByIds
(
Long
[]
heatIds
){
return
tHeatDataDao
.
deleteTHeatDataByIds
(
heatIds
);
}
/**
* 删除热量数据信息
*
* @param heatId 热量数据ID
* @return 结果
*/
@Override
public
int
deleteTHeatDataById
(
Long
heatId
){
return
tHeatDataDao
.
deleteTHeatDataById
(
heatId
);
}
}
src/main/java/com/zehong/utils/DateTimeValueUtil.java
0 → 100644
View file @
86fbb808
package
com
.
zehong
.
utils
;
public
class
DateTimeValueUtil
{
/**
* 时间转换
* @param dateTime 时间
* @return
*/
public
static
String
getDateTimeStr
(
String
dateTime
){
StringBuilder
dateTimeStr
=
new
StringBuilder
(
""
);
dateTimeStr
.
append
(
Integer
.
parseInt
(
dateTime
.
substring
(
0
,
2
),
16
))
.
append
(
Integer
.
parseInt
(
dateTime
.
substring
(
2
,
4
),
16
))
.
append
(
"-"
)
.
append
(
Integer
.
parseInt
(
dateTime
.
substring
(
4
,
6
),
16
))
.
append
(
"-"
)
.
append
(
Integer
.
parseInt
(
dateTime
.
substring
(
6
,
8
),
16
))
.
append
(
" "
)
.
append
(
Integer
.
parseInt
(
dateTime
.
substring
(
8
,
10
),
16
))
.
append
(
":"
)
.
append
(
Integer
.
parseInt
(
dateTime
.
substring
(
10
,
12
),
16
))
.
append
(
":"
)
.
append
(
Integer
.
parseInt
(
dateTime
.
substring
(
12
,
14
),
16
));
return
dateTimeStr
.
toString
();
}
}
src/main/java/com/zehong/utils/HexUtils.java
0 → 100644
View file @
86fbb808
package
com
.
zehong
.
utils
;
import
java.math.BigInteger
;
public
class
HexUtils
{
/**
* 字节转十六进制
* @param b 需要进行转换的byte字节
* @return 转换后的Hex字符串
*/
public
static
String
byteToHex
(
byte
b
){
String
hex
=
Integer
.
toHexString
(
b
&
0xFF
);
if
(
hex
.
length
()
<
2
){
hex
=
"0"
+
hex
;
}
return
hex
;
}
/**
* 字节数组转16进制
* @param bytes 需要转换的byte数组
* @return 转换后的Hex字符串
*/
public
static
String
bytesToHex
(
byte
[]
bytes
)
{
StringBuffer
sb
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
bytes
.
length
;
i
++)
{
String
hex
=
Integer
.
toHexString
(
bytes
[
i
]
&
0xFF
);
if
(
hex
.
length
()
<
2
){
sb
.
append
(
0
);
}
sb
.
append
(
hex
);
}
return
sb
.
toString
();
}
/**
* Hex字符串转byte
* @param inHex 待转换的Hex字符串
* @return 转换后的byte
*/
public
static
byte
hexToByte
(
String
inHex
){
return
(
byte
)
Integer
.
parseInt
(
inHex
,
16
);
}
/**
* hex字符串转byte数组
* @param inHex 待转换的Hex字符串
* @return 转换后的byte数组结果
*/
public
static
byte
[]
hexToByteArray
(
String
inHex
){
int
hexlen
=
inHex
.
length
();
byte
[]
result
;
if
(
hexlen
%
2
==
1
){
//奇数
hexlen
++;
result
=
new
byte
[(
hexlen
/
2
)];
inHex
=
"0"
+
inHex
;
}
else
{
//偶数
result
=
new
byte
[(
hexlen
/
2
)];
}
int
j
=
0
;
for
(
int
i
=
0
;
i
<
hexlen
;
i
+=
2
){
result
[
j
]=
hexToByte
(
inHex
.
substring
(
i
,
i
+
2
));
j
++;
}
return
result
;
}
/**
* 十六进制转单浮点
* @param hex
* @return
*/
public
static
float
hexToFloat
(
String
hex
){
//Integer i = Integer.valueOf(hex.trim(), 16);
//return Float.intBitsToFloat(i);
return
Float
.
intBitsToFloat
(
new
BigInteger
(
hex
.
trim
(),
16
).
intValue
());
}
/**
* 十六进制转浮点
* @param hex
* @return
*/
public
static
double
hexToDouble
(
String
hex
){
Long
l
=
Long
.
valueOf
(
hex
,
16
).
longValue
();
return
Double
.
longBitsToDouble
(
l
);
}
/**
* 十六进制转二进制
* @param hex
* @return
*/
public
static
String
hexToBinary
(
String
hex
){
Integer
num
=
Integer
.
parseInt
(
hex
,
16
);
return
Integer
.
toBinaryString
(
num
);
}
}
src/main/java/com/zehong/utils/NettyClient.java
0 → 100644
View file @
86fbb808
package
com
.
zehong
.
utils
;
import
com.zehong.utils.client.NettyClientHandler
;
import
io.netty.bootstrap.Bootstrap
;
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.NioSocketChannel
;
import
io.netty.handler.codec.string.StringDecoder
;
import
io.netty.handler.codec.string.StringEncoder
;
import
lombok.extern.slf4j.Slf4j
;
/**
* @author gengd
* netty客户端
*/
@Slf4j
public
class
NettyClient
{
/**
* 创建netty客户端并发送信息
* @param msg 发送消息
* @param host 地址
* @param port 端口
*/
public
static
String
nettyConnection
(
String
msg
,
String
host
,
int
port
)
{
NettyClientHandler
nettyClientHandler
=
new
NettyClientHandler
();
EventLoopGroup
group
=
new
NioEventLoopGroup
();
Bootstrap
bootstrap
=
new
Bootstrap
()
.
group
(
group
)
//该参数的作用就是禁止使用Nagle算法,使用于小数据即时传输
.
option
(
ChannelOption
.
TCP_NODELAY
,
true
)
.
channel
(
NioSocketChannel
.
class
)
.
handler
(
new
ChannelInitializer
<
SocketChannel
>()
{
@Override
protected
void
initChannel
(
SocketChannel
socketChannel
)
throws
Exception
{
socketChannel
.
pipeline
().
addLast
(
"decoder"
,
new
StringDecoder
());
socketChannel
.
pipeline
().
addLast
(
"encoder"
,
new
StringEncoder
());
socketChannel
.
pipeline
().
addLast
(
nettyClientHandler
);
}
});
try
{
ChannelFuture
future
=
bootstrap
.
connect
(
host
,
port
).
sync
();
log
.
info
(
"客户端发送成功...."
);
//发送消息
future
.
channel
().
writeAndFlush
(
msg
);
// 等待连接被关闭
future
.
channel
().
closeFuture
().
sync
();
return
nettyClientHandler
.
getResponseMsg
();
}
catch
(
Exception
e
)
{
log
.
error
(
"客户端Netty失败"
,
e
);
}
finally
{
//以一种优雅的方式进行线程退出
group
.
shutdownGracefully
();
}
return
null
;
}
}
src/main/java/com/zehong/utils/RedisUtil.java
0 → 100644
View file @
86fbb808
package
com
.
zehong
.
utils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.CollectionUtils
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.concurrent.TimeUnit
;
@Component
public
class
RedisUtil
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
RedisUtil
.
class
);
@Autowired
private
RedisTemplate
<
String
,
Object
>
redisTemplate
;
public
RedisUtil
(
RedisTemplate
<
String
,
Object
>
redisTemplate
)
{
this
.
redisTemplate
=
redisTemplate
;
}
/**
* 指定缓存失效时间
* @param key 键
* @param time 时间(秒)
* @return
*/
public
boolean
expire
(
String
key
,
long
time
){
try
{
if
(
time
>
0
){
redisTemplate
.
expire
(
key
,
time
,
TimeUnit
.
SECONDS
);
}
return
true
;
}
catch
(
Exception
e
)
{
logger
.
error
(
"redis expire报错:"
+
e
);
return
false
;
}
}
/**
* 根据key 获取过期时间
* @param key 键 不能为null
* @return 时间(秒) 返回0代表为永久有效
*/
public
long
getExpire
(
String
key
){
return
redisTemplate
.
getExpire
(
key
,
TimeUnit
.
SECONDS
);
}
/**
* 判断key是否存在
* @param key 键
* @return true 存在 false不存在
*/
public
boolean
hasKey
(
String
key
){
try
{
return
redisTemplate
.
hasKey
(
key
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"redis hashKey出错:"
+
e
);
return
false
;
}
}
/**
* 删除缓存
* @param key 可以传一个值 或多个
*/
@SuppressWarnings
(
"unchecked"
)
public
void
del
(
String
...
key
){
if
(
key
!=
null
&&
key
.
length
>
0
){
if
(
key
.
length
==
1
){
redisTemplate
.
delete
(
key
[
0
]);
}
else
{
redisTemplate
.
delete
((
Collection
<
String
>)
CollectionUtils
.
arrayToList
(
key
));
}
}
}
//============================String=============================
/**
* 普通缓存获取
* @param key 键
* @return 值
*/
public
Object
get
(
String
key
){
return
key
==
null
?
null
:
redisTemplate
.
opsForValue
().
get
(
key
);
}
/**
* 普通缓存放入
* @param key 键
* @param value 值
* @return true成功 false失败
*/
public
boolean
set
(
String
key
,
Object
value
)
{
try
{
redisTemplate
.
opsForValue
().
set
(
key
,
value
);
return
true
;
}
catch
(
Exception
e
)
{
logger
.
error
(
"redis set出错:"
+
e
);
return
false
;
}
}
/**
* 普通缓存放入并设置时间
* @param key 键
* @param value 值
* @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期
* @return true成功 false 失败
*/
public
boolean
set
(
String
key
,
Object
value
,
long
time
){
try
{
if
(
time
>
0
){
redisTemplate
.
opsForValue
().
set
(
key
,
value
,
time
,
TimeUnit
.
SECONDS
);
}
else
{
set
(
key
,
value
);
}
return
true
;
}
catch
(
Exception
e
)
{
logger
.
error
(
"redis set 带时间戳报错:"
+
e
);
return
false
;
}
}
/**
* 递增
* @param key 键
* @param delta 要增加几(大于0)
* @return
*/
public
long
incr
(
String
key
,
long
delta
){
if
(
delta
<
0
){
throw
new
RuntimeException
(
"递增因子必须大于0"
);
}
return
redisTemplate
.
opsForValue
().
increment
(
key
,
delta
);
}
/**
* 递减
* @param key 键
* @param delta 要减少几(小于0)
* @return
*/
public
long
decr
(
String
key
,
long
delta
){
if
(
delta
<
0
){
throw
new
RuntimeException
(
"递减因子必须大于0"
);
}
return
redisTemplate
.
opsForValue
().
increment
(
key
,
-
delta
);
}
//================================Map=================================
/**
* HashGet
* @param key 键 不能为null
* @param item 项 不能为null
* @return 值
*/
public
Object
hget
(
String
key
,
String
item
){
return
redisTemplate
.
opsForHash
().
get
(
key
,
item
);
}
/**
* 获取hashKey对应的所有键值
* @param key 键
* @return 对应的多个键值
*/
public
Map
<
Object
,
Object
>
hmget
(
String
key
){
return
redisTemplate
.
opsForHash
().
entries
(
key
);
}
/**
* HashSet
* @param key 键
* @param map 对应多个键值
* @return true 成功 false 失败
*/
public
boolean
hmset
(
String
key
,
Map
<
String
,
Object
>
map
){
try
{
redisTemplate
.
opsForHash
().
putAll
(
key
,
map
);
return
true
;
}
catch
(
Exception
e
)
{
logger
.
error
(
"redis hmset出错:"
+
e
);
return
false
;
}
}
/**
* HashSet 并设置时间
* @param key 键
* @param map 对应多个键值
* @param time 时间(秒)
* @return true成功 false失败
*/
public
boolean
hmset
(
String
key
,
Map
<
String
,
Object
>
map
,
long
time
){
try
{
redisTemplate
.
opsForHash
().
putAll
(
key
,
map
);
if
(
time
>
0
){
expire
(
key
,
time
);
}
return
true
;
}
catch
(
Exception
e
)
{
logger
.
error
(
"redis hmset带时间戳报错:"
+
e
);
return
false
;
}
}
/**
* 向一张hash表中放入数据,如果不存在将创建
* @param key 键
* @param item 项
* @param value 值
* @return true 成功 false失败
*/
public
boolean
hset
(
String
key
,
String
item
,
Object
value
)
{
try
{
redisTemplate
.
opsForHash
().
put
(
key
,
item
,
value
);
return
true
;
}
catch
(
Exception
e
)
{
logger
.
error
(
"redis hset出错:"
+
e
);
return
false
;
}
}
/**
* 向一张hash表中放入数据,如果不存在将创建
* @param key 键
* @param item 项
* @param value 值
* @param time 时间(秒) 注意:如果已存在的hash表有时间,这里将会替换原有的时间
* @return true 成功 false失败
*/
public
boolean
hset
(
String
key
,
String
item
,
Object
value
,
long
time
)
{
try
{
redisTemplate
.
opsForHash
().
put
(
key
,
item
,
value
);
if
(
time
>
0
){
expire
(
key
,
time
);
}
return
true
;
}
catch
(
Exception
e
)
{
logger
.
error
(
"redis hset带时间戳报错:"
+
e
);
return
false
;
}
}
/**
* 删除hash表中的值
* @param key 键 不能为null
* @param item 项 可以使多个 不能为null
*/
public
void
hdel
(
String
key
,
Object
...
item
){
redisTemplate
.
opsForHash
().
delete
(
key
,
item
);
}
/**
* 判断hash表中是否有该项的值
* @param key 键 不能为null
* @param item 项 不能为null
* @return true 存在 false不存在
*/
public
boolean
hHasKey
(
String
key
,
String
item
){
return
redisTemplate
.
opsForHash
().
hasKey
(
key
,
item
);
}
/**
* hash递增 如果不存在,就会创建一个 并把新增后的值返回
* @param key 键
* @param item 项
* @param by 要增加几(大于0)
* @return
*/
public
double
hincr
(
String
key
,
String
item
,
double
by
){
return
redisTemplate
.
opsForHash
().
increment
(
key
,
item
,
by
);
}
/**
* hash递减
* @param key 键
* @param item 项
* @param by 要减少记(小于0)
* @return
*/
public
double
hdecr
(
String
key
,
String
item
,
double
by
){
return
redisTemplate
.
opsForHash
().
increment
(
key
,
item
,-
by
);
}
//============================set=============================
/**
* 根据key获取Set中的所有值
* @param key 键
* @return
*/
public
Set
<
Object
>
sGet
(
String
key
){
try
{
return
redisTemplate
.
opsForSet
().
members
(
key
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"redis sGet报错:"
+
e
);
return
null
;
}
}
/**
* 根据value从一个set中查询,是否存在
* @param key 键
* @param value 值
* @return true 存在 false不存在
*/
public
boolean
sHasKey
(
String
key
,
Object
value
){
try
{
return
redisTemplate
.
opsForSet
().
isMember
(
key
,
value
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"redis sHasKey报错:"
+
e
);
return
false
;
}
}
/**
* 将数据放入set缓存
* @param key 键
* @param values 值 可以是多个
* @return 成功个数
*/
public
long
sSet
(
String
key
,
Object
...
values
)
{
try
{
return
redisTemplate
.
opsForSet
().
add
(
key
,
values
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"redis sSet报错:"
+
e
);
return
0
;
}
}
/**
* 将set数据放入缓存
* @param key 键
* @param time 时间(秒)
* @param values 值 可以是多个
* @return 成功个数
*/
public
long
sSetAndTime
(
String
key
,
long
time
,
Object
...
values
)
{
try
{
Long
count
=
redisTemplate
.
opsForSet
().
add
(
key
,
values
);
if
(
time
>
0
)
{
expire
(
key
,
time
);
}
return
count
;
}
catch
(
Exception
e
)
{
logger
.
error
(
"redis sSetAndTime:"
+
e
);
return
0
;
}
}
/**
* 获取set缓存的长度
* @param key 键
* @return
*/
public
long
sGetSetSize
(
String
key
){
try
{
return
redisTemplate
.
opsForSet
().
size
(
key
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"redis sGetSetSize:"
+
e
);
return
0
;
}
}
/**
* 移除值为value的
* @param key 键
* @param values 值 可以是多个
* @return 移除的个数
*/
public
long
setRemove
(
String
key
,
Object
...
values
)
{
try
{
Long
count
=
redisTemplate
.
opsForSet
().
remove
(
key
,
values
);
return
count
;
}
catch
(
Exception
e
)
{
logger
.
error
(
"redis setRemove:"
+
e
);
return
0
;
}
}
//===============================list=================================
/**
* 获取list缓存的内容
* @param key 键
* @param start 开始
* @param end 结束 0 到 -1代表所有值
* @return
*/
public
List
<
Object
>
lGet
(
String
key
,
long
start
,
long
end
){
try
{
return
redisTemplate
.
opsForList
().
range
(
key
,
start
,
end
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"redis lGet:"
+
e
);
return
null
;
}
}
/**
* 获取list缓存的长度
* @param key 键
* @return
*/
public
long
lGetListSize
(
String
key
){
try
{
return
redisTemplate
.
opsForList
().
size
(
key
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"redis lGetListSize:"
+
e
);
return
0
;
}
}
/**
* 通过索引 获取list中的值
* @param key 键
* @param index 索引 index>=0时, 0 表头,1 第二个元素,依次类推;index<0时,-1,表尾,-2倒数第二个元素,依次类推
* @return
*/
public
Object
lGetIndex
(
String
key
,
long
index
){
try
{
return
redisTemplate
.
opsForList
().
index
(
key
,
index
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"redis lGetIndex:"
+
e
);
return
null
;
}
}
/**
* 将list放入缓存
* @param key 键
* @param value 值
* @return
*/
public
boolean
lSet
(
String
key
,
Object
value
)
{
try
{
redisTemplate
.
opsForList
().
rightPush
(
key
,
value
);
return
true
;
}
catch
(
Exception
e
)
{
logger
.
error
(
"redis lSet:"
+
e
);
return
false
;
}
}
/**
* 将list放入缓存
* @param key 键
* @param value 值
* @param time 时间(秒)
* @return
*/
public
boolean
lSet
(
String
key
,
Object
value
,
long
time
)
{
try
{
redisTemplate
.
opsForList
().
rightPush
(
key
,
value
);
if
(
time
>
0
)
{
expire
(
key
,
time
);
}
return
true
;
}
catch
(
Exception
e
)
{
logger
.
error
(
"redis lSet 带时间戳:"
+
e
);
return
false
;
}
}
/**
* 将list放入缓存
* @param key 键
* @param value 值
* @return
*/
public
boolean
lSet
(
String
key
,
List
<
Object
>
value
)
{
try
{
redisTemplate
.
opsForList
().
rightPushAll
(
key
,
value
);
return
true
;
}
catch
(
Exception
e
)
{
logger
.
error
(
"redis lSet:"
+
e
);
return
false
;
}
}
/**
* 将list放入缓存
* @param key 键
* @param value 值
* @param time 时间(秒)
* @return
*/
public
boolean
lSet
(
String
key
,
List
<
Object
>
value
,
long
time
)
{
try
{
redisTemplate
.
opsForList
().
rightPushAll
(
key
,
value
);
if
(
time
>
0
)
{
expire
(
key
,
time
);
}
return
true
;
}
catch
(
Exception
e
)
{
logger
.
error
(
"redis lSet:"
+
e
);
return
false
;
}
}
/**
* 根据索引修改list中的某条数据
* @param key 键
* @param index 索引
* @param value 值
* @return
*/
public
boolean
lUpdateIndex
(
String
key
,
long
index
,
Object
value
)
{
try
{
redisTemplate
.
opsForList
().
set
(
key
,
index
,
value
);
return
true
;
}
catch
(
Exception
e
)
{
logger
.
error
(
"redis lUpdateIndex:"
+
e
);
return
false
;
}
}
/**
* 移除N个值为value
* @param key 键
* @param count 移除多少个
* @param value 值
* @return 移除的个数
*/
public
long
lRemove
(
String
key
,
long
count
,
Object
value
)
{
try
{
Long
remove
=
redisTemplate
.
opsForList
().
remove
(
key
,
count
,
value
);
return
remove
;
}
catch
(
Exception
e
)
{
logger
.
error
(
"redis lRemove:"
+
e
);
return
0
;
}
}
public
Set
keys
(
String
pattern
){
return
redisTemplate
.
keys
(
pattern
);
}
}
src/main/java/com/zehong/utils/SpringUtil.java
0 → 100644
View file @
86fbb808
package
com
.
zehong
.
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
);
}
}
src/main/java/com/zehong/utils/client/NettyClientHandler.java
0 → 100644
View file @
86fbb808
package
com
.
zehong
.
utils
.
client
;
import
io.netty.channel.ChannelHandlerContext
;
import
io.netty.channel.ChannelInboundHandlerAdapter
;
import
lombok.extern.slf4j.Slf4j
;
@Slf4j
public
class
NettyClientHandler
extends
ChannelInboundHandlerAdapter
{
/**
* 接收服务器返回信息
*/
private
String
responseMsg
;
public
String
getResponseMsg
()
{
return
responseMsg
;
}
@Override
public
void
channelActive
(
ChannelHandlerContext
ctx
)
throws
Exception
{
log
.
info
(
"客户端Active ....."
);
}
@Override
public
void
channelRead
(
ChannelHandlerContext
ctx
,
Object
msg
)
throws
Exception
{
log
.
info
(
"客户端收到消息: {}"
,
msg
.
toString
());
//自定义返回体
this
.
responseMsg
=
msg
.
toString
();
ctx
.
close
();
}
@Override
public
void
exceptionCaught
(
ChannelHandlerContext
ctx
,
Throwable
cause
)
throws
Exception
{
log
.
error
(
"netty 客户端发生错误:"
+
cause
);
ctx
.
close
();
}
}
src/main/resources/application-prd.yml
0 → 100644
View file @
86fbb808
src/main/resources/application-test.yml
0 → 100644
View file @
86fbb808
# logging path
logging
:
file
:
path
:
./logs
#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
# redis 配置
redis
:
# 地址
host
:
36.148.23.59
# 端口,默认为6379
port
:
6379
# 数据库索引
database
:
6
# 密码
password
:
1qaz2wsx3edc
# 连接超时时间
timeout
:
10s
lettuce
:
pool
:
# 连接池中的最小空闲连接
min-idle
:
0
# 连接池中的最大空闲连接
max-idle
:
8
# 连接池的最大数据库连接数
max-active
:
8
# #连接池最大阻塞等待时间(使用负值表示没有限制)
max-wait
:
-1ms
TCPNetty
:
ports
:
2496
# 分包消息接收确认
confirmClient
:
host
:
127.0.0.1
port
:
8082
src/main/resources/application.yml
0 → 100644
View file @
86fbb808
server
:
port
:
8079
servlet
:
context-path
:
/supplyHeatDeviceDataCollection
spring
:
profiles
:
active
:
test
\ No newline at end of file
src/main/resources/logback-spring.xml
0 → 100644
View file @
86fbb808
<?xml version="1.0" encoding="UTF-8"?>
<configuration
scan=
"true"
scanPeriod=
"60 seconds"
debug=
"true"
>
<conversionRule
conversionWord=
"clr"
converterClass=
"org.springframework.boot.logging.logback.ColorConverter"
/>
<conversionRule
conversionWord=
"wex"
converterClass=
"org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter"
/>
<conversionRule
conversionWord=
"wEx"
converterClass=
"org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter"
/>
<property
name=
"CONSOLE_LOG_PATTERN"
value=
"${CONSOLE_LOG_PATTERN:-%clr(%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}}){faint} %clr(%X{TRANCE_ID:-}) %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"
/>
<property
name=
"FILE_LOG_PATTERN"
value=
"${FILE_LOG_PATTERN:-%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}} %X{TRANCE_ID:-} ${LOG_LEVEL_PATTERN:-%5p} ${PID:- } --- [%t] %-40.40logger{39} : %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"
/>
<property
name=
"LOG_FILE"
value=
"supplyheatdevicedatacollection.log"
/>
<!-- 控制台输出配置 -->
<appender
name=
"CONSOLE"
class=
"ch.qos.logback.core.ConsoleAppender"
>
<encoder>
<pattern>
${CONSOLE_LOG_PATTERN}
</pattern>
</encoder>
</appender>
<!-- 文件输出配置 -->
<appender
name=
"FILE"
class=
"ch.qos.logback.core.rolling.RollingFileAppender"
>
<encoder>
<pattern>
${FILE_LOG_PATTERN}
</pattern>
</encoder>
<file>
${LOG_PATH}/${LOG_FILE}
</file>
<rollingPolicy
class=
"ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"
>
<!-- 分片格式以及压缩设置 -->
<fileNamePattern>
${LOG_PATH}/${LOG_FILE}.%d{yyyy-MM-dd}.%i.gz
</fileNamePattern>
<!-- 单个分片文件大小,默认是10M(压缩前) -->
<maxFileSize>
${LOG_FILE_MAX_SIZE:-10MB}
</maxFileSize>
<!-- 日志保存的最大时间,默认是永久保存 -->
<maxHistory>
${LOG_FILE_MAX_HISTORY:-30}
</maxHistory>
</rollingPolicy>
</appender>
<root
level=
"INFO"
>
<appender-ref
ref=
"CONSOLE"
/>
<appender-ref
ref=
"FILE"
/>
</root>
</configuration>
\ No newline at end of file
src/main/resources/mapper/TControllerValuesDataMapper.xml
0 → 100644
View file @
86fbb808
<?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.entity.TControllerValuesData"
>
<resultMap
type=
"TControllerValuesData"
id=
"TControllerValuesDataResult"
>
<result
property=
"controllerValueId"
column=
"controller_value_id"
/>
<result
property=
"manufacturersId"
column=
"manufacturers_id"
/>
<result
property=
"equipmentTypeValue"
column=
"equipment_type_value"
/>
<result
property=
"valueId"
column=
"value_id"
/>
<result
property=
"protocolType"
column=
"protocol_type"
/>
<result
property=
"valveOperateType"
column=
"valve_operate_type"
/>
<result
property=
"lowControlTemperatureRange"
column=
"low_control_temperature_range"
/>
<result
property=
"highControlTemperatureRange"
column=
"high_control_temperature_range"
/>
<result
property=
"indoorTemperatureReportMaxTimer"
column=
"indoor_temperature_report_max_timer"
/>
<result
property=
"controlTemperature"
column=
"control_temperature"
/>
<result
property=
"indoorTemperature"
column=
"indoor_temperature"
/>
<result
property=
"openedPercent"
column=
"opened_percent"
/>
<result
property=
"preventFrozenFlag"
column=
"prevent_frozen_flag"
/>
<result
property=
"communicateType"
column=
"communicate_type"
/>
<result
property=
"valvePowerStyle"
column=
"valve_power_style"
/>
<result
property=
"panelPowerTyle"
column=
"panel_power_tyle"
/>
<result
property=
"pairingStatus"
column=
"pairing_status"
/>
<result
property=
"cumulativeOpenedTime"
column=
"cumulative_opened_time"
/>
<result
property=
"cumulativeWorkingTime"
column=
"cumulative_working_time"
/>
<result
property=
"dateTimeValue"
column=
"date_time_value"
/>
<result
property=
"status"
column=
"status"
/>
<result
property=
"cumulativeOpenAndCloseTimes"
column=
"cumulative_open_and_close_times"
/>
<result
property=
"cumulativeIndoorTempMultiplySecond"
column=
"cumulative_indoor_temp_multiply_second"
/>
<result
property=
"softwareVersion"
column=
"software_version"
/>
<result
property=
"freq"
column=
"freq"
/>
<result
property=
"snum"
column=
"snum"
/>
<result
property=
"createTime"
column=
"create_time"
/>
</resultMap>
<sql
id=
"selectTControllerValuesDataVo"
>
select controller_value_id, manufacturers_id, equipment_type_value, value_id, protocol_type, valve_operate_type, low_control_temperature_range, high_control_temperature_range, indoor_temperature_report_max_timer, control_temperature, indoor_temperature, opened_percent, prevent_frozen_flag, communicate_type, valve_power_style, panel_power_tyle, pairing_status, cumulative_opened_time, cumulative_working_time, date_time_value, status, cumulative_open_and_close_times, cumulative_indoor_temp_multiply_second, software_version, freq, snum, create_time from t_controller_values_data
</sql>
<select
id=
"selectTControllerValuesDataList"
parameterType=
"TControllerValuesData"
resultMap=
"TControllerValuesDataResult"
>
<include
refid=
"selectTControllerValuesDataVo"
/>
<where>
<if
test=
"manufacturersId != null and manufacturersId != ''"
>
and manufacturers_id = #{manufacturersId}
</if>
<if
test=
"equipmentTypeValue != null and equipmentTypeValue != ''"
>
and equipment_type_value = #{equipmentTypeValue}
</if>
<if
test=
"valueId != null and valueId != ''"
>
and value_id = #{valueId}
</if>
<if
test=
"protocolType != null and protocolType != ''"
>
and protocol_type = #{protocolType}
</if>
<if
test=
"valveOperateType != null and valveOperateType != ''"
>
and valve_operate_type = #{valveOperateType}
</if>
<if
test=
"lowControlTemperatureRange != null "
>
and low_control_temperature_range = #{lowControlTemperatureRange}
</if>
<if
test=
"highControlTemperatureRange != null "
>
and high_control_temperature_range = #{highControlTemperatureRange}
</if>
<if
test=
"indoorTemperatureReportMaxTimer != null and indoorTemperatureReportMaxTimer != ''"
>
and indoor_temperature_report_max_timer = #{indoorTemperatureReportMaxTimer}
</if>
<if
test=
"controlTemperature != null "
>
and control_temperature = #{controlTemperature}
</if>
<if
test=
"indoorTemperature != null "
>
and indoor_temperature = #{indoorTemperature}
</if>
<if
test=
"openedPercent != null and openedPercent != ''"
>
and opened_percent = #{openedPercent}
</if>
<if
test=
"preventFrozenFlag != null and preventFrozenFlag != ''"
>
and prevent_frozen_flag = #{preventFrozenFlag}
</if>
<if
test=
"communicateType != null and communicateType != ''"
>
and communicate_type = #{communicateType}
</if>
<if
test=
"valvePowerStyle != null and valvePowerStyle != ''"
>
and valve_power_style = #{valvePowerStyle}
</if>
<if
test=
"panelPowerTyle != null and panelPowerTyle != ''"
>
and panel_power_tyle = #{panelPowerTyle}
</if>
<if
test=
"pairingStatus != null and pairingStatus != ''"
>
and pairing_status = #{pairingStatus}
</if>
<if
test=
"cumulativeOpenedTime != null and cumulativeOpenedTime != ''"
>
and cumulative_opened_time = #{cumulativeOpenedTime}
</if>
<if
test=
"cumulativeWorkingTime != null and cumulativeWorkingTime != ''"
>
and cumulative_working_time = #{cumulativeWorkingTime}
</if>
<if
test=
"dateTimeValue != null "
>
and date_time_value = #{dateTimeValue}
</if>
<if
test=
"status != null and status != ''"
>
and status = #{status}
</if>
<if
test=
"cumulativeOpenAndCloseTimes != null and cumulativeOpenAndCloseTimes != ''"
>
and cumulative_open_and_close_times = #{cumulativeOpenAndCloseTimes}
</if>
<if
test=
"cumulativeIndoorTempMultiplySecond != null and cumulativeIndoorTempMultiplySecond != ''"
>
and cumulative_indoor_temp_multiply_second = #{cumulativeIndoorTempMultiplySecond}
</if>
<if
test=
"softwareVersion != null and softwareVersion != ''"
>
and software_version = #{softwareVersion}
</if>
<if
test=
"freq != null and freq != ''"
>
and freq = #{freq}
</if>
<if
test=
"snum != null and snum != ''"
>
and snum = #{snum}
</if>
</where>
</select>
<select
id=
"selectTControllerValuesDataById"
parameterType=
"Long"
resultMap=
"TControllerValuesDataResult"
>
<include
refid=
"selectTControllerValuesDataVo"
/>
where controller_value_id = #{controllerValueId}
</select>
<insert
id=
"insertTControllerValuesData"
parameterType=
"TControllerValuesData"
useGeneratedKeys=
"true"
keyProperty=
"controllerValueId"
>
insert into t_controller_values_data
<trim
prefix=
"("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"manufacturersId != null"
>
manufacturers_id,
</if>
<if
test=
"equipmentTypeValue != null"
>
equipment_type_value,
</if>
<if
test=
"valueId != null"
>
value_id,
</if>
<if
test=
"protocolType != null"
>
protocol_type,
</if>
<if
test=
"valveOperateType != null"
>
valve_operate_type,
</if>
<if
test=
"lowControlTemperatureRange != null"
>
low_control_temperature_range,
</if>
<if
test=
"highControlTemperatureRange != null"
>
high_control_temperature_range,
</if>
<if
test=
"indoorTemperatureReportMaxTimer != null"
>
indoor_temperature_report_max_timer,
</if>
<if
test=
"controlTemperature != null"
>
control_temperature,
</if>
<if
test=
"indoorTemperature != null"
>
indoor_temperature,
</if>
<if
test=
"openedPercent != null"
>
opened_percent,
</if>
<if
test=
"preventFrozenFlag != null"
>
prevent_frozen_flag,
</if>
<if
test=
"communicateType != null"
>
communicate_type,
</if>
<if
test=
"valvePowerStyle != null"
>
valve_power_style,
</if>
<if
test=
"panelPowerTyle != null"
>
panel_power_tyle,
</if>
<if
test=
"pairingStatus != null"
>
pairing_status,
</if>
<if
test=
"cumulativeOpenedTime != null"
>
cumulative_opened_time,
</if>
<if
test=
"cumulativeWorkingTime != null"
>
cumulative_working_time,
</if>
<if
test=
"dateTimeValue != null"
>
date_time_value,
</if>
<if
test=
"status != null"
>
status,
</if>
<if
test=
"cumulativeOpenAndCloseTimes != null"
>
cumulative_open_and_close_times,
</if>
<if
test=
"cumulativeIndoorTempMultiplySecond != null"
>
cumulative_indoor_temp_multiply_second,
</if>
<if
test=
"softwareVersion != null"
>
software_version,
</if>
<if
test=
"freq != null"
>
freq,
</if>
<if
test=
"snum != null"
>
snum,
</if>
<if
test=
"createTime != null"
>
create_time,
</if>
</trim>
<trim
prefix=
"values ("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"manufacturersId != null"
>
#{manufacturersId},
</if>
<if
test=
"equipmentTypeValue != null"
>
#{equipmentTypeValue},
</if>
<if
test=
"valueId != null"
>
#{valueId},
</if>
<if
test=
"protocolType != null"
>
#{protocolType},
</if>
<if
test=
"valveOperateType != null"
>
#{valveOperateType},
</if>
<if
test=
"lowControlTemperatureRange != null"
>
#{lowControlTemperatureRange},
</if>
<if
test=
"highControlTemperatureRange != null"
>
#{highControlTemperatureRange},
</if>
<if
test=
"indoorTemperatureReportMaxTimer != null"
>
#{indoorTemperatureReportMaxTimer},
</if>
<if
test=
"controlTemperature != null"
>
#{controlTemperature},
</if>
<if
test=
"indoorTemperature != null"
>
#{indoorTemperature},
</if>
<if
test=
"openedPercent != null"
>
#{openedPercent},
</if>
<if
test=
"preventFrozenFlag != null"
>
#{preventFrozenFlag},
</if>
<if
test=
"communicateType != null"
>
#{communicateType},
</if>
<if
test=
"valvePowerStyle != null"
>
#{valvePowerStyle},
</if>
<if
test=
"panelPowerTyle != null"
>
#{panelPowerTyle},
</if>
<if
test=
"pairingStatus != null"
>
#{pairingStatus},
</if>
<if
test=
"cumulativeOpenedTime != null"
>
#{cumulativeOpenedTime},
</if>
<if
test=
"cumulativeWorkingTime != null"
>
#{cumulativeWorkingTime},
</if>
<if
test=
"dateTimeValue != null"
>
#{dateTimeValue},
</if>
<if
test=
"status != null"
>
#{status},
</if>
<if
test=
"cumulativeOpenAndCloseTimes != null"
>
#{cumulativeOpenAndCloseTimes},
</if>
<if
test=
"cumulativeIndoorTempMultiplySecond != null"
>
#{cumulativeIndoorTempMultiplySecond},
</if>
<if
test=
"softwareVersion != null"
>
#{softwareVersion},
</if>
<if
test=
"freq != null"
>
#{freq},
</if>
<if
test=
"snum != null"
>
#{snum},
</if>
<if
test=
"createTime != null"
>
#{createTime},
</if>
</trim>
</insert>
<update
id=
"updateTControllerValuesData"
parameterType=
"TControllerValuesData"
>
update t_controller_values_data
<trim
prefix=
"SET"
suffixOverrides=
","
>
<if
test=
"manufacturersId != null"
>
manufacturers_id = #{manufacturersId},
</if>
<if
test=
"equipmentTypeValue != null"
>
equipment_type_value = #{equipmentTypeValue},
</if>
<if
test=
"valueId != null"
>
value_id = #{valueId},
</if>
<if
test=
"protocolType != null"
>
protocol_type = #{protocolType},
</if>
<if
test=
"valveOperateType != null"
>
valve_operate_type = #{valveOperateType},
</if>
<if
test=
"lowControlTemperatureRange != null"
>
low_control_temperature_range = #{lowControlTemperatureRange},
</if>
<if
test=
"highControlTemperatureRange != null"
>
high_control_temperature_range = #{highControlTemperatureRange},
</if>
<if
test=
"indoorTemperatureReportMaxTimer != null"
>
indoor_temperature_report_max_timer = #{indoorTemperatureReportMaxTimer},
</if>
<if
test=
"controlTemperature != null"
>
control_temperature = #{controlTemperature},
</if>
<if
test=
"indoorTemperature != null"
>
indoor_temperature = #{indoorTemperature},
</if>
<if
test=
"openedPercent != null"
>
opened_percent = #{openedPercent},
</if>
<if
test=
"preventFrozenFlag != null"
>
prevent_frozen_flag = #{preventFrozenFlag},
</if>
<if
test=
"communicateType != null"
>
communicate_type = #{communicateType},
</if>
<if
test=
"valvePowerStyle != null"
>
valve_power_style = #{valvePowerStyle},
</if>
<if
test=
"panelPowerTyle != null"
>
panel_power_tyle = #{panelPowerTyle},
</if>
<if
test=
"pairingStatus != null"
>
pairing_status = #{pairingStatus},
</if>
<if
test=
"cumulativeOpenedTime != null"
>
cumulative_opened_time = #{cumulativeOpenedTime},
</if>
<if
test=
"cumulativeWorkingTime != null"
>
cumulative_working_time = #{cumulativeWorkingTime},
</if>
<if
test=
"dateTimeValue != null"
>
date_time_value = #{dateTimeValue},
</if>
<if
test=
"status != null"
>
status = #{status},
</if>
<if
test=
"cumulativeOpenAndCloseTimes != null"
>
cumulative_open_and_close_times = #{cumulativeOpenAndCloseTimes},
</if>
<if
test=
"cumulativeIndoorTempMultiplySecond != null"
>
cumulative_indoor_temp_multiply_second = #{cumulativeIndoorTempMultiplySecond},
</if>
<if
test=
"softwareVersion != null"
>
software_version = #{softwareVersion},
</if>
<if
test=
"freq != null"
>
freq = #{freq},
</if>
<if
test=
"snum != null"
>
snum = #{snum},
</if>
<if
test=
"createTime != null"
>
create_time = #{createTime},
</if>
</trim>
where controller_value_id = #{controllerValueId}
</update>
<delete
id=
"deleteTControllerValuesDataById"
parameterType=
"Long"
>
delete from t_controller_values_data where controller_value_id = #{controllerValueId}
</delete>
<delete
id=
"deleteTControllerValuesDataByIds"
parameterType=
"String"
>
delete from t_controller_values_data where controller_value_id in
<foreach
item=
"controllerValueId"
collection=
"array"
open=
"("
separator=
","
close=
")"
>
#{controllerValueId}
</foreach>
</delete>
</mapper>
\ No newline at end of file
src/main/resources/mapper/THeatDataMapper.xml
0 → 100644
View file @
86fbb808
<?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.dao.THeatDataDao"
>
<resultMap
type=
"THeatData"
id=
"THeatDataResult"
>
<result
property=
"heatId"
column=
"heat_id"
/>
<result
property=
"manufacturersId"
column=
"manufacturers_id"
/>
<result
property=
"equipmentTypeValue"
column=
"equipment_type_value"
/>
<result
property=
"heatMeterId"
column=
"heat_neter_id"
/>
<result
property=
"protocolType"
column=
"protocol_type"
/>
<result
property=
"cumulativeCool"
column=
"cumulative_cool"
/>
<result
property=
"cumulativeCoolUnit"
column=
"cumulative_cool_unit"
/>
<result
property=
"cumulativeHeat"
column=
"cumulative_heat"
/>
<result
property=
"cumulativeHeatUnit"
column=
"cumulative_heat_unit"
/>
<result
property=
"theCurrentThermalPower"
column=
"the_current_thermal_power"
/>
<result
property=
"theCurrentThermalPowerUnit"
column=
"the_current_thermal_power_unit"
/>
<result
property=
"currentFlow"
column=
"current_flow"
/>
<result
property=
"currentFlowUnit"
column=
"current_flow_unit"
/>
<result
property=
"cumulativeFlow"
column=
"cumulative_flow"
/>
<result
property=
"cumulativeFlowUnit"
column=
"cumulative_flow_unit"
/>
<result
property=
"theCurrentWaterTemperature"
column=
"the_current_water_temperature"
/>
<result
property=
"currentReturnTemperature"
column=
"current_return_temperature"
/>
<result
property=
"cumulativeWorkingTime"
column=
"cumulative_working_time"
/>
<result
property=
"dateTimeValue"
column=
"date_time_value"
/>
<result
property=
"cumulativeReturnFlow"
column=
"cumulative_return_flow"
/>
<result
property=
"cumulativeReturnFlowUnit"
column=
"cumulative_return_flow_unit"
/>
<result
property=
"cumulativeFlowDifference"
column=
"cumulative_flow_difference"
/>
<result
property=
"cumulativeFlowDifferenceUnit"
column=
"cumulative_flow_difference_unit"
/>
<result
property=
"returnFlowFlag"
column=
"return_flow_flag"
/>
<result
property=
"stStatus"
column=
"st_status"
/>
<result
property=
"createTime"
column=
"create_time"
/>
</resultMap>
<sql
id=
"selectTHeatDataVo"
>
select heat_id, manufacturers_id, equipment_type_value, heat_neter_id, protocol_type, cumulative_cool, cumulative_cool_unit, cumulative_heat, cumulative_heat_unit, the_current_thermal_power, the_current_thermal_power_unit, current_flow, current_flow_unit, cumulative_flow, cumulative_flow_unit, the_current_water_temperature, current_return_temperature, cumulative_working_time, date_time_value, cumulative_return_flow, cumulative_return_flow_unit, cumulative_flow_difference, cumulative_flow_difference_unit, return_flow_flag, st_status, create_time from t_heat_data
</sql>
<select
id=
"selectTHeatDataList"
parameterType=
"THeatData"
resultMap=
"THeatDataResult"
>
<include
refid=
"selectTHeatDataVo"
/>
<where>
<if
test=
"manufacturersId != null and manufacturersId != ''"
>
and manufacturers_id = #{manufacturersId}
</if>
<if
test=
"equipmentTypeValue != null and equipmentTypeValue != ''"
>
and equipment_type_value = #{equipmentTypeValue}
</if>
<if
test=
"heatMeterId != null and heatMeterId != ''"
>
and heat_neter_id = #{heatMeterId}
</if>
<if
test=
"protocolType != null and protocolType != ''"
>
and protocol_type = #{protocolType}
</if>
<if
test=
"cumulativeCool != null "
>
and cumulative_cool = #{cumulativeCool}
</if>
<if
test=
"cumulativeCoolUnit != null and cumulativeCoolUnit != ''"
>
and cumulative_cool_unit = #{cumulativeCoolUnit}
</if>
<if
test=
"cumulativeHeat != null "
>
and cumulative_heat = #{cumulativeHeat}
</if>
<if
test=
"cumulativeHeatUnit != null and cumulativeHeatUnit != ''"
>
and cumulative_heat_unit = #{cumulativeHeatUnit}
</if>
<if
test=
"theCurrentThermalPower != null "
>
and the_current_thermal_power = #{theCurrentThermalPower}
</if>
<if
test=
"theCurrentThermalPowerUnit != null and theCurrentThermalPowerUnit != ''"
>
and the_current_thermal_power_unit = #{theCurrentThermalPowerUnit}
</if>
<if
test=
"currentFlow != null "
>
and current_flow = #{currentFlow}
</if>
<if
test=
"currentFlowUnit != null and currentFlowUnit != ''"
>
and current_flow_unit = #{currentFlowUnit}
</if>
<if
test=
"cumulativeFlow != null "
>
and cumulative_flow = #{cumulativeFlow}
</if>
<if
test=
"cumulativeFlowUnit != null and cumulativeFlowUnit != ''"
>
and cumulative_flow_unit = #{cumulativeFlowUnit}
</if>
<if
test=
"theCurrentWaterTemperature != null "
>
and the_current_water_temperature = #{theCurrentWaterTemperature}
</if>
<if
test=
"currentReturnTemperature != null "
>
and current_return_temperature = #{currentReturnTemperature}
</if>
<if
test=
"cumulativeWorkingTime != null and cumulativeWorkingTime != ''"
>
and cumulative_working_time = #{cumulativeWorkingTime}
</if>
<if
test=
"dateTimeValue != null "
>
and date_time_value = #{dateTimeValue}
</if>
<if
test=
"cumulativeReturnFlow != null "
>
and cumulative_return_flow = #{cumulativeReturnFlow}
</if>
<if
test=
"cumulativeReturnFlowUnit != null and cumulativeReturnFlowUnit != ''"
>
and cumulative_return_flow_unit = #{cumulativeReturnFlowUnit}
</if>
<if
test=
"cumulativeFlowDifference != null "
>
and cumulative_flow_difference = #{cumulativeFlowDifference}
</if>
<if
test=
"cumulativeFlowDifferenceUnit != null and cumulativeFlowDifferenceUnit != ''"
>
and cumulative_flow_difference_unit = #{cumulativeFlowDifferenceUnit}
</if>
<if
test=
"returnFlowFlag != null and returnFlowFlag != ''"
>
and return_flow_flag = #{returnFlowFlag}
</if>
<if
test=
"stStatus != null and stStatus != ''"
>
and st_status = #{stStatus}
</if>
</where>
</select>
<select
id=
"selectTHeatDataById"
parameterType=
"Long"
resultMap=
"THeatDataResult"
>
<include
refid=
"selectTHeatDataVo"
/>
where heat_id = #{heatId}
</select>
<insert
id=
"insertTHeatData"
parameterType=
"THeatData"
useGeneratedKeys=
"true"
keyProperty=
"heatId"
>
insert into t_heat_data
<trim
prefix=
"("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"manufacturersId != null"
>
manufacturers_id,
</if>
<if
test=
"equipmentTypeValue != null"
>
equipment_type_value,
</if>
<if
test=
"heatMeterId != null"
>
heat_neter_id,
</if>
<if
test=
"protocolType != null"
>
protocol_type,
</if>
<if
test=
"cumulativeCool != null"
>
cumulative_cool,
</if>
<if
test=
"cumulativeCoolUnit != null"
>
cumulative_cool_unit,
</if>
<if
test=
"cumulativeHeat != null"
>
cumulative_heat,
</if>
<if
test=
"cumulativeHeatUnit != null"
>
cumulative_heat_unit,
</if>
<if
test=
"theCurrentThermalPower != null"
>
the_current_thermal_power,
</if>
<if
test=
"theCurrentThermalPowerUnit != null"
>
the_current_thermal_power_unit,
</if>
<if
test=
"currentFlow != null"
>
current_flow,
</if>
<if
test=
"currentFlowUnit != null"
>
current_flow_unit,
</if>
<if
test=
"cumulativeFlow != null"
>
cumulative_flow,
</if>
<if
test=
"cumulativeFlowUnit != null"
>
cumulative_flow_unit,
</if>
<if
test=
"theCurrentWaterTemperature != null"
>
the_current_water_temperature,
</if>
<if
test=
"currentReturnTemperature != null"
>
current_return_temperature,
</if>
<if
test=
"cumulativeWorkingTime != null"
>
cumulative_working_time,
</if>
<if
test=
"dateTimeValue != null"
>
date_time_value,
</if>
<if
test=
"cumulativeReturnFlow != null"
>
cumulative_return_flow,
</if>
<if
test=
"cumulativeReturnFlowUnit != null"
>
cumulative_return_flow_unit,
</if>
<if
test=
"cumulativeFlowDifference != null"
>
cumulative_flow_difference,
</if>
<if
test=
"cumulativeFlowDifferenceUnit != null"
>
cumulative_flow_difference_unit,
</if>
<if
test=
"returnFlowFlag != null"
>
return_flow_flag,
</if>
<if
test=
"stStatus != null"
>
st_status,
</if>
<if
test=
"createTime != null"
>
create_time,
</if>
</trim>
<trim
prefix=
"values ("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"manufacturersId != null"
>
#{manufacturersId},
</if>
<if
test=
"equipmentTypeValue != null"
>
#{equipmentTypeValue},
</if>
<if
test=
"heatMeterId != null"
>
#{heatMeterId},
</if>
<if
test=
"protocolType != null"
>
#{protocolType},
</if>
<if
test=
"cumulativeCool != null"
>
#{cumulativeCool},
</if>
<if
test=
"cumulativeCoolUnit != null"
>
#{cumulativeCoolUnit},
</if>
<if
test=
"cumulativeHeat != null"
>
#{cumulativeHeat},
</if>
<if
test=
"cumulativeHeatUnit != null"
>
#{cumulativeHeatUnit},
</if>
<if
test=
"theCurrentThermalPower != null"
>
#{theCurrentThermalPower},
</if>
<if
test=
"theCurrentThermalPowerUnit != null"
>
#{theCurrentThermalPowerUnit},
</if>
<if
test=
"currentFlow != null"
>
#{currentFlow},
</if>
<if
test=
"currentFlowUnit != null"
>
#{currentFlowUnit},
</if>
<if
test=
"cumulativeFlow != null"
>
#{cumulativeFlow},
</if>
<if
test=
"cumulativeFlowUnit != null"
>
#{cumulativeFlowUnit},
</if>
<if
test=
"theCurrentWaterTemperature != null"
>
#{theCurrentWaterTemperature},
</if>
<if
test=
"currentReturnTemperature != null"
>
#{currentReturnTemperature},
</if>
<if
test=
"cumulativeWorkingTime != null"
>
#{cumulativeWorkingTime},
</if>
<if
test=
"dateTimeValue != null"
>
#{dateTimeValue},
</if>
<if
test=
"cumulativeReturnFlow != null"
>
#{cumulativeReturnFlow},
</if>
<if
test=
"cumulativeReturnFlowUnit != null"
>
#{cumulativeReturnFlowUnit},
</if>
<if
test=
"cumulativeFlowDifference != null"
>
#{cumulativeFlowDifference},
</if>
<if
test=
"cumulativeFlowDifferenceUnit != null"
>
#{cumulativeFlowDifferenceUnit},
</if>
<if
test=
"returnFlowFlag != null"
>
#{returnFlowFlag},
</if>
<if
test=
"stStatus != null"
>
#{stStatus},
</if>
<if
test=
"createTime != null"
>
#{createTime},
</if>
</trim>
</insert>
<update
id=
"updateTHeatData"
parameterType=
"THeatData"
>
update t_heat_data
<trim
prefix=
"SET"
suffixOverrides=
","
>
<if
test=
"manufacturersId != null"
>
manufacturers_id = #{manufacturersId},
</if>
<if
test=
"equipmentTypeValue != null"
>
equipment_type_value = #{equipmentTypeValue},
</if>
<if
test=
"heatMeterId != null"
>
heat_neter_id = #{heatMeterId},
</if>
<if
test=
"protocolType != null"
>
protocol_type = #{protocolType},
</if>
<if
test=
"cumulativeCool != null"
>
cumulative_cool = #{cumulativeCool},
</if>
<if
test=
"cumulativeCoolUnit != null"
>
cumulative_cool_unit = #{cumulativeCoolUnit},
</if>
<if
test=
"cumulativeHeat != null"
>
cumulative_heat = #{cumulativeHeat},
</if>
<if
test=
"cumulativeHeatUnit != null"
>
cumulative_heat_unit = #{cumulativeHeatUnit},
</if>
<if
test=
"theCurrentThermalPower != null"
>
the_current_thermal_power = #{theCurrentThermalPower},
</if>
<if
test=
"theCurrentThermalPowerUnit != null"
>
the_current_thermal_power_unit = #{theCurrentThermalPowerUnit},
</if>
<if
test=
"currentFlow != null"
>
current_flow = #{currentFlow},
</if>
<if
test=
"currentFlowUnit != null"
>
current_flow_unit = #{currentFlowUnit},
</if>
<if
test=
"cumulativeFlow != null"
>
cumulative_flow = #{cumulativeFlow},
</if>
<if
test=
"cumulativeFlowUnit != null"
>
cumulative_flow_unit = #{cumulativeFlowUnit},
</if>
<if
test=
"theCurrentWaterTemperature != null"
>
the_current_water_temperature = #{theCurrentWaterTemperature},
</if>
<if
test=
"currentReturnTemperature != null"
>
current_return_temperature = #{currentReturnTemperature},
</if>
<if
test=
"cumulativeWorkingTime != null"
>
cumulative_working_time = #{cumulativeWorkingTime},
</if>
<if
test=
"dateTimeValue != null"
>
date_time_value = #{dateTimeValue},
</if>
<if
test=
"cumulativeReturnFlow != null"
>
cumulative_return_flow = #{cumulativeReturnFlow},
</if>
<if
test=
"cumulativeReturnFlowUnit != null"
>
cumulative_return_flow_unit = #{cumulativeReturnFlowUnit},
</if>
<if
test=
"cumulativeFlowDifference != null"
>
cumulative_flow_difference = #{cumulativeFlowDifference},
</if>
<if
test=
"cumulativeFlowDifferenceUnit != null"
>
cumulative_flow_difference_unit = #{cumulativeFlowDifferenceUnit},
</if>
<if
test=
"returnFlowFlag != null"
>
return_flow_flag = #{returnFlowFlag},
</if>
<if
test=
"stStatus != null"
>
st_status = #{stStatus},
</if>
<if
test=
"createTime != null"
>
create_time = #{createTime},
</if>
</trim>
where heat_id = #{heatId}
</update>
<delete
id=
"deleteTHeatDataById"
parameterType=
"Long"
>
delete from t_heat_data where heat_id = #{heatId}
</delete>
<delete
id=
"deleteTHeatDataByIds"
parameterType=
"String"
>
delete from t_heat_data where heat_id in
<foreach
item=
"heatId"
collection=
"array"
open=
"("
separator=
","
close=
")"
>
#{heatId}
</foreach>
</delete>
</mapper>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment