package com.benyun.project.third.material.controller;


import com.benyun.common.utils.poi.ExcelUtil;
import com.benyun.framework.aspectj.lang.annotation.Log;
import com.benyun.framework.aspectj.lang.enums.BusinessType;
import com.benyun.framework.web.controller.BaseController;
import com.benyun.framework.web.domain.AjaxResult;
import com.benyun.framework.web.page.TableDataInfo;
import com.benyun.project.third.material.domain.ByMaterialOut;
import com.benyun.project.third.material.service.IByMaterialOutService;
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.*;

import java.util.List;

/**
 * 犇云物料内外对应Controller
 *
 * @author benyun
 * @date 2023-12-04
 */
@Controller
@RequestMapping("/system/out")
public class ByMaterialOutController extends BaseController
{
    private String prefix = "system/out";

    @Autowired
    private IByMaterialOutService byMaterialOutService;

    @RequiresPermissions("system:out:view")
    @GetMapping()
    public String out()
    {
        return prefix + "/out";
    }

    /**
     * 查询犇云物料内外对应列表
     */
    @RequiresPermissions("system:out:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ByMaterialOut byMaterialOut)
    {
        startPage();
        List<ByMaterialOut> list = byMaterialOutService.selectByMaterialOutList(byMaterialOut);
        return getDataTable(list);
    }

    /**
     * 导出犇云物料内外对应列表
     */
    @RequiresPermissions("system:out:export")
    @Log(title = "犇云物料内外对应", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ByMaterialOut byMaterialOut)
    {
        List<ByMaterialOut> list = byMaterialOutService.selectByMaterialOutList(byMaterialOut);
        ExcelUtil<ByMaterialOut> util = new ExcelUtil<ByMaterialOut>(ByMaterialOut.class);
        return util.exportExcel(list, "犇云物料内外对应数据");
    }

    /**
     * 新增犇云物料内外对应
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存犇云物料内外对应
     */
    @RequiresPermissions("system:out:add")
    @Log(title = "犇云物料内外对应", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ByMaterialOut byMaterialOut)
    {
        return toAjax(byMaterialOutService.insertByMaterialOut(byMaterialOut));
    }

    /**
     * 修改犇云物料内外对应
     */
    @RequiresPermissions("system:out:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ByMaterialOut byMaterialOut = byMaterialOutService.selectByMaterialOutById(id);
        mmap.put("byMaterialOut", byMaterialOut);
        return prefix + "/edit";
    }

    /**
     * 修改保存犇云物料内外对应
     */
    @RequiresPermissions("system:out:edit")
    @Log(title = "犇云物料内外对应", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ByMaterialOut byMaterialOut)
    {
        return toAjax(byMaterialOutService.updateByMaterialOut(byMaterialOut));
    }

    /**
     * 删除犇云物料内外对应
     */
    @RequiresPermissions("system:out:remove")
    @Log(title = "犇云物料内外对应", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(byMaterialOutService.deleteByMaterialOutByIds(ids));
    }
}
