Authored by peuei

update

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