hfy 2 minggu lalu
melakukan
d2da098f85
100 mengubah file dengan 4055 tambahan dan 0 penghapusan
  1. 28 0
      .classpath
  2. 7 0
      .gitignore
  3. 0 0
      .lock
  4. 28 0
      .project
  5. 2 0
      image/.gitignore
  6. TEMPAT SAMPAH
      image/background.png
  7. TEMPAT SAMPAH
      image/bg/a_side.png
  8. TEMPAT SAMPAH
      image/bg/b_side.png
  9. TEMPAT SAMPAH
      image/bg/bar_add.png
  10. TEMPAT SAMPAH
      image/bg/bar_bookmark.png
  11. TEMPAT SAMPAH
      image/bg/bar_cmd_go.png
  12. TEMPAT SAMPAH
      image/bg/bar_edit.png
  13. TEMPAT SAMPAH
      image/bg/bar_pause.png
  14. TEMPAT SAMPAH
      image/bg/bar_sampling.png
  15. TEMPAT SAMPAH
      image/bg/bar_setting.png
  16. TEMPAT SAMPAH
      image/bg/bar_stop.png
  17. TEMPAT SAMPAH
      image/bg/close_bt.png
  18. TEMPAT SAMPAH
      image/bg/company_setting_logo.png
  19. TEMPAT SAMPAH
      image/bg/delete.png
  20. TEMPAT SAMPAH
      image/bg/department_setting_logo.png
  21. TEMPAT SAMPAH
      image/bg/download.png
  22. TEMPAT SAMPAH
      image/bg/equipment_setting_logo.png
  23. TEMPAT SAMPAH
      image/bg/gj_001_1_20.png
  24. TEMPAT SAMPAH
      image/bg/gj_001_21_40.png
  25. TEMPAT SAMPAH
      image/bg/gj_001_41_60.png
  26. TEMPAT SAMPAH
      image/bg/green_dot.png
  27. TEMPAT SAMPAH
      image/bg/grey_dot.png
  28. TEMPAT SAMPAH
      image/bg/icon.png
  29. TEMPAT SAMPAH
      image/bg/inductance_logo.png
  30. TEMPAT SAMPAH
      image/bg/insulation_logo.png
  31. TEMPAT SAMPAH
      image/bg/login.png
  32. TEMPAT SAMPAH
      image/bg/logo.png
  33. TEMPAT SAMPAH
      image/bg/logoff.png
  34. TEMPAT SAMPAH
      image/bg/menu_data_analysis.png
  35. TEMPAT SAMPAH
      image/bg/menu_data_preprocess.png
  36. TEMPAT SAMPAH
      image/bg/menu_file.png
  37. TEMPAT SAMPAH
      image/bg/menu_setting.png
  38. TEMPAT SAMPAH
      image/bg/min_bt.png
  39. TEMPAT SAMPAH
      image/bg/ng_bg.png
  40. TEMPAT SAMPAH
      image/bg/ok_bg.png
  41. TEMPAT SAMPAH
      image/bg/open_file.png
  42. TEMPAT SAMPAH
      image/bg/refresh.png
  43. TEMPAT SAMPAH
      image/bg/reset_logo.png
  44. TEMPAT SAMPAH
      image/bg/resistance_logo.png
  45. TEMPAT SAMPAH
      image/bg/save_bg.png
  46. TEMPAT SAMPAH
      image/bg/scan_barcode.png
  47. TEMPAT SAMPAH
      image/bg/tree_folder_icon.png
  48. TEMPAT SAMPAH
      image/bg/tree_leaf_icon.png
  49. TEMPAT SAMPAH
      image/bg/user.png
  50. TEMPAT SAMPAH
      image/bg/vertical_line.png
  51. TEMPAT SAMPAH
      image/bg/zoom_in.png
  52. TEMPAT SAMPAH
      image/bg/zoom_out.png
  53. TEMPAT SAMPAH
      image/close_bt.png
  54. 0 0
      image/cmd.txt
  55. TEMPAT SAMPAH
      image/icon.ico
  56. TEMPAT SAMPAH
      image/info_bt.png
  57. TEMPAT SAMPAH
      image/min_bt.png
  58. TEMPAT SAMPAH
      lib/commons-codec-1.15.jar
  59. TEMPAT SAMPAH
      lib/core-3.5.1.jar
  60. TEMPAT SAMPAH
      lib/fastjson2-2.0.16.jar
  61. TEMPAT SAMPAH
      lib/gson-2.10.jar
  62. TEMPAT SAMPAH
      lib/iot-communication-1.4.4.jar
  63. TEMPAT SAMPAH
      lib/jSerialComm-2.6.2.jar
  64. TEMPAT SAMPAH
      lib/javase-3.5.1.jar
  65. TEMPAT SAMPAH
      lib/jfreechart-1.5.4.jar
  66. TEMPAT SAMPAH
      lib/jshortcut-0.4-oberzalek.jar
  67. TEMPAT SAMPAH
      lib/kotlin-stdlib-1.8.10.jar
  68. TEMPAT SAMPAH
      lib/logback-classic-1.2.13.jar
  69. TEMPAT SAMPAH
      lib/logback-core-1.2.13.jar
  70. TEMPAT SAMPAH
      lib/netty-all-4.1.48.Final.jar
  71. TEMPAT SAMPAH
      lib/okhttp-4.10.0.jar
  72. TEMPAT SAMPAH
      lib/okio-jvm-3.3.0.jar
  73. TEMPAT SAMPAH
      lib/s7connector-2.1.jar
  74. TEMPAT SAMPAH
      lib/slf4j-api-1.7.36.jar
  75. TEMPAT SAMPAH
      lib/sqlite-jdbc-3.36.0.3.jar
  76. 10 0
      src/com/mes/component/CallFromJs.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. 91 0
      src/com/mes/component/QRCodeDialog.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. 58 0
      src/com/mes/ui/CmtReq.java
  88. 391 0
      src/com/mes/ui/DataUtil.java
  89. 53 0
      src/com/mes/ui/ErrorMsg.java
  90. 85 0
      src/com/mes/ui/LockUtil.java
  91. 218 0
      src/com/mes/ui/LoginFarme.java
  92. 1472 0
      src/com/mes/ui/MesClient.java
  93. 139 0
      src/com/mes/ui/MesRevice.java
  94. 227 0
      src/com/mes/ui/ModbusRtu.java
  95. 67 0
      src/com/mes/ui/OprnoUtil.java
  96. 309 0
      src/com/mes/ui/PlcUtil.java
  97. 148 0
      src/com/mes/ui/ProdReq.java
  98. 43 0
      src/com/mes/ui/TableCellEditorButton.java
  99. 14 0
      src/com/mes/ui/TableCellRendererButton.java
  100. 0 0
      src/com/mes/ui/Test.java

