Authored by peuei

update

Showing 18 changed files with 388 additions and 179 deletions
  1 +package com.yoho.datasync.consumer.common;
  2 +
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.alibaba.fastjson.JSONException;
  5 +
  6 +import java.util.Map;
  7 +
  8 +/***
  9 + * @author peuei
  10 + * @date 2019/3/21 11:40
  11 + * @description 文章内容转换工具
  12 + */
  13 +public class ContentConvertUtil {
  14 +
  15 + /**
  16 + * 将JSON字符串转换成Map对象
  17 + *
  18 + * @param jsonString
  19 + * @return
  20 + */
  21 + public static Map jsonString2Map(String jsonString) {
  22 + Map result;
  23 + try {
  24 + result = JSON.parseObject(jsonString, Map.class);
  25 + } catch (JSONException e) {
  26 + return null;
  27 + }
  28 + for (Object key : result.keySet()) {
  29 + final Object innerMap = jsonString2Map((String) result.get(key));
  30 + if (innerMap != null)
  31 + result.put(key, innerMap);
  32 + else
  33 + result.put(key, result.get(key));
  34 + }
  35 + return result;
  36 + }
  37 +}
@@ -2,8 +2,13 @@ package com.yoho.datasync.consumer.dal.repository; @@ -2,8 +2,13 @@ package com.yoho.datasync.consumer.dal.repository;
2 2
3 import com.yoho.datasync.core.base.model.yh_pcms.PublicArticleBlock; 3 import com.yoho.datasync.core.base.model.yh_pcms.PublicArticleBlock;
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 public interface PublicArticleBlockRepository extends JpaRepository<PublicArticleBlock, Integer> { 7 public interface PublicArticleBlockRepository extends JpaRepository<PublicArticleBlock, Integer> {
7 8
8 - PublicArticleBlock findByArticleIdAndOrderBy(Integer articleId, Integer orderBy); 9 + PublicArticleBlock findByArticleIdAndCreateTimeAndOrderBy(Integer articleId, Long createTime, Integer orderBy);
  10 +
  11 + @Query(nativeQuery = true,
  12 + value = "select content_data from public_article_block where article_id = ?1 and content_type='image' order by order_by asc limit 1")
  13 + String findContentData(Integer trueId);
9 } 14 }
@@ -5,5 +5,5 @@ import org.springframework.data.jpa.repository.JpaRepository; @@ -5,5 +5,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
5 5
6 public interface PublicArticleLabelRepository extends JpaRepository<PublicArticleLabel, Integer> { 6 public interface PublicArticleLabelRepository extends JpaRepository<PublicArticleLabel, Integer> {
7 7
8 - 8 + PublicArticleLabel findByLabelIdAndArticleId(Integer labelId, Integer articleId);
9 } 9 }
@@ -5,5 +5,5 @@ import org.springframework.data.jpa.repository.JpaRepository; @@ -5,5 +5,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
5 5
6 public interface PublicArticleProductRepository extends JpaRepository<PublicArticleProduct, Integer> { 6 public interface PublicArticleProductRepository extends JpaRepository<PublicArticleProduct, Integer> {
7 7
8 - 8 + PublicArticleProduct findByArticleIdAndProductSknAndCreateTimeAndOrderBy(Integer articleId, Integer productSkn, Long createTime, Integer orderBy);
9 } 9 }
@@ -2,6 +2,7 @@ package com.yoho.datasync.consumer.dal.repository; @@ -2,6 +2,7 @@ package com.yoho.datasync.consumer.dal.repository;
2 2
3 import com.yoho.datasync.core.base.model.yh_pcms.PublicArticle; 3 import com.yoho.datasync.core.base.model.yh_pcms.PublicArticle;
4 import org.springframework.data.jpa.repository.JpaRepository; 4 import org.springframework.data.jpa.repository.JpaRepository;
  5 +import org.springframework.data.jpa.repository.Modifying;
5 import org.springframework.data.jpa.repository.Query; 6 import org.springframework.data.jpa.repository.Query;
6 7
7 public interface PublicArticleRepository extends JpaRepository<PublicArticle, Integer> { 8 public interface PublicArticleRepository extends JpaRepository<PublicArticle, Integer> {
@@ -13,8 +14,11 @@ public interface PublicArticleRepository extends JpaRepository<PublicArticle, In @@ -13,8 +14,11 @@ public interface PublicArticleRepository extends JpaRepository<PublicArticle, In
13 @Query("select article from PublicArticle article where article.relateId=?1 and article.articleType in (?2)") 14 @Query("select article from PublicArticle article where article.relateId=?1 and article.articleType in (?2)")
14 PublicArticle findByRelateIdInArticleTypes(Integer relateId, int[] types); 15 PublicArticle findByRelateIdInArticleTypes(Integer relateId, int[] types);
15 16
16 -  
17 @Query("select id from PublicArticle where relateId = ?1 and articleType in (?2)") 17 @Query("select id from PublicArticle where relateId = ?1 and articleType in (?2)")
18 Integer findByArticleId(Integer articleId, int[] types); 18 Integer findByArticleId(Integer articleId, int[] types);
19 19
  20 + @Modifying
  21 + @Query("update PublicArticle set coverImg = ?1 where relateId = ?2 and articleType in (?3)")
  22 + void updateCoverImgByArticleIdAndArticleTypes(String coverImg, Integer articleId, int[] articleTypes);
  23 +
20 } 24 }
1 package com.yoho.datasync.consumer.handler.listener; 1 package com.yoho.datasync.consumer.handler.listener;
2 2
3 import com.alibaba.fastjson.JSON; 3 import com.alibaba.fastjson.JSON;
4 -import com.alibaba.fastjson.JSONException; 4 +import com.yoho.datasync.consumer.common.ContentConvertUtil;
5 import com.yoho.datasync.consumer.common.EventEnum; 5 import com.yoho.datasync.consumer.common.EventEnum;
6 import com.yoho.datasync.consumer.handler.helper.AnnotationClassFactory; 6 import com.yoho.datasync.consumer.handler.helper.AnnotationClassFactory;
7 import com.yoho.datasync.consumer.handler.mqcomponent.AbstractMqListener; 7 import com.yoho.datasync.consumer.handler.mqcomponent.AbstractMqListener;
@@ -29,6 +29,8 @@ public class GrassArticleBlockListener extends AbstractMqListener<GrassArticleBl @@ -29,6 +29,8 @@ public class GrassArticleBlockListener extends AbstractMqListener<GrassArticleBl
29 29
30 private static final Logger log = LoggerFactory.getLogger(GrassArticleBlockListener.class); 30 private static final Logger log = LoggerFactory.getLogger(GrassArticleBlockListener.class);
31 31
  32 + private static final Integer DELETE_STATUS = 2;
  33 +
32 @Resource 34 @Resource
33 private AnnotationClassFactory annotationClassFactory; 35 private AnnotationClassFactory annotationClassFactory;
34 36
@@ -38,36 +40,36 @@ public class GrassArticleBlockListener extends AbstractMqListener<GrassArticleBl @@ -38,36 +40,36 @@ public class GrassArticleBlockListener extends AbstractMqListener<GrassArticleBl
38 @Resource 40 @Resource
39 private PublicArticleBlockService publicArticleBlockService; 41 private PublicArticleBlockService publicArticleBlockService;
40 42
  43 + /**
  44 + * @param sourceObject
  45 + * @param checkResult public_article_block表的article_id字段
  46 + */
41 @Override 47 @Override
42 - protected void deleteData(GrassArticleBlock sourceObject, Object checkResult) { 48 + protected void deleteData(GrassArticleBlock sourceObject, Object checkResult) throws Exception {
43 if (sourceObject == null) 49 if (sourceObject == null)
44 return; 50 return;
45 - try {  
46 - final PublicArticleBlock targetObject = doBeforeHandler(sourceObject); 51 + final PublicArticleBlock targetObject = doBeforeHandler(sourceObject, checkResult);
47 if (targetObject == null) { 52 if (targetObject == null) {
48 log.error("convert object to PublicArticleBlock goes error ..."); 53 log.error("convert object to PublicArticleBlock goes error ...");
49 return; 54 return;
50 } 55 }
51 - publicArticleBlockService.deleteData(targetObject);  
52 - } catch (Exception e) {  
53 - log.error("doBeforeHandler goes error with sourceObject {} and exception {}", sourceObject, e);  
54 - } 56 + publicArticleBlockService.deleteData(targetObject, sourceObject.getStatus() == DELETE_STATUS);
55 } 57 }
56 58
  59 + /**
  60 + * @param sourceObject
  61 + * @param checkResult public_article_block表的article_id字段
  62 + */
