Browse Source

布撤防和通断电下行控制

xujie 1 year ago
parent
commit
f07af8738f

+ 24 - 0
soc-api/soc-api-system/src/main/java/com/xunmei/system/api/Eto/BreakerControlEto.java

@@ -0,0 +1,24 @@
+package com.xunmei.system.api.Eto;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import javax.validation.constraints.NotNull;
+import java.io.Serializable;
+
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class BreakerControlEto {
+
+    //open:通电,close:断电
+    @NotNull(message = "控制指令不能为空")
+    private String command;
+
+    private Long orgId;
+
+    private Serializable id;
+}

+ 10 - 0
soc-api/soc-api-system/src/main/java/com/xunmei/system/api/RemoteHostService.java

@@ -6,6 +6,8 @@ import com.xunmei.common.core.domain.R;
 import com.xunmei.common.core.domain.host.remote.DiskInfoGetReq;
 import com.xunmei.common.core.domain.host.remote.VideoIntegrityGetReq;
 import com.xunmei.common.core.web.domain.AjaxResult;
+import com.xunmei.system.api.Eto.BreakerControlEto;
+import com.xunmei.system.api.Eto.SubSystemControlEto;
 import com.xunmei.system.api.domain.SysConfig;
 import com.xunmei.system.api.dto.SysJobDTO;
 import com.xunmei.system.api.factory.RemoteConfigFallbackFactory;
@@ -32,4 +34,12 @@ public interface RemoteHostService {
     @GetMapping("/delData")
     AjaxResult delData(@RequestParam(value = "iotCode") String iotCode);
 
+    @PostMapping("/subSystemControl")
+    AjaxResult subSystemControl(@RequestBody SubSystemControlEto eto);
+
+    @PostMapping("/breakerControlByOrgId")
+    AjaxResult breakerControlByOrgId(@RequestBody BreakerControlEto eto);
+
+    @PostMapping("/breakerControlByDeviceId")
+    AjaxResult breakerControlByDeviceId(@RequestBody BreakerControlEto eto);
 }

+ 17 - 0
soc-api/soc-api-system/src/main/java/com/xunmei/system/api/factory/RemoteHostFallbackFactory.java

@@ -4,6 +4,8 @@ import com.xunmei.common.core.domain.R;
 import com.xunmei.common.core.domain.host.remote.DiskInfoGetReq;
 import com.xunmei.common.core.domain.host.remote.VideoIntegrityGetReq;
 import com.xunmei.common.core.web.domain.AjaxResult;
+import com.xunmei.system.api.Eto.BreakerControlEto;
+import com.xunmei.system.api.Eto.SubSystemControlEto;
 import com.xunmei.system.api.RemoteConfigService;
 import com.xunmei.system.api.RemoteHostService;
 import com.xunmei.system.api.domain.SysConfig;
@@ -46,6 +48,21 @@ public class RemoteHostFallbackFactory implements FallbackFactory<RemoteHostServ
             public AjaxResult delData(String iotCode) {
                 return null;
             }
+
+            @Override
+            public AjaxResult subSystemControl(SubSystemControlEto eto) {
+                return null;
+            }
+
+            @Override
+            public AjaxResult breakerControlByOrgId(BreakerControlEto eto) {
+                return null;
+            }
+
+            @Override
+            public AjaxResult breakerControlByDeviceId(BreakerControlEto eto) {
+                return null;
+            }
         };
     }
 }

+ 7 - 2
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/resumption/controller/ProtectionController.java

@@ -14,6 +14,7 @@ import com.xunmei.core.resumption.dto.protection.ProtectionLogPageDto;
 import com.xunmei.core.resumption.dto.protection.ProtectionPageDto;
 import com.xunmei.core.resumption.service.IProtectionService;
 import com.xunmei.system.api.Eto.SubSystemControlEto;
+import com.xunmei.system.api.RemoteHostService;
 import com.xunmei.system.api.RemoteMediatorService;
 import com.xunmei.system.api.dto.ProtectionDTO;
 import com.xunmei.system.api.vo.ProtectionVO;
