From b1c1c2ad9823a40dca47bcef420247a02201bf86 Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Mon, 4 Mar 2024 18:10:13 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B6=88=E6=81=AF=E4=B8=AD=E5=BF=83):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B6=88=E6=81=AF=E4=B8=AD=E5=BF=83=E8=81=94?= =?UTF-8?q?=E8=B0=83=E6=97=B6=E5=8F=91=E7=8E=B0=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/NotificationController.java | 5 +-- .../dto/sdk/request/NotificationRequest.java | 2 +- .../system/log/dto/NotificationDTO.java | 15 +++++++ .../system/mapper/BaseNotificationMapper.java | 4 +- .../system/mapper/BaseNotificationMapper.xml | 21 +++++---- .../system/service/NotificationService.java | 45 +++++++++---------- .../NotificationControllerTests.java | 5 ++- 7 files changed, 57 insertions(+), 40 deletions(-) create mode 100644 backend/services/system-setting/src/main/java/io/metersphere/system/log/dto/NotificationDTO.java diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/NotificationController.java b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/NotificationController.java index d9bd4329ad..9a6d2e7acd 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/NotificationController.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/NotificationController.java @@ -3,10 +3,9 @@ package io.metersphere.system.controller; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; - -import io.metersphere.project.domain.Notification; import io.metersphere.system.dto.sdk.OptionDTO; import io.metersphere.system.dto.sdk.request.NotificationRequest; +import io.metersphere.system.log.dto.NotificationDTO; import io.metersphere.system.service.NotificationService; import io.metersphere.system.utils.PageUtils; import io.metersphere.system.utils.Pager; @@ -29,7 +28,7 @@ public class NotificationController { @PostMapping(value = "/list/all/page") @Operation(summary = "消息中心-获取消息中心所有消息列表") - public Pager> listNotification(@Validated @RequestBody NotificationRequest notificationRequest) { + public Pager> listNotification(@Validated @RequestBody NotificationRequest notificationRequest) { Page page = PageHelper.startPage(notificationRequest.getCurrent(), notificationRequest.getPageSize(), true); return PageUtils.setPageInfo(page, notificationService.listNotification(notificationRequest, SessionUtils.getUserId())); } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/sdk/request/NotificationRequest.java b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/sdk/request/NotificationRequest.java index 286b541347..4d92b6cef9 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/sdk/request/NotificationRequest.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/sdk/request/NotificationRequest.java @@ -22,7 +22,7 @@ public class NotificationRequest extends BasePageRequest { @Schema(description = "状态") private String status; - @Schema(description = "资源类型: TEST_PLAN/BUG/CASE/API/UI/LOAD/JENKINS") + @Schema(description = "资源类型: TEST_PLAN/BUG/CASE/API/UI/LOAD/JENKINS/SCHEDULE") private String resourceType; @Schema(description = "创建时间") diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/log/dto/NotificationDTO.java b/backend/services/system-setting/src/main/java/io/metersphere/system/log/dto/NotificationDTO.java new file mode 100644 index 0000000000..0cbe07a820 --- /dev/null +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/log/dto/NotificationDTO.java @@ -0,0 +1,15 @@ +package io.metersphere.system.log.dto; + +import io.metersphere.project.domain.Notification; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Data +public class NotificationDTO extends Notification { + + @Schema(description = "头像") + private String avatar; + + @Schema(description = "用户名") + private String userName; +} diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/BaseNotificationMapper.java b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/BaseNotificationMapper.java index 00b598fbe7..add41158e2 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/BaseNotificationMapper.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/BaseNotificationMapper.java @@ -1,14 +1,14 @@ package io.metersphere.system.mapper; -import io.metersphere.project.domain.Notification; import io.metersphere.system.dto.sdk.request.NotificationRequest; +import io.metersphere.system.log.dto.NotificationDTO; import org.apache.ibatis.annotations.Param; import java.util.List; public interface BaseNotificationMapper { - List listNotification(@Param("request") NotificationRequest notificationRequest); + List listNotification(@Param("request") NotificationRequest notificationRequest); } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/BaseNotificationMapper.xml b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/BaseNotificationMapper.xml index 0709ef811e..fd94c2a8e2 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/BaseNotificationMapper.xml +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/BaseNotificationMapper.xml @@ -2,22 +2,25 @@ - + SELECT *, u.name as userName, + ux.avatar as userLogo FROM notification + left join user u on notification.operator = u.id + left join user_extend ux on notification.operator = ux.id + WHERE notification.receiver = #{request.receiver} AND notification.create_time > (unix_timestamp() - 90 * 24 * 3600) * 1000 - AND ( title LIKE #{request.title} OR content LIKE #{request.title} ) + AND ( notification.title LIKE #{request.title} OR notification.content LIKE #{request.title} ) - AND type = #{request.type} + AND notification.type = #{request.type} - AND status = #{request.status} + AND notification.status = #{request.status} - - AND resource_type LIKE #{request.resourceType} + + AND notification.resource_type LIKE #{request.resourceType} - ORDER BY create_time DESC + ORDER BY notification.create_time DESC \ No newline at end of file diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/NotificationService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/NotificationService.java index aafd09cd42..c1bbb4cfe9 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/NotificationService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/NotificationService.java @@ -1,12 +1,12 @@ package io.metersphere.system.service; - import io.metersphere.project.domain.Notification; import io.metersphere.project.domain.NotificationExample; import io.metersphere.project.mapper.NotificationMapper; import io.metersphere.system.dto.sdk.OptionDTO; import io.metersphere.system.dto.sdk.request.NotificationRequest; +import io.metersphere.system.log.dto.NotificationDTO; import io.metersphere.system.mapper.BaseNotificationMapper; import io.metersphere.system.notice.constants.NotificationConstants; import jakarta.annotation.Resource; @@ -29,10 +29,8 @@ public class NotificationService { @Resource private BaseNotificationMapper baseNotificationMapper; - public List listNotification(NotificationRequest notificationRequest, String userId) { - if (StringUtils.isBlank(notificationRequest.getReceiver())) { - notificationRequest.setReceiver(userId); - } + public List listNotification(NotificationRequest notificationRequest, String userId) { + buildParam(notificationRequest, userId); return baseNotificationMapper.listNotification(notificationRequest); } @@ -54,10 +52,8 @@ public class NotificationService { public List countNotification(NotificationRequest notificationRequest, String userId) { ListoptionDTOS = new ArrayList<>(); - if (StringUtils.isBlank(notificationRequest.getReceiver())) { - notificationRequest.setReceiver(userId); - } - List notifications = baseNotificationMapper.listNotification(notificationRequest); + buildParam(notificationRequest, userId); + List notifications = baseNotificationMapper.listNotification(notificationRequest); OptionDTO totalOptionDTO = new OptionDTO(); totalOptionDTO.setId("total"); totalOptionDTO.setName(String.valueOf(notifications.size())); @@ -66,13 +62,22 @@ public class NotificationService { return optionDTOS; } - private static void buildSourceCount(List notifications, List optionDTOS) { + private static void buildParam(NotificationRequest notificationRequest, String userId) { + if (StringUtils.isNotBlank(notificationRequest.getTitle())) { + notificationRequest.setTitle("%" + notificationRequest.getTitle() + "%"); + } + if (StringUtils.isNotBlank(notificationRequest.getResourceType())) { + notificationRequest.setResourceType("%" + notificationRequest.getResourceType() + "%"); + } + if (StringUtils.isBlank(notificationRequest.getReceiver())) { + notificationRequest.setReceiver(userId); + } + } + + private static void buildSourceCount(List notifications, List optionDTOS) { MapcountMap = new HashMap<>(); Map> resourceMap = notifications.stream().collect(Collectors.groupingBy(Notification::getResourceType)); resourceMap.forEach((k,v)->{ - if (k.contains("TEST_PLAN")) { - countMap.merge("TEST_PLAN", v.size(), Integer::sum); - } if (k.contains("BUG")) { countMap.merge("BUG", v.size(), Integer::sum); } @@ -82,20 +87,14 @@ public class NotificationService { if (k.contains("API")) { countMap.merge("API", v.size(), Integer::sum); } - if (k.contains("UI")) { - countMap.merge("UI", v.size(), Integer::sum); - } - if (k.contains("LOAD")) { - countMap.merge("LOAD", v.size(), Integer::sum); - } - if (k.contains("JENKINS")) { - countMap.merge("JENKINS", v.size(), Integer::sum); + if (k.contains("SCHEDULE")) { + countMap.merge("SCHEDULE", v.size(), Integer::sum); } }); countMap.forEach((k,v)->{ OptionDTO optionDTO = new OptionDTO(); - optionDTO.setId("total"); - optionDTO.setName(String.valueOf(notifications.size())); + optionDTO.setId(k); + optionDTO.setName(String.valueOf(v)); optionDTOS.add(optionDTO); }); } diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/NotificationControllerTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/NotificationControllerTests.java index 97dc5e99ae..5d7148a6ef 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/NotificationControllerTests.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/NotificationControllerTests.java @@ -8,6 +8,7 @@ import io.metersphere.system.base.BaseTest; import io.metersphere.system.controller.handler.ResultHolder; import io.metersphere.system.dto.sdk.OptionDTO; import io.metersphere.system.dto.sdk.request.NotificationRequest; +import io.metersphere.system.log.dto.NotificationDTO; import io.metersphere.system.notice.constants.NotificationConstants; import io.metersphere.system.utils.Pager; import jakarta.annotation.Resource; @@ -57,14 +58,14 @@ public class NotificationControllerTests extends BaseTest { notificationRequest.setCurrent(1); notificationRequest.setReceiver("admin"); notificationRequest.setType("SYSTEM_NOTICE"); + notificationRequest.setResourceType("CASE"); MvcResult mvcResult = this.requestPostWithOkAndReturn(NOTIFICATION_LIST_PAGE, notificationRequest); - Pager> tableData = JSON.parseObject(JSON.toJSONString( + Pager> tableData = JSON.parseObject(JSON.toJSONString( JSON.parseObject(mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()), Pager.class); //返回值的页码和当前页码相同 Assertions.assertEquals(tableData.getCurrent(), notificationRequest.getCurrent()); Assertions.assertFalse(tableData.getList().isEmpty()); - } @Test