1.解决误差为0是不符合问题

2.优化检测脚本回显和通讯脚本默认值问题
3.调整三相不平衡度公式工具类
This commit is contained in:
wr
2025-02-25 20:57:41 +08:00
parent d65b68bbf4
commit 5ee33fabdf
10 changed files with 371 additions and 270 deletions

View File

@@ -1124,7 +1124,7 @@ public class DetectionServiceImpl {
}
return BigDecimal.valueOf(devData - channelData);
}
return BigDecimal.valueOf(devData);
return BigDecimal.valueOf(0);
}
public BigDecimal divide(Double devData, Double channelData) {

View File

@@ -176,7 +176,7 @@ public class ResultServiceImpl implements IResultService {
subTypeMap.forEach((subKey, subValue) -> {
if (!"VOLTAGE".equals(dictTree.getCode())) {
TreeDataVO subType = new TreeDataVO();
subType.setScriptTypeName(subName.get(subKey).replace("XX", dictTree.getName()));
subType.setScriptTypeName(!subName.containsKey(subKey)?"":subName.get(subKey).replace("XX", dictTree.getName()));
subType.setScriptTypeCode(subKey);
LinkedHashMap<Integer, List<PqScriptDtls>> indexMap = subValue.stream()
.sorted(Comparator.comparing(PqScriptDtls::getScriptIndex))
@@ -213,13 +213,13 @@ public class ResultServiceImpl implements IResultService {
.collect(Collectors.groupingBy(PqScriptDtls::getScriptSubType, LinkedHashMap::new, Collectors.toList()));
if (CollUtil.isNotEmpty(subSingleTypeMap)) {
TreeDataVO subType = new TreeDataVO();
subType.setScriptTypeName(subName.get("Single").replace("XX", dictTree.getName()));
subType.setScriptTypeName(!subName.containsKey("Single")?"":subName.get("Single").replace("XX", dictTree.getName()));
subType.setScriptTypeCode(dictTree.getCode());
//单影响量下频率准测量集合
List<TreeDataVO> subSingleList = new ArrayList<>();
subSingleTypeMap.forEach((subKey, subValue) -> {
TreeDataVO treeDataVO = new TreeDataVO();
treeDataVO.setScriptTypeName(subName.get(subKey).replace("XX", dictTree.getName()));
treeDataVO.setScriptTypeName(!subName.containsKey(subKey)?"":subName.get(subKey).replace("XX", dictTree.getName()));
treeDataVO.setScriptTypeCode(subKey);
List<TreeDataVO> subTypeList = new ArrayList<>();

View File

@@ -35,7 +35,7 @@ public class PqScriptDtlsParam {
private String subType;
/**
* 多量响量
* 检测序号
*/
private Integer index;
@@ -57,6 +57,8 @@ public class PqScriptDtlsParam {
@JSONField(name = "fFreq", ordinal = 6)
private Double fFreq;
@JSONField(name = "retryCompute", ordinal = 6)
private Boolean retryCompute = false;
/**
* 装置下发参数
*/

View File

@@ -18,7 +18,6 @@ public class ScriptParam {
private String scriptId;
@ApiModelProperty("检测脚本类型")
@NotBlank(message = DevValidMessage.ID_FORMAT_ERROR)
private String scriptType;
@ApiModelProperty("检测脚本序号")

View File

@@ -111,6 +111,7 @@ public class PqScriptCheckDataServiceImpl extends ServiceImpl<PqScriptCheckDataM
.eq(PqScriptCheckData::getScriptId, param.getScriptId())
.eq(ObjectUtil.isNotNull(param.getIndex()),PqScriptCheckData::getScriptIndex, param.getIndex())
.eq(PqScriptCheckData::getValueType, param.getValueType())
.eq(PqScriptCheckData::getPhase, param.getPhase())
.eq(PqScriptCheckData::getEnable, DataStateEnum.ENABLE.getCode());
PqScriptCheckData data = this.getBaseMapper().selectOne(queryWrapper);

View File

@@ -27,7 +27,7 @@ import com.njcn.gather.script.pojo.po.SourceIssue;
import com.njcn.gather.script.service.IPqScriptCheckDataService;
import com.njcn.gather.script.service.IPqScriptDtlsService;
import com.njcn.gather.script.util.ScriptDtlsDesc;
import com.njcn.gather.script.util.UnbanUtil;
import com.njcn.gather.script.util.ThreePhaseUnbalance;
import com.njcn.gather.system.dictionary.pojo.po.DictTree;
import com.njcn.gather.system.dictionary.service.IDictTreeService;
import com.njcn.gather.type.pojo.po.DevType;
@@ -261,6 +261,7 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
List<PqScriptDtlsParam.CheckData> checkDataList = sourceIssue.getCheckDataList();
PqScriptCheckData data;
if (CollUtil.isNotEmpty(checkDataList)) {
checkDataList = checkDataList.stream().filter(x -> ObjectUtil.isNotNull(x.getValue())).collect(Collectors.toList());
for (PqScriptDtlsParam.CheckData checkData : checkDataList) {
data = new PqScriptCheckData();
data.setScriptId(sourceIssue.getScriptId());
@@ -390,6 +391,15 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
//获取所有下拉值情况
List<PqScriptDtlsParam.CheckData> checkDataList = sourceIssue.getCheckDataList();
if (CollUtil.isNotEmpty(checkDataList)) {
Map<String, List<PqScriptCheckData>> checkDataOldMap = new HashMap<>();
if (sourceIssue.getRetryCompute()) {
PqScriptCheckDataParam param = new PqScriptCheckDataParam();
param.setScriptId(sourceIssue.getScriptId());
param.setIndex(sourceIssue.getIndex());
List<PqScriptCheckData> checkDataOld = pqScriptCheckDataService.listCheckDataCode(param);
checkDataOldMap = checkDataOld.stream().collect(Collectors.groupingBy(PqScriptCheckData::getValueTypeCode));
}
List<String> ids = checkDataList.stream().map(PqScriptDtlsParam.CheckData::getValueType).collect(Collectors.toList());
List<DictTree> dictTreeById = dictTreeService.getDictTreeById(ids);
Map<String, DictTree> dicTreeMap = dictTreeById.stream().collect(Collectors.toMap(DictTree::getId, Function.identity()));
@@ -401,14 +411,24 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
DetectionCodeEnum codeEnum = DetectionCodeEnum.getDetectionCodeByCode(dictTree.getCode());
List<PqScriptDtlsParam.ChannelListDTO> channelList = sourceIssue.getChannelList();
List<PqScriptDtlsParam.ChannelListDTO> list;
List<PqScriptCheckData> checkArchive;
if (checkDataOldMap.containsKey(codeEnum.getCode())) {
checkArchive = checkDataOldMap.get(codeEnum.getCode());
} else {
checkArchive = new ArrayList<>();
}
switch (codeEnum) {
case FREQ:
checkData = new PqScriptDtlsParam.CheckData();
checkData.setErrorFlag(channelListDTO.getErrorFlag());
checkData.setEnable(channelListDTO.getEnable());
checkData.setValue(sourceIssue.getFFreq());
checkData.setPhase("T");
checkData.setDataType(channelListDTO.getDataType());
if (CollUtil.isNotEmpty(checkArchive)) {
checkData.setValue(checkArchive.get(0).getValue());
} else {
checkData.setValue(sourceIssue.getFFreq());
}
checkData.setValueType(channelListDTO.getValueType());
checkData.setPid(channelListDTO.getPid());
info.add(checkData);
@@ -417,23 +437,13 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
case VRMS:
if (CollUtil.isNotEmpty(channelList)) {
list = channelList.stream().filter(x -> x.getChannelType().contains("U")).collect(Collectors.toList());
rmsCheck(info, channelListDTO, list);
rmsCheck(info, channelListDTO, list, checkArchive, false);
}
break;
case DELTA_V:
if (CollUtil.isNotEmpty(channelList)) {
list = channelList.stream().filter(x -> x.getChannelType().contains("U")).collect(Collectors.toList());
for (PqScriptDtlsParam.ChannelListDTO listDTO : list) {
checkData = new PqScriptDtlsParam.CheckData();
checkData.setErrorFlag(channelListDTO.getErrorFlag());
checkData.setEnable(channelListDTO.getEnable());
checkData.setValue(0.0);
checkData.setPhase(listDTO.getChannelType().substring(1, 2).toUpperCase());
checkData.setDataType(channelListDTO.getDataType());
checkData.setValueType(channelListDTO.getValueType());
checkData.setPid(channelListDTO.getPid());
info.add(checkData);
}
rmsCheck(info, channelListDTO, list, checkArchive, true);
}
break;
case VA:
@@ -444,7 +454,7 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
checkData.setErrorFlag(channelListDTO.getErrorFlag());
checkData.setEnable(channelListDTO.getEnable());
checkData.setValue(listDTO.getFPhase());
checkData.setPhase(listDTO.getChannelType().substring(1, 2).toUpperCase());
setCheckValue(checkArchive, checkData, listDTO);
checkData.setDataType(channelListDTO.getDataType());
checkData.setValueType(channelListDTO.getValueType());
checkData.setPid(channelListDTO.getPid());
@@ -455,13 +465,13 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
case V2_50:
if (CollUtil.isNotEmpty(channelList)) {
list = channelList.stream().filter(x -> x.getChannelType().contains("U")).collect(Collectors.toList());
harmCheck(info, channelListDTO, list);
harmCheck(info, channelListDTO, list, checkArchive);
}
break;
case I2_50:
if (CollUtil.isNotEmpty(channelList)) {
list = channelList.stream().filter(x -> x.getChannelType().contains("I")).collect(Collectors.toList());
harmCheck(info, channelListDTO, list);
harmCheck(info, channelListDTO, list, checkArchive);
}
break;
case P2_50:
@@ -488,12 +498,7 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
//电压*电流*cos电压角度-电流角度)
checkData.setValue(i.getFAmp() * harmModel.getFAmp() * Math.cos(harmModel.getFPhase() - i.getFPhase()));
}
checkData.setPhase(listDTO.getChannelType().substring(1, 2).toUpperCase());
checkData.setDataType(channelListDTO.getDataType());
checkData.setValueType(channelListDTO.getValueType());
checkData.setPid(channelListDTO.getPid());
info.add(checkData);
setCheck(info, checkData, channelListDTO, checkArchive, listDTO);
}
}
}
@@ -503,13 +508,13 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
case SV_1_49:
if (CollUtil.isNotEmpty(channelList)) {
list = channelList.stream().filter(x -> x.getChannelType().contains("U")).collect(Collectors.toList());
inHarmCheck(info, channelListDTO, list);
inHarmCheck(info, channelListDTO, list, checkArchive);
}
break;
case SI_1_49:
if (CollUtil.isNotEmpty(channelList)) {
list = channelList.stream().filter(x -> x.getChannelType().contains("I")).collect(Collectors.toList());
inHarmCheck(info, channelListDTO, list);
inHarmCheck(info, channelListDTO, list, checkArchive);
}
break;
case MAG:
@@ -519,11 +524,7 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
checkData.setErrorFlag(channelListDTO.getErrorFlag());
checkData.setEnable(channelListDTO.getEnable());
checkData.setValue(listDTO.getDipData().getFTransValue());
checkData.setPhase(listDTO.getChannelType().substring(1, 2).toUpperCase());
checkData.setDataType(channelListDTO.getDataType());
checkData.setValueType(channelListDTO.getValueType());
checkData.setPid(channelListDTO.getPid());
info.add(checkData);
setCheck(info, checkData, channelListDTO, checkArchive, listDTO);
}
break;
case DUR:
@@ -533,27 +534,23 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
checkData.setErrorFlag(channelListDTO.getErrorFlag());
checkData.setEnable(channelListDTO.getEnable());
checkData.setValue(listDTO.getDipData().getRetainTime());
checkData.setPhase(listDTO.getChannelType().substring(1, 2).toUpperCase());
checkData.setDataType(channelListDTO.getDataType());
checkData.setValueType(channelListDTO.getValueType());
checkData.setPid(channelListDTO.getPid());
info.add(checkData);
setCheck(info, checkData, channelListDTO, checkArchive, listDTO);
}
break;
case IRMS:
case IA:
if (CollUtil.isNotEmpty(channelList)) {
list = channelList.stream().filter(x -> x.getChannelType().contains("I")).collect(Collectors.toList());
rmsCheck(info, channelListDTO, list);
rmsCheck(info, channelListDTO, list, checkArchive, false);
}
break;
case V_UNBAN:
list = channelList.stream().filter(x -> x.getChannelType().contains("U")).collect(Collectors.toList());
unbanCheck(info, channelListDTO, channelList, list);
unbanCheck(info, channelListDTO, channelList, list, checkArchive);
break;
case I_UNBAN:
list = channelList.stream().filter(x -> x.getChannelType().contains("I")).collect(Collectors.toList());
unbanCheck(info, channelListDTO, channelList, list);
unbanCheck(info, channelListDTO, channelList, list, checkArchive);
break;
case PST:
if (CollUtil.isNotEmpty(channelList)) {
@@ -565,11 +562,7 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
if (ObjectUtil.isNotNull(listDTO.getFlickerData())) {
checkData.setValue(listDTO.getFlickerData().getFlickerValue());
}
checkData.setPhase(listDTO.getChannelType().substring(1, 2).toUpperCase());
checkData.setDataType(channelListDTO.getDataType());
checkData.setValueType(channelListDTO.getValueType());
checkData.setPid(channelListDTO.getPid());
info.add(checkData);
setCheck(info, checkData, channelListDTO, checkArchive, listDTO);
}
}
@@ -587,6 +580,15 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
return info;
}
private void setCheck(List<PqScriptDtlsParam.CheckData> info, PqScriptDtlsParam.CheckData checkData, PqScriptDtlsParam.CheckData channelListDTO, List<PqScriptCheckData> checkArchive, PqScriptDtlsParam.ChannelListDTO listDTO) {
setCheckValue(checkArchive, checkData, listDTO);
checkData.setPhase(listDTO.getChannelType().substring(1, 2).toUpperCase());
checkData.setDataType(channelListDTO.getDataType());
checkData.setValueType(channelListDTO.getValueType());
checkData.setPid(channelListDTO.getPid());
info.add(checkData);
}
@Override
public Boolean deleteDtls(ScriptParam param) {
this.remove(new LambdaQueryWrapper<PqScriptDtls>()
@@ -627,7 +629,12 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
return Collections.emptyList();
}
private void unbanCheck(List<PqScriptDtlsParam.CheckData> info, PqScriptDtlsParam.CheckData channelListDTO, List<PqScriptDtlsParam.ChannelListDTO> channelList, List<PqScriptDtlsParam.ChannelListDTO> list) {
private void unbanCheck(List<PqScriptDtlsParam.CheckData> info,
PqScriptDtlsParam.CheckData channelListDTO,
List<PqScriptDtlsParam.ChannelListDTO> channelList,
List<PqScriptDtlsParam.ChannelListDTO> list,
List<PqScriptCheckData> checkArchive
) {
PqScriptDtlsParam.CheckData checkData;
if (CollUtil.isNotEmpty(list)) {
PqScriptDtlsParam.ChannelListDTO a = channelList.stream().filter(x -> x.getChannelType().contains("a")).findFirst().get();
@@ -636,7 +643,10 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
checkData = new PqScriptDtlsParam.CheckData();
checkData.setErrorFlag(channelListDTO.getErrorFlag());
checkData.setEnable(channelListDTO.getEnable());
checkData.setValue(UnbanUtil.calculateUnbalance(a.getFAmp(), a.getFPhase(), b.getFAmp(), b.getFPhase(), c.getFAmp(), c.getFPhase()));
checkData.setValue(ThreePhaseUnbalance.calculateUnbalance(a.getFAmp(), a.getFPhase(), b.getFAmp(), b.getFPhase(), c.getFAmp(), c.getFPhase()));
if (CollUtil.isNotEmpty(checkArchive)) {
checkData.setValue(checkArchive.get(0).getValue());
}
checkData.setPhase("T");
checkData.setDataType(channelListDTO.getDataType());
checkData.setValueType(channelListDTO.getValueType());
@@ -645,14 +655,28 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
}
}
private void rmsCheck(List<PqScriptDtlsParam.CheckData> info, PqScriptDtlsParam.CheckData channelListDTO, List<PqScriptDtlsParam.ChannelListDTO> list) {
private void rmsCheck(List<PqScriptDtlsParam.CheckData> info,
PqScriptDtlsParam.CheckData channelListDTO,
List<PqScriptDtlsParam.ChannelListDTO> list,
List<PqScriptCheckData> checkArchive,
Boolean flyDeltaV
) {
PqScriptDtlsParam.CheckData checkData;
for (PqScriptDtlsParam.ChannelListDTO listDTO : list) {
checkData = new PqScriptDtlsParam.CheckData();
checkData.setErrorFlag(channelListDTO.getErrorFlag());
checkData.setEnable(channelListDTO.getEnable());
checkData.setValue(listDTO.getFAmp());
checkData.setPhase(listDTO.getChannelType().substring(1, 2).toUpperCase());
List<PqScriptCheckData> collect = checkArchive.stream().filter(x -> x.getPhase().equals(listDTO.getChannelType().substring(1, 2).toUpperCase())).collect(Collectors.toList());
if (CollUtil.isNotEmpty(collect)) {
checkData.setValue(collect.get(0).getValue());
} else {
if (flyDeltaV) {
checkData.setValue(0.0);
} else {
checkData.setValue(listDTO.getFAmp());
}
}
checkData.setDataType(channelListDTO.getDataType());
checkData.setValueType(channelListDTO.getValueType());
checkData.setPid(channelListDTO.getPid());
@@ -660,7 +684,11 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
}
}
private void inHarmCheck(List<PqScriptDtlsParam.CheckData> info, PqScriptDtlsParam.CheckData channelListDTO, List<PqScriptDtlsParam.ChannelListDTO> uList) {
private void inHarmCheck(List<PqScriptDtlsParam.CheckData> info,
PqScriptDtlsParam.CheckData channelListDTO,
List<PqScriptDtlsParam.ChannelListDTO> uList,
List<PqScriptCheckData> checkArchive
) {
PqScriptDtlsParam.CheckData checkData;
for (PqScriptDtlsParam.ChannelListDTO listDTO : uList) {
List<PqScriptDtlsParam.ChannelListDTO.InharmModel> inharmList = listDTO.getInharmList();
@@ -670,7 +698,7 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
checkData.setErrorFlag(channelListDTO.getErrorFlag());
checkData.setEnable(channelListDTO.getEnable());
checkData.setValue(inharmModel.getFAmp());
checkData.setPhase(listDTO.getChannelType().substring(1, 2).toUpperCase());
setCheckValue(checkArchive, checkData, listDTO);
checkData.setHarmNum(inharmModel.getInharm());
checkData.setDataType(channelListDTO.getDataType());
checkData.setValueType(channelListDTO.getValueType());
@@ -681,7 +709,19 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
}
}
private void harmCheck(List<PqScriptDtlsParam.CheckData> info, PqScriptDtlsParam.CheckData channelListDTO, List<PqScriptDtlsParam.ChannelListDTO> uList) {
private void setCheckValue(List<PqScriptCheckData> checkArchive, PqScriptDtlsParam.CheckData checkData, PqScriptDtlsParam.ChannelListDTO listDTO) {
List<PqScriptCheckData> collect = checkArchive.stream().filter(x -> x.getPhase().equals(listDTO.getChannelType().substring(1, 2).toUpperCase())).collect(Collectors.toList());
if (CollUtil.isNotEmpty(collect)) {
checkData.setValue(collect.get(0).getValue());
}
checkData.setPhase(listDTO.getChannelType().substring(1, 2).toUpperCase());
}
private void harmCheck(List<PqScriptDtlsParam.CheckData> info,
PqScriptDtlsParam.CheckData channelListDTO,
List<PqScriptDtlsParam.ChannelListDTO> uList,
List<PqScriptCheckData> checkArchive
) {
PqScriptDtlsParam.CheckData checkData;
for (PqScriptDtlsParam.ChannelListDTO listDTO : uList) {
List<PqScriptDtlsParam.ChannelListDTO.HarmModel> harmList = listDTO.getHarmList();
@@ -691,6 +731,7 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
checkData.setErrorFlag(channelListDTO.getErrorFlag());
checkData.setEnable(channelListDTO.getEnable());
checkData.setValue(harmModel.getFAmp());
setCheckValue(checkArchive, checkData, listDTO);
checkData.setPhase(listDTO.getChannelType().substring(1, 2).toUpperCase());
checkData.setHarmNum(harmModel.getHarm());
checkData.setDataType(channelListDTO.getDataType());
@@ -740,22 +781,24 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
pqScriptDtls = this.list(queryWrapper);
} else {
//先获取检测脚本类型是否相对值 true相对值 false绝对值相对值要乘额定值,绝对值不需要处理)
Boolean isValueType = pqScriptMapper.selectScriptIsValueType(param.getScriptId());
queryWrapper.eq(PqScriptDtls::getScriptId, param.getScriptId());
pqScriptDtls = this.getBaseMapper().selectJoinList(PqScriptDtls.class, queryWrapper);
if (isValueType) {
for (PqScriptDtls pqScriptDtl : pqScriptDtls) {
if (VOL.equals(pqScriptDtl.getValueType())) {
BigDecimal volValue = new BigDecimal(pqScriptDtl.getValue());
BigDecimal result = volValue.divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_UP)
.multiply(new BigDecimal(volt.toString()));
pqScriptDtl.setValue(result.doubleValue());
}
if (CUR.equals(pqScriptDtl.getValueType())) {
BigDecimal volValue = new BigDecimal(pqScriptDtl.getValue());
BigDecimal result = volValue.divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_UP)
.multiply(new BigDecimal(curr.toString()));
pqScriptDtl.setValue(result.doubleValue());
if (CollUtil.isNotEmpty(param.getDevIds())) {
Boolean isValueType = pqScriptMapper.selectScriptIsValueType(param.getScriptId());
if (isValueType) {
for (PqScriptDtls pqScriptDtl : pqScriptDtls) {
if (VOL.equals(pqScriptDtl.getValueType())) {
BigDecimal volValue = new BigDecimal(pqScriptDtl.getValue());
BigDecimal result = volValue.multiply(new BigDecimal(volt.toString()))
.divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_UP);
pqScriptDtl.setValue(result.doubleValue());
}
if (CUR.equals(pqScriptDtl.getValueType())) {
BigDecimal volValue = new BigDecimal(pqScriptDtl.getValue());
BigDecimal result = volValue.multiply(new BigDecimal(curr.toString()))
.divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_UP);
pqScriptDtl.setValue(result.doubleValue());
}
}
}
}
@@ -786,16 +829,19 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
String code,
List<SourceIssue.ChannelListDTO> channelListDTOS,
PqScriptCheckDataParam checkDataParam) {
for (PqScriptDtls dtls : dtlsList) {
List<String> info = new ArrayList<>();
info.add("A");
info.add("B");
info.add("C");
for (String phase : info) {
List<PqScriptDtls> collect = dtlsList.stream().filter(x -> x.getPhase().equals(phase)).collect(Collectors.toList());
SourceIssue.ChannelListDTO channelListDTO = new SourceIssue.ChannelListDTO();
channelListDTO.setChannelFlag(true);
channelListDTO.setChannelFlag(false);
channelListDTO.setHarmFlag(false);
channelListDTO.setInHarmFlag(false);
channelListDTO.setDipFlag(false);
channelListDTO.setFlickerFlag(false);
channelListDTO.setChannelType(code + dtls.getPhase().toLowerCase());
channelListDTO.setFAmp(dtls.getValue());
channelListDTO.setFPhase(dtls.getAngle());
channelListDTO.setChannelType(code + phase.toLowerCase());
channelListDTO.setHarmList(new ArrayList<>());
channelListDTO.setInharmList(new ArrayList<>());
//暂态数据
@@ -820,57 +866,65 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
flickerDataDTO.setFChagValue(0.0);
channelListDTO.setFlickerData(flickerDataDTO);
if (CollUtil.isNotEmpty(dtlsOtherList)) {
List<PqScriptDtls> phaseList = dtlsOtherList.stream().filter(x -> dtls.getPhase().equals(x.getPhase()))
.sorted(Comparator.comparing(PqScriptDtls::getHarmNum))
.collect(Collectors.toList());
if (CollUtil.isNotEmpty(phaseList)) {
//处理谐波类型
List<PqScriptDtls> harmList = phaseList.stream().filter(x -> harm.equals(x.getValueType()))
if (CollUtil.isNotEmpty(collect)) {
PqScriptDtls dtls = collect.get(0);
channelListDTO.setChannelFlag(true);
channelListDTO.setFAmp(dtls.getValue());
channelListDTO.setFPhase(dtls.getAngle());
if (CollUtil.isNotEmpty(dtlsOtherList)) {
List<PqScriptDtls> phaseList = dtlsOtherList.stream().filter(x -> dtls.getPhase().equals(x.getPhase()))
.collect(Collectors.toList());
if (CollUtil.isNotEmpty(harmList)) {
channelListDTO.setHarmList(getHarmModels(harmList));
channelListDTO.setHarmFlag(true);
}
//处理间谐波类型
List<PqScriptDtls> inHarmList = phaseList.stream().filter(x -> inHarm.equals(x.getValueType()))
.collect(Collectors.toList());
if (CollUtil.isNotEmpty(inHarmList)) {
channelListDTO.setInharmList(getInHarmModels(inHarmList));
channelListDTO.setInHarmFlag(true);
}
//处理暂态数据
List<PqScriptDtls> dipList = phaseList.stream().filter(x -> DIP.equals(x.getValueType()))
.collect(Collectors.toList());
if (CollUtil.isNotEmpty(dipList)) {
PqScriptDtls dip = dipList.get(0);
dipDataDTO.setFTransValue(dip.getTransValue());
// 1.0/频率*持续时间(周波)= 暂态持续时间s
dipDataDTO.setFRetainTime(NumberUtil.round(1.0 / fFreq * dip.getRetainTime(), 3).doubleValue());
dipDataDTO.setRetainTime(dip.getRetainTime());
channelListDTO.setDipFlag(true);
channelListDTO.setDipData(dipDataDTO);
}
//处理闪变数据
List<PqScriptDtls> flickeRList = phaseList.stream().filter(x -> FLICKER.equals(x.getValueType()))
.collect(Collectors.toList());
if (CollUtil.isNotEmpty(flickeRList)) {
PqScriptDtls flicker = flickeRList.get(0);
flickerDataDTO.setFChagFre(flicker.getChagFre());
flickerDataDTO.setFChagValue(flicker.getChagValue());
List<DictTree> treeByCode = dictTreeService.getTreeByCode(DetectionCodeEnum.PST.getCode());
if (CollUtil.isNotEmpty(treeByCode)) {
checkDataParam.setValueType(treeByCode.get(0).getId());
checkDataParam.setPhase(dtls.getPhase());
flickerDataDTO.setFlickerValue(pqScriptCheckDataService.getCheckDataValue(checkDataParam));
if (CollUtil.isNotEmpty(phaseList)) {
//处理谐波类型
List<PqScriptDtls> harmList = phaseList.stream().filter(x -> harm.equals(x.getValueType()))
.filter(x -> ObjectUtil.isNotNull(x.getHarmNum()))
.sorted(Comparator.comparing(PqScriptDtls::getHarmNum))
.collect(Collectors.toList());
if (CollUtil.isNotEmpty(harmList)) {
channelListDTO.setHarmList(getHarmModels(harmList));
channelListDTO.setHarmFlag(true);
}
channelListDTO.setFlickerFlag(true);
channelListDTO.setFlickerData(flickerDataDTO);
}
//处理间谐波类型
List<PqScriptDtls> inHarmList = phaseList.stream().filter(x -> inHarm.equals(x.getValueType()))
.filter(x -> ObjectUtil.isNotNull(x.getHarmNum()))
.sorted(Comparator.comparing(PqScriptDtls::getHarmNum))
.collect(Collectors.toList());
if (CollUtil.isNotEmpty(inHarmList)) {
channelListDTO.setInharmList(getInHarmModels(inHarmList));
channelListDTO.setInHarmFlag(true);
}
//处理暂态数据
List<PqScriptDtls> dipList = phaseList.stream().filter(x -> DIP.equals(x.getValueType()))
.collect(Collectors.toList());
if (CollUtil.isNotEmpty(dipList)) {
PqScriptDtls dip = dipList.get(0);
dipDataDTO.setFTransValue(dip.getTransValue());
// 1.0/频率*持续时间(周波)= 暂态持续时间s
dipDataDTO.setFRetainTime(NumberUtil.round(1.0 / fFreq * dip.getRetainTime(), 3).doubleValue());
dipDataDTO.setRetainTime(dip.getRetainTime());
channelListDTO.setDipFlag(true);
channelListDTO.setDipData(dipDataDTO);
}
//处理闪变数据
List<PqScriptDtls> flickeRList = phaseList.stream().filter(x -> FLICKER.equals(x.getValueType()))
.collect(Collectors.toList());
if (CollUtil.isNotEmpty(flickeRList)) {
PqScriptDtls flicker = flickeRList.get(0);
flickerDataDTO.setFChagFre(flicker.getChagFre());
flickerDataDTO.setFChagValue(flicker.getChagValue());
DictTree dictTreeByCode = dictTreeService.getDictTreeByCode(DetectionCodeEnum.PST.getCode());
if (ObjectUtil.isNotNull(dictTreeByCode)) {
checkDataParam.setValueType(dictTreeByCode.getId());
checkDataParam.setPhase(dtls.getPhase());
flickerDataDTO.setFlickerValue(pqScriptCheckDataService.getCheckDataValue(checkDataParam));
}
channelListDTO.setFlickerFlag(true);
channelListDTO.setFlickerData(flickerDataDTO);
}
}
}
}
channelListDTOS.add(channelListDTO);

View File

@@ -0,0 +1,181 @@
package com.njcn.gather.script.util;
/**
* @author hongawen
* @version 1.0
* @data 2025/2/25 13:24
*/
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
public class ThreePhaseUnbalance {
// 定义复数类
static class Complex {
BigDecimal real; // 复数的实部
BigDecimal imag; // 复数的虚部
// 构造函数,初始化复数的实部和虚部
public Complex(BigDecimal real, BigDecimal imag) {
this.real = real;
this.imag = imag;
}
// 复数加法
public Complex add(Complex other) {
return new Complex(this.real.add(other.real), this.imag.add(other.imag));
}
// 复数乘法
public Complex multiply(Complex other) {
BigDecimal real = this.real.multiply(other.real).subtract(this.imag.multiply(other.imag));
BigDecimal imag = this.real.multiply(other.imag).add(this.imag.multiply(other.real));
return new Complex(real, imag);
}
// 复数除以一个实数
public Complex divide(BigDecimal divisor) {
return new Complex(this.real.divide(divisor, MathContext.DECIMAL128),
this.imag.divide(divisor, MathContext.DECIMAL128));
}
// 计算复数的模(幅值)
public BigDecimal magnitude() {
return BigDecimal.valueOf(Math.sqrt(real.multiply(real).add(imag.multiply(imag)).doubleValue()));
}
}
// 将幅值和角度(角度制)转换为复数
public static Complex fromPolar(BigDecimal magnitude, BigDecimal angleDegrees) {
double angleRadians = Math.toRadians(angleDegrees.doubleValue()); // 将角度转换为弧度
BigDecimal real = magnitude.multiply(BigDecimal.valueOf(Math.cos(angleRadians))); // 计算实部
BigDecimal imag = magnitude.multiply(BigDecimal.valueOf(Math.sin(angleRadians))); // 计算虚部
return new Complex(real, imag);
}
// 计算三相电压的对称分量(零序、正序、负序)
public static Complex[] calculateSymmetricalComponents(Complex va, Complex vb, Complex vc) {
// 120度相位因子 a = e^(j120°) = -0.5 + j * sqrt(3)/2
Complex a = new Complex(BigDecimal.valueOf(-0.5), BigDecimal.valueOf(Math.sqrt(3) / 2));
// 240度相位因子 a^2 = e^(j240°) = -0.5 - j * sqrt(3)/2
Complex a2 = a.multiply(a);
// 零序分量 V0 = (Va + Vb + Vc) / 3
Complex v0 = va.add(vb).add(vc).divide(BigDecimal.valueOf(3));
// 正序分量 V1 = (Va + a * Vb + a^2 * Vc) / 3
Complex v1 = va.add(a.multiply(vb)).add(a2.multiply(vc)).divide(BigDecimal.valueOf(3));
// 负序分量 V2 = (Va + a^2 * Vb + a * Vc) / 3
Complex v2 = va.add(a2.multiply(vb)).add(a.multiply(vc)).divide(BigDecimal.valueOf(3));
// 返回零序、正序、负序分量
return new Complex[]{v0, v1, v2};
}
// 计算三相电压的不平衡度
public static void calculateUnbalance(Complex v0, Complex v1, Complex v2) {
// 计算零序、正序、负序分量的幅值
BigDecimal v0Mag = v0.magnitude(); // 零序分量幅值
BigDecimal v1Mag = v1.magnitude(); // 正序分量幅值
BigDecimal v2Mag = v2.magnitude(); // 负序分量幅值
// 计算不平衡度
BigDecimal zeroSequenceUnbalance = v1Mag.compareTo(BigDecimal.ZERO) != 0 ?
v0Mag.divide(v1Mag, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)) : BigDecimal.ZERO;
BigDecimal negativeSequenceUnbalance = v1Mag.compareTo(BigDecimal.ZERO) != 0 ?
v2Mag.divide(v1Mag, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)) : BigDecimal.ZERO;
BigDecimal positiveSequenceUnbalance = BigDecimal.valueOf(100); // 正序电压不平衡度通常为100%
// 输出结果保留2位小数
System.out.printf("零序电压不平衡度: %.2f%%\n", zeroSequenceUnbalance.setScale(2, RoundingMode.HALF_UP).doubleValue());
System.out.printf("负序电压不平衡度: %.2f%%\n", negativeSequenceUnbalance.setScale(2, RoundingMode.HALF_UP).doubleValue());
System.out.printf("正序电压不平衡度: %.2f%%\n", positiveSequenceUnbalance.setScale(2, RoundingMode.HALF_UP).doubleValue());
}
/**
* 负序电压不平衡度
*/
public static double calculateUnbalance(double Ua0, double thetaA,
double Ub0, double thetaB,
double Uc0, double thetaC) {
// 输入三相电压的幅值和相位角(角度制)
BigDecimal vaMagnitude = new BigDecimal(Ua0);
BigDecimal vaAngle = new BigDecimal(thetaA);
BigDecimal vbMagnitude =new BigDecimal(Ub0);
BigDecimal vbAngle = new BigDecimal(thetaB);
BigDecimal vcMagnitude =new BigDecimal(Uc0);
BigDecimal vcAngle = new BigDecimal(thetaC);
// 将幅值和角度转换为复数
Complex va = fromPolar(vaMagnitude, vaAngle);
Complex vb = fromPolar(vbMagnitude, vbAngle);
Complex vc = fromPolar(vcMagnitude, vcAngle);
// 计算对称分量
Complex[] symmetricalComponents = calculateSymmetricalComponents(va, vb, vc);
Complex v1 = symmetricalComponents[1]; // 正序分量
Complex v2 = symmetricalComponents[2]; // 负序分量
// 计算零序、正序、负序分量的幅值
BigDecimal v1Mag = v1.magnitude(); // 正序分量幅值
BigDecimal v2Mag = v2.magnitude(); // 负序分量幅值
BigDecimal negativeSequenceUnbalance = v1Mag.compareTo(BigDecimal.ZERO) != 0 ?
v2Mag.divide(v1Mag, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)) : BigDecimal.ZERO;
// 输出结果保留2位小数
return negativeSequenceUnbalance.setScale(2, RoundingMode.HALF_UP).doubleValue();
}
public static void main(String[] args) {
// 输入三相电压的幅值和相位角(角度制)
System.out.println("请输入A相电压的幅值单位V");
BigDecimal vaMagnitude = new BigDecimal(57.74);
System.out.println("请输入A相电压的相位角单位");
BigDecimal vaAngle = new BigDecimal(0);
System.out.println("请输入B相电压的幅值单位V");
BigDecimal vbMagnitude =new BigDecimal(57.74*0.9);
System.out.println("请输入B相电压的相位角单位");
BigDecimal vbAngle = new BigDecimal(-122);
System.out.println("请输入C相电压的幅值单位V");
BigDecimal vcMagnitude =new BigDecimal(57.74);
System.out.println("请输入C相电压的相位角单位");
BigDecimal vcAngle = new BigDecimal(118);
// 将幅值和角度转换为复数
Complex va = fromPolar(vaMagnitude, vaAngle);
Complex vb = fromPolar(vbMagnitude, vbAngle);
Complex vc = fromPolar(vcMagnitude, vcAngle);
// 计算对称分量
Complex[] symmetricalComponents = calculateSymmetricalComponents(va, vb, vc);
Complex v0 = symmetricalComponents[0]; // 零序分量
Complex v1 = symmetricalComponents[1]; // 正序分量
Complex v2 = symmetricalComponents[2]; // 负序分量
// 输出对称分量
System.out.printf("零序分量: %.2f + j%.2f\n", v0.real.setScale(2, RoundingMode.HALF_UP).doubleValue(),
v0.imag.setScale(2, RoundingMode.HALF_UP).doubleValue());
System.out.printf("正序分量: %.2f + j%.2f\n", v1.real.setScale(2, RoundingMode.HALF_UP).doubleValue(),
v1.imag.setScale(2, RoundingMode.HALF_UP).doubleValue());
System.out.printf("负序分量: %.2f + j%.2f\n", v2.real.setScale(2, RoundingMode.HALF_UP).doubleValue(),
v2.imag.setScale(2, RoundingMode.HALF_UP).doubleValue());
// 计算并输出不平衡度
calculateUnbalance(v0, v1, v2);
}
}

View File

@@ -1,145 +0,0 @@
package com.njcn.gather.script.util;
import cn.hutool.core.util.NumberUtil;
/**
* @author wr
* @description
* @date 2025/2/19 14:00
*/
public class UnbanUtil {
static class Complex {
double real;
double imag;
Complex(double real, double imag) {
this.real = real;
this.imag = imag;
}
Complex add(Complex other) {
return new Complex(this.real + other.real, this.imag + other.imag);
}
Complex multiply(Complex other) {
double newReal = this.real * other.real - this.imag * other.imag;
double newImag = this.real * other.imag + this.imag * other.real;
return new Complex(newReal, newImag);
}
Complex divideBy3() {
return new Complex(this.real / 3.0, this.imag / 3.0);
}
double magnitude() {
return Math.sqrt(real * real + imag * imag);
}
// 定义旋转因子
static final Complex J120 = new Complex(-0.5, Math.sqrt(3) / 2);
static final Complex J_MINUS_120 = new Complex(-0.5, -Math.sqrt(3) / 2);
}
public static Complex[] calculateSequenceComponents(Complex Ua, Complex Ub, Complex Uc) {
// 计算正序分量
Complex temp1 = Ua.add(Ub.multiply(Complex.J_MINUS_120).add(Uc.multiply(Complex.J120)));
Complex U1 = temp1.divideBy3();
// 计算负序分量
Complex temp2 = Ua.add(Ub.multiply(Complex.J120).add(Uc.multiply(Complex.J_MINUS_120)));
Complex U2 = temp2.divideBy3();
// 计算零序分量
Complex temp0 = Ua.add(Ub).add(Uc);
Complex U0 = temp0.divideBy3();
return new Complex[]{U1, U2, U0};
}
public static double calculateNegativeSequenceImbalance(Complex U1, Complex U2) {
double U1Mag = U1.magnitude();
double U2Mag = U2.magnitude();
return (U2Mag / U1Mag) * 100.0;
}
public static double calculateZeroSequenceImbalance(Complex U1, Complex U0) {
double U1Mag = U1.magnitude();
double U0Mag = U0.magnitude();
return (U0Mag / U1Mag) * 100.0;
}
public static void main(String[] args) {
// 输入三相电压的幅值和相角
double Ua0 = 220.0, thetaA = 0.0; // A相
double Ub0 = 220.0, thetaB = -120.0; // B相
double Uc0 = 220.0, thetaC = 120.0; // C相
// 转换为复数形式
Complex Ua = new Complex(
Ua0 * Math.cos(thetaA * Math.PI / 180.0),
Ua0 * Math.sin(thetaA * Math.PI / 180.0)
);
Complex Ub = new Complex(
Ub0 * Math.cos(thetaB * Math.PI / 180.0),
Ub0 * Math.sin(thetaB * Math.PI / 180.0)
);
Complex Uc = new Complex(
Uc0 * Math.cos(thetaC * Math.PI / 180.0),
Uc0 * Math.sin(thetaC * Math.PI / 180.0)
);
// 计算序分量
Complex[] components = calculateSequenceComponents(Ua, Ub, Uc);
Complex U1 = components[0];
Complex U2 = components[1];
Complex U0 = components[2];
// 输出结果
System.out.printf("正序分量 U1: %.2f + j%.2f%n", U1.real, U1.imag);
System.out.printf("负序分量 U2: %.2f + j%.2f%n", U2.real, U2.imag);
System.out.printf("零序分量 U0: %.2f + j%.2f%n", U0.real, U0.imag);
// 计算不平衡度
double negativeImbalance = calculateNegativeSequenceImbalance(U1, U2);
double zeroImbalance = calculateZeroSequenceImbalance(U1, U0);
System.out.printf("负序不平衡度: %.2f%%%n", negativeImbalance);
System.out.printf("零序不平衡度: %.2f%%%n", zeroImbalance);
}
// 输入三相电压的幅值和相角
public static double calculateUnbalance(double Ua0, double thetaA,
double Ub0, double thetaB,
double Uc0, double thetaC) {
// 转换为复数形式
Complex Ua = new Complex(
Ua0 * Math.cos(thetaA * Math.PI / 180.0),
Ua0 * Math.sin(thetaA * Math.PI / 180.0)
);
Complex Ub = new Complex(
Ub0 * Math.cos(thetaB * Math.PI / 180.0),
Ub0 * Math.sin(thetaB * Math.PI / 180.0)
);
Complex Uc = new Complex(
Uc0 * Math.cos(thetaC * Math.PI / 180.0),
Uc0 * Math.sin(thetaC * Math.PI / 180.0)
);
// 计算序分量
Complex[] components = calculateSequenceComponents(Ua, Ub, Uc);
Complex U1 = components[0];
Complex U2 = components[1];
Complex U0 = components[2];
// 输出结果
System.out.printf("正序分量 U1: %.2f + j%.2f%n", U1.real, U1.imag);
System.out.printf("负序分量 U2: %.2f + j%.2f%n", U2.real, U2.imag);
System.out.printf("零序分量 U0: %.2f + j%.2f%n", U0.real, U0.imag);
// 计算不平衡度
return NumberUtil.round(calculateNegativeSequenceImbalance(U1, U2), 2).doubleValue();
}
}