From 9cf7bde99b211c88edf9d64776d8c5b980c49deb Mon Sep 17 00:00:00 2001
From: Hunter0x7c7 <1125607007@qq.com>
Date: 星期日, 13 八月 2023 17:31:07 +0800
Subject: [PATCH] 修改参数设置对话框Padding

---
 src/main/java/com/github/hunter0x7c7/sync/ctrls/Controller.java |  162 ++++++++++++++++++++++++++++++++---------------------
 1 files changed, 98 insertions(+), 64 deletions(-)

diff --git a/src/main/java/com/github/hunter0x7c7/sync/ctrls/Controller.java b/src/main/java/com/github/hunter0x7c7/sync/ctrls/Controller.java
index ab3c426..b0fd516 100644
--- a/src/main/java/com/github/hunter0x7c7/sync/ctrls/Controller.java
+++ b/src/main/java/com/github/hunter0x7c7/sync/ctrls/Controller.java
@@ -35,13 +35,6 @@
 
 import java.awt.MenuItem;
 import java.awt.*;
-import java.io.File;
-import java.io.UnsupportedEncodingException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.net.URLDecoder;
-import java.nio.file.Files;
 import java.sql.*;
 import java.util.Date;
 import java.util.List;
@@ -53,6 +46,15 @@
 import static com.github.hunter0x7c7.sync.model.global.Parameters.*;
 
 public class Controller {
+    public static final String SQL1_QUERY = "SELECT * FROM IOT_Equipment_Info WHERE IE_Type = 'XPH鐗╄仈缃戝叧'; ";
+    public static final String SQL2_QUERY = "SELECT SD_Addr + '|' + SD_Code IE_Param, * " +
+            "FROM TY_SensorData WHERE SD_Key IN ( '%s' );";
+    public static final String SQL3_UPDATE = "UPDATE IOT_Equipment_Info " +
+            "SET IE_Realtime_Data = ?, IE_Realtime_Time = ?, Edit_User = ?, Edit_Time = ? " +
+            "WHERE IE_Param = ? AND IE_Parent = ( " +
+            "SELECT IE_ID FROM IOT_Equipment_Info WHERE IE_Param = ? " +
+            ") ;";
+
     @FXML
     private TextField tvInputSrcHost;
     @FXML
@@ -112,10 +114,10 @@
     }
 
 
-    @Override
+    /*@Override
     protected void finalize() throws Throwable {
         super.finalize();
-    }
+    }*/
 
     private void init() {
         mCompositeDisposable = new CompositeDisposable();
@@ -176,7 +178,7 @@
                         //娣诲姞鍒扮郴缁熸墭鐩�
                         Stage primaryStage = Session.getInstance().getPrimaryStage();
                         String tooltip = String.format("%s v%s", AppName, VersionName);//SyncTools v1.0
-                        String mipmap = "mipmap/img_chinese_cabbage_16.png";
+                        String mipmap = "mipmap/ic_chinese_cabbage_16.png";
                         MenuItem show = new MenuItem("鏄剧ず");//鏄剧ずShow
                         //缁戝畾绯荤粺鎵樼洏浜嬩欢
                         show.addActionListener(actionListener -> {
@@ -217,13 +219,14 @@
                                     setInputText(tvInputTargetDbName, cb.getTargetDbName());
                                     setInputText(tvInputFreq, cb.getFreqValue());
                                     cbSelectFreqUnit.getSelectionModel().select(cb.getFreqUnit());
+
+                                    //榛樿鍚姩鍚屾鍔熻兘
+                                    if (cb.isStartSync()) {
+                                        startSync();    //鍚姩鍚屾鍔熻兘
+                                    }
                                 }
                             });
 
