您的位置:首页 > 其它

使用二叉树修改帖子及其回复贴的状态

2018-01-04 14:44 239 查看
要屏蔽某个帖子及其下的所有子节点的操作

1、mapper.xml

<update id="updateById">
update post
<set>
<if test="status != null">
status = #{status,jdbcType=TINYINT},
</if>
<if test="operateTime != null">
operate_time = #{operateTime,jdbcType=TIMESTAMP},
</if>
<if test="userId!= null">
user_id= #{userId,jdbcType=VARCHAR}
</if>
</set>
WHERE id IN
<foreach collection="ids" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</update>

2、mapper

void updateById(@Param("status") int status, @Param("operateTime") Date operateTime, @Param("userId") String userId, @Param("ids") List<String> ids);

3、serviceImpl

@Transactional
@Override
public void shieldingPost(String userId, String postId, int status) {

//帖子ID及其下所有回复贴ID,用于修改状态
List<String> ids = new ArrayList<>();
ids.add(postId);

//用于查询帖子下的回复贴ID
List<String> findIds = new ArrayList<>();
findIds.add(postId);
while (true) {
//查询所有父级帖为当前id的所有帖子id
List<String> postIds = postDefinedMapper.findChildrenIdList(findIds);
if (CollectionUtils.isEmpty(postIds)) {
break;
}
for (String p : postIds) {
postId = p;
ids.add(postId);
}
findIds = postIds;
}
Date operateTime = new Date();
postDefinedMapper.updateById(status, operateTime, userId, ids);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