Browse Source

初始化

chefz 1 week ago
commit
efd709b94f
100 changed files with 3518 additions and 0 deletions
  1. 25 0
      .classpath
  2. 7 0
      .gitignore
  3. 0 0
      .lock
  4. 28 0
      .project
  5. 2 0
      image/.gitignore
  6. BIN
      image/background.png
  7. BIN
      image/bg/a_side.png
  8. BIN
      image/bg/b_side.png
  9. BIN
      image/bg/bar_add.png
  10. BIN
      image/bg/bar_bookmark.png
  11. BIN
      image/bg/bar_cmd_go.png
  12. BIN
      image/bg/bar_edit.png
  13. BIN
      image/bg/bar_pause.png
  14. BIN
      image/bg/bar_sampling.png
  15. BIN
      image/bg/bar_setting.png
  16. BIN
      image/bg/bar_stop.png
  17. BIN
      image/bg/close_bt.png
  18. BIN
      image/bg/company_setting_logo.png
  19. BIN
      image/bg/delete.png
  20. BIN
      image/bg/department_setting_logo.png
  21. BIN
      image/bg/download.png
  22. BIN
      image/bg/equipment_setting_logo.png
  23. BIN
      image/bg/gj_001_1_20.png
  24. BIN
      image/bg/gj_001_21_40.png
  25. BIN
      image/bg/gj_001_41_60.png
  26. BIN
      image/bg/green_dot.png
  27. BIN
      image/bg/grey_dot.png
  28. BIN
      image/bg/icon.png
  29. BIN
      image/bg/inductance_logo.png
  30. BIN
      image/bg/insulation_logo.png
  31. BIN
      image/bg/login.png
  32. BIN
      image/bg/logo.png
  33. BIN
      image/bg/logoff.png
  34. BIN
      image/bg/menu_data_analysis.png
  35. BIN
      image/bg/menu_data_preprocess.png
  36. BIN
      image/bg/menu_file.png
  37. BIN
      image/bg/menu_setting.png
  38. BIN
      image/bg/min_bt.png
  39. BIN
      image/bg/ng_bg.png
  40. BIN
      image/bg/ok_bg.png
  41. BIN
      image/bg/open_file.png
  42. BIN
      image/bg/refresh.png
  43. BIN
      image/bg/reset_logo.png
  44. BIN
      image/bg/resistance_logo.png
  45. BIN
      image/bg/save_bg.png
  46. BIN
      image/bg/scan_barcode.png
  47. BIN
      image/bg/tree_folder_icon.png
  48. BIN
      image/bg/tree_leaf_icon.png
  49. BIN
      image/bg/user.png
  50. BIN
      image/bg/vertical_line.png
  51. BIN
      image/bg/zoom_in.png
  52. BIN
      image/bg/zoom_out.png
  53. BIN
      image/close_bt.png
  54. 0 0
      image/cmd.txt
  55. BIN
      image/icon.ico
  56. BIN
      image/info_bt.png
  57. BIN
      image/min_bt.png
  58. BIN
      lib/commons-codec-1.15.jar
  59. BIN
      lib/fastjson2-2.0.16.jar
  60. BIN
      lib/gson-2.10.jar
  61. BIN
      lib/iot-communication-1.4.4.jar
  62. BIN
      lib/jSerialComm-2.6.2.jar
  63. BIN
      lib/jfreechart-1.5.4.jar
  64. BIN
      lib/jshortcut-0.4-oberzalek.jar
  65. BIN
      lib/kotlin-stdlib-1.8.10.jar
  66. BIN
      lib/logback-classic-1.2.13.jar
  67. BIN
      lib/logback-core-1.2.13.jar
  68. BIN
      lib/netty-all-4.1.48.Final.jar
  69. BIN
      lib/okhttp-4.10.0.jar
  70. BIN
      lib/okio-jvm-3.3.0.jar
  71. BIN
      lib/s7connector-2.1.jar
  72. BIN
      lib/slf4j-api-1.7.36.jar
  73. BIN
      lib/sqlite-jdbc-3.36.0.3.jar
  74. 3 0
      src/META-INF/MANIFEST.MF
  75. 10 0
      src/com/mes/component/CallFromJs.java
  76. 156 0
      src/com/mes/component/ConfigPanel.java
  77. 57 0
      src/com/mes/component/MesRadio.java
  78. 44 0
      src/com/mes/component/MesWebView.java
  79. 30 0
      src/com/mes/component/MyDialog.java
  80. 190 0
      src/com/mes/component/ProdReq.java
  81. 90 0
      src/com/mes/netty/MesMsgUtils.java
  82. 63 0
      src/com/mes/netty/NettyClient.java
  83. 82 0
      src/com/mes/netty/NettyClientHandler.java
  84. 73 0
      src/com/mes/netty/ProtocolParam.java
  85. 168 0
      src/com/mes/netty/XDecoder.java
  86. 58 0
      src/com/mes/ui/BindMaterialResp.java
  87. 302 0
      src/com/mes/ui/DataUtil.java
  88. 53 0
      src/com/mes/ui/ErrorMsg.java
  89. 85 0
      src/com/mes/ui/LockUtil.java
  90. 206 0
      src/com/mes/ui/LoginFarme.java
  91. 983 0
      src/com/mes/ui/MesClient.java
  92. 121 0
      src/com/mes/ui/MesRevice.java
  93. 194 0
      src/com/mes/ui/ModbusUtil.java
  94. 65 0
      src/com/mes/ui/OprnoUtil.java
  95. 158 0
      src/com/mes/ui/PlcUtil.java
  96. 148 0
      src/com/mes/ui/ProdReq.java
  97. 43 0
      src/com/mes/ui/TableCellEditorButton.java
  98. 14 0
      src/com/mes/ui/TableCellRendererButton.java
  99. 60 0
      src/com/mes/ui/test.java
  100. 0 0
      src/com/mes/util/Base64Utils.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/iot-communication-1.4.4.jar"/>
+</classpath>

+ 7 - 0
.gitignore

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

+ 0 - 0
.lock


+ 28 - 0
.project

@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>mesclient-op220</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>1765091501343</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>

+ 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


+ 3 - 0
src/META-INF/MANIFEST.MF

@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Main-Class: com.mes.ui.MesClient
+

+ 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;
+    }
+}

+ 156 - 0
src/com/mes/component/ConfigPanel.java

@@ -0,0 +1,156 @@
+package com.mes.component;
+
+import com.mes.ui.MesClient;
+import com.mes.ui.OprnoUtil;
+import com.mes.util.JdbcUtils;
+
+import javax.swing.*;
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
+import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+/**
+ * 设备管理配置面板
+ * 允许在前端动态修改工位信息、任务数及 PLC IP
+ */
+public class ConfigPanel extends JPanel {
+
+    private JTextField txtGw;
+    private JTextField txtGwDes;
+    private JTextField txtASet;
+    private JTextField txtIp;
+
+    public ConfigPanel() {
+        setLayout(null);
+        setBackground(Color.WHITE);
+
+        int startY = 30;
+        int labelX = 100;
+        int fieldX = 260;
+        int width = 250;
+        int height = 40;
+        int gap = 60;
+
+        // 工位编号
+        addLabel("工位编号:", labelX, startY, 150, height);
+        txtGw = addTextField(MesClient.mes_gw, fieldX, startY, width, height);
+        txtGw.getDocument().addDocumentListener(new DocumentListener() {
+            @Override
+            public void insertUpdate(DocumentEvent e) { updateDes(); }
+            @Override
+            public void removeUpdate(DocumentEvent e) { updateDes(); }
+            @Override
+            public void changedUpdate(DocumentEvent e) { updateDes(); }
+            
+            private void updateDes() {
+                String gw = txtGw.getText().trim();
+                String des = OprnoUtil.getGwDes(MesClient.mes_line_sn, gw);
+                txtGwDes.setText(des);
+            }
+        });
+
+        // 工位名称 (只读,自动匹配)
+        startY += gap;
+        addLabel("工位名称:", labelX, startY, 150, height);
+        txtGwDes = addTextField(MesClient.mes_gw_des, fieldX, startY, width, height);
+        txtGwDes.setEditable(false);
+        txtGwDes.setBackground(new Color(240, 240, 240));
+
+        // 任务数
+        startY += gap;
+        addLabel("拉铆枪任务数:", labelX, startY, 150, height);
+        txtASet = addTextField(String.valueOf(MesClient.aSetNum), fieldX, startY, width, height);
+
+        // PLC IP
+        startY += gap;
+        addLabel("拉铆枪IP地址:", labelX, startY, 150, height);
+        txtIp = addTextField(MesClient.curIpA, fieldX, startY, width, height);
+
+        // 保存按钮
+        startY += gap + 20;
+        JButton btnSave = new JButton("保存并同步配置");
+        btnSave.setFont(new Font("微软雅黑", Font.BOLD, 20));
+        btnSave.setBounds(180, startY, 220, 55);
+        btnSave.setBackground(new Color(0, 120, 215));
+        btnSave.setForeground(Color.WHITE);
+        btnSave.setFocusPainted(false);
+        btnSave.addActionListener(new ActionListener() {
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                saveAction();
+            }
+        });
+        add(btnSave);
+    }
+
+    private void addLabel(String text, int x, int y, int w, int h) {
+        JLabel label = new JLabel(text);
+        label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
+        label.setBounds(x, y, w, h);
+        add(label);
+    }
+
+    private JTextField addTextField(String text, int x, int y, int w, int h) {
+        JTextField textField = new JTextField(text);
+        textField.setFont(new Font("微软雅黑", Font.PLAIN, 20));
+        textField.setBounds(x, y, w, h);
+        add(textField);
+        return textField;
+    }
+
+    private void saveAction() {
+        try {
+            String gw = txtGw.getText().trim();
+            // 自动根据工位号获取描述,不再使用手动输入的值
+            String gwDes = OprnoUtil.getGwDes(MesClient.mes_line_sn, gw);
+            if (gwDes.isEmpty()) {
+                gwDes = "未知工位"; // 兜底处理
+            }
+            txtGwDes.setText(gwDes);
+
+            int aSet = Integer.parseInt(txtASet.getText().trim());
+            String ip = txtIp.getText().trim();
+
+            if (gw.isEmpty() || ip.isEmpty()) {
+                JOptionPane.showMessageDialog(this, "工位编号和 IP 地址不能为空", "输入错误", JOptionPane.ERROR_MESSAGE);
+                return;
+            }
+
+            // 1. 持久化到数据库 (移除 B 枪参数)
+            JdbcUtils.updateConfig(aSet, ip, gw, gwDes);
+
+            // 2. 同步更新内存变量
+            MesClient.mes_gw = gw;
+            MesClient.mes_gw_des = gwDes;
+            MesClient.aSetNum = aSet;
+            MesClient.aMax = aSet;
+            
+            // 3. 处理 PLC IP 变更逻辑 (仅在 IP 变化时重连)
+            MesClient.reconnectPlc(ip);
+
+            // 4. 同步更新主界面标签和标题
+            if (MesClient.param1 != null) MesClient.param1.setText(String.valueOf(aSet));
+            if (MesClient.mesClientFrame != null) {
+                MesClient.mesClientFrame.setTitle("MES系统客户端:" + gw + "- " + gwDes);
+            }
+
+            JOptionPane.showMessageDialog(this, "配置保存并同步成功!", "成功", JOptionPane.INFORMATION_MESSAGE);
+        } catch (NumberFormatException ex) {
+            JOptionPane.showMessageDialog(this, "任务数必须为有效数字", "格式错误", JOptionPane.ERROR_MESSAGE);
+        } catch (Exception ex) {
+            JOptionPane.showMessageDialog(this, "保存失败:" + ex.getMessage(), "错误", JOptionPane.ERROR_MESSAGE);
+        }
+    }
+
+    /**
+     * 刷新面板数据
+     */
+    public void refreshFields() {
+        txtGw.setText(MesClient.mes_gw);
+        txtGwDes.setText(MesClient.mes_gw_des);
+        txtASet.setText(String.valueOf(MesClient.aSetNum));
+        txtIp.setText(MesClient.curIpA);
+    }
+}

