From 60a3f2bc64b7a5f502e4133ced31f0b25c88d3f1 Mon Sep 17 00:00:00 2001
From: Hunter0x7c7 <1125607007@qq.com>
Date: 星期四, 12 九月 2024 14:57:03 +0800
Subject: [PATCH] 版本v1.0.2(3)发布。
---
src/main/java/com/github/hunter0x7c7/sync/ctrls/Controller.java | 490 ++++++++++++++++++++++++++++++++++++------------------
1 files changed, 325 insertions(+), 165 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..c2d1428 100644
--- a/src/main/java/com/github/hunter0x7c7/sync/ctrls/Controller.java
+++ b/src/main/java/com/github/hunter0x7c7/sync/ctrls/Controller.java
@@ -7,13 +7,17 @@
import com.github.hunter0x7c7.sync.model.storage.Session;
import com.github.hunter0x7c7.sync.utils.*;
import io.reactivex.Observable;
-import io.reactivex.ObservableSource;
+import io.reactivex.Observer;
+import io.reactivex.*;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Function;
+import io.reactivex.functions.Predicate;
import io.reactivex.schedulers.Schedulers;
import javafx.application.Platform;
+import javafx.beans.value.ChangeListener;
+import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
@@ -35,13 +39,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,12 +50,37 @@
import static com.github.hunter0x7c7.sync.model.global.Parameters.*;
public class Controller {
+ //1. 鍦ㄧ洰鏍囧簱锛屾妸閲囬泦绫荤綉鍏宠澶囧厛鎵惧嚭鏉�
+ public static final String SQL_QUERY_TARGET = "SELECT * " +
+ "FROM IOT_Equipment_Info " +
+ "WHERE IE_Type = '鐗╄仈缃戝叧' " +
+ "OR IE_Type = 'XPH缃戝叧' " +
+ "OR IE_Type = 'XPH鐗╄仈缃戝叧' " +
+ "OR IE_Type = '姘旇薄绔欑綉鍏�' " +
+ "OR IE_Type = '閲囬泦鐗╄仈缃戝叧' " +//娓╁閲囬泦鏈烘煖
+ "OR IE_Type = '铏儏鐩戞祴缃戝叧' " +
+ "OR IE_Type = '澧掓儏缃戝叧' " +
+ "OR IE_Type = '杩滀紶姘磋〃'; ";
+
+ //2. 鍦ㄦ簮鏁版嵁搴擄紝鎶婄浉鍏崇綉鍏宠澶囩殑瀛愯鏌ユ壘鍑烘潵锛屾嫾鎺ュソParam鍙傛暟00|01
+ public static final String SQL_QUERY_SRC = "SELECT SD_Addr + '|' + SD_Code IE_Param, * " +
+ "FROM TY_SensorData " +
+ "WHERE SD_Key IN ( '%s' ); ";
+ //3. 鍦ㄧ洰鏍囧簱锛屾妸鍖归厤鐨勬渶鏂版暟鎹洿鏂板埌鐩稿叧鐨勮涓�
+ public static final String SQL_UPDATE_TARGET = "UPDATE IOT_Equipment_Info " +
+ "SET IE_Realtime_Data = ?, IE_Realtime_Time = ?, Edit_User = ?, Edit_Time = ? " +
+ "WHERE IE_Param = ? " +
+ "AND IE_Parent IN ( " +
+ "SELECT IE_ID " +
+ "FROM IOT_Equipment_Info " +
+ "WHERE IE_Param = ? ) ;";
+
@FXML
private TextField tvInputSrcHost;
@FXML
private TextField tvInputSrcName;
@FXML
- private PasswordField tvInputSrcPwd;
+ private TextField tvInputSrcPwd;
@FXML
private TextField tvInputSrcDbName;
@@ -67,7 +89,7 @@
@FXML
private TextField tvInputTargetName;
@FXML
- private PasswordField tvInputTargetPwd;
+ private TextField tvInputTargetPwd;
@FXML
private TextField tvInputTargetDbName;
@FXML
@@ -96,7 +118,12 @@
private CompositeDisposable mCompositeDisposable;
//鍚屾棰戠巼鍗曚綅鍒楄〃
- private static final TimeUnit[] mFreqUnitList = {TimeUnit.MILLISECONDS, TimeUnit.SECONDS, TimeUnit.MINUTES, TimeUnit.HOURS, TimeUnit.DAYS};
+ private static final TimeUnit[] mFreqUnitList = {
+ TimeUnit.MILLISECONDS,
+ TimeUnit.SECONDS,
+ TimeUnit.MINUTES,
+ TimeUnit.HOURS,
+ TimeUnit.DAYS};
//鍚屾棰戠巼鍗曚綅鍚嶇О鍒楄〃
private static final String[] mFreqNameList = {"姣", "绉�", "鍒嗛挓", "灏忔椂", "澶�"};
//鍚屾娆℃暟
@@ -112,10 +139,10 @@
}
- @Override
+ /*@Override
protected void finalize() throws Throwable {
super.finalize();
- }
+ }*/
private void init() {
mCompositeDisposable = new CompositeDisposable();
@@ -175,14 +202,20 @@
public void accept(Object o) throws Exception {
//娣诲姞鍒扮郴缁熸墭鐩�
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 tooltip = String.format("%s v%s", AppName, VersionName);//SyncTools v1.0
+ String mipmap = "mipmap/ic_chinese_cabbage_16.png";
MenuItem show = new MenuItem("鏄剧ず");//鏄剧ずShow
//缁戝畾绯荤粺鎵樼洏浜嬩欢
show.addActionListener(actionListener -> {
Platform.runLater(() -> {
if (primaryStage != null) {
- primaryStage.show();
+ if (primaryStage.isIconified()) {//鏈�灏忓寲
+ primaryStage.setIconified(false);
+ }
+ if (!primaryStage.isShowing()) {
+ primaryStage.show();
+ }
+ primaryStage.toFront();
}
});
});
@@ -195,77 +228,127 @@
}
};
//娣诲姞鍒扮郴缁熸墭鐩�
- TrayUtil.getInstance().addSystemTray(primaryStage, AppNameString, mipmap, callback, show);
- }
- }).doOnNext(new Consumer<Object>() {
- @Override
- public void accept(Object o) throws Exception {
- //鍒濆鍖栧凡淇濆瓨鐨勯厤缃俊鎭�
- ConfigBean cb = getSaveConfig();
- if (cb != null) {
- //UI绾跨▼
- Platform.runLater(new Runnable() {
- @Override
- public void run() {
- setInputText(tvInputSrcHost, cb.getSrcHost());
- setInputText(tvInputSrcName, cb.getSrcName());
- setInputText(tvInputSrcPwd, getDecryptData(cb.getSrcPwd()));
- setInputText(tvInputSrcDbName, cb.getSrcDbName());
- setInputText(tvInputTargetHost, cb.getTargetHost());
- setInputText(tvInputTargetName, cb.getTargetName());
- setInputText(tvInputTargetPwd, getDecryptData(cb.getTargetPwd()));
- setInputText(tvInputTargetDbName, cb.getTargetDbName());
- setInputText(tvInputFreq, cb.getFreqValue());
- cbSelectFreqUnit.getSelectionModel().select(cb.getFreqUnit());
+ TrayUtil.getInstance().addSystemTray(primaryStage, AppName_zh_rCN, mipmap, callback, show);
+
+ //鏈�灏忓寲涔嬪悗锛屽叧闂獥鍙�
+ primaryStage.iconifiedProperty().addListener(new ChangeListener<Boolean>() {
+ @Override
+ public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
+ //濡傛灉浣犳墽琛屼簡setIconified(true)涔嬪悗鍐嶆墽琛宧ide(),
+ // stage浼氳閿�姣�,鍥犳闇�瑕佸湪绐楀彛鍏抽棴鍓嶅皢Iconified璁句负false
+ if (!oldValue && newValue) {
+ //鏈�灏忓寲涔嬪悗锛屽叧闂獥鍙�
+ if (primaryStage != null) {
+ primaryStage.close();
+ }
}
- });
-
- //榛樿鍚姩鍚屾鍔熻兘
- if (cb.isStartSync()) {
- startSync(); //鍚姩鍚屾鍔熻兘
}
- } else if (BuildType.equals(BuildTypeEnum.DEBUG)) {
- try {
- String srcHost = ConfigProperties.SRC_HOST;
- String srcName = ConfigProperties.SRC_NAME;
- String srcPwd = ConfigProperties.SRC_PWD;
- String srcDbName = ConfigProperties.SRC_DB_NAME;
+ });
+ }
+ }).concatMap(new Function<Object, Observable<ConfigBean>>() {//鍑嗗鍒濆鍖栫殑閰嶇疆鏁版嵁
+ @Override
+ public Observable<ConfigBean> apply(Object o) throws Exception {
+ //鍒濆鍖栧凡淇濆瓨鐨勯厤缃俊鎭�
+ final ConfigBean configBean = getSaveConfig();
+ return Observable.just(configBean != null)
+ .subscribeOn(Schedulers.io())
+ .filter(new Predicate<Boolean>() {
+ @Override
+ public boolean test(Boolean aBoolean) throws Exception {
+ //return false杩囨护, true涓嶈繃婊ゃ�俧alse绔嬪埢鎵цswitchIfEmpty
+ return aBoolean != null && aBoolean;
+ }
+ }).map(new Function<Boolean, ConfigBean>() {
+ @Override
+ public ConfigBean apply(Boolean aBoolean) throws Exception {
+ assert configBean != null;
+ configBean.setSrcPwd(getDecryptData(configBean.getSrcPwd()));
+ configBean.setTargetPwd(getDecryptData(configBean.getTargetPwd()));
+ return configBean;
+ }
+ }).switchIfEmpty(new Observable<ConfigBean>() {
+ @Override
+ protected void subscribeActual(Observer<? super ConfigBean> observer) {
+ //濡傛灉鏄疍ebug鐜鎵嶅垵濮嬪寲娴嬭瘯鏁版嵁
+ if (BuildType.equals(BuildTypeEnum.DEBUG)) {
+ String srcHost = ConfigProperties.SRC_HOST;
+ String srcName = ConfigProperties.SRC_NAME;
+ String srcPwd = ConfigProperties.SRC_PWD;
+ String srcDbName = ConfigProperties.SRC_DB_NAME;
- String targetHost = ConfigProperties.TARGET_HOST;
- String targetName = ConfigProperties.TARGET_NAME;
- String targetPwd = ConfigProperties.TARGET_PWD;
- String targetDbName = ConfigProperties.TARGET_DB_NAME;
+ String targetHost = ConfigProperties.TARGET_HOST;
+ String targetName = ConfigProperties.TARGET_NAME;
+ String targetPwd = ConfigProperties.TARGET_PWD;
+ String targetDbName = ConfigProperties.TARGET_DB_NAME;
+ String freqValue = "5";
+ int freqUnitIndex = 1;//绉�
+
+ ConfigBean cb = new ConfigBean(srcHost, srcName, srcPwd, srcDbName, targetHost, targetName, targetPwd, targetDbName, freqValue, freqUnitIndex, false);
+
+ if (observer != null) {
+ observer.onNext(cb);
+ observer.onComplete();
+ }
+ } else {
+ if (observer != null) {
+ observer.onNext(new ConfigBean());
+ observer.onComplete();
+ }
+ }
+ }
+ });
+ }
+ }).concatMap(new Function<ConfigBean, ObservableSource<ConfigBean>>() {//鏇存柊閰嶇疆鏁版嵁鍒扮晫闈�
+ @Override
+ public ObservableSource<ConfigBean> apply(final ConfigBean cb) throws Exception {
+ //鏁版嵁涓虹┖锛屼笉鏇存柊鐣岄潰
+ if (cb == null) {
+ return Observable.just(new ConfigBean());
+ }
+ //鏇存柊鐣岄潰
+ return Observable.create(new ObservableOnSubscribe<ConfigBean>() {
+ @Override
+ public void subscribe(ObservableEmitter<ConfigBean> emitter) throws Exception {
//UI绾跨▼
Platform.runLater(new Runnable() {
@Override
public void run() {
- setInputText(tvInputSrcHost, srcHost);
- setInputText(tvInputSrcName, srcName);
- setInputText(tvInputSrcPwd, srcPwd);
- setInputText(tvInputSrcDbName, srcDbName);
- setInputText(tvInputTargetHost, targetHost);
- setInputText(tvInputTargetName, targetName);
- setInputText(tvInputTargetPwd, targetPwd);
- setInputText(tvInputTargetDbName, targetDbName);
- setInputText(tvInputFreq, "10");
- cbSelectFreqUnit.getSelectionModel().select(1);
+ //鏇存柊鐣岄潰鏁版嵁
+ setInputText(tvInputSrcHost, cb.getSrcHost());
+ setInputText(tvInputSrcName, cb.getSrcName());
+ setInputText(tvInputSrcPwd, cb.getSrcPwd());
+ setInputText(tvInputSrcDbName, cb.getSrcDbName());
+ setInputText(tvInputTargetHost, cb.getTargetHost());
+ setInputText(tvInputTargetName, cb.getTargetName());
+ setInputText(tvInputTargetPwd, cb.getTargetPwd());
+ setInputText(tvInputTargetDbName, cb.getTargetDbName());
+ setInputText(tvInputFreq, cb.getFreqValue());
+ cbSelectFreqUnit.getSelectionModel().select(cb.getFreqUnit());
+
+ if (emitter != null) {
+ emitter.onNext(cb);
+ emitter.onComplete();
+ }
}
});
- } catch (Exception e) {
- throw new RuntimeException(e);
}
- }
+ });
}
- }).subscribe(new Consumer<Object>() {
+ }).subscribe(new Consumer<ConfigBean>() {
@Override
- public void accept(Object o) throws Exception {
+ public void accept(ConfigBean cb) throws Exception {
//UI绾跨▼
Platform.runLater(new Runnable() {
@Override
public void run() {
updateResult("鏁版嵁鍚屾宸ュ叿");
+
+ //榛樿鍚姩鍚屾鍔熻兘
+ if (cb != null && cb.isStartSync()) {
+ startSync(); //鍚姩鍚屾鍔熻兘
+ }
}
});
}
@@ -336,24 +419,66 @@
//鐐瑰嚮锛氶��鍑�
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();
+ Disposable d = Observable.just(true)
+ .subscribeOn(Schedulers.newThread())
+ .observeOn(Schedulers.io())
+ .doOnNext(new Consumer<Object>() {
+ @Override
+ public void accept(Object o) throws Exception {
+ //1. 鍋滄鍚屾
+ if (isSyncing()) {
+ stopSync();//鍋滄鍚屾
+ }
+ }
+ })
+ .concatMap(new Function<Object, ObservableSource<Object>>() {
+ @Override
+ public ObservableSource<Object> apply(Object o) throws Exception {
+ //2. 绉婚櫎绯荤粺鎵樼洏
+ return Observable.create(new ObservableOnSubscribe<Object>() {
+ @Override
+ public void subscribe(ObservableEmitter<Object> emitter) throws Exception {
+ //妫�鏌ョ郴缁熸槸鍚︽敮鎸佹墭鐩�
+ if (SystemTray.isSupported()) {
+ //閫�鍑轰箣鍓嶅厛绉婚櫎绯荤粺鎵樼洏鍥炬爣
+ final SystemTray tray = SystemTray.getSystemTray();//绯荤粺鎵樼洏
+ final TrayIcon icon = getTrayIcon(tray, APPID);
+ Platform.runLater(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ //绉婚櫎绯荤粺鎵樼洏
+ tray.remove(icon);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ if (emitter != null) {
+ emitter.onNext(o);
+ emitter.onComplete();
+ }
+ }
+ });
+ }
+ }
+ });
+ }
+ })
+ .subscribe(new Consumer<Object>() {
+ @Override
+ public void accept(Object o) throws Exception {
+ //3. 鍋滄鍚屾鍜岀Щ闄ょ郴缁熸墭鐩樺悗锛岄��鍑虹▼搴�
+ TrayUtil.getInstance().exitApp();//閫�鍑�
+ }
+ }, new Consumer<Throwable>() {
+ @Override
+ public void accept(Throwable e) throws Exception {
+ e.printStackTrace();
+
+ TrayUtil.getInstance().exitApp();//閫�鍑�
+ }
+ });
}
+
//鐐瑰嚮锛氬叧浜�
private void clickAbout() {
@@ -392,7 +517,7 @@
, targetFreq, freqSelect, startSync);
//鍐欏叆鏂囦欢
- String path = PathUtil.projectPath + "\\config.json";
+ String path = PathUtil.getConfigFilePath("config.json");
String content = JsonUtil.toJson(cb);
//浣跨敤 BufferedWriter 鍐欐枃浠�
@@ -429,11 +554,21 @@
//鐐瑰嚮锛氬仠姝㈠悓姝�
private void clickStopSync() {
- if (isSyncing()) {
- stopSync();//鍋滄鍚屾
- } else {
- updateResult("鏈惎鍔ㄥ悓姝ュ姛鑳斤紒");
+ stopSync();//鍋滄鍚屾
+ }
+
+ public TrayIcon getTrayIcon(SystemTray tray, String key) {
+ if (tray != null && key != null) {
+ TrayIcon[] icons = tray.getTrayIcons();
+ for (TrayIcon icon : icons) {
+ if (icon == null) continue;
+ //鎵惧埌鎸囧畾鐨勬墭鐩樺浘鏍�
+ if (key.equals(icon.getActionCommand())) {
+ return icon;
+ }
+ }
}
+ return null;
}
//瑙e瘑
@@ -459,7 +594,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 +616,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 +636,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 +682,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 +697,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, 12, 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));
@@ -619,7 +756,7 @@
VBox vBox = new VBox();
- vBox.setPadding(new Insets(20, 20, 4, 20));
+ vBox.setPadding(new Insets(20, 20, 10, 20));
vBox.getChildren().addAll(label1, label2, label3, label4);
stage.setScene(new Scene(vBox));
@@ -677,7 +814,10 @@
//鍚姩鍚屾鍔熻兘
private void startSync() {
mSyncCount = 0;
+ setInputText(txSyncStatus, "鍚姩涓�");
setInputText(txSyncCount, String.valueOf(mSyncCount));
+ setInputText(txStartSyncTime, "-");
+ setInputText(txLastSyncTime, "-");
final String srcHost = getInputText(tvInputSrcHost);
final String srcName = getInputText(tvInputSrcName);
@@ -732,14 +872,18 @@
.doOnNext(new Consumer<Object>() {
@Override
public void accept(Object o) throws Exception {
- //UI绾跨▼
+ setInputText(txStartSyncTime, DateUtils.formatDate(new Date()));
updateResult("杩炴帴涓�...");
+ btnStartSync.setDisable(true);
+ btnStopSync.setDisable(false);
}
})
.observeOn(Schedulers.newThread())
.concatMap(new Function<String, ObservableSource<String>>() {
@Override
public ObservableSource<String> apply(String targetFreq) throws Exception {
+ mSyncCount = 0;
+ setSyncing(true);
return getStartSyncObservable(srcHost, srcName, srcPwd, srcDbName, targetHost, targetName, targetPwd, targetDbName)
.map(new Function<String, String>() {
@Override
@@ -753,20 +897,18 @@
@Override
public void accept(Object o) throws Exception {
//鍚姩鎴愬姛
- setSyncing(true);
- mSyncCount++;
- if (mSyncCount >= Integer.MAX_VALUE) {
- mSyncCount = 0;
+ if (isSyncing()) {
+ mSyncCount++;
+ if (mSyncCount >= Integer.MAX_VALUE) {
+ mSyncCount = 0;
+ }
+ setInputText(txLastSyncTime, DateUtils.formatDate(new Date()));
+ setInputText(txSyncCount, String.valueOf(mSyncCount));
+ setInputText(txSyncStatus, "鍚屾涓�");
+ updateResult("鍚姩鎴愬姛锛�");
+ btnStartSync.setDisable(true);
+ btnStopSync.setDisable(false);
}
- setInputText(txLastSyncTime, DateUtils.formatDate(new Date()));
- setInputText(txSyncCount, String.valueOf(mSyncCount));
-
- btnStartSync.setDisable(true);
- btnStopSync.setDisable(false);
-
- setInputText(txSyncStatus, "鍚屾涓�");
- setInputText(txStartSyncTime, DateUtils.formatDate(new Date()));
- updateResult("鍚姩鎴愬姛锛�");
}
})
.map(new Function<String, Integer>() {
@@ -779,9 +921,9 @@
}
}
})
- .concatMap(new Function<Integer, ObservableSource<String>>() {
+ .concatMap(new Function<Integer, ObservableSource<Object>>() {
@Override
- public ObservableSource<String> apply(Integer freq) throws Exception {
+ public ObservableSource<Object> apply(Integer freq) throws Exception {
int delay = freq > 0 ? freq : 10;
TimeUnit timeUnit = ListUtil.getDataByList(mFreqUnitList, freqSelect);
@@ -789,16 +931,40 @@
//System.out.println("delay:" + delay + " unit:" + unit);
return Observable.timer(delay, unit)
- /*.doOnNext(new Consumer<Long>() {
+ .doOnNext(new Consumer<Long>() {
@Override
public void accept(Long aLong) throws Exception {
- startSync(srcHost, srcName, srcPwd, srcDbName, targetHost, targetName, targetPwd, targetDbName);
+ //濡傛灉涓�旀煇娆℃墽琛屽け璐ワ紝涓嶈兘瀵艰嚧鏁翠釜璁″垝鐨勫け璐�
+ addSubscribe(getStartSyncObservable(srcHost, srcName, srcPwd, srcDbName, targetHost, targetName, targetPwd, targetDbName)
+ .subscribe(new Consumer<Object>() {
+ @Override
+ public void accept(Object o) throws Exception {
+ //鍚屾鎴愬姛锛�
+ if (isSyncing()) {
+ mSyncCount++;
+ if (mSyncCount >= Integer.MAX_VALUE) {
+ mSyncCount = 0;
+ }
+ setInputText(txLastSyncTime, DateUtils.formatDate(new Date()));
+ setInputText(txSyncCount, String.valueOf(mSyncCount));
+ updateResult("鍚屾鎴愬姛锛�");
+ btnStartSync.setDisable(true);
+ btnStopSync.setDisable(false);
+ }
+ }
+ }, new Consumer<Throwable>() {
+ @Override
+ public void accept(Throwable e) throws Exception {
+ e.printStackTrace();
+ //鎵ц澶辫触
+ updateResult(e.getMessage());
+ }
+ }));
}
- })*/
- .concatMap(new Function<Long, ObservableSource<String>>() {
+ }).map(new Function<Long, Object>() {
@Override
- public ObservableSource<String> apply(Long o) throws Exception {
- return getStartSyncObservable(srcHost, srcName, srcPwd, srcDbName, targetHost, targetName, targetPwd, targetDbName);
+ public Object apply(Long aLong) throws Exception {
+ return String.valueOf(aLong);
}
}).repeat();
}
@@ -807,37 +973,30 @@
.subscribe(new Consumer<Object>() {
@Override
public void accept(Object o) throws Exception {
- setSyncing(true);
- mSyncCount++;
- if (mSyncCount >= Integer.MAX_VALUE) {
- mSyncCount = 0;
- }
- setInputText(txLastSyncTime, DateUtils.formatDate(new Date()));
- setInputText(txSyncCount, String.valueOf(mSyncCount));
- updateResult("鍚屾鎴愬姛锛�");
+ //娴佺▼鎵ц瀹屾瘯
}
}, new Consumer<Throwable>() {
@Override
- public void accept(Throwable throwable) throws Exception {
- throwable.printStackTrace();
-
- updateResult(throwable.getMessage());
+ public void accept(Throwable e) throws Exception {
+ e.printStackTrace();
+ //鎵ц澶辫触
+ updateResult(e.getMessage());
}
}));
}
//鍋滄鍚屾
private void stopSync() {
+ setSyncing(false);
+ mSyncCount = 0;
if (mCompositeDisposable != null) {
- mCompositeDisposable.clear();
+ mCompositeDisposable.clear();//娉ㄦ剰锛氫細鎶婃墍鏈夋搷浣滈兘鍙栨秷
}
+ setInputText(txSyncStatus, "宸插仠姝�");
+ updateResult("鍚屾鍋滄锛�");
btnStartSync.setDisable(false);
btnStopSync.setDisable(true);
-
- setSyncing(false);
- setInputText(txSyncStatus, "宸插仠姝�");
- updateResult("鍋滄鎴愬姛锛�");
}
//淇濆瓨 鍦ㄥ惎鍔ㄦ椂鈥濆惎鍔ㄢ�滃悓姝ュ姛鑳�
@@ -856,7 +1015,7 @@
}
cb.setStartSync(startSync);
- String path = PathUtil.projectPath + "\\config.json";
+ String path = PathUtil.getConfigFilePath("config.json");
String content = JsonUtil.toJson(cb);
//浣跨敤 BufferedWriter 鍐欐枃浠�
@@ -893,8 +1052,8 @@
.doOnNext(new Consumer<Object>() {
@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璇彞
+ String urlString = "jdbc:sqlserver://%s;databaseName=%s;integratedSecurity=false;";
+ String targetUrl = String.format(urlString, targetHost, targetDbName);
List<String> keyList = new ArrayList<>();
//1.浠庣洰鏍囧簱鏌ュ嚭鏉ユ湁澶氬皯浼犳劅鍣ㄩ渶瑕佹煡鎵�
@@ -902,7 +1061,7 @@
Statement stmt = con.createStatement()
) {
- ResultSet rs = stmt.executeQuery(sql1);
+ ResultSet rs = stmt.executeQuery(SQL_QUERY_TARGET);
while (rs.next()) {
keyList.add(rs.getString("IE_Param"));
}
@@ -919,11 +1078,10 @@
for (String key : keyList) {
StringUtil.append(sb, key, "','");
}
- String keyArray = String.format("'%s'", sb);
+ String sql = String.format(SQL_QUERY_SRC, 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);
+ String srcUrl = String.format(urlString, srcHost, srcDbName);
+ //System.out.println("sql2:" + sql);
Map<String, List<TargetBean>> map = new HashMap<>();
@@ -932,7 +1090,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 +1120,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(SQL_UPDATE_TARGET);
ps.setString(1, tb.getData());
ps.setTimestamp(2, tb.getTime());
ps.setString(3, version);
@@ -1027,11 +1179,19 @@
}
private void updateResult(String str) {
- System.out.println(str);
+ //杈撳嚭缁撴灉甯︽椂闂�
+ System.out.printf("%s\t%s%n", DateUtils.formatDate(new Date()), str);
setInputText(txOutResult, str);
}
+ 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