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

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.module.produce.manage_sheep.domain.ScChangeVariety;
import com.zhyc.module.produce.manage_sheep.service.IScChangeVarietyService;
import com.zhyc.common.utils.poi.ExcelUtil;
import com.zhyc.common.core.page.TableDataInfo;

/**
 * 改品种记录Controller
 * 
 * @author ruoyi
 * @date 2025-07-24
 */
@RestController
@RequestMapping("/changeVariety/changeVariety")
public class ScChangeVarietyController extends BaseController
{
    @Autowired
    private IScChangeVarietyService scChangeVarietyService;

    /**
     * 查询改品种记录列表
     */
    @PreAuthorize("@ss.hasPermi('changeVariety:changeVariety:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScChangeVariety scChangeVariety)
    {
        startPage();
        List<ScChangeVariety> list = scChangeVarietyService.selectScChangeVarietyList(scChangeVariety);
        return getDataTable(list);
    }

    /**
     * 导出改品种记录列表
     */
    @PreAuthorize("@ss.hasPermi('changeVariety:changeVariety:export')")
    @Log(title = "改品种记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScChangeVariety scChangeVariety)
    {
        List<ScChangeVariety> list = scChangeVarietyService.selectScChangeVarietyList(scChangeVariety);
        ExcelUtil<ScChangeVariety> util = new ExcelUtil<ScChangeVariety>(ScChangeVariety.class);
        util.exportExcel(response, list, "改品种记录数据");
    }

    /**
     * 获取改品种记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('changeVariety:changeVariety:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(scChangeVarietyService.selectScChangeVarietyById(id));
    }

    /**
     * 新增改品种记录
     */
    @PreAuthorize("@ss.hasPermi('changeVariety:changeVariety:add')")
    @Log(title = "改品种记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScChangeVariety scChangeVariety)
    {
        scChangeVariety.setUserId(getUserId());
        scChangeVariety.setDeptId(getDeptId());
        return toAjax(scChangeVarietyService.insertScChangeVariety(scChangeVariety));
    }

    /**
     * 修改改品种记录
     */
    @PreAuthorize("@ss.hasPermi('changeVariety:changeVariety:edit')")
    @Log(title = "改品种记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScChangeVariety scChangeVariety)
    {
        return toAjax(scChangeVarietyService.updateScChangeVariety(scChangeVariety));
    }

    /**
     * 删除改品种记录
     */
    @PreAuthorize("@ss.hasPermi('changeVariety:changeVariety:remove')")
    @Log(title = "改品种记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(scChangeVarietyService.deleteScChangeVarietyByIds(ids));
    }

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