Browse Source

优化消费端

wuweihao 3 years ago
parent
commit
289f5a49ca

+ 80 - 106
720yun_fd_consumer/src/main/java/com/gis/listener/Fd720Listener.java

@@ -30,11 +30,9 @@ import java.util.concurrent.*;
 @RabbitListener(queues = RabbitConfig.PANO_QUEUE) // 指定监听队列
 public class Fd720Listener {
 
-//    @Autowired
-//    ConfigConstant configConstant;
 
-    @Autowired
-    FodderMapper fodderMapper;
+//    @Autowired
+//    FodderMapper fodderMapper;
 
     @Autowired
     FodderService fodderService;
@@ -49,127 +47,103 @@ public class Fd720Listener {
         traceId = System.currentTimeMillis()+"";
         MDC.put("TRACE_ID", traceId);
 
-        log.info("监听消息start: {}, uuid: {}", param, traceId);
+        log.info("监听消息_1_start: {}, uuid: {}", param, traceId);
         try {
             Thread.sleep(300);
         } catch (InterruptedException e) {
             e.printStackTrace();
         }
 
-        processPano(param, traceId);
+//        processPano(param, traceId);
+        fodderService.doSlice(param, traceId);
 
 
-        log.info("监听消息end: {}, uuid: {}", param, traceId);
+        log.info("监听消息_1_end: {}, uuid: {}", param, traceId);
     }
 
 
-    /**
-     * 切图会超时控制
-     * @param id
-     */
-    public void processPano(Long id, String traceId)  {
-        MDC.put("TRACE_ID", traceId);
+//    /**
+//     * 切图会超时控制
+//     * @param id
+//     */
+//    public void processPano(Long id, String traceId)  {
+//        MDC.put("TRACE_ID", traceId);
+//
+//        log.info("切图流程开始 : " + id);
+//        long start = System.currentTimeMillis();
+//        FodderEntity entity = fodderMapper.findById(id);
+//        if (entity == null) {
+//            log.error("场景不存在: " + id);
+//            // 直接结束,抛异常的话,会造成死循环,产生大量日志,而且队列也跑不下去
+//            return;
+//        }
+//        String panoPath = entity.getFilePath();
+//        String sceneCode = entity.getSceneCode();
+//        String cmd = CmdConstant.PANO_KRPANO + panoPath;
+//
+//
+//        // 超时处理机制
+//        final ExecutorService exec = Executors.newFixedThreadPool(1);
+//        Callable<String> call = new Callable<String>() {
+//            @Override
+//            public String call() throws Exception {
+//                MDC.put("TRACE_ID", traceId);
+//                CmdUtils.callLine(cmd, 200);
+//                long end = System.currentTimeMillis();
+//                log.info("切图完成耗时: {} s" ,(end-start)/1000);
+//                log.warn("end processListener : "+ id);
+//                return "执行完成";
+//            }
+//        };
+//        // 超时回调
+//        Future<String> future = exec.submit(call);
+//        try {
+//            String obj = future.get(10, TimeUnit.MINUTES); //任务处理超时时间设为 3分钟
+//            entity.setStatus(3);
+//            String tourXmlScene = fodderService.getTourXmlScene(sceneCode);
+//            entity.setTour(tourXmlScene);
+//            // 上传切图目录
+//            // uploadOss(sceneCode);
+//            fodderService.uploadOss(sceneCode);
+//            log.info("任务成功返回: " + obj);
+//        } catch (InterruptedException e) {
+//            e.printStackTrace();
+//            entity.setStatus(2);
+//            StringWriter trace=new StringWriter();
+//            log.error(trace.toString());
+//            log.error("异常了 InterruptedException");
+//        } catch (ExecutionException | BaseRuntimeException e) {
+//            e.printStackTrace();
+//            StringWriter trace=new StringWriter();
+//            e.printStackTrace(new PrintWriter(trace));
+//            log.error("超时了 1");
+//            // 异常日志要打印,不然不会出现在日志文件中,只会出现在控制台
+//            log.error(trace.toString());
+//            entity.setStatus(2);
+//            future.cancel(true);
+//        } catch (TimeoutException e) {
+//            e.printStackTrace();
+//            StringWriter trace=new StringWriter();
+//            e.printStackTrace(new PrintWriter(trace));
+//            log.error("超时了 2");
+//            log.error(trace.toString());
+//            entity.setStatus(2);
+//            future.cancel(true);
+//        } finally {
+//            entity.setUpdateTime(new Date());
+//            fodderMapper.updateByPrimaryKey(entity);
+//            log.info("切图流程, 更新数据库完成 : " + id);
+//        }
+//        log.info("切图流程结束 : " + id);
+//    }
 
-        log.info("切图流程开始 : " + id);
-        long start = System.currentTimeMillis();
-        FodderEntity entity = fodderMapper.findById(id);
-        if (entity == null) {
-            log.error("场景不存在: " + id);
-            // 直接结束,抛异常的话,会造成死循环,产生大量日志,而且队列也跑不下去
-            return;
-        }
-        String panoPath = entity.getFilePath();
-        String sceneCode = entity.getSceneCode();
-        String cmd = CmdConstant.PANO_KRPANO + panoPath;
-
-
-        // 超时处理机制
-        final ExecutorService exec = Executors.newFixedThreadPool(1);
-        Callable<String> call = new Callable<String>() {
-            @Override
-            public String call() throws Exception {
-                MDC.put("TRACE_ID", traceId);
-                CmdUtils.callLine(cmd, 200);
-                long end = System.currentTimeMillis();
-                log.info("切图完成耗时: {} s" ,(end-start)/1000);
-                log.warn("end processListener : "+ id);
-                return "执行完成";
-            }
-        };
-        // 超时回调
-        Future<String> future = exec.submit(call);
-        try {
-            String obj = future.get(10, TimeUnit.MINUTES); //任务处理超时时间设为 3分钟
-            entity.setStatus(3);
-            String tourXmlScene = fodderService.getTourXmlScene(sceneCode);
-            entity.setTour(tourXmlScene);
-            // 上传切图目录
-            // uploadOss(sceneCode);
-            fodderService.uploadOss(sceneCode);
-            log.info("任务成功返回: " + obj);
-        } catch (InterruptedException e) {
-            e.printStackTrace();
-            entity.setStatus(2);
-            StringWriter trace=new StringWriter();
-            log.error(trace.toString());
-            log.error("异常了 InterruptedException");
-        } catch (ExecutionException | BaseRuntimeException e) {
-            e.printStackTrace();
-            StringWriter trace=new StringWriter();
-            e.printStackTrace(new PrintWriter(trace));
-            log.error("超时了 1");
-            // 异常日志要打印,不然不会出现在日志文件中,只会出现在控制台
-            log.error(trace.toString());
-            entity.setStatus(2);
-            future.cancel(true);
-        } catch (TimeoutException e) {
-            e.printStackTrace();
-            StringWriter trace=new StringWriter();
-            e.printStackTrace(new PrintWriter(trace));
-            log.error("超时了 2");
-            log.error(trace.toString());
-            entity.setStatus(2);
-            future.cancel(true);
-        } finally {
-            entity.setUpdateTime(new Date());
-            fodderMapper.updateByPrimaryKey(entity);
-            log.info("切图流程, 更新数据库完成 : " + id);
-        }
-        log.info("切图流程结束 : " + id);
-    }
 
 
 
-    /**
-     * 上传切图目录
-     */
-//    private void uploadOss(String sceneCode){
-//        String cmd = CmdConstant.OSSUTIL_UPLOAD_DIR;
-//        cmd = cmd.replaceAll("@sceneCode", sceneCode);
-//        log.info("ossCmd: " + cmd);
-//        long start = System.currentTimeMillis();
-//        CmdUtils.callshell(cmd);
-//        long end = System.currentTimeMillis();
-//        log.info("切图上传完成, 耗时:{} s" , (end-start)/1000 );
-//    }
 
-    @Test
-    public void test(){
-        CmdUtils.callshell("ipconfig");
-    }
 
 
 
-//    /**
-//     * by owen 2022-4-1
-//     * 打印错误详情
-//     * @param e
-//     */
-//    private void printErrorMsg(BaseRuntimeException e){
-//        StringWriter trace=new StringWriter();
-//        e.printStackTrace(new PrintWriter(trace));
-//        log.error(trace.toString());
-//    }
 
 
 

+ 77 - 78
720yun_fd_consumer/src/main/java/com/gis/listener/Fd720Listener_2.java

@@ -1,7 +1,6 @@
 package com.gis.listener;
 
 import com.gis.constant.CmdConstant;
-import com.gis.constant.ConfigConstant;
 import com.gis.constant.RabbitConfig;
 import com.gis.entity.FodderEntity;
 import com.gis.exception.BaseRuntimeException;
@@ -9,7 +8,6 @@ import com.gis.mapper.FodderMapper;
 import com.gis.service.FodderService;
 import com.gis.util.CmdUtils;
 import lombok.extern.slf4j.Slf4j;
-import org.junit.Test;
 import org.slf4j.MDC;
 import org.springframework.amqp.rabbit.annotation.RabbitHandler;
 import org.springframework.amqp.rabbit.annotation.RabbitListener;
@@ -33,8 +31,8 @@ import java.util.concurrent.*;
 public class Fd720Listener_2 {
 
 
-    @Autowired
-    FodderMapper fodderMapper;
+//    @Autowired
+//    FodderMapper fodderMapper;
 
     @Autowired
     FodderService fodderService;
@@ -56,86 +54,87 @@ public class Fd720Listener_2 {
             e.printStackTrace();
         }
 
-        processPano(param, traceId);
+//        processPano(param, traceId);
+        fodderService.doSlice(param, traceId);
 
 
         log.info("监听消息_2_end: {}, uuid: {}", param, traceId);
     }
 
 
-    /**
-     * 切图会超时控制
-     * @param id
-     */
-    public void processPano(Long id, String traceId)  {
-        MDC.put("TRACE_ID", traceId);
-
-        log.info("切图流程开始 : " + id);
-        long start = System.currentTimeMillis();
-        FodderEntity entity = fodderMapper.findById(id);
-        if (entity == null) {
-            log.error("场景不存在: " + id);
-            // 直接结束,抛异常的话,会造成死循环,产生大量日志,而且队列也跑不下去
-            return;
-        }
-        String panoPath = entity.getFilePath();
-        String sceneCode = entity.getSceneCode();
-        String cmd = CmdConstant.PANO_KRPANO + panoPath;
-
-
-        // 超时处理机制
-        final ExecutorService exec = Executors.newFixedThreadPool(1);
-        Callable<String> call = new Callable<String>() {
-            @Override
-            public String call() throws Exception {
-                MDC.put("TRACE_ID", traceId);
-                CmdUtils.callLine(cmd, 200);
-                long end = System.currentTimeMillis();
-                log.info("切图完成耗时: {} s" ,(end-start)/1000);
-                log.warn("end processListener : "+ id);
-                return "执行完成";
-            }
-        };
-        // 超时回调
-        Future<String> future = exec.submit(call);
-        try {
-            String obj = future.get(10, TimeUnit.MINUTES); //任务处理超时时间设为 3分钟
-            entity.setStatus(3);
-            String tourXmlScene = fodderService.getTourXmlScene(sceneCode);
-            entity.setTour(tourXmlScene);
-            // 上传切图
-            fodderService.uploadOss(sceneCode);
-            log.info("任务成功返回: " + obj);
-        } catch (InterruptedException e) {
-            e.printStackTrace();
-            entity.setStatus(2);
-            StringWriter trace=new StringWriter();
-            log.error(trace.toString());
-            log.error("异常了 InterruptedException");
-        } catch (ExecutionException | BaseRuntimeException e) {
-            e.printStackTrace();
-            StringWriter trace=new StringWriter();
-            e.printStackTrace(new PrintWriter(trace));
-            log.error("超时了 1");
-            // 异常日志要打印,不然不会出现在日志文件中,只会出现在控制台
-            log.error(trace.toString());
-            entity.setStatus(2);
-            future.cancel(true);
-        } catch (TimeoutException e) {
-            e.printStackTrace();
-            StringWriter trace=new StringWriter();
-            e.printStackTrace(new PrintWriter(trace));
-            log.error("超时了 2");
-            log.error(trace.toString());
-            entity.setStatus(2);
-            future.cancel(true);
-        } finally {
-            entity.setUpdateTime(new Date());
-            fodderMapper.updateByPrimaryKey(entity);
-            log.info("切图流程, 更新数据库完成 : " + id);
-        }
-        log.info("切图流程结束 : " + id);
-    }
+//    /**
+//     * 切图会超时控制
+//     * @param id
+//     */
+//    public void processPano(Long id, String traceId)  {
+//        MDC.put("TRACE_ID", traceId);
+//
+//        log.info("切图流程开始 : " + id);
+//        long start = System.currentTimeMillis();
+//        FodderEntity entity = fodderMapper.findById(id);
+//        if (entity == null) {
+//            log.error("场景不存在: " + id);
+//            // 直接结束,抛异常的话,会造成死循环,产生大量日志,而且队列也跑不下去
+//            return;
+//        }
+//        String panoPath = entity.getFilePath();
+//        String sceneCode = entity.getSceneCode();
+//        String cmd = CmdConstant.PANO_KRPANO + panoPath;
+//
+//
+//        // 超时处理机制
+//        final ExecutorService exec = Executors.newFixedThreadPool(1);
+//        Callable<String> call = new Callable<String>() {
+//            @Override
+//            public String call() throws Exception {
+//                MDC.put("TRACE_ID", traceId);
+//                CmdUtils.callLine(cmd, 200);
+//                long end = System.currentTimeMillis();
+//                log.info("切图完成耗时: {} s" ,(end-start)/1000);
+//                log.warn("end processListener : "+ id);
+//                return "执行完成";
+//            }
+//        };
+//        // 超时回调
+//        Future<String> future = exec.submit(call);
+//        try {
+//            String obj = future.get(10, TimeUnit.MINUTES); //任务处理超时时间设为 3分钟
+//            entity.setStatus(3);
+//            String tourXmlScene = fodderService.getTourXmlScene(sceneCode);
+//            entity.setTour(tourXmlScene);
+//            // 上传切图
+//            fodderService.uploadOss(sceneCode);
+//            log.info("任务成功返回: " + obj);
+//        } catch (InterruptedException e) {
+//            e.printStackTrace();
+//            entity.setStatus(2);
+//            StringWriter trace=new StringWriter();
+//            log.error(trace.toString());
+//            log.error("异常了 InterruptedException");
+//        } catch (ExecutionException | BaseRuntimeException e) {
+//            e.printStackTrace();
+//            StringWriter trace=new StringWriter();
+//            e.printStackTrace(new PrintWriter(trace));
+//            log.error("超时了 1");
+//            // 异常日志要打印,不然不会出现在日志文件中,只会出现在控制台
+//            log.error(trace.toString());
+//            entity.setStatus(2);
+//            future.cancel(true);
+//        } catch (TimeoutException e) {
+//            e.printStackTrace();
+//            StringWriter trace=new StringWriter();
+//            e.printStackTrace(new PrintWriter(trace));
+//            log.error("超时了 2");
+//            log.error(trace.toString());
+//            entity.setStatus(2);
+//            future.cancel(true);
+//        } finally {
+//            entity.setUpdateTime(new Date());
+//            fodderMapper.updateByPrimaryKey(entity);
+//            log.info("切图流程, 更新数据库完成 : " + id);
+//        }
+//        log.info("切图流程结束 : " + id);
+//    }
 
 
 

+ 1 - 6
720yun_fd_consumer/src/main/java/com/gis/service/FodderService.java

@@ -5,10 +5,5 @@ package com.gis.service;
  */
 public interface FodderService {
 
-    String getTourXmlScene(String code);
-
-    /**
-     * 上传切图目录
-     */
-    void uploadOss(String sceneCode);
+    void doSlice(Long param, String traceId);
 }

+ 89 - 5
720yun_fd_consumer/src/main/java/com/gis/service/impl/FodderServiceImpl.java

@@ -4,13 +4,21 @@ import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.util.StrUtil;
 import com.gis.constant.CmdConstant;
 import com.gis.constant.ConfigConstant;
+import com.gis.entity.FodderEntity;
 import com.gis.exception.BaseRuntimeException;
+import com.gis.mapper.FodderMapper;
 import com.gis.service.FodderService;
 import com.gis.util.CmdUtils;
 import lombok.extern.slf4j.Slf4j;
+import org.slf4j.MDC;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.Date;
+import java.util.concurrent.*;
+
 /**
  * Created by owen on 2022/7/27 0027 16:55
  */
@@ -21,12 +29,15 @@ public class FodderServiceImpl implements FodderService {
     @Autowired
     ConfigConstant configConstant;
 
-    @Override
-    public String getTourXmlScene(String code) {
+    @Autowired
+    FodderMapper fodderMapper;
+
+    // 获取切图后的tour.xml
+    private String getTourXmlScene(String code) {
         log.info("处理tour.xml");
         String tourPath = configConstant.serverBasePath + code + "/vtour/tour.xml";
         log.info("tourPath: {}", tourPath);
-        BaseRuntimeException.isTrue(FileUtil.isFile(tourPath), null, code + "_tour.xml文件不存在");
+        BaseRuntimeException.isTrue(!FileUtil.isFile(tourPath), null, code + "_tour.xml文件不存在");
 
         String tour = FileUtil.readString(tourPath, "utf-8");
         tour = StrUtil.subAfter(tour, "</action>", true);
@@ -38,8 +49,8 @@ public class FodderServiceImpl implements FodderService {
         return trim;
     }
 
-    @Override
-    public void uploadOss(String sceneCode) {
+    // 上传切图到oss
+    private void uploadOss(String sceneCode) {
         String cmd = CmdConstant.OSSUTIL_UPLOAD_DIR;
         cmd = cmd.replaceAll("@sceneCode", sceneCode);
         log.info("ossCmd: " + cmd);
@@ -48,4 +59,77 @@ public class FodderServiceImpl implements FodderService {
         long end = System.currentTimeMillis();
         log.info("切图上传完成, 耗时:{} s" , (end-start)/1000 );
     }
+
+    @Override
+    public void doSlice(Long id, String traceId) {
+        MDC.put("TRACE_ID", traceId);
+
+        log.info("切图流程开始 : " + id);
+        long start = System.currentTimeMillis();
+        FodderEntity entity = fodderMapper.findById(id);
+        if (entity == null) {
+            log.error("场景不存在: " + id);
+            // 直接结束,抛异常的话,会造成死循环,产生大量日志,而且队列也跑不下去
+            return;
+        }
+        String panoPath = entity.getFilePath();
+        String sceneCode = entity.getSceneCode();
+        String cmd = CmdConstant.PANO_KRPANO + panoPath;
+
+
+        // 超时处理机制
+        final ExecutorService exec = Executors.newFixedThreadPool(1);
+        Callable<String> call = new Callable<String>() {
+            @Override
+            public String call() throws Exception {
+                MDC.put("TRACE_ID", traceId);
+                CmdUtils.callLine(cmd, 200);
+                long end = System.currentTimeMillis();
+                log.info("切图完成耗时: {} s" ,(end-start)/1000);
+                log.warn("end processListener : "+ id);
+                return "执行完成";
+            }
+        };
+        // 超时回调
+        Future<String> future = exec.submit(call);
+        try {
+            String obj = future.get(10, TimeUnit.MINUTES); //任务处理超时时间设为 3分钟
+            entity.setStatus(3);
+            String tourXmlScene = this.getTourXmlScene(sceneCode);
+            entity.setTour(tourXmlScene);
+            // 上传切图
+            this.uploadOss(sceneCode);
+            log.info("任务成功返回: " + obj);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+            entity.setStatus(2);
+            StringWriter trace=new StringWriter();
+            log.error(trace.toString());
+            log.error("异常了 InterruptedException");
+        } catch (ExecutionException | BaseRuntimeException e) {
+            e.printStackTrace();
+            StringWriter trace=new StringWriter();
+            e.printStackTrace(new PrintWriter(trace));
+            log.error("超时了 1");
+            // 异常日志要打印,不然不会出现在日志文件中,只会出现在控制台
+            log.error(trace.toString());
+            entity.setStatus(2);
+            future.cancel(true);
+        } catch (TimeoutException e) {
+            e.printStackTrace();
+            StringWriter trace=new StringWriter();
+            e.printStackTrace(new PrintWriter(trace));
+            log.error("超时了 2");
+            log.error(trace.toString());
+            entity.setStatus(2);
+            future.cancel(true);
+        } finally {
+            entity.setUpdateTime(new Date());
+            fodderMapper.updateByPrimaryKey(entity);
+            log.info("切图流程, 更新数据库完成 : " + id);
+        }
+        log.info("切图流程结束 : " + id);
+    }
+
+
 }