Authored by peuei

update

... ... @@ -2,11 +2,14 @@ package com.yoho.datasync.consumer.dal.repository;
import com.yoho.datasync.core.base.model.yh_pcms.PublicLabel;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
public interface PublicLabelRepository extends JpaRepository<PublicLabel, Integer>{
public interface PublicLabelRepository extends JpaRepository<PublicLabel, Integer> {
PublicLabel findByRelateIdAndSrcChannel(Integer relateId, Integer srcChannel);
@Query("select id from PublicLabel where relateId = ?1 and srcChannel in (?2)")
Integer findIdByArticleId(Integer trueId, Integer grassSrcChannel);
}
... ...
... ... @@ -5,6 +5,7 @@ import com.yoho.datasync.consumer.handler.helper.AnnotationClassFactory;
import com.yoho.datasync.consumer.handler.mqcomponent.AbstractMqListener;
import com.yoho.datasync.consumer.service.PublicArticleLabelService;
import com.yoho.datasync.consumer.service.PublicArticleService;
import com.yoho.datasync.consumer.service.PublicLabelService;
import com.yoho.datasync.core.base.annotation.MqConsumerListerner;
import com.yoho.datasync.core.base.model.yh_grass.GrassArticleLabel;
import com.yoho.datasync.core.base.model.yh_pcms.PublicArticleLabel;
... ... @@ -32,6 +33,9 @@ public class GrassArticleLabelListener extends AbstractMqListener<GrassArticleLa
@Resource
private PublicArticleLabelService publicArticleLabelService;
@Resource
private PublicLabelService publicLabelService;
private static final Integer GRASS_SRC_CHANNEL = 1;
... ... @@ -100,11 +104,14 @@ public class GrassArticleLabelListener extends AbstractMqListener<GrassArticleLa
}
/**
* 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
* select id from public_label where relate_id=#{grass_article_label.label_id} and src_channel =1
*/
// TODO : wait 暂无对应接口
Integer labelId = publicLabelService.findIdByArticleId(sourceObject.getLabelId(), GRASS_SRC_CHANNEL);
if (labelId == null)
return null;
Integer[] result = new Integer[2];
result[0] = trueId;
result[1] = labelId;
return result;
}
... ...
... ... @@ -17,13 +17,13 @@ public class PublicLabelService {
private static final Logger logger = LoggerFactory.getLogger(PublicLabelService.class);
public void deletePublicLabel(PublicLabel publicLabel) throws Exception{
public void deletePublicLabel(PublicLabel publicLabel) throws Exception {
Integer relateId = publicLabel.getRelateId();
Integer srcChannel = publicLabel.getSrcChannel();
PublicLabel publicLabelFromDB = getByRelateIdAndSrcChannel(relateId, srcChannel);
if (publicLabelFromDB != null) {
repository.deleteById(publicLabelFromDB.getId());
}else{
} else {
logger.error("deletePublicLabel数据不存在relateId={}", publicLabel.getRelateId());
throw new Exception("deletePublicLabel失败");
}
... ... @@ -34,18 +34,22 @@ public class PublicLabelService {
Integer srcChannel = publicLabel.getSrcChannel();
PublicLabel publicLabelFromDB = getByRelateIdAndSrcChannel(relateId, srcChannel);
if (publicLabelFromDB != null) { //更新 需要保证原来的字段值不被null覆盖掉
publicLabelFromDB = BeanCopyUtils.copyNonNullProperties(publicLabel , publicLabelFromDB ,
publicLabelFromDB = BeanCopyUtils.copyNonNullProperties(publicLabel, publicLabelFromDB,
PublicLabel.class);
repository.save(publicLabelFromDB);
}else{ //新增
} else { //新增
repository.save(publicLabel);
}
}
private PublicLabel getByRelateIdAndSrcChannel(Integer relateId , Integer srcChannel){
if(relateId == null || srcChannel == null){
private PublicLabel getByRelateIdAndSrcChannel(Integer relateId, Integer srcChannel) {
if (relateId == null || srcChannel == null) {
return null;
}
return repository.findByRelateIdAndSrcChannel(relateId, srcChannel);
}
public Integer findIdByArticleId(Integer trueId, Integer grassSrcChannel) {
return repository.findIdByArticleId(trueId, grassSrcChannel);
}
}
... ...