diff --git a/src/main/java/io/linfeng/modules/admin/controller/CommentController.java b/src/main/java/io/linfeng/modules/admin/controller/CommentController.java index 6afe807..d64d285 100644 --- a/src/main/java/io/linfeng/modules/admin/controller/CommentController.java +++ b/src/main/java/io/linfeng/modules/admin/controller/CommentController.java @@ -82,8 +82,7 @@ public class CommentController { @RequestMapping("/delete") @RequiresPermissions("admin:comment:delete") public R delete(@RequestBody Long[] ids){ - commentService.removeByIds(Arrays.asList(ids)); - + commentService.deleteByAdmin(Arrays.asList(ids)); return R.ok(); } diff --git a/src/main/java/io/linfeng/modules/admin/controller/DiscussController.java b/src/main/java/io/linfeng/modules/admin/controller/DiscussController.java index 3bf3f4c..01afe4b 100644 --- a/src/main/java/io/linfeng/modules/admin/controller/DiscussController.java +++ b/src/main/java/io/linfeng/modules/admin/controller/DiscussController.java @@ -1,8 +1,12 @@ package io.linfeng.modules.admin.controller; import java.util.Arrays; +import java.util.List; import java.util.Map; +import io.linfeng.common.exception.LinfengException; +import io.linfeng.modules.admin.entity.PostEntity; +import io.linfeng.modules.admin.service.PostService; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PathVariable; @@ -28,8 +32,12 @@ import io.linfeng.common.utils.R; @RestController @RequestMapping("admin/discuss") public class DiscussController { + @Autowired private DiscussService discussService; + @Autowired + private PostService postService; + /** * 列表 @@ -82,8 +90,14 @@ public class DiscussController { @RequestMapping("/delete") @RequiresPermissions("admin:discuss:delete") public R delete(@RequestBody Integer[] ids){ - discussService.removeByIds(Arrays.asList(ids)); - + List list = Arrays.asList(ids); + list.forEach(id->{ + List entityList = postService.lambdaQuery().eq(PostEntity::getDiscussId, id).list(); + if(entityList.size()>0){ + throw new LinfengException("请先删除该话题下的帖子"); + } + discussService.removeById(id); + }); return R.ok(); } diff --git a/src/main/java/io/linfeng/modules/admin/controller/MomentManageController.java b/src/main/java/io/linfeng/modules/admin/controller/MomentManageController.java deleted file mode 100644 index 300b607..0000000 --- a/src/main/java/io/linfeng/modules/admin/controller/MomentManageController.java +++ /dev/null @@ -1,90 +0,0 @@ -package io.linfeng.modules.admin.controller; - -import io.linfeng.common.utils.PageUtils; -import io.linfeng.common.utils.R; -import io.linfeng.modules.app.entity.MomentEntity; -import io.linfeng.modules.app.service.MomentService; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import org.apache.shiro.authz.annotation.RequiresPermissions; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; - -import java.util.Arrays; -import java.util.Map; - -/** - * @author linfeng - * @date 2022/1/5 16:56 - */ -@RestController -@RequestMapping("admin/moment") -@Api(tags = "管理端——动态接口") -public class MomentManageController { - - - @Autowired - private MomentService momentService; - - /** - * 列表 - */ - @ApiOperation("后台——动态分页列表") - @GetMapping("/list") - @RequiresPermissions("app:moment:list") - public R list(@RequestParam Map params){ - PageUtils page = momentService.queryPage(params); - - return R.ok().put("page", page); - } - - - /** - * 信息 - */ - @ApiOperation("后台——根据id获取动态") - @GetMapping("/info/{id}") - @RequiresPermissions("app:moment:info") - public R info(@PathVariable("id") Long id){ - MomentEntity moment = momentService.getById(id); - - return R.ok().put("moment", moment); - } - - /** - * 保存 - */ - @ApiOperation("后台——保存动态") - @PostMapping("/save") - @RequiresPermissions("app:moment:save") - public R save(@RequestBody MomentEntity moment){ - momentService.save(moment); - - return R.ok(); - } - - /** - * 修改 - */ - @ApiOperation("后台——修改动态") - @PostMapping("/update") - @RequiresPermissions("app:moment:update") - public R update(@RequestBody MomentEntity moment){ - momentService.updateById(moment); - - return R.ok(); - } - - /** - * 删除 - */ - @ApiOperation("后台——删除动态") - @PostMapping("/delete") - @RequiresPermissions("app:moment:delete") - public R delete(@RequestBody Long[] ids){ - momentService.removeByIds(Arrays.asList(ids)); - - return R.ok(); - } - -} diff --git a/src/main/java/io/linfeng/modules/admin/service/CommentService.java b/src/main/java/io/linfeng/modules/admin/service/CommentService.java index 3ea51a1..7dc1457 100644 --- a/src/main/java/io/linfeng/modules/admin/service/CommentService.java +++ b/src/main/java/io/linfeng/modules/admin/service/CommentService.java @@ -25,5 +25,6 @@ public interface CommentService extends IService { List getByPid(Long pid); + void deleteByAdmin(List longs); } diff --git a/src/main/java/io/linfeng/modules/admin/service/impl/CommentServiceImpl.java b/src/main/java/io/linfeng/modules/admin/service/impl/CommentServiceImpl.java index 85b96b5..ed4a320 100644 --- a/src/main/java/io/linfeng/modules/admin/service/impl/CommentServiceImpl.java +++ b/src/main/java/io/linfeng/modules/admin/service/impl/CommentServiceImpl.java @@ -17,6 +17,7 @@ import io.linfeng.common.utils.Query; import io.linfeng.modules.admin.dao.CommentDao; import io.linfeng.modules.admin.entity.CommentEntity; import io.linfeng.modules.admin.service.CommentService; +import org.springframework.transaction.annotation.Transactional; @Service("commentService") @@ -47,4 +48,20 @@ public class CommentServiceImpl extends ServiceImpl i } + /** + * 管理端批量删除评论 + * @param list + */ + @Override + @Transactional(rollbackFor = Exception.class) + public void deleteByAdmin(List list) { + list.forEach(id->{ + this.removeById(id); + //子评论更改展示状态为屏蔽 + this.lambdaUpdate() + .set(CommentEntity::getStatus, 0) + .eq(CommentEntity::getPid, id) + .update(); + }); + } } \ No newline at end of file