package com.ruoyi.web.controller.open;

import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.file.FileUtils;
import com.ruoyi.file.object.CommonAttachReq;
import com.ruoyi.file.object.CommonUploadReq;
import com.ruoyi.file.object.UploadForwardReq;
import com.ruoyi.file.object.UploadRedirectReq;
import com.ruoyi.file.object.UploadResp;
import com.ruoyi.file.service.FileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.Map;

/**
 * 文件接口
 * 
 * @author ruoyi
 */
@Api(tags = "文件接口")
@RestController
@RequestMapping("/open/ruralCollectiveAssets")
public class RuralCollectiveAssetsFileController
{
    private static final Logger log = LoggerFactory.getLogger(RuralCollectiveAssetsFileController.class);

    @Autowired
    private FileService fileService;

    /**
     * 单附件上传-返回完整文件路径（单个）
     */
    @ApiOperation("单附件上传-返回完整文件路径（单个）")
    @PostMapping("/common/upload")
    public void commonUpload(@Valid CommonUploadReq req, MultipartFile file, HttpServletRequest request, HttpServletResponse response)
    {
        fileService.commonUpload(file, req, request, response);
    }

    /**
     * 单附件上传-返回ID、URL（单个）
     */
    @ApiOperation("单附件上传-返回ID、URL（单个）")
    @PostMapping("/common/attach")
    public void commonAttach(@Valid CommonAttachReq req, MultipartFile file, HttpServletRequest request, HttpServletResponse response)
    {
        fileService.commonAttach(file, req, request, response);
    }
}
