Selaa lähdekoodia

Merge remote-tracking branch 'origin/V0.0.6-iot' into V0.0.6-iot

jingyuanchao 1 vuosi sitten
vanhempi
commit
fd55f838a6
25 muutettua tiedostoa jossa 462 lisäystä ja 102 poistoa
  1. 3 1
      project_data/sql/0.0.6-iot/soc/soc.sql
  2. 4 0
      soc-common/soc-common-core/src/main/java/com/xunmei/common/core/domain/mediator/domain/IotAlarmData.java
  3. 2 2
      soc-modules/soc-modules-core/src/main/java/com/xunmei/core/resumption/vo/protection/ProtectionLogPageVo.java
  4. 1 1
      soc-modules/soc-modules-core/src/main/resources/mapper/device/ProtectionLogMapper.xml
  5. 4 0
      soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/dto/alarm/IotAlarmRuleSourceDeviceDto.java
  6. 2 61
      soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/dto/dvrDisk/DvrDiskPageDto.java
  7. 4 14
      soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/dto/videoDiagnosis/VideoDiagnosisAppPageDto.java
  8. 4 0
      soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/dto/videoDiagnosis/VideoDiagnosisWebPageDto.java
  9. 8 0
      soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/mapper/IotAlarmRuleSourceMapper.java
  10. 15 4
      soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/impl/IotAlarmRuleServiceImpl.java
  11. 7 3
      soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/impl/IotAlarmRuleSourceServiceImpl.java
  12. 4 1
      soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/impl/VideoDiagnosisServiceImpl.java
  13. 27 0
      soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/vo/alarm/IotAlarmRuleSourceTotalVo.java
  14. 4 0
      soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/vo/alarm/IotInitAlarmRuleVo.java
  15. 5 0
      soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/vo/alarm/ProductDeviceTempVo.java
  16. 6 1
      soc-modules/soc-modules-iot/src/main/resources/mapper/DvrDiskMapper.xml
  17. 25 7
      soc-modules/soc-modules-iot/src/main/resources/mapper/IotAlarmRuleSourceMapper.xml
  18. 1 1
      soc-modules/soc-modules-iot/src/main/resources/mapper/IotDvrChannelMapper.xml
  19. 63 0
      soc-modules/soc-modules-mediator/src/main/java/com/xunmei/mediator/api/enums/AlarmRuleExpressOperateEnum.java
  20. 9 0
      soc-modules/soc-modules-mediator/src/main/java/com/xunmei/mediator/api/mapper/IotAlarmRuleExpressMapper.java
  21. 10 0
      soc-modules/soc-modules-mediator/src/main/java/com/xunmei/mediator/api/mapper/IotAlarmRuleSourceMapper.java
  22. 9 0
      soc-modules/soc-modules-mediator/src/main/java/com/xunmei/mediator/api/mapper/IotAlarmSystemFieldMapper.java
  23. 15 0
      soc-modules/soc-modules-mediator/src/main/java/com/xunmei/mediator/api/service/IotAlarmDataService.java
  24. 210 0
      soc-modules/soc-modules-mediator/src/main/java/com/xunmei/mediator/api/service/impl/IotAlarmDataServiceImpl.java
  25. 20 6
      soc-modules/soc-modules-mediator/src/main/java/com/xunmei/mediator/api/service/impl/IotSensorServiceImpl.java

+ 3 - 1
project_data/sql/0.0.6-iot/soc/soc.sql

@@ -61,6 +61,8 @@ ALTER TABLE `iot_alarm_subsystem`
 MODIFY COLUMN `status` int NULL DEFAULT NULL COMMENT '布防状态,0:撤防,1:布防,2:未知(未登记过或离线)' AFTER `name`;
 update iot_alarm_subsystem set `status`=2 WHERE status is null;
 update iot_alarm_subsystem_log set `status`=2 WHERE status is null;
