Browse Source

feat:节点审核提交上传,更正readme.md文件

lucky 3 months ago
parent
commit
9d1752b800
2 changed files with 144 additions and 0 deletions
  1. 6 0
      README.md
  2. 138 0
      zkqy-common/src/main/java/com/zkqy/common/utils/PlaceholderReplacer.java

+ 6 - 0
README.md

@@ -11,3 +11,9 @@
     地址:http://192.168.110.83:1024/login?tenantCode=huaxian
     账号:huaxian
     密码:123456
+
+# git 多仓库切换提交
+## 本地已有项目添加新的远程仓库
+    git remote add  zkqyOrigin http://175.27.169.173:10880/zkqy-sass-platform/mec-cloud_-intelligent-manufacturing_crm.git
+    git push -u zkqyOrigin master
+    输入用户凭证

+ 138 - 0
zkqy-common/src/main/java/com/zkqy/common/utils/PlaceholderReplacer.java

@@ -0,0 +1,138 @@
+package com.zkqy.common.utils;
+
+import java.io.*;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+
+public class PlaceholderReplacer {
+
+    // 组件id占位符
+    private static final String PLACEHOLDEROne = "${componentId}";
+
+    // 组件ID
+    private static final String COMPONENT_ID = "3c374962955748cab96865977f608af6";
+
+    // 类描述信息占位符
+    private  static  final  String PLACEHOLDERTwo="desc";
+
+    // 类描述信息
+    private  static  final  String PLACEHOLDERDesc="组装节点";
+
+
+
+    public static void main(String[] args) {
+        try {
+            // 文件路径
+            String filePath = "D:\\zkqy\\test\\AddAmmunitionPickingUp.java";
+
+            // 新文件路径(基于组件ID生成)
+            String newFilePath = "D:\\zkqy\\test\\" + COMPONENT_ID + ".java";
+
+            // 第一步:将注解中的内容替换为占位符
+            String filledContent = replaceWithPlaceholder(filePath);
+
+            // 第二步:将填充好的内容写入新文件
+            createNewFile(newFilePath, filledContent);
+
+            System.out.println("操作完成!");
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 将注解中的内容替换为占位符
+     *
+     * @param filePath 文件路径
+     * @throws IOException 如果发生 I/O 错误
+     */
+    private static String replaceWithPlaceholder(String filePath) throws IOException {
+        // 读取文件内容
+        StringBuilder contentBuilder = new StringBuilder();
+        try (BufferedReader reader = Files.newBufferedReader(Paths.get(filePath))) {
+            String line;
+            while ((line = reader.readLine()) != null) {
+                if (line.contains("${componentId}")) {
+                    // 替换为占位符
+                    line = line.replace( PLACEHOLDEROne,COMPONENT_ID);
+                }
+                if(line.contains("@{desc}")){  //${desc}
+                    line = line.replace(PLACEHOLDERTwo,PLACEHOLDERDesc ); //${desc}---> 组装节点
+                }
+                contentBuilder.append(line).append(System.lineSeparator());
+            }
+        }
+
+//        // 写回文件
+//        try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(filePath))) {
+//            writer.write(contentBuilder.toString());
+//        }
+        return contentBuilder.toString();
+    }
+
+
+    /**
+     * 重命名文件
+     *
+     * @param originalFilePath 原始文件路径
+     * @param newFileName      新文件名
+     * @throws IOException 如果发生 I/O 错误
+     */
+    private static void renameFile(String originalFilePath, String newFileName) throws IOException {
+        File originalFile = new File(originalFilePath);
+        File newFile = new File(originalFile.getParent(), newFileName);
+
+        // 确保新文件名不冲突
+        if (!newFile.exists()) {
+            boolean success = originalFile.renameTo(newFile);
+            if (!success) {
+                throw new IOException("无法重命名文件");
+            }
+        } else {
+            throw new IOException("目标文件已存在:" + newFile.getAbsolutePath());
+        }
+    }
+
+
+    /**
+     * 创建新文件并将内容写入
+     *
+     * @param newFilePath 新文件路径
+     * @param content     要写入的内容
+     * @throws IOException 如果发生 I/O 错误
+     */
+    private static void createNewFile(String newFilePath, String content) throws IOException {
+        File newFile = new File(newFilePath);
+
+        // 确保父目录存在
+        if (!newFile.getParentFile().exists()) {
+            newFile.getParentFile().mkdirs();
+        }
+
+        // 写入内容到新文件
+        try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(newFilePath))) {
+            writer.write(content);
+        }
+    }
+
+
+
+    /**
+     * 读取模板文件内容
+     *
+     * @param filePath 模板文件路径
+     * @return 文件内容
+     * @throws IOException 如果读取失败
+     */
+    public  String readTemplateFile(String filePath) throws IOException {
+        // 读取文件内容
+        StringBuilder contentBuilder = new StringBuilder();
+        try (BufferedReader reader = Files.newBufferedReader(Paths.get(filePath))) {
+            String line;
+            while ((line = reader.readLine()) != null) {
+                contentBuilder.append(line).append(System.lineSeparator());
+            }
+        }
+        return contentBuilder.toString();
+    }
+}