MesClient.java 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941
  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 Boolean check_quality_result2 = false;
  36. public static Integer work_status2 = 0;
  37. public static JButton finish_ok_bt_1;
  38. public static JButton finish_ng_bt_1;
  39. public static JTextField product_sn_1;
  40. public static JButton f_scan_data_bt_1;
  41. public static JButton status_menu_1;
  42. public static JTextField pressureText_1; // 压力值显示文本框
  43. public static JTextField leakText_1; // 压力值显示文本框
  44. public static JButton finish_ok_bt_2;
  45. public static JButton finish_ng_bt_2;
  46. public static JTextField product_sn_2;
  47. public static JButton f_scan_data_bt_2;
  48. public static JButton status_menu_2;
  49. public static JTextField pressureText_2; // 压力值显示文本框
  50. public static JTextField leakText_2; // 压力值显示文本框
  51. public static JPanel contentPane;
  52. public static MesClient mesClientFrame;
  53. public static JTabbedPane tabbedPane;
  54. public static JScrollPane indexScrollPaneA;
  55. public static JScrollPane searchScrollPane;
  56. public static JScrollPane searchScrollPaneDj;
  57. public static JPanel panel4;
  58. public static JScrollPane scrollPane4;
  59. public static JPanel panel5;
  60. public static JScrollPane scrollPane5;
  61. public static JButton heart_beat_menu;
  62. public static JButton user_menu;
  63. public static JFrame welcomeWin;
  64. public static JPanel indexPanelB;
  65. public static MesWebView jfxPanel = null;
  66. public static JPanel indexPanelC;
  67. public static MesWebView jfxPanel2 = null;
  68. public static MesRadio mesRadioHj;
  69. public static JTable table;
  70. public static Object[] columnNames = {"物料名称", "绑定批次", "剩余次数", "操作"};
  71. public static Object[][] rowData = null;
  72. String currentSerialPort1 = Config.portName1;
  73. String currentSerialPort2 = Config.portName2;
  74. public static void main(String[] args) {
  75. EventQueue.invokeLater(new Runnable() {
  76. @Override
  77. public void run() {
  78. try {
  79. // 显示界面
  80. mesClientFrame = new MesClient();
  81. mesClientFrame.setVisible(false);
  82. JdbcUtils.getConn();
  83. welcomeWin = new LoginFrame();
  84. welcomeWin.setVisible(true);
  85. } catch (Exception e) {
  86. log.error(e.getMessage());
  87. }
  88. }
  89. });
  90. }
  91. // 初始化TCP
  92. public static void initTcpConnection() {
  93. try {
  94. if (nettyClient == null) {
  95. nettyClient = new NettyClient();
  96. tcp_connect_flag = false; //设置TCP连接状态
  97. DataUtil.synrTcp(nettyClient, Config.gw_1);
  98. }
  99. } catch (Exception e) {
  100. log.error("初始化TCP失败", e);
  101. }
  102. }
  103. //启动心跳包程序
  104. public static java.util.Timer heartBeatTimer;
  105. public static java.util.Timer heartBeatIconTimer;
  106. public static boolean iconREDFlag = true;
  107. public static void startHeartBeatTimer() {
  108. if (heartBeatTimer != null) {
  109. heartBeatTimer.cancel();
  110. }
  111. heartBeatTimer = new java.util.Timer();
  112. heartBeatTimer.schedule(new TimerTask() {
  113. public void run() {
  114. if (nettyClient != null && tcp_connect_flag) {
  115. DataUtil.heartBeat(nettyClient, Config.gw_1);
  116. heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
  117. }
  118. }
  119. }, 100, Config.heart_beat_cycle * 1000);
  120. //心跳显示图标
  121. if (heartBeatIconTimer != null) {
  122. heartBeatIconTimer.cancel();
  123. }
  124. heartBeatIconTimer = new Timer();
  125. heartBeatIconTimer.schedule(new TimerTask() {
  126. public void run() {
  127. if (tcp_connect_flag) {
  128. if (iconREDFlag) {
  129. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  130. iconREDFlag = false;
  131. } else {
  132. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
  133. iconREDFlag = true;
  134. }
  135. heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
  136. heart_beat_menu.setForeground(Color.GREEN);
  137. heart_beat_menu.repaint();
  138. } else {
  139. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  140. heart_beat_menu.setText("Mes连接断开");
  141. heart_beat_menu.setForeground(Color.RED);
  142. heart_beat_menu.repaint();
  143. //若未连接则尝试连接
  144. if (nettyClient != null) {
  145. //TCP重新同步连接
  146. if (allow_connect_again) {
  147. log.info("TCP连接已断开, 在心跳循环中, 发送同步连接请求");
  148. allow_connect_again = false; // 只允许重新同步连接一次
  149. DataUtil.synrTcp(nettyClient, Config.gw_1);
  150. }
  151. }
  152. }
  153. }
  154. }, 100, Config.heart_icon_cycle * 1000);
  155. }
  156. public static void initWarehouseData() {
  157. resetScanA();
  158. resetScanB();
  159. }
  160. public static void resetScanA() {
  161. MesClient.finish_ok_bt_1.setEnabled(false);
  162. MesClient.finish_ng_bt_1.setEnabled(false);
  163. MesClient.f_scan_data_bt_1.setEnabled(true);
  164. // product_sn_1.setText("");
  165. // leakText_1.setText("");
  166. // pressureText_1.setText("");
  167. // MesClient.setMenuState_1("请扫工件码", 0);
  168. // WorkTimer.ateq1.resetFIFO();
  169. work_status1 = 0;
  170. check_quality_result1 = false;
  171. }
  172. public static void resetScanB() {
  173. MesClient.finish_ok_bt_2.setEnabled(false);
  174. MesClient.finish_ng_bt_2.setEnabled(false);
  175. MesClient.f_scan_data_bt_2.setEnabled(true);
  176. // product_sn_2.setText("");
  177. // leakText_2.setText("");
  178. // pressureText_2.setText("");
  179. // MesClient.setMenuState_2("请扫工件码", 0);
  180. // WorkTimer.ateq2.resetFIFO();
  181. work_status2 = 0;
  182. check_quality_result2 = false;
  183. }
  184. public static int userLoginHours;//用户登录所处小时
  185. //换班用户信息检查
  186. private static void shiftUserCheck() {
  187. LocalDateTime now = LocalDateTime.now();
  188. // 判断时间范围
  189. if (userLoginHours >= 8 && userLoginHours < 20) {
  190. int hour = now.getHour();
  191. if (hour >= 20 || hour < 8) {
  192. logoff();
  193. }
  194. } else {
  195. int hour = now.getHour();
  196. if (hour >= 8 && hour < 20) {
  197. logoff();
  198. }
  199. }
  200. }
  201. //获取用户20位
  202. public static void getUser() {
  203. user20 = user_menu.getText();
  204. String space_tmp1 = "";
  205. if (user20.length() < 20) {
  206. for (int i = 0; i < 20 - user20.length(); i++) {
  207. space_tmp1 = space_tmp1 + " ";
  208. }
  209. }
  210. user20 = user20 + space_tmp1;
  211. }
  212. //获取barcode内容36位
  213. public static String getBarcode(String barcodeTmp) {
  214. String barcodeRet = barcodeTmp;
  215. if (barcodeTmp.equalsIgnoreCase("")) {
  216. return "";
  217. } else {
  218. if (barcodeTmp.length() < 36) {
  219. String space = "";
  220. for (int i = 0; i < 36 - barcodeTmp.length(); i++) {
  221. space = space + " ";
  222. }
  223. barcodeRet = barcodeTmp + space;
  224. }
  225. }
  226. return barcodeRet;
  227. }
  228. public static String getBarcode33(String barcodeTmp) {
  229. String barcodeRet = barcodeTmp;
  230. if (barcodeTmp.equalsIgnoreCase("")) {
  231. return "";
  232. } else {
  233. if (barcodeTmp.length() < 33) {
  234. String space = "";
  235. for (int i = 0; i < 33 - barcodeTmp.length(); i++) {
  236. space = space + " ";
  237. }
  238. barcodeRet = barcodeTmp + space;
  239. }
  240. }
  241. return barcodeRet;
  242. }
  243. public static void scanBarcode1() {
  244. if (work_status1 == 1) {
  245. JOptionPane.showMessageDialog(mesClientFrame, "工作中,勿扫码", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
  246. return;
  247. }
  248. WorkTimer.ateq1.resetFIFO();
  249. product_sn_1.setText("");
  250. leakText_1.setText("");
  251. pressureText_1.setText("");
  252. MesClient.setMenuState_1("请扫工件码", 0);
  253. //弹窗扫工件码
  254. String scanBarcode = JOptionPane.showInputDialog(null, "请扫工件码");
  255. if (scanBarcode != null && !scanBarcode.equalsIgnoreCase("")) {
  256. product_sn_1.setText(scanBarcode);
  257. //刷新界面
  258. mesClientFrame.repaint();
  259. if (!tcp_connect_flag) {
  260. JOptionPane.showMessageDialog(mesClientFrame, "设备未连接Mes服务器", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
  261. return;
  262. }
  263. // 查询工件质量
  264. Boolean sendret = DataUtil.checkQuality(nettyClient, scanBarcode.trim(), user20, Config.gw_1);
  265. if (!sendret) {
  266. JOptionPane.showMessageDialog(mesClientFrame, "消息发送失败,请重试", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
  267. }
  268. } else {
  269. JOptionPane.showMessageDialog(mesClientFrame, "请扫工件码", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
  270. }
  271. }
  272. public static void scanBarcode2() {
  273. if (work_status2 == 1) {
  274. JOptionPane.showMessageDialog(mesClientFrame, "工作中,勿扫码", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
  275. return;
  276. }
  277. WorkTimer.ateq2.resetFIFO();
  278. product_sn_2.setText("");
  279. leakText_2.setText("");
  280. pressureText_2.setText("");
  281. MesClient.setMenuState_2("请扫工件码", 0);
  282. //弹窗扫工件码
  283. String scanBarcode = JOptionPane.showInputDialog(null, "请扫工件码");
  284. if (scanBarcode != null && !scanBarcode.equalsIgnoreCase("")) {
  285. product_sn_2.setText(scanBarcode);
  286. //刷新界面
  287. mesClientFrame.repaint();
  288. if (!tcp_connect_flag) {
  289. JOptionPane.showMessageDialog(mesClientFrame, "设备未连接Mes服务器", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
  290. return;
  291. }
  292. // 查询工件质量
  293. Boolean sendret = DataUtil.checkQuality(nettyClient, scanBarcode.trim(), user20, Config.gw_2);
  294. if (!sendret) {
  295. JOptionPane.showMessageDialog(mesClientFrame, "消息发送失败,请重试", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
  296. }
  297. } else {
  298. JOptionPane.showMessageDialog(mesClientFrame, "请扫工件码", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
  299. }
  300. }
  301. public static void logoff() {
  302. mesClientFrame.setVisible(false);
  303. welcomeWin.setVisible(true);
  304. nettyClient = null;
  305. tcp_connect_flag = false;
  306. allow_connect_again = false;
  307. mes_auth = 0;
  308. UpdateQualityTimer.stop(); // 停止更新质量的定时任务
  309. WorkTimer.stop();
  310. }
  311. private static void createQRCode(String s) {
  312. log.info("准备生成二维码");
  313. if(s == null || s.isEmpty()){
  314. log.info("生成二维码失败: 工件码为空");
  315. return;
  316. }
  317. s = s.trim();
  318. try {
  319. BitMatrix bitMatrix = new QRCodeWriter().encode(s, BarcodeFormat.QR_CODE, 200, 200);
  320. BufferedImage qrImage = MatrixToImageWriter.toBufferedImage(bitMatrix);
  321. JDialog qrDialog = new JDialog(mesClientFrame, "", Dialog.ModalityType.APPLICATION_MODAL);
  322. qrDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
  323. qrDialog.setSize(250, 250);
  324. qrDialog.setLocationRelativeTo(mesClientFrame);
  325. qrDialog.setResizable(false);
  326. JLabel qrLabel = new JLabel(new ImageIcon(qrImage));
  327. qrDialog.getContentPane().add(qrLabel, BorderLayout.CENTER);
  328. qrDialog.setVisible(true);
  329. } catch (Exception e) {
  330. log.error("生成二维码失败", e);
  331. }
  332. }
  333. public MesClient() {
  334. setIconImage(Toolkit.getDefaultToolkit().getImage(MesClient.class.getResource("/bg/logo.png")));
  335. setTitle("MES系统客户端:OP310B/OP320 " + Config.gw_des_1);
  336. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  337. setBounds(0, 0, 1024, 768);
  338. JMenuBar menuBar = new JMenuBar();
  339. menuBar.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 26));
  340. setJMenuBar(menuBar);
  341. JMenu fileMenu = new JMenu("用户");
  342. fileMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/user.png")));
  343. fileMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  344. menuBar.add(fileMenu);
  345. JMenuItem exitMenuItem = new JMenuItem("退出");
  346. exitMenuItem.setIcon(new ImageIcon(MesClient.class.getResource("/bg/logoff.png")));
  347. exitMenuItem.setFont(new Font("微软雅黑", Font.PLAIN, 22));
  348. fileMenu.add(exitMenuItem);
  349. exitMenuItem.addMouseListener(new MouseAdapter() {
  350. @Override
  351. public void mousePressed(MouseEvent e) {//只能检测到mousePressed事件
  352. super.mouseClicked(e);
  353. logoff();
  354. }
  355. });
  356. JMenu settingMenu = new JMenu("设置");
  357. //settingMenu.setVisible(false);
  358. settingMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")));
  359. settingMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  360. menuBar.add(settingMenu);
  361. JMenuItem resetTcpMenu = new JMenuItem("重连MES");
  362. resetTcpMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  363. resetTcpMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  364. resetTcpMenu.addMouseListener(new MouseAdapter() {
  365. @Override
  366. public void mousePressed(MouseEvent e) {
  367. super.mouseClicked(e);
  368. //重连mes
  369. nettyClient.future.channel().close();
  370. }
  371. });
  372. settingMenu.add(resetTcpMenu);
  373. JMenuItem resetTcpMenu_1 = new JMenuItem("刷新" + Config.gw_1);
  374. resetTcpMenu_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  375. resetTcpMenu_1.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  376. resetTcpMenu_1.addMouseListener(new MouseAdapter() {
  377. @Override
  378. public void mousePressed(MouseEvent e) {
  379. super.mouseClicked(e);
  380. setMenuState_1("已手动刷新,请扫码", 0);
  381. resetScanA();
  382. }
  383. });
  384. settingMenu.add(resetTcpMenu_1);
  385. JMenuItem resetTcpMenu_2 = new JMenuItem("刷新" + Config.gw_2);
  386. resetTcpMenu_2.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  387. resetTcpMenu_2.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  388. resetTcpMenu_2.addMouseListener(new MouseAdapter() {
  389. @Override
  390. public void mousePressed(MouseEvent e) {
  391. super.mouseClicked(e);
  392. setMenuState_2("已手动刷新,请扫码", 0);
  393. resetScanB();
  394. }
  395. });
  396. settingMenu.add(resetTcpMenu_2);
  397. contentPane = new JPanel();
  398. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  399. setContentPane(contentPane);
  400. contentPane.setLayout(new BorderLayout(0, 0));
  401. JToolBar toolBar = new JToolBar();
  402. contentPane.add(toolBar, BorderLayout.NORTH);
  403. JLabel equipment_statu_label = new JLabel("状态:");
  404. equipment_statu_label.setHorizontalAlignment(SwingConstants.CENTER);
  405. equipment_statu_label.setForeground(Color.BLACK);
  406. equipment_statu_label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  407. equipment_statu_label.setBackground(Color.LIGHT_GRAY);
  408. toolBar.add(equipment_statu_label);
  409. JButton status_menu = new JButton("");
  410. status_menu.addActionListener(new ActionListener() {
  411. public void actionPerformed(ActionEvent e) {
  412. }
  413. });
  414. status_menu.setForeground(Color.GREEN);
  415. status_menu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  416. status_menu.setBackground(Color.BLACK);
  417. toolBar.add(status_menu);
  418. JLabel space_1 = new JLabel(" ");
  419. toolBar.add(space_1);
  420. JLabel heart_beat_status_label = new JLabel("心跳:");
  421. heart_beat_status_label.setHorizontalAlignment(SwingConstants.CENTER);
  422. heart_beat_status_label.setForeground(Color.BLACK);
  423. heart_beat_status_label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  424. heart_beat_status_label.setBackground(Color.LIGHT_GRAY);
  425. toolBar.add(heart_beat_status_label);
  426. heart_beat_menu = new JButton("");
  427. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
  428. heart_beat_menu.setForeground(Color.GREEN);
  429. heart_beat_menu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  430. heart_beat_menu.setBackground(Color.BLACK);
  431. toolBar.add(heart_beat_menu);
  432. JLabel space_2 = new JLabel(" ");
  433. toolBar.add(space_2);
  434. JLabel user_status_label = new JLabel("登录用户:");
  435. user_status_label.setHorizontalAlignment(SwingConstants.CENTER);
  436. user_status_label.setForeground(Color.BLACK);
  437. user_status_label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  438. user_status_label.setBackground(Color.LIGHT_GRAY);
  439. toolBar.add(user_status_label);
  440. user_menu = new JButton("");
  441. user_menu.setForeground(Color.GREEN);
  442. user_menu.setFont(new Font("微软雅黑", Font.PLAIN, 22));
  443. user_menu.setBackground(Color.BLACK);
  444. toolBar.add(user_menu);
  445. JLabel space_3 = new JLabel(" ");
  446. toolBar.add(space_3);
  447. JLabel space_4 = new JLabel(" ");
  448. toolBar.add(space_4);
  449. tabbedPane = new JTabbedPane(JTabbedPane.TOP);
  450. tabbedPane.setMinimumSize(new Dimension(400, 50));
  451. tabbedPane.setFont(new Font("宋体", Font.BOLD, 22));
  452. contentPane.add(tabbedPane);
  453. //首页
  454. JPanel indexPanelA = new JPanel();
  455. indexScrollPaneA = new JScrollPane(indexPanelA);
  456. indexPanelA.setLayout(null);
  457. // 工位1
  458. product_sn_1 = new JTextField();
  459. product_sn_1.setHorizontalAlignment(SwingConstants.CENTER);
  460. product_sn_1.setEditable(false);
  461. product_sn_1.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  462. product_sn_1.setBounds(0, 60, 489, 70);
  463. indexPanelA.add(product_sn_1);
  464. product_sn_1.setColumns(10);
  465. product_sn_1.addMouseListener(new MouseAdapter() {
  466. public void mouseClicked(MouseEvent e) {
  467. createQRCode(product_sn_1.getText());
  468. }
  469. });
  470. f_scan_data_bt_1 = new JButton("扫码");
  471. f_scan_data_bt_1.addActionListener(new ActionListener() {
  472. public void actionPerformed(ActionEvent e) { scanBarcode1();}
  473. });
  474. f_scan_data_bt_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/scan_barcode.png")));
  475. f_scan_data_bt_1.setFont(new Font("微软雅黑", Font.PLAIN, 32));
  476. f_scan_data_bt_1.setBounds(280, 340, 171, 70);
  477. indexPanelA.add(f_scan_data_bt_1);
  478. finish_ok_bt_1 = new JButton("OK");
  479. finish_ok_bt_1.setEnabled(false);
  480. finish_ok_bt_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
  481. finish_ok_bt_1.setFont(new Font("微软雅黑", Font.PLAIN, 32));
  482. finish_ok_bt_1.setBounds(0, 335, 125, 80);
  483. finish_ok_bt_1.setEnabled(false);
  484. indexPanelA.add(finish_ok_bt_1);
  485. finish_ng_bt_1 = new JButton("NG");
  486. finish_ng_bt_1.setEnabled(false);
  487. finish_ng_bt_1.addActionListener(new ActionListener() {
  488. public void actionPerformed(ActionEvent e) {}
  489. });
  490. finish_ng_bt_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ng_bg.png")));
  491. finish_ng_bt_1.setFont(new Font("微软雅黑", Font.PLAIN, 32));
  492. finish_ng_bt_1.setBounds(128, 335, 125, 80);
  493. finish_ng_bt_1.setEnabled(false);
  494. indexPanelA.add(finish_ng_bt_1);
  495. status_menu_1 = new JButton("等待加工信号");
  496. status_menu_1.addActionListener(new ActionListener() {
  497. public void actionPerformed(ActionEvent e) {}
  498. });
  499. status_menu_1.setForeground(Color.GREEN);
  500. status_menu_1.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  501. status_menu_1.setBackground(Color.BLACK);
  502. status_menu_1.setBounds(100, 8, 340, 35);
  503. indexPanelA.add(status_menu_1);
  504. JLabel state_label_1 = new JLabel(Config.gw_1);
  505. state_label_1.setHorizontalAlignment(SwingConstants.LEFT);
  506. state_label_1.setForeground(Color.BLACK);
  507. state_label_1.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  508. state_label_1.setBackground(Color.LIGHT_GRAY);
  509. state_label_1.setBounds(0, 10, 150, 28);
  510. indexPanelA.add(state_label_1);
  511. JLabel lblNewLabel = new JLabel("压力");
  512. lblNewLabel.setHorizontalAlignment(SwingConstants.RIGHT);
  513. lblNewLabel.setFont(new Font("微软雅黑", Font.PLAIN, 25));
  514. lblNewLabel.setBounds(30, 160, 96, 53);
  515. indexPanelA.add(lblNewLabel);
  516. pressureText_1 = new JTextField();
  517. pressureText_1.setFont(new Font("微软雅黑", Font.PLAIN, 25));
  518. pressureText_1.setEnabled(false);
  519. pressureText_1.setForeground(Color.BLACK);
  520. pressureText_1.setBounds(150, 160, 191, 56);
  521. indexPanelA.add(pressureText_1);
  522. pressureText_1.setColumns(10);
  523. JLabel lblNewLabel_1 = new JLabel("泄漏");
  524. lblNewLabel_1.setHorizontalAlignment(SwingConstants.RIGHT);
  525. lblNewLabel_1.setFont(new Font("微软雅黑", Font.PLAIN, 25));
  526. lblNewLabel_1.setBounds(30, 235, 96, 53);
  527. indexPanelA.add(lblNewLabel_1);
  528. leakText_1 = new JTextField();
  529. leakText_1.setFont(new Font("微软雅黑", Font.PLAIN, 25));
  530. leakText_1.setEnabled(false);
  531. leakText_1.setColumns(10);
  532. leakText_1.setBounds(150, 235, 191, 56);
  533. indexPanelA.add(leakText_1);
  534. JLabel serialportStr1 = new JLabel("串口:");
  535. serialportStr1.setHorizontalAlignment(SwingConstants.LEFT);
  536. serialportStr1.setFont(new Font("微软雅黑", Font.PLAIN, 22));
  537. indexPanelA.add(serialportStr1);
  538. serialportStr1.setBounds(338, 490, 100, 45);
  539. // 下拉框
  540. JComboBox<String> comboBox1 = new JComboBox<>(new String[]{"COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", "COM10", "COM11","COM12", "COM13", "COM14", "COM15", "COM16", "COM17", "COM18"});
  541. comboBox1.setPreferredSize(new Dimension(90, 45));
  542. comboBox1.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  543. // 设置初始化选中项
  544. comboBox1.setSelectedItem(Config.portName1);
  545. // 添加监听
  546. comboBox1.addItemListener(new ItemListener() {
  547. @Override
  548. public void itemStateChanged(ItemEvent e) {
  549. String selectedItem = (String) e.getItem();
  550. if (e.getStateChange() == ItemEvent.SELECTED && !Objects.equals(selectedItem, currentSerialPort1)) {
  551. int option = JOptionPane.showConfirmDialog(mesClientFrame, "确定切换串口至" + selectedItem + "?", "切换串口", JOptionPane.OK_CANCEL_OPTION);
  552. if (option == JOptionPane.OK_OPTION) {
  553. // 用户确认切换
  554. log.info("============用户切换{}串口至 {}==============", Config.gw_1, selectedItem);
  555. currentSerialPort1 = selectedItem;
  556. WorkTimer.ateq1.replaceSerialUtil(new SerialUtil(selectedItem));
  557. resetScanA();
  558. setMenuState_1("切换" + Config.gw_1 + "串口至" + selectedItem + ",请扫码", 0);
  559. log.info("=============切换{}串口成功===================", Config.gw_1);
  560. } else {
  561. // 用户取消切换,恢复之前的选项
  562. comboBox1.setSelectedItem(currentSerialPort1);
  563. }
  564. }
  565. }
  566. });
  567. comboBox1.setBounds(385, 490, 100, 45);
  568. indexPanelA.add(comboBox1);
  569. // 工位2
  570. product_sn_2 = new JTextField();
  571. product_sn_2.setHorizontalAlignment(SwingConstants.CENTER);
  572. product_sn_2.setEditable(false);
  573. product_sn_2.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  574. product_sn_2.setBounds(497, 60, 489, 70);
  575. indexPanelA.add(product_sn_2);
  576. product_sn_2.setColumns(10);
  577. product_sn_2.addMouseListener(new MouseAdapter() {
  578. public void mouseClicked(MouseEvent e) {
  579. createQRCode(product_sn_2.getText());
  580. }
  581. });
  582. f_scan_data_bt_2 = new JButton("扫码");
  583. f_scan_data_bt_2.addActionListener(new ActionListener() {
  584. public void actionPerformed(ActionEvent e) { scanBarcode2();}
  585. });
  586. f_scan_data_bt_2.setIcon(new ImageIcon(MesClient.class.getResource("/bg/scan_barcode.png")));
  587. f_scan_data_bt_2.setFont(new Font("微软雅黑", Font.PLAIN, 32));
  588. f_scan_data_bt_2.setBounds(280+497, 340, 171, 70);
  589. indexPanelA.add(f_scan_data_bt_2);
  590. finish_ok_bt_2 = new JButton("OK");
  591. finish_ok_bt_2.setEnabled(false);
  592. finish_ok_bt_2.addActionListener(new ActionListener() {
  593. public void actionPerformed(ActionEvent e) {}
  594. });
  595. finish_ok_bt_2.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
  596. finish_ok_bt_2.setFont(new Font("微软雅黑", Font.PLAIN, 32));
  597. finish_ok_bt_2.setBounds(497, 335, 125, 80);
  598. finish_ok_bt_2.setEnabled(false);
  599. indexPanelA.add(finish_ok_bt_2);
  600. finish_ng_bt_2 = new JButton("NG");
  601. finish_ng_bt_2.setEnabled(false);
  602. finish_ng_bt_2.addActionListener(new ActionListener() {
  603. public void actionPerformed(ActionEvent e) {}
  604. });
  605. finish_ng_bt_2.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ng_bg.png")));
  606. finish_ng_bt_2.setFont(new Font("微软雅黑", Font.PLAIN, 32));
  607. finish_ng_bt_2.setBounds(128 + 497, 335, 125, 80);
  608. finish_ng_bt_2.setEnabled(false);
  609. indexPanelA.add(finish_ng_bt_2);
  610. status_menu_2 = new JButton("等待加工信号");
  611. status_menu_2.addActionListener(new ActionListener() {
  612. public void actionPerformed(ActionEvent e) {
  613. }
  614. });
  615. status_menu_2.setForeground(Color.GREEN);
  616. status_menu_2.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  617. status_menu_2.setBackground(Color.BLACK);
  618. status_menu_2.setBounds(100+497, 8, 340, 35);
  619. indexPanelA.add(status_menu_2);
  620. JLabel state_label_2 = new JLabel(Config.gw_2);
  621. state_label_2.setHorizontalAlignment(SwingConstants.LEFT);
  622. state_label_2.setForeground(Color.BLACK);
  623. state_label_2.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  624. state_label_2.setBackground(Color.LIGHT_GRAY);
  625. state_label_2.setBounds(497, 10, 150, 28);
  626. indexPanelA.add(state_label_2);
  627. JLabel lblNewLabel_2 = new JLabel("压力");
  628. lblNewLabel_2.setHorizontalAlignment(SwingConstants.RIGHT);
  629. lblNewLabel_2.setFont(new Font("微软雅黑", Font.PLAIN, 25));
  630. lblNewLabel_2.setBounds(530, 160, 96, 53);
  631. indexPanelA.add(lblNewLabel_2);
  632. pressureText_2 = new JTextField();
  633. pressureText_2.setFont(new Font("微软雅黑", Font.PLAIN, 25));
  634. pressureText_2.setEnabled(false);
  635. pressureText_2.setForeground(Color.BLACK);
  636. pressureText_2.setBounds(650, 160, 191, 56);
  637. indexPanelA.add(pressureText_2);
  638. pressureText_2.setColumns(10);
  639. JLabel lblNewLabel_3 = new JLabel("泄漏");
  640. lblNewLabel_3.setHorizontalAlignment(SwingConstants.RIGHT);
  641. lblNewLabel_3.setFont(new Font("微软雅黑", Font.PLAIN, 25));
  642. lblNewLabel_3.setBounds(530, 235, 96, 53);
  643. indexPanelA.add(lblNewLabel_3);
  644. leakText_2 = new JTextField();
  645. leakText_2.setFont(new Font("微软雅黑", Font.PLAIN, 25));
  646. leakText_2.setEnabled(false);
  647. leakText_2.setColumns(10);
  648. leakText_2.setBounds(650, 235, 191, 56);
  649. indexPanelA.add(leakText_2);
  650. JLabel serialportStr2 = new JLabel("串口:");
  651. serialportStr2.setHorizontalAlignment(SwingConstants.LEFT);
  652. serialportStr2.setFont(new Font("微软雅黑", Font.PLAIN, 22));
  653. indexPanelA.add(serialportStr2);
  654. serialportStr2.setBounds(838, 490, 100, 45);
  655. // 下拉框
  656. JComboBox<String> comboBox2 = new JComboBox<>(new String[]{"COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", "COM10", "COM11","COM12","COM13", "COM14", "COM15", "COM16", "COM17", "COM18"});
  657. comboBox2.setPreferredSize(new Dimension(90, 45));
  658. comboBox2.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  659. // 设置初始化选中项
  660. comboBox2.setSelectedItem(Config.portName2);
  661. // 添加监听
  662. comboBox2.addItemListener(new ItemListener() {
  663. @Override
  664. public void itemStateChanged(ItemEvent e) {
  665. String selectedItem = (String) e.getItem();
  666. if (e.getStateChange() == ItemEvent.SELECTED && !Objects.equals(selectedItem, currentSerialPort2)) {
  667. int option = JOptionPane.showConfirmDialog(mesClientFrame, "确定切换串口至" + selectedItem + "?", "切换串口", JOptionPane.OK_CANCEL_OPTION);
  668. if (option == JOptionPane.OK_OPTION) {
  669. // 用户确认切换
  670. log.info("==============用户切换{}串口至 {}===============", Config.gw_2, selectedItem);
  671. currentSerialPort2 = selectedItem;
  672. WorkTimer.ateq2.replaceSerialUtil(new SerialUtil(selectedItem));
  673. resetScanB();
  674. setMenuState_2("切换" + Config.gw_2 + "串口至" + selectedItem + ",请扫码", 0);
  675. log.info("==============切换{}串口成功=====================", Config.gw_2);
  676. } else {
  677. // 用户取消切换,恢复之前的选项
  678. comboBox2.setSelectedItem(currentSerialPort2);
  679. }
  680. }
  681. }
  682. });
  683. comboBox2.setBounds(885, 490, 100, 45);
  684. indexPanelA.add(comboBox2);
  685. Panel panel1 = new Panel();
  686. panel1.setEnabled(false);
  687. panel1.setBackground(SystemColor.activeCaptionBorder);
  688. panel1.setBounds(490, 0, 6, 600);
  689. indexPanelA.add(panel1);
  690. tabbedPane.addTab("工作面板", new ImageIcon(MesClient.class.getResource("/bg/a_side.png")), indexScrollPaneA, null);
  691. tabbedPane.setEnabledAt(0, true);
  692. indexPanelC = new JPanel();
  693. searchScrollPaneDj = new JScrollPane(indexPanelC);
  694. indexPanelC.setLayout(null);
  695. tabbedPane.addTab("开班点检", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPaneDj, null);
  696. indexPanelB = new JPanel();
  697. searchScrollPane = new JScrollPane(indexPanelB);
  698. indexPanelB.setLayout(null);
  699. tabbedPane.addTab("OP310B记录", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPane, null);
  700. panel5 = new JPanel();
  701. scrollPane5 = new JScrollPane(panel5);
  702. panel5.setLayout(null);
  703. tabbedPane.addTab("OP320记录", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), scrollPane5, null);
  704. // 员工工作记录
  705. panel4 = new JPanel();
  706. scrollPane4 = new JScrollPane(panel4);
  707. panel4.setLayout(null);
  708. tabbedPane.addTab("人员记录", scrollPane4);
  709. tabbedPane.addChangeListener(new ChangeListener() {
  710. @Override
  711. public void stateChanged(ChangeEvent e) {
  712. JTabbedPane tabbedPane = (JTabbedPane) e.getSource();
  713. int selectedIndex = tabbedPane.getSelectedIndex();
  714. if (selectedIndex == 1) {
  715. }
  716. }
  717. });
  718. }
  719. public static void setMenuState_1(String msg, int error) {
  720. if (error == 0) {
  721. MesClient.status_menu_1.setForeground(Color.GREEN);
  722. } else {
  723. MesClient.status_menu_1.setForeground(Color.RED);
  724. }
  725. MesClient.status_menu_1.setText(msg);
  726. }
  727. public static void setMenuState_2(String msg, int error) {
  728. if (error == 0) {
  729. MesClient.status_menu_2.setForeground(Color.GREEN);
  730. } else {
  731. MesClient.status_menu_2.setForeground(Color.RED);
  732. }
  733. MesClient.status_menu_2.setText(msg);
  734. }
  735. public static void getMaterailData() {
  736. JSONObject retObj = DataUtil.getBindMaterail();
  737. if (retObj.get("result") != null && retObj.get("result").toString().equalsIgnoreCase("true")) {
  738. java.util.List<BindMaterialResp> arrs = retObj.getList("data", BindMaterialResp.class);
  739. int i = 0;
  740. rowData = new Object[arrs.size()][7];
  741. for (BindMaterialResp bindMaterialResp : arrs) {
  742. rowData[i][0] = bindMaterialResp.getMaterialTitle();
  743. rowData[i][1] = bindMaterialResp.getBatchSn();
  744. rowData[i][2] = bindMaterialResp.getLastTimes();
  745. rowData[i][3] = "";
  746. rowData[i][4] = bindMaterialResp.getCraft();
  747. rowData[i][5] = bindMaterialResp.getMaterialId();
  748. rowData[i][6] = bindMaterialResp.getType();
  749. i++;
  750. }
  751. bindBatchPanel();
  752. }
  753. }
  754. public static void updateMaterailData() {
  755. JSONObject retObj = DataUtil.getBindMaterail();
  756. if (retObj.get("result") != null && retObj.get("result").toString().equalsIgnoreCase("true")) {
  757. List<BindMaterialResp> arrs = retObj.getList("data", BindMaterialResp.class);
  758. int i = 0;
  759. for (BindMaterialResp bindMaterialResp : arrs) {
  760. rowData[i][0] = bindMaterialResp.getMaterialTitle();
  761. rowData[i][1] = bindMaterialResp.getBatchSn();
  762. rowData[i][2] = bindMaterialResp.getLastTimes();
  763. rowData[i][3] = "";
  764. rowData[i][4] = bindMaterialResp.getCraft();
  765. rowData[i][5] = bindMaterialResp.getMaterialId();
  766. rowData[i][6] = bindMaterialResp.getType();
  767. i++;
  768. }
  769. MesClient.table.repaint();
  770. }
  771. }
  772. // 绑定物料批次码
  773. public static void scanBatchSn(BindMaterialResp bindMaterialResp) {
  774. //弹窗扫工件码
  775. String scanBarcodeTitle = "请扫物料:" + bindMaterialResp.getMaterialTitle();
  776. String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
  777. if (scanBarcode != null && !scanBarcode.equalsIgnoreCase("")) {
  778. JSONObject retObj = DataUtil.saveBindMaterail(scanBarcode, bindMaterialResp.getCraft(), bindMaterialResp.getMaterialId(), bindMaterialResp.getType());
  779. if (retObj.get("result") != null && retObj.get("result").toString().equalsIgnoreCase("true")) {
  780. MesClient.setMenuState_1("扫物料:" + bindMaterialResp.getMaterialTitle() + "成功", 0);
  781. updateMaterailData();
  782. } else {
  783. if (retObj.get("result") == null) {
  784. MesClient.setMenuState_1("请求失败,请重试", -1);
  785. } else {
  786. if (retObj.get("result").toString().equalsIgnoreCase("false")) {
  787. MesClient.setMenuState_1(retObj.getString("message"), -1);
  788. }
  789. }
  790. }
  791. }
  792. }
  793. public static void bindBatchPanel() {
  794. JPanel indexPanelBB = new JPanel();
  795. JPanel panel = new JPanel();
  796. panel.setBounds(0, 0, 990, 550);
  797. // panel.setBounds(81, 50, 810, 479);
  798. indexPanelBB.add(panel);
  799. panel.setLayout(new GridLayout(0, 1, 0, 0));
  800. table = new JTable(rowData, columnNames) {
  801. public boolean isCellEditable(int row, int column) {
  802. if (column == 3) {
  803. return true;
  804. }
  805. return false;
  806. }
  807. };
  808. table.setRowHeight(40);
  809. table.setEnabled(true);
  810. table.setFont(new Font("微软雅黑", Font.PLAIN, 14));
  811. table.getColumnModel().getColumn(3).setCellRenderer(new TableCellRendererButton());
  812. table.getColumnModel().getColumn(3).setCellEditor(new TableCellEditorButton());
  813. JScrollPane scrollPane = new JScrollPane(table);
  814. panel.add(scrollPane);
  815. JScrollPane indexScrollPaneB = new JScrollPane(indexPanelBB);
  816. indexPanelBB.setLayout(null);
  817. tabbedPane.addTab("绑定物料", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), indexScrollPaneB, null);
  818. }
  819. }