package com.zhyc.module.base.controller;

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

import com.zhyc.module.base.domain.BasSheepVariety;
import com.zhyc.module.base.service.IBasSheepVarietyService;
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.common.utils.poi.ExcelUtil;
import com.zhyc.common.core.page.TableDataInfo;

/**
 * 羊只品种Controller
 * 
 * @author ruoyi
 * @date 2025-07-15
 */
@RestController
@RequestMapping("/base/variety")
public class BasSheepVarietyController extends BaseController
{
    @Autowired
    private IBasSheepVarietyService basSheepVarietyService;

    /**
     * 查询羊只品种列表
     */
    @PreAuthorize("@ss.hasPermi('base:variety:list')")
    @GetMapping("/list")
    public TableDataInfo list(BasSheepVariety basSheepVariety)
    {
        startPage();
        List<BasSheepVariety> list = basSheepVarietyService.selectBasSheepVarietyList(basSheepVariety);
        return getDataTable(list);
    }

    /**
     * 导出羊只品种列表
     */
    @PreAuthorize("@ss.hasPermi('base:variety:export')")
    @Log(title = "羊只品种", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BasSheepVariety basSheepVariety)
    {
        List<BasSheepVariety> list = basSheepVarietyService.selectBasSheepVarietyList(basSheepVariety);
        ExcelUtil<BasSheepVariety> util = new ExcelUtil<BasSheepVariety>(BasSheepVariety.class);
        util.exportExcel(response, list, "羊只品种数据");
    }

    /**
     * 获取羊只品种详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:variety:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(basSheepVarietyService.selectBasSheepVarietyById(id));
    }

    /**
     * 新增羊只品种
     */
    @PreAuthorize("@ss.hasPermi('base:variety:add')")
    @Log(title = "羊只品种", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasSheepVariety basSheepVariety)
    {
        return toAjax(basSheepVarietyService.insertBasSheepVariety(basSheepVariety));
    }

    /**
     * 修改羊只品种
     */
    @PreAuthorize("@ss.hasPermi('base:variety:edit')")
    @Log(title = "羊只品种", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasSheepVariety basSheepVariety)
    {
        return toAjax(basSheepVarietyService.updateBasSheepVariety(basSheepVariety));
    }

    /**
     * 删除羊只品种
     */
    @PreAuthorize("@ss.hasPermi('base:variety:remove')")
    @Log(title = "羊只品种", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(basSheepVarietyService.deleteBasSheepVarietyByIds(ids));
    }
}
