Преглед изворни кода

初始化方法 入参校验

wuweihao пре 3 година
родитељ
комит
04f1d21dc1

+ 45 - 28
laser/src/main/java/com/fdkankan/indoor/core/service/impl/InitServiceImpl.java

@@ -22,10 +22,11 @@ import com.fdkankan.indoor.core.service.*;
 import lombok.extern.slf4j.Slf4j;
 import net.sf.json.JSONArray;
 import net.sf.json.JSONObject;
+import org.apache.commons.lang.StringUtils;
 import org.junit.Test;
 import org.slf4j.MDC;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 
 import java.io.IOException;
@@ -115,6 +116,26 @@ public class InitServiceImpl implements InitService {
             throw new BaseRuntimeException("场景码不能为空");
         }
 
+        String path = param.getPath();
+        if (StrUtil.isBlank(path)) {
+            throw new BaseRuntimeException("init.path路径不能为空");
+        }
+        if (!StringUtils.endsWith(path, "/laserData")) {
+            log.error("init.path路径不合法, {}", 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("用户名称(手机号)不能为空");
+        }
+
+
         // 防止为四维看看重复调用重算
         InitEntity init = findById(sceneCode);
         if (init != null) {
@@ -124,31 +145,13 @@ public class InitServiceImpl implements InitService {
                 log.info("进行手动重新");
             } else {
                 log.info("算法重算");
-                init.setPath(param.getPath());
-                init.setTitle(param.getTitle());
+                init.setTitle(title);
                 init.setUpdateTime(LocalDateTime.now());
                 init.setUseStatus(1);
-                initMapper.save(init);
+//                initMapper.save(init);
             }
         } 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(path);
@@ -164,9 +167,9 @@ public class InitServiceImpl implements InitService {
             init.setUserId(param.getUserId());
             init.setUserName(phone);
 
-            initMapper.save(init);
 
         }
+        initMapper.save(init);
 
 
         InitEntity finalInit = init;
@@ -252,9 +255,9 @@ public class InitServiceImpl implements InitService {
      * @param initParam
      */
     public void initDataStep1(InitEntity initParam, String traceId){
-        log.info("异步初始化数据开始");
         // 链路id
         MDC.put("TRACE_ID", traceId);
+        log.info("异步初始化数据开始");
 
         String sceneCode = initParam.getId();
         String laserDataPath = initParam.getPath();
@@ -264,7 +267,6 @@ public class InitServiceImpl implements InitService {
         // 删除旧数据, 重算使用
         initRemove(sceneCode);
 
-
         // step1 创建t_route表(路径规划)
         createRoute(sceneCode, laserDataPath);
 
@@ -439,9 +441,16 @@ public class InitServiceImpl implements InitService {
 
         log.info("执行手动重新:{}", sceneCode);
         // 重新初始化数据, 地址在里面处理
+        InitEntity initEntity = this.findById(sceneCode);
+        if (initEntity == null){
+            log.info("重算的场景码不存在: {}", sceneCode);
+            return Result.failure("场景不存在");
+        }
         InitDto initDto = new InitDto();
-        initDto.setSceneCode(sceneCode);
+        BeanUtils.copyProperties(initEntity, initDto);
         initDto.setFrom("recount");
+        initDto.setSceneCode(sceneCode);
+        initDto.setPhone(initEntity.getUserName());
 
         this.initData(initDto);
 
@@ -464,10 +473,14 @@ public class InitServiceImpl implements InitService {
      * @param title
      */
     private void replaceHtml(String sceneCode, String title) {
+        log.info("替换输入场景码: {}", sceneCode);
+        log.info("替换输入标题: {}", title);
+
         String indexName = "index.html";
 
         String basePath = configConstant.serverBasePath + "/" + sceneCode + "/";
         String indexPath = basePath + indexName;
+        log.info("替换index.html路径: {}", indexPath);
 
         String indexStr = cn.hutool.core.io.FileUtil.readUtf8String(indexPath);
         if (!indexStr.contains("@replace")) {
@@ -477,13 +490,17 @@ public class InitServiceImpl implements InitService {
         if (!indexStr.contains("@title")) {
             throw new BaseRuntimeException(MsgCode.e3001, "index.html不包@title含默认值, 请查看default文件是否正确");
         }
-
+        log.info("替换非法校验完成");
 
         indexStr = indexStr.replaceAll("@replace", sceneCode);
-        indexStr = indexStr.replaceAll("@title", title);
+        log.info("替换场景码完成", sceneCode);
+        if (StringUtils.isNotBlank(title)){
+            indexStr = indexStr.replaceAll("@title", title);
+        }
+        log.info("替换场标题完成", title);
 
         cn.hutool.core.io.FileUtil.writeUtf8String(indexStr, indexPath);
-        log.info("html文件替完成");
+        log.info("替换html文件完成");
 
     }
 

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

@@ -22,7 +22,7 @@ spring.redis.jedis.pool.max-wait=-1ms
 # \uFFFD\uFFFD\uFFFD\uFFFD\u0328sql\uFFFD\uFFFD\u05BE\uFFFD\uFFFD\uFFFD
 logging.level.org.springframework.data.mongodb.core= info
 
-logging.file.path=/root/user/log/${project.en}_log
+logging.file.path=/root/log/${project.en}_log
 
 swagger.package=com.fdkankan.indoor.core.controller
 swagger.title=${project.sc}-pro