Browse Source

布撤防控制代码和获取iot服务基础数据修改

xujie 1 năm trước cách đây
mục cha
commit
5742399e9c

+ 21 - 0
soc-api/soc-api-system/src/main/java/com/xunmei/system/api/Eto/SubSystemControlEto.java

@@ -0,0 +1,21 @@
+package com.xunmei.system.api.Eto;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import javax.validation.constraints.NotNull;
+
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class SubSystemControlEto {
+
+    @NotNull(message = "报警控制器id不能为空")
+    private Long id;
+
+    @NotNull(message = "控制指令不能为空")
+    private Boolean isAlarm;
+}

+ 6 - 0
soc-api/soc-api-system/src/main/java/com/xunmei/system/api/RemoteMediatorService.java

@@ -2,9 +2,12 @@ package com.xunmei.system.api;
 
 import com.xunmei.common.core.constant.ServiceNameConstants;
 import com.xunmei.common.core.web.domain.AjaxResult;
+import com.xunmei.system.api.Eto.SubSystemControlEto;
 import com.xunmei.system.api.factory.RemoteMediatorFallbackFactory;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 
 /**
  * 字典服务
@@ -30,4 +33,7 @@ public interface RemoteMediatorService {
 
     @GetMapping("/mediator/baseDeviceInfo")
     AjaxResult baseDeviceInfo();
+
+    @PostMapping("/mediator/subSystemControl")
+    AjaxResult subSystemControl(@RequestBody SubSystemControlEto eto);
 }

+ 6 - 0
soc-api/soc-api-system/src/main/java/com/xunmei/system/api/factory/RemoteMediatorFallbackFactory.java

@@ -1,6 +1,7 @@
 package com.xunmei.system.api.factory;
 
 import com.xunmei.common.core.web.domain.AjaxResult;
+import com.xunmei.system.api.Eto.SubSystemControlEto;
 import com.xunmei.system.api.RemoteMediatorService;
 
 import org.slf4j.Logger;
@@ -35,6 +36,11 @@ public class RemoteMediatorFallbackFactory implements FallbackFactory<RemoteMedi
             public AjaxResult baseDeviceInfo() {
                 return null;
             }
+
+            @Override
+            public AjaxResult subSystemControl(SubSystemControlEto eto) {
+                return null;
+            }
         };
     }
 }

+ 13 - 0
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/resumption/controller/ProtectionController.java

@@ -13,6 +13,8 @@ import com.xunmei.core.resumption.dto.protection.ProtectionEditDto;
 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.RemoteMediatorService;
 import com.xunmei.system.api.dto.ProtectionDTO;
 import com.xunmei.system.api.vo.ProtectionVO;
 import io.swagger.annotations.Api;
@@ -34,6 +36,9 @@ class ProtectionController extends BaseController {
     @Resource
     IProtectionService protectionService;
 
+    @Resource
+    RemoteMediatorService remoteMediatorService;
+
     @ApiOperation(value = "分页")
     @GetMapping(value = "page")
 //    @WebMethodLogDesc("防区状态app")
@@ -103,4 +108,12 @@ class ProtectionController extends BaseController {
     public void export(ProtectionPageDto pageDto, HttpServletResponse response) throws Exception {
         protectionService.export(pageDto, response);
     }
+
+    @ApiOperation(value = "布撤防控制")
+    @PostMapping(value = "/subSystemControl")
+    //@RequiresPermissions({"device:subSystemControl"})
+    AjaxResult subSystemControl(@RequestBody SubSystemControlEto eto) {
+
+        return remoteMediatorService.subSystemControl(eto);
+    }
 }

+ 24 - 0
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/resumption/vo/protection/ProtectionPageVo.java

@@ -94,6 +94,30 @@ public class ProtectionPageVo {
 
     @ExcelIgnore
     private Integer inBook;
+
+    /**
+     * 子系统编号
+     */
+    @ExcelIgnore
+    private String code;
+
+    /**
+     * 设备唯一编码
+     */
+    @ExcelIgnore
+    private String deviceCode;
+
+    /**
+     * iotToken
+     */
+    @ExcelIgnore
+    private String iotToken;
+
+    /**
+     * 数据来源 0.页面设备添加 1.报警主机
+     */
+    @ExcelIgnore
+    private Integer source;
 }
 
 

+ 5 - 1
soc-modules/soc-modules-core/src/main/resources/mapper/device/ProtectionMapper.xml

@@ -24,7 +24,11 @@
         a.status_change_time as statusChangeTime,
         c.affiliated_area ,
         c.affiliated_bank,
