Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
amos-boot-biz
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
项目统一框架
amos-boot-biz
Commits
3df46798
Commit
3df46798
authored
Apr 11, 2024
by
caotao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.数据采集服务新增代码注释。
parent
43aba8c7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
3 deletions
+33
-3
DasService.java
.../com/yeejoin/amos/boot/module/das/service/DasService.java
+3
-0
DasServiceImpl.java
...oin/amos/boot/module/das/service/impl/DasServiceImpl.java
+30
-3
No files found.
amos-boot-system-jxiop/amos-boot-module-jxiop-das/src/main/java/com/yeejoin/amos/boot/module/das/service/DasService.java
View file @
3df46798
...
...
@@ -5,5 +5,8 @@ import org.springframework.scheduling.annotation.Async;
import
org.springframework.scheduling.annotation.Scheduled
;
public
interface
DasService
{
/**
* 数据固化
*/
void
dataSolidification
();
}
amos-boot-system-jxiop/amos-boot-module-jxiop-das/src/main/java/com/yeejoin/amos/boot/module/das/service/impl/DasServiceImpl.java
View file @
3df46798
...
...
@@ -35,36 +35,62 @@ public class DasServiceImpl implements DasService {
@Scheduled
(
cron
=
"0 */10 * * * ?"
)
@Override
/**
* 数据固化方法。该方法用于将数据从物联监盘同步到TDengine数据库。
* 这个过程首先会创建一个新的表,然后并行处理每个网关ID的数据固化过程。
* 完成后,会记录此次操作所花费的时间。
*/
public
void
dataSolidification
()
{
// 记录操作开始时间
Long
startTime
=
System
.
currentTimeMillis
();
// 创建新表
indicatorDataMapper
.
createTable
();
// 获取所有网关ID
List
<
String
>
gateWayIds
=
frontGatewayDevicePointsMapper
.
getGatewayIds
();
// 并行处理每个网关ID的数据凝固
gateWayIds
.
parallelStream
().
forEach
(
gatewayId
->
{
dataSolidificationByGatewayId
(
gatewayId
);
});
// 记录操作结束时间
Long
endTime
=
System
.
currentTimeMillis
();
log
.
info
(
"同步ES数据至TDengine耗时:"
+
(
endTime
-
startTime
)
+
"ms"
);
// 记录操作耗时日志
log
.
info
(
"同步物联监盘数据至TDengine耗时:"
+
(
endTime
-
startTime
)
+
"ms"
);
}
/**
* 根据网关ID进行数据凝固操作。
* 该操作首先查询指定网关ID的设备点信息,然后基于这些信息从TDengine数据库中获取相应的数据点值,并将这些值
* 组装成新的数据模型存储到数据库中。此外,该操作还会向EMQX发送一条消息,通知数据同步成功。
*
* @param gatewayId 网关的唯一标识符,用于查询相关设备点信息和数据点值。
*/
@Async
(
"jxiopAsyncExecutor"
)
public
void
dataSolidificationByGatewayId
(
String
gatewayId
)
{
// 根据网关ID查询设备点信息
List
<
FrontGatewayDevicePoints
>
tempPoints
=
frontGatewayDevicePointsMapper
.
getFrontGatewayDevicePointsByGatewayId
(
gatewayId
);
if
(!
ObjectUtils
.
isEmpty
(
tempPoints
))
{
// 检查在TDengine中是否存在对应的表
Long
tableCount
=
tdengineIotDataMapper
.
getTtableCount
(
"stb_"
+
gatewayId
);
if
(!(
tableCount
>
0
))
{
return
;
return
;
// 如果表不存在,则直接返回
}
// 从TDengine中查询数据点值
List
<
StbDtoData
>
stbDtoDataList
=
tdengineIotDataMapper
.
getStbDtoDataByStbName
(
"stb_"
+
gatewayId
);
// 将查询到的数据点值转换为Map形式存储
Map
<
String
,
String
>
stbMap
=
stbDtoDataList
.
parallelStream
().
collect
(
Collectors
.
toMap
(
StbDtoData:
:
getPointSeq
,
StbDtoData:
:
getValue
));
if
(
stbMap
.
size
()
>
0
)
{
// 遍历设备点信息,将每个设备点与从TDengine获取的值匹配,并构建新的数据模型
List
<
IndicatorData
>
listAll
=
new
ArrayList
<>();
tempPoints
.
stream
().
forEach
(
point
->
{
IndicatorData
indicatorData
=
new
IndicatorData
();
// 设置数据模型的各项属性
indicatorData
.
setDataType
(
point
.
getDataType
());
indicatorData
.
setPointSeq
(
point
.
getSequenceNbr
().
toString
());
indicatorData
.
setPointAddress
(
point
.
getPointAddress
());
indicatorData
.
setPointLocation
(
point
.
getPointLocation
());
indicatorData
.
setPointName
(
point
.
getPointName
());
// 设置数据点的值,如果是布尔值则进行转换
indicatorData
.
setValue
(
stbMap
.
get
(
point
.
getSequenceNbr
().
toString
()));
if
(!
ObjectUtils
.
isEmpty
(
indicatorData
.
getValue
())
&&
!
booleans
.
contains
(
indicatorData
.
getValue
()))
{
try
{
...
...
@@ -72,16 +98,17 @@ public class DasServiceImpl implements DasService {
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
listAll
.
add
(
indicatorData
);
});
// 批量插入构建的数据模型到数据库
Lists
.
partition
(
listAll
,
1000
).
stream
().
forEach
(
list
->
{
indicatorDataMapper
.
insertBatch
(
list
,
gatewayId
);
}
);
// 向EMQX发送消息,通知数据同步成功
try
{
HashMap
<
String
,
String
>
syncFlag
=
new
HashMap
<>();
syncFlag
.
put
(
"gateway_id"
,
gatewayId
);
...
...
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