浏览代码

soc-modules-iot模块-诊断任务、诊断阈值-绑定解绑操作,代码优化

humingshi-7@163.com 11 月之前
父节点
当前提交
762c5ec34d

+ 25 - 10
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/controller/CameraDiagnoseMissionController.java

@@ -8,6 +8,8 @@ import com.xunmei.iot.vo.alarmData.AlarmTypeSelectedVO;
 import com.xunmei.iot.vo.sensor.DiagnoseMissionPageVo;
 import io.swagger.annotations.ApiModelProperty;
 import io.swagger.annotations.ApiOperation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.web.bind.annotation.*;
 import javax.annotation.Resource;
 import java.util.List;
@@ -15,6 +17,8 @@ import java.util.List;
 @RestController
 @RequestMapping("/diagnoseMission")
 public class CameraDiagnoseMissionController {
+    protected Logger log = LoggerFactory.getLogger(getClass());
+
     @Resource
     private DiagnoseMissionService diagnoseMissionService;
 
@@ -25,23 +29,34 @@ public class CameraDiagnoseMissionController {
         return page;
     }
 
-    @ApiOperation("获取任务下拉框")
-    @GetMapping({"/missionTypeList"})
-    public List<AlarmTypeSelectedVO> missionTypeList() {
-        return diagnoseMissionService.missionTypeList();
-    }
-
     @ApiModelProperty("诊断任务绑定操作")
     @PostMapping({"/bindMission"})
     public AjaxResult bindMission(@RequestBody final DiagnoseMissionPageDto request) {
-        diagnoseMissionService.camerasBind(request);
-        return AjaxResult.success(null);
+        try {
+            diagnoseMissionService.camerasBind(request);
+        }catch (Exception e){
+            log.error("/diagnoseMission/bindMission,出现异常:{}",e);
+            return AjaxResult.error(e.getMessage());
+        }
+        return AjaxResult.success("操作成功");
     }
 
     @ApiModelProperty("诊断任务解绑操作")
     @PostMapping({"/unbindMission"})
     public AjaxResult unbindMission(@RequestBody final DiagnoseMissionPageDto request) {
-        diagnoseMissionService.selectDiagnoseMissionPage(request);
-        return AjaxResult.success(null);
+        try {
+            diagnoseMissionService.camerasUnbind(request);
+        }catch (Exception e){
+            log.error("/diagnoseMission/unbindMission,出现异常:{}",e);
+            return AjaxResult.error(e.getMessage());
+        }
+        return AjaxResult.success("操作成功");
+    }
+
+
+    @ApiOperation("获取任务下拉框")
+    @GetMapping({"/missionTypeList"})
+    public List<AlarmTypeSelectedVO> missionTypeList() {
+        return diagnoseMissionService.missionTypeList();
     }
 }

+ 24 - 10
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/controller/CameraDiagnoseThresholdController.java

@@ -8,6 +8,8 @@ import com.xunmei.iot.vo.alarmData.AlarmTypeSelectedVO;
 import com.xunmei.iot.vo.sensor.DiagnoseThresholdPageVo;
 import io.swagger.annotations.ApiModelProperty;
 import io.swagger.annotations.ApiOperation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.web.bind.annotation.*;
 import javax.annotation.Resource;
 import java.util.List;
