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
a2d01ed5
Commit
a2d01ed5
authored
Jul 23, 2025
by
tianyiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: 增加批量处理逻辑以优化设备状态更新和消息发送
parent
5983dd6b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
24 deletions
+23
-24
SafetyProblemTracingGenServiceImpl.java
.../biz/service/impl/SafetyProblemTracingGenServiceImpl.java
+23
-24
No files found.
amos-boot-system-tzs/amos-boot-module-jg/amos-boot-module-jg-biz/src/main/java/com/yeejoin/amos/boot/module/jg/biz/service/impl/SafetyProblemTracingGenServiceImpl.java
View file @
a2d01ed5
...
@@ -143,18 +143,22 @@ public class SafetyProblemTracingGenServiceImpl{
...
@@ -143,18 +143,22 @@ public class SafetyProblemTracingGenServiceImpl{
return
;
return
;
}
}
List
<
String
>
records
=
mapList
.
stream
().
map
(
m
->
m
.
get
(
"RECORD"
).
toString
()).
collect
(
Collectors
.
toList
());
List
<
String
>
records
=
mapList
.
stream
().
map
(
m
->
m
.
get
(
"RECORD"
).
toString
()).
collect
(
Collectors
.
toList
());
// 更新设备状态为未处理(异常)
int
batchSize
=
10000
;
idxBizJgOtherInfoService
.
lambdaUpdate
()
for
(
int
i
=
0
;
i
<
records
.
size
();
i
+=
batchSize
)
{
.
in
(
IdxBizJgOtherInfo:
:
getRecord
,
records
)
List
<
String
>
batch
=
records
.
subList
(
i
,
Math
.
min
(
i
+
batchSize
,
records
.
size
()));
.
set
(
IdxBizJgOtherInfo:
:
getStatus
,
SafetyProblemStatusEnum
.
UNHANDLED
.
getCode
())
// 更新设备状态为未处理(异常)
.
update
();
idxBizJgOtherInfoService
.
lambdaUpdate
()
List
<
ESEquipmentCategoryDto
>
esEquipmentCategoryDto
=
Lists
.
newArrayList
();
.
in
(
IdxBizJgOtherInfo:
:
getRecord
,
batch
)
for
(
ESEquipmentCategoryDto
equipmentCategoryDto
:
esEquipmentCategory
.
findAllById
(
records
))
{
.
set
(
IdxBizJgOtherInfo:
:
getStatus
,
SafetyProblemStatusEnum
.
UNHANDLED
.
getCode
())
equipmentCategoryDto
.
setProblemStatus
(
SafetyProblemStatusEnum
.
UNHANDLED
.
getCode
());
.
update
();
esEquipmentCategoryDto
.
add
(
equipmentCategoryDto
);
List
<
ESEquipmentCategoryDto
>
esEquipmentCategoryDto
=
Lists
.
newArrayList
();
for
(
ESEquipmentCategoryDto
equipmentCategoryDto
:
esEquipmentCategory
.
findAllById
(
batch
))
{
equipmentCategoryDto
.
setProblemStatus
(
SafetyProblemStatusEnum
.
UNHANDLED
.
getCode
());
esEquipmentCategoryDto
.
add
(
equipmentCategoryDto
);
}
esEquipmentCategory
.
saveAll
(
esEquipmentCategoryDto
);
sendSafetyProblemMessage
(
mapList
,
safetyProblemTypeEnum
);
}
}
esEquipmentCategory
.
saveAll
(
esEquipmentCategoryDto
);
sendSafetyProblemMessage
(
mapList
,
safetyProblemTypeEnum
);
}
}
private
void
updateEnterpriseAndSendMessage
(
List
<
Map
<
String
,
Object
>>
mapList
)
{
private
void
updateEnterpriseAndSendMessage
(
List
<
Map
<
String
,
Object
>>
mapList
)
{
...
@@ -191,21 +195,16 @@ public class SafetyProblemTracingGenServiceImpl{
...
@@ -191,21 +195,16 @@ public class SafetyProblemTracingGenServiceImpl{
* @param safetyProblemTypeEnum
* @param safetyProblemTypeEnum
*/
*/
private
void
sendSafetyProblemMessage
(
List
<
Map
<
String
,
Object
>>
mapList
,
SafetyProblemTypeEnum
safetyProblemTypeEnum
)
{
private
void
sendSafetyProblemMessage
(
List
<
Map
<
String
,
Object
>>
mapList
,
SafetyProblemTypeEnum
safetyProblemTypeEnum
)
{
int
batchSize
=
10000
;
if
(
CollectionUtil
.
isNotEmpty
(
mapList
)){
for
(
int
i
=
0
;
i
<
mapList
.
size
();
i
+=
batchSize
)
{
try
{
List
<
Map
<
String
,
Object
>>
batch
=
mapList
.
subList
(
i
,
Math
.
min
(
i
+
batchSize
,
mapList
.
size
()));
logger
.
info
(
"发送安全追溯问题主题---->{}"
,
safetyProblemTypeEnum
.
getTopic
());
if
(
CollectionUtil
.
isNotEmpty
(
mapList
)){
emqKeeper
.
getMqttClient
().
publish
(
safetyProblemTypeEnum
.
getTopic
(),
JSON
.
toJSONBytes
(
mapList
),
2
,
false
);
try
{
logger
.
info
(
"发送安全追溯问题消息成功---->"
);
logger
.
info
(
"发送安全追溯问题主题---->{}"
,
safetyProblemTypeEnum
.
getTopic
());
}
catch
(
MqttException
e
)
{
emqKeeper
.
getMqttClient
().
publish
(
safetyProblemTypeEnum
.
getTopic
(),
JSON
.
toJSONBytes
(
batch
),
2
,
false
);
logger
.
error
(
"发送安全追溯问题设备信息消息失败---->{}"
,
e
.
getMessage
());
logger
.
info
(
"发送安全追溯问题消息成功---->"
);
throw
new
RuntimeException
(
e
);
}
catch
(
MqttException
e
)
{
logger
.
error
(
"发送安全追溯问题设备信息消息失败---->{}"
,
e
.
getMessage
());
throw
new
RuntimeException
(
e
);
}
}
}
}
}
}
}
// @Scheduled(cron = "0 0 1 * * ?")
// @Scheduled(cron = "0 0 1 * * ?")
...
...
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