-        a.in_book
+        a.in_book,
+        a.code as code,
+        a.alarm_host_code as deviceCode,
+        a.iot_token as iotToken,
+        a.source
         from iot_alarm_subsystem a
         inner join sys_org c on a.org_id = c.id and c.deleted=0
         <if test="request.checkSub==true">

+ 18 - 0
soc-modules/soc-modules-mediator/src/main/java/com/xunmei/mediator/api/north/controller/MediatorController.java

@@ -3,10 +3,14 @@ package com.xunmei.mediator.api.north.controller;
 
 import com.xunmei.common.core.web.domain.AjaxResult;
 import com.xunmei.mediator.api.host.service.IIotDvrChannelService;
+import com.xunmei.mediator.api.protection.service.IIotAlarmHostService;
 import com.xunmei.mediator.api.video.service.IVideoIntegrityCheckService;
 import com.xunmei.mediator.websocket.service.WebsocketService;
+import com.xunmei.system.api.Eto.SubSystemControlEto;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
@@ -30,6 +34,9 @@ public class MediatorController {
     @Resource
     WebsocketService websocketService;
 
+    @Resource
+    IIotAlarmHostService alarmHostService;
+
 
     @ApiOperation("处理缓存中的通道信息数据")
     @GetMapping({"/mediator/channelCacheDeal"})
@@ -74,4 +81,15 @@ public class MediatorController {
         websocketService.invokeAlarmHostBaseInfoForSchedule();
         return AjaxResult.success();
     }
+
+    @ApiOperation("布撤防控制")
+    @PostMapping({"/mediator/subSystemControl"})
+    public AjaxResult subSystemControl(@RequestBody SubSystemControlEto eto) {
+        try {
+            alarmHostService.subSystemControl(eto.getId(),eto.getIsAlarm());
+            return AjaxResult.success();
+        }catch (Exception r){
+            return AjaxResult.error("布撤防控制指令下发失败!");
+        }
+    }
 }

+ 10 - 1
soc-modules/soc-modules-mediator/src/main/java/com/xunmei/mediator/api/protection/service/impl/IotAlarmHostServiceImpl.java

@@ -137,7 +137,16 @@ public class IotAlarmHostServiceImpl implements IIotAlarmHostService, RouterServ
                     args.put("isArm",isArm);
                     String topic = "/things/" + deviceInfo.getDeviceProduct() + "/" + deviceInfo.getDeviceCode() + "/service/invoke";
                     LogUtils.DEVICE_CONTROL_LOG.info("报警主机布撤防控制topic:{},控制参数:{}",topic,args.toJSONString());
-                    IotServerUtils.invokeIotServer(topic,WebSocketConstants.SUB_SYSTEM_CONTROL,args);
+                    WebsocketResult websocketResult = IotServerUtils.invokeIotServer(topic, WebSocketConstants.SUB_SYSTEM_CONTROL, args);
+                    LogUtils.WEBSOCKET_MSG.info("布撤防控制指令:{}", JacksonUtils.toJSONString(websocketResult));
+                    boolean invoked = WebSocketSessionHolder.sendMessage(subsystem.getIotToken(), JacksonUtils.toJSONString(websocketResult));
+                    if (!invoked){
+                        LogUtils.DEVICE_CONTROL_LOG.error("报警主机布撤防控制失败,指令下发iot服务失败");
+                        throw new RuntimeException();
+                    }
+                }else {
+                    LogUtils.DEVICE_CONTROL_LOG.error("报警主机布撤防控制失败,未找到对应的报警主机,报警控制器编码:{}",id);
+                    throw new RuntimeException();
                 }
             }
         }catch (Exception e){

+ 17 - 0
soc-modules/soc-modules-mediator/src/main/java/com/xunmei/mediator/websocket/holder/WebSocketSessionHolder.java

@@ -134,4 +134,21 @@ public class WebSocketSessionHolder {
             log.error("消息广播失败:{}", e);
         }
     }
+
+    public static boolean sendMessage(String token,String message) {
+        try {
+            WebSocketSession webSocketSession = USER_SESSION_MAP.get(token);
+            if (null == webSocketSession){
+                LogUtils.WEBSOCKET_MSG.error("消息广播失败,未找到对应在线的iot服务,iot服务:{},消息内容:{}", token,message);
+                return false;
+            }
+            webSocketSession.sendMessage(new TextMessage(message));
+            String hostAddress = webSocketSession.getRemoteAddress().getAddress().getHostAddress();
+            LogUtils.WEBSOCKET_MSG.info("消息广播成功,发送目标ip:{},消息内容:{}", hostAddress, message);
+            return true;
+        } catch (IOException e) {
+            log.error("消息广播失败:{}", e);
+            return false;
+        }
+    }
 }

