serv\web- 多租户修改
This commit is contained in:
@@ -78,13 +78,56 @@
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<!-- selectCourses -->
|
||||
<!-- 权限过滤条件(基于dept_path的高效继承) -->
|
||||
<sql id="Permission_Filter">
|
||||
INNER JOIN tb_resource_permission rp ON c.course_id = rp.resource_id
|
||||
AND rp.resource_type = 2
|
||||
AND rp.deleted = 0
|
||||
AND rp.can_read = 1
|
||||
AND (
|
||||
-- 全局权限:所有用户可访问
|
||||
(rp.dept_id IS NULL AND rp.role_id IS NULL)
|
||||
<if test="userDeptRoles != null and userDeptRoles.size() > 0">
|
||||
OR EXISTS (
|
||||
SELECT 1
|
||||
FROM (
|
||||
<foreach collection="userDeptRoles" item="udr" separator=" UNION ALL ">
|
||||
SELECT #{udr.deptID} AS dept_id, #{udr.deptPath} AS dept_path, #{udr.roleID} AS role_id
|
||||
</foreach>
|
||||
) user_roles
|
||||
LEFT JOIN tb_sys_dept perm_dept ON perm_dept.dept_id = rp.dept_id AND perm_dept.deleted = 0
|
||||
WHERE
|
||||
-- 部门级权限:当前部门或父部门(通过dept_path判断继承关系)
|
||||
(rp.role_id IS NULL AND rp.dept_id IS NOT NULL
|
||||
AND user_roles.dept_path LIKE CONCAT(perm_dept.dept_path, '%'))
|
||||
-- 角色级权限:跨部门的角色权限
|
||||
OR (rp.dept_id IS NULL AND rp.role_id = user_roles.role_id)
|
||||
-- 精确权限:特定部门的特定角色
|
||||
OR (rp.dept_id = user_roles.dept_id AND rp.role_id = user_roles.role_id)
|
||||
)
|
||||
</if>
|
||||
)
|
||||
</sql>
|
||||
|
||||
<!-- selectCourses - 添加权限过滤 -->
|
||||
<select id="selectCourses" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_course
|
||||
<include refid="Where_Clause"/>
|
||||
ORDER BY order_num ASC, create_time DESC
|
||||
SELECT DISTINCT c.*
|
||||
FROM tb_course c
|
||||
<include refid="Permission_Filter"/>
|
||||
WHERE c.deleted = 0
|
||||
<if test="filter.courseID != null and filter.courseID != ''">
|
||||
AND c.course_id = #{filter.courseID}
|
||||
</if>
|
||||
<if test="filter.name != null and filter.name != ''">
|
||||
AND c.name LIKE CONCAT('%', #{filter.name}, '%')
|
||||
</if>
|
||||
<if test="filter.teacher != null and filter.teacher != ''">
|
||||
AND c.teacher LIKE CONCAT('%', #{filter.teacher}, '%')
|
||||
</if>
|
||||
<if test="filter.status != null">
|
||||
AND c.status = #{filter.status}
|
||||
</if>
|
||||
ORDER BY c.order_num ASC, c.create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 根据课程ID查询课程信息 -->
|
||||
@@ -270,20 +313,62 @@
|
||||
</delete>
|
||||
|
||||
<!-- 分页查询课程 -->
|
||||
<!-- selectCoursesPage - 添加权限过滤 -->
|
||||
<select id="selectCoursesPage" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List" />
|
||||
FROM tb_course
|
||||
<include refid="Filter_Clause" />
|
||||
ORDER BY order_num ASC, create_time DESC
|
||||
SELECT DISTINCT c.*
|
||||
FROM tb_course c
|
||||
<include refid="Permission_Filter"/>
|
||||
WHERE c.deleted = 0
|
||||
<if test="filter != null">
|
||||
<if test="filter.courseID != null and filter.courseID != ''">
|
||||
AND c.course_id = #{filter.courseID}
|
||||
</if>
|
||||
<if test="filter.name != null and filter.name != ''">
|
||||
AND c.name LIKE CONCAT('%', #{filter.name}, '%')
|
||||
</if>
|
||||
<if test="filter.teacher != null and filter.teacher != ''">
|
||||
AND c.teacher LIKE CONCAT('%', #{filter.teacher}, '%')
|
||||
</if>
|
||||
<if test="filter.status != null">
|
||||
AND c.status = #{filter.status}
|
||||
</if>
|
||||
<if test="filter.orderNum != null">
|
||||
AND c.order_num = #{filter.orderNum}
|
||||
</if>
|
||||
<if test="filter.creator != null and filter.creator != ''">
|
||||
AND c.creator = #{filter.creator}
|
||||
</if>
|
||||
</if>
|
||||
ORDER BY c.order_num ASC, c.create_time DESC
|
||||
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
|
||||
</select>
|
||||
|
||||
<!-- 统计课程总数 -->
|
||||
<!-- 统计课程总数 - 添加权限过滤 -->
|
||||
<select id="countCourses" resultType="long">
|
||||
SELECT COUNT(1)
|
||||
FROM tb_course
|
||||
<include refid="Filter_Clause" />
|
||||
SELECT COUNT(DISTINCT c.id)
|
||||
FROM tb_course c
|
||||
<include refid="Permission_Filter"/>
|
||||
WHERE c.deleted = 0
|
||||
<if test="filter != null">
|
||||
<if test="filter.courseID != null and filter.courseID != ''">
|
||||
AND c.course_id = #{filter.courseID}
|
||||
</if>
|
||||
<if test="filter.name != null and filter.name != ''">
|
||||
AND c.name LIKE CONCAT('%', #{filter.name}, '%')
|
||||
</if>
|
||||
<if test="filter.teacher != null and filter.teacher != ''">
|
||||
AND c.teacher LIKE CONCAT('%', #{filter.teacher}, '%')
|
||||
</if>
|
||||
<if test="filter.status != null">
|
||||
AND c.status = #{filter.status}
|
||||
</if>
|
||||
<if test="filter.orderNum != null">
|
||||
AND c.order_num = #{filter.orderNum}
|
||||
</if>
|
||||
<if test="filter.creator != null and filter.creator != ''">
|
||||
AND c.creator = #{filter.creator}
|
||||
</if>
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<update id="incrementViewCount">
|
||||
|
||||
@@ -56,13 +56,53 @@
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<!-- selectLearningTasks -->
|
||||
<!-- 权限过滤条件(基于dept_path的高效继承) -->
|
||||
<sql id="Permission_Filter">
|
||||
INNER JOIN tb_resource_permission rp ON t.task_id = rp.resource_id
|
||||
AND rp.resource_type = 3
|
||||
AND rp.deleted = 0
|
||||
AND rp.can_read = 1
|
||||
AND (
|
||||
-- 全局权限:所有用户可访问
|
||||
(rp.dept_id IS NULL AND rp.role_id IS NULL)
|
||||
<if test="userDeptRoles != null and userDeptRoles.size() > 0">
|
||||
OR EXISTS (
|
||||
SELECT 1
|
||||
FROM (
|
||||
<foreach collection="userDeptRoles" item="udr" separator=" UNION ALL ">
|
||||
SELECT #{udr.deptID} AS dept_id, #{udr.deptPath} AS dept_path, #{udr.roleID} AS role_id
|
||||
</foreach>
|
||||
) user_roles
|
||||
LEFT JOIN tb_sys_dept perm_dept ON perm_dept.dept_id = rp.dept_id AND perm_dept.deleted = 0
|
||||
WHERE
|
||||
-- 部门级权限:当前部门或父部门(通过dept_path判断继承关系)
|
||||
(rp.role_id IS NULL AND rp.dept_id IS NOT NULL
|
||||
AND user_roles.dept_path LIKE CONCAT(perm_dept.dept_path, '%'))
|
||||
-- 角色级权限:跨部门的角色权限
|
||||
OR (rp.dept_id IS NULL AND rp.role_id = user_roles.role_id)
|
||||
-- 精确权限:特定部门的特定角色
|
||||
OR (rp.dept_id = user_roles.dept_id AND rp.role_id = user_roles.role_id)
|
||||
)
|
||||
</if>
|
||||
)
|
||||
</sql>
|
||||
|
||||
<!-- selectLearningTasks - 添加权限过滤 -->
|
||||
<select id="selectLearningTasks" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_learning_task
|
||||
<include refid="Where_Clause"/>
|
||||
ORDER BY create_time DESC
|
||||
SELECT DISTINCT t.*
|
||||
FROM tb_learning_task t
|
||||
<include refid="Permission_Filter"/>
|
||||
WHERE t.deleted = 0
|
||||
<if test="filter.taskID != null and filter.taskID != ''">
|
||||
AND t.task_id = #{filter.taskID}
|
||||
</if>
|
||||
<if test="filter.name != null and filter.name != ''">
|
||||
AND t.name LIKE CONCAT('%', #{filter.name}, '%')
|
||||
</if>
|
||||
<if test="filter.status != null">
|
||||
AND t.status = #{filter.status}
|
||||
</if>
|
||||
ORDER BY t.create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 根据任务ID查询任务信息 -->
|
||||
@@ -215,33 +255,78 @@
|
||||
</delete>
|
||||
|
||||
<!-- 分页查询学习任务 -->
|
||||
<!-- selectLearningTasksPage - 添加权限过滤 -->
|
||||
<select id="selectLearningTasksPage" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List" />
|
||||
FROM tb_learning_task
|
||||
<include refid="Filter_Clause" />
|
||||
ORDER BY create_time DESC
|
||||
SELECT DISTINCT t.*
|
||||
FROM tb_learning_task t
|
||||
<include refid="Permission_Filter"/>
|
||||
WHERE t.deleted = 0
|
||||
<if test="filter != null">
|
||||
<if test="filter.taskID != null and filter.taskID != ''">
|
||||
AND t.task_id = #{filter.taskID}
|
||||
</if>
|
||||
<if test="filter.name != null and filter.name != ''">
|
||||
AND t.name LIKE CONCAT('%', #{filter.name}, '%')
|
||||
</if>
|
||||
<if test="filter.status != null">
|
||||
AND t.status = #{filter.status}
|
||||
</if>
|
||||
</if>
|
||||
ORDER BY t.create_time DESC
|
||||
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
|
||||
</select>
|
||||
|
||||
<!-- selectUserLearningTasksPage - 添加权限过滤 -->
|
||||
<select id="selectUserLearningTasksPage" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
SELECT DISTINCT
|
||||
tlt.id, tlt.task_id, tlt.name, tlt.description, tlt.start_time, tlt.end_time, ttu.status,
|
||||
tlt.creator, tlt.updater, tlt.create_time, tlt.update_time
|
||||
FROM tb_task_user ttu
|
||||
INNER JOIN tb_learning_task tlt ON ttu.task_id = tlt.task_id
|
||||
INNER JOIN tb_resource_permission rp ON tlt.task_id = rp.resource_id
|
||||
AND rp.resource_type = 3
|
||||
AND rp.deleted = 0
|
||||
AND rp.can_read = 1
|
||||
AND (
|
||||
(rp.dept_id IS NULL AND rp.role_id IS NULL)
|
||||
<if test="userDeptRoles != null and userDeptRoles.size() > 0">
|
||||
OR EXISTS (
|
||||
SELECT 1
|
||||
FROM (
|
||||
<foreach collection="userDeptRoles" item="udr" separator=" UNION ALL ">
|
||||
SELECT #{udr.deptID} AS dept_id, #{udr.roleID} AS role_id
|
||||
</foreach>
|
||||
) user_roles
|
||||
WHERE (rp.dept_id = user_roles.dept_id AND rp.role_id IS NULL)
|
||||
OR (rp.role_id = user_roles.role_id AND rp.dept_id IS NULL)
|
||||
OR (rp.dept_id = user_roles.dept_id AND rp.role_id = user_roles.role_id)
|
||||
)
|
||||
</if>
|
||||
)
|
||||
WHERE ttu.user_id = #{filter.userID}
|
||||
AND tlt.deleted = 0
|
||||
AND ttu.deleted = 0
|
||||
ORDER BY create_time DESC
|
||||
ORDER BY tlt.create_time DESC
|
||||
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
|
||||
</select>
|
||||
|
||||
<!-- 统计学习任务总数 -->
|
||||
<!-- 统计学习任务总数 - 添加权限过滤 -->
|
||||
<select id="countLearningTasks" resultType="long">
|
||||
SELECT COUNT(1)
|
||||
FROM tb_learning_task
|
||||
<include refid="Filter_Clause" />
|
||||
SELECT COUNT(DISTINCT t.id)
|
||||
FROM tb_learning_task t
|
||||
<include refid="Permission_Filter"/>
|
||||
WHERE t.deleted = 0
|
||||
<if test="filter != null">
|
||||
<if test="filter.taskID != null and filter.taskID != ''">
|
||||
AND t.task_id = #{filter.taskID}
|
||||
</if>
|
||||
<if test="filter.name != null and filter.name != ''">
|
||||
AND t.name LIKE CONCAT('%', #{filter.name}, '%')
|
||||
</if>
|
||||
<if test="filter.status != null">
|
||||
AND t.status = #{filter.status}
|
||||
</if>
|
||||
</if>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user