zxl 1 неделя назад
Родитель
Сommit
83033772c3

BIN
pack/dayang-mes.ico


+ 8 - 4
pack/dist/application.yml.example

@@ -16,24 +16,28 @@ logging:
 mes:
   app-title: MES 一拖二大冲
   server-ip: 192.168.9.19
-  tick-ms: 500
-  printer-name:
+#  server-ip: 127.0.0.1
+  tick-ms: 1000
   # 是否写 PLC MES允许运行点。false=开批/结案/清码都不写,本地仍取批盯冲次
   mes-allow-enabled: false
+  # 能耗=额定功率kW×本批设备运行小时(不读 PLC、不做能耗曲线);气垫/顶杆本线不采
   stations:
     - id: 1
       title: TE2-800
-      station-sn: DC-TE2
+      station-sn: DC-800T
       press-profile: TE2_800
       plc-ip: 192.168.0.1
       plc-port: 102
       # MES允许:
       mes-allow-addr: DB5.0.0
+      # 额定功率 kW(按铭牌填;0=不估算能耗)
+      rated-power-kw: 200
     - id: 2
       title: TL4-1600
-      station-sn: DC-TL4
+      station-sn: DC-800T1600
       press-profile: TL4_1600
       plc-ip: 192.168.1.99
       plc-port: 102
       # MES允许:点表 DB76.DBX128.1
       mes-allow-addr: DB76.128.1
+      rated-power-kw: 0

BIN
pack/dist/mesclient-dachong-yt.exe



BIN
pack/splash/blue.bmp


BIN
pack/splash/dark.bmp


BIN
pack/splash/steel.bmp


+ 3 - 12
src/main/java/com/mes/config/DcPressProfiles.java

