Przeglądaj źródła

增加NG中断功能

jingbo 1 dzień temu
rodzic
commit
4c0165a8e9

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

@@ -292,4 +292,59 @@ public class DataUtil {
         }
         return result;
     }
+
+    public static JSONObject addNgData(String sn,String pos) {
+        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/mesProductNg/addData";
+            String params = "__ajax=json&oprno="+oprno+"&lineSn="+lineSn+"&sn="+sn+"&pos="+pos;
+            System.out.println("url="+url);
+            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 checkNgData(String sn,String pos) {
+        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/mesProductNg/ngcheck";
+            String params = "__ajax=json&oprno="+oprno+"&lineSn="+lineSn+"&sn="+sn+"&pos="+pos;
+            System.out.println("url="+url);
+            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;
+        }
+    }
+
 }

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

@@ -107,6 +107,7 @@ public class MesClient extends JFrame {
 //    public static Short bSetNum = 27;
     public static Short sortB = 0;
     public static Short bMax = 0;
+    public static Short bFinish = 0;
     public static List<Map> blist = new ArrayList<>();
     public static Short deviceControl = 0; // 0=本地 1=远程
     public static Integer tjStatus = 0; // 1=提交失败
@@ -119,6 +120,35 @@ public class MesClient extends JFrame {
     public static Object[] columnNames = { "物料名称", "绑定批次", "剩余次数", "操作" };
     public static Object[][] rowData = null;
 
+
+
+    public static Integer zdStatusA = 0;
+    public static Integer zdStatusB = 0;
+
+    public static String foutA = "";
+    public static String fmaxA = "";
+    public static String fminA = "";
+    public static String soutA = "";
+    public static String smaxA = "";
+    public static String sminA = "";
+    public static String curA = "";
+
+    public static String foutB = "";
+    public static String fmaxB = "";
+    public static String fminB = "";
+    public static String soutB = "";
+    public static String smaxB = "";
+    public static String sminB = "";
+    public static String curB = "";
+
+
+    public static JButton resetResultA;
+    public static JButton okResultA;
+    public static JButton ngResultA;
+    public static JButton resetResultB;
+    public static JButton okResultB;
+    public static JButton ngResultB;
+
     public static void main(String[] args) {
         EventQueue.invokeLater(new Runnable() {
             @Override
@@ -412,6 +442,7 @@ public class MesClient extends JFrame {
         MesClient.aMax = 0;
         MesClient.bMax = 0;
         MesClient.aFinish = 0;
+        MesClient.bFinish = 0;
         MesClient.alist = new ArrayList<>();
         MesClient.blist = new ArrayList<>();
         MesClient.sortB = 0;
@@ -425,6 +456,13 @@ public class MesClient extends JFrame {
         if(deviceControl == 1){
 
         }
+        resetResultA.setEnabled(false);
+        okResultA.setEnabled(false);
+        ngResultA.setEnabled(false);
+
+        resetResultB.setEnabled(false);
+        okResultB.setEnabled(false);
+        ngResultB.setEnabled(false);
 
 //        plcA.writeCoil(3128,false);
 //        plcB.writeCoil(3128,false);
@@ -817,6 +855,222 @@ public class MesClient extends JFrame {
         param4.setBounds(608, 285, 83, 34);
         indexPanelA.add(param4);
 
+        resetResultA = new JButton("重拉");
+        resetResultA.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                if(zdStatusA == 1){
+                    JSONObject retObj = DataUtil.checkNgData(product_sn.getText(),"A");
+                    if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
+                        MesClient.zdStatusA = 0;
+                        MesClient.resetResultA.setEnabled(false);
+                        MesClient.okResultA.setEnabled(false);
+                        MesClient.ngResultA.setEnabled(false);
+                        MesClient.sortA = (short) (MesClient.sortA - 1);
+                        MesClient.param2.setText(MesClient.sortA+"");
+                        plcA.writeInt16(1136,MesClient.sortA);
+                        MesClient.foutA = "";
+                        MesClient.soutA = "";
+                        MesClient.fmaxA = "";
+                        MesClient.fminA = "";
+                        MesClient.smaxA = "";
+                        MesClient.sminA = "";
+                        MesClient.curA = "";
+                        ModbusUtil.setPowerOn(plcA);
+                    }else{
+                        MesClient.setMenuStatus("NG中断未审核",-1);
+                    }
+                }
+
+            }
+        });
+        resetResultA.setEnabled(false);
+        resetResultA.setFont(new Font("微软雅黑", Font.PLAIN, 16));
+        resetResultA.setBounds(52, 331, 100, 40);
+        indexPanelA.add(resetResultA);
+
+        okResultA = new JButton("OK");
+        okResultA.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                if(zdStatusA == 1){
+                    JSONObject retObj = DataUtil.checkNgData(product_sn.getText(),"A");
+                    if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
+                        if(!MesClient.product_sn.getText().isEmpty()){
+                            MesClient.aFinish++;
+                            JdbcUtils.insertProdData(MesClient.mes_gw, MesClient.mes_line_sn, MesClient.product_sn.getText(),"A",foutA,soutA,fminA,sminA,fmaxA,smaxA,"1",curA+"", MesClient.user_menu.getText());
+                        }
+                        MesClient.zdStatusA = 0;
+                        MesClient.resetResultA.setEnabled(false);
+                        MesClient.okResultA.setEnabled(false);
+                        MesClient.ngResultA.setEnabled(false);
+                        MesClient.foutA = "";
+                        MesClient.soutA = "";
+                        MesClient.fmaxA = "";
+                        MesClient.fminA = "";
+                        MesClient.smaxA = "";
+                        MesClient.sminA = "";
+                        MesClient.curA = "";
+
+                        ModbusUtil.upResult();
+                        ModbusUtil.setPowerOn(plcA);
+                    }else{
+                        MesClient.setMenuStatus("NG中断未审核",-1);
+                    }
+                }
+            }
+        });
+        okResultA.setEnabled(false);
+        okResultA.setForeground(new Color(0, 128, 0));
+        okResultA.setFont(new Font("微软雅黑", Font.PLAIN, 16));
+        okResultA.setBounds(176, 331, 100, 40);
+        indexPanelA.add(okResultA);
+
+        ngResultA = new JButton("NG");
+        ngResultA.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                if(zdStatusA == 1){
+                    JSONObject retObj = DataUtil.checkNgData(product_sn.getText(),"A");
+                    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());
+                        }
+                        MesClient.zdStatusA = 0;
+                        MesClient.resetResultA.setEnabled(false);
+                        MesClient.okResultA.setEnabled(false);
+                        MesClient.ngResultA.setEnabled(false);
+                        MesClient.foutA = "";
+                        MesClient.soutA = "";
+                        MesClient.fmaxA = "";
+                        MesClient.fminA = "";
+                        MesClient.smaxA = "";
+                        MesClient.sminA = "";
+                        MesClient.curA = "";
+                        ModbusUtil.upResult();
+                        ModbusUtil.setPowerOn(plcA);
+
+                    }else{
+                        MesClient.setMenuStatus("NG中断未审核",-1);
+                    }
+                }
+            }
+        });
+        ngResultA.setEnabled(false);
+        ngResultA.setForeground(new Color(255, 0, 0));
+        ngResultA.setFont(new Font("微软雅黑", Font.PLAIN, 16));
+        ngResultA.setBounds(303, 331, 100, 40);
+        indexPanelA.add(ngResultA);
+
+
+        resetResultB = new JButton("重拉");
+        resetResultB.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                if(zdStatusB == 1){
+                    JSONObject retObj = DataUtil.checkNgData(product_sn.getText(),"B");
+                    if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
+                        MesClient.zdStatusB = 0;
+                        MesClient.resetResultB.setEnabled(false);
+                        MesClient.okResultB.setEnabled(false);
+                        MesClient.ngResultB.setEnabled(false);
+                        MesClient.sortB = (short) (MesClient.sortB - 1);
+                        MesClient.param4.setText(MesClient.sortB+"");
+                        plcB.writeInt16(1136,MesClient.sortB);
+                        MesClient.foutB = "";
+                        MesClient.soutB = "";
+                        MesClient.fmaxB = "";
+                        MesClient.fminB = "";
+                        MesClient.smaxB = "";
+                        MesClient.sminB = "";
+                        MesClient.curB = "";
+                        ModbusUtil.setPowerOn(plcB);
+                    }else{
+                        MesClient.setMenuStatus("NG中断未审核",-1);
+                    }
+                }
+
+            }
+        });
+        resetResultB.setEnabled(false);
+        resetResultB.setFont(new Font("微软雅黑", Font.PLAIN, 16));
+        resetResultB.setBounds(595, 331, 100, 40);
+        indexPanelA.add(resetResultB);
+
+        okResultB = new JButton("OK");
+        okResultB.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                if(zdStatusB == 1){
+                    JSONObject retObj = DataUtil.checkNgData(product_sn.getText(),"B");
+                    if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
+                        if(!MesClient.product_sn.getText().isEmpty()){
+                            MesClient.bFinish++;
+                            JdbcUtils.insertProdData(MesClient.mes_gw, MesClient.mes_line_sn, MesClient.product_sn.getText(),"B",foutB,soutB,fminB,sminB,fmaxB,smaxB,"1",curB+"", MesClient.user_menu.getText());
+                        }
+                        MesClient.zdStatusB = 0;
+                        MesClient.resetResultB.setEnabled(false);
+                        MesClient.okResultB.setEnabled(false);
+                        MesClient.ngResultB.setEnabled(false);
+                        MesClient.foutB = "";
+                        MesClient.soutB = "";
+                        MesClient.fmaxB = "";
+                        MesClient.fminB = "";
+                        MesClient.smaxB = "";
+                        MesClient.sminB = "";
+                        MesClient.curB = "";
+                        ModbusUtil.setPowerOn(plcB);
+
+                        ModbusUtil.upResult();
+                    }else{
+                        MesClient.setMenuStatus("NG中断未审核",-1);
+                    }
+                }
+
+            }
+        });
+        okResultB.setEnabled(false);
+        okResultB.setForeground(new Color(0, 128, 0));
+        okResultB.setFont(new Font("微软雅黑", Font.PLAIN, 16));
+        okResultB.setBounds(718, 331, 100, 40);
+        indexPanelA.add(okResultB);
+
+        ngResultB = new JButton("NG");
+        ngResultB.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                if(zdStatusB == 1){
+                    JSONObject retObj = DataUtil.checkNgData(product_sn.getText(),"B");
+                    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(),"B",foutA,soutA,fminA,sminA,fmaxA,smaxA,"0",curA+"", MesClient.user_menu.getText());
+                        }
+                        MesClient.zdStatusB = 0;
+                        MesClient.resetResultB.setEnabled(false);
+                        MesClient.okResultB.setEnabled(false);
+                        MesClient.ngResultB.setEnabled(false);
+                        MesClient.foutB = "";
+                        MesClient.soutB = "";
+                        MesClient.fmaxB = "";
+                        MesClient.fminB = "";
+                        MesClient.smaxB = "";
+                        MesClient.sminB = "";
+                        MesClient.curB = "";
+                        ModbusUtil.setPowerOn(plcB);
+
+
+                        ModbusUtil.upResult();
+                    }else{
+                        MesClient.setMenuStatus("NG中断未审核",-1);
+                    }
+                }
+
+            }
+        });
+        ngResultB.setEnabled(false);
+        ngResultB.setForeground(Color.RED);
+        ngResultB.setFont(new Font("微软雅黑", Font.PLAIN, 16));
+        ngResultB.setBounds(839, 331, 100, 40);
+        indexPanelA.add(ngResultB);
+
+
+
+
+
         tabbedPane.addTab("工作面板", new ImageIcon(MesClient.class.getResource("/bg/a_side.png")), indexScrollPaneA, null);
         tabbedPane.setEnabledAt(0, true);
 