+ 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);
+    }
+}

+ 190 - 0
src/com/mes/component/ProdReq.java

@@ -0,0 +1,190 @@
+package com.mes.component;
+
+/**
+ * 拉铆数据实体类
+ */
+public class ProdReq {
+    // id
+    private Integer id;
+    // 工位
+    private String gw;
+    // 线体
+    private String lineSn;
+    // 类型
+    private String type;
+    // 工件号
+    private String sn;
+    // 拉力
+    private String fout;
+    // 位移
+    private String sout;
+    // 拉力下偏差
+    private String fmin;
+    // 位移下偏差
+    private String smin;
+    // 拉力上限
+    private String fmax;
+    // 位移上限
+    private String smax;
+    //
+    private String qty;
+    //
+    private String serialNumber;
+    //
+    private Integer sync;
+    //
+    private String recordTime;
+    //
+    private String ucode;
+
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public String getGw() {
+        return gw;
+    }
+
+    public void setGw(String gw) {
+        this.gw = gw;
+    }
+
+    public String getLineSn() {
+        return lineSn;
+    }
+
+    public void setLineSn(String lineSn) {
+        this.lineSn = lineSn;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public String getSn() {
+        return sn;
+    }
+
+    public void setSn(String sn) {
+        this.sn = sn;
+    }
+
+    public String getFout() {
+        return fout;
+    }
+
+    public void setFout(String fout) {
+        this.fout = fout;
+    }
+
+    public String getSout() {
+        return sout;
+    }
+
+    public void setSout(String sout) {
+        this.sout = sout;
+    }
+
+    public String getFmin() {
+        return fmin;
+    }
+
+    public void setFmin(String fmin) {
+        this.fmin = fmin;
+    }
+
+    public String getSmin() {
+        return smin;
+    }
+
+    public void setSmin(String smin) {
+        this.smin = smin;
+    }
+
+    public String getFmax() {
+        return fmax;
+    }
+
+    public void setFmax(String fmax) {
+        this.fmax = fmax;
+    }
+
+    public String getSmax() {
+        return smax;
+    }
+
+    public void setSmax(String smax) {
+        this.smax = smax;
+    }
+
+    public String getQty() {
+        return qty;
+    }
+
+    public void setQty(String qty) {
+        this.qty = qty;
+    }
+
+    public String getSerialNumber() {
+        return serialNumber;
+    }
+
+    public void setSerialNumber(String serialNumber) {
+        this.serialNumber = serialNumber;
+    }
+
+    public Integer getSync() {
+        return sync;
+    }
+
+    public void setSync(Integer sync) {
+        this.sync = sync;
+    }
+
+    public String getRecordTime() {
+        return recordTime;
+    }
+
+    public void setRecordTime(String recordTime) {
+        this.recordTime = recordTime;
+    }
+
+    public String getUcode() {
+        return ucode;
+    }
+
+    public void setUcode(String ucode) {
+        this.ucode = ucode;
+    }
+
+    @Override
+    public String toString() {
+        return "ProdReq{" +
+                "id=" + id +
+                ", gw='" + gw + '\'' +
+                ", lineSn='" + lineSn + '\'' +
+                ", type='" + type + '\'' +
+                ", sn='" + sn + '\'' +
+                ", fout='" + fout + '\'' +
+                ", sout='" + sout + '\'' +
+                ", fmin='" + fmin + '\'' +
+                ", smin='" + smin + '\'' +
+                ", fmax='" + fmax + '\'' +
+                ", smax='" + smax + '\'' +
+                ", qty='" + qty + '\'' +
+                ", serialNumber='" + serialNumber + '\'' +
+                ", sync=" + sync +
+                ", recordTime='" + recordTime + '\'' +
+                ", ucode='" + ucode + '\'' +
+                '}';
+    }
+}

+ 90 - 0
src/com/mes/netty/MesMsgUtils.java

@@ -0,0 +1,90 @@
+package com.mes.netty;
+
+public class MesMsgUtils {
+
+    public static int SYNR_LEN = 46;
+    public static int AXTW_LEN = 46;
+    public static int ACLW_LEN = 46;
+    public static int MCJW_LEN = 96;
+    public static int AQDW_LEN = 96;
+    public static int MBDW_LEN = 96;
+    public static int MJBW_LEN = 96;
+    public static int MQDW_LEN = 96;
+    public static int MKSW_LEN = 96;
+    public static int MSBW_LEN = 96;
+    public static int MCSW_LEN = 96;
+    public static int AQRW_LEN = 96;
+
+    public static String MSG_TYPE[] = {
+        "SYNR",
+        "AXTW",
+        "ACLW",
+        "MCJW",
+        "AQDW",
+        "MBDW",
+        "MJBW",
+        "MQDW",
+        "MKSW",
+        "MSBW",
+        "MCSW",
+        "AQRW",
+    };
+
+    public static int isMsgContentOK(String msg, String msg_type) {
+        //ret=0OK,1 空内容,2 长度不符
+        int ret = 0;
+        if(msg==null||msg.equalsIgnoreCase("")) {
+            ret = 1;
+            return ret;
+        }
+
+        int len = msg.length();
+        //System.out.println("len="+len);
+        switch(msg_type) {
+            case "SYNR":
+            case "AXTW":
+            case "ACLW":
+                if(len==SYNR_LEN) {
+                    ret = 0;
+                }else {
+                    ret = 2;
+                }
+                break;
+            default:
+                if(len==AQDW_LEN) {
+                    ret = 0;
+                }else {
+                    ret = 2;
+                }
+                break;
+        }
+        return ret;
+    }
+
+    // 判断报文类型是否在清单里
+    public static boolean isMsgTypeOk(String msg_type) {
+        for (String str : MSG_TYPE) {
+            if (str.equals(msg_type)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    // 处理报文数据
+    public static String processMsg(String msg, String msg_type) {
+        String processMsgRet = "";
+        if(msg_type.equalsIgnoreCase("SYNR")) {
+
+        }else if(msg_type.equalsIgnoreCase("AXTW")) {
+
+        }else if(msg_type.equalsIgnoreCase("ACLW")) {
+
+        }else{
+            processMsgRet = ProtocolParam.getResult(msg);
+        }
+        return processMsgRet;
+    }
+
+
+}

+ 63 - 0
src/com/mes/netty/NettyClient.java

@@ -0,0 +1,63 @@
+package com.mes.netty;
+
+import io.netty.bootstrap.Bootstrap;
+import io.netty.channel.*;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.channel.socket.nio.NioSocketChannel;
+import io.netty.handler.codec.string.StringEncoder;
+import java.util.concurrent.TimeUnit;
+
+import com.mes.ui.MesClient;
+
+public class NettyClient {
+    public SocketChannel socketChannel;
+    public static ChannelFuture future;
+
+    public  void run(Object msg){
+        //配置线程组
+        EventLoopGroup group = new NioEventLoopGroup();
+        //创建服务启动器
+        Bootstrap bootstrap = new Bootstrap();
+
+        //配置参数
+        bootstrap.group(group)
+                .channel(NioSocketChannel.class)
+                .option(ChannelOption.TCP_NODELAY,true)
+                .handler(new ChannelInitializer<SocketChannel>() {
+                    protected void initChannel(SocketChannel socketChannel) throws Exception {
+                        socketChannel.pipeline()
+                                .addLast(new XDecoder())
+                                .addLast(new StringEncoder())
+//                                    .addLast(new StringDecoder())
+                                .addLast(new NettyClientHandler());
+                    }
+                })
+                .remoteAddress(MesClient.mes_server_ip,MesClient.mes_tcp_port);
+
+        //连接
+        future = bootstrap.connect();
+        System.out.println("客户端正在连接服务端...");
+        //客户端断线重连逻辑
+        future.addListener((ChannelFutureListener) future1 -> {
+            if (future1.isSuccess()) {
+                //tcp连接成功
+                MesClient.tcp_connect_flag = true;
+                //设置TCP请求状态
+                MesClient.connect_request_flag = false;
+                System.out.println("连接Netty服务端成功");
+                future.channel().writeAndFlush(msg);
+            } else {
+                //tcp连接失败
+                MesClient.tcp_connect_flag = false;
+                MesClient.connect_request_flag = true;
+                System.out.println("连接失败,进行断线重连");
+                future1.channel().eventLoop().schedule(() -> run(msg), 10, TimeUnit.SECONDS);
+            }
+            //设置tcp连接状态
+            MesClient.setTcpStatus();
+        });
+        socketChannel = (SocketChannel) future.channel();
+
+    }
+}

+ 82 - 0
src/com/mes/netty/NettyClientHandler.java

@@ -0,0 +1,82 @@
+package com.mes.netty;
+
+import com.mes.ui.MesClient;
+import com.mes.ui.MesRevice;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInboundHandlerAdapter;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+public class NettyClientHandler extends ChannelInboundHandlerAdapter {
+
+    private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+    public static byte[] responseByte;
+
+    @Override
+    public void channelActive(ChannelHandlerContext ctx) throws Exception {
+        System.out.println("mes connecting:" + sdf.format(new Date()));
+    }
+
+    @Override
+    public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
+        Channel channel = ctx.channel();
+        System.err.println("close tcp, ip:" + channel.remoteAddress());
+        MesClient.tcp_connect_flag = false;
+        MesClient.setTcpStatus();
+        // 关闭通道
+        channel.close();
+    }
+
+    @Override
+    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
+        System.out.println("msg:"+msg);
+
+        String mes_msg = formatResult(msg.toString());
+        if(mes_msg == null || mes_msg.isEmpty()){ // error msg
+            return;
+        }
+
+        String msg_type = ProtocolParam.getMsgType(mes_msg);
+        System.out.println("msg_type="+msg_type);
+
+        String processMsgRet = MesMsgUtils.processMsg(mes_msg, msg_type);
+        System.out.println("processMsgRet="+processMsgRet);
+        switch(msg_type) {
+            case "AQDW": // 查询质量
+                MesRevice.checkQualityRevice(processMsgRet,mes_msg);
+                break;
+            case "MKSW":
+                MesRevice.startRevice(processMsgRet,mes_msg);
+                break;
+            case "MBDW":
+                MesRevice.bindRevice(processMsgRet,mes_msg);
+                break;
+            case "MJBW":
+                MesRevice.unbindRevice(processMsgRet,mes_msg);
+                break;
+            case "MQDW":
+                MesRevice.updateResultRevice(processMsgRet,mes_msg);
+                break;
+        }
+
+
+    }
+
+    @Override
+    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
+        ctx.close();
+    }
+
+    private String formatResult(String msg){
+        System.err.println("length:" + msg.length() + " content:" + msg);
+        String msgType = msg.substring(0,2).trim();
+        if(msgType.equals("OK")){
+            return msg.substring(3,msg.length());
+        }else{
+            return "";
+        }
+    }
+
+}

+ 73 - 0
src/com/mes/netty/ProtocolParam.java

@@ -0,0 +1,73 @@
+package com.mes.netty;
+
+
+// 固定格式报文各参数获取方法
+public class ProtocolParam {
+    // bbbbfffffARWAQDWGWOP100 GY100000ID151245P00000106200123062900001      RSOKDA2023-09-07ZT10:16:58
+    public static Integer fixedLength = 96; // 固定长度
+
+    // 获取消息类型  所有报文都可使用
+    public static String getMsgType(String msg){
+        System.out.print(msg);
+        if(msg.length() < 16){
+            return "";
+        }
+        return msg.substring(12,16);
+    }
+
+    // 获取工位号
+    public static String getOprno(String msg){
+        if(msg.length() < 24){
+            return "";
+        }
+        return msg.substring(18,24);
+    }
+
+    // 获取工艺号
+    public static String getCraft(String msg){
+        if(msg.length() < 32){
+            return "";
+        }
+        return msg.substring(26,32);
+    }
+
+    // 获取镭雕码或设备报警故障代码
+    public static String getSn(String msg){
+        if(msg.length() < 70){
+            return "";
+        }
+        return msg.substring(34,70);
+    }
+
+    public static String getLx(String msg){
+        if(msg.length() < 72){
+            return "";
+        }
+        return msg.substring(70,72);
+    }
+
+    // 获取结果
+    public static String getResult(String msg){
+        if(msg.length() < 74){
+            return "";
+        }
+        return msg.substring(72,74);
+    }
+
+    // 获取日期
+    public static String getDay(String msg){
+        if(msg.length() < 86){
+            return "";
+        }
+        return msg.substring(76,86);
+    }
+
+    // 获取时间
+    public static String getTime(String msg){
+        if(msg.length() < 96){
+            return "";
+        }
+        return msg.substring(88,96);
+    }
+
+}

+ 168 - 0
src/com/mes/netty/XDecoder.java

@@ -0,0 +1,168 @@
+package com.mes.netty;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufUtil;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.handler.codec.ByteToMessageDecoder;
+
+import java.util.List;
+
+public class XDecoder extends ByteToMessageDecoder {
+    static final int PACKET_SIZE = 46; // 最短包长度
+    static final int PACKET_MAX_SIZE = 1000; // 最长包长度
+
+    // 用来临时保留没有处理过的请求报文
+    ByteBuf tempMsg = Unpooled.buffer();
+
+    /**
+     * @param ctx
+     * @param in 请求的数据
+     * @param out 将粘在一起的报文拆分后的结果保留起来
+     * @throws Exception
+     */
+    @Override
+    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
+        System.out.println(Thread.currentThread() + "收到了一次数据包,长度是:" + in.readableBytes());
+        String content = hexStringToAscii(ByteBufUtil.hexDump(in));
+        System.out.println("接收包内容:" + hexStringToAscii(ByteBufUtil.hexDump(in)));
+
+        // 合并报文
+        ByteBuf message = null;
+        int tmpMsgSize = tempMsg.readableBytes();
+        // 如果暂存有上一次余下的请求报文,则合并
+        if (tmpMsgSize > 0) {
+            message = Unpooled.buffer();
+            message.writeBytes(tempMsg);
+            message.writeBytes(in);
+            System.out.println("合并:上一数据包余下的长度为:" + tmpMsgSize + ",合并后长度为:" + message.readableBytes());
+            System.out.println("合并后包内容:" + hexStringToAscii(ByteBufUtil.hexDump(message)));
+        } else {
+            message = in;
+        }
+
+//        System.out.println(Thread.currentThread() + "收到了一次数据包,长度是:" + message.readableBytes());
+        int size = 0;
+        String split = "bbbbfffffARW";
+
+        while (true){
+            size = message.readableBytes();
+            if(size >= PACKET_SIZE){
+                String retType = "NG:";
+                int qcsize = 0;
+                String str = hexStringToAscii(ByteBufUtil.hexDump(message));
+                String[] lists = str.split(split);
+
+                if(lists.length == 1 && size > PACKET_MAX_SIZE){ // 大于最大包长度
+                    byte[] request = new byte[size - PACKET_MAX_SIZE];
+                    // 每次从总的消息中读取n个字节的数据
+                    message.readBytes(request);
+                    // 将拆分后的结果放入out列表中,交由后面的业务逻辑去处理
+                    out.add(retType+hexStringToAscii(ByteBufUtil.hexDump(Unpooled.copiedBuffer(request))));
+                    break;
+                }
+
+                if(lists[0].length() > 0){
+                    byte[] request = new byte[lists[0].length()];
+                    // 每次从总的消息中读取n个字节的数据
+                    message.readBytes(request);
+                    // 将拆分后的结果放入out列表中,交由后面的业务逻辑去处理
+                    out.add(retType+hexStringToAscii(ByteBufUtil.hexDump(Unpooled.copiedBuffer(request))));
+                }else{
+                    if(lists.length > 1){
+                        String ss = lists[1];
+                        if(ss.length() <= 4){
+                            qcsize += ss.length();
+                        }else{
+                            String msgType = ProtocolParam.getMsgType(split+ss);
+                            if(!MesMsgUtils.isMsgTypeOk(msgType)){
+                                qcsize += split.length() + ss.length();
+                            }else{
+                                Integer ppsize = checkResultSize(ss,msgType,split);
+                                if(ppsize > 0){
+                                    qcsize = ppsize;
+                                    retType = "OK:";
+                                }else{
+                                    qcsize += split.length() + ss.length();
+                                }
+                            }
+                        }
+                    }
+                }
+
+
+                if(qcsize > 0){
+                    byte[] request = new byte[qcsize];
+                    // 每次从总的消息中读取n个字节的数据
+                    message.readBytes(request);
+                    // 将拆分后的结果放入out列表中,交由后面的业务逻辑去处理
+                    out.add(retType+hexStringToAscii(ByteBufUtil.hexDump(Unpooled.copiedBuffer(request))));
+                }
+            }else{
+                break;
+            }
+        }
+
+        // 多余的报文存起来
+        // 第一个报文: i+  暂存
+        // 第二个报文: 1 与第一次
+        size = message.readableBytes();
+        if (size != 0) {
+            System.out.println("多余的数据长度:" + size);
+            // 剩下来的数据放到tempMsg暂存
+            tempMsg.clear();
+            tempMsg.writeBytes(message.readBytes(size));
+        }
+    }
+
+    private Integer checkResultSize(String str, String msg_type, String split){
+        String oldstr = str;
+        str = split+str;
+        int tpsize = 0;
+        switch(msg_type) {
+            case "SYNR": // 同步
+                if(str.length() >= MesMsgUtils.SYNR_LEN){
+                    tpsize = MesMsgUtils.SYNR_LEN;
+                }
+                break;
+            case "AXTW": // 心跳
+                if(str.length() >= MesMsgUtils.AXTW_LEN){
+                    tpsize = MesMsgUtils.AXTW_LEN;
+                }
+                break;
+            case "ACLW": // 重连
+                if(str.length() >= MesMsgUtils.ACLW_LEN){
+                    tpsize = MesMsgUtils.ACLW_LEN;
+                }
+                break;
+            case "MCJW":
+            case "AQDW":
+            case "MBDW":
+            case "MJBW":
+            case "MQDW":
+            case "MKSW":
+            case "MSBW":
+            case "MCSW":
+            case "AQRW":
+            default: // 默认新报文
+                if(str.length() >= ProtocolParam.fixedLength){ // 大于固定长度
+                    tpsize = ProtocolParam.fixedLength;
+                }
+                break;
+        }
+
+        return tpsize;
+    }
+
+    // 16字符串转Ascii
+    private String hexStringToAscii(String hexString) {
+        StringBuilder sbuilder = new StringBuilder();
+        for (int i = 0; i < hexString.length(); i += 2) {
+            String hexByte = hexString.substring(i, i + 2);
+            int byteValue = Integer.parseInt(hexByte, 16);
+            char c = (char) byteValue;
+            sbuilder.append(c);
+        }
+        return sbuilder.toString();
+    }
+}

