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.EmployeeEntity;
import com.huimv.management.entity.EmployeeEntity;
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.EmployeeDao;
import com.huimv.management.entity.EmployeeEntity;
import com.huimv.management.service.EmployeeService;


@Service("employeeService")
public class EmployeeServiceImpl extends ServiceImpl<EmployeeDao, EmployeeEntity> implements EmployeeService {

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

        return new PageUtils(page);
    }*/
   @Override
   public PageUtils queryPage(Map<String, Object> params) {

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

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


       return new PageUtils(page);
   }

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

}