Explorar o código

更新 删除 tools的旧test.txt 文件

wuweihao %!s(int64=2) %!d(string=hai) anos
pai
achega
daf5231dfa

+ 24 - 0
gis_common/src/main/java/com/gis/common/util/FileUtils.java

@@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.img.ImgUtil;
 import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.lang.Validator;
+import cn.hutool.core.util.ReUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.core.util.URLUtil;
 import com.gis.common.constant.ConfigConstant;
@@ -139,6 +140,29 @@ public class FileUtils {
     }
 
 
+
+    /**
+     * 真删除文件
+     * @param path 参数是相对地址
+     */
+    public void del(String path){
+        if (StrUtil.isBlank(path)){
+            return;
+        }
+        log.info("path: {}", path);
+        // 过滤 路径为/////, 后面必须跟非斜杠字符
+        String regex = "^[/|\\\\]{1,2}[^/|\\\\]\\S";
+        if (!ReUtil.contains(regex, path)){
+            log.warn("非法路径删除:{}", path);
+            return;
+        }
+
+        String delPath = configConstant.serverBasePath + path;
+        FileUtil.del(delPath);
+        log.info("真删除文件: {}", delPath);
+    }
+
+
     /**
      * 单文件上传
      * @param file

+ 15 - 1
gis_service/src/main/java/com/gis/service/impl/OpsServiceImpl.java

@@ -66,6 +66,9 @@ public class OpsServiceImpl implements OpsService {
         try {
             ConvertUtils.convertDamToTxt2(damPath, testModelDataTxtPath);
             log.info("dam2Txt完成, path: {}", testModelDataTxtPath);
+
+
+
         } catch (Exception e) {
             e.printStackTrace();
         }
@@ -75,12 +78,23 @@ public class OpsServiceImpl implements OpsService {
     private void doTxt2Obj(String code){
         // todo modeldata.txt to mesh.obj
         String basePath = configConstant.serverBasePath + code;
-//        String txt2objDir = basePath+ "/test.txt";
+
+        // 删除旧文件test.obj、test.mtl
+        fileUtils.del("/tools/txt2obj/test.txt");
+        fileUtils.del("/tools/txt2obj/test.mtl");
+        fileUtils.del("/tools/txt2obj/test.obj");
+
+
         String txt2objDir = configConstant.serverBasePath + "tools/txt2obj";
+        // 复制txt文件到算法工具目录
+        FileUtil.copy(configConstant.serverBasePath + code + "/test.txt", txt2objDir + "/test.txt", true);
         String txt2objCmd = "python " + configConstant.serverBasePath + "tools\\txt2obj\\run.py " + txt2objDir;
         CmdUtils.callLine(txt2objCmd);
         String meshObjPath = txt2objDir + "/test.obj";
         String meshObjMtlPath = txt2objDir + "/test.mtl";
+
+
+
         if (!FileUtil.exist(meshObjPath)) {
             throw new BaseRuntimeException("算法生成test.obj失败: " + meshObjPath);
         }