Commit 6b661824 authored by liwei's avatar liwei

新增了app评论删除

parent ee67f2c9
...@@ -144,4 +144,18 @@ public class AppOpmArticleController extends CyPaginationController<OpmArticle> ...@@ -144,4 +144,18 @@ public class AppOpmArticleController extends CyPaginationController<OpmArticle>
CyMessCons.MESSAGE_ALERT_ERROR, CyMessCons.MESSAGE_ALERT_ERROR,
dto); dto);
} }
/**
* 逻辑删除评论
*/
@PreAuthorize("@cyPerm.hasPerm('app:opmArticle:delete')")
@DeleteMapping("/deleteComment/{businessId:\\w+}")
public CyResult deleteComment(@PathVariable String businessId,@RequestBody ArticleCommentDTO dto) {
dto.setBusinessId(Integer.valueOf(businessId));
CyPersistModel data = opmArticleServiceImpl.removeComment(dto,"app");
return CyResultGenUtil.builder(data,
CyMessCons.MESSAGE_ALERT_SUCCESS,
CyMessCons.MESSAGE_ALERT_ERROR,
businessId);
}
} }
...@@ -146,9 +146,9 @@ public class OpmArticleController extends CyPaginationController<OpmArticle> { ...@@ -146,9 +146,9 @@ public class OpmArticleController extends CyPaginationController<OpmArticle> {
*/ */
@PreAuthorize("@cyPerm.hasPerm('cms:opmArticle:delete')") @PreAuthorize("@cyPerm.hasPerm('cms:opmArticle:delete')")
@DeleteMapping("/deleteComment/{businessId:\\w+}") @DeleteMapping("/deleteComment/{businessId:\\w+}")
public CyResult deleteComment(@PathVariable String businessId,OpmArticle opmArticle) { public CyResult deleteComment(@PathVariable String businessId,ArticleCommentDTO dto) {
opmArticle.setBusinessId(Integer.valueOf(businessId)); dto.setBusinessId(Integer.valueOf(businessId));
CyPersistModel data = opmArticleServiceImpl.removeComment(opmArticle); CyPersistModel data = opmArticleServiceImpl.removeComment(dto,"web");
return CyResultGenUtil.builder(data, return CyResultGenUtil.builder(data,
CyMessCons.MESSAGE_ALERT_SUCCESS, CyMessCons.MESSAGE_ALERT_SUCCESS,
CyMessCons.MESSAGE_ALERT_ERROR, CyMessCons.MESSAGE_ALERT_ERROR,
......
...@@ -50,7 +50,7 @@ public interface OpmArticleRepository extends CyBaseMapper<OpmArticle> { ...@@ -50,7 +50,7 @@ public interface OpmArticleRepository extends CyBaseMapper<OpmArticle> {
List<ArticleCommentVO> selectArticleChildrenComment(@Param("articleId") Integer articleId, @Param("parentId") Integer parentId, @Param("loginUserId") String loginUserId); List<ArticleCommentVO> selectArticleChildrenComment(@Param("articleId") Integer articleId, @Param("parentId") Integer parentId, @Param("loginUserId") String loginUserId);
//删除评论 //删除评论
int deleteComment(OpmArticle opmArticle); int deleteComment(ArticleCommentDTO dto);
//添加点赞记录 //添加点赞记录
int likeAdd(@Param("entity") LikeDTO likeDTO); int likeAdd(@Param("entity") LikeDTO likeDTO);
...@@ -73,6 +73,12 @@ public interface OpmArticleRepository extends CyBaseMapper<OpmArticle> { ...@@ -73,6 +73,12 @@ public interface OpmArticleRepository extends CyBaseMapper<OpmArticle> {
//动态表评论数+1 //动态表评论数+1
int addArticleCommentCount(Integer articleId); int addArticleCommentCount(Integer articleId);
//动态表评论数-1
int reduceArticleCommentCount(Integer articleId);
//评论表评论数-1
int reduceCommentCount(Integer commentId);
//评论表评论数+1 //评论表评论数+1
int addCommentCount(Integer commentId); int addCommentCount(Integer commentId);
...@@ -84,5 +90,20 @@ public interface OpmArticleRepository extends CyBaseMapper<OpmArticle> { ...@@ -84,5 +90,20 @@ public interface OpmArticleRepository extends CyBaseMapper<OpmArticle> {
//根据id查询评论信息 //根据id查询评论信息
ArticleCommentDTO findCommentById(Integer businessId); ArticleCommentDTO findCommentById(Integer businessId);
//根据动态id查询动态评论
List<ArticleCommentVO> selectArticleCommentCount(@Param("entity") OpmArticle article);
//根据评论id查询子评论数量
Integer selectArticleChildrenCommentCount(@Param("entity") ArticleCommentVO article);
//根据评论id修改动态的评论数量
int updateCommentById(@Param("entity") ArticleCommentVO commentVo);
//根据id查询评论信息
ArticleCommentVO selectCommentById(Integer businessId);
//根据动态id修改动态的评论数量
int updateArticleCommentCountById(@Param("entity") OpmArticle article);
} }
...@@ -7,7 +7,8 @@ import java.util.Date; ...@@ -7,7 +7,8 @@ import java.util.Date;
@Data @Data
public class ArticleCommentDTO { public class ArticleCommentDTO {
//主键
private Integer businessId;
//动态ID //动态ID
private Integer articleId; private Integer articleId;
//评论内容 //评论内容
...@@ -30,4 +31,6 @@ public class ArticleCommentDTO { ...@@ -30,4 +31,6 @@ public class ArticleCommentDTO {
private String remarks; private String remarks;
//评论id //评论id
private Integer commentId; private Integer commentId;
//删除标志
private String delFlag;
} }
...@@ -75,10 +75,10 @@ public interface OpmArticleService { ...@@ -75,10 +75,10 @@ public interface OpmArticleService {
/** /**
* 逻辑删除 评论 * 逻辑删除 评论
* @param opmArticle * @param dto
* @return * @return
*/ */
CyPersistModel removeComment(OpmArticle opmArticle); CyPersistModel removeComment(ArticleCommentDTO dto,String type);
/** /**
* 点赞增加点赞数 * 点赞增加点赞数
......
...@@ -273,9 +273,32 @@ public class OpmArticleServiceImpl extends ServiceImpl<OpmArticleRepository, Opm ...@@ -273,9 +273,32 @@ public class OpmArticleServiceImpl extends ServiceImpl<OpmArticleRepository, Opm
@Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT) @Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT)
@Override @Override
public CyPersistModel merge(OpmArticle opmArticle){ public CyPersistModel merge(OpmArticle opmArticle){
int line = baseMapper.updateById(opmArticle); //先查询该动态
log.debug(CyUserUtil.getAuthenUsername()+"修改了ID为"+ opmArticle.getBusinessId()+"的opmArticle管理信息"); QueryWrapper<OpmArticle> wrapper = new QueryWrapper<>();
wrapper.lambda().eq(OpmArticle::getBusinessId,opmArticle.getBusinessId());
List<OpmArticle> list = baseMapper.selectList(wrapper);
if (list.size() > 0){
OpmArticle article = list.get(0);
//查询该动态下的评论数
List<ArticleCommentVO> comment = baseMapper.selectArticleCommentCount(article);
//修改动态
article.setCommentCount(comment.size());//修改评论数
article.setExamStatus(opmArticle.getExamStatus());//修改审核状态
int line = baseMapper.updateById(article);
//修改子表的评论数 给父级评论数+1
for (ArticleCommentVO commentVo : comment) {
if (commentVo.getParentId() != null){
//查询评论的子评论数量
Integer commentCount = baseMapper.selectArticleChildrenCommentCount(commentVo);
//修改评论的评论数量
commentVo.setCommentCount(commentCount);
baseMapper.updateCommentById(commentVo);
}
}
return new CyPersistModel(line); return new CyPersistModel(line);
} else {
throw new CyServiceException(1001,"该动态已被用户删除!");
}
} }
/** /**
...@@ -466,17 +489,38 @@ public class OpmArticleServiceImpl extends ServiceImpl<OpmArticleRepository, Opm ...@@ -466,17 +489,38 @@ public class OpmArticleServiceImpl extends ServiceImpl<OpmArticleRepository, Opm
/** /**
* 逻辑删除 评论 * 逻辑删除 评论
* @param opmArticle * @param dto
* @return * @return
*/ */
@Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT) @Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT)
@Override @Override
public CyPersistModel removeComment(OpmArticle opmArticle){ public CyPersistModel removeComment(ArticleCommentDTO dto,String type){
opmArticle.setDeleted(); if (type.equals("app")){
int line = baseMapper.deleteComment(opmArticle); //app端
log.debug(CyUserUtil.getAuthenUsername()+"逻辑删除了ID为"+ //删除评论
opmArticle.getBusinessId()+"的opmArticleComment信息"); int line = baseMapper.deleteComment(dto);
return new CyPersistModel(line); int childrenCommentCount = 0;
if (dto.getParentId() != null){
//删除的子评论 需要减掉父评论的数量
baseMapper.reduceCommentCount(dto.getParentId());
} else {
//删除的是父评论 要查父评论下的子评论数量
ArticleCommentVO vo = new ArticleCommentVO();
vo.setParentId(dto.getBusinessId());
Integer count = baseMapper.selectArticleChildrenCommentCount(vo);
childrenCommentCount = count;
}
OpmArticle article = new OpmArticle();
article.setBusinessId(dto.getArticleId());
article.setCommentCount(childrenCommentCount + 1);
baseMapper.updateArticleCommentCountById(article);
return new CyPersistModel(1);
} else {
//web端
dto.setDelFlag("1");
int line = baseMapper.deleteComment(dto);
return new CyPersistModel(1);
}
} }
/** /**
......
...@@ -32,6 +32,11 @@ ...@@ -32,6 +32,11 @@
SET comment_count = comment_count + 1 SET comment_count = comment_count + 1
WHERE business_id = #{articleId}; WHERE business_id = #{articleId};
</update> </update>
<update id="reduceArticleCommentCount">
UPDATE opm_article
SET comment_count = comment_count - 1
WHERE business_id = #{articleId};
</update>
<update id="addCommentCount"> <update id="addCommentCount">
UPDATE opm_article_comment UPDATE opm_article_comment
SET comment_count = comment_count + 1 SET comment_count = comment_count + 1
...@@ -47,6 +52,21 @@ ...@@ -47,6 +52,21 @@
SET like_count = like_count + 1 SET like_count = like_count + 1
WHERE business_id = #{commentId}; WHERE business_id = #{commentId};
</update> </update>
<update id="reduceCommentCount">
UPDATE opm_article_comment
SET comment_count = comment_count - 1
WHERE business_id = #{commentId};
</update>
<update id="updateCommentById">
UPDATE opm_article_comment
SET comment_count = #{entity.commentCount}
WHERE business_id = #{entity.businessId};
</update>
<update id="updateArticleCommentCountById">
UPDATE opm_article
SET comment_count = comment_count - #{entity.commentCount}
WHERE business_id = #{entity.businessId};
</update>
<select id="queryOpmArticle" resultMap="BaseResultMap"> <select id="queryOpmArticle" resultMap="BaseResultMap">
select opa.*,sot.topic_name as topic,mi.mem_code as memCode select opa.*,sot.topic_name as topic,mi.mem_code as memCode
from opm_article opa from opm_article opa
...@@ -703,6 +723,30 @@ ...@@ -703,6 +723,30 @@
where 1=1 where 1=1
and business_id = #{businessId} and business_id = #{businessId}
</select> </select>
<select id="selectArticleCommentCount"
resultType="org.rcisoft.business.opmArticle.entity.ArticleCommentVO">
SELECT *
from opm_article_comment
WHERE 1=1
and del_flag = '0'
and flag = '1'
and exam_status = '1'
and article_id = #{entity.businessId}
</select>
<select id="selectArticleChildrenCommentCount" resultType="java.lang.Integer">
SELECT count(*)
from opm_article_comment
WHERE 1=1
and del_flag = '0'
and flag = '1'
and parent_id = #{entity.parentId}
</select>
<select id="selectCommentById" resultType="org.rcisoft.business.opmArticle.entity.ArticleCommentVO">
select *
from opm_article_comment
where 1=1
and business_id = #{businessId}
</select>
<delete id="deleteComment"> <delete id="deleteComment">
update opm_article_comment set del_flag = '1' where business_id = #{businessId} update opm_article_comment set del_flag = '1' where business_id = #{businessId}
and del_flag = '0' 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