hfy 6 ماه پیش
والد
کامیت
2522e61b20
3فایلهای تغییر یافته به همراه269 افزوده شده و 326 حذف شده
  1. 227 0
      src/com/mes/component/MesClientComponent.java
  2. 23 318
      src/com/mes/ui/MesClient.java
  3. 19 8
      src/com/mes/ui/MesRevice.java

+ 227 - 0
src/com/mes/component/MesClientComponent.java

@@ -0,0 +1,227 @@
+package com.mes.component;
+
+import com.mes.ui.DataUtil;
+import com.mes.ui.MesClient;
+import com.mes.ui.Oprno;
+import com.mes.util.S7PLCUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.FocusAdapter;
+import java.awt.event.FocusEvent;
+import java.util.Timer;
+import java.util.TimerTask;
+
+public class MesClientComponent extends JPanel {
+
+    public static final Logger log = LoggerFactory.getLogger(MesClientComponent.class);
+    // 工位类
+    public Oprno oprnoClass = new Oprno();
+    // 工位号
+    // 线体
+    public static String lineSn = "XT";
+    // 输入框
+    public JTextField productSn;
+    // 状态栏
+    public JButton status_menu;
+    // 宽度
+    public static Integer workWidth = 350;
+    // 高度
+    public static Integer workHeight = 400;
+    // 扫码按钮
+    public JButton scanBtn;
+    // 刷新按钮
+    public JButton resetBtn;
+    // 工作状态
+    // 0:未扫码,等待允许扫码信号 1:扫码成功,质量检查 2:质量合格,开始做件 3:加工完成,提交结果
+    public static Integer work_status = 0;
+
+
+    public JLabel sllabel1;
+
+    public JLabel sllabel2;
+
+
+    // UI
+    public MesClientComponent(Oprno opno){
+        oprnoClass = opno;
+        this.setLayout(null);
+        this.setBackground(Color.WHITE);
+        // 设置灰色边框
+        this.setBorder(BorderFactory.createLineBorder(Color.GRAY));
+        JLabel oprnoLabel = new JLabel(oprnoClass.getOprno());
+        oprnoLabel.setHorizontalAlignment(SwingConstants.CENTER);
+        oprnoLabel.setForeground(Color.BLACK);
+        oprnoLabel.setFont(new Font("微软雅黑", Font.PLAIN, 30));
+        oprnoLabel.setBounds(0, 0, workWidth, 60);
+        this.add(oprnoLabel);
+        // 状态栏
+        status_menu = new JButton("等待上料信号");
+        // 状态栏位置
+        status_menu.setBounds(10, 60, workWidth - 20, 60);
+        // 状态栏文字颜色
+        status_menu.setForeground(Color.GREEN);
+        // 为状态按钮添加点击事件监听器
+        status_menu.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+            }
+        });
+        // 设置状态栏按钮字体为微软雅黑,普通样式,大小20
+        status_menu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
+        // 设置状态栏按钮背景色为黑色
+        status_menu.setBackground(Color.BLACK);
+        // 将状态栏按钮添加到当前面板
+        this.add(status_menu);
+        productSn = new JTextField("");
+        productSn.setHorizontalAlignment(SwingConstants.CENTER);
+        productSn.setForeground(Color.BLACK);
+        productSn.setFont(new Font("微软雅黑", Font.PLAIN, 20));
+        productSn.setEditable(false);
+        productSn.setBounds(10, 130, workWidth-20, 60);
+        productSn.addFocusListener(new FocusAdapter() {
+            @Override
+            public void focusGained(FocusEvent e) {
+
+            }
+        });
+        this.add(productSn);
+
+        scanBtn = new JButton("扫码");
+        final MesClientComponent thisComponent = this;
+        scanBtn.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                System.out.println("扫码");
+                // 获取工件码
+                thisComponent.scanBtnClick();
+            }
+        });
+        scanBtn.setIcon(new ImageIcon(MesClient.class.getResource("/bg/scan_barcode.png")));
+        scanBtn.setFont(new Font("微软雅黑", Font.PLAIN, 32));
+        scanBtn.setBounds(10, 200, workWidth/2 - 5, 60);
+        this.add(scanBtn);
+
+        resetBtn = new JButton("刷新");
+        resetBtn.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                resetBtnClick();
+            }
+        });
+        resetBtn.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
+        resetBtn.setFont(new Font("微软雅黑", Font.PLAIN, 32));
+        resetBtn.setBounds(170, 200, workWidth/2 - 5, 60);
+        this.add(resetBtn);
+        sllabel1 = new JLabel("上料允许");
+        sllabel1.setHorizontalAlignment(SwingConstants.CENTER);
+        sllabel1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
+        sllabel1.setForeground(Color.BLACK);
+        sllabel1.setBounds(0, 280, workWidth/2, 50);
+        this.add(sllabel1);
+        sllabel2 = new JLabel("下料允许");
+        sllabel2.setHorizontalAlignment(SwingConstants.CENTER);
+        sllabel2.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
+        sllabel2.setForeground(Color.BLACK);
+        sllabel2.setBounds(190, 280, workWidth/2, 50);
+        this.add(sllabel2);
+        // 加入定时任务
+        this.startOprnoTimer();
+    }
+
+    // 扫码按钮
+    public void scanBtnClick() {
+        if (!(work_status == 0)){
+            status_menu.setText("工件加工中,请勿重复扫码");
+        }else {
+            String sn = S7PLCUtils.getSnInOprno(oprnoClass, MesClient.s7PLC);
+            if (sn.equals("")){
+                if (productSn.getText().isEmpty()){
+                    // 状态栏改变
+                    status_menu.setText("扫码结果为空");
+                    productSn.setText(oprnoClass.getMes_in());
+                }
+            }else {
+                productSn.setText(sn);
+                work_status = 1;
+            }
+        }
+    }
+
+
+
+
+    // 定时任务
+    public  Timer oprnoTimer;
+    public void startOprnoTimer() {
+        if(oprnoTimer!=null) {
+            oprnoTimer.cancel();
+        }
+        oprnoTimer = new Timer();
+        oprnoTimer.schedule(new TimerTask() {
+            public void run() {
+                if (work_status == 0){
+                    // 未扫码,等待允许扫码信号
+                    // 当遍历出有上料点位为true的工位时
+                    if (MesClient.s7PLC.readBoolean(oprnoClass.getHgA_out()) || MesClient.s7PLC.readBoolean(oprnoClass.getHgB_out())) {
+                        String sn = "";
+                        boolean hgA = MesClient.s7PLC.readBoolean(oprnoClass.getHgA_out());
+                        boolean hgB = MesClient.s7PLC.readBoolean(oprnoClass.getHgB_out());
+                        if (hgA) {
+                            // 获取A号料
+                            sn = MesClient.s7PLC.readString(oprnoClass.getHgA_sn());
+                        }
+                        if (hgB) {
+                            sn = MesClient.s7PLC.readString(oprnoClass.getHgB_sn());
+                        }
+                        productSn.setText(sn);
+                        work_status = 1;
+                    }
+                }else if (work_status == 1){
+                    // 已扫码,等待允许加工信号
+                    String sn = productSn.getText();
+                    Boolean checkQualityResult = DataUtil.checkQualityByGw(MesClient.nettyClient, sn,MesClient.user20,oprnoClass.getOprno());
+                    if (!checkQualityResult){
+                        setMenuStatus("消息发送失败,请重试",-1);
+                    }
+                }else if (work_status == 2){
+                    if (MesClient.s7PLC.readBoolean(oprnoClass.getProcess_ok())){
+                        String sn = productSn.getText();
+                        String ret = "OK";
+                        if (MesClient.s7PLC.readBoolean(oprnoClass.getProcess_result_ng())){
+                            ret = "NG";
+                        }
+                        Boolean result = DataUtil.sendQualityByGW(MesClient.nettyClient, sn, ret, MesClient.user20, oprnoClass.getOprno());
+                        if (!result){
+                            setMenuStatus("消息发送失败,请重试",-1);
+                        }
+                    }
+                }else if (work_status == 3){
+                    productSn.setText("");
+                    work_status = 0;
+                }
+            }
+        },100,3000);
+    }
+
+    // 刷新
+    public void resetBtnClick() {
+        productSn.setText("");
+        work_status = 0;
+        setMenuStatus("请扫码",0);
+    }
+
+
+
+    public  void setMenuStatus(String msg,int error){
+        if(error == 0){
+            this.status_menu.setForeground(Color.GREEN);
+        }else{
+            this.status_menu.setForeground(Color.RED);
+        }
+        this.status_menu.setText(msg);
+    }
+
+
+}

+ 23 - 318
src/com/mes/ui/MesClient.java

@@ -3,6 +3,7 @@ package com.mes.ui;
 import com.alibaba.fastjson2.JSONObject;
 import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType;
 import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
+import com.mes.component.MesClientComponent;
 import com.mes.component.MesRadio;
 import com.mes.component.MesWebView;
 import com.mes.netty.NettyClient;
@@ -69,7 +70,8 @@ public class MesClient extends JFrame {
     public static JScrollPane indexScrollPaneA;
     public static JScrollPane searchScrollPane;
     public static JScrollPane searchScrollPaneDj;
-
+    // 存储工位号和对应的MesClientComponent组件的映射
+    public static Map<String, MesClientComponent> componentMap = new HashMap<>();
 
     public static Boolean check_quality_result = false;
     public static Integer work_status = 0;
@@ -112,26 +114,6 @@ public class MesClient extends JFrame {
     private static final String[] SKIP_PROPERTIES = {"hgA_qr_code", "hgB_qr_code"};
     // 新增:存储动态生成的工位输入框(key=工位号,value=输入框)
     private static Map<String, JTextField> oprnoTextFieldMap = new HashMap<>();
-    // 输入框相关配置(可调整)
-    private static final int TEXT_FIELD_WIDTH = 602; // 输入框宽度
-    private static final int TEXT_FIELD_HEIGHT = 50; // 输入框高度
-    private static final int TEXT_FIELD_X = 81; // 输入框X坐标(与原有工件码输入框对齐)
-    private static final int TEXT_FIELD_MARGIN = 20; // 输入框之间的间距
-    private static final Font TEXT_FIELD_FONT = new Font("微软雅黑", Font.PLAIN, 22); // 输入框字体
-    
-    // 定时任务池
-    private static ScheduledExecutorService schedulerPool;
-    // 存储每个工位的定时任务,用于后续管理和取消
-    private static Map<String, ScheduledFuture<?>> taskMap = new HashMap<>();
-    // 定时任务执行间隔(毫秒)
-    // 定时任务开关状态
-    public static boolean scheduledTasksEnabled = false;
-    private static final long TASK_INTERVAL = 1000;
-    // 时间打印任务间隔(毫秒)
-    private static final long TIME_PRINT_INTERVAL = 500; // 0.5秒
-    // 时间打印任务的引用
-    private static ScheduledFuture<?> timePrintTask = null;
-
     //点检字段
     public static Boolean check_info = false;
 
@@ -195,7 +177,7 @@ public class MesClient extends JFrame {
             log.info("工位信息" + oprno.toString());
         }
 
-        DataUtil.getCheckInfo();
+        //DataUtil.getCheckInfo();
     }
 
     // 初始化TCP
@@ -218,167 +200,29 @@ public class MesClient extends JFrame {
     }
 
     /**
-     * 为指定工位创建定时任务
-     * @param oprnoCode 工位号
-     * @param textField 对应的输入框
+     * 创建工作面板
      */
-    private void createScheduledTask(final String oprnoCode, final JTextField textField) {
-        // 先取消可能存在的旧任务
-        if (taskMap.containsKey(oprnoCode)) {
-            ScheduledFuture<?> oldTask = taskMap.get(oprnoCode);
-            if (!oldTask.isCancelled()) {
-                oldTask.cancel(false);
-            }
-        }
-        
-        // 只有当定时任务开关开启时才创建任务
-        if (scheduledTasksEnabled) {
-            // 创建新的定时任务
-            ScheduledFuture<?> task = schedulerPool.scheduleAtFixedRate(() -> {
-                // 在每次执行前检查开关状态
-                if (scheduledTasksEnabled) {
-                    try {
-                        // 从PLC读取数据(这里是示例,实际使用时需要根据工位号确定对应的PLC地址)
-                        String sn = S7PLCUtils.getSnInOprno(oprnoMap.get(oprnoCode), s7PLC).trim();
-                        // 使用SwingUtilities确保在事件调度线程中更新UI
-                        SwingUtilities.invokeLater(() -> {
-                            // 更新输入框内容
-//                            System.out.println(sn + "加工完成情况" + s7PLC.readBoolean(oprnoMap.get(oprnoCode).process_ok));
-
-                            textField.setText(sn);
-                        });
-                        // 当从对应plc中取到加工完成时执行
-                        if (s7PLC.readBoolean(oprnoMap.get(oprnoCode).process_ok)){
-                            textField.setText(oprnoCode+"加工完成");
-                            System.out.println("工位号:"+oprnoCode);
-                            System.out.println("工位dizhi:"+oprnoMap.get(oprnoCode).process_ok);
-                            System.out.println("sn:"+sn);
-                            System.out.println("加工完成:---------------"+sn);
-                            String qret = "OK";
-                            if (!S7PLCUtils.getResultInOprno(oprnoMap.get(oprnoCode),s7PLC)){
-                                qret = "NG";
-                            }
-                            System.out.println("加工结果:---------------"+qret);
-                            Boolean sendret = DataUtil.sendQualityByGW(nettyClient,sn,qret,user20,oprnoCode);
-                            if (!sendret){
-                                log.error("发送数据失败");
-                            }
-                        }
-                    } catch (Exception e) {
-                        log.error("定时任务执行异常,工位号: " + oprnoCode, e);
-                        // 在异常情况下,也在事件调度线程中更新UI显示错误信息
-                        SwingUtilities.invokeLater(() -> {
-                            textField.setText("读取错误");
-                        });
-                    }
-                }
-            }, 0, TASK_INTERVAL, TimeUnit.MILLISECONDS);
-            
-            // 保存任务引用以便后续管理
-            taskMap.put(oprnoCode, task);
-        } else {
-            log.info("定时任务已关闭,未为工位 " + oprnoCode + " 创建定时任务");
-        }
-    }
-    
+    private void createOprnoPanel(JPanel parentPanel){
 
-    
-    /**
-     * 新增:动态生成工位输入框(根据 oprnoMap 的 key 数量)
-     * @param parentPanel 父面板(indexPanelA)
-     */
-    private void generateOprnoTextFields(JPanel parentPanel) {
-        // 输入框起始Y坐标(在返修件提示标签下方,避免与OK/NG按钮重叠)
-        int startY = 80; // 整体上移,减少顶部空白空间
-        // 标签宽度设置
-        int labelWidth = 120;
-        // 按钮宽度
-        int buttonWidth = 100;
-        // 输入框和按钮之间的间距
-        int gapBetweenFieldAndButton = 5;
-        // 调整后的输入框宽度(为按钮腾出空间)
-        int adjustedTextFieldWidth = TEXT_FIELD_WIDTH - labelWidth - buttonWidth - gapBetweenFieldAndButton;
-
-        // 初始化定时任务池(如果尚未初始化)
-        if (schedulerPool == null || schedulerPool.isShutdown()) {
-            schedulerPool = Executors.newScheduledThreadPool(oprnoMap.size());
-        }
-
-        // 创建一个子面板来容纳所有输入框和标签,便于管理和滚动
-        JPanel textFieldsPanel = new JPanel();
-        textFieldsPanel.setLayout(null);
-        textFieldsPanel.setBounds(TEXT_FIELD_X, startY, TEXT_FIELD_WIDTH, 100 + oprnoMap.size() * (TEXT_FIELD_HEIGHT + TEXT_FIELD_MARGIN));
-        textFieldsPanel.setVisible(true); // 确保工位输入框和标签面板可见
-        
-        // 遍历 oprnoMap,生成输入框和标签(按工位号排序)
         List<String> oprnoCodes = new ArrayList<>(oprnoMap.keySet());
         Collections.sort(oprnoCodes); // 排序,确保输入框顺序固定
-
         int fieldY = 0;
         for (String oprnoCode : oprnoCodes) {
-            // 1. 创建工位号标签
-            JLabel label = new JLabel(oprnoCode + ":");
-            label.setFont(TEXT_FIELD_FONT); // 使用与输入框相同的字体,保持一致性
-            label.setHorizontalAlignment(SwingConstants.RIGHT); // 右对齐,便于与输入框对齐
-            label.setVerticalAlignment(SwingConstants.CENTER);
-            label.setBounds(0, fieldY, labelWidth, TEXT_FIELD_HEIGHT);
-            label.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5)); // 右侧添加一些边距
-            textFieldsPanel.add(label);
-            
-            // 2. 创建输入框
-            JTextField textField = new JTextField();
-            textField.setHorizontalAlignment(SwingConstants.CENTER);
-            textField.setEditable(false); // 设为不可编辑(与工件码输入框一致)
-            textField.setFont(TEXT_FIELD_FONT);
-            textField.setToolTipText("工位:" + oprnoCode); // 鼠标悬浮提示工位号
-            // 设置输入框位置和大小(调整宽度和X坐标,为按钮腾出空间)
-            textField.setBounds(labelWidth, fieldY, adjustedTextFieldWidth, TEXT_FIELD_HEIGHT);
-            // 设置输入框默认文本(只显示状态信息,不包含工位号)
-            textField.setText("");
-
-            // 3. 存储输入框到Map(后续可通过工位号获取/修改输入框内容)
-            oprnoTextFieldMap.put(oprnoCode, textField);
-
-            // 4. 创建刷新按钮
-            JButton refreshButton = new JButton("手动上料");
-            refreshButton.setFont(new Font("SimHei", Font.PLAIN, 12));
-            refreshButton.setBounds(labelWidth + adjustedTextFieldWidth + gapBetweenFieldAndButton, fieldY, buttonWidth, TEXT_FIELD_HEIGHT);
-            refreshButton.setToolTipText("刷新工位:" + oprnoCode);
-            
-            // 5. 为按钮添加点击事件监听器
-            final String currentOprnoCode = oprnoCode; // 必须使用final变量在匿名内部类中访问
-            refreshButton.addActionListener(new ActionListener() {
-                @Override
-                public void actionPerformed(ActionEvent e) {
-                    // 获取输入框内容
-                    String inputValue = textField.getText();
-                    // 打印工位号和输入框内容
-                    System.out.println("工位号:" + currentOprnoCode + ", 输入内容:" + inputValue);
-                    s7PLC.writeBoolean(oprnoMap.get(currentOprnoCode).getMes_in(),true);
-                }
-            });
+            // 按照一行四个的列进行布局
+            int columnIndex = fieldY % 5;
+            int rowIndex = fieldY / 5;
+            MesClientComponent mesClientComponent = new MesClientComponent(oprnoMap.get(oprnoCode));
+            mesClientComponent.setBounds(columnIndex * MesClientComponent.workWidth, rowIndex * MesClientComponent.workHeight, MesClientComponent.workWidth, MesClientComponent.workHeight);
+            parentPanel.add(mesClientComponent);
+            // 将组件添加到映射中,以便通过工位号找到对应的组件
+            componentMap.put(oprnoCode, mesClientComponent);
+            fieldY++;
 
-            // 6. 添加到子面板
-            textFieldsPanel.add(textField);
-            textFieldsPanel.add(refreshButton);
+        }
 
-            // 7. 为当前工位创建定时任务
-            createScheduledTask(oprnoCode, textField);
 
-            // 8. 计算下一个输入框的Y坐标
-            fieldY += TEXT_FIELD_HEIGHT + TEXT_FIELD_MARGIN;
-        }
-        
-        // 添加子面板到父面板
-        parentPanel.add(textFieldsPanel);
-        
-        // 调整父面板的首选大小,确保滚动条正常工作
-        parentPanel.setPreferredSize(new Dimension(parentPanel.getWidth(), Math.max(700, startY + textFieldsPanel.getHeight() + 100)));
-
-        log.info("动态生成 {} 个工位输入框和标签", oprnoTextFieldMap.size());
     }
 
-
     //启动心跳包程序
     public static java.util.Timer heartBeatTimer;
     public static java.util.Timer heartBeatIconTimer;
@@ -575,9 +419,6 @@ public class MesClient extends JFrame {
         welcomeWin.setVisible(true);
         mesClientFrame.setVisible(false);
 
-        // 关闭定时任务池
-        shutdownSchedulerPool();
-        
         nettyClient = null;
 //        if(heartBeatTimer!=null) {
 //            heartBeatTimer.cancel();
@@ -588,89 +429,6 @@ public class MesClient extends JFrame {
         tcp_connect_flag = false;
         connect_request_flag = false;
     }
-    
-    /**
-     * 创建时间打印定时任务
-     */
-    private void createTimePrintTask() {
-        // 先取消可能存在的旧任务
-        if (timePrintTask != null && !timePrintTask.isCancelled()) {
-            timePrintTask.cancel(false);
-        }
-        
-        // 初始化定时任务池(如果尚未初始化)
-        if (schedulerPool == null || schedulerPool.isShutdown()) {
-            schedulerPool = Executors.newScheduledThreadPool(oprnoMap.size() + 1); // +1 为时间打印任务
-        }
-        
-        // 创建时间打印定时任务
-        timePrintTask = schedulerPool.scheduleAtFixedRate(() -> {
-            // 在每次执行前检查开关状态
-            if (scheduledTasksEnabled) {
-                try {
-                    // 获取所有工位对象并转换为数组
-                    Oprno[] oprnos = oprnoMap.values().toArray(new Oprno[0]);
-                    // 调用S7PLCUtils.isStart方法检查工位上料状态
-                    Oprno startOprno = S7PLCUtils.isStart(s7PLC, oprnos);
-                    // 处理返回结果
-                    if (startOprno != null) {
-                        // 判断这个工件码的位置是A面还是B面
-                        System.out.println("上料的工位号码:"+ startOprno.getOprno());
-                        String sn = S7PLCUtils.getSnInJXB(startOprno, s7PLC);
-                        if (sn != null && !sn.isEmpty()) {
-                            // 检查质量
-                            Boolean checkQualityResult = DataUtil.checkQualityByGw(nettyClient, sn, user20,startOprno.getOprno());
-                            if (!checkQualityResult) {
-                                MesClient.setMenuStatus("消息发送失败,请重试",-1);
-                            }
-                        }else {
-                            MesClient.setMenuStatus(startOprno.getOprno()+"获取工件码为空",-1);
-                        }
-                    }
-                } catch (Exception e) {
-                    log.error("时间打印任务执行异常", e);
-                }
-            }
-        }, 0, TIME_PRINT_INTERVAL, TimeUnit.MILLISECONDS);
-    }
-    
-    /**
-     * 关闭定时任务池的方法
-     */
-    private static void shutdownSchedulerPool() {
-        try {
-            if (schedulerPool != null && !schedulerPool.isShutdown()) {
-                // 取消时间打印任务
-                if (timePrintTask != null && !timePrintTask.isCancelled()) {
-                    timePrintTask.cancel(false);
-                    timePrintTask = null;
-                }
-                
-                // 取消所有工位定时任务
-                for (ScheduledFuture<?> future : taskMap.values()) {
-                    if (future != null && !future.isCancelled()) {
-                        future.cancel(false);
-                    }
-                }
-                // 清空任务映射
-                taskMap.clear();
-                // 关闭调度器池
-                schedulerPool.shutdown();
-                // 等待任务池关闭,最多等待3秒
-                if (!schedulerPool.awaitTermination(3, TimeUnit.SECONDS)) {
-                    // 如果超时,强制关闭
-                    schedulerPool.shutdownNow();
-                }
-                log.info("定时任务池已成功关闭");
-            }
-        } catch (Exception e) {
-            log.error("关闭定时任务池时发生异常", e);
-            // 发生异常时强制关闭
-            if (schedulerPool != null && !schedulerPool.isTerminated()) {
-                schedulerPool.shutdownNow();
-            }
-        }
-    }
 
     public MesClient() {
         setIconImage(Toolkit.getDefaultToolkit().getImage(MesClient.class.getResource("/bg/logo.png")));
@@ -680,13 +438,12 @@ public class MesClient extends JFrame {
         addWindowListener(new java.awt.event.WindowAdapter() {
             @Override
             public void windowClosing(java.awt.event.WindowEvent windowEvent) {
-                // 关闭定时任务池
-                shutdownSchedulerPool();
                 // 退出程序
                 System.exit(0);
             }
         });
-        setBounds(0, 0, 1024, 768);
+        setBounds(0, 0, 1024, 1500);
+        setLocationRelativeTo( null);
 
         JMenuBar menuBar = new JMenuBar();
         menuBar.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 26));
@@ -714,59 +471,7 @@ public class MesClient extends JFrame {
         settingMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")));
         settingMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
         menuBar.add(settingMenu);
-        
-        JMenu mesMenu = new JMenu("MES");
-        mesMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/menu_data_analysis.png")));
-        mesMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
-        menuBar.add(mesMenu);
-        
-        JMenuItem taskToggleMenuItem = new JMenuItem("启动 (关闭)");
-        taskToggleMenuItem.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
-        taskToggleMenuItem.setFont(new Font("微软雅黑", Font.PLAIN, 20));
-        taskToggleMenuItem.addMouseListener(new MouseAdapter() {
-            @Override
-            public void mousePressed(MouseEvent e) {
 
-                // 如果当前是关闭状态,用户点击想要开启
-                if (!scheduledTasksEnabled) {
-                    DataUtil.getCheckInfo();
-                    // 先检查开班点检是否完成
-                    if (!check_info) {
-                        // 未完成点检,显示提示并阻止操作
-                        MesClient.setMenuStatus("请先完成开班点检", -1);
-                        return;
-                    }
-                }
-                
-                // 切换定时任务状态
-                scheduledTasksEnabled = !scheduledTasksEnabled;
-                
-                // 更新菜单项文本和图标
-                if (scheduledTasksEnabled) {
-                    taskToggleMenuItem.setText("启动 (开启)");
-                    taskToggleMenuItem.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
-                    // 启动定时任务逻辑将在定时任务执行时检查状态
-                    MesClient.setMenuStatus("定时任务已开启", 1);
-                } else {
-                    taskToggleMenuItem.setText("启动 (关闭)");
-                    taskToggleMenuItem.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
-                    MesClient.setMenuStatus("定时任务已关闭", -1);
-                }
-                
-                // 重新创建时间打印任务,确保其与定时任务开关状态同步
-                createTimePrintTask();
-                
-                // 当定时任务开启时,为所有工位重新创建读码定时任务
-                if (scheduledTasksEnabled) {
-                    for (Map.Entry<String, JTextField> entry : oprnoTextFieldMap.entrySet()) {
-                        String oprnoCode = entry.getKey();
-                        JTextField textField = entry.getValue();
-                        createScheduledTask(oprnoCode, textField);
-                    }
-                }
-            }
-        });
-        mesMenu.add(taskToggleMenuItem);
 
         JMenuItem resetTcpMenu = new JMenuItem("\u91CD\u8FDEMES");
         resetTcpMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
@@ -873,7 +578,9 @@ public class MesClient extends JFrame {
         JPanel indexPanelA = new JPanel();
         indexScrollPaneA = new JScrollPane(indexPanelA);
         indexPanelA.setLayout(null);
-
+        indexPanelA.setPreferredSize(new Dimension(5*MesClientComponent.workWidth, 3*MesClientComponent.workHeight)); // 根据实际内容调整高度
+        indexScrollPaneA.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
+        indexScrollPaneA.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
         product_sn = new JTextField();
         product_sn.setHorizontalAlignment(SwingConstants.CENTER);
         product_sn.setEditable(false);
@@ -911,10 +618,8 @@ public class MesClient extends JFrame {
         fxlabel.setVisible(false);
         indexPanelA.add(fxlabel);
 
-        generateOprnoTextFields(indexPanelA);
-        
-        // 创建时间打印定时任务
-        createTimePrintTask();
+        // 创建工位面板
+        createOprnoPanel(indexPanelA);
 
         finish_ok_bt = new JButton("OK");
         finish_ok_bt.setEnabled(false);

+ 19 - 8
src/com/mes/ui/MesRevice.java

@@ -1,5 +1,6 @@
 package com.mes.ui;
 
+import com.mes.component.MesClientComponent;
 import com.mes.netty.ProtocolParam;
 import com.mes.component.MyDialog;
 import com.mes.util.ErrorMsg;
@@ -35,12 +36,16 @@ public class MesRevice {
 //                DataUtil.sendQuality(MesClient.nettyClient,sn,qret,MesClient.user20);
                 // 获取工位号
                 String oprno = ProtocolParam.getOprno(mes_msg).trim();
-                // 找到对应实体类
-                Oprno oprno1 = MesClient.oprnoMap.get(oprno);
+                // 找到对应的组件并修改状态
+                MesClientComponent component = MesClient.componentMap.get(oprno);
                 // 发送允许启动信号
-                MesClient.s7PLC.writeBoolean(oprno1.getMes_in(), true);
+                MesClient.s7PLC.writeBoolean(component.oprnoClass.getMes_in(), true);
                 // 开始加工报文
-                DataUtil.startWorkByGw(MesClient.nettyClient,ProtocolParam.getSn(mes_msg).trim(),MesClient.user20,oprno1.getOprno());
+                DataUtil.startWorkByGw(MesClient.nettyClient,ProtocolParam.getSn(mes_msg).trim(),MesClient.user20,component.oprnoClass.getOprno());
+                if (component != null) {
+                    component.setMenuStatus("质量检查合格,开始加工", 0);
+                    component.work_status = 2; // 更新工作状态为开始加工
+                }
             }else {
 //                MesClient.check_quality_result = false;
                 String lmsg = ErrorMsg.getErrorMsg(processMsgRet, ProtocolParam.getLx(mes_msg));
@@ -99,11 +104,17 @@ public class MesRevice {
             if(processMsgRet.equalsIgnoreCase("OK")) {
                 // 获取工位号
                 String oprno = ProtocolParam.getOprno(mes_msg).trim();
-                // 找到对应实体类
-                Oprno oprno1 = MesClient.oprnoMap.get(oprno);
+                // 找到对应的组件并修改状态
+                MesClientComponent component = MesClient.componentMap.get(oprno);
                 // 发送允许下料信号
-                MesClient.s7PLC.writeBoolean(oprno1.getMes_out(),true);
-                MesClient.s7PLC.writeBoolean(oprno1.getProcess_ok(),false);
+                MesClient.s7PLC.writeBoolean(component.oprnoClass.getMes_out(),true);
+                // 加工完成信号
+                MesClient.s7PLC.writeBoolean(component.oprnoClass.getProcess_ok(),false);
+
+                if (component != null) {
+                    component.setMenuStatus("提交成功", 0);
+                    component.work_status = 3;
+                }
             }else{
                 MesClient.setMenuStatus("结果提交失败,请重试",-1);
             }