package com.zhyc.module.produce.other.controller;

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

import com.zhyc.module.produce.other.domain.ScCastrate;
import com.zhyc.module.produce.other.service.IScCastrateService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
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-09
 */
@RestController
@RequestMapping("/produce/other/castrate")
public class ScCastrateController extends BaseController
{
    @Autowired
    private IScCastrateService scCastrateService;

    /**
     * 查询去势列表
     */
    @PreAuthorize("@ss.hasPermi('produce:castrate:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScCastrate scCastrate)
    {
        startPage();
        List<ScCastrate> list = scCastrateService.selectScCastrateList(scCastrate);
        return getDataTable(list);
    }

    /**
     * 导出去势列表
     */
    @PreAuthorize("@ss.hasPermi('produce:castrate:export')")
    @Log(title = "去势", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScCastrate scCastrate)
    {
        List<ScCastrate> list = scCastrateService.selectScCastrateList(scCastrate);
        ExcelUtil<ScCastrate> util = new ExcelUtil<ScCastrate>(ScCastrate.class);
        util.exportExcel(response, list, "去势数据");
    }

    /**
     * 获取去势详细信息
     */
    @PreAuthorize("@ss.hasPermi('produce:castrate:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(scCastrateService.selectScCastrateById(id));
    }

    /**
     * 新增去势
     */
    @PreAuthorize("@ss.hasPermi('produce:castrate:add')")
    @Log(title = "去势", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScCastrate scCastrate)
    {
        scCastrate.setUserId(getUserId());
        scCastrate.setDeptId(getDeptId());
        return toAjax(scCastrateService.insertScCastrate(scCastrate));
    }

    /**
     * 修改去势
     */
    @PreAuthorize("@ss.hasPermi('produce:castrate:edit')")
    @Log(title = "去势", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScCastrate scCastrate)
    {
        return toAjax(scCastrateService.updateScCastrate(scCastrate));
    }

    /**
     * 删除去势
     */
    @PreAuthorize("@ss.hasPermi('produce:castrate:remove')")
    @Log(title = "去势", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(scCastrateService.deleteScCastrateByIds(ids));
    }

    @GetMapping("/search_ear_numbers")
    public AjaxResult searchEarNumbers(@RequestParam("query") String query){
        return success(scCastrateService.searchEarNumbers(query.trim()));
    }
}
