Authored by 张帅

检查接口分页

@@ -12,6 +12,8 @@ import com.yoho.datasync.fullsync.service.IGrassArticleDataCheckService; @@ -12,6 +12,8 @@ import com.yoho.datasync.fullsync.service.IGrassArticleDataCheckService;
12 import org.slf4j.Logger; 12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory; 13 import org.slf4j.LoggerFactory;
14 import org.springframework.beans.factory.annotation.Autowired; 14 import org.springframework.beans.factory.annotation.Autowired;
  15 +import org.springframework.data.domain.PageRequest;
  16 +import org.springframework.data.domain.Pageable;
15 import org.springframework.stereotype.Service; 17 import org.springframework.stereotype.Service;
16 18
17 import java.util.*; 19 import java.util.*;
@@ -62,11 +64,23 @@ public class GrassArticleDataCheckServiceImpl implements IGrassArticleDataCheckS @@ -62,11 +64,23 @@ public class GrassArticleDataCheckServiceImpl implements IGrassArticleDataCheckS
62 64
63 @Override 65 @Override
64 public JSONObject checkArticleData(Long startTime, Long endTime) { 66 public JSONObject checkArticleData(Long startTime, Long endTime) {
65 - int grassArticleTotal = grassArticleRepository.countByCreateTimeAfterAndCreateTimeBeforeAndArticleTypeInAndAuthStatusIn(startTime, endTime,needSyncArticleType,needSyncArticleStatus);  
66 - logger.info("checkArticleData , get grassArticleTotal is {}", grassArticleTotal); 67 + int total = grassArticleRepository.countByCreateTimeAfterAndCreateTimeBeforeAndArticleTypeInAndAuthStatusIn(startTime, endTime, needSyncArticleType, needSyncArticleStatus);
  68 + int pageSize = 100;
  69 + int totalPage = total % pageSize ==0 ? total / pageSize : (total / pageSize)+1;
  70 + logger.info("checkArticleData , get grassArticleTotal is {}", total);
  71 + List<Integer> grassArticleIds = Lists.newArrayList();
  72 + for (int i = 0; i < totalPage; i++) {
  73 + Pageable pageReq = PageRequest.of(i, pageSize);
67 List<GrassArticle> grassArticleList = grassArticleRepository.findAllByCreateTimeAfterAndCreateTimeBeforeAndArticleTypeInAndAuthStatusIn( 74 List<GrassArticle> grassArticleList = grassArticleRepository.findAllByCreateTimeAfterAndCreateTimeBeforeAndArticleTypeInAndAuthStatusIn(
68 - startTime, endTime,needSyncArticleType,needSyncArticleStatus);  
69 - List<Integer> grassArticleIds = grassArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList()); 75 + startTime, endTime,needSyncArticleType,needSyncArticleStatus,pageReq);
  76 + List<Integer> grassArticleId = grassArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList());
  77 + grassArticleIds.addAll(grassArticleId);
  78 + try {
  79 + Thread.sleep(200);
  80 + } catch (InterruptedException e) {
  81 + e.printStackTrace();
  82 + }
  83 + }