@@ -39,6 +40,9 @@ class ProtectionController extends BaseController {
     @Resource
     RemoteMediatorService remoteMediatorService;
 
+    @Resource
+    RemoteHostService remoteHostService;
+
     @ApiOperation(value = "分页")
     @GetMapping(value = "page")
 //    @WebMethodLogDesc("防区状态app")
@@ -113,7 +117,8 @@ class ProtectionController extends BaseController {
     @PostMapping(value = "/subSystemControl")
     //@RequiresPermissions({"device:subSystemControl"})
     AjaxResult subSystemControl(@RequestBody SubSystemControlEto eto) {
-
-        return remoteMediatorService.subSystemControl(eto);
+        //直连iot服务改为直连主机,控制指令改为调用主机服务
+        //return remoteMediatorService.subSystemControl(eto);
+        return remoteHostService.subSystemControl(eto);
     }
 }

+ 24 - 1
soc-modules/soc-modules-host/src/main/java/com/xunmei/host/north/controller/HostController.java

@@ -10,6 +10,7 @@ import com.xunmei.host.video.service.IVideoIntegrityCheckService;
 import com.xunmei.host.video.service.IotDvrHardDiskDetectionService;
 import com.xunmei.host.websocket.holder.WebSocketSessionHolder;
 import com.xunmei.host.websocket.service.WebsocketService;
+import com.xunmei.system.api.Eto.BreakerControlEto;
 import com.xunmei.system.api.Eto.SubSystemControlEto;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -69,7 +70,7 @@ public class HostController {
 
 
     @ApiOperation("布撤防控制")
-    @PostMapping({"/mediator/subSystemControl"})
+    @PostMapping({"/subSystemControl"})
     public AjaxResult subSystemControl(@RequestBody SubSystemControlEto eto) {
         try {
             alarmHostService.subSystemControl(eto.getId(), eto.getIsAlarm());
@@ -79,6 +80,28 @@ public class HostController {
         }
     }
 
+    @ApiOperation("通断电控制(组织机构)")
+    @PostMapping({"/breakerControlByOrgId"})
+    public AjaxResult breakerControlByOrgId(@RequestBody BreakerControlEto eto) {
+        try {
+            alarmHostService.breakerControlByOrgId(eto.getOrgId(), eto.getCommand());
+            return AjaxResult.success();
+        } catch (Exception r) {
+            return AjaxResult.error("通断电控制指令下发失败!");
+        }
+    }
+
+    @ApiOperation("通断电控制(设备id)")
+    @PostMapping({"/breakerControlByDeviceId"})
+    public AjaxResult breakerControlByDeviceId(@RequestBody BreakerControlEto eto) {
+        try {
+            alarmHostService.breakerControlByDeviceId(eto.getId(), eto.getCommand());
+            return AjaxResult.success();
+        } catch (Exception r) {
+            return AjaxResult.error("通断电控制指令下发失败!");
+        }
+    }
+
     @ApiOperation("关闭iot链接")
     @GetMapping({"/closeSession"})
     public AjaxResult closeSession(String iotCode) throws IOException {

+ 5 - 0
soc-modules/soc-modules-host/src/main/java/com/xunmei/host/protection/service/IIotAlarmHostService.java

@@ -9,4 +9,9 @@ public interface IIotAlarmHostService {
 
     //布撤防控制
     void subSystemControl(Serializable id,boolean isArm);
+
+    //一键上下班(通断电控制)
+    void breakerControlByOrgId(Long orgId,String command);
+
+    void breakerControlByDeviceId(Serializable id,String command);
 }

+ 68 - 0
soc-modules/soc-modules-host/src/main/java/com/xunmei/host/protection/service/impl/IotAlarmHostServiceImpl.java

@@ -28,6 +28,7 @@ import org.springframework.transaction.annotation.Transactional;
 import javax.annotation.Resource;
 import java.io.Serializable;
 import java.time.LocalDateTime;
+import java.util.List;
 import java.util.StringJoiner;
 
 @Service
@@ -175,6 +176,7 @@ public class IotAlarmHostServiceImpl implements IIotAlarmHostService, RouterServ
             if (subsystem != null) {
                 QueryWrapper<IotDeviceInfo> wrapper = new QueryWrapper<>();
                 wrapper.lambda()
+                        .eq(IotDeviceInfo::getDeleted, 0)
                         .eq(IotDeviceInfo::getDeviceCode, subsystem.getAlarmHostCode())
                         .eq(IotDeviceInfo::getIotToken, subsystem.getIotToken());
                 IotDeviceInfo deviceInfo = iIotDeviceInfoService.getOne(wrapper);
@@ -206,6 +208,72 @@ public class IotAlarmHostServiceImpl implements IIotAlarmHostService, RouterServ
         }
     }
 
+    @Override
+    public void breakerControlByOrgId(Long orgId,String command) {
+        try {
+            QueryWrapper<IotDeviceInfo> wrapper = new QueryWrapper<>();
+            wrapper.lambda()
+                    .eq(IotDeviceInfo::getDeleted, 0)
+                    .eq(IotDeviceInfo::getOrgId, orgId)
+                    .eq(IotDeviceInfo::getDeviceProduct, "FSU_DoPowerControl");
+            List<IotDeviceInfo> list = iIotDeviceInfoService.list(wrapper);
+            if (list != null && list.size() > 0) {
+                for (int i = 0; i < list.size(); i++) {
+                    IotDeviceInfo deviceInfo = list.get(i);
+                    JSONObject args = new JSONObject();
+                    args.put("command", command);
+                    String topic = "/things/" + deviceInfo.getDeviceProduct() + "/" + deviceInfo.getDeviceCode() + "/service/invoke";
+                    JSONObject headers = new JSONObject();
+                    headers.put("productName", deviceInfo.getDeviceProduct());
+                    headers.put("deviceName", deviceInfo.getDeviceCode());
+                    LogUtils.DEVICE_CONTROL_LOG.info("通断电控制topic:{},控制参数:{}", topic, args.toJSONString());
+                    WebsocketResult websocketResult = IotServerUtils.invokeHostServer(topic, headers, WebSocketConstants.BREAKER_CONTROL, args);
+                    LogUtils.WEBSOCKET_MSG.info("通断电控制指令:{}", JacksonUtils.toJSONString(websocketResult));
+                    boolean invoked = WebSocketUtils.sendMessage(deviceInfo.getIotToken(), JacksonUtils.toJSONString(websocketResult));
+                    if (!invoked) {
+                        LogUtils.DEVICE_CONTROL_LOG.error("通断电控制,指令下发iot服务失败");
+                        throw new RuntimeException();
+                    }
+                }
+            }else {
+                LogUtils.DEVICE_CONTROL_LOG.error("通断电控制,组织机构:{} 下未找到控制设备", orgId);
+            }
+        }catch (Exception e){
+            e.printStackTrace();
+            LogUtils.DEVICE_CONTROL_LOG.error("通断电控制", e);
+            throw new RuntimeException(e);
+        }
+    }
+
+    @Override
+    public void breakerControlByDeviceId(Serializable id,String command) {
+        try {
+            IotDeviceInfo deviceInfo = iIotDeviceInfoService.getById(id);
+            if (deviceInfo != null) {
+                String topic = "/things/" + deviceInfo.getDeviceProduct() + "/" + deviceInfo.getDeviceCode() + "/service/invoke";
+                JSONObject args = new JSONObject();
+                args.put("command", command);
+                JSONObject headers = new JSONObject();
+                headers.put("deviceName", deviceInfo.getDeviceCode());
+                headers.put("productName", deviceInfo.getDeviceProduct());
+                LogUtils.DEVICE_CONTROL_LOG.info("通断电控制topic:{},控制参数:{}", topic, args.toJSONString());
+                WebsocketResult websocketResult = IotServerUtils.invokeHostServer(topic, headers, WebSocketConstants.BREAKER_CONTROL, args);
+                LogUtils.WEBSOCKET_MSG.info("通断电控制:{}", JacksonUtils.toJSONString(websocketResult));
+                boolean invoked = WebSocketUtils.sendMessage(deviceInfo.getIotToken(), JacksonUtils.toJSONString(websocketResult));
+                if (!invoked) {
+                    LogUtils.DEVICE_CONTROL_LOG.error("通断电控制,指令下发iot服务失败");
+                    throw new RuntimeException();
+                }
+            }else {
+                LogUtils.DEVICE_CONTROL_LOG.error("通断电控制,未找到控制设备:{}", id);
+            }
+        }catch (Exception e){
+            e.printStackTrace();
+            LogUtils.DEVICE_CONTROL_LOG.error("通断电控制", e);
+            throw new RuntimeException(e);
+        }
+    }
+
     private void saveProtectionLog(IotAlarmSubsystem protection) {
         IotAlarmSubsystemLog protectionLog = new IotAlarmSubsystemLog();
         BeanHelper.copyProperties(protectionLog, protection);

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

@@ -145,6 +145,10 @@ public interface WebSocketConstants {
     String DAILY_HEALTH = "dailyHealth";
 
 
+    /**
+     * 8小时回路通断电控制
+     */
+    String BREAKER_CONTROL = "breakerControl";
 
     // ------------------ IOT提供的服务能力结束 ------------------