|
@@ -3,14 +3,20 @@ package com.fdkankan.scene.service.impl;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
import cn.hutool.core.util.RuntimeUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fdkankan.common.constant.ErrorCode;
|
|
|
+import com.fdkankan.common.constant.SceneStatus;
|
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
|
import com.fdkankan.common.util.FileUtils;
|
|
|
import com.fdkankan.fyun.face.FYunFileServiceInterface;
|
|
|
import com.fdkankan.model.constants.ConstantFilePath;
|
|
|
import com.fdkankan.model.utils.CreateObjUtil;
|
|
|
+import com.fdkankan.redis.constant.RedisKey;
|
|
|
+import com.fdkankan.redis.constant.RedisLockKey;
|
|
|
+import com.fdkankan.redis.util.RedisLockUtil;
|
|
|
+import com.fdkankan.redis.util.RedisUtil;
|
|
|
import com.fdkankan.scene.entity.Scene3dNumMatterPro;
|
|
|
import com.fdkankan.scene.entity.ScenePro;
|
|
|
import com.fdkankan.scene.entity.SceneProEdit;
|
|
@@ -28,6 +34,7 @@ import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.UUID;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.joda.time.DateTime;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -61,6 +68,10 @@ public class InnerApiServiceImpl implements IInnerApiService {
|
|
|
private ISceneProService sceneProService;
|
|
|
@Autowired
|
|
|
private ISceneProEditService sceneProEditService;
|
|
|
+ @Autowired
|
|
|
+ private RedisUtil redisUtil;
|
|
|
+ @Autowired
|
|
|
+ private RedisLockUtil redisLockUtil;
|
|
|
|
|
|
@Override
|
|
|
public ResultData uploadMatterproData(String sceneName, String userName, String floor, MultipartFile file) throws Exception {
|
|
@@ -72,131 +83,158 @@ public class InnerApiServiceImpl implements IInnerApiService {
|
|
|
throw new BusinessException(ErrorCode.FAILURE_CODE_5026);
|
|
|
}
|
|
|
|
|
|
- String sceneNum = "";
|
|
|
- synchronized(this){
|
|
|
- Scene3dNumMatterPro numEntity = scene3dNumMatterProService.findSceneNum();
|
|
|
- sceneNum = numEntity.getCode();
|
|
|
- numEntity.setUsed(1);
|
|
|
- scene3dNumMatterProService.updateById(numEntity);
|
|
|
+ boolean lock = redisLockUtil.lock(RedisLockKey.LOCK_GET_MATTERPRO_NUM, RedisKey.EXPIRE_TIME_1_MINUTE);
|
|
|
+ if(!lock){
|
|
|
+ throw new BusinessException(ErrorCode.SYSTEM_BUSY);
|
|
|
}
|
|
|
+ Scene3dNumMatterPro numEntity = scene3dNumMatterProService.findSceneNum();
|
|
|
+ String sceneNum = numEntity.getCode();
|
|
|
+ numEntity.setUsed(1);
|
|
|
+ scene3dNumMatterProService.updateById(numEntity);
|
|
|
+ redisLockUtil.unlockLua(RedisLockKey.LOCK_GET_MATTERPRO_NUM);
|
|
|
|
|
|
String dataSource = ConstantFilePath.BUILD_MODEL_PATH + UUID.randomUUID() + File.separator ;
|
|
|
-
|
|
|
- File data = new File(dataSource + file.getOriginalFilename());
|
|
|
- if(!data.getParentFile().exists()){
|
|
|
- data.getParentFile().mkdirs();
|
|
|
- }
|
|
|
- file.transferTo(data);
|
|
|
-
|
|
|
- if(file.getOriginalFilename().toLowerCase().endsWith(".zip")){
|
|
|
- CreateObjUtil.unZip(dataSource + file.getOriginalFilename(), dataSource);
|
|
|
- }
|
|
|
- if(file.getOriginalFilename().toLowerCase().endsWith(".rar")){
|
|
|
- CreateObjUtil.unRarWithPath(dataSource + file.getOriginalFilename(), dataSource);
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ result.put("num", sceneNum);
|
|
|
+ result.put("dataSource", dataSource);
|
|
|
+ result.put("status", SceneStatus.wait.code());
|
|
|
+ String key = String.format(RedisKey.SCENE_UPLOAD_MATTERPRO_NUM, sceneNum);
|
|
|
+ redisUtil.set(key, result.toJSONString(), RedisKey.CAMERA_EXPIRE_7_TIME);
|
|
|
+
|
|
|
+ CompletableFuture.runAsync(() -> {
|
|
|
+ try {
|
|
|
+ File data = new File(dataSource + file.getOriginalFilename());
|
|
|
+ if(!data.getParentFile().exists()){
|
|
|
+ data.getParentFile().mkdirs();
|
|
|
+ }
|
|
|
+ file.transferTo(data);
|
|
|
+
|
|
|
+ if(file.getOriginalFilename().toLowerCase().endsWith(".zip")){
|
|
|
+ CreateObjUtil.unZip(dataSource + file.getOriginalFilename(), dataSource);
|
|
|
+ }
|
|
|
+ if(file.getOriginalFilename().toLowerCase().endsWith(".rar")){
|
|
|
+ CreateObjUtil.unRarWithPath(dataSource + file.getOriginalFilename(), dataSource);
|
|
|
// log.info("解压rar开始");
|
|
|
// String command = "unrar x " + dataSource + file.getOriginalFilename() + " " + dataSource;
|
|
|
// RuntimeUtil.exec(command);
|
|
|
// log.info("解压rar完毕:" + command);
|
|
|
- }
|
|
|
-
|
|
|
- Thread.sleep(2000L);
|
|
|
+ }
|
|
|
+
|
|
|
+ Thread.sleep(2000L);
|
|
|
+
|
|
|
+ //删除压缩包
|
|
|
+ new File(dataSource + file.getOriginalFilename()).delete();
|
|
|
+
|
|
|
+ List<String> fileList = new ArrayList<>();
|
|
|
+ FileUtils.readfilePath(dataSource, fileList);
|
|
|
+ String ossPath = "";
|
|
|
+ Map<String, String> uploadMap = new HashMap<>();
|
|
|
+ for (String filePath : fileList) {
|
|
|
+ ossPath = filePath.replace(dataSource, "images/images" + sceneNum + "/");
|
|
|
+ if(ossPath.endsWith("/")){
|
|
|
+ ossPath = ossPath.substring(0, ossPath.lastIndexOf("/"));
|
|
|
+ }
|
|
|
+ uploadMap.put(filePath, ossPath);
|
|
|
+ }
|
|
|
+ fYunFileService.uploadMulFiles(uploadMap);
|
|
|
+
|
|
|
+ ScenePro sceneProEntity = new ScenePro();
|
|
|
+ sceneProEntity.setDataSource(dataSource);
|
|
|
+ sceneProEntity.setNum(sceneNum);
|
|
|
+ sceneProEntity.setSceneDec("<p>四维看看 让空间讲故事</p>");
|
|
|
+ //默认场景名称,若有传场景名称,则以传的为准
|
|
|
+ sceneProEntity.setSceneName("手动上传场景");
|
|
|
+ if(StrUtil.isNotEmpty(sceneName)){
|
|
|
+ sceneProEntity.setSceneName(sceneName);
|
|
|
+ }
|
|
|
+ sceneProEntity.setWebSite(mainUrl + "/" + sceneProV3Url + sceneNum);
|
|
|
+ sceneProEntity.setStatus(-2);
|
|
|
+ sceneProEntity.setPayStatus(1);
|
|
|
+ //默认用户id,若有传用户信息,则以传的为准
|
|
|
+ sceneProEntity.setUserId(2285L);
|
|
|
+ if(StrUtil.isNotEmpty(userName)){
|
|
|
+ User userEntity = userService.findByUserName(userName);
|
|
|
+ if(userEntity != null){
|
|
|
+ sceneProEntity.setUserId(userEntity.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sceneProEntity.setSceneScheme(10);
|
|
|
+ sceneProEntity.setSceneSource(14);
|
|
|
+ sceneProEntity.setBuildType("V3");
|
|
|
+ sceneProService.save(sceneProEntity);
|
|
|
+
|
|
|
+ SceneProEdit sceneProEditEntity = new SceneProEdit();
|
|
|
+ sceneProEditEntity.setProId(sceneProEntity.getId());
|
|
|
+ sceneProEditEntity.setMapVisi(0);
|
|
|
+ sceneProEditEntity.setM2dVisi(1);
|
|
|
+ sceneProEditEntity.setM3dVisi(1);
|
|
|
+ sceneProEditEntity.setPanoVisi(1);
|
|
|
+ sceneProEditEntity.setCadImgVisi(0);
|
|
|
+ sceneProEditService.save(sceneProEditEntity);
|
|
|
+
|
|
|
+ JSONObject scenejson = JSONObject.parseObject(JSONObject.toJSONString(sceneProEntity));
|
|
|
+ scenejson.put("thumbImg", 0);
|
|
|
+ scenejson.put("version", 0);
|
|
|
+ scenejson.put("floorLogo", 0);
|
|
|
+ scenejson.put("sceneKey", "");
|
|
|
+ scenejson.put("public", 0);
|
|
|
+ scenejson.put("visions", 1);
|
|
|
+ scenejson.put("createTime", new DateTime(new Date()).toString("yyyy-MM-dd HH:mm"));
|
|
|
+
|
|
|
+ scenejson.put("floorPublishVer", sceneProEditEntity.getFloorPublishVer());
|
|
|
+ scenejson.put("floorEditVer", sceneProEditEntity.getFloorEditVer());
|
|
|
+ scenejson.put("entry", null);
|
|
|
+
|
|
|
+ scenejson.put("hots", 0);
|
|
|
+
|
|
|
+ FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data/data"+sceneNum+File.separator+"scene.json", scenejson.toString());
|
|
|
+
|
|
|
+ JSONObject floors = new JSONObject();
|
|
|
+ JSONArray floorArr = new JSONArray();
|
|
|
+ JSONObject floorObject = new JSONObject();
|
|
|
+ if(StrUtil.isEmpty(floor)){
|
|
|
+ floorObject = new JSONObject();
|
|
|
+ floorObject.put("id", 0);
|
|
|
+ floorObject.put("subgroup", 0);
|
|
|
+ floorObject.put("name", "1楼");
|
|
|
+ floorObject.put("segment", new JSONArray());
|
|
|
+ floorObject.put("vertex", new JSONArray());
|
|
|
+
|
|
|
+ floorArr.add(floorObject);
|
|
|
+ }else {
|
|
|
+ for(int i = 0; i < Integer.parseInt(floor); i ++){
|
|
|
+ floorObject = new JSONObject();
|
|
|
+ floorObject.put("id", i);
|
|
|
+ floorObject.put("subgroup", i);
|
|
|
+ floorObject.put("name", i+ 1 + "楼");
|
|
|
+ floorObject.put("segment", new JSONArray());
|
|
|
+ floorObject.put("vertex", new JSONArray());
|
|
|
+
|
|
|
+ floorArr.add(floorObject);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ floors.put("floors", floorArr);
|
|
|
+ FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data/data"+sceneNum+File.separator+"floor.json",floors.toJSONString());
|
|
|
+ fYunFileService.uploadFile(ConstantFilePath.SCENE_PATH+"data/data"+sceneNum+File.separator+"floor.json", "data/data"+sceneNum+File.separator+"floor.json");
|
|
|
+ result.put("status", SceneStatus.NO_DISPLAY.code());
|
|
|
+ redisUtil.set(key, result.toJSONString(), RedisKey.CAMERA_EXPIRE_7_TIME);
|
|
|
+ }catch (Exception e){
|
|
|
+ result.put("status", SceneStatus.FAILD.code());
|
|
|
+ redisUtil.set(key, result.toJSONString(), RedisKey.CAMERA_EXPIRE_7_TIME);
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
- //删除压缩包
|
|
|
- new File(dataSource + file.getOriginalFilename()).delete();
|
|
|
+ return ResultData.ok(result);
|
|
|
+ }
|
|
|
|
|
|
-// String dataPath = dataSource + FileUtil.getPrefix(file.getOriginalFilename()) + File.separator;
|
|
|
- List<String> fileList = new ArrayList<>();
|
|
|
- FileUtils.readfilePath(dataSource, fileList);
|
|
|
- String ossPath = "";
|
|
|
- Map<String, String> uploadMap = new HashMap<>();
|
|
|
- for (String filePath : fileList) {
|
|
|
- ossPath = filePath.replace(dataSource, "images/images" + sceneNum + "/");
|
|
|
- if(ossPath.endsWith("/")){
|
|
|
- ossPath = ossPath.substring(0, ossPath.lastIndexOf("/"));
|
|
|
- }
|
|
|
- uploadMap.put(filePath, ossPath);
|
|
|
- }
|
|
|
- fYunFileService.uploadMulFiles(uploadMap);
|
|
|
-
|
|
|
- ScenePro sceneProEntity = new ScenePro();
|
|
|
- sceneProEntity.setDataSource(dataSource);
|
|
|
- sceneProEntity.setNum(sceneNum);
|
|
|
- sceneProEntity.setSceneDec("<p>四维看看 让空间讲故事</p>");
|
|
|
- //默认场景名称,若有传场景名称,则以传的为准
|
|
|
- sceneProEntity.setSceneName("手动上传场景");
|
|
|
- if(StrUtil.isNotEmpty(sceneName)){
|
|
|
- sceneProEntity.setSceneName(sceneName);
|
|
|
- }
|
|
|
- sceneProEntity.setWebSite(mainUrl + "/" + sceneProV3Url + sceneNum);
|
|
|
- sceneProEntity.setStatus(-2);
|
|
|
- sceneProEntity.setPayStatus(1);
|
|
|
- //默认用户id,若有传用户信息,则以传的为准
|
|
|
- sceneProEntity.setUserId(2285L);
|
|
|
- if(StrUtil.isNotEmpty(userName)){
|
|
|
- User userEntity = userService.findByUserName(userName);
|
|
|
- if(userEntity != null){
|
|
|
- sceneProEntity.setUserId(userEntity.getId());
|
|
|
- }
|
|
|
- }
|
|
|
- sceneProEntity.setSceneScheme(10);
|
|
|
- sceneProEntity.setSceneSource(14);
|
|
|
- sceneProEntity.setBuildType("V3");
|
|
|
- sceneProService.save(sceneProEntity);
|
|
|
-
|
|
|
- SceneProEdit sceneProEditEntity = new SceneProEdit();
|
|
|
- sceneProEditEntity.setProId(sceneProEntity.getId());
|
|
|
- sceneProEditEntity.setMapVisi(0);
|
|
|
- sceneProEditEntity.setM2dVisi(1);
|
|
|
- sceneProEditEntity.setM3dVisi(1);
|
|
|
- sceneProEditEntity.setPanoVisi(1);
|
|
|
- sceneProEditEntity.setCadImgVisi(0);
|
|
|
- sceneProEditService.save(sceneProEditEntity);
|
|
|
-
|
|
|
- JSONObject scenejson = JSONObject.parseObject(JSONObject.toJSONString(sceneProEntity));
|
|
|
- scenejson.put("thumbImg", 0);
|
|
|
- scenejson.put("version", 0);
|
|
|
- scenejson.put("floorLogo", 0);
|
|
|
- scenejson.put("sceneKey", "");
|
|
|
- scenejson.put("public", 0);
|
|
|
- scenejson.put("visions", 1);
|
|
|
- scenejson.put("createTime", new DateTime(new Date()).toString("yyyy-MM-dd HH:mm"));
|
|
|
-
|
|
|
- scenejson.put("floorPublishVer", sceneProEditEntity.getFloorPublishVer());
|
|
|
- scenejson.put("floorEditVer", sceneProEditEntity.getFloorEditVer());
|
|
|
- scenejson.put("entry", null);
|
|
|
-
|
|
|
- scenejson.put("hots", 0);
|
|
|
-
|
|
|
- FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data/data"+sceneNum+File.separator+"scene.json", scenejson.toString());
|
|
|
-
|
|
|
- JSONObject floors = new JSONObject();
|
|
|
- JSONArray floorArr = new JSONArray();
|
|
|
- JSONObject floorObject = new JSONObject();
|
|
|
- if(StrUtil.isEmpty(floor)){
|
|
|
- floorObject = new JSONObject();
|
|
|
- floorObject.put("id", 0);
|
|
|
- floorObject.put("subgroup", 0);
|
|
|
- floorObject.put("name", "1楼");
|
|
|
- floorObject.put("segment", new JSONArray());
|
|
|
- floorObject.put("vertex", new JSONArray());
|
|
|
-
|
|
|
- floorArr.add(floorObject);
|
|
|
- }else {
|
|
|
- for(int i = 0; i < Integer.parseInt(floor); i ++){
|
|
|
- floorObject = new JSONObject();
|
|
|
- floorObject.put("id", i);
|
|
|
- floorObject.put("subgroup", i);
|
|
|
- floorObject.put("name", i+ 1 + "楼");
|
|
|
- floorObject.put("segment", new JSONArray());
|
|
|
- floorObject.put("vertex", new JSONArray());
|
|
|
-
|
|
|
- floorArr.add(floorObject);
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public ResultData getUploadMatterproDataStatus(String num) {
|
|
|
+ String key = String.format(RedisKey.SCENE_UPLOAD_MATTERPRO_NUM, num);
|
|
|
+ String jsonStr = redisUtil.get(key);
|
|
|
+ if(StrUtil.isEmpty(jsonStr)){
|
|
|
+ throw new BusinessException(-1, "数据已过期,请前往个人中心查看");
|
|
|
}
|
|
|
- floors.put("floors", floorArr);
|
|
|
- FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data/data"+sceneNum+File.separator+"floor.json",floors.toJSONString());
|
|
|
- fYunFileService.uploadFile(ConstantFilePath.SCENE_PATH+"data/data"+sceneNum+File.separator+"floor.json", "data/data"+sceneNum+File.separator+"floor.json");
|
|
|
- return ResultData.ok(sceneProEntity);
|
|
|
+ return ResultData.ok(JSON.parseObject(jsonStr));
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|