Authored by 张帅

fix

@@ -15,6 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired; @@ -15,6 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired;
15 import org.springframework.data.domain.PageRequest; 15 import org.springframework.data.domain.PageRequest;
16 import org.springframework.data.domain.Pageable; 16 import org.springframework.data.domain.Pageable;
17 import org.springframework.stereotype.Service; 17 import org.springframework.stereotype.Service;
  18 +import org.springframework.util.CollectionUtils;
18 19
19 import java.util.*; 20 import java.util.*;
20 import java.util.stream.Collectors; 21 import java.util.stream.Collectors;
@@ -81,18 +82,24 @@ public class GrassArticleDataCheckServiceImpl implements IGrassArticleDataCheckS @@ -81,18 +82,24 @@ public class GrassArticleDataCheckServiceImpl implements IGrassArticleDataCheckS
81 e.printStackTrace(); 82 e.printStackTrace();
82 } 83 }
83 } 84 }
  85 + int publicCount = 0;
  86 + List<Integer> publicArticleIds = Lists.newArrayList();
  87 + if(!CollectionUtils.isEmpty(grassArticleIds)){
  88 + List<PublicArticle> publicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(grassArticleIds, needSyncArticleType);
  89 + publicArticleIds = publicArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList());
  90 + publicCount = publicArticleList.size();
  91 + }
84 92
85 - List<PublicArticle> publicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(grassArticleIds, needSyncArticleType);  
86 - List<Integer> publicArticleIds = publicArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList());  
87 - int publicCount = publicArticleList.size();  
88 logger.info("checkArticleData , get publicCount is {}", publicCount); 93 logger.info("checkArticleData , get publicCount is {}", publicCount);
89 94
90 JSONObject result = new JSONObject(); 95 JSONObject result = new JSONObject();
91 JSONArray data = new JSONArray(); 96 JSONArray data = new JSONArray();
92 data.add(checkArticle(total, publicCount)); 97 data.add(checkArticle(total, publicCount));
93 - data.add(checkArticleBlock(grassArticleIds, publicArticleIds));  
94 - data.add(checkArticleProduct(grassArticleIds, publicArticleIds));  
95 - data.add(checkArticleLabel(grassArticleIds, publicArticleIds)); 98 + if(!CollectionUtils.isEmpty(publicArticleIds)){
  99 + data.add(checkArticleBlock(grassArticleIds, publicArticleIds));
  100 + data.add(checkArticleProduct(grassArticleIds, publicArticleIds));
  101 + data.add(checkArticleLabel(grassArticleIds, publicArticleIds));
  102 + }
96 result.put("data",data); 103 result.put("data",data);
97 return result; 104 return result;
98 } 105 }
@@ -156,7 +156,10 @@ public class GrassInteractiveDataCheckServiceImpl implements IGrassInteractiveDa @@ -156,7 +156,10 @@ 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 - int public_count = publicUserPraiseRepository.countByTargetIdInAndPraiseTypeIsAndSrcChannelIs(publicArticleId, UserPraiseConstant.ARTICLE_PRAISE , 1); 159 + int public_count=0;
  160 + if(!CollectionUtils.isEmpty(publicArticleId)){
  161 + public_count = publicUserPraiseRepository.countByTargetIdInAndPraiseTypeIsAndSrcChannelIs(publicArticleId, UserPraiseConstant.ARTICLE_PRAISE , 1);
  162 + }
