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.dao.PigstyDao;
import com.huimv.management.entity.UnitEntity;
import com.huimv.management.entity.UnitEntity;
import com.huimv.management.entity.UnitEntity;
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.UnitDao;
import com.huimv.management.entity.UnitEntity;
import com.huimv.management.service.UnitService;


@Service("unitService")
public class UnitServiceImpl extends ServiceImpl<UnitDao, UnitEntity> implements UnitService {

   /* @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<UnitEntity> page = this.page(
                new Query<UnitEntity>().getPage(params),
                new QueryWrapper<UnitEntity>()
        );

        return new PageUtils(page);
    }*/

    @Autowired
    private UnitDao unitDao;

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

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

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


        return new PageUtils(page);
    }

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

}