package com.ruoyi.wx.web.controller;

import com.ruoyi.framework.recovery.service.ICommonService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/wx/common")
public class WxCommonController {

    @Autowired
    private ICommonService commonService;

    /**
     * 通用下载请求
     *
     * @param fileName 文件名称
     */
    @GetMapping("/download")
    public ResponseEntity<Resource> fileDownload(String fileName) {
        try {
            return commonService.downloadFile(fileName);
        } catch (Exception e) {
            log.error("下载文件失败", e);
        }
        return ResponseEntity.notFound().build();
    }
}