160 public_praise_count +=public_count; 163 public_praise_count +=public_count;
161 grass_praise_count +=grass_count; 164 grass_praise_count +=grass_count;
162 try { 165 try {
@@ -184,9 +187,15 @@ public class GrassInteractiveDataCheckServiceImpl implements IGrassInteractiveDa @@ -184,9 +187,15 @@ public class GrassInteractiveDataCheckServiceImpl implements IGrassInteractiveDa
184 logger.info("checkPraiseBySelf begin, startTime is {}, endTime is {}", startTime, endTime); 187 logger.info("checkPraiseBySelf begin, startTime is {}, endTime is {}", startTime, endTime);
185 Long startTimeLong = (long)startTime * 1000; 188 Long startTimeLong = (long)startTime * 1000;
186 Long endTimeLong = (long)endTime * 1000; 189 Long endTimeLong = (long)endTime * 1000;
  190 + JSONObject result = new JSONObject();
187 191
188 List<GrassArticlePraise> grassArticlePraiseList = grassArticlePraiseRepository.findAllByCreateTimeBetween( 192 List<GrassArticlePraise> grassArticlePraiseList = grassArticlePraiseRepository.findAllByCreateTimeBetween(
189 startTime, endTime); 193 startTime, endTime);
  194 + if(grassArticlePraiseList.isEmpty()){
  195 + result.put("grass_praise_count", grassArticlePraiseList.size());
  196 + result.put("public_praise_count", 0 );
  197 + return result;
  198 + }
190 List<Integer> grassArticleIds = grassArticlePraiseList.stream().map(GrassArticlePraise::getArticleId).collect(Collectors.toList()); 199 List<Integer> grassArticleIds = grassArticlePraiseList.stream().map(GrassArticlePraise::getArticleId).collect(Collectors.toList());
191 List<GrassArticle> grassArticleList = grassArticleRepository.findAllByIdIn(grassArticleIds); 200 List<GrassArticle> grassArticleList = grassArticleRepository.findAllByIdIn(grassArticleIds);
192 List<Integer> nowArticleIds = grassArticleList.stream().filter(grassArticle -> grassArticle.getArticleType()==5).map(GrassArticle::getRelateId).collect(Collectors.toList()); 201 List<Integer> nowArticleIds = grassArticleList.stream().filter(grassArticle -> grassArticle.getArticleType()==5).map(GrassArticle::getRelateId).collect(Collectors.toList());
@@ -197,8 +206,11 @@ public class GrassInteractiveDataCheckServiceImpl implements IGrassInteractiveDa @@ -197,8 +206,11 @@ public class GrassInteractiveDataCheckServiceImpl implements IGrassInteractiveDa
197 List<PublicArticle> nowPublicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(nowArticleIds, Lists.newArrayList(5)); 206 List<PublicArticle> nowPublicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(nowArticleIds, Lists.newArrayList(5));
198 publicArticleIds.addAll(nowPublicArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList())); 207 publicArticleIds.addAll(nowPublicArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList()));
199 } 208 }
200 - int public_count = publicUserPraiseRepository.countByTargetIdInAndPraiseTypeIsAndSrcChannelIsAndCreateTimeBetween(publicArticleIds, UserPraiseConstant.ARTICLE_PRAISE , 1,startTimeLong, endTimeLong);  
201 - JSONObject result = new JSONObject(); 209 + int public_count=0;
  210 + if(!CollectionUtils.isEmpty(publicArticleIds)){
  211 + public_count = publicUserPraiseRepository.countByTargetIdInAndPraiseTypeIsAndSrcChannelIsAndCreateTimeBetween(publicArticleIds, UserPraiseConstant.ARTICLE_PRAISE , 1,startTimeLong, endTimeLong);
  212 + }
  213 +
202 result.put("checkPraiseResult", grassArticlePraiseList.size() == public_count? CHECK_SUCCESS : CHECK_FAIL); 214 result.put("checkPraiseResult", grassArticlePraiseList.size() == public_count? CHECK_SUCCESS : CHECK_FAIL);
203 result.put("grass_praise_count", grassArticlePraiseList.size()); 215 result.put("grass_praise_count", grassArticlePraiseList.size());
204 result.put("public_praise_count", public_count ); 216 result.put("public_praise_count", public_count );
@@ -236,7 +248,10 @@ public class GrassInteractiveDataCheckServiceImpl implements IGrassInteractiveDa @@ -236,7 +248,10 @@ public class GrassInteractiveDataCheckServiceImpl implements IGrassInteractiveDa
236 List<PublicArticle> nowPublicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(nowArticleIds, Lists.newArrayList(5)); 248 List<PublicArticle> nowPublicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(nowArticleIds, Lists.newArrayList(5));
237 publicArticleId.addAll(nowPublicArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList())); 249 publicArticleId.addAll(nowPublicArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList()));
238 } 250 }
239 - int public_count = publicUserFavoriteRepository.countByTargetIdInAndFavoriteTypeIsAndSrcChannelIs(publicArticleId, 1 , 1); 251 + int public_count=0;
  252 + if(!CollectionUtils.isEmpty(publicArticleId)){
  253 + public_count = publicUserFavoriteRepository.countByTargetIdInAndFavoriteTypeIsAndSrcChannelIs(publicArticleId, 1 , 1);
  254 + }
