解决已完成的计划绑定新设备时,需要将计划重新改为检测中状态

This commit is contained in:
wr
2025-01-20 08:38:40 +08:00
parent 1d87a607df
commit c9aaf82f3f
6 changed files with 136 additions and 65 deletions

View File

@@ -678,7 +678,7 @@ public class DetectionServiceImpl {
NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(6);
nf.setGroupingUsed(false);
data.setRadius(nf.format(-errSys.getMaxErrorValue()) + "~" + nf.format(-errSys.getMaxErrorValue()));
data.setRadius(nf.format(-errSys.getMaxErrorValue()) + "~" + nf.format(errSys.getMaxErrorValue()));
setDetection(dataRule, harmDataList, errSys, data, v);
}
info.add(data);
@@ -817,7 +817,7 @@ public class DetectionServiceImpl {
nf.setMaximumFractionDigits(6);
nf.setGroupingUsed(false);
errSysDtl.setMaxErrorValue(maxErrorMultiply(errSysDtl.getMaxErrorValue(), data, channelData, errSysDtl.getErrorValueType()));
detectionData.setRadius(nf.format(-errSysDtl.getMaxErrorValue()) + "~" + nf.format(-errSysDtl.getMaxErrorValue()));
detectionData.setRadius(nf.format(-errSysDtl.getMaxErrorValue()) + "~" + nf.format(errSysDtl.getMaxErrorValue()));
setDetection(dataRule, list, errSysDtl, detectionData, channelData);
}
}

View File

