package com.ruoyi.system.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.system.domain.MinioFile;
import com.ruoyi.system.service.IMinioFileService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * minio文件存储Controller
 *
 * @author ruoyi
 * @date 2024-07-30
 */
@RestController
@RequestMapping("/system/file")
public class MinioFileController extends BaseController
{
    @Autowired
    private IMinioFileService minioFileService;

    /**
     * 查询minio文件存储列表
     */
    // @PreAuthorize("@ss.hasPermi('system:file:list')")
    @GetMapping("/list")
    public TableDataInfo list(MinioFile minioFile)
    {
        startPage();
        List<MinioFile> list = minioFileService.selectMinioFileList(minioFile);
        return getDataTable(list);
    }

    /**
     * 导出minio文件存储列表
     */
    // @PreAuthorize("@ss.hasPermi('system:file:export')")
    @Log(title = "minio文件存储", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MinioFile minioFile)
    {
        List<MinioFile> list = minioFileService.selectMinioFileList(minioFile);
        ExcelUtil<MinioFile> util = new ExcelUtil<MinioFile>(MinioFile.class);
        util.exportExcel(response, list, "minio文件存储数据");
    }

    /**
     * 获取minio文件存储详细信息
     */
    // @PreAuthorize("@ss.hasPermi('system:file:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(minioFileService.selectMinioFileById(id));
    }

    /**
     * 新增minio文件存储
     */
    // @PreAuthorize("@ss.hasPermi('system:file:add')")
    @Log(title = "minio文件存储", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MinioFile minioFile)
    {
        return toAjax(minioFileService.insertMinioFile(minioFile));
    }

    /**
     * 修改minio文件存储
     */
    // @PreAuthorize("@ss.hasPermi('system:file:edit')")
    @Log(title = "minio文件存储", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MinioFile minioFile)
    {
        return toAjax(minioFileService.updateMinioFile(minioFile));
    }

    /**
     * 删除minio文件存储
     */
    // @PreAuthorize("@ss.hasPermi('system:file:remove')")
    @Log(title = "minio文件存储", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(minioFileService.deleteMinioFileByIds(ids));
    }
}
