Browse Source

优化 保存应用代码

master
PoffyZhang 1 year ago
parent
commit
a9de05f9e9
1 changed files with 76 additions and 151 deletions
  1. +76
    -151
      pmapi/src/main/java/com/ningdatech/pmapi/projectlib/manage/ProjectLibManage.java

+ 76
- 151
pmapi/src/main/java/com/ningdatech/pmapi/projectlib/manage/ProjectLibManage.java View File

@@ -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<ProjectApplication> 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<ProjectApplication> 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<Long> 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<ProjectApplicationDTO> 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<ProjectCoreBusinessDTO> 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<ProjectApplication> 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<ProjectApplication> 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<Long> applicationIds = applications.stream().map(ProjectApplication::getId).collect(Collectors.toList());
projectCoreBusinessIndicatorsService.remove(Wrappers.lambdaQuery(ProjectCoreBusinessIndicators.class)
.in(ProjectCoreBusinessIndicators::getApplicationId, applicationIds));
}

//app
List<ProjectApplicationDTO> applicationList = projecDto.getApplicationList();
if (CollUtil.isNotEmpty(applicationList)) {
List<ProjectApplication> 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<ProjectApplicationDTO> applicationList = projecDto.getApplicationList();
if (CollUtil.isNotEmpty(applicationList)) {
List<ProjectApplication> 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<ProjectApplication> 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<ProjectApplication> 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<ProjectApplication> applications = projectApplicationService.list(Wrappers.lambdaQuery(ProjectApplication.class)
.eq(ProjectApplication::getProjectCode, project.getProjectCode())
.eq(ProjectApplication::getProjectVersion, version));
if (CollUtil.isNotEmpty(applications)) {
projectApplicationService.removeBatchByIds(applications);
List<Long> 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<ProjectCoreBusinessDTO> 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);
}
}
});
}
}
}

Loading…
Cancel
Save