package com.yunfeiyun.agmp.fms.controller;

import java.util.List;

import com.yunfeiyun.agmp.fms.domain.MppMaterial;
import com.yunfeiyun.agmp.fms.domain.reqvo.MppMaterialReqVo;
import com.yunfeiyun.agmp.fms.domain.resvo.MppMaterialResVo;
import com.yunfeiyun.agmp.fms.service.IMppMaterialService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.yunfeiyun.agmp.common.annotation.Log;
import com.yunfeiyun.agmp.common.core.controller.BaseController;
import com.yunfeiyun.agmp.common.core.domain.AjaxResult;
import com.yunfeiyun.agmp.common.enums.BusinessType;
import com.yunfeiyun.agmp.common.core.page.TableDataInfo;

/**
 * 加工原材料Controller
 * 
 * @author 杨晓辉
 * @date 2023-07-03
 */
@RestController
@RequestMapping("/mpp/material")
public class MppMaterialController extends BaseController
{
    @Autowired
    private IMppMaterialService mppMaterialService;

    /**
     * 查询加工原材料列表
     */
    @PreAuthorize("@ss.hasPermi('mpp:material:list')")
    @GetMapping("/list")
    public TableDataInfo list(MppMaterialReqVo reqVo)
    {
        startPage();
        List<MppMaterialResVo> list = mppMaterialService.selectMppMaterialList(reqVo);
        return getDataTable(list);
    }

    /**
     * 获取加工原材料详细信息
     */
    @PreAuthorize("@ss.hasPermi('mpp:material:info')")
    @GetMapping(value = "/info")
    public AjaxResult getInfo(@RequestParam("materialId") String materialId)
    {
        return success(mppMaterialService.selectMppMaterialByMaterialId(materialId));
    }

    /**
     * 新增加工原材料
     */
    @PreAuthorize("@ss.hasPermi('mpp:material:add')")
    @Log(title = "加工原材料", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody MppMaterial mppMaterial)
    {
        return toAjax(mppMaterialService.insertMppMaterial(mppMaterial));
    }

    /**
     * 修改加工原材料
     */
    @PreAuthorize("@ss.hasPermi('mpp:material:edit')")
    @Log(title = "加工原材料", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody MppMaterial mppMaterial)
    {
        return toAjax(mppMaterialService.updateMppMaterial(mppMaterial));
    }

    /**
     * 删除加工原材料
     */
    @PreAuthorize("@ss.hasPermi('mpp:material:delete')")
    @Log(title = "加工原材料", businessType = BusinessType.DELETE)
	@DeleteMapping("/delete")
    public AjaxResult remove(@RequestParam("materialIds") String[] materialIds)
    {
        return toAjax(mppMaterialService.deleteMppMaterialByMaterialIds(materialIds));
    }
}
