package com.huimv.management.service.impl;

import com.huimv.management.entity.vo.DrinkingWaterVo;
import com.huimv.management.entity.vo.PigBaseVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
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.LairageRecordDao;
import com.huimv.management.entity.LairageRecordEntity;
import com.huimv.management.service.LairageRecordService;

/**
 * 年猪基本
 *
 * @author yinhao
 * @version ${version}
 * @date 2021-07-14 15:11:40
 */
@Service("lairageRecordService")
public class LairageRecordServiceImpl extends ServiceImpl<LairageRecordDao, LairageRecordEntity> implements LairageRecordService {

    @Autowired
    private LairageRecordDao lairageRecordDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        //构建条件查询wrapper
        QueryWrapper<DrinkingWaterVo> queryWrapper = new QueryWrapper<>();

        //耳标
        String eartag = (String) params.get("eartag");
        if (StringUtils.isNotEmpty(eartag)) {
            queryWrapper.like("base.eartag",eartag);
        }

        //性别
        String sex = (String) params.get("sex");
        if (StringUtils.isNotEmpty(sex)) {
            queryWrapper.eq("base.sex",sex);
        }

        //品种
        String breed = (String) params.get("breed");
        if (StringUtils.isNotEmpty(breed)) {
            queryWrapper.eq("base.breed",breed);
        }

        //健康状态
        String healthStatus = (String) params.get("healthStatus");
        if (StringUtils.isNotEmpty(healthStatus)) {
            queryWrapper.eq("base.health_status",Integer.parseInt(healthStatus));
        }

        //养殖状态
        String outFenceStatus = (String) params.get("outFenceStatus");
        if (StringUtils.isNotEmpty(outFenceStatus)) {
            queryWrapper.eq("base.out_fence_status",Integer.parseInt(outFenceStatus));
        }

        //栏期
        String periodId = (String) params.get("periodId");
        if (StringUtils.isNotEmpty(periodId)) {
            queryWrapper.eq("base.period_id",Integer.parseInt(periodId));
        }

        //栋舍
        String pigstyId = (String) params.get("pigstyId");
        if (StringUtils.isNotEmpty(pigstyId)) {
            queryWrapper.eq("base.pigsty_id",Integer.parseInt(pigstyId));
        }
        //单元
        String unitId = (String) params.get("unitId");
        if (StringUtils.isNotEmpty(unitId)) {
            queryWrapper.eq("base.unit_id",Integer.parseInt(unitId));
        }

        //牧场
        String farmId = (String) params.get("formFarmId");
        if (StringUtils.isNotEmpty(farmId)) {
            queryWrapper.eq("base.farm_id",Integer.parseInt(farmId));
        }
        //排除逻辑删除
        queryWrapper.apply(" base.deleted = 0  AND pigsty.deleted = 0 ");
        queryWrapper.orderByDesc("id");
        IPage<PigBaseVo> page = lairageRecordDao.list(new Query<>().getPage(params),queryWrapper);



        return new PageUtils(page);
    }

}