From c936bd549eb74ffb7713bcd807ca187a56464bd7 Mon Sep 17 00:00:00 2001 From: kdyzm Date: Fri, 14 May 2021 18:42:09 +0800 Subject: [PATCH] =?UTF-8?q?xxl-job-admin=E6=89=A7=E8=A1=8C=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E9=A1=B5=E6=96=B0=E5=A2=9E=E6=98=BE=E7=A4=BA=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E5=99=A8=E5=92=8C=E6=89=A7=E8=A1=8Cjob?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/JobLogController.java | 35 ++++++++++++++++--- .../xxl/job/admin/core/model/XxlJobLog.java | 18 ++++++++++ .../com/xxl/job/admin/dao/XxlJobGroupDao.java | 7 ++++ .../com/xxl/job/admin/dao/XxlJobInfoDao.java | 2 ++ .../resources/i18n/message_zh_CN.properties | 2 ++ .../mybatis-mapper/XxlJobGroupMapper.xml | 12 +++++++ .../mybatis-mapper/XxlJobInfoMapper.xml | 14 +++++++- .../resources/static/js/joblog.index.1.js | 20 ++++------- .../templates/joblog/joblog.index.ftl | 6 ++-- 9 files changed, 95 insertions(+), 21 deletions(-) diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobLogController.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobLogController.java index dcf5bb83..2df347f7 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobLogController.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobLogController.java @@ -15,21 +15,21 @@ import com.xxl.job.core.biz.model.LogParam; import com.xxl.job.core.biz.model.LogResult; import com.xxl.job.core.biz.model.ReturnT; +import com.xxl.job.core.handler.annotation.XxlJob; import com.xxl.job.core.util.DateUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; +import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; +import java.util.stream.Collectors; /** * index controller @@ -91,6 +91,7 @@ public Map pageList(HttpServletRequest request, @RequestParam(required = false, defaultValue = "10") int length, int jobGroup, int jobId, int logStatus, String filterTime) { + logger.info("开始执行"); // valid permission JobInfoController.validPermission(request, jobGroup); // 仅管理员支持查询全部;普通用户仅支持查询有权限的 jobGroup @@ -107,6 +108,32 @@ public Map pageList(HttpServletRequest request, // page query List list = xxlJobLogDao.pageList(start, length, jobGroup, jobId, triggerTimeStart, triggerTimeEnd, logStatus); + List jobGroupIds = list.stream().map(XxlJobLog::getJobGroup).collect(Collectors.toList()); + List jobIds = list.stream().map(XxlJobLog::getJobId).collect(Collectors.toList()); + List jobGroups=xxlJobGroupDao.selectByIds(jobGroupIds); + List xxlJobs = xxlJobInfoDao.selectByIds(jobIds); + Map xxlJobInfoMap = new HashMap<>(); + Map xxlJobGroupMap = new HashMap<>(); + if(!CollectionUtils.isEmpty(jobGroups)){ + xxlJobGroupMap = jobGroups.stream().collect(Collectors.toMap(XxlJobGroup::getId,i->i,(v1,v2)->v2)); + } + if(!CollectionUtils.isEmpty(xxlJobs)){ + xxlJobInfoMap = xxlJobs.stream().collect(Collectors.toMap(XxlJobInfo::getId,i->i,(v1,v2)->v2)); + } + Map finalXxlJobGroupMap = xxlJobGroupMap; + Map finalXxlJobInfoMap = xxlJobInfoMap; + list.forEach(item->{ + int jobGroup1 = item.getJobGroup(); + int jobId1 = item.getJobId(); + XxlJobGroup xxlJobGroup = finalXxlJobGroupMap.get(jobGroup1); + XxlJobInfo xxlJobInfo = finalXxlJobInfoMap.get(jobId1); + if(Objects.nonNull(xxlJobGroup)){ + item.setJobGroupName(xxlJobGroup.getTitle()); + } + if(Objects.nonNull(xxlJobInfo)){ + item.setJobName(xxlJobInfo.getJobDesc()); + } + }); int list_count = xxlJobLogDao.pageListCount(start, length, jobGroup, jobId, triggerTimeStart, triggerTimeEnd, logStatus); // package result diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/model/XxlJobLog.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/model/XxlJobLog.java index 7d3072aa..8f551f0a 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/model/XxlJobLog.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/model/XxlJobLog.java @@ -13,6 +13,8 @@ public class XxlJobLog { // job info private int jobGroup; private int jobId; + private String jobGroupName; + private String jobName; // execute info private String executorAddress; @@ -34,6 +36,22 @@ public class XxlJobLog { // alarm info private int alarmStatus; + public String getJobGroupName() { + return jobGroupName; + } + + public void setJobGroupName(String jobGroupName) { + this.jobGroupName = jobGroupName; + } + + public String getJobName() { + return jobName; + } + + public void setJobName(String jobName) { + this.jobName = jobName; + } + public long getId() { return id; } diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/dao/XxlJobGroupDao.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/dao/XxlJobGroupDao.java index b608d9fb..a5df0a14 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/dao/XxlJobGroupDao.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/dao/XxlJobGroupDao.java @@ -34,4 +34,11 @@ public int pageListCount(@Param("offset") int offset, @Param("appname") String appname, @Param("title") String title); + /** + * 批量查询 + * + * @param jobGroupIds + * @return + */ + List selectByIds(@Param("ids") List jobGroupIds); } diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/dao/XxlJobInfoDao.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/dao/XxlJobInfoDao.java index d640efff..721ea473 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/dao/XxlJobInfoDao.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/dao/XxlJobInfoDao.java @@ -1,6 +1,7 @@ package com.xxl.job.admin.dao; import com.xxl.job.admin.core.model.XxlJobInfo; +import com.xxl.job.core.handler.annotation.XxlJob; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -46,4 +47,5 @@ public int pageListCount(@Param("offset") int offset, public int scheduleUpdate(XxlJobInfo xxlJobInfo); + List selectByIds(@Param("ids") List jobIds); } diff --git a/xxl-job-admin/src/main/resources/i18n/message_zh_CN.properties b/xxl-job-admin/src/main/resources/i18n/message_zh_CN.properties index 00ca50e1..f6c74f83 100644 --- a/xxl-job-admin/src/main/resources/i18n/message_zh_CN.properties +++ b/xxl-job-admin/src/main/resources/i18n/message_zh_CN.properties @@ -169,6 +169,8 @@ joblog_field_triggerMsg=调度备注 joblog_field_handleTime=执行时间 joblog_field_handleCode=执行结果 joblog_field_handleMsg=执行备注 +joblog_field_jobgroup=执行器 +joblog_field_job=执行任务 joblog_field_executorAddress=执行器地址 joblog_clean=清理 joblog_clean_log=日志清理 diff --git a/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobGroupMapper.xml b/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobGroupMapper.xml index 87299f88..f51ba6ca 100644 --- a/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobGroupMapper.xml +++ b/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobGroupMapper.xml @@ -87,5 +87,17 @@ + + \ No newline at end of file diff --git a/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobInfoMapper.xml b/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobInfoMapper.xml index 7b3c3a3e..c95a524b 100644 --- a/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobInfoMapper.xml +++ b/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobInfoMapper.xml @@ -227,8 +227,20 @@ ORDER BY id ASC LIMIT #{pagesize} + + - + UPDATE xxl_job_info SET trigger_last_time = #{triggerLastTime}, diff --git a/xxl-job-admin/src/main/resources/static/js/joblog.index.1.js b/xxl-job-admin/src/main/resources/static/js/joblog.index.1.js index e0fc3f20..29b3c9f1 100644 --- a/xxl-job-admin/src/main/resources/static/js/joblog.index.1.js +++ b/xxl-job-admin/src/main/resources/static/js/joblog.index.1.js @@ -141,13 +141,12 @@ $(function() { return data?''+ I18n.system_show +''+ data +'':I18n.system_empty; } }, - { - "data": 'handleTime', - "width":'20%', - "render": function ( data, type, row ) { - return data?moment(data).format("YYYY-MM-DD HH:mm:ss"):""; - } - }, + { + "data": 'jobGroupName' + }, + { + "data": 'jobName' + }, { "data": 'handleCode', "width":'10%', @@ -165,13 +164,6 @@ $(function() { return html; } }, - { - "data": 'handleMsg', - "width":'10%', - "render": function ( data, type, row ) { - return data?''+ I18n.system_show +''+ data +'':I18n.system_empty; - } - }, { "data": 'handleMsg' , "bSortable": false, diff --git a/xxl-job-admin/src/main/resources/templates/joblog/joblog.index.ftl b/xxl-job-admin/src/main/resources/templates/joblog/joblog.index.ftl index a2e983de..a3949a44 100644 --- a/xxl-job-admin/src/main/resources/templates/joblog/joblog.index.ftl +++ b/xxl-job-admin/src/main/resources/templates/joblog/joblog.index.ftl @@ -94,9 +94,11 @@ ${I18n.joblog_field_triggerTime} ${I18n.joblog_field_triggerCode} ${I18n.joblog_field_triggerMsg} - ${I18n.joblog_field_handleTime} + ${I18n.joblog_field_jobgroup} + ${I18n.joblog_field_job} +<#-- ${I18n.joblog_field_handleTime}--> ${I18n.joblog_field_handleCode} - ${I18n.joblog_field_handleMsg} +<#-- ${I18n.joblog_field_handleMsg}--> ${I18n.system_opt}