57 @Override 63 @Override
58 - protected void updateData(GrassArticleBlock sourceObject, Object checkResult) { 64 + protected void updateData(GrassArticleBlock sourceObject, Object checkResult) throws Exception {
59 if (sourceObject == null) 65 if (sourceObject == null)
60 return; 66 return;
61 - try {  
62 - final PublicArticleBlock targetObject = doBeforeHandler(sourceObject); 67 + final PublicArticleBlock targetObject = doBeforeHandler(sourceObject, checkResult);
63 if (targetObject == null) { 68 if (targetObject == null) {
64 log.error("convert object to PublicArticleBlock goes error ..."); 69 log.error("convert object to PublicArticleBlock goes error ...");
65 return; 70 return;
66 } 71 }
67 - publicArticleBlockService.updateData(targetObject);  
68 - } catch (Exception e) {  
69 - log.error("doBeforeHandler goes error with sourceObject {} and exception {}", sourceObject, e);  
70 - } 72 + publicArticleBlockService.updateData(targetObject, sourceObject.getStatus() == DELETE_STATUS);
71 } 73 }
72 74
73 @Override 75 @Override
@@ -76,16 +78,14 @@ public class GrassArticleBlockListener extends AbstractMqListener<GrassArticleBl @@ -76,16 +78,14 @@ public class GrassArticleBlockListener extends AbstractMqListener<GrassArticleBl
76 } 78 }
77 79
78 /** 80 /**
79 - * 对象转换统一处理 GrassArticleBlock -> PublicArticleBlock 81 + * 校验依赖数据是否存在
80 * 82 *
81 * @param sourceObject 83 * @param sourceObject
  84 + * @param action
82 * @return 85 * @return
83 */ 86 */
84 - private PublicArticleBlock doBeforeHandler(GrassArticleBlock sourceObject) throws Exception {  
85 - /**  
86 - * 将源对象转换成目标对象  
87 - */  
88 - final PublicArticleBlock targetObject = annotationClassFactory.convertTargetObjectFromSource(sourceObject, PublicArticleBlock.class); 87 + @Override
  88 + protected Object checkData(GrassArticleBlock sourceObject, String action) {
89 /** 89 /**
90 * public_article_block表的article_id字段为grass_article表中对应的数据同步到public_article表之后的自增主键id 90 * public_article_block表的article_id字段为grass_article表中对应的数据同步到public_article表之后的自增主键id
91 * select id from public_article where relate_id=#{grass_article_block.article_id} and article_type in (1,2,4) 91 * select id from public_article where relate_id=#{grass_article_block.article_id} and article_type in (1,2,4)
@@ -95,11 +95,27 @@ public class GrassArticleBlockListener extends AbstractMqListener<GrassArticleBl @@ -95,11 +95,27 @@ public class GrassArticleBlockListener extends AbstractMqListener<GrassArticleBl
95 log.info("can not get public_article primary key with original articleId {}", sourceObject.getArticleId()); 95 log.info("can not get public_article primary key with original articleId {}", sourceObject.getArticleId());
96 return null; 96 return null;
97 } 97 }
  98 + return relatedId;
  99 + }
  100 +
  101 + /**
  102 + * 对象转换统一处理 GrassArticleBlock -> PublicArticleBlock
  103 + *
  104 + * @param sourceObject
  105 + * @param checkResult
  106 + * @return
  107 + */
  108 + private PublicArticleBlock doBeforeHandler(GrassArticleBlock sourceObject, Object checkResult) throws Exception {
  109 + /**
  110 + * 将源对象转换成目标对象
  111 + */
  112 + final PublicArticleBlock targetObject = annotationClassFactory.convertTargetObjectFromSource(sourceObject, PublicArticleBlock.class);
  113 +
98 /** 114 /**
99 * 文章内容格式转换 115 * 文章内容格式转换
100 */ 116 */
101 articleContentConvert(sourceObject, targetObject); 117 articleContentConvert(sourceObject, targetObject);
102 - targetObject.setArticleId(relatedId); 118 + targetObject.setArticleId((Integer) checkResult);
103 return targetObject; 119 return targetObject;
104 } 120 }
105 121
@@ -110,7 +126,7 @@ public class GrassArticleBlockListener extends AbstractMqListener<GrassArticleBl @@ -110,7 +126,7 @@ public class GrassArticleBlockListener extends AbstractMqListener<GrassArticleBl
110 * @param targetObject 126 * @param targetObject
111 */ 127 */
112 private void articleContentConvert(GrassArticleBlock sourceObject, PublicArticleBlock targetObject) { 128 private void articleContentConvert(GrassArticleBlock sourceObject, PublicArticleBlock targetObject) {
113 - final Map sourceJson = jsonString2Map(sourceObject.getContentData()); 129 + final Map sourceJson = ContentConvertUtil.jsonString2Map(sourceObject.getContentData());
114 if (sourceJson != null) { 130 if (sourceJson != null) {
115 final Map<String, String> map = new HashMap(); 131 final Map<String, String> map = new HashMap();
116 final Map data = (Map) sourceJson.get("data"); 132 final Map data = (Map) sourceJson.get("data");
@@ -128,28 +144,4 @@ public class GrassArticleBlockListener extends AbstractMqListener<GrassArticleBl @@ -128,28 +144,4 @@ public class GrassArticleBlockListener extends AbstractMqListener<GrassArticleBl
128 targetObject.setContentData(JSON.toJSONString(map)); 144 targetObject.setContentData(JSON.toJSONString(map));
129 } 145 }
130 } 146 }
131 -  
132 - /**  
133 - * 将JSON字符串转换成Map对象  
134 - *  
135 - * @param jsonString  
136 - * @return  
137 - */  
138 - private static Map jsonString2Map(String jsonString) {  
139 - Map result;  
140 - try {  
141 - result = JSON.parseObject(jsonString, Map.class);  
142 - } catch (JSONException e) {  
143 - return null;  
144 - }  
145 - for (Object key : result.keySet()) {  
146 - final Object innerMap = jsonString2Map((String) result.get(key));  
147 - if (innerMap != null)  
148 - result.put(key, innerMap);  
149 - else  
150 - result.put(key, result.get(key));  
151 - }  
152 - return result;  
153 - }  
154 -  
155 } 147 }
@@ -37,11 +37,18 @@ public class GrassArticleLabelListener extends AbstractMqListener<GrassArticleLa @@ -37,11 +37,18 @@ public class GrassArticleLabelListener extends AbstractMqListener<GrassArticleLa
37 37
38 private static final Logger log = LoggerFactory.getLogger(GrassArticleLabelListener.class); 38 private static final Logger log = LoggerFactory.getLogger(GrassArticleLabelListener.class);
39 39
  40 + /**
  41 + * @param sourceObject
  42 + * @param checkResult 数组
  43 + * 0: public_article_label 表的 article_id 字段
  44 + * 1: public_article_label 表的 label_id 字段
  45 + * @throws Exception
  46 + */
