|
@@ -222,13 +222,7 @@ public class WbsTreeContractStatisticsServiceImpl extends ServiceImpl<WbsTreeCon
|
|
|
}
|
|
|
|
|
|
private void updateStatusAndIsDeleted(Long contractId) {
|
|
|
- List<WbsTreeContractStatistics> query = jdbcTemplate.query("SELECT a.id,b.status,b.is_deleted from m_wbs_tree_contract_statistics a LEFT JOIN m_wbs_tree_contract b on a.id = b.p_key_id WHERE (a.status != b.status OR a.is_deleted != b.is_deleted) AND b.p_key_id IS NOT NULl and a.contract_id = " + contractId,
|
|
|
- new BeanPropertyRowMapper<>(WbsTreeContractStatistics.class));
|
|
|
- if (query.isEmpty()) {
|
|
|
- return;
|
|
|
- }
|
|
|
- List<WbsTreeContractStatistics> list = query.stream().filter(item -> item.getStatus() != null && item.getIsDeleted() != null).collect(Collectors.toList());
|
|
|
- this.updateBatchById(list);
|
|
|
+ jdbcTemplate.execute("update m_wbs_tree_contract_statistics a LEFT JOIN m_wbs_tree_contract b on a.id = b.p_key_id set a.status = ifnull(b.status, a.status) , a.is_deleted = IFNULL(b.is_deleted,a.is_deleted) WHERE (a.status != b.status OR a.is_deleted != b.is_deleted) AND b.p_key_id IS NOT NULl and a.contract_id = " + contractId);
|
|
|
}
|
|
|
|
|
|
public Boolean updateLeafNum(String ids) {
|
|
@@ -240,6 +234,92 @@ public class WbsTreeContractStatisticsServiceImpl extends ServiceImpl<WbsTreeCon
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void updateAncestors(String ids) {
|
|
|
+ if (!StringUtil.hasText(ids)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String[] split = ids.split(",");
|
|
|
+ if (split.length == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<Long, Long> map = new HashMap<>();
|
|
|
+ {
|
|
|
+ ids = Arrays.stream(split).filter(StringUtil::isNumeric).distinct().collect(Collectors.joining(","));
|
|
|
+ List<WbsTreeContract> query = jdbcTemplate.query("SELECT id,p_key_id,p_id,parent_id FROM m_wbs_tree_contract WHERE is_deleted = 0 and type = 1 and p_key_id in (" + String.join(",", ids) + ")", new BeanPropertyRowMapper<>(WbsTreeContract.class));
|
|
|
+ if (query.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 只更新父级节点
|
|
|
+ Map<Long, List<WbsTreeContract>> childrenMap = query.stream().collect(Collectors.groupingBy(WbsTreeContract::getPId));
|
|
|
+ for (WbsTreeContract wbsTreeContract : query) {
|
|
|
+ List<WbsTreeContract> list = childrenMap.get(wbsTreeContract.getPKeyId());
|
|
|
+ if (list == null) {
|
|
|
+ // 更新当前节点 parent ancestors字段
|
|
|
+ map.put(wbsTreeContract.getPKeyId(), wbsTreeContract.getPId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (map.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<WbsTreeContractStatistics> wbsTreeContractStatistics = this.listByIds(map.keySet());
|
|
|
+ List<WbsTreeContractStatistics> parentList = this.listByIds(map.values());
|
|
|
+ Map<Long, WbsTreeContractStatistics> parentMap = parentList.stream().collect(Collectors.toMap(WbsTreeContractStatistics::getId, item -> item));
|
|
|
+ List<WbsTreeContractStatistics> updateList = new ArrayList<>();
|
|
|
+ List<String> sqlList = new ArrayList<>();
|
|
|
+ for (WbsTreeContractStatistics statistics : wbsTreeContractStatistics) {
|
|
|
+ Long parentId = map.get(statistics.getId());
|
|
|
+ WbsTreeContractStatistics update = new WbsTreeContractStatistics();
|
|
|
+ update.setId(statistics.getId());
|
|
|
+ if (parentId == null) {
|
|
|
+ update.setParentId(0L);
|
|
|
+ update.setAncestors("0");
|
|
|
+ updateList.add(update);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ WbsTreeContractStatistics parent = parentMap.get(parentId);
|
|
|
+ if (parent == null) {
|
|
|
+ update.setParentId(0L);
|
|
|
+ update.setAncestors("0");
|
|
|
+ updateList.add(update);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ update.setParentId(parent.getId());
|
|
|
+ update.setAncestors(parent.getAncestors() + "," + parent.getId());
|
|
|
+ updateList.add(update);
|
|
|
+ WbsTreeContractStatistics temp = new WbsTreeContractStatistics();
|
|
|
+ temp.setId(statistics.getParentId());
|
|
|
+ temp.setAncestors(statistics.getAncestors());
|
|
|
+ parentMap.put(statistics.getParentId(), temp);
|
|
|
+ String oldAncestors = statistics.getAncestors() + "," + statistics.getId();
|
|
|
+ String newAncestors = update.getAncestors() + "," + statistics.getId();
|
|
|
+ String sql = "UPDATE m_wbs_tree_contract_statistics SET ancestors = replace(ancestors, '" + oldAncestors + "', '" + newAncestors + "') WHERE is_deleted = 0 and status = 1 and ancestors like '"
|
|
|
+ + oldAncestors + "%' and contract_id = " + statistics.getContractId();
|
|
|
+ sqlList.add(sql);
|
|
|
+ }
|
|
|
+ Set<Long> parentIds = new HashSet<>();
|
|
|
+ parentMap.values().forEach(item -> {
|
|
|
+ parentIds.add(item.getId());
|
|
|
+ String ancestors = item.getAncestors();
|
|
|
+ if (ancestors != null && !ancestors.isEmpty()) {
|
|
|
+ String[] split1 = ancestors.split(",");
|
|
|
+ for (String s : split1) {
|
|
|
+ if (StringUtil.isNumeric(s)) {
|
|
|
+ parentIds.add(Long.parseLong(s));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ this.updateBatchById(updateList);
|
|
|
+ for (String s : sqlList) {
|
|
|
+ jdbcTemplate.update(s);
|
|
|
+ }
|
|
|
+ if (!parentIds.isEmpty()) {
|
|
|
+ this.baseMapper.updateLeafNum(parentIds);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public void createWbsTreeContractStatisticsParent(WbsTreeContract wbsTreeContract, WbsTreeContractStatistics wbsTreeContractStatistics, List<WbsTreeContractStatistics> wbsTreeContractStatisticsList) {
|
|
|
if (wbsTreeContract.getParentId() == null || wbsTreeContract.getParentId() <= 0) {
|
|
|
wbsTreeContractStatistics.setParentId(0L);
|
|
@@ -253,6 +333,7 @@ public class WbsTreeContractStatisticsServiceImpl extends ServiceImpl<WbsTreeCon
|
|
|
return;
|
|
|
}
|
|
|
parent = createWbsTreeContractStatistics(wbsTreeContractParent);
|
|
|
+ parent.setIsLeaf(0);
|
|
|
createWbsTreeContractStatisticsParent(wbsTreeContractParent, parent, wbsTreeContractStatisticsList);
|
|
|
wbsTreeContractStatisticsList.add(parent);
|
|
|
} else {
|
|
@@ -260,20 +341,24 @@ public class WbsTreeContractStatisticsServiceImpl extends ServiceImpl<WbsTreeCon
|
|
|
wbsTreeContractStatistics.setParentId(parent.getId());
|
|
|
wbsTreeContractStatistics.setAncestors(parent.getAncestors() + "," + parent.getId());
|
|
|
}
|
|
|
+ if (parent.getIsLeaf() == 1) {
|
|
|
+ this.update(Wrappers.<WbsTreeContractStatistics>lambdaUpdate().eq(WbsTreeContractStatistics::getId, parent.getId()).set(WbsTreeContractStatistics::getIsLeaf, 0));
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void createWbsTreeContractStatisticsChildren(WbsTreeContract wbsTreeContract, WbsTreeContractStatistics wbsTreeContractStatistics, List<WbsTreeContractStatistics> wbsTreeContractStatisticsList) {
|
|
|
List<WbsTreeContract> wbsTreeContracts = jdbcTemplate.query("select * from m_wbs_tree_contract where is_deleted = 0 and type = 1 and contract_id = ? and p_id = ?",
|
|
|
new Object[]{wbsTreeContract.getContractId(), wbsTreeContract.getPKeyId()}, new BeanPropertyRowMapper<>(WbsTreeContract.class));
|
|
|
- if (wbsTreeContracts == null || wbsTreeContracts.isEmpty()) {
|
|
|
+ if (wbsTreeContracts.isEmpty()) {
|
|
|
wbsTreeContractStatistics.setIsLeaf(1);
|
|
|
wbsTreeContractStatistics.setLeafNum(0);
|
|
|
return;
|
|
|
}
|
|
|
+ wbsTreeContractStatistics.setIsLeaf(0);
|
|
|
wbsTreeContracts.forEach(item -> {
|
|
|
WbsTreeContractStatistics statistics = createWbsTreeContractStatistics(item);
|
|
|
- createWbsTreeContractStatisticsChildren(item, wbsTreeContractStatistics, wbsTreeContractStatisticsList);
|
|
|
+ createWbsTreeContractStatisticsChildren(item, statistics, wbsTreeContractStatisticsList);
|
|
|
statistics.setAncestors(wbsTreeContractStatistics.getAncestors() + "," + wbsTreeContractStatistics.getId());
|
|
|
statistics.setParentId(wbsTreeContractStatistics.getId());
|
|
|
wbsTreeContractStatisticsList.add(statistics);
|