Skip to content

Commit

Permalink
xxl-job-admin执行日志页新增显示执行器和执行job
Browse files Browse the repository at this point in the history
  • Loading branch information
kdyzm committed May 14, 2021
1 parent 6821d83 commit c936bd5
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -91,6 +91,7 @@ public Map<String, Object> 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

Expand All @@ -107,6 +108,32 @@ public Map<String, Object> pageList(HttpServletRequest request,

// page query
List<XxlJobLog> list = xxlJobLogDao.pageList(start, length, jobGroup, jobId, triggerTimeStart, triggerTimeEnd, logStatus);
List<Integer> jobGroupIds = list.stream().map(XxlJobLog::getJobGroup).collect(Collectors.toList());
List<Integer> jobIds = list.stream().map(XxlJobLog::getJobId).collect(Collectors.toList());
List<XxlJobGroup> jobGroups=xxlJobGroupDao.selectByIds(jobGroupIds);
List<XxlJobInfo> xxlJobs = xxlJobInfoDao.selectByIds(jobIds);
Map<Integer,XxlJobInfo> xxlJobInfoMap = new HashMap<>();
Map<Integer,XxlJobGroup> 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<Integer, XxlJobGroup> finalXxlJobGroupMap = xxlJobGroupMap;
Map<Integer, XxlJobInfo> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,11 @@ public int pageListCount(@Param("offset") int offset,
@Param("appname") String appname,
@Param("title") String title);

/**
* 批量查询
*
* @param jobGroupIds
* @return
*/
List<XxlJobGroup> selectByIds(@Param("ids") List<Integer> jobGroupIds);
}
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -46,4 +47,5 @@ public int pageListCount(@Param("offset") int offset,
public int scheduleUpdate(XxlJobInfo xxlJobInfo);


List<XxlJobInfo> selectByIds(@Param("ids") List<Integer> jobIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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=日志清理
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,17 @@
</if>
</trim>
</select>

<select id="selectByIds" resultType="com.xxl.job.admin.core.model.XxlJobGroup" resultMap="XxlJobGroup">
SELECT
<include refid="Base_Column_List" />
FROM xxl_job_group as t
WHERE t.id in
<trim prefix="(" suffix=")">
<foreach collection="ids" index="index" item="id" separator=",">
#{id}
</foreach>
</trim>
</select>

</mapper>
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,20 @@
ORDER BY id ASC
LIMIT #{pagesize}
</select>

<select id="selectByIds" resultType="com.xxl.job.admin.core.model.XxlJobInfo" resultMap="XxlJobInfo">
SELECT
<include refid="Base_Column_List" />
FROM xxl_job_info as t
WHERE t.id in
<trim prefix="(" suffix=")">
<foreach collection="ids" index="index" item="id" separator=",">
#{id}
</foreach>
</trim>
</select>

<update id="scheduleUpdate" parameterType="com.xxl.job.admin.core.model.XxlJobInfo" >
<update id="scheduleUpdate" parameterType="com.xxl.job.admin.core.model.XxlJobInfo" >
UPDATE xxl_job_info
SET
trigger_last_time = #{triggerLastTime},
Expand Down
20 changes: 6 additions & 14 deletions xxl-job-admin/src/main/resources/static/js/joblog.index.1.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,12 @@ $(function() {
return data?'<a class="logTips" href="javascript:;" >'+ I18n.system_show +'<span style="display:none;">'+ data +'</span></a>':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%',
Expand All @@ -165,13 +164,6 @@ $(function() {
return html;
}
},
{
"data": 'handleMsg',
"width":'10%',
"render": function ( data, type, row ) {
return data?'<a class="logTips" href="javascript:;" >'+ I18n.system_show +'<span style="display:none;">'+ data +'</span></a>':I18n.system_empty;
}
},
{
"data": 'handleMsg' ,
"bSortable": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,11 @@
<th name="triggerTime" >${I18n.joblog_field_triggerTime}</th>
<th name="triggerCode" >${I18n.joblog_field_triggerCode}</th>
<th name="triggerMsg" >${I18n.joblog_field_triggerMsg}</th>
<th name="handleTime" >${I18n.joblog_field_handleTime}</th>
<th name="jobGroupName" >${I18n.joblog_field_jobgroup}</th>
<th name="jobName" >${I18n.joblog_field_job}</th>
<#-- <th name="handleTime" >${I18n.joblog_field_handleTime}</th>-->
<th name="handleCode" >${I18n.joblog_field_handleCode}</th>
<th name="handleMsg" >${I18n.joblog_field_handleMsg}</th>
<#-- <th name="handleMsg" >${I18n.joblog_field_handleMsg}</th>-->
<th name="handleMsg" >${I18n.system_opt}</th>
</tr>
</thead>
Expand Down

0 comments on commit c936bd5

Please sign in to comment.