+ 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;
+    }
+}

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

@@ -0,0 +1,302 @@
+package com.mes.ui;
+
+import com.alibaba.fastjson2.JSONObject;
+import com.mes.netty.NettyClient;
+import com.mes.util.DateLocalUtils;
+import com.mes.util.JdbcUtils;
+
+import java.io.*;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Properties;
+
+public class DataUtil {
+
+    public static Boolean synrTcp(NettyClient nettyClient,String mes_gw){
+        try{
+            //TCP连接后,直接先发同步报文
+            String start = "aaaabbbbbABW";
+            String msgType = "SYNR";
+            String gw = "GW"+DataUtil.rightPad(mes_gw, 6);
+            String da = "DA" + DateLocalUtils.getCurrentDate();
+            String zt = "ZT" + DateLocalUtils.getCurrentTimeHMS();
+            String synr_str = start + msgType + gw + da + zt;
+            //插入报文本地数据
+            String gy = "";
+            String sn = "";
+            JdbcUtils.insertData(gw, gy, synr_str, msgType, sn);
+
+            nettyClient.run(synr_str);
+
+            return true;
+        }catch (Exception e){
+            return false;
+        }
+    }
+
+    public static Boolean heartBeat(NettyClient nettyClient,String mes_gw){
+        try{
+            //TCP连接后,直接先发同步报文
+            String start = "aaaabbbbbABW";
+            String msgType = "AXTW";
+            String gw = "GW"+DataUtil.rightPad(mes_gw, 6);
+            String da = "DA" + DateLocalUtils.getCurrentDate();
+            String zt = "ZT" + DateLocalUtils.getCurrentTimeHMS();
+            String axtw_str = start + msgType + gw + da + zt;
+            //插入报文本地数据
+            String gy = "";
+            String sn = "";
+            JdbcUtils.insertData(gw, gy, axtw_str, msgType, sn);
+            nettyClient.future.channel().writeAndFlush(axtw_str);
+
+            return true;
+        }catch (Exception e){
+            return false;
+        }
+    }
+
+    public static Boolean checkQuality(NettyClient nettyClient, String sn, String user){
+        try{
+            String msgType = "AQDW";
+            String gy = "100000";
+            Boolean aqdw_str = sendMessage(nettyClient,msgType,gy,"",sn,"",user,"00","");
+            return aqdw_str;
+        }catch (Exception e){
+            return false;
+        }
+    }
+
+    public static Boolean startWork(NettyClient nettyClient,String sn,String user){
+        try{
+            String msgType = "MKSW";
+            String gy = "";
+            Boolean aqdw_str = sendMessage(nettyClient,msgType,gy,"",sn,"",user,"00","");
+            return aqdw_str;
+        }catch (Exception e){
+            return false;
+        }
+    }
+
+    public static Boolean bindUser(NettyClient nettyClient,String sn,String user){
+        try{
+            String msgType = "MBDW";
+            String gy = "400001";
+            String param = rightPad(user, 36);
+            Boolean aqdw_str = sendMessage(nettyClient,msgType,gy,"",sn,"",user,"01",param);
+            return aqdw_str;
+        }catch (Exception e){
+            return false;
+        }
+    }
+
+    public static Boolean bindWarehouse(NettyClient nettyClient,String sn,String wsn,String user,String craft){
+        try{
+            String msgType = "MBDW";
+            String param = rightPad(wsn, 36);
+            Boolean aqdw_str = sendMessage(nettyClient,msgType,craft,"",sn,"",user,"01",param);
+            return aqdw_str;
+        }catch (Exception e){
+            return false;
+        }
+    }
+
+    public static Boolean unBindWarehouse(NettyClient nettyClient,String sn,String wsn,String user,String craft){
+        try{
+            String msgType = "MJBW";
+            String param = rightPad(wsn, 36);
+            Boolean aqdw_str = sendMessage(nettyClient,msgType,craft,"",sn,"",user,"01",param);
+            return aqdw_str;
+        }catch (Exception e){
+            return false;
+        }
+    }
+
+    public static Boolean sendQuality(NettyClient nettyClient,String sn,String ret,String user){
+        try{
+            String msgType = "MQDW";
+            String gy = "100000";
+            String param = "";
+            Boolean aqdw_str = sendMessage(nettyClient,msgType,gy,"",sn,ret,user,"00",param);
+            return aqdw_str;
+        }catch (Exception e){
+            return false;
+        }
+    }
+
+    public static Boolean sendMessage(NettyClient nettyClient,String msgType,String craft,String lx,String sn,String result,String user,String paramNums,String params){
+        try{
+            // 使用内存中的动态变量,支持前端修改后的同步
+            String gw = "GW"+rightPad(MesClient.mes_gw, 6);
+            String start = "aaaabbbbbABW";
+            String gy = "GY" + rightPad(craft, 6);
+            String reslx = "LX" + rightPad(lx, 2);
+            String id = MesClient.mes_line_sn + rightPad(sn, 36);
+            String rs = "RS"+ rightPad(result, 2);
+            String da = "DA" + DateLocalUtils.getCurrentDate();
+            String zt = "ZT" + DateLocalUtils.getCurrentTimeHMS();
+            String yh = "YH" + rightPad(user, 20);
+            String aqdw_str = start + msgType + gw + gy + reslx + id + rs + da + zt + yh + paramNums + params;
+            System.out.println("message="+aqdw_str);
+            JdbcUtils.insertData(gw, gy, aqdw_str, msgType, sn);
+            nettyClient.future.channel().writeAndFlush(aqdw_str);
+            return true;
+        }catch (Exception e){
+            return false;
+        }
+    }
+
+    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 mes_server_ip = MesClient.mes_server_ip;
+            String oprno = MesClient.mes_gw.trim();
+            String lineSn = MesClient.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 mes_server_ip = MesClient.mes_server_ip;
+            String oprno = MesClient.mes_gw.trim();
+            String lineSn = MesClient.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 JSONObject upParams(String upparams) {
+        try{
+            String mes_server_ip = MesClient.mes_server_ip;
+            String url = "http://"+mes_server_ip+":8980/js/a/mes/mesProductProd/batchsave";
+            String params = "__ajax=json&oprno="+MesClient.mes_gw+"&lineSn="+MesClient.mes_line_sn+"&params="+upparams;
+            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;
+    }
+
+    public static JSONObject upAlarm(String sn,String ucode) {
+        try{
+            String mes_server_ip = MesClient.mes_server_ip;
+            String oprno = MesClient.mes_gw.trim();
+            String lineSn = MesClient.mes_line_sn.trim();
+            String url = "http://"+mes_server_ip+":8980/js/a/mes/mesProcessAlarm/add";
+            String params = "__ajax=json&oprno="+oprno+"&lineSn="+lineSn+"&sn="+sn+"&ucode="+ucode;
+            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;
+        }
+    }
+}

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

@@ -0,0 +1,53 @@
+package com.mes.ui;
+
+import com.mes.netty.MesMsgUtils;
+import com.mes.netty.ProtocolParam;
+
+public class ErrorMsg {
+    public static void setErrorMsg(String mes_msg){
+        try{
+            String msg_type = ProtocolParam.getMsgType(mes_msg);
+            String processMsgRet = MesMsgUtils.processMsg(mes_msg, msg_type);
+            String lmsg = "该工件本工位不可加工";
+            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"+ ProtocolParam.getLx(mes_msg)+"0加工NG";
+            }else if(processMsgRet.equalsIgnoreCase("QD")) {
+                lmsg = "该工件OP"+ ProtocolParam.getLx(mes_msg)+"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("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 = "工件码重复";
+            }
+
+            MesClient.setMenuStatus(lmsg,-1);
+        }catch (Exception e){
+            MesClient.setMenuStatus("未知错误",-1);
+        }
+    }
+}

