Authored by csgyoho

synnowdata

... ... @@ -11,7 +11,5 @@ public class BaseEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false, unique = true)
protected Integer id;
}
... ...
package com.yoho.datasync.fullsync.dal.repository.pcms.model;
import com.yoho.datasync.fullsync.dal.repository.BaseEntity;
import lombok.Data;
import javax.persistence.*;
... ... @@ -11,9 +12,7 @@ import java.io.Serializable;
@Data
@Entity
@Table(name = "public_label")
public class PublicLabel implements Serializable {
@javax.persistence.Id
private Integer id;
public class PublicLabel extends BaseEntity implements Serializable {
@Column(name = "label_name")
private String labelName;
@Column(name = "group_id")
... ...
... ... @@ -17,6 +17,7 @@ import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import javax.persistence.EntityManager;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Matcher;
... ... @@ -60,7 +61,8 @@ public class YohoNowDataSynService {
private IPublicUserAttentionRepository publicUserAttentionRepository;
@Resource
private ITblAttentionUserRepository tblAttentionUserRepository;
@Resource(name = "entityManagerPrimary")
private EntityManager publicEntityManager;
public final int size=50;
public String synArticle(long begTime, long endTime) {
... ... @@ -92,6 +94,22 @@ public class YohoNowDataSynService {
return "success";
}
private void synArticles(List<PublicArticle> pArticles){
StringBuilder sb = new StringBuilder();
for(PublicArticle article : pArticles){
if(sb.length()==0){
sb.append("insert into public_article(cover_img,article_type ,relate_id ,author_uid,praise_num," +
"status,audit_status,publish_time,create_time,update_time) values");
}else{
sb.append(",");
}
sb.append("(").append(article.getCoverImg()).append(article.getArticleType()).append(article.getRelateId()).
append(article.getAuthorUid()).append(article.getPraiseNum()).append(article.getStatus()).
append(article.getAuditStatus()).append(article.getPublishTime()).append(article.getCreateTime())
.append(article.getUpdateTime());
}
}
private void synArticleAudit(List<PublicArticle> pArticles, List<Posts> postsList) {
List<PublicArticleAudit> auditList = new ArrayList<>();
Map<Integer,Posts> postsMap = BeanConvertUtils.listToMap(postsList,Integer.class,"id");
... ... @@ -118,23 +136,17 @@ public class YohoNowDataSynService {
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(topicIds)){
List<Topic> topicList = topicRepository.selectByIds(topicIds);
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);
... ...
... ... @@ -7,7 +7,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.transaction.PlatformTransactionManager;
... ... @@ -36,6 +36,7 @@ public class PrimaryDataSourceConfig {
public EntityManager entityManager(@Qualifier("entityManagerFactoryPrimary") LocalContainerEntityManagerFactoryBean entityManagerFactory) {
return entityManagerFactory.getObject().createEntityManager();
}
@Primary
@Bean(name = "entityManagerFactoryPrimary")
public LocalContainerEntityManagerFactoryBean entityManagerFactoryPrimary (EntityManagerFactoryBuilder builder) {
... ...