Browse Source

初始化

jingbo 1 tuần trước cách đây
commit
a734a7538f
100 tập tin đã thay đổi với 3354 bổ sung0 xóa
  1. 25 0
      .classpath
  2. 8 0
      .gitignore
  3. 28 0
      .project
  4. BIN
      FCN逆变储能焊机控制器说明书(1)(1).pdf
  5. BIN
      Modbus RTU通讯说明-OP030-8.docx
  6. 2 0
      image/.gitignore
  7. BIN
      image/background.png
  8. BIN
      image/bg/a_side.png
  9. BIN
      image/bg/b_side.png
  10. BIN
      image/bg/bar_add.png
  11. BIN
      image/bg/bar_bookmark.png
  12. BIN
      image/bg/bar_cmd_go.png
  13. BIN
      image/bg/bar_edit.png
  14. BIN
      image/bg/bar_pause.png
  15. BIN
      image/bg/bar_sampling.png
  16. BIN
      image/bg/bar_setting.png
  17. BIN
      image/bg/bar_stop.png
  18. BIN
      image/bg/close_bt.png
  19. BIN
      image/bg/company_setting_logo.png
  20. BIN
      image/bg/delete.png
  21. BIN
      image/bg/department_setting_logo.png
  22. BIN
      image/bg/download.png
  23. BIN
      image/bg/equipment_setting_logo.png
  24. BIN
      image/bg/gj_001_1_20.png
  25. BIN
      image/bg/gj_001_21_40.png
  26. BIN
      image/bg/gj_001_41_60.png
  27. BIN
      image/bg/green_dot.png
  28. BIN
      image/bg/grey_dot.png
  29. BIN
      image/bg/icon.png
  30. BIN
      image/bg/inductance_logo.png
  31. BIN
      image/bg/insulation_logo.png
  32. BIN
      image/bg/login.png
  33. BIN
      image/bg/logo.png
  34. BIN
      image/bg/logoff.png
  35. BIN
      image/bg/menu_data_analysis.png
  36. BIN
      image/bg/menu_data_preprocess.png
  37. BIN
      image/bg/menu_file.png
  38. BIN
      image/bg/menu_setting.png
  39. BIN
      image/bg/min_bt.png
  40. BIN
      image/bg/ng_bg.png
  41. BIN
      image/bg/ok_bg.png
  42. BIN
      image/bg/open_file.png
  43. BIN
      image/bg/refresh.png
  44. BIN
      image/bg/reset_logo.png
  45. BIN
      image/bg/resistance_logo.png
  46. BIN
      image/bg/save_bg.png
  47. BIN
      image/bg/scan_barcode.png
  48. BIN
      image/bg/tree_folder_icon.png
  49. BIN
      image/bg/tree_leaf_icon.png
  50. BIN
      image/bg/user.png
  51. BIN
      image/bg/vertical_line.png
  52. BIN
      image/bg/zoom_in.png
  53. BIN
      image/bg/zoom_out.png
  54. BIN
      image/close_bt.png
  55. 0 0
      image/cmd.txt
  56. BIN
      image/icon.ico
  57. BIN
      image/info_bt.png
  58. BIN
      image/min_bt.png
  59. BIN
      lib/commons-codec-1.15.jar
  60. BIN
      lib/fastjson2-2.0.16.jar
  61. BIN
      lib/gson-2.10.jar
  62. BIN
      lib/iot-communication-1.4.4.jar
  63. BIN
      lib/jSerialComm-2.6.2.jar
  64. BIN
      lib/jfreechart-1.5.4.jar
  65. BIN
      lib/jshortcut-0.4-oberzalek.jar
  66. BIN
      lib/kotlin-stdlib-1.8.10.jar
  67. BIN
      lib/logback-classic-1.2.13.jar
  68. BIN
      lib/logback-core-1.2.13.jar
  69. BIN
      lib/netty-all-4.1.48.Final.jar
  70. BIN
      lib/okhttp-4.10.0.jar
  71. BIN
      lib/okio-jvm-3.3.0.jar
  72. BIN
      lib/s7connector-2.1.jar
  73. BIN
      lib/slf4j-api-1.7.36.jar
  74. BIN
      lib/sqlite-jdbc-3.36.0.3.jar
  75. 10 0
      src/com/mes/component/CallFromJs.java
  76. 57 0
      src/com/mes/component/MesRadio.java
  77. 44 0
      src/com/mes/component/MesWebView.java
  78. 30 0
      src/com/mes/component/MyDialog.java
  79. 58 0
      src/com/mes/ui/BindMaterialResp.java
  80. 340 0
      src/com/mes/ui/DataUtil.java
  81. 85 0
      src/com/mes/ui/LockUtil.java
  82. 194 0
      src/com/mes/ui/LoginFarme.java
  83. 801 0
      src/com/mes/ui/MesClient.java
  84. 92 0
      src/com/mes/ui/OprnoUtil.java
  85. 43 0
      src/com/mes/ui/TableCellEditorButton.java
  86. 14 0
      src/com/mes/ui/TableCellRendererButton.java
  87. 182 0
      src/com/mes/ui/WelderParamPanel.java
  88. 97 0
      src/com/mes/ui/WelderParamService.java
  89. 61 0
      src/com/mes/ui/WorkRecordData.java
  90. 403 0
      src/com/mes/ui/WorkRecordPanel.java
  91. 63 0
      src/com/mes/ui/WorkRecordResp.java
  92. 11 0
      src/com/mes/util/Base64Utils.java
  93. 32 0
      src/com/mes/util/DateLocalUtils.java
  94. 53 0
      src/com/mes/util/ErrorMsg.java
  95. 157 0
      src/com/mes/util/HttpUtils.java
  96. 145 0
      src/com/mes/util/JdbcUtils.java
  97. 199 0
      src/com/mes/util/ModbusRtuClient.java
  98. 76 0
      src/com/mes/util/WelderConfig.java
  99. 44 0
      src/com/mes/util/WelderParamData.java
  100. 0 0
      src/com/mes/util/WelderParamReader.java

+ 25 - 0
.classpath

@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
+		<attributes>
+			<attribute name="module" value="true"/>
+		</attributes>
+	</classpathentry>
+    <classpathentry kind="src" path="image"/>
+	<classpathentry excluding="resources/" kind="src" path="src"/>
+	<classpathentry kind="src" path="src/resources"/>
+	<classpathentry kind="output" path="bin"/>
+	<classpathentry kind="lib" path="lib/s7connector-2.1.jar"/>
+	<classpathentry kind="lib" path="lib/slf4j-api-2.0.6.jar"/>
+	<classpathentry kind="lib" path="lib/okhttp-4.10.0.jar"/>
+	<classpathentry kind="lib" path="lib/kotlin-stdlib-1.8.10.jar"/>
+	<classpathentry kind="lib" path="lib/okio-jvm-3.3.0.jar"/>
+	<classpathentry kind="lib" path="lib/gson-2.10.jar"/>
+	<classpathentry kind="lib" path="lib/jfreechart-1.5.4.jar"/>
+	<classpathentry kind="lib" path="lib/jshortcut-0.4-oberzalek.jar"/>
+	<classpathentry kind="lib" path="lib/netty-all-4.1.48.Final.jar"/>
+	<classpathentry kind="lib" path="lib/sqlite-jdbc-3.36.0.3.jar"/>
+	<classpathentry kind="lib" path="lib/commons-codec-1.15.jar"/>
+	<classpathentry kind="lib" path="lib/fastjson2-2.0.16.jar"/>
+	<classpathentry kind="lib" path="lib/jSerialComm-2.6.2.jar"/>
+</classpath>

+ 8 - 0
.gitignore

@@ -0,0 +1,8 @@
+.idea
+.settings
+classes
+bin
+out
+*.db
+*.iml
+.lock

+ 28 - 0
.project

@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>mesclient-sd</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+	<filteredResources>
+		<filter>
+			<id>1778459887536</id>
+			<name></name>
+			<type>30</type>
+			<matcher>
+				<id>org.eclipse.core.resources.regexFilterMatcher</id>
+				<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
+			</matcher>
+		</filter>
+	</filteredResources>
+</projectDescription>

BIN
FCN逆变储能焊机控制器说明书(1)(1).pdf


BIN
Modbus RTU通讯说明-OP030-8.docx


+ 2 - 0
image/.gitignore

@@ -0,0 +1,2 @@
+META-INF
+_system~.ini

BIN
image/background.png


BIN
image/bg/a_side.png


BIN
image/bg/b_side.png


BIN
image/bg/bar_add.png


BIN
image/bg/bar_bookmark.png


BIN
image/bg/bar_cmd_go.png


BIN
image/bg/bar_edit.png


BIN
image/bg/bar_pause.png


BIN
image/bg/bar_sampling.png


BIN
image/bg/bar_setting.png


BIN
image/bg/bar_stop.png


BIN
image/bg/close_bt.png


BIN
image/bg/company_setting_logo.png


BIN
image/bg/delete.png


BIN
image/bg/department_setting_logo.png


BIN
image/bg/download.png


BIN
image/bg/equipment_setting_logo.png


BIN
image/bg/gj_001_1_20.png


BIN
image/bg/gj_001_21_40.png


BIN
image/bg/gj_001_41_60.png


BIN
image/bg/green_dot.png


BIN
image/bg/grey_dot.png


BIN
image/bg/icon.png


BIN
image/bg/inductance_logo.png


BIN
image/bg/insulation_logo.png


BIN
image/bg/login.png


BIN
image/bg/logo.png


BIN
image/bg/logoff.png


BIN
image/bg/menu_data_analysis.png


BIN
image/bg/menu_data_preprocess.png


BIN
image/bg/menu_file.png


BIN
image/bg/menu_setting.png


BIN
image/bg/min_bt.png


BIN
image/bg/ng_bg.png


BIN
image/bg/ok_bg.png


BIN
image/bg/open_file.png


BIN
image/bg/refresh.png


BIN
image/bg/reset_logo.png


BIN
image/bg/resistance_logo.png


BIN
image/bg/save_bg.png


BIN
image/bg/scan_barcode.png


BIN
image/bg/tree_folder_icon.png


BIN
image/bg/tree_leaf_icon.png


BIN
image/bg/user.png


BIN
image/bg/vertical_line.png


BIN
image/bg/zoom_in.png


BIN
image/bg/zoom_out.png


BIN
image/close_bt.png


+ 0 - 0
image/cmd.txt


BIN
image/icon.ico


BIN
image/info_bt.png


BIN
image/min_bt.png


BIN
lib/commons-codec-1.15.jar


BIN
lib/fastjson2-2.0.16.jar


BIN
lib/gson-2.10.jar


BIN
lib/iot-communication-1.4.4.jar


BIN
lib/jSerialComm-2.6.2.jar


BIN
lib/jfreechart-1.5.4.jar


BIN
lib/jshortcut-0.4-oberzalek.jar


BIN
lib/kotlin-stdlib-1.8.10.jar


BIN
lib/logback-classic-1.2.13.jar


BIN
lib/logback-core-1.2.13.jar


BIN
lib/netty-all-4.1.48.Final.jar


BIN
lib/okhttp-4.10.0.jar


BIN
lib/okio-jvm-3.3.0.jar


BIN
lib/s7connector-2.1.jar


BIN
lib/slf4j-api-1.7.36.jar


BIN
lib/sqlite-jdbc-3.36.0.3.jar


+ 10 - 0
src/com/mes/component/CallFromJs.java

@@ -0,0 +1,10 @@
+package com.mes.component;
+
+import com.mes.ui.MesClient;
+
+public class CallFromJs {
+    public String callFromJs(String info){
+        System.out.print("ss:"+info);
+        return MesClient.sessionid+":java:" + info;
+    }
+}

+ 57 - 0
src/com/mes/component/MesRadio.java

@@ -0,0 +1,57 @@
+package com.mes.component;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+public class MesRadio extends JPanel {
+
+    private String result = "";
+    private Integer i = 0;
+
+    public MesRadio(String[] radioTitles,String[] radioVals){
+        this.setLayout(new FlowLayout());
+        ButtonGroup group = new ButtonGroup();
+        i = 0;
+        for (String title:radioTitles){
+            JRadioButton radioButton = new JRadioButton(title);
+            radioButton.setFont(new Font("微软雅黑", Font.PLAIN, 28));
+
+            String val = radioVals[i];
+            radioButton.setName(val);
+
+            this.add(radioButton);
+            group.add(radioButton);
+
+            radioButton.addActionListener(new ActionListener() {
+                @Override
+                public void actionPerformed(ActionEvent e) {
+                    result = val;
+                    System.out.println("选择:"+result);
+                }
+            });
+            i++;
+        }
+    }
+
+    public void setResult(String ret){
+        this.result = "";
+        Component[] components = this.getComponents();
+        for (Component jRadioButton:components){
+            if(jRadioButton instanceof JRadioButton){
+                JRadioButton jRadioButtonParam = (JRadioButton)jRadioButton;
+                if(ret.equals(jRadioButtonParam.getName())){
+                    jRadioButtonParam.setSelected(true);
+                    this.result = jRadioButtonParam.getName();
+                }else{
+                    jRadioButtonParam.setSelected(false);
+                }
+            }
+        }
+    }
+
+    public String getResult(){
+        return this.result;
+    }
+}

+ 44 - 0
src/com/mes/component/MesWebView.java

@@ -0,0 +1,44 @@
+package com.mes.component;
+
+import javafx.application.Platform;
+import javafx.beans.value.ObservableValue;
+import javafx.concurrent.Worker;
+import javafx.embed.swing.JFXPanel;
+import javafx.scene.Scene;
+import javafx.scene.web.WebEngine;
+import javafx.scene.web.WebView;
+import netscape.javascript.JSObject;
+
+import java.util.Date;
+
+public class MesWebView extends JFXPanel {
+
+    public static WebEngine engine = null;
+
+    public MesWebView(String url){
+
+        Platform.runLater(() -> {
+            WebView webView = new WebView();
+            setScene(new Scene(webView));
+            Date date = new Date();
+//            String url = "http://"+mes_server_ip+":8980/js/a/mes/mesQuality/check?__sid="+sessionid+"&oprno="+mes_gw+"&t="+date.getTime();
+            System.out.print(url);
+            engine = webView.getEngine();
+            CallFromJs bridge = new CallFromJs();
+            engine.getLoadWorker().stateProperty().addListener(
+                    (ObservableValue<? extends Worker.State> ov, Worker.State oldState, Worker.State newState) -> {
+                        if (newState == Worker.State.SUCCEEDED) {
+                            JSObject window = (JSObject) engine.executeScript("window");
+                            window.setMember("apps", bridge);
+                            window.setMember("sout", System.out);
+                        }
+                    }
+            );
+            engine.load(url);
+        });
+    }
+
+    public void reloadWeb(){
+        engine.reload();
+    }
+}

+ 30 - 0
src/com/mes/component/MyDialog.java

@@ -0,0 +1,30 @@
+package com.mes.component;
+
+import javax.swing.*;
+import java.awt.*;
+
+public class MyDialog extends JDialog {
+
+    public MyDialog(Frame owner, String title, String msg){
+        super(owner, title);
+        init(msg);
+    }
+
+    private void init(String msg){
+        Container container = this.getContentPane();
+        container.setLayout(null);
+        container.setBackground(Color.BLACK);
+        this.setSize(800,220);
+        this.setLocationRelativeTo(null);
+
+        JLabel tslabel = new JLabel(msg);
+        tslabel.setHorizontalAlignment(SwingConstants.CENTER);
+        tslabel.setForeground(Color.RED);
+        tslabel.setFont(new Font("微软雅黑", Font.PLAIN,48));
+        tslabel.setBounds(0,30,800,100);
+
+        container.add(tslabel);
+        this.setModal(true);
+        this.setVisible(true);
+    }
+}