70 84
71 List<PublicArticle> publicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(grassArticleIds, needSyncArticleType); 85 List<PublicArticle> publicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(grassArticleIds, needSyncArticleType);
72 List<Integer> publicArticleIds = publicArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList()); 86 List<Integer> publicArticleIds = publicArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList());
@@ -75,7 +89,7 @@ public class GrassArticleDataCheckServiceImpl implements IGrassArticleDataCheckS @@ -75,7 +89,7 @@ public class GrassArticleDataCheckServiceImpl implements IGrassArticleDataCheckS
75 89
76 JSONObject result = new JSONObject(); 90 JSONObject result = new JSONObject();
77 JSONArray data = new JSONArray(); 91 JSONArray data = new JSONArray();
78 - data.add(checkArticle(grassArticleTotal, publicCount)); 92 + data.add(checkArticle(total, publicCount));
79 data.add(checkArticleBlock(grassArticleIds, publicArticleIds)); 93 data.add(checkArticleBlock(grassArticleIds, publicArticleIds));
80 data.add(checkArticleProduct(grassArticleIds, publicArticleIds)); 94 data.add(checkArticleProduct(grassArticleIds, publicArticleIds));
81 data.add(checkArticleLabel(grassArticleIds, publicArticleIds)); 95 data.add(checkArticleLabel(grassArticleIds, publicArticleIds));
@@ -142,7 +142,7 @@ public class GrassInteractiveDataCheckServiceImpl implements IGrassInteractiveDa @@ -142,7 +142,7 @@ public class GrassInteractiveDataCheckServiceImpl implements IGrassInteractiveDa
142 int pageSize = 100; 142 int pageSize = 100;
143 int totalPage = total % pageSize ==0 ? total / pageSize : (total / pageSize)+1; 143 int totalPage = total % pageSize ==0 ? total / pageSize : (total / pageSize)+1;
144 int grass_praise_count=0; 144 int grass_praise_count=0;
145 - List<Integer> publicArticleIds = Lists.newArrayList(); 145 + int public_praise_count=0;
146 for (int i = 0; i < totalPage; i++) { 146 for (int i = 0; i < totalPage; i++) {
147 Pageable pageReq = PageRequest.of(i, pageSize); 147 Pageable pageReq = PageRequest.of(i, pageSize);
148 List<GrassArticle> grassArticleList = grassArticleRepository.findAllByCreateTimeAfterAndCreateTimeBeforeAndArticleTypeInAndAuthStatusIn( 148 List<GrassArticle> grassArticleList = grassArticleRepository.findAllByCreateTimeAfterAndCreateTimeBeforeAndArticleTypeInAndAuthStatusIn(
@@ -156,7 +156,8 @@ public class GrassInteractiveDataCheckServiceImpl implements IGrassInteractiveDa @@ -156,7 +156,8 @@ public class GrassInteractiveDataCheckServiceImpl implements IGrassInteractiveDa
156 List<PublicArticle> nowPublicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(nowArticleIds, Lists.newArrayList(5)); 156 List<PublicArticle> nowPublicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(nowArticleIds, Lists.newArrayList(5));
157 publicArticleId.addAll(nowPublicArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList())); 157 publicArticleId.addAll(nowPublicArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList()));
158 } 158 }
159 - publicArticleIds.addAll(publicArticleId); 159 + int public_count = publicUserPraiseRepository.countByTargetIdInAndPraiseTypeIsAndSrcChannelIs(publicArticleId, UserPraiseConstant.ARTICLE_PRAISE , 1);
  160 + public_praise_count +=public_count;
160 grass_praise_count +=grass_count; 161 grass_praise_count +=grass_count;
161 try { 162 try {
162 Thread.sleep(200); 163 Thread.sleep(200);
@@ -167,11 +168,10 @@ public class GrassInteractiveDataCheckServiceImpl implements IGrassInteractiveDa @@ -167,11 +168,10 @@ public class GrassInteractiveDataCheckServiceImpl implements IGrassInteractiveDa
167 168
168 169
169 170
170 - int public_count = publicUserPraiseRepository.countByTargetIdInAndPraiseTypeIsAndSrcChannelIs(publicArticleIds, UserPraiseConstant.ARTICLE_PRAISE , 1);  
171 JSONObject result = new JSONObject(); 171 JSONObject result = new JSONObject();
172 - result.put("checkPraiseResult", grass_praise_count == public_count? CHECK_SUCCESS : CHECK_FAIL); 172 + result.put("checkPraiseResult", grass_praise_count == public_praise_count? CHECK_SUCCESS : CHECK_FAIL);
173 result.put("grass_praise_count", grass_praise_count ); 173 result.put("grass_praise_count", grass_praise_count );
174 - result.put("public_praise_count", public_count ); 174 + result.put("public_praise_count", public_praise_count );
175 return result; 175 return result;
176 } 176 }
177 177
@@ -219,7 +219,7 @@ public class GrassInteractiveDataCheckServiceImpl implements IGrassInteractiveDa @@ -219,7 +219,7 @@ public class GrassInteractiveDataCheckServiceImpl implements IGrassInteractiveDa
219 int pageSize = 100; 219 int pageSize = 100;
220 int totalPage = total % pageSize ==0 ? total / pageSize : (total / pageSize)+1; 220 int totalPage = total % pageSize ==0 ? total / pageSize : (total / pageSize)+1;
221 int grass_favorite_count = 0; 221 int grass_favorite_count = 0;
222 - List<Integer> publicArticleIds = Lists.newArrayList(); 222 + int public_favorite_count = 0;
223 223
224 for (int i = 0; i < totalPage; i++) { 224 for (int i = 0; i < totalPage; i++) {
225 Pageable pageReq = PageRequest.of(i, pageSize); 225 Pageable pageReq = PageRequest.of(i, pageSize);
@@ -236,16 +236,21 @@ public class GrassInteractiveDataCheckServiceImpl implements IGrassInteractiveDa @@ -236,16 +236,21 @@ public class GrassInteractiveDataCheckServiceImpl implements IGrassInteractiveDa
236 List<PublicArticle> nowPublicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(nowArticleIds, Lists.newArrayList(5)); 236 List<PublicArticle> nowPublicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(nowArticleIds, Lists.newArrayList(5));
237 publicArticleId.addAll(nowPublicArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList())); 237 publicArticleId.addAll(nowPublicArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList()));
238 } 238 }
239 - publicArticleIds.addAll(publicArticleId); 239 + int public_count = publicUserFavoriteRepository.countByTargetIdInAndFavoriteTypeIsAndSrcChannelIs(publicArticleId, 1 , 1);
240 grass_favorite_count += grass_count; 240 grass_favorite_count += grass_count;
  241 + public_favorite_count += public_count;
  242 + try {
  243 + Thread.sleep(200);
  244 + } catch (InterruptedException e) {
  245 + e.printStackTrace();
  246 + }