-                            //榛樿鍚姩鍚屾鍔熻兘
-                            if (cb.isStartSync()) {
-                                startSync();    //鍚姩鍚屾鍔熻兘
-                            }
                         } else if (BuildType.equals(BuildTypeEnum.DEBUG)) {
                             try {
                                 String srcHost = ConfigProperties.SRC_HOST;
@@ -336,24 +339,54 @@
 
     //鐐瑰嚮锛氶��鍑�
     private void clickExit() {
-        if (isSyncing()) {
-            stopSync();//鍋滄鍚屾
-        }
-        //绯荤粺鎵樼洏
-        SystemTray tray = SystemTray.getSystemTray();
-        if (tray != null) {
-            TrayIcon[] icons = tray.getTrayIcons();
-            for (TrayIcon icon : icons) {
-                if (icon == null) continue;
-                //閫�鍑轰箣鍓嶅厛绉婚櫎绯荤粺鎵樼洏鍥炬爣
-                if (APPID.equals(icon.getActionCommand())) {
-                    tray.remove(icon);
-                }
-            }
-        }
-        //閫�鍑�
-        Platform.exit();
+        addSubscribe(Observable.just(true)
+                .subscribeOn(Schedulers.newThread())
+                .observeOn(Schedulers.io())
+                .doOnNext(new Consumer<Object>() {
+                    @Override
+                    public void accept(Object o) throws Exception {
+                        if (isSyncing()) {
+                            stopSync();//鍋滄鍚屾
+                        }
+                    }
+                })
+                .doOnNext(new Consumer<Object>() {
+                    @Override
+                    public void accept(Object o) throws Exception {
+
+                        //妫�鏌ョ郴缁熸槸鍚︽敮鎸佹墭鐩�
+                        if (SystemTray.isSupported()) {
+                            //绯荤粺鎵樼洏
+                            SystemTray tray = SystemTray.getSystemTray();
+                            if (tray != null) {
+                                TrayIcon[] icons = tray.getTrayIcons();
+                                for (TrayIcon icon : icons) {
+                                    if (icon == null) continue;
+                                    //閫�鍑轰箣鍓嶅厛绉婚櫎绯荤粺鎵樼洏鍥炬爣
+                                    if (APPID.equals(icon.getActionCommand())) {
+                                        tray.remove(icon);
+                                    }
+                                }
+                            }
+                        }
+                    }
+                })
+                .subscribe(new Consumer<Boolean>() {
+                    @Override
+                    public void accept(Boolean aBoolean) throws Exception {
+
+                        TrayUtil.getInstance().exitApp();//閫�鍑�
+                    }
+                }, new Consumer<Throwable>() {
+                    @Override
+                    public void accept(Throwable e) throws Exception {
+                        e.printStackTrace();
+
+                        TrayUtil.getInstance().exitApp();//閫�鍑�
+                    }
+                }));
     }
+
 
     //鐐瑰嚮锛氬叧浜�
     private void clickAbout() {
@@ -392,7 +425,7 @@
                                 , targetFreq, freqSelect, startSync);
 
                         //鍐欏叆鏂囦欢
-                        String path = PathUtil.projectPath + "\\config.json";
+                        String path = PathUtil.getConfigFilePath("config.json");
                         String content = JsonUtil.toJson(cb);
 
                         //浣跨敤 BufferedWriter 鍐欐枃浠�
@@ -459,7 +492,7 @@
     //浠庢湰鍦伴厤缃枃浠朵腑鑾峰彇閰嶇疆淇℃伅
     private ConfigBean getSaveConfig() {
         try {
-            String json = FileUtil.bufferedReader(PathUtil.projectPath + "\\config.json");
+            String json = FileUtil.bufferedReader(PathUtil.getConfigFilePath("config.json"));
             return JsonUtil.fromJson(json, ConfigBean.class);
         } catch (Exception e) {
             e.printStackTrace();
@@ -481,7 +514,7 @@
         stage.setTitle("鍙傛暟璁剧疆");
         stage.setResizable(false);
         stage.setWidth(360);
-        stage.setMinHeight(180);
+        stage.setMinHeight(218);
         stage.getIcons().add(new Image("mipmap/ic_chinese_cabbage_48.png"));
         //APPLICATION_MODAL 鍏ㄥ眬妯℃�侊紝璇ョ獥鍙h繍琛屾椂锛屽叾浠栫獥鍙d笉鑳借繘琛屾搷浣�
         //WINDOW_MODAL 涓虹埗绐楀彛绂佺敤锛屽叾浠栫獥鍙e彲浠ヤ娇鐢�
@@ -501,6 +534,16 @@
         generalList.setPadding(new Insets(0, 20, 30, 20));
         generalList.setSpacing(4.0);
         generalList.getChildren().add(cbStartSync);
+
+        Label foot = new Label(String.format("* 鏇存敼灏嗕簬閲嶆柊鍚姩 %s 鍚庣敓鏁�", AppName));//"* 鏇存敼灏嗕簬閲嶆柊鍚姩 SyncTools 鍚庣敓鏁�");
+        foot.setAlignment(Pos.CENTER);
+        foot.setFont(new Font(12));
+
+        VBox content = new VBox();
+        content.setStyle("-fx-background-color: white");
+        content.setPadding(new Insets(20));
+        content.setSpacing(10);
+        content.getChildren().addAll(title, generalList, foot);
 
 
         Button defButton = new Button("纭畾");
@@ -537,9 +580,11 @@
                 saveConfigForIsStartSync(startSync, callback);
             }
         });
+
         Button cancelButton = new Button("鍙栨秷");
         cancelButton.setAlignment(Pos.CENTER);
         cancelButton.setPrefSize(84, 24);
+        cancelButton.setCancelButton(true);
         cancelButton.setOnAction(new EventHandler<ActionEvent>() {
 
             @Override
@@ -550,26 +595,16 @@
             }
         });
 
-        Label label = new Label(String.format("* 鏇存敼灏嗕簬閲嶆柊鍚姩 %s 鍚庣敓鏁�", AppName));//"* 鏇存敼灏嗕簬閲嶆柊鍚姩 SyncTools 鍚庣敓鏁�");
-        label.setAlignment(Pos.CENTER);
-        label.setFont(new Font(12));
-
-        VBox content = new VBox();
-        content.setStyle("-fx-background-color: white");
-        content.setPadding(new Insets(20));
-        content.setSpacing(10);
-        content.getChildren().addAll(title, generalList, label);
-
-
         HBox operate = new HBox();
         operate.setAlignment(Pos.CENTER_RIGHT);
         operate.setSpacing(8);
 //        operate.setStyle("-fx-background-color: #F0F0F0");
