Quellcode durchsuchen

新增客户端版本更新功能

hou vor 3 Stunden
Ursprung
Commit
a06bb2125d

BIN
out/production/OP010/com/mes/ui/LoginFarme$1.class


BIN
out/production/OP010/com/mes/ui/LoginFarme$2.class


BIN
out/production/OP010/com/mes/ui/LoginFarme.class


+ 4 - 1
out/production/OP010/resources/config/config.properties

@@ -1,4 +1,7 @@
 mes.gw=OP010A
 mes.server_ip=127.0.0.1
 #mes.server_ip=192.168.16.99
-mes.line_sn=XT
+mes.line_sn=XT
+# ???????????JAR??????????????????? 0.0.0?
+# ???????????????????????????+1
+mes.client.version=0.0.0

+ 17 - 0
src/com/mes/ui/DataUtil.java

@@ -140,6 +140,7 @@ public class DataUtil {
     }
 
     public static String doPost(String httpUrl, String param) {
+        httpUrl = appendSid(httpUrl);
         HttpURLConnection connection = null;
         InputStream is = null;
         OutputStream os = null;
@@ -311,4 +312,20 @@ public class DataUtil {
         }
         return updateBy;
     }
+
+    private static String appendSid(String url) {
+        if (url == null || url.contains("__sid=") || url.contains("/login")) {
+            return url;
+        }
+        try {
+            String sid = MesClient.sessionid;
+            if (sid == null || sid.length() == 0) {
+                return url;
+            }
+            return url + (url.contains("?") ? "&" : "?") + "__sid=" + sid;
+        } catch (Exception e) {
+            return url;
+        }
+    }
+
 }

+ 3 - 0
src/com/mes/ui/LoginFarme.java

@@ -3,6 +3,7 @@ package com.mes.ui;
 import com.alibaba.fastjson2.JSONObject;
 import com.mes.component.MesRadio;
 import com.mes.component.MesWebView;
+import com.mes.util.ClientUpgrade;
 import com.mes.util.Base64Utils;
 import com.mes.util.HttpUtils;
 
