package com.djhk.uav.equ.service;


import cn.hutool.core.util.ObjectUtil;
import com.djhk.common.api.RemoteFileService;
import com.djhk.common.api.domain.vo.FileVo;
import com.djhk.common.core.domain.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

/**
 * @description 上传文件封装
 * @author jiachengshuai
 * @date 2022/11/28 15:38:25
 * @version 1.0
 */
@Component
@Slf4j
public class FileUploadService
{
    @Autowired
    private RemoteFileService remoteFileService;


    public FileVo fileUpload(MultipartFile file, String objectPrefix, String bucketName, String bizCode, String relateId, String cacheConstants)
    {
        FileVo fileVo = new FileVo();
        R<FileVo> fileResultR = null;
        try {
            fileResultR = remoteFileService.fileV1(file,objectPrefix,bucketName,bizCode);

            if (fileResultR != null &&  ObjectUtil.isNotNull(fileResultR.getData()))
            {
                fileVo = fileResultR.getData();
            }
        } catch (Exception e) {
            log.error("上传文件失败,文件名称:{}" + file.getOriginalFilename());
            e.printStackTrace();
        }

        return fileVo;
    }


}
