Commit 3581711c by 吕明尚

修改定时任务日志表

parent b22a0902
package share.web.controller.system;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import share.common.annotation.Log;
import share.common.core.controller.BaseController;
import share.common.core.domain.AjaxResult;
import share.common.core.page.TableDataInfo;
import share.common.enums.BusinessType;
import share.common.utils.poi.ExcelUtil;
import share.system.domain.JobErrorLog;
import share.system.service.JobErrorLogService;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* 定时任务异常日志Controller
*
* @author wuwenlong
* @date 2024-11-18
*/
@RestController
@RequestMapping("/system/jobErrorLog")
public class JobErrorLogController extends BaseController {
@Autowired
private JobErrorLogService jobErrorLogService;
/**
* 查询定时任务异常日志列表
*/
@PreAuthorize("@ss.hasPermi('system:jobErrorLog:list')")
@GetMapping("/list")
public TableDataInfo list(JobErrorLog jobErrorLog) {
startPage();
List<JobErrorLog> list = jobErrorLogService.selectJobErrorLogList(jobErrorLog);
return getDataTable(list);
}
/**
* 导出定时任务异常日志列表
*/
@PreAuthorize("@ss.hasPermi('system:jobErrorLog:export')")
@Log(title = "定时任务异常日志", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, JobErrorLog jobErrorLog) {
List<JobErrorLog> list = jobErrorLogService.selectJobErrorLogList(jobErrorLog);
ExcelUtil<JobErrorLog> util = new ExcelUtil<JobErrorLog>(JobErrorLog.class);
util.exportExcel(response, list, "定时任务异常日志数据");
}
/**
* 获取定时任务异常日志详细信息
*/
@PreAuthorize("@ss.hasPermi('system:jobErrorLog:query')")
@GetMapping(value = "/{jobLogId}")
public AjaxResult getInfo(@PathVariable("jobLogId") Long jobLogId) {
return success(jobErrorLogService.selectJobErrorLogByJobLogId(jobLogId));
}
/**
* 新增定时任务异常日志
*/
@PreAuthorize("@ss.hasPermi('system:jobErrorLog:add')")
@Log(title = "定时任务异常日志", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody JobErrorLog jobErrorLog) {
return toAjax(jobErrorLogService.insertJobErrorLog(jobErrorLog));
}
/**
* 修改定时任务异常日志
*/
@PreAuthorize("@ss.hasPermi('system:jobErrorLog:edit')")
@Log(title = "定时任务异常日志", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody JobErrorLog jobErrorLog) {
return toAjax(jobErrorLogService.updateJobErrorLog(jobErrorLog));
}
/**
* 删除定时任务异常日志
*/
@PreAuthorize("@ss.hasPermi('system:jobErrorLog:remove')")
@Log(title = "定时任务异常日志", businessType = BusinessType.DELETE)
@DeleteMapping("/{jobLogIds}")
public AjaxResult remove(@PathVariable Long[] jobLogIds) {
return toAjax(jobErrorLogService.deleteJobErrorLogByJobLogIds(jobLogIds));
}
@DeleteMapping("/clean")
public AjaxResult clean() {
jobErrorLogService.cleanJobLog();
return success();
}
}
...@@ -121,6 +121,9 @@ public class RedisTask { ...@@ -121,6 +121,9 @@ public class RedisTask {
@Autowired @Autowired
private ConsumerSecondaryCardService consumerSecondaryCardService; private ConsumerSecondaryCardService consumerSecondaryCardService;
@Autowired
private JobErrorLogService jobErrorLogService;
//15分钟的常量 //15分钟的常量
final long FIFTEEN_MINUTES = 60 * 15; final long FIFTEEN_MINUTES = 60 * 15;
...@@ -849,17 +852,30 @@ public class RedisTask { ...@@ -849,17 +852,30 @@ public class RedisTask {
logger.debug("AutomaticallySecondaryCard:自动结束次卡开始"); logger.debug("AutomaticallySecondaryCard:自动结束次卡开始");
Set<String> keys = redisTemplate.keys(ReceiptRdeisEnum.SECONDARY_CARD.getValue() + "*"); Set<String> keys = redisTemplate.keys(ReceiptRdeisEnum.SECONDARY_CARD.getValue() + "*");
if (keys.size() == 0) return; if (keys.size() == 0) return;
keys.stream().forEach(key -> { for (String key : keys) {
String value = redisUtil.get(String.valueOf(key)); try {
JSONObject jsonObject = new JSONObject(value); String value = redisUtil.get(String.valueOf(key));
Date expirationTime = jsonObject.getDate("expirationTime"); JSONObject jsonObject = new JSONObject(value);
Long consumerSecondaryCardId = jsonObject.getLong("consumerSecondaryCardId"); Date expirationTime = jsonObject.getDate("expirationTime");
if (expirationTime.getTime() < new Date().getTime()) { Long consumerSecondaryCardId = jsonObject.getLong("consumerSecondaryCardId");
consumerSecondaryCardService.removeById(consumerSecondaryCardId); if (expirationTime.getTime() < new Date().getTime()) {
redisUtil.delete(key); consumerSecondaryCardService.removeById(consumerSecondaryCardId);
redisUtil.delete(key);
}
} catch (Exception e) {
String value = redisUtil.get(String.valueOf(key));
JSONObject jsonObject = new JSONObject(value);
JobErrorLog jobErrorLog = new JobErrorLog();
jobErrorLog.setJobName("自动结束次卡");
jobErrorLog.setJobGroup("RedisTask");
jobErrorLog.setInvokeTarget("RedisTask.AutomaticallySecondaryCard");
jobErrorLog.setJobMessage("自动结束次卡:" + jsonObject.toString());
jobErrorLog.setStatus(YesNoEnum.yes.getIndex().toString());
jobErrorLog.setExceptionInfo(e.getMessage());
jobErrorLogService.save(jobErrorLog);
continue;
} }
}); }
logger.debug("AutomaticallySecondaryCard:自动结束次卡结束"); logger.debug("AutomaticallySecondaryCard:自动结束次卡结束");
} }
......
package share.system.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import share.common.annotation.Excel;
import share.common.core.domain.BaseEntity;
/**
* 定时任务异常日志对象 s_job_error_log
*
* @author wuwenlong
* @date 2024-11-18
*/
@Data
@TableName(value = "s_job_error_log")
public class JobErrorLog extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 任务日志ID
*/
@TableId(type = IdType.AUTO)
private Long jobLogId;
/**
* 任务名称
*/
@Excel(name = "任务名称")
private String jobName;
/**
* 任务组名
*/
@Excel(name = "任务组名")
private String jobGroup;
/**
* 调用目标字符串
*/
@Excel(name = "调用目标字符串")
private String invokeTarget;
/**
* 日志信息
*/
@Excel(name = "日志信息")
private String jobMessage;
/**
* 执行状态(0正常 1失败)
*/
@Excel(name = "执行状态", readConverterExp = "0=正常,1=失败")
private String status;
/**
* 异常信息
*/
@Excel(name = "异常信息")
private String exceptionInfo;
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("jobLogId", getJobLogId())
.append("jobName", getJobName())
.append("jobGroup", getJobGroup())
.append("invokeTarget", getInvokeTarget())
.append("jobMessage", getJobMessage())
.append("status", getStatus())
.append("exceptionInfo", getExceptionInfo())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.append("remark", getRemark())
.toString();
}
}
package share.system.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import share.system.domain.JobErrorLog;
import java.util.List;
/**
* 定时任务异常日志Mapper接口
*
* @author wuwenlong
* @date 2024-11-18
*/
public interface JobErrorLogMapper extends BaseMapper<JobErrorLog> {
/**
* 查询定时任务异常日志
*
* @param jobLogId 定时任务异常日志主键
* @return 定时任务异常日志
*/
public JobErrorLog selectJobErrorLogByJobLogId(Long jobLogId);
/**
* 查询定时任务异常日志列表
*
* @param jobErrorLog 定时任务异常日志
* @return 定时任务异常日志集合
*/
public List<JobErrorLog> selectJobErrorLogList(JobErrorLog jobErrorLog);
/**
* 新增定时任务异常日志
*
* @param jobErrorLog 定时任务异常日志
* @return 结果
*/
public int insertJobErrorLog(JobErrorLog jobErrorLog);
/**
* 修改定时任务异常日志
*
* @param jobErrorLog 定时任务异常日志
* @return 结果
*/
public int updateJobErrorLog(JobErrorLog jobErrorLog);
/**
* 删除定时任务异常日志
*
* @param jobLogId 定时任务异常日志主键
* @return 结果
*/
public int deleteJobErrorLogByJobLogId(Long jobLogId);
/**
* 批量删除定时任务异常日志
*
* @param jobLogIds 需要删除的数据主键集合
* @return 结果
*/
public int deleteJobErrorLogByJobLogIds(Long[] jobLogIds);
void cleanJobLog();
}
package share.system.service;
import com.baomidou.mybatisplus.extension.service.IService;
import share.system.domain.JobErrorLog;
import java.util.List;
/**
* 定时任务异常日志Service接口
*
* @author wuwenlong
* @date 2024-11-18
*/
public interface JobErrorLogService extends IService<JobErrorLog> {
/**
* 查询定时任务异常日志
*
* @param jobLogId 定时任务异常日志主键
* @return 定时任务异常日志
*/
public JobErrorLog selectJobErrorLogByJobLogId(Long jobLogId);
/**
* 查询定时任务异常日志列表
*
* @param jobErrorLog 定时任务异常日志
* @return 定时任务异常日志集合
*/
public List<JobErrorLog> selectJobErrorLogList(JobErrorLog jobErrorLog);
/**
* 新增定时任务异常日志
*
* @param jobErrorLog 定时任务异常日志
* @return 结果
*/
public int insertJobErrorLog(JobErrorLog jobErrorLog);
/**
* 修改定时任务异常日志
*
* @param jobErrorLog 定时任务异常日志
* @return 结果
*/
public int updateJobErrorLog(JobErrorLog jobErrorLog);
/**
* 批量删除定时任务异常日志
*
* @param jobLogIds 需要删除的定时任务异常日志主键集合
* @return 结果
*/
public int deleteJobErrorLogByJobLogIds(Long[] jobLogIds);
/**
* 删除定时任务异常日志信息
*
* @param jobLogId 定时任务异常日志主键
* @return 结果
*/
public int deleteJobErrorLogByJobLogId(Long jobLogId);
void cleanJobLog();
}
package share.system.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import share.common.utils.DateUtils;
import share.system.domain.JobErrorLog;
import share.system.mapper.JobErrorLogMapper;
import share.system.service.JobErrorLogService;
import java.util.List;
/**
* 定时任务异常日志Service业务层处理
*
* @author wuwenlong
* @date 2024-11-18
*/
@Service
public class JobErrorLogServiceImpl extends ServiceImpl<JobErrorLogMapper, JobErrorLog> implements JobErrorLogService {
@Autowired
private JobErrorLogMapper jobErrorLogMapper;
/**
* 查询定时任务异常日志
*
* @param jobLogId 定时任务异常日志主键
* @return 定时任务异常日志
*/
@Override
public JobErrorLog selectJobErrorLogByJobLogId(Long jobLogId) {
return jobErrorLogMapper.selectJobErrorLogByJobLogId(jobLogId);
}
/**
* 查询定时任务异常日志列表
*
* @param jobErrorLog 定时任务异常日志
* @return 定时任务异常日志
*/
@Override
public List<JobErrorLog> selectJobErrorLogList(JobErrorLog jobErrorLog) {
return jobErrorLogMapper.selectJobErrorLogList(jobErrorLog);
}
/**
* 新增定时任务异常日志
*
* @param jobErrorLog 定时任务异常日志
* @return 结果
*/
@Override
public int insertJobErrorLog(JobErrorLog jobErrorLog) {
jobErrorLog.setCreateTime(DateUtils.getNowDate());
return jobErrorLogMapper.insertJobErrorLog(jobErrorLog);
}
/**
* 修改定时任务异常日志
*
* @param jobErrorLog 定时任务异常日志
* @return 结果
*/
@Override
public int updateJobErrorLog(JobErrorLog jobErrorLog) {
jobErrorLog.setUpdateTime(DateUtils.getNowDate());
return jobErrorLogMapper.updateJobErrorLog(jobErrorLog);
}
/**
* 批量删除定时任务异常日志
*
* @param jobLogIds 需要删除的定时任务异常日志主键
* @return 结果
*/
@Override
public int deleteJobErrorLogByJobLogIds(Long[] jobLogIds) {
return jobErrorLogMapper.deleteJobErrorLogByJobLogIds(jobLogIds);
}
/**
* 删除定时任务异常日志信息
*
* @param jobLogId 定时任务异常日志主键
* @return 结果
*/
@Override
public int deleteJobErrorLogByJobLogId(Long jobLogId) {
return jobErrorLogMapper.deleteJobErrorLogByJobLogId(jobLogId);
}
@Override
public void cleanJobLog() {
jobErrorLogMapper.cleanJobLog();
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="share.system.mapper.JobErrorLogMapper">
<resultMap type="JobErrorLog" id="JobErrorLogResult">
<result property="jobLogId" column="job_log_id"/>
<result property="jobName" column="job_name"/>
<result property="jobGroup" column="job_group"/>
<result property="invokeTarget" column="invoke_target"/>
<result property="jobMessage" column="job_message"/>
<result property="status" column="status"/>
<result property="exceptionInfo" column="exception_info"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/>
<result property="remark" column="remark"/>
</resultMap>
<sql id="selectJobErrorLogVo">
select job_log_id,
job_name,
job_group,
invoke_target,
job_message,
status,
exception_info,
create_by,
create_time,
update_by,
update_time,
remark
from s_job_error_log
</sql>
<select id="selectJobErrorLogList" parameterType="JobErrorLog" resultMap="JobErrorLogResult">
<include refid="selectJobErrorLogVo"/>
<where>
<if test="jobName != null and jobName != ''">and job_name like concat('%', #{jobName}, '%')</if>
<if test="jobGroup != null and jobGroup != ''">and job_group = #{jobGroup}</if>
<if test="invokeTarget != null and invokeTarget != ''">and invoke_target = #{invokeTarget}</if>
<if test="jobMessage != null and jobMessage != ''">and job_message = #{jobMessage}</if>
<if test="status != null and status != ''">and status = #{status}</if>
<if test="exceptionInfo != null and exceptionInfo != ''">and exception_info = #{exceptionInfo}</if>
</where>
</select>
<select id="selectJobErrorLogByJobLogId" parameterType="Long" resultMap="JobErrorLogResult">
<include refid="selectJobErrorLogVo"/>
where job_log_id = #{jobLogId}
</select>
<insert id="insertJobErrorLog" parameterType="JobErrorLog" useGeneratedKeys="true" keyProperty="jobLogId">
insert into s_job_error_log
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="jobName != null and jobName != ''">job_name,</if>
<if test="jobGroup != null and jobGroup != ''">job_group,</if>
<if test="invokeTarget != null and invokeTarget != ''">invoke_target,</if>
<if test="jobMessage != null">job_message,</if>
<if test="status != null">status,</if>
<if test="exceptionInfo != null">exception_info,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
<if test="remark != null">remark,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="jobName != null and jobName != ''">#{jobName},</if>
<if test="jobGroup != null and jobGroup != ''">#{jobGroup},</if>
<if test="invokeTarget != null and invokeTarget != ''">#{invokeTarget},</if>
<if test="jobMessage != null">#{jobMessage},</if>
<if test="status != null">#{status},</if>
<if test="exceptionInfo != null">#{exceptionInfo},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="remark != null">#{remark},</if>
</trim>
</insert>
<update id="updateJobErrorLog" parameterType="JobErrorLog">
update s_job_error_log
<trim prefix="SET" suffixOverrides=",">
<if test="jobName != null and jobName != ''">job_name = #{jobName},</if>
<if test="jobGroup != null and jobGroup != ''">job_group = #{jobGroup},</if>
<if test="invokeTarget != null and invokeTarget != ''">invoke_target = #{invokeTarget},</if>
<if test="jobMessage != null">job_message = #{jobMessage},</if>
<if test="status != null">status = #{status},</if>
<if test="exceptionInfo != null">exception_info = #{exceptionInfo},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="remark != null">remark = #{remark},</if>
</trim>
where job_log_id = #{jobLogId}
</update>
<delete id="deleteJobErrorLogByJobLogId" parameterType="Long">
delete
from s_job_error_log
where job_log_id = #{jobLogId}
</delete>
<delete id="deleteJobErrorLogByJobLogIds" parameterType="String">
delete from s_job_error_log where job_log_id in
<foreach item="jobLogId" collection="array" open="(" separator="," close=")">
#{jobLogId}
</foreach>
</delete>
<update id="cleanJobLog">
truncate table s_job_error_log
</update>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment