瀏覽代碼

初始化方法改异步执行

wuweihao 3 年之前
父節點
當前提交
e3fa288f59

+ 1 - 0
laser/src/main/java/com/fdkankan/indoor/base/aop/WebLogAspect.java

@@ -72,6 +72,7 @@ public class WebLogAspect {
     public void doAfterReturning(Object ret) throws Throwable {
         // 处理完请求,返回内容
         log.warn("end:{}, uuid: {},  响应耗时:{} ms", request.getRequestURI(), startTime, (System.currentTimeMillis() - startTime));
+        MDC.clear();
     }
 
     /**

+ 126 - 31
laser/src/main/java/com/fdkankan/indoor/core/service/impl/InitServiceImpl.java

@@ -1,5 +1,6 @@
 package com.fdkankan.indoor.core.service.impl;
 
+import cn.hutool.core.thread.ThreadUtil;
 import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSON;
 import com.fdkankan.indoor.base.constant.CmdConstant;
@@ -22,7 +23,9 @@ import lombok.extern.slf4j.Slf4j;
 import net.sf.json.JSONArray;
 import net.sf.json.JSONObject;
 import org.junit.Test;
+import org.slf4j.MDC;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 
 import java.io.IOException;
@@ -129,11 +132,28 @@ public class InitServiceImpl implements InitService {
             }
         } else {
             // 新场景
+
+            // 路径在这里检测
+            String path = param.getPath();
+            if (StrUtil.isBlank(path)) {
+                throw new BaseRuntimeException("init.path路径不能为空");
+            }
+
+            String title = param.getTitle();
+            if (StrUtil.isBlank(title)) {
+                throw new BaseRuntimeException("标题不能为空");
+            }
+
+            String phone = param.getPhone();
+            if (StrUtil.isBlank(phone)) {
+                throw new BaseRuntimeException("用户名称不能为空");
+            }
+
             init = new InitEntity();
             init.setId(sceneCode);
-            init.setPath(param.getPath());
+            init.setPath(path);
             init.setCreateTime(LocalDateTime.now());
-            init.setTitle(param.getTitle());
+            init.setTitle(title);
             init.setChildName(param.getChildName());
             init.setSnCode(param.getSnCode());
             init.setShootTime(param.getCreateTime());
@@ -142,30 +162,108 @@ public class InitServiceImpl implements InitService {
             // https://testlaser.4dkankan.com/maxkk/ + 场景码
             init.setWebSite(configConstant.webSitePath + sceneCode);
             init.setUserId(param.getUserId());
-            init.setUserName(param.getPhone());
+            init.setUserName(phone);
 
             initMapper.save(init);
 
         }
 
-        // 删除旧数据, 重算使用
-        initRemove(sceneCode);
 
-        String path = init.getPath();
-        String title = init.getTitle();
-        // 路径在这里检测
-        if (StrUtil.isBlank(path)) {
-            throw new BaseRuntimeException("init.path路径不能为空");
-        }
+        InitEntity finalInit = init;
+        String traceId = MDC.get("TRACE_ID");
+        log.info("链路id: {}", traceId);
+        ThreadUtil.execAsync(() -> initDataStep1(finalInit, traceId));
+
+
+
+
 
-        if (StrUtil.isBlank(title)) {
-            throw new BaseRuntimeException("标题不能为空");
-        }
 
 
 //        String laserDataPath = path + "/laserData";
-        String laserDataPath = path ;
-        log.info("laserDataPath: {}", laserDataPath);
+//        String laserDataPath = path ;
+//        log.info("laserDataPath: {}", laserDataPath);
+//
+//        // step1 创建t_route表(路径规划)
+//        createRoute(sceneCode, laserDataPath);
+//
+//        // step3 创建poi表, 热点,默认没有
+//        createPoi(sceneCode);
+//
+//        // step4 创建poi_type表, 使用的是模板初始化
+//        createPoiType(sceneCode);
+//
+//        // step5 创建poi_type_group表, 使用的是模板初始化
+//        createPoiTypeGroup(sceneCode);
+//
+//        // step7 复制静态资源
+//        copyDefault(sceneCode);
+//
+//
+//        //step8 替换index.html、/locat/addDataSet.html的场景码, @replace, @title
+//        replaceHtml(sceneCode, title);
+//
+//        // step9 创建 t_measurement表, 测量表,空数据
+//        createMeasurement(sceneCode);
+
+
+//        log.info("================== 初始化第一步完成 ==================");
+//
+//        /**
+//         * 这方法很重要, 会自动初始化initData2 的说有方法
+//         * step10 创建控制点表 t_controlPoint, 读取服务器controlPoint.json文件
+//         */
+//
+//        String controlPointPath = laserDataPath + "/controlPoint.json";
+//        log.info("控制点文件路径:{}", controlPointPath);
+//        boolean flag = false;
+//        if (cn.hutool.core.io.FileUtil.exist(controlPointPath)) {
+//            log.info("处理控制点逻辑");
+//            createControlPoint(sceneCode, laserDataPath);
+//            flag = true;
+//        } else {
+//            log.info("控制点文件不存在:{}", controlPointPath);
+//        }
+
+
+        // 2021-09-23 地址需要更新
+//        init.setUpdateTime(LocalDateTime.now());
+//        Integer recount = init.getRecount();
+//        recount = recount == null ? 1 : recount + 1;
+//        init.setRecount(recount);
+
+
+//        if (flag) {
+//            init.setStatus(1);
+//            log.info("完全初始化完成");
+//        } else {
+//            log.info("initDataStep_1处理完成");
+//            init.setStatus(0);
+//        }
+//
+//        initMapper.save(init);
+
+        return Result.success();
+    }
+
+
+    /**
+     * 初始化数据第一步
+     * @param initParam
+     */
+    public void initDataStep1(InitEntity initParam, String traceId){
+        log.info("异步初始化数据开始");
+        // 链路id
+        MDC.put("TRACE_ID", traceId);
+
+        String sceneCode = initParam.getId();
+        String laserDataPath = initParam.getPath();
+        String title = initParam.getTitle();
+
+
+        // 删除旧数据, 重算使用
+        initRemove(sceneCode);
+
 
         // step1 创建t_route表(路径规划)
         createRoute(sceneCode, laserDataPath);
@@ -189,7 +287,6 @@ public class InitServiceImpl implements InitService {
         // step9 创建 t_measurement表, 测量表,空数据
         createMeasurement(sceneCode);
 
-
         log.info("================== 初始化第一步完成 ==================");
 
         /**
@@ -208,25 +305,24 @@ public class InitServiceImpl implements InitService {
             log.info("控制点文件不存在:{}", controlPointPath);
         }
 
-
-        // 2021-09-23 地址需要更新
-        init.setUpdateTime(LocalDateTime.now());
-        Integer recount = init.getRecount();
-        recount = recount == null ? 1 : recount + 1;
-        init.setRecount(recount);
-
-
         if (flag) {
-            init.setStatus(1);
+            initParam.setStatus(1);
             log.info("完全初始化完成");
         } else {
             log.info("initDataStep_1处理完成");
-            init.setStatus(0);
+            initParam.setStatus(0);
         }
 
-        initMapper.save(init);
+        // 2021-09-23 地址需要更新
+        initParam.setUpdateTime(LocalDateTime.now());
+        Integer recount = initParam.getRecount();
+        recount = recount == null ? 1 : recount + 1;
+        initParam.setRecount(recount);
+
+        initMapper.save(initParam);
+
+        log.info("异步初始化数据结束");
 
-        return Result.success();
     }
 
 
@@ -276,7 +372,7 @@ public class InitServiceImpl implements InitService {
         // step7 创建t_datasets表, 使用的是代码, 需要处理原点之后执行
         DataSetPo dataSet = createDataSet(sceneCode, laserDataPath, calculateEntity.getRotation2(), from);
 
-        // step 10 创建 t_tiled_map表, 需要用到dataSet数据
+        // step 10 创建平面图 t_tiled_map表, 需要用到dataSet数据
         tiledMapService.init(sceneCode, from);
 
 
@@ -305,7 +401,6 @@ public class InitServiceImpl implements InitService {
             throw new BaseRuntimeException("初始化数据不存在:" + sceneCode);
         }
         String path = initEntity.getPath();
-//        path = path + "/laserData";
 
         processCould(sceneCode, path, controlPoint);
 

+ 15 - 0
laser/src/main/java/com/fdkankan/indoor/core/service/impl/TestServiceImpl.java

@@ -1,11 +1,13 @@
 package com.fdkankan.indoor.core.service.impl;
 
+import cn.hutool.core.thread.ThreadUtil;
 import com.fdkankan.indoor.base.util.Result;
 import com.fdkankan.indoor.core.service.TestService;
 import com.fdkankan.indoor.core.entity.vo.BaseListVo;
 import com.fdkankan.indoor.core.entity.vo.HaoVo;
 import com.fdkankan.indoor.core.entity.vo.OwenVo;
 import lombok.extern.slf4j.Slf4j;
+import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.mongodb.core.MongoTemplate;
 import org.springframework.data.mongodb.core.query.Criteria;
@@ -50,4 +52,17 @@ public class TestServiceImpl implements TestService {
 
         return vo;
     }
+
+
+    @Test
+    public  void threadTest(){
+        ThreadUtil.execAsync(() -> test1());
+        System.out.println("运行结束");
+    }
+
+    private void test1() {
+        System.out.println("开始调用");
+//        ThreadUtil.sleep(2);
+        System.out.println("启动了一个多线程");
+    }
 }

+ 9 - 8
laser/src/main/java/com/fdkankan/indoor/core/service/impl/TiledMapServiceImpl.java

@@ -83,8 +83,9 @@ public class TiledMapServiceImpl extends IBaseServiceImpl implements TiledMapSer
             // 2021.09.03
             entity.setData(initData(sceneCode, from));
         } else {
-            log.info("来自web端重算,处理平面图开始, 把cover重新上传oss就行");
-            uploadCover(sceneCode);
+            log.info("来自web端平面图重算, 把cover重新上传oss就行,并计算四叉树值");
+//            uploadCover(sceneCode);
+            entity.setData(initData(sceneCode, from));
         }
 
         entity.setStatus(0);
@@ -424,11 +425,11 @@ public class TiledMapServiceImpl extends IBaseServiceImpl implements TiledMapSer
             path = "F:\\test\\ngin\\age_laser_data\\" + sceneCode + "\\results\\laserData";
         }
         String infoPath = path + "/cover/info.json";
-        log.info("info.json path: {}", infoPath);
+        log.info("平面图info.json path: {}", infoPath);
 
         // 若文件不存在, 返回一个空数组
         if (!FileUtil.isFile(infoPath)){
-            log.warn("info.json文件不存在, 返回一个空数组:{}", sceneCode);
+            log.warn("平面图info.json文件不存在, 返回一个空数组:{}", sceneCode);
             return new ArrayList<>();
         }
 
@@ -436,13 +437,13 @@ public class TiledMapServiceImpl extends IBaseServiceImpl implements TiledMapSer
         JSONObject strJson = JSONObject.parseObject(str);
         JSONArray zoom = strJson.getJSONArray("zoom");
         Integer maxDepth = zoom.size()-1;
-        log.info("maxDepth: {}", maxDepth);
+        log.info("平面图maxDepth: {}", maxDepth);
 
         JSONObject resolution = strJson.getJSONObject("resolution");
         Integer width = resolution.getInteger("width");
         Integer height = resolution.getInteger("height");
         Integer imgWidth = width >= height? width: height;
-        log.info("imgWidth: {}", imgWidth);
+        log.info("平面图imgWidth: {}", imgWidth);
 
 
         double mapSize_m = PlanGraph.getSize(imgWidth, 1);
@@ -457,14 +458,14 @@ public class TiledMapServiceImpl extends IBaseServiceImpl implements TiledMapSer
 
         // 四叉树
         String dirPath = path + "/cover/" + maxDepth;
-        log.info("quadTree dirPath: {}", dirPath);
+        log.info("平面图quadTree dirPath: {}", dirPath);
         Solution solution = new Solution();
         File file = solution.readFiles(dirPath);
         String quadTree = "";
         if(file!=null) {
              quadTree = solution.getXYTiles(file);
         }
-        log.info("quadTree : {}", quadTree);
+        log.info("平面图quadTree : {}", quadTree);
 
 
         TiledMapDto dto = new TiledMapDto();

+ 1 - 1
laser/src/main/resources/application.properties

@@ -15,4 +15,4 @@ project.sc=\u6FC0\u5149\u76F8\u673A
 #\u4E0A\u4F20\u6587\u4EF6\u5927\u5C0F
 spring.servlet.multipart.enabled=true
 spring.servlet.multipart.max-file-size=2048MB
-spring.servlet.multipart.max-request-size=2048MB
+spring.servlet.multipart.max-request-size=2048MB