+UPDATE iot_alarm_subsystem set status_change_time =status_update_time WHERE status_change_time is null;
+UPDATE iot_alarm_subsystem_log set status_change_time =status_update_time WHERE status_change_time is null;
 
 drop table if exists iot_device;
 CREATE TABLE `iot_device` (
@@ -1091,5 +1093,5 @@ INSERT INTO `sys_menu` (`id`, `menu_name`, `parent_id`, `order_num`, `path`, `co
 
 
 
-update sys_menu set component ='iot/subSystem/index',parent_id=1747911340288892930 WHERE menu_name='布撤防情况跟踪' and platform_type=1;
+update sys_menu set component ='iot/subSystem/index' WHERE menu_name='布撤防情况跟踪' and platform_type=1;
 UPDATE sys_menu set path='/iot/subsystem' WHERE path='/protection' and platform_type=0;

+ 4 - 0
soc-common/soc-common-core/src/main/java/com/xunmei/common/core/domain/mediator/domain/IotAlarmData.java

@@ -41,6 +41,10 @@ public class IotAlarmData {
     @TableField("device_id")
     private Long deviceId;
 
+    @ApiModelProperty(value = "机构id")
+    @TableField("org_id")
+    private Long orgId;
+
     @ApiModelProperty(value = "报警源类型(设备类型):4:烟雾传感器;5: 温湿度采集器;6:水浸; 7:门磁、窗磁;8:卷帘门门磁;9:地磁;10燃气报警器;50:报警防区")
     @TableField("source_type")
     private Integer sourceType;

+ 2 - 2
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/resumption/vo/protection/ProtectionLogPageVo.java

@@ -33,9 +33,9 @@ public class ProtectionLogPageVo {
 //    @ApiModelProperty("所属机构")
 //    private String orgName;
 
-    @ApiModelProperty("更新时间")
+    @ApiModelProperty("布撤防")
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm")
-    private Date updateTime;
+    private Date statusChangeTime;
 
     @ApiModelProperty("防区状态")
     private String status;

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

@@ -5,7 +5,7 @@
         select a.id,
         a.name,
         a.status ,
-        a.status_update_time as updateTime,
+        a.status_change_time as statusChangeTime,
         a.status_updator_name as statusUpdatorName
         from iot_alarm_subsystem_log a
         where a.protection_id=#{request.protectionId}

+ 4 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/dto/alarm/IotAlarmRuleSourceDeviceDto.java

@@ -19,6 +19,10 @@ public class IotAlarmRuleSourceDeviceDto {
     @ApiModelProperty(value = "设备名称")
     private String deviceName;
 
+    @ApiModelProperty(value = "是否包含机构子集")
+    private boolean includeSub;
+
+
     /**
      * @see ProductTypeEnum
      */

+ 2 - 61
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/dto/dvrDisk/DvrDiskPageDto.java

@@ -23,71 +23,12 @@ import java.util.Date;
         description = "录像机硬盘检测查询"
 )
 public class DvrDiskPageDto extends PageDto {
-    @ApiModelProperty("录像机的唯一标识")
-//    @Query(
-//            type = QueryConditionType.equal
-//    )
-    private String equipmentCode;
-
     @ApiModelProperty("监控主机的名称")
-//    @Query(
-//            type = QueryConditionType.like
-//    )
     private String hostName;
-//    @ApiModelProperty("报警状态")
-//    @Query(
-//            type = QueryConditionType.equal
-//    )
-//    private AlarmStatus status;
-//    @ApiModelProperty("报警/恢复时间")
-////    @Query(
-////            type = QueryConditionType.equalDate
-////    )
-//    private Date alarmTime;
-
-//    @ApiModelProperty("报警/恢复开始-结束日期")
-//    private Date[] range;
-
-//    /**
-//     * 与alarmTime互斥,alarmTime优先
-//     */
-//    @ApiModelProperty("报警/恢复开始日期")
-////    @Query(
-////            type = QueryConditionType.geDate,column = "alarmTime"
-////    )
-//    @JsonIgnore
-//    private Date alarmStartTime;
-//
-//    /**
-//     * 与alarmTime互斥,alarmTime优先
-//     */
-//    @ApiModelProperty("报警/恢复结束日期")
-////    @Query(
-////            type = QueryConditionType.leDate,column = "alarmTime"
-////    )
-//    @JsonIgnore
-//    private Date alarmEndTime;
-
-
-    @ApiModelProperty("所属机构")
-//    @Query(
-//            type = QueryConditionType.equal
-//    )
-    private Long orgId;
-
-//    @ApiModelProperty("上级银行")
-////    @Query(type = QueryConditionType.org, column = "orgId")
-//    private Long parentId;
-
-    @ApiModelProperty("包含下级")
-    private Boolean checkSub = false;
 
     @JsonIgnore
     private Long categoryId;
 
-//    @ApiModelProperty("id")
-////    @Query(
-////            type = QueryConditionType.equal
-////    )
-//    private String id;
+    @ApiModelProperty("网络状态")
+    private Integer netState;
 }

+ 4 - 14
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/dto/videoDiagnosis/VideoDiagnosisAppPageDto.java

@@ -1,25 +1,15 @@
 package com.xunmei.iot.dto.videoDiagnosis;
 
+import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.xunmei.common.core.web.domain.PageDto;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
 @Data
 public class VideoDiagnosisAppPageDto extends PageDto {
-    //    @ApiModelProperty(value = "监控主机")
-//    private String hostName;
-//
-//    @ApiModelProperty(value = "通道")
-//    private String channelName;
-//
-//    @ApiModelProperty(value = "录像完整性状态")
-//    private Integer integrityState;
-//
-//    @ApiModelProperty(value = "录像存储天数状态")
-//    private Integer daysState;
-//
-//    @ApiModelProperty(value = "视频诊断状态")
-//    private Integer diagnosisState;
     @ApiModelProperty(value = "0:正常,1:异常,2:未知")
     private Integer state;
+
+    @JsonIgnore
+    private Long categoryId;
 }

+ 4 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/dto/videoDiagnosis/VideoDiagnosisWebPageDto.java

@@ -1,5 +1,6 @@
 package com.xunmei.iot.dto.videoDiagnosis;
 
+import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.xunmei.common.core.web.domain.PageDto;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -20,4 +21,7 @@ public class VideoDiagnosisWebPageDto extends PageDto {
 
     @ApiModelProperty(value = "视频诊断状态")
     private Integer diagnosisState;
+
+    @JsonIgnore
+    private Long categoryId;
 }

+ 8 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/mapper/IotAlarmRuleSourceMapper.java

@@ -6,6 +6,7 @@ import com.xunmei.common.core.domain.mediator.domain.IotAlarmRuleSource;
 import com.xunmei.iot.dto.alarm.IotAlarmRuleSourceDeviceDto;
 import com.xunmei.iot.vo.alarm.IotAlarmRuleSourceDetailVo;
 import com.xunmei.iot.vo.alarm.IotAlarmRuleSourceDeviceVo;
+import com.xunmei.iot.vo.alarm.IotAlarmRuleSourceTotalVo;
 import com.xunmei.iot.vo.alarm.ProductTypeDataVo;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
@@ -35,4 +36,11 @@ public interface IotAlarmRuleSourceMapper extends BaseMapper<IotAlarmRuleSource>
      * @return
      */
     Page<IotAlarmRuleSourceDeviceVo> selectDeviceList(Page<IotAlarmRuleSourceDeviceVo> page, @Param("param")IotAlarmRuleSourceDeviceDto param);
+
+    /**
+     * 获取数据
+     * @param ruleId
+     * @return
+     */
+    List<IotAlarmRuleSourceTotalVo> getRuleSourceSize(@Param("ruleId") Long ruleId);
 }

+ 15 - 4
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/impl/IotAlarmRuleServiceImpl.java

@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.xunmei.common.core.domain.mediator.domain.IotAlarmRule;
 import com.xunmei.common.core.domain.mediator.domain.IotAlarmRuleExpress;
+import com.xunmei.common.core.domain.mediator.domain.IotAlarmRuleSource;
 import com.xunmei.common.core.domain.mediator.domain.IotAlarmSystemField;
 import com.xunmei.common.core.util.BeanHelper;
 import com.xunmei.common.core.utils.IDHelper;
@@ -17,15 +18,14 @@ import com.xunmei.common.security.utils.SecurityUtils;
 import com.xunmei.iot.dto.alarm.IotAlarmRuleDto;
 import com.xunmei.iot.dto.alarm.IotAlarmRuleExpressDto;
 import com.xunmei.iot.mapper.IotAlarmRuleMapper;
+import com.xunmei.iot.mapper.IotAlarmRuleSourceMapper;
 import com.xunmei.iot.mapper.IotAlarmSystemFieldMapper;
 import com.xunmei.iot.service.IotAlarmRuleExpressService;
 import com.xunmei.iot.service.IotAlarmRuleService;
-import com.xunmei.iot.vo.alarm.IotAlarmRuleEditVo;
-import com.xunmei.iot.vo.alarm.IotAlarmRuleExpressEditVo;
-import com.xunmei.iot.vo.alarm.IotAlarmSystemFieldVo;
-import com.xunmei.iot.vo.alarm.IotInitAlarmRuleVo;
+import com.xunmei.iot.vo.alarm.*;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.time.LocalDateTime;
 import java.util.*;
@@ -40,6 +40,9 @@ public class IotAlarmRuleServiceImpl extends ServiceImpl<IotAlarmRuleMapper, Iot
     @Autowired
     private IotAlarmRuleExpressService iotAlarmRuleExpressService;
 
+    @Autowired
+    private IotAlarmRuleSourceMapper iotAlarmRuleSourceMapper;
+
     @Override
     public IotInitAlarmRuleVo getAddInitAlarmRuleData() throws Exception {
 
@@ -116,6 +119,8 @@ public class IotAlarmRuleServiceImpl extends ServiceImpl<IotAlarmRuleMapper, Iot
 
         List<IotAlarmRuleExpress> appAlarmRuleExpressList = iotAlarmRuleExpressService.list(new LambdaQueryWrapper<IotAlarmRuleExpress>().eq(IotAlarmRuleExpress::getRuleId, ruleId));
         List<IotAlarmRuleExpressEditVo> appAlarmRuleExpressEditVos = new ArrayList<>();
+        List<IotAlarmRuleSourceTotalVo> iotAlarmRuleSourceTotalVos = iotAlarmRuleSourceMapper.getRuleSourceSize(ruleId);
+        ruleVo.setIotAlarmRuleSourceTotalVos(iotAlarmRuleSourceTotalVos);
         for (IotAlarmRuleExpress express : appAlarmRuleExpressList) {
             IotAlarmRuleExpressEditVo expressNew = new IotAlarmRuleExpressEditVo();
             BeanHelper.copyProperties(expressNew, express);
@@ -164,6 +169,7 @@ public class IotAlarmRuleServiceImpl extends ServiceImpl<IotAlarmRuleMapper, Iot
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public void saveOrUpdateAlarmRule(IotAlarmRuleDto ruleDto) throws Exception {
         IotAlarmRule rule = new IotAlarmRule();
         BeanHelper.copyProperties(rule, ruleDto);
@@ -209,5 +215,10 @@ public class IotAlarmRuleServiceImpl extends ServiceImpl<IotAlarmRuleMapper, Iot
         LambdaQueryWrapper<IotAlarmRuleExpress> ruleExpressWrapper = new LambdaQueryWrapper<>();
         ruleExpressWrapper.eq(IotAlarmRuleExpress::getRuleId,ruleId);
         iotAlarmRuleExpressService.remove(ruleExpressWrapper);
+
+        //删除绑定设备数据
+        LambdaQueryWrapper<IotAlarmRuleSource> iots = new LambdaQueryWrapper<>();
+        iots.eq(IotAlarmRuleSource::getRuleId,ruleId);
+        iotAlarmRuleSourceMapper.delete(iots);
     }
 }

+ 7 - 3
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/impl/IotAlarmRuleSourceServiceImpl.java

@@ -61,7 +61,6 @@ public class IotAlarmRuleSourceServiceImpl extends ServiceImpl<IotAlarmRuleSourc
         List<ProductTypeDataVo> productTypeDataVos = iotAlarmRuleSourceMapper.selectRuleDevice(detailVo.getRuleId());
         //3.处理其他sql获取不了的数据
         for (ProductTypeDataVo pdv : productTypeDataVos) {
-            pdv.setTypeText(ProductTypeEnum.getName(pdv.getType()));
             dealDevice(pdv);
         }
         iotAlarmRuleSourceDetailVo.setTypeDataList(productTypeDataVos);
@@ -97,7 +96,6 @@ public class IotAlarmRuleSourceServiceImpl extends ServiceImpl<IotAlarmRuleSourc
             if (ValueTypeEnum.AllDevice.getText().equals(productType.getValueType()) && productType.getIsAllDeviceEnable()) {
                 ruleSource.setId(IDHelper.id());
                 ruleSource.setOrgId(null);
-
                 ruleSource.setSourceType(productType.getType());
                 ruleSource.setValue(null);
                 ruleSource.setValueType(ValueTypeEnum.AllDevice.getText());
@@ -106,6 +104,12 @@ public class IotAlarmRuleSourceServiceImpl extends ServiceImpl<IotAlarmRuleSourc
             }
             if (productType.getDeviceTempList() != null) {
                 for (ProductDeviceTempVo deviceTempVo : productType.getDeviceTempList()) {
+                    //查询当前设备是否有其他规则绑定,如果有则删除,解绑
+                    QueryWrapper<IotAlarmRuleSource> iqw = new QueryWrapper<>();
+                    iqw.lambda().eq(IotAlarmRuleSource::getOrgId,deviceTempVo.getOrgId())
+                            .eq(IotAlarmRuleSource::getValue,deviceTempVo.getDeviceId())
+                            .eq(IotAlarmRuleSource::getSourceType,productType.getType());
+                    iotAlarmRuleSourceMapper.delete(iqw);
                     ruleSource.setId(IDHelper.id());
                     ruleSource.setOrgId(deviceTempVo.getOrgId());
                     ruleSource.setSourceType(productType.getType());
@@ -171,7 +175,7 @@ public class IotAlarmRuleSourceServiceImpl extends ServiceImpl<IotAlarmRuleSourc
         if(StringUtils.isEmpty(valueType)){
             //未配置设备关联时
             pdv.setIsAllDeviceEnable(false);
-            pdv.setValueType(ValueTypeEnum.AllDevice.getText());
+            pdv.setValueType(ValueTypeEnum.Device.getText());
         }else{
             if(ValueTypeEnum.AllDevice.getText().equals(valueType)){
                 //配置按设备类型关联时

+ 4 - 1
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/impl/VideoDiagnosisServiceImpl.java

@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.xunmei.common.core.constant.SecurityConstants;
 import com.xunmei.common.core.domain.iot.domain.IotDvrChannel;
 import com.xunmei.common.core.domain.video.MediatorVideoIntegrityCheck;
+import com.xunmei.common.core.enums.CategoryDataEnum;
 import com.xunmei.common.core.enums.iot.VideoIntegrityStatus;
 import com.xunmei.common.core.web.page.TableDataInfo;
 import com.xunmei.iot.dto.videoDiagnosis.VideoDiagnosisAppPageDto;
@@ -46,6 +47,7 @@ public class VideoDiagnosisServiceImpl extends ServiceImpl<IotDvrChannelMapper,
             SysOrg org = orgService.selectOrgById(request.getOrgId(), SecurityConstants.INNER);
             orgPath = org.getPath();
         }
+        request.setCategoryId(CategoryDataEnum.MONITOR_HOST_DEVICE.getId());
         Page<VideoDiagnosisWebPageVo> page = request.toPage();
         page = baseMapper.selectPage(page, request, orgPath);
 
@@ -62,6 +64,7 @@ public class VideoDiagnosisServiceImpl extends ServiceImpl<IotDvrChannelMapper,
 
         Page<VideoDiagnosisAppPageVo> page = request.toPage();
 
+        request.setCategoryId(CategoryDataEnum.MONITOR_HOST_DEVICE.getId());
         page = baseMapper.selectAppPage(page, request, orgPath);
         page.getRecords().forEach(r -> {
             if (ObjectUtil.isEmpty(r.getChannels())) {
@@ -92,7 +95,7 @@ public class VideoDiagnosisServiceImpl extends ServiceImpl<IotDvrChannelMapper,
             LambdaQueryWrapper<MediatorVideoIntegrityCheck> wrapper = new LambdaQueryWrapper<>();
             wrapper.eq(MediatorVideoIntegrityCheck::getEquipmentCode, hostCode)
                     .eq(MediatorVideoIntegrityCheck::getChannelCode, channelCode)
-                    .le(MediatorVideoIntegrityCheck::getRecordDate, vo.getStorage().getEarliestTime())
+                    .ge(MediatorVideoIntegrityCheck::getRecordDate, vo.getStorage().getEarliestTime())
                     .select(MediatorVideoIntegrityCheck::getRecordDate, MediatorVideoIntegrityCheck::getStatus);
             Map<Integer, List<MediatorVideoIntegrityCheck>> days = videoIntegrityCheckMapper.selectList(wrapper)
                     .stream().collect(Collectors.groupingBy(d -> d.getStatus()));

+ 27 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/vo/alarm/IotAlarmRuleSourceTotalVo.java

@@ -0,0 +1,27 @@
+package com.xunmei.iot.vo.alarm;
+
+import lombok.Data;
+
+@Data
+public class IotAlarmRuleSourceTotalVo {
+
+    /**
+     * 告警规则id
+     */
+    private String ruleId;
+
+    /**
+     * 资源类型代码 如: 4, 5
+     */
+    private String sourceType;
+
+    /**
+     * 资源类型,如 水浸,烟感
+     */
+    private String sourceName;
+
+    /**
+     * 资源数量,如 1,23,
+     */
+    private String sourceSize;
+}

+ 4 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/vo/alarm/IotInitAlarmRuleVo.java

@@ -24,4 +24,8 @@ public class IotInitAlarmRuleVo implements Serializable {
      * 告警规则
      */
     private List<Map<String,Object>>  iotAlarmRuleExpressEditVosBySourceType;
+    /**
+     * 每种规则绑定设备详情
+     */
+    private List<IotAlarmRuleSourceTotalVo> iotAlarmRuleSourceTotalVos;
 }

+ 5 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/vo/alarm/ProductDeviceTempVo.java

@@ -28,4 +28,9 @@ public class ProductDeviceTempVo {
      * 机构名称
      */
     private String orgName;
+
+    /**
+     * 机构path
+     */
+    private String orgPath;
 }

+ 6 - 1
soc-modules/soc-modules-iot/src/main/resources/mapper/DvrDiskMapper.xml

@@ -39,6 +39,7 @@
             <result column="disk_name" property="diskName"/>
             <result column="total" property="total"/>
             <result column="available" property="available"/>
+            <result column="state" property="state"/>
         </collection>
     </resultMap>
     <select id="selectHostPage" resultMap="selectHostPageMap">
@@ -68,6 +69,9 @@
         <if test="pageDto.hostName!=null and pageDto.hostName!=''">
             and d.equipment_name like concat('%', #{pageDto.hostName},'%')
         </if>
+        <if test="pageDto.netState!=null">
+            and dd.state=#{pageDto.netState}
+        </if>
         <!--        <if test="pageDto.status !=null">-->
         <!--            and dhd.`status` = #{pageDto.status}-->
         <!--        </if>-->
@@ -87,7 +91,8 @@
         `disk_name`,
         `total`,
         `host_code`,
-        `org_id`
+        `org_id`,
+        state
         from iot_dvr_disk
         where host_code = #{equipmentCode}
         and deleted=0

+ 25 - 7
soc-modules/soc-modules-iot/src/main/resources/mapper/IotAlarmRuleSourceMapper.xml

@@ -17,11 +17,12 @@
     <resultMap id="product_type_data" type="com.xunmei.iot.vo.alarm.ProductTypeDataVo">
         <result property="type" column="type"/>
         <result property="valueType" column="value_type"/>
-        <result property="valueType" column="value_type"/>
+        <result property="typeText" column="type_text"/>
         <collection property="deviceTempList" ofType="com.xunmei.iot.vo.alarm.ProductDeviceTempVo">
             <result property="deviceId" column="device_id"/>
             <result property="orgId" column="org_id"/>
             <result property="orgName" column="org_name"/>
+            <result property="orgPath" column="org_path"/>
         </collection>
     </resultMap>
 
@@ -29,14 +30,17 @@
     <select id="selectRuleDevice" resultMap="product_type_data">
         SELECT
             a.source_type AS type,
+            d.source_type_des as type_text,
             b.value_type,
             b.`value` AS device_id,
             b.org_id,
-            c.`name` AS org_name
+            c.`name` AS org_name,
+            c.path AS org_path
         FROM
-            (	select rule_id,source_type from iot_alarm_rule_express  GROUP BY source_type,rule_id) a
-                LEFT JOIN iot_alarm_rule_source b ON a.rule_id = b.rule_id and a.source_type=b.source_type
+            ( SELECT rule_id, source_type FROM iot_alarm_rule_express GROUP BY source_type, rule_id ) a
+                LEFT JOIN iot_alarm_rule_source b ON a.rule_id = b.rule_id AND a.source_type = b.source_type
                 LEFT JOIN sys_org c ON b.org_id = c.id
+                LEFT JOIN (select source_type,source_type_des from iot_alarm_system_field GROUP BY source_type,source_type_des) d on a.source_type = d.source_type
         where a.rule_id = #{ruleId}
     </select>
     <select id="selectDeviceList" resultType="com.xunmei.iot.vo.alarm.IotAlarmRuleSourceDeviceVo">
@@ -48,13 +52,27 @@
         CONCAT(b.affiliated_area,'-',b.affiliated_bank,'-',b.short_name) as org_name
         FROM
         iot_sensor d
-        LEFT JOIN mediator_category c ON c.id = d.category_id
         LEFT JOIN sys_org b ON d.org_id = b.id
-        where d.org_id = #{param.orgId}
-        and c.code = #{param.type}
+        where 1=1
+        <if test="param.includeSub == false">
+         and   d.org_id = #{param.orgId}
+        </if>
+        <if test="param.includeSub == true">
+        and   b.path like concat((select path from sys_org where id = #{param.orgId} ),'%')
+        </if>
+        and d.device_type = #{param.type}
         <if test="param.deviceName != null and param.deviceName != ''">
             and d.device_name like concat('%',#{param.deviceName},'%')
         </if>
 
     </select>
+    <select id="getRuleSourceSize" resultType="com.xunmei.iot.vo.alarm.IotAlarmRuleSourceTotalVo">
+        SELECT
+            a.source_type,
+            a.source_type_des AS source_name,
+            IFNULL( b.source_size, 0 ) AS source_size
+        FROM
+            ( SELECT source_type, source_type_des FROM iot_alarm_system_field GROUP BY source_type, source_type_des ) a
+                LEFT JOIN ( SELECT rule_id, source_type, count(*) source_size FROM iot_alarm_rule_source WHERE rule_id = #{ruleId} GROUP BY rule_id, source_type ) b ON a.source_type = b.source_type
+    </select>
 </mapper>

+ 1 - 1
soc-modules/soc-modules-iot/src/main/resources/mapper/IotDvrChannelMapper.xml

@@ -154,7 +154,7 @@
         org_name,
         #{pageDto.state} as state
         from iot_device
-        WHERE category_id = 1
+        WHERE category_id = #{pageDto.categoryId}
         <if test="pageDto.checkSub==true">
             and org_path like concat(#{orgPath}, '%')
         </if>

+ 63 - 0
soc-modules/soc-modules-mediator/src/main/java/com/xunmei/mediator/api/enums/AlarmRuleExpressOperateEnum.java

@@ -0,0 +1,63 @@
+package com.xunmei.mediator.api.enums;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * @author jingyuanchao
+ * @date 2022/8/1 12:52
+ */
+@Getter
+@NoArgsConstructor
+@AllArgsConstructor
+public enum AlarmRuleExpressOperateEnum {
+
+    /**
+     * 操作符,GT(大于)、GTE(大于等于)、LT(小于)、LTE(小于等
+     * 于)、EQUALS(等于)、STARTS_WITH(以什么开始)、
+     * ENDS_WITH(以什么结束)、CONTAIN(包含)
+     */
+    GT("GT"),
+    GTE("GTE"),
+    LT("LT"),
+    LTE("LTE"),
+    EQUALS("EQUALS"),
+    STARTS_WITH("STARTS_WITH"),
+    ENDS_WITH("ENDS_WITH"),
+    CONTAIN("CONTAIN");
+
+
+    private String text;
+
+    /**
+     * 根据code获取name
+     */
+    public static String getName(String code) {
+        AlarmRuleExpressOperateEnum e = enumMap.get(code);
+        return e != null ? e.getText() : "";
+    }
+
+    /**
+     * 根据code获取枚举对象
+     */
+    public static AlarmRuleExpressOperateEnum getOperateEnum(String code) {
+        return enumMap.get(code);
+    }
+
+    /**
+     * 所有枚举
+     */
+    private static final Map<String, AlarmRuleExpressOperateEnum> enumMap = new LinkedHashMap<>();
+
+    static {
+        for (AlarmRuleExpressOperateEnum typeEnum : AlarmRuleExpressOperateEnum.values()) {
+            enumMap.put(typeEnum.text, typeEnum);
+        }
+    }
+
+
+}

+ 9 - 0
soc-modules/soc-modules-mediator/src/main/java/com/xunmei/mediator/api/mapper/IotAlarmRuleExpressMapper.java

@@ -0,0 +1,9 @@
+package com.xunmei.mediator.api.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.xunmei.common.core.domain.mediator.domain.IotAlarmRuleExpress;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface IotAlarmRuleExpressMapper extends BaseMapper<IotAlarmRuleExpress> {
+}

+ 10 - 0
soc-modules/soc-modules-mediator/src/main/java/com/xunmei/mediator/api/mapper/IotAlarmRuleSourceMapper.java

@@ -0,0 +1,10 @@
+package com.xunmei.mediator.api.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.xunmei.common.core.domain.mediator.domain.IotAlarmRuleSource;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface IotAlarmRuleSourceMapper extends BaseMapper<IotAlarmRuleSource> {
+
+}

+ 9 - 0
soc-modules/soc-modules-mediator/src/main/java/com/xunmei/mediator/api/mapper/IotAlarmSystemFieldMapper.java

@@ -0,0 +1,9 @@
+package com.xunmei.mediator.api.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.xunmei.common.core.domain.mediator.domain.IotAlarmSystemField;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface IotAlarmSystemFieldMapper extends BaseMapper<IotAlarmSystemField> {
+}

+ 15 - 0
soc-modules/soc-modules-mediator/src/main/java/com/xunmei/mediator/api/service/IotAlarmDataService.java

@@ -1,8 +1,11 @@
 package com.xunmei.mediator.api.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.xunmei.common.core.domain.iot.domain.IotSensor;
 import com.xunmei.common.core.domain.mediator.domain.IotAlarmData;
 
+import java.util.List;
+
 /**
  * <p>
  * 告警数据表 服务类
@@ -12,5 +15,17 @@ import com.xunmei.common.core.domain.mediator.domain.IotAlarmData;
  * @since 2024-01-26
  */
 public interface IotAlarmDataService extends IService<IotAlarmData> {
+    /**
+     * 生成告警数据逻辑梳理
+     * 1.根据传入的设备数据,判断设备类型。
+     * 2.根据设备类型获取设备绑定规则。
+     * 3.根据绑定规则判断适用于星期几,时间段。
+     * 4.根据绑定的规则判断是否需要生成告警数据。
+     * 5.如果结果是告警,判断是否已有告警数据,如果有则不生成告警数据。如果是告警结束,则修改告警数据的结束时间。
+     */
+    void dealSensorData(IotSensor iotSensor)throws Exception;
+
+
+    void dealSensorListData(List<IotSensor> iotSensor)throws Exception;
 
 }

+ 210 - 0
soc-modules/soc-modules-mediator/src/main/java/com/xunmei/mediator/api/service/impl/IotAlarmDataServiceImpl.java

@@ -1,11 +1,34 @@
 package com.xunmei.mediator.api.service.impl;
 
 
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.ObjectUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.xunmei.common.core.domain.iot.domain.IotSensor;
 import com.xunmei.common.core.domain.mediator.domain.IotAlarmData;
+import com.xunmei.common.core.domain.mediator.domain.IotAlarmRuleExpress;
+import com.xunmei.common.core.domain.mediator.domain.IotAlarmRuleSource;
+import com.xunmei.common.core.domain.mediator.domain.IotAlarmSystemField;
+import com.xunmei.common.core.enums.CategoryDataEnum;
+import com.xunmei.common.core.utils.DateUtils;
+import com.xunmei.mediator.api.enums.AlarmRuleExpressOperateEnum;
 import com.xunmei.mediator.api.mapper.IotAlarmDataMapper;
+import com.xunmei.mediator.api.mapper.IotAlarmRuleExpressMapper;
+import com.xunmei.mediator.api.mapper.IotAlarmRuleSourceMapper;
+import com.xunmei.mediator.api.mapper.IotAlarmSystemFieldMapper;
 import com.xunmei.mediator.api.service.IotAlarmDataService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.time.LocalDateTime;
+import java.util.*;
+import java.util.function.Function;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -18,4 +41,191 @@ import org.springframework.stereotype.Service;
 @Service
 public class IotAlarmDataServiceImpl extends ServiceImpl<IotAlarmDataMapper, IotAlarmData> implements IotAlarmDataService {
 
+    @Autowired
+    private IotAlarmRuleSourceMapper iotAlarmRuleSourceMapper;
+
+    @Autowired
+    private IotAlarmRuleExpressMapper iotAlarmRuleExpressMapper;
+
+    @Autowired
+    private IotAlarmSystemFieldMapper iotAlarmSystemFieldMapper;
+
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public void dealSensorData(IotSensor iotSensor) throws Exception {
+        /**
+         * 生成告警数据逻辑梳理
+         * 1.根据传入的设备数据,判断设备类型。
+         * 2.根据设备类型获取设备绑定规则。
+         * 3.根据绑定规则判断适用于星期几,时间段。
+         * 4.根据绑定的规则判断是否需要生成告警数据。
+         * 5.如果结果是告警,判断是否已有告警数据,如果有则不生成告警数据。如果是告警结束,则修改告警数据的结束时间。
+         */
+        Date now = new Date();
+        //判断是否有绑定规则
+        QueryWrapper<IotAlarmRuleSource> qw = new QueryWrapper<>();
+        qw.lambda().eq(IotAlarmRuleSource::getValue,iotSensor.getDeviceCode())
+                        .eq(IotAlarmRuleSource::getOrgId,iotSensor.getOrgId());
+        IotAlarmRuleSource iotAlarmRuleSource = iotAlarmRuleSourceMapper.selectOne(qw);
+        if(iotAlarmRuleSource == null){
+            //设备未绑定规则,不做处理
+            return;
+        }
+
+
+        //获取该设备对应的规则
+        int weekDay = DateUtil.thisDayOfWeek() - 1;
+        System.out.println(weekDay);
+        QueryWrapper<IotAlarmRuleExpress> ruleExpress = new QueryWrapper<>();
+        ruleExpress.lambda().eq(IotAlarmRuleExpress::getRuleId,iotAlarmRuleSource.getRuleId())
+                .eq(IotAlarmRuleExpress::getSourceType,iotAlarmRuleSource.getSourceType())
+                .eq(IotAlarmRuleExpress::getWeekDay,weekDay);
+        List<IotAlarmRuleExpress> iotAlarmRuleExpresses = iotAlarmRuleExpressMapper.selectList(ruleExpress);
+
+        List<IotAlarmSystemField> fields = iotAlarmSystemFieldMapper.selectList(null);
+        Map<String, IotAlarmSystemField> fieldMap = fields.stream().collect(Collectors.toMap(IotAlarmSystemField::getSysFieldCode, Function.identity()));
+        String dateStr = DateUtil.format(new Date(), "yyyy-MM-dd");
+        boolean isAlarm = false;
+        boolean isExpress = false;
+        List<IotAlarmData> list = new ArrayList<>();
+        for (IotAlarmRuleExpress express : iotAlarmRuleExpresses) {
+            boolean isOk = comparetoTime(express, dateStr, now);
+            if(!isOk){
+                //不在时间段内
+                continue;
+            }
+            isExpress = true;
+            IotAlarmData alarmData = createAlarmData(iotSensor, express, fieldMap);
+            if(alarmData != null){
+                isAlarm = true;
+                list.add(alarmData);
+            }
+        }
+
+        String deviceCode = iotSensor.getDeviceCode();
+        QueryWrapper<IotAlarmData> queryWrapper = new QueryWrapper<>();
+        queryWrapper.lambda().eq(IotAlarmData::getDeviceId,deviceCode)
+                .eq(IotAlarmData::getOrgId,iotSensor.getOrgId())
+                .isNull(IotAlarmData::getEndTime);
+        List<IotAlarmData> alarms = baseMapper.selectList(queryWrapper);
+        if(isAlarm && alarms.size() == 0){
+            //报警中,且表中没有告警数据,则插入数据
+            this.saveBatch(list);
+        }
+        if(isExpress && !isAlarm && alarms.size() != 0){
+            //报警恢复
+            IotAlarmData iotAlarmData = alarms.get(0);
+            iotAlarmData.setEndTime(LocalDateTime.now());
+            this.updateById(iotAlarmData);
+        }
+
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void dealSensorListData(List<IotSensor> iotSensor) throws Exception {
+        if(ObjectUtil.isEmpty(iotSensor)){
+            return;
+        }
+        for (IotSensor sensor : iotSensor) {
+            dealSensorData(sensor);
+        }
+    }
+
+    private IotAlarmData createAlarmData(IotSensor iotSensor,IotAlarmRuleExpress express,Map<String, IotAlarmSystemField> fieldMap){
+        IotAlarmData iotAlarmData = null;
+        String operator = express.getOperator();
+        String value = express.getValue();
+        String infos = iotSensor.getInfos();
+        Map<String, String> dataMap = dealInfos(infos);
+        IotAlarmSystemField field = fieldMap.get(express.getFieldcode());
+        String sensorValue = dataMap.get(field.getName());
+        if(AlarmRuleExpressOperateEnum.EQUALS.getText().equals(operator)){
+            if(sensorValue.equals(value)){
+                //对上了
+                iotAlarmData = builderAlarm(sensorValue,field,express,iotSensor);
+            }
+        }
+
+        if(AlarmRuleExpressOperateEnum.GT.getText().equals(operator)){
+            if(Integer.parseInt(value) > Integer.parseInt(sensorValue)){
+                //对上了
+                iotAlarmData = builderAlarm(sensorValue,field,express,iotSensor);
+            }
+        }
+
+        if(AlarmRuleExpressOperateEnum.GTE.getText().equals(operator)){
+            if(Integer.parseInt(value) >= Integer.parseInt(sensorValue)){
+                //对上了
+                iotAlarmData = builderAlarm(sensorValue,field,express,iotSensor);
+            }
+        }
+
+        if(AlarmRuleExpressOperateEnum.LT.getText().equals(operator)){
+            if(Integer.parseInt(value) < Integer.parseInt(sensorValue)){
+                //对上了
+                iotAlarmData = builderAlarm(sensorValue,field,express,iotSensor);
+            }
+        }
+
+        if(AlarmRuleExpressOperateEnum.LTE.getText().equals(operator)){
+            if(Integer.parseInt(value) <= Integer.parseInt(sensorValue)){
+                //对上了
+                iotAlarmData = builderAlarm(sensorValue,field,express,iotSensor);
+            }
+        }
+
+        if(AlarmRuleExpressOperateEnum.LTE.getText().equals(operator)){
+            if(Integer.parseInt(value) <= Integer.parseInt(sensorValue)){
+                //对上了
+                iotAlarmData = builderAlarm(sensorValue,field,express,iotSensor);
+            }
+        }
+        return iotAlarmData;
+    }
+
+
+    private IotAlarmData builderAlarm(String sensorValue,IotAlarmSystemField field,IotAlarmRuleExpress express,IotSensor iotSensor){
+        IotAlarmData iotAlarmData = new IotAlarmData();
+        iotAlarmData.setAlarmValue(sensorValue + field.getUnit());
+        iotAlarmData.setTime(LocalDateTime.now());
+        iotAlarmData.setRuleId(express.getRuleId());
+        iotAlarmData.setDeviceId(iotSensor.getDeviceId());
+        iotAlarmData.setSourceType(field.getSourceType());
+        iotAlarmData.setSourceTypeDes(field.getSourceTypeDes());
+        iotAlarmData.setFieldCode(field.getSysFieldCode());
+        iotAlarmData.setOperator(express.getOperator());
+        iotAlarmData.setValue(express.getValue());
+        iotAlarmData.setValueText(express.getValueText());
+        iotAlarmData.setContent(iotSensor.getDeviceName() + "触发" + field.getName());
+        return iotAlarmData;
+    }
+
+    private Map<String,String> dealInfos(String infos){
+        JSONArray objects = JSONArray.parseArray(infos);
+        Map<String,String> map = new HashMap<>();
+        for (Object object : objects) {
+            JSONObject data = (JSONObject) object;
+            map.put(data.getString("name"),data.getString("val"));
+        }
+        return map;
+    }
+
+    private boolean comparetoTime(IotAlarmRuleExpress express,String dateStr,Date now){
+        //判断是否在规则时间段内
+        String format = "yyyy-MM-dd HH:mm:ss";
+        String start = dateStr + " " + express.getStartTime();
+        String end = dateStr + " " + express.getEndTime();
+
+        Date startTime = DateUtils.dateTime(format, start);
+        Date endTime = DateUtils.dateTime(format, end);
+
+        boolean isOk = false;
+        if(now.after(startTime) && now.before(endTime)){
+            isOk = true;
+        }
+        return isOk;
+    }
+
+
 }

+ 20 - 6
soc-modules/soc-modules-mediator/src/main/java/com/xunmei/mediator/api/service/impl/IotSensorServiceImpl.java

@@ -13,10 +13,7 @@ import com.xunmei.common.core.enums.CategoryDataEnum;
 import com.xunmei.common.core.utils.DateUtils;
 import com.xunmei.common.core.utils.IDHelper;
 import com.xunmei.mediator.api.mapper.IotSensorMapper;
-import com.xunmei.mediator.api.service.EquipmentSyncService;
-import com.xunmei.mediator.api.service.IotSensorLogService;
-import com.xunmei.mediator.api.service.IotSensorService;
-import com.xunmei.mediator.api.service.NorthErrorService;
+import com.xunmei.mediator.api.service.*;
 import com.xunmei.mediator.util.CheckDataUtil;
 import com.xunmei.mediator.util.RedisCheckRepeatDataUtil;
 import com.xunmei.system.api.RemoteOrgService;
@@ -31,8 +28,11 @@ import com.xunmei.system.api.util.LogUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.transaction.support.TransactionSynchronization;
+import org.springframework.transaction.support.TransactionSynchronizationManager;
 
 import javax.annotation.Resource;
 import java.text.ParseException;
@@ -57,8 +57,9 @@ public class IotSensorServiceImpl extends ServiceImpl<IotSensorMapper, IotSensor
     private NorthErrorService northErrorService;
     @Resource
     private IotSensorLogService iotSensorLogService;
-    @Resource
-    private EquipmentSyncService equipmentSyncService;
+
+    @Autowired
+    private IotAlarmDataService iotAlarmDataService;
 
     @Override
     @Transactional(rollbackFor = Exception.class)
@@ -121,6 +122,19 @@ public class IotSensorServiceImpl extends ServiceImpl<IotSensorMapper, IotSensor
         northErrorService.saveErrorData(errors);
         updateBatchById(sensorList);
         iotSensorLogService.saveBatch(sensorLogList);
+
+        TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
+            @Override
+            public void afterCommit() {
+                try {
+                    iotAlarmDataService.dealSensorListData(sensorList);
+                } catch (Exception e) {
+                    throw new RuntimeException(e);
+                }
+            }
+        });
+
+
     }
 
     private String dealInfoData(String infoStr) {