package com.huimv.management.service.impl;

import com.huimv.management.entity.PublicNetworkEntity;
import org.apache.commons.lang.StringUtils;
import org.checkerframework.checker.units.qual.A;
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.PublicNetworkDao;
import com.huimv.management.entity.PublicNetworkEntity;
import com.huimv.management.service.PublicNetworkService;


@Service("publicNetworkService")
public class PublicNetworkServiceImpl extends ServiceImpl<PublicNetworkDao, PublicNetworkEntity> implements PublicNetworkService {

    @Autowired
    private PublicNetworkDao publicNetworkDao;

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

        //根据牧场查询
        String farmId = (String) params.get("formFarmId");

        QueryWrapper<PublicNetworkEntity> wrapper = new QueryWrapper<PublicNetworkEntity>();
        wrapper.eq(StringUtils.isNotBlank(farmId),"farm_id",farmId);

        String keyword =(String) params.get("keyword");
        wrapper.like(StringUtils.isNotBlank(keyword),"name",keyword);

        IPage<PublicNetworkEntity> page = this.page(
                new Query<PublicNetworkEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

    @Override
    public List findAll(Integer formFarmId) {
        QueryWrapper<PublicNetworkEntity> wrapper = new QueryWrapper<PublicNetworkEntity>();
        wrapper.eq("farm_id",formFarmId);

        return   publicNetworkDao.selectList(wrapper);
    }
}