...
|
...
|
@@ -3,6 +3,9 @@ package com.yoho.search.consumer.job; |
|
|
import com.yoho.search.base.utils.DateStyle;
|
|
|
import com.yoho.search.base.utils.DateUtil;
|
|
|
import com.yoho.search.dal.ProductHeatValuesMapper;
|
|
|
import com.yoho.search.dal.ProductModelValueMapper;
|
|
|
import com.yoho.search.dal.SknCtrValueMapper;
|
|
|
import com.yoho.search.dal.SknFlowMapper;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
...
|
...
|
@@ -14,35 +17,67 @@ import java.util.Calendar; |
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* Created by wangnan on 2017/4/10.
|
|
|
* Created by wangnan on 2017/8/24.
|
|
|
*/
|
|
|
@Component
|
|
|
public class ProductHeatValueJob {
|
|
|
private static final Logger logger = LoggerFactory.getLogger(ProductHeatValueJob.class);
|
|
|
|
|
|
@Autowired
|
|
|
private ProductHeatValuesMapper productHeatValuesMapper;
|
|
|
|
|
|
private static final int CLEAN_BATCH_COUNT = 1000;
|
|
|
|
|
|
/**
|
|
|
* 每天1点,删除三天前那天的数据
|
|
|
*/
|
|
|
@Scheduled(cron = "0 0 1 * * ?")
|
|
|
public void clean() {
|
|
|
long begin = System.currentTimeMillis();
|
|
|
logger.info("ProductHeatValuesJob.clean start----[begin={}]", begin);
|
|
|
// 默认取前三天
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
calendar.add(Calendar.DAY_OF_MONTH, -3);
|
|
|
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
String generateDateStr = DateUtil.DateToString(calendar.getTime(), DateStyle.YYYYMMDD);
|
|
|
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("ProductHeatValueJobs.clean end----[clearDateStr={}][cost={}]", generateDateStr, System.currentTimeMillis() - begin);
|
|
|
}
|
|
|
public class CleanDataJob {
|
|
|
private static final Logger logger = LoggerFactory.getLogger(CleanDataJob.class);
|
|
|
|
|
|
@Autowired
|
|
|
private ProductHeatValuesMapper productHeatValuesMapper;
|
|
|
@Autowired
|
|
|
private ProductModelValueMapper productModelValueMapper;
|
|
|
@Autowired
|
|
|
private SknFlowMapper sknFlowMapper;
|
|
|
@Autowired
|
|
|
private SknCtrValueMapper sknCtrValueMapper;
|
|
|
|
|
|
|
|
|
private static final int CLEAN_BATCH_COUNT = 1000;
|
|
|
|
|
|
/**
|
|
|
* 每天1点,删除三天前那天的数据
|
|
|
*/
|
|
|
@Scheduled(cron = "0 0 1 * * ?")
|
|
|
public void clean() {
|
|
|
// 默认取前三天
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
calendar.add(Calendar.DAY_OF_MONTH, -3);
|
|
|
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
String generateDateStr = DateUtil.DateToString(calendar.getTime(), DateStyle.YYYYMMDD);
|
|
|
//productHeatValues
|
|
|
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----[clearDateStr={}][cost={}]", generateDateStr, System.currentTimeMillis() - begin);
|
|
|
//productModelValue
|
|
|
begin = System.currentTimeMillis();
|
|
|
logger.info("productModelValue clean start----[begin={}]", begin);
|
|
|
while (CollectionUtils.isNotEmpty(sknList)) {
|
|
|
productModelValueMapper.deleteBatch(sknList,generateDateStr);
|
|
|
sknList = productModelValueMapper.selectSknByDate(generateDateStr, CLEAN_BATCH_COUNT);
|
|
|
}
|
|
|
logger.info("productModelValue clean end----[clearDateStr={}][cost={}]", generateDateStr, System.currentTimeMillis() - begin);
|
|
|
//sknFlow
|
|
|
begin = System.currentTimeMillis();
|
|
|
logger.info("sknFlow clean start----[begin={}]", begin);
|
|
|
while (CollectionUtils.isNotEmpty(sknList)) {
|
|
|
sknFlowMapper.deleteBatch(sknList,generateDateStr);
|
|
|
sknList = sknFlowMapper.selectSknByDate(generateDateStr, CLEAN_BATCH_COUNT);
|
|
|
}
|
|
|
logger.info("sknFlow clean end----[clearDateStr={}][cost={}]", generateDateStr, System.currentTimeMillis() - begin);
|
|
|
//sknCtrValue
|
|
|
begin = System.currentTimeMillis();
|
|
|
logger.info("sknCtrValue clean start----[begin={}]", begin);
|
|
|
while (CollectionUtils.isNotEmpty(sknList)) {
|
|
|
sknCtrValueMapper.deleteBatch(sknList,generateDateStr);
|
|
|
sknList = sknCtrValueMapper.selectSknByDate(generateDateStr, CLEAN_BATCH_COUNT);
|
|
|
}
|
|
|
logger.info("sknCtrValue clean end----[clearDateStr={}][cost={}]", generateDateStr, System.currentTimeMillis() - begin);
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|