package com.ruoyi.web.service;

import com.ruoyi.system.service.IOssService;
import com.ruoyi.system.service.ISysDictTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

@Service
public class CommonService {
    @Autowired
    public ISysDictTypeService dictTypeService;

    @Autowired
    private IOssService ossService;

    /**
     *
     * @param file
     * @param fileUploadType
     * @return url
     */
    public String uploadFile2OSS2(MultipartFile file, Integer fileUploadType){
        if(null == file){
            try {
                throw new Exception("文件不能为空");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        String filePath= dictTypeService.getDictDataByType("file_upload_type",String.valueOf(fileUploadType));

        return ossService.upload(file, filePath);
    }
}
