CaseDownService.java 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. package com.fdkankan.fusion.down;
  2. import cn.hutool.core.io.FileUtil;
  3. import cn.hutool.core.io.IORuntimeException;
  4. import com.alibaba.fastjson.JSON;
  5. import com.alibaba.fastjson.JSONArray;
  6. import com.alibaba.fastjson.JSONObject;
  7. import com.deepoove.poi.XWPFTemplate;
  8. import com.fdkankan.fusion.common.FilePath;
  9. import com.fdkankan.fusion.common.ResultCode;
  10. import com.fdkankan.fusion.common.ResultData;
  11. import com.fdkankan.fusion.common.util.DateUtils;
  12. import com.fdkankan.fusion.common.util.ShellUtil;
  13. import com.fdkankan.fusion.common.util.LocalToOssUtil;
  14. import com.fdkankan.fusion.config.CacheUtil;
  15. import com.fdkankan.fusion.entity.*;
  16. import com.fdkankan.fusion.exception.BusinessException;
  17. import com.fdkankan.fusion.httpClient.LaserService;
  18. import com.fdkankan.fusion.httpClient.response.FdkkResponse;
  19. import com.fdkankan.fusion.request.CaseParam;
  20. import com.fdkankan.fusion.response.DownVo;
  21. import com.fdkankan.fusion.response.DownloadProcessVo;
  22. import com.fdkankan.fusion.response.FusionNumVo;
  23. import com.fdkankan.fusion.response.SceneVo;
  24. import com.fdkankan.fusion.service.*;
  25. import com.fdkankan.fusion.service.impl.DownService;
  26. import com.fdkankan.redis.util.RedisUtil;
  27. import lombok.extern.slf4j.Slf4j;
  28. import org.apache.commons.io.FileUtils;
  29. import org.apache.commons.lang3.StringUtils;
  30. import org.springframework.beans.factory.FactoryBean;
  31. import org.springframework.beans.factory.annotation.Autowired;
  32. import org.springframework.beans.factory.annotation.Value;
  33. import org.springframework.scheduling.annotation.Async;
  34. import org.springframework.stereotype.Service;
  35. import java.io.File;
  36. import java.io.FileOutputStream;
  37. import java.io.IOException;
  38. import java.io.InputStream;
  39. import java.nio.charset.StandardCharsets;
  40. import java.util.Date;
  41. import java.util.HashSet;
  42. import java.util.List;
  43. @Service
  44. @Slf4j
  45. public class CaseDownService {
  46. @Value("${server.servlet.context-path}")
  47. String basePath;
  48. public static String jsonDataName = "data.json";
  49. public static String caseInfo = "/case/getInfo?caseId=";
  50. public static String caseSettingsInfo = "/caseSettings/info?caseId=";
  51. public static String hostIcon = "/edit/hotIcon/list?caseId=";
  52. public static String caseView = "/caseView/allList?caseId=";
  53. public static String caseFiles = "/caseFiles/allList?caseId=";
  54. public static String caseFilesType = "/caseFilesType/allList?caseId=";
  55. public static String caseScene = "/case/sceneList?caseId=";
  56. public static String caseFusion = "/caseFusion/list?caseId=";
  57. public static String caseVideoFolder = "/caseVideoFolder/allList?caseId=";
  58. public static String caseVideo = "/caseVideo/allList?folderId=";
  59. public static String caseTag = "/caseTag/allList?caseId=";
  60. public static String caseTagPoint = "/caseTagPoint/allList?tagId=";
  61. public static String caseInquest = "/caseInquest/info?caseId=";
  62. public static String caseExtractDetail = "/caseExtractDetail/info?caseId=";
  63. public static String fusionGuide = "/fusionGuide/allList?caseId=";
  64. public static String fusionGuidePath = "/fusionGuidePath/allList?guideId=";
  65. public static String fusionMeter = "/fusionMeter/allList?fusionId=";
  66. public static String model = "/model/getInfo?modelId=";
  67. public static String caseImg = "/caseImg/getFfmpegImage?caseId=";
  68. public static String inquestInfoUrl = "/caseInquestInfo/info?caseId=";
  69. public static String casePathInfoUrl = "/casePath/info?caseId=";
  70. public static String laserData = "/laser/dataset/%s/getDataSet";
  71. public static String laserDataSetAndControlPoint = "/laser/4dage/%s/getDataSetAndControlPoint";
  72. public static String laserDataQuery = "/laser/filter/%s/query?datasetId=%s";
  73. @Autowired
  74. ICaseService caseService;
  75. @Autowired
  76. ICaseSettingsService caseSettingsService;
  77. @Autowired
  78. IFusionNumService fusionNumService;
  79. @Autowired
  80. ICaseViewService caseViewService;
  81. @Autowired
  82. ICaseVideoFolderService caseVideoFolderService;
  83. @Autowired
  84. ICaseVideoService caseVideoService;
  85. @Autowired
  86. ICaseFilesService caseFilesService;
  87. @Autowired
  88. ICaseFilesTypeService caseFilesTypeService;
  89. @Autowired
  90. IHotIconService hotIconService;
  91. @Autowired
  92. ICaseTagService caseTagService;
  93. @Autowired
  94. ICaseTagPointService caseTagPointService;
  95. @Autowired
  96. IFusionGuideService fusionGuideService;
  97. @Autowired
  98. IFusionGuidePathService fusionGuidePathService;
  99. @Autowired
  100. ICaseInquestService caseInquestService;
  101. @Autowired
  102. ICaseExtractDetailService caseExtractDetailService;
  103. @Autowired
  104. IFusionMeterService fusionMeterService;
  105. @Autowired
  106. IModelService modelService;
  107. @Autowired
  108. LaserService laserService;
  109. @Autowired
  110. ICaseOfflineService caseOfflineService;
  111. @Autowired
  112. ICaseImgService caseImgService;
  113. @Autowired
  114. ICaseInquestInfoService caseInquestInfoService;
  115. @Autowired
  116. ICasePathService casePathService;
  117. @Autowired
  118. RedisUtil redisUtil;
  119. public static String downProcessKey = "fusion:down:offline:process:caseId:%s";
  120. public static String downProcessKey2 = "fusion:down:process:caseId:%s";
  121. public static String buildSceneKey = "fusion:build:scene:";
  122. public static final String BUILD_SCENE_OFFLINE_CASE = "BUILD:SCENE:OFFLINE:CASE";
  123. public DownVo checkDown(Integer caseId) {
  124. DownVo downVo = new DownVo();
  125. // CaseOffline byCaseId = caseOfflineService.getByCaseId(caseId);
  126. // if(byCaseId != null){
  127. // downVo.setDownloadStatus(3);
  128. // downVo.setDownloadUrl(byCaseId.getOfflineUrl());
  129. // }
  130. return downVo;
  131. }
  132. @Async
  133. public void downOffline(Integer caseId,String zipPath){
  134. String caseOffPath = null;
  135. redisUtil.set(BUILD_SCENE_OFFLINE_CASE,caseId+"",60 * 60 * 24);
  136. try {
  137. String redisKey = String.format(downProcessKey, caseId);
  138. if( redisUtil.hasKey(redisKey)){
  139. String res = redisUtil.get(redisKey);
  140. DownloadProcessVo downloadProcessVo = JSONObject.parseObject(res, DownloadProcessVo.class);
  141. if(downloadProcessVo.getStatus() ==1000 && (downloadProcessVo.getPercent()== null || downloadProcessVo.getPercent() != 100)){
  142. return;
  143. }
  144. }
  145. String timeKey = DateUtils.dateStr();
  146. caseOffPath = zipPath+"offline_"+caseId+"_"+timeKey ;
  147. caseService.updateOfflineStatus(caseId,1,zipPath);
  148. setRedisProcess(caseId,0);
  149. //复制前端资源
  150. cpIndexHtml(caseId,caseOffPath);
  151. setRedisProcess(caseId,10);
  152. //创建data.json并下载资源
  153. createDataJson(caseId,caseOffPath);
  154. //打包zip
  155. //caseOfflineService.saveByCase(caseId,caseOffPath);
  156. setRedisProcess(caseId,100,caseOffPath);
  157. caseService.updateOfflineStatus(caseId,2,caseOffPath);
  158. }catch (IOException e){
  159. log.info("down-offline-IOException:{}",caseId,e);
  160. setRedisProcess(caseId,0,null,1004);
  161. caseService.updateOfflineStatus(caseId,1004,caseOffPath);
  162. }catch (IORuntimeException e){
  163. log.info("down-offline-IORuntimeException:{}",caseId,e);
  164. setRedisProcess(caseId,0,null,1004);
  165. caseService.updateOfflineStatus(caseId,1004,caseOffPath);
  166. }catch (Exception e){
  167. log.info("down-offline-Exception:{}",caseId,e);
  168. setRedisProcess(caseId,0,null,1003);
  169. caseService.updateOfflineStatus(caseId,1003,caseOffPath);
  170. }finally {
  171. redisUtil.del(BUILD_SCENE_OFFLINE_CASE);
  172. }
  173. }
  174. public void setRedisProcess(Integer caseId,Integer num){
  175. setRedisProcess(caseId,num,null,1000);
  176. if(num ==0){
  177. String redisKey2 = String.format(downProcessKey2, caseId);
  178. redisUtil.set(redisKey2,"1",60);
  179. }
  180. }
  181. public void setRedisProcess(Integer caseId,Integer num,String url){
  182. setRedisProcess(caseId,num,url,1000);
  183. }
  184. public void setRedisProcess(Integer caseId,Integer num,String url,Integer status){
  185. String redisKey = String.format(downProcessKey, caseId);
  186. log.info("down-offline-process:{},{},{}",caseId,num,url);
  187. DownloadProcessVo processVo = new DownloadProcessVo();
  188. processVo.setStatus(status);
  189. processVo.setPercent(num);
  190. processVo.setUrl( url);
  191. processVo.setCaseId( caseId);
  192. redisUtil.set(redisKey,JSONObject.toJSONString(processVo),60 * 60 * 24);
  193. }
  194. public DownloadProcessVo process(Integer caseId) {
  195. DownloadProcessVo downVo = new DownloadProcessVo();
  196. String redisKey = String.format(downProcessKey, caseId);
  197. String redisKey2 = String.format(downProcessKey2, caseId);
  198. if(redisUtil.hasKey(redisKey)){
  199. DownloadProcessVo downloadProcessVo = JSONObject.parseObject(redisUtil.get(redisKey), DownloadProcessVo.class);
  200. if(redisUtil.hasKey(redisKey2)){
  201. redisUtil.set(redisKey2,String.valueOf(Integer.parseInt(redisUtil.get(redisKey2)) + 1),60);
  202. }else {
  203. redisUtil.set(redisKey2,"1",60);
  204. }
  205. if(downloadProcessVo.getPercent() == 100){
  206. downloadProcessVo.setPercent(100);
  207. }else{
  208. Integer percent = Integer.parseInt(redisUtil.get(redisKey2)) <100 ? Integer.parseInt(redisUtil.get(redisKey2)) : 99;
  209. downloadProcessVo.setPercent(percent);
  210. }
  211. return downloadProcessVo;
  212. }
  213. return downVo;
  214. }
  215. public void createDataJson(Integer caseId,String caseOffPath){
  216. log.info("down-offline-createDataJson:{}",caseOffPath);
  217. JSONObject jsonObject = new JSONObject();
  218. CaseParam param = new CaseParam();
  219. param.setCaseId(caseId);
  220. //设置案件信息
  221. jsonObject.put(basePath+inquestInfoUrl+caseId, ResultData.ok(caseInquestInfoService.getByCaseId(caseId)));
  222. jsonObject.put(basePath+caseInfo+caseId, ResultData.ok(caseService.getInfo(caseId)));
  223. List<CaseSettings> caseSettings = caseSettingsService.getByFusionId(caseId);
  224. jsonObject.put(basePath+caseSettingsInfo+caseId, ResultData.ok(caseSettings));
  225. for (CaseSettings caseSetting : caseSettings) {
  226. downResource(caseId,caseSetting.getBack(),caseOffPath);
  227. downResource(caseId,caseSetting.getCover(),caseOffPath);
  228. }
  229. List<FusionNumVo> listByCaseId = fusionNumService.getListByCaseId(caseId,null);
  230. jsonObject.put(basePath+caseFusion+caseId, ResultData.ok(listByCaseId));
  231. for (FusionNumVo fusion : listByCaseId) {
  232. jsonObject.put(basePath+fusionMeter+fusion.getFusionId(), ResultData.ok(fusionMeterService.getListByFusionId(fusion.getFusionId(),null)));
  233. }
  234. for (FusionNumVo fusionNumVo : listByCaseId) {
  235. //下载媒体库模型
  236. if(fusionNumVo.getSceneData() != null){
  237. if(fusionNumVo.getSceneData().getType() ==3 && StringUtils.isNotBlank(fusionNumVo.getSceneData().getModelGlbUrl()) ){
  238. downModel(caseId,fusionNumVo.getSceneData().getModelGlbUrl(),caseOffPath);
  239. }
  240. }
  241. }
  242. List<SceneVo> sceneVos = caseService.sceneList(param);
  243. for (SceneVo sceneData : sceneVos) {
  244. //下载模型
  245. if(StringUtils.isNotBlank(sceneData.getModelGlbUrl())){
  246. downModel(caseId,sceneData.getModelGlbUrl(),caseOffPath);
  247. }
  248. if(sceneData.getType() != 3){
  249. //下载场景离线包
  250. downSwkk(caseId,sceneData.getNum(),sceneData.getType(),caseOffPath);
  251. }
  252. if(sceneData.getType() == 2 || sceneData.getType() == 5){
  253. FdkkResponse sceneInfo = laserService.getSceneInfo(sceneData.getNum());
  254. HashSet<String> dataSetIds = new HashSet<>();
  255. if(sceneInfo != null){
  256. JSONArray jsonArray = JSONArray.parseArray(JSONArray.toJSONString(sceneInfo.getData()));
  257. JSONArray newJsonArray = new JSONArray();
  258. for (Object object : jsonArray) {
  259. JSONObject sceneInfoObj = (JSONObject) object;
  260. String newPath = String.format(FilePath.OFFLINE_LASER_OSS_PATH, sceneData.getNum(), sceneData.getNum());
  261. String mapping = sceneInfoObj.getString("mapping");
  262. String oldPath = sceneInfoObj.getString("webBin");
  263. String webBin = null;
  264. if(StringUtils.isNotBlank(mapping)){
  265. webBin =newPath + mapping+ File.separator+ oldPath;
  266. }else {
  267. webBin = newPath+ oldPath;
  268. }
  269. sceneInfoObj.put("oldWebBin",oldPath);
  270. sceneInfoObj.put("webBin",webBin);
  271. newJsonArray.add(sceneInfoObj);
  272. dataSetIds.add( sceneInfoObj.getString("id"));
  273. }
  274. sceneInfo.setData(newJsonArray);
  275. jsonObject.put(String.format(laserData,sceneData.getNum()),sceneInfo);
  276. if(!dataSetIds.isEmpty()){
  277. for (String dataSetId : dataSetIds) {
  278. FdkkResponse sceneInfo2 = laserService.getSceneInfoQuery(sceneData.getNum(),dataSetId);
  279. jsonObject.put(String.format(laserDataQuery,sceneData.getNum(),dataSetId),sceneInfo2);
  280. }
  281. }
  282. }
  283. FdkkResponse dataSetAndControlPoint = laserService.getDataSetAndControlPoint(sceneData.getNum());
  284. if(dataSetAndControlPoint !=null){
  285. jsonObject.put(String.format(laserDataSetAndControlPoint,sceneData.getNum()),dataSetAndControlPoint);
  286. }
  287. }
  288. if(sceneData.getModelId() != null){
  289. jsonObject.put(basePath+model+sceneData.getModelId(), ResultData.ok(modelService.getInfo(sceneData.getModelId())));
  290. }
  291. }
  292. jsonObject.put(basePath+caseScene+caseId, ResultData.ok(sceneVos));
  293. List<CaseView> caseViews = caseViewService.allList(caseId, null, null, null, null);
  294. jsonObject.put(basePath+caseView+caseId, ResultData.ok(caseViews));
  295. for (CaseView view : caseViews) {
  296. downResource(caseId,view.getViewImg(),caseOffPath);
  297. downResource(caseId,view.getViewImgSmall(),caseOffPath);
  298. }
  299. List<CaseVideoFolder> videoFolders = caseVideoFolderService.getAllList(caseId);
  300. jsonObject.put(basePath+caseVideoFolder+caseId, ResultData.ok(videoFolders));
  301. for (CaseVideoFolder videoFolder : videoFolders) {
  302. downResource(caseId,videoFolder.getVideoFolderCover(),caseOffPath);
  303. downResource(caseId,videoFolder.getVideoMergeUrl(),caseOffPath);
  304. List<CaseVideo> allList = caseVideoService.getAllList(videoFolder.getVideoFolderId());
  305. for (CaseVideo video : allList) {
  306. downResource(caseId,video.getVideoCover(),caseOffPath);
  307. downResource(caseId,video.getVideoPath(),caseOffPath);
  308. }
  309. jsonObject.put(basePath+caseVideo+videoFolder.getVideoFolderId(), ResultData.ok(allList));
  310. }
  311. List<CaseFiles> caseFilesList = caseFilesService.allList(caseId, null);
  312. for (CaseFiles files : caseFilesList) {
  313. downResource(caseId,files.getFilesUrl(),caseOffPath);
  314. }
  315. jsonObject.put(basePath+caseFiles+caseId, ResultData.ok(caseFilesList));
  316. jsonObject.put(basePath+caseFilesType+caseId, ResultData.ok(caseFilesTypeService.list()));
  317. List<HotIcon> hotIconList = hotIconService.getListByFusionId(caseId);
  318. for (HotIcon hotIcon : hotIconList) {
  319. downResource(caseId,hotIcon.getIconUrl(),caseOffPath);
  320. }
  321. jsonObject.put(basePath+hostIcon+caseId, ResultData.ok(hotIconList));
  322. List<CaseTag> caseTagList = caseTagService.getListByFusionId(caseId);
  323. jsonObject.put(basePath+caseTag+caseId, ResultData.ok(caseTagList));
  324. for (CaseTag tag : caseTagList) {
  325. jsonObject.put(basePath+caseTagPoint+tag.getTagId(), ResultData.ok(caseTagPointService.allList(tag.getTagId())));
  326. downResources(caseId,tag.getTagImgUrl(),caseOffPath);
  327. downResource(caseId,tag.getHotIconUrl(),caseOffPath);
  328. downResource(caseId,tag.getAudio(),caseOffPath);
  329. }
  330. jsonObject.put(basePath+casePathInfoUrl+caseId, ResultData.ok(casePathService.getByFusionId(caseId)));
  331. List<FusionGuide> fusionGuides = fusionGuideService.getByFusionId(caseId);
  332. jsonObject.put(basePath+fusionGuide+caseId, ResultData.ok(fusionGuides));
  333. for (FusionGuide guide : fusionGuides) {
  334. downResource(caseId,guide.getCover(),caseOffPath);
  335. List<FusionGuidePath> listByGuideId = fusionGuidePathService.getListByGuideId(guide.getFusionGuideId());
  336. for (FusionGuidePath guidePath : listByGuideId) {
  337. downResource(caseId,guidePath.getCover(),caseOffPath);
  338. }
  339. jsonObject.put(basePath+fusionGuidePath+guide.getFusionGuideId(), ResultData.ok(listByGuideId));
  340. }
  341. CaseInquest caseInquest1 = caseInquestService.getByCaseId(caseId);
  342. if(caseInquest1 != null){
  343. XWPFTemplate inquestTemp = caseInquestService.getWordByTemplate(caseInquest1);
  344. downWordByTemplate(caseId,inquestTemp,"caseInquest.doc",caseOffPath);
  345. }
  346. jsonObject.put(basePath+caseInquest+caseId, ResultData.ok(caseInquest1));
  347. CaseExtractDetail caseExtractDetail1 = caseExtractDetailService.getByCaseId(caseId);
  348. if(caseExtractDetail1 != null){
  349. XWPFTemplate detailTemp = caseExtractDetailService.getWordByTemplate(caseExtractDetail1);
  350. downWordByTemplate(caseId,detailTemp,"caseExtractDetail.doc",caseOffPath);
  351. }
  352. jsonObject.put(basePath+caseExtractDetail+caseId, ResultData.ok(caseExtractDetail1));
  353. List<CaseImg> caseImgList = caseImgService.getByCaseId(caseId, 1);
  354. for (CaseImg img : caseImgList) {
  355. downResource(img.getCaseId(),img.getImgUrl(),caseOffPath);
  356. }
  357. jsonObject.put(basePath+caseImg+caseId, ResultData.ok(caseImgList));
  358. FileUtil.writeString(JSON.toJSONString(jsonObject), caseOffPath+"/www/package/"+jsonDataName,"UTF-8");
  359. }
  360. //http://127.0.0.1:8080/offline.html?caseId=362&app=1&share=1#/show/summary
  361. static String batName = "start-browser.bat";
  362. public void cpIndexHtml(Integer caseId,String caseOffPath) throws IOException {
  363. log.info("down-offline-cpIndexHtml:{}",caseOffPath);
  364. FileUtil.copyContent(new File(FilePath.OFFLINE_TEMPLATE_PATH),new File(caseOffPath),true);
  365. String s = FileUtil.readString(caseOffPath + File.separator + batName, StandardCharsets.UTF_8);
  366. String s1 = s.replaceAll("@caseId", String.valueOf(caseId));
  367. if(CacheUtil.settingEntity.getGa()){
  368. s1 = s.replaceAll("@caseId", String.valueOf(caseId)+"^&ga=true");
  369. }
  370. FileUtil.writeString(s1, caseOffPath + File.separator + batName,"UTF-8");
  371. }
  372. @Autowired
  373. DownService downService;
  374. @Autowired
  375. LocalToOssUtil localToOssUtil;
  376. public void downSwkk(Integer caseId,String num,Integer type,String offPath){
  377. String swkkPath = offPath+ "/www/swkk";
  378. String swssPath = offPath + "/www/swss";
  379. String numPath = swkkPath;
  380. Boolean isLaser = false;
  381. if(type == 2 || type == 5){
  382. isLaser = true;
  383. numPath = swssPath;
  384. }
  385. Boolean wita = true;
  386. Long startTime = new Date().getTime();
  387. Long outTime = new Date().getTime();
  388. Long wiatTime = 10000L;
  389. JSONObject jsonObject = getSceneInfo(num);
  390. Integer sceneId = jsonObject.getInteger("id");
  391. laserService.rebuildOffline( isLaser ? swssPath : swkkPath,isLaser,sceneId);
  392. while (wita){
  393. Long nowTime = new Date().getTime();
  394. if(nowTime - startTime < wiatTime){
  395. continue;
  396. }
  397. if(nowTime - outTime > 1000 * 60 * 60 * 2){ //下载单个场景超时时间
  398. throw new BusinessException(ResultCode.SYSTEM_ERROR);
  399. }
  400. startTime = nowTime;
  401. jsonObject = getSceneInfo(num);
  402. sceneId = jsonObject.getInteger("id");
  403. Boolean meshStatus = jsonObject.getBoolean("meshRebuildOffline");
  404. Boolean laserStatus = jsonObject.getBoolean("rebuildOffline");
  405. String meshOfflineFolder = jsonObject.getString("meshOfflineFolder");
  406. String laserOfflineFolder = jsonObject.getString("offlineFolder");
  407. //1 生成成功 ,0:正在生成 1,初次生成 2,下载失败
  408. Integer laserOffStatus = jsonObject.getInteger("buildOfflineStatus");
  409. //1 生成成功,0:正在生成 1,初次生成 2,下载失败
  410. Integer meshBuildOfflineStatus = jsonObject.getInteger("meshBuildOfflineStatus");
  411. wita = downSceneOffline(num,sceneId, isLaser,
  412. isLaser ? swssPath : swkkPath,
  413. isLaser ? laserStatus : meshStatus,
  414. isLaser ? laserOfflineFolder : meshOfflineFolder,
  415. isLaser ? laserOffStatus : meshBuildOfflineStatus
  416. );
  417. }
  418. File file = new File(numPath + File.separator + num);
  419. if(!file.exists()){
  420. log.info("场景下载失败-num:{}",num);
  421. throw new BusinessException(ResultCode.SCENE_DOWN_ERROR);
  422. }
  423. }
  424. private JSONObject getSceneInfo(String num){
  425. FdkkResponse fdkkResponse = laserService.sceneLocInfo(num);
  426. if(fdkkResponse.getCode() != 200){
  427. throw new BusinessException(ResultCode.SYSTEM_ERROR);
  428. }
  429. return (JSONObject) fdkkResponse.getData();
  430. }
  431. /**
  432. * @param buildOfflineStatus //1 生成成功,0:正在生成 1,初次生成 2,下载失败
  433. */
  434. private Boolean downSceneOffline(String num,Integer sceneId, Boolean isLaser, String offPath, Boolean rebuildOffline, String offlineFolder, Integer buildOfflineStatus) {
  435. if(buildOfflineStatus == null|| buildOfflineStatus == 1 || buildOfflineStatus == -1 || buildOfflineStatus ==2){
  436. return false;
  437. }
  438. return true;
  439. }
  440. @Value("${upload.query-path}")
  441. private String queryPath;
  442. public void downZip(Integer type ,String uri,String kkzipPath,String kknumPath,String sszipPath,String ssNumPath){
  443. try {
  444. if(type != 2 && type != 5){ //深时点云
  445. if(uri.contains("?")){
  446. uri = uri.split("[?]")[0];
  447. }
  448. ShellUtil.yunDownload(uri.replace(queryPath, ""), kkzipPath);
  449. ShellUtil.unZip(kkzipPath,kknumPath);
  450. FileUtil.del(kkzipPath);
  451. }else {
  452. ShellUtil.yunDownloadSs(uri.replace(queryPath, ""), sszipPath);
  453. ShellUtil.unZip(sszipPath,ssNumPath);
  454. FileUtil.del(sszipPath);
  455. }
  456. }catch (Exception e){
  457. log.info("下载场景离线包失败:{}",uri,e);
  458. }
  459. }
  460. public void downModel(Integer caseId, String modelGlbUrl,String offPath) {
  461. String path = offPath +FilePath.OFFLINE_OSS_PATH;
  462. JSONArray jsonArray = JSONArray.parseArray(modelGlbUrl);
  463. for (Object object : jsonArray) {
  464. String res = (String) object;
  465. log.info("下载模型:{}",res);
  466. if(res.contains(".json") || res.contains(".obj")){
  467. res = new File(res).getParentFile().getPath();
  468. }
  469. localToOssUtil.downForm(res,path+queryPath+res);
  470. }
  471. }
  472. public void downResources(Integer caseId,String urls,String offPath) {
  473. JSONArray jsonArray = JSONArray.parseArray(urls);
  474. for (Object object : jsonArray) {
  475. String res = (String) object;
  476. downResource(caseId,res,offPath);
  477. }
  478. }
  479. public void downResource(Integer caseId,String url,String offPath) {
  480. if(StringUtils.isBlank(url) ){
  481. return;
  482. }
  483. if("none".equals(url)){
  484. return;
  485. }
  486. if("map".equals(url)){
  487. return;
  488. }
  489. String path = offPath + FilePath.OFFLINE_OSS_PATH;
  490. localToOssUtil.downForm(url,path+queryPath+url);
  491. }
  492. public void downWordByTemplate(Integer caseId,XWPFTemplate template,String name,String offPath){
  493. // 指定输出文件的路径
  494. String outputPath = offPath +FilePath.OFFLINE_RESOURCE_PACKAGE_PATH + name;
  495. try {
  496. FileOutputStream out = new FileOutputStream(outputPath);
  497. template.write(out);
  498. out.close();
  499. log.info("文档已成功写入到: " + outputPath);
  500. } catch (Exception e) {
  501. log.info("写出文档失败:{},{}",caseId,name,e);
  502. throw new BusinessException(ResultCode.SYSTEM_ERROR);
  503. }
  504. }
  505. }