+ 58 - 0
src/com/mes/ui/BindMaterialResp.java

@@ -0,0 +1,58 @@
+package com.mes.ui;
+
+public class BindMaterialResp {
+    private String materialId;
+    private String materialTitle;
+    private String craft;
+    private String batchSn;
+    private String lastTimes;
+    private String type;
+
+    public String getMaterialId() {
+        return materialId;
+    }
+
+    public void setMaterialId(String materialId) {
+        this.materialId = materialId;
+    }
+
+    public String getMaterialTitle() {
+        return materialTitle;
+    }
+
+    public void setMaterialTitle(String materialTitle) {
+        this.materialTitle = materialTitle;
+    }
+
+    public String getCraft() {
+        return craft;
+    }
+
+    public void setCraft(String craft) {
+        this.craft = craft;
+    }
+
+    public String getBatchSn() {
+        return batchSn;
+    }
+
+    public void setBatchSn(String batchSn) {
+        this.batchSn = batchSn;
+    }
+
+    public String getLastTimes() {
+        return lastTimes;
+    }
+
+    public void setLastTimes(String lastTimes) {
+        this.lastTimes = lastTimes;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+}

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

@@ -0,0 +1,340 @@
+package com.mes.ui;
+
+import com.alibaba.fastjson2.JSONArray;
+import com.alibaba.fastjson2.JSONObject;
+import com.mes.util.JdbcUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.*;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+public class DataUtil {
+    public static final Logger log = LoggerFactory.getLogger(DataUtil.class);
+
+    //删除当前工位工件码
+    public static JSONObject delCurSn(String oprno,String serverIp,String lineSn){
+        try {
+            String url = "http://"+serverIp+":8980/js/a/mes/mesProductRecord/cancelCurSn";
+            String params = "__ajax=json&oprno="+oprno+"&lineSn="+lineSn+"&__sid="+MesClient.sessionid;
+            JSONObject result = JSONObject.parseObject(doPost(url, params));
+//            log.info("请求参数:"+params);
+            return result;
+        } catch (Exception e) {
+            log.info("e="+e.getMessage());
+            return null;
+        }
+    }
+
+    //获取当前工位工件码
+    public static JSONObject getCurSn(String oprno,String serverIp,String lineSn){
+        try {
+            String url = "http://"+serverIp+":8980/js/a/mes/mesProductRecord/getCurSn";
+            String params = "__ajax=json&oprno="+oprno+"&lineSn="+lineSn+"&__sid="+MesClient.sessionid;
+            JSONObject result = JSONObject.parseObject(doPost(url, params));
+//            log.info("请求参数:"+params);
+            return result;
+        } catch (Exception e) {
+            log.info("e="+e.getMessage());
+            return null;
+        }
+    }
+
+    // 检查质量
+    public static JSONObject checkQuality(String sn, String user){
+        try{
+            String enconding = "UTF-8";
+            InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
+            Properties pro = new Properties();
+            BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
+            pro.load(br);
+            String mes_server_ip = pro.getProperty("mes.server_ip");
+            String oprno = pro.getProperty("mes.gw").trim();
+            String lineSn = pro.getProperty("mes.line_sn").trim();
+            String url = "http://"+mes_server_ip+":8980/js/a/mes/mesProductRecord/pccheck";
+            String params = "__ajax=json&oprno="+oprno+"&lineSn="+lineSn+"&sn="+sn+"&ucode="+user;
+            log.info("params="+params);
+            String result = doPost(url,params);
+            log.info("result="+result);
+            if(result.equalsIgnoreCase("false")) {
+                return null;
+            }else {
+//                JdbcUtils.insertData(oprno, "100000", params, "AQDW", sn);
+                startWork(sn, user);
+                return JSONObject.parseObject(result);
+            }
+        }catch (Exception e){
+            log.info("e="+e.getMessage());
+            return null;
+        }
+    }
+
+    //提交结果
+    public static JSONObject sendQuality(String sn,String ret,String user){
+        try{
+            String enconding = "UTF-8";
+            InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
+            Properties pro = new Properties();
+            BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
+            pro.load(br);
+            String mes_server_ip = pro.getProperty("mes.server_ip");
+            String oprno = pro.getProperty("mes.gw").trim();
+            String lineSn = pro.getProperty("mes.line_sn").trim();
+            String url = "http://"+mes_server_ip+":8980/js/a/mes/mesProductRecord/pcresult";
+            String params = "__ajax=json&oprno="+oprno+"&lineSn="+lineSn+"&sn="+sn+"&result="+ret+"&ucode="+user;
+            log.info("params="+params);
+            String result = doPost(url,params);
+            log.info("result="+result);
+
+            if(result.equalsIgnoreCase("false")) {
+                return null;
+            }else {
+//                JdbcUtils.insertData(oprno, "100000", params, "MQDW", sn);
+                return JSONObject.parseObject(result);
+            }
+        }catch (Exception e){
+            log.info("e="+e.getMessage());
+            return null;
+        }
+    }
+
+    // 开始工作
+    public static JSONObject startWork(String sn, String user) {
+        try{
+            String enconding = "UTF-8";
+            InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
+            Properties pro = new Properties();
+            BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
+            pro.load(br);
+            String mes_server_ip = pro.getProperty("mes.server_ip");
+            String oprno = pro.getProperty("mes.gw").trim();
+            String lineSn = pro.getProperty("mes.line_sn").trim();
+            String url = "http://"+mes_server_ip+":8980/js/a/mes/mesProductRecord/pcstart";
+            String params = "__ajax=json&oprno="+oprno+"&lineSn="+lineSn+"&sn="+sn+"&ucode="+user;
+            log.info("params="+params);
+            String result = doPost(url,params);
+            log.info("result="+result);
+            if(result.equalsIgnoreCase("false")) {
+                return null;
+            }else {
+                return JSONObject.parseObject(result);
+            }
+        }catch (Exception e){
+            log.info("e="+e.getMessage());
+            return null;
+        }
+    }
+
+
+
+    public static String rightPad(final String str, final int size) {
+        if (str == null) {
+            return null;
+        }
+
+        String strret = str;
+        if(str.length() > size){
+            strret = str.substring(0,size);
+        }
+        return String.format("%-"+size+"s", strret);
+    }
+
+    public static JSONObject getBindMaterail() {
+        try{
+            String enconding = "UTF-8";
+            InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
+            Properties pro = new Properties();
+            BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
+            pro.load(br);
+            String mes_server_ip = pro.getProperty("mes.server_ip");
+            String oprno = pro.getProperty("mes.gw").trim();
+            String lineSn = pro.getProperty("mes.line_sn").trim();
+            String url = "http://"+mes_server_ip+":8980/js/a/mes/mesLineProcessMaterial/materials";
+            String params = "__ajax=json&oprno="+oprno+"&lineSn="+lineSn;
+            System.out.println("params="+params);
+            String result = doPost(url,params);
+            System.out.println("result="+result);
+
+            if(result.equalsIgnoreCase("false")) {
+                return null;
+            }else {
+                return JSONObject.parseObject(result);
+            }
+        }catch (Exception e){
+            return null;
+        }
+    }
+
+    public static JSONObject saveBindMaterail(String batchSn,String craft,String materialId,String type) {
+        try{
+            String enconding = "UTF-8";
+            InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
+            Properties pro = new Properties();
+            BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
+            pro.load(br);
+            String mes_server_ip = pro.getProperty("mes.server_ip");
+            String oprno = pro.getProperty("mes.gw").trim();
+            String lineSn = pro.getProperty("mes.line_sn").trim();
+            String url = "http://"+mes_server_ip+":8980/js/a/mes/mesMaterialPrebind/bind";
+            String params = "__ajax=json&oprno="+oprno+"&lineSn="+lineSn+"&batchSn="+batchSn+"&craft="+craft+"&materialId="+materialId+"&type="+type;
+            System.out.println("params="+params);
+            String result = doPost(url,params);
+            System.out.println("result="+result);
+
+            if(result.equalsIgnoreCase("false")) {
+                return null;
+            }else {
+                return JSONObject.parseObject(result);
+            }
+        }catch (Exception e){
+            return null;
+        }
+    }
+
+    public static String doPost(String httpUrl, String param) {
+        HttpURLConnection connection = null;
+        InputStream is = null;
+        OutputStream os = null;
+        BufferedReader br = null;
+        String result = null;
+        try {
+            URL url = new URL(httpUrl);
+            connection = (HttpURLConnection) url.openConnection();
+            connection.setRequestMethod("POST");
+            connection.setConnectTimeout(15000);
+            connection.setReadTimeout(60000);
+            connection.setDoOutput(true);
+            connection.setDoInput(true);
+            connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
+            connection.setRequestProperty("Authorization", "Bearer da3efcbf-0845-4fe3-8aba-ee040be542c0");
+            os = connection.getOutputStream();
+            os.write(param.getBytes());
+            if (connection.getResponseCode() == 200) {
+                is = connection.getInputStream();
+                br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
+                StringBuffer sbf = new StringBuffer();
+                String temp = null;
+                while ((temp = br.readLine()) != null) {
+                    sbf.append(temp);
+                    sbf.append("\r\n");
+                }
+                result = sbf.toString();
+            }
+        } catch (MalformedURLException e) {
+            e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            if (null != br) {
+                try {
+                    br.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+            if (null != os) {
+                try {
+                    os.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+            if (null != is) {
+                try {
+                    is.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+            connection.disconnect();
+        }
+        return result;
+    }
+
+    /**
+     * 查询工作记录
+     * @param oprno 工位号(空则查所有工位)
+     * @param sn 工件码(可选,用于搜索)
+     * @param pageNo 页码
+     * @param pageSize 每页条数
+     * @return 工作记录响应
+     */
+    public static WorkRecordResp getWorkRecordList(String oprno, String sn, int pageNo, int pageSize) {
+        WorkRecordResp resp = new WorkRecordResp();
+        try {
+            String enconding = "UTF-8";
+            InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
+            Properties pro = new Properties();
+            BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
+            pro.load(br);
+            String mes_server_ip = pro.getProperty("mes.server_ip");
+            String lineSn = pro.getProperty("mes.line_sn").trim();
+            
+            String url = "http://" + mes_server_ip + ":8980/js/a/mes/mesProductRecord/ ";
+            StringBuilder params = new StringBuilder();
+            params.append("__ajax=json");
+            params.append("&lineSn=").append(lineSn);
+            params.append("&pageNo=").append(pageNo);
+            params.append("&pageSize=").append(pageSize);
+            
+            if (oprno != null && !oprno.isEmpty()) {
+                params.append("&oprno=").append(oprno);
+            }
+            // 注意:不传auto参数,这样"所有工位"查询时会返回整条产线所有工位的数据
+            if (sn != null && !sn.isEmpty()) {
+                params.append("&sn=").append(sn);
+            }
+            
+            log.info("查询工作记录: url=" + url + ", params=" + params.toString());
+            String result = doPost(url, params.toString());
+            log.info("查询工作记录结果: result=" + result);
+            
+            if (result == null || result.trim().isEmpty()) {
+                resp.setResult(false);
+                resp.setMessage("请求返回空结果");
+                return resp;
+            }
+            
+            JSONObject jsonObj = JSONObject.parseObject(result);
+            if (jsonObj == null) {
+                resp.setResult(false);
+                resp.setMessage("解析响应失败");
+                return resp;
+            }
+            
+            resp.setResult(true);
+            resp.setPageNo(jsonObj.getIntValue("pageNo"));
+            resp.setPageSize(jsonObj.getIntValue("pageSize"));
+            resp.setCount(jsonObj.getLongValue("count"));
+            
+            List<WorkRecordData> list = new ArrayList<>();
+            JSONArray listArray = jsonObj.getJSONArray("list");
+            if (listArray != null) {
+                for (int i = 0; i < listArray.size(); i++) {
+                    JSONObject item = listArray.getJSONObject(i);
+                    WorkRecordData data = new WorkRecordData();
+                    data.setId(item.getString("id"));
+                    data.setSn(item.getString("sn"));
+                    data.setOprno(item.getString("oprno"));
+                    data.setUpdateBy(item.getString("updateBy"));
+                    data.setUpdateDate(item.getString("updateDate"));
+                    data.setContent(item.getString("content"));
+                    list.add(data);
+                }
+            }
+            resp.setList(list);
+            
+        } catch (Exception e) {
+            log.error("查询工作记录异常: " + e.getMessage());
+            e.printStackTrace();
+            resp.setResult(false);
+            resp.setMessage("查询异常: " + e.getMessage());
+        }
+        return resp;
+    }
+}

+ 85 - 0
src/com/mes/ui/LockUtil.java

@@ -0,0 +1,85 @@
+package com.mes.ui;
+
+import java.io.File;
+import java.io.RandomAccessFile;
+import java.nio.channels.FileChannel;
+import java.nio.channels.FileLock;
+import java.nio.channels.OverlappingFileLockException;
+
+public class LockUtil {
+    private FileChannel channel;
+
+    private FileLock lock;
+
+    private File file;
+
+    private static LockUtil instance = null;
+
+    /**
+     * 获取唯一进程限制的实例
+     * @Title: getInstance
+     * @return  唯一进程实例
+     */
+    public static LockUtil getInstance(){
+        if(instance == null){
+            instance = new LockUtil();
+        }
+        return instance;
+    }
+
+    /**
+     * 进程是否正在运行
+     * @Title: isAppActive
+     * @return  运行与否
+     */
+    public boolean isAppActive() {
+        File file = new File(".lock");
+        try {
+            channel = new RandomAccessFile(file, "rw").getChannel();
+            try {
+                lock = channel.tryLock();
+
+            } catch (OverlappingFileLockException e) {
+                closeLock();
+                return true;
+            }
+            if (lock == null) {
+                closeLock();
+                return true;
+            }
+            Runtime.getRuntime().addShutdownHook(new Thread() {
+                public void run() {
+                    closeLock();
+                    deleteFile();
+                }
+            });
+            return false;
+        } catch (Exception e) {
+            closeLock();
+            return true;
+        }
+    }
+
+    protected void deleteFile() {
+        try {
+            file.delete();
+        } catch (Exception e) {
+
+        }
+
+    }
+
+    private void closeLock() {
+        try {
+            lock.release();
+        } catch (Exception e) {
+
+        }
+
+        try {
+            channel.close();
+        } catch (Exception e) {
+
+        }
+    }
+}

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

@@ -0,0 +1,194 @@
+package com.mes.ui;
+
+import com.alibaba.fastjson2.JSONObject;
+import com.mes.component.MesRadio;
+import com.mes.component.MesWebView;
+import com.mes.util.Base64Utils;
+import com.mes.util.HttpUtils;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.time.LocalDateTime;
+
+public class LoginFarme extends JFrame {
+    //登录模块组件
+    static JLabel userNameLabel= new JLabel("<html><body>用户名:</body></html>",JLabel.LEFT);//用户名
+    static JLabel userPasswordLabel= new JLabel("<html><body>密码:</body></html>",JLabel.LEFT);//用户名
+    public static JTextField userNameTxt;
+    public static JPasswordField userPasswordTxt;
+    static JButton loginButton = new JButton("用户密码登录");
+    static JButton scanLoginButton = new JButton("扫  码  登  录");
+
+    public LoginFarme(){
+        setTitle("MES系统客户端:"+MesClient.mes_gw+" - "+MesClient.mes_gw_des);
+
+        ImageIcon bg = new ImageIcon(MesClient.class.getResource("/background.png"));
+        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+        JLabel imgLabel = new JLabel(bg);//将背景图放在标签里。
+        getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE));//注意这里是关键,将背景标签添加到jfram的LayeredPane面板里。
+        imgLabel.setBounds(0,0,bg.getIconWidth(), bg.getIconHeight());//设置背景标签的位置
+        Container contentPane=getContentPane();
+        contentPane.setLayout(null);//布局,很重要
+        JPanel welcomePanel = new JPanel();
+        //welcomePanel.setLayout(new GridLayout(3, 1));
+        welcomePanel.setLayout(null);
+        //welcomeLable.setBounds(10, 5, 700, 100);
+        welcomePanel.setBounds(30, 330, 890, 300);
+        welcomePanel.setOpaque(false);//背景透明
+        contentPane.add(welcomePanel);
+
+        //登录页面
+        userNameLabel.setBounds(300, 100, 120, 40);
+        userNameLabel.setFont(new java.awt.Font("Dialog",   1,   16));
+        userPasswordLabel.setBounds(300, 150, 120, 40);
+        userPasswordLabel.setFont(new java.awt.Font("Dialog",   1,   16));
+        userNameTxt = new JTextField(20);
+        userNameTxt.setText("system");
+        userNameTxt.setBounds(400, 105, 150, 30);
+        userPasswordTxt = new JPasswordField(20);
+        userPasswordTxt.setBounds(400, 155, 150, 30);
+        userPasswordTxt.setText("Aa111111");
+        loginButton.setFont(new java.awt.Font("Dialog",   1,   16));
+        loginButton.setBounds(300, 200, 255, 40);
+        loginButton.setIcon(new ImageIcon(MesClient.class.getResource("/bg/user.png")));
+
+//        scanLoginButton.setVisible(false);
+        scanLoginButton.setFont(new java.awt.Font("Dialog",   1,   16));
+        scanLoginButton.setBounds(300, 250, 255, 40);
+        scanLoginButton.setIcon(new ImageIcon(MesClient.class.getResource("/bg/scan_barcode.png")));
+
+        welcomePanel.add(userNameLabel);
+        welcomePanel.add(userPasswordLabel);
+        welcomePanel.add(userNameTxt);
+        welcomePanel.add(userPasswordTxt);
+        welcomePanel.add(loginButton);
+        welcomePanel.add(scanLoginButton);
+        loginButton.addActionListener(new ActionListener(){
+            public void actionPerformed(ActionEvent e) {
+                login();
+            }
+        });
+        scanLoginButton.addActionListener(new ActionListener(){
+            public void actionPerformed(ActionEvent e) {
+                scanLogin();
+            }
+        });
+
+        ((JPanel)contentPane).setOpaque(false); //注意这里,将内容面板设为透明。这样LayeredPane面板中的背景才能显示出来。
+        //welcomeWin.setSize(902,678);
+        setResizable(false);//禁止最大化
+        setIconImage(Toolkit.getDefaultToolkit().getImage(MesClient.class.getResource("/bg/logo.png")));
+
+        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
+        int width = 902;
+        int height = 678;
+        setBounds((d.width-width)/2, (d.height-height)/2-(d.height-height)/4, width, height);
+        /*****正常模式******/
+        setVisible(true);
+    }
+
+    //登录
+    public static void login() {
+        String user_str = userNameTxt.getText().toString();
+        String password_str = userPasswordTxt.getText().toString();
+        if(user_str.equalsIgnoreCase("")||password_str.equalsIgnoreCase("")) {
+            JOptionPane.showMessageDialog(MesClient.mesClientFrame,"用户名或密码不能为空","提示窗口", JOptionPane.INFORMATION_MESSAGE);
+            return;
+        }
+        String username = Base64Utils.getBase64(user_str);
+        String password = Base64Utils.getBase64(password_str);
+        System.out.println("&username=" + username + "&password=" + password);
+        String url = "http://"+MesClient.mes_server_ip+":8980/js/a/login?__ajax=json&username="+username+"&password="+password+"&validCode=&__sid=";
+        String loginResult = HttpUtils.sendRequest(url);
+        if(loginResult.equalsIgnoreCase("false")) {
+            JOptionPane.showMessageDialog(MesClient.mesClientFrame,"登录异常,请检查网络或联系网络管理员","提示窗口", JOptionPane.INFORMATION_MESSAGE);
+            return;
+        }else {
+            JSONObject retObj = JSONObject.parseObject(loginResult);
+            if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
+                //检查用户权限是否可登录界面
+                checkUserAuthority(retObj);
+            }else {
+                //ret = "msg save error";
+                //ret = false;
+                JOptionPane.showMessageDialog(MesClient.mesClientFrame,"登录失败,用户名或密码错误","提示窗口", JOptionPane.INFORMATION_MESSAGE);
+                return;
+            }
+        }
+    }
+    //扫码登录
+    public static void scanLogin() {
+        //userNameTxt.setText("");
+        //userPasswordTxt.setText("");
+        String scanContent = JOptionPane.showInputDialog(null, "请扫码工牌二维码");
+        System.out.println("scanContent="+scanContent);
+        if(scanContent!=null&&!scanContent.equalsIgnoreCase("")) {
+            String url = "http://"+MesClient.mes_server_ip+":8980/js/a/mes/mesLogin/login?__login=true&__ajax=json&username="+scanContent;
+            String loginResult = HttpUtils.sendRequest(url);
+            System.out.println("loginResult="+loginResult);
+            if(loginResult.equalsIgnoreCase("false")) {
+                JOptionPane.showMessageDialog(MesClient.mesClientFrame,"登录异常,请检查网络或联系网络管理员","提示窗口", JOptionPane.INFORMATION_MESSAGE);
+                return;
+            }else {
+                JSONObject retObj = JSONObject.parseObject(loginResult);
+                if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
+                    //检查用户权限是否可登录界面
+                    checkUserAuthority(retObj);
+                }else {
+                    JOptionPane.showMessageDialog(MesClient.mesClientFrame,"登录失败,用户名或密码错误","提示窗口", JOptionPane.INFORMATION_MESSAGE);
+                    return;
+                }
+            }
+        }else {
+            JOptionPane.showMessageDialog(MesClient.mesClientFrame,"扫码内容错误","提示窗口", JOptionPane.INFORMATION_MESSAGE);
+            return;
+        }
+    }
+
+    //检查用户权限是否可登录界面
+    public static void checkUserAuthority(JSONObject retObj) {
+        //设置登录用户名
+        JSONObject userObj = JSONObject.parseObject(retObj.get("user").toString());
+        String user_id = userObj.getString("id").toString();
+
+        //获取sessionid,判断权限
+        MesClient.sessionid = retObj.get("sessionid").toString();
+        if(MesClient.sessionid!=null&&!MesClient.sessionid.equalsIgnoreCase("")) {
+            //请求权限
+            String url_authority = "http://"+MesClient.mes_server_ip+":8980/js/a/mes/mesLineProcess/userAuth?__ajax=json&type=0&__sid="+MesClient.sessionid+"&oprno="+MesClient.mes_gw+"&lineSn="+MesClient.mes_line_sn;
+            String authorityResult = HttpUtils.sendRequest(url_authority);
+            System.out.println("authorityResult="+authorityResult);
+            JSONObject authorityObj = JSONObject.parseObject(authorityResult);
+            if(authorityObj.get("result")!=null&&authorityObj.get("result").toString().equalsIgnoreCase("true")) {
+                JSONObject authObjTmp = JSONObject.parseObject(authorityObj.get("data").toString());
+                MesClient.mes_auth = Integer.parseInt(authObjTmp.getString("auth").toString());
+                if(MesClient.mes_auth==0) {
+                    //无权限登录
+                    JOptionPane.showMessageDialog(MesClient.mesClientFrame,"您无权登录该工位","提示窗口", JOptionPane.INFORMATION_MESSAGE);
+                    return;
+                }else if(MesClient.mes_auth==1||MesClient.mes_auth==2) {
+                    // 获取等于所处时间-当前小时
+                    LocalDateTime now = LocalDateTime.now();
+                    MesClient.userLoginHours = now.getHour();
+                    //启动timer心跳包
+                    MesClient.startHeartBeatTimer();
+
+                    //1操作工人,2管理员
+                    //登录成功
+                    MesClient.user_menu.setText(user_id);
+                    MesClient.welcomeWin.setVisible(false);
+                    MesClient.mesClientFrame.setVisible(true);
+                    MesClient.setMenuStatus("焊机参数监控", 0);
+                    MesClient.startWelderParamPolling();
+                }
+
+            }
+
+        }else {
+            JOptionPane.showMessageDialog(MesClient.mesClientFrame,"登录失败,用户名或密码错误","提示窗口", JOptionPane.INFORMATION_MESSAGE);
+            return;
+        }
+    }
+}

+ 801 - 0
src/com/mes/ui/MesClient.java

@@ -0,0 +1,801 @@
+package com.mes.ui;
+
+import com.alibaba.fastjson2.JSONObject;
+import com.mes.component.MesRadio;
+import com.mes.component.MesWebView;
+import com.mes.util.DateLocalUtils;
+import com.mes.util.HttpUtils;
+import com.mes.util.JdbcUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.swing.*;
+import javax.swing.border.EmptyBorder;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import java.awt.*;
+import java.awt.event.*;
+import java.io.*;
+import java.sql.ResultSet;
+import java.sql.Statement;
+import java.time.LocalDateTime;
+import java.util.List;
+import java.util.Properties;
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+public class MesClient extends JFrame {
+    public static final Logger log = LoggerFactory.getLogger(MesClient.class);
+
+    public static int mes_auth = 0; // 权限级别 0=无权限 1=操作工人 2=管理员
+    public static String mes_gw = ""; // 工位号
+    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 = ""; // 产线编号
+
+    //session
+    public static String sessionid = "";
+
+    public static JPanel contentPane;
+    public static MesClient mesClientFrame;
+    public static JTabbedPane tabbedPane;
+    public static JScrollPane indexScrollPaneA;
+    public static JScrollPane searchScrollPane; // 已弃用,改为使用 WorkRecordPanel
+    public static JScrollPane searchScrollPaneDj;
+
+
+    public static Boolean check_quality_result = false;
+    public static Integer work_status = 0;
+
+    public static JButton heart_beat_menu;
+    public static JButton status_menu;
+    public static JButton user_menu;
+
+    public static int scan_type = 0;
+    public static JButton finish_ok_bt;
+    public static JButton finish_ng_bt;
+    public static JTextField product_sn;
+    public static JButton f_scan_data_bt_1;
+
+    public static String user20 = "";
+
+    public static JFrame welcomeWin;
+
+    public static Timer getSnBeatTimer;
+    public static JPanel indexPanelB; // 已弃用,改为使用 WorkRecordPanel
+    public static MesWebView jfxPanel = null;
+    public static JPanel indexPanelC;
+    public static MesWebView jfxPanel2 = null;
+    public static MesRadio mesRadioHj;
+    public static WelderParamPanel welderParamPanel;
+
+    public static JTable table;
+    public static Object[] columnNames = { "物料名称", "绑定批次", "剩余次数", "操作" };
+    public static Object[][] rowData = null;
+
+    public static JLabel fxlabel;
+
+    public static void main(String[] args) {
+
+        if (LockUtil.getInstance().isAppActive() == true){
+//            JOptionPane.showMessageDialog(null, "已有一个程序在运行,程序退出");
+            return;
+        }else{
+            EventQueue.invokeLater(new Runnable() {
+                @Override
+                public void run() {
+                    try{
+                        //读文件配置
+                        readProperty();
+
+                        // 显示界面
+                        mesClientFrame = new MesClient();
+                        mesClientFrame.setVisible(false);
+
+                        JdbcUtils.getConn();
+
+                        welcomeWin = new LoginFarme();
+                        welcomeWin.setVisible(true);
+
+                        // 仅展示焊机参数,不加载物料绑定等页面
+                        // getMaterailData();
+
+                    }catch (Exception e){
+                        e.printStackTrace();
+                    }
+                }
+            });
+        }
+    }
+
+    //读配置文件
+    private static void readProperty() throws IOException{
+        String enconding = "UTF-8";
+        InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
+        Properties pro = new Properties();
+        BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
+        pro.load(br);
+        mes_gw =  pro.getProperty("mes.gw");
+        mes_server_ip = pro.getProperty("mes.server_ip");
+        mes_line_sn = pro.getProperty("mes.line_sn");
+        mes_gw_des = OprnoUtil.getGwDes(mes_line_sn,mes_gw);
+        log.info(mes_gw + ";" + mes_gw_des + ";" + mes_server_ip + ";");
+    }
+
+    //启动心跳包程序
+    public static java.util.Timer heartBeatTimer;
+    public static java.util.Timer heartBeatIconTimer;
+    public static boolean iconREDFlag = true;
+    public static void startHeartBeatTimer() {
+        if(heartBeatTimer!=null) {
+            heartBeatTimer.cancel();
+        }
+
+        //心跳显示图标
+        if(heartBeatIconTimer!=null) {
+            heartBeatIconTimer.cancel();
+        }
+        heartBeatIconTimer = new Timer();
+        heartBeatIconTimer.schedule(new TimerTask() {
+            public void run() {
+                if(iconREDFlag) {
+                    heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
+                    iconREDFlag = false;
+                }else {
+                    heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
+                    iconREDFlag = true;
+                }
+                heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
+                heart_beat_menu.repaint();
+            }
+        }, 100,mes_heart_icon_cycle*1000);
+    }
+
+    //设置tcp连接状态显示
+    public static void setTcpStatus() {
+        status_menu.setText("已连接MES服务器");
+        heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
+        heart_beat_menu.repaint();
+    }
+
+    public static void initWarehouseData(){
+        resetScanA();
+    }
+
+    public static void resetScanA() {
+        JSONObject ret = DataUtil.delCurSn(mes_gw, mes_server_ip, mes_line_sn);
+        if (ret != null && ret.getString("result").equalsIgnoreCase("true")) {
+            work_status = 0;
+            check_quality_result = false;
+            MesClient.finish_ok_bt.setEnabled(false);
+            MesClient.finish_ng_bt.setEnabled(false);
+            product_sn.setText("");
+            MesClient.fxlabel.setVisible(false);
+
+            MesClient.f_scan_data_bt_1.setEnabled(true);
+            MesClient.setMenuStatus("请扫工件码",0);
+//        MesClient.setMenuStatus("开班点检,请先进行OKNG样件测试",-1);
+
+            updateMaterailData();
+//        shiftUserCheck();
+        } else {
+            status_menu.setText("刷新失败");
+        }
+
+    }
+
+    public static int userLoginHours;//用户登录所处小时
+    //换班用户信息检查
+    private static  void  shiftUserCheck() {
+        LocalDateTime now = LocalDateTime.now();
+        // 判断时间范围
+        if (userLoginHours >= 8 && userLoginHours < 20) {
+
+            int hour = now.getHour();
+            if (hour >= 20 || hour < 8) {
+                logoff();
+            }
+        } else {
+            int hour = now.getHour();
+            if (hour >= 8 && hour < 20) {
+                logoff();
+            }
+        }
+    }
+    public static void resetScanB() {
+
+    }
+
+    //获取用户20位
+    public static void getUser() {
+        user20 = user_menu.getText().toString();
+//        String space_tmp1 = "";
+//        if(user20.length()<20) {
+//            for(int i=0;i<20-user20.length();i++) {
+//                space_tmp1 = space_tmp1 + " ";
+//            }
+//        }
+//        user20 = user20 + space_tmp1;
+    }
+
+    //获取barcode内容36位
+    public static String getBarcode(String barcodeTmp) {
+        String barcodeRet = barcodeTmp;
+        if(barcodeTmp.equalsIgnoreCase("")) {
+            return "";
+        }else {
+            if(barcodeTmp.length()<36) {
+                String space = "";
+                for(int i=0;i<36-barcodeTmp.length();i++) {
+                    space = space + " ";
+                }
+                barcodeRet = barcodeTmp + space;
+            }
+        }
+        return barcodeRet;
+    }
+
+    public static void scanBarcode() {
+        if(work_status == 1){
+            JOptionPane.showMessageDialog(mesClientFrame,"工作中,勿扫码","提示窗口", JOptionPane.INFORMATION_MESSAGE);
+            return;
+        }
+        String scanBarcodeTitle = "";
+        switch(scan_type) {
+            case 1:
+                product_sn.setText("");
+                scanBarcodeTitle = "请扫工件码";
+                break;
+        }
+
+        //弹窗扫工件码
+        String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
+        if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")) {
+            //获取用户
+            getUser();
+            //获取扫码内容36位
+            String barcode36 = getBarcode(scanBarcode);//处理36为码
+            //工位号
+            String gw = "";
+            switch(scan_type) {
+                case 1:
+                    product_sn.setText(scanBarcode);
+                    break;
+            }
+            //刷新界面
+            mesClientFrame.repaint();
+
+            // 查询工件质量
+            JSONObject retObj = DataUtil.checkQuality(scanBarcode,user20);
+            if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
+                MesClient.status_menu.setForeground(Color.GREEN);
+                MesClient.check_quality_result = true;//质量合格,可以绑定加工
+                MesClient.status_menu.setText("该工件可以加工");
+                MesClient.work_status = 1;
+                MesClient.f_scan_data_bt_1.setEnabled(false);
+                MesClient.finish_ok_bt.setEnabled(true);
+                MesClient.finish_ng_bt.setEnabled(true);
+            }else{
+                MesClient.check_quality_result = false;
+                MesClient.work_status = 0;
+                if(retObj.get("result")==null){
+                    MesClient.setMenuStatus("请求失败,请重试",-1);
+                }else{
+                    if(retObj.get("result").toString().equalsIgnoreCase("false")){
+                        MesClient.setMenuStatus(retObj.getString("message"),-1);
+                    }
+                }
+            }
+        }else {
+            MesClient.setMenuStatus("请扫工件码,请重试",-1);
+//            JOptionPane.showMessageDialog(mesClientFrame,"请扫工件码","提示窗口", JOptionPane.INFORMATION_MESSAGE);
+            return;
+        }
+    }
+
+    public static void logoff() {
+        WelderParamService.getInstance().stop();
+        welcomeWin.setVisible(true);
+        mesClientFrame.setVisible(false);
+    }
+
+    /** 启动焊机参数轮询(仅页面展示,不上报MES) */
+    public static void startWelderParamPolling() {
+        if (welderParamPanel != null) {
+            WelderParamService.getInstance().bindPanel(welderParamPanel);
+            WelderParamService.getInstance().start();
+        }
+    }
+
+    public MesClient() {
+        setIconImage(Toolkit.getDefaultToolkit().getImage(MesClient.class.getResource("/bg/logo.png")));
+        setTitle("MES系统客户端:"+mes_gw + "- " + mes_gw_des);
+//        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+        setBounds(0, 0, 1024, 768);
+
+        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
+        // 添加窗口监听器
+        addWindowListener(new WindowAdapter() {
+            @Override
+            public void windowClosing(WindowEvent e) {
+                int choice = JOptionPane.showConfirmDialog(null, "确定要关闭窗口吗?", "关闭确认", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
+                if (choice == JOptionPane.YES_OPTION) {
+                    WelderParamService.getInstance().stop();
+                    dispose(); // 释放窗口资源并关闭窗口
+                    System.exit(0);
+                }
+            }
+        });
+
+        JMenuBar menuBar = new JMenuBar();
+        menuBar.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 26));
+        setJMenuBar(menuBar);
+        JMenu fileMenu = new JMenu("用户");
+        fileMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/user.png")));
+        fileMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
+        menuBar.add(fileMenu);
+
+        JMenuItem exitMenuItem = new JMenuItem("退出");
+        exitMenuItem.setIcon(new ImageIcon(MesClient.class.getResource("/bg/logoff.png")));
+        exitMenuItem.setFont(new Font("微软雅黑", Font.PLAIN, 22));
+        fileMenu.add(exitMenuItem);
+        exitMenuItem.addMouseListener(new MouseAdapter() {
+            @Override
+            public void mousePressed(MouseEvent e) {//只能检测到mousePressed事件
+                super.mouseClicked(e);
+                //dispose();
+                logoff();
+            }
+        });
+
+        JMenu settingMenu = new JMenu("设置");
+        settingMenu.setVisible(false);
+        settingMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")));
+        settingMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
+        menuBar.add(settingMenu);
+
+        JMenuItem resetTcpMenu = new JMenuItem("\u91CD\u8FDEMES");
+        resetTcpMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
+        resetTcpMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
+        resetTcpMenu.addMouseListener(new MouseAdapter() {
+            @Override
+            public void mousePressed(MouseEvent e) {
+                super.mouseClicked(e);
+            }
+        });
+//        settingMenu.add(resetTcpMenu);
+
+        JMenuItem resetTcpMenu_1 = new JMenuItem("刷新工件");
+        resetTcpMenu_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
+        resetTcpMenu_1.setFont(new Font("微软雅黑", Font.PLAIN, 20));
+        resetTcpMenu_1.addMouseListener(new MouseAdapter() {
+            @Override
+            public void mousePressed(MouseEvent e) {
+                super.mouseClicked(e);
+                resetScanA();
+            }
+        });
+        // 仅展示焊机参数,隐藏扫码相关菜单
+        // settingMenu.add(resetTcpMenu_1);
+
+        contentPane = new JPanel();
+        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
+        setContentPane(contentPane);
+        contentPane.setLayout(new BorderLayout(0, 0));
+
+        JToolBar toolBar = new JToolBar();
+        contentPane.add(toolBar, BorderLayout.NORTH);
+
+        JLabel equipment_statu_label = new JLabel("状态:");
+        equipment_statu_label.setHorizontalAlignment(SwingConstants.CENTER);
+        equipment_statu_label.setForeground(Color.BLACK);
+        equipment_statu_label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
+        equipment_statu_label.setBackground(Color.LIGHT_GRAY);
+        toolBar.add(equipment_statu_label);
+
+        status_menu = new JButton("设备未连接MES服务器");
+        status_menu.setText("已连接MES服务器");
+        status_menu.setForeground(Color.GREEN);
+        status_menu.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+            }
+        });
+        status_menu.setForeground(Color.GREEN);
+        status_menu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
+        status_menu.setBackground(Color.BLACK);
+        toolBar.add(status_menu);
+
+        JLabel space_1 = new JLabel("    ");
+        toolBar.add(space_1);
+
+        JLabel heart_beat_status_label = new JLabel("心跳:");
+        heart_beat_status_label.setHorizontalAlignment(SwingConstants.CENTER);
+        heart_beat_status_label.setForeground(Color.BLACK);
+        heart_beat_status_label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
+        heart_beat_status_label.setBackground(Color.LIGHT_GRAY);
+        toolBar.add(heart_beat_status_label);
+
+        heart_beat_menu = new JButton("2024-02-20 23:20:10");
+        heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
+        heart_beat_menu.setForeground(Color.GREEN);
+        heart_beat_menu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
+        heart_beat_menu.setBackground(Color.BLACK);
+        toolBar.add(heart_beat_menu);
+
+        JLabel space_2 = new JLabel("    ");
+        toolBar.add(space_2);
+
+        JLabel user_status_label = new JLabel("登录用户:");
+        user_status_label.setHorizontalAlignment(SwingConstants.CENTER);
+        user_status_label.setForeground(Color.BLACK);
+        user_status_label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
+        user_status_label.setBackground(Color.LIGHT_GRAY);
+        toolBar.add(user_status_label);
+
+        user_menu = new JButton("JinJuShi");
+        user_menu.setForeground(Color.GREEN);
+        user_menu.setFont(new Font("微软雅黑", Font.PLAIN, 22));
+        user_menu.setBackground(Color.BLACK);
+        toolBar.add(user_menu);
+
+        JLabel space_3 = new JLabel("    ");
+        toolBar.add(space_3);
+
+        JLabel space_4 = new JLabel("    ");
+        toolBar.add(space_4);
+
+        tabbedPane = new JTabbedPane(JTabbedPane.TOP);
+        tabbedPane.setMinimumSize(new Dimension(400, 50));
+        tabbedPane.setFont(new Font("宋体", Font.BOLD, 22));
+
+        // 保留扫码相关控件引用,避免其他逻辑空指针(不加入界面)
+        product_sn = new JTextField();
+        f_scan_data_bt_1 = new JButton();
+        finish_ok_bt = new JButton();
+        finish_ng_bt = new JButton();
+        fxlabel = new JLabel();
+        fxlabel.setVisible(false);
+
+        // 仅展示焊机加工参数页面
+        welderParamPanel = new WelderParamPanel();
+        contentPane.add(welderParamPanel, BorderLayout.CENTER);
+
+        // ========== 以下页面已隐藏,仅保留加工参数 ==========
+        /*
+        contentPane.add(tabbedPane);
+
+        JPanel indexPanelA = new JPanel();
+        indexScrollPaneA = new JScrollPane(indexPanelA);
+        indexPanelA.setLayout(null);
+
+        product_sn.setHorizontalAlignment(SwingConstants.CENTER);
+        product_sn.setEditable(false);
+        product_sn.setFont(new Font("微软雅黑", Font.PLAIN, 28));
+        product_sn.setBounds(81, 70, 602, 70);
+        indexPanelA.add(product_sn);
+        product_sn.setColumns(10);
+
+        f_scan_data_bt_1.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                scan_type = 1;
+                scanBarcode();
+            }
+        });
+        f_scan_data_bt_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/scan_barcode.png")));
+        f_scan_data_bt_1.setFont(new Font("微软雅黑", Font.PLAIN, 32));
+        f_scan_data_bt_1.setBounds(693, 70, 198, 70);
+        indexPanelA.add(f_scan_data_bt_1);
+
+        fxlabel.setFont(new Font("微软雅黑", Font.PLAIN, 38));
+        fxlabel.setBounds(81, 170, 810, 70);
+        fxlabel.setForeground(Color.RED);
+        fxlabel.setHorizontalAlignment(SwingConstants.CENTER);
+        indexPanelA.add(fxlabel);
+
+        finish_ok_bt.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                if(work_status == 1 && check_quality_result){
+                    getUser();
+                    String sn = MesClient.product_sn.getText().trim();
+                    if(sn.isEmpty()){
+                        MesClient.setMenuStatus("工件码为空,请重试",-1);
+                        return;
+                    }
+
+                    JSONObject retObj = DataUtil.sendQuality(sn,"OK",user20);
+                    System.out.println(retObj);
+                    if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
+                        MesClient.resetScanA();
+                        MesClient.setMenuStatus("结果提交成功,请扫下一件",0);
+                        MesClient.scan_type = 1;
+                        MesClient.scanBarcode();
+                    }else{
+                        if(retObj.get("result")==null){
+                            MesClient.setMenuStatus("请求失败,请重试",-1);
+                        }else{
+                            if(retObj.get("result").toString().equalsIgnoreCase("false")){
+                                MesClient.setMenuStatus(retObj.getString("message"),-1);
+                            }
+                        }
+                    }
+                }
+            }
+        });
+        finish_ok_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
+        finish_ok_bt.setFont(new Font("微软雅黑", Font.PLAIN, 32));
+        finish_ok_bt.setBounds(185, 291, 240, 80);
+        finish_ok_bt.setEnabled(false);
+        indexPanelA.add(finish_ok_bt);
+
+        finish_ng_bt.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                if(work_status == 1 && check_quality_result){
+                    getUser();
+                    String sn = MesClient.product_sn.getText().trim();
+                    if(sn.isEmpty()){
+                        MesClient.setMenuStatus("工件码为空,请重试",-1);
+                        return;
+                    }
+
+                    JSONObject retObj = DataUtil.sendQuality(sn,"NG",user20);
+                    if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
+                        MesClient.resetScanA();
+                        MesClient.setMenuStatus("结果提交成功,请扫下一件",0);
+                        MesClient.scan_type = 1;
+                        MesClient.scanBarcode();
+                    }else{
+                        if(retObj.get("result")==null){
+                            MesClient.setMenuStatus("请求失败,请重试",-1);
+                        }else{
+                            if(retObj.get("result").toString().equalsIgnoreCase("false")){
+                                MesClient.setMenuStatus(retObj.getString("message"),-1);
+                            }
+                        }
+                    }
+                }
+            }
+        });
+        finish_ng_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ng_bg.png")));
+        finish_ng_bt.setFont(new Font("微软雅黑", Font.PLAIN, 32));
+        finish_ng_bt.setBounds(508, 291, 240, 80);
+        finish_ng_bt.setEnabled(false);
+        indexPanelA.add(finish_ng_bt);
+
+        tabbedPane.addTab("工作面板", new ImageIcon(MesClient.class.getResource("/bg/a_side.png")), indexScrollPaneA, null);
+        tabbedPane.setEnabledAt(0, true);
+
+        welderParamPanel = new WelderParamPanel();
+        tabbedPane.addTab("加工参数", new ImageIcon(MesClient.class.getResource("/bg/bar_setting.png")), welderParamPanel, null);
+
+        indexPanelC = new JPanel();
+        searchScrollPaneDj = new JScrollPane(indexPanelC);
+        indexPanelC.setLayout(null);
+        tabbedPane.addTab("开班点检", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPaneDj, null);
+
+        indexPanelB = new JPanel();
+        searchScrollPane = new JScrollPane(indexPanelB);
+        indexPanelB.setLayout(null);
+        tabbedPane.addTab("工作记录", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPane, null);
+
+        tabbedPane.addChangeListener(new ChangeListener() {
+            @Override
+            public void stateChanged(ChangeEvent e) {
+                JTabbedPane tabbedPane = (JTabbedPane) e.getSource();
+                int selectedIndex = tabbedPane.getSelectedIndex();
+                System.out.println("selectedIndex:"+selectedIndex);
+            }
+        });
+        */
+    }
+
+    public static void setMenuStatus(String msg,int error){
+        if(error == 0){
+            MesClient.status_menu.setForeground(Color.GREEN);
+        }else{
+            MesClient.status_menu.setForeground(Color.RED);
+        }
+        MesClient.status_menu.setText(msg);
+    }
+
+    public static void getMaterailData(){
+        try{
+            JSONObject retObj = DataUtil.getBindMaterail();
+            if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
+                java.util.List<BindMaterialResp> arrs = retObj.getList("data",BindMaterialResp.class);
+                int i = 0;
+                rowData = new Object[arrs.size()][7];
+                for (BindMaterialResp bindMaterialResp:arrs){
+                    rowData[i][0] = bindMaterialResp.getMaterialTitle();
+                    rowData[i][1] = bindMaterialResp.getBatchSn();
+                    rowData[i][2] = bindMaterialResp.getLastTimes();
+                    rowData[i][3] = "";
+                    rowData[i][4] = bindMaterialResp.getCraft();
+                    rowData[i][5] = bindMaterialResp.getMaterialId();
+                    rowData[i][6] = bindMaterialResp.getType();
+                    i++;
+                }
+                bindBatchPanel();
+            }
+        }catch (Exception e){
+            log.info(e.getMessage());
+        }
+    }
+
+    public static void updateMaterailData(){
+        try{
+            JSONObject retObj = DataUtil.getBindMaterail();
+            if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
+                List<BindMaterialResp> arrs = retObj.getList("data",BindMaterialResp.class);
+
+                int i = 0;
+                for (BindMaterialResp bindMaterialResp:arrs){
+                    rowData[i][0] = bindMaterialResp.getMaterialTitle();
+                    rowData[i][1] = bindMaterialResp.getBatchSn();
+                    rowData[i][2] = bindMaterialResp.getLastTimes();
+                    rowData[i][3] = "";
+                    rowData[i][4] = bindMaterialResp.getCraft();
+                    rowData[i][5] = bindMaterialResp.getMaterialId();
+                    rowData[i][6] = bindMaterialResp.getType();
+                    i++;
+                }
+
+                MesClient.table.repaint();
+            }
+        }catch (Exception e){
+            log.info(e.getMessage());
+        }
+    }
+
+    // 绑定物料批次码
+    public static void scanBatchSn(BindMaterialResp bindMaterialResp) {
+        //弹窗扫工件码
+        String scanBarcodeTitle = "请扫物料:"+bindMaterialResp.getMaterialTitle();
+        String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
+        if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")) {
+
+            JSONObject retObj = DataUtil.saveBindMaterail(scanBarcode,bindMaterialResp.getCraft(),bindMaterialResp.getMaterialId(),bindMaterialResp.getType());
+            if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
+                MesClient.setMenuStatus("扫物料:"+bindMaterialResp.getMaterialTitle()+"成功",0);
+                updateMaterailData();
+            }else{
+                if(retObj.get("result")==null){
+                    MesClient.setMenuStatus("请求失败,请重试",-1);
+                }else{
+                    if(retObj.get("result").toString().equalsIgnoreCase("false")){
+                        MesClient.setMenuStatus(retObj.getString("message"),-1);
+                    }
+                }
+            }
+        }
+    }
+
+    public static void bindBatchPanel(){
+        JPanel indexPanelBB = new JPanel();
+        JPanel panel = new JPanel();
+        panel.setBounds(0, 0, 990, 550);
+//        panel.setBounds(81, 50, 810, 479);
+        indexPanelBB.add(panel);
+
+        panel.setLayout(new GridLayout(0, 1, 0, 0));
+        table = new JTable(rowData, columnNames){
+            public boolean isCellEditable(int row, int column) {
+                if(column == 3){
+                    return true;
+                }
+                return false;
+            }
+        };
+        table.setRowHeight(40);
+        table.setEnabled(true);
+        table.setFont(new Font("微软雅黑", Font.PLAIN, 14));
+
+        table.getColumnModel().getColumn(3).setCellRenderer(new TableCellRendererButton());
+        table.getColumnModel().getColumn(3).setCellEditor(new TableCellEditorButton());
+
+
+        JScrollPane scrollPane = new JScrollPane(table);
+        panel.add(scrollPane);
+
+        JScrollPane indexScrollPaneB = new JScrollPane(indexPanelBB);
+        indexPanelBB.setLayout(null);
+        tabbedPane.addTab("绑定物料", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), indexScrollPaneB, null);
+    }
+
+    public static void startGetCurSn(){
+        if (getSnBeatTimer != null) {
+            getSnBeatTimer.cancel();
+        }
+        getSnBeatTimer = new Timer();
+        getSnBeatTimer.schedule(new TimerTask() {
+            @Override
+            public void run() {
+                System.out.println("kaishi");
+                if (work_status == 1) {
+                    return;
+                } else if (work_status == 0) {
+                    JSONObject result = DataUtil.getCurSn(mes_gw, mes_server_ip, mes_line_sn);
+                    // 正常处理结果
+                    if (result.containsKey("data")) {
+                        String data = result.getString("data");
+                        if (data != null && !data.isEmpty()) {
+                            product_sn.setText(data);
+                            JSONObject jsonObject = DataUtil.checkQuality(data, user20);
+                            String msg = jsonObject.getString("message");
+                            if (jsonObject.getString("result").equalsIgnoreCase("true")) {
+                                finish_ng_bt.setEnabled(true);
+                                finish_ok_bt.setEnabled(true);
+                                check_quality_result = true;
+                                work_status = 1;
+                                MesClient.setMenuStatus(msg,0);
+                            } else {
+                                work_status = 0;
+                                String msg2 = (jsonObject != null && jsonObject.containsKey("message")) ? jsonObject.getString("message") : "检查失败";
+                                MesClient.setMenuStatus(msg2,-1);
+                                check_quality_result = false;
+                            }
+                        }
+                    }
+                }
+            }
+
+        }, 100, 1000);
+    }
+
+    // 开启发送结果定时任务
+    public static void startUpdateQualityTimer(){
+        // 创建异步线程池
+        ExecutorService executorService = Executors.newSingleThreadExecutor();
+        // 提交任务
+        executorService.submit(() -> {
+            log.info("异步任务执行中...");
+            // 模拟耗时操作
+            try {
+                while (true){
+                    try {
+                        // 确保连接已经打开
+                        if (JdbcUtils.conn == null || JdbcUtils.conn.isClosed()) {
+                            JdbcUtils.openConnection();
+                        }
+
+                        Statement statement = JdbcUtils.conn.createStatement();
+                        String selectSql = "SELECT id, bw FROM submit_record\n" +
+                                "WHERE state = 0 ORDER BY id DESC LIMIT 10";
+                        String updateSql = "UPDATE submit_record \n" +
+                                "SET state = '1'\n" +
+                                "WHERE id = ";
+                        ResultSet rs = statement.executeQuery(selectSql);
+                        while(rs.next()){
+                            int id = rs.getInt("id");
+                            String bw = rs.getString("bw");
+                            // 发送请求
+                            String url = "http://"+MesClient.mes_server_ip+":8980/js/a/mes/mesProductRecord/updateQualityByTiming";
+                            log.info("质量:"+bw);
+                            String s = HttpUtils.sendPostRequestJson(url, bw );
+                            log.info("结果:"+s);
+                            Boolean result = JSONObject.parseObject(s).getBoolean("result");
+                            if(result) {
+                                // 更改状态为 1
+                                statement.executeUpdate(updateSql + id);
+                            }
+                        }
+                        rs.close();
+                        statement.close();
+                    } catch (Exception e) {
+                        log.info(e.getMessage());
+                    }
+                    try {
+                        Thread.sleep(2000);
+                    }catch (Exception e){
+                        log.info(e.getMessage());
+                    }
+                }
+            } catch (Exception e) {
+                log.info(e.getMessage());
+            }
+            log.info("异步任务执行完毕");
+        });
+    }
+}

