package com.fdkankan.contro.service.impl;
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.core.util.ZipUtil;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fdkankan.common.constant.*;
import com.fdkankan.common.exception.BusinessException;
import com.fdkankan.common.util.DateExtUtil;
import com.fdkankan.common.util.FileMd5Util;
import com.fdkankan.common.util.FileUtils;
import com.fdkankan.common.util.SnowflakeIdGenerator;
import com.fdkankan.contro.bean.SendCallAlgorithmDetail;
import com.fdkankan.contro.common.Result;
import com.fdkankan.contro.constant.RedisConstants;
import com.fdkankan.contro.entity.*;
import com.fdkankan.contro.mapper.ISceneFileBuildMapper;
import com.fdkankan.contro.service.*;
import com.fdkankan.contro.vo.ResponseSceneFile;
import com.fdkankan.contro.vo.ScenePlusVO;
import com.fdkankan.contro.vo.SendCallAlgorithmParam;
import com.fdkankan.fyun.config.FYunFileConfig;
import com.fdkankan.fyun.face.FYunFileServiceInterface;
import com.fdkankan.fyun.local.constant.LocalConstants;
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.util.RedisLockUtil;
import com.fdkankan.redis.util.RedisUtil;
import com.fdkankan.web.response.ResultData;
import com.fdkankan.web.util.RSAEncrypt;
import lombok.extern.slf4j.Slf4j;
import net.lingala.zip4j.core.ZipFile;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.web.multipart.MultipartFile;
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;
/**
*
* 场景文件建模表 服务实现类
*
*
* @author dengsixing
* @since 2021-12-23
*/
@Slf4j
@Service
public class SceneFileBuildServiceImpl extends ServiceImpl implements ISceneFileBuildService {
private static final String SPLICE = "#";
private static final String sendCallAlgorithmPath = "/mnt/sendCallAlgorithm/";
private static final String zipPassword = "a3ad34136de359536af553f9e7f3cefd";
@Value("${main.url}")
private String mainUrl;
@Value("${fyun.type}")
private String fyunType;
@Value("${scene.pro.new.url}")
private String sceneProNewUrl;
@Value("${queue.modeling.modeling-pre}")
private String queueModelingPre;
@Autowired
private RedisUtil redisUtil;
@Autowired
private IScenePlusExtService scenePlusExtService;
@Autowired
private IScene3dNumService scene3dNumService;
@Autowired
private IScenePlusService scenePlusService;
@Autowired
private RabbitMqProducer rabbitMqProducer;
@Autowired
private ISceneEditInfoService sceneEditInfoService;
@Autowired
private ISceneEditControlsService sceneEditControlsService;
@Autowired
private ISceneEditInfoExtService sceneEditInfoExtService;
@Autowired
private ISceneCooperationService sceneCooperationService;
@Autowired
private ISceneResourceCameraService sceneResourceCameraService;
@Autowired
private ISceneResourceCooperationService sceneResourceCooperationService;
@Autowired
private ICameraService cameraService;
@Autowired
private ICameraDetailService cameraDetailService;
@Autowired
private IUserService userService;
@Autowired
private ISceneFileUploadService sceneFileUploadService;
@Autowired
private FYunFileServiceInterface fYunFileService;
@Autowired
private FYunFileConfig fYunFileConfig;
@Autowired
private RedisLockUtil redisLockUtil;
@Autowired
private IScenePreService scenePreService;
@Autowired
private ICompanyService companyService;
@Override
public SceneFileBuild findByFileId(String fileId) {
List list = this.list(new LambdaQueryWrapper().eq(SceneFileBuild::getFileId, fileId)
.orderByDesc(SceneFileBuild::getId));
if(CollUtil.isEmpty(list)){
return null;
}
return list.get(0);
}
@Override
public ResponseSceneFile preUpload(String params) throws Exception {
log.info("preUpload-params: "+params);
if (StrUtil.isEmpty(params)){
throw new BusinessException(ErrorCode.PARAM_REQUIRED);
}
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("preUpload-params解密结果:" + restr);
String[] strArr = restr.split(SPLICE);
if (strArr.length != 5) {
throw new BusinessException(ErrorCode.PARAM_REQUIRED);
}
String mac = strArr[0];
String totalPicNum = strArr[1];
String chunks = strArr[2];
String folderName = strArr[3];
if (StrUtil.isEmpty(mac)){
throw new BusinessException(ErrorCode.FAILURE_CODE_5044);
}
if (totalPicNum == null){
throw new BusinessException(ErrorCode.FAILURE_CODE_5045);
}
if (chunks == null){
throw new BusinessException(ErrorCode.FAILURE_CODE_5046);
}
if (folderName == null){
throw new BusinessException(ErrorCode.FAILURE_CODE_5047);
}
log.info("mac:{} 准备上传文件,folderName:{}", mac, folderName);
ResponseSceneFile responseSceneFile = new ResponseSceneFile();
// 检测是否有生成
String fileId = redisUtil.get(String.format(RedisConstants.FOLDER_FILEID_BUILD, folderName));
if (!ObjectUtils.isEmpty(fileId)) {
responseSceneFile.setFileId(fileId);
return responseSceneFile;
}
SceneFileBuild sceneFileBuild = this.findByUnicode(folderName);
if (sceneFileBuild != null) {
fileId = sceneFileBuild.getFileId();
responseSceneFile.setFileId(fileId);
redisUtil.set(String.format(RedisConstants.FOLDER_FILEID_BUILD, folderName), fileId, 2 * 24 * 60 * 60);
return responseSceneFile;
}
// 加锁
long incr = redisUtil.incr(String.format(RedisConstants.FOLDER_LOCK_BUILD, folderName), 1);
if (incr > 1) {
throw new BusinessException(ErrorCode.FAILURE_CODE_5052);
}
redisUtil.expire(String.format(RedisConstants.FOLDER_LOCK_BUILD, folderName), 120);
log.info("开始新生成build数据");
fileId = new SnowflakeIdGenerator(0, 0).nextId() + "";
log.info("新生成build数据,{}", fileId);
sceneFileBuild = new SceneFileBuild();
sceneFileBuild.setChildName(mac);
sceneFileBuild.setFileId(fileId);
sceneFileBuild.setUnicode(folderName);
sceneFileBuild.setTotalPicNum(Integer.valueOf(totalPicNum));
sceneFileBuild.setChunks(Integer.valueOf(chunks));
this.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);
responseSceneFile.setFileId(fileId);
return responseSceneFile;
}
public SceneFileBuild findByUnicode(String unicode) {
List list = this.list(new QueryWrapper()
.eq("unicode", unicode)
.orderByDesc("id"));
if(CollUtil.isEmpty(list))
return null;
return list.get(0);
}
public ScenePlusVO buildScene(String fileId, String prefix,JSONObject jsonObject,String buildType,long cameraType) throws Exception{
//调用createScene方法生成scene数据和加入算法队列
String sceneNum = "";
String cameraName = jsonObject.getJSONObject("cam").getString("uuid");
String unicode = jsonObject.getString("creator") + "_" + jsonObject.getString("uuidtime");
Camera camera = cameraService.getByChildName(cameraName);
if (camera == null) {
throw new BusinessException(CameraConstant.FAILURE_6003);
}
CameraDetail cameraDetail = cameraDetailService.getByCameraId(camera.getId());
if (cameraDetail == null) {
log.error("该相机详情不存在:" + cameraName);
throw new BusinessException(CameraConstant.FAILURE_6003);
}
//查看场景中的文件目录是否有改文件id,有则重新计算改场景,无则新建场景
ScenePlus scenePlus = scenePlusService.getByFileId("/" + fileId + "/");
int rebuild = 1;
if (ObjectUtils.isEmpty(scenePlus)) {
sceneNum = scene3dNumService.generateSceneNum(cameraDetail.getType());
rebuild = 0;
} else {
sceneNum = scenePlus.getNum();
if (scenePlus.getSceneStatus().equals(SceneStatus.wait.code())) {
log.info(scenePlus.getNum() + ":场景处于计算中,不能再计算");
return null;
}
}
if (sceneNum == null) {
log.error("大场景序号为空:" + sceneNum);
throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
}
String dataSource = cameraName.replace("4DKKPRO_", "").replace("-fdage", "").toLowerCase() + File.separator +
fileId + File.separator + unicode;
if (cameraType == 14) {
dataSource = ConstantFilePath.BUILD_MODEL_LASER_PATH +dataSource;
} else {
dataSource = ConstantFilePath.BUILD_MODEL_PATH + dataSource;
}
String localDataPath = String.format(ConstantFilePath.DATABUFFER_FORMAT, sceneNum);
String imgViewPath = String.format(UploadFilePath.IMG_VIEW_PATH, sceneNum);
String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, sceneNum);
String userName = null;
if (!ObjectUtils.isEmpty(cameraDetail.getUserId())) {
SSOUser user = userService.getSSOUserByUserId(cameraDetail.getUserId());
userName = ObjectUtils.isEmpty(user) ? null : user.getUserName();
}
String icon = null;
if (!ObjectUtils.isEmpty(jsonObject.getString("icon"))) {
fYunFileService.copyFileInBucket(ConstantFilePath.OSS_PREFIX + prefix + jsonObject.getString("icon"),imgViewPath + jsonObject.getString("icon"));
icon = fYunFileConfig.getHost() + imgViewPath + jsonObject.getString("icon");
log.info("上传icon成功....");
}
JSONObject firmwareVersion = new JSONObject();
if (!ObjectUtils.isEmpty(jsonObject.getString("camSoftwareVersion"))) {
firmwareVersion.put("camSoftwareVersion", jsonObject.getString("camSoftwareVersion"));
}
if (!ObjectUtils.isEmpty(jsonObject.getString("version"))) {
firmwareVersion.put("version", jsonObject.getString("version"));
}
String sceneUrl = "/" + sceneProNewUrl;
//重算的场景,先移除该场景对应的容量
if (rebuild == 1) {
scenePlusService.resetSpace(sceneNum);
//删除oss的houst_floor.json(国际版可能会卡住)
fYunFileService.deleteFile(dataViewPath + "houst_floor.json");
} else {
//上传log-main.png
fYunFileService.uploadFile(ConstantFilePath.LOGO_PATH + "logo-main.png", imgViewPath + "logo-main.png");
fYunFileService.uploadFile(ConstantFilePath.LOGO_PATH + "logo-main-en.png", imgViewPath + "logo-main-en.png");
}
String algorithm = jsonObject.getString("location") != null && "1".equals(jsonObject.getString("location")) ? "sfm" : "slam";
ScenePlusVO scenePlusVO = this.createScenePlus(sceneNum, camera.getId(), camera.getChildName(), jsonObject.getString("creator"),
jsonObject.getString("pwd"), unicode,cameraType, dataSource, icon, cameraDetail.getUserId(), userName,algorithm,
jsonObject.getJSONArray("points").size(), jsonObject.getString("name"), jsonObject.getString("info"),
jsonObject.getInteger("scenetype"), jsonObject.getString("gps"), rebuild,
jsonObject.getInteger("resolution"), firmwareVersion.toString(), sceneUrl, buildType, cameraDetail.getCooperationUser());
if (Objects.nonNull(scenePlusVO)) {
JSONObject statusJson = new JSONObject();
//临时将-2改成1,app还没完全更新
statusJson.put("status", scenePlusVO.getSceneStatus() == -2 ? 1 : scenePlusVO.getSceneStatus());
statusJson.put("webSite", scenePlusVO.getWebSite());
statusJson.put("sceneNum", scenePlusVO.getNum());
statusJson.put("thumb", scenePlusVO.getThumb());
statusJson.put("payStatus", 0);
statusJson.put("recStatus", 'A');
FileUtils.writeFile(localDataPath + "status.json", statusJson.toString());
fYunFileService.uploadFile(localDataPath + "status.json", dataViewPath + "status.json");
}
BuildSceneCallMessage mqMessage = getBuildSceneMqMessage(sceneNum, cameraType, algorithm, jsonObject.getInteger("resolution"), buildType,
scenePlusVO.getDataSource());
rabbitMqProducer.sendByWorkQueue(queueModelingPre, mqMessage);
return scenePlusVO;
}
@Override
public ResultData uploadSuccessBuild(String params) throws Exception {
log.info("uploadSuccessBuild-params: " + params);
if (StringUtils.isEmpty(params)) {
throw new BusinessException(ErrorCode.PARAM_REQUIRED);
}
params = params.replaceAll("%2B", "+");
params = params.replaceAll(" ", "+");
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.info("uploadSuccessBuild-params解密结果:" + restr);
String[] strArr = restr.split(SPLICE);
if (strArr.length != 3) {
throw new BusinessException(ErrorCode.PARAM_REQUIRED);
}
String mac = strArr[0];
String fileId = strArr[1];
String folderName = redisUtil.get(String.format(RedisConstants.FILEID_FOLDER_BUILD, fileId));
if(StringUtils.isEmpty(folderName)){
SceneFileBuild fileBuild = findByFileId(fileId);
if(ObjectUtils.isEmpty(fileBuild)){
throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
}
folderName = fileBuild.getUnicode();
redisUtil.set(String.format(RedisConstants.FILEID_FOLDER_BUILD, fileId), folderName,2 * 24 * 60 * 60);
}
StringBuilder prefixBuffer = new StringBuilder(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator);
String buildType = "V2";
Long cameraType = 10L;
JSONObject fdageJson = JSONObject.parseObject(fYunFileService.getFileContent(ConstantFilePath.OSS_PREFIX + prefixBuffer + "data.fdage"));
if(ObjectUtils.isEmpty(fdageJson)){
log.info("data.fdage文件不存在");
throw new BusinessException(CameraConstant.FAILURE_6009);
}
//根据videoVersion判断是V2还是V3版本的算法和页面
if (fdageJson.containsKey("videoVersion") && StrUtil.isNotEmpty(fdageJson.getString("videoVersion"))) {
if (fdageJson.getIntValue("videoVersion") >= 4) {
buildType = "V3";
cameraType = 11L;
}
}
buildScene(fileId, prefixBuffer.toString(),fdageJson,buildType,cameraType);
return ResultData.ok();
}
@Override
public ResultData turntableUploadSuccess(String params) throws Exception {
log.info("turntableUploadSuccess-params: " + params);
if (StringUtils.isEmpty(params)) {
throw new BusinessException(ErrorCode.PARAM_REQUIRED);
}
params = params.replaceAll("%2B", "+");
params = params.replaceAll(" ", "+");
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.info("turntableUploadSuccess-params:解密结果:" + restr);
String[] strArr = restr.split(SPLICE);
if (strArr.length != 3) {
throw new BusinessException(ErrorCode.PARAM_REQUIRED);
}
String mac = strArr[0];
String fileId = strArr[1];
String folderName = redisUtil.get(String.format(RedisConstants.FILEID_FOLDER_BUILD, fileId));
if(StringUtils.isEmpty(folderName)){
SceneFileBuild fileBuild = findByFileId(fileId);
if(ObjectUtils.isEmpty(fileBuild)){
throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
}
folderName = fileBuild.getUnicode();
redisUtil.set(String.format(RedisConstants.FILEID_FOLDER_BUILD, fileId), folderName);
}
//云目录
StringBuilder prefixBuffer = new StringBuilder(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator);
JSONObject fdageJson = JSONObject.parseObject(fYunFileService.getFileContent(ConstantFilePath.OSS_PREFIX + prefixBuffer + "data.fdage"));
if(ObjectUtils.isEmpty(fdageJson)){
log.info("data.fdage文件不存在");
throw new BusinessException(CameraConstant.FAILURE_6009);
}
String buildType = "V3";
//13表示转台
Long cameraType = 13L;
//激光转台 八目相机占用 10 和 11
if(fdageJson.getJSONObject("cam").getIntValue("type") == 10){
//激光转台
cameraType = 14L;
}
buildScene(fileId, prefixBuffer.toString(), fdageJson, buildType, cameraType);
return ResultData.ok();
}
public ScenePlusVO createScenePlus(String projectNum, Long cameraId, String cameraName, String phoneId, String sceneKey,
String unicode, Long cameraType, String dataSource, String pic, Long userId, String userName,
String algorithm, Integer sceneShootCount, String sceneName,
String sceneDec, Integer sceneType, String gps,Integer type,
Integer resolution, String firmwareVersion, String url, String buildType,
Long cooperationUser)throws Exception{
ScenePlusVO scenePlusVO = new ScenePlusVO();
ScenePlus scenePlus = new ScenePlus();
ScenePlusExt scenePlusExt = new ScenePlusExt();
scenePlusExt.setWebSite(url+projectNum);
scenePlus.setCameraId(cameraId);
scenePlus.setPhoneId(phoneId);
scenePlus.setNum(projectNum);
scenePlus.setSceneSource(1);
scenePlusExt.setDataSource(dataSource);
if(resolution == null || resolution.intValue() == 0){
scenePlusExt.setSceneScheme(cameraType.intValue());
}else {
scenePlusExt.setSceneScheme(4);
}
//转台相机用4k图
if(cameraType.longValue() == 13 ){
scenePlus.setSceneSource(3);
scenePlusExt.setSceneScheme(10);
}
if (pic != null && pic.length() > 5) {
scenePlusExt.setThumb(pic);
} else {
scenePlusExt.setThumb(ConstantUrl.DEFAULT_SCENE_PIC);
}
scenePlusExt.setThumb(scenePlusExt.getThumb().concat("?t=") + System.currentTimeMillis());
scenePlus.setUserId(userId);
if (sceneShootCount == null) {
scenePlusExt.setShootCount(0);
} else {
scenePlusExt.setShootCount(sceneShootCount);
}
if (sceneName != null) {
scenePlus.setTitle(sceneName);
}
if (sceneDec != null) {
scenePlus.setDescription("" + new String(sceneDec.getBytes("UTF-8")) + "
");
}
if (sceneType != null) {
scenePlus.setSceneType(sceneType);
}
if (gps != null && !gps.trim().equals("")) {
scenePlusExt.setGps(gps);
}
scenePlusExt.setAlgorithm(algorithm);
if(!org.springframework.util.StringUtils.isEmpty(firmwareVersion)){
scenePlusExt.setFirmwareVersion(firmwareVersion);
}
scenePlusExt.setBuildType(buildType);
log.info("场景记录添加到数据库:"+projectNum);
//type=0为新生成场景,其余为重新计算场景
SceneEditInfo sceneEditInfo = new SceneEditInfo();
SceneEditInfoExt sceneEditInfoExt = new SceneEditInfoExt();
SceneEditControls sceneEditControls = new SceneEditControls();
if(type == 0){
scenePlus.setSceneStatus(SceneStatus.wait.code());
scenePlusService.save(scenePlus);
scenePlusExt.setPlusId(scenePlus.getId());
scenePlusExtService.save(scenePlusExt);
sceneEditInfo.setTitle(scenePlus.getTitle());
sceneEditInfo.setDescription(scenePlus.getDescription());
sceneEditInfo.setScenePlusId(scenePlus.getId());
if(StrUtil.isNotBlank(sceneKey)) {
sceneEditInfo.setScenePassword(sceneKey);
sceneEditControls.setShowLock((int) CommonStatus.YES.code());
}
sceneEditInfoService.save(sceneEditInfo);
sceneEditInfoExt.setScenePlusId(scenePlus.getId());
sceneEditInfoExt.setEditInfoId(sceneEditInfo.getId());
sceneEditInfoExtService.save(sceneEditInfoExt);
sceneEditControls.setEditInfoId(sceneEditInfo.getId());
sceneEditControlsService.save(sceneEditControls);
//新增场景时,同时新增场景协作信息
if(cooperationUser != null){
SceneCooperation sceneCooperationEntity = new SceneCooperation();
sceneCooperationEntity.setNum(projectNum);
sceneCooperationEntity.setUserId(cooperationUser);
sceneCooperationService.save(sceneCooperationEntity);
List resourceCameraList = sceneResourceCameraService.findListByCameraId(cameraId);
SceneResourceCooperation sceneResourceCooperation = null;
if(resourceCameraList != null && resourceCameraList.size() > 0){
for (SceneResourceCamera sceneResourceCamera : resourceCameraList) {
sceneResourceCooperation = new SceneResourceCooperation();
sceneResourceCooperation.setSceneResourceId(sceneResourceCamera.getSceneResourceId());
sceneResourceCooperation.setSceneCooperationId(sceneCooperationEntity.getId());
sceneResourceCooperationService.save(sceneResourceCooperation);
}
}
}
}else {
ScenePlus oldScene = scenePlusService.getScenePlusByNum(projectNum);
scenePlus.setId(oldScene.getId());
scenePlus.setSceneStatus(0);
scenePlus.setRecStatus(RecStatus.VALID.code());
scenePlus.setPayStatus(0);
scenePlus.setCreateTime(Calendar.getInstance().getTime());
ScenePlusExt oldSceneExt = scenePlusExtService.getScenePlusExtByPlusId(oldScene.getId());
scenePlusExt.setSpace(oldSceneExt.getSpace());
scenePlusExt.setEcs(oldSceneExt.getEcs());
scenePlusExt.setViewCount(oldSceneExt.getViewCount());
if(sceneName!=null) {
scenePlus.setTitle(sceneName);
}
if(sceneType!=null) {
scenePlus.setSceneType(sceneType);
}
scenePlusService.updateById(scenePlus);
scenePlusExtService.updateById(scenePlusExt);
SceneEditInfo oldSceneEditInfo = sceneEditInfoService.getByScenePlusId(oldScene.getId());
SceneEditInfoExt oldSceneEditeIinfoExt = sceneEditInfoExtService.getByEditInfoId(oldSceneEditInfo.getId());
if(StrUtil.isNotBlank(sceneKey)) {
sceneEditInfo.setScenePassword(sceneKey);
sceneEditControls.setShowLock((int) CommonStatus.YES.code());
}else{
sceneEditInfo.setScenePassword("");
sceneEditControls.setShowLock((int)CommonStatus.NO.code());
}
sceneEditInfo.setTitle(scenePlus.getTitle());
sceneEditInfo.setDescription(scenePlus.getDescription());
sceneEditInfo.setId(oldSceneEditInfo.getId());
sceneEditInfo.setScenePlusId(scenePlus.getId());
sceneEditInfo.setFloorLogoSize(100);
sceneEditInfo.setRecStatus(RecStatus.VALID.code());
sceneEditInfo.setFloorPublishVer(oldSceneEditInfo.getFloorEditVer() + 1);
sceneEditInfo.setFloorEditVer(oldSceneEditInfo.getFloorEditVer() + 1);
sceneEditInfo.setVersion(oldSceneEditInfo.getVersion() + 1);
sceneEditInfoService.updateById(sceneEditInfo);
if(Objects.nonNull(oldSceneEditeIinfoExt)){
sceneEditInfoExt.setId(oldSceneEditeIinfoExt.getId());
sceneEditInfoExt.setEditInfoId(sceneEditInfo.getId());
sceneEditInfoExt.setScenePlusId(scenePlus.getId());
sceneEditInfoExtService.updateById(sceneEditInfoExt);
}
}
BeanUtil.copyProperties(scenePlusExt, scenePlusVO);
BeanUtil.copyProperties(scenePlus, scenePlusVO);
return scenePlusVO;
}
public BuildSceneCallMessage getBuildSceneMqMessage(String projectNum,
Long cameraType, String algorithm, Integer resolution,
String buildType, String dataSource) {
BuildSceneCallMessage mqMsg = new BuildSceneCallMessage();
mqMsg.setSceneNum(projectNum);
mqMsg.setCameraType(String.valueOf(cameraType));
mqMsg.setAlgorithm(algorithm);
mqMsg.setResolution(String.valueOf(resolution));
mqMsg.setBuildType(buildType);
mqMsg.setPath(dataSource);
mqMsg.setCreateTime(DateUtil.format(Calendar.getInstance().getTime(), DateExtUtil.dateStyle));
mqMsg.setExt(new HashMap<>());
return mqMsg;
}
@Override
public ResultData rebuildScene(String num,Boolean force) throws IOException {
ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
if(Objects.isNull(scenePlus)){
throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
}
if (scenePlus.getSceneStatus() == 0 && (ObjectUtils.isEmpty(force) || !force)) {
throw new BusinessException(ErrorCode.FAILURE_CODE_5033);
}
ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
String path = scenePlusExt.getDataSource();
Integer sceneSource = scenePlus.getSceneSource();
String buildType = scenePlusExt.getBuildType();
Integer sceneScheme = scenePlusExt.getSceneScheme();
//重新计算时需要删除文件夹,否知使用缓存
FileUtils.delAllFile(path + File.separator + "results");
String dataFdageOssPath = ConstantFilePath.OSS_PREFIX+ path.replace(ConstantFilePath.BUILD_MODEL_PATH, "")
.replace(ConstantFilePath.BUILD_MODEL_LASER_PATH, "") + "/data.fdage";
JSONObject fdageData = JSONObject.parseObject(fYunFileService.getFileContent(dataFdageOssPath));
if(ObjectUtils.isEmpty(fdageData)){
log.error("data.fdage文件不存在");
return ResultData.error(CameraConstant.FAILURE_6009.code(), CameraConstant.FAILURE_6009.message());
}
//重算的场景,先移除该场景对应的容量
scenePlusService.resetSpace(num);
String statusJsonOssPath = String.format(UploadFilePath.DATA_VIEW_PATH, num) + "status.json";
JSONObject statusJson = JSONObject.parseObject(fYunFileService.getFileContent(String.format(UploadFilePath.DATA_VIEW_PATH, num) + "status.json"));
//临时将-2改成1,app还没完全更新
statusJson.put("status", SceneStatus.wait.code());
fYunFileService.uploadFile(statusJson.toJSONString().getBytes(StandardCharsets.UTF_8),statusJsonOssPath);
Long cameraType = (long)sceneScheme == 3 ? 12 : (long)sceneScheme;
//判断是否转台相机
if(sceneSource == 3){
cameraType = 13L;
}
if(sceneSource == 4){
cameraType = 14L;
}
if(sceneSource == 4){
BuildSceneCallMessage buildSceneMqMessage = this.getBuildSceneMqMessage(
num, cameraType,
fdageData.getString("location") != null && "1".equals(fdageData.getString("location")) ? "sfm" : "slam",
fdageData.getInteger("resolution"), buildType, path);
rabbitMqProducer.sendByWorkQueue(queueModelingPre, buildSceneMqMessage);
}else{
BuildSceneCallMessage buildSceneMqMessage = this.getBuildSceneMqMessage(
num, cameraType, fdageData.getString("location") != null && "1".equals(fdageData.getString("location")) ? "sfm" : "slam",
fdageData.getInteger("resolution"), buildType,
path);
rabbitMqProducer.sendByWorkQueue(queueModelingPre, buildSceneMqMessage);
}
scenePlusService.update(new LambdaUpdateWrapper()
.set(ScenePlus::getSceneStatus, SceneStatus.wait.code())
.eq(ScenePlus::getNum, num));
return ResultData.ok();
}
@Override
public ResultData uploadFile(MultipartFile file, String params) throws Exception {
log.info("upload-params: "+params);
if (StringUtils.isEmpty(params)){
throw new BusinessException(ErrorCode.PARAM_REQUIRED);
}
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.info("upload-params解密结果:" + restr);
String[] strArr = restr.split(SPLICE);
if (strArr.length != 6) {
throw new BusinessException(ErrorCode.PARAM_REQUIRED);
}
String mac = strArr[0];
String fileId = strArr[1];
String picNum = strArr[2];
String md5 = strArr[3];
String chunk = strArr[4];
log.info("mac:{},fileId:{},picNum:{},md5:{},chunk:{}", mac, fileId, picNum, md5, chunk);
ResultData result = null;
if (file.isEmpty()){
log.error("文件为空。");
throw new BusinessException(ErrorCode.PARAM_REQUIRED.code(),"文件为空。");
}
if (StringUtils.isEmpty(fileId)){
log.error("文件Id为空。");
throw new BusinessException(ErrorCode.PARAM_REQUIRED.code(),"文件Id为空。");
}
if (picNum == null){
log.error("照片数目为空。");
throw new BusinessException(ErrorCode.PARAM_REQUIRED.code(),"照片数目为空。");
}
if (StringUtils.isEmpty(mac)){
log.error("mac为空。");
throw new BusinessException(ErrorCode.PARAM_REQUIRED.code(),"mac为空。");
}
if (StringUtils.isEmpty(md5)){
log.error("md5为空。");
throw new BusinessException(ErrorCode.PARAM_REQUIRED.code(),"md5为空。");
}
long size = file.getSize();
log.info("mac:{}, fileId:{}, picNum:{}, md5:{}, chunk:{}", mac, fileId, picNum, md5, chunk);
chunk = chunk.split(SPLICE)[0];
// 获取文件名
String fileName = file.getOriginalFilename();
log.info("上传的文件名为:" + fileName);
// 获取文件的后缀名
String folderName = redisUtil.get(String.format(RedisConstants.FILEID_FOLDER_BUILD, fileId));
if(StringUtils.isEmpty(folderName)){
SceneFileBuild fileBuild = findByFileId(fileId);
if(ObjectUtils.isEmpty(fileBuild)){
log.error("数据不正常,fileBuild没找到");
throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
}
folderName = fileBuild.getUnicode();
redisUtil.set(String.format(RedisConstants.FILEID_FOLDER_BUILD, fileId), folderName,2 * 24 * 60 * 60);
}
// 1. 判断该文件是否已经上传过
// 2. 如果已经上传过,判断MD5值和文件大小是否相等。如果相等,更新数据记录。如果不相等,删除该文件,重新上传。
// 3. 如果未上传过,需要上传。
String filePath = mac.concat(File.separator).concat(fileId).concat(File.separator).concat(folderName);
String yunFilePath = LocalConstants.BASE_PATH.concat(fYunFileConfig.getBucket()).concat(File.separator).concat(ConstantFilePath.OSS_PREFIX)
.concat(filePath).concat(File.separator).concat(fileName);
log.info("yunFilePath:{}", yunFilePath);
boolean needUpload = false;
File yunFile = new File(yunFilePath);
if (yunFile.exists()){
String fileMD5 = FileMd5Util.getFileMD5(yunFile);
if (md5.equals(fileMD5) && yunFile.length() == size){
log.info("文件已存在,MD5和文件大小一致。");
SceneFileUpload uploadEntity = sceneFileUploadService.findByFileIdAndChunk(fileId, Integer.valueOf(chunk));
if (uploadEntity != null){
uploadEntity.setSize((int) size);
uploadEntity.setMd5(md5);
uploadEntity.setFilePath(yunFilePath);
uploadEntity.setFileSourceName(fileName);
uploadEntity.setUploadStatus(1);
sceneFileUploadService.updateById(uploadEntity);
}else{
SceneFileUpload sceneFileUploadEntity = new SceneFileUpload();
sceneFileUploadEntity.setSize((int) size);
sceneFileUploadEntity.setMd5(md5);
sceneFileUploadEntity.setFilePath(yunFilePath.toString());
sceneFileUploadEntity.setFileSourceName(fileName);
sceneFileUploadEntity.setUploadStatus(1);
sceneFileUploadEntity.setFileId(fileId);
sceneFileUploadEntity.setChunk(Integer.valueOf(chunk));
sceneFileUploadService.save(sceneFileUploadEntity);
}
result = ResultData.ok();
}else if (!md5.equals(fileMD5)) {
log.error("文件已上传,上传MD5:"+md5+",服务器MD5:"+fileMD5+"。不一致。上传失败");
FileUtils.delFile(yunFilePath.toString());
needUpload = true;
}else if (yunFile.length() != size){
log.error("文件已上传,文件大小不一致。上传失败");
FileUtils.delFile(yunFilePath);
needUpload = true;
}
}else {
log.error("文件不存在,需要重新上传");
needUpload = true;
}
// 4. 上传成功后,校验MD5和文件大小是否相等
// 5. 如果相等,更新数据记录。如果不相等,返回上传失败结果。
try {
if (needUpload){
fYunFileService.uploadFile(file.getInputStream(),ConstantFilePath.OSS_PREFIX.concat(filePath).concat(File.separator).concat(fileName));
File uploadFile = new File(yunFilePath);
String fileMD5 = FileMd5Util.getFileMD5(uploadFile);
SceneFileUpload sceneFileUploadEntity = new SceneFileUpload();
sceneFileUploadEntity.setSize((int) size);
sceneFileUploadEntity.setMd5(md5);
sceneFileUploadEntity.setFilePath(yunFilePath);
sceneFileUploadEntity.setFileSourceName(fileName);
sceneFileUploadEntity.setFileId(fileId);
sceneFileUploadEntity.setChunk(Integer.valueOf(chunk));
if (md5.equals(fileMD5) && uploadFile.length() == size){
log.info("文件已上传,MD5和文件大小一致。上传成功");
sceneFileUploadEntity.setUploadStatus(1);
sceneFileUploadService.save(sceneFileUploadEntity);
result = ResultData.ok();
}else if (!md5.equals(fileMD5)) {
log.error("文件已上传,上传MD5:"+md5+",服务器MD5:"+fileMD5+"。不一致。上传失败");
sceneFileUploadEntity.setUploadStatus(-1);
sceneFileUploadService.save(sceneFileUploadEntity);
result = ResultData.error(ErrorCode.SYSTEM_ERROR,"上传失败, 请重新上传。");
}else if (uploadFile.length() != size){
log.error("文件已上传,文件大小不一致。上传失败");
sceneFileUploadEntity.setUploadStatus(-1);
sceneFileUploadService.save(sceneFileUploadEntity);
result = ResultData.error(ErrorCode.SYSTEM_ERROR,"上传失败, 请重新上传。");
}
}
}catch (IllegalStateException | IOException e) {
log.error("上传失败, 请重新上传,md5:{},chunk:{}", md5, chunk);
log.error("上传失败", e);
result = ResultData.error(ErrorCode.SYSTEM_ERROR,"上传失败, 请重新上传。");
}
return result;
}
@Override
public ResultData sendCallAlgorithm(SendCallAlgorithmParam param) throws Exception {
log.info("sendCallAlgorithm 参数为:{}", JSONObject.toJSONString(param));
String filePath = param.getFilepath();
String details = param.getDetails()
.replace("base64_urlsafe:","")
.replaceAll("-","+")
.replaceAll("_","/")
.concat("==");
try {
details = cn.hutool.core.codec.Base64.decodeStr(details);
}catch (Exception e){
log.error("details解密报错,details:{}", details);
log.error("details解密报错", e);
return ResultData.error(ErrorCode.PARAM_FORMAT_ERROR);
}
SendCallAlgorithmDetail detail = JSON.parseObject(details, SendCallAlgorithmDetail.class);
Integer fileChunkSum = detail.getFileChunkSum();
String uuid = detail.getUuid();
String snCode = uuid.split("_")[0];
String parentPath = sendCallAlgorithmPath.concat(uuid);
// if(FileUtil.exist(parentPath)){
// FileUtil.del(parentPath);
// }
Camera camera = cameraService.getByChildName(snCode);
if(Objects.isNull(camera)){
throw new BusinessException(ErrorCode.CAMERA_BIND_NO_EXIST.code(), "相机未入库");
}
String localFilePath = parentPath.concat(File.separator).concat(uuid).concat(".zip");
try {
String extName = FileUtil.extName(filePath);
String subFilePath = parentPath.concat(File.separator).concat(uuid).concat(".").concat(extName);
FileUtil.mkParentDirs(localFilePath);
HttpUtil.downloadFile(filePath, subFilePath);
}catch (Exception e){
throw new BusinessException(ErrorCode.FAILURE_CODE_5063.code(), "原始资源压缩包下载失败");
}
//检测压缩包分卷是否与detail中的总数一样
List fileNames = FileUtil.listFileNames(parentPath);
if(fileNames.size() != fileChunkSum){
return ResultData.ok("压缩包分卷不完整,请继续上传剩余的分卷");
}
if(!FileUtil.exist(localFilePath)){
throw new BusinessException(ErrorCode.FAILURE_CODE_5063.code(), "zip压缩包不存在");
}
ScenePre scenePre = new ScenePre();
scenePre.setZipPath(parentPath);
scenePre.setCreateTime(new Date());
scenePre.setUpdateTime(new Date());
scenePre.setStatus(0);
scenePreService.save(scenePre);
// 异步解压资源文件上传
ExecutorService executor = ThreadUtil.newSingleExecutor();
try {
CompletableFuture.runAsync(() -> {
try {
log.info("开始异步解压文件");
ZipFile zipFile = new ZipFile(new File(localFilePath));
if (zipFile.isEncrypted()) {
zipFile.setPassword(zipPassword);
zipFile.extractAll(parentPath);
} else {
ZipUtil.unzip(localFilePath, parentPath);
}
List filePathList = FileUtils.list(new File(parentPath));
String configJsonPath = null;
for (String item : filePathList) {
if(!item.contains("config.json")){
continue;
}
configJsonPath = item;
}
String dataPath = FileUtil.getParent(configJsonPath, 1);
// 读取本地文件并校验文件
// 读取config.json
log.info("config.json路径:{}", configJsonPath);
if(!FileUtil.exist(configJsonPath)){
throw new RuntimeException("config.json 文件有误!");
}
JSONObject configJson = JSONObject.parseObject(FileUtils.readFile(configJsonPath));
String folderName = configJson.getString("id");
String customUserId = configJson.getString("customUserId");
if(StrUtil.isBlank(folderName) || StrUtil.isBlank(snCode)){
throw new RuntimeException("config.json 文件有误!");
}
// 检测是否有生成
String fileId = getFileIdByFolderName(folderName);
String subFolder = snCode.concat(File.separator).concat(fileId).concat(File.separator).concat(folderName);
// 解压获取dataSource 并上传资源到OSS
String dataSource = ConstantFilePath.BUILD_MODEL_PATH.concat(subFolder);
log.info("dataSource 为:{}", dataSource);
scenePre.setFileId(fileId);
scenePre.setStatus(1);
scenePre.setUpdateTime(new Date());
scenePreService.updateById(scenePre);
log.info("异步开始上传文件");
// 上传oaas
fYunFileService.uploadFileByCommand(dataPath, ConstantFilePath.OSS_PREFIX.concat(subFolder));
//删除本地压缩包,防止补拍上传文件不一致
FileUtil.del(parentPath);
scenePre.setOssPath(ConstantFilePath.OSS_PREFIX.concat(subFolder));
scenePre.setStatus(2);
scenePre.setUpdateTime(new Date());
scenePreService.updateById(scenePre);
log.info("文件上传成功,开始通知计算");
// 通知计算
this.copyDataAndBuild(null, dataSource, "V4", null, customUserId);
log.info("通知计算成功");
scenePre.setStatus(3);
scenePre.setUpdateTime(new Date());
scenePreService.updateById(scenePre);
} catch (Exception e) {
log.error("上传失败", e);
scenePre.setStatus(CommonSuccessStatus.Fail.code());
scenePreService.updateById(scenePre);
}
}, executor);
}finally {
executor.shutdown();
}
return ResultData.ok();
}
public static void main(String[] args) {
String details = "{\"camType\":\"kj\",\"uploadType\":\"log\",\"uuid\":\"90d95cdb5_202211141023024060\",\"fileChunkSum\":4,\"fileChunkNum\":0}";
String encode = cn.hutool.core.codec.Base64.encode(details);
System.out.println(encode);
String details2 = "base64_urlsafe:".concat(encode.replaceAll("\\+", "-").replaceAll("/", "_").replaceAll("=", ""));
System.out.println(details2);
String details3 = details2.replace("base64_urlsafe:","").replaceAll("-","+").replaceAll("_","/");//.concat("==");
System.out.println(details3);
String s = cn.hutool.core.codec.Base64.decodeStr(details3);
System.out.println(s);
}
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 = this.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);
}
String 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)) {
fileId = new SnowflakeIdGenerator(0, 0).nextId() + "";
log.info("新生成build数据,{}", fileId);
}
sceneFileBuild = new SceneFileBuild();
sceneFileBuild.setChildName(folderName.split("_")[0]);
sceneFileBuild.setFileId(fileId);
sceneFileBuild.setRecStatus("A");
sceneFileBuild.setUnicode(folderName);
sceneFileBuild.setCreateTime(new Date());
this.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;
}
public ResultData copyDataAndBuild(String sourceBucet,String dataSource,String sceneVer,User user, String customUserId) throws Exception {
if(!StringUtils.equals(sceneVer,"V3") && ! StringUtils.equals(sceneVer,"V4")){
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);
}
// 下载data.fdage
JSONObject fdageData = JSONObject.parseObject(fYunFileService.getFileContent(fYunPath + "/data.fdage"));
if(ObjectUtils.isEmpty(fdageData)){
throw new BusinessException(ErrorCode.SYSTEM_ERROR.code(),"4dage 文件不存在");
}
String cameraName = fdageData.getJSONObject("cam").getString("uuid");
Camera cameraEntity = cameraService.getByChildName(cameraName);
if(cameraEntity == null){
log.error("该相机不存在:" + cameraName);
throw new BusinessException(ErrorCode.FAILURE_CODE_6003);
}
CameraDetail detailEntity = cameraDetailService.getByCameraId(cameraEntity.getId());
if(detailEntity == null){
log.error("该相机详情不存在:" + cameraName);
throw new BusinessException(ErrorCode.FAILURE_CODE_6003);
}
Long cameraType = 11L;
//判断是否转台相机
if (detailEntity.getType() == 9) {
cameraType = 13L;
}
if (detailEntity.getType() == 10) {
cameraType = 14L;
}
String sceneNum = scene3dNumService.generateSceneNum(detailEntity.getType());
String icon = null;
String imgViewPath = null;
switch (sceneVer) {
case "V3":
case "V4":
int rebuild = 0;
ScenePlus scenePlus = scenePlusService.getByFileId(dataSource);
if (!ObjectUtils.isEmpty(scenePlus)) {
log.info("该场景资源已存在,执行补拍逻辑!");
rebuild = 1;
sceneNum = scenePlus.getNum();
}
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, cameraEntity, detailEntity, rebuild, icon, user, customUserId);
break;
}
Map result = new HashMap<>();
result.put("code",sceneNum);
return ResultData.ok(result);
}
private ScenePlusVO buildScenePost(String dataSource, JSONObject jsonObject, String buildType, long cameraType,
String sceneNum, Camera camera, CameraDetail cameraDetail, int rebuild,String icon,User user, String customUserId) throws Exception {
String localDataPath = String.format(ConstantFilePath.DATABUFFER_FORMAT, sceneNum);
String imgViewPath = String.format(UploadFilePath.IMG_VIEW_PATH, sceneNum);
String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, sceneNum);
JSONObject firmwareVersion = new JSONObject();
if (!ObjectUtils.isEmpty(jsonObject.getString("camSoftwareVersion"))) {
firmwareVersion.put("camSoftwareVersion", jsonObject.getString("camSoftwareVersion"));
}
if (!ObjectUtils.isEmpty(jsonObject.getString("version"))) {
firmwareVersion.put("version", jsonObject.getString("version"));
}
String sceneUrl = "/" + sceneProNewUrl;
//重算的场景,先移除该场景对应的容量
if (rebuild == 1) {
scenePlusService.resetSpace(sceneNum);
//删除oss的houst_floor.json(国际版可能会卡住)
fYunFileService.deleteFile(dataViewPath + "houst_floor.json");
} else {
//上传log-main.png
fYunFileService.uploadFile(ConstantFilePath.LOGO_PATH + "logo-main.png", imgViewPath + "logo-main.png");
fYunFileService.uploadFile(ConstantFilePath.LOGO_PATH + "logo-main-en.png", imgViewPath + "logo-main-en.png");
}
String algorithm = jsonObject.getString("location") != null && "1".equals(jsonObject.getString("location")) ? "sfm" : "slam";
String unicode = jsonObject.getString("creator") + "_" + jsonObject.getString("uuidtime");
ScenePlusVO scenePlusVO = this.createScenePlus(sceneNum, camera.getId(), camera.getChildName(), jsonObject.getString("creator"),
jsonObject.getString("pwd"), unicode, cameraType, dataSource, icon, cameraDetail.getUserId() , null, algorithm,
jsonObject.getJSONArray("points").size(), jsonObject.getString("name"), jsonObject.getString("info"),
jsonObject.getInteger("scenetype"), jsonObject.getString("gps"), rebuild,
jsonObject.getInteger("resolution"), firmwareVersion.toString(), sceneUrl, buildType, cameraDetail.getCooperationUser());
if (Objects.nonNull(scenePlusVO)) {
JSONObject statusJson = new JSONObject();
//临时将-2改成1,app还没完全更新
statusJson.put("status", scenePlusVO.getSceneStatus() == -2 ? 1 : scenePlusVO.getSceneStatus());
statusJson.put("webSite", scenePlusVO.getWebSite());
statusJson.put("sceneNum", scenePlusVO.getNum());
statusJson.put("thumb", scenePlusVO.getThumb());
statusJson.put("payStatus", 0);
statusJson.put("recStatus", 'A');
FileUtils.writeFile(localDataPath + "status.json", statusJson.toString());
fYunFileService.uploadFile(localDataPath + "status.json", dataViewPath + "status.json");
}
BuildSceneCallMessage mqMessage = getBuildSceneMqMessage(sceneNum, cameraType, algorithm, jsonObject.getInteger("resolution"), buildType,
scenePlusVO.getDataSource());
if (cameraDetail.getCompanyId() != null) {
Company company = companyService.getById(cameraDetail.getCompanyId());
if (company != null && !ObjectUtils.isEmpty(company.getCalculateFlexibility()) && !company.getCalculateFlexibility()) {
mqMessage.setFlexibility(-1);
}
}
mqMessage.getExt().put("deleteExtras", true);
mqMessage.getExt().put("customUserId", customUserId);
mqMessage.getExt().put("gps", jsonObject.getString("gps"));
rabbitMqProducer.sendByWorkQueue(queueModelingPre, mqMessage);
return scenePlusVO;
}
}