From f8052dc622a8f95f45f47f62e80c08ba1b824408 Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Wed, 23 Oct 2024 19:35:37 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E7=94=A8=E4=BE=8B=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=84=91=E5=9B=BE=E5=88=A0=E9=99=A4=E7=94=A8?= =?UTF-8?q?=E4=BE=8B=E6=97=A5=E5=BF=97=E6=9C=AA=E6=88=90=E5=8A=9F=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/FunctionalMinderUpdateDTO.java | 6 ++- .../service/FunctionalCaseMinderService.java | 39 ++++++++++++++++--- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/dto/FunctionalMinderUpdateDTO.java b/backend/services/case-management/src/main/java/io/metersphere/functional/dto/FunctionalMinderUpdateDTO.java index 03f28317bb..be3e92d610 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/dto/FunctionalMinderUpdateDTO.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/dto/FunctionalMinderUpdateDTO.java @@ -18,6 +18,9 @@ public class FunctionalMinderUpdateDTO implements Serializable { @Schema(description = "新增日志") private List addLogDTOS; + @Schema(description = "删除日志") + private List deleteLogDTOS; + @Schema(description = "更新日志") private List updateLogDTOS; @@ -30,8 +33,9 @@ public class FunctionalMinderUpdateDTO implements Serializable { @Schema(description = "资源Id与相邻点的Map") private Map sourceIdAndTargetIdsMap; - public FunctionalMinderUpdateDTO(List addLogDTOS, List updateLogDTOS, List noticeList, List updateNoticeList) { + public FunctionalMinderUpdateDTO(List addLogDTOS,List deleteLogDTOS, List updateLogDTOS, List noticeList, List updateNoticeList) { this.addLogDTOS = addLogDTOS; + this.deleteLogDTOS = deleteLogDTOS; this.updateLogDTOS = updateLogDTOS; this.noticeList = noticeList; this.updateNoticeList = updateNoticeList; diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseMinderService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseMinderService.java index aad1bb8d14..a5e9babbcd 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseMinderService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseMinderService.java @@ -289,17 +289,19 @@ public class FunctionalCaseMinderService { public void editFunctionalCaseBatch(FunctionalCaseMinderEditRequest request, String userId) { //处理删除的模块和用例和空白节点 User user = userMapper.selectByPrimaryKey(userId); - deleteResource(request, user); + FunctionalMinderUpdateDTO functionalMinderUpdateDTO = new FunctionalMinderUpdateDTO(new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>()); + deleteResource(request, user, functionalMinderUpdateDTO); SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); FunctionalCaseModuleMapper moduleMapper = sqlSession.getMapper(FunctionalCaseModuleMapper.class); MindAdditionalNodeMapper additionalNodeMapper = sqlSession.getMapper(MindAdditionalNodeMapper.class); - FunctionalMinderUpdateDTO functionalMinderUpdateDTO = new FunctionalMinderUpdateDTO(new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>()); //处理模块 Map sourceIdAndInsertModuleIdMap = dealModule(request, userId, moduleMapper, functionalMinderUpdateDTO); List needToTurnModuleIds = sourceIdAndInsertModuleIdMap.keySet().stream().distinct().toList(); //删除用例 if (CollectionUtils.isNotEmpty(needToTurnModuleIds)) { + List logDTOS = deleteLog(needToTurnModuleIds, userId); + functionalMinderUpdateDTO.getDeleteLogDTOS().addAll(logDTOS); functionalCaseTrashService.deleteByIds(request.getProjectId(), needToTurnModuleIds, userId); functionalCaseNoticeService.batchSendNotice(request.getProjectId(), needToTurnModuleIds, user, NoticeConstants.Event.DELETE); } @@ -514,6 +516,29 @@ public class FunctionalCaseMinderService { dealLogAndNotice(request, userId, functionalMinderUpdateDTO); } + private List deleteLog(List needToTurnModuleIds, String userId) { + List dtoList = new ArrayList<>(); + if (CollectionUtils.isNotEmpty(needToTurnModuleIds)) { + List functionalCases = extFunctionalCaseMapper.getLogInfo(needToTurnModuleIds, false); + functionalCases.forEach(functionalCase -> { + LogDTO dto = new LogDTO( + functionalCase.getProjectId(), + null, + functionalCase.getId(), + userId, + OperationLogType.DELETE.name(), + OperationLogModule.FUNCTIONAL_CASE, + functionalCase.getName()); + + dto.setPath("/functional/mind/case/edit"); + dto.setMethod(HttpMethodConstants.POST.name()); + dto.setOriginalValue(JSON.toJSONBytes(functionalCase)); + dtoList.add(dto); + }); + } + return dtoList; + } + /** * @param moveMode 移动方式 前后 * @param targetId 要移动到的目标元素标识 @@ -599,8 +624,12 @@ public class FunctionalCaseMinderService { for (LogDTO updateLogDTO : functionalMinderUpdateDTO.getUpdateLogDTOS()) { updateLogDTO.setOrganizationId(project.getOrganizationId()); } + for (LogDTO updateLogDTO : functionalMinderUpdateDTO.getDeleteLogDTOS()) { + updateLogDTO.setOrganizationId(project.getOrganizationId()); + } operationLogService.batchAdd(functionalMinderUpdateDTO.getAddLogDTOS()); operationLogService.batchAdd(functionalMinderUpdateDTO.getUpdateLogDTOS()); + operationLogService.batchAdd(functionalMinderUpdateDTO.getDeleteLogDTOS()); User user = userMapper.selectByPrimaryKey(userId); List resources = new ArrayList<>(); resources.addAll(JSON.parseArray(JSON.toJSONString(functionalMinderUpdateDTO.getNoticeList()), Map.class)); @@ -1188,16 +1217,16 @@ public class FunctionalCaseMinderService { return functionalCase; } - private void deleteResource(FunctionalCaseMinderEditRequest request, User user) { + private void deleteResource(FunctionalCaseMinderEditRequest request, User user, FunctionalMinderUpdateDTO functionalMinderUpdateDTO) { if (CollectionUtils.isNotEmpty(request.getDeleteResourceList())) { Map> resourceMap = request.getDeleteResourceList().stream().collect(Collectors.groupingBy(MinderOptionDTO::getType)); List caseOptionDTOS = resourceMap.get(Translator.get("minder_extra_node.case")); List caseIds = new ArrayList<>(); if (CollectionUtils.isNotEmpty(caseOptionDTOS)) { caseIds = caseOptionDTOS.stream().map(MinderOptionDTO::getId).toList(); + List logDTOS = deleteLog(caseIds, user.getId()); + functionalMinderUpdateDTO.getDeleteLogDTOS().addAll(logDTOS); functionalCaseService.handDeleteFunctionalCase(caseIds, false, user.getId(), request.getProjectId()); - functionalCaseLogService.batchDeleteFunctionalCaseLogByIds(caseIds, "/functional/mind/case/edit"); - } List caseModuleOptionDTOS = resourceMap.get(Translator.get("minder_extra_node.module")); if (CollectionUtils.isNotEmpty(caseModuleOptionDTOS)) {