@@ -121,7 +121,7 @@ public interface IPqDevService extends IService<PqDev> {
* @param devIds 设备id列表
* @return 绑定成功返回true否则返回false
*/
boolean bind(String planId, List<String> devIds);
Integer bind(String planId, List<String> devIds);
/**
* 获取饼图数据

View File

@@ -11,6 +11,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.njcn.common.pojo.enums.common.DataStateEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.pojo.poi.PullDown;
@@ -48,7 +49,6 @@ import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
@@ -150,7 +150,38 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
}
}
}
return this.lambdaUpdate().set(PqDev::getState, DataStateEnum.DELETED.getCode()).in(PqDev::getId, param.getIds()).update();
if (CollUtil.isNotEmpty(param.getIds())) {
MPJLambdaWrapper<PqDev> queryWrapper = new MPJLambdaWrapper<>();
queryWrapper.selectAll(PqDev.class)
.selectAs("t1.Name", PqDev::getPlanId)
.leftJoin("ad_plan t1 on t1.Id = t.Plan_Id")
.in(PqDev::getId, param.getIds())
.eq(PqDev::getState, DataStateEnum.ENABLE.getCode());
List<PqDev> devList = this.baseMapper.selectJoinList(PqDev.class, queryWrapper);
Map<String, List<PqDev>> collect = devList.stream().filter(x -> StrUtil.isNotBlank(x.getPlanId())).collect(Collectors.groupingBy(PqDev::getPlanId));
StringBuffer str;
if (CollUtil.isNotEmpty(collect)) {
str = new StringBuffer();
collect.forEach((k, v) -> {
str.append(k + ": ");
for (int i = 0; i < v.size(); i++) {
if ( i==v.size()-1) {
str.append(v.get(i).getName());
} else {
str.append(v.get(i).getName() + ",");
}
}
str.append(" &&");
});
} else {
str = null;
}
if (ObjectUtil.isNotNull(str)) {
throw new BusinessException(DevResponseEnum.DEVICE_DELETE, str.toString());
}
return this.lambdaUpdate().set(PqDev::getState, DataStateEnum.DELETED.getCode()).in(PqDev::getId, param.getIds()).update();
}
return true;
}
@Override
@@ -285,14 +316,34 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
@Override
@Transactional(rollbackFor = {Exception.class})
public boolean bind(String planId, List<String> devIds) {
public Integer bind(String planId, List<String> devIds) {
//先将这个绑定的计划全部剔除掉
this.lambdaUpdate().set(PqDev::getPlanId, null).eq(PqDev::getPlanId, planId).update();
//然后进行状态绑定
if (ObjectUtil.isNotEmpty(devIds)) {
this.lambdaUpdate().set(PqDev::getPlanId, planId).in(PqDev::getId, devIds).update();
}
List<PqDev> list = this.list(new LambdaQueryWrapper<PqDev>().in(PqDev::getId, devIds));
//判断是否有处了未检的其他设备
List<Integer> notUnchecked = list.stream().map(PqDev::getCheckState).filter(x -> !x.equals(CheckStateEnum.UNCHECKED.getValue())).distinct().collect(Collectors.toList());
if (CollUtil.isNotEmpty(notUnchecked)) {
List<Integer> unchecked = list.stream().map(PqDev::getCheckState).filter(x -> x.equals(CheckStateEnum.UNCHECKED.getValue())).distinct().collect(Collectors.toList());
if (CollUtil.isNotEmpty(unchecked)) {
return CheckStateEnum.CHECKING.getValue();
}
List<Integer> checking = list.stream().map(PqDev::getCheckState).filter(x -> x.equals(CheckStateEnum.CHECKING.getValue())).distinct().collect(Collectors.toList());
if (checking.size() == notUnchecked.size()) {
return CheckStateEnum.CHECKING.getValue();
}
List<Integer> checked = list.stream().map(PqDev::getCheckState).filter(x -> x.equals(CheckStateEnum.CHECKED.getValue()) ||
x.equals(CheckStateEnum.DOCUMENTED.getValue())
).distinct().collect(Collectors.toList());
if (checked.size() == notUnchecked.size()) {
return CheckStateEnum.CHECKED.getValue();
}
return true;
}
}
return CheckStateEnum.UNCHECKED.getValue();
}
// @Override
@@ -616,7 +667,7 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
long start = Long.parseLong(split[0]);
long end = Long.parseLong(split[1]);
// 避免起始大于结束
if(start > end){
if (start > end) {
long temp = start;
start = end;
end = temp;

View File

@@ -21,7 +21,10 @@ public enum DevResponseEnum {
IMPORT_DATASOURCE_ERROR("A001013","当前模式下一个检测计划只能有一个数据源" ),
DEV_UN_CHECKED("A001013","装置还未检测完成!" ),
DEV_UN_REPORT("A001013","装置报告未生成!" ),
DEVICE_DIS_ERROR("A001014","装置配置异常" );
DEVICE_DIS_ERROR("A001014","装置配置异常" ),
DEVICE_DELETE("A001015","设备无法删除,已绑定计划! " )
;
private final String message;
private final String code;

View File

@@ -75,51 +75,60 @@ public class AdHarmonicServiceImpl extends ServiceImpl<AdHarmonicMappper, AdHarm
.orderByAsc(AdHarmonicResult::getTimeId)
;
List<AdHarmonicResult> adHarmonicResults = this.getBaseMapper().selectJoinList(AdHarmonicResult.class, wrapper);
List<Double> harmNum = param.getHarmNum();
Map<String, List<RawDataVO>> info = new LinkedHashMap<>(3);
if(CollectionUtil.isNotEmpty(adHarmonicResults)){
List<Double> harmNum = param.getHarmNum();
RawDataVO dataVO;
List<RawDataVO> rawDataVOS;
DictTree dictData = dictTreeMapper.selectById(adHarmonicResults.get(0).getAdType());
String unit;
if (DictDataEnum.I2_50.getCode().equals(dictData.getCode()) || DictDataEnum.SI_1_49.getCode().equals(dictData.getCode())) {
unit = "A";
} else {
unit = "%";
}
for (AdHarmonicResult harmonicResult : adHarmonicResults) {
for (Double i : harmNum) {
dataVO = new RawDataVO();
dataVO.setHarmNum(i);
dataVO.setUnit(unit);
try {
Field timeId = harmonicResult.getClass().getDeclaredField("timeId");
timeId.setAccessible(true);
LocalDateTime localDateTime = (LocalDateTime) timeId.get(harmonicResult);
dataVO.setTime(localDateTime.format(DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN)));
Map<String, List<RawDataVO>> info=new LinkedHashMap<>(3);
RawDataVO dataVO;
List<RawDataVO> rawDataVOS;
for (AdHarmonicResult harmonicResult : adHarmonicResults) {
for (Double i : harmNum) {
dataVO = new RawDataVO();
dataVO.setHarmNum(i);
dataVO.setUnit("%");
try {
Field timeId = harmonicResult.getClass().getDeclaredField("timeId");
timeId.setAccessible(true);
LocalDateTime localDateTime = (LocalDateTime) timeId.get(harmonicResult);
dataVO.setTime(localDateTime.format(DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN)));
Field fieldA = harmonicResult.getClass().getDeclaredField("aValue" + isHarmOrInHarm(i).intValue());
fieldA.setAccessible(true);
BigDecimal decimalA = new BigDecimal(fieldA.get(harmonicResult) + "");
dataVO.setDataA(decimalA.toPlainString());
Field fieldA = harmonicResult.getClass().getDeclaredField("aValue" + isHarmOrInHarm(i).intValue());
fieldA.setAccessible(true);
BigDecimal decimalA = new BigDecimal(fieldA.get(harmonicResult)+"");
dataVO.setDataA(decimalA.toPlainString());
Field fieldB = harmonicResult.getClass().getDeclaredField("bValue" + isHarmOrInHarm(i).intValue());
fieldB.setAccessible(true);
BigDecimal decimalB = new BigDecimal(fieldB.get(harmonicResult) + "");
dataVO.setDataB(decimalB.toPlainString());
Field fieldB = harmonicResult.getClass().getDeclaredField("bValue" + isHarmOrInHarm(i).intValue());
fieldB.setAccessible(true);
BigDecimal decimalB = new BigDecimal(fieldB.get(harmonicResult)+"");
dataVO.setDataB(decimalB.toPlainString());
Field fieldC = harmonicResult.getClass().getDeclaredField("cValue" + isHarmOrInHarm(i).intValue());
fieldC.setAccessible(true);
BigDecimal decimalC = new BigDecimal(fieldC.get(harmonicResult) + "");
dataVO.setDataC(decimalC.toPlainString());
} catch (NoSuchFieldException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
if (info.containsKey(String.valueOf(i))) {
info.get(String.valueOf(i)).add(dataVO);
} else {
rawDataVOS = new ArrayList<>();
rawDataVOS.add(dataVO);
info.put(String.valueOf(i), rawDataVOS);
}
Field fieldC = harmonicResult.getClass().getDeclaredField("cValue" + isHarmOrInHarm(i).intValue());
fieldC.setAccessible(true);
BigDecimal decimalC = new BigDecimal(fieldC.get(harmonicResult)+"");
dataVO.setDataC(decimalC.toPlainString());
} catch (NoSuchFieldException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
if(info.containsKey(String.valueOf(i))){
info.get(String.valueOf(i)).add(dataVO);
}else{
rawDataVOS=new ArrayList<>();
rawDataVOS.add(dataVO);
info.put(String.valueOf(i),rawDataVOS) ;
}
}
}
DynamicTableNameHandler.remove();
return info;
}
@@ -135,16 +144,16 @@ public class AdHarmonicServiceImpl extends ServiceImpl<AdHarmonicMappper, AdHarm
.orderByAsc(AdHarmonicResult::getTimeId);
List<AdHarmonicResult> adHarmonicResults = this.getBaseMapper().selectJoinList(AdHarmonicResult.class, wrapper);
Map<String, RawResultDataVO> info=new LinkedHashMap<>(3);
if(CollUtil.isNotEmpty(adHarmonicResults)){
Map<String, RawResultDataVO> info = new LinkedHashMap<>(3);
if (CollUtil.isNotEmpty(adHarmonicResults)) {
List<Double> harmNum = param.getHarmNum();
RawResultDataVO dataVO;
DictTree dictData = dictTreeMapper.selectById(adHarmonicResults.get(0).getAdType());
String unit;
if(DictDataEnum.I2_50.getCode().equals(dictData.getCode())||DictDataEnum.SI_1_49.getCode().equals(dictData.getCode())){
unit="A";
}else{
unit="%";
if (DictDataEnum.I2_50.getCode().equals(dictData.getCode()) || DictDataEnum.SI_1_49.getCode().equals(dictData.getCode())) {
unit = "A";
} else {
unit = "%";
}
for (AdHarmonicResult harmonicResult : adHarmonicResults) {
for (Double i : harmNum) {
@@ -155,19 +164,19 @@ public class AdHarmonicServiceImpl extends ServiceImpl<AdHarmonicMappper, AdHarm
try {
Field fieldA = harmonicResult.getClass().getDeclaredField("aValue" + isHarmOrInHarm(i).intValue());
fieldA.setAccessible(true);
RawResultDataVO.DetectionData a = JSON.parseObject(fieldA.get(harmonicResult)+"", RawResultDataVO.DetectionData.class);
RawResultDataVO.DetectionData a = JSON.parseObject(fieldA.get(harmonicResult) + "", RawResultDataVO.DetectionData.class);
dataVO.setDataA(a);
Field fieldB = harmonicResult.getClass().getDeclaredField("bValue" + isHarmOrInHarm(i).intValue());
fieldB.setAccessible(true);
RawResultDataVO.DetectionData b = JSON.parseObject(fieldB.get(harmonicResult)+"", RawResultDataVO.DetectionData.class);
RawResultDataVO.DetectionData b = JSON.parseObject(fieldB.get(harmonicResult) + "", RawResultDataVO.DetectionData.class);
dataVO.setDataB(b);
Field fieldC = harmonicResult.getClass().getDeclaredField("cValue" + isHarmOrInHarm(i).intValue());
fieldC.setAccessible(true);
RawResultDataVO.DetectionData c = JSON.parseObject(fieldC.get(harmonicResult)+"", RawResultDataVO.DetectionData.class);
RawResultDataVO.DetectionData c = JSON.parseObject(fieldC.get(harmonicResult) + "", RawResultDataVO.DetectionData.class);
dataVO.setDataC(c);
if(ObjectUtil.isNotNull(a)){
if (ObjectUtil.isNotNull(a)) {
dataVO.setRadius(a.getRadius());
}
} catch (NoSuchFieldException e) {
@@ -175,7 +184,7 @@ public class AdHarmonicServiceImpl extends ServiceImpl<AdHarmonicMappper, AdHarm
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
info.put(String.valueOf(i),dataVO) ;
info.put(String.valueOf(i), dataVO);
}
}
}
@@ -192,15 +201,16 @@ public class AdHarmonicServiceImpl extends ServiceImpl<AdHarmonicMappper, AdHarm
LambdaQueryWrapper<AdHarmonicResult> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.select(AdHarmonicResult::getSort)
.eq(AdHarmonicResult::getResultFlag, 2)
.eq(AdHarmonicResult::getScriptId,param.getScriptId());
.eq(AdHarmonicResult::getScriptId, param.getScriptId());
List<AdHarmonicResult> adHarmonicResultList = this.list(lambdaQueryWrapper);
List<Integer> indexes = new ArrayList<>(adHarmonicResultList.stream().map(AdHarmonicResult::getSort).collect(Collectors.toList()));
DynamicTableNameHandler.setTableName(prefixNon + param.getCode());
LambdaQueryWrapper<AdNonHarmonicResult> resultLambdaQueryWrapper = new LambdaQueryWrapper<>();
resultLambdaQueryWrapper.select(AdNonHarmonicResult::getSort)
.eq(AdNonHarmonicResult::getResultFlag,2)
.eq(AdNonHarmonicResult::getScriptId,param.getScriptId());;
.eq(AdNonHarmonicResult::getResultFlag, 2)
.eq(AdNonHarmonicResult::getScriptId, param.getScriptId());
;
List<AdNonHarmonicResult> nonHarmonicResults = adNonHarmonicMapper.selectList(resultLambdaQueryWrapper);
indexes.addAll(nonHarmonicResults.stream().map(AdNonHarmonicResult::getSort).collect(Collectors.toList()));
@@ -210,7 +220,7 @@ public class AdHarmonicServiceImpl extends ServiceImpl<AdHarmonicMappper, AdHarm
@Override
public AdHarmonicResult getSingleResult(SingleNonHarmParam singleNonHarmParam) {
if(ObjectUtil.isNotNull(singleNonHarmParam)){
if (ObjectUtil.isNotNull(singleNonHarmParam)) {
String prefix = "ad_harmonic_result_";
DynamicTableNameHandler.setTableName(prefix + singleNonHarmParam.getPlanCode());
MPJLambdaWrapper<AdHarmonicResult> wrapper = new MPJLambdaWrapper<>();
@@ -218,7 +228,7 @@ public class AdHarmonicServiceImpl extends ServiceImpl<AdHarmonicMappper, AdHarm
.eq(AdHarmonicResult::getSort, singleNonHarmParam.getSort())
.eq(AdHarmonicResult::getAdType, singleNonHarmParam.getAdType());
List<AdHarmonicResult> adHarmonicResults = this.getBaseMapper().selectJoinList(AdHarmonicResult.class, wrapper);
if (CollectionUtil.isNotEmpty(adHarmonicResults)){
if (CollectionUtil.isNotEmpty(adHarmonicResults)) {
return adHarmonicResults.get(0);
}
}

View File

@@ -226,6 +226,13 @@ public class AdNonHarmonicServiceImpl extends ServiceImpl<AdNonHarmonicMapper, A
case "DUR":
unit="s";
break;
/**
* 暂态-持续时间
*/
case "VA":
case "IA":
unit="°";
break;
}
return unit;
}