更新设备物联网逻辑
This commit is contained in:
parent
2e05d93809
commit
8b35e17553
|
@ -1,5 +1,6 @@
|
|||
package com.ruoyi.bst.device.service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -155,11 +156,20 @@ public interface DeviceIotService {
|
|||
*/
|
||||
int updateIot(Device device);
|
||||
|
||||
/**
|
||||
* 更新设备在线状态
|
||||
*
|
||||
* @param mac
|
||||
* @param onlineStatus
|
||||
* @param lastOnlineTime
|
||||
* @return
|
||||
*/
|
||||
int updateOnlineStatus(String mac, String onlineStatus, LocalDateTime lastOnlineTime);
|
||||
|
||||
/**
|
||||
* 蓝牙上传
|
||||
*
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
int bltUpload(DeviceBltUploadDTO dto);
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@ import com.ruoyi.iot.domain.IotDeviceInfo;
|
|||
import com.ruoyi.iot.domain.response.CommandResponse;
|
||||
import com.ruoyi.iot.enums.IotHttpStatus;
|
||||
import com.ruoyi.iot.service.IotService;
|
||||
import com.ruoyi.iot.service.impl.DeviceOnlineStatus;
|
||||
import com.ruoyi.iot.util.IotUtil;
|
||||
import com.ruoyi.system.operLog.service.OperLogService;
|
||||
|
||||
|
@ -293,24 +294,23 @@ public class DeviceIotServiceImpl implements DeviceIotService {
|
|||
.filter(item -> Objects.equals(item.getMac(), device.getMac()))
|
||||
.findFirst().orElse(null);
|
||||
DeviceUtil.setIotInfo(device, iot);
|
||||
|
||||
this.updateIot(device);
|
||||
}
|
||||
|
||||
// 异步发送命令,强制设备上报数据
|
||||
// scheduledExecutorService.execute(() -> {
|
||||
// for (DeviceVO device : deviceList) {
|
||||
// try {
|
||||
// if (onlineType != null) {
|
||||
// iotService.getOnlineStatus(device, onlineType);
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// log.error("强制设备{}上报数据失败", device.getSn(), e);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
scheduledExecutorService.execute(() -> {
|
||||
for (DeviceVO device : deviceList) {
|
||||
try {
|
||||
if (onlineType != null) {
|
||||
iotService.getOnlineStatus(device, onlineType);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("强制设备{}上报数据失败", device.getSn(), e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateIot(Device device) {
|
||||
if (device == null || StringUtils.isBlank(device.getMac())) {
|
||||
return 0;
|
||||
|
@ -351,15 +351,9 @@ public class DeviceIotServiceImpl implements DeviceIotService {
|
|||
if (device.getLastLocationTime() != null) {
|
||||
info.setLastLocationTime(device.getLastLocationTime());
|
||||
}
|
||||
if (device.getOnlineStatus() != null) {
|
||||
info.setOnlineStatus(device.getOnlineStatus());
|
||||
}
|
||||
if (device.getSoftwareVersion() != null) {
|
||||
info.setSoftwareVersion(device.getSoftwareVersion());
|
||||
}
|
||||
if (device.getLastOnlineTime() != null) {
|
||||
info.setLastOnlineTime(device.getLastOnlineTime());
|
||||
}
|
||||
|
||||
String key = CacheConstants.DEVICE_CACHE_INFO + device.getMac();
|
||||
redisCache.setCacheObject(key, info);
|
||||
|
@ -367,6 +361,29 @@ public class DeviceIotServiceImpl implements DeviceIotService {
|
|||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateOnlineStatus(String mac, String onlineStatus, LocalDateTime lastOnlineTime) {
|
||||
if (StringUtils.isBlank(mac)) {
|
||||
return 0;
|
||||
}
|
||||
DeviceCacheInfo info = this.getIotInfo(mac);
|
||||
if (info == null) {
|
||||
info = new DeviceCacheInfo();
|
||||
}
|
||||
|
||||
if (onlineStatus != null) {
|
||||
info.setOnlineStatus(onlineStatus);
|
||||
}
|
||||
if (DeviceOnlineStatus.ONLINE.getStatus().equals(onlineStatus) && lastOnlineTime != null) {
|
||||
info.setLastOnlineTime(lastOnlineTime);
|
||||
}
|
||||
|
||||
String key = CacheConstants.DEVICE_CACHE_INFO + mac;
|
||||
redisCache.setCacheObject(key, info);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean create(String mac) {
|
||||
if (StringUtils.isBlank(mac)) {
|
||||
|
|
|
@ -100,10 +100,6 @@ public class DeviceUtil {
|
|||
if (device == null || info == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (info.getOnlineStatus() != null) {
|
||||
device.setOnlineStatus(info.getOnlineStatus());
|
||||
}
|
||||
if (info.getVoltage() != null) {
|
||||
device.setVoltage(info.getVoltage());
|
||||
}
|
||||
|
@ -137,6 +133,11 @@ public class DeviceUtil {
|
|||
if (info.getSoftwareVersion() != null) {
|
||||
device.setSoftwareVersion(info.getSoftwareVersion());
|
||||
}
|
||||
|
||||
// 在线状态
|
||||
if (info.getOnlineStatus() != null) {
|
||||
device.setOnlineStatus(info.getOnlineStatus());
|
||||
}
|
||||
if (info.getLastOnlineTime() != null) {
|
||||
device.setLastOnlineTime(info.getLastOnlineTime());
|
||||
}
|
||||
|
|
|
@ -108,8 +108,10 @@ public class IotReceiveServiceImpl implements IotReceiveService {
|
|||
device.setOnlineStatus(DeviceOnlineStatus.ONLINE.getStatus());
|
||||
device.setLastOnlineTime(at);
|
||||
|
||||
// 增加更新频率控制
|
||||
// 更新设备信息
|
||||
deviceIotService.updateIot(device);
|
||||
// 更新设备在线状态
|
||||
deviceIotService.updateOnlineStatus(device.getMac(), DeviceOnlineStatus.ONLINE.getStatus(), at);
|
||||
|
||||
// 定位无效,不处理
|
||||
if (device.getLongitude() == null || device.getLatitude() == null) {
|
||||
|
|
|
@ -18,7 +18,6 @@ import com.alibaba.fastjson2.JSONObject;
|
|||
import com.ruoyi.bst.commandLog.domain.CommandLog;
|
||||
import com.ruoyi.bst.commandLog.domain.enums.CommandLogType;
|
||||
import com.ruoyi.bst.commandLog.service.CommandLogService;
|
||||
import com.ruoyi.bst.device.domain.Device;
|
||||
import com.ruoyi.bst.device.service.DeviceIotService;
|
||||
import com.ruoyi.common.constant.CacheConstants;
|
||||
import com.ruoyi.common.constant.HttpStatus;
|
||||
|
@ -319,13 +318,7 @@ public class IotServiceImpl implements IotService {
|
|||
}
|
||||
|
||||
private void updateOnlineStatus(String mac, String status) {
|
||||
Device device = new Device();
|
||||
device.setMac(mac);
|
||||
device.setOnlineStatus(status);
|
||||
if (DeviceOnlineStatus.ONLINE.getStatus().equals(status)) {
|
||||
device.setLastOnlineTime(LocalDateTime.now());
|
||||
}
|
||||
deviceIotService.updateIot(device);
|
||||
deviceIotService.updateOnlineStatus(mac, status, LocalDateTime.now());
|
||||
}
|
||||
|
||||
// 新增命令日志
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.ruoyi.web.bst;
|
|||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.ruoyi.bst.device.service.DeviceAssembler;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
|
@ -13,6 +12,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
import com.ruoyi.bst.areaJoin.domain.enums.AreaJoinPermission;
|
||||
import com.ruoyi.bst.device.domain.DeviceVO;
|
||||
import com.ruoyi.bst.device.domain.enums.DeviceUnLockType;
|
||||
import com.ruoyi.bst.device.service.DeviceAssembler;
|
||||
import com.ruoyi.bst.device.service.DeviceIotService;
|
||||
import com.ruoyi.bst.device.service.DeviceService;
|
||||
import com.ruoyi.bst.device.service.DeviceValidator;
|
||||
|
@ -54,7 +54,8 @@ public class DeviceIotController extends BaseController {
|
|||
|
||||
/**
|
||||
* 执行带设备锁的操作
|
||||
* @param device 设备信息
|
||||
*
|
||||
* @param device 设备信息
|
||||
* @param operation 具体操作
|
||||
* @return 操作结果
|
||||
*/
|
||||
|
@ -77,7 +78,8 @@ public class DeviceIotController extends BaseController {
|
|||
@PutMapping("/unlock")
|
||||
public AjaxResult unlock(@RequestParam(required = false) Long id, @RequestParam(required = false) String sn) {
|
||||
DeviceVO device = this.getDevice(id, sn);
|
||||
return executeWithLock(device, () -> success(deviceIotService.unlock(device, DeviceUnLockType.ADMIN, "管理员开锁", true)));
|
||||
return executeWithLock(device,
|
||||
() -> success(deviceIotService.unlock(device, DeviceUnLockType.ADMIN, "管理员开锁", true)));
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('bst:device:lock')")
|
||||
|
@ -93,7 +95,8 @@ public class DeviceIotController extends BaseController {
|
|||
@PutMapping("/ring")
|
||||
public AjaxResult ring(@RequestParam(required = false) Long id, @RequestParam(required = false) String sn) {
|
||||
DeviceVO device = this.getDevice(id, sn);
|
||||
return executeWithLock(device, () -> success(deviceIotService.play(device, IotConstants.PLAY_WARNING, "管理员响铃寻车", true)));
|
||||
return executeWithLock(device,
|
||||
() -> success(deviceIotService.play(device, IotConstants.PLAY_WARNING, "管理员响铃寻车", true)));
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('bst:device:reboot')")
|
||||
|
@ -127,7 +130,8 @@ public class DeviceIotController extends BaseController {
|
|||
@PreAuthorize("@ss.hasPermi('bst:device:music')")
|
||||
@Log(title = "管理员设置声音", businessType = BusinessType.OTHER, bizIdName = "arg0", bizType = LogBizType.DEVICE)
|
||||
@PutMapping("/music")
|
||||
public AjaxResult music(@RequestParam(required = false) Long id, @RequestParam(required = false) String sn, @RequestParam String music) {
|
||||
public AjaxResult music(@RequestParam(required = false) Long id, @RequestParam(required = false) String sn,
|
||||
@RequestParam String music) {
|
||||
DeviceVO device = this.getDevice(id, sn);
|
||||
return executeWithLock(device, () -> success(deviceIotService.setMusic(device, music, "管理员设置声音", true)));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user