| | |
| | | |
| | | 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; |
| | |
| | | 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 |
| | |
| | | } |
| | | |
| | | |
| | | @Override |
| | | /*@Override |
| | | protected void finalize() throws Throwable { |
| | | super.finalize(); |
| | | } |
| | | }*/ |
| | | |
| | | private void init() { |
| | | mCompositeDisposable = new CompositeDisposable(); |
| | |
| | | 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; |
| | |
| | | |
| | | //点击:退出 |
| | | 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() { |
| | |
| | | , targetFreq, freqSelect, startSync); |
| | | |
| | | //写入文件 |
| | | String path = PathUtil.projectPath + "\\config.json"; |
| | | String path = PathUtil.getConfigFilePath("config.json"); |
| | | String content = JsonUtil.toJson(cb); |
| | | |
| | | //使用 BufferedWriter 写文件 |
| | |
| | | //从本地配置文件中获取配置信息 |
| | | 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(); |
| | |
| | | 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 全局模态,该窗口运行时,其他窗口不能进行操作 |
| | | //WINDOW_MODAL 为父窗口禁用,其他窗口可以使用 |
| | |
| | | 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("确定"); |
| | |
| | | saveConfigForIsStartSync(startSync, callback); |
| | | } |
| | | }); |
| | | |
| | | Button cancelButton = new Button("取消"); |
| | | cancelButton.setAlignment(Pos.CENTER); |
| | | cancelButton.setPrefSize(84, 24); |
| | | cancelButton.setCancelButton(true); |
| | | cancelButton.setOnAction(new EventHandler<ActionEvent>() { |
| | | |
| | | @Override |
| | |
| | | } |
| | | }); |
| | | |
| | | 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)); |
| | |
| | | } |
| | | cb.setStartSync(startSync); |
| | | |
| | | String path = PathUtil.projectPath + "\\config.json"; |
| | | String path = PathUtil.getConfigFilePath("config.json"); |
| | | String content = JsonUtil.toJson(cb); |
| | | |
| | | //使用 BufferedWriter 写文件 |
| | |
| | | @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.从目标库查出来有多少传感器需要查找 |
| | |
| | | Statement stmt = con.createStatement() |
| | | ) { |
| | | |
| | | ResultSet rs = stmt.executeQuery(sql1); |
| | | ResultSet rs = stmt.executeQuery(SQL1_QUERY); |
| | | while (rs.next()) { |
| | | keyList.add(rs.getString("IE_Param")); |
| | | } |
| | |
| | | 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<>(); |
| | | |
| | |
| | | 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"); |
| | |
| | | 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); |
| | |
| | | } |
| | | |
| | | |
| | | private Insets getInsets() { |
| | | if (SystemUtil.isWindows()) { |
| | | return new Insets(0, 0, -10, 0); |
| | | } |
| | | return new Insets(0); |
| | | } |
| | | |
| | | public boolean isSyncing() { |
| | | return mSyncing; |
| | | } |