|
|
@@ -5,7 +5,6 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
@@ -53,6 +52,7 @@ import com.xunmei.host.websocket.service.RouterService;
|
|
|
import com.xunmei.host.websocket.service.WebsocketService;
|
|
|
import com.xunmei.system.api.domain.iot.IotDeviceInfo;
|
|
|
import com.xunmei.system.api.domain.iot.IotDeviceInfoExtend;
|
|
|
+import com.xunmei.system.api.enums.DeviceSyncStatus;
|
|
|
import com.xunmei.system.api.util.LogUtils;
|
|
|
import io.netty.util.internal.StringUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -105,28 +105,14 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
|
|
|
* @return
|
|
|
*/
|
|
|
public IotDeviceInfo selectByTypeAndCode(String token, String deviceType, String product, String deviceCode) {
|
|
|
- /**
|
|
|
- * RedisUtils,加入缓存机制
|
|
|
- */
|
|
|
- String key = DeviceCacheEnum.IOT_BASE_DEVICE_INFO.getCode() + token + "_" + deviceType + "_" + product + "_" + deviceCode;
|
|
|
- IotDeviceInfo info = RedisUtils.getCacheObject(key);
|
|
|
- if (info == null) {
|
|
|
- QueryWrapper<IotDeviceInfo> qw = new QueryWrapper();
|
|
|
- qw.lambda()
|
|
|
- .eq(IotDeviceInfo::getIotToken, token)
|
|
|
- .eq(IotDeviceInfo::getDeviceProduct, product)
|
|
|
- .eq(IotDeviceInfo::getDeviceType, deviceType)
|
|
|
- .eq(IotDeviceInfo::getDeviceCode, deviceCode)
|
|
|
- .orderByDesc(IotDeviceInfo::getUpdateTime)
|
|
|
- .last(Constants.LIMIT1);
|
|
|
- IotDeviceInfo one = getOne(qw);
|
|
|
- if (one != null) {
|
|
|
- updateCache(one, 1);
|
|
|
- return one;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return info;
|
|
|
+ LambdaQueryWrapper<IotDeviceInfo> qw = new LambdaQueryWrapper<>();
|
|
|
+ qw.eq(IotDeviceInfo::getIotToken, token)
|
|
|
+ .eq(IotDeviceInfo::getDeviceProduct, product)
|
|
|
+ .eq(IotDeviceInfo::getDeviceType, deviceType)
|
|
|
+ .eq(IotDeviceInfo::getDeviceCode, deviceCode)
|
|
|
+ .orderByDesc(IotDeviceInfo::getUpdateTime)
|
|
|
+ .last(Constants.LIMIT1);
|
|
|
+ return baseMapper.selectOne(qw);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -136,24 +122,14 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
|
|
|
* @return
|
|
|
*/
|
|
|
public IotDeviceInfo selectByTypeAndHostAndCode(String token, String hostCode, String product, String deviceCode) {
|
|
|
-
|
|
|
- String key = DeviceCacheEnum.IOT_CHANNEL_INFO.getCode() + token + "_" + hostCode + "_" + product + "_" + deviceCode;
|
|
|
- IotDeviceInfo info = RedisUtils.getCacheObject(key);
|
|
|
- if (info == null) {
|
|
|
- QueryWrapper<IotDeviceInfo> qw = new QueryWrapper();
|
|
|
- qw.lambda().eq(IotDeviceInfo::getIotToken, token)
|
|
|
- .eq(IotDeviceInfo::getHostCode, hostCode)
|
|
|
- .eq(IotDeviceInfo::getDeviceProduct, product)
|
|
|
- .eq(IotDeviceInfo::getDeviceCode, deviceCode)
|
|
|
- .orderByDesc(IotDeviceInfo::getUpdateTime)
|
|
|
- .last(Constants.LIMIT1);
|
|
|
- IotDeviceInfo one = getOne(qw);
|
|
|
- if (one != null) {
|
|
|
- updateCache(one, 2);
|
|
|
- return one;
|
|
|
- }
|
|
|
- }
|
|
|
- return info;
|
|
|
+ LambdaQueryWrapper<IotDeviceInfo> qw = new LambdaQueryWrapper<>();
|
|
|
+ qw.eq(IotDeviceInfo::getIotToken, token)
|
|
|
+ .eq(IotDeviceInfo::getHostCode, hostCode)
|
|
|
+ .eq(IotDeviceInfo::getDeviceProduct, product)
|
|
|
+ .eq(IotDeviceInfo::getDeviceCode, deviceCode)
|
|
|
+ .orderByDesc(IotDeviceInfo::getUpdateTime)
|
|
|
+ .last(Constants.LIMIT1);
|
|
|
+ return baseMapper.selectOne(qw);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -161,9 +137,9 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
|
|
|
public void updateDvsDevice(List<IotDeviceInfo> data) {
|
|
|
if (ObjectUtil.isNotEmpty(data)) {
|
|
|
updateBatchById(data);
|
|
|
- for (IotDeviceInfo info : data) {
|
|
|
+ /* for (IotDeviceInfo info : data) {
|
|
|
updateCache(info, 1);
|
|
|
- }
|
|
|
+ }*/
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -174,9 +150,9 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
|
|
|
return;
|
|
|
}
|
|
|
updateBatchById(channels);
|
|
|
- for (IotDeviceInfo info : channels) {
|
|
|
+ /*for (IotDeviceInfo info : channels) {
|
|
|
updateCache(info, 2);
|
|
|
- }
|
|
|
+ }*/
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -186,9 +162,9 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
|
|
|
return;
|
|
|
}
|
|
|
saveBatch(data);
|
|
|
- for (IotDeviceInfo info : data) {
|
|
|
+ /*for (IotDeviceInfo info : data) {
|
|
|
updateCache(info, 1);
|
|
|
- }
|
|
|
+ }*/
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -198,9 +174,9 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
|
|
|
return;
|
|
|
}
|
|
|
saveBatch(data);
|
|
|
- for (IotDeviceInfo info : data) {
|
|
|
+ /*for (IotDeviceInfo info : data) {
|
|
|
updateCache(info, 2);
|
|
|
- }
|
|
|
+ }*/
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -250,9 +226,9 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
|
|
|
public void saveHostDevice(List<IotDeviceInfo> data) {
|
|
|
if (ObjectUtil.isNotEmpty(data)) {
|
|
|
saveBatch(data);
|
|
|
- for (IotDeviceInfo info : data) {
|
|
|
+ /*for (IotDeviceInfo info : data) {
|
|
|
updateCache(info, 1);
|
|
|
- }
|
|
|
+ }*/
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -261,9 +237,9 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
|
|
|
public void updateHostDevice(List<IotDeviceInfo> data) {
|
|
|
if (ObjectUtil.isNotEmpty(data)) {
|
|
|
updateBatchById(data);
|
|
|
- for (IotDeviceInfo info : data) {
|
|
|
+ /*for (IotDeviceInfo info : data) {
|
|
|
updateCache(info, 1);
|
|
|
- }
|
|
|
+ }*/
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -355,6 +331,7 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
|
|
|
//设备状态数据
|
|
|
result.add(WebSocketConstants.DEVICES_STATUS_EVENT);
|
|
|
result.add(WebSocketConstants.INCREMENT_DEVICES_EVENT);
|
|
|
+ result.add(WebSocketConstants.INCREMENT_DEVICES_RESULT_EVENT);
|
|
|
return result.toString();
|
|
|
}
|
|
|
|
|
|
@@ -408,22 +385,23 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
|
|
|
|
|
|
private void dealPushDeviceResult(Object obj) {
|
|
|
final DevicePushResult result = JSON.parseObject(obj.toString(), DevicePushResult.class);
|
|
|
- LogUtils.WEBSOCKET_MSG.info("主机上报处理平台下发设备{}结果:{}", result.getDeviceName(), result);
|
|
|
+ LogUtils.SYNC_DEVICE.info("主机上报处理平台下发设备{}结果:{}", result.getDeviceName(), result);
|
|
|
if (BaseDeviceTypeEnum.Dvs.name().equals(result.getDeviceType()) && WebSocketConstants.INSERT.equals(result.getPushType())) {
|
|
|
//新增DVR的上报结果不在这里处理, 需要等待摄像头上报后修改设备同步状态
|
|
|
+ //如果新增DVR失败,那么会等redis延迟队列去处理设备的同步状态为失败
|
|
|
return;
|
|
|
}
|
|
|
if (ObjectUtil.equal(result.getStatusCode(), HttpStatus.SUCCESS)) {
|
|
|
- updateDeviceSyncStatus(result.getDeviceId(), 2);
|
|
|
+ updateDeviceSyncStatus(result.getDeviceId(), DeviceSyncStatus.SYNC_SUCCESS);
|
|
|
} else {
|
|
|
- updateDeviceSyncStatus(result.getDeviceId(), 3);
|
|
|
+ updateDeviceSyncStatus(result.getDeviceId(), DeviceSyncStatus.SYNC_FAIL);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void updateDeviceSyncStatus(Long id, int status) {
|
|
|
+ private void updateDeviceSyncStatus(Long id, DeviceSyncStatus status) {
|
|
|
if (RedisDelayedQueueUtil.removeDelayedQueue(id, RedisDelayQueueEnum.DEVICE_SYNC_STATUS_MONITOR.getCode())) {
|
|
|
final LambdaUpdateWrapper<IotDeviceInfo> wrapper = new LambdaUpdateWrapper<>();
|
|
|
- wrapper.eq(IotDeviceInfo::getId, id).set(IotDeviceInfo::getSyncStatus, status);
|
|
|
+ wrapper.eq(IotDeviceInfo::getId, id).set(IotDeviceInfo::getSyncStatus, status.getCode());
|
|
|
baseMapper.update(null, wrapper);
|
|
|
}
|
|
|
}
|
|
|
@@ -443,7 +421,7 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
|
|
|
updateHostInfo(baseInfo, hostInfo, code);
|
|
|
updateById(hostInfo);
|
|
|
}
|
|
|
- updateCache(hostInfo, 1);
|
|
|
+ //updateCache(hostInfo, 1);
|
|
|
//删除主机扩展信息
|
|
|
iIotDeviceInfoExtendService.deletedExtendByDeviceId(hostInfo.getId());
|
|
|
|
|
|
@@ -471,9 +449,9 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
|
|
|
updateChannelInfo(subDeviceInfo, channelInfo, hostInfo);
|
|
|
updateChnnelList.add(channelInfo);
|
|
|
}
|
|
|
- updateCache(channelInfo, 2);
|
|
|
+ // updateCache(channelInfo, 2);
|
|
|
}
|
|
|
- updateDeviceSyncStatus(hostInfo.getId(), 2);
|
|
|
+ updateDeviceSyncStatus(hostInfo.getId(), DeviceSyncStatus.SYNC_SUCCESS);
|
|
|
batchDealIotDeviceInfo(Lists.newLinkedList(), addChnnelList, true);
|
|
|
batchDealIotDeviceInfo(Lists.newLinkedList(), updateChnnelList, false);
|
|
|
}
|
|
|
@@ -822,9 +800,9 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
|
|
|
if (collect.isEmpty()) {
|
|
|
return;
|
|
|
}
|
|
|
- for (IotDeviceInfo info : collect) {
|
|
|
+ /* for (IotDeviceInfo info : collect) {
|
|
|
updateCache(info, 1);
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -833,9 +811,9 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
|
|
|
if (collect.isEmpty()) {
|
|
|
return;
|
|
|
}
|
|
|
- for (IotDeviceInfo info : collect) {
|
|
|
+ /*for (IotDeviceInfo info : collect) {
|
|
|
updateCache(info, 2);
|
|
|
- }
|
|
|
+ }*/
|
|
|
}
|
|
|
|
|
|
private IotAlarmSubsystem createAlarmSubSystem(SubDeviceInfo subSystemInfo, IotServerInfo serverInfo) {
|
|
|
@@ -985,11 +963,12 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
|
|
|
if (deviceInfo == null) {
|
|
|
return;
|
|
|
}
|
|
|
- if (deviceInfo.getSyncStatus() != 2) {
|
|
|
+ if (!Objects.equals(deviceInfo.getSyncStatus(), DeviceSyncStatus.SYNC_SUCCESS.getCode())) {
|
|
|
final LambdaUpdateWrapper<IotDeviceInfo> wrapper = new LambdaUpdateWrapper<>();
|
|
|
wrapper.eq(IotDeviceInfo::getId, deviceId);
|
|
|
- wrapper.set(IotDeviceInfo::getSyncStatus, 3);
|
|
|
+ wrapper.set(IotDeviceInfo::getSyncStatus, DeviceSyncStatus.SYNC_FAIL.getCode());
|
|
|
baseMapper.update(null, wrapper);
|
|
|
+ LogUtils.SYNC_DEVICE.info("延迟队列任务触发,修改设备[ {} ]同步状态为失败", deviceInfo.getDeviceName());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -997,7 +976,7 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
|
|
|
public void syncDeviceToHost(Long id) {
|
|
|
final IotDeviceInfo deviceInfo = getById(id);
|
|
|
if (ObjectUtil.isEmpty(deviceInfo)) {
|
|
|
- LogUtils.SYNC_DEVICE_TO_HOST.error("设备信息为空,id:{}", id);
|
|
|
+ LogUtils.SYNC_DEVICE.error("设备信息为空,id:{}", id);
|
|
|
}
|
|
|
final BaseDeviceTypeEnum deviceTypeEnum = BaseDeviceTypeEnum.getEnumByCode(deviceInfo.getDeviceType());
|
|
|
JSONObject param = null;
|
|
|
@@ -1022,15 +1001,11 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
|
|
|
final WebsocketResult result = WebsocketResult.invokeHostServer(topic, new JSONObject(), WebSocketConstants.PUSH_DEVICES_SERVICES, param);
|
|
|
websocketService.sendMsgByTokens(result, deviceInfo.getIotToken());
|
|
|
monitorSyncStatus(deviceInfo);
|
|
|
+ LogUtils.SYNC_DEVICE.info("同步设备[ {} ]至主机 [ {} ],设备类型:{}", deviceInfo.getDeviceName(), deviceInfo.getIotToken(), deviceTypeEnum.getDesc());
|
|
|
}
|
|
|
|
|
|
private void monitorSyncStatus(IotDeviceInfo deviceInfo) {
|
|
|
final LocalDateTime time = LocalDateTime.now().plusMinutes(5);
|
|
|
- /* final JSONObject object = new JSONObject();
|
|
|
- object.put("deviceId", deviceInfo.getId());
|
|
|
- object.put("iotCode", deviceInfo.getId());
|
|
|
- object.put("deviceProduct", deviceInfo.getId());
|
|
|
- object.put("deviceCode", deviceInfo.getId());*/
|
|
|
RedisDelayedQueueUtil.addDelayQueue(deviceInfo.getId(), time, RedisDelayQueueEnum.DEVICE_SYNC_STATUS_MONITOR.getCode());
|
|
|
}
|
|
|
|
|
|
@@ -1041,6 +1016,7 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
|
|
|
|
|
|
private JSONObject deviceInfoToJSB(IotDeviceInfo iotDeviceInfo, IotDeviceInfoExtend extend) {
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("deviceId", iotDeviceInfo.getId());
|
|
|
jsonObject.put("deviceType", BaseDeviceTypeEnum.Dvs.name());
|
|
|
jsonObject.put("deviceProduct", iotDeviceInfo.getDeviceProduct());
|
|
|
final SysMultiLayerDictionary dictionary = baseMapper.selectSysMultiLayerDictionaryById(iotDeviceInfo.getDeviceBrand());
|