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.ProLyUpload;
import com.ruoyi.traceability.service.IProLyUploadService;
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-22
 */
@Controller
@RequestMapping("/traceability/lyupload")
public class ProLyUploadController extends BaseController
{
    private String prefix = "traceability/lyupload";

    @Autowired
    private IProLyUploadService proLyUploadService;

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

    /**
     * 查询冷压数据上传列表
     */
    @RequiresPermissions("traceability:lyupload:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ProLyUpload proLyUpload)
    {
        startPage();
        List<ProLyUpload> list = proLyUploadService.selectProLyUploadList(proLyUpload);
        return getDataTable(list);
    }

    /**
     * 导出冷压数据上传列表
     */
    @RequiresPermissions("traceability:lyupload:export")
    @Log(title = "冷压数据上传", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ProLyUpload proLyUpload)
    {
        List<ProLyUpload> list = proLyUploadService.selectProLyUploadList(proLyUpload);
        ExcelUtil<ProLyUpload> util = new ExcelUtil<ProLyUpload>(ProLyUpload.class);
        return util.exportExcel(list, "冷压数据上传数据");
    }

    /**
     * 新增冷压数据上传
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存冷压数据上传
     */
    @RequiresPermissions("traceability:lyupload:add")
    @Log(title = "冷压数据上传", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ProLyUpload proLyUpload)
    {
        return toAjax(proLyUploadService.insertProLyUpload(proLyUpload));
    }

    /**
     * 修改冷压数据上传
     */
    @RequiresPermissions("traceability:lyupload:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ProLyUpload proLyUpload = proLyUploadService.selectProLyUploadById(id);
        mmap.put("proLyUpload", proLyUpload);
        return prefix + "/edit";
    }

    /**
     * 修改保存冷压数据上传
     */
    @RequiresPermissions("traceability:lyupload:edit")
    @Log(title = "冷压数据上传", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ProLyUpload proLyUpload)
    {
        return toAjax(proLyUploadService.updateProLyUpload(proLyUpload));
    }

    /**
     * 删除冷压数据上传
     */
    @RequiresPermissions("traceability:lyupload:remove")
    @Log(title = "冷压数据上传", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(proLyUploadService.deleteProLyUploadByIds(ids));
    }
}
