package com.ruoyi.manage.controller;

import java.util.List;
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.manage.domain.RecordWasteOut;
import com.ruoyi.manage.service.IRecordWasteOutService;
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 wangh
 * @date 2024-02-21
 */
@Controller
@RequestMapping("/manage/record_waste_out")
public class RecordWasteOutController extends BaseController
{
    private String prefix = "manage/record_waste_out";

    @Autowired
    private IRecordWasteOutService recordWasteOutService;

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

    /**
     * 查询废品处理出库列表
     */
    @RequiresPermissions("manage:record_waste_out:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RecordWasteOut recordWasteOut)
    {
        startPage();
        List<RecordWasteOut> list = recordWasteOutService.selectRecordWasteOutList(recordWasteOut);
        return getDataTable(list);
    }

    /**
     * 导出废品处理出库列表
     */
    @RequiresPermissions("manage:record_waste_out:export")
    @Log(title = "废品处理出库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RecordWasteOut recordWasteOut)
    {
        List<RecordWasteOut> list = recordWasteOutService.selectRecordWasteOutList(recordWasteOut);
        ExcelUtil<RecordWasteOut> util = new ExcelUtil<RecordWasteOut>(RecordWasteOut.class);
        return util.exportExcel(list, "废品处理出库数据");
    }

    /**
     * 新增废品处理出库
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存废品处理出库
     */
    @RequiresPermissions("manage:record_waste_out:add")
    @Log(title = "废品处理出库", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RecordWasteOut recordWasteOut)
    {
        return toAjax(recordWasteOutService.insertRecordWasteOut(recordWasteOut));
    }

    /**
     * 修改废品处理出库
     */
    @RequiresPermissions("manage:record_waste_out:edit")
    @GetMapping("/edit/{objid}")
    public String edit(@PathVariable("objid") Long objid, ModelMap mmap)
    {
        RecordWasteOut recordWasteOut = recordWasteOutService.selectRecordWasteOutByObjid(objid);
        mmap.put("recordWasteOut", recordWasteOut);
        return prefix + "/edit";
    }

    /**
     * 修改保存废品处理出库
     */
    @RequiresPermissions("manage:record_waste_out:edit")
    @Log(title = "废品处理出库", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RecordWasteOut recordWasteOut)
    {
        return toAjax(recordWasteOutService.updateRecordWasteOut(recordWasteOut));
    }

    /**
     * 删除废品处理出库
     */
    @RequiresPermissions("manage:record_waste_out:remove")
    @Log(title = "废品处理出库", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(recordWasteOutService.deleteRecordWasteOutByObjids(ids));
    }
}
