优化锁同步逻辑,兼容钥匙开锁
This commit is contained in:
parent
530f640004
commit
7e0d11d0e3
|
@ -23,7 +23,8 @@ public enum RedisLockKey {
|
|||
ORDER_ADMIN_REFUND("order_admin_refund", "订单人工退款锁"),
|
||||
ORDER_PAY_RIDE_FEE("order_pay_ride_fee", "订单支付骑行费"),
|
||||
VIP_ORDER_CREATE("vip_order_create", "卡券订单创建"),
|
||||
DRIVER_INSERT("driver_insert", "驾驶证认证");
|
||||
DRIVER_INSERT("driver_insert", "驾驶证认证"),
|
||||
DEVICE_MONITOR("device_monitor", "设备监控");
|
||||
|
||||
private final String key;
|
||||
private final String name;
|
||||
|
|
|
@ -6,9 +6,10 @@ import lombok.Getter;
|
|||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum DeviceQuality {
|
||||
|
||||
|
||||
OPEN("1", "开启"),
|
||||
CLOSE("0", "关闭");
|
||||
CLOSE("0", "关闭"),
|
||||
UNKNOWN("49", "未知");
|
||||
|
||||
private final String code;
|
||||
private final String name;
|
||||
|
|
|
@ -6,6 +6,9 @@ import java.util.Map;
|
|||
import java.util.Objects;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
import com.ruoyi.bst.device.domain.enums.*;
|
||||
import com.ruoyi.common.core.redis.RedisLock;
|
||||
import com.ruoyi.common.core.redis.enums.RedisLockKey;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
@ -14,11 +17,6 @@ import com.ruoyi.bst.device.domain.Device;
|
|||
import com.ruoyi.bst.device.domain.DeviceQuery;
|
||||
import com.ruoyi.bst.device.domain.DeviceVO;
|
||||
import com.ruoyi.bst.device.domain.dto.DeviceBltUploadDTO;
|
||||
import com.ruoyi.bst.device.domain.enums.DeviceLocationType;
|
||||
import com.ruoyi.bst.device.domain.enums.DeviceLockStatus;
|
||||
import com.ruoyi.bst.device.domain.enums.DeviceQuality;
|
||||
import com.ruoyi.bst.device.domain.enums.DeviceStatus;
|
||||
import com.ruoyi.bst.device.domain.enums.DeviceUnLockType;
|
||||
import com.ruoyi.bst.device.domain.vo.DeviceIotVO;
|
||||
import com.ruoyi.bst.device.mapper.DeviceMapper;
|
||||
import com.ruoyi.bst.device.service.DeviceConverter;
|
||||
|
@ -72,6 +70,9 @@ public class DeviceIotServiceImpl implements DeviceIotService {
|
|||
@Autowired
|
||||
private OperLogService operLogService;
|
||||
|
||||
@Autowired
|
||||
private RedisLock redisLock;
|
||||
|
||||
private final static Integer SUB_FAST = 5; // 上报频率(快)
|
||||
private final static Integer SUB_SLOW = 300; // 上报频率(慢)
|
||||
private final static Integer SUB_X_SLOW = 50; // 上报频率(X开头硬件)
|
||||
|
@ -369,8 +370,18 @@ public class DeviceIotServiceImpl implements DeviceIotService {
|
|||
if (device == null) {
|
||||
return 0;
|
||||
}
|
||||
if (DeviceLockStatus.CLOSE.getCode().equals(device.getLockStatus())
|
||||
&& !DeviceQuality.CLOSE.getCode().equals(device.getQuality())) {
|
||||
|
||||
// 若不在仓库中 && 系统锁状态为关锁 && 电动车为上电运行,则重新尝试锁车
|
||||
boolean isLock = DeviceLockStatus.CLOSE.getCode().equals(device.getLockStatus());
|
||||
boolean isIotOpen = DeviceIotStatus.POWER_ON.getCode().equals(device.getIotStatus());
|
||||
boolean isStore = DeviceStatus.STORAGE.getCode().equals(device.getStatus());
|
||||
if (!isStore && isLock && isIotOpen) {
|
||||
// 锁60秒,避免频繁操作,无需手动释放锁
|
||||
boolean lock = redisLock.lock(RedisLockKey.DEVICE_MONITOR, device.getMac(), 60);
|
||||
if (!lock) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
CommandResponse res = iotService.lock(device, getDeviceSubSlow(device), "重新尝试锁车", 1);
|
||||
if (device.getOrderId() != null) {
|
||||
operLogService.operSysLog("【设备监控】发现未关闭的车辆", IotUtil.isSuccess(res), LogBizType.ORDER,
|
||||
|
@ -379,7 +390,8 @@ public class DeviceIotServiceImpl implements DeviceIotService {
|
|||
operLogService.operSysLog("【设备监控】发现未关闭的车辆", IotUtil.isSuccess(res), LogBizType.DEVICE, device.getId(),
|
||||
device);
|
||||
}
|
||||
return IotUtil.isSuccess(res) ? 1 : 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -26,7 +26,11 @@ public class IotDeviceSysInfo {
|
|||
@JSONField(name = IotConstants.DS_SYS_Q)
|
||||
private String q;
|
||||
|
||||
// 电动车状态 0断电,1上电运行 2轮动抱死 3超出区域断电(远程下发了qlose)
|
||||
// 电动车状态
|
||||
// 0断电
|
||||
// 1上电运行
|
||||
// 2轮动抱死
|
||||
// 3超出区域断电(远程下发了qlose)
|
||||
@JSONField(name = IotConstants.DS_SYS_STATUS)
|
||||
private String status;
|
||||
|
||||
|
|
|
@ -114,10 +114,13 @@ public class IotReceiveServiceImpl implements IotReceiveService {
|
|||
deviceIotService.updateIot(device);
|
||||
|
||||
// 处理设备定位BUG,若出现BUG则重启设备
|
||||
int handle = this.handleDeviceLocationBug(oldLon, oldLat, oldAt, device);
|
||||
if (handle == 1) {
|
||||
return;
|
||||
}
|
||||
// int handle = this.handleDeviceLocationBug(oldLon, oldLat, oldAt, device);
|
||||
// if (handle == 1) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// 处理定位日志
|
||||
this.handleLocationLog(device);
|
||||
|
||||
// 同步一次设备状态,若操作了同步,则不处理其他事情
|
||||
int monitor = deviceIotService.monitor(device);
|
||||
|
@ -127,9 +130,6 @@ public class IotReceiveServiceImpl implements IotReceiveService {
|
|||
|
||||
// 处理运营区
|
||||
this.handleArea(device);
|
||||
|
||||
// 处理定位日志
|
||||
this.handleLocationLog(device);
|
||||
}
|
||||
// 软件版本
|
||||
else if (IotConstants.DS_VER.equals(msg.getDsId())) {
|
||||
|
@ -189,7 +189,7 @@ public class IotReceiveServiceImpl implements IotReceiveService {
|
|||
if (!isOpen) {
|
||||
// 若当前数据点的上报时间和设备内上次上报的时间不一样,但是定位一样,则重启设备
|
||||
if (newAt.isAfter(oldAt) && MathUtils.equals(newLon, oldLon) && MathUtils.equals(newLat, oldLat)) {
|
||||
String reason = String.format("设备不同时间的两次定位一样,重启设备。新定位:%s,%s,旧定位:%s,%s", newLon, newLat, oldLon, oldLat);
|
||||
String reason = String.format("设备不同时间的两次定位一样,重启设备。新定位:%s,%s,旧定位:%s,%s,时间:%s,%s", newLon, newLat, oldLon, oldLat, newAt, oldAt);
|
||||
deviceIotService.reboot(device, reason, true);
|
||||
return 1;
|
||||
}
|
||||
|
@ -215,8 +215,8 @@ public class IotReceiveServiceImpl implements IotReceiveService {
|
|||
if (duration.getSeconds() > 60) {
|
||||
return;
|
||||
}
|
||||
// 卫星数量小于5,不处理设备操作
|
||||
if (device.getSatellites() == null || device.getSatellites() < 5) {
|
||||
// 卫星定位不准,不处理设备操作
|
||||
if (DeviceUtil.isLowSatelliteSignal(device)) {
|
||||
log.error("卫星数量小于5,不处理: {}", device.getMac());
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user