240 grass_favorite_count += grass_count; 255 grass_favorite_count += grass_count;
241 public_favorite_count += public_count; 256 public_favorite_count += public_count;
242 try { 257 try {
@@ -265,9 +280,16 @@ public class GrassInteractiveDataCheckServiceImpl implements IGrassInteractiveDa @@ -265,9 +280,16 @@ public class GrassInteractiveDataCheckServiceImpl implements IGrassInteractiveDa
265 logger.info("checkFavoriteBySelf begin, startTime is {}, endTime is {}", startTime, endTime); 280 logger.info("checkFavoriteBySelf begin, startTime is {}, endTime is {}", startTime, endTime);
266 Long startTimeLong = (long)startTime * 1000; 281 Long startTimeLong = (long)startTime * 1000;
267 Long endTimeLong = (long)endTime * 1000; 282 Long endTimeLong = (long)endTime * 1000;
  283 + JSONObject result = new JSONObject();
268 284
269 List<UserFavoriteArticle> userFavoriteArticleList = userFavoriteArticleRepository.findAllByCreateTimeBetween( 285 List<UserFavoriteArticle> userFavoriteArticleList = userFavoriteArticleRepository.findAllByCreateTimeBetween(
270 startTime, endTime); 286 startTime, endTime);
  287 +
  288 + if(userFavoriteArticleList.isEmpty()){
  289 + result.put("grass_favorite_count", userFavoriteArticleList.size());
  290 + result.put("public_favorite_count", 0 );
  291 + return result;
  292 + }
271 List<Integer> grassArticleIds = userFavoriteArticleList.stream().map(UserFavoriteArticle::getArticleId).collect(Collectors.toList()); 293 List<Integer> grassArticleIds = userFavoriteArticleList.stream().map(UserFavoriteArticle::getArticleId).collect(Collectors.toList());
272 List<GrassArticle> grassArticleList = grassArticleRepository.findAllByIdIn(grassArticleIds); 294 List<GrassArticle> grassArticleList = grassArticleRepository.findAllByIdIn(grassArticleIds);
273 List<Integer> nowArticleIds = grassArticleList.stream().filter(grassArticle -> grassArticle.getArticleType()==5).map(GrassArticle::getRelateId).collect(Collectors.toList()); 295 List<Integer> nowArticleIds = grassArticleList.stream().filter(grassArticle -> grassArticle.getArticleType()==5).map(GrassArticle::getRelateId).collect(Collectors.toList());
@@ -278,8 +300,10 @@ public class GrassInteractiveDataCheckServiceImpl implements IGrassInteractiveDa @@ -278,8 +300,10 @@ public class GrassInteractiveDataCheckServiceImpl implements IGrassInteractiveDa
278 List<PublicArticle> nowPublicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(nowArticleIds, Lists.newArrayList(5)); 300 List<PublicArticle> nowPublicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(nowArticleIds, Lists.newArrayList(5));
279 publicArticleIds.addAll(nowPublicArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList())); 301 publicArticleIds.addAll(nowPublicArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList()));
280 } 302 }
281 - int public_count = publicUserFavoriteRepository.countByTargetIdInAndFavoriteTypeIsAndSrcChannelIsAndCreateTimeBetween(publicArticleIds, 1, 1,startTimeLong, endTimeLong);  
282 - JSONObject result = new JSONObject(); 303 + int public_count=0;
  304 + if(!CollectionUtils.isEmpty(publicArticleIds)){
  305 + public_count = publicUserFavoriteRepository.countByTargetIdInAndFavoriteTypeIsAndSrcChannelIsAndCreateTimeBetween(publicArticleIds, 1, 1,startTimeLong, endTimeLong);
  306 + }
283 result.put("checkFavoriteResult", userFavoriteArticleList.size() == public_count? CHECK_SUCCESS : CHECK_FAIL); 307 result.put("checkFavoriteResult", userFavoriteArticleList.size() == public_count? CHECK_SUCCESS : CHECK_FAIL);
284 result.put("grass_favorite_count", userFavoriteArticleList.size()); 308 result.put("grass_favorite_count", userFavoriteArticleList.size());
285 result.put("public_favorite_count", public_count ); 309 result.put("public_favorite_count", public_count );
@@ -298,12 +322,15 @@ public class GrassInteractiveDataCheckServiceImpl implements IGrassInteractiveDa @@ -298,12 +322,15 @@ public class GrassInteractiveDataCheckServiceImpl implements IGrassInteractiveDa
298 logger.info("syncUserAttention begin, startTime is {}, endTime is {}", startTime, endTime); 322 logger.info("syncUserAttention begin, startTime is {}, endTime is {}", startTime, endTime);
299 Long startTimeLong = (long)startTime * 1000; 323 Long startTimeLong = (long)startTime * 1000;
300 Long endTimeLong = (long)endTime * 1000; 324 Long endTimeLong = (long)endTime * 1000;
  325 + int public_count = 0;
