|
|
@@ -5,7 +5,6 @@ import com.mes.config.DcPressProfiles;
|
|
|
import com.mes.config.MesClientProperties;
|
|
|
import com.mes.entity.DcRunSnapshot;
|
|
|
import com.mes.service.DcBatchPrinter;
|
|
|
-import com.mes.service.DcPackCode;
|
|
|
import com.mes.service.DcPlcClient;
|
|
|
import com.mes.service.DcWorkRecordStore;
|
|
|
import com.mes.service.MesDcApiClient;
|
|
|
@@ -70,7 +69,8 @@ public class StationPanel extends JPanel {
|
|
|
/** 结案上传未成功时的待重试报文(DONE 态由 tick 续传,避免卡死) */
|
|
|
private volatile Map<String, String> pendingCompleteFields;
|
|
|
private volatile String pendingHow = "";
|
|
|
- private volatile String pendingPackCode = "";
|
|
|
+ /** 挂起结案对应批次码(续传提示用) */
|
|
|
+ private volatile String pendingBatchCode = "";
|
|
|
private volatile int pendingQty;
|
|
|
private volatile boolean pendingPrinted;
|
|
|
private final AtomicBoolean completeRetryBusy = new AtomicBoolean(false);
|
|
|
@@ -524,15 +524,48 @@ public class StationPanel extends JPanel {
|
|
|
requestNextAsync();
|
|
|
}
|
|
|
|
|
|
- /** 手动提交:密码 mes */
|
|
|
+ /**
|
|
|
+ * 手动提交:设置菜单入口。
|
|
|
+ * 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-yt-manual-retry-" + cfg.getStationSn()).start();
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (phase != Phase.RUN) {
|
|
|
- setStatusUi("当前无进行中的批次,无法手动提交");
|
|
|
+ JOptionPane.showMessageDialog(dialogParent(),
|
|
|
+ "当前无进行中的批次,无法手动提交。\n请先取批次并开批后再试。",
|
|
|
+ "手动提交", JOptionPane.INFORMATION_MESSAGE);
|
|
|
return;
|
|
|
}
|
|
|
if (!askMesPassword()) {
|
|
|
return;
|
|
|
}
|
|
|
+ String confirm = "确认手动结案?\n"
|
|
|
+ + "批次码:" + batchCode + "\n"
|
|
|
+ + "本批已产:" + producedQty + "\n"
|
|
|
+ + "计划产量:" + targetQty + "\n"
|
|
|
+ + "本次上报数量:" + producedQty;
|
|
|
+ int ok = JOptionPane.showConfirmDialog(dialogParent(), confirm, "手动提交",
|
|
|
+ JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
|
|
|
+ if (ok != JOptionPane.OK_OPTION) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
finishBatch(producedQty, false, true);
|
|
|
}
|
|
|
|
|
|
@@ -541,7 +574,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;
|
|
|
@@ -550,12 +583,18 @@ 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);
|
|
|
}
|
|
|
@@ -585,14 +624,12 @@ public class StationPanel extends JPanel {
|
|
|
if (time == null || time.isEmpty()) {
|
|
|
time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
|
|
|
}
|
|
|
- final String packCode = DcPackCode.next();
|
|
|
String passResult = aborted ? "NG" : "OK";
|
|
|
DcRunSnapshot snap = lastSnap == null ? new DcRunSnapshot() : lastSnap;
|
|
|
final Map<String, String> fields = new LinkedHashMap<String, String>();
|
|
|
fields.put("stationSn", cfg.getStationSn());
|
|
|
fields.put("stationTitle", tabTitle());
|
|
|
fields.put("batchCode", codeSnap);
|
|
|
- fields.put("packCode", packCode);
|
|
|
fields.put("qty", String.valueOf(qty));
|
|
|
fields.put("targetQty", String.valueOf(targetSnap));
|
|
|
fields.put("produceTime", time);
|
|
|
@@ -608,25 +645,26 @@ public class StationPanel extends JPanel {
|
|
|
fields.put("energyKwh", nvl(snap.energyKwh));
|
|
|
fields.put("deviceRunning", snap.deviceRunning ? "1" : "0");
|
|
|
fields.put("deviceStateText", nvl(snap.deviceStateText));
|
|
|
- // 本机记录先落;挂起报文供 DONE 续传
|
|
|
- DcWorkRecordStore.add(packCode, codeSnap, time, qty, passResult);
|
|
|
+ // 本机记录先落;挂起报文供 DONE 续传(按批次码追溯)
|
|
|
+ DcWorkRecordStore.add(codeSnap, time, qty, passResult);
|
|
|
MainFrame.refreshWorkRecords();
|
|
|
String how = aborted ? "已强制结束" : (manual ? "手动提交" : "本批达标");
|
|
|
pendingCompleteFields = fields;
|
|
|
pendingHow = how;
|
|
|
- pendingPackCode = packCode;
|
|
|
+ pendingBatchCode = codeSnap;
|
|
|
pendingQty = qty;
|
|
|
pendingPrinted = false;
|
|
|
fieldsReady = true;
|
|
|
- // 打印异步:打印机卡死不能挡 MES 结案
|
|
|
+ // 打印异步:打印机卡死不能挡 MES 结案;小票打批次码
|
|
|
final String printTime = time;
|
|
|
+ final String printBatch = codeSnap;
|
|
|
new Thread(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
- boolean ok = DcBatchPrinter.printPack(packCode, printTime, qty);
|
|
|
+ boolean ok = DcBatchPrinter.printBatch(printBatch, printTime, qty);
|
|
|
pendingPrinted = ok;
|
|
|
if (!ok) {
|
|
|
- log.warn("工位[{}] 异步打印失败/无打印机 pack={}", cfg.getStationSn(), packCode);
|
|
|
+ log.warn("工位[{}] 异步打印失败/无打印机 batch={}", cfg.getStationSn(), printBatch);
|
|
|
}
|
|
|
}
|
|
|
}, "dc-yt-print-" + cfg.getStationSn()).start();
|
|
|
@@ -669,7 +707,7 @@ public class StationPanel extends JPanel {
|
|
|
return;
|
|
|
}
|
|
|
final String how = pendingHow;
|
|
|
- final String packCode = pendingPackCode;
|
|
|
+ final String batch = pendingBatchCode;
|
|
|
final int qty = pendingQty;
|
|
|
try {
|
|
|
int maxAttempts = fromFinishThread ? 12 : 1;
|
|
|
@@ -681,10 +719,10 @@ public class StationPanel extends JPanel {
|
|
|
MainFrame.setMesServerOnline(true);
|
|
|
break;
|
|
|
}
|
|
|
- setStatusUi(how + " 包装码=" + packCode + " 上传失败,重试中…(#" + attempt + ")");
|
|
|
+ setStatusUi(how + " 批次码=" + batch + " 上传失败,重试中…(#" + attempt + ")");
|
|
|
MainFrame.setMenuStatus(cfg.getStationSn() + " 上传失败重试 #" + attempt, -1);
|
|
|
- log.warn("工位[{}] 结案上传失败 pack={} attempt={}",
|
|
|
- cfg.getStationSn(), packCode, Integer.valueOf(attempt));
|
|
|
+ log.warn("工位[{}] 结案上传失败 batch={} attempt={}",
|
|
|
+ cfg.getStationSn(), batch, Integer.valueOf(attempt));
|
|
|
if (attempt < maxAttempts) {
|
|
|
try {
|
|
|
Thread.sleep(5000L);
|
|
|
@@ -696,14 +734,14 @@ public class StationPanel extends JPanel {
|
|
|
}
|
|
|
if (uploaded) {
|
|
|
pendingCompleteFields = null;
|
|
|
- final String tip = how + " 包装码=" + packCode + " 数量=" + qty
|
|
|
+ final String tip = how + " 批次码=" + batch + " 数量=" + qty
|
|
|
+ (pendingPrinted ? " 已送打印" : " 打印已提交/待确认")
|
|
|
+ " 已上传";
|
|
|
resetToIdle(tip);
|
|
|
- MainFrame.setMenuStatus(cfg.getStationSn() + " 结案 " + packCode + " x" + qty, 0);
|
|
|
- log.info("工位[{}] 结案成功 pack={} qty={}", cfg.getStationSn(), packCode, Integer.valueOf(qty));
|
|
|
+ MainFrame.setMenuStatus(cfg.getStationSn() + " 结案 " + batch + " x" + qty, 0);
|
|
|
+ log.info("工位[{}] 结案成功 batch={} qty={}", cfg.getStationSn(), batch, Integer.valueOf(qty));
|
|
|
} else {
|
|
|
- setStatusUi(how + " 包装码=" + packCode + " 等待续传…");
|
|
|
+ setStatusUi(how + " 批次码=" + batch + " 等待续传…");
|
|
|
}
|
|
|
} finally {
|
|
|
completeRetryBusy.set(false);
|
|
|
@@ -747,7 +785,7 @@ public class StationPanel extends JPanel {
|
|
|
mesAllowOn = false;
|
|
|
pendingCompleteFields = null;
|
|
|
pendingHow = "";
|
|
|
- pendingPackCode = "";
|
|
|
+ pendingBatchCode = "";
|
|
|
pendingQty = 0;
|
|
|
pendingPrinted = false;
|
|
|
SwingUtilities.invokeLater(new Runnable() {
|