jingyuanchao преди 1 година
родител
ревизия
74f53c03e3

+ 13 - 0
soc-api/soc-api-system/src/main/java/com/xunmei/system/api/util/LogUtils.java

@@ -137,7 +137,20 @@ public class LogUtils {
      * websocket日志
      */
     public  static  final Logger WEBSOCKET_MSG=LoggerFactory.getLogger("websocketMsgLog");
+    /**
+     * websocket 设备基础信息日志
+     */
     public  static  final Logger SOCKET_BASE_DEVICE_INFO=LoggerFactory.getLogger("socketBaseDeviceInfo");
+    /**
+     * websocket 设备状态信息日志
+     */
     public  static  final Logger SOCKET_DEVICE_STATUS_INFO=LoggerFactory.getLogger("socketDeviceStatusInfo");
+    /**
+     * websocket 设备告警信息日志
+     */
     public  static  final Logger SOCKET_DEVICE_ALARM_DATA=LoggerFactory.getLogger("socketDeviceAlarmData");
+    /**
+     * websocket 子系统布撤防状态上报日志
+     */
+    public  static  final Logger SOCKET_SUBSYSTEM_STATUS_DATA=LoggerFactory.getLogger("socketSubSystemStatusData");
 }

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

@@ -53,8 +53,7 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
 
     @Autowired
     private IIotDeviceInfoExtendService iIotDeviceInfoExtendService;
-    @Autowired
-    private IotDvrDiskService iIotDvrDiskService;
+
     @Autowired
     private IotServerInfoService iotServerInfoService;
     @Autowired
@@ -81,7 +80,8 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
                     .eq(IotDeviceInfo::getIotToken, token)
                     .eq(IotDeviceInfo::getDeviceProduct, product)
                     .eq(IotDeviceInfo::getDeviceType, deviceType)
