1.趋势图查询添加多线程处理

2.变压器策略调整
This commit is contained in:
2025-11-11 14:33:16 +08:00
parent b7e3bb9796
commit e9ac024f73
3 changed files with 424 additions and 341 deletions

View File

@@ -8,6 +8,7 @@ import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.common.pojo.enums.common.DataStateEnum;
import com.njcn.common.pojo.exception.BusinessException; import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.device.line.mapper.LineMapper; import com.njcn.device.line.mapper.LineMapper;
import com.njcn.device.pq.enums.LineBaseEnum; import com.njcn.device.pq.enums.LineBaseEnum;
@@ -176,9 +177,9 @@ public class PqsTransformerServiceImpl extends ServiceImpl<PqsTransformerMapper,
.eq(PqsTflgass::getLogicNext, param.getDownNode()) .eq(PqsTflgass::getLogicNext, param.getDownNode())
) )
); );
if(ObjectUtil.isNotNull(tflgass)){ if (ObjectUtil.isNotNull(tflgass)) {
throw new BusinessException(PvDeviceResponseEnum.TRANSFORMER_NAME_REPEAT); throw new BusinessException(PvDeviceResponseEnum.TRANSFORMER_NAME_REPEAT);
}else{ } else {
fly = iPqsTflgassService.save(ass); fly = iPqsTflgassService.save(ass);
} }
@@ -198,59 +199,182 @@ public class PqsTransformerServiceImpl extends ServiceImpl<PqsTransformerMapper,
PqsTflgass one = iPqsTflgassService.getOne(new LambdaQueryWrapper<PqsTflgass>() PqsTflgass one = iPqsTflgassService.getOne(new LambdaQueryWrapper<PqsTflgass>()
.eq(PqsTflgass::getTfIndex, id)); .eq(PqsTflgass::getTfIndex, id));
//1.获取当前变电站下,所拥有的母线条数 List<String> arr = new ArrayList<>();
List<TerminalTree> downVoltage = lineMapper.getvoltage(subId, 1); if (Objects.nonNull(one)) {
//获取母线id arr.add(one.getLogicBefore());
List<String> ids = downVoltage.stream().map(TerminalTree::getId).collect(Collectors.toList()); arr.add(one.getLogicNext());
//查询节点是否绑定
List<PqsTflgass> pqsTflgasses = pqsTflgassMapper.selectFlgass(subId, ids);
String[][] arr = new String[pqsTflgasses.size()][2];
if (CollUtil.isNotEmpty(pqsTflgasses) && ids.size() > 2) {
for (int i = 0; i < pqsTflgasses.size(); i++) {
arr[i][0] = pqsTflgasses.get(i).getLogicBefore();
arr[i][1] = pqsTflgasses.get(i).getLogicNext();
}
} }
voltage.put("bind", arr); voltage.put("bind", arr);
Stream<String> beforeStream = pqsTflgasses.stream().map(PqsTflgass::getLogicBefore); //1.获取当前变电站下,所拥有的母线条数
Stream<String> nextStream = pqsTflgasses.stream().map(PqsTflgass::getLogicNext); List<TerminalTree> downVoltage = lineMapper.getvoltage(subId, 1);
//合并节点,要是母线都存在,说明是跨变电站,反之是本变电站 if(CollUtil.isNotEmpty(arr)) {
List<String> merge = Stream.concat(beforeStream, nextStream) downVoltage.forEach(item->{
.distinct() if(Objects.equals(item.getId(),arr.get(1))){
.collect(Collectors.toList()); item.setLevel(LineBaseEnum.SUB_V_LEVEL.getCode());
//查看已经绑定的母线 }
List<String> bindList = merge.stream().filter(x -> ids.contains(x)).collect(Collectors.toList()); });
}
//绑定母线,如有绑定的母线下不存在这个母线,说明是有跨变电站数据,则新增母线节点,为最底层节点往后,拼接 //获取所有母线层级
List<String> straddleList = merge.stream().filter(x -> !ids.contains(x)).collect(Collectors.toList()); List<Line> UpBusList = lineMapper.selectList(new LambdaQueryWrapper<Line>().eq(Line::getLevel, LineBaseEnum.SUB_V_LEVEL.getCode()).eq(Line::getState, DataStateEnum.ENABLE.getCode()).orderByAsc(Line::getSort));
//判断当前母线下是否还存在,没绑定节点 List<TerminalTree> upTreeList = UpBusList.stream().map(it -> {
List<String> not = ids.stream().filter(x -> !bindList.contains(x)).collect(Collectors.toList()); TerminalTree terminalTree = new TerminalTree();
terminalTree.setId(it.getId());
terminalTree.setName(it.getName());
terminalTree.setPid(it.getPids().split(StrUtil.COMMA)[LineBaseEnum.SUB_LEVEL.getCode()]);
terminalTree.setSort(it.getSort());
if(CollUtil.isNotEmpty(arr)) {
if (it.getId().equals(arr.get(0))) {
terminalTree.setLevel(LineBaseEnum.SUB_V_LEVEL.getCode());
}
}
return terminalTree;
}).collect(Collectors.toList());
//获取母线id
//List<String> ids = downVoltage.stream().map(TerminalTree::getId).collect(Collectors.toList());
List<TerminalTree> upList = TreedChildren(upTreeList, "变压器上节点设备树", subId);
voltage.put("upNode", upList);
List<TerminalTree> downList = TreedChildren(downVoltage, "变压器下节点设备树", subId);
voltage.put("downNode", downList);
return voltage;
}
public Map<String, Object> getGeneratrixOld(String subId, String id) {
Map<String, Object> voltage = new HashMap<>();
//先判断当前,变电站是否已添加了节点
PqsTflgass one = iPqsTflgassService.getOne(new LambdaQueryWrapper<PqsTflgass>()
.eq(PqsTflgass::getTfIndex, id));
//1.获取当前变电站下,所拥有的母线条数
List<TerminalTree> downVoltage = lineMapper.getvoltage(subId, 1);
//获取母线id
List<String> ids = downVoltage.stream().map(TerminalTree::getId).collect(Collectors.toList());
//查询节点是否绑定
List<PqsTflgass> pqsTflgasses = pqsTflgassMapper.selectFlgass(subId, ids);
String[][] arr = new String[pqsTflgasses.size()][2];
if (CollUtil.isNotEmpty(pqsTflgasses) && ids.size() > 2) {
for (int i = 0; i < pqsTflgasses.size(); i++) {
arr[i][0] = pqsTflgasses.get(i).getLogicBefore();
arr[i][1] = pqsTflgasses.get(i).getLogicNext();
}
}
voltage.put("bind", arr);
Stream<String> beforeStream = pqsTflgasses.stream().map(PqsTflgass::getLogicBefore);
Stream<String> nextStream = pqsTflgasses.stream().map(PqsTflgass::getLogicNext);
//合并节点,要是母线都存在,说明是跨变电站,反之是本变电站
List<String> merge = Stream.concat(beforeStream, nextStream)
.distinct()
.collect(Collectors.toList());
//查看已经绑定的母线
List<String> bindList = merge.stream().filter(x -> ids.contains(x)).collect(Collectors.toList());
//绑定母线,如有绑定的母线下不存在这个母线,说明是有跨变电站数据,则新增母线节点,为最底层节点往后,拼接
List<String> straddleList = merge.stream().filter(x -> !ids.contains(x)).collect(Collectors.toList());
//判断当前母线下是否还存在,没绑定节点
List<String> not = ids.stream().filter(x -> !bindList.contains(x)).collect(Collectors.toList());
/**
* 当母线节点+1等于去重之后的绑定节点说明节点已经全部绑定了
*
* 跨变电站
* 1.1当母线小于俩条时为跨
* 1.2当都所有节点都绑定时,只有最起始节点为跨
* 本变电站
* 1.1当有俩条时或者大于俩条时时为本
* 1.2当已绑定有跨变电站时,则上节点为最底层节点母线,下节点为没绑定的母线信息
*/
if (ObjectUtil.isNotNull(one)) {
List<String> collect = ids.stream().filter(x -> x.equals(one.getLogicBefore())).collect(Collectors.toList());
/** /**
* 当母线节点+1等于去重之后的绑定节点说明节点已经全部绑定了 *
* * 1.当母线大于俩条
* 跨变电站 * 2.当所有母线没有绑定是
* 1.1当母线小于俩条时为跨
* 1.2当都所有节点都绑定时,只有最起始节点为跨
* 本变电站
* 1.1当有俩条时或者大于俩条时时为本
* 1.2当已绑定有跨变电站时,则上节点为最底层节点母线,下节点为没绑定的母线信息
*/ */
if (collect.size() > 0) {
List<TerminalTree> upVOList;
if (straddleList.size() > 0 && not.size() > 0) {
String s = mostNext(pqsTflgasses);
upVOList = downVoltage.stream().filter(x -> s.equals(x.getId())).collect(Collectors.toList());
} else {
//上节点id
List<String> upIDs = pqsTflgasses.stream().map(PqsTflgass::getLogicBefore).collect(Collectors.toList());
upVOList = downVoltage.stream().filter(x -> !upIDs.contains(x.getId())).collect(Collectors.toList());
}
//下节点id
List<String> downIDs = pqsTflgasses.stream().map(PqsTflgass::getLogicNext).collect(Collectors.toList());
List<TerminalTree> downVOList = downVoltage.stream().filter(x -> !downIDs.contains(x.getId())).collect(Collectors.toList());
if (ObjectUtil.isNotNull(one)) { if (ObjectUtil.isNotNull(one)) {
List<String> collect = ids.stream().filter(x -> x.equals(one.getLogicBefore())).collect(Collectors.toList()); TerminalTree beforeTree = addTree(one.getLogicBefore());
/** TerminalTree nextTree = addTree(one.getLogicNext());
* 本 upVOList.add(beforeTree);
* 1.当母线大于俩条 downVOList.add(nextTree);
* 2.当所有母线没有绑定是 }
*/ List<TerminalTree> upList = TreedChildren(upVOList, "变压器上节点设备树", subId);
if (collect.size() > 0) { voltage.put("upNode", upList);
List<TerminalTree> downList = TreedChildren(downVOList, "变压器下节点设备树", subId);
voltage.put("downNode", downList);
return voltage;
} else {
//查询所有变电站下母线信息
List<TerminalTree> upVoltage = lineMapper.getvoltage(subId, 0);
if (merge.size() == ids.size()) {
String s = mostBefore(pqsTflgasses);
downVoltage = downVoltage.stream().filter(x -> x.getId().equals(s)).collect(Collectors.toList());
}
if (ObjectUtil.isNotNull(one)) {
TerminalTree beforeTree = addTree(one.getLogicBefore());
TerminalTree nextTree = addTree(one.getLogicNext());
upVoltage = upVoltage.stream().filter(x -> !x.getId().equals(beforeTree.getId())).collect(Collectors.toList());
upVoltage.add(beforeTree);
downVoltage.clear();
downVoltage.add(nextTree);
}
List<TerminalTree> upList = TreedChildren(upVoltage, "变压器上节点设备树", null);
voltage.put("upNode", upList);
List<TerminalTree> downList = TreedChildren(downVoltage, "变压器下节点设备树", subId);
voltage.put("downNode", downList);
return voltage;
}
} else {
//判断是否已经全部绑定
String chain = chain(pqsTflgasses);
String chain2 = chain2(pqsTflgasses);
if (StrUtil.isNotBlank(chain) && not.size() == 0 && pqsTflgasses.size() + 1 != ids.size() && straddleList.size() == 0
|| StrUtil.isNotBlank(chain2) && not.size() == 0 && pqsTflgasses.size() + 1 != ids.size() && straddleList.size() == 0) {
List<String> logicBefore = pqsTflgasses.stream().map(PqsTflgass::getLogicBefore).collect(Collectors.toList());
List<String> logicNext = pqsTflgasses.stream().map(PqsTflgass::getLogicNext).collect(Collectors.toList());
List<TerminalTree> up = downVoltage.stream().filter(x -> !logicBefore.contains(x.getId())).collect(Collectors.toList());
List<TerminalTree> upList = TreedChildren(up, "变压器上节点设备树", subId);
voltage.put("upNode", upList);
List<TerminalTree> down = downVoltage.stream().filter(x -> !logicNext.contains(x.getId())).collect(Collectors.toList());
List<TerminalTree> downList = TreedChildren(down, "变压器下节点设备树", subId);
voltage.put("downNode", downList);
return voltage;
} else {
if (downVoltage.size() > 1 && straddleList.size() == 0 && bindList.size() != ids.size()
|| straddleList.size() > 0 && not.size() > 0
) {
List<TerminalTree> upVOList; List<TerminalTree> upVOList;
if (straddleList.size() > 0 && not.size() > 0) { if (straddleList.size() > 0 && not.size() > 0) {
String s = mostNext(pqsTflgasses); String s = mostNext(pqsTflgasses);
@@ -263,20 +387,24 @@ public class PqsTransformerServiceImpl extends ServiceImpl<PqsTransformerMapper,
//下节点id //下节点id
List<String> downIDs = pqsTflgasses.stream().map(PqsTflgass::getLogicNext).collect(Collectors.toList()); List<String> downIDs = pqsTflgasses.stream().map(PqsTflgass::getLogicNext).collect(Collectors.toList());
List<TerminalTree> downVOList = downVoltage.stream().filter(x -> !downIDs.contains(x.getId())).collect(Collectors.toList());
if (ObjectUtil.isNotNull(one)) { List<TerminalTree> downVOList = downVoltage.stream().filter(x -> !downIDs.contains(x.getId())).collect(Collectors.toList());
TerminalTree beforeTree = addTree(one.getLogicBefore()); if (not.size() == 1) {
TerminalTree nextTree = addTree(one.getLogicNext()); List<String> logicBefore = pqsTflgasses.stream().map(PqsTflgass::getLogicBefore).collect(Collectors.toList());
upVOList.add(beforeTree); downVOList = downVOList.stream().filter(x -> !logicBefore.contains(x.getId())).collect(Collectors.toList());
downVOList.add(nextTree);
} }
List<TerminalTree> upList = TreedChildren(upVOList, "变压器上节点设备树", subId); List<TerminalTree> upList = TreedChildren(upVOList, "变压器上节点设备树", subId);
voltage.put("upNode", upList); voltage.put("upNode", upList);
List<TerminalTree> downList = TreedChildren(downVOList, "变压器下节点设备树", subId); List<TerminalTree> downList = TreedChildren(downVOList, "变压器下节点设备树", subId);
voltage.put("downNode", downList); voltage.put("downNode", downList);
return voltage; }
} else {
/**
* 跨
* 1.当母线小于2条跨
* 2.当所有母线都绑定为跨
*/
else {
//查询所有变电站下母线信息 //查询所有变电站下母线信息
List<TerminalTree> upVoltage = lineMapper.getvoltage(subId, 0); List<TerminalTree> upVoltage = lineMapper.getvoltage(subId, 0);
if (merge.size() == ids.size()) { if (merge.size() == ids.size()) {
@@ -284,304 +412,231 @@ public class PqsTransformerServiceImpl extends ServiceImpl<PqsTransformerMapper,
downVoltage = downVoltage.stream().filter(x -> x.getId().equals(s)).collect(Collectors.toList()); downVoltage = downVoltage.stream().filter(x -> x.getId().equals(s)).collect(Collectors.toList());
} }
if (ObjectUtil.isNotNull(one)) { //下节点id
TerminalTree beforeTree = addTree(one.getLogicBefore()); List<String> downIDs = pqsTflgasses.stream().map(PqsTflgass::getLogicNext).collect(Collectors.toList());
TerminalTree nextTree = addTree(one.getLogicNext()); List<TerminalTree> downVOList = downVoltage.stream().filter(x -> !downIDs.contains(x.getId())).collect(Collectors.toList());
upVoltage = upVoltage.stream().filter(x -> !x.getId().equals(beforeTree.getId())).collect(Collectors.toList());
upVoltage.add(beforeTree);
downVoltage.clear();
downVoltage.add(nextTree);
}
List<TerminalTree> upList = TreedChildren(upVoltage, "变压器上节点设备树", null); List<TerminalTree> upList = TreedChildren(upVoltage, "变压器上节点设备树", null);
voltage.put("upNode", upList); voltage.put("upNode", upList);
List<TerminalTree> downList = TreedChildren(downVoltage, "变压器下节点设备树", subId); List<TerminalTree> downList = TreedChildren(downVOList, "变压器下节点设备树", subId);
voltage.put("downNode", downList); voltage.put("downNode", downList);
return voltage; return voltage;
} }
}
}
return voltage;
}
@Override
public List<TerminalTree> getTransformerTree() {
List<TerminalTree> terminalTrees = this.baseMapper.listTransformer();
return TreedChildren(terminalTrees, "变压器设备树", null);
}
@Override
public List<EntityLogicDTO> getLogic() {
return pqsTflgassMapper.getLogic();
}
/**
* 获取全部子节点
*
* @author cdf
* @date 2021/7/19
*/
public List<TerminalTree> getChildren(TerminalTree item, List<TerminalTree> all) {
return all.stream().filter(allItem -> allItem.getPid().equals(item.getId())).collect(Collectors.toList());
}
/**
* 初始化设备树
*
* @param children 子节点
* @param name 节点名称
* @param subId 不为空则只展示,当前变电站节点的信息,为空则展示所有信息
* @return
*/
public List<TerminalTree> TreedChildren(List<TerminalTree> children, String name, String subId) {
List<TerminalTree> taiZhang = new ArrayList<>();
List<TerminalTree> allList = lineMapper.getAllList();
List<TerminalTree> gdList;
List<TerminalTree> subList;
List<TerminalTree> provinceList;
if (StrUtil.isBlank(subId)) {
subList = allList.stream().filter(item -> item.getLevel().equals(LineBaseEnum.SUB_LEVEL.getCode())).sorted(Comparator.comparing(TerminalTree::getSort)).collect(Collectors.toList());
gdList = allList.stream().filter(item -> item.getLevel().equals(LineBaseEnum.GD_LEVEL.getCode())).sorted(Comparator.comparing(TerminalTree::getSort)).collect(Collectors.toList());
provinceList = lineMapper.getProvinceList(null, 0);
} else {
subList = allList.stream().filter(item -> item.getLevel().equals(LineBaseEnum.SUB_LEVEL.getCode())
&& item.getId().equals(subId)
).sorted(Comparator.comparing(TerminalTree::getSort)).collect(Collectors.toList());
gdList = allList.stream().filter(item -> item.getLevel().equals(LineBaseEnum.GD_LEVEL.getCode())
&& item.getId().equals(subList.get(0).getPid())
).sorted(Comparator.comparing(TerminalTree::getSort)).collect(Collectors.toList());
provinceList = lineMapper.getProvinceList(Arrays.asList(gdList.get(0).getPid()), 1);
}
List<TerminalTree> terminal = children.stream().sorted(Comparator.comparing(TerminalTree::getSort)).collect(Collectors.toList());
subList.forEach(sub -> sub.setChildren(getChildren(sub, terminal)));
gdList.forEach(gd -> gd.setChildren(getChildren(gd, subList)));
provinceList.forEach(province -> province.setChildren(getChildren(province, gdList)));
if (CollectionUtil.isNotEmpty(allList)) {
TerminalTree terminalTree = new TerminalTree();
terminalTree.setId("9999999");
terminalTree.setLevel(0);
terminalTree.setName(name);
if (CollectionUtil.isNotEmpty(provinceList)) {
terminalTree.setChildren(provinceList);
}
taiZhang.add(terminalTree);
}
return taiZhang;
}
/**
* 查找最顶层节点信息
*
* @param pqsTflgasses
* @return
*/
private static String mostBefore(List<PqsTflgass> pqsTflgasses) {
String logicBefore = null;
for (PqsTflgass pqsTflgass : pqsTflgasses) {
//根据获取的的上节点判断是否存在,这上节点是否是尾节点
if (ObjectUtil.isNull(logicBefore)) {
logicBefore = pqsTflgass.getLogicBefore();
} else { } else {
//判断是否已经全部绑定 while (true) {
String chain = chain(pqsTflgasses); for (int i1 = 0; i1 < pqsTflgasses.size(); i1++) {
String chain2 = chain2(pqsTflgasses); String logicNext = pqsTflgasses.get(i1).getLogicNext();
if (StrUtil.isNotBlank(chain) && not.size() == 0&& pqsTflgasses.size()+1!=ids.size()&&straddleList.size()==0 if (logicBefore.equals(logicNext)) {
|| StrUtil.isNotBlank(chain2) && not.size() == 0&& pqsTflgasses.size()+1!=ids.size()&&straddleList.size()==0) { logicBefore = pqsTflgasses.get(i1).getLogicBefore();
List<String> logicBefore = pqsTflgasses.stream().map(PqsTflgass::getLogicBefore).collect(Collectors.toList()); break;
List<String> logicNext = pqsTflgasses.stream().map(PqsTflgass::getLogicNext).collect(Collectors.toList());
List<TerminalTree> up = downVoltage.stream().filter(x -> !logicBefore.contains(x.getId())).collect(Collectors.toList());
List<TerminalTree> upList = TreedChildren(up, "变压器上节点设备树", subId);
voltage.put("upNode", upList);
List<TerminalTree> down = downVoltage.stream().filter(x -> !logicNext.contains(x.getId())).collect(Collectors.toList());
List<TerminalTree> downList = TreedChildren(down, "变压器下节点设备树", subId);
voltage.put("downNode", downList);
return voltage;
} else {
if (downVoltage.size() > 1 && straddleList.size() == 0 && bindList.size() != ids.size()
|| straddleList.size() > 0 && not.size() > 0
) {
List<TerminalTree> upVOList;
if (straddleList.size() > 0 && not.size() > 0) {
String s = mostNext(pqsTflgasses);
upVOList = downVoltage.stream().filter(x -> s.equals(x.getId())).collect(Collectors.toList());
} else { } else {
//上节点id if (i1 == pqsTflgasses.size()) {
List<String> upIDs = pqsTflgasses.stream().map(PqsTflgass::getLogicBefore).collect(Collectors.toList()); break;
upVOList = downVoltage.stream().filter(x -> !upIDs.contains(x.getId())).collect(Collectors.toList()); }
} }
//下节点id
List<String> downIDs = pqsTflgasses.stream().map(PqsTflgass::getLogicNext).collect(Collectors.toList());
List<TerminalTree> downVOList = downVoltage.stream().filter(x -> !downIDs.contains(x.getId())).collect(Collectors.toList());
if(not.size() ==1){
List<String> logicBefore = pqsTflgasses.stream().map(PqsTflgass::getLogicBefore).collect(Collectors.toList());
downVOList = downVOList.stream().filter(x -> !logicBefore.contains(x.getId())).collect(Collectors.toList());
}
List<TerminalTree> upList = TreedChildren(upVOList, "变压器上节点设备树", subId);
voltage.put("upNode", upList);
List<TerminalTree> downList = TreedChildren(downVOList, "变压器下节点设备树", subId);
voltage.put("downNode", downList);
}
/**
* 跨
* 1.当母线小于2条跨
* 2.当所有母线都绑定为跨
*/
else {
//查询所有变电站下母线信息
List<TerminalTree> upVoltage = lineMapper.getvoltage(subId, 0);
if (merge.size() == ids.size()) {
String s = mostBefore(pqsTflgasses);
downVoltage = downVoltage.stream().filter(x -> x.getId().equals(s)).collect(Collectors.toList());
}
//下节点id
List<String> downIDs = pqsTflgasses.stream().map(PqsTflgass::getLogicNext).collect(Collectors.toList());
List<TerminalTree> downVOList = downVoltage.stream().filter(x -> !downIDs.contains(x.getId())).collect(Collectors.toList());
List<TerminalTree> upList = TreedChildren(upVoltage, "变压器上节点设备树", null);
voltage.put("upNode", upList);
List<TerminalTree> downList = TreedChildren(downVOList, "变压器下节点设备树", subId);
voltage.put("downNode", downList);
return voltage;
} }
break;
} }
} }
return voltage;
} }
return logicBefore;
}
@Override /**
public List<TerminalTree> getTransformerTree() { * 查找最底层节点信息
List<TerminalTree> terminalTrees = this.baseMapper.listTransformer(); *
return TreedChildren(terminalTrees, "变压器设备树", null); * @param pqsTflgasses
} * @return
*/
@Override private static String mostNext(List<PqsTflgass> pqsTflgasses) {
public List<EntityLogicDTO> getLogic() { String logicNext = null;
return pqsTflgassMapper.getLogic(); for (PqsTflgass pqsTflgass : pqsTflgasses) {
} //根据获取的的上节点判断是否存在,这上节点是否是尾节点
if (ObjectUtil.isNull(logicNext)) {
/** logicNext = pqsTflgass.getLogicNext();
* 获取全部子节点
*
* @author cdf
* @date 2021/7/19
*/
public List<TerminalTree> getChildren(TerminalTree item, List<TerminalTree> all) {
return all.stream().filter(allItem -> allItem.getPid().equals(item.getId())).collect(Collectors.toList());
}
/**
* 初始化设备树
*
* @param children 子节点
* @param name 节点名称
* @param subId 不为空则只展示,当前变电站节点的信息,为空则展示所有信息
* @return
*/
public List<TerminalTree> TreedChildren(List<TerminalTree> children, String name, String subId) {
List<TerminalTree> taiZhang = new ArrayList<>();
List<TerminalTree> allList = lineMapper.getAllList();
List<TerminalTree> gdList;
List<TerminalTree> subList;
List<TerminalTree> provinceList;
if (StrUtil.isBlank(subId)) {
subList = allList.stream().filter(item -> item.getLevel().equals(LineBaseEnum.SUB_LEVEL.getCode())).sorted(Comparator.comparing(TerminalTree::getSort)).collect(Collectors.toList());
gdList = allList.stream().filter(item -> item.getLevel().equals(LineBaseEnum.GD_LEVEL.getCode())).sorted(Comparator.comparing(TerminalTree::getSort)).collect(Collectors.toList());
provinceList = lineMapper.getProvinceList(null, 0);
} else { } else {
subList = allList.stream().filter(item -> item.getLevel().equals(LineBaseEnum.SUB_LEVEL.getCode()) while (true) {
&& item.getId().equals(subId) for (int i1 = 0; i1 < pqsTflgasses.size(); i1++) {
).sorted(Comparator.comparing(TerminalTree::getSort)).collect(Collectors.toList()); String logicBefore = pqsTflgasses.get(i1).getLogicBefore();
gdList = allList.stream().filter(item -> item.getLevel().equals(LineBaseEnum.GD_LEVEL.getCode()) if (logicNext.equals(logicBefore)) {
&& item.getId().equals(subList.get(0).getPid()) logicNext = pqsTflgasses.get(i1).getLogicNext();
).sorted(Comparator.comparing(TerminalTree::getSort)).collect(Collectors.toList()); break;
provinceList = lineMapper.getProvinceList(Arrays.asList(gdList.get(0).getPid()), 1); } else {
} if (i1 == pqsTflgasses.size()) {
List<TerminalTree> terminal = children.stream().sorted(Comparator.comparing(TerminalTree::getSort)).collect(Collectors.toList());
subList.forEach(sub -> sub.setChildren(getChildren(sub, terminal)));
gdList.forEach(gd -> gd.setChildren(getChildren(gd, subList)));
provinceList.forEach(province -> province.setChildren(getChildren(province, gdList)));
if (CollectionUtil.isNotEmpty(allList)) {
TerminalTree terminalTree = new TerminalTree();
terminalTree.setId("9999999");
terminalTree.setLevel(0);
terminalTree.setName(name);
if (CollectionUtil.isNotEmpty(provinceList)) {
terminalTree.setChildren(provinceList);
}
taiZhang.add(terminalTree);
}
return taiZhang;
}
/**
* 查找最顶层节点信息
*
* @param pqsTflgasses
* @return
*/
private static String mostBefore(List<PqsTflgass> pqsTflgasses) {
String logicBefore = null;
for (PqsTflgass pqsTflgass : pqsTflgasses) {
//根据获取的的上节点判断是否存在,这上节点是否是尾节点
if (ObjectUtil.isNull(logicBefore)) {
logicBefore = pqsTflgass.getLogicBefore();
} else {
while (true) {
for (int i1 = 0; i1 < pqsTflgasses.size(); i1++) {
String logicNext = pqsTflgasses.get(i1).getLogicNext();
if (logicBefore.equals(logicNext)) {
logicBefore = pqsTflgasses.get(i1).getLogicBefore();
break; break;
} else {
if (i1 == pqsTflgasses.size()) {
break;
}
} }
} }
break;
} }
break;
} }
} }
return logicBefore;
} }
return logicNext;
}
/** /**
* 查找最底层节点信息 * 判断是否已经成为链行
* *
* @param pqsTflgasses * @param pqsTflgasses
* @return * @return
*/ */
private static String mostNext(List<PqsTflgass> pqsTflgasses) { private static String chain(List<PqsTflgass> pqsTflgasses) {
String logicNext = null; if (pqsTflgasses.size() < 2) {
for (PqsTflgass pqsTflgass : pqsTflgasses) { return null;
//根据获取的的上节点判断是否存在,这上节点是否是尾节点 }
if (ObjectUtil.isNull(logicNext)) { String logicNext = null;
logicNext = pqsTflgass.getLogicNext(); for (PqsTflgass pqsTflgass : pqsTflgasses) {
} else { //根据获取的的下节点判断是否存在,这下节点是否是首节点
while (true) { if (ObjectUtil.isNull(logicNext)) {
for (int i1 = 0; i1 < pqsTflgasses.size(); i1++) { logicNext = pqsTflgass.getLogicNext();
String logicBefore = pqsTflgasses.get(i1).getLogicBefore(); } else {
if (logicNext.equals(logicBefore)) { while (true) {
logicNext = pqsTflgasses.get(i1).getLogicNext(); for (int i1 = 0; i1 < pqsTflgasses.size(); i1++) {
break; String logicBefore = pqsTflgasses.get(i1).getLogicBefore();
} else { if (logicNext.equals(logicBefore)) {
if (i1 == pqsTflgasses.size()) { logicNext = pqsTflgasses.get(i1).getLogicNext();
break; break;
} } else {
if (i1 == pqsTflgasses.size() - 1) {
return logicNext;
} }
} }
break;
} }
break;
} }
}
return logicNext;
}
/**
* 判断是否已经成为链行
*
* @param pqsTflgasses
* @return
*/
private static String chain(List<PqsTflgass> pqsTflgasses) {
if(pqsTflgasses.size()<2){
return null;
} }
String logicNext = null; }
for (PqsTflgass pqsTflgass : pqsTflgasses) { return logicNext;
//根据获取的的下节点判断是否存在,这下节点是否是首节点 }
if (ObjectUtil.isNull(logicNext)) {
logicNext = pqsTflgass.getLogicNext(); private static String chain2(List<PqsTflgass> pqsTflgasses) {
} else { if (pqsTflgasses.size() < 2) {
while (true) { return null;
for (int i1 = 0; i1 < pqsTflgasses.size(); i1++) { }
String logicBefore = pqsTflgasses.get(i1).getLogicBefore(); String logicBefore = null;
if (logicNext.equals(logicBefore)) { for (PqsTflgass pqsTflgass : pqsTflgasses) {
logicNext = pqsTflgasses.get(i1).getLogicNext(); //根据获取的的下节点判断是否存在,这下节点是否是首节点
break; if (ObjectUtil.isNull(logicBefore)) {
} else { logicBefore = pqsTflgass.getLogicBefore();
if (i1 == pqsTflgasses.size() - 1) { } else {
return logicNext; while (true) {
} for (int i1 = 0; i1 < pqsTflgasses.size(); i1++) {
String logicNext = pqsTflgasses.get(i1).getLogicNext();
if (logicBefore.equals(logicNext)) {
logicBefore = pqsTflgasses.get(i1).getLogicBefore();
break;
} else {
if (i1 == pqsTflgasses.size() - 1) {
return logicBefore;
} }
} }
break;
} }
break;
} }
}
return logicNext;
}
private static String chain2(List<PqsTflgass> pqsTflgasses) {
if(pqsTflgasses.size()<2){
return null;
} }
String logicBefore = null;
for (PqsTflgass pqsTflgass : pqsTflgasses) {
//根据获取的的下节点判断是否存在,这下节点是否是首节点
if (ObjectUtil.isNull(logicBefore)) {
logicBefore = pqsTflgass.getLogicBefore();
} else {
while (true) {
for (int i1 = 0; i1 < pqsTflgasses.size(); i1++) {
String logicNext = pqsTflgasses.get(i1).getLogicNext();
if (logicBefore.equals(logicNext)) {
logicBefore = pqsTflgasses.get(i1).getLogicBefore();
break;
} else {
if (i1 == pqsTflgasses.size() - 1) {
return logicBefore;
}
}
}
break;
}
}
}
return logicBefore;
} }
return logicBefore;
}
/** /**
* 根据母线获取信息 * 根据母线获取信息
* *
* @param id * @param id
* @return * @return
*/ */
public TerminalTree addTree(String id) { public TerminalTree addTree(String id) {
List<TerminalTree> getvoltage = lineMapper.getvoltage(id, 2); List<TerminalTree> getvoltage = lineMapper.getvoltage(id, 2);
getvoltage.get(0).setLevel(5); getvoltage.get(0).setLevel(5);
return getvoltage.get(0); return getvoltage.get(0);
} }

View File

@@ -61,6 +61,7 @@ public class HistoryResultController extends BaseController {
public HttpResult<List<HistoryDataResultVO>> getHistoryResult(@RequestBody @Validated HistoryParam historyParam) { public HttpResult<List<HistoryDataResultVO>> getHistoryResult(@RequestBody @Validated HistoryParam historyParam) {
String methodDescribe = getMethodDescribe("getHistoryResult"); String methodDescribe = getMethodDescribe("getHistoryResult");
List<HistoryDataResultVO> list; List<HistoryDataResultVO> list;
//针对河北现场特殊处理pmswifi_开头监测点为无线装置需要查询influxdb,其他测点查询oracle
if (HistoryDataSource == 1 && !historyParam.getLineId()[0].contains("pmswifi_")) { if (HistoryDataSource == 1 && !historyParam.getLineId()[0].contains("pmswifi_")) {
list = oracleResultService.getHistoryResult(historyParam); list = oracleResultService.getHistoryResult(historyParam);
} else { } else {

View File

@@ -5,6 +5,7 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.TimeInterval;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.njcn.common.pojo.constant.BizParamConstant; import com.njcn.common.pojo.constant.BizParamConstant;
@@ -54,6 +55,9 @@ import lombok.AllArgsConstructor;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
@@ -62,8 +66,11 @@ import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.Instant; import java.time.Instant;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@@ -102,16 +109,24 @@ public class HistoryResultServiceImpl implements HistoryResultService {
private final RStatDataVDMapper dataVDMapper; private final RStatDataVDMapper dataVDMapper;
private final RStatDataHarmRateVDMapper dataHarmRateVDMapper; private final RStatDataHarmRateVDMapper dataHarmRateVDMapper;
private final RStatDataHarmRateIDMapper dataHarmRateIDMapper; private final RStatDataHarmRateIDMapper dataHarmRateIDMapper;
@Autowired
@Qualifier("asyncExecutor")
private Executor asyncExecutor;
@Override @Override
public List<HistoryDataResultVO> getHistoryResult(HistoryParam historyParam) { public List<HistoryDataResultVO> getHistoryResult(HistoryParam historyParam) {
System.out.println("begin============================="+ LocalDateTime.now());
TimeInterval timeInterval = new TimeInterval();
List<HistoryDataResultVO> historyDataResultVOList = new ArrayList<>(); List<HistoryDataResultVO> historyDataResultVOList = new ArrayList<>();
//获取监测点 //获取监测点
String[] points = historyParam.getLineId(); String[] points = historyParam.getLineId();
Integer number = 0;
for (int i = 0; i < points.length; i++) { for (int i = 0; i < points.length; i++) {
HistoryDataResultVO historyDataResultVO; long a = timeInterval.intervalMs();
List<EventDetail> eventDetailList = eventDetailFeignClient.getEventDetailData(points[i], historyParam.getSearchBeginTime(), historyParam.getSearchEndTime()).getData(); List<EventDetail> eventDetailList = eventDetailFeignClient.getEventDetailData(points[i], historyParam.getSearchBeginTime(), historyParam.getSearchEndTime()).getData();
List<EventDetailVO> eventDetailVOList = new ArrayList<>(); List<EventDetailVO> eventDetailVOList = new ArrayList<>();
if (!eventDetailList.isEmpty()) { if (!eventDetailList.isEmpty()) {
for (EventDetail eventdetail : eventDetailList) { for (EventDetail eventdetail : eventDetailList) {
@@ -122,9 +137,21 @@ public class HistoryResultServiceImpl implements HistoryResultService {
eventDetailVOList.add(eventDetailVO); eventDetailVOList.add(eventDetailVO);
} }
} }
//获取监测点的数据单位kV还是v kW还是w
PqsDeviceUnit pqsDeviceUnit = commTerminalGeneralClient.lineUnitDetail(points[i]).getData();
//获取监测点信息
LineDevGetDTO lineDetailDataVO = commTerminalGeneralClient.getMonitorDetail(points[i]).getData();
//获取限值
Overlimit overlimit = commTerminalGeneralClient.getOverLimitData(points[i]).getData();
long b = timeInterval.intervalMs();
System.out.println("feign调用"+(b-a));
//获取指标 //获取指标
String[] contions = historyParam.getCondition(); String[] contions = historyParam.getCondition();
List<CompletableFuture<Void>> futures = new ArrayList<>();
for (int j = 0; j < contions.length; j++) { for (int j = 0; j < contions.length; j++) {
Integer number = 0;
if ("40".equals(contions[j]) || "41".equals(contions[j]) || "42".equals(contions[j]) || "43".equals(contions[j]) if ("40".equals(contions[j]) || "41".equals(contions[j]) || "42".equals(contions[j]) || "43".equals(contions[j])
|| "44".equals(contions[j]) || "45".equals(contions[j]) || "50".equals(contions[j]) || "51".equals(contions[j]) || "44".equals(contions[j]) || "45".equals(contions[j]) || "50".equals(contions[j]) || "51".equals(contions[j])
|| "52".equals(contions[j])) { || "52".equals(contions[j])) {
@@ -133,20 +160,33 @@ public class HistoryResultServiceImpl implements HistoryResultService {
if ("46".equals(contions[j]) || "47".equals(contions[j]) || "48".equals(contions[j]) || "49".equals(contions[j])) { if ("46".equals(contions[j]) || "47".equals(contions[j]) || "48".equals(contions[j]) || "49".equals(contions[j])) {
number = historyParam.getInHarmonic(); number = historyParam.getInHarmonic();
} }
historyDataResultVO = getCondition(historyParam.getSearchBeginTime(), historyParam.getSearchEndTime(), points[i], contions[j], number, historyParam.getValueType(), historyParam.getPtType()); //每个指标独立一个线程去查库,针对现场网络环境比较复杂的场景,正常场景看不太出来效果
/* if (points.length == 1 && j == 0) { asyncMethodWithCustomExecutor(contions[j],number,historyParam,eventDetailVOList,points[i],pqsDeviceUnit,lineDetailDataVO,overlimit,historyDataResultVOList,futures);
historyDataResultVO.setEventDetail(eventDetailVOList);
} else if (points.length > 1) {
historyDataResultVO.setEventDetail(eventDetailVOList);
}*/
historyDataResultVO.setEventDetail(eventDetailVOList);
historyDataResultVOList.add(historyDataResultVO);
} }
// 等待所有任务完成
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
} }
System.out.println("end============================="+LocalDateTime.now());
System.out.println("共计耗时:"+timeInterval.intervalMs()/1000.0);
return historyDataResultVOList; return historyDataResultVOList;
} }
//处理指标查询
public void asyncMethodWithCustomExecutor(String target,Integer number,HistoryParam historyParam,List<EventDetailVO> eventDetailVOList,String point,PqsDeviceUnit pqsDeviceUnit,LineDevGetDTO lineDetailDataVO,Overlimit overlimit,List<HistoryDataResultVO> historyDataResultVOList,List<CompletableFuture<Void>> futures) {
CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
HistoryDataResultVO historyDataResultVO = getCondition(historyParam.getSearchBeginTime(), historyParam.getSearchEndTime(), point, target, number, historyParam.getValueType(), historyParam.getPtType(),pqsDeviceUnit,lineDetailDataVO,overlimit);
historyDataResultVO.setEventDetail(eventDetailVOList);
synchronized (historyDataResultVOList) { // 同步块保证线程安全
historyDataResultVOList.add(historyDataResultVO);
}
System.out.println("执行异步任务,线程名:" + Thread.currentThread().getName());
}, asyncExecutor);
futures.add(future);
}
@Override @Override
public List<HistoryDataResultVO> getHistoryLineData(NormHistoryParam normHistoryParam) { public List<HistoryDataResultVO> getHistoryLineData(NormHistoryParam normHistoryParam) {
List<HistoryDataResultVO> historyDataResultVOList = new ArrayList<>(); List<HistoryDataResultVO> historyDataResultVOList = new ArrayList<>();
@@ -160,9 +200,9 @@ public class HistoryResultServiceImpl implements HistoryResultService {
* 查询稳态数据分析 * 查询稳态数据分析
*/ */
@SneakyThrows @SneakyThrows
private HistoryDataResultVO getCondition(String startTime, String endTime, String lineId, String contion, Integer number, Integer valueType, Integer ptType) { public HistoryDataResultVO getCondition(String startTime, String endTime, String lineId, String contion, Integer number, Integer valueType, Integer ptType,PqsDeviceUnit pqsDeviceUnit,LineDevGetDTO lineDetailDataVO,Overlimit overlimit) {
HistoryDataResultVO historyDataResultVO = new HistoryDataResultVO(); HistoryDataResultVO historyDataResultVO = new HistoryDataResultVO();
QueryResultLimitVO queryResultLimitVO = getQueryResult(startTime, endTime, lineId, contion, number, valueType, ptType); QueryResultLimitVO queryResultLimitVO = getQueryResult(startTime, endTime, lineId, contion, number, valueType, ptType,pqsDeviceUnit,lineDetailDataVO,overlimit);
List<HarmonicHistoryData> harmonicHistoryDataList = queryResultLimitVO.getHarmonicHistoryDataList(); List<HarmonicHistoryData> harmonicHistoryDataList = queryResultLimitVO.getHarmonicHistoryDataList();
BeanUtil.copyProperties(queryResultLimitVO, historyDataResultVO); BeanUtil.copyProperties(queryResultLimitVO, historyDataResultVO);
//时间轴 //时间轴
@@ -207,7 +247,6 @@ public class HistoryResultServiceImpl implements HistoryResultService {
} else { } else {
//按时间分组 //按时间分组
Map<Instant, List<HarmonicHistoryData>> map = harmonicHistoryDataList.stream().collect(Collectors.groupingBy(HarmonicHistoryData::getTime, TreeMap::new, Collectors.toList())); Map<Instant, List<HarmonicHistoryData>> map = harmonicHistoryDataList.stream().collect(Collectors.groupingBy(HarmonicHistoryData::getTime, TreeMap::new, Collectors.toList()));
Float maxI = null; Float maxI = null;
Float minI = null; Float minI = null;
for (Map.Entry<Instant, List<HarmonicHistoryData>> entry : map.entrySet()) { for (Map.Entry<Instant, List<HarmonicHistoryData>> entry : map.entrySet()) {
@@ -241,13 +280,10 @@ public class HistoryResultServiceImpl implements HistoryResultService {
objects[3] = c; objects[3] = c;
maxI = max(maxI, c.floatValue()); maxI = max(maxI, c.floatValue());
minI = min(minI, c.floatValue()); minI = min(minI, c.floatValue());
} }
} }
List<Object> list = new ArrayList<>(Arrays.asList(objects)); List<Object> list = new ArrayList<>(Arrays.asList(objects));
objectListData.add(list); objectListData.add(list);
} }
historyDataResultVO.setMaxValue(maxI); historyDataResultVO.setMaxValue(maxI);
@@ -256,7 +292,6 @@ public class HistoryResultServiceImpl implements HistoryResultService {
historyDataResultVO.setLowerLimit(queryResultLimitVO.getLowerLimit()); historyDataResultVO.setLowerLimit(queryResultLimitVO.getLowerLimit());
historyDataResultVO.setValue(objectListData); historyDataResultVO.setValue(objectListData);
} }
} else { } else {
return historyDataResultVO; return historyDataResultVO;
} }
@@ -284,19 +319,12 @@ public class HistoryResultServiceImpl implements HistoryResultService {
return ding; return ding;
} }
private QueryResultLimitVO getQueryResult(String startTime, String endTime, String lineId, String contion, Integer number, Integer valueType, Integer ptType) { private QueryResultLimitVO getQueryResult(String startTime, String endTime, String lineId, String contion, Integer number, Integer valueType, Integer ptType,PqsDeviceUnit pqsDeviceUnit,LineDevGetDTO lineDetailDataVO,Overlimit overlimit) {
PqsDeviceUnit pqsDeviceUnit = commTerminalGeneralClient.lineUnitDetail(lineId).getData();
QueryResultLimitVO queryResultLimitVO = new QueryResultLimitVO(); QueryResultLimitVO queryResultLimitVO = new QueryResultLimitVO();
if (!lineId.isEmpty()) { if (!lineId.isEmpty()) {
Float topLimit = 0f; Float topLimit = 0f;
Float lowerLimit = 0f; Float lowerLimit = 0f;
//获取监测点信息
LineDevGetDTO lineDetailDataVO = commTerminalGeneralClient.getMonitorDetail(lineId).getData();
//获取限值
Overlimit overlimit = commTerminalGeneralClient.getOverLimitData(lineId).getData();
if (Objects.isNull(overlimit)) { if (Objects.isNull(overlimit)) {
//对配网没有限值的统一处理 //对配网没有限值的统一处理
DictData dictData = dicDataFeignClient.getDicDataById(lineDetailDataVO.getVoltageLevel()).getData(); DictData dictData = dicDataFeignClient.getDicDataById(lineDetailDataVO.getVoltageLevel()).getData();
@@ -305,7 +333,6 @@ public class HistoryResultServiceImpl implements HistoryResultService {
overlimit = COverlimitUtil.globalAssemble(voltageLevel, 10f, 10f, shortVal, 1, 1); overlimit = COverlimitUtil.globalAssemble(voltageLevel, 10f, 10f, shortVal, 1, 1);
} }
//组装sql语句 //组装sql语句
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(InfluxDBTableConstant.TIME + " >= '").append(startTime).append(InfluxDBTableConstant.START_TIME).append("' and ").append(InfluxDBTableConstant.TIME).append(" <= '").append(endTime).append(InfluxDBTableConstant.END_TIME).append("' and ("); stringBuilder.append(InfluxDBTableConstant.TIME + " >= '").append(startTime).append(InfluxDBTableConstant.START_TIME).append("' and ").append(InfluxDBTableConstant.TIME).append(" <= '").append(endTime).append(InfluxDBTableConstant.END_TIME).append("' and (");