@@ -15,6 +17,7 @@ import java.util.List;
 @RestController
 @RequestMapping("/diagnoseThreshold")
 public class CameraDiagnoseThresholdController {
+    protected Logger log = LoggerFactory.getLogger(getClass());
 
     @Resource
     private DiagnoseThresholdService diagnoseThresholdService;
@@ -26,23 +29,34 @@ public class CameraDiagnoseThresholdController {
         return page;
     }
 
-    @ApiOperation("获取阈值下拉框")
-    @GetMapping({"/thresholdTypeList"})
-    public List<AlarmTypeSelectedVO> thresholdTypeList() {
-        return diagnoseThresholdService.thresholdTypeList();
-    }
-
     @ApiModelProperty("诊断阈值绑定操作")
     @PostMapping({"/bindThreshold"})
     public AjaxResult bindThreshold(@RequestBody final DiagnoseThresholdPageDto request) {
-        diagnoseThresholdService.selectDiagnoseThresholdPage(request);
-        return AjaxResult.success(null);
+        try {
+            diagnoseThresholdService.camerasBind(request);
+        }catch (Exception e){
+            log.error("/diagnoseThreshold/bindThreshold,出现异常:{}",e);
+            return AjaxResult.error(e.getMessage());
+        }
+        return AjaxResult.success("操作成功");
     }
 
     @ApiModelProperty("诊断阈值解绑操作")
     @PostMapping({"/unbindThreshold"})
     public AjaxResult unbindThreshold(@RequestBody final DiagnoseThresholdPageDto request) {
-        diagnoseThresholdService.selectDiagnoseThresholdPage(request);
-        return AjaxResult.success(null);
+        try {
+            diagnoseThresholdService.camerasUnbind(request);
+        }catch (Exception e){
+            log.error("/diagnoseThreshold/unbindThreshold,出现异常:{}",e);
+            return AjaxResult.error(e.getMessage());
+        }
+        return AjaxResult.success("操作成功");
+    }
+
+
+    @ApiOperation("获取阈值下拉框")
+    @GetMapping({"/thresholdTypeList"})
+    public List<AlarmTypeSelectedVO> thresholdTypeList() {
+        return diagnoseThresholdService.thresholdTypeList();
     }
 }

+ 2 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/mapper/DiagnoseMissionChMapper.java

@@ -24,6 +24,8 @@ public interface DiagnoseMissionChMapper {
     int batchUpdateMissionCh(@Param("list") List<IotDeviceDiagnoseMissionCh> list);
     //批量插入-默认阈值通道绑定
     int batchInsertThresholdCh(@Param("list") List<IotDeviceDiagnoseThresholdCh> list);
+    //批量删除-任务通道
+    int batchDeleteMissionCh(@Param("ids") List<Long> ids);
 
     List<IotDeviceDiagnoseMission> selectAllDiagnoseMission();
 }

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

@@ -3,17 +3,28 @@ package com.xunmei.iot.mapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.xunmei.common.core.domain.iot.domain.IotDeviceDiagnoseThreshold;
+import com.xunmei.common.core.domain.iot.domain.IotDeviceDiagnoseThresholdCh;
 import com.xunmei.iot.dto.cameraDiagnose.DiagnoseThresholdPageDto;
+import com.xunmei.iot.vo.sensor.DiagnoseThresholdBindVo;
 import com.xunmei.iot.vo.sensor.DiagnoseThresholdPageVo;
 import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
-
 import java.util.List;
 
 @Repository
 public interface DiagnoseThresholdChMapper  extends BaseMapper<IotDeviceDiagnoseThreshold> {
     Page<DiagnoseThresholdPageVo> selectPageData(Page<DiagnoseThresholdPageVo> pageRequest, @Param("request") DiagnoseThresholdPageDto request);
-    List<IotDeviceDiagnoseThreshold> selectAllDiagnoseThreshold();
 
-    Integer selectBindCount(@Param("thresholdCode")String thresholdCode);
+    Integer selectCamerasCount(@Param("request") DiagnoseThresholdPageDto request);
+
+    List<DiagnoseThresholdBindVo> selectCamerasBind(@Param("request") DiagnoseThresholdPageDto request);
+
+    //批量插入-阈值通道绑定
+    int batchInsertThresholdCh(@Param("list") List<IotDeviceDiagnoseThresholdCh> list);
+    //批量删除-阈值通道
+    int batchDeleteThresholdCh(@Param("ids") List<Long> ids);
+    //修改阈值绑定的设备数量
+    Integer updateDignoseNumber(@Param("thresholdCode")String thresholdCode);
+
+    List<IotDeviceDiagnoseThreshold> selectAllDiagnoseThreshold();
 }

+ 4 - 2
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/DiagnoseMissionService.java

