|
@@ -103,11 +103,12 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
public boolean submitWbsTreeInContract(WbsTreeContractDTO pawDTO) {
|
|
|
String wbsTreeIds = pawDTO.getWbsTreeIds();
|
|
|
String[] ids = wbsTreeIds.split(",");
|
|
|
+ //项目对应到合同段的入参节点ids
|
|
|
List<String> idList = Arrays.asList(ids);
|
|
|
List<String> idList1 = idList.stream().filter(string -> !string.isEmpty()).collect(Collectors.toList());
|
|
|
|
|
|
- //获取当前合同段所有节点、表单(不包括客户端新增或者复制节点)
|
|
|
- List<WbsTreeContract> list = baseMapper.selectList(Wrappers.<WbsTreeContract>lambdaQuery()
|
|
|
+ //获取当前合同段所有节点、表单(不包括客户端新增或者复制节点)
|
|
|
+ List<WbsTreeContract> nowContractNodeAndTabAll = baseMapper.selectList(Wrappers.<WbsTreeContract>lambdaQuery()
|
|
|
.select(WbsTreeContract::getId, WbsTreeContract::getType)
|
|
|
.eq(WbsTreeContract::getContractId, pawDTO.getContractId())
|
|
|
.eq(WbsTreeContract::getWbsId, pawDTO.getWbsId())
|
|
@@ -115,56 +116,55 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
.isNull(WbsTreeContract::getOldId));
|
|
|
|
|
|
//当前合同段所有表单ids
|
|
|
- List<String> collect1 = new ArrayList<>();
|
|
|
+ List<String> nowContractTabIds = new ArrayList<>();
|
|
|
//当前合同段所有节点ids
|
|
|
- List<String> collect2 = new ArrayList<>();
|
|
|
- if (list.size() > 0) {
|
|
|
- collect1 = list.stream().filter(f -> f.getType() == 2).collect(Collectors.toList()).stream().map(WbsTreeContract::getId).map(String::valueOf).collect(Collectors.toList());
|
|
|
- collect2 = list.stream().filter(f -> f.getType() == 1).collect(Collectors.toList()).stream().map(WbsTreeContract::getId).map(String::valueOf).collect(Collectors.toList());
|
|
|
+ List<String> nowContractNodeIds = new ArrayList<>();
|
|
|
+ if (nowContractNodeAndTabAll.size() > 0) {
|
|
|
+ nowContractTabIds = nowContractNodeAndTabAll.stream().filter(f -> f.getType() == 2).collect(Collectors.toList()).stream().map(WbsTreeContract::getId).map(String::valueOf).collect(Collectors.toList());
|
|
|
+ nowContractNodeIds = nowContractNodeAndTabAll.stream().filter(f -> f.getType() == 1).collect(Collectors.toList()).stream().map(WbsTreeContract::getId).map(String::valueOf).collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
- List<String> collect3 = collect2;
|
|
|
- List<String> saveIds = idList1.stream().filter(f -> !collect3.contains(f)).collect(Collectors.toList());
|
|
|
- List<String> delIds = collect3.stream().filter(f -> !idList1.contains(f)).collect(Collectors.toList());
|
|
|
+ List<String> finalNowContractNodeIds = nowContractNodeIds;
|
|
|
+ List<String> saveIds = idList1.stream().filter(f -> !finalNowContractNodeIds.contains(f)).collect(Collectors.toList());
|
|
|
+ List<String> delIds = finalNowContractNodeIds.stream().filter(f -> !idList1.contains(f)).collect(Collectors.toList());
|
|
|
|
|
|
//TODO ---------节点未变只同步元素表---------
|
|
|
if (saveIds.size() == 0 && delIds.size() == 0) {
|
|
|
- //当前项目节点下的所有表单Ids
|
|
|
- List<String> collect = new ArrayList<>();
|
|
|
-
|
|
|
- //当前项目所有表
|
|
|
- List<WbsTreePrivate> wbsTreePrivateList = wbsTreePrivateMapper.selectList(Wrappers.<WbsTreePrivate>query().lambda()
|
|
|
+ //当前项目所有原始表(从公有树到项目私有树同步后的,或是私有到私有的)
|
|
|
+ List<WbsTreePrivate> nowProjectTabs = wbsTreePrivateMapper.selectList(Wrappers.<WbsTreePrivate>query().lambda()
|
|
|
.select(WbsTreePrivate::getId, WbsTreePrivate::getParentId, WbsTreePrivate::getType)
|
|
|
.eq(WbsTreePrivate::getProjectId, pawDTO.getProjectId())
|
|
|
.eq(WbsTreePrivate::getWbsId, pawDTO.getWbsId())
|
|
|
.eq(WbsTreePrivate::getStatus, 1)
|
|
|
.eq(WbsTreePrivate::getType, 2)
|
|
|
);
|
|
|
+ //判断当前的表是否有在合同段中有上级节点(不存在上级节点的表说明没有分配,不参与同步,根据入参的节点id与当前项目表的parentId判断)
|
|
|
+ List<String> saveSyncTabIds = nowProjectTabs.stream()
|
|
|
+ .flatMap(wbsTreePrivate -> idList1.stream()
|
|
|
+ .filter(id -> Long.parseLong(id) == (wbsTreePrivate.getParentId()) && wbsTreePrivate.getType() == 2)
|
|
|
+ .map(id -> String.valueOf(wbsTreePrivate.getId())))
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
|
- wbsTreePrivateList.forEach(wbsTreePrivate -> {
|
|
|
- idList1.forEach(id -> {
|
|
|
- if (Long.parseLong(id) == (wbsTreePrivate.getParentId()) && wbsTreePrivate.getType() == 2) {
|
|
|
- collect.add(wbsTreePrivate.getId() + "");
|
|
|
- }
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
- if (collect.size() == collect1.size()) {
|
|
|
+ //如果当前项目表与入参合同段的表一样数量,那么不需要同步
|
|
|
+ if (saveSyncTabIds.size() == nowContractTabIds.size()) {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- List<String> finalCollect = collect1;
|
|
|
- List<String> collect5 = collect.stream().filter(f -> !finalCollect.contains(f)).collect(Collectors.toList());
|
|
|
+ //不同表(需要保存的表),根据当前合同段判断
|
|
|
+ List<String> finalCollect = nowContractTabIds;
|
|
|
+ List<String> saveTabIds = saveSyncTabIds.stream().filter(f -> !finalCollect.contains(f)).collect(Collectors.toList());
|
|
|
|
|
|
+ //构造结果集
|
|
|
List<WbsTreeContract> wbsTreeContractResultData = new ArrayList<>();
|
|
|
- if (collect5.size() > 0) {
|
|
|
- List<WbsTreeContract> wbsTreeContractList = baseMapper.selectList(Wrappers.<WbsTreeContract>lambdaQuery().in(WbsTreeContract::getId, collect5)
|
|
|
- .eq(WbsTreeContract::getContractId, pawDTO.getContractId())
|
|
|
- .eq(WbsTreeContract::getWbsId, pawDTO.getWbsId())
|
|
|
- .eq(WbsTreeContract::getType, 2)
|
|
|
- .eq(WbsTreeContract::getStatus, 1)
|
|
|
- );
|
|
|
- wbsTreeContractList.forEach(obj -> {
|
|
|
+ if (!saveTabIds.isEmpty()) {
|
|
|
+ //获取对应需要同步的表信息(项目级)
|
|
|
+ List<WbsTreePrivate> needSaveSyncProjectTabs = wbsTreePrivateMapper.selectList(Wrappers.<WbsTreePrivate>lambdaQuery()
|
|
|
+ .in(WbsTreePrivate::getId, saveTabIds)
|
|
|
+ .eq(WbsTreePrivate::getProjectId, pawDTO.getProjectId())
|
|
|
+ .eq(WbsTreePrivate::getWbsId, pawDTO.getWbsId())
|
|
|
+ .eq(WbsTreePrivate::getType, 2)
|
|
|
+ .eq(WbsTreePrivate::getStatus, 1));
|
|
|
+ needSaveSyncProjectTabs.forEach(obj -> {
|
|
|
WbsTreeContract wbsTreeContract = BeanUtil.copyProperties(obj, WbsTreeContract.class);
|
|
|
if (wbsTreeContract != null) {
|
|
|
wbsTreeContract.setPKeyId(SnowFlakeUtil.getId());
|
|
@@ -172,6 +172,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
wbsTreeContract.setProjectId(pawDTO.getProjectId());
|
|
|
wbsTreeContract.setContractId(pawDTO.getContractId());
|
|
|
wbsTreeContract.setIsTypePrivatePid(obj.getPKeyId());
|
|
|
+ wbsTreeContract.setCreateTime(new Date());
|
|
|
if (obj.getType() == 2) {
|
|
|
wbsTreeContract.setIsTypePrivatePid(obj.getPKeyId());
|
|
|
}
|
|
@@ -181,7 +182,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
}
|
|
|
|
|
|
if (wbsTreeContractResultData.size() > 0) {
|
|
|
- //获取当前合同段的复制节点或者新增节点(最底层节点)
|
|
|
+ //获取当前合同段的复制节点或者新增节点最底层节点(只有最底层节点存在元素表)
|
|
|
String sql = "SELECT a.id, a.old_id," +
|
|
|
" (SELECT CASE WHEN COUNT(1) > 0 THEN 1 ELSE 0 END" +
|
|
|
" FROM m_wbs_tree_contract b" +
|
|
@@ -202,38 +203,53 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
" AND a.old_id is not null" +
|
|
|
" HAVING hasChildren = 0";
|
|
|
List<WbsTreeContract> copyAndAddNodeList = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(WbsTreeContract.class));
|
|
|
- List<WbsTreeContract> copyAddNodeTabs = new ArrayList<>();
|
|
|
+
|
|
|
+ //新增复制节点对应的表结果集
|
|
|
+ List<WbsTreeContract> copyAddNodeTabsResult = new ArrayList<>();
|
|
|
if (copyAndAddNodeList.size() > 0) {
|
|
|
- //转换为Map,oldId作为Key,id作为value
|
|
|
+ //转换为Map,oldId作为Key,id作为Value
|
|
|
Map<String, List<WbsTreeContract>> oldIdToIdMap = copyAndAddNodeList.stream().collect(Collectors.groupingBy(WbsTreeContract::getOldId));
|
|
|
for (WbsTreeContract synTab : wbsTreeContractResultData) {
|
|
|
- List<WbsTreeContract> nodeIds = oldIdToIdMap.get(synTab.getParentId().toString());
|
|
|
- if (nodeIds != null && nodeIds.size() > 0) {
|
|
|
- WbsTreeContract copyAddNodeTab = BeanUtil.copyProperties(synTab, WbsTreeContract.class);
|
|
|
- for (WbsTreeContract nodeId : nodeIds) {
|
|
|
+ //获取每张需要同步的表与之对应的新增或复制的节点
|
|
|
+ List<WbsTreeContract> copyOrAddNodes = oldIdToIdMap.get(synTab.getParentId().toString());
|
|
|
+ if (copyOrAddNodes != null && copyOrAddNodes.size() > 0) {
|
|
|
+ for (WbsTreeContract node : copyOrAddNodes) {
|
|
|
+ WbsTreeContract copyAddNodeTab = BeanUtil.copyProperties(synTab, WbsTreeContract.class);
|
|
|
if (copyAddNodeTab != null) {
|
|
|
- copyAddNodeTab.setParentId(nodeId.getId());
|
|
|
+ //把表同步到对应的节点下,重新构造ParentId、Ancestors、PKeyId
|
|
|
+ copyAddNodeTab.setParentId(node.getId());
|
|
|
copyAddNodeTab.setAncestors(synTab.getAncestors().replace(synTab.getParentId() + "", copyAddNodeTab.getParentId() + ""));
|
|
|
copyAddNodeTab.setPKeyId(SnowFlakeUtil.getId());
|
|
|
+ copyAddNodeTab.setOldId(synTab.getId() + "");
|
|
|
copyAddNodeTab.setCreateTime(new Date());
|
|
|
- copyAddNodeTabs.add(copyAddNodeTab);
|
|
|
+ copyAddNodeTabsResult.add(copyAddNodeTab);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if (copyAddNodeTabs.size() > 0) {
|
|
|
- //新增复制节点的表
|
|
|
- wbsTreeContractResultData.addAll(copyAddNodeTabs);
|
|
|
+ if (copyAddNodeTabsResult.size() > 0) {
|
|
|
+ wbsTreeContractResultData.addAll(copyAddNodeTabsResult);
|
|
|
+ }
|
|
|
+
|
|
|
+ //去重,构造wbsTreeContractResultData列表中的唯一组合(id, parent_id, wbs_id, contract_id)
|
|
|
+ Set<String> uniqueCombinations = new HashSet<>();
|
|
|
+ for (WbsTreeContract contract : wbsTreeContractResultData) {
|
|
|
+ String combination = contract.getId() + "_" + contract.getParentId() + "_" + contract.getWbsId() + "_" + contract.getContractId();
|
|
|
+ uniqueCombinations.add(combination);
|
|
|
+ }
|
|
|
+ List<String> existingCombinations = new ArrayList<>();
|
|
|
+ if (!uniqueCombinations.isEmpty()) {
|
|
|
+ String inClause = "'" + String.join("','", uniqueCombinations) + "'";
|
|
|
+ String sqlStr = "SELECT CONCAT(id, '_', parent_id, '_', wbs_id, '_', contract_id) AS combination FROM m_wbs_tree_contract WHERE type = 2 AND is_deleted = 0 AND status = 1 AND CONCAT(id, '_', parent_id, '_', wbs_id, '_', contract_id) IN (" + inClause + ")";
|
|
|
+ existingCombinations = jdbcTemplate.queryForList(sqlStr, String.class);
|
|
|
}
|
|
|
Iterator<WbsTreeContract> iterator = wbsTreeContractResultData.iterator();
|
|
|
while (iterator.hasNext()) {
|
|
|
WbsTreeContract next = iterator.next();
|
|
|
- if (next != null) {
|
|
|
- Long aLong = jdbcTemplate.queryForObject("select count(1) from m_wbs_tree_contract where type = 2 and is_deleted = 0 and status = 1 and id = " + next.getId() + " and parent_id = " + next.getParentId() + " and wbs_id = " + next.getWbsId() + " and contract_id = " + next.getContractId(), Long.class);
|
|
|
- if (aLong != null && aLong > 0L) {
|
|
|
- iterator.remove();
|
|
|
- }
|
|
|
+ String combination = next.getId() + "_" + next.getParentId() + "_" + next.getWbsId() + "_" + next.getContractId();
|
|
|
+ if (existingCombinations.contains(combination)) {
|
|
|
+ iterator.remove();
|
|
|
}
|
|
|
}
|
|
|
this.insertBatch(wbsTreeContractResultData, 1000);
|
|
@@ -270,7 +286,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
|
|
|
//TODO ---------新增---------
|
|
|
if (saveIds.size() > 0) {
|
|
|
- List<WbsTreePrivate> wbsTreePrivatesList = new ArrayList<>();
|
|
|
+ /*List<WbsTreePrivate> wbsTreePrivatesList = new ArrayList<>();
|
|
|
List<WbsTreeContract> wbsTreeContractList = new ArrayList<>();
|
|
|
ArrayList<ConstructionLedger> constructionLedgerList = new ArrayList<>();
|
|
|
|
|
@@ -320,6 +336,56 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+ this.insertBatch(wbsTreeContractList, 1000);
|
|
|
+ constructionLedgerFeign.initConstructionLedger(constructionLedgerList);*/
|
|
|
+
|
|
|
+ ArrayList<ConstructionLedger> constructionLedgerList = new ArrayList<>();
|
|
|
+ List<WbsTreePrivate> wbsTreePrivatesList = wbsTreePrivateMapper.selectNodeAndTable2(pawDTO.getWbsId(), pawDTO.getProjectId());
|
|
|
+ Set<Long> saveIdsSet = saveIds.stream().map(Long::parseLong).collect(Collectors.toSet());
|
|
|
+ List<WbsTreeContract> wbsTreeContractList = wbsTreePrivatesList.stream()
|
|
|
+ .filter(wbsTreePrivate -> {
|
|
|
+ if (wbsTreePrivate.getType() == 1 || wbsTreePrivate.getType() == 2) {
|
|
|
+ return saveIdsSet.contains(wbsTreePrivate.getId()) ||
|
|
|
+ (saveIdsSet.contains(wbsTreePrivate.getParentId()) && wbsTreePrivate.getType() == 2);
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ })
|
|
|
+ .map(wbsTreePrivate -> {
|
|
|
+ WbsTreeContract wbsTreeContract = BeanUtil.copyProperties(wbsTreePrivate, WbsTreeContract.class);
|
|
|
+ if (wbsTreeContract != null) {
|
|
|
+ wbsTreeContract.setPKeyId(SnowFlakeUtil.getId());
|
|
|
+ wbsTreeContract.setWbsId(pawDTO.getWbsId());
|
|
|
+ wbsTreeContract.setWbsType(Integer.valueOf(wbsTreePrivate.getWbsType()));
|
|
|
+ wbsTreeContract.setIsBussShow(1);
|
|
|
+ wbsTreeContract.setProjectId(pawDTO.getProjectId());
|
|
|
+ wbsTreeContract.setContractId(pawDTO.getContractId());
|
|
|
+ wbsTreeContract.setIsConcealedWorksNode(0);
|
|
|
+ wbsTreeContract.setIsTypePrivatePid(wbsTreePrivate.getPKeyId());
|
|
|
+ wbsTreeContract.setCreateTime(new Date());
|
|
|
+ if (wbsTreePrivate.getType() == 2) {
|
|
|
+ wbsTreeContract.setIsTypePrivatePid(wbsTreePrivate.getPKeyId());
|
|
|
+ }
|
|
|
+ if (wbsTreePrivate.getType() == 1) {
|
|
|
+ wbsTreeContract.setImportMatchingInfo(wbsTreePrivate.getFullName());
|
|
|
+ }
|
|
|
+ //台账
|
|
|
+ if (wbsTreeContract.getNodeType() == 6) {
|
|
|
+ ConstructionLedger constructionLedger = new ConstructionLedger();
|
|
|
+ constructionLedger.setIsBeton(0);
|
|
|
+ constructionLedger.setWbsId(wbsTreeContract.getPKeyId());
|
|
|
+ constructionLedger.setSite(wbsTreeContract.getNodeName());
|
|
|
+ constructionLedger.setStation(wbsTreeContract.getNodeName());
|
|
|
+ constructionLedger.setContractId(Long.parseLong(pawDTO.getContractId()));
|
|
|
+ constructionLedgerList.add(constructionLedger);
|
|
|
+ }
|
|
|
+ return wbsTreeContract;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ })
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ //入库
|
|
|
this.insertBatch(wbsTreeContractList, 1000);
|
|
|
constructionLedgerFeign.initConstructionLedger(constructionLedgerList);
|
|
|
}
|