...
|
...
|
@@ -4,26 +4,20 @@ import com.alibaba.fastjson.JSONObject; |
|
|
import com.yoho.datasync.fullsync.comm.BeanConvertUtils;
|
|
|
import com.yoho.datasync.fullsync.comm.ImagesConstant;
|
|
|
import com.yoho.datasync.fullsync.comm.ImagesHelper;
|
|
|
import com.yoho.datasync.fullsync.dal.repository.pcms.IPublicArticleAuditRepository;
|
|
|
import com.yoho.datasync.fullsync.dal.repository.pcms.IPublicArticleBlockRepository;
|
|
|
import com.yoho.datasync.fullsync.dal.repository.pcms.IPublicArticleRepository;
|
|
|
import com.yoho.datasync.fullsync.dal.repository.pcms.model.PublicArticle;
|
|
|
import com.yoho.datasync.fullsync.dal.repository.pcms.model.PublicArticleBlock;
|
|
|
import com.yoho.datasync.fullsync.dal.repository.yhsocial.IPostsBlockRepository;
|
|
|
import com.yoho.datasync.fullsync.dal.repository.yhsocial.IPostsPraiseRepository;
|
|
|
import com.yoho.datasync.fullsync.dal.repository.yhsocial.IPostsRepository;
|
|
|
import com.yoho.datasync.fullsync.dal.repository.yhsocial.model.Posts;
|
|
|
import com.yoho.datasync.fullsync.dal.repository.yhsocial.model.PostsBlock;
|
|
|
import com.yoho.datasync.fullsync.dal.repository.yhsocial.model.PostsPraiseTotal;
|
|
|
import com.yoho.datasync.fullsync.dal.repository.pcms.*;
|
|
|
import com.yoho.datasync.fullsync.dal.repository.pcms.model.*;
|
|
|
import com.yoho.datasync.fullsync.dal.repository.yhcms.ITblAttentionUserRepository;
|
|
|
import com.yoho.datasync.fullsync.dal.repository.yhcms.ITblCommentInfoRepository;
|
|
|
import com.yoho.datasync.fullsync.dal.repository.yhcms.model.TblAttentionUser;
|
|
|
import com.yoho.datasync.fullsync.dal.repository.yhcms.model.TblCommentInfo;
|
|
|
import com.yoho.datasync.fullsync.dal.repository.yhsocial.*;
|
|
|
import com.yoho.datasync.fullsync.dal.repository.yhsocial.model.*;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
...
|
...
|
@@ -41,11 +35,32 @@ public class YohoNowDataSynService { |
|
|
@Resource
|
|
|
private IPublicArticleRepository publicArticleRepository;
|
|
|
@Resource
|
|
|
private IPublicArticleLabelRepository publicArticleLabelRepository;
|
|
|
@Resource
|
|
|
private IPostsRepository postsRepository;
|
|
|
@Resource
|
|
|
private IPostsBlockRepository postsBlockRepository;
|
|
|
@Resource
|
|
|
private IPostsPraiseRepository postsPraiseRepository;
|
|
|
@Resource
|
|
|
private ITopicPostRepository topicPostRepository;
|
|
|
@Resource
|
|
|
private ITopicRepository topicRepository;
|
|
|
@Resource
|
|
|
private IPublicLabelRepository publicLabelRepository;
|
|
|
@Resource
|
|
|
private ITblCommentInfoRepository tblCommentInfoRepository;
|
|
|
@Resource
|
|
|
private IPublicUserCommentRepository publicUserCommentRepository;
|
|
|
@Resource
|
|
|
private ICommunityUserRepository communityUserRepository;
|
|
|
@Resource
|
|
|
private IPublicUserPraiseRepository publicUserPraiseRepository;
|
|
|
@Resource
|
|
|
private IPublicUserAttentionRepository publicUserAttentionRepository;
|
|
|
@Resource
|
|
|
private ITblAttentionUserRepository tblAttentionUserRepository;
|
|
|
|
|
|
public final int size=50;
|
|
|
|
|
|
public String synArticle(long begTime, long endTime) {
|
...
|
...
|
@@ -62,10 +77,12 @@ public class YohoNowDataSynService { |
|
|
Map<Integer,PostsPraiseTotal> postsPraiseTotalMap = BeanConvertUtils.listToMap(praiseTotals,Integer.class,"postsId");
|
|
|
List<PublicArticle> pArticles = buildPublicArticles(postsList,postsBlockMap,postsPraiseTotalMap);
|
|
|
publicArticleRepository.saveAll(pArticles);
|
|
|
//TODO 文章审核表不同步
|
|
|
//文章审核表同步
|
|
|
synArticleAudit(pArticles,postsList);
|
|
|
//文章内容block同步
|
|
|
synArticleBlock(pArticles,postsBlockMap);
|
|
|
//用户文章关联标签同步
|
|
|
synArticleLabel(pArticles);
|
|
|
try {
|
|
|
Thread.sleep(200);
|
|
|
} catch (InterruptedException e) {
|
...
|
...
|
@@ -75,10 +92,88 @@ public class YohoNowDataSynService { |
|
|
return "success";
|
|
|
}
|
|
|
|
|
|
private void synArticleAudit(List<PublicArticle> pArticles, List<Posts> postsList) {
|
|
|
List<PublicArticleAudit> auditList = new ArrayList<>();
|
|
|
Map<Integer,Posts> postsMap = BeanConvertUtils.listToMap(postsList,Integer.class,"id");
|
|
|
for(PublicArticle article : pArticles){
|
|
|
Posts posts = postsMap.get(article.getRelateId());
|
|
|
PublicArticleAudit audit = new PublicArticleAudit();
|
|
|
audit.setArticleId(article.getId());
|
|
|
audit.setAuditAccount(posts.getRevieweUserName());
|
|
|
audit.setAuditTime(posts.getRevieweTime());
|
|
|
audit.setAuditStatus(2);//审核都是通过的
|
|
|
auditList.add(audit);
|
|
|
}
|
|
|
if(!auditList.isEmpty()){
|
|
|
publicArticleAuditRepository.saveAll(auditList);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void synArticleLabel( List<PublicArticle> pArticleList){
|
|
|
if(CollectionUtils.isEmpty(pArticleList)){
|
|
|
return;
|
|
|
}
|
|
|
try{
|
|
|
//这批文章的postid
|
|
|
List<Integer> postIds = pArticleList.stream().map(PublicArticle::getRelateId).collect(Collectors.toList());
|
|
|
Map<Integer,Integer> articleIdAndPostIdMap = pArticleList.stream().
|
|
|
collect(Collectors.toMap(PublicArticle::getRelateId, PublicArticle::getId,(k1, k2)->k1));
|
|
|
//获取在grass 模块已存在的uid, 并排除
|
|
|
List<TopicPost> topicPosts = topicPostRepository.selectByPostIds(postIds);
|
|
|
//同步标签
|
|
|
List<Integer> topicIds = topicPosts.stream().map(TopicPost::getTopicId).distinct().collect(Collectors.toList());
|
|
|
List<PublicLabel> needSyncLabelList = new ArrayList<>();
|
|
|
if(!CollectionUtils.isEmpty(topicIds)){
|
|
|
//排除已经同步过来的标签
|
|
|
List<PublicLabel> existLabel = publicLabelRepository.selectByIds(topicIds);
|
|
|
List<Integer> existLabelIds = existLabel.stream().map(PublicLabel::getId).collect(Collectors.toList());
|
|
|
List<Integer> needSyncIds = topicIds.stream().filter(integer -> !existLabelIds.contains(integer)).collect(Collectors.toList());
|
|
|
if(!CollectionUtils.isEmpty(needSyncIds)){
|
|
|
List<Topic> topicList = topicRepository.selectByIds(needSyncIds);
|
|
|
if(!CollectionUtils.isEmpty(topicList)){
|
|
|
long now = System.currentTimeMillis();
|
|
|
topicList.forEach(x -> {
|
|
|
PublicLabel grassLabel = new PublicLabel();
|
|
|
grassLabel.setId(x.getId());
|
|
|
grassLabel.setLabelName(x.getTopicName().replace("#",""));
|
|
|
grassLabel.setStatus(1);
|
|
|
grassLabel.setCreateTime(now);
|
|
|
grassLabel.setIsVisible(2); //用户不可见
|
|
|
needSyncLabelList.add(grassLabel);
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if(!CollectionUtils.isEmpty(needSyncLabelList)){
|
|
|
publicLabelRepository.saveAll(needSyncLabelList);//TODO id是否也保存了
|
|
|
}
|
|
|
|
|
|
//需要同步过来的文章和话题关联关系
|
|
|
List<PublicArticleLabel> needSyncList = new ArrayList<>();
|
|
|
if(!CollectionUtils.isEmpty(topicPosts)){
|
|
|
long now = System.currentTimeMillis();
|
|
|
topicPosts.forEach(x -> {
|
|
|
PublicArticleLabel articleLabel = new PublicArticleLabel();
|
|
|
articleLabel.setLabelId(x.getTopicId());
|
|
|
articleLabel.setArticleId(articleIdAndPostIdMap.get(x.getPostId()));
|
|
|
articleLabel.setCreateTime(now);
|
|
|
articleLabel.setSrcChannel(3); // now社区
|
|
|
needSyncList.add(articleLabel);
|
|
|
});
|
|
|
}
|
|
|
if(!CollectionUtils.isEmpty(needSyncList)){
|
|
|
publicArticleLabelRepository.saveAll(needSyncList);
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void synArticleBlock(List<PublicArticle> pArticles, Map<Integer, List<PostsBlock>> postsBlockMap) {
|
|
|
List<PublicArticleBlock> pBlocks = new ArrayList<>();
|
|
|
for(PublicArticle article : pArticles){
|
|
|
List<PostsBlock> blocks = postsBlockMap.get(article.getRelateId());
|
|
|
Map<Integer,Boolean> coverImgBlockMap = new HashMap<>();
|
|
|
for(PostsBlock block : blocks){
|
|
|
PublicArticleBlock pBlock = new PublicArticleBlock();
|
|
|
pBlock.setArticleId(article.getId());
|
...
|
...
|
@@ -86,7 +181,12 @@ public class YohoNowDataSynService { |
|
|
pBlock.setOrderBy(block.getOrderBy());
|
|
|
pBlock.setContentType(block.getTemplateKey());
|
|
|
if(block.getTemplateKey().equals(PostsBlock.TEMPLATEKEY_IMAGE)){
|
|
|
pBlock.setContentData(getImageBlock(block.getContentData(), block.getSize()));
|
|
|
String isCoverImg="N";
|
|
|
if(null == coverImgBlockMap.get(block.getPostsId())){
|
|
|
isCoverImg="Y";
|
|
|
coverImgBlockMap.put(block.getPostsId(),true);
|
|
|
}
|
|
|
pBlock.setContentData(getImageBlock(block.getContentData(), block.getSize(),isCoverImg));
|
|
|
pBlocks.add(pBlock);
|
|
|
}
|
|
|
if(block.getTemplateKey().equals(PostsBlock.TEMPLATEKEY_TEXT)){
|
...
|
...
|
@@ -102,39 +202,27 @@ public class YohoNowDataSynService { |
|
|
sb.forEach(s -> {
|
|
|
result.set(result.get().replace(s, ""));
|
|
|
});
|
|
|
pBlock.setContentData(getBlock(PostsBlock.TEMPLATEKEY_TEXT, result.get()));
|
|
|
pBlock.setContentData(getTextBlock(result.get()));
|
|
|
pBlocks.add(pBlock);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if(!pBlocks.isEmpty()){
|
|
|
publicArticleBlockRepository.saveAll(pBlocks);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private String getBlock(String templatName, String data){
|
|
|
JSONObject o = new JSONObject();
|
|
|
private String getTextBlock(String data){
|
|
|
JSONObject dataObject = new JSONObject();
|
|
|
switch (templatName){
|
|
|
case PostsBlock.TEMPLATEKEY_IMAGE:
|
|
|
String urlWithHttp = ImagesHelper.getImageAbsoluteUrl(data, ImagesConstant.BUCKET_GRASS);
|
|
|
String finalUrl = ImagesHelper.convertImageUrlWithDefault(urlWithHttp);
|
|
|
dataObject.put("src",finalUrl);
|
|
|
dataObject.put("width",1);
|
|
|
dataObject.put("height",1);
|
|
|
break;
|
|
|
case PostsBlock.TEMPLATEKEY_TEXT:
|
|
|
dataObject.put("text",data);
|
|
|
break;
|
|
|
default:break;
|
|
|
}
|
|
|
o.put("template_name", templatName);
|
|
|
o.put("data", dataObject.toJSONString());
|
|
|
return o.toJSONString();
|
|
|
dataObject.put("content",data);
|
|
|
dataObject.put("type","text");
|
|
|
return dataObject.toJSONString();
|
|
|
}
|
|
|
|
|
|
private String getImageBlock(String data, String size) {
|
|
|
private String getImageBlock(String data, String size,String isCoverImg) {
|
|
|
if(StringUtils.isEmpty(data) || (!data.startsWith("http://") && !data.startsWith("/"))){
|
|
|
return "";
|
|
|
}
|
|
|
JSONObject o = new JSONObject();
|
|
|
JSONObject dataObject = new JSONObject();
|
|
|
String width = "";
|
|
|
String height = "";
|
...
|
...
|
@@ -147,13 +235,12 @@ public class YohoNowDataSynService { |
|
|
}
|
|
|
String url = ImagesHelper.getImageAbsoluteUrl(data, ImagesConstant.BUCKET_SOCIAL_PIC);
|
|
|
String finalUrl = ImagesHelper.convertImageUrlWithDefault(url);
|
|
|
dataObject.put("src",finalUrl);
|
|
|
dataObject.put("url",finalUrl);
|
|
|
dataObject.put("width",StringUtils.isEmpty(width) ? 1 : width);
|
|
|
dataObject.put("height",StringUtils.isEmpty(height) ? 1 : height);
|
|
|
|
|
|
o.put("template_name", "image");
|
|
|
o.put("data", dataObject.toJSONString());
|
|
|
return o.toJSONString();
|
|
|
dataObject.put("type", "image");
|
|
|
dataObject.put("isCoverImg",isCoverImg);
|
|
|
return dataObject.toJSONString();
|
|
|
}
|
|
|
|
|
|
private List<PublicArticle> buildPublicArticles(List<Posts> postsList, Map<Integer, List<PostsBlock>> postsBlockMap, Map<Integer, PostsPraiseTotal> postsPraiseTotalMap) {
|
...
|
...
|
@@ -161,28 +248,359 @@ public class YohoNowDataSynService { |
|
|
for(Posts posts : postsList){
|
|
|
List<PostsBlock> postsBlocks = postsBlockMap.get(posts.getId());
|
|
|
PostsPraiseTotal postsPraiseTotal = postsPraiseTotalMap.get(posts.getId());
|
|
|
if(!CollectionUtils.isEmpty(postsBlocks)){
|
|
|
postsBlocks = postsBlocks.stream().filter(s -> s.getTemplateKey().equals("image")).collect(Collectors.toList());
|
|
|
if(CollectionUtils.isEmpty(postsBlocks)){
|
|
|
continue;
|
|
|
}
|
|
|
if(CollectionUtils.isEmpty(postsBlocks)){
|
|
|
continue;
|
|
|
}
|
|
|
List<PostsBlock> imgBlockList = postsBlocks.stream().filter(s -> s.getTemplateKey().equals("image")).collect(Collectors.toList());
|
|
|
if(CollectionUtils.isEmpty(imgBlockList)){
|
|
|
continue;
|
|
|
}
|
|
|
PublicArticle article = new PublicArticle();
|
|
|
article.setArticleType(5); //now社区文章同步类型
|
|
|
article.setRelateId(posts.getId());
|
|
|
//article.setMinRelateId();//TODO 二次同步什么鬼?
|
|
|
article.setAuthorUid(posts.getAuthorId());//authorUid
|
|
|
// article.setAuthorType();//authorType TODO 是啥
|
|
|
article.setPraiseNum(postsPraiseTotal == null ? 0 : postsPraiseTotal.getTotal());//praiseCount
|
|
|
article.setPraiseNum(postsPraiseTotal == null ? 0 : postsPraiseTotal.getTotal().intValue());//praiseCount
|
|
|
// article.setFavoriteNum();//favoriteCount TODO
|
|
|
article.setStatus(1);//auth_status
|
|
|
article.setAuditStatus(2);//auth_status 与审核相关
|
|
|
article.setPublishTime(posts.getCreateTime());//create_time
|
|
|
article.setCreateTime(posts.getCreateTime());//create_time
|
|
|
article.setUpdateTime(posts.getUpdateTime());//update_time
|
|
|
article.setCoverImg(postsBlocks.get(0).getContentData());
|
|
|
//设置封面
|
|
|
PostsBlock coverBlock = imgBlockList.get(0);
|
|
|
String coverImgData = getImageBlock(coverBlock.getContentData(), coverBlock.getSize(),"Y");
|
|
|
article.setCoverImg(coverImgData);
|
|
|
articleList.add(article);
|
|
|
}
|
|
|
return articleList;
|
|
|
}
|
|
|
|
|
|
public String synArticleAttach(long begTime, long endTime, int type, boolean isFromArticle) {
|
|
|
switch (type){
|
|
|
case 0:
|
|
|
if(isFromArticle){
|
|
|
synCommentDataByArticle(begTime,endTime);
|
|
|
}else{
|
|
|
synCommentDataByTime((int)(begTime/1000),(int)(endTime/1000));
|
|
|
}
|
|
|
break;
|
|
|
case 1:
|
|
|
if(isFromArticle){
|
|
|
synPraiseDataByArticle(begTime,endTime);
|
|
|
}else{
|
|
|
synPraiseDataByTime(begTime,endTime);
|
|
|
}
|
|
|
break;
|
|
|
case 2:
|
|
|
if(isFromArticle){
|
|
|
synAttentionAuthorByArticle(begTime,endTime);
|
|
|
}else {
|
|
|
synAttentionAuthorByTime((int)(begTime/1000),(int)(endTime/1000));
|
|
|
}
|
|
|
break;
|
|
|
default:
|
|
|
return "false";
|
|
|
}
|
|
|
return "success";
|
|
|
}
|
|
|
|
|
|
private void synAttentionAuthorByArticle(long begTime, long endTime) {
|
|
|
int total = publicArticleRepository.selectTotal(begTime,endTime);
|
|
|
for(int offset=0;offset<total;offset+=size) {
|
|
|
List<PublicArticle> articleList = publicArticleRepository.selectByTime(begTime, endTime, offset, size);
|
|
|
List<Integer> authorUids = articleList.stream().map(PublicArticle::getAuthorUid).collect(Collectors.toList());
|
|
|
if(CollectionUtils.isEmpty(authorUids)){
|
|
|
return;
|
|
|
}
|
|
|
//然后根据uid_attention查找粉丝
|
|
|
int fanUserTotal = tblAttentionUserRepository.selectTotalByUidAttentions(authorUids);
|
|
|
for(int i=0;i<fanUserTotal;i+=size){
|
|
|
List<TblAttentionUser> fanUsersList = tblAttentionUserRepository.selectByUidAttentions(authorUids,i,size);
|
|
|
Map<Integer,List<TblAttentionUser>> fanUsersMap = buildFanUserMap(fanUsersList);
|
|
|
if(null != fanUsersMap && fanUsersMap.size() != 0){
|
|
|
//过滤掉马甲用户
|
|
|
List<Integer> fanUids = fanUsersMap.keySet().stream().collect(Collectors.toList());
|
|
|
List<Integer> filtedFanUids = communityUserRepository.selectRealUids(fanUids);
|
|
|
List<PublicUserAttention> userAttentions = buildSynAttentionAuthor(fanUsersMap,filtedFanUids);
|
|
|
if(!CollectionUtils.isEmpty(userAttentions)){
|
|
|
publicUserAttentionRepository.saveAll(userAttentions);
|
|
|
try{
|
|
|
Thread.sleep(200);
|
|
|
}catch (Exception exp){
|
|
|
exp.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void synAttentionAuthorByTime(int begTime, int endTime) {
|
|
|
int total = tblAttentionUserRepository.selectTotalByTime(begTime,endTime);
|
|
|
for(int offset=0;offset<total;offset+=size) {
|
|
|
List<TblAttentionUser> fanUsersList = tblAttentionUserRepository.selectByTime(begTime,endTime,offset,size);
|
|
|
Map<Integer,List<TblAttentionUser>> fanUsersMap = buildFanUserMap(fanUsersList);
|
|
|
if(null != fanUsersMap && fanUsersMap.size() != 0){
|
|
|
//过滤掉马甲用户
|
|
|
List<Integer> fanUids = fanUsersMap.keySet().stream().collect(Collectors.toList());
|
|
|
List<Integer> filtedFanUids = communityUserRepository.selectRealUids(fanUids);
|
|
|
List<PublicUserAttention> userAttentions = buildSynAttentionAuthor(fanUsersMap,filtedFanUids);
|
|
|
if(!CollectionUtils.isEmpty(userAttentions)){
|
|
|
publicUserAttentionRepository.saveAll(userAttentions);
|
|
|
try{
|
|
|
Thread.sleep(200);
|
|
|
}catch (Exception exp){
|
|
|
exp.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private List<PublicUserAttention> buildSynAttentionAuthor(Map<Integer, List<TblAttentionUser>> fanUsersMap, List<Integer> filtedFanUids) {
|
|
|
List<PublicUserAttention> userAttentions = new ArrayList<>();
|
|
|
for(Integer fanUid : filtedFanUids){
|
|
|
List<TblAttentionUser> tblAttentionUsers = fanUsersMap.get(fanUid);
|
|
|
for(TblAttentionUser tblAttentionUser : tblAttentionUsers){
|
|
|
PublicUserAttention userAttention = new PublicUserAttention(tblAttentionUser);
|
|
|
userAttentions.add(userAttention);
|
|
|
}
|
|
|
}
|
|
|
return userAttentions;
|
|
|
}
|
|
|
|
|
|
private Map<Integer,List<TblAttentionUser>> buildFanUserMap(List<TblAttentionUser> fanUsersList){
|
|
|
if(CollectionUtils.isEmpty(fanUsersList)){
|
|
|
return null;
|
|
|
}
|
|
|
Map<Integer,List<TblAttentionUser>> fanUsersMap = new HashMap<>();
|
|
|
for(TblAttentionUser attentionUser : fanUsersList){
|
|
|
if(attentionUser.getUid() == null){
|
|
|
continue;
|
|
|
}
|
|
|
List<TblAttentionUser> attentionUsers = fanUsersMap.get(attentionUser.getUid());
|
|
|
if(attentionUsers == null){
|
|
|
attentionUsers = new ArrayList<>();
|
|
|
fanUsersMap.put(attentionUser.getUid(),attentionUsers);
|
|
|
}
|
|
|
attentionUsers.add(attentionUser);
|
|
|
}
|
|
|
return fanUsersMap;
|
|
|
}
|
|
|
|
|
|
private void synPraiseDataByArticle(long begTime, long endTime) {
|
|
|
int total = publicArticleRepository.selectTotal(begTime,endTime);
|
|
|
for(int offset=0;offset<total;offset+=size){
|
|
|
List<PublicArticle> articleList = publicArticleRepository.selectByTime(begTime,endTime,offset,size);
|
|
|
Map<Integer,PublicArticle> articleMap = BeanConvertUtils.listToMap(articleList,Integer.class,"relateId");
|
|
|
List<Integer> relateIds = articleMap.keySet().stream().collect(Collectors.toList());
|
|
|
if(CollectionUtils.isEmpty(relateIds)){
|
|
|
return;
|
|
|
}
|
|
|
//根据文章relate_id去posts_praise.posts_id查找点赞数据,无需过滤马甲
|
|
|
int praiseTotal = postsPraiseRepository.selectTotalByPostIds(relateIds);
|
|
|
for(int i=0;i<praiseTotal;i+=size){
|
|
|
List<PostsPraise> praiseList = postsPraiseRepository.selectByPostIds(relateIds,i,size);
|
|
|
//将点赞数据同步到表grass_article_praise
|
|
|
List<PublicUserPraise> articlePraises = buildSynArticlePraises(articleMap,praiseList);
|
|
|
if(!articlePraises.isEmpty()){
|
|
|
publicUserPraiseRepository.saveAll(articlePraises);
|
|
|
try{
|
|
|
Thread.sleep(500);
|
|
|
}catch (Exception exp){
|
|
|
exp.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void synPraiseDataByTime(long begTime, long endTime) {
|
|
|
int total = postsPraiseRepository.selectTotalByTime(begTime,endTime);
|
|
|
for(int offset=0;offset<total;offset+=size){
|
|
|
List<PostsPraise> praiseList = postsPraiseRepository.selectByTime(begTime,endTime,offset,size);
|
|
|
if(CollectionUtils.isEmpty(praiseList)){
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
List<Integer> postIds = praiseList.stream().map(PostsPraise::getPostsId).collect(Collectors.toList());
|
|
|
List<PublicArticle> articleList = publicArticleRepository.selectByRelateIds(postIds);
|
|
|
Map<Integer,PublicArticle> articleMap = BeanConvertUtils.listToMap(articleList,Integer.class,"relateId");
|
|
|
|
|
|
//将点赞数据同步到表grass_article_praise
|
|
|
List<PublicUserPraise> articlePraises = buildSynArticlePraises(articleMap,praiseList);
|
|
|
if(!articlePraises.isEmpty()){
|
|
|
publicUserPraiseRepository.saveAll(articlePraises);
|
|
|
try{
|
|
|
Thread.sleep(500);
|
|
|
}catch (Exception exp){
|
|
|
exp.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private List<PublicUserPraise> buildSynArticlePraises(Map<Integer, PublicArticle> articleMap, List<PostsPraise> praiseList) {
|
|
|
List<PublicUserPraise> articlePraises = new ArrayList<>();
|
|
|
for(PostsPraise praise : praiseList){
|
|
|
PublicArticle article = articleMap.get(praise.getPostsId());
|
|
|
if(null == article){
|
|
|
continue;
|
|
|
}
|
|
|
PublicUserPraise articlePraise = new PublicUserPraise(praise,article);
|
|
|
articlePraises.add(articlePraise);
|
|
|
}
|
|
|
return articlePraises;
|
|
|
}
|
|
|
|
|
|
private void synCommentDataByArticle(long begTime, long endTime) {
|
|
|
int total = publicArticleRepository.selectTotal(begTime,endTime);
|
|
|
for(int offset=0;offset<total;offset+=size){
|
|
|
List<PublicArticle> articleList = publicArticleRepository.selectByTime(begTime,endTime,offset,size);
|
|
|
Map<Integer,PublicArticle> articleMap = BeanConvertUtils.listToMap(articleList,Integer.class,"relateId");
|
|
|
List<Integer> relateIds = articleMap.keySet().stream().collect(Collectors.toList());
|
|
|
if(CollectionUtils.isEmpty(relateIds)){
|
|
|
return;
|
|
|
}
|
|
|
//先同步根评论
|
|
|
int rootTotal = tblCommentInfoRepository.selectTotalRootByContentIds(relateIds);
|
|
|
for(int i=0;i<rootTotal;i+=size){
|
|
|
List<TblCommentInfo> rootComments = tblCommentInfoRepository.selectRootByContentIds(relateIds,i,size);
|
|
|
if(CollectionUtils.isEmpty(rootComments)){
|
|
|
break;
|
|
|
}
|
|
|
List<PublicUserComment> parentArticleComments = batchSaveNewComment(articleMap,rootComments,null);
|
|
|
if(!CollectionUtils.isEmpty(parentArticleComments)){
|
|
|
List<Integer> parentIds = parentArticleComments.stream().map(comm->comm.getRelateId()).collect(Collectors.toList());
|
|
|
List<TblCommentInfo> childComments = tblCommentInfoRepository.selectChildByToCommentIds(parentIds);
|
|
|
while(!CollectionUtils.isEmpty(childComments)){
|
|
|
parentArticleComments = batchSaveNewComment(articleMap,childComments,parentArticleComments);
|
|
|
if(CollectionUtils.isEmpty(parentArticleComments)){
|
|
|
break;
|
|
|
}
|
|
|
parentIds = parentArticleComments.stream().map(comm->comm.getRelateId()).collect(Collectors.toList());
|
|
|
childComments = tblCommentInfoRepository.selectChildByToCommentIds(parentIds);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void synCommentDataByTime(int begTime, int endTime){
|
|
|
int total = tblCommentInfoRepository.selectTotalRootByTime(begTime,endTime);
|
|
|
for(int offset=0;offset<total;offset+=size){
|
|
|
List<TblCommentInfo> rootComments = tblCommentInfoRepository.selectRootByTime(begTime,endTime,offset,size);
|
|
|
if(CollectionUtils.isEmpty(rootComments)){
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
List<Integer> articleRelateIds = rootComments.stream().map(TblCommentInfo::getContentId).collect(Collectors.toList());
|
|
|
List<PublicArticle> articleList = publicArticleRepository.selectByRelateIds(articleRelateIds);
|
|
|
Map<Integer,PublicArticle> articleMap = BeanConvertUtils.listToMap(articleList,Integer.class,"relateId");
|
|
|
|
|
|
List<PublicUserComment> parentArticleComments = batchSaveNewComment(articleMap,rootComments,null);
|
|
|
if(!CollectionUtils.isEmpty(parentArticleComments)){
|
|
|
List<Integer> parentIds = parentArticleComments.stream().map(comm->comm.getRelateId()).collect(Collectors.toList());
|
|
|
List<TblCommentInfo> childComments = tblCommentInfoRepository.selectChildByToCommentIds(parentIds);
|
|
|
while(!CollectionUtils.isEmpty(childComments)){
|
|
|
parentArticleComments = batchSaveNewComment(articleMap,childComments,parentArticleComments);
|
|
|
if(CollectionUtils.isEmpty(parentArticleComments)){
|
|
|
break;
|
|
|
}
|
|
|
parentIds = parentArticleComments.stream().map(comm->comm.getRelateId()).collect(Collectors.toList());
|
|
|
childComments = tblCommentInfoRepository.selectChildByToCommentIds(parentIds);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private List<PublicUserComment> batchSaveNewComment(Map<Integer, PublicArticle> articleMap, List<TblCommentInfo> comments,
|
|
|
List<PublicUserComment> parentArticleComments) {
|
|
|
//过滤掉马甲用户
|
|
|
filterTblCommentInfos(comments);
|
|
|
if(CollectionUtils.isEmpty(comments)){
|
|
|
return null;
|
|
|
}
|
|
|
List<PublicUserComment> articleComments = buildSynNewComments(articleMap,comments,parentArticleComments);
|
|
|
if(!CollectionUtils.isEmpty(articleComments)){
|
|
|
publicUserCommentRepository.saveAll(articleComments);
|
|
|
// List<Integer> relateIds = articleComments.stream().map(comm->comm.getRelateId())
|
|
|
// .collect(Collectors.toList());
|
|
|
// articleComments = publicUserCommentRepository.selectByRelateIds(relateIds,3);//src_channel 已经把id带出来了
|
|
|
try{
|
|
|
Thread.sleep(200);
|
|
|
}catch (Exception exp){
|
|
|
exp.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
return articleComments;
|
|
|
}
|
|
|
|
|
|
private List<PublicUserComment> buildSynNewComments(Map<Integer, PublicArticle> articleMap, List<TblCommentInfo> comments,
|
|
|
List<PublicUserComment> parentArticleComments) {
|
|
|
List<PublicUserComment> articleComments = new ArrayList<>();
|
|
|
for(TblCommentInfo comment : comments){
|
|
|
PublicArticle article = null == comment.getContentId() ? null : articleMap.get(comment.getContentId());
|
|
|
if(article == null){
|
|
|
continue;
|
|
|
}
|
|
|
PublicUserComment parent = findParentGrassComment(comment.getToCommentId(),parentArticleComments);
|
|
|
PublicUserComment articleComment = new PublicUserComment(comment,article.getId(),parent);
|
|
|
articleComments.add(articleComment);
|
|
|
}
|
|
|
return articleComments;
|
|
|
}
|
|
|
|
|
|
private PublicUserComment findParentGrassComment(Integer relateId, List<PublicUserComment> parentArticleComments) {
|
|
|
if(CollectionUtils.isEmpty(parentArticleComments) || relateId == null){
|
|
|
return null;
|
|
|
}
|
|
|
for(PublicUserComment comment : parentArticleComments){
|
|
|
if(relateId.equals(comment.getRelateId())){
|
|
|
return comment;
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
private void filterTblCommentInfos(List<TblCommentInfo> comments) {
|
|
|
if(CollectionUtils.isEmpty(comments)){
|
|
|
return;
|
|
|
}
|
|
|
Set<Integer> commentUidSet = new HashSet<>();
|
|
|
comments.stream().forEach(
|
|
|
comm->{
|
|
|
if(comm.getUid()!=null && comm.getUid()!=0){
|
|
|
commentUidSet.add(comm.getUid());
|
|
|
}
|
|
|
if(comm.getToUid()!=null && comm.getToUid()!=0){
|
|
|
commentUidSet.add(comm.getToUid());
|
|
|
}
|
|
|
}
|
|
|
);
|
|
|
List<Integer> commentUids = commentUidSet.stream().collect(Collectors.toList());
|
|
|
if(CollectionUtils.isEmpty(commentUids)){
|
|
|
return;
|
|
|
}
|
|
|
List<Integer> filterUids = communityUserRepository.selectRealUids(commentUids);
|
|
|
for(int i=0;i<comments.size();){
|
|
|
TblCommentInfo socialComments = comments.get(i);
|
|
|
boolean isDelFromid = true;
|
|
|
boolean isDelToid = true;
|
|
|
for(Integer uid : filterUids){
|
|
|
if(socialComments.getUid() == null || socialComments.getUid() == 0 || uid.equals(socialComments.getUid())){
|
|
|
isDelFromid = false;
|
|
|
}
|
|
|
if(socialComments.getToUid() == null || socialComments.getToUid() == 0 || uid.equals(socialComments.getToUid())){
|
|
|
isDelToid = false;
|
|
|
}
|
|
|
}
|
|
|
if(isDelFromid || isDelToid){
|
|
|
comments.remove(i);
|
|
|
}else{
|
|
|
i++;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} |
...
|
...
|
|