1.正式检测-检测树

This commit is contained in:
wr
2025-01-02 13:48:42 +08:00
parent 14f3ab52bb
commit f45a344db8
15 changed files with 364 additions and 40 deletions

View File

@@ -5,8 +5,8 @@ import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.LogUtil;
import com.njcn.gather.result.pojo.param.ResultParam;
import com.njcn.gather.result.pojo.vo.DetectionInfoVO;
import com.njcn.gather.result.pojo.vo.FormContentVO;
import com.njcn.gather.result.pojo.vo.TreeDataVO;
import com.njcn.gather.result.service.IResultService;
import com.njcn.web.controller.BaseController;
import com.njcn.web.utils.HttpResultUtil;
@@ -50,12 +50,9 @@ public class ResultController extends BaseController {
@PostMapping("/treeData")
@ApiOperation("查询检测结果-树形结构的具体检测项")
@ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
public HttpResult<List<TreeDataVO>> treeData(@RequestBody @Validated ResultParam.QueryParam queryParam) {
public HttpResult<List<DetectionInfoVO>> treeData(@RequestBody @Validated ResultParam queryParam) {
String methodDescribe = getMethodDescribe("treeData");
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
List<DetectionInfoVO> infoVOS = resultService.treeData(queryParam);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, infoVOS, methodDescribe);
}
}

View File

@@ -0,0 +1,36 @@
package com.njcn.gather.result.pojo.enums;
import lombok.Getter;
/**
* @author caozehui
* @data 2024/11/9
*/
@Getter
public enum ResultUnitEnum {
FREQ_UNIT("Hz", "频率"),
V_RELATIVE_UNIT("%Un", "电压"),
V_ABSOLUTELY_UNIT("V", "电压"),
I_RELATIVE_UNIT("%In", "电流"),
I_ABSOLUTELY_UNIT("A", "电流"),
HV_UNIT("%", "谐波电压"),
HI_UNIT("%", "谐波电流"),
HP_UNIT("W", "谐波有功功率"),
HSV_UNIT("%", "间谐波电压"),
HSI_UNIT("%", "间谐波电流"),
VOLTAGE_MAG_UNIT("周波", "暂态持续时间"),
VOLTAGE_DUR_UNIT("%", "暂态深度"),
IMBV_UNIT("%", "电压不平衡度"),
IMBA_UNIT("%", "电流不平衡度"),
;
private String unit;
private String name;
ResultUnitEnum(String unit, String name) {
this.unit = unit;
this.name = name;
}
}

View File

