Parcourir la source

新增生产类型,智界和尚界

setting il y a 3 jours
Parent
commit
549bbc758c
4 fichiers modifiés avec 236 ajouts et 1 suppressions
  1. 11 0
      .project
  2. 1 1
      src/com/mes/ui/DataUtil.java
  3. 167 0
      src/com/mes/ui/MesClient.java
  4. 57 0
      src/com/mes/util/JdbcUtils.java

+ 11 - 0
.project

@@ -14,4 +14,15 @@
 	<natures>
 		<nature>org.eclipse.jdt.core.javanature</nature>
 	</natures>
+	<filteredResources>
+		<filter>
+			<id>1785720386937</id>
+			<name></name>
+			<type>30</type>
+			<matcher>
+				<id>org.eclipse.core.resources.regexFilterMatcher</id>
+				<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
+			</matcher>
+		</filter>
+	</filteredResources>
 </projectDescription>

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

@@ -25,7 +25,7 @@ public class DataUtil {
             String params = "__ajax=json&oprno="+oprno+"&lineSn="+lineSn+"&sn="+sn+"&ucode="+user;
             log.info("params="+params);
             String result = doPost(url,params);
-            log.info("result="+result);
+            log.info("result="+result); 
             if(result == null || result.trim().isEmpty() || result.equalsIgnoreCase("false")) {
                 return null;
             }else {

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

@@ -3,6 +3,7 @@ package com.mes.ui;
 import com.alibaba.fastjson2.JSONObject;
 import com.mes.component.MesRadio;
 import com.mes.component.MesWebView;
+import com.mes.component.ProductTypePanel;
 import com.mes.util.DateLocalUtils;
 import com.mes.util.HttpUtils;
 import com.mes.util.JdbcUtils;
@@ -90,6 +91,17 @@ public class MesClient extends JFrame {
     public static MesWebView jfxPanel2 = null;
     public static MesRadio mesRadioHj;
 
+    //新增字段
+    public static ProductTypePanel productTypePanel;
+    public static JLabel productTypeCurrentLabel;
+    public static final int PRODUCT_SN_LENGTH = 32;
+    public static final String PREFIX_ZJ = "000020021815-01000016";  //智界
+    public static final String PREFIX_SJ = "000020022029-01000016";  //尚界
+    public static final String PRODUCT_TYPE_SWITCH_PASSWORD = "503833";
+    public static final String PRODUCT_TYPE_ZJ = ProductTypePanel.TYPE_ZJ;
+    public static final String PRODUCT_TYPE_SJ = ProductTypePanel.TYPE_SJ;
+
+
     public static JTable table;
     public static Object[] columnNames = { "物料名称", "绑定批次", "剩余次数", "操作" };
     public static Object[][] rowData = null;
@@ -403,6 +415,7 @@ public class MesClient extends JFrame {
     }
 
     public static void initWarehouseData(){
+        loadProductTypeFromDb(); //新增
         resetScanA();
     }
 
@@ -811,6 +824,7 @@ public class MesClient extends JFrame {
         //弹窗扫工件码
         String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
         if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")) {
+            scanBarcode = scanBarcode.trim(); //生产类型新增
             //获取用户
             getUser();
             //获取扫码内容36位
@@ -825,6 +839,21 @@ public class MesClient extends JFrame {
             //刷新界面
             mesClientFrame.repaint();
 
+            //生产类型新增
+            String validateMsg = validateProductSnMessage(scanBarcode);
+            if (validateMsg != null) {
+                check_quality_result = false;
+                work_status = 0;
+                MesClient.finish_ok_bt.setEnabled(false);
+                MesClient.finish_ng_bt.setEnabled(false);
+                MesClient.f_scan_data_bt_1.setEnabled(true);
+                updateProductTypePanelEnabled(true);
+                MesClient.setMenuStatus(validateMsg, -1);
+
+                return;
+            }
+            updateProductTypePanelEnabled(false);
+
             // 查询工件质量
             JSONObject retObj = DataUtil.checkQuality(scanBarcode,user20);
             if(retObj == null){
@@ -1104,6 +1133,17 @@ public class MesClient extends JFrame {
         finish_ok_bt.setEnabled(false);
         finish_ok_bt.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
+                String sn = getBarcode(product_sn.getText());
+                if(sn.isEmpty()){
+                    MesClient.setMenuStatus("工件码为空,请重试",-1);
+                    return;
+                }
+                //生产类型新增
+                String validateMsg = validateProductSnMessage(sn);
+                if (validateMsg != null) {
+                    MesClient.setMenuStatus(validateMsg, -1);
+                    return;
+                }
                 manualSubmitQualityResult("OK");
             }
         });
@@ -1117,6 +1157,17 @@ public class MesClient extends JFrame {
         finish_ng_bt.setEnabled(false);
         finish_ng_bt.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
+                String sn = getBarcode(product_sn.getText());
+                if(sn.isEmpty()){
+                    MesClient.setMenuStatus("工件码为空,请重试",-1);
+                    return;
+                }
+
+                String validateMsg = validateProductSnMessage(sn);
+                if (validateMsg != null) {
+                    MesClient.setMenuStatus(validateMsg, -1);
+                    return;
+                }
                 manualSubmitQualityResult("NG");
             }
         });
@@ -1134,6 +1185,47 @@ public class MesClient extends JFrame {
 
         indexPanelC = new JPanel(new BorderLayout());
 
+        //新增的面板
+        JPanel indexPanelProductType = new JPanel();
+        indexPanelProductType.setLayout(null);
+        JScrollPane productTypeScrollPane = new JScrollPane(indexPanelProductType);
+
+        JLabel productTypeTitle = new JLabel("生产类型设置");
+        productTypeTitle.setFont(new Font("微软雅黑", Font.BOLD, 28));
+        productTypeTitle.setForeground(new Color(64, 64, 64));
+        productTypeTitle.setHorizontalAlignment(SwingConstants.CENTER);
+        productTypeTitle.setBounds(81, 80, 810, 50);
+        indexPanelProductType.add(productTypeTitle);
+
+        JLabel productTypeHint = new JLabel("请选择当前生产的工件类型,切换后将保存到本地并用于扫码校验");
+        productTypeHint.setFont(new Font("微软雅黑", Font.PLAIN, 20));
+        productTypeHint.setForeground(new Color(140, 140, 140));
+        productTypeHint.setHorizontalAlignment(SwingConstants.CENTER);
+        productTypeHint.setBounds(81, 140, 810, 40);
+        indexPanelProductType.add(productTypeHint);
+
+        productTypePanel = new ProductTypePanel(PRODUCT_TYPE_SWITCH_PASSWORD);
+        productTypePanel.setBounds(276, 210, 420, 72);
+        productTypePanel.setOnChangeListener(() -> {
+            if (work_status == 0) {
+                saveProductTypeToDb();
+                setMenuStatus("当前生产类型:" + getProductTypeName() + ",请扫工件码", 0);
+            }
+            refreshProductTypeCurrentLabel();
+        });
+        indexPanelProductType.add(productTypePanel);
+
+        productTypeCurrentLabel = new JLabel();
+        productTypeCurrentLabel.setFont(new Font("微软雅黑", Font.PLAIN, 22));
+        productTypeCurrentLabel.setForeground(new Color(64, 64, 64));
+        productTypeCurrentLabel.setHorizontalAlignment(SwingConstants.CENTER);
+        productTypeCurrentLabel.setBounds(81, 310, 810, 40);
+        refreshProductTypeCurrentLabel();
+        indexPanelProductType.add(productTypeCurrentLabel);
+
+        tabbedPane.addTab("生产类型", new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")), productTypeScrollPane, null);
+
+
         tabbedPane.addTab("开班点检", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), indexPanelC, null);
 
 
@@ -1208,6 +1300,81 @@ public class MesClient extends JFrame {
         });
     }
 
+    private static String validateProductSnMessage(String sn) {
+        if (sn == null || sn.isEmpty()) {
+            return "工件码为空,请重试";
+        }
+        if (sn.length() != PRODUCT_SN_LENGTH) {
+            return "工件码长度须为32位,当前" + sn.length() + "位";
+        }
+        String prefix = getProductSnPrefix();
+        if (!sn.startsWith(prefix)) {
+            return "工件码前缀与当前类型(" + getProductTypeName() + ")不匹配,当前工件码为" + getProductTypeNameBySn(sn);
+        }
+        return null;
+    }
+
+    private static void updateProductTypePanelEnabled(boolean enabled) {
+        if (productTypePanel != null) {
+            productTypePanel.setEnabled(enabled);
+        }
+    }
+    public static void loadProductTypeFromDb() {
+        if (productTypePanel == null) {
+            return;
+        }
+        String savedType = JdbcUtils.getClientConfig(
+                JdbcUtils.getProductTypeConfigKey(mes_gw),
+                PRODUCT_TYPE_ZJ
+        );
+        if (PRODUCT_TYPE_SJ.equals(savedType)) {
+            productTypePanel.setResult(PRODUCT_TYPE_SJ);
+        } else {
+            productTypePanel.setResult(PRODUCT_TYPE_ZJ);
+        }
+        refreshProductTypeCurrentLabel();
+    }
+
+    public static void refreshProductTypeCurrentLabel() {
+        if (productTypeCurrentLabel != null) {
+            productTypeCurrentLabel.setText("当前选择:" + getProductTypeName() + "(前缀 " + getProductSnPrefix() + ")");
+        }
+    }
+
+    public static void saveProductTypeToDb() {
+        if (productTypePanel == null) {
+            return;
+        }
+        JdbcUtils.saveClientConfig(
+                JdbcUtils.getProductTypeConfigKey(mes_gw),
+                productTypePanel.getResult()
+        );
+    }
+
+    public static String getProductSnPrefix() {
+        if (productTypePanel != null && PRODUCT_TYPE_SJ.equals(productTypePanel.getResult())) {
+            return PREFIX_SJ;
+        }
+        return PREFIX_ZJ;
+    }
+
+    public static String getProductTypeName() {
+        if (productTypePanel != null) {
+            return productTypePanel.getTypeName();
+        }
+        return "智界";
+    }
+
+    private static String getProductTypeNameBySn(String sn) {
+        if (sn.startsWith(PREFIX_SJ)) {
+            return "尚界";
+        }
+        if (sn.startsWith(PREFIX_ZJ)) {
+            return "智界";
+        }
+        return "未知";
+    }
+
     // 软件设置页面UI构建(含编辑/保存/重载按钮)
     private JPanel buildSoftwareSettingPanel() {
         JPanel panel = new JPanel();

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

@@ -105,9 +105,66 @@ public class JdbcUtils {
 				")";
 		statement.executeUpdate(rivetRecord);
 
+        //新增表
+        String clientConfig = "CREATE TABLE if not exists client_config("
+                + "config_key VARCHAR(100) PRIMARY KEY,"
+                + "config_value VARCHAR(500),"
+                + "update_time DATETIME"
+                + ")";
+        statement.executeUpdate(clientConfig);
+
         statement.close();
     }
 
+    //新增方法
+    public static void saveClientConfig(String key, String value) {
+        try {
+            if (conn == null || conn.isClosed()) {
+                openConnection();
+            }
+            String sql = "INSERT INTO client_config (config_key, config_value, update_time) VALUES (?, ?, ?) "
+                    + "ON CONFLICT(config_key) DO UPDATE SET config_value = excluded.config_value, update_time = excluded.update_time";
+            PreparedStatement ps = conn.prepareStatement(sql);
+            ps.setString(1, key);
+            ps.setString(2, value);
+            ps.setString(3, DateLocalUtils.getCurrentTime());
+            ps.executeUpdate();
+            ps.close();
+            log.info("保存本地配置: {}={}", key, value);
+        } catch (SQLException e) {
+            log.info("保存本地配置失败: {}", e.getMessage());
+        }
+    }
+
+    //新增方法
+    public static String getClientConfig(String key, String defaultValue) {
+        try {
+            if (conn == null || conn.isClosed()) {
+                openConnection();
+            }
+            String sql = "SELECT config_value FROM client_config WHERE config_key = ?";
+            PreparedStatement ps = conn.prepareStatement(sql);
+            ps.setString(1, key);
+            ResultSet rs = ps.executeQuery();
+            if (rs.next()) {
+                String value = rs.getString("config_value");
+                rs.close();
+                ps.close();
+                return value;
+            }
+            rs.close();
+            ps.close();
+        } catch (SQLException e) {
+            log.info("读取本地配置失败: {}", e.getMessage());
+        }
+        return defaultValue;
+    }
+
+    //新增方法
+    public static String getProductTypeConfigKey(String gw) {
+        return "product_type_" + gw;
+    }
+
 	public static String getServerIpByOp(String op) {
 		try {
 			if (op == null || op.trim().isEmpty()) {