MesClient.java 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260
  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 org.slf4j.Logger;
  12. import org.slf4j.LoggerFactory;
  13. import javax.swing.*;
  14. import javax.swing.border.EmptyBorder;
  15. import javax.swing.event.ChangeEvent;
  16. import javax.swing.event.ChangeListener;
  17. import java.awt.*;
  18. import java.awt.event.ActionEvent;
  19. import java.awt.event.ActionListener;
  20. import java.awt.event.MouseAdapter;
  21. import java.awt.event.MouseEvent;
  22. import java.io.BufferedReader;
  23. import java.io.IOException;
  24. import java.io.InputStream;
  25. import java.io.InputStreamReader;
  26. import java.util.*;
  27. import java.util.List;
  28. import java.util.Timer;
  29. public class MesClient extends JFrame {
  30. private static final Logger log = LoggerFactory.getLogger(MesClient.class);
  31. private static String Drivde = "org.sqlite.JDBC";
  32. public static int mes_auth = 0; // 权限级别 0=无权限 1=操作工人 2=管理员
  33. public static String mes_gw = ""; // 工位号
  34. public static String mes_gw_des = ""; // 工位名称
  35. public static String mes_server_ip = ""; // 服务器IP地址
  36. public static int mes_tcp_port = 3000; // TCP服务端口
  37. public static int mes_heart_beat_cycle = 10; // 心跳周期
  38. public static int mes_heart_icon_cycle = 1;
  39. public static String mes_line_sn = ""; // 产线编号
  40. //TCP连接
  41. public static NettyClient nettyClient;
  42. //TCP连接状态
  43. public static boolean tcp_connect_flag = false;
  44. //TCP连接请求
  45. public static boolean connect_request_flag = false;
  46. //session
  47. public static String sessionid = "";
  48. public static JPanel contentPane;
  49. public static MesClient mesClientFrame;
  50. public static JTabbedPane tabbedPane;
  51. public static JScrollPane indexScrollPaneA;
  52. public static JScrollPane searchScrollPane;
  53. public static JScrollPane searchScrollPaneDj;
  54. public static Boolean check_quality_result = false;
  55. public static Integer work_status = 0;
  56. public static JButton heart_beat_menu;
  57. public static JButton status_menu;
  58. public static JButton user_menu;
  59. public static int scan_type = 0;
  60. public static JButton finish_ok_bt;
  61. public static JButton finish_ng_bt;
  62. public static JTextField product_sn;
  63. public static JButton f_scan_data_bt_1;
  64. public static String user20 = "";
  65. public static JFrame welcomeWin;
  66. public static JPanel indexPanelB;
  67. public static MesWebView jfxPanel = null;
  68. public static JPanel indexPanelC;
  69. public static MesWebView jfxPanel2 = null;
  70. public static MesRadio mesRadioHj;
  71. public static JTextField param1;
  72. public static JTextField param2;
  73. public static JTextField param3;
  74. public static JTextField param4;
  75. public static ModbusTcp plcA = new ModbusTcp(1, "192.168.1.7");
  76. public static ModbusTcp plcB = new ModbusTcp(1, "192.168.1.8");
  77. // public static ModbusTcp plcA = new ModbusTcp(1, "192.168.1.27");
  78. // public static ModbusTcp plcB = new ModbusTcp(1, "192.168.1.28");
  79. public static Timer cjTimer;
  80. public static Timer cjTimer2;
  81. public static Timer cjTimer3;
  82. public static Short aSetNum = 44;
  83. // public static Short aSetNum = 49;
  84. public static Short sortA = 0;
  85. public static Short aMax = 0;
  86. public static Short aFinish = 0;
  87. public static List<Map> alist = new ArrayList<>();
  88. public static Short bSetNum = 44;
  89. // public static Short bSetNum = 27;
  90. public static Short sortB = 0;
  91. public static Short bMax = 0;
  92. public static Short bFinish = 0;
  93. public static List<Map> blist = new ArrayList<>();
  94. public static Short deviceControl = 0; // 0=本地 1=远程
  95. public static Integer tjStatus = 0; // 1=提交失败
  96. public static String tjFlagTextErr = "结果上传MES失败,请重试";
  97. public static String curSn = "";
  98. public static JTable table;
  99. public static Object[] columnNames = { "物料名称", "绑定批次", "剩余次数", "操作" };
  100. public static Object[][] rowData = null;
  101. public static Integer zdStatusA = 0;
  102. public static Integer zdStatusB = 0;
  103. public static String foutA = "";
  104. public static String fmaxA = "";
  105. public static String fminA = "";
  106. public static String soutA = "";
  107. public static String smaxA = "";
  108. public static String sminA = "";
  109. public static String curA = "";
  110. public static String foutB = "";
  111. public static String fmaxB = "";
  112. public static String fminB = "";
  113. public static String soutB = "";
  114. public static String smaxB = "";
  115. public static String sminB = "";
  116. public static String curB = "";
  117. public static JButton resetResultA;
  118. public static JButton okResultA;
  119. public static JButton ngResultA;
  120. public static JButton resetResultB;
  121. public static JButton okResultB;
  122. public static JButton ngResultB;
  123. public static void main(String[] args) {
  124. EventQueue.invokeLater(new Runnable() {
  125. @Override
  126. public void run() {
  127. try{
  128. //读文件配置
  129. readProperty();
  130. // 显示界面
  131. mesClientFrame = new MesClient();
  132. mesClientFrame.setVisible(false);
  133. JdbcUtils.getConn();
  134. welcomeWin = new LoginFarme();
  135. welcomeWin.setVisible(true);
  136. getPlcParam();
  137. upParams();
  138. setDeviceStart();
  139. getMaterailData();
  140. }catch (Exception e){
  141. e.printStackTrace();
  142. }
  143. }
  144. });
  145. }
  146. public static java.util.Timer cjTimer4;
  147. public static void setDeviceStart() {
  148. if(cjTimer4!=null) {
  149. cjTimer4.cancel();
  150. }
  151. cjTimer4 = new Timer();
  152. cjTimer4.schedule(new TimerTask() {
  153. public void run() {
  154. try{
  155. if(work_status == 1){
  156. List<Boolean> yxstatus = plcA.readCoil(3128,1);
  157. if(yxstatus.size() >= 1 && !yxstatus.get(0)){
  158. if(!MesClient.curSn.isEmpty() && MesClient.aMax > 0 && MesClient.aMax == MesClient.sortA){
  159. ModbusUtil.setPowerOff(plcA);
  160. }else{
  161. ModbusUtil.setPowerOn(plcA);
  162. }
  163. }
  164. List<Boolean> yxstatusb = plcB.readCoil(3128,1);
  165. if(yxstatusb.size() >= 1 && !yxstatusb.get(0)){
  166. if(!MesClient.curSn.isEmpty() && MesClient.bMax > 0 && MesClient.bMax == MesClient.sortB){
  167. ModbusUtil.setPowerOff(plcB);
  168. }else{
  169. ModbusUtil.setPowerOn(plcB);
  170. }
  171. }
  172. }else{
  173. List<Boolean> yxstatus = plcA.readCoil(3128,1);
  174. if(yxstatus.size() >= 1 && yxstatus.get(0)){
  175. ModbusUtil.setPowerOff(plcA);
  176. }
  177. List<Boolean> yxstatusb = plcB.readCoil(3128,1);
  178. if(yxstatusb.size() >= 1 && yxstatusb.get(0)){
  179. ModbusUtil.setPowerOff(plcB);
  180. }
  181. }
  182. }catch (Exception e){
  183. e.printStackTrace();
  184. }
  185. }
  186. }, 1000,1000);
  187. }
  188. //读配置文件
  189. private static void readProperty() throws IOException{
  190. String enconding = "UTF-8";
  191. InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
  192. Properties pro = new Properties();
  193. BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
  194. pro.load(br);
  195. mes_gw = pro.getProperty("mes.gw");
  196. // mes_gw_des = pro.getProperty("mes.gw_des");
  197. mes_server_ip = pro.getProperty("mes.server_ip");
  198. mes_tcp_port = Integer.parseInt(pro.getProperty("mes.tcp_port"));
  199. mes_heart_beat_cycle = Integer.parseInt(pro.getProperty("mes.heart_beat_cycle"));
  200. mes_line_sn = pro.getProperty("mes.line_sn");
  201. mes_gw_des = OprnoUtil.getGwDes(mes_line_sn,mes_gw);
  202. System.out.println(mes_gw + ";" + mes_gw_des + ";" + mes_server_ip + ";" + mes_tcp_port + ";" + mes_heart_beat_cycle);
  203. }
  204. public static void getPlcParam() {
  205. if(cjTimer!=null) {
  206. cjTimer.cancel();
  207. }
  208. cjTimer = new Timer();
  209. cjTimer.schedule(new TimerTask() {
  210. public void run() {
  211. try{
  212. if(work_status == 1){
  213. ModbusUtil.getDataA(plcA);
  214. }
  215. }catch (Exception e){
  216. e.printStackTrace();
  217. }
  218. try{
  219. if(work_status == 1){
  220. ModbusUtil.getDataB(plcB);
  221. }
  222. }catch (Exception e){
  223. e.printStackTrace();
  224. }
  225. }
  226. }, 1000,500);
  227. }
  228. public static void getPlcSn() {
  229. if(cjTimer3!=null) {
  230. cjTimer3.cancel();
  231. }
  232. cjTimer3 = new Timer();
  233. cjTimer3.schedule(new TimerTask() {
  234. public void run() {
  235. try{
  236. String cSn = ModbusUtil.getSn(plcA);
  237. if(!cSn.isEmpty()){
  238. if(curSn.isEmpty()){
  239. product_sn.setText(cSn);
  240. curSn = cSn;
  241. //发送AQDW质量询问报文,当收到返回UD才能工作
  242. getUser();
  243. log.info("【质量检查-PLC触发】准备发送 AQDW 质量询问报文, SN: {}, User: {}", curSn, user20);
  244. Boolean sendret = DataUtil.checkQuality(nettyClient,curSn,user20);
  245. log.info("【质量检查-PLC触发】请求发送结果: {}", sendret);
  246. if(!sendret){
  247. MesClient.setMenuStatus("消息发送失败,请重试",-1);
  248. }
  249. }else if(!curSn.isEmpty() && !cSn.equals(curSn)){
  250. resetScanA();
  251. }
  252. }
  253. }catch (Exception e){
  254. e.printStackTrace();
  255. }
  256. }
  257. }, 1000,1000);
  258. }
  259. public static void upParams() {
  260. if(cjTimer2!=null) {
  261. cjTimer2.cancel();
  262. }
  263. cjTimer2 = new Timer();
  264. cjTimer2.schedule(new TimerTask() {
  265. public void run() {
  266. try{
  267. List<ProdReq> prods = JdbcUtils.getProds();
  268. log.info("【参数定时上传】获取到待同步的生产数据,记录数: {}", prods.size());
  269. if(prods.size() > 0){
  270. // 定时上传参数
  271. log.debug("【参数定时上传】请求数据详情: {}", JSON.toJSONString(prods));
  272. JSONObject retObj = DataUtil.upParams(JSON.toJSONString(prods));
  273. log.info("【参数定时上传】服务端返回结果: {}", retObj != null ? retObj.toJSONString() : "null");
  274. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  275. // 更新sqlite已同步
  276. for(ProdReq prodReq:prods){
  277. JdbcUtils.updateProdSync(prodReq.getId(),1);
  278. }
  279. log.info("【参数定时上传】本地 SQLite 状态更新完成");
  280. } else {
  281. log.warn("【参数定时上传】接口返回非 true,未更新本地状态");
  282. }
  283. }
  284. }catch (Exception e){
  285. log.error("【参数定时上传】发生异常: ", e);
  286. }
  287. }
  288. }, 1000,30*1000);
  289. }
  290. // 初始化TCP
  291. public static void initTcpConnection() {
  292. try {
  293. if(nettyClient==null) {
  294. //初始化TCP连接
  295. nettyClient = new NettyClient();
  296. //TCP连接状态
  297. tcp_connect_flag = false;
  298. //设置TCP请求状态
  299. connect_request_flag = true;
  300. DataUtil.synrTcp(nettyClient,mes_gw);
  301. }
  302. } catch (Exception e) {
  303. // TODO Auto-generated catch block
  304. e.printStackTrace();
  305. }
  306. }
  307. //启动心跳包程序
  308. public static java.util.Timer heartBeatTimer;
  309. public static java.util.Timer heartBeatIconTimer;
  310. public static boolean iconREDFlag = true;
  311. public static void startHeartBeatTimer() {
  312. if(heartBeatTimer!=null) {
  313. heartBeatTimer.cancel();
  314. }
  315. heartBeatTimer = new java.util.Timer();
  316. heartBeatTimer.schedule(new TimerTask() {
  317. public void run() {
  318. if(nettyClient!=null&&tcp_connect_flag) {
  319. //System.out.println("发送心跳报文");
  320. DataUtil.heartBeat(nettyClient,mes_gw);
  321. heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
  322. }
  323. }
  324. }, 100,mes_heart_beat_cycle*1000);
  325. //心跳显示图标
  326. if(heartBeatIconTimer!=null) {
  327. heartBeatIconTimer.cancel();
  328. }
  329. heartBeatIconTimer = new Timer();
  330. heartBeatIconTimer.schedule(new TimerTask() {
  331. public void run() {
  332. if(tcp_connect_flag) {
  333. if(iconREDFlag) {
  334. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  335. iconREDFlag = false;
  336. }else {
  337. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
  338. iconREDFlag = true;
  339. }
  340. heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
  341. heart_beat_menu.repaint();
  342. }else {
  343. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  344. heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
  345. heart_beat_menu.repaint();
  346. //若未连接则尝试连接
  347. if(nettyClient!=null&&!tcp_connect_flag){
  348. System.out.println("TCP已断开");
  349. //TCP重新同步连接
  350. if(!connect_request_flag) {
  351. //System.out.println("TCP重新同步连接");
  352. //设置TCP请求状态,只重新同步连接一次
  353. connect_request_flag = true;
  354. DataUtil.synrTcp(nettyClient,mes_gw);
  355. }
  356. }
  357. }
  358. }
  359. }, 100,mes_heart_icon_cycle*1000);
  360. }
  361. //设置tcp连接状态显示
  362. public static void setTcpStatus() {
  363. if(tcp_connect_flag) {
  364. status_menu.setText("已连接MES服务器");
  365. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  366. heart_beat_menu.repaint();
  367. }else {
  368. status_menu.setText("未连接MES服务器");
  369. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  370. heart_beat_menu.repaint();
  371. }
  372. }
  373. public static void initWarehouseData(){
  374. resetScanA();
  375. }
  376. public static void resetScanA() {
  377. work_status = 0;
  378. check_quality_result = false;
  379. MesClient.finish_ok_bt.setEnabled(false);
  380. MesClient.finish_ng_bt.setEnabled(false);
  381. product_sn.setText("");
  382. curSn = "";
  383. MesClient.f_scan_data_bt_1.setEnabled(true);
  384. MesClient.setMenuStatus("请扫工件码",0);
  385. MesClient.aMax = 0;
  386. MesClient.bMax = 0;
  387. MesClient.aFinish = 0;
  388. MesClient.bFinish = 0;
  389. MesClient.alist = new ArrayList<>();
  390. MesClient.blist = new ArrayList<>();
  391. MesClient.sortB = 0;
  392. MesClient.sortA = 0;
  393. MesClient.param1.setText("");
  394. MesClient.param2.setText("");
  395. MesClient.param3.setText("");
  396. MesClient.param4.setText("");
  397. deviceControl = ModbusUtil.getControlModel(plcA);
  398. if(deviceControl == 1){
  399. }
  400. resetResultA.setEnabled(false);
  401. okResultA.setEnabled(false);
  402. ngResultA.setEnabled(false);
  403. resetResultB.setEnabled(false);
  404. okResultB.setEnabled(false);
  405. ngResultB.setEnabled(false);
  406. // plcA.writeCoil(3128,false);
  407. // plcB.writeCoil(3128,false);
  408. ModbusUtil.setPowerOff(MesClient.plcA); // 远程关机
  409. ModbusUtil.setPowerOff(MesClient.plcB); // 远程关机
  410. ModbusUtil.setTask(MesClient.plcA,MesClient.aSetNum);
  411. ModbusUtil.setTask(MesClient.plcB,MesClient.bSetNum);
  412. updateMaterailData();
  413. }
  414. public static void resetScanB() {
  415. }
  416. //获取用户20位
  417. public static void getUser() {
  418. user20 = user_menu.getText().toString();
  419. String space_tmp1 = "";
  420. if(user20.length()<20) {
  421. for(int i=0;i<20-user20.length();i++) {
  422. space_tmp1 = space_tmp1 + " ";
  423. }
  424. }
  425. user20 = user20 + space_tmp1;
  426. }
  427. //获取barcode内容36位
  428. public static String getBarcode(String barcodeTmp) {
  429. String barcodeRet = barcodeTmp;
  430. if(barcodeTmp.equalsIgnoreCase("")) {
  431. return "";
  432. }else {
  433. if(barcodeTmp.length()<36) {
  434. String space = "";
  435. for(int i=0;i<36-barcodeTmp.length();i++) {
  436. space = space + " ";
  437. }
  438. barcodeRet = barcodeTmp + space;
  439. }
  440. }
  441. return barcodeRet;
  442. }
  443. public static void scanBarcode() {
  444. if(work_status == 1){
  445. JOptionPane.showMessageDialog(mesClientFrame,"工作中,勿扫码","提示窗口", JOptionPane.INFORMATION_MESSAGE);
  446. return;
  447. }
  448. String scanBarcodeTitle = "";
  449. switch(scan_type) {
  450. case 1:
  451. product_sn.setText("");
  452. scanBarcodeTitle = "请扫工件码";
  453. break;
  454. }
  455. //弹窗扫工件码
  456. String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
  457. if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")) {
  458. //获取用户
  459. getUser();
  460. //获取扫码内容36位
  461. String barcode36 = getBarcode(scanBarcode);//处理36为码
  462. //工位号
  463. String gw = "";
  464. switch(scan_type) {
  465. case 1:
  466. product_sn.setText(scanBarcode);
  467. curSn = scanBarcode;
  468. break;
  469. }
  470. //刷新界面
  471. mesClientFrame.repaint();
  472. if(!tcp_connect_flag) {
  473. JOptionPane.showMessageDialog(mesClientFrame,"设备未连接Mes服务器","提示窗口", JOptionPane.INFORMATION_MESSAGE);
  474. return;
  475. }
  476. // 查询工件质量
  477. log.info("【质量检查-扫码触发】准备发送扫码质量询问报文, SN: {}, User: {}", barcode36, user20);
  478. Boolean sendret = DataUtil.checkQuality(nettyClient,barcode36,user20);
  479. log.info("【质量检查-扫码触发】请求发送结果: {}", sendret);
  480. if(!sendret){
  481. JOptionPane.showMessageDialog(mesClientFrame,"消息发送失败,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
  482. return;
  483. }
  484. }else {
  485. JOptionPane.showMessageDialog(mesClientFrame,"请扫工件码","提示窗口", JOptionPane.INFORMATION_MESSAGE);
  486. return;
  487. }
  488. }
  489. public static void logoff() {
  490. // welcomeWin.setVisible(true);
  491. mesClientFrame.setVisible(false);
  492. nettyClient = null;
  493. // if(heartBeatTimer!=null) {
  494. // heartBeatTimer.cancel();
  495. // }
  496. // if(heartBeatIconTimer!=null) {
  497. // heartBeatIconTimer.cancel();
  498. // }
  499. tcp_connect_flag = false;
  500. connect_request_flag = false;
  501. }
  502. public MesClient() {
  503. setIconImage(Toolkit.getDefaultToolkit().getImage(MesClient.class.getResource("/bg/logo.png")));
  504. setTitle("MES系统客户端:"+mes_gw + "- " + mes_gw_des);
  505. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  506. setBounds(0, 0, 1024, 768);
  507. JMenuBar menuBar = new JMenuBar();
  508. menuBar.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 26));
  509. setJMenuBar(menuBar);
  510. JMenu fileMenu = new JMenu("用户");
  511. fileMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/user.png")));
  512. fileMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  513. menuBar.add(fileMenu);
  514. JMenuItem exitMenuItem = new JMenuItem("退出");
  515. exitMenuItem.setIcon(new ImageIcon(MesClient.class.getResource("/bg/logoff.png")));
  516. exitMenuItem.setFont(new Font("微软雅黑", Font.PLAIN, 22));
  517. fileMenu.add(exitMenuItem);
  518. exitMenuItem.addMouseListener(new MouseAdapter() {
  519. @Override
  520. public void mousePressed(MouseEvent e) {//只能检测到mousePressed事件
  521. super.mouseClicked(e);
  522. //dispose();
  523. logoff();
  524. }
  525. });
  526. JMenu settingMenu = new JMenu("设置");
  527. //settingMenu.setVisible(false);
  528. settingMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")));
  529. settingMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  530. menuBar.add(settingMenu);
  531. JMenuItem resetTcpMenu = new JMenuItem("\u91CD\u8FDEMES");
  532. resetTcpMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  533. resetTcpMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  534. resetTcpMenu.addMouseListener(new MouseAdapter() {
  535. @Override
  536. public void mousePressed(MouseEvent e) {
  537. super.mouseClicked(e);
  538. //重连mes
  539. nettyClient.future.channel().close();
  540. }
  541. });
  542. settingMenu.add(resetTcpMenu);
  543. JMenuItem resetTcpMenu_1 = new JMenuItem("刷新工件");
  544. resetTcpMenu_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  545. resetTcpMenu_1.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  546. resetTcpMenu_1.addMouseListener(new MouseAdapter() {
  547. @Override
  548. public void mousePressed(MouseEvent e) {
  549. super.mouseClicked(e);
  550. resetScanA();
  551. }
  552. });
  553. settingMenu.add(resetTcpMenu_1);
  554. contentPane = new JPanel();
  555. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  556. setContentPane(contentPane);
  557. contentPane.setLayout(new BorderLayout(0, 0));
  558. JToolBar toolBar = new JToolBar();
  559. contentPane.add(toolBar, BorderLayout.NORTH);
  560. JLabel equipment_statu_label = new JLabel("状态:");
  561. equipment_statu_label.setHorizontalAlignment(SwingConstants.CENTER);
  562. equipment_statu_label.setForeground(Color.BLACK);
  563. equipment_statu_label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  564. equipment_statu_label.setBackground(Color.LIGHT_GRAY);
  565. toolBar.add(equipment_statu_label);
  566. status_menu = new JButton("设备未连接MES服务器");
  567. if(tcp_connect_flag) {
  568. status_menu.setText("已连接MES服务器");
  569. status_menu.setForeground(Color.GREEN);
  570. }else {
  571. status_menu.setText("未连接MES服务器");
  572. status_menu.setForeground(Color.DARK_GRAY);
  573. }
  574. status_menu.addActionListener(new ActionListener() {
  575. public void actionPerformed(ActionEvent e) {
  576. }
  577. });
  578. status_menu.setForeground(Color.GREEN);
  579. status_menu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  580. status_menu.setBackground(Color.BLACK);
  581. toolBar.add(status_menu);
  582. JLabel space_1 = new JLabel(" ");
  583. toolBar.add(space_1);
  584. JLabel heart_beat_status_label = new JLabel("心跳:");
  585. heart_beat_status_label.setHorizontalAlignment(SwingConstants.CENTER);
  586. heart_beat_status_label.setForeground(Color.BLACK);
  587. heart_beat_status_label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  588. heart_beat_status_label.setBackground(Color.LIGHT_GRAY);
  589. toolBar.add(heart_beat_status_label);
  590. heart_beat_menu = new JButton("2024-02-20 23:20:10");
  591. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
  592. heart_beat_menu.setForeground(Color.GREEN);
  593. heart_beat_menu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  594. heart_beat_menu.setBackground(Color.BLACK);
  595. toolBar.add(heart_beat_menu);
  596. JLabel space_2 = new JLabel(" ");
  597. toolBar.add(space_2);
  598. JLabel user_status_label = new JLabel("登录用户:");
  599. user_status_label.setHorizontalAlignment(SwingConstants.CENTER);
  600. user_status_label.setForeground(Color.BLACK);
  601. user_status_label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  602. user_status_label.setBackground(Color.LIGHT_GRAY);
  603. toolBar.add(user_status_label);
  604. user_menu = new JButton("JinJuShi");
  605. user_menu.setForeground(Color.GREEN);
  606. user_menu.setFont(new Font("微软雅黑", Font.PLAIN, 22));
  607. user_menu.setBackground(Color.BLACK);
  608. toolBar.add(user_menu);
  609. JLabel space_3 = new JLabel(" ");
  610. toolBar.add(space_3);
  611. JLabel space_4 = new JLabel(" ");
  612. toolBar.add(space_4);
  613. tabbedPane = new JTabbedPane(JTabbedPane.TOP);
  614. tabbedPane.setMinimumSize(new Dimension(400, 50));
  615. tabbedPane.setFont(new Font("宋体", Font.BOLD, 22));
  616. contentPane.add(tabbedPane);
  617. //首页
  618. JPanel indexPanelA = new JPanel();
  619. indexScrollPaneA = new JScrollPane(indexPanelA);
  620. indexPanelA.setLayout(null);
  621. product_sn = new JTextField();
  622. product_sn.setHorizontalAlignment(SwingConstants.CENTER);
  623. product_sn.setEditable(false);
  624. product_sn.setFont(new Font("微软雅黑", Font.PLAIN, 28));
  625. product_sn.setBounds(81, 70, 602, 70);
  626. indexPanelA.add(product_sn);
  627. product_sn.setColumns(10);
  628. f_scan_data_bt_1 = new JButton("扫码");
  629. f_scan_data_bt_1.addActionListener(new ActionListener() {
  630. public void actionPerformed(ActionEvent e) {
  631. scan_type = 1;
  632. scanBarcode();
  633. }
  634. });
  635. f_scan_data_bt_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/scan_barcode.png")));
  636. f_scan_data_bt_1.setFont(new Font("微软雅黑", Font.PLAIN, 32));
  637. f_scan_data_bt_1.setBounds(693, 70, 198, 70);
  638. indexPanelA.add(f_scan_data_bt_1);
  639. // String[] hjtitles = new String[]{"焊机1","焊机2","焊机3"};
  640. // String[] hjvals = new String[]{"HJ001","HJ002","HJ003"};
  641. // mesRadioHj = new MesRadio(hjtitles,hjvals);
  642. // mesRadioHj.setSize(500,50);
  643. // mesRadioHj.setBounds(190,170,500,50);
  644. // indexPanelA.add(mesRadioHj);
  645. finish_ok_bt = new JButton("OK");
  646. finish_ok_bt.setEnabled(false);
  647. finish_ok_bt.addActionListener(new ActionListener() {
  648. public void actionPerformed(ActionEvent e) {
  649. log.info("【总控操作】点击了 [OK] 按钮,当前产品SN: {}, 操作用户: {}", product_sn.getText(), user_menu.getText());
  650. if(work_status == 1 && check_quality_result){
  651. String sn = getBarcode(product_sn.getText());
  652. getUser();
  653. String qret = "OK";
  654. log.info("【判定上传】准备发送质量判定结果, SN: {}, 结果: {}", sn, qret);
  655. Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20);
  656. log.info("【判定上传】发送结果: {}", sendret);
  657. if(!sendret){
  658. MesClient.setMenuStatus("消息发送失败,请重试",-1);
  659. // JOptionPane.showMessageDialog(mesClientFrame,"消息发送失败,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
  660. return;
  661. }
  662. }
  663. }
  664. });
  665. finish_ok_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
  666. finish_ok_bt.setFont(new Font("微软雅黑", Font.PLAIN, 32));
  667. // finish_ok_bt.setBounds(185, 291, 240, 80);
  668. finish_ok_bt.setBounds(185, 371, 240, 80);
  669. finish_ok_bt.setEnabled(false);
  670. indexPanelA.add(finish_ok_bt);
  671. finish_ng_bt = new JButton("NG");
  672. finish_ng_bt.setEnabled(false);
  673. finish_ng_bt.addActionListener(new ActionListener() {
  674. public void actionPerformed(ActionEvent e) {
  675. log.info("【总控操作】点击了 [NG] 按钮,当前产品SN: {}, 操作用户: {}", product_sn.getText(), user_menu.getText());
  676. if(work_status == 1 && check_quality_result){
  677. String sn = getBarcode(product_sn.getText());
  678. getUser();
  679. String qret = "NG";
  680. log.info("【判定上传】准备发送质量判定结果, SN: {}, 结果: {}", sn, qret);
  681. Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20);
  682. log.info("【判定上传】发送结果: {}", sendret);
  683. if(!sendret){
  684. MesClient.setMenuStatus("消息发送失败,请重试",-1);
  685. // JOptionPane.showMessageDialog(mesClientFrame,"消息发送失败,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
  686. return;
  687. }
  688. }
  689. }
  690. });
  691. finish_ng_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ng_bg.png")));
  692. finish_ng_bt.setFont(new Font("微软雅黑", Font.PLAIN, 32));
  693. finish_ng_bt.setBounds(508, 371, 240, 80);
  694. finish_ng_bt.setEnabled(false);
  695. indexPanelA.add(finish_ng_bt);
  696. JLabel lblNewLabel = new JLabel("A\u67AA");
  697. lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
  698. lblNewLabel.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  699. lblNewLabel.setBounds(204, 186, 166, 28);
  700. indexPanelA.add(lblNewLabel);
  701. JLabel lblNewLabel_1 = new JLabel("\u9884\u8BBE\u6570\u91CF");
  702. lblNewLabel_1.setFont(new Font("微软雅黑", Font.PLAIN, 18));
  703. lblNewLabel_1.setBounds(204, 241, 83, 34);
  704. indexPanelA.add(lblNewLabel_1);
  705. param1 = new JTextField();
  706. param1.setHorizontalAlignment(SwingConstants.CENTER);
  707. param1.setFont(new Font("微软雅黑", Font.PLAIN, 18));
  708. param1.setText("0");
  709. param1.setEditable(false);
  710. param1.setBounds(288, 241, 83, 34);
  711. indexPanelA.add(param1);
  712. param1.setColumns(10);
  713. JLabel lblNewLabel_1_1 = new JLabel("\u5B8C\u6210\u6570\u91CF");
  714. lblNewLabel_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 18));
  715. lblNewLabel_1_1.setBounds(204, 285, 83, 34);
  716. indexPanelA.add(lblNewLabel_1_1);
  717. param2 = new JTextField();
  718. param2.setHorizontalAlignment(SwingConstants.CENTER);
  719. param2.setFont(new Font("微软雅黑", Font.PLAIN, 18));
  720. param2.setText("0");
  721. param2.setEditable(false);
  722. param2.setColumns(10);
  723. param2.setBounds(288, 285, 83, 34);
  724. indexPanelA.add(param2);
  725. JLabel lblB = new JLabel("B\u67AA");
  726. lblB.setHorizontalAlignment(SwingConstants.CENTER);
  727. lblB.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  728. lblB.setBounds(525, 186, 166, 28);
  729. indexPanelA.add(lblB);
  730. JLabel lblNewLabel_1_2 = new JLabel("\u9884\u8BBE\u6570\u91CF");
  731. lblNewLabel_1_2.setFont(new Font("微软雅黑", Font.PLAIN, 18));
  732. lblNewLabel_1_2.setBounds(525, 241, 83, 34);
  733. indexPanelA.add(lblNewLabel_1_2);
  734. param3 = new JTextField();
  735. param3.setText("0");
  736. param3.setHorizontalAlignment(SwingConstants.CENTER);
  737. param3.setFont(new Font("微软雅黑", Font.PLAIN, 18));
  738. param3.setEditable(false);
  739. param3.setColumns(10);
  740. param3.setBounds(608, 241, 83, 34);
  741. indexPanelA.add(param3);
  742. JLabel lblNewLabel_1_1_1 = new JLabel("\u5B8C\u6210\u6570\u91CF");
  743. lblNewLabel_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 18));
  744. lblNewLabel_1_1_1.setBounds(525, 285, 83, 34);
  745. indexPanelA.add(lblNewLabel_1_1_1);
  746. param4 = new JTextField();
  747. param4.setText("0");
  748. param4.setHorizontalAlignment(SwingConstants.CENTER);
  749. param4.setFont(new Font("微软雅黑", Font.PLAIN, 18));
  750. param4.setEditable(false);
  751. param4.setColumns(10);
  752. param4.setBounds(608, 285, 83, 34);
  753. indexPanelA.add(param4);
  754. resetResultA = new JButton("重拉");
  755. resetResultA.addActionListener(new ActionListener() {
  756. public void actionPerformed(ActionEvent e) {
  757. log.info("【A枪操作】点击了 [重拉] 按钮,当前产品SN: {}", product_sn.getText());
  758. if(zdStatusA == 1){
  759. log.info("【NG审核检查】准备校验 A枪 NG中断数据, SN: {}", product_sn.getText());
  760. JSONObject retObj = DataUtil.checkNgData(product_sn.getText(),"A");
  761. log.info("【NG审核检查】校验返回结果: {}", retObj != null ? retObj.toJSONString() : "null");
  762. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  763. MesClient.zdStatusA = 0;
  764. MesClient.resetResultA.setEnabled(false);
  765. MesClient.okResultA.setEnabled(false);
  766. MesClient.ngResultA.setEnabled(false);
  767. MesClient.sortA = (short) (MesClient.sortA - 1);
  768. MesClient.param2.setText(MesClient.sortA+"");
  769. plcA.writeInt16(1136,MesClient.sortA);
  770. MesClient.foutA = "";
  771. MesClient.soutA = "";
  772. MesClient.fmaxA = "";
  773. MesClient.fminA = "";
  774. MesClient.smaxA = "";
  775. MesClient.sminA = "";
  776. MesClient.curA = "";
  777. ModbusUtil.setPowerOn(plcA);
  778. }else{
  779. MesClient.setMenuStatus("NG中断未审核",-1);
  780. }
  781. }
  782. }
  783. });
  784. resetResultA.setEnabled(false);
  785. resetResultA.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  786. resetResultA.setBounds(52, 331, 100, 40);
  787. indexPanelA.add(resetResultA);
  788. okResultA = new JButton("OK");
  789. okResultA.addActionListener(new ActionListener() {
  790. public void actionPerformed(ActionEvent e) {
  791. log.info("【A枪操作】点击了 [OK] 按钮,当前产品SN: {}", product_sn.getText());
  792. if(zdStatusA == 1){
  793. log.info("【NG审核检查】准备校验 A枪 NG中断数据, SN: {}", product_sn.getText());
  794. JSONObject retObj = DataUtil.checkNgData(product_sn.getText(),"A");
  795. log.info("【NG审核检查】校验返回结果: {}", retObj != null ? retObj.toJSONString() : "null");
  796. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  797. if(!MesClient.product_sn.getText().isEmpty()){
  798. MesClient.aFinish++;
  799. JdbcUtils.insertProdData(MesClient.mes_gw, MesClient.mes_line_sn, MesClient.product_sn.getText(),"A",foutA,soutA,fminA,sminA,fmaxA,smaxA,"1",curA+"", MesClient.user_menu.getText());
  800. }
  801. MesClient.zdStatusA = 0;
  802. MesClient.resetResultA.setEnabled(false);
  803. MesClient.okResultA.setEnabled(false);
  804. MesClient.ngResultA.setEnabled(false);
  805. MesClient.foutA = "";
  806. MesClient.soutA = "";
  807. MesClient.fmaxA = "";
  808. MesClient.fminA = "";
  809. MesClient.smaxA = "";
  810. MesClient.sminA = "";
  811. MesClient.curA = "";
  812. ModbusUtil.upResult();
  813. ModbusUtil.setPowerOn(plcA);
  814. }else{
  815. MesClient.setMenuStatus("NG中断未审核",-1);
  816. }
  817. }
  818. }
  819. });
  820. okResultA.setEnabled(false);
  821. okResultA.setForeground(new Color(0, 128, 0));
  822. okResultA.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  823. okResultA.setBounds(176, 331, 100, 40);
  824. indexPanelA.add(okResultA);
  825. ngResultA = new JButton("NG");
  826. ngResultA.addActionListener(new ActionListener() {
  827. public void actionPerformed(ActionEvent e) {
  828. log.info("【A枪操作】点击了 [NG] 按钮,当前产品SN: {}", product_sn.getText());
  829. if(zdStatusA == 1){
  830. log.info("【NG审核检查】准备校验 A枪 NG中断数据, SN: {}", product_sn.getText());
  831. JSONObject retObj = DataUtil.checkNgData(product_sn.getText(),"A");
  832. log.info("【NG审核检查】校验返回结果: {}", retObj != null ? retObj.toJSONString() : "null");
  833. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  834. if(!MesClient.product_sn.getText().isEmpty()){
  835. JdbcUtils.insertProdData(MesClient.mes_gw, MesClient.mes_line_sn, MesClient.product_sn.getText(),"A",foutA,soutA,fminA,sminA,fmaxA,smaxA,"0",curA+"", MesClient.user_menu.getText());
  836. }
  837. MesClient.zdStatusA = 0;
  838. MesClient.resetResultA.setEnabled(false);
  839. MesClient.okResultA.setEnabled(false);
  840. MesClient.ngResultA.setEnabled(false);
  841. MesClient.foutA = "";
  842. MesClient.soutA = "";
  843. MesClient.fmaxA = "";
  844. MesClient.fminA = "";
  845. MesClient.smaxA = "";
  846. MesClient.sminA = "";
  847. MesClient.curA = "";
  848. ModbusUtil.upResult();
  849. ModbusUtil.setPowerOn(plcA);
  850. }else{
  851. MesClient.setMenuStatus("NG中断未审核",-1);
  852. }
  853. }
  854. }
  855. });
  856. ngResultA.setEnabled(false);
  857. ngResultA.setForeground(new Color(255, 0, 0));
  858. ngResultA.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  859. ngResultA.setBounds(303, 331, 100, 40);
  860. indexPanelA.add(ngResultA);
  861. resetResultB = new JButton("重拉");
  862. resetResultB.addActionListener(new ActionListener() {
  863. public void actionPerformed(ActionEvent e) {
  864. log.info("【B枪操作】点击了 [重拉] 按钮,当前产品SN: {}", product_sn.getText());
  865. if(zdStatusB == 1){
  866. log.info("【NG审核检查】准备校验 B枪 NG中断数据, SN: {}", product_sn.getText());
  867. JSONObject retObj = DataUtil.checkNgData(product_sn.getText(),"B");
  868. log.info("【NG审核检查】校验返回结果: {}", retObj != null ? retObj.toJSONString() : "null");
  869. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  870. MesClient.zdStatusB = 0;
  871. MesClient.resetResultB.setEnabled(false);
  872. MesClient.okResultB.setEnabled(false);
  873. MesClient.ngResultB.setEnabled(false);
  874. MesClient.sortB = (short) (MesClient.sortB - 1);
  875. MesClient.param4.setText(MesClient.sortB+"");
  876. plcB.writeInt16(1136,MesClient.sortB);
  877. MesClient.foutB = "";
  878. MesClient.soutB = "";
  879. MesClient.fmaxB = "";
  880. MesClient.fminB = "";
  881. MesClient.smaxB = "";
  882. MesClient.sminB = "";
  883. MesClient.curB = "";
  884. ModbusUtil.setPowerOn(plcB);
  885. }else{
  886. MesClient.setMenuStatus("NG中断未审核",-1);
  887. }
  888. }
  889. }
  890. });
  891. resetResultB.setEnabled(false);
  892. resetResultB.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  893. resetResultB.setBounds(595, 331, 100, 40);
  894. indexPanelA.add(resetResultB);
  895. okResultB = new JButton("OK");
  896. okResultB.addActionListener(new ActionListener() {
  897. public void actionPerformed(ActionEvent e) {
  898. log.info("【B枪操作】点击了 [OK] 按钮,当前产品SN: {}", product_sn.getText());
  899. if(zdStatusB == 1){
  900. log.info("【NG审核检查】准备校验 B枪 NG中断数据, SN: {}", product_sn.getText());
  901. JSONObject retObj = DataUtil.checkNgData(product_sn.getText(),"B");
  902. log.info("【NG审核检查】校验返回结果: {}", retObj != null ? retObj.toJSONString() : "null");
  903. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  904. if(!MesClient.product_sn.getText().isEmpty()){
  905. MesClient.bFinish++;
  906. JdbcUtils.insertProdData(MesClient.mes_gw, MesClient.mes_line_sn, MesClient.product_sn.getText(),"B",foutB,soutB,fminB,sminB,fmaxB,smaxB,"1",curB+"", MesClient.user_menu.getText());
  907. }
  908. MesClient.zdStatusB = 0;
  909. MesClient.resetResultB.setEnabled(false);
  910. MesClient.okResultB.setEnabled(false);
  911. MesClient.ngResultB.setEnabled(false);
  912. MesClient.foutB = "";
  913. MesClient.soutB = "";
  914. MesClient.fmaxB = "";
  915. MesClient.fminB = "";
  916. MesClient.smaxB = "";
  917. MesClient.sminB = "";
  918. MesClient.curB = "";
  919. ModbusUtil.setPowerOn(plcB);
  920. ModbusUtil.upResult();
  921. }else{
  922. MesClient.setMenuStatus("NG中断未审核",-1);
  923. }
  924. }
  925. }
  926. });
  927. okResultB.setEnabled(false);
  928. okResultB.setForeground(new Color(0, 128, 0));
  929. okResultB.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  930. okResultB.setBounds(718, 331, 100, 40);
  931. indexPanelA.add(okResultB);
  932. ngResultB = new JButton("NG");
  933. ngResultB.addActionListener(new ActionListener() {
  934. public void actionPerformed(ActionEvent e) {
  935. log.info("【B枪操作】点击了 [NG] 按钮,当前产品SN: {}", product_sn.getText());
  936. if(zdStatusB == 1){
  937. log.info("【NG审核检查】准备校验 B枪 NG中断数据, SN: {}", product_sn.getText());
  938. JSONObject retObj = DataUtil.checkNgData(product_sn.getText(),"B");
  939. log.info("【NG审核检查】校验返回结果: {}", retObj != null ? retObj.toJSONString() : "null");
  940. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  941. if(!MesClient.product_sn.getText().isEmpty()){
  942. JdbcUtils.insertProdData(MesClient.mes_gw, MesClient.mes_line_sn, MesClient.product_sn.getText(),"B",foutA,soutA,fminA,sminA,fmaxA,smaxA,"0",curA+"", MesClient.user_menu.getText());
  943. }
  944. MesClient.zdStatusB = 0;
  945. MesClient.resetResultB.setEnabled(false);
  946. MesClient.okResultB.setEnabled(false);
  947. MesClient.ngResultB.setEnabled(false);
  948. MesClient.foutB = "";
  949. MesClient.soutB = "";
  950. MesClient.fmaxB = "";
  951. MesClient.fminB = "";
  952. MesClient.smaxB = "";
  953. MesClient.sminB = "";
  954. MesClient.curB = "";
  955. ModbusUtil.setPowerOn(plcB);
  956. ModbusUtil.upResult();
  957. }else{
  958. MesClient.setMenuStatus("NG中断未审核",-1);
  959. }
  960. }
  961. }
  962. });
  963. ngResultB.setEnabled(false);
  964. ngResultB.setForeground(Color.RED);
  965. ngResultB.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  966. ngResultB.setBounds(839, 331, 100, 40);
  967. indexPanelA.add(ngResultB);
  968. tabbedPane.addTab("工作面板", new ImageIcon(MesClient.class.getResource("/bg/a_side.png")), indexScrollPaneA, null);
  969. tabbedPane.setEnabledAt(0, true);
  970. // searchScrollPane = new JScrollPane((Component) null);
  971. indexPanelC = new JPanel();
  972. searchScrollPaneDj = new JScrollPane(indexPanelC);
  973. indexPanelC.setLayout(null);
  974. tabbedPane.addTab("开班点检", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPaneDj, null);
  975. indexPanelB = new JPanel();
  976. searchScrollPane = new JScrollPane(indexPanelB);
  977. indexPanelB.setLayout(null);
  978. tabbedPane.addTab("工作记录", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPane, null);
  979. tabbedPane.addChangeListener(new ChangeListener() {
  980. @Override
  981. public void stateChanged(ChangeEvent e) {
  982. JTabbedPane tabbedPane = (JTabbedPane) e.getSource();
  983. int selectedIndex = tabbedPane.getSelectedIndex();
  984. System.out.println("selectedIndex:"+selectedIndex);
  985. if(selectedIndex == 1){
  986. }
  987. }
  988. });
  989. }
  990. public static void setMenuStatus(String msg,int error){
  991. if(error == 0){
  992. MesClient.status_menu.setForeground(Color.GREEN);
  993. }else{
  994. MesClient.status_menu.setForeground(Color.RED);
  995. }
  996. MesClient.status_menu.setText(msg);
  997. }
  998. public static void getMaterailData(){
  999. JSONObject retObj = DataUtil.getBindMaterail();
  1000. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  1001. java.util.List<BindMaterialResp> arrs = retObj.getList("data",BindMaterialResp.class);
  1002. int i = 0;
  1003. rowData = new Object[arrs.size()][7];
  1004. for (BindMaterialResp bindMaterialResp:arrs){
  1005. rowData[i][0] = bindMaterialResp.getMaterialTitle();
  1006. rowData[i][1] = bindMaterialResp.getBatchSn();
  1007. rowData[i][2] = bindMaterialResp.getLastTimes();
  1008. rowData[i][3] = "";
  1009. rowData[i][4] = bindMaterialResp.getCraft();
  1010. rowData[i][5] = bindMaterialResp.getMaterialId();
  1011. rowData[i][6] = bindMaterialResp.getType();
  1012. i++;
  1013. }
  1014. bindBatchPanel();
  1015. }
  1016. }
  1017. public static void updateMaterailData(){
  1018. JSONObject retObj = DataUtil.getBindMaterail();
  1019. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  1020. List<BindMaterialResp> arrs = retObj.getList("data",BindMaterialResp.class);
  1021. int i = 0;
  1022. for (BindMaterialResp bindMaterialResp:arrs){
  1023. rowData[i][0] = bindMaterialResp.getMaterialTitle();
  1024. rowData[i][1] = bindMaterialResp.getBatchSn();
  1025. rowData[i][2] = bindMaterialResp.getLastTimes();
  1026. rowData[i][3] = "";
  1027. rowData[i][4] = bindMaterialResp.getCraft();
  1028. rowData[i][5] = bindMaterialResp.getMaterialId();
  1029. rowData[i][6] = bindMaterialResp.getType();
  1030. i++;
  1031. }
  1032. MesClient.table.repaint();
  1033. }
  1034. }
  1035. // 绑定物料批次码
  1036. public static void scanBatchSn(BindMaterialResp bindMaterialResp) {
  1037. //弹窗扫工件码
  1038. String scanBarcodeTitle = "请扫物料:"+bindMaterialResp.getMaterialTitle();
  1039. String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
  1040. if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")) {
  1041. JSONObject retObj = DataUtil.saveBindMaterail(scanBarcode,bindMaterialResp.getCraft(),bindMaterialResp.getMaterialId(),bindMaterialResp.getType());
  1042. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  1043. MesClient.setMenuStatus("扫物料:"+bindMaterialResp.getMaterialTitle()+"成功",0);
  1044. updateMaterailData();
  1045. }else{
  1046. if(retObj.get("result")==null){
  1047. MesClient.setMenuStatus("请求失败,请重试",-1);
  1048. }else{
  1049. if(retObj.get("result").toString().equalsIgnoreCase("false")){
  1050. MesClient.setMenuStatus(retObj.getString("message"),-1);
  1051. }
  1052. }
  1053. }
  1054. }
  1055. }
  1056. public static void bindBatchPanel(){
  1057. JPanel indexPanelBB = new JPanel();
  1058. JPanel panel = new JPanel();
  1059. panel.setBounds(0, 0, 990, 550);
  1060. // panel.setBounds(81, 50, 810, 479);
  1061. indexPanelBB.add(panel);
  1062. panel.setLayout(new GridLayout(0, 1, 0, 0));
  1063. table = new JTable(rowData, columnNames){
  1064. public boolean isCellEditable(int row, int column) {
  1065. if(column == 3){
  1066. return true;
  1067. }
  1068. return false;
  1069. }
  1070. };
  1071. table.setRowHeight(40);
  1072. table.setEnabled(true);
  1073. table.setFont(new Font("微软雅黑", Font.PLAIN, 14));
  1074. table.getColumnModel().getColumn(3).setCellRenderer(new TableCellRendererButton());
  1075. table.getColumnModel().getColumn(3).setCellEditor(new TableCellEditorButton());
  1076. JScrollPane scrollPane = new JScrollPane(table);
  1077. panel.add(scrollPane);
  1078. JScrollPane indexScrollPaneB = new JScrollPane(indexPanelBB);
  1079. indexPanelBB.setLayout(null);
  1080. tabbedPane.addTab("绑定物料", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), indexScrollPaneB, null);
  1081. }
  1082. }