package com.ozs.base.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.ozs.base.domain.BaseNotice;
import com.ozs.base.domain.BaseNoticeType;
import com.ozs.base.mapper.BaseNoticeMapper;
import com.ozs.base.mapper.BaseNoticeTypeMapper;
import com.ozs.base.service.BaseNoticeService;
import com.ozs.base.service.BaseNoticeTypeService;
import com.ozs.base.vo.BaseNoticePageReqVo;
import com.ozs.plan.doman.MonthlyReconciliation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class BaseNoticeServiceImpl extends ServiceImpl<BaseNoticeMapper, BaseNotice> implements BaseNoticeService {


    @Autowired
    private BaseNoticeMapper baseNoticeMapper;

    @Override
    public IPage<BaseNotice> queryPage(BaseNoticePageReqVo vo) {
        int pageNum = Integer.parseInt(vo.getPageNum().toString());
        int pageSize = Integer.parseInt(vo.getPageSize().toString());
        vo.setNoticeName(StringUtils.isBlank(vo.getNoticeName()) ? null : vo.getNoticeName());
        Page<BaseNotice> page = PageHelper.startPage(pageNum, pageSize)
                .doSelectPage(() -> baseNoticeMapper.query(vo));
        com.baomidou.mybatisplus.extension.plugins.pagination.Page<BaseNotice> pageR =
                new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(pageNum, pageSize);
        pageR.setRecords(page.getResult());
        pageR.setSize(page.size());
        pageR.setTotal(page.getTotal());
        return pageR;

    }
}
