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.extra.qrcode.QrCodeUtil; import cn.hutool.extra.qrcode.QrConfig; 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.FileUtils; import com.fdkankan.common.util.SnowflakeIdGenerator; import com.fdkankan.contro.constant.RedisConstants; import com.fdkankan.contro.entity.*; import com.fdkankan.contro.enums.CameraTypeEnum; import com.fdkankan.contro.mapper.ISceneFileBuildMapper; import com.fdkankan.contro.service.ICommonService; import com.fdkankan.contro.service.*; import com.fdkankan.contro.vo.ResponseSceneFile; import com.fdkankan.contro.vo.ScenePlusVO; import com.fdkankan.fyun.config.FYunFileConfig; import com.fdkankan.fyun.face.FYunFileServiceInterface; import com.fdkankan.image.MatrixToImageWriterUtil; import com.fdkankan.model.constants.ConstantFilePath; import com.fdkankan.model.constants.UploadFilePath; import com.fdkankan.model.utils.SceneUtil; 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; import com.fdkankan.web.response.ResultData; import com.fdkankan.web.util.RSAEncrypt; import lombok.extern.slf4j.Slf4j; import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.StringUtils; import org.joda.time.DateTime; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.http.*; import org.springframework.stereotype.Service; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.util.ObjectUtils; import org.springframework.web.client.RestTemplate; import javax.annotation.Resource; 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; /** *

* 场景文件建模表 服务实现类 *

* * @author dengsixing * @since 2021-12-23 */ @RefreshScope @Slf4j @Service public class SceneFileBuildServiceImpl extends ServiceImpl implements ISceneFileBuildService { private static final String SPLICE = "#"; @Value("${main.url}") private String mainUrl; @Value("${scene.pro.new.url}") private String sceneProNewUrl; @Value("${scene.pro.v3.url}") private String sceneProV3Url; @Value("${queue.modeling.modeling-pre}") private String queueModelingPre; @Value("${queue.modeling.v3.modeling-pre}") private String queueV3ModelingPre; @Value("${queue.modeling.intermit.modeling-pre}") private String queueIntermitModelingPre; @Value("${queue.modeling.liguang.modeling-pre:liguang-modeling-pre}") private String queueLiguangModelingPre; @Value("${v3.controlUrl:#{null}}") private String v3controlUrl; @Value("${model.modelKind:3dtiles}") private String modelKind; @Value("#{'${model.3dtiles.sceneSource:}'.split(',')}") private List sdTilesSceneSourceList; @Value("#{'${camType.laser:}'.split(',')}") private List laserCamTypeList; @Value("${build.notSupport.beforeTime:202203}") private String jgNotSupportBuildTime; @Autowired private RedisUtil redisUtil; @Autowired private IScenePlusExtService scenePlusExtService; @Autowired private IScene3dNumService scene3dNumService; @Autowired private IScenePlusService scenePlusService; @Autowired private RabbitMqProducer rabbitMqProducer; @Autowired private ISceneProEditService sceneProEditService; @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 ICompanyService companyService; @Resource private FYunFileServiceInterface fYunFileService; @Autowired private FYunFileConfig fYunFileConfig; @Autowired private ISceneProService sceneProService; @Autowired private IFdkkLaserService fdkkLaserService; @Autowired private RedisLockUtil redisLockUtil; private RestTemplate restTemplate = new RestTemplate(); @Autowired private ISceneCopyDistinctEnvService sceneCopyDistinctEnvService; @Autowired private ISceneCopyLogService sceneCopyLogService; @Autowired private ISceneCleanOrigService sceneCleanOrigService; @Autowired private ICommonService commonService; @Autowired private IExceedSpaceSceneService exceedSpaceSceneService; @Autowired private ISceneColdStorageLogService sceneColdStorageLogService; @Autowired private ISceneColdStorageService sceneColdStorageService; @Autowired private IntermitSceneService intermitSceneService; @Autowired private ISceneRebuildLogService sceneRebuildLogService; @Autowired private ISceneUploadCountService sceneUploadCountService; @Autowired private IWbService wbService; @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 (StrUtil.isEmpty(fileId)) { SceneFileBuild sceneFileBuild = this.findByUnicode(folderName); if (sceneFileBuild != null) { fileId = sceneFileBuild.getFileId(); } } if(StrUtil.isNotEmpty(fileId)){ //校验目录是否被上锁,如果上锁,抛出错误(避免删除原始资源定时任务执行过程中,有场景补拍重新上传) String homePath = redisUtil.get(String.format(RedisKey.SCENE_OSS_HOME_DIR_DELETE, folderName)); if(StrUtil.isNotEmpty(homePath)){ throw new BusinessException(ErrorCode.FAILURE_CODE_5073); } //如果原始资源目录不是正在被定时任务删除中,就加上上传锁,并正常返回 homePath = ConstantFilePath.OSS_PREFIX.concat(mac).concat("/").concat(fileId).concat("/").concat(folderName); redisUtil.set(String.format(RedisKey.SCENE_OSS_HOME_DIR_UPLOAD, folderName), homePath, RedisKey.CAMERA_EXPIRE_7_TIME); responseSceneFile.setFileId(fileId); redisUtil.set(String.format(RedisConstants.FOLDER_FILEID_BUILD, folderName), fileId, 2 * 24 * 60 * 60); return responseSceneFile; } // 加锁 boolean lock = redisLockUtil.lock(String.format(RedisConstants.FOLDER_LOCK_BUILD, folderName), 120); if (!lock) { throw new BusinessException(ErrorCode.FAILURE_CODE_5052); } // 查找场景表 LambdaQueryWrapper proWrapper = new LambdaQueryWrapper<>(); proWrapper.like(ScenePro::getDataSource, "/" + folderName); ScenePro pro = sceneProService.getOne(proWrapper); String dataSource = null; if (!ObjectUtils.isEmpty(pro)) { dataSource = pro.getDataSource(); } else { dataSource = scenePlusService.getDataSourceLikeUnicode("/" + folderName); } if (StrUtil.isNotEmpty(dataSource)) { log.info("从数据库中查到与 fileId:{} 匹配的路径为:{}", fileId, dataSource); int n = dataSource.split("/").length; if (n > 1) { fileId = dataSource.split("/")[n - 2]; } } if (StrUtil.isEmpty(fileId)) { fileId = new SnowflakeIdGenerator(0, 0).nextId() + ""; log.info("新生成build数据,{}", fileId); } SceneFileBuild sceneFileBuild = new SceneFileBuild(); sceneFileBuild.setChildName(mac); sceneFileBuild.setFileId(fileId); sceneFileBuild.setRecStatus("A"); sceneFileBuild.setUnicode(folderName); sceneFileBuild.setTotalPicNum(Integer.valueOf(totalPicNum)); sceneFileBuild.setChunks(Integer.valueOf(chunks)); 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); 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 = CommonStatus.YES.code(); if (ObjectUtils.isEmpty(scenePlus)) { //清除超容量场景记录 exceedSpaceSceneService.repeal(camera.getId(), fileId, unicode); sceneNum = scene3dNumService.generateSceneNum(cameraDetail.getType()); rebuild = CommonStatus.NO.code(); } else { sceneNum = scenePlus.getNum(); sceneCopyLogService.checkCanBuild(sceneNum); //看看相机固件有bug,会重复发两次计算请求,所以这里判断,如果是看看场景,需要判断场景是否在计算中,如果是,直接返回成功 if (cameraType == 10L && 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); } //如果是相机计算容量的模式是场景个数模式,则需要拦截计算 //文保系统v1.5.0增加需求,文保vr场景默认不封存(条件companyI=26&&location=7) if(rebuild == CommonStatus.NO.code() && !commonService.checkIsSpVr(jsonObject, cameraDetail)){//新场景需要校验容量是否超出限制 boolean exceedSpace = exceedSpaceSceneService.cehckExceedSpace(sceneNum, cameraDetail, cameraName, fileId, unicode); if(exceedSpace){ ScenePlusVO scenePlusVO = new ScenePlusVO(); scenePlusVO.setNum(sceneNum); scenePlusVO.setSceneStatus(SceneStatus.EXCEED_SPACE.code()); return scenePlusVO; } } 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 imgViewPath = String.format(UploadFilePath.IMG_VIEW_PATH, sceneNum); 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成功...."); } return buildScenePost(dataSource, jsonObject, buildType, cameraType, sceneNum, cameraDetail, rebuild,icon); } private ScenePlusVO buildScenePost(String dataSource, JSONObject jsonObject, String buildType, long cameraType, String sceneNum, CameraDetail cameraDetail, int rebuild,String icon) throws Exception { String imgViewPath = String.format(UploadFilePath.IMG_VIEW_PATH, sceneNum); String userName = null; if (!ObjectUtils.isEmpty(cameraDetail.getUserId())) { SSOUser user = userService.getSSOUserByUserId(cameraDetail.getUserId()); userName = ObjectUtils.isEmpty(user) ? null : user.getUserName(); } 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 = mainUrl + "/" + sceneProNewUrl; //重算的场景,先移除该场景对应的容量 if (rebuild == 1) { scenePlusService.resetSpace(sceneNum); } 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, cameraDetail.getCameraId(), jsonObject.getString("creator"), jsonObject.getString("pwd"),cameraType, jsonObject.getJSONObject("cam").getIntValue("type"), dataSource, icon, cameraDetail.getUserId(), userName,algorithm,jsonObject.getInteger("location"), 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()); //上传app状态文件 commonService.uploadStatusJson(sceneNum, scenePlusVO.getSceneStatus(), scenePlusVO.getWebSite(),scenePlusVO.getThumb(),PayStatus.NOT_PAY.code(), String.format(UploadFilePath.DATA_VIEW_PATH, sceneNum)); BuildSceneCallMessage mqMessage = getBuildSceneMqMessage(sceneNum, cameraType, algorithm, jsonObject, 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("keepTitle", 0); if(jsonObject.getIntValue("location") == 7){ //发送到全景看看进行初始化 intermitSceneService.sendMq(scenePlusVO.getNum(), jsonObject, CommonSuccessStatus.WAITING.code()); rabbitMqProducer.sendByWorkQueue(queueIntermitModelingPre, mqMessage); }else{ //如果是四普的看见相机场景,也需要推送全景vr if(cameraType == 13 && Objects.nonNull(cameraDetail.getCompanyId()) && cameraDetail.getCompanyId() == 26){ wbService.sendMq(sceneNum, CommonSuccessStatus.WAITING.code()); } rabbitMqProducer.sendByWorkQueue(queueModelingPre, mqMessage); } return scenePlusVO; } public ScenePlusVO buildV3Scene(ScenePro scenePro,String fileId, String prefix,JSONObject jsonObject,String buildType,long cameraType) throws Exception{ sceneCopyLogService.checkCanBuild(scenePro.getNum()); //调用createScene方法生成scene数据和加入算法队列 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); } String sceneNum = scenePro.getNum(); if (scenePro.getStatus().equals(SceneStatus.wait.code())) { log.info(scenePro.getNum() + ":场景处于计算中,不能再计算"); return null; } String localDataPath = String.format(ConstantFilePath.DATABUFFER_FORMAT, sceneNum); String imgViewPath = String.format(ConstantFilePath.IMAGE_PATH_FORMAT, sceneNum); String dataViewPath = String.format(ConstantFilePath.DATA_PATH_FORMAT, 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")); } //删除oss的houst_floor.json(国际版可能会卡住) fYunFileService.deleteFile(dataViewPath + "houst_floor.json"); String algorithm = jsonObject.getString("location") != null && "1".equals(jsonObject.getString("location")) ? "sfm" : "slam"; ScenePlusVO scenePlusVO = this.createScenePro(sceneNum, camera.getId(), camera.getChildName(), jsonObject.getString("creator"), jsonObject.getString("pwd"), unicode,cameraType, fileId, icon, cameraDetail.getUserId(), userName,algorithm, jsonObject.getJSONArray("points").size(), jsonObject.getString("name"), jsonObject.getString("info"), jsonObject.getInteger("scenetype"), jsonObject.getString("gps"), jsonObject.getInteger("resolution"), firmwareVersion.toString(), buildType); //上传场景状态文件 commonService.uploadStatusJson(sceneNum, scenePlusVO.getSceneStatus(), scenePlusVO.getWebSite(),scenePlusVO.getThumb(),PayStatus.NOT_PAY.code(), String.format(ConstantFilePath.DATA_PATH_FORMAT, sceneNum)); BuildSceneCallMessage mqMessage = getBuildSceneMqMessage(sceneNum, cameraType, algorithm, jsonObject, buildType, scenePlusVO.getDataSource()); if (cameraDetail.getCompanyId() != null) { Company company = companyService.getById(cameraDetail.getCompanyId()); if (company != null) { log.info("复制企业logo"); SceneProEdit sceneEditInfo = sceneProEditService.getByProId(scenePlusVO.getId()); if (StrUtil.isNotEmpty(company.getTopLogo())) { fYunFileService.copyFileInBucket(company.getTopLogo(),imgViewPath + "logo-main.png"); } if (StrUtil.isNotEmpty(company.getFloorLogo())) { fYunFileService.copyFileInBucket(company.getFloorLogo(),imgViewPath + "floorLogoImg.png"); sceneEditInfo.setFloorLogo("user"); } if (StrUtil.isNotEmpty(company.getQrLogo())) { createQrCode(sceneNum,scenePlusVO.getWebSite(),company.getQrLogo()); } sceneProEditService.updateById(sceneEditInfo); if (!ObjectUtils.isEmpty(company.getCalculateFlexibility()) && !company.getCalculateFlexibility()) { mqMessage.setFlexibility(-1); } } } rabbitMqProducer.sendByWorkQueue(queueV3ModelingPre, mqMessage); return scenePlusVO; } private void createQrCode(String num, String url, String qrLogo) { String localLogoPath = null; if (!org.apache.commons.lang3.ObjectUtils.isEmpty(qrLogo)) { try { localLogoPath = ConstantFilePath.AGENT_PATH + qrLogo.substring(qrLogo.lastIndexOf("//") + 1); HttpUtil.downloadFile(qrLogo, localLogoPath); } catch (Exception e) { log.error("公司logo下载失败:{}", qrLogo); localLogoPath = null; } } //生成二维码 String outPathZh = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+ num +".png"; String outPathEn = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+ num +"_en.png"; QrConfig qrConfig = QrConfig.create(); qrConfig.setWidth(512); qrConfig.setHeight(512); if(!org.apache.commons.lang3.ObjectUtils.isEmpty(localLogoPath)){ qrConfig.setImg(localLogoPath); } QrCodeUtil.generate(url, qrConfig, FileUtil.file(outPathZh)); QrCodeUtil.generate(url + "&lang=en", qrConfig, FileUtil.file(outPathEn)); //上传二维码 fYunFileService.uploadFile(outPathZh, String.format(UploadFilePath.DOWNLOADS_QRCODE, num) + num + ".png"); fYunFileService.uploadFile(outPathEn, String.format(UploadFilePath.DOWNLOADS_QRCODE, num) + num + "_en.png"); if(!org.apache.commons.lang3.ObjectUtils.isEmpty(localLogoPath)){ FileUtils.deleteFile(localLogoPath); } } @Override public ResultData uploadSuccessBuild(String params) throws Exception { log.info("uploadSuccessBuild-params: " + params); String preParams = 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); } sceneUploadCountService.resetCountByUuid(folderName); StringBuilder prefixBuffer = new StringBuilder(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator); String buildType = "V2"; Long cameraType = 10L; if(!fYunFileService.fileExist(ConstantFilePath.OSS_PREFIX + prefixBuffer + "data.fdage")){ log.error("data.fdage文件不存在"); throw new BusinessException(CameraConstant.FAILURE_6009); } 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; } } this.removeUpdateV4(ConstantFilePath.OSS_PREFIX + prefixBuffer + "data.fdage", fdageJson); // 判断是否是V3的场景 ScenePro scenePro = sceneProService.getOne( new LambdaQueryWrapper().like(ScenePro::getDataSource, "/".concat(fileId).concat("/"))); boolean callV3 = callV3(scenePro, preParams, fdageJson, "api/scene/file/uploadSuccessBuild"); if(callV3) return ResultData.ok(); if (ObjectUtils.isEmpty(scenePro) || (!ObjectUtils.isEmpty(scenePro.getIsUpgrade()) && scenePro.getIsUpgrade() == 1)) { buildScene(fileId, prefixBuffer.toString(),fdageJson,buildType,cameraType); }else{ buildV3Scene(scenePro,fileId, prefixBuffer.toString(),fdageJson,buildType,cameraType); } return ResultData.ok(); } private void removeUpdateV4(String dataFdagePath, JSONObject fdageJson){ Integer updateV4 = fdageJson.getInteger("updateV4"); if(Objects.isNull(updateV4) || updateV4 == 0){ return; } fdageJson.put("updateV4", CommonStatus.NO.code()); fYunFileService.uploadFile(fdageJson.toJSONString().getBytes(StandardCharsets.UTF_8), dataFdagePath); } private boolean callV3(ScenePro scenePro, String preParams, JSONObject fdageJson,String api) throws Exception { //复制出来的场景不支持补拍上传 if(Objects.nonNull(scenePro)){ sceneCopyLogService.checkCanBuild(scenePro.getNum()); } String cameraName = fdageJson.getJSONObject("cam").getString("uuid"); 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); } // 判断是否是正顺|火调|普通v3的场景,如果是正顺|火调|普通v3的场景,则发送到原来的系统进行计算 if (!ObjectUtils.isEmpty(cameraDetail.getCompanyId())) { Company company = companyService.getById(cameraDetail.getCompanyId()); if(ObjectUtils.isEmpty(company)){ log.error("企业配置有误:" + cameraName); throw new BusinessException(CameraConstant.FAILURE_6003); } if (!ObjectUtils.isEmpty(company.getSceneVersion()) && company.getSceneVersion().equals("V3")) { //如果是app重新上传,需要解冻结 if(Objects.nonNull(scenePro)){ sceneColdStorageService.unfreeze(scenePro.getNum(), "用户相机重新全量上传", scenePro.getDataSource()); } callV3Service(preParams, api); return Boolean.TRUE; } } // TODO: 2023/1/12 3dtiles临时上激光场景 // else if (Objects.nonNull(scenePro) && // scenePro.getSceneSource() != SceneSource.JG.code() && // scenePro.getIsUpgrade() == CommonStatus.NO.code().intValue()){ // callV3Service(preParams,api); // return Boolean.TRUE; // } return Boolean.FALSE; } public void callV3Service(String params,String api) throws Exception { log.info("params:{}", params); if(ObjectUtils.isEmpty(v3controlUrl)){ log.error("未配置V3服务器!"); throw new Exception("未配置V3服务器!"); } HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.MULTIPART_FORM_DATA); MultiValueMap paramMap = new LinkedMultiValueMap(); paramMap.add("params",params); HttpEntity formEntity = new HttpEntity<>(paramMap,headers); ResponseEntity responseEntity = restTemplate.postForEntity(v3controlUrl+api, formEntity, Result.class); if (responseEntity.getStatusCode().value() != HttpStatus.OK.value() || responseEntity.getBody().getCode() != ServerCode.SUCCESS.code()) { log.error("正顺场景请求V3服务器失败, params:{}, result:{}",params, JSON.toJSONString(responseEntity)); throw new BusinessException(ErrorCode.SYSTEM_BUSY); } log.info("正顺场景请求V3服务器成功!"); } @Override public ResultData turntableUploadSuccess(String params) throws Exception { log.info("turntableUploadSuccess-params: " + params); String preParams = 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); } sceneUploadCountService.resetCountByUuid(folderName); //云目录 StringBuilder prefixBuffer = new StringBuilder(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator); if(!fYunFileService.fileExist(ConstantFilePath.OSS_PREFIX + prefixBuffer + "data.fdage")){ log.error("data.fdage文件不存在"); throw new BusinessException(CameraConstant.FAILURE_6009); } 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); } this.removeUpdateV4(ConstantFilePath.OSS_PREFIX + prefixBuffer + "data.fdage", fdageJson); String buildType = "V3"; //13表示转台 Long cameraType = 13L; //激光相机10 13 int camType = fdageJson.getJSONObject("cam").getIntValue("type"); log.info("camType:{}", camType); if(laserCamTypeList.contains(camType)){ //激光转台 cameraType = 14L; } // 判断是否是V3的场景 ScenePro scenePro = sceneProService.getOne( new LambdaQueryWrapper().like(ScenePro::getDataSource, "/".concat(fileId).concat("/"))); boolean callV3 = callV3(scenePro, preParams, fdageJson, "api/scene/file/turntableUploadSuccess"); if (callV3) return ResultData.ok(); //激光场景校验是否能够计算 this.checkJgCanBuild(scenePro); ScenePlusVO scenePlusVO = null; if (ObjectUtils.isEmpty(scenePro) || (!ObjectUtils.isEmpty(scenePro.getIsUpgrade()) && scenePro.getIsUpgrade() == 1)) { scenePlusVO = buildScene(fileId, prefixBuffer.toString(), fdageJson, buildType, cameraType); } else { scenePlusVO = buildV3Scene(scenePro,fileId, prefixBuffer.toString(), fdageJson, buildType, cameraType); } if(ObjectUtils.isEmpty(scenePlusVO) || scenePlusVO.getSceneStatus() == SceneStatus.EXCEED_SPACE.code()){ return ResultData.ok(); } // 通知激光场景系统开始构建场景 if(cameraType.longValue() == 14 && fdageJson.getIntValue("location") != 7){ ScenePlus scenePlus = scenePlusService.getScenePlusByNum(scenePlusVO.getNum()); Long sceneUserId = scenePlus.getUserId(); String userName = null; if(!ObjectUtils.isEmpty(sceneUserId)){ userName = userService.getSSOUserByUserId(sceneUserId).getUserName(); } //判断 是否为激光相机 Camera camera = cameraService.getByChildName(mac); if(Objects.nonNull(scenePlus)){ fdkkLaserService.saveScene(scenePlus,fdageJson,camera,userName,false, scenePlus.getPayStatus()); }else{ fdkkLaserService.saveScene(scenePro,fdageJson.getString("pwd"),camera,userName,false, scenePro.getPayStatus()); } } return ResultData.ok(); } @Override public ResultData reverseScene(JSONObject params) throws Exception { String title = params.getString("title"); Long userId = params.getLong("userId"); String otherType = params.getString("otherType");//AZ String path = params.getString("path"); Long sourceId = params.getLong("sourceId"); Integer isObj = params.getIntValue("isObj"); String buildType = "V3"; String num = scene3dNumService.generateSceneNum(null); ScenePlus scenePlus = new ScenePlus(); ScenePlusExt scenePlusExt = new ScenePlusExt(); SceneEditInfo sceneEditInfo = new SceneEditInfo(); SceneEditInfoExt sceneEditInfoExt = new SceneEditInfoExt(); SceneEditControls sceneEditControls = new SceneEditControls(); scenePlus.setTitle(title); scenePlus.setUserId(userId); scenePlus.setPayStatus(PayStatus.PAY.code()); scenePlus.setSceneStatus(CommonOperStatus.WAITING.code()); scenePlus.setOtherType(otherType); scenePlus.setSourceId(sourceId); if("AZ".equals(otherType)){ num = "AZ-" + num; scenePlus.setSceneSource(SceneSource.ZT.code()); scenePlusExt.setSceneFrom(SceneFrom.MINION.code()); scenePlusExt.setModelKind(ModelKind.DAM.code()); }else{ num = "e57-" + num; scenePlus.setSceneSource(57); scenePlusExt.setSceneFrom(SceneFrom.LASER.code()); scenePlusExt.setModelKind(ModelKind.THREE_D_TILE.code()); } params.put("num", num); SSOUser user = userService.getSSOUserByUserId(userId); scenePlus.setNum(num); scenePlus.setCreateTime(new Date()); scenePlusService.save(scenePlus); StringBuilder prefixBuffer = new StringBuilder(ConstantFilePath.BUILD_MODEL_PATH).append("reverseScene/").append(UUID.randomUUID()); scenePlusExt.setSceneKind(SceneKind.TILES.code()); scenePlusExt.setSceneResolution(SceneResolution.four_K.code()); scenePlusExt.setBuildType(buildType); scenePlusExt.setLocation(4); scenePlusExt.setSceneScheme(SceneScheme.FOUR_K.code()); scenePlusExt.setPlusId(scenePlus.getId()); scenePlusExt.setDataSource(prefixBuffer.toString()); scenePlusExt.setIsObj(isObj); scenePlusExt.setThumb(ConstantUrl.DEFAULT_SCENE_PIC); scenePlusExtService.save(scenePlusExt); sceneEditInfo.setTitle(title); sceneEditInfo.setScenePlusId(scenePlus.getId()); sceneEditInfoService.save(sceneEditInfo); sceneEditInfoExt.setScenePlusId(scenePlus.getId()); sceneEditInfoExt.setEditInfoId(sceneEditInfo.getId()); sceneEditInfoExtService.save(sceneEditInfoExt); sceneEditControls.setEditInfoId(sceneEditInfo.getId()); sceneEditControlsService.save(sceneEditControls); if("AZ".equals(otherType)){ rabbitMqProducer.sendByWorkQueue("reverse-scene", params); }else{ fdkkLaserService.sendE57ToLaser(scenePlus, scenePlusExt, null); rabbitMqProducer.sendByWorkQueue("reverseE57-modeling-pre", params); } return ResultData.ok(); } public ScenePlusVO createScenePlus(String projectNum, Long cameraId, String phoneId, String sceneKey, Long cameraType, int camType, String dataSource, String pic, Long userId, String userName, String algorithm, Integer location, 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(SceneSource.BM.code()); scenePlusExt.setDataSource(dataSource); scenePlusExt.setLocation(location); if (sceneName != null) { scenePlus.setTitle(sceneName); scenePlus.setLaserTitle(sceneName); } if(resolution == null || resolution.intValue() == 0){ scenePlusExt.setSceneScheme(cameraType.intValue()); }else { scenePlusExt.setSceneScheme(SceneScheme.BM.code()); } //转台相机用4k图 if(cameraType.longValue() == 13){ scenePlus.setSceneSource(SceneSource.ZT.code()); scenePlusExt.setSceneScheme(SceneScheme.FOUR_K.code()); } //激光相机 if(cameraType.longValue() == 14){ scenePlus.setSceneSource(SceneSource.JG.code()); scenePlusExt.setSceneScheme(SceneScheme.FOUR_K.code()); if(camType == CameraTypeEnum.LASER_SG.getType()){ scenePlus.setSceneSource(SceneSource.SG.code()); } } //全景看看场景用相机类型包括 看看 看见 深时 深光,所以这里做一个统一处理,为了让场景不在各平台中显示出来 if(Objects.nonNull(location) && location == 7){ scenePlus.setSceneSource(SceneSource.QJKK.code()); } if(ModelKind.THREE_D_TILE.code().equals(modelKind) && CollUtil.isNotEmpty(sdTilesSceneSourceList) && sdTilesSceneSourceList.contains(scenePlus.getSceneSource())){ scenePlusExt.setModelKind(modelKind); } if (pic != null && pic.length() > 5) { scenePlusExt.setThumb(pic); } else { scenePlusExt.setThumb(ConstantUrl.DEFAULT_SCENE_PIC); } scenePlusExt.setThumb(scenePlusExt.getThumb().concat("?t=") + System.currentTimeMillis()); if (!ObjectUtils.isEmpty(userName)) { scenePlus.setUserId(userId); } if (sceneShootCount == null) { scenePlusExt.setShootCount(0); } else { scenePlusExt.setShootCount(sceneShootCount); } 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.setEditInfoId(sceneEditInfo.getId()); sceneEditInfoExt.setScenePlusId(scenePlus.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(SceneStatus.wait.code()); scenePlus.setRecStatus(RecStatus.VALID.code()); scenePlus.setPayStatus(PayStatus.NOT_PAY.code()); scenePlus.setCreateTime(Calendar.getInstance().getTime()); ScenePlusExt oldSceneExt = scenePlusExtService.getScenePlusExtByPlusId(oldScene.getId()); scenePlusExt.setSpace(oldSceneExt.getSpace()); scenePlusExt.setEcs(oldSceneExt.getEcs()); scenePlusExt.setViewCount(oldSceneExt.getViewCount()); if(sceneType!=null) { scenePlus.setSceneType(sceneType); } scenePlusService.updateById(scenePlus); scenePlusExtService.updateById(scenePlusExt); SceneEditInfo oldSceneEditInfo = sceneEditInfoService.getByScenePlusId(oldScene.getId()); SceneEditInfoExt oldSceneEditeIinfoExt = sceneEditInfoExtService.getByEditInfoId(oldSceneEditInfo.getId()); 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.saveOrUpdate(sceneEditInfoExt); } BeanUtil.copyProperties(scenePlusExt, scenePlusVO); BeanUtil.copyProperties(scenePlus, scenePlusVO); return scenePlusVO; } public ScenePlusVO createScenePro(String projectNum, Long cameraId, String cameraName, String phoneId, String sceneKey, String unicode, Long cameraType, String fileId, String pic, Long userId, String userName, String algorithm, Integer sceneShootCount, String sceneName,String sceneDec, Integer sceneType, String gps,Integer resolution, String firmwareVersion, String buildType )throws Exception{ ScenePro scene = sceneProService.getByNum(projectNum); SceneProEdit sceneEdit = sceneProEditService.getByProId(scene.getId()); scene.setCameraId(cameraId); scene.setPhoneId(phoneId); scene.setNum(projectNum); scene.setSpace(0L); if (pic != null && pic.length() > 5) { scene.setThumb(pic); } else { scene.setThumb(ConstantUrl.DEFAULT_SCENE_PIC); } scene.setThumb(scene.getThumb().concat("?t=") + System.currentTimeMillis()); if (!ObjectUtils.isEmpty(userName)) { scene.setUserId(userId); } if (sceneShootCount == null) { scene.setShootCount(0); } else { scene.setShootCount(sceneShootCount); } if (sceneName != null) { scene.setSceneName(sceneName); } if (sceneDec != null) { scene.setSceneDec("

" + new String(sceneDec.getBytes("UTF-8")) + "

"); } if (sceneType != null) { scene.setSceneType(sceneType); } if (gps != null && !gps.trim().equals("")) { scene.setGps(gps); } scene.setAlgorithm(algorithm); if(!org.springframework.util.StringUtils.isEmpty(firmwareVersion)){ scene.setFirmwareVersion(firmwareVersion); } scene.setBuildType(buildType); log.info("场景记录添加到数据库:"+projectNum); scene.setStatus(0); scene.setPayStatus(0); scene.setRecStatus("A"); scene.setCreateTime(new Date()); if (sceneName != null) { scene.setSceneName(sceneName); } if (sceneType != null) { scene.setSceneType(sceneType); } sceneProService.updateById(scene); sceneEdit.setNeedKey(0); if (cameraType.longValue() != 14 && !ObjectUtils.isEmpty(sceneKey)) { sceneEdit.setNeedKey(1); sceneEdit.setSceneKey(sceneKey); } sceneEdit.setProId(scene.getId()); sceneEdit.setMapVisi(1); sceneEdit.setTourVisi(1); sceneEdit.setVrVisi(1); sceneEdit.setCadImgVisi(1); sceneEdit.setPanoVisi(1); sceneEdit.setOverlay(null); sceneEdit.setM2dVisi(1); sceneEdit.setPlayData(null); sceneEdit.setFloorLogo("0"); sceneEdit.setM3dVisi(1); sceneEdit.setJumpScene(false); sceneEdit.setMeasureVisi(0); sceneEdit.setFloorLogoSize(100); sceneEdit.setUpdateTime(new Date()); sceneEdit.setRecStatus("A"); sceneEdit.setFloorPublishVer(sceneEdit.getFloorEditVer() + 1); sceneEdit.setFloorEditVer(sceneEdit.getFloorEditVer() + 1); sceneEdit.setVersion(sceneEdit.getVersion() + 1); sceneEdit.setImagesVersion(sceneEdit.getImagesVersion() + 1); sceneProEditService.updateById(sceneEdit); JSONObject scenejson = JSONObject.parseObject(JSONObject.toJSONString(scene)); scenejson.put("thumbImg", 0); scenejson.put("version", sceneEdit.getVersion()); scenejson.put("floorLogo", 0); if(!ObjectUtils.isEmpty(sceneKey)){ scenejson.put("sceneKey", sceneKey); scenejson.put("public", 1); }else{ scenejson.put("sceneKey", ""); scenejson.put("public", 0); } if(cameraType.longValue() < 4 || cameraType.longValue() == 5 || cameraType.longValue() == 6){ scenejson.put("visions", 1); }else { scenejson.put("visions", 2); } scenejson.put("createTime", new DateTime(new Date()).toString("yyyy-MM-dd HH:mm")); scenejson.put("floorPublishVer", sceneEdit.getFloorPublishVer()); scenejson.put("floorEditVer", sceneEdit.getFloorEditVer()); scenejson.put("rulerVisi", sceneEdit.getRulerVisi()); scenejson.put("entry", null); if(!org.springframework.util.StringUtils.isEmpty(sceneEdit.getHotsIds())){ scenejson.put("hots", 1); } File file = new File(ConstantFilePath.SCENE_PATH+"data/data"+projectNum); if(!file.exists()||!file.isDirectory()) { file.mkdirs(); } FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data/data"+projectNum+File.separator+"scene.json", scenejson.toString()); //生成二维码 MatrixToImageWriterUtil.createQRCode(scene.getWebSite(), ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+projectNum+".png",false, null); MatrixToImageWriterUtil.createQRCode(scene.getWebSite() + "&lang=en", ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+projectNum+"_en.png",false, null); log.info("二维码生成完成"); ScenePlusVO scenePlusVO = new ScenePlusVO(); scenePlusVO.setSceneStatus(scene.getStatus()); scenePlusVO.setThumb(scene.getThumb()); scenePlusVO.setPayStatus(scene.getPayStatus()); scenePlusVO.setId(scene.getId()); scenePlusVO.setNum(scene.getNum()); scenePlusVO.setWebSite(scene.getWebSite()); scenePlusVO.setDataSource(scene.getDataSource()); return scenePlusVO; } public BuildSceneCallMessage getBuildSceneMqMessage(String projectNum, Long cameraType, String algorithm, JSONObject fdageJson, String buildType, String dataSource) { BuildSceneCallMessage mqMsg = new BuildSceneCallMessage(); mqMsg.setSceneNum(projectNum); mqMsg.setCameraType(String.valueOf(cameraType)); mqMsg.setAlgorithm(algorithm); mqMsg.setResolution(String.valueOf(fdageJson.getInteger("resolution"))); mqMsg.setBuildType(buildType); mqMsg.setPath(dataSource); mqMsg.setCreateTime(DateUtil.format(Calendar.getInstance().getTime(), DateExtUtil.dateStyle)); Map ext = new HashMap<>(); ext.put("location", fdageJson.getInteger("location")); mqMsg.setExt(ext); return mqMsg; } @Override public ResultData rebuildScene(String num,Boolean force,Boolean deleteExtras, String from) throws IOException { ScenePro scenePro = sceneProService.getByNum(num); ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num); //复制出来的场景不支持重算 List sceneCopyLogs = sceneCopyLogService. listByNewNum(num); if(CollUtil.isNotEmpty(sceneCopyLogs)){ throw new BusinessException(ErrorCode.FAILURE_CODE_5071); } //已删除原始资源的场景不支持重算 Date laseCallTime = null; ScenePlusExt scenePlusExt = null; if(Objects.nonNull(scenePlus)){ scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId()); laseCallTime = scenePlusExt.getAlgorithmTime(); }else{ laseCallTime = scenePro.getCreateTime(); } //查询场景是否处于冻结状态,如果已冻结,不允许重算 SceneColdStorage sceneColdStorage = sceneColdStorageService.getOne(new LambdaQueryWrapper().eq(SceneColdStorage::getNum, num).eq(SceneColdStorage::getState, 1)); if(Objects.nonNull(sceneColdStorage)){ throw new BusinessException(ErrorCode.FAILURE_CODE_5074); } //查询最后一次计算时间后是否有删除过目录,如果有,则不支持重算 List sceneCleanOrigs = sceneCleanOrigService.lisByNumAfterLastCall(num, laseCallTime); if(CollUtil.isNotEmpty(sceneCleanOrigs)){ throw new BusinessException(ErrorCode.FAILURE_CODE_5072); } //激光场景校验是否能够计算 this.checkJgCanBuild(scenePro); if(Objects.nonNull(scenePro) && (Objects.isNull(scenePro.getIsUpgrade()) || scenePro.getIsUpgrade() != CommonStatus.YES.code().intValue())){ return rebuildV3Scene(scenePro,num,force); } 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); } String path = scenePlusExt.getDataSource(); String buildType = scenePlusExt.getBuildType(); 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")); if(ObjectUtils.isEmpty(statusJson)){ statusJson = new JSONObject(); } //临时将-2改成1,app还没完全更新 statusJson.put("status", SceneStatus.wait.code()); fYunFileService.uploadFile(statusJson.toJSONString().getBytes(StandardCharsets.UTF_8),statusJsonOssPath); CameraDetail cameraDetail = cameraDetailService.getByCameraId(scenePlus.getCameraId()); Long cameraType = 10L;//默认看看 if(cameraDetail.getType() == 9){//看见 cameraType = 13L; } if(cameraDetail.getType() == 10 || cameraDetail.getType() == 11){//深时、深光 cameraType = 14L; } BuildSceneCallMessage message = null; if(cameraType == 14){ String userName = null; Long sceneUserId = scenePlus.getUserId(); if (!ObjectUtils.isEmpty(sceneUserId)) { SSOUser user = userService.getSSOUserByUserId(sceneUserId); userName = user.getUserName(); } Camera cameraEntity = cameraService.getById(scenePlus.getCameraId()); if(Objects.isNull(scenePlusExt.getLocation()) || scenePlusExt.getLocation() != 7){ fdkkLaserService.saveScene(scenePlus,null,cameraEntity,userName,true, scenePlus.getPayStatus()); } message = this.getBuildSceneMqMessage( num, cameraType, fdageData.getString("location") != null && "1".equals(fdageData.getString("location")) ? "sfm" : "slam", fdageData, buildType, path); }else{ message = this.getBuildSceneMqMessage( num, cameraType, fdageData.getString("location") != null && "1".equals(fdageData.getString("location")) ? "sfm" : "slam", fdageData, buildType, path); } if(deleteExtras){ message.getExt().put("deleteExtras",deleteExtras); } if (force) { message.setRebuild("1"); } message.getExt().put("keepTitle", 1); String ossOrignPath = commonService.getOssOrignPath(path); String ossPath = fYunFileService.getFileContent(ossOrignPath + "custom.txt"); if(StrUtil.isNotEmpty(ossPath) && ossPath.contains("MKT862")){ JSONObject jsonObject = new JSONObject(); jsonObject.put("location", 4); BuildSceneCallMessage mqMessage = getBuildSceneMqMessage(num, 13L, null, jsonObject, "V3", path); mqMessage.getExt().put("deleteExtras", deleteExtras); mqMessage.getExt().put("ossPath", ossPath); //故宫博物馆需求,特殊算法参数 mqMessage.getExt().put("splitType", "SPLIT_V3"); mqMessage.getExt().put("skyboxType", "SKYBOX_V6"); rabbitMqProducer.sendByWorkQueue(queueLiguangModelingPre, mqMessage); }else{ if(Objects.nonNull(scenePlusExt.getLocation()) && scenePlusExt.getLocation() == 7){ //发送到全景看看进行初始化 JSONObject jsonObject = JSONObject.parseObject(fYunFileService.getFileContent(SceneUtil.getHomePath(scenePlusExt.getDataSource()) + "data.fdage")); intermitSceneService.sendMq(num, jsonObject, CommonSuccessStatus.WAITING.code()); rabbitMqProducer.sendByWorkQueue(queueIntermitModelingPre, message); }else{ wbService.sendMq(num, CommonSuccessStatus.WAITING.code()); rabbitMqProducer.sendByWorkQueue(queueModelingPre, message); } } scenePlusService.update(new LambdaUpdateWrapper() .set(ScenePlus::getSceneStatus, SceneStatus.wait.code()) .eq(ScenePlus::getNum, num)); if(ModelKind.THREE_D_TILE.code().equals(modelKind) && CollUtil.isNotEmpty(sdTilesSceneSourceList) && sdTilesSceneSourceList.contains(scenePlus.getSceneSource())){ scenePlusExt.setModelKind(modelKind); } scenePlusExtService.updateById(scenePlusExt); //记录日志表 SceneRebuildLog rebuildLog = new SceneRebuildLog(); rebuildLog.setNum(num); rebuildLog.setSource(from); sceneRebuildLogService.save(rebuildLog); return ResultData.ok(); } @Override public ResultData rebuildSceneE57(String num,Boolean force,Boolean deleteExtras, String from) 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()); //复制出来的场景不支持重算 List sceneCopyLogs = sceneCopyLogService. listByNewNum(num); if(CollUtil.isNotEmpty(sceneCopyLogs)){ throw new BusinessException(ErrorCode.FAILURE_CODE_5071); } //查询场景是否处于冻结状态,如果已冻结,不允许重算 SceneColdStorage sceneColdStorage = sceneColdStorageService.getOne(new LambdaQueryWrapper().eq(SceneColdStorage::getNum, num).eq(SceneColdStorage::getState, 1)); if(Objects.nonNull(sceneColdStorage)){ throw new BusinessException(ErrorCode.FAILURE_CODE_5074); } String path = scenePlusExt.getDataSource(); String buildType = scenePlusExt.getBuildType(); String e57FileKey = SceneUtil.getHomePath(path) + "input.e57"; if(!fYunFileService.fileExist(e57FileKey)){ return ResultData.error(ErrorCode.FAILURE_CODE_5074); } //重算的场景,先移除该场景对应的容量 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")); if(ObjectUtils.isEmpty(statusJson)){ statusJson = new JSONObject(); } //临时将-2改成1,app还没完全更新 statusJson.put("status", SceneStatus.wait.code()); fYunFileService.uploadFile(statusJson.toJSONString().getBytes(StandardCharsets.UTF_8),statusJsonOssPath); scenePlusService.update(new LambdaUpdateWrapper() .set(ScenePlus::getSceneStatus, SceneStatus.wait.code()) .eq(ScenePlus::getNum, num)); HashMap params = new HashMap<>(); params.put("num", num); params.put("rebuild", 1); params.put("deleteExtras", deleteExtras); fdkkLaserService.sendRebuildE57ToLaser(scenePlus, scenePlusExt); rabbitMqProducer.sendByWorkQueue("reverseE57-modeling-pre", params); //记录日志表 SceneRebuildLog rebuildLog = new SceneRebuildLog(); rebuildLog.setNum(num); rebuildLog.setSource(from); sceneRebuildLogService.save(rebuildLog); return ResultData.ok(); } /** * 由于算法不支持2022年三月份前的激光场景计算,这里需要校验是否是能计算,不能就退出重算 * @return */ private void checkJgCanBuild(ScenePro scenePro){ if(Objects.isNull(scenePro) || StrUtil.isEmpty(scenePro.getDataSource()) || !SceneSource.JG.code().equals(scenePro.getSceneSource())){ return; } cn.hutool.core.date.DateTime limitTime = DateExtUtil.parse(jgNotSupportBuildTime, DateExtUtil.dateStyle10); String dataSource = scenePro.getDataSource(); String sceneDateTimeStr = dataSource.substring(dataSource.lastIndexOf("_") + 1).substring(0, 6); //如果截取的时间串是空的,无法判断时间,就退出,正常走计算逻辑 if(StrUtil.isEmpty(sceneDateTimeStr)){ return; } cn.hutool.core.date.DateTime sceneDateTime = null; try{ sceneDateTime = DateExtUtil.parse(sceneDateTimeStr, DateExtUtil.dateStyle10); if(Objects.isNull(sceneDateTime)){ return; } }catch (Exception e){ //如果截取的时间串转换日期错误,无法判断时间,退出函数 return; } if(sceneDateTime.before(limitTime)){ throw new BusinessException(ErrorCode.FAILURE_CODE_5067); } } public ResultData rebuildV3Scene(ScenePro scenePro,String num,Boolean force) throws IOException { if (scenePro.getStatus() == 0 && (ObjectUtils.isEmpty(force) || !force)) { throw new BusinessException(ErrorCode.FAILURE_CODE_5033); } String path = scenePro.getDataSource(); Integer sceneSource = scenePro.getSceneSource(); String buildType = scenePro.getBuildType(); Integer sceneScheme = scenePro.getSceneScheme(); 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()); } String statusJsonOssPath = String.format(ConstantFilePath.DATA_PATH_FORMAT, num) + "status.json"; JSONObject statusJson = JSONObject.parseObject(fYunFileService.getFileContent(statusJsonOssPath)); if (ObjectUtils.isEmpty(statusJson)) { statusJson = new JSONObject(); } //临时将-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) { String userName = null; Long sceneUserId = scenePro.getUserId(); if (!ObjectUtils.isEmpty(sceneUserId)) { SSOUser user = userService.getSSOUserByUserId(sceneUserId); userName = user.getUserName(); } Camera cameraEntity = cameraService.getById(scenePro.getCameraId()); fdkkLaserService.saveScene(scenePro, null, cameraEntity, userName, true, scenePro.getPayStatus()); } BuildSceneCallMessage buildSceneMqMessage = this.getBuildSceneMqMessage( num, cameraType, fdageData.getString("location") != null && "1".equals(fdageData.getString("location")) ? "sfm" : "slam", fdageData, buildType, path); rabbitMqProducer.sendByWorkQueue(queueV3ModelingPre, buildSceneMqMessage); //重算的场景,先移除该场景对应的容量 sceneProService.update(new LambdaUpdateWrapper() .set(ScenePro::getStatus, SceneStatus.wait.code()) .set(ScenePro::getSpace,0) .eq(ScenePro::getNum, num)); return ResultData.ok(); } @Override 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); // } // 下载data.fdage JSONObject fdageData = JSONObject.parseObject(fYunFileService.getFileContent(sourceBucet, 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){ throw new BusinessException(ErrorCode.FAILURE_CODE_6003); } CameraDetail detailEntity = cameraDetailService.getByCameraId(cameraEntity.getId()); if(detailEntity == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_6003); } // 拷贝资源至新的资源路径 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("/")); String newFYunPath = ConstantFilePath.OSS_PREFIX + newDataSource.replace(ConstantFilePath.BUILD_MODEL_PATH, "") .replace(ConstantFilePath.BUILD_MODEL_LASER_PATH, ""); List pros = sceneProService.list(new LambdaQueryWrapper().eq(ScenePro::getDataSource, newDataSource)); if (CollUtil.isNotEmpty(pros)) { return ResultData.error(ErrorCode.PARAM_ERROR.code(),newDataSource + "已存在,请勿重复添加!"); } List plusExts = scenePlusExtService.list(new LambdaQueryWrapper().eq(ScenePlusExt::getDataSource, newDataSource)); if (CollUtil.isNotEmpty(plusExts)) { return ResultData.error(ErrorCode.PARAM_ERROR.code(),newDataSource + "已存在,请勿重复添加!"); } List newFyunFileList = fYunFileService.listRemoteFiles(newFYunPath); if(CollUtil.isNotEmpty(newFyunFileList)){ return ResultData.error(ErrorCode.PARAM_ERROR.code(),newFYunPath + "已存在,请勿重复添加!"); } String sceneNum = scene3dNumService.generateSceneNum(detailEntity.getType()); //写入日志表 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; } if (CollUtil.isNotEmpty(laserCamTypeList) && laserCamTypeList.contains(detailEntity.getType())) { cameraType = 14L; } 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, cameraEntity, userName, false, 0); } break; } }catch (Exception e){ log.error("复制场景异常", e); } }, executor).whenComplete((reslut, e) -> { log.info("复制场景souceDataSource:{},newDataSource:{}结束-{}",dataSource,newDataSource, new Date()); }); }catch (Exception e){ log.error("线程错误:{}",e); }finally { executor.shutdown(); } Map result = new HashMap<>(); result.put("code",sceneNum); result.put("newDataSource",newDataSource); return ResultData.ok(result); } private void buildV3Scene2(String dataSource,JSONObject jsonObject,long cameraType,String sceneNum,Camera cameraEntity,CameraDetail detailEntity,String icon) throws Exception { String cameraName = jsonObject.getJSONObject("cam").getString("uuid"); log.info("查询相机:" + cameraName); String userName = null; if(detailEntity.getUserId() != null){ SSOUser user = userService.getSSOUserByUserId(detailEntity.getUserId()); userName = user.getUserName(); } JSONObject firmwareVersion = new JSONObject(); if(jsonObject.containsKey("camSoftwareVersion") && StringUtils.isNotEmpty(jsonObject.getString("camSoftwareVersion"))){ firmwareVersion.put("camSoftwareVersion", jsonObject.getString("camSoftwareVersion")); } if(jsonObject.containsKey("version") && StringUtils.isNotEmpty(jsonObject.getString("version"))){ firmwareVersion.put("version", jsonObject.getString("version")); } String buildType = "V3"; String sceneUrl = mainUrl + "/" + sceneProV3Url; boolean isObj = jsonObject.containsKey("exportMeshObj") && jsonObject.getIntValue("exportMeshObj") == 1; ScenePro scenePro = createScenePro(sceneNum, detailEntity.getCameraId(), jsonObject.getString("creator"), jsonObject.getString("pwd"), cameraType, dataSource, "", icon, detailEntity.getUserId(), userName, jsonObject.getString("location") != null && "1".equals(jsonObject.getString("location")) ? "sfm" : "slam", jsonObject.getJSONArray("points").size(), jsonObject.getString("name"), jsonObject.getString("info"), jsonObject.getInteger("scenetype"), jsonObject.getString("gps"), 0, jsonObject.getInteger("resolution"), firmwareVersion.toString(), sceneUrl, buildType, detailEntity.getCooperationUser(), isObj); // 通知激光场景系统开始构建场景 if(cameraType == 14){ scenePro.setStatus(0); fdkkLaserService.saveScene(scenePro, jsonObject.getString("pwd"), cameraEntity, userName, false, scenePro.getPayStatus()); } BuildSceneCallMessage buildSceneMqMessage = this.getBuildSceneMqMessage( sceneNum, cameraType, jsonObject.getString("location") != null && "1".equals(jsonObject.getString("location")) ? "sfm" : "slam", jsonObject, buildType, dataSource); rabbitMqProducer.sendByWorkQueue(queueV3ModelingPre, buildSceneMqMessage); } public ScenePro createScenePro(String projectNum, Long cameraId, String phoneId, String sceneKey, Long cameraType, String dataSource, String imgsName, 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,Boolean isObj) throws Exception { ScenePro scene; SceneProEdit sceneEdit; if (type == 0) { scene = new ScenePro(); sceneEdit = new SceneProEdit(); } else { scene = sceneProService.getByNum(projectNum); sceneEdit = sceneProEditService.getByProId(scene.getId()); } //先返回链接地址 scene.setWebSite(url + projectNum); scene.setCameraId(cameraId); scene.setPhoneId(phoneId); scene.setNum(projectNum); scene.setSceneSource(1); scene.setDataSource(dataSource); if (cameraType.longValue() == 5 || cameraType.longValue() == 6) { //场景来源双目相机 scene.setSceneSource(2); } if (resolution == null || resolution.intValue() == 0) { scene.setSceneScheme(cameraType.intValue()); } else { scene.setSceneScheme(4); } //场景来源双目相机,sceneScheme为4,加载high,low图 if (cameraType.longValue() == 5 || cameraType.longValue() == 6) { scene.setSceneScheme(4); } //转台相机用4k图 if (cameraType.longValue() == 13) { scene.setSceneSource(3); scene.setSceneScheme(10); } //激光相机 if (cameraType.longValue() == 14) { scene.setSceneSource(4); scene.setSceneScheme(10); } if (pic != null && pic.length() > 5) { scene.setThumb(pic); } else { scene.setThumb(ConstantUrl.DEFAULT_SCENE_PIC); } scene.setThumb(scene.getThumb().concat("?t=") + System.currentTimeMillis()); if (!ObjectUtils.isEmpty(userName)) { scene.setUserId(userId); } if (sceneShootCount == null) { scene.setShootCount(0); } else { scene.setShootCount(sceneShootCount); } if (sceneName != null) { scene.setSceneName(sceneName); } if (sceneDec != null) { scene.setSceneDec("

" + new String(sceneDec.getBytes("UTF-8")) + "

"); } if (sceneType != null) { scene.setSceneType(sceneType); } if (gps != null && !gps.trim().equals("")) { scene.setGps(gps); } scene.setAlgorithm(algorithm); scene.setFilesName(imgsName); if (!org.springframework.util.StringUtils.isEmpty(firmwareVersion)) { scene.setFirmwareVersion(firmwareVersion); } scene.setBuildType(buildType); log.info("场景记录添加到数据库:" + projectNum); //type=0为新生成场景,其余为重新计算场景 if (type == 0) { scene.setIsObj(ObjectUtils.isEmpty(isObj) || !isObj ? 0 : 1); sceneProService.save(scene); sceneEdit = new SceneProEdit(); sceneEdit.setNeedKey(0); if (sceneKey == null) { sceneKey = ""; } sceneEdit.setSceneKey(sceneKey); if (!sceneKey.equals("")) { sceneEdit.setNeedKey(1); } else { sceneEdit.setNeedKey(0); } sceneEdit.setProId(scene.getId()); sceneEdit.setMapVisi(1); sceneEdit.setTourVisi(1); sceneEdit.setVrVisi(1); sceneEdit.setRulerVisi(0); sceneEdit.setCadImgVisi(1); sceneEdit.setPanoVisi(1); sceneEdit.setM2dVisi(1); sceneEdit.setM3dVisi(1); sceneEdit.setMeasureVisi(0); sceneEdit.setFloorLogoSize(100); sceneEdit.setCreateTime(new Date()); sceneProEditService.save(sceneEdit); //新增场景时,同时新增场景协作信息 if (cooperationUser != null) { SceneCooperation sceneCooperationEntity = new SceneCooperation(); sceneCooperationEntity.setNum(projectNum); sceneCooperationEntity.setUserId(cooperationUser); sceneCooperationService.save(sceneCooperationEntity); List resourceCameraList = sceneResourceCameraService.findListByCameraId(cameraId); SceneResourceCooperation sceneResourceCooperationEntity = null; if (resourceCameraList != null && resourceCameraList.size() > 0) { for (SceneResourceCamera sceneResourceCameraEntity : resourceCameraList) { sceneResourceCooperationEntity = new SceneResourceCooperation(); sceneResourceCooperationEntity.setSceneResourceId(sceneResourceCameraEntity.getSceneResourceId()); sceneResourceCooperationEntity.setSceneCooperationId(sceneCooperationEntity.getId()); sceneResourceCooperationService.save(sceneResourceCooperationEntity); } } } } else { scene.setStatus(0); scene.setPayStatus(0); scene.setRecStatus("A"); scene.setCreateTime(new Date()); if (sceneName != null) { scene.setSceneName(sceneName); } if (sceneType != null) { scene.setSceneType(sceneType); } sceneProService.updateById(scene); sceneEdit.setNeedKey(0); if (cameraType.longValue() != 14 && !ObjectUtils.isEmpty(sceneKey)) { sceneEdit.setNeedKey(1); sceneEdit.setSceneKey(sceneKey); } sceneEdit.setProId(scene.getId()); sceneEdit.setMapVisi(1); sceneEdit.setTourVisi(1); sceneEdit.setVrVisi(1); sceneEdit.setCadImgVisi(1); sceneEdit.setPanoVisi(1); sceneEdit.setOverlay(null); sceneEdit.setM2dVisi(1); sceneEdit.setPlayData(null); sceneEdit.setFloorLogo("0"); sceneEdit.setM3dVisi(1); sceneEdit.setJumpScene(false); sceneEdit.setMeasureVisi(0); sceneEdit.setFloorLogoSize(100); sceneEdit.setUpdateTime(new Date()); sceneEdit.setRecStatus("A"); sceneEdit.setFloorPublishVer(sceneEdit.getFloorEditVer() + 1); sceneEdit.setFloorEditVer(sceneEdit.getFloorEditVer() + 1); sceneEdit.setVersion(sceneEdit.getVersion() + 1); sceneEdit.setImagesVersion(sceneEdit.getImagesVersion() + 1); sceneProEditService.updateById(sceneEdit); } JSONObject scenejson = JSONObject.parseObject(JSONObject.toJSONString(scene)); scenejson.put("thumbImg", 0); scenejson.put("version", sceneEdit.getVersion()); scenejson.put("floorLogo", 0); if (!ObjectUtils.isEmpty(sceneKey)) { scenejson.put("sceneKey", sceneKey); scenejson.put("public", 1); } else { scenejson.put("sceneKey", ""); scenejson.put("public", 0); } if (cameraType.longValue() < 4 || cameraType.longValue() == 5 || cameraType.longValue() == 6) { scenejson.put("visions", 1); } else { scenejson.put("visions", 2); } scenejson.put("createTime", new DateTime(new Date()).toString("yyyy-MM-dd HH:mm")); scenejson.put("floorPublishVer", sceneEdit.getFloorPublishVer()); scenejson.put("floorEditVer", sceneEdit.getFloorEditVer()); scenejson.put("rulerVisi", sceneEdit.getRulerVisi()); scenejson.put("entry", null); if (!org.springframework.util.StringUtils.isEmpty(sceneEdit.getHotsIds())) { scenejson.put("hots", 1); } File file = new File(ConstantFilePath.SCENE_PATH + "data/data" + projectNum); if (!file.exists() || !file.isDirectory()) { file.mkdirs(); } FileUtils.writeFile(ConstantFilePath.SCENE_PATH + "data/data" + projectNum + File.separator + "scene.json", scenejson.toString()); return scene; } private ResultData rebuildV3SceneToMini(ScenePro scenePro){ log.info("v3场景重算,请求v3服务器,url:{}",v3controlUrl+"api/scene/rebuildScene?num=" + scenePro.getNum()); ResponseEntity responseEntity = restTemplate.getForEntity(v3controlUrl+"api/scene/rebuildScene?num=" + scenePro.getNum(), Result.class); if (responseEntity.getStatusCode().value() != HttpStatus.OK.value() || responseEntity.getBody().getCode() != ServerCode.SUCCESS.code()) { log.error("请求V3服务器重算场景失败, num:{}, result:{}",scenePro.getNum(), JSON.toJSONString(responseEntity)); throw new BusinessException(ErrorCode.SYSTEM_BUSY); } log.info("v3场景重算,请求v3服务器,url:{}, result",v3controlUrl+"api/scene/rebuildScene?num=" + scenePro.getNum(), JSON.toJSONString(responseEntity)); return ResultData.ok(); } @Override public ResultData uploadLiguang(String num, String snCode, String ossPath) throws Exception { if(StrUtil.isEmpty(ossPath)){ return ResultData.error(-1, "资源路径不能为空"); } if(!StrUtil.endWith(ossPath, "/")){ ossPath = ossPath + "/"; } if(StrUtil.isEmpty(num) && StrUtil.isEmpty(snCode)){ return ResultData.error(-1, "场景码或者相机码不能同时为空"); } String fileId = null, unicode = null; String dataSource = null; String[] arr = null; ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num); ScenePlusExt scenePlusExt = null; SceneEditInfo sceneEditInfo = null; SceneEditInfoExt sceneEditInfoExt = null; SceneEditControls sceneEditControls = null; if(Objects.nonNull(scenePlus)){ scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId()); sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId()); sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfo.getId()); sceneEditControls = sceneEditControlsService.getBySceneEditId(sceneEditInfo.getId()); dataSource = scenePlusExt.getDataSource(); arr = dataSource.replace(ConstantFilePath.BUILD_MODEL_PATH, "").split("/"); fileId = arr[1]; unicode = arr[2]; snCode = arr[0]; }else{ //生成场景码 num = scene3dNumService.generateSceneNum(CameraTypeEnum.DOUBLE_EYE_TURN.getType()); } Camera camera = cameraService.getBySnCode(snCode); CameraDetail cameraDetail = cameraDetailService.getByCameraId(camera.getId()); //生成unicode if(StrUtil.isEmpty(unicode)){ unicode = snCode + "_" + DateUtil.format(new Date(), "yyyyMMddHHmmss"); } //生成fileid if (StrUtil.isEmpty(fileId)) { fileId = new SnowflakeIdGenerator(0, 0).nextId() + ""; SceneFileBuild sceneFileBuild = new SceneFileBuild(); sceneFileBuild.setChildName(snCode); sceneFileBuild.setFileId(fileId); sceneFileBuild.setUnicode(unicode); sceneFileBuild.setTotalPicNum(0); sceneFileBuild.setChunks(0); sceneFileBuild.setCreateTime(new Date()); this.save(sceneFileBuild); } dataSource = ConstantFilePath.BUILD_MODEL_PATH + snCode + "/" + fileId + "/" + unicode; String dataFdageStr = fYunFileService.getFileContent(ossPath + "data.fdage"); JSONObject dataFdage = JSON.parseObject(dataFdageStr); String name = dataFdage.getString("name"); //生成主表 if(Objects.isNull(scenePlus)){ scenePlus = new ScenePlus(); scenePlus.setNum(num); scenePlus.setDescription("

四维看看 让空间讲故事

"); scenePlus.setUserId(cameraDetail.getUserId()); scenePlus.setPhoneId(snCode); scenePlus.setTitle(name); scenePlus.setSceneStatus(SceneStatus.wait.code()); scenePlus.setSceneSource(SceneSource.ZT.code()); scenePlus.setPayStatus(PayStatus.PAY.code()); scenePlus.setSceneType(SceneType.OTHER.code()); scenePlus.setCameraId(camera.getId()); } scenePlusService.saveOrUpdate(scenePlus); if(Objects.isNull(scenePlusExt)){ scenePlusExt = new ScenePlusExt(); scenePlusExt.setPlusId(scenePlus.getId()); scenePlusExt.setDataSource(dataSource); scenePlusExt.setWebSite(mainUrl + "/smg.html?m=" + num); scenePlusExt.setThumb(ConstantUrl.DEFAULT_SCENE_PIC); scenePlusExt.setSceneScheme(SceneScheme.FOUR_K.code()); scenePlusExt.setSceneResolution(SceneResolution.four_K.code()); scenePlusExt.setSceneFrom(SceneFrom.MINION.code()); scenePlusExt.setSceneKind(SceneKind.TILES.code()); scenePlusExt.setModelKind(ModelKind.DAM.code()); scenePlusExt.setYunFileBucket(fYunFileConfig.getBucket()); scenePlusExt.setLocation(4); scenePlusExt.setBuildType("V3"); } scenePlusExtService.saveOrUpdate(scenePlusExt); //生成编辑表 if(Objects.isNull(sceneEditInfo)){ sceneEditInfo = new SceneEditInfo(); sceneEditInfo.setScenePlusId(scenePlus.getId()); sceneEditInfo.setTitle(name); sceneEditInfo.setDescription(scenePlus.getDescription()); } sceneEditInfoService.saveOrUpdate(sceneEditInfo); if(Objects.isNull(sceneEditInfoExt)){ sceneEditInfoExt = new SceneEditInfoExt(); sceneEditInfoExt.setScenePlusId(scenePlus.getId()); sceneEditInfoExt.setEditInfoId(sceneEditInfo.getId()); } sceneEditInfoExtService.saveOrUpdate(sceneEditInfoExt); //生成控制表 if(Objects.isNull(sceneEditControls)){ sceneEditControls = new SceneEditControls(); sceneEditControls.setEditInfoId(sceneEditInfo.getId()); } sceneEditControlsService.saveOrUpdate(sceneEditControls); //上传data.fdage和custom.txt到home目录 String homePath = dataSource.replace(ConstantFilePath.BUILD_MODEL_PATH, ConstantFilePath.OSS_PREFIX); fYunFileService.uploadFile(dataFdageStr.getBytes(StandardCharsets.UTF_8), homePath + "data.fdage"); fYunFileService.uploadFile(ossPath.getBytes(StandardCharsets.UTF_8), homePath + "custom.txt"); JSONObject jsonObject = new JSONObject(); jsonObject.put("location", 4); BuildSceneCallMessage mqMessage = getBuildSceneMqMessage(num, 13L, null, jsonObject, "V3", dataSource); mqMessage.getExt().put("deleteExtras", true); mqMessage.getExt().put("ossPath", ossPath); //故宫博物馆需求,特殊算法参数 mqMessage.getExt().put("splitType", "SPLIT_V3"); mqMessage.getExt().put("skyboxType", "SKYBOX_V6"); rabbitMqProducer.sendByWorkQueue(queueLiguangModelingPre, mqMessage); //推送mq到前置计算 return ResultData.ok(num); } }