Selaa lähdekoodia

打码:工作面板新增产品选择,按所选产品取长码并保持

  - 工作面板新增产品PN下拉(195/196/198)
  - 选择结果保存在本机,重启或换班后自动沿用
  - 每次向 MES 取码时带上当前产品,MES 按产品下发对应长码
  - 切换产品后下一件即生效,无需重启
wangxichen 1 päivä sitten
vanhempi
commit
6cbdaadb30

+ 3 - 2
src/com/mes/ui/DataUtil.java

@@ -168,7 +168,8 @@ public class DataUtil {
         }
     }
 
-    public static JSONObject getHmbContent(String user){
+    // pn:产品PN号(195/196/198),决定长码前缀
+    public static JSONObject getHmbContent(String user, String pn){
         try{
             String enconding = "UTF-8";
             InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
@@ -179,7 +180,7 @@ public class DataUtil {
             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/mesProductHmb/getContent";
-            String params = "__ajax=json&oprno="+oprno+"&lineSn="+lineSn+"&ucode="+user;
+            String params = "__ajax=json&oprno="+oprno+"&lineSn="+lineSn+"&pn="+pn+"&ucode="+user;
             log.info("params="+params);
             String result = doPost(url,params);
             log.info("result="+result);

+ 35 - 2
src/com/mes/ui/MesClient.java

@@ -64,6 +64,11 @@ public class MesClient extends JFrame {
 
     public static String user20 = "";
 
+    // 产品PN号(195/196/198),决定长码前缀 F95621032519X
+    public static final String[] PN_LIST = {"195", "196", "198"};
+    public static JComboBox<String> pnCombo;
+    public static String pnCacheKey = "pn_";
+
     public static JFrame welcomeWin;
 
 //    public static JPanel indexPanelB;
@@ -95,12 +100,13 @@ public class MesClient extends JFrame {
                         //读文件配置
                         readProperty();
 
+                        // 先连本地库,界面初始化时读取产品PN缓存
+                        JdbcUtils.getConn();
+
                         // 显示界面
                         mesClientFrame = new MesClient();
                         mesClientFrame.setVisible(false);
 
-                        JdbcUtils.getConn();
-
                         welcomeWin = new LoginFarme();
                         welcomeWin.setVisible(true);
 
@@ -140,6 +146,7 @@ public class MesClient extends JFrame {
         mes_server_ip = pro.getProperty("mes.server_ip");
         mes_line_sn = pro.getProperty("mes.line_sn");
         mes_gw_des = OprnoUtil.getGwDes(mes_line_sn,mes_gw);
+        pnCacheKey = "pn_" + mes_gw; // 产品PN按工位缓存
         log.info(mes_gw + ";" + mes_gw_des + ";" + mes_server_ip + ";");
     }
 
@@ -222,6 +229,11 @@ public class MesClient extends JFrame {
 
     }
 
+    // 当前选中的产品PN号,未选择时默认195
+    public static String getPn() {
+        return pnCombo == null ? PN_LIST[0] : String.valueOf(pnCombo.getSelectedItem());
+    }
+
     //获取用户20位
     public static void getUser() {
         user20 = user_menu.getText().toString();
@@ -468,6 +480,27 @@ public class MesClient extends JFrame {
         indexPanelA.add(product_sn);
         product_sn.setColumns(10);
 
+        // 产品PN选择:决定长码前缀,选择后存本地,重启保持
+        JLabel pnLabel = new JLabel("产品PN:");
+        pnLabel.setFont(new Font("微软雅黑", Font.PLAIN, 20));
+        pnLabel.setBounds(81, 15, 100, 40);
+        indexPanelA.add(pnLabel);
+
+        pnCombo = new JComboBox<>(PN_LIST);
+        pnCombo.setFont(new Font("微软雅黑", Font.PLAIN, 20));
+        pnCombo.setBounds(185, 15, 140, 40);
+        String cachePn = JdbcUtils.getCacheValue(pnCacheKey);
+        pnCombo.setSelectedItem(cachePn.isEmpty() ? PN_LIST[0] : cachePn);
+        pnCombo.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                String pn = getPn();
+                JdbcUtils.setCacheValue(pnCacheKey, pn);
+                setMenuStatus("当前产品:" + pn, 0);
+                log.info("切换产品PN: {}", pn);
+            }
+        });
+        indexPanelA.add(pnCombo);
+
         f_scan_data_bt_1 = new JButton("扫码");
         f_scan_data_bt_1.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {

+ 1 - 1
src/com/mes/ui/OprnoUtil.java

@@ -18,7 +18,7 @@ public class OprnoUtil {
     public static String[] xtoprnodes = new String[]{
             "底板预拼+打码", "底板反面FSW", "底板反面打磨", "底板正面FSW", "CNC侧铣", "干冰清洁",
             "封板预装+点焊", "封板正面FSW", "封板正面打磨", "封板反面FSW", "TIG手工焊", "打磨",
-            "检漏一序", "前膨胀梁打码", "预拼锁付", "弧焊一序", "弧焊二序", "TIG手工焊",
+            "检漏一序", "膨胀梁打码", "预拼锁付", "弧焊一序", "弧焊二序", "TIG手工焊",
             "打磨", "总成正面CNC", "总成反面CNC", "吹铝屑+刮毛刺+清洁", "检漏二序", "拉铆",
             "箱体气密一序", "水道气密一序", "人工清洁", "螺套安装", "抽芯拉铆", "支架安装",
             "白件GP12", "检具", "喷粉前打包", "氦检", "箱体气密二序", "总成清洁",

+ 6 - 1
src/com/mes/ui/PlcUtil.java

@@ -50,7 +50,12 @@ public class PlcUtil {
         Boolean feeding = getFeeding(s7PLC);
         if (feeding && MesClient.dateLoading == 0){
             MesClient.dateLoading = 1;
-            JSONObject retObj = DataUtil.getHmbContent(MesClient.user_menu.getText().trim());
+            JSONObject retObj = DataUtil.getHmbContent(MesClient.user_menu.getText().trim(), MesClient.getPn());
+            if(retObj == null){
+                MesClient.setMenuStatus("请求失败,请重试",-1);
+                MesClient.dateLoading = 0;
+                return;
+            }
             if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
                 String hmb = retObj.getString("data");
                 setQrcode(s7PLC,hmb);

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

@@ -5,6 +5,8 @@ import org.slf4j.LoggerFactory;
 
 import java.sql.Connection;
 import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
 
@@ -77,8 +79,57 @@ public class JdbcUtils {
 				")";
 		statement.executeUpdate(submitRecord);
 
+		// 本地配置缓存表(如产品PN号,选择后保持)
+		String cache = "CREATE TABLE if not exists cache("
+				+ "id INTEGER PRIMARY KEY AUTOINCREMENT,"
+				+ "sn VARCHAR(20),"
+				+ "content VARCHAR(3000),"
+				+ "record_time DATETIME,"
+				+ "UNIQUE (sn))";
+		statement.executeUpdate(cache);
+
         statement.close();
     }
+
+	// 读取本地缓存,不存在返回空串
+	public static synchronized String getCacheValue(String key) {
+		String content = "";
+		try {
+			if (conn == null || conn.isClosed()) {
+				getConn();
+			}
+			PreparedStatement ps = conn.prepareStatement("select content from cache where sn = ? order by id asc limit 1");
+			ps.setString(1, key);
+			ResultSet rs = ps.executeQuery();
+			if (rs.next()) {
+				content = rs.getString(1);
+			}
+			rs.close();
+			ps.close();
+		} catch (Exception e) {
+			log.info("读取本地缓存失败: {}", e.getMessage());
+		}
+		return content == null ? "" : content;
+	}
+
+	// 写入本地缓存,已存在则覆盖
+	public static synchronized boolean setCacheValue(String key, String value) {
+		try {
+			if (conn == null || conn.isClosed()) {
+				getConn();
+			}
+			PreparedStatement ps = conn.prepareStatement("INSERT OR REPLACE INTO cache (sn, content, record_time) VALUES (?,?,?)");
+			ps.setString(1, key);
+			ps.setString(2, value);
+			ps.setString(3, DateLocalUtils.getCurrentTime());
+			ps.executeUpdate();
+			ps.close();
+			return true;
+		} catch (Exception e) {
+			log.info("写入本地缓存失败: {}", e.getMessage());
+			return false;
+		}
+	}
     
     //插入数据
     public static boolean insertData(String gw, String gy, String bw, String message_type, String sn) {