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.ProReadrecord;
import com.ruoyi.traceability.service.IProReadrecordService;
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-18
 */
@Controller
@RequestMapping("/traceability/readRecord")
public class ProReadrecordController extends BaseController
{
    private String prefix = "traceability/readRecord";

    @Autowired
    private IProReadrecordService proReadrecordService;

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

    /**
     * 查询读取记录列表
     */
    @RequiresPermissions("traceability:readRecord:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ProReadrecord proReadrecord)
    {
        startPage();
        List<ProReadrecord> list = proReadrecordService.selectProReadrecordList(proReadrecord);
        return getDataTable(list);
    }

    /**
     * 导出读取记录列表
     */
    @RequiresPermissions("traceability:readRecord:export")
    @Log(title = "读取记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ProReadrecord proReadrecord)
    {
        List<ProReadrecord> list = proReadrecordService.selectProReadrecordList(proReadrecord);
        ExcelUtil<ProReadrecord> util = new ExcelUtil<ProReadrecord>(ProReadrecord.class);
        return util.exportExcel(list, "读取记录数据");
    }

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

    /**
     * 新增保存读取记录
     */
    @RequiresPermissions("traceability:readRecord:add")
    @Log(title = "读取记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ProReadrecord proReadrecord)
    {
        return toAjax(proReadrecordService.insertProReadrecord(proReadrecord));
    }

    /**
     * 修改读取记录
     */
    @RequiresPermissions("traceability:readRecord:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ProReadrecord proReadrecord = proReadrecordService.selectProReadrecordById(id);
        mmap.put("proReadrecord", proReadrecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存读取记录
     */
    @RequiresPermissions("traceability:readRecord:edit")
    @Log(title = "读取记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ProReadrecord proReadrecord)
    {
        return toAjax(proReadrecordService.updateProReadrecord(proReadrecord));
    }

    /**
     * 删除读取记录
     */
    @RequiresPermissions("traceability:readRecord:remove")
    @Log(title = "读取记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(proReadrecordService.deleteProReadrecordByIds(ids));
    }
}