Commit 0bffcdb7 by YG8999

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

parent 66bae630
......@@ -12,13 +12,13 @@ import share.system.domain.vo.MqttxVo;
public interface DeviceOpService {
/**
* 小程序订单开门
* 小程序订单开门、通电
* @param deviceParam
*/
void openDoor(DeviceParamVo deviceParam);
/**
* 小程序订单开门
* 小程序订单开门、通电
* @param roomId 房间id
* @param phone 操作用户
*/
......
......@@ -56,11 +56,11 @@ public class DeviceOpServiceImpl implements DeviceOpService {
for (Device device : list) {
if (DeviceType.DEVICE_CCEE.getCode().equals(device.getDevType())) {
// 门锁
this.deviceOpInit(device.getDevId(), deviceParam.getPhone(), "10");
this.deviceOpInit(device.getDevId(), deviceParam.getPhone(), "10", false, 0L);
}
if (DeviceType.DEVICE_0001.getCode().equals(device.getDevType())) {
// 取电开关
this.deviceOpInit(device.getDevId(), deviceParam.getPhone(), "20");
this.deviceOpInit(device.getDevId(), deviceParam.getPhone(), "20", true, 2L);
}
}
......@@ -81,24 +81,44 @@ public class DeviceOpServiceImpl implements DeviceOpService {
for (Device device : list) {
if (DeviceType.DEVICE_CCEE.getCode().equals(device.getDevType())) {
// 门锁
this.deviceOpInit(device.getDevId(), phone, "10");
this.deviceOpInit(device.getDevId(), phone, "10", false, 0L);
}
if (DeviceType.DEVICE_0001.getCode().equals(device.getDevType())) {
// 取电开关
this.deviceOpInit(device.getDevId(), phone, "20");
this.deviceOpInit(device.getDevId(), phone, "20", true, 2L);
}
}
}
}
private void deviceOpInit(String devId, String phone, String opType) {
// 获取mqtt的topic、payload
MqttxVo mqttxVo = mqttxService.openOrCloseDevice(devId, phone, opType);
// 发送mqtt消息
mqttGatewayComponent.sendToMqtt(mqttxVo.getTopic(), 0, mqttxVo.getPayload());
// 写日志记录
deviceLogService.addDeviceLog(mqttxVo, phone);
private void deviceOpInit(String devId, String phone, String opType, boolean isASync, long m) {
if (isASync) {
// 异步执行
CompletableFuture.supplyAsync(() -> {
// 延时执行操作
try {
Thread.sleep(m * 1000);
// 获取mqtt的topic、payload
MqttxVo mqttxVo = mqttxService.openOrCloseDevice(devId, phone, opType);
// 发送mqtt消息
mqttGatewayComponent.sendToMqtt(mqttxVo.getTopic(), 0, mqttxVo.getPayload());
// 写日志记录
deviceLogService.addDeviceLog(mqttxVo, phone);
logger.info("延时执行开门、取电操作完成!");
} catch (InterruptedException e) {
e.printStackTrace();
}
return "Result: devId=" + devId;
});
} else {
// 获取mqtt的topic、payload
MqttxVo mqttxVo = mqttxService.openOrCloseDevice(devId, phone, opType);
// 发送mqtt消息
mqttGatewayComponent.sendToMqtt(mqttxVo.getTopic(), 0, mqttxVo.getPayload());
// 写日志记录
deviceLogService.addDeviceLog(mqttxVo, phone);
}
}
/**
......
......@@ -66,8 +66,8 @@
select t1.id, t1.account, t1.nick_name, t1.avatar, t1.phone, t1.level, t1.role_type, t1.sex, t1.addres, t1.amount,
t1.free_amount, t1.total_times, t1.duration, t1.status, t1.pwd, t1.create_time, t1.last_login_time
from s_consumer t1
left join s_store_consumer t2 on t2.consumer_id = t1.id
where t1.role_type = '1' and t1.id not in (select consumer_id from s_store_consumer where store_id = #{storeId})
where t1.role_type = '1'
and t1.id not in (select consumer_id from s_store_consumer where store_id = #{storeId})
<if test="nickName != null and nickName != ''">
AND t1.nick_name like concat('%', #{nickName}, '%')
</if>
......
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