package com.fdkankan.contro.service.impl; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateUtil; import cn.hutool.core.exceptions.ExceptionUtil; import cn.hutool.core.io.FileUtil; import cn.hutool.core.lang.UUID; import cn.hutool.core.util.StrUtil; import cn.hutool.crypto.digest.MD5; 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.*; import com.fdkankan.contro.bean.SendCallAlgorithmDetail; import com.fdkankan.contro.common.Result; import com.fdkankan.contro.constant.ApiConstant; import com.fdkankan.contro.constant.ModelingControlRespCode; import com.fdkankan.contro.constant.RedisConstants; import com.fdkankan.contro.constant.RedisKeyExt; import com.fdkankan.contro.entity.*; import com.fdkankan.contro.enums.CameraTypeEnum; import com.fdkankan.contro.httpclient.MyClient; import com.fdkankan.contro.mapper.ISceneFileBuildMapper; import com.fdkankan.contro.service.*; import com.fdkankan.contro.util.HttpUtilExt; 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.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.ResultData; import com.fdkankan.web.util.RSAEncrypt; import lombok.extern.slf4j.Slf4j; import net.lingala.zip4j.ZipFile; 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 org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.*; /** *

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

* * @author dengsixing * @since 2021-12-23 */ @RefreshScope @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"; private static final String URL_ADD_UCENTER_USER = "/service/manage/inner/addUcenterUser"; @Value("${scene.pro.new.url}") private String sceneProNewUrl; @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("${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; @Value("${4dkk.fdService.basePath}") private String fdServiceUrl; @Value("${user.password.key:0000000856753656}") private String userPasswordKey; @Value("${user.password.iv:pwel781esd6wglxm}") private String userPasswordIv; @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; @Resource private ICompanyService companyService; @Resource private FYunFileServiceInterface fYunFileService; @Autowired private FYunFileConfig fYunFileConfig; @Autowired private RedisLockUtil redisLockUtil; private RestTemplate restTemplate = new RestTemplate(); @Autowired private ISceneCopyLogService sceneCopyLogService; @Autowired private ICommonService commonService; @Autowired private IExceedSpaceSceneService exceedSpaceSceneService; @Autowired private ISceneColdStorageService sceneColdStorageService; @Autowired private IntermitSceneService intermitSceneService; @Autowired private ISceneRebuildLogService sceneRebuildLogService; @Autowired private ISceneUploadCountService sceneUploadCountService; @Autowired private ISceneProService sceneProService; @Autowired private ISceneProEditService sceneProEditService; @Autowired private IFdkkLaserService fdkkLaserService; @Resource private MyClient myClient; @Autowired private IJyUserService jyUserService; @Autowired private IOrigFileUploadService origFileUploadService; @Autowired private IOrigFileUploadBatchService origFileUploadBatchService; @Autowired private IJmgaService jmgaService; @Autowired private ISceneOrigBdService sceneOrigBdService; @Autowired private UploadShootingService uploadShootingService; @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, User user, boolean forceBuild) throws Exception{ //调用createScene方法生成scene数据和加入算法队列 String sceneNum = ""; String cameraName = jsonObject.getJSONObject("cam").getString("uuid"); String unicode = jsonObject.getString("creator") + "_" + jsonObject.getString("uuidtime"); int camType = jsonObject.getJSONObject("cam").getIntValue("type"); String cameraInStoreUrl = fdServiceUrl + ApiConstant.URL_CAMERA_INSTORE; Map cameraInStoreParams = new HashMap<>(); cameraInStoreParams.put("cameraType", camType); cameraInStoreParams.put("snCode", jsonObject.getString("creator")); ResultData post = myClient.post(cameraInStoreUrl, cameraInStoreParams); log.info("---------cameraInStore result:{}-----------", post); if(Objects.isNull(user)){ JSONObject configJson = JSONObject.parseObject(fYunFileService.getFileContent(ConstantFilePath.OSS_PREFIX + prefix + "config.json")); String folderName = configJson.getString("id"); String customUserId = configJson.getString("customUserId"); String customUserName = configJson.getString("customUserName"); String customUserPwd = configJson.getString("customUserPwd"); if(StrUtil.isBlank(folderName) || StrUtil.isBlank(jsonObject.getString("creator"))){ throw new RuntimeException("config.json 文件有误!"); } //调注册用户接口 Map params = new HashMap<>(); params.put("ryId", customUserId); params.put("ryNo", customUserName); // params.put("nickName", customUserName);//去掉昵称,又燕海的接口进行判断 params.put("password", AesUtil.encryptCBC(customUserPwd, userPasswordKey, userPasswordIv, AesUtil.ALMODE_CBC_NOPADDING)); String url = fdServiceUrl.concat(ApiConstant.URL_ADD_UCENTER_USER); myClient.post(url, params); JyUser jyUser = jyUserService.getByRyId(customUserId); user = userService.getById(jyUser.getUserId()); if(Objects.isNull(jyUser)){ throw new RuntimeException("注册用户失败"); } } 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); if (scenePlus.getSceneStatus().equals(SceneStatus.wait.code())) { log.info(scenePlus.getNum() + ":场景处于计算中,不能再计算"); if(!forceBuild){ return null; } } } if (sceneNum == null) { log.error("大场景序号为空:" + sceneNum); throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } //如果是相机计算容量的模式是场景个数模式,则需要拦截计算 if(rebuild == CommonStatus.NO.code()){//新场景需要校验容量是否超出限制 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, camera, cameraDetail, rebuild,icon, user); } private ScenePlusVO buildScenePost(String dataSource, JSONObject jsonObject, String buildType, long cameraType, String sceneNum, Camera camera, CameraDetail cameraDetail, int rebuild,String icon, User user) 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 = "/" + 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"; 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,jsonObject.getJSONObject("cam").getIntValue("type"), dataSource, icon, user.getId(), 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()); ScenePlus scenePlus = scenePlusService.getScenePlusByNum(sceneNum); ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId()); boolean isObj = jsonObject.containsKey("exportMeshObj") && jsonObject.getIntValue("exportMeshObj") == 1; scenePlusExt.setIsObj(isObj ? CommonStatus.YES.code().intValue() : CommonStatus.NO.code().intValue()); scenePlusExtService.updateById(scenePlusExt); //上传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()); mqMessage.getExt().put("uuid", unicode); 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); if(jsonObject.getIntValue("location") == 7){ //发送到全景看看进行初始化 intermitSceneService.sendMq(scenePlusVO.getNum(), jsonObject, CommonSuccessStatus.WAITING.code()); rabbitMqProducer.sendByWorkQueue(queueIntermitModelingPre, mqMessage); }else{ 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, User user, boolean forceBuild, boolean checkUploadFile) 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; String fileUploadedOpName = "fileUploadedOp.cam"; String fileUploadedOpKey = new StringBuilder( ConstantFilePath.OSS_PREFIX).append(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator).append(fileUploadedOpName).toString(); if(fYunFileService.fileExist(fileUploadedOpKey)){ Set notExistsFiles = commonService.checkUploadFile(mac, fileId, folderName, fYunFileConfig.getFyunType()); if(CollUtil.isNotEmpty(notExistsFiles)){ log.error("文件缺失, unicode:{}, 缺失文件:{}", folderName, notExistsFiles); if(checkUploadFile){ throw new BusinessException(ModelingControlRespCode.FILE_EMPTY.code(), ModelingControlRespCode.FILE_EMPTY.message()); } } } 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; } } int camType = fdageJson.getJSONObject("cam").getIntValue("type"); if(camType == 5){ cameraType = 6L; } buildScene(fileId, prefixBuffer.toString(),fdageJson,buildType,cameraType, user, forceBuild); 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; } } 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, User user, boolean forceBuild, boolean checkUploadFille) 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); String fileUploadedOpName = "fileUploadedOp.cam"; String fileUploadedOpKey = new StringBuilder( ConstantFilePath.OSS_PREFIX).append(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator).append(fileUploadedOpName).toString(); if(fYunFileService.fileExist(fileUploadedOpKey)){ Set notExistsFiles = commonService.checkUploadFile(mac, fileId, folderName, fYunFileConfig.getFyunType()); if(CollUtil.isNotEmpty(notExistsFiles)){ log.error("文件缺失, unicode:{}, 缺失文件:{}", folderName, notExistsFiles); if(checkUploadFille){ throw new BusinessException(ModelingControlRespCode.FILE_EMPTY.code(), ModelingControlRespCode.FILE_EMPTY.message()); } } } 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); } 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; } ScenePlusVO scenePlusVO = buildScene(fileId, prefixBuffer.toString(), fdageJson, buildType, cameraType, user, forceBuild); // 通知激光场景系统开始构建场景 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); fdkkLaserService.saveScene(scenePlus,fdageJson,camera,userName,false, scenePlus.getPayStatus(), null); } return ResultData.ok(); } public ScenePlusVO createScenePlus(String projectNum, Long cameraId, String cameraName, String phoneId, String sceneKey, String unicode, 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); scenePlus.setStartBuildTime(new Date()); if(resolution == null || resolution.intValue() == 0){ scenePlusExt.setSceneScheme(cameraType.intValue()); }else { scenePlusExt.setSceneScheme(SceneScheme.BM.code()); } if(cameraType == 6){ scenePlusVO.setThreeCamType("yzl"); } //转台相机用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); } //圆周率相机场景用3dtiles模型是 if(cameraType == 6){ scenePlusExt.setModelKind(modelKind); } if (pic != null && pic.length() > 5) { scenePlusExt.setThumb(pic); } else { scenePlusExt.setThumb(fYunFileConfig.getHost() + "/loading/thumb.jpg"); } 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 (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为新生成场景,其余为重新计算场景 if(camType == 5){//圆周率 scenePlus.setThreeCamType("yzl"); } 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.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.setCreateTime(Calendar.getInstance().getTime()); scenePlus.setBuildFailReason(""); //只要开始常规场景上传计算,场景就不可以预览了 scenePlus.setPreview(CommonStatus.NO.code().intValue()); ScenePlusExt oldSceneExt = scenePlusExtService.getScenePlusExtByPlusId(oldScene.getId()); scenePlusExt.setSpace(oldSceneExt.getSpace()); scenePlusExt.setEcs(oldSceneExt.getEcs()); scenePlusExt.setViewCount(oldSceneExt.getViewCount()); scenePlusExt.setId(oldSceneExt.getId()); 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()); 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); } //已删除原始资源的场景不支持重算 Long cameraId = null; Date laseCallTime = null; ScenePlusExt scenePlusExt = null; if(Objects.nonNull(scenePlus)){ scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId()); laseCallTime = scenePlusExt.getAlgorithmTime(); cameraId = scenePlus.getCameraId(); }else{ laseCallTime = scenePro.getCreateTime(); cameraId = scenePro.getCameraId(); } //激光场景校验是否能够计算 this.checkJgCanBuild(scenePro); 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(); Integer sceneSource = scenePlus.getSceneSource(); String buildType = scenePlusExt.getBuildType(); Integer sceneScheme = scenePlusExt.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()); } //重算的场景,先移除该场景对应的容量 CameraDetail cameraDetail = cameraDetailService.getByCameraId(cameraId); if(CollUtil.isEmpty(laserCamTypeList) || !laserCamTypeList.contains(cameraDetail.getType())){ try { scenePlusService.resetSpace(num); }catch (Exception e){ log.error("重置容量失败", e); } } 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); Long cameraType = (long)sceneScheme == 3 ? 12 : (long)sceneScheme; //判断是否转台相机 if(sceneSource == 3){ cameraType = 13L; } if(sceneSource == 4 || sceneSource == 5){ cameraType = 14L; } String threeCamType = scenePlus.getThreeCamType(); if(StrUtil.isNotEmpty(threeCamType) && "yzl".equals(threeCamType)){ cameraType = 6L; } 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(), null); } 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); message.getExt().put("threeCamType", threeCamType); } if(deleteExtras){ message.getExt().put("deleteExtras",deleteExtras); } if(force){ message.getExt().put("forceRebuild", force); } message.setRebuild("1"); 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{ rabbitMqProducer.sendByWorkQueue(queueModelingPre, message); } redisUtil.incr("modeling-count:" + num, 1); scenePlusService.update(new LambdaUpdateWrapper() .set(ScenePlus::getSceneStatus, SceneStatus.wait.code()) .set(ScenePlus::getBuildFailReason, null) .set(ScenePlus::getStartBuildTime, new Date()) .eq(ScenePlus::getNum, num)); if(ModelKind.THREE_D_TILE.code().equals(modelKind) && CollUtil.isNotEmpty(sdTilesSceneSourceList) && sdTilesSceneSourceList.contains(scenePlus.getSceneSource())){ scenePlusExt.setModelKind(modelKind); } if(cameraType == 6L){ scenePlusExt.setModelKind(modelKind); } scenePlusExt.setUpdateTime(new Date()); scenePlusExtService.updateById(scenePlusExt); //记录日志表 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); } } 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, String uploadType) throws Exception { String imgViewPath = String.format(UploadFilePath.IMG_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) { ScenePlus scenePlus = scenePlusService.getScenePlusByNum(sceneNum); ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId()); scenePlusExt.setSpace(0L); scenePlusExt.setUpdateTime(null); scenePlusExtService.updateById(scenePlusExt); } 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,jsonObject.getJSONObject("cam").getIntValue("type"), dataSource, icon, user.getId() , null, 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()); ScenePlus scenePlus = scenePlusService.getScenePlusByNum(sceneNum); scenePlus.setTaskId(jsonObject.getString("taskId")); scenePlus.setKNo(jsonObject.getString("kNo")); scenePlus.setPushAddress(jsonObject.getString("pushAddress")); scenePlus.setDistrictCode(jsonObject.getString("districtCode")); scenePlus.setDistrictName(jsonObject.getString("districtName")); scenePlusService.updateById(scenePlus); ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId()); boolean isObj = jsonObject.containsKey("exportMeshObj") && jsonObject.getIntValue("exportMeshObj") == 1; scenePlusExt.setIsObj(isObj ? CommonStatus.YES.code().intValue() : CommonStatus.NO.code().intValue()); scenePlusExtService.updateById(scenePlusExt); 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.setRebuild(String.valueOf(rebuild)); mqMessage.getExt().put("deleteExtras", true); mqMessage.getExt().put("customUserId", customUserId); mqMessage.getExt().put("gps", jsonObject.getString("gps")); mqMessage.getExt().put("threeCamType", scenePlusVO.getThreeCamType()); mqMessage.getExt().put("sceneOrigBdId", jsonObject.getLong("sceneOrigBdId")); if(uploadType.equals("single")){//场景上传模式(single-细小文件上传, zip-压缩包上传) OrigFileUploadBatch condition = new OrigFileUploadBatch(); condition.setUuid(unicode); condition.setStatus(0); OrigFileUploadBatch origFileUploadBatch = origFileUploadBatchService.getByCondition(condition); origFileUploadBatch.setStatus(4);//修改为等待通知计算状态,由定时任务统一分配计算 origFileUploadBatch.setMqContent(JSON.toJSONString(mqMessage)); origFileUploadBatchService.updateById(origFileUploadBatch); redisUtil.del("single:upload:uuid:" + unicode); }else{ rabbitMqProducer.sendByWorkQueue(queueModelingPre, mqMessage); } jmgaService.sendStatus(sceneNum, "上传完毕"); return scenePlusVO; } @Override public ResultData uploadFile(MultipartFile file, String params, String dir) 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(dir).concat(fileName); log.info("yunFilePath:{}", yunFilePath); String key = RedisKeyExt.CAM_FILE_LIST.replace("@unicode@", folderName); String value = size + "_" + fileName; 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); } redisUtil.sSet(key, value); result = ResultData.ok(); }else if (!md5.equals(fileMD5)) { log.warn("文件已上传,上传MD5:"+md5+",服务器MD5:"+fileMD5+"。不一致。上传失败"); FileUtils.delFile(yunFilePath.toString()); needUpload = true; }else if (yunFile.length() != size){ log.warn("文件已上传,文件大小不一致。上传失败"); FileUtils.delFile(yunFilePath); needUpload = true; } }else { log.info("文件不存在,需要重新上传"); needUpload = true; } // 4. 上传成功后,校验MD5和文件大小是否相等 // 5. 如果相等,更新数据记录。如果不相等,返回上传失败结果。 try { if (needUpload){ fYunFileService.uploadFile(file.getInputStream(),ConstantFilePath.OSS_PREFIX.concat(filePath).concat(File.separator).concat(dir).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); redisUtil.sSet(key, value); 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 uploadFile(SendCallAlgorithmParam param) throws Exception { log.info("sendCallAlgorithm 参数为:{}", JSONObject.toJSONString(param)); String filePath = param.getFilepath(); if(StrUtil.isBlank(filePath)){ throw new BusinessException(ErrorCode.PARAM_REQUIRED.code(), "filePath不能为空"); } SendCallAlgorithmDetail detail = param.getDetails(); String uploadType = detail.getUploadType(); if(StrUtil.isNotEmpty(uploadType) && "log".equals(uploadType)){ return ResultData.ok(); } String uuid = detail.getUuid(); if(StrUtil.isBlank(uuid)){ throw new BusinessException(ErrorCode.PARAM_REQUIRED.code(), "uuid不能为空"); } String fileName = detail.getFileName(); if(StrUtil.isBlank(fileName)){ throw new BusinessException(ErrorCode.PARAM_REQUIRED.code(), "fileName不能为空"); } String callType = param.getDetails().getCallType(); if(StrUtil.isNotEmpty(callType) && callType.equals("UPLOAD_WHILE_SHOOTING")){ uploadShootingService.uploadFile(param); return ResultData.ok(); } boolean lock = redisLockUtil.lock("lock:single:upload:uuid:" + uuid, uuid, 1); if(!lock){//如果拿不到锁,证明 Thread.sleep(2000L); } String batchId = redisUtil.get("single:upload:uuid:" + uuid); if(StrUtil.isEmpty(batchId)){ OrigFileUploadBatch condition = new OrigFileUploadBatch(); condition.setUuid(uuid); condition.setStatus(0); OrigFileUploadBatch origFileUploadBatch = origFileUploadBatchService.getByCondition(condition); if(Objects.isNull(origFileUploadBatch)){ batchId = redisUtil.get("single:upload:uuid:" + uuid); if(StrUtil.isEmpty(batchId)){ batchId = UUID.fastUUID().toString().replace("-", ""); redisUtil.set("single:upload:uuid:" + uuid, batchId); origFileUploadBatch = new OrigFileUploadBatch(); origFileUploadBatch.setUuid(uuid); origFileUploadBatch.setBatchId(batchId); origFileUploadBatchService.save(origFileUploadBatch); } } } //插入上传明细表 OrigFileUpload origFileUpload = new OrigFileUpload(); origFileUpload.setFileUrl(filePath); origFileUpload.setFileName(fileName); origFileUpload.setBatchId(batchId); origFileUploadService.save(origFileUpload); if(lock){ redisLockUtil.unlockLua("lock:single:upload:uuid:" + uuid, uuid); } if(fileName.equals("config.json")){ HttpUtilExt.downloadFileAndCheck(filePath, sendCallAlgorithmPath.concat(uuid).concat("/config.json"), 300000); } if(fileName.equals("data.fdage")){ HttpUtilExt.downloadFileAndCheck(filePath, sendCallAlgorithmPath.concat(uuid).concat("/data.fdage"), 300000); } if(fileName.equals("scene_up_data.txt")){ HttpUtilExt.downloadFileAndCheck(filePath, sendCallAlgorithmPath.concat(uuid).concat("/scene_up_data.txt"), 300000); } return ResultData.ok(); } @Override public ResultData noticeBuild(String uuid, Long bdId, String dataSource, String uploadType) throws Exception { log.info("通知计算,uuid:{} " + uuid); String sceneNum = null; SceneOrigBd sceneOrigBd = null; try { String[] uuidArr = uuid.split("_"); String snCode = uuidArr[0]; JSONObject fdageData = null; if(StrUtil.isNotEmpty(dataSource)){ String homePath = SceneUtil.getHomePath(dataSource); fdageData = JSONObject.parseObject(fYunFileService.getFileContent(homePath + "data.fdage")); }else{ fdageData = JSONObject.parseObject(FileUtils.readFile(sendCallAlgorithmPath.concat(uuid).concat("/data.fdage"))); } int camType = fdageData.getJSONObject("cam").getIntValue("type"); if(Objects.nonNull(bdId)){ sceneOrigBd = sceneOrigBdService.getById(bdId); fdageData.put("taskId", sceneOrigBd.getTaskId()); fdageData.put("kNo", sceneOrigBd.getKNo()); fdageData.put("sceneOrigBdId", bdId); fdageData.put("pushAddress", sceneOrigBd.getPushAddress()); fdageData.put("districtCode", sceneOrigBd.getDistrictCode()); fdageData.put("districtName", sceneOrigBd.getDistrictName()); } //相机入库 String cameraInStoreUrl = fdServiceUrl + ApiConstant.URL_CAMERA_INSTORE; Map cameraInStoreParams = new HashMap<>(); cameraInStoreParams.put("cameraType", camType); cameraInStoreParams.put("snCode", snCode); ResultData post = myClient.post(cameraInStoreUrl, cameraInStoreParams); log.info("---------cameraInStore result:{}-----------", post); Long cameraType = 13L;//默认为看见相机 Camera camera = cameraService.getBySnCode(snCode); if(Objects.isNull(camera)){ throw new BusinessException(ErrorCode.CAMERA_BIND_NO_EXIST.code(), "相机未入库"); } CameraDetail cameraDetail = cameraDetailService.getByCameraId(camera.getId()); if(Objects.isNull(cameraDetail)){ throw new BusinessException(ErrorCode.CAMERA_BIND_NO_EXIST.code(), "相机未入库"); } camType = cameraDetail.getType(); if(camType == 10 || camType == 11){ cameraType = 14L;//深时或者深光 }else if(camType == 9){ cameraType = 13L;//看见 }else if(camType == 5){ cameraType = 6L;//圆周率 }else { cameraType = 10L;//看看 } String ryId = null; String ryNo = null; String password = null; String phone = null; String idCard = null; String jyNo = null; String nickName = null; String districtCode = null; String districtName = null; String ryOrgCode = null; String ryOrgName = null; if(uploadType != null && uploadType.equals("single")){ String fileId = this.getFileId(snCode, uuid); String subFolder = snCode.concat(File.separator).concat(fileId).concat(File.separator).concat(uuid); dataSource = ConstantFilePath.BUILD_MODEL_PATH.concat(subFolder); log.info("dataSource 为:{}", dataSource); JSONObject configJson = JSONObject.parseObject(FileUtils.readFile(sendCallAlgorithmPath.concat(uuid).concat("/config.json"))); String folderName = configJson.getString("id"); ryId = configJson.getString("customUserId"); ryNo = configJson.getString("customUserName"); // password = AesUtil.encryptCBC(configJson.getString("customUserPwd"), userPasswordKey, userPasswordIv, AesUtil.ALMODE_CBC_NOPADDING); password = MD5.create().digestHex(configJson.getString("customUserPwd")); if(StrUtil.isBlank(folderName) || StrUtil.isBlank(snCode)){ throw new RuntimeException("config.json 文件有误!"); } }else{ ryId = sceneOrigBd.getRyId(); ryNo = sceneOrigBd.getRyId(); password = sceneOrigBd.getPassword(); phone = sceneOrigBd.getRyPhone(); idCard = sceneOrigBd.getRyCid(); jyNo = sceneOrigBd.getRyNo(); nickName = sceneOrigBd.getRyName(); districtCode = sceneOrigBd.getDistrictCode(); districtName = sceneOrigBd.getDistrictName(); ryOrgCode = sceneOrigBd.getRyOrgCode(); ryOrgName = sceneOrigBd.getRyOrgName(); } //调注册用户接口 Map params = new HashMap<>(); params.put("ryId", ryId); params.put("ryNo", ryNo); params.put("password", password); params.put("phone", phone); params.put("idCard", idCard); params.put("jyNo", jyNo); params.put("nickName", nickName); params.put("districtCode", districtCode); params.put("districtName", districtName); params.put("ryOrgCode", ryOrgCode); params.put("ryOrgName", ryOrgName); String url = fdServiceUrl.concat(ApiConstant.URL_ADD_UCENTER_USER); ResultData post1 = myClient.post(url, params); log.info("---------registerUser result:{}-----------", post1); JyUser jyUser = jyUserService.getByRyId(ryId); User user = userService.getById(jyUser.getUserId()); if(Objects.isNull(jyUser)){ throw new RuntimeException("注册用户失败"); } int rebuild = 0; ScenePlus scenePlus = scenePlusService.getByFileId(dataSource); if (!ObjectUtils.isEmpty(scenePlus)) { log.info("该场景资源已存在,执行补拍逻辑!"); rebuild = 1; sceneNum = scenePlus.getNum(); }else{ sceneNum = scene3dNumService.generateSceneNum(cameraDetail.getType()); } buildScenePost(dataSource, fdageData, "V3", cameraType, sceneNum, camera, cameraDetail, rebuild, "", user, ryId, uploadType); scenePlus = scenePlusService.getScenePlusByNum(sceneNum); if(cameraType == 14){ fdkkLaserService.saveScene(scenePlus,fdageData,camera,user.getUserName(),rebuild == 1 ? true : false, scenePlus.getPayStatus(), null); } }catch (Exception e){ log.error("通知计算报错,uuid:{}", uuid, e); if(StrUtil.isNotEmpty(sceneNum)){ jmgaService.updateSceneFailAndZipLog(sceneNum, "通知计算报错"); String buildLogPath = String.format(UploadFilePath.BUILD_LOG_PATH, sceneNum); String preLogPath = buildLogPath + "noticeBuild-error-" + DateUtil.format(new Date(), DatePattern.PURE_DATETIME_PATTERN) + ".log"; fYunFileService.uploadFile(ExceptionUtil.stacktraceToString(e).getBytes(StandardCharsets.UTF_8), preLogPath); jmgaService.sendStatus(sceneNum, "通知计算失败"); } throw e; } return ResultData.ok(); } @Override public ResultData noticeBuild(SendCallAlgorithmDetail detail) throws Exception { String unicode = detail.getUuid(); log.info("通知计算,uuid:{} " + unicode); String sceneNum = null; try { String[] uuidArr = unicode.split("_"); JSONObject fdageData = JSONObject.parseObject(FileUtils.readFile(sendCallAlgorithmPath.concat(unicode).concat("/data.fdage"))); OrigFileUploadBatch condition = new OrigFileUploadBatch(); condition.setUuid(unicode); condition.setStatus(0); OrigFileUploadBatch origFileUploadBatch = origFileUploadBatchService.getByCondition(condition); origFileUploadBatch.setStatus(4);//修改为等待通知计算状态,由定时任务统一分配计算 origFileUploadBatchService.updateById(origFileUploadBatch); redisUtil.del("single:upload:uuid:" + unicode);//删除当前批次缓存,如果场景补拍上传就会创建一个新的批次号 buildScenePost(dataSource, fdageData, "V3", cameraType, sceneNum, camera, cameraDetail, rebuild, "", user, ryId, uploadType); }catch (Exception e){ log.error("通知计算报错,uuid:{}", uuid, e); if(StrUtil.isNotEmpty(sceneNum)){ jmgaService.updateSceneFailAndZipLog(sceneNum, "通知计算报错"); String buildLogPath = String.format(UploadFilePath.BUILD_LOG_PATH, sceneNum); String preLogPath = buildLogPath + "noticeBuild-error-" + DateUtil.format(new Date(), DatePattern.PURE_DATETIME_PATTERN) + ".log"; fYunFileService.uploadFile(ExceptionUtil.stacktraceToString(e).getBytes(StandardCharsets.UTF_8), preLogPath); jmgaService.sendStatus(sceneNum, "通知计算失败"); } throw e; } return ResultData.ok(); } @Override public String getFileId(String snCode, String uuid){ // 检测是否有生成 String fileId = null; SceneFileBuild sceneFileBuild = this.findByUnicode(uuid); if(Objects.nonNull(sceneFileBuild)){ fileId = sceneFileBuild.getFileId(); return fileId; } fileId = new SnowflakeIdGenerator(0, 0).nextId() + ""; log.info("新场景,fileid:{}", fileId); sceneFileBuild = new SceneFileBuild(); sceneFileBuild.setChildName(snCode); sceneFileBuild.setFileId(fileId); sceneFileBuild.setRecStatus("A"); sceneFileBuild.setUnicode(uuid); sceneFileBuild.setCreateTime(new Date()); this.save(sceneFileBuild); return fileId; } }