+ 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) {
+
+        }
+    }
+}

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

@@ -0,0 +1,206 @@
+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;
+
+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) {
+                    //初始化tcp连接,发送同步报文
+                    MesClient.initTcpConnection();
+                    //启动timer心跳包
+                    MesClient.startHeartBeatTimer();
+
+                    //1操作工人,2管理员
+                    //登录成功
+                    MesClient.user_menu.setText(user_id);
+                    MesClient.welcomeWin.setVisible(false);
+                    MesClient.mesClientFrame.setVisible(true);
+
+                    if(MesClient.jfxPanel == null){
+                        String url = "http://"+ MesClient.mes_server_ip+":8980/js/a/mes/mesProductRecord/work?__sid="+MesClient.sessionid+"&oprno="+MesClient.mes_gw+"&lineSn="+MesClient.mes_line_sn;
+                        MesClient.jfxPanel = new MesWebView(url);
+                        MesClient.jfxPanel.setSize(990, 550);
+                        MesClient.indexPanelB.add(MesClient.jfxPanel);
+                    }
+
+                    if(MesClient.jfxPanel2 == null){
+                        String url = "http://"+ MesClient.mes_server_ip+":8980/js/a/mes/mesProcessCheckRecord/ulist?__sid="+MesClient.sessionid+"&oprno="+MesClient.mes_gw+"&lineSn="+MesClient.mes_line_sn;
+                        MesClient.jfxPanel2 = new MesWebView(url);
+                        MesClient.jfxPanel2.setSize(990, 550);
+                        MesClient.indexPanelC.add(MesClient.jfxPanel2);
+                    }
+
+                    MesClient.initWarehouseData();
+                }
+
+            }
+
+        }else {
+            JOptionPane.showMessageDialog(MesClient.mesClientFrame,"登录失败,用户名或密码错误","提示窗口", JOptionPane.INFORMATION_MESSAGE);
+            return;
+        }
+    }
+}

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

