在AutoDeleteLogTask类中
将
@Autowired
private ScheduleJobService scheduleJobService;
修改为
@Autowired
private ScheduleJobLogService scheduleJobLogService;
将
scheduleJobService.autoDeleteLog();
修改为
scheduleJobLogService.autoDeleteLog();
在ScheduleJobService类添加方法
/**
- 自动删除日志
*/
void autoDeleteLog();
在ScheduleJobServiceImpl类添加
/**
- 自动删除日志
*/
@Override
public void autoDeleteLog() {
String beforeDate = DateUtil.offsetDay(new Date(), -9).toString("yyyy-MM-dd");
UpdateWrapper wrapper = Wrappers.update();
wrapper.lt("create_time", beforeDate);
dao.delete(wrapper);
}
示例图如下:
订单任务表(带数据)sql:
-- Table structure for eb_schedule_job
DROP TABLE IF EXISTS eb_schedule_job
;
CREATE TABLE eb_schedule_job
(
job_id
int(11) NOT NULL AUTO_INCREMENT COMMENT '任务id',
bean_name
varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT 'spring bean名称',
method_name
varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '方法名',
params
varchar(2000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '参数',
cron_expression
varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT 'cron表达式',
status
tinyint(4) NULL DEFAULT NULL COMMENT '任务状态 0:正常 1:暂停',
remark
varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '备注',
is_delte
tinyint(1) UNSIGNED NULL DEFAULT 0 COMMENT '是否删除',
create_time
timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
PRIMARY KEY (job_id
) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 20 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '定时任务' ROW_FORMAT = Dynamic;
-- Records of eb_schedule_job
INSERT INTO eb_schedule_job
VALUES (1, 'BargainStopChangeTask', 'bargainStopChange', '', '0 0 0 */1 * ?', 0, '砍价活动结束状态变化', 0, '2021-12-01 10:55:06');
INSERT INTO eb_schedule_job
VALUES (2, 'BrokerageFrozenTask', 'brokerageFrozen', '', '0 0 */1 * * ?', 0, '佣金冻结期解冻处理', 0, '2021-12-01 10:55:06');
INSERT INTO eb_schedule_job
VALUES (3, 'CouponOverdueTask', 'couponOverdue', '', '0 */1 * * * ?', 0, '优惠券过期处理', 0, '2021-12-01 10:55:06');
INSERT INTO eb_schedule_job
VALUES (4, 'IntegralFrozenTask', 'integralFrozen', '', '0 */1 * * * ?', 0, '积分冻结期解冻处理', 0, '2021-12-01 10:55:06');
INSERT INTO eb_schedule_job
VALUES (5, 'OrderAutoCancelTask', 'autoCancel', '', '0 */1 * * * ?', 0, '系统自动取消未支付订单', 0, '2021-12-01 10:55:06');
INSERT INTO eb_schedule_job
VALUES (6, 'OrderAutoCompleteTask', 'autoComplete', '', '0 0 */1 * * ?', 0, '订单自动完成处理', 0, '2021-12-01 10:55:06');
INSERT INTO eb_schedule_job
VALUES (7, 'OrderCancelTask', 'userCancel', '', '0 */1 * * * ?', 0, '用户取消订单处理', 0, '2021-12-01 10:55:06');
INSERT INTO eb_schedule_job
VALUES (8, 'OrderCompleteTask', 'orderComplete', '', '0 */1 * * * ?', 0, '用户订单完成处理', 0, '2021-12-01 10:55:06');
INSERT INTO eb_schedule_job
VALUES (9, 'OrderPaySuccessTask', 'orderPayAfter', '', '0 */1 * * * ?', 0, '订单支付成功后置处理', 0, '2021-12-01 10:55:07');
INSERT INTO eb_schedule_job
VALUES (10, 'OrderReceiptTask', 'orderReceipt', '', '0 */1 * * * ?', 0, '用户确认收货后置处理', 0, '2021-12-01 10:55:07');
INSERT INTO eb_schedule_job
VALUES (11, 'OrderRefundTask', 'orderRefund', '', '0 */1 * * * ?', 0, '订单退款处理', 0, '2021-12-01 10:55:07');
INSERT INTO eb_schedule_job
VALUES (12, 'AutoUpdateCatTask', 'autoUpdateCat', '', '0 0 1 * * ?', 0, '自动更新自定义交易组件类目', 0, '2021-12-01 10:55:07');
INSERT INTO eb_schedule_job
VALUES (13, 'PinkStatusChangeTask', 'pinkStatusChage', '', '0 */1 * * * ?', 0, '拼团状态变化处理', 0, '2021-12-01 10:55:07');
INSERT INTO eb_schedule_job
VALUES (14, 'ProductStockTask', 'stockOperation', '', '0 */1 * * * ?', 0, '操作商品库存', 0, '2021-12-01 10:55:07');
INSERT INTO eb_schedule_job
VALUES (15, 'StatisticsTask', 'statistics', '', '0 0 0 */1 * ?', 0, '统计定时任务', 0, '2021-12-01 10:55:07');
INSERT INTO eb_schedule_job
VALUES (16, 'AsyncWeChatProgramTempMessage', 'init', '', '0 */1 * * * ?', 0, '小程序消费队列消费', 0, '2021-12-01 10:55:07');
INSERT INTO eb_schedule_job
VALUES (17, 'AsyncWeChatPublicTempMessage', 'init', '', '0 */1 * * * ?', 0, '公众号消费队列消费', 0, '2021-12-01 10:55:07');
INSERT INTO eb_schedule_job
VALUES (18, 'AutoDeleteLogTask', 'autoDeleteLog', '', '0 0 0 */1 * ?', 0, '自动删除不需要的历史日志', 0, '2022-01-05 15:03:18');
附件的后缀可改为.sql
{{item.user_info.nickname ? item.user_info.nickname : item.user_name}}
作者 管理员 企业
{{itemf.name}}
{{itemc.user_info.nickname}}
{{itemc.user_name}}
回复 {{itemc.comment_user_info.nickname}}
{{itemf.name}}