From a9de05f9e9a5227e4b91ec16e81374cef697d672 Mon Sep 17 00:00:00 2001 From: PoffyZhang <99775271@qq.com> Date: Tue, 1 Aug 2023 14:01:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pmapi/projectlib/manage/ProjectLibManage.java | 227 +++++++-------------- 1 file changed, 76 insertions(+), 151 deletions(-) diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/manage/ProjectLibManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/manage/ProjectLibManage.java index 177679e..3e98ca4 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/manage/ProjectLibManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/manage/ProjectLibManage.java @@ -272,30 +272,6 @@ public class ProjectLibManage { projectService.updateById(project); } } - - //保存项目应用 - Boolean isApp = Objects.nonNull(projectDto.getIncludeApplication()) && CommonEnum.YES.getCode().equals(projectDto.getIncludeApplication()) - ? Boolean.TRUE : Boolean.FALSE; - //采取批量删除 批量添加的方式 - Integer version = Objects.nonNull(project.getVersion()) ? project.getVersion() : 1; - projectApplicationService.remove(Wrappers.lambdaQuery(ProjectApplication.class) - .eq(ProjectApplication::getProjectCode, project.getProjectCode()) - .eq(ProjectApplication::getProjectVersion, version)); - if (isApp && CollUtil.isNotEmpty(projectDto.getApplicationList())) { - Project finalProject = project; - List applications = projectDto.getApplicationList().stream().map(application -> { - ProjectApplication projectApplication = new ProjectApplication(); - BeanUtils.copyProperties(application, projectApplication); - projectApplication.setId(null); - projectApplication.setProjectId(finalProject.getId()); - projectApplication.setProjectCode(finalProject.getProjectCode()); - projectApplication.setBuildOrgCode(finalProject.getBuildOrgCode()); - projectApplication.setBuildOrgName(finalProject.getBuildOrgName()); - projectApplication.setProjectVersion(version); - return projectApplication; - }).collect(Collectors.toList()); - projectApplicationService.saveOrUpdateBatch(applications); - } return project; } catch (Exception e) { log.error("项目信息入库错误 " + e); @@ -356,49 +332,6 @@ public class ProjectLibManage { projectService.updateById(project); } } - - //保存项目应用 - Boolean isApp = Objects.nonNull(projectDto.getIncludeApplication()) && CommonEnum.YES.getCode().equals(projectDto.getIncludeApplication()) - ? Boolean.TRUE : Boolean.FALSE; - //采取批量删除 批量添加的方式 批量删除建设方案申报后的应用信息及关联的核心业务 - List applications = projectApplicationService.list(Wrappers.lambdaQuery(ProjectApplication.class) - .eq(ProjectApplication::getProjectCode, project.getProjectCode()) - .eq(ProjectApplication::getProjectVersion, project.getVersion()) - .eq(ProjectApplication::getIsConstruct, Boolean.TRUE)); - if (CollUtil.isNotEmpty(applications)) { - projectApplicationService.removeBatchByIds(applications); - List applicationIds = applications.stream().map(ProjectApplication::getId).collect(Collectors.toList()); - projectCoreBusinessIndicatorsService.remove(Wrappers.lambdaQuery(ProjectCoreBusinessIndicators.class) - .in(ProjectCoreBusinessIndicators::getApplicationId,applicationIds)); - } - - if (isApp && CollUtil.isNotEmpty(projectDto.getApplicationList())) { - Project finalProject = project; - List applicationList = projectDto.getApplicationList(); - for (ProjectApplicationDTO application : applicationList) { - ProjectApplication projectApplication = new ProjectApplication(); - BeanUtils.copyProperties(application, projectApplication); - projectApplication.setId(null); - projectApplication.setProjectId(finalProject.getId()); - projectApplication.setProjectCode(finalProject.getProjectCode()); - projectApplication.setBuildOrgCode(finalProject.getBuildOrgCode()); - projectApplication.setBuildOrgName(finalProject.getBuildOrgName()); - projectApplication.setIsConstruct(Boolean.TRUE); - projectApplication.setProjectVersion(finalProject.getVersion()); - boolean result = projectApplicationService.save(projectApplication); - // 保存应用关联的核心业务 - List coreBusinessList = application.getCoreBusinessList(); - Boolean hasCoreBusiness = CollUtil.isNotEmpty(coreBusinessList) ? Boolean.TRUE : Boolean.FALSE; - if (Boolean.TRUE.equals(result) && Boolean.TRUE.equals(hasCoreBusiness)){ - for (ProjectCoreBusinessDTO coreBusiness : coreBusinessList) { - ProjectCoreBusinessIndicators projectCoreBusinessIndicators = new ProjectCoreBusinessIndicators(); - BeanUtils.copyProperties(coreBusiness, projectCoreBusinessIndicators); - projectCoreBusinessIndicators.setApplicationId(application.getId()); - projectCoreBusinessIndicatorsService.save(projectCoreBusinessIndicators); - } - } - } - } return project; } catch (Exception e) { log.error("项目信息入库错误 " + e); @@ -416,29 +349,7 @@ public class ProjectLibManage { public Project reSaveProjectNewVersion(ProjectDTO projectDto) { //流程启动之后 入库项目 重要业务信息 用于列表查询 展示 try { - Project project = newProjectWithVersion(projectDto); - - //保存项目应用 - Boolean isApp = Objects.nonNull(projectDto.getIncludeApplication()) && CommonEnum.YES.getCode().equals(projectDto.getIncludeApplication()) - ? Boolean.TRUE : Boolean.FALSE; - //采取批量删除 批量添加的方式 - projectApplicationService.remove(Wrappers.lambdaQuery(ProjectApplication.class) - .eq(ProjectApplication::getProjectCode, project.getProjectCode()) - .eq(ProjectApplication::getProjectVersion, project.getVersion())); - if (isApp && CollUtil.isNotEmpty(projectDto.getApplicationList())) { - Project finalProject = project; - List applications = projectDto.getApplicationList().stream().map(application -> { - ProjectApplication projectApplication = new ProjectApplication(); - BeanUtils.copyProperties(application, projectApplication); - projectApplication.setId(null); - projectApplication.setProjectId(finalProject.getId()); - projectApplication.setProjectCode(finalProject.getProjectCode()); - projectApplication.setProjectVersion(finalProject.getVersion()); - return projectApplication; - }).collect(Collectors.toList()); - projectApplicationService.saveOrUpdateBatch(applications); - } - return project; + return newProjectWithVersion(projectDto); } catch (Exception e) { log.error("项目信息入库错误 " + e); throw new BusinessException("项目信息入库错误 :" + e); @@ -470,6 +381,8 @@ public class ProjectLibManage { .ne(Project::getId, project.getId()) .eq(Project::getProjectCode, project.getProjectCode())); + saveApplication(projecDto,project,null); + return project; } @@ -499,41 +412,14 @@ public class ProjectLibManage { .ne(Project::getId, project.getId()) .eq(Project::getProjectCode, project.getProjectCode())); - //删除当前版本的app 一般情况是没有 保险起见 - List applications = projectApplicationService.list(Wrappers.lambdaQuery(ProjectApplication.class) - .eq(ProjectApplication::getProjectCode, project.getProjectCode()) - .eq(ProjectApplication::getProjectVersion, project.getVersion())); - if (CollUtil.isNotEmpty(applications)) { - projectApplicationService.removeBatchByIds(applications); - List applicationIds = applications.stream().map(ProjectApplication::getId).collect(Collectors.toList()); - projectCoreBusinessIndicatorsService.remove(Wrappers.lambdaQuery(ProjectCoreBusinessIndicators.class) - .in(ProjectCoreBusinessIndicators::getApplicationId, applicationIds)); - } - //app - List applicationList = projecDto.getApplicationList(); - if (CollUtil.isNotEmpty(applicationList)) { - List apps = applicationList.stream() - .map(a -> { - ProjectApplication app = BeanUtil.copyProperties(a, ProjectApplication.class); - app.setId(null); - app.setProjectId(project.getId()); - app.setProjectCode(project.getProjectCode()); - app.setBuildOrgName(project.getBuildOrgName()); - app.setBuildOrgCode(project.getBuildOrgCode()); - app.setIsConstruct(isConstruct); - app.setProjectVersion(project.getVersion()); - return app; - }) - .collect(Collectors.toList()); - projectApplicationService.saveBatch(apps); - } + saveApplication(projecDto,project,isConstruct); } return project; } - public Project saveProjectWithVersion(ProjectDTO projecDto, String instanceId, Integer instType) { + public Project saveProjectWithVersion(ProjectDTO projecDto, String instanceId, Integer instType,Boolean isConstruct) { Project oldProject = projectService.getById(projecDto.getId()); Project project = new Project(); VUtils.isTrue(Objects.isNull(oldProject)) @@ -564,27 +450,7 @@ public class ProjectLibManage { .eq(Project::getProjectCode, project.getProjectCode())); //app - //采取批量删除 批量添加的方式 - projectApplicationService.remove(Wrappers.lambdaQuery(ProjectApplication.class) - .eq(ProjectApplication::getProjectCode, project.getProjectCode()) - .eq(ProjectApplication::getProjectVersion, project.getVersion())); - - List applicationList = projecDto.getApplicationList(); - if (CollUtil.isNotEmpty(applicationList)) { - List apps = applicationList.stream() - .map(a -> { - ProjectApplication app = BeanUtil.copyProperties(a, ProjectApplication.class); - app.setId(null); - app.setProjectId(project.getId()); - app.setProjectCode(project.getProjectCode()); - app.setBuildOrgName(project.getBuildOrgName()); - app.setBuildOrgCode(project.getBuildOrgCode()); - app.setProjectVersion(project.getVersion()); - return app; - }) - .collect(Collectors.toList()); - projectApplicationService.saveBatch(apps); - } + saveApplication(projecDto,project,isConstruct); } return project; @@ -617,17 +483,7 @@ public class ProjectLibManage { .ne(Project::getId, project.getId()) .eq(Project::getProjectCode, project.getProjectCode())); - List apps = projectApplicationService.list(Wrappers.lambdaQuery(ProjectApplication.class) - .eq(ProjectApplication::getProjectId, oldProject.getId())); - if(CollUtil.isNotEmpty(apps)){ - apps = apps.stream().map(app -> { - app.setProjectVersion(project.getVersion()); - app.setProjectId(project.getId()); - app.setId(null); - return app; - }).collect(Collectors.toList()); - projectApplicationService.saveBatch(apps); - } + saveApplication(project,oldProject,null); } return project; @@ -662,6 +518,9 @@ public class ProjectLibManage { .set(Project::getNewest, Boolean.FALSE) .ne(Project::getId, project.getId()) .eq(Project::getProjectCode, project.getProjectCode())); + + //APP + saveApplication(project,oldProject,null); } return project; @@ -696,6 +555,8 @@ public class ProjectLibManage { .set(Project::getNewest, Boolean.FALSE) .ne(Project::getId, project.getId()) .eq(Project::getProjectCode, project.getProjectCode())); + + saveApplication(project,oldProject,Boolean.TRUE); } return project; @@ -1209,4 +1070,68 @@ public class ProjectLibManage { res.put(ProjectConstant.ProjectLib.PROCESS_KEY, todoService.getProcessDetail(req)); return res; } + + private void saveApplication(Project project,Project oldProject,Boolean isConstruct) { + List apps = projectApplicationService.list(Wrappers.lambdaQuery(ProjectApplication.class) + .eq(ProjectApplication::getProjectCode, oldProject.getProjectCode()) + .eq(ProjectApplication::getProjectVersion, oldProject.getVersion())); + if(CollUtil.isNotEmpty(apps)){ + apps = apps.stream().map(app -> { + app.setProjectVersion(project.getVersion()); + app.setProjectId(project.getId()); + app.setId(null); + if(Objects.nonNull(isConstruct)){ + app.setIsConstruct(isConstruct); + } + return app; + }).collect(Collectors.toList()); + projectApplicationService.saveBatch(apps); + } + } + + private void saveApplication(ProjectDTO projectDto,Project project,Boolean isConstruct) { + //保存项目应用 + Boolean isApp = Objects.nonNull(projectDto.getIncludeApplication()) && CommonEnum.YES.getCode().equals(projectDto.getIncludeApplication()) + ? Boolean.TRUE : Boolean.FALSE; + //采取批量删除 批量添加的方式 + Integer version = Objects.nonNull(project.getVersion()) ? project.getVersion() : 1; + //删除当前版本的app 一般情况是没有 保险起见 + List applications = projectApplicationService.list(Wrappers.lambdaQuery(ProjectApplication.class) + .eq(ProjectApplication::getProjectCode, project.getProjectCode()) + .eq(ProjectApplication::getProjectVersion, version)); + if (CollUtil.isNotEmpty(applications)) { + projectApplicationService.removeBatchByIds(applications); + List applicationIds = applications.stream().map(ProjectApplication::getId).collect(Collectors.toList()); + projectCoreBusinessIndicatorsService.remove(Wrappers.lambdaQuery(ProjectCoreBusinessIndicators.class) + .in(ProjectCoreBusinessIndicators::getApplicationId, applicationIds)); + } + + if (isApp && CollUtil.isNotEmpty(projectDto.getApplicationList())) { + Project finalProject = project; + projectDto.getApplicationList().forEach(application -> { + ProjectApplication projectApplication = new ProjectApplication(); + BeanUtils.copyProperties(application, projectApplication); + projectApplication.setId(null); + projectApplication.setProjectId(finalProject.getId()); + projectApplication.setProjectCode(finalProject.getProjectCode()); + projectApplication.setBuildOrgCode(finalProject.getBuildOrgCode()); + projectApplication.setBuildOrgName(finalProject.getBuildOrgName()); + projectApplication.setProjectVersion(version); + projectApplication.setIsConstruct(isConstruct); + + boolean result = projectApplicationService.save(projectApplication); + // 保存应用关联的核心业务 + List coreBusinessList = application.getCoreBusinessList(); + Boolean hasCoreBusiness = CollUtil.isNotEmpty(coreBusinessList) ? Boolean.TRUE : Boolean.FALSE; + if (Boolean.TRUE.equals(result) && Boolean.TRUE.equals(hasCoreBusiness)){ + for (ProjectCoreBusinessDTO coreBusiness : coreBusinessList) { + ProjectCoreBusinessIndicators projectCoreBusinessIndicators = new ProjectCoreBusinessIndicators(); + BeanUtils.copyProperties(coreBusiness, projectCoreBusinessIndicators); + projectCoreBusinessIndicators.setApplicationId(application.getId()); + projectCoreBusinessIndicatorsService.save(projectCoreBusinessIndicators); + } + } + }); + } + } }