package com.huimv.management.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huimv.management.entity.PeriodEntity;
import com.huimv.management.entity.PeriodEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huimv.common.utils.PageUtils;
import com.huimv.common.utils.Query;

import com.huimv.management.dao.PeriodDao;
import com.huimv.management.entity.PeriodEntity;
import com.huimv.management.service.PeriodService;


@Service("periodService")
public class PeriodServiceImpl extends ServiceImpl<PeriodDao, PeriodEntity> implements PeriodService {

    @Autowired
    private PeriodDao periodDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        LambdaQueryWrapper<PeriodEntity> lambdaQuery = Wrappers.lambdaQuery();
        String keywords = (String) params.get("keywords");
        //没有参数
        if (keywords == null || keywords.equals("")){
            IPage<PeriodEntity> page = this.page(
                    new Query<PeriodEntity>().getPage(params),
                    new QueryWrapper<PeriodEntity>()
            );
            return new PageUtils(page);
        }

        lambdaQuery.like(PeriodEntity::getPigstyId,keywords);
        IPage<PeriodEntity> page = page(this.page(
                new Query<PeriodEntity>().getPage(params)
        ), lambdaQuery);


        return new PageUtils(page);
    }

    @Override
    public List findAll() {
        LambdaQueryWrapper<PeriodEntity> lambdaQuery = Wrappers.lambdaQuery();
        List<PeriodEntity> pastureEntities = periodDao.selectList(lambdaQuery);
        return pastureEntities;
    }

}