package com.ruoyi.web.controller.open;

import com.ruoyi.file.request.CommonAttachReq;
import com.ruoyi.file.request.CommonUploadReq;
import com.ruoyi.file.request.FinanceVoucherUploadReq;
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.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;

/**
 * 文件接口
 * 
 * @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);
    }

    /**
     * 凭证附件上传
     */
    @ApiOperation("凭证附件上传")
    @PostMapping("/finance/voucher/upload")
    public void financeVoucherUpload(@Valid FinanceVoucherUploadReq req, MultipartFile file, HttpServletRequest request, HttpServletResponse response)
    {
        fileService.financeVoucherUpload(file, req, request, response);
    }
}
