|
@@ -3175,61 +3175,60 @@ public class WbsTreePrivateServiceImpl extends BaseServiceImpl<WbsTreePrivateMap
|
|
|
private SqlSessionFactory sqlSessionFactory;
|
|
|
|
|
|
/**
|
|
|
- * 更新指定项目的私有节点的父节点ID
|
|
|
- * 此方法首先检查在当前项目下是否存在状态为1(通常表示有效或激活状态)的私有节点
|
|
|
- * 如果不存在这样的节点,则直接返回,不进行任何更新操作
|
|
|
- * 如果存在,则尝试更新这些节点的父节点ID
|
|
|
- * 此方法使用事务管理,确保在遇到异常时可以回滚更改
|
|
|
- *
|
|
|
- * @param projectId 项目ID,用于指定需要更新私有节点父节点ID的项目
|
|
|
- * @throws ServiceException 如果更新操作失败,则抛出此异常
|
|
|
- */
|
|
|
-@Transactional(rollbackFor = Exception.class)
|
|
|
-public void updatePrivatePid(String projectId) {
|
|
|
- // 输入校验
|
|
|
- if (StringUtils.isBlank(projectId)) {
|
|
|
- throw new IllegalArgumentException("项目ID不能为空");
|
|
|
- }
|
|
|
-
|
|
|
- // 判断当前项目级下是否存在私有节点
|
|
|
- Long count = baseMapper.selectCount(Wrappers.<WbsTreePrivate>lambdaQuery()
|
|
|
- .select(WbsTreePrivate::getId)
|
|
|
- .eq(WbsTreePrivate::getProjectId, projectId)
|
|
|
- .eq(WbsTreePrivate::getStatus, 1));
|
|
|
- if (count == 0L) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- try {
|
|
|
- // 尝试更新私有节点的父节点ID
|
|
|
- Integer updatedRows = baseMapper.updatePrivatePid(projectId);
|
|
|
- if (updatedRows == 0) {
|
|
|
- throw new ServiceException("操作失败:未找到可更新的节点");
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- throw new ServiceException("操作失败: " + e.getMessage());
|
|
|
- }
|
|
|
-
|
|
|
- // 获取所有节点数据并更新 ancestors 字段
|
|
|
- try (SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false)) {
|
|
|
- WbsTreePrivateMapper mapper = sqlSession.getMapper(WbsTreePrivateMapper.class);
|
|
|
-
|
|
|
- // 获取所有节点数据
|
|
|
- List<WbsTreePrivate> list = repairWithMemoryCalculation(projectId);
|
|
|
-
|
|
|
- int batchSize = 1000;
|
|
|
- for (int i = 0; i < list.size(); i += batchSize) {
|
|
|
- List<WbsTreePrivate> batch = list.subList(i, Math.min(i + batchSize, list.size()));
|
|
|
- mapper.updateBatchAncestorsByPKeyId(batch);
|
|
|
- }
|
|
|
-
|
|
|
- // 统一提交事务
|
|
|
- sqlSession.commit();
|
|
|
- } catch (Exception e) {
|
|
|
- throw new ServiceException("操作失败: " + e.getMessage());
|
|
|
- }
|
|
|
-}
|
|
|
+ * 更新指定项目的私有节点的父节点ID
|
|
|
+ * 此方法首先检查在当前项目下是否存在状态为1(通常表示有效或激活状态)的私有节点
|
|
|
+ * 如果不存在这样的节点,则直接返回,不进行任何更新操作
|
|
|
+ * 如果存在,则尝试更新这些节点的父节点ID
|
|
|
+ * 此方法使用事务管理,确保在遇到异常时可以回滚更改
|
|
|
+ *
|
|
|
+ * @param projectId 项目ID,用于指定需要更新私有节点父节点ID的项目
|
|
|
+ * @throws ServiceException 如果更新操作失败,则抛出此异常
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void updatePrivatePid(String projectId) {
|
|
|
+ // 输入校验
|
|
|
+ if (StringUtils.isBlank(projectId)) {
|
|
|
+ throw new IllegalArgumentException("项目ID不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 判断当前项目级下是否存在私有节点
|
|
|
+ Long count = baseMapper.selectCount(Wrappers.<WbsTreePrivate>lambdaQuery()
|
|
|
+ .select(WbsTreePrivate::getId)
|
|
|
+ .eq(WbsTreePrivate::getProjectId, projectId)
|
|
|
+ .eq(WbsTreePrivate::getStatus, 1));
|
|
|
+ if (count == 0L) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
+ try {
|
|
|
+ // 尝试更新私有节点的父节点ID
|
|
|
+ Integer updatedRows = baseMapper.updatePrivatePid(projectId);
|
|
|
+ if (updatedRows == 0) {
|
|
|
+ throw new ServiceException("操作失败:未找到可更新的节点");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ServiceException("操作失败: " + e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取所有节点数据并更新 ancestors 字段
|
|
|
+ try (SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false)) {
|
|
|
+ WbsTreePrivateMapper mapper = sqlSession.getMapper(WbsTreePrivateMapper.class);
|
|
|
+
|
|
|
+ // 获取所有节点数据
|
|
|
+ List<WbsTreePrivate> list = repairWithMemoryCalculation(projectId);
|
|
|
+
|
|
|
+ int batchSize = 1000;
|
|
|
+ for (int i = 0; i < list.size(); i += batchSize) {
|
|
|
+ List<WbsTreePrivate> batch = list.subList(i, Math.min(i + batchSize, list.size()));
|
|
|
+ mapper.updateBatchAncestorsByPKeyId(batch);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 统一提交事务
|
|
|
+ sqlSession.commit();
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ServiceException("操作失败: " + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
public List<WbsTreePrivate> repairWithMemoryCalculation(String projectId) {
|
|
@@ -3284,7 +3283,7 @@ public void updatePrivatePid(String projectId) {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- path.add(0,0L);
|
|
|
+ path.add(0, 0L);
|
|
|
return String.join(",", path.stream().map(String::valueOf).toArray(String[]::new));
|
|
|
}
|
|
|
|