|
@@ -5,7 +5,9 @@ import lombok.AllArgsConstructor;
|
|
|
import org.springblade.common.utils.SnowFlakeUtil;
|
|
|
import org.springblade.core.log.exception.ServiceException;
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl;
|
|
|
+import org.springblade.core.secure.utils.SecureUtil;
|
|
|
import org.springblade.core.tool.utils.BeanUtil;
|
|
|
+import org.springblade.core.tool.utils.ObjectUtil;
|
|
|
import org.springblade.meter.dto.MeterTreeContractSaveBatchDTO;
|
|
|
import org.springblade.meter.dto.MeterTreeContractSaveDTO;
|
|
|
import org.springblade.meter.entity.MeterTreeContract;
|
|
@@ -68,6 +70,10 @@ public class MeterTreeContractServiceImpl extends BaseServiceImpl<MeterTreeContr
|
|
|
cObj.setAncestor(null); //后面重新计算子级ancestor
|
|
|
}
|
|
|
|
|
|
+ if (ObjectUtil.isNotEmpty(SecureUtil.getTenantId())) {
|
|
|
+ cObj.setTenantId(Long.parseLong(SecureUtil.getTenantId()));
|
|
|
+ }
|
|
|
+
|
|
|
meterTreeContractResultData.add(cObj);
|
|
|
}
|
|
|
|
|
@@ -101,7 +107,6 @@ public class MeterTreeContractServiceImpl extends BaseServiceImpl<MeterTreeContr
|
|
|
.select(MeterTreeContract::getSourceNodeId)
|
|
|
.eq(MeterTreeContract::getTemplateId, templateId)
|
|
|
.eq(MeterTreeContract::getContractId, contractId)
|
|
|
- .eq(MeterTreeContract::getDataSourceType, 1) //此处只判断引用的(因为是靠引用id来获取父节点信息)
|
|
|
.eq(MeterTreeContract::getStatus, 1));
|
|
|
|
|
|
/*获取meterTreeProjects差集*/
|
|
@@ -110,116 +115,275 @@ public class MeterTreeContractServiceImpl extends BaseServiceImpl<MeterTreeContr
|
|
|
.noneMatch(contract -> contract.getSourceNodeId().equals(project.getId())))
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
- /*增量同步(该接口逻辑与contractSave接口中的划分子级一样)*/
|
|
|
+ /*原始数据类型*/
|
|
|
+ List<MeterTreeProject> meterTreeProjects_1 = difference.stream().filter(f -> f.getDataSourceType().equals(1) && ObjectUtil.isNotEmpty(f.getSourceNodeId())).collect(Collectors.toList());
|
|
|
+ /*新增数据类型*/
|
|
|
+ List<MeterTreeProject> meterTreeProjects_2 = difference.stream().filter(f -> f.getDataSourceType().equals(2) && ObjectUtil.isEmpty(f.getSourceNodeId())).collect(Collectors.toList());
|
|
|
+
|
|
|
+ /*增量同步*/
|
|
|
if (!difference.isEmpty()) {
|
|
|
try {
|
|
|
- /*构造差集节点id=parentId关系Maps*/
|
|
|
- Map<Long, Long> idAndParentIdMaps = difference.stream().collect(Collectors.toMap(MeterTreeProject::getId, MeterTreeProject::getParentId));
|
|
|
-
|
|
|
- /*获取所有要新增的项目级的根节点ids*/
|
|
|
- Set<Long> rootNodeIds = this.getRootNodeIds(difference);
|
|
|
- /*获取根节点的父级节点ids*/
|
|
|
- List<MeterTreeProject> meterTreeProjectsParentNodes = meterTreeProjectMapper.selectList(Wrappers.<MeterTreeProject>lambdaQuery()
|
|
|
- .select(MeterTreeProject::getParentId)
|
|
|
- .eq(MeterTreeProject::getStatus, 1)
|
|
|
- .eq(MeterTreeProject::getTemplateId, templateId)
|
|
|
- .eq(MeterTreeProject::getProjectId, projectId)
|
|
|
- .in(MeterTreeProject::getId, rootNodeIds)
|
|
|
- );
|
|
|
- Set<Long> parentRootNodeIds = meterTreeProjectsParentNodes.stream().map(MeterTreeProject::getParentId).collect(Collectors.toSet());
|
|
|
-
|
|
|
- /*获取父级节点(即contractSave接口的合同段计量树选择新增节点meterTreeContractNode对象)*/
|
|
|
- List<MeterTreeContract> meterTreeContractNodesList = baseMapper.selectList(Wrappers.<MeterTreeContract>lambdaQuery()
|
|
|
- .eq(MeterTreeContract::getStatus, 1)
|
|
|
- .eq(MeterTreeContract::getContractId, contractId)
|
|
|
- .eq(MeterTreeContract::getTemplateId, templateId)
|
|
|
- .in(MeterTreeContract::getSourceNodeId, parentRootNodeIds) //项目根节点父级 指向合同段原始id字段
|
|
|
- );
|
|
|
- Map<Long, List<MeterTreeContract>> meterTreeContractNodesMaps = meterTreeContractNodesList.stream().collect(Collectors.groupingBy(MeterTreeContract::getSourceNodeId));
|
|
|
-
|
|
|
- for (Long parentRootId : parentRootNodeIds) {
|
|
|
- /*新增到合同段处的根节点的父级节点信息,由于合同段树新增是从项目选择的(相当于复制),那么sourceNodeId就有相同的,就有N个,所以是多份父级节点*/
|
|
|
- List<MeterTreeContract> contractParentRootNodeList = meterTreeContractNodesMaps.get(parentRootId);
|
|
|
- for (MeterTreeContract meterTreeContractNode : contractParentRootNodeList) {
|
|
|
-
|
|
|
- for (Long rootNodeId : rootNodeIds) {
|
|
|
- /*归纳到自己节点下 TODO 待测试,这里是否需要,项目同步是需要判断的*/
|
|
|
- Long rootIdRecordParentId = idAndParentIdMaps.get(rootNodeId);
|
|
|
- if (!rootIdRecordParentId.equals(parentRootId)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
+ boolean varResult = false;
|
|
|
+
|
|
|
+ /* ======== 处理原始数据(指从系统同步引用,有source_node_id,且data_source_type = 1 ) ======== */
|
|
|
+ if (meterTreeProjects_1.size() > 0) {
|
|
|
+ /*构造差集节点id=parentId关系Maps*/
|
|
|
+ Map<Long, Long> idAndParentIdMaps = meterTreeProjects_1.stream().collect(Collectors.toMap(MeterTreeProject::getId, MeterTreeProject::getParentId));
|
|
|
+
|
|
|
+ /*获取所有要新增的项目级的根节点ids*/
|
|
|
+ Set<Long> rootNodeIds = this.getRootNodeIds(meterTreeProjects_1);
|
|
|
+ /*获取根节点的父级节点ids*/
|
|
|
+ List<MeterTreeProject> meterTreeProjectsParentNodes = meterTreeProjectMapper.selectList(Wrappers.<MeterTreeProject>lambdaQuery()
|
|
|
+ .select(MeterTreeProject::getParentId)
|
|
|
+ .eq(MeterTreeProject::getStatus, 1)
|
|
|
+ .eq(MeterTreeProject::getTemplateId, templateId)
|
|
|
+ .eq(MeterTreeProject::getProjectId, projectId)
|
|
|
+ .in(MeterTreeProject::getId, rootNodeIds)
|
|
|
+ );
|
|
|
+ Set<Long> parentRootNodeIds = meterTreeProjectsParentNodes.stream().map(MeterTreeProject::getParentId).collect(Collectors.toSet());
|
|
|
+ if (parentRootNodeIds.size() == 0) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /*获取父级节点(即contractSave接口的合同段计量树选择新增节点meterTreeContractNode对象)*/
|
|
|
+ List<MeterTreeContract> meterTreeContractNodesList = baseMapper.selectList(Wrappers.<MeterTreeContract>lambdaQuery()
|
|
|
+ .eq(MeterTreeContract::getStatus, 1)
|
|
|
+ .eq(MeterTreeContract::getContractId, contractId)
|
|
|
+ .eq(MeterTreeContract::getTemplateId, templateId)
|
|
|
+ .in(MeterTreeContract::getSourceNodeId, parentRootNodeIds) //项目根节点父级 指向合同段原始id字段
|
|
|
+ );
|
|
|
+ Map<Long, List<MeterTreeContract>> meterTreeContractNodesMaps = meterTreeContractNodesList.stream().collect(Collectors.groupingBy(MeterTreeContract::getSourceNodeId));
|
|
|
+
|
|
|
+ for (Long parentRootId : parentRootNodeIds) {
|
|
|
+ /*新增到合同段处的根节点的父级节点信息,由于合同段树新增是从项目选择的(相当于复制),那么sourceNodeId就有相同的,就有N个,所以是多份父级节点*/
|
|
|
+ List<MeterTreeContract> contractParentRootNodeList = meterTreeContractNodesMaps.get(parentRootId);
|
|
|
+ for (MeterTreeContract meterTreeContractNode : contractParentRootNodeList) {
|
|
|
+
|
|
|
+ for (Long rootNodeId : rootNodeIds) {
|
|
|
+ /*归纳到自己节点下*/
|
|
|
+ Long rootIdRecordParentId = idAndParentIdMaps.get(rootNodeId);
|
|
|
+ if (!rootIdRecordParentId.equals(parentRootId)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
- /*获取新增节点的所有子级相关节点*/
|
|
|
- List<MeterTreeProject> projectNode = this.getMeterTreeProjectNode(projectId, templateId, rootNodeId);
|
|
|
+ /*获取新增节点的所有子级相关节点*/
|
|
|
+ List<MeterTreeProject> projectNode = this.getMeterTreeProjectNode(projectId, templateId, rootNodeId);
|
|
|
|
|
|
- /*构造数据*/
|
|
|
- /*创建旧节点ID和新节点ID的映射Map*/
|
|
|
- Map<Long, Long> newRootAndChildNodeIdMap = new HashMap<>(projectNode.size());
|
|
|
- List<Long> projectNodeIdList = projectNode.stream().map(MeterTreeProject::getId).collect(Collectors.toList());
|
|
|
- for (Long oldNodeId : projectNodeIdList) {
|
|
|
- newRootAndChildNodeIdMap.put(oldNodeId, SnowFlakeUtil.getId());
|
|
|
- }
|
|
|
- /*把项目节点id、parentId、ancestor替换成新的,构造成MeterTreeContract对象*/
|
|
|
- List<MeterTreeContract> meterTreeContractResultData = new ArrayList<>(projectNodeIdList.size());
|
|
|
- for (MeterTreeProject pObj : projectNode) {
|
|
|
- MeterTreeContract cObj = new MeterTreeContract();
|
|
|
- BeanUtil.copyProperties(pObj, cObj);
|
|
|
- cObj.setContractId(contractId);
|
|
|
-
|
|
|
- /*数据源id*/
|
|
|
- cObj.setSourceNodeId(pObj.getId());
|
|
|
- cObj.setDataSourceType(1); //项目引用
|
|
|
- cObj.setUpdateStatus(0); //非编辑
|
|
|
-
|
|
|
- /*id*/
|
|
|
- cObj.setId(newRootAndChildNodeIdMap.get(pObj.getId()));
|
|
|
- /*parentId*/
|
|
|
- Long parentId = newRootAndChildNodeIdMap.getOrDefault(pObj.getParentId(), null);
|
|
|
- if (parentId == null) {
|
|
|
- /*根节点*/
|
|
|
- cObj.setParentId(meterTreeContractNode.getId());
|
|
|
- /*ancestor(根节点ancestor指向就是 外部合同段树 处选择的节点)*/
|
|
|
- cObj.setAncestor(meterTreeContractNode.getAncestor() + "," + cObj.getParentId());
|
|
|
- } else {
|
|
|
- /*非根节点*/
|
|
|
- cObj.setParentId(parentId);
|
|
|
- cObj.setAncestor(null); //后面重新计算子级ancestor
|
|
|
+ /*剔除所有新增引用节点*/
|
|
|
+ projectNode.removeIf(obj -> obj.getDataSourceType().equals(2));
|
|
|
+
|
|
|
+ /*构造数据*/
|
|
|
+ /*创建旧节点ID和新节点ID的映射Map*/
|
|
|
+ Map<Long, Long> newRootAndChildNodeIdMap = new HashMap<>(projectNode.size());
|
|
|
+ List<Long> projectNodeIdList = projectNode.stream().map(MeterTreeProject::getId).collect(Collectors.toList());
|
|
|
+ for (Long oldNodeId : projectNodeIdList) {
|
|
|
+ newRootAndChildNodeIdMap.put(oldNodeId, SnowFlakeUtil.getId());
|
|
|
+ }
|
|
|
+ /*把项目节点id、parentId、ancestor替换成新的,构造成MeterTreeContract对象*/
|
|
|
+ List<MeterTreeContract> meterTreeContractResultData = new ArrayList<>(projectNodeIdList.size());
|
|
|
+ for (MeterTreeProject pObj : projectNode) {
|
|
|
+ MeterTreeContract cObj = new MeterTreeContract();
|
|
|
+ BeanUtil.copyProperties(pObj, cObj);
|
|
|
+ cObj.setContractId(contractId);
|
|
|
+
|
|
|
+ /*数据源id*/
|
|
|
+ cObj.setSourceNodeId(pObj.getId());
|
|
|
+ cObj.setDataSourceType(1); //项目原始引用
|
|
|
+ cObj.setUpdateStatus(0); //非编辑
|
|
|
+
|
|
|
+ /*id*/
|
|
|
+ cObj.setId(newRootAndChildNodeIdMap.get(pObj.getId()));
|
|
|
+ /*parentId*/
|
|
|
+ Long parentId = newRootAndChildNodeIdMap.getOrDefault(pObj.getParentId(), null);
|
|
|
+ if (parentId == null) {
|
|
|
+ /*根节点*/
|
|
|
+ cObj.setParentId(meterTreeContractNode.getId());
|
|
|
+ /*ancestor(根节点ancestor指向就是 外部合同段树 处选择的节点)*/
|
|
|
+ cObj.setAncestor(meterTreeContractNode.getAncestor() + "," + cObj.getParentId());
|
|
|
+ } else {
|
|
|
+ /*非根节点*/
|
|
|
+ cObj.setParentId(parentId);
|
|
|
+ cObj.setAncestor(null); //后面重新计算子级ancestor
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ObjectUtil.isNotEmpty(SecureUtil.getTenantId())) {
|
|
|
+ cObj.setTenantId(Long.parseLong(SecureUtil.getTenantId()));
|
|
|
+ }
|
|
|
+
|
|
|
+ meterTreeContractResultData.add(cObj);
|
|
|
+ }
|
|
|
+
|
|
|
+ /*层级结构排序*/
|
|
|
+ List<MeterTreeContract> sortedList_1 = this.sortMeterTreeContracts(meterTreeContractResultData);
|
|
|
+
|
|
|
+ /*构造ancestor*/
|
|
|
+ for (MeterTreeContract contract : sortedList_1) {
|
|
|
+ if (contract.getAncestor() == null) {
|
|
|
+ //如果当前元素是子级(ancestor为null),找到对应的父级
|
|
|
+ Long parentId = contract.getParentId();
|
|
|
+ String parentAncestor = this.getAncestorForParentId(meterTreeContractResultData, parentId);
|
|
|
+ //构造新的ancestor字段
|
|
|
+ String newAncestor = parentAncestor + "," + parentId;
|
|
|
+ contract.setAncestor(newAncestor);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- meterTreeContractResultData.add(cObj);
|
|
|
+ /*入库*/
|
|
|
+ this.saveBatch(sortedList_1, 1000);
|
|
|
}
|
|
|
+ }
|
|
|
+ }
|
|
|
+ varResult = true;
|
|
|
+ }
|
|
|
|
|
|
- /*层级结构排序*/
|
|
|
- List<MeterTreeContract> sortedList = this.sortMeterTreeContracts(meterTreeContractResultData);
|
|
|
-
|
|
|
- /*构造ancestor*/
|
|
|
- for (MeterTreeContract contract : sortedList) {
|
|
|
- if (contract.getAncestor() == null) {
|
|
|
- //如果当前元素是子级(ancestor为null),找到对应的父级
|
|
|
- Long parentId = contract.getParentId();
|
|
|
- String parentAncestor = this.getAncestorForParentId(meterTreeContractResultData, parentId);
|
|
|
- //构造新的ancestor字段
|
|
|
- String newAncestor = parentAncestor + "," + parentId;
|
|
|
- contract.setAncestor(newAncestor);
|
|
|
+ /* ======== 处理新增数据(指项目处手动新增,没有source_node_id,且data_source_type = 2 ) ======== */
|
|
|
+ if (meterTreeProjects_2.size() > 0) {
|
|
|
+ /*获取所有新增数据中的根节点信息*/
|
|
|
+ List<MeterTreeProject> addRootNodes = this.findRootNodes(meterTreeProjects_2);
|
|
|
+ List<Long> rootNodeIds = addRootNodes.stream().map(MeterTreeProject::getId).collect(Collectors.toList());
|
|
|
+
|
|
|
+ /*构造新增根节点id=parentId关系Maps*/
|
|
|
+ Map<Long, Long> idAndParentIdMaps = addRootNodes.stream().collect(Collectors.toMap(MeterTreeProject::getId, MeterTreeProject::getParentId));
|
|
|
+
|
|
|
+ /*获取根节点对应的父级原始节点信息*/
|
|
|
+ Set<Long> parentIds = addRootNodes.stream().map(MeterTreeProject::getParentId).collect(Collectors.toSet());
|
|
|
+ /*确定对应到合同段节点的sourceNodeId节点信息(定位新增节点到合同段节点中的位置信息)*/
|
|
|
+ List<MeterTreeProject> meterTreeProjectsFu = meterTreeProjectMapper.selectList(Wrappers.<MeterTreeProject>lambdaQuery()
|
|
|
+ .select(MeterTreeProject::getId)
|
|
|
+ .in(MeterTreeProject::getId, parentIds)
|
|
|
+ //.isNotNull(MeterTreeProject::getSourceNodeId) //此处不能通过sourceNodeId判断,因为存在是在手动新增的节点下继续手动新增子级,那么父级sourceNodeId必定为null
|
|
|
+ );
|
|
|
+ List<Long> parentRootNodeIds = meterTreeProjectsFu.stream().map(MeterTreeProject::getId).collect(Collectors.toList());
|
|
|
+ if (parentRootNodeIds.size() == 0) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /*获取父级节点(即contractSave接口的合同段计量树选择新增节点meterTreeContractNode对象)*/
|
|
|
+ List<MeterTreeContract> meterTreeContractNodesList = baseMapper.selectList(Wrappers.<MeterTreeContract>lambdaQuery()
|
|
|
+ .eq(MeterTreeContract::getStatus, 1)
|
|
|
+ .eq(MeterTreeContract::getContractId, contractId)
|
|
|
+ .eq(MeterTreeContract::getTemplateId, templateId)
|
|
|
+ .in(MeterTreeContract::getSourceNodeId, parentRootNodeIds) //项目根节点父级 指向合同段原始id字段
|
|
|
+ );
|
|
|
+ Map<Long, List<MeterTreeContract>> meterTreeContractNodesMaps = meterTreeContractNodesList.stream().collect(Collectors.groupingBy(MeterTreeContract::getSourceNodeId));
|
|
|
+
|
|
|
+ for (Long parentRootId : parentRootNodeIds) {
|
|
|
+ /*新增到合同段处的根节点的父级节点信息,由于合同段树新增是从项目选择的(相当于复制),那么sourceNodeId就有相同的,就有N个,所以是多份父级节点*/
|
|
|
+ List<MeterTreeContract> contractParentRootNodeList = meterTreeContractNodesMaps.get(parentRootId);
|
|
|
+ for (MeterTreeContract meterTreeContractNode : contractParentRootNodeList) {
|
|
|
+
|
|
|
+ for (Long rootNodeId : rootNodeIds) {
|
|
|
+ /*归纳到自己节点下*/
|
|
|
+ Long rootIdRecordParentId = idAndParentIdMaps.get(rootNodeId);
|
|
|
+ if (!rootIdRecordParentId.equals(parentRootId)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ /*获取新增节点的所有子级相关节点*/
|
|
|
+ List<MeterTreeProject> projectNode = this.getMeterTreeProjectNode(projectId, templateId, rootNodeId);
|
|
|
+
|
|
|
+ /*剔除所有原始引用节点*/
|
|
|
+ projectNode.removeIf(obj -> obj.getDataSourceType().equals(1));
|
|
|
+
|
|
|
+ /*构造数据*/
|
|
|
+ /*创建旧节点ID和新节点ID的映射Map*/
|
|
|
+ Map<Long, Long> newRootAndChildNodeIdMap = new HashMap<>(projectNode.size());
|
|
|
+ List<Long> projectNodeIdList = projectNode.stream().map(MeterTreeProject::getId).collect(Collectors.toList());
|
|
|
+ for (Long oldNodeId : projectNodeIdList) {
|
|
|
+ newRootAndChildNodeIdMap.put(oldNodeId, SnowFlakeUtil.getId());
|
|
|
+ }
|
|
|
+ /*把项目节点id、parentId、ancestor替换成新的,构造成MeterTreeContract对象*/
|
|
|
+ List<MeterTreeContract> meterTreeContractResultData = new ArrayList<>(projectNodeIdList.size());
|
|
|
+ for (MeterTreeProject pObj : projectNode) {
|
|
|
+ MeterTreeContract cObj = new MeterTreeContract();
|
|
|
+ BeanUtil.copyProperties(pObj, cObj);
|
|
|
+ cObj.setContractId(contractId);
|
|
|
+
|
|
|
+ /*数据源id*/
|
|
|
+ cObj.setSourceNodeId(pObj.getId());
|
|
|
+ cObj.setDataSourceType(3); //项目新增引用(项目是新增的)
|
|
|
+ cObj.setUpdateStatus(0); //非编辑
|
|
|
+
|
|
|
+ /*id*/
|
|
|
+ cObj.setId(newRootAndChildNodeIdMap.get(pObj.getId()));
|
|
|
+ /*parentId*/
|
|
|
+ Long parentId = newRootAndChildNodeIdMap.getOrDefault(pObj.getParentId(), null);
|
|
|
+ if (parentId == null) {
|
|
|
+ /*根节点*/
|
|
|
+ cObj.setParentId(meterTreeContractNode.getId());
|
|
|
+ /*ancestor(根节点ancestor指向就是 外部合同段树 处选择的节点)*/
|
|
|
+ cObj.setAncestor(meterTreeContractNode.getAncestor() + "," + cObj.getParentId());
|
|
|
+ } else {
|
|
|
+ /*非根节点*/
|
|
|
+ cObj.setParentId(parentId);
|
|
|
+ cObj.setAncestor(null); //后面重新计算子级ancestor
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ObjectUtil.isNotEmpty(SecureUtil.getTenantId())) {
|
|
|
+ cObj.setTenantId(Long.parseLong(SecureUtil.getTenantId()));
|
|
|
+ }
|
|
|
+
|
|
|
+ meterTreeContractResultData.add(cObj);
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- /*入库*/
|
|
|
- this.saveBatch(sortedList, 1000);
|
|
|
+ /*层级结构排序*/
|
|
|
+ List<MeterTreeContract> sortedList_2 = this.sortMeterTreeContracts(meterTreeContractResultData);
|
|
|
+
|
|
|
+ /*构造ancestor*/
|
|
|
+ for (MeterTreeContract contract : sortedList_2) {
|
|
|
+ if (contract.getAncestor() == null) {
|
|
|
+ //如果当前元素是子级(ancestor为null),找到对应的父级
|
|
|
+ Long parentId = contract.getParentId();
|
|
|
+ String parentAncestor = this.getAncestorForParentId(meterTreeContractResultData, parentId);
|
|
|
+ //构造新的ancestor字段
|
|
|
+ String newAncestor = parentAncestor + "," + parentId;
|
|
|
+ contract.setAncestor(newAncestor);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /*入库*/
|
|
|
+ this.saveBatch(sortedList_2, 1000);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ varResult = true;
|
|
|
}
|
|
|
- return true;
|
|
|
+
|
|
|
+ return varResult;
|
|
|
+
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
throw new ServiceException("操作异常!");
|
|
|
}
|
|
|
-
|
|
|
} else {
|
|
|
throw new ServiceException("未获取到需要同步的项目级计量单元信息!");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取所有新增节点中的根节点信息
|
|
|
+ *
|
|
|
+ * @param meterTreeProjects
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<MeterTreeProject> findRootNodes(List<MeterTreeProject> meterTreeProjects) {
|
|
|
+ List<MeterTreeProject> rootNodes = new ArrayList<>();
|
|
|
+ Map<Long, MeterTreeProject> idToProjectMap = new HashMap<>();
|
|
|
+ for (MeterTreeProject project : meterTreeProjects) {
|
|
|
+ idToProjectMap.put(project.getId(), project);
|
|
|
+ }
|
|
|
+ //遍历列表找到所有的根节点
|
|
|
+ for (MeterTreeProject project : meterTreeProjects) {
|
|
|
+ Long parentId = project.getParentId();
|
|
|
+ if (parentId == null || !idToProjectMap.containsKey(parentId)) {
|
|
|
+ //找到父级为null或者未找到父级对象的节点,即根节点
|
|
|
+ rootNodes.add(project);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return rootNodes;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public boolean contractSave(MeterTreeContractSaveBatchDTO dto) {
|
|
@@ -263,6 +427,10 @@ public class MeterTreeContractServiceImpl extends BaseServiceImpl<MeterTreeContr
|
|
|
/*ancestor*/
|
|
|
cObj.setAncestor(meterTreeContractNode.getAncestor() + "," + cObj.getParentId());
|
|
|
|
|
|
+ if (ObjectUtil.isNotEmpty(SecureUtil.getTenantId())) {
|
|
|
+ cObj.setTenantId(Long.parseLong(SecureUtil.getTenantId()));
|
|
|
+ }
|
|
|
+
|
|
|
baseMapper.insert(cObj);
|
|
|
}
|
|
|
|
|
@@ -320,6 +488,10 @@ public class MeterTreeContractServiceImpl extends BaseServiceImpl<MeterTreeContr
|
|
|
cObj.setAncestor(null); //后面重新计算子级ancestor
|
|
|
}
|
|
|
|
|
|
+ if (ObjectUtil.isNotEmpty(SecureUtil.getTenantId())) {
|
|
|
+ cObj.setTenantId(Long.parseLong(SecureUtil.getTenantId()));
|
|
|
+ }
|
|
|
+
|
|
|
meterTreeContractResultData.add(cObj);
|
|
|
}
|
|
|
|