MesClient.java 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958
  1. package com.mes.ui;
  2. import com.alibaba.fastjson2.JSON;
  3. import com.alibaba.fastjson2.JSONObject;
  4. import com.github.xingshuangs.iot.protocol.modbus.service.ModbusTcp;
  5. import com.mes.component.MesRadio;
  6. import com.mes.component.MesWebView;
  7. import com.mes.netty.NettyClient;
  8. import com.mes.util.DateLocalUtils;
  9. import com.mes.util.JdbcUtils;
  10. import javafx.embed.swing.JFXPanel;
  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.ActionEvent;
  17. import java.awt.event.ActionListener;
  18. import java.awt.event.MouseAdapter;
  19. import java.awt.event.MouseEvent;
  20. import java.io.BufferedReader;
  21. import java.io.IOException;
  22. import java.io.InputStream;
  23. import java.io.InputStreamReader;
  24. import java.util.*;
  25. import java.util.List;
  26. import java.util.Timer;
  27. public class MesClient extends JFrame {
  28. private static String Drivde = "org.sqlite.JDBC";
  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_tcp_port = 3000; // TCP服务端口
  34. public static int mes_heart_beat_cycle = 10; // 心跳周期
  35. public static int mes_heart_icon_cycle = 1;
  36. public static String mes_line_sn = ""; // 产线编号
  37. //TCP连接
  38. public static NettyClient nettyClient;
  39. //TCP连接状态
  40. public static boolean tcp_connect_flag = false;
  41. //TCP连接请求
  42. public static boolean connect_request_flag = false;
  43. //session
  44. public static String sessionid = "";
  45. public static JPanel contentPane;
  46. public static MesClient mesClientFrame;
  47. public static JTabbedPane tabbedPane;
  48. public static JScrollPane indexScrollPaneA;
  49. public static JScrollPane searchScrollPane;
  50. public static JScrollPane searchScrollPaneDj;
  51. public static Boolean check_quality_result = false;
  52. public static Integer work_status = 0;
  53. public static JButton heart_beat_menu;
  54. public static JButton status_menu;
  55. public static JButton user_menu;
  56. public static int scan_type = 0;
  57. public static JButton finish_ok_bt;
  58. public static JButton finish_ng_bt;
  59. public static JTextField product_sn;
  60. public static JButton f_scan_data_bt_1;
  61. public static String user20 = "";
  62. public static JFrame welcomeWin;
  63. public static JPanel indexPanelB;
  64. public static MesWebView jfxPanel = null;
  65. public static JPanel indexPanelC;
  66. public static MesWebView jfxPanel2 = null;
  67. public static MesRadio mesRadioHj;
  68. public static JTextField param1;
  69. public static JTextField param2;
  70. public static JTextField param3;
  71. public static JTextField param4;
  72. public static ModbusTcp plcA = new ModbusTcp(1, "192.168.1.7");
  73. public static ModbusTcp plcB = new ModbusTcp(1, "192.168.1.8");
  74. // public static ModbusTcp plcA = new ModbusTcp(1, "192.168.1.27");
  75. // public static ModbusTcp plcB = new ModbusTcp(1, "192.168.1.28");
  76. public static Timer cjTimer;
  77. public static Timer cjTimer2;
  78. public static Timer cjTimer3;
  79. public static Short aSetNum = 27;
  80. // public static Short aSetNum = 49;
  81. public static Short sortA = 0;
  82. public static Short aMax = 0;
  83. public static Short aFinish = 0;
  84. public static List<Map> alist = new ArrayList<>();
  85. public static Short bSetNum = 36;
  86. // public static Short bSetNum = 27;
  87. public static Short sortB = 0;
  88. public static Short bMax = 0;
  89. public static List<Map> blist = new ArrayList<>();
  90. public static Short deviceControl = 0; // 0=本地 1=远程
  91. public static Integer tjStatus = 0; // 1=提交失败
  92. public static String tjFlagTextErr = "结果上传MES失败,请重试";
  93. public static String curSn = "";
  94. public static JTable table;
  95. public static Object[] columnNames = { "物料名称", "绑定批次", "剩余次数", "操作" };
  96. public static Object[][] rowData = null;
  97. public static void main(String[] args) {
  98. EventQueue.invokeLater(new Runnable() {
  99. @Override
  100. public void run() {
  101. try{
  102. //读文件配置
  103. readProperty();
  104. // 显示界面
  105. mesClientFrame = new MesClient();
  106. mesClientFrame.setVisible(false);
  107. JdbcUtils.getConn();
  108. welcomeWin = new LoginFarme();
  109. welcomeWin.setVisible(true);
  110. getPlcParam();
  111. upParams();
  112. setDeviceStart();
  113. getMaterailData();
  114. }catch (Exception e){
  115. e.printStackTrace();
  116. }
  117. }
  118. });
  119. }
  120. public static java.util.Timer cjTimer4;
  121. public static void setDeviceStart() {
  122. if(cjTimer4!=null) {
  123. cjTimer4.cancel();
  124. }
  125. cjTimer4 = new Timer();
  126. cjTimer4.schedule(new TimerTask() {
  127. public void run() {
  128. try{
  129. if(work_status == 1){
  130. List<Boolean> yxstatus = plcA.readCoil(3128,1);
  131. if(yxstatus.size() >= 1 && !yxstatus.get(0)){
  132. if(!MesClient.curSn.isEmpty() && MesClient.aMax > 0 && MesClient.aMax == MesClient.sortA){
  133. ModbusUtil.setPowerOff(plcA);
  134. }else{
  135. ModbusUtil.setPowerOn(plcA);
  136. }
  137. }
  138. List<Boolean> yxstatusb = plcB.readCoil(3128,1);
  139. if(yxstatusb.size() >= 1 && !yxstatusb.get(0)){
  140. if(!MesClient.curSn.isEmpty() && MesClient.bMax > 0 && MesClient.bMax == MesClient.sortB){
  141. ModbusUtil.setPowerOff(plcB);
  142. }else{
  143. ModbusUtil.setPowerOn(plcB);
  144. }
  145. }
  146. }else{
  147. List<Boolean> yxstatus = plcA.readCoil(3128,1);
  148. if(yxstatus.size() >= 1 && yxstatus.get(0)){
  149. ModbusUtil.setPowerOff(plcA);
  150. }
  151. List<Boolean> yxstatusb = plcB.readCoil(3128,1);
  152. if(yxstatusb.size() >= 1 && yxstatusb.get(0)){
  153. ModbusUtil.setPowerOff(plcB);
  154. }
  155. }
  156. }catch (Exception e){
  157. e.printStackTrace();
  158. }
  159. }
  160. }, 1000,1000);
  161. }
  162. //读配置文件
  163. private static void readProperty() throws IOException{
  164. String enconding = "UTF-8";
  165. InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
  166. Properties pro = new Properties();
  167. BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
  168. pro.load(br);
  169. mes_gw = pro.getProperty("mes.gw");
  170. // mes_gw_des = pro.getProperty("mes.gw_des");
  171. mes_server_ip = pro.getProperty("mes.server_ip");
  172. mes_tcp_port = Integer.parseInt(pro.getProperty("mes.tcp_port"));
  173. mes_heart_beat_cycle = Integer.parseInt(pro.getProperty("mes.heart_beat_cycle"));
  174. mes_line_sn = pro.getProperty("mes.line_sn");
  175. mes_gw_des = OprnoUtil.getGwDes(mes_line_sn,mes_gw);
  176. System.out.println(mes_gw + ";" + mes_gw_des + ";" + mes_server_ip + ";" + mes_tcp_port + ";" + mes_heart_beat_cycle);
  177. }
  178. public static void getPlcParam() {
  179. if(cjTimer!=null) {
  180. cjTimer.cancel();
  181. }
  182. cjTimer = new Timer();
  183. cjTimer.schedule(new TimerTask() {
  184. public void run() {
  185. try{
  186. if(work_status == 1){
  187. ModbusUtil.getDataA(plcA);
  188. }
  189. }catch (Exception e){
  190. e.printStackTrace();
  191. }
  192. try{
  193. if(work_status == 1){
  194. ModbusUtil.getDataB(plcB);
  195. }
  196. }catch (Exception e){
  197. e.printStackTrace();
  198. }
  199. }
  200. }, 1000,500);
  201. }
  202. public static void getPlcSn() {
  203. if(cjTimer3!=null) {
  204. cjTimer3.cancel();
  205. }
  206. cjTimer3 = new Timer();
  207. cjTimer3.schedule(new TimerTask() {
  208. public void run() {
  209. try{
  210. String cSn = ModbusUtil.getSn(plcA);
  211. if(!cSn.isEmpty()){
  212. if(curSn.isEmpty()){
  213. product_sn.setText(cSn);
  214. curSn = cSn;
  215. //发送AQDW质量询问报文,当收到返回UD才能工作
  216. getUser();
  217. Boolean sendret = DataUtil.checkQuality(nettyClient,curSn,user20);
  218. if(!sendret){
  219. MesClient.setMenuStatus("消息发送失败,请重试",-1);
  220. }
  221. }else if(!curSn.isEmpty() && !cSn.equals(curSn)){
  222. resetScanA();
  223. }
  224. }
  225. }catch (Exception e){
  226. e.printStackTrace();
  227. }
  228. }
  229. }, 1000,1000);
  230. }
  231. public static void upParams() {
  232. if(cjTimer2!=null) {
  233. cjTimer2.cancel();
  234. }
  235. cjTimer2 = new Timer();
  236. cjTimer2.schedule(new TimerTask() {
  237. public void run() {
  238. try{
  239. List<ProdReq> prods = JdbcUtils.getProds();
  240. System.out.println("prods:"+ JSON.toJSONString(prods));
  241. if(prods.size() > 0){
  242. // 定时上传参数
  243. JSONObject retObj = DataUtil.upParams(JSON.toJSONString(prods));
  244. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  245. // 更新sqlite已同步
  246. for(ProdReq prodReq:prods){
  247. JdbcUtils.updateProdSync(prodReq.getId(),1);
  248. }
  249. }
  250. }
  251. }catch (Exception e){
  252. e.printStackTrace();
  253. }
  254. }
  255. }, 1000,30*1000);
  256. }
  257. // 初始化TCP
  258. public static void initTcpConnection() {
  259. try {
  260. if(nettyClient==null) {
  261. //初始化TCP连接
  262. nettyClient = new NettyClient();
  263. //TCP连接状态
  264. tcp_connect_flag = false;
  265. //设置TCP请求状态
  266. connect_request_flag = true;
  267. DataUtil.synrTcp(nettyClient,mes_gw);
  268. }
  269. } catch (Exception e) {
  270. // TODO Auto-generated catch block
  271. e.printStackTrace();
  272. }
  273. }
  274. //启动心跳包程序
  275. public static java.util.Timer heartBeatTimer;
  276. public static java.util.Timer heartBeatIconTimer;
  277. public static boolean iconREDFlag = true;
  278. public static void startHeartBeatTimer() {
  279. if(heartBeatTimer!=null) {
  280. heartBeatTimer.cancel();
  281. }
  282. heartBeatTimer = new java.util.Timer();
  283. heartBeatTimer.schedule(new TimerTask() {
  284. public void run() {
  285. if(nettyClient!=null&&tcp_connect_flag) {
  286. //System.out.println("发送心跳报文");
  287. DataUtil.heartBeat(nettyClient,mes_gw);
  288. heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
  289. }
  290. }
  291. }, 100,mes_heart_beat_cycle*1000);
  292. //心跳显示图标
  293. if(heartBeatIconTimer!=null) {
  294. heartBeatIconTimer.cancel();
  295. }
  296. heartBeatIconTimer = new Timer();
  297. heartBeatIconTimer.schedule(new TimerTask() {
  298. public void run() {
  299. if(tcp_connect_flag) {
  300. if(iconREDFlag) {
  301. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  302. iconREDFlag = false;
  303. }else {
  304. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
  305. iconREDFlag = true;
  306. }
  307. heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
  308. heart_beat_menu.repaint();
  309. }else {
  310. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  311. heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
  312. heart_beat_menu.repaint();
  313. //若未连接则尝试连接
  314. if(nettyClient!=null&&!tcp_connect_flag){
  315. System.out.println("TCP已断开");
  316. //TCP重新同步连接
  317. if(!connect_request_flag) {
  318. //System.out.println("TCP重新同步连接");
  319. //设置TCP请求状态,只重新同步连接一次
  320. connect_request_flag = true;
  321. DataUtil.synrTcp(nettyClient,mes_gw);
  322. }
  323. }
  324. }
  325. }
  326. }, 100,mes_heart_icon_cycle*1000);
  327. }
  328. //设置tcp连接状态显示
  329. public static void setTcpStatus() {
  330. if(tcp_connect_flag) {
  331. status_menu.setText("已连接MES服务器");
  332. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  333. heart_beat_menu.repaint();
  334. }else {
  335. status_menu.setText("未连接MES服务器");
  336. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  337. heart_beat_menu.repaint();
  338. }
  339. }
  340. public static void initWarehouseData(){
  341. resetScanA();
  342. }
  343. public static void resetScanA() {
  344. work_status = 0;
  345. check_quality_result = false;
  346. MesClient.finish_ok_bt.setEnabled(false);
  347. MesClient.finish_ng_bt.setEnabled(false);
  348. product_sn.setText("");
  349. curSn = "";
  350. MesClient.f_scan_data_bt_1.setEnabled(true);
  351. MesClient.setMenuStatus("请扫工件码",0);
  352. MesClient.aMax = 0;
  353. MesClient.bMax = 0;
  354. MesClient.aFinish = 0;
  355. MesClient.alist = new ArrayList<>();
  356. MesClient.blist = new ArrayList<>();
  357. MesClient.sortB = 0;
  358. MesClient.sortA = 0;
  359. MesClient.param1.setText("");
  360. MesClient.param2.setText("");
  361. MesClient.param3.setText("");
  362. MesClient.param4.setText("");
  363. deviceControl = ModbusUtil.getControlModel(plcA);
  364. if(deviceControl == 1){
  365. }
  366. // plcA.writeCoil(3128,false);
  367. // plcB.writeCoil(3128,false);
  368. ModbusUtil.setPowerOff(MesClient.plcA); // 远程关机
  369. ModbusUtil.setPowerOff(MesClient.plcB); // 远程关机
  370. ModbusUtil.setTask(MesClient.plcA,MesClient.aSetNum);
  371. ModbusUtil.setTask(MesClient.plcB,MesClient.bSetNum);
  372. updateMaterailData();
  373. }
  374. public static void resetScanB() {
  375. }
  376. //获取用户20位
  377. public static void getUser() {
  378. user20 = user_menu.getText().toString();
  379. String space_tmp1 = "";
  380. if(user20.length()<20) {
  381. for(int i=0;i<20-user20.length();i++) {
  382. space_tmp1 = space_tmp1 + " ";
  383. }
  384. }
  385. user20 = user20 + space_tmp1;
  386. }
  387. //获取barcode内容36位
  388. public static String getBarcode(String barcodeTmp) {
  389. String barcodeRet = barcodeTmp;
  390. if(barcodeTmp.equalsIgnoreCase("")) {
  391. return "";
  392. }else {
  393. if(barcodeTmp.length()<36) {
  394. String space = "";
  395. for(int i=0;i<36-barcodeTmp.length();i++) {
  396. space = space + " ";
  397. }
  398. barcodeRet = barcodeTmp + space;
  399. }
  400. }
  401. return barcodeRet;
  402. }
  403. public static void scanBarcode() {
  404. if(work_status == 1){
  405. JOptionPane.showMessageDialog(mesClientFrame,"工作中,勿扫码","提示窗口", JOptionPane.INFORMATION_MESSAGE);
  406. return;
  407. }
  408. String scanBarcodeTitle = "";
  409. switch(scan_type) {
  410. case 1:
  411. product_sn.setText("");
  412. scanBarcodeTitle = "请扫工件码";
  413. break;
  414. }
  415. //弹窗扫工件码
  416. String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
  417. if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")) {
  418. //获取用户
  419. getUser();
  420. //获取扫码内容36位
  421. String barcode36 = getBarcode(scanBarcode);//处理36为码
  422. //工位号
  423. String gw = "";
  424. switch(scan_type) {
  425. case 1:
  426. product_sn.setText(scanBarcode);
  427. curSn = scanBarcode;
  428. break;
  429. }
  430. //刷新界面
  431. mesClientFrame.repaint();
  432. if(!tcp_connect_flag) {
  433. JOptionPane.showMessageDialog(mesClientFrame,"设备未连接Mes服务器","提示窗口", JOptionPane.INFORMATION_MESSAGE);
  434. return;
  435. }
  436. // 查询工件质量
  437. Boolean sendret = DataUtil.checkQuality(nettyClient,barcode36,user20);
  438. if(!sendret){
  439. JOptionPane.showMessageDialog(mesClientFrame,"消息发送失败,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
  440. return;
  441. }
  442. }else {
  443. JOptionPane.showMessageDialog(mesClientFrame,"请扫工件码","提示窗口", JOptionPane.INFORMATION_MESSAGE);
  444. return;
  445. }
  446. }
  447. public static void logoff() {
  448. // welcomeWin.setVisible(true);
  449. mesClientFrame.setVisible(false);
  450. nettyClient = null;
  451. // if(heartBeatTimer!=null) {
  452. // heartBeatTimer.cancel();
  453. // }
  454. // if(heartBeatIconTimer!=null) {
  455. // heartBeatIconTimer.cancel();
  456. // }
  457. tcp_connect_flag = false;
  458. connect_request_flag = false;
  459. }
  460. public MesClient() {
  461. setIconImage(Toolkit.getDefaultToolkit().getImage(MesClient.class.getResource("/bg/logo.png")));
  462. setTitle("MES系统客户端:"+mes_gw + "- " + mes_gw_des);
  463. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  464. setBounds(0, 0, 1024, 768);
  465. JMenuBar menuBar = new JMenuBar();
  466. menuBar.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 26));
  467. setJMenuBar(menuBar);
  468. JMenu fileMenu = new JMenu("用户");
  469. fileMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/user.png")));
  470. fileMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  471. menuBar.add(fileMenu);
  472. JMenuItem exitMenuItem = new JMenuItem("退出");
  473. exitMenuItem.setIcon(new ImageIcon(MesClient.class.getResource("/bg/logoff.png")));
  474. exitMenuItem.setFont(new Font("微软雅黑", Font.PLAIN, 22));
  475. fileMenu.add(exitMenuItem);
  476. exitMenuItem.addMouseListener(new MouseAdapter() {
  477. @Override
  478. public void mousePressed(MouseEvent e) {//只能检测到mousePressed事件
  479. super.mouseClicked(e);
  480. //dispose();
  481. logoff();
  482. }
  483. });
  484. JMenu settingMenu = new JMenu("设置");
  485. //settingMenu.setVisible(false);
  486. settingMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")));
  487. settingMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  488. menuBar.add(settingMenu);
  489. JMenuItem resetTcpMenu = new JMenuItem("\u91CD\u8FDEMES");
  490. resetTcpMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  491. resetTcpMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  492. resetTcpMenu.addMouseListener(new MouseAdapter() {
  493. @Override
  494. public void mousePressed(MouseEvent e) {
  495. super.mouseClicked(e);
  496. //重连mes
  497. nettyClient.future.channel().close();
  498. }
  499. });
  500. settingMenu.add(resetTcpMenu);
  501. JMenuItem resetTcpMenu_1 = new JMenuItem("刷新工件");
  502. resetTcpMenu_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  503. resetTcpMenu_1.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  504. resetTcpMenu_1.addMouseListener(new MouseAdapter() {
  505. @Override
  506. public void mousePressed(MouseEvent e) {
  507. super.mouseClicked(e);
  508. resetScanA();
  509. }
  510. });
  511. settingMenu.add(resetTcpMenu_1);
  512. contentPane = new JPanel();
  513. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  514. setContentPane(contentPane);
  515. contentPane.setLayout(new BorderLayout(0, 0));
  516. JToolBar toolBar = new JToolBar();
  517. contentPane.add(toolBar, BorderLayout.NORTH);
  518. JLabel equipment_statu_label = new JLabel("状态:");
  519. equipment_statu_label.setHorizontalAlignment(SwingConstants.CENTER);
  520. equipment_statu_label.setForeground(Color.BLACK);
  521. equipment_statu_label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  522. equipment_statu_label.setBackground(Color.LIGHT_GRAY);
  523. toolBar.add(equipment_statu_label);
  524. status_menu = new JButton("设备未连接MES服务器");
  525. if(tcp_connect_flag) {
  526. status_menu.setText("已连接MES服务器");
  527. status_menu.setForeground(Color.GREEN);
  528. }else {
  529. status_menu.setText("未连接MES服务器");
  530. status_menu.setForeground(Color.DARK_GRAY);
  531. }
  532. status_menu.addActionListener(new ActionListener() {
  533. public void actionPerformed(ActionEvent e) {
  534. }
  535. });
  536. status_menu.setForeground(Color.GREEN);
  537. status_menu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  538. status_menu.setBackground(Color.BLACK);
  539. toolBar.add(status_menu);
  540. JLabel space_1 = new JLabel(" ");
  541. toolBar.add(space_1);
  542. JLabel heart_beat_status_label = new JLabel("心跳:");
  543. heart_beat_status_label.setHorizontalAlignment(SwingConstants.CENTER);
  544. heart_beat_status_label.setForeground(Color.BLACK);
  545. heart_beat_status_label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  546. heart_beat_status_label.setBackground(Color.LIGHT_GRAY);
  547. toolBar.add(heart_beat_status_label);
  548. heart_beat_menu = new JButton("2024-02-20 23:20:10");
  549. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
  550. heart_beat_menu.setForeground(Color.GREEN);
  551. heart_beat_menu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  552. heart_beat_menu.setBackground(Color.BLACK);
  553. toolBar.add(heart_beat_menu);
  554. JLabel space_2 = new JLabel(" ");
  555. toolBar.add(space_2);
  556. JLabel user_status_label = new JLabel("登录用户:");
  557. user_status_label.setHorizontalAlignment(SwingConstants.CENTER);
  558. user_status_label.setForeground(Color.BLACK);
  559. user_status_label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  560. user_status_label.setBackground(Color.LIGHT_GRAY);
  561. toolBar.add(user_status_label);
  562. user_menu = new JButton("JinJuShi");
  563. user_menu.setForeground(Color.GREEN);
  564. user_menu.setFont(new Font("微软雅黑", Font.PLAIN, 22));
  565. user_menu.setBackground(Color.BLACK);
  566. toolBar.add(user_menu);
  567. JLabel space_3 = new JLabel(" ");
  568. toolBar.add(space_3);
  569. JLabel space_4 = new JLabel(" ");
  570. toolBar.add(space_4);
  571. tabbedPane = new JTabbedPane(JTabbedPane.TOP);
  572. tabbedPane.setMinimumSize(new Dimension(400, 50));
  573. tabbedPane.setFont(new Font("宋体", Font.BOLD, 22));
  574. contentPane.add(tabbedPane);
  575. //首页
  576. JPanel indexPanelA = new JPanel();
  577. indexScrollPaneA = new JScrollPane(indexPanelA);
  578. indexPanelA.setLayout(null);
  579. product_sn = new JTextField();
  580. product_sn.setHorizontalAlignment(SwingConstants.CENTER);
  581. product_sn.setEditable(false);
  582. product_sn.setFont(new Font("微软雅黑", Font.PLAIN, 28));
  583. product_sn.setBounds(81, 70, 602, 70);
  584. indexPanelA.add(product_sn);
  585. product_sn.setColumns(10);
  586. f_scan_data_bt_1 = new JButton("扫码");
  587. f_scan_data_bt_1.addActionListener(new ActionListener() {
  588. public void actionPerformed(ActionEvent e) {
  589. scan_type = 1;
  590. scanBarcode();
  591. }
  592. });
  593. f_scan_data_bt_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/scan_barcode.png")));
  594. f_scan_data_bt_1.setFont(new Font("微软雅黑", Font.PLAIN, 32));
  595. f_scan_data_bt_1.setBounds(693, 70, 198, 70);
  596. indexPanelA.add(f_scan_data_bt_1);
  597. // String[] hjtitles = new String[]{"焊机1","焊机2","焊机3"};
  598. // String[] hjvals = new String[]{"HJ001","HJ002","HJ003"};
  599. // mesRadioHj = new MesRadio(hjtitles,hjvals);
  600. // mesRadioHj.setSize(500,50);
  601. // mesRadioHj.setBounds(190,170,500,50);
  602. // indexPanelA.add(mesRadioHj);
  603. finish_ok_bt = new JButton("OK");
  604. finish_ok_bt.setEnabled(false);
  605. finish_ok_bt.addActionListener(new ActionListener() {
  606. public void actionPerformed(ActionEvent e) {
  607. if(work_status == 1 && check_quality_result){
  608. String sn = getBarcode(product_sn.getText());
  609. getUser();
  610. String qret = "OK";
  611. Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20);
  612. if(!sendret){
  613. MesClient.setMenuStatus("消息发送失败,请重试",-1);
  614. // JOptionPane.showMessageDialog(mesClientFrame,"消息发送失败,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
  615. return;
  616. }
  617. }
  618. }
  619. });
  620. finish_ok_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
  621. finish_ok_bt.setFont(new Font("微软雅黑", Font.PLAIN, 32));
  622. // finish_ok_bt.setBounds(185, 291, 240, 80);
  623. finish_ok_bt.setBounds(185, 371, 240, 80);
  624. finish_ok_bt.setEnabled(false);
  625. indexPanelA.add(finish_ok_bt);
  626. finish_ng_bt = new JButton("NG");
  627. finish_ng_bt.setEnabled(false);
  628. finish_ng_bt.addActionListener(new ActionListener() {
  629. public void actionPerformed(ActionEvent e) {
  630. if(work_status == 1 && check_quality_result){
  631. String sn = getBarcode(product_sn.getText());
  632. getUser();
  633. String qret = "NG";
  634. Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20);
  635. if(!sendret){
  636. MesClient.setMenuStatus("消息发送失败,请重试",-1);
  637. // JOptionPane.showMessageDialog(mesClientFrame,"消息发送失败,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
  638. return;
  639. }
  640. }
  641. }
  642. });
  643. finish_ng_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ng_bg.png")));
  644. finish_ng_bt.setFont(new Font("微软雅黑", Font.PLAIN, 32));
  645. finish_ng_bt.setBounds(508, 371, 240, 80);
  646. finish_ng_bt.setEnabled(false);
  647. indexPanelA.add(finish_ng_bt);
  648. JLabel lblNewLabel = new JLabel("A\u67AA");
  649. lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
  650. lblNewLabel.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  651. lblNewLabel.setBounds(204, 186, 166, 28);
  652. indexPanelA.add(lblNewLabel);
  653. JLabel lblNewLabel_1 = new JLabel("\u9884\u8BBE\u6570\u91CF");
  654. lblNewLabel_1.setFont(new Font("微软雅黑", Font.PLAIN, 18));
  655. lblNewLabel_1.setBounds(204, 241, 83, 34);
  656. indexPanelA.add(lblNewLabel_1);
  657. param1 = new JTextField();
  658. param1.setHorizontalAlignment(SwingConstants.CENTER);
  659. param1.setFont(new Font("微软雅黑", Font.PLAIN, 18));
  660. param1.setText("0");
  661. param1.setEditable(false);
  662. param1.setBounds(288, 241, 83, 34);
  663. indexPanelA.add(param1);
  664. param1.setColumns(10);
  665. JLabel lblNewLabel_1_1 = new JLabel("\u5B8C\u6210\u6570\u91CF");
  666. lblNewLabel_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 18));
  667. lblNewLabel_1_1.setBounds(204, 285, 83, 34);
  668. indexPanelA.add(lblNewLabel_1_1);
  669. param2 = new JTextField();
  670. param2.setHorizontalAlignment(SwingConstants.CENTER);
  671. param2.setFont(new Font("微软雅黑", Font.PLAIN, 18));
  672. param2.setText("0");
  673. param2.setEditable(false);
  674. param2.setColumns(10);
  675. param2.setBounds(288, 285, 83, 34);
  676. indexPanelA.add(param2);
  677. JLabel lblB = new JLabel("B\u67AA");
  678. lblB.setHorizontalAlignment(SwingConstants.CENTER);
  679. lblB.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  680. lblB.setBounds(525, 186, 166, 28);
  681. indexPanelA.add(lblB);
  682. JLabel lblNewLabel_1_2 = new JLabel("\u9884\u8BBE\u6570\u91CF");
  683. lblNewLabel_1_2.setFont(new Font("微软雅黑", Font.PLAIN, 18));
  684. lblNewLabel_1_2.setBounds(525, 241, 83, 34);
  685. indexPanelA.add(lblNewLabel_1_2);
  686. param3 = new JTextField();
  687. param3.setText("0");
  688. param3.setHorizontalAlignment(SwingConstants.CENTER);
  689. param3.setFont(new Font("微软雅黑", Font.PLAIN, 18));
  690. param3.setEditable(false);
  691. param3.setColumns(10);
  692. param3.setBounds(608, 241, 83, 34);
  693. indexPanelA.add(param3);
  694. JLabel lblNewLabel_1_1_1 = new JLabel("\u5B8C\u6210\u6570\u91CF");
  695. lblNewLabel_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 18));
  696. lblNewLabel_1_1_1.setBounds(525, 285, 83, 34);
  697. indexPanelA.add(lblNewLabel_1_1_1);
  698. param4 = new JTextField();
  699. param4.setText("0");
  700. param4.setHorizontalAlignment(SwingConstants.CENTER);
  701. param4.setFont(new Font("微软雅黑", Font.PLAIN, 18));
  702. param4.setEditable(false);
  703. param4.setColumns(10);
  704. param4.setBounds(608, 285, 83, 34);
  705. indexPanelA.add(param4);
  706. tabbedPane.addTab("工作面板", new ImageIcon(MesClient.class.getResource("/bg/a_side.png")), indexScrollPaneA, null);
  707. tabbedPane.setEnabledAt(0, true);
  708. // searchScrollPane = new JScrollPane((Component) null);
  709. indexPanelC = new JPanel();
  710. searchScrollPaneDj = new JScrollPane(indexPanelC);
  711. indexPanelC.setLayout(null);
  712. tabbedPane.addTab("开班点检", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPaneDj, null);
  713. indexPanelB = new JPanel();
  714. searchScrollPane = new JScrollPane(indexPanelB);
  715. indexPanelB.setLayout(null);
  716. tabbedPane.addTab("工作记录", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPane, null);
  717. tabbedPane.addChangeListener(new ChangeListener() {
  718. @Override
  719. public void stateChanged(ChangeEvent e) {
  720. JTabbedPane tabbedPane = (JTabbedPane) e.getSource();
  721. int selectedIndex = tabbedPane.getSelectedIndex();
  722. System.out.println("selectedIndex:"+selectedIndex);
  723. if(selectedIndex == 1){
  724. }
  725. }
  726. });
  727. }
  728. public static void setMenuStatus(String msg,int error){
  729. if(error == 0){
  730. MesClient.status_menu.setForeground(Color.GREEN);
  731. }else{
  732. MesClient.status_menu.setForeground(Color.RED);
  733. }
  734. MesClient.status_menu.setText(msg);
  735. }
  736. public static void getMaterailData(){
  737. JSONObject retObj = DataUtil.getBindMaterail();
  738. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  739. java.util.List<BindMaterialResp> arrs = retObj.getList("data",BindMaterialResp.class);
  740. int i = 0;
  741. rowData = new Object[arrs.size()][7];
  742. for (BindMaterialResp bindMaterialResp:arrs){
  743. rowData[i][0] = bindMaterialResp.getMaterialTitle();
  744. rowData[i][1] = bindMaterialResp.getBatchSn();
  745. rowData[i][2] = bindMaterialResp.getLastTimes();
  746. rowData[i][3] = "";
  747. rowData[i][4] = bindMaterialResp.getCraft();
  748. rowData[i][5] = bindMaterialResp.getMaterialId();
  749. rowData[i][6] = bindMaterialResp.getType();
  750. i++;
  751. }
  752. bindBatchPanel();
  753. }
  754. }
  755. public static void updateMaterailData(){
  756. JSONObject retObj = DataUtil.getBindMaterail();
  757. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  758. List<BindMaterialResp> arrs = retObj.getList("data",BindMaterialResp.class);
  759. int i = 0;
  760. for (BindMaterialResp bindMaterialResp:arrs){
  761. rowData[i][0] = bindMaterialResp.getMaterialTitle();
  762. rowData[i][1] = bindMaterialResp.getBatchSn();
  763. rowData[i][2] = bindMaterialResp.getLastTimes();
  764. rowData[i][3] = "";
  765. rowData[i][4] = bindMaterialResp.getCraft();
  766. rowData[i][5] = bindMaterialResp.getMaterialId();
  767. rowData[i][6] = bindMaterialResp.getType();
  768. i++;
  769. }
  770. MesClient.table.repaint();
  771. }
  772. }
  773. // 绑定物料批次码
  774. public static void scanBatchSn(BindMaterialResp bindMaterialResp) {
  775. //弹窗扫工件码
  776. String scanBarcodeTitle = "请扫物料:"+bindMaterialResp.getMaterialTitle();
  777. String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
  778. if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")) {
  779. JSONObject retObj = DataUtil.saveBindMaterail(scanBarcode,bindMaterialResp.getCraft(),bindMaterialResp.getMaterialId(),bindMaterialResp.getType());
  780. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  781. MesClient.setMenuStatus("扫物料:"+bindMaterialResp.getMaterialTitle()+"成功",0);
  782. updateMaterailData();
  783. }else{
  784. if(retObj.get("result")==null){
  785. MesClient.setMenuStatus("请求失败,请重试",-1);
  786. }else{
  787. if(retObj.get("result").toString().equalsIgnoreCase("false")){
  788. MesClient.setMenuStatus(retObj.getString("message"),-1);
  789. }
  790. }
  791. }
  792. }
  793. }
  794. public static void bindBatchPanel(){
  795. JPanel indexPanelBB = new JPanel();
  796. JPanel panel = new JPanel();
  797. panel.setBounds(0, 0, 990, 550);
  798. // panel.setBounds(81, 50, 810, 479);
  799. indexPanelBB.add(panel);
  800. panel.setLayout(new GridLayout(0, 1, 0, 0));
  801. table = new JTable(rowData, columnNames){
  802. public boolean isCellEditable(int row, int column) {
  803. if(column == 3){
  804. return true;
  805. }
  806. return false;
  807. }
  808. };
  809. table.setRowHeight(40);
  810. table.setEnabled(true);
  811. table.setFont(new Font("微软雅黑", Font.PLAIN, 14));
  812. table.getColumnModel().getColumn(3).setCellRenderer(new TableCellRendererButton());
  813. table.getColumnModel().getColumn(3).setCellEditor(new TableCellEditorButton());
  814. JScrollPane scrollPane = new JScrollPane(table);
  815. panel.add(scrollPane);
  816. JScrollPane indexScrollPaneB = new JScrollPane(indexPanelBB);
  817. indexPanelBB.setLayout(null);
  818. tabbedPane.addTab("绑定物料", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), indexScrollPaneB, null);
  819. }
  820. }