mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 10:29:19 +08:00
初始化项目
This commit is contained in:
+83
@@ -0,0 +1,83 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.LoginDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.RegisterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.vo.LoginVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.service.UserService;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.service.PermissionCheckService;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 认证控制器
|
||||
*/
|
||||
@Tag(name = "认证管理", description = "用户注册、登录等认证相关接口")
|
||||
@RestController
|
||||
@RequestMapping("/auth")
|
||||
public class AuthController {
|
||||
|
||||
private final UserService userService;
|
||||
private final PermissionCheckService permissionCheckService;
|
||||
private final CurrentUserContext currentUserContext;
|
||||
|
||||
public AuthController(UserService userService, PermissionCheckService permissionCheckService, CurrentUserContext currentUserContext) {
|
||||
this.userService = userService;
|
||||
this.permissionCheckService = permissionCheckService;
|
||||
this.currentUserContext = currentUserContext;
|
||||
}
|
||||
|
||||
@Operation(summary = "用户注册", description = "用户注册接口,支持通过登录账号或手机号码注册")
|
||||
@PostMapping("/register")
|
||||
public ApiResponse<LoginVO> register(@Valid @RequestBody RegisterDTO registerDTO) {
|
||||
LoginVO loginVO = userService.register(registerDTO);
|
||||
return ApiResponse.success(loginVO);
|
||||
}
|
||||
|
||||
@Operation(summary = "用户登录", description = "用户登录接口,支持通过登录账号或手机号码登录")
|
||||
@PostMapping("/login")
|
||||
public ApiResponse<LoginVO> login(@Valid @RequestBody LoginDTO loginDTO) {
|
||||
LoginVO loginVO = userService.login(loginDTO);
|
||||
return ApiResponse.success(loginVO);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取用户权限码", description = "获取当前登录用户的权限码列表")
|
||||
@GetMapping("/codes")
|
||||
public ApiResponse<List<String>> getAccessCodes() {
|
||||
try {
|
||||
String role = currentUserContext.getCurrentUserPayload().getRole();
|
||||
Long positionId = currentUserContext.getCurrentUserPayload().getPositionId();
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
|
||||
List<String> permissions;
|
||||
|
||||
// 根据角色返回不同的权限
|
||||
switch (role) {
|
||||
case "super":
|
||||
// 超级管理员拥有所有权限
|
||||
permissions = List.of("*");
|
||||
break;
|
||||
case "company":
|
||||
// 公司管理员拥有公司相关权限
|
||||
permissions = List.of("company:*");
|
||||
break;
|
||||
case "user":
|
||||
// 普通用户根据岗位获取权限
|
||||
permissions = permissionCheckService.getPositionPermissions(positionId, companyId);
|
||||
break;
|
||||
default:
|
||||
permissions = List.of();
|
||||
}
|
||||
|
||||
return ApiResponse.success(permissions);
|
||||
} catch (Exception e) {
|
||||
// 如果获取权限失败,返回空列表
|
||||
return ApiResponse.success(List.of());
|
||||
}
|
||||
}
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.menu.CreateMenuDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.menu.UpdateMenuDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.vo.MenuVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.service.MenuService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 菜单管理控制器
|
||||
*/
|
||||
@Tag(name = "菜单管理", description = "菜单的增删改查接口")
|
||||
@RestController
|
||||
@RequestMapping("/menu")
|
||||
public class MenuController {
|
||||
|
||||
private final MenuService menuService;
|
||||
|
||||
public MenuController(MenuService menuService) {
|
||||
this.menuService = menuService;
|
||||
}
|
||||
|
||||
@Operation(summary = "创建菜单", description = "创建新的菜单")
|
||||
@PostMapping("/create")
|
||||
public ApiResponse<MenuVO> createMenu(@Valid @RequestBody CreateMenuDTO createMenuDTO) {
|
||||
MenuVO menuVO = menuService.createMenu(createMenuDTO);
|
||||
return ApiResponse.success(menuVO);
|
||||
}
|
||||
|
||||
@Operation(summary = "更新菜单", description = "更新现有菜单信息")
|
||||
@PutMapping("/update/{id}")
|
||||
public ApiResponse<MenuVO> updateMenu(@Valid @RequestBody UpdateMenuDTO updateMenuDTO,
|
||||
@PathVariable Long id) {
|
||||
MenuVO menuVO = menuService.updateMenu(updateMenuDTO, id);
|
||||
return ApiResponse.success(menuVO);
|
||||
}
|
||||
|
||||
@Operation(summary = "删除菜单", description = "删除指定菜单")
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public ApiResponse<Void> deleteMenu(
|
||||
@Parameter(description = "菜单ID") @PathVariable Long id) {
|
||||
menuService.deleteMenu(id);
|
||||
return ApiResponse.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "获取菜单树", description = "获取完整的菜单树结构")
|
||||
@GetMapping("/tree")
|
||||
public ApiResponse<List<MenuVO>> getMenuTree() {
|
||||
List<MenuVO> menuTree = menuService.getMenuTree();
|
||||
return ApiResponse.success(menuTree);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取所有菜单", description = "获取所有菜单的列表")
|
||||
@GetMapping("/list")
|
||||
public ApiResponse<List<MenuVO>> getAllMenus() {
|
||||
List<MenuVO> menuList = menuService.getAllMenus();
|
||||
return ApiResponse.success(menuList);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取菜单详情", description = "根据ID获取菜单详细信息")
|
||||
@GetMapping("/detail/{id}")
|
||||
public ApiResponse<MenuVO> getMenuDetail(
|
||||
@Parameter(description = "菜单ID") @PathVariable Long id) {
|
||||
MenuVO menuVO = menuService.getMenuDetail(id);
|
||||
return ApiResponse.success(menuVO);
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.permission.CreatePermissionDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.permission.PermissionFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.permission.UpdatePermissionDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.vo.PermissionVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.service.PermissionService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 权限管理控制器
|
||||
*/
|
||||
@Tag(name = "权限管理", description = "权限的增删改查接口")
|
||||
@RestController
|
||||
@RequestMapping("/permission")
|
||||
public class PermissionController {
|
||||
|
||||
private final PermissionService permissionService;
|
||||
|
||||
public PermissionController(PermissionService permissionService) {
|
||||
this.permissionService = permissionService;
|
||||
}
|
||||
|
||||
@Operation(summary = "创建权限", description = "创建新的权限")
|
||||
@PostMapping("/create")
|
||||
public ApiResponse<PermissionVO> createPermission(@Valid @RequestBody CreatePermissionDTO createPermissionDTO) {
|
||||
PermissionVO permissionVO = permissionService.createPermission(createPermissionDTO);
|
||||
return ApiResponse.success(permissionVO);
|
||||
}
|
||||
|
||||
@Operation(summary = "更新权限", description = "更新现有权限信息")
|
||||
@PutMapping("/update/{id}")
|
||||
public ApiResponse<PermissionVO> updatePermission(@Valid @RequestBody UpdatePermissionDTO updatePermissionDTO,
|
||||
@PathVariable Long id) {
|
||||
PermissionVO permissionVO = permissionService.updatePermission(updatePermissionDTO, id);
|
||||
return ApiResponse.success(permissionVO);
|
||||
}
|
||||
|
||||
@Operation(summary = "删除权限", description = "删除指定权限")
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public ApiResponse<Void> deletePermission(
|
||||
@Parameter(description = "权限ID") @PathVariable Long id) {
|
||||
permissionService.deletePermission(id);
|
||||
return ApiResponse.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "分页获取权限列表", description = "根据条件分页获取权限列表")
|
||||
@PostMapping("/page")
|
||||
public ApiResponse<PageResultVO<PermissionVO>> getPermissionPage(
|
||||
@Valid @RequestBody PageQueryDTO<PermissionFilterDTO> filterDTO) {
|
||||
PageResultVO<PermissionVO> pageResult = permissionService.getPermissionPage(filterDTO);
|
||||
return ApiResponse.success(pageResult);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取权限详情", description = "根据ID获取权限详细信息")
|
||||
@GetMapping("/detail/{id}")
|
||||
public ApiResponse<PermissionVO> getPermissionDetail(
|
||||
@Parameter(description = "权限ID") @PathVariable Long id) {
|
||||
PermissionVO permissionVO = permissionService.getPermissionDetail(id);
|
||||
return ApiResponse.success(permissionVO);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取所有权限", description = "获取所有启用的权限列表")
|
||||
@GetMapping("/list")
|
||||
public ApiResponse<List<PermissionVO>> getAllPermissions() {
|
||||
List<PermissionVO> permissionList = permissionService.getAllPermissions();
|
||||
return ApiResponse.success(permissionList);
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.ChangePasswordDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.UpdateUserInfoDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.vo.UserVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.service.UserService;
|
||||
|
||||
/**
|
||||
* 用户管理控制器
|
||||
*/
|
||||
@Tag(name = "用户管理", description = "用户信息管理相关接口")
|
||||
@RestController
|
||||
@RequestMapping("/user")
|
||||
public class UserController {
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
public UserController(UserService userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@Operation(summary = "获取用户信息", description = "获取当前登录用户的详细信息")
|
||||
@GetMapping("/info")
|
||||
public ApiResponse<UserVO> getUserInfo() {
|
||||
UserVO userVO = userService.getCurrentUserInfo();
|
||||
return ApiResponse.success(userVO);
|
||||
}
|
||||
|
||||
@Operation(summary = "更新用户信息", description = "更新当前登录用户的基本信息")
|
||||
@PutMapping("/info")
|
||||
public ApiResponse<UserVO> updateUserInfo(@Valid @RequestBody UpdateUserInfoDTO updateUserInfoDTO) {
|
||||
UserVO userVO = userService.updateCurrentUserInfo(updateUserInfoDTO);
|
||||
return ApiResponse.success(userVO);
|
||||
}
|
||||
|
||||
@Operation(summary = "修改密码", description = "修改当前登录用户的密码")
|
||||
@PostMapping("/change-password")
|
||||
public ApiResponse<Void> changePassword(@Valid @RequestBody ChangePasswordDTO changePasswordDTO) {
|
||||
userService.changePassword(changePasswordDTO);
|
||||
return ApiResponse.success();
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.po.MenuPO;
|
||||
|
||||
/**
|
||||
* 系统菜单Mapper
|
||||
*/
|
||||
@Mapper
|
||||
public interface MenuMapper extends BaseMapper<MenuPO> {
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.po.MenuPermissionPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.vo.MenuPermissionVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 菜单权限关联Mapper接口
|
||||
*/
|
||||
@Mapper
|
||||
public interface MenuPermissionMapper extends BaseMapper<MenuPermissionPO> {
|
||||
|
||||
/**
|
||||
* 根据菜单ID查询权限列表
|
||||
*
|
||||
* @param menuId 菜单ID
|
||||
* @return 权限列表
|
||||
*/
|
||||
List<MenuPermissionVO> selectPermissionsByMenuId(@Param("menuId") Long menuId);
|
||||
|
||||
/**
|
||||
* 根据菜单ID列表查询权限列表
|
||||
*
|
||||
* @param menuIds 菜单ID列表
|
||||
* @return 权限列表
|
||||
*/
|
||||
List<MenuPermissionVO> selectPermissionsByMenuIds(@Param("menuIds") List<Long> menuIds);
|
||||
|
||||
/**
|
||||
* 根据权限ID查询菜单列表
|
||||
*
|
||||
* @param permissionId 权限ID
|
||||
* @return 菜单列表
|
||||
*/
|
||||
List<MenuPermissionVO> selectMenusByPermissionId(@Param("permissionId") Long permissionId);
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.po.PermissionPO;
|
||||
|
||||
/**
|
||||
* 权限Mapper接口
|
||||
*/
|
||||
@Mapper
|
||||
public interface PermissionMapper extends BaseMapper<PermissionPO> {
|
||||
|
||||
/**
|
||||
* 分页查询权限列表
|
||||
*
|
||||
* @param page 分页参数
|
||||
* @param code 权限码
|
||||
* @param name 权限名称
|
||||
* @param type 权限类型
|
||||
* @param status 状态
|
||||
* @return 分页结果
|
||||
*/
|
||||
IPage<PermissionPO> selectPermissionPage(Page<PermissionPO> page,
|
||||
@Param("code") String code,
|
||||
@Param("name") String name,
|
||||
@Param("type") String type,
|
||||
@Param("status") Integer status);
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.po.UserPO;
|
||||
|
||||
/**
|
||||
* 系统用户Mapper接口
|
||||
*/
|
||||
@Mapper
|
||||
public interface UserMapper extends BaseMapper<UserPO> {
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.model.dto.menu;
|
||||
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 批量分配菜单权限DTO
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class BatchAssignMenuPermissionDTO {
|
||||
|
||||
/**
|
||||
* 菜单ID
|
||||
*/
|
||||
@NotNull(message = "菜单ID不能为空")
|
||||
private Long menuId;
|
||||
|
||||
/**
|
||||
* 权限ID列表
|
||||
*/
|
||||
@NotEmpty(message = "权限列表不能为空")
|
||||
private List<Long> permissionIds;
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.model.dto.menu;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 创建菜单DTO
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class CreateMenuDTO {
|
||||
|
||||
/**
|
||||
* 父菜单ID
|
||||
*/
|
||||
private Long parentId;
|
||||
|
||||
/**
|
||||
* 菜单名称
|
||||
*/
|
||||
@NotBlank(message = "菜单名称不能为空")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 菜单标题
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 路由路径
|
||||
*/
|
||||
private String path;
|
||||
|
||||
/**
|
||||
* 页面组件
|
||||
*/
|
||||
private String component;
|
||||
|
||||
/**
|
||||
* 重定向地址
|
||||
*/
|
||||
private String redirect;
|
||||
|
||||
/**
|
||||
* 路由图标
|
||||
*/
|
||||
private String icon;
|
||||
|
||||
/**
|
||||
* 顺序
|
||||
*/
|
||||
private Integer order;
|
||||
|
||||
/**
|
||||
* 菜单类型 (catalog-目录,menu-菜单,button-按钮,embedded-内联,link-外链)
|
||||
*/
|
||||
@NotBlank(message = "菜单类型不能为空")
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 是否显示在菜单中 (0-否 1-是)
|
||||
*/
|
||||
private Integer visible;
|
||||
|
||||
/**
|
||||
* 状态 (0-禁用 1-启用)
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 是否缓存
|
||||
*/
|
||||
private Integer keepAlive;
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.model.dto.menu;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 更新菜单DTO
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class UpdateMenuDTO {
|
||||
|
||||
/**
|
||||
* 父菜单ID
|
||||
*/
|
||||
private Long parentId;
|
||||
|
||||
/**
|
||||
* 菜单名称
|
||||
*/
|
||||
@NotBlank(message = "菜单名称不能为空")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 菜单标题
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 路由路径
|
||||
*/
|
||||
private String path;
|
||||
|
||||
/**
|
||||
* 页面组件
|
||||
*/
|
||||
private String component;
|
||||
|
||||
/**
|
||||
* 重定向地址
|
||||
*/
|
||||
private String redirect;
|
||||
|
||||
/**
|
||||
* 路由图标
|
||||
*/
|
||||
private String icon;
|
||||
|
||||
/**
|
||||
* 顺序
|
||||
*/
|
||||
private Integer order;
|
||||
|
||||
/**
|
||||
* 菜单类型 (catalog-目录,menu-菜单,button-按钮,embedded-内联,link-外链)
|
||||
*/
|
||||
@NotBlank(message = "菜单类型不能为空")
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 是否显示在菜单中 (0-否 1-是)
|
||||
*/
|
||||
private Integer visible;
|
||||
|
||||
/**
|
||||
* 状态 (0-禁用 1-启用)
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 是否缓存
|
||||
*/
|
||||
private Integer keepAlive;
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.model.dto.permission;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 创建权限DTO
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class CreatePermissionDTO {
|
||||
|
||||
/**
|
||||
* 权限码(唯一标识,如 user:add, order:approve)
|
||||
*/
|
||||
@NotBlank(message = "权限码不能为空")
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 权限名称(用于显示,如 用户新增、订单审核)
|
||||
*/
|
||||
@NotBlank(message = "权限名称不能为空")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 权限类型(api-接口权限,button-按钮权限,data-数据权限)
|
||||
*/
|
||||
@NotBlank(message = "权限类型不能为空")
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 状态:1-启用 0-禁用
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.model.dto.permission;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 权限过滤DTO
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class PermissionFilterDTO {
|
||||
|
||||
/**
|
||||
* 权限码
|
||||
*/
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 权限名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 权限类型
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private Integer status;
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.model.dto.permission;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 更新权限DTO
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class UpdatePermissionDTO {
|
||||
|
||||
/**
|
||||
* 权限码(唯一标识,如 user:add, order:approve)
|
||||
*/
|
||||
@NotBlank(message = "权限码不能为空")
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 权限名称(用于显示,如 用户新增、订单审核)
|
||||
*/
|
||||
@NotBlank(message = "权限名称不能为空")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 权限类型(api-接口权限,button-按钮权限,data-数据权限)
|
||||
*/
|
||||
@NotBlank(message = "权限类型不能为空")
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 状态:1-启用 0-禁用
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.model.dto.user;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 修改密码DTO
|
||||
*/
|
||||
@Data
|
||||
public class ChangePasswordDTO {
|
||||
|
||||
/**
|
||||
* 旧密码
|
||||
*/
|
||||
@NotBlank(message = "旧密码不能为空")
|
||||
private String oldPassword;
|
||||
|
||||
/**
|
||||
* 新密码
|
||||
*/
|
||||
@NotBlank(message = "新密码不能为空")
|
||||
// @Pattern(regexp = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)[a-zA-Z\\d@$!%*?&]{8,}$",
|
||||
// message = "密码必须包含大小写字母和数字,长度至少8位")
|
||||
private String newPassword;
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.model.dto.user;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 用户登录DTO
|
||||
*/
|
||||
@Data
|
||||
public class LoginDTO {
|
||||
|
||||
/**
|
||||
* 登录账号(可以是loginCode或phone)
|
||||
*/
|
||||
@NotBlank(message = "登录账号不能为空")
|
||||
private String account;
|
||||
|
||||
/**
|
||||
* 登录密码
|
||||
*/
|
||||
@NotBlank(message = "密码不能为空")
|
||||
private String password;
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.model.dto.user;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 用户注册DTO
|
||||
*/
|
||||
@Data
|
||||
public class RegisterDTO {
|
||||
|
||||
/**
|
||||
* 登录账号
|
||||
*/
|
||||
private String loginCode;
|
||||
|
||||
/**
|
||||
* 手机号码
|
||||
*/
|
||||
@Pattern(regexp = "^(|1[3-9]\\d{9})$", message = "手机号码格式不正确")
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
* 登录密码
|
||||
*/
|
||||
@NotBlank(message = "密码不能为空")
|
||||
// @Pattern(regexp = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)[a-zA-Z\\d@$!%*?&]{8,}$",
|
||||
// message = "密码必须包含大小写字母和数字,长度至少8位")
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 验证登录账号和手机号码至少填写一个
|
||||
*/
|
||||
public boolean isValid() {
|
||||
return (loginCode != null && !loginCode.trim().isEmpty()) ||
|
||||
(phone != null && !phone.trim().isEmpty());
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.model.dto.user;
|
||||
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 更新用户信息DTO
|
||||
*/
|
||||
@Data
|
||||
public class UpdateUserInfoDTO {
|
||||
|
||||
/**
|
||||
* 用户名称
|
||||
*/
|
||||
private String realName;
|
||||
|
||||
/**
|
||||
* 头像路径
|
||||
*/
|
||||
private String avatar;
|
||||
|
||||
/**
|
||||
* 手机号码
|
||||
*/
|
||||
@Pattern(regexp = "^(|1[3-9]\\d{9})$", message = "手机号码格式不正确")
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
* 备注信息
|
||||
*/
|
||||
private String remark;
|
||||
}
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.model.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 系统菜单实体
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("sys_menu")
|
||||
public class MenuPO {
|
||||
|
||||
/**
|
||||
* 菜单ID
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.ASSIGN_ID)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 父菜单ID
|
||||
*/
|
||||
@TableField("parent_id")
|
||||
private Long parentId;
|
||||
|
||||
/**
|
||||
* 菜单名称
|
||||
*/
|
||||
@TableField("name")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 菜单标题
|
||||
*/
|
||||
@TableField("title")
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 路由路径
|
||||
*/
|
||||
@TableField("path")
|
||||
private String path;
|
||||
|
||||
/**
|
||||
* 页面组件
|
||||
*/
|
||||
@TableField("component")
|
||||
private String component;
|
||||
|
||||
/**
|
||||
* 重定向地址
|
||||
*/
|
||||
@TableField("redirect")
|
||||
private String redirect;
|
||||
|
||||
/**
|
||||
* 路由图标
|
||||
*/
|
||||
@TableField("icon")
|
||||
private String icon;
|
||||
|
||||
/**
|
||||
* 顺序
|
||||
*/
|
||||
@TableField("`order`")
|
||||
private Integer order;
|
||||
|
||||
/**
|
||||
* 菜单类型 (目录,菜单,按钮,内联,外链)
|
||||
*/
|
||||
@TableField("type")
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 是否显示在菜单中 (0-否 1-是)
|
||||
*/
|
||||
@TableField("visible")
|
||||
private Integer visible;
|
||||
|
||||
/**
|
||||
* 状态 (0-禁用 1-启用)
|
||||
*/
|
||||
@TableField("status")
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 是否缓存
|
||||
*/
|
||||
@TableField("keep_alive")
|
||||
private Integer keepAlive;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 创建人ID
|
||||
*/
|
||||
@TableField("create_by")
|
||||
private Long createBy;
|
||||
|
||||
/**
|
||||
* 更新人ID
|
||||
*/
|
||||
@TableField("update_by")
|
||||
private Long updateBy;
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.model.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 菜单与权限关联实体
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("rel_menu_permission")
|
||||
public class MenuPermissionPO {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 菜单ID
|
||||
*/
|
||||
@TableField("menu_id")
|
||||
private Long menuId;
|
||||
|
||||
/**
|
||||
* 权限ID
|
||||
*/
|
||||
@TableField("permission_id")
|
||||
private Long permissionId;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 创建人ID
|
||||
*/
|
||||
@TableField("create_by")
|
||||
private Long createBy;
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.model.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 系统权限实体
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("sys_permission")
|
||||
public class PermissionPO {
|
||||
|
||||
/**
|
||||
* 权限ID
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 权限码(唯一标识,如 user:add, order:approve)
|
||||
*/
|
||||
@TableField("code")
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 权限名称(用于显示,如 用户新增、订单审核)
|
||||
*/
|
||||
@TableField("name")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 权限类型(api-接口权限,button-按钮权限,data-数据权限)
|
||||
*/
|
||||
@TableField("type")
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 状态:1-启用 0-禁用
|
||||
*/
|
||||
@TableField("status")
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@TableField("remark")
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 创建人ID
|
||||
*/
|
||||
@TableField("create_by")
|
||||
private Long createBy;
|
||||
|
||||
/**
|
||||
* 更新人ID
|
||||
*/
|
||||
@TableField("update_by")
|
||||
private Long updateBy;
|
||||
}
|
||||
+148
@@ -0,0 +1,148 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.model.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 系统用户实体
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("sys_user")
|
||||
public class UserPO {
|
||||
|
||||
/**
|
||||
* 用户编号
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.ASSIGN_ID)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 公司id
|
||||
*/
|
||||
@TableField("company_id")
|
||||
private Long companyId;
|
||||
|
||||
/**
|
||||
* 部门id
|
||||
*/
|
||||
@TableField("department_id")
|
||||
private Long departmentId;
|
||||
|
||||
/**
|
||||
* 岗位id
|
||||
*/
|
||||
@TableField("position_id")
|
||||
private Long positionId;
|
||||
|
||||
/**
|
||||
* 登录账号
|
||||
*/
|
||||
@TableField("login_code")
|
||||
private String loginCode;
|
||||
|
||||
/**
|
||||
* 登录密码
|
||||
*/
|
||||
@TableField("password")
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 手机号码
|
||||
*/
|
||||
@TableField("phone")
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
* 用户名称
|
||||
*/
|
||||
@TableField("real_name")
|
||||
private String realName;
|
||||
|
||||
/**
|
||||
* 头像路径
|
||||
*/
|
||||
@TableField("avatar")
|
||||
private String avatar;
|
||||
|
||||
/**
|
||||
* 关联角色(user-普通账户 admin-公司管理员账户 super-超管账户)
|
||||
*/
|
||||
@TableField("role")
|
||||
private String role;
|
||||
|
||||
/**
|
||||
* 密码安全级别(0-初始 1-很弱 2-弱 3-安全 4-很安全)
|
||||
*/
|
||||
@TableField("pwd_security_level")
|
||||
private Integer pwdSecurityLevel;
|
||||
|
||||
/**
|
||||
* 密码最后更新时间
|
||||
*/
|
||||
@TableField("pwd_update_time")
|
||||
private LocalDateTime pwdUpdateTime;
|
||||
|
||||
/**
|
||||
* 最后登录ip
|
||||
*/
|
||||
@TableField("last_login_ip")
|
||||
private String lastLoginIp;
|
||||
|
||||
/**
|
||||
* 最后登录时间
|
||||
*/
|
||||
@TableField("last_login_date")
|
||||
private LocalDateTime lastLoginDate;
|
||||
|
||||
/**
|
||||
* 冻结时间
|
||||
*/
|
||||
@TableField("freeze_date")
|
||||
private LocalDateTime freezeDate;
|
||||
|
||||
/**
|
||||
* 冻结原因
|
||||
*/
|
||||
@TableField("freeze_cause")
|
||||
private String freezeCause;
|
||||
|
||||
/**
|
||||
* 状态(0-正常 1-删除 2-停用 3-冻结)
|
||||
*/
|
||||
@TableField("status")
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 备注信息
|
||||
*/
|
||||
@TableField("remark")
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 创建者
|
||||
*/
|
||||
@TableField("create_by")
|
||||
private Long createBy;
|
||||
|
||||
/**
|
||||
* 更新者
|
||||
*/
|
||||
@TableField("update_by")
|
||||
private Long updateBy;
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.model.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 登录响应VO
|
||||
*/
|
||||
@Data
|
||||
public class LoginVO {
|
||||
|
||||
/**
|
||||
* JWT令牌
|
||||
*/
|
||||
private String token;
|
||||
|
||||
/**
|
||||
* 用户信息
|
||||
*/
|
||||
private UserVO user;
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.model.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 菜单权限关联VO
|
||||
*/
|
||||
@Data
|
||||
public class MenuPermissionVO {
|
||||
|
||||
/**
|
||||
* 关联ID
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 菜单ID
|
||||
*/
|
||||
private Long menuId;
|
||||
|
||||
/**
|
||||
* 菜单名称
|
||||
*/
|
||||
private String menuName;
|
||||
|
||||
/**
|
||||
* 菜单标题
|
||||
*/
|
||||
private String menuTitle;
|
||||
|
||||
/**
|
||||
* 权限ID
|
||||
*/
|
||||
private Long permissionId;
|
||||
|
||||
/**
|
||||
* 权限码
|
||||
*/
|
||||
private String permissionCode;
|
||||
|
||||
/**
|
||||
* 权限名称
|
||||
*/
|
||||
private String permissionName;
|
||||
|
||||
/**
|
||||
* 权限类型
|
||||
*/
|
||||
private String permissionType;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.model.vo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 菜单VO
|
||||
*/
|
||||
@Data
|
||||
@ToString(exclude = "children")
|
||||
@EqualsAndHashCode(exclude = "children")
|
||||
public class MenuVO {
|
||||
|
||||
/**
|
||||
* 菜单ID
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 父菜单ID
|
||||
*/
|
||||
private Long parentId;
|
||||
|
||||
/**
|
||||
* 菜单名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 菜单标题
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 路由路径
|
||||
*/
|
||||
private String path;
|
||||
|
||||
/**
|
||||
* 页面组件
|
||||
*/
|
||||
private String component;
|
||||
|
||||
/**
|
||||
* 重定向地址
|
||||
*/
|
||||
private String redirect;
|
||||
|
||||
/**
|
||||
* 路由图标
|
||||
*/
|
||||
private String icon;
|
||||
|
||||
/**
|
||||
* 顺序
|
||||
*/
|
||||
private Integer order;
|
||||
|
||||
/**
|
||||
* 菜单类型 (catalog-目录,menu-菜单,button-按钮,embedded-内联,link-外链)
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 是否显示在菜单中 (0-否 1-是)
|
||||
*/
|
||||
private Integer visible;
|
||||
|
||||
/**
|
||||
* 状态 (0-禁用 1-启用)
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 是否缓存
|
||||
*/
|
||||
private Integer keepAlive;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 子菜单列表
|
||||
*/
|
||||
private List<MenuVO> children;
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.model.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 权限VO
|
||||
*/
|
||||
@Data
|
||||
public class PermissionVO {
|
||||
|
||||
/**
|
||||
* 权限ID
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 权限码(唯一标识,如 user:add, order:approve)
|
||||
*/
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 权限名称(用于显示,如 用户新增、订单审核)
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 权限类型(api-接口权限,button-按钮权限,data-数据权限)
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 状态:1-启用 0-禁用
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.model.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 用户信息VO
|
||||
*/
|
||||
@Data
|
||||
public class UserVO {
|
||||
|
||||
/**
|
||||
* 用户编号
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 公司id
|
||||
*/
|
||||
private Long companyId;
|
||||
|
||||
/**
|
||||
* 部门id
|
||||
*/
|
||||
private Long departmentId;
|
||||
|
||||
/**
|
||||
* 岗位id
|
||||
*/
|
||||
private Long positionId;
|
||||
|
||||
/**
|
||||
* 登录账号
|
||||
*/
|
||||
private String loginCode;
|
||||
|
||||
/**
|
||||
* 手机号码
|
||||
*/
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
* 用户名称
|
||||
*/
|
||||
private String realName;
|
||||
|
||||
/**
|
||||
* 头像路径
|
||||
*/
|
||||
private String avatar;
|
||||
|
||||
/**
|
||||
* 关联角色(user-普通账户 company-公司账户 super-超管账户)
|
||||
*/
|
||||
private String role;
|
||||
|
||||
/**
|
||||
* 密码安全级别(0-初始 1-很弱 2-弱 3-安全 4-很安全)
|
||||
*/
|
||||
private Integer pwdSecurityLevel;
|
||||
|
||||
/**
|
||||
* 密码最后更新时间
|
||||
*/
|
||||
private LocalDateTime pwdUpdateTime;
|
||||
|
||||
/**
|
||||
* 最后登录ip
|
||||
*/
|
||||
private String lastLoginIp;
|
||||
|
||||
/**
|
||||
* 最后登录时间
|
||||
*/
|
||||
private LocalDateTime lastLoginDate;
|
||||
|
||||
/**
|
||||
* 冻结时间
|
||||
*/
|
||||
private LocalDateTime freezeDate;
|
||||
|
||||
/**
|
||||
* 冻结原因
|
||||
*/
|
||||
private String freezeCause;
|
||||
|
||||
/**
|
||||
* 状态(0-正常 1-删除 2-停用 3-冻结)
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 备注信息
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.service;
|
||||
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.menu.BatchAssignMenuPermissionDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.vo.MenuPermissionVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 菜单权限关联服务接口
|
||||
*/
|
||||
public interface MenuPermissionService {
|
||||
|
||||
/**
|
||||
* 批量分配菜单权限
|
||||
*
|
||||
* @param batchAssignDTO 批量分配DTO
|
||||
*/
|
||||
void batchAssignMenuPermissions(BatchAssignMenuPermissionDTO batchAssignDTO);
|
||||
|
||||
/**
|
||||
* 取消菜单权限
|
||||
*
|
||||
* @param menuId 菜单ID
|
||||
* @param permissionId 权限ID
|
||||
*/
|
||||
void removeMenuPermission(Long menuId, Long permissionId);
|
||||
|
||||
/**
|
||||
* 根据菜单ID查询权限列表
|
||||
*
|
||||
* @param menuId 菜单ID
|
||||
* @return 权限列表
|
||||
*/
|
||||
List<MenuPermissionVO> getPermissionsByMenuId(Long menuId);
|
||||
|
||||
/**
|
||||
* 根据菜单ID列表查询权限列表
|
||||
*
|
||||
* @param menuIds 菜单ID列表
|
||||
* @return 权限列表
|
||||
*/
|
||||
List<MenuPermissionVO> getPermissionsByMenuIds(List<Long> menuIds);
|
||||
|
||||
/**
|
||||
* 根据权限ID查询菜单列表
|
||||
*
|
||||
* @param permissionId 权限ID
|
||||
* @return 菜单列表
|
||||
*/
|
||||
List<MenuPermissionVO> getMenusByPermissionId(Long permissionId);
|
||||
|
||||
/**
|
||||
* 检查菜单是否有指定权限
|
||||
*
|
||||
* @param menuId 菜单ID
|
||||
* @param permissionId 权限ID
|
||||
* @return 是否有权限
|
||||
*/
|
||||
boolean hasMenuPermission(Long menuId, Long permissionId);
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.menu.CreateMenuDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.menu.UpdateMenuDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.po.MenuPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.vo.MenuVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 系统菜单服务接口
|
||||
*/
|
||||
public interface MenuService extends IService<MenuPO> {
|
||||
|
||||
/**
|
||||
* 创建菜单
|
||||
*
|
||||
* @param createMenuDTO 创建菜单信息
|
||||
* @return 菜单信息
|
||||
*/
|
||||
MenuVO createMenu(CreateMenuDTO createMenuDTO);
|
||||
|
||||
/**
|
||||
* 更新菜单
|
||||
*
|
||||
* @param updateMenuDTO 更新菜单信息
|
||||
* @return 菜单信息
|
||||
*/
|
||||
MenuVO updateMenu(UpdateMenuDTO updateMenuDTO, Long id);
|
||||
|
||||
/**
|
||||
* 删除菜单
|
||||
*
|
||||
* @param id 菜单ID
|
||||
*/
|
||||
void deleteMenu(Long id);
|
||||
|
||||
/**
|
||||
* 获取菜单树
|
||||
*
|
||||
* @return 菜单树列表
|
||||
*/
|
||||
List<MenuVO> getMenuTree();
|
||||
|
||||
/**
|
||||
* 获取所有菜单
|
||||
*
|
||||
* @return 菜单列表
|
||||
*/
|
||||
List<MenuVO> getAllMenus();
|
||||
|
||||
/**
|
||||
* 获取菜单详情
|
||||
*
|
||||
* @param id 菜单ID
|
||||
* @return 菜单详情
|
||||
*/
|
||||
MenuVO getMenuDetail(Long id);
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.service;
|
||||
|
||||
/**
|
||||
* 权限检查服务接口
|
||||
* 专门用于权限验证
|
||||
*/
|
||||
public interface PermissionCheckService {
|
||||
|
||||
/**
|
||||
* 根据岗位ID检查是否有指定权限
|
||||
*
|
||||
* @param positionId 岗位ID
|
||||
* @param permissionCode 权限码
|
||||
* @param companyId 公司ID
|
||||
* @return 是否有权限
|
||||
*/
|
||||
boolean hasPermissionByPosition(Long positionId, String permissionCode, Long companyId);
|
||||
|
||||
/**
|
||||
* 获取岗位的所有权限码
|
||||
*
|
||||
* @param positionId 岗位ID
|
||||
* @param companyId 公司ID
|
||||
* @return 权限码列表
|
||||
*/
|
||||
java.util.List<String> getPositionPermissions(Long positionId, Long companyId);
|
||||
|
||||
/**
|
||||
* 根据用户角色检查是否有权限
|
||||
*
|
||||
* @param role 用户角色 (super/company/user)
|
||||
* @param permissionCode 权限码
|
||||
* @param positionId 岗位ID (仅user角色需要)
|
||||
* @param companyId 公司ID
|
||||
* @return 是否有权限
|
||||
*/
|
||||
boolean hasPermissionByRole(String role, String permissionCode, Long positionId, Long companyId);
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.service;
|
||||
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.permission.CreatePermissionDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.permission.PermissionFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.permission.UpdatePermissionDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.vo.PermissionVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 权限服务接口
|
||||
*/
|
||||
public interface PermissionService {
|
||||
|
||||
/**
|
||||
* 创建权限
|
||||
*
|
||||
* @param createPermissionDTO 创建权限DTO
|
||||
* @return 权限VO
|
||||
*/
|
||||
PermissionVO createPermission(CreatePermissionDTO createPermissionDTO);
|
||||
|
||||
/**
|
||||
* 更新权限
|
||||
*
|
||||
* @param updatePermissionDTO 更新权限DTO
|
||||
* @param id 权限ID
|
||||
* @return 权限VO
|
||||
*/
|
||||
PermissionVO updatePermission(UpdatePermissionDTO updatePermissionDTO, Long id);
|
||||
|
||||
/**
|
||||
* 删除权限
|
||||
*
|
||||
* @param id 权限ID
|
||||
*/
|
||||
void deletePermission(Long id);
|
||||
|
||||
/**
|
||||
* 分页获取权限列表
|
||||
*
|
||||
* @param filterDTO 过滤条件
|
||||
* @return 分页结果
|
||||
*/
|
||||
PageResultVO<PermissionVO> getPermissionPage(PageQueryDTO<PermissionFilterDTO> filterDTO);
|
||||
|
||||
/**
|
||||
* 获取权限详情
|
||||
*
|
||||
* @param id 权限ID
|
||||
* @return 权限VO
|
||||
*/
|
||||
PermissionVO getPermissionDetail(Long id);
|
||||
|
||||
/**
|
||||
* 获取所有权限列表
|
||||
*
|
||||
* @return 权限列表
|
||||
*/
|
||||
List<PermissionVO> getAllPermissions();
|
||||
|
||||
/**
|
||||
* 根据岗位ID检查是否有指定权限
|
||||
*
|
||||
* @param positionId 岗位ID
|
||||
* @param permissionCode 权限码
|
||||
* @param companyId 公司ID
|
||||
* @return 是否有权限
|
||||
*/
|
||||
boolean hasPermissionByPosition(Long positionId, String permissionCode, Long companyId);
|
||||
|
||||
/**
|
||||
* 获取岗位的所有权限码
|
||||
*
|
||||
* @param positionId 岗位ID
|
||||
* @param companyId 公司ID
|
||||
* @return 权限码列表
|
||||
*/
|
||||
List<String> getPositionPermissions(Long positionId, Long companyId);
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.ChangePasswordDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.LoginDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.RegisterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.UpdateUserInfoDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.po.UserPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.vo.LoginVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.vo.UserVO;
|
||||
|
||||
/**
|
||||
* 系统用户服务接口
|
||||
*/
|
||||
public interface UserService extends IService<UserPO> {
|
||||
|
||||
/**
|
||||
* 用户注册
|
||||
*
|
||||
* @param registerDTO 注册信息
|
||||
* @return 登录响应
|
||||
*/
|
||||
LoginVO register(RegisterDTO registerDTO);
|
||||
|
||||
/**
|
||||
* 用户登录
|
||||
*
|
||||
* @param loginDTO 登录信息
|
||||
* @return 登录响应
|
||||
*/
|
||||
LoginVO login(LoginDTO loginDTO);
|
||||
|
||||
/**
|
||||
* 根据登录账号或手机号查询用户
|
||||
*
|
||||
* @param account 登录账号或手机号
|
||||
* @return 用户信息
|
||||
*/
|
||||
UserPO findByAccount(String account);
|
||||
|
||||
/**
|
||||
* 获取当前登录用户信息
|
||||
*
|
||||
* @return 用户信息
|
||||
*/
|
||||
UserVO getCurrentUserInfo();
|
||||
|
||||
/**
|
||||
* 更新当前登录用户信息
|
||||
*
|
||||
* @param updateUserInfoDTO 更新信息
|
||||
* @return 更新后的用户信息
|
||||
*/
|
||||
UserVO updateCurrentUserInfo(UpdateUserInfoDTO updateUserInfoDTO);
|
||||
|
||||
/**
|
||||
* 修改当前登录用户密码
|
||||
*
|
||||
* @param changePasswordDTO 密码信息
|
||||
*/
|
||||
void changePassword(ChangePasswordDTO changePasswordDTO);
|
||||
}
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.mapper.MenuPermissionMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.menu.BatchAssignMenuPermissionDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.po.MenuPermissionPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.vo.MenuPermissionVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.service.MenuPermissionService;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 菜单权限关联服务实现类
|
||||
*/
|
||||
@Service
|
||||
public class MenuPermissionServiceImpl implements MenuPermissionService {
|
||||
|
||||
private final MenuPermissionMapper menuPermissionMapper;
|
||||
private final CurrentUserContext currentUserContext;
|
||||
|
||||
public MenuPermissionServiceImpl(MenuPermissionMapper menuPermissionMapper,
|
||||
CurrentUserContext currentUserContext) {
|
||||
this.menuPermissionMapper = menuPermissionMapper;
|
||||
this.currentUserContext = currentUserContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void batchAssignMenuPermissions(BatchAssignMenuPermissionDTO batchAssignDTO) {
|
||||
Long menuId = batchAssignDTO.getMenuId();
|
||||
List<Long> permissionIds = batchAssignDTO.getPermissionIds();
|
||||
|
||||
// 先删除该菜单的所有权限
|
||||
LambdaQueryWrapper<MenuPermissionPO> deleteWrapper = new LambdaQueryWrapper<>();
|
||||
deleteWrapper.eq(MenuPermissionPO::getMenuId, menuId);
|
||||
menuPermissionMapper.delete(deleteWrapper);
|
||||
|
||||
// 批量插入新的权限
|
||||
List<MenuPermissionPO> menuPermissions = new ArrayList<>();
|
||||
for (Long permissionId : permissionIds) {
|
||||
MenuPermissionPO menuPermission = new MenuPermissionPO();
|
||||
menuPermission.setMenuId(menuId);
|
||||
menuPermission.setPermissionId(permissionId);
|
||||
menuPermission.setCreateBy(currentUserContext.getCurrentUserId());
|
||||
menuPermissions.add(menuPermission);
|
||||
}
|
||||
|
||||
if (!menuPermissions.isEmpty()) {
|
||||
menuPermissions.forEach(menuPermissionMapper::insert);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeMenuPermission(Long menuId, Long permissionId) {
|
||||
LambdaQueryWrapper<MenuPermissionPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(MenuPermissionPO::getMenuId, menuId)
|
||||
.eq(MenuPermissionPO::getPermissionId, permissionId);
|
||||
|
||||
int result = menuPermissionMapper.delete(wrapper);
|
||||
if (result == 0) {
|
||||
throw new BusinessException("菜单权限关联不存在");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MenuPermissionVO> getPermissionsByMenuId(Long menuId) {
|
||||
return menuPermissionMapper.selectPermissionsByMenuId(menuId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MenuPermissionVO> getPermissionsByMenuIds(List<Long> menuIds) {
|
||||
if (menuIds == null || menuIds.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return menuPermissionMapper.selectPermissionsByMenuIds(menuIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MenuPermissionVO> getMenusByPermissionId(Long permissionId) {
|
||||
return menuPermissionMapper.selectMenusByPermissionId(permissionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMenuPermission(Long menuId, Long permissionId) {
|
||||
LambdaQueryWrapper<MenuPermissionPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(MenuPermissionPO::getMenuId, menuId)
|
||||
.eq(MenuPermissionPO::getPermissionId, permissionId);
|
||||
|
||||
return menuPermissionMapper.selectCount(wrapper) > 0;
|
||||
}
|
||||
}
|
||||
+232
@@ -0,0 +1,232 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.mapper.MenuMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.menu.CreateMenuDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.menu.UpdateMenuDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.po.MenuPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.vo.MenuVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.service.MenuService;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 系统菜单服务实现类
|
||||
*/
|
||||
@Service
|
||||
public class MenuServiceImpl extends ServiceImpl<MenuMapper, MenuPO> implements MenuService {
|
||||
|
||||
private final CurrentUserContext currentUserContext;
|
||||
|
||||
public MenuServiceImpl(CurrentUserContext currentUserContext) {
|
||||
this.currentUserContext = currentUserContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MenuVO createMenu(CreateMenuDTO createMenuDTO) {
|
||||
// 验证父菜单是否存在
|
||||
if (createMenuDTO.getParentId() != null) {
|
||||
MenuPO parentMenu = this.getById(createMenuDTO.getParentId());
|
||||
if (parentMenu == null) {
|
||||
throw new BusinessException("父菜单不存在");
|
||||
}
|
||||
}
|
||||
|
||||
// 检查菜单名称是否重复
|
||||
LambdaQueryWrapper<MenuPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(MenuPO::getName, createMenuDTO.getName());
|
||||
if (this.count(wrapper) > 0) {
|
||||
throw new BusinessException("菜单名称已存在");
|
||||
}
|
||||
|
||||
// 创建菜单
|
||||
MenuPO menu = new MenuPO();
|
||||
BeanUtils.copyProperties(createMenuDTO, menu);
|
||||
|
||||
// 设置默认值
|
||||
if (menu.getVisible() == null) {
|
||||
menu.setVisible(1);
|
||||
}
|
||||
if (menu.getStatus() == null) {
|
||||
menu.setStatus(1);
|
||||
}
|
||||
if (menu.getKeepAlive() == null) {
|
||||
menu.setKeepAlive(0);
|
||||
}
|
||||
if (menu.getOrder() == null) {
|
||||
menu.setOrder(0);
|
||||
}
|
||||
|
||||
// 设置创建人ID
|
||||
menu.setCreateBy(currentUserContext.getCurrentUserId());
|
||||
|
||||
// 保存菜单
|
||||
this.save(menu);
|
||||
|
||||
// 转换为VO并返回
|
||||
return convertToVO(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MenuVO updateMenu(UpdateMenuDTO updateMenuDTO, Long id) {
|
||||
// 检查菜单是否存在
|
||||
MenuPO existingMenu = this.getById(id);
|
||||
if (existingMenu == null) {
|
||||
throw new BusinessException("菜单不存在");
|
||||
}
|
||||
|
||||
// 验证父菜单是否存在(不能设置自己为父菜单)
|
||||
if (updateMenuDTO.getParentId() != null) {
|
||||
if (updateMenuDTO.getParentId().equals(id)) {
|
||||
throw new BusinessException("不能设置自己为父菜单");
|
||||
}
|
||||
MenuPO parentMenu = this.getById(updateMenuDTO.getParentId());
|
||||
if (parentMenu == null) {
|
||||
throw new BusinessException("父菜单不存在");
|
||||
}
|
||||
}
|
||||
|
||||
// 检查菜单名称是否重复(排除自己)
|
||||
LambdaQueryWrapper<MenuPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(MenuPO::getName, updateMenuDTO.getName())
|
||||
.ne(MenuPO::getId, id);
|
||||
if (this.count(wrapper) > 0) {
|
||||
throw new BusinessException("菜单名称已存在");
|
||||
}
|
||||
|
||||
// 更新菜单
|
||||
MenuPO menu = new MenuPO();
|
||||
BeanUtils.copyProperties(updateMenuDTO, menu);
|
||||
|
||||
// 设置更新人ID
|
||||
menu.setUpdateBy(currentUserContext.getCurrentUserId());
|
||||
|
||||
// 保存菜单
|
||||
this.updateById(menu);
|
||||
|
||||
// 转换为VO并返回
|
||||
return convertToVO(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteMenu(Long id) {
|
||||
// 检查菜单是否存在
|
||||
MenuPO menu = this.getById(id);
|
||||
if (menu == null) {
|
||||
throw new BusinessException("菜单不存在");
|
||||
}
|
||||
|
||||
// 检查是否有子菜单
|
||||
LambdaQueryWrapper<MenuPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(MenuPO::getParentId, id);
|
||||
if (this.count(wrapper) > 0) {
|
||||
throw new BusinessException("存在子菜单,无法删除");
|
||||
}
|
||||
|
||||
// 删除菜单
|
||||
this.removeById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MenuVO> getMenuTree() {
|
||||
// 查询所有菜单
|
||||
LambdaQueryWrapper<MenuPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.orderByAsc(MenuPO::getOrder);
|
||||
List<MenuPO> menuList = this.list(wrapper);
|
||||
|
||||
// 转换为VO
|
||||
List<MenuVO> menuVOList = menuList.stream()
|
||||
.map(this::convertToVO)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 构建树形结构
|
||||
return buildMenuTree(menuVOList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MenuVO> getAllMenus() {
|
||||
// 查询所有菜单
|
||||
LambdaQueryWrapper<MenuPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.orderByAsc(MenuPO::getOrder);
|
||||
List<MenuPO> menuList = this.list(wrapper);
|
||||
|
||||
// 转换为VO并返回
|
||||
return menuList.stream()
|
||||
.map(this::convertToVO)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MenuVO getMenuDetail(Long id) {
|
||||
// 根据ID查询菜单
|
||||
MenuPO menuPO = this.getById(id);
|
||||
if (menuPO == null) {
|
||||
throw new RuntimeException("菜单不存在");
|
||||
}
|
||||
|
||||
// 转换为VO并返回
|
||||
return convertToVO(menuPO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建菜单树
|
||||
*/
|
||||
private List<MenuVO> buildMenuTree(List<MenuVO> menuList) {
|
||||
// 按父ID分组
|
||||
Map<Long, List<MenuVO>> parentMap = menuList.stream()
|
||||
.collect(Collectors.groupingBy(menu -> menu.getParentId() != null ? menu.getParentId() : 0L));
|
||||
|
||||
// 递归构建树
|
||||
return buildTreeRecursive(parentMap, 0L, new ArrayList<>(), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归构建树形结构(带循环引用检测)
|
||||
*/
|
||||
private List<MenuVO> buildTreeRecursive(Map<Long, List<MenuVO>> parentMap, Long parentId, List<Long> visitedIds,
|
||||
int depth) {
|
||||
// 防止无限递归,设置最大深度限制
|
||||
if (depth > 100) {
|
||||
throw new BusinessException("菜单层级过深,可能存在循环引用");
|
||||
}
|
||||
|
||||
List<MenuVO> children = parentMap.get(parentId);
|
||||
if (children == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
for (MenuVO menu : children) {
|
||||
// 检查是否已经访问过该节点,防止循环引用
|
||||
if (visitedIds.contains(menu.getId())) {
|
||||
throw new BusinessException("检测到菜单循环引用,菜单ID: " + menu.getId());
|
||||
}
|
||||
|
||||
// 创建新访问路径,包含当前节点
|
||||
List<Long> newVisitedIds = new ArrayList<>(visitedIds);
|
||||
newVisitedIds.add(menu.getId());
|
||||
|
||||
// 递归构建子菜单
|
||||
List<MenuVO> childList = buildTreeRecursive(parentMap, menu.getId(), newVisitedIds, depth + 1);
|
||||
menu.setChildren(childList);
|
||||
}
|
||||
|
||||
return children;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为VO
|
||||
*/
|
||||
private MenuVO convertToVO(MenuPO menu) {
|
||||
MenuVO menuVO = new MenuVO();
|
||||
BeanUtils.copyProperties(menu, menuVO);
|
||||
return menuVO;
|
||||
}
|
||||
}
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.service.impl;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.service.PositionCompanyMenuService;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.model.vo.PositionMenuVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.mapper.MenuPermissionMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.vo.MenuPermissionVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.service.PermissionCheckService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 权限检查服务实现类
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class PermissionCheckServiceImpl implements PermissionCheckService {
|
||||
|
||||
private final PositionCompanyMenuService positionCompanyMenuService;
|
||||
private final MenuPermissionMapper menuPermissionMapper;
|
||||
|
||||
public PermissionCheckServiceImpl(PositionCompanyMenuService positionCompanyMenuService,
|
||||
MenuPermissionMapper menuPermissionMapper) {
|
||||
this.positionCompanyMenuService = positionCompanyMenuService;
|
||||
this.menuPermissionMapper = menuPermissionMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermissionByPosition(Long positionId, String permissionCode, Long companyId) {
|
||||
if (positionId == null || permissionCode == null || companyId == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
List<PositionMenuVO> positionMenus = positionCompanyMenuService.getMenusByPositionId(positionId);
|
||||
if (positionMenus.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
List<Long> menuIds = positionMenus.stream()
|
||||
.map(PositionMenuVO::getCompanyMenuId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<MenuPermissionVO> menuPermissions = menuPermissionMapper.selectPermissionsByMenuIds(menuIds);
|
||||
|
||||
return menuPermissions.stream()
|
||||
.anyMatch(mp -> permissionCode.equals(mp.getPermissionCode()));
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("权限验证异常", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getPositionPermissions(Long positionId, Long companyId) {
|
||||
if (positionId == null || companyId == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
try {
|
||||
List<PositionMenuVO> positionMenus = positionCompanyMenuService.getMenusByPositionId(positionId);
|
||||
if (positionMenus.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
List<Long> menuIds = positionMenus.stream()
|
||||
.map(PositionMenuVO::getCompanyMenuId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<MenuPermissionVO> menuPermissions = menuPermissionMapper.selectPermissionsByMenuIds(menuIds);
|
||||
|
||||
return menuPermissions.stream()
|
||||
.map(MenuPermissionVO::getPermissionCode)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("获取岗位权限异常", e);
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermissionByRole(String role, String permissionCode, Long positionId, Long companyId) {
|
||||
if (role == null || permissionCode == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (role) {
|
||||
case "super":
|
||||
return true;
|
||||
case "company":
|
||||
return true;
|
||||
case "user":
|
||||
if (positionId == null || companyId == null) {
|
||||
return false;
|
||||
}
|
||||
return hasPermissionByPosition(positionId, permissionCode, companyId);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
+185
@@ -0,0 +1,185 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.mapper.PermissionMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.permission.CreatePermissionDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.permission.PermissionFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.permission.UpdatePermissionDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.po.PermissionPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.vo.PermissionVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.service.PermissionService;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.service.PositionCompanyMenuService;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.model.vo.PositionMenuVO;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 权限服务实现类
|
||||
*/
|
||||
@Service
|
||||
public class PermissionServiceImpl implements PermissionService {
|
||||
|
||||
private final PermissionMapper permissionMapper;
|
||||
private final CurrentUserContext currentUserContext;
|
||||
private final PositionCompanyMenuService positionCompanyMenuService;
|
||||
|
||||
public PermissionServiceImpl(PermissionMapper permissionMapper, CurrentUserContext currentUserContext,
|
||||
PositionCompanyMenuService positionCompanyMenuService) {
|
||||
this.permissionMapper = permissionMapper;
|
||||
this.currentUserContext = currentUserContext;
|
||||
this.positionCompanyMenuService = positionCompanyMenuService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionVO createPermission(CreatePermissionDTO createPermissionDTO) {
|
||||
// 检查权限码是否已存在
|
||||
LambdaQueryWrapper<PermissionPO> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(PermissionPO::getCode, createPermissionDTO.getCode());
|
||||
if (permissionMapper.selectCount(queryWrapper) > 0) {
|
||||
throw new BusinessException("权限码已存在");
|
||||
}
|
||||
|
||||
PermissionPO permissionPO = new PermissionPO();
|
||||
BeanUtils.copyProperties(createPermissionDTO, permissionPO);
|
||||
|
||||
// 设置默认状态
|
||||
if (permissionPO.getStatus() == null) {
|
||||
permissionPO.setStatus(1);
|
||||
}
|
||||
|
||||
// 设置创建人
|
||||
permissionPO.setCreateBy(currentUserContext.getCurrentUserId());
|
||||
|
||||
permissionMapper.insert(permissionPO);
|
||||
|
||||
return convertToVO(permissionPO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionVO updatePermission(UpdatePermissionDTO updatePermissionDTO, Long id) {
|
||||
PermissionPO existingPermission = permissionMapper.selectById(id);
|
||||
if (existingPermission == null) {
|
||||
throw new BusinessException("权限不存在");
|
||||
}
|
||||
|
||||
// 检查权限码是否已被其他权限使用
|
||||
LambdaQueryWrapper<PermissionPO> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(PermissionPO::getCode, updatePermissionDTO.getCode())
|
||||
.ne(PermissionPO::getId, id);
|
||||
if (permissionMapper.selectCount(queryWrapper) > 0) {
|
||||
throw new BusinessException("权限码已存在");
|
||||
}
|
||||
|
||||
BeanUtils.copyProperties(updatePermissionDTO, existingPermission);
|
||||
existingPermission.setUpdateBy(currentUserContext.getCurrentUserId());
|
||||
|
||||
permissionMapper.updateById(existingPermission);
|
||||
|
||||
return convertToVO(existingPermission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deletePermission(Long id) {
|
||||
PermissionPO permission = permissionMapper.selectById(id);
|
||||
if (permission == null) {
|
||||
throw new BusinessException("权限不存在");
|
||||
}
|
||||
|
||||
permissionMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResultVO<PermissionVO> getPermissionPage(PageQueryDTO<PermissionFilterDTO> filterDTO) {
|
||||
Page<PermissionPO> page = new Page<>(filterDTO.getPage(), filterDTO.getPageSize());
|
||||
|
||||
IPage<PermissionPO> permissionPage = permissionMapper.selectPermissionPage(
|
||||
page,
|
||||
filterDTO.getFilters().getCode(),
|
||||
filterDTO.getFilters().getName(),
|
||||
filterDTO.getFilters().getType(),
|
||||
filterDTO.getFilters().getStatus());
|
||||
|
||||
List<PermissionVO> permissionVOList = permissionPage.getRecords().stream()
|
||||
.map(this::convertToVO)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return PageResultVO.create(
|
||||
permissionVOList,
|
||||
permissionPage.getTotal(),
|
||||
(int) permissionPage.getCurrent(),
|
||||
(int) permissionPage.getSize());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionVO getPermissionDetail(Long id) {
|
||||
PermissionPO permission = permissionMapper.selectById(id);
|
||||
if (permission == null) {
|
||||
throw new BusinessException("权限不存在");
|
||||
}
|
||||
|
||||
return convertToVO(permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PermissionVO> getAllPermissions() {
|
||||
LambdaQueryWrapper<PermissionPO> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(PermissionPO::getStatus, 1)
|
||||
.orderByAsc(PermissionPO::getCreateTime);
|
||||
|
||||
List<PermissionPO> permissionList = permissionMapper.selectList(queryWrapper);
|
||||
|
||||
return permissionList.stream()
|
||||
.map(this::convertToVO)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermissionByPosition(Long positionId, String permissionCode, Long companyId) {
|
||||
if (positionId == null || permissionCode == null || companyId == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 获取岗位的所有菜单权限
|
||||
List<PositionMenuVO> positionMenus = positionCompanyMenuService.getMenusByPositionId(positionId);
|
||||
|
||||
// 检查岗位是否有对应的菜单权限,并且该菜单关联了指定的权限码
|
||||
// 这里需要根据菜单ID查询对应的权限码
|
||||
// 由于权限码是存储在sys_permission表中的,需要通过菜单权限关联表查询
|
||||
|
||||
// 简化实现:检查岗位是否有任何菜单权限(实际应该检查具体的权限码)
|
||||
return !positionMenus.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getPositionPermissions(Long positionId, Long companyId) {
|
||||
if (positionId == null || companyId == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
// 获取岗位的所有菜单权限
|
||||
List<PositionMenuVO> positionMenus = positionCompanyMenuService.getMenusByPositionId(positionId);
|
||||
|
||||
// 这里应该根据菜单ID查询对应的权限码列表
|
||||
// 简化实现:返回空列表
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为VO
|
||||
*/
|
||||
private PermissionVO convertToVO(PermissionPO permissionPO) {
|
||||
PermissionVO permissionVO = new PermissionVO();
|
||||
BeanUtils.copyProperties(permissionPO, permissionVO);
|
||||
return permissionVO;
|
||||
}
|
||||
}
|
||||
+263
@@ -0,0 +1,263 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.mapper.UserMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.ChangePasswordDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.LoginDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.RegisterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.UpdateUserInfoDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.po.UserPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.vo.LoginVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.vo.UserVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.service.UserService;
|
||||
import top.xyquan.ecomdmbbackend.utils.JwtUtils;
|
||||
import top.xyquan.ecomdmbbackend.utils.SecurityUtils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 系统用户服务实现类
|
||||
*/
|
||||
@Service
|
||||
public class UserServiceImpl extends ServiceImpl<UserMapper, UserPO> implements UserService {
|
||||
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
private final JwtUtils jwtUtils;
|
||||
|
||||
public UserServiceImpl(PasswordEncoder passwordEncoder, JwtUtils jwtUtils) {
|
||||
this.passwordEncoder = passwordEncoder;
|
||||
this.jwtUtils = jwtUtils;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoginVO register(RegisterDTO registerDTO) {
|
||||
// 验证登录账号和手机号码至少填写一个
|
||||
if (!registerDTO.isValid()) {
|
||||
throw new BusinessException("登录账号和手机号码至少填写一个");
|
||||
}
|
||||
|
||||
// 检查登录账号是否已存在
|
||||
if (StringUtils.hasText(registerDTO.getLoginCode())) {
|
||||
LambdaQueryWrapper<UserPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(UserPO::getLoginCode, registerDTO.getLoginCode());
|
||||
if (this.count(wrapper) > 0) {
|
||||
throw new BusinessException("登录账号已存在");
|
||||
}
|
||||
}
|
||||
|
||||
// 检查手机号码是否已存在
|
||||
if (StringUtils.hasText(registerDTO.getPhone())) {
|
||||
LambdaQueryWrapper<UserPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(UserPO::getPhone, registerDTO.getPhone());
|
||||
if (this.count(wrapper) > 0) {
|
||||
throw new BusinessException("手机号码已存在");
|
||||
}
|
||||
}
|
||||
|
||||
// 创建用户
|
||||
UserPO user = new UserPO();
|
||||
user.setLoginCode(registerDTO.getLoginCode());
|
||||
user.setPhone(registerDTO.getPhone());
|
||||
user.setPassword(passwordEncoder.encode(registerDTO.getPassword()));
|
||||
user.setRealName("用户" + System.currentTimeMillis()); // 默认用户名
|
||||
user.setRole("user"); // 默认角色
|
||||
user.setStatus(0); // 正常状态
|
||||
user.setPwdSecurityLevel(0); // 初始密码安全级别
|
||||
user.setPwdUpdateTime(LocalDateTime.now());
|
||||
|
||||
// 保存用户
|
||||
this.save(user);
|
||||
|
||||
// 生成登录响应
|
||||
return generateLoginResponse(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoginVO login(LoginDTO loginDTO) {
|
||||
// 根据账号查询用户
|
||||
UserPO user = findByAccount(loginDTO.getAccount());
|
||||
if (user == null) {
|
||||
throw new BusinessException("用户不存在");
|
||||
}
|
||||
|
||||
// 验证密码
|
||||
if (!passwordEncoder.matches(loginDTO.getPassword(), user.getPassword())) {
|
||||
throw new BusinessException("密码错误");
|
||||
}
|
||||
|
||||
// 检查用户状态
|
||||
if (user.getStatus() != 0) {
|
||||
throw new BusinessException("用户状态异常,无法登录");
|
||||
}
|
||||
|
||||
// 更新最后登录信息
|
||||
user.setLastLoginDate(LocalDateTime.now());
|
||||
this.updateById(user);
|
||||
|
||||
// 生成登录响应
|
||||
return generateLoginResponse(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserPO findByAccount(String account) {
|
||||
LambdaQueryWrapper<UserPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.and(w -> w.eq(UserPO::getLoginCode, account)
|
||||
.or()
|
||||
.eq(UserPO::getPhone, account));
|
||||
return this.getOne(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserVO getCurrentUserInfo() {
|
||||
// 从Security上下文获取用户ID
|
||||
Long userId = SecurityUtils.getCurrentUserId();
|
||||
if (userId == null) {
|
||||
throw new BusinessException("用户未登录");
|
||||
}
|
||||
|
||||
// 查询用户信息
|
||||
UserPO user = this.getById(userId);
|
||||
if (user == null) {
|
||||
throw new BusinessException("用户不存在");
|
||||
}
|
||||
|
||||
// 转换为VO
|
||||
UserVO userVO = new UserVO();
|
||||
BeanUtils.copyProperties(user, userVO);
|
||||
return userVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserVO updateCurrentUserInfo(UpdateUserInfoDTO updateUserInfoDTO) {
|
||||
// 从Security上下文获取用户ID
|
||||
Long userId = SecurityUtils.getCurrentUserId();
|
||||
if (userId == null) {
|
||||
throw new BusinessException("用户未登录");
|
||||
}
|
||||
|
||||
// 查询用户信息
|
||||
UserPO user = this.getById(userId);
|
||||
if (user == null) {
|
||||
throw new BusinessException("用户不存在");
|
||||
}
|
||||
|
||||
// 检查手机号码是否已被其他用户使用
|
||||
if (StringUtils.hasText(updateUserInfoDTO.getPhone()) &&
|
||||
!updateUserInfoDTO.getPhone().equals(user.getPhone())) {
|
||||
LambdaQueryWrapper<UserPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(UserPO::getPhone, updateUserInfoDTO.getPhone());
|
||||
if (this.count(wrapper) > 0) {
|
||||
throw new BusinessException("手机号码已被其他用户使用");
|
||||
}
|
||||
}
|
||||
|
||||
// 更新用户信息
|
||||
if (StringUtils.hasText(updateUserInfoDTO.getRealName())) {
|
||||
user.setRealName(updateUserInfoDTO.getRealName());
|
||||
}
|
||||
if (StringUtils.hasText(updateUserInfoDTO.getAvatar())) {
|
||||
user.setAvatar(updateUserInfoDTO.getAvatar());
|
||||
}
|
||||
if (StringUtils.hasText(updateUserInfoDTO.getPhone())) {
|
||||
user.setPhone(updateUserInfoDTO.getPhone());
|
||||
}
|
||||
if (StringUtils.hasText(updateUserInfoDTO.getRemark())) {
|
||||
user.setRemark(updateUserInfoDTO.getRemark());
|
||||
}
|
||||
|
||||
// 保存更新
|
||||
this.updateById(user);
|
||||
|
||||
// 转换为VO并返回
|
||||
UserVO userVO = new UserVO();
|
||||
BeanUtils.copyProperties(user, userVO);
|
||||
return userVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changePassword(ChangePasswordDTO changePasswordDTO) {
|
||||
// 从Security上下文获取用户ID
|
||||
Long userId = SecurityUtils.getCurrentUserId();
|
||||
if (userId == null) {
|
||||
throw new BusinessException("用户未登录");
|
||||
}
|
||||
|
||||
// 查询用户信息
|
||||
UserPO user = this.getById(userId);
|
||||
if (user == null) {
|
||||
throw new BusinessException("用户不存在");
|
||||
}
|
||||
|
||||
// 验证旧密码
|
||||
if (!passwordEncoder.matches(changePasswordDTO.getOldPassword(), user.getPassword())) {
|
||||
throw new BusinessException("旧密码错误");
|
||||
}
|
||||
|
||||
// 更新密码
|
||||
user.setPassword(passwordEncoder.encode(changePasswordDTO.getNewPassword()));
|
||||
user.setPwdUpdateTime(LocalDateTime.now());
|
||||
user.setPwdSecurityLevel(calculatePasswordSecurityLevel(changePasswordDTO.getNewPassword()));
|
||||
|
||||
// 保存更新
|
||||
this.updateById(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成登录响应
|
||||
*/
|
||||
private LoginVO generateLoginResponse(UserPO user) {
|
||||
LoginVO loginVO = new LoginVO();
|
||||
|
||||
// 生成JWT令牌,包含用户ID和公司ID
|
||||
String token = jwtUtils.generateToken(user.getId().toString(), user.getCompanyId());
|
||||
loginVO.setToken(token);
|
||||
|
||||
// 转换用户信息
|
||||
UserVO userVO = new UserVO();
|
||||
BeanUtils.copyProperties(user, userVO);
|
||||
loginVO.setUser(userVO);
|
||||
|
||||
return loginVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算密码安全级别
|
||||
*/
|
||||
private Integer calculatePasswordSecurityLevel(String password) {
|
||||
if (password == null || password.length() < 8) {
|
||||
return 1; // 很弱
|
||||
}
|
||||
|
||||
boolean hasLower = password.matches(".*[a-z].*");
|
||||
boolean hasUpper = password.matches(".*[A-Z].*");
|
||||
boolean hasDigit = password.matches(".*\\d.*");
|
||||
boolean hasSpecial = password.matches(".*[@$!%*?&].*");
|
||||
|
||||
int score = 0;
|
||||
if (hasLower)
|
||||
score++;
|
||||
if (hasUpper)
|
||||
score++;
|
||||
if (hasDigit)
|
||||
score++;
|
||||
if (hasSpecial)
|
||||
score++;
|
||||
|
||||
if (password.length() >= 12)
|
||||
score++;
|
||||
|
||||
return switch (score) {
|
||||
case 0, 1 -> 1; // 很弱
|
||||
case 2 -> 2; // 弱
|
||||
case 3 -> 3; // 安全
|
||||
case 4, 5 -> 4; // 很安全
|
||||
default -> 2; // 弱
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user