|
@@ -11,7 +11,9 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.mixsmart.utils.CustomFunction;
|
|
|
+import com.sun.org.apache.xpath.internal.operations.Bool;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import lombok.Data;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.apache.poi.ss.usermodel.Cell;
|
|
|
import org.apache.poi.ss.usermodel.Row;
|
|
@@ -63,7 +65,9 @@ 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.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Isolation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.LinkedCaseInsensitiveMap;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
@@ -571,12 +575,73 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
// //表单排序
|
|
|
// if (resultTabs.size() > 0) {
|
|
|
// List<AppWbsTreeContractVO> resultTabsToCopy = this.sortTabs(resultTabs, "__"); //复制表排序
|
|
|
-// return this.sortTabs(resultTabs, "_PL_"); //频率表排序
|
|
|
+// return this.sortTabs(resultTabsToCopy, "_PL_"); //频率表排序
|
|
|
// }
|
|
|
// }
|
|
|
+ // 使用自定义 Comparator 进行排序
|
|
|
+ resultTabs.sort(new WbsTreeContractComparator());
|
|
|
return resultTabs;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public static class WbsTreeContractComparator implements Comparator<AppWbsTreeContractVO> {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int compare(AppWbsTreeContractVO o1, AppWbsTreeContractVO o2) {
|
|
|
+ // 先比较 sort 属性
|
|
|
+ Integer sort1 = o1.getSort();
|
|
|
+ Integer sort2 = o2.getSort();
|
|
|
+ if (sort1 == null && sort2 == null) {
|
|
|
+ // 两个 sort 都为空,认为相等
|
|
|
+ return 0;
|
|
|
+ } else if (sort1 == null) {
|
|
|
+ // 第一个 sort 为空,排在后面
|
|
|
+ return 1;
|
|
|
+ } else if (sort2 == null) {
|
|
|
+ // 第二个 sort 为空,排在前面
|
|
|
+ return -1;
|
|
|
+ } else {
|
|
|
+ // 两个 sort 都不为空,按 sort 排序
|
|
|
+ int sortComparison = Integer.compare(sort1, sort2);
|
|
|
+ if (sortComparison != 0) {
|
|
|
+ return sortComparison;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果 sort 相同,比较 nodeName
|
|
|
+ String name1 = o1.getNodeName();
|
|
|
+ String name2 = o2.getNodeName();
|
|
|
+
|
|
|
+ boolean hasUnderscore1 = name1.contains("__");
|
|
|
+ boolean hasUnderscore2 = name2.contains("__");
|
|
|
+
|
|
|
+ if (!hasUnderscore1 && !hasUnderscore2) {
|
|
|
+ // 两个都不包含 __,按字母顺序排序
|
|
|
+ return name1.compareTo(name2);
|
|
|
+ } else if (!hasUnderscore1) {
|
|
|
+ // 第一个不包含 __,排在前面
|
|
|
+ return -1;
|
|
|
+ } else if (!hasUnderscore2) {
|
|
|
+ // 第二个不包含 __,排在前面
|
|
|
+ return 1;
|
|
|
+ } else {
|
|
|
+ // 两个都包含 __,按 __ 后面的数字排序
|
|
|
+ int number1 = getNumberAfterUnderscore(name1);
|
|
|
+ int number2 = getNumberAfterUnderscore(name2);
|
|
|
+ return Integer.compare(number1, number2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private int getNumberAfterUnderscore(String name) {
|
|
|
+ String[] parts = name.split("__");
|
|
|
+ if (parts.length > 1) {
|
|
|
+ return Integer.parseInt(parts[1]);
|
|
|
+ }
|
|
|
+ return Integer.MAX_VALUE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 元素表排序
|
|
|
*
|
|
@@ -2183,7 +2248,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
return null;
|
|
|
}
|
|
|
@Override
|
|
|
- @Transactional
|
|
|
+ @Transactional(isolation = Isolation.READ_COMMITTED)
|
|
|
public R importTree(MultipartFile file, Long pkeyId) throws IOException {
|
|
|
InputStream inputStream = file.getInputStream();
|
|
|
org.apache.poi.ss.usermodel.Workbook workbook = new XSSFWorkbook(inputStream);
|
|
@@ -2205,16 +2270,22 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
String itemCode = getCellValue(row.getCell(9)); // J列:分项工程编号
|
|
|
String subItemName = getCellValue(row.getCell(10)); // K列:子分项工程名称
|
|
|
String subItemCode = getCellValue(row.getCell(11));// L列:子分项工程编号
|
|
|
- ImportTreeDto dto=new ImportTreeDto(unitName,unitCode,1,unitName==null,subUnitName,subUnitCode,18,subUnitName==null,divisionName,divisionCode,2,divisionName==null, subDivisionName,subDivisionCode,3,subDivisionName==null,itemName,itemCode,4,itemName==null,subItemName,subItemCode,5,subItemName==null);
|
|
|
+ ImportTreeDto dto=new ImportTreeDto(unitName,unitCode,1,StringUtils.isEmpty(unitName) ,subUnitName,subUnitCode,18,StringUtils.isEmpty(subUnitName),divisionName,divisionCode,2,StringUtils.isEmpty(divisionName), subDivisionName,subDivisionCode,3,StringUtils.isEmpty(subDivisionName),itemName,itemCode,4,StringUtils.isEmpty(itemName),subItemName,subItemCode,5,StringUtils.isEmpty(subItemName));
|
|
|
list.add(dto);
|
|
|
}
|
|
|
if(list.isEmpty()){
|
|
|
throw new ServiceException("导入模版为空,请先填写数据");
|
|
|
}
|
|
|
+ //过滤出空节点
|
|
|
+ list=list.stream().filter(o->!o.getIsUnit()||!o.getIsSubUnit()||!o.getIsDivision()||!o.getIsSubDivision()||!o.getIsItem()||!o.getIsSubItem()).collect(Collectors.toList());
|
|
|
+ //过滤出相同节点但是编号不同的情况
|
|
|
+ if(hasConflictingCodes(list)){
|
|
|
+ throw new ServiceException("导入模版存在相同节点但不同编号,请修改");
|
|
|
+ }
|
|
|
//最高节点
|
|
|
WbsTreeContract wbsTreeContractRoot = baseMapper.selectOne(Wrappers.<WbsTreeContract>query().lambda().eq(WbsTreeContract::getPKeyId, pkeyId));
|
|
|
//获取当前节点下所有子节点
|
|
|
- List<WbsTreeContractVO> wbsTreeContractVOS = contractInfoMapper.tree4(wbsTreeContractRoot.getContractId(), String.valueOf(wbsTreeContractRoot.getId()));
|
|
|
+ List<WbsTreeContractVO> wbsTreeContractVOS = contractInfoMapper.tree4(wbsTreeContractRoot.getContractId(), String.valueOf(wbsTreeContractRoot.getPKeyId()));
|
|
|
// 定义 nodeType 的优先级顺序 18是子单位工程,后期加上去的,不敢动原本的顺序
|
|
|
List<Integer> priorityOrder = Arrays.asList(1, 18, 2, 3, 4, 5);
|
|
|
// 自定义 Comparator
|
|
@@ -2238,7 +2309,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
for (WbsTreeContractVO vo : wbsTreeContractVOS) {
|
|
|
//wbs节点和单位工程的名称类型能对应上,并且编号不一样,就修改编号
|
|
|
if(vo.getNodeName().equals(dto.getUnitName())&&vo.getNodeType()==1){
|
|
|
- if(vo.getPartitionCode().equals(dto.getUnitCode())){
|
|
|
+ if(vo.getPartitionCode()==null||!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());
|
|
|
}
|
|
@@ -2248,7 +2319,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
//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())){
|
|
|
+ if(vo.getPartitionCode()==null||!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());
|
|
|
}
|
|
@@ -2266,7 +2337,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
continue;
|
|
|
}
|
|
|
//wbs节点和子分部工程的名称类型能对应上,并且编号不一样,并且祖级节点也都能对应上,就修改编号
|
|
|
- if(vo.getNodeName().equals(dto.getSubDivisionName())&&vo.getNodeType()==3&&!vo.getPartitionCode().equals(dto.getSubDivisionName())){
|
|
|
+ if(vo.getNodeName().equals(dto.getSubDivisionName())&&vo.getNodeType()==3&&(vo.getPartitionCode()==null||!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());
|
|
@@ -2275,7 +2346,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
continue;
|
|
|
}
|
|
|
//wbs节点和分项工程的名称类型能对应上,并且编号不一样,并且祖级节点也都能对应上,就修改编号
|
|
|
- if(vo.getNodeName().equals(dto.getItemName())&&vo.getNodeType()==4&&!vo.getPartitionCode().equals(dto.getItemName())){
|
|
|
+ if(vo.getNodeName().equals(dto.getItemName())&&vo.getNodeType()==4&&(vo.getPartitionCode()==null||!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());
|
|
@@ -2284,7 +2355,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
continue;
|
|
|
}
|
|
|
//wbs节点和子分项工程的名称类型能对应上,并且编号不一样,并且祖级节点也都能对应上,就修改编号
|
|
|
- if(vo.getNodeName().equals(dto.getSubItemName())&&vo.getNodeType()==5&&!vo.getPartitionCode().equals(dto.getSubItemName())){
|
|
|
+ if(vo.getNodeName().equals(dto.getSubItemName())&&vo.getNodeType()==5&&(vo.getPartitionCode()==null||!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());
|
|
@@ -2297,72 +2368,520 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
//新增
|
|
|
for (ImportTreeDto dto : list) {
|
|
|
//单位工程:如果没有被处理过,说明需要新增
|
|
|
+ String sqlList="Select * from m_wbs_tree_contract where contract_id="+wbsTreeContractRoot.getContractId()+" and wbs_id="+wbsTreeContractRoot.getWbsId()+" and is_deleted=0";
|
|
|
+ List<WbsTreeContract> WbsTreeContractList = jdbcTemplate.query(sqlList, new BeanPropertyRowMapper<>(WbsTreeContract.class));
|
|
|
if (!dto.getIsUnit()){
|
|
|
- WbsTreeContract unit = new WbsTreeContract();
|
|
|
- BeanUtil.copy(wbsTreeContractRoot,unit);
|
|
|
- unit.setPKeyId(SnowFlakeUtil.getId());
|
|
|
- unit.setId(SnowFlakeUtil.getId());
|
|
|
- unit.setParentId(wbsTreeContractRoot.getId());
|
|
|
- unit.setAncestors(wbsTreeContractRoot.getAncestors()+","+unit.getId());
|
|
|
- unit.setIsCustom(1);
|
|
|
- unit.setIsTypePrivatePid(null);
|
|
|
- unit.setNodeType(1);
|
|
|
- insertList.add(unit);
|
|
|
+ //检测是否已经存在,如果存在,就不需要新增了
|
|
|
+ Boolean exist = this.isExist(dto, WbsTreeContractList, 1, Long.valueOf(wbsTreeContractRoot.getContractId()));
|
|
|
+ if(!exist){
|
|
|
+ WbsTreeContract unit = new WbsTreeContract();
|
|
|
+ BeanUtil.copy(wbsTreeContractRoot,unit);
|
|
|
+ unit.setPKeyId(SnowFlakeUtil.getId());
|
|
|
+ unit.setId(SnowFlakeUtil.getId());
|
|
|
+ unit.setParentId(wbsTreeContractRoot.getId());
|
|
|
+ unit.setAncestors("0,"+wbsTreeContractRoot.getPKeyId()+","+unit.getPKeyId());
|
|
|
+ unit.setIsCustom(1);
|
|
|
+ unit.setPartitionCode(dto.getUnitCode());
|
|
|
+ unit.setNodeType(1);
|
|
|
+ unit.setNodeName(dto.getUnitName());
|
|
|
+ unit.setFullName(dto.getUnitName());
|
|
|
+ baseMapper.insert(unit);
|
|
|
+ insertList.add(unit);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
//子单位工程:如果没有被处理过,说明需要新增,最重要是需要找到父节点。单位工程不会有相同的,所以直接根据名称查找
|
|
|
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));
|
|
|
- WbsTreeContract subUnit = new WbsTreeContract();
|
|
|
- BeanUtil.copy(fatherNode,subUnit);
|
|
|
- subUnit.setPKeyId(SnowFlakeUtil.getId());
|
|
|
- subUnit.setId(SnowFlakeUtil.getId());
|
|
|
- subUnit.setParentId(fatherNode.getId());
|
|
|
- subUnit.setAncestors(fatherNode.getAncestors()+","+subUnit.getId());
|
|
|
- subUnit.setIsCustom(1);
|
|
|
- subUnit.setIsTypePrivatePid(null);
|
|
|
- subUnit.setNodeType(18);
|
|
|
- insertList.add(subUnit);
|
|
|
+ Boolean exist = this.isExist(dto, WbsTreeContractList, 2, Long.valueOf(wbsTreeContractRoot.getContractId()));
|
|
|
+ if(!exist){
|
|
|
+ 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).last("LIMIT 1"));
|
|
|
+ WbsTreeContract subUnit = new WbsTreeContract();
|
|
|
+ BeanUtil.copy(fatherNode,subUnit);
|
|
|
+ subUnit.setPKeyId(SnowFlakeUtil.getId());
|
|
|
+ subUnit.setId(SnowFlakeUtil.getId());
|
|
|
+ subUnit.setParentId(fatherNode.getId());
|
|
|
+ subUnit.setAncestors(fatherNode.getAncestors()+","+subUnit.getPKeyId());
|
|
|
+ subUnit.setIsCustom(1);
|
|
|
+ subUnit.setPartitionCode(dto.getSubUnitCode());
|
|
|
+ subUnit.setNodeType(18);
|
|
|
+ subUnit.setNodeName(dto.getSubUnitName());
|
|
|
+ subUnit.setFullName(dto.getSubUnitName());
|
|
|
+ baseMapper.insert(subUnit);
|
|
|
+ insertList.add(subUnit);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
//分部工程:如果没有被处理过,说明需要新增,最重要是需要找到父节点。现在的办法是(通过祖级节点名称拼接的方式来判断)。
|
|
|
if(!dto.getIsDivision()){
|
|
|
- String fatherNodeName="";
|
|
|
- if(dto.getSubUnitName()!=null&&!dto.getSubUnitName().equals("")){
|
|
|
- fatherNodeName=dto.getSubUnitName();
|
|
|
- }else if(dto.getUnitName()!=null&&!dto.getUnitName().equals("")){
|
|
|
- fatherNodeName=dto.getUnitName();
|
|
|
- }
|
|
|
- List<WbsTreeContract> list1 = baseMapper.selectList(Wrappers.<WbsTreeContract>lambdaQuery().eq(WbsTreeContract::getNodeName, fatherNodeName).eq(WbsTreeContract::getProjectId, wbsTreeContractRoot.getProjectId())
|
|
|
- .eq(WbsTreeContract::getContractId, wbsTreeContractRoot.getContractId()).eq(WbsTreeContract::getIsDeleted, 0));
|
|
|
- if(list1.size()>0){
|
|
|
- for (WbsTreeContract contract : list1) {
|
|
|
- String[] ids = contract.getAncestors().split(",");
|
|
|
- ids=Arrays.stream(ids)
|
|
|
- .filter(id -> !id.equals("0")) // 过滤掉值为 "0" 的元素
|
|
|
- .toArray(String[]::new);
|
|
|
- String sql="Select node_name from m_wbs_tree_contract where id in("+String.join("','", ids)+")";
|
|
|
- List<String> nodeNames = jdbcTemplate.query(sql, new SingleColumnRowMapper<>(String.class));
|
|
|
- String result = String.join("",nodeNames);
|
|
|
- String ancestorsName=dto.getUnitName()!=null?dto.getUnitName():""+dto.getSubUnitName()!=null?dto.getSubUnitName():"";
|
|
|
- if(result.equals(ancestorsName)){
|
|
|
- WbsTreeContract division = new WbsTreeContract();
|
|
|
- BeanUtil.copy(contract,division);
|
|
|
- division.setPKeyId(SnowFlakeUtil.getId());
|
|
|
- division.setId(SnowFlakeUtil.getId());
|
|
|
- division.setParentId(contract.getId());
|
|
|
- division.setAncestors(contract.getAncestors()+","+division.getId());
|
|
|
- division.setIsCustom(1);
|
|
|
- division.setIsTypePrivatePid(null);
|
|
|
- division.setNodeType(2);
|
|
|
- insertList.add(division);
|
|
|
- break;
|
|
|
+ Boolean exist = this.isExist(dto, WbsTreeContractList, 3, Long.valueOf(wbsTreeContractRoot.getContractId()));
|
|
|
+ if(!exist){
|
|
|
+ String fatherNodeName="";
|
|
|
+ if(dto.getSubUnitName()!=null&&!dto.getSubUnitName().equals("")){
|
|
|
+ fatherNodeName=dto.getSubUnitName();
|
|
|
+ }else if(dto.getUnitName()!=null&&!dto.getUnitName().equals("")){
|
|
|
+ fatherNodeName=dto.getUnitName();
|
|
|
+ }
|
|
|
+ List<WbsTreeContract> list1 = baseMapper.selectList(Wrappers.<WbsTreeContract>lambdaQuery().eq(WbsTreeContract::getNodeName, fatherNodeName).eq(WbsTreeContract::getProjectId, wbsTreeContractRoot.getProjectId())
|
|
|
+ .eq(WbsTreeContract::getContractId, wbsTreeContractRoot.getContractId()).eq(WbsTreeContract::getIsDeleted, 0));
|
|
|
+ if(list1.size()>0){
|
|
|
+ for (WbsTreeContract contract : list1) {
|
|
|
+ String[] ids = contract.getAncestors().split(",");
|
|
|
+ ids=Arrays.stream(ids)
|
|
|
+ .filter(id -> !id.equals("0")) // 过滤掉值为 "0" 的元素
|
|
|
+ .toArray(String[]::new);
|
|
|
+ String sql="Select node_name from m_wbs_tree_contract where p_key_id in("+String.join(",", ids)+")";
|
|
|
+ List<String> nodeNames = jdbcTemplate.query(sql, new SingleColumnRowMapper<>(String.class));
|
|
|
+ String result = String.join("",nodeNames);
|
|
|
+ String ancestorsName= wbsTreeContractRoot.getNodeName()+StringUtils.defaultString(dto.getUnitName())
|
|
|
+ + StringUtils.defaultString(dto.getSubUnitName());
|
|
|
+ if(result.equals(ancestorsName)){
|
|
|
+ WbsTreeContract division = new WbsTreeContract();
|
|
|
+ BeanUtil.copy(contract,division);
|
|
|
+ division.setPKeyId(SnowFlakeUtil.getId());
|
|
|
+ division.setId(SnowFlakeUtil.getId());
|
|
|
+ division.setParentId(contract.getId());
|
|
|
+ division.setAncestors(contract.getAncestors()+","+division.getPKeyId());
|
|
|
+ division.setIsCustom(1);
|
|
|
+ division.setPartitionCode(dto.getDivisionCode());
|
|
|
+ division.setNodeType(2);
|
|
|
+ division.setNodeName(dto.getDivisionName());
|
|
|
+ division.setFullName(dto.getDivisionName());
|
|
|
+ baseMapper.insert(division);
|
|
|
+ insertList.add(division);
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
//子分部工程:如果没有被处理过,说明需要新增,最重要是需要找到父节点。现在的办法是(通过祖级节点名称拼接的方式来判断)。
|
|
|
if(!dto.getIsSubDivision()){
|
|
|
- String fatherNodeName="";
|
|
|
+ Boolean exist = this.isExist(dto, WbsTreeContractList, 4, Long.valueOf(wbsTreeContractRoot.getContractId()));
|
|
|
+ if(!exist){
|
|
|
+ String fatherNodeName="";
|
|
|
+ if(dto.getDivisionName()!=null&&!dto.getDivisionName().equals("")){
|
|
|
+ fatherNodeName=dto.getDivisionName();
|
|
|
+ } else if(dto.getSubUnitName()!=null&&!dto.getSubUnitName().equals("")){
|
|
|
+ fatherNodeName=dto.getSubUnitName();
|
|
|
+ }else if(dto.getUnitName()!=null&&!dto.getUnitName().equals("")){
|
|
|
+ fatherNodeName=dto.getUnitName();
|
|
|
+ }
|
|
|
+ List<WbsTreeContract> list1 = baseMapper.selectList(Wrappers.<WbsTreeContract>lambdaQuery().eq(WbsTreeContract::getNodeName, fatherNodeName).eq(WbsTreeContract::getProjectId, wbsTreeContractRoot.getProjectId())
|
|
|
+ .eq(WbsTreeContract::getContractId, wbsTreeContractRoot.getContractId()).eq(WbsTreeContract::getIsDeleted, 0));
|
|
|
+ if(list1.size()>0){
|
|
|
+ for (WbsTreeContract contract : list1) {
|
|
|
+ String[] ids = contract.getAncestors().split(",");
|
|
|
+ ids=Arrays.stream(ids)
|
|
|
+ .filter(id -> !id.equals("0")) // 过滤掉值为 "0" 的元素
|
|
|
+ .toArray(String[]::new);
|
|
|
+ String sql="Select node_name from m_wbs_tree_contract where p_key_id in("+String.join(",", ids)+")";
|
|
|
+ List<String> nodeNames = jdbcTemplate.query(sql, new SingleColumnRowMapper<>(String.class));
|
|
|
+ String result = String.join("",nodeNames);
|
|
|
+ String ancestorsName= wbsTreeContractRoot.getNodeName()+StringUtils.defaultString(dto.getUnitName())
|
|
|
+ + StringUtils.defaultString(dto.getSubUnitName())
|
|
|
+ +StringUtils.defaultString(dto.getDivisionName());
|
|
|
+ if(result.equals(ancestorsName)){
|
|
|
+ WbsTreeContract subDivision = new WbsTreeContract();
|
|
|
+ BeanUtil.copy(contract,subDivision);
|
|
|
+ subDivision.setPKeyId(SnowFlakeUtil.getId());
|
|
|
+ subDivision.setId(SnowFlakeUtil.getId());
|
|
|
+ subDivision.setParentId(contract.getId());
|
|
|
+ subDivision.setAncestors(contract.getAncestors()+","+subDivision.getPKeyId());
|
|
|
+ subDivision.setIsCustom(1);
|
|
|
+ subDivision.setPartitionCode(dto.getDivisionCode());
|
|
|
+ subDivision.setNodeType(3);
|
|
|
+ subDivision.setNodeName(dto.getSubDivisionName());
|
|
|
+ subDivision.setFullName(dto.getSubDivisionName());
|
|
|
+ baseMapper.insert(subDivision);
|
|
|
+ insertList.add(subDivision);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ //分项节点:如果没有被处理过,说明需要新增,最重要是需要找到父节点。现在的办法是(通过祖级节点名称拼接的方式来判断)。
|
|
|
+ if(!dto.getIsItem()){
|
|
|
+ Boolean exist = this.isExist(dto, WbsTreeContractList, 5, Long.valueOf(wbsTreeContractRoot.getContractId()));
|
|
|
+ if(!exist){
|
|
|
+ String fatherNodeName="";
|
|
|
+ if(dto.getSubDivisionName()!=null&&!dto.getSubDivisionName().equals("")){
|
|
|
+ fatherNodeName=dto.getSubDivisionName();
|
|
|
+ }
|
|
|
+ else if(dto.getDivisionName()!=null&&!dto.getDivisionName().equals("")){
|
|
|
+ fatherNodeName=dto.getDivisionName();
|
|
|
+ } else if(dto.getSubUnitName()!=null&&!dto.getSubUnitName().equals("")){
|
|
|
+ fatherNodeName=dto.getSubUnitName();
|
|
|
+ }else if(dto.getUnitName()!=null&&!dto.getUnitName().equals("")){
|
|
|
+ fatherNodeName=dto.getUnitName();
|
|
|
+ }
|
|
|
+ List<WbsTreeContract> list1 = baseMapper.selectList(Wrappers.<WbsTreeContract>lambdaQuery().eq(WbsTreeContract::getNodeName, fatherNodeName).eq(WbsTreeContract::getProjectId, wbsTreeContractRoot.getProjectId())
|
|
|
+ .eq(WbsTreeContract::getContractId, wbsTreeContractRoot.getContractId()).eq(WbsTreeContract::getIsDeleted, 0));
|
|
|
+ if(list1.size()>0){
|
|
|
+ for (WbsTreeContract contract : list1) {
|
|
|
+ String[] ids = contract.getAncestors().split(",");
|
|
|
+ ids=Arrays.stream(ids)
|
|
|
+ .filter(id -> !id.equals("0")) // 过滤掉值为 "0" 的元素
|
|
|
+ .toArray(String[]::new);
|
|
|
+ String sql="Select node_name from m_wbs_tree_contract where p_key_id in("+String.join(",", ids)+")";
|
|
|
+ List<String> nodeNames = jdbcTemplate.query(sql, new SingleColumnRowMapper<>(String.class));
|
|
|
+ String result = String.join("",nodeNames);
|
|
|
+ String ancestorsName= wbsTreeContractRoot.getNodeName()+StringUtils.defaultString(dto.getUnitName())
|
|
|
+ + StringUtils.defaultString(dto.getSubUnitName())
|
|
|
+ +StringUtils.defaultString(dto.getDivisionName())
|
|
|
+ +StringUtils.defaultString(dto.getSubDivisionName());
|
|
|
+ if(result.equals(ancestorsName)){
|
|
|
+ WbsTreeContract item = new WbsTreeContract();
|
|
|
+ BeanUtil.copy(contract,item);
|
|
|
+ item.setPKeyId(SnowFlakeUtil.getId());
|
|
|
+ item.setId(SnowFlakeUtil.getId());
|
|
|
+ item.setParentId(contract.getId());
|
|
|
+ item.setAncestors(contract.getAncestors()+","+item.getPKeyId());
|
|
|
+ item.setIsCustom(1);
|
|
|
+ item.setPartitionCode(dto.getItemCode());
|
|
|
+ item.setNodeType(4);
|
|
|
+ item.setNodeName(dto.getItemName());
|
|
|
+ item.setFullName(dto.getItemName());
|
|
|
+ baseMapper.insert(item);
|
|
|
+ insertList.add(item);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ //子分项节点:如果没有被处理过,说明需要新增,最重要是需要找到父节点。现在的办法是(通过祖级节点名称拼接的方式来判断)。
|
|
|
+ if(!dto.getIsSubItem()){
|
|
|
+ Boolean exist = this.isExist(dto, WbsTreeContractList, 6, Long.valueOf(wbsTreeContractRoot.getContractId()));
|
|
|
+ if(!exist){
|
|
|
+ String fatherNodeName="";
|
|
|
+ if(dto.getItemName()!=null&&!dto.getItemName().equals("")){
|
|
|
+ fatherNodeName=dto.getItemName();
|
|
|
+ } else if(dto.getSubDivisionName()!=null&&!dto.getSubDivisionName().equals("")){
|
|
|
+ fatherNodeName=dto.getSubDivisionName();
|
|
|
+ }
|
|
|
+ else if(dto.getDivisionName()!=null&&!dto.getDivisionName().equals("")){
|
|
|
+ fatherNodeName=dto.getDivisionName();
|
|
|
+ } else if(dto.getSubUnitName()!=null&&!dto.getSubUnitName().equals("")){
|
|
|
+ fatherNodeName=dto.getSubUnitName();
|
|
|
+ }else if(dto.getUnitName()!=null&&!dto.getUnitName().equals("")){
|
|
|
+ fatherNodeName=dto.getUnitName();
|
|
|
+ }
|
|
|
+ List<WbsTreeContract> list1 = baseMapper.selectList(Wrappers.<WbsTreeContract>lambdaQuery().eq(WbsTreeContract::getNodeName, fatherNodeName).eq(WbsTreeContract::getProjectId, wbsTreeContractRoot.getProjectId())
|
|
|
+ .eq(WbsTreeContract::getContractId, wbsTreeContractRoot.getContractId()).eq(WbsTreeContract::getIsDeleted, 0));
|
|
|
+ if(list1.size()>0){
|
|
|
+ for (WbsTreeContract contract : list1) {
|
|
|
+ String[] ids = contract.getAncestors().split(",");
|
|
|
+ ids=Arrays.stream(ids)
|
|
|
+ .filter(id -> !id.equals("0")) // 过滤掉值为 "0" 的元素
|
|
|
+ .toArray(String[]::new);
|
|
|
+ String sql="Select node_name from m_wbs_tree_contract where p_key_id in("+String.join(",", ids)+")";
|
|
|
+ List<String> nodeNames = jdbcTemplate.query(sql, new SingleColumnRowMapper<>(String.class));
|
|
|
+ String result = String.join("",nodeNames);
|
|
|
+ String ancestorsName= wbsTreeContractRoot.getNodeName()+StringUtils.defaultString(dto.getUnitName())
|
|
|
+ + StringUtils.defaultString(dto.getSubUnitName())
|
|
|
+ +StringUtils.defaultString(dto.getDivisionName())
|
|
|
+ +StringUtils.defaultString(dto.getSubDivisionName())
|
|
|
+ +StringUtils.defaultString(dto.getItemName());
|
|
|
+ if(result.equals(ancestorsName)){
|
|
|
+ WbsTreeContract subItem = new WbsTreeContract();
|
|
|
+ BeanUtil.copy(contract,subItem);
|
|
|
+ subItem.setPKeyId(SnowFlakeUtil.getId());
|
|
|
+ subItem.setId(SnowFlakeUtil.getId());
|
|
|
+ subItem.setParentId(contract.getId());
|
|
|
+ subItem.setAncestors(contract.getAncestors()+","+subItem.getPKeyId());
|
|
|
+ subItem.setIsCustom(1);
|
|
|
+ subItem.setPartitionCode(dto.getSubItemCode());
|
|
|
+ subItem.setNodeType(5);
|
|
|
+ subItem.setNodeName(dto.getSubItemName());
|
|
|
+ subItem.setFullName(dto.getSubItemName());
|
|
|
+ baseMapper.insert(subItem);
|
|
|
+ insertList.add(subItem);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+// if(insertList.size()>0){
|
|
|
+// baseMapper.insertBatchSomeColumn(insertList);
|
|
|
+// }
|
|
|
+ return R.success("新增了"+insertList.size()+"个节点"+","+String.join(",",updateList)+"节点编号已被修改");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+// public class NodeInfo {
|
|
|
+// private String nodeName;
|
|
|
+// private Long parentId;
|
|
|
+//
|
|
|
+// public NodeInfo(String nodeName, Long parentId) {
|
|
|
+// this.nodeName=nodeName;
|
|
|
+// this.parentId=parentId;
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 构造器、getter和setter
|
|
|
+//
|
|
|
+// }
|
|
|
+public static boolean hasConflictingCodes(List<ImportTreeDto> list) {
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ for (int j = i + 1; j < list.size(); j++) {
|
|
|
+ ImportTreeDto dto1 = list.get(i);
|
|
|
+ ImportTreeDto dto2 = list.get(j);
|
|
|
+
|
|
|
+ // 检查单位工程层级
|
|
|
+ if (checkUnitLevelConflict(dto1, dto2)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查子单位工程层级
|
|
|
+ if (checkSubUnitLevelConflict(dto1, dto2)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查分部工程层级
|
|
|
+ if (checkDivisionLevelConflict(dto1, dto2)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查子分部工程层级
|
|
|
+ if (checkSubDivisionLevelConflict(dto1, dto2)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查分项工程层级
|
|
|
+ if (checkItemLevelConflict(dto1, dto2)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查子分项工程层级
|
|
|
+ if (checkSubItemLevelConflict(dto1, dto2)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+}
|
|
|
+ private static boolean checkUnitLevelConflict(ImportTreeDto dto1, ImportTreeDto dto2) {
|
|
|
+ return Objects.equals(dto1.getUnitName(), dto2.getUnitName()) &&
|
|
|
+ Objects.equals(dto1.getUnitType(), dto2.getUnitType()) &&
|
|
|
+ !Objects.equals(dto1.getUnitCode(), dto2.getUnitCode());
|
|
|
+ }
|
|
|
+
|
|
|
+ private static boolean checkSubUnitLevelConflict(ImportTreeDto dto1, ImportTreeDto dto2) {
|
|
|
+ String fatherNodeName1=dto1.getUnitName();
|
|
|
+ Integer fatherNodeType1=dto1.getUnitType();
|
|
|
+ String fatherNodeName2=dto2.getUnitName();
|
|
|
+ Integer fatherNodeType2=dto2.getUnitType();
|
|
|
+ return Objects.equals(dto1.getSubUnitName(), dto2.getSubUnitName()) &&
|
|
|
+ Objects.equals(dto1.getSubUnitType(), dto2.getSubUnitType()) &&
|
|
|
+ Objects.equals(fatherNodeName1, fatherNodeName2) &&
|
|
|
+ Objects.equals(fatherNodeType1, fatherNodeType2) &&
|
|
|
+ !Objects.equals(dto1.getSubUnitCode(), dto2.getSubUnitCode());
|
|
|
+ }
|
|
|
+
|
|
|
+ private static boolean checkDivisionLevelConflict(ImportTreeDto dto1, ImportTreeDto dto2) {
|
|
|
+ String fatherNodeName1="";
|
|
|
+ Integer fatherNodeType1=0;
|
|
|
+ String fatherNodeName2="";
|
|
|
+ Integer fatherNodeType2=0;
|
|
|
+ if(dto1.getSubUnitName()!=null){
|
|
|
+ fatherNodeName1=dto1.getSubUnitName();
|
|
|
+ fatherNodeType1=dto1.getSubUnitType();
|
|
|
+ }else {
|
|
|
+ fatherNodeName1=dto1.getUnitName();
|
|
|
+ fatherNodeType1=dto1.getUnitType();
|
|
|
+ }
|
|
|
+ if(dto2.getSubUnitName()!=null){
|
|
|
+ fatherNodeName2=dto2.getSubUnitName();
|
|
|
+ fatherNodeType2=dto2.getSubUnitType();
|
|
|
+ }else {
|
|
|
+ fatherNodeName2=dto2.getUnitName();
|
|
|
+ fatherNodeType2=dto2.getUnitType();
|
|
|
+ }
|
|
|
+ return Objects.equals(dto1.getDivisionName(), dto2.getDivisionName()) &&
|
|
|
+ Objects.equals(dto1.getDivisionType(), dto2.getDivisionType()) &&
|
|
|
+ Objects.equals(fatherNodeName1, fatherNodeName2) &&
|
|
|
+ Objects.equals(fatherNodeType1, fatherNodeType2) &&
|
|
|
+ !Objects.equals(dto1.getDivisionCode(), dto2.getDivisionCode());
|
|
|
+ }
|
|
|
+
|
|
|
+ private static boolean checkSubDivisionLevelConflict(ImportTreeDto dto1, ImportTreeDto dto2) {
|
|
|
+ String fatherNodeName1="";
|
|
|
+ Integer fatherNodeType1=0;
|
|
|
+ String fatherNodeName2="";
|
|
|
+ Integer fatherNodeType2=0;
|
|
|
+ if(dto1.getDivisionName()!=null){
|
|
|
+ fatherNodeName1=dto1.getDivisionName();
|
|
|
+ fatherNodeType1=dto1.getDivisionType();
|
|
|
+ }
|
|
|
+ else if(dto1.getSubUnitName()!=null){
|
|
|
+ fatherNodeName1=dto1.getSubUnitName();
|
|
|
+ fatherNodeType1=dto1.getSubUnitType();
|
|
|
+ }else {
|
|
|
+ fatherNodeName1=dto1.getUnitName();
|
|
|
+ fatherNodeType1=dto1.getUnitType();
|
|
|
+ }
|
|
|
+ if(dto2.getDivisionName()!=null){
|
|
|
+ fatherNodeName2=dto2.getDivisionName();
|
|
|
+ fatherNodeType2=dto2.getDivisionType();
|
|
|
+ }
|
|
|
+ else if(dto2.getSubUnitName()!=null){
|
|
|
+ fatherNodeName2=dto2.getSubUnitName();
|
|
|
+ fatherNodeType2=dto2.getSubUnitType();
|
|
|
+ }else {
|
|
|
+ fatherNodeName2=dto2.getUnitName();
|
|
|
+ fatherNodeType2=dto2.getUnitType();
|
|
|
+ }
|
|
|
+ return Objects.equals(dto1.getSubDivisionName(), dto2.getSubDivisionName()) &&
|
|
|
+ Objects.equals(dto1.getSubDivisionType(), dto2.getSubDivisionType()) &&
|
|
|
+ Objects.equals(fatherNodeName1, fatherNodeName2) &&
|
|
|
+ Objects.equals(fatherNodeType1, fatherNodeType2) &&
|
|
|
+ !Objects.equals(dto1.getSubDivisionCode(), dto2.getSubDivisionCode());
|
|
|
+ }
|
|
|
+
|
|
|
+ private static boolean checkItemLevelConflict(ImportTreeDto dto1, ImportTreeDto dto2) {
|
|
|
+ String fatherNodeName1="";
|
|
|
+ Integer fatherNodeType1=0;
|
|
|
+ String fatherNodeName2="";
|
|
|
+ Integer fatherNodeType2=0;
|
|
|
+ if(dto1.getSubDivisionName()!=null){
|
|
|
+ fatherNodeName1=dto1.getSubDivisionName();
|
|
|
+ fatherNodeType1=dto1.getSubDivisionType();
|
|
|
+ }
|
|
|
+ else if(dto1.getDivisionName()!=null){
|
|
|
+ fatherNodeName1=dto1.getDivisionName();
|
|
|
+ fatherNodeType1=dto1.getDivisionType();
|
|
|
+ }
|
|
|
+ else if(dto1.getSubUnitName()!=null){
|
|
|
+ fatherNodeName1=dto1.getSubUnitName();
|
|
|
+ fatherNodeType1=dto1.getSubUnitType();
|
|
|
+ }else {
|
|
|
+ fatherNodeName1=dto1.getUnitName();
|
|
|
+ fatherNodeType1=dto1.getUnitType();
|
|
|
+ }
|
|
|
+ if(dto2.getSubDivisionName()!=null){
|
|
|
+ fatherNodeName2=dto2.getSubDivisionName();
|
|
|
+ fatherNodeType2=dto2.getSubDivisionType();
|
|
|
+ }
|
|
|
+ else if(dto2.getDivisionName()!=null){
|
|
|
+ fatherNodeName2=dto2.getDivisionName();
|
|
|
+ fatherNodeType2=dto2.getDivisionType();
|
|
|
+ }
|
|
|
+ else if(dto2.getSubUnitName()!=null){
|
|
|
+ fatherNodeName2=dto2.getSubUnitName();
|
|
|
+ fatherNodeType2=dto2.getSubUnitType();
|
|
|
+ }else {
|
|
|
+ fatherNodeName2=dto2.getUnitName();
|
|
|
+ fatherNodeType2=dto2.getUnitType();
|
|
|
+ }
|
|
|
+ return Objects.equals(dto1.getItemName(), dto2.getItemName()) &&
|
|
|
+ Objects.equals(dto1.getItemType(), dto2.getItemType()) &&
|
|
|
+ Objects.equals(fatherNodeName1, fatherNodeName2) &&
|
|
|
+ Objects.equals(fatherNodeType1, fatherNodeType2) &&
|
|
|
+ !Objects.equals(dto1.getItemCode(), dto2.getItemCode());
|
|
|
+ }
|
|
|
+
|
|
|
+ private static boolean checkSubItemLevelConflict(ImportTreeDto dto1, ImportTreeDto dto2) {
|
|
|
+ String fatherNodeName1="";
|
|
|
+ Integer fatherNodeType1=0;
|
|
|
+ String fatherNodeName2="";
|
|
|
+ Integer fatherNodeType2=0;
|
|
|
+ if(dto1.getItemName()!=null){
|
|
|
+ fatherNodeName1=dto1.getItemName();
|
|
|
+ fatherNodeType1=dto1.getItemType();
|
|
|
+ }
|
|
|
+ else if(dto1.getSubDivisionName()!=null){
|
|
|
+ fatherNodeName1=dto1.getSubDivisionName();
|
|
|
+ fatherNodeType1=dto1.getSubDivisionType();
|
|
|
+ }
|
|
|
+ else if(dto1.getDivisionName()!=null){
|
|
|
+ fatherNodeName1=dto1.getDivisionName();
|
|
|
+ fatherNodeType1=dto1.getDivisionType();
|
|
|
+ }
|
|
|
+ else if(dto1.getSubUnitName()!=null){
|
|
|
+ fatherNodeName1=dto1.getSubUnitName();
|
|
|
+ fatherNodeType1=dto1.getSubUnitType();
|
|
|
+ }else {
|
|
|
+ fatherNodeName1=dto1.getUnitName();
|
|
|
+ fatherNodeType1=dto1.getUnitType();
|
|
|
+ }
|
|
|
+ if(dto2.getItemName()!=null){
|
|
|
+ fatherNodeName2=dto2.getItemName();
|
|
|
+ fatherNodeType2=dto2.getItemType();
|
|
|
+ }
|
|
|
+ else if(dto2.getSubDivisionName()!=null){
|
|
|
+ fatherNodeName2=dto2.getSubDivisionName();
|
|
|
+ fatherNodeType2=dto2.getSubDivisionType();
|
|
|
+ }
|
|
|
+ else if(dto2.getDivisionName()!=null){
|
|
|
+ fatherNodeName2=dto2.getDivisionName();
|
|
|
+ fatherNodeType2=dto2.getDivisionType();
|
|
|
+ }
|
|
|
+ else if(dto2.getSubUnitName()!=null){
|
|
|
+ fatherNodeName2=dto2.getSubUnitName();
|
|
|
+ fatherNodeType2=dto2.getSubUnitType();
|
|
|
+ }else {
|
|
|
+ fatherNodeName2=dto2.getUnitName();
|
|
|
+ fatherNodeType2=dto2.getUnitType();
|
|
|
+ }
|
|
|
+ return Objects.equals(dto1.getSubItemName(), dto2.getSubItemName()) &&
|
|
|
+ Objects.equals(dto1.getSubItemType(), dto2.getSubItemType()) &&
|
|
|
+ Objects.equals(fatherNodeName1, fatherNodeName2) &&
|
|
|
+ Objects.equals(fatherNodeType1, fatherNodeType2) &&
|
|
|
+ !Objects.equals(dto1.getSubItemCode(), dto2.getSubItemCode());
|
|
|
+ }
|
|
|
+ private Boolean isExist(ImportTreeDto dto, List<WbsTreeContract> wbsTreeContractList, int type,Long contractId) {
|
|
|
+ String nodeName="";
|
|
|
+ if(type==1){
|
|
|
+ nodeName=dto.getUnitName();
|
|
|
+ }
|
|
|
+ else if(type==2){
|
|
|
+ nodeName=dto.getSubUnitName();
|
|
|
+ }
|
|
|
+ else if(type==3){
|
|
|
+ nodeName=dto.getDivisionName();
|
|
|
+ }
|
|
|
+ else if(type==4){
|
|
|
+ nodeName=dto.getSubDivisionName();
|
|
|
+ }
|
|
|
+ else if(type==5){
|
|
|
+ nodeName=dto.getItemName();
|
|
|
+ }
|
|
|
+ else if(type==6){
|
|
|
+ nodeName=dto.getSubItemName();
|
|
|
+ }
|
|
|
+ String finalNodeName = nodeName;
|
|
|
+ List<Long> list = wbsTreeContractList.stream()
|
|
|
+ .filter(item -> finalNodeName.equals(item.getNodeName()))
|
|
|
+ .map(item -> item.getParentId())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if(list.size()==0){
|
|
|
+ return false;
|
|
|
+ }else {
|
|
|
+ if(type==1){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ //如果数据库中存在名称相同的节点,查询该节点的祖级节点
|
|
|
+ String sql="select node_name from m_wbs_tree_contract where is_deleted=0 and contract_id="+contractId+" and id in ("+String.join(",", list.stream().map(String::valueOf).collect(Collectors.toList()))+")";
|
|
|
+ List<String> nodeNames = jdbcTemplate.query(sql, new SingleColumnRowMapper<>(String.class));
|
|
|
+ String fatherNodeName="";
|
|
|
+ if(type==2){
|
|
|
+ fatherNodeName=dto.getUnitName();
|
|
|
+ }
|
|
|
+ else if(type==3){
|
|
|
+ if(dto.getSubUnitName()!=null&&!dto.getSubUnitName().equals("")){
|
|
|
+ fatherNodeName=dto.getSubUnitName();
|
|
|
+ }else if(dto.getUnitName()!=null&&!dto.getUnitName().equals("")){
|
|
|
+ fatherNodeName=dto.getUnitName();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if(type==4){
|
|
|
if(dto.getDivisionName()!=null&&!dto.getDivisionName().equals("")){
|
|
|
fatherNodeName=dto.getDivisionName();
|
|
|
} else if(dto.getSubUnitName()!=null&&!dto.getSubUnitName().equals("")){
|
|
@@ -2370,129 +2889,44 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
}else if(dto.getUnitName()!=null&&!dto.getUnitName().equals("")){
|
|
|
fatherNodeName=dto.getUnitName();
|
|
|
}
|
|
|
- List<WbsTreeContract> list1 = baseMapper.selectList(Wrappers.<WbsTreeContract>lambdaQuery().eq(WbsTreeContract::getNodeName, fatherNodeName).eq(WbsTreeContract::getProjectId, wbsTreeContractRoot.getProjectId())
|
|
|
- .eq(WbsTreeContract::getContractId, wbsTreeContractRoot.getContractId()).eq(WbsTreeContract::getIsDeleted, 0));
|
|
|
- if(list1.size()>0){
|
|
|
- for (WbsTreeContract contract : list1) {
|
|
|
- String[] ids = contract.getAncestors().split(",");
|
|
|
- ids=Arrays.stream(ids)
|
|
|
- .filter(id -> !id.equals("0")) // 过滤掉值为 "0" 的元素
|
|
|
- .toArray(String[]::new);
|
|
|
- String sql="Select node_name from m_wbs_tree_contract where id in("+String.join("','", ids)+")";
|
|
|
- List<String> nodeNames = jdbcTemplate.query(sql, new SingleColumnRowMapper<>(String.class));
|
|
|
- String result = String.join("",nodeNames);
|
|
|
- String ancestorsName=dto.getUnitName()!=null?dto.getUnitName():""+dto.getSubUnitName()!=null?dto.getSubUnitName():""+dto.getDivisionName()!=null?dto.getDivisionName():"";
|
|
|
- if(result.equals(ancestorsName)){
|
|
|
- WbsTreeContract subDivision = new WbsTreeContract();
|
|
|
- BeanUtil.copy(contract,subDivision);
|
|
|
- subDivision.setPKeyId(SnowFlakeUtil.getId());
|
|
|
- subDivision.setId(SnowFlakeUtil.getId());
|
|
|
- subDivision.setParentId(contract.getId());
|
|
|
- subDivision.setAncestors(contract.getAncestors()+","+subDivision.getId());
|
|
|
- subDivision.setIsCustom(1);
|
|
|
- subDivision.setIsTypePrivatePid(null);
|
|
|
- subDivision.setNodeType(3);
|
|
|
- insertList.add(subDivision);
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
- //分项节点:如果没有被处理过,说明需要新增,最重要是需要找到父节点。现在的办法是(通过祖级节点名称拼接的方式来判断)。
|
|
|
- if(!dto.getIsItem()){
|
|
|
- String fatherNodeName="";
|
|
|
- if(dto.getItemName()!=null&&!dto.getItemName().equals("")){
|
|
|
- fatherNodeName=dto.getItemName();
|
|
|
- } else if(dto.getDivisionName()!=null&&!dto.getDivisionName().equals("")){
|
|
|
+ else if(type==5){
|
|
|
+ if(dto.getSubDivisionName()!=null&&!dto.getSubDivisionName().equals("")){
|
|
|
+ fatherNodeName=dto.getSubDivisionName();
|
|
|
+ }
|
|
|
+ else if(dto.getDivisionName()!=null&&!dto.getDivisionName().equals("")){
|
|
|
fatherNodeName=dto.getDivisionName();
|
|
|
} else if(dto.getSubUnitName()!=null&&!dto.getSubUnitName().equals("")){
|
|
|
fatherNodeName=dto.getSubUnitName();
|
|
|
}else if(dto.getUnitName()!=null&&!dto.getUnitName().equals("")){
|
|
|
fatherNodeName=dto.getUnitName();
|
|
|
}
|
|
|
- List<WbsTreeContract> list1 = baseMapper.selectList(Wrappers.<WbsTreeContract>lambdaQuery().eq(WbsTreeContract::getNodeName, fatherNodeName).eq(WbsTreeContract::getProjectId, wbsTreeContractRoot.getProjectId())
|
|
|
- .eq(WbsTreeContract::getContractId, wbsTreeContractRoot.getContractId()).eq(WbsTreeContract::getIsDeleted, 0));
|
|
|
- if(list1.size()>0){
|
|
|
- for (WbsTreeContract contract : list1) {
|
|
|
- String[] ids = contract.getAncestors().split(",");
|
|
|
- ids=Arrays.stream(ids)
|
|
|
- .filter(id -> !id.equals("0")) // 过滤掉值为 "0" 的元素
|
|
|
- .toArray(String[]::new);
|
|
|
- String sql="Select node_name from m_wbs_tree_contract where id in("+String.join("','", ids)+")";
|
|
|
- List<String> nodeNames = jdbcTemplate.query(sql, new SingleColumnRowMapper<>(String.class));
|
|
|
- String result = String.join("",nodeNames);
|
|
|
- String ancestorsName=dto.getUnitName()!=null?dto.getUnitName():""+dto.getSubUnitName()!=null?dto.getSubUnitName():""+dto.getDivisionName()!=null?dto.getDivisionName():""+dto.getSubUnitName()!=null?dto.getSubUnitName():"";
|
|
|
- if(result.equals(ancestorsName)){
|
|
|
- WbsTreeContract item = new WbsTreeContract();
|
|
|
- BeanUtil.copy(contract,item);
|
|
|
- item.setPKeyId(SnowFlakeUtil.getId());
|
|
|
- item.setId(SnowFlakeUtil.getId());
|
|
|
- item.setParentId(contract.getId());
|
|
|
- item.setAncestors(contract.getAncestors()+","+item.getId());
|
|
|
- item.setIsCustom(1);
|
|
|
- item.setIsTypePrivatePid(null);
|
|
|
- item.setNodeType(4);
|
|
|
- insertList.add(item);
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
- //子分项节点:如果没有被处理过,说明需要新增,最重要是需要找到父节点。现在的办法是(通过祖级节点名称拼接的方式来判断)。
|
|
|
- if(!dto.getIsSubItem()){
|
|
|
- String fatherNodeName="";
|
|
|
- if(dto.getSubItemName()!=null&&!dto.getSubItemName().equals("")){
|
|
|
- fatherNodeName=dto.getSubItemName();
|
|
|
- }else if(dto.getItemName()!=null&&!dto.getItemName().equals("")){
|
|
|
- fatherNodeName=dto.getItemName();
|
|
|
- } else if(dto.getDivisionName()!=null&&!dto.getDivisionName().equals("")){
|
|
|
+ else if(type==6){
|
|
|
+ if(dto.getItemName()!=null&&!dto.getItemName().equals("")){
|
|
|
+ } else if(dto.getSubDivisionName()!=null&&!dto.getSubDivisionName().equals("")){
|
|
|
+ fatherNodeName=dto.getSubDivisionName();
|
|
|
+ }
|
|
|
+ else if(dto.getDivisionName()!=null&&!dto.getDivisionName().equals("")){
|
|
|
fatherNodeName=dto.getDivisionName();
|
|
|
} else if(dto.getSubUnitName()!=null&&!dto.getSubUnitName().equals("")){
|
|
|
fatherNodeName=dto.getSubUnitName();
|
|
|
}else if(dto.getUnitName()!=null&&!dto.getUnitName().equals("")){
|
|
|
fatherNodeName=dto.getUnitName();
|
|
|
}
|
|
|
- List<WbsTreeContract> list1 = baseMapper.selectList(Wrappers.<WbsTreeContract>lambdaQuery().eq(WbsTreeContract::getNodeName, fatherNodeName).eq(WbsTreeContract::getProjectId, wbsTreeContractRoot.getProjectId())
|
|
|
- .eq(WbsTreeContract::getContractId, wbsTreeContractRoot.getContractId()).eq(WbsTreeContract::getIsDeleted, 0));
|
|
|
- if(list1.size()>0){
|
|
|
- for (WbsTreeContract contract : list1) {
|
|
|
- String[] ids = contract.getAncestors().split(",");
|
|
|
- ids=Arrays.stream(ids)
|
|
|
- .filter(id -> !id.equals("0")) // 过滤掉值为 "0" 的元素
|
|
|
- .toArray(String[]::new);
|
|
|
- String sql="Select node_name from m_wbs_tree_contract where id in("+String.join("','", ids)+")";
|
|
|
- List<String> nodeNames = jdbcTemplate.query(sql, new SingleColumnRowMapper<>(String.class));
|
|
|
- String result = String.join("",nodeNames);
|
|
|
- String ancestorsName=dto.getUnitName()!=null?dto.getUnitName():""+dto.getSubUnitName()!=null?dto.getSubUnitName():""+dto.getDivisionName()!=null?dto.getDivisionName():""+dto.getSubUnitName()!=null?dto.getSubUnitName():""+dto.getItemName()!=null?dto.getItemName():"";
|
|
|
- if(result.equals(ancestorsName)){
|
|
|
- WbsTreeContract subItem = new WbsTreeContract();
|
|
|
- BeanUtil.copy(contract,subItem);
|
|
|
- subItem.setPKeyId(SnowFlakeUtil.getId());
|
|
|
- subItem.setId(SnowFlakeUtil.getId());
|
|
|
- subItem.setParentId(contract.getId());
|
|
|
- subItem.setAncestors(contract.getAncestors()+","+subItem.getId());
|
|
|
- subItem.setIsCustom(1);
|
|
|
- subItem.setIsTypePrivatePid(null);
|
|
|
- subItem.setNodeType(5);
|
|
|
- insertList.add(subItem);
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
+
|
|
|
+ if(nodeNames.size()>0&&nodeNames.contains(fatherNodeName)){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
}
|
|
|
- if(insertList.size()>0){
|
|
|
- baseMapper.insertBatchSomeColumn(insertList);
|
|
|
- }
|
|
|
- return R.success("新增了"+insertList.size()+"个节点"+","+String.join(",",updateList)+"节点编号已被修改");
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
//判断名称是否都在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(","))+")";
|
|
|
+ String sql="select node_name from m_wbs_tree_contract where p_key_id in ("+String.join(",", vo.getAncestors().split(","))+")";
|
|
|
List<String> ancestorNames = jdbcTemplate.query(sql, new SingleColumnRowMapper<>(String.class));
|
|
|
list.removeIf(Objects::isNull);
|
|
|
if(!ancestorNames.isEmpty()){
|
|
@@ -3111,4 +3545,46 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ public void updateAncestors() {
|
|
|
+ // 获取所有节点
|
|
|
+ List<WbsTreeContract> allNodes = baseMapper.selectList(new LambdaQueryWrapper<>(WbsTreeContract.class).eq(WbsTreeContract::getProjectId,1630011899725201410L));
|
|
|
+
|
|
|
+ // 构建父子关系映射
|
|
|
+ Map<Long, List<WbsTreeContract>> parentChildMap = new HashMap<>();
|
|
|
+ Map<Long, WbsTreeContract> nodeMap = new HashMap<>();
|
|
|
+
|
|
|
+ for (WbsTreeContract node : allNodes) {
|
|
|
+ nodeMap.put(node.getId(), node);
|
|
|
+ parentChildMap.computeIfAbsent(node.getParentId(), k -> new ArrayList<>()).add(node);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 从根节点开始递归设置 ancestors
|
|
|
+ List<WbsTreeContract> rootNodes = parentChildMap.getOrDefault(0L, Collections.emptyList());
|
|
|
+ for (WbsTreeContract rootNode : rootNodes) {
|
|
|
+ setAncestors(rootNode, parentChildMap, nodeMap);
|
|
|
+ }
|
|
|
+ System.out.println("完成");
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setAncestors(WbsTreeContract node, Map<Long, List<WbsTreeContract>> parentChildMap, Map<Long, WbsTreeContract> nodeMap) {
|
|
|
+ if (node.getParentId() == 0) {
|
|
|
+ node.setAncestors("");
|
|
|
+ } else {
|
|
|
+ WbsTreeContract parentNode = nodeMap.get(node.getParentId());
|
|
|
+ if (parentNode != null) {
|
|
|
+ node.setAncestors(parentNode.getAncestors() + (parentNode.getAncestors().isEmpty() ? "" : ",") + parentNode.getPKeyId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新数据库
|
|
|
+ UpdateWrapper<WbsTreeContract> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper.eq("id", node.getId()).eq("project_id",node.getProjectId()).set("ancestors", node.getAncestors());
|
|
|
+ baseMapper.update(null, updateWrapper);
|
|
|
+
|
|
|
+ // 递归处理子节点
|
|
|
+ List<WbsTreeContract> children = parentChildMap.getOrDefault(node.getId(), Collections.emptyList());
|
|
|
+ for (WbsTreeContract child : children) {
|
|
|
+ setAncestors(child, parentChildMap, nodeMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|