package com.ruoyi.web.controller.coffee;

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.*;
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.system.domain.Material;
import com.ruoyi.system.service.IMaterialService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 原料Controller
 * 
 * @author ruoyi
 * @date 2022-04-28
 */
@RestController
@RequestMapping("/system/material")
public class MaterialController extends BaseController
{
    @Autowired
    private IMaterialService materialService;

    /**
     * 查询原料列表
     */
    @PreAuthorize("@ss.hasPermi('system:material:list')")
    @GetMapping("/list")
    public TableDataInfo list(Material material)
    {
        startPage();
        List<Material> list = materialService.selectMaterialList(material);
        return getDataTable(list);
    }



    /**
     * 获取原料详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:material:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(materialService.selectMaterialById(id));
    }

    /**
     * 新增原料
     */
  //  @PreAuthorize("@ss.hasPermi('system:material:add')")
    @Log(title = "原料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Material material)
    {
        return  AjaxResult.success(materialService.insertMaterial(material));
    }

    /**
     * 修改原料
     */
    @PreAuthorize("@ss.hasPermi('system:material:edit')")
    @Log(title = "原料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Material material)
    {
        return materialService.updateMaterial(material);
    }

    /**
     * 删除原料
     */
    @PreAuthorize("@ss.hasPermi('system:material:remove')")
    @Log(title = "原料", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@RequestParam  String id)
    {
        return  materialService.deleteMaterialById(id);
    }


}