@@ -0,0 +1,983 @@
+package com.mes.ui;
+
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONObject;
+import com.github.xingshuangs.iot.protocol.modbus.service.ModbusTcp;
+import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType;
+import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
+import com.mes.component.ConfigPanel;
+import com.mes.component.MesRadio;
+import com.mes.component.MesWebView;
+import com.mes.netty.NettyClient;
+import com.mes.util.DateLocalUtils;
+import com.mes.util.JdbcUtils;
+import javafx.embed.swing.JFXPanel;
+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.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.*;
+import java.util.List;
+import java.util.Timer;
+
+public class MesClient extends JFrame {
+
+    public static final Logger log = LoggerFactory.getLogger(MesClient.class);
+    private static String Driver = "org.sqlite.JDBC";
+
+    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_tcp_port = 3000; // TCP服务端口 (默认)
+    public static int mes_heart_beat_cycle = 10; // 心跳周期 (默认)
+    public static int mes_heart_icon_cycle = 1;
+    public static String mes_line_sn = "XT"; // 产线编号 (默认)
+
+    //TCP连接
+    public static NettyClient nettyClient;
+    //TCP连接状态
+    public static boolean tcp_connect_flag = false;
+    //TCP连接请求
+    public static boolean connect_request_flag = false;
+
+    //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;
+    public static JScrollPane searchScrollPaneDj;
+    public static ConfigPanel configPanel; // 配置面板
+
+
+    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 JPanel indexPanelB;
+    public static MesWebView jfxPanel = null;
+    public static JPanel indexPanelC;
+    public static MesWebView jfxPanel2 = null;
+    public static MesRadio mesRadioHj;
+
+    public static JTextField param1;
+    public static JTextField param2;
+    public static JTextField param_f; // 拉力显示
+    public static JTextField param_s; // 位移显示
+
+    public static String curIpA = "192.168.0.200"; // PLC IP (默认)
+    public static S7PLC plcA = null; // 延迟初始化
+
+    public static Timer cjTimer;
+
+    public static Timer cjTimer2;
+
+    public static Timer cjTimer3;
+
+    public static int aSetNum = 11;
+    public static int bSetNum = 0; // 单枪模式,B枪设为0
+    public static int sortA = 0;
+    public static int aMax = 11;
+    public static Short aFinish = 0;
+    public static List<Map> alist = new ArrayList<>();
+    public static List<String> atids = new ArrayList<>();
+
+    public static Integer tjStatus = 0; // 0=未提交 1=已提交
+
+
+    public static String namea = "A"; // A枪名称 M5
+    public static Integer maxa = 12; // A枪任务数  360=12 290=89
+    public static Integer cura = 0; // A枪当前数
+    public static Integer resulta = 0; // A枪结果 0=NG 1=OK
+
+    public static String tjFlagTextErr = "结果上传MES失败,请重试";
+
+    public static String curSn = "";
+
+    public static JTable table;
+    public static Object[] columnNames = { "物料名称", "绑定批次", "剩余次数", "操作" };
+    public static Object[][] rowData = null;
+
+    public static void main(String[] args) {
+        if (LockUtil.getInstance().isAppActive() == true){
+//            JOptionPane.showMessageDialog(null, "已有一个程序在运行,程序退出");
+            return;
+        }
+        EventQueue.invokeLater(new Runnable() {
+            @Override
+            public void run() {
+                try{
+                    // 1. 加载驱动并建立连接
+                    JdbcUtils.getConn();
+
+                    // 2. 读文件配置 (第二优先级,覆盖硬编码)
+                    readProperty();
+
+                    // 3. 初始化本地数据库配置 (第一优先级,覆盖文件配置)
+                    initLocalConfig();
+
+                    // 3.5 最终初始化 PLC 连接 (根据确定的 IP)
+                    if (plcA == null) {
+                        plcA = new S7PLC(EPlcType.S1200, curIpA);
+                    }
+
+                    // 4. 显示界面
+                    mesClientFrame = new MesClient();
+                    mesClientFrame.setVisible(false);
+
+                    welcomeWin = new LoginFarme();
+                    welcomeWin.setVisible(true);
+
+                    getPlcParam();
+
+                    upParams();
+
+                    setDeviceStart();
+
+                    getMaterailData();
+
+                }catch (Exception e){
+                    e.printStackTrace();
+                }
+            }
+        });
+    }
+
+    /**
+     * 重连 PLC (仅当 IP 地址确实发生变更时执行)
+     */
+    public static void reconnectPlc(String newIp) {
+        try {
+            // 增加二次校验:如果新 IP 与当前 IP 相同,则跳过重连
+            if (plcA != null && curIpA.equals(newIp)) {
+                log.info("PLC IP 未发生变化,跳过重连。");
+                return;
+            }
+            
+            curIpA = newIp;
+            plcA = new S7PLC(EPlcType.S1200, newIp);
+            log.info("PLC IP 已变更,执行重连: " + newIp);
+        } catch (Exception e) {
+            log.error("PLC 重连失败", e);
+        }
+    }
+
+    public static java.util.Timer cjTimer4;
+    public static void setDeviceStart() {
+        if(cjTimer4!=null) {
+            cjTimer4.cancel();
+        }
+        cjTimer4 = new Timer();
+        cjTimer4.schedule(new TimerTask() {
+            public void run() {
+                try{
+                    if(work_status == 1){
+//                        Boolean reta = plcA.readBoolean("DB14.0.0");
+//                      Boolean reta = plcA.readBoolean("DB4.DBX0.1");
+//                        if(reta){ // mes未允许
+//                            PlcUtil.setPowerOn(plcA);
+//                        }
+                    }else{
+//                        Boolean reta = plcA.readBoolean("DB14.0.0");
+//                        Boolean reta = plcA.readBoolean("DB4.DBX0.1");
+//                        if(!reta){ // mes允许
+//                            PlcUtil.setPowerOff(plcA);
+//                        }
+                    }
+                }catch (Exception e){
+                    e.printStackTrace();
+                }
+            }
+        }, 1000,1000);
+    }
+
+    //读配置文件
+    private static void readProperty() throws IOException{
+        String enconding = "UTF-8";
+        InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
+        if (is == null) {
+            log.warn("未找到 config.properties 文件,将使用硬编码默认值");
+            return;
+        }
+        Properties pro = new Properties();
+        BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
+        pro.load(br);
+
+        // 逐项判空覆盖 (只有配置文件中有值时才覆盖默认值)
+        String tmpGw = pro.getProperty("mes.gw");
+        if (tmpGw != null && !tmpGw.isEmpty()) mes_gw = tmpGw;
+
+        String tmpServerIp = pro.getProperty("mes.server_ip");
+        if (tmpServerIp != null && !tmpServerIp.isEmpty()) mes_server_ip = tmpServerIp;
+
+        String tmpPort = pro.getProperty("mes.tcp_port");
+        if (tmpPort != null && !tmpPort.isEmpty()) mes_tcp_port = Integer.parseInt(tmpPort);
+
+        String tmpCycle = pro.getProperty("mes.heart_beat_cycle");
+        if (tmpCycle != null && !tmpCycle.isEmpty()) mes_heart_beat_cycle = Integer.parseInt(tmpCycle);
+
+        String tmpLineSn = pro.getProperty("mes.line_sn");
+        if (tmpLineSn != null && !tmpLineSn.isEmpty()) mes_line_sn = tmpLineSn;
+
+        // 根据加载后的产线和工位获取描述
+        mes_gw_des = OprnoUtil.getGwDes(mes_line_sn, mes_gw);
+
+        log.info("配置文件加载完成: " + mes_gw + ";" + mes_gw_des + ";" + mes_server_ip + ";" + mes_tcp_port);
+    }
+
+    private static void initLocalConfig() {
+        // 1. 尝试从数据库加载 (最高优先级)
+        Map<String, Object> config = JdbcUtils.getConfig();
+        if (config != null && config.size() > 0) {
+            // 数据库中的值只有不为 null 时才覆盖
+            if (config.get("a_set_num") != null) {
+                aSetNum = (Integer) config.get("a_set_num");
+                aMax = aSetNum;
+            }
+
+            String dbIp = (String) config.get("plc_ip");
+            if (dbIp != null && !dbIp.isEmpty()) curIpA = dbIp;
+
+            String dbGw = (String) config.get("mes_gw");
+            if (dbGw != null && !dbGw.isEmpty()) mes_gw = dbGw;
+
+            String dbGwDes = (String) config.get("mes_gw_des");
+            if (dbGwDes != null && !dbGwDes.isEmpty()) mes_gw_des = dbGwDes;
+
+            log.info("本地数据库配置加载成功,已覆盖文件配置。");
+        } else {
+            log.info("本地数据库无配置,将维持配置文件或硬编码配置。");
+        }
+
+        // 同步 UI 初始值
+        if (param1 != null) param1.setText(String.valueOf(aSetNum));
+    }
+
+    public static void getPlcParam() {
+        if(cjTimer!=null) {
+            cjTimer.cancel();
+        }
+        cjTimer = new Timer();
+        cjTimer.schedule(new TimerTask() {
+            public void run() {
+                try{
+                    if(work_status == 1){
+                        PlcUtil.getDataA(plcA);
+                    }
+
+                }catch (Exception e){
+                    e.printStackTrace();
+                }
+            }
+        }, 1000,500);
+    }
+
+    public static void upParams() {
+        if(cjTimer2!=null) {
+            cjTimer2.cancel();
+        }
+        cjTimer2 = new Timer();
+        cjTimer2.schedule(new TimerTask() {
+            public void run() {
+                try{
+                    List<ProdReq> prods = JdbcUtils.getProds();
+                    System.out.println("prods:"+ JSON.toJSONString(prods));
+                    if(prods.size() > 0){
+                        // 定时上传参数
+                        JSONObject retObj = DataUtil.upParams(JSON.toJSONString(prods));
+                        if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
+                            // 更新sqlite已同步
+                            for(ProdReq prodReq:prods){
+                                JdbcUtils.updateProdSync(prodReq.getId(),1);
+                            }
+                        }
+                    }
+                }catch (Exception e){
+                    e.printStackTrace();
+                }
+            }
+        }, 1000,30*1000);
+    }
+
+    // 初始化TCP
+    public static void initTcpConnection() {
+        try {
+            if(nettyClient==null) {
+                //初始化TCP连接
+                nettyClient = new NettyClient();
+                //TCP连接状态
+                tcp_connect_flag = false;
+                //设置TCP请求状态
+                connect_request_flag = true;
+
+                DataUtil.synrTcp(nettyClient,mes_gw);
+            }
+        } catch (Exception e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+    }
+
+    //启动心跳包程序
+    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();
+        }
+        heartBeatTimer = new java.util.Timer();
+        heartBeatTimer.schedule(new TimerTask() {
+            public void run() {
+                if(nettyClient!=null&&tcp_connect_flag) {
+                    //System.out.println("发送心跳报文");
+                    DataUtil.heartBeat(nettyClient,mes_gw);
+
+                    heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
+                }
+            }
+        }, 100,mes_heart_beat_cycle*1000);
+
+        //心跳显示图标
+        if(heartBeatIconTimer!=null) {
+            heartBeatIconTimer.cancel();
+        }
+        heartBeatIconTimer = new Timer();
+        heartBeatIconTimer.schedule(new TimerTask() {
+            public void run() {
+                if(tcp_connect_flag) {
+                    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();
+                }else {
+                    heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
+                    heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
+                    heart_beat_menu.repaint();
+
+                    //若未连接则尝试连接
+                    if(nettyClient!=null&&!tcp_connect_flag){
+                        System.out.println("TCP已断开");
+                        //TCP重新同步连接
+                        if(!connect_request_flag) {
+                            //System.out.println("TCP重新同步连接");
+                            //设置TCP请求状态,只重新同步连接一次
+                            connect_request_flag = true;
+
+                            DataUtil.synrTcp(nettyClient,mes_gw);
+                        }
+
+                    }
+                }
+            }
+        }, 100,mes_heart_icon_cycle*1000);
+    }
+
+    //设置tcp连接状态显示
+    public static void setTcpStatus() {
+        if(tcp_connect_flag) {
+            status_menu.setText("已连接MES服务器");
+            heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
+            heart_beat_menu.repaint();
+        }else {
+            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() {
+        MesClient.status_menu.setText("工件状态");
+        MesClient.curSn = "";
+        MesClient.product_sn.setText("");
+        MesClient.work_status = 0;
+        MesClient.check_quality_result = false;
+        MesClient.f_scan_data_bt_1.setEnabled(true);
+        MesClient.finish_ok_bt.setEnabled(false);
+        MesClient.finish_ng_bt.setEnabled(false);
+        MesClient.tjStatus = 0;
+
+        MesClient.sortA = 0;
+        MesClient.aFinish = 0;
+        MesClient.alist.clear();
+        MesClient.atids.clear();
+        MesClient.param2.setText("0");
+        MesClient.param_f.setText("0");
+        MesClient.param_s.setText("0");
+        MesClient.param1.setText(String.valueOf(aSetNum));
+
+        PlcUtil.setTask(MesClient.plcA, MesClient.aSetNum);
+        PlcUtil.setPowerOff(MesClient.plcA); // 远程关机
+    }
+
+    public static void checkSnType(String sn) {
+        if(sn.length() < 20){
+            return;
+        }
+        String xwd = sn.substring(0,14);
+        switch (xwd){
+            case "000020015308-0":// 国内长续航
+            case "000020015305-0":// 国内超长续航
+            case "000020020155-0":// 国内长续航
+            case "000020020156-0":// 国内超长续航
+            case "000020017939-0":// 中亚长续航
+            case "000020017933-0":// 中亚超长续航
+                aSetNum = 42;
+                aMax = 42;
+                break;
+            case "000020018302-0":// 海外长续航
+            case "000020018301-0":// 海外超长续航
+            case "000020020890-0":// 海外长续航
+            case "000020020889-0":// 海外超长续航
+                aSetNum = 46;
+                aMax = 46;
+                break;
+        }
+        if (param1 != null) {
+            param1.setText(String.valueOf(aSetNum));
+        }
+    }
+
+    //获取用户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);
+                    curSn = scanBarcode;
+                    break;
+            }
+            //刷新界面
+            mesClientFrame.repaint();
+
+            if(!tcp_connect_flag) {
+                JOptionPane.showMessageDialog(mesClientFrame,"设备未连接Mes服务器","提示窗口", JOptionPane.INFORMATION_MESSAGE);
+                return;
+            }
+
+            // 查询工件质量
+            Boolean sendret = DataUtil.checkQuality(nettyClient,barcode36,user20);
+            if(!sendret){
+                JOptionPane.showMessageDialog(mesClientFrame,"消息发送失败,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
+                return;
+            }
+        }else {
+            JOptionPane.showMessageDialog(mesClientFrame,"请扫工件码","提示窗口", JOptionPane.INFORMATION_MESSAGE);
+            return;
+        }
+    }
+
+    public static void logoff() {
+        welcomeWin.setVisible(true);
+        mesClientFrame.setVisible(false);
+
+        nettyClient = null;
+        tcp_connect_flag = false;
+        connect_request_flag = false;
+    }
+
+    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);
+
+        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("重连MES");
+        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);
+                //重连mes
+                nettyClient.future.channel().close();
+            }
+        });
+        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服务器");
+        if(tcp_connect_flag) {
+            status_menu.setText("已连接MES服务器");
+            status_menu.setForeground(Color.GREEN);
+        }else {
+            status_menu.setText("未连接MES服务器");
+            status_menu.setForeground(Color.DARK_GRAY);
+        }
+        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));
+        contentPane.add(tabbedPane);
+
+        //首页
+        JPanel indexPanelA = new JPanel();
+        indexScrollPaneA = new JScrollPane(indexPanelA);
+        indexPanelA.setLayout(null);
+
+        product_sn = new JTextField();
+        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 = new JButton("扫码");
+        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);
+
+        finish_ok_bt = new JButton("OK");
+        finish_ok_bt.setEnabled(false);
+        finish_ok_bt.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                if(work_status == 1 && check_quality_result){
+
+                    String sn = getBarcode(product_sn.getText());
+                    getUser();
+
+                    String qret = "OK";
+                    Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20);
+                    if(!sendret){
+                        MesClient.setMenuStatus("消息发送失败,请重试",-1);
+                        return;
+                    }
+                }
+            }
+        });
+        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, 371, 240, 80);
+        finish_ok_bt.setEnabled(false);
+        indexPanelA.add(finish_ok_bt);
+
+        finish_ng_bt = new JButton("NG");
+        finish_ng_bt.setEnabled(false);
+        finish_ng_bt.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                if(work_status == 1 && check_quality_result){
+
+                    String sn = getBarcode(product_sn.getText());
+                    getUser();
+                    String qret = "NG";
+                    Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20);
+                    if(!sendret){
+                        MesClient.setMenuStatus("消息发送失败,请重试",-1);
+                        return;
+                    }
+                }
+            }
+        });
+        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, 371, 240, 80);
+        finish_ng_bt.setEnabled(false);
+        indexPanelA.add(finish_ng_bt);
+
+        JLabel lblNewLabel = new JLabel("拉铆枪");
+        lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
+        lblNewLabel.setFont(new Font("微软雅黑", Font.PLAIN, 20));
+        lblNewLabel.setBounds(370, 186, 166, 28);
+        indexPanelA.add(lblNewLabel);
+
+        JLabel lblNewLabel_1 = new JLabel("预设数量");
+        lblNewLabel_1.setFont(new Font("微软雅黑", Font.PLAIN, 18));
+        lblNewLabel_1.setBounds(270, 241, 83, 34);
+        indexPanelA.add(lblNewLabel_1);
+
+        param1 = new JTextField();
+        param1.setHorizontalAlignment(SwingConstants.CENTER);
+        param1.setFont(new Font("微软雅黑", Font.PLAIN, 18));
+        param1.setText(String.valueOf(aSetNum));
+        param1.setEditable(false);
+        param1.setBounds(354, 241, 83, 34);
+        indexPanelA.add(param1);
+        param1.setColumns(10);
+
+        JLabel lblNewLabel_1_1 = new JLabel("完成数量");
+        lblNewLabel_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 18));
+        lblNewLabel_1_1.setBounds(270, 285, 83, 34);
+        indexPanelA.add(lblNewLabel_1_1);
+
+        param2 = new JTextField();
+        param2.setHorizontalAlignment(SwingConstants.CENTER);
+        param2.setFont(new Font("微软雅黑", Font.PLAIN, 18));
+        param2.setText("0");
+        param2.setEditable(false);
+        param2.setColumns(10);
+        param2.setBounds(354, 285, 83, 34);
+        indexPanelA.add(param2);
+
+        JLabel lblF = new JLabel("拉力(N)");
+        lblF.setFont(new Font("微软雅黑", Font.PLAIN, 18));
+        lblF.setBounds(500, 241, 83, 34);
+        indexPanelA.add(lblF);
+
+        param_f = new JTextField();
+        param_f.setHorizontalAlignment(SwingConstants.CENTER);
+        param_f.setFont(new Font("微软雅黑", Font.PLAIN, 18));
+        param_f.setText("0");
+        param_f.setEditable(false);
+        param_f.setColumns(10);
+        param_f.setBounds(584, 241, 83, 34);
+        indexPanelA.add(param_f);
+
+        JLabel lblS = new JLabel("位移(mm)");
+        lblS.setFont(new Font("微软雅黑", Font.PLAIN, 18));
+        lblS.setBounds(500, 285, 83, 34);
+        indexPanelA.add(lblS);
+
+        param_s = new JTextField();
+        param_s.setHorizontalAlignment(SwingConstants.CENTER);
+        param_s.setFont(new Font("微软雅黑", Font.PLAIN, 18));
+        param_s.setText("0");
+        param_s.setEditable(false);
+        param_s.setColumns(10);
+        param_s.setBounds(584, 285, 83, 34);
+        indexPanelA.add(param_s);
+
+        tabbedPane.addTab("工作面板", new ImageIcon(MesClient.class.getResource("/bg/a_side.png")), indexScrollPaneA, null);
+        tabbedPane.setEnabledAt(0, true);
+
+        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);
+
+        // 设备管理 (配置页)
+        configPanel = new ConfigPanel();
+        tabbedPane.addTab("设备管理", new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")), configPanel, 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);
+
+                if (selectedIndex == 3) { // 假设设备管理是第4个页签 (索引为3)
+                    String password = JOptionPane.showInputDialog(mesClientFrame, "请输入管理员密码:", "权限验证", JOptionPane.QUESTION_MESSAGE);
+                    if (password != null && password.equalsIgnoreCase("mes")) {
+                        lastSelectedIndex = selectedIndex;
+                        if (configPanel != null) configPanel.refreshFields();
+                    } else {
+                        if (password != null) {
+                            JOptionPane.showMessageDialog(mesClientFrame, "密码错误!", "错误", JOptionPane.ERROR_MESSAGE);
+                        }
+                        // 跳回上一个选中的页签
+                        tabbedPane.setSelectedIndex(lastSelectedIndex);
+                    }
+                } else {
+                    lastSelectedIndex = selectedIndex;
+                }
+            }
+        });
+    }
+
+    public static int lastSelectedIndex = 0;
+
+    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(){
+        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();
+        }
+    }
+
+    public static void updateMaterailData(){
+        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();
+        }
+    }
+
+    // 绑定物料批次码
+    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);
+        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);
+    }
+}

