Authored by liangyi.chen@yoho.cn

Fix Bug

... ... @@ -12,7 +12,8 @@ public enum EventEnum {
GRASS_LABEL_GROUP_UPDATEDATA("DealData", "GrassLabelGroupListener.dealData"),
GRASS_LABEL_UPDATEDATA("DealData", "GrassLabelGroupListener.dealData"),
GRASS_ARTICLE_LABEL_UPDATE("dealData", "GrassArticleLabelListener.dealData"),
GRASS_USER_ACHIEVE_UPDATE("dealData", "GrassUserAchieveListener.dealData");
GRASS_USER_ACHIEVE_UPDATE("dealData", "GrassUserAchieveListener.dealData"),
GRASS_VIRTUAL_USER_UPDATE("dealData", "GrassVirtualUserListener.dealData");
... ...
... ... @@ -65,17 +65,21 @@ public class GrassArticleCommentListener extends AbstractMqListener<GrassArticle
ServiceConstant.articleTypes);
publicUserComment.setArticleId(articleId);
//查询当前评论被回复的id,即GrassArticleComment中的parentId对应的评论ID
PublicUserComment publicUserCommentToComment = publicUserCommentService.getPublicUserCommentByUniqueKey
(sourceObject.getParentId(), ServiceConstant.SRCCHANNEL_TYPE.YOHO_GRASS);
if(publicUserCommentToComment != null){
publicUserComment.setToCommentId(publicUserCommentToComment.getId());
if(sourceObject.getParentId() != null){
PublicUserComment publicUserCommentToComment = publicUserCommentService.getPublicUserCommentByUniqueKey
(sourceObject.getParentId(), ServiceConstant.SRCCHANNEL_TYPE.YOHO_GRASS);
if(publicUserCommentToComment != null){
publicUserComment.setToCommentId(publicUserCommentToComment.getId());
}
}
//rootId设置:select id from public_user_comment where relate_id = #{grass_article_comment.root_id} and
// src_channel = 1;
PublicUserComment rootpublicUserComment = publicUserCommentService.getPublicUserCommentByUniqueKey
(sourceObject.getRootId() , ServiceConstant.SRCCHANNEL_TYPE.YOHO_GRASS);
if(rootpublicUserComment != null){
publicUserComment.setRootId(rootpublicUserComment.getId());
if(sourceObject.getRootId() != null){
PublicUserComment rootpublicUserComment = publicUserCommentService.getPublicUserCommentByUniqueKey
(sourceObject.getRootId() , ServiceConstant.SRCCHANNEL_TYPE.YOHO_GRASS);
if(rootpublicUserComment != null){
publicUserComment.setRootId(rootpublicUserComment.getId());
}
}
//将grass_article_comment.content的文本格式转换成public_user_comment.content_data的json格式
if(!StringUtils.isEmpty(sourceObject.getContent())){
... ... @@ -102,8 +106,6 @@ public class GrassArticleCommentListener extends AbstractMqListener<GrassArticle
publicUserComment.setAuditStatus(ServiceConstant.Public_User_Comment.NOPASS_AUDIT_STATUS);
}
}
publicUserCommentService.saveOrUpdatePublicUserComment(publicUserComment);
}
... ...
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.PublicVirtualUserService;
import com.yoho.datasync.core.base.annotation.MqConsumerListerner;
import com.yoho.datasync.core.base.model.yh_grass.GrassVirtualUser;
import com.yoho.datasync.core.base.model.yh_pcms.PublicVirtualUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@Component
@MqConsumerListerner(dbName = "yh_grass",tableName = "grass_virtual_user")
public class GrassVirtualUserListener extends AbstractMqListener<GrassVirtualUser> {
@Resource
PublicVirtualUserService publicVirtualUserService;
@Resource
AnnotationClassFactory annotationClassFactory;
private static final Logger logger = LoggerFactory.getLogger(GrassVirtualUserListener.class);
@Override
protected void deleteData(GrassVirtualUser sourceObject , Object checkResult) throws Exception {
PublicVirtualUser publicVirtualUser = annotationClassFactory.convertTargetObjectFromSource(sourceObject,
PublicVirtualUser.class);
if(publicVirtualUser == null){
logger.error("deleteData failed , publicVirtualUser is null");
return;
}
publicVirtualUser.setSrcChannel(ServiceConstant.SRCCHANNEL_TYPE.YOHO_GRASS);
publicVirtualUserService.deletePbulicVirtualUser(publicVirtualUser);
}
@Override
protected void updateData(GrassVirtualUser sourceObject , Object checkResult) throws Exception {
PublicVirtualUser publicVirtualUser = annotationClassFactory.convertTargetObjectFromSource(sourceObject,
PublicVirtualUser.class);
if(publicVirtualUser == null){
logger.error("updateData failed , publicVirtualUser is null");
return;
}
publicVirtualUser.setSrcChannel(ServiceConstant.SRCCHANNEL_TYPE.YOHO_GRASS);
publicVirtualUserService.saveOrUpdatePbulicVirtualUser(publicVirtualUser);
}
@Override
protected EventEnum getEventReportEnum() {
return EventEnum.GRASS_VIRTUAL_USER_UPDATE;
}
}
... ...
... ... @@ -21,7 +21,7 @@ public class PublicLabelGroupService {
public void deletePublicLabelGroup(PublicLabelGroup publicLabelGroup) throws Exception{
Integer relateId = publicLabelGroup.getRelateId();
Integer srcChannel = publicLabelGroup.getSrcChannel();
PublicLabelGroup publicLabelGroupFromDB = getByRelateIdAndSrcChannel(relateId, srcChannel);
PublicLabelGroup publicLabelGroupFromDB = getPublicLableGroupByRelateIdAndSrcChannel(relateId, srcChannel);
if (publicLabelGroupFromDB != null) {
repository.deleteById(publicLabelGroupFromDB.getId());
}else{
... ... @@ -30,10 +30,10 @@ public class PublicLabelGroupService {
}
}
public void saveOrUpdatePublicLabelGroup(PublicLabelGroup publicLabelGroup) {
public void saveOrUpdatePublicLabelGroup(PublicLabelGroup publicLabelGroup)throws Exception {
Integer relateId = publicLabelGroup.getRelateId();
Integer srcChannel = publicLabelGroup.getSrcChannel();
PublicLabelGroup publicLabelGroupFromDB = getByRelateIdAndSrcChannel(relateId, srcChannel);
PublicLabelGroup publicLabelGroupFromDB = getPublicLableGroupByRelateIdAndSrcChannel(relateId, srcChannel);
if (publicLabelGroupFromDB != null) { //更新 需要保证原来的字段值不被null覆盖掉
publicLabelGroupFromDB = BeanCopyUtils.copyNonNullProperties(publicLabelGroup , publicLabelGroupFromDB ,
PublicLabelGroup.class);
... ... @@ -43,9 +43,10 @@ public class PublicLabelGroupService {
}
}
private PublicLabelGroup getByRelateIdAndSrcChannel(Integer relateId , Integer srcChannel){
private PublicLabelGroup getPublicLableGroupByRelateIdAndSrcChannel(Integer relateId , Integer srcChannel)throws Exception{
if(relateId == null || srcChannel == null){
return null;
logger.error("参数错误relateId={},srcChannel={}", relateId , srcChannel);
throw new Exception("getPublicLableGroupByRelateIdAndSrcChannel参数错误");
}
return repository.findByRelateIdAndSrcChannel(relateId, srcChannel);
}
... ...
... ... @@ -20,7 +20,7 @@ public class PublicLabelService {
public void deletePublicLabel(PublicLabel publicLabel) throws Exception {
Integer relateId = publicLabel.getRelateId();
Integer srcChannel = publicLabel.getSrcChannel();
PublicLabel publicLabelFromDB = getByRelateIdAndSrcChannel(relateId, srcChannel);
PublicLabel publicLabelFromDB = getPublicLableByRelateIdAndSrcChannel(relateId, srcChannel);
if (publicLabelFromDB != null) {
repository.deleteById(publicLabelFromDB.getId());
} else {
... ... @@ -29,10 +29,10 @@ public class PublicLabelService {
}
}
public void saveOrUpdatePublicLabel(PublicLabel publicLabel) {
public void saveOrUpdatePublicLabel(PublicLabel publicLabel) throws Exception{
Integer relateId = publicLabel.getRelateId();
Integer srcChannel = publicLabel.getSrcChannel();
PublicLabel publicLabelFromDB = getByRelateIdAndSrcChannel(relateId, srcChannel);
PublicLabel publicLabelFromDB = getPublicLableByRelateIdAndSrcChannel(relateId, srcChannel);
if (publicLabelFromDB != null) { //更新 需要保证原来的字段值不被null覆盖掉
publicLabelFromDB = BeanCopyUtils.copyNonNullProperties(publicLabel, publicLabelFromDB,
PublicLabel.class);
... ... @@ -42,9 +42,10 @@ public class PublicLabelService {
}
}
private PublicLabel getByRelateIdAndSrcChannel(Integer relateId, Integer srcChannel) {
private PublicLabel getPublicLableByRelateIdAndSrcChannel(Integer relateId, Integer srcChannel)throws Exception {
if (relateId == null || srcChannel == null) {
return null;
logger.error("参数错误relateId={},srcChannel={}", relateId , srcChannel);
throw new Exception("getPublicLableByRelateIdAndSrcChannel参数错误");
}
return repository.findByRelateIdAndSrcChannel(relateId, srcChannel);
}
... ...
... ... @@ -30,14 +30,16 @@ public class PublicUserAttentionService {
}
}
private PublicUserAttention getPublicUserAttentionByUniqueKey(Integer uid , Integer attentionType , Integer targetId){
private PublicUserAttention getPublicUserAttentionByUniqueKey(Integer uid , Integer attentionType , Integer targetId)
throws Exception{
if(uid == null || attentionType == null || targetId == null){
return null;
logger.error("参数错误uid={},attentionType={},targetId={}", uid , attentionType , targetId);
throw new Exception("getPublicUserAttentionByUniqueKey参数错误");
}
return repository.findByUidAndAttentionTypeAndTargetId(uid , attentionType , targetId);
}
public void saveOrUpdatePublicUserAttention(PublicUserAttention publicUserAttention) {
public void saveOrUpdatePublicUserAttention(PublicUserAttention publicUserAttention) throws Exception{
PublicUserAttention publicUserAttentionFromDB = getPublicUserAttentionByUniqueKey(publicUserAttention.getUid(),
publicUserAttention.getAttentionType(),publicUserAttention.getTargetId());
if (publicUserAttentionFromDB != null) { //更新 需要保证原来的字段值不被null覆盖掉
... ...
... ... @@ -18,7 +18,7 @@ public class PublicUserCommentService {
private static final Logger logger = LoggerFactory.getLogger(PublicUserCommentService.class);
public void saveOrUpdatePublicUserComment(PublicUserComment publicUserComment) {
public void saveOrUpdatePublicUserComment(PublicUserComment publicUserComment) throws Exception {
PublicUserComment publicUserCommentFromDB = getPublicUserCommentByUniqueKey(publicUserComment.getRelateId(),
publicUserComment.getSrcChannel());
if (publicUserCommentFromDB != null) { //更新 需要保证原来的字段值不被null覆盖掉
... ... @@ -42,10 +42,10 @@ public class PublicUserCommentService {
}
}
public PublicUserComment getPublicUserCommentByUniqueKey(Integer relateId , Integer srcChannel){
public PublicUserComment getPublicUserCommentByUniqueKey(Integer relateId , Integer srcChannel) throws Exception{
if(relateId == null || srcChannel == null){
logger.error("relateId={},srcChannel={}", relateId , srcChannel);
return null;
logger.error("参数错误relateId={},srcChannel={}", relateId , srcChannel);
throw new Exception("getPublicUserCommentByUniqueKey参数错误");
}
return repository.findByRelateIdAndSrcChannel(relateId , srcChannel);
}
... ...
... ... @@ -18,7 +18,7 @@ public class PublicUserFavoriteService {
private static final Logger logger = LoggerFactory.getLogger(PublicUserFavoriteService.class);
public void saveOrUpdatePublicUserPraise(PublicUserFavorite publicUserFavorite) {
public void saveOrUpdatePublicUserPraise(PublicUserFavorite publicUserFavorite)throws Exception {
PublicUserFavorite publicUserFavoriteFromDB = getPublicUserFavoriteByUniqueKey(publicUserFavorite);
if (publicUserFavoriteFromDB != null) { //更新
BeanCopyUtils.copyNonNullProperties(publicUserFavorite , publicUserFavoriteFromDB , PublicUserFavorite.class);
... ... @@ -39,14 +39,14 @@ public class PublicUserFavoriteService {
}
}
private PublicUserFavorite getPublicUserFavoriteByUniqueKey(PublicUserFavorite publicUserFavorite){
private PublicUserFavorite getPublicUserFavoriteByUniqueKey(PublicUserFavorite publicUserFavorite) throws Exception{
//来源类型,收藏对象,和收藏着uid确定唯一一条记录
Integer srcChannel = publicUserFavorite.getSrcChannel();
Integer uid = publicUserFavorite.getUid();
Integer targetId = publicUserFavorite.getTargetId();
if(srcChannel == null || uid == null || targetId == null){
logger.error("参数不合法srcChannel={},uid={},targetId={}", srcChannel , uid , targetId);
return null;
throw new Exception("getPublicUserFavoriteByUniqueKey参数错误");
}
return repository.findByUidAndSrcChannelAndTargetId(uid , srcChannel , targetId);
}
... ...
... ... @@ -30,7 +30,7 @@ public class PublicUserHomepageService {
}
}
public void saveOrUpdatePbulicUserHomepage(PublicUserHomepage publicUserHomepage) {
public void saveOrUpdatePbulicUserHomepage(PublicUserHomepage publicUserHomepage)throws Exception {
Integer uid = publicUserHomepage.getUid();
Integer userType = publicUserHomepage.getUserType();
Integer srcChannel = publicUserHomepage.getSrcChannel();
... ... @@ -44,9 +44,10 @@ public class PublicUserHomepageService {
}
}
private PublicUserHomepage getByUidAndUserTypeAndSrcChannel(Integer uid , Integer userType , Integer srcChannel){
private PublicUserHomepage getByUidAndUserTypeAndSrcChannel(Integer uid , Integer userType , Integer srcChannel)throws Exception{
if(uid == null || userType == null || srcChannel == null){
return null;
logger.error("参数不合法srcChannel={},uid={},userType={}", srcChannel , uid , userType);
throw new Exception("getByUidAndUserTypeAndSrcChannel参数错误");
}
return repository.findByUidAndUserTypeAndSrcChannel(uid , userType , srcChannel);
}
... ...
... ... @@ -18,7 +18,7 @@ public class PublicUserPraiseService {
private static final Logger logger = LoggerFactory.getLogger(PublicUserPraiseService.class);
public void saveOrUpdatePublicUserPraise(PublicUserPraise publicUserPraise) {
public void saveOrUpdatePublicUserPraise(PublicUserPraise publicUserPraise)throws Exception {
PublicUserPraise publicUserPraiseFromDB = getPublicUserPraiseByUniqueKey(publicUserPraise);
if (publicUserPraiseFromDB != null) { //更新
BeanCopyUtils.copyNonNullProperties(publicUserPraise , publicUserPraiseFromDB , PublicUserPraise.class);
... ... @@ -40,14 +40,14 @@ public class PublicUserPraiseService {
}
}
private PublicUserPraise getPublicUserPraiseByUniqueKey(PublicUserPraise publicUserPraise){
private PublicUserPraise getPublicUserPraiseByUniqueKey(PublicUserPraise publicUserPraise)throws Exception{
//点赞类型,点赞对象,和点赞者id确定唯一一条记录
Integer praiseType = publicUserPraise.getPraiseType();
Integer uid = publicUserPraise.getUid();
Integer targetId = publicUserPraise.getTargetId();
if(praiseType == null || uid == null || targetId == null){
logger.error("参数不合法praiseType={},uid={},targetId={}", praiseType , uid , targetId);
return null;
throw new Exception("getPublicUserPraiseByUniqueKey参数错误");
}
return repository.findByUidAndPraiseTypeAndTargetId(uid , praiseType , targetId);
}
... ...
... ... @@ -20,7 +20,7 @@ public class PublicVirtualUserService {
public void deletePbulicVirtualUser(PublicVirtualUser publicVirtualUser) throws Exception{
Integer uid = publicVirtualUser.getUid();
Integer srcChannel = publicVirtualUser.getSrcChannel();
PublicVirtualUser publicVirtualUserFromDB = getByUidAndUserTypeAndSrcChannel(uid , srcChannel);
PublicVirtualUser publicVirtualUserFromDB = getPublicVirtualUserByUidAndAndSrcChannel(uid , srcChannel);
if (publicVirtualUserFromDB != null) {
repository.deleteById(publicVirtualUserFromDB.getId());
}else{
... ... @@ -29,10 +29,10 @@ public class PublicVirtualUserService {
}
}
public void saveOrUpdatePbulicVirtualUser(PublicVirtualUser publicVirtualUser) {
public void saveOrUpdatePbulicVirtualUser(PublicVirtualUser publicVirtualUser) throws Exception{
Integer uid = publicVirtualUser.getUid();
Integer srcChannel = publicVirtualUser.getSrcChannel();
PublicVirtualUser publicVirtualUserFromDB = getByUidAndUserTypeAndSrcChannel(uid , srcChannel);
PublicVirtualUser publicVirtualUserFromDB = getPublicVirtualUserByUidAndAndSrcChannel(uid , srcChannel);
if (publicVirtualUserFromDB != null) { //更新 需要保证原来的字段值不被null覆盖掉
publicVirtualUserFromDB = BeanCopyUtils.copyNonNullProperties(publicVirtualUser , publicVirtualUserFromDB ,
PublicVirtualUser.class);
... ... @@ -42,9 +42,10 @@ public class PublicVirtualUserService {
}
}
private PublicVirtualUser getByUidAndUserTypeAndSrcChannel(Integer uid , Integer srcChannel){
private PublicVirtualUser getPublicVirtualUserByUidAndAndSrcChannel(Integer uid , Integer srcChannel)throws Exception{
if(uid == null || srcChannel == null){
return null;
logger.error("参数不合法srcChannel={},uid={}", srcChannel , uid);
throw new Exception("getPublicVirtualUserByUidAndAndSrcChannel参数错误");
}
return repository.findByUidAndSrcChannel(uid , srcChannel);
}
... ...
... ... @@ -4,7 +4,6 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication(scanBasePackages = "com.yoho.datasync")
... ... @@ -17,8 +16,4 @@ public class YohoDatasyncConsumerApplication {
SpringApplication.run(YohoDatasyncConsumerApplication.class, args);
}
@RequestMapping("/test")
public String test(){
return "200";
}
}
... ...