 package com.huimv.management.controller;

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

import io.swagger.annotations.Api;
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.YearPigBaseEntity;
import com.huimv.management.service.YearPigBaseService;
import com.huimv.common.utils.PageUtils;
import com.huimv.common.utils.R;



/**
 * 年猪基本
 *
 * @author yinhao
 * @email yinhao@163.com
 * @date 2021-05-07 15:32:42
 */
@Api(tags = "年猪基本")
@RestController
@RequestMapping("management/yearpigbase")
public class YearPigBaseController {
    @Autowired
    private YearPigBaseService yearPigBaseService;

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

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


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		YearPigBaseEntity yearPigBase = yearPigBaseService.getById(id);

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

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody YearPigBaseEntity yearPigBase){
		yearPigBaseService.save(yearPigBase);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody YearPigBaseEntity yearPigBase){
		yearPigBaseService.updateById(yearPigBase);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		yearPigBaseService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /*@RequestMapping("/batchLairage")
    public R batchLairage(@RequestBody Map<String, Object> map){
        String eartags = (String)map.get("eartags");
        Integer periodId = (Integer)map.get("periodId");
        String[] split = eartags.split(",");
        yearPigBaseService.batchLairage(split,periodId);

        return R.ok();
    } */
    @RequestMapping("/batchLairage")
    public R batchLairage(@RequestBody YearPigBaseEntity yearPigBase){

        for (String eartage : yearPigBase.getEartag().split(",")) {
            yearPigBase.setEartag(eartage);
            yearPigBaseService.save(yearPigBase);
        }

        return R.ok();
    }

}
