package com.mosty.hczx.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mosty.base.model.entity.hczx.TbHcRytzbq;
import com.mosty.base.model.query.hczx.TbHcRytzbqQuery;
import com.mosty.hczx.mapper.TbHcRytzbqMapper;
import com.mosty.hczx.service.TbHcRytzbqService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author dw
 * @since 2022/9/17
 **/
@Service
public class TbHcRytzbqServiceImpl extends ServiceImpl<TbHcRytzbqMapper, TbHcRytzbq>
        implements TbHcRytzbqService {

    @Override
    public IPage<TbHcRytzbq> selectPage(TbHcRytzbqQuery dto) {
        dto.setPageCurrent(dto.getPageCurrent() == null ? 1 : dto.getPageCurrent());
        dto.setPageSize(dto.getPageSize() == null ? 10 : dto.getPageSize());
        return this.baseMapper.selectPage(
                new Page<>(dto.getPageCurrent(), dto.getPageSize()),
                new LambdaQueryWrapper<TbHcRytzbq>()
                        .eq(StringUtils.isNotBlank(dto.getTzbqdm()), TbHcRytzbq::getTzbqdm, dto.getTzbqdm())
                        .eq(StringUtils.isNotBlank(dto.getTzbqlb()), TbHcRytzbq::getTzbqlb, dto.getTzbqlb())
                        .like(StringUtils.isNotBlank(dto.getTzbqmc()), TbHcRytzbq::getTzbqmc, dto.getTzbqmc())
                        .eq(StringUtils.isNotBlank(dto.getTzsx()), TbHcRytzbq::getTzsx, dto.getTzsx())
        );
    }

    @Override
    public List<TbHcRytzbq> selectList(TbHcRytzbq dto) {
        return this.baseMapper.selectList(
                new LambdaQueryWrapper<TbHcRytzbq>()
                        .eq(StringUtils.isNotBlank(dto.getTzbqdm()), TbHcRytzbq::getTzbqdm, dto.getTzbqdm())
                        .eq(StringUtils.isNotBlank(dto.getTzbqlb()), TbHcRytzbq::getTzbqlb, dto.getTzbqlb())
                        .like(StringUtils.isNotBlank(dto.getTzbqmc()), TbHcRytzbq::getTzbqmc, dto.getTzbqmc())
                        .eq(StringUtils.isNotBlank(dto.getTzsx()), TbHcRytzbq::getTzsx, dto.getTzsx())
        );
    }
}
