package com.huimv.admin.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huimv.admin.system.entity.ProdFarmName;
import com.huimv.admin.system.mapper.ProdFarmNameMapper;
import com.huimv.admin.system.service.IProdFarmNameService;
import com.huimv.common.utils.Result;
import com.huimv.common.utils.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author astupidcoder
 * @since 2021-11-20
 */
@Service
public class ProdFarmNameServiceImpl extends ServiceImpl<ProdFarmNameMapper, ProdFarmName> implements IProdFarmNameService {



    @Autowired
    private ProdFarmNameMapper farmNameMapper;

    @Override
    public void updatName() {
       List<ProdFarmName> farms  = farmNameMapper.updatName();
       this.saveBatch(farms);

    }

    @Override
    public Result listPage(Map map) {
        Integer current = (Integer) map.get("current");
        String strchStr = (String)map.get("strchStr");
        Integer size =(Integer) map.get("size");
        QueryWrapper<ProdFarmName> wrapper = new QueryWrapper<>();

        if (StringUtils.isNotBlank(strchStr)){
            wrapper.like("farm_name",strchStr)
            .or().like("erp_farm_name",strchStr)
                    .or().like("erp_short_name",strchStr);

        }

        IPage<ProdFarmName> page = page(new Page<>(current, size), wrapper);
        return new Result(ResultCode.SUCCESS,page);
    }
}
