|
|
@@ -1,16 +1,27 @@
|
|
|
package com.fdkankan.contro.mq.listener;
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.codec.Base64;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
import cn.hutool.core.util.ZipUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.fdkankan.common.constant.ErrorCode;
|
|
|
+import com.fdkankan.common.exception.BusinessException;
|
|
|
+import com.fdkankan.common.util.CmdUtils;
|
|
|
+import com.fdkankan.contro.bean.SceneJsonBean;
|
|
|
+import com.fdkankan.contro.constant.UploadSceneSourceType;
|
|
|
import com.fdkankan.contro.constant.ZipConstant;
|
|
|
+import com.fdkankan.contro.entity.*;
|
|
|
+import com.fdkankan.contro.service.*;
|
|
|
import com.fdkankan.fyun.face.FYunFileServiceInterface;
|
|
|
import com.fdkankan.model.constants.ConstantFilePath;
|
|
|
import com.fdkankan.model.constants.UploadFilePath;
|
|
|
+import com.fdkankan.web.util.RSAEncrypt;
|
|
|
import com.rabbitmq.client.Channel;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import net.lingala.zip4j.core.ZipFile;
|
|
|
+import org.apache.commons.io.filefilter.NameFileFilter;
|
|
|
import org.springframework.amqp.core.Message;
|
|
|
import org.springframework.amqp.rabbit.annotation.Queue;
|
|
|
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
|
|
@@ -18,8 +29,10 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.io.File;
|
|
|
+import java.io.FileFilter;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
|
|
|
@Slf4j
|
|
|
@Component
|
|
|
@@ -27,6 +40,21 @@ public class UploadSceneListener {
|
|
|
|
|
|
@Autowired
|
|
|
private FYunFileServiceInterface fYunFileService;
|
|
|
+ @Autowired
|
|
|
+ private ISceneFileBuildService sceneFileBuildService;
|
|
|
+ @Autowired
|
|
|
+ private IUserService userService;
|
|
|
+ @Autowired
|
|
|
+ private IScenePlusService scenePlusService;
|
|
|
+ @Autowired
|
|
|
+ private IScenePlusExtService scenePlusExtService;
|
|
|
+ @Autowired
|
|
|
+ private ISceneEditInfoService sceneEditInfoService;
|
|
|
+ @Autowired
|
|
|
+ private ISceneEditInfoExtService sceneEditInfoExtService;
|
|
|
+ @Autowired
|
|
|
+ private ISceneEditControlsService sceneEditControlsService;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* @param channel
|
|
|
@@ -55,32 +83,14 @@ public class UploadSceneListener {
|
|
|
} else {
|
|
|
ZipUtil.unzip(zipPath, zipDir + uuid);
|
|
|
}
|
|
|
-
|
|
|
- //去读data.fdage
|
|
|
- String dataFdagePath = zipDir + uuid + "/data.fdage";
|
|
|
- if(!FileUtil.exist(dataFdagePath)){
|
|
|
- log.warn("---------dataFdagePath:{}", dataFdagePath);
|
|
|
- throw new BusinessException(ErrorCode.FAILURE_CODE_4002.code(), ErrorCode.FAILURE_CODE_4002.formatMessage("data.fdage"));
|
|
|
- }
|
|
|
- JSONObject dataFdageObj = JSONObject.parseObject(FileUtil.readUtf8String(dataFdagePath));
|
|
|
- int camType = dataFdageObj.getJSONObject("cam").getIntValue("type");
|
|
|
- String snCode = dataFdageObj.getJSONObject("cam").getString("uuid");
|
|
|
- String uuidTime = dataFdageObj.getString("uuidtime");
|
|
|
- String uniCode = snCode + "_" + uuidTime;
|
|
|
- String fileId = sceneFileBuildService.getFileId(snCode, uniCode);
|
|
|
- String homePath = "/oss/4dkankan/" + ConstantFilePath.OSS_PREFIX + snCode + "/" + fileId + "/" + uniCode;
|
|
|
- FileUtil.mkdir(homePath);
|
|
|
- String cpCmd = "cp -p -r " + zipDir + uuid + "/* " + homePath;
|
|
|
- CmdUtils.callLineSh(cpCmd);
|
|
|
-
|
|
|
- String params = snCode + "#" + fileId + "#" + uniCode;
|
|
|
- String encode = Base64.encode(RSAEncrypt.encrypt(RSAEncrypt.loadPublicKeyByStr(RSAEncrypt.loadPublicKeyByFile()), params.getBytes(StandardCharsets.UTF_8)));
|
|
|
- if(camType == 9 || camType == 10 || camType == 11){
|
|
|
- sceneFileBuildService.turntableUploadSuccess(encode, user);
|
|
|
- }else{
|
|
|
- sceneFileBuildService.uploadSuccessBuild(encode, user);
|
|
|
+ //资源包类型 orig-原始数据 offline 离线包
|
|
|
+ if(UploadSceneSourceType.ORIG.getCode().equalsIgnoreCase(sourceType)){
|
|
|
+ this.uploadSceneOirg(num, zipDir + uuid);
|
|
|
}
|
|
|
|
|
|
+ if(UploadSceneSourceType.OFFLINE.getCode().equalsIgnoreCase(sourceType)){
|
|
|
+ this.uploadSceneOffline(num, zipDir + uuid);
|
|
|
+ }
|
|
|
|
|
|
}catch (Exception e){
|
|
|
log.error("处理管理后台上传场景报错, content:{}", msg, e);
|
|
|
@@ -90,4 +100,80 @@ public class UploadSceneListener {
|
|
|
log.info("结束处理管理后台上传场景,content:{}", msg);
|
|
|
}
|
|
|
|
|
|
+ private void uploadSceneOirg(String num, String sourcePath) throws Exception {
|
|
|
+ ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
|
|
|
+ NameFileFilter fileFilter = new NameFileFilter("data.fdage");
|
|
|
+ File dataFdageFile = FileUtil.loopFiles(sourcePath, fileFilter).stream().findFirst().filter(v -> !v.getAbsolutePath().contains("/backup/")).get();
|
|
|
+
|
|
|
+ //去读data.fdage
|
|
|
+ if(dataFdageFile != null && !dataFdageFile.exists()){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_4002.code(), ErrorCode.FAILURE_CODE_4002.formatMessage("data.fdage"));
|
|
|
+ }
|
|
|
+ JSONObject dataFdageObj = JSONObject.parseObject(FileUtil.readUtf8String(dataFdageFile));
|
|
|
+ int camType = dataFdageObj.getJSONObject("cam").getIntValue("type");
|
|
|
+ String snCode = dataFdageObj.getJSONObject("cam").getString("uuid");
|
|
|
+ String uuidTime = dataFdageObj.getString("uuidtime");
|
|
|
+ String uniCode = snCode + "_" + uuidTime;
|
|
|
+ String fileId = sceneFileBuildService.getFileId(snCode, uniCode);
|
|
|
+ String homePath = "/oss/4dkankan/" + ConstantFilePath.OSS_PREFIX + snCode + "/" + fileId + "/" + uniCode;
|
|
|
+ FileUtil.mkdir(homePath);
|
|
|
+ String fileDir = sourcePath + "/" + uniCode;//本地版压缩包包含了一层unicode目录
|
|
|
+ String cpCmd = "cp -p -r " + fileDir + "/* " + homePath;
|
|
|
+ CmdUtils.callLineSh(cpCmd);
|
|
|
+
|
|
|
+ Long userId = scenePlus.getUserId();
|
|
|
+ User user = userService.getById(userId);
|
|
|
+ String params = snCode + "#" + fileId + "#" + uniCode;
|
|
|
+ String encode = Base64.encode(RSAEncrypt.encrypt(RSAEncrypt.loadPublicKeyByStr(RSAEncrypt.loadPublicKeyByFile()), params.getBytes(StandardCharsets.UTF_8)));
|
|
|
+ if(camType == 9 || camType == 10 || camType == 11){
|
|
|
+ sceneFileBuildService.turntableUploadSuccess(encode, user);
|
|
|
+ }else{
|
|
|
+ sceneFileBuildService.uploadSuccessBuild(encode, user);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void uploadSceneOffline(String num, String sourcePath) throws Exception {
|
|
|
+ ScenePlus scenePlusDb = scenePlusService.getScenePlusByNum(num);
|
|
|
+ ScenePlusExt scenePlusExtDb = scenePlusExtService.getScenePlusExtByPlusId(scenePlusDb.getId());
|
|
|
+ NameFileFilter fileFilter = new NameFileFilter("scene.json");
|
|
|
+ File sceneJsonFile = FileUtil.loopFiles(sourcePath, fileFilter).get(0);
|
|
|
+
|
|
|
+ //去读data.fdage
|
|
|
+ if(sceneJsonFile != null && !sceneJsonFile.exists()){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_4002.code(), ErrorCode.FAILURE_CODE_4002.formatMessage("scene.json"));
|
|
|
+ }
|
|
|
+
|
|
|
+ SceneJsonBean sceneJsonBean = JSONObject.parseObject(FileUtil.readUtf8String(sceneJsonFile), SceneJsonBean.class);
|
|
|
+ String sceneViewDataPath = "/oss/4dkankan/" + String.format(UploadFilePath.VIEW_PATH, num);
|
|
|
+ FileUtil.mkdir(sceneViewDataPath);
|
|
|
+ String cpCmd = "cp -p -r " + sourcePath + "/* " + sceneViewDataPath;
|
|
|
+ CmdUtils.callLineSh(cpCmd);
|
|
|
+
|
|
|
+ String sceneJsonStr = FileUtil.readUtf8String(sceneJsonFile);
|
|
|
+ ScenePlus scenePlus = JSON.parseObject(sceneJsonStr, ScenePlus.class);
|
|
|
+ scenePlus.setId(scenePlusDb.getId());
|
|
|
+ scenePlusService.updateById(scenePlus);
|
|
|
+
|
|
|
+ ScenePlusExt scenePlusExt = JSON.parseObject(sceneJsonStr, ScenePlusExt.class);
|
|
|
+ scenePlusExt.setPlusId(scenePlusExtDb.getPlusId());
|
|
|
+ scenePlusExt.setId(scenePlusExtDb.getId());
|
|
|
+ scenePlusExtService.updateById(scenePlusExt);
|
|
|
+
|
|
|
+ SceneEditInfo sceneEditInfo = JSON.parseObject(sceneJsonStr, SceneEditInfo.class);
|
|
|
+ sceneEditInfo.setId(null);
|
|
|
+ sceneEditInfo.setScenePlusId(scenePlusDb.getId());
|
|
|
+ sceneEditInfoService.save(sceneEditInfo);
|
|
|
+
|
|
|
+ SceneEditInfoExt sceneEditInfoExt = JSON.parseObject(sceneJsonStr, SceneEditInfoExt.class);
|
|
|
+ sceneEditInfoExt.setId(null);
|
|
|
+ sceneEditInfoExt.setScenePlusId(scenePlusDb.getId());
|
|
|
+ sceneEditInfoExt.setEditInfoId(sceneEditInfo.getId());
|
|
|
+ sceneEditInfoExtService.save(sceneEditInfoExt);
|
|
|
+
|
|
|
+ SceneEditControls sceneEditControls = JSON.parseObject(sceneJsonStr, SceneEditControls.class);
|
|
|
+ sceneEditControls.setId(null);
|
|
|
+ sceneEditControls.setEditInfoId(sceneEditInfo.getId());
|
|
|
+ sceneEditControlsService.save(sceneEditControls);
|
|
|
+ }
|
|
|
+
|
|
|
}
|