|
@@ -17,6 +17,7 @@ import org.springframework.util.CollectionUtils; |
|
@@ -17,6 +17,7 @@ import org.springframework.util.CollectionUtils; |
17
|
import org.springframework.util.StringUtils;
|
17
|
import org.springframework.util.StringUtils;
|
18
|
|
18
|
|
19
|
import javax.annotation.Resource;
|
19
|
import javax.annotation.Resource;
|
|
|
20
|
+import javax.persistence.EntityManager;
|
20
|
import java.util.*;
|
21
|
import java.util.*;
|
21
|
import java.util.concurrent.atomic.AtomicReference;
|
22
|
import java.util.concurrent.atomic.AtomicReference;
|
22
|
import java.util.regex.Matcher;
|
23
|
import java.util.regex.Matcher;
|
|
@@ -60,7 +61,8 @@ public class YohoNowDataSynService { |
|
@@ -60,7 +61,8 @@ public class YohoNowDataSynService { |
60
|
private IPublicUserAttentionRepository publicUserAttentionRepository;
|
61
|
private IPublicUserAttentionRepository publicUserAttentionRepository;
|
61
|
@Resource
|
62
|
@Resource
|
62
|
private ITblAttentionUserRepository tblAttentionUserRepository;
|
63
|
private ITblAttentionUserRepository tblAttentionUserRepository;
|
63
|
-
|
64
|
+ @Resource(name = "entityManagerPrimary")
|
|
|
65
|
+ private EntityManager publicEntityManager;
|
64
|
public final int size=50;
|
66
|
public final int size=50;
|
65
|
|
67
|
|
66
|
public String synArticle(long begTime, long endTime) {
|
68
|
public String synArticle(long begTime, long endTime) {
|
|
@@ -92,6 +94,22 @@ public class YohoNowDataSynService { |
|
@@ -92,6 +94,22 @@ public class YohoNowDataSynService { |
92
|
return "success";
|
94
|
return "success";
|
93
|
}
|
95
|
}
|
94
|
|
96
|
|
|
|
97
|
+ private void synArticles(List<PublicArticle> pArticles){
|
|
|
98
|
+ StringBuilder sb = new StringBuilder();
|
|
|
99
|
+ for(PublicArticle article : pArticles){
|
|
|
100
|
+ if(sb.length()==0){
|
|
|
101
|
+ sb.append("insert into public_article(cover_img,article_type ,relate_id ,author_uid,praise_num," +
|
|
|
102
|
+ "status,audit_status,publish_time,create_time,update_time) values");
|
|
|
103
|
+ }else{
|
|
|
104
|
+ sb.append(",");
|
|
|
105
|
+ }
|
|
|
106
|
+ sb.append("(").append(article.getCoverImg()).append(article.getArticleType()).append(article.getRelateId()).
|
|
|
107
|
+ append(article.getAuthorUid()).append(article.getPraiseNum()).append(article.getStatus()).
|
|
|
108
|
+ append(article.getAuditStatus()).append(article.getPublishTime()).append(article.getCreateTime())
|
|
|
109
|
+ .append(article.getUpdateTime());
|
|
|
110
|
+ }
|
|
|
111
|
+ }
|
|
|
112
|
+
|
95
|
private void synArticleAudit(List<PublicArticle> pArticles, List<Posts> postsList) {
|
113
|
private void synArticleAudit(List<PublicArticle> pArticles, List<Posts> postsList) {
|
96
|
List<PublicArticleAudit> auditList = new ArrayList<>();
|
114
|
List<PublicArticleAudit> auditList = new ArrayList<>();
|
97
|
Map<Integer,Posts> postsMap = BeanConvertUtils.listToMap(postsList,Integer.class,"id");
|
115
|
Map<Integer,Posts> postsMap = BeanConvertUtils.listToMap(postsList,Integer.class,"id");
|
|
@@ -118,23 +136,17 @@ public class YohoNowDataSynService { |
|
@@ -118,23 +136,17 @@ public class YohoNowDataSynService { |
118
|
List<Integer> postIds = pArticleList.stream().map(PublicArticle::getRelateId).collect(Collectors.toList());
|
136
|
List<Integer> postIds = pArticleList.stream().map(PublicArticle::getRelateId).collect(Collectors.toList());
|
119
|
Map<Integer,Integer> articleIdAndPostIdMap = pArticleList.stream().
|
137
|
Map<Integer,Integer> articleIdAndPostIdMap = pArticleList.stream().
|
120
|
collect(Collectors.toMap(PublicArticle::getRelateId, PublicArticle::getId,(k1, k2)->k1));
|
138
|
collect(Collectors.toMap(PublicArticle::getRelateId, PublicArticle::getId,(k1, k2)->k1));
|
121
|
- //获取在grass 模块已存在的uid, 并排除
|
|
|
122
|
List<TopicPost> topicPosts = topicPostRepository.selectByPostIds(postIds);
|
139
|
List<TopicPost> topicPosts = topicPostRepository.selectByPostIds(postIds);
|
123
|
//同步标签
|
140
|
//同步标签
|
124
|
List<Integer> topicIds = topicPosts.stream().map(TopicPost::getTopicId).distinct().collect(Collectors.toList());
|
141
|
List<Integer> topicIds = topicPosts.stream().map(TopicPost::getTopicId).distinct().collect(Collectors.toList());
|
125
|
List<PublicLabel> needSyncLabelList = new ArrayList<>();
|
142
|
List<PublicLabel> needSyncLabelList = new ArrayList<>();
|
126
|
if(!CollectionUtils.isEmpty(topicIds)){
|
143
|
if(!CollectionUtils.isEmpty(topicIds)){
|
127
|
- //排除已经同步过来的标签
|
|
|
128
|
- List<PublicLabel> existLabel = publicLabelRepository.selectByIds(topicIds);
|
|
|
129
|
- List<Integer> existLabelIds = existLabel.stream().map(PublicLabel::getId).collect(Collectors.toList());
|
|
|
130
|
- List<Integer> needSyncIds = topicIds.stream().filter(integer -> !existLabelIds.contains(integer)).collect(Collectors.toList());
|
|
|
131
|
- if(!CollectionUtils.isEmpty(needSyncIds)){
|
|
|
132
|
- List<Topic> topicList = topicRepository.selectByIds(needSyncIds);
|
144
|
+ if(!CollectionUtils.isEmpty(topicIds)){
|
|
|
145
|
+ List<Topic> topicList = topicRepository.selectByIds(topicIds);
|
133
|
if(!CollectionUtils.isEmpty(topicList)){
|
146
|
if(!CollectionUtils.isEmpty(topicList)){
|
134
|
long now = System.currentTimeMillis();
|
147
|
long now = System.currentTimeMillis();
|
135
|
topicList.forEach(x -> {
|
148
|
topicList.forEach(x -> {
|
136
|
PublicLabel grassLabel = new PublicLabel();
|
149
|
PublicLabel grassLabel = new PublicLabel();
|
137
|
- grassLabel.setId(x.getId());
|
|
|
138
|
grassLabel.setLabelName(x.getTopicName().replace("#",""));
|
150
|
grassLabel.setLabelName(x.getTopicName().replace("#",""));
|
139
|
grassLabel.setStatus(1);
|
151
|
grassLabel.setStatus(1);
|
140
|
grassLabel.setCreateTime(now);
|
152
|
grassLabel.setCreateTime(now);
|