| | |
| | | return; |
| | | } |
| | | |
| | | Map<Long, Integer> userTaskCountMap = buildUserTaskCountMap(tasks); |
| | | if (userTaskCountMap.isEmpty()) { |
| | | Map<Long, List<Long>> userTaskIdsMap = buildUserTaskIdsMap(tasks); |
| | | if (userTaskIdsMap.isEmpty()) { |
| | | log.warn("任务接收人为空,跳过通知"); |
| | | return; |
| | | } |
| | | |
| | | Set<Long> allUserIds = userTaskCountMap.keySet(); |
| | | Set<Long> allUserIds = userTaskIdsMap.keySet(); |
| | | |
| | | Map<Long, XpOperationsUser> userMap = fetchOperationUsers(allUserIds); |
| | | if (CollectionUtils.isEmpty(userMap)) { |
| | |
| | | List<XpOperationsUserNotification> notifications = new ArrayList<>(); |
| | | int pushCount = 0; |
| | | |
| | | for (Map.Entry<Long, Integer> entry : userTaskCountMap.entrySet()) { |
| | | for (Map.Entry<Long, List<Long>> entry : userTaskIdsMap.entrySet()) { |
| | | Long userId = entry.getKey(); |
| | | Integer taskCount = entry.getValue(); |
| | | if (taskCount == null || taskCount <= 0) { |
| | | List<Long> taskIds = entry.getValue(); |
| | | int taskCount = taskIds == null ? 0 : taskIds.size(); |
| | | if (taskCount <= 0) { |
| | | continue; |
| | | } |
| | | |
| | |
| | | continue; |
| | | } |
| | | |
| | | // 只有一个待完成任务时 dataId 赋值为该任务 ID,多个则赋值为 0 |
| | | long dataId = taskCount == 1 ? taskIds.get(0) : 0L; |
| | | |
| | | String content = buildContent(taskCount); |
| | | String bodyJson = buildPushBodyJson(content); |
| | | |
| | |
| | | notification.setNotificationType(NotificationTypeEnum.TASK_NEW.getCode()); |
| | | notification.setNotificationContent(content); |
| | | notification.setOperationsUserId(userId); |
| | | notification.setDataId(0L); |
| | | notification.setDataId(dataId); |
| | | notification.setReadStatus(0); |
| | | notification.setNotificationExt(bodyJson); |
| | | notifications.add(notification); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 构建用户待办数量映射 |
| | | * 构建用户待办任务 ID 列表映射 |
| | | * key: 运维人员 ID,value: 该用户名下的待办任务 ID 列表 |
| | | */ |
| | | private Map<Long, Integer> buildUserTaskCountMap(List<XpTask> tasks) { |
| | | Map<Long, Integer> userTaskCountMap = new HashMap<>(); |
| | | private Map<Long, List<Long>> buildUserTaskIdsMap(List<XpTask> tasks) { |
| | | Map<Long, List<Long>> userTaskIdsMap = new HashMap<>(); |
| | | for (XpTask task : tasks) { |
| | | Set<Long> userIds = parseUserIds(task.getHandleUserId()); |
| | | if (!CollectionUtils.isEmpty(userIds)) { |
| | | for (Long userId : userIds) { |
| | | userTaskCountMap.put(userId, userTaskCountMap.getOrDefault(userId, 0) + 1); |
| | | userTaskIdsMap.computeIfAbsent(userId, k -> new ArrayList<>()).add(task.getId()); |
| | | } |
| | | } |
| | | } |
| | | return userTaskCountMap; |
| | | return userTaskIdsMap; |
| | | } |
| | | |
| | | /** |