Authored by liangyi.chen@yoho.cn

Add file

... ... @@ -8,8 +8,10 @@ public enum EventEnum {
GRASSUSERATTENTIONLISTENER_UPDATE("DealData", "GrassUserAttentionListener.dealData"),
GRASS_ARTICLE_UPDATE("dealData", "GrassArticleListener.dealData"),
GRASS_ARTICLE_BLOCK_UPDATE("dealData", "GrassArticleBlockListener.dealData"),
GRASS_ARTICLE_LABEL_UPDATE("dealData", "GrassArticleLabelListener.dealData"),
GRASS_ARTICLE_PRODUCT_UPDATE("dealData", "GrassArticleProductListener.dealData");
GRASS_ARTICLE_PRODUCT_UPDATE("dealData", "GrassArticleProductListener.dealData"),
GRASSLABELGROUPLISTENER_UPDATEDATA("DealData", "GrassLableGroupListener.dealData"),
GRASS_ARTICLE_LABEL_UPDATE("dealData", "GrassArticleLabelListener.dealData");
private String eventName;
private String functionName;
... ...
... ... @@ -86,4 +86,20 @@ public class ServiceConstant {
int CANCEL_STATUS = 1;
}
public interface Grass_Label_Group{
/**
* 标签分组状态 1开启,0关闭
*/
int OPEN_STATUS = 1;
int CLOSE_STATUS = 0;
}
public interface Public_Label_Group{
/**
* 标签分组状态 1开启,2关闭
*/
int OPEN_STATUS = 1;
int CLOSE_STATUS = 2;
}
}
... ...
package com.yoho.datasync.consumer.dal.repository;
import com.yoho.datasync.core.base.model.yh_pcms.PublicLabelGroup;
import org.springframework.data.jpa.repository.JpaRepository;
public interface PublicLabelGroupRepository extends JpaRepository<PublicLabelGroup, Integer>{
PublicLabelGroup findByRelateIdAndSrcChannel(Integer relateId, Integer srcChannel);
}
... ...
package com.yoho.datasync.consumer.handler.listener;
import com.yoho.datasync.consumer.common.EventEnum;
import com.yoho.datasync.consumer.common.ServiceConstant;
import com.yoho.datasync.consumer.handler.helper.AnnotationClassFactory;
import com.yoho.datasync.consumer.handler.mqcomponent.AbstractMqListener;
import com.yoho.datasync.consumer.service.PublicLabelGroupService;
import com.yoho.datasync.core.base.annotation.MqConsumerListerner;
import com.yoho.datasync.core.base.model.yh_grass.GrassLabelGroup;
import com.yoho.datasync.core.base.model.yh_pcms.PublicLabelGroup;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@Component
@MqConsumerListerner(dbName = "yh_grass",tableName = "grass_lable_group")
public class GrassLableGroupListener extends AbstractMqListener<GrassLabelGroup> {
@Resource
PublicLabelGroupService publicLabelGroupService;
@Resource
AnnotationClassFactory annotationClassFactory;
private static final Logger logger = LoggerFactory.getLogger(GrassLableGroupListener.class);
@Override
protected void deleteData(GrassLabelGroup sourceObject , Object checkResult) throws Exception {
PublicLabelGroup publicLabelGroup = annotationClassFactory.convertTargetObjectFromSource(sourceObject,
PublicLabelGroup.class);
if(publicLabelGroup == null){
logger.error("deleteData failed , publicLabelGroup is null");
return;
}
publicLabelGroup.setSrcChannel(ServiceConstant.SRCCHANNEL_TYPE.YOHO_GRASS);
publicLabelGroupService.deletePublicLabelGroup(publicLabelGroup);
}
@Override
protected void updateData(GrassLabelGroup sourceObject , Object checkResult) throws Exception {
PublicLabelGroup publicLabelGroup = annotationClassFactory.convertTargetObjectFromSource(sourceObject,PublicLabelGroup.class);
if(publicLabelGroup == null){
logger.error("updateData failed , publicLabelGroup is null");
return;
}
if(sourceObject.getStatus() != null){
switch (sourceObject.getStatus()){
case ServiceConstant.Grass_Label_Group.CLOSE_STATUS:
publicLabelGroup.setStatus(ServiceConstant.Public_Label_Group.CLOSE_STATUS);
break;
case ServiceConstant.Grass_Label_Group.OPEN_STATUS:
publicLabelGroup.setStatus(ServiceConstant.Public_Label_Group.OPEN_STATUS);
}
}
publicLabelGroup.setSrcChannel(ServiceConstant.SRCCHANNEL_TYPE.YOHO_GRASS);
publicLabelGroupService.saveOrUpdatePublicUserAttention(publicLabelGroup);
}
@Override
protected EventEnum getEventReportEnum() {
return EventEnum.GRASSLABELGROUPLISTENER_UPDATEDATA;
}
}
... ...
package com.yoho.datasync.consumer.service;
import com.yoho.datasync.consumer.common.BeanCopyUtils;
import com.yoho.datasync.consumer.dal.repository.PublicLabelGroupRepository;
import com.yoho.datasync.core.base.model.yh_pcms.PublicLabelGroup;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service
public class PublicLabelGroupService {
@Resource
private PublicLabelGroupRepository repository;
private static final Logger logger = LoggerFactory.getLogger(PublicLabelGroupService.class);
public void deletePublicLabelGroup(PublicLabelGroup publicLabelGroup) throws Exception{
Integer relateId = publicLabelGroup.getRelateId();
Integer srcChannel = publicLabelGroup.getSrcChannel();
PublicLabelGroup publicLabelGroupFromDB = getByRelateIdAndSrcChannel(relateId, srcChannel);
if (publicLabelGroupFromDB != null) {
repository.deleteById(publicLabelGroupFromDB.getId());
}else{
logger.error("deletePublicLabelGroup数据不存在relateId={}", publicLabelGroup.getRelateId());
throw new Exception("deletePublicLabelGroup失败");
}
}
public void saveOrUpdatePublicUserAttention(PublicLabelGroup publicLabelGroup) {
Integer relateId = publicLabelGroup.getRelateId();
Integer srcChannel = publicLabelGroup.getSrcChannel();
PublicLabelGroup publicLabelGroupFromDB = getByRelateIdAndSrcChannel(relateId, srcChannel);
if (publicLabelGroupFromDB != null) { //更新 需要保证原来的字段值不被null覆盖掉
publicLabelGroupFromDB = BeanCopyUtils.copyNonNullProperties(publicLabelGroup , publicLabelGroupFromDB ,
PublicLabelGroup.class);
repository.save(publicLabelGroupFromDB);
}else{ //新增
repository.save(publicLabelGroup);
}
}
private PublicLabelGroup getByRelateIdAndSrcChannel(Integer relateId , Integer srcChannel){
if(relateId == null || srcChannel == null){
return null;
}
return repository.findByRelateIdAndSrcChannel(relateId, srcChannel);
}
}
... ...
... ... @@ -43,8 +43,9 @@ public class PublicUserAttentionService {
if (publicUserAttentionFromDB != null) { //更新 需要保证原来的字段值不被null覆盖掉
publicUserAttentionFromDB = BeanCopyUtils.copyNonNullProperties(publicUserAttention , publicUserAttentionFromDB ,
PublicUserAttention.class);
}
repository.save(publicUserAttentionFromDB);
}else{
repository.save(publicUserAttention); //新增
}
}
}
... ...
... ... @@ -24,9 +24,10 @@ public class PublicUserCommentService {
if (publicUserCommentFromDB != null) { //更新 需要保证原来的字段值不被null覆盖掉
publicUserCommentFromDB = BeanCopyUtils.copyNonNullProperties(publicUserComment , publicUserCommentFromDB ,
PublicUserComment.class);
}
repository.save(publicUserCommentFromDB);
}else{
repository.save(publicUserComment); //新增
}
}
public void deletePublicUserComment(PublicUserComment publicUserComment) throws Exception{
... ...
... ... @@ -22,9 +22,10 @@ public class PublicUserFavoriteService {
PublicUserFavorite publicUserFavoriteFromDB = getPublicUserFavoriteByUniqueKey(publicUserFavorite);
if (publicUserFavoriteFromDB != null) { //更新
BeanCopyUtils.copyNonNullProperties(publicUserFavorite , publicUserFavoriteFromDB , PublicUserFavorite.class);
}
repository.save(publicUserFavoriteFromDB);
}else{
repository.save(publicUserFavorite); //新增
}
}
public void deletePublicUserPraise(PublicUserFavorite publicUserFavorite) throws Exception{
... ...
... ... @@ -22,11 +22,13 @@ public class PublicUserPraiseService {
PublicUserPraise publicUserPraiseFromDB = getPublicUserPraiseByUniqueKey(publicUserPraise);
if (publicUserPraiseFromDB != null) { //更新
BeanCopyUtils.copyNonNullProperties(publicUserPraise , publicUserPraiseFromDB , PublicUserPraise.class);
}
repository.save(publicUserPraiseFromDB);
}else{ //新增
repository.save(publicUserPraise);
}
}
public void deletePublicUserPraise(PublicUserPraise publicUserPraise) throws Exception{
PublicUserPraise publicUserPraiseFromDB = getPublicUserPraiseByUniqueKey(publicUserPraise);
if (publicUserPraiseFromDB != null) {
... ...