package com.sz.admin.monitor.controller;


import cn.dev33.satoken.annotation.SaIgnore;
import com.sz.admin.monitor.pojo.dto.file.FileEntityDTO;
import com.sz.admin.monitor.pojo.dto.file.FileStorageDTO;
import com.sz.admin.monitor.pojo.que.file.FileStorageQue;
import com.sz.admin.monitor.service.impl.FileServiceImpl;
import com.sz.core.common.entity.ApiResult;
import com.sz.core.common.entity.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author xq
 * @description:
 * @date 2026/2/2 22:31
 */
@RestController
@RequestMapping("/fileStorage")
public class FileController {

    @Autowired
    private FileServiceImpl fileService;

    @GetMapping("/deleteFileById")
    public ApiResult<String> deleteFileById(@RequestParam("id") String id){
        return fileService.deleteFileById(id);
    }

    @PostMapping("/editFileNameById")
    public ApiResult<String> editFileNameById(@RequestBody FileEntityDTO dto){
        return fileService.editFileNameById(dto);
    }

    @PostMapping("/file/list")
    public ApiResult<PageResult<FileEntityDTO>> getFileObjectList(@RequestBody FileStorageQue que){
        return fileService.getFileObjectList(que);
    }

    @GetMapping("/getPreviewFile/{id}")
    @SaIgnore
    public ResponseEntity<byte[]> getPreviewFile(@PathVariable String id){
        return fileService.getPreviewFile(id);
    }

    @GetMapping("/getFile")
    public ApiResult<FileStorageDTO> getFile(@RequestParam("id") String id) {
        return fileService.getFile(id);
    }

    @PostMapping("/saveFile")
    public ApiResult<FileStorageDTO> saveFile(@RequestParam("file") MultipartFile file) {
        return fileService.saveFile(file);
    }

    @GetMapping("/test")
    public void test01(){
        fileService.test01();
    }


}