+ 28 - 0
.classpath

@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="image"/>
+	<classpathentry excluding="resources/" kind="src" path="src"/>
+	<classpathentry kind="src" path="src/resources"/>
+	<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="lib" path="lib/logback-core-1.2.13.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/logback-classic-1.2.13.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/jSerialComm-2.6.2.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"/>
+	<classpathentry kind="lib" path="lib/okio-jvm-3.3.0.jar"/>
+	<classpathentry kind="lib" path="lib/s7connector-2.1.jar"/>
+	<classpathentry kind="lib" path="lib/slf4j-api-1.7.36.jar"/>
+	<classpathentry kind="lib" path="lib/sqlite-jdbc-3.36.0.3.jar"/>
+	<classpathentry kind="output" path="bin"/>
+</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-op130A</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>1757488872243</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

TEMPAT SAMPAH
image/background.png


TEMPAT SAMPAH
image/bg/a_side.png


TEMPAT SAMPAH
image/bg/b_side.png


TEMPAT SAMPAH
image/bg/bar_add.png


TEMPAT SAMPAH
image/bg/bar_bookmark.png


TEMPAT SAMPAH
image/bg/bar_cmd_go.png


TEMPAT SAMPAH
image/bg/bar_edit.png


TEMPAT SAMPAH
image/bg/bar_pause.png


TEMPAT SAMPAH
image/bg/bar_sampling.png


TEMPAT SAMPAH
image/bg/bar_setting.png


TEMPAT SAMPAH
image/bg/bar_stop.png


TEMPAT SAMPAH
image/bg/close_bt.png


TEMPAT SAMPAH
image/bg/company_setting_logo.png


TEMPAT SAMPAH
image/bg/delete.png


TEMPAT SAMPAH
image/bg/department_setting_logo.png


TEMPAT SAMPAH
image/bg/download.png


TEMPAT SAMPAH
image/bg/equipment_setting_logo.png


TEMPAT SAMPAH
image/bg/gj_001_1_20.png


TEMPAT SAMPAH
image/bg/gj_001_21_40.png


TEMPAT SAMPAH
image/bg/gj_001_41_60.png


TEMPAT SAMPAH
image/bg/green_dot.png


TEMPAT SAMPAH
image/bg/grey_dot.png


TEMPAT SAMPAH
image/bg/icon.png


TEMPAT SAMPAH
image/bg/inductance_logo.png


TEMPAT SAMPAH
image/bg/insulation_logo.png


TEMPAT SAMPAH
image/bg/login.png


TEMPAT SAMPAH
image/bg/logo.png


TEMPAT SAMPAH
image/bg/logoff.png


TEMPAT SAMPAH
image/bg/menu_data_analysis.png


TEMPAT SAMPAH
image/bg/menu_data_preprocess.png


TEMPAT SAMPAH
image/bg/menu_file.png


TEMPAT SAMPAH
image/bg/menu_setting.png


TEMPAT SAMPAH
image/bg/min_bt.png


TEMPAT SAMPAH
image/bg/ng_bg.png


TEMPAT SAMPAH
image/bg/ok_bg.png


TEMPAT SAMPAH
image/bg/open_file.png


TEMPAT SAMPAH
image/bg/refresh.png


TEMPAT SAMPAH
image/bg/reset_logo.png


TEMPAT SAMPAH
image/bg/resistance_logo.png


TEMPAT SAMPAH
image/bg/save_bg.png


TEMPAT SAMPAH
image/bg/scan_barcode.png


TEMPAT SAMPAH
image/bg/tree_folder_icon.png


TEMPAT SAMPAH
image/bg/tree_leaf_icon.png


TEMPAT SAMPAH
image/bg/user.png


TEMPAT SAMPAH
image/bg/vertical_line.png


TEMPAT SAMPAH
image/bg/zoom_in.png


TEMPAT SAMPAH
image/bg/zoom_out.png


TEMPAT SAMPAH
image/close_bt.png


+ 0 - 0
image/cmd.txt


TEMPAT SAMPAH
image/icon.ico


TEMPAT SAMPAH
image/info_bt.png


TEMPAT SAMPAH
image/min_bt.png


TEMPAT SAMPAH
lib/commons-codec-1.15.jar


TEMPAT SAMPAH
lib/core-3.5.1.jar


TEMPAT SAMPAH
lib/fastjson2-2.0.16.jar


TEMPAT SAMPAH
lib/gson-2.10.jar


TEMPAT SAMPAH
lib/iot-communication-1.4.4.jar


TEMPAT SAMPAH
lib/jSerialComm-2.6.2.jar


TEMPAT SAMPAH
lib/javase-3.5.1.jar


TEMPAT SAMPAH
lib/jfreechart-1.5.4.jar


TEMPAT SAMPAH
lib/jshortcut-0.4-oberzalek.jar


TEMPAT SAMPAH
lib/kotlin-stdlib-1.8.10.jar


TEMPAT SAMPAH
lib/logback-classic-1.2.13.jar


TEMPAT SAMPAH
lib/logback-core-1.2.13.jar


TEMPAT SAMPAH
lib/netty-all-4.1.48.Final.jar


TEMPAT SAMPAH
lib/okhttp-4.10.0.jar


TEMPAT SAMPAH
lib/okio-jvm-3.3.0.jar


TEMPAT SAMPAH
lib/s7connector-2.1.jar


TEMPAT SAMPAH
lib/slf4j-api-1.7.36.jar


