package com.ruoyi.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.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cs.domain.CsFile;
import com.ruoyi.cs.service.ICsFileService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文件上传Controller
 *
 * @author ruoyi
 * @date 2024-10-12
 */
@RestController
@RequestMapping("/cs/csFile")
public class CsFileController extends BaseController
{
    @Autowired
    private ICsFileService csFileService;

    /**
     * 查询文件上传列表
     */
    @PreAuthorize("@ss.hasPermi('cs:csFile:list')")
    @GetMapping("/list")
    public TableDataInfo list(CsFile csFile)
    {
        startPage();
        List<CsFile> list = csFileService.selectCsFileList(csFile);
        return getDataTable(list);
    }

    /**
     * 导出文件上传列表
     */
    @PreAuthorize("@ss.hasPermi('cs:csFile:export')")
    @Log(title = "文件上传", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CsFile csFile)
    {
        List<CsFile> list = csFileService.selectCsFileList(csFile);
        ExcelUtil<CsFile> util = new ExcelUtil<CsFile>(CsFile.class);
        util.exportExcel(response, list, "文件上传数据");
    }

    /**
     * 获取文件上传详细信息
     */
    @PreAuthorize("@ss.hasPermi('cs:csFile:query')")
    @GetMapping(value = "/{fileId}")
    public AjaxResult getInfo(@PathVariable("fileId") String fileId)
    {
        return AjaxResult.success(csFileService.selectCsFileByFileId(fileId));
    }

    /**
     * 新增文件上传
     */
    @PreAuthorize("@ss.hasPermi('cs:csFile:add')")
    @Log(title = "文件上传", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CsFile csFile)
    {
        return toAjax(csFileService.insertCsFile(csFile));
    }

    /**
     * 修改文件上传
     */
    @PreAuthorize("@ss.hasPermi('cs:csFile:edit')")
    @Log(title = "文件上传", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CsFile csFile)
    {
        return toAjax(csFileService.updateCsFile(csFile));
    }

    /**
     * 删除文件上传
     */
    @PreAuthorize("@ss.hasPermi('cs:csFile:remove')")
    @Log(title = "文件上传", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fileIds}")
    public AjaxResult remove(@PathVariable String[] fileIds)
    {
        return toAjax(csFileService.deleteCsFileByFileIds(fileIds));
    }
}
