Showing
2 changed files
with
8 additions
and
2 deletions
1 | package com.yoho.datasync.fullsync.controller; | 1 | package com.yoho.datasync.fullsync.controller; |
2 | 2 | ||
3 | import com.yoho.datasync.fullsync.service.YohoNowDataSynService; | 3 | import com.yoho.datasync.fullsync.service.YohoNowDataSynService; |
4 | +import org.slf4j.Logger; | ||
5 | +import org.slf4j.LoggerFactory; | ||
4 | import org.springframework.web.bind.annotation.RequestMapping; | 6 | import org.springframework.web.bind.annotation.RequestMapping; |
5 | import org.springframework.web.bind.annotation.RequestParam; | 7 | import org.springframework.web.bind.annotation.RequestParam; |
6 | import org.springframework.web.bind.annotation.RestController; | 8 | import org.springframework.web.bind.annotation.RestController; |
@@ -13,6 +15,8 @@ import javax.annotation.Resource; | @@ -13,6 +15,8 @@ import javax.annotation.Resource; | ||
13 | @RestController | 15 | @RestController |
14 | public class YohoNowDataSynController { | 16 | public class YohoNowDataSynController { |
15 | 17 | ||
18 | + private final Logger logger = LoggerFactory.getLogger(YohoNowDataSynController.class); | ||
19 | + | ||
16 | @Resource | 20 | @Resource |
17 | private YohoNowDataSynService yohoNowDataSynService; | 21 | private YohoNowDataSynService yohoNowDataSynService; |
18 | 22 | ||
@@ -24,6 +28,7 @@ public class YohoNowDataSynController { | @@ -24,6 +28,7 @@ public class YohoNowDataSynController { | ||
24 | 28 | ||
25 | @RequestMapping("/synYohoNow/article") | 29 | @RequestMapping("/synYohoNow/article") |
26 | public String synArticle(@RequestParam("begTime") long begTime,@RequestParam("endTime") long endTime){ | 30 | public String synArticle(@RequestParam("begTime") long begTime,@RequestParam("endTime") long endTime){ |
31 | + logger.info("synArticle: begTime is {}, endTime is {}", begTime, endTime); | ||
27 | return yohoNowDataSynService.synArticle(begTime,endTime); | 32 | return yohoNowDataSynService.synArticle(begTime,endTime); |
28 | } | 33 | } |
29 | 34 |
@@ -70,8 +70,9 @@ public class YohoNowDataSynService { | @@ -70,8 +70,9 @@ public class YohoNowDataSynService { | ||
70 | public final int size=50; | 70 | public final int size=50; |
71 | private Boolean isStop =false; | 71 | private Boolean isStop =false; |
72 | 72 | ||
73 | - public String synArticle(long begTime, long endTime) { | 73 | + public synchronized String synArticle(long begTime, long endTime) { |
74 | int total = postsRepository.selectTotal(begTime,endTime); | 74 | int total = postsRepository.selectTotal(begTime,endTime); |
75 | + logger.info("synArticle.total is {}", total); | ||
75 | for(int offset=0;offset<total;offset+=size){ | 76 | for(int offset=0;offset<total;offset+=size){ |
76 | List<Posts> postsList = postsRepository.selectByTime(begTime,endTime,offset,size); | 77 | List<Posts> postsList = postsRepository.selectByTime(begTime,endTime,offset,size); |
77 | if(postsList.isEmpty()){ | 78 | if(postsList.isEmpty()){ |
@@ -83,7 +84,7 @@ public class YohoNowDataSynService { | @@ -83,7 +84,7 @@ public class YohoNowDataSynService { | ||
83 | Map<Integer,List<PostsBlock>> postsBlockMap = BeanConvertUtils.listToListMap(postsBlocks,Integer.class,"postsId"); | 84 | Map<Integer,List<PostsBlock>> postsBlockMap = BeanConvertUtils.listToListMap(postsBlocks,Integer.class,"postsId"); |
84 | Map<Integer,PostsPraiseTotal> postsPraiseTotalMap = BeanConvertUtils.listToMap(praiseTotals,Integer.class,"postsId"); | 85 | Map<Integer,PostsPraiseTotal> postsPraiseTotalMap = BeanConvertUtils.listToMap(praiseTotals,Integer.class,"postsId"); |
85 | List<PublicArticle> pArticles = buildPublicArticles(postsList,postsBlockMap,postsPraiseTotalMap); | 86 | List<PublicArticle> pArticles = buildPublicArticles(postsList,postsBlockMap,postsPraiseTotalMap); |
86 | - logger.info("before synArticle.size is {}",pArticles.size()); | 87 | + logger.info("before synArticle.size is {}, offset is {}",pArticles.size(), offset); |
87 | publicArticleRepository.saveAll(pArticles); | 88 | publicArticleRepository.saveAll(pArticles); |
88 | publicArticleRepository.flush(); | 89 | publicArticleRepository.flush(); |
89 | //文章审核表同步 | 90 | //文章审核表同步 |
-
Please register or login to post a comment