package com.zhyc.module.base.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zhyc.module.base.domain.BasSheep;
import com.zhyc.module.base.service.IBasSheepService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
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.RestController;
import com.zhyc.common.annotation.Log;
import com.zhyc.common.core.controller.BaseController;
import com.zhyc.common.core.domain.AjaxResult;
import com.zhyc.common.enums.BusinessType;
import com.zhyc.module.base.domain.DaRanch;
import com.zhyc.module.base.service.IDaRanchService;
import com.zhyc.common.utils.poi.ExcelUtil;
import com.zhyc.common.core.page.TableDataInfo;

/**
 * 牧场管理Controller
 * 
 * @author ruoyi
 * @date 2025-07-22
 */
@RestController
@RequestMapping("/ranch/ranch")
public class DaRanchController extends BaseController
{
    @Autowired
    private IDaRanchService daRanchService;

    @Autowired
    private IBasSheepService basSheepService;
    /**
     * 查询牧场管理列表
     */
//    @PreAuthorize("@ss.hasPermi('ranch:ranch:list')")
    @GetMapping("/list")
    public TableDataInfo list(DaRanch daRanch)
    {
        startPage();
        List<DaRanch> list = daRanchService.selectDaRanchList(daRanch);
        return getDataTable(list);
    }

    /**
     * 导出牧场管理列表
     */
//    @PreAuthorize("@ss.hasPermi('ranch:ranch:export')")
    @Log(title = "牧场管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DaRanch daRanch)
    {
        List<DaRanch> list = daRanchService.selectDaRanchList(daRanch);
        ExcelUtil<DaRanch> util = new ExcelUtil<DaRanch>(DaRanch.class);
        util.exportExcel(response, list, "牧场管理数据");
    }

    /**
     * 获取牧场管理详细信息
     */
//    @PreAuthorize("@ss.hasPermi('ranch:ranch:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(daRanchService.selectDaRanchById(id));
    }

    /**
     * 获取指定牧场下的所有羊只耳号
     */
    @GetMapping("/getSheepByRanchId/{ranchId}")
    public AjaxResult getSheepByRanchId(@PathVariable Long ranchId) {
        List<BasSheep> sheepList = basSheepService.getSheepByRanchId(ranchId);
        return AjaxResult.success(sheepList);
    }


    /**
     * 新增牧场管理
     */
//    @PreAuthorize("@ss.hasPermi('ranch:ranch:add')")
    @Log(title = "牧场管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DaRanch daRanch)
    {
        return toAjax(daRanchService.insertDaRanch(daRanch));
    }

    /**
     * 修改牧场管理
     */
//    @PreAuthorize("@ss.hasPermi('ranch:ranch:edit')")
    @Log(title = "牧场管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DaRanch daRanch)
    {
        return toAjax(daRanchService.updateDaRanch(daRanch));
    }

    /**
     * 删除牧场管理
     */
//    @PreAuthorize("@ss.hasPermi('ranch:ranch:remove')")
    @Log(title = "牧场管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(daRanchService.deleteDaRanchByIds(ids));
    }
}
