|
@@ -0,0 +1,60 @@
|
|
|
+package com.fdkankan.jp.xspace.service.impl;
|
|
|
+
|
|
|
+
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.fdkankan.fyun.face.FYunFileServiceInterface;
|
|
|
+import com.fdkankan.jp.xspace.common.ResultCode;
|
|
|
+import com.fdkankan.jp.xspace.common.constant.NasPathConstant;
|
|
|
+import com.fdkankan.jp.xspace.common.constant.OSSPathConstant;
|
|
|
+import com.fdkankan.jp.xspace.common.exception.BusinessException;
|
|
|
+import com.fdkankan.jp.xspace.entity.SceneXspace;
|
|
|
+import com.fdkankan.jp.xspace.entity.User;
|
|
|
+import com.fdkankan.jp.xspace.entity.XspaceUser;
|
|
|
+import com.fdkankan.jp.xspace.service.IFileService;
|
|
|
+import com.fdkankan.jp.xspace.service.ISceneXspaceService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.UUID;
|
|
|
+
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class FileServiceImpl implements IFileService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISceneXspaceService sceneXspaceService;
|
|
|
+ @Resource
|
|
|
+ private FYunFileServiceInterface fYunFileService;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String uploadXspaceSceneFile(MultipartFile file, String num, String fileName, User user) throws IOException {
|
|
|
+ SceneXspace sceneXspace = sceneXspaceService.getByNumAndUserId(num, user.getId());
|
|
|
+ if(Objects.isNull(sceneXspace)){
|
|
|
+ throw new BusinessException(ResultCode.SCENE_NOT_EXIT);
|
|
|
+ }
|
|
|
+
|
|
|
+ String url = null;
|
|
|
+ String localPath = null;
|
|
|
+ try {
|
|
|
+ String ossKey = String.format(OSSPathConstant.XSPACE_SCENE_FORMAT, num, sceneXspace.getSerial()) + fileName;
|
|
|
+ String extName = FileUtil.extName(fileName);
|
|
|
+ localPath = NasPathConstant.temp_path + UUID.randomUUID() + "." + extName;
|
|
|
+ FileUtil.mkParentDirs(localPath);
|
|
|
+ file.transferTo(new File(localPath));
|
|
|
+ url = fYunFileService.uploadFile(localPath, ossKey);
|
|
|
+ }finally {
|
|
|
+ if(StrUtil.isNotEmpty(localPath) && FileUtil.exist(localPath)){
|
|
|
+ FileUtil.del(localPath);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return url;
|
|
|
+ }
|
|
|
+}
|