+ 92 - 0
src/com/mes/ui/OprnoUtil.java

@@ -0,0 +1,92 @@
+package com.mes.ui;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+public class OprnoUtil {
+    public static String[] xtoprnos = new String[]{
+            "OP010",
+            "OP030",
+            "OP050",
+            "OP060",
+            "OP070",
+            "OP080",
+            "OP090",
+            "OP100",
+            "OP110",
+            "OP120",
+            "OP130",
+            "OP140",
+            "OP150",
+            "OP160",
+            "OP190",
+            "OP210",
+            "OP220"
+    };
+
+    public static String[] xtoprnodes = new String[]{
+            "镭雕",
+            "凸焊",
+            "左右吊耳组件弧焊",
+            "左右吊耳组件点焊",
+            "电池壳分总成1点焊",
+            "电池壳分总成1点焊补焊",
+            "电池壳分总成2点焊",
+            "电池壳分总成2点焊补焊",
+            "电池壳分总成3点焊",
+            "电池壳分总成4点焊",
+            "电池壳分总成5点焊补焊",
+            "电池壳分总成6弧焊",
+            "电池壳分总成7弧焊",
+            "电池壳分总成8弧焊",
+            "气密检测",
+            "拉铆",
+            "总成气密检测"
+    };
+    public static String[] lboprnos = new String[]{
+            "OP010","OP040", "OP060", "OP070", "OP080",
+            "OP110", "OP130", "OP150", "OP180", "OP190",
+    };
+    public static String[] lboprnodes = new String[]{
+            "镭雕二维码","左右边框总成", "前后边框总成", "总成框架拼焊-A", "总成框架弧焊-B",
+            "气密检测", "拉铆框架正面", "液冷板装配拉铆", "总成气密检测", "在线检测"
+    };
+    public static String getGwDes(String lineSn,String oprno){
+        String des = "";
+        oprno = formatOprno(oprno);
+        if(lineSn.equals("HEVXT")){
+            int i = 0;
+            for (String gw:xtoprnos){
+                if(gw.equals(oprno)){
+                    des = xtoprnodes[i];
+                    break;
+                }
+                i++;
+            }
+        }else if(lineSn.equals("115XT")){
+            int i = 0;
+            for (String gw:lboprnos){
+                if(gw.equals(oprno)){
+                    des = lboprnodes[i];
+                    break;
+                }
+                i++;
+            }
+        }
+        return des;
+    }
+
+    public static String formatOprno(String oprno){
+        List<String> lists = new ArrayList<>();
+
+        if(oprno.length() == 6){
+            String ysoprno = oprno.substring(0,5).trim();
+            if(!lists.contains(ysoprno)){
+                oprno = ysoprno;
+            }
+        }
+
+        return  oprno;
+    }
+}

