Authored by Zhao

rebuildjob添加历史价格的逻辑

1 -package com.yoho.search.consumer.job;  
2 -  
3 -import com.yoho.search.dal.ProductPriceHistoryMapper;  
4 -import org.springframework.beans.factory.annotation.Autowired;  
5 -import org.springframework.scheduling.annotation.Scheduled;  
6 -import org.springframework.stereotype.Component;  
7 -  
8 -@Component  
9 -public class HistoryPriceJob {  
10 - @Autowired  
11 - private ProductPriceHistoryMapper productPriceHistoryMapper;  
12 -  
13 - @Scheduled(cron = "0 30 2 * * ?")  
14 - public void updateHistoryPriceTask () {  
15 - productPriceHistoryMapper.backupHistoryPrice();  
16 - productPriceHistoryMapper.updateCurrentPrice();  
17 - }  
18 -}  
1 package com.yoho.search.consumer.job; 1 package com.yoho.search.consumer.job;
2 2
  3 +import com.yoho.search.consumer.service.base.ProductPriceService;
3 import org.slf4j.Logger; 4 import org.slf4j.Logger;
4 import org.slf4j.LoggerFactory; 5 import org.slf4j.LoggerFactory;
5 import org.springframework.beans.factory.annotation.Autowired; 6 import org.springframework.beans.factory.annotation.Autowired;
@@ -22,6 +23,8 @@ public class IndexRebuildJob implements ApplicationEventPublisherAware { @@ -22,6 +23,8 @@ public class IndexRebuildJob implements ApplicationEventPublisherAware {
22 private IYohoIndexService yohoIndexService; 23 private IYohoIndexService yohoIndexService;
23 @Autowired 24 @Autowired
24 private RebuildFlagService rebuildFlagService; 25 private RebuildFlagService rebuildFlagService;
  26 + @Autowired
  27 + private ProductPriceService productPriceService;
25 28
26 private static final Logger logger = LoggerFactory.getLogger(IndexRebuildJob.class); 29 private static final Logger logger = LoggerFactory.getLogger(IndexRebuildJob.class);
27 30
@@ -33,6 +36,11 @@ public class IndexRebuildJob implements ApplicationEventPublisherAware { @@ -33,6 +36,11 @@ public class IndexRebuildJob implements ApplicationEventPublisherAware {
33 } 36 }
34 37
35 @Scheduled(cron = "0 0 3 * * ?") 38 @Scheduled(cron = "0 0 3 * * ?")
  39 + public void rebuildIndexTask() {
  40 + productPriceService.batchUpdateHistoryPrice();
  41 + execute();
  42 + }
  43 +
36 public void execute() { 44 public void execute() {
37 long begin = System.currentTimeMillis(); 45 long begin = System.currentTimeMillis();
38 logger.info("indexRebuildJob execute start----[begin={}]", begin); 46 logger.info("indexRebuildJob execute start----[begin={}]", begin);
@@ -76,4 +76,10 @@ public class ProductPriceService { @@ -76,4 +76,10 @@ public class ProductPriceService {
76 public List<ProductPriceHistory> selectProductPriceHistorys(List<Integer> sknList) { 76 public List<ProductPriceHistory> selectProductPriceHistorys(List<Integer> sknList) {
77 return productPriceHistoryMapper.selectByPrimaryKeyList(sknList); 77 return productPriceHistoryMapper.selectByPrimaryKeyList(sknList);
78 } 78 }
  79 +
  80 + public void batchUpdateHistoryPrice () {
  81 + productPriceHistoryMapper.backupHistoryPrice();
  82 + productPriceHistoryMapper.updateCurrentPrice();
  83 + }
  84 +
79 } 85 }