lyhzzz 3 лет назад
Родитель
Сommit
6e9ab526ea

+ 2 - 2
4dkankan-center-modeling/src/main/resources/bootstrap.yml

@@ -20,11 +20,11 @@ spring:
             group: DEFAULT_GROUP
             refresh: true
 
-          - data-id: oss-config.yaml
+          - data-id: other-config.yaml
             group: DEFAULT_GROUP
             refresh: true
 
-          - data-id: other-config.yaml
+          - data-id: common-upload-config.yaml
             group: DEFAULT_GROUP
             refresh: true
       discovery:

+ 4 - 3
4dkankan-center-platform/src/main/resources/bootstrap.yml

@@ -24,17 +24,18 @@ spring:
             group: DEFAULT_GROUP
             refresh: true
 
-          - data-id: oss-config.yaml
+          - data-id: other-config.yaml
             group: DEFAULT_GROUP
             refresh: true
 
-          - data-id: other-config.yaml
+          - data-id: sms-config.yaml
             group: DEFAULT_GROUP
             refresh: true
 
-          - data-id: sms-config.yaml
+          - data-id: common-upload-config.yaml
             group: DEFAULT_GROUP
             refresh: true
+
       discovery:
         server-addr: 192.168.0.47:8848
         namespace: 4dkankan-dev

+ 7 - 7
4dkankan-center-scene/src/main/java/com/fdkankan/scene/controller/SceneUploadController.java

@@ -10,8 +10,6 @@ import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.multipart.MultipartFile;
 
