Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gxpt_ht
Overview
Overview
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
pseer
gxpt_ht
Commits
e8ca0bbf
Commit
e8ca0bbf
authored
Nov 30, 2023
by
YG8999
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
延时执行开门关门取电接口
parent
0bffcdb7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
10 deletions
+32
-10
DeviceOpService.java
...m/src/main/java/share/system/service/DeviceOpService.java
+4
-2
DeviceOpServiceImpl.java
...n/java/share/system/service/impl/DeviceOpServiceImpl.java
+28
-8
No files found.
share-system/src/main/java/share/system/service/DeviceOpService.java
View file @
e8ca0bbf
...
...
@@ -63,15 +63,17 @@ public interface DeviceOpService {
* @return
*/
void
asyncActionExecute
(
Long
roomId
,
String
phone
,
String
content
,
String
startTime
,
String
endTime
,
String
number
,
L
ong
m
);
String
content
,
String
startTime
,
String
endTime
,
String
number
,
l
ong
m
);
/**
* 开锁/关锁、取电/断电
* @param roomId 房间id
* @param phone 操作用户
* @param opType 操作类型:10:开门,20:取电,30:锁门,40:断电
* @param isAsync 是否延时操作
* @param m 延长执行时间:秒
* @return
*/
void
openOrCloseDevice
(
Long
roomId
,
String
phone
,
String
opType
);
void
openOrCloseDevice
(
Long
roomId
,
String
phone
,
String
opType
,
boolean
isAsync
,
long
m
);
}
share-system/src/main/java/share/system/service/impl/DeviceOpServiceImpl.java
View file @
e8ca0bbf
...
...
@@ -194,7 +194,7 @@ public class DeviceOpServiceImpl implements DeviceOpService {
*/
@Override
public
void
asyncActionExecute
(
Long
roomId
,
String
phone
,
String
content
,
String
startTime
,
String
endTime
,
String
number
,
L
ong
m
)
{
String
startTime
,
String
endTime
,
String
number
,
l
ong
m
)
{
SRoom
room
=
roomMapper
.
selectSRoomById
(
roomId
);
if
(
room
!=
null
)
{
// 异步执行
...
...
@@ -231,7 +231,7 @@ public class DeviceOpServiceImpl implements DeviceOpService {
* @return
*/
@Override
public
void
openOrCloseDevice
(
Long
roomId
,
String
phone
,
String
opType
)
{
public
void
openOrCloseDevice
(
Long
roomId
,
String
phone
,
String
opType
,
boolean
isAsync
,
long
m
)
{
SRoom
room
=
roomMapper
.
selectSRoomById
(
roomId
);
if
(
room
!=
null
)
{
LambdaQueryWrapper
<
Device
>
queryWrapper
=
new
LambdaQueryWrapper
<>();
...
...
@@ -245,12 +245,32 @@ public class DeviceOpServiceImpl implements DeviceOpService {
}
List
<
Device
>
list
=
deviceMapper
.
selectList
(
queryWrapper
);
list
.
stream
().
forEach
(
device
->
{
// 获取mqtt的topic、payload
MqttxVo
mqttxVo
=
mqttxService
.
openOrCloseDevice
(
device
.
getDevId
(),
phone
,
opType
);
// 发送mqtt消息
mqttGatewayComponent
.
sendToMqtt
(
mqttxVo
.
getTopic
(),
0
,
mqttxVo
.
getPayload
());
// 写日志记录
deviceLogService
.
addDeviceLog
(
mqttxVo
,
phone
);
if
(
isAsync
)
{
// 异步执行
CompletableFuture
.
supplyAsync
(()
->
{
// 延时执行操作
try
{
Thread
.
sleep
(
m
*
1000
);
// 获取mqtt的topic、payload
MqttxVo
mqttxVo
=
mqttxService
.
openOrCloseDevice
(
device
.
getDevId
(),
phone
,
opType
);
// 发送mqtt消息
mqttGatewayComponent
.
sendToMqtt
(
mqttxVo
.
getTopic
(),
0
,
mqttxVo
.
getPayload
());
// 写日志记录
deviceLogService
.
addDeviceLog
(
mqttxVo
,
phone
);
logger
.
info
(
"延时执行开锁/关锁、取电/断电完成!"
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
return
"Result: devid="
+
device
.
getDevId
()
;
});
}
else
{
// 获取mqtt的topic、payload
MqttxVo
mqttxVo
=
mqttxService
.
openOrCloseDevice
(
device
.
getDevId
(),
phone
,
opType
);
// 发送mqtt消息
mqttGatewayComponent
.
sendToMqtt
(
mqttxVo
.
getTopic
(),
0
,
mqttxVo
.
getPayload
());
// 写日志记录
deviceLogService
.
addDeviceLog
(
mqttxVo
,
phone
);
}
});
}
}
...
...
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