package com.zcxk.rmcp.web.controller;

import com.zcxk.core.common.pojo.AjaxMessage;
import com.zcxk.rmcp.core.entity.FileLog;
import com.zcxk.rmcp.web.service.FileLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

@Controller
@ResponseBody
@RequestMapping("file")
@Api(tags = "文件")
public class FileController {

    @Autowired
    private FileLogService fileLogService;
    @Value("${rmcp.url}")
    private String rmcpUrl;


    @PostMapping
    @ApiOperation(value = "文件上传")
    public AjaxMessage<Map<String,String>> uploadFile(MultipartFile file) {
        String url = fileLogService.uploadFile(file);
        Map<String,String> map = new HashMap<>();
        map.put("url",rmcpUrl+"/file"+url);
        return AjaxMessage.success(map);
    }



}
