system和auth 初步构建
This commit is contained in:
@@ -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