From 8bc7057b49e111ec5b65c19fd4bb71bbba0b4574 Mon Sep 17 00:00:00 2001 From: WendyYang Date: Fri, 6 Dec 2024 16:07:19 +0800 Subject: [PATCH] =?UTF-8?q?feat:=201.=20=E4=BC=9A=E8=AE=AE=E5=85=B3?= =?UTF-8?q?=E8=81=94=E3=80=81=E7=A7=BB=E9=99=A4=E9=A1=B9=E7=9B=AE=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=90=88=E5=B9=B6=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/meeting/controller/MeetingController.java | 7 -- .../entity/req/MeetingAppendProjectReq.java | 2 - .../hz/pm/api/meeting/manage/MeetingManage.java | 110 ++++++++++----------- 3 files changed, 54 insertions(+), 65 deletions(-) diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/meeting/controller/MeetingController.java b/hz-pm-api/src/main/java/com/hz/pm/api/meeting/controller/MeetingController.java index 7ecab86..25b5e37 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/meeting/controller/MeetingController.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/meeting/controller/MeetingController.java @@ -199,13 +199,6 @@ public class MeetingController { meetingManage.appendProject(req); } - @PostMapping("/project/remove") - @WebLog("移除项目") - @ApiOperation("移除项目") - public void removeProject(@RequestBody @Valid MeetingAppendProjectReq req) { - meetingManage.removeProject(req); - } - @GetMapping("/{meetingId}/projects") @ApiOperation("会议关联项目列表") public List projectsByMeetingId(@PathVariable Long meetingId) { diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/meeting/entity/req/MeetingAppendProjectReq.java b/hz-pm-api/src/main/java/com/hz/pm/api/meeting/entity/req/MeetingAppendProjectReq.java index 4a9c4f1..58c4187 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/meeting/entity/req/MeetingAppendProjectReq.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/meeting/entity/req/MeetingAppendProjectReq.java @@ -3,7 +3,6 @@ package com.hz.pm.api.meeting.entity.req; import io.swagger.annotations.ApiModelProperty; import lombok.Data; -import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; import java.util.List; @@ -22,7 +21,6 @@ public class MeetingAppendProjectReq { @ApiModelProperty("会议ID") private Long meetingId; - @NotEmpty(message = "项目ID列表不能为空") @ApiModelProperty("项目ID列表") private List projectIds; diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/meeting/manage/MeetingManage.java b/hz-pm-api/src/main/java/com/hz/pm/api/meeting/manage/MeetingManage.java index 873c826..6d0804d 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/meeting/manage/MeetingManage.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/meeting/manage/MeetingManage.java @@ -31,7 +31,10 @@ import com.hz.pm.api.meeting.builder.MeetingReviewProjectBuilder; import com.hz.pm.api.meeting.builder.ProjectReviewResultBuilder; import com.hz.pm.api.meeting.entity.domain.*; import com.hz.pm.api.meeting.entity.dto.*; -import com.hz.pm.api.meeting.entity.enumeration.*; +import com.hz.pm.api.meeting.entity.enumeration.ExpertAttendStatusEnum; +import com.hz.pm.api.meeting.entity.enumeration.ExpertInviteTypeEnum; +import com.hz.pm.api.meeting.entity.enumeration.MeetingReviewTypeEnum; +import com.hz.pm.api.meeting.entity.enumeration.MeetingStatusEnum; import com.hz.pm.api.meeting.entity.req.*; import com.hz.pm.api.meeting.entity.vo.*; import com.hz.pm.api.meeting.helper.ExpertInviteHelper; @@ -1013,71 +1016,66 @@ public class MeetingManage { Meeting meeting = meetingService.getById(req.getMeetingId()); Assert.notNull(meeting, "会议不存在"); Assert.isTrue(MeetingStatusEnum.NORMAL.eq(meeting.getStatus()), "当前会议无法添加项目"); - List projectCodes = CollUtils.convert(req.getProjectIds(), ProjectIdCodeCacheUtil::get); + List projectCodes; + if (CollUtil.isNotEmpty(req.getProjectIds())) { + projectCodes = CollUtils.convert(req.getProjectIds(), ProjectIdCodeCacheUtil::get); + } else { + projectCodes = Collections.emptyList(); + } Wrapper query = Wrappers.lambdaQuery(MeetingInnerProject.class) .select(MeetingInnerProject::getMeetingId, MeetingInnerProject::getProjectCode, MeetingInnerProject::getId, MeetingInnerProject::getReviewResult) - .in(MeetingInnerProject::getProjectCode, projectCodes); - Collection linkedProjList = BizUtils.groupFirst(meetingInnerProjectService.list(query), - MeetingInnerProject::getProjectCode, Comparator.comparing(MeetingInnerProject::getId).reversed()); - // 移除已关联当前会议的项目 - projectCodes.removeIf(w -> CollUtil.anyMatch(linkedProjList, - x -> x.getProjectCode().equals(w) && x.getMeetingId().equals(meeting.getId()))); - if (projectCodes.isEmpty()) { + .eq(MeetingInnerProject::getMeetingId, meeting.getId()); + List linkedProjList = meetingInnerProjectService.list(query); + if (linkedProjList.isEmpty() && projectCodes.isEmpty()) { return; } - linkedProjList.removeIf(w -> w.getMeetingId().equals(meeting.getId())); - if (CollUtil.isNotEmpty(linkedProjList)) { - Set linkedMeetingIds = CollUtils.fieldSet(linkedProjList, MeetingInnerProject::getMeetingId); - if (!linkedMeetingIds.isEmpty()) { - List meetings = meetingService.listByIds(linkedMeetingIds); - Map meetingMap = CollUtils.listToMap(meetings, Meeting::getId); - if (CollUtil.anyMatch(linkedProjList, w -> { - Meeting linkedMeeting = meetingMap.get(w.getMeetingId()); - return MeetingStatusEnum.NORMAL.eq(linkedMeeting.getStatus()) - && ExpertReviewResultEnum.PASS.eq(w.getReviewResult()); - })) { - throw ReturnException.wrap("所选项目包含已评审通过的项目"); + List deletedProjectCodes = linkedProjList.stream().filter(w -> { + boolean deleted = !projectCodes.remove(w.getProjectCode()); + if (deleted && w.getReviewResult() != null) { + throw ReturnException.wrap("已上传评审结果的项目不可移除"); + } + return deleted; + }).map(MeetingInnerProject::getProjectCode).collect(Collectors.toList()); + + List changeProjectCodes = new ArrayList<>(); + changeProjectCodes.addAll(projectCodes); + changeProjectCodes.addAll(deletedProjectCodes); + List projects = projectService.listNewestByProjectCodes(changeProjectCodes); + // 校验项目状态 + for (Project project : projects) { + if (deletedProjectCodes.contains(project.getProjectCode())) { + if (!ProjectStatus.ON_EXPERT_REVIEW.eq(project.getStatus())) { + throw ReturnException.wrap("仅专家评审中的项目可以移除"); + } + } else { + if (!ProjectStatus.WITHOUT_EXPERT_REVIEW.eq(project.getStatus())) { + throw ReturnException.wrap("仅待专家评审的项目可以关联"); } } } - List projects = projectService.listNewestByProjectCodes(projectCodes); - if (CollUtil.anyMatch(projects, w -> !ProjectStatus.WITHOUT_EXPERT_REVIEW.eq(w.getStatus()))) { - throw ReturnException.wrap("所选项目必须为待专家评审状态"); - } - List mips = CollUtils.convert(projects, w -> { - projectStateMachineUtil.pass(w); - MeetingInnerProject mip = new MeetingInnerProject(); - mip.setProjectId(w.getId()); - mip.setMeetingId(req.getMeetingId()); - mip.setProjectCode(w.getProjectCode()); - return mip; - }); - projectService.updateBatchById(projects); - meetingInnerProjectService.saveBatch(mips); - } - - @Transactional(rollbackFor = Exception.class) - public synchronized void removeProject(MeetingAppendProjectReq req) { - Meeting meeting = meetingService.getById(req.getMeetingId()); - Assert.notNull(meeting, "会议不存在"); - Assert.isTrue(MeetingStatusEnum.NORMAL.eq(meeting.getStatus()), "当前会议无法移除项目"); - List projectCodes = CollUtils.convert(req.getProjectIds(), ProjectIdCodeCacheUtil::get); - Wrapper query = Wrappers.lambdaQuery(MeetingInnerProject.class) - .select(MeetingInnerProject::getId, MeetingInnerProject::getProjectCode, MeetingInnerProject::getReviewResult) - .in(MeetingInnerProject::getProjectCode, projectCodes) - .eq(MeetingInnerProject::getMeetingId, meeting.getId()); - List linkedProjList = meetingInnerProjectService.list(query); - if (projectCodes.size() != linkedProjList.size()) { - throw ReturnException.wrap("所选项目与当前会议未关联"); + Map> changeProjectMap = CollUtils.group(projects, + w -> projectCodes.contains(w.getProjectCode())); + List newLinkedProjList = changeProjectMap.get(Boolean.TRUE); + if (CollUtil.isNotEmpty(newLinkedProjList)) { + List mips = CollUtils.convert(projects, w -> { + projectStateMachineUtil.pass(w); + MeetingInnerProject mip = new MeetingInnerProject(); + mip.setProjectId(w.getId()); + mip.setMeetingId(req.getMeetingId()); + mip.setProjectCode(w.getProjectCode()); + return mip; + }); + meetingInnerProjectService.saveBatch(mips); } - if (CollUtil.anyMatch(linkedProjList, w -> w.getReviewResult() != null)) { - throw ReturnException.wrap("已上传评审结果的项目不能移除"); + // + List delLinkedProjList = changeProjectMap.get(Boolean.FALSE); + if (CollUtil.isNotEmpty(delLinkedProjList)) { + meetingInnerProjectService.remove(Wrappers.lambdaQuery(MeetingInnerProject.class) + .in(MeetingInnerProject::getProjectCode, deletedProjectCodes) + .eq(MeetingInnerProject::getMeetingId, meeting.getId())); + delLinkedProjList.forEach(projectStateMachineUtil::withDraw); } - Set mipIds = CollUtils.fieldSet(linkedProjList, MeetingInnerProject::getId); - meetingInnerProjectService.removeByIds(mipIds); - List projects = projectService.listNewestByProjectCodes(projectCodes); - projects.forEach(projectStateMachineUtil::withDraw); projectService.updateBatchById(projects); }