性能优化
This commit is contained in:
parent
6c8c9ae112
commit
ce0437814b
|
@ -17,7 +17,8 @@ public enum RedisLockKey {
|
||||||
DEVICE_SN_UNIQUE("device_sn_unique", "设备SN唯一"),
|
DEVICE_SN_UNIQUE("device_sn_unique", "设备SN唯一"),
|
||||||
DEVICE_MAC_UNIQUE("device_mac_unique", "设备MAC唯一"),
|
DEVICE_MAC_UNIQUE("device_mac_unique", "设备MAC唯一"),
|
||||||
USER_NAME_UNIQUE("user_name_unique", "用户账号唯一"),
|
USER_NAME_UNIQUE("user_name_unique", "用户账号唯一"),
|
||||||
DEVICE_IOT_REFRESH("device_iot_refresh", "设备物联网信息刷新");
|
DEVICE_IOT_REFRESH("device_iot_refresh", "设备物联网信息刷新"),
|
||||||
|
DEVICE_UPDATE_IOT_LOCK("device_update_iot_lock", "设备更新物联网信息锁");
|
||||||
|
|
||||||
private final String key;
|
private final String key;
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
|
@ -111,7 +111,7 @@ public class DeviceIotServiceImpl implements DeviceIotService {
|
||||||
|
|
||||||
transactionTemplate.execute(status -> {
|
transactionTemplate.execute(status -> {
|
||||||
// 更新数据库
|
// 更新数据库
|
||||||
int rows = deviceMapper.updateByQuery(data, query);
|
int rows = deviceMapper.updateByQuerySimple(data, query);
|
||||||
vo.setDb(rows);
|
vo.setDb(rows);
|
||||||
|
|
||||||
if (rows > 0) {
|
if (rows > 0) {
|
||||||
|
@ -157,9 +157,9 @@ public class DeviceIotServiceImpl implements DeviceIotService {
|
||||||
query.setStatusList(DeviceStatus.canUserLock());
|
query.setStatusList(DeviceStatus.canUserLock());
|
||||||
}
|
}
|
||||||
|
|
||||||
Integer result = transactionTemplate.execute(status -> {
|
transactionTemplate.execute(status -> {
|
||||||
// 更新设备状态
|
// 更新设备状态
|
||||||
int rows = deviceMapper.updateByQuery(data, query);
|
int rows = deviceMapper.updateByQuerySimple(data, query);
|
||||||
vo.setDb(rows);
|
vo.setDb(rows);
|
||||||
|
|
||||||
if (rows > 0) {
|
if (rows > 0) {
|
||||||
|
@ -200,7 +200,7 @@ public class DeviceIotServiceImpl implements DeviceIotService {
|
||||||
// 是否有正在进行的订单
|
// 是否有正在进行的订单
|
||||||
boolean hasOrder = device.getOrderDeviceId() != null && OrderDeviceStatus.inUse().contains(device.getOrderDeviceStatus());
|
boolean hasOrder = device.getOrderDeviceId() != null && OrderDeviceStatus.inUse().contains(device.getOrderDeviceStatus());
|
||||||
|
|
||||||
Integer result = transactionTemplate.execute(status -> {
|
transactionTemplate.execute(status -> {
|
||||||
// 更新设备状态
|
// 更新设备状态
|
||||||
Device data = new Device();
|
Device data = new Device();
|
||||||
data.setLockStatus(DeviceLockStatus.CLOSE.getCode());
|
data.setLockStatus(DeviceLockStatus.CLOSE.getCode());
|
||||||
|
@ -208,7 +208,7 @@ public class DeviceIotServiceImpl implements DeviceIotService {
|
||||||
DeviceQuery query = new DeviceQuery();
|
DeviceQuery query = new DeviceQuery();
|
||||||
query.setId(device.getId());
|
query.setId(device.getId());
|
||||||
query.setStatusList(DeviceStatus.canQLock());
|
query.setStatusList(DeviceStatus.canQLock());
|
||||||
int rows = deviceMapper.updateByQuery(data, query);
|
int rows = deviceMapper.updateByQuerySimple(data, query);
|
||||||
vo.setDb(rows);
|
vo.setDb(rows);
|
||||||
|
|
||||||
if (rows > 0) {
|
if (rows > 0) {
|
||||||
|
|
|
@ -480,7 +480,7 @@ public class DeviceServiceImpl implements DeviceService
|
||||||
data.setOnlineStatus(onlineStatus);
|
data.setOnlineStatus(onlineStatus);
|
||||||
DeviceQuery query = new DeviceQuery();
|
DeviceQuery query = new DeviceQuery();
|
||||||
query.setEqMac(mac);
|
query.setEqMac(mac);
|
||||||
return deviceMapper.updateByQuery(data, query);
|
return deviceMapper.updateByQuerySimple(data, query);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -235,7 +235,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
select
|
select
|
||||||
bll.longitude,
|
bll.longitude,
|
||||||
bll.latitude
|
bll.latitude
|
||||||
<include refid="searchTables"/>
|
from bst_location_log bll
|
||||||
<where>
|
<where>
|
||||||
<include refid="searchCondition"/>
|
<include refid="searchCondition"/>
|
||||||
</where>
|
</where>
|
||||||
|
|
|
@ -29,6 +29,8 @@ import com.ruoyi.bst.locationLog.domain.LocationLog;
|
||||||
import com.ruoyi.bst.locationLog.service.LocationLogConverter;
|
import com.ruoyi.bst.locationLog.service.LocationLogConverter;
|
||||||
import com.ruoyi.common.constant.CacheConstants;
|
import com.ruoyi.common.constant.CacheConstants;
|
||||||
import com.ruoyi.common.core.redis.RedisCache;
|
import com.ruoyi.common.core.redis.RedisCache;
|
||||||
|
import com.ruoyi.common.core.redis.RedisLock;
|
||||||
|
import com.ruoyi.common.core.redis.enums.RedisLockKey;
|
||||||
import com.ruoyi.common.enums.LogBizType;
|
import com.ruoyi.common.enums.LogBizType;
|
||||||
import com.ruoyi.common.utils.DateUtils;
|
import com.ruoyi.common.utils.DateUtils;
|
||||||
import com.ruoyi.common.utils.MathUtils;
|
import com.ruoyi.common.utils.MathUtils;
|
||||||
|
@ -76,6 +78,9 @@ public class IotReceiveServiceImpl implements IotReceiveService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private OperLogService operLogService;
|
private OperLogService operLogService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedisLock redisLock;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleReceive(ReceiveMsg msg) {
|
public void handleReceive(ReceiveMsg msg) {
|
||||||
if (msg == null) {
|
if (msg == null) {
|
||||||
|
@ -103,10 +108,9 @@ public class IotReceiveServiceImpl implements IotReceiveService {
|
||||||
// 更新设备信息
|
// 更新设备信息
|
||||||
device.setOnlineStatus(DeviceOnlineStatus.ONLINE.getStatus());
|
device.setOnlineStatus(DeviceOnlineStatus.ONLINE.getStatus());
|
||||||
device.setLastOnlineTime(at);
|
device.setLastOnlineTime(at);
|
||||||
int update = deviceIotService.updateIot(device);
|
|
||||||
if (update != 1) {
|
// 增加更新频率控制
|
||||||
log.error("更新设备信息失败: {}", msg.getDevName());
|
this.updateDeviceIot(device);
|
||||||
}
|
|
||||||
|
|
||||||
// 定位无效,不处理
|
// 定位无效,不处理
|
||||||
if (device.getLongitude() == null || device.getLatitude() == null) {
|
if (device.getLongitude() == null || device.getLatitude() == null) {
|
||||||
|
@ -143,6 +147,22 @@ public class IotReceiveServiceImpl implements IotReceiveService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新设备物联网信息
|
||||||
|
* @param device
|
||||||
|
*/
|
||||||
|
private void updateDeviceIot(DeviceVO device) {
|
||||||
|
boolean lock = redisLock.lock(RedisLockKey.DEVICE_UPDATE_IOT_LOCK.getKey(), device.getMac(), 20L, TimeUnit.SECONDS, 1);
|
||||||
|
if (lock) {
|
||||||
|
int update = deviceIotService.updateIot(device);
|
||||||
|
if (update != 1) {
|
||||||
|
log.error("更新设备信息失败: {}", device.getMac());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.info("设备{}更新太频繁,跳过本次更新", device.getMac());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理设备重启
|
* 处理设备重启
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -289,13 +289,19 @@ public class IotServiceImpl implements IotService {
|
||||||
// 转为在线状态,并缓存结果10秒
|
// 转为在线状态,并缓存结果10秒
|
||||||
String status = this.parseToOnlineStatus(res, deviceName, true);
|
String status = this.parseToOnlineStatus(res, deviceName, true);
|
||||||
redisCache.setCacheObject(this.getOnlineCacheKey(deviceName), status, 10, TimeUnit.SECONDS);
|
redisCache.setCacheObject(this.getOnlineCacheKey(deviceName), status, 10, TimeUnit.SECONDS);
|
||||||
|
|
||||||
// 异步更新设备在线状态
|
// 异步更新设备在线状态
|
||||||
scheduledExecutorService.schedule(() -> {
|
boolean lock = redisLock.lock(RedisLockKey.DEVICE_UPDATE_IOT_LOCK.getKey(), deviceName, 20L, TimeUnit.SECONDS, 1);
|
||||||
int update = deviceService.updateOnlineStatusByMac(deviceName, status);
|
if (lock ) {
|
||||||
if (update != 1) {
|
scheduledExecutorService.execute(() -> {
|
||||||
log.error("异步更新设备在线状态失败,MAC={},status={}", deviceName, status);
|
int update = deviceService.updateOnlineStatusByMac(deviceName, status);
|
||||||
}
|
if (update != 1) {
|
||||||
},0, TimeUnit.SECONDS);
|
log.error("异步更新设备在线状态失败,MAC={},status={}", deviceName, status);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
log.info("设备{}更新太频繁,跳过本次更新", deviceName);
|
||||||
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user