Преглед изворни кода

添加转目视频相关接口

zhujinghui пре 4 година
родитељ
комит
55026dcd14

+ 423 - 0
4dkankan-common/src/main/java/com/fdkankan/common/jedis/JedisUtil.java

@@ -0,0 +1,423 @@
+package com.fdkankan.common.jedis;
+
+import lombok.extern.log4j.Log4j2;
+import redis.clients.jedis.*;
+
+import java.io.*;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.ReentrantLock;
+
+
+/**
+ * Redis client base on jedis 根据继承类的不同,
+ * jedis实例方式不用:JedisSimpleFactry/JedisPoolFactry/ShardedJedisPoolFactry
+ * <p>
+ * 2015-7-10 18:34:07
+ * <p>
+ * # for redis (sharded.jedis.address=host01:port,host02:port)
+ * sharded.jedis.address=127.0.0.1:6379,127.0.0.1:6379,127.0.0.1:6379
+ */
+@Log4j2
+public class JedisUtil {
+    
+    private static final int DEFAULT_EXPIRE_TIME = 7200; // 默认过期时间,单位/秒, 60*60*2=2H, 两小时
+    private static String address;
+    private static JedisPoolConfig config;
+
+    public static void init(String address, JedisPoolConfig config) {
+        JedisUtil.address = address;
+        JedisUtil.config = config;
+    }
+
+    // ------------------------ ShardedJedisPool ------------------------
+    /**
+     * 方式01: Redis单节点 + Jedis单例 : Redis单节点压力过重, Jedis单例存在并发瓶颈 》》不可用于线上
+     * new Jedis("127.0.0.1", 6379).get("cache_key");
+     * 方式02: Redis单节点 + JedisPool单节点连接池 》》 Redis单节点压力过重,负载和容灾比较差
+     * new JedisPool(new JedisPoolConfig(), "127.0.0.1", 6379, 10000).getResource().get("cache_key");
+     * 方式03: Redis集群(通过client端集群,一致性哈希方式实现) + Jedis多节点连接池 》》Redis集群,负载和容灾较好, ShardedJedisPool一致性哈希分片,读写均匀,动态扩充
+     * new ShardedJedisPool(new JedisPoolConfig(), new LinkedList<JedisShardInfo>());
+     */
+
+    private static ShardedJedisPool shardedJedisPool;
+    private static ReentrantLock INSTANCE_INIT_LOCL = new ReentrantLock(false);
+
+
+    private static final String LOCK_SUCCESS = "OK";
+    private static final String SET_IF_NOT_EXIST = "NX";
+    private static final String SET_WITH_EXPIRE_TIME = "PX";
+    private static final Long RELEASE_SUCCESS = 1L;
+
+    /**
+     * 获取ShardedJedis实例
+     *
+     * @return
+     */
+    private static ShardedJedis getInstance() {
+        if (shardedJedisPool == null) {
+            try {
+                if (INSTANCE_INIT_LOCL.tryLock(2, TimeUnit.SECONDS)) {
+                    try {
+                        if (shardedJedisPool == null) {
+                            // JedisShardInfo List
+                            List<JedisShardInfo> jedisShardInfos = new LinkedList<JedisShardInfo>();
+
+                            String[] addressArr = address.split(",");
+                            for (int i = 0; i < addressArr.length; i++) {
+                                String[] addressInfo = addressArr[i].split(":");
+                                String host = addressInfo[0];
+                                int port = Integer.valueOf(addressInfo[1]);
+                                JedisShardInfo jedisShardInfo = new JedisShardInfo(host, port, 10000);
+                                jedisShardInfos.add(jedisShardInfo);
+                            }
+                            shardedJedisPool = new ShardedJedisPool(config, jedisShardInfos);
+                            log.info(">>>>>>>>>>> xxl-sso, JedisUtil.ShardedJedisPool init success.");
+                        }
+
+                    } finally {
+                        INSTANCE_INIT_LOCL.unlock();
+                    }
+                }
+
+            } catch (InterruptedException e) {
+                log.error("系统异常:", e);
+            }
+        }
+
+        if (shardedJedisPool == null) {
+            throw new NullPointerException(">>>>>>>>>>> xxl-sso, JedisUtil.ShardedJedisPool is null.");
+        }
+
+        ShardedJedis shardedJedis = shardedJedisPool.getResource();
+        return shardedJedis;
+    }
+
+    // ------------------------ serialize and unserialize ------------------------
+
+    /**
+     * 将对象-->byte[] (由于jedis中不支持直接存储object所以转换成byte[]存入)
+     *
+     * @param object
+     * @return
+     */
+    private static byte[] serialize(Object object) {
+        ObjectOutputStream oos = null;
+        ByteArrayOutputStream baos = null;
+        try {
+            // 序列化
+            baos = new ByteArrayOutputStream();
+            oos = new ObjectOutputStream(baos);
+            oos.writeObject(object);
+            byte[] bytes = baos.toByteArray();
+            return bytes;
+        } catch (Exception e) {
+            log.error("{}", e);
+        } finally {
+            try {
+                oos.close();
+                baos.close();
+            } catch (IOException e) {
+                log.error("{}", e);
+            }
+        }
+        return null;
+    }
+
+    /**
+     * 将byte[] -->Object
+     *
+     * @param bytes
+     * @return
+     */
+    private static Object unserialize(byte[] bytes) {
+        ByteArrayInputStream bais = null;
+        try {
+            // 反序列化
+            bais = new ByteArrayInputStream(bytes);
+            ObjectInputStream ois = new ObjectInputStream(bais);
+            return ois.readObject();
+        } catch (Exception e) {
+            log.error("{}", e);
+        } finally {
+            try {
+                bais.close();
+            } catch (IOException e) {
+                log.error("{}", e);
+            }
+        }
+        return null;
+    }
+
+    // ------------------------ jedis util ------------------------
+    /**
+     * 存储简单的字符串或者是Object 因为jedis没有分装直接存储Object的方法,所以在存储对象需斟酌下
+     * 存储对象的字段是不是非常多而且是不是每个字段都用到,如果是的话那建议直接存储对象,
+     * 否则建议用集合的方式存储,因为redis可以针对集合进行日常的操作很方便而且还可以节省空间
+     */
+
+    /**
+     * Set String
+     *
+     * @param key
+     * @param value
+     * @param seconds 存活时间,单位/秒
+     * @return
+     */
+    public static String setStringValue(String key, String value, int seconds) {
+        String result = null;
+        ShardedJedis client = getInstance();
+        try {
+            result = client.setex(key, seconds, value);
+        } catch (Exception e) {
+            log.info("{}", e);
+        } finally {
+            client.close();
+        }
+        return result;
+    }
+
+    /**
+     * Set String (默认存活时间, 2H)
+     *
+     * @param key
+     * @param value
+     * @return
+     */
+    public static String setStringValue(String key, String value) {
+        return setStringValue(key, value, DEFAULT_EXPIRE_TIME);
+    }
+
+    /**
+     * Set Object
+     *
+     * @param key
+     * @param obj
+     * @param seconds 存活时间,单位/秒
+     */
+    public static String setObjectValue(String key, Object obj, int seconds) {
+        String result = null;
+        ShardedJedis client = getInstance();
+        try {
+            result = client.setex(key.getBytes(), seconds, serialize(obj));
+        } catch (Exception e) {
+            log.info("{}", e);
+        } finally {
+            client.close();
+        }
+        return result;
+    }
+
+    /**
+     * Set Object (默认存活时间, 2H)
+     *
+     * @param key
+     * @param obj
+     * @return
+     */
+    public static String setObjectValue(String key, Object obj) {
+        return setObjectValue(key, obj, DEFAULT_EXPIRE_TIME);
+    }
+
+    /**
+     * Get String
+     *
+     * @param key
+     * @return
+     */
+    public static String getStringValue(String key) {
+        String value = null;
+        ShardedJedis client = getInstance();
+        try {
+            value = client.get(key);
+        } catch (Exception e) {
+            log.info("", e);
+        } finally {
+            client.close();
+        }
+        return value;
+    }
+
+    /**
+     * Get Object
+     *
+     * @param key
+     * @return
+     */
+    public static Object getObjectValue(String key) {
+        Object obj = null;
+        ShardedJedis client = getInstance();
+        try {
+            byte[] bytes = client.get(key.getBytes());
+            if (bytes != null && bytes.length > 0) {
+                obj = unserialize(bytes);
+            }
+        } catch (Exception e) {
+            log.info("", e);
+        } finally {
+            client.close();
+        }
+        return obj;
+    }
+
+    /**
+     * Delete
+     *
+     * @param key
+     * @return Integer reply, specifically:
+     * an integer greater than 0 if one or more keys were removed
+     * 0 if none of the specified key existed
+     */
+    public static Long del(String key) {
+        Long result = null;
+        ShardedJedis client = getInstance();
+        try {
+            result = client.del(key);
+        } catch (Exception e) {
+            log.info("{}", e);
+        } finally {
+            client.close();
+        }
+        return result;
+    }
+
+    /**
+     * incrBy	value值加i
+     *
+     * @param key
+     * @param i
+     * @return new value after incr
+     */
+    public static Long incrBy(String key, int i) {
+        Long result = null;
+        ShardedJedis client = getInstance();
+        try {
+            result = client.incrBy(key, i);
+        } catch (Exception e) {
+            log.info("{}", e);
+        } finally {
+            client.close();
+        }
+        return result;
+    }
+
+    /**
+     * exists
+     *
+     * @param key
+     * @return Boolean reply, true if the key exists, otherwise false
+     */
+    public static boolean exists(String key) {
+        Boolean result = null;
+        ShardedJedis client = getInstance();
+        try {
+            result = client.exists(key);
+        } catch (Exception e) {
+            log.info("{}", e);
+        } finally {
+            client.close();
+        }
+        return result;
+    }
+
+    /**
+     * expire	重置存活时间
+     *
+     * @param key
+     * @param seconds 存活时间,单位/秒
+     * @return Integer reply, specifically:
+     * 1: the timeout was set.
+     * 0: the timeout was not set since the key already has an associated timeout (versions lt 2.1.3), or the key does not exist.
+     */
+    public static long expire(String key, int seconds) {
+        Long result = null;
+        ShardedJedis client = getInstance();
+        try {
+            result = client.expire(key, seconds);
+        } catch (Exception e) {
+            log.info("{}", e);
+        } finally {
+            client.close();
+        }
+        return result;
+    }
+
+    /**
+     * expireAt		设置存活截止时间
+     *
+     * @param key
+     * @param unixTime 存活截止时间戳
+     * @return
+     */
+    public static long expireAt(String key, long unixTime) {
+        Long result = null;
+        ShardedJedis client = getInstance();
+        try {
+            result = client.expireAt(key, unixTime);
+        } catch (Exception e) {
+            log.info("{}", e);
+        } finally {
+            client.close();
+        }
+        return result;
+    }
+
+    /**
+     * 尝试获取分布式锁
+     *
+     * @param lockKey    锁
+     * @param requestId  请求标识
+     * @param expireTime 超期时间
+     * @return 是否获取成功
+     */
+    public static boolean tryLock(String lockKey, String requestId, int expireTime) {
+        String result = getInstance().set(lockKey, requestId, SET_IF_NOT_EXIST, SET_WITH_EXPIRE_TIME, expireTime);
+        if (LOCK_SUCCESS.equals(result)) {
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * 释放分布式锁
+     *
+     * @param lockKey   锁
+     * @param requestId 请求标识
+     * @return 是否释放成功
+     */
+    public static boolean releaseLock(String lockKey, String requestId) {
+        Jedis jedis = (Jedis) getInstance().getShard(lockKey);
+        String script = "if redis.call('get', KEYS[1]) == ARGV[1] then return redis.call('del', KEYS[1]) else return 0 end";
+        Object result = jedis.eval(script, Collections.singletonList(lockKey), Collections.singletonList(requestId));
+        if (RELEASE_SUCCESS.equals(result)) {
+            return true;
+        }
+        return false;
+    }
+
+    public static void main(String[] args) {
+		/*init("127.0.0.1:6379");
+		setObjectValue("key", "666");
+		System.out.println(getObjectValue("key"));*/
+
+
+        String key = "key";
+        String request = UUID.randomUUID().toString();
+        try {
+            boolean lock = tryLock(key, request, 10 * 1000);
+            if (!lock) {
+                System.out.println("locked error");
+                return;
+            }
+            //do something
+        } finally {
+            releaseLock(key, request);
+        }
+
+
+    }
+
+}

+ 62 - 0
4dkankan-common/src/main/java/com/fdkankan/common/jedis/RedisConfig.java

@@ -0,0 +1,62 @@
+package com.fdkankan.common.jedis;
+
+import lombok.extern.log4j.Log4j2;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.cache.annotation.CachingConfigurerSupport;
+import org.springframework.cache.annotation.EnableCaching;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import redis.clients.jedis.JedisPoolConfig;
+
+@Log4j2
+@Configuration
+@EnableCaching
+@ConfigurationProperties
+public class RedisConfig extends CachingConfigurerSupport implements InitializingBean {
+
+    @Override
+    public void afterPropertiesSet() throws Exception {
+        log.warn("redis.address:"+address);
+        JedisUtil.init(address, jedisPoolConfig());
+    }
+
+    @Value("${spring.redis.database}")
+    private int database;
+    @Value("${spring.redis.host}")
+    private String host;
+    @Value("${spring.redis.port}")
+    private int port;
+    @Value("${spring.redis.password}")
+    private String password;
+    @Value("${spring.redis.timeout}")
+    private String timeout;
+    @Value("${spring.redis.jedis.pool.max-idle}")
+    private int maxIdle;
+    @Value("${spring.redis.jedis.pool.min-idle}")
+    private int minIdle;
+    @Value("${spring.redis.host}:${spring.redis.port}")
+    private String address;
+
+    /**
+     * 连接池配置
+     * @Description:
+     * @return
+     */
+    @Bean
+    public JedisPoolConfig jedisPoolConfig() {
+        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
+        jedisPoolConfig.setMaxIdle(maxIdle);
+        jedisPoolConfig.setMinIdle(minIdle);
+//        jedisPoolConfig.setMaxTotal(maxTotal);			            // 最大连接数, 默认8个
+//        jedisPoolConfig.setMaxWaitMillis(maxWaitMillis);	        // 获取连接时的最大等待毫秒数(如果设置为阻塞时BlockWhenExhausted),如果超时就抛异常, 小于零:阻塞不确定的时间,  默认-1
+        jedisPoolConfig.setTestOnBorrow(true);		                // 在获取连接的时候检查有效性, 默认false
+        jedisPoolConfig.setTestOnReturn(true);                      // 调用returnObject方法时,是否进行有效检查
+        jedisPoolConfig.setTestWhileIdle(true);		                // Idle时进行连接扫描
+        jedisPoolConfig.setTimeBetweenEvictionRunsMillis(30000);	//表示idle object evitor两次扫描之间要sleep的毫秒数
+        jedisPoolConfig.setNumTestsPerEvictionRun(10);			    //表示idle object evitor每次扫描的最多的对象数
+        jedisPoolConfig.setMinEvictableIdleTimeMillis(60000);	    //表示一个对象至少停留在idle状态的最短时间,然后才能被idle object evitor扫描并驱逐;这一项只有在timeBetweenEvictionRunsMillis大于0时才有意义
+        return jedisPoolConfig;
+    }
+}

+ 17 - 0
4dkankan-modeling/src/main/java/com/fdkankan/modeling/message/BuildSceneReceiver.java

@@ -240,6 +240,12 @@ public class BuildSceneReceiver {
                 map.put(path + File.separator + "capture/Up2.xml", "data/data" + projectNum + "/Up2.xml");
 
 
+                if(Integer.parseInt(cameraType) == 13){
+                    //转台相机
+                    map.put(path + File.separator + "capture/Up.txt", "data/data" + projectNum + "/Up.txt");
+                    map.put(path + File.separator + "capture/Up2.txt", "data/data" + projectNum + "/Up2.txt");
+                }
+
                 uploadToOssUtil.uploadMulFiles(map);
                 payStatus = 1;
 
@@ -306,9 +312,20 @@ public class BuildSceneReceiver {
                 if(dataJson.containsKey("videoVersion") && StringUtils.isNotEmpty(dataJson.getString("videoVersion")) && Integer.parseInt(dataJson.getString("videoVersion")) >= 4){
                     videosJson.put("version", 3);
                     videosJson.put("upPath", prefixAli + "data/data" + projectNum + "/Up.xml");
+
+                    if(Integer.parseInt(cameraType) == 13){
+                        //转台相机
+                        videosJson.put("upPath", videosJson.getString("upPath").replace(".xml", ".txt"));
+                    }
+
                 }else {
                     videosJson.put("version", 1);
                     videosJson.put("upPath", prefixAli + "data/data" + projectNum + "/Up2.xml");
+
+                    if(Integer.parseInt(cameraType) == 13){
+                        //转台相机
+                        videosJson.put("upPath", videosJson.getString("upPath").replace(".xml", ".txt"));
+                    }
                 }
 
                 if(Integer.parseInt(cameraType) == 5){

+ 13 - 0
4dkankan-scene/src/main/java/com/fdkankan/scene/util/ComputerUtil.java

@@ -299,6 +299,13 @@ public class ComputerUtil {
             splitType = "SPLIT_V1";
 //            skyboxType = "SKYBOX_V4";  //tiles
             dataDescribe = "double spherical";
+
+            if(Integer.parseInt(cameraType) == 13){
+                //转台相机
+                skyboxType = "SKYBOX_V6";
+                splitType = "SPLIT_V12";
+            }
+
         }else {
             if("sfm".equals(algorithm)){
                 splitType = "SPLIT_V2";
@@ -364,6 +371,12 @@ public class ComputerUtil {
             scene.setSceneScheme(12);
         }
 
+        //转台相机用4k图
+        if(cameraType.longValue() == 13 ){
+            scene.setSceneSource(3);
+            scene.setSceneScheme(10);
+        }
+
         if(pic!=null&&pic.length()>5)
         {
             scene.setThumb(pic);

+ 187 - 163
4dkankan-web/src/main/java/com/fdkankan/web/controller/SceneFileController.java

@@ -4,18 +4,21 @@ import com.alibaba.fastjson.JSONObject;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fdkankan.base.config.FileRouteConfig;
 import com.fdkankan.base.constant.CameraConstant;
-import com.fdkankan.base.constant.LoginConstant;
 import com.fdkankan.base.constant.SceneConstant;
 import com.fdkankan.base.mq.ModelingMsgProducer;
 import com.fdkankan.base.service.impl.FileService;
-import com.fdkankan.base.util.*;
+import com.fdkankan.base.util.RSAEncrypt;
+import com.fdkankan.base.util.SnowflakeIdGenerator;
 import com.fdkankan.common.api.BaseController;
 import com.fdkankan.common.constant.ConstantFilePath;
+import com.fdkankan.common.constant.ConstantUrl;
 import com.fdkankan.common.exception.BaseRuntimeException;
+import com.fdkankan.common.jedis.JedisUtil;
 import com.fdkankan.common.model.Result;
-import com.fdkankan.common.util.*;
+import com.fdkankan.common.util.FileUtils;
+import com.fdkankan.common.util.RubberSheetingUtil;
+import com.fdkankan.common.util.UploadToOssUtil;
 import com.fdkankan.common.vo.response.ResponseSceneFile;
-import com.fdkankan.scene.entity.CameraEntity;
 import com.fdkankan.scene.entity.*;
 import com.fdkankan.scene.service.*;
 import com.fdkankan.scene.util.ComputerUtil;
@@ -23,7 +26,6 @@ import com.fdkankan.scene.util.CreateObjUtil;
 import com.github.pagehelper.util.StringUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
-import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.log4j.Log4j2;
 import org.apache.commons.codec.binary.Base64;
@@ -33,9 +35,7 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
-import org.springframework.web.multipart.MultipartFile;
 
 import java.io.File;
 import java.io.IOException;
@@ -61,6 +61,7 @@ public class SceneFileController extends BaseController {
 
     @Autowired
     private ICameraService cameraService;
+
     @Autowired
     private ObjectMapper mapper;
 
@@ -80,6 +81,9 @@ public class SceneFileController extends BaseController {
     @Autowired
     private RedisTemplate<String, String> redisTemplate;
 
+    @Autowired
+    private RubberSheetingUtil rubberSheetingUtil;
+
 
     @Value("${main.url}")
     private String mainUrl;
@@ -102,8 +106,9 @@ public class SceneFileController extends BaseController {
     @Value("${ecs.type}")
     private String ecsType;
 
-    @Autowired
-    private RubberSheetingUtil rubberSheetingUtil;
+    @Value("${oss.type}")
+    private String type;
+
 
     /**
      * 场景文件上传之前先获取fileId
@@ -546,160 +551,179 @@ public class SceneFileController extends BaseController {
     }
 
 
+    /**
+     * 更新fileid文件的上传状态
+     *
+     * @param params
+     * @return
+     */
+    @PostMapping("turntableUploadSuccess")
+    @ApiOperation("转台相机上传成功,生成场景")
+    @ApiImplicitParam(name = "params", value = "加密参数", dataType = "String")
+    public Result turntableUploadSuccess(String params) throws Exception {
+        log.info("uploadSuccessBuild-params: " + params);
+        if (StringUtils.isEmpty(params)) {
+            throw new BaseRuntimeException("params为空。");
+        }
+        params = params.replaceAll("%2B", "+");
+        Base64 base64 = new Base64();
+        String cipher = params;
+        // 私钥解密过程
+        byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()),
+                base64.decode(cipher));
+        String restr = new String(res, "UTF-8");
+        log.debug("uploadSuccessBuild-params解密结果:" + restr);
+        String[] strArr = restr.split(splice);
+        if (strArr.length != 3) {
+            throw new BaseRuntimeException("缺少必要参数。");
+        }
+        String mac = strArr[0];
+        String fileId = strArr[1];
+        String folderName = JedisUtil.getStringValue(fileId);
+        if(StringUtils.isEmpty(folderName)){
+            SceneProEntity sceneProEntity = sceneProService.getSceneStatusByUnicode("/" + fileId + "/", "A");
+            if(sceneProEntity != null){
+                folderName = sceneProEntity.getDataSource().substring(sceneProEntity.getDataSource().lastIndexOf("/") + 1);
+            }
 
-//    private Result uploadFile(MultipartFile file, String params) throws Exception{
-//
-//
-//        log.info("upload-params: "+params);
-//        if (StringUtils.isEmpty(params)){
-//            throw new BaseRuntimeException("params为空。");
-//        }
-//        params = params.replaceAll("%2B", "+");
-//        Base64 base64 = new Base64();
-//        String cipher = params;
-//        // 私钥解密过程
-//        byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()),
-//                base64.decode(cipher));
-//        String restr = new String(res, "UTF-8");
-//        log.debug("upload-params解密结果:" + restr);
-//        String[] strArr = restr.split(splice);
-//        if (strArr.length != 6) {
-//            throw new BaseRuntimeException("缺少必要参数");
-//        }
-//        String mac = strArr[0];
-//        String fileId = strArr[1];
-//        String picNum = strArr[2];
-//        String md5 = strArr[3];
-//        String chunk = strArr[4];
-//
-//        Result result = null;
-//        if (file.isEmpty()){
-//            throw new BaseRuntimeException("文件为空。");
-//        }
-//        if (StringUtils.isEmpty(fileId)){
-//            throw new BaseRuntimeException("文件Id为空。");
-//        }
-//        if (picNum == null){
-//            throw new BaseRuntimeException("照片数目为空。");
-//        }
-//        if (StringUtils.isEmpty(mac)){
-//            throw new BaseRuntimeException("mac为空。");
-//        }
-//        if (StringUtils.isEmpty(md5)){
-//            throw new BaseRuntimeException("md5为空。");
-//        }
-//        long size = file.getSize();
-//        log.warn("fileId:"+fileId+"---picNum:"+picNum+"---size:"+size+"---md5:"+md5+"---mac:"+mac);
-//        /*int count = sceneFileUploadService.getCountByFileId(fileId);
-//        if (count > 0){
-//            return Result.failure("文件Id重复,请重新获取。");
-//        }*/
-//        chunk = chunk.split(splice)[0];
-//        // 获取文件名
-//        String fileName = file.getOriginalFilename();
-//        log.info("上传的文件名为:" + fileName);
-//        // 获取文件的后缀名
-//        String suffixName = fileName.substring(fileName.lastIndexOf("."));
-//        log.info("上传的后缀名为:" + suffixName);
-//        String folderName = redisTemplate.opsForValue().get(fileId);
-//        if(StringUtils.isEmpty(folderName)){
-//            SceneProEntity sceneProEntity = sceneProService.getSceneStatusByUnicode("/" + fileId + "/", "0");
-//            if(sceneProEntity != null){
-//                folderName = sceneProEntity.getDataSource().substring(sceneProEntity.getDataSource().lastIndexOf("/") + 1);
-//            }
-//        }
-//        // 1. 判断该文件是否已经上传过
-//        // 2. 如果已经上传过,判断MD5值和文件大小是否相等。如果相等,更新数据记录。如果不相等,删除该文件,重新上传。
-//        // 3. 如果未上传过,需要上传。
-//        StringBuffer filePathBuffer = new StringBuffer(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator).append("capture");
-//        StringBuffer sb = new StringBuffer(routeConfig.getHardDisk()).append(filePathBuffer.toString()).append(File.separator).append(fileName);
-//
-//        boolean needUpload = false;
-//        File dbFile = new File(sb.toString());
-//        if (dbFile.exists()){
-//            String fileMD5 = FileMd5Util.getFileMD5(dbFile);
-//            if (md5.equals(fileMD5) && dbFile.length() == size){
-//                log.warn("文件已存在,MD5和文件大小一致。");
-//
-//                SceneFileUploadEntity uploadEntity = sceneFileUploadService.findByFileIdAndChunk(fileId, Integer.valueOf(chunk));
-//                if (uploadEntity != null){
-////                    uploadEntity.setPicNum(Integer.valueOf(picNum));
-//                    uploadEntity.setSize((int) size);
-//                    uploadEntity.setMd5(md5);
-//                    uploadEntity.setFilePath(sb.toString());
-//                    uploadEntity.setFileSourceName(fileName);
-//                    uploadEntity.setUploadStatus(1);
-//                    sceneFileUploadService.update(uploadEntity);
-//                }else{
-//                    SceneFileUploadEntity sceneFileUploadEntity = new SceneFileUploadEntity();
-////                    sceneFileUploadEntity.setPicNum(Integer.valueOf(picNum));
-//                    sceneFileUploadEntity.setSize((int) size);
-//                    sceneFileUploadEntity.setMd5(md5);
-//                    sceneFileUploadEntity.setFilePath(sb.toString());
-//                    sceneFileUploadEntity.setFileSourceName(fileName);
-//                    sceneFileUploadEntity.setUploadStatus(1);
-//                    sceneFileUploadEntity.setFileId(fileId);
-//                    sceneFileUploadEntity.setChunk(Integer.valueOf(chunk));
-//                    sceneFileUploadService.save(sceneFileUploadEntity);
-//                }
-//                result = Result.success();
-//            }else if (!md5.equals(fileMD5)) {
-//                log.warn("文件已上传,上传MD5:"+md5+",服务器MD5:"+fileMD5+"。不一致。上传失败");
-//                FileUtil.delFile(sb.toString());
-//                needUpload = true;
-//            }else if (dbFile.length() != size){
-//                log.warn("文件已上传,文件大小不一致。上传失败");
-//                FileUtil.delFile(sb.toString());
-//                needUpload = true;
-//            }
-//        }else {
-//            log.warn("文件不存在,需要重新上传");
-//            needUpload = true;
-//        }
-//
-//        // 4. 上传成功后,校验MD5和文件大小是否相等
-//        // 5. 如果相等,更新数据记录。如果不相等,返回上传失败结果。
-//        try {
-//            if (needUpload){
-//                String name = fileName.substring(0, fileName.lastIndexOf("."));
-//                String filePath = fileService.saveFile(file, filePathBuffer.toString(), name);
-//                File uploadFile = new File(filePath);
-//                String fileMD5 = FileMd5Util.getFileMD5(uploadFile);
-//
-//                SceneFileUploadEntity sceneFileUploadEntity = new SceneFileUploadEntity();
-////                sceneFileUploadEntity.setPicNum(Integer.valueOf(picNum));
-//                sceneFileUploadEntity.setSize((int) size);
-//                sceneFileUploadEntity.setMd5(md5);
-//                sceneFileUploadEntity.setFilePath(sb.toString());
-//                sceneFileUploadEntity.setFileSourceName(fileName);
-//                sceneFileUploadEntity.setFileId(fileId);
-//                sceneFileUploadEntity.setChunk(Integer.valueOf(chunk));
-//
-//                if (md5.equals(fileMD5) && uploadFile.length() == size){
-//                    log.warn("文件已上传,MD5和文件大小一致。上传成功");
-//
-//                    sceneFileUploadEntity.setUploadStatus(1);
-//                    sceneFileUploadService.save(sceneFileUploadEntity);
-////                    sceneFileBuildService.updateUploadStatus(Long.parseLong(fileId), filePath);
-////                    sceneFileBuildService.unzipSingleFile(sb.toString());
-//
-//                    result = Result.success();
-//                }else if (!md5.equals(fileMD5)) {
-//                    log.warn("文件已上传,上传MD5:"+md5+",服务器MD5:"+fileMD5+"。不一致。上传失败");
-//                    sceneFileUploadEntity.setUploadStatus(-1);
-//                    sceneFileUploadService.save(sceneFileUploadEntity);
-//                    result = Result.failure("上传失败, 请重新上传。");
-//                }else if (uploadFile.length() != size){
-//                    log.warn("文件已上传,文件大小不一致。上传失败");
-//                    sceneFileUploadEntity.setUploadStatus(-1);
-//                    sceneFileUploadService.save(sceneFileUploadEntity);
-//                    result = Result.failure("上传失败, 请重新上传。");
-//                }
-//            }
-//        }catch (IllegalStateException | IOException e) {
-//            result = Result.failure("上传失败, 请重新上传。");
-//        }
-//        return result;
-//    }
+            if(StringUtils.isEmpty(folderName)){
+                SceneFileBuildEntity sceneFileBuildEntity = sceneFileBuildService.findByFileId(fileId);
+                if(sceneFileBuildEntity != null){
+                    folderName = sceneFileBuildEntity.getUnicode();
+                }
+            }
+        }
+        StringBuilder filePathBuffer = new StringBuilder(routeConfig.getHardDisk()).append(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator).append("capture").append(File.separator);
+        StringBuilder prefixBuffer = new StringBuilder(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator);
+
+        File filePath = new File(filePathBuffer.toString());
+        if(!filePath.exists()){
+            filePath.mkdirs();
+        }
+        if("s3".equals(type)){
+            CreateObjUtil.ossFileCp(ConstantFilePath.OSS_PREFIX + prefixBuffer.toString() + "data.fdage", filePathBuffer.toString() + "data.fdage");
+        }else {
+            CreateObjUtil.ossUtilCp(ConstantFilePath.OSS_PREFIX + prefixBuffer.toString() + "data.fdage", filePathBuffer.toString());
+        }
+        turntableBuildScene(filePathBuffer.toString(), fileId, true, prefixBuffer.toString());
+        return Result.success();
+    }
+
+
+    public void turntableBuildScene(String filePath, String fileId, boolean fromOss, String prefix) throws Exception{
+        //获取解压后的资源的data.fdage中的数据
+//            File folderPath = new File(hardDisk + File.separator + childName + File.separator +
+//                    fileId).listFiles()[0];
+        String data = FileUtils.readFile(filePath + "data.fdage");
+        JSONObject jsonObject = JSONObject.parseObject(data);
+
+        //调用createScene方法生成scene数据和加入算法队列
+        if(jsonObject == null) {
+            log.info("data.fdage文件不存在");
+            throw new BaseRuntimeException(CameraConstant.FAILURE_CODE_6009, CameraConstant.FAILURE_MSG_6009);
+        }
 
+        String sceneNum = "";
+
+        String snCode = jsonObject.getJSONObject("cam").getString("uuid");
+        String unicode = jsonObject.getString("creator") + "_" + jsonObject.getString("uuidtime");
+//            sceneProService.updateRecStatus(unicode);
+        //查看场景中的文件目录是否有改文件id,有则重新计算改场景,无则新建场景
+        SceneProEntity proEntity = sceneProService.findByFileId("/" + fileId + "/");
+        int rebuild = 1;
+        if(proEntity != null){
+            sceneNum = proEntity.getNum();
+            if(proEntity.getStatus() == 0){
+                log.info(sceneNum + ":场景处于计算中,不能再计算");
+                return;
+            }
+        }else {
+            synchronized(this){
+                Scene3dNumNewEntity numEntity = numService.findSceneNum(unicode);
+                sceneNum = numEntity.getCode();
+                numEntity.setUsed(1);
+                numEntity.setFolderName(unicode);
+                numService.update(numEntity);
+                rebuild = 0;
+            }
+        }
+
+        if(sceneNum == null){
+            log.error("大场景序号为空:" + sceneNum);
+            throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
+        }
+
+        log.info("查询相机:" + snCode);
+        CameraEntity cameraEntity = cameraService.findByChildName(snCode);
+
+        if(cameraEntity ==  null){
+            log.error("该相机不存在:" + snCode);
+            cameraEntity = cameraService.findBySnCode(snCode);
+            if(cameraEntity == null){
+                throw new BaseRuntimeException(CameraConstant.FAILURE_CODE_6003, CameraConstant.FAILURE_MSG_6003);
+            }
+        }
+
+
+        String userName = null;
+        String userId = jsonObject.getString("uploadUserID");
+        String departmentId = jsonObject.getString("uploadDepartmentID");
+
+        String icon = null;
+        if(jsonObject.containsKey("icon") && StringUtil.isNotEmpty(jsonObject.getString("icon"))){
+            CreateObjUtil.ossUtilCp(ConstantFilePath.OSS_PREFIX + prefix + jsonObject.getString("icon"), filePath);
+            icon = prefixAli + "images/images" + sceneNum + "/" + jsonObject.getString("icon");
+            if("s3".equals(type)){
+                CreateObjUtil.ossFileCp(ConstantFilePath.OSS_PREFIX + prefix + jsonObject.getString("icon"), filePath + jsonObject.getString("icon"));
+                icon = ConstantUrl.PREFIX_AWS + "images/images" + sceneNum + "/" + jsonObject.getString("icon");
+            }
+            uploadToOssUtil.upload(filePath + jsonObject.getString("icon"), "images/images" + sceneNum + "/" + jsonObject.getString("icon"));
+        }
+
+        JSONObject firmwareVersion = new JSONObject();
+        if(jsonObject.containsKey("camSoftwareVersion") && StringUtil.isNotEmpty(jsonObject.getString("camSoftwareVersion"))){
+            firmwareVersion.put("camSoftwareVersion", jsonObject.getString("camSoftwareVersion"));
+        }
+
+        if(jsonObject.containsKey("version") && StringUtil.isNotEmpty(jsonObject.getString("version"))){
+            firmwareVersion.put("version", jsonObject.getString("version"));
+        }
+
+        String sceneUrl = mainUrl + sceneProUrl;
+        String codeUrl = mainIntranetUrl + sceneProUrl;
+        String buildType = "V3";
+        //13表示转台
+        Long cameraType = 13L;
+
+       if(rebuild != 1){
+           //上传log-main.png
+           uploadToOssUtil.upload(ConstantFilePath.LOGO_PATH + "logo-main.png", "images/images" + sceneNum + "/logo-main.png");
+           uploadToOssUtil.upload(ConstantFilePath.LOGO_PATH + "logo-main-en.png", "images/images" + sceneNum + "/logo-main-en.png");
+       }
+
+
+        SceneProEntity scene = null;
+        scene = ComputerUtil.createScenePro(sceneNum, cameraEntity.getId(), cameraEntity.getChildName(), jsonObject.getString("creator"),
+                jsonObject.getString("pwd"), unicode,
+                cameraType, String.valueOf(fileId), prefix, "", icon, "0", userId, userName,
+                jsonObject.getString("location") != null && "1".equals(jsonObject.getString("location")) ? "sfm" : "slam",
+                jsonObject.getJSONArray("points").size(), jsonObject.getString("name"), jsonObject.getString("info"),
+                jsonObject.getInteger("scenetype"), jsonObject.getString("gps"), sceneProService, sceneProEditService, rebuild, producer,
+                jsonObject.getInteger("resolution"), firmwareVersion.toString(), sceneUrl, buildType, ecsType, codeUrl, departmentId);
+
+
+        if(scene != null){
+            JSONObject statusJson = new JSONObject();
+            statusJson.put("status", scene.getStatus());
+            statusJson.put("webSite", scene.getWebSite());
+            statusJson.put("sceneNum", scene.getNum());
+            statusJson.put("thumb", scene.getThumb());
+            statusJson.put("payStatus", scene.getPayStatus());
+            statusJson.put("isDelete", scene.getIsDelete());
+            FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data/data"+sceneNum+File.separator+"status.json", statusJson.toString());
+            uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH+"data/data"+sceneNum+File.separator+"status.json",
+                    "data/data"+sceneNum+File.separator+"status.json");
+        }
+
+    }
 }