301 List<GrassUserAttention> grassUserAttentionList = grassUserAttentionRepository.findAllByCreateTimeBetweenAndCreateTimeAfter( 326 List<GrassUserAttention> grassUserAttentionList = grassUserAttentionRepository.findAllByCreateTimeBetweenAndCreateTimeAfter(
302 startTime, endTime, DATA_BEGIN_TIME); 327 startTime, endTime, DATA_BEGIN_TIME);
303 - List<Integer> uids = grassUserAttentionList.stream().map(GrassUserAttention::getUid).collect(Collectors.toList());  
304 - List<Integer> followIds = grassUserAttentionList.stream().map(GrassUserAttention::getFollowUid).collect(Collectors.toList());  
305 - int public_count = publicUserAttentionRepository.countByTargetIdInAndUidInAndAttentionTypeIsAndSrcChannelIsAndCreateTimeBetween(followIds, uids, 1,1,startTimeLong, endTimeLong);  
306 - JSONObject result = new JSONObject(); 328 + if(!grassUserAttentionList.isEmpty()){
  329 + List<Integer> uids = grassUserAttentionList.stream().map(GrassUserAttention::getUid).collect(Collectors.toList());
  330 + List<Integer> followIds = grassUserAttentionList.stream().map(GrassUserAttention::getFollowUid).collect(Collectors.toList());
  331 + public_count = publicUserAttentionRepository.countByTargetIdInAndUidInAndAttentionTypeIsAndSrcChannelIsAndCreateTimeBetween(followIds, uids, 1,1,startTimeLong, endTimeLong);
  332 + }
  333 + JSONObject result = new JSONObject();
307 result.put("checkUserAttentionResult", grassUserAttentionList.size() == public_count? CHECK_SUCCESS : CHECK_FAIL); 334 result.put("checkUserAttentionResult", grassUserAttentionList.size() == public_count? CHECK_SUCCESS : CHECK_FAIL);
308 result.put("grass_userAttention_count", grassUserAttentionList.size()); 335 result.put("grass_userAttention_count", grassUserAttentionList.size());
309 result.put("public_userAttention_count", public_count ); 336 result.put("public_userAttention_count", public_count );
@@ -348,8 +375,10 @@ public class GrassInteractiveDataCheckServiceImpl implements IGrassInteractiveDa @@ -348,8 +375,10 @@ public class GrassInteractiveDataCheckServiceImpl implements IGrassInteractiveDa
348 List<PublicArticle> nowPublicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(nowArticleIds, Lists.newArrayList(5)); 375 List<PublicArticle> nowPublicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(nowArticleIds, Lists.newArrayList(5));
349 publicArticleId.addAll(nowPublicArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList())); 376 publicArticleId.addAll(nowPublicArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList()));
350 } 377 }
351 - int public_count = publicUserCommentRepository.countByArticleIdInAndSrcChannelIs(publicArticleId, 1);  
352 - 378 + int public_count = 0;
  379 + if(!CollectionUtils.isEmpty(publicArticleId)){
  380 + public_count = publicUserCommentRepository.countByArticleIdInAndSrcChannelIs(publicArticleId, 1);
  381 + }
