From e81fa4548d7ef2ea754248139b1b79b05e63849c Mon Sep 17 00:00:00 2001 From: joylink_zhangsai <1021828630@qq.com> Date: Fri, 9 Dec 2022 18:04:38 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E9=99=A4=E5=AF=B9Org.projectCode?= =?UTF-8?q?=E7=9A=84=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rtss/controller/CompanyController.java | 36 ++--- .../rtss/controller/org/OrgController.java | 4 +- .../controller/org/OrgProjectController.java | 6 +- .../project/ProjectInfoController.java | 8 +- .../java/club/joylink/rtss/entity/Org.java | 5 +- .../rtss/services/ISysUserService.java | 15 +- .../joylink/rtss/services/SysUserService.java | 109 ++++++-------- .../rtss/services/org/IOrgProjectService.java | 2 + .../services/org/IOrgScoringRuleService.java | 4 +- .../rtss/services/org/IOrgService.java | 26 ++-- .../rtss/services/org/IOrgUserService.java | 18 +-- .../rtss/services/org/OrgProjectService.java | 38 ++--- .../services/org/OrgScoringRuleService.java | 14 +- .../joylink/rtss/services/org/OrgService.java | 133 +++++++++++------- .../rtss/services/org/OrgUserService.java | 69 +++++---- .../rtss/services/project/ProjectService.java | 6 +- .../services/project/ProjectServiceImpl.java | 12 +- .../java/club/joylink/rtss/vo/AccountVO.java | 24 ++-- .../club/joylink/rtss/vo/LoginUserInfoVO.java | 15 +- .../rtss/vo/client/ExamDefinitionVO.java | 4 +- .../joylink/rtss/vo/client/org/CompanyVO.java | 75 ---------- .../rtss/vo/client/org/OrgProjectVO.java | 3 - .../org/{DepartmentVO.java => OrgVO.java} | 63 ++++++--- 23 files changed, 315 insertions(+), 374 deletions(-) delete mode 100644 src/main/java/club/joylink/rtss/vo/client/org/CompanyVO.java rename src/main/java/club/joylink/rtss/vo/client/org/{DepartmentVO.java => OrgVO.java} (61%) diff --git a/src/main/java/club/joylink/rtss/controller/CompanyController.java b/src/main/java/club/joylink/rtss/controller/CompanyController.java index 7467eaff1..225dcb419 100644 --- a/src/main/java/club/joylink/rtss/controller/CompanyController.java +++ b/src/main/java/club/joylink/rtss/controller/CompanyController.java @@ -44,7 +44,7 @@ public class CompanyController { * 创建顶级组织 */ @PostMapping - public CompanyVO create(@RequestBody @Validated CompanyVO company, @RequestAttribute(AuthenticateInterceptor.LOGIN_USER_KEY) AccountVO user) { + public OrgVO create(@RequestBody @Validated OrgVO company, @RequestAttribute(AuthenticateInterceptor.LOGIN_USER_KEY) AccountVO user) { return iOrgService.createTopOrg(company, user); } @@ -52,7 +52,7 @@ public class CompanyController { * 获取公司列表 */ @GetMapping - public List queryAll() { + public List queryAll() { return iOrgService.queryAllTopOrg(); } @@ -60,7 +60,7 @@ public class CompanyController { * 分页获取公司列表 */ @GetMapping("paging") - public PageVO pagingQueryAll(OrgQueryVO queryVO) { + public PageVO pagingQueryAll(OrgQueryVO queryVO) { return iOrgService.pagedQueryAllTopOrg(queryVO); } @@ -68,7 +68,7 @@ public class CompanyController { * 查询公司信息 */ @GetMapping("{id}") - public CompanyVO get(@PathVariable Long id) { + public OrgVO get(@PathVariable Long id) { return iOrgService.get(id); } @@ -76,7 +76,7 @@ public class CompanyController { * 更新公司信息 */ @PutMapping("{id}") - public CompanyVO updateCompany(@PathVariable Long id, @RequestBody @Validated CompanyVO company, @RequestAttribute AccountVO user) { + public OrgVO updateCompany(@PathVariable Long id, @RequestBody @Validated OrgVO company, @RequestAttribute AccountVO user) { return iOrgService.updateOrg(id, company, user); } @@ -84,7 +84,7 @@ public class CompanyController { * 微信小程用户绑定为单位管理员 */ @PutMapping(path = "/bind/company") - public CompanyVO userScanCodeBindCompany(Long userId, Long companyId) { + public OrgVO userScanCodeBindCompany(Long userId, Long companyId) { return iOrgUserService.userScanCodeBindCompanyManager(userId, companyId); } @@ -92,15 +92,15 @@ public class CompanyController { * 添加部门信息 */ @PostMapping(path = "/dept") - public DepartmentVO createDepart(@RequestBody @Validated DepartmentVO departmentVO) { - return iOrgUserService.createDepart(departmentVO); + public OrgVO createDepart(@RequestBody @Validated OrgVO orgVO) { + return iOrgUserService.createDepart(orgVO); } /** * 获取单位所有部门 */ @GetMapping(path = "{companyId}/dept") - public List queryCompanyDepart(@PathVariable Long companyId) { + public List queryCompanyDepart(@PathVariable Long companyId) { return iOrgUserService.getCompanyAllDepart(companyId); } @@ -108,7 +108,7 @@ public class CompanyController { * 获取部门及其子树 */ @GetMapping(path = "{companyId}/dept/{deptId}/tree") - public DepartmentVO queryDepartTree(@PathVariable Long deptId, @PathVariable Long companyId) { + public OrgVO queryDepartTree(@PathVariable Long deptId, @PathVariable Long companyId) { return iOrgUserService.getDepartTree(companyId, deptId); } @@ -116,7 +116,7 @@ public class CompanyController { * 获取部门及其子部门 */ @GetMapping(path = "{companyId}/dept/{deptId}") - public List queryDepart(@PathVariable Long deptId, @PathVariable Long companyId) { + public List queryDepart(@PathVariable Long deptId, @PathVariable Long companyId) { return iOrgUserService.getDepartAndChild(companyId, deptId); } @@ -132,16 +132,16 @@ public class CompanyController { * 查询部门信息 */ @GetMapping("/dept/{deptId}") - public DepartmentVO getDepart(@PathVariable Long deptId) { - return iOrgUserService.getDepartById(deptId); + public OrgVO queryDepart(@PathVariable Long deptId) { + return iOrgUserService.queryDepartById(deptId); } /** * 更新部门信息 */ @PutMapping("/dept/{id}") - public void updateDepartInfo(@PathVariable Long id, @RequestBody @Validated DepartmentVO departmentVO) { - iOrgUserService.updateDepartInfo(id, departmentVO); + public void updateDepartInfo(@PathVariable Long id, @RequestBody @Validated OrgVO orgVO) { + iOrgUserService.updateDepartInfo(id, orgVO); } /** @@ -228,7 +228,7 @@ public class CompanyController { * 分页查询当前登录用户所属组织下的班级 */ @GetMapping("/paged/cls") - public PageVO pagedQuerySelfCls(OrgQueryVO queryVO, @RequestAttribute LoginUserInfoVO loginInfo) { + public PageVO pagedQuerySelfCls(OrgQueryVO queryVO, @RequestAttribute LoginUserInfoVO loginInfo) { return iOrgService.pagedQueryCls(queryVO, loginInfo); } @@ -236,7 +236,7 @@ public class CompanyController { * 查询当前登录项目所属组织下的班级 */ @GetMapping("/list/cls") - public List queryCls(OrgQueryVO queryVO, @RequestAttribute LoginUserInfoVO loginInfo) { + public List queryCls(OrgQueryVO queryVO, @RequestAttribute LoginUserInfoVO loginInfo) { return iOrgService.queryCls(queryVO, loginInfo); } @@ -302,7 +302,7 @@ public class CompanyController { * 查询规则能够应用到的组织 */ @GetMapping("/orgScoringRule/{ruleId}/canApplyTo") - public List queryRuleCanApplyTo(@PathVariable Long ruleId, @RequestAttribute AccountVO user) { + public List queryRuleCanApplyTo(@PathVariable Long ruleId, @RequestAttribute AccountVO user) { return iOrgScoringRuleService.queryRuleCanApplyTo(ruleId, user); } diff --git a/src/main/java/club/joylink/rtss/controller/org/OrgController.java b/src/main/java/club/joylink/rtss/controller/org/OrgController.java index d3df41233..501bf5135 100644 --- a/src/main/java/club/joylink/rtss/controller/org/OrgController.java +++ b/src/main/java/club/joylink/rtss/controller/org/OrgController.java @@ -1,7 +1,7 @@ package club.joylink.rtss.controller.org; import club.joylink.rtss.services.org.IOrgService; -import club.joylink.rtss.vo.client.org.DepartmentVO; +import club.joylink.rtss.vo.client.org.OrgVO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -23,7 +23,7 @@ public class OrgController { * 列表查询该组织下的所有班级 */ @GetMapping("/{topOrgId}/cls/list") - public List listQueryCls(@PathVariable long topOrgId) { + public List listQueryCls(@PathVariable long topOrgId) { return iOrgService.listQueryCls(topOrgId); } } diff --git a/src/main/java/club/joylink/rtss/controller/org/OrgProjectController.java b/src/main/java/club/joylink/rtss/controller/org/OrgProjectController.java index a2750b18f..e62a6b610 100644 --- a/src/main/java/club/joylink/rtss/controller/org/OrgProjectController.java +++ b/src/main/java/club/joylink/rtss/controller/org/OrgProjectController.java @@ -5,8 +5,8 @@ import club.joylink.rtss.entity.org.OrgProject; import club.joylink.rtss.services.org.IOrgProjectService; import club.joylink.rtss.services.org.OrgService; import club.joylink.rtss.vo.LoginUserInfoVO; -import club.joylink.rtss.vo.client.org.CompanyVO; import club.joylink.rtss.vo.client.org.OrgProjectVO; +import club.joylink.rtss.vo.client.org.OrgVO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; @@ -57,8 +57,8 @@ public class OrgProjectController { OrgProject orgProject = new OrgProject(); orgProject.setCreateTime(LocalDateTime.now()); orgProject.setCreatorId(1L); - List orgs = orgService.queryAllTopOrg(); - for (CompanyVO org : orgs) { + List orgs = orgService.queryAllTopOrg(); + for (OrgVO org : orgs) { List projectCodes = org.getProjectCodes(); if (!CollectionUtils.isEmpty(projectCodes)) { for (String projectCode : projectCodes) { 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 59a35153e..a8459676e 100644 --- a/src/main/java/club/joylink/rtss/controller/project/ProjectInfoController.java +++ b/src/main/java/club/joylink/rtss/controller/project/ProjectInfoController.java @@ -6,7 +6,7 @@ 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.client.org.OrgVO; import club.joylink.rtss.vo.project.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -69,14 +69,14 @@ public class ProjectInfoController { } @GetMapping("/{id}/orgList") - public List orgList(@PathVariable Long id) { + public List orgList(@PathVariable Long id) { return projectService.projectOrgList(id); } @PostMapping("/{id}/createDefaultOrg") - public ProjectInfoVO quickCreateDefaultOrg(@PathVariable Long id, @RequestBody CompanyVO companyVO + public ProjectInfoVO quickCreateDefaultOrg(@PathVariable Long id, @RequestBody OrgVO orgVO , @RequestAttribute(AuthenticateInterceptor.LOGIN_USER_KEY) AccountVO user) { - return projectService.quickCreateDefaultOrg(id, companyVO, user); + return projectService.quickCreateDefaultOrg(id, orgVO, user); } @GetMapping("/viewSetting/page") diff --git a/src/main/java/club/joylink/rtss/entity/Org.java b/src/main/java/club/joylink/rtss/entity/Org.java index 55931e44c..1b6885639 100644 --- a/src/main/java/club/joylink/rtss/entity/Org.java +++ b/src/main/java/club/joylink/rtss/entity/Org.java @@ -4,7 +4,7 @@ import java.io.Serializable; import java.time.LocalDateTime; /** - * @author + * @author * 组织树 */ public class Org implements Serializable { @@ -28,6 +28,7 @@ public class Org implements Serializable { /** * 关联项目code */ + @Deprecated(forRemoval = true) private String projectCode; private String code; @@ -211,4 +212,4 @@ public class Org implements Serializable { sb.append("]"); return sb.toString(); } -} \ No newline at end of file +} diff --git a/src/main/java/club/joylink/rtss/services/ISysUserService.java b/src/main/java/club/joylink/rtss/services/ISysUserService.java index c3a156e2c..0ea9b3921 100644 --- a/src/main/java/club/joylink/rtss/services/ISysUserService.java +++ b/src/main/java/club/joylink/rtss/services/ISysUserService.java @@ -1,12 +1,11 @@ package club.joylink.rtss.services; -import club.joylink.rtss.entity.Org; import club.joylink.rtss.entity.SysAccount; import club.joylink.rtss.vo.AccountVO; import club.joylink.rtss.vo.LoginUserInfoVO; import club.joylink.rtss.vo.UserQueryVO; import club.joylink.rtss.vo.client.PageVO; -import club.joylink.rtss.vo.client.org.CompanyVO; +import club.joylink.rtss.vo.client.org.OrgVO; import club.joylink.rtss.vo.client.user.*; import club.joylink.rtss.vo.user.AccountCreateVO; import club.joylink.rtss.vo.wx.WmUserSession; @@ -33,16 +32,6 @@ public interface ISysUserService { */ AccountVO findUserById(Long id); - /** - * 设置用户的(与项目{project}关联的)组织信息 - */ - void setOrgInfoOfOrgRelWithTheProject(String project, AccountVO accountVO); - - /** - * 设置用户与该组织的关联信息 - */ - void setOrgInfoOfThisOrg(Org topOrg, AccountVO accountVO); - SysAccount findEntity(@NonNull String account, long orgId); boolean isExist(@NonNull String account, long orgId); @@ -308,7 +297,7 @@ public interface ISysUserService { */ void userBindWm(String code, Long userId); - CompanyVO userScanCodeBindCompanyManager(Long userId, Long companyId); + OrgVO userScanCodeBindCompanyManager(Long userId, Long companyId); AccountVO getUserBaseInfoById(Long id); diff --git a/src/main/java/club/joylink/rtss/services/SysUserService.java b/src/main/java/club/joylink/rtss/services/SysUserService.java index c0c1b3b6e..8aec54394 100644 --- a/src/main/java/club/joylink/rtss/services/SysUserService.java +++ b/src/main/java/club/joylink/rtss/services/SysUserService.java @@ -1,6 +1,5 @@ package club.joylink.rtss.services; -import club.joylink.rtss.configuration.configProp.WeChatConfig; import club.joylink.rtss.constants.BusinessConsts; import club.joylink.rtss.constants.EmailSubject; import club.joylink.rtss.constants.StatusEnum; @@ -10,13 +9,14 @@ import club.joylink.rtss.dao.UserSubscribeMapper; import club.joylink.rtss.entity.*; import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.services.cache.ICacheService; +import club.joylink.rtss.services.org.IOrgProjectService; import club.joylink.rtss.services.org.IOrgService; import club.joylink.rtss.services.org.IOrgUserService; import club.joylink.rtss.util.EncryptUtil; import club.joylink.rtss.util.RandomGenerator; import club.joylink.rtss.vo.*; import club.joylink.rtss.vo.client.PageVO; -import club.joylink.rtss.vo.client.org.CompanyVO; +import club.joylink.rtss.vo.client.org.OrgVO; import club.joylink.rtss.vo.client.user.*; import club.joylink.rtss.vo.map.MapVO; import club.joylink.rtss.vo.user.AccountCreateVO; @@ -64,9 +64,6 @@ public class SysUserService implements ISysUserService { @Autowired private UserSubscribeMapper userSubscribeMapper; - @Autowired - private WeChatConfig weChatConfig; - @Autowired private IWxApiService iWxApiService; @@ -84,6 +81,8 @@ public class SysUserService implements ISysUserService { @Autowired private QRCodeManager qrCodeManager; + @Autowired + private IOrgProjectService iOrgProjectService; /** * @update 20221019 删除账号查询逻辑,去除绑定组织操作 @@ -112,47 +111,6 @@ public class SysUserService implements ISysUserService { return accountVO; } - @Override - public void setOrgInfoOfOrgRelWithTheProject(String project, AccountVO accountVO) { - if (project != null) { - Org topOrg = iOrgService.findTopOrgOfUser(accountVO.getId()); - if (topOrg != null && topOrg.getProjectCode().contains(project)) { - setOrgInfoOfThisOrg(topOrg, accountVO); - } - } - } - - @Override - public void setOrgInfoOfThisOrg(Org topOrg, AccountVO accountVO) { - if (topOrg != null && accountVO != null && topOrg.getId() != null && accountVO.getId() != null) { - boolean flag = false; - if (Objects.equals(topOrg.getId(), accountVO.getOrgId())) { - flag = true; - } else { - List orgUsers = iOrgUserService.findEntitiesByUserId(accountVO.getId(), null); - if (CollectionUtils.isEmpty(orgUsers)) - return; - if (orgUsers.stream().anyMatch(ou -> Objects.equals(ou.getOrgId(), topOrg.getId()))) { - flag = true; - } else { - List orgIds = orgUsers.stream().map(OrgUser::getOrgId).collect(Collectors.toList()); - if (CollectionUtils.isEmpty(orgIds)) - return; - List orgs = iOrgService.findEntities(orgIds, BusinessConsts.Org.Status.VALID); - if (CollectionUtils.isEmpty(orgs)) - return; - Set userRelTopOrgId = orgs.stream().map(Org::getRootId).collect(Collectors.toSet()); //用户直接或间接关联的所有顶级组织id - if (userRelTopOrgId.contains(topOrg.getId())) { - flag = true; - } - } - } - if (flag) { - accountVO.setOrgInfo(topOrg, iOrgUserService.isTheRoleInThisOrg(accountVO.getId(), topOrg.getId(), BusinessConsts.OrgRole.Admin)); - } - } - } - @Override public SysAccount findEntity(@NonNull String account, long orgId) { SysAccountExample example = new SysAccountExample(); @@ -301,20 +259,32 @@ public class SysUserService implements ISysUserService { PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize()); Page page = (Page) this.sysAccountDAO.selectByExample(example); List accountVOS = AccountVO.convertFromDB(page.getResult()); - List userIds = accountVOS.stream().map(AccountVO::getId).collect(Collectors.toList()); - Map userOrgMap = iOrgUserService.findEntitiesByUserIds(userIds, BusinessConsts.OrgRole.Admin) - .stream().collect(Collectors.toMap(OrgUser::getUserId, OrgUser::getOrgId)); - Map orgMap = iOrgService.findEntities(new ArrayList<>(userOrgMap.values()), BusinessConsts.Org.Status.VALID) - .stream().collect(Collectors.toMap(Org::getId, Function.identity())); - accountVOS.forEach(vo -> { - Long orgId = userOrgMap.get(vo.getId()); - if (orgId != null) { - Org org = orgMap.get(orgId); - if (org != null) { - vo.setOrgInfo(org, true); - } +// List userIds = accountVOS.stream().map(AccountVO::getId).collect(Collectors.toList()); +// Map userOrgMap = iOrgUserService.findEntitiesByUserIds(userIds, BusinessConsts.OrgRole.Admin) +// .stream().collect(Collectors.toMap(OrgUser::getUserId, OrgUser::getOrgId)); +// Map orgMap = iOrgService.findEntities(new ArrayList<>(userOrgMap.values()), BusinessConsts.Org.Status.VALID) +// .stream().collect(Collectors.toMap(Org::getId, Function.identity())); +// Map> orgId_projects_map = iOrgProjectService.queryOrgProjectListByOrgIds(new ArrayList<>(orgMap.keySet())).stream() +// .collect(Collectors.groupingBy(OrgProject::getOrgId, Collectors.mapping(OrgProject::getProjectCode, Collectors.toList()))); +// accountVOS.forEach(vo -> { +// Long orgId = userOrgMap.get(vo.getId()); +// if (orgId != null) { +// Org org = orgMap.get(orgId); +// if (org != null) { +// vo.setOrgInfo(org, true, orgId_projects_map.get(org.getId())); +// } +// } +// }); + List orgIds = accountVOS.stream().map(AccountVO::getOrgId).collect(Collectors.toList()); + Map orgMap = iOrgService.findEntities(orgIds, null).stream() + .collect(Collectors.toMap(Org::getId, Function.identity())); + accountVOS.forEach(accountVO -> { + Org org = orgMap.get(accountVO.getOrgId()); + if (org != null) { + accountVO.setOrgInfo(org, false, null); } }); + return PageVO.convert(page, accountVOS); } @@ -405,15 +375,13 @@ public class SysUserService implements ISysUserService { @Override @Transactional - public CompanyVO userScanCodeBindCompanyManager(Long userId, Long companyId) { - Org company = companyDAO.selectByPrimaryKey(companyId); - BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(company, String.format("id为[%s]的组织不存在", companyId)); + public OrgVO userScanCodeBindCompanyManager(Long userId, Long companyId) { SysAccount sysAccount = sysAccountDAO.selectByPrimaryKey(userId); BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(sysAccount, String.format("id为[%s]的用户不存在", userId)); AccountVO accountVO = new AccountVO(sysAccount); - iOrgUserService.userBindCompanyManager(accountVO, companyId); + OrgVO orgVO = iOrgUserService.userBindCompanyManager(accountVO, companyId); this.loginSessionManager.updateLoginUser(accountVO); - return new CompanyVO(company); + return orgVO; } @Override @@ -1056,11 +1024,16 @@ public class SysUserService implements ISysUserService { private AccountVO queryUserInfoWithOrgInfo(long userId) { SysAccount sysAccount = getEntity(userId); AccountVO accountVO = new AccountVO(sysAccount); - List adminOrgUser = iOrgUserService.findEntitiesByUserId(userId, BusinessConsts.OrgRole.Admin); - if (!CollectionUtils.isEmpty(adminOrgUser)) { - Org org = iOrgService.findEntity(adminOrgUser.get(0).getOrgId()); - accountVO.setOrgInfo(org, true); - } +// 2022-12-09 17:27:30 账号组织关系变成一对多之后,这里逻辑不清楚了,经查,只用到了account字段,故删除以下 +// List adminOrgUser = iOrgUserService.findEntitiesByUserId(userId, BusinessConsts.OrgRole.Admin); +// if (!CollectionUtils.isEmpty(adminOrgUser)) { +// Org org = iOrgService.findEntity(adminOrgUser.get(0).getOrgId()); +// if (org != null) { +// List projects = iOrgProjectService.queryOrgProjectListByOrgId(org.getId()).stream() +// .map(OrgProject::getProjectCode).collect(Collectors.toList()); +// accountVO.setOrgInfo(org, true, projects); +// } +// } return accountVO; } diff --git a/src/main/java/club/joylink/rtss/services/org/IOrgProjectService.java b/src/main/java/club/joylink/rtss/services/org/IOrgProjectService.java index d592692fb..ffc62c8c3 100644 --- a/src/main/java/club/joylink/rtss/services/org/IOrgProjectService.java +++ b/src/main/java/club/joylink/rtss/services/org/IOrgProjectService.java @@ -37,4 +37,6 @@ public interface IOrgProjectService { * 保存顶级信息时,处理编辑信息 */ void update(Long orgId, List projectList, AccountVO user); + + List queryOrgProjectListByOrgIds(List orgIds); } diff --git a/src/main/java/club/joylink/rtss/services/org/IOrgScoringRuleService.java b/src/main/java/club/joylink/rtss/services/org/IOrgScoringRuleService.java index 0c462cc7f..056b8068e 100644 --- a/src/main/java/club/joylink/rtss/services/org/IOrgScoringRuleService.java +++ b/src/main/java/club/joylink/rtss/services/org/IOrgScoringRuleService.java @@ -3,10 +3,10 @@ package club.joylink.rtss.services.org; import club.joylink.rtss.vo.AccountVO; import club.joylink.rtss.vo.LoginUserInfoVO; import club.joylink.rtss.vo.client.PageVO; -import club.joylink.rtss.vo.client.org.DepartmentVO; import club.joylink.rtss.vo.client.org.OrgScoringResultVO; import club.joylink.rtss.vo.client.org.OrgScoringRuleQueryVO; import club.joylink.rtss.vo.client.org.OrgScoringRuleVO; +import club.joylink.rtss.vo.client.org.OrgVO; import org.springframework.transaction.annotation.Transactional; import java.util.List; @@ -57,5 +57,5 @@ public interface IOrgScoringRuleService { * 查询评价规则能应用到的组织 * @return */ - List queryRuleCanApplyTo(Long ruleId, AccountVO user); + List queryRuleCanApplyTo(Long ruleId, AccountVO user); } diff --git a/src/main/java/club/joylink/rtss/services/org/IOrgService.java b/src/main/java/club/joylink/rtss/services/org/IOrgService.java index eed5d6f44..f33058330 100644 --- a/src/main/java/club/joylink/rtss/services/org/IOrgService.java +++ b/src/main/java/club/joylink/rtss/services/org/IOrgService.java @@ -6,10 +6,9 @@ import club.joylink.rtss.vo.LoginUserInfoVO; import club.joylink.rtss.vo.client.ExamDefinitionVO; import club.joylink.rtss.vo.client.Node; import club.joylink.rtss.vo.client.PageVO; -import club.joylink.rtss.vo.client.org.CompanyVO; -import club.joylink.rtss.vo.client.org.DepartmentVO; import club.joylink.rtss.vo.client.org.NonTopOrgCreateVO; import club.joylink.rtss.vo.client.org.OrgQueryVO; +import club.joylink.rtss.vo.client.org.OrgVO; import org.springframework.transaction.annotation.Transactional; import java.util.Collection; @@ -17,11 +16,11 @@ import java.util.List; public interface IOrgService { @Transactional - CompanyVO createTopOrg(CompanyVO companyVO, AccountVO user); + OrgVO createTopOrg(OrgVO orgVO, AccountVO user); - List queryAllTopOrg(); + List queryAllTopOrg(); - PageVO pagedQueryAllTopOrg(OrgQueryVO queryVO); + PageVO pagedQueryAllTopOrg(OrgQueryVO queryVO); void confirmExist(Long orgId); @@ -37,7 +36,7 @@ public interface IOrgService { // TODO 20220922 将Project 修改为 String Collection findEntities(String project, String status); - CompanyVO updateOrg(Long id, CompanyVO companyVO, AccountVO user); + OrgVO updateOrg(Long id, OrgVO orgVO, AccountVO user); /** * 删除非顶级组织 @@ -51,12 +50,12 @@ public interface IOrgService { /** * 分页查询自己创建的班级 */ - PageVO pagedQueryCls(OrgQueryVO queryVO, LoginUserInfoVO loginInfo); + PageVO pagedQueryCls(OrgQueryVO queryVO, LoginUserInfoVO loginInfo); /** * 查询自己创建的班级 */ - List queryCls(OrgQueryVO queryVO, LoginUserInfoVO loginInfo); + List queryCls(OrgQueryVO queryVO, LoginUserInfoVO loginInfo); /** * 获取该组织所属的顶级组织 @@ -70,7 +69,7 @@ public interface IOrgService { */ Node adminQueryOrgTree(Long orgId); - CompanyVO get(Long id); + OrgVO get(Long id); /** * 查询这些考试关联的班级 @@ -96,5 +95,12 @@ public interface IOrgService { * 查询该组织下的所有班级。 * 目前组织结构仅有两级,非顶级的就是班级。 */ - List listQueryCls(long topOrgId); + List listQueryCls(long topOrgId); + + /** + * 查询组织信息(可能返回null) + */ + OrgVO query(Long id); + + OrgVO getTopOrg(long topOrgId); } diff --git a/src/main/java/club/joylink/rtss/services/org/IOrgUserService.java b/src/main/java/club/joylink/rtss/services/org/IOrgUserService.java index bfd1057e2..09a3ef94f 100644 --- a/src/main/java/club/joylink/rtss/services/org/IOrgUserService.java +++ b/src/main/java/club/joylink/rtss/services/org/IOrgUserService.java @@ -15,21 +15,21 @@ public interface IOrgUserService { /** * 用户绑定为单位管理员 */ - CompanyVO userScanCodeBindCompanyManager(Long userId, Long companyId); + OrgVO userScanCodeBindCompanyManager(Long userId, Long companyId); - DepartmentVO createDepart(DepartmentVO departmentVO); + OrgVO createDepart(OrgVO orgVO); - void updateDepartInfo(Long id, DepartmentVO departmentVO); + void updateDepartInfo(Long id, OrgVO orgVO); - DepartmentVO getDepartById(Long deptId); + OrgVO queryDepartById(Long deptId); - List getCompanyDepartTree(Long companyId); + List getCompanyDepartTree(Long companyId); - List getCompanyAllDepart(Long companyId); + List getCompanyAllDepart(Long companyId); - DepartmentVO getDepartTree(Long companyId, Long deptId); + OrgVO getDepartTree(Long companyId, Long deptId); - List getDepartAndChild(Long companyId, Long deptId); + List getDepartAndChild(Long companyId, Long deptId); void addDepartUserInfo(AccountVO user, UserDepartRelVO userDepartRelVO); @@ -74,7 +74,7 @@ public interface IOrgUserService { List findEntitiesByUserId(long userId, BusinessConsts.OrgRole role); - void userBindCompanyManager(AccountVO accountVO, Long topOrgId); + OrgVO userBindCompanyManager(AccountVO accountVO, Long topOrgId); List statisticUsage(UsageQueryVO queryVO); diff --git a/src/main/java/club/joylink/rtss/services/org/OrgProjectService.java b/src/main/java/club/joylink/rtss/services/org/OrgProjectService.java index 5de9b9aaf..fb2da28c5 100644 --- a/src/main/java/club/joylink/rtss/services/org/OrgProjectService.java +++ b/src/main/java/club/joylink/rtss/services/org/OrgProjectService.java @@ -15,6 +15,7 @@ import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType; import club.joylink.rtss.vo.AccountVO; import club.joylink.rtss.vo.LoginUserInfoVO; import club.joylink.rtss.vo.client.org.OrgProjectVO; +import club.joylink.rtss.vo.client.org.OrgVO; import club.joylink.rtss.vo.project.ProjectVO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -22,6 +23,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -38,6 +40,10 @@ public class OrgProjectService implements IOrgProjectService { @Autowired private OrgDAO orgDAO; + @Autowired + private IOrgService iOrgService; + @Autowired + private IOrgUserService iOrgUserService; @Override public List queryOrgProjectListByOrgId(Long orgId) { @@ -78,24 +84,9 @@ public class OrgProjectService implements IOrgProjectService { @Override public void signInOrg(Long orgId, LoginUserInfoVO loginInfo) { - // TODO 验证权限 - - Org topOrg = orgDAO.selectByPrimaryKey(orgId); - if (topOrg == null) { - throw new SimulationException(SimulationExceptionType.Illegal_Argument); - } - // 是否是顶级组织的管理员 - OrgUserExample example = new OrgUserExample(); - example.createCriteria().andUserIdEqualTo(loginInfo.getAccountVO().getId()).andOrgIdEqualTo(orgId); - List orgUserList = orgUserDAO.selectByExample(example); - OrgProjectVO orgProjectVO = new OrgProjectVO(topOrg); - if (!CollectionUtils.isEmpty(orgUserList)) { - List roleList = orgUserList.stream().map(OrgUser::getRole).collect(Collectors.toList()); - orgProjectVO.setRole(roleList); - } else { - orgProjectVO.setRole(List.of()); - } - loginInfo.setOrgProjectVO(orgProjectVO); + OrgVO orgVO = iOrgService.getTopOrg(orgId); + boolean orgAdmin = iOrgUserService.isTheRoleInThisOrg(loginInfo.getAccountVO().getId(), orgId, BusinessConsts.OrgRole.Admin); + loginInfo.setOrgProjectVO(orgVO, orgAdmin); } @Override @@ -139,6 +130,17 @@ public class OrgProjectService implements IOrgProjectService { } } + @Override + public List queryOrgProjectListByOrgIds(List orgIds) { + if (CollectionUtils.isEmpty(orgIds)) { + return new ArrayList<>(); + } else { + OrgProjectExample example = new OrgProjectExample(); + example.createCriteria().andOrgIdIn(orgIds); + return orgProjectDao.selectByExample(example); + } + } + /** * 判断数组是否发生变化 */ diff --git a/src/main/java/club/joylink/rtss/services/org/OrgScoringRuleService.java b/src/main/java/club/joylink/rtss/services/org/OrgScoringRuleService.java index 0e893cd1a..644bcfee7 100644 --- a/src/main/java/club/joylink/rtss/services/org/OrgScoringRuleService.java +++ b/src/main/java/club/joylink/rtss/services/org/OrgScoringRuleService.java @@ -4,6 +4,7 @@ import club.joylink.rtss.constants.BusinessConsts; import club.joylink.rtss.dao.OrgScoringRuleDAO; import club.joylink.rtss.dao.OrgScoringRuleRelDAO; import club.joylink.rtss.entity.*; +import club.joylink.rtss.entity.org.OrgProject; import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.services.IExamService; import club.joylink.rtss.services.ISysUserService; @@ -14,10 +15,10 @@ import club.joylink.rtss.vo.AccountVO; import club.joylink.rtss.vo.LoginUserInfoVO; import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.client.UserRankStatsVO; -import club.joylink.rtss.vo.client.org.DepartmentVO; import club.joylink.rtss.vo.client.org.OrgScoringResultVO; import club.joylink.rtss.vo.client.org.OrgScoringRuleQueryVO; import club.joylink.rtss.vo.client.org.OrgScoringRuleVO; +import club.joylink.rtss.vo.client.org.OrgVO; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import lombok.NonNull; @@ -68,6 +69,8 @@ public class OrgScoringRuleService implements IOrgScoringRuleService { @Autowired private IOrgExamService iOrgExamService; + @Autowired + private IOrgProjectService iOrgProjectService; @Override @@ -233,7 +236,7 @@ public class OrgScoringRuleService implements IOrgScoringRuleService { } @Override - public List queryRuleCanApplyTo(Long ruleId, AccountVO user) { + public List queryRuleCanApplyTo(Long ruleId, AccountVO user) { OrgScoringRuleWithBLOBs rule = getRuleEntity(ruleId); OrgScoringRuleVO vo = OrgScoringRuleVO.buildDetails(rule, null); List lessonIds = vo.getAllLessonIds(); @@ -251,9 +254,9 @@ public class OrgScoringRuleService implements IOrgScoringRuleService { clsIds.addAll(iOrgExamService.findEntities(examIds, user.getId()) .stream().map(OrgExam::getOrgId).collect(Collectors.toList())); } else { - return DepartmentVO.convert2VOList(iOrgService.findEntitiesByParentId(rule.getOrgId(), null, BusinessConsts.Org.Status.VALID)); + return OrgVO.convert2VOList(iOrgService.findEntitiesByParentId(rule.getOrgId(), null, BusinessConsts.Org.Status.VALID)); } - return DepartmentVO.convert2VOList(iOrgService.findEntities(clsIds, BusinessConsts.Org.Status.VALID)); + return OrgVO.convert2VOList(iOrgService.findEntities(clsIds, BusinessConsts.Org.Status.VALID)); } private void check4Update(OrgScoringRuleVO orgScoringRuleVO) { @@ -306,8 +309,9 @@ public class OrgScoringRuleService implements IOrgScoringRuleService { List userIds = students.stream().map(OrgUser::getUserId).collect(Collectors.toList()); List users = iSysUserService.findEntities(userIds, "id"); Org topOrg = iOrgService.getTopOrgEntity(orgScoringRuleVO.getOrgIds().get(0)); + List projects = iOrgProjectService.queryOrgProjectListByOrgId(topOrg.getId()).stream() + .map(OrgProject::getProjectCode).collect(Collectors.toList()); List results = users.stream().map(OrgScoringResultVO::new).collect(Collectors.toList()); - List projects = List.of(topOrg.getProjectCode().split(",")); this.score(results, orgScoringRuleVO.getScoringRules(), projects); return results; } diff --git a/src/main/java/club/joylink/rtss/services/org/OrgService.java b/src/main/java/club/joylink/rtss/services/org/OrgService.java index 39e5f08d5..efc3d4a0f 100644 --- a/src/main/java/club/joylink/rtss/services/org/OrgService.java +++ b/src/main/java/club/joylink/rtss/services/org/OrgService.java @@ -6,6 +6,7 @@ import club.joylink.rtss.entity.Org; import club.joylink.rtss.entity.OrgExample; import club.joylink.rtss.entity.OrgUser; import club.joylink.rtss.entity.SysAccount; +import club.joylink.rtss.entity.org.OrgProject; import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.services.ISysUserService; import club.joylink.rtss.services.QRCodeManager; @@ -14,7 +15,10 @@ import club.joylink.rtss.vo.LoginUserInfoVO; import club.joylink.rtss.vo.client.ExamDefinitionVO; import club.joylink.rtss.vo.client.Node; import club.joylink.rtss.vo.client.PageVO; -import club.joylink.rtss.vo.client.org.*; +import club.joylink.rtss.vo.client.org.NonTopOrgCreateVO; +import club.joylink.rtss.vo.client.org.OrgQueryVO; +import club.joylink.rtss.vo.client.org.OrgUserVO; +import club.joylink.rtss.vo.client.org.OrgVO; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import lombok.NonNull; @@ -48,14 +52,14 @@ public class OrgService implements IOrgService { @Transactional @Override - public CompanyVO createTopOrg(CompanyVO companyVO, AccountVO user) { + public OrgVO createTopOrg(OrgVO orgVO, AccountVO user) { // /* 检查 */ -// if (!CollectionUtils.isEmpty(companyVO.getProjectCodes())) { -// confirmProjectCodesNotRepeat(null, companyVO.getProjectCodes()); +// if (!CollectionUtils.isEmpty(orgVO.getProjectCodes())) { +// confirmProjectCodesNotRepeat(null, orgVO.getProjectCodes()); // } - confirmNameUnique(null, companyVO.getName()); + confirmNameUnique(null, orgVO.getName()); /* 处理 */ - Org entity = companyVO.toDB(); + Org entity = orgVO.toDB(); entity.setId(null); entity.setCreatorId(user.getId()); entity.setCreateTime(LocalDateTime.now()); @@ -64,8 +68,8 @@ public class OrgService implements IOrgService { entity.setRootId(entity.getId()); orgDAO.updateByPrimaryKey(entity); // 20220929 增加 - orgProjectService.save(entity.getId(), companyVO.getProjectCodes(), user); - return new CompanyVO(entity); + orgProjectService.save(entity.getId(), orgVO.getProjectCodes(), user); + return new OrgVO(entity, orgVO.getProjectCodes()); } /** @@ -83,15 +87,17 @@ public class OrgService implements IOrgService { } @Override - public List queryAllTopOrg() { + public List queryAllTopOrg() { OrgExample example = new OrgExample(); example.createCriteria().andParentIdIsNull(); - List list = this.orgDAO.selectByExample(example); - return CompanyVO.convert2VOList(list); + List orgs = this.orgDAO.selectByExample(example); + List orgIds = orgs.stream().map(Org::getId).collect(Collectors.toList()); + List orgProjects = orgProjectService.queryOrgProjectListByOrgIds(orgIds); + return OrgVO.convert2VOList(orgs, orgProjects); } @Override - public PageVO pagedQueryAllTopOrg(OrgQueryVO queryVO) { + public PageVO pagedQueryAllTopOrg(OrgQueryVO queryVO) { PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize()); OrgExample example = new OrgExample(); OrgExample.Criteria criteria = example.createCriteria(); @@ -100,7 +106,9 @@ public class OrgService implements IOrgService { criteria.andNameLike(String.format("%%%s%%", queryVO.getName())); } Page page = (Page) orgDAO.selectByExample(example); - List voList = CompanyVO.convert2VOList(page.getResult()); + List orgIds = page.getResult().stream().map(Org::getId).collect(Collectors.toList()); + List orgProjects = orgProjectService.queryOrgProjectListByOrgIds(orgIds); + List voList = OrgVO.convert2VOList(page.getResult(), orgProjects); return PageVO.convert(page, voList); } @@ -152,23 +160,25 @@ public class OrgService implements IOrgService { } @Override - public CompanyVO updateOrg(Long id, CompanyVO companyVO, AccountVO user) { + public OrgVO updateOrg(Long id, OrgVO orgVO, AccountVO user) { //校验 Org org = getEntity(id); - if (!CollectionUtils.isEmpty(companyVO.getProjectCodes())) { + if (!CollectionUtils.isEmpty(orgVO.getProjectCodes())) { BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertTrue(isTopOrg(org), "非顶级组织不能修改关联项目"); -// confirmProjectCodesNotRepeat(org.getId(), companyVO.getProjectCodes()); +// confirmProjectCodesNotRepeat(org.getId(), orgVO.getProjectCodes()); // 20220929 增加 - orgProjectService.update(id, companyVO.getProjectCodes(), user); + orgProjectService.update(id, orgVO.getProjectCodes(), user); } - confirmNameUnique(id, companyVO.getName()); + confirmNameUnique(id, orgVO.getName()); //更新 - org.setName(companyVO.getName()); - org.setProjectCode(companyVO.getDBProjectCode()); + org.setName(orgVO.getName()); +// org.setProjectCode(orgVO.getDBProjectCode()); org.setUpdateId(user.getId()); org.setUpdateTime(LocalDateTime.now()); this.orgDAO.updateByPrimaryKeySelective(org); - return new CompanyVO(org); + List projects = orgProjectService.queryOrgProjectListByOrgId(org.getId()).stream() + .map(OrgProject::getProjectCode).collect(Collectors.toList()); + return new OrgVO(org, projects); } @Override @@ -194,21 +204,19 @@ public class OrgService implements IOrgService { } @Override - public PageVO pagedQueryCls(OrgQueryVO queryVO, LoginUserInfoVO loginInfo) { + public PageVO pagedQueryCls(OrgQueryVO queryVO, LoginUserInfoVO loginInfo) { OrgExample example = new OrgExample(); OrgExample.Criteria criteria = example.createCriteria().andParentIdEqualTo(loginInfo.getTopOrgId()) .andStatusEqualTo(BusinessConsts.Org.Status.VALID); - if (queryVO != null) { - if (StringUtils.hasText(queryVO.getName())) { - criteria.andNameLike(String.format("%%%s%%", queryVO.getName())); - } - if (StringUtils.hasText(queryVO.getCreatorName())) { - List creatorIds = iSysUserService.findUserByName(queryVO.getCreatorName()).stream().map(AccountVO::getId).collect(Collectors.toList()); - if (CollectionUtils.isEmpty(creatorIds)) { - return new PageVO<>(queryVO.getPageNum(), queryVO.getPageSize(), 0, new ArrayList<>()); - } else { - criteria.andCreatorIdIn(creatorIds); - } + if (StringUtils.hasText(queryVO.getName())) { + criteria.andNameLike(String.format("%%%s%%", queryVO.getName())); + } + if (StringUtils.hasText(queryVO.getCreatorName())) { + List creatorIds = iSysUserService.findUserByName(queryVO.getCreatorName()).stream().map(AccountVO::getId).collect(Collectors.toList()); + if (CollectionUtils.isEmpty(creatorIds)) { + return new PageVO<>(queryVO.getPageNum(), queryVO.getPageSize(), 0, new ArrayList<>()); + } else { + criteria.andCreatorIdIn(creatorIds); } } PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize()); @@ -216,15 +224,15 @@ public class OrgService implements IOrgService { List creatorIds = page.stream().map(Org::getCreatorId).collect(Collectors.toList()); Map creatorMap = iSysUserService.findEntities(creatorIds, null).stream() .collect(Collectors.toMap(SysAccount::getId, Function.identity())); - List list = page.getResult().stream().map(entity -> { + List list = page.getResult().stream().map(entity -> { int numberOfPeople = iOrgUserService.getQuantities(entity.getId(), BusinessConsts.OrgRole.Student); - return new DepartmentVO(entity, numberOfPeople, creatorMap.get(entity.getCreatorId())); + return new OrgVO(entity, null, numberOfPeople, creatorMap.get(entity.getCreatorId())); }).collect(Collectors.toList()); return PageVO.convert(page, list); } @Override - public List queryCls(OrgQueryVO queryVO, LoginUserInfoVO loginInfo) { + public List queryCls(OrgQueryVO queryVO, LoginUserInfoVO loginInfo) { OrgExample example = new OrgExample(); OrgExample.Criteria criteria = example.createCriteria() .andParentIdEqualTo(loginInfo.getTopOrgId()) @@ -235,7 +243,7 @@ public class OrgService implements IOrgService { } } List clsList = orgDAO.selectByExample(example); - return clsList.stream().map(DepartmentVO::new).collect(Collectors.toList()); + return clsList.stream().map(OrgVO::new).collect(Collectors.toList()); } @Override @@ -263,13 +271,13 @@ public class OrgService implements IOrgService { @Override public Node adminQueryOrgTree(Long orgId) { /* 先筛选组织 */ - Org org = getEntity(orgId); - Map> groupByParentIdOrg = findEntitiesByRootId(org.getRootId(), null, BusinessConsts.Org.Status.VALID) - .stream().filter(o -> o.getParentId() != null).collect(Collectors.groupingBy(Org::getParentId)); - Node root = new Node<>(new DepartmentVO(org), Node.Type.ORG); + OrgVO orgVO = get(orgId); + Map> groupByParentIdOrg = findEntitiesByRootId(orgVO.getRootId(), null, BusinessConsts.Org.Status.VALID) + .stream().filter(o -> !isTopOrg(o)).collect(Collectors.groupingBy(Org::getParentId)); + Node root = new Node<>(orgVO, Node.Type.ORG); Map> all_orgId_node_map = new HashMap<>(); //所有的组织和对应的节点 Map> orgId_node_map = new HashMap<>(); - orgId_node_map.put(org.getId(), root); + orgId_node_map.put(orgVO.getId(), root); while (!orgId_node_map.isEmpty()) { all_orgId_node_map.putAll(orgId_node_map); Map> newMap = new HashMap<>(); @@ -277,7 +285,7 @@ public class OrgService implements IOrgService { List childOrgList = groupByParentIdOrg.get(k); if (!CollectionUtils.isEmpty(childOrgList)) { List> children = childOrgList.stream().map(o -> { - Node node = new Node<>(new DepartmentVO(o), Node.Type.ORG); + Node node = new Node<>(new OrgVO(o), Node.Type.ORG); newMap.put(o.getId(), node); return node; }).collect(Collectors.toList()); @@ -309,9 +317,10 @@ public class OrgService implements IOrgService { } @Override - public CompanyVO get(Long id) { - Org entity = getEntity(id); - return new CompanyVO(entity); + public OrgVO get(Long id) { + OrgVO vo = query(id); + BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(vo, String.format("[id:%s]的组织不存在", id)); + return vo; } @Override @@ -381,9 +390,35 @@ public class OrgService implements IOrgService { } @Override - public List listQueryCls(long topOrgId) { + public List listQueryCls(long topOrgId) { List clsList = findClsByTopOrgId(topOrgId); - return DepartmentVO.convert2VOList(clsList); + return OrgVO.convert2VOList(clsList); + } + + @Override + public OrgVO query(Long id) { + Org entity = findEntity(id); + if (entity == null) { + return null; + } + List projects; + if (isTopOrg(entity)) { + projects = orgProjectService.queryOrgProjectListByOrgId(entity.getId()).stream() + .map(OrgProject::getProjectCode).collect(Collectors.toList()); + } else { + projects = null; + } + return new OrgVO(entity, projects); + } + + @Override + public OrgVO getTopOrg(long topOrgId) { + Org org = getEntity(topOrgId); + BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(isTopOrg(org), + String.format("[id:%s]的组织不是顶级组织", topOrgId)); + List projects = orgProjectService.queryOrgProjectListByOrgId(topOrgId) + .stream().map(OrgProject::getProjectCode).collect(Collectors.toList()); + return new OrgVO(org, projects); } /** @@ -420,7 +455,7 @@ public class OrgService implements IOrgService { } private boolean isTopOrg(long orgId) { - return getEntity(orgId).getParentId() == null; + return isTopOrg(getEntity(orgId)); } private boolean isTopOrg(Org org) { diff --git a/src/main/java/club/joylink/rtss/services/org/OrgUserService.java b/src/main/java/club/joylink/rtss/services/org/OrgUserService.java index 89a5c20c1..9f8dbf66b 100644 --- a/src/main/java/club/joylink/rtss/services/org/OrgUserService.java +++ b/src/main/java/club/joylink/rtss/services/org/OrgUserService.java @@ -66,7 +66,7 @@ public class OrgUserService implements IOrgUserService { @Override - public CompanyVO userScanCodeBindCompanyManager(Long userId, Long companyId) { + public OrgVO userScanCodeBindCompanyManager(Long userId, Long companyId) { return iSysUserService.userScanCodeBindCompanyManager(userId, companyId); } @@ -76,23 +76,22 @@ public class OrgUserService implements IOrgUserService { * 增加部门 */ @Override - public DepartmentVO createDepart(DepartmentVO departmentVO) { - BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertNotTrue(departmentIsExist(departmentVO), "同级部门信息重复"); - Org entity = departmentVO.toDB(); + public OrgVO createDepart(OrgVO orgVO) { + BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertNotTrue(departmentIsExist(orgVO), "同级部门信息重复"); + Org entity = orgVO.toDB(); orgDAO.insert(entity); - departmentVO.setId(entity.getId()); - return departmentVO; + orgVO.setId(entity.getId()); + return orgVO; } /** * 修改部门 */ @Override - public void updateDepartInfo(Long deptId, DepartmentVO departmentVO) { - Org entity = departmentVO.toDB(); + public void updateDepartInfo(Long deptId, OrgVO orgVO) { + Org entity = orgVO.toDB(); entity.setId(deptId); entity.setRootId(null); - entity.setProjectCode(null); orgDAO.updateByPrimaryKeySelective(entity); } @@ -102,12 +101,8 @@ public class OrgUserService implements IOrgUserService { * @param deptId */ @Override - public DepartmentVO getDepartById(Long deptId) { - Org entity = orgDAO.selectByPrimaryKey(deptId); - if (Objects.isNull(entity)) { - return null; - } - return new DepartmentVO(entity); + public OrgVO queryDepartById(Long deptId) { + return iOrgService.query(deptId); } /** @@ -116,54 +111,54 @@ public class OrgUserService implements IOrgUserService { * @param companyId */ @Override - public List getCompanyDepartTree(Long companyId) { + public List getCompanyDepartTree(Long companyId) { OrgExample example = new OrgExample(); example.createCriteria().andRootIdEqualTo(companyId); List orgList = orgDAO.selectByExample(example); - return DepartmentVO.buildDeptTree(DepartmentVO.convert2VOList(orgList)); + return OrgVO.buildDeptTree(OrgVO.convert2VOList(orgList)); } @Override - public List getCompanyAllDepart(Long companyId) { + public List getCompanyAllDepart(Long companyId) { OrgExample example = new OrgExample(); example.createCriteria().andRootIdEqualTo(companyId).andParentIdIsNotNull(); List companyDepartments = orgDAO.selectByExample(example); - return DepartmentVO.convert2VOList(companyDepartments); + return OrgVO.convert2VOList(companyDepartments); } @Override - public DepartmentVO getDepartTree(Long companyId, Long deptId) { + public OrgVO getDepartTree(Long companyId, Long deptId) { Org companyDepartment = orgDAO.selectByPrimaryKey(deptId); OrgExample example = new OrgExample(); example.createCriteria().andRootIdEqualTo(companyId).andParentIdIsNotNull(); List companyDepartments = orgDAO.selectByExample(example); - List childDept = DepartmentVO.getChildDept(deptId, DepartmentVO.convert2VOList(companyDepartments)); - DepartmentVO departmentVO = new DepartmentVO(companyDepartment); - departmentVO.setChildDept(childDept); - return departmentVO; + List childDept = OrgVO.getChildDept(deptId, OrgVO.convert2VOList(companyDepartments)); + OrgVO orgVO = new OrgVO(companyDepartment); + orgVO.setChildDept(childDept); + return orgVO; } @Override - public List getDepartAndChild(Long companyId, Long deptId) { + public List getDepartAndChild(Long companyId, Long deptId) { var example = new OrgExample(); example.createCriteria().andRootIdEqualTo(companyId).andParentIdIsNotNull(); var companyDepartments = orgDAO.selectByExample(example); - var childDept = DepartmentVO.getChildDeptList(deptId, DepartmentVO.convert2VOList(companyDepartments)); + var childDept = OrgVO.getChildDeptList(deptId, OrgVO.convert2VOList(companyDepartments)); var companyDepartment = orgDAO.selectByPrimaryKey(deptId); - childDept.add(new DepartmentVO(companyDepartment)); + childDept.add(new OrgVO(companyDepartment)); return childDept; } - private boolean departmentIsExist(DepartmentVO departmentVO) { + private boolean departmentIsExist(OrgVO orgVO) { var example = new OrgExample(); OrgExample.Criteria criteria = example.createCriteria() - .andRootIdEqualTo(departmentVO.getRootId()) - .andNameEqualTo(departmentVO.getName()); - if (Objects.isNull(departmentVO.getParentId())) { + .andRootIdEqualTo(orgVO.getRootId()) + .andNameEqualTo(orgVO.getName()); + if (Objects.isNull(orgVO.getParentId())) { criteria.andParentIdIsNull(); } else { - criteria.andParentIdEqualTo(departmentVO.getParentId()); + criteria.andParentIdEqualTo(orgVO.getParentId()); } return orgDAO.countByExample(example) != 0; @@ -373,9 +368,9 @@ public class OrgUserService implements IOrgUserService { } @Override - public void userBindCompanyManager(AccountVO accountVO, Long topOrgId) { - Org topOrg = iOrgService.getEntity(topOrgId); - BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNull(topOrg.getParentId(), "所选组织不是顶级组织"); + public OrgVO userBindCompanyManager(AccountVO accountVO, Long topOrgId) { + OrgVO topOrgVO = iOrgService.get(topOrgId); + BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNull(topOrgVO.getParentId(), "所选组织不是顶级组织"); BusinessExceptionAssertEnum.OPERATION_REPEAT.assertNotTrue(isTheRoleInThisOrg(accountVO.getId(), topOrgId, BusinessConsts.OrgRole.Admin), "已经是所选组织管理员"); /* 如果是其它组织的管理员,删除关系 */ @@ -388,7 +383,9 @@ public class OrgUserService implements IOrgUserService { } /* 建立新关系 */ create(topOrgId, accountVO.getId(), BusinessConsts.OrgRole.Admin); - accountVO.setOrgInfo(topOrg, true); + return topOrgVO; + +// accountVO.setOrgInfo(topOrg, true); 现在登录信息里的组织信息应该是和登录的项目相关,所以不需要这个逻辑 } @Override 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 662c6bb26..832ab39c6 100644 --- a/src/main/java/club/joylink/rtss/services/project/ProjectService.java +++ b/src/main/java/club/joylink/rtss/services/project/ProjectService.java @@ -4,7 +4,7 @@ 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.client.org.OrgVO; import club.joylink.rtss.vo.project.*; import java.util.List; @@ -62,12 +62,12 @@ public interface ProjectService { /** * 根据项目ID获取与项目关联的所有组织信息 */ - List projectOrgList(Long id); + List projectOrgList(Long id); /** * 快速创建默认组织 */ - ProjectInfoVO quickCreateDefaultOrg(Long id, CompanyVO companyVO, AccountVO user); + ProjectInfoVO quickCreateDefaultOrg(Long id, OrgVO companyVO, 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 b9ca41057..2cb8e0a49 100644 --- a/src/main/java/club/joylink/rtss/services/project/ProjectServiceImpl.java +++ b/src/main/java/club/joylink/rtss/services/project/ProjectServiceImpl.java @@ -18,7 +18,7 @@ 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.client.org.OrgVO; import club.joylink.rtss.vo.project.*; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; @@ -166,7 +166,7 @@ public class ProjectServiceImpl implements ProjectService { } @Override - public List projectOrgList(Long id) { + public List projectOrgList(Long id) { Project project = projectDAO.selectByPrimaryKey(id); if (project == null) { throw new SimulationException(SimulationExceptionType.Illegal_Argument, "项目不存在"); @@ -175,7 +175,7 @@ public class ProjectServiceImpl implements ProjectService { if (!CollectionUtils.isEmpty(orgProjectList)) { List orgIdList = orgProjectList.stream().map(OrgProject::getOrgId).distinct().collect(Collectors.toList()); List orgList = getOrgList(orgIdList); - return orgList.stream().map(CompanyVO::simpleInfoVO).collect(Collectors.toList()); + return orgList.stream().map(OrgVO::simpleInfoVO).collect(Collectors.toList()); } return List.of(); } @@ -183,7 +183,7 @@ public class ProjectServiceImpl implements ProjectService { @Override @Transactional(rollbackFor = Exception.class) @CacheEvict(cacheNames = "project", allEntries = true) - public ProjectInfoVO quickCreateDefaultOrg(Long id, CompanyVO companyVO, AccountVO user) { + public ProjectInfoVO quickCreateDefaultOrg(Long id, OrgVO companyVO, AccountVO user) { Project project = projectDAO.selectByPrimaryKey(id); if (project == null) { throw new SimulationException(SimulationExceptionType.Illegal_Argument, "项目不存在"); @@ -194,7 +194,7 @@ public class ProjectServiceImpl implements ProjectService { } // 保存默认组织 companyVO.setProjectCodes(List.of(project.getCode())); - CompanyVO resultCompany = orgService.createTopOrg(companyVO, user); + OrgVO resultCompany = orgService.createTopOrg(companyVO, user); // 修改项目信息 setProjectDefaultOrg(id, resultCompany.getId()); ProjectInfoVO projectVO = new ProjectInfoVO(project); @@ -395,4 +395,4 @@ public class ProjectServiceImpl implements ProjectService { }).collect(Collectors.toList()); return projectVOList; } -} \ No newline at end of file +} diff --git a/src/main/java/club/joylink/rtss/vo/AccountVO.java b/src/main/java/club/joylink/rtss/vo/AccountVO.java index cdfe2a983..adf44745c 100644 --- a/src/main/java/club/joylink/rtss/vo/AccountVO.java +++ b/src/main/java/club/joylink/rtss/vo/AccountVO.java @@ -3,7 +3,7 @@ package club.joylink.rtss.vo; import club.joylink.rtss.constants.BusinessConsts; import club.joylink.rtss.entity.Org; import club.joylink.rtss.entity.SysAccount; -import club.joylink.rtss.vo.client.org.OrgProjectVO; +import club.joylink.rtss.vo.client.org.OrgVO; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; @@ -17,7 +17,6 @@ import javax.validation.constraints.NotBlank; import java.io.Serializable; import java.time.LocalDateTime; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -49,7 +48,7 @@ public class AccountVO implements Serializable { public static final String Type_3 = "3"; // 第三方企业子账户 /** - * 用户所属的顶级组织 + * 账号所属的组织(是账号表里的字段) */ private Long orgId; @@ -298,13 +297,11 @@ public class AccountVO implements Serializable { } } - public void setOrgInfo(Org org, Boolean companyAdmin) { + public void setOrgInfo(Org org, Boolean companyAdmin, List projectCodes) { this.companyId = org.getId(); this.companyName = org.getName(); this.companyAdmin = companyAdmin; - if (StringUtils.hasText(org.getProjectCode())) { - this.projectCodes = Arrays.asList(org.getProjectCode().split(",")); - } + this.projectCodes = projectCodes; } public void copyOrgInfo(AccountVO accountVO) { @@ -321,13 +318,12 @@ public class AccountVO implements Serializable { return Type_3.equalsIgnoreCase(this.type) && StringUtils.hasText(this.parentAccount); } - public void setOrgProjectVO(OrgProjectVO orgProjectVO) { - if (orgProjectVO != null) { - this.companyId = orgProjectVO.getOrgId(); - this.companyName = orgProjectVO.getName(); - this.companyAdmin = !CollectionUtils.isEmpty(orgProjectVO.getRole()) - && orgProjectVO.getRole().contains(BusinessConsts.OrgRole.Admin.name()); - this.projectCodes = Arrays.asList(orgProjectVO.getProjectCode().split(",")); + public void setOrgProjectVO(OrgVO orgVO, boolean orgAdmin) { + if (orgVO != null) { + this.companyId = orgVO.getId(); + this.companyName = orgVO.getName(); + this.companyAdmin = orgAdmin; + this.projectCodes = orgVO.getProjectCodes(); } else { this.companyId = 0L; this.companyName = null; diff --git a/src/main/java/club/joylink/rtss/vo/LoginUserInfoVO.java b/src/main/java/club/joylink/rtss/vo/LoginUserInfoVO.java index fb43c506a..871fbb1d9 100644 --- a/src/main/java/club/joylink/rtss/vo/LoginUserInfoVO.java +++ b/src/main/java/club/joylink/rtss/vo/LoginUserInfoVO.java @@ -4,7 +4,7 @@ import club.joylink.rtss.constants.Client; import club.joylink.rtss.entity.SysAccountLogin; import club.joylink.rtss.entity.project.Project; import club.joylink.rtss.util.EncryptUtil; -import club.joylink.rtss.vo.client.org.OrgProjectVO; +import club.joylink.rtss.vo.client.org.OrgVO; import club.joylink.rtss.vo.client.project.ProjectDeviceVO; import club.joylink.rtss.vo.project.ProjectVO; import lombok.Getter; @@ -50,9 +50,6 @@ public class LoginUserInfoVO { private LocalDateTime preLogoutTime; private LocalDateTime lastQueryTime; // 最后使用时间 - // 20220929 增加 - private OrgProjectVO orgProjectVO; - public LoginUserInfoVO(AccountVO accountVO, Client client, String project, ProjectDeviceVO deviceVO) { this.accountVO = accountVO; this.client = client; @@ -148,14 +145,10 @@ public class LoginUserInfoVO { * 获取顶级组织Id */ public Long getTopOrgId() { - if (orgProjectVO == null) { - return null; - } - return orgProjectVO.getTopOrgId(); + return getAccountVO().getCompanyId(); } - public void setOrgProjectVO(OrgProjectVO orgProjectVO) { - this.orgProjectVO = orgProjectVO; - this.accountVO.setOrgProjectVO(orgProjectVO); + public void setOrgProjectVO(OrgVO orgVO, boolean orgAdmin) { + this.accountVO.setOrgProjectVO(orgVO, orgAdmin); } } diff --git a/src/main/java/club/joylink/rtss/vo/client/ExamDefinitionVO.java b/src/main/java/club/joylink/rtss/vo/client/ExamDefinitionVO.java index f06f13a24..576d3e59c 100644 --- a/src/main/java/club/joylink/rtss/vo/client/ExamDefinitionVO.java +++ b/src/main/java/club/joylink/rtss/vo/client/ExamDefinitionVO.java @@ -2,7 +2,7 @@ package club.joylink.rtss.vo.client; import club.joylink.rtss.entity.ExamDefinition; import club.joylink.rtss.entity.SysAccount; -import club.joylink.rtss.vo.client.org.DepartmentVO; +import club.joylink.rtss.vo.client.org.OrgVO; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; @@ -135,7 +135,7 @@ public class ExamDefinitionVO { private Boolean system; /**关联班级列表*/ - private List classes; + private List classes; private List clsIds; diff --git a/src/main/java/club/joylink/rtss/vo/client/org/CompanyVO.java b/src/main/java/club/joylink/rtss/vo/client/org/CompanyVO.java deleted file mode 100644 index 36f68af7d..000000000 --- a/src/main/java/club/joylink/rtss/vo/client/org/CompanyVO.java +++ /dev/null @@ -1,75 +0,0 @@ -package club.joylink.rtss.vo.client.org; - -import club.joylink.rtss.entity.Org; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import org.springframework.util.CollectionUtils; -import org.springframework.util.StringUtils; - -import javax.validation.constraints.NotBlank; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -@Getter -@Setter -@NoArgsConstructor -public class CompanyVO { - - @JsonSerialize(using = ToStringSerializer.class) - private Long id; - - private String code; - /** - * 公司名称 - */ - @NotBlank(message = "公司名称不能为空") - private String name; - - private List projectCodes; - - public CompanyVO(Org entity) { - this.id = entity.getId(); - this.code = entity.getCode(); - this.name = entity.getName(); - if (StringUtils.hasText(entity.getProjectCode())) { - this.projectCodes = Arrays.asList(entity.getProjectCode().split(",")); - } - } - - public static CompanyVO simpleInfoVO(Org entity) { - CompanyVO companyVO = new CompanyVO(); - companyVO.setId(entity.getId()); - companyVO.setName(entity.getName()); - return companyVO; - } - - public static List convert2VOList(List dataList) { - List voList = new ArrayList<>(); - for (Org entity : dataList) { - voList.add(new CompanyVO(entity)); - } - return voList; - } - - public Org toDB() { - Org entity = new Org(); - entity.setId(this.id); - entity.setName(this.name); - entity.setProjectCode(getDBProjectCode()); - return entity; - } - - @JsonIgnore - public String getDBProjectCode() { - if (!CollectionUtils.isEmpty(projectCodes)) { - return String.join(",", projectCodes); - } else { - return null; - } - } -} diff --git a/src/main/java/club/joylink/rtss/vo/client/org/OrgProjectVO.java b/src/main/java/club/joylink/rtss/vo/client/org/OrgProjectVO.java index c2b6747bb..9a58d37f1 100644 --- a/src/main/java/club/joylink/rtss/vo/client/org/OrgProjectVO.java +++ b/src/main/java/club/joylink/rtss/vo/client/org/OrgProjectVO.java @@ -17,12 +17,9 @@ public class OrgProjectVO { private List role; - private String projectCode; - public OrgProjectVO(Org org) { this.orgId = org.getId(); this.name = org.getName(); this.topOrgId = org.getRootId(); - this.projectCode = org.getProjectCode(); } } diff --git a/src/main/java/club/joylink/rtss/vo/client/org/DepartmentVO.java b/src/main/java/club/joylink/rtss/vo/client/org/OrgVO.java similarity index 61% rename from src/main/java/club/joylink/rtss/vo/client/org/DepartmentVO.java rename to src/main/java/club/joylink/rtss/vo/client/org/OrgVO.java index b48aee8aa..20825a035 100644 --- a/src/main/java/club/joylink/rtss/vo/client/org/DepartmentVO.java +++ b/src/main/java/club/joylink/rtss/vo/client/org/OrgVO.java @@ -2,6 +2,7 @@ package club.joylink.rtss.vo.client.org; import club.joylink.rtss.entity.Org; import club.joylink.rtss.entity.SysAccount; +import club.joylink.rtss.entity.org.OrgProject; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; @@ -9,20 +10,19 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import org.springframework.util.CollectionUtils; -import org.springframework.util.StringUtils; import javax.validation.constraints.NotBlank; import java.time.LocalDateTime; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.stream.Collectors; @Getter @Setter @NoArgsConstructor -public class DepartmentVO { +public class OrgVO { @JsonSerialize(using = ToStringSerializer.class) private Long id; @@ -49,7 +49,7 @@ public class DepartmentVO { */ private Integer numberOfPeople; - private List childDept; + private List childDept; private Long creatorId; @@ -57,26 +57,28 @@ public class DepartmentVO { private String creatorNickName; - public DepartmentVO(Org entity) { + public OrgVO(Org entity) { this.id = entity.getId(); this.code = entity.getCode(); this.name = entity.getName(); - if (StringUtils.hasText(entity.getProjectCode())) { - this.projectCodes = Arrays.asList(entity.getProjectCode().split(",")); - } this.parentId = entity.getParentId(); this.rootId = entity.getRootId(); this.creatorId = entity.getCreatorId(); this.createTime = entity.getCreateTime(); } - public DepartmentVO(Org entity, Integer numberOfPeople) { + public OrgVO(Org entity, List projectCodes) { this(entity); + this.projectCodes = projectCodes; + } + + public OrgVO(Org entity, List projectCodes, Integer numberOfPeople) { + this(entity, projectCodes); this.numberOfPeople = numberOfPeople; } - public DepartmentVO(Org entity, Integer numberOfPeople, SysAccount creator) { - this(entity, numberOfPeople); + public OrgVO(Org entity, List projectCodes, Integer numberOfPeople, SysAccount creator) { + this(entity, projectCodes, numberOfPeople); if (creator != null) { this.creatorId = creator.getId(); this.creatorName = creator.getName(); @@ -84,11 +86,24 @@ public class DepartmentVO { } } - public static List convert2VOList(List dataList) { - if (CollectionUtils.isEmpty(dataList)) { + public static List convert2VOList(List orgs) { + if (CollectionUtils.isEmpty(orgs)) { return new ArrayList<>(); } else { - return dataList.stream().map(DepartmentVO::new).collect(Collectors.toList()); + return orgs.stream().map(OrgVO::new).collect(Collectors.toList()); + } + } + + public static List convert2VOList(List orgs, List orgProjects) { + if (CollectionUtils.isEmpty(orgs)) { + return new ArrayList<>(); + } else { + Map> orgId_projects_map = orgProjects.stream() + .collect(Collectors.groupingBy(OrgProject::getOrgId, + Collectors.mapping(OrgProject::getProjectCode, Collectors.toList()))); + return orgs.stream() + .map(org -> new OrgVO(org, orgId_projects_map.get(org.getId()))) + .collect(Collectors.toList()); } } @@ -98,12 +113,11 @@ public class DepartmentVO { entity.setName(this.name); entity.setParentId(this.parentId); entity.setRootId(this.rootId); - entity.setProjectCode(String.join(",", this.projectCodes)); return entity; } - public static List buildDeptTree(List voList) { - List rootDeparts = new ArrayList<>(); + public static List buildDeptTree(List voList) { + List rootDeparts = new ArrayList<>(); voList.forEach(d -> { if (Objects.isNull(d.getParentId())) { d.setChildDept(getChildDept(d.getId(), voList)); @@ -113,8 +127,8 @@ public class DepartmentVO { return rootDeparts; } - public static List getChildDept(Long parentId, List list) { - List child = new ArrayList<>(); + public static List getChildDept(Long parentId, List list) { + List child = new ArrayList<>(); list.forEach(c -> { if (parentId == c.getParentId()) { child.add(c); @@ -129,8 +143,8 @@ public class DepartmentVO { return child; } - public static List getChildDeptList(Long parentId, List list) { - List child = new ArrayList<>(); + public static List getChildDeptList(Long parentId, List list) { + List child = new ArrayList<>(); list.forEach(c -> { if (parentId == c.getParentId()) { child.add(c); @@ -143,4 +157,11 @@ public class DepartmentVO { }); return child; } + + public static OrgVO simpleInfoVO(Org org) { + OrgVO orgVO = new OrgVO(); + orgVO.setId(org.getId()); + orgVO.setName(org.getName()); + return orgVO; + } }