package com.huimv.management.service.impl;

import com.huimv.management.entity.HealthMedicalRecordEntity;
import org.apache.commons.lang.StringUtils;
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.HealthImmuneRecordDao;
import com.huimv.management.entity.HealthImmuneRecordEntity;
import com.huimv.management.service.HealthImmuneRecordService;


@Service("healthImmuneRecordService")
public class HealthImmuneRecordServiceImpl extends ServiceImpl<HealthImmuneRecordDao, HealthImmuneRecordEntity> implements HealthImmuneRecordService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        //根据牧场查询
        String farmId = (String) params.get("farmId");

        QueryWrapper<HealthImmuneRecordEntity> wrapper = new QueryWrapper<HealthImmuneRecordEntity>();
        wrapper.eq(StringUtils.isNotBlank(farmId),"farm_id",farmId);
        IPage<HealthImmuneRecordEntity> page = this.page(
                new Query<HealthImmuneRecordEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

    @Override
    public void saveAll(String[] eartags, String vaccine, Integer farmId, String manName, Integer manId) {
        HealthImmuneRecordEntity healthImmuneRecordEntity = new HealthImmuneRecordEntity();
        healthImmuneRecordEntity.setFarmId(farmId);
        healthImmuneRecordEntity.setManId(manId);
        healthImmuneRecordEntity.setManName(manName);
        healthImmuneRecordEntity.setVaccineName(vaccine);
        for (String eartag : eartags) {
            healthImmuneRecordEntity.setPigId(eartag);
            save(healthImmuneRecordEntity);
        }
    }

}