SceneFileBuildServiceImpl.java 81 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690
  1. package com.fdkankan.contro.service.impl;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import cn.hutool.core.collection.CollUtil;
  4. import cn.hutool.core.date.DateUtil;
  5. import cn.hutool.core.util.StrUtil;
  6. import com.alibaba.fastjson.JSON;
  7. import com.alibaba.fastjson.JSONArray;
  8. import com.alibaba.fastjson.JSONObject;
  9. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  10. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  11. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  12. import com.fdkankan.common.constant.CameraConstant;
  13. import com.fdkankan.common.constant.CommonStatus;
  14. import com.fdkankan.common.constant.ConstantFilePath;
  15. import com.fdkankan.common.constant.ConstantUrl;
  16. import com.fdkankan.common.constant.ErrorCode;
  17. import com.fdkankan.common.constant.RecStatus;
  18. import com.fdkankan.common.constant.SceneStatus;
  19. import com.fdkankan.common.constant.UploadFilePath;
  20. import com.fdkankan.common.constant.UploadStatus;
  21. import com.fdkankan.common.exception.BusinessException;
  22. import com.fdkankan.common.response.ResultData;
  23. import com.fdkankan.common.util.ComputerUtil;
  24. import com.fdkankan.common.util.CreateObjUtil;
  25. import com.fdkankan.common.util.DateExtUtil;
  26. import com.fdkankan.common.util.FileMd5Util;
  27. import com.fdkankan.common.util.FileUpload;
  28. import com.fdkankan.common.util.FileUtil;
  29. import com.fdkankan.common.util.FileUtils;
  30. import com.fdkankan.common.util.MatrixToImageWriterUtil;
  31. import com.fdkankan.common.util.RSAEncrypt;
  32. import com.fdkankan.common.util.SnowflakeIdGenerator;
  33. import com.fdkankan.contro.config.FileRouteConfig;
  34. import com.fdkankan.contro.entity.Camera;
  35. import com.fdkankan.contro.entity.CameraDetail;
  36. import com.fdkankan.contro.entity.Company;
  37. import com.fdkankan.contro.entity.SSOUser;
  38. import com.fdkankan.contro.entity.SceneCooperation;
  39. import com.fdkankan.contro.entity.SceneEditControls;
  40. import com.fdkankan.contro.entity.SceneEditInfo;
  41. import com.fdkankan.contro.entity.SceneEditInfoExt;
  42. import com.fdkankan.contro.entity.SceneFileBuild;
  43. import com.fdkankan.contro.entity.SceneFileUpload;
  44. import com.fdkankan.contro.entity.ScenePlus;
  45. import com.fdkankan.contro.entity.ScenePlusExt;
  46. import com.fdkankan.contro.entity.SceneProPO;
  47. import com.fdkankan.contro.entity.SceneResourceCamera;
  48. import com.fdkankan.contro.entity.SceneResourceCooperation;
  49. import com.fdkankan.contro.mapper.ISceneFileBuildMapper;
  50. import com.fdkankan.contro.service.ICameraDetailService;
  51. import com.fdkankan.contro.service.ICameraService;
  52. import com.fdkankan.contro.service.ICompanyService;
  53. import com.fdkankan.contro.service.IScene3dNumService;
  54. import com.fdkankan.contro.service.ISceneCooperationService;
  55. import com.fdkankan.contro.service.ISceneEditControlsService;
  56. import com.fdkankan.contro.service.ISceneEditInfoExtService;
  57. import com.fdkankan.contro.service.ISceneEditInfoService;
  58. import com.fdkankan.contro.service.ISceneFileBuildService;
  59. import com.fdkankan.contro.service.ISceneFileUploadService;
  60. import com.fdkankan.contro.service.IScenePlusExtService;
  61. import com.fdkankan.contro.service.IScenePlusService;
  62. import com.fdkankan.contro.service.ISceneProEditExtService;
  63. import com.fdkankan.contro.service.ISceneProEditService;
  64. import com.fdkankan.contro.service.ISceneProExtService;
  65. import com.fdkankan.contro.service.ISceneProService;
  66. import com.fdkankan.contro.service.ISceneResourceCameraService;
  67. import com.fdkankan.contro.service.ISceneResourceCooperationService;
  68. import com.fdkankan.contro.service.IUserService;
  69. import com.fdkankan.contro.vo.ResponseSceneFile;
  70. import com.fdkankan.contro.vo.ScenePlusVO;
  71. import com.fdkankan.fyun.constant.StorageType;
  72. import com.fdkankan.fyun.oss.UploadToOssUtil;
  73. import com.fdkankan.rabbitmq.bean.BuildSceneCallMessage;
  74. import com.fdkankan.rabbitmq.util.RabbitMqProducer;
  75. import com.fdkankan.redis.util.RedisUtil;
  76. import java.io.File;
  77. import java.io.IOException;
  78. import java.time.LocalDate;
  79. import java.util.ArrayList;
  80. import java.util.Arrays;
  81. import java.util.Calendar;
  82. import java.util.Date;
  83. import java.util.HashMap;
  84. import java.util.List;
  85. import java.util.Map;
  86. import java.util.Objects;
  87. import java.util.UUID;
  88. import lombok.extern.slf4j.Slf4j;
  89. import org.apache.commons.codec.binary.Base64;
  90. import org.apache.commons.lang3.StringUtils;
  91. import org.springframework.beans.factory.annotation.Autowired;
  92. import org.springframework.beans.factory.annotation.Value;
  93. import org.springframework.stereotype.Service;
  94. import org.springframework.util.ObjectUtils;
  95. import org.springframework.web.multipart.MultipartFile;
  96. /**
  97. * <p>
  98. * 场景文件建模表 服务实现类
  99. * </p>
  100. *
  101. * @author dengsixing
  102. * @since 2021-12-23
  103. */
  104. @Slf4j
  105. @Service
  106. public class SceneFileBuildServiceImpl extends ServiceImpl<ISceneFileBuildMapper, SceneFileBuild> implements ISceneFileBuildService {
  107. private static final String SPLICE = "#";
  108. @Value("${main.url}")
  109. private String mainUrl;
  110. @Value("${scene.pro.url}")
  111. private String sceneProUrl;
  112. @Value("${scene.pro.new.url}")
  113. private String sceneProNewUrl;
  114. @Value("${upload.type}")
  115. private String type;
  116. @Value("${oss.prefix.ali}")
  117. private String prefixAli;
  118. @Value("${ecs.type}")
  119. private String ecsType;
  120. @Value("${unCalculated.company.ids:#{null}}")
  121. private String[] unCalculatedCompanyIds;
  122. @Value("${queue.modeling.modeling-call}")
  123. private String queueModelingCall;
  124. @Value("${queue.modeling.modeling-pre}")
  125. private String queueModelingPre;
  126. @Value("${queue.modeling.video-a}")
  127. private String queueVideoA;
  128. @Value("${queue.modeling.pic-a}")
  129. private String queuePicA;
  130. @Autowired
  131. private ISceneFileUploadService sceneFileUploadService;
  132. @Autowired
  133. private ISceneProService sceneProService;
  134. @Autowired
  135. private RedisUtil redisUtil;
  136. @Autowired
  137. private FileRouteConfig routeConfig;
  138. @Autowired
  139. private UploadToOssUtil uploadToOssUtil;
  140. @Autowired
  141. private IScenePlusExtService scenePlusExtService;
  142. @Autowired
  143. private IScene3dNumService scene3dNumService;
  144. @Autowired
  145. private IScenePlusService scenePlusService;
  146. @Autowired
  147. private RabbitMqProducer rabbitMqProducer;
  148. @Autowired
  149. private ISceneProEditService sceneProEditService;
  150. @Autowired
  151. private ISceneEditInfoService sceneEditInfoService;
  152. @Autowired
  153. private ISceneEditControlsService sceneEditControlsService;
  154. @Autowired
  155. private ISceneEditInfoExtService sceneEditInfoExtService;
  156. @Autowired
  157. private ISceneCooperationService sceneCooperationService;
  158. @Autowired
  159. private ISceneResourceCameraService sceneResourceCameraService;
  160. @Autowired
  161. private ISceneResourceCooperationService sceneResourceCooperationService;
  162. @Autowired
  163. private ICameraService cameraService;
  164. @Autowired
  165. private ICameraDetailService cameraDetailService;
  166. @Autowired
  167. private IUserService userService;
  168. @Autowired
  169. private ICompanyService companyService;
  170. @Autowired
  171. private ISceneProEditExtService sceneProEditExtService;
  172. @Autowired
  173. private ISceneProExtService sceneProExtService;
  174. @Override
  175. public SceneFileBuild findByFileId(String fileId) {
  176. List<SceneFileBuild> list = this.list(new LambdaQueryWrapper<SceneFileBuild>()
  177. .eq(SceneFileBuild::getFileId, fileId)
  178. .orderByDesc(SceneFileBuild::getId));
  179. if(CollUtil.isEmpty(list))
  180. return null;
  181. return list.get(0);
  182. }
  183. @Override
  184. public ResponseSceneFile preUpload(String params) throws Exception {
  185. log.info("preUpload-params: "+params);
  186. if (StrUtil.isEmpty(params)){
  187. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  188. }
  189. params = params.replaceAll("%2B", "+");
  190. Base64 base64 = new Base64();
  191. String cipher = params;
  192. // 私钥解密过程
  193. byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()),
  194. base64.decode(cipher));
  195. String restr = new String(res, "UTF-8");
  196. log.debug("preUpload-params解密结果:" + restr);
  197. String[] strArr = restr.split(SPLICE);
  198. if (strArr.length != 5) {
  199. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  200. }
  201. String mac = strArr[0];
  202. String totalPicNum = strArr[1];
  203. String chunks = strArr[2];
  204. String folderName = strArr[3];
  205. if (StrUtil.isEmpty(mac)){
  206. throw new BusinessException(ErrorCode.FAILURE_CODE_5044);
  207. }
  208. if (totalPicNum == null){
  209. throw new BusinessException(ErrorCode.FAILURE_CODE_5045);
  210. }
  211. if (chunks == null){
  212. throw new BusinessException(ErrorCode.FAILURE_CODE_5046);
  213. }
  214. if (folderName == null){
  215. throw new BusinessException(ErrorCode.FAILURE_CODE_5047);
  216. }
  217. log.info("mac:" + mac + "准备上传文件");
  218. String dataSource = scenePlusService.getDataSourceLikeUnicode("/" + folderName);
  219. if(StrUtil.isNotEmpty(dataSource)){
  220. int n = dataSource.split("/").length;
  221. if(n > 1){
  222. String fileId = dataSource.split("/")[n - 2];
  223. ResponseSceneFile responseSceneFile = new ResponseSceneFile();
  224. responseSceneFile.setFileId(fileId);
  225. //可以重复上传,文件id保存50年(因为该redis工具无法设置永久保存)
  226. redisUtil.set(fileId, folderName, 1537920000);
  227. return responseSceneFile;
  228. }
  229. }else {
  230. SceneFileBuild sceneFileBuild = this.findByUnicode(folderName);
  231. if(sceneFileBuild != null){
  232. String fileId = sceneFileBuild.getFileId();
  233. ResponseSceneFile responseSceneFile = new ResponseSceneFile();
  234. responseSceneFile.setFileId(fileId);
  235. //可以重复上传,文件id保存50年(因为该redis工具无法设置永久保存)
  236. redisUtil.set(fileId, folderName, 1537920000);
  237. return responseSceneFile;
  238. }
  239. }
  240. // 构造方法设置机器码:第0个机房的第0台机器
  241. SnowflakeIdGenerator snowflakeIdGenerator = new SnowflakeIdGenerator(0, 0);
  242. long fileId = snowflakeIdGenerator.nextId();
  243. SceneFileBuild sceneFileBuild = new SceneFileBuild();
  244. sceneFileBuild.setChildName(mac);
  245. sceneFileBuild.setFileId(String.valueOf(fileId));
  246. sceneFileBuild.setUnicode(folderName);
  247. sceneFileBuild.setUploadStatus(0);
  248. sceneFileBuild.setBuildStatus(0);
  249. sceneFileBuild.setTotalPicNum(Integer.valueOf(totalPicNum));
  250. sceneFileBuild.setChunks(Integer.valueOf(chunks));
  251. this.save(sceneFileBuild);
  252. ResponseSceneFile responseSceneFile = new ResponseSceneFile();
  253. responseSceneFile.setFileId(String.valueOf(fileId));
  254. //可以重复上传,文件id保存50年(因为该redis工具无法设置永久保存)
  255. redisUtil.set(String.valueOf(fileId), folderName, 1537920000);
  256. return responseSceneFile;
  257. }
  258. public SceneFileBuild findByUnicode(String unicode) {
  259. List<SceneFileBuild> list = this.list(new QueryWrapper<SceneFileBuild>()
  260. .eq("unicode", unicode)
  261. .orderByDesc("id"));
  262. if(CollUtil.isEmpty(list))
  263. return null;
  264. return list.get(0);
  265. }
  266. @Override
  267. public ResponseSceneFile getProgress(String params) throws Exception {
  268. log.info("getProgress-params:{} ", params);
  269. if (StrUtil.isEmpty(params)){
  270. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  271. }
  272. params = params.replaceAll("%2B", "+");
  273. Base64 base64 = new Base64();
  274. String cipher = params;
  275. // 私钥解密过程
  276. byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()),
  277. base64.decode(cipher));
  278. String restr = new String(res, "UTF-8");
  279. log.debug("getProgress-params解密结果:{}" , restr);
  280. String[] strArr = restr.split(SPLICE);
  281. if (strArr.length != 3) {
  282. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  283. }
  284. String fileId = strArr[0];
  285. String chunk = strArr[1];
  286. chunk = chunk.split(SPLICE)[0];
  287. SceneFileUpload sceneFileUpload = sceneFileUploadService.findByFileIdAndChunk(fileId, Integer.valueOf(chunk));
  288. ResponseSceneFile responseSceneFile = new ResponseSceneFile();
  289. responseSceneFile.setUploadStatus(sceneFileUpload != null ? sceneFileUpload.getUploadStatus() : -1);
  290. return responseSceneFile;
  291. }
  292. @Override
  293. public ResultData uploadFile(MultipartFile file, String params) throws Exception{
  294. log.info("upload-params: "+params);
  295. if (StringUtils.isEmpty(params)){
  296. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  297. }
  298. params = params.replaceAll("%2B", "+");
  299. Base64 base64 = new Base64();
  300. String cipher = params;
  301. // 私钥解密过程
  302. byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()),
  303. base64.decode(cipher));
  304. String restr = new String(res, "UTF-8");
  305. log.debug("upload-params解密结果:{}", restr);
  306. String[] strArr = restr.split(SPLICE);
  307. if (strArr.length != 6) {
  308. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  309. }
  310. String mac = strArr[0];
  311. String fileId = strArr[1];
  312. String picNum = strArr[2];
  313. String md5 = strArr[3];
  314. String chunk = strArr[4];
  315. ResultData result = null;
  316. if (file.isEmpty()){
  317. throw new BusinessException(ErrorCode.FAILURE_CODE_5048);
  318. }
  319. if (StringUtils.isEmpty(fileId)){
  320. throw new BusinessException(ErrorCode.FAILURE_CODE_5049);
  321. }
  322. if (picNum == null){
  323. throw new BusinessException(ErrorCode.FAILURE_CODE_5050);
  324. }
  325. if (StringUtils.isEmpty(mac)){
  326. throw new BusinessException(ErrorCode.FAILURE_CODE_5044);
  327. }
  328. if (StringUtils.isEmpty(md5)){
  329. throw new BusinessException(ErrorCode.FAILURE_CODE_5051);
  330. }
  331. long size = file.getSize();
  332. log.warn("fileId:"+fileId+"---picNum:"+picNum+"---size:"+size+"---md5:"+md5+"---mac:"+mac);
  333. chunk = chunk.split(SPLICE)[0];
  334. // 获取文件名
  335. String fileName = file.getOriginalFilename();
  336. log.info("上传的文件名为:" + fileName);
  337. // 获取文件的后缀名
  338. String suffixName = fileName.substring(fileName.lastIndexOf("."));
  339. log.info("上传的后缀名为:" + suffixName);
  340. Object folderNameObject = redisUtil.get(fileId);
  341. String folderName = folderNameObject == null ? null : (String)folderNameObject;
  342. if(StrUtil.isEmpty(folderName)){
  343. String dataSource = scenePlusService.getDataSourceLikeUnicode("/" + fileId + "/");
  344. if(StrUtil.isNotEmpty(dataSource)){
  345. folderName = dataSource.substring(dataSource.lastIndexOf("/") + 1);
  346. }
  347. }
  348. // 1. 判断该文件是否已经上传过
  349. // 2. 如果已经上传过,判断MD5值和文件大小是否相等。如果相等,更新数据记录。如果不相等,删除该文件,重新上传。
  350. // 3. 如果未上传过,需要上传。
  351. StringBuffer filePathBuffer = new StringBuffer(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator).append("capture");
  352. StringBuffer sb = new StringBuffer(routeConfig.getHardDisk()).append(filePathBuffer.toString()).append(File.separator).append(fileName);
  353. boolean needUpload = false;
  354. File dbFile = new File(sb.toString());
  355. if (dbFile.exists()){
  356. String fileMD5 = FileMd5Util.getFileMD5(dbFile);
  357. if (md5.equals(fileMD5) && dbFile.length() == size){
  358. log.warn("文件已存在,MD5和文件大小一致。");
  359. SceneFileUpload uploadEntity = sceneFileUploadService.findByFileIdAndChunk(fileId, Integer.valueOf(chunk));
  360. if (uploadEntity != null){
  361. uploadEntity.setSize((int) size);
  362. uploadEntity.setMd5(md5);
  363. uploadEntity.setFilePath(sb.toString());
  364. uploadEntity.setFileSourceName(fileName);
  365. uploadEntity.setUploadStatus(UploadStatus.SUCCESS.code());
  366. sceneFileUploadService.updateById(uploadEntity);
  367. }else{
  368. SceneFileUpload sceneFileUploadEntity = new SceneFileUpload();
  369. sceneFileUploadEntity.setSize((int) size);
  370. sceneFileUploadEntity.setMd5(md5);
  371. sceneFileUploadEntity.setFilePath(sb.toString());
  372. sceneFileUploadEntity.setFileSourceName(fileName);
  373. sceneFileUploadEntity.setUploadStatus(UploadStatus.SUCCESS.code());
  374. sceneFileUploadEntity.setFileId(fileId);
  375. sceneFileUploadEntity.setChunk(Integer.valueOf(chunk));
  376. sceneFileUploadEntity.setRecStatus(RecStatus.VALID.code());
  377. sceneFileUploadService.save(sceneFileUploadEntity);
  378. }
  379. result = ResultData.ok();
  380. }else if (!md5.equals(fileMD5)) {
  381. log.warn("文件已上传,上传MD5:"+md5+",服务器MD5:"+fileMD5+"。不一致。上传失败");
  382. FileUtil.delFile(sb.toString());
  383. needUpload = true;
  384. }else if (dbFile.length() != size){
  385. log.warn("文件已上传,文件大小不一致。上传失败");
  386. FileUtil.delFile(sb.toString());
  387. needUpload = true;
  388. }
  389. }else {
  390. log.warn("文件不存在,需要重新上传");
  391. needUpload = true;
  392. }
  393. // 4. 上传成功后,校验MD5和文件大小是否相等
  394. // 5. 如果相等,更新数据记录。如果不相等,返回上传失败结果。
  395. try {
  396. if (needUpload){
  397. String name = fileName.substring(0, fileName.lastIndexOf("."));
  398. String filePath = this.saveFile(file, filePathBuffer.toString(), name);
  399. File uploadFile = new File(filePath);
  400. String fileMD5 = FileMd5Util.getFileMD5(uploadFile);
  401. SceneFileUpload sceneFileUploadEntity = new SceneFileUpload();
  402. sceneFileUploadEntity.setSize((int) size);
  403. sceneFileUploadEntity.setMd5(md5);
  404. sceneFileUploadEntity.setFilePath(sb.toString());
  405. sceneFileUploadEntity.setFileSourceName(fileName);
  406. sceneFileUploadEntity.setFileId(fileId);
  407. sceneFileUploadEntity.setChunk(Integer.valueOf(chunk));
  408. sceneFileUploadEntity.setRecStatus(RecStatus.VALID.code());
  409. if (md5.equals(fileMD5) && uploadFile.length() == size){
  410. log.warn("文件已上传,MD5和文件大小一致。上传成功");
  411. sceneFileUploadEntity.setUploadStatus(1);
  412. sceneFileUploadService.save(sceneFileUploadEntity);
  413. result = ResultData.ok();
  414. }else if (!md5.equals(fileMD5)) {
  415. log.warn("文件已上传,上传MD5:"+md5+",服务器MD5:"+fileMD5+"。不一致。上传失败");
  416. sceneFileUploadEntity.setUploadStatus(-1);
  417. sceneFileUploadService.save(sceneFileUploadEntity);
  418. result = ResultData.error(ErrorCode.FAILURE_CODE_5052);
  419. }else if (uploadFile.length() != size){
  420. log.warn("文件已上传,文件大小不一致。上传失败");
  421. sceneFileUploadEntity.setUploadStatus(-1);
  422. sceneFileUploadService.save(sceneFileUploadEntity);
  423. result = ResultData.error(ErrorCode.FAILURE_CODE_5052);
  424. }
  425. }
  426. }catch (IllegalStateException | IOException e) {
  427. log.error(ErrorCode.FAILURE_CODE_5052.message(), e);
  428. result = ResultData.error(ErrorCode.FAILURE_CODE_5052);
  429. }
  430. return result;
  431. }
  432. public String saveFile(MultipartFile file, String filePath, String fileId) throws IOException {
  433. //扩展名格式
  434. String extName = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
  435. String name;
  436. /*
  437. 指定上传目录
  438. */
  439. if (filePath != null && !"".equals(filePath.trim())) {
  440. name = designatedUp(filePath, fileId, file);
  441. return name;
  442. }
  443. /*
  444. 默认上传目录
  445. */
  446. //图片类型文件
  447. if (this.inArray(routeConfig.getImageType(), extName)) {
  448. filePath = routeConfig.getImageFolder();
  449. }
  450. //视频类型文件
  451. else if (this.inArray(routeConfig.getVideoType(), extName)) {
  452. filePath = routeConfig.getVideoFolder();
  453. }
  454. //文档类型文件
  455. else if (this.inArray(routeConfig.getDocumentType(), extName)) {
  456. filePath = routeConfig.getDocumentFolder();
  457. }
  458. //音频类型文件
  459. else if (this.inArray(routeConfig.getMusicType(), extName)) {
  460. filePath = routeConfig.getMusicFolder();
  461. } else {
  462. return "This upload type is not supported temporarily";
  463. }
  464. name = myfileUp(filePath, file);
  465. return name;
  466. }
  467. /**
  468. * 默认上传文件到文件夹
  469. *
  470. * @param folder 默认文件夹
  471. * @param file 上传的文件
  472. * @return
  473. */
  474. private String myfileUp(String folder, MultipartFile file) throws IOException {
  475. LocalDate today = LocalDate.now();
  476. String saveName = File.separator + today.getYear() + "." + today.getMonthValue() + File.separator;
  477. String fileCode = UUID.randomUUID().toString().trim().replaceAll("-", "");
  478. String returnName = FileUpload.fileUp(file, routeConfig.getHardDisk() + File.separator + folder + saveName, fileCode);
  479. saveName = folder + File.separator + saveName + File.separator + returnName;
  480. log.warn("This file has been uploaded: " + saveName);
  481. return saveName;
  482. }
  483. /**
  484. * 判断数组中是否包含某个元素
  485. *
  486. * @param array 类型的数组
  487. * @param element 被检查的类型
  488. * @return
  489. */
  490. private boolean inArray(String[] array, String element) {
  491. boolean flag = false;
  492. for (String type : array) {
  493. if (element.equals(type)) {
  494. flag = true;
  495. break;
  496. }
  497. }
  498. return flag;
  499. }
  500. /**
  501. * 指定目录上传文件
  502. *
  503. * @param folder 指定文件夹
  504. * @param file 上传文件
  505. * @return
  506. */
  507. private String designatedUp(String folder, String fileId, MultipartFile file) throws IOException {
  508. StringBuffer sb = new StringBuffer(routeConfig.getHardDisk()).append(File.separator).append(folder);
  509. String returnName = FileUpload.fileUp(file, sb.toString(), fileId);
  510. String filePathName = sb.toString() + File.separator + File.separator + returnName;
  511. log.warn("This file has been uploaded: " + filePathName);
  512. return filePathName;
  513. }
  514. @Override
  515. public ResultData uploadSuccess(String params) throws Exception {
  516. log.info("uploadSuccess-params: " + params);
  517. if (StrUtil.isEmpty(params)) {
  518. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  519. }
  520. params = params.replaceAll("%2B", "+");
  521. Base64 base64 = new Base64();
  522. String cipher = params;
  523. // 私钥解密过程
  524. byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()),
  525. base64.decode(cipher));
  526. String restr = new String(res, "UTF-8");
  527. log.debug("uploadSuccess-params解密结果:" + restr);
  528. String[] strArr = restr.split(SPLICE);
  529. if (strArr.length != 3) {
  530. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  531. }
  532. String mac = strArr[0];
  533. String fileId = strArr[1];
  534. Object folderNameObject = redisUtil.get(fileId);
  535. String folderName = folderNameObject == null ? null : (String)folderNameObject;
  536. if(StringUtils.isEmpty(folderName)){
  537. String dataSource = scenePlusService.getDataSourceLikeUnicode("/" + fileId + "/");
  538. if(StrUtil.isNotEmpty(dataSource)){
  539. folderName = dataSource.substring(dataSource.lastIndexOf("/") + 1);
  540. }
  541. if(StringUtils.isEmpty(folderName)){
  542. SceneFileBuild sceneFileBuild = this.findByFileId(fileId);
  543. if(sceneFileBuild != null){
  544. folderName = sceneFileBuild.getUnicode();
  545. }
  546. }
  547. }
  548. 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);
  549. boolean flag = this.uploadSuccess(fileId, filePathBuffer);
  550. if(flag){
  551. //调用建模的方法
  552. }
  553. buildScene(filePathBuffer.toString(), fileId, false, null);
  554. return ResultData.ok();
  555. }
  556. public void buildScene(String filePath, String fileId, boolean fromOss, String prefix) throws Exception{
  557. //获取解压后的资源的data.fdage中的数据
  558. String data = FileUtils.readFile(filePath + "data.fdage");
  559. JSONObject jsonObject = JSONObject.parseObject(data);
  560. //调用createScene方法生成scene数据和加入算法队列
  561. if(jsonObject != null){
  562. //有calibration值为标定,1: camera_calibration 2: color_anlysis,0正常计算
  563. if(jsonObject.get("calibration") != null && jsonObject.getString("calibration").equals("1")){
  564. String mac = filePath.replace(ConstantFilePath.BUILD_MODEL_PATH, "").split("/")[0];
  565. String calPath = ConstantFilePath.BUILD_MODEL_PATH + mac + "/camera_calibration";
  566. //生成标定数据
  567. ComputerUtil.createCalibrationData(calPath, filePath);
  568. //开始标定计算
  569. rabbitMqProducer.sendByWorkQueue(queueModelingCall, calPath);
  570. }else if(jsonObject.get("calibration") != null && jsonObject.getString("calibration").equals("2")){
  571. String mac = filePath.replace(ConstantFilePath.BUILD_MODEL_PATH, "").split("/")[0];
  572. String calPath = ConstantFilePath.BUILD_MODEL_PATH + mac + "/color_anlysis";
  573. //生成标定数据
  574. ComputerUtil.createCalibrationData(calPath, filePath);
  575. //开始标定计算
  576. Map<String,String> map = ComputerUtil.computerCalibration(calPath);
  577. }else if(jsonObject.get("calibration") != null && jsonObject.getString("calibration").equals("3")){
  578. String mac = filePath.replace(ConstantFilePath.BUILD_MODEL_PATH, "").split("/")[0];
  579. String calPath = ConstantFilePath.BUILD_MODEL_PATH + mac + "/shading";
  580. //生成标定数据
  581. ComputerUtil.createCalibrationData(calPath, filePath);
  582. //开始标定计算
  583. rabbitMqProducer.sendByWorkQueue(queueModelingCall, calPath);
  584. }else {
  585. String sceneNum = "";
  586. String cameraName = jsonObject.getJSONObject("cam").getString("uuid");
  587. String unicode = jsonObject.getString("creator") + "_" + jsonObject.getString("uuidtime");
  588. log.info("查询相机:" + cameraName);
  589. Camera camera = cameraService.getByChildName(cameraName);
  590. if(camera == null){
  591. log.error("该相机不存在:" + cameraName);
  592. //偶现data.fdage给的相机码多了或少了4DKKPRO_
  593. if(cameraName.contains("4DKKPRO_")){
  594. camera = cameraService.getByChildName(cameraName.replace("4DKKPRO_", ""));
  595. }else {
  596. camera = cameraService.getByChildName("4DKKPRO_" + cameraName);
  597. }
  598. if(camera == null){
  599. throw new BusinessException(CameraConstant.FAILURE_6003);
  600. }
  601. }
  602. CameraDetail cameraDetail = cameraDetailService.getByCameraId(camera.getId());
  603. if(cameraDetail == null){
  604. log.error("该相机详情不存在:" + cameraName);
  605. throw new BusinessException(CameraConstant.FAILURE_6003);
  606. }
  607. //查看场景中的文件目录是否有改文件id,有则重新计算改场景,无则新建场景
  608. ScenePlus scenePlus = scenePlusService.getByFileId("/" + fileId + "/");
  609. int rebuild = 1;
  610. if(Objects.nonNull(scenePlus)){
  611. sceneNum = scenePlus.getNum();
  612. if(scenePlus.getSceneStatus() == SceneStatus.wait.code()){
  613. log.info(sceneNum + ":场景处于计算中,不能再计算");
  614. return;
  615. }
  616. }else {
  617. sceneNum = scene3dNumService.generateSceneNum(cameraDetail.getType());
  618. rebuild = 0;
  619. }
  620. if(sceneNum == null){
  621. log.error("大场景序号为空:" + sceneNum);
  622. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  623. }
  624. String localDataPath = String.format(ConstantFilePath.DATABUFFER_FORMAT, sceneNum);
  625. String localImagesPath = String.format(ConstantFilePath.IMAGESBUFFER_FORMAT, sceneNum);
  626. String imgViewPath = String.format(UploadFilePath.IMG_VIEW_PATH, sceneNum);
  627. String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, sceneNum);
  628. String userName = null;
  629. if(cameraDetail.getUserId() != null){
  630. SSOUser user = userService.getSSOUserByUserId(cameraDetail.getUserId());
  631. if(user != null){
  632. userName = user.getUserName();
  633. }
  634. }
  635. String icon = null;
  636. if(jsonObject.containsKey("icon") && StrUtil.isNotEmpty(jsonObject.getString("icon"))){
  637. CreateObjUtil.ossUtilCp(ConstantFilePath.OSS_PREFIX + prefix + jsonObject.getString("icon"), filePath);
  638. icon = prefixAli + "images/images" + sceneNum + "/" + jsonObject.getString("icon");
  639. if(StorageType.AWS.code().equals(type)){
  640. CreateObjUtil.ossFileCp(ConstantFilePath.OSS_PREFIX + prefix + jsonObject.getString("icon"), filePath + jsonObject.getString("icon"));
  641. icon = ConstantUrl.PREFIX_AWS + imgViewPath + jsonObject.getString("icon");
  642. }
  643. uploadToOssUtil.upload(filePath + jsonObject.getString("icon"), imgViewPath + jsonObject.getString("icon"));
  644. }
  645. JSONObject firmwareVersion = new JSONObject();
  646. if(jsonObject.containsKey("camSoftwareVersion") && StrUtil.isNotEmpty(jsonObject.getString("camSoftwareVersion"))){
  647. firmwareVersion.put("camSoftwareVersion", jsonObject.getString("camSoftwareVersion"));
  648. }
  649. if(jsonObject.containsKey("version") && StrUtil.isNotEmpty(jsonObject.getString("version"))){
  650. firmwareVersion.put("version", jsonObject.getString("version"));
  651. }
  652. String sceneUrl = mainUrl +"/"+sceneProNewUrl;
  653. String buildType = "V2";
  654. Long cameraType = 10L;
  655. //根据videoVersion判断是V2还是V3版本的算法和页面
  656. if(jsonObject.containsKey("videoVersion") && StrUtil.isNotEmpty(jsonObject.getString("videoVersion"))){
  657. if(jsonObject.getIntValue("videoVersion") >= 4){
  658. buildType = "V3";
  659. cameraType = 11L;
  660. }
  661. }
  662. //重算的场景,先移除该场景对应的容量
  663. if(rebuild == 1){
  664. scenePlusService.resetSpace(sceneNum);
  665. }else {
  666. //上传log-main.png
  667. uploadToOssUtil.upload(ConstantFilePath.LOGO_PATH + "logo-main.png", imgViewPath + "logo-main.png");
  668. uploadToOssUtil.upload(ConstantFilePath.LOGO_PATH + "logo-main-en.png", imgViewPath + "logo-main-en.png");
  669. }
  670. ScenePlusVO scenePlusVO = null;
  671. Object[] objects = null;
  672. BuildSceneCallMessage mqMessage = null;
  673. if(fromOss){
  674. objects = this.createScenePlus(sceneNum, camera.getId(), camera.getChildName(), jsonObject.getString("creator"),
  675. jsonObject.getString("pwd"), unicode,
  676. cameraType, String.valueOf(fileId), prefix, "", icon, "0", cameraDetail.getUserId(), userName,
  677. jsonObject.getString("location") != null && "1".equals(jsonObject.getString("location")) ? "sfm" : "slam",
  678. jsonObject.getJSONArray("points").size(), jsonObject.getString("name"), jsonObject.getString("info"),
  679. jsonObject.getInteger("scenetype"), jsonObject.getString("gps"), rebuild,
  680. jsonObject.getInteger("resolution"), firmwareVersion.toString(), sceneUrl, buildType, ecsType,cameraDetail.getCooperationUser());
  681. }else {
  682. objects = this.createScenePlus(sceneNum, camera.getId(), camera.getChildName(), jsonObject.getString("creator"),
  683. jsonObject.getString("pwd"), unicode,
  684. cameraDetail.getGoodsId(), String.valueOf(fileId), "", "", icon, "0", cameraDetail.getUserId(), userName,
  685. jsonObject.getString("location") != null && "1".equals(jsonObject.getString("location")) ? "sfm" : "slam",
  686. jsonObject.getJSONArray("points").size(), jsonObject.getString("name"), jsonObject.getString("info"),
  687. jsonObject.getInteger("scenetype"), jsonObject.getString("gps"), rebuild,
  688. jsonObject.getInteger("resolution"), firmwareVersion.toString(), sceneUrl, buildType, ecsType, cameraDetail.getCooperationUser());
  689. }
  690. scenePlusVO = (ScenePlusVO)objects[0];
  691. mqMessage = (BuildSceneCallMessage)objects[1];
  692. if(Objects.nonNull(scenePlusVO)){
  693. JSONObject statusJson = new JSONObject();
  694. //临时将-2改成1,app还没完全更新
  695. statusJson.put("status", scenePlusVO.getSceneStatus() == -2 ? 1 : scenePlusVO.getSceneStatus());
  696. statusJson.put("webSite", scenePlusVO.getWebSite());
  697. statusJson.put("sceneNum", scenePlusVO.getNum());
  698. statusJson.put("thumb", scenePlusVO.getThumb());
  699. statusJson.put("payStatus", scenePlusVO.getPayStatus());
  700. statusJson.put("recStatus", scenePlusVO.getRecStatus());
  701. FileUtils.writeFile(localDataPath + "status.json", statusJson.toString());
  702. uploadToOssUtil.upload(localDataPath + "status.json", dataViewPath + "status.json");
  703. }
  704. //删除oss的houst_floor.json(国际版可能会卡住)
  705. uploadToOssUtil.delete(dataViewPath + "houst_floor.json");
  706. if(cameraDetail.getCompanyId() != null){
  707. Company company = companyService.getById(cameraDetail.getCompanyId());
  708. if(company != null){
  709. log.info("复制企业logo");
  710. SceneEditInfo sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlusVO.getId());
  711. SceneEditInfoExt sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfo.getId());
  712. if(StrUtil.isNotEmpty(company.getTopLogo())){
  713. //复制阿里云主服务器的图片到横琴云副服务器中
  714. if(!new File(ConstantFilePath.BASE_PATH + File.separator + company.getTopLogo()).exists()){
  715. log.info("下载topLogo");
  716. FileUtils.downLoadFromUrl(mainUrl + company.getTopLogo() + "?t=" + System.currentTimeMillis(),
  717. company.getTopLogo().substring(company.getTopLogo().lastIndexOf("/") + 1),
  718. ConstantFilePath.BASE_PATH + company.getTopLogo().substring(0, company.getTopLogo().lastIndexOf("/")));
  719. }
  720. FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + company.getTopLogo(),
  721. localImagesPath + "logo-main.png", true);
  722. uploadToOssUtil.upload(localImagesPath + "logo-main.png", imgViewPath + "logo-main.png");
  723. }
  724. if(StrUtil.isNotEmpty(company.getFloorLogo())){
  725. //复制阿里云主服务器的图片到横琴云副服务器中
  726. if(!new File(ConstantFilePath.BASE_PATH + File.separator + company.getFloorLogo()).exists()){
  727. log.info("下载floorLogo");
  728. FileUtils.downLoadFromUrl(mainUrl + company.getFloorLogo() + "?t=" + System.currentTimeMillis(),
  729. company.getFloorLogo().substring(company.getFloorLogo().lastIndexOf("/") + 1),
  730. ConstantFilePath.BASE_PATH + company.getFloorLogo().substring(0, company.getFloorLogo().lastIndexOf("/")));
  731. }
  732. FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + company.getFloorLogo(),
  733. localImagesPath + "floorLogoImg.png", true);
  734. uploadToOssUtil.upload(localImagesPath + "floorLogoImg.png", imgViewPath + "floorLogoImg.png");
  735. sceneEditInfo.setFloorLogo("user");
  736. }
  737. if(StrUtil.isNotEmpty(company.getQrLogo())){
  738. //复制阿里云主服务器的图片到横琴云副服务器中
  739. // TODO: 2022/7/25 目前v4版本不需要生成带logo的二维码,这里先注释掉 dsx-------------------------------start
  740. // if(!new File(ConstantFilePath.BASE_PATH + File.separator + company.getQrLogo()).exists()){
  741. // log.info("下载qrLogo");
  742. // FileUtils.downLoadFromUrl(mainUrl + company.getQrLogo() + "?t=" + System.currentTimeMillis(),
  743. // company.getQrLogo().substring(company.getQrLogo().lastIndexOf("/") + 1),
  744. // ConstantFilePath.BASE_PATH + company.getQrLogo().substring(0, company.getQrLogo().lastIndexOf("/")));
  745. // }
  746. //
  747. // FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + company.getQrLogo(),
  748. // ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png", true);
  749. // uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png",
  750. // "images/images" + sceneNum + "/QRShareLogo.png");
  751. // sceneProEdit.setShareLogo("images/images" + sceneNum + "/QRShareLogo.png");
  752. // TODO: 2022/7/25 目前v4版本不需要生成带logo的二维码,这里先注释掉 dsx-------------------------------end
  753. //生成新的分享的二维码
  754. MatrixToImageWriterUtil.createQRCode(sceneUrl + sceneNum, ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneNum+".png",
  755. false, ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png");
  756. MatrixToImageWriterUtil.createQRCode(sceneUrl + sceneNum + "&lang=en", ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneNum+"_en.png",
  757. false, ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png");
  758. }
  759. // TODO: 2022/7/25 目前v4版本还没开发地面点位log功能,这里先注释掉 dsx-------------------------------start
  760. // if(StrUtil.isNotEmpty(company.getMarkerLogo())){
  761. // //复制阿里云主服务器的图片到横琴云副服务器中
  762. // if(!new File(ConstantFilePath.BASE_PATH + File.separator + company.getMarkerLogo()).exists()){
  763. // log.info("下载floorLogo");
  764. // FileUtils.downLoadFromUrl(mainUrl + company.getMarkerLogo() + "?t=" + System.currentTimeMillis(),
  765. // company.getMarkerLogo().substring(company.getMarkerLogo().lastIndexOf("/") + 1),
  766. // ConstantFilePath.BASE_PATH + company.getMarkerLogo().substring(0, company.getMarkerLogo().lastIndexOf("/")));
  767. // }
  768. //
  769. // FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + company.getMarkerLogo(),
  770. // ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/marker.png", true);
  771. // uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/marker.png",
  772. // "images/images" + sceneNum + "/marker.png");
  773. //
  774. // sceneProEdit.setMarkerLogo("user");
  775. // jsonMap.put("markerLogo", "user");
  776. // }
  777. // TODO: 2022/7/25 目前v4版本还没开发地面点位log功能,这里先注释掉 dsx-------------------------------end
  778. sceneEditInfoService.updateById(sceneEditInfo);
  779. }
  780. }
  781. rabbitMqProducer.sendByWorkQueue(queueModelingPre, mqMessage);
  782. }
  783. }else {
  784. log.info("data.fdage文件不存在");
  785. throw new BusinessException(CameraConstant.FAILURE_6009);
  786. }
  787. }
  788. public boolean uploadSuccess(String fileId, StringBuilder filePathBuffer) {
  789. SceneFileBuild sceneFileBuild = findByFileId(fileId);
  790. if (Objects.isNull(sceneFileBuild))
  791. return false;
  792. Long uploadSuccessCount = sceneFileUploadService.countUploadSuccessByFileId(fileId);
  793. sceneFileBuild.setUploadStatus(UploadStatus.SUCCESS.code());
  794. sceneFileBuild.setChunks(Integer.valueOf(uploadSuccessCount.toString()));
  795. sceneFileBuild.setUpdateTime(Calendar.getInstance().getTime());
  796. this.updateById(sceneFileBuild);
  797. return true;
  798. }
  799. @Override
  800. public ResultData uploadSuccessBuild(String params) throws Exception {
  801. log.info("uploadSuccessBuild-params: " + params);
  802. if (StringUtils.isEmpty(params)) {
  803. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  804. }
  805. params = params.replaceAll("%2B", "+");
  806. params = params.replaceAll(" ", "+");
  807. Base64 base64 = new Base64();
  808. String cipher = params;
  809. // 私钥解密过程
  810. byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()),
  811. base64.decode(cipher));
  812. String restr = new String(res, "UTF-8");
  813. log.debug("uploadSuccessBuild-params解密结果:" + restr);
  814. String[] strArr = restr.split(SPLICE);
  815. if (strArr.length != 3) {
  816. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  817. }
  818. String mac = strArr[0];
  819. String fileId = strArr[1];
  820. Object folderNameObject = redisUtil.get(fileId);
  821. String folderName = folderNameObject == null ? null : (String)folderNameObject;
  822. if(StringUtils.isEmpty(folderName)){
  823. SceneProPO sceneProPO = sceneProService.getSceneStatusByUnicode("/" + fileId + "/");
  824. if(sceneProPO != null){
  825. folderName = sceneProPO.getDataSource().substring(sceneProPO.getDataSource().lastIndexOf("/") + 1);
  826. }
  827. if(StringUtils.isEmpty(folderName)){
  828. SceneFileBuild sceneFileBuild = this.findByFileId(fileId);
  829. if(sceneFileBuild != null){
  830. folderName = sceneFileBuild.getUnicode();
  831. }
  832. }
  833. }
  834. StringBuilder filePathBuffer = new StringBuilder(routeConfig.getHardDisk())
  835. .append(mac).append(File.separator)
  836. .append(fileId).append(File.separator)
  837. .append(folderName).append(File.separator)
  838. .append("capture").append(File.separator);
  839. StringBuilder prefixBuffer = new StringBuilder(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator);
  840. File filePath = new File(filePathBuffer.toString());
  841. if(!filePath.exists()){
  842. filePath.mkdirs();
  843. }
  844. if(StorageType.AWS.code().equals(type)){
  845. CreateObjUtil.ossFileCp(ConstantFilePath.OSS_PREFIX + prefixBuffer.toString() + "data.fdage", filePathBuffer.toString() + "data.fdage");
  846. }else {
  847. CreateObjUtil.ossUtilCp(ConstantFilePath.OSS_PREFIX + prefixBuffer.toString() + "data.fdage", filePathBuffer.toString());
  848. }
  849. buildScene(filePathBuffer.toString(), fileId, true, prefixBuffer.toString());
  850. return ResultData.ok();
  851. }
  852. @Override
  853. public ResultData turntableUploadSuccess(String params) throws Exception {
  854. log.info("turntableUploadSuccess-params: " + params);
  855. if (StringUtils.isEmpty(params)) {
  856. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  857. }
  858. params = params.replaceAll("%2B", "+");
  859. params = params.replaceAll(" ", "+");
  860. Base64 base64 = new Base64();
  861. String cipher = params;
  862. // 私钥解密过程
  863. byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()),
  864. base64.decode(cipher));
  865. String restr = new String(res, "UTF-8");
  866. log.info("uploadSuccessBuild-params解密结果:" + restr);
  867. String[] strArr = restr.split(SPLICE);
  868. if (strArr.length != 3) {
  869. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  870. }
  871. String mac = strArr[0];
  872. String fileId = strArr[1];
  873. Object folderNameObject = redisUtil.get(fileId);
  874. String folderName = folderNameObject == null ? null : (String)folderNameObject;
  875. if(StringUtils.isEmpty(folderName)){
  876. ScenePlusExt scenePlusExt = scenePlusExtService.list(
  877. new LambdaQueryWrapper<ScenePlusExt>()
  878. .like(ScenePlusExt::getDataSource, "%/" + fileId + "/%")).get(0);
  879. if(scenePlusExt != null){
  880. folderName = scenePlusExt.getDataSource().substring(scenePlusExt.getDataSource().lastIndexOf("/") + 1);
  881. }
  882. if(StringUtils.isEmpty(folderName)){
  883. SceneFileBuild sceneFileBuild = this.findByFileId(fileId);
  884. if(sceneFileBuild != null){
  885. folderName = sceneFileBuild.getUnicode();
  886. }
  887. }
  888. }
  889. //判断 是否为激光相机
  890. Camera camera = cameraService.getByChildName(mac);
  891. CameraDetail cameraDetail = cameraDetailService.getByCameraId(camera.getId());
  892. String hardDisk = routeConfig.getHardDisk();
  893. if(cameraDetail!=null){
  894. if(cameraDetail.getType() == 10){
  895. hardDisk = routeConfig.getHardDiskLaser();
  896. }
  897. }
  898. log.info("相机 mnt 路径 : " + hardDisk + ", 相机类型 : " + cameraDetail.getType());
  899. //本机目录
  900. 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);
  901. //云目录
  902. StringBuilder prefixBuffer = new StringBuilder(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator);
  903. File filePath = new File(filePathBuffer.toString());
  904. if(!filePath.exists()){
  905. filePath.mkdirs();
  906. }
  907. if(StorageType.AWS.code().equals(type)){
  908. CreateObjUtil.ossFileCp(ConstantFilePath.OSS_PREFIX + prefixBuffer.toString() + "data.fdage", filePathBuffer.toString() + "data.fdage");
  909. }else {
  910. CreateObjUtil.ossUtilCp(ConstantFilePath.OSS_PREFIX + prefixBuffer.toString() + "data.fdage", filePathBuffer.toString());
  911. }
  912. turntableBuildScene(filePathBuffer.toString(), fileId, true, prefixBuffer.toString());
  913. return ResultData.ok();
  914. }
  915. public void turntableBuildScene(String filePath, String fileId, boolean fromOss, String prefix) throws Exception{
  916. String data = FileUtils.readFile(filePath + "data.fdage");
  917. JSONObject jsonObject = JSONObject.parseObject(data);
  918. //调用createScene方法生成scene数据和加入算法队列
  919. if(jsonObject == null) {
  920. log.info("data.fdage文件不存在");
  921. throw new BusinessException(CameraConstant.FAILURE_6009);
  922. }
  923. String sceneNum = "";
  924. String snCode = jsonObject.getJSONObject("cam").getString("uuid");
  925. String unicode = jsonObject.getString("creator") + "_" + jsonObject.getString("uuidtime"); //从data.fage 取出
  926. //查看场景中的文件目录是否有改文件id,有则重新计算改场景,无则新建场景
  927. ScenePlus scene = scenePlusService.getByFileId("/" + fileId + "/");
  928. int rebuild = 1;
  929. log.info("是否是重算,rebuild:{}",rebuild);
  930. log.info("查询相机:" + snCode);
  931. Camera camera = cameraService.getByChildName(snCode);
  932. if(camera == null){
  933. log.error("该相机不存在:" + snCode);
  934. camera = cameraService.getBySnCode(snCode);
  935. if(camera == null){
  936. throw new BusinessException(CameraConstant.FAILURE_6003);
  937. }
  938. }
  939. CameraDetail cameraDetail = cameraDetailService.getByCameraId(camera.getId());
  940. if(cameraDetail == null){
  941. log.error("该相机详情不存在:" + snCode);
  942. throw new BusinessException(CameraConstant.FAILURE_6003);
  943. }
  944. if(Objects.nonNull(scene)){
  945. sceneNum = scene.getNum();
  946. if(scene.getSceneStatus() == SceneStatus.wait.code()){
  947. log.info(sceneNum + ":场景处于计算中,不能再计算");
  948. return;
  949. }
  950. }else {
  951. sceneNum = scene3dNumService.generateSceneNum(cameraDetail.getType());
  952. rebuild = 0;
  953. }
  954. if(sceneNum == null){
  955. log.error("大场景序号为空:" + sceneNum);
  956. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  957. }
  958. String localDataPath = String.format(ConstantFilePath.DATABUFFER_FORMAT, sceneNum);
  959. String localImagesPath = String.format(ConstantFilePath.IMAGESBUFFER_FORMAT, sceneNum);
  960. String imageViewPath = String.format(UploadFilePath.IMG_VIEW_PATH, sceneNum);
  961. String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, sceneNum);
  962. String userName = null;
  963. if(cameraDetail.getUserId() != null){
  964. SSOUser user = userService.getSSOUserByUserId(cameraDetail.getUserId());
  965. if(user != null){
  966. userName = user.getUserName();
  967. }
  968. }
  969. String icon = null;
  970. if(jsonObject.containsKey("icon") && StrUtil.isNotEmpty(jsonObject.getString("icon"))){
  971. CreateObjUtil.ossUtilCp(ConstantFilePath.OSS_PREFIX + prefix + jsonObject.getString("icon"), filePath);
  972. icon = prefixAli + imageViewPath + jsonObject.getString("icon");
  973. if(StorageType.AWS.code().equals(type)){
  974. CreateObjUtil.ossFileCp(ConstantFilePath.OSS_PREFIX + prefix + jsonObject.getString("icon"), filePath + jsonObject.getString("icon"));
  975. icon = ConstantUrl.PREFIX_AWS + imageViewPath + jsonObject.getString("icon");
  976. }
  977. uploadToOssUtil.upload(filePath + jsonObject.getString("icon"), imageViewPath + jsonObject.getString("icon"));
  978. log.info("上传icon成功....");
  979. }
  980. JSONObject firmwareVersion = new JSONObject();
  981. if(jsonObject.containsKey("camSoftwareVersion") && StrUtil.isNotEmpty(jsonObject.getString("camSoftwareVersion"))){
  982. firmwareVersion.put("camSoftwareVersion", jsonObject.getString("camSoftwareVersion"));
  983. }
  984. if(jsonObject.containsKey("version") && StrUtil.isNotEmpty(jsonObject.getString("version"))){
  985. firmwareVersion.put("version", jsonObject.getString("version"));
  986. }
  987. String sceneUrl = mainUrl + sceneProNewUrl;
  988. String buildType = "V3";
  989. //13表示转台
  990. Long cameraType = 13L;
  991. //激光转台 八目相机占用 10 和 11
  992. if(jsonObject.getJSONObject("cam").getIntValue("type") == 10){
  993. //激光转台
  994. cameraType = 14L;
  995. }
  996. //重算的场景,先移除该场景对应的容量
  997. if(rebuild == 1){
  998. scenePlusService.resetSpace(sceneNum);
  999. }else {
  1000. //上传log-main.png
  1001. uploadToOssUtil.upload(ConstantFilePath.LOGO_PATH + "logo-main.png", imageViewPath + "logo-main.png");
  1002. uploadToOssUtil.upload(ConstantFilePath.LOGO_PATH + "logo-main-en.png", imageViewPath + "logo-main-en.png");
  1003. log.info("第一次计算场景,上传logo-main.png");
  1004. }
  1005. Object[] objects = this.createScenePlus(sceneNum, camera.getId(), camera.getChildName(), jsonObject.getString("creator"),
  1006. jsonObject.getString("pwd"), unicode,
  1007. cameraType, String.valueOf(fileId), prefix, "", icon, "0", cameraDetail.getUserId(), userName,
  1008. jsonObject.getString("location") != null && "1".equals(jsonObject.getString("location")) ? "sfm" : "slam",
  1009. jsonObject.getJSONArray("points").size(), jsonObject.getString("name"), jsonObject.getString("info"),
  1010. jsonObject.getInteger("scenetype"), jsonObject.getString("gps"), rebuild,
  1011. jsonObject.getInteger("resolution"), firmwareVersion.toString(), sceneUrl, buildType, ecsType, cameraDetail.getCooperationUser());
  1012. BuildSceneCallMessage mqMessage = (BuildSceneCallMessage)objects[1];
  1013. ScenePlusVO scenePlusVO = (ScenePlusVO) objects[0];
  1014. if(scenePlusVO != null){
  1015. JSONObject statusJson = new JSONObject();
  1016. //临时将-2改成1,app还没完全更新
  1017. statusJson.put("status", scenePlusVO.getSceneStatus() == -2? 1 : scene.getSceneStatus());
  1018. statusJson.put("webSite", scenePlusVO.getWebSite());
  1019. statusJson.put("sceneNum", scenePlusVO.getNum());
  1020. statusJson.put("thumb", scenePlusVO.getThumb());
  1021. statusJson.put("payStatus", scenePlusVO.getPayStatus());
  1022. statusJson.put("recStatus", scenePlusVO.getRecStatus());
  1023. FileUtils.writeFile(localDataPath + "status.json", statusJson.toString());
  1024. uploadToOssUtil.upload(localDataPath + "status.json", dataViewPath + File.separator+"status.json");
  1025. log.info("上传status.json,上传内容:{}" + statusJson.toString());
  1026. }
  1027. if(cameraDetail.getCompanyId() != null){
  1028. Company company = companyService.getById(cameraDetail.getCompanyId());
  1029. if(company != null){
  1030. Map<String, Object> jsonMap = new HashMap<>();
  1031. log.info("复制企业logo");
  1032. SceneEditInfo sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlusVO.getId());
  1033. // SceneProEdit sceneProEdit = sceneProEditService.findByProId(scene.getId());
  1034. // SceneProEditExt sceneProEditExt = sceneProEditExtService.getByProEditId(sceneProEdit.getId());
  1035. if(StrUtil.isNotEmpty(company.getTopLogo())){
  1036. FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + company.getTopLogo(),localImagesPath + "logo-main.png", true);
  1037. uploadToOssUtil.upload(localImagesPath + "logo-main.png", imageViewPath + "logo-main.png");
  1038. }
  1039. if(StrUtil.isNotEmpty(company.getFloorLogo())){
  1040. FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + company.getFloorLogo(),
  1041. localImagesPath + "floorLogoImg.png", true);
  1042. uploadToOssUtil.upload(localImagesPath + "floorLogoImg.png",
  1043. imageViewPath + "floorLogoImg.png");
  1044. sceneEditInfo.setFloorLogo("user");
  1045. }
  1046. if(StrUtil.isNotEmpty(company.getQrLogo())){
  1047. // TODO: 2022/7/25 目前v4版本不需要生成带logo的二维码,这里先注释掉 dsx-------------------------------start
  1048. // FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + company.getQrLogo(),
  1049. // ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png", true);
  1050. //
  1051. // uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png",
  1052. // imageViewPath + "QRShareLogo.png");
  1053. //
  1054. // // TODO: 2022/1/24 暂时保留旧版本,系统稳定后删除
  1055. // uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png",
  1056. // "images/images" + sceneNum + "/QRShareLogo.png");
  1057. //
  1058. //// sceneProEdit.setShareLogo("images/images" + sceneNum + "/QRShareLogo.png");//旧系统代码,先保留
  1059. // sceneProEdit.setShareLogo(imageViewPath + "QRShareLogo.png");
  1060. // TODO: 2022/7/25 目前v4版本不需要生成带logo的二维码,这里先注释掉 dsx-------------------------------end
  1061. //生成新的分享的二维码-中文版本
  1062. MatrixToImageWriterUtil.createQRCode(sceneUrl + sceneNum, ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneNum+".png",
  1063. false, ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png");
  1064. //生成新的分享的二维码-英文版本
  1065. MatrixToImageWriterUtil.createQRCode(sceneUrl + sceneNum + "&lang=en", ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneNum+"_en.png",
  1066. false, ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png");
  1067. }
  1068. // TODO: 2022/7/25 目前v4版本还没开发地面点位log功能,这里先注释掉 dsx-------------------------------start
  1069. // if(StrUtil.isNotEmpty(company.getMarkerLogo())){
  1070. // FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + company.getMarkerLogo(),
  1071. // ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/marker.png", true);
  1072. // uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/marker.png",
  1073. // imageViewPath + "marker.png");
  1074. //
  1075. // // TODO: 2022/1/24 暂时保留旧版本,系统稳定后删除
  1076. // uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/marker.png",
  1077. // "images/images" + sceneNum + "/marker.png");
  1078. //
  1079. // sceneProEdit.setMarkerLogo("user");
  1080. // jsonMap.put("markerLogo", "user");
  1081. // }
  1082. // TODO: 2022/7/25 目前v4版本还没开发地面点位log功能,这里先注释掉 dsx-------------------------------end
  1083. sceneEditInfoService.updateById(sceneEditInfo);
  1084. }
  1085. //删除oss的houst_floor.json
  1086. uploadToOssUtil.delete(dataViewPath + "houst_floor.json");
  1087. }
  1088. //激光转台 八目相机占用 10 和 11
  1089. log.info("发送mq,camType:{}", jsonObject.getJSONObject("cam").getIntValue("type"));
  1090. if(jsonObject.getJSONObject("cam").getIntValue("type") == 10){
  1091. // mqProducer.sendOneWay(topicLaserA, mqMessage);
  1092. // TODO: 2022/3/19 这里应该是发送激光的 ,目前还不清楚,先统一发送同一个mq
  1093. rabbitMqProducer.sendByWorkQueue(queueModelingPre, mqMessage);
  1094. }else if(scene != null){
  1095. rabbitMqProducer.sendByWorkQueue(queueModelingPre, mqMessage);
  1096. }
  1097. }
  1098. public Object[] createScenePlus(String projectNum, Long cameraId, String cameraName, String phoneId, String sceneKey,
  1099. String unicode, Long cameraType, String fileId, String prefix,
  1100. String imgsName, String pic, String isModel, Long userId, String userName,
  1101. String algorithm, Integer sceneShootCount, String sceneName,
  1102. String sceneDec, Integer sceneType, String gps,Integer type,
  1103. Integer resolution, String firmwareVersion, String url, String buildType, String ecsType,
  1104. Long cooperationUser)throws Exception{
  1105. ScenePlusVO scenePlusVO = new ScenePlusVO();
  1106. ScenePlus scenePlus = new ScenePlus();
  1107. ScenePlusExt scenePlusExt = new ScenePlusExt();
  1108. scenePlusExt.setWebSite(url+projectNum);
  1109. scenePlus.setCameraId(cameraId);
  1110. scenePlus.setPhoneId(phoneId);
  1111. scenePlus.setNum(projectNum);
  1112. String path = ConstantFilePath.BUILD_MODEL_PATH + unicode;
  1113. scenePlus.setSceneSource(1);
  1114. if(cameraType.longValue() == 5 || cameraType.longValue() == 6){
  1115. //场景来源双目相机
  1116. scenePlus.setSceneSource(2);
  1117. scenePlusExt.setDataSource(ConstantFilePath.BUILD_MODEL_PATH + unicode);
  1118. }else if(cameraType.longValue() == 14){
  1119. scenePlusExt.setDataSource(ConstantFilePath.BUILD_MODEL_LASER_PATH +
  1120. cameraName.replace("4DKKPRO_", "").replace("-fdage", "").toLowerCase() + File.separator +
  1121. fileId + File.separator + unicode);
  1122. path = ConstantFilePath.BUILD_MODEL_LASER_PATH + unicode;
  1123. log.info("激光相机 dataSource :" + scenePlusExt.getDataSource());
  1124. }else if(cameraType.longValue() >= 3){
  1125. scenePlusExt.setDataSource(ConstantFilePath.BUILD_MODEL_PATH +
  1126. cameraName.replace("4DKKPRO_", "").replace("-fdage", "").toLowerCase() + File.separator +
  1127. fileId + File.separator + unicode);
  1128. }else {
  1129. scenePlusExt.setDataSource(prefix+imgsName);
  1130. }
  1131. if(!org.springframework.util.StringUtils.isEmpty(ecsType)){
  1132. scenePlusExt.setEcs(ecsType);
  1133. }
  1134. if(resolution == null || resolution.intValue() == 0){
  1135. scenePlusExt.setSceneScheme(cameraType.intValue());
  1136. }else {
  1137. scenePlusExt.setSceneScheme(4);
  1138. }
  1139. //场景来源双目相机,sceneScheme为4,加载high,low图
  1140. if(cameraType.longValue() == 5 || cameraType.longValue() == 6){
  1141. scenePlusExt.setSceneScheme(4);
  1142. }
  1143. //转台相机用4k图
  1144. if(cameraType.longValue() == 13 ){
  1145. scenePlus.setSceneSource(3);
  1146. scenePlusExt.setSceneScheme(10);
  1147. }
  1148. //激光相机
  1149. if(cameraType.longValue() == 14 ){
  1150. scenePlus.setSceneSource(4);
  1151. scenePlusExt.setSceneScheme(10);
  1152. }
  1153. if(pic!=null&&pic.length()>5)
  1154. {
  1155. scenePlusExt.setThumb(pic);
  1156. }
  1157. else
  1158. {
  1159. scenePlusExt.setThumb(ConstantUrl.DEFAULT_SCENE_PIC);
  1160. }
  1161. scenePlusExt.setThumb(scenePlusExt.getThumb().concat("?t=")+System.currentTimeMillis());
  1162. if(!ObjectUtils.isEmpty(userName)){
  1163. scenePlus.setUserId(userId);
  1164. }
  1165. if(sceneShootCount == null)
  1166. {
  1167. scenePlusExt.setShootCount(0);
  1168. }
  1169. else
  1170. {
  1171. scenePlusExt.setShootCount(sceneShootCount);
  1172. }
  1173. if(sceneName!=null)
  1174. {
  1175. scenePlus.setTitle(sceneName);
  1176. }
  1177. if(sceneDec!=null)
  1178. {
  1179. scenePlus.setDescription("<p>"+ new String(sceneDec.getBytes("UTF-8"))+"</p>");
  1180. }
  1181. if(sceneType!=null)
  1182. {
  1183. scenePlus.setSceneType(sceneType);
  1184. }
  1185. if(gps!=null&&!gps.trim().equals(""))
  1186. {
  1187. scenePlusExt.setGps(gps);
  1188. }
  1189. scenePlusExt.setAlgorithm(algorithm);
  1190. if(!org.springframework.util.StringUtils.isEmpty(firmwareVersion)){
  1191. scenePlusExt.setFirmwareVersion(firmwareVersion);
  1192. }
  1193. scenePlusExt.setBuildType(buildType);
  1194. log.info("场景记录添加到数据库:"+projectNum);
  1195. //type=0为新生成场景,其余为重新计算场景
  1196. SceneEditInfo sceneEditInfo = new SceneEditInfo();
  1197. SceneEditInfoExt sceneEditInfoExt = new SceneEditInfoExt();
  1198. SceneEditControls sceneEditControls = new SceneEditControls();
  1199. if(type == 0){
  1200. scenePlus.setSceneStatus(SceneStatus.wait.code());
  1201. scenePlusService.save(scenePlus);
  1202. scenePlusExt.setPlusId(scenePlus.getId());
  1203. scenePlusExtService.save(scenePlusExt);
  1204. sceneEditInfo.setScenePlusId(scenePlus.getId());
  1205. if(StrUtil.isNotBlank(sceneKey)) {
  1206. sceneEditInfo.setScenePassword(sceneKey);
  1207. sceneEditControls.setShowLock((int) CommonStatus.YES.code());
  1208. }
  1209. sceneEditInfoService.save(sceneEditInfo);
  1210. sceneEditControls.setEditInfoId(sceneEditInfo.getId());
  1211. sceneEditControlsService.save(sceneEditControls);
  1212. //新增场景时,同时新增场景协作信息
  1213. if(cooperationUser != null){
  1214. SceneCooperation sceneCooperationEntity = new SceneCooperation();
  1215. sceneCooperationEntity.setNum(projectNum);
  1216. sceneCooperationEntity.setUserId(cooperationUser);
  1217. sceneCooperationService.save(sceneCooperationEntity);
  1218. List<SceneResourceCamera> resourceCameraList = sceneResourceCameraService.findListByCameraId(cameraId);
  1219. SceneResourceCooperation sceneResourceCooperation = null;
  1220. if(resourceCameraList != null && resourceCameraList.size() > 0){
  1221. for (SceneResourceCamera sceneResourceCamera : resourceCameraList) {
  1222. sceneResourceCooperation = new SceneResourceCooperation();
  1223. sceneResourceCooperation.setSceneResourceId(sceneResourceCamera.getSceneResourceId());
  1224. sceneResourceCooperation.setSceneCooperationId(sceneCooperationEntity.getId());
  1225. sceneResourceCooperationService.save(sceneResourceCooperation);
  1226. }
  1227. }
  1228. }
  1229. }else {
  1230. ScenePlus oldScene = scenePlusService.getScenePlusByNum(projectNum);
  1231. scenePlus.setId(oldScene.getId());
  1232. scenePlus.setSceneStatus(0);
  1233. scenePlus.setRecStatus(RecStatus.VALID.code());
  1234. scenePlus.setPayStatus(0);
  1235. scenePlus.setCreateTime(Calendar.getInstance().getTime());
  1236. ScenePlusExt oldSceneExt = scenePlusExtService.getScenePlusExtByPlusId(oldScene.getId());
  1237. scenePlusExt.setSpace(oldSceneExt.getSpace());
  1238. scenePlusExt.setEcs(oldSceneExt.getEcs());
  1239. scenePlusExt.setViewCount(oldSceneExt.getViewCount());
  1240. if(sceneName!=null) {
  1241. scenePlus.setTitle(sceneName);
  1242. }
  1243. if(sceneType!=null) {
  1244. scenePlus.setSceneType(sceneType);
  1245. }
  1246. scenePlusService.updateById(scenePlus);
  1247. scenePlusExtService.updateById(scenePlusExt);
  1248. SceneEditInfo oldSceneEditInfo = sceneEditInfoService.getByScenePlusId(oldScene.getId());
  1249. SceneEditInfoExt oldSceneEditeIinfoExt = sceneEditInfoExtService.getByEditInfoId(oldSceneEditInfo.getId());
  1250. if(StrUtil.isNotBlank(sceneKey)) {
  1251. sceneEditInfo.setScenePassword(sceneKey);
  1252. sceneEditControls.setShowLock((int) CommonStatus.YES.code());
  1253. }else{
  1254. sceneEditInfo.setScenePassword("");
  1255. sceneEditControls.setShowLock((int)CommonStatus.NO.code());
  1256. }
  1257. sceneEditInfo.setId(oldSceneEditInfo.getId());
  1258. sceneEditInfo.setScenePlusId(scenePlus.getId());
  1259. sceneEditInfo.setFloorLogoSize(100);
  1260. sceneEditInfo.setRecStatus(RecStatus.VALID.code());
  1261. sceneEditInfo.setFloorPublishVer(oldSceneEditInfo.getFloorEditVer() + 1);
  1262. sceneEditInfo.setFloorEditVer(oldSceneEditInfo.getFloorEditVer() + 1);
  1263. sceneEditInfo.setVersion(oldSceneEditInfo.getVersion() + 1);
  1264. sceneEditInfoService.updateById(sceneEditInfo);
  1265. sceneEditInfoExt.setId(oldSceneEditeIinfoExt.getId());
  1266. sceneEditInfoExt.setEditInfoId(sceneEditInfo.getId());
  1267. sceneEditInfoExt.setScenePlusId(scenePlus.getId());
  1268. sceneEditInfoExtService.updateById(sceneEditInfoExt);
  1269. }
  1270. BuildSceneCallMessage buildSceneMqMessage =this.getBuildSceneMqMessage(
  1271. projectNum, cameraName, unicode, cameraType, fileId, prefix, imgsName, isModel,
  1272. userName, algorithm, resolution, buildType, path, scenePlus.getId(), scenePlus.getTitle(),
  1273. scenePlusExt.getWebSite(), scenePlus.getCreateTime(), scenePlus.getUserId(),
  1274. scenePlusExt.getDataSource(), scenePlus.getSceneStatus(), scenePlus.getPayStatus(), scenePlusExt.getThumb());
  1275. BeanUtil.copyProperties(scenePlusExt, scenePlusVO);
  1276. BeanUtil.copyProperties(scenePlus, scenePlusVO);
  1277. //当mq排队数大于指定数量时使用弹性升缩
  1278. return new Object[]{scenePlusVO, buildSceneMqMessage};
  1279. }
  1280. public BuildSceneCallMessage getBuildSceneMqMessage(String projectNum, String cameraName, String unicode,
  1281. Long cameraType, String fileId,String prefix, String imgsName,
  1282. String isModel, String userName,String algorithm, Integer resolution,
  1283. String buildType, String path, Long sceneProId, String sceneName, String webSite,
  1284. Date sceneProCreateTime, Long userId, String dataSource,
  1285. Integer sceneStatus, Integer PayStatus, String thumb) {
  1286. BuildSceneCallMessage mqMsg = new BuildSceneCallMessage();
  1287. mqMsg.setSceneProId(sceneProId);
  1288. mqMsg.setSceneNum(projectNum);
  1289. mqMsg.setCameraName(cameraName);
  1290. mqMsg.setUnicode(unicode);
  1291. mqMsg.setCameraType(String.valueOf(cameraType));
  1292. mqMsg.setFileId(fileId);
  1293. mqMsg.setPrefix(prefix);
  1294. mqMsg.setImgsName(imgsName);
  1295. mqMsg.setIsModel(isModel);
  1296. mqMsg.setUserName(userName);
  1297. mqMsg.setAlgorithm(algorithm);
  1298. mqMsg.setResolution(String.valueOf(resolution));
  1299. mqMsg.setBuildType(buildType);
  1300. mqMsg.setPath(path);
  1301. mqMsg.setSceneName(sceneName);
  1302. mqMsg.setWebSite(webSite);
  1303. mqMsg.setSceneProCreateTime(sceneProCreateTime);
  1304. mqMsg.setUserId(userId);
  1305. mqMsg.setDataSource(dataSource);
  1306. mqMsg.setSceneStatus(sceneStatus);
  1307. mqMsg.setPayStatus(PayStatus);
  1308. mqMsg.setCreateTime(DateUtil.format(Calendar.getInstance().getTime(), DateExtUtil.dateStyle));
  1309. mqMsg.setThumb(thumb);
  1310. return mqMsg;
  1311. }
  1312. @Override
  1313. public ResultData getS3UploadUrl(String params) throws Exception {
  1314. if (StringUtils.isEmpty(params)) {
  1315. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  1316. }
  1317. JSONObject jsonObject = JSON.parseObject(params);
  1318. if(jsonObject == null){
  1319. throw new BusinessException(ErrorCode.PARAM_FORMAT_ERROR);
  1320. }
  1321. JSONArray files = jsonObject.getJSONArray("Files");
  1322. if(files == null){
  1323. throw new BusinessException(ErrorCode.PARAM_FORMAT_ERROR);
  1324. }
  1325. List<String> urls = new ArrayList<>();
  1326. for(int i = 0, len = files.size(); i < len; i++){
  1327. urls.add(files.getJSONObject(i).getString("filename"));
  1328. }
  1329. return ResultData.ok(uploadToOssUtil.getUploadS3Url(urls));
  1330. }
  1331. @Override
  1332. public ResultData buildLiteScene(String prefix, String dataFdage, String zipName, String userName, String password, String oldNum) throws Exception{
  1333. log.info("参数-prefix: {}, dataFdage: {}, zipName: {}, password: {}, userName: {}", prefix,
  1334. dataFdage, zipName, password, userName);
  1335. if(StringUtils.isEmpty(prefix) || StringUtils.isEmpty(dataFdage) || StringUtils.isEmpty(zipName) ||
  1336. StringUtils.isEmpty(userName) || StringUtils.isEmpty(password)){
  1337. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  1338. }
  1339. Camera camera = cameraService.getByChildName(userName);
  1340. if(camera == null){
  1341. camera = cameraService.getBySnCode(userName);
  1342. }
  1343. if (camera == null){
  1344. throw new BusinessException(CameraConstant.FAILURE_6003);
  1345. }
  1346. if(!password.equals(camera.getChildPassword())){
  1347. throw new BusinessException(ErrorCode.FAILURE_CODE_3014);
  1348. }
  1349. CameraDetail cameraDetail = cameraDetailService.getByCameraId(camera.getId());
  1350. if(cameraDetail == null){
  1351. throw new BusinessException(CameraConstant.FAILURE_6003);
  1352. }
  1353. String unicode = prefix.substring(prefix.lastIndexOf("/") + 1);
  1354. String path = ConstantFilePath.BUILD_MODEL_PATH + unicode;
  1355. //下载data.fdage
  1356. FileUtils.downLoadFromUrl(prefix + "/" + dataFdage + "?m=" + System.currentTimeMillis(), dataFdage, path + File.separator + "capture");
  1357. String data = FileUtils.readFile(path + File.separator + "capture/" + dataFdage);
  1358. JSONObject jsonObject = JSONObject.parseObject(data);
  1359. if(jsonObject == null){
  1360. log.info("data.fdage不存在");
  1361. throw new BusinessException(CameraConstant.FAILURE_6009);
  1362. }
  1363. String sceneNum = "";
  1364. //查看场景中的文件目录是否有改文件id,有则重新计算改场景,无则新建场景
  1365. ScenePlus scenePlus = scenePlusService.getByFileId("/" + unicode);
  1366. int rebuild = 1;
  1367. if(StrUtil.isNotEmpty(oldNum)){
  1368. sceneNum = oldNum;
  1369. }else {
  1370. if(scenePlus != null){
  1371. sceneNum = scenePlus.getNum();
  1372. //重算的场景,先移除该场景对应的容量
  1373. scenePlusService.resetSpace(sceneNum);
  1374. }else {
  1375. sceneNum = scene3dNumService.generateSceneNum(cameraDetail.getType());
  1376. rebuild = 0;
  1377. }
  1378. }
  1379. String localDataPath = String.format(ConstantFilePath.DATABUFFER_FORMAT, sceneNum);
  1380. String imgViewPath = String.format(UploadFilePath.IMG_VIEW_PATH, sceneNum);
  1381. String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, sceneNum);
  1382. String cameraName = jsonObject.getJSONObject("cam").getString("uuid");
  1383. log.info("查询相机:" + cameraName);
  1384. camera = cameraService.getByChildName(cameraName);
  1385. if(camera == null){
  1386. log.error("该相机不存在:" + cameraName);
  1387. //偶现data.fdage给的相机码多了或少了4DKKPRO_
  1388. if(cameraName.contains("4DKKPRO_")){
  1389. camera = cameraService.getByChildName(cameraName.replace("4DKKPRO_", ""));
  1390. }else {
  1391. camera = cameraService.getByChildName("4DKKPRO_" + cameraName);
  1392. }
  1393. if(camera == null){
  1394. throw new BusinessException(CameraConstant.FAILURE_6003);
  1395. }
  1396. }
  1397. String icon = null;
  1398. if(jsonObject.containsKey("icon") && StrUtil.isNotEmpty(jsonObject.getString("icon"))){
  1399. //下载封面图icon
  1400. FileUtils.downLoadFromUrl(prefix + "/" + jsonObject.getString("icon") + "?m=" + System.currentTimeMillis(), jsonObject.getString("icon"), path + File.separator + "capture");
  1401. uploadToOssUtil.upload(path + File.separator + "capture" + File.separator +
  1402. jsonObject.getString("icon"), imgViewPath + jsonObject.getString("icon"));
  1403. icon = prefixAli + imgViewPath + jsonObject.getString("icon");
  1404. if(StorageType.AWS.code().equals(type)){
  1405. icon = ConstantUrl.PREFIX_AWS + imgViewPath + jsonObject.getString("icon");
  1406. }
  1407. }
  1408. JSONObject firmwareVersion = new JSONObject();
  1409. if(jsonObject.containsKey("camSoftwareVersion") && StrUtil.isNotEmpty(jsonObject.getString("camSoftwareVersion"))){
  1410. firmwareVersion.put("camSoftwareVersion", jsonObject.getString("camSoftwareVersion"));
  1411. }
  1412. if(jsonObject.containsKey("version") && StrUtil.isNotEmpty(jsonObject.getString("version"))){
  1413. firmwareVersion.put("version", jsonObject.getString("version"));
  1414. }
  1415. String sceneUrl = mainUrl + sceneProNewUrl;
  1416. String buildType = "V3";
  1417. //表示新款双目
  1418. Long cameraType = 5L;
  1419. if(jsonObject.getJSONObject("cam").getIntValue("type") == 5){
  1420. //6表示小红屋双目
  1421. cameraType = 6L;
  1422. }
  1423. Object[] objects = this.createScenePlus(sceneNum, camera.getId(), camera.getChildName(),
  1424. jsonObject.getString("creator"),
  1425. jsonObject.getString("pwd"), unicode,
  1426. cameraType, "", prefix, zipName, icon, "0", cameraDetail.getUserId(), userName,
  1427. jsonObject.getString("location") != null && "1".equals(jsonObject.getString("location"))
  1428. ? "sfm" : "slam",
  1429. jsonObject.getJSONArray("points").size(), jsonObject.getString("name"),
  1430. jsonObject.getString("info"),
  1431. jsonObject.getInteger("scenetype"), jsonObject.getString("gps"), rebuild,
  1432. 4, firmwareVersion.toString(), sceneUrl, buildType, ecsType,
  1433. cameraDetail.getCooperationUser());
  1434. BuildSceneCallMessage mqMessage = (BuildSceneCallMessage)objects[1];
  1435. ScenePlusVO scenePlusVO = (ScenePlusVO) objects[0];
  1436. if(scenePlusVO == null){
  1437. log.info("双目相机入库失败");
  1438. return ResultData.error(ErrorCode.FAILURE_CODE_5056);
  1439. }
  1440. JSONObject statusJson = new JSONObject();
  1441. //临时将-2改成1,app还没完全更新
  1442. statusJson.put("status", scenePlusVO.getSceneStatus() == -2? 1 : scenePlusVO.getSceneStatus());
  1443. statusJson.put("webSite", scenePlusVO.getWebSite());
  1444. statusJson.put("sceneNum", scenePlusVO.getNum());
  1445. statusJson.put("thumb", scenePlusVO.getThumb());
  1446. statusJson.put("payStatus", scenePlusVO.getPayStatus());
  1447. FileUtils.writeFile(localDataPath + "status.json", statusJson.toString());
  1448. uploadToOssUtil.upload(localDataPath + "status.json", dataViewPath + "status.json");
  1449. //删除oss的houst_floor.json
  1450. uploadToOssUtil.delete(dataViewPath + "houst_floor.json");
  1451. rabbitMqProducer.sendByWorkQueue(queueModelingPre, mqMessage);
  1452. Map<String, String> map = new HashMap<>();
  1453. map.put("sceneNum", sceneNum);
  1454. map.put("sceneUrl", sceneUrl + sceneNum);
  1455. return ResultData.ok(map);
  1456. }
  1457. @Override
  1458. public ResultData buildScene(String prefix, String unicode, String zip, String dataFdage) throws Exception{
  1459. String data = FileUtils.readFile(ConstantFilePath.BUILD_MODEL_PATH + unicode + "/data.fdage");
  1460. JSONObject jsonObject = JSONObject.parseObject(data);
  1461. String cameraName = jsonObject.getJSONObject("cam").getString("uuid");
  1462. log.info("查询相机:" + cameraName);
  1463. Camera cameraEntity = cameraService.getByChildName(cameraName);
  1464. if(cameraEntity == null){
  1465. log.error("该相机不存在:" + cameraName);
  1466. //偶现data.fdage给的相机码多了或少了4DKKPRO_
  1467. if(cameraName.contains("4DKKPRO_")){
  1468. cameraEntity = cameraService.getByChildName(cameraName.replace("4DKKPRO_", ""));
  1469. }else {
  1470. cameraEntity = cameraService.getByChildName("4DKKPRO_" + cameraName);
  1471. }
  1472. if(cameraEntity == null){
  1473. throw new BusinessException(CameraConstant.FAILURE_6003);
  1474. }
  1475. }
  1476. CameraDetail detailEntity = cameraDetailService.getByCameraId(cameraEntity.getId());
  1477. if(detailEntity == null){
  1478. log.error("该相机详情不存在:" + cameraName);
  1479. throw new BusinessException(CameraConstant.FAILURE_6003);
  1480. }
  1481. String sceneNum = scene3dNumService.generateSceneNum(detailEntity.getType());
  1482. return ResultData.ok(mainUrl + sceneProNewUrl + sceneNum);
  1483. }
  1484. }