@@ -91,6 +92,7 @@ public class LoginFarme extends JFrame {
 
     //登录
     public static void login() {
+        ClientUpgrade.checkIfConfigured(MesClient.welcomeWin);
         String user_str = userNameTxt.getText().toString();
         String password_str = userPasswordTxt.getText().toString();
         if(user_str.equalsIgnoreCase("")||password_str.equalsIgnoreCase("")) {
@@ -120,6 +122,7 @@ public class LoginFarme extends JFrame {
     }
     //扫码登录
     public static void scanLogin() {
+        ClientUpgrade.checkIfConfigured(MesClient.welcomeWin);
         //userNameTxt.setText("");
         //userPasswordTxt.setText("");
         String scanContent = JOptionPane.showInputDialog(null, "请扫码工牌二维码");

+ 20 - 1
src/com/mes/ui/MesClient.java

@@ -4,6 +4,8 @@ import com.alibaba.fastjson2.JSONObject;
 import com.mes.component.MesRadio;
 import com.mes.component.ProductTypePanel;
 import com.mes.component.MesWebView;
+import com.mes.util.ClientVersionUtils;
+import com.mes.util.ClientUpgrade;
 import com.mes.util.ConfigUtil;
 import com.mes.util.DateLocalUtils;
 import com.mes.util.HttpUtils;
@@ -36,7 +38,8 @@ public class MesClient extends JFrame {
     public static String mes_gw_des = ""; // 工位名称
     public static String mes_server_ip = ""; // 服务器IP地址
     public static int mes_heart_icon_cycle = 1;
-    public static String mes_line_sn = ""; // 产线编号
+    public static String mes_line_sn = "";
+    public static String client_version = "0.0.0"; // 打包发布版本,需和后台 JAR 管理版本号对齐 // 产线编号
 
     //session
     public static String sessionid = "";
@@ -89,6 +92,9 @@ public class MesClient extends JFrame {
     public static JLabel fxlabel;
 
     public static void main(String[] args) {
+        if (ClientUpgrade.handleInstallArgs(args)) {
+            return;
+        }
 
         if (LockUtil.getInstance().isAppActive() == true){
 //            JOptionPane.showMessageDialog(null, "已有一个程序在运行,程序退出");
@@ -100,6 +106,11 @@ public class MesClient extends JFrame {
                     try{
                         //读文件配置
                         readProperty();
+                        if (ClientUpgrade.recoverIncompleteInstall()) {
+                            return;
+                        }
+                        ClientUpgrade.cleanupInstallLeftovers();
+                        ClientUpgrade.checkIfConfigured(null);
 
                         // 显示界面
                         mesClientFrame = new MesClient();
@@ -121,6 +132,14 @@ public class MesClient extends JFrame {
     }
 
     //读配置文件
+
+    private static String parseClientVersion(String value) {
+        if (value == null || value.trim().isEmpty()) {
+            return "0.0.0";
+        }
+        return ClientVersionUtils.normalize(value.trim());
+    }
+
     private static void readProperty() throws IOException{
         Properties pro = ConfigUtil.loadProperties();
         mes_gw = pro.getProperty("mes.gw");

Datei-Diff unterdrückt, da er zu groß ist
+ 1091 - 0
src/com/mes/util/ClientUpgrade.java


+ 75 - 0
src/com/mes/util/ClientVersionUtils.java

@@ -0,0 +1,75 @@
+package com.mes.util;
+
+/**
+ * 客户端版本号比较,格式 0.0.0 / 0.0.1。
+ * 没有点的旧数字(如 1)按 0.0.1 处理。
+ */
+public final class ClientVersionUtils {
+
+    private ClientVersionUtils() {
+    }
+
+    public static int compare(String left, String right) {
+        int[] a = parse(left);
+        int[] b = parse(right);
+        int n = Math.max(a.length, b.length);
+        for (int i = 0; i < n; i++) {
+            int va = i < a.length ? a[i] : 0;
+            int vb = i < b.length ? b[i] : 0;
+            if (va != vb) {
+                return va < vb ? -1 : 1;
+            }
+        }
+        return 0;
+    }
+
+    public static boolean isNewer(String latest, String current) {
+        return compare(latest, current) > 0;
+    }
+
+    public static String max(String left, String right) {
+        if (isBlank(left)) {
+            return normalize(right);
+        }
+        if (isBlank(right)) {
+            return normalize(left);
+        }
+        return compare(left, right) >= 0 ? normalize(left) : normalize(right);
+    }
+
+    public static String normalize(String version) {
+        if (isBlank(version)) {
+            return "0.0.0";
+        }
+        int[] parts = parse(version);
+        return parts[0] + "." + parts[1] + "." + parts[2];
+    }
+
+    private static int[] parse(String version) {
+        int[] result = new int[] {0, 0, 0};
+        if (isBlank(version)) {
+            return result;
+        }
+        String[] parts = version.trim().split("\\.");
+        if (parts.length == 1) {
+            result[2] = parseInt(parts[0]);
+            return result;
+        }
+        for (int i = 0; i < parts.length && i < 3; i++) {
+            result[i] = parseInt(parts[i]);
+        }
+        return result;
+    }
+
+    private static int parseInt(String value) {
+        try {
+            return Integer.parseInt(value.trim());
+        } catch (Exception e) {
+            return 0;
+        }
+    }
+
+    private static boolean isBlank(String value) {
+        return value == null || value.trim().length() == 0;
+    }
+}

+ 21 - 0
src/com/mes/util/HttpUtils.java

@@ -1,5 +1,7 @@
 package com.mes.util;
 
+import com.mes.ui.MesClient;
+
 import java.io.*;
 import java.net.HttpURLConnection;
 import java.net.URISyntaxException;
@@ -13,6 +15,7 @@ public class HttpUtils {
 	 */
     //http post请求
     public static String sendRequest(String urlParam) {
+        urlParam = appendSid(urlParam);
 		String requestType = "POST";
         //根据接收内容返回数据结果
     	String ret = "";
@@ -66,6 +69,7 @@ public class HttpUtils {
 
 
     public static String sendPostRequest(String urlParam, String params) {
+        urlParam = appendSid(urlParam);
         String requestType = "POST";
         //根据接收内容返回数据结果
         String ret = "";
@@ -124,6 +128,7 @@ public class HttpUtils {
     }
 
     public static String sendPostRequestJson(String apiUrl, String jsonData) throws IOException {
+        apiUrl = appendSid(apiUrl);
         URL url = new URL(apiUrl);
         HttpURLConnection conn = (HttpURLConnection) url.openConnection();
         conn.setRequestMethod("POST");
@@ -154,4 +159,20 @@ public class HttpUtils {
         return response.toString();
     }
 
+
+    private static String appendSid(String url) {
+        if (url == null || url.contains("__sid=") || url.contains("/login")) {
+            return url;
+        }
+        try {
+            String sid = MesClient.sessionid;
+            if (sid == null || sid.length() == 0) {
+                return url;
+            }
+            return url + (url.contains("?") ? "&" : "?") + "__sid=" + sid;
+        } catch (Exception e) {
+            return url;
+        }
+    }
+
 }

+ 6 - 3
src/resources/config/config.properties

@@ -1,4 +1,7 @@
 mes.gw=OP010A
-#mes.server_ip=127.0.0.1
-mes.server_ip=192.168.16.99
-mes.line_sn=XT
+mes.server_ip=127.0.0.1
+#mes.server_ip=192.168.16.99
+mes.line_sn=XT
+# ???????????JAR??????????????????? 0.0.0?
+# ???????????????????????????+1
+mes.client.version=0.0.0