system和auth 初步构建

This commit is contained in:
2025-09-28 17:32:37 +08:00
parent c22d5561cd
commit ef96570896
38 changed files with 4741 additions and 249 deletions

View 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

View 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>

View File

@@ -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>

View 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>

View File

@@ -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>

View 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>

View 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>