+ 83 - 8
src/com/mes/ui/ModbusUtil.java

@@ -32,7 +32,7 @@ public class ModbusUtil {
 
         if(MesClient.sortA == cur - 1){
             MesClient.sortA = cur;
-            MesClient.aFinish = plc.readInt16(1138);
+//            MesClient.aFinish = plc.readInt16(1138);
             String fout = plc.readInt16(1064)+"";
             String sout = (float)plc.readInt16(1065)/1000+"";
 
@@ -45,6 +45,40 @@ public class ModbusUtil {
             MesClient.param2.setText(cur+"");
             System.out.println("cur:"+cur);
 
+
+            String qty = "1";
+            if(Integer.valueOf(fout) < Integer.valueOf(fmin) || Integer.valueOf(fout) > Integer.valueOf(fmax)){
+                qty = "0";
+            }
+            if(Float.valueOf(sout) < Float.valueOf(smin) || Float.valueOf(sout) > Float.valueOf(smax)){
+                qty = "0";
+            }
+
+            if(qty.equals("0")){
+                MesClient.zdStatusA = 1;
+                MesClient.foutA = fout;
+                MesClient.soutA = sout;
+                MesClient.fmaxA = fmax;
+                MesClient.fminA = fmin;
+                MesClient.sminA = smin;
+                MesClient.smaxA = smax;
+                MesClient.curA = cur+"";
+                MesClient.resetResultA.setEnabled(true);
+                MesClient.okResultA.setEnabled(true);
+                MesClient.ngResultA.setEnabled(true);
+                ModbusUtil.setPowerOff(plc);
+
+                if(!MesClient.product_sn.getText().isEmpty()){
+                    JdbcUtils.insertProdData(MesClient.mes_gw, MesClient.mes_line_sn, MesClient.product_sn.getText(),"A",fout,sout,fmin,smin,fmax,smax,qty,cur+"", MesClient.user_menu.getText());
+                    DataUtil.addNgData(MesClient.product_sn.getText(),"A");
+                }
+            }
+            if(qty.equals("1") && !MesClient.product_sn.getText().isEmpty()){
+                MesClient.aFinish++;
+                JdbcUtils.insertProdData(MesClient.mes_gw, MesClient.mes_line_sn, MesClient.product_sn.getText(),"A",fout,sout,fmin,smin,fmax,smax,qty,cur+"", MesClient.user_menu.getText());
+            }
+
+
 //            拉铆中更换配方
             if(MesClient.sortA == 4){
 //                    plc.writeInt16(1070,(short) 2000);
@@ -52,12 +86,14 @@ public class ModbusUtil {
             }
 
 
-            if(!MesClient.product_sn.getText().isEmpty()){
-                JdbcUtils.insertProdData(MesClient.mes_gw, MesClient.mes_line_sn, MesClient.product_sn.getText(),"A",fout,sout,fmin,smin,fmax,smax,"1",cur+"", MesClient.user_menu.getText());
-            }
+//            if(!MesClient.product_sn.getText().isEmpty()){
+//                JdbcUtils.insertProdData(MesClient.mes_gw, MesClient.mes_line_sn, MesClient.product_sn.getText(),"A",fout,sout,fmin,smin,fmax,smax,"1",cur+"", MesClient.user_menu.getText());
+//            }
+        }
+        if (MesClient.zdStatusA == 1){
+            upResult();
         }
 
-        upResult();
     }
 
     public static void getDataB(ModbusTcp plc){
@@ -93,6 +129,36 @@ public class ModbusUtil {
             String fmax = plc.readInt16(1069)+"";
             String smax = (float)plc.readInt16(1071)/1000+"";
 
+            String qty = "1";
+            if(Integer.valueOf(fout) < Integer.valueOf(fmin) || Integer.valueOf(fout) > Integer.valueOf(fmax)){
+                qty = "0";
+            }
+            if(Float.valueOf(sout) < Float.valueOf(smin) || Float.valueOf(sout) > Float.valueOf(smax)){
+                qty = "0";
+            }
+
+            if(qty.equals("0")){
+                MesClient.zdStatusB = 1;
+                MesClient.foutB = fout;
+                MesClient.soutB = sout;
+                MesClient.fmaxB = fmax;
+                MesClient.fminB = fmin;
+                MesClient.sminB = smin;
+                MesClient.smaxB = smax;
+                MesClient.curB = cur+"";
+                MesClient.resetResultB.setEnabled(true);
+                MesClient.okResultB.setEnabled(true);
+                MesClient.ngResultB.setEnabled(true);
+
+                ModbusUtil.setPowerOff(MesClient.plcB);
+
+                if(!MesClient.product_sn.getText().isEmpty()){
+                    JdbcUtils.insertProdData(MesClient.mes_gw, MesClient.mes_line_sn, MesClient.product_sn.getText(),"B",fout,sout,fmin,smin,fmax,smax,qty,cur+"", MesClient.user_menu.getText());
+                    DataUtil.addNgData(MesClient.product_sn.getText(),"B");
+                }
+
+            }
+
             // 拉铆过程中更换配方
             if(MesClient.sortB == 18){
 //                plc.writeInt16(1070,(short) 4000);
@@ -103,12 +169,18 @@ public class ModbusUtil {
             MesClient.param4.setText(cur+"");
 
             System.out.println("cur:"+cur);
-            if(!MesClient.product_sn.getText().isEmpty()){
-               JdbcUtils.insertProdData(MesClient.mes_gw, MesClient.mes_line_sn, MesClient.product_sn.getText(),"B",fout,sout,fmin,smin,fmax,smax,"1",cur+"", MesClient.user_menu.getText());
+//            if(!MesClient.product_sn.getText().isEmpty()){
+//               JdbcUtils.insertProdData(MesClient.mes_gw, MesClient.mes_line_sn, MesClient.product_sn.getText(),"B",fout,sout,fmin,smin,fmax,smax,"1",cur+"", MesClient.user_menu.getText());
+//            }
+            if(qty.equals("1") &&!MesClient.product_sn.getText().isEmpty()){
+                MesClient.bFinish++;
+                JdbcUtils.insertProdData(MesClient.mes_gw, MesClient.mes_line_sn, MesClient.product_sn.getText(),"B",fout,sout,fmin,smin,fmax,smax,"1",cur+"", MesClient.user_menu.getText());
             }
         }
 
-        upResult();
+        if (MesClient.zdStatusB == 0){
+            upResult();
+        }
 
     }
 
@@ -125,6 +197,9 @@ public class ModbusUtil {
                 if(MesClient.aFinish != MesClient.aMax){
                     retf = "NG";
                 }
+                if (MesClient.bFinish != MesClient.bMax){
+                    retf = "NG";
+                }
                 Boolean ret = DataUtil.sendQuality(MesClient.nettyClient, MesClient.product_sn.getText(),retf, MesClient.user20);
                 if(!ret){
                     MesClient.setMenuStatus(MesClient.tjFlagTextErr,-1);