package com.fs.company.controller;

import java.util.List;
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.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.enums.BusinessType;
import com.fs.company.domain.CompanyMaterial;
import com.fs.company.service.ICompanyMaterialService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 原材料Controller
 * 
 * @author fs
 * @date 2025-07-01
 */
@RestController
@RequestMapping("/company/companyMaterial")
public class CompanyMaterialController extends BaseController
{
    @Autowired
    private ICompanyMaterialService companyMaterialService;

    /**
     * 查询原材料列表
     */
    @PreAuthorize("@ss.hasPermi('company:companyMaterial:list')")
    @GetMapping("/list")
    public TableDataInfo list(CompanyMaterial companyMaterial)
    {
        startPage();
        List<CompanyMaterial> list = companyMaterialService.selectCompanyMaterialList(companyMaterial);
        return getDataTable(list);
    }

    /**
     * 导出原材料列表
     */
    @PreAuthorize("@ss.hasPermi('company:companyMaterial:export')")
    @Log(title = "原材料", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CompanyMaterial companyMaterial)
    {
        List<CompanyMaterial> list = companyMaterialService.selectCompanyMaterialList(companyMaterial);
        ExcelUtil<CompanyMaterial> util = new ExcelUtil<CompanyMaterial>(CompanyMaterial.class);
        return util.exportExcel(list, "原材料数据");
    }

    /**
     * 获取原材料详细信息
     */
    @PreAuthorize("@ss.hasPermi('company:companyMaterial:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(companyMaterialService.selectCompanyMaterialById(id));
    }

    /**
     * 新增原材料
     */
    @PreAuthorize("@ss.hasPermi('company:companyMaterial:add')")
    @Log(title = "原材料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CompanyMaterial companyMaterial)
    {
        return toAjax(companyMaterialService.insertCompanyMaterial(companyMaterial));
    }

    /**
     * 修改原材料
     */
    @PreAuthorize("@ss.hasPermi('company:companyMaterial:edit')")
    @Log(title = "原材料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CompanyMaterial companyMaterial)
    {
        return toAjax(companyMaterialService.updateCompanyMaterial(companyMaterial));
    }

    /**
     * 删除原材料
     */
    @PreAuthorize("@ss.hasPermi('company:companyMaterial:remove')")
    @Log(title = "原材料", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(companyMaterialService.deleteCompanyMaterialByIds(ids));
    }
}
