|
@@ -61,6 +61,7 @@ import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.jdbc.BadSqlGrammarException;
|
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
+import org.springframework.jdbc.core.SingleColumnRowMapper;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.LinkedCaseInsensitiveMap;
|
|
@@ -2206,26 +2207,124 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
WbsTreeContract wbsTreeContractRoot = baseMapper.selectOne(Wrappers.<WbsTreeContract>query().lambda().eq(WbsTreeContract::getPKeyId, pkeyId));
|
|
|
//获取当前节点下所有子节点
|
|
|
List<WbsTreeContractVO> wbsTreeContractVOS = contractInfoMapper.tree4(wbsTreeContractRoot.getContractId(), String.valueOf(wbsTreeContractRoot.getId()));
|
|
|
+ // 定义 nodeType 的优先级顺序 18是子单位工程,后期加上去的,不敢动原本的顺序
|
|
|
+ List<Integer> priorityOrder = Arrays.asList(1, 18, 2, 3, 4, 5);
|
|
|
+ // 自定义 Comparator
|
|
|
+ Comparator<WbsTreeContractVO> comparator = (vo1, vo2) -> {
|
|
|
+ int index1 = priorityOrder.indexOf(vo1.getNodeType());
|
|
|
+ int index2 = priorityOrder.indexOf(vo2.getNodeType());
|
|
|
+ return Integer.compare(index1, index2);
|
|
|
+ };
|
|
|
+ // 对集合进行排序
|
|
|
+ wbsTreeContractVOS.sort(comparator);
|
|
|
if (wbsTreeContractVOS.size() <= 0) {
|
|
|
throw new ServiceException("未查询到当前合同段的wbs树,请先分配该合同的合同段wsb树");
|
|
|
}
|
|
|
//本次新增的节点
|
|
|
- List<String>insertList=new ArrayList<>();
|
|
|
+ List<WbsTreeContract>insertList=new ArrayList<>();
|
|
|
//本次修改的节点
|
|
|
List<String> updateList=new ArrayList<>();
|
|
|
|
|
|
- //新增和修改
|
|
|
+ //导入节点与现有节点进行比较。进行修改编号
|
|
|
for (ImportTreeDto dto : list) {
|
|
|
for (WbsTreeContractVO vo : wbsTreeContractVOS) {
|
|
|
- //wbs节点的名称和单位工程的名称类型能对应上,并且编号不一,就修改编号
|
|
|
+ //wbs节点和单位工程的名称类型能对应上,并且编号不一样,就修改编号
|
|
|
if(vo.getNodeName().equals(dto.getUnitName())&&vo.getNodeType()==1){
|
|
|
- baseMapper.update(null,Wrappers.<WbsTreeContract>lambdaUpdate().set(WbsTreeContract::getPartitionCode,dto.getUnitCode()).eq(WbsTreeContract::getPKeyId,vo.getPrimaryKeyId()));
|
|
|
+ if(vo.getPartitionCode().equals(dto.getUnitCode())){
|
|
|
+ baseMapper.update(null,Wrappers.<WbsTreeContract>lambdaUpdate().set(WbsTreeContract::getPartitionCode,dto.getUnitCode()).eq(WbsTreeContract::getPKeyId,vo.getPrimaryKeyId()));
|
|
|
+ updateList.add(vo.getNodeName());
|
|
|
+ }
|
|
|
+ dto.setIsUnit(true);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //wbs节点和子单位工程的名称类型能对应上,并且编号不一样,并且祖级节点也都能对应上,就修改编号
|
|
|
+ if(vo.getNodeName().equals(dto.getSubUnitName())&&vo.getNodeType()==18){
|
|
|
+ if(isTrueNode(Arrays.asList(dto.getUnitName(),dto.getSubUnitName()),vo)){
|
|
|
+ if(!vo.getPartitionCode().equals(dto.getSubUnitCode())){
|
|
|
+ baseMapper.update(null,Wrappers.<WbsTreeContract>lambdaUpdate().set(WbsTreeContract::getPartitionCode,dto.getSubUnitCode()).eq(WbsTreeContract::getPKeyId,vo.getPrimaryKeyId()));
|
|
|
+ updateList.add(vo.getNodeName());
|
|
|
+ }
|
|
|
+ dto.setIsSubUnit(true);
|
|
|
+ }
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //wbs节点和分部工程的名称类型能对应上,并且编号不一样,并且祖级节点也都能对应上,就修改编号
|
|
|
+ if(vo.getNodeName().equals(dto.getDivisionName())&&vo.getNodeType()==2&&!vo.getPartitionCode().equals(dto.getDivisionName())){
|
|
|
+ if(isTrueNode(Arrays.asList(dto.getUnitName(),dto.getSubUnitName(),dto.getDivisionName()),vo)){
|
|
|
+ baseMapper.update(null,Wrappers.<WbsTreeContract>lambdaUpdate().set(WbsTreeContract::getPartitionCode,dto.getDivisionCode()).eq(WbsTreeContract::getPKeyId,vo.getPrimaryKeyId()));
|
|
|
+ updateList.add(vo.getNodeName());
|
|
|
+ }
|
|
|
+ dto.setIsDivision(true);
|
|
|
continue;
|
|
|
}
|
|
|
+ //wbs节点和子分部工程的名称类型能对应上,并且编号不一样,并且祖级节点也都能对应上,就修改编号
|
|
|
+ if(vo.getNodeName().equals(dto.getSubDivisionName())&&vo.getNodeType()==3&&!vo.getPartitionCode().equals(dto.getSubDivisionName())){
|
|
|
+ if(isTrueNode(Arrays.asList(dto.getUnitName(),dto.getSubUnitName(),dto.getDivisionName(),dto.getSubDivisionName()),vo)){
|
|
|
+ baseMapper.update(null,Wrappers.<WbsTreeContract>lambdaUpdate().set(WbsTreeContract::getPartitionCode,dto.getSubDivisionCode()).eq(WbsTreeContract::getPKeyId,vo.getPrimaryKeyId()));
|
|
|
+ updateList.add(vo.getNodeName());
|
|
|
+ }
|
|
|
+ dto.setIsSubDivision(true);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //wbs节点和分项工程的名称类型能对应上,并且编号不一样,并且祖级节点也都能对应上,就修改编号
|
|
|
+ if(vo.getNodeName().equals(dto.getItemName())&&vo.getNodeType()==4&&!vo.getPartitionCode().equals(dto.getItemName())){
|
|
|
+ if(isTrueNode(Arrays.asList(dto.getUnitName(),dto.getSubUnitName(),dto.getDivisionName(),dto.getSubDivisionName(),dto.getItemName()),vo)){
|
|
|
+ baseMapper.update(null,Wrappers.<WbsTreeContract>lambdaUpdate().set(WbsTreeContract::getPartitionCode,dto.getItemCode()).eq(WbsTreeContract::getPKeyId,vo.getPrimaryKeyId()));
|
|
|
+ updateList.add(vo.getNodeName());
|
|
|
+ }
|
|
|
+ dto.setIsItem(true);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //wbs节点和子分项工程的名称类型能对应上,并且编号不一样,并且祖级节点也都能对应上,就修改编号
|
|
|
+ if(vo.getNodeName().equals(dto.getSubItemName())&&vo.getNodeType()==5&&!vo.getPartitionCode().equals(dto.getSubItemName())){
|
|
|
+ if(isTrueNode(Arrays.asList(dto.getUnitName(),dto.getSubUnitName(),dto.getDivisionName(),dto.getSubDivisionName(),dto.getItemName(),dto.getSubItemName()),vo)){
|
|
|
+ baseMapper.update(null,Wrappers.<WbsTreeContract>lambdaUpdate().set(WbsTreeContract::getPartitionCode,dto.getSubItemCode()).eq(WbsTreeContract::getPKeyId,vo.getPrimaryKeyId()));
|
|
|
+ updateList.add(vo.getNodeName());
|
|
|
+ }
|
|
|
+ dto.setIsSubItem(true);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ //新增
|
|
|
+ for (ImportTreeDto dto : list) {
|
|
|
+ //单位工程:如果没有被处理过,说明需要新增
|
|
|
+ if (!dto.getIsUnit()){
|
|
|
+ WbsTreeContract contract = new WbsTreeContract();
|
|
|
+ BeanUtil.copy(wbsTreeContractRoot,contract);
|
|
|
+ contract.setPKeyId(SnowFlakeUtil.getId());
|
|
|
+ contract.setId(SnowFlakeUtil.getId());
|
|
|
+ contract.setParentId(wbsTreeContractRoot.getId());
|
|
|
+ contract.setAncestors(wbsTreeContractRoot.getAncestors()+","+contract.getId());
|
|
|
+ contract.setIsCustom(1);
|
|
|
+ contract.setIsTypePrivatePid(null);
|
|
|
+ baseMapper.insert(contract);
|
|
|
+ }
|
|
|
+ //子单位工程:如果没有被处理过,说明需要新增,最重要是需要找到父节点。单位工程不会有相同的,所以直接根据名称查找
|
|
|
+ if(!dto.getIsSubUnit()){
|
|
|
+ WbsTreeContract fatherNode = baseMapper.selectOne(Wrappers.<WbsTreeContract>lambdaQuery().eq(WbsTreeContract::getNodeName, dto.getUnitName()).eq(WbsTreeContract::getProjectId, wbsTreeContractRoot.getProjectId())
|
|
|
+ .eq(WbsTreeContract::getContractId, wbsTreeContractRoot.getContractId()).eq(WbsTreeContract::getIsDeleted, 0));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断名称是否都在wbs的祖级节点里面
|
|
|
+ private Boolean isTrueNode(List<String> list, WbsTreeContractVO vo){
|
|
|
+ String sql="select node_name from m_wbs_tree_contract where id in ("+String.join("','", vo.getAncestors().split(","))+")";
|
|
|
+ List<String> ancestorNames = jdbcTemplate.query(sql, new SingleColumnRowMapper<>(String.class));
|
|
|
+ list.removeIf(Objects::isNull);
|
|
|
+ if(!ancestorNames.isEmpty()){
|
|
|
+ if(ancestorNames.containsAll(list)){
|
|
|
+ return true;
|
|
|
+ }else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|