Browse Source

上传,下载

lyhzzz 2 years ago
parent
commit
c197c6cd29

+ 0 - 5
pom.xml

@@ -73,11 +73,6 @@
             <version>3.0.0-SNAPSHOT</version>
         </dependency>
 
-        <dependency>
-            <groupId>com.fdkankan</groupId>
-            <artifactId>4dkankan-utils-model</artifactId>
-            <version>3.0.0-SNAPSHOT</version>
-        </dependency>
 
         <dependency>
             <groupId>com.fdkankan</groupId>

+ 15 - 1
src/main/java/com/fdkankan/ucenter/UserCenterApplication.java

@@ -1,6 +1,10 @@
 package com.fdkankan.ucenter;
 
+import com.fdkankan.ucenter.common.constants.NacosProperty;
+import com.fdkankan.ucenter.common.constants.ShellCmd;
 import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.CommandLineRunner;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@@ -14,10 +18,20 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
 @EnableScheduling
 @ComponentScan(basePackages = {"com.fdkankan.*"})
 @MapperScan("com.fdkankan.**.mapper")
-public class UserCenterApplication {
+public class UserCenterApplication implements CommandLineRunner {
+
+    @Value("${fyun.bucket}")
+    private String bucket;
+    @Value("${fyun.type}")
+    private String uploadType;
 
     public static void main(String[] args) {
         SpringApplication.run(UserCenterApplication.class, args);
     }
 
+    @Override
+    public void run(String... args) throws Exception {
+        NacosProperty.bucket = bucket;
+        NacosProperty.uploadType = uploadType;
+    }
 }

+ 33 - 0
src/main/java/com/fdkankan/ucenter/common/constants/ConstantFilePath.java

@@ -0,0 +1,33 @@
+package com.fdkankan.ucenter.common.constants;
+
+public class ConstantFilePath {
+    public static final String BASE_PATH = "/mnt/4Dkankan";
+    // 用户上传图片
+    public static final String USER_IMAGES_PATH = "/mnt/4Dkankan/user/";
+    // 场景
+    public static final String SCENE_PATH = "/mnt/4Dkankan/scene/";
+    // 场景
+    public static final String SCENE_V4_PATH = "/mnt/4Dkankan/scene_v4/";
+    //生成模型的路径
+    public static final String BUILD_MODEL_PATH = "/mnt/data/";
+    //生成模型的路径
+    public static String BUILD_MODEL_LASER_PATH ="/mnt/data/";
+
+    public static final String OSS_PREFIX = "home/";
+
+    /**
+     * 场景数据文件路径
+     */
+    public static final String DATABUFFER_FORMAT = SCENE_PATH + "data/data%s/";
+
+    public static final String DATA_PATH_FORMAT = "data/data%s/";
+
+    public static final String SCENE_IMAGES_PATH_V4 = SCENE_V4_PATH + "%s/images/";
+
+    public static final String SCENE_VIDEOS_PATH_V4 = SCENE_V4_PATH + "%s/videos/";
+
+    public static final String SCENE_VOICES_PATH_V4 = SCENE_V4_PATH + "%s/voices/";
+
+    public static final String SCENE_USER_PATH_V4 = SCENE_V4_PATH + "%s/user/";
+
+}

+ 7 - 0
src/main/java/com/fdkankan/ucenter/common/constants/NacosProperty.java

@@ -0,0 +1,7 @@
+package com.fdkankan.ucenter.common.constants;
+
+public class NacosProperty {
+
+    public static String bucket;
+    public static String uploadType;
+}

+ 15 - 0
src/main/java/com/fdkankan/ucenter/common/constants/ShellCmd.java

@@ -0,0 +1,15 @@
+package com.fdkankan.ucenter.common.constants;
+
+public class ShellCmd {
+
+	/**
+	 * oss文件上传命令 bash /opt/ossutil/fyun-upload.sh {bucket} {srcPath} {destPath} {fyunType} {opType}
+	 * opType: file or folder
+	 * fyunType : oss ,aws
+	 */
+	public static final String FYUN_UPLOAD = "sudo bash /opt/ossutil/fyun-upload.sh %s %s /%s %s %s";
+	public static final String FYUN_DOWN = "sudo bash /opt/ossutil/fyun-download.sh %s %s /%s %s %s";
+
+
+
+}

+ 21 - 0
src/main/java/com/fdkankan/ucenter/common/constants/UploadFilePath.java

@@ -0,0 +1,21 @@
+package com.fdkankan.ucenter.common.constants;
+
+public class UploadFilePath {
+
+    /**
+     * oss.场景码目录
+     */
+    public static final String EDIT_PATH =  "scene_edit_data/%s/";
+    public static final String VIEW_PATH =  "scene_view_data/%s/";
+    /**
+     * 场景数据
+     */
+    public static final String DATA_EDIT_PATH =  "scene_edit_data/%s/data/";
+    public static final String DATA_VIEW_PATH =  "scene_view_data/%s/data/";
+
+
+    public static final String DOWNLOADS_QRCODE = "downloads/scene/%s/QRcode/";
+
+
+
+}

+ 131 - 0
src/main/java/com/fdkankan/ucenter/common/utils/ShellUtil.java

@@ -0,0 +1,131 @@
+package com.fdkankan.ucenter.common.utils;
+
+import cn.hutool.core.io.file.FileReader;
+import com.alibaba.fastjson.JSONObject;
+import com.fdkankan.ucenter.common.constants.NacosProperty;
+import com.fdkankan.ucenter.common.constants.ShellCmd;
+import lombok.extern.slf4j.Slf4j;
+
+import java.io.BufferedReader;
+import java.io.Closeable;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+@Slf4j
+public class ShellUtil {
+
+    /**
+     * 执行系统命令, 返回执行结果
+     * @param cmd 需要执行的命令
+     */
+    public static void execCmd(String cmd) {
+        StringBuilder result = new StringBuilder();
+
+        Process process = null;
+        BufferedReader bufrIn = null;
+        BufferedReader bufrError = null;
+        long startTime = System.currentTimeMillis();
+
+        try {
+            // 执行命令, 返回一个子进程对象(命令在子进程中执行)
+            log.info("执行cmd:{}",cmd);
+            process = Runtime.getRuntime().exec(cmd);
+            // 获取命令执行结果, 有两个结果: 正常的输出 和 错误的输出(PS: 子进程的输出就是主进程的输入)
+            //处理InputStream的线程
+            threadRun(process);
+            // 方法阻塞, 等待命令执行完成(成功会返回0)
+            process.waitFor();
+        }catch (Exception e){
+            e.printStackTrace();
+        }finally {
+            closeStream(bufrIn);
+            closeStream(bufrError);
+            // 销毁子进程
+            if (process != null) {
+                process.destroy();
+            }
+        }
+        // 返回执行结果
+        log.info("执行cmd:{},结果:{},耗时:{}", cmd,result.toString(),System.currentTimeMillis() -startTime);
+    }
+
+    private static void threadRun(Process process) {
+        new Thread() {
+            @Override
+            public void run() {
+                BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
+                String line = null;
+                try {
+                    while((line = in.readLine()) != null) {
+                       log.debug("output: " + line);
+                    }
+                }
+                catch (IOException e) {
+                    e.printStackTrace();
+                }
+                finally {
+                    try {
+                        in.close();
+                    }
+                    catch (IOException e) {
+                        e.printStackTrace();
+                    }
+                }
+            }
+        }.start();
+        new Thread() {
+            @Override
+            public void run() {
+                BufferedReader err = new BufferedReader(new InputStreamReader(process.getErrorStream()));
+                String line = null;
+                try {
+                    while((line = err.readLine()) != null) {
+                        log.debug("err: " + line);
+                    }
+                }
+                catch (IOException e) {
+                    e.printStackTrace();
+                }
+                finally {
+                    try {
+                        err.close();
+                    }
+                    catch (IOException e) {
+                        e.printStackTrace();
+                    }
+                }
+            }
+        }.start();
+    }
+
+    private static void closeStream(Closeable stream) {
+        if (stream != null) {
+            try {
+                stream.close();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
+
+    /**
+     * oss文件上传命令 bash /opt/ossutil/fyun-upload.sh {bucket} {srcPath} {destPath} {fyunType} {opType}
+     * opType: file or folder
+     *  //@param bucket     桶名
+     * @param srcPath    源文件路径
+     * @param destPath   目标文件路径
+     *  //@param fyunType   oss or aws
+     */
+    public static void yunUpload(String srcPath,String destPath){
+        String opType = srcPath.contains(".")? "file":"folder" ;
+        String cmd = String.format(ShellCmd.FYUN_UPLOAD, NacosProperty.bucket,srcPath,destPath,NacosProperty.uploadType,opType);
+        execCmd(cmd);
+    }
+    public static void yunDownload(String srcPath,String destPath){
+        String opType = srcPath.contains(".")? "file":"folder" ;
+        String cmd = String.format(ShellCmd.FYUN_DOWN,NacosProperty.bucket,srcPath,destPath,NacosProperty.uploadType,opType);
+        execCmd(cmd);
+    }
+
+}

+ 1 - 1
src/main/java/com/fdkankan/ucenter/pay/factory/impl/PayOrderService.java

@@ -6,7 +6,7 @@ import com.alipay.api.AlipayClient;
 import com.alipay.api.DefaultAlipayClient;
 import com.alipay.api.domain.AlipayTradeWapPayModel;
 import com.alipay.api.request.AlipayTradeWapPayRequest;
-import com.fdkankan.model.constants.ConstantFilePath;
+import com.fdkankan.ucenter.common.constants.ConstantFilePath;
 import com.fdkankan.common.constant.ErrorCode;
 import com.fdkankan.common.exception.BusinessException;
 import com.fdkankan.common.util.MD5;

+ 1 - 1
src/main/java/com/fdkankan/ucenter/service/impl/AppSceneService.java

@@ -1,7 +1,7 @@
 package com.fdkankan.ucenter.service.impl;
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.fdkankan.model.constants.ConstantFilePath;
+import com.fdkankan.ucenter.common.constants.ConstantFilePath;
 import com.fdkankan.common.constant.SceneConstant;
 import com.fdkankan.common.exception.BusinessException;
 import com.fdkankan.ucenter.common.PageInfo;

+ 1 - 1
src/main/java/com/fdkankan/ucenter/service/impl/LoginService.java

@@ -9,7 +9,7 @@ import com.fdkankan.common.util.JwtUtil;
 import com.fdkankan.common.util.NumberUtils;
 import com.fdkankan.common.util.SecurityUtil;
 import com.fdkankan.image.MatrixToImageWriterUtil;
-import com.fdkankan.model.constants.ConstantFilePath;
+import com.fdkankan.ucenter.common.constants.ConstantFilePath;
 import com.fdkankan.redis.constant.RedisKey;
 import com.fdkankan.redis.util.RedisUtil;
 import com.fdkankan.sms.SendMailAcceUtils;

+ 1 - 1
src/main/java/com/fdkankan/ucenter/service/impl/SceneEditInfoServiceImpl.java

@@ -9,7 +9,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.fdkankan.common.constant.ErrorCode;
 import com.fdkankan.common.exception.BusinessException;
 import com.fdkankan.common.util.FileUtils;
-import com.fdkankan.model.constants.ConstantFilePath;
+import com.fdkankan.ucenter.common.constants.ConstantFilePath;
 import com.fdkankan.redis.constant.RedisKey;
 import com.fdkankan.redis.constant.RedisLockKey;
 import com.fdkankan.redis.util.RedisLockUtil;

+ 2 - 2
src/main/java/com/fdkankan/ucenter/service/impl/ScenePlusServiceImpl.java

@@ -9,8 +9,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fdkankan.common.util.FileUtils;
 import com.fdkankan.fyun.face.FYunFileServiceInterface;
 import com.fdkankan.image.MatrixToImageWriterUtil;
-import com.fdkankan.model.constants.ConstantFilePath;
-import com.fdkankan.model.constants.UploadFilePath;
+import com.fdkankan.ucenter.common.constants.ConstantFilePath;
+import com.fdkankan.ucenter.common.constants.UploadFilePath;
 import com.fdkankan.redis.constant.RedisKey;
 import com.fdkankan.redis.util.RedisUtil;
 import com.fdkankan.ucenter.bean.SceneJsonBean;

+ 30 - 19
src/main/java/com/fdkankan/ucenter/service/impl/SceneProServiceImpl.java

@@ -15,11 +15,11 @@ import com.fdkankan.redis.constant.RedisKey;
 import com.fdkankan.ucenter.common.PageInfo;
 import com.fdkankan.fyun.face.FYunFileServiceInterface;
 import com.fdkankan.image.MatrixToImageWriterUtil;
-import com.fdkankan.model.constants.ConstantFilePath;
-import com.fdkankan.model.constants.UploadFilePath;
-import com.fdkankan.model.utils.CreateObjUtil;
+import com.fdkankan.ucenter.common.constants.ConstantFilePath;
+import com.fdkankan.ucenter.common.constants.UploadFilePath;
 import com.fdkankan.redis.util.RedisUtil;
 import com.fdkankan.ucenter.common.RedisKeyUtil;
+import com.fdkankan.ucenter.common.utils.ShellUtil;
 import com.fdkankan.ucenter.constant.CameraConstant;
 import com.fdkankan.ucenter.constant.LoginConstant;
 import com.fdkankan.ucenter.entity.*;
@@ -341,10 +341,6 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
                     vo.setCreateTimeStr(vo.getCreateTime());
                 }
             }
-            List<SceneVo> records = sceneVoPage.getRecords();
-            List<SceneVo> sceneList = records.parallelStream().filter(entity -> entity.getIsFolder() == 0).collect(Collectors.toList());
-            folderList.addAll(sceneList);
-            sceneVoPage.setRecords(folderList);
         }
         //设置协作者信息
         if(sceneVoPage.getRecords().size() >0){
@@ -360,6 +356,21 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
                 }
             }
         }
