package com.moral.task;
|
|
import javax.annotation.Resource;
|
|
import com.moral.service.HistoryService;
|
import com.moral.util.DateUtil;
|
import com.xxl.job.core.biz.model.ReturnT;
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.stereotype.Component;
|
|
import java.text.SimpleDateFormat;
|
import java.util.Date;
|
|
@Component
|
public class HistoryTableCreatAndDeleteTask {
|
private static transient Logger logger = LoggerFactory.getLogger(HistoryTableInsertTask.class);
|
@Resource
|
private HistoryService historyService;
|
|
@XxlJob("deleteHitoryTable")
|
public ReturnT deleteHistoryTable(String param) {
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
String yearMonthDay = sdf.format(DateUtil.rollHour(new Date(), -8*24));
|
try {
|
historyService.dropHistoryTable(yearMonthDay);
|
} catch (Exception e) {
|
logger.error(e.getMessage());
|
return new ReturnT(500, "history_" + yearMonthDay + "删除失败");
|
}
|
return new ReturnT(200, "history_" + yearMonthDay + "删除成功");
|
}
|
|
@XxlJob("createHistoryTable")
|
public ReturnT createHistoryTable(String param) {
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
String yearMonthDay = sdf.format(DateUtil.rollHour(new Date(), 24));
|
try {
|
historyService.createHistoryTable(yearMonthDay);
|
} catch (Exception e) {
|
logger.error(e.getMessage());
|
return new ReturnT(500, "history_" + yearMonthDay + "创建失败");
|
}
|
return new ReturnT(200, "history_" + yearMonthDay + "创建成功");
|
}
|
|
}
|