Преглед на файлове

联动OP040提交按钮

wangxichen преди 22 часа
родител
ревизия
e23bf56d14
променени са 4 файла, в които са добавени 120 реда и са изтрити 0 реда
  1. 30 0
      src/com/mes/ui/DataUtil.java
  2. 31 0
      src/com/mes/ui/MesClient.java
  3. 16 0
      src/com/mes/ui/MesRevice.java
  4. 43 0
      src/com/mes/util/JdbcUtils.java

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

@@ -142,6 +142,36 @@ public class DataUtil {
         }
     }
 
+    // OP040联动提交:GW固定OP040A,GY=100000,paramNums=00,无参数
+    public static Boolean sendQualityForOp040(NettyClient nettyClient,String sn,String ret,String user){
+        try{
+            String msgType = "MQDW";
+            String craft = "100000";
+            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 gw = "GW"+rightPad("OP040A", 6);
+            String start = "aaaabbbbbABW";
+            String gy = "GY" + rightPad(craft, 6);
+            String reslx = "LX" + rightPad("", 2);
+            String id = pro.getProperty("mes.line_sn") + rightPad(sn, 36);
+            String rs = "RS"+ rightPad(ret, 2);
+            String da = "DA" + DateLocalUtils.getCurrentDate();
+            String zt = "ZT" + DateLocalUtils.getCurrentTimeHMS();
+            String yh = "YH" + rightPad(user, 20);
+            String aqdw_str = start + msgType + gw + gy + reslx + id + rs + da + zt + yh + "00";
+            System.out.println("OP040 message="+aqdw_str);
+            JdbcUtils.insertData(gw, gy, aqdw_str, msgType, sn);
+            nettyClient.future.channel().writeAndFlush(aqdw_str);
+            return true;
+        }catch (Exception e){
+            e.printStackTrace();
+            return false;
+        }
+    }
+
     public static Boolean sendQuality2(String sn,String result,String user,String op){
         try{
             String msgType = "MQDW";

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

@@ -161,6 +161,8 @@ public class MesClient extends JFrame {
 
     public static String programNoB = "";
 
+    public static Boolean op040AutoSubmit = true; // OP040联动提交开关
+
     public static void main(String[] args) {
         if (LockUtil.getInstance().isAppActive() == true){
 //            JOptionPane.showMessageDialog(null, "已有一个程序在运行,程序退出");
@@ -176,6 +178,10 @@ public class MesClient extends JFrame {
 
                     JdbcUtils.getConn();
 
+                    // 从数据库加载OP040联动提交开关状态
+                    String op040Flag = JdbcUtils.getConfig("op040_auto_submit", "true");
+                    op040AutoSubmit = op040Flag.equals("true");
+
                     welcomeWin = new LoginFarme();
                     welcomeWin.setVisible(true);
 
@@ -652,6 +658,31 @@ public class MesClient extends JFrame {
         });
         settingMenu.add(resetTcpMenu_1_1sd);
 
+        JMenuItem op040SubmitMenu = new JMenuItem("OP040联动提交:" + (op040AutoSubmit ? "开" : "关"));
+        op040SubmitMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
+        op040SubmitMenu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
+        op040SubmitMenu.addMouseListener(new MouseAdapter() {
+            @Override
+            public void mousePressed(MouseEvent e) {
+                super.mouseClicked(e);
+                String pwd = JOptionPane.showInputDialog(mesClientFrame, "请输入密码");
+                if(pwd != null && pwd.equals("mes123")){
+                    op040AutoSubmit = !op040AutoSubmit;
+                    JdbcUtils.setConfig("op040_auto_submit", op040AutoSubmit ? "true" : "false");
+                    if(op040AutoSubmit){
+                        op040SubmitMenu.setText("OP040联动提交:开");
+                        MesClient.setMenuStatus("OP040联动提交已开启",0);
+                    }else{
+                        op040SubmitMenu.setText("OP040联动提交:关");
+                        MesClient.setMenuStatus("OP040联动提交已关闭",0);
+                    }
+                }else if(pwd != null){
+                    MesClient.setMenuStatus("密码错误",-1);
+                }
+            }
+        });
+        settingMenu.add(op040SubmitMenu);
+
         contentPane = new JPanel();
         contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
         setContentPane(contentPane);

+ 16 - 0
src/com/mes/ui/MesRevice.java

@@ -160,6 +160,22 @@ public class MesRevice {
                     MesClient.pxstatus1.setText("A:提交成功");
                     MesClient.resetScanA();
                 }
+
+                // OP040联动提交
+                if(MesClient.op040AutoSubmit){
+                    String oprno = ProtocolParam.getOprno(mes_msg).trim();
+                    // 只有OP060自身的提交成功才触发,避免OP040回复再次触发
+                    if(oprno.startsWith(MesClient.mes_gw)){
+                        MesClient.getUser();
+                        String barcode36 = MesClient.getBarcode(sn);
+                        Boolean op040ret = DataUtil.sendQualityForOp040(MesClient.nettyClient, barcode36, "OK", MesClient.user20);
+                        if(!op040ret){
+                            System.out.println("OP040联动提交发送失败");
+                        }else{
+                            System.out.println("OP040联动提交已发送");
+                        }
+                    }
+                }
             }else{
                 if(sn.equals(MesClient.product_sn2.getText())){
                     MesClient.pxstatus2.setText("B:提交失败");

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

@@ -79,6 +79,12 @@ public class JdbcUtils {
 				")";
 		statement.executeUpdate(submitRecord);
 
+		// 创建配置表
+		String sqlConfig = "CREATE TABLE if not exists sys_config("
+				+ "config_key VARCHAR(50) PRIMARY KEY,"
+				+ "config_value VARCHAR(200))";
+		statement.executeUpdate(sqlConfig);
+
         statement.close();
     }
     
@@ -244,6 +250,43 @@ public class JdbcUtils {
             e.printStackTrace();
         }
     }
+
+    // 读取配置项,不存在返回defaultValue
+    public static String getConfig(String key, String defaultValue){
+        try{
+            if(conn == null || conn.isClosed()){
+                openConnection();
+            }
+            Statement statement = conn.createStatement();
+            ResultSet rs = statement.executeQuery("SELECT config_value FROM sys_config WHERE config_key = '"+key+"'");
+            if(rs.next()){
+                String val = rs.getString(1);
+                rs.close();
+                statement.close();
+                return val;
+            }
+            rs.close();
+            statement.close();
+        }catch(Exception e){
+            e.printStackTrace();
+        }
+        return defaultValue;
+    }
+
+    // 保存配置项(存在则更新,不存在则插入)
+    public static void setConfig(String key, String value){
+        try{
+            if(conn == null || conn.isClosed()){
+                openConnection();
+            }
+            Statement statement = conn.createStatement();
+            String sql = "INSERT OR REPLACE INTO sys_config (config_key, config_value) VALUES ('"+key+"','"+value+"')";
+            statement.executeUpdate(sql);
+            statement.close();
+        }catch(Exception e){
+            e.printStackTrace();
+        }
+    }
     
     
   //设备结构数据库