|
|
@@ -101,6 +101,30 @@ public class MesClient extends JFrame {
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
+ // 设置全局异常处理器,防止程序突然崩溃
|
|
|
+ Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
|
|
|
+ @Override
|
|
|
+ public void uncaughtException(Thread t, Throwable e) {
|
|
|
+ System.err.println("=== 捕获到未处理的异常 ===");
|
|
|
+ System.err.println("线程: " + t.getName());
|
|
|
+ System.err.println("异常信息: " + e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
+
|
|
|
+ // 显示错误对话框
|
|
|
+ SwingUtilities.invokeLater(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ JOptionPane.showMessageDialog(
|
|
|
+ mesClientFrame,
|
|
|
+ "程序发生错误:\n" + e.getMessage(),
|
|
|
+ "错误",
|
|
|
+ JOptionPane.ERROR_MESSAGE
|
|
|
+ );
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
EventQueue.invokeLater(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
@@ -134,7 +158,14 @@ public class MesClient extends JFrame {
|
|
|
startSubmitCheckTimer();
|
|
|
|
|
|
}catch (Exception e){
|
|
|
+ System.err.println("=== 初始化过程中发生异常 ===");
|
|
|
e.printStackTrace();
|
|
|
+ JOptionPane.showMessageDialog(
|
|
|
+ null,
|
|
|
+ "程序初始化失败:\n" + e.getMessage(),
|
|
|
+ "错误",
|
|
|
+ JOptionPane.ERROR_MESSAGE
|
|
|
+ );
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
@@ -143,6 +174,11 @@ public class MesClient extends JFrame {
|
|
|
public static void initGunPanels() {
|
|
|
gunPanels.clear();
|
|
|
|
|
|
+ // 清空容器中的所有组件,防止重复添加
|
|
|
+ if (gunPanelContainer != null) {
|
|
|
+ gunPanelContainer.removeAll();
|
|
|
+ }
|
|
|
+
|
|
|
System.out.println("initGunPanels - gunPanelContainer: " + gunPanelContainer);
|
|
|
|
|
|
List<YgslConfig> configs = JdbcUtils.getEnabledYgslConfigs();
|
|
|
@@ -159,8 +195,6 @@ public class MesClient extends JFrame {
|
|
|
|
|
|
if (gunPanelContainer != null) {
|
|
|
gunPanelContainer.add(gunPanel);
|
|
|
- gunPanelContainer.revalidate();
|
|
|
- gunPanelContainer.repaint();
|
|
|
gunPanel.connect();
|
|
|
System.out.println("已添加枪到容器: " + config.getGunName());
|
|
|
} else {
|
|
|
@@ -168,6 +202,12 @@ public class MesClient extends JFrame {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 刷新容器显示
|
|
|
+ if (gunPanelContainer != null) {
|
|
|
+ gunPanelContainer.revalidate();
|
|
|
+ gunPanelContainer.repaint();
|
|
|
+ }
|
|
|
+
|
|
|
System.out.println("已加载 " + gunPanels.size() + " 把扭力枪");
|
|
|
}
|
|
|
|
|
|
@@ -179,7 +219,12 @@ public class MesClient extends JFrame {
|
|
|
submitCheckTimer.schedule(new TimerTask() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
- checkAllGunsCompleted();
|
|
|
+ try {
|
|
|
+ checkAllGunsCompleted();
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.err.println("=== submitCheckTimer定时任务异常 ===");
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
}
|
|
|
}, 1000, 1000);
|
|
|
}
|
|
|
@@ -272,11 +317,16 @@ public class MesClient extends JFrame {
|
|
|
heartBeatTimer = new java.util.Timer();
|
|
|
heartBeatTimer.schedule(new TimerTask() {
|
|
|
public void run() {
|
|
|
- if(nettyClient!=null&&tcp_connect_flag) {
|
|
|
- //System.out.println("发送心跳报文");
|
|
|
- DataUtil.heartBeat(nettyClient,mes_gw);
|
|
|
+ try {
|
|
|
+ if(nettyClient!=null&&tcp_connect_flag) {
|
|
|
+ //System.out.println("发送心跳报文");
|
|
|
+ DataUtil.heartBeat(nettyClient,mes_gw);
|
|
|
|
|
|
- heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
|
|
|
+ heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.err.println("=== 心跳发送异常 ===");
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
}, 100,mes_heart_beat_cycle*1000);
|
|
|
@@ -288,34 +338,39 @@ public class MesClient extends JFrame {
|
|
|
heartBeatIconTimer = new Timer();
|
|
|
heartBeatIconTimer.schedule(new TimerTask() {
|
|
|
public void run() {
|
|
|
- if(tcp_connect_flag) {
|
|
|
- if(iconREDFlag) {
|
|
|
- heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
|
|
|
- iconREDFlag = false;
|
|
|
- }else {
|
|
|
- heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
|
|
|
- iconREDFlag = true;
|
|
|
- }
|
|
|
- heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
|
|
|
- heart_beat_menu.repaint();
|
|
|
- }else {
|
|
|
- heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
|
|
|
- heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
|
|
|
- heart_beat_menu.repaint();
|
|
|
-
|
|
|
- //若未连接则尝试连接
|
|
|
- if(nettyClient!=null&&!tcp_connect_flag){
|
|
|
- System.out.println("TCP已断开");
|
|
|
- //TCP重新同步连接
|
|
|
- if(!connect_request_flag) {
|
|
|
- //System.out.println("TCP重新同步连接");
|
|
|
- //设置TCP请求状态,只重新同步连接一次
|
|
|
- connect_request_flag = true;
|
|
|
-
|
|
|
- DataUtil.synrTcp(nettyClient,mes_gw);
|
|
|
+ try {
|
|
|
+ if(tcp_connect_flag) {
|
|
|
+ if(iconREDFlag) {
|
|
|
+ heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
|
|
|
+ iconREDFlag = false;
|
|
|
+ }else {
|
|
|
+ heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
|
|
|
+ iconREDFlag = true;
|
|
|
}
|
|
|
+ heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
|
|
|
+ heart_beat_menu.repaint();
|
|
|
+ }else {
|
|
|
+ heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
|
|
|
+ heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
|
|
|
+ heart_beat_menu.repaint();
|
|
|
+
|
|
|
+ //若未连接则尝试连接
|
|
|
+ if(nettyClient!=null&&!tcp_connect_flag){
|
|
|
+ System.out.println("TCP已断开");
|
|
|
+ //TCP重新同步连接
|
|
|
+ if(!connect_request_flag) {
|
|
|
+ //System.out.println("TCP重新同步连接");
|
|
|
+ //设置TCP请求状态,只重新同步连接一次
|
|
|
+ connect_request_flag = true;
|
|
|
+
|
|
|
+ DataUtil.synrTcp(nettyClient,mes_gw);
|
|
|
+ }
|
|
|
|
|
|
+ }
|
|
|
}
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.err.println("=== 心跳图标更新异常 ===");
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
}, 100,mes_heart_icon_cycle*1000);
|
|
|
@@ -363,6 +418,7 @@ public class MesClient extends JFrame {
|
|
|
}
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
+ System.err.println("=== deviceOnline定时任务异常 ===");
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
@@ -383,7 +439,7 @@ public class MesClient extends JFrame {
|
|
|
if(prods.size() > 0){
|
|
|
// 定时上传参数
|
|
|
JSONObject retObj = DataUtil.upParams(JSON.toJSONString(prods));
|
|
|
- if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
|
|
|
+ if(retObj!=null && retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
|
|
|
// 更新sqlite已同步
|
|
|
for(YgslResp prodReq:prods){
|
|
|
JdbcUtils.updateSync(prodReq.getId(),1);
|
|
|
@@ -391,6 +447,7 @@ public class MesClient extends JFrame {
|
|
|
}
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
+ System.err.println("=== upParams定时任务异常 ===");
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
@@ -408,12 +465,13 @@ public class MesClient extends JFrame {
|
|
|
try{
|
|
|
if(work_status == 1 && mes_gw.equals("OP290") && pz_status == 0){
|
|
|
JSONObject retObj = DataUtil.checkpz(product_sn.getText());
|
|
|
- if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
|
|
|
+ if(retObj!=null && retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
|
|
|
pz_status = 1; // 已拍照
|
|
|
pzlabel.setVisible(true);
|
|
|
}
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
+ System.err.println("=== checkpz定时任务异常 ===");
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|