package com.ruoyi.project.sems.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.sems.domain.TApproverFile;
import com.ruoyi.project.sems.service.ITApproverFileService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 审批附件Controller
 *
 * @author ruoyi
 * @date 2021-08-08
 */
@RestController
@RequestMapping("/sems/approveFile")
public class TApproverFileController extends BaseController
{
    @Autowired
    private ITApproverFileService tApproverFileService;

    /**
     * 查询审批附件列表
     */
    @PreAuthorize("@ss.hasPermi('sems:approveFile:list')")
    @GetMapping("/list")
    public TableDataInfo list(TApproverFile tApproverFile)
    {
        startPage();
        List<TApproverFile> list = tApproverFileService.selectTApproverFileList(tApproverFile);
        return getDataTable(list);
    }

    /**
     * 导出审批附件列表
     */
    @PreAuthorize("@ss.hasPermi('sems:approveFile:export')")
    @Log(title = "审批附件", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TApproverFile tApproverFile)
    {
        List<TApproverFile> list = tApproverFileService.selectTApproverFileList(tApproverFile);
        ExcelUtil<TApproverFile> util = new ExcelUtil<TApproverFile>(TApproverFile.class);
        return util.exportExcel(list, "approveFile");
    }

    /**
     * 获取审批附件详细信息
     */
    @PreAuthorize("@ss.hasPermi('sems:approveFile:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tApproverFileService.selectTApproverFileById(id));
    }

    /**
     * 新增审批附件
     */
    @PreAuthorize("@ss.hasPermi('sems:approveFile:add')")
    @Log(title = "审批附件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TApproverFile tApproverFile)
    {
        return toAjax(tApproverFileService.insertTApproverFile(tApproverFile));
    }

    /**
     * 修改审批附件
     */
    @PreAuthorize("@ss.hasPermi('sems:approveFile:edit')")
    @Log(title = "审批附件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TApproverFile tApproverFile)
    {
        return toAjax(tApproverFileService.updateTApproverFile(tApproverFile));
    }

    /**
     * 删除审批附件
     */
    @PreAuthorize("@ss.hasPermi('sems:approveFile:remove')")
    @Log(title = "审批附件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tApproverFileService.deleteTApproverFileByIds(ids));
    }
}
