|
|
@ -1,6 +1,7 @@ |
|
|
|
package com.qs.serve.modules.bms.service.impl; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
import com.qs.serve.common.model.dto.TreeNode; |
|
|
|
import com.qs.serve.modules.bms.common.CenterExtendBuildType; |
|
|
|
import com.qs.serve.modules.bms.entity.vo.BmsCenterExtendTreeVo; |
|
|
|
import com.qs.serve.modules.bms.service.BmsCenterExtendService; |
|
|
@ -31,26 +32,36 @@ public class BmsCenterExtendBuildServiceImpl extends ServiceImpl<BmsCenterExtend |
|
|
|
@Override |
|
|
|
public void initData() { |
|
|
|
List<BmsCenterExtendTreeVo> treeVoList = centerExtendService.transferTree(); |
|
|
|
List<BmsCenterExtendBuild> buildList = new ArrayList<>(); |
|
|
|
this.recursionBuildExtendCenter(treeVoList, buildList, null); |
|
|
|
List<BmsCenterExtendBuild> buildTreeList = new ArrayList<>(); |
|
|
|
List<BmsCenterExtendBuild> buildDataList = new ArrayList<>(); |
|
|
|
this.recursionBuildExtendCenter(treeVoList,treeVoList, buildTreeList,buildDataList, null); |
|
|
|
this.saveBatch(buildTreeList); |
|
|
|
this.saveBatch(buildDataList); |
|
|
|
} |
|
|
|
|
|
|
|
private void recursionBuildExtendCenter(List<BmsCenterExtendTreeVo> allTreeList, List<BmsCenterExtendBuild> buildList, BmsCenterExtendBuild parent) { |
|
|
|
private void recursionBuildExtendCenter(List<BmsCenterExtendTreeVo> allTreeList,List<BmsCenterExtendTreeVo> childList, List<BmsCenterExtendBuild> buildTreeList,List<BmsCenterExtendBuild> buildDataList, BmsCenterExtendBuild parent) { |
|
|
|
//存放上级对象
|
|
|
|
for (BmsCenterExtendTreeVo source : allTreeList) { |
|
|
|
for (BmsCenterExtendTreeVo source : childList) { |
|
|
|
BmsCenterExtendBuild build = new BmsCenterExtendBuild(); |
|
|
|
build.setBuildType(CenterExtendBuildType.TREE); |
|
|
|
build.setSourceId(source.getSourceId()); |
|
|
|
if(parent !=null){ |
|
|
|
String[] pathIds = parent.getPathIds().split("_"); |
|
|
|
for (String pathId : pathIds) { |
|
|
|
if(pathId.equals(source.getId())){ |
|
|
|
String[] centerIds = parent.getPathCenterIds().split("_"); |
|
|
|
for (String centerId : centerIds) { |
|
|
|
if(centerId.equals(source.getCenterId())){ |
|
|
|
build.setBuildType(CenterExtendBuildType.ERROR); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
build.setPathIds(parent.getPathIds() + "_" + source.getId()); |
|
|
|
build.setPathCenterIds(parent.getPathCenterIds() + "_" + source.getCenterId()); |
|
|
|
build.setPathCenterIds(parent.getPathCenterCodes() + "_" + source.getCenterCode()); |
|
|
|
build.setPathCenterIds(parent.getPathCenterNames() + "_" + source.getCenterName()); |
|
|
|
}else { |
|
|
|
build.setPathIds("0_" + source.getId()); |
|
|
|
build.setPathIds(source.getId()+""); |
|
|
|
build.setPathCenterIds(source.getCenterId()); |
|
|
|
build.setPathCenterCodes(source.getCenterCode()); |
|
|
|
build.setPathCenterNames(source.getCenterName()); |
|
|
|
} |
|
|
|
build.setCenterType(source.getCenterType()); |
|
|
|
build.setCenterId(source.getCenterId()); |
|
|
@ -60,12 +71,17 @@ public class BmsCenterExtendBuildServiceImpl extends ServiceImpl<BmsCenterExtend |
|
|
|
build.setStopTime(source.getStopTime()); |
|
|
|
build.setStopFlag(source.getStopFlag()); |
|
|
|
build.setWeightRate(source.getWeightRate()); |
|
|
|
buildList.add(build); |
|
|
|
buildTreeList.add(build); |
|
|
|
|
|
|
|
//判断是否最后一级
|
|
|
|
if(source.getChildren()==null||source.getChildren().size()==0){ |
|
|
|
//自下而上查询返回所有占比
|
|
|
|
BmsCenterExtendBuild buildData = buildDataByTreeVo(source,source.getWeightRate()); |
|
|
|
buildList.add(buildData); |
|
|
|
buildData.setPathIds(build.getPathIds()); |
|
|
|
buildData.setPathCenterIds(build.getPathCenterIds()); |
|
|
|
buildData.setPathCenterCodes(build.getPathCenterCodes()); |
|
|
|
buildData.setPathCenterNames(build.getPathCenterNames()); |
|
|
|
buildDataList.add(buildData); |
|
|
|
//提取父级节点
|
|
|
|
List<BmsCenterExtendTreeVo> parents = new ArrayList<>(); |
|
|
|
this.filterParents(allTreeList, source, parents); |
|
|
@ -75,16 +91,28 @@ public class BmsCenterExtendBuildServiceImpl extends ServiceImpl<BmsCenterExtend |
|
|
|
BmsCenterExtendTreeVo treeVo = parents.get(i); |
|
|
|
//计算父级节点比率
|
|
|
|
BigDecimal currParentWeightRate = treeVo.getWeightRate(); |
|
|
|
String pathIds = treeVo.getSourceId().toString(); |
|
|
|
String pathCenterIds = treeVo.getSourceId().toString(); |
|
|
|
String pathCenterCodes = treeVo.getCenterCode(); |
|
|
|
String pathCenterNames = treeVo.getCenterName(); |
|
|
|
for (int j = i+1; j < parents.size(); j++) { |
|
|
|
BmsCenterExtendTreeVo nextTreeVo = parents.get(j); |
|
|
|
currParentWeightRate = currParentWeightRate.multiply(nextTreeVo.getWeightRate()); |
|
|
|
pathIds = nextTreeVo.getSourceId() + "_"+pathIds; |
|
|
|
pathCenterIds = nextTreeVo.getCenterId() + "_"+pathCenterIds; |
|
|
|
pathCenterCodes = nextTreeVo.getCenterCode() + "_"+pathCenterCodes; |
|
|
|
pathCenterNames = nextTreeVo.getCenterName() + "_"+pathCenterNames; |
|
|
|
} |
|
|
|
BmsCenterExtendBuild buildParentData = this.buildDataByTreeVo(treeVo, currParentWeightRate); |
|
|
|
buildList.add(buildParentData); |
|
|
|
buildParentData.setPathIds(pathIds+"_"+buildData.getSourceId()); |
|
|
|
buildParentData.setPathCenterIds(pathCenterIds); |
|
|
|
buildParentData.setPathCenterCodes(pathCenterCodes); |
|
|
|
buildParentData.setPathCenterNames(pathCenterNames); |
|
|
|
buildDataList.add(buildParentData); |
|
|
|
} |
|
|
|
}else { |
|
|
|
//递归调用
|
|
|
|
this.recursionBuildExtendCenter(allTreeList, buildList, build); |
|
|
|
this.recursionBuildExtendCenter(allTreeList,source.getChildren(), buildTreeList,buildDataList, build); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -117,11 +145,11 @@ public class BmsCenterExtendBuildServiceImpl extends ServiceImpl<BmsCenterExtend |
|
|
|
* @param parents |
|
|
|
*/ |
|
|
|
private void filterParents(List<BmsCenterExtendTreeVo> allTreeList, BmsCenterExtendTreeVo source, List<BmsCenterExtendTreeVo> parents) { |
|
|
|
String pid = source.getParentId(); |
|
|
|
String pid = source.getComboParentId(); |
|
|
|
for (BmsCenterExtendTreeVo treeVo : allTreeList) { |
|
|
|
if(treeVo.getId().equals(pid)){ |
|
|
|
if(treeVo.getComboId().equals(pid)){ |
|
|
|
parents.add(treeVo); |
|
|
|
if(!treeVo.getParentId().equals("0")){ |
|
|
|
if(!treeVo.getComboParentId().equals("0")){ |
|
|
|
this.filterParents(allTreeList,treeVo,parents); |
|
|
|
} |
|
|
|
break; |
|
|
|