feat: 新增批量删除通知公告接口
This commit is contained in:
parent
d60aeb76a3
commit
f0efbd76ba
|
@ -14,12 +14,13 @@ import cn.iocoder.yudao.module.system.service.notice.NoticeService;
|
|||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
|
@ -60,6 +61,15 @@ public class NoticeController {
|
|||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete-list")
|
||||
@Operation(summary = "批量删除通知公告")
|
||||
@Parameter(name = "ids", description = "编号列表", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('system:notice:delete')")
|
||||
public CommonResult<Boolean> deleteNoticeList(@RequestParam("ids") List<Long> ids) {
|
||||
noticeService.deleteNoticeList(ids);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获取通知公告列表")
|
||||
@PreAuthorize("@ss.hasPermission('system:notice:query')")
|
||||
|
|
|
@ -5,6 +5,8 @@ import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticePageReqVO
|
|||
import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeSaveReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.notice.NoticeDO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 通知公告 Service 接口
|
||||
*/
|
||||
|
@ -32,6 +34,13 @@ public interface NoticeService {
|
|||
*/
|
||||
void deleteNotice(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除通知公告
|
||||
*
|
||||
* @param ids 编号列表
|
||||
*/
|
||||
void deleteNoticeList(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得通知公告分页列表
|
||||
*
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package cn.iocoder.yudao.module.system.service.notice;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
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
|
|||
import cn.iocoder.yudao.module.system.dal.dataobject.notice.NoticeDO;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.notice.NoticeMapper;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.NOTICE_NOT_FOUND;
|
||||
|
@ -49,6 +51,14 @@ public class NoticeServiceImpl implements NoticeService {
|
|||
noticeMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteNoticeList(List<Long> ids) {
|
||||
// 校验是否存在
|
||||
validateNoticesExists(ids);
|
||||
// 批量删除通知公告
|
||||
noticeMapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<NoticeDO> getNoticePage(NoticePageReqVO reqVO) {
|
||||
return noticeMapper.selectPage(reqVO);
|
||||
|
@ -70,4 +80,15 @@ public class NoticeServiceImpl implements NoticeService {
|
|||
}
|
||||
}
|
||||
|
||||
private void validateNoticesExists(List<Long> ids) {
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
return;
|
||||
}
|
||||
// 校验存在
|
||||
List<NoticeDO> notices = noticeMapper.selectByIds(ids);
|
||||
if (CollUtil.isEmpty(notices) || notices.size() != ids.size()) {
|
||||
throw exception(NOTICE_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue