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.ProDownrecord;
import com.ruoyi.traceability.service.IProDownrecordService;
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-13
 */
@Controller
@RequestMapping("/traceability/downRecord")
public class ProDownrecordController extends BaseController
{
    private String prefix = "traceability/downRecord";

    @Autowired
    private IProDownrecordService proDownrecordService;

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

    /**
     * 查询下料记录列表
     */
    @RequiresPermissions("traceability:downRecord:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ProDownrecord proDownrecord)
    {
        startPage();
        List<ProDownrecord> list = proDownrecordService.selectProDownrecordList(proDownrecord);
        return getDataTable(list);
    }

    /**
     * 导出下料记录列表
     */
    @RequiresPermissions("traceability:downRecord:export")
    @Log(title = "下料记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ProDownrecord proDownrecord)
    {
        List<ProDownrecord> list = proDownrecordService.selectProDownrecordList(proDownrecord);
        ExcelUtil<ProDownrecord> util = new ExcelUtil<ProDownrecord>(ProDownrecord.class);
        return util.exportExcel(list, "下料记录数据");
    }

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

    /**
     * 新增保存下料记录
     */
    @RequiresPermissions("traceability:downRecord:add")
    @Log(title = "下料记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ProDownrecord proDownrecord)
    {
        return toAjax(proDownrecordService.insertProDownrecord(proDownrecord));
    }

    /**
     * 修改下料记录
     */
    @RequiresPermissions("traceability:downRecord:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ProDownrecord proDownrecord = proDownrecordService.selectProDownrecordById(id);
        mmap.put("proDownrecord", proDownrecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存下料记录
     */
    @RequiresPermissions("traceability:downRecord:edit")
    @Log(title = "下料记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ProDownrecord proDownrecord)
    {
        return toAjax(proDownrecordService.updateProDownrecord(proDownrecord));
    }

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