SceneFileBuildServiceImpl.java 123 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635
  1. package com.fdkankan.scene.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.core.conditions.update.LambdaUpdateWrapper;
  12. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  13. import com.fdkankan.common.config.FileRouteConfig;
  14. import com.fdkankan.common.constant.*;
  15. import com.fdkankan.common.exception.BusinessException;
  16. import com.fdkankan.common.response.ResultData;
  17. import com.fdkankan.common.user.SSOUser;
  18. import com.fdkankan.common.util.*;
  19. import com.fdkankan.fyun.oss.UploadToOssUtil;
  20. import com.fdkankan.mq.message.BuildSceneMqMessage;
  21. import com.fdkankan.mq.util.RocketMQProducer;
  22. import com.fdkankan.platform.api.feign.PlatformGoodsClient;
  23. import com.fdkankan.platform.api.feign.PlatformUserClient;
  24. import com.fdkankan.platform.api.vo.Camera;
  25. import com.fdkankan.platform.api.vo.CameraDetail;
  26. import com.fdkankan.platform.api.vo.Company;
  27. import com.fdkankan.redis.util.RedisUtil;
  28. import com.fdkankan.scene.entity.*;
  29. import com.fdkankan.scene.mapper.ISceneFileBuildMapper;
  30. import com.fdkankan.scene.service.*;
  31. import com.fdkankan.scene.vo.*;
  32. import lombok.extern.slf4j.Slf4j;
  33. import org.apache.commons.codec.binary.Base64;
  34. import org.apache.commons.lang3.StringUtils;
  35. import org.joda.time.DateTime;
  36. import org.springframework.beans.factory.annotation.Autowired;
  37. import org.springframework.beans.factory.annotation.Value;
  38. import org.springframework.scheduling.annotation.Async;
  39. import org.springframework.stereotype.Service;
  40. import org.springframework.util.ObjectUtils;
  41. import org.springframework.web.bind.annotation.RequestBody;
  42. import org.springframework.web.multipart.MultipartFile;
  43. import javax.servlet.http.HttpServletRequest;
  44. import javax.servlet.http.HttpServletResponse;
  45. import javax.xml.transform.Result;
  46. import java.io.BufferedReader;
  47. import java.io.File;
  48. import java.io.IOException;
  49. import java.io.InputStreamReader;
  50. import java.time.LocalDate;
  51. import java.util.*;
  52. /**
  53. * <p>
  54. * 场景文件建模表 服务实现类
  55. * </p>
  56. *
  57. * @author dengsixing
  58. * @since 2021-12-23
  59. */
  60. @Slf4j
  61. @Service
  62. public class SceneFileBuildServiceImpl extends ServiceImpl<ISceneFileBuildMapper, SceneFileBuild> implements ISceneFileBuildService {
  63. private static final String SPLICE = "#";
  64. @Value("${main.url}")
  65. private String mainUrl;
  66. @Value("${scene.url}")
  67. private String sceneUrl;
  68. @Value("${scene.pro.url}")
  69. private String sceneProUrl;
  70. @Value("${scene.pro.new.url}")
  71. private String sceneProNewUrl;
  72. @Value("${upload.type}")
  73. private String type;
  74. @Value("${oss.prefix.ali}")
  75. private String prefixAli;
  76. @Value("${ecs.type}")
  77. private String ecsType;
  78. @Value("${unCalculated.company.ids:#{null}}")
  79. private String[] unCalculatedCompanyIds;
  80. @Value("${rocketmq.build-scene.topicName.topic-modeling-a}")
  81. private String topicModelingA;
  82. @Value("${rocketmq.build-scene.topicName.topic-modeling-a-pre}")
  83. private String topicModelingAPre;
  84. @Value("${rocketmq.build-scene.topicName.topic-laser-a}")
  85. private String topicLaserA;
  86. @Value("${rocketmq.build-scene.topicName.topic-video-a}")
  87. private String topicVideoA;
  88. @Value("${rocketmq.build-scene.topicName.topic-pic-a}")
  89. private String topicPicA;
  90. @Autowired
  91. private IScenePlusService scenePlusService;
  92. @Autowired
  93. private IScenePlusExtService scenePlusExtService;
  94. @Autowired
  95. IPicSceneProgressService picSceneProgressService;
  96. @Autowired
  97. IVideoSceneProgressService videoSceneProgressService;
  98. @Autowired
  99. PlatformGoodsClient platformGoodsClient;
  100. @Autowired
  101. PlatformUserClient platformUserClient;
  102. @Autowired
  103. ISceneFileUploadService sceneFileUploadService;
  104. @Autowired
  105. ISceneProService sceneProService;
  106. @Autowired
  107. private FileRouteConfig routeConfig;
  108. @Autowired
  109. UploadToOssUtil uploadToOssUtil;
  110. @Autowired
  111. ISceneProEditService sceneProEditService;
  112. @Autowired
  113. ISceneProEditExtService sceneProEditExtService;
  114. @Autowired
  115. IScene3dNumService scene3dNumService;
  116. @Autowired
  117. ISceneProExtService sceneProExtService;
  118. @Autowired
  119. ISceneCooperationService sceneCooperationService;
  120. @Autowired
  121. ISceneResourceCameraService sceneResourceCameraService;
  122. @Autowired
  123. ISceneResourceCooperationService sceneResourceCooperationService;
  124. @Autowired
  125. RocketMQProducer mqProducer;
  126. @Autowired
  127. RedisUtil redisUtil;
  128. @Autowired
  129. ISceneService sceneService;
  130. @Autowired
  131. ISceneExtService sceneExtService;
  132. @Autowired
  133. IFdkkLaserService fdkkLaserService;
  134. @Autowired
  135. ISceneEditInfoService sceneEditInfoService;
  136. @Override
  137. public SceneFileBuild findByFileId(String fileId) {
  138. List<SceneFileBuild> list = this.list(new LambdaQueryWrapper<SceneFileBuild>()
  139. .eq(SceneFileBuild::getTbStatus, TbStatus.VALID.code())
  140. .eq(SceneFileBuild::getFileId, fileId)
  141. .orderByDesc(SceneFileBuild::getId));
  142. if(CollUtil.isEmpty(list))
  143. return null;
  144. return list.get(0);
  145. }
  146. @Override
  147. public boolean uploadSuccess(String fileId, StringBuilder filePathBuffer) {
  148. SceneFileBuild sceneFileBuild = findByFileId(fileId);
  149. if (Objects.isNull(sceneFileBuild))
  150. return false;
  151. Long uploadSuccessCount = sceneFileUploadService.countUploadSuccessByFileId(fileId);
  152. sceneFileBuild.setUploadStatus(UploadStatus.SUCCESS.code());
  153. sceneFileBuild.setChunks(Integer.valueOf(uploadSuccessCount.toString()));
  154. sceneFileBuild.setUpdateTime(Calendar.getInstance().getTime());
  155. this.updateById(sceneFileBuild);
  156. return true;
  157. }
  158. @Override
  159. public SceneFileBuild findByUnicode(String unicode) {
  160. List<SceneFileBuild> list = this.list(new QueryWrapper<SceneFileBuild>()
  161. .eq("tb_status", TbStatus.VALID.code())
  162. .eq("unicode", unicode)
  163. .orderByDesc("id"));
  164. if(CollUtil.isEmpty(list))
  165. return null;
  166. return list.get(0);
  167. }
  168. @Async
  169. @Override
  170. public void unzipSingleFile(String filePath) {
  171. log.info("文件路径:{}", filePath);
  172. File file = new File(filePath);
  173. if (file.exists()){
  174. log.error(filePath + ":文件不存在");
  175. throw new BusinessException(ErrorCode.FAILURE_CODE_5038);
  176. }
  177. String parentFilePath = file.getParentFile().getPath();
  178. log.info("解压目标目录:{}", parentFilePath);
  179. StringBuffer exec = new StringBuffer(" tar xvf ");
  180. exec.append(filePath);
  181. exec.append(" -C ").append(parentFilePath).append(File.separator);
  182. System.out.println(exec.toString());
  183. String[] cmdExec = new String[]{"/bin/sh", "-c", exec.toString()};
  184. int code = executeLinuxShell(cmdExec);
  185. if (code == 0){
  186. log.info("解压完成,文件路径:{}, 开始执行删除压缩文件", filePath);
  187. file.delete();
  188. }else {
  189. log.error("解压失败,文件路径:{},解压状态:{}", filePath, code);
  190. }
  191. }
  192. private int executeLinuxShell(String[] command) {
  193. Process shellProcess = null;
  194. BufferedReader shellErrorResultReader = null;
  195. BufferedReader shellInfoResultReader = null;
  196. try {
  197. shellProcess = Runtime.getRuntime().exec(command);
  198. shellErrorResultReader = new BufferedReader(new InputStreamReader(shellProcess.getErrorStream()));
  199. shellInfoResultReader = new BufferedReader(new InputStreamReader(shellProcess.getInputStream()));
  200. String infoLine;
  201. while ((infoLine = shellInfoResultReader.readLine()) != null) {
  202. log.info("linux环境脚本执行信息:{}", infoLine);
  203. }
  204. String errorLine;
  205. while ((errorLine = shellErrorResultReader.readLine()) != null) {
  206. log.warn("linux环境脚本执行信息:{}", errorLine);
  207. }
  208. // 等待程序执行结束并输出状态
  209. int exitCode = shellProcess.waitFor();
  210. if (0 == exitCode) {
  211. log.info("linux环境脚本执行成功");
  212. } else {
  213. log.error("linux环境脚本执行失败:" + exitCode);
  214. }
  215. return exitCode;
  216. } catch (Exception e) {
  217. log.error("linux环境shell脚本执行错误", e);
  218. return 1;
  219. } finally {
  220. if (null != shellInfoResultReader) {
  221. try {
  222. shellInfoResultReader.close();
  223. } catch (IOException e) {
  224. log.error("linux环境脚本流文件关闭异常:", e);
  225. }
  226. }
  227. if (null != shellErrorResultReader) {
  228. try {
  229. shellErrorResultReader.close();
  230. } catch (IOException e) {
  231. log.error("linux环境脚本流文件关闭异常:", e);
  232. }
  233. }
  234. if (null != shellProcess) {
  235. shellProcess.destroy();
  236. }
  237. }
  238. }
  239. @Override
  240. public ResponseSceneFile preUpload(String params) throws Exception {
  241. log.info("preUpload-params: "+params);
  242. if (StrUtil.isEmpty(params)){
  243. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  244. }
  245. params = params.replaceAll("%2B", "+");
  246. Base64 base64 = new Base64();
  247. String cipher = params;
  248. // 私钥解密过程
  249. byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()),
  250. base64.decode(cipher));
  251. String restr = new String(res, "UTF-8");
  252. log.debug("preUpload-params解密结果:" + restr);
  253. String[] strArr = restr.split(SPLICE);
  254. if (strArr.length != 5) {
  255. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  256. }
  257. String mac = strArr[0];
  258. String totalPicNum = strArr[1];
  259. String chunks = strArr[2];
  260. String folderName = strArr[3];
  261. if (StrUtil.isEmpty(mac)){
  262. throw new BusinessException(ErrorCode.FAILURE_CODE_5044);
  263. }
  264. if (totalPicNum == null){
  265. throw new BusinessException(ErrorCode.FAILURE_CODE_5045);
  266. }
  267. if (chunks == null){
  268. throw new BusinessException(ErrorCode.FAILURE_CODE_5046);
  269. }
  270. if (folderName == null){
  271. throw new BusinessException(ErrorCode.FAILURE_CODE_5047);
  272. }
  273. log.info("mac:" + mac + "准备上传文件");
  274. SceneProPO scenePro = sceneProService.getSceneStatusByUnicode("/" + folderName, TbStatus.VALID.code());
  275. if(scenePro != null && scenePro.getDataSource() != null){
  276. int n = scenePro.getDataSource().split("/").length;
  277. if(n > 1){
  278. String fileId = scenePro.getDataSource().split("/")[n - 2];
  279. ResponseSceneFile responseSceneFile = new ResponseSceneFile();
  280. responseSceneFile.setFileId(fileId);
  281. //可以重复上传,文件id保存50年(因为该redis工具无法设置永久保存)
  282. redisUtil.set(fileId, folderName, 1537920000);
  283. return responseSceneFile;
  284. }
  285. }else {
  286. SceneFileBuild sceneFileBuild = this.findByUnicode(folderName);
  287. if(sceneFileBuild != null){
  288. String fileId = sceneFileBuild.getFileId();
  289. ResponseSceneFile responseSceneFile = new ResponseSceneFile();
  290. responseSceneFile.setFileId(fileId);
  291. //可以重复上传,文件id保存50年(因为该redis工具无法设置永久保存)
  292. redisUtil.set(fileId, folderName, 1537920000);
  293. return responseSceneFile;
  294. }
  295. }
  296. // 构造方法设置机器码:第0个机房的第0台机器
  297. SnowflakeIdGenerator snowflakeIdGenerator = new SnowflakeIdGenerator(0, 0);
  298. long fileId = snowflakeIdGenerator.nextId();
  299. SceneFileBuild sceneFileBuild = new SceneFileBuild();
  300. sceneFileBuild.setChildName(mac);
  301. sceneFileBuild.setFileId(String.valueOf(fileId));
  302. sceneFileBuild.setUnicode(folderName);
  303. sceneFileBuild.setUploadStatus(0);
  304. sceneFileBuild.setBuildStatus(0);
  305. sceneFileBuild.setTotalPicNum(Integer.valueOf(totalPicNum));
  306. sceneFileBuild.setChunks(Integer.valueOf(chunks));
  307. this.save(sceneFileBuild);
  308. ResponseSceneFile responseSceneFile = new ResponseSceneFile();
  309. responseSceneFile.setFileId(String.valueOf(fileId));
  310. //可以重复上传,文件id保存50年(因为该redis工具无法设置永久保存)
  311. redisUtil.set(String.valueOf(fileId), folderName, 1537920000);
  312. return responseSceneFile;
  313. }
  314. @Override
  315. public ResponseSceneFile getProgress(String params) throws Exception {
  316. log.info("getProgress-params:{} ", params);
  317. if (StrUtil.isEmpty(params)){
  318. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  319. }
  320. params = params.replaceAll("%2B", "+");
  321. Base64 base64 = new Base64();
  322. String cipher = params;
  323. // 私钥解密过程
  324. byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()),
  325. base64.decode(cipher));
  326. String restr = new String(res, "UTF-8");
  327. log.debug("getProgress-params解密结果:{}" , restr);
  328. String[] strArr = restr.split(SPLICE);
  329. if (strArr.length != 3) {
  330. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  331. }
  332. String fileId = strArr[0];
  333. String chunk = strArr[1];
  334. chunk = chunk.split(SPLICE)[0];
  335. SceneFileUpload sceneFileUpload = sceneFileUploadService.findByFileIdAndChunk(fileId, Integer.valueOf(chunk));
  336. ResponseSceneFile responseSceneFile = new ResponseSceneFile();
  337. responseSceneFile.setUploadStatus(sceneFileUpload != null ? sceneFileUpload.getUploadStatus() : -1);
  338. return responseSceneFile;
  339. }
  340. @Override
  341. public ResultData uploadFile(MultipartFile file, String params) throws Exception{
  342. log.info("upload-params: "+params);
  343. if (StringUtils.isEmpty(params)){
  344. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  345. }
  346. params = params.replaceAll("%2B", "+");
  347. Base64 base64 = new Base64();
  348. String cipher = params;
  349. // 私钥解密过程
  350. byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()),
  351. base64.decode(cipher));
  352. String restr = new String(res, "UTF-8");
  353. log.debug("upload-params解密结果:{}", restr);
  354. String[] strArr = restr.split(SPLICE);
  355. if (strArr.length != 6) {
  356. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  357. }
  358. String mac = strArr[0];
  359. String fileId = strArr[1];
  360. String picNum = strArr[2];
  361. String md5 = strArr[3];
  362. String chunk = strArr[4];
  363. ResultData result = null;
  364. if (file.isEmpty()){
  365. throw new BusinessException(ErrorCode.FAILURE_CODE_5048);
  366. }
  367. if (StringUtils.isEmpty(fileId)){
  368. throw new BusinessException(ErrorCode.FAILURE_CODE_5049);
  369. }
  370. if (picNum == null){
  371. throw new BusinessException(ErrorCode.FAILURE_CODE_5050);
  372. }
  373. if (StringUtils.isEmpty(mac)){
  374. throw new BusinessException(ErrorCode.FAILURE_CODE_5044);
  375. }
  376. if (StringUtils.isEmpty(md5)){
  377. throw new BusinessException(ErrorCode.FAILURE_CODE_5051);
  378. }
  379. long size = file.getSize();
  380. log.warn("fileId:"+fileId+"---picNum:"+picNum+"---size:"+size+"---md5:"+md5+"---mac:"+mac);
  381. chunk = chunk.split(SPLICE)[0];
  382. // 获取文件名
  383. String fileName = file.getOriginalFilename();
  384. log.info("上传的文件名为:" + fileName);
  385. // 获取文件的后缀名
  386. String suffixName = fileName.substring(fileName.lastIndexOf("."));
  387. log.info("上传的后缀名为:" + suffixName);
  388. Object folderNameObject = redisUtil.get(fileId);
  389. String folderName = folderNameObject == null ? null : (String)folderNameObject;
  390. if(StringUtils.isEmpty(folderName)){
  391. SceneProPO scenePro = sceneProService.getSceneStatusByUnicode("/" + fileId + "/", TbStatus.VALID.code());
  392. if(scenePro != null){
  393. folderName = scenePro.getDataSource().substring(scenePro.getDataSource().lastIndexOf("/") + 1);
  394. }
  395. }
  396. // 1. 判断该文件是否已经上传过
  397. // 2. 如果已经上传过,判断MD5值和文件大小是否相等。如果相等,更新数据记录。如果不相等,删除该文件,重新上传。
  398. // 3. 如果未上传过,需要上传。
  399. StringBuffer filePathBuffer = new StringBuffer(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator).append("capture");
  400. StringBuffer sb = new StringBuffer(routeConfig.getHardDisk()).append(filePathBuffer.toString()).append(File.separator).append(fileName);
  401. boolean needUpload = false;
  402. File dbFile = new File(sb.toString());
  403. if (dbFile.exists()){
  404. String fileMD5 = FileMd5Util.getFileMD5(dbFile);
  405. if (md5.equals(fileMD5) && dbFile.length() == size){
  406. log.warn("文件已存在,MD5和文件大小一致。");
  407. SceneFileUpload uploadEntity = sceneFileUploadService.findByFileIdAndChunk(fileId, Integer.valueOf(chunk));
  408. if (uploadEntity != null){
  409. uploadEntity.setSize((int) size);
  410. uploadEntity.setMd5(md5);
  411. uploadEntity.setFilePath(sb.toString());
  412. uploadEntity.setFileSourceName(fileName);
  413. uploadEntity.setUploadStatus(1);
  414. sceneFileUploadService.updateById(uploadEntity);
  415. }else{
  416. SceneFileUpload sceneFileUploadEntity = new SceneFileUpload();
  417. sceneFileUploadEntity.setSize((int) size);
  418. sceneFileUploadEntity.setMd5(md5);
  419. sceneFileUploadEntity.setFilePath(sb.toString());
  420. sceneFileUploadEntity.setFileSourceName(fileName);
  421. sceneFileUploadEntity.setUploadStatus(1);
  422. sceneFileUploadEntity.setFileId(fileId);
  423. sceneFileUploadEntity.setChunk(Integer.valueOf(chunk));
  424. sceneFileUploadService.save(sceneFileUploadEntity);
  425. }
  426. result = ResultData.ok();
  427. }else if (!md5.equals(fileMD5)) {
  428. log.warn("文件已上传,上传MD5:"+md5+",服务器MD5:"+fileMD5+"。不一致。上传失败");
  429. FileUtil.delFile(sb.toString());
  430. needUpload = true;
  431. }else if (dbFile.length() != size){
  432. log.warn("文件已上传,文件大小不一致。上传失败");
  433. FileUtil.delFile(sb.toString());
  434. needUpload = true;
  435. }
  436. }else {
  437. log.warn("文件不存在,需要重新上传");
  438. needUpload = true;
  439. }
  440. // 4. 上传成功后,校验MD5和文件大小是否相等
  441. // 5. 如果相等,更新数据记录。如果不相等,返回上传失败结果。
  442. try {
  443. if (needUpload){
  444. String name = fileName.substring(0, fileName.lastIndexOf("."));
  445. String filePath = this.saveFile(file, filePathBuffer.toString(), name);
  446. File uploadFile = new File(filePath);
  447. String fileMD5 = FileMd5Util.getFileMD5(uploadFile);
  448. SceneFileUpload sceneFileUploadEntity = new SceneFileUpload();
  449. sceneFileUploadEntity.setSize((int) size);
  450. sceneFileUploadEntity.setMd5(md5);
  451. sceneFileUploadEntity.setFilePath(sb.toString());
  452. sceneFileUploadEntity.setFileSourceName(fileName);
  453. sceneFileUploadEntity.setFileId(fileId);
  454. sceneFileUploadEntity.setChunk(Integer.valueOf(chunk));
  455. if (md5.equals(fileMD5) && uploadFile.length() == size){
  456. log.warn("文件已上传,MD5和文件大小一致。上传成功");
  457. sceneFileUploadEntity.setUploadStatus(1);
  458. sceneFileUploadService.save(sceneFileUploadEntity);
  459. result = ResultData.ok();
  460. }else if (!md5.equals(fileMD5)) {
  461. log.warn("文件已上传,上传MD5:"+md5+",服务器MD5:"+fileMD5+"。不一致。上传失败");
  462. sceneFileUploadEntity.setUploadStatus(-1);
  463. sceneFileUploadService.save(sceneFileUploadEntity);
  464. result = ResultData.error(ErrorCode.FAILURE_CODE_5052);
  465. }else if (uploadFile.length() != size){
  466. log.warn("文件已上传,文件大小不一致。上传失败");
  467. sceneFileUploadEntity.setUploadStatus(-1);
  468. sceneFileUploadService.save(sceneFileUploadEntity);
  469. result = ResultData.error(ErrorCode.FAILURE_CODE_5052);
  470. }
  471. }
  472. }catch (IllegalStateException | IOException e) {
  473. log.error(ErrorCode.FAILURE_CODE_5052.message(), e);
  474. result = ResultData.error(ErrorCode.FAILURE_CODE_5052);
  475. }
  476. return result;
  477. }
  478. @Override
  479. public ResultData uploadSuccess(String params) throws Exception {
  480. log.info("uploadSuccess-params: " + params);
  481. if (StrUtil.isEmpty(params)) {
  482. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  483. }
  484. params = params.replaceAll("%2B", "+");
  485. Base64 base64 = new Base64();
  486. String cipher = params;
  487. // 私钥解密过程
  488. byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()),
  489. base64.decode(cipher));
  490. String restr = new String(res, "UTF-8");
  491. log.debug("uploadSuccess-params解密结果:" + restr);
  492. String[] strArr = restr.split(SPLICE);
  493. if (strArr.length != 3) {
  494. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  495. }
  496. String mac = strArr[0];
  497. String fileId = strArr[1];
  498. Object folderNameObject = redisUtil.get(fileId);
  499. String folderName = folderNameObject == null ? null : (String)folderNameObject;
  500. if(StringUtils.isEmpty(folderName)){
  501. SceneProPO scenePro = sceneProService.getSceneStatusByUnicode("/" + fileId + "/", TbStatus.VALID.code());
  502. if(scenePro != null){
  503. folderName = scenePro.getDataSource().substring(scenePro.getDataSource().lastIndexOf("/") + 1);
  504. }
  505. if(StringUtils.isEmpty(folderName)){
  506. SceneFileBuild sceneFileBuild = this.findByFileId(fileId);
  507. if(sceneFileBuild != null){
  508. folderName = sceneFileBuild.getUnicode();
  509. }
  510. }
  511. }
  512. 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);
  513. boolean flag = this.uploadSuccess(fileId, filePathBuffer);
  514. if(flag){
  515. //调用建模的方法
  516. buildScene(filePathBuffer.toString(), fileId, false, null);
  517. }
  518. return ResultData.ok();
  519. }
  520. @Override
  521. public ResultData uploadSuccessBuild(String params) throws Exception {
  522. log.info("uploadSuccessBuild-params: " + params);
  523. if (StringUtils.isEmpty(params)) {
  524. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  525. }
  526. params = params.replaceAll("%2B", "+");
  527. params = params.replaceAll(" ", "+");
  528. Base64 base64 = new Base64();
  529. String cipher = params;
  530. // 私钥解密过程
  531. byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()),
  532. base64.decode(cipher));
  533. String restr = new String(res, "UTF-8");
  534. log.debug("uploadSuccessBuild-params解密结果:" + restr);
  535. String[] strArr = restr.split(SPLICE);
  536. if (strArr.length != 3) {
  537. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  538. }
  539. String mac = strArr[0];
  540. String fileId = strArr[1];
  541. Object folderNameObject = redisUtil.get(fileId);
  542. String folderName = folderNameObject == null ? null : (String)folderNameObject;
  543. if(StringUtils.isEmpty(folderName)){
  544. SceneProPO sceneProPO = sceneProService.getSceneStatusByUnicode("/" + fileId + "/", TbStatus.VALID.code());
  545. if(sceneProPO != null){
  546. folderName = sceneProPO.getDataSource().substring(sceneProPO.getDataSource().lastIndexOf("/") + 1);
  547. }
  548. if(StringUtils.isEmpty(folderName)){
  549. SceneFileBuild sceneFileBuild = this.findByFileId(fileId);
  550. if(sceneFileBuild != null){
  551. folderName = sceneFileBuild.getUnicode();
  552. }
  553. }
  554. }
  555. StringBuilder filePathBuffer = new StringBuilder(routeConfig.getHardDisk())
  556. .append(mac).append(File.separator)
  557. .append(fileId).append(File.separator)
  558. .append(folderName).append(File.separator)
  559. .append("capture").append(File.separator);
  560. StringBuilder prefixBuffer = new StringBuilder(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator);
  561. File filePath = new File(filePathBuffer.toString());
  562. if(!filePath.exists()){
  563. filePath.mkdirs();
  564. }
  565. if("aws".equals(type)){
  566. CreateObjUtil.ossFileCp(ConstantFilePath.OSS_PREFIX + prefixBuffer.toString() + "data.fdage", filePathBuffer.toString() + "data.fdage");
  567. }else {
  568. CreateObjUtil.ossUtilCp(ConstantFilePath.OSS_PREFIX + prefixBuffer.toString() + "data.fdage", filePathBuffer.toString());
  569. }
  570. buildScene(filePathBuffer.toString(), fileId, true, prefixBuffer.toString());
  571. return ResultData.ok();
  572. }
  573. @Override
  574. public ResultData turntableUploadSuccess(String params) throws Exception {
  575. log.info("turntableUploadSuccess-params: " + params);
  576. if (StringUtils.isEmpty(params)) {
  577. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  578. }
  579. params = params.replaceAll("%2B", "+");
  580. params = params.replaceAll(" ", "+");
  581. Base64 base64 = new Base64();
  582. String cipher = params;
  583. // 私钥解密过程
  584. byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()),
  585. base64.decode(cipher));
  586. String restr = new String(res, "UTF-8");
  587. log.info("uploadSuccessBuild-params解密结果:" + restr);
  588. String[] strArr = restr.split(SPLICE);
  589. if (strArr.length != 3) {
  590. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  591. }
  592. String mac = strArr[0];
  593. String fileId = strArr[1];
  594. Object folderNameObject = redisUtil.get(fileId);
  595. String folderName = folderNameObject == null ? null : (String)folderNameObject;
  596. if(StringUtils.isEmpty(folderName)){
  597. // TODO: 2022/3/19 plus版本稳定后删除----------------------------------------------------------------------start
  598. // SceneProPO sceneProPO = sceneProService.getSceneStatusByUnicode("/" + fileId + "/", TbStatus.VALID.code());
  599. // if(sceneProPO != null){
  600. // folderName = sceneProPO.getDataSource().substring(sceneProPO.getDataSource().lastIndexOf("/") + 1);
  601. // }
  602. // TODO: 2022/3/19 plus版本稳定后删除----------------------------------------------------------------------end
  603. ScenePlusExt scenePlusExt = scenePlusExtService.list(
  604. new LambdaQueryWrapper<ScenePlusExt>()
  605. .like(ScenePlusExt::getDataSource, "%/" + fileId + "/%")).get(0);
  606. if(scenePlusExt != null){
  607. folderName = scenePlusExt.getDataSource().substring(scenePlusExt.getDataSource().lastIndexOf("/") + 1);
  608. }
  609. if(StringUtils.isEmpty(folderName)){
  610. SceneFileBuild sceneFileBuild = this.findByFileId(fileId);
  611. if(sceneFileBuild != null){
  612. folderName = sceneFileBuild.getUnicode();
  613. }
  614. }
  615. }
  616. //判断 是否为激光相机
  617. ResultData<Camera> cameraResult = platformGoodsClient.getCameraByChildName(mac);
  618. if(!cameraResult.getSuccess()){
  619. log.error("获取不到Camera数据, childName: {}" , mac);
  620. throw new Exception();
  621. }
  622. Camera camera = cameraResult.getData();
  623. ResultData<CameraDetail> cameraDetailResult = platformGoodsClient.getCameraDetailByCameraId(camera.getId());
  624. if(!cameraDetailResult.getSuccess()){
  625. log.error("获取不到CameraDetail数据, CameraId: {}" , camera.getId());
  626. throw new Exception();
  627. }
  628. CameraDetail cameraDetail = cameraDetailResult.getData();
  629. String hardDisk = routeConfig.getHardDisk();
  630. if(cameraDetail!=null){
  631. if(cameraDetail.getCameraType() == 10){
  632. hardDisk = routeConfig.getHardDiskLaser();
  633. }
  634. }
  635. log.info("相机 mnt 路径 : " + hardDisk + ", 相机类型 : " + cameraDetail.getCameraType());
  636. //本机目录
  637. 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);
  638. //云目录
  639. StringBuilder prefixBuffer = new StringBuilder(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator);
  640. File filePath = new File(filePathBuffer.toString());
  641. if(!filePath.exists()){
  642. filePath.mkdirs();
  643. }
  644. if("aws".equals(type)){
  645. CreateObjUtil.ossFileCp(ConstantFilePath.OSS_PREFIX + prefixBuffer.toString() + "data.fdage", filePathBuffer.toString() + "data.fdage");
  646. }else {
  647. CreateObjUtil.ossUtilCp(ConstantFilePath.OSS_PREFIX + prefixBuffer.toString() + "data.fdage", filePathBuffer.toString());
  648. }
  649. turntableBuildScene(filePathBuffer.toString(), fileId, true, prefixBuffer.toString());
  650. return ResultData.ok();
  651. }
  652. @Override
  653. public ResultData getS3UploadUrl(String params) throws Exception {
  654. if (StringUtils.isEmpty(params)) {
  655. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  656. }
  657. JSONObject jsonObject = JSON.parseObject(params);
  658. if(jsonObject == null){
  659. throw new BusinessException(ErrorCode.PARAM_FORMAT_ERROR);
  660. }
  661. JSONArray files = jsonObject.getJSONArray("Files");
  662. if(files == null){
  663. throw new BusinessException(ErrorCode.PARAM_FORMAT_ERROR);
  664. }
  665. List<String> urls = new ArrayList<>();
  666. for(int i = 0, len = files.size(); i < len; i++){
  667. urls.add(files.getJSONObject(i).getString("filename"));
  668. }
  669. return ResultData.ok(uploadToOssUtil.getUploadS3Url(urls));
  670. }
  671. @Override
  672. public ResultData buildLiteScene(String prefix, String dataFdage, String zipName, String userName, String password, String oldNum) throws Exception{
  673. log.info("参数-prefix: {}, dataFdage: {}, zipName: {}, password: {}, userName: {}", prefix,
  674. dataFdage, zipName, password, userName);
  675. if(StringUtils.isEmpty(prefix) || StringUtils.isEmpty(dataFdage) || StringUtils.isEmpty(zipName) ||
  676. StringUtils.isEmpty(userName) || StringUtils.isEmpty(password)){
  677. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  678. }
  679. ResultData<Camera> cameraResult = platformGoodsClient.getCameraByChildName(userName);
  680. Camera camera = cameraResult.getData();
  681. if(camera == null){
  682. cameraResult = platformGoodsClient.getCameraBySnCode(userName);
  683. camera = cameraResult.getData();
  684. }
  685. if (camera == null){
  686. throw new BusinessException(CameraConstant.FAILURE_6003);
  687. }
  688. if(!password.equals(camera.getChildPassword())){
  689. throw new BusinessException(ErrorCode.FAILURE_CODE_3014);
  690. }
  691. String unicode = prefix.substring(prefix.lastIndexOf("/") + 1);
  692. String path = ConstantFilePath.BUILD_MODEL_PATH + unicode;
  693. //下载data.fdage
  694. FileUtils.downLoadFromUrl(prefix + "/" + dataFdage + "?m=" + System.currentTimeMillis(), dataFdage, path + File.separator + "capture");
  695. String data = FileUtils.readFile(path + File.separator + "capture/" + dataFdage);
  696. JSONObject jsonObject = JSONObject.parseObject(data);
  697. if(jsonObject == null){
  698. log.info("data.fdage不存在");
  699. throw new BusinessException(CameraConstant.FAILURE_6009);
  700. }
  701. String sceneNum = "";
  702. //查看场景中的文件目录是否有改文件id,有则重新计算改场景,无则新建场景
  703. SceneProPO sceneProPO = sceneProService.findByFileId("/" + unicode);
  704. int rebuild = 1;
  705. if(StrUtil.isNotEmpty(oldNum)){
  706. sceneNum = oldNum;
  707. }else {
  708. if(sceneProPO != null){
  709. sceneNum = sceneProPO.getNum();
  710. //重算的场景,先移除该场景对应的容量
  711. sceneProService.rebuildReduceSpaceBySceneNum(sceneNum);
  712. }else {
  713. sceneNum = scene3dNumService.generateSceneNum();
  714. rebuild = 0;
  715. }
  716. }
  717. String cameraName = jsonObject.getJSONObject("cam").getString("uuid");
  718. log.info("查询相机:" + cameraName);
  719. cameraResult = platformGoodsClient.getCameraByChildName(cameraName);
  720. camera = cameraResult.getData();
  721. if(camera == null){
  722. log.error("该相机不存在:" + cameraName);
  723. //偶现data.fdage给的相机码多了或少了4DKKPRO_
  724. if(cameraName.contains("4DKKPRO_")){
  725. cameraResult = platformGoodsClient.getCameraByChildName(cameraName.replace("4DKKPRO_", ""));
  726. camera = cameraResult.getData();
  727. }else {
  728. cameraResult = platformGoodsClient.getCameraByChildName("4DKKPRO_" + cameraName);
  729. camera = cameraResult.getData();
  730. }
  731. if(camera == null){
  732. throw new BusinessException(CameraConstant.FAILURE_6003);
  733. }
  734. }
  735. ResultData<CameraDetail> detailResult = platformGoodsClient.getCameraDetailByCameraId(camera.getId());
  736. CameraDetail cameraDetail = detailResult.getData();
  737. if(cameraDetail == null){
  738. log.error("该相机详情不存在:" + cameraName);
  739. throw new BusinessException(CameraConstant.FAILURE_6003);
  740. }
  741. String icon = null;
  742. if(jsonObject.containsKey("icon") && StrUtil.isNotEmpty(jsonObject.getString("icon"))){
  743. //下载封面图icon
  744. FileUtils.downLoadFromUrl(prefix + "/" + jsonObject.getString("icon") + "?m=" + System.currentTimeMillis(), jsonObject.getString("icon"), path + File.separator + "capture");
  745. uploadToOssUtil.upload(path + File.separator + "capture" + File.separator +
  746. jsonObject.getString("icon"), "images/images" + sceneNum + "/" + jsonObject.getString("icon"));
  747. icon = prefixAli + "images/images" + sceneNum + "/" + jsonObject.getString("icon");
  748. if("aws".equals(type)){
  749. icon = ConstantUrl.PREFIX_AWS + "images/images" + sceneNum + "/" + jsonObject.getString("icon");
  750. }
  751. }
  752. JSONObject firmwareVersion = new JSONObject();
  753. if(jsonObject.containsKey("camSoftwareVersion") && StrUtil.isNotEmpty(jsonObject.getString("camSoftwareVersion"))){
  754. firmwareVersion.put("camSoftwareVersion", jsonObject.getString("camSoftwareVersion"));
  755. }
  756. if(jsonObject.containsKey("version") && StrUtil.isNotEmpty(jsonObject.getString("version"))){
  757. firmwareVersion.put("version", jsonObject.getString("version"));
  758. }
  759. String sceneUrl = mainUrl + sceneProNewUrl;
  760. String buildType = "V3";
  761. //表示新款双目
  762. Long cameraType = 5L;
  763. if(jsonObject.getJSONObject("cam").getIntValue("type") == 5){
  764. //6表示小红屋双目
  765. cameraType = 6L;
  766. }
  767. SceneProPO scene = this.createScenePro(sceneNum, camera.getId(), camera.getChildName(), jsonObject.getString("creator"),
  768. jsonObject.getString("pwd"), unicode,
  769. cameraType, "", prefix, zipName, icon, "0", cameraDetail.getUserId(), userName,
  770. jsonObject.getString("location") != null && "1".equals(jsonObject.getString("location")) ? "sfm" : "slam",
  771. jsonObject.getJSONArray("points").size(), jsonObject.getString("name"), jsonObject.getString("info"),
  772. jsonObject.getInteger("scenetype"), jsonObject.getString("gps"), rebuild,
  773. 4, firmwareVersion.toString(), sceneUrl, buildType, type, ecsType, cameraDetail.getCooperationUser());
  774. if(scene == null){
  775. log.info("双目相机入库失败");
  776. return ResultData.error(ErrorCode.FAILURE_CODE_5056);
  777. }
  778. JSONObject statusJson = new JSONObject();
  779. //临时将-2改成1,app还没完全更新
  780. statusJson.put("status", scene.getSceneStatus() == -2? 1 : scene.getSceneStatus());
  781. statusJson.put("webSite", scene.getWebSite());
  782. statusJson.put("sceneNum", scene.getNum());
  783. statusJson.put("thumb", scene.getThumb());
  784. statusJson.put("payStatus", scene.getPayStatus());
  785. FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data/data"+sceneNum+File.separator+"status.json", statusJson.toString());
  786. uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH+"data/data"+sceneNum+File.separator+"status.json",
  787. "data/data"+sceneNum+File.separator+"status.json");
  788. //删除oss的houst_floor.json
  789. uploadToOssUtil.delete("data/data"+sceneNum+File.separator+"houst_floor.json");
  790. mqProducer.sendInOrder(topicModelingA, scene.getId()+"", scene.getMqMsg());
  791. Map<String, String> map = new HashMap<>();
  792. map.put("sceneNum", sceneNum);
  793. map.put("sceneUrl", sceneUrl + sceneNum);
  794. return ResultData.ok(map);
  795. }
  796. @Override
  797. public ResultData buildScene(String prefix, String unicode, String zip, String dataFdage) throws Exception{
  798. String data = FileUtils.readFile(ConstantFilePath.BUILD_MODEL_PATH + unicode + "/data.fdage");
  799. JSONObject jsonObject = JSONObject.parseObject(data);
  800. String sceneNum = scene3dNumService.generateSceneNum();
  801. return ResultData.ok(mainUrl + sceneProNewUrl + sceneNum);
  802. }
  803. public void turntableBuildScene(String filePath, String fileId, boolean fromOss, String prefix) throws Exception{
  804. String data = FileUtils.readFile(filePath + "data.fdage");
  805. JSONObject jsonObject = JSONObject.parseObject(data);
  806. //调用createScene方法生成scene数据和加入算法队列
  807. if(jsonObject == null) {
  808. log.info("data.fdage文件不存在");
  809. throw new BusinessException(CameraConstant.FAILURE_6009);
  810. }
  811. String sceneNum = "";
  812. String snCode = jsonObject.getJSONObject("cam").getString("uuid");
  813. String unicode = jsonObject.getString("creator") + "_" + jsonObject.getString("uuidtime"); //从data.fage 取出
  814. // sceneProService.updateRecStatus(unicode);
  815. //查看场景中的文件目录是否有改文件id,有则重新计算改场景,无则新建场景
  816. ScenePlusExt scene = scenePlusExtService.list(
  817. new LambdaQueryWrapper<ScenePlusExt>()
  818. .like(ScenePlusExt::getDataSource, "%/" + fileId + "/%")).get(0);
  819. // TODO: 2022/3/19 plus 版本稳定后删除-------------------------------start
  820. SceneProPO scene = sceneProService.findByFileId("/" + fileId + "/");
  821. // TODO: 2022/3/19 plus 版本稳定后删除-------------------------------end
  822. int rebuild = 1;
  823. if(scene != null){
  824. sceneNum = scene.getNum();
  825. if(scene.getSceneStatus() == SceneStatus.wait.code()){
  826. log.info(sceneNum + ":场景处于计算中,不能再计算");
  827. return;
  828. }
  829. }else {
  830. sceneNum = scene3dNumService.generateSceneNum();
  831. rebuild = 0;
  832. }
  833. log.info("是否是重算,rebuild:{}",rebuild);
  834. if(sceneNum == null){
  835. log.error("大场景序号为空:" + sceneNum);
  836. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  837. }
  838. String imageViewPath = String.format(UploadFilePath.IMG_VIEW_PATH, sceneNum);
  839. String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, sceneNum);
  840. log.info("查询相机:" + snCode);
  841. ResultData<Camera> cameraResult = platformGoodsClient.getCameraByChildName(snCode);
  842. Camera camera = cameraResult.getData();
  843. if(camera == null){
  844. log.error("该相机不存在:" + snCode);
  845. cameraResult = platformGoodsClient.getCameraBySnCode(snCode);
  846. camera = cameraResult.getData();
  847. if(camera == null){
  848. throw new BusinessException(CameraConstant.FAILURE_6003);
  849. }
  850. }
  851. ResultData<CameraDetail> cameraDetailResult = platformGoodsClient.getCameraDetailByCameraId(camera.getId());
  852. CameraDetail cameraDetail = cameraDetailResult.getData();
  853. if(cameraDetail == null){
  854. log.error("该相机详情不存在:" + snCode);
  855. throw new BusinessException(CameraConstant.FAILURE_6003);
  856. }
  857. String userName = null;
  858. if(cameraDetail.getUserId() != null){
  859. ResultData<SSOUser> ssoResult = platformUserClient.getSSOUserByUserId(cameraDetail.getUserId());
  860. SSOUser user = ssoResult.getData();
  861. if(user != null){
  862. userName = user.getUserName();
  863. }
  864. }
  865. String icon = null;//新系统
  866. if(jsonObject.containsKey("icon") && StrUtil.isNotEmpty(jsonObject.getString("icon"))){
  867. CreateObjUtil.ossUtilCp(ConstantFilePath.OSS_PREFIX + prefix + jsonObject.getString("icon"), filePath);
  868. icon = prefixAli + imageViewPath + jsonObject.getString("icon");
  869. if("aws".equals(type)){
  870. CreateObjUtil.ossFileCp(ConstantFilePath.OSS_PREFIX + prefix + jsonObject.getString("icon"), filePath + jsonObject.getString("icon"));
  871. icon = ConstantUrl.PREFIX_AWS + imageViewPath + jsonObject.getString("icon");
  872. }
  873. uploadToOssUtil.upload(filePath + jsonObject.getString("icon"), imageViewPath + jsonObject.getString("icon"));
  874. // TODO: 2022/1/24 暂时保留旧版本,系统稳定后删除
  875. uploadToOssUtil.upload(filePath + jsonObject.getString("icon"), "images/images" + sceneNum + "/" + jsonObject.getString("icon"));
  876. log.info("上传icon成功....");
  877. }
  878. JSONObject firmwareVersion = new JSONObject();
  879. if(jsonObject.containsKey("camSoftwareVersion") && StrUtil.isNotEmpty(jsonObject.getString("camSoftwareVersion"))){
  880. firmwareVersion.put("camSoftwareVersion", jsonObject.getString("camSoftwareVersion"));
  881. }
  882. if(jsonObject.containsKey("version") && StrUtil.isNotEmpty(jsonObject.getString("version"))){
  883. firmwareVersion.put("version", jsonObject.getString("version"));
  884. }
  885. String sceneUrl = mainUrl + sceneProNewUrl;
  886. String buildType = "V3";
  887. //13表示转台
  888. Long cameraType = 13L;
  889. //激光转台 八目相机占用 10 和 11
  890. if(jsonObject.getJSONObject("cam").getIntValue("type") == 10){
  891. //激光转台
  892. cameraType = 14L;
  893. }
  894. //重算的场景,先移除该场景对应的容量
  895. if(rebuild == 1){
  896. sceneProService.rebuildReduceSpaceBySceneNum(sceneNum);
  897. }else {
  898. //上传log-main.png
  899. uploadToOssUtil.upload(ConstantFilePath.LOGO_PATH + "logo-main.png", imageViewPath + "logo-main.png");
  900. uploadToOssUtil.upload(ConstantFilePath.LOGO_PATH + "logo-main-en.png", imageViewPath + "logo-main-en.png");
  901. // TODO: 2022/1/24 暂时保留旧版本,系统稳定后删除
  902. uploadToOssUtil.upload(ConstantFilePath.LOGO_PATH + "logo-main.png", "images/images" + sceneNum + "/logo-main.png");
  903. uploadToOssUtil.upload(ConstantFilePath.LOGO_PATH + "logo-main-en.png", "images/images" + sceneNum + "/logo-main-en.png");
  904. log.info("第一次计算场景,上传logo-main.png");
  905. }
  906. SceneProPO scene = null;
  907. scene = this.createScenePro(sceneNum, camera.getId(), camera.getChildName(), jsonObject.getString("creator"),
  908. jsonObject.getString("pwd"), unicode,
  909. cameraType, String.valueOf(fileId), prefix, "", icon, "0", cameraDetail.getUserId(), userName,
  910. jsonObject.getString("location") != null && "1".equals(jsonObject.getString("location")) ? "sfm" : "slam",
  911. jsonObject.getJSONArray("points").size(), jsonObject.getString("name"), jsonObject.getString("info"),
  912. jsonObject.getInteger("scenetype"), jsonObject.getString("gps"), rebuild,
  913. jsonObject.getInteger("resolution"), firmwareVersion.toString(), sceneUrl, buildType, type, ecsType,cameraDetail.getCooperationUser());
  914. if(scene != null){
  915. JSONObject statusJson = new JSONObject();
  916. //临时将-2改成1,app还没完全更新
  917. statusJson.put("status", scene.getSceneStatus() == -2? 1 : scene.getSceneStatus());
  918. statusJson.put("webSite", scene.getWebSite());
  919. statusJson.put("sceneNum", scene.getNum());
  920. statusJson.put("thumb", scene.getThumb());
  921. statusJson.put("payStatus", scene.getPayStatus());
  922. statusJson.put("recStatus", scene.getRecStatus());
  923. FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data/data"+sceneNum+File.separator+"status.json", statusJson.toString());
  924. uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH+"data/data"+sceneNum+File.separator+"status.json",
  925. dataViewPath + File.separator+"status.json");
  926. // TODO: 2022/1/24 暂时保留旧版本,系统稳定后删除
  927. uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH+"data/data"+sceneNum+File.separator+"status.json",
  928. "data/data"+sceneNum+File.separator+"status.json");
  929. log.info("上传status.json,上传内容:{}" + statusJson.toString());
  930. }
  931. if(cameraDetail.getCompanyId() != null){
  932. ResultData<Company> companyResult = platformUserClient.getCompanyById(cameraDetail.getCompanyId());
  933. Company company = companyResult.getData();
  934. if(company != null){
  935. Map<String, Object> jsonMap = new HashMap<>();
  936. log.info("复制企业logo");
  937. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scene.getId());
  938. SceneProEditExt sceneProEditExt = sceneProEditExtService.getByProEditId(sceneProEdit.getId());
  939. if(StrUtil.isNotEmpty(company.getTopLogo())){
  940. FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + company.getTopLogo(),
  941. ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/logo-main.png", true);
  942. uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/logo-main.png",
  943. imageViewPath + "logo-main.png");
  944. // TODO: 2022/1/24 暂时保留旧版本,系统稳定后删除
  945. uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/logo-main.png",
  946. "images/images" + sceneNum + "/logo-main.png");
  947. }
  948. if(StrUtil.isNotEmpty(company.getFloorLogo())){
  949. FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + company.getFloorLogo(),
  950. ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/floorLogoImg.png", true);
  951. uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/floorLogoImg.png",
  952. imageViewPath + "floorLogoImg.png");
  953. // TODO: 2022/1/24 暂时保留旧版本,系统稳定后删除
  954. uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/floorLogoImg.png",
  955. "images/images" + sceneNum + "/floorLogoImg.png");
  956. sceneProEdit.setFloorLogo("user");
  957. jsonMap.put("floorLogoSize", sceneProEdit.getFloorLogoSize());
  958. jsonMap.put("floorLogo", "user");
  959. }
  960. if(StrUtil.isNotEmpty(company.getQrLogo())){
  961. FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + company.getQrLogo(),
  962. ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png", true);
  963. uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png",
  964. imageViewPath + "QRShareLogo.png");
  965. // TODO: 2022/1/24 暂时保留旧版本,系统稳定后删除
  966. uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png",
  967. "images/images" + sceneNum + "/QRShareLogo.png");
  968. // sceneProEdit.setShareLogo("images/images" + sceneNum + "/QRShareLogo.png");//旧系统代码,先保留
  969. sceneProEdit.setShareLogo(imageViewPath + "QRShareLogo.png");
  970. //生成新的分享的二维码-中文版本
  971. MatrixToImageWriterUtil.createQRCode(sceneUrl + sceneNum, ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneNum+".png",
  972. ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png");
  973. //生成新的分享的二维码-英文版本
  974. MatrixToImageWriterUtil.createQRCode(sceneUrl + sceneNum + "&lang=en", ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneNum+"_en.png",
  975. ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png");
  976. }
  977. if(StrUtil.isNotEmpty(company.getMarkerLogo())){
  978. FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + company.getMarkerLogo(),
  979. ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/marker.png", true);
  980. uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/marker.png",
  981. imageViewPath + "marker.png");
  982. // TODO: 2022/1/24 暂时保留旧版本,系统稳定后删除
  983. uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/marker.png",
  984. "images/images" + sceneNum + "/marker.png");
  985. sceneProEdit.setMarkerLogo("user");
  986. jsonMap.put("markerLogo", "user");
  987. }
  988. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  989. sceneProEditService.updateById(sceneProEdit);
  990. sceneProEditExt.setUpdateTime(Calendar.getInstance().getTime());
  991. sceneProEditExt.setShowLogoBottom(company.getShowLogo());
  992. sceneProEditExtService.updateById(sceneProEditExt);
  993. jsonMap.put("showLogoBottom", company.getShowLogo());
  994. FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + "/scene.json", jsonMap);
  995. }
  996. //删除oss的houst_floor.json
  997. uploadToOssUtil.delete(dataViewPath + "houst_floor.json");
  998. // TODO: 2022/1/24 暂时保留旧版本,系统稳定后删除
  999. uploadToOssUtil.delete("data/data"+sceneNum+File.separator+"houst_floor.json");
  1000. }
  1001. //激光转台 八目相机占用 10 和 11
  1002. log.info("发送mq,camType:{}", jsonObject.getJSONObject("cam").getIntValue("type"));
  1003. if(jsonObject.getJSONObject("cam").getIntValue("type") == 10){
  1004. mqProducer.sendOneWay(topicLaserA, scene.getMqMsg());
  1005. }else if(scene != null){
  1006. // mqProducer.sendInOrder(topicModelingA, scene.getId()+"", scene.getMqMsg());
  1007. mqProducer.syncSend(topicModelingAPre, scene.getMqMsg());
  1008. }
  1009. }
  1010. @Override
  1011. public ResultData buildScene(BuildSceneParamVO buildScene) throws Exception {
  1012. if(StrUtil.isEmpty(buildScene.getUnicode()) || StrUtil.isEmpty(buildScene.getCameraName()) ||
  1013. StrUtil.isEmpty(buildScene.getSceneKey()) ||
  1014. StrUtil.isEmpty(buildScene.getPrefix()) || StrUtil.isEmpty(buildScene.getFileName()) ||
  1015. StrUtil.isEmpty(buildScene.getSceneName()) || StrUtil.isEmpty(buildScene.getSceneDec()) ||
  1016. buildScene.getSceneType() == null || buildScene.getShootCount() == null ||
  1017. StrUtil.isEmpty(buildScene.getThumb()) || StrUtil.isEmpty(buildScene.getAlgorithm()) ){
  1018. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  1019. }
  1020. String sceneNum = null;
  1021. try{
  1022. sceneNum = scene3dNumService.generateSceneNum();
  1023. if(sceneNum == null){
  1024. log.error("大场景序号为空:" + sceneNum);
  1025. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1026. }
  1027. log.info("查询相机:" + buildScene.getCameraName());
  1028. ResultData<Camera> cameraResult= platformGoodsClient.getCameraByChildName(buildScene.getCameraName());
  1029. Camera camera = cameraResult.getData();
  1030. if(camera == null){
  1031. log.error("该相机不存在:" + buildScene.getCameraName());
  1032. throw new BusinessException(CameraConstant.FAILURE_6003);
  1033. }
  1034. ResultData<CameraDetail> cameraDetailResult = platformGoodsClient.getCameraDetailByCameraId(camera.getId());
  1035. CameraDetail cameraDetail = cameraDetailResult.getData();
  1036. int balance = Integer.valueOf(cameraDetail.getBalance());
  1037. if(balance - Constant.MONEY_SCENE <0){
  1038. log.error("相机点数不足:" + buildScene.getCameraName());
  1039. throw new BusinessException(CameraConstant.FAILURE_6006);
  1040. }
  1041. ResultData<SSOUser> ssoUserResult = platformUserClient.getSSOUserByUserId(cameraDetail.getUserId());
  1042. SSOUser user = ssoUserResult.getData();
  1043. if(user == null){
  1044. log.error("用户id不存在:" + cameraDetail.getUserId());
  1045. throw new BusinessException(ErrorCode.FAILURE_CODE_3015);
  1046. }
  1047. ScenePO scenePO = this.createScene(sceneNum, camera.getId(), camera.getChildName(), buildScene.getPhoneId(),
  1048. buildScene.getSceneKey(), buildScene.getUnicode(), cameraDetail.getCameraType(), "0", buildScene.getPrefix(),
  1049. buildScene.getFileName(), buildScene.getThumb(), "0", cameraDetail.getUserId(), user.getUserName(),
  1050. buildScene.getAlgorithm(), buildScene.getShootCount(), buildScene.getSceneName(),
  1051. buildScene.getSceneDec(), buildScene.getSceneType(), buildScene.getGps(), 0, mainUrl + sceneUrl, ecsType);
  1052. return ResultData.ok(scenePO);
  1053. }catch (Exception e){
  1054. log.error("增加大场景失败:" + sceneNum);
  1055. sceneProService.updateStatus(sceneNum, -1);
  1056. throw new BusinessException(ErrorCode.FAILURE_CODE_5011);
  1057. }
  1058. }
  1059. public void buildScene(String filePath, String fileId, boolean fromOss, String prefix) throws Exception{
  1060. //获取解压后的资源的data.fdage中的数据
  1061. String data = FileUtils.readFile(filePath + "data.fdage");
  1062. JSONObject jsonObject = JSONObject.parseObject(data);
  1063. //调用createScene方法生成scene数据和加入算法队列
  1064. if(jsonObject != null){
  1065. //有calibration值为标定,1: camera_calibration 2: color_anlysis,0正常计算
  1066. if(jsonObject.get("calibration") != null && jsonObject.getString("calibration").equals("1")){
  1067. String mac = filePath.replace(ConstantFilePath.BUILD_MODEL_PATH, "").split("/")[0];
  1068. String calPath = ConstantFilePath.BUILD_MODEL_PATH + mac + "/camera_calibration";
  1069. //生成标定数据
  1070. ComputerUtil.createCalibrationData(calPath, filePath);
  1071. //开始标定计算
  1072. mqProducer.sendInOrder(topicModelingA, new Random().nextInt()+"", calPath);
  1073. }else if(jsonObject.get("calibration") != null && jsonObject.getString("calibration").equals("2")){
  1074. String mac = filePath.replace(ConstantFilePath.BUILD_MODEL_PATH, "").split("/")[0];
  1075. String calPath = ConstantFilePath.BUILD_MODEL_PATH + mac + "/color_anlysis";
  1076. //生成标定数据
  1077. ComputerUtil.createCalibrationData(calPath, filePath);
  1078. //开始标定计算
  1079. Map<String,String> map = ComputerUtil.computerCalibration(calPath);
  1080. }else if(jsonObject.get("calibration") != null && jsonObject.getString("calibration").equals("3")){
  1081. String mac = filePath.replace(ConstantFilePath.BUILD_MODEL_PATH, "").split("/")[0];
  1082. String calPath = ConstantFilePath.BUILD_MODEL_PATH + mac + "/shading";
  1083. //生成标定数据
  1084. ComputerUtil.createCalibrationData(calPath, filePath);
  1085. //开始标定计算
  1086. mqProducer.sendInOrder(topicModelingA, new Random().nextInt()+"", calPath);
  1087. }else {
  1088. String sceneNum = "";
  1089. String cameraName = jsonObject.getJSONObject("cam").getString("uuid");
  1090. String unicode = jsonObject.getString("creator") + "_" + jsonObject.getString("uuidtime");
  1091. //查看场景中的文件目录是否有改文件id,有则重新计算改场景,无则新建场景
  1092. SceneProPO proEntity = sceneProService.findByFileId("/" + fileId + "/");
  1093. int rebuild = 1;
  1094. if(proEntity != null){
  1095. sceneNum = proEntity.getNum();
  1096. if(proEntity.getSceneStatus() == SceneStatus.wait.code()){
  1097. log.info(sceneNum + ":场景处于计算中,不能再计算");
  1098. return;
  1099. }
  1100. }else {
  1101. sceneNum = scene3dNumService.generateSceneNum();
  1102. rebuild = 0;
  1103. }
  1104. if(sceneNum == null){
  1105. log.error("大场景序号为空:" + sceneNum);
  1106. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1107. }
  1108. log.info("查询相机:" + cameraName);
  1109. ResultData<Camera> cameraResult = platformGoodsClient.getCameraByChildName(cameraName);
  1110. Camera camera = cameraResult.getData();
  1111. if(camera == null){
  1112. log.error("该相机不存在:" + cameraName);
  1113. //偶现data.fdage给的相机码多了或少了4DKKPRO_
  1114. if(cameraName.contains("4DKKPRO_")){
  1115. cameraResult = platformGoodsClient.getCameraByChildName(cameraName.replace("4DKKPRO_", ""));
  1116. camera = cameraResult.getData();
  1117. }else {
  1118. cameraResult = platformGoodsClient.getCameraByChildName("4DKKPRO_" + cameraName);
  1119. camera = cameraResult.getData();
  1120. }
  1121. if(camera == null){
  1122. throw new BusinessException(CameraConstant.FAILURE_6003);
  1123. }
  1124. }
  1125. ResultData<CameraDetail> cameraDetailResult = platformGoodsClient.getCameraDetailByCameraId(camera.getId());
  1126. CameraDetail cameraDetail = cameraDetailResult.getData();
  1127. if(cameraDetail == null){
  1128. log.error("该相机详情不存在:" + cameraName);
  1129. throw new BusinessException(CameraConstant.FAILURE_6003);
  1130. }
  1131. String userName = null;
  1132. if(cameraDetail.getUserId() != null){
  1133. ResultData<SSOUser> ssoResult = platformUserClient.getSSOUserByUserId(cameraDetail.getUserId());
  1134. SSOUser user = ssoResult.getData();
  1135. if(user != null){
  1136. userName = user.getUserName();
  1137. }
  1138. }
  1139. String icon = null;
  1140. if(jsonObject.containsKey("icon") && StrUtil.isNotEmpty(jsonObject.getString("icon"))){
  1141. CreateObjUtil.ossUtilCp(ConstantFilePath.OSS_PREFIX + prefix + jsonObject.getString("icon"), filePath);
  1142. icon = prefixAli + "images/images" + sceneNum + "/" + jsonObject.getString("icon");
  1143. if("aws".equals(type)){
  1144. CreateObjUtil.ossFileCp(ConstantFilePath.OSS_PREFIX + prefix + jsonObject.getString("icon"), filePath + jsonObject.getString("icon"));
  1145. icon = ConstantUrl.PREFIX_AWS + "images/images" + sceneNum + "/" + jsonObject.getString("icon");
  1146. }
  1147. uploadToOssUtil.upload(filePath + jsonObject.getString("icon"), "images/images" + sceneNum + "/" + jsonObject.getString("icon"));
  1148. }
  1149. JSONObject firmwareVersion = new JSONObject();
  1150. if(jsonObject.containsKey("camSoftwareVersion") && StrUtil.isNotEmpty(jsonObject.getString("camSoftwareVersion"))){
  1151. firmwareVersion.put("camSoftwareVersion", jsonObject.getString("camSoftwareVersion"));
  1152. }
  1153. if(jsonObject.containsKey("version") && StrUtil.isNotEmpty(jsonObject.getString("version"))){
  1154. firmwareVersion.put("version", jsonObject.getString("version"));
  1155. }
  1156. String sceneUrl = mainUrl + sceneProUrl;
  1157. String buildType = "V2";
  1158. Long cameraType = 10L;
  1159. //根据videoVersion判断是V2还是V3版本的算法和页面
  1160. if(jsonObject.containsKey("videoVersion") && StrUtil.isNotEmpty(jsonObject.getString("videoVersion"))){
  1161. if(jsonObject.getIntValue("videoVersion") >= 4){
  1162. buildType = "V3";
  1163. cameraType = 11L;
  1164. sceneUrl = mainUrl + sceneProNewUrl;
  1165. }
  1166. }
  1167. //重算的场景,先移除该场景对应的容量
  1168. if(rebuild == 1){
  1169. sceneProService.rebuildReduceSpaceBySceneNum(sceneNum);
  1170. }else {
  1171. //上传log-main.png
  1172. uploadToOssUtil.upload(ConstantFilePath.LOGO_PATH + "logo-main.png", "images/images" + sceneNum + "/logo-main.png");
  1173. uploadToOssUtil.upload(ConstantFilePath.LOGO_PATH + "logo-main-en.png", "images/images" + sceneNum + "/logo-main-en.png");
  1174. }
  1175. SceneProPO sceneProPO = null;
  1176. if(fromOss){
  1177. sceneProPO = this.createScenePro(sceneNum, camera.getId(), camera.getChildName(), jsonObject.getString("creator"),
  1178. jsonObject.getString("pwd"), unicode,
  1179. cameraType, String.valueOf(fileId), prefix, "", icon, "0", cameraDetail.getUserId(), userName,
  1180. jsonObject.getString("location") != null && "1".equals(jsonObject.getString("location")) ? "sfm" : "slam",
  1181. jsonObject.getJSONArray("points").size(), jsonObject.getString("name"), jsonObject.getString("info"),
  1182. jsonObject.getInteger("scenetype"), jsonObject.getString("gps"), rebuild,
  1183. jsonObject.getInteger("resolution"), firmwareVersion.toString(), sceneUrl, buildType, type, ecsType,cameraDetail.getCooperationUser());
  1184. }else {
  1185. sceneProPO = this.createScenePro(sceneNum, camera.getId(), camera.getChildName(), jsonObject.getString("creator"),
  1186. jsonObject.getString("pwd"), unicode,
  1187. cameraDetail.getGoodsId(), String.valueOf(fileId), "", "", icon, "0", cameraDetail.getUserId(), userName,
  1188. jsonObject.getString("location") != null && "1".equals(jsonObject.getString("location")) ? "sfm" : "slam",
  1189. jsonObject.getJSONArray("points").size(), jsonObject.getString("name"), jsonObject.getString("info"),
  1190. jsonObject.getInteger("scenetype"), jsonObject.getString("gps"), rebuild,
  1191. jsonObject.getInteger("resolution"), firmwareVersion.toString(), sceneUrl, buildType, type, ecsType, cameraDetail.getCooperationUser());
  1192. }
  1193. if(sceneProPO != null){
  1194. JSONObject statusJson = new JSONObject();
  1195. //临时将-2改成1,app还没完全更新
  1196. statusJson.put("status", sceneProPO.getSceneStatus() == -2 ? 1 : sceneProPO.getSceneStatus());
  1197. statusJson.put("webSite", sceneProPO.getWebSite());
  1198. statusJson.put("sceneNum", sceneProPO.getNum());
  1199. statusJson.put("thumb", sceneProPO.getThumb());
  1200. statusJson.put("payStatus", sceneProPO.getPayStatus());
  1201. statusJson.put("recStatus", sceneProPO.getRecStatus());
  1202. FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data/data"+sceneNum+File.separator+"status.json", statusJson.toString());
  1203. uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH+"data/data"+sceneNum+File.separator+"status.json",
  1204. "data/data"+sceneNum+File.separator+"status.json");
  1205. }
  1206. //删除oss的houst_floor.json(国际版可能会卡住)
  1207. uploadToOssUtil.delete("data/data"+sceneNum+File.separator+"houst_floor.json");
  1208. if(cameraDetail.getCompanyId() != null){
  1209. ResultData<Company> companyResult = platformUserClient.getCompanyById(cameraDetail.getCompanyId());
  1210. Company company = companyResult.getData();
  1211. if(company != null){
  1212. Map<String, Object> jsonMap = new HashMap<>();
  1213. log.info("复制企业logo");
  1214. SceneProEdit sceneProEdit = sceneProEditService.findByProId(sceneProPO.getId());
  1215. SceneProEditExt sceneProEditExt = sceneProEditExtService.getByProEditId(sceneProEdit.getId());
  1216. if(StrUtil.isNotEmpty(company.getTopLogo())){
  1217. //复制阿里云主服务器的图片到横琴云副服务器中
  1218. if(!new File(ConstantFilePath.BASE_PATH + File.separator + company.getTopLogo()).exists()){
  1219. log.info("下载topLogo");
  1220. FileUtils.downLoadFromUrl(mainUrl + company.getTopLogo() + "?t=" + System.currentTimeMillis(),
  1221. company.getTopLogo().substring(company.getTopLogo().lastIndexOf("/") + 1),
  1222. ConstantFilePath.BASE_PATH + company.getTopLogo().substring(0, company.getTopLogo().lastIndexOf("/")));
  1223. }
  1224. FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + company.getTopLogo(),
  1225. ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/logo-main.png", true);
  1226. uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/logo-main.png",
  1227. "images/images" + sceneNum + "/logo-main.png");
  1228. }
  1229. if(StrUtil.isNotEmpty(company.getFloorLogo())){
  1230. //复制阿里云主服务器的图片到横琴云副服务器中
  1231. if(!new File(ConstantFilePath.BASE_PATH + File.separator + company.getFloorLogo()).exists()){
  1232. log.info("下载floorLogo");
  1233. FileUtils.downLoadFromUrl(mainUrl + company.getFloorLogo() + "?t=" + System.currentTimeMillis(),
  1234. company.getFloorLogo().substring(company.getFloorLogo().lastIndexOf("/") + 1),
  1235. ConstantFilePath.BASE_PATH + company.getFloorLogo().substring(0, company.getFloorLogo().lastIndexOf("/")));
  1236. }
  1237. FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + company.getFloorLogo(),
  1238. ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/floorLogoImg.png", true);
  1239. uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/floorLogoImg.png",
  1240. "images/images" + sceneNum + "/floorLogoImg.png");
  1241. sceneProEdit.setFloorLogo("user");
  1242. jsonMap.put("floorLogoSize", sceneProEdit.getFloorLogoSize());
  1243. jsonMap.put("floorLogo", "user");
  1244. }
  1245. if(StrUtil.isNotEmpty(company.getQrLogo())){
  1246. //复制阿里云主服务器的图片到横琴云副服务器中
  1247. if(!new File(ConstantFilePath.BASE_PATH + File.separator + company.getQrLogo()).exists()){
  1248. log.info("下载qrLogo");
  1249. FileUtils.downLoadFromUrl(mainUrl + company.getQrLogo() + "?t=" + System.currentTimeMillis(),
  1250. company.getQrLogo().substring(company.getQrLogo().lastIndexOf("/") + 1),
  1251. ConstantFilePath.BASE_PATH + company.getQrLogo().substring(0, company.getQrLogo().lastIndexOf("/")));
  1252. }
  1253. FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + company.getQrLogo(),
  1254. ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png", true);
  1255. uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png",
  1256. "images/images" + sceneNum + "/QRShareLogo.png");
  1257. sceneProEdit.setShareLogo("images/images" + sceneNum + "/QRShareLogo.png");
  1258. //生成新的分享的二维码
  1259. MatrixToImageWriterUtil.createQRCode(sceneUrl + sceneNum, ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneNum+".png",
  1260. ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png");
  1261. MatrixToImageWriterUtil.createQRCode(sceneUrl + sceneNum + "&lang=en", ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneNum+"_en.png",
  1262. ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png");
  1263. }
  1264. if(StrUtil.isNotEmpty(company.getMarkerLogo())){
  1265. //复制阿里云主服务器的图片到横琴云副服务器中
  1266. if(!new File(ConstantFilePath.BASE_PATH + File.separator + company.getMarkerLogo()).exists()){
  1267. log.info("下载floorLogo");
  1268. FileUtils.downLoadFromUrl(mainUrl + company.getMarkerLogo() + "?t=" + System.currentTimeMillis(),
  1269. company.getMarkerLogo().substring(company.getMarkerLogo().lastIndexOf("/") + 1),
  1270. ConstantFilePath.BASE_PATH + company.getMarkerLogo().substring(0, company.getMarkerLogo().lastIndexOf("/")));
  1271. }
  1272. FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + company.getMarkerLogo(),
  1273. ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/marker.png", true);
  1274. uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/marker.png",
  1275. "images/images" + sceneNum + "/marker.png");
  1276. sceneProEdit.setMarkerLogo("user");
  1277. jsonMap.put("markerLogo", "user");
  1278. }
  1279. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  1280. sceneProEditService.updateById(sceneProEdit);
  1281. sceneProEditExt.setUpdateTime(Calendar.getInstance().getTime());
  1282. sceneProEditExt.setShowLogoBottom(company.getShowLogo());
  1283. sceneProEditExtService.updateById(sceneProEditExt);
  1284. jsonMap.put("showLogoBottom", company.getShowLogo());
  1285. FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + "/scene.json", jsonMap);
  1286. }
  1287. }
  1288. // 正顺相机不予计算
  1289. Long companyId = cameraDetail.getCompanyId();
  1290. if(Objects.nonNull(unCalculatedCompanyIds) && Arrays.asList(unCalculatedCompanyIds).contains(companyId)){
  1291. return;
  1292. }
  1293. if(sceneProPO != null){
  1294. mqProducer.sendInOrder(topicModelingA, sceneProPO.getId()+"", sceneProPO.getMqMsg());
  1295. }
  1296. }
  1297. }else {
  1298. log.info("data.fdage文件不存在");
  1299. throw new BusinessException(CameraConstant.FAILURE_6009);
  1300. }
  1301. }
  1302. public ScenePO createScene(String projectNum, Long cameraId, String cameraName, String phoneId, String scenepsd,
  1303. String unicode, Integer cameraType, String fileId, String prefix,
  1304. String imgsName, String pic, String isModel, Long userId, String userName,
  1305. String algorithm, Integer sceneShootCount, String sceneName,
  1306. String sceneDec, Integer sceneType, String gps,
  1307. Integer type, String url, String ecsType)throws Exception{
  1308. //先返回链接地址
  1309. ScenePO scenePo = new ScenePO();
  1310. Scene scene = new Scene();
  1311. SceneExt sceneExt = new SceneExt();
  1312. scene.setWebSite(url+projectNum);
  1313. scene.setCameraId(cameraId);
  1314. scene.setPhoneId(phoneId);
  1315. scene.setNum(String.valueOf(projectNum));
  1316. if(scenepsd == null)
  1317. {
  1318. scenepsd = "";
  1319. }
  1320. if(!scenepsd.equals(""))
  1321. {
  1322. scene.setSceneKey(scenepsd);
  1323. }
  1324. if(!org.springframework.util.StringUtils.isEmpty(ecsType)){
  1325. sceneExt.setOss(ecsType);
  1326. }
  1327. String path = ConstantFilePath.BUILD_MODEL_PATH + unicode;
  1328. if(cameraType.longValue() >= 4){
  1329. scene.setDataSource(ConstantFilePath.BUILD_MODEL_PATH +
  1330. cameraName.replace("4DKKPRO_", "").replace("-fdage", "").toLowerCase() + File.separator + fileId + File.separator + unicode);
  1331. }else {
  1332. scene.setDataSource(prefix+imgsName);
  1333. }
  1334. if(cameraType.longValue() == 14){
  1335. scene.setDataSource(ConstantFilePath.BUILD_MODEL_LASER_PATH +
  1336. cameraName.replace("4DKKPRO_", "").replace("-fdage", "").toLowerCase() + File.separator +
  1337. fileId + File.separator + unicode);
  1338. log.info("激光相机 dataSource :" + scene.getDataSource());
  1339. }
  1340. if(pic!=null&&pic.length()>5) {
  1341. scene.setThumb(pic);
  1342. }else{
  1343. scene.setThumb(ConstantUrl.DEFAULT_SCENE_PIC);
  1344. }
  1345. BuildSceneMqMessage buildSceneMqMessage = new BuildSceneMqMessage();
  1346. buildSceneMqMessage.setUnicode(unicode);
  1347. buildSceneMqMessage.setPath(path);
  1348. buildSceneMqMessage.setPrefix(prefix);
  1349. buildSceneMqMessage.setImgsName(imgsName);
  1350. buildSceneMqMessage.setSceneNum(projectNum);
  1351. buildSceneMqMessage.setIsModel(isModel);
  1352. buildSceneMqMessage.setCameraType(String.valueOf(cameraType));
  1353. buildSceneMqMessage.setAlgorithm(algorithm);
  1354. buildSceneMqMessage.setFileId(fileId);
  1355. buildSceneMqMessage.setCameraName(cameraName);
  1356. if(StrUtil.isNotBlank(userName))
  1357. {
  1358. buildSceneMqMessage.setUserName(userName);
  1359. scene.setUserId(userId);
  1360. }
  1361. else
  1362. {
  1363. buildSceneMqMessage.setUserName("noMan");
  1364. }
  1365. // mqProducer.syncSend(topicModelingA, buildSceneMqMessage);
  1366. mqProducer.syncSend(topicModelingAPre, buildSceneMqMessage);
  1367. if(sceneShootCount == null)
  1368. {
  1369. sceneExt.setShootCount(0);
  1370. }
  1371. else
  1372. {
  1373. sceneExt.setShootCount(sceneShootCount);
  1374. }
  1375. if(sceneName!=null)
  1376. {
  1377. scene.setSceneName(sceneName);
  1378. }
  1379. if(sceneDec!=null)
  1380. {
  1381. scene.setSceneDec("<p>"+sceneDec+"</p>");
  1382. }
  1383. if(sceneType!=null)
  1384. {
  1385. scene.setSceneType(sceneType);
  1386. }
  1387. if(gps!=null&&!gps.trim().equals(""))
  1388. {
  1389. sceneExt.setGps(gps);
  1390. }
  1391. sceneExt.setSceneScheme(cameraType.intValue());
  1392. sceneExt.setAlgorithm(algorithm);
  1393. log.info("场景记录添加到数据库:"+projectNum);
  1394. //type=0为新生成场景,其余为重新计算场景
  1395. if(type == 0){
  1396. sceneService.save(scene);
  1397. sceneExt.setSceneId(scene.getId());
  1398. sceneExtService.save(sceneExt);
  1399. }
  1400. JSONObject scenejson = JSONObject.parseObject(JSONObject.toJSONString(scene));
  1401. scenejson.put("thumbImg", 0);
  1402. scenejson.put("version", 0);
  1403. scenejson.put("floorLogo", 0);
  1404. if(!scenepsd.equals("")){
  1405. scenejson.put("scenePsd", scenepsd);
  1406. scenejson.put("public", 1);
  1407. }else{
  1408. scenejson.put("scenePsd", "");
  1409. scenejson.put("public", 0);
  1410. }
  1411. if(cameraType < 4){
  1412. scenejson.put("visions", 1);
  1413. }else {
  1414. scenejson.put("visions", 2);
  1415. }
  1416. scenejson.put("createTime", new DateTime(new Date()).toString("yyyy-MM-dd HH:mm"));
  1417. File file = new File(ConstantFilePath.SCENE_PATH+"data/data"+projectNum);
  1418. if(!file.exists()||!file.isDirectory())
  1419. {
  1420. file.mkdirs();
  1421. }
  1422. FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data/data"+projectNum+File.separator+"scene.json", scenejson.toString());
  1423. // UploadToOssUtil.upload(ConstantFilePath.SCENE_PATH+"data/data"+projectNum+File.separator+"scene.json", "data/data"+projectNum+File.separator+"scene.json");
  1424. //生成二维码
  1425. MatrixToImageWriterUtil.createQRCode(url + projectNum, ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+projectNum+".png", null);
  1426. MatrixToImageWriterUtil.createQRCode(url + projectNum + "&lang=en", ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+projectNum+"_en.png", null);
  1427. log.info("二维码生成完成");
  1428. BeanUtil.copyProperties(sceneExt, scenePo);
  1429. BeanUtil.copyProperties(scene, scenePo);
  1430. return scenePo;
  1431. }
  1432. public ScenePlusVO createScenePlus(String projectNum, Long cameraId, String cameraName, String phoneId, String scenepsd,
  1433. String unicode, Integer cameraType, String fileId, String prefix,
  1434. String imgsName, String pic, String isModel, Long userId, String userName,
  1435. String algorithm, Integer sceneShootCount, String sceneName,
  1436. String sceneDec, Integer sceneType, String gps,
  1437. Integer type, String url, String ecsType)throws Exception{
  1438. ScenePlusVO scenePlusVO = new ScenePlusVO();
  1439. ScenePlus scenePlus = new ScenePlus();
  1440. ScenePlusExt scenePlusExt = new ScenePlusExt();
  1441. // ScenePO scenePo = new ScenePO();
  1442. // Scene scene = new Scene();
  1443. // SceneExt sceneExt = new SceneExt();
  1444. scenePlusExt.setWebSite(url+projectNum);
  1445. scenePlus.setCameraId(cameraId);
  1446. scenePlus.setPhoneId(phoneId);
  1447. scenePlus.setNum(String.valueOf(projectNum));
  1448. if(scenepsd == null)
  1449. {
  1450. scenepsd = "";
  1451. }
  1452. // TODO: 2022/3/16 这里暂时不确定要不要 ---start
  1453. // if(!scenepsd.equals(""))
  1454. // {
  1455. // scene.setSceneKey(scenepsd);
  1456. // }
  1457. // TODO: 2022/3/16 这里暂时不确定要不要 ---end
  1458. if(!org.springframework.util.StringUtils.isEmpty(ecsType)){
  1459. scenePlusExt.setEcs(ecsType);
  1460. }
  1461. String path = ConstantFilePath.BUILD_MODEL_PATH + unicode;
  1462. if(cameraType.longValue() >= 4){
  1463. scenePlusExt.setDataSource(ConstantFilePath.BUILD_MODEL_PATH +
  1464. cameraName.replace("4DKKPRO_", "").replace("-fdage", "").toLowerCase() + File.separator + fileId + File.separator + unicode);
  1465. }else {
  1466. scenePlusExt.setDataSource(prefix+imgsName);
  1467. }
  1468. if(cameraType.longValue() == 14){
  1469. scenePlusExt.setDataSource(ConstantFilePath.BUILD_MODEL_LASER_PATH +
  1470. cameraName.replace("4DKKPRO_", "").replace("-fdage", "").toLowerCase() + File.separator +
  1471. fileId + File.separator + unicode);
  1472. log.info("激光相机 dataSource :" + scenePlusExt.getDataSource());
  1473. }
  1474. if(pic!=null&&pic.length()>5) {
  1475. scenePlusExt.setThumb(pic);
  1476. }else{
  1477. scenePlusExt.setThumb(ConstantUrl.DEFAULT_SCENE_PIC);
  1478. }
  1479. BuildSceneMqMessage buildSceneMqMessage = new BuildSceneMqMessage();
  1480. buildSceneMqMessage.setUnicode(unicode);
  1481. buildSceneMqMessage.setPath(path);
  1482. buildSceneMqMessage.setPrefix(prefix);
  1483. buildSceneMqMessage.setImgsName(imgsName);
  1484. buildSceneMqMessage.setSceneNum(projectNum);
  1485. buildSceneMqMessage.setIsModel(isModel);
  1486. buildSceneMqMessage.setCameraType(String.valueOf(cameraType));
  1487. buildSceneMqMessage.setAlgorithm(algorithm);
  1488. buildSceneMqMessage.setFileId(fileId);
  1489. buildSceneMqMessage.setCameraName(cameraName);
  1490. if(StrUtil.isNotBlank(userName))
  1491. {
  1492. buildSceneMqMessage.setUserName(userName);
  1493. scenePlus.setUserId(userId);
  1494. }
  1495. else
  1496. {
  1497. buildSceneMqMessage.setUserName("noMan");
  1498. }
  1499. mqProducer.syncSend(topicModelingAPre, buildSceneMqMessage);
  1500. if(sceneShootCount == null)
  1501. {
  1502. scenePlusExt.setShootCount(0);
  1503. }
  1504. else
  1505. {
  1506. scenePlusExt.setShootCount(sceneShootCount);
  1507. }
  1508. if(sceneName!=null)
  1509. {
  1510. scenePlus.setTitle(sceneName);
  1511. }
  1512. if(sceneDec!=null)
  1513. {
  1514. scenePlus.setDescription("<p>"+sceneDec+"</p>");
  1515. }
  1516. if(sceneType!=null)
  1517. {
  1518. scenePlus.setSceneType(sceneType);
  1519. }
  1520. if(gps!=null&&!gps.trim().equals(""))
  1521. {
  1522. scenePlusExt.setGps(gps);
  1523. }
  1524. scenePlusExt.setSceneScheme(cameraType.intValue());
  1525. scenePlusExt.setAlgorithm(algorithm);
  1526. log.info("场景记录添加到数据库:"+projectNum);
  1527. //type=0为新生成场景,其余为重新计算场景
  1528. if(type == 0){
  1529. scenePlusService.save(scenePlus);
  1530. scenePlusExt.setPlusId(scenePlus.getId());
  1531. scenePlusExtService.save(scenePlusExt);
  1532. }
  1533. BeanUtil.copyProperties(scenePlusExt, scenePlusVO);
  1534. BeanUtil.copyProperties(scenePlus, scenePlusVO);
  1535. JSONObject scenejson = JSONObject.parseObject(JSONObject.toJSONString(scenePlusVO));
  1536. scenejson.put("thumbImg", 0);
  1537. scenejson.put("version", 0);
  1538. scenejson.put("floorLogo", 0);
  1539. if(!scenepsd.equals("")){
  1540. scenejson.put("scenePsd", scenepsd);
  1541. scenejson.put("public", 1);
  1542. }else{
  1543. scenejson.put("scenePsd", "");
  1544. scenejson.put("public", 0);
  1545. }
  1546. if(cameraType < 4){
  1547. scenejson.put("visions", 1);
  1548. }else {
  1549. scenejson.put("visions", 2);
  1550. }
  1551. scenejson.put("createTime", new DateTime(new Date()).toString("yyyy-MM-dd HH:mm"));
  1552. File file = new File(ConstantFilePath.SCENE_PATH+"data/data"+projectNum);
  1553. if(!file.exists()||!file.isDirectory())
  1554. {
  1555. file.mkdirs();
  1556. }
  1557. FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data/data"+projectNum+File.separator+"scene.json", scenejson.toString());
  1558. // UploadToOssUtil.upload(ConstantFilePath.SCENE_PATH+"data/data"+projectNum+File.separator+"scene.json", "data/data"+projectNum+File.separator+"scene.json");
  1559. //生成二维码
  1560. MatrixToImageWriterUtil.createQRCode(url + projectNum, ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+projectNum+".png", null);
  1561. MatrixToImageWriterUtil.createQRCode(url + projectNum + "&lang=en", ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+projectNum+"_en.png", null);
  1562. log.info("二维码生成完成");
  1563. return scenePlusVO;
  1564. }
  1565. public SceneProPO createScenePro(String projectNum, Long cameraId, String cameraName, String phoneId, String sceneKey,
  1566. String unicode, Long cameraType, String fileId, String prefix,
  1567. String imgsName, String pic, String isModel, Long userId, String userName,
  1568. String algorithm, Integer sceneShootCount, String sceneName,
  1569. String sceneDec, Integer sceneType, String gps,Integer type,
  1570. Integer resolution, String firmwareVersion, String url, String buildType, String ossType, String ecsType,
  1571. Long cooperationUser)throws Exception{
  1572. //先返回链接地址
  1573. SceneProPO sceneProPO = new SceneProPO();
  1574. ScenePro scenePro = new ScenePro();
  1575. SceneProExt sceneProExt = new SceneProExt();
  1576. scenePro.setWebSite(url+projectNum);
  1577. scenePro.setCameraId(cameraId);
  1578. sceneProExt.setPhoneId(phoneId);
  1579. scenePro.setNum(projectNum);
  1580. String path = ConstantFilePath.BUILD_MODEL_PATH + unicode;
  1581. sceneProExt.setSceneSource(1);
  1582. if(cameraType.longValue() == 5 || cameraType.longValue() == 6){
  1583. //场景来源双目相机
  1584. sceneProExt.setSceneSource(2);
  1585. sceneProExt.setDataSource(ConstantFilePath.BUILD_MODEL_PATH + unicode);
  1586. }else if(cameraType.longValue() == 14){
  1587. sceneProExt.setDataSource(ConstantFilePath.BUILD_MODEL_LASER_PATH +
  1588. cameraName.replace("4DKKPRO_", "").replace("-fdage", "").toLowerCase() + File.separator +
  1589. fileId + File.separator + unicode);
  1590. path = ConstantFilePath.BUILD_MODEL_LASER_PATH + unicode;
  1591. log.info("激光相机 dataSource :" + sceneProExt.getDataSource());
  1592. }else if(cameraType.longValue() >= 3){
  1593. sceneProExt.setDataSource(ConstantFilePath.BUILD_MODEL_PATH +
  1594. cameraName.replace("4DKKPRO_", "").replace("-fdage", "").toLowerCase() + File.separator +
  1595. fileId + File.separator + unicode);
  1596. }else {
  1597. sceneProExt.setDataSource(prefix+imgsName);
  1598. }
  1599. if(!org.springframework.util.StringUtils.isEmpty(ecsType)){
  1600. sceneProExt.setEcs(ecsType);
  1601. }
  1602. if(resolution == null || resolution.intValue() == 0){
  1603. scenePro.setSceneScheme(cameraType.intValue());
  1604. }else {
  1605. scenePro.setSceneScheme(4);
  1606. }
  1607. //场景来源双目相机,sceneScheme为4,加载high,low图
  1608. if(cameraType.longValue() == 5 || cameraType.longValue() == 6){
  1609. scenePro.setSceneScheme(4);
  1610. }
  1611. //转台相机用4k图
  1612. if(cameraType.longValue() == 13 ){
  1613. sceneProExt.setSceneSource(3);
  1614. scenePro.setSceneScheme(10);
  1615. }
  1616. //激光相机
  1617. if(cameraType.longValue() == 14 ){
  1618. sceneProExt.setSceneSource(4);
  1619. scenePro.setSceneScheme(10);
  1620. }
  1621. if(pic!=null&&pic.length()>5)
  1622. {
  1623. scenePro.setThumb(pic);
  1624. }
  1625. else
  1626. {
  1627. scenePro.setThumb(ConstantUrl.DEFAULT_SCENE_PIC);
  1628. }
  1629. scenePro.setThumb(scenePro.getThumb().concat("?t=")+System.currentTimeMillis());
  1630. if(!ObjectUtils.isEmpty(userName)){
  1631. scenePro.setUserId(userId);
  1632. }
  1633. if(sceneShootCount == null)
  1634. {
  1635. sceneProExt.setShootCount(0);
  1636. }
  1637. else
  1638. {
  1639. sceneProExt.setShootCount(sceneShootCount);
  1640. }
  1641. if(sceneName!=null)
  1642. {
  1643. scenePro.setSceneName(sceneName);
  1644. }
  1645. if(sceneDec!=null)
  1646. {
  1647. scenePro.setSceneDec("<p>"+ new String(sceneDec.getBytes("UTF-8"))+"</p>");
  1648. }
  1649. if(sceneType!=null)
  1650. {
  1651. scenePro.setSceneType(sceneType);
  1652. }
  1653. if(gps!=null&&!gps.trim().equals(""))
  1654. {
  1655. scenePro.setGps(gps);
  1656. }
  1657. sceneProExt.setAlgorithm(algorithm);
  1658. sceneProExt.setFilesName(imgsName);
  1659. if(!org.springframework.util.StringUtils.isEmpty(firmwareVersion)){
  1660. sceneProExt.setFirmwareVersion(firmwareVersion);
  1661. }
  1662. scenePro.setBuildType(buildType);
  1663. log.info("场景记录添加到数据库:"+projectNum);
  1664. //type=0为新生成场景,其余为重新计算场景
  1665. // TODO: 2022/2/23 SceneProEdit 重构版本SceneProEdit 这个表可能不用,这里先暂时注释掉
  1666. // SceneProEdit sceneProEdit = new SceneProEdit();
  1667. // SceneProEditExt sceneProEditExt = new SceneProEditExt();
  1668. if(type == 0){
  1669. scenePro.setSceneStatus(SceneStatus.wait.code());
  1670. sceneProService.save(scenePro);
  1671. sceneProExt.setSceneProId(scenePro.getId());
  1672. sceneProExtService.save(sceneProExt);
  1673. SceneEditInfo sceneEditInfo = new SceneEditInfo();
  1674. sceneEditInfo.setSceneProId(scenePro.getId());
  1675. sceneEditInfoService.save(sceneEditInfo);
  1676. // sceneProEdit.setNeedKey(0);
  1677. // if(sceneKey == null) {
  1678. // sceneKey = "";
  1679. // }
  1680. // sceneProEdit.setSceneKey(sceneKey);
  1681. // if(!sceneKey.equals("")) {
  1682. // sceneProEdit.setNeedKey(1);
  1683. // }else {
  1684. // sceneProEdit.setNeedKey(0);
  1685. // }
  1686. //
  1687. // sceneProEdit.setProId(scenePro.getId());
  1688. // sceneProEdit.setFloorLogoSize(100);
  1689. // sceneProEdit.setCreateTime(Calendar.getInstance().getTime());
  1690. // sceneProEditService.save(sceneProEdit);
  1691. //
  1692. // sceneProEditExt.setProEditId(sceneProEdit.getId());
  1693. // sceneProEditExt.setProId(scenePro.getId());
  1694. // sceneProEditExt.setMapVisi(1);
  1695. // sceneProEditExt.setTourVisi(1);
  1696. // sceneProEditExt.setVrVisi(1);
  1697. // sceneProEditExt.setRulerVisi(1);
  1698. // sceneProEditExt.setCadImgVisi(1);
  1699. // sceneProEditExt.setPanoVisi(1);
  1700. // sceneProEditExt.setM2dVisi(1);
  1701. // sceneProEditExt.setM3dVisi(1);
  1702. // sceneProEditExt.setMeasureVisi(0);
  1703. // sceneProEditExt.setCreateTime(Calendar.getInstance().getTime());
  1704. // sceneProEditExtService.save(sceneProEditExt);
  1705. //新增场景时,同时新增场景协作信息
  1706. if(cooperationUser != null){
  1707. SceneCooperation sceneCooperationEntity = new SceneCooperation();
  1708. sceneCooperationEntity.setNum(projectNum);
  1709. sceneCooperationEntity.setUserId(cooperationUser);
  1710. sceneCooperationService.save(sceneCooperationEntity);
  1711. List<SceneResourceCamera> resourceCameraList = sceneResourceCameraService.findListByCameraId(cameraId);
  1712. SceneResourceCooperation sceneResourceCooperation = null;
  1713. if(resourceCameraList != null && resourceCameraList.size() > 0){
  1714. for (SceneResourceCamera sceneResourceCamera : resourceCameraList) {
  1715. sceneResourceCooperation = new SceneResourceCooperation();
  1716. sceneResourceCooperation.setSceneResourceId(sceneResourceCamera.getSceneResourceId());
  1717. sceneResourceCooperation.setSceneCooperationId(sceneCooperationEntity.getId());
  1718. sceneResourceCooperationService.save(sceneResourceCooperation);
  1719. }
  1720. }
  1721. }
  1722. }else {
  1723. ScenePro oldScene = sceneProService.findBySceneNum(projectNum);
  1724. scenePro.setId(oldScene.getId());
  1725. scenePro.setSceneStatus(0);
  1726. scenePro.setTbStatus(TbStatus.VALID.code());
  1727. scenePro.setPayStatus(0);
  1728. scenePro.setCreateTime(new Date());
  1729. SceneProExt oldSceneProExt = sceneProExtService.findBySceneProId(oldScene.getId());
  1730. sceneProExt.setSpace(oldSceneProExt.getSpace());
  1731. sceneProExt.setEcs(oldSceneProExt.getEcs());
  1732. sceneProExt.setViewCount(oldSceneProExt.getViewCount());
  1733. if(sceneName!=null) {
  1734. scenePro.setSceneName(sceneName);
  1735. }
  1736. if(sceneType!=null) {
  1737. scenePro.setSceneType(sceneType);
  1738. }
  1739. scenePro.setUpdateTime(Calendar.getInstance().getTime());
  1740. sceneProExt.setUpdateTime(Calendar.getInstance().getTime());
  1741. sceneProService.updateById(scenePro);
  1742. sceneProExtService.updateById(sceneProExt);
  1743. // TODO: 2022/2/23 如果是重算场景 ,这里需要更新一些字段,现在还不知道更写哪些字段,先留空
  1744. SceneEditInfo sceneEditInfo = sceneEditInfoService.getBySceneProId(oldScene.getId());
  1745. if(sceneEditInfo == null){
  1746. throw new BusinessException(ErrorCode.FAILURE_CODE_7008);
  1747. }
  1748. sceneEditInfoService.updateById(sceneEditInfo);
  1749. // SceneProEdit oldSceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  1750. // SceneProEditExt oldSceneProEditeExt = sceneProEditExtService.getByProEditId(oldSceneProEdit.getId());
  1751. // sceneProEdit.setNeedKey(0);
  1752. //
  1753. // if(sceneKey == null) {
  1754. // sceneKey = "";
  1755. // }
  1756. // sceneProEdit.setSceneKey(sceneKey);
  1757. // if(!sceneKey.equals("")) {
  1758. // sceneProEdit.setNeedKey(1);
  1759. // }else {
  1760. // sceneProEdit.setNeedKey(0);
  1761. // }
  1762. //
  1763. // sceneProEdit.setId(oldSceneProEdit.getId());
  1764. // sceneProEdit.setProId(scenePro.getId());
  1765. // sceneProEdit.setFloorLogoSize(100);
  1766. // sceneProEdit.setTbStatus(TbStatus.VALID.code());
  1767. // sceneProEdit.setFloorPublishVer(oldSceneProEdit.getFloorEditVer() + 1);
  1768. // sceneProEdit.setFloorEditVer(oldSceneProEdit.getFloorEditVer() + 1);
  1769. // sceneProEdit.setVersion(oldSceneProEdit.getVersion() + 1);
  1770. // sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  1771. // sceneProEditService.updateById(sceneProEdit);
  1772. //
  1773. // sceneProEditExt.setId(oldSceneProEditeExt.getId());
  1774. // sceneProEditExt.setProId(scenePro.getId());
  1775. // sceneProEditExt.setMapVisi(1);
  1776. // sceneProEditExt.setTourVisi(1);
  1777. // sceneProEditExt.setVrVisi(1);
  1778. // sceneProEditExt.setRulerVisi(1);
  1779. // sceneProEditExt.setCadImgVisi(1);
  1780. // sceneProEditExt.setPanoVisi(1);
  1781. // sceneProEditExt.setM2dVisi(1);
  1782. // sceneProEditExt.setM3dVisi(1);
  1783. // sceneProEditExt.setMeasureVisi(0);
  1784. // sceneProEditExt.setCreateTime(oldSceneProEdit.getCreateTime());
  1785. // sceneProEditExt.setImagesVersion(oldSceneProEditeExt.getImagesVersion() + 1);
  1786. // sceneProEditExt.setUpdateTime(Calendar.getInstance().getTime());
  1787. // sceneProEditExtService.updateById(sceneProEditExt);
  1788. }
  1789. BuildSceneMqMessage buildSceneMqMessage =this.getBuildSceneMqMessage(
  1790. projectNum, cameraName, unicode, cameraType, fileId, prefix, imgsName, isModel,
  1791. userName, algorithm, resolution, buildType, path, scenePro.getId(), scenePro.getSceneName(),
  1792. scenePro.getWebSite(), scenePro.getCreateTime(), scenePro.getUserId(),
  1793. sceneProExt.getDataSource(), scenePro.getSceneStatus(), scenePro.getPayStatus(), scenePro.getThumb());
  1794. sceneProPO.setMqMsg(buildSceneMqMessage);
  1795. BeanUtil.copyProperties(sceneProExt, sceneProPO);
  1796. BeanUtil.copyProperties(scenePro, sceneProPO);
  1797. JSONObject scenejson = JSONObject.parseObject(JSONObject.toJSONString(sceneProPO));
  1798. scenejson.put("thumbImg", 0);
  1799. scenejson.put("version", 0);
  1800. scenejson.put("floorLogo", 0);
  1801. if(!sceneKey.equals("")){
  1802. scenejson.put("sceneKey", sceneKey);
  1803. scenejson.put("public", 1);
  1804. }else{
  1805. scenejson.put("sceneKey", "");
  1806. scenejson.put("public", 0);
  1807. }
  1808. if(cameraType.longValue() < 4 || cameraType.longValue() == 5 || cameraType.longValue() == 6){
  1809. scenejson.put("visions", 1);
  1810. }else {
  1811. scenejson.put("visions", 2);
  1812. }
  1813. scenejson.put("createTime", new DateTime(new Date()).toString("yyyy-MM-dd HH:mm"));
  1814. // scenejson.put("floorPublishVer", sceneProEdit.getFloorPublishVer());
  1815. // scenejson.put("floorEditVer", sceneProEdit.getFloorEditVer());
  1816. scenejson.put("entry", null);
  1817. // if(!org.springframework.util.StringUtils.isEmpty(sceneProEdit.getHotsIds())){
  1818. // scenejson.put("hots", 1);
  1819. // }
  1820. File file = new File(ConstantFilePath.SCENE_PATH+"data/data"+projectNum);
  1821. if(!file.exists()||!file.isDirectory())
  1822. {
  1823. file.mkdirs();
  1824. }
  1825. FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data/data"+projectNum+File.separator+"scene.json", scenejson.toString());
  1826. //生成二维码
  1827. MatrixToImageWriterUtil.createQRCode(url + projectNum, ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+projectNum+".png", null);
  1828. MatrixToImageWriterUtil.createQRCode(url + projectNum + "&lang=en", ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+projectNum+"_en.png", null);
  1829. log.info("二维码生成完成");
  1830. //当mq排队数大于指定数量时使用弹性升缩
  1831. return sceneProPO;
  1832. }
  1833. public BuildSceneMqMessage getBuildSceneMqMessage(String projectNum, String cameraName, String unicode,
  1834. Long cameraType, String fileId,String prefix, String imgsName,
  1835. String isModel, String userName,String algorithm, Integer resolution,
  1836. String buildType, String path, Long sceneProId, String sceneName, String webSite,
  1837. Date sceneProCreateTime, Long userId, String dataSource,
  1838. Integer sceneStatus, Integer PayStatus, String thumb) {
  1839. BuildSceneMqMessage mqMsg = new BuildSceneMqMessage();
  1840. mqMsg.setSceneProId(sceneProId);
  1841. mqMsg.setSceneNum(projectNum);
  1842. mqMsg.setCameraName(cameraName);
  1843. mqMsg.setUnicode(unicode);
  1844. mqMsg.setCameraType(String.valueOf(cameraType));
  1845. mqMsg.setFileId(fileId);
  1846. mqMsg.setPrefix(prefix);
  1847. mqMsg.setImgsName(imgsName);
  1848. mqMsg.setIsModel(isModel);
  1849. mqMsg.setUserName(userName);
  1850. mqMsg.setAlgorithm(algorithm);
  1851. mqMsg.setResolution(String.valueOf(resolution));
  1852. mqMsg.setBuildType(buildType);
  1853. mqMsg.setPath(path);
  1854. mqMsg.setSceneName(sceneName);
  1855. mqMsg.setWebSite(webSite);
  1856. mqMsg.setSceneProCreateTime(sceneProCreateTime);
  1857. mqMsg.setUserId(userId);
  1858. mqMsg.setDataSource(dataSource);
  1859. mqMsg.setSceneStatus(sceneStatus);
  1860. mqMsg.setPayStatus(PayStatus);
  1861. mqMsg.setCreateTime(DateUtil.format(Calendar.getInstance().getTime(), DateExtUtil.dateStyle));
  1862. mqMsg.setThumb(thumb);
  1863. return mqMsg;
  1864. }
  1865. public String saveFile(MultipartFile file, String filePath, String fileId) throws IOException {
  1866. //扩展名格式
  1867. String extName = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
  1868. String name;
  1869. /*
  1870. 指定上传目录
  1871. */
  1872. if (filePath != null && !"".equals(filePath.trim())) {
  1873. name = designatedUp(filePath, fileId, file);
  1874. return name;
  1875. }
  1876. /*
  1877. 默认上传目录
  1878. */
  1879. //图片类型文件
  1880. if (this.inArray(routeConfig.getImageType(), extName)) {
  1881. filePath = routeConfig.getImageFolder();
  1882. }
  1883. //视频类型文件
  1884. else if (this.inArray(routeConfig.getVideoType(), extName)) {
  1885. filePath = routeConfig.getVideoFolder();
  1886. }
  1887. //文档类型文件
  1888. else if (this.inArray(routeConfig.getDocumentType(), extName)) {
  1889. filePath = routeConfig.getDocumentFolder();
  1890. }
  1891. //音频类型文件
  1892. else if (this.inArray(routeConfig.getMusicType(), extName)) {
  1893. filePath = routeConfig.getMusicFolder();
  1894. } else {
  1895. return "This upload type is not supported temporarily";
  1896. }
  1897. name = myfileUp(filePath, file);
  1898. return name;
  1899. }
  1900. /**
  1901. * 删除文件
  1902. *
  1903. * @param filePath 包含文件路径的文件名
  1904. * @return
  1905. */
  1906. public String dropFile(String filePath) {
  1907. try {
  1908. FileUtil.delFile(routeConfig.getHardDisk() + File.separator + filePath);
  1909. return "successful operation";
  1910. } catch (Exception e) {
  1911. return "drop file error";
  1912. }
  1913. }
  1914. /**
  1915. * 判断数组中是否包含某个元素
  1916. *
  1917. * @param array 类型的数组
  1918. * @param element 被检查的类型
  1919. * @return
  1920. */
  1921. private boolean inArray(String[] array, String element) {
  1922. boolean flag = false;
  1923. for (String type : array) {
  1924. if (element.equals(type)) {
  1925. flag = true;
  1926. break;
  1927. }
  1928. }
  1929. return flag;
  1930. }
  1931. /**
  1932. * 默认上传文件到文件夹
  1933. *
  1934. * @param folder 默认文件夹
  1935. * @param file 上传的文件
  1936. * @return
  1937. */
  1938. private String myfileUp(String folder, MultipartFile file) throws IOException {
  1939. LocalDate today = LocalDate.now();
  1940. String saveName = File.separator + today.getYear() + "." + today.getMonthValue() + File.separator;
  1941. String fileCode = UUID.randomUUID().toString().trim().replaceAll("-", "");
  1942. String returnName = FileUpload.fileUp(file, routeConfig.getHardDisk() + File.separator + folder + saveName, fileCode);
  1943. saveName = folder + File.separator + saveName + File.separator + returnName;
  1944. log.warn("This file has been uploaded: " + saveName);
  1945. return saveName;
  1946. }
  1947. /**
  1948. * 指定目录上传文件
  1949. *
  1950. * @param folder 指定文件夹
  1951. * @param file 上传文件
  1952. * @return
  1953. */
  1954. private String designatedUp(String folder, String fileId, MultipartFile file) throws IOException {
  1955. StringBuffer sb = new StringBuffer(routeConfig.getHardDisk()).append(File.separator).append(folder);
  1956. String returnName = FileUpload.fileUp(file, sb.toString(), fileId);
  1957. String filePathName = sb.toString() + File.separator + File.separator + returnName;
  1958. log.warn("This file has been uploaded: " + filePathName);
  1959. return filePathName;
  1960. }
  1961. public ResultData rebuildScene(String num) throws Exception {
  1962. if (StringUtils.isEmpty(num)) {
  1963. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  1964. }
  1965. // TODO: 2022/3/16 旧主表逻辑, 待删除 -------------------------------start
  1966. ScenePro scenePro = sceneProService.findBySceneNum(num);
  1967. // SceneProExt sceneProExt = null;
  1968. ScenePO scenePO = null;
  1969. // String path = "";
  1970. // if(scenePro == null){
  1971. // scenePO = sceneService.findBySceneNum(sceneCode);
  1972. // if(scenePO == null){
  1973. // throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1974. // }else {
  1975. // path = ConstantFilePath.BUILD_MODEL_PATH + scenePO.getDataSource().split("/")[scenePO.getDataSource().split("/").length - 2];
  1976. // }
  1977. // }else {
  1978. // sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
  1979. // path = sceneProExt.getDataSource();
  1980. // }
  1981. // Integer sceneSource = sceneProExt.getSceneSource();
  1982. // String dataSource = sceneProExt.getDataSource();
  1983. // Long sceneUserId = scenePro.getUserId();
  1984. // String buildType = scenePro.getBuildType();
  1985. // Integer sceneStatus = scenePro.getSceneStatus();
  1986. // String webSite = scenePro.getWebSite();
  1987. // String thumb = scenePro.getThumb();
  1988. // Integer payStatus = scenePro.getPayStatus();
  1989. // Integer sceneScheme = scenePro.getSceneScheme();
  1990. // Long sceneId = scenePro.getId();
  1991. // String sceneName = scenePro.getSceneName();
  1992. // Date createTime = scenePro.getCreateTime();
  1993. // TODO: 2022/3/16 旧主表逻辑, 待删除 -------------------------------end
  1994. ScenePlusVO scenePlusVO = null;
  1995. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  1996. if(Objects.isNull(scenePlus)){
  1997. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1998. }
  1999. ScenePlusExt scenePlusExt = scenePlusExtService.getSceneProExtByPlusId(scenePlus.getId());
  2000. String path = scenePlusExt.getDataSource();
  2001. Integer sceneSource = scenePlus.getSceneSource();
  2002. String dataSource = scenePlusExt.getDataSource();
  2003. Long sceneUserId = scenePlus.getUserId();
  2004. String buildType = scenePlusExt.getBuildType();
  2005. Integer sceneStatus = scenePlus.getSceneStatus();
  2006. String webSite = scenePlusExt.getWebSite();
  2007. String thumb = scenePlusExt.getThumb();
  2008. Integer payStatus = scenePlus.getPayStatus();
  2009. Integer sceneScheme = scenePlusExt.getSceneScheme();
  2010. Long sceneId = scenePlus.getId();
  2011. String sceneName = scenePlus.getTitle();
  2012. Date createTime = scenePlus.getCreateTime();
  2013. //重新计算时需要删除文件夹,否知使用缓存
  2014. FileUtils.delAllFile(path + File.separator + "results");
  2015. String fileId = path.split("/")[path.split("/").length - 2];
  2016. log.info("fileId:" + fileId);
  2017. //获取解压后的资源的data.fdage中的数据
  2018. File folderPath = new File(path);
  2019. if ("aws".equals(type)) {
  2020. CreateObjUtil.ossUtilCp(ConstantFilePath.OSS_PREFIX + path.replace(ConstantFilePath.BUILD_MODEL_PATH, ""),
  2021. path + "/capture/");
  2022. } else {
  2023. if(sceneSource == 4){
  2024. CreateObjUtil.ossUtilCp(ConstantFilePath.OSS_PREFIX + path.replace(ConstantFilePath.BUILD_MODEL_LASER_PATH, "") + "/data.fdage", path + "/capture/");
  2025. }else{
  2026. CreateObjUtil.ossUtilCp(ConstantFilePath.OSS_PREFIX + path.replace(ConstantFilePath.BUILD_MODEL_PATH, "") + "/data.fdage", path + "/capture/");
  2027. }
  2028. }
  2029. String data = FileUtils.readFile(folderPath.getAbsolutePath() + File.separator + "capture" + File.separator + "data.fdage");
  2030. com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(data);
  2031. if(ObjectUtils.isEmpty(jsonObject)){
  2032. log.error("data.fdage文件不存在");
  2033. return ResultData.error(CameraConstant.FAILURE_6009.code(), CameraConstant.FAILURE_6009.message());
  2034. }
  2035. //有points字段的是八目
  2036. if (!jsonObject.containsKey("points")) {
  2037. String cameraName = jsonObject.getString("camid");
  2038. ResultData<Camera> cameraResult = platformGoodsClient.getCameraByChildName(cameraName);
  2039. Camera camera = cameraResult.getData();
  2040. if (camera == null) {
  2041. log.error("该相机不存在:" + cameraName);
  2042. throw new BusinessException(CameraConstant.FAILURE_6003);
  2043. }
  2044. ResultData<CameraDetail> detailResult = platformGoodsClient.getCameraDetailByCameraId(camera.getId());
  2045. CameraDetail detail = detailResult.getData();
  2046. if (detail == null) {
  2047. log.error("该相机详情不存在:" + cameraName);
  2048. throw new BusinessException(CameraConstant.FAILURE_6003);
  2049. }
  2050. Long userId = null;
  2051. String userName = null;
  2052. if (detail.getUserId() != null) {
  2053. ResultData<SSOUser> ssoUserResult = platformUserClient.getSSOUserByUserId(detail.getUserId());
  2054. SSOUser user = ssoUserResult.getData();
  2055. if (user == null) {
  2056. log.error("用户id不存在:" + detail.getUserId());
  2057. } else {
  2058. userId = user.getId();
  2059. userName = user.getUserName();
  2060. }
  2061. }
  2062. String unicode = jsonObject.getString("creator") + "_" + jsonObject.getString("uuidtime");
  2063. // TODO: 2022/3/16 旧主表逻辑, 待删除 -------------------------------start
  2064. // scenePO = this.createScene(num, camera.getId(),
  2065. // cameraName, jsonObject.getString("creator"),
  2066. // jsonObject.getString("pwd"), unicode, detail.getCameraType(),
  2067. // fileId, "http://creator.4dkankan.com/" + unicode + File.separator, "zip.Zip",
  2068. // jsonObject.getString("scenePic"), "0", userId, userName,
  2069. // jsonObject.getString("location") != null && "1".equals(jsonObject.getString("location")) ? "sfm" : "slam",
  2070. // jsonObject.getJSONArray("imgs").size(), jsonObject.getString("name"), jsonObject.getString("info"),
  2071. // jsonObject.getInteger("scenetype"), jsonObject.getString("gps"),
  2072. // 1, mainUrl + sceneUrl, ecsType);
  2073. // TODO: 2022/3/16 旧主表逻辑, 待删除 -------------------------------end
  2074. scenePlusVO = this.createScenePlus(num, camera.getId(),
  2075. cameraName, jsonObject.getString("creator"),
  2076. jsonObject.getString("pwd"), unicode, detail.getCameraType(),
  2077. fileId, "http://creator.4dkankan.com/" + unicode + File.separator, "zip.Zip",
  2078. jsonObject.getString("scenePic"), "0", userId, userName,
  2079. jsonObject.getString("location") != null && "1".equals(jsonObject.getString("location")) ? "sfm" : "slam",
  2080. jsonObject.getJSONArray("imgs").size(), jsonObject.getString("name"), jsonObject.getString("info"),
  2081. jsonObject.getInteger("scenetype"), jsonObject.getString("gps"),
  2082. 1, mainUrl + sceneUrl, ecsType);
  2083. } else {
  2084. String cameraName = jsonObject.getJSONObject("cam").getString("uuid");
  2085. String userName = null;
  2086. if (!ObjectUtils.isEmpty(sceneUserId)) {
  2087. ResultData<SSOUser> ssoUserResult = platformUserClient.getSSOUserByUserId(sceneUserId);
  2088. SSOUser user = ssoUserResult.getData();
  2089. userName = user.getUserName();
  2090. }
  2091. //重算的场景,先移除该场景对应的容量
  2092. sceneProService.rebuildReduceSpaceBySceneNum(num);
  2093. JSONObject statusJson = new JSONObject();
  2094. //临时将-2改成1,app还没完全更新
  2095. statusJson.put("status", sceneStatus == -2 ? 1 : sceneStatus);
  2096. statusJson.put("webSite", webSite);
  2097. statusJson.put("sceneNum", num);
  2098. statusJson.put("thumb", thumb);
  2099. statusJson.put("payStatus", payStatus);
  2100. FileUtils.writeFile(ConstantFilePath.SCENE_PATH + "data/data" + num + File.separator + "status.json", statusJson.toString());
  2101. uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "data/data" + num + File.separator + "status.json",
  2102. "data/data" + num + File.separator + "status.json");
  2103. String unicode = jsonObject.getString("creator") + "_" + jsonObject.getString("uuidtime");
  2104. Long cameraType = (long)sceneScheme == 3 ? 12 : (long)sceneScheme;
  2105. //判断是否转台相机
  2106. if(sceneSource == 3){
  2107. cameraType = 13L;
  2108. }
  2109. if(sceneSource == 4){
  2110. cameraType = 14L;
  2111. }
  2112. if(sceneSource == 4){
  2113. fdkkLaserService.updateSceneStatus(num,0);
  2114. BuildSceneMqMessage buildSceneMqMessage =this.getBuildSceneMqMessage(
  2115. num, cameraName, unicode, cameraType, fileId,
  2116. dataSource.replace(ConstantFilePath.BUILD_MODEL_PATH, "")
  2117. .replace(ConstantFilePath.BUILD_MODEL_LASER_PATH,"")+ File.separator,
  2118. "zip.Zip", "0",
  2119. userName, jsonObject.getString("location") != null && "1".equals(jsonObject.getString("location")) ? "sfm" : "slam",
  2120. jsonObject.getInteger("resolution"), buildType,
  2121. ConstantFilePath.BUILD_MODEL_LASER_PATH + unicode, sceneId, sceneName,
  2122. webSite, createTime, sceneUserId, dataSource, sceneStatus, payStatus, thumb);
  2123. mqProducer.syncSend(topicModelingAPre, buildSceneMqMessage);
  2124. }else{
  2125. BuildSceneMqMessage buildSceneMqMessage =this.getBuildSceneMqMessage(
  2126. num, cameraName, unicode, cameraType, fileId,
  2127. dataSource.replace(ConstantFilePath.BUILD_MODEL_PATH, "")
  2128. .replace(ConstantFilePath.BUILD_MODEL_LASER_PATH,"")+ File.separator,
  2129. "zip.Zip", "0",
  2130. userName, jsonObject.getString("location") != null && "1".equals(jsonObject.getString("location")) ? "sfm" : "slam",
  2131. jsonObject.getInteger("resolution"), buildType,
  2132. ConstantFilePath.BUILD_MODEL_PATH + unicode, sceneId, sceneName,
  2133. webSite, createTime, sceneUserId, dataSource, sceneStatus, payStatus, thumb);
  2134. mqProducer.syncSend(topicModelingAPre, buildSceneMqMessage);
  2135. }
  2136. sceneProService.updateStatus(num,0);
  2137. scenePlusService.update(new LambdaUpdateWrapper<ScenePlus>()
  2138. .set(ScenePlus::getSceneStatus, SceneStatus.wait.code())
  2139. .eq(ScenePlus::getNum, num));
  2140. // TODO: 2022/3/16 旧主表逻辑, 待删除 -------------------------------start
  2141. // 更新imageVersion
  2142. // sceneProEditService.updateImageVersionByProId(scenePro.getId());
  2143. // TODO: 2022/3/16 旧主表逻辑, 待删除 -------------------------------end
  2144. }
  2145. log.info("生成新的场景重新计算");
  2146. return ResultData.ok();
  2147. }
  2148. public ResultData rebuildVideoScene(RebuildVedioSceneParamVO param) throws Exception {
  2149. if(StringUtils.isEmpty(param.getNum()) || StringUtils.isEmpty(param.getPanoId())){
  2150. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  2151. }
  2152. String num = param.getNum();
  2153. ScenePro scenePro = sceneProService.findBySceneNum(num);
  2154. SceneProExt sceneProExt = null;
  2155. ScenePO scene = null;
  2156. String path = "";
  2157. if(scenePro == null){
  2158. scene = sceneService.findBySceneNum(num);
  2159. if(scene == null){
  2160. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  2161. }else {
  2162. path = ConstantFilePath.BUILD_MODEL_PATH + scene.getDataSource().split("/")[scene.getDataSource().split("/").length - 2];
  2163. }
  2164. }else {
  2165. sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
  2166. path = sceneProExt.getDataSource();
  2167. }
  2168. //先从备份文件下拉取
  2169. CreateObjUtil.ossUtilCp("video/video" +scenePro.getNum() + File.separator + "back" + File.separator,
  2170. sceneProExt.getDataSource() + "_rv" + File.separator + "videoback_temp");
  2171. String backpathtemp = sceneProExt.getDataSource() + "_rv" + File.separator + "videoback_temp";
  2172. File fileback = new File(backpathtemp);
  2173. File[] filebackList = fileback.listFiles();
  2174. if(filebackList.length<=0){
  2175. String backpath = sceneProExt.getDataSource() + "_rv" + File.separator + "videoback";
  2176. log.info("------------------" + backpath);
  2177. File file = new File(backpath);
  2178. //验证video 文件夹下是否有备份
  2179. CreateObjUtil.ossUtilCp("video/video" +scenePro.getNum() + File.separator,
  2180. sceneProExt.getDataSource() + "_rv" + File.separator + "videoback");
  2181. String name = "";
  2182. Map<String,String> map = new HashMap<>();
  2183. file = new File(backpath);
  2184. File[] fileList = file.listFiles();
  2185. if(fileList.length>0){
  2186. for(File f:fileList){
  2187. name = f.getName();
  2188. log.info("file name :" + name);
  2189. map.put(sceneProExt.getDataSource() + "_rv" + File.separator + "videoback" + File.separator + name,
  2190. "video/video" +scenePro.getNum() + File.separator + "back" + File.separator + name);
  2191. }
  2192. }
  2193. //上传
  2194. log.info("上传内容 ===== + " + map);
  2195. uploadToOssUtil.uploadMulFiles(map);
  2196. FileUtils.deleteDirectory(backpathtemp);
  2197. }
  2198. //更新旧记录
  2199. videoSceneProgressService.updateProgressRec(param);
  2200. //往文件中写入值
  2201. JSONObject reObject = new JSONObject();
  2202. JSONObject Object = new JSONObject();
  2203. Object.put("name",param.getPanoId());
  2204. Object.put("x",param.getX());
  2205. Object.put("y",param.getY());
  2206. Object.put("width",param.getW());
  2207. Object.put("height",param.getH());
  2208. JSONArray arrayRe = new JSONArray();
  2209. arrayRe.add(Object);
  2210. reObject.put("required_videos",arrayRe);
  2211. JSONObject hdrObject = new JSONObject();
  2212. if(StringUtils.isNotEmpty(scenePro.getVideos())){
  2213. JSONObject object = JSONObject.parseObject(scenePro.getVideos());
  2214. if(object.containsKey("data")){
  2215. JSONArray array = new JSONArray();
  2216. array = (JSONArray) object.get("data");
  2217. arrayRe = new JSONArray();
  2218. if(array.size()>0){
  2219. for(int i = 0; i < array.size(); i++) {
  2220. JSONObject obj = (JSONObject) array.get(i);
  2221. Object = new JSONObject();
  2222. Object.put("name",(String) obj.get("id"));
  2223. Object.put("value",(String) obj.get("value"));
  2224. Object.put("fov",(String) obj.get("blend_fov"));
  2225. arrayRe.add(Object);
  2226. }
  2227. hdrObject.put("hdr_param",arrayRe);
  2228. }
  2229. }
  2230. }else{
  2231. hdrObject.put("hdr_param","{}");
  2232. }
  2233. //重新计算时需要删除文件夹,否知使用缓存
  2234. log.info("开始清除result");
  2235. FileUtils.delAllFile(path + File.separator + "results");
  2236. log.info("清除result结束");
  2237. String fileId = path.split("/")[path.split("/").length - 2];
  2238. log.info("fileId:" + fileId);
  2239. String parametr = "";
  2240. parametr += scenePro.getNum() + ":;" +
  2241. param.getPanoId();
  2242. long start = System.currentTimeMillis();
  2243. VideoSceneProgress videoSceneProgress= new VideoSceneProgress();
  2244. videoSceneProgress.setNum(scenePro.getNum());
  2245. videoSceneProgress.setVideoName(param.getPanoId());
  2246. videoSceneProgress.setDataSource(sceneProExt.getDataSource());
  2247. videoSceneProgress.setRebuildResult(2);
  2248. videoSceneProgress.setDataSource(sceneProExt.getDataSource());
  2249. videoSceneProgress.setRebuildQueueStartTime(new Date());
  2250. videoSceneProgress.setHdrParam(hdrObject.toJSONString());
  2251. videoSceneProgress.setRebuildParam(reObject.toJSONString());
  2252. videoSceneProgressService.save(videoSceneProgress);
  2253. mqProducer.syncSend(topicVideoA, parametr);
  2254. return ResultData.ok();
  2255. }
  2256. public ResultData rebuildPicScene(@RequestBody RebuildVedioSceneParamVO param) throws Exception {
  2257. if(StringUtils.isEmpty(param.getNum())){
  2258. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  2259. }
  2260. String num = param.getNum();
  2261. ScenePro scenePro = sceneProService.findBySceneNum(num);
  2262. String path = "";
  2263. if(scenePro == null){
  2264. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  2265. }
  2266. SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
  2267. path = sceneProExt.getDataSource();
  2268. PicSceneProgress picSceneProgressFromDb = picSceneProgressService.findrebuildVideoProgressDetail(num,null);
  2269. if(!ObjectUtils.isEmpty(picSceneProgressFromDb) && (picSceneProgressFromDb.getRebuildResult() == 2 || picSceneProgressFromDb.getRebuildResult() == 3)){
  2270. return ResultData.error(ErrorCode.FAILURE_CODE_5035);
  2271. }
  2272. //更新旧记录
  2273. picSceneProgressService.updateProgressRec(param);
  2274. //重新计算时需要删除文件夹,否知使用缓存
  2275. log.info("开始清除result");
  2276. FileUtils.delAllFile(path + File.separator + "results");
  2277. log.info("清除result结束");
  2278. String fileId = path.split("/")[path.split("/").length - 2];
  2279. log.info("fileId:" + fileId);
  2280. PicSceneProgress picSceneProgress = new PicSceneProgress();
  2281. picSceneProgress.setNum(scenePro.getNum());
  2282. picSceneProgress.setVideoName(param.getPanoId());
  2283. picSceneProgress.setDataSource(sceneProExt.getDataSource());
  2284. picSceneProgress.setRebuildResult(2);
  2285. picSceneProgress.setDataSource(sceneProExt.getDataSource());
  2286. picSceneProgress.setRebuildQueueStartTime(new Date());
  2287. picSceneProgress.setRebuildParam(JSONObject.toJSONString(param));
  2288. picSceneProgressService.save(picSceneProgress);
  2289. String parametr = picSceneProgress.getId()+"";
  2290. mqProducer.syncSend(topicPicA, parametr);
  2291. return ResultData.ok();
  2292. }
  2293. public static void main(String[] args) {
  2294. // ScenePro scenePro = new ScenePro();
  2295. // scenePro.setCameraId(1l);
  2296. // SceneProExt sceneProExt = new SceneProExt();
  2297. // sceneProExt.setSceneStatus(2);
  2298. SceneProPO sceneProPO = new SceneProPO();
  2299. // BeanUtil.copyProperties(scenePro, sceneProPO);
  2300. // BeanUtil.copyProperties(sceneProExt, sceneProPO);
  2301. // System.out.println(123);
  2302. // JSONObject jsonObject = new JSONObject();
  2303. // jsonObject.put("test", null);
  2304. }
  2305. }