TEMPAT SAMPAH
lib/sqlite-jdbc-3.36.0.3.jar


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

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

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

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

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

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

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

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

+ 91 - 0
src/com/mes/component/QRCodeDialog.java

@@ -0,0 +1,91 @@
+package com.mes.component;
+
+import com.google.zxing.BarcodeFormat;
+import com.google.zxing.EncodeHintType;
+import com.google.zxing.WriterException;
+import com.google.zxing.common.BitMatrix;
+import com.google.zxing.qrcode.QRCodeWriter;
+import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.image.BufferedImage;
+import java.util.HashMap;
+import java.util.Map;
+
+public class QRCodeDialog extends JDialog {
+    
+    private static final int QR_CODE_SIZE = 400; // 二维码尺寸
+
+    public QRCodeDialog(JFrame owner, String title, String content){
+        super(owner, title, true);
+        init(content, owner);
+    }
+
+    private void init(String content, JFrame owner){
+        Container container = this.getContentPane();
+        container.setLayout(new BorderLayout());
+        container.setBackground(Color.WHITE);
+        
+        // 生成二维码图片
+        BufferedImage qrImage = generateQRCode(content);
+        
+        if(qrImage != null){
+            // 显示二维码
+            JLabel imageLabel = new JLabel(new ImageIcon(qrImage));
+            imageLabel.setHorizontalAlignment(SwingConstants.CENTER);
+            container.add(imageLabel, BorderLayout.CENTER);
+            
+            // 显示文本内容
+            JLabel textLabel = new JLabel(content);
+            textLabel.setHorizontalAlignment(SwingConstants.CENTER);
+            textLabel.setFont(new Font("微软雅黑", Font.PLAIN, 18));
+            textLabel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
+            container.add(textLabel, BorderLayout.SOUTH);
+        }else{
+            // 如果生成失败,显示错误信息
+            JLabel errorLabel = new JLabel("二维码生成失败");
+            errorLabel.setHorizontalAlignment(SwingConstants.CENTER);
+            errorLabel.setForeground(Color.RED);
+            errorLabel.setFont(new Font("微软雅黑", Font.PLAIN, 24));
+            container.add(errorLabel, BorderLayout.CENTER);
+        }
+        
+        this.setSize(QR_CODE_SIZE + 50, QR_CODE_SIZE + 100);
+        this.setLocationRelativeTo(owner);
+        this.setResizable(false);
+        this.setVisible(true);
+    }
+
+    /**
+     * 生成二维码图片
+     * @param content 二维码内容
+     * @return BufferedImage
+     */
+    private BufferedImage generateQRCode(String content) {
+        try {
+            // 设置二维码参数
+            Map<EncodeHintType, Object> hints = new HashMap<>();
+            hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); // 容错级别
+            hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); // 字符编码
+            hints.put(EncodeHintType.MARGIN, 1); // 边距
+
+            // 生成二维码矩阵
+            QRCodeWriter qrCodeWriter = new QRCodeWriter();
+            BitMatrix bitMatrix = qrCodeWriter.encode(content, BarcodeFormat.QR_CODE, QR_CODE_SIZE, QR_CODE_SIZE, hints);
+
+            // 转换为图片
+            BufferedImage image = new BufferedImage(QR_CODE_SIZE, QR_CODE_SIZE, BufferedImage.TYPE_INT_RGB);
+            for (int x = 0; x < QR_CODE_SIZE; x++) {
+                for (int y = 0; y < QR_CODE_SIZE; y++) {
+                    image.setRGB(x, y, bitMatrix.get(x, y) ? 0xFF000000 : 0xFFFFFFFF);
+                }
+            }
+            return image;
+        } catch (WriterException e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
+}
+

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

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

@@ -0,0 +1,58 @@
+package com.mes.ui;
+
+public class CmtReq {
+    private Integer id;
+    private String oprno;
+    private String lineSn;
+    private String sn;
+    private String content;
+    private Integer sync;
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public String getOprno() {
+        return oprno;
+    }
+
+    public void setOprno(String oprno) {
+        this.oprno = oprno;
+    }
+
+    public String getLineSn() {
+        return lineSn;
+    }
+
+    public void setLineSn(String lineSn) {
+        this.lineSn = lineSn;
+    }
+
+    public String getSn() {
+        return sn;
+    }
+
+    public void setSn(String sn) {
+        this.sn = sn;
+    }
+
+    public String getContent() {
+        return content;
+    }
+
+    public void setContent(String content) {
+        this.content = content;
+    }
+
+    public Integer getSync() {
+        return sync;
+    }
+
+    public void setSync(Integer sync) {
+        this.sync = sync;
+    }
+}

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

