Commit e8ca0bbf by YG8999

延时执行开门关门取电接口

parent 0bffcdb7
......@@ -63,15 +63,17 @@ public interface DeviceOpService {
* @return
*/
void asyncActionExecute(Long roomId, String phone,
String content, String startTime, String endTime, String number, Long m);
String content, String startTime, String endTime, String number, long 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);
}
......@@ -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, Long m) {
String startTime, String endTime, String number, long 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);
}
});
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment