فهرست منبع

update parallelStream

xiewj 1 سال پیش
والد
کامیت
e9f9bd54a5

+ 1 - 1
src/main/java/com/fdkankan/download/listener/RsyncSceneListener.java

@@ -19,7 +19,7 @@ import java.nio.charset.StandardCharsets;
 @Component
 public class RsyncSceneListener {
 
-    public final static String RSYNC_CMD = "rsync -avP -e 'ssh -p $port' $source $user@$host:$dest";
+    public final static String RSYNC_CMD = "rsync -avP -e 'ssh -p $port' $source $user@$host:$dest --info=progress2";
 
     @Value("${rsync.host}")
     private String host;

+ 1 - 1
src/main/java/com/fdkankan/download/service/ILaserService.java

@@ -13,7 +13,7 @@ import java.util.List;
  */
 public interface ILaserService   {
 
-    void downloadHandler(String num) throws Exception;
+    String downloadHandler(String num) throws Exception;
 
 
 }

+ 5 - 1
src/main/java/com/fdkankan/download/service/impl/GenSceneRunnerImpl.java

@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.exceptions.ExceptionUtil;
 import cn.hutool.core.thread.ExecutorBuilder;
 import cn.hutool.core.util.ArrayUtil;
+import cn.hutool.core.util.StrUtil;
 import cn.hutool.system.HostInfo;
 import cn.hutool.system.SystemUtil;
 import com.alibaba.fastjson.JSONObject;
@@ -91,7 +92,10 @@ public class GenSceneRunnerImpl implements CommandLineRunner {
                             threadPoolExecutor.submit(() -> {
                                 try {
                                     // TODO: 2024/1/3 文杰实现
-                                    laserService.downloadHandler(scenePlus.getNum());
+                                    String zipPath = laserService.downloadHandler(scenePlus.getNum());
+                                    if (StrUtil.isNotEmpty(zipPath)){
+                                        send(zipPath);
+                                    }
                                     downloadLogService.saveLog(scenePlus.getNum(), "laser", CommonSuccessStatus.SUCCESS.code(), null);
                                 } catch (Exception e) {
                                     downloadLogService.saveLog(scenePlus.getNum(), "laser", CommonSuccessStatus.FAIL.code(), ExceptionUtil.stacktraceToString(e, 3000));

+ 64 - 54
src/main/java/com/fdkankan/download/service/impl/LaserService.java

@@ -10,6 +10,7 @@ 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.ImageTypeDetail;
 import com.fdkankan.download.bean.LaserResultData;
 import com.fdkankan.download.bean.ResultData;
 import com.fdkankan.download.callback.ErrorCallback;
@@ -36,6 +37,7 @@ import oshi.software.os.windows.WindowsOperatingSystem;
 import javax.annotation.Resource;
 import java.io.File;
 import java.nio.charset.Charset;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 
@@ -70,7 +72,7 @@ public class LaserService  implements ILaserService {
     @Value("${path.zip-local}")
     private String zipLocalFormat;
     @Override
-    public void downloadHandler(String num) throws Exception {
+    public String 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());
@@ -78,61 +80,63 @@ public class LaserService  implements ILaserService {
                 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;
+                List<OfflineDTO> dataDetails = Collections.synchronizedList(data);
+                synchronized(dataDetails) {
+                    data.parallelStream().forEach(datum -> {
+                        //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);
                                     }
-                                    String srcPath=key;
-                                    if(!key.startsWith("/")){
-                                        srcPath = "/"+key;
+                                    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 + num +
+                                                File.separator + "www" +
+                                                File.separator + num + srcPath);
                                     }
-                                    this.downloadFile(laserResourceUrl+key,sourceLocal+
-                                            File.separator+num+
-                                            File.separator+"www"+
-                                            File.separator+num+srcPath);
-                                }
-                            }else{
-                                String srcPath=datum.getKey();
-                                if("/".equals(datum.getKey().substring(0,1))){
-                                    srcPath = srcPath.substring(1);
+                                } else {
+                                    String srcPath = datum.getKey();
+                                    if ("/".equals(datum.getKey().substring(0, 1))) {
+                                        srcPath = srcPath.substring(1);
+                                    }
+                                    fYunFileService.downloadFileByCommand(bucket, sourceLocal + datum.getPath(), srcPath);
                                 }
-                                fYunFileService.downloadFileByCommand(bucket,sourceLocal+datum.getPath(),srcPath);
-                            }
-                            break;
-                        case 3:
+                                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);
+                                List<String> strings = fYunFileService.listRemoteFiles(bucket, path);
                                 for (String key : strings) {
-                                    if (StrUtil.isEmpty(FileUtil.extName(key))||FileUtil.extName(key).equalsIgnoreCase("ply")){
+                                    if (StrUtil.isEmpty(FileUtil.extName(key)) || FileUtil.extName(key).equalsIgnoreCase("ply")) {
                                         continue;
                                     }
-                                    this.downloadFile(laserResourceUrl+key,sourceLocal+
-                                            File.separator+num+
-                                            File.separator+"www"+
-                                            File.separator+num+
-                                            File.separator+"wwwroot"+
-                                            File.separator+datum.getSceneCode()+
-                                            File.separator+"data"+
-                                            File.separator+datum.getSceneCode()+
-                                            File.separator+"depthmap"+
-                                            File.separator+FileUtil.getName(key));
+                                    this.downloadFile(laserResourceUrl + key, sourceLocal +
+                                            File.separator + num +
+                                            File.separator + "www" +
+                                            File.separator + num +
+                                            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();
@@ -147,13 +151,18 @@ public class LaserService  implements ILaserService {
 //                                    }
 //                                }
 //                            }
-                            break;
-                        case 4:
-                            downloadService.cutImg(datum.getSceneCode(),sourceLocal+datum.getPath(),"4k","tiles");
-                            break;
-                        default:
-                            break;
-                    }
+                                break;
+                            case 4:
+                                try {
+                                    downloadService.cutImg(datum.getSceneCode(), sourceLocal + datum.getPath(), "4k", "tiles");
+                                } catch (Exception e) {
+                                    throw new RuntimeException(e);
+                                }
+                                break;
+                            default:
+                                break;
+                        }
+                    });
                 }
                 String path=sourceLocal+File.separator+num;
 
@@ -181,14 +190,15 @@ public class LaserService  implements ILaserService {
                 String zipPath = String.format(this.zipLocalFormat, num + "_laser");
                 FileUtil.move(file,new File(zipPath),true);
                 log.info("生成完成");
+                return zipPath;
             }
         }catch (Exception e){
-            e.printStackTrace();
+            throw e;
         }finally {
 //            String path=sourceLocal+File.separator+num;
 //            FileUtil.del(path);
         }
-
+        return "";
     }
     @SneakyThrows
     public File offlineZip(String sceneCode, String path, String target) {