浏览代码

设备同步代码提交

jingyuanchao 11 月之前
父节点
当前提交
31aaff04ef

+ 7 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/controller/IotDeviceInfoController.java

@@ -90,4 +90,11 @@ public class IotDeviceInfoController {
     AjaxResult baseDeviceGet() {
         return AjaxResult.success(remoteHostService.getDevices());
     }
+
+    @ApiOperation("同步设备")
+    @GetMapping({"/reSyncDevice/{id}"})
+    AjaxResult reSyncDevice(@PathVariable Long id) {
+        deviceInfoService.reSyncDevice(id);
+        return AjaxResult.success();
+    }
 }

+ 3 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/IIotDeviceInfoService.java

@@ -45,4 +45,7 @@ public interface IIotDeviceInfoService extends IService<IotDeviceInfo> {
     Integer editNetHostDevice(EditNetHostDeviceDto req);
 
     NetHostDeviceInfoVo netHostDeviceInfo(Long id);
+
+    Integer reSyncDevice(Long id);
+
 }

+ 13 - 5
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/impl/IotDeviceInfoServiceImpl.java

@@ -69,6 +69,7 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
     private IotDeviceInfoExtendService extendService;
     @Resource
     private ApplicationEventPublisher eventPublisher;
+
     @Override
     public TableDataInfo<IotDeviceInfoPageVo> deviceInfoPage(IotDeviceInfoPageDto request) {
         if (request.getCheckSub()) {
@@ -222,7 +223,7 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
         }
 
         extendService.updateByDeviceId(deviceId, req);
-        eventPublisher.publishEvent(new DeviceSyncEvent(this,deviceId));
+        eventPublisher.publishEvent(new DeviceSyncEvent(this, deviceId));
         return effect;
     }
 
@@ -312,7 +313,7 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
         }
 
         updateAddAlarmHostDevice(req);
-        eventPublisher.publishEvent(new DeviceSyncEvent(this,deviceId));
+        eventPublisher.publishEvent(new DeviceSyncEvent(this, deviceId));
         return 1;
     }
 
@@ -498,7 +499,7 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
             deviceInfo = new IotDeviceInfo();
             deviceInfo.setCreateTime(new Date());
             deviceInfo.setCreateBy(sysUser.getId().toString());
-        }else {
+        } else {
             deviceInfo = getById(req.getId());
         }
         BeanUtil.copyProperties(req, deviceInfo);
@@ -529,7 +530,7 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
         deviceInfo.setDeleted(0);
         saveOrUpdate(deviceInfo);
         extendService.updateNetHostExtendByDeviceId(deviceInfo.getId(), req);
-        eventPublisher.publishEvent(new DeviceSyncEvent(this,deviceInfo.getId()));
+        eventPublisher.publishEvent(new DeviceSyncEvent(this, deviceInfo.getId()));
         return 1;
     }
 
@@ -540,7 +541,7 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
         if (deviceInfo == null) {
             throw new RuntimeException("设备不存在");
         }
-        NetHostDeviceInfoVo resp=new NetHostDeviceInfoVo();
+        NetHostDeviceInfoVo resp = new NetHostDeviceInfoVo();
         final IotDeviceInfoExtend extend = extendService.findByDeviceId(id);
         BeanUtil.copyProperties(deviceInfo, resp);
         resp.setIotCode(deviceInfo.getIotToken());
@@ -548,4 +549,11 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
         resp.setServerIp(extend.getNetAddress());
         return resp;
     }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public Integer reSyncDevice(Long id) {
+        eventPublisher.publishEvent(new DeviceSyncEvent(this, id));
+        return 1;
+    }
 }