diff --git a/src/test/java/BuilderPackageEcology.java b/src/test/java/BuilderPackageEcology.java index eedc19f..885e867 100644 --- a/src/test/java/BuilderPackageEcology.java +++ b/src/test/java/BuilderPackageEcology.java @@ -16,8 +16,8 @@ import javafx.stage.Stage; import java.io.File; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; +import java.text.SimpleDateFormat; +import java.util.*; public class BuilderPackageEcology extends Application { @@ -68,17 +68,33 @@ public class BuilderPackageEcology extends Application { buttonBox.setSpacing(10); buttonBox.setPadding(new Insets(10)); buttonBox.setAlignment(Pos.CENTER_RIGHT); - + Map param = new HashMap<>(8); + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd"); + Date date = new Date(); + param.put("date", simpleDateFormat.format(date)); Button button = new Button("生成升级包"); button.setOnAction(event -> { + // 输出包编号和功能名称的值 + String packageNumber = packageNumberTextField.getText(); + String functionName = functionNameTextField.getText(); FileChooser fileChooser = new FileChooser(); String defaultName = FileTreeBuilder.zipDefaultName; if (StrUtil.isBlank(defaultName)) { defaultName = "sh_ebu_dev_1_ecology.zip"; } - + param.put("name", functionName); + param.put("no", packageNumber); + defaultName = replacePlaceholders(defaultName, param); + replacePlaceholders(defaultName, param); + String defaultDir = FileTreeBuilder.defaultDir; + if (StrUtil.isNotBlank(defaultDir)) { + try { + fileChooser.setInitialDirectory(new File(defaultDir)); + } catch (Exception ignore) { + System.out.println(defaultDir); + } + } fileChooser.setInitialFileName(defaultName); - // fileChooser.setInitialDirectory(); File outputFile = fileChooser.showSaveDialog(primaryStage); if (outputFile != null) { try { @@ -97,14 +113,11 @@ public class BuilderPackageEcology extends Application { }); clearSelections(); updateTreeView(); + packageNumberTextField.setText(""); + functionNameTextField.setText(""); showSuccessAlert("升级包制作成功!"); System.out.println("压缩包位置: " + outputFile.getPath()); - // 输出包编号和功能名称的值 - String packageNumber = packageNumberTextField.getText(); - String functionName = functionNameTextField.getText(); - System.out.println("包编号: " + packageNumber); - System.out.println("功能名称: " + functionName); } catch (IOException e) { throw new RuntimeException(e); } @@ -154,6 +167,7 @@ public class BuilderPackageEcology extends Application { } } filePaths.clear(); + } private void updateTreeView() { @@ -217,6 +231,25 @@ public class BuilderPackageEcology extends Application { alert.showAndWait(); } + public static String replacePlaceholders(String inputString, Map placeholderMap) { + StringBuilder outputString = new StringBuilder(inputString); + + for (Map.Entry entry : placeholderMap.entrySet()) { + String placeholder = "${" + entry.getKey() + "}"; + String value = entry.getValue(); + + // 检查占位符是否存在于字符串中 + if (outputString.indexOf(placeholder) != -1) { + // 使用 String 类的 replace 方法进行占位符的替换 + outputString.replace(outputString.indexOf(placeholder), + outputString.indexOf(placeholder) + placeholder.length(), + value); + } + } + + return outputString.toString(); + } + public static void main(String[] args) { launch(args); } diff --git a/src/test/java/builderpackage/FileTreeBuilder.java b/src/test/java/builderpackage/FileTreeBuilder.java index 5b7e1a7..436fe9b 100644 --- a/src/test/java/builderpackage/FileTreeBuilder.java +++ b/src/test/java/builderpackage/FileTreeBuilder.java @@ -1,10 +1,10 @@ package builderpackage; +import aiyh.utils.excention.CustomerException; import aiyh.utils.tool.cn.hutool.core.util.StrUtil; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; +import java.io.*; +import java.nio.charset.StandardCharsets; import java.util.*; public class FileTreeBuilder { @@ -27,7 +27,11 @@ public class FileTreeBuilder { Properties properties = new Properties(); try (InputStream inputStream = FileTreeBuilder.class.getClassLoader().getResourceAsStream("application.properties")) { - properties.load(inputStream); + if (inputStream == null) { + throw new CustomerException("测试包的resources中不存在application.properties!"); + } + BufferedReader bf = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8)); + properties.load(bf); // 通过键获取属性值 String value = properties.getProperty("packageBlackPaths"); if (StrUtil.isNotBlank(value)) {