package com.fs.app.controller;

import com.fs.common.core.domain.R;
import com.fs.common.exception.file.OssException;
import com.fs.common.utils.security.OssUploadSecurityUtils;
import com.fs.course.param.UserCourseComplaintRecordParam;
import com.fs.course.service.IFsUserCourseComplaintTypeService;
import com.fs.course.vo.FsUserCourseComplaintTypeListVO;
import com.fs.qw.param.QwUserComplaintRecordParam;
import com.fs.qw.service.IQwUserComplainRecordService;
import com.fs.system.oss.CloudStorageService;
import com.fs.system.oss.OSSFactory;
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;

import java.util.List;


@Api("公共接口")
@RestController
@RequestMapping(value="/app/common")
public class CommonController {

    @Autowired
    private IQwUserComplainRecordService qwUserComplainRecordService;

    @Autowired
    private IFsUserCourseComplaintTypeService fsUserCourseComplaintTypeService;

    @PostMapping("uploadOSS")
    public R uploadOSS(@RequestParam("file") MultipartFile file) throws Exception
    {

        if (file.isEmpty())
        {
            throw new OssException("上传文件不能为空");
        }
        // 上传文件（后缀白名单，不影响正常图片/文档/音视频上传）
        String suffix = OssUploadSecurityUtils.validateAndGetDotSuffix(file);
        CloudStorageService storage = OSSFactory.build();
        String url = storage.uploadSuffix(file.getBytes(), suffix);
        return R.ok().put("url",url);
    }

}
