|
@@ -0,0 +1,214 @@
|
|
|
|
+package com.fdkankan.download.service.impl;
|
|
|
|
+
|
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
|
+import cn.hutool.core.io.file.FileReader;
|
|
|
|
+import cn.hutool.core.io.file.FileWriter;
|
|
|
|
+import cn.hutool.core.thread.ThreadUtil;
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
|
+import cn.hutool.system.oshi.OshiUtil;
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.fdkankan.common.util.CmdUtils;
|
|
|
|
+import com.fdkankan.download.bean.LaserResultData;
|
|
|
|
+import com.fdkankan.download.bean.ResultData;
|
|
|
|
+import com.fdkankan.download.callback.ErrorCallback;
|
|
|
|
+import com.fdkankan.download.callback.SuccessCallback;
|
|
|
|
+import com.fdkankan.download.callback.SuccessLaserCallback;
|
|
|
|
+import com.fdkankan.download.entity.DTO.OfflineDTO;
|
|
|
|
+import com.fdkankan.download.httpclient.HttpClient;
|
|
|
|
+import com.fdkankan.download.service.IDownloadService;
|
|
|
|
+import com.fdkankan.download.service.ILaserService;
|
|
|
|
+import com.fdkankan.download.service.IScenePlusService;
|
|
|
|
+import com.fdkankan.download.util.ImgUtil;
|
|
|
|
+import com.fdkankan.fyun.face.FYunFileServiceInterface;
|
|
|
|
+import jodd.util.SystemUtil;
|
|
|
|
+import lombok.SneakyThrows;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import net.lingala.zip4j.ZipFile;
|
|
|
|
+import net.lingala.zip4j.model.ZipParameters;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+import oshi.software.os.OperatingSystem;
|
|
|
|
+import oshi.software.os.windows.WindowsOperatingSystem;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.nio.charset.Charset;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @author Xiewj
|
|
|
|
+ * @date 2024/1/4
|
|
|
|
+ */
|
|
|
|
+@Service
|
|
|
|
+@Slf4j
|
|
|
|
+public class LaserService implements ILaserService {
|
|
|
|
+
|
|
|
|
+ @Value("${laserhost}")
|
|
|
|
+ private String host;
|
|
|
|
+ @Resource
|
|
|
|
+ private HttpClient httpClient;
|
|
|
|
+ @Value("${api.offlineData}")
|
|
|
|
+ private String offlineData;
|
|
|
|
+ @Resource
|
|
|
|
+ private FYunFileServiceInterface fYunFileService;
|
|
|
|
+ @Value("${laser.bucket}")
|
|
|
|
+ private String bucket;
|
|
|
|
+ @Value("${path.source-local-laser}")
|
|
|
|
+ private String sourceLocal;
|
|
|
|
+ @Value("${path.laserschool}")
|
|
|
|
+ private String laserschool;
|
|
|
|
+ @Autowired
|
|
|
|
+ IDownloadService downloadService;
|
|
|
|
+ @Value("${download.config.resource-url}")
|
|
|
|
+ private String resourceUrl;
|
|
|
|
+ @Value("${download.config.laser-resource-url}")
|
|
|
|
+ private String laserResourceUrl;
|
|
|
|
+ @Value("${path.zip-local}")
|
|
|
|
+ private String zipLocalFormat;
|
|
|
|
+ @Override
|
|
|
|
+ public void downloadHandler(String num) throws Exception {
|
|
|
|
+ String url = host.concat(String.format(offlineData, num));
|
|
|
|
+ try {
|
|
|
|
+ LaserResultData<List<OfflineDTO> > resultData = httpClient.get(url, new SuccessLaserCallback(), new ErrorCallback());
|
|
|
|
+ if (resultData.getCode()==200){
|
|
|
|
+ OperatingSystem os = OshiUtil.getOs();
|
|
|
|
+
|
|
|
|
+ List<OfflineDTO> data = resultData.getData();
|
|
|
|
+ for (OfflineDTO datum : data) {
|
|
|
|
+ //1 json ,2下载,3深度图 ,4全景图
|
|
|
|
+ switch (datum.getType()) {
|
|
|
|
+ case 1:
|
|
|
|
+ FileUtil.writeUtf8String(JSON.toJSONStringWithDateFormat(datum.getData(),"yyyy-MM-dd HH:mm:ss").replaceAll("\\n", " ").replaceAll("\\t", " "), sourceLocal+ File.separator+datum.getPath());
|
|
|
|
+ break;
|
|
|
|
+ case 2:
|
|
|
|
+ if (os instanceof WindowsOperatingSystem){
|
|
|
|
+ String path = datum.getKey();
|
|
|
|
+ if (datum.getKey().startsWith("/")) {
|
|
|
|
+ path = path.substring(1);
|
|
|
|
+ }
|
|
|
|
+ List<String> strings = fYunFileService.listRemoteFiles(bucket,path);
|
|
|
|
+ for (String key : strings) {
|
|
|
|
+ if (StrUtil.isEmpty(FileUtil.extName(key))){
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ String srcPath=key;
|
|
|
|
+ if(!key.startsWith("/")){
|
|
|
|
+ srcPath = "/"+key;
|
|
|
|
+ }
|
|
|
|
+ this.downloadFile(laserResourceUrl+key,sourceLocal+
|
|
|
|
+ File.separator+datum.getSceneCode()+
|
|
|
|
+ File.separator+"www"+
|
|
|
|
+ File.separator+datum.getSceneCode()+srcPath);
|
|
|
|
+ }
|
|
|
|
+ }else{
|
|
|
|
+ String srcPath=datum.getKey();
|
|
|
|
+ if("/".equals(datum.getKey().substring(0,1))){
|
|
|
|
+ srcPath = srcPath.substring(1);
|
|
|
|
+ }
|
|
|
|
+ fYunFileService.downloadFileByCommand(bucket,srcPath,sourceLocal+datum.getPath());
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case 3:
|
|
|
|
+ if (os instanceof WindowsOperatingSystem){
|
|
|
|
+ String path = datum.getKey();
|
|
|
|
+ if (datum.getKey().startsWith("/")) {
|
|
|
|
+ path = path.substring(1);
|
|
|
|
+ }
|
|
|
|
+ List<String> strings = fYunFileService.listRemoteFiles(bucket,path);
|
|
|
|
+ for (String key : strings) {
|
|
|
|
+ if (StrUtil.isEmpty(FileUtil.extName(key))||FileUtil.extName(key).equalsIgnoreCase("ply")){
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ this.downloadFile(laserResourceUrl+key,sourceLocal+
|
|
|
|
+ File.separator+datum.getSceneCode()+
|
|
|
|
+ File.separator+"www"+
|
|
|
|
+ File.separator+datum.getSceneCode()+
|
|
|
|
+ File.separator+"wwwroot"+
|
|
|
|
+ File.separator+datum.getSceneCode()+
|
|
|
|
+ File.separator+"data"+
|
|
|
|
+ File.separator+datum.getSceneCode()+
|
|
|
|
+ File.separator+"depthmap"+
|
|
|
|
+ File.separator+FileUtil.getName(key));
|
|
|
|
+ }
|
|
|
|
+ }else{
|
|
|
|
+ String srcPath=datum.getKey();
|
|
|
|
+ if("/".equals(datum.getKey().substring(0,1))){
|
|
|
|
+ srcPath = srcPath.substring(1);
|
|
|
|
+ }
|
|
|
|
+ fYunFileService.downloadFileByCommand(bucket,srcPath,sourceLocal+datum.getPath());
|
|
|
|
+ File[] deptLs = FileUtil.ls(sourceLocal+datum.getPath());
|
|
|
|
+ for (File dept : deptLs) {
|
|
|
|
+ if (FileUtil.extName(dept).equalsIgnoreCase("ply")){
|
|
|
|
+ FileUtil.del(dept);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case 4:
|
|
|
|
+ downloadService.cutImg(num,sourceLocal+datum.getPath(),"4k","tiles");
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ String path=sourceLocal+File.separator+num;
|
|
|
|
+
|
|
|
|
+ //处理html的编码
|
|
|
|
+ String htmlPath=laserschool+"www/offline.html";
|
|
|
|
+ if (FileUtil.exist(htmlPath)){
|
|
|
|
+ String copyPath=path+File.separator+"www"+File.separator;
|
|
|
|
+ FileUtil.copy(htmlPath, copyPath, true);
|
|
|
|
+ FileReader fileReader = new FileReader(copyPath+"offline.html");
|
|
|
|
+ String html = fileReader.readString();
|
|
|
|
+ FileWriter fileWriter=new FileWriter(copyPath+"offline.html");
|
|
|
|
+ fileWriter.write(html.replaceAll("@lang@","zh"),false);
|
|
|
|
+ }
|
|
|
|
+ String browserBatPath=laserschool+"start-browser.bat";
|
|
|
|
+ if (FileUtil.exist(browserBatPath)){
|
|
|
|
+ String copyPath=path+File.separator;
|
|
|
|
+ FileUtil.copy(browserBatPath, copyPath, true);
|
|
|
|
+ FileReader fileReader = new FileReader(copyPath+"start-browser.bat");
|
|
|
|
+ String bat = fileReader.readString();
|
|
|
|
+ FileWriter fileWriter=new FileWriter(copyPath+"start-browser.bat");
|
|
|
|
+ fileWriter.write(bat.replaceAll("@sceneCode@",num),false);
|
|
|
|
+ }
|
|
|
|
+ String target=num + "_laser.zip";
|
|
|
|
+ File file=offlineZip(num, path, target);
|
|
|
|
+ String zipPath = String.format(this.zipLocalFormat, num + "_laser");
|
|
|
|
+ FileUtil.move(file,new File(zipPath),true);
|
|
|
|
+ log.info("生成完成");
|
|
|
|
+ }
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }finally {
|
|
|
|
+// String path=sourceLocal+File.separator+num;
|
|
|
|
+// FileUtil.del(path);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ @SneakyThrows
|
|
|
|
+ public File offlineZip(String sceneCode, String path, String target) {
|
|
|
|
+ String bashOfflinePath = laserschool + "bashOffline.zip";
|
|
|
|
+ File file = new File(path + File.separator + "bashOffline.zip");
|
|
|
|
+ FileUtil.copy(new File(bashOfflinePath), file, true);
|
|
|
|
+ ZipParameters zipParameters = new ZipParameters();
|
|
|
|
+ zipParameters.setOverrideExistingFilesInZip(false);
|
|
|
|
+ ZipFile zipFile = new ZipFile(file);
|
|
|
|
+ zipFile.setCharset(Charset.forName("GBK"));
|
|
|
|
+ zipFile.removeFile("www/offline.html");
|
|
|
|
+ zipFile.addFolder(new File(path + File.separator + "www"), zipParameters);
|
|
|
|
+ zipFile.addFile(new File(path + File.separator + "start-browser.bat"));
|
|
|
|
+ return FileUtil.rename(zipFile.getFile(),target, true);
|
|
|
|
+ }
|
|
|
|
+ public void downloadFile(String url, String path){
|
|
|
|
+ File file = new File(path);
|
|
|
|
+ if(!file.getParentFile().exists()){
|
|
|
|
+ file.getParentFile().mkdirs();
|
|
|
|
+ }
|
|
|
|
+ HttpUtil.downloadFile(url, FileUtil.file(path));
|
|
|
|
+ }
|
|
|
|
+}
|