package com.zhyc.module.dairyProducts.controller;

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

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

/**
 * 称重校正Controller
 * * @author ruoyi
 * @date 2025-07-12
 */
@RestController
@RequestMapping("/weightCorrection/weightCorrection")
public class XzWegihCorrectionController extends BaseController
{
    @Autowired
    private IXzWegihCorrectionService xzWegihCorrectionService;

    /**
     * 查询称重校正列表
     */
    @PreAuthorize("@ss.hasPermi('weightCorrection:weightCorrection:list')")
    @GetMapping("/list")
    public TableDataInfo list(XzWegihCorrection xzWegihCorrection)
    {
        startPage();
        List<XzWegihCorrection> list = xzWegihCorrectionService.selectXzWegihCorrectionList(xzWegihCorrection);
        return getDataTable(list);
    }

    /**
     * 导出称重校正列表
     */
    @PreAuthorize("@ss.hasPermi('weightCorrection:weightCorrection:export')")
    @Log(title = "称重校正", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, XzWegihCorrection xzWegihCorrection)
    {
        List<XzWegihCorrection> list = xzWegihCorrectionService.selectXzWegihCorrectionList(xzWegihCorrection);
        ExcelUtil<XzWegihCorrection> util = new ExcelUtil<XzWegihCorrection>(XzWegihCorrection.class);
        util.exportExcel(response, list, "称重校正数据");
    }

    /**
     * 获取称重校正详细信息
     */
    @PreAuthorize("@ss.hasPermi('weightCorrection:weightCorrection:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(xzWegihCorrectionService.selectXzWegihCorrectionById(id));
    }

    /**
     * 新增称重校正
     */
    @PreAuthorize("@ss.hasPermi('weightCorrection:weightCorrection:add')")
    @Log(title = "称重校正", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody XzWegihCorrection xzWegihCorrection)
    {
        // 自动填充用户ID和部门ID
        xzWegihCorrection.setUserId(getUserId());
        xzWegihCorrection.setDeptId(getDeptId());
        return toAjax(xzWegihCorrectionService.insertXzWegihCorrection(xzWegihCorrection));
    }

    /**
     * 修改称重校正
     */
    @PreAuthorize("@ss.hasPermi('weightCorrection:weightCorrection:edit')")
    @Log(title = "称重校正", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody XzWegihCorrection xzWegihCorrection)
    {
        return toAjax(xzWegihCorrectionService.updateXzWegihCorrection(xzWegihCorrection));
    }

    /**
     * 删除称重校正
     */
    @PreAuthorize("@ss.hasPermi('weightCorrection:weightCorrection:remove')")
    @Log(title = "称重校正", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(xzWegihCorrectionService.deleteXzWegihCorrectionByIds(ids));
    }
}