|
|
@@ -11,6 +11,7 @@ import com.mes.component.MesRadio;
|
|
|
import com.mes.component.MesWebView;
|
|
|
import com.mes.component.MyDialog;
|
|
|
import com.mes.netty.NettyClient;
|
|
|
+import com.mes.util.ConfigUtil;
|
|
|
import com.mes.util.DateLocalUtils;
|
|
|
import com.mes.util.HttpUtils;
|
|
|
import com.mes.util.IweldCloudUtil;
|
|
|
@@ -37,10 +38,12 @@ import java.sql.SQLException;
|
|
|
import java.sql.Statement;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.Properties;
|
|
|
import java.util.Timer;
|
|
|
import java.util.TimerTask;
|
|
|
-import java.util.List;
|
|
|
|
|
|
public class MesClient extends JFrame {
|
|
|
public static final Logger log = LoggerFactory.getLogger(MesClient.class);
|
|
|
@@ -59,6 +62,36 @@ public class MesClient extends JFrame {
|
|
|
public static NettyClient nettyClient;
|
|
|
public static boolean tcp_connect_flag = false;
|
|
|
public static boolean connect_request_flag = false;
|
|
|
+ private static volatile long lastTcpReconnectMs = 0;
|
|
|
+ private static final Object tcpReconnectLock = new Object();
|
|
|
+
|
|
|
+ /** 断线后延迟重连,避免报文尚未回包就被 SYNR 新连接打断 */
|
|
|
+ public static void scheduleTcpReconnect(){
|
|
|
+ synchronized (tcpReconnectLock){
|
|
|
+ long now = System.currentTimeMillis();
|
|
|
+ if(now - lastTcpReconnectMs < 3000){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(connect_request_flag || nettyClient == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ connect_request_flag = true;
|
|
|
+ lastTcpReconnectMs = now;
|
|
|
+ }
|
|
|
+ new Timer(true).schedule(new TimerTask() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ try{
|
|
|
+ if(nettyClient != null && !tcp_connect_flag){
|
|
|
+ System.out.println("TCP断线,延迟重连...");
|
|
|
+ DataUtil.synrTcp(nettyClient, mes_gw);
|
|
|
+ }
|
|
|
+ }finally {
|
|
|
+ connect_request_flag = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, 2000);
|
|
|
+ }
|
|
|
|
|
|
//session
|
|
|
public static String sessionid = "";
|
|
|
@@ -85,17 +118,12 @@ public class MesClient extends JFrame {
|
|
|
public static JButton user_menu;
|
|
|
|
|
|
public static int scan_type = 0;
|
|
|
- public static JButton finish_ok_bt;
|
|
|
- public static JButton finish_ok_bt2;
|
|
|
- public static JButton finish_ng_bt;
|
|
|
- public static JButton finish_ng_bt2;
|
|
|
+ public static JButton batch_scan_1;
|
|
|
+ public static JButton batch_scan_2;
|
|
|
public static JTextField product_sn;
|
|
|
public static JLabel pxstatus1;
|
|
|
public static JLabel pxstatus2;
|
|
|
|
|
|
- public static JButton batch_scan_1;
|
|
|
- public static JButton batch_scan_2;
|
|
|
-
|
|
|
public static Integer tjFlag = 0; // 0=未开始 1=已扫码,设备未启动 2=设备运行中 3=设备运行结束
|
|
|
|
|
|
public static Integer tjFlaga = 0; // 0=未开始 1=已扫码,设备未启动 2=设备运行中 3=设备运行结束
|
|
|
@@ -277,16 +305,13 @@ public class MesClient extends JFrame {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
- }, 1000,500);
|
|
|
+ }, 1000, IweldCloudUtil.getCollectIntervalMs());
|
|
|
}
|
|
|
|
|
|
//鐠囧鍘ょ純顔芥瀮娴狅拷
|
|
|
private static void readProperty() throws IOException{
|
|
|
- String enconding = "UTF-8";
|
|
|
- InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
|
|
|
- Properties pro = new Properties();
|
|
|
- BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
|
|
|
- pro.load(br);
|
|
|
+ Properties pro = ConfigUtil.loadProperties();
|
|
|
+ ConfigUtil.printStartupInfo();
|
|
|
mes_gw = pro.getProperty("mes.gw");
|
|
|
|
|
|
// mes_gw_des = pro.getProperty("mes.gw_des");
|
|
|
@@ -371,18 +396,9 @@ public class MesClient extends JFrame {
|
|
|
heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
|
|
|
heart_beat_menu.repaint();
|
|
|
|
|
|
- //閼汇儲婀潻鐐村复閸掓瑥鐨剧拠鏇$箾閹猴拷
|
|
|
- if(nettyClient!=null&&!tcp_connect_flag){
|
|
|
- System.out.println("TCP瀹稿弶鏌囧锟�");
|
|
|
- //TCP闁插秵鏌婇崥灞绢劄鏉╃偞甯�
|
|
|
- if(!connect_request_flag) {
|
|
|
- //System.out.println("TCP闁插秵鏌婇崥灞绢劄鏉╃偞甯�");
|
|
|
- //鐠佸墽鐤員CP鐠囬攱鐪伴悩鑸碉拷锟�,閸欘亪鍣搁弬鏉挎倱濮濄儴绻涢幒銉ょ濞嗭拷
|
|
|
- connect_request_flag = true;
|
|
|
-
|
|
|
- DataUtil.synrTcp(nettyClient,mes_gw);
|
|
|
- }
|
|
|
-
|
|
|
+ // TCP 断线时延迟重连
|
|
|
+ if(nettyClient!=null && !tcp_connect_flag){
|
|
|
+ scheduleTcpReconnect();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -425,7 +441,6 @@ public class MesClient extends JFrame {
|
|
|
public static void resetScanA() {
|
|
|
work_status = 0;
|
|
|
check_quality_result = false;
|
|
|
- MesClient.finish_ok_bt.setEnabled(false);
|
|
|
MesClient.mesQualityFlagA = false;
|
|
|
product_sn.setText("");
|
|
|
MesClient.pxstatus1.setText("A");
|
|
|
@@ -448,9 +463,6 @@ public class MesClient extends JFrame {
|
|
|
MesClient.formatScanType(1);
|
|
|
// PlcUtil.changeEnable(MesClient.s7PLC,false);
|
|
|
|
|
|
- finish_ok_bt.setEnabled(false);
|
|
|
- finish_ng_bt.setEnabled(false);
|
|
|
-
|
|
|
updateMaterailData(); // 更新物料
|
|
|
|
|
|
shiftUserCheck();
|
|
|
@@ -483,7 +495,6 @@ public class MesClient extends JFrame {
|
|
|
public static void resetScanB() {
|
|
|
work_status2 = 0;
|
|
|
check_quality_result2 = false;
|
|
|
- MesClient.finish_ng_bt.setEnabled(false);
|
|
|
MesClient.mesQualityFlagB = false;
|
|
|
product_sn2.setText("");
|
|
|
|
|
|
@@ -504,9 +515,6 @@ public class MesClient extends JFrame {
|
|
|
// MesClient.batch_scan_2.setEnabled(false);
|
|
|
MesClient.formatScanType(1);
|
|
|
// PlcUtil.changeEnable(MesClient.s7PLC,false);
|
|
|
- finish_ok_bt2.setEnabled(false);
|
|
|
- finish_ng_bt2.setEnabled(false);
|
|
|
-
|
|
|
|
|
|
updateMaterailData(); // 更新物料
|
|
|
|
|
|
@@ -525,7 +533,84 @@ public class MesClient extends JFrame {
|
|
|
user20 = user20 + space_tmp1;
|
|
|
}
|
|
|
|
|
|
- //閼惧嘲褰嘼arcode閸愬懎顔�36娴o拷
|
|
|
+ /** 提交质量结果,并将焊接实时参数落本地库 */
|
|
|
+ public static boolean submitQualityAndFlush(String face, String result) {
|
|
|
+ getUser();
|
|
|
+ String rawSn = "A".equals(face) ? product_sn.getText() : product_sn2.getText();
|
|
|
+ if(rawSn == null || rawSn.trim().isEmpty()){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ String sn = getBarcode(rawSn.trim());
|
|
|
+ Boolean sendret = DataUtil.sendQuality(nettyClient, sn, result, user20, face);
|
|
|
+ IweldCloudUtil.flushWeldingParamsOnFinish(face);
|
|
|
+ return sendret != null && sendret;
|
|
|
+ }
|
|
|
+
|
|
|
+ /** manualImmediateReset=true 时发送成功后立即复位;自动流程由 MesRevice 等待 MES 回包后复位 */
|
|
|
+ public static void handleSubmitResult(String face, String result, boolean manualImmediateReset) {
|
|
|
+ if(!tcp_connect_flag){
|
|
|
+ setMenuStatus("未连接MES服务器", -1);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String label = "A".equals(face) ? "A面" : "B面";
|
|
|
+ String rawSn = "A".equals(face) ? product_sn.getText() : product_sn2.getText();
|
|
|
+ if(rawSn == null || rawSn.trim().isEmpty()){
|
|
|
+ setMenuStatus(label + "无工件码,请先扫码", -1);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ boolean sendret = submitQualityAndFlush(face, result);
|
|
|
+ if(!sendret){
|
|
|
+ if("A".equals(face)){
|
|
|
+ pxstatus1.setText("A:结果上传MES失败");
|
|
|
+ tjStatusa = 1;
|
|
|
+ }else{
|
|
|
+ pxstatus2.setText("B:结果上传MES失败");
|
|
|
+ tjStatusb = 1;
|
|
|
+ }
|
|
|
+ setMenuStatus(label + "提交失败,请重试", -1);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(manualImmediateReset){
|
|
|
+ if("A".equals(face)){
|
|
|
+ pxstatus1.setText("OK".equals(result) ? "A:提交成功" : "A:已提交NG");
|
|
|
+ status_menu.setText("OK".equals(result) ? "A件提交成功" : "A件已提交NG");
|
|
|
+ resetScanA();
|
|
|
+ }else{
|
|
|
+ pxstatus2.setText("OK".equals(result) ? "B:提交成功" : "B:已提交NG");
|
|
|
+ status_menu.setText("OK".equals(result) ? "B件提交成功" : "B件已提交NG");
|
|
|
+ resetScanB();
|
|
|
+ }
|
|
|
+ setMenuStatus(label + ("OK".equals(result) ? "提交成功" : "已提交NG"), 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void promptManualSubmit(String face) {
|
|
|
+ String label = "A".equals(face) ? "A面" : "B面";
|
|
|
+ String rawSn = "A".equals(face) ? product_sn.getText() : product_sn2.getText();
|
|
|
+ if(rawSn == null || rawSn.trim().isEmpty()){
|
|
|
+ setMenuStatus(label + "无工件码,请先扫码", -1);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ int choice = JOptionPane.showOptionDialog(
|
|
|
+ mesClientFrame,
|
|
|
+ label + " 工件: " + rawSn.trim() + "\n请选择提交结果",
|
|
|
+ "手动提交-" + label,
|
|
|
+ JOptionPane.DEFAULT_OPTION,
|
|
|
+ JOptionPane.QUESTION_MESSAGE,
|
|
|
+ null,
|
|
|
+ new Object[]{"OK", "NG", "取消"},
|
|
|
+ "OK"
|
|
|
+ );
|
|
|
+ if(choice == 0){
|
|
|
+ handleSubmitResult(face, "OK", true);
|
|
|
+ }else if(choice == 1){
|
|
|
+ handleSubmitResult(face, "NG", true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public static String getBarcode(String barcodeTmp) {
|
|
|
String barcodeRet = barcodeTmp;
|
|
|
if(barcodeTmp.equalsIgnoreCase("")) {
|
|
|
@@ -601,7 +686,9 @@ public class MesClient extends JFrame {
|
|
|
public void mousePressed(MouseEvent e) {
|
|
|
super.mouseClicked(e);
|
|
|
//闁插秷绻沵es
|
|
|
- nettyClient.future.channel().close();
|
|
|
+ if(nettyClient != null && nettyClient.isChannelActive()){
|
|
|
+ nettyClient.future.channel().close();
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
settingMenu.add(resetTcpMenu);
|
|
|
@@ -637,16 +724,7 @@ public class MesClient extends JFrame {
|
|
|
@Override
|
|
|
public void mousePressed(MouseEvent e) {
|
|
|
super.mouseClicked(e);
|
|
|
- finish_ok_bt.setEnabled(true);
|
|
|
- finish_ng_bt.setEnabled(true);
|
|
|
-// MesClient.finish_ok_bt.setEnabled(true);
|
|
|
-// if(MesClient.work_status == 1){
|
|
|
-// Boolean sendret = DataUtil.sendQuality(MesClient.nettyClient,MesClient.product_sn.getText(),"OK",MesClient.user20,"A");
|
|
|
-// if(!sendret){
|
|
|
-// MesClient.pxstatus1.setText("A:结果上传MES失败");
|
|
|
-// MesClient.tjStatusa = 1;
|
|
|
-// }
|
|
|
-// }
|
|
|
+ promptManualSubmit("A");
|
|
|
}
|
|
|
});
|
|
|
settingMenu.add(resetTcpMenu_1sd);
|
|
|
@@ -658,14 +736,7 @@ public class MesClient extends JFrame {
|
|
|
@Override
|
|
|
public void mousePressed(MouseEvent e) {
|
|
|
super.mouseClicked(e);
|
|
|
- finish_ok_bt2.setEnabled(true);
|
|
|
- finish_ng_bt2.setEnabled(true);
|
|
|
-// MesClient.finish_ng_bt.setEnabled(true);
|
|
|
-// Boolean sendret = DataUtil.sendQuality(MesClient.nettyClient,MesClient.product_sn2.getText(),"OK",MesClient.user20,"B");
|
|
|
-// if(!sendret){
|
|
|
-// MesClient.pxstatus2.setText("B:结果上传MES失败");
|
|
|
-// MesClient.tjStatusb = 1;
|
|
|
-// }
|
|
|
+ promptManualSubmit("B");
|
|
|
}
|
|
|
});
|
|
|
settingMenu.add(resetTcpMenu_1_1sd);
|
|
|
@@ -767,152 +838,6 @@ public class MesClient extends JFrame {
|
|
|
// mesRadioHj.setBounds(190,170,500,50);
|
|
|
// indexPanelA.add(mesRadioHj);
|
|
|
|
|
|
- finish_ok_bt = new JButton("OK");
|
|
|
- finish_ok_bt.setEnabled(false);
|
|
|
- finish_ok_bt.addActionListener(new ActionListener() {
|
|
|
- public void actionPerformed(ActionEvent e) {
|
|
|
-// if(work_status == 1 && check_quality_result){
|
|
|
-//
|
|
|
-//
|
|
|
-// }
|
|
|
- String sn = getBarcode(product_sn.getText());
|
|
|
- getUser();
|
|
|
-
|
|
|
- if(!sn.isEmpty()){
|
|
|
- String qret = "OK";
|
|
|
- Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"A");
|
|
|
- if(!sendret){
|
|
|
- MesClient.pxstatus1.setText("A:结果上传MES失败");
|
|
|
- MesClient.tjStatusa = 1;
|
|
|
- }else{
|
|
|
- MesClient.pxstatus1.setText("A:提交成功");
|
|
|
- MesClient.status_menu.setText("A件提交成功");
|
|
|
- MesClient.resetScanA();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- });
|
|
|
- finish_ok_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
|
|
|
- finish_ok_bt.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 32));
|
|
|
- finish_ok_bt.setBounds(50, 380, 160, 80);
|
|
|
- finish_ok_bt.setEnabled(false);
|
|
|
-// indexPanelA.add(finish_ok_bt);
|
|
|
-
|
|
|
- finish_ng_bt = new JButton("NG");
|
|
|
- finish_ng_bt.setEnabled(false);
|
|
|
- finish_ng_bt.addActionListener(new ActionListener() {
|
|
|
- public void actionPerformed(ActionEvent e) {
|
|
|
-// if(work_status == 1 && check_quality_result){
|
|
|
-//
|
|
|
-// String sn = getBarcode(product_sn.getText());
|
|
|
-// getUser();
|
|
|
-// String qret = "OK";
|
|
|
-// Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"B");
|
|
|
-// if(!sendret){
|
|
|
-// JOptionPane.showMessageDialog(mesClientFrame,"上传MES失败,请重试","提醒", JOptionPane.INFORMATION_MESSAGE);
|
|
|
-// return;
|
|
|
-// }
|
|
|
-// }
|
|
|
- String sn = getBarcode(product_sn2.getText());
|
|
|
- getUser();
|
|
|
-
|
|
|
- if(!sn.isEmpty()){
|
|
|
- String qret = "OK";
|
|
|
- Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"B");
|
|
|
- if(!sendret){
|
|
|
- MesClient.pxstatus2.setText("B:结果上传MES失败");
|
|
|
- MesClient.tjStatusb = 1;
|
|
|
- }else{
|
|
|
- MesClient.pxstatus2.setText("B:提交成功");
|
|
|
- MesClient.status_menu.setText("B件提交成功");
|
|
|
- MesClient.resetScanB();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- finish_ng_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
|
|
|
- finish_ng_bt.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 32));
|
|
|
- finish_ng_bt.setBounds(280, 380, 160, 80);
|
|
|
- finish_ng_bt.setEnabled(false);
|
|
|
-// indexPanelA.add(finish_ng_bt);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- finish_ok_bt2 = new JButton("OK");
|
|
|
- finish_ok_bt2.setEnabled(false);
|
|
|
- finish_ok_bt2.addActionListener(new ActionListener() {
|
|
|
- public void actionPerformed(ActionEvent e) {
|
|
|
-// if(work_status == 1 && check_quality_result){
|
|
|
-//
|
|
|
-//
|
|
|
-// }
|
|
|
- String sn = getBarcode(product_sn.getText());
|
|
|
- getUser();
|
|
|
-
|
|
|
- if(!sn.isEmpty()){
|
|
|
- String qret = "OK";
|
|
|
- Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"B");
|
|
|
- if(!sendret){
|
|
|
- MesClient.pxstatus2.setText("B:结果上传MES失败");
|
|
|
- MesClient.tjStatusb = 1;
|
|
|
- }else{
|
|
|
- MesClient.pxstatus2.setText("B:提交成功");
|
|
|
- MesClient.status_menu.setText("B件提交成功");
|
|
|
- MesClient.resetScanB();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- });
|
|
|
- finish_ok_bt2.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
|
|
|
- finish_ok_bt2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 32));
|
|
|
- finish_ok_bt2.setBounds(550, 380, 160, 80);
|
|
|
- finish_ok_bt2.setEnabled(false);
|
|
|
-// indexPanelA.add(finish_ok_bt2);
|
|
|
-
|
|
|
- finish_ng_bt2 = new JButton("NG");
|
|
|
- finish_ng_bt2.setEnabled(false);
|
|
|
- finish_ng_bt2.addActionListener(new ActionListener() {
|
|
|
- public void actionPerformed(ActionEvent e) {
|
|
|
-// if(work_status == 1 && check_quality_result){
|
|
|
-//
|
|
|
-// String sn = getBarcode(product_sn.getText());
|
|
|
-// getUser();
|
|
|
-// String qret = "OK";
|
|
|
-// Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"B");
|
|
|
-// if(!sendret){
|
|
|
-// JOptionPane.showMessageDialog(mesClientFrame,"上传MES失败,请重试","提醒", JOptionPane.INFORMATION_MESSAGE);
|
|
|
-// return;
|
|
|
-// }
|
|
|
-// }
|
|
|
- String sn = getBarcode(product_sn2.getText());
|
|
|
- getUser();
|
|
|
-
|
|
|
- if(!sn.isEmpty()){
|
|
|
- String qret = "NG";
|
|
|
- Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"B");
|
|
|
- if(!sendret){
|
|
|
- MesClient.pxstatus2.setText("B:结果上传MES失败");
|
|
|
- MesClient.tjStatusb = 1;
|
|
|
- }else{
|
|
|
- MesClient.pxstatus2.setText("B:提交成功");
|
|
|
- MesClient.status_menu.setText("B件提交成功");
|
|
|
- MesClient.resetScanB();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- finish_ng_bt2.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
|
|
|
- finish_ng_bt2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 32));
|
|
|
- finish_ng_bt2.setBounds(780, 380, 160, 80);
|
|
|
- finish_ng_bt2.setEnabled(false);
|
|
|
-// indexPanelA.add(finish_ng_bt2);
|
|
|
-
|
|
|
product_sn2 = new JTextField();
|
|
|
product_sn2.setText("");
|
|
|
product_sn2.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
@@ -1393,67 +1318,164 @@ public class MesClient extends JFrame {
|
|
|
MesClient.status_menu.setText(msg);
|
|
|
}
|
|
|
|
|
|
- public static void getMaterailData(){
|
|
|
- JSONObject retObj = DataUtil.getBindMaterail();
|
|
|
- if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
|
|
|
- List<BindMaterialResp> arrs = retObj.getList("data",BindMaterialResp.class);
|
|
|
- int i = 0;
|
|
|
- rowData = new Object[arrs.size()][7];
|
|
|
- for (BindMaterialResp bindMaterialResp:arrs){
|
|
|
- rowData[i][0] = bindMaterialResp.getMaterialTitle();
|
|
|
- rowData[i][1] = bindMaterialResp.getBatchSn();
|
|
|
- rowData[i][2] = bindMaterialResp.getLastTimes();
|
|
|
- rowData[i][3] = "";
|
|
|
- rowData[i][4] = bindMaterialResp.getCraft();
|
|
|
- rowData[i][5] = bindMaterialResp.getMaterialId();
|
|
|
- rowData[i][6] = bindMaterialResp.getType();
|
|
|
- i++;
|
|
|
- }
|
|
|
- bindBatchPanel();
|
|
|
+ /** A/B 面绑定工位:gwflag=A 绑 OP060A/B,gwflag=B 绑 OP060C/D */
|
|
|
+ public static String[] getMaterialOprnos(){
|
|
|
+ if("A".equals(mes_gwflag)){
|
|
|
+ return new String[]{mes_gw + "A", mes_gw + "B"};
|
|
|
+ }else if("B".equals(mes_gwflag)){
|
|
|
+ return new String[]{mes_gw + "C", mes_gw + "D"};
|
|
|
}
|
|
|
+ return new String[]{mes_gw};
|
|
|
}
|
|
|
|
|
|
- public static void updateMaterailData(){
|
|
|
- JSONObject retObj = DataUtil.getBindMaterail();
|
|
|
- if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
|
|
|
- List<BindMaterialResp> arrs = retObj.getList("data",BindMaterialResp.class);
|
|
|
-
|
|
|
- int i = 0;
|
|
|
- for (BindMaterialResp bindMaterialResp:arrs){
|
|
|
- rowData[i][0] = bindMaterialResp.getMaterialTitle();
|
|
|
- rowData[i][1] = bindMaterialResp.getBatchSn();
|
|
|
- rowData[i][2] = bindMaterialResp.getLastTimes();
|
|
|
- rowData[i][3] = "";
|
|
|
- rowData[i][4] = bindMaterialResp.getCraft();
|
|
|
- rowData[i][5] = bindMaterialResp.getMaterialId();
|
|
|
- rowData[i][6] = bindMaterialResp.getType();
|
|
|
- i++;
|
|
|
+ /** A/B 共用库存:合并各面查询结果,剩余次数取较小值 */
|
|
|
+ private static String materialRowKey(BindMaterialResp item){
|
|
|
+ return String.valueOf(item.getMaterialId()) + "|" + String.valueOf(item.getCraft()) + "|" + String.valueOf(item.getType());
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Integer parseLastTimes(String lastTimes){
|
|
|
+ if(lastTimes == null || lastTimes.trim().isEmpty()){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ try{
|
|
|
+ return Integer.parseInt(lastTimes.trim());
|
|
|
+ }catch (NumberFormatException e){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String mergeSharedLastTimes(String left, String right){
|
|
|
+ Integer leftVal = parseLastTimes(left);
|
|
|
+ Integer rightVal = parseLastTimes(right);
|
|
|
+ if(leftVal == null){
|
|
|
+ return right != null ? right : "";
|
|
|
+ }
|
|
|
+ if(rightVal == null){
|
|
|
+ return left;
|
|
|
+ }
|
|
|
+ return String.valueOf(Math.min(leftVal, rightVal));
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String pickSharedBatchSn(String left, String right){
|
|
|
+ if(left != null && !left.trim().isEmpty()){
|
|
|
+ return left;
|
|
|
+ }
|
|
|
+ return right != null ? right : "";
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void mergeSharedMaterial(BindMaterialResp target, BindMaterialResp source){
|
|
|
+ target.setLastTimes(mergeSharedLastTimes(target.getLastTimes(), source.getLastTimes()));
|
|
|
+ target.setBatchSn(pickSharedBatchSn(target.getBatchSn(), source.getBatchSn()));
|
|
|
+ }
|
|
|
+
|
|
|
+ private static List<BindMaterialResp> loadSharedMaterialList(){
|
|
|
+ Map<String, BindMaterialResp> merged = new LinkedHashMap<>();
|
|
|
+ for(String oprno : getMaterialOprnos()){
|
|
|
+ JSONObject retObj = DataUtil.getBindMaterail(oprno);
|
|
|
+ if(retObj == null || retObj.get("result") == null || !retObj.get("result").toString().equalsIgnoreCase("true")){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ List<BindMaterialResp> arrs = retObj.getList("data", BindMaterialResp.class);
|
|
|
+ if(arrs == null || arrs.isEmpty()){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ for(BindMaterialResp item : arrs){
|
|
|
+ String key = materialRowKey(item);
|
|
|
+ BindMaterialResp existing = merged.get(key);
|
|
|
+ if(existing == null){
|
|
|
+ merged.put(key, item);
|
|
|
+ }else{
|
|
|
+ mergeSharedMaterial(existing, item);
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
+ return new ArrayList<>(merged.values());
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Object[][] buildMaterialRowData(){
|
|
|
+ List<BindMaterialResp> arrs = loadSharedMaterialList();
|
|
|
+ if(arrs.isEmpty()){
|
|
|
+ return new Object[0][7];
|
|
|
+ }
|
|
|
+ Object[][] rows = new Object[arrs.size()][7];
|
|
|
+ int i = 0;
|
|
|
+ for (BindMaterialResp bindMaterialResp : arrs){
|
|
|
+ rows[i][0] = bindMaterialResp.getMaterialTitle();
|
|
|
+ rows[i][1] = bindMaterialResp.getBatchSn() != null ? bindMaterialResp.getBatchSn() : "";
|
|
|
+ rows[i][2] = bindMaterialResp.getLastTimes() != null ? bindMaterialResp.getLastTimes() : "";
|
|
|
+ rows[i][3] = "";
|
|
|
+ rows[i][4] = bindMaterialResp.getCraft();
|
|
|
+ rows[i][5] = bindMaterialResp.getMaterialId();
|
|
|
+ rows[i][6] = bindMaterialResp.getType();
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ return rows;
|
|
|
+ }
|
|
|
|
|
|
+ public static void getMaterailData(){
|
|
|
+ rowData = buildMaterialRowData();
|
|
|
+ bindBatchPanel();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void updateMaterailData(){
|
|
|
+ rowData = buildMaterialRowData();
|
|
|
+ if(MesClient.table != null){
|
|
|
+ MesClient.table.setModel(new javax.swing.table.DefaultTableModel(rowData, columnNames){
|
|
|
+ public boolean isCellEditable(int row, int column) {
|
|
|
+ return column == 3;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ MesClient.table.getColumnModel().getColumn(3).setCellRenderer(new TableCellRendererButton());
|
|
|
+ MesClient.table.getColumnModel().getColumn(3).setCellEditor(new TableCellEditorButton());
|
|
|
+ MesClient.table.revalidate();
|
|
|
MesClient.table.repaint();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 绑定物料批次码
|
|
|
- public static void scanBatchSn(BindMaterialResp bindMaterialResp) { // 扫码类型
|
|
|
- //弹窗扫工件码
|
|
|
- String scanBarcodeTitle = "请扫物料:"+bindMaterialResp.getMaterialTitle();
|
|
|
+ // 绑定物料批次码(A/B 共用,扫码一次同步绑定各面工位)
|
|
|
+ public static void scanBatchSn(BindMaterialResp bindMaterialResp) {
|
|
|
+ String scanBarcodeTitle = "请扫物料:" + bindMaterialResp.getMaterialTitle();
|
|
|
String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
|
|
|
if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")) {
|
|
|
+ String[] oprnos = getMaterialOprnos();
|
|
|
+ if(oprnos.length == 0){
|
|
|
+ MesClient.setMenuStatus("工位配置异常,请检查 config.properties", -1);
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- JSONObject retObj = DataUtil.saveBindMaterail(scanBarcode,bindMaterialResp.getCraft(),bindMaterialResp.getMaterialId(),bindMaterialResp.getType());
|
|
|
- if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
|
|
|
- MesClient.setMenuStatus("扫物料:"+bindMaterialResp.getMaterialTitle()+"成功",0);
|
|
|
- updateMaterailData();
|
|
|
- }else{
|
|
|
- if(retObj.get("result")==null){
|
|
|
- MesClient.setMenuStatus("请求失败,请重试",-1);
|
|
|
- }else{
|
|
|
- if(retObj.get("result").toString().equalsIgnoreCase("false")){
|
|
|
- MesClient.setMenuStatus(retObj.getString("message"),-1);
|
|
|
+ String failOprno = null;
|
|
|
+ String failMsg = null;
|
|
|
+ for(String oprno : oprnos){
|
|
|
+ JSONObject retObj = DataUtil.saveBindMaterail(
|
|
|
+ scanBarcode,
|
|
|
+ bindMaterialResp.getCraft(),
|
|
|
+ bindMaterialResp.getMaterialId(),
|
|
|
+ bindMaterialResp.getType(),
|
|
|
+ oprno.trim());
|
|
|
+ if(retObj == null || retObj.get("result") == null){
|
|
|
+ failOprno = oprno;
|
|
|
+ failMsg = "请求失败,请重试";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if(!retObj.get("result").toString().equalsIgnoreCase("true")){
|
|
|
+ failOprno = oprno;
|
|
|
+ failMsg = retObj.getString("message");
|
|
|
+ if(failMsg == null || failMsg.isEmpty()){
|
|
|
+ failMsg = "绑定失败";
|
|
|
}
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ if(failOprno == null){
|
|
|
+ MesClient.setMenuStatus("扫物料:" + bindMaterialResp.getMaterialTitle() + "成功(A/B共用)", 0);
|
|
|
+ updateMaterailData();
|
|
|
+ }else if(oprnos.length > 1){
|
|
|
+ MesClient.setMenuStatus(failOprno + "绑定失败:" + failMsg, -1);
|
|
|
+ updateMaterailData();
|
|
|
+ }else{
|
|
|
+ MesClient.setMenuStatus(failMsg, -1);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|