40 @Override 47 @Override
41 protected void deleteData(GrassArticleLabel sourceObject, Object checkResult) throws Exception { 48 protected void deleteData(GrassArticleLabel sourceObject, Object checkResult) throws Exception {
42 if (sourceObject == null) 49 if (sourceObject == null)
43 return; 50 return;
44 - final PublicArticleLabel targetObject = doBeforeHandler(sourceObject); 51 + final PublicArticleLabel targetObject = doBeforeHandler(sourceObject, checkResult);
45 if (targetObject == null) { 52 if (targetObject == null) {
46 log.error("convert object to PublicArticleLabel goes error ..."); 53 log.error("convert object to PublicArticleLabel goes error ...");
47 return; 54 return;
@@ -49,11 +56,18 @@ public class GrassArticleLabelListener extends AbstractMqListener<GrassArticleLa @@ -49,11 +56,18 @@ public class GrassArticleLabelListener extends AbstractMqListener<GrassArticleLa
49 publicArticleLabelService.deleteData(targetObject); 56 publicArticleLabelService.deleteData(targetObject);
50 } 57 }
51 58
  59 + /**
  60 + * @param sourceObject
  61 + * @param checkResult 数组
  62 + * 0: public_article_label 表的 article_id 字段
  63 + * 1: public_article_label 表的 label_id 字段
  64 + * @throws Exception
  65 + */
52 @Override 66 @Override
53 protected void updateData(GrassArticleLabel sourceObject, Object checkResult) throws Exception { 67 protected void updateData(GrassArticleLabel sourceObject, Object checkResult) throws Exception {
54 if (sourceObject == null) 68 if (sourceObject == null)
55 return; 69 return;
56 - final PublicArticleLabel targetObject = doBeforeHandler(sourceObject); 70 + final PublicArticleLabel targetObject = doBeforeHandler(sourceObject, checkResult);
57 if (targetObject == null) { 71 if (targetObject == null) {
58 log.error("convert object to PublicArticleLabel goes error ..."); 72 log.error("convert object to PublicArticleLabel goes error ...");
59 return; 73 return;
@@ -67,14 +81,14 @@ public class GrassArticleLabelListener extends AbstractMqListener<GrassArticleLa @@ -67,14 +81,14 @@ public class GrassArticleLabelListener extends AbstractMqListener<GrassArticleLa
67 } 81 }
68 82
69 /** 83 /**
70 - * 对象转换统一处理 GrassArticleLabel -> PublicArticleLabel 84 + * 获取依赖信息
71 * 85 *
72 * @param sourceObject 86 * @param sourceObject
  87 + * @param action
73 * @return 88 * @return
74 */ 89 */
75 - private PublicArticleLabel doBeforeHandler(GrassArticleLabel sourceObject) throws Exception {  
76 -  
77 - final PublicArticleLabel targetObject = annotationClassFactory.convertTargetObjectFromSource(sourceObject, PublicArticleLabel.class); 90 + @Override
  91 + protected Object checkData(GrassArticleLabel sourceObject, String action) {
78 /** 92 /**
79 * public_article_label 表的 article_id 字段为 grass_article_label.article_id 在 grass_article 表中对应的数据同步到 public_article 表之后的自增主键id 93 * public_article_label 表的 article_id 字段为 grass_article_label.article_id 在 grass_article 表中对应的数据同步到 public_article 表之后的自增主键id
80 * select id from public_article where relate_id=#{grass_article_label.article_id} and article_type in (1,2,4) 94 * select id from public_article where relate_id=#{grass_article_label.article_id} and article_type in (1,2,4)
@@ -84,12 +98,30 @@ public class GrassArticleLabelListener extends AbstractMqListener<GrassArticleLa @@ -84,12 +98,30 @@ public class GrassArticleLabelListener extends AbstractMqListener<GrassArticleLa
84 log.info("can not get public_article primary key with articleId {}", sourceObject.getArticleId()); 98 log.info("can not get public_article primary key with articleId {}", sourceObject.getArticleId());
85 return null; 99 return null;
86 } 100 }
87 - targetObject.setArticleId(trueId);  
88 /** 101 /**
89 * public_article_label 表的 label_id 字段为 grass_article_label.label_id 在 grass_label 表中对应的数据同步到 public_label 表之后的自增主键id 102 * public_article_label 表的 label_id 字段为 grass_article_label.label_id 在 grass_label 表中对应的数据同步到 public_label 表之后的自增主键id
90 * select id from public_label where relate_id=#{grass_article_label.article_id} and src_channel =1 103 * select id from public_label where relate_id=#{grass_article_label.article_id} and src_channel =1
91 */ 104 */
92 // TODO : wait 暂无对应接口 105 // TODO : wait 暂无对应接口
  106 + Integer[] result = new Integer[2];
  107 + result[0] = trueId;
  108 + return result;
  109 + }
  110 +
  111 + /**
  112 + * 对象转换统一处理 GrassArticleLabel -> PublicArticleLabel
  113 + *
  114 + * @param sourceObject
  115 + * @param checkResult
  116 + * @return
  117 + */
  118 + private PublicArticleLabel doBeforeHandler(GrassArticleLabel sourceObject, Object checkResult) throws Exception {
  119 +
  120 + final PublicArticleLabel targetObject = annotationClassFactory.convertTargetObjectFromSource(sourceObject, PublicArticleLabel.class);
  121 +
  122 + targetObject.setArticleId(((Integer[]) checkResult)[0]);
  123 + targetObject.setLabelId(((Integer[]) checkResult)[1]);
  124 +
93 /** 125 /**
94 * 种草社区洗过来的数据 public_article_label.src_channel 字段值为 1 126 * 种草社区洗过来的数据 public_article_label.src_channel 字段值为 1
95 */ 127 */
1 package com.yoho.datasync.consumer.handler.listener; 1 package com.yoho.datasync.consumer.handler.listener;
2 2
  3 +import com.yoho.datasync.consumer.common.ContentConvertUtil;
3 import com.yoho.datasync.consumer.common.EventEnum; 4 import com.yoho.datasync.consumer.common.EventEnum;
4 import com.yoho.datasync.consumer.handler.helper.AnnotationClassFactory; 5 import com.yoho.datasync.consumer.handler.helper.AnnotationClassFactory;
5 import com.yoho.datasync.consumer.handler.mqcomponent.AbstractMqListener; 6 import com.yoho.datasync.consumer.handler.mqcomponent.AbstractMqListener;
  7 +import com.yoho.datasync.consumer.service.PublicArticleBlockService;
6 import com.yoho.datasync.consumer.service.PublicArticleService; 8 import com.yoho.datasync.consumer.service.PublicArticleService;
7 import com.yoho.datasync.core.base.annotation.MqConsumerListerner; 9 import com.yoho.datasync.core.base.annotation.MqConsumerListerner;
  10 +import com.yoho.datasync.core.base.constant.DatasyncConstant;
8 import com.yoho.datasync.core.base.model.yh_grass.GrassArticle; 11 import com.yoho.datasync.core.base.model.yh_grass.GrassArticle;
9 import com.yoho.datasync.core.base.model.yh_pcms.PublicArticle; 12 import com.yoho.datasync.core.base.model.yh_pcms.PublicArticle;
10 import com.yoho.datasync.core.base.model.yh_pcms.PublicArticleAudit; 13 import com.yoho.datasync.core.base.model.yh_pcms.PublicArticleAudit;
@@ -13,6 +16,7 @@ import org.slf4j.LoggerFactory; @@ -13,6 +16,7 @@ import org.slf4j.LoggerFactory;
13 import org.springframework.stereotype.Component; 16 import org.springframework.stereotype.Component;
14 17
15 import javax.annotation.Resource; 18 import javax.annotation.Resource;
  19 +import java.util.Map;
16 20
17 /*** 21 /***
18 * @author peuei 22 * @author peuei
@@ -29,6 +33,9 @@ public class GrassArticleListener extends AbstractMqListener<GrassArticle> { @@ -29,6 +33,9 @@ public class GrassArticleListener extends AbstractMqListener<GrassArticle> {
29 @Resource 33 @Resource
30 private PublicArticleService publicArticleService; 34 private PublicArticleService publicArticleService;
31 35
  36 + @Resource
  37 + private PublicArticleBlockService publicArticleBlockService;
  38 +
32 private static final Logger log = LoggerFactory.getLogger(GrassArticleListener.class); 39 private static final Logger log = LoggerFactory.getLogger(GrassArticleListener.class);
33 40
34 private static final Integer UNCHECKED = 1; 41 private static final Integer UNCHECKED = 1;
@@ -38,30 +45,21 @@ public class GrassArticleListener extends AbstractMqListener<GrassArticle> { @@ -38,30 +45,21 @@ public class GrassArticleListener extends AbstractMqListener<GrassArticle> {
38 private static final Integer DRAFT = 0; 45 private static final Integer DRAFT = 0;
39 46
40 @Override 47 @Override
41 - protected void deleteData(GrassArticle sourceObject, Object checkResult) { 48 + protected void deleteData(GrassArticle sourceObject, Object checkResult) throws Exception {
42 if (sourceObject == null) 49 if (sourceObject == null)
43 return; 50 return;
44 - try {  
45 final PublicArticle targetObject = beforeHandlerPlugFirst(sourceObject); 51 final PublicArticle targetObject = beforeHandlerPlugFirst(sourceObject);
46 publicArticleService.deleteData(targetObject); 52 publicArticleService.deleteData(targetObject);
47 - } catch (Exception e) {  
48 - log.error("deleteData goes error, with sourceObject {} and exception {}", sourceObject.toString(), e);  
49 - }  
50 } 53 }
51 54
52 55
53 @Override 56 @Override
54 - protected void updateData(GrassArticle sourceObject, Object checkResult) { 57 + protected void updateData(GrassArticle sourceObject, Object checkResult) throws Exception {
55 if (sourceObject == null) 58 if (sourceObject == null)
56 return; 59 return;
57 - try {  
58 final PublicArticle publicArticle = beforeHandlerPlugFirst(sourceObject); 60 final PublicArticle publicArticle = beforeHandlerPlugFirst(sourceObject);
59 final PublicArticleAudit publicArticleAudit = beforeHandlerPlugSecond(sourceObject); 61 final PublicArticleAudit publicArticleAudit = beforeHandlerPlugSecond(sourceObject);
60 - publicArticleService.updateData(publicArticle, publicArticleAudit);  
61 - } catch (Exception e) {  
62 - log.error("deleteData goes error, with sourceObject {} and exception {}", sourceObject.toString(), e);  
63 - }  
64 - 62 + publicArticleService.updateData(publicArticle, publicArticleAudit, checkResult);
65 } 63 }
66 64
67 @Override 65 @Override
@@ -70,6 +68,39 @@ public class GrassArticleListener extends AbstractMqListener<GrassArticle> { @@ -70,6 +68,39 @@ public class GrassArticleListener extends AbstractMqListener<GrassArticle> {
70 } 68 }
71 69
72 /** 70 /**
  71 + * 获取 cover_img
  72 + * public_article.cover_img 字段需要取 grass_article_block 表中content_data字段中的src值进行更新
  73 + * select content_data from grass_article_block where template_key='image' order by order_by asc limit 1
  74 + * 文章id关联关系为:grass_article_block.articleId = public_article.relate_id and public_article.article_type in (1,2,4);
  75 + *
  76 + * @param sourceObject
  77 + * @return
  78 + */
  79 + @Override
  80 + protected Object checkData(GrassArticle sourceObject, String action) {
  81 + if (DatasyncConstant.ACTION_UPDATE.equals(action)) {
  82 + // 更新操作才去查找 cover_img
  83 + Integer trueId = publicArticleService.getByArticleIdAndType(sourceObject.getId());
  84 + if (trueId == null) {
  85 + return null;
  86 + }
  87 + String contentData = publicArticleBlockService.findContentData(trueId);
  88 + if (contentData == null) {
  89 + return null;
  90 + }
  91 + try {
  92 + Map map = ContentConvertUtil.jsonString2Map(contentData);
  93 + String coverImg = (String) ((Map) (map.get("data"))).get("src");
  94 + return coverImg;
  95 + } catch (Exception e) {
  96 + return null;
  97 + }
  98 + }
  99 + // 如果不是更新操作,直接返回
  100 + return sourceObject;
  101 + }
  102 +
  103 + /**
73 * 对象转换统一处理 GrassArticle -> PublicArticle 104 * 对象转换统一处理 GrassArticle -> PublicArticle
74 * 105 *
75 * @param sourceObject 106 * @param sourceObject
@@ -95,7 +126,7 @@ public class GrassArticleListener extends AbstractMqListener<GrassArticle> { @@ -95,7 +126,7 @@ public class GrassArticleListener extends AbstractMqListener<GrassArticle> {
95 * @return 126 * @return
96 * @throws Exception 127 * @throws Exception
97 */ 128 */
98 - private PublicArticleAudit beforeHandlerPlugSecond(GrassArticle sourceObject) throws Exception { 129 + private PublicArticleAudit beforeHandlerPlugSecond(GrassArticle sourceObject) {
99 final PublicArticleAudit targetObject = new PublicArticleAudit(); 130 final PublicArticleAudit targetObject = new PublicArticleAudit();
100 /** 131 /**
101 * grass_article.auth_status(0 未审核, 1 审核通过, 2 审核未通过) 132 * grass_article.auth_status(0 未审核, 1 审核通过, 2 审核未通过)
@@ -115,8 +146,6 @@ public class GrassArticleListener extends AbstractMqListener<GrassArticle> { @@ -115,8 +146,6 @@ public class GrassArticleListener extends AbstractMqListener<GrassArticle> {
115 targetObject.setAuditAccount(sourceObject.getAuthorizeAccount()); 146 targetObject.setAuditAccount(sourceObject.getAuthorizeAccount());
116 targetObject.setAuditTime(sourceObject.getAuthTime()); 147 targetObject.setAuditTime(sourceObject.getAuthTime());
117 /** 148 /**
118 - * CAUTION : 新增的时候没办法 -_-  
119 - *  
120 * public_article_audit 表中的 article_id 字段为种草文章同步到公共库 public_article 表中的自增id字段 149 * public_article_audit 表中的 article_id 字段为种草文章同步到公共库 public_article 表中的自增id字段
121 * select id from public_article where relate_id=#{grass_article.article_id} and article_type in (1,2,4); 150 * select id from public_article where relate_id=#{grass_article.article_id} and article_type in (1,2,4);
122 */ 151 */
@@ -16,7 +16,7 @@ import org.springframework.stereotype.Component; @@ -16,7 +16,7 @@ import org.springframework.stereotype.Component;
16 import javax.annotation.Resource; 16 import javax.annotation.Resource;
17 17
18 @Component 18 @Component
19 -@MqConsumerListerner(dbName = "yh_grass",tableName = "grass_article_praise") 19 +@MqConsumerListerner(dbName = "yh_grass", tableName = "grass_article_praise")
20 public class GrassArticlePraiseListener extends AbstractMqListener<GrassArticlePraise> { 20 public class GrassArticlePraiseListener extends AbstractMqListener<GrassArticlePraise> {
21 21
22 @Resource 22 @Resource
@@ -31,34 +31,34 @@ public class GrassArticlePraiseListener extends AbstractMqListener<GrassArticleP @@ -31,34 +31,34 @@ public class GrassArticlePraiseListener extends AbstractMqListener<GrassArticleP
31 private static final Logger logger = LoggerFactory.getLogger(GrassArticlePraiseListener.class); 31 private static final Logger logger = LoggerFactory.getLogger(GrassArticlePraiseListener.class);
32 32
33 @Override 33 @Override
34 - protected void deleteData(GrassArticlePraise sourceObject , Object checkResult) throws Exception { 34 + protected void deleteData(GrassArticlePraise sourceObject, Object checkResult) throws Exception {
35 PublicUserPraise publicUserPraise = annotationClassFactory.convertTargetObjectFromSource 35 PublicUserPraise publicUserPraise = annotationClassFactory.convertTargetObjectFromSource
36 - (sourceObject,PublicUserPraise.class);  
37 - if(publicUserPraise == null){ 36 + (sourceObject, PublicUserPraise.class);
  37 + if (publicUserPraise == null) {
38 logger.error("deleteData failed , publicUserPraise is null"); 38 logger.error("deleteData failed , publicUserPraise is null");
39 return; 39 return;
40 } 40 }
41 //public_user_praise.target_id取值:select id from public_article where relate_id = 41 //public_user_praise.target_id取值:select id from public_article where relate_id =
42 // #{grass_article_praise.article_id} and article_type in (1,2,4); 42 // #{grass_article_praise.article_id} and article_type in (1,2,4);
43 - publicUserPraise.setTargetId((Integer)checkResult); 43 + publicUserPraise.setTargetId((Integer) checkResult);
44 publicUserPraise.setPraiseType(ServiceConstant.Public_User_Phraise.ARTICLE_PHRAISE); 44 publicUserPraise.setPraiseType(ServiceConstant.Public_User_Phraise.ARTICLE_PHRAISE);
45 praiseService.deletePublicUserPraise(publicUserPraise); 45 praiseService.deletePublicUserPraise(publicUserPraise);
46 } 46 }
47 47
48 @Override 48 @Override
49 - protected void updateData(GrassArticlePraise sourceObject , Object checkResult) throws Exception { 49 + protected void updateData(GrassArticlePraise sourceObject, Object checkResult) throws Exception {
50 PublicUserPraise publicUserPraise = annotationClassFactory.convertTargetObjectFromSource 50 PublicUserPraise publicUserPraise = annotationClassFactory.convertTargetObjectFromSource
51 - (sourceObject,PublicUserPraise.class);  
52 - if(publicUserPraise == null){ 51 + (sourceObject, PublicUserPraise.class);
  52 + if (publicUserPraise == null) {
53 logger.error("updateData failed , publicUserPraise is null"); 53 logger.error("updateData failed , publicUserPraise is null");
54 return; 54 return;
55 } 55 }
56 //public_user_praise.target_id取值:select id from public_article where relate_id = 56 //public_user_praise.target_id取值:select id from public_article where relate_id =
57 // #{grass_article_praise.article_id} and article_type in (1,2,4); 57 // #{grass_article_praise.article_id} and article_type in (1,2,4);
58 - publicUserPraise.setTargetId((Integer)checkResult); 58 + publicUserPraise.setTargetId((Integer) checkResult);
59 //grass_article_praise.status(0:已点赞,1:已取消)和public_user_praise.status(1-已点赞,2-已取消)状态转换 59 //grass_article_praise.status(0:已点赞,1:已取消)和public_user_praise.status(1-已点赞,2-已取消)状态转换
60 - if(sourceObject.getStatus() != null){  
61 - switch (sourceObject.getStatus()){ 60 + if (sourceObject.getStatus() != null) {
  61 + switch (sourceObject.getStatus()) {
62 case ServiceConstant.Grass_Article_Phraise.CANCELED_STATUS: 62 case ServiceConstant.Grass_Article_Phraise.CANCELED_STATUS:
63 publicUserPraise.setStatus(ServiceConstant.Public_User_Phraise.CANCELED_STATUS); 63 publicUserPraise.setStatus(ServiceConstant.Public_User_Phraise.CANCELED_STATUS);
64 break; 64 break;
@@ -78,7 +78,7 @@ public class GrassArticlePraiseListener extends AbstractMqListener<GrassArticleP @@ -78,7 +78,7 @@ public class GrassArticlePraiseListener extends AbstractMqListener<GrassArticleP
78 } 78 }
79 79
80 @Override 80 @Override
81 - protected Object checkData(GrassArticlePraise sourceObject) { 81 + protected Object checkData(GrassArticlePraise sourceObject, String action) {
82 return publicArticleService.findArticleIdByRelateIdInArticleTypes(sourceObject.getArticleId(), 82 return publicArticleService.findArticleIdByRelateIdInArticleTypes(sourceObject.getArticleId(),
83 ServiceConstant.articleTypes); 83 ServiceConstant.articleTypes);
84 } 84 }
@@ -27,6 +27,8 @@ public class GrassArticleProductListener extends AbstractMqListener<GrassArticle @@ -27,6 +27,8 @@ public class GrassArticleProductListener extends AbstractMqListener<GrassArticle
27 27
28 private static final Integer GRASS_SRC_CHANNEL = 1; 28 private static final Integer GRASS_SRC_CHANNEL = 1;
29 29
  30 + private static final Integer DELETE_STATUS = 2;
  31 +
30 @Resource 32 @Resource
31 private PublicArticleService publicArticleService; 33 private PublicArticleService publicArticleService;
32 34
@@ -36,29 +38,39 @@ public class GrassArticleProductListener extends AbstractMqListener<GrassArticle @@ -36,29 +38,39 @@ public class GrassArticleProductListener extends AbstractMqListener<GrassArticle
36 @Resource 38 @Resource
37 private PublicArticleProductService publicArticleProductService; 39 private PublicArticleProductService publicArticleProductService;
38 40
  41 + /**
  42 + * @param sourceObject
  43 + * @param checkResult public_article_product 表的 article_id 字段
  44 + * @throws Exception
  45 + */
39 @Override 46 @Override
40 - protected void deleteData(GrassArticleProduct sourceObject,Object checkResult) throws Exception { 47 + protected void deleteData(GrassArticleProduct sourceObject, Object checkResult) throws Exception {
41 if (sourceObject == null) 48 if (sourceObject == null)
42 return; 49 return;
43 - final PublicArticleProduct targetObject = doBeforeHandler(sourceObject); 50 + final PublicArticleProduct targetObject = doBeforeHandler(sourceObject, checkResult);
44 if (targetObject == null) { 51 if (targetObject == null) {
45 log.error("convert object to PublicArticleProduct goes error ..."); 52 log.error("convert object to PublicArticleProduct goes error ...");
46 return; 53 return;
47 } 54 }
48 - publicArticleProductService.deleteData(targetObject); 55 + publicArticleProductService.deleteData(targetObject, sourceObject.getStatus() == DELETE_STATUS);
49 } 56 }
50 57
51 58
  59 + /**
  60 + * @param sourceObject
  61 + * @param checkResult public_article_product 表的 article_id 字段
  62 + * @throws Exception
  63 + */
52 @Override 64 @Override
53 - protected void updateData(GrassArticleProduct sourceObject,Object checkResult) throws Exception { 65 + protected void updateData(GrassArticleProduct sourceObject, Object checkResult) throws Exception {
54 if (sourceObject == null) 66 if (sourceObject == null)
55 return; 67 return;
56 - final PublicArticleProduct targetObject = doBeforeHandler(sourceObject); 68 + final PublicArticleProduct targetObject = doBeforeHandler(sourceObject, checkResult);
57 if (targetObject == null) { 69 if (targetObject == null) {
58 log.error("convert object to PublicArticleProduct goes error ..."); 70 log.error("convert object to PublicArticleProduct goes error ...");
59 return; 71 return;
60 } 72 }
61 - publicArticleProductService.updateData(targetObject); 73 + publicArticleProductService.updateData(targetObject, sourceObject.getStatus() == DELETE_STATUS);
62 } 74 }
63 75
64 @Override 76 @Override
@@ -66,15 +78,8 @@ public class GrassArticleProductListener extends AbstractMqListener<GrassArticle @@ -66,15 +78,8 @@ public class GrassArticleProductListener extends AbstractMqListener<GrassArticle
66 return EventEnum.GRASS_ARTICLE_PRODUCT_UPDATE; 78 return EventEnum.GRASS_ARTICLE_PRODUCT_UPDATE;
67 } 79 }
68 80
69 - /**  
70 - * 统一对象转换 GrassArticleProduct -> PublicArticleProduct  
71 - *  
72 - * @param sourceObject  
73 - * @return  
74 - */  
75 - private PublicArticleProduct doBeforeHandler(GrassArticleProduct sourceObject) throws Exception {  
76 -  
77 - final PublicArticleProduct targetObject = annotationClassFactory.convertTargetObjectFromSource(sourceObject, PublicArticleProduct.class); 81 + @Override
  82 + protected Object checkData(GrassArticleProduct sourceObject, String action) {
78 /** 83 /**
79 * public_article_product 表的 article_id 字段为 grass_article_product.article_id 在 grass_article 表中对应的数据同步到 public_article 表之后的自增主键id 84 * public_article_product 表的 article_id 字段为 grass_article_product.article_id 在 grass_article 表中对应的数据同步到 public_article 表之后的自增主键id
80 * select id from public_article where relate_id=#{grass_article_product.article_id} and article_type in (1,2,4); 85 * select id from public_article where relate_id=#{grass_article_product.article_id} and article_type in (1,2,4);
@@ -84,7 +89,21 @@ public class GrassArticleProductListener extends AbstractMqListener<GrassArticle @@ -84,7 +89,21 @@ public class GrassArticleProductListener extends AbstractMqListener<GrassArticle
84 log.info("can not get public_article primary key with articleId {}", sourceObject.getArticleId()); 89 log.info("can not get public_article primary key with articleId {}", sourceObject.getArticleId());
85 return null; 90 return null;
86 } 91 }
87 - targetObject.setArticleId(trueId); 92 + return trueId;
  93 + }
  94 +
  95 + /**
  96 + * 统一对象转换 GrassArticleProduct -> PublicArticleProduct
  97 + *
  98 + * @param sourceObject
  99 + * @param checkResult
  100 + * @return
  101 + */
  102 + private PublicArticleProduct doBeforeHandler(GrassArticleProduct sourceObject, Object checkResult) throws Exception {
  103 +
  104 + final PublicArticleProduct targetObject = annotationClassFactory.convertTargetObjectFromSource(sourceObject, PublicArticleProduct.class);
  105 +
  106 + targetObject.setArticleId((Integer) checkResult);
88 /** 107 /**
89 * 种草社区洗过来的数据public_article_label.src_channel字段值为 1 108 * 种草社区洗过来的数据public_article_label.src_channel字段值为 1
90 */ 109 */
@@ -16,7 +16,7 @@ import org.springframework.stereotype.Component; @@ -16,7 +16,7 @@ import org.springframework.stereotype.Component;
16 import javax.annotation.Resource; 16 import javax.annotation.Resource;
17 17
18 @Component 18 @Component
19 -@MqConsumerListerner(dbName = "yh_grass",tableName = "grass_comment_praise") 19 +@MqConsumerListerner(dbName = "yh_grass", tableName = "grass_comment_praise")
20 public class GrassCommentPraiseListener extends AbstractMqListener<GrassCommentPraise> { 20 public class GrassCommentPraiseListener extends AbstractMqListener<GrassCommentPraise> {
21 21
22 @Resource 22 @Resource
@@ -31,35 +31,35 @@ public class GrassCommentPraiseListener extends AbstractMqListener<GrassCommentP @@ -31,35 +31,35 @@ public class GrassCommentPraiseListener extends AbstractMqListener<GrassCommentP
31 private static final Logger logger = LoggerFactory.getLogger(GrassCommentPraiseListener.class); 31 private static final Logger logger = LoggerFactory.getLogger(GrassCommentPraiseListener.class);
32 32
33 @Override 33 @Override
34 - protected void deleteData(GrassCommentPraise sourceObject , Object checkResult) throws Exception { 34 + protected void deleteData(GrassCommentPraise sourceObject, Object checkResult) throws Exception {
35 PublicUserPraise publicUserPraise = annotationClassFactory.convertTargetObjectFromSource(sourceObject, 35 PublicUserPraise publicUserPraise = annotationClassFactory.convertTargetObjectFromSource(sourceObject,
36 PublicUserPraise.class); 36 PublicUserPraise.class);
37 - if(publicUserPraise == null){ 37 + if (publicUserPraise == null) {
38 logger.error("deleteData failed , publicUserPraise is null"); 38 logger.error("deleteData failed , publicUserPraise is null");
39 return; 39 return;
40 } 40 }
41 //public_user_praise.target_id取值:select id from public_article where relate_id = 41 //public_user_praise.target_id取值:select id from public_article where relate_id =
42 // #{grass_comment_praise.comment_id} and article_type in (1,2,4); 42 // #{grass_comment_praise.comment_id} and article_type in (1,2,4);
43 - publicUserPraise.setTargetId((Integer)checkResult); 43 + publicUserPraise.setTargetId((Integer) checkResult);
44 publicUserPraise.setPraiseType(ServiceConstant.Public_User_Phraise.COMMENT_PHRAISE); 44 publicUserPraise.setPraiseType(ServiceConstant.Public_User_Phraise.COMMENT_PHRAISE);
45 publicUserPraise.setSrcChannel(ServiceConstant.SRCCHANNEL_TYPE.YOHO_GRASS); 45 publicUserPraise.setSrcChannel(ServiceConstant.SRCCHANNEL_TYPE.YOHO_GRASS);
46 praiseService.deletePublicUserPraise(publicUserPraise); 46 praiseService.deletePublicUserPraise(publicUserPraise);
47 } 47 }
48 48
49 @Override 49 @Override
50 - protected void updateData(GrassCommentPraise sourceObject , Object checkResult) throws Exception {  
51 - if(sourceObject == null){ 50 + protected void updateData(GrassCommentPraise sourceObject, Object checkResult) throws Exception {
  51 + if (sourceObject == null) {
52 return; 52 return;
53 } 53 }
54 - PublicUserPraise publicUserPraise = annotationClassFactory.convertTargetObjectFromSource(sourceObject,PublicUserPraise.class);  
55 - if(publicUserPraise == null){ 54 + PublicUserPraise publicUserPraise = annotationClassFactory.convertTargetObjectFromSource(sourceObject, PublicUserPraise.class);
  55 + if (publicUserPraise == null) {
56 logger.error("updateData failed , publicUserPraise is null"); 56 logger.error("updateData failed , publicUserPraise is null");
57 return; 57 return;
58 } 58 }
59 - publicUserPraise.setTargetId((Integer)checkResult); 59 + publicUserPraise.setTargetId((Integer) checkResult);
60 //grass_article_praise.status(0:已点赞,1:已取消)和public_user_praise.status(1-已点赞,2-已取消)状态转换 60 //grass_article_praise.status(0:已点赞,1:已取消)和public_user_praise.status(1-已点赞,2-已取消)状态转换
61 - if(sourceObject.getStatus() != null){  
62 - switch (sourceObject.getStatus()){ 61 + if (sourceObject.getStatus() != null) {
  62 + switch (sourceObject.getStatus()) {
63 case ServiceConstant.Grass_Article_Phraise.CANCELED_STATUS: 63 case ServiceConstant.Grass_Article_Phraise.CANCELED_STATUS:
64 publicUserPraise.setStatus(ServiceConstant.Public_User_Phraise.CANCELED_STATUS); 64 publicUserPraise.setStatus(ServiceConstant.Public_User_Phraise.CANCELED_STATUS);
65 break; 65 break;
@@ -74,7 +74,7 @@ public class GrassCommentPraiseListener extends AbstractMqListener<GrassCommentP @@ -74,7 +74,7 @@ public class GrassCommentPraiseListener extends AbstractMqListener<GrassCommentP
74 } 74 }
75 75
76 @Override 76 @Override
77 - protected Object checkData(GrassCommentPraise sourceObject) { 77 + protected Object checkData(GrassCommentPraise sourceObject, String action) {
78 return publicArticleService.findArticleIdByRelateIdInArticleTypes(sourceObject.getCommentId(), 78 return publicArticleService.findArticleIdByRelateIdInArticleTypes(sourceObject.getCommentId(),
79 ServiceConstant.articleTypes); 79 ServiceConstant.articleTypes);
80 } 80 }
@@ -16,7 +16,7 @@ import org.springframework.stereotype.Component; @@ -16,7 +16,7 @@ import org.springframework.stereotype.Component;
16 import javax.annotation.Resource; 16 import javax.annotation.Resource;
17 17
18 @Component 18 @Component
19 -@MqConsumerListerner(dbName = "yh_grass",tableName = "grass_user_attention") 19 +@MqConsumerListerner(dbName = "yh_grass", tableName = "grass_user_attention")
20 public class GrassUserAttentionListener extends AbstractMqListener<GrassUserAttention> { 20 public class GrassUserAttentionListener extends AbstractMqListener<GrassUserAttention> {
21 21
22 @Resource 22 @Resource
@@ -31,19 +31,19 @@ public class GrassUserAttentionListener extends AbstractMqListener<GrassUserAtte @@ -31,19 +31,19 @@ public class GrassUserAttentionListener extends AbstractMqListener<GrassUserAtte
31 private static final Logger logger = LoggerFactory.getLogger(GrassUserAttentionListener.class); 31 private static final Logger logger = LoggerFactory.getLogger(GrassUserAttentionListener.class);
32 32
33 @Override 33 @Override
34 - protected void deleteData(GrassUserAttention sourceObject,Object checkResult) throws Exception { 34 + protected void deleteData(GrassUserAttention sourceObject, Object checkResult) throws Exception {
35 PublicUserAttention publicUserAttention = annotationClassFactory.convertTargetObjectFromSource(sourceObject, 35 PublicUserAttention publicUserAttention = annotationClassFactory.convertTargetObjectFromSource(sourceObject,
36 PublicUserAttention.class); 36 PublicUserAttention.class);
37 - if(publicUserAttention == null){ 37 + if (publicUserAttention == null) {
38 logger.error("deleteData failed , publicUserAttention is null"); 38 logger.error("deleteData failed , publicUserAttention is null");
39 throw new Exception("GrassUserAttentionListener deleteData failed , publicUserAttention is null"); 39 throw new Exception("GrassUserAttentionListener deleteData failed , publicUserAttention is null");
40 } 40 }
41 //grass_user_attention.attention_type取0时public_user_attention.target_id取值: 41 //grass_user_attention.attention_type取0时public_user_attention.target_id取值:
42 //select id from public_topic where relate_id = #{grass_user_attention.topic_id} and src_channel = 1 42 //select id from public_topic where relate_id = #{grass_user_attention.topic_id} and src_channel = 1
43 Integer targetId = null; 43 Integer targetId = null;
44 - switch (sourceObject.getAttentionType()){  
45 - case ServiceConstant.Grass_User_Attention.ATTENTION_TYPE_TOPIC :  
46 - targetId = (Integer)checkResult; 44 + switch (sourceObject.getAttentionType()) {
  45 + case ServiceConstant.Grass_User_Attention.ATTENTION_TYPE_TOPIC:
  46 + targetId = (Integer) checkResult;
47 publicUserAttention.setAttentionType(ServiceConstant.Public_User_Attention.ATTENTION_TYPE_TOPIC); 47 publicUserAttention.setAttentionType(ServiceConstant.Public_User_Attention.ATTENTION_TYPE_TOPIC);
48 break; 48 break;
49 case ServiceConstant.Grass_User_Attention.ATTENTION_TYPE_USER: 49 case ServiceConstant.Grass_User_Attention.ATTENTION_TYPE_USER:
@@ -55,28 +55,28 @@ public class GrassUserAttentionListener extends AbstractMqListener<GrassUserAtte @@ -55,28 +55,28 @@ public class GrassUserAttentionListener extends AbstractMqListener<GrassUserAtte
55 } 55 }
56 56
57 @Override 57 @Override
58 - protected void updateData(GrassUserAttention sourceObject,Object checkResult) throws Exception { 58 + protected void updateData(GrassUserAttention sourceObject, Object checkResult) throws Exception {
59 PublicUserAttention publicUserAttention = annotationClassFactory.convertTargetObjectFromSource(sourceObject, 59 PublicUserAttention publicUserAttention = annotationClassFactory.convertTargetObjectFromSource(sourceObject,
60 PublicUserAttention.class); 60 PublicUserAttention.class);
61 - if(publicUserAttention == null){ 61 + if (publicUserAttention == null) {
62 logger.error("updateData failed , publicUserAttention is null"); 62 logger.error("updateData failed , publicUserAttention is null");
63 return; 63 return;
64 } 64 }
65 //关注状态的转换grass_user_attention.status(0 关注,1 取消) 65 //关注状态的转换grass_user_attention.status(0 关注,1 取消)
66 // public_user_attention.status(0-已取消 1-已关注 2-互相关注) 66 // public_user_attention.status(0-已取消 1-已关注 2-互相关注)
67 - switch (sourceObject.getStatus()){  
68 - case ServiceConstant.Grass_User_Attention.ATTENTION_STATUS : 67 + switch (sourceObject.getStatus()) {
  68 + case ServiceConstant.Grass_User_Attention.ATTENTION_STATUS:
69 publicUserAttention.setAttentionType(ServiceConstant.Public_User_Attention.ATTENTION_STATUS); 69 publicUserAttention.setAttentionType(ServiceConstant.Public_User_Attention.ATTENTION_STATUS);
70 break; 70 break;
71 - case ServiceConstant.Grass_User_Attention.CANCEL_STATUS : 71 + case ServiceConstant.Grass_User_Attention.CANCEL_STATUS:
72 publicUserAttention.setAttentionType(ServiceConstant.Public_User_Attention.CANCEL_STATUS); 72 publicUserAttention.setAttentionType(ServiceConstant.Public_User_Attention.CANCEL_STATUS);
73 } 73 }
74 //grass_user_attention.attention_type取0时public_user_attention.target_id取值: 74 //grass_user_attention.attention_type取0时public_user_attention.target_id取值:
75 //select id from public_topic where relate_id = #{grass_user_attention.topic_id} and src_channel = 1 75 //select id from public_topic where relate_id = #{grass_user_attention.topic_id} and src_channel = 1
76 Integer targetId = null; 76 Integer targetId = null;
77 - switch (sourceObject.getAttentionType()){  
78 - case ServiceConstant.Grass_User_Attention.ATTENTION_TYPE_TOPIC :  
79 - targetId = (Integer)checkResult; 77 + switch (sourceObject.getAttentionType()) {
  78 + case ServiceConstant.Grass_User_Attention.ATTENTION_TYPE_TOPIC:
  79 + targetId = (Integer) checkResult;
80 publicUserAttention.setAttentionType(ServiceConstant.Public_User_Attention.ATTENTION_TYPE_TOPIC); 80 publicUserAttention.setAttentionType(ServiceConstant.Public_User_Attention.ATTENTION_TYPE_TOPIC);
81 break; 81 break;
82 case ServiceConstant.Grass_User_Attention.ATTENTION_TYPE_USER: 82 case ServiceConstant.Grass_User_Attention.ATTENTION_TYPE_USER:
@@ -97,11 +97,11 @@ public class GrassUserAttentionListener extends AbstractMqListener<GrassUserAtte @@ -97,11 +97,11 @@ public class GrassUserAttentionListener extends AbstractMqListener<GrassUserAtte
97 97
98 98
99 @Override 99 @Override
100 - protected Object checkData(GrassUserAttention sourceObject) { 100 + protected Object checkData(GrassUserAttention sourceObject, String action) {
101 //grass_user_attention.attention_type取0时public_user_attention.target_id取值: 101 //grass_user_attention.attention_type取0时public_user_attention.target_id取值:
102 //select id from public_topic where relate_id = #{grass_user_attention.topic_id} and src_channel = 1 102 //select id from public_topic where relate_id = #{grass_user_attention.topic_id} and src_channel = 1
103 - if(ServiceConstant.Grass_User_Attention.ATTENTION_TYPE_TOPIC == sourceObject.getAttentionType()){  
104 - return publicTopicService.findTopicIdByRelateIdAndSrcChannel(sourceObject.getTopicId() , 103 + if (ServiceConstant.Grass_User_Attention.ATTENTION_TYPE_TOPIC == sourceObject.getAttentionType()) {
  104 + return publicTopicService.findTopicIdByRelateIdAndSrcChannel(sourceObject.getTopicId(),
105 ServiceConstant.SRCCHANNEL_TYPE.YOHO_GRASS); 105 ServiceConstant.SRCCHANNEL_TYPE.YOHO_GRASS);
106 } 106 }
107 return sourceObject; 107 return sourceObject;
@@ -16,7 +16,7 @@ import org.springframework.stereotype.Component; @@ -16,7 +16,7 @@ import org.springframework.stereotype.Component;
16 import javax.annotation.Resource; 16 import javax.annotation.Resource;
17 17
18 @Component 18 @Component
19 -@MqConsumerListerner(dbName = "yh_grass",tableName = "user_favorite_article") 19 +@MqConsumerListerner(dbName = "yh_grass", tableName = "user_favorite_article")
20 public class UserFavoriteArticleListener extends AbstractMqListener<UserFavoriteArticle> { 20 public class UserFavoriteArticleListener extends AbstractMqListener<UserFavoriteArticle> {
21 21
22 @Resource 22 @Resource
@@ -31,31 +31,31 @@ public class UserFavoriteArticleListener extends AbstractMqListener<UserFavorite @@ -31,31 +31,31 @@ public class UserFavoriteArticleListener extends AbstractMqListener<UserFavorite
31 private static final Logger logger = LoggerFactory.getLogger(UserFavoriteArticleListener.class); 31 private static final Logger logger = LoggerFactory.getLogger(UserFavoriteArticleListener.class);
32 32
33 @Override 33 @Override
34 - protected void deleteData(UserFavoriteArticle sourceObject , Object checkResult) throws Exception { 34 + protected void deleteData(UserFavoriteArticle sourceObject, Object checkResult) throws Exception {
35 PublicUserFavorite publicUserFavorite = annotationClassFactory.convertTargetObjectFromSource(sourceObject, 35 PublicUserFavorite publicUserFavorite = annotationClassFactory.convertTargetObjectFromSource(sourceObject,
36 PublicUserFavorite.class); 36 PublicUserFavorite.class);
37 - if(publicUserFavorite == null){ 37 + if (publicUserFavorite == null) {
38 logger.error("deleteData failed , publicUserFavorite is null"); 38 logger.error("deleteData failed , publicUserFavorite is null");
39 throw new Exception("UserFavoriteArticleListener deleteData failed , publicUserFavorite is null"); 39 throw new Exception("UserFavoriteArticleListener deleteData failed , publicUserFavorite is null");
40 } 40 }
41 //public_user_favorite.target_id取值:select id from public_article where relate_id = 41 //public_user_favorite.target_id取值:select id from public_article where relate_id =
42 // #{user_favorite_article.article_id} and article_type in (1,2,4); 42 // #{user_favorite_article.article_id} and article_type in (1,2,4);
43 - publicUserFavorite.setTargetId((Integer)checkResult); 43 + publicUserFavorite.setTargetId((Integer) checkResult);
44 publicUserFavorite.setSrcChannel(ServiceConstant.SRCCHANNEL_TYPE.YOHO_GRASS); 44 publicUserFavorite.setSrcChannel(ServiceConstant.SRCCHANNEL_TYPE.YOHO_GRASS);
45 publicUserFavoriteService.deletePublicUserPraise(publicUserFavorite); 45 publicUserFavoriteService.deletePublicUserPraise(publicUserFavorite);
46 } 46 }
47 47
48 @Override 48 @Override
49 - protected void updateData(UserFavoriteArticle sourceObject , Object checkResult) throws Exception { 49 + protected void updateData(UserFavoriteArticle sourceObject, Object checkResult) throws Exception {
50 PublicUserFavorite publicUserFavorite = annotationClassFactory.convertTargetObjectFromSource 50 PublicUserFavorite publicUserFavorite = annotationClassFactory.convertTargetObjectFromSource
51 - (sourceObject,PublicUserFavorite.class);  
52 - if(publicUserFavorite == null){ 51 + (sourceObject, PublicUserFavorite.class);
  52 + if (publicUserFavorite == null) {
53 logger.error("updateData failed , publicUserFavorite is null"); 53 logger.error("updateData failed , publicUserFavorite is null");
54 throw new Exception("UserFavoriteArticleListener deleteData failed , publicUserFavorite is null"); 54 throw new Exception("UserFavoriteArticleListener deleteData failed , publicUserFavorite is null");
55 } 55 }
56 //public_user_favorite.target_id取值:select id from public_article where relate_id = 56 //public_user_favorite.target_id取值:select id from public_article where relate_id =
57 // #{user_favorite_article.article_id} and article_type in (1,2,4); 57 // #{user_favorite_article.article_id} and article_type in (1,2,4);
58 - publicUserFavorite.setTargetId((Integer)checkResult); 58 + publicUserFavorite.setTargetId((Integer) checkResult);
59 publicUserFavorite.setFavoriteType(ServiceConstant.Public_User_Favorite.FAVORITE_TYPE_ARTICLE); 59 publicUserFavorite.setFavoriteType(ServiceConstant.Public_User_Favorite.FAVORITE_TYPE_ARTICLE);
60 publicUserFavorite.setSrcChannel(ServiceConstant.SRCCHANNEL_TYPE.YOHO_GRASS); 60 publicUserFavorite.setSrcChannel(ServiceConstant.SRCCHANNEL_TYPE.YOHO_GRASS);
61 publicUserFavoriteService.saveOrUpdatePublicUserPraise(publicUserFavorite); 61 publicUserFavoriteService.saveOrUpdatePublicUserPraise(publicUserFavorite);
@@ -69,7 +69,7 @@ public class UserFavoriteArticleListener extends AbstractMqListener<UserFavorite @@ -69,7 +69,7 @@ public class UserFavoriteArticleListener extends AbstractMqListener<UserFavorite
69 } 69 }
70 70
71 @Override 71 @Override
72 - protected Object checkData(UserFavoriteArticle sourceObject) { 72 + protected Object checkData(UserFavoriteArticle sourceObject, String action) {
73 return publicArticleService.findArticleIdByRelateIdInArticleTypes(sourceObject.getArticleId(), 73 return publicArticleService.findArticleIdByRelateIdInArticleTypes(sourceObject.getArticleId(),
74 ServiceConstant.articleTypes); 74 ServiceConstant.articleTypes);
75 } 75 }
@@ -26,7 +26,7 @@ public abstract class AbstractMqListener<T> implements MessageListener { @@ -26,7 +26,7 @@ public abstract class AbstractMqListener<T> implements MessageListener {
26 /** 26 /**
27 * 这里是多线程的,同表共享一个Map 27 * 这里是多线程的,同表共享一个Map
28 */ 28 */
29 - private ConcurrentLinkedHashMap<String, Long> keyVersionMap = new ConcurrentLinkedHashMap.Builder<String , Long>() 29 + private ConcurrentLinkedHashMap<String, Long> keyVersionMap = new ConcurrentLinkedHashMap.Builder<String, Long>()
30 .maximumWeightedCapacity(2000) 30 .maximumWeightedCapacity(2000)
31 .weigher(Weighers.singleton()) 31 .weigher(Weighers.singleton())
32 .build(); 32 .build();
@@ -57,7 +57,7 @@ public abstract class AbstractMqListener<T> implements MessageListener { @@ -57,7 +57,7 @@ public abstract class AbstractMqListener<T> implements MessageListener {
57 private String getDataVersionKey(MqMessageEntity mqMessageEntity) { 57 private String getDataVersionKey(MqMessageEntity mqMessageEntity) {
58 String dbName = mqMessageEntity.getDbName(); 58 String dbName = mqMessageEntity.getDbName();
59 String tableName = mqMessageEntity.getTableName(); 59 String tableName = mqMessageEntity.getTableName();
60 - String primaryKeysValue = messageHelper.getPrimaryKeysValue(tableConfigLoader.getTableConfig(dbName,tableName), 60 + String primaryKeysValue = messageHelper.getPrimaryKeysValue(tableConfigLoader.getTableConfig(dbName, tableName),
61 mqMessageEntity.getData()); 61 mqMessageEntity.getData());
62 return dbName + "." + tableName + "." + primaryKeysValue; 62 return dbName + "." + tableName + "." + primaryKeysValue;
63 } 63 }
@@ -104,18 +104,18 @@ public abstract class AbstractMqListener<T> implements MessageListener { @@ -104,18 +104,18 @@ public abstract class AbstractMqListener<T> implements MessageListener {
104 } 104 }
105 105
106 // 对象强转 106 // 对象强转
107 - ParameterizedType t = (ParameterizedType)this.getClass().getGenericSuperclass(); //获得带有泛型的父类  
108 - T object = JSONObject.parseObject(JSON.toJSONString(messageJsonObject.getData()),t.getActualTypeArguments()[0]); 107 + ParameterizedType t = (ParameterizedType) this.getClass().getGenericSuperclass(); //获得带有泛型的父类
  108 + T object = JSONObject.parseObject(JSON.toJSONString(messageJsonObject.getData()), t.getActualTypeArguments()[0]);
109 109
110 // 参数检测,不满足条件,隔一分钟再检查一次 110 // 参数检测,不满足条件,隔一分钟再检查一次
111 - Object checkResult = this.checkData(object);  
112 - if(checkResult==null){ 111 + Object checkResult = this.checkData(object, messageJsonObject.getAction());
  112 + if (checkResult == null) {
113 logger.info("checkData fail, wait 60s ......"); 113 logger.info("checkData fail, wait 60s ......");
114 TimeUnit.SECONDS.sleep(60); 114 TimeUnit.SECONDS.sleep(60);
115 } 115 }
116 - checkResult = this.checkData(object);  
117 - if(checkResult==null){  
118 - logger.error("checkData fail, direct return ......, data is [{}]",messageJsonObject); 116 + checkResult = this.checkData(object, messageJsonObject.getAction());
  117 + if (checkResult == null) {
  118 + logger.error("checkData fail, direct return ......, data is [{}]", messageJsonObject);
119 return; 119 return;
120 } 120 }
121 121
@@ -126,14 +126,14 @@ public abstract class AbstractMqListener<T> implements MessageListener { @@ -126,14 +126,14 @@ public abstract class AbstractMqListener<T> implements MessageListener {
126 while (retryCount <= getMaxRetryTime()) { 126 while (retryCount <= getMaxRetryTime()) {
127 try { 127 try {
128 if (isDelete) { 128 if (isDelete) {
129 - this.doDeleteData(object,checkResult); 129 + this.doDeleteData(object, checkResult);
130 } else { 130 } else {
131 - this.doUpdateData(object,checkResult); 131 + this.doUpdateData(object, checkResult);
132 } 132 }
133 break; 133 break;
134 } catch (Exception e) { 134 } catch (Exception e) {
135 Thread.sleep(1000); 135 Thread.sleep(1000);
136 - logger.error("doConsume happen error, json is {},isDelete is {}, exception is :", messageJsonObject,isDelete, e); 136 + logger.error("doConsume happen error, json is {},isDelete is {}, exception is :", messageJsonObject, isDelete, e);
137 if (retryCount > getMaxRetryTime()) { 137 if (retryCount > getMaxRetryTime()) {
138 throw e; 138 throw e;
139 } 139 }
@@ -157,31 +157,31 @@ public abstract class AbstractMqListener<T> implements MessageListener { @@ -157,31 +157,31 @@ public abstract class AbstractMqListener<T> implements MessageListener {
157 return 5; 157 return 5;
158 } 158 }
159 159
160 - private void doDeleteData(T object,Object checkResult) throws Exception { 160 + private void doDeleteData(T object, Object checkResult) throws Exception {
161 long begin = System.currentTimeMillis(); 161 long begin = System.currentTimeMillis();
162 - this.deleteData(object,checkResult); 162 + this.deleteData(object, checkResult);
163 long cost = System.currentTimeMillis() - begin; 163 long cost = System.currentTimeMillis() - begin;
164 - logger.info("[func=doDeleteData][cost={}ms][eventName={}]", cost,this.getEventReportEnum().getFunctionName()); 164 + logger.info("[func=doDeleteData][cost={}ms][eventName={}]", cost, this.getEventReportEnum().getFunctionName());
165 } 165 }
166 166
167 - private void doUpdateData(T object,Object checkResult) throws Exception { 167 + private void doUpdateData(T object, Object checkResult) throws Exception {
168 long begin = System.currentTimeMillis(); 168 long begin = System.currentTimeMillis();
169 - this.updateData(object,checkResult); 169 + this.updateData(object, checkResult);
170 long cost = System.currentTimeMillis() - begin; 170 long cost = System.currentTimeMillis() - begin;
171 - logger.info("[func=doUpdateData][cost={}ms][eventName={}]", cost,this.getEventReportEnum().getFunctionName()); 171 + logger.info("[func=doUpdateData][cost={}ms][eventName={}]", cost, this.getEventReportEnum().getFunctionName());
172 } 172 }
173 173
174 174
175 /** 175 /**
176 * 删除数据 176 * 删除数据
177 */ 177 */
178 - protected abstract void deleteData(final T sourceObject,final Object checkResult) throws Exception; 178 + protected abstract void deleteData(final T sourceObject, final Object checkResult) throws Exception;
179 179
180 180
181 /** 181 /**
182 * 更新数据 182 * 更新数据
183 */ 183 */
184 - protected abstract void updateData(final T sourceObject,final Object checkResult) throws Exception; 184 + protected abstract void updateData(final T sourceObject, final Object checkResult) throws Exception;
185 185
186 /** 186 /**
187 * 定义事件类型 187 * 定义事件类型
@@ -189,9 +189,11 @@ public abstract class AbstractMqListener<T> implements MessageListener { @@ -189,9 +189,11 @@ public abstract class AbstractMqListener<T> implements MessageListener {
189 protected abstract EventEnum getEventReportEnum(); 189 protected abstract EventEnum getEventReportEnum();
190 190
191 /** 191 /**
192 - * 数据检测 192 + * @param sourceObject
  193 + * @param action 操作
  194 + * @return
193 */ 195 */
194 - protected Object checkData(T sourceObject) { 196 + protected Object checkData(T sourceObject, String action) {
195 return sourceObject; 197 return sourceObject;
196 } 198 }
197 199
1 package com.yoho.datasync.consumer.service; 1 package com.yoho.datasync.consumer.service;
2 2
  3 +import com.yoho.datasync.consumer.common.ContentConvertUtil;
  4 +import com.yoho.datasync.consumer.common.ServiceConstant;
3 import com.yoho.datasync.consumer.dal.repository.PublicArticleBlockRepository; 5 import com.yoho.datasync.consumer.dal.repository.PublicArticleBlockRepository;
  6 +import com.yoho.datasync.consumer.dal.repository.PublicArticleRepository;
4 import com.yoho.datasync.core.base.model.yh_pcms.PublicArticleBlock; 7 import com.yoho.datasync.core.base.model.yh_pcms.PublicArticleBlock;
5 import org.slf4j.Logger; 8 import org.slf4j.Logger;
6 import org.slf4j.LoggerFactory; 9 import org.slf4j.LoggerFactory;
7 import org.springframework.stereotype.Service; 10 import org.springframework.stereotype.Service;
8 11
9 import javax.annotation.Resource; 12 import javax.annotation.Resource;
  13 +import java.util.Map;
10 14
11 @Service 15 @Service
12 public class PublicArticleBlockService { 16 public class PublicArticleBlockService {
@@ -14,6 +18,9 @@ public class PublicArticleBlockService { @@ -14,6 +18,9 @@ public class PublicArticleBlockService {
14 @Resource 18 @Resource
15 private PublicArticleBlockRepository publicArticleBlockRepository; 19 private PublicArticleBlockRepository publicArticleBlockRepository;
16 20
  21 + @Resource
  22 + private PublicArticleRepository publicArticleRepository;
  23 +
17 private static final Logger log = LoggerFactory.getLogger(PublicArticleBlockService.class); 24 private static final Logger log = LoggerFactory.getLogger(PublicArticleBlockService.class);
18 25
19 /** 26 /**
@@ -21,9 +28,10 @@ public class PublicArticleBlockService { @@ -21,9 +28,10 @@ public class PublicArticleBlockService {
21 * 28 *
22 * 注意:关于 public_article_block 表, 29 * 注意:关于 public_article_block 表,
23 * 对于每一次文章更新, 30 * 对于每一次文章更新,
24 - * 后台都是直接将原来的记录统统删除,再插入新的数据;  
25 - * 所以没有更新操作,只有插入操作;  
26 - * 并且在每一次插入操作之前,以前的数据已被删除干净 31 + * 后台都是直接将原来的记录统统删除【逻辑删除】,再插入新的数据;
  32 + * 也就是说监听到的都应该是【update语句】
  33 + * 再监听到逻辑删除【update语句】发生时,应该将原来的数据删除;
  34 + * 在查找原来的数据时加上create_time过滤,防止误删除;
27 * 35 *
28 * ************************************************************************ 36 * ************************************************************************
29 */ 37 */
@@ -32,9 +40,11 @@ public class PublicArticleBlockService { @@ -32,9 +40,11 @@ public class PublicArticleBlockService {
32 * 删除数据 40 * 删除数据
33 * 41 *
34 * @param targetObject 42 * @param targetObject
  43 + * @param b
35 */ 44 */
36 - public void deleteData(PublicArticleBlock targetObject) {  
37 - PublicArticleBlock existObject = publicArticleBlockRepository.findByArticleIdAndOrderBy(targetObject.getArticleId(), targetObject.getOrderBy()); 45 + public void deleteData(PublicArticleBlock targetObject, boolean b) {
  46 + PublicArticleBlock existObject = publicArticleBlockRepository.
  47 + findByArticleIdAndCreateTimeAndOrderBy(targetObject.getArticleId(), targetObject.getCreateTime(), targetObject.getOrderBy());
38 if (existObject == null) { 48 if (existObject == null) {
39 log.info("get nothing from database by condition articleId and orderBy with targetObject {}", targetObject.toString()); 49 log.info("get nothing from database by condition articleId and orderBy with targetObject {}", targetObject.toString());
40 return; 50 return;
@@ -43,17 +53,44 @@ public class PublicArticleBlockService { @@ -43,17 +53,44 @@ public class PublicArticleBlockService {
43 } 53 }
44 54
45 /** 55 /**
46 - * 结合具体的业务,每一次操作都应该是新增 56 + * 结合具体的业务,监听到逻辑删除【update语句】发生时,应该将原来的数据删除
47 * 57 *
48 * @param targetObject 58 * @param targetObject
  59 + * @param flag 标记状态位是否为删除状态
49 */ 60 */
50 - public void updateData(PublicArticleBlock targetObject) {  
51 - PublicArticleBlock existObject = publicArticleBlockRepository.findByArticleIdAndOrderBy(targetObject.getArticleId(), targetObject.getOrderBy());  
52 - if (existObject != null) {  
53 - log.error("something goes wrong ... with PublicArticleBlock {}", existObject.toString()); 61 + public void updateData(PublicArticleBlock targetObject, boolean flag) {
  62 + if (flag) {
  63 + PublicArticleBlock existObject = publicArticleBlockRepository.
  64 + findByArticleIdAndCreateTimeAndOrderBy(targetObject.getArticleId(), targetObject.getCreateTime(), targetObject.getOrderBy());
  65 + if (existObject == null) {
  66 + log.error("something goes wrong ... data is null...");
  67 + return;
  68 + }
  69 + publicArticleBlockRepository.deleteById(existObject.getId());
54 return; 70 return;
55 } 71 }
  72 + // 否则为插入操作
56 publicArticleBlockRepository.save(targetObject); 73 publicArticleBlockRepository.save(targetObject);
  74 + // 更新 public_article.cover_img
  75 + if (targetObject.getOrderBy() == 0) {
  76 + try {
  77 + Map map = ContentConvertUtil.jsonString2Map(targetObject.getContentData());
  78 + String coverImg = (String) ((Map) (map.get("data"))).get("src");
  79 + if (coverImg != null)
  80 + publicArticleRepository.updateCoverImgByArticleIdAndArticleTypes(coverImg, targetObject.getArticleId(), ServiceConstant.articleTypes);
  81 + } catch (Exception e) {
  82 + log.error("update public_article.cover_img goes error with exception {}", e);
  83 + }
  84 + }
57 } 85 }
58 86
  87 + /**
  88 + * 根据文章ID查找文章内容
  89 + *
  90 + * @param trueId
  91 + * @return
  92 + */
  93 + public String findContentData(Integer trueId) {
  94 + return publicArticleBlockRepository.findContentData(trueId);
  95 + }
59 } 96 }
@@ -2,6 +2,8 @@ package com.yoho.datasync.consumer.service; @@ -2,6 +2,8 @@ package com.yoho.datasync.consumer.service;
2 2
3 import com.yoho.datasync.consumer.dal.repository.PublicArticleLabelRepository; 3 import com.yoho.datasync.consumer.dal.repository.PublicArticleLabelRepository;
4 import com.yoho.datasync.core.base.model.yh_pcms.PublicArticleLabel; 4 import com.yoho.datasync.core.base.model.yh_pcms.PublicArticleLabel;
  5 +import org.slf4j.Logger;
  6 +import org.slf4j.LoggerFactory;
5 import org.springframework.stereotype.Service; 7 import org.springframework.stereotype.Service;
6 8
7 import javax.annotation.Resource; 9 import javax.annotation.Resource;
@@ -9,16 +11,30 @@ import javax.annotation.Resource; @@ -9,16 +11,30 @@ import javax.annotation.Resource;
9 @Service 11 @Service
10 public class PublicArticleLabelService { 12 public class PublicArticleLabelService {
11 13
  14 + /**
  15 + * ***********************************************************
  16 + * 根据实际处理逻辑,对于用户文章关联标签表 grass_article_label
  17 + * 只有删除和插入操作
  18 + * ***********************************************************
  19 + */
  20 +
12 @Resource 21 @Resource
13 private PublicArticleLabelRepository publicArticleLabelRepository; 22 private PublicArticleLabelRepository publicArticleLabelRepository;
14 23
  24 + private static final Logger log = LoggerFactory.getLogger(PublicArticleLabelService.class);
  25 +
15 /** 26 /**
16 * 删除数据 27 * 删除数据
17 * 28 *
18 * @param targetObject 29 * @param targetObject
19 */ 30 */
20 public void deleteData(PublicArticleLabel targetObject) { 31 public void deleteData(PublicArticleLabel targetObject) {
21 - 32 + final PublicArticleLabel existObject = publicArticleLabelRepository.findByLabelIdAndArticleId(targetObject.getLabelId(), targetObject.getLabelId());
  33 + if (existObject == null) {
  34 + log.info("get nothing from database by condition labelId and articleId with targetObject {}", targetObject.toString());
  35 + return;
  36 + }
  37 + publicArticleLabelRepository.deleteById(existObject.getId());
22 } 38 }
23 39
24 /** 40 /**
@@ -27,6 +43,6 @@ public class PublicArticleLabelService { @@ -27,6 +43,6 @@ public class PublicArticleLabelService {
27 * @param targetObject 43 * @param targetObject
28 */ 44 */
29 public void updateData(PublicArticleLabel targetObject) { 45 public void updateData(PublicArticleLabel targetObject) {
30 - 46 + publicArticleLabelRepository.save(targetObject);
31 } 47 }
32 } 48 }
@@ -2,6 +2,8 @@ package com.yoho.datasync.consumer.service; @@ -2,6 +2,8 @@ package com.yoho.datasync.consumer.service;
2 2
3 import com.yoho.datasync.consumer.dal.repository.PublicArticleProductRepository; 3 import com.yoho.datasync.consumer.dal.repository.PublicArticleProductRepository;
4 import com.yoho.datasync.core.base.model.yh_pcms.PublicArticleProduct; 4 import com.yoho.datasync.core.base.model.yh_pcms.PublicArticleProduct;
  5 +import org.slf4j.Logger;
  6 +import org.slf4j.LoggerFactory;
5 import org.springframework.stereotype.Service; 7 import org.springframework.stereotype.Service;
6 8
7 import javax.annotation.Resource; 9 import javax.annotation.Resource;
@@ -9,24 +11,57 @@ import javax.annotation.Resource; @@ -9,24 +11,57 @@ import javax.annotation.Resource;
9 @Service 11 @Service
10 public class PublicArticleProductService { 12 public class PublicArticleProductService {
11 13
  14 + /**
  15 + * ********************************************************************
  16 + * 根据实际代码逻辑,对于用户关联商品表 grass_article_product,
  17 + * 对于每一次更新,
  18 + * 后台都是直接将原来的记录统统删除【逻辑删除】,再插入新的数据;
  19 + * 也就是说监听到的都应该是【update语句】
  20 + * 再监听到逻辑删除【update语句】发生时,应该将原来的数据删除;
  21 + * 在查找原来的数据时加上create_time过滤,防止误删除;
  22 + * ********************************************************************
  23 + */
  24 +
12 @Resource 25 @Resource
13 private PublicArticleProductRepository publicArticleProductRepository; 26 private PublicArticleProductRepository publicArticleProductRepository;
14 27
  28 + private static final Logger log = LoggerFactory.getLogger(PublicArticleProductService.class);
  29 +
15 /** 30 /**
16 * 删除数据 31 * 删除数据
17 * 32 *
18 * @param targetObject 33 * @param targetObject
  34 + * @param b
19 */ 35 */
20 - public void deleteData(PublicArticleProduct targetObject) {  
21 - 36 + public void deleteData(PublicArticleProduct targetObject, boolean b) {
  37 + final PublicArticleProduct existObject = publicArticleProductRepository.
  38 + findByArticleIdAndProductSknAndCreateTimeAndOrderBy(targetObject.getArticleId(), targetObject.getProductSkn(), targetObject.getCreateTime(), targetObject.getOrderBy());
  39 + if (existObject == null) {
  40 + log.info("get nothing from database by condition labelId and articleId with targetObject {}", targetObject.toString());
  41 + return;
  42 + }
  43 + publicArticleProductRepository.deleteById(existObject.getId());
22 } 44 }
23 45
24 /** 46 /**
25 * 修改或清空数据 47 * 修改或清空数据
26 * 48 *
27 * @param targetObject 49 * @param targetObject
  50 + * @param flag 标记状态位是否为删除状态
28 */ 51 */
29 - public void updateData(PublicArticleProduct targetObject) {  
30 - 52 + public void updateData(PublicArticleProduct targetObject, boolean flag) {
  53 + if (flag) {
  54 + // 监听到逻辑删除
  55 + final PublicArticleProduct existObject = publicArticleProductRepository.
  56 + findByArticleIdAndProductSknAndCreateTimeAndOrderBy(targetObject.getArticleId(), targetObject.getProductSkn(), targetObject.getCreateTime(), targetObject.getOrderBy());
  57 + if (existObject == null) {
  58 + log.error("something goes wrong ... data is null");
  59 + return;
  60 + }
  61 + publicArticleProductRepository.deleteById(existObject.getId());
  62 + return;
  63 + }
  64 + // 插入
  65 + publicArticleProductRepository.save(targetObject);
31 } 66 }
32 } 67 }
@@ -45,15 +45,16 @@ public class PublicArticleService { @@ -45,15 +45,16 @@ public class PublicArticleService {
45 * 45 *
46 * @param targetObject 46 * @param targetObject
47 * @param publicArticleAudit 47 * @param publicArticleAudit
  48 + * @param checkResult
48 */ 49 */
49 - public void updateData(PublicArticle targetObject, PublicArticleAudit publicArticleAudit) { 50 + public void updateData(PublicArticle targetObject, PublicArticleAudit publicArticleAudit, Object checkResult) {
50 // public_article_audit表中的article_id字段为种草文章同步到公共库public_article表中的自增id字段 51 // public_article_audit表中的article_id字段为种草文章同步到公共库public_article表中的自增id字段
51 // select id from public_article where relate_id=#{grass_article.article_id} and article_type in (1,2,4) 52 // select id from public_article where relate_id=#{grass_article.article_id} and article_type in (1,2,4)
52 PublicArticle existObject = validateInfoAndGetRecord(targetObject); 53 PublicArticle existObject = validateInfoAndGetRecord(targetObject);
53 boolean mark = true; 54 boolean mark = true;
54 if (existObject != null) { 55 if (existObject != null) {
55 mark = false; 56 mark = false;
56 - // TODO : 获取 cover_img 57 + targetObject.setCoverImg((String) checkResult);
57 if (targetObject.getId() != null) { 58 if (targetObject.getId() != null) {
58 log.error("something goes wrong ..."); 59 log.error("something goes wrong ...");
59 return; 60 return;