Commit b7c0a691 authored by liwei's avatar liwei

修改了动态评论接口

parent cc6c0e71
......@@ -112,7 +112,7 @@ public class AppOpmArticleController extends CyPaginationController<OpmArticle>
return CyResultGenUtil.builder(new CyPersistModel(1),
CyMessCons.MESSAGE_ALERT_SUCCESS,
CyMessCons.MESSAGE_ALERT_ERROR,
opmArticleServiceImpl.findById(businessId));
opmArticleServiceImpl.findById(businessId,"app"));
}
/**
......
......@@ -103,7 +103,7 @@ public class OpmArticleController extends CyPaginationController<OpmArticle> {
return CyResultGenUtil.builder(new CyPersistModel(1),
CyMessCons.MESSAGE_ALERT_SUCCESS,
CyMessCons.MESSAGE_ALERT_ERROR,
opmArticleServiceImpl.findById(businessId));
opmArticleServiceImpl.findById(businessId, "web"));
}
@PreAuthorize("@cyPerm.hasPerm('cms:opmArticle:query')")
......
......@@ -37,9 +37,12 @@ public interface OpmArticleRepository extends CyBaseMapper<OpmArticle> {
OpmArticle selectArticleDetail(@Param("articleId") Integer articleId, @Param("loginUserId") String loginUserId);
//查询评论
//web查询评论
List<ArticleCommentVO> selectArticleComment(@Param("articleId") Integer articleId, @Param("loginUserId") String loginUserId);
//app查询评论
List<ArticleCommentVO> appSelectArticleComment(@Param("articleId") Integer articleId, @Param("loginUserId") String loginUserId);
//查询评论下的子评论
List<ArticleCommentVO> selectArticleChildrenComment(@Param("articleId") Integer articleId, @Param("parentId") Integer parentId, @Param("loginUserId") String loginUserId);
......@@ -75,5 +78,8 @@ public interface OpmArticleRepository extends CyBaseMapper<OpmArticle> {
//查询某个人的动态列表
IPage<OpmArticle> queryUserArticlePaged(CyPageInfo cyPageInfo, @Param("entity") OpmArticle opmArticle);
//根据id查询评论信息
ArticleCommentDTO findCommentById(Integer businessId);
}
......@@ -28,4 +28,6 @@ public class ArticleCommentDTO {
private String examStatus;
//备注
private String remarks;
//评论id
private Integer commentId;
}
......@@ -48,7 +48,7 @@ public interface OpmArticleService {
* @param id
* @return
*/
OpmArticle findById(Integer id);
OpmArticle findById(Integer id,String type);
/**
* 分页查询 opmArticle管理
......
......@@ -247,19 +247,34 @@ public class OpmArticleServiceImpl extends ServiceImpl<OpmArticleRepository, Opm
* @return
*/
@Override
public OpmArticle findById(Integer articleId){
String loginUserId = CyUserUtil.getAuthenBusinessId();
//根据动态id 查询动态详情
OpmArticle opmArticle = baseMapper.selectArticleDetail(articleId,loginUserId);
//查询该动态的评论
List<ArticleCommentVO> list = baseMapper.selectArticleComment(opmArticle.getBusinessId(),loginUserId);
list.forEach(item -> {
//查询该条评论下的子评论
List<ArticleCommentVO> childrenCommentList = baseMapper.selectArticleChildrenComment(opmArticle.getBusinessId(),item.getBusinessId(),loginUserId);
item.setChildrenCommentList(childrenCommentList);
});
opmArticle.setArticleCommentVOList(list);
return opmArticle;
public OpmArticle findById(Integer articleId,String type){
if (type.equals("app")){
String loginUserId = CyUserUtil.getAuthenBusinessId();
//根据动态id 查询动态详情
OpmArticle opmArticle = baseMapper.selectArticleDetail(articleId,loginUserId);
//查询该动态的评论
List<ArticleCommentVO> list = baseMapper.appSelectArticleComment(opmArticle.getBusinessId(),loginUserId);
list.forEach(item -> {
//查询该条评论下的子评论
List<ArticleCommentVO> childrenCommentList = baseMapper.selectArticleChildrenComment(opmArticle.getBusinessId(),item.getBusinessId(),loginUserId);
item.setChildrenCommentList(childrenCommentList);
});
opmArticle.setArticleCommentVOList(list);
return opmArticle;
} else {
String loginUserId = CyUserUtil.getAuthenBusinessId();
//根据动态id 查询动态详情
OpmArticle opmArticle = baseMapper.selectArticleDetail(articleId,loginUserId);
//查询该动态的评论
List<ArticleCommentVO> list = baseMapper.selectArticleComment(opmArticle.getBusinessId(),loginUserId);
list.forEach(item -> {
//查询该条评论下的子评论
List<ArticleCommentVO> childrenCommentList = baseMapper.selectArticleChildrenComment(opmArticle.getBusinessId(),item.getBusinessId(),loginUserId);
item.setChildrenCommentList(childrenCommentList);
});
opmArticle.setArticleCommentVOList(list);
return opmArticle;
}
}
/**
......@@ -504,7 +519,18 @@ public class OpmArticleServiceImpl extends ServiceImpl<OpmArticleRepository, Opm
String nowDate = now.format(formatter);
//获取动态创建时间
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String createDate = sdf.format(dto.getCreateDate());
//根据parentId查询需要回复的评论信息
ArticleCommentDTO comment = baseMapper.findCommentById(dto.getCommentId());
String createDate = "";//动态创建时间
Integer commentedUserId = null;//被评论人id
if (comment == null){
//发的是第一级评论
createDate = sdf.format(new Date());
commentedUserId = Integer.valueOf(userId);
} else {
createDate = String.valueOf(comment.getCreateDate());
commentedUserId = comment.getCreateBy();
}
try {
//计算当前时间和动态创建时间的秒数差
long timeSeconds = TimeUtil.getTimeSecond(createDate,nowDate);
......@@ -535,9 +561,11 @@ public class OpmArticleServiceImpl extends ServiceImpl<OpmArticleRepository, Opm
dto.setExamStatus("3");
dto.setRemarks(msg.toString());
}
} else {
dto.setExamStatus("0");
}
//4、校验通过 进行插入评论数据
dto.setCommentedUserId(Integer.valueOf(CyUserUtil.getAuthenBusinessId()));
dto.setCommentedUserId(commentedUserId);
dto.setCreateDate(new Date());
dto.setUpdateDate(new Date());
dto.setCreateBy(Integer.valueOf(CyUserUtil.getAuthenBusinessId()));
......
......@@ -392,13 +392,41 @@
AND opc.del_flag = '0'
AND opc.parent_id is null
AND opc.article_id = #{articleId}
and opc.exam_status = '1'
AND NOT EXISTS (
SELECT 1 FROM opm_black_list obl
WHERE (obl.user_id = #{loginUserId} AND obl.target_id = opc.user_id)
OR (obl.user_id = opc.user_id AND obl.target_id = #{loginUserId})
)
</select>
<select id="appSelectArticleComment" resultType="org.rcisoft.business.opmArticle.entity.ArticleCommentVO">
SELECT opc.business_id,
opc.content,
opc.parent_id,
opc.create_date,
opc.like_count,
opc.comment_count,
opc.create_by AS userId,
opc.user_id AS commentedUserId,
mi.mem_code as memCode,
mi.mem_nick_name as memNickName,
mi.avatar as avatarId,
CASE
WHEN oal.business_id IS NOT NULL THEN 1 ELSE 0
END AS isLike
FROM opm_article_comment opc
LEFT JOIN mem_info mi ON mi.user_id = opc.create_by
LEFT JOIN opm_article_like oal on oal.comment_id = opc.business_id and oal.user_id = #{loginUserId}
WHERE 1 = 1
AND opc.del_flag = '0'
AND opc.parent_id is null
AND opc.article_id = #{articleId}
and opc.exam_status = '1'
AND NOT EXISTS (
SELECT 1 FROM opm_black_list obl
WHERE (obl.user_id = #{loginUserId} AND obl.target_id = opc.user_id)
OR (obl.user_id = opc.user_id AND obl.target_id = #{loginUserId})
)
</select>
<select id="selectArticleChildrenComment" resultType="org.rcisoft.business.opmArticle.entity.ArticleCommentVO">
SELECT
opc.business_id,
......@@ -431,6 +459,12 @@
OR (obl.user_id = opc.user_id AND obl.target_id = #{loginUserId})
)
</select>
<select id="findCommentById" resultType="org.rcisoft.business.opmArticle.entity.ArticleCommentDTO">
select *
from opm_article_comment
where 1=1
and business_id = #{businessId}
</select>
<delete id="deleteComment">
update opm_article_comment set del_flag = '1' where business_id = #{businessId}
and del_flag = '0'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment