dzc преди 12 часа
родител
ревизия
082a3fb93a

BIN
out/production/OP010/com/mes/ui/LoginFarme.class


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

@@ -214,7 +214,8 @@ public class DataUtil {
             String mes_server_ip = pro.getProperty("mes.server_ip");
             String lineSn = pro.getProperty("mes.line_sn").trim();
             
-            String url = "http://" + mes_server_ip + ":8980/js/a/mes/mesProductRecord/ ";
+            // 与 WebView 工作记录页对应的数据接口(其它工位客户端同为 workData)
+            String url = "http://" + mes_server_ip + ":8980/js/a/mes/mesProductRecord/workData";
             StringBuilder params = new StringBuilder();
             params.append("__ajax=json");
             params.append("&lineSn=").append(lineSn);
@@ -260,7 +261,7 @@ public class DataUtil {
                     data.setId(item.getString("id"));
                     data.setSn(item.getString("sn"));
                     data.setOprno(item.getString("oprno"));
-                    data.setUpdateBy(item.getString("updateBy"));
+                    data.setUpdateBy(parseUpdateBy(item));
                     data.setUpdateDate(item.getString("updateDate"));
                     data.setContent(item.getString("content"));
                     list.add(data);
@@ -276,4 +277,38 @@ public class DataUtil {
         }
         return resp;
     }
+
+    /**
+     * 解析作业人员字段:支持字符串,或用户对象中的 loginName/userName/userCode
+     */
+    private static String parseUpdateBy(JSONObject item) {
+        if (item == null) {
+            return "";
+        }
+        Object updateByObj = item.get("updateBy");
+        if (updateByObj == null) {
+            // 兼容其它可能字段
+            String ucode = item.getString("ucode");
+            return ucode != null ? ucode : "";
+        }
+        if (updateByObj instanceof JSONObject) {
+            JSONObject userObj = (JSONObject) updateByObj;
+            String name = userObj.getString("loginName");
+            if (name == null || name.isEmpty()) {
+                name = userObj.getString("userName");
+            }
+            if (name == null || name.isEmpty()) {
+                name = userObj.getString("userCode");
+            }
+            if (name == null || name.isEmpty()) {
+                name = userObj.getString("id");
+            }
+            return name != null ? name : "";
+        }
+        String updateBy = String.valueOf(updateByObj).trim();
+        if ("null".equalsIgnoreCase(updateBy)) {
+            return "";
+        }
+        return updateBy;
+    }
 }

+ 15 - 9
src/com/mes/ui/LoginFarme.java

@@ -151,7 +151,18 @@ public class LoginFarme extends JFrame {
     public static void checkUserAuthority(JSONObject retObj) {
         //设置登录用户名
         JSONObject userObj = JSONObject.parseObject(retObj.get("user").toString());
-        String user_id = userObj.getString("id").toString();
+        String user_id = userObj.getString("id");
+        // 优先取登录名,供界面“登录用户”和作业人员列显示
+        String loginName = userObj.getString("loginName");
+        if (loginName == null || loginName.trim().isEmpty()) {
+            loginName = userObj.getString("userCode");
+        }
+        if (loginName == null || loginName.trim().isEmpty()) {
+            loginName = userObj.getString("userName");
+        }
+        if (loginName == null || loginName.trim().isEmpty()) {
+            loginName = user_id;
+        }
 
         //获取sessionid,判断权限
         MesClient.sessionid = retObj.get("sessionid").toString();
@@ -177,17 +188,12 @@ public class LoginFarme extends JFrame {
 
                     //1操作工人,2管理员
                     //登录成功
-                    MesClient.user_menu.setText(user_id);
+                    MesClient.user_menu.setText(loginName);
+                    MesClient.getUser();
                     MesClient.welcomeWin.setVisible(false);
                     MesClient.mesClientFrame.setVisible(true);
 
-                    // 已弃用WebView(工作记录),改为使用WorkRecordPanel
-                     if(MesClient.jfxPanel == null){
-                         String url = "http://"+ MesClient.mes_server_ip+":8980/js/a/mes/mesProductRecord/work?oprno="+MesClient.mes_gw+"&lineSn="+MesClient.mes_line_sn;
-                         MesClient.jfxPanel = new MesWebView(url);
-                         MesClient.jfxPanel.setSize(990, 550);
-                         MesClient.indexPanelB.add(MesClient.jfxPanel);
-                     }
+                    // 工作记录已改用 WorkRecordPanel,不再加载 WebView
 
                     if(MesClient.jfxPanel2 == null){
                         String url = "http://"+ MesClient.mes_server_ip+":8980/js/a/mes/mesProcessCheckRecord/ulist?ucode="+user_id+"&oprno="+MesClient.mes_gw+"&lineSn="+MesClient.mes_line_sn;

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

@@ -695,49 +695,43 @@ public class MesClient extends JFrame {
         tabbedPane.addTab("开班点检", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), indexPanelC, null);
 
 
-        // ========== 工作记录 Tab(改造:当前工位Tab + 所有工位Tab) ==========
-        // 旧代码已注释:
-         indexPanelB = new JPanel();
-         searchScrollPane = new JScrollPane(indexPanelB);
-         indexPanelB.setLayout(null);
-         tabbedPane.addTab("工作记录", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPane, null);
-
-//        // 创建工作记录的子 TabbedPane
-//        JTabbedPane workRecordTabbedPane = new JTabbedPane(JTabbedPane.TOP);
-//        workRecordTabbedPane.setFont(new Font("微软雅黑", Font.PLAIN, 14));
-//
-//        // OKNG 工位:当前工位 + 所有工位
-//        WorkRecordPanel[] workRecordPanels = new WorkRecordPanel[2];
-//
-//        // 当前工位Tab(使用配置文件中的 mes.gw)
-//        workRecordPanels[0] = new WorkRecordPanel(mes_gw, mes_line_sn);
-//        workRecordTabbedPane.addTab(mes_gw, null, workRecordPanels[0], "查询" + mes_gw + "的工作记录");
-//
-//        // 所有工位Tab(查询整条产线所有工位)
-//        workRecordPanels[1] = new WorkRecordPanel(null, mes_line_sn);
-//        workRecordTabbedPane.addTab("所有工位", null, workRecordPanels[1], "查询整条产线所有工位的工作记录");
-//
-//        // 切换子Tab时自动刷新数据
-//        workRecordTabbedPane.addChangeListener(e -> {
-//            int selectedIndex = workRecordTabbedPane.getSelectedIndex();
-//            if (selectedIndex >= 0 && selectedIndex < workRecordPanels.length) {
-//                workRecordPanels[selectedIndex].refreshData();
-//            }
-//        });
-//
-//        // 将子 TabbedPane 添加到主 TabbedPane
-//        tabbedPane.addTab("工作记录", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), workRecordTabbedPane, null);
-//
+        // ========== 工作记录 Tab(使用 WorkRecordPanel,作业人员显示登录用户名) ==========
+        JTabbedPane workRecordTabbedPane = new JTabbedPane(JTabbedPane.TOP);
+        workRecordTabbedPane.setFont(new Font("微软雅黑", Font.PLAIN, 14));
+
+        final WorkRecordPanel[] workRecordPanels = new WorkRecordPanel[2];
+
+        // 当前工位Tab(使用配置文件中的 mes.gw)
+        workRecordPanels[0] = new WorkRecordPanel(mes_gw, mes_line_sn);
+        workRecordTabbedPane.addTab(mes_gw, null, workRecordPanels[0], "查询" + mes_gw + "的工作记录");
+
+        // 所有工位Tab(查询整条产线所有工位)
+        workRecordPanels[1] = new WorkRecordPanel(null, mes_line_sn);
+        workRecordTabbedPane.addTab("所有工位", null, workRecordPanels[1], "查询整条产线所有工位的工作记录");
+
+        // 切换子Tab时自动刷新数据
+        workRecordTabbedPane.addChangeListener(e -> {
+            int selectedIndex = workRecordTabbedPane.getSelectedIndex();
+            if (selectedIndex >= 0 && selectedIndex < workRecordPanels.length) {
+                workRecordPanels[selectedIndex].refreshData();
+            }
+        });
+
+        tabbedPane.addTab("工作记录", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), workRecordTabbedPane, null);
 
 		tabbedPane.addChangeListener(new ChangeListener() {
             @Override
             public void stateChanged(ChangeEvent e) {
-                JTabbedPane tabbedPane = (JTabbedPane) e.getSource();
-                int selectedIndex = tabbedPane.getSelectedIndex();
+                JTabbedPane pane = (JTabbedPane) e.getSource();
+                int selectedIndex = pane.getSelectedIndex();
                 System.out.println("selectedIndex:"+selectedIndex);
 
-                if(selectedIndex == 1){
-
+                // 切换到“工作记录”时刷新当前子Tab数据
+                if ("工作记录".equals(pane.getTitleAt(selectedIndex))) {
+                    int subIndex = workRecordTabbedPane.getSelectedIndex();
+                    if (subIndex >= 0 && subIndex < workRecordPanels.length) {
+                        workRecordPanels[subIndex].refreshData();
+                    }
                 }
             }
         });

+ 28 - 11
src/com/mes/ui/WorkRecordPanel.java

@@ -20,8 +20,8 @@ public class WorkRecordPanel extends JPanel {
 
     private static final Logger log = LoggerFactory.getLogger(WorkRecordPanel.class);
 
-    // 表格列名
-    private static final String[] COLUMN_NAMES = {"工件码", "工位号", "工位结果", "作业人员", "日期"};
+    // 表格列名(与原 WebView 工作记录页列顺序一致)
+    private static final String[] COLUMN_NAMES = {"工件码", "工位号", "作业人员", "日期", "工位结果"};
 
     // 分页配置
     private static final int PAGE_SIZE = 20;
@@ -236,15 +236,15 @@ public class WorkRecordPanel extends JPanel {
         // 工位号
         column = table.getColumnModel().getColumn(1);
         column.setPreferredWidth(90);
-        // 工位结果
-        column = table.getColumnModel().getColumn(2);
-        column.setPreferredWidth(70);
         // 作业人员
-        column = table.getColumnModel().getColumn(3);
+        column = table.getColumnModel().getColumn(2);
         column.setPreferredWidth(100);
         // 日期
-        column = table.getColumnModel().getColumn(4);
+        column = table.getColumnModel().getColumn(3);
         column.setPreferredWidth(150);
+        // 工位结果
+        column = table.getColumnModel().getColumn(4);
+        column.setPreferredWidth(70);
     }
 
     /**
@@ -363,16 +363,17 @@ public class WorkRecordPanel extends JPanel {
         }
         statusLabel.setText("工位:" + oprnoDisplay + " 共" + totalCount + "条");
 
-        // 填充表格数据
+        // 填充表格数据;作业人员使用当前登录用户名
+        String loginUser = getLoginUserName();
         List<WorkRecordData> list = resp.getList();
         if (list != null && !list.isEmpty()) {
             for (WorkRecordData data : list) {
                 Object[] row = {
                         data.getSn(),
                         data.getOprno(),
-                        data.getContent(),
-                        data.getUpdateBy(),
-                        data.getUpdateDate()
+                        loginUser,
+                        data.getUpdateDate(),
+                        data.getContent()
                 };
                 tableModel.addRow(row);
             }
@@ -400,4 +401,20 @@ public class WorkRecordPanel extends JPanel {
     public String getOprno() {
         return oprno;
     }
+
+    /**
+     * 获取当前登录用户名(界面“登录用户”显示值)
+     */
+    private String getLoginUserName() {
+        if (MesClient.user_menu != null) {
+            String name = MesClient.user_menu.getText();
+            if (name != null) {
+                return name.trim();
+            }
+        }
+        if (MesClient.user20 != null && !MesClient.user20.isEmpty()) {
+            return MesClient.user20.trim();
+        }
+        return "";
+    }
 }

+ 2 - 2
src/resources/config/config.properties

@@ -1,4 +1,4 @@
 mes.gw=OP010A
-mes.server_ip=127.0.0.1
-#mes.server_ip=192.168.16.99
+#mes.server_ip=127.0.0.1
+mes.server_ip=192.168.16.99
 mes.line_sn=XT