jinpengyong
2020-12-16 96d7cf8eb72810dfa5921a585d64b5ce9909d416
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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 + "创建成功");
    }
 
}