StationPanel.java 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076
  1. package com.mes.ui;
  2. import com.alibaba.fastjson2.JSONObject;
  3. import com.mes.config.MesClientProperties;
  4. import com.mes.entity.DcRunSnapshot;
  5. import com.mes.service.DcBatchPrinter;
  6. import com.mes.service.DcLineBatchContext;
  7. import com.mes.service.DcPlcClient;
  8. import com.mes.service.DcPrintQueueStore;
  9. import com.mes.service.DcWorkRecordStore;
  10. import com.mes.service.MesDcApiClient;
  11. import org.slf4j.Logger;
  12. import org.slf4j.LoggerFactory;
  13. import javax.swing.*;
  14. import javax.swing.border.EmptyBorder;
  15. import java.awt.*;
  16. import java.awt.event.ActionEvent;
  17. import java.awt.event.ActionListener;
  18. import java.text.SimpleDateFormat;
  19. import java.util.Arrays;
  20. import java.util.Date;
  21. import java.util.LinkedHashMap;
  22. import java.util.Map;
  23. import java.util.concurrent.atomic.AtomicBoolean;
  24. /**
  25. * 自动化大冲线体主面板:取批次 → MES允许 → 读 DB260 展示;
  26. * 结案打印由压机5冲次达标触发(本页不再按 DB260 产量自动结案)。
  27. */
  28. public class StationPanel extends JPanel {
  29. private static final Logger log = LoggerFactory.getLogger(StationPanel.class);
  30. /** 兜底取批最小间隔(SSE 正常时由门铃触发) */
  31. private static final long POLL_BATCH_INTERVAL_MS = 2000L;
  32. /** IDLE 等 PDA;RUN 允许运行盯产量;DONE 结案过渡 */
  33. public enum Phase {
  34. IDLE, RUN, DONE
  35. }
  36. private final MesClientProperties.StationConfig cfg;
  37. private final String serverIp;
  38. private final DcPlcClient plc;
  39. private final AtomicBoolean busy = new AtomicBoolean(false);
  40. /** 后台 nextBatch 进行中 */
  41. private final AtomicBoolean nextBusy = new AtomicBoolean(false);
  42. private volatile Phase phase = Phase.IDLE;
  43. private volatile String batchCode = "";
  44. /** 本件结案工号:优先 nextBatch 带回的入队 userCode */
  45. private volatile String currentUserCode = "";
  46. private volatile int targetQty;
  47. /** 开批时 PLC 实际产量起点;中途复位后会按已产重定 */
  48. private volatile int baseActualQty;
  49. /** 本批已产件数(中途产量复位不丢进度) */
  50. private volatile int producedQty;
  51. /** 上一拍读到的实际产量,用于发现中途被清零/变小 */
  52. private volatile int lastActualQty;
  53. private volatile String batchStartTime = "";
  54. private volatile long lastPollBatchAtMs;
  55. /** 最近一次 DB260 快照,结案时一并上传(只传一次,不采样堆) */
  56. private volatile DcRunSnapshot lastSnap = new DcRunSnapshot();
  57. /** 结案上传未成功时的待重试报文(DONE 态由 tick 续传,避免热队列卡「已取」) */
  58. private volatile Map<String, String> pendingCompleteFields;
  59. /** 挂起结案说明文案(达标/手动/强制) */
  60. private volatile String pendingHow = "";
  61. /** 挂起结案对应批次码(续传提示用) */
  62. private volatile String pendingBatchCode = "";
  63. /** 挂起结案数量 */
  64. private volatile int pendingQty;
  65. /** 异步打印是否已成功送出(仅提示,不挡结案) */
  66. private volatile boolean pendingPrinted;
  67. /** 结案上传重试互斥,避免 finish 线程与 tick 同时打 completeBatch */
  68. private final AtomicBoolean completeRetryBusy = new AtomicBoolean(false);
  69. private final JLabel lblStation;
  70. private final JLabel lblStatus;
  71. private final JTextField txtBatch;
  72. private final JTextField txtTarget;
  73. private final JTextField txtCurrentPart;
  74. private final JTextField txtNextPart;
  75. private final JTextField txtActualQty;
  76. private final JTextField txtProduced;
  77. private final JTextField txtDowntime;
  78. private final JTextField txtTakt;
  79. /** 产线状态文案示值 */
  80. private final JTextField txtLineState;
  81. /** 五台压机本批进度(主界面汇总,结案看压机5) */
  82. private final JTextField txtPressProgress;
  83. /** 服务端 SSE 呼吸灯 */
  84. private final BreathingLight serverHeartbeat;
  85. /** PLC 连接指示灯:绿=已连,红=未连 */
  86. private final StatusLight lampPlc;
  87. /** PLC 连接状态说明 */
  88. private final JLabel lblPlcState;
  89. /** 产线状态指示灯:绿=正常,灰=待机,红=故障 */
  90. private final StatusLight lampLineState;
  91. /** 产线状态说明 */
  92. private final JLabel lblLineState;
  93. /** MES 允许运行指示灯:绿=已开,灰=关 */
  94. private final StatusLight lampMesAllow;
  95. /** MES 允许状态说明 */
  96. private final JLabel lblMesAllowState;
  97. /** 漏推送时现场可点:强制 nextBatch */
  98. private final JButton btnNext;
  99. public StationPanel(MesClientProperties.StationConfig cfg, String serverIp) {
  100. this.cfg = cfg;
  101. this.serverIp = serverIp == null ? "" : serverIp.trim();
  102. // mes-allow-enabled=false 时开批/结案/清码都不写 PLC 允许点
  103. this.plc = new DcPlcClient(cfg.getStationSn(), cfg.getPlcIp(), cfg.getPlcPort(),
  104. cfg.getMesAllowAddr(), MainFrame.mes_allow_enabled);
  105. setLayout(new BorderLayout(0, 0));
  106. setBackground(UiTheme.BG);
  107. setBorder(new EmptyBorder(0, 0, 0, 0));
  108. String titleText = nvl(cfg.getTitle());
  109. if (titleText.isEmpty()) {
  110. titleText = "自动化大冲";
  111. }
  112. JPanel header = UiTheme.gradientHeader();
  113. header.setBorder(new EmptyBorder(16, 20, 16, 20));
  114. lblStation = new JLabel(titleText);
  115. lblStation.setFont(UiTheme.FONT_TITLE);
  116. lblStation.setForeground(Color.WHITE);
  117. // Consolas 不支持中文,副标题只用工位编码,避免乱码方框
  118. JLabel lblCode = new JLabel(nvl(cfg.getStationSn()));
  119. lblCode.setFont(new Font("Consolas", Font.BOLD, 13));
  120. lblCode.setForeground(new Color(140, 210, 220));
  121. JPanel titleCol = new JPanel();
  122. titleCol.setOpaque(false);
  123. titleCol.setLayout(new BoxLayout(titleCol, BoxLayout.Y_AXIS));
  124. titleCol.add(lblStation);
  125. titleCol.add(Box.createVerticalStrut(3));
  126. titleCol.add(lblCode);
  127. serverHeartbeat = new BreathingLight();
  128. serverHeartbeat.setOnline(false);
  129. lampPlc = new StatusLight();
  130. lblPlcState = headerStateLabel("未连接");
  131. lampLineState = new StatusLight();
  132. lblLineState = headerStateLabel("待机");
  133. lampMesAllow = new StatusLight();
  134. lblMesAllowState = headerStateLabel("关");
  135. JPanel east = new JPanel(new FlowLayout(FlowLayout.RIGHT, 14, 0));
  136. east.setOpaque(false);
  137. east.add(headerBreathingItem("MES", serverHeartbeat));
  138. east.add(headerLampItem("PLC", lampPlc, lblPlcState));
  139. east.add(headerLampItem("产线", lampLineState, lblLineState));
  140. east.add(headerLampItem("MES允许", lampMesAllow, lblMesAllowState));
  141. header.add(titleCol, BorderLayout.WEST);
  142. header.add(east, BorderLayout.EAST);
  143. // 状态条紧贴顶栏下方,一眼能看到当前阶段
  144. lblStatus = new JLabel("空闲:等待扫码下发批次…");
  145. lblStatus.setFont(UiTheme.FONT_BODY);
  146. lblStatus.setOpaque(true);
  147. lblStatus.setBackground(UiTheme.OK_BG);
  148. lblStatus.setForeground(UiTheme.OK_FG);
  149. lblStatus.setBorder(new EmptyBorder(9, 16, 9, 16));
  150. JPanel north = new JPanel(new BorderLayout(0, 0));
  151. north.setOpaque(false);
  152. north.add(header, BorderLayout.NORTH);
  153. north.add(lblStatus, BorderLayout.SOUTH);
  154. add(north, BorderLayout.NORTH);
  155. // 本批 : 线体过程 按 1:3 等比分高;格子有最小高度,再矮则滚动
  156. JPanel main = new JPanel(new GridBagLayout());
  157. main.setOpaque(false);
  158. main.setBorder(new EmptyBorder(16, 20, 16, 20));
  159. JPanel batchCard = UiTheme.card();
  160. batchCard.setLayout(new BorderLayout(0, 10));
  161. batchCard.add(UiTheme.sectionTitle("本批"), BorderLayout.NORTH);
  162. JPanel batchGrid = new JPanel(new GridLayout(1, 2, 14, 0));
  163. batchGrid.setOpaque(false);
  164. batchGrid.setPreferredSize(new Dimension(10, UiTheme.TILE_PREF_H));
  165. batchGrid.setMinimumSize(new Dimension(10, UiTheme.TILE_MIN_H));
  166. txtBatch = roField();
  167. txtTarget = roField();
  168. batchGrid.add(UiTheme.paramTile("批次码", txtBatch, UiTheme.STRIPE_SIDE));
  169. batchGrid.add(UiTheme.paramTile("本批目标数量", txtTarget, UiTheme.STRIPE_SIDE));
  170. batchCard.add(batchGrid, BorderLayout.CENTER);
  171. JPanel runCard = UiTheme.card();
  172. runCard.setLayout(new BorderLayout(0, 10));
  173. runCard.add(UiTheme.sectionTitle("线体过程"), BorderLayout.NORTH);
  174. JPanel grid = new JPanel(new GridLayout(3, 3, 14, 14));
  175. grid.setOpaque(false);
  176. // 3 行格子最小总高,防止被压成一条线
  177. grid.setMinimumSize(new Dimension(10, UiTheme.TILE_MIN_H * 3 + 28));
  178. grid.setPreferredSize(new Dimension(10, UiTheme.TILE_PREF_H * 3 + 28));
  179. txtCurrentPart = roField();
  180. txtNextPart = roField();
  181. txtActualQty = roField();
  182. txtProduced = roField();
  183. txtDowntime = roField();
  184. txtTakt = roField();
  185. txtPressProgress = roField();
  186. txtLineState = roField();
  187. grid.add(UiTheme.paramTile("当前零件名称", txtCurrentPart, UiTheme.STRIPE_SIDE));
  188. grid.add(UiTheme.paramTile("下一零件名称", txtNextPart, UiTheme.STRIPE_SIDE));
  189. grid.add(UiTheme.paramTile("实际产量", txtActualQty, UiTheme.STRIPE_SIDE));
  190. grid.add(UiTheme.paramTile("停机时间", txtDowntime, UiTheme.STRIPE_SIDE));
  191. grid.add(UiTheme.paramTile("生产节拍", txtTakt, UiTheme.STRIPE_SIDE));
  192. grid.add(UiTheme.paramTile("产线状态", txtLineState, UiTheme.STRIPE_SIDE));
  193. grid.add(UiTheme.paramTile("本批已产", txtProduced, UiTheme.STRIPE_SIDE));
  194. UiTheme.markTileValueBase(txtProduced, UiTheme.FONT_SN.getSize2D());
  195. grid.add(UiTheme.paramTile("五台冲次数量进度", txtPressProgress, UiTheme.STRIPE_SIDE));
  196. UiTheme.markTileValueBase(txtPressProgress, UiTheme.FONT_BODY.getSize2D());
  197. runCard.add(grid, BorderLayout.CENTER);
  198. GridBagConstraints gc = new GridBagConstraints();
  199. gc.gridx = 0;
  200. gc.fill = GridBagConstraints.BOTH;
  201. gc.weightx = 1;
  202. gc.gridy = 0;
  203. gc.weighty = 1; // 本批约 1 行
  204. main.add(batchCard, gc);
  205. gc.gridy = 1;
  206. gc.weighty = 3; // 线体过程约 3 行,与本批等比分高
  207. gc.insets = new Insets(14, 0, 0, 0);
  208. main.add(runCard, gc);
  209. JScrollPane scroll = new JScrollPane(main);
  210. scroll.setBorder(BorderFactory.createEmptyBorder());
  211. scroll.setOpaque(false);
  212. scroll.getViewport().setOpaque(false);
  213. scroll.getVerticalScrollBar().setUnitIncrement(16);
  214. add(scroll, BorderLayout.CENTER);
  215. // 底部操作区:只保留「取批次」按钮
  216. JPanel actions = new JPanel(new FlowLayout(FlowLayout.RIGHT, 10, 0));
  217. actions.setOpaque(false);
  218. actions.setBorder(new EmptyBorder(0, 20, 16, 20));
  219. btnNext = UiTheme.primaryBtn("取批次");
  220. btnNext.addActionListener(new ActionListener() {
  221. @Override
  222. public void actionPerformed(ActionEvent e) {
  223. onManualNextClick();
  224. }
  225. });
  226. actions.add(btnNext);
  227. add(actions, BorderLayout.SOUTH);
  228. }
  229. public String getStationSn() {
  230. return nvl(cfg.getStationSn());
  231. }
  232. /** 单设备客户端:页签名固定为工作面板 */
  233. public String tabTitle() {
  234. return "工作面板";
  235. }
  236. public void initPlc() {
  237. plc.connect();
  238. uiPlcLabel();
  239. refreshSnapshotUi(plc.readSnapshot());
  240. }
  241. /**
  242. * 周期:重连、刷 DB260;RUN 只展示线体产量差,不按 DB260 自动结案。
  243. * 结案由压机5冲次达标触发 {@link #finishFromPress5(int)}。
  244. */
  245. public void tick() {
  246. if (busy.get()) {
  247. return;
  248. }
  249. try {
  250. plc.maintainConnection();
  251. uiPlcLabel();
  252. uiServerHeartbeat();
  253. DcRunSnapshot snap = plc.readSnapshot();
  254. if (snap != null) {
  255. lastSnap = snap;
  256. }
  257. refreshSnapshotUi(snap);
  258. refreshPressProgressUi();
  259. if (phase == Phase.IDLE) {
  260. if (!MainFrame.isMesServerOnline()) {
  261. setStatusUi("空闲:MES/SSE 未连接,等待服务端…");
  262. } else {
  263. setStatusUi("空闲:等待扫码下发批次…");
  264. }
  265. return;
  266. }
  267. if (phase == Phase.DONE) {
  268. // 上传曾失败:用挂起报文续传,成功前不重新开批、不回空闲
  269. retryPendingCompleteIfAny();
  270. return;
  271. }
  272. if (phase == Phase.RUN) {
  273. // 线体产量差仅展示;结案看压机5
  274. updateProducedAgainstActual(snap.actualQty);
  275. setText(txtProduced, String.valueOf(producedQty));
  276. int p5 = DcLineBatchContext.getPressProduced(5);
  277. setStatusUi("生产中 批次=" + batchCode
  278. + " 压机5 " + p5 + " / " + targetQty
  279. + " (达标后打印结案)");
  280. }
  281. } catch (Exception e) {
  282. log.warn("工位[{}] tick 异常: {}", cfg.getStationSn(), e.getMessage());
  283. }
  284. }
  285. /** SSE / 兜底:空闲则 nextBatch */
  286. public void tryAutoNextFromPush() {
  287. if (phase != Phase.IDLE) {
  288. return;
  289. }
  290. requestNextAsync();
  291. }
  292. public void tryAutoNextFromPush(String enqueueStationSn) {
  293. if (enqueueStationSn == null || !enqueueStationSn.trim().equalsIgnoreCase(getStationSn())) {
  294. return;
  295. }
  296. tryAutoNextFromPush();
  297. }
  298. /**
  299. * SSE 清码:本机正占用同一批次码则关允许并回空闲。
  300. * 结案上传中(DONE+挂起报文)不打断,避免丢续传导致热队列卡「已取」。
  301. */
  302. public void applyClearedFromPush(String clearedSn) {
  303. String local = nvl(batchCode);
  304. String remote = nvl(clearedSn);
  305. if (local.isEmpty() || remote.isEmpty() || !local.equalsIgnoreCase(remote)) {
  306. return;
  307. }
  308. if (phase == Phase.IDLE) {
  309. return;
  310. }
  311. if (phase == Phase.DONE && pendingCompleteFields != null) {
  312. log.info("工位[{}] 结案上传中收到清码 sn={},不打断", cfg.getStationSn(), local);
  313. return;
  314. }
  315. if (!busy.compareAndSet(false, true)) {
  316. return;
  317. }
  318. try {
  319. log.info("工位[{}] 收到清码推送,复位本地 batch={}", cfg.getStationSn(), local);
  320. plc.setMesAllow(false);
  321. pendingCompleteFields = null;
  322. // resetToIdle 内会关闭共享批次并通知压机页冲刷
  323. resetToIdle("服务端已清码 " + local);
  324. MainFrame.setMenuStatus(cfg.getStationSn() + " 已清码 " + local, 0);
  325. } finally {
  326. busy.set(false);
  327. }
  328. }
  329. /** 异步 nextBatch,不堵 PLC tick(自动门铃/兜底,带 2s 节流) */
  330. public void requestNextAsync() {
  331. requestNextAsync(false);
  332. }
  333. /**
  334. * 异步 nextBatch。
  335. *
  336. * @param forceManual true=手动按钮:跳过节流,必打日志,失败把服务端文案顶到状态条
  337. */
  338. public void requestNextAsync(final boolean forceManual) {
  339. if (phase != Phase.IDLE) {
  340. if (forceManual) {
  341. log.info("工位[{}] 手动取批次忽略:当前 phase={}", cfg.getStationSn(), phase);
  342. }
  343. return;
  344. }
  345. long now = System.currentTimeMillis();
  346. if (!forceManual && now - lastPollBatchAtMs < POLL_BATCH_INTERVAL_MS) {
  347. return;
  348. }
  349. lastPollBatchAtMs = now;
  350. if (serverIp.isEmpty()) {
  351. setStatusUi("空闲:等待扫码(server-ip 未配,仅可联调模拟)");
  352. log.warn("工位[{}] 取批次中止:server-ip 未配置", cfg.getStationSn());
  353. return;
  354. }
  355. if (!nextBusy.compareAndSet(false, true)) {
  356. if (forceManual) {
  357. setStatusUi("取批次进行中,请稍候…");
  358. log.info("工位[{}] 手动取批次:已有请求在飞,跳过重复点击", cfg.getStationSn());
  359. }
  360. return;
  361. }
  362. log.info("工位[{}] 开始 nextBatch{}", cfg.getStationSn(), forceManual ? "(手动)" : "");
  363. new Thread(new Runnable() {
  364. @Override
  365. public void run() {
  366. try {
  367. JSONObject ret = MesDcApiClient.nextBatch(serverIp, cfg.getStationSn());
  368. if (phase != Phase.IDLE) {
  369. log.info("工位[{}] nextBatch 返回时已非空闲 phase={},丢弃结果",
  370. cfg.getStationSn(), phase);
  371. return;
  372. }
  373. if (ret == null) {
  374. setStatusUi("取批次无响应(检查服务端/网络)");
  375. log.warn("工位[{}] nextBatch 无响应 server={}", cfg.getStationSn(), serverIp);
  376. return;
  377. }
  378. if (!MesDcApiClient.isSuccess(ret)) {
  379. String msg = MesDcApiClient.messageOf(ret);
  380. // 模具寿命:状态栏必显;弹窗仅手动取批,避免 SSE/轮询反复弹窗
  381. if (msg != null && msg.indexOf("模具寿命已到") >= 0) {
  382. setStatusUi(msg);
  383. if (forceManual) {
  384. showMoldLifeDialog(msg);
  385. }
  386. } else {
  387. setStatusUi("取批次:" + msg);
  388. }
  389. log.info("工位[{}] nextBatch 未取到:{}", cfg.getStationSn(), msg);
  390. return;
  391. }
  392. String code = MesDcApiClient.dataStr(ret, "batchCode");
  393. if (code.isEmpty()) {
  394. code = MesDcApiClient.dataStr(ret, "sn");
  395. }
  396. int target = MesDcApiClient.dataInt(ret, "targetQty", 0);
  397. if (target <= 0) {
  398. target = MesDcApiClient.dataInt(ret, "qty", 0);
  399. }
  400. if (code.isEmpty() || target <= 0) {
  401. setStatusUi("取批次成功但缺批次码/目标数量");
  402. log.warn("工位[{}] nextBatch 成功但缺 batchCode/targetQty: {}", cfg.getStationSn(), ret);
  403. return;
  404. }
  405. String queueUser = MesDcApiClient.dataStr(ret, "userCode");
  406. if (queueUser.isEmpty()) {
  407. queueUser = MesDcApiClient.dataStr(ret, "ucode");
  408. }
  409. log.info("工位[{}] nextBatch 成功 batch={} target={} userCode={}",
  410. cfg.getStationSn(), code, Integer.valueOf(target), queueUser);
  411. startBatchFromPda(code, target, queueUser);
  412. } finally {
  413. nextBusy.set(false);
  414. }
  415. }
  416. }, "dc-next-" + cfg.getStationSn()).start();
  417. }
  418. /**
  419. * 批次到位:记起点产量 → MES允许=true → 进入 RUN;本批做完再写 false。
  420. *
  421. * @param queueUserCode PDA 入队工号(可空)
  422. */
  423. private void startBatchFromPda(String code, int target, String queueUserCode) {
  424. // DONE 挂起续传中禁止再开批,避免冲掉待上传结案
  425. if (phase == Phase.RUN || phase == Phase.DONE) {
  426. return;
  427. }
  428. if (!busy.compareAndSet(false, true)) {
  429. return;
  430. }
  431. try {
  432. if (!plc.isConnected()) {
  433. plc.connect();
  434. }
  435. // 服务端 next 后队列已是「已取」:PLC 读不到也不能丢弃,否则热表卡住、界面像没反应
  436. Integer base = plc.readActualQty();
  437. int baseQty = 0;
  438. if (base == null) {
  439. log.warn("工位[{}] 开批时读实际产量失败(PLC 未连/点位异常),起点按 0,batch={}",
  440. cfg.getStationSn(), code);
  441. } else {
  442. baseQty = base.intValue();
  443. }
  444. batchCode = code;
  445. currentUserCode = queueUserCode == null ? "" : queueUserCode.trim();
  446. targetQty = target;
  447. baseActualQty = baseQty;
  448. lastActualQty = baseActualQty;
  449. producedQty = 0;
  450. batchStartTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
  451. // 共享给五台压机页:只主界面持有批次码
  452. DcLineBatchContext.open(batchCode, targetQty, batchStartTime);
  453. MainFrame.notifyPressesBatchOpened();
  454. boolean wrote = plc.setMesAllow(true);
  455. phase = Phase.RUN;
  456. setText(txtBatch, batchCode);
  457. setText(txtTarget, String.valueOf(targetQty));
  458. setText(txtProduced, "0");
  459. setMesAllowLamp(wrote);
  460. // 开批提示:区分开关关 / 点未配或写失败
  461. String tip;
  462. if (wrote) {
  463. tip = "批次已开,MES允许已写";
  464. } else if (!plc.isMesAllowEnabled()) {
  465. tip = "批次已开(MES允许开关已关,未写PLC)";
  466. } else {
  467. tip = "批次已开(允许点未配/写失败)";
  468. }
  469. if (base == null) {
  470. tip = tip + " PLC产量未读到,起点=0";
  471. } else {
  472. tip = tip + " 起始产量=" + baseActualQty;
  473. }
  474. tip = tip + " 结案看压机5";
  475. setStatusUi(tip);
  476. MainFrame.setMenuStatus(cfg.getStationSn() + " 开批 " + batchCode + " 目标" + targetQty, 0);
  477. log.info("工位[{}] 开批 batch={} target={} baseQty={} plcOk={}(结案条件=压机5达标)",
  478. cfg.getStationSn(), batchCode, Integer.valueOf(targetQty),
  479. Integer.valueOf(baseActualQty), Boolean.valueOf(base != null));
  480. } finally {
  481. busy.set(false);
  482. }
  483. }
  484. /**
  485. * 手动取批次:SSE 漏推时立刻 nextBatch(跳过节流,必打日志)。
  486. * 仅空闲可用。
  487. */
  488. public void onManualNextClick() {
  489. log.info("工位[{}] 点击「取批次」 phase={}", cfg.getStationSn(), phase);
  490. if (phase != Phase.IDLE) {
  491. setStatusUi("当前非空闲,无法取批次(进行中请用手动提交结案)");
  492. return;
  493. }
  494. setStatusUi("正在手动取批次…");
  495. requestNextAsync(true);
  496. }
  497. /**
  498. * 手动提交:设置菜单入口。
  499. * RUN:密码 mes → 确认批次/数量 → 结案(走挂起续传)。
  500. * DONE+挂起:可立即再打一次上传;其它态弹窗说明。
  501. */
  502. public void onManualSubmitClick() {
  503. log.info("工位[{}] 点击「手动提交」 phase={} batch={}",
  504. cfg.getStationSn(), phase, batchCode);
  505. if (phase == Phase.DONE && pendingCompleteFields != null) {
  506. int opt = JOptionPane.showConfirmDialog(dialogParent(),
  507. "批次 " + pendingBatchCode + " 结案上传未成功,是否立即重试?",
  508. "手动提交", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
  509. if (opt == JOptionPane.YES_OPTION) {
  510. setStatusUi("手动触发结案续传…");
  511. new Thread(new Runnable() {
  512. @Override
  513. public void run() {
  514. uploadPendingComplete(false);
  515. }
  516. }, "dc-manual-retry-" + cfg.getStationSn()).start();
  517. }
  518. return;
  519. }
  520. if (phase != Phase.RUN) {
  521. JOptionPane.showMessageDialog(dialogParent(),
  522. "当前无进行中的批次,无法手动提交。\n请先取批次并开批后再试。",
  523. "手动提交", JOptionPane.INFORMATION_MESSAGE);
  524. return;
  525. }
  526. if (!askMesPassword()) {
  527. return;
  528. }
  529. int qty = DcLineBatchContext.getPressProduced(5);
  530. if (qty <= 0) {
  531. qty = producedQty;
  532. }
  533. String confirm = "确认手动结案?\n"
  534. + "批次码:" + batchCode + "\n"
  535. + "压机5已产:" + DcLineBatchContext.getPressProduced(5) + "\n"
  536. + "线体已产:" + producedQty + "\n"
  537. + "计划产量:" + targetQty + "\n"
  538. + "本次上报数量:" + qty;
  539. int ok = JOptionPane.showConfirmDialog(dialogParent(), confirm, "手动提交",
  540. JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
  541. if (ok != JOptionPane.OK_OPTION) {
  542. return;
  543. }
  544. finishBatch(qty, false, true);
  545. }
  546. /**
  547. * 压机5冲次达标回调:按压机5已产数量结案并打印。
  548. *
  549. * @param press5Qty 压机5本批已产
  550. */
  551. public void finishFromPress5(int press5Qty) {
  552. if (phase != Phase.RUN) {
  553. return;
  554. }
  555. int qty = press5Qty > 0 ? press5Qty : DcLineBatchContext.getPressProduced(5);
  556. if (qty <= 0) {
  557. qty = producedQty;
  558. }
  559. log.info("工位[{}] 收到压机5达标结案 qty={} batch={}",
  560. cfg.getStationSn(), Integer.valueOf(qty), batchCode);
  561. finishBatch(qty, false, false);
  562. }
  563. /**
  564. * 弹出密码框;正确密码为 mes。
  565. *
  566. * @return true=校验通过
  567. */
  568. private boolean askMesPassword() {
  569. JPasswordField pf = new JPasswordField(12);
  570. JPanel box = new JPanel(new BorderLayout(8, 8));
  571. box.add(new JLabel("请输入密码"), BorderLayout.NORTH);
  572. box.add(pf, BorderLayout.CENTER);
  573. int opt = JOptionPane.showConfirmDialog(dialogParent(), box, "手动提交",
  574. JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
  575. if (opt != JOptionPane.OK_OPTION) {
  576. return false;
  577. }
  578. char[] input = pf.getPassword();
  579. boolean ok = Arrays.equals(input, "mes".toCharArray());
  580. Arrays.fill(input, '\0');
  581. if (!ok) {
  582. JOptionPane.showMessageDialog(dialogParent(), "密码错误", "手动提交", JOptionPane.WARNING_MESSAGE);
  583. return false;
  584. }
  585. return true;
  586. }
  587. /** 弹窗挂到主窗,避免工作面板未显示时对话框位置异常 */
  588. private Component dialogParent() {
  589. Window w = SwingUtilities.getWindowAncestor(this);
  590. return w != null ? w : this;
  591. }
  592. /** 产量达标结案 */
  593. private void finishBatch(final int qty, final boolean aborted) {
  594. finishBatch(qty, aborted, false);
  595. }
  596. /**
  597. * 结案:关 MES允许 → 本机记录 → 异步打印 → 挂起报文上传;
  598. * 仅 completeBatch 成功才回空闲,失败留 DONE 由 tick 续传。
  599. *
  600. * @param qty 本批数量
  601. * @param aborted 是否强制中断(结果 NG)
  602. * @param manual 是否手动提交
  603. */
  604. private void finishBatch(final int qty, final boolean aborted, final boolean manual) {
  605. if (!busy.compareAndSet(false, true)) {
  606. return;
  607. }
  608. phase = Phase.DONE;
  609. final String codeSnap = batchCode;
  610. final String timeSnap = batchStartTime;
  611. new Thread(new Runnable() {
  612. @Override
  613. public void run() {
  614. boolean fieldsReady = false;
  615. try {
  616. // 本批做完:MES允许改回 false
  617. plc.setMesAllow(false);
  618. SwingUtilities.invokeLater(new Runnable() {
  619. @Override
  620. public void run() {
  621. setMesAllowLamp(false);
  622. }
  623. });
  624. String time = timeSnap;
  625. if (time == null || time.isEmpty()) {
  626. time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
  627. }
  628. // 过站结果:中断 NG,否则 OK(含手动提交)
  629. String passResult = aborted ? "NG" : "OK";
  630. DcRunSnapshot snap = lastSnap == null ? new DcRunSnapshot() : lastSnap;
  631. final Map<String, String> fields = new LinkedHashMap<String, String>();
  632. fields.put("stationSn", cfg.getStationSn());
  633. fields.put("batchCode", codeSnap);
  634. fields.put("qty", String.valueOf(qty));
  635. fields.put("produceTime", time);
  636. fields.put("aborted", aborted ? "1" : "0");
  637. fields.put("manual", manual ? "1" : "0");
  638. fields.put("result", passResult);
  639. // 结案工号:取批时队列带回的入队工号;空则 system
  640. String jobUser = currentUserCode == null ? "" : currentUserCode.trim();
  641. fields.put("userCode", jobUser.isEmpty() ? "system" : jobUser);
  642. fields.put("currentPart", nvl(snap.currentPart));
  643. fields.put("nextPart", nvl(snap.nextPart));
  644. fields.put("actualQty", String.valueOf(snap.actualQty));
  645. fields.put("downtime", String.valueOf(snap.downtime));
  646. fields.put("takt", String.valueOf(snap.takt));
  647. fields.put("lineState", String.valueOf(snap.lineState));
  648. fields.put("lineStateText", nvl(snap.lineStateText));
  649. // 本机记录先落;挂起报文供 DONE 续传(按批次码幂等)
  650. DcWorkRecordStore.add(codeSnap, time, qty, passResult);
  651. MainFrame.refreshWorkRecords();
  652. String how = aborted ? "已强制结束" : (manual ? "手动提交" : "压机5达标");
  653. pendingCompleteFields = fields;
  654. pendingHow = how;
  655. pendingBatchCode = codeSnap;
  656. pendingQty = qty;
  657. pendingPrinted = false;
  658. fieldsReady = true;
  659. // 手动打印:只入列表不自动打;自动模式:异步送打(卡死不能挡结案)
  660. final String printTime = time;
  661. final String printBatch = codeSnap;
  662. final int printQty = qty;
  663. if (DcBatchPrinter.isManualPrintMode()) {
  664. DcPrintQueueStore.addPending(printBatch, printTime, printQty);
  665. MainFrame.refreshPrintList();
  666. pendingPrinted = false;
  667. log.info("工位[{}] 手动打印模式:批次已入打印列表 batch={}", cfg.getStationSn(), printBatch);
  668. setStatusUi("已入打印列表,请到「打印列表」确认送打");
  669. } else {
  670. new Thread(new Runnable() {
  671. @Override
  672. public void run() {
  673. boolean ok = DcBatchPrinter.printBatch(printBatch, printTime, printQty);
  674. pendingPrinted = ok;
  675. if (ok) {
  676. // 自动打成功也记一笔已打印,便于打印列表追溯
  677. DcPrintQueueStore.addPending(printBatch, printTime, printQty);
  678. DcPrintQueueStore.markPrinted(printBatch);
  679. MainFrame.refreshPrintList();
  680. } else {
  681. log.warn("工位[{}] 异步打印失败/无打印机 batch={}", cfg.getStationSn(), printBatch);
  682. }
  683. }
  684. }, "dc-print-" + cfg.getStationSn()).start();
  685. }
  686. // 先放 busy:phase=DONE,tick 可刷灯并可走续传
  687. busy.set(false);
  688. uploadPendingComplete(true);
  689. } catch (Exception ex) {
  690. log.error("工位[{}] 结案异常: {}", cfg.getStationSn(), ex.getMessage(), ex);
  691. setStatusUi("结案异常:" + ex.getMessage());
  692. if (!fieldsReady) {
  693. // 报文未备好:回到 RUN,可手动再提交
  694. phase = Phase.RUN;
  695. }
  696. } finally {
  697. busy.set(false);
  698. }
  699. }
  700. }, "dc-finish-" + cfg.getStationSn()).start();
  701. }
  702. /** DONE 态 tick 触发:有挂起结案则续传 */
  703. private void retryPendingCompleteIfAny() {
  704. if (pendingCompleteFields == null) {
  705. return;
  706. }
  707. uploadPendingComplete(false);
  708. }
  709. /**
  710. * 上传挂起的结案报文;成功才回空闲(关共享批次、通知压机)。
  711. *
  712. * @param fromFinishThread true=结案线程内首轮(可多等几轮);false=tick 续传单次
  713. */
  714. private void uploadPendingComplete(boolean fromFinishThread) {
  715. final Map<String, String> fields = pendingCompleteFields;
  716. if (fields == null) {
  717. return;
  718. }
  719. if (!completeRetryBusy.compareAndSet(false, true)) {
  720. return;
  721. }
  722. final String how = pendingHow;
  723. final String batch = pendingBatchCode;
  724. final int qty = pendingQty;
  725. try {
  726. int maxAttempts = fromFinishThread ? 12 : 1;
  727. boolean uploaded = false;
  728. for (int attempt = 1; attempt <= maxAttempts; attempt++) {
  729. JSONObject ret = MesDcApiClient.completeBatch(serverIp, fields);
  730. uploaded = MesDcApiClient.isSuccess(ret);
  731. if (uploaded) {
  732. break;
  733. }
  734. setStatusUi(how + " 批次码=" + batch + " 上传失败,重试中…(#" + attempt + ")");
  735. MainFrame.setMenuStatus(cfg.getStationSn() + " 上传失败重试 #" + attempt, -1);
  736. log.warn("工位[{}] 结案上传失败 batch={} attempt={} msg={}",
  737. cfg.getStationSn(), batch, Integer.valueOf(attempt),
  738. MesDcApiClient.messageOf(ret));
  739. if (attempt < maxAttempts) {
  740. try {
  741. Thread.sleep(5000L);
  742. } catch (InterruptedException ie) {
  743. Thread.currentThread().interrupt();
  744. break;
  745. }
  746. }
  747. }
  748. if (uploaded) {
  749. pendingCompleteFields = null;
  750. // 手动模式:未自动送打,提示去打印列表;自动模式按是否真正送打成功区分
  751. String printTip;
  752. if (DcBatchPrinter.isManualPrintMode()) {
  753. printTip = " 待手动打印";
  754. } else if (pendingPrinted) {
  755. printTip = " 已送打印";
  756. } else {
  757. printTip = " 打印已提交/待确认";
  758. }
  759. final String tip = how + " 批次码=" + batch + " 数量=" + qty
  760. + printTip + " 已上传";
  761. resetToIdle(tip);
  762. MainFrame.setMenuStatus(cfg.getStationSn() + " 结案 " + batch + " x" + qty, 0);
  763. log.info("工位[{}] 结案成功 batch={} qty={}", cfg.getStationSn(), batch, Integer.valueOf(qty));
  764. } else {
  765. setStatusUi(how + " 批次码=" + batch + " 等待续传…");
  766. }
  767. } finally {
  768. completeRetryBusy.set(false);
  769. }
  770. }
  771. /**
  772. * 按 PLC 实际产量累计本批已产。
  773. * 若实际产量比上一拍变小(人为复位/清零),保留已产件数,把起点挪到「当前值 − 已产」,
  774. * 避免差值为负导致进度归零、永远达不到目标。
  775. *
  776. * @param actualQty 当前 PLC 实际产量示值
  777. */
  778. private void updateProducedAgainstActual(int actualQty) {
  779. if (actualQty < lastActualQty) {
  780. int kept = producedQty;
  781. baseActualQty = actualQty - kept;
  782. log.warn("工位[{}] 检测到实际产量复位/变小:上次={} 本次={},保留已产={},重定起点={}",
  783. cfg.getStationSn(),
  784. Integer.valueOf(lastActualQty),
  785. Integer.valueOf(actualQty),
  786. Integer.valueOf(kept),
  787. Integer.valueOf(baseActualQty));
  788. setStatusUi("检测到产量复位,已保留本批进度 " + kept + " / " + targetQty);
  789. }
  790. int produced = actualQty - baseActualQty;
  791. if (produced < 0) {
  792. produced = 0;
  793. }
  794. // 本批内已产只增不减,防止抖动回退
  795. if (produced > producedQty) {
  796. producedQty = produced;
  797. }
  798. lastActualQty = actualQty;
  799. }
  800. private void resetToIdle(String msg) {
  801. phase = Phase.IDLE;
  802. batchCode = "";
  803. currentUserCode = "";
  804. targetQty = 0;
  805. baseActualQty = 0;
  806. producedQty = 0;
  807. lastActualQty = 0;
  808. batchStartTime = "";
  809. pendingCompleteFields = null;
  810. pendingHow = "";
  811. pendingBatchCode = "";
  812. pendingQty = 0;
  813. pendingPrinted = false;
  814. // 上传成功或清码后才关共享批次,挂起续传期间压机仍能看见本批
  815. DcLineBatchContext.close();
  816. MainFrame.notifyPressesBatchClosed();
  817. SwingUtilities.invokeLater(new Runnable() {
  818. @Override
  819. public void run() {
  820. setText(txtBatch, "");
  821. setText(txtTarget, "");
  822. setText(txtProduced, "");
  823. setText(txtPressProgress, "");
  824. setMesAllowLamp(false);
  825. setStatusUi(msg == null || msg.isEmpty()
  826. ? "空闲:等待扫码下发批次…" : msg + " → 等待下一笔");
  827. }
  828. });
  829. }
  830. /** 刷新主界面「五台冲次进度」汇总 */
  831. private void refreshPressProgressUi() {
  832. if (phase != Phase.RUN) {
  833. return;
  834. }
  835. final int target = targetQty;
  836. final StringBuilder sb = new StringBuilder();
  837. for (int i = 1; i <= 5; i++) {
  838. if (i > 1) {
  839. sb.append(" ");
  840. }
  841. sb.append(i).append('#').append(DcLineBatchContext.getPressProduced(i));
  842. if (target > 0) {
  843. sb.append('/').append(target);
  844. }
  845. }
  846. SwingUtilities.invokeLater(new Runnable() {
  847. @Override
  848. public void run() {
  849. setText(txtPressProgress, sb.toString());
  850. }
  851. });
  852. }
  853. private void refreshSnapshotUi(final DcRunSnapshot s) {
  854. if (s == null) {
  855. return;
  856. }
  857. SwingUtilities.invokeLater(new Runnable() {
  858. @Override
  859. public void run() {
  860. setText(txtCurrentPart, s.currentPart);
  861. setText(txtNextPart, s.nextPart);
  862. setText(txtActualQty, String.valueOf(s.actualQty));
  863. setText(txtDowntime, String.valueOf(s.downtime));
  864. setText(txtTakt, String.valueOf(s.takt));
  865. setText(txtLineState, nvl(s.lineStateText).isEmpty()
  866. ? String.valueOf(s.lineState) : s.lineStateText);
  867. setLineStateLamp(s.lineState);
  868. setMesAllowLamp(phase == Phase.RUN);
  869. }
  870. });
  871. }
  872. /**
  873. * 产线状态灯 + 说明:2 正常;3 故障;0/1 待机。
  874. */
  875. private void setLineStateLamp(final int lineState) {
  876. SwingUtilities.invokeLater(new Runnable() {
  877. @Override
  878. public void run() {
  879. StatusLight.Level lv = StatusLight.Level.OFF;
  880. String tip = "待机";
  881. if (lineState == 2) {
  882. lv = StatusLight.Level.ON;
  883. tip = "正常";
  884. } else if (lineState == 3) {
  885. lv = StatusLight.Level.FAULT;
  886. tip = "故障";
  887. }
  888. lampLineState.setLevel(lv);
  889. lblLineState.setText(tip);
  890. }
  891. });
  892. }
  893. /** 刷新 MES 允许指示灯 + 说明 */
  894. private void setMesAllowLamp(final boolean on) {
  895. SwingUtilities.invokeLater(new Runnable() {
  896. @Override
  897. public void run() {
  898. lampMesAllow.setOn(on);
  899. lblMesAllowState.setText(on ? "开" : "关");
  900. }
  901. });
  902. }
  903. /** 顶栏刷新:连接灯 + 状态说明 */
  904. private void uiPlcLabel() {
  905. final boolean ok = plc.isConnected();
  906. SwingUtilities.invokeLater(new Runnable() {
  907. @Override
  908. public void run() {
  909. lampPlc.setLevel(ok ? StatusLight.Level.ON : StatusLight.Level.FAULT);
  910. lblPlcState.setText(ok ? "已连接" : "未连接");
  911. }
  912. });
  913. }
  914. /** 按 SSE 连接态刷新 MES 呼吸灯 */
  915. private void uiServerHeartbeat() {
  916. final boolean online = MainFrame.isMesServerOnline();
  917. SwingUtilities.invokeLater(new Runnable() {
  918. @Override
  919. public void run() {
  920. serverHeartbeat.setOnline(online);
  921. serverHeartbeat.setToolTipText(online
  922. ? "服务端已连接(SSE 正常)"
  923. : "服务端已断开(SSE 未连)");
  924. }
  925. });
  926. }
  927. /** 顶栏状态说明(灯正下方) */
  928. private static JLabel headerStateLabel(String text) {
  929. JLabel lb = new JLabel(text, SwingConstants.CENTER);
  930. lb.setFont(new Font("微软雅黑", Font.PLAIN, 11));
  931. lb.setForeground(new Color(200, 230, 235));
  932. lb.setAlignmentX(Component.CENTER_ALIGNMENT);
  933. return lb;
  934. }
  935. /**
  936. * 顶栏一组:名称在上、灯居中、状态说明在灯下方。
  937. */
  938. private static JPanel headerLampItem(String name, StatusLight lamp, JLabel stateLbl) {
  939. JPanel p = new JPanel();
  940. p.setOpaque(false);
  941. p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
  942. JLabel lb = new JLabel(name, SwingConstants.CENTER);
  943. lb.setFont(new Font("微软雅黑", Font.PLAIN, 12));
  944. lb.setForeground(new Color(160, 210, 220));
  945. lb.setAlignmentX(Component.CENTER_ALIGNMENT);
  946. lamp.setAlignmentX(Component.CENTER_ALIGNMENT);
  947. stateLbl.setAlignmentX(Component.CENTER_ALIGNMENT);
  948. p.add(lb);
  949. p.add(Box.createVerticalStrut(2));
  950. p.add(lamp);
  951. p.add(Box.createVerticalStrut(2));
  952. p.add(stateLbl);
  953. return p;
  954. }
  955. /** 顶栏 MES 呼吸灯一组 */
  956. private static JPanel headerBreathingItem(String name, BreathingLight lamp) {
  957. JPanel p = new JPanel();
  958. p.setOpaque(false);
  959. p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
  960. JLabel lb = new JLabel(name, SwingConstants.CENTER);
  961. lb.setFont(new Font("微软雅黑", Font.PLAIN, 12));
  962. lb.setForeground(new Color(160, 210, 220));
  963. lb.setAlignmentX(Component.CENTER_ALIGNMENT);
  964. lamp.setAlignmentX(Component.CENTER_ALIGNMENT);
  965. p.add(lb);
  966. p.add(Box.createVerticalStrut(4));
  967. p.add(lamp);
  968. return p;
  969. }
  970. /**
  971. * 模具寿命卡关弹窗(取批线程回调,切回 EDT)。
  972. *
  973. * @param msg 服务端失败文案
  974. */
  975. private void showMoldLifeDialog(final String msg) {
  976. SwingUtilities.invokeLater(new Runnable() {
  977. @Override
  978. public void run() {
  979. JOptionPane.showMessageDialog(dialogParent(),
  980. msg == null || msg.isEmpty() ? "模具寿命已到,请更换模具" : msg,
  981. "模具寿命", JOptionPane.WARNING_MESSAGE);
  982. }
  983. });
  984. }
  985. private void setStatusUi(final String text) {
  986. SwingUtilities.invokeLater(new Runnable() {
  987. @Override
  988. public void run() {
  989. lblStatus.setText(text == null ? "" : text);
  990. String t = text == null ? "" : text;
  991. if (t.contains("失败") || t.contains("故障") || t.contains("模具寿命已到")) {
  992. lblStatus.setBackground(UiTheme.ERR_BG);
  993. lblStatus.setForeground(UiTheme.ERR_FG);
  994. } else if (t.contains("生产中") || t.contains("已开") || t.contains("开批")) {
  995. lblStatus.setBackground(UiTheme.RUN_BG);
  996. lblStatus.setForeground(UiTheme.RUN_FG);
  997. } else {
  998. lblStatus.setBackground(UiTheme.OK_BG);
  999. lblStatus.setForeground(UiTheme.OK_FG);
  1000. }
  1001. }
  1002. });
  1003. }
  1004. private static JTextField roField() {
  1005. JTextField t = new JTextField();
  1006. t.setEditable(false);
  1007. t.setFont(UiTheme.FONT_VALUE);
  1008. return t;
  1009. }
  1010. private static void setText(JTextField t, String v) {
  1011. if (t != null) {
  1012. t.setText(v == null ? "" : v);
  1013. }
  1014. }
  1015. private static String nvl(String s) {
  1016. return s == null ? "" : s.trim();
  1017. }
  1018. }