system和auth 初步构建
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
package org.xyzh.api.system.dept;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.xyzh.common.core.domain.ResultDomain;
|
||||
import org.xyzh.common.dto.dept.TbSysDept;
|
||||
|
||||
/**
|
||||
* @description DepartmentService.java文件描述 部门服务接口
|
||||
* @filename DepartmentService.java
|
||||
* @author yslg
|
||||
* @copyright xyzh
|
||||
* @ since 2025-09-28
|
||||
*/
|
||||
public interface DepartmentService {
|
||||
|
||||
/**
|
||||
* @description 查询所有部门
|
||||
* @return ResultDomain<TbSysDept> 部门列表
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
ResultDomain<TbSysDept> getAllDepartments();
|
||||
|
||||
/**
|
||||
* @description 根据ID查询部门
|
||||
* @param deptId 部门ID
|
||||
* @return ResultDomain<TbSysDept> 部门信息
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
ResultDomain<TbSysDept> getDepartmentById(String deptId);
|
||||
|
||||
/**
|
||||
* @description 根据父部门ID查询子部门
|
||||
* @param parentId 父部门ID
|
||||
* @return ResultDomain<TbSysDept> 子部门列表
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
ResultDomain<TbSysDept> getDepartmentsByParentId(String parentId);
|
||||
|
||||
/**
|
||||
* @description 创建部门
|
||||
* @param department 部门信息
|
||||
* @return ResultDomain<TbSysDept> 创建结果
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
ResultDomain<TbSysDept> createDepartment(TbSysDept department);
|
||||
|
||||
/**
|
||||
* @description 更新部门
|
||||
* @param department 部门信息
|
||||
* @return ResultDomain<TbSysDept> 更新结果
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
ResultDomain<TbSysDept> updateDepartment(TbSysDept department);
|
||||
|
||||
/**
|
||||
* @description 删除部门
|
||||
* @param deptId 部门ID
|
||||
* @return ResultDomain<TbSysDept> 删除结果
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
ResultDomain<TbSysDept> deleteDepartment(String deptId);
|
||||
|
||||
/**
|
||||
* @description 检查部门名称是否存在
|
||||
* @param deptName 部门名称
|
||||
* @param excludeId 排除的部门ID(用于更新时排除自身)
|
||||
* @return ResultDomain<Boolean> 是否存在
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
ResultDomain<Boolean> checkDepartmentNameExists(String deptName, String excludeId);
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package org.xyzh.api.system.menu;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.xyzh.common.core.domain.ResultDomain;
|
||||
import org.xyzh.common.core.page.PageParam;
|
||||
import org.xyzh.common.dto.menu.TbSysMenu;
|
||||
|
||||
@@ -15,97 +16,113 @@ import org.xyzh.common.dto.menu.TbSysMenu;
|
||||
public interface MenuService {
|
||||
|
||||
/**
|
||||
* @description 添加菜单
|
||||
* @param menu 菜单对象
|
||||
* @return void
|
||||
* @description 获取所有菜单
|
||||
* @return ResultDomain<TbSysMenu> 菜单列表
|
||||
* @author yslg
|
||||
* @since 2025-09-27
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
void addMenu(TbSysMenu menu);
|
||||
ResultDomain<TbSysMenu> getAllMenus();
|
||||
|
||||
/**
|
||||
* @description 根据菜单ID查询菜单
|
||||
* @param menuId 菜单ID
|
||||
* @return ResultDomain<TbSysMenu> 菜单信息
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
ResultDomain<TbSysMenu> getMenuById(String menuId);
|
||||
|
||||
/**
|
||||
* @description 根据用户ID查询菜单列表
|
||||
* @param userId 用户ID
|
||||
* @return ResultDomain<TbSysMenu> 菜单列表
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
ResultDomain<TbSysMenu> getMenusByUserId(String userId);
|
||||
|
||||
/**
|
||||
* @description 根据角色ID查询菜单列表
|
||||
* @param roleId 角色ID
|
||||
* @return ResultDomain<TbSysMenu> 菜单列表
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
ResultDomain<TbSysMenu> getMenusByRoleId(String roleId);
|
||||
|
||||
/**
|
||||
* @description 根据父菜单ID查询子菜单
|
||||
* @param parentId 父菜单ID
|
||||
* @return ResultDomain<TbSysMenu> 子菜单列表
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
ResultDomain<TbSysMenu> getMenusByParentId(String parentId);
|
||||
|
||||
/**
|
||||
* @description 获取菜单树结构
|
||||
* @return ResultDomain<TbSysMenu> 菜单树
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
ResultDomain<TbSysMenu> getMenuTree();
|
||||
|
||||
/**
|
||||
* @description 创建菜单
|
||||
* @param menu 菜单对象
|
||||
* @return ResultDomain<TbSysMenu> 创建结果
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
ResultDomain<TbSysMenu> createMenu(TbSysMenu menu);
|
||||
|
||||
/**
|
||||
* @description 更新菜单
|
||||
* @param menu 菜单对象
|
||||
* @return void
|
||||
* @return ResultDomain<TbSysMenu> 更新结果
|
||||
* @author yslg
|
||||
* @since 2025-09-27
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
void updateMenu(TbSysMenu menu);
|
||||
ResultDomain<TbSysMenu> updateMenu(TbSysMenu menu);
|
||||
|
||||
/**
|
||||
* @description 删除菜单
|
||||
* @param menuID 菜单ID
|
||||
* @param deep 是否深度删除(删除该菜单及其所有子菜单)
|
||||
* @return void
|
||||
* @param menuId 菜单ID
|
||||
* @return ResultDomain<TbSysMenu> 删除结果
|
||||
* @author yslg
|
||||
* @since 2025-09-27
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
void deleteMenu(String menuID, boolean deep);
|
||||
ResultDomain<TbSysMenu> deleteMenu(String menuId);
|
||||
|
||||
/**
|
||||
* @description 导入菜单
|
||||
* @param menus 菜单列表
|
||||
* @return void
|
||||
* @description 检查菜单名称是否存在
|
||||
* @param menuName 菜单名称
|
||||
* @param excludeId 排除的菜单ID(用于更新时排除自身)
|
||||
* @return ResultDomain<Boolean> 是否存在
|
||||
* @author yslg
|
||||
* @since 2025-09-27
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
void importMenus(List<TbSysMenu> menus);
|
||||
ResultDomain<Boolean> checkMenuNameExists(String menuName, String excludeId);
|
||||
|
||||
/**
|
||||
* @description 导出菜单
|
||||
* @param filter 菜单对象
|
||||
* @return 菜单列表
|
||||
* @description 修改菜单状态
|
||||
* @param menuId 菜单ID
|
||||
* @param status 新状态
|
||||
* @return ResultDomain<TbSysMenu> 修改结果
|
||||
* @author yslg
|
||||
* @since 2025-09-27
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
List<TbSysMenu> exportMenus(TbSysMenu filter);
|
||||
ResultDomain<TbSysMenu> changeMenuStatus(String menuId, Integer status);
|
||||
|
||||
/**
|
||||
* @description 查找菜单
|
||||
* @param menu 菜单对象
|
||||
* @return 菜单对象
|
||||
* @description 修改菜单可见性
|
||||
* @param menuId 菜单ID
|
||||
* @param visible 可见性
|
||||
* @return ResultDomain<TbSysMenu> 修改结果
|
||||
* @author yslg
|
||||
* @since 2025-09-27
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
TbSysMenu find(TbSysMenu filter);
|
||||
|
||||
/**
|
||||
* @description 分页查找菜单
|
||||
* @param menu 菜单对象
|
||||
* @param pageParam 分页参数
|
||||
* @return 菜单列表
|
||||
* @author yslg
|
||||
* @since 2025-09-27
|
||||
*/
|
||||
List<TbSysMenu> findPageMenus(TbSysMenu menu, PageParam pageParam);
|
||||
|
||||
/**
|
||||
* @description 根据菜单ID列表查找菜单
|
||||
* @param menuIDs 菜单ID列表
|
||||
* @return 菜单列表
|
||||
* @author yslg
|
||||
* @since 2025-09-27
|
||||
*/
|
||||
List<TbSysMenu> findByIDs(List<String> menuIDs);
|
||||
|
||||
/**
|
||||
* @description 查找子菜单
|
||||
* @param parentID 父菜单ID
|
||||
* @return 子菜单列表
|
||||
* @author yslg
|
||||
* @since 2025-09-27
|
||||
*/
|
||||
List<TbSysMenu> findChildListByParentID(String parentID);
|
||||
|
||||
/**
|
||||
* @description 查找所有菜单
|
||||
* @return 菜单列表
|
||||
* @author yslg
|
||||
* @since 2025-09-27
|
||||
*/
|
||||
List<TbSysMenu> findAll();
|
||||
|
||||
List<TbSysMenu> permissionMenus(List<String> permissionIDList);
|
||||
ResultDomain<TbSysMenu> changeMenuVisibility(String menuId, Boolean visible);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.xyzh.common.core.domain.ResultDomain;
|
||||
import org.xyzh.common.dto.permission.TbSysPermission;
|
||||
|
||||
/**
|
||||
@@ -13,105 +14,107 @@ import org.xyzh.common.dto.permission.TbSysPermission;
|
||||
* @copyright xyzh
|
||||
* @since 2025-09-26
|
||||
*/
|
||||
|
||||
public interface PermissionService {
|
||||
|
||||
/**
|
||||
* @description 添加权限
|
||||
* @param permission 权限对象
|
||||
* @return void
|
||||
/**
|
||||
* @description 获取所有权限
|
||||
* @return ResultDomain<TbSysPermission> 权限列表
|
||||
* @author yslg
|
||||
* @since 2025-09-27
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
void addPermission(TbSysPermission permission);
|
||||
ResultDomain<TbSysPermission> getAllPermissions();
|
||||
|
||||
/**
|
||||
/**
|
||||
* @description 根据权限ID查询权限
|
||||
* @param permissionId 权限ID
|
||||
* @return ResultDomain<TbSysPermission> 权限信息
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
ResultDomain<TbSysPermission> getPermissionById(String permissionId);
|
||||
|
||||
/**
|
||||
* @description 根据权限编码查询权限
|
||||
* @param permissionCode 权限编码
|
||||
* @return ResultDomain<TbSysPermission> 权限信息
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
ResultDomain<TbSysPermission> getPermissionByCode(String permissionCode);
|
||||
|
||||
/**
|
||||
* @description 根据用户ID查询权限列表
|
||||
* @param userId 用户ID
|
||||
* @return ResultDomain<TbSysPermission> 权限列表
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
ResultDomain<TbSysPermission> getPermissionsByUserId(String userId);
|
||||
|
||||
/**
|
||||
* @description 根据角色ID查询权限列表
|
||||
* @param roleId 角色ID
|
||||
* @return ResultDomain<TbSysPermission> 权限列表
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
ResultDomain<TbSysPermission> getPermissionsByRoleId(String roleId);
|
||||
|
||||
/**
|
||||
* @description 创建权限
|
||||
* @param permission 权限对象
|
||||
* @return ResultDomain<TbSysPermission> 创建结果
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
ResultDomain<TbSysPermission> createPermission(TbSysPermission permission);
|
||||
|
||||
/**
|
||||
* @description 更新权限
|
||||
* @param permission 权限对象
|
||||
* @return void
|
||||
* @return ResultDomain<TbSysPermission> 更新结果
|
||||
* @author yslg
|
||||
* @since 2025-09-27
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
void updatePermission(TbSysPermission permission);
|
||||
ResultDomain<TbSysPermission> updatePermission(TbSysPermission permission);
|
||||
|
||||
/**
|
||||
/**
|
||||
* @description 删除权限
|
||||
* @param permissionID 权限ID
|
||||
* @return void
|
||||
* @param permissionId 权限ID
|
||||
* @return ResultDomain<TbSysPermission> 删除结果
|
||||
* @author yslg
|
||||
* @since 2025-09-27
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
void deletePermission(String permissionID);
|
||||
|
||||
/**
|
||||
* @description 批量导入权限
|
||||
* @param permissions 权限列表
|
||||
* @return void
|
||||
* @author yslg
|
||||
* @since 2025-09-27
|
||||
*/
|
||||
void importPermissions(List<TbSysPermission> permissions);
|
||||
|
||||
/**
|
||||
* @description 条件导出权限
|
||||
* @param filter 权限对象
|
||||
* @return 权限列表
|
||||
* @author yslg
|
||||
* @since 2025-09-27
|
||||
*/
|
||||
List<TbSysPermission> exportPermissions(TbSysPermission filter);
|
||||
|
||||
/**
|
||||
* @description 权限ID查询
|
||||
* @param permissionID 权限ID
|
||||
* @return 权限对象
|
||||
* @author yslg
|
||||
* @since 2025-09-27
|
||||
*/
|
||||
TbSysPermission findByID(String permissionID);
|
||||
|
||||
/**
|
||||
* @description 批量权限ID查询
|
||||
* @param permissionIDs 权限ID列表
|
||||
* @return 权限对象列表
|
||||
* @author yslg
|
||||
* @since 2025-09-27
|
||||
*/
|
||||
List<TbSysPermission> findByIDs(Collection<String> permissionIDs);
|
||||
|
||||
/**
|
||||
* @description 根据用户ID查询用户权限集合
|
||||
* @param userID 用户ID
|
||||
* @return 权限集合
|
||||
* @author yslg
|
||||
* @since 2025-09-27
|
||||
*/
|
||||
Set<TbSysPermission> findUserPermissions(String userID);
|
||||
ResultDomain<TbSysPermission> deletePermission(String permissionId);
|
||||
|
||||
/**
|
||||
* @description 根据角色ID查询角色权限集合
|
||||
* @param roleID 角色ID
|
||||
* @return 权限集合
|
||||
* @description 检查权限名称是否存在
|
||||
* @param permissionName 权限名称
|
||||
* @param excludeId 排除的权限ID(用于更新时排除自身)
|
||||
* @return ResultDomain<Boolean> 是否存在
|
||||
* @author yslg
|
||||
* @since 2025-09-27
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
Set<TbSysPermission> findRolePermissions(String roleID);
|
||||
ResultDomain<Boolean> checkPermissionNameExists(String permissionName, String excludeId);
|
||||
|
||||
/**
|
||||
* @description 根据角色ID列表查询角色权限集合
|
||||
* @param roleIDList 角色ID列表
|
||||
* @return 权限集合
|
||||
* @author yslg
|
||||
* @since 2025-09-27
|
||||
*/
|
||||
Set<TbSysPermission> findRolesPermissions(List<String> roleIDList);
|
||||
|
||||
/**
|
||||
* @description 判断用户是否拥有某个权限
|
||||
* @param userID 用户ID
|
||||
* @description 检查权限编码是否存在
|
||||
* @param permissionCode 权限编码
|
||||
* @return true-拥有;false-不拥有
|
||||
* @param excludeId 排除的权限ID(用于更新时排除自身)
|
||||
* @return ResultDomain<Boolean> 是否存在
|
||||
* @author yslg
|
||||
* @since 2025-09-27
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
boolean hasPermission(String userID, String permissionCode);
|
||||
ResultDomain<Boolean> checkPermissionCodeExists(String permissionCode, String excludeId);
|
||||
|
||||
/**
|
||||
* @description 修改权限状态
|
||||
* @param permissionId 权限ID
|
||||
* @param status 新状态
|
||||
* @return ResultDomain<TbSysPermission> 修改结果
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
ResultDomain<TbSysPermission> changePermissionStatus(String permissionId, Integer status);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.xyzh.api.system.role;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import org.xyzh.common.core.domain.ResultDomain;
|
||||
import org.xyzh.common.dto.role.TbSysRole;
|
||||
|
||||
|
||||
@@ -15,74 +14,75 @@ import org.xyzh.common.dto.role.TbSysRole;
|
||||
public interface RoleService {
|
||||
|
||||
/**
|
||||
* @description 添加角色
|
||||
* @param role 角色对象
|
||||
* @return void
|
||||
* @description 获取所有角色
|
||||
* @return ResultDomain<TbSysRole> 角色列表
|
||||
* @author yslg
|
||||
* @since 2025-09-27
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
void addRole(TbSysRole role);
|
||||
ResultDomain<TbSysRole> getAllRoles();
|
||||
|
||||
/**
|
||||
* @description 根据角色ID查询角色
|
||||
* @param roleId 角色ID
|
||||
* @return ResultDomain<TbSysRole> 角色信息
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
ResultDomain<TbSysRole> getRoleById(String roleId);
|
||||
|
||||
/**
|
||||
* @description 根据用户ID查询角色列表
|
||||
* @param userId 用户ID
|
||||
* @return ResultDomain<TbSysRole> 角色列表
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
ResultDomain<TbSysRole> getRolesByUserId(String userId);
|
||||
|
||||
/**
|
||||
* @description 创建角色
|
||||
* @param role 角色对象
|
||||
* @return ResultDomain<TbSysRole> 创建结果
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
ResultDomain<TbSysRole> createRole(TbSysRole role);
|
||||
|
||||
/**
|
||||
* @description 更新角色
|
||||
* @param role 角色对象
|
||||
* @return void
|
||||
* @return ResultDomain<TbSysRole> 更新结果
|
||||
* @author yslg
|
||||
* @since 2025-09-27
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
void updateRole(TbSysRole role);
|
||||
ResultDomain<TbSysRole> updateRole(TbSysRole role);
|
||||
|
||||
/**
|
||||
* @description 删除角色
|
||||
* @param roleID 角色ID
|
||||
* @return void
|
||||
* @param roleId 角色ID
|
||||
* @return ResultDomain<TbSysRole> 删除结果
|
||||
* @author yslg
|
||||
* @since 2025-09-27
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
void deleteRole(String roleID);
|
||||
ResultDomain<TbSysRole> deleteRole(String roleId);
|
||||
|
||||
/**
|
||||
* @description 批量导入角色
|
||||
* @param roles 角色列表
|
||||
* @return void
|
||||
* @description 检查角色名称是否存在
|
||||
* @param roleName 角色名称
|
||||
* @param excludeId 排除的角色ID(用于更新时排除自身)
|
||||
* @return ResultDomain<Boolean> 是否存在
|
||||
* @author yslg
|
||||
* @since 2025-09-27
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
void importRoles(List<TbSysRole> roles);
|
||||
ResultDomain<Boolean> checkRoleNameExists(String roleName, String excludeId);
|
||||
|
||||
/**
|
||||
* @description 条件导出角色
|
||||
* @param filter 角色对象
|
||||
* @return 角色列表
|
||||
* @description 修改角色状态
|
||||
* @param roleId 角色ID
|
||||
* @param status 新状态
|
||||
* @return ResultDomain<TbSysRole> 修改结果
|
||||
* @author yslg
|
||||
* @since 2025-09-27
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
List<TbSysRole> exportRoles(TbSysRole filter);
|
||||
|
||||
/**
|
||||
* @description 通过主键查找
|
||||
* @param roleID 角色ID
|
||||
* @return 角色对象
|
||||
* @author yslg
|
||||
* @since 2025-09-27
|
||||
*/
|
||||
TbSysRole findByID(String roleID);
|
||||
|
||||
/**
|
||||
* @description 批量通过主键查找
|
||||
* @param roleIDs 角色ID集合
|
||||
* @return 角色列表
|
||||
* @author yslg
|
||||
* @since 2025-09-27
|
||||
*/
|
||||
List<TbSysRole> findByIDs(Collection<String> roleIDs);
|
||||
|
||||
/**
|
||||
* @description 根据用户ID查询用户角色列表
|
||||
* @param userID 用户ID
|
||||
* @return 角色列表
|
||||
* @author yslg
|
||||
* @since 2025-09-27
|
||||
*/
|
||||
List<TbSysRole> findUserRoleList(String userID);
|
||||
ResultDomain<TbSysRole> changeRoleStatus(String roleId, Integer status);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.xyzh.api.system.user;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.xyzh.common.core.domain.ResultDomain;
|
||||
import org.xyzh.common.dto.user.TbSysUser;
|
||||
|
||||
/**
|
||||
@@ -15,74 +16,115 @@ import org.xyzh.common.dto.user.TbSysUser;
|
||||
public interface UserService {
|
||||
|
||||
/**
|
||||
* @description 添加用户
|
||||
* @param user 用户对象
|
||||
* @return void
|
||||
* @description 获取所有用户
|
||||
* @return ResultDomain<TbSysUser> 用户列表
|
||||
* @author yslg
|
||||
* @since 2025-09-27
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
void addUser(TbSysUser user);
|
||||
ResultDomain<TbSysUser> getAllUsers();
|
||||
|
||||
/**
|
||||
* @description 根据用户ID查询用户
|
||||
* @param userId 用户ID
|
||||
* @return ResultDomain<TbSysUser> 用户信息
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
ResultDomain<TbSysUser> getUserById(String userId);
|
||||
|
||||
/**
|
||||
* @description 根据用户名查询用户
|
||||
* @param username 用户名
|
||||
* @return ResultDomain<TbSysUser> 用户信息
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
ResultDomain<TbSysUser> getUserByUsername(String username);
|
||||
|
||||
/**
|
||||
* @description 根据过滤条件查询用户(支持多种查询条件组合)
|
||||
* @param filter 过滤条件(支持userID、username、email、phone等字段)
|
||||
* @return ResultDomain<TbSysUser> 用户信息
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
ResultDomain<TbSysUser> getUserByFilter(TbSysUser filter);
|
||||
|
||||
/**
|
||||
* @description 创建用户
|
||||
* @param user 用户对象
|
||||
* @return ResultDomain<TbSysUser> 创建结果
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
ResultDomain<TbSysUser> createUser(TbSysUser user);
|
||||
|
||||
/**
|
||||
* @description 更新用户
|
||||
* @param user 用户对象
|
||||
* @return void
|
||||
* @return ResultDomain<TbSysUser> 更新结果
|
||||
* @author yslg
|
||||
* @since 2025-09-27
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
void updateUser(TbSysUser user);
|
||||
ResultDomain<TbSysUser> updateUser(TbSysUser user);
|
||||
|
||||
/**
|
||||
* @description 删除用户(逻辑或物理取决于实现)
|
||||
* @description 删除用户(逻辑删除)
|
||||
* @param userId 用户ID
|
||||
* @return void
|
||||
* @return ResultDomain<TbSysUser> 删除结果
|
||||
* @author yslg
|
||||
* @since 2025-09-27
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
void deleteUser(String userID);
|
||||
ResultDomain<TbSysUser> deleteUser(String userId);
|
||||
|
||||
/**
|
||||
* @description 批量导入用户
|
||||
* @param users 用户列表
|
||||
* @return void
|
||||
* @description 检查用户名是否存在
|
||||
* @param username 用户名
|
||||
* @param excludeId 排除的用户ID(用于更新时排除自身)
|
||||
* @return ResultDomain<Boolean> 是否存在
|
||||
* @author yslg
|
||||
* @since 2025-09-27
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
void importUsers(List<TbSysUser> users);
|
||||
ResultDomain<Boolean> checkUsernameExists(String username, String excludeId);
|
||||
|
||||
/**
|
||||
* @description 条件导出用户
|
||||
* @param filter 用户对象
|
||||
* @return 用户列表
|
||||
* @description 检查邮箱是否存在
|
||||
* @param email 邮箱
|
||||
* @param excludeId 排除的用户ID(用于更新时排除自身)
|
||||
* @return ResultDomain<Boolean> 是否存在
|
||||
* @author yslg
|
||||
* @since 2025-09-27
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
List<TbSysUser> exportUsers(TbSysUser filter);
|
||||
ResultDomain<Boolean> checkEmailExists(String email, String excludeId);
|
||||
|
||||
/**
|
||||
* @description 查找用户
|
||||
* @param filter 用户对象
|
||||
* @return 用户对象
|
||||
* @description 搜索用户
|
||||
* @param username 用户名(模糊查询)
|
||||
* @param email 邮箱(模糊查询)
|
||||
* @param status 状态
|
||||
* @return ResultDomain<TbSysUser> 用户列表
|
||||
* @author yslg
|
||||
* @since 2025-09-27
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
TbSysUser find(TbSysUser filter);
|
||||
ResultDomain<TbSysUser> searchUsers(String username, String email, String status);
|
||||
|
||||
/**
|
||||
* @description 通过主键集合查找用户列表
|
||||
* @param userIds 用户ID集合
|
||||
* @return 用户列表
|
||||
* @description 修改用户状态
|
||||
* @param userId 用户ID
|
||||
* @param status 新状态
|
||||
* @return ResultDomain<TbSysUser> 修改结果
|
||||
* @author yslg
|
||||
* @since 2025-09-27
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
List<TbSysUser> findByIDs(Collection<String> userIDs);
|
||||
ResultDomain<TbSysUser> changeUserStatus(String userId, Integer status);
|
||||
|
||||
/**
|
||||
* @description 根据角色ID查询用户列表
|
||||
* @param roleId 角色ID
|
||||
* @return 用户列表
|
||||
* @description 重置用户密码
|
||||
* @param userId 用户ID
|
||||
* @param newPassword 新密码
|
||||
* @return ResultDomain<TbSysUser> 重置结果
|
||||
* @author yslg
|
||||
* @since 2025-09-27
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
List<TbSysUser> listUsersByRoleID(String roleID);
|
||||
ResultDomain<TbSysUser> resetPassword(String userId, String newPassword);
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public class EmailLoginStrategy implements LoginStrategy {
|
||||
public TbSysUser findUser(LoginParam loginParam) {
|
||||
TbSysUser filter = new TbSysUser();
|
||||
filter.setEmail(loginParam.getEmail());
|
||||
return userService.find(filter);
|
||||
return userService.getUserByFilter(filter).getData();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -39,7 +39,7 @@ public class PhoneLoginStrategy implements LoginStrategy {
|
||||
public TbSysUser findUser(LoginParam loginParam) {
|
||||
TbSysUser filter = new TbSysUser();
|
||||
filter.setPhone(loginParam.getPhone());
|
||||
return userService.find(filter);
|
||||
return userService.getUserByFilter(filter).getData();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -39,7 +39,7 @@ public class UsernameLoginStrategy implements LoginStrategy {
|
||||
public TbSysUser findUser(LoginParam loginParam) {
|
||||
TbSysUser filter = new TbSysUser();
|
||||
filter.setUsername(loginParam.getUsername());
|
||||
return userService.find(filter);
|
||||
return userService.getUserByFilter(filter).getData();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -35,7 +35,7 @@ public class WechatLoginStrategy implements LoginStrategy {
|
||||
public TbSysUser findUser(LoginParam loginParam) {
|
||||
TbSysUser filter = new TbSysUser();
|
||||
filter.setWechatID(loginParam.getWechatID());
|
||||
return userService.find(filter);
|
||||
return userService.getUserByFilter(filter).getData();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.xyzh.common.dto;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.Date;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
/**
|
||||
@@ -47,7 +47,7 @@ public class BaseDTO implements Serializable{
|
||||
* @author yslg
|
||||
* @since 2025-09-10
|
||||
*/
|
||||
private Integer deleted;
|
||||
private boolean deleted;
|
||||
|
||||
|
||||
|
||||
@@ -136,11 +136,11 @@ public class BaseDTO implements Serializable{
|
||||
|
||||
/**
|
||||
* @description 获取是否删除
|
||||
* @return Integer 是否删除
|
||||
* @return boolean 是否删除
|
||||
* @author yslg
|
||||
* @since 2025-09-10
|
||||
*/
|
||||
public Integer getDeleted() {
|
||||
public boolean getDeleted() {
|
||||
return deleted;
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ public class BaseDTO implements Serializable{
|
||||
* @author yslg
|
||||
* @since 2025-09-10
|
||||
*/
|
||||
public void setDeleted(Integer deleted) {
|
||||
public void setDeleted(boolean deleted) {
|
||||
this.deleted = deleted;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,6 +54,54 @@ public class TbSysDept extends BaseDTO{
|
||||
*/
|
||||
private String updater;
|
||||
|
||||
// Getter和Setter方法
|
||||
public String getDeptID() {
|
||||
return deptID;
|
||||
}
|
||||
|
||||
public void setDeptID(String deptID) {
|
||||
this.deptID = deptID;
|
||||
}
|
||||
|
||||
public String getParentID() {
|
||||
return parentID;
|
||||
}
|
||||
|
||||
public void setParentID(String parentID) {
|
||||
this.parentID = parentID;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getCreator() {
|
||||
return creator;
|
||||
}
|
||||
|
||||
public void setCreator(String creator) {
|
||||
this.creator = creator;
|
||||
}
|
||||
|
||||
public String getUpdater() {
|
||||
return updater;
|
||||
}
|
||||
|
||||
public void setUpdater(String updater) {
|
||||
this.updater = updater;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
@@ -0,0 +1,603 @@
|
||||
package org.xyzh.common.utils;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.*;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* @description NonUtils.java文件描述 空值判断工具类
|
||||
* @filename NonUtils.java
|
||||
* @author yslg
|
||||
* @copyright xyzh
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
public class NonUtils {
|
||||
|
||||
private NonUtils() {
|
||||
throw new UnsupportedOperationException("工具类不能被实例化");
|
||||
}
|
||||
|
||||
// ======================== 基础null判断 ========================
|
||||
|
||||
/**
|
||||
* 判断对象是否为null
|
||||
*
|
||||
* @param obj 待判断的对象
|
||||
* @return true-对象为null,false-对象不为null
|
||||
*/
|
||||
public static boolean isNull(Object obj) {
|
||||
return obj == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断对象是否不为null
|
||||
*
|
||||
* @param obj 待判断的对象
|
||||
* @return true-对象不为null,false-对象为null
|
||||
*/
|
||||
public static boolean isNotNull(Object obj) {
|
||||
return obj != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断多个对象是否都为null
|
||||
*
|
||||
* @param objects 待判断的对象数组
|
||||
* @return true-所有对象都为null,false-至少有一个对象不为null
|
||||
*/
|
||||
public static boolean isAllNull(Object... objects) {
|
||||
if (objects == null || objects.length == 0) {
|
||||
return true;
|
||||
}
|
||||
for (Object obj : objects) {
|
||||
if (isNotNull(obj)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断多个对象是否都不为null
|
||||
*
|
||||
* @param objects 待判断的对象数组
|
||||
* @return true-所有对象都不为null,false-至少有一个对象为null
|
||||
*/
|
||||
public static boolean isAllNotNull(Object... objects) {
|
||||
if (objects == null || objects.length == 0) {
|
||||
return false;
|
||||
}
|
||||
for (Object obj : objects) {
|
||||
if (isNull(obj)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断多个对象中是否存在null
|
||||
*
|
||||
* @param objects 待判断的对象数组
|
||||
* @return true-存在null对象,false-不存在null对象
|
||||
*/
|
||||
public static boolean hasNull(Object... objects) {
|
||||
if (objects == null || objects.length == 0) {
|
||||
return true;
|
||||
}
|
||||
for (Object obj : objects) {
|
||||
if (isNull(obj)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ======================== 空值判断(包含null、空字符串、空集合等) ========================
|
||||
|
||||
/**
|
||||
* 判断对象是否为空
|
||||
* - null -> true
|
||||
* - "" -> true
|
||||
* - " " -> true (仅包含空白字符)
|
||||
* - 空集合 -> true
|
||||
* - 空数组 -> true
|
||||
*
|
||||
* @param obj 待判断的对象
|
||||
* @return true-对象为空,false-对象不为空
|
||||
*/
|
||||
public static boolean isEmpty(Object obj) {
|
||||
if (isNull(obj)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 字符串判断
|
||||
if (obj instanceof CharSequence) {
|
||||
return ((CharSequence) obj).length() == 0 || obj.toString().trim().isEmpty();
|
||||
}
|
||||
|
||||
// 集合判断
|
||||
if (obj instanceof Collection) {
|
||||
return ((Collection<?>) obj).isEmpty();
|
||||
}
|
||||
|
||||
// Map判断
|
||||
if (obj instanceof Map) {
|
||||
return ((Map<?, ?>) obj).isEmpty();
|
||||
}
|
||||
|
||||
// 数组判断
|
||||
if (obj.getClass().isArray()) {
|
||||
return Array.getLength(obj) == 0;
|
||||
}
|
||||
|
||||
// Optional判断
|
||||
if (obj instanceof Optional) {
|
||||
return !((Optional<?>) obj).isPresent();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断对象是否不为空
|
||||
*
|
||||
* @param obj 待判断的对象
|
||||
* @return true-对象不为空,false-对象为空
|
||||
*/
|
||||
public static boolean isNotEmpty(Object obj) {
|
||||
return !isEmpty(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断多个对象是否都为空
|
||||
*
|
||||
* @param objects 待判断的对象数组
|
||||
* @return true-所有对象都为空,false-至少有一个对象不为空
|
||||
*/
|
||||
public static boolean isAllEmpty(Object... objects) {
|
||||
if (objects == null || objects.length == 0) {
|
||||
return true;
|
||||
}
|
||||
for (Object obj : objects) {
|
||||
if (isNotEmpty(obj)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断多个对象是否都不为空
|
||||
*
|
||||
* @param objects 待判断的对象数组
|
||||
* @return true-所有对象都不为空,false-至少有一个对象为空
|
||||
*/
|
||||
public static boolean isAllNotEmpty(Object... objects) {
|
||||
if (objects == null || objects.length == 0) {
|
||||
return false;
|
||||
}
|
||||
for (Object obj : objects) {
|
||||
if (isEmpty(obj)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断多个对象中是否存在空值
|
||||
*
|
||||
* @param objects 待判断的对象数组
|
||||
* @return true-存在空值,false-不存在空值
|
||||
*/
|
||||
public static boolean hasEmpty(Object... objects) {
|
||||
if (objects == null || objects.length == 0) {
|
||||
return true;
|
||||
}
|
||||
for (Object obj : objects) {
|
||||
if (isEmpty(obj)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ======================== 深度递归判断 ========================
|
||||
|
||||
/**
|
||||
* 深度判断对象是否为空(递归检查)
|
||||
* 对于集合、数组等容器类型,会递归检查其内部元素
|
||||
*
|
||||
* @param obj 待判断的对象
|
||||
* @return true-对象为空(包括递归检查),false-对象不为空
|
||||
*/
|
||||
public static boolean isDeepEmpty(Object obj) {
|
||||
return isDeepEmpty(obj, new HashSet<>());
|
||||
}
|
||||
|
||||
/**
|
||||
* 深度判断对象是否为空(递归检查,防止循环引用)
|
||||
*
|
||||
* @param obj 待判断的对象
|
||||
* @param visited 已访问对象集合,用于防止循环引用
|
||||
* @return true-对象为空(包括递归检查),false-对象不为空
|
||||
*/
|
||||
private static boolean isDeepEmpty(Object obj, Set<Object> visited) {
|
||||
if (isEmpty(obj)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 防止循环引用
|
||||
if (visited.contains(obj)) {
|
||||
return false;
|
||||
}
|
||||
visited.add(obj);
|
||||
|
||||
try {
|
||||
// 集合类型递归检查
|
||||
if (obj instanceof Collection) {
|
||||
Collection<?> collection = (Collection<?>) obj;
|
||||
for (Object item : collection) {
|
||||
if (!isDeepEmpty(item, visited)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Map类型递归检查
|
||||
if (obj instanceof Map) {
|
||||
Map<?, ?> map = (Map<?, ?>) obj;
|
||||
for (Map.Entry<?, ?> entry : map.entrySet()) {
|
||||
if (!isDeepEmpty(entry.getKey(), visited) || !isDeepEmpty(entry.getValue(), visited)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// 数组类型递归检查
|
||||
if (obj.getClass().isArray()) {
|
||||
int length = Array.getLength(obj);
|
||||
for (int i = 0; i < length; i++) {
|
||||
if (!isDeepEmpty(Array.get(obj, i), visited)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Optional类型递归检查
|
||||
if (obj instanceof Optional) {
|
||||
Optional<?> optional = (Optional<?>) obj;
|
||||
return !optional.isPresent() || isDeepEmpty(optional.get(), visited);
|
||||
}
|
||||
|
||||
// 其他类型认为不为空
|
||||
return false;
|
||||
|
||||
} finally {
|
||||
visited.remove(obj);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 深度判断对象是否不为空(递归检查)
|
||||
*
|
||||
* @param obj 待判断的对象
|
||||
* @return true-对象不为空(包括递归检查),false-对象为空
|
||||
*/
|
||||
public static boolean isDeepNotEmpty(Object obj) {
|
||||
return !isDeepEmpty(obj);
|
||||
}
|
||||
|
||||
// ======================== 集合专用方法 ========================
|
||||
|
||||
/**
|
||||
* 判断集合是否为空或null
|
||||
*
|
||||
* @param collection 待判断的集合
|
||||
* @return true-集合为null或空,false-集合不为空
|
||||
*/
|
||||
public static boolean isEmptyCollection(Collection<?> collection) {
|
||||
return collection == null || collection.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断集合是否不为空且不为null
|
||||
*
|
||||
* @param collection 待判断的集合
|
||||
* @return true-集合不为null且不为空,false-集合为null或空
|
||||
*/
|
||||
public static boolean isNotEmptyCollection(Collection<?> collection) {
|
||||
return collection != null && !collection.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断集合是否包含有效元素(非null且非空的元素)
|
||||
*
|
||||
* @param collection 待判断的集合
|
||||
* @return true-集合包含有效元素,false-集合为空或只包含null/空元素
|
||||
*/
|
||||
public static boolean hasValidElements(Collection<?> collection) {
|
||||
if (isEmptyCollection(collection)) {
|
||||
return false;
|
||||
}
|
||||
for (Object item : collection) {
|
||||
if (isNotEmpty(item)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断集合是否所有元素都有效(非null且非空)
|
||||
*
|
||||
* @param collection 待判断的集合
|
||||
* @return true-集合所有元素都有效,false-集合为空或包含null/空元素
|
||||
*/
|
||||
public static boolean allValidElements(Collection<?> collection) {
|
||||
if (isEmptyCollection(collection)) {
|
||||
return false;
|
||||
}
|
||||
for (Object item : collection) {
|
||||
if (isEmpty(item)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 过滤集合中的空元素,返回新集合
|
||||
*
|
||||
* @param collection 原集合
|
||||
* @param <T> 集合元素类型
|
||||
* @return 过滤后的新集合
|
||||
*/
|
||||
public static <T> List<T> filterEmpty(Collection<T> collection) {
|
||||
if (isEmptyCollection(collection)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<T> result = new ArrayList<>();
|
||||
for (T item : collection) {
|
||||
if (isNotEmpty(item)) {
|
||||
result.add(item);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// ======================== Map专用方法 ========================
|
||||
|
||||
/**
|
||||
* 判断Map是否为空或null
|
||||
*
|
||||
* @param map 待判断的Map
|
||||
* @return true-Map为null或空,false-Map不为空
|
||||
*/
|
||||
public static boolean isEmptyMap(Map<?, ?> map) {
|
||||
return map == null || map.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断Map是否不为空且不为null
|
||||
*
|
||||
* @param map 待判断的Map
|
||||
* @return true-Map不为null且不为空,false-Map为null或空
|
||||
*/
|
||||
public static boolean isNotEmptyMap(Map<?, ?> map) {
|
||||
return map != null && !map.isEmpty();
|
||||
}
|
||||
|
||||
// ======================== 数组专用方法 ========================
|
||||
|
||||
/**
|
||||
* 判断数组是否为空或null
|
||||
*
|
||||
* @param array 待判断的数组
|
||||
* @return true-数组为null或空,false-数组不为空
|
||||
*/
|
||||
public static boolean isEmptyArray(Object array) {
|
||||
return array == null || !array.getClass().isArray() || Array.getLength(array) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断数组是否不为空且不为null
|
||||
*
|
||||
* @param array 待判断的数组
|
||||
* @return true-数组不为null且不为空,false-数组为null或空
|
||||
*/
|
||||
public static boolean isNotEmptyArray(Object array) {
|
||||
return array != null && array.getClass().isArray() && Array.getLength(array) > 0;
|
||||
}
|
||||
|
||||
// ======================== 字符串专用方法 ========================
|
||||
|
||||
/**
|
||||
* 判断字符串是否为空或null(包括空白字符串)
|
||||
*
|
||||
* @param str 待判断的字符串
|
||||
* @return true-字符串为null、空或只包含空白字符,false-字符串有有效内容
|
||||
*/
|
||||
public static boolean isEmptyString(String str) {
|
||||
return str == null || str.trim().isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断字符串是否不为空且不为null
|
||||
*
|
||||
* @param str 待判断的字符串
|
||||
* @return true-字符串不为null且有有效内容,false-字符串为null、空或只包含空白字符
|
||||
*/
|
||||
public static boolean isNotEmptyString(String str) {
|
||||
return str != null && !str.trim().isEmpty();
|
||||
}
|
||||
|
||||
// ======================== 条件判断方法 ========================
|
||||
|
||||
/**
|
||||
* 如果对象为空则返回默认值
|
||||
*
|
||||
* @param obj 待判断的对象
|
||||
* @param defaultValue 默认值
|
||||
* @param <T> 对象类型
|
||||
* @return 如果obj为空则返回defaultValue,否则返回obj
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T defaultIfEmpty(T obj, T defaultValue) {
|
||||
return isEmpty(obj) ? defaultValue : obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果对象为null则返回默认值
|
||||
*
|
||||
* @param obj 待判断的对象
|
||||
* @param defaultValue 默认值
|
||||
* @param <T> 对象类型
|
||||
* @return 如果obj为null则返回defaultValue,否则返回obj
|
||||
*/
|
||||
public static <T> T defaultIfNull(T obj, T defaultValue) {
|
||||
return isNull(obj) ? defaultValue : obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取第一个非空的对象
|
||||
*
|
||||
* @param objects 对象数组
|
||||
* @param <T> 对象类型
|
||||
* @return 第一个非空的对象,如果都为空则返回null
|
||||
*/
|
||||
@SafeVarargs
|
||||
public static <T> T firstNotEmpty(T... objects) {
|
||||
if (objects == null || objects.length == 0) {
|
||||
return null;
|
||||
}
|
||||
for (T obj : objects) {
|
||||
if (isNotEmpty(obj)) {
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取第一个非null的对象
|
||||
*
|
||||
* @param objects 对象数组
|
||||
* @param <T> 对象类型
|
||||
* @return 第一个非null的对象,如果都为null则返回null
|
||||
*/
|
||||
@SafeVarargs
|
||||
public static <T> T firstNotNull(T... objects) {
|
||||
if (objects == null || objects.length == 0) {
|
||||
return null;
|
||||
}
|
||||
for (T obj : objects) {
|
||||
if (isNotNull(obj)) {
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// ======================== 统计方法 ========================
|
||||
|
||||
/**
|
||||
* 统计数组中非空元素的个数
|
||||
*
|
||||
* @param objects 对象数组
|
||||
* @return 非空元素个数
|
||||
*/
|
||||
public static int countNotEmpty(Object... objects) {
|
||||
if (objects == null || objects.length == 0) {
|
||||
return 0;
|
||||
}
|
||||
int count = 0;
|
||||
for (Object obj : objects) {
|
||||
if (isNotEmpty(obj)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计数组中非null元素的个数
|
||||
*
|
||||
* @param objects 对象数组
|
||||
* @return 非null元素个数
|
||||
*/
|
||||
public static int countNotNull(Object... objects) {
|
||||
if (objects == null || objects.length == 0) {
|
||||
return 0;
|
||||
}
|
||||
int count = 0;
|
||||
for (Object obj : objects) {
|
||||
if (isNotNull(obj)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
// ======================== 断言方法 ========================
|
||||
|
||||
/**
|
||||
* 断言对象不为null,如果为null则抛出异常
|
||||
*
|
||||
* @param obj 待断言的对象
|
||||
* @param message 异常消息
|
||||
* @throws IllegalArgumentException 如果对象为null
|
||||
*/
|
||||
public static void requireNotNull(Object obj, String message) {
|
||||
if (isNull(obj)) {
|
||||
throw new IllegalArgumentException(message != null ? message : "对象不能为null");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 断言对象不为空,如果为空则抛出异常
|
||||
*
|
||||
* @param obj 待断言的对象
|
||||
* @param message 异常消息
|
||||
* @throws IllegalArgumentException 如果对象为空
|
||||
*/
|
||||
public static void requireNotEmpty(Object obj, String message) {
|
||||
if (isEmpty(obj)) {
|
||||
throw new IllegalArgumentException(message != null ? message : "对象不能为空");
|
||||
}
|
||||
}
|
||||
|
||||
// ======================== 类型检查方法 ========================
|
||||
|
||||
/**
|
||||
* 检查对象是否为指定类型且不为null
|
||||
*
|
||||
* @param obj 待检查的对象
|
||||
* @param clazz 目标类型
|
||||
* @param <T> 目标类型
|
||||
* @return true-对象不为null且为指定类型,false-否则
|
||||
*/
|
||||
public static <T> boolean isInstanceAndNotNull(Object obj, Class<T> clazz) {
|
||||
return isNotNull(obj) && clazz.isInstance(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* 安全的类型转换,如果对象为null或不是目标类型则返回null
|
||||
*
|
||||
* @param obj 待转换的对象
|
||||
* @param clazz 目标类型
|
||||
* @param <T> 目标类型
|
||||
* @return 转换后的对象,如果转换失败则返回null
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T safeCast(Object obj, Class<T> clazz) {
|
||||
if (isInstanceAndNotNull(obj, clazz)) {
|
||||
return (T) obj;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,7 @@
|
||||
<!-- 数据库依赖 -->
|
||||
<mysql.version>9.4.0</mysql.version>
|
||||
<hikaricp.version>7.0.2</hikaricp.version>
|
||||
<mybatis-plus.version>3.5.14</mybatis-plus.version>
|
||||
|
||||
<fastjson.version>2.0.58</fastjson.version>
|
||||
<jakarta.servlet.version>6.1.0</jakarta.servlet.version>
|
||||
@@ -130,6 +131,12 @@
|
||||
<version>${hikaricp.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>${mybatis-plus.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- JSON 解析器和生成器 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
|
||||
@@ -18,4 +18,55 @@
|
||||
<maven.compiler.target>21</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- API依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.xyzh</groupId>
|
||||
<artifactId>api-system</artifactId>
|
||||
<version>${school-news.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Common模块依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.xyzh</groupId>
|
||||
<artifactId>common-all</artifactId>
|
||||
<version>${school-news.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Boot Web -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- MyBatis Plus -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MySQL驱动 -->
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 数据库连接池 -->
|
||||
<dependency>
|
||||
<groupId>com.zaxxer</groupId>
|
||||
<artifactId>HikariCP</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Log4j2 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-log4j2</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -1,7 +0,0 @@
|
||||
package org.xyzh;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello world!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.xyzh.system;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* @description SystemApplication.java文件描述 系统管理模块启动类
|
||||
* @filename SystemApplication.java
|
||||
* @author yslg
|
||||
* @copyright xyzh
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@MapperScan("org.xyzh.system.mapper")
|
||||
public class SystemApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SystemApplication.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.xyzh.system.department.service;
|
||||
import org.xyzh.api.system.dept.DepartmentService;
|
||||
|
||||
/**
|
||||
* @description SysDepartmentService.java文件描述 系统部门服务接口
|
||||
* @filename SysDepartmentService.java
|
||||
* @author yslg
|
||||
* @copyright xyzh
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
public interface SysDepartmentService extends DepartmentService {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,289 @@
|
||||
package org.xyzh.system.department.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.xyzh.common.core.domain.ResultDomain;
|
||||
import org.xyzh.common.dto.dept.TbSysDept;
|
||||
import org.xyzh.common.utils.IDUtils;
|
||||
import org.xyzh.system.department.service.SysDepartmentService;
|
||||
import org.xyzh.system.mapper.DepartmentMapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @description SysDepartmentServiceImpl.java文件描述 系统部门服务实现类
|
||||
* @filename SysDepartmentServiceImpl.java
|
||||
* @author yslg
|
||||
* @copyright xyzh
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
@Service
|
||||
public class SysDepartmentServiceImpl implements SysDepartmentService {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SysDepartmentServiceImpl.class);
|
||||
|
||||
@Autowired
|
||||
private DepartmentMapper departmentMapper;
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysDept> getAllDepartments() {
|
||||
ResultDomain<TbSysDept> resultDomain = new ResultDomain<>();
|
||||
|
||||
try {
|
||||
logger.info("开始查询所有部门");
|
||||
|
||||
LambdaQueryWrapper<TbSysDept> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(TbSysDept::getDeleted, false)
|
||||
.orderByAsc(TbSysDept::getCreateTime);
|
||||
|
||||
List<TbSysDept> departments = departmentMapper.selectList(queryWrapper);
|
||||
|
||||
logger.info("查询所有部门完成,共找到{}个部门", departments.size());
|
||||
resultDomain.success("查询成功", departments);
|
||||
return resultDomain;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("查询所有部门失败", e);
|
||||
resultDomain.fail("查询部门失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysDept> getDepartmentById(String deptId) {
|
||||
ResultDomain<TbSysDept> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("开始根据ID查询部门:{}", deptId);
|
||||
|
||||
if (!StringUtils.hasText(deptId)) {
|
||||
resultDomain.fail("部门ID不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<TbSysDept> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(TbSysDept::getDeptID, deptId)
|
||||
.eq(TbSysDept::getDeleted, false);
|
||||
|
||||
TbSysDept department = departmentMapper.selectOne(queryWrapper);
|
||||
|
||||
if (department == null) {
|
||||
logger.warn("未找到部门:{}", deptId);
|
||||
resultDomain.fail("未找到指定部门");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
logger.info("根据ID查询部门完成:{}", deptId);
|
||||
resultDomain.success("查询成功", department);
|
||||
return resultDomain;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("根据ID查询部门失败:{}", deptId, e);
|
||||
resultDomain.fail("查询部门失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysDept> getDepartmentsByParentId(String parentId) {
|
||||
ResultDomain<TbSysDept> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("开始根据父部门ID查询子部门:{}", parentId);
|
||||
|
||||
List<TbSysDept> departments = departmentMapper.selectByParentId(parentId);
|
||||
|
||||
logger.info("根据父部门ID查询子部门完成,共找到{}个子部门", departments.size());
|
||||
resultDomain.success("查询成功", departments);
|
||||
return resultDomain;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("根据父部门ID查询子部门失败:{}", parentId, e);
|
||||
resultDomain.fail("查询子部门失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysDept> createDepartment(TbSysDept department) {
|
||||
ResultDomain<TbSysDept> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("开始创建部门:{}", department.getName());
|
||||
|
||||
// 参数校验
|
||||
if (!StringUtils.hasText(department.getName())) {
|
||||
resultDomain.fail("部门名称不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 检查部门名称是否已存在
|
||||
ResultDomain<Boolean> checkResult = checkDepartmentNameExists(department.getName(), null);
|
||||
if (!checkResult.isSuccess()) {
|
||||
resultDomain.fail(checkResult.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
if (checkResult.getData()) {
|
||||
resultDomain.fail("部门名称已存在");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 设置基础信息
|
||||
department.setID(IDUtils.generateID());
|
||||
department.setDeptID(IDUtils.generateID());
|
||||
department.setCreateTime(new Date());
|
||||
department.setDeleted(false);
|
||||
|
||||
// 插入数据库
|
||||
int result = departmentMapper.insert(department);
|
||||
|
||||
if (result > 0) {
|
||||
logger.info("创建部门成功:{}", department.getName());
|
||||
resultDomain.success("创建部门成功", department);
|
||||
return resultDomain;
|
||||
} else {
|
||||
logger.warn("创建部门失败:{}", department.getName());
|
||||
resultDomain.fail("创建部门失败");
|
||||
}
|
||||
|
||||
return resultDomain;
|
||||
} catch (Exception e) {
|
||||
logger.error("创建部门异常:{}", department.getName(), e);
|
||||
resultDomain.fail("创建部门失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysDept> updateDepartment(TbSysDept department) {
|
||||
ResultDomain<TbSysDept> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("开始更新部门:{}", department.getDeptID());
|
||||
|
||||
// 参数校验
|
||||
if (!StringUtils.hasText(department.getDeptID())) {
|
||||
resultDomain.fail("部门ID不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
if (!StringUtils.hasText(department.getName())) {
|
||||
resultDomain.fail("部门名称不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 检查部门是否存在
|
||||
ResultDomain<TbSysDept> existResult = getDepartmentById(department.getDeptID());
|
||||
if (!existResult.isSuccess()) {
|
||||
resultDomain.fail(existResult.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 检查部门名称是否已存在(排除自身)
|
||||
ResultDomain<Boolean> checkResult = checkDepartmentNameExists(department.getName(), department.getID());
|
||||
if (!checkResult.isSuccess()) {
|
||||
resultDomain.fail(checkResult.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
if (checkResult.getData()) {
|
||||
resultDomain.fail("部门名称已存在");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 设置更新时间
|
||||
department.setUpdateTime(new Date());
|
||||
|
||||
// 更新数据库
|
||||
int result = departmentMapper.updateById(department);
|
||||
|
||||
if (result > 0) {
|
||||
logger.info("更新部门成功:{}", department.getDeptID());
|
||||
resultDomain.success("更新部门成功", department);
|
||||
return resultDomain;
|
||||
} else {
|
||||
logger.warn("更新部门失败:{}", department.getDeptID());
|
||||
resultDomain.fail("更新部门失败");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("更新部门异常:{}", department.getDeptID(), e);
|
||||
resultDomain.fail("更新部门失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysDept> deleteDepartment(String deptId) {
|
||||
ResultDomain<TbSysDept> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("开始删除部门:{}", deptId);
|
||||
|
||||
if (!StringUtils.hasText(deptId)) {
|
||||
resultDomain.fail("部门ID不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 检查部门是否存在
|
||||
ResultDomain<TbSysDept> existResult = getDepartmentById(deptId);
|
||||
if (!existResult.isSuccess()) {
|
||||
resultDomain.fail(existResult.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 检查是否有子部门
|
||||
ResultDomain<TbSysDept> childrenResult = getDepartmentsByParentId(deptId);
|
||||
if (childrenResult.isSuccess() && childrenResult.getData() != null) {
|
||||
resultDomain.fail("该部门下有子部门,无法删除");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 逻辑删除
|
||||
TbSysDept department = existResult.getData();
|
||||
department.setDeleted(true);
|
||||
department.setDeleteTime(new Date());
|
||||
|
||||
int result = departmentMapper.updateById(department);
|
||||
|
||||
if (result > 0) {
|
||||
logger.info("删除部门成功:{}", deptId);
|
||||
resultDomain.success("删除部门成功", department);
|
||||
return resultDomain;
|
||||
} else {
|
||||
logger.warn("删除部门失败:{}", deptId);
|
||||
resultDomain.fail("删除部门失败");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("删除部门异常:{}", deptId, e);
|
||||
resultDomain.fail("删除部门失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<Boolean> checkDepartmentNameExists(String deptName, String excludeId) {
|
||||
ResultDomain<Boolean> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("检查部门名称是否存在:{}", deptName);
|
||||
|
||||
if (!StringUtils.hasText(deptName)) {
|
||||
resultDomain.fail("部门名称不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
int count = departmentMapper.countByDeptName(deptName, excludeId);
|
||||
boolean exists = count > 0;
|
||||
|
||||
logger.info("部门名称存在性检查完成:{},存在:{}", deptName, exists);
|
||||
resultDomain.success("检查完成", exists);
|
||||
return resultDomain;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("检查部门名称存在性失败:{}", deptName, e);
|
||||
resultDomain.fail("检查失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package org.xyzh.system.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.xyzh.common.dto.dept.TbSysDept;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @description DepartmentMapper.java文件描述 部门数据访问层
|
||||
* @filename DepartmentMapper.java
|
||||
* @author yslg
|
||||
* @copyright xyzh
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
@Mapper
|
||||
public interface DepartmentMapper extends BaseMapper<TbSysDept> {
|
||||
|
||||
/**
|
||||
* @description 根据父部门ID查询子部门列表
|
||||
* @param parentId 父部门ID
|
||||
* @return List<TbSysDept> 子部门列表
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
List<TbSysDept> selectByParentId(@Param("parentId") String parentId);
|
||||
|
||||
/**
|
||||
* @description 检查部门名称是否存在
|
||||
* @param deptName 部门名称
|
||||
* @param excludeId 排除的部门ID(用于更新时排除自身)
|
||||
* @return int 存在的数量
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
int countByDeptName(@Param("deptName") String deptName, @Param("excludeId") String excludeId);
|
||||
|
||||
/**
|
||||
* @description 根据部门ID查询部门信息(包含父部门信息)
|
||||
* @param deptId 部门ID
|
||||
* @return TbSysDept 部门信息
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
TbSysDept selectDeptWithParent(@Param("deptId") String deptId);
|
||||
|
||||
/**
|
||||
* @description 查询部门树结构
|
||||
* @return List<TbSysDept> 部门树
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
List<TbSysDept> selectDeptTree();
|
||||
|
||||
/**
|
||||
* @description 批量删除部门(逻辑删除)
|
||||
* @param deptIds 部门ID列表
|
||||
* @param updater 更新人
|
||||
* @return int 影响行数
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
int batchDeleteByIds(@Param("deptIds") List<String> deptIds, @Param("updater") String updater);
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package org.xyzh.system.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.xyzh.common.dto.menu.TbSysMenu;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @description MenuMapper.java文件描述 菜单数据访问层
|
||||
* @filename MenuMapper.java
|
||||
* @author yslg
|
||||
* @copyright xyzh
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
@Mapper
|
||||
public interface MenuMapper extends BaseMapper<TbSysMenu> {
|
||||
|
||||
/**
|
||||
* @description 根据用户ID查询菜单列表
|
||||
* @param userId 用户ID
|
||||
* @return List<TbSysMenu> 菜单列表
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
List<TbSysMenu> selectMenusByUserId(@Param("userId") String userId);
|
||||
|
||||
/**
|
||||
* @description 根据角色ID查询菜单列表
|
||||
* @param roleId 角色ID
|
||||
* @return List<TbSysMenu> 菜单列表
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
List<TbSysMenu> selectMenusByRoleId(@Param("roleId") String roleId);
|
||||
|
||||
/**
|
||||
* @description 根据父菜单ID查询子菜单列表
|
||||
* @param parentId 父菜单ID
|
||||
* @return List<TbSysMenu> 子菜单列表
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
List<TbSysMenu> selectByParentId(@Param("parentId") String parentId);
|
||||
|
||||
/**
|
||||
* @description 查询菜单树结构
|
||||
* @return List<TbSysMenu> 菜单树
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
List<TbSysMenu> selectMenuTree();
|
||||
|
||||
/**
|
||||
* @description 检查菜单名称是否存在
|
||||
* @param menuName 菜单名称
|
||||
* @param excludeId 排除的菜单ID
|
||||
* @return int 存在数量
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
int countByMenuName(@Param("menuName") String menuName, @Param("excludeId") String excludeId);
|
||||
|
||||
/**
|
||||
* @description 批量删除菜单(逻辑删除)
|
||||
* @param menuIds 菜单ID列表
|
||||
* @param updater 更新人
|
||||
* @return int 影响行数
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
int batchDeleteByIds(@Param("menuIds") List<String> menuIds, @Param("updater") String updater);
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package org.xyzh.system.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.xyzh.common.dto.permission.TbSysPermission;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @description PermissionMapper.java文件描述 权限数据访问层
|
||||
* @filename PermissionMapper.java
|
||||
* @author yslg
|
||||
* @copyright xyzh
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
@Mapper
|
||||
public interface PermissionMapper extends BaseMapper<TbSysPermission> {
|
||||
|
||||
/**
|
||||
* @description 根据用户ID查询权限列表
|
||||
* @param userId 用户ID
|
||||
* @return List<TbSysPermission> 权限列表
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
List<TbSysPermission> selectPermissionsByUserId(@Param("userId") String userId);
|
||||
|
||||
/**
|
||||
* @description 根据角色ID查询权限列表
|
||||
* @param roleId 角色ID
|
||||
* @return List<TbSysPermission> 权限列表
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
List<TbSysPermission> selectPermissionsByRoleId(@Param("roleId") String roleId);
|
||||
|
||||
/**
|
||||
* @description 根据权限编码查询权限
|
||||
* @param permissionCode 权限编码
|
||||
* @return TbSysPermission 权限信息
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
TbSysPermission selectByPermissionCode(@Param("permissionCode") String permissionCode);
|
||||
|
||||
/**
|
||||
* @description 检查权限名称是否存在
|
||||
* @param permissionName 权限名称
|
||||
* @param excludeId 排除的权限ID
|
||||
* @return int 存在数量
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
int countByPermissionName(@Param("permissionName") String permissionName, @Param("excludeId") String excludeId);
|
||||
|
||||
/**
|
||||
* @description 检查权限编码是否存在
|
||||
* @param permissionCode 权限编码
|
||||
* @param excludeId 排除的权限ID
|
||||
* @return int 存在数量
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
int countByPermissionCode(@Param("permissionCode") String permissionCode, @Param("excludeId") String excludeId);
|
||||
|
||||
/**
|
||||
* @description 批量删除权限(逻辑删除)
|
||||
* @param permissionIds 权限ID列表
|
||||
* @param updater 更新人
|
||||
* @return int 影响行数
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
int batchDeleteByIds(@Param("permissionIds") List<String> permissionIds, @Param("updater") String updater);
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package org.xyzh.system.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.xyzh.common.dto.role.TbSysRole;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @description RoleMapper.java文件描述 角色数据访问层
|
||||
* @filename RoleMapper.java
|
||||
* @author yslg
|
||||
* @copyright xyzh
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
@Mapper
|
||||
public interface RoleMapper extends BaseMapper<TbSysRole> {
|
||||
|
||||
/**
|
||||
* @description 根据用户ID查询角色列表
|
||||
* @param userId 用户ID
|
||||
* @return List<TbSysRole> 角色列表
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
List<TbSysRole> selectRolesByUserId(@Param("userId") String userId);
|
||||
|
||||
/**
|
||||
* @description 根据角色编码查询角色
|
||||
* @param roleCode 角色编码
|
||||
* @return TbSysRole 角色信息
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
TbSysRole selectByRoleCode(@Param("roleCode") String roleCode);
|
||||
|
||||
/**
|
||||
* @description 检查角色名称是否存在
|
||||
* @param roleName 角色名称
|
||||
* @param excludeId 排除的角色ID
|
||||
* @return int 存在数量
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
int countByRoleName(@Param("roleName") String roleName, @Param("excludeId") String excludeId);
|
||||
|
||||
/**
|
||||
* @description 检查角色编码是否存在
|
||||
* @param roleCode 角色编码
|
||||
* @param excludeId 排除的角色ID
|
||||
* @return int 存在数量
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
int countByRoleCode(@Param("roleCode") String roleCode, @Param("excludeId") String excludeId);
|
||||
|
||||
/**
|
||||
* @description 批量删除角色(逻辑删除)
|
||||
* @param roleIds 角色ID列表
|
||||
* @param updater 更新人
|
||||
* @return int 影响行数
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
int batchDeleteByIds(@Param("roleIds") List<String> roleIds, @Param("updater") String updater);
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package org.xyzh.system.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.xyzh.common.dto.user.TbSysUser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @description UserMapper.java文件描述 用户数据访问层
|
||||
* @filename UserMapper.java
|
||||
* @author yslg
|
||||
* @copyright xyzh
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
@Mapper
|
||||
public interface UserMapper extends BaseMapper<TbSysUser> {
|
||||
|
||||
/**
|
||||
* @description 根据用户名查询用户
|
||||
* @param username 用户名
|
||||
* @return TbSysUser 用户信息
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
TbSysUser selectByUsername(@Param("username") String username);
|
||||
|
||||
/**
|
||||
* @description 根据邮箱查询用户
|
||||
* @param email 邮箱
|
||||
* @return TbSysUser 用户信息
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
TbSysUser selectByEmail(@Param("email") String email);
|
||||
|
||||
/**
|
||||
* @description 根据手机号查询用户
|
||||
* @param phone 手机号
|
||||
* @return TbSysUser 用户信息
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
TbSysUser selectByPhone(@Param("phone") String phone);
|
||||
|
||||
/**
|
||||
* @description 根据过滤条件查询用户
|
||||
* @param filter 过滤条件
|
||||
* @return TbSysUser 用户信息
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
TbSysUser selectByFilter(@Param("filter") TbSysUser filter);
|
||||
|
||||
/**
|
||||
* @description 查询用户列表(分页)
|
||||
* @param username 用户名(模糊查询)
|
||||
* @param email 邮箱(模糊查询)
|
||||
* @param status 用户状态
|
||||
* @return List<TbSysUser> 用户列表
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
List<TbSysUser> selectUserList(@Param("username") String username,
|
||||
@Param("email") String email,
|
||||
@Param("status") String status);
|
||||
|
||||
/**
|
||||
* @description 批量删除用户(逻辑删除)
|
||||
* @param userIds 用户ID列表
|
||||
* @param updater 更新人
|
||||
* @return int 影响行数
|
||||
* @author yslg
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
int batchDeleteByIds(@Param("userIds") List<String> userIds, @Param("updater") String updater);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package org.xyzh.system.menu.service;
|
||||
|
||||
import org.xyzh.api.system.menu.MenuService;
|
||||
|
||||
/**
|
||||
* @description SysMenuService.java文件描述 系统菜单服务接口
|
||||
* @filename SysMenuService.java
|
||||
* @author yslg
|
||||
* @copyright xyzh
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
public interface SysMenuService extends MenuService {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,448 @@
|
||||
package org.xyzh.system.menu.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.xyzh.common.core.domain.ResultDomain;
|
||||
import org.xyzh.common.dto.menu.TbSysMenu;
|
||||
import org.xyzh.common.utils.IDUtils;
|
||||
import org.xyzh.system.mapper.MenuMapper;
|
||||
import org.xyzh.system.menu.service.SysMenuService;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @description SysMenuServiceImpl.java文件描述 系统菜单服务实现类
|
||||
* @filename SysMenuServiceImpl.java
|
||||
* @author yslg
|
||||
* @copyright xyzh
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
@Service
|
||||
public class SysMenuServiceImpl implements SysMenuService {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SysMenuServiceImpl.class);
|
||||
|
||||
@Autowired
|
||||
private MenuMapper menuMapper;
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysMenu> getAllMenus() {
|
||||
ResultDomain<TbSysMenu> resultDomain = new ResultDomain<>();
|
||||
|
||||
try {
|
||||
logger.info("开始查询所有菜单");
|
||||
|
||||
LambdaQueryWrapper<TbSysMenu> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(TbSysMenu::getDeleted, false)
|
||||
.orderByAsc(TbSysMenu::getCreateTime);
|
||||
|
||||
List<TbSysMenu> menus = menuMapper.selectList(queryWrapper);
|
||||
|
||||
logger.info("查询所有菜单完成,共找到{}个菜单", menus.size());
|
||||
resultDomain.success("查询成功", menus);
|
||||
return resultDomain;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("查询所有菜单失败", e);
|
||||
resultDomain.fail("查询菜单失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysMenu> getMenuById(String menuId) {
|
||||
ResultDomain<TbSysMenu> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("开始根据ID查询菜单:{}", menuId);
|
||||
|
||||
if (!StringUtils.hasText(menuId)) {
|
||||
resultDomain.fail("菜单ID不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<TbSysMenu> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(TbSysMenu::getMenuID, menuId)
|
||||
.eq(TbSysMenu::getDeleted, false);
|
||||
|
||||
TbSysMenu menu = menuMapper.selectOne(queryWrapper);
|
||||
|
||||
if (menu == null) {
|
||||
logger.warn("未找到菜单:{}", menuId);
|
||||
resultDomain.fail("未找到指定菜单");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
logger.info("根据ID查询菜单完成:{}", menuId);
|
||||
resultDomain.success("查询成功", menu);
|
||||
return resultDomain;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("根据ID查询菜单失败:{}", menuId, e);
|
||||
resultDomain.fail("查询菜单失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysMenu> getMenusByUserId(String userId) {
|
||||
ResultDomain<TbSysMenu> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("开始根据用户ID查询菜单列表:{}", userId);
|
||||
|
||||
if (!StringUtils.hasText(userId)) {
|
||||
resultDomain.fail("用户ID不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
List<TbSysMenu> menus = menuMapper.selectMenusByUserId(userId);
|
||||
|
||||
logger.info("根据用户ID查询菜单列表完成,共找到{}个菜单", menus.size());
|
||||
resultDomain.success("查询成功", menus);
|
||||
return resultDomain;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("根据用户ID查询菜单列表失败:{}", userId, e);
|
||||
resultDomain.fail("查询菜单失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysMenu> getMenusByRoleId(String roleId) {
|
||||
ResultDomain<TbSysMenu> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("开始根据角色ID查询菜单列表:{}", roleId);
|
||||
|
||||
if (!StringUtils.hasText(roleId)) {
|
||||
resultDomain.fail("角色ID不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
List<TbSysMenu> menus = menuMapper.selectMenusByRoleId(roleId);
|
||||
|
||||
logger.info("根据角色ID查询菜单列表完成,共找到{}个菜单", menus.size());
|
||||
resultDomain.success("查询成功", menus);
|
||||
return resultDomain;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("根据角色ID查询菜单列表失败:{}", roleId, e);
|
||||
resultDomain.fail("查询菜单失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysMenu> getMenusByParentId(String parentId) {
|
||||
ResultDomain<TbSysMenu> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("开始根据父菜单ID查询子菜单:{}", parentId);
|
||||
|
||||
List<TbSysMenu> menus = menuMapper.selectByParentId(parentId);
|
||||
|
||||
logger.info("根据父菜单ID查询子菜单完成,共找到{}个子菜单", menus.size());
|
||||
resultDomain.success("查询成功", menus);
|
||||
return resultDomain;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("根据父菜单ID查询子菜单失败:{}", parentId, e);
|
||||
resultDomain.fail("查询子菜单失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysMenu> getMenuTree() {
|
||||
ResultDomain<TbSysMenu> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("开始查询菜单树结构");
|
||||
|
||||
List<TbSysMenu> menus = menuMapper.selectMenuTree();
|
||||
|
||||
logger.info("查询菜单树结构完成,共找到{}个菜单", menus.size());
|
||||
resultDomain.success("查询成功", menus);
|
||||
return resultDomain;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("查询菜单树结构失败", e);
|
||||
resultDomain.fail("查询菜单树失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysMenu> createMenu(TbSysMenu menu) {
|
||||
ResultDomain<TbSysMenu> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("开始创建菜单:{}", menu.getName());
|
||||
|
||||
// 参数校验
|
||||
if (!StringUtils.hasText(menu.getName())) {
|
||||
resultDomain.fail("菜单名称不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 检查菜单名称是否已存在
|
||||
ResultDomain<Boolean> checkResult = checkMenuNameExists(menu.getName(), null);
|
||||
if (!checkResult.isSuccess()) {
|
||||
resultDomain.fail(checkResult.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
if (checkResult.getData()) {
|
||||
resultDomain.fail("菜单名称已存在");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 设置基础信息
|
||||
menu.setID(IDUtils.generateID());
|
||||
menu.setMenuID(IDUtils.generateID());
|
||||
menu.setCreateTime(new Date());
|
||||
menu.setDeleted(false);
|
||||
|
||||
|
||||
// 插入数据库
|
||||
int result = menuMapper.insert(menu);
|
||||
|
||||
if (result > 0) {
|
||||
logger.info("创建菜单成功:{}", menu.getName());
|
||||
resultDomain.success("创建菜单成功", menu);
|
||||
return resultDomain;
|
||||
} else {
|
||||
logger.warn("创建菜单失败:{}", menu.getName());
|
||||
resultDomain.fail("创建菜单失败");
|
||||
}
|
||||
|
||||
return resultDomain;
|
||||
} catch (Exception e) {
|
||||
logger.error("创建菜单异常:{}", menu.getName(), e);
|
||||
resultDomain.fail("创建菜单失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysMenu> updateMenu(TbSysMenu menu) {
|
||||
ResultDomain<TbSysMenu> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("开始更新菜单:{}", menu.getMenuID());
|
||||
|
||||
// 参数校验
|
||||
if (!StringUtils.hasText(menu.getMenuID())) {
|
||||
resultDomain.fail("菜单ID不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
if (!StringUtils.hasText(menu.getName())) {
|
||||
resultDomain.fail("菜单名称不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 检查菜单是否存在
|
||||
ResultDomain<TbSysMenu> existResult = getMenuById(menu.getMenuID());
|
||||
if (!existResult.isSuccess()) {
|
||||
resultDomain.fail(existResult.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 检查菜单名称是否已存在(排除自身)
|
||||
ResultDomain<Boolean> checkResult = checkMenuNameExists(menu.getName(), menu.getID());
|
||||
if (!checkResult.isSuccess()) {
|
||||
resultDomain.fail(checkResult.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
if (checkResult.getData()) {
|
||||
resultDomain.fail("菜单名称已存在");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 设置更新时间
|
||||
menu.setUpdateTime(new Date());
|
||||
|
||||
// 更新数据库
|
||||
int result = menuMapper.updateById(menu);
|
||||
|
||||
if (result > 0) {
|
||||
logger.info("更新菜单成功:{}", menu.getMenuID());
|
||||
resultDomain.success("更新菜单成功", menu);
|
||||
return resultDomain;
|
||||
} else {
|
||||
logger.warn("更新菜单失败:{}", menu.getMenuID());
|
||||
resultDomain.fail("更新菜单失败");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("更新菜单异常:{}", menu.getMenuID(), e);
|
||||
resultDomain.fail("更新菜单失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysMenu> deleteMenu(String menuId) {
|
||||
ResultDomain<TbSysMenu> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("开始删除菜单:{}", menuId);
|
||||
|
||||
if (!StringUtils.hasText(menuId)) {
|
||||
resultDomain.fail("菜单ID不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 检查菜单是否存在
|
||||
ResultDomain<TbSysMenu> existResult = getMenuById(menuId);
|
||||
if (!existResult.isSuccess()) {
|
||||
resultDomain.fail(existResult.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 检查是否有子菜单
|
||||
ResultDomain<TbSysMenu> childrenResult = getMenusByParentId(menuId);
|
||||
if (childrenResult.isSuccess() && childrenResult.getData() != null) {
|
||||
resultDomain.fail("该菜单下有子菜单,无法删除");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 逻辑删除
|
||||
TbSysMenu menu = existResult.getData();
|
||||
menu.setDeleted(true);
|
||||
menu.setDeleteTime(new Date());
|
||||
|
||||
int result = menuMapper.updateById(menu);
|
||||
|
||||
if (result > 0) {
|
||||
logger.info("删除菜单成功:{}", menuId);
|
||||
resultDomain.success("删除菜单成功", menu);
|
||||
return resultDomain;
|
||||
} else {
|
||||
logger.warn("删除菜单失败:{}", menuId);
|
||||
resultDomain.fail("删除菜单失败");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("删除菜单异常:{}", menuId, e);
|
||||
resultDomain.fail("删除菜单失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<Boolean> checkMenuNameExists(String menuName, String excludeId) {
|
||||
ResultDomain<Boolean> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("检查菜单名称是否存在:{}", menuName);
|
||||
|
||||
if (!StringUtils.hasText(menuName)) {
|
||||
resultDomain.fail("菜单名称不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
int count = menuMapper.countByMenuName(menuName, excludeId);
|
||||
boolean exists = count > 0;
|
||||
|
||||
logger.info("菜单名称存在性检查完成:{},存在:{}", menuName, exists);
|
||||
resultDomain.success("检查完成", exists);
|
||||
return resultDomain;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("检查菜单名称存在性失败:{}", menuName, e);
|
||||
resultDomain.fail("检查失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysMenu> changeMenuStatus(String menuId, Integer status) {
|
||||
ResultDomain<TbSysMenu> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("开始修改菜单状态:{},状态:{}", menuId, status);
|
||||
|
||||
if (!StringUtils.hasText(menuId)) {
|
||||
resultDomain.fail("菜单ID不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
if (status == null) {
|
||||
resultDomain.fail("菜单状态不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 检查菜单是否存在
|
||||
ResultDomain<TbSysMenu> existResult = getMenuById(menuId);
|
||||
if (!existResult.isSuccess()) {
|
||||
resultDomain.fail(existResult.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
TbSysMenu menu = existResult.getData();
|
||||
|
||||
menu.setUpdateTime(new Date());
|
||||
|
||||
int result = menuMapper.updateById(menu);
|
||||
|
||||
if (result > 0) {
|
||||
logger.info("修改菜单状态成功:{}", menuId);
|
||||
resultDomain.success("修改菜单状态成功", menu);
|
||||
return resultDomain;
|
||||
} else {
|
||||
logger.warn("修改菜单状态失败:{}", menuId);
|
||||
resultDomain.fail("修改菜单状态失败");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("修改菜单状态异常:{}", menuId, e);
|
||||
resultDomain.fail("修改菜单状态失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysMenu> changeMenuVisibility(String menuId, Boolean visible) {
|
||||
ResultDomain<TbSysMenu> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("开始修改菜单可见性:{},可见性:{}", menuId, visible);
|
||||
|
||||
if (!StringUtils.hasText(menuId)) {
|
||||
resultDomain.fail("菜单ID不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
if (visible == null) {
|
||||
resultDomain.fail("菜单可见性不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 检查菜单是否存在
|
||||
ResultDomain<TbSysMenu> existResult = getMenuById(menuId);
|
||||
if (!existResult.isSuccess()) {
|
||||
resultDomain.fail(existResult.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
TbSysMenu menu = existResult.getData();
|
||||
menu.setUpdateTime(new Date());
|
||||
|
||||
int result = menuMapper.updateById(menu);
|
||||
|
||||
if (result > 0) {
|
||||
logger.info("修改菜单可见性成功:{}", menuId);
|
||||
resultDomain.success("修改菜单可见性成功", menu);
|
||||
return resultDomain;
|
||||
} else {
|
||||
logger.warn("修改菜单可见性失败:{}", menuId);
|
||||
resultDomain.fail("修改菜单可见性失败");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("修改菜单可见性异常:{}", menuId, e);
|
||||
resultDomain.fail("修改菜单可见性失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package org.xyzh.system.permission.service;
|
||||
|
||||
import org.xyzh.api.system.permission.PermissionService;
|
||||
|
||||
/**
|
||||
* @description SysPermissionService.java文件描述 系统权限服务接口
|
||||
* @filename SysPermissionService.java
|
||||
* @author yslg
|
||||
* @copyright xyzh
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
public interface SysPermissionService extends PermissionService {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,445 @@
|
||||
package org.xyzh.system.permission.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.xyzh.common.core.domain.ResultDomain;
|
||||
import org.xyzh.common.dto.permission.TbSysPermission;
|
||||
import org.xyzh.common.utils.IDUtils;
|
||||
import org.xyzh.system.mapper.PermissionMapper;
|
||||
import org.xyzh.system.permission.service.SysPermissionService;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @description SysPermissionServiceImpl.java文件描述 系统权限服务实现类
|
||||
* @filename SysPermissionServiceImpl.java
|
||||
* @author yslg
|
||||
* @copyright xyzh
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
@Service
|
||||
public class SysPermissionServiceImpl implements SysPermissionService {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SysPermissionServiceImpl.class);
|
||||
|
||||
@Autowired
|
||||
private PermissionMapper permissionMapper;
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysPermission> getAllPermissions() {
|
||||
ResultDomain<TbSysPermission> resultDomain = new ResultDomain<>();
|
||||
|
||||
try {
|
||||
logger.info("开始查询所有权限");
|
||||
|
||||
LambdaQueryWrapper<TbSysPermission> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(TbSysPermission::getDeleted, false)
|
||||
.orderByAsc(TbSysPermission::getCreateTime);
|
||||
|
||||
List<TbSysPermission> permissions = permissionMapper.selectList(queryWrapper);
|
||||
|
||||
logger.info("查询所有权限完成,共找到{}个权限", permissions.size());
|
||||
resultDomain.success("查询成功", permissions);
|
||||
return resultDomain;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("查询所有权限失败", e);
|
||||
resultDomain.fail("查询权限失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysPermission> getPermissionById(String permissionId) {
|
||||
ResultDomain<TbSysPermission> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("开始根据ID查询权限:{}", permissionId);
|
||||
|
||||
if (!StringUtils.hasText(permissionId)) {
|
||||
resultDomain.fail("权限ID不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<TbSysPermission> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(TbSysPermission::getPermissionID, permissionId)
|
||||
.eq(TbSysPermission::getDeleted, false);
|
||||
|
||||
TbSysPermission permission = permissionMapper.selectOne(queryWrapper);
|
||||
|
||||
if (permission == null) {
|
||||
logger.warn("未找到权限:{}", permissionId);
|
||||
resultDomain.fail("未找到指定权限");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
logger.info("根据ID查询权限完成:{}", permissionId);
|
||||
resultDomain.success("查询成功", permission);
|
||||
return resultDomain;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("根据ID查询权限失败:{}", permissionId, e);
|
||||
resultDomain.fail("查询权限失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysPermission> getPermissionByCode(String permissionCode) {
|
||||
ResultDomain<TbSysPermission> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("开始根据权限编码查询权限:{}", permissionCode);
|
||||
|
||||
if (!StringUtils.hasText(permissionCode)) {
|
||||
resultDomain.fail("权限编码不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
TbSysPermission permission = permissionMapper.selectByPermissionCode(permissionCode);
|
||||
|
||||
if (permission == null) {
|
||||
logger.warn("未找到权限:{}", permissionCode);
|
||||
resultDomain.fail("未找到指定权限");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
logger.info("根据权限编码查询权限完成:{}", permissionCode);
|
||||
resultDomain.success("查询成功", permission);
|
||||
return resultDomain;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("根据权限编码查询权限失败:{}", permissionCode, e);
|
||||
resultDomain.fail("查询权限失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysPermission> getPermissionsByUserId(String userId) {
|
||||
ResultDomain<TbSysPermission> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("开始根据用户ID查询权限列表:{}", userId);
|
||||
|
||||
if (!StringUtils.hasText(userId)) {
|
||||
resultDomain.fail("用户ID不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
List<TbSysPermission> permissions = permissionMapper.selectPermissionsByUserId(userId);
|
||||
|
||||
logger.info("根据用户ID查询权限列表完成,共找到{}个权限", permissions.size());
|
||||
resultDomain.success("查询成功", permissions);
|
||||
return resultDomain;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("根据用户ID查询权限列表失败:{}", userId, e);
|
||||
resultDomain.fail("查询权限失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysPermission> getPermissionsByRoleId(String roleId) {
|
||||
ResultDomain<TbSysPermission> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("开始根据角色ID查询权限列表:{}", roleId);
|
||||
|
||||
if (!StringUtils.hasText(roleId)) {
|
||||
resultDomain.fail("角色ID不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
List<TbSysPermission> permissions = permissionMapper.selectPermissionsByRoleId(roleId);
|
||||
|
||||
logger.info("根据角色ID查询权限列表完成,共找到{}个权限", permissions.size());
|
||||
resultDomain.success("查询成功", permissions);
|
||||
return resultDomain;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("根据角色ID查询权限列表失败:{}", roleId, e);
|
||||
resultDomain.fail("查询权限失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysPermission> createPermission(TbSysPermission permission) {
|
||||
ResultDomain<TbSysPermission> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("开始创建权限:{}", permission.getName());
|
||||
|
||||
// 参数校验
|
||||
if (!StringUtils.hasText(permission.getName())) {
|
||||
resultDomain.fail("权限名称不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
if (!StringUtils.hasText(permission.getCode())) {
|
||||
resultDomain.fail("权限编码不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 检查权限名称是否已存在
|
||||
ResultDomain<Boolean> nameCheckResult = checkPermissionNameExists(permission.getName(), null);
|
||||
if (!nameCheckResult.isSuccess()) {
|
||||
resultDomain.fail(nameCheckResult.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
if (nameCheckResult.getData()) {
|
||||
resultDomain.fail("权限名称已存在");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 检查权限编码是否已存在
|
||||
ResultDomain<Boolean> codeCheckResult = checkPermissionCodeExists(permission.getCode(), null);
|
||||
if (!codeCheckResult.isSuccess()) {
|
||||
resultDomain.fail(codeCheckResult.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
if (codeCheckResult.getData()) {
|
||||
resultDomain.fail("权限编码已存在");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 设置基础信息
|
||||
permission.setID(IDUtils.generateID());
|
||||
permission.setPermissionID(IDUtils.generateID());
|
||||
permission.setCreateTime(new Date());
|
||||
permission.setDeleted(false);
|
||||
|
||||
// 插入数据库
|
||||
int result = permissionMapper.insert(permission);
|
||||
|
||||
if (result > 0) {
|
||||
logger.info("创建权限成功:{}", permission.getName());
|
||||
resultDomain.success("创建权限成功", permission);
|
||||
return resultDomain;
|
||||
} else {
|
||||
logger.warn("创建权限失败:{}", permission.getName());
|
||||
resultDomain.fail("创建权限失败");
|
||||
}
|
||||
|
||||
return resultDomain;
|
||||
} catch (Exception e) {
|
||||
logger.error("创建权限异常:{}", permission.getName(), e);
|
||||
resultDomain.fail("创建权限失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysPermission> updatePermission(TbSysPermission permission) {
|
||||
ResultDomain<TbSysPermission> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("开始更新权限:{}", permission.getPermissionID());
|
||||
|
||||
// 参数校验
|
||||
if (!StringUtils.hasText(permission.getPermissionID())) {
|
||||
resultDomain.fail("权限ID不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
if (!StringUtils.hasText(permission.getName())) {
|
||||
resultDomain.fail("权限名称不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
if (!StringUtils.hasText(permission.getCode())) {
|
||||
resultDomain.fail("权限编码不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 检查权限是否存在
|
||||
ResultDomain<TbSysPermission> existResult = getPermissionById(permission.getPermissionID());
|
||||
if (!existResult.isSuccess()) {
|
||||
resultDomain.fail(existResult.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 检查权限名称是否已存在(排除自身)
|
||||
ResultDomain<Boolean> nameCheckResult = checkPermissionNameExists(permission.getName(), permission.getID());
|
||||
if (!nameCheckResult.isSuccess()) {
|
||||
resultDomain.fail(nameCheckResult.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
if (nameCheckResult.getData()) {
|
||||
resultDomain.fail("权限名称已存在");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 检查权限编码是否已存在(排除自身)
|
||||
ResultDomain<Boolean> codeCheckResult = checkPermissionCodeExists(permission.getCode(), permission.getID());
|
||||
if (!codeCheckResult.isSuccess()) {
|
||||
resultDomain.fail(codeCheckResult.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
if (codeCheckResult.getData()) {
|
||||
resultDomain.fail("权限编码已存在");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 设置更新时间
|
||||
permission.setUpdateTime(new Date());
|
||||
|
||||
// 更新数据库
|
||||
int result = permissionMapper.updateById(permission);
|
||||
|
||||
if (result > 0) {
|
||||
logger.info("更新权限成功:{}", permission.getPermissionID());
|
||||
resultDomain.success("更新权限成功", permission);
|
||||
return resultDomain;
|
||||
} else {
|
||||
logger.warn("更新权限失败:{}", permission.getPermissionID());
|
||||
resultDomain.fail("更新权限失败");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("更新权限异常:{}", permission.getPermissionID(), e);
|
||||
resultDomain.fail("更新权限失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysPermission> deletePermission(String permissionId) {
|
||||
ResultDomain<TbSysPermission> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("开始删除权限:{}", permissionId);
|
||||
|
||||
if (!StringUtils.hasText(permissionId)) {
|
||||
resultDomain.fail("权限ID不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 检查权限是否存在
|
||||
ResultDomain<TbSysPermission> existResult = getPermissionById(permissionId);
|
||||
if (!existResult.isSuccess()) {
|
||||
resultDomain.fail(existResult.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// TODO: 检查权限是否被角色使用,如果被使用则不能删除
|
||||
|
||||
// 逻辑删除
|
||||
TbSysPermission permission = existResult.getData();
|
||||
permission.setDeleted(true);
|
||||
permission.setDeleteTime(new Date());
|
||||
|
||||
int result = permissionMapper.updateById(permission);
|
||||
|
||||
if (result > 0) {
|
||||
logger.info("删除权限成功:{}", permissionId);
|
||||
resultDomain.success("删除权限成功", permission);
|
||||
return resultDomain;
|
||||
} else {
|
||||
logger.warn("删除权限失败:{}", permissionId);
|
||||
resultDomain.fail("删除权限失败");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("删除权限异常:{}", permissionId, e);
|
||||
resultDomain.fail("删除权限失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<Boolean> checkPermissionNameExists(String permissionName, String excludeId) {
|
||||
ResultDomain<Boolean> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("检查权限名称是否存在:{}", permissionName);
|
||||
|
||||
if (!StringUtils.hasText(permissionName)) {
|
||||
resultDomain.fail("权限名称不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
int count = permissionMapper.countByPermissionName(permissionName, excludeId);
|
||||
boolean exists = count > 0;
|
||||
|
||||
logger.info("权限名称存在性检查完成:{},存在:{}", permissionName, exists);
|
||||
resultDomain.success("检查完成", exists);
|
||||
return resultDomain;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("检查权限名称存在性失败:{}", permissionName, e);
|
||||
resultDomain.fail("检查失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<Boolean> checkPermissionCodeExists(String permissionCode, String excludeId) {
|
||||
ResultDomain<Boolean> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("检查权限编码是否存在:{}", permissionCode);
|
||||
|
||||
if (!StringUtils.hasText(permissionCode)) {
|
||||
resultDomain.fail("权限编码不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
int count = permissionMapper.countByPermissionCode(permissionCode, excludeId);
|
||||
boolean exists = count > 0;
|
||||
|
||||
logger.info("权限编码存在性检查完成:{},存在:{}", permissionCode, exists);
|
||||
resultDomain.success("检查完成", exists);
|
||||
return resultDomain;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("检查权限编码存在性失败:{}", permissionCode, e);
|
||||
resultDomain.fail("检查失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysPermission> changePermissionStatus(String permissionId, Integer status) {
|
||||
ResultDomain<TbSysPermission> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("开始修改权限状态:{},状态:{}", permissionId, status);
|
||||
|
||||
if (!StringUtils.hasText(permissionId)) {
|
||||
resultDomain.fail("权限ID不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
if (status == null) {
|
||||
resultDomain.fail("权限状态不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 检查权限是否存在
|
||||
ResultDomain<TbSysPermission> existResult = getPermissionById(permissionId);
|
||||
if (!existResult.isSuccess()) {
|
||||
resultDomain.fail(existResult.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
TbSysPermission permission = existResult.getData();
|
||||
|
||||
permission.setUpdateTime(new Date());
|
||||
|
||||
int result = permissionMapper.updateById(permission);
|
||||
|
||||
if (result > 0) {
|
||||
logger.info("修改权限状态成功:{}", permissionId);
|
||||
resultDomain.success("修改权限状态成功", permission);
|
||||
return resultDomain;
|
||||
} else {
|
||||
logger.warn("修改权限状态失败:{}", permissionId);
|
||||
resultDomain.fail("修改权限状态失败");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("修改权限状态异常:{}", permissionId, e);
|
||||
resultDomain.fail("修改权限状态失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package org.xyzh.system.role.service;
|
||||
|
||||
import org.xyzh.api.system.role.RoleService;
|
||||
|
||||
/**
|
||||
* @description SysRoleService.java文件描述 系统角色服务接口
|
||||
* @filename SysRoleService.java
|
||||
* @author yslg
|
||||
* @copyright xyzh
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
public interface SysRoleService extends RoleService {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,335 @@
|
||||
package org.xyzh.system.role.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.xyzh.common.core.domain.ResultDomain;
|
||||
import org.xyzh.common.dto.role.TbSysRole;
|
||||
import org.xyzh.common.utils.IDUtils;
|
||||
import org.xyzh.system.mapper.RoleMapper;
|
||||
import org.xyzh.system.role.service.SysRoleService;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @description SysRoleServiceImpl.java文件描述 系统角色服务实现类
|
||||
* @filename SysRoleServiceImpl.java
|
||||
* @author yslg
|
||||
* @copyright xyzh
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
@Service
|
||||
public class SysRoleServiceImpl implements SysRoleService {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SysRoleServiceImpl.class);
|
||||
|
||||
@Autowired
|
||||
private RoleMapper roleMapper;
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysRole> getAllRoles() {
|
||||
ResultDomain<TbSysRole> resultDomain = new ResultDomain<>();
|
||||
|
||||
try {
|
||||
logger.info("开始查询所有角色");
|
||||
|
||||
LambdaQueryWrapper<TbSysRole> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(TbSysRole::getDeleted, false)
|
||||
.orderByAsc(TbSysRole::getCreateTime);
|
||||
|
||||
List<TbSysRole> roles = roleMapper.selectList(queryWrapper);
|
||||
|
||||
logger.info("查询所有角色完成,共找到{}个角色", roles.size());
|
||||
resultDomain.success("查询成功", roles);
|
||||
return resultDomain;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("查询所有角色失败", e);
|
||||
resultDomain.fail("查询角色失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysRole> getRoleById(String roleId) {
|
||||
ResultDomain<TbSysRole> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("开始根据ID查询角色:{}", roleId);
|
||||
|
||||
if (!StringUtils.hasText(roleId)) {
|
||||
resultDomain.fail("角色ID不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<TbSysRole> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(TbSysRole::getRoleID, roleId)
|
||||
.eq(TbSysRole::getDeleted, false);
|
||||
|
||||
TbSysRole role = roleMapper.selectOne(queryWrapper);
|
||||
|
||||
if (role == null) {
|
||||
logger.warn("未找到角色:{}", roleId);
|
||||
resultDomain.fail("未找到指定角色");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
logger.info("根据ID查询角色完成:{}", roleId);
|
||||
resultDomain.success("查询成功", role);
|
||||
return resultDomain;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("根据ID查询角色失败:{}", roleId, e);
|
||||
resultDomain.fail("查询角色失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysRole> getRolesByUserId(String userId) {
|
||||
ResultDomain<TbSysRole> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("开始根据用户ID查询角色列表:{}", userId);
|
||||
|
||||
if (!StringUtils.hasText(userId)) {
|
||||
resultDomain.fail("用户ID不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
List<TbSysRole> roles = roleMapper.selectRolesByUserId(userId);
|
||||
|
||||
logger.info("根据用户ID查询角色列表完成,共找到{}个角色", roles.size());
|
||||
resultDomain.success("查询成功", roles);
|
||||
return resultDomain;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("根据用户ID查询角色列表失败:{}", userId, e);
|
||||
resultDomain.fail("查询角色失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysRole> createRole(TbSysRole role) {
|
||||
ResultDomain<TbSysRole> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("开始创建角色:{}", role.getName());
|
||||
|
||||
// 参数校验
|
||||
if (!StringUtils.hasText(role.getName())) {
|
||||
resultDomain.fail("角色名称不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
|
||||
// 检查角色名称是否已存在
|
||||
ResultDomain<Boolean> nameCheckResult = checkRoleNameExists(role.getName(), null);
|
||||
if (!nameCheckResult.isSuccess()) {
|
||||
resultDomain.fail(nameCheckResult.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
if (nameCheckResult.getData()) {
|
||||
resultDomain.fail("角色名称已存在");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 设置基础信息
|
||||
role.setID(IDUtils.generateID());
|
||||
role.setRoleID(IDUtils.generateID());
|
||||
role.setCreateTime(new Date());
|
||||
role.setDeleted(false);
|
||||
|
||||
// 插入数据库
|
||||
int result = roleMapper.insert(role);
|
||||
|
||||
if (result > 0) {
|
||||
logger.info("创建角色成功:{}", role.getName());
|
||||
resultDomain.success("创建角色成功", role);
|
||||
return resultDomain;
|
||||
} else {
|
||||
logger.warn("创建角色失败:{}", role.getName());
|
||||
resultDomain.fail("创建角色失败");
|
||||
}
|
||||
|
||||
return resultDomain;
|
||||
} catch (Exception e) {
|
||||
logger.error("创建角色异常:{}", role.getName(), e);
|
||||
resultDomain.fail("创建角色失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysRole> updateRole(TbSysRole role) {
|
||||
ResultDomain<TbSysRole> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("开始更新角色:{}", role.getRoleID());
|
||||
|
||||
// 参数校验
|
||||
if (!StringUtils.hasText(role.getRoleID())) {
|
||||
resultDomain.fail("角色ID不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
if (!StringUtils.hasText(role.getName())) {
|
||||
resultDomain.fail("角色名称不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 检查角色是否存在
|
||||
ResultDomain<TbSysRole> existResult = getRoleById(role.getRoleID());
|
||||
if (!existResult.isSuccess()) {
|
||||
resultDomain.fail(existResult.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 检查角色名称是否已存在(排除自身)
|
||||
ResultDomain<Boolean> nameCheckResult = checkRoleNameExists(role.getName(), role.getID());
|
||||
if (!nameCheckResult.isSuccess()) {
|
||||
resultDomain.fail(nameCheckResult.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
if (nameCheckResult.getData()) {
|
||||
resultDomain.fail("角色名称已存在");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 设置更新时间
|
||||
role.setUpdateTime(new Date());
|
||||
|
||||
// 更新数据库
|
||||
int result = roleMapper.updateById(role);
|
||||
|
||||
if (result > 0) {
|
||||
logger.info("更新角色成功:{}", role.getRoleID());
|
||||
resultDomain.success("更新角色成功", role);
|
||||
return resultDomain;
|
||||
} else {
|
||||
logger.warn("更新角色失败:{}", role.getRoleID());
|
||||
resultDomain.fail("更新角色失败");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("更新角色异常:{}", role.getRoleID(), e);
|
||||
resultDomain.fail("更新角色失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysRole> deleteRole(String roleId) {
|
||||
ResultDomain<TbSysRole> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("开始删除角色:{}", roleId);
|
||||
|
||||
if (!StringUtils.hasText(roleId)) {
|
||||
resultDomain.fail("角色ID不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 检查角色是否存在
|
||||
ResultDomain<TbSysRole> existResult = getRoleById(roleId);
|
||||
if (!existResult.isSuccess()) {
|
||||
resultDomain.fail(existResult.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// TODO: 检查角色是否被用户使用,如果被使用则不能删除
|
||||
|
||||
// 逻辑删除
|
||||
TbSysRole role = existResult.getData();
|
||||
role.setDeleted(true);
|
||||
role.setDeleteTime(new Date());
|
||||
|
||||
int result = roleMapper.updateById(role);
|
||||
|
||||
if (result > 0) {
|
||||
logger.info("删除角色成功:{}", roleId);
|
||||
resultDomain.success("删除角色成功", role);
|
||||
return resultDomain;
|
||||
} else {
|
||||
logger.warn("删除角色失败:{}", roleId);
|
||||
resultDomain.fail("删除角色失败");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("删除角色异常:{}", roleId, e);
|
||||
resultDomain.fail("删除角色失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<Boolean> checkRoleNameExists(String roleName, String excludeId) {
|
||||
ResultDomain<Boolean> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("检查角色名称是否存在:{}", roleName);
|
||||
|
||||
if (!StringUtils.hasText(roleName)) {
|
||||
resultDomain.fail("角色名称不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
int count = roleMapper.countByRoleName(roleName, excludeId);
|
||||
boolean exists = count > 0;
|
||||
|
||||
logger.info("角色名称存在性检查完成:{},存在:{}", roleName, exists);
|
||||
resultDomain.success("检查完成", exists);
|
||||
return resultDomain;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("检查角色名称存在性失败:{}", roleName, e);
|
||||
resultDomain.fail("检查失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysRole> changeRoleStatus(String roleId, Integer status) {
|
||||
ResultDomain<TbSysRole> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("开始修改角色状态:{},状态:{}", roleId, status);
|
||||
|
||||
if (!StringUtils.hasText(roleId)) {
|
||||
resultDomain.fail("角色ID不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
if (status == null) {
|
||||
resultDomain.fail("角色状态不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 检查角色是否存在
|
||||
ResultDomain<TbSysRole> existResult = getRoleById(roleId);
|
||||
if (!existResult.isSuccess()) {
|
||||
resultDomain.fail(existResult.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
TbSysRole role = existResult.getData();
|
||||
role.setUpdateTime(new Date());
|
||||
|
||||
int result = roleMapper.updateById(role);
|
||||
|
||||
if (result > 0) {
|
||||
logger.info("修改角色状态成功:{}", roleId);
|
||||
resultDomain.success("修改角色状态成功", role);
|
||||
return resultDomain;
|
||||
} else {
|
||||
logger.warn("修改角色状态失败:{}", roleId);
|
||||
resultDomain.fail("修改角色状态失败");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("修改角色状态异常:{}", roleId, e);
|
||||
resultDomain.fail("修改角色状态失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package org.xyzh.system.user.service;
|
||||
|
||||
import org.xyzh.api.system.user.UserService;
|
||||
|
||||
/**
|
||||
* @description SysUserService.java文件描述 系统用户服务接口
|
||||
* @filename SysUserService.java
|
||||
* @author yslg
|
||||
* @copyright xyzh
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
public interface SysUserService extends UserService {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,515 @@
|
||||
package org.xyzh.system.user.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.xyzh.common.core.domain.ResultDomain;
|
||||
import org.xyzh.common.dto.user.TbSysUser;
|
||||
import org.xyzh.common.utils.IDUtils;
|
||||
import org.xyzh.system.mapper.UserMapper;
|
||||
import org.xyzh.system.user.service.SysUserService;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @description SysUserServiceImpl.java文件描述 系统用户服务实现类
|
||||
* @filename SysUserServiceImpl.java
|
||||
* @author yslg
|
||||
* @copyright xyzh
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
@Service
|
||||
public class SysUserServiceImpl implements SysUserService {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SysUserServiceImpl.class);
|
||||
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysUser> getAllUsers() {
|
||||
ResultDomain<TbSysUser> resultDomain = new ResultDomain<>();
|
||||
|
||||
try {
|
||||
logger.info("开始查询所有用户");
|
||||
|
||||
LambdaQueryWrapper<TbSysUser> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(TbSysUser::getDeleted, false)
|
||||
.orderByAsc(TbSysUser::getCreateTime);
|
||||
|
||||
List<TbSysUser> users = userMapper.selectList(queryWrapper);
|
||||
|
||||
logger.info("查询所有用户完成,共找到{}个用户", users.size());
|
||||
resultDomain.success("查询成功", users);
|
||||
return resultDomain;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("查询所有用户失败", e);
|
||||
resultDomain.fail("查询用户失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysUser> getUserById(String userId) {
|
||||
ResultDomain<TbSysUser> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("开始根据ID查询用户:{}", userId);
|
||||
|
||||
if (!StringUtils.hasText(userId)) {
|
||||
resultDomain.fail("用户ID不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<TbSysUser> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(TbSysUser::getID, userId)
|
||||
.eq(TbSysUser::getDeleted, false);
|
||||
|
||||
TbSysUser user = userMapper.selectOne(queryWrapper);
|
||||
|
||||
if (user == null) {
|
||||
logger.warn("未找到用户:{}", userId);
|
||||
resultDomain.fail("未找到指定用户");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
logger.info("根据ID查询用户完成:{}", userId);
|
||||
resultDomain.success("查询成功", user);
|
||||
return resultDomain;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("根据ID查询用户失败:{}", userId, e);
|
||||
resultDomain.fail("查询用户失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysUser> getUserByUsername(String username) {
|
||||
ResultDomain<TbSysUser> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("开始根据用户名查询用户:{}", username);
|
||||
|
||||
if (!StringUtils.hasText(username)) {
|
||||
resultDomain.fail("用户名不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
TbSysUser user = userMapper.selectByUsername(username);
|
||||
|
||||
if (user == null) {
|
||||
logger.warn("未找到用户:{}", username);
|
||||
resultDomain.fail("未找到指定用户");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
logger.info("根据用户名查询用户完成:{}", username);
|
||||
resultDomain.success("查询成功", user);
|
||||
return resultDomain;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("根据用户名查询用户失败:{}", username, e);
|
||||
resultDomain.fail("查询用户失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysUser> getUserByFilter(TbSysUser filter) {
|
||||
ResultDomain<TbSysUser> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("开始根据过滤条件查询用户:{}", filter);
|
||||
|
||||
if (filter == null) {
|
||||
resultDomain.fail("过滤条件不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 检查至少有一个查询条件
|
||||
boolean hasFilter = StringUtils.hasText(filter.getID()) ||
|
||||
StringUtils.hasText(filter.getUsername()) ||
|
||||
StringUtils.hasText(filter.getEmail()) ||
|
||||
StringUtils.hasText(filter.getPhone());
|
||||
|
||||
if (!hasFilter) {
|
||||
resultDomain.fail("至少需要提供一个查询条件");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
TbSysUser user = userMapper.selectByFilter(filter);
|
||||
|
||||
if (user == null) {
|
||||
logger.warn("未找到符合条件的用户:{}", filter);
|
||||
resultDomain.fail("未找到指定用户");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
logger.info("根据过滤条件查询用户完成:{}", filter);
|
||||
resultDomain.success("查询成功", user);
|
||||
return resultDomain;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("根据过滤条件查询用户失败:{}", filter, e);
|
||||
resultDomain.fail("查询用户失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysUser> createUser(TbSysUser user) {
|
||||
ResultDomain<TbSysUser> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("开始创建用户:{}", user.getUsername());
|
||||
|
||||
// 参数校验
|
||||
if (!StringUtils.hasText(user.getUsername())) {
|
||||
resultDomain.fail("用户名不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 检查用户名是否已存在
|
||||
ResultDomain<Boolean> checkResult = checkUsernameExists(user.getUsername(), null);
|
||||
if (!checkResult.isSuccess()) {
|
||||
resultDomain.fail(checkResult.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
if (checkResult.getData()) {
|
||||
resultDomain.fail("用户名已存在");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 检查邮箱是否已存在
|
||||
if (StringUtils.hasText(user.getEmail())) {
|
||||
ResultDomain<Boolean> emailCheckResult = checkEmailExists(user.getEmail(), null);
|
||||
if (!emailCheckResult.isSuccess()) {
|
||||
resultDomain.fail(emailCheckResult.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
if (emailCheckResult.getData()) {
|
||||
resultDomain.fail("邮箱已存在");
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
// 设置基础信息
|
||||
user.setID(IDUtils.generateID());
|
||||
user.setCreateTime(new Date());
|
||||
user.setDeleted(false);
|
||||
if (user.getStatus() == null) {
|
||||
user.setStatus(1); // 默认启用状态
|
||||
}
|
||||
|
||||
// 插入数据库
|
||||
int result = userMapper.insert(user);
|
||||
|
||||
if (result > 0) {
|
||||
logger.info("创建用户成功:{}", user.getUsername());
|
||||
resultDomain.success("创建用户成功", user);
|
||||
return resultDomain;
|
||||
} else {
|
||||
logger.warn("创建用户失败:{}", user.getUsername());
|
||||
resultDomain.fail("创建用户失败");
|
||||
}
|
||||
|
||||
return resultDomain;
|
||||
} catch (Exception e) {
|
||||
logger.error("创建用户异常:{}", user.getUsername(), e);
|
||||
resultDomain.fail("创建用户失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysUser> updateUser(TbSysUser user) {
|
||||
ResultDomain<TbSysUser> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("开始更新用户:{}", user.getID());
|
||||
|
||||
// 参数校验
|
||||
if (!StringUtils.hasText(user.getID())) {
|
||||
resultDomain.fail("用户ID不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
if (!StringUtils.hasText(user.getUsername())) {
|
||||
resultDomain.fail("用户名不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 检查用户是否存在
|
||||
ResultDomain<TbSysUser> existResult = getUserById(user.getID());
|
||||
if (!existResult.isSuccess()) {
|
||||
resultDomain.fail(existResult.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 检查用户名是否已存在(排除自身)
|
||||
ResultDomain<Boolean> checkResult = checkUsernameExists(user.getUsername(), user.getID());
|
||||
if (!checkResult.isSuccess()) {
|
||||
resultDomain.fail(checkResult.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
if (checkResult.getData()) {
|
||||
resultDomain.fail("用户名已存在");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 检查邮箱是否已存在(排除自身)
|
||||
if (StringUtils.hasText(user.getEmail())) {
|
||||
ResultDomain<Boolean> emailCheckResult = checkEmailExists(user.getEmail(), user.getID());
|
||||
if (!emailCheckResult.isSuccess()) {
|
||||
resultDomain.fail(emailCheckResult.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
if (emailCheckResult.getData()) {
|
||||
resultDomain.fail("邮箱已存在");
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
// 设置更新时间
|
||||
user.setUpdateTime(new Date());
|
||||
|
||||
// 更新数据库
|
||||
int result = userMapper.updateById(user);
|
||||
|
||||
if (result > 0) {
|
||||
logger.info("更新用户成功:{}", user.getID());
|
||||
resultDomain.success("更新用户成功", user);
|
||||
return resultDomain;
|
||||
} else {
|
||||
logger.warn("更新用户失败:{}", user.getID());
|
||||
resultDomain.fail("更新用户失败");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("更新用户异常:{}", user.getID(), e);
|
||||
resultDomain.fail("更新用户失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysUser> deleteUser(String userId) {
|
||||
ResultDomain<TbSysUser> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("开始删除用户:{}", userId);
|
||||
|
||||
if (!StringUtils.hasText(userId)) {
|
||||
resultDomain.fail("用户ID不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 检查用户是否存在
|
||||
ResultDomain<TbSysUser> existResult = getUserById(userId);
|
||||
if (!existResult.isSuccess()) {
|
||||
resultDomain.fail(existResult.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 逻辑删除
|
||||
TbSysUser user = existResult.getData();
|
||||
user.setDeleted(true);
|
||||
user.setDeleteTime(new Date());
|
||||
|
||||
int result = userMapper.updateById(user);
|
||||
|
||||
if (result > 0) {
|
||||
logger.info("删除用户成功:{}", userId);
|
||||
resultDomain.success("删除用户成功", user);
|
||||
return resultDomain;
|
||||
} else {
|
||||
logger.warn("删除用户失败:{}", userId);
|
||||
resultDomain.fail("删除用户失败");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("删除用户异常:{}", userId, e);
|
||||
resultDomain.fail("删除用户失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<Boolean> checkUsernameExists(String username, String excludeId) {
|
||||
ResultDomain<Boolean> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("检查用户名是否存在:{}", username);
|
||||
|
||||
if (!StringUtils.hasText(username)) {
|
||||
resultDomain.fail("用户名不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<TbSysUser> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(TbSysUser::getUsername, username)
|
||||
.eq(TbSysUser::getDeleted, false);
|
||||
|
||||
if (StringUtils.hasText(excludeId)) {
|
||||
queryWrapper.ne(TbSysUser::getID, excludeId);
|
||||
}
|
||||
|
||||
long count = userMapper.selectCount(queryWrapper);
|
||||
boolean exists = count > 0;
|
||||
|
||||
logger.info("用户名存在性检查完成:{},存在:{}", username, exists);
|
||||
resultDomain.success("检查完成", exists);
|
||||
return resultDomain;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("检查用户名存在性失败:{}", username, e);
|
||||
resultDomain.fail("检查失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<Boolean> checkEmailExists(String email, String excludeId) {
|
||||
ResultDomain<Boolean> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("检查邮箱是否存在:{}", email);
|
||||
|
||||
if (!StringUtils.hasText(email)) {
|
||||
resultDomain.fail("邮箱不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<TbSysUser> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(TbSysUser::getEmail, email)
|
||||
.eq(TbSysUser::getDeleted, false);
|
||||
|
||||
if (StringUtils.hasText(excludeId)) {
|
||||
queryWrapper.ne(TbSysUser::getID, excludeId);
|
||||
}
|
||||
|
||||
long count = userMapper.selectCount(queryWrapper);
|
||||
boolean exists = count > 0;
|
||||
|
||||
logger.info("邮箱存在性检查完成:{},存在:{}", email, exists);
|
||||
resultDomain.success("检查完成", exists);
|
||||
return resultDomain;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("检查邮箱存在性失败:{}", email, e);
|
||||
resultDomain.fail("检查失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysUser> searchUsers(String username, String email, String status) {
|
||||
ResultDomain<TbSysUser> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("开始搜索用户,用户名:{},邮箱:{},状态:{}", username, email, status);
|
||||
|
||||
List<TbSysUser> users = userMapper.selectUserList(username, email, status);
|
||||
|
||||
logger.info("搜索用户完成,共找到{}个用户", users.size());
|
||||
resultDomain.success("搜索成功", users);
|
||||
return resultDomain;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("搜索用户失败", e);
|
||||
resultDomain.fail("搜索用户失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysUser> changeUserStatus(String userId, Integer status) {
|
||||
ResultDomain<TbSysUser> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("开始修改用户状态:{},状态:{}", userId, status);
|
||||
|
||||
if (!StringUtils.hasText(userId)) {
|
||||
resultDomain.fail("用户ID不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
if (status == null) {
|
||||
resultDomain.fail("用户状态不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 检查用户是否存在
|
||||
ResultDomain<TbSysUser> existResult = getUserById(userId);
|
||||
if (!existResult.isSuccess()) {
|
||||
resultDomain.fail(existResult.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
TbSysUser user = existResult.getData();
|
||||
user.setStatus(status);
|
||||
user.setUpdateTime(new Date());
|
||||
|
||||
int result = userMapper.updateById(user);
|
||||
|
||||
if (result > 0) {
|
||||
logger.info("修改用户状态成功:{}", userId);
|
||||
resultDomain.success("修改用户状态成功", user);
|
||||
return resultDomain;
|
||||
} else {
|
||||
logger.warn("修改用户状态失败:{}", userId);
|
||||
resultDomain.fail("修改用户状态失败");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("修改用户状态异常:{}", userId, e);
|
||||
resultDomain.fail("修改用户状态失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysUser> resetPassword(String userId, String newPassword) {
|
||||
ResultDomain<TbSysUser> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
logger.info("开始重置用户密码:{}", userId);
|
||||
|
||||
if (!StringUtils.hasText(userId)) {
|
||||
resultDomain.fail("用户ID不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
if (!StringUtils.hasText(newPassword)) {
|
||||
resultDomain.fail("新密码不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 检查用户是否存在
|
||||
ResultDomain<TbSysUser> existResult = getUserById(userId);
|
||||
if (!existResult.isSuccess()) {
|
||||
resultDomain.fail(existResult.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
TbSysUser user = existResult.getData();
|
||||
// TODO: 这里应该对密码进行加密处理
|
||||
user.setPassword(newPassword);
|
||||
user.setUpdateTime(new Date());
|
||||
|
||||
int result = userMapper.updateById(user);
|
||||
|
||||
if (result > 0) {
|
||||
logger.info("重置用户密码成功:{}", userId);
|
||||
resultDomain.success("重置密码成功", user);
|
||||
return resultDomain;
|
||||
} else {
|
||||
logger.warn("重置用户密码失败:{}", userId);
|
||||
resultDomain.fail("重置密码失败");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("重置用户密码异常:{}", userId, e);
|
||||
resultDomain.fail("重置密码失败:" + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
}
|
||||
98
schoolNewsServ/system/src/main/resources/application.yml
Normal file
98
schoolNewsServ/system/src/main/resources/application.yml
Normal file
@@ -0,0 +1,98 @@
|
||||
server:
|
||||
port: 8082
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: school-news-system
|
||||
|
||||
# 数据源配置
|
||||
datasource:
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://localhost:3306/school_news?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8
|
||||
username: root
|
||||
password: root
|
||||
|
||||
# Druid 配置
|
||||
druid:
|
||||
initial-size: 5
|
||||
min-idle: 5
|
||||
max-active: 20
|
||||
max-wait: 60000
|
||||
time-between-eviction-runs-millis: 60000
|
||||
min-evictable-idle-time-millis: 300000
|
||||
validation-query: SELECT 1
|
||||
test-while-idle: true
|
||||
test-on-borrow: false
|
||||
test-on-return: false
|
||||
pool-prepared-statements: true
|
||||
max-pool-prepared-statement-per-connection-size: 20
|
||||
|
||||
# 监控统计配置
|
||||
filter:
|
||||
stat:
|
||||
enabled: true
|
||||
db-type: mysql
|
||||
log-slow-sql: true
|
||||
slow-sql-millis: 2000
|
||||
wall:
|
||||
enabled: true
|
||||
db-type: mysql
|
||||
|
||||
# Web监控配置
|
||||
web-stat-filter:
|
||||
enabled: true
|
||||
url-pattern: /*
|
||||
exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"
|
||||
|
||||
stat-view-servlet:
|
||||
enabled: true
|
||||
url-pattern: /druid/*
|
||||
reset-enable: false
|
||||
login-username: admin
|
||||
login-password: admin123
|
||||
|
||||
# MyBatis Plus配置
|
||||
mybatis-plus:
|
||||
# 实体类扫描包
|
||||
type-aliases-package: org.xyzh.common.dto
|
||||
# mapper xml文件位置
|
||||
mapper-locations: classpath:mapper/*.xml
|
||||
# 全局配置
|
||||
global-config:
|
||||
db-config:
|
||||
# 主键策略:雪花算法
|
||||
id-type: assign_id
|
||||
# 逻辑删除字段
|
||||
logic-delete-field: deleted
|
||||
logic-delete-value: 1
|
||||
logic-not-delete-value: 0
|
||||
# 字段填充策略
|
||||
insert-strategy: not_null
|
||||
update-strategy: not_null
|
||||
select-strategy: not_empty
|
||||
# SQL配置
|
||||
configuration:
|
||||
# 开启驼峰命名转换
|
||||
map-underscore-to-camel-case: true
|
||||
# 开启二级缓存
|
||||
cache-enabled: true
|
||||
# 打印SQL
|
||||
log-impl: org.apache.ibatis.logging.slf4j.Slf4jImpl
|
||||
|
||||
# 日志配置
|
||||
logging:
|
||||
config: classpath:log4j2-spring.xml
|
||||
level:
|
||||
org.xyzh.system: DEBUG
|
||||
org.xyzh.system.mapper: DEBUG
|
||||
|
||||
# 管理端点配置
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: health,info,metrics
|
||||
endpoint:
|
||||
health:
|
||||
show-details: when-authorized
|
||||
175
schoolNewsServ/system/src/main/resources/log4j2-spring.xml
Normal file
175
schoolNewsServ/system/src/main/resources/log4j2-spring.xml
Normal file
@@ -0,0 +1,175 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
@description log4j2-spring.xml文件描述 System模块Log4j2配置文件
|
||||
@filename log4j2-spring.xml
|
||||
@author yslg
|
||||
@copyright xyzh
|
||||
@since 2025-09-28
|
||||
-->
|
||||
<Configuration status="WARN" monitorInterval="30">
|
||||
|
||||
<!-- 全局属性 -->
|
||||
<Properties>
|
||||
<!-- 应用名称 -->
|
||||
<Property name="APP_NAME">school-news-system</Property>
|
||||
<!-- 日志文件路径 -->
|
||||
<Property name="LOG_HOME">./logs/${APP_NAME}</Property>
|
||||
<!-- 日志格式 -->
|
||||
<Property name="LOG_PATTERN">%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level [%X{traceId}] %logger{36} - %msg%n</Property>
|
||||
<!-- 控制台日志格式(带颜色) -->
|
||||
<Property name="CONSOLE_PATTERN">%d{HH:mm:ss.SSS} %highlight{%-5level} [%t] %style{[%X{traceId}]}{cyan} %style{%logger{36}}{magenta} - %msg%n</Property>
|
||||
</Properties>
|
||||
|
||||
<!-- 输出器配置 -->
|
||||
<Appenders>
|
||||
|
||||
<!-- 控制台输出 -->
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="${CONSOLE_PATTERN}"/>
|
||||
<!-- 只输出INFO及以上级别 -->
|
||||
<ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
|
||||
</Console>
|
||||
|
||||
<!-- 调试日志文件 -->
|
||||
<RollingFile name="DebugFile" fileName="${LOG_HOME}/debug.log"
|
||||
filePattern="${LOG_HOME}/debug.%d{yyyy-MM-dd}.%i.log.gz">
|
||||
<PatternLayout pattern="${LOG_PATTERN}"/>
|
||||
<Policies>
|
||||
<!-- 每天轮转 -->
|
||||
<TimeBasedTriggeringPolicy interval="1"/>
|
||||
<!-- 文件大小超过100MB轮转 -->
|
||||
<SizeBasedTriggeringPolicy size="100MB"/>
|
||||
</Policies>
|
||||
<!-- 保留30天的日志文件 -->
|
||||
<DefaultRolloverStrategy max="30"/>
|
||||
<!-- 只输出DEBUG级别 -->
|
||||
<LevelRangeFilter minLevel="DEBUG" maxLevel="DEBUG" onMatch="ACCEPT" onMismatch="DENY"/>
|
||||
</RollingFile>
|
||||
|
||||
<!-- 信息日志文件 -->
|
||||
<RollingFile name="InfoFile" fileName="${LOG_HOME}/info.log"
|
||||
filePattern="${LOG_HOME}/info.%d{yyyy-MM-dd}.%i.log.gz">
|
||||
<PatternLayout pattern="${LOG_PATTERN}"/>
|
||||
<Policies>
|
||||
<TimeBasedTriggeringPolicy interval="1"/>
|
||||
<SizeBasedTriggeringPolicy size="100MB"/>
|
||||
</Policies>
|
||||
<DefaultRolloverStrategy max="30"/>
|
||||
<!-- 只输出INFO级别 -->
|
||||
<LevelRangeFilter minLevel="INFO" maxLevel="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
|
||||
</RollingFile>
|
||||
|
||||
<!-- 警告日志文件 -->
|
||||
<RollingFile name="WarnFile" fileName="${LOG_HOME}/warn.log"
|
||||
filePattern="${LOG_HOME}/warn.%d{yyyy-MM-dd}.%i.log.gz">
|
||||
<PatternLayout pattern="${LOG_PATTERN}"/>
|
||||
<Policies>
|
||||
<TimeBasedTriggeringPolicy interval="1"/>
|
||||
<SizeBasedTriggeringPolicy size="100MB"/>
|
||||
</Policies>
|
||||
<DefaultRolloverStrategy max="30"/>
|
||||
<!-- 只输出WARN级别 -->
|
||||
<LevelRangeFilter minLevel="WARN" maxLevel="WARN" onMatch="ACCEPT" onMismatch="DENY"/>
|
||||
</RollingFile>
|
||||
|
||||
<!-- 错误日志文件 -->
|
||||
<RollingFile name="ErrorFile" fileName="${LOG_HOME}/error.log"
|
||||
filePattern="${LOG_HOME}/error.%d{yyyy-MM-dd}.%i.log.gz">
|
||||
<PatternLayout pattern="${LOG_PATTERN}"/>
|
||||
<Policies>
|
||||
<TimeBasedTriggeringPolicy interval="1"/>
|
||||
<SizeBasedTriggeringPolicy size="100MB"/>
|
||||
</Policies>
|
||||
<DefaultRolloverStrategy max="30"/>
|
||||
<!-- 只输出ERROR及以上级别 -->
|
||||
<ThresholdFilter level="ERROR" onMatch="ACCEPT" onMismatch="DENY"/>
|
||||
</RollingFile>
|
||||
|
||||
<!-- SQL日志文件 -->
|
||||
<RollingFile name="SqlFile" fileName="${LOG_HOME}/sql.log"
|
||||
filePattern="${LOG_HOME}/sql.%d{yyyy-MM-dd}.%i.log.gz">
|
||||
<PatternLayout pattern="${LOG_PATTERN}"/>
|
||||
<Policies>
|
||||
<TimeBasedTriggeringPolicy interval="1"/>
|
||||
<SizeBasedTriggeringPolicy size="50MB"/>
|
||||
</Policies>
|
||||
<DefaultRolloverStrategy max="7"/>
|
||||
</RollingFile>
|
||||
|
||||
<!-- 异步输出器 -->
|
||||
<AsyncAppender name="AsyncConsole">
|
||||
<AppenderRef ref="Console"/>
|
||||
<BufferSize>1024</BufferSize>
|
||||
</AsyncAppender>
|
||||
|
||||
<AsyncAppender name="AsyncDebugFile">
|
||||
<AppenderRef ref="DebugFile"/>
|
||||
<BufferSize>1024</BufferSize>
|
||||
</AsyncAppender>
|
||||
|
||||
<AsyncAppender name="AsyncInfoFile">
|
||||
<AppenderRef ref="InfoFile"/>
|
||||
<BufferSize>1024</BufferSize>
|
||||
</AsyncAppender>
|
||||
|
||||
<AsyncAppender name="AsyncWarnFile">
|
||||
<AppenderRef ref="WarnFile"/>
|
||||
<BufferSize>1024</BufferSize>
|
||||
</AsyncAppender>
|
||||
|
||||
<AsyncAppender name="AsyncErrorFile">
|
||||
<AppenderRef ref="ErrorFile"/>
|
||||
<BufferSize>1024</BufferSize>
|
||||
</AsyncAppender>
|
||||
|
||||
<AsyncAppender name="AsyncSqlFile">
|
||||
<AppenderRef ref="SqlFile"/>
|
||||
<BufferSize>512</BufferSize>
|
||||
</AsyncAppender>
|
||||
|
||||
</Appenders>
|
||||
|
||||
<!-- 记录器配置 -->
|
||||
<Loggers>
|
||||
|
||||
<!-- SQL日志 -->
|
||||
<Logger name="org.xyzh.system.mapper" level="DEBUG" additivity="false">
|
||||
<AppenderRef ref="AsyncSqlFile"/>
|
||||
<AppenderRef ref="AsyncConsole"/>
|
||||
</Logger>
|
||||
|
||||
<!-- MyBatis日志 -->
|
||||
<Logger name="com.baomidou.mybatisplus" level="DEBUG" additivity="false">
|
||||
<AppenderRef ref="AsyncSqlFile"/>
|
||||
</Logger>
|
||||
|
||||
<!-- Druid日志 -->
|
||||
<Logger name="com.alibaba.druid" level="INFO" additivity="false">
|
||||
<AppenderRef ref="AsyncInfoFile"/>
|
||||
</Logger>
|
||||
|
||||
<!-- Spring框架日志 -->
|
||||
<Logger name="org.springframework" level="INFO" additivity="false">
|
||||
<AppenderRef ref="AsyncInfoFile"/>
|
||||
</Logger>
|
||||
|
||||
<!-- 系统模块日志 -->
|
||||
<Logger name="org.xyzh.system" level="DEBUG" additivity="false">
|
||||
<AppenderRef ref="AsyncDebugFile"/>
|
||||
<AppenderRef ref="AsyncInfoFile"/>
|
||||
<AppenderRef ref="AsyncWarnFile"/>
|
||||
<AppenderRef ref="AsyncErrorFile"/>
|
||||
<AppenderRef ref="AsyncConsole"/>
|
||||
</Logger>
|
||||
|
||||
<!-- 根记录器 -->
|
||||
<Root level="INFO">
|
||||
<AppenderRef ref="AsyncInfoFile"/>
|
||||
<AppenderRef ref="AsyncWarnFile"/>
|
||||
<AppenderRef ref="AsyncErrorFile"/>
|
||||
<AppenderRef ref="AsyncConsole"/>
|
||||
</Root>
|
||||
|
||||
</Loggers>
|
||||
|
||||
</Configuration>
|
||||
@@ -0,0 +1,148 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.xyzh.system.mapper.DepartmentMapper">
|
||||
|
||||
<!-- 基础结果映射 -->
|
||||
<resultMap id="BaseResultMap" type="org.xyzh.common.dto.dept.TbSysDept">
|
||||
<id column="id" property="id" jdbcType="VARCHAR"/>
|
||||
<result column="dept_id" property="deptID" jdbcType="VARCHAR"/>
|
||||
<result column="name" property="name" jdbcType="VARCHAR"/>
|
||||
<result column="parent_id" property="parentID" jdbcType="VARCHAR"/>
|
||||
<result column="description" property="description" jdbcType="VARCHAR"/>
|
||||
<result column="creator" property="creator" jdbcType="VARCHAR"/>
|
||||
<result column="updater" property="updater" jdbcType="VARCHAR"/>
|
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="delete_time" property="deleteTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="deleted" property="deleted" jdbcType="BOOLEAN"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 基础字段 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, dept_id, name, parent_id, description, creator, updater,
|
||||
create_time, update_time, delete_time, deleted
|
||||
</sql>
|
||||
|
||||
<!-- 通用条件 -->
|
||||
<sql id="Where_Clause">
|
||||
<where>
|
||||
deleted = 0
|
||||
<if test="deptID != null and deptID != ''">
|
||||
AND dept_id = #{deptID}
|
||||
</if>
|
||||
<if test="parentID != null and parentID != ''">
|
||||
AND parent_id = #{parentID}
|
||||
</if>
|
||||
<if test="name != null and name != ''">
|
||||
AND name LIKE CONCAT('%', #{name}, '%')
|
||||
</if>
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<!-- 根据父部门ID查询子部门列表 -->
|
||||
<select id="selectByParentId" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_sys_dept
|
||||
WHERE deleted = 0
|
||||
AND parent_id = #{parentId}
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 检查部门名称是否存在 -->
|
||||
<select id="countByDeptName" resultType="int">
|
||||
SELECT COUNT(1)
|
||||
FROM tb_sys_dept
|
||||
WHERE deleted = 0
|
||||
AND name = #{deptName}
|
||||
<if test="excludeId != null and excludeId != ''">
|
||||
AND id != #{excludeId}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<!-- 根据部门ID查询部门信息(包含父部门信息) -->
|
||||
<select id="selectDeptWithParent" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
d.id, d.dept_id, d.parent_id, d.name, d.description,
|
||||
d.creator, d.updater, d.create_time, d.update_time,
|
||||
d.delete_time, d.deleted,
|
||||
p.name AS parent_name
|
||||
FROM tb_sys_dept d
|
||||
LEFT JOIN tb_sys_dept p ON d.parent_id = p.dept_id AND p.deleted = 0
|
||||
WHERE d.deleted = 0
|
||||
AND d.dept_id = #{deptId}
|
||||
</select>
|
||||
|
||||
<!-- 查询部门树结构 -->
|
||||
<select id="selectDeptTree" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_sys_dept
|
||||
WHERE deleted = 0
|
||||
ORDER BY
|
||||
CASE WHEN parent_id IS NULL OR parent_id = '' THEN 0 ELSE 1 END,
|
||||
parent_id,
|
||||
create_time ASC
|
||||
</select>
|
||||
|
||||
<!-- 批量删除部门(逻辑删除) -->
|
||||
<update id="batchDeleteByIds">
|
||||
UPDATE tb_sys_dept
|
||||
SET deleted = 1,
|
||||
delete_time = NOW(),
|
||||
updater = #{updater}
|
||||
WHERE deleted = 0
|
||||
AND id IN
|
||||
<foreach collection="deptIds" item="deptId" open="(" separator="," close=")">
|
||||
#{deptId}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
<!-- 插入部门 -->
|
||||
<insert id="insert" parameterType="org.xyzh.common.dto.dept.TbSysDept">
|
||||
INSERT INTO tb_sys_dept
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">id,</if>
|
||||
<if test="deptID != null">dept_id,</if>
|
||||
<if test="parentID != null">parent_id,</if>
|
||||
<if test="name != null">name,</if>
|
||||
<if test="description != null">description,</if>
|
||||
<if test="creator != null">creator,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
deleted
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">#{id},</if>
|
||||
<if test="deptID != null">#{deptID},</if>
|
||||
<if test="parentID != null">#{parentID},</if>
|
||||
<if test="name != null">#{name},</if>
|
||||
<if test="description != null">#{description},</if>
|
||||
<if test="creator != null">#{creator},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
0
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<!-- 更新部门 -->
|
||||
<update id="updateById" parameterType="org.xyzh.common.dto.dept.TbSysDept">
|
||||
UPDATE tb_sys_dept
|
||||
<set>
|
||||
<if test="deptID != null">dept_id = #{deptID},</if>
|
||||
<if test="parentID != null">parent_id = #{parentID},</if>
|
||||
<if test="name != null">name = #{name},</if>
|
||||
<if test="description != null">description = #{description},</if>
|
||||
<if test="updater != null">updater = #{updater},</if>
|
||||
update_time = NOW()
|
||||
</set>
|
||||
WHERE id = #{id} AND deleted = 0
|
||||
</update>
|
||||
|
||||
<!-- 根据ID删除(逻辑删除) -->
|
||||
<update id="deleteById">
|
||||
UPDATE tb_sys_dept
|
||||
SET deleted = 1,
|
||||
delete_time = NOW()
|
||||
WHERE id = #{id} AND deleted = 0
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
214
schoolNewsServ/system/src/main/resources/mapper/MenuMapper.xml
Normal file
214
schoolNewsServ/system/src/main/resources/mapper/MenuMapper.xml
Normal file
@@ -0,0 +1,214 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.xyzh.system.mapper.MenuMapper">
|
||||
|
||||
<!-- 基础结果映射 -->
|
||||
<resultMap id="BaseResultMap" type="org.xyzh.common.dto.menu.TbSysMenu">
|
||||
<id column="id" property="id" jdbcType="VARCHAR"/>
|
||||
<result column="menu_id" property="menuID" jdbcType="VARCHAR"/>
|
||||
<result column="name" property="menuName" jdbcType="VARCHAR"/>
|
||||
<result column="parent_id" property="parentID" jdbcType="VARCHAR"/>
|
||||
<result column="url" property="path" jdbcType="VARCHAR"/>
|
||||
<result column="icon" property="icon" jdbcType="VARCHAR"/>
|
||||
<result column="order_num" property="sort" jdbcType="INTEGER"/>
|
||||
<result column="type" property="menuType" jdbcType="INTEGER"/>
|
||||
<result column="creator" property="creator" jdbcType="VARCHAR"/>
|
||||
<result column="updater" property="updater" jdbcType="VARCHAR"/>
|
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="delete_time" property="deleteTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="deleted" property="deleted" jdbcType="TINYINT"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 基础字段 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, menu_id, name, parent_id, url, icon, order_num, type,
|
||||
creator, updater, create_time, update_time, delete_time, deleted
|
||||
</sql>
|
||||
|
||||
<!-- 通用条件 -->
|
||||
<sql id="Where_Clause">
|
||||
<where>
|
||||
deleted = 0
|
||||
<if test="menuName != null and menuName != ''">
|
||||
AND menu_name LIKE CONCAT('%', #{menuName}, '%')
|
||||
</if>
|
||||
<if test="menuType != null">
|
||||
AND menu_type = #{menuType}
|
||||
</if>
|
||||
<if test="status != null">
|
||||
AND status = #{status}
|
||||
</if>
|
||||
<if test="visible != null">
|
||||
AND visible = #{visible}
|
||||
</if>
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<!-- 根据用户ID查询菜单列表 -->
|
||||
<select id="selectMenusByUserId" resultMap="BaseResultMap">
|
||||
SELECT DISTINCT
|
||||
m.id, m.menu_id, m.parent_id, m.menu_name, m.menu_type,
|
||||
m.path, m.component, m.permission, m.icon, m.sort,
|
||||
m.visible, m.status, m.external_link, m.cache, m.frame,
|
||||
m.query, m.remark, m.creator, m.updater,
|
||||
m.create_time, m.update_time, m.delete_time, m.deleted
|
||||
FROM tb_sys_menu m
|
||||
INNER JOIN tb_sys_role_menu rm ON m.menu_id = rm.menu_id
|
||||
INNER JOIN tb_sys_user_role ur ON rm.role_id = ur.role_id
|
||||
WHERE m.deleted = 0
|
||||
AND rm.deleted = 0
|
||||
AND ur.deleted = 0
|
||||
AND ur.user_id = #{userId}
|
||||
AND m.status = 1
|
||||
AND m.visible = 1
|
||||
ORDER BY m.sort ASC, m.create_time ASC
|
||||
</select>
|
||||
|
||||
<!-- 根据角色ID查询菜单列表 -->
|
||||
<select id="selectMenusByRoleId" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
m.id, m.menu_id, m.parent_id, m.menu_name, m.menu_type,
|
||||
m.path, m.component, m.permission, m.icon, m.sort,
|
||||
m.visible, m.status, m.external_link, m.cache, m.frame,
|
||||
m.query, m.remark, m.creator, m.updater,
|
||||
m.create_time, m.update_time, m.delete_time, m.deleted
|
||||
FROM tb_sys_menu m
|
||||
INNER JOIN tb_sys_role_menu rm ON m.menu_id = rm.menu_id
|
||||
WHERE m.deleted = 0
|
||||
AND rm.deleted = 0
|
||||
AND rm.role_id = #{roleId}
|
||||
ORDER BY m.sort ASC, m.create_time ASC
|
||||
</select>
|
||||
|
||||
<!-- 根据父菜单ID查询子菜单列表 -->
|
||||
<select id="selectByParentId" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_sys_menu
|
||||
WHERE deleted = 0
|
||||
AND parent_id = #{parentId}
|
||||
ORDER BY sort ASC, create_time ASC
|
||||
</select>
|
||||
|
||||
<!-- 查询菜单树结构 -->
|
||||
<select id="selectMenuTree" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_sys_menu
|
||||
WHERE deleted = 0
|
||||
ORDER BY
|
||||
CASE WHEN parent_id IS NULL OR parent_id = '' THEN 0 ELSE 1 END,
|
||||
parent_id,
|
||||
sort ASC,
|
||||
create_time ASC
|
||||
</select>
|
||||
|
||||
<!-- 检查菜单名称是否存在 -->
|
||||
<select id="countByMenuName" resultType="int">
|
||||
SELECT COUNT(1)
|
||||
FROM tb_sys_menu
|
||||
WHERE deleted = 0
|
||||
AND menu_name = #{menuName}
|
||||
<if test="excludeId != null and excludeId != ''">
|
||||
AND id != #{excludeId}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<!-- 批量删除菜单(逻辑删除) -->
|
||||
<update id="batchDeleteByIds">
|
||||
UPDATE tb_sys_menu
|
||||
SET deleted = 1,
|
||||
delete_time = NOW(),
|
||||
updater = #{updater}
|
||||
WHERE deleted = 0
|
||||
AND id IN
|
||||
<foreach collection="menuIds" item="menuId" open="(" separator="," close=")">
|
||||
#{menuId}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
<!-- 插入菜单 -->
|
||||
<insert id="insert" parameterType="org.xyzh.common.dto.menu.TbSysMenu">
|
||||
INSERT INTO tb_sys_menu
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">id,</if>
|
||||
<if test="menuID != null">menu_id,</if>
|
||||
<if test="parentID != null">parent_id,</if>
|
||||
<if test="menuName != null">menu_name,</if>
|
||||
<if test="menuType != null">menu_type,</if>
|
||||
<if test="path != null">path,</if>
|
||||
<if test="component != null">component,</if>
|
||||
<if test="permission != null">permission,</if>
|
||||
<if test="icon != null">icon,</if>
|
||||
<if test="sort != null">sort,</if>
|
||||
<if test="visible != null">visible,</if>
|
||||
<if test="status != null">status,</if>
|
||||
<if test="externalLink != null">external_link,</if>
|
||||
<if test="cache != null">cache,</if>
|
||||
<if test="frame != null">frame,</if>
|
||||
<if test="query != null">query,</if>
|
||||
<if test="remark != null">remark,</if>
|
||||
<if test="creator != null">creator,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
deleted
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">#{id},</if>
|
||||
<if test="menuID != null">#{menuID},</if>
|
||||
<if test="parentID != null">#{parentID},</if>
|
||||
<if test="menuName != null">#{menuName},</if>
|
||||
<if test="menuType != null">#{menuType},</if>
|
||||
<if test="path != null">#{path},</if>
|
||||
<if test="component != null">#{component},</if>
|
||||
<if test="permission != null">#{permission},</if>
|
||||
<if test="icon != null">#{icon},</if>
|
||||
<if test="sort != null">#{sort},</if>
|
||||
<if test="visible != null">#{visible},</if>
|
||||
<if test="status != null">#{status},</if>
|
||||
<if test="externalLink != null">#{externalLink},</if>
|
||||
<if test="cache != null">#{cache},</if>
|
||||
<if test="frame != null">#{frame},</if>
|
||||
<if test="query != null">#{query},</if>
|
||||
<if test="remark != null">#{remark},</if>
|
||||
<if test="creator != null">#{creator},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
0
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<!-- 更新菜单 -->
|
||||
<update id="updateById" parameterType="org.xyzh.common.dto.menu.TbSysMenu">
|
||||
UPDATE tb_sys_menu
|
||||
<set>
|
||||
<if test="menuID != null">menu_id = #{menuID},</if>
|
||||
<if test="parentID != null">parent_id = #{parentID},</if>
|
||||
<if test="menuName != null">menu_name = #{menuName},</if>
|
||||
<if test="menuType != null">menu_type = #{menuType},</if>
|
||||
<if test="path != null">path = #{path},</if>
|
||||
<if test="component != null">component = #{component},</if>
|
||||
<if test="permission != null">permission = #{permission},</if>
|
||||
<if test="icon != null">icon = #{icon},</if>
|
||||
<if test="sort != null">sort = #{sort},</if>
|
||||
<if test="visible != null">visible = #{visible},</if>
|
||||
<if test="status != null">status = #{status},</if>
|
||||
<if test="externalLink != null">external_link = #{externalLink},</if>
|
||||
<if test="cache != null">cache = #{cache},</if>
|
||||
<if test="frame != null">frame = #{frame},</if>
|
||||
<if test="query != null">query = #{query},</if>
|
||||
<if test="remark != null">remark = #{remark},</if>
|
||||
<if test="updater != null">updater = #{updater},</if>
|
||||
update_time = NOW()
|
||||
</set>
|
||||
WHERE id = #{id} AND deleted = 0
|
||||
</update>
|
||||
|
||||
<!-- 根据ID删除(逻辑删除) -->
|
||||
<update id="deleteById">
|
||||
UPDATE tb_sys_menu
|
||||
SET deleted = 1,
|
||||
delete_time = NOW()
|
||||
WHERE id = #{id} AND deleted = 0
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,185 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.xyzh.system.mapper.PermissionMapper">
|
||||
|
||||
<!-- 基础结果映射 -->
|
||||
<resultMap id="BaseResultMap" type="org.xyzh.common.dto.permission.TbSysPermission">
|
||||
<id column="id" property="id" jdbcType="VARCHAR"/>
|
||||
<result column="permission_id" property="permissionID" jdbcType="VARCHAR"/>
|
||||
<result column="name" property="permissionName" jdbcType="VARCHAR"/>
|
||||
<result column="code" property="permissionCode" jdbcType="VARCHAR"/>
|
||||
<result column="description" property="description" jdbcType="VARCHAR"/>
|
||||
<result column="creator" property="creator" jdbcType="VARCHAR"/>
|
||||
<result column="updater" property="updater" jdbcType="VARCHAR"/>
|
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="delete_time" property="deleteTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="deleted" property="deleted" jdbcType="BOOLEAN"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 基础字段 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, permission_id, name, code, description, creator, updater,
|
||||
create_time, update_time, delete_time, deleted
|
||||
</sql>
|
||||
|
||||
<!-- 通用条件 -->
|
||||
<sql id="Where_Clause">
|
||||
<where>
|
||||
deleted = 0
|
||||
<if test="permissionName != null and permissionName != ''">
|
||||
AND permission_name LIKE CONCAT('%', #{permissionName}, '%')
|
||||
</if>
|
||||
<if test="permissionCode != null and permissionCode != ''">
|
||||
AND permission_code = #{permissionCode}
|
||||
</if>
|
||||
<if test="permissionType != null">
|
||||
AND permission_type = #{permissionType}
|
||||
</if>
|
||||
<if test="status != null">
|
||||
AND status = #{status}
|
||||
</if>
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<!-- 根据用户ID查询权限列表 -->
|
||||
<select id="selectPermissionsByUserId" resultMap="BaseResultMap">
|
||||
SELECT DISTINCT
|
||||
p.id, p.permission_id, p.permission_name, p.permission_code,
|
||||
p.permission_type, p.resource_url, p.http_method, p.description,
|
||||
p.status, p.sort, p.creator, p.updater,
|
||||
p.create_time, p.update_time, p.delete_time, p.deleted
|
||||
FROM tb_sys_permission p
|
||||
INNER JOIN tb_sys_role_permission rp ON p.permission_id = rp.permission_id
|
||||
INNER JOIN tb_sys_user_role ur ON rp.role_id = ur.role_id
|
||||
WHERE p.deleted = 0
|
||||
AND rp.deleted = 0
|
||||
AND ur.deleted = 0
|
||||
AND ur.user_id = #{userID}
|
||||
AND p.status = 1
|
||||
ORDER BY p.sort ASC, p.create_time ASC
|
||||
</select>
|
||||
|
||||
<!-- 根据角色ID查询权限列表 -->
|
||||
<select id="selectPermissionsByRoleId" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
p.id, p.permission_id, p.permission_name, p.permission_code,
|
||||
p.permission_type, p.resource_url, p.http_method, p.description,
|
||||
p.status, p.sort, p.creator, p.updater,
|
||||
p.create_time, p.update_time, p.delete_time, p.deleted
|
||||
FROM tb_sys_permission p
|
||||
INNER JOIN tb_sys_role_permission rp ON p.permission_id = rp.permission_id
|
||||
WHERE p.deleted = 0
|
||||
AND rp.deleted = 0
|
||||
AND rp.role_id = #{roleId}
|
||||
ORDER BY p.sort ASC, p.create_time ASC
|
||||
</select>
|
||||
|
||||
<!-- 根据权限编码查询权限 -->
|
||||
<select id="selectByPermissionCode" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_sys_permission
|
||||
WHERE deleted = 0
|
||||
AND permission_code = #{permissionCode}
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
<!-- 检查权限名称是否存在 -->
|
||||
<select id="countByPermissionName" resultType="int">
|
||||
SELECT COUNT(1)
|
||||
FROM tb_sys_permission
|
||||
WHERE deleted = 0
|
||||
AND permission_name = #{permissionName}
|
||||
<if test="excludeId != null and excludeId != ''">
|
||||
AND id != #{excludeId}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<!-- 检查权限编码是否存在 -->
|
||||
<select id="countByPermissionCode" resultType="int">
|
||||
SELECT COUNT(1)
|
||||
FROM tb_sys_permission
|
||||
WHERE deleted = 0
|
||||
AND permission_code = #{permissionCode}
|
||||
<if test="excludeId != null and excludeId != ''">
|
||||
AND id != #{excludeId}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<!-- 批量删除权限(逻辑删除) -->
|
||||
<update id="batchDeleteByIds">
|
||||
UPDATE tb_sys_permission
|
||||
SET deleted = 1,
|
||||
delete_time = NOW(),
|
||||
updater = #{updater}
|
||||
WHERE deleted = 0
|
||||
AND id IN
|
||||
<foreach collection="permissionIds" item="permissionId" open="(" separator="," close=")">
|
||||
#{permissionId}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
<!-- 插入权限 -->
|
||||
<insert id="insert" parameterType="org.xyzh.common.dto.permission.TbSysPermission">
|
||||
INSERT INTO tb_sys_permission
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">id,</if>
|
||||
<if test="permissionID != null">permission_id,</if>
|
||||
<if test="permissionName != null">permission_name,</if>
|
||||
<if test="permissionCode != null">permission_code,</if>
|
||||
<if test="permissionType != null">permission_type,</if>
|
||||
<if test="resourceUrl != null">resource_url,</if>
|
||||
<if test="httpMethod != null">http_method,</if>
|
||||
<if test="description != null">description,</if>
|
||||
<if test="status != null">status,</if>
|
||||
<if test="sort != null">sort,</if>
|
||||
<if test="creator != null">creator,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
deleted
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">#{id},</if>
|
||||
<if test="permissionID != null">#{permissionID},</if>
|
||||
<if test="permissionName != null">#{permissionName},</if>
|
||||
<if test="permissionCode != null">#{permissionCode},</if>
|
||||
<if test="permissionType != null">#{permissionType},</if>
|
||||
<if test="resourceUrl != null">#{resourceUrl},</if>
|
||||
<if test="httpMethod != null">#{httpMethod},</if>
|
||||
<if test="description != null">#{description},</if>
|
||||
<if test="status != null">#{status},</if>
|
||||
<if test="sort != null">#{sort},</if>
|
||||
<if test="creator != null">#{creator},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
0
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<!-- 更新权限 -->
|
||||
<update id="updateById" parameterType="org.xyzh.common.dto.permission.TbSysPermission">
|
||||
UPDATE tb_sys_permission
|
||||
<set>
|
||||
<if test="permissionID != null">permission_id = #{permissionID},</if>
|
||||
<if test="permissionName != null">permission_name = #{permissionName},</if>
|
||||
<if test="permissionCode != null">permission_code = #{permissionCode},</if>
|
||||
<if test="permissionType != null">permission_type = #{permissionType},</if>
|
||||
<if test="resourceUrl != null">resource_url = #{resourceUrl},</if>
|
||||
<if test="httpMethod != null">http_method = #{httpMethod},</if>
|
||||
<if test="description != null">description = #{description},</if>
|
||||
<if test="status != null">status = #{status},</if>
|
||||
<if test="sort != null">sort = #{sort},</if>
|
||||
<if test="updater != null">updater = #{updater},</if>
|
||||
update_time = NOW()
|
||||
</set>
|
||||
WHERE id = #{id} AND deleted = 0
|
||||
</update>
|
||||
|
||||
<!-- 根据ID删除(逻辑删除) -->
|
||||
<update id="deleteById">
|
||||
UPDATE tb_sys_permission
|
||||
SET deleted = 1,
|
||||
delete_time = NOW()
|
||||
WHERE id = #{id} AND deleted = 0
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
153
schoolNewsServ/system/src/main/resources/mapper/RoleMapper.xml
Normal file
153
schoolNewsServ/system/src/main/resources/mapper/RoleMapper.xml
Normal file
@@ -0,0 +1,153 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.xyzh.system.mapper.RoleMapper">
|
||||
|
||||
<!-- 基础结果映射 -->
|
||||
<resultMap id="BaseResultMap" type="org.xyzh.common.dto.role.TbSysRole">
|
||||
<id column="id" property="id" jdbcType="VARCHAR"/>
|
||||
<result column="role_id" property="roleID" jdbcType="VARCHAR"/>
|
||||
<result column="name" property="roleName" jdbcType="VARCHAR"/>
|
||||
<result column="description" property="description" jdbcType="VARCHAR"/>
|
||||
<result column="creator" property="creator" jdbcType="VARCHAR"/>
|
||||
<result column="updater" property="updater" jdbcType="VARCHAR"/>
|
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="delete_time" property="deleteTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="deleted" property="deleted" jdbcType="BOOLEAN"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 基础字段 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, role_id, name, description, creator, updater,
|
||||
create_time, update_time, delete_time, deleted
|
||||
</sql>
|
||||
|
||||
<!-- 通用条件 -->
|
||||
<sql id="Where_Clause">
|
||||
<where>
|
||||
deleted = 0
|
||||
<if test="roleName != null and roleName != ''">
|
||||
AND role_name LIKE CONCAT('%', #{roleName}, '%')
|
||||
</if>
|
||||
<if test="roleCode != null and roleCode != ''">
|
||||
AND role_code = #{roleCode}
|
||||
</if>
|
||||
<if test="status != null">
|
||||
AND status = #{status}
|
||||
</if>
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<!-- 根据用户ID查询角色列表 -->
|
||||
<select id="selectRolesByUserId" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
r.id, r.role_id, r.role_name, r.role_code, r.description,
|
||||
r.status, r.sort, r.creator, r.updater,
|
||||
r.create_time, r.update_time, r.delete_time, r.deleted
|
||||
FROM tb_sys_role r
|
||||
INNER JOIN tb_sys_user_role ur ON r.role_id = ur.role_id
|
||||
WHERE r.deleted = 0
|
||||
AND ur.deleted = 0
|
||||
AND ur.user_id = #{userID}
|
||||
ORDER BY r.sort ASC, r.create_time ASC
|
||||
</select>
|
||||
|
||||
<!-- 根据角色编码查询角色 -->
|
||||
<select id="selectByRoleCode" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_sys_role
|
||||
WHERE deleted = 0
|
||||
AND role_code = #{roleCode}
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
<!-- 检查角色名称是否存在 -->
|
||||
<select id="countByRoleName" resultType="int">
|
||||
SELECT COUNT(1)
|
||||
FROM tb_sys_role
|
||||
WHERE deleted = 0
|
||||
AND role_name = #{roleName}
|
||||
<if test="excludeId != null and excludeId != ''">
|
||||
AND id != #{excludeId}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<!-- 检查角色编码是否存在 -->
|
||||
<select id="countByRoleCode" resultType="int">
|
||||
SELECT COUNT(1)
|
||||
FROM tb_sys_role
|
||||
WHERE deleted = 0
|
||||
AND role_code = #{roleCode}
|
||||
<if test="excludeId != null and excludeId != ''">
|
||||
AND id != #{excludeId}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<!-- 批量删除角色(逻辑删除) -->
|
||||
<update id="batchDeleteByIds">
|
||||
UPDATE tb_sys_role
|
||||
SET deleted = 1,
|
||||
delete_time = NOW(),
|
||||
updater = #{updater}
|
||||
WHERE deleted = 0
|
||||
AND id IN
|
||||
<foreach collection="roleIds" item="roleId" open="(" separator="," close=")">
|
||||
#{roleId}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
<!-- 插入角色 -->
|
||||
<insert id="insert" parameterType="org.xyzh.common.dto.role.TbSysRole">
|
||||
INSERT INTO tb_sys_role
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">id,</if>
|
||||
<if test="roleID != null">role_id,</if>
|
||||
<if test="roleName != null">role_name,</if>
|
||||
<if test="roleCode != null">role_code,</if>
|
||||
<if test="description != null">description,</if>
|
||||
<if test="status != null">status,</if>
|
||||
<if test="sort != null">sort,</if>
|
||||
<if test="creator != null">creator,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
deleted
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">#{id},</if>
|
||||
<if test="roleID != null">#{roleID},</if>
|
||||
<if test="roleName != null">#{roleName},</if>
|
||||
<if test="roleCode != null">#{roleCode},</if>
|
||||
<if test="description != null">#{description},</if>
|
||||
<if test="status != null">#{status},</if>
|
||||
<if test="sort != null">#{sort},</if>
|
||||
<if test="creator != null">#{creator},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
0
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<!-- 更新角色 -->
|
||||
<update id="updateById" parameterType="org.xyzh.common.dto.role.TbSysRole">
|
||||
UPDATE tb_sys_role
|
||||
<set>
|
||||
<if test="roleID != null">role_id = #{roleID},</if>
|
||||
<if test="roleName != null">role_name = #{roleName},</if>
|
||||
<if test="roleCode != null">role_code = #{roleCode},</if>
|
||||
<if test="description != null">description = #{description},</if>
|
||||
<if test="status != null">status = #{status},</if>
|
||||
<if test="sort != null">sort = #{sort},</if>
|
||||
<if test="updater != null">updater = #{updater},</if>
|
||||
update_time = NOW()
|
||||
</set>
|
||||
WHERE id = #{id} AND deleted = 0
|
||||
</update>
|
||||
|
||||
<!-- 根据ID删除(逻辑删除) -->
|
||||
<update id="deleteById">
|
||||
UPDATE tb_sys_role
|
||||
SET deleted = 1,
|
||||
delete_time = NOW()
|
||||
WHERE id = #{id} AND deleted = 0
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
194
schoolNewsServ/system/src/main/resources/mapper/UserMapper.xml
Normal file
194
schoolNewsServ/system/src/main/resources/mapper/UserMapper.xml
Normal file
@@ -0,0 +1,194 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.xyzh.system.mapper.UserMapper">
|
||||
|
||||
<!-- 基础结果映射 -->
|
||||
<resultMap id="BaseResultMap" type="org.xyzh.common.dto.user.TbSysUser">
|
||||
<id column="id" property="id" jdbcType="VARCHAR"/>
|
||||
<result column="username" property="username" jdbcType="VARCHAR"/>
|
||||
<result column="password" property="password" jdbcType="VARCHAR"/>
|
||||
<result column="email" property="email" jdbcType="VARCHAR"/>
|
||||
<result column="phone" property="phone" jdbcType="VARCHAR"/>
|
||||
<result column="wechat_id" property="wechatID" jdbcType="VARCHAR"/>
|
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="delete_time" property="deleteTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="deleted" property="deleted" jdbcType="Boolean"/>
|
||||
<result column="status" property="status" jdbcType="INTEGER"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 基础字段 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, username, password, email, phone, wechat_id,
|
||||
create_time, update_time, delete_time, deleted, status
|
||||
</sql>
|
||||
|
||||
<!-- 通用条件 -->
|
||||
<sql id="Where_Clause">
|
||||
<where>
|
||||
deleted = 0
|
||||
<if test="username != null and username != ''">
|
||||
AND username LIKE CONCAT('%', #{username}, '%')
|
||||
</if>
|
||||
<if test="email != null and email != ''">
|
||||
AND email LIKE CONCAT('%', #{email}, '%')
|
||||
</if>
|
||||
<if test="phone != null and phone != ''">
|
||||
AND phone = #{phone}
|
||||
</if>
|
||||
<if test="status != null">
|
||||
AND status = #{status}
|
||||
</if>
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<!-- 根据用户名查询用户 -->
|
||||
<select id="selectByUsername" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_sys_user
|
||||
WHERE deleted = 0
|
||||
AND username = #{username}
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
<!-- 根据邮箱查询用户 -->
|
||||
<select id="selectByEmail" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_sys_user
|
||||
WHERE deleted = 0
|
||||
AND email = #{email}
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
<!-- 根据手机号查询用户 -->
|
||||
<select id="selectByPhone" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_sys_user
|
||||
WHERE deleted = 0
|
||||
AND phone = #{phone}
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
<!-- 根据过滤条件查询用户 -->
|
||||
<select id="selectByFilter" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_sys_user
|
||||
<where>
|
||||
deleted = 0
|
||||
<if test="filter.id != null and filter.id != ''">
|
||||
AND id = #{filter.id}
|
||||
</if>
|
||||
<if test="filter.username != null and filter.username != ''">
|
||||
AND username = #{filter.username}
|
||||
</if>
|
||||
<if test="filter.email != null and filter.email != ''">
|
||||
AND email = #{filter.email}
|
||||
</if>
|
||||
<if test="filter.phone != null and filter.phone != ''">
|
||||
AND phone = #{filter.phone}
|
||||
</if>
|
||||
<if test="filter.status != null">
|
||||
AND status = #{filter.status}
|
||||
</if>
|
||||
<if test="filter.wechatID != null and filter.wechatID != ''">
|
||||
AND wechat_id = #{filter.wechatID}
|
||||
</if>
|
||||
</where>
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
<!-- 查询用户列表 -->
|
||||
<select id="selectUserList" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_sys_user
|
||||
<include refid="Where_Clause"/>
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 批量删除用户(逻辑删除) -->
|
||||
<update id="batchDeleteByIds">
|
||||
UPDATE tb_sys_user
|
||||
SET deleted = 1,
|
||||
delete_time = NOW(),
|
||||
updater = #{updater}
|
||||
WHERE deleted = 0
|
||||
AND id IN
|
||||
<foreach collection="userIds" item="userId" open="(" separator="," close=")">
|
||||
#{userId}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
<!-- 插入用户 -->
|
||||
<insert id="insert" parameterType="org.xyzh.common.dto.user.TbSysUser">
|
||||
INSERT INTO tb_sys_user
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">id,</if>
|
||||
<if test="username != null">username,</if>
|
||||
<if test="password != null">password,</if>
|
||||
<if test="email != null">email,</if>
|
||||
<if test="phone != null">phone,</if>
|
||||
<if test="avatar != null">avatar,</if>
|
||||
<if test="nickname != null">nickname,</if>
|
||||
<if test="gender != null">gender,</if>
|
||||
<if test="birthday != null">birthday,</if>
|
||||
<if test="status != null">status,</if>
|
||||
<if test="lastLoginTime != null">last_login_time,</if>
|
||||
<if test="lastLoginIp != null">last_login_ip,</if>
|
||||
<if test="creator != null">creator,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
deleted
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">#{id},</if>
|
||||
<if test="username != null">#{username},</if>
|
||||
<if test="password != null">#{password},</if>
|
||||
<if test="email != null">#{email},</if>
|
||||
<if test="phone != null">#{phone},</if>
|
||||
<if test="avatar != null">#{avatar},</if>
|
||||
<if test="nickname != null">#{nickname},</if>
|
||||
<if test="gender != null">#{gender},</if>
|
||||
<if test="birthday != null">#{birthday},</if>
|
||||
<if test="status != null">#{status},</if>
|
||||
<if test="lastLoginTime != null">#{lastLoginTime},</if>
|
||||
<if test="lastLoginIp != null">#{lastLoginIp},</if>
|
||||
<if test="creator != null">#{creator},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
0
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<!-- 更新用户 -->
|
||||
<update id="updateById" parameterType="org.xyzh.common.dto.user.TbSysUser">
|
||||
UPDATE tb_sys_user
|
||||
<set>
|
||||
<if test="username != null">username = #{username},</if>
|
||||
<if test="password != null">password = #{password},</if>
|
||||
<if test="email != null">email = #{email},</if>
|
||||
<if test="phone != null">phone = #{phone},</if>
|
||||
<if test="avatar != null">avatar = #{avatar},</if>
|
||||
<if test="nickname != null">nickname = #{nickname},</if>
|
||||
<if test="gender != null">gender = #{gender},</if>
|
||||
<if test="birthday != null">birthday = #{birthday},</if>
|
||||
<if test="status != null">status = #{status},</if>
|
||||
<if test="lastLoginTime != null">last_login_time = #{lastLoginTime},</if>
|
||||
<if test="lastLoginIp != null">last_login_ip = #{lastLoginIp},</if>
|
||||
<if test="updater != null">updater = #{updater},</if>
|
||||
update_time = NOW()
|
||||
</set>
|
||||
WHERE id = #{id} AND deleted = 0
|
||||
</update>
|
||||
|
||||
<!-- 根据ID删除(逻辑删除) -->
|
||||
<update id="deleteById">
|
||||
UPDATE tb_sys_user
|
||||
SET deleted = 1,
|
||||
delete_time = NOW()
|
||||
WHERE id = #{id} AND deleted = 0
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user