 package com.huimv.management.controller;

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

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.huimv.management.entity.HealthImmuneRecordEntity;
import com.huimv.management.service.HealthImmuneRecordService;
import com.huimv.common.utils.PageUtils;
import com.huimv.common.utils.R;



/**
 * 
 *
 * @author yinhao
 * @email yinhao@163.com
 * @date 2021-06-10 09:44:06
 */
@Api(tags = "免疫记录表")
@RestController
@RequestMapping("management/healthimmunerecord")
public class HealthImmuneRecordController {
    @Autowired
    private HealthImmuneRecordService healthImmuneRecordService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = healthImmuneRecordService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		HealthImmuneRecordEntity healthImmuneRecord = healthImmuneRecordService.getById(id);

        return R.ok().put("healthImmuneRecord", healthImmuneRecord);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody HealthImmuneRecordEntity healthImmuneRecord){
		healthImmuneRecordService.save(healthImmuneRecord);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody HealthImmuneRecordEntity healthImmuneRecord){
		healthImmuneRecordService.updateById(healthImmuneRecord);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
        for (Integer id : ids) {
            
        }
		healthImmuneRecordService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     *  根据疫苗名称，小猪编号id(可批量)向免疫记录表中插入数据
     */
    @RequestMapping("/saveAll")
    public R saveAll(@RequestBody Map<String, Object> map){
        String eartags = (String)map.get("eartags");
        String manName = (String)map.get("manName");
        String[] split = eartags.split(",");


        String vaccine = (String)map.get("vaccine");
        Integer farmId = Integer.parseInt((String)map.get("farmId"));
        Integer manId = (Integer)map.get("manId");

        healthImmuneRecordService.saveAll(split,vaccine,farmId,manName,manId);

        return R.ok();
    }
    /**
     * 查询全部
     */
    @RequestMapping("/findAll")
    public R findAll(){
        return R.ok().put("all",healthImmuneRecordService.list());
    }
}