+ 43 - 0
src/com/mes/ui/TableCellEditorButton.java

@@ -0,0 +1,43 @@
+package com.mes.ui;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+public class TableCellEditorButton extends DefaultCellEditor {
+    private JButton btn;
+    public TableCellEditorButton() {
+        super(new JTextField());
+        //设置点击一次就激活,否则默认好像是点击2次激活。
+        this.setClickCountToStart(1);
+        btn = new JButton("扫码");
+        btn.addActionListener(new ActionListener() {
+
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                System.out.println("按钮事件触发----");
+                int selectedRow = MesClient.table.getSelectedRow();//获得选中行的索引
+//                MesClient.rowData[selectedRow][1] = (new Date()).getTime();
+//                MesClient.table.repaint(); //重绘
+
+//                MesClient.scan_type = selectedRow + 4;
+                BindMaterialResp bindMaterialResp = new BindMaterialResp();
+                bindMaterialResp.setMaterialTitle(MesClient.rowData[selectedRow][0] + "");
+                bindMaterialResp.setBatchSn(MesClient.rowData[selectedRow][1] + "");
+                bindMaterialResp.setLastTimes(MesClient.rowData[selectedRow][2] + "");
+                bindMaterialResp.setCraft(MesClient.rowData[selectedRow][4] + "");
+                bindMaterialResp.setMaterialId(MesClient.rowData[selectedRow][5] + "");
+                bindMaterialResp.setType(MesClient.rowData[selectedRow][6] + "");
+
+                MesClient.scanBatchSn(bindMaterialResp);
+            }
+        });
+
+    }
+    @Override
+    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
+
+        return btn;
+    }
+}

