package com.hwrj.cloud.admin.controller;

import com.hwrj.cloud.admin.util.OrderNo;
import com.hwrj.cloud.admin.util.UploadFileUtil;
import com.hwrj.cloud.common.api.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Api(tags = "FileUploadController",description = "图片上传接口")
@RestController
@RequestMapping("/upload")
public class FileUploadController  {

    @Autowired
    private UploadFileUtil uploadFileUtil;

    @ApiOperation("上传接口")
    @PostMapping("/fileImg")
    public CommonResult uploadFile(@RequestParam(value = "file") MultipartFile file,String type){
        type =1+"";
        if ((!"123456".contains(type))||type.length()>1){
            return CommonResult.failed("上传失败");
        }
        String s = uploadFileUtil.uploadQiNiuFiles(file, "0/" + type + "/" + OrderNo.NextOrderNo());
        return CommonResult.success(s);
    }


}
