소스 검색

添加日志

sunxianglong 6 일 전
부모
커밋
6298515e9c
1개의 변경된 파일63개의 추가작업 그리고 13개의 파일을 삭제
  1. 63 13
      src/com/mes/ui/MesClient.java

+ 63 - 13
src/com/mes/ui/MesClient.java

@@ -10,6 +10,8 @@ import com.mes.netty.NettyClient;
 import com.mes.util.DateLocalUtils;
 import com.mes.util.JdbcUtils;
 import javafx.embed.swing.JFXPanel;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import javax.swing.*;
 import javax.swing.border.EmptyBorder;
@@ -33,6 +35,8 @@ import java.util.concurrent.Executors;
 
 public class MesClient extends JFrame {
 
+    private static final Logger log = LoggerFactory.getLogger(MesClient.class);
+
     private static String Drivde = "org.sqlite.JDBC";
 
     public static int mes_auth = 0; // 权限级别 0=无权限 1=操作工人 2=管理员
@@ -171,6 +175,7 @@ public class MesClient extends JFrame {
 
                     deviceOnline();
                 }catch (Exception e){
+                    log.error("系统初始化异常: ", e);
                     e.printStackTrace();
                 }
             }
@@ -194,6 +199,7 @@ public class MesClient extends JFrame {
                         }
                     }
                 }catch (Exception e){
+                    log.error("设备启动监控异常: ", e);
                     e.printStackTrace();
                 }
             }
@@ -217,7 +223,8 @@ public class MesClient extends JFrame {
 
         mes_gw_des = OprnoUtil.getGwDes(mes_line_sn,mes_gw);
 
-        System.out.println(mes_gw + ";" + mes_gw_des + ";" + mes_server_ip + ";" + mes_tcp_port + ";" + mes_heart_beat_cycle);
+        log.info("加载配置: gw={}, gw_des={}, server_ip={}, tcp_port={}, heart_beat_cycle={}",
+                mes_gw, mes_gw_des, mes_server_ip, mes_tcp_port, mes_heart_beat_cycle);
     }
 
     public static void getPlcParam() {
@@ -294,18 +301,25 @@ public class MesClient extends JFrame {
             public void run() {
                 try{
                     List<ProdReq> prods = JdbcUtils.getProds();
-                    System.out.println("prods:"+ JSON.toJSONString(prods));
+                    log.info("【参数定时上传】获取到待同步的生产数据,记录数: {}", prods.size());
                     if(prods.size() > 0){
+                        log.debug("【参数定时上传】请求数据详情: {}", JSON.toJSONString(prods));
                         // 定时上传参数
                         JSONObject retObj = DataUtil.upParams(JSON.toJSONString(prods));
+                        log.info("【参数定时上传】服务端返回结果: {}", retObj != null ? retObj.toJSONString() : "null");
+
                         if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
                             // 更新sqlite已同步
                             for(ProdReq prodReq:prods){
                                 JdbcUtils.updateProdSync(prodReq.getId(),1);
                             }
+                            log.info("【参数定时上传】本地 SQLite 状态更新完成");
+                        } else {
+                            log.warn("【参数定时上传】接口返回非 true,未更新本地状态");
                         }
                     }
                 }catch (Exception e){
+                    log.error("【参数定时上传】发生异常: ", e);
                     e.printStackTrace();
                 }
             }
@@ -326,7 +340,7 @@ public class MesClient extends JFrame {
                 DataUtil.synrTcp(nettyClient,mes_gw);
             }
         } catch (Exception e) {
-            // TODO Auto-generated catch block
+            log.error("初始化TCP连接异常: ", e);
             e.printStackTrace();
         }
     }
