MesClient.java 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  1. package com.mes.ui;
  2. import com.alibaba.fastjson2.JSONObject;
  3. import com.mes.component.MesRadio;
  4. import com.mes.component.MesWebView;
  5. import com.mes.util.DateLocalUtils;
  6. import com.mes.util.HttpUtils;
  7. import com.mes.util.JdbcUtils;
  8. import com.mes.util.PrintUtil;
  9. import org.slf4j.Logger;
  10. import org.slf4j.LoggerFactory;
  11. import javax.swing.*;
  12. import javax.swing.border.EmptyBorder;
  13. import javax.swing.event.ChangeEvent;
  14. import javax.swing.event.ChangeListener;
  15. import java.awt.*;
  16. import java.awt.event.*;
  17. import java.io.*;
  18. import java.sql.ResultSet;
  19. import java.sql.Statement;
  20. import java.time.LocalDateTime;
  21. import java.util.List;
  22. import java.util.Properties;
  23. import java.util.Timer;
  24. import java.util.TimerTask;
  25. import java.util.concurrent.ExecutorService;
  26. import java.util.concurrent.Executors;
  27. public class MesClient extends JFrame {
  28. public static final Logger log = LoggerFactory.getLogger(MesClient.class);
  29. public static int mes_auth = 0; // 权限级别 0=无权限 1=操作工人 2=管理员
  30. public static String mes_gw = ""; // 工位号
  31. public static String mes_gw_des = ""; // 工位名称
  32. public static String mes_server_ip = ""; // 服务器IP地址
  33. public static int mes_heart_icon_cycle = 1;
  34. public static String mes_line_sn = ""; // 产线编号
  35. //session
  36. public static String sessionid = "";
  37. public static JPanel contentPane;
  38. public static MesClient mesClientFrame;
  39. public static JTabbedPane tabbedPane;
  40. public static JScrollPane indexScrollPaneA;
  41. public static JScrollPane searchScrollPane; // 已弃用,改为使用 WorkRecordPanel
  42. public static JScrollPane searchScrollPaneDj;
  43. public static Boolean check_quality_result = false;
  44. public static Integer work_status = 0;
  45. public static JButton heart_beat_menu;
  46. public static JButton status_menu;
  47. public static JButton user_menu;
  48. public static int scan_type = 0;
  49. public static JButton finish_ok_bt;
  50. public static JButton finish_ng_bt;
  51. public static JTextField product_sn;
  52. public static JButton f_scan_data_bt_1;
  53. public static String user20 = "";
  54. public static JFrame welcomeWin;
  55. public static JPanel indexPanelB; // 已弃用,改为使用 WorkRecordPanel
  56. public static MesWebView jfxPanel = null;
  57. public static JPanel indexPanelC;
  58. public static MesWebView jfxPanel2 = null;
  59. public static MesRadio mesRadioHj;
  60. public static JTable table;
  61. public static Object[] columnNames = { "物料名称", "绑定批次", "剩余次数", "操作" };
  62. public static Object[][] rowData = null;
  63. public static JLabel fxlabel;
  64. public static void main(String[] args) {
  65. if (LockUtil.getInstance().isAppActive() == true){
  66. // JOptionPane.showMessageDialog(null, "已有一个程序在运行,程序退出");
  67. return;
  68. }else{
  69. EventQueue.invokeLater(new Runnable() {
  70. @Override
  71. public void run() {
  72. try{
  73. //读文件配置
  74. readProperty();
  75. // 显示界面
  76. mesClientFrame = new MesClient();
  77. mesClientFrame.setVisible(false);
  78. JdbcUtils.getConn();
  79. welcomeWin = new LoginFarme();
  80. welcomeWin.setVisible(true);
  81. getMaterailData();
  82. }catch (Exception e){
  83. e.printStackTrace();
  84. }
  85. }
  86. });
  87. }
  88. }
  89. //读配置文件
  90. private static void readProperty() throws IOException{
  91. String enconding = "UTF-8";
  92. InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
  93. Properties pro = new Properties();
  94. BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
  95. pro.load(br);
  96. mes_gw = pro.getProperty("mes.gw");
  97. mes_server_ip = pro.getProperty("mes.server_ip");
  98. mes_line_sn = pro.getProperty("mes.line_sn");
  99. mes_gw_des = OprnoUtil.getGwDes(mes_line_sn,mes_gw);
  100. log.info(mes_gw + ";" + mes_gw_des + ";" + mes_server_ip + ";");
  101. }
  102. //启动心跳包程序
  103. public static java.util.Timer heartBeatTimer;
  104. public static java.util.Timer heartBeatIconTimer;
  105. public static boolean iconREDFlag = true;
  106. public static void startHeartBeatTimer() {
  107. if(heartBeatTimer!=null) {
  108. heartBeatTimer.cancel();
  109. }
  110. //心跳显示图标
  111. if(heartBeatIconTimer!=null) {
  112. heartBeatIconTimer.cancel();
  113. }
  114. heartBeatIconTimer = new Timer();
  115. heartBeatIconTimer.schedule(new TimerTask() {
  116. public void run() {
  117. if(iconREDFlag) {
  118. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  119. iconREDFlag = false;
  120. }else {
  121. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
  122. iconREDFlag = true;
  123. }
  124. heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
  125. heart_beat_menu.repaint();
  126. }
  127. }, 100,mes_heart_icon_cycle*1000);
  128. }
  129. //设置tcp连接状态显示
  130. public static void setTcpStatus() {
  131. status_menu.setText("已连接MES服务器");
  132. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  133. heart_beat_menu.repaint();
  134. }
  135. public static void initWarehouseData(){
  136. resetScanA();
  137. }
  138. public static void resetScanA() {
  139. work_status = 0;
  140. check_quality_result = false;
  141. // 只保留“打印精追码”,扫码/OKNG 功能已注释掉
  142. if(MesClient.finish_ok_bt!=null){
  143. MesClient.finish_ok_bt.setEnabled(false);
  144. }
  145. if(MesClient.finish_ng_bt!=null){
  146. MesClient.finish_ng_bt.setEnabled(false);
  147. }
  148. if(MesClient.product_sn!=null){
  149. product_sn.setText("");
  150. }
  151. if(MesClient.fxlabel!=null){
  152. MesClient.fxlabel.setVisible(false);
  153. }
  154. if(MesClient.f_scan_data_bt_1!=null){
  155. MesClient.f_scan_data_bt_1.setEnabled(false);
  156. }
  157. MesClient.setMenuStatus("请点击打印精追码",0);
  158. // MesClient.setMenuStatus("开班点检,请先进行OKNG样件测试",-1);
  159. updateMaterailData();
  160. // shiftUserCheck();
  161. }
  162. public static int userLoginHours;//用户登录所处小时
  163. public static JTextField printerSn;
  164. public static JButton printerBtn;
  165. //换班用户信息检查
  166. private static void shiftUserCheck() {
  167. LocalDateTime now = LocalDateTime.now();
  168. // 判断时间范围
  169. if (userLoginHours >= 8 && userLoginHours < 20) {
  170. int hour = now.getHour();
  171. if (hour >= 20 || hour < 8) {
  172. logoff();
  173. }
  174. } else {
  175. int hour = now.getHour();
  176. if (hour >= 8 && hour < 20) {
  177. logoff();
  178. }
  179. }
  180. }
  181. public static void resetScanB() {
  182. }
  183. //获取用户20位
  184. public static void getUser() {
  185. user20 = user_menu.getText().toString();
  186. // String space_tmp1 = "";
  187. // if(user20.length()<20) {
  188. // for(int i=0;i<20-user20.length();i++) {
  189. // space_tmp1 = space_tmp1 + " ";
  190. // }
  191. // }
  192. // user20 = user20 + space_tmp1;
  193. }
  194. //获取barcode内容36位
  195. public static String getBarcode(String barcodeTmp) {
  196. String barcodeRet = barcodeTmp;
  197. if(barcodeTmp.equalsIgnoreCase("")) {
  198. return "";
  199. }else {
  200. if(barcodeTmp.length()<36) {
  201. String space = "";
  202. for(int i=0;i<36-barcodeTmp.length();i++) {
  203. space = space + " ";
  204. }
  205. barcodeRet = barcodeTmp + space;
  206. }
  207. }
  208. return barcodeRet;
  209. }
  210. public static void scanBarcode() {
  211. if(work_status == 1){
  212. JOptionPane.showMessageDialog(mesClientFrame,"工作中,勿扫码","提示窗口", JOptionPane.INFORMATION_MESSAGE);
  213. return;
  214. }
  215. // UI 已移除扫码输入框:避免意外触发导致空指针
  216. if(MesClient.product_sn==null){
  217. MesClient.setMenuStatus("扫码功能已关闭,请点击打印精追码",-1);
  218. return;
  219. }
  220. String scanBarcodeTitle = "";
  221. switch(scan_type) {
  222. case 1:
  223. product_sn.setText("");
  224. scanBarcodeTitle = "请扫工件码";
  225. break;
  226. }
  227. //弹窗扫工件码
  228. String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
  229. if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")) {
  230. //获取用户
  231. getUser();
  232. //获取扫码内容36位
  233. String barcode36 = getBarcode(scanBarcode);//处理36为码
  234. //工位号
  235. String gw = "";
  236. switch(scan_type) {
  237. case 1:
  238. product_sn.setText(scanBarcode);
  239. break;
  240. }
  241. //刷新界面
  242. mesClientFrame.repaint();
  243. // 查询工件质量
  244. JSONObject retObj = DataUtil.checkQuality(scanBarcode,user20);
  245. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  246. MesClient.status_menu.setForeground(Color.GREEN);
  247. MesClient.check_quality_result = true;//质量合格,可以绑定加工
  248. MesClient.status_menu.setText("该工件可以加工");
  249. MesClient.work_status = 1;
  250. if(MesClient.f_scan_data_bt_1!=null){
  251. MesClient.f_scan_data_bt_1.setEnabled(false);
  252. }
  253. if(MesClient.finish_ok_bt!=null){
  254. MesClient.finish_ok_bt.setEnabled(true);
  255. }
  256. if(MesClient.finish_ng_bt!=null){
  257. MesClient.finish_ng_bt.setEnabled(true);
  258. }
  259. }else{
  260. MesClient.check_quality_result = false;
  261. MesClient.work_status = 0;
  262. if(retObj.get("result")==null){
  263. MesClient.setMenuStatus("请求失败,请重试",-1);
  264. }else{
  265. if(retObj.get("result").toString().equalsIgnoreCase("false")){
  266. MesClient.setMenuStatus(retObj.getString("message"),-1);
  267. }
  268. }
  269. }
  270. }else {
  271. MesClient.setMenuStatus("请扫工件码,请重试",-1);
  272. // JOptionPane.showMessageDialog(mesClientFrame,"请扫工件码","提示窗口", JOptionPane.INFORMATION_MESSAGE);
  273. return;
  274. }
  275. }
  276. public static void logoff() {
  277. welcomeWin.setVisible(true);
  278. mesClientFrame.setVisible(false);
  279. }
  280. public static void createSn(){
  281. JSONObject retObj = DataUtil.createSn();
  282. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  283. String wsn = retObj.getString("data");
  284. printerSn.setText(wsn);
  285. PrintUtil.printLabel(wsn);
  286. }else{
  287. if(retObj.get("result")==null){
  288. MesClient.setMenuStatus("请求失败,请重试",-1);
  289. }else{
  290. if(retObj.get("result").toString().equalsIgnoreCase("false")){
  291. MesClient.setMenuStatus(retObj.getString("message"),-1);
  292. }
  293. }
  294. }
  295. }
  296. public MesClient() {
  297. setIconImage(Toolkit.getDefaultToolkit().getImage(MesClient.class.getResource("/bg/logo.png")));
  298. setTitle("MES系统客户端:打印精追码");
  299. // setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  300. setBounds(0, 0, 1024, 768);
  301. setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
  302. // 添加窗口监听器
  303. addWindowListener(new WindowAdapter() {
  304. @Override
  305. public void windowClosing(WindowEvent e) {
  306. int choice = JOptionPane.showConfirmDialog(null, "确定要关闭窗口吗?", "关闭确认", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
  307. if (choice == JOptionPane.YES_OPTION) {
  308. // 如果用户点击“是”,则关闭窗口
  309. dispose(); // 释放窗口资源并关闭窗口
  310. System.exit(0);
  311. }
  312. }
  313. });
  314. JMenuBar menuBar = new JMenuBar();
  315. menuBar.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 26));
  316. setJMenuBar(menuBar);
  317. JMenu fileMenu = new JMenu("用户");
  318. fileMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/user.png")));
  319. fileMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  320. menuBar.add(fileMenu);
  321. JMenuItem exitMenuItem = new JMenuItem("退出");
  322. exitMenuItem.setIcon(new ImageIcon(MesClient.class.getResource("/bg/logoff.png")));
  323. exitMenuItem.setFont(new Font("微软雅黑", Font.PLAIN, 22));
  324. fileMenu.add(exitMenuItem);
  325. exitMenuItem.addMouseListener(new MouseAdapter() {
  326. @Override
  327. public void mousePressed(MouseEvent e) {//只能检测到mousePressed事件
  328. super.mouseClicked(e);
  329. //dispose();
  330. logoff();
  331. }
  332. });
  333. JMenu settingMenu = new JMenu("设置");
  334. //settingMenu.setVisible(false);
  335. settingMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")));
  336. settingMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  337. menuBar.add(settingMenu);
  338. JMenuItem resetTcpMenu = new JMenuItem("\u91CD\u8FDEMES");
  339. resetTcpMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  340. resetTcpMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  341. resetTcpMenu.addMouseListener(new MouseAdapter() {
  342. @Override
  343. public void mousePressed(MouseEvent e) {
  344. super.mouseClicked(e);
  345. }
  346. });
  347. // settingMenu.add(resetTcpMenu);
  348. JMenuItem resetTcpMenu_1 = new JMenuItem("刷新工件");
  349. resetTcpMenu_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  350. resetTcpMenu_1.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  351. resetTcpMenu_1.addMouseListener(new MouseAdapter() {
  352. @Override
  353. public void mousePressed(MouseEvent e) {
  354. super.mouseClicked(e);
  355. resetScanA();
  356. }
  357. });
  358. settingMenu.add(resetTcpMenu_1);
  359. contentPane = new JPanel();
  360. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  361. setContentPane(contentPane);
  362. contentPane.setLayout(new BorderLayout(0, 0));
  363. JToolBar toolBar = new JToolBar();
  364. contentPane.add(toolBar, BorderLayout.NORTH);
  365. JLabel equipment_statu_label = new JLabel("状态:");
  366. equipment_statu_label.setHorizontalAlignment(SwingConstants.CENTER);
  367. equipment_statu_label.setForeground(Color.BLACK);
  368. equipment_statu_label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  369. equipment_statu_label.setBackground(Color.LIGHT_GRAY);
  370. toolBar.add(equipment_statu_label);
  371. status_menu = new JButton("设备未连接MES服务器");
  372. status_menu.setText("已连接MES服务器");
  373. status_menu.setForeground(Color.GREEN);
  374. status_menu.addActionListener(new ActionListener() {
  375. public void actionPerformed(ActionEvent e) {
  376. }
  377. });
  378. status_menu.setForeground(Color.GREEN);
  379. status_menu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  380. status_menu.setBackground(Color.BLACK);
  381. toolBar.add(status_menu);
  382. JLabel space_1 = new JLabel(" ");
  383. toolBar.add(space_1);
  384. JLabel heart_beat_status_label = new JLabel("心跳:");
  385. heart_beat_status_label.setHorizontalAlignment(SwingConstants.CENTER);
  386. heart_beat_status_label.setForeground(Color.BLACK);
  387. heart_beat_status_label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  388. heart_beat_status_label.setBackground(Color.LIGHT_GRAY);
  389. toolBar.add(heart_beat_status_label);
  390. heart_beat_menu = new JButton("2024-02-20 23:20:10");
  391. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
  392. heart_beat_menu.setForeground(Color.GREEN);
  393. heart_beat_menu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  394. heart_beat_menu.setBackground(Color.BLACK);
  395. toolBar.add(heart_beat_menu);
  396. JLabel space_2 = new JLabel(" ");
  397. toolBar.add(space_2);
  398. JLabel user_status_label = new JLabel("登录用户:");
  399. user_status_label.setHorizontalAlignment(SwingConstants.CENTER);
  400. user_status_label.setForeground(Color.BLACK);
  401. user_status_label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  402. user_status_label.setBackground(Color.LIGHT_GRAY);
  403. toolBar.add(user_status_label);
  404. user_menu = new JButton("JinJuShi");
  405. user_menu.setForeground(Color.GREEN);
  406. user_menu.setFont(new Font("微软雅黑", Font.PLAIN, 22));
  407. user_menu.setBackground(Color.BLACK);
  408. toolBar.add(user_menu);
  409. JLabel space_3 = new JLabel(" ");
  410. toolBar.add(space_3);
  411. JLabel space_4 = new JLabel(" ");
  412. toolBar.add(space_4);
  413. tabbedPane = new JTabbedPane(JTabbedPane.TOP);
  414. tabbedPane.setMinimumSize(new Dimension(400, 50));
  415. tabbedPane.setFont(new Font("宋体", Font.BOLD, 22));
  416. contentPane.add(tabbedPane);
  417. //首页
  418. JPanel indexPanelA = new JPanel();
  419. indexScrollPaneA = new JScrollPane(indexPanelA);
  420. indexPanelA.setLayout(null);
  421. /*
  422. * 扫码输入框(你说的“扫码的那个框”)已注释掉:
  423. * 仅保留打印精追码功能,不再展示/使用 product_sn。
  424. */
  425. // product_sn = new JTextField();
  426. // product_sn.setHorizontalAlignment(SwingConstants.CENTER);
  427. // product_sn.setEditable(false);
  428. // product_sn.setFont(new Font("微软雅黑", Font.PLAIN, 28));
  429. // product_sn.setBounds(81, 70, 602, 70);
  430. // indexPanelA.add(product_sn);
  431. // product_sn.setColumns(10);
  432. /*
  433. * 扫码功能已注释:只保留“打印精追码”。
  434. * f_scan_data_bt_1 初始化/事件绑定如下被注释掉:
  435. */
  436. // f_scan_data_bt_1 = new JButton("扫码");
  437. // f_scan_data_bt_1.addActionListener(new ActionListener() {
  438. // public void actionPerformed(ActionEvent e) {
  439. // scan_type = 1;
  440. // scanBarcode();
  441. // }
  442. // });
  443. // f_scan_data_bt_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/scan_barcode.png")));
  444. // f_scan_data_bt_1.setFont(new Font("微软雅黑", Font.PLAIN, 32));
  445. // f_scan_data_bt_1.setBounds(693, 70, 198, 70);
  446. // indexPanelA.add(f_scan_data_bt_1);
  447. // String[] hjtitles = new String[]{"焊机1","焊机2","焊机3"};
  448. // String[] hjvals = new String[]{"HJ001","HJ002","HJ003"};
  449. // mesRadioHj = new MesRadio(hjtitles,hjvals);
  450. // mesRadioHj.setSize(500,50);
  451. // mesRadioHj.setBounds(190,170,500,50);
  452. // indexPanelA.add(mesRadioHj);
  453. // 返修提示在本需求中不使用,同步注释掉
  454. // fxlabel = new JLabel("该工件为返修件,请仔细检查");
  455. // fxlabel.setFont(new Font("微软雅黑", Font.PLAIN, 38));
  456. // fxlabel.setBounds(81, 170, 810, 70);
  457. // fxlabel.setForeground(Color.RED);
  458. // fxlabel.setHorizontalAlignment(SwingConstants.CENTER);
  459. // fxlabel.setVisible(false);
  460. // indexPanelA.add(fxlabel);
  461. /*
  462. * OK/NG(OKNG) 功能已注释:只保留“打印精追码”。
  463. * finish_ok_bt / finish_ng_bt 初始化/事件绑定如下被注释掉:
  464. */
  465. // finish_ok_bt = new JButton("OK");
  466. // finish_ok_bt.setEnabled(false);
  467. // finish_ok_bt.addActionListener(new ActionListener() {
  468. // public void actionPerformed(ActionEvent e) {
  469. // if(work_status == 1 && check_quality_result){
  470. // getUser();
  471. // String sn = MesClient.product_sn.getText().trim();
  472. // if(sn.isEmpty()){
  473. // MesClient.setMenuStatus("工件码为空,请重试",-1);
  474. // return;
  475. // }
  476. //
  477. // JSONObject retObj = DataUtil.sendQuality(sn,"OK",user20);
  478. // System.out.println(retObj);
  479. // if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  480. // MesClient.resetScanA();
  481. // MesClient.setMenuStatus("结果提交成功,请扫下一件",0);
  482. // MesClient.scan_type = 1;
  483. // MesClient.scanBarcode();
  484. // }else{
  485. // if(retObj.get("result")==null){
  486. // MesClient.setMenuStatus("请求失败,请重试",-1);
  487. // }else{
  488. // if(retObj.get("result").toString().equalsIgnoreCase("false")){
  489. // MesClient.setMenuStatus(retObj.getString("message"),-1);
  490. // }
  491. // }
  492. // }
  493. // }
  494. // }
  495. // });
  496. // finish_ok_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
  497. // finish_ok_bt.setFont(new Font("微软雅黑", Font.PLAIN, 32));
  498. // finish_ok_bt.setBounds(185, 291, 240, 80);
  499. // finish_ok_bt.setEnabled(false);
  500. // indexPanelA.add(finish_ok_bt);
  501. //
  502. // finish_ng_bt = new JButton("NG");
  503. // finish_ng_bt.setEnabled(false);
  504. // finish_ng_bt.addActionListener(new ActionListener() {
  505. // public void actionPerformed(ActionEvent e) {
  506. // if(work_status == 1 && check_quality_result){
  507. // getUser();
  508. // String sn = MesClient.product_sn.getText().trim();
  509. // if(sn.isEmpty()){
  510. // MesClient.setMenuStatus("工件码为空,请重试",-1);
  511. // return;
  512. // }
  513. //
  514. // JSONObject retObj = DataUtil.sendQuality(sn,"NG",user20);
  515. // if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  516. // MesClient.resetScanA();
  517. // MesClient.setMenuStatus("结果提交成功,请扫下一件",0);
  518. // MesClient.scan_type = 1;
  519. // MesClient.scanBarcode();
  520. // }else{
  521. // if(retObj.get("result")==null){
  522. // MesClient.setMenuStatus("请求失败,请重试",-1);
  523. // }else{
  524. // if(retObj.get("result").toString().equalsIgnoreCase("false")){
  525. // MesClient.setMenuStatus(retObj.getString("message"),-1);
  526. // }
  527. // }
  528. // }
  529. // }
  530. // }
  531. // });
  532. // finish_ng_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ng_bg.png")));
  533. // finish_ng_bt.setFont(new Font("微软雅黑", Font.PLAIN, 32));
  534. // finish_ng_bt.setBounds(508, 291, 240, 80);
  535. // finish_ng_bt.setEnabled(false);
  536. // indexPanelA.add(finish_ng_bt);
  537. printerBtn = new JButton("打印精追码");
  538. printerBtn.setFont(new Font("微软雅黑", Font.PLAIN, 32));
  539. // 居中展示
  540. printerBtn.setBounds(147, 240, 198, 70);
  541. indexPanelA.add(printerBtn);
  542. printerBtn.addActionListener(new ActionListener() {
  543. public void actionPerformed(ActionEvent e) {
  544. createSn();
  545. }
  546. });
  547. printerSn = new JTextField();
  548. printerSn.setHorizontalAlignment(SwingConstants.CENTER);
  549. printerSn.setFont(new Font("微软雅黑", Font.PLAIN, 28));
  550. printerSn.setEditable(false);
  551. printerSn.setColumns(10);
  552. // 与按钮保持居中对齐
  553. printerSn.setBounds(355, 240, 398, 70);
  554. indexPanelA.add(printerSn);
  555. tabbedPane.addTab("工作面板", new ImageIcon(MesClient.class.getResource("/bg/a_side.png")), indexScrollPaneA, null);
  556. tabbedPane.setEnabledAt(0, true);
  557. // searchScrollPane = new JScrollPane((Component) null);
  558. indexPanelC = new JPanel();
  559. searchScrollPaneDj = new JScrollPane(indexPanelC);
  560. indexPanelC.setLayout(null);
  561. // tabbedPane.addTab("开班点检", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPaneDj, null);
  562. // ========== 工作记录 Tab(改造:当前工位Tab + 所有工位Tab) ==========
  563. // 旧代码已注释:
  564. indexPanelB = new JPanel();
  565. searchScrollPane = new JScrollPane(indexPanelB);
  566. indexPanelB.setLayout(null);
  567. // tabbedPane.addTab("工作记录", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPane, null);
  568. // // 创建工作记录的子 TabbedPane
  569. // JTabbedPane workRecordTabbedPane = new JTabbedPane(JTabbedPane.TOP);
  570. // workRecordTabbedPane.setFont(new Font("微软雅黑", Font.PLAIN, 14));
  571. //
  572. // // OKNG 工位:当前工位 + 所有工位
  573. // WorkRecordPanel[] workRecordPanels = new WorkRecordPanel[2];
  574. //
  575. // // 当前工位Tab(使用配置文件中的 mes.gw)
  576. // workRecordPanels[0] = new WorkRecordPanel(mes_gw, mes_line_sn);
  577. // workRecordTabbedPane.addTab(mes_gw, null, workRecordPanels[0], "查询" + mes_gw + "的工作记录");
  578. //
  579. // // 所有工位Tab(查询整条产线所有工位)
  580. // workRecordPanels[1] = new WorkRecordPanel(null, mes_line_sn);
  581. // workRecordTabbedPane.addTab("所有工位", null, workRecordPanels[1], "查询整条产线所有工位的工作记录");
  582. //
  583. // // 切换子Tab时自动刷新数据
  584. // workRecordTabbedPane.addChangeListener(e -> {
  585. // int selectedIndex = workRecordTabbedPane.getSelectedIndex();
  586. // if (selectedIndex >= 0 && selectedIndex < workRecordPanels.length) {
  587. // workRecordPanels[selectedIndex].refreshData();
  588. // }
  589. // });
  590. //
  591. // // 将子 TabbedPane 添加到主 TabbedPane
  592. // tabbedPane.addTab("工作记录", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), workRecordTabbedPane, null);
  593. //
  594. tabbedPane.addChangeListener(new ChangeListener() {
  595. @Override
  596. public void stateChanged(ChangeEvent e) {
  597. JTabbedPane tabbedPane = (JTabbedPane) e.getSource();
  598. int selectedIndex = tabbedPane.getSelectedIndex();
  599. System.out.println("selectedIndex:"+selectedIndex);
  600. if(selectedIndex == 1){
  601. }
  602. }
  603. });
  604. }
  605. public static void setMenuStatus(String msg,int error){
  606. if(error == 0){
  607. MesClient.status_menu.setForeground(Color.GREEN);
  608. }else{
  609. MesClient.status_menu.setForeground(Color.RED);
  610. }
  611. MesClient.status_menu.setText(msg);
  612. }
  613. public static void getMaterailData(){
  614. try{
  615. JSONObject retObj = DataUtil.getBindMaterail();
  616. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  617. java.util.List<BindMaterialResp> arrs = retObj.getList("data",BindMaterialResp.class);
  618. int i = 0;
  619. rowData = new Object[arrs.size()][7];
  620. for (BindMaterialResp bindMaterialResp:arrs){
  621. rowData[i][0] = bindMaterialResp.getMaterialTitle();
  622. rowData[i][1] = bindMaterialResp.getBatchSn();
  623. rowData[i][2] = bindMaterialResp.getLastTimes();
  624. rowData[i][3] = "";
  625. rowData[i][4] = bindMaterialResp.getCraft();
  626. rowData[i][5] = bindMaterialResp.getMaterialId();
  627. rowData[i][6] = bindMaterialResp.getType();
  628. i++;
  629. }
  630. bindBatchPanel();
  631. }
  632. }catch (Exception e){
  633. log.info(e.getMessage());
  634. }
  635. }
  636. public static void updateMaterailData(){
  637. try{
  638. JSONObject retObj = DataUtil.getBindMaterail();
  639. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  640. List<BindMaterialResp> arrs = retObj.getList("data",BindMaterialResp.class);
  641. int i = 0;
  642. for (BindMaterialResp bindMaterialResp:arrs){
  643. rowData[i][0] = bindMaterialResp.getMaterialTitle();
  644. rowData[i][1] = bindMaterialResp.getBatchSn();
  645. rowData[i][2] = bindMaterialResp.getLastTimes();
  646. rowData[i][3] = "";
  647. rowData[i][4] = bindMaterialResp.getCraft();
  648. rowData[i][5] = bindMaterialResp.getMaterialId();
  649. rowData[i][6] = bindMaterialResp.getType();
  650. i++;
  651. }
  652. MesClient.table.repaint();
  653. }
  654. }catch (Exception e){
  655. log.info(e.getMessage());
  656. }
  657. }
  658. // 绑定物料批次码
  659. public static void scanBatchSn(BindMaterialResp bindMaterialResp) {
  660. //弹窗扫工件码
  661. String scanBarcodeTitle = "请扫物料:"+bindMaterialResp.getMaterialTitle();
  662. String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
  663. if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")) {
  664. JSONObject retObj = DataUtil.saveBindMaterail(scanBarcode,bindMaterialResp.getCraft(),bindMaterialResp.getMaterialId(),bindMaterialResp.getType());
  665. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  666. MesClient.setMenuStatus("扫物料:"+bindMaterialResp.getMaterialTitle()+"成功",0);
  667. updateMaterailData();
  668. }else{
  669. if(retObj.get("result")==null){
  670. MesClient.setMenuStatus("请求失败,请重试",-1);
  671. }else{
  672. if(retObj.get("result").toString().equalsIgnoreCase("false")){
  673. MesClient.setMenuStatus(retObj.getString("message"),-1);
  674. }
  675. }
  676. }
  677. }
  678. }
  679. public static void bindBatchPanel(){
  680. JPanel indexPanelBB = new JPanel();
  681. JPanel panel = new JPanel();
  682. panel.setBounds(0, 0, 990, 550);
  683. // panel.setBounds(81, 50, 810, 479);
  684. indexPanelBB.add(panel);
  685. panel.setLayout(new GridLayout(0, 1, 0, 0));
  686. table = new JTable(rowData, columnNames){
  687. public boolean isCellEditable(int row, int column) {
  688. if(column == 3){
  689. return true;
  690. }
  691. return false;
  692. }
  693. };
  694. table.setRowHeight(40);
  695. table.setEnabled(true);
  696. table.setFont(new Font("微软雅黑", Font.PLAIN, 14));
  697. table.getColumnModel().getColumn(3).setCellRenderer(new TableCellRendererButton());
  698. table.getColumnModel().getColumn(3).setCellEditor(new TableCellEditorButton());
  699. JScrollPane scrollPane = new JScrollPane(table);
  700. panel.add(scrollPane);
  701. JScrollPane indexScrollPaneB = new JScrollPane(indexPanelBB);
  702. indexPanelBB.setLayout(null);
  703. tabbedPane.addTab("绑定物料", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), indexScrollPaneB, null);
  704. }
  705. // 开启发送结果定时任务
  706. public static void startUpdateQualityTimer(){
  707. // 创建异步线程池
  708. ExecutorService executorService = Executors.newSingleThreadExecutor();
  709. // 提交任务
  710. executorService.submit(() -> {
  711. log.info("异步任务执行中...");
  712. // 模拟耗时操作
  713. try {
  714. while (true){
  715. try {
  716. // 确保连接已经打开
  717. if (JdbcUtils.conn == null || JdbcUtils.conn.isClosed()) {
  718. JdbcUtils.openConnection();
  719. }
  720. Statement statement = JdbcUtils.conn.createStatement();
  721. String selectSql = "SELECT id, bw FROM submit_record\n" +
  722. "WHERE state = 0 ORDER BY id DESC LIMIT 10";
  723. String updateSql = "UPDATE submit_record \n" +
  724. "SET state = '1'\n" +
  725. "WHERE id = ";
  726. ResultSet rs = statement.executeQuery(selectSql);
  727. while(rs.next()){
  728. int id = rs.getInt("id");
  729. String bw = rs.getString("bw");
  730. // 发送请求
  731. String url = "http://"+MesClient.mes_server_ip+":8980/js/a/mes/mesProductRecord/updateQualityByTiming";
  732. log.info("质量:"+bw);
  733. String s = HttpUtils.sendPostRequestJson(url, bw );
  734. log.info("结果:"+s);
  735. Boolean result = JSONObject.parseObject(s).getBoolean("result");
  736. if(result) {
  737. // 更改状态为 1
  738. statement.executeUpdate(updateSql + id);
  739. }
  740. }
  741. rs.close();
  742. statement.close();
  743. } catch (Exception e) {
  744. log.info(e.getMessage());
  745. }
  746. try {
  747. Thread.sleep(2000);
  748. }catch (Exception e){
  749. log.info(e.getMessage());
  750. }
  751. }
  752. } catch (Exception e) {
  753. log.info(e.getMessage());
  754. }
  755. log.info("异步任务执行完毕");
  756. });
  757. }
  758. }