Преглед изворни кода

soc-modules-iot模块-诊断阈值管理-添加编辑

humingshi-7@163.com пре 11 месеци
родитељ
комит
f433281a68

+ 3 - 3
project_data/sql/1.0.11/soc.sql

@@ -223,10 +223,10 @@ CREATE TABLE `iot_device_diagnose_threshold` (
   `fuzzy` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '模糊',
   `contrast` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '对比度',
   `create_time` datetime DEFAULT NULL COMMENT '创建时间',
-  `dignose_number` int DEFAULT NULL COMMENT '绑定通道数量',
+  `diagnose_number` int DEFAULT NULL COMMENT '绑定通道数量',
   `type` bigint DEFAULT NULL COMMENT '是否默认标识,1为默认,0为其他',
-  `validityBeginTime` time DEFAULT NULL COMMENT '有效开始时间',
-  `validityEndTime` time DEFAULT NULL COMMENT '有效结束时间',
+  `begin_time` time DEFAULT NULL COMMENT '有效开始时间',
+  `end_time` time DEFAULT NULL COMMENT '有效结束时间',
   `iot_token` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT 'iot服务唯一编码',
   PRIMARY KEY (`threshold_code`) USING BTREE
 ) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='摄像机诊断阈值表';

+ 6 - 6
soc-common/soc-common-core/src/main/java/com/xunmei/common/core/domain/iot/domain/IotDeviceDiagnoseThreshold.java

