提交 3a216db4 authored 作者: 吴德鹏's avatar 吴德鹏

帖子管理优化

上级 be0f0664
......@@ -116,9 +116,16 @@ public class PostController {
@ResponseBody
public R placedPostTop(@PathVariable("id") String id) {
postService.placedPostTop(id);
return R.ok();
int res = postService.placedPostTop(id);
if (res > 0) {
return R.ok();
} else if (res == 0) {
return R.error("置顶数量最多4个");
} else if (res == -1) {
return R.error("改帖子已下线或删除");
}
return R.error("操作失败");
}
......
......@@ -11,7 +11,9 @@ import org.apache.ibatis.annotations.Param;
*/
public interface PostDao extends BaseDao<PostEntity> {
int changePostStatus(@Param("archived")Integer archived,@Param("ids") String ids[]);
int changePostStatus(@Param("archived") Integer archived, @Param("ids") String ids[]);
int placedTop(Integer id, Integer isTop);
int getPostTopNum();
}
......@@ -132,6 +132,18 @@ public class PostServiceImpl implements PostService {
*/
@Override
public int changeStatus(Integer archived, String[] ids) {
System.err.println("======>>>>>" + archived);
//下线帖子
if ("2".equals(archived.toString())) {
for (int i = 0; i < ids.length; i++) {
PostEntity post = postDao.queryObject(ids[i]);
Integer isTop = post.getIsTop();
if ("1".equals(isTop.toString())) {
post.setIsTop(0);//取消置顶
postDao.update(post);
}
}
}
return postDao.changePostStatus(archived, ids);
}
......@@ -144,10 +156,22 @@ public class PostServiceImpl implements PostService {
*/
@Override
public int placedPostTop(String id) {
int res = 0;
//根据ID查询帖子信息
PostEntity post = postDao.queryObject(id);
Integer isTop = post.getIsTop();
post.setIsTop(isTop == 0 ? 1 : 0);
return postDao.update(post);
Integer isTop = post.getIsTop();//置顶标志
Integer archived = post.getArchived();//状态
//最多置顶4个帖子
if (postDao.getPostTopNum() >= 4 && "0".equals(isTop.toString())) {
return res;
}
if ("1".equals(archived.toString())) {
post.setIsTop(isTop == 0 ? 1 : 0);
res = postDao.update(post);
} else {
res = -1;
}
return res;
}
}
......@@ -174,4 +174,9 @@
#{id}
</foreach>
</update>
<!--统计置顶帖子数量-->
<select id="getPostTopNum" resultType="int">
select count(1) from post where is_top=1 and archived=1
</select>
</mapper>
\ No newline at end of file
......@@ -211,7 +211,7 @@ let vm = new Vue({
if (!vm.isShow) {
vm.post.archived = 2;
} else {
vm.post.isShow = 1;
vm.post.archived = 1;
}
let url = vm.post.id == null ? "../post/save" : "../post/update";
vm.post.picture = this.uploadList.map(res => res).join(',');
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论