package com.ruoyi.web.controller.sapMaterial;

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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sapMaterial.domain.SapMaterial;
import com.ruoyi.sapMaterial.service.ISapMaterialService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物料管理Controller
 *
 * @author ruoyi
 * @date 2024-03-12
 */
@RestController
@RequestMapping("/sapMaterial/sapMaterial")
public class SapMaterialController extends BaseController
{
    @Autowired
    private ISapMaterialService sapMaterialService;

    /**
     * 查询物料管理列表
     */
    @PreAuthorize("@ss.hasPermi('sapMaterial:sapMaterial:list')")
    @GetMapping("/list")
    public TableDataInfo list(SapMaterial sapMaterial)
    {
        startPage();
        List<SapMaterial> list = sapMaterialService.selectSapMaterialList(sapMaterial);
        return getDataTable(list);
    }

    /**
     * 导出物料管理列表
     */
    @PreAuthorize("@ss.hasPermi('sapMaterial:sapMaterial:export')")
    @Log(title = "物料管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SapMaterial sapMaterial)
    {
        List<SapMaterial> list = sapMaterialService.selectSapMaterialList(sapMaterial);
        ExcelUtil<SapMaterial> util = new ExcelUtil<SapMaterial>(SapMaterial.class);
        util.exportExcel(response, list, "物料管理数据");
    }

    /**
     * 获取物料管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('sapMaterial:sapMaterial:query')")
    @GetMapping(value = "/{materialId}")
    public AjaxResult getInfo(@PathVariable("materialId") Long materialId)
    {
        return success(sapMaterialService.selectSapMaterialByMaterialId(materialId));
    }

    /**
     * 新增物料管理
     */
    @PreAuthorize("@ss.hasPermi('sapMaterial:sapMaterial:add')")
    @Log(title = "物料管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SapMaterial sapMaterial)
    {
        return toAjax(sapMaterialService.insertSapMaterial(sapMaterial));
    }

    /**
     * 修改物料管理
     */
    @PreAuthorize("@ss.hasPermi('sapMaterial:sapMaterial:edit')")
    @Log(title = "物料管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SapMaterial sapMaterial)
    {
        return toAjax(sapMaterialService.updateSapMaterial(sapMaterial));
    }

    /**
     * 删除物料管理
     */
    @PreAuthorize("@ss.hasPermi('sapMaterial:sapMaterial:remove')")
    @Log(title = "物料管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{materialIds}")
    public AjaxResult remove(@PathVariable Long[] materialIds)
    {
        return toAjax(sapMaterialService.deleteSapMaterialByMaterialIds(materialIds));
    }
}
