|  | @@ -1,6 +1,8 @@
 | 
											
												
													
														|  |  package com.xunmei.iot.service.impl;
 |  |  package com.xunmei.iot.service.impl;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  import cn.hutool.core.util.ObjectUtil;
 |  |  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.baomidou.mybatisplus.extension.plugins.pagination.Page;
 | 
											
												
													
														|  |  import com.google.common.collect.Lists;
 |  |  import com.google.common.collect.Lists;
 | 
											
												
													
														|  |  import com.xunmei.common.core.constant.CacheConstants;
 |  |  import com.xunmei.common.core.constant.CacheConstants;
 | 
											
										
											
												
													
														|  | @@ -9,6 +11,7 @@ import com.xunmei.common.core.domain.iot.domain.IotDeviceDiagnoseThreshold;
 | 
											
												
													
														|  |  import com.xunmei.common.core.domain.iot.domain.IotDeviceDiagnoseThresholdCh;
 |  |  import com.xunmei.common.core.domain.iot.domain.IotDeviceDiagnoseThresholdCh;
 | 
											
												
													
														|  |  import com.xunmei.common.core.enums.OrgTypeEnum;
 |  |  import com.xunmei.common.core.enums.OrgTypeEnum;
 | 
											
												
													
														|  |  import com.xunmei.common.core.exception.ServiceException;
 |  |  import com.xunmei.common.core.exception.ServiceException;
 | 
											
												
													
														|  | 
 |  | +import com.xunmei.common.core.utils.DateUtils;
 | 
											
												
													
														|  |  import com.xunmei.common.core.utils.IDHelper;
 |  |  import com.xunmei.common.core.utils.IDHelper;
 | 
											
												
													
														|  |  import com.xunmei.common.core.utils.StringUtils;
 |  |  import com.xunmei.common.core.utils.StringUtils;
 | 
											
												
													
														|  |  import com.xunmei.common.core.web.page.TableDataInfo;
 |  |  import com.xunmei.common.core.web.page.TableDataInfo;
 | 
											
										
											
												
													
														|  | @@ -17,14 +20,17 @@ import com.xunmei.iot.dto.cameraDiagnose.DiagnoseThresholdPageDto;
 | 
											
												
													
														|  |  import com.xunmei.iot.mapper.DiagnoseThresholdChMapper;
 |  |  import com.xunmei.iot.mapper.DiagnoseThresholdChMapper;
 | 
											
												
													
														|  |  import com.xunmei.iot.service.DiagnoseThresholdService;
 |  |  import com.xunmei.iot.service.DiagnoseThresholdService;
 | 
											
												
													
														|  |  import com.xunmei.iot.vo.alarmData.AlarmTypeSelectedVO;
 |  |  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.DiagnoseThresholdBindVo;
 | 
											
												
													
														|  |  import com.xunmei.iot.vo.sensor.DiagnoseThresholdPageVo;
 |  |  import com.xunmei.iot.vo.sensor.DiagnoseThresholdPageVo;
 | 
											
												
													
														|  |  import com.xunmei.system.api.RemoteOrgService;
 |  |  import com.xunmei.system.api.RemoteOrgService;
 | 
											
												
													
														|  |  import com.xunmei.system.api.domain.SysOrg;
 |  |  import com.xunmei.system.api.domain.SysOrg;
 | 
											
												
													
														|  |  import com.xunmei.system.api.vo.SysOrgVO;
 |  |  import com.xunmei.system.api.vo.SysOrgVO;
 | 
											
												
													
														|  | 
 |  | +import org.springframework.beans.BeanUtils;
 | 
											
												
													
														|  |  import org.springframework.beans.factory.annotation.Autowired;
 |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
											
												
													
														|  |  import org.springframework.stereotype.Service;
 |  |  import org.springframework.stereotype.Service;
 | 
											
												
													
														|  |  import org.springframework.transaction.annotation.Transactional;
 |  |  import org.springframework.transaction.annotation.Transactional;
 | 
											
												
													
														|  | 
 |  | +import org.springframework.util.DigestUtils;
 | 
											
												
													
														|  |  import javax.annotation.Resource;
 |  |  import javax.annotation.Resource;
 | 
											
												
													
														|  |  import java.util.Arrays;
 |  |  import java.util.Arrays;
 | 
											
												
													
														|  |  import java.util.List;
 |  |  import java.util.List;
 | 
											
										
											
												
													
														|  | @@ -39,7 +45,7 @@ public class DiagnoseThresholdServiceImpl  implements DiagnoseThresholdService {
 | 
											
												
													
														|  |      private DiagnoseThresholdChMapper diagnoseThresholdChMapper;
 |  |      private DiagnoseThresholdChMapper diagnoseThresholdChMapper;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      @Override
 |  |      @Override
 | 
											
												
													
														|  | -    public TableDataInfo<DiagnoseThresholdPageVo> selectDiagnoseThresholdPage(DiagnoseThresholdPageDto request) {
 |  | 
 | 
											
												
													
														|  | 
 |  | +    public TableDataInfo<DiagnoseThresholdPageVo> selectCameraThresholdPage(DiagnoseThresholdPageDto request) {
 | 
											
												
													
														|  |          final SysOrg sysOrg = orgService.selectOrgById(request.getOrgId(), SecurityConstants.INNER);
 |  |          final SysOrg sysOrg = orgService.selectOrgById(request.getOrgId(), SecurityConstants.INNER);
 | 
											
												
													
														|  |          if (ObjectUtil.equal(Boolean.TRUE, request.getCheckSub())) {
 |  |          if (ObjectUtil.equal(Boolean.TRUE, request.getCheckSub())) {
 | 
											
												
													
														|  |              request.setOrgPath(sysOrg.getPath());
 |  |              request.setOrgPath(sysOrg.getPath());
 | 
											
										
											
												
													
														|  | @@ -69,7 +75,7 @@ public class DiagnoseThresholdServiceImpl  implements DiagnoseThresholdService {
 | 
											
												
													
														|  |                      for(IotDeviceDiagnoseThreshold threshold:thresholds){
 |  |                      for(IotDeviceDiagnoseThreshold threshold:thresholds){
 | 
											
												
													
														|  |                          if(threshold.getThresholdCode().equals(code)){
 |  |                          if(threshold.getThresholdCode().equals(code)){
 | 
											
												
													
														|  |                              buffer.append(threshold.getThresholdName()).append("【")
 |  |                              buffer.append(threshold.getThresholdName()).append("【")
 | 
											
												
													
														|  | -                                    .append(threshold.getValiditybegintime()).append("--").append(threshold.getValidityendtime())
 |  | 
 | 
											
												
													
														|  | 
 |  | +                                    .append(threshold.getBeginTime()).append("--").append(threshold.getEndTime())
 | 
											
												
													
														|  |                                      .append("】").append(",");
 |  |                                      .append("】").append(",");
 | 
											
												
													
														|  |                              isMatch = true;
 |  |                              isMatch = true;
 | 
											
												
													
														|  |                          }
 |  |                          }
 | 
											
										
											
												
													
														|  | @@ -133,7 +139,7 @@ public class DiagnoseThresholdServiceImpl  implements DiagnoseThresholdService {
 | 
											
												
													
														|  |              }
 |  |              }
 | 
											
												
													
														|  |              //获取涉及阈值配置,并修改设备数量
 |  |              //获取涉及阈值配置,并修改设备数量
 | 
											
												
													
														|  |              for (String bindThresholdCode:bindThresholdCodes) {
 |  |              for (String bindThresholdCode:bindThresholdCodes) {
 | 
											
												
													
														|  | -                diagnoseThresholdChMapper.updateDignoseNumber(bindThresholdCode);
 |  | 
 | 
											
												
													
														|  | 
 |  | +                diagnoseThresholdChMapper.updateDiagnoseNumber(bindThresholdCode);
 | 
											
												
													
														|  |              }
 |  |              }
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
										
											
												
													
														|  | @@ -182,11 +188,106 @@ public class DiagnoseThresholdServiceImpl  implements DiagnoseThresholdService {
 | 
											
												
													
														|  |              }
 |  |              }
 | 
											
												
													
														|  |              //获取涉及阈值配置,并修改设备数量
 |  |              //获取涉及阈值配置,并修改设备数量
 | 
											
												
													
														|  |              for (String bindThresholdCode:unbindThresholdCodes) {
 |  |              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(">",">").replace("<","<");
 | 
											
												
													
														|  | 
 |  | +        String covered=request.getCovered().replace(">",">").replace("<","<");
 | 
											
												
													
														|  | 
 |  | +        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(DateUtils.getTime());
 | 
											
												
													
														|  | 
 |  | +        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(DateUtils.getTime());
 | 
											
												
													
														|  | 
 |  | +        threshold.setType(0L);
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        diagnoseThresholdChMapper.updateById(threshold);
 | 
											
												
													
														|  | 
 |  | +    }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      @Override
 |  |      @Override
 | 
											
												
													
														|  |      public List<AlarmTypeSelectedVO> thresholdTypeList() {
 |  |      public List<AlarmTypeSelectedVO> thresholdTypeList() {
 | 
											
										
											
												
													
														|  | @@ -200,7 +301,7 @@ public class DiagnoseThresholdServiceImpl  implements DiagnoseThresholdService {
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |              buffer = new StringBuffer();
 |  |              buffer = new StringBuffer();
 | 
											
												
													
														|  |              buffer.append(threshold.getThresholdName()).append("【")
 |  |              buffer.append(threshold.getThresholdName()).append("【")
 | 
											
												
													
														|  | -                    .append(threshold.getValiditybegintime()).append("--").append(threshold.getValidityendtime())
 |  | 
 | 
											
												
													
														|  | 
 |  | +                    .append(threshold.getBeginTime()).append("--").append(threshold.getEndTime())
 | 
											
												
													
														|  |                      .append("】");
 |  |                      .append("】");
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |              bean.setValue(threshold.getThresholdCode());
 |  |              bean.setValue(threshold.getThresholdCode());
 | 
											
										
											
												
													
														|  | @@ -210,4 +311,43 @@ public class DiagnoseThresholdServiceImpl  implements DiagnoseThresholdService {
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |          return list;
 |  |          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();
 | 
											
												
													
														|  | 
 |  | +    }
 | 
											
												
													
														|  |  }
 |  |  }
 |