From ceafebe073cc96781563fc2dd97c41611566a5ae Mon Sep 17 00:00:00 2001 From: song-cc-rock Date: Fri, 1 Mar 2024 16:01:56 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E7=BC=BA=E9=99=B7=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=BA=E9=99=B7=E6=93=8D=E4=BD=9C=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E7=9A=84=E9=80=9A=E7=9F=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1036449 --user=宋昌昌 【项目管理】消息通知-批量编辑缺陷-未发送通知 https://www.tapd.cn/55049933/s/1467801 --- .../bug/controller/BugController.java | 4 +- .../bug/service/BugLogService.java | 2 +- .../bug/service/BugNoticeService.java | 85 ++++++++-------- .../metersphere/bug/service/BugService.java | 24 ++--- frontend/src/views/bug-management/index.vue | 96 ++++++++----------- 5 files changed, 94 insertions(+), 117 deletions(-) diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/controller/BugController.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/controller/BugController.java index 475eb2d7a0..ca2ee24c17 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/controller/BugController.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/controller/BugController.java @@ -125,8 +125,8 @@ public class BugController { @GetMapping("/delete/{id}") @Operation(summary = "缺陷管理-列表-删除缺陷") @RequiresPermissions(PermissionConstants.PROJECT_BUG_DELETE) - @Log(type = OperationLogType.DELETE, expression = "#msClass.deleteLog(#id)", msClass = BugLogService.class) @SendNotice(taskType = NoticeConstants.TaskType.BUG_TASK, event = NoticeConstants.Event.DELETE, target = "#targetClass.getNoticeById(#id)", targetClass = BugNoticeService.class) + @Log(type = OperationLogType.DELETE, expression = "#msClass.deleteLog(#id)", msClass = BugLogService.class) public void delete(@PathVariable String id) { bugService.delete(id, SessionUtils.getUserId()); } @@ -176,6 +176,7 @@ public class BugController { @Operation(summary = "缺陷管理-列表-批量删除缺陷") @RequiresPermissions(PermissionConstants.PROJECT_BUG_DELETE) @CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project") + @SendNotice(taskType = NoticeConstants.TaskType.BUG_TASK, event = NoticeConstants.Event.DELETE, target = "#targetClass.getBatchNoticeByRequest(#request)", targetClass = BugNoticeService.class) public void batchDelete(@Validated @RequestBody BugBatchRequest request) { request.setUseTrash(false); bugService.batchDelete(request, SessionUtils.getUserId()); @@ -185,6 +186,7 @@ public class BugController { @Operation(summary = "缺陷管理-列表-批量编辑缺陷") @RequiresPermissions(PermissionConstants.PROJECT_BUG_UPDATE) @CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project") + @SendNotice(taskType = NoticeConstants.TaskType.BUG_TASK, event = NoticeConstants.Event.UPDATE, target = "#targetClass.getBatchNoticeByRequest(#request)", targetClass = BugNoticeService.class) public void batchUpdate(@Validated @RequestBody BugBatchUpdateRequest request) { request.setUseTrash(false); bugService.batchUpdate(request, SessionUtils.getUserId()); diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugLogService.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugLogService.java index ecb15f0c93..ebeeae63a8 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugLogService.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugLogService.java @@ -106,7 +106,7 @@ public class BugLogService { * @param id 缺陷ID * @return 缺陷DTO */ - private BugDTO getOriginalValue(String id) { + public BugDTO getOriginalValue(String id) { // 缺陷基础信息 BugDTO originalBug = new BugDTO(); Bug bug = bugMapper.selectByPrimaryKey(id); diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugNoticeService.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugNoticeService.java index 4c18927c5f..1123c977e6 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugNoticeService.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugNoticeService.java @@ -1,27 +1,19 @@ package io.metersphere.bug.service; -import io.metersphere.bug.domain.Bug; +import io.metersphere.bug.dto.request.BugBatchRequest; import io.metersphere.bug.dto.request.BugEditRequest; -import io.metersphere.bug.dto.response.BugCustomFieldDTO; -import io.metersphere.bug.mapper.ExtBugCustomFieldMapper; +import io.metersphere.bug.dto.response.BugDTO; import io.metersphere.plugin.platform.dto.SelectOption; -import io.metersphere.system.domain.User; +import io.metersphere.sdk.util.BeanUtils; import io.metersphere.system.dto.BugNoticeDTO; import io.metersphere.system.dto.sdk.OptionDTO; -import io.metersphere.system.mapper.UserMapper; -import io.metersphere.system.notice.NoticeModel; -import io.metersphere.system.notice.constants.NoticeConstants; -import io.metersphere.system.notice.utils.MessageTemplateUtils; -import io.metersphere.system.service.NoticeSendService; import jakarta.annotation.Resource; -import org.apache.commons.beanutils.BeanMap; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -35,15 +27,13 @@ public class BugNoticeService { public static final String CUSTOM_HANDLE_USER = "处理人"; @Resource - private UserMapper userMapper; + private BugService bugService; + @Resource + private BugLogService bugLogService; @Resource private BugCommonService bugCommonService; @Resource private BugStatusService bugStatusService; - @Resource - private NoticeSendService noticeSendService; - @Resource - private ExtBugCustomFieldMapper extBugCustomFieldMapper; /** * 获取缺陷通知 @@ -84,43 +74,46 @@ public class BugNoticeService { } /** - * 发送删除缺陷通知 - * @param bug 缺陷 - * @param currentUser 当前用户 + * 获取缺陷通知 + * @param id 缺陷ID */ - public void sendDeleteNotice(Bug bug, String currentUser) { - Map statusMap = getStatusMap(bug.getProjectId()); - Map handlerMap = getHandleMap(bug.getProjectId()); - // 缺陷相关内容 + public BugNoticeDTO getNoticeById(String id) { + // 缺陷基础信息 + BugDTO bugDTO = bugLogService.getOriginalValue(id); + // 构建通知对象 BugNoticeDTO notice = new BugNoticeDTO(); - notice.setTitle(bug.getTitle()); - notice.setStatus(statusMap.get(bug.getStatus())); - notice.setHandleUser(handlerMap.get(bug.getHandleUser())); - List customFields = extBugCustomFieldMapper.getBugAllCustomFields(List.of(bug.getId()), bug.getProjectId()); - List fields = customFields.stream().map(field -> { - OptionDTO fieldDTO = new OptionDTO(); - fieldDTO.setId(field.getName()); - fieldDTO.setName(field.getValue()); - return fieldDTO; - }).toList(); - notice.setCustomFields(fields); - BeanMap beanMap = new BeanMap(notice); - User user = userMapper.selectByPrimaryKey(currentUser); - Map paramMap = new HashMap<>(beanMap); - paramMap.put(NoticeConstants.RelatedUser.OPERATOR, user.getName()); - Map defaultTemplateMap = MessageTemplateUtils.getDefaultTemplateMap(); - String template = defaultTemplateMap.get(NoticeConstants.TemplateText.BUG_TASK_DELETE); - Map defaultSubjectMap = MessageTemplateUtils.getDefaultTemplateSubjectMap(); - String subject = defaultSubjectMap.get(NoticeConstants.TemplateText.BUG_TASK_DELETE); - NoticeModel noticeModel = NoticeModel.builder().operator(currentUser) - .context(template).subject(subject).paramMap(paramMap).event(NoticeConstants.Event.DELETE).build(); - noticeSendService.send(NoticeConstants.TaskType.BUG_TASK, noticeModel); + BeanUtils.copyBean(notice, bugDTO); + // 自定义字段解析{name: value} + if (CollectionUtils.isNotEmpty(bugDTO.getCustomFields())) { + List fields = new ArrayList<>(); + bugDTO.getCustomFields().forEach(field -> { + // 其他自定义字段 + OptionDTO fieldDTO = new OptionDTO(); + fieldDTO.setId(field.getName()); + fieldDTO.setName(field.getValue()); + fields.add(fieldDTO); + }); + notice.setCustomFields(fields); + } + return notice; + } + + /** + * 获取批量操作的缺陷通知 + * @param request 批量请求参数 + * @return 缺陷通知集合 + */ + public List getBatchNoticeByRequest(BugBatchRequest request) { + List notices = new ArrayList<>(); + List batchIds = bugService.getBatchIdsByRequest(request); + batchIds.forEach(id -> notices.add(getNoticeById(id))); + return notices; } /** * 获取状态集合 * @param projectId 项目ID - * @return + * @return 状态集合 */ private Map getStatusMap(String projectId) { List statusOption = bugStatusService.getHeaderStatusOption(projectId); diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugService.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugService.java index 86034567f6..95201488c4 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugService.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugService.java @@ -91,8 +91,6 @@ import static io.metersphere.bug.enums.result.BugResultCode.NOT_LOCAL_BUG_ERROR; @Transactional(rollbackFor = Exception.class) public class BugService { - private static int MAX_TAG_SIZE = 10; - @Resource private BugMapper bugMapper; @Resource @@ -118,8 +116,6 @@ public class BugService { @Resource private BaseTemplateCustomFieldService baseTemplateCustomFieldService; @Resource - private BugNoticeService bugNoticeService; - @Resource private BugCommonService bugCommonService; @Resource private BugCustomFieldMapper bugCustomFieldMapper; @@ -162,6 +158,8 @@ public class BugService { public static final Long INTERVAL_POS = 5000L; + private static final int MAX_TAG_SIZE = 10; + /** * 缺陷列表查询 * @@ -178,12 +176,6 @@ public class BugService { return buildExtraInfo(bugList); } - private void checkTagLength(List tags) { - if (CollectionUtils.isNotEmpty(tags) && tags.size() > MAX_TAG_SIZE) { - throw new MSException(Translator.getWithArgs("bug_tags_size_large_than", String.valueOf(MAX_TAG_SIZE))); - } - } - /** * 创建或编辑缺陷 * @@ -332,8 +324,6 @@ public class BugService { clearAssociate(id, bug.getProjectId()); bugMapper.deleteByPrimaryKey(id); } - // 发送通知 - bugNoticeService.sendDeleteNotice(bug, currentUser); } /** @@ -1511,4 +1501,14 @@ public class BugService { Set keySet = ConcurrentHashMap.newKeySet(); return t -> keySet.add(function.apply(t)); } + + /** + * 校验TAG长度 + * @param tags 标签集合 + */ + private void checkTagLength(List tags) { + if (CollectionUtils.isNotEmpty(tags) && tags.size() > MAX_TAG_SIZE) { + throw new MSException(Translator.getWithArgs("bug_tags_size_large_than", String.valueOf(MAX_TAG_SIZE))); + } + } } \ No newline at end of file diff --git a/frontend/src/views/bug-management/index.vue b/frontend/src/views/bug-management/index.vue index 36aa0c6621..3bcd672f1d 100644 --- a/frontend/src/views/bug-management/index.vue +++ b/frontend/src/views/bug-management/index.vue @@ -123,53 +123,48 @@