MesClient.java 30 KB

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