From 8c9c9eb0c054dac32b408e8a2660b775f884f99d Mon Sep 17 00:00:00 2001 From: weizhihong Date: Wed, 12 Oct 2022 15:49:26 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E9=A1=B9=E7=9B=AE=E5=BF=AB=E6=8D=B7?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E7=BB=84=E7=BB=87=E6=8E=A5=E5=8F=A3=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project/ProjectInfoController.java | 9 +- .../rtss/services/project/ProjectService.java | 6 + .../services/project/ProjectServiceImpl.java | 110 +++++++++++------- .../rtss/vo/project/ProjectInfoVO.java | 13 ++- 4 files changed, 96 insertions(+), 42 deletions(-) diff --git a/src/main/java/club/joylink/rtss/controller/project/ProjectInfoController.java b/src/main/java/club/joylink/rtss/controller/project/ProjectInfoController.java index 2564d7260..07f32ff55 100644 --- a/src/main/java/club/joylink/rtss/controller/project/ProjectInfoController.java +++ b/src/main/java/club/joylink/rtss/controller/project/ProjectInfoController.java @@ -1,8 +1,10 @@ package club.joylink.rtss.controller.project; +import club.joylink.rtss.controller.advice.AuthenticateInterceptor; import club.joylink.rtss.entity.project.Project; import club.joylink.rtss.entity.project.ProjectView; import club.joylink.rtss.services.project.ProjectService; +import club.joylink.rtss.vo.AccountVO; import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.client.org.CompanyVO; import club.joylink.rtss.vo.project.*; @@ -66,8 +68,13 @@ public class ProjectInfoController { return projectService.projectOrgList(id); } - @GetMapping("/viewSetting/page") + @PostMapping("/{id}/createDefaultOrg") + public ProjectInfoVO quickCreateDefaultOrg(@PathVariable Long id, String name + , @RequestAttribute(AuthenticateInterceptor.LOGIN_USER_KEY) AccountVO user) { + return projectService.quickCreateDefaultOrg(id, name, user); + } + @GetMapping("/viewSetting/page") public PageVO projectViewPagingQuery(ProjectViewQueryVO queryVO) { return projectService.projectViewPagingQuery(queryVO); } diff --git a/src/main/java/club/joylink/rtss/services/project/ProjectService.java b/src/main/java/club/joylink/rtss/services/project/ProjectService.java index 5bb1671fb..08cfb8878 100644 --- a/src/main/java/club/joylink/rtss/services/project/ProjectService.java +++ b/src/main/java/club/joylink/rtss/services/project/ProjectService.java @@ -2,6 +2,7 @@ package club.joylink.rtss.services.project; import club.joylink.rtss.entity.project.Project; import club.joylink.rtss.entity.project.ProjectView; +import club.joylink.rtss.vo.AccountVO; import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.client.org.CompanyVO; import club.joylink.rtss.vo.project.*; @@ -58,6 +59,11 @@ public interface ProjectService { */ List projectOrgList(Long id); + /** + * 快速创建默认组织 + */ + ProjectInfoVO quickCreateDefaultOrg(Long id, String name, AccountVO user); + /** * 前端设置信息分页 */ diff --git a/src/main/java/club/joylink/rtss/services/project/ProjectServiceImpl.java b/src/main/java/club/joylink/rtss/services/project/ProjectServiceImpl.java index ef545f40d..4e84c6baf 100644 --- a/src/main/java/club/joylink/rtss/services/project/ProjectServiceImpl.java +++ b/src/main/java/club/joylink/rtss/services/project/ProjectServiceImpl.java @@ -12,8 +12,10 @@ import club.joylink.rtss.entity.project.Project; import club.joylink.rtss.entity.project.ProjectExample; import club.joylink.rtss.entity.project.ProjectView; import club.joylink.rtss.entity.project.ProjectViewExample; +import club.joylink.rtss.services.org.OrgService; import club.joylink.rtss.simulation.cbtc.exception.SimulationException; import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType; +import club.joylink.rtss.vo.AccountVO; import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.client.org.CompanyVO; import club.joylink.rtss.vo.project.*; @@ -52,6 +54,9 @@ public class ProjectServiceImpl implements ProjectService { @Autowired private OrgDAO orgDAO; + @Autowired + private OrgService orgService; + @Override public PageVO pagingQuery(ProjectQueryVO queryVO) { PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize()); @@ -157,49 +162,29 @@ public class ProjectServiceImpl implements ProjectService { return List.of(); } - private List getOrgProjectList(List projectCodeList) { - OrgProjectExample orgProjectExample = new OrgProjectExample(); - orgProjectExample.createCriteria().andProjectCodeIn(projectCodeList); - return orgProjectDao.selectByExample(orgProjectExample); - } - - private List getOrgList(List orgIdList) { - OrgExample orgExample = new OrgExample(); - orgExample.createCriteria().andIdIn(orgIdList); - return orgDAO.selectByExample(orgExample); - } - - /** - * 查询项目列表时,关联组织信息 - */ - private List handleProjectOrgInfo(List projectList) { - List projectCodeList = projectList.stream().map(Project::getCode).collect(Collectors.toList()); - if (CollectionUtils.isEmpty(projectCodeList)) { - return List.of(); + @Override + @Transactional(rollbackFor = Exception.class) + @CacheEvict(cacheNames = "project", allEntries = true) + public ProjectInfoVO quickCreateDefaultOrg(Long id, String name, AccountVO user) { + Project project = projectDAO.selectByPrimaryKey(id); + if (project == null) { + throw new SimulationException(SimulationExceptionType.Illegal_Argument, "项目不存在"); } - List orgProjectList = getOrgProjectList(projectCodeList); - Map orgMap = new HashMap<>(); - Map> orgProjectMap = new HashMap<>(orgProjectList.size()); + List orgProjectList = getOrgProjectList(List.of(project.getCode())); if (!CollectionUtils.isEmpty(orgProjectList)) { - List orgIdList = orgProjectList.stream().map(OrgProject::getOrgId).distinct().collect(Collectors.toList()); - List orgList = getOrgList(orgIdList); - orgMap.putAll(orgList.stream().collect(Collectors.toMap(Org::getId, o -> o))); - orgProjectMap.putAll(orgProjectList.stream().collect(Collectors.groupingBy(OrgProject::getProjectCode, Collectors.mapping(OrgProject::getOrgId, Collectors.toList())))); + throw new SimulationException(SimulationExceptionType.Illegal_Argument, "存在关联组织,请设置"); } - // 包装projectVO - List projectVOList = projectList.stream().map(p -> { - ProjectInfoVO projectVO = new ProjectInfoVO(p); - if (orgProjectMap.containsKey(p.getCode())) { - List orgNameList = orgProjectMap.get(p.getCode()).stream().filter(id -> orgMap.containsKey(id)) - .map(id -> orgMap.get(id).getName()).sorted().collect(Collectors.toList()); - projectVO.setOrgName(orgNameList); - } - if (p.getDefaultOrg() != null && orgMap.containsKey(p.getDefaultOrg())) { - projectVO.setDefaultOrgName(orgMap.get(p.getDefaultOrg()).getName()); - } - return projectVO; - }).collect(Collectors.toList()); - return projectVOList; + // 保存默认组织 + CompanyVO companyVO = new CompanyVO(); + companyVO.setName(name); + companyVO.setProjectCodes(List.of(project.getCode())); + CompanyVO resultCompany = orgService.createTopOrg(companyVO, user); + // 修改项目信息 + setProjectDefaultOrg(id, resultCompany.getId()); + ProjectInfoVO projectVO = new ProjectInfoVO(project); + projectVO.setOrgList(List.of(name)); + projectVO.setDefaultOrgName(name); + return projectVO; } @Override @@ -325,4 +310,49 @@ public class ProjectServiceImpl implements ProjectService { List projectList = projectViewDAO.selectWithBLOBsByExample(new ProjectViewExample()); return projectList.stream().map(projectView -> new ProjectViewVO(projectView)).collect(Collectors.toList()); } + + private List getOrgProjectList(List projectCodeList) { + OrgProjectExample orgProjectExample = new OrgProjectExample(); + orgProjectExample.createCriteria().andProjectCodeIn(projectCodeList); + return orgProjectDao.selectByExample(orgProjectExample); + } + + private List getOrgList(List orgIdList) { + OrgExample orgExample = new OrgExample(); + orgExample.createCriteria().andIdIn(orgIdList); + return orgDAO.selectByExample(orgExample); + } + + /** + * 查询项目列表时,关联组织信息 + */ + private List handleProjectOrgInfo(List projectList) { + List projectCodeList = projectList.stream().map(Project::getCode).collect(Collectors.toList()); + if (CollectionUtils.isEmpty(projectCodeList)) { + return List.of(); + } + List orgProjectList = getOrgProjectList(projectCodeList); + Map orgMap = new HashMap<>(); + Map> orgProjectMap = new HashMap<>(orgProjectList.size()); + if (!CollectionUtils.isEmpty(orgProjectList)) { + List orgIdList = orgProjectList.stream().map(OrgProject::getOrgId).distinct().collect(Collectors.toList()); + List orgList = getOrgList(orgIdList); + orgMap.putAll(orgList.stream().collect(Collectors.toMap(Org::getId, o -> o))); + orgProjectMap.putAll(orgProjectList.stream().collect(Collectors.groupingBy(OrgProject::getProjectCode, Collectors.mapping(OrgProject::getOrgId, Collectors.toList())))); + } + // 包装projectVO + List projectVOList = projectList.stream().map(p -> { + ProjectInfoVO projectVO = new ProjectInfoVO(p); + if (orgProjectMap.containsKey(p.getCode())) { + List orgNameList = orgProjectMap.get(p.getCode()).stream().filter(id -> orgMap.containsKey(id)) + .map(id -> orgMap.get(id).getName()).sorted().collect(Collectors.toList()); + projectVO.setOrgList(orgNameList); + } + if (p.getDefaultOrg() != null && orgMap.containsKey(p.getDefaultOrg())) { + projectVO.setDefaultOrgName(orgMap.get(p.getDefaultOrg()).getName()); + } + return projectVO; + }).collect(Collectors.toList()); + return projectVOList; + } } \ No newline at end of file diff --git a/src/main/java/club/joylink/rtss/vo/project/ProjectInfoVO.java b/src/main/java/club/joylink/rtss/vo/project/ProjectInfoVO.java index 03c435810..d36262204 100644 --- a/src/main/java/club/joylink/rtss/vo/project/ProjectInfoVO.java +++ b/src/main/java/club/joylink/rtss/vo/project/ProjectInfoVO.java @@ -3,6 +3,7 @@ package club.joylink.rtss.vo.project; import club.joylink.rtss.entity.project.Project; import lombok.Getter; import lombok.Setter; +import org.springframework.util.CollectionUtils; import java.util.List; @@ -40,7 +41,7 @@ public class ProjectInfoVO { /** * 关联组织名称 */ - private List orgName; + private List orgList; /** * 默认组织ID @@ -52,6 +53,11 @@ public class ProjectInfoVO { */ private String defaultOrgName; + /** + * 是否可以创建默认组织 + */ + private boolean createDefaultOrg; + public ProjectInfoVO(Project project) { this.id = project.getId(); this.code = project.getCode(); @@ -60,4 +66,9 @@ public class ProjectInfoVO { this.serverSetting = project.getServerSetting(); this.defaultOrg = project.getDefaultOrg(); } + + public void setOrgList(List orgList) { + this.orgList = orgList; + this.createDefaultOrg = CollectionUtils.isEmpty(orgList); + } }