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.ProLogrecord;
import com.ruoyi.traceability.service.IProLogrecordService;
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-12-01
 */
@Controller
@RequestMapping("/traceability/logrecord")
public class ProLogrecordController extends BaseController
{
    private String prefix = "traceability/logrecord";

    @Autowired
    private IProLogrecordService proLogrecordService;

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

    /**
     * 查询机台日志列表
     */
    @RequiresPermissions("traceability:logrecord:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ProLogrecord proLogrecord)
    {
        startPage();
        List<ProLogrecord> list = proLogrecordService.selectProLogrecordList(proLogrecord);
        return getDataTable(list);
    }

    /**
     * 导出机台日志列表
     */
    @RequiresPermissions("traceability:logrecord:export")
    @Log(title = "机台日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ProLogrecord proLogrecord)
    {
        List<ProLogrecord> list = proLogrecordService.selectProLogrecordList(proLogrecord);
        ExcelUtil<ProLogrecord> util = new ExcelUtil<ProLogrecord>(ProLogrecord.class);
        return util.exportExcel(list, "机台日志数据");
    }

    /**
     * 新增机台日志
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存机台日志
     */
    @RequiresPermissions("traceability:logrecord:add")
    @Log(title = "机台日志", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ProLogrecord proLogrecord)
    {
        return toAjax(proLogrecordService.insertProLogrecord(proLogrecord));
    }

    /**
     * 修改机台日志
     */
    @RequiresPermissions("traceability:logrecord:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ProLogrecord proLogrecord = proLogrecordService.selectProLogrecordById(id);
        mmap.put("proLogrecord", proLogrecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存机台日志
     */
    @RequiresPermissions("traceability:logrecord:edit")
    @Log(title = "机台日志", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ProLogrecord proLogrecord)
    {
        return toAjax(proLogrecordService.updateProLogrecord(proLogrecord));
    }

    /**
     * 删除机台日志
     */
    @RequiresPermissions("traceability:logrecord:remove")
    @Log(title = "机台日志", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(proLogrecordService.deleteProLogrecordByIds(ids));
    }
}