@@ -343,7 +357,6 @@ public class MesClient extends JFrame {
         heartBeatTimer.schedule(new TimerTask() {
             public void run() {
                 if(nettyClient!=null&&tcp_connect_flag) {
-                    //System.out.println("发送心跳报文");
                     DataUtil.heartBeat(nettyClient,mes_gw);
 
                     heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
@@ -375,10 +388,9 @@ public class MesClient extends JFrame {
 
                     //若未连接则尝试连接
                     if(nettyClient!=null&&!tcp_connect_flag){
-                        System.out.println("TCP已断开");
+                        log.warn("TCP已断开,尝试重新连接");
                         //TCP重新同步连接
                         if(!connect_request_flag) {
-                            //System.out.println("TCP重新同步连接");
                             //设置TCP请求状态,只重新同步连接一次
                             connect_request_flag = true;
 
@@ -409,6 +421,7 @@ public class MesClient extends JFrame {
     }
 
     public static void resetScanA() {
+        log.info("【系统操作】执行产品及面板状态重置 (resetScanA)");
         work_status = 0;
         check_quality_result = false;
         MesClient.finish_ok_bt.setEnabled(false);
@@ -541,7 +554,10 @@ public class MesClient extends JFrame {
             }
 
             // 查询工件质量
+            log.info("【质量检查-扫码触发】准备发送扫码质量询问报文, SN: {}, User: {}", barcode36, user20);
             Boolean sendret = DataUtil.checkQuality(nettyClient,barcode36,user20);
+            log.info("【质量检查-扫码触发】请求发送结果: {}", sendret);
+
             if(!sendret){
                 JOptionPane.showMessageDialog(mesClientFrame,"消息发送失败,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
                 return;
@@ -553,6 +569,7 @@ public class MesClient extends JFrame {
     }
 
     public static void logoff() {
+        log.info("【系统操作】用户执行退出登录 (logoff)");
 //        welcomeWin.setVisible(true);
         mesClientFrame.setVisible(false);
 
@@ -607,8 +624,11 @@ public class MesClient extends JFrame {
             @Override
             public void mousePressed(MouseEvent e) {
                 super.mouseClicked(e);
+                log.info("【系统设置】用户点击了 [重连MES] 菜单");
                 //重连mes
-                nettyClient.future.channel().close();
+                if(nettyClient != null && nettyClient.future != null && nettyClient.future.channel() != null) {
+                    nettyClient.future.channel().close();
+                }
             }
         });
         settingMenu.add(resetTcpMenu);
@@ -620,6 +640,7 @@ public class MesClient extends JFrame {
             @Override
             public void mousePressed(MouseEvent e) {
                 super.mouseClicked(e);
+                log.info("【系统设置】用户点击了 [刷新工件] 菜单");
                 resetScanA();
             }
         });
@@ -717,6 +738,7 @@ public class MesClient extends JFrame {
         f_scan_data_bt_1 = new JButton("扫码");
         f_scan_data_bt_1.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
+                log.info("【总控操作】点击了 [扫码(工件)] 按钮");
                 scan_type = 1;
                 scanBarcode();
             }
@@ -752,6 +774,7 @@ public class MesClient extends JFrame {
 
 //                scanBarcodeLb();
 //                scan_type = 1;
+                log.info("【总控操作】点击了 [扫码(冷板)] 按钮");
                 if (product_sn.getText().isEmpty()){
                     setMenuStatus("请在工件上料完成后扫码!",1);
                     return;
@@ -774,6 +797,7 @@ public class MesClient extends JFrame {
         finish_ok_bt.setEnabled(false);
         finish_ok_bt.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
+                log.info("【总控操作】点击了 [OK] 按钮,当前产品SN: {}, 操作用户: {}", product_sn.getText(), user_menu.getText());
                 if(work_status == 1 && check_quality_result){
                     if (product_sn_lb.getText().equals("")){
                         JOptionPane.showMessageDialog(MesClient.mesClientFrame,"请绑定冷板码","提示窗口", JOptionPane.INFORMATION_MESSAGE);
@@ -783,7 +807,9 @@ public class MesClient extends JFrame {
                     getUser();
 
                     String qret = "OK";
+                    log.info("【判定上传】准备发送质量判定结果, SN: {}, 结果: {}", sn, qret);
                     Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20);
+                    log.info("【判定上传】发送结果: {}", sendret);
                     if(!sendret){
                         MesClient.setMenuStatus("消息发送失败,请重试",-1);
 //                        JOptionPane.showMessageDialog(mesClientFrame,"消息发送失败,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
@@ -803,12 +829,15 @@ public class MesClient extends JFrame {
         finish_ng_bt.setEnabled(false);
         finish_ng_bt.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
+                log.info("【总控操作】点击了 [NG] 按钮,当前产品SN: {}, 操作用户: {}", product_sn.getText(), user_menu.getText());
                 if(work_status == 1 && check_quality_result){
 
                     String sn = getBarcode(product_sn.getText());
                     getUser();
                     String qret = "NG";
+                    log.info("【判定上传】准备发送质量判定结果, SN: {}, 结果: {}", sn, qret);
                     Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20);
+                    log.info("【判定上传】发送结果: {}", sendret);
                     if(!sendret){
                         MesClient.setMenuStatus("消息发送失败,请重试",-1);
 //                        JOptionPane.showMessageDialog(mesClientFrame,"消息发送失败,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
@@ -903,8 +932,12 @@ public class MesClient extends JFrame {
         resetResultA = new JButton("重拉");
         resetResultA.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
+                log.info("【A枪操作】点击了 [重拉] 按钮,当前产品SN: {}", product_sn.getText());
                 if(zdStatusA == 1){
+                    log.info("【NG审核检查】准备校验 A枪 NG中断数据, SN: {}", product_sn.getText());
                     JSONObject retObj = DataUtil.checkNgData(product_sn.getText(),"A");
+                    log.info("【NG审核检查】校验返回结果: {}", retObj != null ? retObj.toJSONString() : "null");
+
                     if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
                         MesClient.zdStatusA = 0;
                         MesClient.resetResultA.setEnabled(false);
@@ -936,8 +969,12 @@ public class MesClient extends JFrame {
         okResultA = new JButton("OK");
         okResultA.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
+                log.info("【A枪操作】点击了 [OK] 按钮,当前产品SN: {}", product_sn.getText());
                 if(zdStatusA == 1){
+                    log.info("【NG审核检查】准备校验 A枪 NG中断数据, SN: {}", product_sn.getText());
                     JSONObject retObj = DataUtil.checkNgData(product_sn.getText(),"A");
+                    log.info("【NG审核检查】校验返回结果: {}", retObj != null ? retObj.toJSONString() : "null");
+
                     if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
 //                        if(!MesClient.product_sn.getText().isEmpty()){
 //
@@ -973,8 +1010,12 @@ public class MesClient extends JFrame {
         ngResultA = new JButton("NG");
         ngResultA.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
+                log.info("【A枪操作】点击了 [NG] 按钮,当前产品SN: {}", product_sn.getText());
                 if(zdStatusA == 1){
+                    log.info("【NG审核检查】准备校验 A枪 NG中断数据, SN: {}", product_sn.getText());
                     JSONObject retObj = DataUtil.checkNgData(product_sn.getText(),"A");
+                    log.info("【NG审核检查】校验返回结果: {}", retObj != null ? retObj.toJSONString() : "null");
+
                     if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
                         if(!MesClient.product_sn.getText().isEmpty()){
                             JdbcUtils.insertProdData(MesClient.mes_gw, MesClient.mes_line_sn, MesClient.product_sn.getText(),"A",foutA,soutA,fminA,sminA,fmaxA,smaxA,"0",curA+"", MesClient.user_menu.getText());
@@ -1008,7 +1049,7 @@ public class MesClient extends JFrame {
         tabbedPane.addTab("工作面板", new ImageIcon(MesClient.class.getResource("/bg/a_side.png")), indexScrollPaneA, null);
         tabbedPane.setEnabledAt(0, true);
 
-//		searchScrollPane = new JScrollPane((Component) null);
+//     searchScrollPane = new JScrollPane((Component) null);
 
         indexPanelC = new JPanel();
         searchScrollPaneDj = new JScrollPane(indexPanelC);
@@ -1021,10 +1062,10 @@ public class MesClient extends JFrame {
         searchScrollPane = new JScrollPane(indexPanelB);
         indexPanelB.setLayout(null);
 
-//		tabbedPane.addTab("工作记录", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPane, null);
+//     tabbedPane.addTab("工作记录", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPane, null);
 
 
-		tabbedPane.addChangeListener(new ChangeListener() {
+        tabbedPane.addChangeListener(new ChangeListener() {
             @Override
             public void stateChanged(ChangeEvent e) {
                 JTabbedPane tabbedPane = (JTabbedPane) e.getSource();
@@ -1064,14 +1105,17 @@ public class MesClient extends JFrame {
     // 获取开班点检状态
     public static void getCheckResult(){
         try{
+            log.info("【开班点检】准备获取点检状态...");
             JSONObject retObj = DataUtil.getCheckResult();
+            log.info("【开班点检】获取结果: {}", retObj != null ? retObj.toJSONString() : "null");
+
             if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) { // 已点检
                 MesClient.checkState = true;
             }else{ // 未点检
                 MesClient.checkState = false;
             }
         }catch (Exception e){
-            e.printStackTrace();
+            log.error("【开班点检】获取点检状态异常: ", e);
             MesClient.checkState = false;
         }
         MesClient.formatDeviceState();
@@ -1164,7 +1208,10 @@ public class MesClient extends JFrame {
         String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
         if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")) {
 
+            log.info("【物料绑定】扫描物料: {}, 批次码: {}", bindMaterialResp.getMaterialTitle(), scanBarcode);
             JSONObject retObj = DataUtil.saveBindMaterail(scanBarcode,bindMaterialResp.getCraft(),bindMaterialResp.getMaterialId(),bindMaterialResp.getType());
+            log.info("【物料绑定】返回结果: {}", retObj != null ? retObj.toJSONString() : "null");
+
             if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
                 MesClient.setMenuStatus("扫物料:"+bindMaterialResp.getMaterialTitle()+"成功",0);
                 updateMaterailData();
@@ -1226,7 +1273,7 @@ public class MesClient extends JFrame {
             //获取用户
             getUser();
             //获取扫码内容36位
-            String barcode36 = getBarcode(scanBarcode);//处理36为码
+            String warehouseSn = getBarcode(scanBarcode);//处理36为码
             //工位号
             String gw = "";
             product_sn_lb.setText(scanBarcode);
@@ -1238,10 +1285,13 @@ public class MesClient extends JFrame {
                 // 检查工件质量
                 if(work_status == 1) {
                     // 直接调用绑定
-                    String warehouseSn = getBarcode(product_sn_lb.getText());
                     String sn = getBarcode(product_sn.getText());
                     getUser();
+
+                    log.info("【冷板绑定】准备调用绑定接口, SN: {}, 冷板码: {}", sn, warehouseSn);
                     JSONObject retObj = DataUtil.bindWarehouse(sn, warehouseSn, user20, "400006");
+                    log.info("【冷板绑定】绑定返回结果: {}", retObj != null ? retObj.toJSONString() : "null");
+
                     if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
                         MesClient.setMenuStatus("绑定成功",0);
                     }else{