refactor: 补充文档并优化代码

This commit is contained in:
2025-12-27 11:36:28 +08:00
parent 3f1c320a48
commit aa19c91465
32 changed files with 99 additions and 81 deletions
@@ -5,6 +5,7 @@ import com.auth0.jwt.algorithms.Algorithm;
import com.onixbyte.helix.domain.entity.User; import com.onixbyte.helix.domain.entity.User;
import com.onixbyte.helix.properties.TokenProperties; import com.onixbyte.helix.properties.TokenProperties;
import com.onixbyte.helix.utils.DateTimeUtil; import com.onixbyte.helix.utils.DateTimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@@ -31,6 +32,7 @@ public class TokenClient {
* @param tokenProperties the configuration properties for the token, such as issuer and * @param tokenProperties the configuration properties for the token, such as issuer and
* validity period * validity period
*/ */
@Autowired
public TokenClient(Algorithm algorithm, TokenProperties tokenProperties) { public TokenClient(Algorithm algorithm, TokenProperties tokenProperties) {
this.algorithm = algorithm; this.algorithm = algorithm;
this.tokenProperties = tokenProperties; this.tokenProperties = tokenProperties;
@@ -6,6 +6,7 @@ import com.onixbyte.helix.exception.BizException;
import com.onixbyte.helix.service.AssetService; import com.onixbyte.helix.service.AssetService;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@@ -31,6 +32,7 @@ public class AssetController {
* *
* @param assetService the file service to use for file operations * @param assetService the file service to use for file operations
*/ */
@Autowired
public AssetController(AssetService assetService) { public AssetController(AssetService assetService) {
this.assetService = assetService; this.assetService = assetService;
} }
@@ -5,6 +5,7 @@ import com.onixbyte.helix.domain.web.response.LoginSuccessResponse;
import com.onixbyte.helix.service.AuthService; import com.onixbyte.helix.service.AuthService;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@@ -15,6 +16,7 @@ public class AuthController {
private static final Logger log = LoggerFactory.getLogger(AuthController.class); private static final Logger log = LoggerFactory.getLogger(AuthController.class);
private final AuthService authService; private final AuthService authService;
@Autowired
public AuthController(AuthService authService) { public AuthController(AuthService authService) {
this.authService = authService; this.authService = authService;
} }
@@ -2,6 +2,7 @@ package com.onixbyte.helix.controller;
import com.onixbyte.helix.domain.web.response.CaptchaResponse; import com.onixbyte.helix.domain.web.response.CaptchaResponse;
import com.onixbyte.helix.service.CaptchaService; import com.onixbyte.helix.service.CaptchaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@@ -15,6 +16,7 @@ public class CaptchaController {
private final CaptchaService captchaService; private final CaptchaService captchaService;
@Autowired
public CaptchaController(CaptchaService captchaService) { public CaptchaController(CaptchaService captchaService) {
this.captchaService = captchaService; this.captchaService = captchaService;
} }
@@ -3,6 +3,7 @@ package com.onixbyte.helix.controller;
import com.onixbyte.helix.domain.entity.Department; import com.onixbyte.helix.domain.entity.Department;
import com.onixbyte.helix.domain.model.TreeNode; import com.onixbyte.helix.domain.model.TreeNode;
import com.onixbyte.helix.service.DepartmentService; import com.onixbyte.helix.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@@ -15,6 +16,7 @@ public class DepartmentController {
private final DepartmentService departmentService; private final DepartmentService departmentService;
@Autowired
public DepartmentController(DepartmentService departmentService) { public DepartmentController(DepartmentService departmentService) {
this.departmentService = departmentService; this.departmentService = departmentService;
} }
@@ -37,7 +37,6 @@ import java.util.stream.Collectors;
@RestControllerAdvice @RestControllerAdvice
public class ExceptionController { public class ExceptionController {
/** /**
* Handles business logic exceptions thrown throughout the application. * Handles business logic exceptions thrown throughout the application.
* <p> * <p>
@@ -3,6 +3,7 @@ package com.onixbyte.helix.controller;
import com.onixbyte.helix.domain.entity.Menu; import com.onixbyte.helix.domain.entity.Menu;
import com.onixbyte.helix.domain.model.TreeNode; import com.onixbyte.helix.domain.model.TreeNode;
import com.onixbyte.helix.service.MenuService; import com.onixbyte.helix.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@@ -15,6 +16,7 @@ public class MenuController {
private final MenuService menuService; private final MenuService menuService;
@Autowired
public MenuController(MenuService menuService) { public MenuController(MenuService menuService) {
this.menuService = menuService; this.menuService = menuService;
} }
@@ -2,6 +2,7 @@ package com.onixbyte.helix.controller;
import com.onixbyte.helix.domain.entity.Position; import com.onixbyte.helix.domain.entity.Position;
import com.onixbyte.helix.service.PositionService; import com.onixbyte.helix.service.PositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
@@ -16,6 +17,7 @@ public class PositionController {
private final PositionService positionService; private final PositionService positionService;
@Autowired
public PositionController(PositionService positionService) { public PositionController(PositionService positionService) {
this.positionService = positionService; this.positionService = positionService;
} }
@@ -5,6 +5,7 @@ import com.onixbyte.helix.domain.web.request.AddRoleRequest;
import com.onixbyte.helix.domain.web.request.EditRoleRequest; import com.onixbyte.helix.domain.web.request.EditRoleRequest;
import com.onixbyte.helix.domain.web.request.QueryRoleRequest; import com.onixbyte.helix.domain.web.request.QueryRoleRequest;
import com.onixbyte.helix.service.RoleService; import com.onixbyte.helix.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
@@ -18,6 +19,7 @@ public class RoleController {
private final RoleService roleService; private final RoleService roleService;
@Autowired
public RoleController(RoleService roleService) { public RoleController(RoleService roleService) {
this.roleService = roleService; this.roleService = roleService;
} }
@@ -1,12 +1,12 @@
package com.onixbyte.helix.controller; package com.onixbyte.helix.controller;
import com.onixbyte.helix.domain.entity.User;
import com.onixbyte.helix.domain.web.request.AddUserRequest; import com.onixbyte.helix.domain.web.request.AddUserRequest;
import com.onixbyte.helix.domain.web.request.QueryUserRequest; import com.onixbyte.helix.domain.web.request.QueryUserRequest;
import com.onixbyte.helix.domain.web.request.ResetPasswordRequest; import com.onixbyte.helix.domain.web.request.ResetPasswordRequest;
import com.onixbyte.helix.domain.web.request.UpdateUserRequest; import com.onixbyte.helix.domain.web.request.UpdateUserRequest;
import com.onixbyte.helix.domain.web.response.UserDetailResponse; import com.onixbyte.helix.domain.web.response.UserDetailResponse;
import com.onixbyte.helix.service.UserService; import com.onixbyte.helix.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
@@ -21,6 +21,7 @@ public class UserController {
private final UserService userService; private final UserService userService;
@Autowired
public UserController(UserService userService) { public UserController(UserService userService) {
this.userService = userService; this.userService = userService;
} }
@@ -1,6 +1,7 @@
package com.onixbyte.helix.manager; package com.onixbyte.helix.manager;
import com.onixbyte.helix.properties.ApplicationProperties; import com.onixbyte.helix.properties.ApplicationProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Component @Component
@@ -8,6 +9,7 @@ public class ApplicationManager {
private final ApplicationProperties applicationProperties; private final ApplicationProperties applicationProperties;
@Autowired
public ApplicationManager(ApplicationProperties applicationProperties) { public ApplicationManager(ApplicationProperties applicationProperties) {
this.applicationProperties = applicationProperties; this.applicationProperties = applicationProperties;
} }
@@ -2,13 +2,12 @@ package com.onixbyte.helix.manager;
import com.onixbyte.helix.constant.CacheName; import com.onixbyte.helix.constant.CacheName;
import com.onixbyte.helix.domain.entity.Asset; import com.onixbyte.helix.domain.entity.Asset;
import com.onixbyte.helix.exception.BizException;
import com.onixbyte.helix.mapper.AssetMapper; import com.onixbyte.helix.mapper.AssetMapper;
import com.onixbyte.helix.repository.AssetRepository; import com.onixbyte.helix.repository.AssetRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut; import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Component @Component
@@ -17,6 +16,7 @@ public class AssetManager {
private final AssetMapper assetMapper; private final AssetMapper assetMapper;
private final AssetRepository assetRepository; private final AssetRepository assetRepository;
@Autowired
public AssetManager(AssetMapper assetMapper, AssetRepository assetRepository) { public AssetManager(AssetMapper assetMapper, AssetRepository assetRepository) {
this.assetMapper = assetMapper; this.assetMapper = assetMapper;
this.assetRepository = assetRepository; this.assetRepository = assetRepository;
@@ -3,6 +3,7 @@ package com.onixbyte.helix.manager;
import com.onixbyte.helix.constant.CacheName; import com.onixbyte.helix.constant.CacheName;
import com.onixbyte.helix.domain.entity.Authority; import com.onixbyte.helix.domain.entity.Authority;
import com.onixbyte.helix.mapper.AuthorityMapper; import com.onixbyte.helix.mapper.AuthorityMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@@ -13,6 +14,7 @@ public class AuthorityManager {
private final AuthorityMapper authorityMapper; private final AuthorityMapper authorityMapper;
@Autowired
public AuthorityManager(AuthorityMapper authorityMapper) { public AuthorityManager(AuthorityMapper authorityMapper) {
this.authorityMapper = authorityMapper; this.authorityMapper = authorityMapper;
} }
@@ -3,6 +3,7 @@ package com.onixbyte.helix.manager;
import com.onixbyte.helix.domain.entity.Department; import com.onixbyte.helix.domain.entity.Department;
import com.onixbyte.helix.mapper.DepartmentMapper; import com.onixbyte.helix.mapper.DepartmentMapper;
import com.onixbyte.helix.repository.DepartmentRepository; import com.onixbyte.helix.repository.DepartmentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@@ -15,6 +16,7 @@ public class DepartmentManager {
private final DepartmentMapper departmentMapper; private final DepartmentMapper departmentMapper;
private final DepartmentRepository departmentRepository; private final DepartmentRepository departmentRepository;
@Autowired
public DepartmentManager(DepartmentMapper departmentMapper, DepartmentRepository departmentRepository) { public DepartmentManager(DepartmentMapper departmentMapper, DepartmentRepository departmentRepository) {
this.departmentMapper = departmentMapper; this.departmentMapper = departmentMapper;
this.departmentRepository = departmentRepository; this.departmentRepository = departmentRepository;
@@ -4,6 +4,7 @@ import com.onixbyte.helix.domain.entity.Menu;
import com.onixbyte.helix.mapper.MenuMapper; import com.onixbyte.helix.mapper.MenuMapper;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.List; import java.util.List;
@@ -13,6 +14,7 @@ public class MenuManager {
private static final Logger log = LoggerFactory.getLogger(MenuManager.class); private static final Logger log = LoggerFactory.getLogger(MenuManager.class);
private final MenuMapper menuMapper; private final MenuMapper menuMapper;
@Autowired
public MenuManager(MenuMapper menuMapper) { public MenuManager(MenuMapper menuMapper) {
this.menuMapper = menuMapper; this.menuMapper = menuMapper;
} }
@@ -3,8 +3,8 @@ package com.onixbyte.helix.manager;
import com.onixbyte.helix.domain.entity.Position; import com.onixbyte.helix.domain.entity.Position;
import com.onixbyte.helix.mapper.PositionMapper; import com.onixbyte.helix.mapper.PositionMapper;
import com.onixbyte.helix.repository.PositionRepository; import com.onixbyte.helix.repository.PositionRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@@ -14,6 +14,7 @@ public class PositionManager {
private final PositionMapper positionMapper; private final PositionMapper positionMapper;
private final PositionRepository positionRepository; private final PositionRepository positionRepository;
@Autowired
public PositionManager(PositionMapper positionMapper, PositionRepository positionRepository) { public PositionManager(PositionMapper positionMapper, PositionRepository positionRepository) {
this.positionMapper = positionMapper; this.positionMapper = positionMapper;
this.positionRepository = positionRepository; this.positionRepository = positionRepository;
@@ -1,11 +1,11 @@
package com.onixbyte.helix.manager; package com.onixbyte.helix.manager;
import com.onixbyte.helix.constant.Status;
import com.onixbyte.helix.domain.database.query.wrapper.QueryRoleWrapper; import com.onixbyte.helix.domain.database.query.wrapper.QueryRoleWrapper;
import com.onixbyte.helix.domain.entity.Role; import com.onixbyte.helix.domain.entity.Role;
import com.onixbyte.helix.exception.BizException; import com.onixbyte.helix.exception.BizException;
import com.onixbyte.helix.mapper.RoleMapper; import com.onixbyte.helix.mapper.RoleMapper;
import com.onixbyte.helix.repository.RoleRepository; import com.onixbyte.helix.repository.RoleRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.*; import org.springframework.data.domain.*;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@@ -20,6 +20,7 @@ public class RoleManager {
private final RoleMapper roleMapper; private final RoleMapper roleMapper;
private final RoleRepository roleRepository; private final RoleRepository roleRepository;
@Autowired
public RoleManager(RoleMapper roleMapper, RoleRepository roleRepository) { public RoleManager(RoleMapper roleMapper, RoleRepository roleRepository) {
this.roleMapper = roleMapper; this.roleMapper = roleMapper;
this.roleRepository = roleRepository; this.roleRepository = roleRepository;
@@ -2,6 +2,7 @@ package com.onixbyte.helix.manager;
import com.onixbyte.helix.domain.entity.Setting; import com.onixbyte.helix.domain.entity.Setting;
import com.onixbyte.helix.repository.SettingRepository; import com.onixbyte.helix.repository.SettingRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@@ -10,6 +11,7 @@ public class SettingManager {
private final SettingRepository settingRepository; private final SettingRepository settingRepository;
@Autowired
public SettingManager(SettingRepository settingRepository) { public SettingManager(SettingRepository settingRepository) {
this.settingRepository = settingRepository; this.settingRepository = settingRepository;
} }
@@ -10,6 +10,7 @@ import com.onixbyte.helix.mapper.UserMapper;
import com.onixbyte.helix.repository.UserRepository; import com.onixbyte.helix.repository.UserRepository;
import com.onixbyte.region.Region; import com.onixbyte.region.Region;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CachePut; import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Example; import org.springframework.data.domain.Example;
@@ -30,7 +31,12 @@ public class UserManager {
private final UserRepository userRepository; private final UserRepository userRepository;
private final PasswordEncoder passwordEncoder; private final PasswordEncoder passwordEncoder;
public UserManager(UserMapper userMapper, UserRepository userRepository, PasswordEncoder passwordEncoder) { @Autowired
public UserManager(
UserMapper userMapper,
UserRepository userRepository,
PasswordEncoder passwordEncoder
) {
this.userMapper = userMapper; this.userMapper = userMapper;
this.userRepository = userRepository; this.userRepository = userRepository;
this.passwordEncoder = passwordEncoder; this.passwordEncoder = passwordEncoder;
@@ -1,12 +1,11 @@
package com.onixbyte.helix.manager; package com.onixbyte.helix.manager;
import com.onixbyte.helix.domain.entity.UserRole; import com.onixbyte.helix.domain.entity.UserRole;
import com.onixbyte.helix.exception.BizException;
import com.onixbyte.helix.mapper.UserRoleMapper; import com.onixbyte.helix.mapper.UserRoleMapper;
import com.onixbyte.helix.repository.UserRoleRepository; import com.onixbyte.helix.repository.UserRoleRepository;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.List; import java.util.List;
@@ -18,6 +17,7 @@ public class UserRoleManager {
private final UserRoleMapper userRoleMapper; private final UserRoleMapper userRoleMapper;
private final UserRoleRepository userRoleRepository; private final UserRoleRepository userRoleRepository;
@Autowired
public UserRoleManager(UserRoleMapper userRoleMapper, UserRoleRepository userRoleRepository) { public UserRoleManager(UserRoleMapper userRoleMapper, UserRoleRepository userRoleRepository) {
this.userRoleMapper = userRoleMapper; this.userRoleMapper = userRoleMapper;
this.userRoleRepository = userRoleRepository; this.userRoleRepository = userRoleRepository;
@@ -1,60 +0,0 @@
/**
* Business logic management and orchestration package for the Helix application.
* <p>
* This package is designed to contain manager classes that orchestrate complex business operations,
* coordinate between multiple services, and handle cross-cutting concerns that span multiple
* domain boundaries.
* <p>
* <strong>Manager Pattern:</strong> Managers in this package serve as facades or coordinators that
* encapsulate complex business workflows, typically involving multiple services, repositories,
* or external systems. They provide a higher-level abstraction over individual service components.
* <p>
* <strong>Intended Contents:</strong>
* <ul>
* <li>
* <strong>Workflow Managers:</strong> Orchestrate multi-step business processes
* </li>
* <li>
* <strong>Integration Managers:</strong> Coordinate interactions with external systems
* </li>
* <li>
* <strong>Transaction Managers:</strong> Handle complex transactional scenarios
* </li>
* <li>
* <strong>Cache Managers:</strong> Manage caching strategies and cache invalidation
* </li>
* <li>
* <strong>Event Managers:</strong> Coordinate event publishing and handling
* </li>
* </ul>
* <p>
* <strong>Design Guidelines:</strong>
* <ul>
* <li>
* <strong>Single Responsibility:</strong> Each manager should focus on a specific business domain
* or cross-cutting concern
* </li>
* <li>
* <strong>Service Coordination:</strong> Managers should delegate to services rather than
* implementing business logic directly
* </li>
* <li>
* <strong>Transaction Boundaries:</strong> Define clear transactional boundaries for
* complex operations
* </li>
* <li>
* <strong>Error Handling:</strong> Provide comprehensive error handling and rollback mechanisms
* for complex workflows
* </li>
* </ul>
* <p>
* Managers typically sit between the controller layer and the service layer, providing a
* coordination point for complex operations that require multiple service interactions or
* cross-cutting concerns.
*
* @author zihluwang
* @since 1.0.0
* @see com.onixbyte.helix.service
* @see org.springframework.transaction.annotation.Transactional
*/
package com.onixbyte.helix.manager;
@@ -7,6 +7,7 @@ import com.onixbyte.helix.manager.UserManager;
import com.onixbyte.helix.security.authentication.UsernamePasswordAuthentication; import com.onixbyte.helix.security.authentication.UsernamePasswordAuthentication;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.security.authentication.AuthenticationProvider; import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
@@ -24,7 +25,12 @@ public class UsernamePasswordAuthenticationProvider implements AuthenticationPro
private final PasswordEncoder passwordEncoder; private final PasswordEncoder passwordEncoder;
private final AuthorityManager authorityManager; private final AuthorityManager authorityManager;
public UsernamePasswordAuthenticationProvider(UserManager userManager, PasswordEncoder passwordEncoder, AuthorityManager authorityManager) { @Autowired
public UsernamePasswordAuthenticationProvider(
UserManager userManager,
PasswordEncoder passwordEncoder,
AuthorityManager authorityManager
) {
this.userManager = userManager; this.userManager = userManager;
this.passwordEncoder = passwordEncoder; this.passwordEncoder = passwordEncoder;
this.authorityManager = authorityManager; this.authorityManager = authorityManager;
@@ -5,6 +5,7 @@ import com.onixbyte.helix.exception.BizException;
import com.onixbyte.helix.manager.AssetManager; import com.onixbyte.helix.manager.AssetManager;
import com.onixbyte.helix.properties.AssetProperties; import com.onixbyte.helix.properties.AssetProperties;
import com.onixbyte.helix.utils.SecurityUtil; import com.onixbyte.helix.utils.SecurityUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@@ -34,6 +35,7 @@ public class AssetService {
private final S3Client s3Client; private final S3Client s3Client;
private final AssetManager assetManager; private final AssetManager assetManager;
@Autowired
public AssetService( public AssetService(
AssetProperties assetProperties, AssetProperties assetProperties,
S3Client s3Client, S3Client s3Client,
@@ -51,14 +51,14 @@ public class CaptchaService {
return null; return null;
} }
// 生成 UUID 及验证码 // Generate UUID and captcha
var uuid = UUID.randomUUID().toString().replaceAll("-", ""); var uuid = UUID.randomUUID().toString().replaceAll("-", "");
var captchaCode = producer.createText(); var captchaCode = producer.createText();
// 将验证码保存到缓存中 // Store UUID and captcha to cache
captchaManager.setCaptcha(uuid, captchaCode); captchaManager.setCaptcha(uuid, captchaCode);
// 生成验证码图片 // Generate captcha image
var captchaImage = producer.createImage(captchaCode); var captchaImage = producer.createImage(captchaCode);
try (var byteArrayOutputStream = new FastByteArrayOutputStream()) { try (var byteArrayOutputStream = new FastByteArrayOutputStream()) {
ImageIO.write(captchaImage, FileType.Image.JPEG.getExtension(), byteArrayOutputStream); ImageIO.write(captchaImage, FileType.Image.JPEG.getExtension(), byteArrayOutputStream);
@@ -69,8 +69,4 @@ public class CaptchaService {
throw new BizException("无法生成验证码图片。"); throw new BizException("无法生成验证码图片。");
} }
} }
public String getCaptcha(String uuid) {
return captchaManager.getCaptcha(uuid);
}
} }
@@ -4,7 +4,7 @@ import com.onixbyte.helix.domain.entity.Department;
import com.onixbyte.helix.domain.model.TreeNode; import com.onixbyte.helix.domain.model.TreeNode;
import com.onixbyte.helix.manager.DepartmentManager; import com.onixbyte.helix.manager.DepartmentManager;
import com.onixbyte.helix.utils.TreeUtil; import com.onixbyte.helix.utils.TreeUtil;
import org.springframework.data.domain.PageRequest; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -15,6 +15,7 @@ public class DepartmentService {
private final DepartmentManager departmentManager; private final DepartmentManager departmentManager;
@Autowired
public DepartmentService(DepartmentManager departmentManager) { public DepartmentService(DepartmentManager departmentManager) {
this.departmentManager = departmentManager; this.departmentManager = departmentManager;
} }
@@ -7,6 +7,7 @@ import com.onixbyte.helix.utils.SecurityUtil;
import com.onixbyte.helix.utils.TreeUtil; import com.onixbyte.helix.utils.TreeUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
@@ -16,6 +17,7 @@ public class MenuService {
private static final Logger log = LoggerFactory.getLogger(MenuService.class); private static final Logger log = LoggerFactory.getLogger(MenuService.class);
private final MenuManager menuManager; private final MenuManager menuManager;
@Autowired
public MenuService(MenuManager menuManager) { public MenuService(MenuManager menuManager) {
this.menuManager = menuManager; this.menuManager = menuManager;
} }
@@ -2,17 +2,17 @@ package com.onixbyte.helix.service;
import com.onixbyte.helix.domain.entity.Position; import com.onixbyte.helix.domain.entity.Position;
import com.onixbyte.helix.manager.PositionManager; import com.onixbyte.helix.manager.PositionManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
@Service @Service
public class PositionService { public class PositionService {
private final PositionManager positionManager; private final PositionManager positionManager;
@Autowired
public PositionService(PositionManager positionManager) { public PositionService(PositionManager positionManager) {
this.positionManager = positionManager; this.positionManager = positionManager;
} }
@@ -9,6 +9,7 @@ import com.onixbyte.helix.domain.web.request.QueryRoleRequest;
import com.onixbyte.helix.manager.RoleManager; import com.onixbyte.helix.manager.RoleManager;
import jakarta.transaction.Transactional; import jakarta.transaction.Transactional;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -20,6 +21,7 @@ public class RoleService {
private final RoleManager roleManager; private final RoleManager roleManager;
@Autowired
public RoleService(RoleManager roleManager) { public RoleService(RoleManager roleManager) {
this.roleManager = roleManager; this.roleManager = roleManager;
} }
@@ -17,6 +17,7 @@ import com.onixbyte.helix.manager.UserManager;
import com.onixbyte.helix.manager.UserRoleManager; import com.onixbyte.helix.manager.UserRoleManager;
import com.onixbyte.identitygenerator.IdentityGenerator; import com.onixbyte.identitygenerator.IdentityGenerator;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder;
@@ -36,6 +37,7 @@ public class UserService {
private final PasswordEncoder passwordEncoder; private final PasswordEncoder passwordEncoder;
private final ApplicationManager applicationManager; private final ApplicationManager applicationManager;
@Autowired
public UserService( public UserService(
UserManager userManager, UserManager userManager,
IdentityGenerator<Long> userIdentityGenerator, IdentityGenerator<Long> userIdentityGenerator,
@@ -4,8 +4,19 @@ import java.time.Instant;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;
/**
* DateTimeUtil helps to convert date and time between different types.
*
* @author zihluwang
*/
public class DateTimeUtil { public class DateTimeUtil {
/**
* Convert {@link LocalDateTime} to {@link Instant}.
*
* @param localDateTime local date time to be converted
* @return converted instant
*/
public static Instant asInstant(LocalDateTime localDateTime) { public static Instant asInstant(LocalDateTime localDateTime) {
return localDateTime.atZone(ZoneId.systemDefault()) return localDateTime.atZone(ZoneId.systemDefault())
.toInstant(); .toInstant();
@@ -7,10 +7,24 @@ import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
/**
* SecurityUtil helps to manipulate Spring Security.
*
* @author zihluwang
*/
public class SecurityUtil { public class SecurityUtil {
private static final Logger log = LoggerFactory.getLogger(SecurityUtil.class); private static final Logger log = LoggerFactory.getLogger(SecurityUtil.class);
private SecurityUtil() {
}
/**
* Get user information from {@link SecurityContextHolder}.
*
* @return user information
* @throws BizException if user information is not saved in {@link SecurityContextHolder}
*/
public static User getCurrentUser() { public static User getCurrentUser() {
var _details = SecurityContextHolder.getContext() var _details = SecurityContextHolder.getContext()
.getAuthentication() .getAuthentication()
@@ -9,8 +9,16 @@ import org.springframework.http.HttpStatus;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/**
* TreeUtil help to build a tree or forest of specified data.
*
* @author zihluwang
*/
public class TreeUtil { public class TreeUtil {
private TreeUtil() {
}
/** /**
* Builds a tree from a flat list of items that implement Treeable. * Builds a tree from a flat list of items that implement Treeable.
* *
@@ -40,7 +48,7 @@ public class TreeUtil {
// Get root item and build root node // Get root item and build root node
var rootItem = rootItems.get(0); var rootItem = rootItems.get(0);
var rootNode = new TreeNode<T>(rootItem); var rootNode = new TreeNode<>(rootItem);
idToNodeMap.remove(rootItem.getId()); idToNodeMap.remove(rootItem.getId());
// Iterate through all departments to build the hierarchy. // Iterate through all departments to build the hierarchy.