|
@@ -3,27 +3,36 @@ package com.sckw.slope.detection.service;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.github.pagehelper.PageInfo;
|
|
|
|
|
+import com.sckw.core.exception.BusinessException;
|
|
|
import com.sckw.core.model.constant.NumberConstant;
|
|
import com.sckw.core.model.constant.NumberConstant;
|
|
|
import com.sckw.core.model.enums.DeviceEnum;
|
|
import com.sckw.core.model.enums.DeviceEnum;
|
|
|
import com.sckw.core.model.page.PageRes;
|
|
import com.sckw.core.model.page.PageRes;
|
|
|
|
|
+import com.sckw.core.utils.IdWorker;
|
|
|
|
|
+import com.sckw.core.utils.RegularUtils;
|
|
|
|
|
+import com.sckw.core.utils.StringUtils;
|
|
|
|
|
+import com.sckw.core.web.constant.HttpStatus;
|
|
|
import com.sckw.core.web.response.HttpResult;
|
|
import com.sckw.core.web.response.HttpResult;
|
|
|
import com.sckw.slope.detection.dao.mysql.*;
|
|
import com.sckw.slope.detection.dao.mysql.*;
|
|
|
import com.sckw.slope.detection.model.dos.mysql.KwsDeviceReference;
|
|
import com.sckw.slope.detection.model.dos.mysql.KwsDeviceReference;
|
|
|
import com.sckw.slope.detection.model.dos.mysql.KwsThreshold;
|
|
import com.sckw.slope.detection.model.dos.mysql.KwsThreshold;
|
|
|
-import com.sckw.slope.detection.model.dto.DeviceElementDTO;
|
|
|
|
|
-import com.sckw.slope.detection.model.dto.HeaderData;
|
|
|
|
|
-import com.sckw.slope.detection.model.dto.ThresholdSelectDTO;
|
|
|
|
|
|
|
+import com.sckw.slope.detection.model.dto.*;
|
|
|
import com.sckw.slope.detection.model.param.ThresholdDetailQuery;
|
|
import com.sckw.slope.detection.model.param.ThresholdDetailQuery;
|
|
|
import com.sckw.slope.detection.model.param.ThresholdQuery;
|
|
import com.sckw.slope.detection.model.param.ThresholdQuery;
|
|
|
import com.sckw.slope.detection.model.vo.ThresholdDetailVO;
|
|
import com.sckw.slope.detection.model.vo.ThresholdDetailVO;
|
|
|
|
|
+import com.sckw.slope.detection.service.repository.KwsThresholdRepository;
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
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.util.CollectionUtils;
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -50,6 +59,9 @@ public class ThresholdService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
KwsThresholdMapper thresholdMapper;
|
|
KwsThresholdMapper thresholdMapper;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ KwsThresholdRepository thresholdRepository;
|
|
|
|
|
+
|
|
|
@Autowired
|
|
@Autowired
|
|
|
KwsDeviceReferenceMapper deviceReferenceMapper;
|
|
KwsDeviceReferenceMapper deviceReferenceMapper;
|
|
|
|
|
|
|
@@ -75,7 +87,7 @@ public class ThresholdService {
|
|
|
.eq(KwsThreshold::getDeviceId, deviceId)
|
|
.eq(KwsThreshold::getDeviceId, deviceId)
|
|
|
.eq(KwsThreshold::getMountainId, headerData.getMountainId())
|
|
.eq(KwsThreshold::getMountainId, headerData.getMountainId())
|
|
|
.eq(KwsThreshold::getDelFlag, NumberConstant.ZERO)
|
|
.eq(KwsThreshold::getDelFlag, NumberConstant.ZERO)
|
|
|
- .orderByDesc(KwsThreshold::getUpdateTime)
|
|
|
|
|
|
|
+ .orderByDesc(KwsThreshold::getCreateTime)
|
|
|
);
|
|
);
|
|
|
String setting = "0";
|
|
String setting = "0";
|
|
|
String statusName = "未设置";
|
|
String statusName = "未设置";
|
|
@@ -113,8 +125,8 @@ public class ThresholdService {
|
|
|
dto.setStatus(setting);
|
|
dto.setStatus(setting);
|
|
|
dto.setStatusName(statusName);
|
|
dto.setStatusName(statusName);
|
|
|
dto.setPhones(phones.toString());
|
|
dto.setPhones(phones.toString());
|
|
|
- dto.setUpdateByName(CollectionUtils.isEmpty(kwsThresholds) ? null : kwsThresholds.get(0).getUpdateName());
|
|
|
|
|
- dto.setUpdateTime(CollectionUtils.isEmpty(kwsThresholds) ? null : kwsThresholds.get(0).getUpdateTime());
|
|
|
|
|
|
|
+ dto.setUpdateByName(CollectionUtils.isEmpty(kwsThresholds) ? null : kwsThresholds.get(0).getCreateName());
|
|
|
|
|
+ dto.setUpdateTime(CollectionUtils.isEmpty(kwsThresholds) ? null : kwsThresholds.get(0).getCreateTime());
|
|
|
}
|
|
}
|
|
|
return PageRes.build(info, dtoList);
|
|
return PageRes.build(info, dtoList);
|
|
|
}
|
|
}
|
|
@@ -143,10 +155,10 @@ public class ThresholdService {
|
|
|
vo.setItemValue(deviceReference == null ? null : deviceReference.getValue());
|
|
vo.setItemValue(deviceReference == null ? null : deviceReference.getValue());
|
|
|
//查询td获取数据
|
|
//查询td获取数据
|
|
|
// vo.setVariation();
|
|
// vo.setVariation();
|
|
|
- List<ThresholdDetailVO.ThresholdBean> beanList = new ArrayList<>();
|
|
|
|
|
|
|
+ List<ThresholdBean> beanList = new ArrayList<>();
|
|
|
for (KwsThreshold threshold : kwsThreshold) {
|
|
for (KwsThreshold threshold : kwsThreshold) {
|
|
|
- ThresholdDetailVO.ThresholdBean bean = new ThresholdDetailVO.ThresholdBean();
|
|
|
|
|
- bean.setLevel(threshold.getLevel().toString());
|
|
|
|
|
|
|
+ ThresholdBean bean = new ThresholdBean();
|
|
|
|
|
+ bean.setLevel(threshold.getLevel());
|
|
|
bean.setMax(threshold.getMax());
|
|
bean.setMax(threshold.getMax());
|
|
|
bean.setMin(threshold.getMin());
|
|
bean.setMin(threshold.getMin());
|
|
|
beanList.add(bean);
|
|
beanList.add(bean);
|
|
@@ -155,4 +167,361 @@ public class ThresholdService {
|
|
|
}
|
|
}
|
|
|
return HttpResult.ok(vo);
|
|
return HttpResult.ok(vo);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Transactional
|
|
|
|
|
+ public HttpResult configuration(ThresholdConfigurationDTO configurationDTO, HttpServletRequest request) {
|
|
|
|
|
+ HeaderData headerData = commonService.getHeaderData(request);
|
|
|
|
|
+ List<ThresholdBean> threshold = configurationDTO.getThreshold();
|
|
|
|
|
+ String itemName = configurationDTO.getItemName();
|
|
|
|
|
+ String phones = configurationDTO.getPhones();
|
|
|
|
|
+ String deviceId = configurationDTO.getDeviceId();
|
|
|
|
|
+ if (CollectionUtils.isEmpty(threshold)) {
|
|
|
|
|
+ return HttpResult.error(HttpStatus.GLOBAL_EXCEPTION_CODE, "设置阈值不能全部为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ List<String> phonesStr = StringUtils.splitStrToList(phones, String.class);
|
|
|
|
|
+ for (String phone : phonesStr) {
|
|
|
|
|
+ if (!RegularUtils.matchs(RegularUtils.PHONE_REG, phone)) {
|
|
|
|
|
+ return HttpResult.error(HttpStatus.GLOBAL_EXCEPTION_CODE, "联系电话格式不正确,请检查并重新输入!");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ //页面阈值等级校验
|
|
|
|
|
+ //当前使用阈值123级硬编码校验
|
|
|
|
|
+ checkThresholdLevel(configurationDTO, headerData);
|
|
|
|
|
+ //后期阈值等级扩容可调用此方法
|
|
|
|
|
+ //checkLevelMax(threshold, configurationDTO, headerData);
|
|
|
|
|
+ for (ThresholdBean thresholdBean : threshold) {
|
|
|
|
|
+ //验证数据库层面阈值数据存储值
|
|
|
|
|
+ int level = thresholdBean.getLevel();
|
|
|
|
|
+ checkDatabaseThresholdLevel(level, thresholdBean, headerData, deviceId, itemName);
|
|
|
|
|
+ KwsThreshold selected = thresholdMapper.selectOne(new LambdaQueryWrapper<KwsThreshold>()
|
|
|
|
|
+ .eq(KwsThreshold::getMountainId, headerData.getMountainId())
|
|
|
|
|
+ .eq(KwsThreshold::getDeviceId, deviceId)
|
|
|
|
|
+ .eq(KwsThreshold::getItemName, itemName)
|
|
|
|
|
+ .eq(KwsThreshold::getCompanyId, headerData.getMountainId())
|
|
|
|
|
+ .eq(KwsThreshold::getLevel, level)
|
|
|
|
|
+ .eq(KwsThreshold::getDelFlag, NumberConstant.ZERO)
|
|
|
|
|
+ );
|
|
|
|
|
+ if (selected == null) {
|
|
|
|
|
+ KwsThreshold kwsThreshold = new KwsThreshold();
|
|
|
|
|
+ kwsThreshold.setId(new IdWorker(NumberConstant.ONE).nextId());
|
|
|
|
|
+ kwsThreshold.setDeviceId(Long.parseLong(deviceId));
|
|
|
|
|
+ kwsThreshold.setItemName(itemName);
|
|
|
|
|
+ kwsThreshold.setCompanyId(headerData.getCompanyId());
|
|
|
|
|
+ kwsThreshold.setMountainId(headerData.getMountainId());
|
|
|
|
|
+ //计算设置状态 便于select
|
|
|
|
|
+ String setting = checkAndSettings(configurationDTO, headerData);
|
|
|
|
|
+ kwsThreshold.setSetting(setting);
|
|
|
|
|
+ kwsThreshold.setLevel(Integer.valueOf(thresholdBean.getLevel()));
|
|
|
|
|
+ kwsThreshold.setMax(thresholdBean.getMax());
|
|
|
|
|
+ kwsThreshold.setMin(thresholdBean.getMin());
|
|
|
|
|
+ kwsThreshold.setPhones(phones);
|
|
|
|
|
+ kwsThreshold.setStatus(0);
|
|
|
|
|
+ kwsThreshold.setCreateBy(headerData.getCreateBy() == null ? null : Long.parseLong(headerData.getCreateBy()));
|
|
|
|
|
+ kwsThreshold.setCreateName(headerData.getCreateName());
|
|
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
|
|
+ kwsThreshold.setCreateTime(now);
|
|
|
|
|
+ thresholdMapper.insert(kwsThreshold);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ selected.setLevel(Integer.valueOf(thresholdBean.getLevel()));
|
|
|
|
|
+ //计算设置状态 便于select
|
|
|
|
|
+ String setting = checkAndSettings(configurationDTO, headerData);
|
|
|
|
|
+ selected.setSetting(setting);
|
|
|
|
|
+ selected.setMax(thresholdBean.getMax());
|
|
|
|
|
+ selected.setMin(thresholdBean.getMin());
|
|
|
|
|
+ selected.setPhones(phones);
|
|
|
|
|
+ selected.setStatus(0);
|
|
|
|
|
+ selected.setUpdateBy(headerData.getUpdateBy() == null ? null : Long.parseLong(headerData.getUpdateBy()));
|
|
|
|
|
+ selected.setUpdateName(headerData.getUpdateName());
|
|
|
|
|
+ selected.setUpdateTime(LocalDateTime.now());
|
|
|
|
|
+ thresholdRepository.saveOrUpdate(selected);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return HttpResult.ok();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 比较数据库中存在的阈值与页面填写的阈值范围
|
|
|
|
|
+ * @param level 阈值等级
|
|
|
|
|
+ * @param thresholdBean 页面填写数据
|
|
|
|
|
+ * @param headerData 请求头信息
|
|
|
|
|
+ * @param deviceId 设备id
|
|
|
|
|
+ * @param itemName 要素项
|
|
|
|
|
+ */
|
|
|
|
|
+ private void checkDatabaseThresholdLevel(int level, ThresholdBean thresholdBean, HeaderData headerData, String deviceId, String itemName) {
|
|
|
|
|
+ if (1 == level) {
|
|
|
|
|
+ KwsThreshold twoKwsThreshold = thresholdSelect(2, headerData, deviceId, itemName);
|
|
|
|
|
+ KwsThreshold threeKwsThreshold = thresholdSelect(3, headerData, deviceId, itemName);
|
|
|
|
|
+ if (twoKwsThreshold != null) {
|
|
|
|
|
+ String min = twoKwsThreshold.getMin();
|
|
|
|
|
+ if (min.contains("-")) {
|
|
|
|
|
+ min = StringUtils.deleteCharString(min, "-");
|
|
|
|
|
+ }
|
|
|
|
|
+ String max = twoKwsThreshold.getMax();
|
|
|
|
|
+ if (Long.parseLong(thresholdBean.getMax()) > Long.parseLong(max)) {
|
|
|
|
|
+ throw new BusinessException("阈值设置数据填写错误");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (Long.parseLong(thresholdBean.getMin()) > Long.parseLong(min)) {
|
|
|
|
|
+ throw new BusinessException("阈值设置数据填写错误");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (threeKwsThreshold != null) {
|
|
|
|
|
+ String min = threeKwsThreshold.getMin();
|
|
|
|
|
+ if (min.contains("-")) {
|
|
|
|
|
+ min = StringUtils.deleteCharString(min, "-");
|
|
|
|
|
+ }
|
|
|
|
|
+ String max = threeKwsThreshold.getMax();
|
|
|
|
|
+ if (Long.parseLong(thresholdBean.getMax()) > Long.parseLong(max)) {
|
|
|
|
|
+ throw new BusinessException("阈值设置数据填写错误");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (Long.parseLong(thresholdBean.getMin()) > Long.parseLong(min)) {
|
|
|
|
|
+ throw new BusinessException("阈值设置数据填写错误");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (2 == level) {
|
|
|
|
|
+ KwsThreshold oneKwsThreshold = thresholdSelect(1, headerData, deviceId, itemName);
|
|
|
|
|
+ KwsThreshold threeKwsThreshold = thresholdSelect(3, headerData, deviceId, itemName);
|
|
|
|
|
+ if (oneKwsThreshold != null) {
|
|
|
|
|
+ String max = oneKwsThreshold.getMax();
|
|
|
|
|
+ String min = oneKwsThreshold.getMin();
|
|
|
|
|
+ if (min.contains("-")) {
|
|
|
|
|
+ min = StringUtils.deleteCharString(min, "-");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (Long.parseLong(thresholdBean.getMax()) < Long.parseLong(max)) {
|
|
|
|
|
+ throw new BusinessException("阈值设置数据填写错误");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (Long.parseLong(thresholdBean.getMin()) < Long.parseLong(min)) {
|
|
|
|
|
+ throw new BusinessException("阈值设置数据填写错误");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (threeKwsThreshold != null) {
|
|
|
|
|
+ String max = threeKwsThreshold.getMax();
|
|
|
|
|
+ String min = threeKwsThreshold.getMin();
|
|
|
|
|
+ if (min.contains("-")) {
|
|
|
|
|
+ min = StringUtils.deleteCharString(min, "-");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (Long.parseLong(thresholdBean.getMax()) > Long.parseLong(max)) {
|
|
|
|
|
+ throw new BusinessException("阈值设置数据填写错误");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (Long.parseLong(thresholdBean.getMin()) > Long.parseLong(min)) {
|
|
|
|
|
+ throw new BusinessException("阈值设置数据填写错误");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (3 == level) {
|
|
|
|
|
+ KwsThreshold oneKwsThreshold = thresholdSelect(1, headerData, deviceId, itemName);
|
|
|
|
|
+ KwsThreshold twoKwsThreshold = thresholdSelect(2, headerData, deviceId, itemName);
|
|
|
|
|
+ if (oneKwsThreshold != null) {
|
|
|
|
|
+ String max = oneKwsThreshold.getMax();
|
|
|
|
|
+ String min = oneKwsThreshold.getMin();
|
|
|
|
|
+ if (min.contains("-")) {
|
|
|
|
|
+ min = StringUtils.deleteCharString(min, "-");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (Long.parseLong(thresholdBean.getMax()) < Long.parseLong(max)) {
|
|
|
|
|
+ throw new BusinessException("阈值设置数据填写错误");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (Long.parseLong(thresholdBean.getMin()) < Long.parseLong(min)) {
|
|
|
|
|
+ throw new BusinessException("阈值设置数据填写错误");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (twoKwsThreshold != null) {
|
|
|
|
|
+ String max = twoKwsThreshold.getMax();
|
|
|
|
|
+ String min = twoKwsThreshold.getMin();
|
|
|
|
|
+ if (min.contains("-")) {
|
|
|
|
|
+ min = StringUtils.deleteCharString(min, "-");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (Long.parseLong(thresholdBean.getMax()) < Long.parseLong(max)) {
|
|
|
|
|
+ throw new BusinessException("阈值设置数据填写错误");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (Long.parseLong(thresholdBean.getMin()) < Long.parseLong(min)) {
|
|
|
|
|
+ throw new BusinessException("阈值设置数据填写错误");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private KwsThreshold thresholdSelect(int level, HeaderData headerData, String deviceId, String itemName) {
|
|
|
|
|
+ KwsThreshold threshold = thresholdMapper.selectOne(new LambdaQueryWrapper<KwsThreshold>()
|
|
|
|
|
+ .eq(KwsThreshold::getMountainId, headerData.getMountainId())
|
|
|
|
|
+ .eq(KwsThreshold::getDeviceId, deviceId)
|
|
|
|
|
+ .eq(KwsThreshold::getItemName, itemName)
|
|
|
|
|
+ .eq(KwsThreshold::getCompanyId, headerData.getMountainId())
|
|
|
|
|
+ .eq(KwsThreshold::getLevel, 2)
|
|
|
|
|
+ .eq(KwsThreshold::getDelFlag, NumberConstant.ZERO)
|
|
|
|
|
+ );
|
|
|
|
|
+ return threshold;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void checkThresholdLevel(ThresholdConfigurationDTO configurationDTO, HeaderData headerData) {
|
|
|
|
|
+ List<ThresholdBean> threshold = configurationDTO.getThreshold();
|
|
|
|
|
+ Map<Integer, ThresholdBean> maps = threshold.stream().collect(Collectors.toMap(ThresholdBean::getLevel, Function.identity(), (key1, key2) -> key2));
|
|
|
|
|
+ ThresholdBean thresholdBeanOne = maps.get(1);
|
|
|
|
|
+ ThresholdBean thresholdBeanTwo = maps.get(2);
|
|
|
|
|
+ ThresholdBean thresholdBeanThree = maps.get(3);
|
|
|
|
|
+ if (thresholdBeanTwo != null) {
|
|
|
|
|
+ String min = thresholdBeanTwo.getMin();
|
|
|
|
|
+ if (min.contains("-")) {
|
|
|
|
|
+ min = com.sckw.core.utils.StringUtils.deleteCharString(min, "-");
|
|
|
|
|
+ }
|
|
|
|
|
+ String max = thresholdBeanTwo.getMax();
|
|
|
|
|
+ if (thresholdBeanThree != null) {
|
|
|
|
|
+ String minThree = thresholdBeanThree.getMin();
|
|
|
|
|
+ if (minThree.contains("-")) {
|
|
|
|
|
+ minThree = com.sckw.core.utils.StringUtils.deleteCharString(minThree, "-");
|
|
|
|
|
+ }
|
|
|
|
|
+ String maxThree = thresholdBeanThree.getMax();
|
|
|
|
|
+ if (BigDecimal.valueOf(Long.parseLong(max)).compareTo(BigDecimal.valueOf(Long.parseLong(maxThree))) > 0) {
|
|
|
|
|
+ throw new BusinessException("阈值填写错误");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (BigDecimal.valueOf(Long.parseLong(min)).compareTo(BigDecimal.valueOf(Long.parseLong(minThree))) < 0) {
|
|
|
|
|
+ throw new BusinessException("阈值填写错误");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (thresholdBeanOne != null) {
|
|
|
|
|
+ String minOne = thresholdBeanOne.getMin();
|
|
|
|
|
+ if (minOne.contains("-")) {
|
|
|
|
|
+ minOne = com.sckw.core.utils.StringUtils.deleteCharString(minOne, "-");
|
|
|
|
|
+ }
|
|
|
|
|
+ String maxThree = thresholdBeanOne.getMax();
|
|
|
|
|
+ if (BigDecimal.valueOf(Long.parseLong(max)).compareTo(BigDecimal.valueOf(Long.parseLong(maxThree))) < 0) {
|
|
|
|
|
+ throw new BusinessException("阈值填写错误");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (BigDecimal.valueOf(Long.parseLong(min)).compareTo(BigDecimal.valueOf(Long.parseLong(minOne))) > 0) {
|
|
|
|
|
+ throw new BusinessException("阈值填写错误");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (thresholdBeanThree != null) {
|
|
|
|
|
+ String minThree = thresholdBeanThree.getMin();
|
|
|
|
|
+ if (minThree.contains("-")) {
|
|
|
|
|
+ minThree = com.sckw.core.utils.StringUtils.deleteCharString(minThree, "-");
|
|
|
|
|
+ }
|
|
|
|
|
+ String maxThree = thresholdBeanThree.getMax();
|
|
|
|
|
+ if (thresholdBeanTwo != null) {
|
|
|
|
|
+ String twoMax = thresholdBeanTwo.getMax();
|
|
|
|
|
+ String twoMin = thresholdBeanTwo.getMin();
|
|
|
|
|
+ if (BigDecimal.valueOf(Long.parseLong(twoMax)).compareTo(BigDecimal.valueOf(Long.parseLong(maxThree))) > 0) {
|
|
|
|
|
+ throw new BusinessException("阈值填写错误");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (BigDecimal.valueOf(Long.parseLong(twoMin)).compareTo(BigDecimal.valueOf(Long.parseLong(minThree))) > 0) {
|
|
|
|
|
+ throw new BusinessException("阈值填写错误");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void checkLevelMax(List<ThresholdBean> threshold, ThresholdConfigurationDTO configurationDTO, HeaderData headerData) {
|
|
|
|
|
+ Integer maxLevel = threshold.stream().map(ThresholdBean::getLevel).max((x, y) -> x - y).get();
|
|
|
|
|
+ if (threshold.size() > 1) {
|
|
|
|
|
+ Map<Integer, ThresholdBean> maps = threshold.stream().collect(Collectors.toMap(ThresholdBean::getLevel, Function.identity(), (key1, key2) -> key2));
|
|
|
|
|
+ int count = 0;
|
|
|
|
|
+ for (int i = maxLevel; i > 0; i--) {
|
|
|
|
|
+ ThresholdBean thresholdBean = maps.get(maxLevel);
|
|
|
|
|
+ if (thresholdBean != null) {
|
|
|
|
|
+ String thresholdBeanMin = thresholdBean.getMin();
|
|
|
|
|
+ if (thresholdBeanMin.contains("-")) {
|
|
|
|
|
+ thresholdBeanMin = com.sckw.core.utils.StringUtils.deleteCharString(thresholdBeanMin, "-");
|
|
|
|
|
+ }
|
|
|
|
|
+ ThresholdBean thresholdBean1 = maps.get(i);
|
|
|
|
|
+ if (thresholdBean1 != null) {
|
|
|
|
|
+ String max = thresholdBean1.getMax();
|
|
|
|
|
+ String min = thresholdBean1.getMin();
|
|
|
|
|
+ if (min.contains("-")) {
|
|
|
|
|
+ min = com.sckw.core.utils.StringUtils.deleteCharString(min, "-");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (BigDecimal.valueOf(Long.parseLong(max)).compareTo(BigDecimal.valueOf(Long.parseLong(thresholdBean.getMax()))) > 0) {
|
|
|
|
|
+ throw new BusinessException("阈值填写错误");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (BigDecimal.valueOf(Long.parseLong(min)).compareTo(BigDecimal.valueOf(Long.parseLong(thresholdBeanMin))) < 0) {
|
|
|
|
|
+ throw new BusinessException("阈值填写错误");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ for (ThresholdBean value : maps.values()) {
|
|
|
|
|
+ int level = value.getLevel();
|
|
|
|
|
+ if (level == count) {
|
|
|
|
|
+ int levelMax = level + 1;
|
|
|
|
|
+ int levelMin = level - 1;
|
|
|
|
|
+ if (maps.get(levelMax) != null) {
|
|
|
|
|
+ String min = value.getMin();
|
|
|
|
|
+ String max = value.getMax();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (maps.get(levelMin) != null) {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ ThresholdBean thresholdBean2 = maps.get(2);
|
|
|
|
|
+ ThresholdBean thresholdBean1 = maps.get(1);
|
|
|
|
|
+ ThresholdBean thresholdBean3 = maps.get(3);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (1 != maxLevel) {
|
|
|
|
|
+ //上限界定
|
|
|
|
|
+ KwsThreshold maxThreshold = thresholdMapper.selectOne(new LambdaQueryWrapper<KwsThreshold>()
|
|
|
|
|
+ .eq(KwsThreshold::getMountainId, headerData.getMountainId())
|
|
|
|
|
+ .eq(KwsThreshold::getDeviceId, Long.parseLong(configurationDTO.getDeviceId()))
|
|
|
|
|
+ .eq(KwsThreshold::getItemName, configurationDTO.getItemName())
|
|
|
|
|
+ .eq(KwsThreshold::getCompanyId, headerData.getMountainId())
|
|
|
|
|
+ .eq(KwsThreshold::getLevel, (maxLevel + 1))
|
|
|
|
|
+ .eq(KwsThreshold::getDelFlag, NumberConstant.ZERO)
|
|
|
|
|
+ );
|
|
|
|
|
+ if (maxThreshold != null) {
|
|
|
|
|
+ String max = maxThreshold.getMax();
|
|
|
|
|
+ String min = maxThreshold.getMin();
|
|
|
|
|
+ }
|
|
|
|
|
+ //下限界定
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String checkAndSettings(ThresholdConfigurationDTO configurationDTO, HeaderData headerData) {
|
|
|
|
|
+ String deviceId = configurationDTO.getDeviceId();
|
|
|
|
|
+ List<Integer> status = new ArrayList<>();
|
|
|
|
|
+ status.add(DeviceEnum.ALREADY_REFERRED_TO.getCode());
|
|
|
|
|
+ //基本要素
|
|
|
|
|
+ List<DeviceElementDTO> basiclElementList = deviceModelPartMapper.selectElementList(configurationDTO.getProjectId(),
|
|
|
|
|
+ headerData.getMountainId(), status, Long.parseLong(deviceId));
|
|
|
|
|
+ //集成要素
|
|
|
|
|
+ List<DeviceElementDTO> integratedElementList = deviceIntegrationMapper.selectIntegratedElement(configurationDTO.getProjectId(),
|
|
|
|
|
+ headerData.getMountainId(), status, Long.parseLong(deviceId));
|
|
|
|
|
+ int count = 0;
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(basiclElementList)) {
|
|
|
|
|
+ List<String> collect = basiclElementList.stream().map(DeviceElementDTO::getElement).collect(Collectors.toList());
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(collect)) {
|
|
|
|
|
+ for (String s : collect) {
|
|
|
|
|
+ List<String> stringList = StringUtils.splitStrToList(s, String.class);
|
|
|
|
|
+ count = count + stringList.size();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(integratedElementList)) {
|
|
|
|
|
+ List<String> collect = basiclElementList.stream().map(DeviceElementDTO::getIntegrationElement).collect(Collectors.toList());
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(collect)) {
|
|
|
|
|
+ for (String s : collect) {
|
|
|
|
|
+ List<String> stringList = StringUtils.splitStrToList(s, String.class);
|
|
|
|
|
+ count = count + stringList.size();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ List<KwsThreshold> kwsThresholds = thresholdMapper.selectList(new LambdaQueryWrapper<KwsThreshold>()
|
|
|
|
|
+ .eq(KwsThreshold::getDeviceId, configurationDTO.getDeviceId())
|
|
|
|
|
+ .eq(KwsThreshold::getMountainId, headerData.getMountainId())
|
|
|
|
|
+ .eq(KwsThreshold::getDelFlag, NumberConstant.ZERO)
|
|
|
|
|
+ );
|
|
|
|
|
+ int number = 0;
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(kwsThresholds)) {
|
|
|
|
|
+ List<String> collect = kwsThresholds.stream().map(KwsThreshold::getItemName).distinct().collect(Collectors.toList());
|
|
|
|
|
+ number = collect.size();
|
|
|
|
|
+ }
|
|
|
|
|
+ // 0未设置 1 部分设置 2 已设置
|
|
|
|
|
+ String setting = "0";
|
|
|
|
|
+ if (number != 0) {
|
|
|
|
|
+ if (count == number) {
|
|
|
|
|
+ setting = "2";
|
|
|
|
|
+ } else if (count > number) {
|
|
|
|
|
+ setting = "1";
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return setting;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|