+ 14 - 0
src/com/mes/ui/TableCellRendererButton.java

@@ -0,0 +1,14 @@
+package com.mes.ui;
+
+import javax.swing.*;
+import javax.swing.table.TableCellRenderer;
+import java.awt.*;
+
+public class TableCellRendererButton implements TableCellRenderer {
+    @Override
+    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
+                                                   int row, int column) {
+        JButton button = new JButton("扫码");
+        return button;
+    }
+}

+ 182 - 0
src/com/mes/ui/WelderParamPanel.java

@@ -0,0 +1,182 @@
+package com.mes.ui;
+
+import com.mes.util.WelderParamData;
+
+import javax.swing.*;
+import javax.swing.border.TitledBorder;
+import java.awt.*;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * 焊机加工参数展示面板(只读,不涉及扫码与后台提交)
+ */
+public class WelderParamPanel extends JPanel {
+
+    private final JLabel connLabel = new JLabel("通讯:未连接");
+    private final JLabel updateLabel = new JLabel("最近刷新:--");
+    private final Map<String, JLabel> valueLabels = new LinkedHashMap<>();
+
+    public WelderParamPanel() {
+        setLayout(new BorderLayout(8, 8));
+        setBackground(Color.WHITE);
+        initUI();
+    }
+
+    private void initUI() {
+        JPanel topPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 16, 8));
+        topPanel.setBackground(new Color(248, 248, 248));
+        connLabel.setFont(new Font("微软雅黑", Font.BOLD, 18));
+        updateLabel.setFont(new Font("微软雅黑", Font.PLAIN, 14));
+        topPanel.add(connLabel);
+        topPanel.add(updateLabel);
+        add(topPanel, BorderLayout.NORTH);
+
+        JPanel center = new JPanel(new GridLayout(1, 3, 12, 0));
+        center.setBorder(BorderFactory.createEmptyBorder(8, 12, 12, 12));
+        center.setBackground(Color.WHITE);
+        center.add(createSection("设备状态", new String[][]{
+                {"工作模式", "workMode"},
+                {"运行状态", "runState"},
+                {"修模状态", "toolingState"},
+                {"报警信息", "alarmText"},
+                {"当前规范号", "specNo"},
+                {"焊接计数", "weldCount"},
+                {"电容电压", "capVoltage"}
+        }));
+        center.add(createSection("当前规范设定", new String[][]{
+                {"预压时间", "prePressTime"},
+                {"加压时间", "pressTime"},
+                {"预热电压", "specPreheatVoltage"},
+                {"预热电流", "specPreheatCurrent"},
+                {"预热时间", "specPreheatTime"},
+                {"焊接电压", "specWeldVoltage"},
+                {"焊接电流", "specWeldCurrent"},
+                {"焊接时间", "specWeldTime"},
+                {"回火电压", "specTemperVoltage"},
+                {"回火电流", "specTemperCurrent"},
+                {"回火时间", "specTemperTime"}
+        }));
+        center.add(createSection("最近焊接结果", new String[][]{
+                {"预热电压", "preheatVoltage"},
+                {"焊接电压", "weldVoltage"},
+                {"回火电压", "temperVoltage"},
+                {"预热峰值电流", "preheatPeakCurrent"},
+                {"焊接峰值电流", "weldPeakCurrent"},
+                {"回火峰值电流", "temperPeakCurrent"}
+        }));
+        add(center, BorderLayout.CENTER);
+    }
+
+    private JPanel createSection(String title, String[][] fields) {
+        JPanel panel = new JPanel(new GridBagLayout());
+        panel.setBackground(Color.WHITE);
+        panel.setBorder(BorderFactory.createTitledBorder(
+                BorderFactory.createLineBorder(new Color(210, 210, 210)),
+                title,
+                TitledBorder.LEFT,
+                TitledBorder.TOP,
+                new Font("微软雅黑", Font.BOLD, 16),
+                new Color(50, 50, 50)
+        ));
+
+        GridBagConstraints gc = new GridBagConstraints();
+        gc.insets = new Insets(6, 8, 6, 8);
+        gc.anchor = GridBagConstraints.WEST;
+        gc.fill = GridBagConstraints.HORIZONTAL;
+        gc.weightx = 1;
+
+        for (int i = 0; i < fields.length; i++) {
+            gc.gridx = 0;
+            gc.gridy = i;
+            JLabel nameLabel = new JLabel(fields[i][0] + ":");
+            nameLabel.setFont(new Font("微软雅黑", Font.PLAIN, 15));
+            panel.add(nameLabel, gc);
+
+            gc.gridx = 1;
+            JLabel valueLabel = new JLabel("--");
+            valueLabel.setFont(new Font("微软雅黑", Font.BOLD, 16));
+            valueLabel.setForeground(new Color(0, 102, 153));
+            panel.add(valueLabel, gc);
+            valueLabels.put(fields[i][1], valueLabel);
+        }
+        return panel;
+    }
+
+    public void updateData(WelderParamData data) {
+        if (data == null) {
+            return;
+        }
+        if (data.connected) {
+            connLabel.setText("通讯:已连接");
+            connLabel.setForeground(new Color(0, 128, 0));
+        } else {
+            connLabel.setText("通讯:异常 - " + safe(data.errorMessage));
+            connLabel.setForeground(Color.RED);
+        }
+        updateLabel.setText("最近刷新:" + new java.text.SimpleDateFormat("HH:mm:ss").format(new java.util.Date()));
+
+        setValue("workMode", data.workMode);
+        setValue("runState", data.runState);
+        setValue("toolingState", data.toolingState);
+        setValue("alarmText", data.alarmText, isAlarm(data.alarmText) ? Color.RED : new Color(0, 102, 153));
+        setValue("specNo", data.specNo > 0 ? String.valueOf(data.specNo) : "--");
+        setValue("weldCount", String.valueOf(data.weldCount));
+        setValue("capVoltage", data.capVoltage > 0 ? data.capVoltage + " V" : "--");
+
+        setValue("prePressTime", formatTime(data.prePressTime));
+        setValue("pressTime", formatTime(data.pressTime));
+        setValue("specPreheatVoltage", formatVoltage(data.specPreheatVoltage));
+        setValue("specPreheatCurrent", formatCurrentSetting(data.specPreheatCurrent));
+        setValue("specPreheatTime", formatMs(data.specPreheatTime));
+        setValue("specWeldVoltage", formatVoltage(data.specWeldVoltage));
+        setValue("specWeldCurrent", formatCurrentSetting(data.specWeldCurrent));
+        setValue("specWeldTime", formatMs(data.specWeldTime));
+        setValue("specTemperVoltage", formatVoltage(data.specTemperVoltage));
+        setValue("specTemperCurrent", formatCurrentSetting(data.specTemperCurrent));
+        setValue("specTemperTime", formatMs(data.specTemperTime));
+
+        setValue("preheatVoltage", formatVoltage(data.preheatVoltage));
+        setValue("weldVoltage", formatVoltage(data.weldVoltage));
+        setValue("temperVoltage", formatVoltage(data.temperVoltage));
+        setValue("preheatPeakCurrent", safe(data.preheatPeakCurrent));
+        setValue("weldPeakCurrent", safe(data.weldPeakCurrent));
+        setValue("temperPeakCurrent", safe(data.temperPeakCurrent));
+    }
+
+    private void setValue(String key, String text) {
+        setValue(key, text, new Color(0, 102, 153));
+    }
+
+    private void setValue(String key, String text, Color color) {
+        JLabel label = valueLabels.get(key);
+        if (label != null) {
+            label.setText(safe(text));
+            label.setForeground(color);
+        }
+    }
+
+    private static boolean isAlarm(String alarmText) {
+        return alarmText != null && !"无报警".equals(alarmText) && !alarmText.isEmpty();
+    }
+
+    private static String formatTime(int value) {
+        return value > 0 ? value + " t" : "--";
+    }
+
+    private static String formatMs(int value) {
+        return value > 0 ? value + " ms" : "--";
+    }
+
+    private static String formatVoltage(int value) {
+        return value > 0 ? value + " V" : "--";
+    }
+
+    private static String formatCurrentSetting(int value) {
+        return value > 0 ? value + " KA" : "--";
+    }
+
+    private static String safe(String text) {
+        return text == null || text.isEmpty() ? "--" : text;
+    }
+}

