Authored by chaogeng

fix

package com.yoho.datasync.fullsync.controller;
import com.yoho.datasync.fullsync.service.YohoNowDataSynService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
... ... @@ -13,6 +15,8 @@ import javax.annotation.Resource;
@RestController
public class YohoNowDataSynController {
private final Logger logger = LoggerFactory.getLogger(YohoNowDataSynController.class);
@Resource
private YohoNowDataSynService yohoNowDataSynService;
... ... @@ -24,6 +28,7 @@ public class YohoNowDataSynController {
@RequestMapping("/synYohoNow/article")
public String synArticle(@RequestParam("begTime") long begTime,@RequestParam("endTime") long endTime){
logger.info("synArticle: begTime is {}, endTime is {}", begTime, endTime);
return yohoNowDataSynService.synArticle(begTime,endTime);
}
... ...
... ... @@ -70,8 +70,9 @@ public class YohoNowDataSynService {
public final int size=50;
private Boolean isStop =false;
public String synArticle(long begTime, long endTime) {
public synchronized String synArticle(long begTime, long endTime) {
int total = postsRepository.selectTotal(begTime,endTime);
logger.info("synArticle.total is {}", total);
for(int offset=0;offset<total;offset+=size){
List<Posts> postsList = postsRepository.selectByTime(begTime,endTime,offset,size);
if(postsList.isEmpty()){
... ... @@ -83,7 +84,7 @@ public class YohoNowDataSynService {
Map<Integer,List<PostsBlock>> postsBlockMap = BeanConvertUtils.listToListMap(postsBlocks,Integer.class,"postsId");
Map<Integer,PostsPraiseTotal> postsPraiseTotalMap = BeanConvertUtils.listToMap(praiseTotals,Integer.class,"postsId");
List<PublicArticle> pArticles = buildPublicArticles(postsList,postsBlockMap,postsPraiseTotalMap);
logger.info("before synArticle.size is {}",pArticles.size());
logger.info("before synArticle.size is {}, offset is {}",pArticles.size(), offset);
publicArticleRepository.saveAll(pArticles);
publicArticleRepository.flush();
//文章审核表同步
... ...