@@ -15,6 +15,31 @@ import javax.validation.constraints.Pattern;
@Data
public class ResultParam {
/**
* 检测大相信息
*/
private String scriptType;
/**
* 检测脚本id
*/
private String scriptId;
/**
* 装置id
*/
private String devId="5eaba83670ff4d9daf892a62a5e13ea3";
/**
* 装置通道
*/
private String devNum="1";
/**
* 自动生成,用于生成数据表后缀
*/
private Integer code=1;
@Data
public static class QueryParam {

View File

@@ -0,0 +1,35 @@
package com.njcn.gather.result.pojo.vo;
import lombok.Data;
import java.util.List;
import java.util.Map;
/**
* @author wr
* @description
* @date 2024/12/31 15:00
*/
@Data
public class DetectionInfoVO {
/**
* 检测项目名称
*/
private String scriptTypeName;
/**
* 测试相
*/
private Integer index;
/**
* 是否检测合格
*/
private Integer fly;
/**
* 检测信息集合
*/
private List<DetectionInfoVO> children;
}

View File

@@ -1,12 +1,30 @@
package com.njcn.gather.result.service;
import com.njcn.gather.result.pojo.param.ResultParam;
import com.njcn.gather.result.pojo.vo.DetectionInfoVO;
import com.njcn.gather.result.pojo.vo.FormContentVO;
import java.util.List;
/**
* @author caozehui
* @data 2024-12-30
*/
public interface IResultService {
/**
* 检测详情表单头
* @param queryParam
* @return
*/
FormContentVO getFormContent(ResultParam.QueryParam queryParam);
/**
* 获取检测详情信息
* @param param
* @return: java.util.List<com.njcn.gather.result.pojo.vo.DetectionInfoVO>
* @Author: wr
* @Date: 2024/12/31 15:14
*/
List<DetectionInfoVO> treeData(ResultParam param);
}

View File

@@ -1,12 +1,19 @@
package com.njcn.gather.result.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.njcn.db.mybatisplus.handler.DynamicTableNameHandler;
import cn.hutool.core.util.StrUtil;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.njcn.common.pojo.enums.common.DataStateEnum;
import com.njcn.gather.device.device.service.IPqDevService;
import com.njcn.gather.device.script.mapper.PqScriptMapper;
import com.njcn.gather.device.script.pojo.po.PqScriptDtls;
import com.njcn.gather.device.script.service.IPqScriptDtlsService;
import com.njcn.gather.plan.pojo.po.AdPlan;
import com.njcn.gather.plan.service.IAdPlanService;
import com.njcn.gather.result.pojo.enums.ResultUnitEnum;
import com.njcn.gather.result.pojo.param.ResultParam;
import com.njcn.gather.result.pojo.vo.DetectionInfoVO;
import com.njcn.gather.result.pojo.vo.FormContentVO;
import com.njcn.gather.result.service.IResultService;
import com.njcn.gather.storage.pojo.po.AdBaseResult;
@@ -20,6 +27,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
@@ -37,9 +45,12 @@ public class ResultServiceImpl implements IResultService {
private final AdNonHarmonicService adNonHarmonicService;
private final AdHarmonicService adHarmonicService;
private final IPqScriptDtlsService pqScriptDtlsService;
private final PqScriptMapper scriptMapper;
private final IDictTreeService dictTreeService;
// 谐波类code取树形字典表中的code
/**
* 谐波类code取树形字典表中的code
*/
private final List<String> HARMONIC_TYPE_CODE = Arrays.asList("HV", "HI", "HP", "HSV", "HSI");
@@ -60,35 +71,22 @@ public class ResultServiceImpl implements IResultService {
List<Map<String, String>> chnList = new ArrayList<>();
List<AdBaseResult> allResultList = new ArrayList<>();
if (ObjectUtil.isNotNull(queryParam.getScriptType())) { //只查询指定的脚本类型
//只查询指定的脚本类型
if (ObjectUtil.isNotNull(queryParam.getScriptType())) {
List<Integer> indexList = pqScriptDtlsService.getIndexList(queryParam.getScriptType(), scriptId);
DictTree dictTree = dictTreeService.getById(queryParam.getScriptType());
if (HARMONIC_TYPE_CODE.contains(dictTree.getCode())) {
String prefix = "ad_harmonic_result_";
DynamicTableNameHandler.setTableName(prefix + plan.getCode());
allResultList.addAll(adHarmonicService.get(scriptId, indexList, queryParam.getDeviceId(), queryParam.getChnNum()));
DynamicTableNameHandler.remove();
allResultList.addAll(adHarmonicService.get(scriptId, indexList, queryParam.getDeviceId(), queryParam.getChnNum(), plan.getCode()));
} else {
String prefix = "ad_non_harmonic_result_";
DynamicTableNameHandler.setTableName(prefix + plan.getCode());
allResultList.addAll(adNonHarmonicService.get(scriptId, indexList, queryParam.getDeviceId(), queryParam.getChnNum()));
DynamicTableNameHandler.remove();
allResultList.addAll(adNonHarmonicService.get(scriptId, indexList, queryParam.getDeviceId(), queryParam.getChnNum(), plan.getCode()));
}
} else { //查询所有的脚本类型
String prefix = "ad_harmonic_result_";
DynamicTableNameHandler.setTableName(prefix + plan.getCode());
allResultList.addAll(adHarmonicService.get(scriptId, null, queryParam.getDeviceId(), queryParam.getChnNum()));
DynamicTableNameHandler.remove();
prefix = "ad_non_harmonic_result_";
DynamicTableNameHandler.setTableName(prefix + plan.getCode());
allResultList.addAll(adNonHarmonicService.get(scriptId, null, queryParam.getDeviceId(), queryParam.getChnNum()));
DynamicTableNameHandler.remove();
allResultList.addAll(adHarmonicService.get(scriptId, null, queryParam.getDeviceId(), queryParam.getChnNum(), plan.getCode()));
allResultList.addAll(adNonHarmonicService.get(scriptId, null, queryParam.getDeviceId(), queryParam.getChnNum(), plan.getCode()));
}
if(ObjectUtil.isNotEmpty(allResultList)){
if (ObjectUtil.isNotEmpty(allResultList)) {
Map<String, List<AdBaseResult>> chnMap = allResultList.stream().collect(
Collectors.groupingBy(obj -> obj.getMonitorId().substring(obj.getMonitorId().lastIndexOf("_") + 1))
);
@@ -102,8 +100,198 @@ public class ResultServiceImpl implements IResultService {
}
chnList.sort(Comparator.comparingInt(o -> Integer.parseInt(o.get("value"))));
formContentVO.setChnList(chnList);
return formContentVO;
}
@Override
public List<DetectionInfoVO> treeData(ResultParam param) {
//根据所有的检测脚本查询出检测信息
List<PqScriptDtls> dtlsList = pqScriptDtlsService.list(new MPJLambdaWrapper<PqScriptDtls>()
.selectAll(PqScriptDtls.class)
.eq(StrUtil.isNotBlank(param.getScriptId()), PqScriptDtls::getScriptId, param.getScriptId())
.eq(StrUtil.isNotBlank(param.getScriptType()), PqScriptDtls::getScriptType, param.getScriptType())
.eq(PqScriptDtls::getIndex, 81)
.ne(PqScriptDtls::getIndex, -1)
.eq(PqScriptDtls::getEnable, DataStateEnum.ENABLE.getCode()));
List<AdBaseResult> allResultList = new ArrayList<>();
List<Integer> indexList = new ArrayList<>();
if (StrUtil.isNotBlank(param.getScriptType())) {
indexList = pqScriptDtlsService.getIndexList(param.getScriptType(), param.getScriptId());
}
allResultList.addAll(adNonHarmonicService.get(param.getScriptId(), indexList, param.getDevId(), param.getDevNum(), param.getCode()));
allResultList.addAll(adHarmonicService.get(param.getScriptId(), indexList, param.getDevId(), param.getDevNum(), param.getCode()));
Map<Integer, Set<Integer>> resultMap = new HashMap<>(5);
if (CollUtil.isNotEmpty(allResultList)) {
resultMap = allResultList.stream().collect(Collectors.groupingBy(AdBaseResult::getIndex, Collectors.mapping(AdBaseResult::getResultFlag, Collectors.toSet())));
}
Map<String, List<PqScriptDtls>> dtlsSortMap = dtlsList.stream()
.sorted(Comparator.comparing(PqScriptDtls::getIndex))
.collect(Collectors.groupingBy(PqScriptDtls::getScriptType, LinkedHashMap::new, Collectors.toList()));
List<DictTree> dictTreeById = dictTreeService.getDictTreeById(new ArrayList<>(dtlsSortMap.keySet()));
Map<String, DictTree> dictTreeMap = dictTreeById.stream().collect(Collectors.toMap(DictTree::getId, Function.identity()));
Map<String, String> subName = new LinkedHashMap<>();
subName.put("Base", "额定工作条件下的测量");
subName.put("VOL", "电压对XX测量的影响");
subName.put("Freq", "频率对XX测量的影响");
subName.put("Harm", "谐波对XX测量的影响");
Boolean isValueType = scriptMapper.selectScriptIsValueType(param.getScriptId());
List<DetectionInfoVO> infoVOS = new ArrayList<>();
Map<Integer, Set<Integer>> finalResultMap = resultMap;
dtlsSortMap.forEach((key, value) -> {
DictTree dictTree = dictTreeMap.get(key);
if (ObjectUtil.isNotNull(dictTree)) {
List<DetectionInfoVO> scriptSubList=new ArrayList<>();
LinkedHashMap<String, List<PqScriptDtls>> subTypeMap = value.stream()
.sorted(Comparator.comparing(PqScriptDtls::getIndex))
.collect(Collectors.groupingBy(PqScriptDtls::getScriptSubType, LinkedHashMap::new, Collectors.toList()));
subTypeMap.forEach((subKey, subValue) -> {
List<DetectionInfoVO> scriptDlsList=new ArrayList<>();
//根据index进行分组统计小相检测信息
LinkedHashMap<Integer, List<PqScriptDtls>> indexMap = subValue.stream()
.sorted(Comparator.comparing(PqScriptDtls::getIndex))
.collect(Collectors.groupingBy(PqScriptDtls::getIndex, LinkedHashMap::new, Collectors.toList()));
indexMap.forEach((index, scriptDtlIndex) -> {
if (finalResultMap.containsKey(index)) {
Set<Integer> nums = finalResultMap.get(index);
DetectionInfoVO childInfo = new DetectionInfoVO();
StringBuffer buffer = new StringBuffer();
buffer.append("输入:");
List<PqScriptDtls> freq = scriptDtlIndex.stream().filter(x -> "Freq".equals(x.getValueType())).collect(Collectors.toList());
if (CollUtil.isNotEmpty(freq)) {
buffer.append("频率=" + freq.get(0).getValue() + ResultUnitEnum.FREQ_UNIT.getUnit() + " ");
}
List<PqScriptDtls> vol = scriptDtlIndex.stream().filter(x -> "VOL".equals(x.getValueType()))
.sorted(Comparator.comparing(PqScriptDtls::getPhase)).collect(Collectors.toList());
if (CollUtil.isNotEmpty(vol)) {
String unit;
if (isValueType) {
unit = ResultUnitEnum.V_RELATIVE_UNIT.getUnit();
} else {
unit = ResultUnitEnum.V_ABSOLUTELY_UNIT.getUnit();
}
for (PqScriptDtls dtls : vol) {
buffer.append("U" + dtls.getPhase().toLowerCase() + "=" + dtls.getValue() + unit + " ");
}
}
List<PqScriptDtls> cur = scriptDtlIndex.stream().filter(x -> "CUR".equals(x.getValueType()))
.sorted(Comparator.comparing(PqScriptDtls::getPhase))
.collect(Collectors.toList());
if (CollUtil.isNotEmpty(cur)) {
String unit;
if (isValueType) {
unit = ResultUnitEnum.I_RELATIVE_UNIT.getUnit();
} else {
unit = ResultUnitEnum.I_ABSOLUTELY_UNIT.getUnit();
}
for (PqScriptDtls dtls : vol) {
buffer.append("I" + dtls.getPhase().toLowerCase() + "=" + dtls.getValue() + unit + " ");
}
}
dtlsSetBuffer(scriptDtlIndex, vol, buffer, "Harm_V", "次谐波电压幅值", ResultUnitEnum.HV_UNIT.getUnit(), true);
dtlsSetBuffer(scriptDtlIndex, vol, buffer, "Harm_I", "次谐波电流幅值", ResultUnitEnum.HI_UNIT.getUnit(), true);
dtlsSetBuffer(scriptDtlIndex, vol, buffer, "InHarm_V", "次间谐波电压幅值", ResultUnitEnum.HSV_UNIT.getUnit(), false);
dtlsSetBuffer(scriptDtlIndex, vol, buffer, "InHarm_I", "次间谐波电流幅值", ResultUnitEnum.HSI_UNIT.getUnit(), false);
dtlsSetBufferDip(scriptDtlIndex, vol, buffer, "Dip", "暂态", ResultUnitEnum.HSI_UNIT.getUnit());
dtlsSetBufferFlicker(scriptDtlIndex, vol, buffer, "Flicker", "闪变");
childInfo.setIndex(index);
childInfo.setFly(conform(nums));
childInfo.setScriptTypeName(buffer.toString());
scriptDlsList.add(childInfo);
}
});
if (CollUtil.isNotEmpty(scriptDlsList)) {
DetectionInfoVO sub=new DetectionInfoVO();
sub.setScriptTypeName(subName.get(subKey).replace("XX", dictTree.getName()));
sub.setChildren(scriptDlsList);
scriptSubList.add(sub);
}
});
if (CollUtil.isNotEmpty(scriptSubList)) {
//大相检测信息
DetectionInfoVO infoVO = new DetectionInfoVO();
infoVO.setScriptTypeName(dictTree.getName());
infoVO.setChildren(scriptSubList);
infoVOS.add(infoVO);
}
}
});
return infoVOS;
}
private static void dtlsSetBuffer(List<PqScriptDtls> scriptDtlIndex, List<PqScriptDtls> vol, StringBuffer buffer, String valueType, String name, String unit, Boolean fly) {
LinkedHashMap<Double, List<PqScriptDtls>> harmNumMap = scriptDtlIndex.stream()
.filter(x -> valueType.equals(x.getValueType()))
.sorted(Comparator.comparing(PqScriptDtls::getIndex))
.collect(Collectors.groupingBy(PqScriptDtls::getHarmNum, LinkedHashMap::new, Collectors.toList()));
harmNumMap.forEach((harmNum, value) -> {
if (fly) {
buffer.append(String.format("%.0f", harmNum) + name + "(");
} else {
buffer.append(harmNum + name + "(");
}
List<PqScriptDtls> list = scriptDtlIndex.stream().filter(x -> valueType.equals(x.getValueType()))
.sorted(Comparator.comparing(PqScriptDtls::getPhase))
.collect(Collectors.toList());
if (CollUtil.isNotEmpty(list)) {
for (PqScriptDtls dtls : vol) {
buffer.append(dtls.getPhase() + "相=" + dtls.getValue() + unit + " ");
}
buffer.append(") ");
}
});
}
private static void dtlsSetBufferDip(List<PqScriptDtls> scriptDtlIndex, List<PqScriptDtls> vol, StringBuffer buffer, String valueType, String name, String unit) {
List<PqScriptDtls> list = scriptDtlIndex.stream().filter(x -> valueType.equals(x.getValueType()))
.sorted(Comparator.comparing(PqScriptDtls::getPhase))
.collect(Collectors.toList());
if (CollUtil.isNotEmpty(list)) {
buffer.append(name + " ");
for (PqScriptDtls dtls : vol) {
buffer.append(dtls.getPhase() + "相(暂态深度=" + dtls.getTransValue() + ResultUnitEnum.VOLTAGE_DUR_UNIT.getUnit()
+ " 暂态持续时间=" + dtls.getRetainTime() + ResultUnitEnum.VOLTAGE_DUR_UNIT.getUnit() + ") ");
}
}
}
private static void dtlsSetBufferFlicker(List<PqScriptDtls> scriptDtlIndex, List<PqScriptDtls> vol, StringBuffer buffer, String valueType, String name) {
List<PqScriptDtls> list = scriptDtlIndex.stream().filter(x -> valueType.equals(x.getValueType()))
.sorted(Comparator.comparing(PqScriptDtls::getPhase))
.collect(Collectors.toList());
if (CollUtil.isNotEmpty(list)) {
buffer.append(name + " ");
for (PqScriptDtls dtls : vol) {
buffer.append(dtls.getPhase() + "相(变动频度=" + dtls.getTransValue()
+ "次/min 变动量=" + dtls.getRetainTime() + ResultUnitEnum.VOLTAGE_DUR_UNIT.getUnit() + ") ");
}
}
}
private Integer conform(Set<Integer> numbers) {
if (numbers.size() > 2) {
return 4;
} else if (numbers.size() > 1) {
if (numbers.contains(4)) {
return 4;
} else if (numbers.contains(2)) {
return 2;
}
}
return new ArrayList<>(numbers).get(0);
}
}