package com.ruoyi.traceability.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.traceability.domain.ProUprecord;
import com.ruoyi.traceability.service.IProUprecordService;
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 wenjy
 * @date 2022-11-09
 */
@Controller
@RequestMapping("/traceability/upRecord")
public class ProUprecordController extends BaseController
{
    private String prefix = "traceability/upRecord";

    @Autowired
    private IProUprecordService proUprecordService;

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

    /**
     * 查询上料记录列表
     */
    @RequiresPermissions("traceability:upRecord:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ProUprecord proUprecord)
    {
        startPage();
        List<ProUprecord> list = proUprecordService.selectProUprecordList(proUprecord);
        return getDataTable(list);
    }

    /**
     * 导出上料记录列表
     */
    @RequiresPermissions("traceability:upRecord:export")
    @Log(title = "上料记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ProUprecord proUprecord)
    {
        List<ProUprecord> list = proUprecordService.selectProUprecordList(proUprecord);
        ExcelUtil<ProUprecord> util = new ExcelUtil<ProUprecord>(ProUprecord.class);
        return util.exportExcel(list, "上料记录数据");
    }

    /**
     * 新增上料记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存上料记录
     */
    @RequiresPermissions("traceability:upRecord:add")
    @Log(title = "上料记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ProUprecord proUprecord)
    {
        return toAjax(proUprecordService.insertProUprecord(proUprecord));
    }

    /**
     * 修改上料记录
     */
    @RequiresPermissions("traceability:upRecord:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ProUprecord proUprecord = proUprecordService.selectProUprecordById(id);
        mmap.put("proUprecord", proUprecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存上料记录
     */
    @RequiresPermissions("traceability:upRecord:edit")
    @Log(title = "上料记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ProUprecord proUprecord)
    {
        return toAjax(proUprecordService.updateProUprecord(proUprecord));
    }

    /**
     * 删除上料记录
     */
    @RequiresPermissions("traceability:upRecord:remove")
    @Log(title = "上料记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(proUprecordService.deleteProUprecordByIds(ids));
    }
}
