MesClient.java 46 KB

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