Commit f0efbd76ba21bc455f9ca85c3862a1885b9d4b93
1 parent
d60aeb76
feat: 新增批量删除通知公告接口
Showing
3 changed files
with
43 additions
and
3 deletions
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/NoticeController.java
| @@ -14,12 +14,13 @@ import cn.iocoder.yudao.module.system.service.notice.NoticeService; | @@ -14,12 +14,13 @@ import cn.iocoder.yudao.module.system.service.notice.NoticeService; | ||
| 14 | import io.swagger.v3.oas.annotations.Operation; | 14 | import io.swagger.v3.oas.annotations.Operation; |
| 15 | import io.swagger.v3.oas.annotations.Parameter; | 15 | import io.swagger.v3.oas.annotations.Parameter; |
| 16 | import io.swagger.v3.oas.annotations.tags.Tag; | 16 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 17 | +import jakarta.annotation.Resource; | ||
| 18 | +import jakarta.validation.Valid; | ||
| 17 | import org.springframework.security.access.prepost.PreAuthorize; | 19 | import org.springframework.security.access.prepost.PreAuthorize; |
| 18 | import org.springframework.validation.annotation.Validated; | 20 | import org.springframework.validation.annotation.Validated; |
| 19 | import org.springframework.web.bind.annotation.*; | 21 | import org.springframework.web.bind.annotation.*; |
| 20 | 22 | ||
| 21 | -import jakarta.annotation.Resource; | ||
| 22 | -import jakarta.validation.Valid; | 23 | +import java.util.List; |
| 23 | 24 | ||
| 24 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 25 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 25 | 26 | ||
| @@ -60,6 +61,15 @@ public class NoticeController { | @@ -60,6 +61,15 @@ public class NoticeController { | ||
| 60 | return success(true); | 61 | return success(true); |
| 61 | } | 62 | } |
| 62 | 63 | ||
| 64 | + @DeleteMapping("/delete-list") | ||
| 65 | + @Operation(summary = "批量删除通知公告") | ||
| 66 | + @Parameter(name = "ids", description = "编号列表", required = true) | ||
| 67 | + @PreAuthorize("@ss.hasPermission('system:notice:delete')") | ||
| 68 | + public CommonResult<Boolean> deleteNoticeList(@RequestParam("ids") List<Long> ids) { | ||
| 69 | + noticeService.deleteNoticeList(ids); | ||
| 70 | + return success(true); | ||
| 71 | + } | ||
| 72 | + | ||
| 63 | @GetMapping("/page") | 73 | @GetMapping("/page") |
| 64 | @Operation(summary = "获取通知公告列表") | 74 | @Operation(summary = "获取通知公告列表") |
| 65 | @PreAuthorize("@ss.hasPermission('system:notice:query')") | 75 | @PreAuthorize("@ss.hasPermission('system:notice:query')") |
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/notice/NoticeService.java
| @@ -5,6 +5,8 @@ import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticePageReqVO | @@ -5,6 +5,8 @@ import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticePageReqVO | ||
| 5 | import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeSaveReqVO; | 5 | import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeSaveReqVO; |
| 6 | import cn.iocoder.yudao.module.system.dal.dataobject.notice.NoticeDO; | 6 | import cn.iocoder.yudao.module.system.dal.dataobject.notice.NoticeDO; |
| 7 | 7 | ||
| 8 | +import java.util.List; | ||
| 9 | + | ||
| 8 | /** | 10 | /** |
| 9 | * 通知公告 Service 接口 | 11 | * 通知公告 Service 接口 |
| 10 | */ | 12 | */ |
| @@ -33,6 +35,13 @@ public interface NoticeService { | @@ -33,6 +35,13 @@ public interface NoticeService { | ||
| 33 | void deleteNotice(Long id); | 35 | void deleteNotice(Long id); |
| 34 | 36 | ||
| 35 | /** | 37 | /** |
| 38 | + * 批量删除通知公告 | ||
| 39 | + * | ||
| 40 | + * @param ids 编号列表 | ||
| 41 | + */ | ||
| 42 | + void deleteNoticeList(List<Long> ids); | ||
| 43 | + | ||
| 44 | + /** | ||
| 36 | * 获得通知公告分页列表 | 45 | * 获得通知公告分页列表 |
| 37 | * | 46 | * |
| 38 | * @param reqVO 分页条件 | 47 | * @param reqVO 分页条件 |
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/notice/NoticeServiceImpl.java
| 1 | package cn.iocoder.yudao.module.system.service.notice; | 1 | package cn.iocoder.yudao.module.system.service.notice; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.collection.CollUtil; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | 5 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 5 | import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticePageReqVO; | 6 | import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticePageReqVO; |
| @@ -7,9 +8,10 @@ import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeSaveReqVO | @@ -7,9 +8,10 @@ import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeSaveReqVO | ||
| 7 | import cn.iocoder.yudao.module.system.dal.dataobject.notice.NoticeDO; | 8 | import cn.iocoder.yudao.module.system.dal.dataobject.notice.NoticeDO; |
| 8 | import cn.iocoder.yudao.module.system.dal.mysql.notice.NoticeMapper; | 9 | import cn.iocoder.yudao.module.system.dal.mysql.notice.NoticeMapper; |
| 9 | import com.google.common.annotations.VisibleForTesting; | 10 | import com.google.common.annotations.VisibleForTesting; |
| 11 | +import jakarta.annotation.Resource; | ||
| 10 | import org.springframework.stereotype.Service; | 12 | import org.springframework.stereotype.Service; |
| 11 | 13 | ||
| 12 | -import jakarta.annotation.Resource; | 14 | +import java.util.List; |
| 13 | 15 | ||
| 14 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 16 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 15 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.NOTICE_NOT_FOUND; | 17 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.NOTICE_NOT_FOUND; |
| @@ -50,6 +52,14 @@ public class NoticeServiceImpl implements NoticeService { | @@ -50,6 +52,14 @@ public class NoticeServiceImpl implements NoticeService { | ||
| 50 | } | 52 | } |
| 51 | 53 | ||
| 52 | @Override | 54 | @Override |
| 55 | + public void deleteNoticeList(List<Long> ids) { | ||
| 56 | + // 校验是否存在 | ||
| 57 | + validateNoticesExists(ids); | ||
| 58 | + // 批量删除通知公告 | ||
| 59 | + noticeMapper.deleteByIds(ids); | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + @Override | ||
| 53 | public PageResult<NoticeDO> getNoticePage(NoticePageReqVO reqVO) { | 63 | public PageResult<NoticeDO> getNoticePage(NoticePageReqVO reqVO) { |
| 54 | return noticeMapper.selectPage(reqVO); | 64 | return noticeMapper.selectPage(reqVO); |
| 55 | } | 65 | } |
| @@ -70,4 +80,15 @@ public class NoticeServiceImpl implements NoticeService { | @@ -70,4 +80,15 @@ public class NoticeServiceImpl implements NoticeService { | ||
| 70 | } | 80 | } |
| 71 | } | 81 | } |
| 72 | 82 | ||
| 83 | + private void validateNoticesExists(List<Long> ids) { | ||
| 84 | + if (CollUtil.isEmpty(ids)) { | ||
| 85 | + return; | ||
| 86 | + } | ||
| 87 | + // 校验存在 | ||
| 88 | + List<NoticeDO> notices = noticeMapper.selectByIds(ids); | ||
| 89 | + if (CollUtil.isEmpty(notices) || notices.size() != ids.size()) { | ||
| 90 | + throw exception(NOTICE_NOT_FOUND); | ||
| 91 | + } | ||
| 92 | + } | ||
| 93 | + | ||
| 73 | } | 94 | } |