+ 97 - 0
src/com/mes/ui/WelderParamService.java

@@ -0,0 +1,97 @@
+package com.mes.ui;
+
+import com.mes.util.ModbusRtuClient;
+import com.mes.util.WelderConfig;
+import com.mes.util.WelderParamData;
+import com.mes.util.WelderParamReader;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.swing.*;
+
+/**
+ * 焊机参数轮询服务
+ */
+public class WelderParamService {
+
+    private static final Logger log = LoggerFactory.getLogger(WelderParamService.class);
+
+    private static WelderParamService instance;
+
+    private WelderConfig config;
+    private ModbusRtuClient client;
+    private WelderParamReader reader;
+    private Timer pollTimer;
+    private WelderParamPanel panel;
+
+    public static synchronized WelderParamService getInstance() {
+        if (instance == null) {
+            instance = new WelderParamService();
+        }
+        return instance;
+    }
+
+    public void bindPanel(WelderParamPanel panel) {
+        this.panel = panel;
+    }
+
+    public void start() {
+        stop();
+        config = WelderConfig.load();
+        if (!config.enabled) {
+            log.info("焊机参数展示未启用(welder.enabled=false)");
+            if (panel != null) {
+                SwingUtilities.invokeLater(() -> panel.updateData(WelderParamData.disconnected("未启用焊机通讯")));
+            }
+            return;
+        }
+
+        client = new ModbusRtuClient();
+        reader = new WelderParamReader(client);
+        if (!client.open(config)) {
+            if (panel != null) {
+                SwingUtilities.invokeLater(() -> panel.updateData(
+                        WelderParamData.disconnected("无法打开串口 " + config.port)));
+            }
+            return;
+        }
+
+        pollTimer = new Timer(config.pollIntervalMs, e -> pollOnce());
+        pollTimer.setInitialDelay(0);
+        pollTimer.start();
+        log.info("焊机参数轮询已启动, 端口={}, 站号={}", config.port, config.slaveId);
+    }
+
+    public void stop() {
+        if (pollTimer != null) {
+            pollTimer.stop();
+            pollTimer = null;
+        }
+        if (client != null) {
+            client.close();
+            client = null;
+        }
+        reader = null;
+    }
+
+    private void pollOnce() {
+        if (reader == null || panel == null) {
+            return;
+        }
+        new SwingWorker<WelderParamData, Void>() {
+            @Override
+            protected WelderParamData doInBackground() {
+                return reader.read();
+            }
+
+            @Override
+            protected void done() {
+                try {
+                    panel.updateData(get());
+                } catch (Exception ex) {
+                    panel.updateData(WelderParamData.disconnected(ex.getMessage()));
+                }
+            }
+        }.execute();
+    }
+}

+ 61 - 0
src/com/mes/ui/WorkRecordData.java

@@ -0,0 +1,61 @@
+package com.mes.ui;
+
+/**
+ * 工作记录数据实体类
+ */
+public class WorkRecordData {
+    private String id;
+    private String sn;          // 工件码
+    private String oprno;       // 工位号
+    private String updateBy;    // 作业人员
+    private String updateDate;  // 日期
+    private String content;     // 工位结果
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public String getSn() {
+        return sn;
+    }
+
+    public void setSn(String sn) {
+        this.sn = sn;
+    }
+
+    public String getOprno() {
+        return oprno;
+    }
+
+    public void setOprno(String oprno) {
+        this.oprno = oprno;
+    }
+
+    public String getUpdateBy() {
+        return updateBy;
+    }
+
+    public void setUpdateBy(String updateBy) {
+        this.updateBy = updateBy;
+    }
+
+    public String getUpdateDate() {
+        return updateDate;
+    }
+
+    public void setUpdateDate(String updateDate) {
+        this.updateDate = updateDate;
+    }
+
+    public String getContent() {
+        return content;
+    }
+
+    public void setContent(String content) {
+        this.content = content;
+    }
+}

+ 403 - 0
src/com/mes/ui/WorkRecordPanel.java

@@ -0,0 +1,403 @@
+package com.mes.ui;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.swing.*;
+import javax.swing.table.DefaultTableCellRenderer;
+import javax.swing.table.DefaultTableModel;
+import javax.swing.table.TableColumn;
+import java.awt.*;
+import java.awt.event.ComponentAdapter;
+import java.awt.event.ComponentEvent;
+import java.util.List;
+
+/**
+ * 工作记录面板组件
+ * 支持分页查询和展示工作记录数据
+ */
+public class WorkRecordPanel extends JPanel {
+
+    private static final Logger log = LoggerFactory.getLogger(WorkRecordPanel.class);
+
+    // 表格列名
+    private static final String[] COLUMN_NAMES = {"工件码", "工位号", "工位结果", "作业人员", "日期"};
+
+    // 分页配置
+    private static final int PAGE_SIZE = 20;
+
+    // 查询条件
+    private String oprno;  // 工位号(null或空则查全部)
+    private String lineSn; // 产线编号
+    private boolean isAllStation; // 是否是"所有工位"模式
+
+    // 分页状态
+    private int pageNo = 1;
+    private long totalCount = 0;
+    private int totalPages = 0;
+
+    // UI组件
+    private JTable table;
+    private DefaultTableModel tableModel;
+    private JLabel pageLabel;
+    private JButton btnPrevious;
+    private JButton btnNext;
+    private JButton btnRefresh;
+    private JButton btnSearch;
+    private JLabel statusLabel;
+    private JTextField snSearchField;      // 工件码搜索框
+    private JTextField oprnoSearchField;   // 工位号搜索框(仅"所有工位"模式)
+    private JLabel snLabel;
+    private JLabel oprnoLabel;
+
+    /**
+     * 构造函数
+     * @param oprno 工位号(如OP150A查询该工位,null或空则查所有工位)
+     * @param lineSn 产线编号
+     */
+    public WorkRecordPanel(String oprno, String lineSn) {
+        this.oprno = oprno;
+        this.lineSn = lineSn;
+        this.isAllStation = (oprno == null || oprno.isEmpty());
+        initUI();
+    }
+
+    /**
+     * 初始化UI
+     */
+    private void initUI() {
+        setLayout(null);
+        setBackground(Color.WHITE);
+
+        // 顶部控制区
+        JPanel topPanel = new JPanel();
+        topPanel.setLayout(null);
+        topPanel.setBounds(0, 0, 1200, 50);
+        topPanel.setBackground(new Color(248, 248, 248));
+        add(topPanel);
+
+        int xPos = 10;
+
+        // 状态标签
+        String displayOprno = isAllStation ? "所有工位" : oprno;
+        statusLabel = new JLabel("工位:" + displayOprno);
+        statusLabel.setFont(new Font("微软雅黑", Font.PLAIN, 13));
+        statusLabel.setBounds(xPos, 10, 160, 30);
+        topPanel.add(statusLabel);
+        xPos += 165;
+
+        // 工件码搜索
+        snLabel = new JLabel("工件码:");
+        snLabel.setFont(new Font("微软雅黑", Font.PLAIN, 13));
+        snLabel.setBounds(xPos, 10, 50, 30);
+        topPanel.add(snLabel);
+        xPos += 52;
+
+        snSearchField = new JTextField();
+        snSearchField.setFont(new Font("微软雅黑", Font.PLAIN, 13));
+        snSearchField.setBounds(xPos, 10, 200, 30);
+        snSearchField.addActionListener(e -> doSearch()); // 回车搜索
+        topPanel.add(snSearchField);
+        xPos += 210;
+
+        // 工位号搜索(仅"所有工位"模式显示)
+        if (isAllStation) {
+            oprnoLabel = new JLabel("工位:");
+            oprnoLabel.setFont(new Font("微软雅黑", Font.PLAIN, 13));
+            oprnoLabel.setBounds(xPos, 10, 40, 30);
+            topPanel.add(oprnoLabel);
+            xPos += 42;
+
+            oprnoSearchField = new JTextField();
+            oprnoSearchField.setFont(new Font("微软雅黑", Font.PLAIN, 13));
+            oprnoSearchField.setBounds(xPos, 10, 100, 30);
+            oprnoSearchField.addActionListener(e -> doSearch()); // 回车搜索
+            topPanel.add(oprnoSearchField);
+            xPos += 110;
+        }
+
+        // 查询按钮
+        btnSearch = new JButton("查询");
+        btnSearch.setFont(new Font("微软雅黑", Font.PLAIN, 13));
+        btnSearch.setBounds(xPos, 10, 70, 30);
+        btnSearch.addActionListener(e -> doSearch());
+        topPanel.add(btnSearch);
+        xPos += 80;
+
+        // 刷新按钮
+        btnRefresh = new JButton("刷新");
+        btnRefresh.setFont(new Font("微软雅黑", Font.PLAIN, 13));
+        btnRefresh.setBounds(xPos, 10, 70, 30);
+        btnRefresh.addActionListener(e -> {
+            clearSearchFields();
+            refreshData();
+        });
+        topPanel.add(btnRefresh);
+        xPos += 80;
+
+        // 上一页按钮
+        btnPrevious = new JButton("上一页");
+        btnPrevious.setFont(new Font("微软雅黑", Font.PLAIN, 13));
+        btnPrevious.setBounds(xPos, 10, 80, 30);
+        btnPrevious.addActionListener(e -> {
+            if (pageNo > 1) {
+                pageNo--;
+                loadData();
+            }
+        });
+        topPanel.add(btnPrevious);
+        xPos += 85;
+
+        // 页码显示
+        pageLabel = new JLabel("0/0");
+        pageLabel.setFont(new Font("微软雅黑", Font.PLAIN, 13));
+        pageLabel.setHorizontalAlignment(SwingConstants.CENTER);
+        pageLabel.setBorder(BorderFactory.createLineBorder(Color.GRAY, 1));
+        pageLabel.setBounds(xPos, 10, 70, 30);
+        topPanel.add(pageLabel);
+        xPos += 75;
+
+        // 下一页按钮
+        btnNext = new JButton("下一页");
+        btnNext.setFont(new Font("微软雅黑", Font.PLAIN, 13));
+        btnNext.setBounds(xPos, 10, 80, 30);
+        btnNext.addActionListener(e -> {
+            if (pageNo < totalPages) {
+                pageNo++;
+                loadData();
+            }
+        });
+        topPanel.add(btnNext);
+
+        // 表格面板
+        JPanel tablePanel = new JPanel();
+        tablePanel.setBounds(0, 50, 1200, 518);
+        tablePanel.setLayout(new GridLayout(1, 1, 0, 0));
+        add(tablePanel);
+
+        // 创建表格模型
+        tableModel = new DefaultTableModel(COLUMN_NAMES, 0) {
+            @Override
+            public boolean isCellEditable(int row, int column) {
+                return false;
+            }
+        };
+
+        // 创建表格
+        table = new JTable(tableModel);
+        table.setRowHeight(32);
+        table.setFont(new Font("微软雅黑", Font.PLAIN, 13));
+        table.getTableHeader().setFont(new Font("微软雅黑", Font.BOLD, 14));
+        table.getTableHeader().setReorderingAllowed(false);
+
+        // 设置列宽
+        setColumnWidths();
+
+        // 设置居中渲染器
+        DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
+        centerRenderer.setHorizontalAlignment(JLabel.CENTER);
+        for (int i = 0; i < table.getColumnCount(); i++) {
+            table.getColumnModel().getColumn(i).setCellRenderer(centerRenderer);
+        }
+
+        // 添加滚动面板
+        JScrollPane scrollPane = new JScrollPane(table);
+        tablePanel.add(scrollPane);
+
+        // 添加组件大小变化监听器
+        addComponentListener(new ComponentAdapter() {
+            @Override
+            public void componentResized(ComponentEvent e) {
+                int w = getWidth();
+                int h = getHeight();
+
+                // 调整顶部面板宽度
+                topPanel.setBounds(0, 0, w, 50);
+
+                // 调整表格面板
+                if (h > 50) {
+                    tablePanel.setBounds(0, 50, w, h - 50);
+                }
+
+                topPanel.revalidate();
+                tablePanel.revalidate();
+            }
+        });
+    }
+
+    /**
+     * 设置列宽
+     */
+    private void setColumnWidths() {
+        TableColumn column;
+        // 工件码
+        column = table.getColumnModel().getColumn(0);
+        column.setPreferredWidth(260);
+        // 工位号
+        column = table.getColumnModel().getColumn(1);
+        column.setPreferredWidth(90);
+        // 工位结果
+        column = table.getColumnModel().getColumn(2);
+        column.setPreferredWidth(70);
+        // 作业人员
+        column = table.getColumnModel().getColumn(3);
+        column.setPreferredWidth(100);
+        // 日期
+        column = table.getColumnModel().getColumn(4);
+        column.setPreferredWidth(150);
+    }
+
+    /**
+     * 清空搜索框
+     */
+    private void clearSearchFields() {
+        snSearchField.setText("");
+        if (oprnoSearchField != null) {
+            oprnoSearchField.setText("");
+        }
+    }
+
+    /**
+     * 执行搜索
+     */
+    private void doSearch() {
+        pageNo = 1;
+        loadData();
+    }
+
+    /**
+     * 刷新数据(重置到第一页)
+     */
+    public void refreshData() {
+        pageNo = 1;
+        loadData();
+    }
+
+    /**
+     * 加载数据
+     */
+    public void loadData() {
+        // 获取搜索条件
+        String searchSn = snSearchField.getText().trim();
+        String searchOprno = oprno; // 默认使用构造函数传入的工位号
+
+        // 如果是"所有工位"模式,检查是否有工位号搜索条件
+        if (isAllStation && oprnoSearchField != null) {
+            String inputOprno = oprnoSearchField.getText().trim();
+            if (!inputOprno.isEmpty()) {
+                searchOprno = inputOprno;
+            }
+        }
+
+        final String finalSearchOprno = searchOprno;
+        final String finalSearchSn = searchSn;
+
+        // 在后台线程中执行数据加载
+        SwingWorker<WorkRecordResp, Void> worker = new SwingWorker<WorkRecordResp, Void>() {
+            @Override
+            protected WorkRecordResp doInBackground() throws Exception {
+                // 更新状态
+                SwingUtilities.invokeLater(() -> {
+                    statusLabel.setText("正在加载...");
+                    setButtonsEnabled(false);
+                });
+
+                // 调用接口查询数据
+                return DataUtil.getWorkRecordList(finalSearchOprno, finalSearchSn, pageNo, PAGE_SIZE);
+            }
+
+            @Override
+            protected void done() {
+                try {
+                    WorkRecordResp resp = get();
+                    updateUI(resp, finalSearchOprno);
+                } catch (Exception e) {
+                    log.error("加载工作记录失败: {}", e.getMessage());
+                    updateUIError("加载失败: " + e.getMessage());
+                }
+            }
+        };
+        worker.execute();
+    }
+
+    /**
+     * 设置按钮启用状态
+     */
+    private void setButtonsEnabled(boolean enabled) {
+        btnSearch.setEnabled(enabled);
+        btnRefresh.setEnabled(enabled);
+        btnPrevious.setEnabled(enabled && pageNo > 1);
+        btnNext.setEnabled(enabled && pageNo < totalPages);
+    }
+
+    /**
+     * 更新UI显示数据
+     */
+    private void updateUI(WorkRecordResp resp, String queryOprno) {
+        // 清空表格
+        tableModel.setRowCount(0);
+
+        if (resp == null || !resp.isResult()) {
+            String msg = resp != null ? resp.getMessage() : "请求失败";
+            updateUIError(msg);
+            return;
+        }
+
+        // 更新分页信息
+        totalCount = resp.getCount();
+        totalPages = (int) Math.ceil((double) totalCount / PAGE_SIZE);
+        if (totalPages == 0) totalPages = 1;
+
+        // 更新页码显示
+        pageLabel.setText(pageNo + "/" + totalPages);
+
+        // 更新按钮状态
+        setButtonsEnabled(true);
+
+        // 更新状态标签
+        String oprnoDisplay;
+        if (isAllStation) {
+            oprnoDisplay = (queryOprno == null || queryOprno.isEmpty()) ? "所有工位" : queryOprno;
+        } else {
+            oprnoDisplay = oprno;
+        }
+        statusLabel.setText("工位:" + oprnoDisplay + " 共" + totalCount + "条");
+
+        // 填充表格数据
+        List<WorkRecordData> list = resp.getList();
+        if (list != null && !list.isEmpty()) {
+            for (WorkRecordData data : list) {
+                Object[] row = {
+                        data.getSn(),
+                        data.getOprno(),
+                        data.getContent(),
+                        data.getUpdateBy(),
+                        data.getUpdateDate()
+                };
+                tableModel.addRow(row);
+            }
+        }
+
+        // 刷新表格
+        table.repaint();
+    }
+
+    /**
+     * 更新UI显示错误信息
+     */
+    private void updateUIError(String message) {
+        statusLabel.setText("错误: " + message);
+        pageLabel.setText("0/0");
+        setButtonsEnabled(true);
+        btnPrevious.setEnabled(false);
+        btnNext.setEnabled(false);
+        tableModel.setRowCount(0);
+    }
+
+    /**
+     * 获取当前工位号
+     */
+    public String getOprno() {
+        return oprno;
+    }
+}

