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()