refactor(notification): 优化质量通知用户关联逻辑
- 移除手动选择用户的条件判断,统一调用用户关联保存方法 - 更新业务错误验证逻辑,检查用户列表和部门列表均为空的情况 - 重构saveNotificationUsers方法,区分全部用户和手动选择用户的处理流程 - 修复查询条件中的空格格式问题 - 优化代码结构,提高可读性和维护性
This commit is contained in:
parent
5e88f5c36e
commit
8d3d446df2
|
|
@ -100,11 +100,8 @@ public class QualityNotificationControllerService {
|
|||
qualityNotificationFileService.saveBatch(attachments);
|
||||
}
|
||||
|
||||
// 如果是手动选择用户,保存用户关联
|
||||
if (request.getTargetType() == 2) {
|
||||
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);
|
||||
}
|
||||
|
||||
if (CollectionUtil.isNotEmpty(request.getAttachments())) {
|
||||
qualityNotificationFileService.lambdaUpdate()
|
||||
|
|
@ -272,6 +269,26 @@ public class QualityNotificationControllerService {
|
|||
*/
|
||||
private void saveNotificationUsers(Long notificationId, QmsQualityNotificationAddQO request,
|
||||
String operator, Long operatorId, LocalDateTime now) {
|
||||
if (request.getTargetType() == 1) {
|
||||
userService.lambdaQuery()
|
||||
.in(User::getId, userInteriorService.list()
|
||||
.stream()
|
||||
.map(UserInterior::getUserId)
|
||||
.toList()
|
||||
)
|
||||
.list()
|
||||
.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())
|
||||
);
|
||||
});
|
||||
} else if (request.getTargetType() == 2) {
|
||||
List<QmsQualityNotificationTarget> datas = new ArrayList<>();
|
||||
if (CollectionUtil.isNotEmpty(request.getUserIds())) {
|
||||
datas.addAll(
|
||||
|
|
@ -329,6 +346,7 @@ public class QualityNotificationControllerService {
|
|||
}
|
||||
notificationUserService.saveBatch(datas);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 翻译名称
|
||||
|
|
|
|||
Loading…
Reference in New Issue