Authored by peuei

update

@@ -2,11 +2,14 @@ package com.yoho.datasync.consumer.dal.repository; @@ -2,11 +2,14 @@ package com.yoho.datasync.consumer.dal.repository;
2 2
3 import com.yoho.datasync.core.base.model.yh_pcms.PublicLabel; 3 import com.yoho.datasync.core.base.model.yh_pcms.PublicLabel;
4 import org.springframework.data.jpa.repository.JpaRepository; 4 import org.springframework.data.jpa.repository.JpaRepository;
  5 +import org.springframework.data.jpa.repository.Query;
5 6
6 7
7 -public interface PublicLabelRepository extends JpaRepository<PublicLabel, Integer>{ 8 +public interface PublicLabelRepository extends JpaRepository<PublicLabel, Integer> {
8 9
9 10
10 PublicLabel findByRelateIdAndSrcChannel(Integer relateId, Integer srcChannel); 11 PublicLabel findByRelateIdAndSrcChannel(Integer relateId, Integer srcChannel);
11 12
  13 + @Query("select id from PublicLabel where relateId = ?1 and srcChannel in (?2)")
  14 + Integer findIdByArticleId(Integer trueId, Integer grassSrcChannel);
12 } 15 }
@@ -5,6 +5,7 @@ import com.yoho.datasync.consumer.handler.helper.AnnotationClassFactory; @@ -5,6 +5,7 @@ import com.yoho.datasync.consumer.handler.helper.AnnotationClassFactory;
5 import com.yoho.datasync.consumer.handler.mqcomponent.AbstractMqListener; 5 import com.yoho.datasync.consumer.handler.mqcomponent.AbstractMqListener;
6 import com.yoho.datasync.consumer.service.PublicArticleLabelService; 6 import com.yoho.datasync.consumer.service.PublicArticleLabelService;
7 import com.yoho.datasync.consumer.service.PublicArticleService; 7 import com.yoho.datasync.consumer.service.PublicArticleService;
  8 +import com.yoho.datasync.consumer.service.PublicLabelService;
8 import com.yoho.datasync.core.base.annotation.MqConsumerListerner; 9 import com.yoho.datasync.core.base.annotation.MqConsumerListerner;
9 import com.yoho.datasync.core.base.model.yh_grass.GrassArticleLabel; 10 import com.yoho.datasync.core.base.model.yh_grass.GrassArticleLabel;
10 import com.yoho.datasync.core.base.model.yh_pcms.PublicArticleLabel; 11 import com.yoho.datasync.core.base.model.yh_pcms.PublicArticleLabel;
@@ -32,6 +33,9 @@ public class GrassArticleLabelListener extends AbstractMqListener<GrassArticleLa @@ -32,6 +33,9 @@ public class GrassArticleLabelListener extends AbstractMqListener<GrassArticleLa
32 @Resource 33 @Resource
33 private PublicArticleLabelService publicArticleLabelService; 34 private PublicArticleLabelService publicArticleLabelService;
34 35
  36 + @Resource
  37 + private PublicLabelService publicLabelService;
  38 +
35 39
36 private static final Integer GRASS_SRC_CHANNEL = 1; 40 private static final Integer GRASS_SRC_CHANNEL = 1;
37 41
@@ -100,11 +104,14 @@ public class GrassArticleLabelListener extends AbstractMqListener<GrassArticleLa @@ -100,11 +104,14 @@ public class GrassArticleLabelListener extends AbstractMqListener<GrassArticleLa
100 } 104 }
101 /** 105 /**
102 * public_article_label 表的 label_id 字段为 grass_article_label.label_id 在 grass_label 表中对应的数据同步到 public_label 表之后的自增主键id 106 * public_article_label 表的 label_id 字段为 grass_article_label.label_id 在 grass_label 表中对应的数据同步到 public_label 表之后的自增主键id
103 - * select id from public_label where relate_id=#{grass_article_label.article_id} and src_channel =1 107 + * select id from public_label where relate_id=#{grass_article_label.label_id} and src_channel =1
104 */ 108 */
105 - // TODO : wait 暂无对应接口 109 + Integer labelId = publicLabelService.findIdByArticleId(sourceObject.getLabelId(), GRASS_SRC_CHANNEL);
  110 + if (labelId == null)
  111 + return null;
