Authored by liangyi.chen@yoho.cn

公共评论表

package com.yoho.datasync.consumer.handler.helper;
package com.yoho.datasync.consumer.common;
import org.springframework.beans.BeanUtils;
... ...
... ... @@ -21,4 +21,23 @@ public class ServiceConstant {
Integer COMMENT_PHRAISE = 2;
}
public interface Grass_Article_Comment{
/**
* 种草的文章评论状态 (0 待审核,1通过,2未通过)
*/
int TO_AUDIT_Status = 0;
int PASS_AUDIT_STATUS = 1;
int NOPASS_AUDIT_STATUS = 2;
}
public interface Public_User_Comment{
/**
* 公共库的用户评论状态(1-未审核 2-审核通过 3-审核未通过)
*/
int TO_AUDIT_Status = 1;
int PASS_AUDIT_STATUS = 2;
int NOPASS_AUDIT_STATUS = 3;
}
}
... ...
... ... @@ -8,7 +8,6 @@ public interface PublicArticleRepository extends JpaRepository<PublicArticle, In
PublicArticle findByRelateIdAndArticleType(Integer relateId, Integer articleType);
@Query("select article from PublicArticle article where article.relateId=?1 and article.articleType in (?2)")
PublicArticle findByRelateIdInArticleTypes(Integer relateId, int[] types);
... ...
package com.yoho.datasync.consumer.handler.listener;
import com.alibaba.fastjson.JSON;
import com.yoho.datasync.consumer.common.EventEnum;
import com.yoho.datasync.consumer.common.ServiceConstant;
import com.yoho.datasync.consumer.handler.helper.AnnotationClassFactory;
... ... @@ -14,8 +15,11 @@ import com.yoho.datasync.core.base.model.yh_pcms.PublicUserPraise;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
@Component
@MqConsumerListerner(dbName = "yh_grass",tableName = "grass_article_comment")
... ... @@ -66,6 +70,44 @@ public class PublicUserCommentListener extends AbstractMqListener<GrassArticleCo
if(publicArticle != null){
publicUserComment.setArticleId(publicArticle.getId());
}
//查询当前评论被回复的id,即GrassArticleComment中的parentId对应的评论ID
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());
}
//将grass_article_comment.content的文本格式转换成public_user_comment.content_data的json格式
if(!StringUtils.isEmpty(sourceObject.getContent())){
Map<String , String> contentMap = new HashMap<>();
contentMap.put("type" , "text");
contentMap.put("content" , sourceObject.getContent());
publicUserComment.setContentData(JSON.toJSONString(contentMap));
}
//grass_article_comment.status>0时,public_user_comment.audit_time =grass_article_comment.update_time
//grass_article_comment.status(0 待审核,1通过,2未通过)和public_user_comment.audit_status
// (1-未审核 2-审核通过 3-审核未通过)转换
if(sourceObject.getStatus() != null){
if(sourceObject.getStatus() > 0){
publicUserComment.setAuditTime(Long.valueOf(sourceObject.getUpdateTime()));
}
switch (sourceObject.getStatus()){
case ServiceConstant.Grass_Article_Comment.TO_AUDIT_Status :
publicUserComment.setAuditStatus(ServiceConstant.Public_User_Comment.TO_AUDIT_Status);
break;
case ServiceConstant.Grass_Article_Comment.PASS_AUDIT_STATUS :
publicUserComment.setAuditStatus(ServiceConstant.Public_User_Comment.PASS_AUDIT_STATUS);
break;
case ServiceConstant.Grass_Article_Comment.NOPASS_AUDIT_STATUS :
publicUserComment.setAuditStatus(ServiceConstant.Public_User_Comment.NOPASS_AUDIT_STATUS);
}
}
publicUserCommentService.saveOrUpdatePublicUserComment(publicUserComment);
... ...
package com.yoho.datasync.consumer.service;
import com.yoho.datasync.consumer.common.BeanCopyUtils;
import com.yoho.datasync.consumer.dal.repository.PublicUserCommentRepository;
import com.yoho.datasync.core.base.model.yh_pcms.PublicUserComment;
import org.slf4j.Logger;
... ... @@ -18,16 +19,19 @@ public class PublicUserCommentService {
private static final Logger logger = LoggerFactory.getLogger(PublicUserCommentService.class);
public void saveOrUpdatePublicUserComment(PublicUserComment publicUserComment) {
PublicUserComment publicUserCommentFromDB = getPublicUserCommentByUniqueKey(publicUserComment);
PublicUserComment publicUserCommentFromDB = getPublicUserCommentByUniqueKey(publicUserComment.getRelateId(),
publicUserComment.getSrcChannel());
if (publicUserCommentFromDB != null) { //更新 需要保证原来的字段值不被null覆盖掉
publicUserCommentFromDB.setId(publicUserCommentFromDB.getId());
publicUserCommentFromDB = BeanCopyUtils.copyNonNullProperties(publicUserComment , publicUserCommentFromDB ,
PublicUserComment.class);
}
repository.save(publicUserComment);
repository.save(publicUserCommentFromDB);
}
public void deletePublicUserComment(PublicUserComment publicUserComment) throws Exception{
PublicUserComment publicUserCommentFromDB = getPublicUserCommentByUniqueKey(publicUserComment);
PublicUserComment publicUserCommentFromDB = getPublicUserCommentByUniqueKey(publicUserComment.getRelateId(),
publicUserComment.getSrcChannel());
if (publicUserCommentFromDB != null) {
repository.deleteById(publicUserCommentFromDB.getId());
}else{
... ... @@ -37,9 +41,7 @@ public class PublicUserCommentService {
}
}
public PublicUserComment getPublicUserCommentByUniqueKey(PublicUserComment publicUserComment){
Integer relateId = publicUserComment.getRelateId();
Integer srcChannel = publicUserComment.getSrcChannel();
public PublicUserComment getPublicUserCommentByUniqueKey(Integer relateId , Integer srcChannel){
if(relateId == null || srcChannel == null){
logger.error("relateId={},srcChannel={}", relateId , srcChannel);
return null;
... ...