+ 63 - 0
src/com/mes/ui/WorkRecordResp.java

@@ -0,0 +1,63 @@
+package com.mes.ui;
+
+import java.util.List;
+
+/**
+ * 工作记录查询响应实体类
+ */
+public class WorkRecordResp {
+    private boolean result;
+    private String message;
+    private int pageNo;
+    private int pageSize;
+    private long count;
+    private List<WorkRecordData> list;
+
+    public boolean isResult() {
+        return result;
+    }
+
+    public void setResult(boolean result) {
+        this.result = result;
+    }
+
+    public String getMessage() {
+        return message;
+    }
+
+    public void setMessage(String message) {
+        this.message = message;
+    }
+
+    public int getPageNo() {
+        return pageNo;
+    }
+
+    public void setPageNo(int pageNo) {
+        this.pageNo = pageNo;
+    }
+
+    public int getPageSize() {
+        return pageSize;
+    }
+
+    public void setPageSize(int pageSize) {
+        this.pageSize = pageSize;
+    }
+
+    public long getCount() {
+        return count;
+    }
+
+    public void setCount(long count) {
+        this.count = count;
+    }
+
+    public List<WorkRecordData> getList() {
+        return list;
+    }
+
+    public void setList(List<WorkRecordData> list) {
+        this.list = list;
+    }
+}

+ 11 - 0
src/com/mes/util/Base64Utils.java

@@ -0,0 +1,11 @@
+package com.mes.util;
+
+import org.apache.commons.codec.binary.Base64;
+
+public class Base64Utils {
+	public static String getBase64(String str) {
+        byte[] binaryData = str.getBytes();
+        String encodedString = Base64.encodeBase64String(binaryData);
+        return encodedString;
+	}
+}

+ 32 - 0
src/com/mes/util/DateLocalUtils.java

@@ -0,0 +1,32 @@
+package com.mes.util;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+public class DateLocalUtils {
+	public static SimpleDateFormat DATA_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
+	public static SimpleDateFormat DATA_FORMAT1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
+	
+	
+	public static String getCurrentTime() {
+		String currentTime = DATA_FORMAT.format(new Date());
+		return currentTime;
+	}
+	
+	public static String getCurrentTime1() {
+		String currentTime = DATA_FORMAT1.format(new Date());
+		return currentTime;
+	}
+
+	public static SimpleDateFormat DATA_FORMAT2 = new SimpleDateFormat("yyyy-MM-dd");
+	public static String getCurrentDate() {
+		String currentTime = DATA_FORMAT2.format(new Date());
+		return currentTime;
+	}
+
+	public static SimpleDateFormat DATA_FORMAT3 = new SimpleDateFormat("HH:mm:ss");
+	public static String getCurrentTimeHMS() {
+		String currentTime = DATA_FORMAT3.format(new Date());
+		return currentTime;
+	}
+}

+ 53 - 0
src/com/mes/util/ErrorMsg.java

@@ -0,0 +1,53 @@
+package com.mes.util;
+
+public class ErrorMsg {
+    public static String getErrorMsg(String processMsgRet,String lx){
+        String lmsg = "该工件本工位不可加工";
+        try{
+            if(processMsgRet.equalsIgnoreCase("OK")||processMsgRet.equalsIgnoreCase("NG")) {
+                lmsg = "该工件本工位已加工,结果:"+processMsgRet;
+            }else if(processMsgRet.equalsIgnoreCase("NE")) {
+                lmsg = "该工件未录入系统";
+            }else if(processMsgRet.equalsIgnoreCase("NN")) {
+                lmsg = "该工件跳过该工位";
+            }else if(processMsgRet.equalsIgnoreCase("QN")) {
+                lmsg = "该工件OP"+ lx+"0加工NG";
+            }else if(processMsgRet.equalsIgnoreCase("QD")) {
+                lmsg = "该工件OP"+ lx+"0未加工";
+            }else if(processMsgRet.equalsIgnoreCase("NF")) {
+                lmsg = "该工件已合格下线";
+            }else if(processMsgRet.equalsIgnoreCase("NR")) {
+                lmsg = "该工件离线返修中";
+            }else if(processMsgRet.equalsIgnoreCase("NB")) {
+                lmsg = "该工件已报废";
+            }else if(processMsgRet.equalsIgnoreCase("ND")) {
+                lmsg = "该工件NG待处理";
+            }else if(processMsgRet.equalsIgnoreCase("FN")) {
+                lmsg = "首件检查工件不合格停机";
+            }else if(processMsgRet.equalsIgnoreCase("GN")) {
+                lmsg = "更换配件首件检查不合格停机";
+            }else if(processMsgRet.equalsIgnoreCase("CS")) {
+                lmsg = "首件检查两小时内未检查,超时停机";
+            }else if(processMsgRet.equalsIgnoreCase("DJ")) {
+                lmsg = "未进行开班点检";
+            }else if(processMsgRet.equalsIgnoreCase("BM")) {
+                lmsg = "未绑定物料";
+            }else if(processMsgRet.equalsIgnoreCase("PL")) {
+                lmsg = "配件寿命不足";
+            }else if(processMsgRet.equalsIgnoreCase("QM")) {
+                lmsg = "两次气密必须间隔15分钟";
+            }else if(processMsgRet.equalsIgnoreCase("GS")) {
+                lmsg = "工件码格式不正确";
+            }else if(processMsgRet.equalsIgnoreCase("CF")) {
+                lmsg = "工件码重复";
+            }else if(processMsgRet.equalsIgnoreCase("AL")) {
+                lmsg = "该工件存在未处理的报警信息";
+            } else if (processMsgRet.equalsIgnoreCase("PZ")) {
+                lmsg = "该工件未拍照";
+            } else if (processMsgRet.equalsIgnoreCase("CS")) {
+                lmsg = "超时";
+            }
+        }catch (Exception e){ }
+        return lmsg;
+    }
+}

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

@@ -0,0 +1,157 @@
+package com.mes.util;
+
+import java.io.*;
+import java.net.HttpURLConnection;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+public class HttpUtils {
+	/**
+	 * HTTP请求,正确报文解析,并保存数据到生产记录数据
+	 * @return 
+	 * @throws URISyntaxException
+	 */
+    //http post请求
+    public static String sendRequest(String urlParam) {
+		String requestType = "POST";
+        //根据接收内容返回数据结果
+    	String ret = "";
+    	System.out.println(urlParam);
+        HttpURLConnection con = null;
+        BufferedReader buffer = null;
+        StringBuffer resultBuffer = null;
+        try {
+            URL url = new URL(urlParam);
+            //得到连接对象
+            con = (HttpURLConnection) url.openConnection();
+            //设置请求类型
+            con.setRequestMethod(requestType);
+            //设置请求需要返回的数据类型和字符集类型
+            con.setRequestProperty("Content-Type", "application/json;charset=GBK");  
+            //允许写出
+            con.setDoOutput(true);
+            //允许读入
+            con.setDoInput(true);
+            //不使用缓存
+            con.setUseCaches(false);
+            //得到响应码
+            int responseCode = con.getResponseCode();
+            System.out.println("responseCode="+responseCode);
+            if(responseCode == HttpURLConnection.HTTP_OK){
+                //得到响应流
+                InputStream inputStream = con.getInputStream();
+                //将响应流转换成字符串
+                resultBuffer = new StringBuffer();
+                String line;
+                buffer = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
+                while ((line = buffer.readLine()) != null) {
+                    resultBuffer.append(line);
+                }
+                System.out.println(resultBuffer.toString());
+                ret = resultBuffer.toString();
+            }else {
+            	//ret = String.valueOf(responseCode);
+            	ret = "false";
+            }
+            con.disconnect();
+        }catch(Exception e) {
+        	//ret = false;
+        	//System.out.println("e.toString()="+e.toString());
+        	//return e.toString();
+            //e.printStackTrace();
+        	ret = "false";
+        }
+        return ret;
+    }
+
+
+    public static String sendPostRequest(String urlParam, String params) {
+        String requestType = "POST";
+        //根据接收内容返回数据结果
+        String ret = "";
+        System.out.println(urlParam);
+        HttpURLConnection con = null;
+        BufferedReader buffer = null;
+        StringBuffer resultBuffer = null;
+        try {
+            URL url = new URL(urlParam);
+            //得到连接对象
+            con = (HttpURLConnection) url.openConnection();
+            //设置请求类型
+            con.setRequestMethod(requestType);
+            //设置请求需要返回的数据类型和字符集类型
+            con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=GBK");
+            //允许写出
+            con.setDoOutput(true);
+            //允许读入
+            con.setDoInput(true);
+            //不使用缓存
+            con.setUseCaches(false);
+
+            // 获取URLConnection对象对应的输出流
+            OutputStreamWriter out = new OutputStreamWriter( con.getOutputStream(),"UTF-8");// utf-8编码
+            // 发送请求参数
+            out.write(params);
+
+            //得到响应码
+            int responseCode = con.getResponseCode();
+            System.out.println("responseCode="+responseCode);
+            if(responseCode == HttpURLConnection.HTTP_OK){
+                //得到响应流
+                InputStream inputStream = con.getInputStream();
+                //将响应流转换成字符串
+                resultBuffer = new StringBuffer();
+                String line;
+                buffer = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
+                while ((line = buffer.readLine()) != null) {
+                    resultBuffer.append(line);
+                }
+                System.out.println(resultBuffer.toString());
+                ret = resultBuffer.toString();
+            }else {
+                //ret = String.valueOf(responseCode);
+                ret = "false";
+            }
+            con.disconnect();
+        }catch(Exception e) {
+            //ret = false;
+            //System.out.println("e.toString()="+e.toString());
+            //return e.toString();
+            //e.printStackTrace();
+            ret = "false";
+        }
+        return ret;
+    }
+
+    public static String sendPostRequestJson(String apiUrl, String jsonData) throws IOException {
+        URL url = new URL(apiUrl);
+        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+        conn.setRequestMethod("POST");
+        conn.setRequestProperty("Content-Type", "application/json");
+        conn.setDoOutput(true);
+
+        // 发送请求数据
+        try (OutputStream os = conn.getOutputStream()) {
+            byte[] input = jsonData.getBytes("utf-8");
+            os.write(input, 0, input.length);
+        }
+
+        // 获取响应数据
+        StringBuilder response = new StringBuilder();
+        int responseCode = conn.getResponseCode();
+//        System.out.println("Sending POST request to URL: " + apiUrl);
+//        System.out.println("Post parameters: " + jsonData);
+//        System.out.println("Response Code: " + responseCode);
+
+        try (BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"))) {
+            String responseLine;
+            while ((responseLine = br.readLine()) != null) {
+                response.append(responseLine.trim());
+            }
+        }
+
+        conn.disconnect();
+        return response.toString();
+    }
+
+}

+ 145 - 0
src/com/mes/util/JdbcUtils.java

