增加构建通知
This commit is contained in:
parent
13b2a6ac53
commit
cb5741f487
@ -13,6 +13,10 @@ import org.mapstruct.Mappings;
|
||||
public interface UserConverter extends BaseConverter<User, UserDTO> {
|
||||
// MapStruct 会自动实现所有方法
|
||||
|
||||
@Override
|
||||
@Mapping(target = "department", ignore = true)
|
||||
User toEntity(UserDTO dto);
|
||||
|
||||
@Mapping(target = "token", ignore = true)
|
||||
@Mapping(target = "roles", ignore = true)
|
||||
@Mapping(target = "permissions", ignore = true)
|
||||
|
||||
@ -80,7 +80,21 @@ public class UserServiceImpl extends BaseServiceImpl<User, UserDTO, UserQuery, L
|
||||
dto.setPassword(PasswordGenerator.encode("123456"));
|
||||
log.info("用户 {} 未设置密码,使用默认密码: 123456", dto.getUsername());
|
||||
}
|
||||
return super.create(dto);
|
||||
|
||||
// 转换为实体
|
||||
validateUniqueConstraints(dto);
|
||||
User entity = userConverter.toEntity(dto);
|
||||
|
||||
// 设置部门
|
||||
if (dto.getDepartmentId() != null) {
|
||||
Department department = departmentRepository.findById(dto.getDepartmentId())
|
||||
.orElseThrow(() -> new BusinessException(ResponseCode.DEPARTMENT_NOT_FOUND));
|
||||
entity.setDepartment(department);
|
||||
}
|
||||
|
||||
// 保存并返回
|
||||
User savedEntity = userRepository.save(entity);
|
||||
return userConverter.toDto(savedEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Loading…
Reference in New Issue
Block a user