-import java.util.List;
-
 @RestController
 @RequestMapping("/api/scene/upload")
 public class SceneUploadController extends BaseController {
@@ -21,17 +19,19 @@ public class SceneUploadController extends BaseController {
 
     /**
      * 上传图片到oss,base64
-     * imgData   图片base64
+     * base64   图片base64
+     * fileName  文件名称
      * files     文件
-     * sceneCode 场景码
+     * num 场景码
      * type     0添加,1替换
      */
     @RequestMapping(value = "/files", method = RequestMethod.POST)
-    public List<String> uploads(@RequestParam(value = "imgData",required = false) String imgData,
+    public String uploads(@RequestParam(value = "base64",required = false) String base64,
+                                     @RequestParam(value = "fileName",required = false) String fileName,
                                      @RequestParam(value = "files",required = false) MultipartFile[] files,
-                                     @RequestParam(value = "sceneCode",required = false) String sceneCode,
+                                     @RequestParam(value = "num",required = false) String num,
                                      @RequestParam(value = "type",required = false,defaultValue = "0") Integer type) throws Exception {
-        return sceneUploadService.uploads(imgData,files,sceneCode,type);
+        return sceneUploadService.uploads(base64,fileName,files,num,type);
     }
 
 }

+ 2 - 4
4dkankan-center-scene/src/main/java/com/fdkankan/scene/service/ISceneUploadService.java

@@ -1,11 +1,9 @@
 package com.fdkankan.scene.service;
 
-import com.fdkankan.scene.entity.SceneUpload;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.fdkankan.scene.entity.SceneUpload;
 import org.springframework.web.multipart.MultipartFile;
 
-import java.util.List;
-
 /**
  * <p>
  *  服务类
@@ -16,5 +14,5 @@ import java.util.List;
  */
 public interface ISceneUploadService extends IService<SceneUpload> {
 
-    List<String> uploads(String imgData, MultipartFile[] files, String sceneCode, Integer type) throws Exception;
+    String uploads(String imgData, String fileName,MultipartFile[] files, String sceneCode, Integer type) throws Exception;
 }

+ 19 - 8
4dkankan-center-scene/src/main/java/com/fdkankan/scene/service/impl/SceneUploadServiceImpl.java

@@ -7,7 +7,7 @@ import com.fdkankan.common.exception.BusinessException;
 import com.fdkankan.common.user.SSOLoginHelper;
 import com.fdkankan.common.util.BASE64DecodedMultipartFile;
 import com.fdkankan.common.util.FileUtil;
-import com.fdkankan.fyun.oss.OssFilePath;
+import com.fdkankan.fyun.oss.UploadFilePath;
 import com.fdkankan.fyun.oss.UploadToOssUtil;
 import com.fdkankan.scene.entity.SceneUpload;
 import com.fdkankan.scene.mapper.ISceneUploadMapper;
@@ -54,7 +54,7 @@ public class SceneUploadServiceImpl extends ServiceImpl<ISceneUploadMapper, Scen
     private SSOLoginHelper ssoLoginHelper;
 
     @Override
-    public List<String> uploads(String imgData,MultipartFile[] files,String sceneCode,Integer type) throws Exception{
+    public String uploads(String imgData,String fileName,MultipartFile[] files,String sceneCode,Integer type) throws Exception{
         List<MultipartFile> multipartFiles = new ArrayList<>();
         if(StringUtils.isNotBlank(imgData)){
             MultipartFile file = BASE64DecodedMultipartFile.base64ToMultipart(imgData);
@@ -63,10 +63,10 @@ public class SceneUploadServiceImpl extends ServiceImpl<ISceneUploadMapper, Scen
         if(files !=null && files.length >0){
             multipartFiles.addAll(Arrays.asList(files));
         }
-        return this.uploadFiles(multipartFiles,sceneCode,type);
+        return this.uploadFiles(fileName,multipartFiles,sceneCode,type);
     }
 
-    public List<String> uploadFiles(List<MultipartFile> files, String sceneCode, Integer type) throws Exception{
+    public String uploadFiles(String sendFileName,List<MultipartFile> files, String sceneCode, Integer type) throws Exception{
         if (StringUtils.isEmpty(sceneCode) || files == null || files.size() <= 0) {
             throw new BusinessException(ErrorCode.MISSING_REQUIRED_PARAMETERS);
         }
@@ -89,21 +89,32 @@ public class SceneUploadServiceImpl extends ServiceImpl<ISceneUploadMapper, Scen
             prefix = fileName.substring(fileName.lastIndexOf("."));
             File newFile = File.createTempFile(UUID.randomUUID().toString() ,prefix);
             file.transferTo(newFile);
-            String ossPath = String.format(OssFilePath.USER_EDIT_PATH ,sceneCode) + fileName;
+            String realFileName = fileName;
+            if(files.size() ==1 && StringUtils.isNotBlank(sendFileName)){
+                realFileName = sendFileName ;
+            }
+            String ossPath = String.format(UploadFilePath.USER_EDIT_PATH ,sceneCode) + realFileName;
             try {
                 uploadToOssUtil.upload2(newFile.getPath(),ossPath);
             }catch (Exception e){
                 log.error(ossPath+"上传文件失败"+e);
                 throw new BusinessException(-1,"上传文件失败");
             }
-            String url =String.format("http://%s.%s/%s", bucket, point.replace("http://",""), ossPath);
-            urlList.add(url);
+            //String url =String.format("http://%s.%s/%s", bucket, point.replace("http://",""), ossPath);
+            urlList.add(realFileName);
 
             FileUtil.delFile(newFile.getPath());
             //添加记录
             this.saveData(sceneCode,ossPath,prefix);
         }
-        return urlList;
+        StringBuilder returnString = new StringBuilder();
+        for (String res : urlList) {
+            if(StringUtils.isNotBlank(returnString)){
+                returnString.append(",");
+            }
+            returnString.append(res);
+        }
+        return returnString.toString();
     }
 
     private void updateFileByPreFix(String sceneCode, String prefix) {

+ 2 - 2
4dkankan-center-scene/src/main/resources/bootstrap.yml

@@ -35,11 +35,11 @@ spring:
             group: DEFAULT_GROUP
             refresh: true
 
-          - data-id: oss-config.yaml
+          - data-id: other-config.yaml
             group: DEFAULT_GROUP
             refresh: true
 
-          - data-id: other-config.yaml
+          - data-id: common-upload-config.yaml
             group: DEFAULT_GROUP
             refresh: true
       discovery: