CleanDataJob.java
5.89 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package com.yoho.search.consumer.job;
import java.util.Calendar;
import java.util.List;
import com.yoho.search.dal.*;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import com.yoho.search.base.utils.DateStyle;
import com.yoho.search.base.utils.DateUtil;
/**
* Created by wangnan on 2017/8/24.
*/
@Component
public class CleanDataJob {
private final Logger logger = LoggerFactory.getLogger(getClass());
private static final int CLEAN_BATCH_COUNT = 1000;
@Autowired
private ProductHeatValuesMapper productHeatValuesMapper;
@Autowired
private ProductModelValueMapper productModelValueMapper;
@Autowired
private SknFlowMapper sknFlowMapper;
@Autowired
private SknCtrValueMapper sknCtrValueMapper;
@Autowired
private ProductSalesInfoMapper productSalesInfoMapper;
@Autowired
private BrandVectorFeatureMapper brandVectorFeatureMapper;
@Autowired
private SimilarSknMapper similarSknMapper;
private String getLastThreeDayDate() {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DAY_OF_MONTH, -3);
calendar.set(Calendar.HOUR_OF_DAY, 0);
return DateUtil.DateToString(calendar.getTime(), DateStyle.YYYYMMDD);
}
@Scheduled(cron = "0 0 1 * * ?")
public void cleanProductModelValue() {
String generateDateStr = getLastThreeDayDate();
long begin = System.currentTimeMillis();
logger.info("productModelValue clean start----[begin={}]", begin);
List<Long> sknList = productModelValueMapper.selectSknByDate(generateDateStr, CLEAN_BATCH_COUNT);
while (CollectionUtils.isNotEmpty(sknList)) {
productModelValueMapper.deleteBatch(sknList, generateDateStr);
sknList = productModelValueMapper.selectSknByDate(generateDateStr, CLEAN_BATCH_COUNT);
}
logger.info("productModelValue clean end----[clearDate={}][cost={}]", generateDateStr, System.currentTimeMillis() - begin);
}
@Scheduled(cron = "0 5 1 * * ?")
public void cleanSknFlow() {
String generateDateStr = getLastThreeDayDate();
long begin = System.currentTimeMillis();
logger.info("sknFlow clean start----[begin={}]", begin);
List<Long> sknList = sknFlowMapper.selectSknByDate(generateDateStr, CLEAN_BATCH_COUNT);
while (CollectionUtils.isNotEmpty(sknList)) {
sknFlowMapper.deleteBatch(sknList, generateDateStr);
sknList = sknFlowMapper.selectSknByDate(generateDateStr, CLEAN_BATCH_COUNT);
}
logger.info("sknFlow clean end----[clearDate={}][cost={}]", generateDateStr, System.currentTimeMillis() - begin);
}
@Scheduled(cron = "0 10 1 * * ?")
public void cleanSknCtrValue() {
String generateDateStr = getLastThreeDayDate();
long begin = System.currentTimeMillis();
logger.info("sknCtrValue clean start----[begin={}]", begin);
List<Long> sknList = sknCtrValueMapper.selectSknByDate(generateDateStr, CLEAN_BATCH_COUNT);
while (CollectionUtils.isNotEmpty(sknList)) {
sknCtrValueMapper.deleteBatch(sknList, generateDateStr);
sknList = sknCtrValueMapper.selectSknByDate(generateDateStr, CLEAN_BATCH_COUNT);
}
logger.info("sknCtrValue clean end----[clearDate={}][cost={}]", generateDateStr, System.currentTimeMillis() - begin);
}
@Scheduled(cron = "0 15 1 * * ?")
public void cleanProductSalesInfo() {
String generateDateStr = getLastThreeDayDate();
long begin = System.currentTimeMillis();
logger.info("productSalesInfo clean start----[begin={}]", begin);
List<Long> sknList = productSalesInfoMapper.selectSknByDate(generateDateStr, CLEAN_BATCH_COUNT);
while (CollectionUtils.isNotEmpty(sknList)) {
productSalesInfoMapper.deleteBatch(sknList, generateDateStr);
sknList = productSalesInfoMapper.selectSknByDate(generateDateStr, CLEAN_BATCH_COUNT);
}
logger.info("productSalesInfo clean end----[clearDate={}][cost={}]", generateDateStr, System.currentTimeMillis() - begin);
}
@Scheduled(cron = "0 20 1 * * ?")
public void cleanProductHeatValues() {
String generateDateStr = getLastThreeDayDate();
long begin = System.currentTimeMillis();
logger.info("productHeatValues clean start----[begin={}]", begin);
List<Long> sknList = productHeatValuesMapper.selectSknByDate(generateDateStr, CLEAN_BATCH_COUNT);
while (CollectionUtils.isNotEmpty(sknList)) {
productHeatValuesMapper.deleteBatch(sknList, generateDateStr);
sknList = productHeatValuesMapper.selectSknByDate(generateDateStr, CLEAN_BATCH_COUNT);
}
logger.info("productHeatValues clean end----[clearDate={}][cost={}]", generateDateStr, System.currentTimeMillis() - begin);
}
@Scheduled(cron = "0 25 1 * * ?")
public void cleanBrandVectorFeature() {
String generateDateStr = getLastThreeDayDate();
long begin = System.currentTimeMillis();
logger.info("BrandVectorFeature clean start----[begin={}]", begin);
brandVectorFeatureMapper.deleteBatchByDateId(generateDateStr);
logger.info("BrandVectorFeature clean end----[clearDateStr={}][cost={}]", generateDateStr, System.currentTimeMillis() - begin);
}
@Scheduled(cron = "0 30 1 * * ?")
public void cleanSimilarSkn() {
String generateDateStr = getLastThreeDayDate();
long begin = System.currentTimeMillis();
logger.info("SimilarSkn clean start----[begin={}]", begin);
similarSknMapper.deleteBatchByDateId(Integer.valueOf(generateDateStr));
logger.info("SimilarSkn clean end----[clearDateStr={}][cost={}]", generateDateStr, System.currentTimeMillis() - begin);
}
}