MesClient.java 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503
  1. package com.mes.ui;
  2. import com.alibaba.fastjson2.JSONObject;
  3. import com.google.zxing.BarcodeFormat;
  4. import com.google.zxing.WriterException;
  5. import com.google.zxing.client.j2se.MatrixToImageWriter;
  6. import com.google.zxing.common.BitMatrix;
  7. import com.google.zxing.qrcode.QRCodeWriter;
  8. import com.mes.component.MesRadio;
  9. import com.mes.component.MesWebView;
  10. import com.mes.netty.NettyClient;
  11. import com.mes.util.*;
  12. import org.slf4j.Logger;
  13. import org.slf4j.LoggerFactory;
  14. import javax.swing.*;
  15. import javax.swing.border.EmptyBorder;
  16. import javax.swing.event.ChangeEvent;
  17. import javax.swing.event.ChangeListener;
  18. import java.awt.*;
  19. import java.awt.event.*;
  20. import java.awt.image.BufferedImage;
  21. import java.time.LocalDateTime;
  22. import java.util.*;
  23. import java.util.List;
  24. import java.util.Timer;
  25. public class MesClient extends JFrame {
  26. public static final Logger log = LoggerFactory.getLogger(MesClient.class);
  27. public static int mes_auth = 0; // 权限级别 0=无权限 1=操作工人 2=管理员
  28. public static boolean tcp_connect_flag = false; //TCP连接状态
  29. public static boolean allow_connect_again = false; // 是否允许断线重连, true 表示 允许
  30. public static String user20 = "";
  31. public static String sessionid = "";
  32. public static NettyClient nettyClient;
  33. public static Boolean check_quality_result1 = false;
  34. public static Integer work_status1 = 0;
  35. public static Integer canReadResult1 = 0; // 1=可以读取结果
  36. public static Boolean check_quality_result2 = false;
  37. public static Integer work_status2 = 0;
  38. public static Integer canReadResult2 = 0; // 1=可以读取结果
  39. // 记录扫码工件码的时间,用于限制提交必须在扫码后满30秒
  40. public static long scan_time1 = 0L;
  41. public static long scan_time2 = 0L;
  42. public static JButton finish_ok_bt_1;
  43. public static JButton finish_ng_bt_1;
  44. public static JTextField product_sn_1;
  45. public static JButton f_scan_data_bt_1;
  46. public static JButton status_menu_1;
  47. public static JTextField pressureText_1; // 压力值显示文本框
  48. public static JTextField leakText_1; // 压力值显示文本框
  49. public static JButton finish_ok_bt_2;
  50. public static JButton finish_ng_bt_2;
  51. public static JTextField product_sn_2;
  52. public static JButton f_scan_data_bt_2;
  53. public static JButton status_menu_2;
  54. public static JTextField pressureText_2; // 压力值显示文本框
  55. public static JTextField leakText_2; // 压力值显示文本框
  56. public static JPanel contentPane;
  57. public static MesClient mesClientFrame;
  58. public static JTabbedPane tabbedPane;
  59. public static JScrollPane indexScrollPaneA;
  60. public static JScrollPane searchScrollPane;
  61. public static JScrollPane searchScrollPaneDjA;
  62. public static JScrollPane searchScrollPaneDjB;
  63. public static JPanel panel4;
  64. public static JScrollPane scrollPane4;
  65. public static JPanel panel5;
  66. public static JScrollPane scrollPane5;
  67. public static JButton heart_beat_menu;
  68. public static JButton user_menu;
  69. public static JFrame welcomeWin;
  70. public static JPanel indexPanelB;
  71. public static MesWebView jfxPanel = null;
  72. public static JPanel indexPanelDjA;
  73. public static JPanel indexPanelDjB;
  74. public static MesWebView jfxPanelDjA = null;
  75. public static MesWebView jfxPanelDjB = null;
  76. public static MesRadio mesRadioHj;
  77. public static JTable table;
  78. public static Object[] columnNames = {"物料名称", "绑定批次", "剩余次数", "操作"};
  79. public static Object[][] rowData = null;
  80. // 记录查询(仿照 OP370-AUTO:工件码/测试日期/压力/泄漏值/结果)
  81. public static JTable recordTable_1;
  82. public static Object[] recordColumnNames_1 = {"工件码", "测试日期", "压力", "泄漏值", "结果"};
  83. public static Object[][] recordRowData_1 = new Object[12][5];
  84. public static JLabel recordPageLabel_1;
  85. public static int recordPageNo_1 = 1;
  86. public static int recordTotalPages_1 = 0;
  87. public static JTextField recordSearchField_1;
  88. public static JTable recordTable_2;
  89. public static Object[] recordColumnNames_2 = {"工件码", "测试日期", "压力", "泄漏值", "结果"};
  90. public static Object[][] recordRowData_2 = new Object[12][5];
  91. public static JLabel recordPageLabel_2;
  92. public static int recordPageNo_2 = 1;
  93. public static int recordTotalPages_2 = 0;
  94. public static JTextField recordSearchField_2;
  95. public static JTable recordTableOkng;
  96. public static Object[] recordColumnNamesOkng = {"工位", "样件", "工件码", "测试日期", "压力", "泄漏值", "结果"};
  97. public static Object[][] recordRowDataOkng = new Object[12][7];
  98. public static JLabel recordPageLabelOkng;
  99. public static int recordPageNoOkng = 1;
  100. public static int recordTotalPagesOkng = 0;
  101. public static JTextField recordSearchFieldOkng;
  102. public static JPanel panelOkng;
  103. public static JScrollPane scrollPaneOkng;
  104. private static final List<String> okngSampleSns = new ArrayList<>();
  105. private static final Map<String, String> okngSampleType = new HashMap<>();
  106. String currentSerialPort1 = Config.portName1;
  107. String currentSerialPort2 = Config.portName2;
  108. public static TCPClient tcpClient1 = new TCPClient("192.168.18.184",9004);
  109. public static TCPClient tcpClient2 = new TCPClient("192.168.18.183",9004);
  110. public static int scanFlag1 = 0;
  111. public static int scanFlag2 = 0;
  112. public static void main(String[] args) {
  113. EventQueue.invokeLater(new Runnable() {
  114. @Override
  115. public void run() {
  116. try {
  117. // 显示界面
  118. mesClientFrame = new MesClient();
  119. mesClientFrame.setVisible(false);
  120. JdbcUtils.getConn();
  121. welcomeWin = new LoginFrame();
  122. welcomeWin.setVisible(true);
  123. } catch (Exception e) {
  124. log.error(e.getMessage());
  125. }
  126. }
  127. });
  128. }
  129. // 初始化TCP
  130. public static void initTcpConnection() {
  131. try {
  132. if (nettyClient == null) {
  133. nettyClient = new NettyClient();
  134. tcp_connect_flag = false; //设置TCP连接状态
  135. DataUtil.synrTcp(nettyClient, Config.gw_1);
  136. }
  137. } catch (Exception e) {
  138. log.error("初始化TCP失败", e);
  139. }
  140. }
  141. //启动心跳包程序
  142. public static java.util.Timer heartBeatTimer;
  143. public static java.util.Timer heartBeatIconTimer;
  144. public static boolean iconREDFlag = true;
  145. public static void startHeartBeatTimer() {
  146. if (heartBeatTimer != null) {
  147. heartBeatTimer.cancel();
  148. }
  149. heartBeatTimer = new java.util.Timer();
  150. heartBeatTimer.schedule(new TimerTask() {
  151. public void run() {
  152. if (nettyClient != null && tcp_connect_flag) {
  153. DataUtil.heartBeat(nettyClient, Config.gw_1);
  154. heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
  155. }
  156. }
  157. }, 100, Config.heart_beat_cycle * 1000);
  158. //心跳显示图标
  159. if (heartBeatIconTimer != null) {
  160. heartBeatIconTimer.cancel();
  161. }
  162. heartBeatIconTimer = new Timer();
  163. heartBeatIconTimer.schedule(new TimerTask() {
  164. public void run() {
  165. if (tcp_connect_flag) {
  166. if (iconREDFlag) {
  167. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  168. iconREDFlag = false;
  169. } else {
  170. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
  171. iconREDFlag = true;
  172. }
  173. heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
  174. heart_beat_menu.setForeground(Color.GREEN);
  175. heart_beat_menu.repaint();
  176. } else {
  177. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  178. heart_beat_menu.setText("Mes连接断开");
  179. heart_beat_menu.setForeground(Color.RED);
  180. heart_beat_menu.repaint();
  181. //若未连接则尝试连接
  182. if (nettyClient != null) {
  183. //TCP重新同步连接
  184. if (allow_connect_again) {
  185. log.info("TCP连接已断开, 在心跳循环中, 发送同步连接请求");
  186. allow_connect_again = false; // 只允许重新同步连接一次
  187. DataUtil.synrTcp(nettyClient, Config.gw_1);
  188. }
  189. }
  190. }
  191. }
  192. }, 100, Config.heart_icon_cycle * 1000);
  193. }
  194. public static void initWarehouseData() {
  195. resetScanA();
  196. resetScanB();
  197. }
  198. public static void resetScanA() {
  199. MesClient.finish_ok_bt_1.setEnabled(false);
  200. MesClient.finish_ng_bt_1.setEnabled(false);
  201. MesClient.f_scan_data_bt_1.setEnabled(true);
  202. product_sn_1.setText("");
  203. scan_time1 = 0L;
  204. // leakText_1.setText("");
  205. // pressureText_1.setText("");
  206. // MesClient.setMenuState_1("请扫工件码", 0);
  207. // WorkTimer.ateq1.resetFIFO();
  208. work_status1 = 0;
  209. check_quality_result1 = false;
  210. }
  211. public static void resetScanB() {
  212. MesClient.finish_ok_bt_2.setEnabled(false);
  213. MesClient.finish_ng_bt_2.setEnabled(false);
  214. MesClient.f_scan_data_bt_2.setEnabled(true);
  215. product_sn_2.setText("");
  216. scan_time2 = 0L;
  217. // leakText_2.setText("");
  218. // pressureText_2.setText("");
  219. // MesClient.setMenuState_2("请扫工件码", 0);
  220. // WorkTimer.ateq2.resetFIFO();
  221. work_status2 = 0;
  222. check_quality_result2 = false;
  223. }
  224. public static int userLoginHours;//用户登录所处小时
  225. //换班用户信息检查
  226. private static void shiftUserCheck() {
  227. LocalDateTime now = LocalDateTime.now();
  228. // 判断时间范围
  229. if (userLoginHours >= 8 && userLoginHours < 20) {
  230. int hour = now.getHour();
  231. if (hour >= 20 || hour < 8) {
  232. logoff();
  233. }
  234. } else {
  235. int hour = now.getHour();
  236. if (hour >= 8 && hour < 20) {
  237. logoff();
  238. }
  239. }
  240. }
  241. //获取用户20位
  242. public static void getUser() {
  243. user20 = user_menu.getText();
  244. String space_tmp1 = "";
  245. if (user20.length() < 20) {
  246. for (int i = 0; i < 20 - user20.length(); i++) {
  247. space_tmp1 = space_tmp1 + " ";
  248. }
  249. }
  250. user20 = user20 + space_tmp1;
  251. }
  252. //获取barcode内容36位
  253. public static String getBarcode(String barcodeTmp) {
  254. String barcodeRet = barcodeTmp;
  255. if (barcodeTmp.equalsIgnoreCase("")) {
  256. return "";
  257. } else {
  258. if (barcodeTmp.length() < 36) {
  259. String space = "";
  260. for (int i = 0; i < 36 - barcodeTmp.length(); i++) {
  261. space = space + " ";
  262. }
  263. barcodeRet = barcodeTmp + space;
  264. }
  265. }
  266. return barcodeRet;
  267. }
  268. public static String getBarcode33(String barcodeTmp) {
  269. String barcodeRet = barcodeTmp;
  270. if (barcodeTmp.equalsIgnoreCase("")) {
  271. return "";
  272. } else {
  273. if (barcodeTmp.length() < 33) {
  274. String space = "";
  275. for (int i = 0; i < 33 - barcodeTmp.length(); i++) {
  276. space = space + " ";
  277. }
  278. barcodeRet = barcodeTmp + space;
  279. }
  280. }
  281. return barcodeRet;
  282. }
  283. public static void scanBarcode1() {
  284. if (work_status1 == 1) {
  285. JOptionPane.showMessageDialog(mesClientFrame, "工作中,勿扫码", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
  286. return;
  287. }
  288. WorkTimer.ateq1.resetFIFO();
  289. product_sn_1.setText("");
  290. leakText_1.setText("");
  291. pressureText_1.setText("");
  292. MesClient.setMenuState_1("请扫工件码", 0);
  293. //弹窗扫工件码
  294. // String scanBarcode = JOptionPane.showInputDialog(null, "请扫工件码");
  295. String scanBarcode = MesClient.scanQrcode1();
  296. if (scanBarcode != null && !scanBarcode.equalsIgnoreCase("")) {
  297. product_sn_1.setText(scanBarcode);
  298. scan_time1 = System.currentTimeMillis();
  299. //刷新界面
  300. mesClientFrame.repaint();
  301. if (!tcp_connect_flag) {
  302. JOptionPane.showMessageDialog(mesClientFrame, "设备未连接Mes服务器", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
  303. return;
  304. }
  305. // 查询工件质量
  306. Boolean sendret = DataUtil.checkQuality(nettyClient, scanBarcode.trim(), user20, Config.gw_1);
  307. if (!sendret) {
  308. JOptionPane.showMessageDialog(mesClientFrame, "消息发送失败,请重试", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
  309. }
  310. } else {
  311. JOptionPane.showMessageDialog(mesClientFrame, "请扫工件码", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
  312. }
  313. }
  314. public static void scanBarcode2() {
  315. if (work_status2 == 1) {
  316. JOptionPane.showMessageDialog(mesClientFrame, "工作中,勿扫码", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
  317. return;
  318. }
  319. WorkTimer.ateq2.resetFIFO();
  320. product_sn_2.setText("");
  321. leakText_2.setText("");
  322. pressureText_2.setText("");
  323. MesClient.setMenuState_2("请扫工件码", 0);
  324. //弹窗扫工件码
  325. // String scanBarcode = JOptionPane.showInputDialog(null, "请扫工件码");
  326. String scanBarcode = MesClient.scanQrcode2();
  327. if (scanBarcode != null && !scanBarcode.equalsIgnoreCase("")) {
  328. product_sn_2.setText(scanBarcode);
  329. scan_time2 = System.currentTimeMillis();
  330. //刷新界面
  331. mesClientFrame.repaint();
  332. if (!tcp_connect_flag) {
  333. JOptionPane.showMessageDialog(mesClientFrame, "设备未连接Mes服务器", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
  334. return;
  335. }
  336. // 查询工件质量
  337. Boolean sendret = DataUtil.checkQuality(nettyClient, scanBarcode.trim(), user20, Config.gw_2);
  338. if (!sendret) {
  339. JOptionPane.showMessageDialog(mesClientFrame, "消息发送失败,请重试", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
  340. }
  341. } else {
  342. JOptionPane.showMessageDialog(mesClientFrame, "请扫工件码", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
  343. }
  344. }
  345. public static void logoff() {
  346. mesClientFrame.setVisible(false);
  347. welcomeWin.setVisible(true);
  348. nettyClient = null;
  349. tcp_connect_flag = false;
  350. allow_connect_again = false;
  351. mes_auth = 0;
  352. UpdateQualityTimer.stop(); // 停止更新质量的定时任务
  353. WorkTimer.stop();
  354. }
  355. private static void createQRCode(String s) {
  356. log.info("准备生成二维码");
  357. if(s == null || s.isEmpty()){
  358. log.info("生成二维码失败: 工件码为空");
  359. return;
  360. }
  361. s = s.trim();
  362. try {
  363. BitMatrix bitMatrix = new QRCodeWriter().encode(s, BarcodeFormat.QR_CODE, 200, 200);
  364. BufferedImage qrImage = MatrixToImageWriter.toBufferedImage(bitMatrix);
  365. JDialog qrDialog = new JDialog(mesClientFrame, "", Dialog.ModalityType.APPLICATION_MODAL);
  366. qrDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
  367. qrDialog.setSize(250, 250);
  368. qrDialog.setLocationRelativeTo(mesClientFrame);
  369. qrDialog.setResizable(false);
  370. JLabel qrLabel = new JLabel(new ImageIcon(qrImage));
  371. qrDialog.getContentPane().add(qrLabel, BorderLayout.CENTER);
  372. qrDialog.setVisible(true);
  373. } catch (Exception e) {
  374. log.error("生成二维码失败", e);
  375. }
  376. }
  377. public MesClient() {
  378. setIconImage(Toolkit.getDefaultToolkit().getImage(MesClient.class.getResource("/bg/logo.png")));
  379. setTitle("MES系统客户端:OP400A/OP400B " + "总成气密检测");
  380. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  381. setBounds(0, 0, 1024, 768);
  382. JMenuBar menuBar = new JMenuBar();
  383. menuBar.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 26));
  384. setJMenuBar(menuBar);
  385. JMenu fileMenu = new JMenu("用户");
  386. fileMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/user.png")));
  387. fileMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  388. menuBar.add(fileMenu);
  389. JMenuItem exitMenuItem = new JMenuItem("退出");
  390. exitMenuItem.setIcon(new ImageIcon(MesClient.class.getResource("/bg/logoff.png")));
  391. exitMenuItem.setFont(new Font("微软雅黑", Font.PLAIN, 22));
  392. fileMenu.add(exitMenuItem);
  393. exitMenuItem.addMouseListener(new MouseAdapter() {
  394. @Override
  395. public void mousePressed(MouseEvent e) {//只能检测到mousePressed事件
  396. super.mouseClicked(e);
  397. logoff();
  398. }
  399. });
  400. JMenu settingMenu = new JMenu("设置");
  401. //settingMenu.setVisible(false);
  402. settingMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")));
  403. settingMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  404. menuBar.add(settingMenu);
  405. JMenuItem resetTcpMenu = new JMenuItem("重连MES");
  406. resetTcpMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  407. resetTcpMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  408. resetTcpMenu.addMouseListener(new MouseAdapter() {
  409. @Override
  410. public void mousePressed(MouseEvent e) {
  411. super.mouseClicked(e);
  412. //重连mes
  413. nettyClient.future.channel().close();
  414. }
  415. });
  416. settingMenu.add(resetTcpMenu);
  417. JMenuItem resetTcpMenu_1 = new JMenuItem("刷新" + Config.gw_1);
  418. resetTcpMenu_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  419. resetTcpMenu_1.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  420. resetTcpMenu_1.addMouseListener(new MouseAdapter() {
  421. @Override
  422. public void mousePressed(MouseEvent e) {
  423. super.mouseClicked(e);
  424. setMenuState_1("已手动刷新,请扫码", 0);
  425. resetScanA();
  426. }
  427. });
  428. settingMenu.add(resetTcpMenu_1);
  429. JMenuItem resetTcpMenu_2 = new JMenuItem("刷新" + Config.gw_2);
  430. resetTcpMenu_2.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  431. resetTcpMenu_2.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  432. resetTcpMenu_2.addMouseListener(new MouseAdapter() {
  433. @Override
  434. public void mousePressed(MouseEvent e) {
  435. super.mouseClicked(e);
  436. setMenuState_2("已手动刷新,请扫码", 0);
  437. resetScanB();
  438. }
  439. });
  440. settingMenu.add(resetTcpMenu_2);
  441. contentPane = new JPanel();
  442. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  443. setContentPane(contentPane);
  444. contentPane.setLayout(new BorderLayout(0, 0));
  445. JToolBar toolBar = new JToolBar();
  446. contentPane.add(toolBar, BorderLayout.NORTH);
  447. JLabel equipment_statu_label = new JLabel("状态:");
  448. equipment_statu_label.setHorizontalAlignment(SwingConstants.CENTER);
  449. equipment_statu_label.setForeground(Color.BLACK);
  450. equipment_statu_label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  451. equipment_statu_label.setBackground(Color.LIGHT_GRAY);
  452. toolBar.add(equipment_statu_label);
  453. JButton status_menu = new JButton("");
  454. status_menu.addActionListener(new ActionListener() {
  455. public void actionPerformed(ActionEvent e) {
  456. }
  457. });
  458. status_menu.setForeground(Color.GREEN);
  459. status_menu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  460. status_menu.setBackground(Color.BLACK);
  461. toolBar.add(status_menu);
  462. JLabel space_1 = new JLabel(" ");
  463. toolBar.add(space_1);
  464. JLabel heart_beat_status_label = new JLabel("心跳:");
  465. heart_beat_status_label.setHorizontalAlignment(SwingConstants.CENTER);
  466. heart_beat_status_label.setForeground(Color.BLACK);
  467. heart_beat_status_label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  468. heart_beat_status_label.setBackground(Color.LIGHT_GRAY);
  469. toolBar.add(heart_beat_status_label);
  470. heart_beat_menu = new JButton("");
  471. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
  472. heart_beat_menu.setForeground(Color.GREEN);
  473. heart_beat_menu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  474. heart_beat_menu.setBackground(Color.BLACK);
  475. toolBar.add(heart_beat_menu);
  476. JLabel space_2 = new JLabel(" ");
  477. toolBar.add(space_2);
  478. JLabel user_status_label = new JLabel("登录用户:");
  479. user_status_label.setHorizontalAlignment(SwingConstants.CENTER);
  480. user_status_label.setForeground(Color.BLACK);
  481. user_status_label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  482. user_status_label.setBackground(Color.LIGHT_GRAY);
  483. toolBar.add(user_status_label);
  484. user_menu = new JButton("");
  485. user_menu.setForeground(Color.GREEN);
  486. user_menu.setFont(new Font("微软雅黑", Font.PLAIN, 22));
  487. user_menu.setBackground(Color.BLACK);
  488. toolBar.add(user_menu);
  489. JLabel space_3 = new JLabel(" ");
  490. toolBar.add(space_3);
  491. JLabel space_4 = new JLabel(" ");
  492. toolBar.add(space_4);
  493. tabbedPane = new JTabbedPane(JTabbedPane.TOP);
  494. tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
  495. tabbedPane.setMinimumSize(new Dimension(400, 50));
  496. tabbedPane.setFont(new Font("宋体", Font.BOLD, 22));
  497. contentPane.add(tabbedPane);
  498. //首页
  499. JPanel indexPanelA = new JPanel();
  500. indexScrollPaneA = new JScrollPane(indexPanelA);
  501. indexPanelA.setLayout(null);
  502. // 工位1
  503. product_sn_1 = new JTextField();
  504. product_sn_1.setHorizontalAlignment(SwingConstants.CENTER);
  505. product_sn_1.setEditable(false);
  506. product_sn_1.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  507. product_sn_1.setBounds(0, 60, 489, 70);
  508. indexPanelA.add(product_sn_1);
  509. product_sn_1.setColumns(10);
  510. product_sn_1.addMouseListener(new MouseAdapter() {
  511. public void mouseClicked(MouseEvent e) {
  512. createQRCode(product_sn_1.getText());
  513. }
  514. });
  515. f_scan_data_bt_1 = new JButton("扫码");
  516. f_scan_data_bt_1.addActionListener(new ActionListener() {
  517. public void actionPerformed(ActionEvent e) { scanBarcode1();}
  518. });
  519. f_scan_data_bt_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/scan_barcode.png")));
  520. f_scan_data_bt_1.setFont(new Font("微软雅黑", Font.PLAIN, 32));
  521. f_scan_data_bt_1.setBounds(280, 340, 171, 70);
  522. indexPanelA.add(f_scan_data_bt_1);
  523. finish_ok_bt_1 = new JButton("OK");
  524. finish_ok_bt_1.setEnabled(false);
  525. finish_ok_bt_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
  526. finish_ok_bt_1.setFont(new Font("微软雅黑", Font.PLAIN, 32));
  527. finish_ok_bt_1.setBounds(0, 335, 125, 80);
  528. finish_ok_bt_1.setEnabled(false);
  529. indexPanelA.add(finish_ok_bt_1);
  530. finish_ng_bt_1 = new JButton("NG");
  531. finish_ng_bt_1.setEnabled(false);
  532. finish_ng_bt_1.addActionListener(new ActionListener() {
  533. public void actionPerformed(ActionEvent e) {}
  534. });
  535. finish_ng_bt_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ng_bg.png")));
  536. finish_ng_bt_1.setFont(new Font("微软雅黑", Font.PLAIN, 32));
  537. finish_ng_bt_1.setBounds(128, 335, 125, 80);
  538. finish_ng_bt_1.setEnabled(false);
  539. indexPanelA.add(finish_ng_bt_1);
  540. status_menu_1 = new JButton("等待加工信号");
  541. status_menu_1.addActionListener(new ActionListener() {
  542. public void actionPerformed(ActionEvent e) {}
  543. });
  544. status_menu_1.setForeground(Color.GREEN);
  545. status_menu_1.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  546. status_menu_1.setBackground(Color.BLACK);
  547. status_menu_1.setBounds(100, 8, 340, 35);
  548. indexPanelA.add(status_menu_1);
  549. JLabel state_label_1 = new JLabel(Config.gw_1);
  550. state_label_1.setHorizontalAlignment(SwingConstants.LEFT);
  551. state_label_1.setForeground(Color.BLACK);
  552. state_label_1.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  553. state_label_1.setBackground(Color.LIGHT_GRAY);
  554. state_label_1.setBounds(0, 10, 150, 28);
  555. indexPanelA.add(state_label_1);
  556. JLabel lblNewLabel = new JLabel("压力");
  557. lblNewLabel.setHorizontalAlignment(SwingConstants.RIGHT);
  558. lblNewLabel.setFont(new Font("微软雅黑", Font.PLAIN, 25));
  559. lblNewLabel.setBounds(30, 160, 96, 53);
  560. indexPanelA.add(lblNewLabel);
  561. pressureText_1 = new JTextField();
  562. pressureText_1.setFont(new Font("微软雅黑", Font.PLAIN, 25));
  563. pressureText_1.setEnabled(false);
  564. pressureText_1.setForeground(Color.BLACK);
  565. pressureText_1.setBounds(150, 160, 191, 56);
  566. indexPanelA.add(pressureText_1);
  567. pressureText_1.setColumns(10);
  568. JLabel lblNewLabel_1 = new JLabel("泄漏");
  569. lblNewLabel_1.setHorizontalAlignment(SwingConstants.RIGHT);
  570. lblNewLabel_1.setFont(new Font("微软雅黑", Font.PLAIN, 25));
  571. lblNewLabel_1.setBounds(30, 235, 96, 53);
  572. indexPanelA.add(lblNewLabel_1);
  573. leakText_1 = new JTextField();
  574. leakText_1.setFont(new Font("微软雅黑", Font.PLAIN, 25));
  575. leakText_1.setEnabled(false);
  576. leakText_1.setColumns(10);
  577. leakText_1.setBounds(150, 235, 191, 56);
  578. indexPanelA.add(leakText_1);
  579. JLabel serialportStr1 = new JLabel("串口:");
  580. serialportStr1.setHorizontalAlignment(SwingConstants.LEFT);
  581. serialportStr1.setFont(new Font("微软雅黑", Font.PLAIN, 22));
  582. indexPanelA.add(serialportStr1);
  583. serialportStr1.setBounds(338, 490, 100, 45);
  584. // 下拉框
  585. JComboBox<String> comboBox1 = new JComboBox<>(new String[]{"COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", "COM10", "COM11","COM12", "COM13", "COM14", "COM15", "COM16", "COM17", "COM18"});
  586. comboBox1.setPreferredSize(new Dimension(90, 45));
  587. comboBox1.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  588. // 设置初始化选中项
  589. comboBox1.setSelectedItem(Config.portName1);
  590. // 添加监听
  591. comboBox1.addItemListener(new ItemListener() {
  592. @Override
  593. public void itemStateChanged(ItemEvent e) {
  594. String selectedItem = (String) e.getItem();
  595. if (e.getStateChange() == ItemEvent.SELECTED && !Objects.equals(selectedItem, currentSerialPort1)) {
  596. int option = JOptionPane.showConfirmDialog(mesClientFrame, "确定切换串口至" + selectedItem + "?", "切换串口", JOptionPane.OK_CANCEL_OPTION);
  597. if (option == JOptionPane.OK_OPTION) {
  598. // 用户确认切换
  599. log.info("============用户切换{}串口至 {}==============", Config.gw_1, selectedItem);
  600. currentSerialPort1 = selectedItem;
  601. WorkTimer.ateq1.replaceSerialUtil(new SerialUtil(selectedItem));
  602. resetScanA();
  603. setMenuState_1("切换" + Config.gw_1 + "串口至" + selectedItem + ",请扫码", 0);
  604. log.info("=============切换{}串口成功===================", Config.gw_1);
  605. } else {
  606. // 用户取消切换,恢复之前的选项
  607. comboBox1.setSelectedItem(currentSerialPort1);
  608. }
  609. }
  610. }
  611. });
  612. comboBox1.setBounds(385, 490, 100, 45);
  613. indexPanelA.add(comboBox1);
  614. // 工位2
  615. product_sn_2 = new JTextField();
  616. product_sn_2.setHorizontalAlignment(SwingConstants.CENTER);
  617. product_sn_2.setEditable(false);
  618. product_sn_2.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  619. product_sn_2.setBounds(497, 60, 489, 70);
  620. indexPanelA.add(product_sn_2);
  621. product_sn_2.setColumns(10);
  622. product_sn_2.addMouseListener(new MouseAdapter() {
  623. public void mouseClicked(MouseEvent e) {
  624. createQRCode(product_sn_2.getText());
  625. }
  626. });
  627. f_scan_data_bt_2 = new JButton("扫码");
  628. f_scan_data_bt_2.addActionListener(new ActionListener() {
  629. public void actionPerformed(ActionEvent e) { scanBarcode2();}
  630. });
  631. f_scan_data_bt_2.setIcon(new ImageIcon(MesClient.class.getResource("/bg/scan_barcode.png")));
  632. f_scan_data_bt_2.setFont(new Font("微软雅黑", Font.PLAIN, 32));
  633. f_scan_data_bt_2.setBounds(280+497, 340, 171, 70);
  634. indexPanelA.add(f_scan_data_bt_2);
  635. finish_ok_bt_2 = new JButton("OK");
  636. finish_ok_bt_2.setEnabled(false);
  637. finish_ok_bt_2.addActionListener(new ActionListener() {
  638. public void actionPerformed(ActionEvent e) {}
  639. });
  640. finish_ok_bt_2.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
  641. finish_ok_bt_2.setFont(new Font("微软雅黑", Font.PLAIN, 32));
  642. finish_ok_bt_2.setBounds(497, 335, 125, 80);
  643. finish_ok_bt_2.setEnabled(false);
  644. indexPanelA.add(finish_ok_bt_2);
  645. finish_ng_bt_2 = new JButton("NG");
  646. finish_ng_bt_2.setEnabled(false);
  647. finish_ng_bt_2.addActionListener(new ActionListener() {
  648. public void actionPerformed(ActionEvent e) {}
  649. });
  650. finish_ng_bt_2.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ng_bg.png")));
  651. finish_ng_bt_2.setFont(new Font("微软雅黑", Font.PLAIN, 32));
  652. finish_ng_bt_2.setBounds(128 + 497, 335, 125, 80);
  653. finish_ng_bt_2.setEnabled(false);
  654. indexPanelA.add(finish_ng_bt_2);
  655. status_menu_2 = new JButton("等待加工信号");
  656. status_menu_2.addActionListener(new ActionListener() {
  657. public void actionPerformed(ActionEvent e) {
  658. }
  659. });
  660. status_menu_2.setForeground(Color.GREEN);
  661. status_menu_2.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  662. status_menu_2.setBackground(Color.BLACK);
  663. status_menu_2.setBounds(100+497, 8, 340, 35);
  664. indexPanelA.add(status_menu_2);
  665. JLabel state_label_2 = new JLabel(Config.gw_2);
  666. state_label_2.setHorizontalAlignment(SwingConstants.LEFT);
  667. state_label_2.setForeground(Color.BLACK);
  668. state_label_2.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  669. state_label_2.setBackground(Color.LIGHT_GRAY);
  670. state_label_2.setBounds(497, 10, 150, 28);
  671. indexPanelA.add(state_label_2);
  672. JLabel lblNewLabel_2 = new JLabel("压力");
  673. lblNewLabel_2.setHorizontalAlignment(SwingConstants.RIGHT);
  674. lblNewLabel_2.setFont(new Font("微软雅黑", Font.PLAIN, 25));
  675. lblNewLabel_2.setBounds(530, 160, 96, 53);
  676. indexPanelA.add(lblNewLabel_2);
  677. pressureText_2 = new JTextField();
  678. pressureText_2.setFont(new Font("微软雅黑", Font.PLAIN, 25));
  679. pressureText_2.setEnabled(false);
  680. pressureText_2.setForeground(Color.BLACK);
  681. pressureText_2.setBounds(650, 160, 191, 56);
  682. indexPanelA.add(pressureText_2);
  683. pressureText_2.setColumns(10);
  684. JLabel lblNewLabel_3 = new JLabel("泄漏");
  685. lblNewLabel_3.setHorizontalAlignment(SwingConstants.RIGHT);
  686. lblNewLabel_3.setFont(new Font("微软雅黑", Font.PLAIN, 25));
  687. lblNewLabel_3.setBounds(530, 235, 96, 53);
  688. indexPanelA.add(lblNewLabel_3);
  689. leakText_2 = new JTextField();
  690. leakText_2.setFont(new Font("微软雅黑", Font.PLAIN, 25));
  691. leakText_2.setEnabled(false);
  692. leakText_2.setColumns(10);
  693. leakText_2.setBounds(650, 235, 191, 56);
  694. indexPanelA.add(leakText_2);
  695. JLabel serialportStr2 = new JLabel("串口:");
  696. serialportStr2.setHorizontalAlignment(SwingConstants.LEFT);
  697. serialportStr2.setFont(new Font("微软雅黑", Font.PLAIN, 22));
  698. indexPanelA.add(serialportStr2);
  699. serialportStr2.setBounds(838, 490, 100, 45);
  700. // 下拉框
  701. JComboBox<String> comboBox2 = new JComboBox<>(new String[]{"COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", "COM10", "COM11","COM12","COM13", "COM14", "COM15", "COM16", "COM17", "COM18"});
  702. comboBox2.setPreferredSize(new Dimension(90, 45));
  703. comboBox2.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  704. // 设置初始化选中项
  705. comboBox2.setSelectedItem(Config.portName2);
  706. // 添加监听
  707. comboBox2.addItemListener(new ItemListener() {
  708. @Override
  709. public void itemStateChanged(ItemEvent e) {
  710. String selectedItem = (String) e.getItem();
  711. if (e.getStateChange() == ItemEvent.SELECTED && !Objects.equals(selectedItem, currentSerialPort2)) {
  712. int option = JOptionPane.showConfirmDialog(mesClientFrame, "确定切换串口至" + selectedItem + "?", "切换串口", JOptionPane.OK_CANCEL_OPTION);
  713. if (option == JOptionPane.OK_OPTION) {
  714. // 用户确认切换
  715. log.info("==============用户切换{}串口至 {}===============", Config.gw_2, selectedItem);
  716. currentSerialPort2 = selectedItem;
  717. WorkTimer.ateq2.replaceSerialUtil(new SerialUtil(selectedItem));
  718. resetScanB();
  719. setMenuState_2("切换" + Config.gw_2 + "串口至" + selectedItem + ",请扫码", 0);
  720. log.info("==============切换{}串口成功=====================", Config.gw_2);
  721. } else {
  722. // 用户取消切换,恢复之前的选项
  723. comboBox2.setSelectedItem(currentSerialPort2);
  724. }
  725. }
  726. }
  727. });
  728. comboBox2.setBounds(885, 490, 100, 45);
  729. indexPanelA.add(comboBox2);
  730. Panel panel1 = new Panel();
  731. panel1.setEnabled(false);
  732. panel1.setBackground(SystemColor.activeCaptionBorder);
  733. panel1.setBounds(490, 0, 6, 600);
  734. indexPanelA.add(panel1);
  735. tabbedPane.addTab("工作面板", new ImageIcon(MesClient.class.getResource("/bg/a_side.png")), indexScrollPaneA, null);
  736. tabbedPane.setEnabledAt(0, true);
  737. indexPanelDjA = new JPanel();
  738. searchScrollPaneDjA = new JScrollPane(indexPanelDjA);
  739. indexPanelDjA.setLayout(null);
  740. tabbedPane.addTab(Config.gw_1 + "开班点检", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPaneDjA, null);
  741. indexPanelDjB = new JPanel();
  742. searchScrollPaneDjB = new JScrollPane(indexPanelDjB);
  743. indexPanelDjB.setLayout(null);
  744. tabbedPane.addTab(Config.gw_2 + "开班点检", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPaneDjB, null);
  745. indexPanelB = new JPanel();
  746. searchScrollPane = new JScrollPane(indexPanelB);
  747. indexPanelB.setLayout(null);
  748. //获取配置文件mes.gw_1值
  749. tabbedPane.addTab(Config.gw_1+"记录", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPane, null);
  750. panel5 = new JPanel();
  751. scrollPane5 = new JScrollPane(panel5);
  752. panel5.setLayout(null);
  753. tabbedPane.addTab(Config.gw_2+"记录", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), scrollPane5, null);
  754. panelOkng = new JPanel();
  755. scrollPaneOkng = new JScrollPane(panelOkng);
  756. panelOkng.setLayout(null);
  757. tabbedPane.addTab("OKNG样件", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), scrollPaneOkng, null);
  758. // 员工工作记录
  759. panel4 = new JPanel();
  760. scrollPane4 = new JScrollPane(panel4);
  761. panel4.setLayout(null);
  762. tabbedPane.addTab("人员记录", scrollPane4);
  763. tabbedPane.addChangeListener(new ChangeListener() {
  764. @Override
  765. public void stateChanged(ChangeEvent e) {
  766. JTabbedPane tabbedPane = (JTabbedPane) e.getSource();
  767. int selectedIndex = tabbedPane.getSelectedIndex();
  768. if (selectedIndex == 1) {
  769. }
  770. // 切换 tab 时刷新记录查询(保持与 OP370-AUTO 一致:打开页面自动刷新)
  771. // gw_1记录 tab index: 3, gw_2记录 tab index: 4, OKNG样件 tab index: 5
  772. if (selectedIndex == 3) {
  773. loadRecordData_1();
  774. } else if (selectedIndex == 4) {
  775. loadRecordData_2();
  776. } else if (selectedIndex == 5) {
  777. loadOkngRecordData();
  778. }
  779. }
  780. });
  781. // 初始化两条线的“记录查询”界面
  782. initRecordPanel_1(indexPanelB);
  783. initRecordPanel_2(panel5);
  784. initOkngRecordPanel(panelOkng);
  785. }
  786. private static void initRecordPanel_1(JPanel container) {
  787. // 顶部搜索栏
  788. JPanel top = new JPanel();
  789. top.setBounds(0, 0, 990, 50);
  790. top.setLayout(null);
  791. container.add(top);
  792. recordSearchField_1 = new JTextField();
  793. recordSearchField_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  794. recordSearchField_1.setForeground(Color.BLACK);
  795. recordSearchField_1.setBounds(10, 5, 371, 40);
  796. top.add(recordSearchField_1);
  797. JButton searchBtn = new JButton("搜索");
  798. searchBtn.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  799. searchBtn.setBounds(385, 5, 90, 40);
  800. top.add(searchBtn);
  801. searchBtn.addActionListener(e -> {
  802. recordPageNo_1 = 1;
  803. loadRecordData_1();
  804. });
  805. JButton resetBtn = new JButton("重置");
  806. resetBtn.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  807. resetBtn.setBounds(475, 5, 90, 40);
  808. top.add(resetBtn);
  809. resetBtn.addActionListener(e -> {
  810. recordSearchField_1.setText("");
  811. recordPageNo_1 = 1;
  812. loadRecordData_1();
  813. });
  814. JButton btnPrevious = new JButton("上一页");
  815. btnPrevious.setFont(new Font("微软雅黑", Font.PLAIN, 18));
  816. btnPrevious.setBounds(680, 5, 100, 40);
  817. top.add(btnPrevious);
  818. btnPrevious.addActionListener(e -> {
  819. if (recordPageNo_1 > 1) {
  820. recordPageNo_1--;
  821. loadRecordData_1();
  822. }
  823. });
  824. recordPageLabel_1 = new JLabel("0/0");
  825. recordPageLabel_1.setFont(new Font("微软雅黑", Font.PLAIN, 18));
  826. recordPageLabel_1.setHorizontalAlignment(SwingConstants.CENTER);
  827. recordPageLabel_1.setBorder(BorderFactory.createLineBorder(Color.GRAY, 1));
  828. recordPageLabel_1.setBounds(780, 5, 100, 40);
  829. top.add(recordPageLabel_1);
  830. JButton btnNext = new JButton("下一页");
  831. btnNext.setFont(new Font("微软雅黑", Font.PLAIN, 18));
  832. btnNext.setBounds(880, 5, 100, 40);
  833. top.add(btnNext);
  834. btnNext.addActionListener(e -> {
  835. if (recordPageNo_1 < recordTotalPages_1) {
  836. recordPageNo_1++;
  837. loadRecordData_1();
  838. }
  839. });
  840. // 表格区域
  841. JPanel tablePanel = new JPanel();
  842. tablePanel.setBounds(0, 49, 990, 518);
  843. tablePanel.setLayout(new GridLayout(0, 1, 0, 0));
  844. container.add(tablePanel);
  845. recordTable_1 = new JTable(recordRowData_1, recordColumnNames_1) {
  846. public boolean isCellEditable(int row, int column) {
  847. return false;
  848. }
  849. };
  850. recordTable_1.setRowHeight(40);
  851. recordTable_1.setEnabled(true);
  852. recordTable_1.setFont(new Font("微软雅黑", Font.PLAIN, 14));
  853. javax.swing.table.DefaultTableCellRenderer centerRenderer = new javax.swing.table.DefaultTableCellRenderer();
  854. centerRenderer.setHorizontalAlignment(JLabel.CENTER);
  855. recordTable_1.setDefaultRenderer(Object.class, centerRenderer);
  856. JScrollPane scrollPane = new JScrollPane(recordTable_1);
  857. tablePanel.add(scrollPane);
  858. // 初次加载
  859. loadRecordData_1();
  860. }
  861. private static void initRecordPanel_2(JPanel container) {
  862. JPanel top = new JPanel();
  863. top.setBounds(0, 0, 990, 50);
  864. top.setLayout(null);
  865. container.add(top);
  866. recordSearchField_2 = new JTextField();
  867. recordSearchField_2.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  868. recordSearchField_2.setForeground(Color.BLACK);
  869. recordSearchField_2.setBounds(10, 5, 371, 40);
  870. top.add(recordSearchField_2);
  871. JButton searchBtn = new JButton("搜索");
  872. searchBtn.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  873. searchBtn.setBounds(385, 5, 90, 40);
  874. top.add(searchBtn);
  875. searchBtn.addActionListener(e -> {
  876. recordPageNo_2 = 1;
  877. loadRecordData_2();
  878. });
  879. JButton resetBtn = new JButton("重置");
  880. resetBtn.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  881. resetBtn.setBounds(475, 5, 90, 40);
  882. top.add(resetBtn);
  883. resetBtn.addActionListener(e -> {
  884. recordSearchField_2.setText("");
  885. recordPageNo_2 = 1;
  886. loadRecordData_2();
  887. });
  888. JButton btnPrevious = new JButton("上一页");
  889. btnPrevious.setFont(new Font("微软雅黑", Font.PLAIN, 18));
  890. btnPrevious.setBounds(680, 5, 100, 40);
  891. top.add(btnPrevious);
  892. btnPrevious.addActionListener(e -> {
  893. if (recordPageNo_2 > 1) {
  894. recordPageNo_2--;
  895. loadRecordData_2();
  896. }
  897. });
  898. recordPageLabel_2 = new JLabel("0/0");
  899. recordPageLabel_2.setFont(new Font("微软雅黑", Font.PLAIN, 18));
  900. recordPageLabel_2.setHorizontalAlignment(SwingConstants.CENTER);
  901. recordPageLabel_2.setBorder(BorderFactory.createLineBorder(Color.GRAY, 1));
  902. recordPageLabel_2.setBounds(780, 5, 100, 40);
  903. top.add(recordPageLabel_2);
  904. JButton btnNext = new JButton("下一页");
  905. btnNext.setFont(new Font("微软雅黑", Font.PLAIN, 18));
  906. btnNext.setBounds(880, 5, 100, 40);
  907. top.add(btnNext);
  908. btnNext.addActionListener(e -> {
  909. if (recordPageNo_2 < recordTotalPages_2) {
  910. recordPageNo_2++;
  911. loadRecordData_2();
  912. }
  913. });
  914. JPanel tablePanel = new JPanel();
  915. tablePanel.setBounds(0, 49, 990, 518);
  916. tablePanel.setLayout(new GridLayout(0, 1, 0, 0));
  917. container.add(tablePanel);
  918. recordTable_2 = new JTable(recordRowData_2, recordColumnNames_2) {
  919. public boolean isCellEditable(int row, int column) {
  920. return false;
  921. }
  922. };
  923. recordTable_2.setRowHeight(40);
  924. recordTable_2.setEnabled(true);
  925. recordTable_2.setFont(new Font("微软雅黑", Font.PLAIN, 14));
  926. javax.swing.table.DefaultTableCellRenderer centerRenderer = new javax.swing.table.DefaultTableCellRenderer();
  927. centerRenderer.setHorizontalAlignment(JLabel.CENTER);
  928. recordTable_2.setDefaultRenderer(Object.class, centerRenderer);
  929. JScrollPane scrollPane = new JScrollPane(recordTable_2);
  930. tablePanel.add(scrollPane);
  931. loadRecordData_2();
  932. }
  933. private static void initOkngRecordPanel(JPanel container) {
  934. JPanel top = new JPanel();
  935. top.setBounds(0, 0, 990, 50);
  936. top.setLayout(null);
  937. container.add(top);
  938. recordSearchFieldOkng = new JTextField();
  939. recordSearchFieldOkng.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  940. recordSearchFieldOkng.setForeground(Color.BLACK);
  941. recordSearchFieldOkng.setBounds(10, 5, 371, 40);
  942. top.add(recordSearchFieldOkng);
  943. JButton searchBtn = new JButton("搜索");
  944. searchBtn.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  945. searchBtn.setBounds(385, 5, 90, 40);
  946. top.add(searchBtn);
  947. searchBtn.addActionListener(e -> {
  948. recordPageNoOkng = 1;
  949. loadOkngRecordData();
  950. });
  951. JButton resetBtn = new JButton("重置");
  952. resetBtn.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  953. resetBtn.setBounds(475, 5, 90, 40);
  954. top.add(resetBtn);
  955. resetBtn.addActionListener(e -> {
  956. recordSearchFieldOkng.setText("");
  957. recordPageNoOkng = 1;
  958. loadOkngRecordData();
  959. });
  960. JButton btnPrevious = new JButton("上一页");
  961. btnPrevious.setFont(new Font("微软雅黑", Font.PLAIN, 18));
  962. btnPrevious.setBounds(680, 5, 100, 40);
  963. top.add(btnPrevious);
  964. btnPrevious.addActionListener(e -> {
  965. if (recordPageNoOkng > 1) {
  966. recordPageNoOkng--;
  967. loadOkngRecordData();
  968. }
  969. });
  970. recordPageLabelOkng = new JLabel("0/0");
  971. recordPageLabelOkng.setFont(new Font("微软雅黑", Font.PLAIN, 18));
  972. recordPageLabelOkng.setHorizontalAlignment(SwingConstants.CENTER);
  973. recordPageLabelOkng.setBorder(BorderFactory.createLineBorder(Color.GRAY, 1));
  974. recordPageLabelOkng.setBounds(780, 5, 100, 40);
  975. top.add(recordPageLabelOkng);
  976. JButton btnNext = new JButton("下一页");
  977. btnNext.setFont(new Font("微软雅黑", Font.PLAIN, 18));
  978. btnNext.setBounds(880, 5, 100, 40);
  979. top.add(btnNext);
  980. btnNext.addActionListener(e -> {
  981. if (recordPageNoOkng < recordTotalPagesOkng) {
  982. recordPageNoOkng++;
  983. loadOkngRecordData();
  984. }
  985. });
  986. JPanel tablePanel = new JPanel();
  987. tablePanel.setBounds(0, 49, 990, 518);
  988. tablePanel.setLayout(new GridLayout(0, 1, 0, 0));
  989. container.add(tablePanel);
  990. recordTableOkng = new JTable(recordRowDataOkng, recordColumnNamesOkng) {
  991. public boolean isCellEditable(int row, int column) {
  992. return false;
  993. }
  994. };
  995. recordTableOkng.setRowHeight(40);
  996. recordTableOkng.setEnabled(true);
  997. recordTableOkng.setFont(new Font("微软雅黑", Font.PLAIN, 14));
  998. javax.swing.table.DefaultTableCellRenderer centerRenderer = new javax.swing.table.DefaultTableCellRenderer();
  999. centerRenderer.setHorizontalAlignment(JLabel.CENTER);
  1000. recordTableOkng.setDefaultRenderer(Object.class, centerRenderer);
  1001. JScrollPane scrollPane = new JScrollPane(recordTableOkng);
  1002. tablePanel.add(scrollPane);
  1003. }
  1004. private static boolean refreshOkngSamples() {
  1005. okngSampleSns.clear();
  1006. okngSampleType.clear();
  1007. JSONObject ret = DataUtil.getQmSampleSns(Config.gw_1, Config.line_sn);
  1008. if (ret == null || !"true".equalsIgnoreCase(String.valueOf(ret.get("result")))) {
  1009. return false;
  1010. }
  1011. JSONObject data = ret.getJSONObject("data");
  1012. if (data == null) {
  1013. return true;
  1014. }
  1015. addOkngSamples(data.getString("ok"), "OK件");
  1016. addOkngSamples(data.getString("ng"), "NG件");
  1017. return true;
  1018. }
  1019. private static void addOkngSamples(String sns, String type) {
  1020. if (sns == null || sns.trim().isEmpty()) {
  1021. return;
  1022. }
  1023. for (String sn : sns.split(",", -1)) {
  1024. String code = sn.trim();
  1025. if (code.isEmpty()) {
  1026. continue;
  1027. }
  1028. if (!okngSampleSns.contains(code)) {
  1029. okngSampleSns.add(code);
  1030. }
  1031. String old = okngSampleType.get(code);
  1032. if (old == null) {
  1033. okngSampleType.put(code, type);
  1034. } else if (!old.equals(type) && !old.contains(type)) {
  1035. okngSampleType.put(code, old + "/" + type);
  1036. }
  1037. }
  1038. }
  1039. private static void loadOkngRecordData() {
  1040. clearRecordRowData(recordRowDataOkng);
  1041. boolean loaded = refreshOkngSamples();
  1042. int pageSize = 12;
  1043. String snLike = recordSearchFieldOkng == null ? "" : recordSearchFieldOkng.getText();
  1044. List<String> oprnos = new ArrayList<>();
  1045. oprnos.add(Config.gw_1);
  1046. oprnos.add(Config.gw_2);
  1047. if (!loaded) {
  1048. recordTotalPagesOkng = 0;
  1049. if (recordPageLabelOkng != null) recordPageLabelOkng.setText("失败");
  1050. if (recordTableOkng != null) recordTableOkng.repaint();
  1051. return;
  1052. }
  1053. int totalItems = QMParamsDAO.countByOprnosAndSns(oprnos, okngSampleSns, snLike);
  1054. if (totalItems <= 0) {
  1055. recordTotalPagesOkng = 0;
  1056. if (recordPageLabelOkng != null) recordPageLabelOkng.setText(okngSampleSns.isEmpty() ? "未配置" : "0/0");
  1057. if (recordTableOkng != null) recordTableOkng.repaint();
  1058. return;
  1059. }
  1060. recordTotalPagesOkng = (int) Math.ceil((double) totalItems / (double) pageSize);
  1061. if (recordPageNoOkng > recordTotalPagesOkng) recordPageNoOkng = recordTotalPagesOkng;
  1062. if (recordPageNoOkng < 1) recordPageNoOkng = 1;
  1063. if (recordPageLabelOkng != null) recordPageLabelOkng.setText(recordPageNoOkng + "/" + recordTotalPagesOkng);
  1064. int offset = (recordPageNoOkng - 1) * pageSize;
  1065. List<Map<String, Object>> rows = QMParamsDAO.queryByOprnosAndSns(oprnos, okngSampleSns, snLike, pageSize, offset);
  1066. int rowIndex = 0;
  1067. for (Map<String, Object> r : rows) {
  1068. if (rowIndex >= recordRowDataOkng.length) break;
  1069. String sn = r.get("sn") == null ? "" : String.valueOf(r.get("sn")).trim();
  1070. String recordTime = r.get("record_time") == null ? "" : String.valueOf(r.get("record_time"));
  1071. String pressure = (r.get("pressure_value") == null ? "" : String.valueOf(r.get("pressure_value")))
  1072. + (r.get("pressure_unit") == null ? "" : String.valueOf(r.get("pressure_unit")));
  1073. String leak = (r.get("leak_value") == null ? "" : String.valueOf(r.get("leak_value")))
  1074. + (r.get("leak_unit") == null ? "" : String.valueOf(r.get("leak_unit")));
  1075. String result = r.get("test_result") == null ? "" : String.valueOf(r.get("test_result"));
  1076. String oprno = r.get("oprno") == null ? "" : String.valueOf(r.get("oprno"));
  1077. recordRowDataOkng[rowIndex][0] = oprno;
  1078. recordRowDataOkng[rowIndex][1] = okngSampleType.getOrDefault(sn, "");
  1079. recordRowDataOkng[rowIndex][2] = sn;
  1080. recordRowDataOkng[rowIndex][3] = recordTime;
  1081. recordRowDataOkng[rowIndex][4] = pressure;
  1082. recordRowDataOkng[rowIndex][5] = leak;
  1083. recordRowDataOkng[rowIndex][6] = result;
  1084. rowIndex++;
  1085. }
  1086. if (recordTableOkng != null) recordTableOkng.repaint();
  1087. }
  1088. private static void clearRecordRowData(Object[][] rowData) {
  1089. for (int i = 0; i < rowData.length; i++) {
  1090. for (int j = 0; j < rowData[i].length; j++) {
  1091. rowData[i][j] = null;
  1092. }
  1093. }
  1094. }
  1095. private static void loadRecordData_1() {
  1096. clearRecordRowData(recordRowData_1);
  1097. int pageSize = 12;
  1098. int offset = (recordPageNo_1 - 1) * pageSize;
  1099. String snLike = recordSearchField_1 == null ? "" : recordSearchField_1.getText();
  1100. int totalItems = QMParamsDAO.countByOprnoAndSnLike(Config.gw_1, snLike);
  1101. if (totalItems <= 0) {
  1102. recordTotalPages_1 = 0;
  1103. if (recordPageLabel_1 != null) recordPageLabel_1.setText("0/0");
  1104. if (recordTable_1 != null) recordTable_1.repaint();
  1105. return;
  1106. }
  1107. recordTotalPages_1 = (int) Math.ceil((double) totalItems / (double) pageSize);
  1108. if (recordPageNo_1 > recordTotalPages_1) recordPageNo_1 = recordTotalPages_1;
  1109. if (recordPageLabel_1 != null) recordPageLabel_1.setText(recordPageNo_1 + "/" + recordTotalPages_1);
  1110. java.util.List<java.util.Map<String, Object>> rows = QMParamsDAO.queryByOprnoAndSnLike(Config.gw_1, snLike, pageSize, offset);
  1111. int rowIndex = 0;
  1112. for (java.util.Map<String, Object> r : rows) {
  1113. if (rowIndex >= recordRowData_1.length) break;
  1114. String sn = r.get("sn") == null ? "" : String.valueOf(r.get("sn"));
  1115. String recordTime = r.get("record_time") == null ? "" : String.valueOf(r.get("record_time"));
  1116. String pressure = (r.get("pressure_value") == null ? "" : String.valueOf(r.get("pressure_value")))
  1117. + (r.get("pressure_unit") == null ? "" : String.valueOf(r.get("pressure_unit")));
  1118. String leak = (r.get("leak_value") == null ? "" : String.valueOf(r.get("leak_value")))
  1119. + (r.get("leak_unit") == null ? "" : String.valueOf(r.get("leak_unit")));
  1120. String result = r.get("test_result") == null ? "" : String.valueOf(r.get("test_result"));
  1121. recordRowData_1[rowIndex][0] = sn;
  1122. recordRowData_1[rowIndex][1] = recordTime;
  1123. recordRowData_1[rowIndex][2] = pressure;
  1124. recordRowData_1[rowIndex][3] = leak;
  1125. recordRowData_1[rowIndex][4] = result;
  1126. rowIndex++;
  1127. }
  1128. if (recordTable_1 != null) recordTable_1.repaint();
  1129. }
  1130. private static void loadRecordData_2() {
  1131. clearRecordRowData(recordRowData_2);
  1132. int pageSize = 12;
  1133. int offset = (recordPageNo_2 - 1) * pageSize;
  1134. String snLike = recordSearchField_2 == null ? "" : recordSearchField_2.getText();
  1135. int totalItems = QMParamsDAO.countByOprnoAndSnLike(Config.gw_2, snLike);
  1136. if (totalItems <= 0) {
  1137. recordTotalPages_2 = 0;
  1138. if (recordPageLabel_2 != null) recordPageLabel_2.setText("0/0");
  1139. if (recordTable_2 != null) recordTable_2.repaint();
  1140. return;
  1141. }
  1142. recordTotalPages_2 = (int) Math.ceil((double) totalItems / (double) pageSize);
  1143. if (recordPageNo_2 > recordTotalPages_2) recordPageNo_2 = recordTotalPages_2;
  1144. if (recordPageLabel_2 != null) recordPageLabel_2.setText(recordPageNo_2 + "/" + recordTotalPages_2);
  1145. java.util.List<java.util.Map<String, Object>> rows = QMParamsDAO.queryByOprnoAndSnLike(Config.gw_2, snLike, pageSize, offset);
  1146. int rowIndex = 0;
  1147. for (java.util.Map<String, Object> r : rows) {
  1148. if (rowIndex >= recordRowData_2.length) break;
  1149. String sn = r.get("sn") == null ? "" : String.valueOf(r.get("sn"));
  1150. String recordTime = r.get("record_time") == null ? "" : String.valueOf(r.get("record_time"));
  1151. String pressure = (r.get("pressure_value") == null ? "" : String.valueOf(r.get("pressure_value")))
  1152. + (r.get("pressure_unit") == null ? "" : String.valueOf(r.get("pressure_unit")));
  1153. String leak = (r.get("leak_value") == null ? "" : String.valueOf(r.get("leak_value")))
  1154. + (r.get("leak_unit") == null ? "" : String.valueOf(r.get("leak_unit")));
  1155. String result = r.get("test_result") == null ? "" : String.valueOf(r.get("test_result"));
  1156. recordRowData_2[rowIndex][0] = sn;
  1157. recordRowData_2[rowIndex][1] = recordTime;
  1158. recordRowData_2[rowIndex][2] = pressure;
  1159. recordRowData_2[rowIndex][3] = leak;
  1160. recordRowData_2[rowIndex][4] = result;
  1161. rowIndex++;
  1162. }
  1163. if (recordTable_2 != null) recordTable_2.repaint();
  1164. }
  1165. public static void setMenuState_1(String msg, int error) {
  1166. if (error == 0) {
  1167. MesClient.status_menu_1.setForeground(Color.GREEN);
  1168. } else {
  1169. MesClient.status_menu_1.setForeground(Color.RED);
  1170. }
  1171. MesClient.status_menu_1.setText(msg);
  1172. }
  1173. public static void setMenuState_2(String msg, int error) {
  1174. if (error == 0) {
  1175. MesClient.status_menu_2.setForeground(Color.GREEN);
  1176. } else {
  1177. MesClient.status_menu_2.setForeground(Color.RED);
  1178. }
  1179. MesClient.status_menu_2.setText(msg);
  1180. }
  1181. public static void getMaterailData() {
  1182. JSONObject retObj = DataUtil.getBindMaterail();
  1183. if (retObj.get("result") != null && retObj.get("result").toString().equalsIgnoreCase("true")) {
  1184. java.util.List<BindMaterialResp> arrs = retObj.getList("data", BindMaterialResp.class);
  1185. int i = 0;
  1186. rowData = new Object[arrs.size()][7];
  1187. for (BindMaterialResp bindMaterialResp : arrs) {
  1188. rowData[i][0] = bindMaterialResp.getMaterialTitle();
  1189. rowData[i][1] = bindMaterialResp.getBatchSn();
  1190. rowData[i][2] = bindMaterialResp.getLastTimes();
  1191. rowData[i][3] = "";
  1192. rowData[i][4] = bindMaterialResp.getCraft();
  1193. rowData[i][5] = bindMaterialResp.getMaterialId();
  1194. rowData[i][6] = bindMaterialResp.getType();
  1195. i++;
  1196. }
  1197. bindBatchPanel();
  1198. }
  1199. }
  1200. public static void updateMaterailData() {
  1201. JSONObject retObj = DataUtil.getBindMaterail();
  1202. if (retObj.get("result") != null && retObj.get("result").toString().equalsIgnoreCase("true")) {
  1203. List<BindMaterialResp> arrs = retObj.getList("data", BindMaterialResp.class);
  1204. int i = 0;
  1205. for (BindMaterialResp bindMaterialResp : arrs) {
  1206. rowData[i][0] = bindMaterialResp.getMaterialTitle();
  1207. rowData[i][1] = bindMaterialResp.getBatchSn();
  1208. rowData[i][2] = bindMaterialResp.getLastTimes();
  1209. rowData[i][3] = "";
  1210. rowData[i][4] = bindMaterialResp.getCraft();
  1211. rowData[i][5] = bindMaterialResp.getMaterialId();
  1212. rowData[i][6] = bindMaterialResp.getType();
  1213. i++;
  1214. }
  1215. MesClient.table.repaint();
  1216. }
  1217. }
  1218. // 绑定物料批次码
  1219. public static void scanBatchSn(BindMaterialResp bindMaterialResp) {
  1220. //弹窗扫工件码
  1221. String scanBarcodeTitle = "请扫物料:" + bindMaterialResp.getMaterialTitle();
  1222. String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
  1223. if (scanBarcode != null && !scanBarcode.equalsIgnoreCase("")) {
  1224. JSONObject retObj = DataUtil.saveBindMaterail(scanBarcode, bindMaterialResp.getCraft(), bindMaterialResp.getMaterialId(), bindMaterialResp.getType());
  1225. if (retObj.get("result") != null && retObj.get("result").toString().equalsIgnoreCase("true")) {
  1226. MesClient.setMenuState_1("扫物料:" + bindMaterialResp.getMaterialTitle() + "成功", 0);
  1227. updateMaterailData();
  1228. } else {
  1229. if (retObj.get("result") == null) {
  1230. MesClient.setMenuState_1("请求失败,请重试", -1);
  1231. } else {
  1232. if (retObj.get("result").toString().equalsIgnoreCase("false")) {
  1233. MesClient.setMenuState_1(retObj.getString("message"), -1);
  1234. }
  1235. }
  1236. }
  1237. }
  1238. }
  1239. public static void bindBatchPanel() {
  1240. JPanel indexPanelBB = new JPanel();
  1241. JPanel panel = new JPanel();
  1242. panel.setBounds(0, 0, 990, 550);
  1243. // panel.setBounds(81, 50, 810, 479);
  1244. indexPanelBB.add(panel);
  1245. panel.setLayout(new GridLayout(0, 1, 0, 0));
  1246. table = new JTable(rowData, columnNames) {
  1247. public boolean isCellEditable(int row, int column) {
  1248. if (column == 3) {
  1249. return true;
  1250. }
  1251. return false;
  1252. }
  1253. };
  1254. table.setRowHeight(40);
  1255. table.setEnabled(true);
  1256. table.setFont(new Font("微软雅黑", Font.PLAIN, 14));
  1257. table.getColumnModel().getColumn(3).setCellRenderer(new TableCellRendererButton());
  1258. table.getColumnModel().getColumn(3).setCellEditor(new TableCellEditorButton());
  1259. JScrollPane scrollPane = new JScrollPane(table);
  1260. panel.add(scrollPane);
  1261. JScrollPane indexScrollPaneB = new JScrollPane(indexPanelBB);
  1262. indexPanelBB.setLayout(null);
  1263. tabbedPane.addTab("绑定物料", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), indexScrollPaneB, null);
  1264. }
  1265. public static String scanQrcode1(){
  1266. if(scanFlag1 == 1){
  1267. return "";
  1268. }
  1269. scanFlag1 = 1;
  1270. String sn = "";
  1271. try{
  1272. if (tcpClient1.socket == null || !tcpClient1.socket.isConnected() || tcpClient1.socket.isClosed()) {
  1273. tcpClient1.connect();
  1274. }
  1275. log.error("扫码枪1正在进行扫码,请勿操作",0);
  1276. sn = tcpClient1.receiveResponse();
  1277. if (sn == null || sn.equals("")) {
  1278. sn = "";
  1279. }
  1280. tcpClient1.close();
  1281. }catch (Exception e) {
  1282. e.printStackTrace();
  1283. log.error("scanQrcode1:"+sn);
  1284. tcpClient1.close();
  1285. }
  1286. MesClient.setMenuState_1(sn,0);
  1287. scanFlag1 = 0;
  1288. return sn;
  1289. }
  1290. public static String scanQrcode2(){
  1291. if(scanFlag2 == 1){
  1292. return "";
  1293. }
  1294. scanFlag2 = 1;
  1295. String sn = "";
  1296. try{
  1297. if (tcpClient2.socket == null || !tcpClient2.socket.isConnected() || tcpClient2.socket.isClosed()) {
  1298. tcpClient2.connect();
  1299. }
  1300. log.error("扫码枪2正在进行扫码,请勿操作",0);
  1301. sn = tcpClient2.receiveResponse();
  1302. if (sn == null || sn.equals("")) {
  1303. sn = "";
  1304. }
  1305. tcpClient2.close();
  1306. }catch (Exception e) {
  1307. e.printStackTrace();
  1308. log.error("scanQrcode2:"+sn);
  1309. tcpClient2.close();
  1310. }
  1311. MesClient.setMenuState_2(sn,0);
  1312. scanFlag2 = 0;
  1313. return sn;
  1314. }
  1315. }