package com.zhyc.module.dairyProducts.controller;

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

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

/**
 * 生乳检验记录Controller
 * * @author ruoyi
 * @date 2025-07-15
 */
@RestController
@RequestMapping("/rawMilkTest/rawMilkTest")
public class NpRawMilkInspeController extends BaseController
{
    @Autowired
    private INpRawMilkInspeService npRawMilkInspeService;

    /**
     * 查询生乳检验记录列表
     */
    @PreAuthorize("@ss.hasPermi('rawMilkTest:rawMilkTest:list')")
    @GetMapping("/list")
    public TableDataInfo list(NpRawMilkInspe npRawMilkInspe)
    {
        startPage();
        List<NpRawMilkInspe> list = npRawMilkInspeService.selectNpRawMilkInspeList(npRawMilkInspe);
        return getDataTable(list);
    }

    /**
     * 导出生乳检验记录列表
     */
    @PreAuthorize("@ss.hasPermi('rawMilkTest:rawMilkTest:export')")
    @Log(title = "生乳检验记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NpRawMilkInspe npRawMilkInspe)
    {
        List<NpRawMilkInspe> list = npRawMilkInspeService.selectNpRawMilkInspeList(npRawMilkInspe);
        ExcelUtil<NpRawMilkInspe> util = new ExcelUtil<NpRawMilkInspe>(NpRawMilkInspe.class);
        util.exportExcel(response, list, "生乳检验记录数据");
    }

    /**
     * 获取生乳检验记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('rawMilkTest:rawMilkTest:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(npRawMilkInspeService.selectNpRawMilkInspeById(id));
    }

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

        return toAjax(npRawMilkInspeService.insertNpRawMilkInspe(npRawMilkInspe));
    }

    /**
     * 修改生乳检验记录
     */
    @PreAuthorize("@ss.hasPermi('rawMilkTest:rawMilkTest:edit')")
    @Log(title = "生乳检验记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NpRawMilkInspe npRawMilkInspe)
    {
        return toAjax(npRawMilkInspeService.updateNpRawMilkInspe(npRawMilkInspe));
    }

    /**
     * 删除生乳检验记录
     */
    @PreAuthorize("@ss.hasPermi('rawMilkTest:rawMilkTest:remove')")
    @Log(title = "生乳检验记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(npRawMilkInspeService.deleteNpRawMilkInspeByIds(ids));
    }
}