|
|
@@ -4,7 +4,7 @@ import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.mes.config.MesClientProperties;
|
|
|
import com.mes.entity.DcRunSnapshot;
|
|
|
import com.mes.service.DcBatchPrinter;
|
|
|
-import com.mes.service.DcPackCode;
|
|
|
+import com.mes.service.DcLineBatchContext;
|
|
|
import com.mes.service.DcPlcClient;
|
|
|
import com.mes.service.DcWorkRecordStore;
|
|
|
import com.mes.service.MesDcApiClient;
|
|
|
@@ -24,7 +24,8 @@ import java.util.Map;
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
|
|
/**
|
|
|
- * 自动化大冲单线面板:轮询取批次 → MES允许=true → 读 DB260 盯产量 → 结案再允许=false → 打印。
|
|
|
+ * 自动化大冲线体主面板:取批次 → MES允许 → 读 DB260 展示;
|
|
|
+ * 结案打印由压机5冲次达标触发(本页不再按 DB260 产量自动结案)。
|
|
|
*/
|
|
|
public class StationPanel extends JPanel {
|
|
|
|
|
|
@@ -58,10 +59,20 @@ public class StationPanel extends JPanel {
|
|
|
private volatile long lastPollBatchAtMs;
|
|
|
/** 最近一次 DB260 快照,结案时一并上传(只传一次,不采样堆) */
|
|
|
private volatile DcRunSnapshot lastSnap = new DcRunSnapshot();
|
|
|
+ /** 结案上传未成功时的待重试报文(DONE 态由 tick 续传,避免热队列卡「已取」) */
|
|
|
+ private volatile Map<String, String> pendingCompleteFields;
|
|
|
+ /** 挂起结案说明文案(达标/手动/强制) */
|
|
|
+ private volatile String pendingHow = "";
|
|
|
+ /** 挂起结案对应批次码(续传提示用) */
|
|
|
+ private volatile String pendingBatchCode = "";
|
|
|
+ /** 挂起结案数量 */
|
|
|
+ private volatile int pendingQty;
|
|
|
+ /** 异步打印是否已成功送出(仅提示,不挡结案) */
|
|
|
+ private volatile boolean pendingPrinted;
|
|
|
+ /** 结案上传重试互斥,避免 finish 线程与 tick 同时打 completeBatch */
|
|
|
+ private final AtomicBoolean completeRetryBusy = new AtomicBoolean(false);
|
|
|
|
|
|
private final JLabel lblStation;
|
|
|
- /** 顶栏 PLC 地址文案(不含连接状态) */
|
|
|
- private final JLabel lblPlc;
|
|
|
private final JLabel lblStatus;
|
|
|
private final JTextField txtBatch;
|
|
|
private final JTextField txtTarget;
|
|
|
@@ -71,6 +82,10 @@ public class StationPanel extends JPanel {
|
|
|
private final JTextField txtProduced;
|
|
|
private final JTextField txtDowntime;
|
|
|
private final JTextField txtTakt;
|
|
|
+ /** 产线状态文案示值 */
|
|
|
+ private final JTextField txtLineState;
|
|
|
+ /** 五台压机本批进度(主界面汇总,结案看压机5) */
|
|
|
+ private final JTextField txtPressProgress;
|
|
|
/** 服务端 SSE 呼吸灯 */
|
|
|
private final BreathingLight serverHeartbeat;
|
|
|
/** PLC 连接指示灯:绿=已连,红=未连 */
|
|
|
@@ -127,9 +142,6 @@ public class StationPanel extends JPanel {
|
|
|
lblLineState = headerStateLabel("待机");
|
|
|
lampMesAllow = new StatusLight();
|
|
|
lblMesAllowState = headerStateLabel("关");
|
|
|
- lblPlc = new JLabel(plcAddrText());
|
|
|
- lblPlc.setFont(new Font("Consolas", Font.PLAIN, 12));
|
|
|
- lblPlc.setForeground(new Color(160, 210, 220));
|
|
|
|
|
|
JPanel east = new JPanel(new FlowLayout(FlowLayout.RIGHT, 14, 0));
|
|
|
east.setOpaque(false);
|
|
|
@@ -137,10 +149,6 @@ public class StationPanel extends JPanel {
|
|
|
east.add(headerLampItem("PLC", lampPlc, lblPlcState));
|
|
|
east.add(headerLampItem("产线", lampLineState, lblLineState));
|
|
|
east.add(headerLampItem("MES允许", lampMesAllow, lblMesAllowState));
|
|
|
- // 有 IP 时才跟地址
|
|
|
- if (!plcAddrText().isEmpty()) {
|
|
|
- east.add(lblPlc);
|
|
|
- }
|
|
|
header.add(titleCol, BorderLayout.WEST);
|
|
|
header.add(east, BorderLayout.EAST);
|
|
|
|
|
|
@@ -158,52 +166,75 @@ public class StationPanel extends JPanel {
|
|
|
north.add(lblStatus, BorderLayout.SOUTH);
|
|
|
add(north, BorderLayout.NORTH);
|
|
|
|
|
|
- JPanel main = new JPanel(new BorderLayout(0, 14));
|
|
|
+ // 本批 : 线体过程 按 1:3 等比分高;格子有最小高度,再矮则滚动
|
|
|
+ JPanel main = new JPanel(new GridBagLayout());
|
|
|
main.setOpaque(false);
|
|
|
main.setBorder(new EmptyBorder(16, 20, 16, 20));
|
|
|
|
|
|
- // —— 本批:上方两格,固定偏好高度 ——
|
|
|
JPanel batchCard = UiTheme.card();
|
|
|
batchCard.setLayout(new BorderLayout(0, 10));
|
|
|
batchCard.add(UiTheme.sectionTitle("本批"), BorderLayout.NORTH);
|
|
|
JPanel batchGrid = new JPanel(new GridLayout(1, 2, 14, 0));
|
|
|
batchGrid.setOpaque(false);
|
|
|
batchGrid.setPreferredSize(new Dimension(10, UiTheme.TILE_PREF_H));
|
|
|
+ batchGrid.setMinimumSize(new Dimension(10, UiTheme.TILE_MIN_H));
|
|
|
txtBatch = roField();
|
|
|
txtTarget = roField();
|
|
|
batchGrid.add(UiTheme.paramTile("批次码", txtBatch, UiTheme.STRIPE_SIDE));
|
|
|
batchGrid.add(UiTheme.paramTile("本批目标数量", txtTarget, UiTheme.STRIPE_SIDE));
|
|
|
batchCard.add(batchGrid, BorderLayout.CENTER);
|
|
|
|
|
|
- // —— 线体过程:占满剩余高度,大字示值填空 ——
|
|
|
JPanel runCard = UiTheme.card();
|
|
|
runCard.setLayout(new BorderLayout(0, 10));
|
|
|
runCard.add(UiTheme.sectionTitle("线体过程"), BorderLayout.NORTH);
|
|
|
- JPanel grid = new JPanel(new GridLayout(2, 3, 14, 14));
|
|
|
+ JPanel grid = new JPanel(new GridLayout(3, 3, 14, 14));
|
|
|
grid.setOpaque(false);
|
|
|
+ // 3 行格子最小总高,防止被压成一条线
|
|
|
+ grid.setMinimumSize(new Dimension(10, UiTheme.TILE_MIN_H * 3 + 28));
|
|
|
+ grid.setPreferredSize(new Dimension(10, UiTheme.TILE_PREF_H * 3 + 28));
|
|
|
txtCurrentPart = roField();
|
|
|
txtNextPart = roField();
|
|
|
txtActualQty = roField();
|
|
|
txtProduced = roField();
|
|
|
- txtProduced.setFont(UiTheme.FONT_SN);
|
|
|
txtDowntime = roField();
|
|
|
txtTakt = roField();
|
|
|
- grid.add(UiTheme.paramTile("当前零件", txtCurrentPart, UiTheme.STRIPE_SIDE));
|
|
|
- grid.add(UiTheme.paramTile("下一零件", txtNextPart, UiTheme.STRIPE_SIDE));
|
|
|
- grid.add(UiTheme.paramTile("累计实际产量", txtActualQty, UiTheme.STRIPE_SIDE));
|
|
|
- grid.add(UiTheme.paramTile("本批已产", txtProduced, UiTheme.STRIPE_SIDE));
|
|
|
+ txtPressProgress = roField();
|
|
|
+ txtLineState = roField();
|
|
|
+ grid.add(UiTheme.paramTile("当前零件名称", txtCurrentPart, UiTheme.STRIPE_SIDE));
|
|
|
+ grid.add(UiTheme.paramTile("下一零件名称", txtNextPart, UiTheme.STRIPE_SIDE));
|
|
|
+ grid.add(UiTheme.paramTile("实际产量", txtActualQty, UiTheme.STRIPE_SIDE));
|
|
|
grid.add(UiTheme.paramTile("停机时间", txtDowntime, UiTheme.STRIPE_SIDE));
|
|
|
grid.add(UiTheme.paramTile("生产节拍", txtTakt, UiTheme.STRIPE_SIDE));
|
|
|
+ grid.add(UiTheme.paramTile("产线状态", txtLineState, UiTheme.STRIPE_SIDE));
|
|
|
+ grid.add(UiTheme.paramTile("本批已产", txtProduced, UiTheme.STRIPE_SIDE));
|
|
|
+ UiTheme.markTileValueBase(txtProduced, UiTheme.FONT_SN.getSize2D());
|
|
|
+ grid.add(UiTheme.paramTile("五台冲次数量进度", txtPressProgress, UiTheme.STRIPE_SIDE));
|
|
|
+ UiTheme.markTileValueBase(txtPressProgress, UiTheme.FONT_BODY.getSize2D());
|
|
|
runCard.add(grid, BorderLayout.CENTER);
|
|
|
|
|
|
- main.add(batchCard, BorderLayout.NORTH);
|
|
|
- main.add(runCard, BorderLayout.CENTER);
|
|
|
- add(main, BorderLayout.CENTER);
|
|
|
-
|
|
|
- JPanel actions = new JPanel(new BorderLayout(0, 0));
|
|
|
+ GridBagConstraints gc = new GridBagConstraints();
|
|
|
+ gc.gridx = 0;
|
|
|
+ gc.fill = GridBagConstraints.BOTH;
|
|
|
+ gc.weightx = 1;
|
|
|
+ gc.gridy = 0;
|
|
|
+ gc.weighty = 1; // 本批约 1 行
|
|
|
+ main.add(batchCard, gc);
|
|
|
+ gc.gridy = 1;
|
|
|
+ gc.weighty = 3; // 线体过程约 3 行,与本批等比分高
|
|
|
+ gc.insets = new Insets(14, 0, 0, 0);
|
|
|
+ main.add(runCard, gc);
|
|
|
+
|
|
|
+ JScrollPane scroll = new JScrollPane(main);
|
|
|
+ scroll.setBorder(BorderFactory.createEmptyBorder());
|
|
|
+ scroll.setOpaque(false);
|
|
|
+ scroll.getViewport().setOpaque(false);
|
|
|
+ scroll.getVerticalScrollBar().setUnitIncrement(16);
|
|
|
+ add(scroll, BorderLayout.CENTER);
|
|
|
+
|
|
|
+ // 底部操作区:只保留「取批次」按钮
|
|
|
+ JPanel actions = new JPanel(new FlowLayout(FlowLayout.RIGHT, 10, 0));
|
|
|
actions.setOpaque(false);
|
|
|
actions.setBorder(new EmptyBorder(0, 20, 16, 20));
|
|
|
- JLabel tip = UiTheme.mutedLabel("正常靠 SSE 自动取批;未收到推送可点「取批次」,或等约 15 秒安全轮询");
|
|
|
btnNext = UiTheme.primaryBtn("取批次");
|
|
|
btnNext.addActionListener(new ActionListener() {
|
|
|
@Override
|
|
|
@@ -211,11 +242,7 @@ public class StationPanel extends JPanel {
|
|
|
onManualNextClick();
|
|
|
}
|
|
|
});
|
|
|
- JPanel btns = new JPanel(new FlowLayout(FlowLayout.RIGHT, 10, 0));
|
|
|
- btns.setOpaque(false);
|
|
|
- btns.add(btnNext);
|
|
|
- actions.add(tip, BorderLayout.WEST);
|
|
|
- actions.add(btns, BorderLayout.EAST);
|
|
|
+ actions.add(btnNext);
|
|
|
add(actions, BorderLayout.SOUTH);
|
|
|
}
|
|
|
|
|
|
@@ -235,8 +262,8 @@ public class StationPanel extends JPanel {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 周期:重连、刷 DB260;RUN 算产量差达标结案。
|
|
|
- * 取批由 SSE 门铃 / 断线兜底触发,不在 tick 里狂轮询。
|
|
|
+ * 周期:重连、刷 DB260;RUN 只展示线体产量差,不按 DB260 自动结案。
|
|
|
+ * 结案由压机5冲次达标触发 {@link #finishFromPress5(int)}。
|
|
|
*/
|
|
|
public void tick() {
|
|
|
if (busy.get()) {
|
|
|
@@ -251,6 +278,7 @@ public class StationPanel extends JPanel {
|
|
|
lastSnap = snap;
|
|
|
}
|
|
|
refreshSnapshotUi(snap);
|
|
|
+ refreshPressProgressUi();
|
|
|
if (phase == Phase.IDLE) {
|
|
|
if (!MainFrame.isMesServerOnline()) {
|
|
|
setStatusUi("空闲:MES/SSE 未连接,等待服务端…");
|
|
|
@@ -259,14 +287,19 @@ public class StationPanel extends JPanel {
|
|
|
}
|
|
|
return;
|
|
|
}
|
|
|
+ if (phase == Phase.DONE) {
|
|
|
+ // 上传曾失败:用挂起报文续传,成功前不重新开批、不回空闲
|
|
|
+ retryPendingCompleteIfAny();
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (phase == Phase.RUN) {
|
|
|
- // 产量差达标;若中途实际产量被复位变小,保留已产并重定起点
|
|
|
+ // 线体产量差仅展示;结案看压机5
|
|
|
updateProducedAgainstActual(snap.actualQty);
|
|
|
setText(txtProduced, String.valueOf(producedQty));
|
|
|
- setStatusUi("生产中 批次=" + batchCode + " 已产 " + producedQty + " / 目标 " + targetQty);
|
|
|
- if (producedQty >= targetQty) {
|
|
|
- finishBatch(producedQty, false);
|
|
|
- }
|
|
|
+ int p5 = DcLineBatchContext.getPressProduced(5);
|
|
|
+ setStatusUi("生产中 批次=" + batchCode
|
|
|
+ + " 压机5 " + p5 + " / " + targetQty
|
|
|
+ + " (达标后打印结案)");
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
log.warn("工位[{}] tick 异常: {}", cfg.getStationSn(), e.getMessage());
|
|
|
@@ -288,14 +321,21 @@ public class StationPanel extends JPanel {
|
|
|
tryAutoNextFromPush();
|
|
|
}
|
|
|
|
|
|
- /** SSE 清码:占用同一批次则复位 */
|
|
|
+ /**
|
|
|
+ * SSE 清码:本机正占用同一批次码则关允许并回空闲。
|
|
|
+ * 结案上传中(DONE+挂起报文)不打断,避免丢续传导致热队列卡「已取」。
|
|
|
+ */
|
|
|
public void applyClearedFromPush(String clearedSn) {
|
|
|
String local = nvl(batchCode);
|
|
|
String remote = nvl(clearedSn);
|
|
|
if (local.isEmpty() || remote.isEmpty() || !local.equalsIgnoreCase(remote)) {
|
|
|
return;
|
|
|
}
|
|
|
- if (phase == Phase.IDLE || phase == Phase.DONE) {
|
|
|
+ if (phase == Phase.IDLE) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (phase == Phase.DONE && pendingCompleteFields != null) {
|
|
|
+ log.info("工位[{}] 结案上传中收到清码 sn={},不打断", cfg.getStationSn(), local);
|
|
|
return;
|
|
|
}
|
|
|
if (!busy.compareAndSet(false, true)) {
|
|
|
@@ -304,6 +344,8 @@ public class StationPanel extends JPanel {
|
|
|
try {
|
|
|
log.info("工位[{}] 收到清码推送,复位本地 batch={}", cfg.getStationSn(), local);
|
|
|
plc.setMesAllow(false);
|
|
|
+ pendingCompleteFields = null;
|
|
|
+ // resetToIdle 内会关闭共享批次并通知压机页冲刷
|
|
|
resetToIdle("服务端已清码 " + local);
|
|
|
MainFrame.setMenuStatus(cfg.getStationSn() + " 已清码 " + local, 0);
|
|
|
} finally {
|
|
|
@@ -311,51 +353,60 @@ public class StationPanel extends JPanel {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /** 开批失败后延迟再 next */
|
|
|
- private void scheduleNextRetry(long delayMs) {
|
|
|
- final long wait = delayMs > 0L ? delayMs : 3000L;
|
|
|
- new Thread(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- try {
|
|
|
- Thread.sleep(wait);
|
|
|
- } catch (InterruptedException ie) {
|
|
|
- Thread.currentThread().interrupt();
|
|
|
- return;
|
|
|
- }
|
|
|
- lastPollBatchAtMs = 0L;
|
|
|
- tryAutoNextFromPush();
|
|
|
- }
|
|
|
- }, "dc-next-retry-" + cfg.getStationSn()).start();
|
|
|
+ /** 异步 nextBatch,不堵 PLC tick(自动门铃/兜底,带 2s 节流) */
|
|
|
+ public void requestNextAsync() {
|
|
|
+ requestNextAsync(false);
|
|
|
}
|
|
|
|
|
|
- /** 异步 nextBatch,不堵 PLC tick */
|
|
|
- public void requestNextAsync() {
|
|
|
+ /**
|
|
|
+ * 异步 nextBatch。
|
|
|
+ *
|
|
|
+ * @param forceManual true=手动按钮:跳过节流,必打日志,失败把服务端文案顶到状态条
|
|
|
+ */
|
|
|
+ public void requestNextAsync(final boolean forceManual) {
|
|
|
if (phase != Phase.IDLE) {
|
|
|
+ if (forceManual) {
|
|
|
+ log.info("工位[{}] 手动取批次忽略:当前 phase={}", cfg.getStationSn(), phase);
|
|
|
+ }
|
|
|
return;
|
|
|
}
|
|
|
long now = System.currentTimeMillis();
|
|
|
- if (now - lastPollBatchAtMs < POLL_BATCH_INTERVAL_MS) {
|
|
|
+ if (!forceManual && now - lastPollBatchAtMs < POLL_BATCH_INTERVAL_MS) {
|
|
|
return;
|
|
|
}
|
|
|
lastPollBatchAtMs = now;
|
|
|
if (serverIp.isEmpty()) {
|
|
|
setStatusUi("空闲:等待扫码(server-ip 未配,仅可联调模拟)");
|
|
|
+ log.warn("工位[{}] 取批次中止:server-ip 未配置", cfg.getStationSn());
|
|
|
return;
|
|
|
}
|
|
|
if (!nextBusy.compareAndSet(false, true)) {
|
|
|
+ if (forceManual) {
|
|
|
+ setStatusUi("取批次进行中,请稍候…");
|
|
|
+ log.info("工位[{}] 手动取批次:已有请求在飞,跳过重复点击", cfg.getStationSn());
|
|
|
+ }
|
|
|
return;
|
|
|
}
|
|
|
+ log.info("工位[{}] 开始 nextBatch{}", cfg.getStationSn(), forceManual ? "(手动)" : "");
|
|
|
new Thread(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
try {
|
|
|
JSONObject ret = MesDcApiClient.nextBatch(serverIp, cfg.getStationSn());
|
|
|
if (phase != Phase.IDLE) {
|
|
|
+ log.info("工位[{}] nextBatch 返回时已非空闲 phase={},丢弃结果",
|
|
|
+ cfg.getStationSn(), phase);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (ret == null) {
|
|
|
+ setStatusUi("取批次无响应(检查服务端/网络)");
|
|
|
+ log.warn("工位[{}] nextBatch 无响应 server={}", cfg.getStationSn(), serverIp);
|
|
|
return;
|
|
|
}
|
|
|
if (!MesDcApiClient.isSuccess(ret)) {
|
|
|
- setStatusUi("空闲:等待扫码下发批次…");
|
|
|
+ String msg = MesDcApiClient.messageOf(ret);
|
|
|
+ setStatusUi("取批次:" + msg);
|
|
|
+ log.info("工位[{}] nextBatch 未取到:{}", cfg.getStationSn(), msg);
|
|
|
return;
|
|
|
}
|
|
|
String code = MesDcApiClient.dataStr(ret, "batchCode");
|
|
|
@@ -367,9 +418,12 @@ public class StationPanel extends JPanel {
|
|
|
target = MesDcApiClient.dataInt(ret, "qty", 0);
|
|
|
}
|
|
|
if (code.isEmpty() || target <= 0) {
|
|
|
+ setStatusUi("取批次成功但缺批次码/目标数量");
|
|
|
log.warn("工位[{}] nextBatch 成功但缺 batchCode/targetQty: {}", cfg.getStationSn(), ret);
|
|
|
return;
|
|
|
}
|
|
|
+ log.info("工位[{}] nextBatch 成功 batch={} target={}",
|
|
|
+ cfg.getStationSn(), code, Integer.valueOf(target));
|
|
|
startBatchFromPda(code, target);
|
|
|
} finally {
|
|
|
nextBusy.set(false);
|
|
|
@@ -382,7 +436,8 @@ public class StationPanel extends JPanel {
|
|
|
* 批次到位:记起点产量 → MES允许=true → 进入 RUN;本批做完再写 false。
|
|
|
*/
|
|
|
private void startBatchFromPda(String code, int target) {
|
|
|
- if (phase == Phase.RUN) {
|
|
|
+ // DONE 挂起续传中禁止再开批,避免冲掉待上传结案
|
|
|
+ if (phase == Phase.RUN || phase == Phase.DONE) {
|
|
|
return;
|
|
|
}
|
|
|
if (!busy.compareAndSet(false, true)) {
|
|
|
@@ -392,63 +447,127 @@ public class StationPanel extends JPanel {
|
|
|
if (!plc.isConnected()) {
|
|
|
plc.connect();
|
|
|
}
|
|
|
+ // 服务端 next 后队列已是「已取」:PLC 读不到也不能丢弃,否则热表卡住、界面像没反应
|
|
|
Integer base = plc.readActualQty();
|
|
|
+ int baseQty = 0;
|
|
|
if (base == null) {
|
|
|
- // 队列已是已取:必须重试 nextBatch,否则等不到下一次 SSE
|
|
|
- setStatusUi("收到批次,但读实际产量失败,将自动重试…");
|
|
|
- MainFrame.setMenuStatus(cfg.getStationSn() + " 开批失败:读产量", -1);
|
|
|
- scheduleNextRetry(3000L);
|
|
|
- return;
|
|
|
+ log.warn("工位[{}] 开批时读实际产量失败(PLC 未连/点位异常),起点按 0,batch={}",
|
|
|
+ cfg.getStationSn(), code);
|
|
|
+ } else {
|
|
|
+ baseQty = base.intValue();
|
|
|
}
|
|
|
batchCode = code;
|
|
|
targetQty = target;
|
|
|
- baseActualQty = base.intValue();
|
|
|
+ baseActualQty = baseQty;
|
|
|
lastActualQty = baseActualQty;
|
|
|
producedQty = 0;
|
|
|
batchStartTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
|
|
|
+ // 共享给五台压机页:只主界面持有批次码
|
|
|
+ DcLineBatchContext.open(batchCode, targetQty, batchStartTime);
|
|
|
+ MainFrame.notifyPressesBatchOpened();
|
|
|
boolean wrote = plc.setMesAllow(true);
|
|
|
phase = Phase.RUN;
|
|
|
setText(txtBatch, batchCode);
|
|
|
setText(txtTarget, String.valueOf(targetQty));
|
|
|
setText(txtProduced, "0");
|
|
|
setMesAllowLamp(wrote);
|
|
|
- setStatusUi((wrote ? "批次已开,MES允许已写" : "批次已开(允许点未配/写失败,本地仍盯产量)")
|
|
|
- + " 起始产量=" + baseActualQty);
|
|
|
+ String tip = wrote ? "批次已开,MES允许已写" : "批次已开(允许点未配/写失败)";
|
|
|
+ if (base == null) {
|
|
|
+ tip = tip + " PLC产量未读到,起点=0";
|
|
|
+ } else {
|
|
|
+ tip = tip + " 起始产量=" + baseActualQty;
|
|
|
+ }
|
|
|
+ tip = tip + " 结案看压机5";
|
|
|
+ setStatusUi(tip);
|
|
|
MainFrame.setMenuStatus(cfg.getStationSn() + " 开批 " + batchCode + " 目标" + targetQty, 0);
|
|
|
- log.info("工位[{}] 开批 batch={} target={} baseQty={}",
|
|
|
- cfg.getStationSn(), batchCode, Integer.valueOf(targetQty), Integer.valueOf(baseActualQty));
|
|
|
+ log.info("工位[{}] 开批 batch={} target={} baseQty={} plcOk={}(结案条件=压机5达标)",
|
|
|
+ cfg.getStationSn(), batchCode, Integer.valueOf(targetQty),
|
|
|
+ Integer.valueOf(baseActualQty), Boolean.valueOf(base != null));
|
|
|
} finally {
|
|
|
busy.set(false);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 手动取批次:SSE 漏推时立刻 nextBatch(清空节流)。
|
|
|
+ * 手动取批次:SSE 漏推时立刻 nextBatch(跳过节流,必打日志)。
|
|
|
* 仅空闲可用。
|
|
|
*/
|
|
|
public void onManualNextClick() {
|
|
|
+ log.info("工位[{}] 点击「取批次」 phase={}", cfg.getStationSn(), phase);
|
|
|
if (phase != Phase.IDLE) {
|
|
|
setStatusUi("当前非空闲,无法取批次(进行中请用手动提交结案)");
|
|
|
return;
|
|
|
}
|
|
|
- lastPollBatchAtMs = 0L;
|
|
|
setStatusUi("正在手动取批次…");
|
|
|
- requestNextAsync();
|
|
|
+ requestNextAsync(true);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 手动提交:校验密码 mes 后,按当前已产数量结案(过站结果 OK)。
|
|
|
- * 由主窗页签左侧「设置」菜单调用。
|
|
|
+ * 手动提交:设置菜单入口。
|
|
|
+ * RUN:密码 mes → 确认批次/数量 → 结案(走挂起续传)。
|
|
|
+ * DONE+挂起:可立即再打一次上传;其它态弹窗说明。
|
|
|
*/
|
|
|
public void onManualSubmitClick() {
|
|
|
+ log.info("工位[{}] 点击「手动提交」 phase={} batch={}",
|
|
|
+ cfg.getStationSn(), phase, batchCode);
|
|
|
+ if (phase == Phase.DONE && pendingCompleteFields != null) {
|
|
|
+ int opt = JOptionPane.showConfirmDialog(dialogParent(),
|
|
|
+ "批次 " + pendingBatchCode + " 结案上传未成功,是否立即重试?",
|
|
|
+ "手动提交", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
|
|
|
+ if (opt == JOptionPane.YES_OPTION) {
|
|
|
+ setStatusUi("手动触发结案续传…");
|
|
|
+ new Thread(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ uploadPendingComplete(false);
|
|
|
+ }
|
|
|
+ }, "dc-manual-retry-" + cfg.getStationSn()).start();
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (phase != Phase.RUN) {
|
|
|
- setStatusUi("当前无进行中的批次,无法手动提交");
|
|
|
+ JOptionPane.showMessageDialog(dialogParent(),
|
|
|
+ "当前无进行中的批次,无法手动提交。\n请先取批次并开批后再试。",
|
|
|
+ "手动提交", JOptionPane.INFORMATION_MESSAGE);
|
|
|
return;
|
|
|
}
|
|
|
if (!askMesPassword()) {
|
|
|
return;
|
|
|
}
|
|
|
- finishBatch(producedQty, false, true);
|
|
|
+ int qty = DcLineBatchContext.getPressProduced(5);
|
|
|
+ if (qty <= 0) {
|
|
|
+ qty = producedQty;
|
|
|
+ }
|
|
|
+ String confirm = "确认手动结案?\n"
|
|
|
+ + "批次码:" + batchCode + "\n"
|
|
|
+ + "压机5已产:" + DcLineBatchContext.getPressProduced(5) + "\n"
|
|
|
+ + "线体已产:" + producedQty + "\n"
|
|
|
+ + "计划产量:" + targetQty + "\n"
|
|
|
+ + "本次上报数量:" + qty;
|
|
|
+ int ok = JOptionPane.showConfirmDialog(dialogParent(), confirm, "手动提交",
|
|
|
+ JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
|
|
|
+ if (ok != JOptionPane.OK_OPTION) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ finishBatch(qty, false, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 压机5冲次达标回调:按压机5已产数量结案并打印。
|
|
|
+ *
|
|
|
+ * @param press5Qty 压机5本批已产
|
|
|
+ */
|
|
|
+ public void finishFromPress5(int press5Qty) {
|
|
|
+ if (phase != Phase.RUN) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ int qty = press5Qty > 0 ? press5Qty : DcLineBatchContext.getPressProduced(5);
|
|
|
+ if (qty <= 0) {
|
|
|
+ qty = producedQty;
|
|
|
+ }
|
|
|
+ log.info("工位[{}] 收到压机5达标结案 qty={} batch={}",
|
|
|
+ cfg.getStationSn(), Integer.valueOf(qty), batchCode);
|
|
|
+ finishBatch(qty, false, false);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -461,7 +580,7 @@ public class StationPanel extends JPanel {
|
|
|
JPanel box = new JPanel(new BorderLayout(8, 8));
|
|
|
box.add(new JLabel("请输入密码"), BorderLayout.NORTH);
|
|
|
box.add(pf, BorderLayout.CENTER);
|
|
|
- int opt = JOptionPane.showConfirmDialog(this, box, "手动提交",
|
|
|
+ int opt = JOptionPane.showConfirmDialog(dialogParent(), box, "手动提交",
|
|
|
JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
|
|
|
if (opt != JOptionPane.OK_OPTION) {
|
|
|
return false;
|
|
|
@@ -470,19 +589,26 @@ public class StationPanel extends JPanel {
|
|
|
boolean ok = Arrays.equals(input, "mes".toCharArray());
|
|
|
Arrays.fill(input, '\0');
|
|
|
if (!ok) {
|
|
|
- JOptionPane.showMessageDialog(this, "密码错误", "手动提交", JOptionPane.WARNING_MESSAGE);
|
|
|
+ JOptionPane.showMessageDialog(dialogParent(), "密码错误", "手动提交", JOptionPane.WARNING_MESSAGE);
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ /** 弹窗挂到主窗,避免工作面板未显示时对话框位置异常 */
|
|
|
+ private Component dialogParent() {
|
|
|
+ Window w = SwingUtilities.getWindowAncestor(this);
|
|
|
+ return w != null ? w : this;
|
|
|
+ }
|
|
|
+
|
|
|
/** 产量达标结案 */
|
|
|
private void finishBatch(final int qty, final boolean aborted) {
|
|
|
finishBatch(qty, aborted, false);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 结案。
|
|
|
+ * 结案:关 MES允许 → 本机记录 → 异步打印 → 挂起报文上传;
|
|
|
+ * 仅 completeBatch 成功才回空闲,失败留 DONE 由 tick 续传。
|
|
|
*
|
|
|
* @param qty 本批数量
|
|
|
* @param aborted 是否强制中断(结果 NG)
|
|
|
@@ -498,26 +624,26 @@ public class StationPanel extends JPanel {
|
|
|
new Thread(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
+ boolean fieldsReady = false;
|
|
|
try {
|
|
|
// 本批做完:MES允许改回 false
|
|
|
plc.setMesAllow(false);
|
|
|
+ SwingUtilities.invokeLater(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ setMesAllowLamp(false);
|
|
|
+ }
|
|
|
+ });
|
|
|
String time = timeSnap;
|
|
|
if (time == null || time.isEmpty()) {
|
|
|
time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
|
|
|
}
|
|
|
- // 包装码:年月日 + 随机6位,打印与上传都用它做批量追溯
|
|
|
- final String packCode = DcPackCode.next();
|
|
|
- boolean printed = DcBatchPrinter.printPack(packCode, time, qty);
|
|
|
// 过站结果:中断 NG,否则 OK(含手动提交)
|
|
|
String passResult = aborted ? "NG" : "OK";
|
|
|
- DcWorkRecordStore.add(packCode, codeSnap, time, qty, passResult);
|
|
|
- MainFrame.refreshWorkRecords();
|
|
|
- // 结案只上传一次:包装码 + 批次码 + 本批数量 + DB260 过程参数
|
|
|
DcRunSnapshot snap = lastSnap == null ? new DcRunSnapshot() : lastSnap;
|
|
|
- Map<String, String> fields = new LinkedHashMap<String, String>();
|
|
|
+ final Map<String, String> fields = new LinkedHashMap<String, String>();
|
|
|
fields.put("stationSn", cfg.getStationSn());
|
|
|
fields.put("batchCode", codeSnap);
|
|
|
- fields.put("packCode", packCode);
|
|
|
fields.put("qty", String.valueOf(qty));
|
|
|
fields.put("produceTime", time);
|
|
|
fields.put("aborted", aborted ? "1" : "0");
|
|
|
@@ -530,21 +656,39 @@ public class StationPanel extends JPanel {
|
|
|
fields.put("takt", String.valueOf(snap.takt));
|
|
|
fields.put("lineState", String.valueOf(snap.lineState));
|
|
|
fields.put("lineStateText", nvl(snap.lineStateText));
|
|
|
- MesDcApiClient.completeBatch(serverIp, fields);
|
|
|
-
|
|
|
- String how = aborted ? "已强制结束" : (manual ? "手动提交" : "本批达标");
|
|
|
- final String tip = how + " 包装码=" + packCode + " 数量=" + qty
|
|
|
- + (printed ? " 已送打印" : " 打印失败/无打印机");
|
|
|
- SwingUtilities.invokeLater(new Runnable() {
|
|
|
+ // 本机记录先落;挂起报文供 DONE 续传(按批次码幂等)
|
|
|
+ DcWorkRecordStore.add(codeSnap, time, qty, passResult);
|
|
|
+ MainFrame.refreshWorkRecords();
|
|
|
+ String how = aborted ? "已强制结束" : (manual ? "手动提交" : "压机5达标");
|
|
|
+ pendingCompleteFields = fields;
|
|
|
+ pendingHow = how;
|
|
|
+ pendingBatchCode = codeSnap;
|
|
|
+ pendingQty = qty;
|
|
|
+ pendingPrinted = false;
|
|
|
+ fieldsReady = true;
|
|
|
+ // 打印异步:打印机卡死不能挡 MES 结案;小票打批次码
|
|
|
+ final String printTime = time;
|
|
|
+ final String printBatch = codeSnap;
|
|
|
+ new Thread(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
- resetToIdle(tip);
|
|
|
- MainFrame.setMenuStatus(cfg.getStationSn() + " 结案 " + packCode + " x" + qty, 0);
|
|
|
+ boolean ok = DcBatchPrinter.printBatch(printBatch, printTime, qty);
|
|
|
+ pendingPrinted = ok;
|
|
|
+ if (!ok) {
|
|
|
+ log.warn("工位[{}] 异步打印失败/无打印机 batch={}", cfg.getStationSn(), printBatch);
|
|
|
+ }
|
|
|
}
|
|
|
- });
|
|
|
- log.info("工位[{}] 结案 batch={} pack={} qty={} aborted={} manual={} printed={}",
|
|
|
- cfg.getStationSn(), codeSnap, packCode, Integer.valueOf(qty),
|
|
|
- Boolean.valueOf(aborted), Boolean.valueOf(manual), Boolean.valueOf(printed));
|
|
|
+ }, "dc-print-" + cfg.getStationSn()).start();
|
|
|
+ // 先放 busy:phase=DONE,tick 可刷灯并可走续传
|
|
|
+ busy.set(false);
|
|
|
+ uploadPendingComplete(true);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ log.error("工位[{}] 结案异常: {}", cfg.getStationSn(), ex.getMessage(), ex);
|
|
|
+ setStatusUi("结案异常:" + ex.getMessage());
|
|
|
+ if (!fieldsReady) {
|
|
|
+ // 报文未备好:回到 RUN,可手动再提交
|
|
|
+ phase = Phase.RUN;
|
|
|
+ }
|
|
|
} finally {
|
|
|
busy.set(false);
|
|
|
}
|
|
|
@@ -552,6 +696,69 @@ public class StationPanel extends JPanel {
|
|
|
}, "dc-finish-" + cfg.getStationSn()).start();
|
|
|
}
|
|
|
|
|
|
+ /** DONE 态 tick 触发:有挂起结案则续传 */
|
|
|
+ private void retryPendingCompleteIfAny() {
|
|
|
+ if (pendingCompleteFields == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ uploadPendingComplete(false);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 上传挂起的结案报文;成功才回空闲(关共享批次、通知压机)。
|
|
|
+ *
|
|
|
+ * @param fromFinishThread true=结案线程内首轮(可多等几轮);false=tick 续传单次
|
|
|
+ */
|
|
|
+ private void uploadPendingComplete(boolean fromFinishThread) {
|
|
|
+ final Map<String, String> fields = pendingCompleteFields;
|
|
|
+ if (fields == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!completeRetryBusy.compareAndSet(false, true)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ final String how = pendingHow;
|
|
|
+ final String batch = pendingBatchCode;
|
|
|
+ final int qty = pendingQty;
|
|
|
+ try {
|
|
|
+ int maxAttempts = fromFinishThread ? 12 : 1;
|
|
|
+ boolean uploaded = false;
|
|
|
+ for (int attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
|
+ JSONObject ret = MesDcApiClient.completeBatch(serverIp, fields);
|
|
|
+ uploaded = MesDcApiClient.isSuccess(ret);
|
|
|
+ if (uploaded) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ setStatusUi(how + " 批次码=" + batch + " 上传失败,重试中…(#" + attempt + ")");
|
|
|
+ MainFrame.setMenuStatus(cfg.getStationSn() + " 上传失败重试 #" + attempt, -1);
|
|
|
+ log.warn("工位[{}] 结案上传失败 batch={} attempt={} msg={}",
|
|
|
+ cfg.getStationSn(), batch, Integer.valueOf(attempt),
|
|
|
+ MesDcApiClient.messageOf(ret));
|
|
|
+ if (attempt < maxAttempts) {
|
|
|
+ try {
|
|
|
+ Thread.sleep(5000L);
|
|
|
+ } catch (InterruptedException ie) {
|
|
|
+ Thread.currentThread().interrupt();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (uploaded) {
|
|
|
+ pendingCompleteFields = null;
|
|
|
+ final String tip = how + " 批次码=" + batch + " 数量=" + qty
|
|
|
+ + (pendingPrinted ? " 已送打印" : " 打印已提交/待确认")
|
|
|
+ + " 已上传";
|
|
|
+ resetToIdle(tip);
|
|
|
+ MainFrame.setMenuStatus(cfg.getStationSn() + " 结案 " + batch + " x" + qty, 0);
|
|
|
+ log.info("工位[{}] 结案成功 batch={} qty={}", cfg.getStationSn(), batch, Integer.valueOf(qty));
|
|
|
+ } else {
|
|
|
+ setStatusUi(how + " 批次码=" + batch + " 等待续传…");
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ completeRetryBusy.set(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 按 PLC 实际产量累计本批已产。
|
|
|
* 若实际产量比上一拍变小(人为复位/清零),保留已产件数,把起点挪到「当前值 − 已产」,
|
|
|
@@ -590,12 +797,21 @@ public class StationPanel extends JPanel {
|
|
|
producedQty = 0;
|
|
|
lastActualQty = 0;
|
|
|
batchStartTime = "";
|
|
|
+ pendingCompleteFields = null;
|
|
|
+ pendingHow = "";
|
|
|
+ pendingBatchCode = "";
|
|
|
+ pendingQty = 0;
|
|
|
+ pendingPrinted = false;
|
|
|
+ // 上传成功或清码后才关共享批次,挂起续传期间压机仍能看见本批
|
|
|
+ DcLineBatchContext.close();
|
|
|
+ MainFrame.notifyPressesBatchClosed();
|
|
|
SwingUtilities.invokeLater(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
setText(txtBatch, "");
|
|
|
setText(txtTarget, "");
|
|
|
setText(txtProduced, "");
|
|
|
+ setText(txtPressProgress, "");
|
|
|
setMesAllowLamp(false);
|
|
|
setStatusUi(msg == null || msg.isEmpty()
|
|
|
? "空闲:等待扫码下发批次…" : msg + " → 等待下一笔");
|
|
|
@@ -603,6 +819,30 @@ public class StationPanel extends JPanel {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ /** 刷新主界面「五台冲次进度」汇总 */
|
|
|
+ private void refreshPressProgressUi() {
|
|
|
+ if (phase != Phase.RUN) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ final int target = targetQty;
|
|
|
+ final StringBuilder sb = new StringBuilder();
|
|
|
+ for (int i = 1; i <= 5; i++) {
|
|
|
+ if (i > 1) {
|
|
|
+ sb.append(" ");
|
|
|
+ }
|
|
|
+ sb.append(i).append('#').append(DcLineBatchContext.getPressProduced(i));
|
|
|
+ if (target > 0) {
|
|
|
+ sb.append('/').append(target);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ SwingUtilities.invokeLater(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ setText(txtPressProgress, sb.toString());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
private void refreshSnapshotUi(final DcRunSnapshot s) {
|
|
|
if (s == null) {
|
|
|
return;
|
|
|
@@ -615,6 +855,8 @@ public class StationPanel extends JPanel {
|
|
|
setText(txtActualQty, String.valueOf(s.actualQty));
|
|
|
setText(txtDowntime, String.valueOf(s.downtime));
|
|
|
setText(txtTakt, String.valueOf(s.takt));
|
|
|
+ setText(txtLineState, nvl(s.lineStateText).isEmpty()
|
|
|
+ ? String.valueOf(s.lineState) : s.lineStateText);
|
|
|
setLineStateLamp(s.lineState);
|
|
|
setMesAllowLamp(phase == Phase.RUN);
|
|
|
}
|
|
|
@@ -654,13 +896,12 @@ public class StationPanel extends JPanel {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- /** 顶栏刷新:连接灯 + 状态说明 + 地址 */
|
|
|
+ /** 顶栏刷新:连接灯 + 状态说明 */
|
|
|
private void uiPlcLabel() {
|
|
|
final boolean ok = plc.isConnected();
|
|
|
SwingUtilities.invokeLater(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
- lblPlc.setText(plcAddrText());
|
|
|
lampPlc.setLevel(ok ? StatusLight.Level.ON : StatusLight.Level.FAULT);
|
|
|
lblPlcState.setText(ok ? "已连接" : "未连接");
|
|
|
}
|
|
|
@@ -681,15 +922,6 @@ public class StationPanel extends JPanel {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- /** PLC 地址;IP 未配返回空 */
|
|
|
- private String plcAddrText() {
|
|
|
- String ip = nvl(cfg.getPlcIp());
|
|
|
- if (ip.isEmpty()) {
|
|
|
- return "";
|
|
|
- }
|
|
|
- return ip + ":" + cfg.getPlcPort();
|
|
|
- }
|
|
|
-
|
|
|
/** 顶栏状态说明(灯正下方) */
|
|
|
private static JLabel headerStateLabel(String text) {
|
|
|
JLabel lb = new JLabel(text, SwingConstants.CENTER);
|