@@ -0,0 +1,145 @@
+package com.mes.util;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+public class JdbcUtils {
+	public static final Logger log =  LoggerFactory.getLogger(JdbcUtils.class);
+	//通过上面的工具就可以获取到properties文件中的键值从而可以加载驱动 获取链接 从而 可以增删改查
+	public static Connection conn = null;
+    public static String Drivde="org.sqlite.JDBC";
+	public static String DATABASE_URL="jdbc:sqlite:mes_db.db";
+    
+    public static Connection getConn(){
+        try {
+            Class.forName(Drivde);// 加载驱动,连接sqlite的jdbc
+            conn = DriverManager.getConnection(DATABASE_URL);//连接数据库zhou.db,不存在则创建
+            System.out.println("连接到SQLite数据库成功!");
+            create_bw_record();//初始化结构表
+            //create_measure_data();//初始化测试数据表
+        } catch (Exception e) {
+            // TODO Auto-generated catch block
+        	close();//关闭数据库连接
+            e.printStackTrace();
+        }
+        return conn;
+    }
+
+	public static void openConnection() {
+		try {
+			Class.forName(Drivde);// 加载驱动,连接sqlite的jdbc
+			conn = DriverManager.getConnection(DATABASE_URL);
+		} catch (ClassNotFoundException e) {
+			e.printStackTrace();
+		} catch (SQLException e) {
+			e.printStackTrace();
+			// 如果连接失败,尝试重连
+			reconnect();
+		}
+	}
+
+	private static void reconnect() {
+		try {
+			// 关闭旧连接
+			if (conn != null && !conn.isClosed()) {
+				conn.close();
+			}
+			// 重新建立连接
+			conn = DriverManager.getConnection(DATABASE_URL);
+		} catch (SQLException e) {
+			e.printStackTrace();
+			// 如果重连失败,可以进一步处理异常,比如记录日志、通知管理员等
+		}
+	}
+    
+    public static void create_bw_record() throws SQLException {
+    	Statement statement=conn.createStatement();   //创建连接对象,是Java的一个操作数据库的重要接口
+        //设备结构数据库
+        String sqlEquipment = "CREATE TABLE if not exists bw_record("
+        		+ "id INTEGER PRIMARY KEY AUTOINCREMENT,gw VARCHAR(20),gy VARCHAR(20),message_type VARCHAR(20),sn VARCHAR(48),bw VARCHAR(1000),record_time DATETIME,"
+        		+ "info_01 VARCHAR(200),info_02 VARCHAR(200),info_03 VARCHAR(200))";
+//        statement.executeUpdate("drop table if exists bw_record");//判断是否有表tables的存在。有则删除
+        statement.executeUpdate(sqlEquipment);
+
+		// 创建 提交记录表
+		String submitRecord = "CREATE TABLE if not exists submit_record(\n" +
+				"   id INTEGER PRIMARY KEY AUTOINCREMENT, -- 自增ID\n" +
+				"   oprno VARCHAR(20),                    -- 工位号 \n" +
+				"   sn VARCHAR(48),                       -- 二维码\n" +
+				"   bw VARCHAR(1000),                     -- 报文 \n" +
+				"   record_time DATETIME,                 -- 记录时间\n" +
+				"   state CHAR(1)      -- 状态(0 ->未提交, 1 ->已提交)\n" +
+				")";
+		statement.executeUpdate(submitRecord);
+
+        statement.close();
+    }
+    
+    //插入数据
+    public static boolean insertData(String gw, String gy, String bw, String message_type, String sn) {
+    	boolean ret = false;
+    	String record_time = DateLocalUtils.getCurrentTime();
+		try {
+			// 确保连接已经打开
+			if (JdbcUtils.conn == null || JdbcUtils.conn.isClosed()) {
+				JdbcUtils.openConnection();
+			}
+			//创建连接对象,是Java的一个操作数据库的重要接口
+			Statement statement=conn.createStatement();
+			statement.executeUpdate("INSERT INTO bw_record (gw,gy,bw,record_time,message_type,sn) VALUES"
+					+ " ('"+gw+"', '"+gy+"', '"+bw+"', '"+record_time+"','"+message_type+"','"+sn+"')");//向数据库中插入数据
+			statement.close();
+			ret = true;
+		} catch (SQLException e) {
+			// TODO Auto-generated catch block
+			//e.printStackTrace();
+			ret = false;
+		}
+
+		return ret;
+    }
+
+	// 向 submit_record表 插入提交记录数据
+	public static boolean insertSubmitRecord(String oprno, String sn, String bw){
+		boolean ret = false;
+		String record_time = DateLocalUtils.getCurrentTime();
+		try {
+			// 确保连接已经打开
+			if (JdbcUtils.conn == null || JdbcUtils.conn.isClosed()) {
+				JdbcUtils.openConnection();
+			}
+			Statement statement=conn.createStatement();
+			String insertSQL = "INSERT INTO submit_record (oprno, sn, bw, record_time, state)" +
+					"VALUES('" + oprno + "', '" + sn + "', '" + bw + "', '" + record_time + "', '0')";
+			statement.executeUpdate(insertSQL);
+			statement.close();
+			ret = true;
+			log.info("向submit_record表插入数据成功: {}", insertSQL);
+		} catch (SQLException e) {
+			ret = false;
+			log.info("向submit_record表插入数据失败");
+		}
+		return ret;
+	}
+
+    
+    public static void close(){
+        try {
+        	if(conn!=null) {
+        		conn.close();
+        	}
+        } catch (SQLException e) {
+            e.printStackTrace();
+        }
+    }
+    
+    
+
+}
+ 
+

+ 199 - 0
src/com/mes/util/ModbusRtuClient.java

@@ -0,0 +1,199 @@
+package com.mes.util;
+
+import com.fazecast.jSerialComm.SerialPort;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.Arrays;
+
+/**
+ * Modbus RTU 主站客户端(RS485 串口)
+ */
+public class ModbusRtuClient {
+
+    private static final Logger log = LoggerFactory.getLogger(ModbusRtuClient.class);
+
+    private SerialPort serialPort;
+    private int slaveId;
+    private int timeoutMs;
+    private final Object ioLock = new Object();
+
+    public boolean open(WelderConfig config) {
+        close();
+        slaveId = config.slaveId;
+        timeoutMs = config.timeoutMs;
+
+        serialPort = SerialPort.getCommPort(config.port);
+        serialPort.setBaudRate(config.baud);
+        serialPort.setNumDataBits(config.dataBits);
+        serialPort.setNumStopBits(config.stopBits);
+        serialPort.setParity(parseParity(config.parity));
+        serialPort.setComPortTimeouts(SerialPort.TIMEOUT_READ_SEMI_BLOCKING, timeoutMs, 0);
+
+        if (!serialPort.openPort()) {
+            log.error("打开串口失败: {}", config.port);
+            serialPort = null;
+            return false;
+        }
+        log.info("焊机串口已打开: {}, {}bps, 校验={}", config.port, config.baud, config.parity);
+        return true;
+    }
+
+    public void close() {
+        if (serialPort != null && serialPort.isOpen()) {
+            serialPort.closePort();
+        }
+        serialPort = null;
+    }
+
+    public boolean isOpen() {
+        return serialPort != null && serialPort.isOpen();
+    }
+
+    /**
+     * 读保持寄存器(功能码 03H)
+     */
+    public int[] readHoldingRegisters(int startAddress, int count) throws IOException {
+        if (!isOpen()) {
+            throw new IOException("串口未打开");
+        }
+        if (count <= 0 || count > 20) {
+            throw new IOException("读取字数须在 1~20 之间");
+        }
+
+            synchronized (ioLock) {
+            clearInputBuffer();
+
+            byte[] request = new byte[8];
+            request[0] = (byte) slaveId;
+            request[1] = 0x03;
+            request[2] = (byte) ((startAddress >> 8) & 0xFF);
+            request[3] = (byte) (startAddress & 0xFF);
+            request[4] = (byte) ((count >> 8) & 0xFF);
+            request[5] = (byte) (count & 0xFF);
+            appendCrc(request, 6);
+
+            int written = serialPort.writeBytes(request, request.length);
+            if (written != request.length) {
+                throw new IOException("发送 Modbus 指令失败");
+            }
+
+            byte[] response = readResponse(5 + count * 2);
+            validateResponse(response, (byte) 0x03, count * 2);
+
+            int[] values = new int[count];
+            for (int i = 0; i < count; i++) {
+                int hi = response[3 + i * 2] & 0xFF;
+                int lo = response[4 + i * 2] & 0xFF;
+                values[i] = (hi << 8) | lo;
+            }
+            return values;
+        }
+    }
+
+    private void clearInputBuffer() {
+        byte[] trash = new byte[256];
+        while (serialPort.bytesAvailable() > 0) {
+            serialPort.readBytes(trash, Math.min(trash.length, serialPort.bytesAvailable()));
+        }
+    }
+
+    private byte[] readResponse(int expectedDataBytes) throws IOException {
+        // 地址(1) + 功能码(1) + 字节数(1) + 数据(N) + CRC(2)
+        int frameLen = 3 + expectedDataBytes + 2;
+        byte[] buffer = new byte[frameLen];
+        int total = 0;
+        long deadline = System.currentTimeMillis() + timeoutMs;
+
+        while (total < 3 && System.currentTimeMillis() < deadline) {
+            int n = serialPort.readBytes(buffer, 3 - total, total);
+            if (n > 0) {
+                total += n;
+            }
+        }
+        if (total < 3) {
+            throw new IOException("读取 Modbus 响应超时");
+        }
+
+        if ((buffer[1] & 0x80) != 0) {
+            readRemain(buffer, 3, 2);
+            throw new IOException("Modbus 异常应答, 故障码=0x" + Integer.toHexString(buffer[2] & 0xFF));
+        }
+
+        int dataBytes = buffer[2] & 0xFF;
+        readRemain(buffer, 3, dataBytes + 2);
+        return Arrays.copyOf(buffer, 3 + dataBytes + 2);
+    }
+
+    private void readRemain(byte[] buffer, int offset, int length) throws IOException {
+        int total = 0;
+        long deadline = System.currentTimeMillis() + timeoutMs;
+        while (total < length && System.currentTimeMillis() < deadline) {
+            int n = serialPort.readBytes(buffer, length - total, offset + total);
+            if (n > 0) {
+                total += n;
+            }
+        }
+        if (total < length) {
+            throw new IOException("读取 Modbus 数据区超时");
+        }
+    }
+
+    private void validateResponse(byte[] response, byte functionCode, int dataBytes) throws IOException {
+        if (response.length < 5) {
+            throw new IOException("Modbus 响应长度不足");
+        }
+        if ((response[0] & 0xFF) != (slaveId & 0xFF)) {
+            throw new IOException("Modbus 站号不匹配");
+        }
+        if (response[1] != functionCode) {
+            throw new IOException("Modbus 功能码不匹配");
+        }
+        if ((response[2] & 0xFF) != dataBytes) {
+            throw new IOException("Modbus 数据长度不匹配");
+        }
+        if (!verifyCrc(response)) {
+            throw new IOException("Modbus CRC 校验失败");
+        }
+    }
+
+    private static int parseParity(String parity) {
+        if ("NONE".equalsIgnoreCase(parity)) {
+            return SerialPort.NO_PARITY;
+        }
+        if ("ODD".equalsIgnoreCase(parity)) {
+            return SerialPort.ODD_PARITY;
+        }
+        return SerialPort.EVEN_PARITY;
+    }
+
+    private static void appendCrc(byte[] data, int length) {
+        int crc = calcCrc16(data, 0, length);
+        data[length] = (byte) (crc & 0xFF);
+        data[length + 1] = (byte) ((crc >> 8) & 0xFF);
+    }
+
+    private static boolean verifyCrc(byte[] data) {
+        int len = data.length - 2;
+        int crc = calcCrc16(data, 0, len);
+        int lo = data[len] & 0xFF;
+        int hi = data[len + 1] & 0xFF;
+        return crc == ((hi << 8) | lo);
+    }
+
+    private static int calcCrc16(byte[] data, int offset, int length) {
+        int crc = 0xFFFF;
+        for (int i = offset; i < offset + length; i++) {
+            crc ^= (data[i] & 0xFF);
+            for (int j = 0; j < 8; j++) {
+                if ((crc & 0x0001) != 0) {
+                    crc = (crc >> 1) ^ 0xA001;
+                } else {
+                    crc >>= 1;
+                }
+            }
+        }
+        return crc;
+    }
+}

+ 76 - 0
src/com/mes/util/WelderConfig.java

@@ -0,0 +1,76 @@
+package com.mes.util;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Properties;
+
+/**
+ * 焊机 Modbus RTU 通讯配置
+ * 对应 config.properties 中 welder.* 配置项
+ */
+public class WelderConfig {
+
+    // 是否启用焊机参数读取(true=连接焊机并刷新页面,false=不连接)
+    public boolean enabled = true;
+
+    // 串口号,USB转485在设备管理器中显示的COM口,如COM3、COM5
+    public String port = "COM3";
+
+    // 波特率,菲斯特协议固定9600,一般无需修改
+    public int baud = 9600;
+
+    // 数据位,固定8位
+    public int dataBits = 8;
+
+    // 停止位,固定1位
+    public int stopBits = 1;
+
+    // 校验方式,文档要求偶校验,可选 EVEN / NONE / ODD
+    public String parity = "EVEN";
+
+    // 下位机号(Modbus站号),须与焊机参数Eb一致,范围0-99
+    public int slaveId = 1;
+
+    // 轮询间隔(毫秒),每隔多久读取一次焊机参数
+    public int pollIntervalMs = 500;
+
+    // 通讯超时(毫秒),单次读写无响应则判失败
+    public int timeoutMs = 1000;
+
+    public static WelderConfig load() {
+        WelderConfig config = new WelderConfig();
+        try {
+            InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
+            if (is == null) {
+                return config;
+            }
+            Properties pro = new Properties();
+            BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
+            pro.load(br);
+            br.close();
+
+            // welder.enabled
+            config.enabled = Boolean.parseBoolean(pro.getProperty("welder.enabled", "true"));
+            // welder.port
+            config.port = pro.getProperty("welder.port", "COM3").trim();
+            // welder.baud
+            config.baud = Integer.parseInt(pro.getProperty("welder.baud", "9600").trim());
+            // welder.databits
+            config.dataBits = Integer.parseInt(pro.getProperty("welder.databits", "8").trim());
+            // welder.stopbits
+            config.stopBits = Integer.parseInt(pro.getProperty("welder.stopbits", "1").trim());
+            // welder.parity
+            config.parity = pro.getProperty("welder.parity", "EVEN").trim().toUpperCase();
+            // welder.slaveId
+            config.slaveId = Integer.parseInt(pro.getProperty("welder.slaveId", "1").trim());
+            // welder.pollIntervalMs
+            config.pollIntervalMs = Integer.parseInt(pro.getProperty("welder.pollIntervalMs", "500").trim());
+            // welder.timeoutMs
+            config.timeoutMs = Integer.parseInt(pro.getProperty("welder.timeoutMs", "1000").trim());
+        } catch (Exception e) {
+            // 读取失败时使用上方默认值
+        }
+        return config;
+    }
+}

+ 44 - 0
src/com/mes/util/WelderParamData.java

@@ -0,0 +1,44 @@
+package com.mes.util;
+
+/**
+ * 焊机加工参数快照
+ */
+public class WelderParamData {
+
+    public boolean connected;
+    public String errorMessage;
+
+    public String workMode;
+    public String runState;
+    public String toolingState;
+    public String alarmText;
+    public int weldCount;
+    public int specNo;
+
+    public int capVoltage;
+    public int preheatVoltage;
+    public int weldVoltage;
+    public int temperVoltage;
+    public String preheatPeakCurrent;
+    public String weldPeakCurrent;
+    public String temperPeakCurrent;
+
+    public int prePressTime;
+    public int pressTime;
+    public int specPreheatVoltage;
+    public int specPreheatCurrent;
+    public int specPreheatTime;
+    public int specWeldVoltage;
+    public int specWeldCurrent;
+    public int specWeldTime;
+    public int specTemperVoltage;
+    public int specTemperCurrent;
+    public int specTemperTime;
+
+    public static WelderParamData disconnected(String message) {
+        WelderParamData data = new WelderParamData();
+        data.connected = false;
+        data.errorMessage = message;
+        return data;
+    }
+}

+ 0 - 0
src/com/mes/util/WelderParamReader.java


Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác