mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-11-04 04:08:43 +08:00 
			
		
		
		
	完善 NoticeServiceImpl 单元测试
This commit is contained in:
		@@ -57,8 +57,8 @@ public class NoticeController {
 | 
			
		||||
    @GetMapping("/page")
 | 
			
		||||
    @ApiOperation("获取通知公告列表")
 | 
			
		||||
    @PreAuthorize("@ss.hasPermission('system:notice:query')")
 | 
			
		||||
    public CommonResult<PageResult<NoticeRespVO>> pageNotices(@Validated NoticePageReqVO reqVO) {
 | 
			
		||||
        return success(NoticeConvert.INSTANCE.convertPage(noticeService.pageNotices(reqVO)));
 | 
			
		||||
    public CommonResult<PageResult<NoticeRespVO>> getNoticePage(@Validated NoticePageReqVO reqVO) {
 | 
			
		||||
        return success(NoticeConvert.INSTANCE.convertPage(noticeService.getNoticePage(reqVO)));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @GetMapping("/get")
 | 
			
		||||
 
 | 
			
		||||
@@ -39,7 +39,7 @@ public interface NoticeService {
 | 
			
		||||
     * @param reqVO 分页条件
 | 
			
		||||
     * @return 部门分页列表
 | 
			
		||||
     */
 | 
			
		||||
    PageResult<NoticeDO> pageNotices(NoticePageReqVO reqVO);
 | 
			
		||||
    PageResult<NoticeDO> getNoticePage(NoticePageReqVO reqVO);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 获得岗位公告公告信息
 | 
			
		||||
 
 | 
			
		||||
@@ -1,18 +1,18 @@
 | 
			
		||||
package cn.iocoder.yudao.module.system.service.notice;
 | 
			
		||||
 | 
			
		||||
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
 | 
			
		||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
 | 
			
		||||
import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeCreateReqVO;
 | 
			
		||||
import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticePageReqVO;
 | 
			
		||||
import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeUpdateReqVO;
 | 
			
		||||
import cn.iocoder.yudao.module.system.convert.notice.NoticeConvert;
 | 
			
		||||
import cn.iocoder.yudao.module.system.dal.mysql.notice.NoticeMapper;
 | 
			
		||||
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 org.springframework.stereotype.Service;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Resource;
 | 
			
		||||
 | 
			
		||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
 | 
			
		||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.NOTICE_NOT_FOUND;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@@ -36,7 +36,7 @@ public class NoticeServiceImpl implements NoticeService {
 | 
			
		||||
    @Override
 | 
			
		||||
    public void updateNotice(NoticeUpdateReqVO reqVO) {
 | 
			
		||||
        // 校验是否存在
 | 
			
		||||
        this.checkNoticeExists(reqVO.getId());
 | 
			
		||||
        validateNoticeExists(reqVO.getId());
 | 
			
		||||
        // 更新通知公告
 | 
			
		||||
        NoticeDO updateObj = NoticeConvert.INSTANCE.convert(reqVO);
 | 
			
		||||
        noticeMapper.updateById(updateObj);
 | 
			
		||||
@@ -45,13 +45,13 @@ public class NoticeServiceImpl implements NoticeService {
 | 
			
		||||
    @Override
 | 
			
		||||
    public void deleteNotice(Long id) {
 | 
			
		||||
        // 校验是否存在
 | 
			
		||||
        this.checkNoticeExists(id);
 | 
			
		||||
        validateNoticeExists(id);
 | 
			
		||||
        // 删除通知公告
 | 
			
		||||
        noticeMapper.deleteById(id);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public PageResult<NoticeDO> pageNotices(NoticePageReqVO reqVO) {
 | 
			
		||||
    public PageResult<NoticeDO> getNoticePage(NoticePageReqVO reqVO) {
 | 
			
		||||
        return noticeMapper.selectPage(reqVO);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -61,13 +61,13 @@ public class NoticeServiceImpl implements NoticeService {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @VisibleForTesting
 | 
			
		||||
    public void checkNoticeExists(Long id) {
 | 
			
		||||
    public void validateNoticeExists(Long id) {
 | 
			
		||||
        if (id == null) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        NoticeDO notice = noticeMapper.selectById(id);
 | 
			
		||||
        if (notice == null) {
 | 
			
		||||
            throw ServiceExceptionUtil.exception(NOTICE_NOT_FOUND);
 | 
			
		||||
            throw exception(NOTICE_NOT_FOUND);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user