@@ -10,7 +10,9 @@ public interface DiagnoseMissionService {
 
     TableDataInfo<DiagnoseMissionPageVo> selectDiagnoseMissionPage(DiagnoseMissionPageDto request);
 
-    List<AlarmTypeSelectedVO> missionTypeList();
-
     void camerasBind(DiagnoseMissionPageDto request);
+
+    void camerasUnbind(DiagnoseMissionPageDto request);
+
+    List<AlarmTypeSelectedVO> missionTypeList();
 }

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

@@ -4,12 +4,15 @@ 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.DiagnoseThresholdPageVo;
-
 import java.util.List;
 
 public interface DiagnoseThresholdService {
 
     TableDataInfo<DiagnoseThresholdPageVo> selectDiagnoseThresholdPage(DiagnoseThresholdPageDto request);
 
+    void camerasBind(DiagnoseThresholdPageDto request);
+
+    void camerasUnbind(DiagnoseThresholdPageDto request);
+
     List<AlarmTypeSelectedVO> thresholdTypeList();
 }

+ 58 - 26
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/impl/DiagnoseMissionServiceImpl.java

@@ -27,8 +27,11 @@ import com.xunmei.iot.vo.sensor.DiagnoseMissionPageVo;
 import com.xunmei.system.api.RemoteOrgService;
 import com.xunmei.system.api.domain.SysOrg;
 import com.xunmei.system.api.vo.SysOrgVO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import javax.annotation.Resource;
 import java.util.Arrays;
 import java.util.List;
