Ver código fonte

增加OKNG件记录

hou 2 semanas atrás
pai
commit
5fb565f0c3

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

@@ -189,6 +189,26 @@ public class DataUtil {
         return String.format("%-"+size+"s", strret);
     }
 
+    public static JSONObject getQmSampleSns(String oprno, String lineSn) {
+        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 url = "http://" + mes_server_ip + ":8980/js/a/mes/mesProductQm/sampleSns";
+            String params = "__ajax=json&oprno=" + oprno + "&lineSn=" + lineSn;
+            String result = doPost(url, params);
+            if (result == null || result.equalsIgnoreCase("false")) {
+                return null;
+            }
+            return JSONObject.parseObject(result);
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
     public static JSONObject getBindMaterail() {
         try{
             String enconding = "UTF-8";

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

@@ -105,6 +105,16 @@ public class MesClient extends JFrame {
     public static int totalPages; // 总页数
     public static JTextField textField;//搜索框
 
+    public static JTable okngTable;
+    public static Object[] okngColumnNames = {"样件", "工件码", "测试日期", "压力", "泄露值", "结果"};
+    public static Object[][] okngRowData = new Object[12][6];
+    public static JLabel okngPageLabel;
+    public static int okngPageNo = 1;
+    public static int okngTotalPages;
+    public static JTextField okngTextField;
+    private static final List<String> okngSampleSns = new ArrayList<>();
+    private static final Map<String, String> okngSampleType = new HashMap<>();
+
     public static JTable table2;
     public static Object[] columnNames2 = { "任务名称" };
     public static Object[][] rowData2 = {{""},{""},{""}};
@@ -919,6 +929,7 @@ public class MesClient extends JFrame {
         toolBar.add(space_4);
 
         tabbedPane = new JTabbedPane(JTabbedPane.TOP);
+        tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
         tabbedPane.setMinimumSize(new Dimension(400, 50));
         tabbedPane.setFont(new Font("宋体", Font.BOLD, 22));
         contentPane.add(tabbedPane);
@@ -1239,6 +1250,7 @@ public class MesClient extends JFrame {
 
         tabbedPane.addTab("记录查询", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPaneDj, null);
 
+        initOkngRecordPanel();
 
         indexPanelB = new JPanel();
         searchScrollPane = new JScrollPane(indexPanelB);
@@ -1940,6 +1952,9 @@ public class MesClient extends JFrame {
             public void stateChanged(ChangeEvent e) {
                 JTabbedPane tabbedPane = (JTabbedPane) e.getSource();
                 int selectedIndex = tabbedPane.getSelectedIndex();
+                if (selectedIndex == tabbedPane.indexOfTab("OKNG样件")) {
+                    loadOkngRecordData();
+                }
                 if(selectedIndex == 1){
 
                 }
@@ -1948,6 +1963,202 @@ public class MesClient extends JFrame {
         });
     }
 
+    private static void initOkngRecordPanel() {
+        JPanel container = new JPanel();
+        container.setLayout(null);
+        JScrollPane scrollPane = new JScrollPane(container);
+
+        JPanel top = new JPanel();
+        top.setBounds(0, 0, 990, 50);
+        top.setLayout(null);
+        container.add(top);
+
+        okngTextField = new JTextField();
+        okngTextField.setFont(new Font("微软雅黑", Font.PLAIN, 16));
+        okngTextField.setForeground(Color.BLACK);
+        okngTextField.setBounds(10, 5, 371, 40);
+        top.add(okngTextField);
+
+        JButton searchBtn = new JButton("搜索");
+        searchBtn.setFont(new Font("微软雅黑", Font.PLAIN, 20));
+        searchBtn.setBounds(385, 5, 90, 40);
+        top.add(searchBtn);
+        searchBtn.addActionListener(e -> {
+            okngPageNo = 1;
+            loadOkngRecordData();
+        });
+
+        JButton resetBtn = new JButton("重置");
+        resetBtn.setFont(new Font("微软雅黑", Font.PLAIN, 20));
+        resetBtn.setBounds(475, 5, 90, 40);
+        top.add(resetBtn);
+        resetBtn.addActionListener(e -> {
+            okngTextField.setText("");
+            okngPageNo = 1;
+            loadOkngRecordData();
+        });
+
+        JButton btnPrevious = new JButton("上一页");
+        btnPrevious.setFont(new Font("微软雅黑", Font.PLAIN, 18));
+        btnPrevious.setBounds(680, 5, 100, 40);
+        top.add(btnPrevious);
+        btnPrevious.addActionListener(e -> {
+            if (okngPageNo > 1) {
+                okngPageNo--;
+                loadOkngRecordData();
+            }
+        });
+
+        okngPageLabel = new JLabel("0/0");
+        okngPageLabel.setFont(new Font("微软雅黑", Font.PLAIN, 18));
+        okngPageLabel.setHorizontalAlignment(SwingConstants.CENTER);
+        okngPageLabel.setBorder(BorderFactory.createLineBorder(Color.GRAY, 1));
+        okngPageLabel.setBounds(780, 5, 100, 40);
+        top.add(okngPageLabel);
+
+        JButton btnNext = new JButton("下一页");
+        btnNext.setFont(new Font("微软雅黑", Font.PLAIN, 18));
+        btnNext.setBounds(880, 5, 100, 40);
+        top.add(btnNext);
+        btnNext.addActionListener(e -> {
+            if (okngPageNo < okngTotalPages) {
+                okngPageNo++;
+                loadOkngRecordData();
+            }
+        });
+
+        JPanel tablePanel = new JPanel();
+        tablePanel.setBounds(0, 49, 990, 518);
+        tablePanel.setLayout(new GridLayout(0, 1, 0, 0));
+        container.add(tablePanel);
+
+        okngTable = new JTable(okngRowData, okngColumnNames) {
+            public boolean isCellEditable(int row, int column) {
+                return false;
+            }
+        };
+        okngTable.setRowHeight(40);
+        okngTable.setFont(new Font("微软雅黑", Font.PLAIN, 14));
+        CenterRenderer centerRenderer = new CenterRenderer();
+        for (int i = 0; i < okngTable.getColumnCount(); i++) {
+            okngTable.getColumn(okngTable.getColumnName(i)).setCellRenderer(centerRenderer);
+        }
+        tablePanel.add(new JScrollPane(okngTable));
+
+        tabbedPane.addTab("OKNG样件", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), scrollPane, null);
+    }
+
+    private static void loadOkngRecordData() {
+        for (int i = 0; i < okngRowData.length; i++) {
+            for (int j = 0; j < okngRowData[i].length; j++) {
+                okngRowData[i][j] = null;
+            }
+        }
+        boolean loaded = refreshOkngSamples();
+        int pageSize = 12;
+        String snLike = okngTextField == null ? "" : okngTextField.getText();
+        if (!loaded) {
+            okngTotalPages = 0;
+            if (okngPageLabel != null) {
+                okngPageLabel.setText("失败");
+            }
+            if (okngTable != null) {
+                okngTable.repaint();
+            }
+            return;
+        }
+        int totalItems = JdbcUtils.countTestRecordBySns(okngSampleSns, snLike);
+        if (totalItems <= 0) {
+            okngTotalPages = 0;
+            if (okngPageLabel != null) {
+                okngPageLabel.setText(okngSampleSns.isEmpty() ? "未配置" : "0/0");
+            }
+            if (okngTable != null) {
+                okngTable.repaint();
+            }
+            return;
+        }
+        okngTotalPages = (int) Math.ceil((double) totalItems / (double) pageSize);
+        if (okngPageNo > okngTotalPages) {
+            okngPageNo = okngTotalPages;
+        }
+        if (okngPageNo < 1) {
+            okngPageNo = 1;
+        }
+        if (okngPageLabel != null) {
+            okngPageLabel.setText(okngPageNo + "/" + okngTotalPages);
+        }
+        int offset = (okngPageNo - 1) * pageSize;
+        List<String[]> rows = JdbcUtils.queryTestRecordBySns(okngSampleSns, snLike, pageSize, offset);
+        int rowIndex = 0;
+        for (String[] row : rows) {
+            if (rowIndex >= okngRowData.length) {
+                break;
+            }
+            okngRowData[rowIndex][0] = okngSampleType.getOrDefault(row[0], "");
+            okngRowData[rowIndex][1] = row[0];
+            okngRowData[rowIndex][2] = row[1];
+            okngRowData[rowIndex][3] = row[2];
+            okngRowData[rowIndex][4] = row[3];
+            okngRowData[rowIndex][5] = row[4];
+            rowIndex++;
+        }
+        if (okngTable != null) {
+            okngTable.repaint();
+        }
+    }
+
+    private static boolean refreshOkngSamples() {
+        okngSampleSns.clear();
+        okngSampleType.clear();
+        String oprno = "";
+        String lineSn = "";
+        try {
+            InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
+            Properties pro = new Properties();
+            BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
+            pro.load(br);
+            oprno = pro.getProperty("mes.gw");
+            lineSn = pro.getProperty("mes.line_sn");
+            br.close();
+        } catch (Exception e) {
+            log.error("读取工位配置失败", e);
+            return false;
+        }
+        JSONObject ret = DataUtil.getQmSampleSns(oprno == null ? "" : oprno.trim(), lineSn == null ? "" : lineSn.trim());
+        if (ret == null || !"true".equalsIgnoreCase(String.valueOf(ret.get("result")))) {
+            return false;
+        }
+        JSONObject data = ret.getJSONObject("data");
+        if (data == null) {
+            return true;
+        }
+        addOkngSamples(data.getString("ok"), "OK件");
+        addOkngSamples(data.getString("ng"), "NG件");
+        return true;
+    }
+
+    private static void addOkngSamples(String sns, String type) {
+        if (sns == null || sns.trim().isEmpty()) {
+            return;
+        }
+        for (String sn : sns.split(",", -1)) {
+            String code = sn.trim();
+            if (code.isEmpty()) {
+                continue;
+            }
+            if (!okngSampleSns.contains(code)) {
+                okngSampleSns.add(code);
+            }
+            String old = okngSampleType.get(code);
+            if (old == null) {
+                okngSampleType.put(code, type);
+            } else if (!old.equals(type) && !old.contains(type)) {
+                okngSampleType.put(code, old + "/" + type);
+            }
+        }
+    }
+
     public static void setMenuStatus(String msg,int error){
         if(error == 0){
             MesClient.status_menu.setForeground(Color.GREEN);

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

@@ -332,6 +332,101 @@ public class JdbcUtils {
 		}
 	}
 
+	public static int countTestRecordBySns(List<String> sns, String snLike) {
+		if (sns == null || sns.isEmpty()) {
+			return 0;
+		}
+		StringBuilder sql = new StringBuilder("SELECT count(*) AS total FROM test_record WHERE sn IN (");
+		appendPlaceholders(sql, sns.size());
+		sql.append(")");
+		boolean hasLike = snLike != null && !snLike.trim().isEmpty();
+		if (hasLike) {
+			sql.append(" AND sn LIKE ?");
+		}
+		try {
+			if (JdbcUtils.conn == null || JdbcUtils.conn.isClosed()) {
+				JdbcUtils.openConnection();
+			}
+			try (PreparedStatement pstmt = conn.prepareStatement(sql.toString())) {
+				int idx = 1;
+				for (String sn : sns) {
+					pstmt.setString(idx++, sn);
+				}
+				if (hasLike) {
+					pstmt.setString(idx, "%" + snLike.trim() + "%");
+				}
+				try (ResultSet rs = pstmt.executeQuery()) {
+					if (rs.next()) {
+						return rs.getInt("total");
+					}
+				}
+			}
+		} catch (SQLException e) {
+			log.error("查询OKNG样件记录条数失败", e);
+		}
+		return 0;
+	}
+
+	public static List<String[]> queryTestRecordBySns(List<String> sns, String snLike, int limit, int offset) {
+		List<String[]> rows = new ArrayList<>();
+		if (sns == null || sns.isEmpty()) {
+			return rows;
+		}
+		StringBuilder sql = new StringBuilder("SELECT sn, create_time, param1, param2, param3, param4, result FROM test_record WHERE sn IN (");
+		appendPlaceholders(sql, sns.size());
+		sql.append(")");
+		boolean hasLike = snLike != null && !snLike.trim().isEmpty();
+		if (hasLike) {
+			sql.append(" AND sn LIKE ?");
+		}
+		sql.append(" ORDER BY id DESC LIMIT ? OFFSET ?");
+		try {
+			if (JdbcUtils.conn == null || JdbcUtils.conn.isClosed()) {
+				JdbcUtils.openConnection();
+			}
+			try (PreparedStatement pstmt = conn.prepareStatement(sql.toString())) {
+				int idx = 1;
+				for (String sn : sns) {
+					pstmt.setString(idx++, sn);
+				}
+				if (hasLike) {
+					pstmt.setString(idx++, "%" + snLike.trim() + "%");
+				}
+				pstmt.setInt(idx++, limit);
+				pstmt.setInt(idx, offset);
+				try (ResultSet rs = pstmt.executeQuery()) {
+					while (rs.next()) {
+						String pressure = nullToEmpty(rs.getString("param1")) + nullToEmpty(rs.getString("param2"));
+						String leak = nullToEmpty(rs.getString("param3")) + nullToEmpty(rs.getString("param4"));
+						rows.add(new String[]{
+								nullToEmpty(rs.getString("sn")).trim(),
+								nullToEmpty(rs.getString("create_time")),
+								pressure,
+								leak,
+								nullToEmpty(rs.getString("result"))
+						});
+					}
+				}
+			}
+		} catch (SQLException e) {
+			log.error("查询OKNG样件记录失败", e);
+		}
+		return rows;
+	}
+
+	private static void appendPlaceholders(StringBuilder sql, int n) {
+		for (int i = 0; i < n; i++) {
+			if (i > 0) {
+				sql.append(',');
+			}
+			sql.append('?');
+		}
+	}
+
+	private static String nullToEmpty(String value) {
+		return value == null ? "" : value;
+	}
+
 
 	//面板查询(分页)
 	public static List<QmData> getTestDataAll() {

+ 7 - 7
src/com/mes/util/SerialPortUtils.java

@@ -280,11 +280,11 @@ public class SerialPortUtils {
 
         if (isOpen) {
             serialPort.writeBytes(data.getBytes(), data.length());
-            log.info("成品气密仪已发送数据:" + data);
+            log.info("气密仪已发送数据:" + data);
             return true;
         } else {
-            log.info("成品气密仪串口未打开,尝试重新打开串口...");
-            MesClient.setMenuStatus("成品气密仪连接失败,请检查设备后重试",1);
+            log.info("气密仪串口未打开,尝试重新打开串口...");
+            MesClient.setMenuStatus("气密仪连接失败,请检查设备后重试",1);
 
             isOpen = openPort();
             return false;
@@ -340,8 +340,8 @@ public class SerialPortUtils {
             }
             return true;
         } else {
-            log.info("成品气密仪串口未打开,尝试重新打开串口...");
-            MesClient.setMenuStatus("成品气密仪连接失败,请检查设备后重试",1);
+            log.info("气密仪串口未打开,尝试重新打开串口...");
+            MesClient.setMenuStatus("气密仪连接失败,请检查设备后重试",1);
             isOpen = openPort();
             return false;
         }
@@ -372,8 +372,8 @@ public class SerialPortUtils {
             }
             return true;
         } else {
-            log.info("成品气密仪串口未打开,尝试重新打开串口...");
-            MesClient.setMenuStatus("成品气密仪连接失败,请检查设备后重试",1);
+            log.info("气密仪串口未打开,尝试重新打开串口...");
+            MesClient.setMenuStatus("气密仪连接失败,请检查设备后重试",1);
             isOpen = openPort();
             return false;
         }

+ 4 - 4
src/resources/config/config.properties

@@ -1,7 +1,7 @@
-mes.gw=OP370A
-#mes.server_ip=127.0.0.1
-mes.server_ip=192.168.18.99
+mes.gw=OP370B
+mes.server_ip=127.0.0.1
+#mes.server_ip=192.168.18.99
 mes.tcp_port=3000
 mes.heart_beat_cycle=60
 mes.line_sn=XT
-portName1=COM9
+portName1=COM7