| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415 |
- package com.fdkankan.fusion.down;
- import cn.hutool.core.io.FileUtil;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.deepoove.poi.XWPFTemplate;
- import com.fdkankan.fusion.common.FilePath;
- import com.fdkankan.fusion.common.ResultData;
- import com.fdkankan.fusion.common.util.*;
- import com.fdkankan.fusion.config.CacheUtil;
- import com.fdkankan.fusion.entity.*;
- import com.fdkankan.fusion.httpClient.LaserService;
- import com.fdkankan.fusion.httpClient.response.FdkkResponse;
- import com.fdkankan.fusion.request.CaseParam;
- import com.fdkankan.fusion.response.DownVo;
- import com.fdkankan.fusion.response.DownloadProcessVo;
- import com.fdkankan.fusion.response.FusionNumVo;
- import com.fdkankan.fusion.response.SceneVo;
- import com.fdkankan.fusion.service.*;
- import com.fdkankan.fusion.service.impl.DownService;
- import com.fdkankan.redis.util.RedisUtil;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.scheduling.annotation.Async;
- import org.springframework.stereotype.Service;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.nio.charset.StandardCharsets;
- import java.util.HashMap;
- import java.util.HashSet;
- import java.util.List;
- @Service
- @Slf4j
- public class FusionDownService {
- @Value("${server.servlet.context-path}")
- String basePath;
- public static String jsonDataName = "data.json";
- public static String caseFusionInfo = "/caseFusion/info?fusionId=";
- public static String caseFusionList= "/caseFusion/list?fusionId=";
- public static String mapConfig = "/notAuth/getMapConfig";
- public static String caseSettingsInfo = "/caseSettings/info?fusionId=";
- public static String hostIconTreeList = "/edit/hotIcon/treeList?fusionId=";
- public static String caseTag = "/caseTag/allList?fusionId=";
- public static String caseTagPoint = "/caseTagPoint/allList?tagId=";
- public static String fusionGuide = "/fusionGuide/allList?fusionId=";
- public static String fusionGuidePath = "/fusionGuidePath/allList?guideId=";
- public static String fusionMeter = "/fusionMeter/allList?fusionId=";
- public static String casePathInfoUrl = "/casePath/info?fusionId=";
- public static String caseAnimationUrl = "/caseAnimation/list?fusionId=";
- public static String laserData = "/laser/dataset/%s/getDataSet";
- public static String laserDataSetAndControlPoint = "/laser/4dage/%s/getDataSetAndControlPoint";
- public static String laserDataQuery = "/laser/filter/%s/query?datasetId=%s";
- @Autowired
- ICaseSettingsService caseSettingsService;
- @Autowired
- IFusionNumService fusionNumService;
- @Autowired
- ICaseViewService caseViewService;
- @Autowired
- ICaseVideoFolderService caseVideoFolderService;
- @Autowired
- ICaseVideoService caseVideoService;
- @Autowired
- ICaseFilesService caseFilesService;
- @Autowired
- ICaseFilesTypeService caseFilesTypeService;
- @Autowired
- IHotIconService hotIconService;
- @Autowired
- ICaseTagService caseTagService;
- @Autowired
- ICaseTagPointService caseTagPointService;
- @Autowired
- IFusionGuideService fusionGuideService;
- @Autowired
- IFusionGuidePathService fusionGuidePathService;
- @Autowired
- ICaseInquestService caseInquestService;
- @Autowired
- ICaseExtractDetailService caseExtractDetailService;
- @Autowired
- IFusionMeterService fusionMeterService;
- @Autowired
- IModelService modelService;
- @Autowired
- LaserService laserService;
- @Autowired
- ICaseOfflineService caseOfflineService;
- @Autowired
- ICaseImgService caseImgService;
- @Autowired
- ICasePathService casePathService;
- @Autowired
- ICaseFusionService caseFusionService;
- @Autowired
- ICaseAnimationService caseAnimationService;
- @Autowired
- IMapConfigService mapConfigService;
- @Autowired
- RedisUtil redisUtil;
- public static String downProcessKey = "fusion:down:offline:process:fusionId:%s";
- @Async
- public void downOffline(Integer fusionId){
- String caseOffPath = null;
- String zipName = null;
- try {
- String redisKey = String.format(downProcessKey, fusionId);
- if(redisUtil.hasKey(redisKey)){
- String res = redisUtil.get(redisKey);
- DownloadProcessVo downloadProcessVo = JSONObject.parseObject(res, DownloadProcessVo.class);
- if(downloadProcessVo.getStatus() != 1003 && (downloadProcessVo.getPercent()== null || downloadProcessVo.getPercent() != 100)){
- return;
- }
- }
- String timeKey = DateUtils.dateStr();
- caseOffPath =FilePath.OFFLINE_PACKAGE_PATH+timeKey+fusionId ;
- setRedisProcess(fusionId,0);
- //复制前端资源
- cpIndexHtml(fusionId,caseOffPath);
- setRedisProcess(fusionId,10);
- //创建data.json并下载资源
- createDataJson(fusionId,caseOffPath+"/www");
- //打包zip
- zipName = caseOffPath+".zip";
- ShellUtil.zip(zipName,caseOffPath);
- setRedisProcess(fusionId,70);
- //上传oss
- String ossUrl = zipName.replace("/mnt/", "");
- ShellUtil.yunUpload(zipName,ossUrl);
- ossUrl = queryPath + ossUrl;
- setRedisProcess(fusionId,100,ossUrl);
- }catch (Exception e){
- log.info("down-offline-error:{}",fusionId,e);
- setRedisProcess(fusionId,0,null,1003);
- }finally {
- delFile(caseOffPath);
- delFile(zipName);
- }
- }
- private void delFile(String path){
- if(StringUtils.isNotBlank(path)){
- try {
- FileUtil.del(path);
- }catch (Exception e){
- log.info("删除文件失败:{}",path);
- }
- }
- }
- public void setRedisProcess(Integer caseId,Integer num){
- setRedisProcess(caseId,num,null,1000);
- }
- public void setRedisProcess(Integer caseId,Integer num,String url){
- setRedisProcess(caseId,num,url,1000);
- }
- public void setRedisProcess(Integer caseId,Integer num,String url,Integer status){
- String redisKey = String.format(downProcessKey, caseId);
- log.info("down-offline-process:{},{},{}",caseId,num,url);
- DownloadProcessVo processVo = new DownloadProcessVo();
- processVo.setStatus(status);
- processVo.setPercent(num);
- processVo.setUrl( url);
- redisUtil.set(redisKey,JSONObject.toJSONString(processVo));
- }
- public DownloadProcessVo process(Integer caseId) {
- DownloadProcessVo downVo = new DownloadProcessVo();
- String redisKey = String.format(downProcessKey, caseId);
- if(redisUtil.hasKey(redisKey)){
- return JSONObject.parseObject(redisUtil.get(redisKey),DownloadProcessVo.class);
- }
- return downVo;
- }
- public void createDataJson(Integer fusionId,String caseOffPath){
- log.info("down-offline-createDataJson:{}",fusionId);
- JSONObject jsonObject = new JSONObject();
- CaseFusion caseFusion = caseFusionService.getById(fusionId);
- jsonObject.put(basePath+caseFusionInfo+fusionId, ResultData.ok(caseFusion));
- List<FusionNumVo> sceneListVo = caseFusionService.getSceneListVo(fusionId);
- List<MapConfig> list = mapConfigService.list();
- jsonObject.put(basePath+mapConfig, ResultData.ok(list));
- List<CaseSettings> caseSettings = caseSettingsService.getByFusionId(fusionId);
- jsonObject.put(basePath+caseSettingsInfo+fusionId, ResultData.ok(caseSettings));
- for (CaseSettings caseSetting : caseSettings) {
- downResource(caseSetting.getBack(),caseOffPath);
- downResource(caseSetting.getCover(),caseOffPath);
- }
- HashMap<String,String> repMap = new HashMap<>();
- jsonObject.put(basePath+fusionMeter+fusionId, ResultData.ok(fusionMeterService.getListByFusionId(fusionId,null)));
- List<FusionNumVo> fusionNumVos = caseFusionService.getSceneListVo(fusionId);
- for (FusionNumVo fusionNumVo : fusionNumVos) {
- SceneVo sceneData = fusionNumVo.getSceneData();
- //下载模型
- if(StringUtils.isNotBlank(sceneData.getModelGlbUrl())){
- downModel(sceneData.getModelGlbUrl(),caseOffPath);
- }
- if(sceneData.getType() != 3){
- //下载场景离线包
- repMap.put(sceneData.getCutModelPath(),sceneData.getCutModelPath().replace("/"+ CacheUtil.queryPath+"/","/swkk/"+sceneData.getNum() +"/wwwroot/"));
- repMap.put(sceneData.getSceneJsonPath(),sceneData.getSceneJsonPath().replace("/"+CacheUtil.queryPath+"/","/swkk/"+sceneData.getNum() +"/wwwroot/"));
- repMap.put(sceneData.getSurveillancePath(),sceneData.getSurveillancePath().replace("/"+CacheUtil.queryPath+"/","/swkk/"+sceneData.getNum() +"/wwwroot/"));
- downSwkk(caseOffPath,sceneData.getNum(),sceneData.getType());
- }
- if(NumTypeUtils.isLaser(sceneData.getType())){
- FdkkResponse sceneInfo = laserService.getSceneInfo(sceneData.getNum());
- HashSet<String> dataSetIds = new HashSet<>();
- if(sceneInfo != null){
- JSONArray jsonArray = JSONArray.parseArray(JSONArray.toJSONString(sceneInfo.getData()));
- JSONArray newJsonArray = new JSONArray();
- for (Object object : jsonArray) {
- JSONObject sceneInfoObj = (JSONObject) object;
- String newPath = String.format(FilePath.OFFLINE_LASER_OSS_PATH, sceneData.getNum(), sceneData.getNum());
- String oldPath = sceneInfoObj.getString("webBin");
- sceneInfoObj.put("oldWebBin",oldPath);
- sceneInfoObj.put("webBin",newPath + oldPath);
- newJsonArray.add(sceneInfoObj);
- dataSetIds.add( sceneInfoObj.getString("id"));
- }
- sceneInfo.setData(newJsonArray);
- jsonObject.put(String.format(laserData,sceneData.getNum()),sceneInfo);
- if(!dataSetIds.isEmpty()){
- for (String dataSetId : dataSetIds) {
- FdkkResponse sceneInfo2 = laserService.getSceneInfoQuery(sceneData.getNum(),dataSetId);
- jsonObject.put(String.format(laserDataQuery,sceneData.getNum(),dataSetId),sceneInfo2);
- }
- }
- }
- FdkkResponse dataSetAndControlPoint = laserService.getDataSetAndControlPoint(sceneData.getNum());
- if(dataSetAndControlPoint !=null){
- jsonObject.put(String.format(laserDataSetAndControlPoint,sceneData.getNum()),dataSetAndControlPoint);
- }
- }
- }
- jsonObject.put(basePath+caseFusionList+fusionId, ResultData.ok(sceneListVo));
- List<HotIcon> hotIconList = hotIconService.getListByFusionId(fusionId);
- for (HotIcon hotIcon : hotIconList) {
- downResource(hotIcon.getIconUrl(),caseOffPath);
- }
- // jsonObject.put(basePath+hostIcon+fusionId, ResultData.ok(hotIconList));
- List<HotIcon> treeList = hotIconService.treeList(hotIconList);
- jsonObject.put(basePath+hostIconTreeList+fusionId, ResultData.ok(treeList));
- List<CaseTag> caseTagList = caseTagService.getListByFusionId(fusionId);
- jsonObject.put(basePath+caseTag+fusionId, ResultData.ok(caseTagList));
- for (CaseTag tag : caseTagList) {
- jsonObject.put(basePath+caseTagPoint+tag.getTagId(), ResultData.ok(caseTagPointService.allList(tag.getTagId())));
- downResources(tag.getTagImgUrl(),caseOffPath);
- downResource(tag.getHotIconUrl(),caseOffPath);
- downResource(tag.getAudio(),caseOffPath);
- }
- jsonObject.put(basePath+casePathInfoUrl+fusionId, ResultData.ok(casePathService.getByFusionId(fusionId)));
- List<FusionGuide> fusionGuides = fusionGuideService.getByFusionId(fusionId);
- jsonObject.put(basePath+fusionGuide+fusionId, ResultData.ok(fusionGuides));
- for (FusionGuide guide : fusionGuides) {
- downResource(guide.getCover(),caseOffPath);
- List<FusionGuidePath> listByGuideId = fusionGuidePathService.getListByGuideId(guide.getFusionGuideId());
- for (FusionGuidePath guidePath : listByGuideId) {
- downResource(guidePath.getCover(),caseOffPath);
- }
- jsonObject.put(basePath+fusionGuidePath+guide.getFusionGuideId(), ResultData.ok(listByGuideId));
- }
- List<CaseAnimation> listByFusionId = caseAnimationService.getListByFusionId(fusionId);
- for (CaseAnimation caseAnimation : listByFusionId) {
- downModel(caseAnimation.getUrl(),caseOffPath);
- }
- jsonObject.put(basePath+caseAnimationUrl+fusionId, ResultData.ok(listByFusionId));
- String jsonString = jsonObject.toJSONString();
- if(!repMap.isEmpty()){
- for (String key : repMap.keySet()) {
- jsonString = jsonString.replace(key,repMap.get(key));
- }
- }
- FileUtil.writeString(jsonString, caseOffPath+"/www/package/"+jsonDataName,"UTF-8");
- }
- //http://127.0.0.1:8080/offline.html?caseId=362&app=1&share=1#/show/summary
- static String batName = "start-browser.bat";
- public void cpIndexHtml(Integer caseId,String caseOfflinePath){
- log.info("down-offline-cpIndexHtml:{}",caseId);
- FileUtil.copyContent(new File(FilePath.OFFLINE_TEMPLATE_PATH_Fusion),new File(caseOfflinePath),true);
- String s = FileUtil.readString(caseOfflinePath + File.separator + batName, StandardCharsets.UTF_8);
- s = s.replaceAll("@caseId", String.valueOf(caseId));
- FileUtil.writeString(s, caseOfflinePath + File.separator + batName,"UTF-8");
- }
- @Autowired
- DownService downService;
- @Autowired
- UploadToOssUtil uploadToOssUtil;
- public void downSwkk(String path,String num,Integer type){
- String swkkPath = path + "/swkk/"+num;
- String swkkZipPath = swkkPath +".zip";
- String swssPath = path + "/swss/"+num;
- String swssZipPath = swssPath +".zip";
- Integer isObj = 0;
- if(type == 4 || type == 6){
- isObj =1;
- }
- try {
- DownVo downVo = downService.checkDownLoad(num, isObj,"offline");
- log.info("down:{}",downVo);
- if(downVo.getDownloadStatus() == 3 && StringUtils.isNotBlank(downVo.getDownloadUrl())){
- downZip(type,downVo.getDownloadUrl(),swkkZipPath,swkkPath,swssZipPath,swssPath);
- }else {
- DownVo down = downService.down(num, isObj,"offline");
- if(down.getDownloadStatus() == 1){
- DownloadProcessVo downloadProcessVo = downService.downloadProcess(num, isObj);
- while (downloadProcessVo.getStatus() != 1002 ){
- downloadProcessVo = downService.downloadProcess(num, isObj);
- Thread.sleep(2000L);
- }
- downZip(type,downloadProcessVo.getUrl(),swkkZipPath,swkkPath,swssZipPath,swssPath);
- }
- }
- }catch (Exception e){
- log.info("下载场景离线包失败:{}",num,e);
- }
- }
- @Value("${upload.query-path}")
- private String queryPath;
- public void downZip(Integer type ,String uri,String kkzipPath,String kknumPath,String sszipPath,String ssNumPath){
- try {
- if(type != 2 && type != 5){ //深时点云
- if(uri.contains("?")){
- uri = uri.split("[?]")[0];
- }
- ShellUtil.yunDownload(uri.replace(queryPath, ""), kkzipPath);
- ShellUtil.unZip(kkzipPath,kknumPath);
- FileUtil.del(kkzipPath);
- }else {
- ShellUtil.yunDownloadSs(uri.replace(queryPath, ""), sszipPath);
- ShellUtil.unZip(sszipPath,ssNumPath);
- FileUtil.del(sszipPath);
- }
- }catch (Exception e){
- log.info("下载场景离线包失败:{}",uri,e);
- }
- }
- public void downModel( String modelGlbUrl,String path) {
- JSONArray jsonArray = JSONArray.parseArray(modelGlbUrl);
- for (Object object : jsonArray) {
- String res = (String) object;
- log.info("下载模型:{}",res);
- res = res.replace(queryPath, "");
- if(res.contains(".json") ){
- res = new File(res).getParentFile().getPath();
- }
- ShellUtil.yunDownload(res, path +"/"+ res);
- }
- }
- public void downResources(String urls,String offPath) {
- JSONArray jsonArray = JSONArray.parseArray(urls);
- for (Object object : jsonArray) {
- String res = (String) object;
- downResource(res,offPath);
- }
- }
- public void downResource(String url,String path) {
- if(StringUtils.isBlank(url) ){
- return;
- }
- url = url.replace(queryPath, "");
- if( !uploadToOssUtil.existKey(url)){
- log.info("downResource文件不存在:{},{}",url,path);
- return;
- }
- ShellUtil.yunDownload(url,path+"/"+url);
- }
- }
|