package com.ruoyi.project.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.project.business.domain.TbFile;
import com.ruoyi.project.business.service.ITbFileService;
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.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 2024-04-19
 */
@RestController
@RequestMapping("/system/file")
public class TbFileController extends BaseController
{
    @Autowired
    private ITbFileService tbFileService;

    /**
     * 查询附件列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TbFile tbFile)
    {
        startPage();
        List<TbFile> list = tbFileService.selectTbFileList(tbFile);
        return getDataTable(list);
    }

    /**
     * 导出附件列表
     */
    @Log(title = "附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbFile tbFile)
    {
        List<TbFile> list = tbFileService.selectTbFileList(tbFile);
        ExcelUtil<TbFile> util = new ExcelUtil<TbFile>(TbFile.class);
        util.exportExcel(response, list, "附件数据");
    }

    /**
     * 获取附件详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbFileService.selectTbFileById(id));
    }

    /**
     * 新增附件
     */
    @Log(title = "附件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbFile tbFile)
    {
        return toAjax(tbFileService.insertTbFile(tbFile));
    }

    /**
     * 修改附件
     */
    @Log(title = "附件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbFile tbFile)
    {
        return toAjax(tbFileService.updateTbFile(tbFile));
    }

    /**
     * 删除附件
     */
    @Log(title = "附件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbFileService.deleteTbFileByIds(ids));
    }
}
