serv\web- 日志
This commit is contained in:
@@ -5,6 +5,7 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.xyzh.common.core.page.PageParam;
|
||||
import org.xyzh.common.dto.crontab.TbCrontabTask;
|
||||
import org.xyzh.common.vo.UserDeptRoleVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -55,31 +56,42 @@ public interface CrontabTaskMapper extends BaseMapper<TbCrontabTask> {
|
||||
TbCrontabTask selectTaskById(@Param("taskId") String taskId);
|
||||
|
||||
/**
|
||||
* @description 根据过滤条件查询任务列表
|
||||
* @description 根据过滤条件查询任务列表(包含权限过滤)
|
||||
* @param filter 过滤条件
|
||||
* @param userDeptRoles 用户部门角色列表
|
||||
* @return List<TbCrontabTask> 任务列表
|
||||
* @author yslg
|
||||
* @since 2025-10-25
|
||||
*/
|
||||
List<TbCrontabTask> selectTaskList(@Param("filter") TbCrontabTask filter);
|
||||
List<TbCrontabTask> selectTaskList(@Param("filter") TbCrontabTask filter, @Param("userDeptRoles") List<UserDeptRoleVO> userDeptRoles);
|
||||
|
||||
/**
|
||||
* @description 分页查询任务列表
|
||||
* @description 分页查询任务列表(包含权限过滤)
|
||||
* @param filter 过滤条件
|
||||
* @param pageParam 分页参数
|
||||
* @param userDeptRoles 用户部门角色列表
|
||||
* @return List<TbCrontabTask> 任务列表
|
||||
* @author yslg
|
||||
* @since 2025-10-25
|
||||
*/
|
||||
List<TbCrontabTask> selectTaskPage(@Param("filter") TbCrontabTask filter, @Param("pageParam") PageParam pageParam);
|
||||
List<TbCrontabTask> selectTaskPage(@Param("filter") TbCrontabTask filter, @Param("pageParam") PageParam pageParam, @Param("userDeptRoles") List<UserDeptRoleVO> userDeptRoles);
|
||||
|
||||
/**
|
||||
* @description 查询所有运行中的任务
|
||||
* @description 查询所有运行中的任务(包含权限过滤)
|
||||
* @param userDeptRoles 用户部门角色列表
|
||||
* @return List<TbCrontabTask> 任务列表
|
||||
* @author yslg
|
||||
* @since 2025-10-25
|
||||
*/
|
||||
List<TbCrontabTask> selectRunningTasks();
|
||||
List<TbCrontabTask> selectRunningTasks(@Param("userDeptRoles") List<UserDeptRoleVO> userDeptRoles);
|
||||
|
||||
/**
|
||||
* @description 查询所有运行中的任务(系统级,不含权限过滤,用于系统初始化)
|
||||
* @return List<TbCrontabTask> 任务列表
|
||||
* @author yslg
|
||||
* @since 2025-10-25
|
||||
*/
|
||||
List<TbCrontabTask> selectAllRunningTasks();
|
||||
|
||||
/**
|
||||
* @description 更新任务状态
|
||||
@@ -102,12 +114,13 @@ public interface CrontabTaskMapper extends BaseMapper<TbCrontabTask> {
|
||||
TbCrontabTask selectTaskByBeanAndMethod(@Param("beanName") String beanName, @Param("methodName") String methodName);
|
||||
|
||||
/**
|
||||
* @description 查询任务总数
|
||||
* @description 查询任务总数(包含权限过滤)
|
||||
* @param filter 过滤条件
|
||||
* @param userDeptRoles 用户部门角色列表
|
||||
* @return int 任务总数
|
||||
* @author yslg
|
||||
* @since 2025-10-25
|
||||
*/
|
||||
int countSelectTask(@Param("filter") TbCrontabTask filter);
|
||||
int countSelectTask(@Param("filter") TbCrontabTask filter, @Param("userDeptRoles") List<UserDeptRoleVO> userDeptRoles);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,8 +33,8 @@ public class SchedulerInitializer implements CommandLineRunner {
|
||||
try {
|
||||
logger.info("开始初始化定时任务...");
|
||||
|
||||
// 查询所有运行中的任务
|
||||
List<TbCrontabTask> runningTasks = taskMapper.selectRunningTasks();
|
||||
// 查询所有运行中的任务(系统级,不受权限限制)
|
||||
List<TbCrontabTask> runningTasks = taskMapper.selectAllRunningTasks();
|
||||
|
||||
if (runningTasks != null && !runningTasks.isEmpty()) {
|
||||
for (TbCrontabTask task : runningTasks) {
|
||||
|
||||
@@ -217,7 +217,8 @@ public class CrontabServiceImpl implements CrontabService {
|
||||
}
|
||||
filter.setDeleted(false);
|
||||
|
||||
List<TbCrontabTask> list = taskMapper.selectTaskList(filter);
|
||||
List<UserDeptRoleVO> userDeptRoles = LoginUtil.getCurrentDeptRole();
|
||||
List<TbCrontabTask> list = taskMapper.selectTaskList(filter, userDeptRoles);
|
||||
resultDomain.success("查询成功", list);
|
||||
} catch (Exception e) {
|
||||
logger.error("查询定时任务列表异常: ", e);
|
||||
@@ -239,8 +240,9 @@ public class CrontabServiceImpl implements CrontabService {
|
||||
pageParam = new PageParam();
|
||||
}
|
||||
|
||||
List<TbCrontabTask> list = taskMapper.selectTaskPage(filter, pageParam);
|
||||
int total = taskMapper.countSelectTask(filter);
|
||||
List<UserDeptRoleVO> userDeptRoles = LoginUtil.getCurrentDeptRole();
|
||||
List<TbCrontabTask> list = taskMapper.selectTaskPage(filter, pageParam, userDeptRoles);
|
||||
int total = taskMapper.countSelectTask(filter, userDeptRoles);
|
||||
|
||||
PageDomain<TbCrontabTask> pageDomain = new PageDomain<>();
|
||||
pageDomain.setDataList(list);
|
||||
|
||||
@@ -90,6 +90,37 @@
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<!-- 权限过滤条件(基于dept_path的高效继承) -->
|
||||
<sql id="Permission_Filter">
|
||||
INNER JOIN tb_resource_permission rp ON ct.task_id = rp.resource_id
|
||||
AND rp.resource_type = 7
|
||||
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>
|
||||
|
||||
<!-- 插入任务 -->
|
||||
<insert id="insertTask">
|
||||
INSERT INTO tb_crontab_task
|
||||
@@ -168,27 +199,69 @@
|
||||
|
||||
<!-- 根据过滤条件查询任务列表 -->
|
||||
<select id="selectTaskList" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List" />
|
||||
FROM tb_crontab_task
|
||||
<include refid="Filter_Where_Clause" />
|
||||
ORDER BY create_time DESC
|
||||
SELECT DISTINCT ct.*
|
||||
FROM tb_crontab_task ct
|
||||
<include refid="Permission_Filter" />
|
||||
WHERE ct.deleted = 0
|
||||
<if test="filter != null">
|
||||
<if test="filter.ID != null and filter.ID != ''">
|
||||
AND ct.id = #{filter.ID}
|
||||
</if>
|
||||
<if test="filter.taskId != null and filter.taskId != ''">
|
||||
AND ct.task_id = #{filter.taskId}
|
||||
</if>
|
||||
<if test="filter.taskName != null and filter.taskName != ''">
|
||||
AND ct.task_name LIKE CONCAT('%', #{filter.taskName}, '%')
|
||||
</if>
|
||||
<if test="filter.taskGroup != null and filter.taskGroup != ''">
|
||||
AND ct.task_group = #{filter.taskGroup}
|
||||
</if>
|
||||
<if test="filter.status != null">
|
||||
AND ct.status = #{filter.status}
|
||||
</if>
|
||||
</if>
|
||||
ORDER BY ct.create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 分页查询任务列表 -->
|
||||
<select id="selectTaskPage" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List" />
|
||||
FROM tb_crontab_task
|
||||
<include refid="Filter_Where_Clause" />
|
||||
ORDER BY create_time DESC
|
||||
SELECT DISTINCT ct.*
|
||||
FROM tb_crontab_task ct
|
||||
<include refid="Permission_Filter" />
|
||||
WHERE ct.deleted = 0
|
||||
<if test="filter != null">
|
||||
<if test="filter.ID != null and filter.ID != ''">
|
||||
AND ct.id = #{filter.ID}
|
||||
</if>
|
||||
<if test="filter.taskId != null and filter.taskId != ''">
|
||||
AND ct.task_id = #{filter.taskId}
|
||||
</if>
|
||||
<if test="filter.taskName != null and filter.taskName != ''">
|
||||
AND ct.task_name LIKE CONCAT('%', #{filter.taskName}, '%')
|
||||
</if>
|
||||
<if test="filter.taskGroup != null and filter.taskGroup != ''">
|
||||
AND ct.task_group = #{filter.taskGroup}
|
||||
</if>
|
||||
<if test="filter.status != null">
|
||||
AND ct.status = #{filter.status}
|
||||
</if>
|
||||
</if>
|
||||
ORDER BY ct.create_time DESC
|
||||
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
|
||||
</select>
|
||||
|
||||
<!-- 查询所有运行中的任务 -->
|
||||
<!-- 查询所有运行中的任务(包含权限过滤) -->
|
||||
<select id="selectRunningTasks" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List" />
|
||||
SELECT DISTINCT ct.*
|
||||
FROM tb_crontab_task ct
|
||||
<include refid="Permission_Filter" />
|
||||
WHERE ct.status = 1 AND ct.deleted = 0
|
||||
ORDER BY ct.create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 查询所有运行中的任务(系统级,不含权限过滤,用于系统初始化) -->
|
||||
<select id="selectAllRunningTasks" resultMap="BaseResultMap">
|
||||
SELECT *
|
||||
FROM tb_crontab_task
|
||||
WHERE status = 1 AND deleted = 0
|
||||
ORDER BY create_time DESC
|
||||
@@ -214,9 +287,27 @@
|
||||
</select>
|
||||
|
||||
<!-- countSelectTask -->
|
||||
|
||||
<select id="countSelectTask">
|
||||
SELECT COUNT(1) FROM tb_crontab_task
|
||||
<include refid="Filter_Where_Clause" />
|
||||
<select id="countSelectTask" resultType="int">
|
||||
SELECT COUNT(DISTINCT ct.id)
|
||||
FROM tb_crontab_task ct
|
||||
<include refid="Permission_Filter" />
|
||||
WHERE ct.deleted = 0
|
||||
<if test="filter != null">
|
||||
<if test="filter.ID != null and filter.ID != ''">
|
||||
AND ct.id = #{filter.ID}
|
||||
</if>
|
||||
<if test="filter.taskId != null and filter.taskId != ''">
|
||||
AND ct.task_id = #{filter.taskId}
|
||||
</if>
|
||||
<if test="filter.taskName != null and filter.taskName != ''">
|
||||
AND ct.task_name LIKE CONCAT('%', #{filter.taskName}, '%')
|
||||
</if>
|
||||
<if test="filter.taskGroup != null and filter.taskGroup != ''">
|
||||
AND ct.task_group = #{filter.taskGroup}
|
||||
</if>
|
||||
<if test="filter.status != null">
|
||||
AND ct.status = #{filter.status}
|
||||
</if>
|
||||
</if>
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user