+ 11 - 6
soc-modules/soc-modules-mediator/src/main/java/com/xunmei/mediator/websocket/service/impl/WebsocketServiceImpl.java

@@ -30,6 +30,7 @@ import com.xunmei.mediator.websocket.dto.dvs.DiskInfo;
 import com.xunmei.mediator.websocket.dto.dvs.DvsBaseInfo;
 import com.xunmei.mediator.websocket.dto.dvs.DvsInfo;
 import com.xunmei.mediator.websocket.enums.ProductEnums;
+import com.xunmei.mediator.websocket.holder.WebSocketSessionHolder;
 import com.xunmei.mediator.websocket.redis.WebsocketPublisher;
 import com.xunmei.mediator.websocket.service.RouterService;
 import com.xunmei.mediator.websocket.service.WebsocketService;
@@ -85,10 +86,12 @@ public class WebsocketServiceImpl implements WebsocketService, RouterService {
 
     @Override
     public void invokeBaseDeviceInfoForSchedule() {
-        List<String> categories = Arrays.asList(WebSocketConstants.DVS, WebSocketConstants.ALARM_HOST);
+        List<String> categories = Arrays.asList(WebSocketConstants.DVS, WebSocketConstants.ALARM_HOST, WebSocketConstants.FSU_GATEWAY);
         JSONObject args = new JSONObject();
         args.put("categories", categories);
-        IotServerUtils.invokeIotServer(iotServerDeviceTopic, WebSocketConstants.GET_DEVICE_BASE_INFOS, args);
+        WebsocketResult websocketResult = IotServerUtils.invokeIotServer(iotServerDeviceTopic, WebSocketConstants.GET_DEVICE_BASE_INFOS, args);
+        LogUtils.WEBSOCKET_MSG.info("获取设备基础数据:{}", JacksonUtils.toJSONString(websocketResult));
+        WebSocketSessionHolder.sendAll(JacksonUtils.toJSONString(websocketResult));
     }
 
     @Override
@@ -96,8 +99,9 @@ public class WebsocketServiceImpl implements WebsocketService, RouterService {
         String[] productNames = ProductEnums.DVS.getProductName();
         JSONObject args = new JSONObject();
         args.put("productNames", productNames);
-
-        IotServerUtils.invokeIotServer(iotServerDeviceTopic, WebSocketConstants.GET_DVS_DEVICE_INFOS, args);
+        WebsocketResult websocketResult = IotServerUtils.invokeIotServer(iotServerDeviceTopic, WebSocketConstants.GET_DVS_DEVICE_INFOS, args);
+        LogUtils.WEBSOCKET_MSG.info("获取dvs下基础数据:{}", JacksonUtils.toJSONString(websocketResult));
+        WebSocketSessionHolder.sendAll(JacksonUtils.toJSONString(websocketResult));
     }
 
     @Override
@@ -105,8 +109,9 @@ public class WebsocketServiceImpl implements WebsocketService, RouterService {
         String[] productNames = ProductEnums.ALARM_HOST.getProductName();
         JSONObject args = new JSONObject();
         args.put("productNames", productNames);
-
-        IotServerUtils.invokeIotServer(iotServerDeviceTopic, WebSocketConstants.GET_ALARM_HOST_DEVICE_INFOS, args);
+        WebsocketResult websocketResult = IotServerUtils.invokeIotServer(iotServerDeviceTopic, WebSocketConstants.GET_ALARM_HOST_DEVICE_INFOS, args);
+        LogUtils.WEBSOCKET_MSG.info("获取报警主机下数据:{}", JacksonUtils.toJSONString(websocketResult));
+        WebSocketSessionHolder.sendAll(JacksonUtils.toJSONString(websocketResult));
     }
 
     /**

+ 0 - 2
soc-modules/soc-modules-mediator/src/main/java/com/xunmei/mediator/websocket/utils/IotServerUtils.java

@@ -8,7 +8,6 @@ import com.xunmei.mediator.websocket.constant.WebSocketConstants;
 import com.xunmei.mediator.websocket.dto.WebsocketResult;
 import com.xunmei.mediator.websocket.enums.TopicTypeEnums;
 import com.xunmei.mediator.websocket.holder.WebSocketSessionHolder;
-import com.xunmei.system.api.util.LogUtils;
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -31,7 +30,6 @@ public class IotServerUtils {
         hashMap.put(WebSocketConstants.SERVICE, service);
         hashMap.put(WebSocketConstants.ARGS, args);
         websocketResult.setPayload(hashMap);
-        WebSocketSessionHolder.sendAll(JacksonUtils.toJSONString(websocketResult));
         return websocketResult;
     }