package com.ruoyi.project.patrol.patrol.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.patrol.patrol.domain.TFile;
import com.ruoyi.project.patrol.patrol.service.ITFileService;
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 2023-08-29
 */
@RestController
@RequestMapping("/patrol/file")
public class TFileController extends BaseController
{
    @Autowired
    private ITFileService tFileService;

    /**
     * 查询附件列表
     */
    @PreAuthorize("@ss.hasPermi('patrol:file:list')")
    @GetMapping("/list")
    public TableDataInfo list(TFile tFile)
    {
        startPage();
        List<TFile> list = tFileService.selectTFileList(tFile);
        return getDataTable(list);
    }

    /**
     * 导出附件列表
     */
    
    @Log(title = "附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public AjaxResult export(TFile tFile)
    {
        List<TFile> list = tFileService.selectTFileList(tFile);
        ExcelUtil<TFile> util = new ExcelUtil<TFile>(TFile.class);
        return util.exportExcel(list,  "附件数据");
    }

    /**
     * 获取附件详细信息
     */
    @PreAuthorize("@ss.hasPermi('patrol:file:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tFileService.selectTFileById(id));
    }

    /**
     * 新增附件
     */
    @PreAuthorize("@ss.hasPermi('patrol:file:add')")
    @Log(title = "附件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TFile tFile)
    {
        return toAjax(tFileService.insertTFile(tFile));
    }

    /**
     * 修改附件
     */
    @PreAuthorize("@ss.hasPermi('patrol:file:edit')")
    @Log(title = "附件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TFile tFile)
    {
        return toAjax(tFileService.updateTFile(tFile));
    }

    /**
     * 删除附件
     */
    @PreAuthorize("@ss.hasPermi('patrol:file:remove')")
    @Log(title = "附件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tFileService.deleteTFileByIds(ids));
    }
}