241 } 247 }
242 248
243 249
244 - int public_count = publicUserFavoriteRepository.countByTargetIdInAndFavoriteTypeIsAndSrcChannelIs(publicArticleIds, 1 , 1);  
245 JSONObject result = new JSONObject(); 250 JSONObject result = new JSONObject();
246 - result.put("checkFavoriteResult", grass_favorite_count == public_count? CHECK_SUCCESS : CHECK_FAIL); 251 + result.put("checkFavoriteResult", grass_favorite_count == public_favorite_count? CHECK_SUCCESS : CHECK_FAIL);
247 result.put("grass_favorite_count", grass_favorite_count ); 252 result.put("grass_favorite_count", grass_favorite_count );
248 - result.put("public_favorite_count", public_count ); 253 + result.put("public_favorite_count", public_favorite_count );
249 return result; 254 return result;
250 } 255 }
251 256
@@ -324,7 +329,7 @@ public class GrassInteractiveDataCheckServiceImpl implements IGrassInteractiveDa @@ -324,7 +329,7 @@ public class GrassInteractiveDataCheckServiceImpl implements IGrassInteractiveDa
324 int total = grassArticleRepository.countByCreateTimeAfterAndCreateTimeBeforeAndArticleTypeInAndAuthStatusIn(startTimeLong, endTimeLong,needSyncArticleType,needSyncArticleStatus); 329 int total = grassArticleRepository.countByCreateTimeAfterAndCreateTimeBeforeAndArticleTypeInAndAuthStatusIn(startTimeLong, endTimeLong,needSyncArticleType,needSyncArticleStatus);
325 int totalPage = total % pageSize ==0 ? total / pageSize : (total / pageSize)+1; 330 int totalPage = total % pageSize ==0 ? total / pageSize : (total / pageSize)+1;
326 int grass_comment_count = 0; 331 int grass_comment_count = 0;
327 - List<Integer> publicArticleIds = Lists.newArrayList(); 332 + int public_comment_count = 0;
328 333
329 for (int i = 0; i < totalPage; i++) { 334 for (int i = 0; i < totalPage; i++) {
330 Pageable pageReq = PageRequest.of(i, pageSize); 335 Pageable pageReq = PageRequest.of(i, pageSize);
@@ -343,16 +348,22 @@ public class GrassInteractiveDataCheckServiceImpl implements IGrassInteractiveDa @@ -343,16 +348,22 @@ public class GrassInteractiveDataCheckServiceImpl implements IGrassInteractiveDa
343 List<PublicArticle> nowPublicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(nowArticleIds, Lists.newArrayList(5)); 348 List<PublicArticle> nowPublicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(nowArticleIds, Lists.newArrayList(5));
344 publicArticleId.addAll(nowPublicArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList())); 349 publicArticleId.addAll(nowPublicArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList()));
345 } 350 }
346 - publicArticleIds.addAll(publicArticleId); 351 + int public_count = publicUserCommentRepository.countByArticleIdInAndSrcChannelIs(publicArticleId, 1);
  352 +
347 grass_comment_count += grass_count; 353 grass_comment_count += grass_count;
  354 + public_comment_count += public_count;
  355 + try {
  356 + Thread.sleep(200);
  357 + } catch (InterruptedException e) {
  358 + e.printStackTrace();
  359 + }
348 } 360 }
349 361
350 - int public_count = publicUserCommentRepository.countByArticleIdInAndSrcChannelIs(publicArticleIds, 1);  
351 362
352 JSONObject result = new JSONObject(); 363 JSONObject result = new JSONObject();
353 - result.put("checkCommentResult", grass_comment_count == public_count? CHECK_SUCCESS : CHECK_FAIL); 364 + result.put("checkCommentResult", grass_comment_count == public_comment_count? CHECK_SUCCESS : CHECK_FAIL);
354 result.put("grass_comment_count", grass_comment_count); 365 result.put("grass_comment_count", grass_comment_count);
355 - result.put("public_comment_count", public_count ); 366 + result.put("public_comment_count", public_comment_count );
356 return result; 367 return result;
357 } 368 }
358 369