fix(项目管理): 修复消息通知显示未读状态问题

--bug=1039289 --user=郭雨琦 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001039289
This commit is contained in:
guoyuqi 2024-04-17 15:22:20 +08:00 committed by 刘瑞斌
parent 6442bd7641
commit f37615913a
5 changed files with 55 additions and 6 deletions

View File

@ -6,6 +6,7 @@ import com.github.pagehelper.PageHelper;
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.security.CheckOwner;
import io.metersphere.system.service.NotificationService;
import io.metersphere.system.utils.PageUtils;
import io.metersphere.system.utils.Pager;
@ -45,6 +46,13 @@ public class NotificationController {
return notificationService.readAll(resourceType, SessionUtils.getUserId());
}
@GetMapping(value = "/un-read/{projectId}")
@Operation(summary = "消息中心-获取未读的消息")
@CheckOwner(resourceId = "#projectId", resourceType = "project")
public Integer getUnRead(@PathVariable(value = "projectId") String projectId) {
return notificationService.getUnRead(projectId);
}
@PostMapping(value = "/count")
@Operation(summary = "消息中心-获取消息中心消息具体类型具体状态的数量")
public List<OptionDTO> countNotification(@RequestBody NotificationRequest notificationRequest) {

View File

@ -54,7 +54,7 @@ public class NotificationService {
}
public List<OptionDTO> countNotification(NotificationRequest notificationRequest, String userId) {
List<OptionDTO>optionDTOS = new ArrayList<>();
List<OptionDTO> optionDTOS = new ArrayList<>();
buildParam(notificationRequest, userId);
List<NotificationDTO> notifications = baseNotificationMapper.listNotification(notificationRequest);
OptionDTO totalOptionDTO = new OptionDTO();
@ -78,9 +78,9 @@ public class NotificationService {
}
private static void buildSourceCount(List<NotificationDTO> notifications, List<OptionDTO> optionDTOS) {
Map<String,Integer>countMap = new HashMap<>();
Map<String, Integer> countMap = new HashMap<>();
Map<String, List<Notification>> resourceMap = notifications.stream().collect(Collectors.groupingBy(Notification::getResourceType));
resourceMap.forEach((k,v)->{
resourceMap.forEach((k, v) -> {
if (k.contains("BUG")) {
countMap.merge("BUG", v.size(), Integer::sum);
}
@ -94,7 +94,7 @@ public class NotificationService {
countMap.merge("SCHEDULE", v.size(), Integer::sum);
}
});
countMap.forEach((k,v)->{
countMap.forEach((k, v) -> {
OptionDTO optionDTO = new OptionDTO();
optionDTO.setId(k);
optionDTO.setName(String.valueOf(v));
@ -107,5 +107,9 @@ public class NotificationService {
}
public Integer getUnRead(String projectId) {
NotificationExample example = new NotificationExample();
example.createCriteria().andProjectIdEqualTo(projectId).andStatusEqualTo(NotificationConstants.Status.UNREAD.name());
return (int) notificationMapper.countByExample(example);
}
}

View File

@ -39,6 +39,7 @@ public class NotificationControllerTests extends BaseTest {
public static final String NOTIFICATION_READ = "/notification/read/";
public static final String NOTIFICATION_READ_ALL = "/notification/read/all";
public static final String NOTIFICATION_COUNT = "/notification/count";
public static final String NOTIFICATION_UN_READ = "/notification/un-read";
@Resource
protected NotificationMapper notificationMapper;
@ -126,6 +127,16 @@ public class NotificationControllerTests extends BaseTest {
Assertions.assertFalse(optionDTOS.isEmpty());
}
@Test
@Order(5)
void getUnReadNotificationCount() throws Exception {
MvcResult mvcResult = this.requestGetWithOkAndReturn(NOTIFICATION_UN_READ+"/10000100001");
String updateReturnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(updateReturnData, ResultHolder.class);
Integer i = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), Integer.class);
Assertions.assertNotNull(i);
}
@Autowired

View File

@ -1,4 +1,5 @@
import MSR from '@/api/http/index';
import * as bugURL from '@/api/requrls/bug-management';
import { CommonList, TableQueryParams } from '@/models/common';
@ -88,3 +89,7 @@ export function queryMessageHistoryCount(data: historyQueryParams) {
export function getMessageReadAll(resourceType?: string) {
return MSR.get<number>({ url: '/notification/read/all', params: { resourceType } });
}
export function getMessageUnReadCount(projectId: string) {
return MSR.get<number>({ url: '/notification/un-read', params: projectId });
}

View File

@ -57,13 +57,18 @@
<li>
<a-tooltip :content="t('settings.navbar.alerts')">
<div class="message-box-trigger">
<a-badge :count="9" dot>
<a-badge v-if="unReadCount > 0" :count="9" dot>
<a-button type="secondary" @click="goMessageCenter">
<template #icon>
<icon-notification />
</template>
</a-button>
</a-badge>
<a-button v-else type="secondary" @click="goMessageCenter">
<template #icon>
<icon-notification />
</template>
</a-button>
</div>
</a-tooltip>
<a-popover
@ -155,6 +160,7 @@
import TopMenu from '@/components/business/ms-top-menu/index.vue';
import TaskCenterModal from './taskCenterModal.vue';
import { getMessageUnReadCount } from '@/api/modules/message';
import { switchProject } from '@/api/modules/project-management/project';
import { MENU_LEVEL, type PathMapRoute } from '@/config/pathMap';
import { useI18n } from '@/hooks/useI18n';
@ -179,6 +185,11 @@
const router = useRouter();
const { t } = useI18n();
const unReadCount = ref<number>(0);
async function checkMessageRead() {
unReadCount.value = await getMessageUnReadCount(appStore.currentProjectId);
}
watch(
() => appStore.currentOrgId,
async () => {
@ -189,6 +200,16 @@
}
);
watch(
() => appStore.getCurrentTopMenu?.name,
(val) => {
checkMessageRead();
},
{
immediate: true,
}
);
const showProjectSelect = computed(() => {
const { getRouteLevelByKey } = usePathMap();
//