|
|
@ -13,6 +13,7 @@ import com.qs.serve.modules.bms.mapper.BmsCenterExtendBuildMapper; |
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
/** |
|
|
@ -34,9 +35,9 @@ public class BmsCenterExtendBuildServiceImpl extends ServiceImpl<BmsCenterExtend |
|
|
|
this.recursionBuildExtendCenter(treeVoList, buildList, null); |
|
|
|
} |
|
|
|
|
|
|
|
private void recursionBuildExtendCenter(List<BmsCenterExtendTreeVo> treeVoList, List<BmsCenterExtendBuild> buildList, BmsCenterExtendBuild parent) { |
|
|
|
private void recursionBuildExtendCenter(List<BmsCenterExtendTreeVo> allTreeList, List<BmsCenterExtendBuild> buildList, BmsCenterExtendBuild parent) { |
|
|
|
//存放上级对象
|
|
|
|
for (BmsCenterExtendTreeVo source : treeVoList) { |
|
|
|
for (BmsCenterExtendTreeVo source : allTreeList) { |
|
|
|
BmsCenterExtendBuild build = new BmsCenterExtendBuild(); |
|
|
|
build.setBuildType(CenterExtendBuildType.TREE); |
|
|
|
build.setSourceId(source.getSourceId()); |
|
|
@ -63,28 +64,67 @@ public class BmsCenterExtendBuildServiceImpl extends ServiceImpl<BmsCenterExtend |
|
|
|
//判断是否最后一级
|
|
|
|
if(source.getChildren()==null||source.getChildren().size()==0){ |
|
|
|
//自下而上查询返回所有占比
|
|
|
|
BmsCenterExtendBuild buildData = new BmsCenterExtendBuild(); |
|
|
|
buildData.setBuildType(CenterExtendBuildType.DATA); |
|
|
|
buildData.setSourceId(source.getSourceId()); |
|
|
|
buildData.setCenterType(source.getCenterType()); |
|
|
|
buildData.setCenterId(source.getCenterId()); |
|
|
|
buildData.setCenterCode(source.getCenterCode()); |
|
|
|
buildData.setCenterName(source.getCenterName()); |
|
|
|
buildData.setStartTime(source.getStartTime()); |
|
|
|
buildData.setStopTime(source.getStopTime()); |
|
|
|
buildData.setStopFlag(source.getStopFlag()); |
|
|
|
buildData.setWeightRate(source.getWeightRate()); |
|
|
|
BmsCenterExtendBuild buildData = buildDataByTreeVo(source,source.getWeightRate()); |
|
|
|
buildList.add(buildData); |
|
|
|
//TODO
|
|
|
|
BigDecimal weightRate = source.getWeightRate(); |
|
|
|
String pid = source.getParentId(); |
|
|
|
for (BmsCenterExtendTreeVo treeVo : treeVoList) { |
|
|
|
|
|
|
|
//提取父级节点
|
|
|
|
List<BmsCenterExtendTreeVo> parents = new ArrayList<>(); |
|
|
|
this.filterParents(allTreeList, source, parents); |
|
|
|
//修改为 从上往下
|
|
|
|
Collections.reverse(parents); |
|
|
|
for (int i = 0; i < parents.size(); i++) { |
|
|
|
BmsCenterExtendTreeVo treeVo = parents.get(i); |
|
|
|
//计算父级节点比率
|
|
|
|
BigDecimal currParentWeightRate = treeVo.getWeightRate(); |
|
|
|
for (int j = i+1; j < parents.size(); j++) { |
|
|
|
BmsCenterExtendTreeVo nextTreeVo = parents.get(j); |
|
|
|
currParentWeightRate = currParentWeightRate.multiply(nextTreeVo.getWeightRate()); |
|
|
|
} |
|
|
|
BmsCenterExtendBuild buildParentData = this.buildDataByTreeVo(treeVo, currParentWeightRate); |
|
|
|
buildList.add(buildParentData); |
|
|
|
} |
|
|
|
|
|
|
|
}else { |
|
|
|
//递归调用
|
|
|
|
this.recursionBuildExtendCenter(treeVoList, buildList, build); |
|
|
|
this.recursionBuildExtendCenter(allTreeList, buildList, build); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 建立数据类型对象 |
|
|
|
* @param source |
|
|
|
* @param currParentWeightRate |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private BmsCenterExtendBuild buildDataByTreeVo(BmsCenterExtendTreeVo source, BigDecimal currParentWeightRate) { |
|
|
|
BmsCenterExtendBuild parentData = new BmsCenterExtendBuild(); |
|
|
|
parentData.setBuildType(CenterExtendBuildType.DATA); |
|
|
|
parentData.setSourceId(source.getSourceId()); |
|
|
|
parentData.setCenterType(source.getCenterType()); |
|
|
|
parentData.setCenterId(source.getCenterId()); |
|
|
|
parentData.setCenterCode(source.getCenterCode()); |
|
|
|
parentData.setCenterName(source.getCenterName()); |
|
|
|
parentData.setStartTime(source.getStartTime()); |
|
|
|
parentData.setStopTime(source.getStopTime()); |
|
|
|
parentData.setStopFlag(source.getStopFlag()); |
|
|
|
parentData.setWeightRate(currParentWeightRate); |
|
|
|
return parentData; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 过滤获取父级节点(自下而上) |
|
|
|
* @param allTreeList |
|
|
|
* @param source |
|
|
|
* @param parents |
|
|
|
*/ |
|
|
|
private void filterParents(List<BmsCenterExtendTreeVo> allTreeList, BmsCenterExtendTreeVo source, List<BmsCenterExtendTreeVo> parents) { |
|
|
|
String pid = source.getParentId(); |
|
|
|
for (BmsCenterExtendTreeVo treeVo : allTreeList) { |
|
|
|
if(treeVo.getId().equals(pid)){ |
|
|
|
parents.add(treeVo); |
|
|
|
if(!treeVo.getParentId().equals("0")){ |
|
|
|
this.filterParents(allTreeList,treeVo,parents); |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|