1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690 |
- 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.util.StrUtil;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.fdkankan.common.constant.CameraConstant;
- import com.fdkankan.common.constant.CommonStatus;
- import com.fdkankan.common.constant.ConstantFilePath;
- import com.fdkankan.common.constant.ConstantUrl;
- import com.fdkankan.common.constant.ErrorCode;
- import com.fdkankan.common.constant.RecStatus;
- import com.fdkankan.common.constant.SceneStatus;
- import com.fdkankan.common.constant.UploadFilePath;
- import com.fdkankan.common.constant.UploadStatus;
- import com.fdkankan.common.exception.BusinessException;
- import com.fdkankan.common.response.ResultData;
- import com.fdkankan.common.util.ComputerUtil;
- import com.fdkankan.common.util.CreateObjUtil;
- import com.fdkankan.common.util.DateExtUtil;
- import com.fdkankan.common.util.FileMd5Util;
- import com.fdkankan.common.util.FileUpload;
- import com.fdkankan.common.util.FileUtil;
- import com.fdkankan.common.util.FileUtils;
- import com.fdkankan.common.util.MatrixToImageWriterUtil;
- import com.fdkankan.common.util.RSAEncrypt;
- import com.fdkankan.common.util.SnowflakeIdGenerator;
- import com.fdkankan.contro.config.FileRouteConfig;
- import com.fdkankan.contro.entity.Camera;
- import com.fdkankan.contro.entity.CameraDetail;
- import com.fdkankan.contro.entity.Company;
- import com.fdkankan.contro.entity.SSOUser;
- import com.fdkankan.contro.entity.SceneCooperation;
- import com.fdkankan.contro.entity.SceneEditControls;
- import com.fdkankan.contro.entity.SceneEditInfo;
- import com.fdkankan.contro.entity.SceneEditInfoExt;
- import com.fdkankan.contro.entity.SceneFileBuild;
- import com.fdkankan.contro.entity.SceneFileUpload;
- import com.fdkankan.contro.entity.ScenePlus;
- import com.fdkankan.contro.entity.ScenePlusExt;
- import com.fdkankan.contro.entity.SceneProPO;
- import com.fdkankan.contro.entity.SceneResourceCamera;
- import com.fdkankan.contro.entity.SceneResourceCooperation;
- import com.fdkankan.contro.mapper.ISceneFileBuildMapper;
- import com.fdkankan.contro.service.ICameraDetailService;
- import com.fdkankan.contro.service.ICameraService;
- import com.fdkankan.contro.service.ICompanyService;
- import com.fdkankan.contro.service.IScene3dNumService;
- import com.fdkankan.contro.service.ISceneCooperationService;
- import com.fdkankan.contro.service.ISceneEditControlsService;
- import com.fdkankan.contro.service.ISceneEditInfoExtService;
- import com.fdkankan.contro.service.ISceneEditInfoService;
- import com.fdkankan.contro.service.ISceneFileBuildService;
- import com.fdkankan.contro.service.ISceneFileUploadService;
- import com.fdkankan.contro.service.IScenePlusExtService;
- import com.fdkankan.contro.service.IScenePlusService;
- import com.fdkankan.contro.service.ISceneProEditExtService;
- import com.fdkankan.contro.service.ISceneProEditService;
- import com.fdkankan.contro.service.ISceneProExtService;
- import com.fdkankan.contro.service.ISceneProService;
- import com.fdkankan.contro.service.ISceneResourceCameraService;
- import com.fdkankan.contro.service.ISceneResourceCooperationService;
- import com.fdkankan.contro.service.IUserService;
- import com.fdkankan.contro.vo.ResponseSceneFile;
- import com.fdkankan.contro.vo.ScenePlusVO;
- import com.fdkankan.fyun.constant.StorageType;
- import com.fdkankan.fyun.oss.UploadToOssUtil;
- import com.fdkankan.rabbitmq.bean.BuildSceneCallMessage;
- import com.fdkankan.rabbitmq.util.RabbitMqProducer;
- import com.fdkankan.redis.util.RedisUtil;
- import java.io.File;
- import java.io.IOException;
- import java.time.LocalDate;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Calendar;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.Objects;
- import java.util.UUID;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.codec.binary.Base64;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.stereotype.Service;
- import org.springframework.util.ObjectUtils;
- import org.springframework.web.multipart.MultipartFile;
- /**
- * <p>
- * 场景文件建模表 服务实现类
- * </p>
- *
- * @author dengsixing
- * @since 2021-12-23
- */
- @Slf4j
- @Service
- public class SceneFileBuildServiceImpl extends ServiceImpl<ISceneFileBuildMapper, SceneFileBuild> implements ISceneFileBuildService {
- private static final String SPLICE = "#";
- @Value("${main.url}")
- private String mainUrl;
- @Value("${scene.pro.url}")
- private String sceneProUrl;
- @Value("${scene.pro.new.url}")
- private String sceneProNewUrl;
- @Value("${upload.type}")
- private String type;
- @Value("${oss.prefix.ali}")
- private String prefixAli;
- @Value("${ecs.type}")
- private String ecsType;
- @Value("${unCalculated.company.ids:#{null}}")
- private String[] unCalculatedCompanyIds;
- @Value("${queue.modeling.modeling-call}")
- private String queueModelingCall;
- @Value("${queue.modeling.modeling-pre}")
- private String queueModelingPre;
- @Value("${queue.modeling.video-a}")
- private String queueVideoA;
- @Value("${queue.modeling.pic-a}")
- private String queuePicA;
- @Autowired
- private ISceneFileUploadService sceneFileUploadService;
- @Autowired
- private ISceneProService sceneProService;
- @Autowired
- private RedisUtil redisUtil;
- @Autowired
- private FileRouteConfig routeConfig;
- @Autowired
- private UploadToOssUtil uploadToOssUtil;
- @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;
- @Autowired
- private ISceneProEditExtService sceneProEditExtService;
- @Autowired
- private ISceneProExtService sceneProExtService;
- @Override
- public SceneFileBuild findByFileId(String fileId) {
- List<SceneFileBuild> list = this.list(new LambdaQueryWrapper<SceneFileBuild>()
- .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:" + mac + "准备上传文件");
- String dataSource = scenePlusService.getDataSourceLikeUnicode("/" + folderName);
- if(StrUtil.isNotEmpty(dataSource)){
- int n = dataSource.split("/").length;
- if(n > 1){
- String fileId = dataSource.split("/")[n - 2];
- ResponseSceneFile responseSceneFile = new ResponseSceneFile();
- responseSceneFile.setFileId(fileId);
- //可以重复上传,文件id保存50年(因为该redis工具无法设置永久保存)
- redisUtil.set(fileId, folderName, 1537920000);
- return responseSceneFile;
- }
- }else {
- SceneFileBuild sceneFileBuild = this.findByUnicode(folderName);
- if(sceneFileBuild != null){
- String fileId = sceneFileBuild.getFileId();
- ResponseSceneFile responseSceneFile = new ResponseSceneFile();
- responseSceneFile.setFileId(fileId);
- //可以重复上传,文件id保存50年(因为该redis工具无法设置永久保存)
- redisUtil.set(fileId, folderName, 1537920000);
- return responseSceneFile;
- }
- }
- // 构造方法设置机器码:第0个机房的第0台机器
- SnowflakeIdGenerator snowflakeIdGenerator = new SnowflakeIdGenerator(0, 0);
- long fileId = snowflakeIdGenerator.nextId();
- SceneFileBuild sceneFileBuild = new SceneFileBuild();
- sceneFileBuild.setChildName(mac);
- sceneFileBuild.setFileId(String.valueOf(fileId));
- sceneFileBuild.setUnicode(folderName);
- sceneFileBuild.setUploadStatus(0);
- sceneFileBuild.setBuildStatus(0);
- sceneFileBuild.setTotalPicNum(Integer.valueOf(totalPicNum));
- sceneFileBuild.setChunks(Integer.valueOf(chunks));
- this.save(sceneFileBuild);
- ResponseSceneFile responseSceneFile = new ResponseSceneFile();
- responseSceneFile.setFileId(String.valueOf(fileId));
- //可以重复上传,文件id保存50年(因为该redis工具无法设置永久保存)
- redisUtil.set(String.valueOf(fileId), folderName, 1537920000);
- return responseSceneFile;
- }
- public SceneFileBuild findByUnicode(String unicode) {
- List<SceneFileBuild> list = this.list(new QueryWrapper<SceneFileBuild>()
- .eq("unicode", unicode)
- .orderByDesc("id"));
- if(CollUtil.isEmpty(list))
- return null;
- return list.get(0);
- }
- @Override
- public ResponseSceneFile getProgress(String params) throws Exception {
- log.info("getProgress-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("getProgress-params解密结果:{}" , restr);
- String[] strArr = restr.split(SPLICE);
- if (strArr.length != 3) {
- throw new BusinessException(ErrorCode.PARAM_REQUIRED);
- }
- String fileId = strArr[0];
- String chunk = strArr[1];
- chunk = chunk.split(SPLICE)[0];
- SceneFileUpload sceneFileUpload = sceneFileUploadService.findByFileIdAndChunk(fileId, Integer.valueOf(chunk));
- ResponseSceneFile responseSceneFile = new ResponseSceneFile();
- responseSceneFile.setUploadStatus(sceneFileUpload != null ? sceneFileUpload.getUploadStatus() : -1);
- return responseSceneFile;
- }
- @Override
- public ResultData uploadFile(MultipartFile file, String params) throws Exception{
- log.info("upload-params: "+params);
- if (StringUtils.isEmpty(params)){
- throw new BusinessException(ErrorCode.PARAM_REQUIRED);
- }
- params = params.replaceAll("%2B", "+");
- Base64 base64 = new Base64();
- String cipher = params;
- // 私钥解密过程
- byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()),
- base64.decode(cipher));
- String restr = new String(res, "UTF-8");
- log.debug("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];
- ResultData result = null;
- if (file.isEmpty()){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5048);
- }
- if (StringUtils.isEmpty(fileId)){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5049);
- }
- if (picNum == null){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5050);
- }
- if (StringUtils.isEmpty(mac)){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5044);
- }
- if (StringUtils.isEmpty(md5)){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5051);
- }
- long size = file.getSize();
- log.warn("fileId:"+fileId+"---picNum:"+picNum+"---size:"+size+"---md5:"+md5+"---mac:"+mac);
- chunk = chunk.split(SPLICE)[0];
- // 获取文件名
- String fileName = file.getOriginalFilename();
- log.info("上传的文件名为:" + fileName);
- // 获取文件的后缀名
- String suffixName = fileName.substring(fileName.lastIndexOf("."));
- log.info("上传的后缀名为:" + suffixName);
- Object folderNameObject = redisUtil.get(fileId);
- String folderName = folderNameObject == null ? null : (String)folderNameObject;
- if(StrUtil.isEmpty(folderName)){
- String dataSource = scenePlusService.getDataSourceLikeUnicode("/" + fileId + "/");
- if(StrUtil.isNotEmpty(dataSource)){
- folderName = dataSource.substring(dataSource.lastIndexOf("/") + 1);
- }
- }
- // 1. 判断该文件是否已经上传过
- // 2. 如果已经上传过,判断MD5值和文件大小是否相等。如果相等,更新数据记录。如果不相等,删除该文件,重新上传。
- // 3. 如果未上传过,需要上传。
- StringBuffer filePathBuffer = new StringBuffer(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator).append("capture");
- StringBuffer sb = new StringBuffer(routeConfig.getHardDisk()).append(filePathBuffer.toString()).append(File.separator).append(fileName);
- boolean needUpload = false;
- File dbFile = new File(sb.toString());
- if (dbFile.exists()){
- String fileMD5 = FileMd5Util.getFileMD5(dbFile);
- if (md5.equals(fileMD5) && dbFile.length() == size){
- log.warn("文件已存在,MD5和文件大小一致。");
- SceneFileUpload uploadEntity = sceneFileUploadService.findByFileIdAndChunk(fileId, Integer.valueOf(chunk));
- if (uploadEntity != null){
- uploadEntity.setSize((int) size);
- uploadEntity.setMd5(md5);
- uploadEntity.setFilePath(sb.toString());
- uploadEntity.setFileSourceName(fileName);
- uploadEntity.setUploadStatus(UploadStatus.SUCCESS.code());
- sceneFileUploadService.updateById(uploadEntity);
- }else{
- SceneFileUpload sceneFileUploadEntity = new SceneFileUpload();
- sceneFileUploadEntity.setSize((int) size);
- sceneFileUploadEntity.setMd5(md5);
- sceneFileUploadEntity.setFilePath(sb.toString());
- sceneFileUploadEntity.setFileSourceName(fileName);
- sceneFileUploadEntity.setUploadStatus(UploadStatus.SUCCESS.code());
- sceneFileUploadEntity.setFileId(fileId);
- sceneFileUploadEntity.setChunk(Integer.valueOf(chunk));
- sceneFileUploadEntity.setRecStatus(RecStatus.VALID.code());
- sceneFileUploadService.save(sceneFileUploadEntity);
- }
- result = ResultData.ok();
- }else if (!md5.equals(fileMD5)) {
- log.warn("文件已上传,上传MD5:"+md5+",服务器MD5:"+fileMD5+"。不一致。上传失败");
- FileUtil.delFile(sb.toString());
- needUpload = true;
- }else if (dbFile.length() != size){
- log.warn("文件已上传,文件大小不一致。上传失败");
- FileUtil.delFile(sb.toString());
- needUpload = true;
- }
- }else {
- log.warn("文件不存在,需要重新上传");
- needUpload = true;
- }
- // 4. 上传成功后,校验MD5和文件大小是否相等
- // 5. 如果相等,更新数据记录。如果不相等,返回上传失败结果。
- try {
- if (needUpload){
- String name = fileName.substring(0, fileName.lastIndexOf("."));
- String filePath = this.saveFile(file, filePathBuffer.toString(), name);
- File uploadFile = new File(filePath);
- String fileMD5 = FileMd5Util.getFileMD5(uploadFile);
- SceneFileUpload sceneFileUploadEntity = new SceneFileUpload();
- sceneFileUploadEntity.setSize((int) size);
- sceneFileUploadEntity.setMd5(md5);
- sceneFileUploadEntity.setFilePath(sb.toString());
- sceneFileUploadEntity.setFileSourceName(fileName);
- sceneFileUploadEntity.setFileId(fileId);
- sceneFileUploadEntity.setChunk(Integer.valueOf(chunk));
- sceneFileUploadEntity.setRecStatus(RecStatus.VALID.code());
- if (md5.equals(fileMD5) && uploadFile.length() == size){
- log.warn("文件已上传,MD5和文件大小一致。上传成功");
- sceneFileUploadEntity.setUploadStatus(1);
- sceneFileUploadService.save(sceneFileUploadEntity);
- result = ResultData.ok();
- }else if (!md5.equals(fileMD5)) {
- log.warn("文件已上传,上传MD5:"+md5+",服务器MD5:"+fileMD5+"。不一致。上传失败");
- sceneFileUploadEntity.setUploadStatus(-1);
- sceneFileUploadService.save(sceneFileUploadEntity);
- result = ResultData.error(ErrorCode.FAILURE_CODE_5052);
- }else if (uploadFile.length() != size){
- log.warn("文件已上传,文件大小不一致。上传失败");
- sceneFileUploadEntity.setUploadStatus(-1);
- sceneFileUploadService.save(sceneFileUploadEntity);
- result = ResultData.error(ErrorCode.FAILURE_CODE_5052);
- }
- }
- }catch (IllegalStateException | IOException e) {
- log.error(ErrorCode.FAILURE_CODE_5052.message(), e);
- result = ResultData.error(ErrorCode.FAILURE_CODE_5052);
- }
- return result;
- }
- public String saveFile(MultipartFile file, String filePath, String fileId) throws IOException {
- //扩展名格式
- String extName = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
- String name;
- /*
- 指定上传目录
- */
- if (filePath != null && !"".equals(filePath.trim())) {
- name = designatedUp(filePath, fileId, file);
- return name;
- }
- /*
- 默认上传目录
- */
- //图片类型文件
- if (this.inArray(routeConfig.getImageType(), extName)) {
- filePath = routeConfig.getImageFolder();
- }
- //视频类型文件
- else if (this.inArray(routeConfig.getVideoType(), extName)) {
- filePath = routeConfig.getVideoFolder();
- }
- //文档类型文件
- else if (this.inArray(routeConfig.getDocumentType(), extName)) {
- filePath = routeConfig.getDocumentFolder();
- }
- //音频类型文件
- else if (this.inArray(routeConfig.getMusicType(), extName)) {
- filePath = routeConfig.getMusicFolder();
- } else {
- return "This upload type is not supported temporarily";
- }
- name = myfileUp(filePath, file);
- return name;
- }
- /**
- * 默认上传文件到文件夹
- *
- * @param folder 默认文件夹
- * @param file 上传的文件
- * @return
- */
- private String myfileUp(String folder, MultipartFile file) throws IOException {
- LocalDate today = LocalDate.now();
- String saveName = File.separator + today.getYear() + "." + today.getMonthValue() + File.separator;
- String fileCode = UUID.randomUUID().toString().trim().replaceAll("-", "");
- String returnName = FileUpload.fileUp(file, routeConfig.getHardDisk() + File.separator + folder + saveName, fileCode);
- saveName = folder + File.separator + saveName + File.separator + returnName;
- log.warn("This file has been uploaded: " + saveName);
- return saveName;
- }
- /**
- * 判断数组中是否包含某个元素
- *
- * @param array 类型的数组
- * @param element 被检查的类型
- * @return
- */
- private boolean inArray(String[] array, String element) {
- boolean flag = false;
- for (String type : array) {
- if (element.equals(type)) {
- flag = true;
- break;
- }
- }
- return flag;
- }
- /**
- * 指定目录上传文件
- *
- * @param folder 指定文件夹
- * @param file 上传文件
- * @return
- */
- private String designatedUp(String folder, String fileId, MultipartFile file) throws IOException {
- StringBuffer sb = new StringBuffer(routeConfig.getHardDisk()).append(File.separator).append(folder);
- String returnName = FileUpload.fileUp(file, sb.toString(), fileId);
- String filePathName = sb.toString() + File.separator + File.separator + returnName;
- log.warn("This file has been uploaded: " + filePathName);
- return filePathName;
- }
- @Override
- public ResultData uploadSuccess(String params) throws Exception {
- log.info("uploadSuccess-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("uploadSuccess-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];
- Object folderNameObject = redisUtil.get(fileId);
- String folderName = folderNameObject == null ? null : (String)folderNameObject;
- if(StringUtils.isEmpty(folderName)){
- String dataSource = scenePlusService.getDataSourceLikeUnicode("/" + fileId + "/");
- if(StrUtil.isNotEmpty(dataSource)){
- folderName = dataSource.substring(dataSource.lastIndexOf("/") + 1);
- }
- if(StringUtils.isEmpty(folderName)){
- SceneFileBuild sceneFileBuild = this.findByFileId(fileId);
- if(sceneFileBuild != null){
- folderName = sceneFileBuild.getUnicode();
- }
- }
- }
- StringBuilder filePathBuffer = new StringBuilder(routeConfig.getHardDisk()).append(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator).append("capture").append(File.separator);
- boolean flag = this.uploadSuccess(fileId, filePathBuffer);
- if(flag){
- //调用建模的方法
- }
- buildScene(filePathBuffer.toString(), fileId, false, null);
- return ResultData.ok();
- }
- public void buildScene(String filePath, String fileId, boolean fromOss, String prefix) throws Exception{
- //获取解压后的资源的data.fdage中的数据
- String data = FileUtils.readFile(filePath + "data.fdage");
- JSONObject jsonObject = JSONObject.parseObject(data);
- //调用createScene方法生成scene数据和加入算法队列
- if(jsonObject != null){
- //有calibration值为标定,1: camera_calibration 2: color_anlysis,0正常计算
- if(jsonObject.get("calibration") != null && jsonObject.getString("calibration").equals("1")){
- String mac = filePath.replace(ConstantFilePath.BUILD_MODEL_PATH, "").split("/")[0];
- String calPath = ConstantFilePath.BUILD_MODEL_PATH + mac + "/camera_calibration";
- //生成标定数据
- ComputerUtil.createCalibrationData(calPath, filePath);
- //开始标定计算
- rabbitMqProducer.sendByWorkQueue(queueModelingCall, calPath);
- }else if(jsonObject.get("calibration") != null && jsonObject.getString("calibration").equals("2")){
- String mac = filePath.replace(ConstantFilePath.BUILD_MODEL_PATH, "").split("/")[0];
- String calPath = ConstantFilePath.BUILD_MODEL_PATH + mac + "/color_anlysis";
- //生成标定数据
- ComputerUtil.createCalibrationData(calPath, filePath);
- //开始标定计算
- Map<String,String> map = ComputerUtil.computerCalibration(calPath);
- }else if(jsonObject.get("calibration") != null && jsonObject.getString("calibration").equals("3")){
- String mac = filePath.replace(ConstantFilePath.BUILD_MODEL_PATH, "").split("/")[0];
- String calPath = ConstantFilePath.BUILD_MODEL_PATH + mac + "/shading";
- //生成标定数据
- ComputerUtil.createCalibrationData(calPath, filePath);
- //开始标定计算
- rabbitMqProducer.sendByWorkQueue(queueModelingCall, calPath);
- }else {
- String sceneNum = "";
- String cameraName = jsonObject.getJSONObject("cam").getString("uuid");
- String unicode = jsonObject.getString("creator") + "_" + jsonObject.getString("uuidtime");
- log.info("查询相机:" + cameraName);
- Camera camera = cameraService.getByChildName(cameraName);
- if(camera == null){
- log.error("该相机不存在:" + cameraName);
- //偶现data.fdage给的相机码多了或少了4DKKPRO_
- if(cameraName.contains("4DKKPRO_")){
- camera = cameraService.getByChildName(cameraName.replace("4DKKPRO_", ""));
- }else {
- camera = cameraService.getByChildName("4DKKPRO_" + cameraName);
- }
- if(camera == null){
- throw new BusinessException(CameraConstant.FAILURE_6003);
- }
- }
- CameraDetail cameraDetail = cameraDetailService.getByCameraId(camera.getId());
- if(cameraDetail == null){
- log.error("该相机详情不存在:" + cameraName);
- throw new BusinessException(CameraConstant.FAILURE_6003);
- }
- //查看场景中的文件目录是否有改文件id,有则重新计算改场景,无则新建场景
- ScenePlus scenePlus = scenePlusService.getByFileId("/" + fileId + "/");
- int rebuild = 1;
- if(Objects.nonNull(scenePlus)){
- sceneNum = scenePlus.getNum();
- if(scenePlus.getSceneStatus() == SceneStatus.wait.code()){
- log.info(sceneNum + ":场景处于计算中,不能再计算");
- return;
- }
- }else {
- sceneNum = scene3dNumService.generateSceneNum(cameraDetail.getType());
- rebuild = 0;
- }
- if(sceneNum == null){
- log.error("大场景序号为空:" + sceneNum);
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
- }
- String localDataPath = String.format(ConstantFilePath.DATABUFFER_FORMAT, sceneNum);
- String localImagesPath = String.format(ConstantFilePath.IMAGESBUFFER_FORMAT, sceneNum);
- String imgViewPath = String.format(UploadFilePath.IMG_VIEW_PATH, sceneNum);
- String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, sceneNum);
- String userName = null;
- if(cameraDetail.getUserId() != null){
- SSOUser user = userService.getSSOUserByUserId(cameraDetail.getUserId());
- if(user != null){
- userName = user.getUserName();
- }
- }
- String icon = null;
- if(jsonObject.containsKey("icon") && StrUtil.isNotEmpty(jsonObject.getString("icon"))){
- CreateObjUtil.ossUtilCp(ConstantFilePath.OSS_PREFIX + prefix + jsonObject.getString("icon"), filePath);
- icon = prefixAli + "images/images" + sceneNum + "/" + jsonObject.getString("icon");
- if(StorageType.AWS.code().equals(type)){
- CreateObjUtil.ossFileCp(ConstantFilePath.OSS_PREFIX + prefix + jsonObject.getString("icon"), filePath + jsonObject.getString("icon"));
- icon = ConstantUrl.PREFIX_AWS + imgViewPath + jsonObject.getString("icon");
- }
- uploadToOssUtil.upload(filePath + jsonObject.getString("icon"), imgViewPath + jsonObject.getString("icon"));
- }
- JSONObject firmwareVersion = new JSONObject();
- if(jsonObject.containsKey("camSoftwareVersion") && StrUtil.isNotEmpty(jsonObject.getString("camSoftwareVersion"))){
- firmwareVersion.put("camSoftwareVersion", jsonObject.getString("camSoftwareVersion"));
- }
- if(jsonObject.containsKey("version") && StrUtil.isNotEmpty(jsonObject.getString("version"))){
- firmwareVersion.put("version", jsonObject.getString("version"));
- }
- String sceneUrl = mainUrl +"/"+sceneProNewUrl;
- String buildType = "V2";
- Long cameraType = 10L;
- //根据videoVersion判断是V2还是V3版本的算法和页面
- if(jsonObject.containsKey("videoVersion") && StrUtil.isNotEmpty(jsonObject.getString("videoVersion"))){
- if(jsonObject.getIntValue("videoVersion") >= 4){
- buildType = "V3";
- cameraType = 11L;
- }
- }
- //重算的场景,先移除该场景对应的容量
- if(rebuild == 1){
- scenePlusService.resetSpace(sceneNum);
- }else {
- //上传log-main.png
- uploadToOssUtil.upload(ConstantFilePath.LOGO_PATH + "logo-main.png", imgViewPath + "logo-main.png");
- uploadToOssUtil.upload(ConstantFilePath.LOGO_PATH + "logo-main-en.png", imgViewPath + "logo-main-en.png");
- }
- ScenePlusVO scenePlusVO = null;
- Object[] objects = null;
- BuildSceneCallMessage mqMessage = null;
- if(fromOss){
- objects = this.createScenePlus(sceneNum, camera.getId(), camera.getChildName(), jsonObject.getString("creator"),
- jsonObject.getString("pwd"), unicode,
- cameraType, String.valueOf(fileId), prefix, "", icon, "0", cameraDetail.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"), rebuild,
- jsonObject.getInteger("resolution"), firmwareVersion.toString(), sceneUrl, buildType, ecsType,cameraDetail.getCooperationUser());
- }else {
- objects = this.createScenePlus(sceneNum, camera.getId(), camera.getChildName(), jsonObject.getString("creator"),
- jsonObject.getString("pwd"), unicode,
- cameraDetail.getGoodsId(), String.valueOf(fileId), "", "", icon, "0", cameraDetail.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"), rebuild,
- jsonObject.getInteger("resolution"), firmwareVersion.toString(), sceneUrl, buildType, ecsType, cameraDetail.getCooperationUser());
- }
- scenePlusVO = (ScenePlusVO)objects[0];
- mqMessage = (BuildSceneCallMessage)objects[1];
- if(Objects.nonNull(scenePlusVO)){
- JSONObject statusJson = new JSONObject();
- //临时将-2改成1,app还没完全更新
- statusJson.put("status", scenePlusVO.getSceneStatus() == -2 ? 1 : scenePlusVO.getSceneStatus());
- statusJson.put("webSite", scenePlusVO.getWebSite());
- statusJson.put("sceneNum", scenePlusVO.getNum());
- statusJson.put("thumb", scenePlusVO.getThumb());
- statusJson.put("payStatus", scenePlusVO.getPayStatus());
- statusJson.put("recStatus", scenePlusVO.getRecStatus());
- FileUtils.writeFile(localDataPath + "status.json", statusJson.toString());
- uploadToOssUtil.upload(localDataPath + "status.json", dataViewPath + "status.json");
- }
- //删除oss的houst_floor.json(国际版可能会卡住)
- uploadToOssUtil.delete(dataViewPath + "houst_floor.json");
- if(cameraDetail.getCompanyId() != null){
- Company company = companyService.getById(cameraDetail.getCompanyId());
- if(company != null){
- log.info("复制企业logo");
- SceneEditInfo sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlusVO.getId());
- SceneEditInfoExt sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfo.getId());
- if(StrUtil.isNotEmpty(company.getTopLogo())){
- //复制阿里云主服务器的图片到横琴云副服务器中
- if(!new File(ConstantFilePath.BASE_PATH + File.separator + company.getTopLogo()).exists()){
- log.info("下载topLogo");
- FileUtils.downLoadFromUrl(mainUrl + company.getTopLogo() + "?t=" + System.currentTimeMillis(),
- company.getTopLogo().substring(company.getTopLogo().lastIndexOf("/") + 1),
- ConstantFilePath.BASE_PATH + company.getTopLogo().substring(0, company.getTopLogo().lastIndexOf("/")));
- }
- FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + company.getTopLogo(),
- localImagesPath + "logo-main.png", true);
- uploadToOssUtil.upload(localImagesPath + "logo-main.png", imgViewPath + "logo-main.png");
- }
- if(StrUtil.isNotEmpty(company.getFloorLogo())){
- //复制阿里云主服务器的图片到横琴云副服务器中
- if(!new File(ConstantFilePath.BASE_PATH + File.separator + company.getFloorLogo()).exists()){
- log.info("下载floorLogo");
- FileUtils.downLoadFromUrl(mainUrl + company.getFloorLogo() + "?t=" + System.currentTimeMillis(),
- company.getFloorLogo().substring(company.getFloorLogo().lastIndexOf("/") + 1),
- ConstantFilePath.BASE_PATH + company.getFloorLogo().substring(0, company.getFloorLogo().lastIndexOf("/")));
- }
- FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + company.getFloorLogo(),
- localImagesPath + "floorLogoImg.png", true);
- uploadToOssUtil.upload(localImagesPath + "floorLogoImg.png", imgViewPath + "floorLogoImg.png");
- sceneEditInfo.setFloorLogo("user");
- }
- if(StrUtil.isNotEmpty(company.getQrLogo())){
- //复制阿里云主服务器的图片到横琴云副服务器中
- // TODO: 2022/7/25 目前v4版本不需要生成带logo的二维码,这里先注释掉 dsx-------------------------------start
- // if(!new File(ConstantFilePath.BASE_PATH + File.separator + company.getQrLogo()).exists()){
- // log.info("下载qrLogo");
- // FileUtils.downLoadFromUrl(mainUrl + company.getQrLogo() + "?t=" + System.currentTimeMillis(),
- // company.getQrLogo().substring(company.getQrLogo().lastIndexOf("/") + 1),
- // ConstantFilePath.BASE_PATH + company.getQrLogo().substring(0, company.getQrLogo().lastIndexOf("/")));
- // }
- //
- // FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + company.getQrLogo(),
- // ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png", true);
- // uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png",
- // "images/images" + sceneNum + "/QRShareLogo.png");
- // sceneProEdit.setShareLogo("images/images" + sceneNum + "/QRShareLogo.png");
- // TODO: 2022/7/25 目前v4版本不需要生成带logo的二维码,这里先注释掉 dsx-------------------------------end
- //生成新的分享的二维码
- MatrixToImageWriterUtil.createQRCode(sceneUrl + sceneNum, ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneNum+".png",
- false, ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png");
- MatrixToImageWriterUtil.createQRCode(sceneUrl + sceneNum + "&lang=en", ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneNum+"_en.png",
- false, ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png");
- }
- // TODO: 2022/7/25 目前v4版本还没开发地面点位log功能,这里先注释掉 dsx-------------------------------start
- // if(StrUtil.isNotEmpty(company.getMarkerLogo())){
- // //复制阿里云主服务器的图片到横琴云副服务器中
- // if(!new File(ConstantFilePath.BASE_PATH + File.separator + company.getMarkerLogo()).exists()){
- // log.info("下载floorLogo");
- // FileUtils.downLoadFromUrl(mainUrl + company.getMarkerLogo() + "?t=" + System.currentTimeMillis(),
- // company.getMarkerLogo().substring(company.getMarkerLogo().lastIndexOf("/") + 1),
- // ConstantFilePath.BASE_PATH + company.getMarkerLogo().substring(0, company.getMarkerLogo().lastIndexOf("/")));
- // }
- //
- // FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + company.getMarkerLogo(),
- // ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/marker.png", true);
- // uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/marker.png",
- // "images/images" + sceneNum + "/marker.png");
- //
- // sceneProEdit.setMarkerLogo("user");
- // jsonMap.put("markerLogo", "user");
- // }
- // TODO: 2022/7/25 目前v4版本还没开发地面点位log功能,这里先注释掉 dsx-------------------------------end
- sceneEditInfoService.updateById(sceneEditInfo);
- }
- }
- rabbitMqProducer.sendByWorkQueue(queueModelingPre, mqMessage);
- }
- }else {
- log.info("data.fdage文件不存在");
- throw new BusinessException(CameraConstant.FAILURE_6009);
- }
- }
- public boolean uploadSuccess(String fileId, StringBuilder filePathBuffer) {
- SceneFileBuild sceneFileBuild = findByFileId(fileId);
- if (Objects.isNull(sceneFileBuild))
- return false;
- Long uploadSuccessCount = sceneFileUploadService.countUploadSuccessByFileId(fileId);
- sceneFileBuild.setUploadStatus(UploadStatus.SUCCESS.code());
- sceneFileBuild.setChunks(Integer.valueOf(uploadSuccessCount.toString()));
- sceneFileBuild.setUpdateTime(Calendar.getInstance().getTime());
- this.updateById(sceneFileBuild);
- return true;
- }
- @Override
- public ResultData uploadSuccessBuild(String params) throws Exception {
- log.info("uploadSuccessBuild-params: " + params);
- if (StringUtils.isEmpty(params)) {
- throw new BusinessException(ErrorCode.PARAM_REQUIRED);
- }
- params = params.replaceAll("%2B", "+");
- params = params.replaceAll(" ", "+");
- Base64 base64 = new Base64();
- String cipher = params;
- // 私钥解密过程
- byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()),
- base64.decode(cipher));
- String restr = new String(res, "UTF-8");
- log.debug("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];
- Object folderNameObject = redisUtil.get(fileId);
- String folderName = folderNameObject == null ? null : (String)folderNameObject;
- if(StringUtils.isEmpty(folderName)){
- SceneProPO sceneProPO = sceneProService.getSceneStatusByUnicode("/" + fileId + "/");
- if(sceneProPO != null){
- folderName = sceneProPO.getDataSource().substring(sceneProPO.getDataSource().lastIndexOf("/") + 1);
- }
- if(StringUtils.isEmpty(folderName)){
- SceneFileBuild sceneFileBuild = this.findByFileId(fileId);
- if(sceneFileBuild != null){
- folderName = sceneFileBuild.getUnicode();
- }
- }
- }
- StringBuilder filePathBuffer = new StringBuilder(routeConfig.getHardDisk())
- .append(mac).append(File.separator)
- .append(fileId).append(File.separator)
- .append(folderName).append(File.separator)
- .append("capture").append(File.separator);
- StringBuilder prefixBuffer = new StringBuilder(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator);
- File filePath = new File(filePathBuffer.toString());
- if(!filePath.exists()){
- filePath.mkdirs();
- }
- if(StorageType.AWS.code().equals(type)){
- CreateObjUtil.ossFileCp(ConstantFilePath.OSS_PREFIX + prefixBuffer.toString() + "data.fdage", filePathBuffer.toString() + "data.fdage");
- }else {
- CreateObjUtil.ossUtilCp(ConstantFilePath.OSS_PREFIX + prefixBuffer.toString() + "data.fdage", filePathBuffer.toString());
- }
- buildScene(filePathBuffer.toString(), fileId, true, prefixBuffer.toString());
- return ResultData.ok();
- }
- @Override
- public ResultData turntableUploadSuccess(String params) throws Exception {
- log.info("turntableUploadSuccess-params: " + params);
- if (StringUtils.isEmpty(params)) {
- throw new BusinessException(ErrorCode.PARAM_REQUIRED);
- }
- params = params.replaceAll("%2B", "+");
- params = params.replaceAll(" ", "+");
- Base64 base64 = new Base64();
- String cipher = params;
- // 私钥解密过程
- byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()),
- base64.decode(cipher));
- String restr = new String(res, "UTF-8");
- log.info("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];
- Object folderNameObject = redisUtil.get(fileId);
- String folderName = folderNameObject == null ? null : (String)folderNameObject;
- if(StringUtils.isEmpty(folderName)){
- ScenePlusExt scenePlusExt = scenePlusExtService.list(
- new LambdaQueryWrapper<ScenePlusExt>()
- .like(ScenePlusExt::getDataSource, "%/" + fileId + "/%")).get(0);
- if(scenePlusExt != null){
- folderName = scenePlusExt.getDataSource().substring(scenePlusExt.getDataSource().lastIndexOf("/") + 1);
- }
- if(StringUtils.isEmpty(folderName)){
- SceneFileBuild sceneFileBuild = this.findByFileId(fileId);
- if(sceneFileBuild != null){
- folderName = sceneFileBuild.getUnicode();
- }
- }
- }
- //判断 是否为激光相机
- Camera camera = cameraService.getByChildName(mac);
- CameraDetail cameraDetail = cameraDetailService.getByCameraId(camera.getId());
- String hardDisk = routeConfig.getHardDisk();
- if(cameraDetail!=null){
- if(cameraDetail.getType() == 10){
- hardDisk = routeConfig.getHardDiskLaser();
- }
- }
- log.info("相机 mnt 路径 : " + hardDisk + ", 相机类型 : " + cameraDetail.getType());
- //本机目录
- StringBuilder filePathBuffer = new StringBuilder(hardDisk).append(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator).append("capture").append(File.separator);
- //云目录
- StringBuilder prefixBuffer = new StringBuilder(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator);
- File filePath = new File(filePathBuffer.toString());
- if(!filePath.exists()){
- filePath.mkdirs();
- }
- if(StorageType.AWS.code().equals(type)){
- CreateObjUtil.ossFileCp(ConstantFilePath.OSS_PREFIX + prefixBuffer.toString() + "data.fdage", filePathBuffer.toString() + "data.fdage");
- }else {
- CreateObjUtil.ossUtilCp(ConstantFilePath.OSS_PREFIX + prefixBuffer.toString() + "data.fdage", filePathBuffer.toString());
- }
- turntableBuildScene(filePathBuffer.toString(), fileId, true, prefixBuffer.toString());
- return ResultData.ok();
- }
- public void turntableBuildScene(String filePath, String fileId, boolean fromOss, String prefix) throws Exception{
- String data = FileUtils.readFile(filePath + "data.fdage");
- JSONObject jsonObject = JSONObject.parseObject(data);
- //调用createScene方法生成scene数据和加入算法队列
- if(jsonObject == null) {
- log.info("data.fdage文件不存在");
- throw new BusinessException(CameraConstant.FAILURE_6009);
- }
- String sceneNum = "";
- String snCode = jsonObject.getJSONObject("cam").getString("uuid");
- String unicode = jsonObject.getString("creator") + "_" + jsonObject.getString("uuidtime"); //从data.fage 取出
- //查看场景中的文件目录是否有改文件id,有则重新计算改场景,无则新建场景
- ScenePlus scene = scenePlusService.getByFileId("/" + fileId + "/");
- int rebuild = 1;
- log.info("是否是重算,rebuild:{}",rebuild);
- log.info("查询相机:" + snCode);
- Camera camera = cameraService.getByChildName(snCode);
- if(camera == null){
- log.error("该相机不存在:" + snCode);
- camera = cameraService.getBySnCode(snCode);
- if(camera == null){
- throw new BusinessException(CameraConstant.FAILURE_6003);
- }
- }
- CameraDetail cameraDetail = cameraDetailService.getByCameraId(camera.getId());
- if(cameraDetail == null){
- log.error("该相机详情不存在:" + snCode);
- throw new BusinessException(CameraConstant.FAILURE_6003);
- }
- if(Objects.nonNull(scene)){
- sceneNum = scene.getNum();
- if(scene.getSceneStatus() == SceneStatus.wait.code()){
- log.info(sceneNum + ":场景处于计算中,不能再计算");
- return;
- }
- }else {
- sceneNum = scene3dNumService.generateSceneNum(cameraDetail.getType());
- rebuild = 0;
- }
- if(sceneNum == null){
- log.error("大场景序号为空:" + sceneNum);
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
- }
- String localDataPath = String.format(ConstantFilePath.DATABUFFER_FORMAT, sceneNum);
- String localImagesPath = String.format(ConstantFilePath.IMAGESBUFFER_FORMAT, sceneNum);
- String imageViewPath = String.format(UploadFilePath.IMG_VIEW_PATH, sceneNum);
- String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, sceneNum);
- String userName = null;
- if(cameraDetail.getUserId() != null){
- SSOUser user = userService.getSSOUserByUserId(cameraDetail.getUserId());
- if(user != null){
- userName = user.getUserName();
- }
- }
- String icon = null;
- if(jsonObject.containsKey("icon") && StrUtil.isNotEmpty(jsonObject.getString("icon"))){
- CreateObjUtil.ossUtilCp(ConstantFilePath.OSS_PREFIX + prefix + jsonObject.getString("icon"), filePath);
- icon = prefixAli + imageViewPath + jsonObject.getString("icon");
- if(StorageType.AWS.code().equals(type)){
- CreateObjUtil.ossFileCp(ConstantFilePath.OSS_PREFIX + prefix + jsonObject.getString("icon"), filePath + jsonObject.getString("icon"));
- icon = ConstantUrl.PREFIX_AWS + imageViewPath + jsonObject.getString("icon");
- }
- uploadToOssUtil.upload(filePath + jsonObject.getString("icon"), imageViewPath + jsonObject.getString("icon"));
- log.info("上传icon成功....");
- }
- JSONObject firmwareVersion = new JSONObject();
- if(jsonObject.containsKey("camSoftwareVersion") && StrUtil.isNotEmpty(jsonObject.getString("camSoftwareVersion"))){
- firmwareVersion.put("camSoftwareVersion", jsonObject.getString("camSoftwareVersion"));
- }
- if(jsonObject.containsKey("version") && StrUtil.isNotEmpty(jsonObject.getString("version"))){
- firmwareVersion.put("version", jsonObject.getString("version"));
- }
- String sceneUrl = mainUrl + sceneProNewUrl;
- String buildType = "V3";
- //13表示转台
- Long cameraType = 13L;
- //激光转台 八目相机占用 10 和 11
- if(jsonObject.getJSONObject("cam").getIntValue("type") == 10){
- //激光转台
- cameraType = 14L;
- }
- //重算的场景,先移除该场景对应的容量
- if(rebuild == 1){
- scenePlusService.resetSpace(sceneNum);
- }else {
- //上传log-main.png
- uploadToOssUtil.upload(ConstantFilePath.LOGO_PATH + "logo-main.png", imageViewPath + "logo-main.png");
- uploadToOssUtil.upload(ConstantFilePath.LOGO_PATH + "logo-main-en.png", imageViewPath + "logo-main-en.png");
- log.info("第一次计算场景,上传logo-main.png");
- }
- Object[] objects = this.createScenePlus(sceneNum, camera.getId(), camera.getChildName(), jsonObject.getString("creator"),
- jsonObject.getString("pwd"), unicode,
- cameraType, String.valueOf(fileId), prefix, "", icon, "0", cameraDetail.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"), rebuild,
- jsonObject.getInteger("resolution"), firmwareVersion.toString(), sceneUrl, buildType, ecsType, cameraDetail.getCooperationUser());
- BuildSceneCallMessage mqMessage = (BuildSceneCallMessage)objects[1];
- ScenePlusVO scenePlusVO = (ScenePlusVO) objects[0];
- if(scenePlusVO != null){
- JSONObject statusJson = new JSONObject();
- //临时将-2改成1,app还没完全更新
- statusJson.put("status", scenePlusVO.getSceneStatus() == -2? 1 : scene.getSceneStatus());
- statusJson.put("webSite", scenePlusVO.getWebSite());
- statusJson.put("sceneNum", scenePlusVO.getNum());
- statusJson.put("thumb", scenePlusVO.getThumb());
- statusJson.put("payStatus", scenePlusVO.getPayStatus());
- statusJson.put("recStatus", scenePlusVO.getRecStatus());
- FileUtils.writeFile(localDataPath + "status.json", statusJson.toString());
- uploadToOssUtil.upload(localDataPath + "status.json", dataViewPath + File.separator+"status.json");
- log.info("上传status.json,上传内容:{}" + statusJson.toString());
- }
- if(cameraDetail.getCompanyId() != null){
- Company company = companyService.getById(cameraDetail.getCompanyId());
- if(company != null){
- Map<String, Object> jsonMap = new HashMap<>();
- log.info("复制企业logo");
- SceneEditInfo sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlusVO.getId());
- // SceneProEdit sceneProEdit = sceneProEditService.findByProId(scene.getId());
- // SceneProEditExt sceneProEditExt = sceneProEditExtService.getByProEditId(sceneProEdit.getId());
- if(StrUtil.isNotEmpty(company.getTopLogo())){
- FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + company.getTopLogo(),localImagesPath + "logo-main.png", true);
- uploadToOssUtil.upload(localImagesPath + "logo-main.png", imageViewPath + "logo-main.png");
- }
- if(StrUtil.isNotEmpty(company.getFloorLogo())){
- FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + company.getFloorLogo(),
- localImagesPath + "floorLogoImg.png", true);
- uploadToOssUtil.upload(localImagesPath + "floorLogoImg.png",
- imageViewPath + "floorLogoImg.png");
- sceneEditInfo.setFloorLogo("user");
- }
- if(StrUtil.isNotEmpty(company.getQrLogo())){
- // TODO: 2022/7/25 目前v4版本不需要生成带logo的二维码,这里先注释掉 dsx-------------------------------start
- // FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + company.getQrLogo(),
- // ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png", true);
- //
- // uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png",
- // imageViewPath + "QRShareLogo.png");
- //
- // // TODO: 2022/1/24 暂时保留旧版本,系统稳定后删除
- // uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png",
- // "images/images" + sceneNum + "/QRShareLogo.png");
- //
- //// sceneProEdit.setShareLogo("images/images" + sceneNum + "/QRShareLogo.png");//旧系统代码,先保留
- // sceneProEdit.setShareLogo(imageViewPath + "QRShareLogo.png");
- // TODO: 2022/7/25 目前v4版本不需要生成带logo的二维码,这里先注释掉 dsx-------------------------------end
- //生成新的分享的二维码-中文版本
- MatrixToImageWriterUtil.createQRCode(sceneUrl + sceneNum, ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneNum+".png",
- false, ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png");
- //生成新的分享的二维码-英文版本
- MatrixToImageWriterUtil.createQRCode(sceneUrl + sceneNum + "&lang=en", ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneNum+"_en.png",
- false, ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png");
- }
- // TODO: 2022/7/25 目前v4版本还没开发地面点位log功能,这里先注释掉 dsx-------------------------------start
- // if(StrUtil.isNotEmpty(company.getMarkerLogo())){
- // FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + company.getMarkerLogo(),
- // ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/marker.png", true);
- // uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/marker.png",
- // imageViewPath + "marker.png");
- //
- // // TODO: 2022/1/24 暂时保留旧版本,系统稳定后删除
- // uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/marker.png",
- // "images/images" + sceneNum + "/marker.png");
- //
- // sceneProEdit.setMarkerLogo("user");
- // jsonMap.put("markerLogo", "user");
- // }
- // TODO: 2022/7/25 目前v4版本还没开发地面点位log功能,这里先注释掉 dsx-------------------------------end
- sceneEditInfoService.updateById(sceneEditInfo);
- }
- //删除oss的houst_floor.json
- uploadToOssUtil.delete(dataViewPath + "houst_floor.json");
- }
- //激光转台 八目相机占用 10 和 11
- log.info("发送mq,camType:{}", jsonObject.getJSONObject("cam").getIntValue("type"));
- if(jsonObject.getJSONObject("cam").getIntValue("type") == 10){
- // mqProducer.sendOneWay(topicLaserA, mqMessage);
- // TODO: 2022/3/19 这里应该是发送激光的 ,目前还不清楚,先统一发送同一个mq
- rabbitMqProducer.sendByWorkQueue(queueModelingPre, mqMessage);
- }else if(scene != null){
- rabbitMqProducer.sendByWorkQueue(queueModelingPre, mqMessage);
- }
- }
- public Object[] createScenePlus(String projectNum, Long cameraId, String cameraName, String phoneId, String sceneKey,
- String unicode, Long cameraType, String fileId, String prefix,
- String imgsName, String pic, String isModel, 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, String ecsType,
- 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);
- String path = ConstantFilePath.BUILD_MODEL_PATH + unicode;
- scenePlus.setSceneSource(1);
- if(cameraType.longValue() == 5 || cameraType.longValue() == 6){
- //场景来源双目相机
- scenePlus.setSceneSource(2);
- scenePlusExt.setDataSource(ConstantFilePath.BUILD_MODEL_PATH + unicode);
- }else if(cameraType.longValue() == 14){
- scenePlusExt.setDataSource(ConstantFilePath.BUILD_MODEL_LASER_PATH +
- cameraName.replace("4DKKPRO_", "").replace("-fdage", "").toLowerCase() + File.separator +
- fileId + File.separator + unicode);
- path = ConstantFilePath.BUILD_MODEL_LASER_PATH + unicode;
- log.info("激光相机 dataSource :" + scenePlusExt.getDataSource());
- }else if(cameraType.longValue() >= 3){
- scenePlusExt.setDataSource(ConstantFilePath.BUILD_MODEL_PATH +
- cameraName.replace("4DKKPRO_", "").replace("-fdage", "").toLowerCase() + File.separator +
- fileId + File.separator + unicode);
- }else {
- scenePlusExt.setDataSource(prefix+imgsName);
- }
- if(!org.springframework.util.StringUtils.isEmpty(ecsType)){
- scenePlusExt.setEcs(ecsType);
- }
- if(resolution == null || resolution.intValue() == 0){
- scenePlusExt.setSceneScheme(cameraType.intValue());
- }else {
- scenePlusExt.setSceneScheme(4);
- }
- //场景来源双目相机,sceneScheme为4,加载high,low图
- if(cameraType.longValue() == 5 || cameraType.longValue() == 6){
- scenePlusExt.setSceneScheme(4);
- }
- //转台相机用4k图
- if(cameraType.longValue() == 13 ){
- scenePlus.setSceneSource(3);
- scenePlusExt.setSceneScheme(10);
- }
- //激光相机
- if(cameraType.longValue() == 14 ){
- scenePlus.setSceneSource(4);
- scenePlusExt.setSceneScheme(10);
- }
- if(pic!=null&&pic.length()>5)
- {
- scenePlusExt.setThumb(pic);
- }
- else
- {
- scenePlusExt.setThumb(ConstantUrl.DEFAULT_SCENE_PIC);
- }
- scenePlusExt.setThumb(scenePlusExt.getThumb().concat("?t=")+System.currentTimeMillis());
- if(!ObjectUtils.isEmpty(userName)){
- scenePlus.setUserId(userId);
- }
- if(sceneShootCount == null)
- {
- scenePlusExt.setShootCount(0);
- }
- else
- {
- scenePlusExt.setShootCount(sceneShootCount);
- }
- if(sceneName!=null)
- {
- scenePlus.setTitle(sceneName);
- }
- if(sceneDec!=null)
- {
- scenePlus.setDescription("<p>"+ new String(sceneDec.getBytes("UTF-8"))+"</p>");
- }
- 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.setScenePlusId(scenePlus.getId());
- if(StrUtil.isNotBlank(sceneKey)) {
- sceneEditInfo.setScenePassword(sceneKey);
- sceneEditControls.setShowLock((int) CommonStatus.YES.code());
- }
- sceneEditInfoService.save(sceneEditInfo);
- sceneEditControls.setEditInfoId(sceneEditInfo.getId());
- sceneEditControlsService.save(sceneEditControls);
- //新增场景时,同时新增场景协作信息
- if(cooperationUser != null){
- SceneCooperation sceneCooperationEntity = new SceneCooperation();
- sceneCooperationEntity.setNum(projectNum);
- sceneCooperationEntity.setUserId(cooperationUser);
- sceneCooperationService.save(sceneCooperationEntity);
- List<SceneResourceCamera> resourceCameraList = sceneResourceCameraService.findListByCameraId(cameraId);
- SceneResourceCooperation sceneResourceCooperation = null;
- if(resourceCameraList != null && resourceCameraList.size() > 0){
- for (SceneResourceCamera sceneResourceCamera : resourceCameraList) {
- sceneResourceCooperation = new SceneResourceCooperation();
- sceneResourceCooperation.setSceneResourceId(sceneResourceCamera.getSceneResourceId());
- sceneResourceCooperation.setSceneCooperationId(sceneCooperationEntity.getId());
- sceneResourceCooperationService.save(sceneResourceCooperation);
- }
- }
- }
- }else {
- ScenePlus oldScene = scenePlusService.getScenePlusByNum(projectNum);
- scenePlus.setId(oldScene.getId());
- scenePlus.setSceneStatus(0);
- scenePlus.setRecStatus(RecStatus.VALID.code());
- scenePlus.setPayStatus(0);
- scenePlus.setCreateTime(Calendar.getInstance().getTime());
- ScenePlusExt oldSceneExt = scenePlusExtService.getScenePlusExtByPlusId(oldScene.getId());
- scenePlusExt.setSpace(oldSceneExt.getSpace());
- scenePlusExt.setEcs(oldSceneExt.getEcs());
- scenePlusExt.setViewCount(oldSceneExt.getViewCount());
- if(sceneName!=null) {
- scenePlus.setTitle(sceneName);
- }
- if(sceneType!=null) {
- scenePlus.setSceneType(sceneType);
- }
- scenePlusService.updateById(scenePlus);
- scenePlusExtService.updateById(scenePlusExt);
- SceneEditInfo oldSceneEditInfo = sceneEditInfoService.getByScenePlusId(oldScene.getId());
- SceneEditInfoExt oldSceneEditeIinfoExt = sceneEditInfoExtService.getByEditInfoId(oldSceneEditInfo.getId());
- if(StrUtil.isNotBlank(sceneKey)) {
- sceneEditInfo.setScenePassword(sceneKey);
- sceneEditControls.setShowLock((int) CommonStatus.YES.code());
- }else{
- sceneEditInfo.setScenePassword("");
- sceneEditControls.setShowLock((int)CommonStatus.NO.code());
- }
- sceneEditInfo.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);
- sceneEditInfoExt.setId(oldSceneEditeIinfoExt.getId());
- sceneEditInfoExt.setEditInfoId(sceneEditInfo.getId());
- sceneEditInfoExt.setScenePlusId(scenePlus.getId());
- sceneEditInfoExtService.updateById(sceneEditInfoExt);
- }
- BuildSceneCallMessage buildSceneMqMessage =this.getBuildSceneMqMessage(
- projectNum, cameraName, unicode, cameraType, fileId, prefix, imgsName, isModel,
- userName, algorithm, resolution, buildType, path, scenePlus.getId(), scenePlus.getTitle(),
- scenePlusExt.getWebSite(), scenePlus.getCreateTime(), scenePlus.getUserId(),
- scenePlusExt.getDataSource(), scenePlus.getSceneStatus(), scenePlus.getPayStatus(), scenePlusExt.getThumb());
- BeanUtil.copyProperties(scenePlusExt, scenePlusVO);
- BeanUtil.copyProperties(scenePlus, scenePlusVO);
- //当mq排队数大于指定数量时使用弹性升缩
- return new Object[]{scenePlusVO, buildSceneMqMessage};
- }
- public BuildSceneCallMessage getBuildSceneMqMessage(String projectNum, String cameraName, String unicode,
- Long cameraType, String fileId,String prefix, String imgsName,
- String isModel, String userName,String algorithm, Integer resolution,
- String buildType, String path, Long sceneProId, String sceneName, String webSite,
- Date sceneProCreateTime, Long userId, String dataSource,
- Integer sceneStatus, Integer PayStatus, String thumb) {
- BuildSceneCallMessage mqMsg = new BuildSceneCallMessage();
- mqMsg.setSceneProId(sceneProId);
- mqMsg.setSceneNum(projectNum);
- mqMsg.setCameraName(cameraName);
- mqMsg.setUnicode(unicode);
- mqMsg.setCameraType(String.valueOf(cameraType));
- mqMsg.setFileId(fileId);
- mqMsg.setPrefix(prefix);
- mqMsg.setImgsName(imgsName);
- mqMsg.setIsModel(isModel);
- mqMsg.setUserName(userName);
- mqMsg.setAlgorithm(algorithm);
- mqMsg.setResolution(String.valueOf(resolution));
- mqMsg.setBuildType(buildType);
- mqMsg.setPath(path);
- mqMsg.setSceneName(sceneName);
- mqMsg.setWebSite(webSite);
- mqMsg.setSceneProCreateTime(sceneProCreateTime);
- mqMsg.setUserId(userId);
- mqMsg.setDataSource(dataSource);
- mqMsg.setSceneStatus(sceneStatus);
- mqMsg.setPayStatus(PayStatus);
- mqMsg.setCreateTime(DateUtil.format(Calendar.getInstance().getTime(), DateExtUtil.dateStyle));
- mqMsg.setThumb(thumb);
- return mqMsg;
- }
- @Override
- public ResultData getS3UploadUrl(String params) throws Exception {
- if (StringUtils.isEmpty(params)) {
- throw new BusinessException(ErrorCode.PARAM_REQUIRED);
- }
- JSONObject jsonObject = JSON.parseObject(params);
- if(jsonObject == null){
- throw new BusinessException(ErrorCode.PARAM_FORMAT_ERROR);
- }
- JSONArray files = jsonObject.getJSONArray("Files");
- if(files == null){
- throw new BusinessException(ErrorCode.PARAM_FORMAT_ERROR);
- }
- List<String> urls = new ArrayList<>();
- for(int i = 0, len = files.size(); i < len; i++){
- urls.add(files.getJSONObject(i).getString("filename"));
- }
- return ResultData.ok(uploadToOssUtil.getUploadS3Url(urls));
- }
- @Override
- public ResultData buildLiteScene(String prefix, String dataFdage, String zipName, String userName, String password, String oldNum) throws Exception{
- log.info("参数-prefix: {}, dataFdage: {}, zipName: {}, password: {}, userName: {}", prefix,
- dataFdage, zipName, password, userName);
- if(StringUtils.isEmpty(prefix) || StringUtils.isEmpty(dataFdage) || StringUtils.isEmpty(zipName) ||
- StringUtils.isEmpty(userName) || StringUtils.isEmpty(password)){
- throw new BusinessException(ErrorCode.PARAM_REQUIRED);
- }
- Camera camera = cameraService.getByChildName(userName);
- if(camera == null){
- camera = cameraService.getBySnCode(userName);
- }
- if (camera == null){
- throw new BusinessException(CameraConstant.FAILURE_6003);
- }
- if(!password.equals(camera.getChildPassword())){
- throw new BusinessException(ErrorCode.FAILURE_CODE_3014);
- }
- CameraDetail cameraDetail = cameraDetailService.getByCameraId(camera.getId());
- if(cameraDetail == null){
- throw new BusinessException(CameraConstant.FAILURE_6003);
- }
- String unicode = prefix.substring(prefix.lastIndexOf("/") + 1);
- String path = ConstantFilePath.BUILD_MODEL_PATH + unicode;
- //下载data.fdage
- FileUtils.downLoadFromUrl(prefix + "/" + dataFdage + "?m=" + System.currentTimeMillis(), dataFdage, path + File.separator + "capture");
- String data = FileUtils.readFile(path + File.separator + "capture/" + dataFdage);
- JSONObject jsonObject = JSONObject.parseObject(data);
- if(jsonObject == null){
- log.info("data.fdage不存在");
- throw new BusinessException(CameraConstant.FAILURE_6009);
- }
- String sceneNum = "";
- //查看场景中的文件目录是否有改文件id,有则重新计算改场景,无则新建场景
- ScenePlus scenePlus = scenePlusService.getByFileId("/" + unicode);
- int rebuild = 1;
- if(StrUtil.isNotEmpty(oldNum)){
- sceneNum = oldNum;
- }else {
- if(scenePlus != null){
- sceneNum = scenePlus.getNum();
- //重算的场景,先移除该场景对应的容量
- scenePlusService.resetSpace(sceneNum);
- }else {
- sceneNum = scene3dNumService.generateSceneNum(cameraDetail.getType());
- rebuild = 0;
- }
- }
- String localDataPath = String.format(ConstantFilePath.DATABUFFER_FORMAT, sceneNum);
- String imgViewPath = String.format(UploadFilePath.IMG_VIEW_PATH, sceneNum);
- String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, sceneNum);
- String cameraName = jsonObject.getJSONObject("cam").getString("uuid");
- log.info("查询相机:" + cameraName);
- camera = cameraService.getByChildName(cameraName);
- if(camera == null){
- log.error("该相机不存在:" + cameraName);
- //偶现data.fdage给的相机码多了或少了4DKKPRO_
- if(cameraName.contains("4DKKPRO_")){
- camera = cameraService.getByChildName(cameraName.replace("4DKKPRO_", ""));
- }else {
- camera = cameraService.getByChildName("4DKKPRO_" + cameraName);
- }
- if(camera == null){
- throw new BusinessException(CameraConstant.FAILURE_6003);
- }
- }
- String icon = null;
- if(jsonObject.containsKey("icon") && StrUtil.isNotEmpty(jsonObject.getString("icon"))){
- //下载封面图icon
- FileUtils.downLoadFromUrl(prefix + "/" + jsonObject.getString("icon") + "?m=" + System.currentTimeMillis(), jsonObject.getString("icon"), path + File.separator + "capture");
- uploadToOssUtil.upload(path + File.separator + "capture" + File.separator +
- jsonObject.getString("icon"), imgViewPath + jsonObject.getString("icon"));
- icon = prefixAli + imgViewPath + jsonObject.getString("icon");
- if(StorageType.AWS.code().equals(type)){
- icon = ConstantUrl.PREFIX_AWS + imgViewPath + jsonObject.getString("icon");
- }
- }
- JSONObject firmwareVersion = new JSONObject();
- if(jsonObject.containsKey("camSoftwareVersion") && StrUtil.isNotEmpty(jsonObject.getString("camSoftwareVersion"))){
- firmwareVersion.put("camSoftwareVersion", jsonObject.getString("camSoftwareVersion"));
- }
- if(jsonObject.containsKey("version") && StrUtil.isNotEmpty(jsonObject.getString("version"))){
- firmwareVersion.put("version", jsonObject.getString("version"));
- }
- String sceneUrl = mainUrl + sceneProNewUrl;
- String buildType = "V3";
- //表示新款双目
- Long cameraType = 5L;
- if(jsonObject.getJSONObject("cam").getIntValue("type") == 5){
- //6表示小红屋双目
- cameraType = 6L;
- }
- Object[] objects = this.createScenePlus(sceneNum, camera.getId(), camera.getChildName(),
- jsonObject.getString("creator"),
- jsonObject.getString("pwd"), unicode,
- cameraType, "", prefix, zipName, icon, "0", cameraDetail.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"), rebuild,
- 4, firmwareVersion.toString(), sceneUrl, buildType, ecsType,
- cameraDetail.getCooperationUser());
- BuildSceneCallMessage mqMessage = (BuildSceneCallMessage)objects[1];
- ScenePlusVO scenePlusVO = (ScenePlusVO) objects[0];
- if(scenePlusVO == null){
- log.info("双目相机入库失败");
- return ResultData.error(ErrorCode.FAILURE_CODE_5056);
- }
- JSONObject statusJson = new JSONObject();
- //临时将-2改成1,app还没完全更新
- statusJson.put("status", scenePlusVO.getSceneStatus() == -2? 1 : scenePlusVO.getSceneStatus());
- statusJson.put("webSite", scenePlusVO.getWebSite());
- statusJson.put("sceneNum", scenePlusVO.getNum());
- statusJson.put("thumb", scenePlusVO.getThumb());
- statusJson.put("payStatus", scenePlusVO.getPayStatus());
- FileUtils.writeFile(localDataPath + "status.json", statusJson.toString());
- uploadToOssUtil.upload(localDataPath + "status.json", dataViewPath + "status.json");
- //删除oss的houst_floor.json
- uploadToOssUtil.delete(dataViewPath + "houst_floor.json");
- rabbitMqProducer.sendByWorkQueue(queueModelingPre, mqMessage);
- Map<String, String> map = new HashMap<>();
- map.put("sceneNum", sceneNum);
- map.put("sceneUrl", sceneUrl + sceneNum);
- return ResultData.ok(map);
- }
- @Override
- public ResultData buildScene(String prefix, String unicode, String zip, String dataFdage) throws Exception{
- String data = FileUtils.readFile(ConstantFilePath.BUILD_MODEL_PATH + unicode + "/data.fdage");
- JSONObject jsonObject = JSONObject.parseObject(data);
- String cameraName = jsonObject.getJSONObject("cam").getString("uuid");
- log.info("查询相机:" + cameraName);
- Camera cameraEntity = cameraService.getByChildName(cameraName);
- if(cameraEntity == null){
- log.error("该相机不存在:" + cameraName);
- //偶现data.fdage给的相机码多了或少了4DKKPRO_
- if(cameraName.contains("4DKKPRO_")){
- cameraEntity = cameraService.getByChildName(cameraName.replace("4DKKPRO_", ""));
- }else {
- cameraEntity = cameraService.getByChildName("4DKKPRO_" + cameraName);
- }
- if(cameraEntity == null){
- throw new BusinessException(CameraConstant.FAILURE_6003);
- }
- }
- CameraDetail detailEntity = cameraDetailService.getByCameraId(cameraEntity.getId());
- if(detailEntity == null){
- log.error("该相机详情不存在:" + cameraName);
- throw new BusinessException(CameraConstant.FAILURE_6003);
- }
- String sceneNum = scene3dNumService.generateSceneNum(detailEntity.getType());
- return ResultData.ok(mainUrl + sceneProNewUrl + sceneNum);
- }
- }
|