package com.zhyc.module.dairyProducts.controller;

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

import com.zhyc.module.dairyProducts.domain.NpYogurtInsp;
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.dairyProducts.service.INpYogurtInspService;
import com.zhyc.common.utils.poi.ExcelUtil;
import com.zhyc.common.core.page.TableDataInfo;

/**
 * 酸奶生产，成品检疫记录Controller
 * * @author ruoyi
 * @date 2025-07-17
 */
@RestController
@RequestMapping("/yogurtTest/yogurtTest")
public class NpYogurtInspController extends BaseController
{
    @Autowired
    private INpYogurtInspService npYogurtInspService;

    /**
     * 查询酸奶生产，成品检疫记录列表
     */
    @PreAuthorize("@ss.hasPermi('yogurtTest:yogurtTest:list')")
    @GetMapping("/list")
    public TableDataInfo list(NpYogurtInsp npYogurtInsp)
    {
        startPage();
        List<NpYogurtInsp> list = npYogurtInspService.selectNpYogurtInspList(npYogurtInsp);
        return getDataTable(list);
    }

    /**
     * 导出酸奶生产，成品检疫记录列表
     */
    @PreAuthorize("@ss.hasPermi('yogurtTest:yogurtTest:export')")
    @Log(title = "酸奶生产，成品检疫记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NpYogurtInsp npYogurtInsp)
    {
        List<NpYogurtInsp> list = npYogurtInspService.selectNpYogurtInspList(npYogurtInsp);
        ExcelUtil<NpYogurtInsp> util = new ExcelUtil<NpYogurtInsp>(NpYogurtInsp.class);
        util.exportExcel(response, list, "酸奶生产，成品检疫记录数据");
    }

    /**
     * 获取酸奶生产，成品检疫记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('yogurtTest:yogurtTest:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(npYogurtInspService.selectNpYogurtInspById(id));
    }

    /**
     * 新增酸奶生产，成品检疫记录
     */
    @PreAuthorize("@ss.hasPermi('yogurtTest:yogurtTest:add')")
    @Log(title = "酸奶生产，成品检疫记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NpYogurtInsp npYogurtInsp)
    {
        // === 修改开始：注入当前用户和部门ID ===
        npYogurtInsp.setUserId(getUserId());
        npYogurtInsp.setDeptId(getDeptId());
        // === 修改结束 ===

        return toAjax(npYogurtInspService.insertNpYogurtInsp(npYogurtInsp));
    }

    /**
     * 修改酸奶生产，成品检疫记录
     */
    @PreAuthorize("@ss.hasPermi('yogurtTest:yogurtTest:edit')")
    @Log(title = "酸奶生产，成品检疫记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NpYogurtInsp npYogurtInsp)
    {
        return toAjax(npYogurtInspService.updateNpYogurtInsp(npYogurtInsp));
    }

    /**
     * 删除酸奶生产，成品检疫记录
     */
    @PreAuthorize("@ss.hasPermi('yogurtTest:yogurtTest:remove')")
    @Log(title = "酸奶生产，成品检疫记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(npYogurtInspService.deleteNpYogurtInspByIds(ids));
    }
}