|
@@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.thread.ThreadUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.extra.qrcode.QrCodeUtil;
|
|
|
import cn.hutool.extra.qrcode.QrConfig;
|
|
@@ -32,6 +33,7 @@ import com.fdkankan.model.constants.ConstantFilePath;
|
|
|
import com.fdkankan.model.constants.UploadFilePath;
|
|
|
import com.fdkankan.rabbitmq.bean.BuildSceneCallMessage;
|
|
|
import com.fdkankan.rabbitmq.util.RabbitMqProducer;
|
|
|
+import com.fdkankan.redis.constant.RedisKey;
|
|
|
import com.fdkankan.redis.util.RedisLockUtil;
|
|
|
import com.fdkankan.redis.util.RedisUtil;
|
|
|
import com.fdkankan.web.response.Result;
|
|
@@ -55,6 +57,9 @@ import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -157,6 +162,9 @@ public class SceneFileBuildServiceImpl extends ServiceImpl<ISceneFileBuildMapper
|
|
|
|
|
|
private RestTemplate restTemplate = new RestTemplate();
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ISceneCopyDistinctEnvService sceneCopyDistinctEnvService;
|
|
|
+
|
|
|
@Override
|
|
|
public SceneFileBuild findByFileId(String fileId) {
|
|
|
|
|
@@ -1294,16 +1302,17 @@ public class SceneFileBuildServiceImpl extends ServiceImpl<ISceneFileBuildMapper
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public ResultData copyDataAndBuild(String sourceBucet,String dataSource,String sceneVer) throws Exception {
|
|
|
- if(!StringUtils.equals(sceneVer,"V3") && ! StringUtils.equals(sceneVer,"V4")){
|
|
|
+ public ResultData copyDataAndBuild(String sourceBucet,String dataSource, String sceneVer) throws Exception {
|
|
|
+ if(!SceneVersionType.V3.code().equals(sceneVer)
|
|
|
+ && !SceneVersionType.V4.code().equals(sceneVer)){
|
|
|
throw new BusinessException(ErrorCode.PARAM_FORMAT_ERROR.code(),"版本有误,请填写 V3 或者 V4");
|
|
|
}
|
|
|
|
|
|
String fYunPath = ConstantFilePath.OSS_PREFIX + dataSource.replace(ConstantFilePath.BUILD_MODEL_PATH, "")
|
|
|
.replace(ConstantFilePath.BUILD_MODEL_LASER_PATH, "");
|
|
|
- if(!ObjectUtils.isEmpty(sourceBucet)){
|
|
|
- fYunFileService.copyFileBetweenBucket(sourceBucet,fYunPath,fYunFileConfig.getBucket(),fYunPath);
|
|
|
- }
|
|
|
+// if(!ObjectUtils.isEmpty(sourceBucet)){
|
|
|
+// fYunFileService.copyFileBetweenBucket(sourceBucet,fYunPath,fYunFileConfig.getBucket(),fYunPath);
|
|
|
+// }
|
|
|
// 下载data.fdage
|
|
|
JSONObject fdageData = JSONObject.parseObject(fYunFileService.getFileContent(fYunPath + "/data.fdage"));
|
|
|
if(ObjectUtils.isEmpty(fdageData)){
|
|
@@ -1320,66 +1329,105 @@ public class SceneFileBuildServiceImpl extends ServiceImpl<ISceneFileBuildMapper
|
|
|
throw new BusinessException(ErrorCode.FAILURE_CODE_6003);
|
|
|
}
|
|
|
|
|
|
- Long cameraType = 11L;
|
|
|
- //判断是否转台相机
|
|
|
- if (detailEntity.getType() == 9) {
|
|
|
- cameraType = 13L;
|
|
|
- }
|
|
|
+ // 拷贝资源至新的资源路径
|
|
|
+ String[] newDataPath = dataSource.split("/");
|
|
|
+ newDataPath[4] = newDataPath[4] + "_" + System.currentTimeMillis();
|
|
|
+ String time = DateExtUtil.format(Calendar.getInstance().getTime(), DateExtUtil.dateStyle11);
|
|
|
+ newDataPath[5] = newDataPath[5].split("_")[0] + "_" + time;
|
|
|
+ String newDataSource = Arrays.stream(newDataPath).collect(Collectors.joining("/"));
|
|
|
|
|
|
- if (detailEntity.getType() == 10) {
|
|
|
- cameraType = 14L;
|
|
|
+ String newFYunPath = ConstantFilePath.OSS_PREFIX + newDataSource.replace(ConstantFilePath.BUILD_MODEL_PATH, "")
|
|
|
+ .replace(ConstantFilePath.BUILD_MODEL_LASER_PATH, "");
|
|
|
+
|
|
|
+ List<ScenePro> pros = sceneProService.list(new LambdaQueryWrapper<ScenePro>().eq(ScenePro::getDataSource, newDataSource));
|
|
|
+ if (CollUtil.isNotEmpty(pros)) {
|
|
|
+ return ResultData.error(ErrorCode.PARAM_ERROR.code(),newDataSource + "已存在,请勿重复添加!");
|
|
|
+ }
|
|
|
+ List<ScenePlusExt> plusExts = scenePlusExtService.list(new LambdaQueryWrapper<ScenePlusExt>().eq(ScenePlusExt::getDataSource, newDataSource));
|
|
|
+ if (CollUtil.isNotEmpty(plusExts)) {
|
|
|
+ return ResultData.error(ErrorCode.PARAM_ERROR.code(),newDataSource + "已存在,请勿重复添加!");
|
|
|
}
|
|
|
+ List<String> newFyunFileList = fYunFileService.listRemoteFiles(newFYunPath);
|
|
|
+ if(CollUtil.isNotEmpty(newFyunFileList)){
|
|
|
+ return ResultData.error(ErrorCode.PARAM_ERROR.code(),newFYunPath + "已存在,请勿重复添加!");
|
|
|
+ }
|
|
|
+
|
|
|
String sceneNum = scene3dNumService.generateSceneNum(detailEntity.getType());
|
|
|
|
|
|
- String icon = null;
|
|
|
- String imgViewPath = null;
|
|
|
- switch (sceneVer) {
|
|
|
- case "V3":
|
|
|
- List<ScenePro> pros = sceneProService.list(new LambdaQueryWrapper<ScenePro>()
|
|
|
- .like(ScenePro::getDataSource, dataSource));
|
|
|
- if (pros.size() > 0) {
|
|
|
- return ResultData.error(ErrorCode.PARAM_ERROR.code(),"该场景资源已存在,请勿重复添加!");
|
|
|
- }
|
|
|
+ //写入日志表
|
|
|
+ SceneCopyDistinctEnv sceneCopyDistinctEnv = new SceneCopyDistinctEnv();
|
|
|
+ sceneCopyDistinctEnv.setNum(sceneNum);
|
|
|
+ sceneCopyDistinctEnv.setSrcDataSource(dataSource);
|
|
|
+ sceneCopyDistinctEnv.setTargetDataSource(newDataSource);
|
|
|
+ sceneCopyDistinctEnvService.save(sceneCopyDistinctEnv);
|
|
|
+
|
|
|
+ ExecutorService executor = ThreadUtil.newSingleExecutor();
|
|
|
+ try {
|
|
|
+ CompletableFuture.runAsync(() -> {
|
|
|
+ try {
|
|
|
+ fYunFileService.copyFileBetweenBucket(sourceBucet, fYunPath, fYunFileConfig.getBucket(), newFYunPath);
|
|
|
+
|
|
|
+ fdageData.put("uuidtime",time);
|
|
|
+ fYunFileService.uploadFile(fdageData.toJSONString().getBytes(),newFYunPath+"/data.fdage");
|
|
|
+
|
|
|
+ Long cameraType = 11L;
|
|
|
+ //判断是否转台相机
|
|
|
+ if (detailEntity.getType() == 9) {
|
|
|
+ cameraType = 13L;
|
|
|
+ }
|
|
|
|
|
|
- imgViewPath = String.format(ConstantFilePath.IMAGE_PATH_FORMAT, sceneNum);
|
|
|
- if(fdageData.containsKey("icon") && StringUtils.isNotEmpty(fdageData.getString("icon"))){
|
|
|
- String ossPath = ConstantFilePath.OSS_PREFIX + dataSource.replace(ConstantFilePath.BUILD_MODEL_PATH, "")
|
|
|
- .replace(ConstantFilePath.BUILD_MODEL_LASER_PATH, "");
|
|
|
- fYunFileService.copyFileInBucket(ossPath + File.separator + fdageData.getString("icon"),imgViewPath + fdageData.getString("icon"));
|
|
|
- icon = fYunFileConfig.getHost() + imgViewPath + fdageData.getString("icon");
|
|
|
- log.info("上传icon成功....");
|
|
|
- }
|
|
|
- buildV3Scene2(dataSource,fdageData,cameraType,sceneNum,cameraEntity,detailEntity,icon);
|
|
|
- break;
|
|
|
- case "V4":
|
|
|
- List<ScenePlusExt> plusExts = scenePlusExtService.list(new LambdaQueryWrapper<ScenePlusExt>()
|
|
|
- .like(ScenePlusExt::getDataSource, dataSource));
|
|
|
- if (plusExts.size() > 0) {
|
|
|
- return ResultData.error(ErrorCode.PARAM_ERROR.code(),"该场景资源已存在,请勿重复添加!");
|
|
|
- }
|
|
|
+ if (detailEntity.getType() == 10) {
|
|
|
+ cameraType = 14L;
|
|
|
+ }
|
|
|
|
|
|
- imgViewPath = String.format(UploadFilePath.IMG_VIEW_PATH, sceneNum);
|
|
|
- if(fdageData.containsKey("icon") && StringUtils.isNotEmpty(fdageData.getString("icon"))){
|
|
|
- String ossPath = ConstantFilePath.OSS_PREFIX + dataSource.replace(ConstantFilePath.BUILD_MODEL_PATH, "")
|
|
|
- .replace(ConstantFilePath.BUILD_MODEL_LASER_PATH, "");
|
|
|
- fYunFileService.copyFileInBucket(ossPath + File.separator + fdageData.getString("icon"),imgViewPath + fdageData.getString("icon"));
|
|
|
- icon = fYunFileConfig.getHost() + imgViewPath + fdageData.getString("icon");
|
|
|
- log.info("上传icon成功....");
|
|
|
- }
|
|
|
- buildScenePost(dataSource, fdageData, "V3", cameraType, sceneNum, detailEntity, 0, icon);
|
|
|
- if (cameraType == 14) {
|
|
|
- // 通知激光系统
|
|
|
- ScenePlus scenePlus = scenePlusService.getScenePlusByNum(sceneNum);
|
|
|
- String userName = null;
|
|
|
- if (!ObjectUtils.isEmpty(detailEntity.getUserId())) {
|
|
|
- userName = userService.getSSOUserByUserId(detailEntity.getUserId()).getUserName();
|
|
|
+ String icon = null;
|
|
|
+ String imgViewPath = null;
|
|
|
+ switch (sceneVer) {
|
|
|
+ case "V3":
|
|
|
+ imgViewPath = String.format(ConstantFilePath.IMAGE_PATH_FORMAT, sceneNum);
|
|
|
+ if(fdageData.containsKey("icon") && StringUtils.isNotEmpty(fdageData.getString("icon"))){
|
|
|
+ String ossPath = ConstantFilePath.OSS_PREFIX + newDataSource.replace(ConstantFilePath.BUILD_MODEL_PATH, "")
|
|
|
+ .replace(ConstantFilePath.BUILD_MODEL_LASER_PATH, "");
|
|
|
+ fYunFileService.copyFileInBucket(ossPath + File.separator + fdageData.getString("icon"),imgViewPath + fdageData.getString("icon"));
|
|
|
+ icon = fYunFileConfig.getHost() + imgViewPath + fdageData.getString("icon");
|
|
|
+ }
|
|
|
+ buildV3Scene2(newDataSource,fdageData,cameraType,sceneNum,cameraEntity,detailEntity,icon);
|
|
|
+ break;
|
|
|
+ case "V4":
|
|
|
+ imgViewPath = String.format(UploadFilePath.IMG_VIEW_PATH, sceneNum);
|
|
|
+ if(fdageData.containsKey("icon") && StringUtils.isNotEmpty(fdageData.getString("icon"))){
|
|
|
+ String ossPath = ConstantFilePath.OSS_PREFIX + newDataSource.replace(ConstantFilePath.BUILD_MODEL_PATH, "")
|
|
|
+ .replace(ConstantFilePath.BUILD_MODEL_LASER_PATH, "");
|
|
|
+ fYunFileService.copyFileInBucket(ossPath + File.separator + fdageData.getString("icon"),imgViewPath + fdageData.getString("icon"));
|
|
|
+ icon = fYunFileConfig.getHost() + imgViewPath + fdageData.getString("icon");
|
|
|
+ }
|
|
|
+ buildScenePost(newDataSource, fdageData, "V3", cameraType, sceneNum, detailEntity, 0, icon);
|
|
|
+ if (cameraType == 14) {
|
|
|
+ // 通知激光系统
|
|
|
+ ScenePlus scenePlus = scenePlusService.getScenePlusByNum(sceneNum);
|
|
|
+ String userName = null;
|
|
|
+ if (!ObjectUtils.isEmpty(detailEntity.getUserId())) {
|
|
|
+ userName = userService.getSSOUserByUserId(detailEntity.getUserId()).getUserName();
|
|
|
+ }
|
|
|
+ fdkkLaserService.saveScene(scenePlus, fdageData.getString("pwd"), cameraEntity, userName, false);
|
|
|
+ }
|
|
|
+ break;
|
|
|
}
|
|
|
- fdkkLaserService.saveScene(scenePlus, fdageData.getString("pwd"), cameraEntity, userName, false);
|
|
|
+
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("复制场景异常", e);
|
|
|
}
|
|
|
- break;
|
|
|
+ }, executor).whenComplete((reslut, e) -> {
|
|
|
+ log.info("复制场景souceDataSource:{},newDataSource:{}结束-{}",dataSource,newDataSource, new Date());
|
|
|
+ });
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("线程错误:{}",e);
|
|
|
+ }finally {
|
|
|
+ executor.shutdown();
|
|
|
}
|
|
|
Map<String,Object> result = new HashMap<>();
|
|
|
result.put("code",sceneNum);
|
|
|
+ result.put("newDataSource",newDataSource);
|
|
|
return ResultData.ok(result);
|
|
|
}
|
|
|
|