package com.zhyc.module.base.controller;

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

import com.zhyc.module.base.util.SheepPedigreeExcelUtils;
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.SheepPedigree;
import com.zhyc.module.base.service.ISheepPedigreeService;
import com.zhyc.common.utils.poi.ExcelUtil;
import com.zhyc.common.core.page.TableDataInfo;

/**
 * VIEWController
 * 
 * @author ruoyi
 * @date 2026-02-04
 */
@RestController
@RequestMapping("/system/pedigree")
public class SheepPedigreeController extends BaseController
{
    @Autowired
    private ISheepPedigreeService sheepPedigreeService;


    /**
     * 查询VIEW列表
     */
    @PreAuthorize("@ss.hasPermi('system:pedigree:list')")
    @GetMapping("/list")
    public TableDataInfo list(SheepPedigree sheepPedigree)
    {
        startPage();
        List<SheepPedigree> list = sheepPedigreeService.selectSheepPedigreeList(sheepPedigree);
        return getDataTable(list);
    }

    /**
     * 导出VIEW列表
     */

    // 在Controller/Service中注入工具类
    @Autowired
    private SheepPedigreeExcelUtils sheepPedigreeExcelUtils;
    @PreAuthorize("@ss.hasPermi('system:pedigree:export')")
    @Log(title = "VIEW", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SheepPedigree sheepPedigree) throws Exception {
        List<SheepPedigree> dataList = sheepPedigreeService.selectSheepPedigreeList(sheepPedigree);
        // 调用实例方法（而非静态方法）
        sheepPedigreeExcelUtils.export(response, dataList);
    }

    /**
     * 获取VIEW详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:pedigree:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sheepPedigreeService.selectSheepPedigreeById(id));
    }

    /**
     * 新增VIEW
     */
    @PreAuthorize("@ss.hasPermi('system:pedigree:add')")
    @Log(title = "VIEW", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SheepPedigree sheepPedigree)
    {
        return toAjax(sheepPedigreeService.insertSheepPedigree(sheepPedigree));
    }

    /**
     * 修改VIEW
     */
    @PreAuthorize("@ss.hasPermi('system:pedigree:edit')")
    @Log(title = "VIEW", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SheepPedigree sheepPedigree)
    {
        return toAjax(sheepPedigreeService.updateSheepPedigree(sheepPedigree));
    }

    /**
     * 删除VIEW
     */
    @PreAuthorize("@ss.hasPermi('system:pedigree:remove')")
    @Log(title = "VIEW", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sheepPedigreeService.deleteSheepPedigreeByIds(ids));
    }
}