106 Integer[] result = new Integer[2]; 112 Integer[] result = new Integer[2];
107 result[0] = trueId; 113 result[0] = trueId;
  114 + result[1] = labelId;
108 return result; 115 return result;
109 } 116 }
110 117
@@ -17,13 +17,13 @@ public class PublicLabelService { @@ -17,13 +17,13 @@ public class PublicLabelService {
17 17
18 private static final Logger logger = LoggerFactory.getLogger(PublicLabelService.class); 18 private static final Logger logger = LoggerFactory.getLogger(PublicLabelService.class);
19 19
20 - public void deletePublicLabel(PublicLabel publicLabel) throws Exception{ 20 + public void deletePublicLabel(PublicLabel publicLabel) throws Exception {
21 Integer relateId = publicLabel.getRelateId(); 21 Integer relateId = publicLabel.getRelateId();
22 Integer srcChannel = publicLabel.getSrcChannel(); 22 Integer srcChannel = publicLabel.getSrcChannel();
23 PublicLabel publicLabelFromDB = getByRelateIdAndSrcChannel(relateId, srcChannel); 23 PublicLabel publicLabelFromDB = getByRelateIdAndSrcChannel(relateId, srcChannel);
24 if (publicLabelFromDB != null) { 24 if (publicLabelFromDB != null) {
25 repository.deleteById(publicLabelFromDB.getId()); 25 repository.deleteById(publicLabelFromDB.getId());
26 - }else{ 26 + } else {
27 logger.error("deletePublicLabel数据不存在relateId={}", publicLabel.getRelateId()); 27 logger.error("deletePublicLabel数据不存在relateId={}", publicLabel.getRelateId());
28 throw new Exception("deletePublicLabel失败"); 28 throw new Exception("deletePublicLabel失败");
29 } 29 }
@@ -34,18 +34,22 @@ public class PublicLabelService { @@ -34,18 +34,22 @@ public class PublicLabelService {
34 Integer srcChannel = publicLabel.getSrcChannel(); 34 Integer srcChannel = publicLabel.getSrcChannel();
35 PublicLabel publicLabelFromDB = getByRelateIdAndSrcChannel(relateId, srcChannel); 35 PublicLabel publicLabelFromDB = getByRelateIdAndSrcChannel(relateId, srcChannel);
36 if (publicLabelFromDB != null) { //更新 需要保证原来的字段值不被null覆盖掉 36 if (publicLabelFromDB != null) { //更新 需要保证原来的字段值不被null覆盖掉
37 - publicLabelFromDB = BeanCopyUtils.copyNonNullProperties(publicLabel , publicLabelFromDB , 37 + publicLabelFromDB = BeanCopyUtils.copyNonNullProperties(publicLabel, publicLabelFromDB,
38 PublicLabel.class); 38 PublicLabel.class);
39 repository.save(publicLabelFromDB); 39 repository.save(publicLabelFromDB);
40 - }else{ //新增 40 + } else { //新增
41 repository.save(publicLabel); 41 repository.save(publicLabel);
42 } 42 }
43 } 43 }
44 44
45 - private PublicLabel getByRelateIdAndSrcChannel(Integer relateId , Integer srcChannel){  
46 - if(relateId == null || srcChannel == null){ 45 + private PublicLabel getByRelateIdAndSrcChannel(Integer relateId, Integer srcChannel) {
  46 + if (relateId == null || srcChannel == null) {
47 return null; 47 return null;
48 } 48 }
49 return repository.findByRelateIdAndSrcChannel(relateId, srcChannel); 49 return repository.findByRelateIdAndSrcChannel(relateId, srcChannel);
50 } 50 }
  51 +
  52 + public Integer findIdByArticleId(Integer trueId, Integer grassSrcChannel) {
  53 + return repository.findIdByArticleId(trueId, grassSrcChannel);
  54 + }
51 } 55 }