...
|
...
|
@@ -60,17 +60,25 @@ public class GrassInteractiveDataSyncServiceImpl implements IGrassInteractiveDat |
|
|
@Autowired
|
|
|
private PublicUserCommentRepository publicUserCommentRepository;
|
|
|
|
|
|
@Autowired
|
|
|
private GrassCommentPraiseRepository grassCommentPraiseRepository;
|
|
|
|
|
|
public static final int DATA_BEGIN_TIME = 1551283200;
|
|
|
|
|
|
private static final int PRAISE = 1;
|
|
|
private static final int COMMENT = 2;
|
|
|
private static final int FAVORITE = 3;
|
|
|
private static final int ATTENTION = 4;
|
|
|
private static final int COMMENT_PRAISE = 5;
|
|
|
|
|
|
//根据article表的时间区间同步从表内对应 articleId的从表数据
|
|
|
private static final int MASTER = 1;
|
|
|
//根据各自从表数据的时间区间 同步时间区间内对应的从表内容
|
|
|
private static final int SLAVE = 2;
|
|
|
|
|
|
private static List<Integer> needSyncArticleType = new ArrayList<>();
|
|
|
public static List<Integer> needSyncArticleType = new ArrayList<>();
|
|
|
|
|
|
private static List<Integer> needSyncArticleStatus = new ArrayList<>();
|
|
|
public static List<Integer> needSyncArticleStatus = new ArrayList<>();
|
|
|
|
|
|
static {
|
|
|
needSyncArticleType.add(1);
|
...
|
...
|
@@ -85,7 +93,7 @@ public class GrassInteractiveDataSyncServiceImpl implements IGrassInteractiveDat |
|
|
|
|
|
@Override
|
|
|
public String syncInteractiveData(Integer startTime, Integer endTime, Integer timeType, Integer syncType) {
|
|
|
// syncType : 1、同步点赞 2、 同步评论 3、 同步收藏 4、 同步关注
|
|
|
// syncType : 1、同步点赞 2、 同步评论 3、 同步收藏 4、 同步关注 5、同步评论的点赞
|
|
|
switch (syncType){
|
|
|
case PRAISE:
|
|
|
syncPraise(startTime, endTime, timeType);
|
...
|
...
|
@@ -99,6 +107,9 @@ public class GrassInteractiveDataSyncServiceImpl implements IGrassInteractiveDat |
|
|
case COMMENT:
|
|
|
syncComments(startTime, endTime,timeType);
|
|
|
break;
|
|
|
case COMMENT_PRAISE:
|
|
|
syncCommentPraise(startTime, endTime);
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
|
...
|
...
|
@@ -139,6 +150,11 @@ public class GrassInteractiveDataSyncServiceImpl implements IGrassInteractiveDat |
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 同步用户点赞 (起始时间条件根据 文章表时间区间)
|
|
|
* @param startTime
|
|
|
* @param endTime
|
|
|
*/
|
|
|
private void syncPraiseByArticle(Integer startTime, Integer endTime){
|
|
|
logger.info("syncPraiseByArticle begin, startTime is {}, endTime is {}", startTime, endTime);
|
|
|
ExecutorService es = Executors.newSingleThreadExecutor();
|
...
|
...
|
@@ -167,23 +183,11 @@ public class GrassInteractiveDataSyncServiceImpl implements IGrassInteractiveDat |
|
|
startTime, endTime,needSyncArticleType,needSyncArticleStatus,pageReq);
|
|
|
|
|
|
List<Integer> grassArticleIds = grassArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList());
|
|
|
List<Integer> grassRelatedIds = grassArticleList.stream().filter(grassArticle -> grassArticle.getArticleType()==5)
|
|
|
.map(GrassArticle::getRelateId).collect(Collectors.toList());
|
|
|
//社区文章 relate_id 和article_id 对应关系
|
|
|
Map<Integer, Integer> grassRelatedIdAndIdMap = grassArticleList.stream().filter(grassArticle -> grassArticle.getArticleType()==5)
|
|
|
.collect(Collectors.toMap(GrassArticle::getRelateId, GrassArticle::getId));
|
|
|
List<PublicArticle> publicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(grassArticleIds, needSyncArticleType);
|
|
|
List<PublicArticle> publicArticleNowList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(grassRelatedIds, Lists.newArrayList(5));
|
|
|
Map<Integer, Integer> publicArticleIdAndGrassIdMap = new HashMap<>();
|
|
|
Map<Integer, Integer> nowArticleIdAndpublicArticleIdMap = new HashMap<>();
|
|
|
publicArticleList.forEach(publicArticle -> {
|
|
|
publicArticleIdAndGrassIdMap.put(publicArticle.getRelateId(), publicArticle.getId());
|
|
|
});
|
|
|
publicArticleNowList.forEach(publicArticle -> {
|
|
|
Integer grassArticleId = grassRelatedIdAndIdMap.get(publicArticle.getRelateId());
|
|
|
nowArticleIdAndpublicArticleIdMap.put(grassArticleId, publicArticle.getId());
|
|
|
});
|
|
|
List<GrassArticlePraise> grassArticlePraiseList = grassArticlePraiseRepository.findAllByArticleIdIn(grassArticleIds);
|
|
|
|
|
|
Map<Integer, Integer> publicArticleIdAndGrassIdMap = getGrassArticleIdAndPublicIdMap(grassArticleIds);
|
|
|
Map<Integer, Integer> nowArticleIdAndpublicArticleIdMap = getNowArticleIdAndPublicIdMap(grassArticleList);
|
|
|
|
|
|
List<GrassArticlePraise> grassArticlePraiseList = grassArticlePraiseRepository.findAllByArticleIdInAndCreateTimeAfter(grassArticleIds, DATA_BEGIN_TIME);
|
|
|
logger.info("syncPraiseByArticlePage find grassArticlePraise num is {}", grassArticlePraiseList.size());
|
|
|
List<PublicUserPraise> needSyncData = buildPublicUserPraise(publicArticleIdAndGrassIdMap, nowArticleIdAndpublicArticleIdMap,grassArticlePraiseList);
|
|
|
publicUserPraiseRepository.saveAll(needSyncData);
|
...
|
...
|
@@ -227,6 +231,11 @@ public class GrassInteractiveDataSyncServiceImpl implements IGrassInteractiveDat |
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 同步用户点赞 (起始时间条件根据 点赞表时间区间)
|
|
|
* @param startTime
|
|
|
* @param endTime
|
|
|
*/
|
|
|
private void syncPraiseBySelf(Integer startTime, Integer endTime){
|
|
|
logger.info("syncPraiseBySelf begin, startTime is {}, endTime is {}", startTime, endTime);
|
|
|
ExecutorService es = Executors.newSingleThreadExecutor();
|
...
|
...
|
@@ -255,18 +264,20 @@ public class GrassInteractiveDataSyncServiceImpl implements IGrassInteractiveDat |
|
|
List<Integer> grassArticleIds = grassArticlePraiseList.stream().map(GrassArticlePraise::getArticleId).collect(Collectors.toList());
|
|
|
List<GrassArticle> grassArticleList = grassArticleRepository.findAllByIdIn(grassArticleIds);
|
|
|
|
|
|
Map<Integer, Integer> nowArticleIdAndpublicArticleIdMap = getNowArticleIdAndPulicIdMap(grassArticleList);
|
|
|
Map<Integer, Integer> nowArticleIdAndpublicArticleIdMap = getNowArticleIdAndPublicIdMap(grassArticleList);
|
|
|
|
|
|
Map<Integer, Integer> publicArticleIdAndGrassIdMap = getGrassArticleIdAndPublicIdMap(grassArticleIds);
|
|
|
|
|
|
List<PublicArticle> publicUserPraiseList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(grassArticleIds, needSyncArticleType);
|
|
|
Map<Integer, Integer> publicArticleIdAndGrassIdMap = new HashMap<>();
|
|
|
publicUserPraiseList.forEach(publicArticle -> {
|
|
|
publicArticleIdAndGrassIdMap.put(publicArticle.getRelateId(), publicArticle.getId());
|
|
|
});
|
|
|
List<PublicUserPraise> needSyncData = buildPublicUserPraise(publicArticleIdAndGrassIdMap,nowArticleIdAndpublicArticleIdMap, grassArticlePraiseList);
|
|
|
publicUserPraiseRepository.saveAll(needSyncData);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 同步用户收藏 (起始时间条件根据 文章表时间区间)
|
|
|
* @param startTime
|
|
|
* @param endTime
|
|
|
*/
|
|
|
private void syncFavoriteByArticle(Integer startTime, Integer endTime){
|
|
|
logger.info("syncFavoriteByArticle begin, startTime is {}, endTime is {}", startTime, endTime);
|
|
|
ExecutorService es = Executors.newSingleThreadExecutor();
|
...
|
...
|
@@ -295,24 +306,12 @@ public class GrassInteractiveDataSyncServiceImpl implements IGrassInteractiveDat |
|
|
startTime, endTime,needSyncArticleType,needSyncArticleStatus,pageReq);
|
|
|
|
|
|
List<Integer> grassArticleIds = grassArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList());
|
|
|
List<Integer> grassRelatedIds = grassArticleList.stream().filter(grassArticle -> grassArticle.getArticleType()==5)
|
|
|
.map(GrassArticle::getRelateId).collect(Collectors.toList());
|
|
|
//社区文章 relate_id 和article_id 对应关系
|
|
|
Map<Integer, Integer> grassRelatedIdAndIdMap = grassArticleList.stream().filter(grassArticle -> grassArticle.getArticleType()==5)
|
|
|
.collect(Collectors.toMap(GrassArticle::getRelateId, GrassArticle::getId));
|
|
|
List<PublicArticle> publicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(grassArticleIds, needSyncArticleType);
|
|
|
List<PublicArticle> publicArticleNowList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(grassRelatedIds, Lists.newArrayList(5));
|
|
|
|
|
|
Map<Integer, Integer> publicArticleIdAndGrassIdMap = new HashMap<>();
|
|
|
publicArticleList.forEach(publicArticle -> {
|
|
|
publicArticleIdAndGrassIdMap.put(publicArticle.getRelateId(), publicArticle.getId());
|
|
|
});
|
|
|
Map<Integer, Integer> nowArticleIdAndpublicArticleIdMap = new HashMap<>();
|
|
|
publicArticleNowList.forEach(publicArticle -> {
|
|
|
Integer grassArticleId = grassRelatedIdAndIdMap.get(publicArticle.getRelateId());
|
|
|
nowArticleIdAndpublicArticleIdMap.put(grassArticleId, publicArticle.getId());
|
|
|
});
|
|
|
List<UserFavoriteArticle> userFavoriteArticleList = userFavoriteArticleRepository.findAllByArticleIdIn(grassArticleIds);
|
|
|
|
|
|
Map<Integer, Integer> publicArticleIdAndGrassIdMap = getGrassArticleIdAndPublicIdMap(grassArticleIds);
|
|
|
|
|
|
Map<Integer, Integer> nowArticleIdAndpublicArticleIdMap = getNowArticleIdAndPublicIdMap(grassArticleList);
|
|
|
|
|
|
List<UserFavoriteArticle> userFavoriteArticleList = userFavoriteArticleRepository.findAllByArticleIdInAndCreateTimeAfter(grassArticleIds, DATA_BEGIN_TIME);
|
|
|
logger.info("syncFavoriteByArticlePage find userFavoriteArticle num is {}", userFavoriteArticleList.size());
|
|
|
List<PublicUserFavorite> needSyncData = buildPublicUserFavorite(publicArticleIdAndGrassIdMap,nowArticleIdAndpublicArticleIdMap, userFavoriteArticleList);
|
|
|
publicUserFavoriteRepository.saveAll(needSyncData);
|
...
|
...
|
@@ -347,6 +346,11 @@ public class GrassInteractiveDataSyncServiceImpl implements IGrassInteractiveDat |
|
|
return resultList;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 同步用户收藏 (起始时间条件根据 收藏表时间区间)
|
|
|
* @param startTime
|
|
|
* @param endTime
|
|
|
*/
|
|
|
private void syncFavoriteBySelf(Integer startTime, Integer endTime){
|
|
|
logger.info("syncFavoriteBySelf begin, startTime is {}, endTime is {}", startTime, endTime);
|
|
|
ExecutorService es = Executors.newSingleThreadExecutor();
|
...
|
...
|
@@ -375,17 +379,20 @@ public class GrassInteractiveDataSyncServiceImpl implements IGrassInteractiveDat |
|
|
List<Integer> grassArticleIds = userFavoriteArticleList.stream().map(UserFavoriteArticle::getArticleId).collect(Collectors.toList());
|
|
|
|
|
|
List<GrassArticle> grassArticleList = grassArticleRepository.findAllByIdIn(grassArticleIds);
|
|
|
Map<Integer, Integer> nowArticleIdAndpublicArticleIdMap = getNowArticleIdAndPulicIdMap(grassArticleList);
|
|
|
Map<Integer, Integer> nowArticleIdAndpublicArticleIdMap = getNowArticleIdAndPublicIdMap(grassArticleList);
|
|
|
|
|
|
Map<Integer, Integer> publicArticleIdAndGrassIdMap = getGrassArticleIdAndPublicIdMap(grassArticleIds);
|
|
|
|
|
|
List<PublicArticle> publicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(grassArticleIds, needSyncArticleType);
|
|
|
Map<Integer, Integer> publicArticleIdAndGrassIdMap = new HashMap<>();
|
|
|
publicArticleList.forEach(publicArticle -> {
|
|
|
publicArticleIdAndGrassIdMap.put(publicArticle.getRelateId(), publicArticle.getId());
|
|
|
});
|
|
|
List<PublicUserFavorite> needSyncData = buildPublicUserFavorite(publicArticleIdAndGrassIdMap,nowArticleIdAndpublicArticleIdMap, userFavoriteArticleList);
|
|
|
publicUserFavoriteRepository.saveAll(needSyncData);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 同步用户关注
|
|
|
* @param startTime
|
|
|
* @param endTime
|
|
|
*/
|
|
|
private void syncUserAttention(Integer startTime, Integer endTime){
|
|
|
logger.info("syncUserAttention begin, startTime is {}, endTime is {}", startTime, endTime);
|
|
|
ExecutorService es = Executors.newSingleThreadExecutor();
|
...
|
...
|
@@ -408,8 +415,8 @@ public class GrassInteractiveDataSyncServiceImpl implements IGrassInteractiveDat |
|
|
|
|
|
private void syncUserAttentionPage(int startTime, int endTime, int indexPage, int pageSize){
|
|
|
Pageable pageReq = PageRequest.of(indexPage, pageSize);
|
|
|
List<GrassUserAttention> grassUserAttentionList = grassUserAttentionRepository.findAllByCreateTimeBetween(
|
|
|
startTime, endTime,pageReq);
|
|
|
List<GrassUserAttention> grassUserAttentionList = grassUserAttentionRepository.findAllByCreateTimeBetweenAndCreateTimeAfter(
|
|
|
startTime, endTime, DATA_BEGIN_TIME, pageReq);
|
|
|
|
|
|
List<PublicUserAttention> needSyncData = buildPublicUserAttention(grassUserAttentionList);
|
|
|
publicUserAttentionRepository.saveAll(needSyncData);
|
...
|
...
|
@@ -436,6 +443,7 @@ public class GrassInteractiveDataSyncServiceImpl implements IGrassInteractiveDat |
|
|
return resultList;
|
|
|
}
|
|
|
|
|
|
//种草用户关注status → 公共库用户关注status 转换
|
|
|
private int convertAttentionStatus(int grassAttentionStatus){
|
|
|
switch (grassAttentionStatus){
|
|
|
case UserAttentionConstant.GRASS_HAS_ATTENTION:
|
...
|
...
|
@@ -521,13 +529,9 @@ public class GrassInteractiveDataSyncServiceImpl implements IGrassInteractiveDat |
|
|
List<Integer> grassArticleIds = grassArticleCommentsList.stream().map(GrassArticleComment::getDestId).collect(Collectors.toList());
|
|
|
|
|
|
List<GrassArticle> grassArticleList = grassArticleRepository.findAllByIdIn(grassArticleIds);
|
|
|
Map<Integer, Integer> nowArticleIdAndpublicArticleIdMap = getNowArticleIdAndPulicIdMap(grassArticleList);
|
|
|
Map<Integer, Integer> nowArticleIdAndpublicArticleIdMap = getNowArticleIdAndPublicIdMap(grassArticleList);
|
|
|
|
|
|
List<PublicArticle> publicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(grassArticleIds, needSyncArticleType);
|
|
|
Map<Integer, Integer> publicArticleIdAndGrassIdMap = new HashMap<>();
|
|
|
publicArticleList.forEach(publicArticle -> {
|
|
|
publicArticleIdAndGrassIdMap.put(publicArticle.getRelateId(), publicArticle.getId());
|
|
|
});
|
|
|
Map<Integer, Integer> publicArticleIdAndGrassIdMap = getGrassArticleIdAndPublicIdMap(grassArticleIds);
|
|
|
|
|
|
//先把时间区间内所有的新产生的根评论同步
|
|
|
List<GrassArticleComment> grassRootArticleComments = grassArticleCommentsList.stream().filter(grassArticleComment -> grassArticleComment.getParentId() == null).collect(Collectors.toList());;
|
...
|
...
|
@@ -565,31 +569,17 @@ public class GrassInteractiveDataSyncServiceImpl implements IGrassInteractiveDat |
|
|
startTime, endTime,needSyncArticleType,needSyncArticleStatus,pageReq);
|
|
|
|
|
|
List<Integer> grassArticleIds = grassArticleList.stream().map(BaseEntity::getId).collect(Collectors.toList());
|
|
|
List<Integer> grassRelatedIds = grassArticleList.stream().filter(grassArticle -> grassArticle.getArticleType()==5)
|
|
|
.map(GrassArticle::getRelateId).collect(Collectors.toList());
|
|
|
//社区文章 relate_id 和article_id 对应关系
|
|
|
Map<Integer, Integer> grassRelatedIdAndIdMap = grassArticleList.stream().filter(grassArticle -> grassArticle.getArticleType()==5)
|
|
|
.collect(Collectors.toMap(GrassArticle::getRelateId, GrassArticle::getId));
|
|
|
|
|
|
List<PublicArticle> publicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(grassArticleIds, needSyncArticleType);
|
|
|
List<PublicArticle> publicArticleNowList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(grassRelatedIds, Lists.newArrayList(5));
|
|
|
Map<Integer, Integer> publicArticleIdAndGrassIdMap = new HashMap<>();
|
|
|
publicArticleList.forEach(publicArticle -> {
|
|
|
publicArticleIdAndGrassIdMap.put(publicArticle.getRelateId(), publicArticle.getId());
|
|
|
});
|
|
|
|
|
|
Map<Integer, Integer> nowArticleIdAndpublicArticleIdMap = new HashMap<>();
|
|
|
publicArticleNowList.forEach(publicArticle -> {
|
|
|
Integer grassArticleId = grassRelatedIdAndIdMap.get(publicArticle.getRelateId());
|
|
|
nowArticleIdAndpublicArticleIdMap.put(grassArticleId, publicArticle.getId());
|
|
|
});
|
|
|
Map<Integer, Integer> publicArticleIdAndGrassIdMap = getGrassArticleIdAndPublicIdMap(grassArticleIds);
|
|
|
|
|
|
Map<Integer, Integer> nowArticleIdAndpublicArticleIdMap = getNowArticleIdAndPublicIdMap(grassArticleList);
|
|
|
|
|
|
//先把所有根评论同步
|
|
|
List<PublicUserComment> roots = queryAndBuildRootComment(grassArticleIds, publicArticleIdAndGrassIdMap,nowArticleIdAndpublicArticleIdMap);
|
|
|
List<PublicUserComment> rootPublicComments = publicUserCommentRepository.saveAll(roots);
|
|
|
//审核未通过的不查
|
|
|
List<GrassArticleComment> childrenComments = grassArticleCommentRepository.findAllByDestIdInAndArticleTypeInAndStatusIsNotAndParentIdIsNotNull(grassArticleIds,
|
|
|
needSyncArticleType, 2);
|
|
|
List<GrassArticleComment> childrenComments = grassArticleCommentRepository.findAllByDestIdInAndArticleTypeInAndStatusIsNotAndParentIdIsNotNullAndCreateTimeAfter(grassArticleIds,
|
|
|
needSyncArticleType, 2, DATA_BEGIN_TIME);
|
|
|
Map<Integer, Integer> rootIdMap = new HashMap<>();
|
|
|
rootPublicComments.forEach(publicUserComment -> {
|
|
|
rootIdMap.put(publicUserComment.getRelateId(), publicUserComment.getId());
|
...
|
...
|
@@ -605,13 +595,14 @@ public class GrassInteractiveDataSyncServiceImpl implements IGrassInteractiveDat |
|
|
List<PublicUserComment> result;
|
|
|
|
|
|
//审核未通过的不查
|
|
|
List<GrassArticleComment> rootComments = grassArticleCommentRepository.findAllByDestIdInAndArticleTypeInAndStatusIsNotAndParentIdIsNull(grassArticleIds,
|
|
|
needSyncArticleType, 2);
|
|
|
List<GrassArticleComment> rootComments = grassArticleCommentRepository.findAllByDestIdInAndArticleTypeInAndStatusIsNotAndParentIdIsNullAndCreateTimeAfter(grassArticleIds,
|
|
|
needSyncArticleType, 2,DATA_BEGIN_TIME);
|
|
|
|
|
|
result = buildRootComments(publicArticleIdAndGrassIdMap, rootComments,nowArticleIdAndpublicArticleIdMap);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
|
|
|
private List<PublicUserComment> buildRootComments( Map<Integer, Integer> publicArticleIdAndGrassIdMap, List<GrassArticleComment> grassRootArticleComments,
|
|
|
Map<Integer, Integer> nowArticleIdAndpublicArticleIdMap){
|
|
|
List<PublicUserComment> result = Lists.newArrayList();
|
...
|
...
|
@@ -730,6 +721,7 @@ public class GrassInteractiveDataSyncServiceImpl implements IGrassInteractiveDat |
|
|
return syncPublicUserCommentList;
|
|
|
}
|
|
|
|
|
|
//种草评论内容 → 公共库评论内容转换
|
|
|
private String convertCommentContent(String text){
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
jsonObject.put("type","text");
|
...
|
...
|
@@ -737,6 +729,7 @@ public class GrassInteractiveDataSyncServiceImpl implements IGrassInteractiveDat |
|
|
return jsonObject.toString();
|
|
|
}
|
|
|
|
|
|
//种草评论status → 公共库评论status转换
|
|
|
private int convertCommentStatus(int grassCommentStatus){
|
|
|
switch (grassCommentStatus){
|
|
|
case UserCommentConstant.GRASS_NOT_AUDIT:
|
...
|
...
|
@@ -750,7 +743,13 @@ public class GrassInteractiveDataSyncServiceImpl implements IGrassInteractiveDat |
|
|
}
|
|
|
}
|
|
|
|
|
|
private Map<Integer, Integer> getNowArticleIdAndPulicIdMap(List<GrassArticle> grassArticleList){
|
|
|
/**
|
|
|
* 获取种草文章中社区同步过来的文章 在公共库的文章id
|
|
|
* 返回种草库中id 和公共库中id的对应关系map
|
|
|
* @param grassArticleList
|
|
|
* @return
|
|
|
*/
|
|
|
private Map<Integer, Integer> getNowArticleIdAndPublicIdMap(List<GrassArticle> grassArticleList){
|
|
|
Map<Integer, Integer> nowArticleIdAndpublicArticleIdMap = new HashMap<>();
|
|
|
List<Integer> grassRelatedIds = grassArticleList.stream().filter(grassArticle -> grassArticle.getArticleType()==5)
|
|
|
.map(GrassArticle::getRelateId).collect(Collectors.toList());
|
...
|
...
|
@@ -766,7 +765,83 @@ public class GrassInteractiveDataSyncServiceImpl implements IGrassInteractiveDat |
|
|
}
|
|
|
return nowArticleIdAndpublicArticleIdMap;
|
|
|
}
|
|
|
private Map<Integer, Integer> getGrassArticleIdAndPublicIdMap(List<Integer> grassArticleIds){
|
|
|
Map<Integer, Integer> grassArticleIdAndpublicArticleIdMap = new HashMap<>();
|
|
|
if(!CollectionUtils.isEmpty(grassArticleIds)){
|
|
|
List<PublicArticle> publicArticleList = publicArticleRepository.findAllByRelateIdInAndArticleTypeIn(grassArticleIds, Lists.newArrayList(1,2,4));
|
|
|
publicArticleList.forEach(publicArticle -> {
|
|
|
grassArticleIdAndpublicArticleIdMap.put(publicArticle.getRelateId(), publicArticle.getId());
|
|
|
});
|
|
|
}
|
|
|
return grassArticleIdAndpublicArticleIdMap;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 同步种草评论的点赞
|
|
|
* @param startTime
|
|
|
* @param endTime
|
|
|
*/
|
|
|
private void syncCommentPraise(Integer startTime, Integer endTime){
|
|
|
logger.info("syncCommentPraise begin, startTime is {}, endTime is {}", startTime, endTime);
|
|
|
ExecutorService es = Executors.newSingleThreadExecutor();
|
|
|
int pageSize = 100;
|
|
|
int total = grassCommentPraiseRepository.countByCreateTimeBetween(startTime, endTime);
|
|
|
logger.info("syncCommentPraise get commentPraise count is {}", total);
|
|
|
int totalPage = total % pageSize ==0 ? total / pageSize : (total / pageSize)+1;
|
|
|
try{
|
|
|
//每次查询100条,增加detail
|
|
|
for (int index=0; index < totalPage; index++) {
|
|
|
int indexPage = index;
|
|
|
es.execute(() -> {
|
|
|
syncCommentPraisePage(startTime, endTime, indexPage, pageSize);
|
|
|
});
|
|
|
}
|
|
|
}finally {
|
|
|
es.shutdown();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void syncCommentPraisePage(int startTime, int endTime, int indexPage, int pageSize){
|
|
|
Pageable pageReq = PageRequest.of(indexPage, pageSize);
|
|
|
List<GrassCommentPraise> grassCommentPraiseList = grassCommentPraiseRepository.findAllByCreateTimeBetween(
|
|
|
startTime, endTime,pageReq);
|
|
|
|
|
|
if(CollectionUtils.isEmpty(grassCommentPraiseList)){
|
|
|
logger.info("syncCommentPraisePage , grassCommentPraiseList is empty");
|
|
|
return;
|
|
|
}
|
|
|
List<Integer> grassCommentIds = grassCommentPraiseList.stream().map(GrassCommentPraise::getCommentId).collect(Collectors.toList());
|
|
|
List<PublicUserComment> publicUserComments = publicUserCommentRepository.findAllByRelateIdInAndSrcChannelIs(grassCommentIds, 1);
|
|
|
Map<Integer, Integer> relateIdMap = new HashMap<>();
|
|
|
publicUserComments.forEach(publicUserComment -> {
|
|
|
relateIdMap.put(publicUserComment.getRelateId(), publicUserComment.getId());
|
|
|
});
|
|
|
|
|
|
List<PublicUserPraise> needSyncData = buildPublicUserPraise(relateIdMap, grassCommentPraiseList);
|
|
|
publicUserPraiseRepository.saveAll(needSyncData);
|
|
|
}
|
|
|
|
|
|
private List<PublicUserPraise> buildPublicUserPraise(Map<Integer, Integer> relateIdMap, List<GrassCommentPraise> grassCommentPraiseList){
|
|
|
List<PublicUserPraise> result = Lists.newArrayList();
|
|
|
grassCommentPraiseList.forEach(grassCommentPraise -> {
|
|
|
Integer targrtId = relateIdMap.get(grassCommentPraise.getCommentId());
|
|
|
if(null == targrtId){
|
|
|
return;
|
|
|
}
|
|
|
PublicUserPraise publicUserPraise = new PublicUserPraise();
|
|
|
publicUserPraise.setUid(grassCommentPraise.getUid());
|
|
|
publicUserPraise.setPraiseType(2);
|
|
|
publicUserPraise.setStatus(convertPraiseStatus(grassCommentPraise.getStatus()));
|
|
|
publicUserPraise.setSrcChannel(1);
|
|
|
publicUserPraise.setTargetId(targrtId);
|
|
|
publicUserPraise.setCreateTime(convertIntTimeToLong(grassCommentPraise.getCreateTime()));
|
|
|
publicUserPraise.setUpdateTime(convertIntTimeToLong(grassCommentPraise.getUpdateTime()));
|
|
|
result.add(publicUserPraise);
|
|
|
});
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
private Long convertIntTimeToLong(Integer time){
|
|
|
return Long.valueOf(Optional.ofNullable(time).orElse(0)) * 1000;
|
...
|
...
|
|