Commit 25c62520 by 吕明尚

增加定时任务日志

parent a059699f
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.SysJobLog;
import share.system.service.SysJobLogService;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* 定时任务日志Controller
*
* @author wuwenlong
* @date 2024-11-15
*/
@RestController
@RequestMapping("/system/sysJobLog")
public class SysJobLogController extends BaseController {
@Autowired
private SysJobLogService sysJobLogService;
/**
* 查询定时任务日志列表
*/
@PreAuthorize("@ss.hasPermi('system:sysJobLog:list')")
@GetMapping("/list")
public TableDataInfo list(SysJobLog sysJobLog) {
startPage();
List<SysJobLog> list = sysJobLogService.selectSysJobLogList(sysJobLog);
return getDataTable(list);
}
/**
* 导出定时任务日志列表
*/
@PreAuthorize("@ss.hasPermi('system:sysJobLog:export')")
@Log(title = "定时任务日志", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, SysJobLog sysJobLog) {
List<SysJobLog> list = sysJobLogService.selectSysJobLogList(sysJobLog);
ExcelUtil<SysJobLog> util = new ExcelUtil<SysJobLog>(SysJobLog.class);
util.exportExcel(response, list, "定时任务日志数据");
}
/**
* 获取定时任务日志详细信息
*/
@PreAuthorize("@ss.hasPermi('system:sysJobLog:query')")
@GetMapping(value = "/{jobLogId}")
public AjaxResult getInfo(@PathVariable("jobLogId") Long jobLogId) {
return success(sysJobLogService.selectSysJobLogByJobLogId(jobLogId));
}
/**
* 新增定时任务日志
*/
@PreAuthorize("@ss.hasPermi('system:sysJobLog:add')")
@Log(title = "定时任务日志", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody SysJobLog sysJobLog) {
return toAjax(sysJobLogService.insertSysJobLog(sysJobLog));
}
/**
* 修改定时任务日志
*/
@PreAuthorize("@ss.hasPermi('system:sysJobLog:edit')")
@Log(title = "定时任务日志", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody SysJobLog sysJobLog) {
return toAjax(sysJobLogService.updateSysJobLog(sysJobLog));
}
/**
* 删除定时任务日志
*/
@PreAuthorize("@ss.hasPermi('system:sysJobLog:remove')")
@Log(title = "定时任务日志", businessType = BusinessType.DELETE)
@DeleteMapping("/{jobLogIds}")
public AjaxResult remove(@PathVariable Long[] jobLogIds) {
return toAjax(sysJobLogService.deleteSysJobLogByJobLogIds(jobLogIds));
}
@DeleteMapping("/clean")
public AjaxResult clean() {
sysJobLogService.cleanJobLog();
return success();
}
}
......@@ -121,6 +121,9 @@ public class RedisTask {
@Autowired
private ConsumerSecondaryCardService consumerSecondaryCardService;
@Autowired
private SysJobLogService sysJobLogService;
//15分钟的常量
final long FIFTEEN_MINUTES = 60 * 15;
......@@ -377,7 +380,27 @@ public class RedisTask {
redisUtil.set(ReceiptRdeisEnum.ROOM_EXPIRE_TIME.getValue() + sOrder.getOrderNo(), json.toString());
logger.debug("订单号为:" + sOrder.getOrderNo() + "的订单已结束,更改订单状态为已使用");
}
SysJobLog sysJobLog = new SysJobLog();
sysJobLog.setJobName("AutoAddSCleanRecords:自动添加保洁记录");
sysJobLog.setJobGroup("RedisTask");
sysJobLog.setInvokeTarget("AutoAddSCleanRecords");
sysJobLog.setJobMessage("自动添加保洁记录:" + jsonObject.toString());
sysJobLog.setStatus(YesNoEnum.no.getIndex().toString());
sysJobLogService.save(sysJobLog);
} catch (BaseException e) {
String value = redisUtil.get(String.valueOf(o));
JSONObject jsonObject = new JSONObject(value);
logger.error("订单号:" + jsonObject.getStr("orderNo") + "异常,"
+ "异常为:" + e.getMessage()
);
SysJobLog sysJobLog = new SysJobLog();
sysJobLog.setJobName("AutoAddSCleanRecords:自动添加保洁记录");
sysJobLog.setJobGroup("RedisTask");
sysJobLog.setInvokeTarget("AutoAddSCleanRecords");
sysJobLog.setJobMessage("自动添加保洁记录:" + jsonObject.toString());
sysJobLog.setStatus(YesNoEnum.yes.getIndex().toString());
sysJobLog.setExceptionInfo(e.getMessage());
sysJobLogService.save(sysJobLog);
continue;
}
}
......
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;
/**
* 定时任务日志对象 sys_job_log
*
* @author wuwenlong
* @date 2024-11-15
*/
@Data
@TableName("sys_job_log")
public class SysJobLog 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("createTime", getCreateTime())
.toString();
}
}
package share.system.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import share.system.domain.SysJobLog;
import java.util.List;
/**
* 定时任务日志Mapper接口
*
* @author wuwenlong
* @date 2024-11-15
*/
public interface SysJobLogMapper extends BaseMapper<SysJobLog> {
/**
* 查询定时任务日志
*
* @param jobLogId 定时任务日志主键
* @return 定时任务日志
*/
public SysJobLog selectSysJobLogByJobLogId(Long jobLogId);
/**
* 查询定时任务日志列表
*
* @param sysJobLog 定时任务日志
* @return 定时任务日志集合
*/
public List<SysJobLog> selectSysJobLogList(SysJobLog sysJobLog);
/**
* 新增定时任务日志
*
* @param sysJobLog 定时任务日志
* @return 结果
*/
public int insertSysJobLog(SysJobLog sysJobLog);
/**
* 修改定时任务日志
*
* @param sysJobLog 定时任务日志
* @return 结果
*/
public int updateSysJobLog(SysJobLog sysJobLog);
/**
* 删除定时任务日志
*
* @param jobLogId 定时任务日志主键
* @return 结果
*/
public int deleteSysJobLogByJobLogId(Long jobLogId);
/**
* 批量删除定时任务日志
*
* @param jobLogIds 需要删除的数据主键集合
* @return 结果
*/
public int deleteSysJobLogByJobLogIds(Long[] jobLogIds);
void cleanJobLog();
}
package share.system.service;
import com.baomidou.mybatisplus.extension.service.IService;
import share.system.domain.SysJobLog;
import java.util.List;
/**
* 定时任务日志Service接口
*
* @author wuwenlong
* @date 2024-11-15
*/
public interface SysJobLogService extends IService<SysJobLog> {
/**
* 查询定时任务日志
*
* @param jobLogId 定时任务日志主键
* @return 定时任务日志
*/
public SysJobLog selectSysJobLogByJobLogId(Long jobLogId);
/**
* 查询定时任务日志列表
*
* @param sysJobLog 定时任务日志
* @return 定时任务日志集合
*/
public List<SysJobLog> selectSysJobLogList(SysJobLog sysJobLog);
/**
* 新增定时任务日志
*
* @param sysJobLog 定时任务日志
* @return 结果
*/
public int insertSysJobLog(SysJobLog sysJobLog);
/**
* 修改定时任务日志
*
* @param sysJobLog 定时任务日志
* @return 结果
*/
public int updateSysJobLog(SysJobLog sysJobLog);
/**
* 批量删除定时任务日志
*
* @param jobLogIds 需要删除的定时任务日志主键集合
* @return 结果
*/
public int deleteSysJobLogByJobLogIds(Long[] jobLogIds);
/**
* 删除定时任务日志信息
*
* @param jobLogId 定时任务日志主键
* @return 结果
*/
public int deleteSysJobLogByJobLogId(Long jobLogId);
public 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.SysJobLog;
import share.system.mapper.SysJobLogMapper;
import share.system.service.SysJobLogService;
import java.util.List;
/**
* 定时任务日志Service业务层处理
*
* @author wuwenlong
* @date 2024-11-15
*/
@Service
public class SysJobLogServiceImpl extends ServiceImpl<SysJobLogMapper, SysJobLog> implements SysJobLogService {
@Autowired
private SysJobLogMapper sysJobLogMapper;
/**
* 查询定时任务日志
*
* @param jobLogId 定时任务日志主键
* @return 定时任务日志
*/
@Override
public SysJobLog selectSysJobLogByJobLogId(Long jobLogId) {
return sysJobLogMapper.selectSysJobLogByJobLogId(jobLogId);
}
/**
* 查询定时任务日志列表
*
* @param sysJobLog 定时任务日志
* @return 定时任务日志
*/
@Override
public List<SysJobLog> selectSysJobLogList(SysJobLog sysJobLog) {
return sysJobLogMapper.selectSysJobLogList(sysJobLog);
}
/**
* 新增定时任务日志
*
* @param sysJobLog 定时任务日志
* @return 结果
*/
@Override
public int insertSysJobLog(SysJobLog sysJobLog) {
sysJobLog.setCreateTime(DateUtils.getNowDate());
return sysJobLogMapper.insertSysJobLog(sysJobLog);
}
/**
* 修改定时任务日志
*
* @param sysJobLog 定时任务日志
* @return 结果
*/
@Override
public int updateSysJobLog(SysJobLog sysJobLog) {
return sysJobLogMapper.updateSysJobLog(sysJobLog);
}
/**
* 批量删除定时任务日志
*
* @param jobLogIds 需要删除的定时任务日志主键
* @return 结果
*/
@Override
public int deleteSysJobLogByJobLogIds(Long[] jobLogIds) {
return sysJobLogMapper.deleteSysJobLogByJobLogIds(jobLogIds);
}
/**
* 删除定时任务日志信息
*
* @param jobLogId 定时任务日志主键
* @return 结果
*/
@Override
public int deleteSysJobLogByJobLogId(Long jobLogId) {
return sysJobLogMapper.deleteSysJobLogByJobLogId(jobLogId);
}
@Override
public void cleanJobLog() {
sysJobLogMapper.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.SysJobLogMapper">
<resultMap type="SysJobLog" id="SysJobLogResult">
<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="createTime" column="create_time"/>
</resultMap>
<sql id="selectSysJobLogVo">
select job_log_id,
job_name,
job_group,
invoke_target,
job_message,
status,
exception_info,
create_time
from sys_job_log
</sql>
<select id="selectSysJobLogList" parameterType="SysJobLog" resultMap="SysJobLogResult">
<include refid="selectSysJobLogVo"/>
<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="selectSysJobLogByJobLogId" parameterType="Long" resultMap="SysJobLogResult">
<include refid="selectSysJobLogVo"/>
where job_log_id = #{jobLogId}
</select>
<insert id="insertSysJobLog" parameterType="SysJobLog" useGeneratedKeys="true" keyProperty="jobLogId">
insert into sys_job_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="createTime != null">create_time,</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="createTime != null">#{createTime},</if>
</trim>
</insert>
<update id="updateSysJobLog" parameterType="SysJobLog">
update sys_job_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="createTime != null">create_time = #{createTime},</if>
</trim>
where job_log_id = #{jobLogId}
</update>
<delete id="deleteSysJobLogByJobLogId" parameterType="Long">
delete
from sys_job_log
where job_log_id = #{jobLogId}
</delete>
<delete id="deleteSysJobLogByJobLogIds" parameterType="String">
delete from sys_job_log where job_log_id in
<foreach item="jobLogId" collection="array" open="(" separator="," close=")">
#{jobLogId}
</foreach>
</delete>
<update id="cleanJobLog">
truncate table sys_job_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