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

/**
 * 鲜奶生产，成品检验记录Controller
 * * @author ruoyi
 * @date 2025-07-18
 */
@RestController
@RequestMapping("/freshMilkTest/freshMilkTest")
public class NpFreshMilkInspController extends BaseController
{
    @Autowired
    private INpFreshMilkInspService npFreshMilkInspService;

    /**
     * 查询鲜奶生产，成品检验记录列表
     */
    @PreAuthorize("@ss.hasPermi('freshMilkTest:freshMilkTest:list')")
    @GetMapping("/list")
    public TableDataInfo list(NpFreshMilkInsp npFreshMilkInsp)
    {
        startPage();
        List<NpFreshMilkInsp> list = npFreshMilkInspService.selectNpFreshMilkInspList(npFreshMilkInsp);
        return getDataTable(list);
    }

    /**
     * 导出鲜奶生产，成品检验记录列表
     */
    @PreAuthorize("@ss.hasPermi('freshMilkTest:freshMilkTest:export')")
    @Log(title = "鲜奶生产，成品检验记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NpFreshMilkInsp npFreshMilkInsp)
    {
        List<NpFreshMilkInsp> list = npFreshMilkInspService.selectNpFreshMilkInspList(npFreshMilkInsp);
        ExcelUtil<NpFreshMilkInsp> util = new ExcelUtil<NpFreshMilkInsp>(NpFreshMilkInsp.class);
        util.exportExcel(response, list, "鲜奶生产，成品检验记录数据");
    }

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

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

        return toAjax(npFreshMilkInspService.insertNpFreshMilkInsp(npFreshMilkInsp));
    }

    /**
     * 修改鲜奶生产，成品检验记录
     */
    @PreAuthorize("@ss.hasPermi('freshMilkTest:freshMilkTest:edit')")
    @Log(title = "鲜奶生产，成品检验记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NpFreshMilkInsp npFreshMilkInsp)
    {
        return toAjax(npFreshMilkInspService.updateNpFreshMilkInsp(npFreshMilkInsp));
    }

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