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.ScChangeComment;
import com.zhyc.module.produce.manage_sheep.service.IScChangeCommentService;
import com.zhyc.common.utils.poi.ExcelUtil;
import com.zhyc.common.core.page.TableDataInfo;

/**
 * 改备注Controller
 * 
 * @author ruoyi
 * @date 2025-07-24
 */
@RestController
@RequestMapping("/changeComment/changeComment")
public class ScChangeCommentController extends BaseController
{
    @Autowired
    private IScChangeCommentService scChangeCommentService;

    /**
     * 查询改备注列表
     */
    @PreAuthorize("@ss.hasPermi('changeComment:changeComment:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScChangeComment scChangeComment)
    {
        startPage();
        List<ScChangeComment> list = scChangeCommentService.selectScChangeCommentList(scChangeComment);
        return getDataTable(list);
    }

    /**
     * 导出改备注列表
     */
    @PreAuthorize("@ss.hasPermi('changeComment:changeComment:export')")
    @Log(title = "改备注", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScChangeComment scChangeComment)
    {
        List<ScChangeComment> list = scChangeCommentService.selectScChangeCommentList(scChangeComment);
        ExcelUtil<ScChangeComment> util = new ExcelUtil<ScChangeComment>(ScChangeComment.class);
        util.exportExcel(response, list, "改备注数据");
    }

    /**
     * 获取改备注详细信息
     */
    @PreAuthorize("@ss.hasPermi('changeComment:changeComment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(scChangeCommentService.selectScChangeCommentById(id));
    }

    /**
     * 新增改备注
     */
    @PreAuthorize("@ss.hasPermi('changeComment:changeComment:add')")
    @Log(title = "改备注", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScChangeComment scChangeComment)
    {
        scChangeComment.setUserId(getUserId());
        scChangeComment.setDeptId(getDeptId());
        return toAjax(scChangeCommentService.insertScChangeComment(scChangeComment));
    }

    /**
     * 修改改备注
     */
    @PreAuthorize("@ss.hasPermi('changeComment:changeComment:edit')")
    @Log(title = "改备注", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScChangeComment scChangeComment)
    {
        return toAjax(scChangeCommentService.updateScChangeComment(scChangeComment));
    }

    /**
     * 删除改备注
     */
    @PreAuthorize("@ss.hasPermi('changeComment:changeComment:remove')")
    @Log(title = "改备注", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(scChangeCommentService.deleteScChangeCommentByIds(ids));
    }

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