| | |
| | | |
| | | 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(); |
| | |
| | | //添加到系统托盘 |
| | | 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 -> { |
| | |
| | | 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(); |
| | |
| | | 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(); |
| | |
| | | } |
| | | 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); |