package com.ruoyi.web.controller.api;


import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.cs.service.ISysFileService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * 文件请求处理
 *
 * @author xiaoniu
 */
@Tag(name = "下载管理")
@RestController
@RequestMapping("/api/download")
public class ApiSysFileController {

    @Resource
    private ISysFileService sysFileService;

    @GetMapping
    @Operation(summary = "文件下载", description = "传入fileUrl")
    public void downloadFile(HttpServletResponse response,
                             @Parameter(description = "文件地址", required = true) @RequestParam String fileUrl) {
        if (StringUtils.isBlank(fileUrl)){
            throw new ServiceException("请传入需要下载的文件地址");
        }
        sysFileService.downloadFile(response, fileUrl);
    }

}