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

/**
 * 干物质校正Controller
 * * @author ruoyi
 * @date 2025-07-12
 */
@RestController
@RequestMapping("/dryMatterCorrection/dryMatterCorrection")
public class XzDryMatterCorrectionController extends BaseController
{
    @Autowired
    private IXzDryMatterCorrectionService xzDryMatterCorrectionService;

    /**
     * 查询干物质校正列表
     */
    @PreAuthorize("@ss.hasPermi('dryMatterCorrection:dryMatterCorrection:list')")
    @GetMapping("/list")
    public TableDataInfo list(XzDryMatterCorrection xzDryMatterCorrection)
    {
        startPage();
        List<XzDryMatterCorrection> list = xzDryMatterCorrectionService.selectXzDryMatterCorrectionList(xzDryMatterCorrection);
        return getDataTable(list);
    }

    /**
     * 导出干物质校正列表
     */
    @PreAuthorize("@ss.hasPermi('dryMatterCorrection:dryMatterCorrection:export')")
    @Log(title = "干物质校正", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, XzDryMatterCorrection xzDryMatterCorrection)
    {
        List<XzDryMatterCorrection> list = xzDryMatterCorrectionService.selectXzDryMatterCorrectionList(xzDryMatterCorrection);
        ExcelUtil<XzDryMatterCorrection> util = new ExcelUtil<XzDryMatterCorrection>(XzDryMatterCorrection.class);
        util.exportExcel(response, list, "干物质校正数据");
    }

    /**
     * 获取干物质校正详细信息
     */
    @PreAuthorize("@ss.hasPermi('dryMatterCorrection:dryMatterCorrection:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(xzDryMatterCorrectionService.selectXzDryMatterCorrectionById(id));
    }

    /**
     * 新增干物质校正
     */
    @PreAuthorize("@ss.hasPermi('dryMatterCorrection:dryMatterCorrection:add')")
    @Log(title = "干物质校正", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody XzDryMatterCorrection xzDryMatterCorrection)
    {
        // 自动填充用户ID和部门ID
        xzDryMatterCorrection.setUserId(getUserId());
        xzDryMatterCorrection.setDeptId(getDeptId());
        return toAjax(xzDryMatterCorrectionService.insertXzDryMatterCorrection(xzDryMatterCorrection));
    }

    /**
     * 修改干物质校正
     */
    @PreAuthorize("@ss.hasPermi('dryMatterCorrection:dryMatterCorrection:edit')")
    @Log(title = "干物质校正", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody XzDryMatterCorrection xzDryMatterCorrection)
    {
        return toAjax(xzDryMatterCorrectionService.updateXzDryMatterCorrection(xzDryMatterCorrection));
    }

    /**
     * 删除干物质校正
     */
    @PreAuthorize("@ss.hasPermi('dryMatterCorrection:dryMatterCorrection:remove')")
    @Log(title = "干物质校正", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(xzDryMatterCorrectionService.deleteXzDryMatterCorrectionByIds(ids));
    }
}