Authored by liangyi.chen@yoho.cn

Add file

@@ -8,8 +8,10 @@ public enum EventEnum { @@ -8,8 +8,10 @@ public enum EventEnum {
8 GRASSUSERATTENTIONLISTENER_UPDATE("DealData", "GrassUserAttentionListener.dealData"), 8 GRASSUSERATTENTIONLISTENER_UPDATE("DealData", "GrassUserAttentionListener.dealData"),
9 GRASS_ARTICLE_UPDATE("dealData", "GrassArticleListener.dealData"), 9 GRASS_ARTICLE_UPDATE("dealData", "GrassArticleListener.dealData"),
10 GRASS_ARTICLE_BLOCK_UPDATE("dealData", "GrassArticleBlockListener.dealData"), 10 GRASS_ARTICLE_BLOCK_UPDATE("dealData", "GrassArticleBlockListener.dealData"),
11 - GRASS_ARTICLE_LABEL_UPDATE("dealData", "GrassArticleLabelListener.dealData"),  
12 - GRASS_ARTICLE_PRODUCT_UPDATE("dealData", "GrassArticleProductListener.dealData"); 11 + GRASS_ARTICLE_PRODUCT_UPDATE("dealData", "GrassArticleProductListener.dealData"),
  12 + GRASSLABELGROUPLISTENER_UPDATEDATA("DealData", "GrassLableGroupListener.dealData"),
  13 + GRASS_ARTICLE_LABEL_UPDATE("dealData", "GrassArticleLabelListener.dealData");
  14 +
13 15
14 private String eventName; 16 private String eventName;
15 private String functionName; 17 private String functionName;
@@ -86,4 +86,20 @@ public class ServiceConstant { @@ -86,4 +86,20 @@ public class ServiceConstant {
86 int CANCEL_STATUS = 1; 86 int CANCEL_STATUS = 1;
87 } 87 }
88 88
  89 + public interface Grass_Label_Group{
  90 + /**
  91 + * 标签分组状态 1开启,0关闭
  92 + */
  93 + int OPEN_STATUS = 1;
  94 + int CLOSE_STATUS = 0;
  95 + }
  96 +
  97 + public interface Public_Label_Group{
  98 + /**
  99 + * 标签分组状态 1开启,2关闭
  100 + */
  101 + int OPEN_STATUS = 1;
  102 + int CLOSE_STATUS = 2;
  103 + }
  104 +
89 } 105 }
  1 +package com.yoho.datasync.consumer.dal.repository;
  2 +
  3 +
  4 +import com.yoho.datasync.core.base.model.yh_pcms.PublicLabelGroup;
  5 +import org.springframework.data.jpa.repository.JpaRepository;
  6 +
  7 +public interface PublicLabelGroupRepository extends JpaRepository<PublicLabelGroup, Integer>{
  8 +
  9 + PublicLabelGroup findByRelateIdAndSrcChannel(Integer relateId, Integer srcChannel);
  10 +
  11 +}
  1 +package com.yoho.datasync.consumer.handler.listener;
  2 +
  3 +import com.yoho.datasync.consumer.common.EventEnum;
  4 +import com.yoho.datasync.consumer.common.ServiceConstant;
  5 +import com.yoho.datasync.consumer.handler.helper.AnnotationClassFactory;
  6 +import com.yoho.datasync.consumer.handler.mqcomponent.AbstractMqListener;
  7 +import com.yoho.datasync.consumer.service.PublicLabelGroupService;
  8 +import com.yoho.datasync.core.base.annotation.MqConsumerListerner;
  9 +import com.yoho.datasync.core.base.model.yh_grass.GrassLabelGroup;
  10 +import com.yoho.datasync.core.base.model.yh_pcms.PublicLabelGroup;
  11 +import org.slf4j.Logger;
  12 +import org.slf4j.LoggerFactory;
  13 +import org.springframework.stereotype.Component;
  14 +
  15 +import javax.annotation.Resource;
  16 +
  17 +@Component
  18 +@MqConsumerListerner(dbName = "yh_grass",tableName = "grass_lable_group")
  19 +public class GrassLableGroupListener extends AbstractMqListener<GrassLabelGroup> {
  20 +
  21 + @Resource
  22 + PublicLabelGroupService publicLabelGroupService;
  23 +
  24 + @Resource
  25 + AnnotationClassFactory annotationClassFactory;
  26 +
  27 + private static final Logger logger = LoggerFactory.getLogger(GrassLableGroupListener.class);
  28 +
  29 + @Override
  30 + protected void deleteData(GrassLabelGroup sourceObject , Object checkResult) throws Exception {
  31 + PublicLabelGroup publicLabelGroup = annotationClassFactory.convertTargetObjectFromSource(sourceObject,
  32 + PublicLabelGroup.class);
  33 + if(publicLabelGroup == null){
  34 + logger.error("deleteData failed , publicLabelGroup is null");
  35 + return;
  36 + }
  37 +
  38 + publicLabelGroup.setSrcChannel(ServiceConstant.SRCCHANNEL_TYPE.YOHO_GRASS);
  39 + publicLabelGroupService.deletePublicLabelGroup(publicLabelGroup);
  40 + }
  41 +
  42 + @Override
  43 + protected void updateData(GrassLabelGroup sourceObject , Object checkResult) throws Exception {
  44 + PublicLabelGroup publicLabelGroup = annotationClassFactory.convertTargetObjectFromSource(sourceObject,PublicLabelGroup.class);
  45 + if(publicLabelGroup == null){
  46 + logger.error("updateData failed , publicLabelGroup is null");
  47 + return;
  48 + }
  49 + if(sourceObject.getStatus() != null){
  50 + switch (sourceObject.getStatus()){
  51 + case ServiceConstant.Grass_Label_Group.CLOSE_STATUS:
  52 + publicLabelGroup.setStatus(ServiceConstant.Public_Label_Group.CLOSE_STATUS);
  53 + break;
  54 + case ServiceConstant.Grass_Label_Group.OPEN_STATUS:
  55 + publicLabelGroup.setStatus(ServiceConstant.Public_Label_Group.OPEN_STATUS);
  56 + }
  57 + }
  58 + publicLabelGroup.setSrcChannel(ServiceConstant.SRCCHANNEL_TYPE.YOHO_GRASS);
  59 + publicLabelGroupService.saveOrUpdatePublicUserAttention(publicLabelGroup);
  60 +
  61 + }
  62 +
  63 +
  64 + @Override
  65 + protected EventEnum getEventReportEnum() {
  66 + return EventEnum.GRASSLABELGROUPLISTENER_UPDATEDATA;
  67 + }
  68 +}
  1 +package com.yoho.datasync.consumer.service;
  2 +
  3 +import com.yoho.datasync.consumer.common.BeanCopyUtils;
  4 +import com.yoho.datasync.consumer.dal.repository.PublicLabelGroupRepository;
  5 +import com.yoho.datasync.core.base.model.yh_pcms.PublicLabelGroup;
  6 +import org.slf4j.Logger;
  7 +import org.slf4j.LoggerFactory;
  8 +import org.springframework.stereotype.Service;
  9 +
  10 +import javax.annotation.Resource;
  11 +
  12 +
  13 +@Service
  14 +public class PublicLabelGroupService {
  15 +
  16 + @Resource
  17 + private PublicLabelGroupRepository repository;
  18 +
  19 + private static final Logger logger = LoggerFactory.getLogger(PublicLabelGroupService.class);
  20 +
  21 + public void deletePublicLabelGroup(PublicLabelGroup publicLabelGroup) throws Exception{
  22 + Integer relateId = publicLabelGroup.getRelateId();
  23 + Integer srcChannel = publicLabelGroup.getSrcChannel();
  24 + PublicLabelGroup publicLabelGroupFromDB = getByRelateIdAndSrcChannel(relateId, srcChannel);
  25 + if (publicLabelGroupFromDB != null) {
  26 + repository.deleteById(publicLabelGroupFromDB.getId());
  27 + }else{
  28 + logger.error("deletePublicLabelGroup数据不存在relateId={}", publicLabelGroup.getRelateId());
  29 + throw new Exception("deletePublicLabelGroup失败");
  30 + }
  31 + }
  32 +
  33 + public void saveOrUpdatePublicUserAttention(PublicLabelGroup publicLabelGroup) {
  34 + Integer relateId = publicLabelGroup.getRelateId();
  35 + Integer srcChannel = publicLabelGroup.getSrcChannel();
  36 + PublicLabelGroup publicLabelGroupFromDB = getByRelateIdAndSrcChannel(relateId, srcChannel);
  37 + if (publicLabelGroupFromDB != null) { //更新 需要保证原来的字段值不被null覆盖掉
  38 + publicLabelGroupFromDB = BeanCopyUtils.copyNonNullProperties(publicLabelGroup , publicLabelGroupFromDB ,
  39 + PublicLabelGroup.class);
  40 + repository.save(publicLabelGroupFromDB);
  41 + }else{ //新增
  42 + repository.save(publicLabelGroup);
  43 + }
  44 + }
  45 +
  46 + private PublicLabelGroup getByRelateIdAndSrcChannel(Integer relateId , Integer srcChannel){
  47 + if(relateId == null || srcChannel == null){
  48 + return null;
  49 + }
  50 + return repository.findByRelateIdAndSrcChannel(relateId, srcChannel);
  51 + }
  52 +}