@@ -36,6 +39,8 @@ import java.util.stream.Collectors;
 
 @Service
 public class DiagnoseMissionServiceImpl implements DiagnoseMissionService {
+    protected Logger log = LoggerFactory.getLogger(getClass());
+
     @Resource
     private RemoteOrgService orgService;
 
@@ -94,29 +99,7 @@ public class DiagnoseMissionServiceImpl implements DiagnoseMissionService {
 
 
     @Override
-    public List<AlarmTypeSelectedVO> missionTypeList() {
-        List<AlarmTypeSelectedVO> list = Lists.newArrayList();
-        AlarmTypeSelectedVO bean;
-        List<IotDeviceDiagnoseMission> missions = diagnoseMissionChMapper.selectAllDiagnoseMission();
-
-        StringBuffer buffer;
-        for (IotDeviceDiagnoseMission mission : missions) {
-            bean = new AlarmTypeSelectedVO();
-
-            buffer = new StringBuffer();
-            buffer.append(mission.getName()).append("【")
-                    .append(mission.getBeginTime()).append("--").append(mission.getEndTime())
-                    .append("】");
-
-            bean.setValue(mission.getMissionId());
-            bean.setLabel(buffer.toString());
-            list.add(bean);
-        }
-
-        return list;
-    }
-
-    @Override
+    @Transactional
     public void camerasBind(DiagnoseMissionPageDto request){
         final SysOrg sysOrg = orgService.selectOrgById(request.getOrgId(), SecurityConstants.INNER);
         if (ObjectUtil.equal(Boolean.TRUE, request.getCheckSub())) {
@@ -182,8 +165,57 @@ public class DiagnoseMissionServiceImpl implements DiagnoseMissionService {
         }
 
         //更新默认阈值绑定数量
-        Integer cameraBindCount = diagnoseThresholdChMapper.selectBindCount(system.getThresholdCode());
-        system.setDignoseNumber(cameraBindCount);
-        diagnoseThresholdChMapper.updateById(system);
+        diagnoseThresholdChMapper.updateDignoseNumber(system.getThresholdCode());
+    }
+
+    @Override
+    @Transactional
+    public void camerasUnbind(DiagnoseMissionPageDto request){
+        final SysOrg sysOrg = orgService.selectOrgById(request.getOrgId(), SecurityConstants.INNER);
+        if (ObjectUtil.equal(Boolean.TRUE, request.getCheckSub())) {
+            request.setOrgPath(sysOrg.getPath());
+            request.setOrgId(null);
+        }
+
+        Integer camerasCount = diagnoseMissionChMapper.selectCamerasCount(request);
+        if (camerasCount == null || camerasCount == 0) {
+            String errorMsg = "绑定任务查询条件筛选结果为空!";
+            throw  new ServiceException(errorMsg);
+        }
+
+
+        List<DiagnoseMissionBindVo> list = diagnoseMissionChMapper.selectCamerasBind(request);
+
+        //需要解除绑定的集合
+        List<Long> unbindIds = Lists.newArrayList();
+        for (DiagnoseMissionBindVo item : list) {
+            if (StringUtils.isNotEmpty(item.getMissionId())) unbindIds.add(item.getId());
+        }
+        //删除绑定的诊断任务
+        if (unbindIds != null && !unbindIds.isEmpty()) diagnoseMissionChMapper.batchDeleteMissionCh(unbindIds);
+
+    }
+
+    @Override
+    public List<AlarmTypeSelectedVO> missionTypeList() {
+        List<AlarmTypeSelectedVO> list = Lists.newArrayList();
+        AlarmTypeSelectedVO bean;
+        List<IotDeviceDiagnoseMission> missions = diagnoseMissionChMapper.selectAllDiagnoseMission();
+
+        StringBuffer buffer;
+        for (IotDeviceDiagnoseMission mission : missions) {
+            bean = new AlarmTypeSelectedVO();
+
+            buffer = new StringBuffer();
+            buffer.append(mission.getName()).append("【")
+                    .append(mission.getBeginTime()).append("--").append(mission.getEndTime())
+                    .append("】");
+
+            bean.setValue(mission.getMissionId());
+            bean.setLabel(buffer.toString());
+            list.add(bean);
+        }
+
+        return list;
     }
 }

+ 104 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/impl/DiagnoseThresholdServiceImpl.java

@@ -6,7 +6,10 @@ import com.google.common.collect.Lists;
 import com.xunmei.common.core.constant.CacheConstants;
 import com.xunmei.common.core.constant.SecurityConstants;
 import com.xunmei.common.core.domain.iot.domain.IotDeviceDiagnoseThreshold;
+import com.xunmei.common.core.domain.iot.domain.IotDeviceDiagnoseThresholdCh;
 import com.xunmei.common.core.enums.OrgTypeEnum;
+import com.xunmei.common.core.exception.ServiceException;
+import com.xunmei.common.core.utils.IDHelper;
 import com.xunmei.common.core.utils.StringUtils;
 import com.xunmei.common.core.web.page.TableDataInfo;
 import com.xunmei.common.redis.utils.RedisUtils;
@@ -14,12 +17,14 @@ 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.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.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import javax.annotation.Resource;
 import java.util.Arrays;
 import java.util.List;
@@ -85,6 +90,105 @@ public class DiagnoseThresholdServiceImpl  implements DiagnoseThresholdService {
 
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void camerasBind(DiagnoseThresholdPageDto req) {
+        final SysOrg sysOrg = orgService.selectOrgById(req.getOrgId(), SecurityConstants.INNER);
+        if (ObjectUtil.equal(Boolean.TRUE, req.getCheckSub())) {
+            req.setOrgPath(sysOrg.getPath());
+            req.setOrgId(null);
+        }
+
+        Integer camerasCount = diagnoseThresholdChMapper.selectCamerasCount(req);
+        if (camerasCount == null || camerasCount == 0) {
+            String errorMsg = "绑定阈值查询条件筛选结果为空!";
+            throw  new ServiceException(errorMsg);
+        }
+
+        List<DiagnoseThresholdBindVo> list = diagnoseThresholdChMapper.selectCamerasBind(req);
+        //获取要绑定的通道
+        List<IotDeviceDiagnoseThresholdCh> batchInserts = Lists.newArrayList();
+
+        List<String> bindThresholdCodes = req.getBindThresholdCodes();
+        if (bindThresholdCodes != null && !bindThresholdCodes.isEmpty()) {
+            for (String bindThresholdCode:bindThresholdCodes) {
+                for (DiagnoseThresholdBindVo info : list) {
+                    String beanThresholdCodes = info.getThresholdCodes();
+                    //避免重复绑定
+                    if (StringUtils.isNotEmpty(beanThresholdCodes)
+                            &&beanThresholdCodes.contains(bindThresholdCode)) {continue;}
+
+                    IotDeviceDiagnoseThresholdCh ch = new IotDeviceDiagnoseThresholdCh();
+                    //1.生成绑定数据
+                    ch.setIotToken(info.getIotToken());
+                    ch.setDeviceProduct(info.getDeviceProduct());
+                    ch.setDvs(info.getDvs());
+                    ch.setChannel(info.getChannel());
+                    ch.setThresholdCode(bindThresholdCode);
+                    ch.setId(IDHelper.id());
+                    batchInserts.add(ch);
+                }
+            }
+            if (batchInserts != null && !batchInserts.isEmpty()) {
+                diagnoseThresholdChMapper.batchInsertThresholdCh(batchInserts);
+            }
+            //获取涉及阈值配置,并修改设备数量
+            for (String bindThresholdCode:bindThresholdCodes) {
+                diagnoseThresholdChMapper.updateDignoseNumber(bindThresholdCode);
+            }
+        }
+    }
+
+    @Override
+    public void camerasUnbind(DiagnoseThresholdPageDto req){
+        final SysOrg sysOrg = orgService.selectOrgById(req.getOrgId(), SecurityConstants.INNER);
+        if (ObjectUtil.equal(Boolean.TRUE, req.getCheckSub())) {
+            req.setOrgPath(sysOrg.getPath());
+            req.setOrgId(null);
+        }
+
+        Integer camerasCount = diagnoseThresholdChMapper.selectCamerasCount(req);
+        if (camerasCount == null || camerasCount == 0) {
+            String errorMsg = "解绑阈值查询条件筛选结果为空!";
+            throw  new ServiceException(errorMsg);
+        }
+
+        List<DiagnoseThresholdBindVo> list = diagnoseThresholdChMapper.selectCamerasBind(req);
+
+        //需要解除绑定的id集合
+        List<Long> unbindIds = Lists.newArrayList();
+
+        List<String> unbindThresholdCodes = req.getBindThresholdCodes();
+        if (unbindThresholdCodes != null && !unbindThresholdCodes.isEmpty()) {
+            for (String unbindThresholdCode:unbindThresholdCodes) {
+                for (DiagnoseThresholdBindVo info : list) {
+                    String beanThresholdCodes = info.getThresholdCodes();
+                    //通道是否有绑定阈值
+                    if(StringUtils.isNotEmpty(beanThresholdCodes)) {
+                        String[] beanThresholdCodeArr = beanThresholdCodes.split(",");
+                        //通道绑定的阈值是否与将要解绑的一致,一致就解绑
+                        for (String beanThresholdCode : beanThresholdCodeArr) {
+                            if (beanThresholdCode.contains(unbindThresholdCode)) {
+                                String id = beanThresholdCode.split("#")[1];
+                                unbindIds.add(Long.parseLong(id));
+                            }
+                        }
+
+                    }
+                }
+            }
+
+            if (unbindIds != null && !unbindIds.isEmpty()) {
+                diagnoseThresholdChMapper.batchDeleteThresholdCh(unbindIds);
+            }
+            //获取涉及阈值配置,并修改设备数量
+            for (String bindThresholdCode:unbindThresholdCodes) {
+                diagnoseThresholdChMapper.updateDignoseNumber(bindThresholdCode);
+            }
+        }
+    }
+
+
+    @Override
     public List<AlarmTypeSelectedVO> thresholdTypeList() {
         List<AlarmTypeSelectedVO> list = Lists.newArrayList();
         AlarmTypeSelectedVO bean;

+ 1 - 1
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/vo/sensor/DiagnoseMissionBindVo.java

@@ -8,6 +8,6 @@ import lombok.Data;
 @Data
 public class DiagnoseMissionBindVo extends IotDeviceDiagnoseMissionCh {
     @JsonIgnore
-    @ApiModelProperty("机构路径")
+    @ApiModelProperty("已绑定阈值集合")
     private String thresholdCodes;
 }

+ 14 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/vo/sensor/DiagnoseThresholdBindVo.java

@@ -0,0 +1,14 @@
+package com.xunmei.iot.vo.sensor;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.xunmei.common.core.domain.iot.domain.IotDeviceDiagnoseThresholdCh;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+public class DiagnoseThresholdBindVo extends IotDeviceDiagnoseThresholdCh{
+
+    @JsonIgnore
+    @ApiModelProperty("已绑定阈值集合")
+    private String thresholdCodes;
+}

+ 11 - 3
soc-modules/soc-modules-iot/src/main/resources/mapper/DiagnoseMissionChMapper.xml

@@ -89,15 +89,15 @@
     <select id="selectCamerasBind" resultType="com.xunmei.iot.vo.sensor.DiagnoseMissionBindVo">
         select c.* from
         (
-        select s.iot_token,s.device_product,s.host_code dvs,s.device_code channel,
-        (select mission_id from iot_device_diagnose_mission_ch ch where ch.iot_token = s.iot_token
-        and ch.device_product=s.device_product and ch.dvs = s.host_code and ch.channel = s.device_code limit 1) mission_id,
+        select s.iot_token,s.device_product,s.host_code dvs,s.device_code channel,ch.mission_id,ch.id,
         (select group_concat(threshold_code) from iot_device_diagnose_threshold_ch ch where ch.iot_token = s.iot_token
         and ch.device_product=s.device_product and ch.dvs = s.host_code and ch.channel = s.device_code) threshold_codes
         from iot_device_info s
         inner join iot_device_info dvs on dvs.iot_token = s.iot_token
         and dvs.device_product = s.device_product and dvs.device_code = s.host_code
         and dvs.deleted = 0 and s.enable = 0 and dvs.device_type = 1
+        left join iot_device_diagnose_mission_ch ch on ch.iot_token = s.iot_token
+        and ch.device_product=s.device_product and ch.dvs = s.host_code and ch.channel = s.device_code
         where s.deleted=0 and s.enable=0 and s.device_type = 2
         <if test="request.orgId!= null">
             and s.org_id=#{request.orgId}
@@ -159,6 +159,14 @@
         </foreach>
     </insert>
 
+
+    <delete id="batchDeleteMissionCh" parameterType="java.lang.Long">
+        delete from iot_device_diagnose_mission_ch where id in
+        <foreach collection="ids" item="item" index="index"
+                 open="(" separator="," close=")">#{item}
+        </foreach>
+    </delete>
+
     <select id="selectAllDiagnoseMission" resultType="com.xunmei.common.core.domain.iot.domain.IotDeviceDiagnoseMission">
         select * from iot_device_diagnose_mission
     </select>

+ 108 - 4
soc-modules/soc-modules-iot/src/main/resources/mapper/DiagnoseThresholdChMapper.xml

@@ -44,11 +44,115 @@
 
     </select>
 
-    <select id="selectAllDiagnoseThreshold" resultType="com.xunmei.common.core.domain.iot.domain.IotDeviceDiagnoseThreshold">
-        select * from iot_device_diagnose_threshold
+
+    <select id="selectCamerasCount" resultType="java.lang.Integer">
+        select count(1) from
+        (
+        select s.iot_token,s.device_product,s.host_code dvs,s.device_code channel,
+        (select group_concat(threshold_code) from iot_device_diagnose_threshold_ch ch where ch.iot_token = s.iot_token
+        and ch.device_product=s.device_product and ch.dvs = s.host_code and ch.channel = s.device_code) threshold_codes
+        from iot_device_info s
+        inner join iot_device_info dvs on dvs.iot_token = s.iot_token
+        and dvs.device_product = s.device_product and dvs.device_code = s.host_code
+        and dvs.deleted = 0 and s.enable = 0 and dvs.device_type = 1
+        where s.deleted=0 and s.enable=0 and s.device_type = 2
+        <if test="request.orgId!= null">
+            and s.org_id=#{request.orgId}
+        </if>
+        <if test="request.orgPath!= null">
+            and s.org_path like CONCAT(#{request.orgPath}, '%')
+        </if>
+        <if test="request.deviceName != null and request.deviceName!= ''">
+            and s.device_name like CONCAT('%',#{request.deviceName},'%')
+        </if>
+        order by s.host_code ,cast(s.device_code as signed)
+        ) c where 1=1
+        <choose>
+            <when test=" request.state == null">
+            </when>
+            <when test=" request.state == 0">
+                and c.threshold_codes is null
+            </when>
+            <otherwise>
+                and c.threshold_codes is not null
+            </otherwise>
+        </choose>
+        <choose>
+            <when test=" request.thresholdCode != null and request.thresholdCode != '' ">
+                and c.threshold_codes like CONCAT('%',#{request.thresholdCode}, '%')
+            </when>
+            <otherwise>
+            </otherwise>
+        </choose>
+
     </select>
 
-    <select id="selectBindCount" resultType="java.lang.Integer">
-        select count(1) from iot_device_diagnose_threshold_ch where threshold_code = #{thresholdCode}
+    <select id="selectCamerasBind" resultType="com.xunmei.iot.vo.sensor.DiagnoseThresholdBindVo">
+        select c.* from
+        (
+        select s.iot_token,s.device_product,s.host_code dvs,s.device_code channel,
+        (select group_concat(concat(threshold_code,'#',id)) from iot_device_diagnose_threshold_ch ch where ch.iot_token = s.iot_token
+        and ch.device_product=s.device_product and ch.dvs = s.host_code and ch.channel = s.device_code) threshold_codes
+        from iot_device_info s
+        inner join iot_device_info dvs on dvs.iot_token = s.iot_token
+        and dvs.device_product = s.device_product and dvs.device_code = s.host_code
+        and dvs.deleted = 0 and s.enable = 0 and dvs.device_type = 1
+        where s.deleted=0 and s.enable=0 and s.device_type = 2
+        <if test="request.orgId!= null">
+            and s.org_id=#{request.orgId}
+        </if>
+        <if test="request.orgPath!= null">
+            and s.org_path like CONCAT(#{request.orgPath}, '%')
+        </if>
+        <if test="request.deviceName != null and request.deviceName!= ''">
+            and s.device_name like CONCAT('%',#{request.deviceName},'%')
+        </if>
+        order by s.host_code ,cast(s.device_code as signed)
+        ) c where 1=1
+        <choose>
+            <when test=" request.state == null">
+            </when>
+            <when test=" request.state == 0">
+                and c.threshold_codes is null
+            </when>
+            <otherwise>
+                and c.threshold_codes is not null
+            </otherwise>
+        </choose>
+        <choose>
+            <when test=" request.thresholdCode != null and request.thresholdCode != '' ">
+                and c.threshold_codes like CONCAT('%',#{request.thresholdCode}, '%')
+            </when>
+            <otherwise>
+            </otherwise>
+        </choose>
+
+    </select>
+
+    <insert id="batchInsertThresholdCh" parameterType="java.util.List">
+        insert into iot_device_diagnose_threshold_ch (id,threshold_code,iot_token,device_product,dvs,channel)
+        values
+        <foreach collection="list" item="item" index="index" separator=",">
+            (#{item.id},#{item.thresholdCode},#{item.iotToken},#{item.deviceProduct},#{item.dvs}, #{item.channel})
+        </foreach>
+    </insert>
+
+    <delete id="batchDeleteThresholdCh" parameterType="java.lang.Long">
+        delete from iot_device_diagnose_threshold_ch where id in
+        <foreach collection="ids" item="item" index="index"
+                 open="(" separator="," close=")">#{item}
+        </foreach>
+    </delete>
+
+    <select id="updateDignoseNumber" resultType="java.lang.Integer">
+        update iot_device_diagnose_threshold set dignose_number =
+        (
+           select count(1) from iot_device_diagnose_threshold_ch where threshold_code = #{thresholdCode}
+        )
+        where threshold_code =  #{thresholdCode}
+    </select>
+
+    <select id="selectAllDiagnoseThreshold" resultType="com.xunmei.common.core.domain.iot.domain.IotDeviceDiagnoseThreshold">
+        select * from iot_device_diagnose_threshold
     </select>
 </mapper>