Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
entrance_api
Project
Project
Details
Activity
Releases
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
王琮
entrance_api
Commits
aabe49ec
Commit
aabe49ec
authored
Dec 23, 2022
by
zhangyanduan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add:添加门磁设备数据上报处理逻辑
parent
2b1d51cc
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
159 additions
and
32 deletions
+159
-32
AepPushServiceImpl.java
...soft/integration/aep/service/impl/AepPushServiceImpl.java
+132
-4
DoorDeviceInfo.java
...org/rcisoft/sys/doordeviceinfo/entity/DoorDeviceInfo.java
+0
-20
DoorDeviceInfoService.java
...oft/sys/doordeviceinfo/service/DoorDeviceInfoService.java
+8
-0
DoorDeviceInfoServiceImpl.java
...oordeviceinfo/service/impl/DoorDeviceInfoServiceImpl.java
+18
-0
DoorReportData.java
...org/rcisoft/sys/doorreportdata/entity/DoorReportData.java
+1
-8
No files found.
src/main/java/org/rcisoft/integration/aep/service/impl/AepPushServiceImpl.java
View file @
aabe49ec
package
org
.
rcisoft
.
integration
.
aep
.
service
.
impl
;
package
org
.
rcisoft
.
integration
.
aep
.
service
.
impl
;
import
cn.hutool.core.codec.Base64
;
import
cn.hutool.core.codec.Base64
;
import
cn.hutool.core.date.DateUtil
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.rcisoft.integration.aep.service.IAepPushService
;
import
org.rcisoft.integration.aep.service.IAepPushService
;
import
org.rcisoft.sys.doordeviceinfo.entity.DoorDeviceInfo
;
import
org.rcisoft.sys.doordeviceinfo.service.DoorDeviceInfoService
;
import
org.rcisoft.sys.doorreportdata.entity.DoorReportData
;
import
org.rcisoft.sys.doorreportdata.service.DoorReportDataService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.Date
;
/**
/**
* AEP门磁设备推送处理逻辑
* AEP门磁设备推送处理逻辑
*/
*/
...
@@ -17,6 +26,12 @@ import org.springframework.transaction.annotation.Transactional;
...
@@ -17,6 +26,12 @@ import org.springframework.transaction.annotation.Transactional;
@Transactional
(
readOnly
=
true
,
propagation
=
Propagation
.
NOT_SUPPORTED
)
@Transactional
(
readOnly
=
true
,
propagation
=
Propagation
.
NOT_SUPPORTED
)
public
class
AepPushServiceImpl
implements
IAepPushService
{
public
class
AepPushServiceImpl
implements
IAepPushService
{
@Autowired
private
DoorDeviceInfoService
doorDeviceInfoService
;
@Autowired
private
DoorReportDataService
doorReportDataService
;
/**
/**
* 门磁数据上报处理
* 门磁数据上报处理
...
@@ -57,13 +72,98 @@ public class AepPushServiceImpl implements IAepPushService {
...
@@ -57,13 +72,98 @@ public class AepPushServiceImpl implements IAepPushService {
String
deviceData
=
payload
.
getString
(
"APPdata"
);
String
deviceData
=
payload
.
getString
(
"APPdata"
);
//Base64解码
//Base64解码
String
hexStr
=
Base64
.
decodeStr
(
deviceData
);
String
hexStr
=
Base64
.
decodeStr
(
deviceData
);
//AA5501030A010000000000D00C0000EB
DoorReportData
reportData
=
new
DoorReportData
();
reportData
.
setDeviceImei
(
deviceIMEICode
);
String
dataStatus
=
convertBean
(
reportData
,
hexStr
);
if
(
StringUtils
.
equals
(
"200"
,
dataStatus
)){
DoorDeviceInfo
deviceInfo
=
doorDeviceInfoService
.
getDeviceInfoByIMEICode
(
deviceIMEICode
);
if
(
deviceInfo
!=
null
){
reportData
.
setDeviceId
(
Long
.
valueOf
(
deviceInfo
.
getBusinessId
()));
}
reportData
.
setReportTime
(
new
Date
(
timestamp
));
reportData
.
setFlag
(
"0"
);
reportData
.
setDelFlag
(
"0"
);
//保存数据操作
doorReportDataService
.
persist
(
reportData
);
}
}
else
{
}
else
{
//异常信息,获取负载信息失败了
//异常信息,获取负载信息失败了
log
.
error
(
"当前设备["
+
deviceIMEICode
+
"] 上报数据内容为空,属于异常数据"
);
log
.
error
(
"当前设备["
+
deviceIMEICode
+
"] 上报数据内容为空,属于异常数据"
);
}
}
}
}
/**
* 根据Hex解析数据并返回对象
* @param hexStr
* @return 解析状态
* -1: 解析失败,数据存在异常
* 200:解析正常
* 0:解析正常,数据无需处理
*/
private
String
convertBean
(
DoorReportData
convertBean
,
String
hexStr
){
/**
* 设备上报数据: AA55 01 03 0A 010000000000280C0000 43
* 设备心跳: AA55 01 02 14 010000000000530C53649C004E80AD0011000013 69
* 设备注册: AA55 01 06 18 011001046011311883631901101089861120224015401557 72
*
*/
String
resultCode
=
null
;
try
{
if
(
hexStr
.
length
()>=
32
){
String
frameHeaderStr
=
hexStr
.
substring
(
0
,
4
);
//帧头
String
deviceTypeStr
=
hexStr
.
substring
(
4
,
6
);
// 产品类型
String
commandStr
=
hexStr
.
substring
(
6
,
8
);
//指令类型
String
dataLengthStr
=
hexStr
.
substring
(
8
,
10
);
//数据包长度
int
dataLength
=
Integer
.
parseInt
(
dataLengthStr
,
16
);
String
payloadData
=
hexStr
.
substring
(
10
,(
10
+
dataLength
*
2
));
//数据包内容
if
(
StringUtils
.
equals
(
"AA55"
,
frameHeaderStr
)){
switch
(
commandStr
){
case
"01"
:
//设备注册
case
"06"
:
//设备注册新
case
"05"
:
//NB网关报警
case
"02"
:
//心跳数据
resultCode
=
"0"
;
log
.
info
(
"设备:【"
+
convertBean
.
getDeviceImei
()+
"】发送的指令:【"
+
hexStr
+
"】 无需入库"
);
break
;
case
"03"
:
//NB单品报警
//开始解析负载数据信息
String
status
=
payloadData
.
substring
(
0
,
4
);
//门磁状态
String
deviceStatus
=
payloadData
.
substring
(
4
,
12
);
//设备状态
String
fcStatus
=
deviceStatus
.
substring
(
4
,
5
);
//防拆状态
String
dcStatus
=
deviceStatus
.
substring
(
6
,
7
);
//电池状态
if
(
"1"
.
equals
(
fcStatus
)
||
"1"
.
equals
(
dcStatus
)){
//发生报警信息,不再检查门状态
convertBean
.
setDataType
(
"WARN"
);
convertBean
.
setDataVal
(
"1"
.
equals
(
fcStatus
)?
"设备被拆,请检查"
:
"设备电量低,请检查"
);
}
else
{
if
(
StringUtils
.
equals
(
"0100"
,
status
)){
convertBean
.
setDataType
(
"OPEN"
);
//开门状态
}
else
{
convertBean
.
setDataType
(
"CLOSE"
);
//关门
}
}
convertBean
.
setRemarks
(
hexStr
);
resultCode
=
"200"
;
break
;
}
}
else
{
//指令不符合要求,属于错误数据
log
.
error
(
"设备:【"
+
convertBean
.
getDeviceImei
()+
"】发送的指令:【"
+
hexStr
+
"】 错误,无法解析"
);
return
"-1"
;
}
}
else
{
//指令不符合要求,属于错误数据
log
.
error
(
"设备:【"
+
convertBean
.
getDeviceImei
()+
"】发送的指令:【"
+
hexStr
+
"】 错误,无法解析"
);
resultCode
=
"-1"
;
}
}
catch
(
Exception
e
){
log
.
error
(
e
.
getMessage
(),
e
);
log
.
error
(
"设备:【"
+
convertBean
.
getDeviceImei
()+
"】发送的指令:【"
+
hexStr
+
"】 解析错误"
);
resultCode
=
"-1"
;
}
return
resultCode
;
}
/**
/**
...
@@ -71,24 +171,52 @@ public class AepPushServiceImpl implements IAepPushService {
...
@@ -71,24 +171,52 @@ public class AepPushServiceImpl implements IAepPushService {
* @param data
* @param data
*/
*/
private
void
eventReportHandle
(
JSONObject
data
){
private
void
eventReportHandle
(
JSONObject
data
){
//获取设备编码
String
deviceIMEICode
=
data
.
getString
(
"IMEI"
);
//获取上报时间
long
timestamp
=
data
.
getLongValue
(
"timestamp"
);
//事件类型 1:信息 2:警告 3: 故障
String
eventType
=
data
.
getString
(
"eventType"
);
// 事件内容 暂不解析
JSONObject
eventData
=
data
.
getJSONObject
(
"eventContent"
);
if
(
StringUtils
.
equals
(
"2"
,
eventType
)
||
StringUtils
.
equals
(
"3"
,
eventType
)){
DoorReportData
reportData
=
new
DoorReportData
();
reportData
.
setDeviceImei
(
deviceIMEICode
);
reportData
.
setDataType
(
"WARN"
);
reportData
.
setFlag
(
"0"
);
reportData
.
setDelFlag
(
"0"
);
reportData
.
setReportTime
(
new
Date
(
timestamp
));
DoorDeviceInfo
deviceInfo
=
doorDeviceInfoService
.
getDeviceInfoByIMEICode
(
deviceIMEICode
);
if
(
deviceInfo
!=
null
){
reportData
.
setDeviceId
(
Long
.
valueOf
(
deviceInfo
.
getBusinessId
()));
}
StringBuffer
dataValStr
=
new
StringBuffer
();
dataValStr
.
append
(
"设备发生【"
).
append
(
StringUtils
.
equals
(
"2"
,
eventType
)?
"警告"
:
"故障"
).
append
(
"】事件"
);
dataValStr
.
append
(
" 事件内容:【"
).
append
(
eventData
.
toJSONString
()).
append
(
"】"
);
reportData
.
setDataVal
(
dataValStr
.
toString
());
doorReportDataService
.
persist
(
reportData
);
}
else
{
log
.
error
(
"设备:【"
+
deviceIMEICode
+
"】 上报设备事件信息:"
+
eventData
.
toJSONString
());
}
}
}
/**
/**
* 设备上下线处理逻辑
* 设备上下线处理逻辑
* 此处没有设备的编码数据,无法入库处理,因此此处仅做日志记录
* @param data
* @param data
*/
*/
private
void
deviceUpOrDownHandle
(
JSONObject
data
){
private
void
deviceUpOrDownHandle
(
JSONObject
data
){
log
.
info
(
"系统设备上线/下线通知:【"
+
data
.
toJSONString
()+
"】"
);
}
}
/**
/**
* 设备添加删除处理逻辑
* 设备添加删除处理逻辑
* 设备添加删除逻辑不再系统内体现,因此此处可能就没有上报的内容,但是为保证消息完整记录,此处记录下来
* @param data
* @param data
*/
*/
private
void
deviceAddOrDelHandle
(
JSONObject
data
){
private
void
deviceAddOrDelHandle
(
JSONObject
data
){
log
.
info
(
"系统设备发生变更:【"
+
data
.
toJSONString
()+
"】"
);
}
}
}
}
src/main/java/org/rcisoft/sys/doordeviceinfo/entity/DoorDeviceInfo.java
View file @
aabe49ec
...
@@ -19,51 +19,31 @@ public class DoorDeviceInfo extends CyIdIncreEntity<DoorDeviceInfo> {
...
@@ -19,51 +19,31 @@ public class DoorDeviceInfo extends CyIdIncreEntity<DoorDeviceInfo> {
* @column device_imei
* @column device_imei
* @default
* @default
*/
*/
@Excel
(
name
=
"设备imei码"
,
orderNum
=
"0"
,
width
=
20
)
private
String
deviceImei
;
private
String
deviceImei
;
/**
/**
* @desc 设备名称
* @desc 设备名称
* @column device_name
* @column device_name
* @default
* @default
*/
*/
@Excel
(
name
=
"设备名称"
,
orderNum
=
"1"
,
width
=
20
)
private
String
deviceName
;
private
String
deviceName
;
/**
/**
* @desc 设备所在地址
* @desc 设备所在地址
* @column device_address
* @column device_address
* @default
* @default
*/
*/
@Excel
(
name
=
"设备所在地址"
,
orderNum
=
"2"
,
width
=
20
)
private
String
deviceAddress
;
private
String
deviceAddress
;
/**
/**
* @desc 设备所在区域
* @desc 设备所在区域
* @column device_area
* @column device_area
* @default
* @default
*/
*/
@Excel
(
name
=
"设备所在区域"
,
orderNum
=
"3"
,
width
=
20
)
private
String
deviceArea
;
private
String
deviceArea
;
/**
/**
* @desc 设备所在点位
* @desc 设备所在点位
* @column device_point
* @column device_point
* @default
* @default
*/
*/
@Excel
(
name
=
"设备所在点位"
,
orderNum
=
"4"
,
width
=
20
)
private
String
devicePoint
;
private
String
devicePoint
;
/**
* @desc 备注
* @column remark
* @default
*/
@Excel
(
name
=
"备注"
,
orderNum
=
"5"
,
width
=
20
)
private
String
remark
;
/**
* @desc 删除注记
* @column del_flag
* @default
*/
@Excel
(
name
=
"删除注记"
,
orderNum
=
"6"
,
width
=
20
)
private
String
delFlag
;
}
}
src/main/java/org/rcisoft/sys/doordeviceinfo/service/DoorDeviceInfoService.java
View file @
aabe49ec
...
@@ -64,4 +64,12 @@ public interface DoorDeviceInfoService {
...
@@ -64,4 +64,12 @@ public interface DoorDeviceInfoService {
*/
*/
List
<
DoorDeviceInfo
>
export
(
DoorDeviceInfo
doorDeviceInfo
);
List
<
DoorDeviceInfo
>
export
(
DoorDeviceInfo
doorDeviceInfo
);
/***
* 根究设备的IMEI编码获取设备
* @param deviceImei
* @return
*/
DoorDeviceInfo
getDeviceInfoByIMEICode
(
String
deviceImei
);
}
}
src/main/java/org/rcisoft/sys/doordeviceinfo/service/impl/DoorDeviceInfoServiceImpl.java
View file @
aabe49ec
...
@@ -116,4 +116,22 @@ public class DoorDeviceInfoServiceImpl extends ServiceImpl<DoorDeviceInfoReposit
...
@@ -116,4 +116,22 @@ public class DoorDeviceInfoServiceImpl extends ServiceImpl<DoorDeviceInfoReposit
return
doorDeviceInfoList
;
return
doorDeviceInfoList
;
}
}
/***
* 根究设备的IMEI编码获取设备
* @param deviceImei
* @return
*/
@Override
public
DoorDeviceInfo
getDeviceInfoByIMEICode
(
String
deviceImei
)
{
QueryWrapper
<
DoorDeviceInfo
>
queryWrapper
=
new
QueryWrapper
<>();
queryWrapper
.
eq
(
"device_imei"
,
deviceImei
);
queryWrapper
.
eq
(
"del_flag"
,
"0"
);
List
<
DoorDeviceInfo
>
doorDeviceInfos
=
baseMapper
.
selectList
(
queryWrapper
);
if
(
doorDeviceInfos
!=
null
&&
!
doorDeviceInfos
.
isEmpty
()){
return
doorDeviceInfos
.
get
(
0
);
}
else
{
return
null
;
}
}
}
}
src/main/java/org/rcisoft/sys/doorreportdata/entity/DoorReportData.java
View file @
aabe49ec
...
@@ -22,15 +22,13 @@ public class DoorReportData extends CyIdIncreEntity<DoorReportData> {
...
@@ -22,15 +22,13 @@ public class DoorReportData extends CyIdIncreEntity<DoorReportData> {
* @column device_id
* @column device_id
* @default
* @default
*/
*/
@Excel
(
name
=
"设备主键"
,
orderNum
=
"0"
,
width
=
20
)
private
Long
deviceId
;
private
BigInteger
deviceId
;
/**
/**
* @desc 设备imei编码
* @desc 设备imei编码
* @column device_imei
* @column device_imei
* @default
* @default
*/
*/
@Excel
(
name
=
"设备imei编码"
,
orderNum
=
"1"
,
width
=
20
)
private
String
deviceImei
;
private
String
deviceImei
;
/**
/**
...
@@ -43,30 +41,25 @@ public class DoorReportData extends CyIdIncreEntity<DoorReportData> {
...
@@ -43,30 +41,25 @@ public class DoorReportData extends CyIdIncreEntity<DoorReportData> {
* @column data_type
* @column data_type
* @default
* @default
*/
*/
@Excel
(
name
=
"设备上报数据类型 open:开门 close:关门 warn:警告 up:设备上线 down:设备下线 "
,
orderNum
=
"2"
,
width
=
20
)
private
String
dataType
;
private
String
dataType
;
/**
/**
* @desc 设备上报数据内容
* @desc 设备上报数据内容
* @column data_val
* @column data_val
* @default
* @default
*/
*/
@Excel
(
name
=
"设备上报数据内容"
,
orderNum
=
"3"
,
width
=
20
)
private
String
dataVal
;
private
String
dataVal
;
/**
/**
* @desc 上报时间
* @desc 上报时间
* @column report_time
* @column report_time
* @default
* @default
*/
*/
@Excel
(
name
=
"上报时间"
,
orderNum
=
"4"
,
width
=
20
)
private
Date
reportTime
;
private
Date
reportTime
;
/**
/**
* @desc 抓拍图像
* @desc 抓拍图像
* @column capture_pic
* @column capture_pic
* @default
* @default
*/
*/
@Excel
(
name
=
"抓拍图像"
,
orderNum
=
"5"
,
width
=
20
)
private
String
capturePic
;
private
String
capturePic
;
}
}
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