From 8d3d446df2fca54bd35924cd1a9fd51e74c922db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E9=B9=8F=E9=A3=9E?= Date: Sat, 13 Jun 2026 14:25:14 +0800 Subject: [PATCH] =?UTF-8?q?refactor(notification):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E8=B4=A8=E9=87=8F=E9=80=9A=E7=9F=A5=E7=94=A8=E6=88=B7=E5=85=B3?= =?UTF-8?q?=E8=81=94=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除手动选择用户的条件判断,统一调用用户关联保存方法 - 更新业务错误验证逻辑,检查用户列表和部门列表均为空的情况 - 重构saveNotificationUsers方法,区分全部用户和手动选择用户的处理流程 - 修复查询条件中的空格格式问题 - 优化代码结构,提高可读性和维护性 --- .../QualityNotificationControllerService.java | 124 ++++++++++-------- 1 file changed, 71 insertions(+), 53 deletions(-) diff --git a/nflg-qms-admin/src/main/java/com/nflg/qms/admin/service/QualityNotificationControllerService.java b/nflg-qms-admin/src/main/java/com/nflg/qms/admin/service/QualityNotificationControllerService.java index b014f828..68efc762 100644 --- a/nflg-qms-admin/src/main/java/com/nflg/qms/admin/service/QualityNotificationControllerService.java +++ b/nflg-qms-admin/src/main/java/com/nflg/qms/admin/service/QualityNotificationControllerService.java @@ -100,10 +100,7 @@ public class QualityNotificationControllerService { qualityNotificationFileService.saveBatch(attachments); } - // 如果是手动选择用户,保存用户关联 - if (request.getTargetType() == 2) { - saveNotificationUsers(entity.getId(), request, operator, operatorId, now); - } + saveNotificationUsers(entity.getId(), request, operator, operatorId, now); } /** @@ -116,8 +113,10 @@ public class QualityNotificationControllerService { // 如果是手动选择用户,必须提供用户ID列表 if (request.getTargetType() == 2) { - VUtil.trueThrowBusinessError(CollectionUtil.isEmpty(request.getUserIds())) - .throwMessage("手动选择用户时,用户列表不能为空"); + VUtil.trueThrowBusinessError(CollectionUtil.isEmpty(request.getUserIds()) + && CollectionUtil.isEmpty(request.getDepartmentIds()) + ) + .throwMessage("手动选择用户时,用户列表和部门列表不能为空"); } String operator = UserUtil.getUserName(); @@ -141,9 +140,7 @@ public class QualityNotificationControllerService { .remove(); // 如果是手动选择用户,重新保存用户关联 - if (request.getTargetType() == 2 && CollectionUtil.isNotEmpty(request.getUserIds())) { - saveNotificationUsers(request.getId(), request, operator, operatorId, now); - } + saveNotificationUsers(request.getId(), request, operator, operatorId, now); if (CollectionUtil.isNotEmpty(request.getAttachments())) { qualityNotificationFileService.lambdaUpdate() @@ -218,7 +215,7 @@ public class QualityNotificationControllerService { if (entity.getTargetType() == 2) { List users = notificationUserService.lambdaQuery() .eq(QmsQualityNotificationTarget::getNotificationId, id) - .eq(QmsQualityNotificationTarget::getSourceType,0) + .eq(QmsQualityNotificationTarget::getSourceType, 0) .list(); if (CollectionUtil.isNotEmpty(users)) { List userIds = users.stream() @@ -272,49 +269,14 @@ public class QualityNotificationControllerService { */ private void saveNotificationUsers(Long notificationId, QmsQualityNotificationAddQO request, String operator, Long operatorId, LocalDateTime now) { - List datas = new ArrayList<>(); - if (CollectionUtil.isNotEmpty(request.getUserIds())) { - datas.addAll( - request.getUserIds().stream() - .map(userId -> new QmsQualityNotificationTarget() - .setNotificationId(notificationId) - .setSourceId(userId) - .setSourceType(0) - .setCreateById(operatorId) - .setCreateBy(operator) - .setCreateTime(now)) - .toList() - ); - } - if (CollectionUtil.isNotEmpty(request.getDepartmentIds())) { - datas.addAll( - request.getDepartmentIds().stream() - .map(departmentId -> new QmsQualityNotificationTarget() - .setNotificationId(notificationId) - .setSourceId(departmentId) - .setSourceType(1) - .setCreateById(operatorId) - .setCreateBy(operator) - .setCreateTime(now)) - .toList() - ); - } - List userIds = request.getUserIds(); - if (CollectionUtil.isNotEmpty(request.getDepartmentIds())) { - if (CollectionUtil.isEmpty(userIds)) { - userIds = new ArrayList<>(); - } - userIds.addAll( - userInteriorService.lambdaQuery() - .in(UserInterior::getDeptId, request.getDepartmentIds()) - .list() + if (request.getTargetType() == 1) { + userService.lambdaQuery() + .in(User::getId, userInteriorService.list() .stream() .map(UserInterior::getUserId) .toList() - ); - } - if (CollectionUtil.isNotEmpty(userIds)) { - userService.listByIds(userIds) + ) + .list() .forEach(user -> { todoItemService.add(new QmsTodoItem() .setTitle(request.getTitle()) @@ -326,8 +288,64 @@ public class QualityNotificationControllerService { .setCreateTime(LocalDateTime.now()) ); }); + } else if (request.getTargetType() == 2) { + List datas = new ArrayList<>(); + if (CollectionUtil.isNotEmpty(request.getUserIds())) { + datas.addAll( + request.getUserIds().stream() + .map(userId -> new QmsQualityNotificationTarget() + .setNotificationId(notificationId) + .setSourceId(userId) + .setSourceType(0) + .setCreateById(operatorId) + .setCreateBy(operator) + .setCreateTime(now)) + .toList() + ); + } + if (CollectionUtil.isNotEmpty(request.getDepartmentIds())) { + datas.addAll( + request.getDepartmentIds().stream() + .map(departmentId -> new QmsQualityNotificationTarget() + .setNotificationId(notificationId) + .setSourceId(departmentId) + .setSourceType(1) + .setCreateById(operatorId) + .setCreateBy(operator) + .setCreateTime(now)) + .toList() + ); + } + List userIds = request.getUserIds(); + if (CollectionUtil.isNotEmpty(request.getDepartmentIds())) { + if (CollectionUtil.isEmpty(userIds)) { + userIds = new ArrayList<>(); + } + userIds.addAll( + userInteriorService.lambdaQuery() + .in(UserInterior::getDeptId, request.getDepartmentIds()) + .list() + .stream() + .map(UserInterior::getUserId) + .toList() + ); + } + if (CollectionUtil.isNotEmpty(userIds)) { + userService.listByIds(userIds) + .forEach(user -> { + todoItemService.add(new QmsTodoItem() + .setTitle(request.getTitle()) + .setCode(basdeSerialNumberControllerService.generateSerialNumber(47)) + .setSourceId(notificationId) + .setSourceTypeId(dictionaryItemService.getIdByCode("MessageType", "QualityNotification")) + .setCreateUserId(user.getId()) + .setCreateUserName(user.getUserName()) + .setCreateTime(LocalDateTime.now()) + ); + }); + } + notificationUserService.saveBatch(datas); } - notificationUserService.saveBatch(datas); } /** @@ -341,7 +359,7 @@ public class QualityNotificationControllerService { vo.setDepartmentIds( notificationUserService.lambdaQuery() .eq(QmsQualityNotificationTarget::getNotificationId, vo.getId()) - .eq(QmsQualityNotificationTarget::getSourceType,1) + .eq(QmsQualityNotificationTarget::getSourceType, 1) .list() .stream() .map(QmsQualityNotificationTarget::getSourceId) @@ -349,7 +367,7 @@ public class QualityNotificationControllerService { ); List users = notificationUserService.lambdaQuery() .eq(QmsQualityNotificationTarget::getNotificationId, vo.getId()) - .eq(QmsQualityNotificationTarget::getSourceType,0) + .eq(QmsQualityNotificationTarget::getSourceType, 0) .list(); if (CollectionUtil.isNotEmpty(users)) { List userIds = users.stream()