-                    .eq(IotDeviceInfo::getDeviceCode, deviceCode);
+                    .eq(IotDeviceInfo::getDeviceCode, deviceCode)
+                    .eq(IotDeviceInfo::getDeleted, 0);
             IotDeviceInfo one = getOne(qw);
             if (one != null) {
                 updateCache(one, 1);
@@ -107,7 +107,8 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
             qw.lambda().eq(IotDeviceInfo::getIotToken, token)
                     .eq(IotDeviceInfo::getHostCode, hostCode)
                     .eq(IotDeviceInfo::getDeviceProduct, product)
-                    .eq(IotDeviceInfo::getDeviceCode, deviceCode);
+                    .eq(IotDeviceInfo::getDeviceCode, deviceCode)
+                    .eq(IotDeviceInfo::getDeleted, 0);
             IotDeviceInfo one = getOne(qw);
             if (one != null) {
                 updateCache(one, 2);
@@ -443,8 +444,6 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
         //逻辑删除Dvs扩展信息
         iIotDeviceInfoExtendService.deleteDeviceExtendByTokenAndDeviceType(serverInfo.getIotCode(), BaseDeviceTypeEnum.Dvs.getCode());
         iIotDeviceInfoExtendService.deleteDeviceExtendByTokenAndDeviceType(serverInfo.getIotCode(), BaseDeviceTypeEnum.FSU.getCode());
-        //逻辑删除所有硬盘信息
-        iIotDvrDiskService.deleteByToken(serverInfo.getIotCode());
 
         List<DvsBaseInfo> dvsBaseInfoList = dataList.stream().filter(r -> ObjectUtil.equal(r.getType(), BaseDeviceTypeEnum.Dvs.name())
                 || ObjectUtil.equal(r.getType(), BaseDeviceTypeEnum.FSU.name())).collect(Collectors.toList());

+ 2 - 1
soc-modules/soc-modules-host/src/main/java/com/xunmei/host/video/service/IotDvrDiskService.java

@@ -28,7 +28,8 @@ public interface IotDvrDiskService extends IService<IotDvrDisk> {
      * 逻辑删除硬盘信息
      * @param token
      */
-    void deleteByToken(String token);
+    void deleteByTokenAndHostCode(String token,String hostCode);
+    void updateDeleteByIds(List<Long> ids);
 
     /**
      * 根据token,diskIndex查询硬盘信息

+ 63 - 30
soc-modules/soc-modules-host/src/main/java/com/xunmei/host/video/service/impl/IotDvrDiskServiceImpl.java

@@ -1,9 +1,11 @@
 package com.xunmei.host.video.service.impl;
 
+import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.util.NumberUtil;
 import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.fastjson2.JSON;
 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.extension.service.impl.ServiceImpl;
 import com.xunmei.common.core.constant.CacheConstants;
@@ -70,72 +72,103 @@ public class IotDvrDiskServiceImpl extends ServiceImpl<IotDvrDiskMapper, IotDvrD
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public void updateStatusByDiskDetection(IotDvrHardDiskDetection req,String token) {
+    public void updateStatusByDiskDetection(IotDvrHardDiskDetection req, String token) {
         final String equipmentCode = req.getEquipmentCode();
         final List<IotDvrDisk> list = lambdaQuery().eq(IotDvrDisk::getHostCode, equipmentCode).eq(IotDvrDisk::getIotToken, token).eq(IotDvrDisk::getDeleted, 0).list();
+        final List<Long> ids = list.stream().map(IotDvrDisk::getId).collect(Collectors.toList());
+        //全部逻辑删除
+        updateDeleteByIds(ids);
         final String detailInfo = req.getDetailInfo();
         final List<Map> mapList = JSON.parseArray(detailInfo, Map.class);
         List<IotDvrDisk> diskArrayList = new ArrayList<>();
         for (Map map : mapList) {
-            final String index = (String) map.get("diskSerialNum");
+            final String index = (String) map.get("index");
             if (ObjectUtil.isNull(index)) {
                 continue;
             }
-            final Optional<IotDvrDisk> first = list.stream().filter(disk -> ObjectUtil.equal(disk.getDiskIndex(), String.valueOf(index))).findFirst();
-            if (!first.isPresent()) {
-                LogUtils.STATUS_INFO_DISKS.info("硬盘检测上报消息处理磁盘状态时未找到对应磁盘,主机code:{},磁盘号:{}", equipmentCode, index);
-                continue;
+            IotDvrDisk iotDvrDisk;
+            final Optional<IotDvrDisk> first = list.stream().filter(disk -> ObjectUtil.equal(disk.getDiskIndex(), index)).findFirst();
+            if (first.isPresent()) {
+                iotDvrDisk = first.get();
+            } else {
+                iotDvrDisk = new IotDvrDisk();
+                iotDvrDisk.setCreateTime(LocalDateTime.now());
+                iotDvrDisk.setUpdateTime(LocalDateTime.now());
+                iotDvrDisk.setOrgId(req.getOrgId());
+                iotDvrDisk.setOrgName(req.getOrgName());
+                iotDvrDisk.setOrgPath(req.getOrgPath());
+                iotDvrDisk.setHostCode(req.getEquipmentCode());
+                iotDvrDisk.setIotToken(token);
+                iotDvrDisk.setDiskIndex(index);
+                iotDvrDisk.setSource(1);
             }
-            final IotDvrDisk iotDvrDisk = first.get();
-            iotDvrDisk.setState((Integer) map.get("state"));
-            iotDvrDisk.setDiskName((String) map.get("name"));
             String totalBytes = String.valueOf(map.get("totalBytes"));
-            String availableBytes = String.valueOf(map.get("availableBytes")) ;
+            String availableBytes = String.valueOf(map.get("availableBytes"));
             String originState = String.valueOf(map.get("originState"));
-            //Integer freeBytes = (Integer) map.get("freeBytes");
-
+            iotDvrDisk.setState((Integer) map.get("state"));
+            iotDvrDisk.setDiskName((String) map.get("name"));
             iotDvrDisk.setOriginState(DvrDiskOriginState.getByCodeField(originState));
             iotDvrDisk.setAvailable(new BigDecimal(availableBytes).divide(BigDecimal.valueOf(1024 * 1024), 2, RoundingMode.HALF_UP).intValue());
             iotDvrDisk.setTotal(new BigDecimal(totalBytes).divide(BigDecimal.valueOf(1024 * 1024), 2, RoundingMode.HALF_UP).intValue());
             iotDvrDisk.setStateUpdateTime(req.getCheckTime());
             iotDvrDisk.setUpdateTime(LocalDateTime.now());
+            iotDvrDisk.setDeleted(0);
             diskArrayList.add(iotDvrDisk);
         }
-        updateBatchById(diskArrayList);
+        if (CollectionUtil.isNotEmpty(diskArrayList)) {
+            saveOrUpdateBatch(diskArrayList);
+        }
+
     }
 
     /**
      * 逻辑删除磁盘信息
+     *
      * @param token
      */
     @Transactional(rollbackFor = Exception.class)
     @Override
-    public void deleteByToken(String token) {
+    public void deleteByTokenAndHostCode(String token,String hostCode) {
         UpdateWrapper<IotDvrDisk> uw = new UpdateWrapper<>();
-        uw.lambda().eq(IotDvrDisk::getIotToken,token);
-        uw.lambda().set(IotDvrDisk::getDeleted,1);
+        uw.lambda().eq(IotDvrDisk::getIotToken, token);
+        uw.lambda().eq(IotDvrDisk::getHostCode, hostCode);
+        uw.lambda().set(IotDvrDisk::getDeleted, 1);
         update(uw);
     }
 
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void updateDeleteByIds(List<Long> ids) {
+        if (ObjectUtil.isEmpty(ids)){
+            return;
+        }
+        final LambdaUpdateWrapper<IotDvrDisk> wrapper = new LambdaUpdateWrapper<>();
+        wrapper.in(IotDvrDisk::getId, ids);
+        wrapper.set(IotDvrDisk::getDeleted, 1);
+        update(wrapper);
+    }
+
     /**
      * 获取磁盘信息
+     *
      * @param token
      * @param hostCode
      * @param diskIndex
      * @return
      */
     @Override
-    public IotDvrDisk selectByTokenAndDiskIndex(String token, String hostCode,String diskIndex) {
-        String key = DVR_DISK_KEY + token + "_"+hostCode + "_" + diskIndex;
-        IotDvrDisk info =  RedisUtils.getCacheObject(key);
-        if(info == null){
+    public IotDvrDisk selectByTokenAndDiskIndex(String token, String hostCode, String diskIndex) {
+        String key = DVR_DISK_KEY + token + "_" + hostCode + "_" + diskIndex;
+        IotDvrDisk info = RedisUtils.getCacheObject(key);
+        if (info == null) {
             QueryWrapper<IotDvrDisk> qw = new QueryWrapper<>();
-            qw.lambda().eq(IotDvrDisk::getIotToken,token)
-                    .eq(IotDvrDisk::getHostCode,hostCode)
-                    .eq(IotDvrDisk::getDiskIndex,diskIndex);
+            qw.lambda().eq(IotDvrDisk::getIotToken, token)
+                    .eq(IotDvrDisk::getHostCode, hostCode)
+                    .eq(IotDvrDisk::getDeleted, 0)
+                    .eq(IotDvrDisk::getDiskIndex, diskIndex);
             IotDvrDisk one = getOne(qw);
-            if(one != null){
-                RedisUtils.setCacheObject(key,one, Duration.ofMillis(1000 * 60 * 60));
+            if (one != null) {
+                RedisUtils.setCacheObject(key, one, Duration.ofMillis(1000 * 60 * 60));
             }
             return one;
         }
@@ -145,11 +178,11 @@ public class IotDvrDiskServiceImpl extends ServiceImpl<IotDvrDiskMapper, IotDvrD
     @Override
     @Transactional(rollbackFor = Exception.class)
     public void updateBatchDisks(List<IotDvrDisk> iotDvrDisks) {
-        if(ObjectUtil.isNotEmpty(iotDvrDisks)){
+        if (ObjectUtil.isNotEmpty(iotDvrDisks)) {
             updateBatchById(iotDvrDisks);
             for (IotDvrDisk iotDvrDisk : iotDvrDisks) {
                 String key = DVR_DISK_KEY + iotDvrDisk.getIotToken() + "_" + iotDvrDisk.getHostCode() + "_" + iotDvrDisk.getDiskIndex();
-                RedisUtils.setCacheObject(key,iotDvrDisk, Duration.ofMillis(1000 * 60 * 60));
+                RedisUtils.setCacheObject(key, iotDvrDisk, Duration.ofMillis(1000 * 60 * 60));
             }
         }
     }
@@ -157,11 +190,11 @@ public class IotDvrDiskServiceImpl extends ServiceImpl<IotDvrDiskMapper, IotDvrD
     @Override
     @Transactional(rollbackFor = Exception.class)
     public void saveBatchDisks(List<IotDvrDisk> iotDvrDisks) {
-        if(ObjectUtil.isNotEmpty(iotDvrDisks)){
+        if (ObjectUtil.isNotEmpty(iotDvrDisks)) {
             saveBatch(iotDvrDisks);
             for (IotDvrDisk iotDvrDisk : iotDvrDisks) {
                 String key = DVR_DISK_KEY + iotDvrDisk.getIotToken() + "_" + iotDvrDisk.getHostCode() + "_" + iotDvrDisk.getDiskIndex();
-                RedisUtils.setCacheObject(key,iotDvrDisk, Duration.ofMillis(1000 * 60 * 60));
+                RedisUtils.setCacheObject(key, iotDvrDisk, Duration.ofMillis(1000 * 60 * 60));
             }
         }
     }
@@ -256,7 +289,7 @@ public class IotDvrDiskServiceImpl extends ServiceImpl<IotDvrDiskMapper, IotDvrD
             List<IotDvrDisk> diskList = listMap.get(hostDeviceOptional.get().getEquipmentCode());
             List<DvrdiskDto> diskSpaces = pageDto.getDiskSpace();
             if (ObjectUtil.isNull(diskList)) {
-                diskList=new ArrayList<>();
+                diskList = new ArrayList<>();
             }
             for (DvrdiskDto dto : diskSpaces) {
                 List<String> fields = new ArrayList<>();

+ 3 - 2
soc-modules/soc-modules-host/src/main/java/com/xunmei/host/video/service/impl/IotDvrHardDiskDetectionServiceImpl.java

@@ -101,10 +101,11 @@ public class IotDvrHardDiskDetectionServiceImpl extends ServiceImpl<IotDvrHardDi
             dto.setDeviceName(req.getDeviceName());
             dto.setProductName(req.getProductName());
             final ReceiveErrorDto res = saveData(dto, req.getId());
+            return null;
             //构建返回数据
-            String topic = req.getTopic() + "/reply";
+           /* String topic = req.getTopic() + "/reply";
             final JSONObject errorDto = IotServerUtils.dealReceiveErrorDto(res);
-            return IotServerUtils.invokeUpLinkServer(topic, req.getProductName(), req.getDeviceName(), req.getEvent(), errorDto, req.getId());
+            return IotServerUtils.invokeUpLinkServer(topic, req.getProductName(), req.getDeviceName(), req.getEvent(), errorDto, req.getId());*/
         } catch (IllegalAccessException e) {
             throw new RuntimeException(e);
         }

+ 21 - 0
soc-modules/soc-modules-host/src/main/resources/logback.xml

@@ -104,6 +104,23 @@
         </encoder>
     </appender>
 
+    <!-- 子系统布撤防状态上报日志  -->
+    <appender name="socketSubSystemStatusData" class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
+            <maxFileSize>${max.file.size}</maxFileSize>
+            <!--日志文件输出的文件名-->
+            <FileNamePattern>${LOG_HOME}/socketSubSystemStatusData/%d{yyyy-MM-dd}-%i.log</FileNamePattern>
+            <!--日志文件保留天数-->
+            <maxHistory>${max.history}</maxHistory>
+            <totalSizeCap>${total.size.cap}</totalSizeCap>
+            <cleanHistoryOnStart>true</cleanHistoryOnStart>
+        </rollingPolicy>
+        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
+            <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
+            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
+        </encoder>
+    </appender>
+
 
     <logger name="websocketMsgLog" additivity="false" level="info">
         <!--上面appender元素的name值。为了和logger的name属性做区分,我故意写的不一样-->
@@ -122,6 +139,10 @@
         <!--上面appender元素的name值。为了和logger的name属性做区分,我故意写的不一样-->
         <appender-ref ref="socketDeviceAlarmData"/>
     </logger>
+    <logger name="socketSubSystemStatusData" additivity="false" level="info">
+        <!--上面appender元素的name值。为了和logger的name属性做区分,我故意写的不一样-->
+        <appender-ref ref="socketSubSystemStatusData"/>
+    </logger>
 
     <!-- 日志输出级别 -->
     <root level="INFO">

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

@@ -80,7 +80,7 @@ public class IotAlarmHostServiceImpl implements IIotAlarmHostService, RouterServ
     @Transactional(rollbackFor = Exception.class)
     public void changeSubSystemStatus(WebsocketExecuteReq req) {
         try {
-            LogUtils.STATUS_INFO_DEFENCEAREA.info("【iot服务报警主机布撤防状态变更事件】【iotToken:{}】【msgId:{}】【接收参数:{}】", req.getToken(), req.getId(), JSON.toJSONString(req));
+            LogUtils.SOCKET_SUBSYSTEM_STATUS_DATA.info("【iot服务报警主机布撤防状态变更事件】【iotToken:{}】【msgId:{}】【接收参数:{}】", req.getToken(), req.getId(), JSON.toJSONString(req));
             if (req.getData() != null) {
                 JSONObject object = (JSONObject) req.getData();
                 Integer subSystemId = object.getInteger("id");
@@ -94,25 +94,27 @@ public class IotAlarmHostServiceImpl implements IIotAlarmHostService, RouterServ
                         .eq(IotAlarmSubsystem::getDeleted, 0);
                 IotAlarmSubsystem subsystem = subsystemService.getOne(wrapper);
 
-                if (subsystem != null) {
-                    Integer dbStatus = subsystem.getStatus();
-                    //Arm:布防 DisArm:撤防 Unknown:未知
-                    //0:撤防,1:布防,2:未知
-                    if ("arm".equals(status)) {
-                        subsystem.setStatus(ProtectionStatus.PROTECTION.ordinal());
-                    } else if ("disArm".equals(status)) {
-                        subsystem.setStatus(ProtectionStatus.REMOVAL.ordinal());
-                    } else {
-                        subsystem.setStatus(ProtectionStatus.UNKNOWN.ordinal());
-                    }
-                    subsystem.setStatusUpdateTime(LocalDateTime.now());
-                    if (ObjectUtil.notEqual(subsystem.getStatus(), dbStatus)) {
-                        subsystem.setStatusChangeTime(LocalDateTime.now());
-                    }
-                    subsystemService.updateById(subsystem);
-
-                    this.saveProtectionLog(subsystem);
+                if (subsystem == null) {
+                    LogUtils.SOCKET_SUBSYSTEM_STATUS_DATA.error("【iot服务报警主机布撤防状态变更事件】【iotToken:{}】【msgId:{}】未能找到对应子系统", req.getToken(), req.getId() );
+                    return;
                 }
+                Integer dbStatus = subsystem.getStatus();
+                //Arm:布防 DisArm:撤防 Unknown:未知
+                //0:撤防,1:布防,2:未知
+                if ("arm".equals(status)) {
+                    subsystem.setStatus(ProtectionStatus.PROTECTION.ordinal());
+                } else if ("disArm".equals(status)) {
+                    subsystem.setStatus(ProtectionStatus.REMOVAL.ordinal());
+                } else {
+                    subsystem.setStatus(ProtectionStatus.UNKNOWN.ordinal());
+                }
+                subsystem.setStatusUpdateTime(LocalDateTime.now());
+                if (ObjectUtil.notEqual(subsystem.getStatus(), dbStatus)) {
+                    subsystem.setStatusChangeTime(LocalDateTime.now());
+                }
+                subsystemService.updateById(subsystem);
+
+                this.saveProtectionLog(subsystem);
             }
         } catch (Exception e) {
             e.printStackTrace();