+ 121 - 0
src/com/mes/ui/MesRevice.java

@@ -0,0 +1,121 @@
+package com.mes.ui;
+
+import com.mes.netty.ProtocolParam;
+import com.mes.component.MyDialog;
+
+import javax.swing.*;
+import java.awt.*;
+
+public class MesRevice {
+
+    // 质量查询
+    public static void checkQualityRevice(String processMsgRet,String mes_msg){
+        try{
+            String sn = ProtocolParam.getSn(mes_msg).trim();
+            MesClient.checkSnType(sn);
+
+            if(processMsgRet.equalsIgnoreCase("UD")) {
+                MesClient.status_menu.setForeground(Color.GREEN);
+                MesClient.check_quality_result = true;//质量合格,可以绑定加工
+                MesClient.setMenuStatus("该工件可以加工",0);
+
+                MesClient.work_status = 1;
+                MesClient.f_scan_data_bt_1.setEnabled(false);
+                MesClient.tjStatus = 0;
+
+                PlcUtil.setPowerOn(MesClient.plcA); // 远程开机
+                PlcUtil.setTask(MesClient.plcA,MesClient.aSetNum);
+
+                //扫码后,验证可以加工之后进行实际值清0
+                MesClient.param2.setText("0");
+
+   /*             //拉铆箱实际值清零
+                MesClient.plcA.writeInt32("DB1.184.0",0);
+                MesClient.plcA.writeInt32("DB1.714.0",0);*/
+
+            }else {
+                MesClient.check_quality_result = false;
+                ErrorMsg.setErrorMsg(mes_msg);
+
+                PlcUtil.setPowerOff(MesClient.plcA);
+
+            }
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+    }
+
+    // 开始回复处理
+    public static void startRevice(String processMsgRet,String mes_msg){
+        try{
+            if(processMsgRet.equalsIgnoreCase("OK")) {
+                MesClient.work_status = 1;
+                MesClient.f_scan_data_bt_1.setEnabled(false);
+                MesClient.tjStatus = 0;
+//                MesClient.deviceControl = ModbusUtil.getControlModel(MesClient.plcA);
+//                if(MesClient.deviceControl == 1){
+//
+//                }
+
+//                MesClient.plcA.writeCoil(3128,false);
+//                MesClient.plcB.writeCoil(3128,false);
+
+//                ModbusUtil.setPowerOn(MesClient.plcA); // 远程开机
+//                ModbusUtil.setPowerOn(MesClient.plcB); // 远程开机
+//
+//                ModbusUtil.setTask(MesClient.plcA,MesClient.aSetNum);
+//                ModbusUtil.setTask(MesClient.plcB,MesClient.bSetNum);
+            }
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+    }
+
+    // 绑定
+    public static void bindRevice(String processMsgRet,String mes_msg){
+        try{
+            if(processMsgRet.equalsIgnoreCase("OK")) {
+
+            }else{
+
+            }
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+    }
+
+    // 解绑
+    public static void unbindRevice(String processMsgRet,String mes_msg){
+        try{
+            if(processMsgRet.equalsIgnoreCase("OK")) {
+
+            }else{
+
+            }
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+    }
+
+    // 上传质量
+    public static void updateResultRevice(String processMsgRet,String mes_msg){
+        try{
+            if(processMsgRet.equalsIgnoreCase("OK")) {
+
+                MesClient.resetScanA();
+//                MesClient.status_menu.setText("结果提交成功,请扫下一件");
+                MesClient.setMenuStatus("结果提交成功,请扫下一件",0);
+                MesClient.scan_type = 1;
+//                MesClient.scanBarcode();
+
+            }else{
+                MesClient.setMenuStatus("结果提交失败,请重试",-1);
+//                MesClient.status_menu.setText("结果提交失败,请重试");
+//                JOptionPane.showMessageDialog(MesClient.mesClientFrame,"结果提交失败,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
+//                return;
+            }
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+    }
+}

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

@@ -0,0 +1,194 @@
+package com.mes.ui;
+
+import com.github.xingshuangs.iot.protocol.modbus.service.ModbusTcp;
+import com.mes.util.JdbcUtils;
+
+import java.nio.charset.Charset;
+
+public class ModbusUtil {
+
+    public static void getDataA(ModbusTcp plc){
+
+        // 说明
+        //预设数量有变化不能修改
+        // 打钉数应按实际监听数算
+
+        // 41065=F-out  41066=S-out
+        // 41069=F-min  41071=S-min 41070=F-max  41072=S-max
+        // 预设数量=41129  完成数=41137
+
+        Short cur = plc.readInt16(1136);
+//        System.out.println("F-out:"+plc.readInt16(1064));
+//        System.out.println("S-out:"+plc.readInt16(1065));
+//        System.out.println("F-min:"+plc.readInt16(1068));
+//        System.out.println("S-min:"+plc.readInt16(1070));
+//        System.out.println("F-max:"+plc.readInt16(1069));
+//        System.out.println("S-max:"+plc.readInt16(1071));
+//        System.out.println("预设数量:"+plc.readInt16(1128));
+        //System.out.println("当前数量:"+cur);
+        if(MesClient.aMax <= 0){
+            MesClient.aMax = plc.readInt16(1128); // 任务数量
+            MesClient.param1.setText(String.valueOf(MesClient.aMax));
+        }
+
+        if(MesClient.sortA == cur - 1){
+            MesClient.sortA = cur;
+            MesClient.aFinish = plc.readInt16(1138);
+            String fout = plc.readInt16(1064)+"";
+            String sout = (float)plc.readInt16(1065)/1000+"";
+
+            String fmin = plc.readInt16(1068)+"";
+            String smin = (float)plc.readInt16(1070)/1000+"";
+
+            String fmax = plc.readInt16(1069)+"";
+            String smax = (float)plc.readInt16(1071)/1000+"";
+
+            MesClient.param2.setText(cur+"");
+            System.out.println("cur:"+cur);
+            if(!MesClient.product_sn.getText().isEmpty()){
+                JdbcUtils.insertProdData(MesClient.mes_gw, MesClient.mes_line_sn, MesClient.product_sn.getText(),"A",fout,sout,fmin,smin,fmax,smax,"1",cur+"", MesClient.user_menu.getText());
+            }
+        }
+
+        upResult();
+    }
+
+
+
+    // 上传总结果
+    public static void upResult(){
+        if(!MesClient.curSn.isEmpty() && MesClient.aMax > 0 && MesClient.aMax == MesClient.sortA){
+            MesClient.finish_ok_bt.setEnabled(true);
+            MesClient.finish_ng_bt.setEnabled(true);
+
+            if(MesClient.tjStatus == 0 && MesClient.check_quality_result){
+                MesClient.tjStatus = 1;
+                MesClient.getUser();
+                String retf = "OK";
+                if(MesClient.aFinish != MesClient.aMax){
+                    retf = "NG";
+                }
+                Boolean ret = DataUtil.sendQuality(MesClient.nettyClient, MesClient.product_sn.getText(),retf, MesClient.user20);
+                if(!ret){
+                    MesClient.setMenuStatus(MesClient.tjFlagTextErr,-1);
+                }
+            }
+
+        }
+    }
+
+    // 获取控制模式
+    public static short getControlModel(ModbusTcp plc){
+        short control = 0;
+        try{
+            control = plc.readInt16(1090);
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+
+        return control;
+    }
+
+    // 获取二维码
+    public static String getSn(ModbusTcp plc){
+        String sn = "";
+        try{
+            sn = plc.readString(1216,40, Charset.forName("UTF8"));
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+
+        return splitIntoChunks(sn,2);
+    }
+
+    // 每两个字符分割,并反转
+    private static String splitIntoChunks(String str, int chunkSize) {
+        if (str == null || str.isEmpty() || chunkSize <= 0) {
+            return "";
+        }
+
+        int length = str.length();
+        int arraySize = (length + chunkSize - 1) / chunkSize;
+        String[] result = new String[arraySize];
+
+        for (int i = 0, j = 0; i < length; i += chunkSize, j++) {
+            int endIndex = Math.min(i + chunkSize, length);
+            String sttr = str.substring(i, endIndex);
+            StringBuilder sb = new StringBuilder(sttr);
+            String reversedStr = sb.reverse().toString(); // 字符串反转
+            result[j] = reversedStr;
+        }
+
+        return String.join("",result);
+    }
+
+    // 远程开机
+    public static Boolean setPowerOn(ModbusTcp plc){
+        Boolean ret = false;
+        try{
+            plc.writeCoil(3128,true);
+//            plc.writeCoil(3079,false);
+//            plc.writeCoil(3328,true); // 必须选关掉关机,开机才起左右
+            ret = true;
+        }catch (Exception e){
+            e.printStackTrace();
+            ret = false;
+        }
+
+        return ret;
+    }
+
+    // 远程关机
+    public static Boolean setPowerOff(ModbusTcp plc){
+        Boolean ret = false;
+        try{
+            plc.writeCoil(3128,false);
+//            plc.writeCoil(3328,false);
+//            plc.writeCoil(3079,true); // 关机
+            // 必须选关掉关机,开机才起左右
+            ret = true;
+        }catch (Exception e){
+            e.printStackTrace();
+            ret = false;
+        }
+
+        return ret;
+    }
+
+    // 重置任务
+    public static void setTask(ModbusTcp plc,Short setNum){
+        try{
+            // 设置模式 1=标记铆接模式
+            plc.writeInt16(1092,(short) 1);
+            // 设置任务
+            plc.writeInt16(1128,setNum);
+            plc.writeInt16(1136,(short) 0);
+            plc.writeInt16(1138,(short) 0);
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+    }
+
+
+//        A枪说明 192.168.1.7
+//        plc.writeCoil(3079,false);
+//        plc.writeCoil(3328,true); // 必须选关掉关机,开机才起左右
+////        plc.writeCoil(3128,false);
+//        System.out.println("控制模式:"+plc.readInt16(1090)); // 1091 控制模式
+//        System.out.println("系统运行中:"+plc.readCoil(3128,1)); // 3129 系统运行中
+//        System.out.println("结束暂停:"+plc.readCoil(3132,1)); // 3133 系统运行中
+//        System.out.println("远程开机:"+plc.readCoil(3328,1)); // 3329 远程开机
+//        System.out.println("远程关机:"+plc.readCoil(3079,1)); // 3080 远程关机
+//        System.out.println("作业模式:"+plc.readInt16(1092)); // 1093 作业模式
+//        System.out.println("最大拉力:"+plc.readInt16(1064)); // 1065 最大拉力
+//        System.out.println("对应位移:"+plc.readInt16(1065)); // 1066 对应位移
+//        System.out.println("任务数量:"+plc.readInt16(1128)); // 1129 任务数量
+//        System.out.println("合格数量:"+plc.readInt16(1138)); // 1139 合格数量
+//        System.out.println("质量状态:"+plc.readInt16(1072)); // 1073 质量状态
+//        System.out.println("F-out:"+plc.readInt16(1064));
+//        System.out.println("S-out:"+plc.readInt16(1065));
+//        System.out.println("F-min:"+plc.readInt16(1068));
+//        System.out.println("S-min:"+plc.readInt16(1070));
+//        System.out.println("F-max:"+plc.readInt16(1069));
+//        System.out.println("S-max:"+plc.readInt16(1071));
+}

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

@@ -0,0 +1,65 @@
+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", "OP020", "OP030", "OP040", "OP051", "OP052", "OP060", "OP070",
+            "OP080", "OP090", "OP100", "OP110", "OP120", "OP130", "OP140", "OP150",
+            "OP160", "OP170", "OP180", "OP190", "OP200", "OP210", "OP220", "OP230",
+            "OP240", "OP250", "OP260", "OP270", "OP281", "OP282", "OP283", "OP284",
+            "OP290", "OP300", "OP310", "OP320", "OP330", "OP340", "OP350", "OP360",
+            "OP370", "OP380", "OP390", "OP400", "OP410", "OP420", "OP430", "OP440",
+            "OP450", "OP460", "OP470", "OP480", "OP490"
+    };
+    public static String[] xtoprnodes = new String[]{
+            "进料检", "入库", "领料", "镭雕二维码", "前后梁压铆", "前后梁压铆螺母柱-涂胶", "左/右前边框与封堵片焊接", "Flyback固定支架安装钢丝牙套",
+            "小总成焊接", "框架CMT焊接", "人工正面补焊", "人工反面补焊", "焊缝铣削打磨", "焊道检验", "框架CNC反面加工", "框架反面清洁去毛刺",
+            "框架找漏", "框架清洁", "框架终检", "液冷板安装", "冷板激光焊", "液冷板FSW", "水嘴、匙孔焊接", "CNC加工箱体正面",
+            "箱体正反面清洁", "封堵片焊接", "总成反面装螺套", "总成反面拉铆", "总成正面装配", "总成正面装配", "总成正面装配", "总成正面拉铆",
+            "安装中吊点", "型腔封堵", "箱体静置", "箱体气密", "液冷板气密检测", "粘贴MPP泡棉", "底护板气密", "底护板安装",
+            "底护板螺栓复拧", "反面终检", "粘贴陶瓷胶带", "总成清洁", "蓝光检测", "总成检具检验", "正面终检", "CCD错漏检",
+            "绝缘耐压检测", "接地点检测", "GP12", "下线拍照", "称重+包装"
+    };
+    public static String[] lboprnos = new String[]{};
+    public static String[] lboprnodes = new String[]{};
+    public static String getGwDes(String lineSn,String oprno){
+        String des = "";
+        oprno = formatOprno(oprno);
+        if(lineSn.equals("XT")){
+            int i = 0;
+            for (String gw:xtoprnos){
+                if(gw.equals(oprno)){
+                    des = xtoprnodes[i];
+                    break;
+                }
+                i++;
+            }
+        }else if(lineSn.equals("LB")){
+            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;
+    }
+}

+ 158 - 0
src/com/mes/ui/PlcUtil.java

@@ -0,0 +1,158 @@
+package com.mes.ui;
+
+import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
+import com.mes.util.JdbcUtils;
+import java.text.DecimalFormat;
+
+/**
+ * PLC 通讯工具类
+ * 处理 A 枪的数据采集、任务设置及状态控制
+ */
+public class PlcUtil {
+
+    /**
+     * 获取 A 枪数据
+     * @param plc PLC对象
+     */
+    public static void getDataA(S7PLC plc){
+        try {
+            // 读取当前完成数量 (DB41.32)
+            int cur = plc.readInt32("DB41.32.0");
+            MesClient.param1.setText(String.valueOf(MesClient.aMax));
+
+            // 如果当前数量增加,则记录数据
+            if(MesClient.sortA < cur){
+                MesClient.sortA = cur;
+                if (cur == 9){
+                    plc.writeUInt16("DB40.2",2);
+                }
+                
+                // 读取力值和位移
+                int fout = plc.readInt32("DB41.24.0");
+                Float sout = plc.readFloat32("DB41.28.0");
+
+                // 读取最小值设定
+                int fmin = plc.readInt32("DB41.0.0") - plc.readInt32("DB41.8.0");
+                Float smin = plc.readFloat32("DB41.12.0") - plc.readFloat32("DB41.20.0");
+
+                // 读取最大值设定
+                int fmax = plc.readInt32("DB41.0.0") + plc.readInt32("DB41.4.0");
+                Float smax = (float) (plc.readInt32("DB41.12.0") + plc.readFloat32("DB41.16.0"));
+
+                String qty = "0";
+                // 判定单次结果
+                if(getResultDingA(plc).equals("OK")){
+                    MesClient.aFinish++;
+                    qty = "1";
+                }
+
+                DecimalFormat decimalFormat = new DecimalFormat("#.###");
+                String soutstr = decimalFormat.format(sout);
+                String sminstr = decimalFormat.format(smin);
+                String smaxstr = decimalFormat.format(smax);
+                
+                String foutstr = fout + "";
+                MesClient.param2.setText(cur+"");
+                MesClient.param_f.setText(foutstr); // 实时更新拉力显示
+                MesClient.param_s.setText(soutstr); // 实时更新位移显示
+                
+                // 插入本地数据库
+                if(!MesClient.product_sn.getText().isEmpty()){
+                    JdbcUtils.insertProdData(MesClient.mes_gw, MesClient.mes_line_sn, MesClient.product_sn.getText(),"A",fout+"",soutstr,fmin+"",sminstr,fmax+"",smaxstr,qty,cur+"", MesClient.user_menu.getText());
+                }
+            }
+
+            // 任务完成,自动关机
+            if (cur >= MesClient.aMax){
+                setPowerOff(plc);
+            }
+
+            // 检查是否上传总结果
+            upResult();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 上传总结果到 MES
+     */
+    public static void upResult(){
+        // 当完成数量 (sortA) 等于 预设数量 (aMax) 时触发
+        if(!MesClient.curSn.isEmpty() && MesClient.aMax > 0 && MesClient.sortA == MesClient.aMax){
+            MesClient.finish_ok_bt.setEnabled(true);
+            MesClient.finish_ng_bt.setEnabled(true);
+
+            // 自动提交逻辑:仅在未提交且质量校验通过时执行一次
+            if(MesClient.tjStatus == 0 && MesClient.check_quality_result){
+                MesClient.tjStatus = 1; // 标记为已提交,防止重复触发
+                MesClient.setMenuStatus("正在自动提交结果...", 0);
+                
+                MesClient.getUser();
+                String retf = "OK";
+                // 如果 OK 的数量 (aFinish) 不等于 预设数量 (aMax),则总结果为 NG
+                if(MesClient.aFinish < MesClient.aMax){
+                    retf = "NG";
+                }
+                
+                Boolean ret = DataUtil.sendQuality(MesClient.nettyClient, MesClient.product_sn.getText(), retf, MesClient.user20);
+                if(!ret){
+                    MesClient.tjStatus = 0; // 发送失败则允许重试
+                    MesClient.setMenuStatus(MesClient.tjFlagTextErr, -1);
+                }
+            }
+        }
+    }
+
+    /**
+     * 远程开机
+     */
+    public static Boolean setPowerOn(S7PLC plc){
+        try{
+            plc.writeBoolean("DB40.0.0",true);
+            return true;
+        }catch (Exception e){
+            e.printStackTrace();
+            return false;
+        }
+    }
+
+    /**
+     * 远程关机
+     */
+    public static Boolean setPowerOff(S7PLC plc){
+        try{
+            plc.writeBoolean("DB40.0.0",false);
+            return true;
+        }catch (Exception e){
+            e.printStackTrace();
+            return false;
+        }
+    }
+
+    /**
+     * 重置任务并写入预设数量
+     */
+    public static void setTask(S7PLC plc,int setNumA){
+        try{
+            plc.writeUInt16("DB40.2",1);
+            plc.writeUInt16("DB40.4",setNumA);
+            plc.writeInt32("DB41.32.0",0);
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 获取单次拉铆结果
+     */
+    public static String getResultDingA(S7PLC plc){
+        try{
+            byte retang = plc.readByte("DB41.26");
+            return (retang == 1) ? "OK" : "NG";
+        }catch (Exception e){
+            e.printStackTrace();
+            return "NG";
+        }
+    }
+}

+ 148 - 0
src/com/mes/ui/ProdReq.java

@@ -0,0 +1,148 @@
+package com.mes.ui;
+
+public class ProdReq {
+    private Integer id;
+    private String gw;
+    private String lineSn;
+    private String type;
+    private String sn;
+    private String fout;
+    private String sout;
+    private String fmin;
+    private String smin;
+    private String fmax;
+    private String smax;
+    private String qty;
+    private String serialNumber;
+    private Integer sync;
+    private String recordTime;
+    private String ucode;
+
+    public String getUcode() {
+        return ucode;
+    }
+
+    public void setUcode(String ucode) {
+        this.ucode = ucode;
+    }
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public String getGw() {
+        return gw;
+    }
+
+    public void setGw(String gw) {
+        this.gw = gw;
+    }
+
+    public String getLineSn() {
+        return lineSn;
+    }
+
+    public void setLineSn(String lineSn) {
+        this.lineSn = lineSn;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public String getSn() {
+        return sn;
+    }
+
+    public void setSn(String sn) {
+        this.sn = sn;
+    }
+
+    public String getFout() {
+        return fout;
+    }
+
+    public void setFout(String fout) {
+        this.fout = fout;
+    }
+
+    public String getSout() {
+        return sout;
+    }
+
+    public void setSout(String sout) {
+        this.sout = sout;
+    }
+
+    public String getFmin() {
+        return fmin;
+    }
+
+    public void setFmin(String fmin) {
+        this.fmin = fmin;
+    }
+
+    public String getSmin() {
+        return smin;
+    }
+
+    public void setSmin(String smin) {
+        this.smin = smin;
+    }
+
+    public String getFmax() {
+        return fmax;
+    }
+
+    public void setFmax(String fmax) {
+        this.fmax = fmax;
+    }
+
+    public String getSmax() {
+        return smax;
+    }
+
+    public void setSmax(String smax) {
+        this.smax = smax;
+    }
+
+    public String getQty() {
+        return qty;
+    }
+
+    public void setQty(String qty) {
+        this.qty = qty;
+    }
+
+    public String getSerialNumber() {
+        return serialNumber;
+    }
+
+    public void setSerialNumber(String serialNumber) {
+        this.serialNumber = serialNumber;
+    }
+
+    public Integer getSync() {
+        return sync;
+    }
+
+    public void setSync(Integer sync) {
+        this.sync = sync;
+    }
+
+    public String getRecordTime() {
+        return recordTime;
+    }
+
+    public void setRecordTime(String recordTime) {
+        this.recordTime = recordTime;
+    }
+}

+ 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;
+    }
+}

+ 60 - 0
src/com/mes/ui/test.java

@@ -0,0 +1,60 @@
+package com.mes.ui;
+
+import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType;
+import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
+
+public class test {
+
+    public static S7PLC plcA = new S7PLC( EPlcType.S1200,"192.168.0.200");
+
+    public static void main(String[] args) {
+        plcA.writeBoolean("DB40.0.0",true);
+        plcA.writeBoolean("DB50.0.0",true);
+//        plcA.writeUInt16("DB1.DBW584",3);
+//        plcA.writeBoolean("DB1.DBX2.6",false);
+//        System.out.println(plcA.readUInt16("DB1.440"));
+//        plcA.writeUInt16("DB1.DBW584",3);
+//        System.out.println(plcA.readInt32("DB1.184.0"));
+//        plcA.writeInt32("DB1.184.0",0);
+//        plcA.writeInt32("DB1.176.0",3);
+
+        System.out.println("查看实际数量");
+//        System.out.println(plcA.readInt32("DB1.184.0"));
+//        System.out.println("查看产品号");
+//        System.out.println(plcA.readUInt16("DB1.DBW54"));
+
+//        plcA.writeBoolean("DB1.DBX2.6",false);
+
+//        plcA.writeInt32("DB4.DBX0.0",1);
+
+//        plcA.writeInt32("DB1.714.0",0);
+
+
+        System.out.println(plcA.readInt32("DB1.184.0"));
+
+        System.out.println(plcA.readInt32("DB1.714.0"));
+
+//        plcA.writeUInt16("DB1.DBW54",2);
+
+//        System.out.println(plcA.readUInt16("DB1.DBW54"));
+
+//        plcA.writeInt32("DB1.714.0",0);
+
+//        System.out.println("A:"+plcA.readBoolean("DB4.DBX0.1"));
+
+//        plcA.writeBoolean("DB4.DBX0.1",false);
+//        System.out.println("B:"+plcA.readBoolean("DB4.DBX204.0"));
+//        plcA.writeBoolean("DB4.DBX204.0",false);
+
+//        plcA.writeInt32("DB4.DBX0.1",1);
+//        plcA.writeInt32("DB4.DBX204.0",1);
+
+        plcA.writeBoolean("DB4.DBX0.1",false);
+        plcA.writeBoolean("DB4.DBX204.0",false);
+
+    }
+
+    // 启停
+    // 选择产品
+    //
+}

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


Some files were not shown because too many files changed in this diff