@@ -0,0 +1,391 @@
+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,String op){
+        try{
+            String msgType = "AQDW";
+            String gy = "100000";
+            Boolean aqdw_str = sendMessage(nettyClient,msgType,gy,"",sn,"",user,"00","",op);
+            return aqdw_str;
+        }catch (Exception e){
+            return false;
+        }
+    }
+
+    public static Boolean startWork(NettyClient nettyClient,String sn,String user,String op){
+        try{
+            String msgType = "MKSW";
+            String gy = "";
+            Boolean aqdw_str = sendMessage(nettyClient,msgType,gy,"",sn,"",user,"00","",op);
+            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,String op){
+        try{
+            String msgType = "MQDW";
+            String gy = "100000";
+            String paramNums = "01";
+            String params = "";
+            if(op.equals("A")){
+                params = rightPad("Y"+MesClient.programNoA, 12);
+            }else{
+                params = rightPad("Y"+MesClient.programNoB, 12);
+            }
+            Boolean aqdw_str = sendMessage(nettyClient,msgType,gy,"",sn,ret,user,paramNums,params,op);
+            return aqdw_str;
+        }catch (Exception e){
+            return false;
+        }
+    }
+
+    public static Boolean sendQuality2(String sn,String result,String user,String op){
+        try{
+            String msgType = "MQDW";
+            String craft = "100000";
+            String lx = "";
+            String paramNums = "01";
+            String params = "";
+            if(op.equals("A")){
+                params = rightPad("Y"+MesClient.programNoA, 12);
+            }else{
+                params = rightPad("Y"+MesClient.programNoB, 12);
+            }
+
+            if(MesClient.mes_gwflag.equals("B")){
+                if(op.equals("A")){
+                    op = "C";
+                }else{
+                    op = "D";
+                }
+            }
+
+            InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
+            Properties pro = new Properties();
+            BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
+            pro.load(br);
+            String gw = "GW"+rightPad(pro.getProperty("mes.gw")+op, 6);
+            String start = "aaaabbbbbABW";
+            String gy = "GY" + rightPad(craft, 6);
+            String reslx = "LX" + rightPad(lx, 2);
+            String id = pro.getProperty("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;
+//            JdbcUtils.insertData(gw, gy, aqdw_str, msgType, sn);
+            JdbcUtils.insertSubmitRecord(gw, sn, aqdw_str);
+            return true;
+        }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,String op){
+        try{
+            String enconding = "UTF-8";
+            InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
+            Properties pro = new Properties();
+            BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
+            pro.load(br);
+
+            if(MesClient.mes_gwflag.equals("B")){
+                if(op.equals("A")){
+                    op = "C";
+                }else{
+                    op = "D";
+                }
+            }else if(MesClient.mes_gwflag.equals("C")){
+                if(op.equals("A")){
+                    op = "E";
+                }else{
+                    op = "F";
+                }
+            }
+
+            String gw = "GW"+rightPad(pro.getProperty("mes.gw")+op, 6);
+            String start = "aaaabbbbbABW";
+            String gy = "GY" + rightPad(craft, 6);
+            String reslx = "LX" + rightPad(lx, 2);
+            String id = pro.getProperty("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 upParams(String upparams) {
+        try{
+            String enconding = "UTF-8";
+            InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
+            Properties pro = new Properties();
+            BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
+            pro.load(br);
+            String mes_server_ip = pro.getProperty("mes.server_ip");
+            String oprno = pro.getProperty("mes.gw").trim();
+            String url = "http://"+mes_server_ip+":8980/js/a/mes/mesProductCmt/batchsave";
+            String params = "__ajax=json&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 JSONObject getBindMaterail() {
+        try{
+            String enconding = "UTF-8";
+            InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
+            Properties pro = new Properties();
+            BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
+            pro.load(br);
+            String mes_server_ip = pro.getProperty("mes.server_ip");
+            String oprno = pro.getProperty("mes.gw").trim();
+            String lineSn = pro.getProperty("mes.line_sn").trim();
+            String url = "http://"+mes_server_ip+":8980/js/a/mes/mesLineProcessMaterial/materials";
+            String params = "__ajax=json&oprno="+oprno+"&lineSn="+lineSn;
+            System.out.println("params="+params);
+            String result = doPost(url,params);
+            System.out.println("result="+result);
+
+            if(result.equalsIgnoreCase("false")) {
+                return null;
+            }else {
+                return JSONObject.parseObject(result);
+            }
+        }catch (Exception e){
+            return null;
+        }
+    }
+
+    public static JSONObject saveBindMaterail(String batchSn,String craft,String materialId,String type) {
+        try{
+            String enconding = "UTF-8";
+            InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
+            Properties pro = new Properties();
+            BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
+            pro.load(br);
+            String mes_server_ip = pro.getProperty("mes.server_ip");
+            String oprno = pro.getProperty("mes.gw").trim();
+            String lineSn = pro.getProperty("mes.line_sn").trim();
+            String url = "http://"+mes_server_ip+":8980/js/a/mes/mesMaterialPrebind/bind";
+            String params = "__ajax=json&oprno="+oprno+"&lineSn="+lineSn+"&batchSn="+batchSn+"&craft="+craft+"&materialId="+materialId+"&type="+type;
+            System.out.println("params="+params);
+            String result = doPost(url,params);
+            System.out.println("result="+result);
+
+            if(result.equalsIgnoreCase("false")) {
+                return null;
+            }else {
+                return JSONObject.parseObject(result);
+            }
+        }catch (Exception e){
+            return null;
+        }
+    }
+
+    public static JSONObject saveGzCheck(String content,String userCode) {
+        try{
+            String enconding = "UTF-8";
+            InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
+            Properties pro = new Properties();
+            BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
+            pro.load(br);
+            String mes_server_ip = pro.getProperty("mes.server_ip");
+            String oprno = pro.getProperty("mes.gw").trim();
+            String lineSn = pro.getProperty("mes.line_sn").trim();
+            String url = "http://"+mes_server_ip+":8980/js/a/mes/mesProcessCheckGz/submit";
+            String params = "__ajax=json&oprno="+oprno+"&lineSn="+lineSn+"&createBy="+userCode;
+            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;
+    }
+}

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

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

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

File diff ditekan karena terlalu besar
+ 1472 - 0
src/com/mes/ui/MesClient.java


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

@@ -0,0 +1,139 @@
+package com.mes.ui;
+
+import com.mes.netty.ProtocolParam;
+import com.mes.component.MyDialog;
+import com.mes.util.CommonUtils;
+import com.mes.util.ErrorMsg;
+
+import javax.swing.*;
+import java.awt.*;
+
+public class MesRevice {
+
+    // 质量查询
+    public static void checkQualityRevice(String processMsgRet,String mes_msg){
+        try{
+            if(processMsgRet.equalsIgnoreCase("UD")) {
+//                MesClient.status_menu.setForeground(Color.GREEN);
+//                MesClient.status_menu.setText("该工件可以加工");
+
+                String oprno = ProtocolParam.getOprno(mes_msg).trim();
+                String sn = ProtocolParam.getSn(mes_msg).trim();
+
+                MesClient.lastpage = 0;
+                if(oprno.equals(MesClient.mes_gw+"A") || oprno.equals(MesClient.mes_gw+"C") || oprno.equals(MesClient.mes_gw+"E")){
+                    MesClient.finish_ok_bt.setEnabled(false);
+                    MesClient.mesQualityFlagA = true;
+                    MesClient.pxstatus1.setText("A:可以加工,等待设备启动");
+                    MesClient.curSna = MesClient.product_sn.getText();
+                    MesClient.tjFlaga = 1;
+
+
+                    // 程序号防错功能已注释
+                    // MesClient.programNoA = PlcUtil.getProgranNoA(MesClient.s7PLC)+"";
+                    // System.err.println(MesClient.programNoA);
+                    // System.err.println(CommonUtils.checkProgramNoSn(sn,MesClient.programNoA));
+                    // if(!CommonUtils.checkProgramNoSn(sn,MesClient.programNoA)){
+                    //     MesClient.pxstatus1.setText("A:当前工件与设备程序不匹配");
+                    //     MesClient.setMenuStatus("A:当前工件与设备程序不匹配",-1);
+                    // }
+
+
+
+                }else{
+                    MesClient.finish_ng_bt.setEnabled(false);
+                    MesClient.mesQualityFlagB = true;
+                    MesClient.pxstatus2.setText("B:可以加工,等待设备启动");
+                    MesClient.curSnb = MesClient.product_sn2.getText();
+                    MesClient.tjFlagb = 1;
+
+                    // 程序号防错功能已注释
+                    // MesClient.programNoB = PlcUtil.getProgranNoB(MesClient.s7PLC)+"";
+//                    PlcUtil.changeEnable(MesClient.s7PLC,true);
+                    // if(!CommonUtils.checkProgramNoSn(sn,MesClient.programNoB)){
+                    //     MesClient.pxstatus2.setText("B:当前工件与设备程序不匹配");
+                    //     MesClient.setMenuStatus("B:当前工件与设备程序不匹配",-1);
+                    // }
+                }
+
+            }else {
+                if(MesClient.scan_type == 1){
+                    MesClient.check_quality_result = false;
+                }else{
+                    MesClient.check_quality_result2 = false;
+                }
+
+                String lmsg = ErrorMsg.getErrorMsg(processMsgRet, ProtocolParam.getLx(mes_msg));
+
+                MesClient.setMenuStatus(lmsg,-1);
+                PlcUtil.changeEnable(MesClient.s7PLC,false);
+
+            }
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+    }
+
+    // 开始回复处理
+    public static void startRevice(String processMsgRet,String mes_msg){
+        try{
+            if(processMsgRet.equalsIgnoreCase("OK")) {
+
+            }
+        }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{
+            String sn = ProtocolParam.getSn(mes_msg).trim();
+            if(processMsgRet.equalsIgnoreCase("OK")) {
+                if(sn.equals(MesClient.product_sn2.getText())){
+                    MesClient.pxstatus2.setText("B:提交成功");
+                    MesClient.resetScanB();
+                }else{
+                    MesClient.pxstatus1.setText("A:提交成功");
+                    MesClient.resetScanA();
+                }
+            }else{
+                if(sn.equals(MesClient.product_sn2.getText())){
+                    MesClient.pxstatus2.setText("B:提交失败");
+//                    MesClient.resetScanB();
+                }else{
+                    MesClient.pxstatus1.setText("A:提交失败");
+//                    MesClient.resetScanA();
+                }
+            }
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+    }
+}

+ 227 - 0
src/com/mes/ui/ModbusRtu.java

@@ -0,0 +1,227 @@
+package com.mes.ui;
+
+import com.fazecast.jSerialComm.*;
+
+import java.math.BigInteger;
+
+public class ModbusRtu {
+    public static SerialPort connect(){
+        try{
+            SerialPort serialPort = SerialPort.getCommPort("COM5"); // 替换为你的端口名
+            serialPort.setComPortParameters(38400, 8, SerialPort.ONE_STOP_BIT, SerialPort.NO_PARITY); // 设置端口参数
+            serialPort.setComPortTimeouts(SerialPort.TIMEOUT_READ_BLOCKING, 1000, 0);
+
+            if (serialPort.openPort()) {
+                System.out.println("Port opened successfully.");
+                return serialPort;
+            } else {
+               return null;
+            }
+        }catch (Exception e){
+            e.printStackTrace();
+            return null;
+        }
+    }
+
+    public static void disconnect(SerialPort serialPort) {
+        if (serialPort != null && serialPort.isOpen()) {
+            serialPort.closePort();
+        }
+    }
+
+    public static SerialPort reconnect(SerialPort serialPort) {
+        disconnect(serialPort);
+        return connect();
+    }
+
+    public static void openDevice(SerialPort serialPort) {
+        System.out.println("isOpen:");
+        if(serialPort ==null || !serialPort.isOpen()){
+            serialPort = reconnect(serialPort);
+        }
+
+        try {
+            String writeString = "010600000000"; // 关
+            String crc = getCRC16_Modbus_Str(writeString);
+            byte[] writeBuffer = hexStringToByteArray(writeString+crc);
+            serialPort.writeBytes(writeBuffer, writeBuffer.length);
+
+            // 接收数据
+            byte[] readBuffer = new byte[512]; // 调整数组大小以适应预期的响应长度
+            int numRead = serialPort.readBytes(readBuffer, readBuffer.length);
+            System.out.println("Read " + numRead + " bytes.");
+
+            // 将读取的字节转换为十六进制字符串
+            StringBuilder data = new StringBuilder();
+            for (int i = 0; i < numRead; i++) {
+                data.append(String.format("%02X", readBuffer[i]));
+            }
+            String revStr = data.toString();
+//            String ret = revStr.substring(6,8);
+            System.out.println("Received data: " + revStr);
+//            System.out.println("ret data: " + ret);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            serialPort.closePort();
+        } finally {
+
+        }
+    }
+
+    public static void closeDevice(SerialPort serialPort) {
+        if(serialPort ==null || !serialPort.isOpen()){
+            serialPort = reconnect(serialPort);
+        }
+        try {
+            String writeString = "010600000001"; // 开
+            String crc = getCRC16_Modbus_Str(writeString);
+            byte[] writeBuffer = hexStringToByteArray(writeString+crc);
+            serialPort.writeBytes(writeBuffer, writeBuffer.length);
+
+            // 接收数据
+            byte[] readBuffer = new byte[512]; // 调整数组大小以适应预期的响应长度
+            int numRead = serialPort.readBytes(readBuffer, readBuffer.length);
+            System.out.println("Read " + numRead + " bytes.");
+
+            // 将读取的字节转换为十六进制字符串
+            StringBuilder data = new StringBuilder();
+            for (int i = 0; i < numRead; i++) {
+                data.append(String.format("%02X", readBuffer[i]));
+            }
+            String revStr = data.toString();
+//            String ret = revStr.substring(6,8);
+            System.out.println("Received data: " + revStr);
+//            System.out.println("ret data: " + ret);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            serialPort.closePort();
+        } finally {
+
+        }
+    }
+
+    public static Boolean readCoil(SerialPort serialPort,int pos) {
+        if(serialPort ==null || !serialPort.isOpen()){
+            serialPort = reconnect(serialPort);
+        }
+        try {
+            String writeString = "010100000"+pos+"01"; // 线圈地址 0/1,目前只有2路
+            String crc = getCRC16_Modbus_Str(writeString);
+            byte[] writeBuffer = hexStringToByteArray(writeString+crc);
+            serialPort.writeBytes(writeBuffer, writeBuffer.length);
+
+            // 接收数据
+            byte[] readBuffer = new byte[512]; // 调整数组大小以适应预期的响应长度
+            int numRead = serialPort.readBytes(readBuffer, readBuffer.length);
+            System.out.println("Read " + numRead + " bytes.");
+
+            // 将读取的字节转换为十六进制字符串
+            StringBuilder data = new StringBuilder();
+            for (int i = 0; i < numRead; i++) {
+                data.append(String.format("%02X", readBuffer[i]));
+            }
+            String revStr = data.toString();
+            String ret = revStr.substring(6,8);
+            System.out.println("Received data: " + revStr);
+            System.out.println("ret data: " + ret);
+
+            if(ret.equals("01")){
+                MesClient.setMenuStatus("当前结果为:true",0);
+                return true;
+            }else{
+                MesClient.setMenuStatus("当前结果为:false",0);
+                return false;
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            MesClient.setMenuStatus("串口断线",0);
+            serialPort.closePort();
+            return false;
+        }
+    }
+
+
+    /**
+     * CRC16(modbus)校验
+     * 获取crc16校验码,参数data中不能有空格
+     * @param data
+     * @return
+     */
+    public static String getCRC16_Modbus_Str(String data) {
+        data = data.replace(" ", "");
+        int len = data.length();
+        if (!(len % 2 == 0)) {
+            return "0000";
+        }
+        int num = len / 2;
+        byte[] para = new byte[num];
+        for (int i = 0; i < num; i++) {
+            int value = Integer.valueOf(data.substring(i * 2, 2 * (i + 1)), 16);
+            para[i] = (byte) value;
+        }
+        return getCRC(para);
+    }
+
+    /**
+     * 计算CRC16校验码
+     * @param bytes
+     *            字节数组
+     * @return {@link String} 校验码
+     * @since 1.0
+     */
+    public static String getCRC(byte[] bytes) {
+        // CRC寄存器全为1
+        int CRC = 0x0000ffff;
+        // 多项式校验值
+        int POLYNOMIAL = 0x0000a001;
+        int i, j;
+        for (i = 0; i < bytes.length; i++) {
+            CRC ^= ((int) bytes[i] & 0x000000ff);
+            for (j = 0; j < 8; j++) {
+                if ((CRC & 0x00000001) != 0) {
+                    CRC >>= 1;
+                    CRC ^= POLYNOMIAL;
+                } else {
+                    CRC >>= 1;
+                }
+            }
+        }
+        // 结果转换为16进制
+        String result = Integer.toHexString(CRC).toUpperCase();
+        if (result.length() != 4) {
+            StringBuffer sb = new StringBuffer("0000");
+            result = sb.replace(4 - result.length(), 4, result).toString();
+        }
+        //高位在前地位在后
+        //return result.substring(2, 4) + " " + result.substring(0, 2);
+        // 交换高低位,低位在前高位在后
+        return result.substring(2, 4) +  result.substring(0, 2);
+    }
+
+    public static byte[] hexStringToByteArray(String hexString) {
+        // 去除字符串前后的空格
+        hexString = hexString.trim();
+
+        // 确保字符串的长度是偶数
+        if (hexString.length() % 2 != 0) {
+            throw new IllegalArgumentException("Invalid hex string");
+        }
+
+        // 将字符串转换为BigInteger对象
+        BigInteger bigInt = new BigInteger(hexString, 16);
+
+        // 获取BigInteger表示的字节数组
+        byte[] byteArray = bigInt.toByteArray();
+
+        // 处理符号位,如果数组的长度大于字符串的长度,则将符号位字节去除
+        if (byteArray.length > hexString.length() / 2) {
+            byte[] trimmedArray = new byte[hexString.length() / 2];
+            System.arraycopy(byteArray, 1, trimmedArray, 0, trimmedArray.length);
+            return trimmedArray;
+        }
+
+        return byteArray;
+    }
+}

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

@@ -0,0 +1,67 @@
+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[]{
+            "OP040","OP050","OP060","OP070","OP080","OP090","OP100",
+            "OP110","OP120","OP130","OP140","OP150","OP170","OP190",
+            "OP200","OP210","OP220","OP230","OP240","OP250","OP260",
+            "OP270","OP280","OP290","OP300","OP310","OP320","OP340",
+            "OP350","OP360","OP370","OP370","OP380","OP390","OP400","OP410","OP420"
+    };
+    public static String[] xtoprnodes = new String[]{
+            "镭雕二维码","前边梁压铆,单部件拉铆","框架CMT焊接","人工补焊",
+            "焊道检查","焊道打磨","","框架气密","框架反面CNC加工+去毛刺","框架反面,吹铝屑+清洁",
+            "框架涂胶","液冷板安装+水冷板点焊","液冷板FSW","匙孔补焊+匙孔补焊打磨",
+            "总成正面CNC+去毛刺","总成正面,吹铝屑+清洁","总成正面装配","套筒涂胶","封堵片焊接",
+            "左右边梁封堵","半成品气密","VHB胶带粘贴+冷板泡棉粘贴","冷板背面涂胶",
+            "底护板清洗","安装底护板","成品气密","液冷板气密","总成检具检验","箱体封堵",
+            "总成清洁","粘贴云母片","CCD","终检","GP12正面","后梁底涂镭雕","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;
+    }
+}

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

@@ -0,0 +1,309 @@
+package com.mes.ui;
+
+import com.alibaba.fastjson2.JSON;
+import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
+import com.mes.util.CommonUtils;
+import com.mes.util.DateLocalUtils;
+import com.mes.util.JdbcUtils;
+
+import java.util.ArrayList;
+
+public class PlcUtil {
+
+    public static void getParamDyDl(S7PLC s7PLC){
+        Boolean starta = getAStart(s7PLC); //A启动中
+        Boolean startb = getBStart(s7PLC); //B启动中
+
+        if(MesClient.tjFlaga == 2 || MesClient.tjFlagb == 2){ //运行中
+            Float dya = s7PLC.readFloat32("DB1010.2");
+            Float dla = s7PLC.readFloat32("DB1010.8");
+            Float ssa = s7PLC.readFloat32("DB1010.14");
+            Short cwa = s7PLC.readInt16("DB1010.18");
+            Short joba = s7PLC.readInt16("DB1010.20");
+
+            MesClient.param1.setText(dya+"");
+            MesClient.param2.setText(dla+"");
+            MesClient.param3.setText(ssa+"");
+            MesClient.param4.setText(cwa+"");
+            MesClient.param5.setText(joba+"");
+
+            Float dyb = s7PLC.readFloat32("DB1010.26");
+            Float dlb = s7PLC.readFloat32("DB1010.34");
+            Float ssb = s7PLC.readFloat32("DB1010.42");
+            Short cwb = s7PLC.readInt16("DB1010.46");
+            Short jobb = s7PLC.readInt16("DB1010.48");
+
+            MesClient.param21.setText(dyb+"");
+            MesClient.param22.setText(dlb+"");
+            MesClient.param23.setText(ssb+"");
+            MesClient.param24.setText(cwb+"");
+            MesClient.param25.setText(jobb+"");
+
+            String record_time = DateLocalUtils.getCurrentTime();
+            MesClient.hjparams.add(dya+"|"+dla+"|"+ssa+"|"+cwa+"|"+joba+"|"+dyb+"|"+dlb+"|"+ssb+"|"+cwb+"|"+jobb+"|"+record_time);
+            System.out.println("cmt:"+dya+"|"+dla+"|"+ssa+"|"+cwa+"|"+joba+"|"+dyb+"|"+dlb+"|"+ssb+"|"+cwb+"|"+jobb+"|"+record_time);
+
+            if(MesClient.hjparams.size() == 60){
+                try{
+                    // 根据curFlag确定工位号和工件码
+                    String oprno = MesClient.mes_gw+"A";
+                    String sn = MesClient.curSna;
+                    if(MesClient.curFlag.equals("B")){
+                        oprno = MesClient.mes_gw+"B";
+                        sn = MesClient.curSnb;
+                    }
+                    if(MesClient.mes_gwflag.equals("B")){
+                        if(MesClient.curFlag.equals("A")){
+                            oprno = MesClient.mes_gw+"C";
+                        }else{
+                            oprno = MesClient.mes_gw+"D";
+                        }
+                    }
+                    // 检查工件码是否为空,为空则不上传
+                    if(sn != null && !sn.trim().isEmpty()){
+                        JdbcUtils.insertCmtData(oprno,MesClient.mes_line_sn,sn, JSON.toJSONString(MesClient.hjparams));
+                        System.out.println("cmt:"+MesClient.curFlag+" sn:"+sn);
+                    }else{
+                        System.out.println("工件码为空,跳过保存数据");
+                    }
+                    MesClient.hjparams = new ArrayList<>();
+                }catch (Exception e){
+                    e.printStackTrace();
+                }
+            }
+        }else{
+            if(MesClient.hjparams.size() != 60 && MesClient.hjparams.size() > 0){
+                try{
+                    // 根据curFlag确定工位号和工件码
+                    String oprno = MesClient.mes_gw+"A";
+                    String sn = MesClient.curSna;
+                    if(MesClient.curFlag.equals("B")){
+                        oprno = MesClient.mes_gw+"B";
+                        sn = MesClient.curSnb;
+                    }
+                    if(MesClient.mes_gwflag.equals("B")){
+                        if(MesClient.curFlag.equals("A")){
+                            oprno = MesClient.mes_gw+"C";
+                        }else{
+                            oprno = MesClient.mes_gw+"D";
+                        }
+                    }
+                    // 检查工件码是否为空,为空则不上传
+                    if(sn != null && !sn.trim().isEmpty()){
+                        JdbcUtils.insertCmtData(oprno,MesClient.mes_line_sn,sn, JSON.toJSONString(MesClient.hjparams));
+                        System.out.println("cmt:"+MesClient.curFlag+" sn:"+sn);
+                    }else{
+                        System.out.println("工件码为空,跳过保存剩余数据");
+                    }
+                    MesClient.hjparams = new ArrayList<>();
+                }catch (Exception e){
+                    e.printStackTrace();
+                }
+            }
+        }
+    }
+
+
+    // 获取A启动状态
+    public static Boolean getAStart(S7PLC s7PLC){
+        try{
+            return s7PLC.readBoolean("DB1.2.2");
+        }catch (Exception e){
+            e.printStackTrace();
+            return false;
+        }
+    }
+
+    // 获取A的结束状态
+    public static Boolean getAFinish(S7PLC s7PLC){
+        try{
+            boolean a = s7PLC.readBoolean("DB1.2.5");
+            boolean b = s7PLC.readBoolean("DB1.2.3");
+//            Boolean ret = s7PLC.readBoolean("DB1.2.0");
+
+            return a || b;
+        }catch (Exception e){
+            e.printStackTrace();
+            return false;
+        }
+    }
+
+    public static void getStatusA(S7PLC s7PLC){
+        if(MesClient.tjFlaga == 1){ // 已扫码,设备未运行
+            Boolean starta = getAStart(s7PLC); //A启动中
+            if(starta){
+                MesClient.curFlag = "A";
+                MesClient.tjFlaga = 2;
+                MesClient.pxstatus1.setText("A:设备运行中");
+                // 更新curSna为当前文本框中的工件码
+                if(MesClient.curSna == null || MesClient.curSna.isEmpty()){
+                    MesClient.curSna = MesClient.product_sn.getText();
+                }
+                if(MesClient.lastpage == 0){
+                    MesClient.lastpage = 1;
+                    PlcUtil.changeEnable(s7PLC,false);
+                }
+            }else{
+                // 程序号防错功能已注释 - 直接允许启动
+                // if(CommonUtils.checkProgramNoSn(MesClient.product_sn.getText(),MesClient.programNoA)){
+                    Boolean reta = getEnable(s7PLC);
+                    if(!reta){
+                        PlcUtil.changeEnable(MesClient.s7PLC,true);
+                    }
+                // }
+            }
+        }else if(MesClient.tjFlaga == 2){
+            Boolean afinish = getAFinish(s7PLC); //A焊接完成
+            if(afinish){ // B启动中,A当做完成
+                MesClient.tjFlaga = 3;
+                MesClient.pxstatus1.setText("A:设备运行结束,提交结果中");
+                MesClient.finish_ok_bt.setEnabled(true);
+
+                Boolean sendret = DataUtil.sendQuality(MesClient.nettyClient,MesClient.product_sn.getText(),"OK",MesClient.user20,"A");
+//                Boolean sendret = DataUtil.sendQuality(MesClient.product_sn.getText(),"OK",MesClient.user20,"A");
+                if(!sendret){
+                    MesClient.pxstatus1.setText("A:结果上传MES失败");
+                    MesClient.tjStatusa = 1;
+                }else{
+//                    MesClient.pxstatus1.setText("A:提交成功");
+//                    MesClient.resetScanA();
+                }
+            }
+        }
+    }
+
+    // 获取B启动状态
+    public static Boolean getBStart(S7PLC s7PLC){
+        try{
+            return s7PLC.readBoolean("DB1.2.3");
+        }catch (Exception e){
+            e.printStackTrace();
+            return false;
+        }
+    }
+
+    // 获取B的结束状态
+    public static Boolean getBFinish(S7PLC s7PLC){
+        try{
+            boolean a = s7PLC.readBoolean("DB1.2.7");
+            boolean b = s7PLC.readBoolean("DB1.2.2");
+//            Boolean ret = s7PLC.readBoolean("DB1.2.1");
+            return a || b;
+        }catch (Exception e){
+            e.printStackTrace();
+            return false;
+        }
+    }
+
+    public static void getStatusB(S7PLC s7PLC){
+        if(MesClient.tjFlagb == 1){ // 已扫码,设备未运行
+            Boolean startb = getBStart(s7PLC); //B启动中
+            if(startb){
+                MesClient.curFlag = "B";
+                MesClient.tjFlagb = 2;
+                MesClient.pxstatus2.setText("B:设备运行中");
+                // 更新curSnb为当前文本框中的工件码
+                if(MesClient.curSnb == null || MesClient.curSnb.isEmpty()){
+                    MesClient.curSnb = MesClient.product_sn2.getText();
+                }
+                if(MesClient.lastpage == 0){
+                    MesClient.lastpage = 1;
+                    PlcUtil.changeEnable(s7PLC,false);
+                }
+            }else{
+                // 程序号防错功能已注释 - 直接允许启动
+                // if(CommonUtils.checkProgramNoSn(MesClient.product_sn2.getText(),MesClient.programNoB)){
+                    Boolean reta = getEnable(s7PLC);
+                    if(!reta){
+                        PlcUtil.changeEnable(MesClient.s7PLC,true);
+                    }
+                // }
+            }
+        }else if(MesClient.tjFlagb == 2){
+            Boolean bfinish = getBFinish(s7PLC); //B焊接完成
+            if(bfinish){
+                MesClient.tjFlagb = 3;
+                MesClient.pxstatus2.setText("B:设备运行结束,提交结果中");
+                MesClient.finish_ng_bt.setEnabled(true);
+
+//                Boolean sendret = DataUtil.sendQuality(MesClient.product_sn2.getText(),"OK",MesClient.user20,"B");
+                Boolean sendret = DataUtil.sendQuality(MesClient.nettyClient,MesClient.product_sn2.getText(),"OK",MesClient.user20,"B");
+                if(!sendret){
+                    MesClient.pxstatus2.setText("B:结果上传MES失败");
+                    MesClient.tjStatusb = 1;
+                }else{
+//                    MesClient.pxstatus2.setText("B:提交成功");
+//                    MesClient.resetScanB();
+                }
+            }
+
+        }
+    }
+
+
+    // 修改设备的禁用开关
+    public static Boolean changeEnable(S7PLC s7PLC,Boolean result){
+        try{
+            s7PLC.writeBoolean("DB9.18.1",result); // AB
+            return true;
+        }catch (Exception e){
+            e.printStackTrace();
+            return false;
+        }
+    }
+
+    // 获取MES允许的值
+    public static Boolean getEnable(S7PLC s7PLC){
+        Boolean ret = false;
+        try{
+            ret = s7PLC.readBoolean("DB9.18.1");
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+        return ret;
+    }
+
+
+
+    // 获取当前是A面还是B面
+    public static String getCurAside(S7PLC s7PLC){
+        String str = "A";
+        try{
+            Boolean ret = s7PLC.readBoolean("DB1.2.0"); // 当前A面
+            if(!ret){
+                str = "B";
+            }
+
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+        return str;
+    }
+
+    // 获取程序号A
+    public static int getProgranNoA(S7PLC s7PLC){
+        int str = 0;
+        try{
+            int ret = Integer.valueOf(s7PLC.readByte("DB8.3")); // AB
+            return ret;
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+        return str;
+    }
+
+    // 获取程序号B
+    public static int getProgranNoB(S7PLC s7PLC){
+        int str = 0;
+        try{
+            int ret = Integer.valueOf(s7PLC.readByte("DB8.4")); // AB
+            return ret;
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+        return str;
+    }
+
+
+
+}

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

+ 0 - 0
src/com/mes/ui/Test.java


Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini