【项目快捷创建组织接口】
This commit is contained in:
parent
1973bf3f24
commit
8c9c9eb0c0
@ -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<ProjectView> projectViewPagingQuery(ProjectViewQueryVO queryVO) {
|
||||
return projectService.projectViewPagingQuery(queryVO);
|
||||
}
|
||||
|
@ -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<CompanyVO> projectOrgList(Long id);
|
||||
|
||||
/**
|
||||
* 快速创建默认组织
|
||||
*/
|
||||
ProjectInfoVO quickCreateDefaultOrg(Long id, String name, AccountVO user);
|
||||
|
||||
/**
|
||||
* 前端设置信息分页
|
||||
*/
|
||||
|
@ -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<ProjectInfoVO> pagingQuery(ProjectQueryVO queryVO) {
|
||||
PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize());
|
||||
@ -157,49 +162,29 @@ public class ProjectServiceImpl implements ProjectService {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
private List<OrgProject> getOrgProjectList(List<String> projectCodeList) {
|
||||
OrgProjectExample orgProjectExample = new OrgProjectExample();
|
||||
orgProjectExample.createCriteria().andProjectCodeIn(projectCodeList);
|
||||
return orgProjectDao.selectByExample(orgProjectExample);
|
||||
}
|
||||
|
||||
private List<Org> getOrgList(List<Long> orgIdList) {
|
||||
OrgExample orgExample = new OrgExample();
|
||||
orgExample.createCriteria().andIdIn(orgIdList);
|
||||
return orgDAO.selectByExample(orgExample);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询项目列表时,关联组织信息
|
||||
*/
|
||||
private List<ProjectInfoVO> handleProjectOrgInfo(List<Project> projectList) {
|
||||
List<String> 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<OrgProject> orgProjectList = getOrgProjectList(projectCodeList);
|
||||
Map<Long, Org> orgMap = new HashMap<>();
|
||||
Map<String, List<Long>> orgProjectMap = new HashMap<>(orgProjectList.size());
|
||||
List<OrgProject> orgProjectList = getOrgProjectList(List.of(project.getCode()));
|
||||
if (!CollectionUtils.isEmpty(orgProjectList)) {
|
||||
List<Long> orgIdList = orgProjectList.stream().map(OrgProject::getOrgId).distinct().collect(Collectors.toList());
|
||||
List<Org> 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<ProjectInfoVO> projectVOList = projectList.stream().map(p -> {
|
||||
ProjectInfoVO projectVO = new ProjectInfoVO(p);
|
||||
if (orgProjectMap.containsKey(p.getCode())) {
|
||||
List<String> 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<ProjectView> projectList = projectViewDAO.selectWithBLOBsByExample(new ProjectViewExample());
|
||||
return projectList.stream().map(projectView -> new ProjectViewVO(projectView)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private List<OrgProject> getOrgProjectList(List<String> projectCodeList) {
|
||||
OrgProjectExample orgProjectExample = new OrgProjectExample();
|
||||
orgProjectExample.createCriteria().andProjectCodeIn(projectCodeList);
|
||||
return orgProjectDao.selectByExample(orgProjectExample);
|
||||
}
|
||||
|
||||
private List<Org> getOrgList(List<Long> orgIdList) {
|
||||
OrgExample orgExample = new OrgExample();
|
||||
orgExample.createCriteria().andIdIn(orgIdList);
|
||||
return orgDAO.selectByExample(orgExample);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询项目列表时,关联组织信息
|
||||
*/
|
||||
private List<ProjectInfoVO> handleProjectOrgInfo(List<Project> projectList) {
|
||||
List<String> projectCodeList = projectList.stream().map(Project::getCode).collect(Collectors.toList());
|
||||
if (CollectionUtils.isEmpty(projectCodeList)) {
|
||||
return List.of();
|
||||
}
|
||||
List<OrgProject> orgProjectList = getOrgProjectList(projectCodeList);
|
||||
Map<Long, Org> orgMap = new HashMap<>();
|
||||
Map<String, List<Long>> orgProjectMap = new HashMap<>(orgProjectList.size());
|
||||
if (!CollectionUtils.isEmpty(orgProjectList)) {
|
||||
List<Long> orgIdList = orgProjectList.stream().map(OrgProject::getOrgId).distinct().collect(Collectors.toList());
|
||||
List<Org> 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<ProjectInfoVO> projectVOList = projectList.stream().map(p -> {
|
||||
ProjectInfoVO projectVO = new ProjectInfoVO(p);
|
||||
if (orgProjectMap.containsKey(p.getCode())) {
|
||||
List<String> 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;
|
||||
}
|
||||
}
|
@ -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<String> orgName;
|
||||
private List<String> 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<String> orgList) {
|
||||
this.orgList = orgList;
|
||||
this.createDefaultOrg = CollectionUtils.isEmpty(orgList);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user