@@ -2,6 +2,7 @@ package com.mes.config;
 
 /**
  * 一拖二大冲点表:TE2-800 / TL4-1600。
+ * 能耗不读 PLC(按额定功率×运行时间估算);气垫风压/顶杆行程本线不采集(仅自动化大冲压机1有)。
  */
 public enum DcPressProfiles {
 
@@ -14,7 +15,6 @@ public enum DcPressProfiles {
 			"DB91.2",
 			"DB900.360",
 			"DB63.6",
-			"",
 			true),
 
 	/** TL4-1600 */
@@ -26,11 +26,10 @@ public enum DcPressProfiles {
 			"DB76.0",
 			"DB76.54",
 			"DB76.100",
-			"DB8.116",
 			false);
 
 	private final String title;
-	/** 设备运行 BOOL */
+	/** 设备运行 BOOL(兼作能耗运行计时) */
 	private final String deviceRunAddr;
 	/** 生产高度 REAL */
 	private final String dieHeightAddr;
@@ -42,14 +41,12 @@ public enum DcPressProfiles {
 	private final String tonnageAddr;
 	/** 压机行程次数 REAL(SPM) */
 	private final String pressSpmAddr;
-	/** 电能能耗 DINT 地址 */
-	private final String energyAddr;
 	/** 吨位是否按 DINT 读(否则 REAL) */
 	private final boolean tonnageDint;
 
 	DcPressProfiles(String title, String deviceRunAddr,
 			String dieHeightAddr, String strokeCountAddr, String cylinderPressureAddr,
-			String tonnageAddr, String pressSpmAddr, String energyAddr, boolean tonnageDint) {
+			String tonnageAddr, String pressSpmAddr, boolean tonnageDint) {
 		this.title = title;
 		this.deviceRunAddr = deviceRunAddr;
 		this.dieHeightAddr = dieHeightAddr;
@@ -57,7 +54,6 @@ public enum DcPressProfiles {
 		this.cylinderPressureAddr = cylinderPressureAddr;
 		this.tonnageAddr = tonnageAddr;
 		this.pressSpmAddr = pressSpmAddr;
-		this.energyAddr = energyAddr == null ? "" : energyAddr.trim();
 		this.tonnageDint = tonnageDint;
 	}
 
@@ -89,11 +85,6 @@ public enum DcPressProfiles {
 		return pressSpmAddr;
 	}
 
-	/** 电能能耗点地址 */
-	public String getEnergyAddr() {
-		return energyAddr;
-	}
-
 	public boolean isTonnageDint() {
 		return tonnageDint;
 	}

+ 14 - 1
src/main/java/com/mes/config/MesClientProperties.java

@@ -16,7 +16,7 @@ public class MesClientProperties {
 	/** MES 服务器 IP */
 	private String serverIp = "";
 	/** 刷新周期毫秒 */
-	private int tickMs = 500;
+	private int tickMs = 1000;
 	/** 结案小票打印机名;空=系统默认 */
 	private String printerName = "";
 	/**
@@ -49,6 +49,11 @@ public class MesClientProperties {
 		private String mesAllowAddr = "";
 		/** Tab / 顶栏显示名 */
 		private String title = "";
+		/**
+		 * 额定功率(kW)。能耗=额定功率×本批设备运行小时;不读 PLC。
+		 * ≤0 表示未配置,不估算。
+		 */
+		private double ratedPowerKw = 0D;
 
 		public int getId() {
 			return id;
@@ -106,6 +111,14 @@ public class MesClientProperties {
 			this.title = title;
 		}
 
+		public double getRatedPowerKw() {
+			return ratedPowerKw;
+		}
+
+		public void setRatedPowerKw(double ratedPowerKw) {
+			this.ratedPowerKw = ratedPowerKw;
+		}
+
 		/** 解析机型枚举 */
 		public DcPressProfiles resolveProfile() {
 			return DcPressProfiles.of(pressProfile);

+ 11 - 4
src/main/java/com/mes/entity/DcRunSnapshot.java

@@ -1,8 +1,8 @@
 package com.mes.entity;
 
 /**
- * 一拖二大冲实时快照:生产高度/冲次/顶缸压力/吨位/行程次数/电能能耗 + 设备运行态。
- * 示值保留设备原串,统计另议。
+ * 一拖二大冲实时快照:生产高度/冲次/顶缸压力/吨位/行程次数 + 设备运行态。
+ * 能耗改为额定功率×运行时间估算,PLC 不再填充 energyKwh。
  */
 public class DcRunSnapshot {
 
@@ -18,17 +18,24 @@ public class DcRunSnapshot {
 	public String tonnage = "";
 	/** 压机行程次数 / SPM(原串) */
 	public String pressSpm = "";
-	/** 电能能耗示值(原串) */
+	/** 能耗:PLC 不再读;结案用估算值 */
 	public String energyKwh = "";
 	/** 设备是否运行 */
 	public boolean deviceRunning;
 	/** 设备状态文案 */
 	public String deviceStateText = "未知";
+	/** MES 允许运行(PLC 读回) */
+	public boolean mesAllow;
+	/** 本拍是否读到 MES 允许点(点未配/未连/读失败则为 false) */
+	public boolean mesAllowReadOk;
+	/** 本拍是否读到有效运行状态(未连/读失败则为 false,勿当默认停机结案) */
+	public boolean statusReadOk;
 
 	@Override
 	public String toString() {
 		return "stroke=" + strokeCount + ", die=" + dieHeight + ", press=" + cylinderPressure
 				+ ", ton=" + tonnage + ", spm=" + pressSpm + ", energy=" + energyKwh
-				+ ", run=" + deviceRunning;
+				+ ", run=" + deviceRunning + ", MES允许="
+				+ (mesAllowReadOk ? (mesAllow ? "开" : "关") : "未读");
 	}
 }

+ 29 - 5
src/main/java/com/mes/service/DcPlcClient.java

@@ -138,7 +138,9 @@ public class DcPlcClient {
 		return writeBoolean(mesAllowAddr, allow);
 	}
 
-	/** 轮询读本机需采集的过程参数(不含「无」与 MES 屏蔽) */
+	/**
+	 * 轮询读本机过程参数;若配置了 mes-allow-addr 则同拍读回 MES 允许(供界面灯)。
+	 */
 	public DcRunSnapshot readSnapshot() {
 		DcRunSnapshot s = new DcRunSnapshot();
 		if (!ensurePlc()) {
@@ -158,14 +160,14 @@ public class DcPlcClient {
 			}
 			// 压机行程次数:REAL 读后四舍五入成整数
 			s.pressSpm = fmtInt(plc.readFloat32(profile.getPressSpmAddr()));
-			// 电能能耗 DINT
-			if (!isBlank(profile.getEnergyAddr())) {
-				s.energyKwh = String.valueOf(plc.readInt32(profile.getEnergyAddr()));
-			}
+			// 能耗不读 PLC,由界面按额定功率×运行时间估算
 			if (!isBlank(profile.getDeviceRunAddr())) {
 				s.deviceRunning = plc.readBoolean(profile.getDeviceRunAddr());
 				s.deviceStateText = s.deviceRunning ? "运行" : "停止";
+				// 运行态读成功才算有效;默认 false 不得当「已停」结案
+				s.statusReadOk = true;
 			}
+			fillMesAllowFromPlc(s);
 		} catch (Exception e) {
 			log.warn("工位[{}] 读过程参数失败: {}", stationSn, e.getMessage());
 			markDisconnectedAndResetBackoff();
@@ -173,6 +175,28 @@ public class DcPlcClient {
 		return s;
 	}
 
+	/** 仅读 MES 允许点;失败或点未配返回 null */
+	public Boolean readMesAllow() {
+		if (mesAllowAddr.isEmpty() || !ensurePlc() || plc == null) {
+			return null;
+		}
+		try {
+			return Boolean.valueOf(plc.readBoolean(mesAllowAddr));
+		} catch (Exception e) {
+			log.warn("工位[{}] 读 MES允许 {} 失败: {}", stationSn, mesAllowAddr, e.getMessage());
+			markDisconnectedAndResetBackoff();
+			return null;
+		}
+	}
+
+	private void fillMesAllowFromPlc(DcRunSnapshot s) {
+		if (mesAllowAddr.isEmpty() || plc == null) {
+			return;
+		}
+		s.mesAllow = plc.readBoolean(mesAllowAddr);
+		s.mesAllowReadOk = true;
+	}
+
 	/** 仅读冲次累计;失败返回 null */
 	public Long readStrokeCount() {
 		if (!ensurePlc()) {

+ 15 - 2
src/main/java/com/mes/service/MesDcApiClient.java

@@ -28,7 +28,7 @@ public final class MesDcApiClient {
 
 	/**
 	 * 取本工位待开批次(PDA 已扫码入通用队列)。
-	 * 路径:{@code /js/a/mes/mesFlexDcYt/nextBatch};期望 data:batchCode、targetQty。
+	 * 路径:{@code /js/a/mes/mesFlexDcYt/nextBatch};期望 data:batchCode。
 	 */
 	public static JSONObject nextBatch(String serverIp, String stationSn) {
 		Map<String, String> p = new LinkedHashMap<String, String>();
@@ -37,7 +37,20 @@ public final class MesDcApiClient {
 	}
 
 	/**
-	 * 批次结案一次上报:按批次码追溯 + 过程参数(落 mes_flex_dc_yt)。
+	 * 清码:从服务端热表清掉本工位该批次码(待取/已取均可)。
+	 * sn、stationSn 服务端均必填。路径:{@code /js/a/mes/mesFlexQueue/clear}。
+	 */
+	public static JSONObject clear(String serverIp, String sn, String stationSn, String userCode) {
+		Map<String, String> p = new LinkedHashMap<String, String>();
+		p.put("sn", nvl(sn));
+		p.put("stationSn", nvl(stationSn));
+		p.put("userCode", nvl(userCode));
+		return post(serverIp, "/js/a/mes/mesFlexQueue/clear", p);
+	}
+
+	/**
+	 * 周期上传(约 2 分钟一段):qty=本段冲次差,带 clientId 幂等;
+	 * 成功看 data.needScanBatch / sessionEnded / mesAllow。
 	 * 路径:{@code /js/a/mes/mesFlexDcYt/completeBatch}。
 	 */
 	public static JSONObject completeBatch(String serverIp, Map<String, String> fields) {

+ 2 - 65
src/main/java/com/mes/ui/MainFrame.java

@@ -1,7 +1,6 @@
 package com.mes.ui;
 
 import com.mes.config.MesClientProperties;
-import com.mes.service.DcBatchPrinter;
 import com.mes.service.MesFlexQueuePushClient;
 import com.mes.util.SingleInstanceLock;
 import com.mes.util.UiImages;
@@ -24,7 +23,6 @@ import java.util.concurrent.atomic.AtomicInteger;
 
 /**
  * 一拖二大冲主窗:两台压机各自独立周期 / 结案;取批次订 SSE 门铃 + 断线慢轮询兜底。
- * 支持手动打印模式:结案入打印列表,工人确认后再送打。
  */
 public class MainFrame extends JFrame {
 
@@ -40,8 +38,6 @@ public class MainFrame extends JFrame {
 	private static MesClientProperties props;
 	private static final List<StationPanel> stationPanels = new ArrayList<StationPanel>();
 	private static WorkRecordPanel workRecordPanel;
-	/** 打印列表页(结案入队 / 手动送打后刷新) */
-	private static PrintListPanel printListPanel;
 	/** 取码队列 SSE(入队门铃 / 清码) */
 	private static MesFlexQueuePushClient pushClient;
 	/** SSE 断线时 IDLE 慢轮询 nextBatch */
@@ -102,9 +98,7 @@ public class MainFrame extends JFrame {
 		if (mes_app_title.isEmpty()) {
 			mes_app_title = "MES 一拖二大冲";
 		}
-		DcBatchPrinter.setPrinterName(p.getPrinterName());
 		mes_allow_enabled = p.isMesAllowEnabled();
-		log.info("打印机配置 name={}", trim(p.getPrinterName()).isEmpty() ? "(系统默认)" : trim(p.getPrinterName()));
 		log.info("MES允许开关 mes-allow-enabled={}", Boolean.valueOf(mes_allow_enabled));
 		List<MesClientProperties.StationConfig> list = p.getStations();
 		if (list == null || list.isEmpty()) {
@@ -149,7 +143,7 @@ public class MainFrame extends JFrame {
 	}
 
 	public MainFrame() {
-		setIconImage(Toolkit.getDefaultToolkit().getImage(UiImages.icon("logo.png")));
+		setIconImage(Toolkit.getDefaultToolkit().getImage(UiImages.icon("dayang-mes.png")));
 		setTitle(mes_app_title);
 		setBounds(40, 40, 1280, 720);
 		setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
@@ -208,7 +202,6 @@ public class MainFrame extends JFrame {
 		cards.setOpaque(false);
 		final List<JButton> stationNavBtns = new ArrayList<JButton>();
 		final JButton btnRecord = navBtn("工作记录", false);
-		final JButton btnPrintList = navBtn("打印列表", false);
 
 		for (int i = 0; i < stations.size(); i++) {
 			MesClientProperties.StationConfig sc = stations.get(i);
@@ -228,14 +221,11 @@ public class MainFrame extends JFrame {
 						styleNavSelected(stationNavBtns.get(j), j == idx);
 					}
 					styleNavSelected(btnRecord, false);
-					styleNavSelected(btnPrintList, false);
 				}
 			});
 		}
 		workRecordPanel = new WorkRecordPanel();
-		printListPanel = new PrintListPanel();
 		cards.add(workRecordPanel, "record");
-		cards.add(printListPanel, "print");
 
 		final JButton btnSettings = navBtn("设置", false);
 		// 重量级弹出,避免被卡片层盖住像点了没反应
@@ -265,34 +255,9 @@ public class MainFrame extends JFrame {
 		});
 		settingsMenu.add(miNext);
 		settingsMenu.add(miManual);
-		settingsMenu.addSeparator();
-		// 设置 → 打印:总开关;关则自动/列表都不送打
-		final JCheckBoxMenuItem miPrint = new JCheckBoxMenuItem("打印");
-		miPrint.setFont(new Font("微软雅黑", Font.PLAIN, 14));
-		miPrint.setSelected(DcBatchPrinter.isPrintEnabled());
-		miPrint.addActionListener(new ActionListener() {
-			@Override
-			public void actionPerformed(ActionEvent e) {
-				DcBatchPrinter.setPrintEnabled(miPrint.isSelected());
-			}
-		});
-		settingsMenu.add(miPrint);
-		// 设置 → 手动打印:开=结案入列表;关=结案自动打
-		final JCheckBoxMenuItem miManualPrint = new JCheckBoxMenuItem("手动打印");
-		miManualPrint.setFont(new Font("微软雅黑", Font.PLAIN, 14));
-		miManualPrint.setSelected(DcBatchPrinter.isManualPrintMode());
-		miManualPrint.addActionListener(new ActionListener() {
-			@Override
-			public void actionPerformed(ActionEvent e) {
-				DcBatchPrinter.setManualPrintMode(miManualPrint.isSelected());
-			}
-		});
-		settingsMenu.add(miManualPrint);
 		btnSettings.addActionListener(new ActionListener() {
 			@Override
 			public void actionPerformed(ActionEvent e) {
-				miPrint.setSelected(DcBatchPrinter.isPrintEnabled());
-				miManualPrint.setSelected(DcBatchPrinter.isManualPrintMode());
 				settingsMenu.show(btnSettings, 0, btnSettings.getHeight());
 			}
 		});
@@ -304,21 +269,6 @@ public class MainFrame extends JFrame {
 					styleNavSelected(stationNavBtns.get(j), false);
 				}
 				styleNavSelected(btnRecord, true);
-				styleNavSelected(btnPrintList, false);
-			}
-		});
-		btnPrintList.addActionListener(new ActionListener() {
-			@Override
-			public void actionPerformed(ActionEvent e) {
-				((CardLayout) cards.getLayout()).show(cards, "print");
-				for (int j = 0; j < stationNavBtns.size(); j++) {
-					styleNavSelected(stationNavBtns.get(j), false);
-				}
-				styleNavSelected(btnRecord, false);
-				styleNavSelected(btnPrintList, true);
-				if (printListPanel != null) {
-					printListPanel.reload();
-				}
 			}
 		});
 
@@ -331,7 +281,6 @@ public class MainFrame extends JFrame {
 			nav.add(b);
 		}
 		nav.add(btnRecord);
-		nav.add(btnPrintList);
 
 		JPanel page = new JPanel(new BorderLayout(0, 0));
 		page.setOpaque(false);
@@ -379,21 +328,9 @@ public class MainFrame extends JFrame {
 		});
 	}
 
-	/** 结案入队 / 送打后刷新打印列表 */
-	public static void refreshPrintList() {
-		SwingUtilities.invokeLater(new Runnable() {
-			@Override
-			public void run() {
-				if (printListPanel != null) {
-					printListPanel.reload();
-				}
-			}
-		});
-	}
-
 	/** 每台压机各自 startStationLoop,共享 Timer/线程池一律不用 */
 	private static void startStationLoops() {
-		int period = 500;
+		int period = 1000;
 		if (props != null && props.getTickMs() > 0) {
 			period = props.getTickMs();
 		}

Разница между файлами не показана из-за своего большого размера
+ 614 - 235
src/main/java/com/mes/ui/StationPanel.java


+ 8 - 5
src/main/resources/config/application.yml

@@ -17,24 +17,27 @@ mes:
   app-title: MES 一拖二大冲
   server-ip: 192.168.9.19
 #  server-ip: 127.0.0.1
-  tick-ms: 500
-  printer-name:
+  tick-ms: 1000
   # 是否写 PLC MES允许运行点。false=开批/结案/清码都不写,本地仍取批盯冲次
-  mes-allow-enabled: true
+  mes-allow-enabled: false
+  # 能耗=额定功率kW×本批设备运行小时(不读 PLC、不做能耗曲线);气垫/顶杆本线不采
   stations:
     - id: 1
       title: TE2-800
-      station-sn: DC-TE2
+      station-sn: DC-800T
       press-profile: TE2_800
       plc-ip: 192.168.0.1
       plc-port: 102
       # MES允许:
       mes-allow-addr: DB5.0.0
+      # 额定功率 kW(按铭牌填;0=不估算能耗)
+      rated-power-kw: 200
     - id: 2
       title: TL4-1600
-      station-sn: DC-TL4
+      station-sn: DC-800T1600
       press-profile: TL4_1600
       plc-ip: 192.168.1.99
       plc-port: 102
       # MES允许:点表 DB76.DBX128.1
       mes-allow-addr: DB76.128.1
+      rated-power-kw: 0

BIN
src/main/resources/images/dayang-mes.ico


BIN
src/main/resources/images/icon.ico


BIN
src/main/resources/images/icons/dayang-mes.png


BIN
src/main/resources/images/icons/logo.png