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.RecordWasteIn;
import com.ruoyi.manage.service.IRecordWasteInService;
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-01-29
 */
@Controller
@RequestMapping("/manage/record_waste_in")
public class RecordWasteInController extends BaseController
{
    private String prefix = "manage/record_waste_in";

    @Autowired
    private IRecordWasteInService recordWasteInService;

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

    /**
     * 查询废品入库记录列表
     */
    @RequiresPermissions("manage:record_waste_in:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RecordWasteIn recordWasteIn)
    {
        startPage();
        List<RecordWasteIn> list = recordWasteInService.selectRecordWasteInList(recordWasteIn);
        return getDataTable(list);
    }

    /**
     * 导出废品入库记录列表
     */
    @RequiresPermissions("manage:record_waste_in:export")
    @Log(title = "废品入库记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RecordWasteIn recordWasteIn)
    {
        List<RecordWasteIn> list = recordWasteInService.selectRecordWasteInList(recordWasteIn);
        ExcelUtil<RecordWasteIn> util = new ExcelUtil<RecordWasteIn>(RecordWasteIn.class);
        return util.exportExcel(list, "废品入库记录数据");
    }

    /**
     * 新增废品入库记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存废品入库记录
     */
    @RequiresPermissions("manage:record_waste_in:add")
    @Log(title = "废品入库记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RecordWasteIn recordWasteIn)
    {
        return toAjax(recordWasteInService.insertRecordWasteIn(recordWasteIn));
    }

    /**
     * 修改废品入库记录
     */
    @RequiresPermissions("manage:record_waste_in:edit")
    @GetMapping("/edit/{objid}")
    public String edit(@PathVariable("objid") Long objid, ModelMap mmap)
    {
        RecordWasteIn recordWasteIn = recordWasteInService.selectRecordWasteInByObjid(objid);
        mmap.put("recordWasteIn", recordWasteIn);
        return prefix + "/edit";
    }

    /**
     * 修改保存废品入库记录
     */
    @RequiresPermissions("manage:record_waste_in:edit")
    @Log(title = "废品入库记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RecordWasteIn recordWasteIn)
    {
        return toAjax(recordWasteInService.updateRecordWasteIn(recordWasteIn));
    }

    /**
     * 删除废品入库记录
     */
    @RequiresPermissions("manage:record_waste_in:remove")
    @Log(title = "废品入库记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(recordWasteInService.deleteRecordWasteInByObjids(ids));
    }
}
