MesClient.java 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228
  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.netty.NettyClient;
  8. import com.mes.netty.ProtocolParam;
  9. import com.mes.util.DateLocalUtils;
  10. import com.mes.util.ErrorMsg;
  11. import com.mes.util.HttpUtils;
  12. import com.mes.util.JdbcUtils;
  13. import javafx.embed.swing.JFXPanel;
  14. import org.slf4j.Logger;
  15. import org.slf4j.LoggerFactory;
  16. import javax.swing.*;
  17. import javax.swing.border.EmptyBorder;
  18. import javax.swing.event.ChangeEvent;
  19. import javax.swing.event.ChangeListener;
  20. import java.awt.*;
  21. import java.awt.event.ActionEvent;
  22. import java.awt.event.ActionListener;
  23. import java.awt.event.MouseAdapter;
  24. import java.awt.event.MouseEvent;
  25. import java.io.*;
  26. import java.nio.channels.FileChannel;
  27. import java.nio.channels.FileLock;
  28. import java.nio.channels.OverlappingFileLockException;
  29. import java.sql.ResultSet;
  30. import java.sql.SQLException;
  31. import java.sql.Statement;
  32. import java.time.LocalDateTime;
  33. import java.util.List;
  34. import java.util.Properties;
  35. import java.util.Timer;
  36. import java.util.TimerTask;
  37. import java.util.concurrent.ExecutorService;
  38. import java.util.concurrent.Executors;
  39. public class MesClient extends JFrame {
  40. public static final Logger log = LoggerFactory.getLogger(MesClient.class);
  41. public static int mes_auth = 0; // 权限级别 0=无权限 1=操作工人 2=管理员
  42. public static String mes_gw = ""; // 工位号
  43. public static String mes_gw_des = ""; // 工位名称
  44. public static String mes_server_ip = ""; // 服务器IP地址
  45. public static int mes_tcp_port = 3000; // TCP服务端口
  46. public static int mes_heart_beat_cycle = 10; // 心跳周期
  47. public static int mes_heart_icon_cycle = 1;
  48. public static String mes_line_sn = ""; // 产线编号
  49. //TCP连接
  50. public static NettyClient nettyClient;
  51. //TCP连接状态
  52. public static boolean tcp_connect_flag = false;
  53. //TCP连接请求
  54. public static boolean connect_request_flag = false;
  55. //session
  56. public static String sessionid = "";
  57. public static JPanel contentPane;
  58. public static MesClient mesClientFrame;
  59. public static JTabbedPane tabbedPane;
  60. public static JScrollPane indexScrollPaneA;
  61. public static JScrollPane searchScrollPane;
  62. public static JScrollPane searchScrollPaneDj;
  63. public static JScrollPane searchScrollPaneC;
  64. public static JScrollPane searchScrollPaneD;
  65. public static Boolean check_quality_result = false;
  66. public static Integer work_status = 0;
  67. public static Boolean bind_lb_result = false;
  68. public static JButton heart_beat_menu;
  69. public static JButton status_menu;
  70. public static JButton user_menu;
  71. public static int scan_type = 0;
  72. public static JButton finish_ok_bt;
  73. public static JButton finish_ng_bt;
  74. public static JTextField product_sn;
  75. public static JTextField product_sn_LB;
  76. public static JButton f_scan_data_bt_1;
  77. public static JButton f_scan_data_bt_2;
  78. public static String user20 = "";
  79. public static JFrame welcomeWin;
  80. public static JPanel indexPanelB;
  81. public static MesWebView jfxPanel = null;
  82. public static JPanel indexPanelC;
  83. public static MesWebView jfxPanel2 = null;
  84. public static MesRadio mesRadioHj;
  85. public static JPanel indexPanelD;
  86. public static JPanel indexPanelE;
  87. public static MesWebView jfxPanel3 = null;
  88. public static MesWebView jfxPanel4 = null;
  89. public static JTable table;
  90. public static Object[] columnNames = { "物料名称", "绑定批次", "剩余次数", "操作" };
  91. public static Object[][] rowData = null;
  92. public static JLabel fxlabel;
  93. public static JLabel timer_label; // 倒计时显示
  94. public static boolean timer_flag = false; // 开始计时标志 false=非工作开始计时 true=工件开始计时
  95. public static long timer_nums = 0; // 秒数
  96. public static S7PLC s7PLC = new S7PLC(EPlcType.S1200,"10.88.10.80");
  97. public static void main(String[] args) {
  98. try{
  99. //读文件配置
  100. readProperty();
  101. }catch (Exception e){
  102. e.printStackTrace();
  103. }
  104. if (LockUtil.getInstance().isAppActive() == true){
  105. JOptionPane.showMessageDialog(null, "已有一个程序在运行,程序退出");
  106. return;
  107. }else{
  108. EventQueue.invokeLater(new Runnable() {
  109. @Override
  110. public void run() {
  111. try{
  112. s7PLC.setConnectTimeout(800);
  113. s7PLC.setReceiveTimeout(800);
  114. // 显示界面
  115. mesClientFrame = new MesClient();
  116. mesClientFrame.setVisible(false);
  117. JdbcUtils.getConn();
  118. welcomeWin = new LoginFarme();
  119. welcomeWin.setVisible(true);
  120. getMaterailData();
  121. startPlcTimer();
  122. }catch (Exception e){
  123. e.printStackTrace();
  124. }
  125. }
  126. });
  127. }
  128. }
  129. //读配置文件
  130. private static void readProperty() throws IOException{
  131. String enconding = "UTF-8";
  132. InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
  133. Properties pro = new Properties();
  134. BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
  135. pro.load(br);
  136. mes_gw = pro.getProperty("mes.gw");
  137. mes_server_ip = pro.getProperty("mes.server_ip");
  138. mes_tcp_port = Integer.parseInt(pro.getProperty("mes.tcp_port"));
  139. mes_heart_beat_cycle = Integer.parseInt(pro.getProperty("mes.heart_beat_cycle"));
  140. mes_line_sn = pro.getProperty("mes.line_sn");
  141. mes_gw_des = OprnoUtil.getGwDes(mes_line_sn,mes_gw);
  142. log.info(mes_gw + ";" + mes_gw_des + ";" + mes_server_ip + ";" + mes_tcp_port + ";" + mes_heart_beat_cycle);
  143. }
  144. // 初始化TCP
  145. public static void initTcpConnection() {
  146. try {
  147. if(nettyClient==null) {
  148. //初始化TCP连接
  149. nettyClient = new NettyClient();
  150. //TCP连接状态
  151. tcp_connect_flag = false;
  152. //设置TCP请求状态
  153. connect_request_flag = true;
  154. DataUtil.synrTcp(nettyClient,mes_gw);
  155. }
  156. } catch (Exception e) {
  157. // TODO Auto-generated catch block
  158. e.printStackTrace();
  159. }
  160. }
  161. //启动心跳包程序
  162. public static java.util.Timer heartBeatTimer;
  163. public static java.util.Timer heartBeatIconTimer;
  164. public static boolean iconREDFlag = true;
  165. // 心跳程序包
  166. public static void startHeartBeatTimer() {
  167. if(heartBeatTimer!=null) {
  168. heartBeatTimer.cancel();
  169. }
  170. heartBeatTimer = new java.util.Timer();
  171. heartBeatTimer.schedule(new TimerTask() {
  172. public void run() {
  173. if(nettyClient!=null&&tcp_connect_flag) {
  174. //System.out.println("发送心跳报文");
  175. DataUtil.heartBeat(nettyClient,mes_gw);
  176. heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
  177. }
  178. }
  179. }, 100,mes_heart_beat_cycle*1000);
  180. //心跳显示图标
  181. if(heartBeatIconTimer!=null) {
  182. heartBeatIconTimer.cancel();
  183. }
  184. heartBeatIconTimer = new Timer();
  185. heartBeatIconTimer.schedule(new TimerTask() {
  186. public void run() {
  187. if(tcp_connect_flag) {
  188. if(iconREDFlag) {
  189. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  190. iconREDFlag = false;
  191. }else {
  192. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
  193. iconREDFlag = true;
  194. }
  195. heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
  196. heart_beat_menu.repaint();
  197. }else {
  198. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  199. heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
  200. heart_beat_menu.repaint();
  201. //若未连接则尝试连接
  202. if(nettyClient!=null&&!tcp_connect_flag){
  203. System.out.println("TCP已断开");
  204. //TCP重新同步连接
  205. if(!connect_request_flag) {
  206. //System.out.println("TCP重新同步连接");
  207. //设置TCP请求状态,只重新同步连接一次
  208. connect_request_flag = true;
  209. DataUtil.synrTcp(nettyClient,mes_gw);
  210. }
  211. }
  212. }
  213. }
  214. }, 100,mes_heart_icon_cycle*1000);
  215. }
  216. //设置tcp连接状态显示
  217. public static void setTcpStatus() {
  218. if(tcp_connect_flag) {
  219. status_menu.setText("已连接MES服务器");
  220. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  221. heart_beat_menu.repaint();
  222. }else {
  223. status_menu.setText("未连接MES服务器");
  224. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  225. heart_beat_menu.repaint();
  226. }
  227. }
  228. public static void initWarehouseData(){
  229. resetScanA();
  230. }
  231. public static void resetScanA() {
  232. MesClient.fxlabel.setVisible(false);
  233. // 信号重置
  234. RobotUtil.setAllowFeeding(s7PLC,false);
  235. RobotUtil.setAllowBlanking(s7PLC,false);
  236. MesClient.status_menu.setText("请扫工件码");
  237. MesClient.product_sn.setText("");
  238. MesClient.product_sn_LB.setText("");
  239. MesClient.bind_lb_result = false;
  240. MesClient.work_status = 0;
  241. MesClient.check_quality_result = false;
  242. MesClient.index = 0;
  243. updateMaterailData();
  244. // shiftUserCheck();
  245. }
  246. public static int userLoginHours;//用户登录所处小时
  247. //换班用户信息检查
  248. private static void shiftUserCheck() {
  249. LocalDateTime now = LocalDateTime.now();
  250. // 判断时间范围
  251. if (userLoginHours >= 8 && userLoginHours < 20) {
  252. int hour = now.getHour();
  253. if (hour >= 20 || hour < 8) {
  254. logoff();
  255. }
  256. } else {
  257. int hour = now.getHour();
  258. if (hour >= 8 && hour < 20) {
  259. logoff();
  260. }
  261. }
  262. }
  263. //获取用户20位
  264. public static void getUser() {
  265. user20 = user_menu.getText().toString();
  266. String space_tmp1 = "";
  267. if(user20.length()<20) {
  268. for(int i=0;i<20-user20.length();i++) {
  269. space_tmp1 = space_tmp1 + " ";
  270. }
  271. }
  272. user20 = user20 + space_tmp1;
  273. }
  274. //获取barcode内容36位
  275. public static String getBarcode(String barcodeTmp) {
  276. String barcodeRet = barcodeTmp;
  277. if(barcodeTmp.equalsIgnoreCase("")) {
  278. return "";
  279. }else {
  280. if(barcodeTmp.length()<36) {
  281. String space = "";
  282. for(int i=0;i<36-barcodeTmp.length();i++) {
  283. space = space + " ";
  284. }
  285. barcodeRet = barcodeTmp + space;
  286. }
  287. }
  288. return barcodeRet;
  289. }
  290. public static void scanBarcode() {
  291. if(work_status == 1){
  292. JOptionPane.showMessageDialog(mesClientFrame,"工作中,勿扫码","提示窗口", JOptionPane.INFORMATION_MESSAGE);
  293. return;
  294. }
  295. String scanBarcodeTitle = "";
  296. switch(scan_type) {
  297. case 1:
  298. product_sn.setText("");
  299. scanBarcodeTitle = "请扫工件码";
  300. break;
  301. }
  302. //弹窗扫工件码
  303. String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
  304. if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")) {
  305. //获取用户
  306. getUser();
  307. //获取扫码内容36位
  308. String barcode36 = getBarcode(scanBarcode);//处理36为码
  309. //工位号
  310. String gw = "";
  311. switch(scan_type) {
  312. case 1:
  313. product_sn.setText(scanBarcode);
  314. break;
  315. }
  316. //刷新界面
  317. mesClientFrame.repaint();
  318. if(!tcp_connect_flag) {
  319. MesClient.setMenuStatus("设备未连接Mes服务器",-1);
  320. // JOptionPane.showMessageDialog(mesClientFrame,"设备未连接Mes服务器","提示窗口", JOptionPane.INFORMATION_MESSAGE);
  321. return;
  322. }
  323. // 查询工件质量
  324. Boolean sendret = DataUtil.checkQuality(nettyClient,barcode36,user20);
  325. if(!sendret){
  326. MesClient.setMenuStatus("消息发送失败,请重试",-1);
  327. return;
  328. }
  329. }else {
  330. MesClient.setMenuStatus("请扫工件码,请重试",-1);
  331. return;
  332. }
  333. }
  334. //
  335. public static void scanBarcode2() {
  336. // 判断工件码是不是空的
  337. if(work_status != 1) {
  338. setMenuStatus("未扫工件码!", 1);
  339. return;
  340. }
  341. // 绑定冷板
  342. //弹窗扫工件码
  343. String scanBarcode = JOptionPane.showInputDialog(null, "冷板码");
  344. if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")) {
  345. JSONObject retObj = DataUtil.bindWarehouseApi(product_sn.getText(),"400006",scanBarcode,user20);
  346. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  347. bind_lb_result = true;
  348. product_sn_LB.setText(scanBarcode);
  349. log.info("bind_lb_result2:"+bind_lb_result);
  350. Boolean reg = DataUtil.sendQuality(MesClient.nettyClient, MesClient.product_sn.getText(), "OK",MesClient.user20);
  351. if (!reg){
  352. setMenuStatus("报文发送异常", -1);
  353. return;
  354. }
  355. }else{
  356. setMenuStatus("绑定失败!", 1);
  357. return;
  358. }
  359. }
  360. }
  361. public static void logoff() {
  362. welcomeWin.setVisible(true);
  363. mesClientFrame.setVisible(false);
  364. nettyClient = null;
  365. // if(heartBeatTimer!=null) {
  366. // heartBeatTimer.cancel();
  367. // }
  368. // if(heartBeatIconTimer!=null) {
  369. // heartBeatIconTimer.cancel();
  370. // }
  371. tcp_connect_flag = false;
  372. connect_request_flag = false;
  373. }
  374. public static ImageIcon imageGreen;
  375. public static ImageIcon imageGray;
  376. public static JLabel feedinglabel;
  377. public static JLabel feedinglabel2;
  378. public static JLabel feedingmeslabel;
  379. public static JLabel runlabel; //运行反馈,
  380. public static JLabel blankinglabel; // 下料反馈
  381. public static JLabel blankingmeslabel; // 下料MES反馈
  382. public MesClient() {
  383. setIconImage(Toolkit.getDefaultToolkit().getImage(MesClient.class.getResource("/bg/logo.png")));
  384. setTitle("MES系统客户端:"+mes_gw + "- " + mes_gw_des);
  385. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  386. setBounds(0, 0, 1024, 768);
  387. JMenuBar menuBar = new JMenuBar();
  388. menuBar.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 26));
  389. setJMenuBar(menuBar);
  390. JMenu fileMenu = new JMenu("用户");
  391. fileMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/user.png")));
  392. fileMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  393. menuBar.add(fileMenu);
  394. JMenuItem exitMenuItem = new JMenuItem("退出");
  395. exitMenuItem.setIcon(new ImageIcon(MesClient.class.getResource("/bg/logoff.png")));
  396. exitMenuItem.setFont(new Font("微软雅黑", Font.PLAIN, 22));
  397. fileMenu.add(exitMenuItem);
  398. exitMenuItem.addMouseListener(new MouseAdapter() {
  399. @Override
  400. public void mousePressed(MouseEvent e) {//只能检测到mousePressed事件
  401. super.mouseClicked(e);
  402. //dispose();
  403. logoff();
  404. }
  405. });
  406. JMenu settingMenu = new JMenu("交互设置");
  407. //settingMenu.setVisible(false);
  408. settingMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")));
  409. settingMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  410. menuBar.add(settingMenu);
  411. JMenuItem resetTcpMenu = new JMenuItem("\u91CD\u8FDEMES");
  412. resetTcpMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  413. resetTcpMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  414. resetTcpMenu.addMouseListener(new MouseAdapter() {
  415. @Override
  416. public void mousePressed(MouseEvent e) {
  417. super.mouseClicked(e);
  418. //重连mes
  419. nettyClient.future.channel().close();
  420. }
  421. });
  422. settingMenu.add(resetTcpMenu);
  423. JMenuItem resetTcpMenu2 = new JMenuItem("刷新工件");
  424. resetTcpMenu2.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  425. resetTcpMenu2.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  426. resetTcpMenu2.addMouseListener(new MouseAdapter() {
  427. @Override
  428. public void mousePressed(MouseEvent e) {
  429. super.mouseClicked(e);
  430. resetScanA();
  431. }
  432. });
  433. settingMenu.add(resetTcpMenu2);
  434. JMenuItem resetTcpMenu_1 = new JMenuItem("重新读码");
  435. resetTcpMenu_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  436. resetTcpMenu_1.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  437. resetTcpMenu_1.addMouseListener(new MouseAdapter() {
  438. @Override
  439. public void mousePressed(MouseEvent e) {
  440. super.mouseClicked(e);
  441. try {
  442. String sn = "";
  443. boolean hgA = RobotUtil.getFeedingA(s7PLC);
  444. boolean hgB = RobotUtil.getFeedingB(s7PLC);
  445. if (!hgA && !hgB) {
  446. sn = "";
  447. }
  448. if (hgA) {
  449. sn = RobotUtil.getProductSnA(s7PLC);
  450. }else if (hgB) {
  451. sn = RobotUtil.getProductSnB(s7PLC);
  452. }else {
  453. sn = RobotUtil.getProductSn(s7PLC);
  454. }
  455. log.info("工件码:"+sn);
  456. if (sn == null || sn.trim().isEmpty() || "".equals(sn)) {
  457. setMenuStatus("扫码结果为空", -1);
  458. return;
  459. }else{
  460. sn = sn.trim();
  461. product_sn.setText(sn);
  462. String barcode36 = getBarcode(sn);
  463. Boolean checkQualityResult = DataUtil.checkQuality(MesClient.nettyClient, barcode36,MesClient.user20);
  464. if (!checkQualityResult){
  465. setMenuStatus("消息发送失败,请重试",-1);
  466. }
  467. }
  468. } catch (Exception e2) {
  469. log.error("读取 PLC 工件码失败", e2);
  470. setMenuStatus("读取 PLC 失败", -1);
  471. }
  472. }
  473. });
  474. settingMenu.add(resetTcpMenu_1);
  475. //允许上料
  476. JMenuItem allow_up_material = new JMenuItem("允许上料");
  477. allow_up_material.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  478. allow_up_material.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  479. allow_up_material.addMouseListener(new MouseAdapter() {
  480. @Override
  481. public void mousePressed(MouseEvent e) {
  482. super.mouseClicked(e);
  483. // 弹框输入密码,如果输入的为”503833“即可允许上料
  484. String input = JOptionPane.showInputDialog(null, "请输入密码");
  485. if (!input.equalsIgnoreCase("503833")) {
  486. JOptionPane.showMessageDialog(mesClientFrame, "密码错误", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
  487. return;
  488. }
  489. // 允许上料
  490. MesClient.s7PLC.writeBoolean("DB503.0.2", true);
  491. }
  492. });
  493. // settingMenu.add(allow_up_material);
  494. // 允许下料
  495. JMenuItem allow_down_material = new JMenuItem("允许下料");
  496. allow_down_material.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  497. allow_down_material.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  498. allow_down_material.addMouseListener(new MouseAdapter() {
  499. @Override
  500. public void mousePressed(MouseEvent e) {
  501. super.mouseClicked(e);
  502. // 弹框输入密码,如果输入的为”503833“即可允许下料
  503. String input = JOptionPane.showInputDialog(null, "请输入密码");
  504. if (!input.equalsIgnoreCase("503833")) {
  505. JOptionPane.showMessageDialog(mesClientFrame, "密码错误", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
  506. return;
  507. }
  508. MesClient.s7PLC.writeBoolean("DB503.0.5", true);
  509. }
  510. });
  511. // settingMenu.add(allow_down_material);
  512. // 重置信号
  513. JMenuItem reset_signal = new JMenuItem("重置信号");
  514. reset_signal.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  515. reset_signal.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  516. reset_signal.addMouseListener(new MouseAdapter() {
  517. @Override
  518. public void mousePressed(MouseEvent e) {
  519. super.mouseClicked(e);
  520. // 弹框输入密码,如果输入的为”503833“即可允许下料
  521. String input = JOptionPane.showInputDialog(null, "请输入密码");
  522. if (!input.equalsIgnoreCase("503833")) {
  523. JOptionPane.showMessageDialog(mesClientFrame, "密码错误", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
  524. return;
  525. }
  526. MesClient.s7PLC.writeBoolean("DB503.0.2", false);
  527. MesClient.s7PLC.writeBoolean("DB503.0.5", false);
  528. }
  529. });
  530. // settingMenu.add(reset_signal);
  531. contentPane = new JPanel();
  532. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  533. setContentPane(contentPane);
  534. contentPane.setLayout(new BorderLayout(0, 0));
  535. JToolBar toolBar = new JToolBar();
  536. contentPane.add(toolBar, BorderLayout.NORTH);
  537. JLabel equipment_statu_label = new JLabel("状态:");
  538. equipment_statu_label.setHorizontalAlignment(SwingConstants.CENTER);
  539. equipment_statu_label.setForeground(Color.BLACK);
  540. equipment_statu_label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  541. equipment_statu_label.setBackground(Color.LIGHT_GRAY);
  542. toolBar.add(equipment_statu_label);
  543. status_menu = new JButton("设备未连接MES服务器");
  544. if(tcp_connect_flag) {
  545. status_menu.setText("已连接MES服务器");
  546. status_menu.setForeground(Color.GREEN);
  547. }else {
  548. status_menu.setText("未连接MES服务器");
  549. status_menu.setForeground(Color.DARK_GRAY);
  550. }
  551. status_menu.addActionListener(new ActionListener() {
  552. public void actionPerformed(ActionEvent e) {
  553. }
  554. });
  555. status_menu.setForeground(Color.GREEN);
  556. status_menu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  557. status_menu.setBackground(Color.BLACK);
  558. toolBar.add(status_menu);
  559. JLabel space_1 = new JLabel(" ");
  560. toolBar.add(space_1);
  561. JLabel heart_beat_status_label = new JLabel("心跳:");
  562. heart_beat_status_label.setHorizontalAlignment(SwingConstants.CENTER);
  563. heart_beat_status_label.setForeground(Color.BLACK);
  564. heart_beat_status_label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  565. heart_beat_status_label.setBackground(Color.LIGHT_GRAY);
  566. toolBar.add(heart_beat_status_label);
  567. heart_beat_menu = new JButton("2024-02-20 23:20:10");
  568. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
  569. heart_beat_menu.setForeground(Color.GREEN);
  570. heart_beat_menu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  571. heart_beat_menu.setBackground(Color.BLACK);
  572. toolBar.add(heart_beat_menu);
  573. JLabel space_2 = new JLabel(" ");
  574. toolBar.add(space_2);
  575. JLabel user_status_label = new JLabel("登录用户:");
  576. user_status_label.setHorizontalAlignment(SwingConstants.CENTER);
  577. user_status_label.setForeground(Color.BLACK);
  578. user_status_label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  579. user_status_label.setBackground(Color.LIGHT_GRAY);
  580. toolBar.add(user_status_label);
  581. user_menu = new JButton("JinJuShi");
  582. user_menu.setForeground(Color.GREEN);
  583. user_menu.setFont(new Font("微软雅黑", Font.PLAIN, 22));
  584. user_menu.setBackground(Color.BLACK);
  585. toolBar.add(user_menu);
  586. JLabel space_3 = new JLabel(" ");
  587. toolBar.add(space_3);
  588. JLabel space_4 = new JLabel(" ");
  589. toolBar.add(space_4);
  590. tabbedPane = new JTabbedPane(JTabbedPane.TOP);
  591. tabbedPane.setMinimumSize(new Dimension(400, 50));
  592. tabbedPane.setFont(new Font("宋体", Font.BOLD, 22));
  593. contentPane.add(tabbedPane);
  594. //首页
  595. JPanel indexPanelA = new JPanel();
  596. indexScrollPaneA = new JScrollPane(indexPanelA);
  597. indexPanelA.setLayout(null);
  598. //前方加入提示词
  599. JLabel index_label = new JLabel("工件码:");
  600. index_label.setHorizontalAlignment(SwingConstants.CENTER);
  601. index_label.setForeground(Color.BLACK);
  602. index_label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  603. index_label.setBounds(81, 10, 100, 50);
  604. indexPanelA.add(index_label);
  605. product_sn = new JTextField();
  606. product_sn.setHorizontalAlignment(SwingConstants.CENTER);
  607. product_sn.setEditable(false);
  608. product_sn.setFont(new Font("微软雅黑", Font.PLAIN, 28));
  609. product_sn.setBounds(81, 70, 602, 70);
  610. indexPanelA.add(product_sn);
  611. product_sn.setColumns(10);
  612. //冷板码提示词
  613. JLabel index_label_LB = new JLabel("冷板码:");
  614. index_label_LB.setHorizontalAlignment(SwingConstants.CENTER);
  615. index_label_LB.setForeground(Color.BLACK);
  616. index_label_LB.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  617. index_label_LB.setBounds(81, 150, 100, 50);
  618. indexPanelA.add(index_label_LB);
  619. //下方增加一个绑定冷板的输入框
  620. product_sn_LB = new JTextField();
  621. product_sn_LB.setHorizontalAlignment(SwingConstants.CENTER);
  622. product_sn_LB.setEditable(false);
  623. product_sn_LB.setFont(new Font("微软雅黑", Font.PLAIN, 28));
  624. product_sn_LB.setBounds(81, 200, 602, 70);
  625. indexPanelA.add(product_sn_LB);
  626. product_sn_LB.setColumns(10);
  627. f_scan_data_bt_1 = new JButton("扫码");
  628. f_scan_data_bt_1.addActionListener(new ActionListener() {
  629. public void actionPerformed(ActionEvent e) {
  630. scan_type = 1;
  631. scanBarcode();
  632. }
  633. });
  634. f_scan_data_bt_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/scan_barcode.png")));
  635. f_scan_data_bt_1.setFont(new Font("微软雅黑", Font.PLAIN, 32));
  636. f_scan_data_bt_1.setBounds(693, 70, 198, 70);
  637. // 绑定冷板按钮
  638. f_scan_data_bt_2 = new JButton("绑定");
  639. f_scan_data_bt_2.addActionListener(new ActionListener() {
  640. public void actionPerformed(ActionEvent e) {
  641. scan_type = 2;
  642. scanBarcode2();
  643. }
  644. });
  645. f_scan_data_bt_2.setIcon(new ImageIcon(MesClient.class.getResource("/bg/scan_barcode.png")));
  646. f_scan_data_bt_2.setFont(new Font("微软雅黑", Font.PLAIN, 32));
  647. f_scan_data_bt_2.setBounds(693, 200, 198, 70);
  648. indexPanelA.add(f_scan_data_bt_2);
  649. // indexPanelA.add(f_scan_data_bt_1);
  650. // String[] hjtitles = new String[]{"焊机1","焊机2","焊机3"};
  651. // String[] hjvals = new String[]{"HJ001","HJ002","HJ003"};
  652. // mesRadioHj = new MesRadio(hjtitles,hjvals);
  653. // mesRadioHj.setSize(500,50);
  654. // mesRadioHj.setBounds(190,170,500,50);
  655. // indexPanelA.add(mesRadioHj);
  656. fxlabel = new JLabel("该工件为返修件,请仔细检查");
  657. fxlabel.setFont(new Font("微软雅黑", Font.PLAIN, 38));
  658. fxlabel.setBounds(81, 170, 810, 70);
  659. fxlabel.setForeground(Color.RED);
  660. fxlabel.setHorizontalAlignment(SwingConstants.CENTER);
  661. fxlabel.setVisible(false);
  662. indexPanelA.add(fxlabel);
  663. finish_ok_bt = new JButton("OK");
  664. finish_ok_bt.setEnabled(false);
  665. finish_ok_bt.addActionListener(new ActionListener() {
  666. public void actionPerformed(ActionEvent e) {
  667. if(work_status == 1 && check_quality_result){
  668. String sn = getBarcode(product_sn.getText());
  669. if(sn.isEmpty()){
  670. MesClient.setMenuStatus("工件码为空,请重试",-1);
  671. return;
  672. }
  673. getUser();
  674. String qret = "OK";
  675. Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20);
  676. if(!sendret){
  677. MesClient.setMenuStatus("消息发送失败,请重试",-1);
  678. return;
  679. }else{
  680. // MesClient.resetScanA();
  681. // MesClient.scan_type = 1;
  682. // MesClient.scanBarcode();
  683. // MesClient.setMenuStatus("结果提交成功,请扫下一件",0);
  684. }
  685. }
  686. }
  687. });
  688. finish_ok_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
  689. finish_ok_bt.setFont(new Font("微软雅黑", Font.PLAIN, 32));
  690. finish_ok_bt.setBounds(185, 291, 240, 80);
  691. finish_ok_bt.setEnabled(false);
  692. // indexPanelA.add(finish_ok_bt);
  693. finish_ng_bt = new JButton("NG");
  694. finish_ng_bt.setEnabled(false);
  695. finish_ng_bt.addActionListener(new ActionListener() {
  696. public void actionPerformed(ActionEvent e) {
  697. if(work_status == 1 && check_quality_result){
  698. String sn = getBarcode(product_sn.getText());
  699. if(sn.isEmpty()){
  700. MesClient.setMenuStatus("工件码为空,请重试",-1);
  701. return;
  702. }
  703. getUser();
  704. String qret = "NG";
  705. Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20);
  706. if(!sendret){
  707. MesClient.setMenuStatus("消息发送失败,请重试",-1);
  708. return;
  709. }else{
  710. // MesClient.resetScanA();
  711. // MesClient.scan_type = 1;
  712. // MesClient.scanBarcode();
  713. // MesClient.setMenuStatus("结果提交成功,请扫下一件",0);
  714. }
  715. }
  716. }
  717. });
  718. finish_ng_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ng_bg.png")));
  719. finish_ng_bt.setFont(new Font("微软雅黑", Font.PLAIN, 32));
  720. finish_ng_bt.setBounds(508, 291, 240, 80);
  721. finish_ng_bt.setEnabled(false);
  722. // indexPanelA.add(finish_ng_bt);
  723. imageGreen = new ImageIcon(MesClient.class.getResource("/bg/green_dot.png"));
  724. imageGreen.setImage(imageGreen.getImage().getScaledInstance(20, 20, Image.SCALE_SMOOTH));
  725. imageGray = new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png"));
  726. imageGray.setImage(imageGray.getImage().getScaledInstance(20, 20, Image.SCALE_SMOOTH));
  727. feedingmeslabel = new JLabel("MES允许上料");
  728. feedingmeslabel.setHorizontalAlignment(SwingConstants.LEFT);
  729. feedingmeslabel.setIcon(imageGreen);
  730. feedingmeslabel.setForeground(Color.BLACK);
  731. feedingmeslabel.setBounds(30, 440, 200, 30);
  732. feedingmeslabel.addMouseListener(new MouseAdapter() {
  733. public void mouseClicked(MouseEvent e) {
  734. // 弹框输入密码,如果输入的为”503833“即可允许上料
  735. String input = JOptionPane.showInputDialog(null, "请输入密码");
  736. if (!input.equalsIgnoreCase("503833")) {
  737. JOptionPane.showMessageDialog(mesClientFrame, "密码错误", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
  738. return;
  739. }
  740. boolean ret = RobotUtil.getAllowFeeding(s7PLC);
  741. int choice = JOptionPane.showConfirmDialog(null, "确定修改MES允许上料结果为"+(ret?"false":"true")+"吗?", "操作确认", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
  742. if (choice == JOptionPane.YES_OPTION) {
  743. RobotUtil.setAllowFeeding(s7PLC,!ret);
  744. }
  745. }
  746. });
  747. indexPanelA.add(feedingmeslabel);
  748. blankingmeslabel = new JLabel("MES下料反馈");
  749. blankingmeslabel.setHorizontalAlignment(SwingConstants.LEFT);
  750. blankingmeslabel.setIcon(imageGreen);
  751. blankingmeslabel.setForeground(Color.BLACK);
  752. blankingmeslabel.setBounds(240, 440, 200, 30);
  753. indexPanelA.add(blankingmeslabel);
  754. blankingmeslabel.addMouseListener(new MouseAdapter() {
  755. public void mouseClicked(MouseEvent e) {
  756. // 弹框输入密码,如果输入的为”503833“即可允许上料
  757. String input = JOptionPane.showInputDialog(null, "请输入密码");
  758. if (!input.equalsIgnoreCase("503833")) {
  759. JOptionPane.showMessageDialog(mesClientFrame, "密码错误", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
  760. return;
  761. }
  762. boolean ret = RobotUtil.getAllowBlanking(s7PLC);
  763. int choice = JOptionPane.showConfirmDialog(null, "确定修改MES下料反馈结果为"+(ret?"false":"true")+"吗?", "操作确认", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
  764. if (choice == JOptionPane.YES_OPTION) {
  765. RobotUtil.setAllowBlanking(s7PLC,!ret);
  766. }
  767. }
  768. });
  769. feedinglabel = new JLabel("抓手A上料");
  770. feedinglabel.setHorizontalAlignment(SwingConstants.LEFT);
  771. feedinglabel.setIcon(imageGreen);
  772. feedinglabel.setForeground(Color.BLACK);
  773. feedinglabel.setBounds(30, 480, 200, 30);
  774. indexPanelA.add(feedinglabel);
  775. feedinglabel2 = new JLabel("抓手B上料");
  776. feedinglabel2.setHorizontalAlignment(SwingConstants.LEFT);
  777. feedinglabel2.setIcon(imageGreen);
  778. feedinglabel2.setForeground(Color.BLACK);
  779. feedinglabel2.setBounds(240, 480, 200, 30);
  780. indexPanelA.add(feedinglabel2);
  781. runlabel = new JLabel("上料完成");
  782. runlabel.setHorizontalAlignment(SwingConstants.LEFT);
  783. runlabel.setIcon(imageGreen);
  784. runlabel.setForeground(Color.BLACK);
  785. runlabel.setBounds(450, 480, 200, 30);
  786. indexPanelA.add(runlabel);
  787. blankinglabel = new JLabel("加工完成");
  788. blankinglabel.setHorizontalAlignment(SwingConstants.LEFT);
  789. blankinglabel.setIcon(imageGreen);
  790. blankinglabel.setForeground(Color.BLACK);
  791. blankinglabel.setBounds(660, 480, 200, 30);
  792. indexPanelA.add(blankinglabel);
  793. tabbedPane.addTab("工作面板", new ImageIcon(MesClient.class.getResource("/bg/a_side.png")), indexScrollPaneA, null);
  794. tabbedPane.setEnabledAt(0, true);
  795. // searchScrollPane = new JScrollPane((Component) null);
  796. indexPanelC = new JPanel();
  797. searchScrollPaneDj = new JScrollPane(indexPanelC);
  798. indexPanelC.setLayout(null);
  799. tabbedPane.addTab("开班点检", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPaneDj, null);
  800. indexPanelB = new JPanel();
  801. searchScrollPane = new JScrollPane(indexPanelB);
  802. indexPanelB.setLayout(null);
  803. tabbedPane.addTab("工作记录", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPane, null);
  804. indexPanelE = new JPanel();
  805. searchScrollPaneC = new JScrollPane(indexPanelE);
  806. indexPanelE.setLayout(null);
  807. tabbedPane.addTab("胶水寿命", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPaneC, null);
  808. tabbedPane.addChangeListener(new ChangeListener() {
  809. @Override
  810. public void stateChanged(ChangeEvent e) {
  811. JTabbedPane tabbedPane = (JTabbedPane) e.getSource();
  812. int selectedIndex = tabbedPane.getSelectedIndex();
  813. System.out.println("selectedIndex:"+selectedIndex);
  814. if(selectedIndex == 1){
  815. }
  816. }
  817. });
  818. }
  819. //页面菜单状态
  820. public static void setMenuStatus(String msg,int error){
  821. if(error == 0){
  822. MesClient.status_menu.setForeground(Color.GREEN);
  823. }else{
  824. MesClient.status_menu.setForeground(Color.RED);
  825. }
  826. MesClient.status_menu.setText(msg);
  827. }
  828. public static void getMaterailData(){
  829. try{
  830. JSONObject retObj = DataUtil.getBindMaterail();
  831. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  832. java.util.List<BindMaterialResp> arrs = retObj.getList("data",BindMaterialResp.class);
  833. int i = 0;
  834. rowData = new Object[arrs.size()][7];
  835. for (BindMaterialResp bindMaterialResp:arrs){
  836. rowData[i][0] = bindMaterialResp.getMaterialTitle();
  837. rowData[i][1] = bindMaterialResp.getBatchSn();
  838. rowData[i][2] = bindMaterialResp.getLastTimes();
  839. rowData[i][3] = "";
  840. rowData[i][4] = bindMaterialResp.getCraft();
  841. rowData[i][5] = bindMaterialResp.getMaterialId();
  842. rowData[i][6] = bindMaterialResp.getType();
  843. i++;
  844. }
  845. bindBatchPanel();
  846. }
  847. }catch (Exception e){
  848. log.info(e.getMessage());
  849. }
  850. }
  851. public static void updateMaterailData(){
  852. try{
  853. JSONObject retObj = DataUtil.getBindMaterail();
  854. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  855. List<BindMaterialResp> arrs = retObj.getList("data",BindMaterialResp.class);
  856. int i = 0;
  857. for (BindMaterialResp bindMaterialResp:arrs){
  858. rowData[i][0] = bindMaterialResp.getMaterialTitle();
  859. rowData[i][1] = bindMaterialResp.getBatchSn();
  860. rowData[i][2] = bindMaterialResp.getLastTimes();
  861. rowData[i][3] = "";
  862. rowData[i][4] = bindMaterialResp.getCraft();
  863. rowData[i][5] = bindMaterialResp.getMaterialId();
  864. rowData[i][6] = bindMaterialResp.getType();
  865. i++;
  866. }
  867. MesClient.table.repaint();
  868. }
  869. }catch (Exception e){
  870. log.info(e.getMessage());
  871. }
  872. }
  873. // 绑定物料批次码
  874. public static void scanBatchSn(BindMaterialResp bindMaterialResp) {
  875. //弹窗扫工件码
  876. String scanBarcodeTitle = "请扫物料:"+bindMaterialResp.getMaterialTitle();
  877. String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
  878. if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")) {
  879. JSONObject retObj = DataUtil.saveBindMaterail(scanBarcode,bindMaterialResp.getCraft(),bindMaterialResp.getMaterialId(),bindMaterialResp.getType());
  880. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  881. MesClient.setMenuStatus("扫物料:"+bindMaterialResp.getMaterialTitle()+"成功",0);
  882. updateMaterailData();
  883. }else{
  884. if(retObj.get("result")==null){
  885. MesClient.setMenuStatus("请求失败,请重试",-1);
  886. }else{
  887. if(retObj.get("result").toString().equalsIgnoreCase("false")){
  888. MesClient.setMenuStatus(retObj.getString("message"),-1);
  889. }
  890. }
  891. }
  892. }
  893. }
  894. public static void bindBatchPanel(){
  895. JPanel indexPanelBB = new JPanel();
  896. JPanel panel = new JPanel();
  897. panel.setBounds(0, 0, 990, 550);
  898. // panel.setBounds(81, 50, 810, 479);
  899. indexPanelBB.add(panel);
  900. panel.setLayout(new GridLayout(0, 1, 0, 0));
  901. table = new JTable(rowData, columnNames){
  902. public boolean isCellEditable(int row, int column) {
  903. if(column == 3){
  904. return true;
  905. }
  906. return false;
  907. }
  908. };
  909. table.setRowHeight(40);
  910. table.setEnabled(true);
  911. table.setFont(new Font("微软雅黑", Font.PLAIN, 14));
  912. table.getColumnModel().getColumn(3).setCellRenderer(new TableCellRendererButton());
  913. table.getColumnModel().getColumn(3).setCellEditor(new TableCellEditorButton());
  914. JScrollPane scrollPane = new JScrollPane(table);
  915. panel.add(scrollPane);
  916. JScrollPane indexScrollPaneB = new JScrollPane(indexPanelBB);
  917. indexPanelBB.setLayout(null);
  918. tabbedPane.addTab("绑定物料", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), indexScrollPaneB, null);
  919. }
  920. // 开启发送结果定时任务
  921. public static void startUpdateQualityTimer(){
  922. // 创建异步线程池
  923. ExecutorService executorService = Executors.newSingleThreadExecutor();
  924. // 提交任务
  925. executorService.submit(() -> {
  926. log.info("异步任务执行中...");
  927. // 模拟耗时操作
  928. try {
  929. while (true){
  930. try {
  931. // 确保连接已经打开
  932. if (JdbcUtils.conn == null || JdbcUtils.conn.isClosed()) {
  933. JdbcUtils.openConnection();
  934. }
  935. Statement statement = JdbcUtils.conn.createStatement();
  936. String selectSql = "SELECT id, bw FROM submit_record\n" +
  937. "WHERE state = 0 ORDER BY id DESC LIMIT 10";
  938. String updateSql = "UPDATE submit_record \n" +
  939. "SET state = '1'\n" +
  940. "WHERE id = ";
  941. ResultSet rs = statement.executeQuery(selectSql);
  942. while(rs.next()){
  943. int id = rs.getInt("id");
  944. String bw = rs.getString("bw");
  945. // 发送请求
  946. String url = "http://"+MesClient.mes_server_ip+":8980/js/a/mes/mesProductRecord/updateQualityByTiming";
  947. log.info("质量:"+bw);
  948. String s = HttpUtils.sendPostRequestJson(url, bw );
  949. log.info("结果:"+s);
  950. Boolean result = JSONObject.parseObject(s).getBoolean("result");
  951. if(result) {
  952. // 更改状态为 1
  953. statement.executeUpdate(updateSql + id);
  954. }
  955. }
  956. rs.close();
  957. statement.close();
  958. } catch (Exception e) {
  959. log.info(e.getMessage());
  960. }
  961. try {
  962. Thread.sleep(2000);
  963. }catch (Exception e){
  964. log.info(e.getMessage());
  965. }
  966. }
  967. } catch (Exception e) {
  968. log.info(e.getMessage());
  969. }
  970. log.info("异步任务执行完毕");
  971. });
  972. }
  973. // plc交互定时任务
  974. public static java.util.Timer plcTimer;
  975. // 程序逻辑流程:0:等待扫码信号
  976. public static Integer index = 0;
  977. public static void startPlcTimer(){
  978. if (plcTimer != null){
  979. plcTimer.cancel();
  980. plcTimer = null;
  981. }
  982. plcTimer = new java.util.Timer();
  983. plcTimer.schedule(new TimerTask() {
  984. @Override
  985. public void run() {
  986. if(!MesClient.sessionid.isEmpty()) { // 必须先登录
  987. Boolean feedingRetA = RobotUtil.getFeedingA(s7PLC);
  988. Boolean feedingRetB = RobotUtil.getFeedingB(s7PLC);
  989. Boolean feedingFinish = RobotUtil.getFeedingFinish(s7PLC);
  990. Boolean workFinish = RobotUtil.getWorkFinish(s7PLC);
  991. Boolean allowFeeding = RobotUtil.getAllowFeeding(s7PLC);
  992. Boolean allowBlanking = RobotUtil.getAllowBlanking(s7PLC);
  993. feedinglabel.setIcon(feedingRetA ? imageGreen : imageGray);
  994. feedinglabel2.setIcon(feedingRetB ? imageGreen : imageGray);
  995. runlabel.setIcon(feedingFinish ? imageGreen : imageGray);
  996. blankinglabel.setIcon(workFinish ? imageGreen : imageGray);
  997. feedingmeslabel.setIcon(allowFeeding ? imageGreen : imageGray);
  998. blankingmeslabel.setIcon(allowBlanking ? imageGreen : imageGray);
  999. log.info("index:"+index);
  1000. log.info("feedingRetA:"+feedingRetA);
  1001. log.info("feedingRetB:"+feedingRetB);
  1002. log.info("feedingFinish:"+feedingFinish);
  1003. log.info("workFinish:"+workFinish);
  1004. log.info("allowFeeding:"+allowFeeding);
  1005. log.info("allowBlanking:"+allowBlanking);
  1006. if (index == 0){
  1007. if(allowFeeding){
  1008. RobotUtil.setAllowFeeding(s7PLC, false);
  1009. }
  1010. if(workFinish){
  1011. RobotUtil.setAllowBlanking(s7PLC,true);
  1012. }else{
  1013. RobotUtil.setAllowBlanking(s7PLC,false);
  1014. }
  1015. if(feedingRetA || feedingRetB){
  1016. String sn = "";
  1017. if(feedingRetA){
  1018. sn = RobotUtil.getProductSnA(s7PLC);
  1019. }
  1020. if(feedingRetB){
  1021. sn = RobotUtil.getProductSnB(s7PLC);
  1022. }
  1023. if (sn == null || sn.trim().isEmpty() || "".equals(sn)) {
  1024. setMenuStatus("读码结果为空", -1);
  1025. return;
  1026. }else{
  1027. product_sn.setText(sn);
  1028. String barcode36 = getBarcode(sn);
  1029. Boolean checkQualityResult = DataUtil.checkQuality(MesClient.nettyClient, barcode36,MesClient.user20);
  1030. if (!checkQualityResult){
  1031. setMenuStatus("消息发送失败,请重试",-1);
  1032. }
  1033. }
  1034. }else{
  1035. setMenuStatus("等待上料信号",0);
  1036. }
  1037. }else if(index == 1){
  1038. if(feedingFinish || workFinish || feedingRetA || feedingRetB){
  1039. setMenuStatus("上料完成,开始加工",0);
  1040. index = 2;
  1041. RobotUtil.setAllowFeeding(s7PLC, false);
  1042. }else{
  1043. RobotUtil.setAllowFeeding(s7PLC, true);
  1044. }
  1045. }else if(index == 2){
  1046. if(workFinish || feedingRetA || feedingRetB){ // 提交结果
  1047. // 冷板为空不允许提交
  1048. if (!bind_lb_result){
  1049. setMenuStatus("请先绑定冷板", -1);
  1050. return;
  1051. }
  1052. Boolean reg = DataUtil.sendQuality(MesClient.nettyClient, MesClient.product_sn.getText(), "OK",MesClient.user20);
  1053. if (!reg){
  1054. setMenuStatus("报文发送异常", -1);
  1055. return;
  1056. }
  1057. }
  1058. }
  1059. }
  1060. }
  1061. }, 0, 2500);
  1062. }
  1063. }