@@ -76,20 +76,20 @@ public class IotDeviceDiagnoseThreshold implements Serializable {
     private LocalDateTime createTime;
 
     @ApiModelProperty(value = "绑定通道数量")
-    @TableField("dignose_number")
-    private Integer dignoseNumber;
+    @TableField("diagnose_number")
+    private Integer diagnoseNumber;
 
     @ApiModelProperty(value = "是否默认标识,1为默认,0为其他")
     @TableField("type")
     private Long type;
 
     @ApiModelProperty(value = "有效开始时间")
-    @TableField("validityBeginTime")
-    private LocalTime validitybegintime;
+    @TableField("begin_time")
+    private String beginTime;
 
     @ApiModelProperty(value = "有效结束时间")
-    @TableField("validityEndTime")
-    private LocalTime validityendtime;
+    @TableField("end_time")
+    private String endTime;
 
     @ApiModelProperty(value = "iot服务唯一编码")
     @TableField("iot_token")

+ 47 - 2
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/controller/CameraDiagnoseThresholdController.java

@@ -1,10 +1,12 @@
 package com.xunmei.iot.controller;
 
+import com.xunmei.common.core.domain.iot.domain.IotDeviceDiagnoseThreshold;
 import com.xunmei.common.core.web.domain.AjaxResult;
 import com.xunmei.common.core.web.page.TableDataInfo;
 import com.xunmei.iot.dto.cameraDiagnose.DiagnoseThresholdPageDto;
 import com.xunmei.iot.service.DiagnoseThresholdService;
 import com.xunmei.iot.vo.alarmData.AlarmTypeSelectedVO;
+import com.xunmei.iot.vo.sensor.DiagnoseThresholdAddVo;
 import com.xunmei.iot.vo.sensor.DiagnoseThresholdPageVo;
 import io.swagger.annotations.ApiModelProperty;
 import io.swagger.annotations.ApiOperation;
@@ -23,9 +25,9 @@ public class CameraDiagnoseThresholdController {
     private DiagnoseThresholdService diagnoseThresholdService;
 
     @ApiOperation("诊断阈值绑定列表")
-    @PostMapping({"/list"})
+    @PostMapping({"/cameraList"})
     public TableDataInfo<DiagnoseThresholdPageVo> webPage(@RequestBody final DiagnoseThresholdPageDto request) {
-        TableDataInfo<DiagnoseThresholdPageVo> page = diagnoseThresholdService.selectDiagnoseThresholdPage(request);
+        TableDataInfo<DiagnoseThresholdPageVo> page = diagnoseThresholdService.selectCameraThresholdPage(request);
         return page;
     }
 
@@ -54,6 +56,49 @@ public class CameraDiagnoseThresholdController {
     }
 
 
+    @ApiOperation("诊断阈值管理列表")
+    @GetMapping({"/list"})
+    public List<IotDeviceDiagnoseThreshold> list() {
+        return diagnoseThresholdService.selectThresholdPage();
+    }
+
+
+    @ApiOperation("删除诊断阈值")
+    @GetMapping({"/deleteThreshold"})
+    public AjaxResult deleteThreshold(@RequestParam(value = "thresholdCode")String thresholdCode) {
+        try {
+            diagnoseThresholdService.deleteThreshold(thresholdCode);
+        }catch (Exception e){
+            log.error("/diagnoseThreshold/deleteThreshold,出现异常:{}",e);
+            return AjaxResult.error(e.getMessage());
+        }
+        return AjaxResult.success("操作成功");
+    }
+
+    @ApiOperation("添加诊断阈值")
+    @PostMapping({"/addThreshold"})
+    public AjaxResult addThreshold(@RequestBody DiagnoseThresholdAddVo request) {
+        try {
+            diagnoseThresholdService.addThreshold(request);
+        }catch (Exception e){
+            log.error("/diagnoseThreshold/addThreshold,出现异常:{}",e);
+            return AjaxResult.error(e.getMessage());
+        }
+        return AjaxResult.success("操作成功");
+    }
+
+    @ApiOperation("编辑诊断阈值")
+    @PostMapping({"/editThreshold"})
+    public AjaxResult editThreshold(@RequestBody DiagnoseThresholdAddVo request) {
+        try {
+            diagnoseThresholdService.editThreshold(request);
+        }catch (Exception e){
+            log.error("/diagnoseThreshold/editThreshold,出现异常:{}",e);
+            return AjaxResult.error(e.getMessage());
+        }
+        return AjaxResult.success("操作成功");
+    }
+
     @ApiOperation("获取阈值下拉框")
     @GetMapping({"/thresholdTypeList"})
     public List<AlarmTypeSelectedVO> thresholdTypeList() {

+ 3 - 1
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/mapper/DiagnoseThresholdChMapper.java

@@ -24,7 +24,9 @@ public interface DiagnoseThresholdChMapper  extends BaseMapper<IotDeviceDiagnose
     //批量删除-阈值通道
     int batchDeleteThresholdCh(@Param("ids") List<Long> ids);
     //修改阈值绑定的设备数量
-    Integer updateDignoseNumber(@Param("thresholdCode")String thresholdCode);
+    Integer updateDiagnoseNumber(@Param("thresholdCode")String thresholdCode);
+
+    int deleteCamerasByThresholdCode(@Param("thresholdCode")String thresholdCode);
 
     List<IotDeviceDiagnoseThreshold> selectAllDiagnoseThreshold();
 }

+ 11 - 1
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/DiagnoseThresholdService.java

@@ -1,18 +1,28 @@
 package com.xunmei.iot.service;
 
+import com.xunmei.common.core.domain.iot.domain.IotDeviceDiagnoseThreshold;
 import com.xunmei.common.core.web.page.TableDataInfo;
 import com.xunmei.iot.dto.cameraDiagnose.DiagnoseThresholdPageDto;
 import com.xunmei.iot.vo.alarmData.AlarmTypeSelectedVO;
+import com.xunmei.iot.vo.sensor.DiagnoseThresholdAddVo;
 import com.xunmei.iot.vo.sensor.DiagnoseThresholdPageVo;
 import java.util.List;
 
 public interface DiagnoseThresholdService {
 
-    TableDataInfo<DiagnoseThresholdPageVo> selectDiagnoseThresholdPage(DiagnoseThresholdPageDto request);
+    TableDataInfo<DiagnoseThresholdPageVo> selectCameraThresholdPage(DiagnoseThresholdPageDto request);
 
     void camerasBind(DiagnoseThresholdPageDto request);
 
     void camerasUnbind(DiagnoseThresholdPageDto request);
 
+    List<IotDeviceDiagnoseThreshold> selectThresholdPage();
+
+    void deleteThreshold(String thresholdCode);
+
+    void addThreshold(DiagnoseThresholdAddVo request);
+
+    void editThreshold(DiagnoseThresholdAddVo request);
+
     List<AlarmTypeSelectedVO> thresholdTypeList();
 }

+ 2 - 1
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/impl/DiagnoseMissionServiceImpl.java

@@ -169,7 +169,7 @@ public class DiagnoseMissionServiceImpl implements DiagnoseMissionService {
         }
 
         //更新默认阈值绑定数量
-        diagnoseThresholdChMapper.updateDignoseNumber(system.getThresholdCode());
+        diagnoseThresholdChMapper.updateDiagnoseNumber(system.getThresholdCode());
     }
 
     @Override
@@ -206,6 +206,7 @@ public class DiagnoseMissionServiceImpl implements DiagnoseMissionService {
     }
 
     @Override
+    @Transactional
     public void deleteMission(String missionId){
 //        QueryWrapper<IotDeviceDiagnoseMission> queryWrapper = new QueryWrapper();
 //        queryWrapper.eq("mission_id", missionId);

+ 147 - 5
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/impl/DiagnoseThresholdServiceImpl.java

@@ -1,6 +1,8 @@
 package com.xunmei.iot.service.impl;
 
 import cn.hutool.core.util.ObjectUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.google.common.collect.Lists;
 import com.xunmei.common.core.constant.CacheConstants;
@@ -17,15 +19,21 @@ import com.xunmei.iot.dto.cameraDiagnose.DiagnoseThresholdPageDto;
 import com.xunmei.iot.mapper.DiagnoseThresholdChMapper;
 import com.xunmei.iot.service.DiagnoseThresholdService;
 import com.xunmei.iot.vo.alarmData.AlarmTypeSelectedVO;
+import com.xunmei.iot.vo.sensor.DiagnoseThresholdAddVo;
 import com.xunmei.iot.vo.sensor.DiagnoseThresholdBindVo;
 import com.xunmei.iot.vo.sensor.DiagnoseThresholdPageVo;
 import com.xunmei.system.api.RemoteOrgService;
 import com.xunmei.system.api.domain.SysOrg;
 import com.xunmei.system.api.vo.SysOrgVO;
+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.util.DigestUtils;
+
 import javax.annotation.Resource;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
 import java.util.Arrays;
 import java.util.List;
 import java.util.stream.Collectors;
@@ -39,7 +47,7 @@ public class DiagnoseThresholdServiceImpl  implements DiagnoseThresholdService {
     private DiagnoseThresholdChMapper diagnoseThresholdChMapper;
 
     @Override
-    public TableDataInfo<DiagnoseThresholdPageVo> selectDiagnoseThresholdPage(DiagnoseThresholdPageDto request) {
+    public TableDataInfo<DiagnoseThresholdPageVo> selectCameraThresholdPage(DiagnoseThresholdPageDto request) {
         final SysOrg sysOrg = orgService.selectOrgById(request.getOrgId(), SecurityConstants.INNER);
         if (ObjectUtil.equal(Boolean.TRUE, request.getCheckSub())) {
             request.setOrgPath(sysOrg.getPath());
@@ -69,7 +77,7 @@ public class DiagnoseThresholdServiceImpl  implements DiagnoseThresholdService {
                     for(IotDeviceDiagnoseThreshold threshold:thresholds){
                         if(threshold.getThresholdCode().equals(code)){
                             buffer.append(threshold.getThresholdName()).append("【")
-                                    .append(threshold.getValiditybegintime()).append("--").append(threshold.getValidityendtime())
+                                    .append(threshold.getBeginTime()).append("--").append(threshold.getEndTime())
                                     .append("】").append(",");
                             isMatch = true;
                         }
@@ -133,7 +141,7 @@ public class DiagnoseThresholdServiceImpl  implements DiagnoseThresholdService {
             }
             //获取涉及阈值配置,并修改设备数量
             for (String bindThresholdCode:bindThresholdCodes) {
-                diagnoseThresholdChMapper.updateDignoseNumber(bindThresholdCode);
+                diagnoseThresholdChMapper.updateDiagnoseNumber(bindThresholdCode);
             }
         }
     }
@@ -182,11 +190,106 @@ public class DiagnoseThresholdServiceImpl  implements DiagnoseThresholdService {
             }
             //获取涉及阈值配置,并修改设备数量
             for (String bindThresholdCode:unbindThresholdCodes) {
-                diagnoseThresholdChMapper.updateDignoseNumber(bindThresholdCode);
+                diagnoseThresholdChMapper.updateDiagnoseNumber(bindThresholdCode);
             }
         }
     }
 
+    @Override
+    public List<IotDeviceDiagnoseThreshold> selectThresholdPage(){
+        return diagnoseThresholdChMapper.selectList(Wrappers.emptyWrapper());
+    }
+
+    @Override
+    @Transactional
+    public void deleteThreshold(String thresholdCode){
+        IotDeviceDiagnoseThreshold system = diagnoseThresholdChMapper.selectById(thresholdCode);
+        if (system == null) {
+            String errorMsg = "当前阈值不存在!";
+            throw  new ServiceException(errorMsg);
+        }
+        if (system.getType() == 1) {
+            String errorMsg = "默认阈值不能删除!";
+            throw  new ServiceException(errorMsg);
+        }
+        //删除阈值
+        diagnoseThresholdChMapper.deleteById(thresholdCode);
+        //删除关联视频通道
+        diagnoseThresholdChMapper.deleteCamerasByThresholdCode(thresholdCode);
+    }
+
+    @Override
+    public void addThreshold(DiagnoseThresholdAddVo request){
+        String nosignal=request.getNosignal().replace("&gt;",">").replace("&lt;","<");
+        String covered=request.getCovered().replace("&gt;",">").replace("&lt;","<");
+        request.setNosignal(nosignal);
+        request.setCovered(covered);
+
+        String thresholdCode = DigestUtils.md5DigestAsHex(getThresholdGuid(request).getBytes());
+
+        QueryWrapper<IotDeviceDiagnoseThreshold> queryWrapper = new QueryWrapper();
+        queryWrapper.eq("threshold_code", thresholdCode);
+        List<IotDeviceDiagnoseThreshold> list = diagnoseThresholdChMapper.selectList(queryWrapper);
+        if (!list.isEmpty()) {
+            String errorMsg = "已存在相同参数的阈值配置'" + list.get(0).getThresholdName() + "'!";
+            throw  new ServiceException(errorMsg);
+        }
+
+        queryWrapper = new QueryWrapper();
+        queryWrapper.eq("threshold_name", request.getThresholdName());
+        long nameCount = diagnoseThresholdChMapper.selectCount(queryWrapper);
+        if (nameCount > 0) {
+            String errorMsg = "已存在相同名称的阈值配置";
+            throw  new ServiceException(errorMsg);
+        }
+
+        IotDeviceDiagnoseThreshold threshold = new IotDeviceDiagnoseThreshold();
+
+        BeanUtils.copyProperties(request, threshold);
+        threshold.setBeginTime(request.getTimeRange()[0]);
+        threshold.setEndTime(request.getTimeRange()[1]);
+
+        threshold.setThresholdCode(thresholdCode);
+        threshold.setCreateTime(LocalDateTime.now());
+        threshold.setDiagnoseNumber(0);
+        threshold.setType(0L);
+
+        diagnoseThresholdChMapper.insert(threshold);
+    }
+
+    @Override
+    public void editThreshold(DiagnoseThresholdAddVo request){
+        //todo:
+        String thresholdCode = DigestUtils.md5DigestAsHex(getThresholdGuid(request).getBytes());
+
+        QueryWrapper<IotDeviceDiagnoseThreshold> queryWrapper = new QueryWrapper();
+//        queryWrapper.eq("threshold_code", thresholdCode);
+//        List<IotDeviceDiagnoseThreshold> list = diagnoseThresholdChMapper.selectList(queryWrapper);
+//        if (!list.isEmpty()) {
+//            String errorMsg = "已存在相同参数的阈值配置'" + list.get(0).getThresholdName() + "'!";
+//            throw  new ServiceException(errorMsg);
+//        }
+
+        queryWrapper = new QueryWrapper();
+        queryWrapper.eq("threshold_name", request.getThresholdName()).ne("threshold_code", thresholdCode);
+        long nameCount = diagnoseThresholdChMapper.selectCount(queryWrapper);
+        if (nameCount > 0) {
+            String errorMsg = "已存在相同名称的阈值配置";
+            throw new ServiceException(errorMsg);
+        }
+
+        IotDeviceDiagnoseThreshold threshold = new IotDeviceDiagnoseThreshold();
+
+        BeanUtils.copyProperties(request, threshold);
+        threshold.setBeginTime(request.getTimeRange()[0]);
+        threshold.setEndTime(request.getTimeRange()[1]);
+
+        threshold.setThresholdCode(thresholdCode);
+        threshold.setCreateTime(LocalDateTime.now());
+        threshold.setType(0L);
+
+        diagnoseThresholdChMapper.updateById(threshold);
+    }
 
     @Override
     public List<AlarmTypeSelectedVO> thresholdTypeList() {
@@ -200,7 +303,7 @@ public class DiagnoseThresholdServiceImpl  implements DiagnoseThresholdService {
 
             buffer = new StringBuffer();
             buffer.append(threshold.getThresholdName()).append("【")
-                    .append(threshold.getValiditybegintime()).append("--").append(threshold.getValidityendtime())
+                    .append(threshold.getBeginTime()).append("--").append(threshold.getEndTime())
                     .append("】");
 
             bean.setValue(threshold.getThresholdCode());
@@ -210,4 +313,43 @@ public class DiagnoseThresholdServiceImpl  implements DiagnoseThresholdService {
 
         return list;
     }
+
+    private String getThresholdGuid(IotDeviceDiagnoseThreshold threshold) {
+        StringBuffer sb = new StringBuffer();
+        String color = "@value>=150";
+        threshold.setColor(color);
+        sb.append(color);
+
+        String contrast = "@value<=0";
+        threshold.setContrast(contrast);
+        sb.append(contrast);
+
+        String covered = threshold.getCovered();
+        sb.append(covered);
+
+        String freeze = "@value>=250";
+        threshold.setFreeze(freeze);
+        sb.append(freeze);
+
+        String fuzzy = "@value>=253";
+        threshold.setFuzzy(fuzzy);
+        sb.append(fuzzy);
+
+        String luminance = "@value>=225";
+        threshold.setLuminance(luminance);
+        sb.append(luminance);
+
+        String nosignal = threshold.getNosignal();
+        sb.append(nosignal);
+
+        String roll = "@value>=140";
+        threshold.setRoll(roll);
+        sb.append(roll);
+
+        String snow = "@value>=7";
+        threshold.setSnow(snow);
+        sb.append(snow);
+
+        return sb.toString();
+    }
 }

+ 12 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/vo/sensor/DiagnoseThresholdAddVo.java

@@ -0,0 +1,12 @@
+package com.xunmei.iot.vo.sensor;
+
+import com.xunmei.common.core.domain.iot.domain.IotDeviceDiagnoseThreshold;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+public class DiagnoseThresholdAddVo extends IotDeviceDiagnoseThreshold {
+
+    @ApiModelProperty("已选择有效时段集合")
+    private String[] timeRange;
+}

+ 6 - 2
soc-modules/soc-modules-iot/src/main/resources/mapper/DiagnoseThresholdChMapper.xml

@@ -144,14 +144,18 @@
         </foreach>
     </delete>
 
-    <select id="updateDignoseNumber" resultType="java.lang.Integer">
-        update iot_device_diagnose_threshold set dignose_number =
+    <select id="updateDiagnoseNumber" resultType="java.lang.Integer">
+        update iot_device_diagnose_threshold set diagnose_number =
         (
            select count(1) from iot_device_diagnose_threshold_ch where threshold_code = #{thresholdCode}
         )
         where threshold_code =  #{thresholdCode}
     </select>
 
+    <delete id="deleteCamerasByThresholdCode">
+        delete from iot_device_diagnose_threshold_ch where threshold_code = #{thresholdCode}
+    </delete>
+
     <select id="selectAllDiagnoseThreshold" resultType="com.xunmei.common.core.domain.iot.domain.IotDeviceDiagnoseThreshold">
         select * from iot_device_diagnose_threshold
     </select>