Bläddra i källkod

新增模具寿命判断

zxl 3 veckor sedan
förälder
incheckning
42bfb06ac1

+ 15 - 0
src/main/java/com/mes/config/MesClientProperties.java

@@ -19,6 +19,12 @@ public class MesClientProperties {
 	private int tickMs = 500;
 	/** 结案小票打印机名;空=系统默认 */
 	private String printerName = "";
+	/**
+	 * 是否写 PLC MES 允许运行点。
+	 * false:开批/结案/清码都不写允许信号,本地仍可取批盯冲次。
+	 * yml:{@code mes-allow-enabled}
+	 */
+	private boolean mesAllowEnabled = true;
 	/** 两台压机工位 */
 	private List<StationConfig> stations = new ArrayList<StationConfig>();
 
@@ -138,6 +144,15 @@ public class MesClientProperties {
 		this.printerName = printerName;
 	}
 
+	/** 是否写 PLC MES 允许运行点 */
+	public boolean isMesAllowEnabled() {
+		return mesAllowEnabled;
+	}
+
+	public void setMesAllowEnabled(boolean mesAllowEnabled) {
+		this.mesAllowEnabled = mesAllowEnabled;
+	}
+
 	public List<StationConfig> getStations() {
 		return stations;
 	}

+ 40 - 0
src/main/java/com/mes/service/DcBatchPrinter.java

@@ -28,16 +28,32 @@ import java.util.Map;
 /**
  * 一拖二结案小票:上方居中批次码二维码,下方居中批次码文字。
  * 打印机名由 yml {@code mes.printer-name} 指定;空则用系统默认打印机。
+ * 界面「设置 → 打印」开关控制是否真正送打;勾选状态本地记住。
  */
 public final class DcBatchPrinter {
 
 	private static final Logger log = LoggerFactory.getLogger(DcBatchPrinter.class);
 
+	/** Preferences 节点:记住「打印」开关 */
+	private static final String PREF_NODE = "com.mes.dachong.yt";
+	private static final String PREF_PRINT_ENABLED = "printEnabled";
+
 	/** 二维码边长(像素,按可打印宽度再裁) */
 	private static final int QR_PREF_PX = 200;
 
 	/** 目标打印机名称(空=默认打印机) */
 	private static volatile String printerName = "";
+	/** 界面「打印」开关;默认开 */
+	private static volatile boolean printEnabled = true;
+
+	static {
+		try {
+			printEnabled = java.util.prefs.Preferences.userRoot()
+					.node(PREF_NODE).getBoolean(PREF_PRINT_ENABLED, true);
+		} catch (Exception ignored) {
+			printEnabled = true;
+		}
+	}
 
 	private DcBatchPrinter() {
 	}
@@ -47,8 +63,28 @@ public final class DcBatchPrinter {
 		printerName = name == null ? "" : name.trim();
 	}
 
+	/** 当前是否允许结案打印(设置菜单「打印」) */
+	public static boolean isPrintEnabled() {
+		return printEnabled;
+	}
+
+	/**
+	 * 设置是否打印,并写入本机 Preferences(重启仍有效)。
+	 */
+	public static void setPrintEnabled(boolean enabled) {
+		printEnabled = enabled;
+		try {
+			java.util.prefs.Preferences.userRoot().node(PREF_NODE)
+					.putBoolean(PREF_PRINT_ENABLED, enabled);
+		} catch (Exception e) {
+			log.warn("保存打印开关失败: {}", e.getMessage());
+		}
+		log.info("打印开关={}", Boolean.valueOf(enabled));
+	}
+
 	/**
 	 * 连接打印机并送打批次码小票(上二维码、下批次码,均居中)。
+	 * 开关关闭时直接跳过并返回 false。
 	 *
 	 * @param batchCode 批次码(二维码内容与下方文字)
 	 * @param produceTime 保留入参兼容调用方(本版小票不印)
@@ -56,6 +92,10 @@ public final class DcBatchPrinter {
 	 * @return 是否送打印成功
 	 */
 	public static boolean printBatch(final String batchCode, final String produceTime, final int qty) {
+		if (!printEnabled) {
+			log.info("打印开关已关,跳过送打 batch={}", batchCode == null ? "" : batchCode.trim());
+			return false;
+		}
 		final String code = batchCode == null ? "" : batchCode.trim();
 		if (code.isEmpty()) {
 			log.warn("批次码为空,跳过打印");

+ 46 - 3
src/main/java/com/mes/service/DcPlcClient.java

@@ -24,6 +24,8 @@ public class DcPlcClient {
 	private final DcPressProfiles profile;
 	/** MES 允许 BOOL;空则跳过写 PLC */
 	private final String mesAllowAddr;
+	/** 总开关:false 时 setMesAllow 直接跳过,不发开/关 */
+	private final boolean mesAllowEnabled;
 
 	private S7PLC plc;
 	private volatile boolean connected;
@@ -32,12 +34,26 @@ public class DcPlcClient {
 
 	public DcPlcClient(String stationSn, String plcIp, int plcPort,
 			DcPressProfiles profile, String mesAllowAddr) {
+		this(stationSn, plcIp, plcPort, profile, mesAllowAddr, true);
+	}
+
+	/**
+	 * @param mesAllowEnabled false=完全不写 MES 允许点(开批/结案/清码都跳过)
+	 */
+	public DcPlcClient(String stationSn, String plcIp, int plcPort,
+			DcPressProfiles profile, String mesAllowAddr, boolean mesAllowEnabled) {
 		this.stationSn = stationSn == null ? "" : stationSn.trim();
 		this.plcIp = plcIp == null ? "" : plcIp.trim();
 		this.plcPort = plcPort <= 0 ? 102 : plcPort;
 		this.profile = profile == null ? DcPressProfiles.TE2_800 : profile;
 		// 两台都有 MES 允许;地址未提供前 yml 留空,开批/结案仍本地盯冲次
 		this.mesAllowAddr = mesAllowAddr == null ? "" : mesAllowAddr.trim();
+		this.mesAllowEnabled = mesAllowEnabled;
+	}
+
+	/** 是否允许写 MES 允许点(yml mes-allow-enabled) */
+	public boolean isMesAllowEnabled() {
+		return mesAllowEnabled;
 	}
 
 	public String getStationSn() {
@@ -105,9 +121,15 @@ public class DcPlcClient {
 	}
 
 	/**
-	 * 写 MES 允许运行。点未配置时返回 false(业务仍可本地走完)。
+	 * 写 MES 允许运行。
+	 * 开关关闭或点未配置时返回 false(业务仍可本地走完)。
 	 */
 	public boolean setMesAllow(boolean allow) {
+		if (!mesAllowEnabled) {
+			log.debug("工位[{}] mes-allow-enabled=false,跳过写 PLC allow={}",
+					stationSn, Boolean.valueOf(allow));
+			return false;
+		}
 		if (mesAllowAddr.isEmpty()) {
 			log.warn("工位[{}] mes-allow-addr 未配置(预留),跳过写 PLC allow={}",
 					stationSn, Boolean.valueOf(allow));
@@ -127,13 +149,15 @@ public class DcPlcClient {
 			long stroke = plc.readUInt32(profile.getStrokeCountAddr());
 			s.strokeCount = stroke;
 			s.strokeCountText = String.valueOf(stroke);
-			s.cylinderPressure = fmtFloat(plc.readFloat32(profile.getCylinderPressureAddr()));
+			// 顶缸压力:界面/上报保留两位小数
+			s.cylinderPressure = fmtFloatScale(plc.readFloat32(profile.getCylinderPressureAddr()), 2);
 			if (profile.isTonnageDint()) {
 				s.tonnage = String.valueOf(plc.readInt32(profile.getTonnageAddr()));
 			} else {
 				s.tonnage = fmtFloat(plc.readFloat32(profile.getTonnageAddr()));
 			}
-			s.pressSpm = fmtFloat(plc.readFloat32(profile.getPressSpmAddr()));
+			// 压机行程次数:REAL 读后四舍五入成整数
+			s.pressSpm = fmtInt(plc.readFloat32(profile.getPressSpmAddr()));
 			// 电能能耗 DINT
 			if (!isBlank(profile.getEnergyAddr())) {
 				s.energyKwh = String.valueOf(plc.readInt32(profile.getEnergyAddr()));
@@ -230,4 +254,23 @@ public class DcPlcClient {
 		}
 		return s;
 	}
+
+	/** 固定小数位(如顶缸压力 2 位) */
+	private static String fmtFloatScale(float v, int scale) {
+		if (Float.isNaN(v) || Float.isInfinite(v)) {
+			return "";
+		}
+		if (scale < 0) {
+			return fmtFloat(v);
+		}
+		return String.format(java.util.Locale.US, "%." + scale + "f", Float.valueOf(v));
+	}
+
+	/** REAL → 四舍五入整数 */
+	private static String fmtInt(float v) {
+		if (Float.isNaN(v) || Float.isInfinite(v)) {
+			return "";
+		}
+		return String.valueOf(Math.round(v));
+	}
 }

+ 17 - 0
src/main/java/com/mes/ui/MainFrame.java

@@ -33,6 +33,8 @@ public class MainFrame extends JFrame {
 
 	public static String mes_server_ip = "";
 	public static String mes_app_title = "MES 一拖二大冲";
+	/** 是否写 PLC MES 允许运行点;false=跳过开/关允许 */
+	public static boolean mes_allow_enabled = true;
 
 	private static MesClientProperties props;
 	private static final List<StationPanel> stationPanels = new ArrayList<StationPanel>();
@@ -98,7 +100,9 @@ public class MainFrame extends JFrame {
 			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()) {
 			log.warn("mes.stations 为空");
@@ -254,9 +258,22 @@ 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);
 		btnSettings.addActionListener(new ActionListener() {
 			@Override
 			public void actionPerformed(ActionEvent e) {
+				miPrint.setSelected(DcBatchPrinter.isPrintEnabled());
 				settingsMenu.show(btnSettings, 0, btnSettings.getHeight());
 			}
 		});

+ 30 - 5
src/main/java/com/mes/ui/StationPanel.java

@@ -65,6 +65,8 @@ public class StationPanel extends JPanel {
 
 	private volatile Phase phase = Phase.IDLE;
 	private volatile String batchCode = "";
+	/** 本件结案工号:优先 nextBatch 带回的入队 userCode */
+	private volatile String currentUserCode = "";
 	private volatile int targetQty;
 	/** 开批时冲次起点;中途复位后按已产重定 */
 	private volatile long baseStrokeCount;
@@ -113,8 +115,9 @@ public class StationPanel extends JPanel {
 		this.cfg = cfg;
 		this.profile = cfg.resolveProfile();
 		this.serverIp = serverIp == null ? "" : serverIp.trim();
+		// mes-allow-enabled=false 时开批/结案/清码都不写 PLC 允许点
 		this.plc = new DcPlcClient(cfg.getStationSn(), cfg.getPlcIp(), cfg.getPlcPort(),
-				this.profile, cfg.getMesAllowAddr());
+				this.profile, cfg.getMesAllowAddr(), MainFrame.mes_allow_enabled);
 
 		setLayout(new BorderLayout(0, 0));
 		setBackground(UiTheme.BG);
@@ -489,7 +492,13 @@ public class StationPanel extends JPanel {
 						log.warn("工位[{}] nextBatch 成功但缺 batchCode/targetQty: {}", cfg.getStationSn(), ret);
 						return;
 					}
-					startBatchFromPda(code, target);
+					String queueUser = MesDcApiClient.dataStr(ret, "userCode");
+					if (queueUser.isEmpty()) {
+						queueUser = MesDcApiClient.dataStr(ret, "ucode");
+					}
+					log.info("工位[{}] nextBatch 成功 batch={} target={} userCode={}",
+							cfg.getStationSn(), code, Integer.valueOf(target), queueUser);
+					startBatchFromPda(code, target, queueUser);
 				} finally {
 					nextBusy.set(false);
 				}
@@ -497,7 +506,10 @@ public class StationPanel extends JPanel {
 		}, "dc-yt-next-" + cfg.getStationSn()).start();
 	}
 
-	private void startBatchFromPda(String code, int target) {
+	/**
+	 * @param queueUserCode PDA 入队工号(可空)
+	 */
+	private void startBatchFromPda(String code, int target, String queueUserCode) {
 		if (phase == Phase.RUN || phase == Phase.DONE) {
 			return;
 		}
@@ -517,6 +529,7 @@ public class StationPanel extends JPanel {
 				return;
 			}
 			batchCode = code;
+			currentUserCode = queueUserCode == null ? "" : queueUserCode.trim();
 			targetQty = target;
 			baseStrokeCount = base.longValue();
 			lastStrokeCount = baseStrokeCount;
@@ -525,8 +538,16 @@ public class StationPanel extends JPanel {
 			boolean wrote = plc.setMesAllow(true);
 			mesAllowOn = wrote;
 			phase = Phase.RUN;
-			final String tip = (wrote ? "批次已开,MES允许已写" : "批次已开(允许点未配/写失败,本地仍盯冲次)")
-					+ "  起始冲次=" + baseStrokeCount;
+			// 开批提示:区分开关关 / 点未配或写失败
+			String tipCore;
+			if (wrote) {
+				tipCore = "批次已开,MES允许已写";
+			} else if (!plc.isMesAllowEnabled()) {
+				tipCore = "批次已开(MES允许开关已关,未写PLC)";
+			} else {
+				tipCore = "批次已开(允许点未配/写失败,本地仍盯冲次)";
+			}
+			final String tip = tipCore + "  起始冲次=" + baseStrokeCount;
 			final String codeUi = batchCode;
 			final int targetUi = targetQty;
 			SwingUtilities.invokeLater(new Runnable() {
@@ -676,6 +697,9 @@ public class StationPanel extends JPanel {
 					fields.put("aborted", aborted ? "1" : "0");
 					fields.put("manual", manual ? "1" : "0");
 					fields.put("result", passResult);
+					// 结案工号:取批时队列带回的入队工号;空则 system
+					String jobUser = currentUserCode == null ? "" : currentUserCode.trim();
+					fields.put("userCode", jobUser.isEmpty() ? "system" : jobUser);
 					fields.put("pressProfile", profile.name());
 					fields.put("dieHeight", nvl(snap.dieHeight));
 					fields.put("strokeCount", nvl(snap.strokeCountText));
@@ -963,6 +987,7 @@ public class StationPanel extends JPanel {
 	private void resetToIdle(String msg) {
 		phase = Phase.IDLE;
 		batchCode = "";
+		currentUserCode = "";
 		targetQty = 0;
 		baseStrokeCount = 0L;
 		synchronized (sampleBuf) {

+ 3 - 1
src/main/resources/config/application.yml

@@ -15,9 +15,11 @@ logging:
 
 mes:
   app-title: MES 一拖二大冲
-  server-ip: 127.0.0.1
+  server-ip: 192.168.9.19
   tick-ms: 500
   printer-name:
+  # 是否写 PLC MES允许运行点。false=开批/结案/清码都不写,本地仍取批盯冲次
+  mes-allow-enabled: false
   stations:
     - id: 1
       title: TE2-800