Authored by csgyoho

synnowdata

@@ -11,7 +11,5 @@ public class BaseEntity { @@ -11,7 +11,5 @@ public class BaseEntity {
11 @GeneratedValue(strategy = GenerationType.IDENTITY) 11 @GeneratedValue(strategy = GenerationType.IDENTITY)
12 @Column(name = "id", nullable = false, unique = true) 12 @Column(name = "id", nullable = false, unique = true)
13 protected Integer id; 13 protected Integer id;
14 -  
15 -  
16 } 14 }
17 15
1 package com.yoho.datasync.fullsync.dal.repository.pcms.model; 1 package com.yoho.datasync.fullsync.dal.repository.pcms.model;
2 2
  3 +import com.yoho.datasync.fullsync.dal.repository.BaseEntity;
3 import lombok.Data; 4 import lombok.Data;
4 5
5 import javax.persistence.*; 6 import javax.persistence.*;
@@ -11,9 +12,7 @@ import java.io.Serializable; @@ -11,9 +12,7 @@ import java.io.Serializable;
11 @Data 12 @Data
12 @Entity 13 @Entity
13 @Table(name = "public_label") 14 @Table(name = "public_label")
14 -public class PublicLabel implements Serializable {  
15 - @javax.persistence.Id  
16 - private Integer id; 15 +public class PublicLabel extends BaseEntity implements Serializable {
17 @Column(name = "label_name") 16 @Column(name = "label_name")
18 private String labelName; 17 private String labelName;
19 @Column(name = "group_id") 18 @Column(name = "group_id")
@@ -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);
@@ -7,7 +7,7 @@ import org.springframework.context.annotation.Bean; @@ -7,7 +7,7 @@ import org.springframework.context.annotation.Bean;
7 import org.springframework.context.annotation.Configuration; 7 import org.springframework.context.annotation.Configuration;
8 import org.springframework.context.annotation.Primary; 8 import org.springframework.context.annotation.Primary;
9 import org.springframework.data.jpa.repository.config.EnableJpaRepositories; 9 import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
10 -import org.springframework.orm.jpa.JpaTransactionManager; 10 +import org.springframework.jdbc.datasource.DataSourceTransactionManager;
11 import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; 11 import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
12 import org.springframework.transaction.PlatformTransactionManager; 12 import org.springframework.transaction.PlatformTransactionManager;
13 13
@@ -36,6 +36,7 @@ public class PrimaryDataSourceConfig { @@ -36,6 +36,7 @@ public class PrimaryDataSourceConfig {
36 public EntityManager entityManager(@Qualifier("entityManagerFactoryPrimary") LocalContainerEntityManagerFactoryBean entityManagerFactory) { 36 public EntityManager entityManager(@Qualifier("entityManagerFactoryPrimary") LocalContainerEntityManagerFactoryBean entityManagerFactory) {
37 return entityManagerFactory.getObject().createEntityManager(); 37 return entityManagerFactory.getObject().createEntityManager();
38 } 38 }
  39 +
39 @Primary 40 @Primary
40 @Bean(name = "entityManagerFactoryPrimary") 41 @Bean(name = "entityManagerFactoryPrimary")
41 public LocalContainerEntityManagerFactoryBean entityManagerFactoryPrimary (EntityManagerFactoryBuilder builder) { 42 public LocalContainerEntityManagerFactoryBean entityManagerFactoryPrimary (EntityManagerFactoryBuilder builder) {