@@ -43,8 +43,9 @@ public class PublicUserAttentionService { @@ -43,8 +43,9 @@ public class PublicUserAttentionService {
43 if (publicUserAttentionFromDB != null) { //更新 需要保证原来的字段值不被null覆盖掉 43 if (publicUserAttentionFromDB != null) { //更新 需要保证原来的字段值不被null覆盖掉
44 publicUserAttentionFromDB = BeanCopyUtils.copyNonNullProperties(publicUserAttention , publicUserAttentionFromDB , 44 publicUserAttentionFromDB = BeanCopyUtils.copyNonNullProperties(publicUserAttention , publicUserAttentionFromDB ,
45 PublicUserAttention.class); 45 PublicUserAttention.class);
46 -  
47 - }  
48 repository.save(publicUserAttentionFromDB); 46 repository.save(publicUserAttentionFromDB);
  47 + }else{
  48 + repository.save(publicUserAttention); //新增
  49 + }
49 } 50 }
50 } 51 }
@@ -24,9 +24,10 @@ public class PublicUserCommentService { @@ -24,9 +24,10 @@ public class PublicUserCommentService {
24 if (publicUserCommentFromDB != null) { //更新 需要保证原来的字段值不被null覆盖掉 24 if (publicUserCommentFromDB != null) { //更新 需要保证原来的字段值不被null覆盖掉
25 publicUserCommentFromDB = BeanCopyUtils.copyNonNullProperties(publicUserComment , publicUserCommentFromDB , 25 publicUserCommentFromDB = BeanCopyUtils.copyNonNullProperties(publicUserComment , publicUserCommentFromDB ,
26 PublicUserComment.class); 26 PublicUserComment.class);
27 -  
28 - }  
29 repository.save(publicUserCommentFromDB); 27 repository.save(publicUserCommentFromDB);
  28 + }else{
  29 + repository.save(publicUserComment); //新增
  30 + }
30 } 31 }
31 32
32 public void deletePublicUserComment(PublicUserComment publicUserComment) throws Exception{ 33 public void deletePublicUserComment(PublicUserComment publicUserComment) throws Exception{
@@ -22,9 +22,10 @@ public class PublicUserFavoriteService { @@ -22,9 +22,10 @@ public class PublicUserFavoriteService {
22 PublicUserFavorite publicUserFavoriteFromDB = getPublicUserFavoriteByUniqueKey(publicUserFavorite); 22 PublicUserFavorite publicUserFavoriteFromDB = getPublicUserFavoriteByUniqueKey(publicUserFavorite);
23 if (publicUserFavoriteFromDB != null) { //更新 23 if (publicUserFavoriteFromDB != null) { //更新
24 BeanCopyUtils.copyNonNullProperties(publicUserFavorite , publicUserFavoriteFromDB , PublicUserFavorite.class); 24 BeanCopyUtils.copyNonNullProperties(publicUserFavorite , publicUserFavoriteFromDB , PublicUserFavorite.class);
25 -  
26 - }  
27 repository.save(publicUserFavoriteFromDB); 25 repository.save(publicUserFavoriteFromDB);
  26 + }else{
  27 + repository.save(publicUserFavorite); //新增
  28 + }
28 } 29 }
29 30
30 public void deletePublicUserPraise(PublicUserFavorite publicUserFavorite) throws Exception{ 31 public void deletePublicUserPraise(PublicUserFavorite publicUserFavorite) throws Exception{
@@ -22,11 +22,13 @@ public class PublicUserPraiseService { @@ -22,11 +22,13 @@ public class PublicUserPraiseService {
22 PublicUserPraise publicUserPraiseFromDB = getPublicUserPraiseByUniqueKey(publicUserPraise); 22 PublicUserPraise publicUserPraiseFromDB = getPublicUserPraiseByUniqueKey(publicUserPraise);
23 if (publicUserPraiseFromDB != null) { //更新 23 if (publicUserPraiseFromDB != null) { //更新
24 BeanCopyUtils.copyNonNullProperties(publicUserPraise , publicUserPraiseFromDB , PublicUserPraise.class); 24 BeanCopyUtils.copyNonNullProperties(publicUserPraise , publicUserPraiseFromDB , PublicUserPraise.class);
25 -  
26 - } 25 + repository.save(publicUserPraiseFromDB);
  26 + }else{ //新增
27 repository.save(publicUserPraise); 27 repository.save(publicUserPraise);
28 } 28 }
29 29
  30 + }
  31 +
30 public void deletePublicUserPraise(PublicUserPraise publicUserPraise) throws Exception{ 32 public void deletePublicUserPraise(PublicUserPraise publicUserPraise) throws Exception{
31 PublicUserPraise publicUserPraiseFromDB = getPublicUserPraiseByUniqueKey(publicUserPraise); 33 PublicUserPraise publicUserPraiseFromDB = getPublicUserPraiseByUniqueKey(publicUserPraise);
32 if (publicUserPraiseFromDB != null) { 34 if (publicUserPraiseFromDB != null) {