调度中心API

This commit is contained in:
XinWei 2024-07-11 13:13:09 +08:00
parent 5eff5433fe
commit 0f93f5d2ab
6 changed files with 83 additions and 15 deletions

View File

@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import javax.validation.Valid;
import java.util.Date;
/**
* @Description 调度任务日志Api接口
@ -23,7 +24,13 @@ public interface JobLogApi {
String PREFIX = ApiConstants.PREFIX + "/log";
@GetMapping(PREFIX + "/page")
@Operation(summary = "获得所有任务列表")
public CommonResult<PageResult<JobLogRespDTO>> getPage(@Valid JobLogPageReqDTO jobLogPageReqDTO);
public CommonResult<PageResult<JobLogRespDTO>> getPage(@RequestParam(value = "pageNo") Integer pageNo,
@RequestParam(value = "pageSize") Integer pageSize,
@RequestParam(value = "jobId") Integer jobId,
@RequestParam(required = false, value = "handlerName") String handlerName,
@RequestParam(required = false, value = "beginTime") Date beginTime,
@RequestParam(required = false, value = "endTime") Date endTime,
@RequestParam(required = false, value = "status") Integer status);
@GetMapping(PREFIX + "/get")
@Operation(summary = "获得任务日志详情")

View File

@ -16,6 +16,7 @@ import com.xxl.job.core.util.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@ -40,13 +41,26 @@ public class JobLogApiImpl implements JobLogApi {
public XxlJobLogDao xxlJobLogDao;
@Override
public CommonResult<PageResult<JobLogRespDTO>> getPage(JobLogPageReqDTO jobLogPageReqDTO) {
public CommonResult<PageResult<JobLogRespDTO>> getPage(Integer pageNo,
Integer pageSize,
Integer jobId,
String handlerName,
Date beginTime,
Date endTime,
Integer status) {
JobLogPageReqDTO jobLogPageReqDTO = new JobLogPageReqDTO();
jobLogPageReqDTO.setPageNo(pageNo);
jobLogPageReqDTO.setPageSize(pageSize);
jobLogPageReqDTO.setJobId(jobId);
jobLogPageReqDTO.setHandlerName(handlerName);
jobLogPageReqDTO.setBeginTime(beginTime);
jobLogPageReqDTO.setEndTime(endTime);
jobLogPageReqDTO.setStatus(status);
// 设置默认组为3
int jobGroup = 3;
int status = jobLogPageReqDTO.getStatus() == null ? -1 : jobLogPageReqDTO.getStatus();
// page query
List<JobLogRespDTO> list = xxlJobLogDao.apiPageList(jobLogPageReqDTO.getPageNo(), jobLogPageReqDTO.getPageSize(), jobGroup, jobLogPageReqDTO.getJobId(), jobLogPageReqDTO.getBeginTime(), jobLogPageReqDTO.getEndTime(), status);
int list_count = xxlJobLogDao.pageListCount(jobLogPageReqDTO.getPageNo(), jobLogPageReqDTO.getPageSize(), jobGroup, jobLogPageReqDTO.getJobId(), jobLogPageReqDTO.getBeginTime(), jobLogPageReqDTO.getEndTime(), status);
List<JobLogRespDTO> list = xxlJobLogDao.apiPageList(jobLogPageReqDTO.getPageNo(), jobLogPageReqDTO.getPageSize(), jobGroup, jobLogPageReqDTO.getJobId(), jobLogPageReqDTO.getBeginTime(), jobLogPageReqDTO.getEndTime(), status, jobLogPageReqDTO.getHandlerName());
int list_count = xxlJobLogDao.apiPageListCount(jobLogPageReqDTO.getPageNo(), jobLogPageReqDTO.getPageSize(), jobGroup, jobLogPageReqDTO.getJobId(), jobLogPageReqDTO.getBeginTime(), jobLogPageReqDTO.getEndTime(), status, jobLogPageReqDTO.getHandlerName());
// package result
PageResult<JobLogRespDTO> pageResult = new PageResult<>();
pageResult.setTotal((long) list_count);
@ -60,13 +74,14 @@ public class JobLogApiImpl implements JobLogApi {
JobLogRespDTO jobLogRespDTO = new JobLogRespDTO();
jobLogRespDTO.setId(id);
jobLogRespDTO.setJobId(load.getJobId());
if (load.getTriggerCode() == 200) {
jobLogRespDTO.setDuration((int) (load.getHandleTime().getTime() - load.getTriggerTime().getTime()));
}
jobLogRespDTO.setBeginTime(load.getTriggerTime());
jobLogRespDTO.setEndTime(load.getHandleTime());
jobLogRespDTO.setHandlerName(load.getExecutorHandler());
jobLogRespDTO.setHandlerParam(load.getExecutorParam());
jobLogRespDTO.setStatus(load.getAlarmStatus());
jobLogRespDTO.setExecuteIndex(1);
jobLogRespDTO.setStatus(load.getHandleCode() == 200 ? 1 : 2);
return CommonResult.success(jobLogRespDTO);
}
}

View File

@ -30,7 +30,8 @@ public interface XxlJobLogDao {
@Param("jobId") int jobId,
@Param("triggerTimeStart") Date triggerTimeStart,
@Param("triggerTimeEnd") Date triggerTimeEnd,
@Param("logStatus") Integer logStatus);
@Param("logStatus") Integer logStatus,
@Param("handlerName") String handlerName);
public int pageListCount(@Param("offset") int offset,
@Param("pagesize") int pagesize,
@Param("jobGroup") int jobGroup,
@ -67,4 +68,12 @@ public interface XxlJobLogDao {
public List<Long> findLostJobIds(@Param("losedTime") Date losedTime);
int apiPageListCount(@Param("offset") int offset,
@Param("pagesize") int pagesize,
@Param("jobGroup") int jobGroup,
@Param("jobId") int jobId,
@Param("triggerTimeStart") Date triggerTimeStart,
@Param("triggerTimeEnd") Date triggerTimeEnd,
@Param("logStatus") Integer logStatus,
@Param("handlerName") String handlerName);
}

View File

@ -87,10 +87,11 @@
<result column="trigger_time" property="beginTime"/>
<result column="handle_time" property="endTime"/>
<result column="duration" property="duration"/>
<result column="alarm_status" property="status"/>
<result column="status" property="status"/>
</resultMap>
<select id="apiPageList" resultMap="ApiXxlJobLog">
SELECT <include refid="Base_Column_List" />, ROW_NUMBER() OVER (ORDER BY t.trigger_time) AS 'index', (t.handle_time -t.trigger_time) AS 'duration'
SELECT <include refid="Base_Column_List" />, ROW_NUMBER() OVER (ORDER BY t.trigger_time) AS 'index', (t.handle_time -t.trigger_time) AS 'duration',
IF(t.handle_code = 200, 1, 2) AS 'status'
FROM xxl_job_log AS t
<trim prefix="WHERE" prefixOverrides="AND | OR" >
<if test="jobId==0 and jobGroup gt 0">
@ -118,6 +119,9 @@
AND t.trigger_code = 200
AND t.handle_code = 0
</if>
<if test="handlerName != null">
AND t.handlerName LIKE CONCAT('%', #{handlerName}, '%')
</if>
</trim>
ORDER BY t.trigger_time DESC
LIMIT #{offset}, #{pagesize}
@ -154,6 +158,40 @@
</if>
</trim>
</select>
<select id="apiPageListCount" resultType="int">
SELECT count(1)
FROM xxl_job_log AS t
<trim prefix="WHERE" prefixOverrides="AND | OR" >
<if test="jobId==0 and jobGroup gt 0">
AND t.job_group = #{jobGroup}
</if>
<if test="jobId gt 0">
AND t.job_id = #{jobId}
</if>
<if test="triggerTimeStart != null">
AND t.trigger_time <![CDATA[ >= ]]> #{triggerTimeStart}
</if>
<if test="triggerTimeEnd != null">
AND t.trigger_time <![CDATA[ <= ]]> #{triggerTimeEnd}
</if>
<if test="logStatus == 1" >
AND t.handle_code = 200
</if>
<if test="logStatus == 2" >
AND (
t.trigger_code NOT IN (0, 200) OR
t.handle_code NOT IN (0, 200)
)
</if>
<if test="logStatus == 3" >
AND t.trigger_code = 200
AND t.handle_code = 0
</if>
<if test="handlerName != null">
AND t.executor_handler LIKE CONCAT('%', #{handlerName}, '%')
</if>
</trim>
</select>
<select id="load" parameterType="java.lang.Long" resultMap="XxlJobLog">
SELECT <include refid="Base_Column_List" />

View File

@ -36,7 +36,7 @@ public class JobLogController {
@Operation(summary = "获得任务日志列表")
@PreAuthorize("@ss.hasPermission('infra:job-log:query')")
public CommonResult<PageResult<JobLogRespDTO>> getPage(@Valid JobLogPageReqDTO jobLogPageReqDTO){
return jobLogApi.getPage(jobLogPageReqDTO);
return jobLogApi.getPage(jobLogPageReqDTO.getPageNo(), jobLogPageReqDTO.getPageSize(), jobLogPageReqDTO.getJobId(), jobLogPageReqDTO.getHandlerName(), jobLogPageReqDTO.getBeginTime(), jobLogPageReqDTO.getEndTime(), jobLogPageReqDTO.getStatus());
}
@GetMapping("/get")
@ -52,7 +52,7 @@ public class JobLogController {
public void exportJobInfoExcel(@Valid JobLogPageReqDTO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<JobLogRespDTO> list = jobLogApi.getPage(pageReqVO).getData().getList();
List<JobLogRespDTO> list = jobLogApi.getPage(pageReqVO.getPageNo(), pageReqVO.getPageSize(), pageReqVO.getJobId(), pageReqVO.getHandlerName(), pageReqVO.getBeginTime(), pageReqVO.getEndTime(), pageReqVO.getStatus()).getData().getList();
//导出 Excel
ExcelUtils.write(response, "任务调度.xls", "数据", JobLogRespDTO.class,
list);

View File

@ -156,7 +156,6 @@ yudao:
- infra_file_content
- infra_job
- infra_job_log
- infra_job_log
- infra_data_source_config
debug: false