+        if(param.getSceneSource().equals("1")){         //增加双目文件夹
+            SceneVo sceneVo = new SceneVo();
+            sceneVo.setId(-1L);
+            sceneVo.setIsFolder(1);
+            sceneVo.setName("双目文件夹");
+            sceneVo.setType("0");
+            Integer count = sceneService.getCountByUserId(user.getId());
+            sceneVo.setSceneNum(Long.valueOf(count));
+            folderList.add(sceneVo);
+        }
+        List<SceneVo> sceneList = sceneVoPage.getRecords().parallelStream().filter(entity -> entity.getIsFolder() == 0).collect(Collectors.toList());
+        if(sceneList.size() >0){
+            folderList.addAll(sceneList);
+        }
+        sceneVoPage.setRecords(folderList);
         JSONObject jsonObject = new JSONObject();
         jsonObject.put("pageInfo",PageInfo.PageInfo(sceneVoPage));
         jsonObject.put("sceneNum",sceneVoPage.getTotal() - folderNum);
@@ -560,10 +571,10 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
      * @throws Exception
      */
     private void downloadFromOldNumFromOss(String sceneNum, String newNum) throws Exception {
-        CreateObjUtil.ossUtilCp("images/images" + sceneNum + "/", ConstantFilePath.SCENE_PATH + "images/images" + newNum);
-        CreateObjUtil.ossUtilCp("data/data" + sceneNum + "/", ConstantFilePath.SCENE_PATH + "data/data" + newNum);
-        CreateObjUtil.ossUtilCp("voice/voice" + sceneNum + "/", ConstantFilePath.SCENE_PATH + "voice/voice" + newNum);
-        CreateObjUtil.ossUtilCp("video/video" + sceneNum + "/", ConstantFilePath.SCENE_PATH + "video/video" + newNum);
+        ShellUtil.yunDownload("images/images" + sceneNum + "/", ConstantFilePath.SCENE_PATH + "images/images" + newNum);
+        ShellUtil.yunDownload("data/data" + sceneNum + "/", ConstantFilePath.SCENE_PATH + "data/data" + newNum);
+        ShellUtil.yunDownload("voice/voice" + sceneNum + "/", ConstantFilePath.SCENE_PATH + "voice/voice" + newNum);
+        ShellUtil.yunDownload("video/video" + sceneNum + "/", ConstantFilePath.SCENE_PATH + "video/video" + newNum);
     }
 
     /**
@@ -581,7 +592,7 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
 
     public void copyFdage(String oldDataSource,String newDataSource,String buildModelPath,String time) throws Exception {
 
-        CreateObjUtil.ossUtilCp(ConstantFilePath.OSS_PREFIX + oldDataSource.replace(buildModelPath, "")+"/", newDataSource);
+        ShellUtil.yunDownload(ConstantFilePath.OSS_PREFIX + oldDataSource.replace(buildModelPath, "")+"/", newDataSource);
         // 修改data.fdage
         String data = FileUtils.readFile(newDataSource + "/data.fdage");
         JSONObject jsonObject = JSONObject.parseObject(data);
@@ -591,12 +602,12 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
         }
         jsonObject.put("uuidtime",time);
         FileUtils.writeFile(newDataSource + "/data.fdage", jsonObject.toJSONString());
-        CreateObjUtil.ossUtilCpFolder(newDataSource, bucket.concat("/" + ConstantFilePath.OSS_PREFIX + newDataSource.replace(buildModelPath, "")));
+        ShellUtil.yunUpload(newDataSource, bucket.concat("/" + ConstantFilePath.OSS_PREFIX + newDataSource.replace(buildModelPath, "")));
 
         // 复制计算结果
-        CreateObjUtil.ossUtilCp(ConstantFilePath.OSS_PREFIX + oldDataSource.concat("_results/").replace(buildModelPath, ""), newDataSource.concat("_results"));
+        ShellUtil.yunDownload(ConstantFilePath.OSS_PREFIX + oldDataSource.concat("_results/").replace(buildModelPath, ""), newDataSource.concat("_results"));
         if(new File(newDataSource.concat("_results")).exists()){
-            CreateObjUtil.ossUtilCpFolder(newDataSource.concat("_results"),bucket.concat("/" + ConstantFilePath.OSS_PREFIX + newDataSource.concat("_results").replace(buildModelPath, "")));
+            ShellUtil.yunUpload(newDataSource.concat("_results"),bucket.concat("/" + ConstantFilePath.OSS_PREFIX + newDataSource.concat("_results").replace(buildModelPath, "")));
             FileUtils.delAllFile(newDataSource.concat("_results"));
         }
         FileUtils.delAllFile(newDataSource);
@@ -644,10 +655,10 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
      * @param newNum
      */
     private void uploadNewSceneToOss(String newNum) {
-        CreateObjUtil.ossUtilCpFolder("/mnt/4Dkankan/scene/images/images" + newNum, bucket.concat("/images/images") + newNum);
-        CreateObjUtil.ossUtilCpFolder("/mnt/4Dkankan/scene/data/data" + newNum, bucket.concat("/data/data") + newNum);
-        CreateObjUtil.ossUtilCpFolder("/mnt/4Dkankan/scene/voice/voice" + newNum, bucket.concat("/voice/voice") + newNum);
-        CreateObjUtil.ossUtilCpFolder("/mnt/4Dkankan/scene/video/video" + newNum, bucket.concat("/video/video") + newNum);
+        ShellUtil.yunUpload("/mnt/4Dkankan/scene/images/images" + newNum, bucket.concat("/images/images") + newNum);
+        ShellUtil.yunUpload("/mnt/4Dkankan/scene/data/data" + newNum, bucket.concat("/data/data") + newNum);
+        ShellUtil.yunUpload("/mnt/4Dkankan/scene/voice/voice" + newNum, bucket.concat("/voice/voice") + newNum);
+        ShellUtil.yunUpload("/mnt/4Dkankan/scene/video/video" + newNum, bucket.concat("/video/video") + newNum);
     }
 
     @Override

+ 1 - 1
src/main/java/com/fdkankan/ucenter/service/impl/UserServiceImpl.java

@@ -10,7 +10,7 @@ import com.fdkankan.common.constant.ConstantUrl;
 import com.fdkankan.common.exception.BusinessException;
 import com.fdkankan.common.util.*;
 import com.fdkankan.fyun.face.FYunFileServiceInterface;
-import com.fdkankan.model.constants.ConstantFilePath;
+import com.fdkankan.ucenter.common.constants.ConstantFilePath;
 import com.fdkankan.redis.constant.RedisKey;
 import com.fdkankan.redis.util.RedisUtil;
 import com.fdkankan.sensitive.Variable;