From 8693449f85c44cf4943f1db4484898875eeffc61 Mon Sep 17 00:00:00 2001 From: tiger_zhou <123456> Date: Tue, 11 Oct 2022 10:03:39 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E7=90=86=E8=AE=BA=E8=AF=95=E9=A2=98?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E4=BB=A3=E7=A0=81=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../services/paper/PagerQuestionService.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/club/joylink/rtss/services/paper/PagerQuestionService.java b/src/main/java/club/joylink/rtss/services/paper/PagerQuestionService.java index 803456573..364165cef 100644 --- a/src/main/java/club/joylink/rtss/services/paper/PagerQuestionService.java +++ b/src/main/java/club/joylink/rtss/services/paper/PagerQuestionService.java @@ -38,8 +38,8 @@ public class PagerQuestionService { /** * 查询列表 - * @param queryVO - * @param isPaging + * @param queryVO   + * @param isPaging   * @param companyIdCanNull 是否允许公司组织id可以为空,true=管理使用,false = 组织使用 * @return */ @@ -68,7 +68,7 @@ public class PagerQuestionService { /** * 获取题库分页列表 - * @param queryVO + * @param queryVO   * @return */ public PageVO pagingQueryQuestions(QuestionQueryVO queryVO,boolean companyIdCanNull) { @@ -80,7 +80,7 @@ public class PagerQuestionService { /** * 获取题型列表 - * @param queryVO + * @param queryVO   * @return */ public List queryQuestions(QuestionQueryVO queryVO,boolean companyIdCanNull) { @@ -92,7 +92,7 @@ public class PagerQuestionService { /** * 获取题型所有数据 - * @param questionId + * @param questionId   * @param doNotCheckDel 是否检测数据状态是否删除 true = 不检测,false=检测 * @return */ @@ -166,8 +166,8 @@ public class PagerQuestionService { /** * 根据公司id和标签或类型查询 - * @param companyId - * @param queryVO + * @param companyId   + * @param queryVO   * @return */ public List queryQuestionsForRaceLable(Long companyId, PagerLableQueryVO queryVO) { @@ -185,8 +185,8 @@ public class PagerQuestionService { } /** * 添加修改 - * @param questionVO - * @param accountVO + * @param questionVO   + * @param accountVO   */ public void saveOrUpdate(PaperQuestionVO questionVO, AccountVO accountVO) { BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(Objects.isNull(questionVO.getOrgId()),"组织id不能为空"); From 2745d4950b9e771cc46bf9198486fe27c30a001f Mon Sep 17 00:00:00 2001 From: weizhihong Date: Wed, 12 Oct 2022 14:11:58 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E3=80=90=E9=A1=B9=E7=9B=AE=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E9=BB=98=E8=AE=A4=E7=BB=84=E7=BB=87=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=EF=BC=8C=E5=8E=BB=E9=99=A4=E5=89=8D=E7=AB=AF=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=AD=97=E6=AE=B5=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/20221015-wei-projectDefaultOrg.sql | 2 + .../project/ProjectInfoController.java | 21 ++-- .../joylink/rtss/entity/project/Project.java | 10 +- .../CompetitionPracticalService.java | 2 +- .../services/project/DeviceServiceImpl.java | 2 +- .../rtss/services/project/ProjectService.java | 20 ++-- .../services/project/ProjectServiceImpl.java | 99 +++++++++++++++++-- .../rtss/simulation/cbtc/Simulation.java | 56 ++++++++--- .../rtss/vo/project/ProjectInfoVO.java | 63 ++++++++++++ .../mybatis/mapper/ProjectDaoMapper.xml | 24 ++--- 10 files changed, 245 insertions(+), 54 deletions(-) create mode 100644 sql/20221015-wei-projectDefaultOrg.sql create mode 100644 src/main/java/club/joylink/rtss/vo/project/ProjectInfoVO.java diff --git a/sql/20221015-wei-projectDefaultOrg.sql b/sql/20221015-wei-projectDefaultOrg.sql new file mode 100644 index 000000000..37535a181 --- /dev/null +++ b/sql/20221015-wei-projectDefaultOrg.sql @@ -0,0 +1,2 @@ +alter table `joylink`.`project` +ADD COLUMN `default_org` bigint NULL comment '默认组织ID' AFTER `server_setting`; \ No newline at end of file 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 4e4231f38..da32cb4cb 100644 --- a/src/main/java/club/joylink/rtss/controller/project/ProjectInfoController.java +++ b/src/main/java/club/joylink/rtss/controller/project/ProjectInfoController.java @@ -1,13 +1,11 @@ package club.joylink.rtss.controller.project; +import club.joylink.rtss.entity.Org; 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.client.PageVO; -import club.joylink.rtss.vo.project.ProjectQueryVO; -import club.joylink.rtss.vo.project.ProjectVO; -import club.joylink.rtss.vo.project.ProjectViewQueryVO; -import club.joylink.rtss.vo.project.ProjectViewVO; +import club.joylink.rtss.vo.project.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -24,12 +22,12 @@ public class ProjectInfoController { private ProjectService projectService; @GetMapping("/page") - public PageVO pagingQuery(ProjectQueryVO queryVO) { + public PageVO pagingQuery(ProjectQueryVO queryVO) { return projectService.pagingQuery(queryVO); } @GetMapping("/all") - public List getAllProject() { + public List getAllProject() { return projectService.getAllProject(); } @@ -58,7 +56,18 @@ public class ProjectInfoController { return projectService.checkProjectCode(code); } + @PutMapping("/setDefaultOrg") + public void setProjectDefaultOrg(Long id, Long orgId) { + projectService.setProjectDefaultOrg(id, orgId); + } + + @GetMapping("/{id}/orgList") + public List orgList(@PathVariable Long id) { + return projectService.projectOrgList(id); + } + @GetMapping("/viewSetting/page") + public PageVO projectViewPagingQuery(ProjectViewQueryVO queryVO) { return projectService.projectViewPagingQuery(queryVO); } diff --git a/src/main/java/club/joylink/rtss/entity/project/Project.java b/src/main/java/club/joylink/rtss/entity/project/Project.java index 6464c918a..ab6890c99 100644 --- a/src/main/java/club/joylink/rtss/entity/project/Project.java +++ b/src/main/java/club/joylink/rtss/entity/project/Project.java @@ -60,16 +60,16 @@ public class Project { */ private Integer status; - /** - * 是否供前端选择 - */ - private Integer viewShow; - /** * 后端服务设置 */ private String serverSetting; + /** + * 默认组织ID + */ + private Long defaultOrg; + @JsonIgnore public static boolean isDefault(String code) { return StringUtils.isEmpty(code) || DEFAULT_PROJECT_LABEL.contains(code); diff --git a/src/main/java/club/joylink/rtss/services/completition/CompetitionPracticalService.java b/src/main/java/club/joylink/rtss/services/completition/CompetitionPracticalService.java index fffefb3b7..2123e8341 100644 --- a/src/main/java/club/joylink/rtss/services/completition/CompetitionPracticalService.java +++ b/src/main/java/club/joylink/rtss/services/completition/CompetitionPracticalService.java @@ -31,7 +31,6 @@ import club.joylink.rtss.util.VoiceFileUtils; 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.voice.VoiceRecognitionResult; import club.joylink.rtss.vo.client.competition.*; import club.joylink.rtss.vo.client.order.OrderCreateVO; import club.joylink.rtss.vo.client.order.OrderDetailCreateVO; @@ -41,6 +40,7 @@ import club.joylink.rtss.vo.client.permission.PermissionVO; import club.joylink.rtss.vo.client.script.ScriptActionVO; import club.joylink.rtss.vo.client.script.ScriptVO; import club.joylink.rtss.vo.client.userPermission.UserPermissionVO; +import club.joylink.rtss.vo.client.voice.VoiceRecognitionResult; import club.joylink.rtss.vo.map.MapVO; import club.joylink.rtss.vo.project.ProjectVO; import com.github.pagehelper.Page; diff --git a/src/main/java/club/joylink/rtss/services/project/DeviceServiceImpl.java b/src/main/java/club/joylink/rtss/services/project/DeviceServiceImpl.java index 00355cfd7..29342e577 100644 --- a/src/main/java/club/joylink/rtss/services/project/DeviceServiceImpl.java +++ b/src/main/java/club/joylink/rtss/services/project/DeviceServiceImpl.java @@ -278,7 +278,7 @@ public class DeviceServiceImpl implements DeviceService { private ProjectDevice getEntityById(long id) { return projectDeviceDAO.selectByPrimaryKey(id); } - + private void check(ProjectDevice entity, ProjectDeviceVO projectDeviceVO) { BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertEquals(entity.getProjectCode(), projectDeviceVO.getProject()); BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertEquals(entity.getCode(), projectDeviceVO.getCode()); 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 333a1ccab..4f136f7fd 100644 --- a/src/main/java/club/joylink/rtss/services/project/ProjectService.java +++ b/src/main/java/club/joylink/rtss/services/project/ProjectService.java @@ -1,12 +1,10 @@ package club.joylink.rtss.services.project; +import club.joylink.rtss.entity.Org; import club.joylink.rtss.entity.project.Project; import club.joylink.rtss.entity.project.ProjectView; import club.joylink.rtss.vo.client.PageVO; -import club.joylink.rtss.vo.project.ProjectQueryVO; -import club.joylink.rtss.vo.project.ProjectVO; -import club.joylink.rtss.vo.project.ProjectViewQueryVO; -import club.joylink.rtss.vo.project.ProjectViewVO; +import club.joylink.rtss.vo.project.*; import java.util.List; @@ -18,12 +16,12 @@ public interface ProjectService { /** * 分页 */ - PageVO pagingQuery(ProjectQueryVO queryVO); + PageVO pagingQuery(ProjectQueryVO queryVO); /** * 列表 */ - List getAllProject(); + List getAllProject(); /** * 项目Id请求项目信息 @@ -50,6 +48,16 @@ public interface ProjectService { */ boolean checkProjectCode(String code); + /** + * 设置项目默认组织 + */ + void setProjectDefaultOrg(Long id, Long orgId); + + /** + * 根据项目ID获取与项目关联的所有组织信息 + */ + List projectOrgList(Long id); + /** * 前端设置信息分页 */ 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 284742bc3..45b970557 100644 --- a/src/main/java/club/joylink/rtss/services/project/ProjectServiceImpl.java +++ b/src/main/java/club/joylink/rtss/services/project/ProjectServiceImpl.java @@ -1,7 +1,13 @@ package club.joylink.rtss.services.project; +import club.joylink.rtss.dao.OrgDAO; +import club.joylink.rtss.dao.org.OrgProjectDao; import club.joylink.rtss.dao.project.ProjectDAO; import club.joylink.rtss.dao.project.ProjectViewDAO; +import club.joylink.rtss.entity.Org; +import club.joylink.rtss.entity.OrgExample; +import club.joylink.rtss.entity.org.OrgProject; +import club.joylink.rtss.entity.org.OrgProjectExample; import club.joylink.rtss.entity.project.Project; import club.joylink.rtss.entity.project.ProjectExample; import club.joylink.rtss.entity.project.ProjectView; @@ -9,10 +15,7 @@ import club.joylink.rtss.entity.project.ProjectViewExample; import club.joylink.rtss.simulation.cbtc.exception.SimulationException; import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType; import club.joylink.rtss.vo.client.PageVO; -import club.joylink.rtss.vo.project.ProjectQueryVO; -import club.joylink.rtss.vo.project.ProjectVO; -import club.joylink.rtss.vo.project.ProjectViewQueryVO; -import club.joylink.rtss.vo.project.ProjectViewVO; +import club.joylink.rtss.vo.project.*; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import org.springframework.beans.factory.annotation.Autowired; @@ -24,7 +27,9 @@ import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import java.time.LocalDateTime; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; @Service @@ -40,8 +45,14 @@ public class ProjectServiceImpl implements ProjectService { @Autowired private ProjectViewDAO projectViewDAO; + @Autowired + private OrgProjectDao orgProjectDao; + + @Autowired + private OrgDAO orgDAO; + @Override - public PageVO pagingQuery(ProjectQueryVO queryVO) { + public PageVO pagingQuery(ProjectQueryVO queryVO) { PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize()); ProjectExample projectExample = new ProjectExample(); ProjectExample.Criteria criteria = projectExample.createCriteria().andStatusEqualTo(EFFECT_PROJECT_STATUS); @@ -52,14 +63,16 @@ public class ProjectServiceImpl implements ProjectService { criteria.andNameLike(queryVO.getName()); } Page page = (Page) projectDAO.selectWithBLOBsByExample(projectExample); - return PageVO.convert(page, page.getResult()); + List projectVOList = handleProjectOrgInfo(page.getResult()); + return PageVO.convert(page, projectVOList); } @Override - public List getAllProject() { + public List getAllProject() { ProjectExample projectExample = new ProjectExample(); projectExample.createCriteria().andStatusEqualTo(EFFECT_PROJECT_STATUS); - return projectDAO.selectByExample(projectExample); + List projectList = projectDAO.selectWithBLOBsByExample(projectExample); + return handleProjectOrgInfo(projectList); } @Override @@ -119,6 +132,74 @@ public class ProjectServiceImpl implements ProjectService { return num > 0; } + @Override + @CacheEvict(cacheNames = "project", allEntries = true) + public void setProjectDefaultOrg(Long id, Long orgId) { + Project project = new Project(); + project.setId(id); + project.setDefaultOrg(orgId); + projectDAO.updateByPrimaryKeySelective(project); + } + + @Override + public List projectOrgList(Long id) { + Project project = projectDAO.selectByPrimaryKey(id); + if (project == null) { + throw new SimulationException(SimulationExceptionType.Illegal_Argument, "项目不存在"); + } + List orgProjectList = getOrgProjectList(List.of(project.getCode())); + if (!CollectionUtils.isEmpty(orgProjectList)) { + List orgIdList = orgProjectList.stream().map(OrgProject::getOrgId).distinct().collect(Collectors.toList()); + return getOrgList(orgIdList); + } + 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(); + } + 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.setOrgName(orgNameList); + } + if (p.getDefaultOrg() != null && orgMap.containsKey(p.getDefaultOrg())) { + projectVO.setDefaultOrgName(orgMap.get(p.getDefaultOrg()).getName()); + } + return projectVO; + }).collect(Collectors.toList()); + return projectVOList; + } + @Override public PageVO projectViewPagingQuery(ProjectViewQueryVO queryVO) { PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize()); @@ -208,7 +289,7 @@ public class ProjectServiceImpl implements ProjectService { @Override public List getSimpleProjectList() { ProjectExample projectExample = new ProjectExample(); - projectExample.createCriteria().andStatusEqualTo(EFFECT_PROJECT_STATUS).andViewShowEqualTo(1); + projectExample.createCriteria().andStatusEqualTo(EFFECT_PROJECT_STATUS); List projectList = projectDAO.selectWithBLOBsByExample(projectExample); return projectList.stream().map(project -> new ProjectVO(project)).collect(Collectors.toList()); } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/Simulation.java b/src/main/java/club/joylink/rtss/simulation/cbtc/Simulation.java index c3c563980..6473cd351 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/Simulation.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/Simulation.java @@ -733,42 +733,70 @@ public class Simulation extends club.joylink.rtss.simulation.Simulation orgName; + + /** + * 默认组织ID + */ + private Long defaultOrg; + + /** + * 默认组织名称 + */ + private String defaultOrgName; + + public ProjectInfoVO(Project project) { + this.id = project.getId(); + this.code = project.getCode(); + this.name = project.getName(); + this.description = project.getDescription(); + this.serverSetting = project.getServerSetting(); + this.defaultOrg = project.getDefaultOrg(); + } +} diff --git a/src/main/resources/mybatis/mapper/ProjectDaoMapper.xml b/src/main/resources/mybatis/mapper/ProjectDaoMapper.xml index 3cb27738e..c53716c86 100644 --- a/src/main/resources/mybatis/mapper/ProjectDaoMapper.xml +++ b/src/main/resources/mybatis/mapper/ProjectDaoMapper.xml @@ -8,7 +8,7 @@ - + @@ -75,7 +75,7 @@ - id, code, name, create_time, update_time, status, view_show + id, code, name, create_time, update_time, status, default_org description,server_setting @@ -146,10 +146,10 @@ - insert into project ( code, name, description, create_time, update_time, status, server_setting,view_show) + insert into project ( code, name, description, create_time, update_time, status, server_setting,default_org) values (#{code,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{description,jdbcType=LONGVARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, #{status,jdbcType=INTEGER}, - #{serverSetting,jdbcType=LONGVARCHAR},#{viewShow,jdbcType=INTEGER}) + #{serverSetting,jdbcType=LONGVARCHAR}, #{defaultOrg, jdbcType=BIGINT}) @@ -179,8 +179,8 @@ server_setting, - - view_show, + + default_org, @@ -208,8 +208,8 @@ #{serverSetting,jdbcType=LONGVARCHAR}, - - #{viewShow,jdbcType=INTEGER}, + + #{defaultOrg, jdbcType=BIGINT}, @@ -238,8 +238,8 @@ server_setting = #{serverSetting,jdbcType=LONGVARCHAR}, - - view_show = #{viewShow,jdbcType=INTEGER}, + + default_org = #{defaultOrg, jdbcType=BIGINT}, where id = #{id,jdbcType=BIGINT} @@ -254,7 +254,7 @@ update_time = #{updateTime,jdbcType=TIMESTAMP}, status = #{status,jdbcType=INTEGER}, server_setting = #{serverSetting,jdbcType=LONGVARCHAR}, - view_show = #{viewShow,jdbcType=INTEGER} + default_org = #{defaultOrg, jdbcType=BIGINT} where id = #{id,jdbcType=BIGINT} @@ -266,7 +266,7 @@ create_time = #{createTime,jdbcType=TIMESTAMP}, update_time = #{updateTime,jdbcType=TIMESTAMP}, status = #{status,jdbcType=INTEGER}, - server_setting = #{serverSetting,jdbcType=LONGVARCHAR} + default_org = #{defaultOrg, jdbcType=BIGINT} where id = #{id,jdbcType=BIGINT} From 1973bf3f24411a21d571534de2892e7e35d23b29 Mon Sep 17 00:00:00 2001 From: weizhihong Date: Wed, 12 Oct 2022 14:24:02 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E3=80=90=E6=9F=A5=E8=AF=A2=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E5=85=B3=E8=81=94=E7=BB=84=E7=BB=87=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E8=BF=87=E6=BB=A4=E5=A4=9A=E4=BD=99=E5=AD=97=E6=AE=B5=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project/ProjectInfoController.java | 4 +- .../rtss/services/project/ProjectService.java | 4 +- .../services/project/ProjectServiceImpl.java | 6 +- .../joylink/rtss/vo/client/org/CompanyVO.java | 81 ++++++++++--------- 4 files changed, 53 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 da32cb4cb..2564d7260 100644 --- a/src/main/java/club/joylink/rtss/controller/project/ProjectInfoController.java +++ b/src/main/java/club/joylink/rtss/controller/project/ProjectInfoController.java @@ -1,10 +1,10 @@ package club.joylink.rtss.controller.project; -import club.joylink.rtss.entity.Org; 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.client.PageVO; +import club.joylink.rtss.vo.client.org.CompanyVO; import club.joylink.rtss.vo.project.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -62,7 +62,7 @@ public class ProjectInfoController { } @GetMapping("/{id}/orgList") - public List orgList(@PathVariable Long id) { + public List orgList(@PathVariable Long id) { return projectService.projectOrgList(id); } 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 4f136f7fd..5bb1671fb 100644 --- a/src/main/java/club/joylink/rtss/services/project/ProjectService.java +++ b/src/main/java/club/joylink/rtss/services/project/ProjectService.java @@ -1,9 +1,9 @@ package club.joylink.rtss.services.project; -import club.joylink.rtss.entity.Org; import club.joylink.rtss.entity.project.Project; import club.joylink.rtss.entity.project.ProjectView; import club.joylink.rtss.vo.client.PageVO; +import club.joylink.rtss.vo.client.org.CompanyVO; import club.joylink.rtss.vo.project.*; import java.util.List; @@ -56,7 +56,7 @@ public interface ProjectService { /** * 根据项目ID获取与项目关联的所有组织信息 */ - List projectOrgList(Long id); + List projectOrgList(Long id); /** * 前端设置信息分页 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 45b970557..ef545f40d 100644 --- a/src/main/java/club/joylink/rtss/services/project/ProjectServiceImpl.java +++ b/src/main/java/club/joylink/rtss/services/project/ProjectServiceImpl.java @@ -15,6 +15,7 @@ import club.joylink.rtss.entity.project.ProjectViewExample; import club.joylink.rtss.simulation.cbtc.exception.SimulationException; import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType; import club.joylink.rtss.vo.client.PageVO; +import club.joylink.rtss.vo.client.org.CompanyVO; import club.joylink.rtss.vo.project.*; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; @@ -142,7 +143,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, "项目不存在"); @@ -150,7 +151,8 @@ public class ProjectServiceImpl implements ProjectService { List orgProjectList = getOrgProjectList(List.of(project.getCode())); if (!CollectionUtils.isEmpty(orgProjectList)) { List orgIdList = orgProjectList.stream().map(OrgProject::getOrgId).distinct().collect(Collectors.toList()); - return getOrgList(orgIdList); + List orgList = getOrgList(orgIdList); + return orgList.stream().map(CompanyVO::simpleInfoVO).collect(Collectors.toList()); } return List.of(); } 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 index 47489f5b8..36f68af7d 100644 --- a/src/main/java/club/joylink/rtss/vo/client/org/CompanyVO.java +++ b/src/main/java/club/joylink/rtss/vo/client/org/CompanyVO.java @@ -20,47 +20,56 @@ import java.util.List; @NoArgsConstructor public class CompanyVO { - @JsonSerialize(using = ToStringSerializer.class) - private Long id; + @JsonSerialize(using = ToStringSerializer.class) + private Long id; - private String code; - /**公司名称*/ - @NotBlank(message = "公司名称不能为空") - private String name; + private String code; + /** + * 公司名称 + */ + @NotBlank(message = "公司名称不能为空") + private String name; - private List projectCodes; + 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 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 List convert2VOList(List dataList) { - List voList = new ArrayList<>(); - for (Org entity : dataList) { - voList.add(new CompanyVO(entity)); - } - return voList; - } + 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; - } + 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; - } - } + @JsonIgnore + public String getDBProjectCode() { + if (!CollectionUtils.isEmpty(projectCodes)) { + return String.join(",", projectCodes); + } else { + return null; + } + } } From 8c9c9eb0c054dac32b408e8a2660b775f884f99d Mon Sep 17 00:00:00 2001 From: weizhihong Date: Wed, 12 Oct 2022 15:49:26 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E3=80=90=E9=A1=B9=E7=9B=AE=E5=BF=AB?= =?UTF-8?q?=E6=8D=B7=E5=88=9B=E5=BB=BA=E7=BB=84=E7=BB=87=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=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); + } } From 3de220bc628b17db1db7955146500a1f703db8ef Mon Sep 17 00:00:00 2001 From: tiger_zhou <123456> Date: Wed, 12 Oct 2022 16:52:53 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E7=90=86=E8=AE=BA=E8=AF=95=E9=A2=98?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E4=BF=AE=E6=94=B9=E8=A1=A8=E6=98=8E=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E2=80=9Crts=5F=E2=80=9D=E5=89=8D=E7=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/202201010-zhouyin.sql | 2 +- sql/20220921-zhouyin.sql | 4 +-- .../rtss/dao/paper/PaperQuestionDAO.java | 2 +- .../mybatis/mapper/PaperQuestionDAO.xml | 28 +++++++++---------- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/sql/202201010-zhouyin.sql b/sql/202201010-zhouyin.sql index c5ffd9ba8..9eabbdf77 100644 --- a/sql/202201010-zhouyin.sql +++ b/sql/202201010-zhouyin.sql @@ -1,3 +1,3 @@ -- 新实训标添加组织id -alter table published_training2 add column org_id bigint; +alter table rts_published_training2 add column org_id bigint; diff --git a/sql/20220921-zhouyin.sql b/sql/20220921-zhouyin.sql index 7a938cfe3..e50200198 100644 --- a/sql/20220921-zhouyin.sql +++ b/sql/20220921-zhouyin.sql @@ -1,6 +1,6 @@ -- 新题库 -DROP TABLE IF EXISTS `paper_question`; -CREATE TABLE `paper_question` ( +DROP TABLE IF EXISTS `rts_paper_question`; +CREATE TABLE `rts_paper_question` ( `id` bigint NOT NULL AUTO_INCREMENT COMMENT 'id', `type` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '类型 选择题=select,判断题=judge,多选题=multi', `question` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT '问题内容', diff --git a/src/main/java/club/joylink/rtss/dao/paper/PaperQuestionDAO.java b/src/main/java/club/joylink/rtss/dao/paper/PaperQuestionDAO.java index af87d9172..696a4590f 100644 --- a/src/main/java/club/joylink/rtss/dao/paper/PaperQuestionDAO.java +++ b/src/main/java/club/joylink/rtss/dao/paper/PaperQuestionDAO.java @@ -15,7 +15,7 @@ import java.util.List; @Repository public interface PaperQuestionDAO { @Select("