jingyuanchao 11 сар өмнө
parent
commit
74b3f70bae

+ 3 - 1
soc-api/soc-api-system/src/main/java/com/xunmei/system/api/RemoteHostService.java

@@ -12,7 +12,6 @@ import com.xunmei.system.api.factory.RemoteHostFallbackFactory;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.web.bind.annotation.*;
 
-import java.util.List;
 import java.util.Set;
 
 @FeignClient(contextId = "remoteHostService", value = ServiceNameConstants.HOST, fallbackFactory = RemoteHostFallbackFactory.class)
@@ -75,4 +74,7 @@ public interface RemoteHostService {
 
     @GetMapping("/syncDevice/{id}")
     AjaxResult syncDeviceToHost(@PathVariable("id") Long id);
+
+    @GetMapping("/deletedDeviceAndSyncToHost/{id}")
+    AjaxResult deletedDeviceAndSyncToHost(@PathVariable("id") Long id);
 }

+ 5 - 1
soc-api/soc-api-system/src/main/java/com/xunmei/system/api/factory/RemoteHostFallbackFactory.java

@@ -13,7 +13,6 @@ import org.slf4j.LoggerFactory;
 import org.springframework.cloud.openfeign.FallbackFactory;
 import org.springframework.stereotype.Component;
 
-import java.util.List;
 import java.util.Set;
 
 @Component
@@ -87,6 +86,11 @@ public class RemoteHostFallbackFactory implements FallbackFactory<RemoteHostServ
             public AjaxResult syncDeviceToHost(Long id) {
                 return null;
             }
+
+            @Override
+            public AjaxResult deletedDeviceAndSyncToHost(Long id) {
+                return null;
+            }
         };
     }
 }

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

@@ -90,4 +90,6 @@ public interface IIotDeviceInfoService extends IService<IotDeviceInfo> {
     void changeDevice(ControlDeviceDto eto);
 
     void syncDeviceToHost(Long id);
+
+    void deletedDeviceAndSyncToHost(Long id);
 }

+ 20 - 0
soc-modules/soc-modules-host/src/main/java/com/xunmei/host/iot/service/impl/IotDeviceInfoServiceImpl.java

@@ -1387,4 +1387,24 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
 
         return object;
     }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void deletedDeviceAndSyncToHost(Long id) {
+        final IotDeviceInfo deviceInfo = getById(id);
+        if (deviceInfo == null) {
+            return;
+        }
+        final BaseDeviceTypeEnum deviceTypeEnum = BaseDeviceTypeEnum.getEnumByCode(deviceInfo.getDeviceType());
+        JSONObject param = new JSONObject();
+        param.put("deviceType", deviceTypeEnum.name());
+        param.put("deviceCode", deviceInfo.getDeviceCode());
+        param.put("deviceProduct", deviceInfo.getDeviceProduct());
+
+        final String topic = TopicTypeEnums.formatUrl(TopicTypeEnums.PRODUCT_SERVICE_INVOKE.getUrl(), WebSocketConstants.DETECTION_HOST, WebSocketConstants.DETECTION_HOST_DEVICE);
+        final WebsocketResult result = WebsocketResult.invokeHostServer(topic, new JSONObject(), WebSocketConstants.DELETED_DEVICES_SERVICES, param);
+        websocketService.sendMsgByTokens(result, deviceInfo.getIotToken());
+        monitorSyncStatus(deviceInfo);
+        LogUtils.SYNC_DEVICE.info("设备[ {} ]已被删除,同步至主机 [ {} ],设备类型:{}", deviceInfo.getDeviceName(), deviceInfo.getIotToken(), deviceTypeEnum.getDesc());
+    }
 }

+ 6 - 0
soc-modules/soc-modules-host/src/main/java/com/xunmei/host/north/controller/HostController.java

@@ -126,4 +126,10 @@ public class HostController {
         deviceInfoService.syncDeviceToHost(id);
         return AjaxResult.success();
     }
+
+    @GetMapping("/deletedDeviceAndSyncToHost/{id}")
+    AjaxResult deletedDeviceAndSyncToHost(@PathVariable("id") Long id) {
+        deviceInfoService.deletedDeviceAndSyncToHost(id);
+        return AjaxResult.success();
+    }
 }

+ 4 - 0
soc-modules/soc-modules-host/src/main/java/com/xunmei/host/websocket/constant/WebSocketConstants.java

@@ -152,6 +152,10 @@ public interface WebSocketConstants {
      */
     String PUSH_DEVICES_SERVICES = "pushDevice";
     /**
+     * 平台推送删除主机基础信息 服务名称
+     */
+    String DELETED_DEVICES_SERVICES = "deletedDevice";
+    /**
      * 增量设备数据 上送平台
      */
     String INCREMENT_DEVICES_EVENT = "incrementDevices";

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

@@ -99,7 +99,7 @@ public class IotDeviceInfoController {
     }
 
     @ApiOperation("删除设备")
-    @GetMapping({"/deletedDevice/{id}"})
+    @GetMapping({"/deleted/{id}"})
     AjaxResult deletedDevice(@PathVariable Long id) {
         deviceInfoService.deletedDevice(id);
         return AjaxResult.success();

+ 1 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/impl/IotDeviceInfoServiceImpl.java

@@ -608,6 +608,7 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
 
         }
         extendService.updateDeletedByDeviceId(deviceId);
+        remoteHostService.deletedDeviceAndSyncToHost(deviceId);
 
     }