353 grass_comment_count += grass_count; 382 grass_comment_count += grass_count;
354 public_comment_count += public_count; 383 public_comment_count += public_count;
355 try { 384 try {
@@ -372,9 +401,17 @@ public class GrassInteractiveDataCheckServiceImpl implements IGrassInteractiveDa @@ -372,9 +401,17 @@ public class GrassInteractiveDataCheckServiceImpl implements IGrassInteractiveDa
372 logger.info("checkCommentsBySelf begin, startTime is {}, endTime is {}", startTime, endTime); 401 logger.info("checkCommentsBySelf begin, startTime is {}, endTime is {}", startTime, endTime);
373 Long startTimeLong = (long)startTime * 1000; 402 Long startTimeLong = (long)startTime * 1000;
374 Long endTimeLong = (long)endTime * 1000; 403 Long endTimeLong = (long)endTime * 1000;
  404 + JSONObject result = new JSONObject();
375 405
376 List<GrassArticleComment> grassArticleComments = grassArticleCommentRepository.findAllByCreateTimeBetween( 406 List<GrassArticleComment> grassArticleComments = grassArticleCommentRepository.findAllByCreateTimeBetween(
377 startTime, endTime); 407 startTime, endTime);
  408 +
  409 + if(grassArticleComments.isEmpty()){
  410 + result.put("grass_comment_count", grassArticleComments.size());
  411 + result.put("public_comment_count", 0 );
  412 + return result;
  413 + }
  414 +
378 List<Integer> grassArticleIds = grassArticleComments.stream().map(GrassArticleComment::getDestId).collect(Collectors.toList()); 415 List<Integer> grassArticleIds = grassArticleComments.stream().map(GrassArticleComment::getDestId).collect(Collectors.toList());
379 List<GrassArticle> grassArticleList = grassArticleRepository.findAllByIdIn(grassArticleIds); 416 List<GrassArticle> grassArticleList = grassArticleRepository.findAllByIdIn(grassArticleIds);
380 List<Integer> nowArticleIds = grassArticleList.stream().filter(grassArticle -> grassArticle.getArticleType()==5).map(GrassArticle::getRelateId).collect(Collectors.toList()); 417 List<Integer> nowArticleIds = grassArticleList.stream().filter(grassArticle -> grassArticle.getArticleType()==5).map(GrassArticle::getRelateId).collect(Collectors.toList());
@@ -385,8 +422,11 @@ public class GrassInteractiveDataCheckServiceImpl implements IGrassInteractiveDa @@ -385,8 +422,11 @@ public class GrassInteractiveDataCheckServiceImpl implements IGrassInteractiveDa
385 List<PublicArticle> nowPublicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(nowArticleIds, Lists.newArrayList(5)); 422 List<PublicArticle> nowPublicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(nowArticleIds, Lists.newArrayList(5));
386 publicArticleIds.addAll(nowPublicArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList())); 423 publicArticleIds.addAll(nowPublicArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList()));
387 } 424 }
388 - int public_count = publicUserCommentRepository.countByArticleIdInAndSrcChannelIsAndCreateTimeBetween(publicArticleIds, 1,startTimeLong, endTimeLong);  
389 - JSONObject result = new JSONObject(); 425 +
  426 + int public_count = 0;
  427 + if(!CollectionUtils.isEmpty(publicArticleIds)){
  428 + public_count = publicUserCommentRepository.countByArticleIdInAndSrcChannelIsAndCreateTimeBetween(publicArticleIds, 1,startTimeLong, endTimeLong);
  429 + }
390 result.put("checkCommentResult", grassArticleComments.size() == public_count? CHECK_SUCCESS : CHECK_FAIL); 430 result.put("checkCommentResult", grassArticleComments.size() == public_count? CHECK_SUCCESS : CHECK_FAIL);
391 result.put("grass_comment_count", grassArticleComments.size()); 431 result.put("grass_comment_count", grassArticleComments.size());
392 result.put("public_comment_count", public_count ); 432 result.put("public_comment_count", public_count );
@@ -419,8 +459,11 @@ public class GrassInteractiveDataCheckServiceImpl implements IGrassInteractiveDa @@ -419,8 +459,11 @@ public class GrassInteractiveDataCheckServiceImpl implements IGrassInteractiveDa
419 grass_count ++; 459 grass_count ++;
420 } 460 }
421 } 461 }
  462 + int public_count = 0;
  463 + if(!CollectionUtils.isEmpty(publicCommentIds)){
  464 + public_count = publicUserPraiseRepository.countByTargetIdInAndPraiseTypeIsAndSrcChannelIsAndCreateTimeBetween(publicCommentIds, 2, 1,startTimeLong,endTimeLong);
422 465
423 - int public_count = publicUserPraiseRepository.countByTargetIdInAndPraiseTypeIsAndSrcChannelIsAndCreateTimeBetween(publicCommentIds, 2, 1,startTimeLong,endTimeLong); 466 + }
424 JSONObject result = new JSONObject(); 467 JSONObject result = new JSONObject();
425 result.put("checkCommentPraiseResult", grass_count == public_count? CHECK_SUCCESS : CHECK_FAIL); 468 result.put("checkCommentPraiseResult", grass_count == public_count? CHECK_SUCCESS : CHECK_FAIL);
426 result.put("grass_count", grass_count); 469 result.put("grass_count", grass_count);