 package com.huimv.management.controller;

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

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.PublicNetworkEntity;
import com.huimv.management.service.PublicNetworkService;
import com.huimv.common.utils.PageUtils;
import com.huimv.common.utils.R;



/**
 * 
 *
 * @author yinhao
 * @email yinhao@163.com
 * @date 2021-06-24 09:55:37
 */
@RestController
@RequestMapping("management/publicnetwork")
public class PublicNetworkController {
    @Autowired
    private PublicNetworkService publicNetworkService;

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

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


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		PublicNetworkEntity publicNetwork = publicNetworkService.getById(id);

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

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody PublicNetworkEntity publicNetwork){
		publicNetworkService.save(publicNetwork);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody PublicNetworkEntity publicNetwork){
		publicNetworkService.updateById(publicNetwork);

        return R.ok();
    }

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

        return R.ok();
    }

    @RequestMapping("/findAll")
    public R findAll(Integer formFarmId){
        if (formFarmId == null){
            return R.error("请选择牧场");
        }
       return R.ok().put("data", publicNetworkService.findAll(formFarmId));
    }

}
