|
@@ -1,29 +1,36 @@
|
|
|
package com.fdkankan.contro.controller;
|
|
|
|
|
|
+import cn.hutool.core.util.ZipUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.fdkankan.common.constant.ErrorCode;
|
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
|
-import com.fdkankan.contro.entity.Company;
|
|
|
+import com.fdkankan.common.util.FileUtils;
|
|
|
+import com.fdkankan.common.util.SnowflakeIdGenerator;
|
|
|
+import com.fdkankan.contro.constant.RedisConstants;
|
|
|
+import com.fdkankan.contro.entity.SceneFileBuild;
|
|
|
+import com.fdkankan.contro.entity.ScenePro;
|
|
|
import com.fdkankan.contro.service.ISceneFileBuildService;
|
|
|
+import com.fdkankan.contro.service.IScenePlusService;
|
|
|
+import com.fdkankan.contro.service.ISceneProService;
|
|
|
import com.fdkankan.contro.vo.ResponseSceneFile;
|
|
|
import com.fdkankan.fyun.face.FYunFileServiceInterface;
|
|
|
-import com.fdkankan.rabbitmq.bean.BuildSceneCallMessage;
|
|
|
-import com.fdkankan.rabbitmq.util.RabbitMqProducer;
|
|
|
+import com.fdkankan.model.constants.ConstantFilePath;
|
|
|
+import com.fdkankan.redis.util.RedisLockUtil;
|
|
|
+import com.fdkankan.redis.util.RedisUtil;
|
|
|
import com.fdkankan.web.response.ResultData;
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.tomcat.util.bcel.Const;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* 场景文件上传模块
|
|
@@ -39,6 +46,18 @@ public class SceneFileController{
|
|
|
@Autowired
|
|
|
private FYunFileServiceInterface fYunFileService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private RedisLockUtil redisLockUtil;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RedisUtil redisUtil;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IScenePlusService scenePlusService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISceneProService sceneProService;
|
|
|
+
|
|
|
/**
|
|
|
* 场景文件上传之前先获取fileId
|
|
|
* @param params
|
|
@@ -120,22 +139,103 @@ public class SceneFileController{
|
|
|
|
|
|
@PostMapping("sendCallAlgorithm")
|
|
|
public ResultData sendCallAlgorithm(Map<String,String> params) throws Exception {
|
|
|
+ log.info("sendCallAlgorithm 参数为:{}",JSONObject.toJSONString(params));
|
|
|
String filePath = params.get("filePath");
|
|
|
if(ObjectUtils.isEmpty(filePath)){
|
|
|
throw new BusinessException(ErrorCode.PARAM_ERROR,"filePath为空。");
|
|
|
}
|
|
|
+ if(!filePath.endsWith(File.separator)){
|
|
|
+ filePath = filePath.concat(File.separator);
|
|
|
+ }
|
|
|
// 读取本地文件并校验文件
|
|
|
// 读取config.json
|
|
|
+ if(!new File(filePath+"config.json").exists()){
|
|
|
+ throw new BusinessException(ErrorCode.PARAM_ERROR,"缺少 config.json 文件");
|
|
|
+ }
|
|
|
|
|
|
+ JSONObject configJson = JSONObject.parseObject(FileUtils.readFile(filePath + "config.json"));
|
|
|
|
|
|
+ String folderName = configJson.getString("id");
|
|
|
+ String sncode = configJson.getString("sn");
|
|
|
+ String zipFileName = configJson.getString("zipFileName");
|
|
|
+ if(ObjectUtils.isEmpty(folderName) || ObjectUtils.isEmpty(sncode) || ObjectUtils.isEmpty(zipFileName)){
|
|
|
+ throw new BusinessException(ErrorCode.PARAM_ERROR,"config.json 文件有误!");
|
|
|
+ }
|
|
|
|
|
|
+ // 检测是否有生成
|
|
|
+ String fileId = getFileIdByFolderName(folderName);
|
|
|
+ String subFolder = sncode.concat(File.separator).concat(fileId).concat(File.separator).concat(folderName);
|
|
|
// 解压获取dataSource 并上传资源到OSS
|
|
|
- String dataSource = null;
|
|
|
- // 通知计算
|
|
|
+ String dataSource = ConstantFilePath.BUILD_MODEL_PATH.concat(subFolder);
|
|
|
+ log.info("dataSource 为:{}", dataSource);
|
|
|
|
|
|
+ // 解压资源文件上传
|
|
|
+ ZipUtil.unzip(filePath.concat(zipFileName),dataSource.concat(File.separator).concat("capture"));
|
|
|
+
|
|
|
+ // 上传oaas
|
|
|
+ fYunFileService.uploadFileByCommand(dataSource.concat(File.separator).concat("capture"), ConstantFilePath.OSS_PREFIX.concat(subFolder));
|
|
|
+
|
|
|
+ // 通知计算
|
|
|
return sceneFileBuildService.copyDataAndBuild(null,dataSource ,"V4");
|
|
|
}
|
|
|
|
|
|
+ private String getFileIdByFolderName(String folderName) {
|
|
|
+ // 检测是否有生成
|
|
|
+ String fileId = redisUtil.get(String.format(RedisConstants.FOLDER_FILEID_BUILD, folderName));
|
|
|
+ if (!org.springframework.util.ObjectUtils.isEmpty(fileId)) {
|
|
|
+ return fileId;
|
|
|
+ }
|
|
|
+
|
|
|
+ SceneFileBuild sceneFileBuild = sceneFileBuildService.findByUnicode(folderName);
|
|
|
+ if (sceneFileBuild != null) {
|
|
|
+ fileId = sceneFileBuild.getFileId();
|
|
|
+ redisUtil.set(String.format(RedisConstants.FOLDER_FILEID_BUILD, folderName), fileId, 2 * 24 * 60 * 60);
|
|
|
+ return fileId;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 加锁
|
|
|
+ boolean lock = redisLockUtil.lock(String.format(RedisConstants.FOLDER_LOCK_BUILD, folderName), 120);
|
|
|
+ if (!lock) {
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_5052);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查找场景表
|
|
|
+ LambdaQueryWrapper<ScenePro> proWrapper = new LambdaQueryWrapper<>();
|
|
|
+ proWrapper.like(ScenePro::getDataSource, "/" + folderName).eq(ScenePro::getRecStatus, 'A');
|
|
|
+ ScenePro pro = sceneProService.getOne(proWrapper);
|
|
|
+
|
|
|
+ String dataSource = null;
|
|
|
+
|
|
|
+ if (!org.springframework.util.ObjectUtils.isEmpty(pro)) {
|
|
|
+ dataSource = pro.getDataSource();
|
|
|
+ } else {
|
|
|
+ dataSource = scenePlusService.getDataSourceLikeUnicode("/" + folderName);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!org.springframework.util.ObjectUtils.isEmpty(dataSource)) {
|
|
|
+ log.info("从数据库中查到与 fileId:{} 匹配的路径为:{}", fileId, dataSource);
|
|
|
+ int n = dataSource.split("/").length;
|
|
|
+ if (n > 1) {
|
|
|
+ fileId = dataSource.split("/")[n - 2];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (org.springframework.util.ObjectUtils.isEmpty(fileId)) {
|
|
|
+ throw new BusinessException(ErrorCode.PARAM_ERROR,"获取FileID 失败,请重新拍摄!");
|
|
|
+ }
|
|
|
+
|
|
|
+ sceneFileBuild = new SceneFileBuild();
|
|
|
+ sceneFileBuild.setChildName(dataSource.split("_")[0]);
|
|
|
+ sceneFileBuild.setFileId(fileId);
|
|
|
+ sceneFileBuild.setRecStatus("A");
|
|
|
+ sceneFileBuild.setUnicode(folderName);
|
|
|
+ sceneFileBuild.setCreateTime(new Date());
|
|
|
+ sceneFileBuildService.save(sceneFileBuild);
|
|
|
+ redisUtil.set(String.format(RedisConstants.FOLDER_FILEID_BUILD, folderName), fileId, 2 * 24 * 60 * 60);
|
|
|
+ redisUtil.set(String.format(RedisConstants.FILEID_FOLDER_BUILD, fileId), folderName, 2 * 24 * 60 * 60);
|
|
|
+ return fileId;
|
|
|
+ }
|
|
|
+
|
|
|
@GetMapping("copyDataAndBuild")
|
|
|
public ResultData copyDataAndBuild(@RequestParam(value = "dataSource") String dataSource,@RequestParam(value = "sceneVer") String sceneVer,
|
|
|
@RequestParam(value = "sourceBucket",required = false) String sourceBucket) throws Exception {
|