package com.ruoyi.web.controller.baseinfo;

import java.util.List;

import com.ruoyi.baseinfo.domain.BaseWorkingprocedureInfo;
import com.ruoyi.baseinfo.service.IBaseWorkingprocedureInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.baseinfo.domain.BaseMaterialtypeInfo;
import com.ruoyi.baseinfo.service.IBaseMaterialtypeInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物料类型基础信息Controller
 * 
 * @author CaesarBao
 * @date 2020-10-22
 */
@Controller
@RequestMapping("/baseinfo/materialtypeinfo")
public class BaseMaterialtypeInfoController extends BaseController
{
    private String prefix = "baseinfo/materialtypeinfo";

    @Autowired
    private IBaseMaterialtypeInfoService baseMaterialtypeInfoService;
    @Autowired
    private IBaseWorkingprocedureInfoService baseWorkingprocedureInfoService;

    @RequiresPermissions("baseinfo:materialtypeinfo:view")
    @GetMapping()
    public String materialtypeinfo(ModelMap mmap)
    {
        BaseWorkingprocedureInfo BaseWorkingprocedureInfo = new BaseWorkingprocedureInfo();
        mmap.put("cbWorkingProcedureInfo",baseWorkingprocedureInfoService.selectBaseWorkingprocedureInfoList(BaseWorkingprocedureInfo));
        return prefix + "/materialtypeinfo";
    }

    /**
     * 查询物料类型基础信息列表
     */
    @RequiresPermissions("baseinfo:materialtypeinfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BaseMaterialtypeInfo baseMaterialtypeInfo)
    {
        startPage();
        List<BaseMaterialtypeInfo> list = baseMaterialtypeInfoService.selectBaseMaterialtypeInfoList(baseMaterialtypeInfo);
        return getDataTable(list);
    }

    /**
     * 导出物料类型基础信息列表
     */
    @RequiresPermissions("baseinfo:materialtypeinfo:export")
    @Log(title = "物料类型基础信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BaseMaterialtypeInfo baseMaterialtypeInfo)
    {
        List<BaseMaterialtypeInfo> list = baseMaterialtypeInfoService.selectBaseMaterialtypeInfoList(baseMaterialtypeInfo);
        ExcelUtil<BaseMaterialtypeInfo> util = new ExcelUtil<BaseMaterialtypeInfo>(BaseMaterialtypeInfo.class);
        return util.exportExcel(list, "materialtypeinfo");
    }

    /**
     * 新增物料类型基础信息
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        mmap.put("cbWorkingProcedureInfo",baseWorkingprocedureInfoService.selectAddBaseWorkingprocedureInfoList());
        return prefix + "/add";
    }

    /**
     * 新增保存物料类型基础信息
     */
    @RequiresPermissions("baseinfo:materialtypeinfo:add")
    @Log(title = "物料类型基础信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BaseMaterialtypeInfo baseMaterialtypeInfo)
    {
        return toAjax(baseMaterialtypeInfoService.insertBaseMaterialtypeInfo(baseMaterialtypeInfo));
    }

    /**
     * 修改物料类型基础信息
     */
    @GetMapping("/edit/{objid}")
    public String edit(@PathVariable("objid") Long objid, ModelMap mmap)
    {
        BaseMaterialtypeInfo baseMaterialtypeInfo = baseMaterialtypeInfoService.selectBaseMaterialtypeInfoById(objid);
        mmap.put("cbEditWorkingProcedureInfo",baseWorkingprocedureInfoService.selectEditBaseWorkingprocedureInfoList(baseMaterialtypeInfo.getWorkingProcedureId()));
        mmap.put("baseMaterialtypeInfo", baseMaterialtypeInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存物料类型基础信息
     */
    @RequiresPermissions("baseinfo:materialtypeinfo:edit")
    @Log(title = "物料类型基础信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BaseMaterialtypeInfo baseMaterialtypeInfo)
    {
        return toAjax(baseMaterialtypeInfoService.updateBaseMaterialtypeInfo(baseMaterialtypeInfo));
    }

    /**
     * 删除物料类型基础信息
     */
    @RequiresPermissions("baseinfo:materialtypeinfo:remove")
    @Log(title = "物料类型基础信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(baseMaterialtypeInfoService.deleteBaseMaterialtypeInfoByIds(ids));
    }
}