-        operate.setPadding(new Insets(12, 20, 6, 20));
+        operate.setPadding(new Insets(12, 20, 8, 20));
         operate.getChildren().addAll(defButton, cancelButton);
 
         VBox vBox = new VBox();
-        vBox.setSpacing(4.0);
+        vBox.setSpacing(0);
+        vBox.setPadding(getInsets());
         vBox.getChildren().addAll(content, operate);
 
         stage.setScene(new Scene(vBox));
@@ -856,7 +891,7 @@
                         }
                         cb.setStartSync(startSync);
 
-                        String path = PathUtil.projectPath + "\\config.json";
+                        String path = PathUtil.getConfigFilePath("config.json");
                         String content = JsonUtil.toJson(cb);
 
                         //浣跨敤 BufferedWriter 鍐欐枃浠�
@@ -894,7 +929,6 @@
                     @Override
                     public void accept(Object o) throws Exception {
                         String targetUrl = "jdbc:sqlserver://" + targetHost + ";databaseName=" + targetDbName + ";integratedSecurity=false;";
-                        String sql1 = "SELECT * FROM IOT_Equipment_Info WHERE IE_Type = 'XPH鐗╄仈缃戝叧'; ";//杩欓噷涓鸿緭鍏ョ殑SQL璇彞
                         List<String> keyList = new ArrayList<>();
 
                         //1.浠庣洰鏍囧簱鏌ュ嚭鏉ユ湁澶氬皯浼犳劅鍣ㄩ渶瑕佹煡鎵�
@@ -902,7 +936,7 @@
                              Statement stmt = con.createStatement()
                         ) {
 
-                            ResultSet rs = stmt.executeQuery(sql1);
+                            ResultSet rs = stmt.executeQuery(SQL1_QUERY);
                             while (rs.next()) {
                                 keyList.add(rs.getString("IE_Param"));
                             }
@@ -919,11 +953,10 @@
                         for (String key : keyList) {
                             StringUtil.append(sb, key, "','");
                         }
-                        String keyArray = String.format("'%s'", sb);
+                        String sql = String.format(SQL2_QUERY, sb);
 
                         String srcUrl = "jdbc:sqlserver://" + srcHost + ";databaseName=" + srcDbName + ";integratedSecurity=false;";
-                        String sql2 = "SELECT SD_Addr + '|' + SD_Code IE_Param, * FROM TY_SensorData WHERE SD_Key IN ( " + keyArray + " );";
-                        //System.out.println("sql:" + sql2);
+                        //System.out.println("sql2:" + sql);
 
                         Map<String, List<TargetBean>> map = new HashMap<>();
 
@@ -932,7 +965,7 @@
                              Statement stmt = con.createStatement()
                         ) {
                             List<TargetBean> list;
-                            ResultSet rs = stmt.executeQuery(sql2);
+                            ResultSet rs = stmt.executeQuery(sql);
                             while (rs.next()) {
                                 String key = rs.getString("SD_Key");
                                 String param = rs.getString("IE_Param");
@@ -962,23 +995,17 @@
                              Statement stmt3 = con3.createStatement()
                         ) {
                             //寰幆淇敼鏁版嵁
+                            Timestamp time = new Timestamp(System.currentTimeMillis());
+                            String version = String.format("%sV%s", AppName, VersionName);//"SyncToolsV1.0";
                             Set<Map.Entry<String, List<TargetBean>>> entrySet = map.entrySet();
                             for (Map.Entry<String, List<TargetBean>> entry : entrySet) {
-                                String key = entry.getKey();
                                 List<TargetBean> list = entry.getValue();
                                 if (list != null) {
-                                    Timestamp time = new Timestamp(System.currentTimeMillis());
-                                    String version = String.format("%sV%s", AppName, VersionName);//"SyncToolsV1.0";
+                                    String key = entry.getKey();
                                     for (TargetBean tb : list) {
                                         if (tb == null) continue;
 
-                                        String sql3 = "UPDATE IOT_Equipment_Info " +
-                                                "SET IE_Realtime_Data = ?, IE_Realtime_Time = ?, Edit_User = ?, Edit_Time = ? " +
-                                                "WHERE IE_Param = ? AND IE_Parent = ( " +
-                                                "SELECT IE_ID FROM IOT_Equipment_Info WHERE IE_Param = ? " +
-                                                ") ;";
-
-                                        PreparedStatement ps = con3.prepareStatement(sql3);
+                                        PreparedStatement ps = con3.prepareStatement(SQL3_UPDATE);
                                         ps.setString(1, tb.getData());
                                         ps.setTimestamp(2, tb.getTime());
                                         ps.setString(3, version);
@@ -1032,6 +1059,13 @@
     }
 
 
+    private Insets getInsets() {
+        if (SystemUtil.isWindows()) {
+            return new Insets(0, 0, -6, 0);
+        }
+        return new Insets(0);
+    }
+
     public boolean isSyncing() {
         return mSyncing;
     }

--
Gitblit v1.9.1