MesClient.java 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672
  1. package com.mes.ui;
  2. import com.alibaba.fastjson2.JSON;
  3. import com.alibaba.fastjson2.JSONArray;
  4. import com.alibaba.fastjson2.JSONObject;
  5. import com.github.s7connector.impl.utils.S7Utils;
  6. import com.github.xingshuangs.iot.protocol.modbus.service.ModbusTcp;
  7. import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType;
  8. import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
  9. import com.mes.component.MesRadio;
  10. import com.mes.component.MesWebView;
  11. import com.mes.component.MyDialog;
  12. import com.mes.netty.NettyClient;
  13. import com.mes.util.DateLocalUtils;
  14. import com.mes.util.HttpUtils;
  15. import com.mes.util.JdbcUtils;
  16. import javafx.embed.swing.JFXPanel;
  17. import org.slf4j.Logger;
  18. import org.slf4j.LoggerFactory;
  19. import javax.swing.*;
  20. import javax.swing.border.EmptyBorder;
  21. import java.awt.*;
  22. import java.awt.event.ActionEvent;
  23. import java.awt.event.ActionListener;
  24. import java.awt.event.MouseAdapter;
  25. import java.awt.event.MouseEvent;
  26. import java.io.BufferedReader;
  27. import java.io.IOException;
  28. import java.io.InputStream;
  29. import java.io.InputStreamReader;
  30. import java.sql.ResultSet;
  31. import java.sql.SQLException;
  32. import java.sql.Statement;
  33. import java.time.LocalDateTime;
  34. import java.util.ArrayList;
  35. import java.util.Properties;
  36. import java.util.Timer;
  37. import java.util.TimerTask;
  38. import java.util.List;
  39. public class MesClient extends JFrame {
  40. public static final Logger log = LoggerFactory.getLogger(MesClient.class);
  41. private static String Drivde = "org.sqlite.JDBC";
  42. public static int mes_auth = 0;
  43. public static String mes_gw = "";
  44. public static String mes_gw_des = "";
  45. public static String mes_server_ip = "";
  46. public static int mes_tcp_port = 3000;
  47. public static int mes_heart_beat_cycle = 10;
  48. public static int mes_heart_icon_cycle = 1;
  49. public static String mes_line_sn = "";
  50. public static String mes_gwflag = ""; // 工位标识
  51. public static NettyClient nettyClient;
  52. public static boolean tcp_connect_flag = false;
  53. public static boolean connect_request_flag = false;
  54. //session
  55. public static String sessionid = "";
  56. public static JPanel contentPane;
  57. public static MesClient mesClientFrame;
  58. public static JTabbedPane tabbedPane;
  59. public static JScrollPane indexScrollPaneA;
  60. public static JScrollPane indexScrollPaneB;
  61. public static JScrollPane searchScrollPane;
  62. public static JScrollPane searchScrollPaneGz;
  63. public static JScrollPane searchScrollPaneDj;
  64. public static Boolean check_quality_result = false;
  65. public static Integer work_status = 0;
  66. public static Integer work_status2 = 0;
  67. public static Boolean check_quality_result2 = false;
  68. public static Integer batch_status = 0; //A面 1=已绑定 0=未绑定
  69. public static Integer batch_status2 = 0; //B面 1=已绑定 0=未绑定
  70. public static JButton heart_beat_menu;
  71. public static JButton status_menu;
  72. public static JButton user_menu;
  73. public static int scan_type = 0;
  74. public static JButton finish_ok_bt;
  75. public static JButton finish_ok_bt2;
  76. public static JButton finish_ng_bt;
  77. public static JButton finish_ng_bt2;
  78. public static JTextField product_sn;
  79. public static JLabel pxstatus1;
  80. public static JLabel pxstatus2;
  81. public static JButton batch_scan_1;
  82. public static JButton batch_scan_2;
  83. public static Integer tjFlag = 0; // 0=未开始 1=已扫码,设备未启动 2=设备运行中 3=设备运行结束
  84. public static Integer tjFlaga = 0; // 0=未开始 1=已扫码,设备未启动 2=设备运行中 3=设备运行结束
  85. public static Integer tjFlagb = 0; // 0=未开始 1=已扫码,设备未启动 2=设备运行中 3=设备运行结束
  86. public static Integer tjStatusa = 0; // 1=提交失败
  87. public static Integer tjStatusb = 0; // 1=提交失败
  88. public static String curFlag = ""; // 当前工作的面板
  89. public static String curSna = "";
  90. public static String curSnb = "";
  91. public static String curPage = "";
  92. public static Integer checkA = 0;
  93. public static Integer checkB = 0;
  94. public static Integer lastpage = 0;
  95. public static Boolean mesQualityFlagA = false; // true=可工作
  96. public static Boolean mesQualityFlagB = false; // true=可工作
  97. public static Boolean mesErrorFlagA = false; // true=提交MES失败,手动提交
  98. public static Boolean mesErrorFlagB = false; // true=提交MES失败,手动提交
  99. public static String user20 = "";
  100. public static JFrame welcomeWin;
  101. public static JPanel indexPanelB;
  102. public static JPanel indexPanelC;
  103. public static MesWebView jfxPanel = null;
  104. public static MesWebView jfxPanel2 = null;
  105. public static MesRadio mesRadioHj;
  106. public static S7PLC s7PLC = new S7PLC(EPlcType.S1200, "10.85.10.131"); //100 AB工位
  107. public static List<String> hjparams = new ArrayList<>();
  108. public static JTable table;
  109. public static Object[] columnNames = { "物料名称", "绑定批次", "剩余次数", "操作" };
  110. public static Object[][] rowData = null;
  111. // public static Object[][] rowData = {
  112. // };
  113. public static void main(String[] args) {
  114. EventQueue.invokeLater(new Runnable() {
  115. @Override
  116. public void run() {
  117. try{
  118. //鐠囩粯鏋冩禒鍫曞帳缂冿拷
  119. readProperty();
  120. // 设置连接超时为500ms,读取超时为500ms,避免长时间阻塞
  121. s7PLC.setConnectTimeout(1000);
  122. s7PLC.setReceiveTimeout(1000);
  123. // 閺勫墽銇氶悾宀勬桨
  124. mesClientFrame = new MesClient();
  125. mesClientFrame.setVisible(false);
  126. JdbcUtils.getConn();
  127. welcomeWin = new LoginFarme();
  128. welcomeWin.setVisible(true);
  129. getMaterailData();
  130. log.info("--------------------------------------"+sessionid);
  131. //获取当前面
  132. textFocus();
  133. getPlcParam();
  134. //
  135. // upParams();
  136. //
  137. getPlcParams();
  138. }catch (Exception e){
  139. e.printStackTrace();
  140. }
  141. }
  142. });
  143. }
  144. public static Timer cjTimerText;
  145. public static void textFocus() {
  146. if(cjTimerText!=null) {
  147. cjTimerText.cancel();
  148. }
  149. cjTimerText = new Timer();
  150. cjTimerText.schedule(new TimerTask() {
  151. public void run() {
  152. txtfa.requestFocusInWindow();
  153. MesClient.curPage = PlcUtil.getCurAside(s7PLC);
  154. if(MesClient.curPage .equals("A")){
  155. page_text.setText("当前:A面");
  156. }else{
  157. page_text.setText("当前:B面");
  158. }
  159. }
  160. }, 1000,1000);
  161. }
  162. public static Timer cjTimer3;
  163. public static void upParams() {
  164. if(cjTimer3!=null) {
  165. cjTimer3.cancel();
  166. }
  167. cjTimer3 = new Timer();
  168. cjTimer3.schedule(new TimerTask() {
  169. public void run() {
  170. try{
  171. List<CmtReq> prods = JdbcUtils.getCmtParams();
  172. System.out.println("prods:"+ JSON.toJSONString(prods));
  173. if(prods.size() > 0){
  174. // 定时上传参数
  175. JSONObject retObj = DataUtil.upParams(JSON.toJSONString(prods));
  176. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  177. // 更新sqlite已同步
  178. for(CmtReq prodReq:prods){
  179. JdbcUtils.updateProdSync(prodReq.getId(),1);
  180. }
  181. }
  182. }
  183. }catch (Exception e){
  184. e.printStackTrace();
  185. }
  186. }
  187. }, 1000,30*1000);
  188. }
  189. public static Timer cjTimer;
  190. public static void getPlcParam() {
  191. if(cjTimer!=null) {
  192. cjTimer.cancel();
  193. }
  194. cjTimer = new Timer();
  195. cjTimer.schedule(new TimerTask() {
  196. public void run() {
  197. try{
  198. if(!MesClient.sessionid.isEmpty()){
  199. PlcUtil.getStatusA(s7PLC);
  200. log.info("获取A面状态");
  201. }
  202. }catch (Exception e){
  203. e.printStackTrace();
  204. }
  205. try{
  206. if(!MesClient.sessionid.isEmpty()){
  207. PlcUtil.getStatusB(s7PLC);
  208. log.info("获取B面状态");
  209. }
  210. }catch (Exception e){
  211. e.printStackTrace();
  212. }
  213. }
  214. }, 1000,2000);
  215. }
  216. public static Timer cjTimer2;
  217. public static void getPlcParams() {
  218. if(cjTimer2!=null) {
  219. cjTimer2.cancel();
  220. }
  221. cjTimer2 = new Timer();
  222. cjTimer2.schedule(new TimerTask() {
  223. public void run() {
  224. try{
  225. log.info("获取电压电流参数");
  226. PlcUtil.getParamDyDl(s7PLC);
  227. log.info("获取电压电流参数");
  228. }catch (Exception e){
  229. e.printStackTrace();
  230. }
  231. }
  232. }, 1000,500);
  233. }
  234. //鐠囧鍘ょ純顔芥瀮娴狅拷
  235. private static void readProperty() throws IOException{
  236. String enconding = "UTF-8";
  237. InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
  238. Properties pro = new Properties();
  239. BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
  240. pro.load(br);
  241. mes_gw = pro.getProperty("mes.gw");
  242. // mes_gw_des = pro.getProperty("mes.gw_des");
  243. mes_server_ip = pro.getProperty("mes.server_ip");
  244. mes_tcp_port = Integer.parseInt(pro.getProperty("mes.tcp_port"));
  245. mes_heart_beat_cycle = Integer.parseInt(pro.getProperty("mes.heart_beat_cycle"));
  246. mes_line_sn = pro.getProperty("mes.line_sn");
  247. mes_gw_des = OprnoUtil.getGwDes(mes_line_sn,mes_gw);
  248. mes_gwflag = pro.getProperty("mes.gwflag");
  249. System.out.println(mes_gw + ";" + mes_gw_des + ";" + mes_server_ip + ";" + mes_tcp_port + ";" + mes_heart_beat_cycle);
  250. }
  251. // 閸掓繂顫愰崠鏈P
  252. public static void initTcpConnection() {
  253. try {
  254. if(nettyClient==null) {
  255. //閸掓繂顫愰崠鏈P鏉╃偞甯�
  256. nettyClient = new NettyClient();
  257. //TCP鏉╃偞甯撮悩鑸碉拷锟�
  258. tcp_connect_flag = false;
  259. //鐠佸墽鐤員CP鐠囬攱鐪伴悩鑸碉拷锟�
  260. connect_request_flag = true;
  261. DataUtil.synrTcp(nettyClient,mes_gw);
  262. }
  263. } catch (Exception e) {
  264. // TODO Auto-generated catch block
  265. e.printStackTrace();
  266. }
  267. }
  268. //閸氼垰濮╄箛鍐儲閸栧懐鈻兼惔锟�
  269. public static java.util.Timer heartBeatTimer;
  270. public static java.util.Timer heartBeatIconTimer;
  271. public static boolean iconREDFlag = true;
  272. private static final long BUSINESS_STATUS_HOLD_MILLIS = 5000L;
  273. private static final long QUALITY_REPLY_TIMEOUT_MILLIS = 5000L;
  274. private static volatile long lastBusinessStatusTime = 0L;
  275. private static volatile boolean waitingQualityReply = false;
  276. private static String waitingQualitySn = "";
  277. private static String waitingQualityPage = "";
  278. private static Timer qualityReplyTimer;
  279. public static JTextField param1;
  280. public static JTextField param2;
  281. public static JTextField param3;
  282. public static JTextField param4;
  283. public static JTextField param5;
  284. public static JTextField product_sn2;
  285. public static JTextField param21;
  286. public static JTextField param22;
  287. public static JTextField param23;
  288. public static JTextField param24;
  289. public static JTextField param25;
  290. public static void startHeartBeatTimer() {
  291. if(heartBeatTimer!=null) {
  292. heartBeatTimer.cancel();
  293. }
  294. heartBeatTimer = new java.util.Timer();
  295. heartBeatTimer.schedule(new TimerTask() {
  296. public void run() {
  297. if(nettyClient!=null&&tcp_connect_flag) {
  298. //System.out.println("閸欐垿锟戒礁绺剧捄铏Г閺傦拷");
  299. DataUtil.heartBeat(nettyClient,mes_gw);
  300. heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
  301. }
  302. }
  303. }, 100,mes_heart_beat_cycle*1000);
  304. //韫囧啳鐑﹂弰鍓с仛閸ョ偓鐖�
  305. if(heartBeatIconTimer!=null) {
  306. heartBeatIconTimer.cancel();
  307. }
  308. heartBeatIconTimer = new Timer();
  309. heartBeatIconTimer.schedule(new TimerTask() {
  310. public void run() {
  311. if(tcp_connect_flag) {
  312. if(iconREDFlag) {
  313. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  314. iconREDFlag = false;
  315. }else {
  316. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
  317. iconREDFlag = true;
  318. }
  319. heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
  320. heart_beat_menu.repaint();
  321. }else {
  322. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  323. heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
  324. heart_beat_menu.repaint();
  325. //閼汇儲婀潻鐐村复閸掓瑥鐨剧拠鏇$箾閹猴拷
  326. if(nettyClient!=null&&!tcp_connect_flag){
  327. System.out.println("TCP瀹稿弶鏌囧锟�");
  328. //TCP闁插秵鏌婇崥灞绢劄鏉╃偞甯�
  329. if(!connect_request_flag) {
  330. //System.out.println("TCP闁插秵鏌婇崥灞绢劄鏉╃偞甯�");
  331. //鐠佸墽鐤員CP鐠囬攱鐪伴悩鑸碉拷锟�,閸欘亪鍣搁弬鏉挎倱濮濄儴绻涢幒銉ょ濞嗭拷
  332. connect_request_flag = true;
  333. DataUtil.synrTcp(nettyClient,mes_gw);
  334. }
  335. }
  336. }
  337. }
  338. }, 100,mes_heart_icon_cycle*1000);
  339. }
  340. //鐠佸墽鐤唗cp鏉╃偞甯撮悩鑸碉拷浣规▔缁�锟�
  341. public static void setTcpStatus() {
  342. boolean updateStatusText = status_menu != null && !isBusinessStatusHolding();
  343. if(tcp_connect_flag) {
  344. if(updateStatusText) {
  345. status_menu.setForeground(Color.GREEN);
  346. status_menu.setText("已连接MES服务器");
  347. }
  348. if(heart_beat_menu != null) {
  349. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  350. heart_beat_menu.repaint();
  351. }
  352. }else {
  353. if(updateStatusText) {
  354. status_menu.setForeground(Color.RED);
  355. status_menu.setText("未连接MES服务器");
  356. }
  357. if(heart_beat_menu != null) {
  358. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  359. heart_beat_menu.repaint();
  360. }
  361. }
  362. }
  363. private static boolean isBusinessStatusHolding(){
  364. return System.currentTimeMillis() - lastBusinessStatusTime < BUSINESS_STATUS_HOLD_MILLIS;
  365. }
  366. public static void initWarehouseData(){
  367. resetScanA();
  368. resetScanB();
  369. PlcUtil.changeEnable(s7PLC,false);
  370. }
  371. public static void resetScanA() {
  372. work_status = 0;
  373. check_quality_result = false;
  374. MesClient.finish_ok_bt.setEnabled(false);
  375. MesClient.mesQualityFlagA = false;
  376. product_sn.setText("");
  377. MesClient.pxstatus1.setText("A");
  378. MesClient.param1.setText("");
  379. MesClient.param2.setText("");
  380. MesClient.param3.setText("");
  381. MesClient.param4.setText("");
  382. MesClient.param5.setText("");
  383. MesClient.param21.setText("");
  384. MesClient.param22.setText("");
  385. MesClient.param23.setText("");
  386. MesClient.param24.setText("");
  387. MesClient.param25.setText("");
  388. MesClient.curSna = "";
  389. MesClient.tjFlaga = 0;
  390. MesClient.checkA = 0;
  391. MesClient.textField.setText("");
  392. MesClient.batch_scan_1.setEnabled(false);
  393. MesClient.formatScanType(1);
  394. PlcUtil.changeEnable(MesClient.s7PLC,false);
  395. finish_ok_bt.setEnabled(false);
  396. finish_ng_bt.setEnabled(false);
  397. updateMaterailData(); // 更新物料
  398. shiftUserCheck();
  399. }
  400. public static int userLoginHours;//用户登录所处小时
  401. public static JTextField textField;
  402. public static JTextField textField_1;
  403. public static JTextField txtfa;
  404. public static JLabel scan_type_text;
  405. public static JLabel page_text;
  406. //换班用户信息检查
  407. private static void shiftUserCheck() {
  408. LocalDateTime now = LocalDateTime.now();
  409. // 判断时间范围
  410. if (userLoginHours >= 8 && userLoginHours < 20) {
  411. int hour = now.getHour();
  412. if (hour >= 20 || hour < 8) {
  413. logoff();
  414. }
  415. } else {
  416. int hour = now.getHour();
  417. if (hour >= 8 && hour < 20) {
  418. logoff();
  419. }
  420. }
  421. }
  422. public static void resetScanB() {
  423. work_status2 = 0;
  424. check_quality_result2 = false;
  425. MesClient.finish_ng_bt.setEnabled(false);
  426. MesClient.mesQualityFlagB = false;
  427. product_sn2.setText("");
  428. MesClient.pxstatus2.setText("B");
  429. MesClient.param1.setText("");
  430. MesClient.param2.setText("");
  431. MesClient.param3.setText("");
  432. MesClient.param4.setText("");
  433. MesClient.param5.setText("");
  434. MesClient.param21.setText("");
  435. MesClient.param22.setText("");
  436. MesClient.param23.setText("");
  437. MesClient.param24.setText("");
  438. MesClient.param25.setText("");
  439. MesClient.curSnb = "";
  440. MesClient.tjFlagb = 0;
  441. MesClient.checkB = 0;
  442. MesClient.textField_1.setText("");
  443. MesClient.batch_scan_2.setEnabled(false);
  444. MesClient.formatScanType(1);
  445. PlcUtil.changeEnable(MesClient.s7PLC,false);
  446. finish_ok_bt2.setEnabled(false);
  447. finish_ng_bt2.setEnabled(false);
  448. updateMaterailData(); // 更新物料
  449. // shiftUserCheck();
  450. }
  451. //閼惧嘲褰囬悽銊﹀煕20娴o拷
  452. public static void getUser() {
  453. user20 = user_menu.getText().toString();
  454. String space_tmp1 = "";
  455. if(user20.length()<20) {
  456. for(int i=0;i<20-user20.length();i++) {
  457. space_tmp1 = space_tmp1 + " ";
  458. }
  459. }
  460. user20 = user20 + space_tmp1;
  461. }
  462. //閼惧嘲褰嘼arcode閸愬懎顔�36娴o拷
  463. public static String getBarcode(String barcodeTmp) {
  464. String barcodeRet = barcodeTmp;
  465. if(barcodeTmp.equalsIgnoreCase("")) {
  466. return "";
  467. }else {
  468. if(barcodeTmp.length()<36) {
  469. String space = "";
  470. for(int i=0;i<36-barcodeTmp.length();i++) {
  471. space = space + " ";
  472. }
  473. barcodeRet = barcodeTmp + space;
  474. }
  475. }
  476. return barcodeRet;
  477. }
  478. public static boolean isValidLaserBarcode(String barcode){
  479. if(barcode == null){
  480. return false;
  481. }
  482. String sn = barcode.trim();
  483. return sn.length() >= 22 && sn.length() <= 36 && sn.matches("[A-Za-z0-9]+");
  484. }
  485. public static synchronized void beginQualityCheck(String sn, String page){
  486. waitingQualityReply = true;
  487. waitingQualitySn = sn == null ? "" : sn.trim();
  488. waitingQualityPage = page == null ? "" : page;
  489. if(qualityReplyTimer != null){
  490. qualityReplyTimer.cancel();
  491. }
  492. qualityReplyTimer = new Timer();
  493. final String checkSn = waitingQualitySn;
  494. final String checkPage = waitingQualityPage;
  495. qualityReplyTimer.schedule(new TimerTask() {
  496. @Override
  497. public void run() {
  498. failPendingQualityCheck(checkSn, checkPage, "该工件未录入系统");
  499. }
  500. }, QUALITY_REPLY_TIMEOUT_MILLIS);
  501. }
  502. public static synchronized boolean finishQualityCheck(String sn){
  503. String checkSn = sn == null ? "" : sn.trim();
  504. if(!waitingQualityReply || !waitingQualitySn.equals(checkSn)){
  505. return false;
  506. }
  507. waitingQualityReply = false;
  508. waitingQualitySn = "";
  509. waitingQualityPage = "";
  510. if(qualityReplyTimer != null){
  511. qualityReplyTimer.cancel();
  512. qualityReplyTimer = null;
  513. }
  514. return true;
  515. }
  516. public static void failPendingQualityCheck(String msg){
  517. String sn;
  518. String page;
  519. synchronized (MesClient.class) {
  520. if(!waitingQualityReply){
  521. return;
  522. }
  523. sn = waitingQualitySn;
  524. page = waitingQualityPage;
  525. }
  526. failPendingQualityCheck(sn, page, msg);
  527. }
  528. private static void failPendingQualityCheck(String sn, String page, String msg){
  529. synchronized (MesClient.class) {
  530. if(!waitingQualityReply || !waitingQualitySn.equals(sn) || !waitingQualityPage.equals(page)){
  531. return;
  532. }
  533. waitingQualityReply = false;
  534. waitingQualitySn = "";
  535. waitingQualityPage = "";
  536. if(qualityReplyTimer != null){
  537. qualityReplyTimer.cancel();
  538. qualityReplyTimer = null;
  539. }
  540. }
  541. if("A".equals(page)){
  542. product_sn.setText("");
  543. check_quality_result = false;
  544. }else{
  545. product_sn2.setText("");
  546. check_quality_result2 = false;
  547. }
  548. PlcUtil.changeEnable(s7PLC,false);
  549. MesClient.setMenuStatus(msg,-1);
  550. }
  551. public static void logoff() {
  552. welcomeWin.setVisible(true);
  553. mesClientFrame.setVisible(false);
  554. nettyClient = null;
  555. if(heartBeatTimer!=null) {
  556. heartBeatTimer.cancel();
  557. }
  558. if(heartBeatIconTimer!=null) {
  559. heartBeatIconTimer.cancel();
  560. }
  561. tcp_connect_flag = false;
  562. connect_request_flag = false;
  563. }
  564. public MesClient() {
  565. setIconImage(Toolkit.getDefaultToolkit().getImage(MesClient.class.getResource("/bg/logo.png")));
  566. setTitle("MES系统客户端:"+mes_gw + "- " + mes_gw_des);
  567. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  568. setBounds(0, 0, 1024, 768);
  569. JMenuBar menuBar = new JMenuBar();
  570. menuBar.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 26));
  571. setJMenuBar(menuBar);
  572. JMenu fileMenu = new JMenu("\u7528\u6237");
  573. fileMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/user.png")));
  574. fileMenu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  575. menuBar.add(fileMenu);
  576. JMenuItem exitMenuItem = new JMenuItem("退出");
  577. exitMenuItem.setIcon(new ImageIcon(MesClient.class.getResource("/bg/logoff.png")));
  578. exitMenuItem.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
  579. fileMenu.add(exitMenuItem);
  580. exitMenuItem.addMouseListener(new MouseAdapter() {
  581. @Override
  582. public void mousePressed(MouseEvent e) {//閸欘亣鍏樺Λ锟藉ù瀣煂mousePressed娴滃娆�
  583. super.mouseClicked(e);
  584. //dispose();
  585. logoff();
  586. }
  587. });
  588. JMenu settingMenu = new JMenu("设置");
  589. //settingMenu.setVisible(false);
  590. settingMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")));
  591. settingMenu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  592. menuBar.add(settingMenu);
  593. JMenuItem resetTcpMenu = new JMenuItem("\u91CD\u8FDEMES");
  594. resetTcpMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  595. resetTcpMenu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  596. resetTcpMenu.addMouseListener(new MouseAdapter() {
  597. @Override
  598. public void mousePressed(MouseEvent e) {
  599. super.mouseClicked(e);
  600. //闁插秷绻沵es
  601. nettyClient.future.channel().close();
  602. }
  603. });
  604. settingMenu.add(resetTcpMenu);
  605. JMenuItem resetTcpMenu_1 = new JMenuItem("\u91CD\u65B0\u626B\u7801-A");
  606. resetTcpMenu_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  607. resetTcpMenu_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  608. resetTcpMenu_1.addMouseListener(new MouseAdapter() {
  609. @Override
  610. public void mousePressed(MouseEvent e) {
  611. super.mouseClicked(e);
  612. resetScanA();
  613. }
  614. });
  615. settingMenu.add(resetTcpMenu_1);
  616. JMenuItem resetTcpMenu_1_1 = new JMenuItem("\u91CD\u65B0\u626B\u7801-B");
  617. resetTcpMenu_1_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  618. resetTcpMenu_1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  619. resetTcpMenu_1_1.addMouseListener(new MouseAdapter() {
  620. @Override
  621. public void mousePressed(MouseEvent e) {
  622. super.mouseClicked(e);
  623. resetScanB();
  624. }
  625. });
  626. settingMenu.add(resetTcpMenu_1_1);
  627. JMenuItem resetTcpMenu_1sd = new JMenuItem("手动提交-A");
  628. resetTcpMenu_1sd.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  629. resetTcpMenu_1sd.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  630. resetTcpMenu_1sd.addMouseListener(new MouseAdapter() {
  631. @Override
  632. public void mousePressed(MouseEvent e) {
  633. super.mouseClicked(e);
  634. finish_ok_bt.setEnabled(true);
  635. finish_ng_bt.setEnabled(true);
  636. // MesClient.finish_ok_bt.setEnabled(true);
  637. // if(MesClient.work_status == 1){
  638. // Boolean sendret = DataUtil.sendQuality(MesClient.nettyClient,MesClient.product_sn.getText(),"OK",MesClient.user20,"A");
  639. // if(!sendret){
  640. // MesClient.pxstatus1.setText("A:结果上传MES失败");
  641. // MesClient.tjStatusa = 1;
  642. // }
  643. // }
  644. }
  645. });
  646. settingMenu.add(resetTcpMenu_1sd);
  647. JMenuItem resetTcpMenu_1_1sd = new JMenuItem("手动提交-B");
  648. resetTcpMenu_1_1sd.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  649. resetTcpMenu_1_1sd.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  650. resetTcpMenu_1_1sd.addMouseListener(new MouseAdapter() {
  651. @Override
  652. public void mousePressed(MouseEvent e) {
  653. super.mouseClicked(e);
  654. finish_ok_bt2.setEnabled(true);
  655. finish_ng_bt2.setEnabled(true);
  656. // MesClient.finish_ng_bt.setEnabled(true);
  657. // Boolean sendret = DataUtil.sendQuality(MesClient.nettyClient,MesClient.product_sn2.getText(),"OK",MesClient.user20,"B");
  658. // if(!sendret){
  659. // MesClient.pxstatus2.setText("B:结果上传MES失败");
  660. // MesClient.tjStatusb = 1;
  661. // }
  662. }
  663. });
  664. settingMenu.add(resetTcpMenu_1_1sd);
  665. contentPane = new JPanel();
  666. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  667. setContentPane(contentPane);
  668. contentPane.setLayout(new BorderLayout(0, 0));
  669. JToolBar toolBar = new JToolBar();
  670. contentPane.add(toolBar, BorderLayout.NORTH);
  671. JLabel equipment_statu_label = new JLabel("\u72B6\u6001\uFF1A");
  672. equipment_statu_label.setHorizontalAlignment(SwingConstants.CENTER);
  673. equipment_statu_label.setForeground(Color.BLACK);
  674. equipment_statu_label.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  675. equipment_statu_label.setBackground(Color.LIGHT_GRAY);
  676. toolBar.add(equipment_statu_label);
  677. status_menu = new JButton("设备未连接MES服务器");
  678. if(tcp_connect_flag) {
  679. status_menu.setText("已连接MES服务器");
  680. status_menu.setForeground(Color.GREEN);
  681. }else {
  682. status_menu.setText("未连接MES服务器");
  683. status_menu.setForeground(Color.DARK_GRAY);
  684. }
  685. status_menu.addActionListener(new ActionListener() {
  686. public void actionPerformed(ActionEvent e) {
  687. }
  688. });
  689. status_menu.setForeground(Color.GREEN);
  690. status_menu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  691. status_menu.setBackground(Color.BLACK);
  692. toolBar.add(status_menu);
  693. JLabel space_1 = new JLabel(" ");
  694. toolBar.add(space_1);
  695. JLabel heart_beat_status_label = new JLabel("\u5FC3\u8DF3\uFF1A");
  696. heart_beat_status_label.setHorizontalAlignment(SwingConstants.CENTER);
  697. heart_beat_status_label.setForeground(Color.BLACK);
  698. heart_beat_status_label.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  699. heart_beat_status_label.setBackground(Color.LIGHT_GRAY);
  700. toolBar.add(heart_beat_status_label);
  701. heart_beat_menu = new JButton("2024-02-20 23:20:10");
  702. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
  703. heart_beat_menu.setForeground(Color.GREEN);
  704. heart_beat_menu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  705. heart_beat_menu.setBackground(Color.BLACK);
  706. toolBar.add(heart_beat_menu);
  707. JLabel space_2 = new JLabel(" ");
  708. toolBar.add(space_2);
  709. JLabel user_status_label = new JLabel("\u767B\u5F55\u7528\u6237\uFF1A");
  710. user_status_label.setHorizontalAlignment(SwingConstants.CENTER);
  711. user_status_label.setForeground(Color.BLACK);
  712. user_status_label.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  713. user_status_label.setBackground(Color.LIGHT_GRAY);
  714. toolBar.add(user_status_label);
  715. user_menu = new JButton("JinJuShi");
  716. user_menu.setForeground(Color.GREEN);
  717. user_menu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
  718. user_menu.setBackground(Color.BLACK);
  719. toolBar.add(user_menu);
  720. JLabel space_3 = new JLabel(" ");
  721. toolBar.add(space_3);
  722. JLabel space_4 = new JLabel(" ");
  723. toolBar.add(space_4);
  724. tabbedPane = new JTabbedPane(JTabbedPane.TOP);
  725. tabbedPane.setMinimumSize(new Dimension(400, 50));
  726. tabbedPane.setFont(new Font("Microsoft YaHei UI", Font.BOLD, 22));
  727. contentPane.add(tabbedPane);
  728. //妫f牠銆�
  729. JPanel indexPanelA = new JPanel();
  730. indexScrollPaneA = new JScrollPane(indexPanelA);
  731. indexPanelA.setLayout(null);
  732. product_sn = new JTextField();
  733. product_sn.setText("");
  734. product_sn.setHorizontalAlignment(SwingConstants.CENTER);
  735. product_sn.setEditable(false);
  736. product_sn.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
  737. product_sn.setBounds(26, 152, 446, 70);
  738. indexPanelA.add(product_sn);
  739. product_sn.setColumns(10);
  740. // String[] hjtitles = new String[]{"閻掑﹥婧�1","閻掑﹥婧�2","閻掑﹥婧�3"};
  741. // String[] hjvals = new String[]{"HJ001","HJ002","HJ003"};
  742. // mesRadioHj = new MesRadio(hjtitles,hjvals);
  743. // mesRadioHj.setSize(500,50);
  744. // mesRadioHj.setBounds(190,170,500,50);
  745. // indexPanelA.add(mesRadioHj);
  746. finish_ok_bt = new JButton("OK");
  747. finish_ok_bt.setEnabled(false);
  748. finish_ok_bt.addActionListener(new ActionListener() {
  749. public void actionPerformed(ActionEvent e) {
  750. // if(work_status == 1 && check_quality_result){
  751. //
  752. //
  753. // }
  754. String sn = getBarcode(product_sn.getText());
  755. getUser();
  756. if(!sn.isEmpty()){
  757. String qret = "OK";
  758. Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"A");
  759. if(!sendret){
  760. MesClient.pxstatus1.setText("A:结果上传MES失败");
  761. MesClient.tjStatusa = 1;
  762. }else{
  763. MesClient.pxstatus1.setText("A:提交成功");
  764. MesClient.status_menu.setText("A件提交成功");
  765. MesClient.resetScanA();
  766. }
  767. }
  768. }
  769. });
  770. finish_ok_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
  771. finish_ok_bt.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 32));
  772. finish_ok_bt.setBounds(50, 380, 160, 80);
  773. finish_ok_bt.setEnabled(false);
  774. // indexPanelA.add(finish_ok_bt);
  775. finish_ng_bt = new JButton("NG");
  776. finish_ng_bt.setEnabled(false);
  777. finish_ng_bt.addActionListener(new ActionListener() {
  778. public void actionPerformed(ActionEvent e) {
  779. // if(work_status == 1 && check_quality_result){
  780. //
  781. // String sn = getBarcode(product_sn.getText());
  782. // getUser();
  783. // String qret = "OK";
  784. // Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"B");
  785. // if(!sendret){
  786. // JOptionPane.showMessageDialog(mesClientFrame,"上传MES失败,请重试","提醒", JOptionPane.INFORMATION_MESSAGE);
  787. // return;
  788. // }
  789. // }
  790. String sn = getBarcode(product_sn2.getText());
  791. getUser();
  792. if(!sn.isEmpty()){
  793. String qret = "OK";
  794. Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"B");
  795. if(!sendret){
  796. MesClient.pxstatus2.setText("B:结果上传MES失败");
  797. MesClient.tjStatusb = 1;
  798. }else{
  799. MesClient.pxstatus2.setText("B:提交成功");
  800. MesClient.status_menu.setText("B件提交成功");
  801. MesClient.resetScanB();
  802. }
  803. }
  804. }
  805. });
  806. finish_ng_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
  807. finish_ng_bt.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 32));
  808. finish_ng_bt.setBounds(280, 380, 160, 80);
  809. finish_ng_bt.setEnabled(false);
  810. // indexPanelA.add(finish_ng_bt);
  811. finish_ok_bt2 = new JButton("OK");
  812. finish_ok_bt2.setEnabled(false);
  813. finish_ok_bt2.addActionListener(new ActionListener() {
  814. public void actionPerformed(ActionEvent e) {
  815. // if(work_status == 1 && check_quality_result){
  816. //
  817. //
  818. // }
  819. String sn = getBarcode(product_sn.getText());
  820. getUser();
  821. if(!sn.isEmpty()){
  822. String qret = "OK";
  823. Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"B");
  824. if(!sendret){
  825. MesClient.pxstatus2.setText("B:结果上传MES失败");
  826. MesClient.tjStatusb = 1;
  827. }else{
  828. MesClient.pxstatus2.setText("B:提交成功");
  829. MesClient.status_menu.setText("B件提交成功");
  830. MesClient.resetScanB();
  831. }
  832. }
  833. }
  834. });
  835. finish_ok_bt2.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
  836. finish_ok_bt2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 32));
  837. finish_ok_bt2.setBounds(550, 380, 160, 80);
  838. finish_ok_bt2.setEnabled(false);
  839. // indexPanelA.add(finish_ok_bt2);
  840. finish_ng_bt2 = new JButton("NG");
  841. finish_ng_bt2.setEnabled(false);
  842. finish_ng_bt2.addActionListener(new ActionListener() {
  843. public void actionPerformed(ActionEvent e) {
  844. // if(work_status == 1 && check_quality_result){
  845. //
  846. // String sn = getBarcode(product_sn.getText());
  847. // getUser();
  848. // String qret = "OK";
  849. // Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"B");
  850. // if(!sendret){
  851. // JOptionPane.showMessageDialog(mesClientFrame,"上传MES失败,请重试","提醒", JOptionPane.INFORMATION_MESSAGE);
  852. // return;
  853. // }
  854. // }
  855. String sn = getBarcode(product_sn2.getText());
  856. getUser();
  857. if(!sn.isEmpty()){
  858. String qret = "NG";
  859. Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"B");
  860. if(!sendret){
  861. MesClient.pxstatus2.setText("B:结果上传MES失败");
  862. MesClient.tjStatusb = 1;
  863. }else{
  864. MesClient.pxstatus2.setText("B:提交成功");
  865. MesClient.status_menu.setText("B件提交成功");
  866. MesClient.resetScanB();
  867. }
  868. }
  869. }
  870. });
  871. finish_ng_bt2.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
  872. finish_ng_bt2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 32));
  873. finish_ng_bt2.setBounds(780, 380, 160, 80);
  874. finish_ng_bt2.setEnabled(false);
  875. // indexPanelA.add(finish_ng_bt2);
  876. // JLabel lblNewLabel = new JLabel("电压");
  877. // lblNewLabel.setHorizontalAlignment(SwingConstants.RIGHT);
  878. // lblNewLabel.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  879. // lblNewLabel.setBounds(26, 340, 100, 40);
  880. // lblNewLabel.setVisible(true);
  881. // indexPanelA.add(lblNewLabel);
  882. //
  883. // JLabel lblNewLabel_1 = new JLabel("电流");
  884. // lblNewLabel_1.setHorizontalAlignment(SwingConstants.RIGHT);
  885. // lblNewLabel_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  886. // lblNewLabel_1.setBounds(226, 340, 100, 40);
  887. // lblNewLabel_1.setVisible(true);
  888. // indexPanelA.add(lblNewLabel_1);
  889. //
  890. // param1 = new JTextField();
  891. // param1.setEnabled(false);
  892. // param1.setEditable(false);
  893. // param1.setHorizontalAlignment(SwingConstants.CENTER);
  894. // param1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  895. // param1.setBounds(136, 340, 70, 40);
  896. // param1.setVisible(true);
  897. // indexPanelA.add(param1);
  898. // param1.setColumns(10);
  899. //
  900. // param2 = new JTextField();
  901. // param2.setEnabled(false);
  902. // param2.setEditable(false);
  903. // param2.setHorizontalAlignment(SwingConstants.CENTER);
  904. // param2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  905. // param2.setColumns(10);
  906. // param2.setBounds(345, 340, 70, 40);
  907. // param2.setVisible(true);
  908. // indexPanelA.add(param2);
  909. //
  910. // JLabel lblNewLabel_2 = new JLabel("送丝速度");
  911. // lblNewLabel_2.setHorizontalAlignment(SwingConstants.RIGHT);
  912. // lblNewLabel_2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  913. // lblNewLabel_2.setBounds(26, 401, 100, 40);
  914. // lblNewLabel_2.setVisible(true);
  915. // indexPanelA.add(lblNewLabel_2);
  916. //
  917. // param3 = new JTextField();
  918. // param3.setEnabled(false);
  919. // param3.setEditable(false);
  920. // param3.setHorizontalAlignment(SwingConstants.CENTER);
  921. // param3.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  922. // param3.setColumns(10);
  923. // param3.setBounds(136, 401, 70, 40);
  924. // param3.setVisible(true);
  925. // indexPanelA.add(param3);
  926. //
  927. // JLabel lblNewLabel_1_1 = new JLabel("错误代码");
  928. // lblNewLabel_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
  929. // lblNewLabel_1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  930. // lblNewLabel_1_1.setBounds(213, 401, 122, 40);
  931. // lblNewLabel_1_1.setVisible(true);
  932. // indexPanelA.add(lblNewLabel_1_1);
  933. //
  934. // param4 = new JTextField();
  935. // param4.setEnabled(false);
  936. // param4.setEditable(false);
  937. // param4.setHorizontalAlignment(SwingConstants.CENTER);
  938. // param4.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  939. // param4.setColumns(10);
  940. // param4.setBounds(345, 401, 70, 40);
  941. // param4.setVisible(true);
  942. // indexPanelA.add(param4);
  943. //
  944. // param5 = new JTextField();
  945. // param5.setEnabled(false);
  946. // param5.setEditable(false);
  947. // param5.setHorizontalAlignment(SwingConstants.CENTER);
  948. // param5.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  949. // param5.setColumns(10);
  950. // param5.setBounds(226, 470, 70, 40);
  951. // param5.setVisible(true);
  952. // indexPanelA.add(param5);
  953. //
  954. // JLabel lblNewLabel_1_1_1 = new JLabel("JOB号");
  955. // lblNewLabel_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
  956. // lblNewLabel_1_1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  957. // lblNewLabel_1_1_1.setBounds(106, 470, 122, 40);
  958. // lblNewLabel_1_1_1.setVisible(true);
  959. // indexPanelA.add(lblNewLabel_1_1_1);
  960. product_sn2 = new JTextField();
  961. product_sn2.setText("");
  962. product_sn2.setHorizontalAlignment(SwingConstants.CENTER);
  963. product_sn2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
  964. product_sn2.setEditable(false);
  965. product_sn2.setColumns(10);
  966. product_sn2.setBounds(517, 152, 446, 70);
  967. indexPanelA.add(product_sn2);
  968. JSeparator separator = new JSeparator();
  969. separator.setBounds(450, 247, 0, 120);
  970. indexPanelA.add(separator);
  971. JSeparator separator_1 = new JSeparator();
  972. separator_1.setOrientation(SwingConstants.VERTICAL);
  973. separator_1.setBounds(495, 91, 23, 250);
  974. indexPanelA.add(separator_1);
  975. // JLabel lblNewLabel_3 = new JLabel("电压");
  976. // lblNewLabel_3.setHorizontalAlignment(SwingConstants.RIGHT);
  977. // lblNewLabel_3.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  978. // lblNewLabel_3.setBounds(528, 340, 100, 40);
  979. // lblNewLabel_3.setVisible(true);
  980. // indexPanelA.add(lblNewLabel_3);
  981. //
  982. // param21 = new JTextField();
  983. // param21.setEnabled(false);
  984. // param21.setEditable(false);
  985. // param21.setHorizontalAlignment(SwingConstants.CENTER);
  986. // param21.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  987. // param21.setColumns(10);
  988. // param21.setBounds(638, 340, 70, 40);
  989. // param21.setVisible(true);
  990. // indexPanelA.add(param21);
  991. //
  992. // JLabel lblNewLabel_1_2 = new JLabel("电流");
  993. // lblNewLabel_1_2.setHorizontalAlignment(SwingConstants.RIGHT);
  994. // lblNewLabel_1_2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  995. // lblNewLabel_1_2.setBounds(742, 340, 100, 40);
  996. // lblNewLabel_1_2.setVisible(true);
  997. // indexPanelA.add(lblNewLabel_1_2);
  998. //
  999. // param22 = new JTextField();
  1000. // param22.setEnabled(false);
  1001. // param22.setEditable(false);
  1002. // param22.setHorizontalAlignment(SwingConstants.CENTER);
  1003. // param22.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  1004. // param22.setColumns(10);
  1005. // param22.setBounds(852, 340, 70, 40);
  1006. // param22.setVisible(true);
  1007. // indexPanelA.add(param22);
  1008. //
  1009. // JLabel lblNewLabel_2_1 = new JLabel("送丝速度");
  1010. // lblNewLabel_2_1.setHorizontalAlignment(SwingConstants.RIGHT);
  1011. // lblNewLabel_2_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  1012. // lblNewLabel_2_1.setBounds(528, 401, 100, 40);
  1013. // lblNewLabel_2_1.setVisible(true);
  1014. // indexPanelA.add(lblNewLabel_2_1);
  1015. //
  1016. // param23 = new JTextField();
  1017. // param23.setEnabled(false);
  1018. // param23.setEditable(false);
  1019. // param23.setHorizontalAlignment(SwingConstants.CENTER);
  1020. // param23.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  1021. // param23.setColumns(10);
  1022. // param23.setBounds(638, 401, 70, 40);
  1023. // param23.setVisible(true);
  1024. // indexPanelA.add(param23);
  1025. //
  1026. // JLabel lblNewLabel_1_1_2 = new JLabel("错误代码");
  1027. // lblNewLabel_1_1_2.setHorizontalAlignment(SwingConstants.RIGHT);
  1028. // lblNewLabel_1_1_2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  1029. // lblNewLabel_1_1_2.setBounds(718, 401, 122, 40);
  1030. // lblNewLabel_1_1_2.setVisible(true);
  1031. // indexPanelA.add(lblNewLabel_1_1_2);
  1032. //
  1033. // param24 = new JTextField();
  1034. // param24.setEnabled(false);
  1035. // param24.setEditable(false);
  1036. // param24.setHorizontalAlignment(SwingConstants.CENTER);
  1037. // param24.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  1038. // param24.setColumns(10);
  1039. // param24.setBounds(852, 401, 70, 40);
  1040. // param24.setVisible(true);
  1041. // indexPanelA.add(param24);
  1042. //
  1043. // JLabel lblNewLabel_1_1_1_1 = new JLabel("JOB号");
  1044. // lblNewLabel_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
  1045. // lblNewLabel_1_1_1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  1046. // lblNewLabel_1_1_1_1.setBounds(609, 470, 122, 40);
  1047. // lblNewLabel_1_1_1_1.setVisible(true);
  1048. // indexPanelA.add(lblNewLabel_1_1_1_1);
  1049. //
  1050. // param25 = new JTextField();
  1051. // param25.setEnabled(false);
  1052. // param25.setEditable(false);
  1053. // param25.setHorizontalAlignment(SwingConstants.CENTER);
  1054. // param25.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  1055. // param25.setColumns(10);
  1056. // param25.setBounds(742, 470, 70, 40);
  1057. // param25.setVisible(true);
  1058. // indexPanelA.add(param25);
  1059. pxstatus1 = new JLabel("A");
  1060. pxstatus1.setForeground(new Color(255, 128, 64));
  1061. pxstatus1.setHorizontalAlignment(SwingConstants.CENTER);
  1062. pxstatus1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  1063. pxstatus1.setBounds(26, 98, 446, 44);
  1064. indexPanelA.add(pxstatus1);
  1065. pxstatus2 = new JLabel("B");
  1066. pxstatus2.setForeground(new Color(255, 128, 64));
  1067. pxstatus2.setHorizontalAlignment(SwingConstants.CENTER);
  1068. pxstatus2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  1069. pxstatus2.setBounds(517, 98, 446, 44);
  1070. indexPanelA.add(pxstatus2);
  1071. JSeparator separator_2 = new JSeparator();
  1072. separator_2.setBounds(10, 264, 973, 13);
  1073. indexPanelA.add(separator_2);
  1074. // JLabel lblNewLabel_4 = new JLabel("焊机1");
  1075. // lblNewLabel_4.setHorizontalAlignment(SwingConstants.CENTER);
  1076. // lblNewLabel_4.setFont(new Font("微软雅黑", Font.PLAIN, 24));
  1077. // lblNewLabel_4.setBounds(170, 290, 156, 40);
  1078. // lblNewLabel_4.setVisible(true);
  1079. // indexPanelA.add(lblNewLabel_4);
  1080. //
  1081. // JLabel lblNewLabel_4_1 = new JLabel("焊机2");
  1082. // lblNewLabel_4_1.setHorizontalAlignment(SwingConstants.CENTER);
  1083. // lblNewLabel_4_1.setFont(new Font("微软雅黑", Font.PLAIN, 24));
  1084. // lblNewLabel_4_1.setBounds(670, 287, 156, 40);
  1085. // lblNewLabel_4_1.setVisible(true);
  1086. // indexPanelA.add(lblNewLabel_4_1);
  1087. JSeparator separator_1_1 = new JSeparator();
  1088. separator_1_1.setOrientation(SwingConstants.VERTICAL);
  1089. separator_1_1.setBounds(495, 278, 23, 232);
  1090. indexPanelA.add(separator_1_1);
  1091. textField = new JTextField();
  1092. textField.setText("");
  1093. textField.setHorizontalAlignment(SwingConstants.CENTER);
  1094. textField.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
  1095. textField.setEditable(false);
  1096. textField.setColumns(10);
  1097. textField.setBounds(26, 333, 446, 70);
  1098. indexPanelA.add(textField);
  1099. batch_scan_1 = new JButton("解绑");
  1100. batch_scan_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/delete.png")));
  1101. batch_scan_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 32));
  1102. batch_scan_1.setEnabled(false);
  1103. batch_scan_1.setBounds(136, 430, 230, 80);
  1104. batch_scan_1.addActionListener(new ActionListener() {
  1105. public void actionPerformed(ActionEvent e) {
  1106. if(MesClient.curPage.equals("B")){
  1107. MesClient.setMenuStatus("该状态前梁压铸无法解绑",-1);
  1108. }else{
  1109. String sn = MesClient.product_sn.getText().trim();
  1110. String wsn = MesClient.textField.getText().trim();
  1111. JSONObject retObj = DataUtil.unBindWarehouseData(sn,wsn,user_menu.getText().trim(),"400002");
  1112. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  1113. MesClient.setMenuStatus("前梁压铸码解绑成功",0);
  1114. MesClient.formatScanType(2);
  1115. textField.setText("");
  1116. batch_scan_1.setEnabled(false);
  1117. PlcUtil.changeEnable(s7PLC,false);
  1118. }else{
  1119. MesClient.formatScanType(2);
  1120. batch_scan_1.setEnabled(true);
  1121. if(retObj.get("result")==null){
  1122. MesClient.setMenuStatus("请求失败,前梁压铸码解绑失败,请重试",-1);
  1123. }else{
  1124. if(retObj.get("result").toString().equalsIgnoreCase("false")){
  1125. MesClient.setMenuStatus(retObj.getString("message"),-1);
  1126. }
  1127. }
  1128. }
  1129. }
  1130. }
  1131. });
  1132. indexPanelA.add(batch_scan_1);
  1133. textField_1 = new JTextField();
  1134. textField_1.setText("");
  1135. textField_1.setHorizontalAlignment(SwingConstants.CENTER);
  1136. textField_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
  1137. textField_1.setEditable(false);
  1138. textField_1.setColumns(10);
  1139. textField_1.setBounds(517, 333, 446, 70);
  1140. indexPanelA.add(textField_1);
  1141. batch_scan_2 = new JButton("解绑");
  1142. batch_scan_2.setIcon(new ImageIcon(MesClient.class.getResource("/bg/delete.png")));
  1143. batch_scan_2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 32));
  1144. batch_scan_2.setEnabled(false);
  1145. batch_scan_2.setBounds(633, 430, 230, 80);
  1146. batch_scan_2.addActionListener(new ActionListener() {
  1147. public void actionPerformed(ActionEvent e) {
  1148. if(MesClient.curPage.equals("A")){
  1149. MesClient.setMenuStatus("该状态前梁压铸无法解绑",-1);
  1150. }else{
  1151. String sn = MesClient.product_sn2.getText().trim();
  1152. String wsn = MesClient.textField_1.getText().trim();
  1153. JSONObject retObj = DataUtil.unBindWarehouseData(sn,wsn,user_menu.getText().trim(),"400002");
  1154. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  1155. MesClient.setMenuStatus("前梁压铸码解绑成功",0);
  1156. MesClient.formatScanType(2);
  1157. textField_1.setText("");
  1158. batch_scan_2.setEnabled(false);
  1159. PlcUtil.changeEnable(s7PLC,false);
  1160. }else{
  1161. if(retObj.get("result")==null){
  1162. MesClient.setMenuStatus("请求失败,前梁压铸码解绑失败,请重试",-1);
  1163. }else{
  1164. if(retObj.get("result").toString().equalsIgnoreCase("false")){
  1165. MesClient.setMenuStatus(retObj.getString("message"),-1);
  1166. }
  1167. }
  1168. }
  1169. }
  1170. }
  1171. });
  1172. indexPanelA.add(batch_scan_2);
  1173. JLabel pxstatus1_1 = new JLabel("A前梁压铸");
  1174. pxstatus1_1.setHorizontalAlignment(SwingConstants.CENTER);
  1175. pxstatus1_1.setForeground(new Color(0, 0, 0));
  1176. pxstatus1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  1177. pxstatus1_1.setBounds(26, 283, 446, 44);
  1178. indexPanelA.add(pxstatus1_1);
  1179. JLabel pxstatus1_1_1 = new JLabel("B前梁压铸");
  1180. pxstatus1_1_1.setHorizontalAlignment(SwingConstants.CENTER);
  1181. pxstatus1_1_1.setForeground(Color.BLACK);
  1182. pxstatus1_1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  1183. pxstatus1_1_1.setBounds(517, 283, 446, 44);
  1184. indexPanelA.add(pxstatus1_1_1);
  1185. txtfa = new JTextField();
  1186. txtfa.setHorizontalAlignment(SwingConstants.LEFT);
  1187. txtfa.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
  1188. txtfa.setColumns(10);
  1189. txtfa.setBounds(239, 10, 503, 60);
  1190. indexPanelA.add(txtfa);
  1191. txtfa.addActionListener(new ActionListener() {
  1192. public void actionPerformed(ActionEvent e) {
  1193. scanBarcode();
  1194. }
  1195. });
  1196. page_text = new JLabel("当前:A面");
  1197. page_text.setForeground(new Color(0, 255, 64));
  1198. page_text.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  1199. page_text.setHorizontalAlignment(SwingConstants.RIGHT);
  1200. page_text.setBounds(97, 10, 132, 60);
  1201. indexPanelA.add(page_text);
  1202. scan_type_text = new JLabel("镭雕码");
  1203. scan_type_text.setForeground(new Color(255, 128, 64));
  1204. scan_type_text.setHorizontalAlignment(SwingConstants.LEFT);
  1205. scan_type_text.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  1206. scan_type_text.setBounds(752, 10, 132, 60);
  1207. indexPanelA.add(scan_type_text);
  1208. tabbedPane.addTab("工作面板", new ImageIcon(MesClient.class.getResource("/bg/a_side.png")), indexScrollPaneA, null);
  1209. tabbedPane.setEnabledAt(0, true);
  1210. JPanel indexPanelGz = new JPanel();
  1211. searchScrollPaneGz = new JScrollPane(indexPanelGz);
  1212. indexPanelGz.setLayout(null);
  1213. indexPanelB = new JPanel();
  1214. searchScrollPane = new JScrollPane(indexPanelB);
  1215. indexPanelB.setLayout(null);
  1216. tabbedPane.addTab("工作记录", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPane, null);
  1217. indexPanelC = new JPanel();
  1218. searchScrollPaneDj = new JScrollPane(indexPanelC);
  1219. indexPanelC.setLayout(null);
  1220. tabbedPane.addTab("开班点检", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPaneDj, null);
  1221. // bindBatchPanel();
  1222. }
  1223. public static void formatScanType(int st){
  1224. scan_type = st;
  1225. if(scan_type == 1){
  1226. scan_type_text.setText("镭雕码");
  1227. }else if(scan_type == 2){
  1228. scan_type_text.setText("前梁压铸码");
  1229. }else{
  1230. scan_type_text.setText("");
  1231. }
  1232. }
  1233. public static void scanBarcode() {
  1234. String scanBarcodeSn = txtfa.getText().trim();
  1235. txtfa.setText("");
  1236. System.out.println("scan_type:"+scan_type);
  1237. //刷新界面
  1238. mesClientFrame.repaint();
  1239. System.out.println("456");
  1240. System.out.println("156"+scan_type);
  1241. if(MesClient.scan_type == 1){ // 镭雕码
  1242. System.out.println("type1");
  1243. if(scanBarcodeSn.isEmpty()){
  1244. System.out.println("type2");
  1245. MesClient.setMenuStatus("镭雕码不能为空",1);
  1246. return;
  1247. }
  1248. if(!isValidLaserBarcode(scanBarcodeSn)){
  1249. MesClient.setMenuStatus("工件码格式不正确",1);
  1250. return;
  1251. }
  1252. if(nettyClient == null || !tcp_connect_flag || NettyClient.future == null ||
  1253. NettyClient.future.channel() == null || !NettyClient.future.channel().isActive()){
  1254. tcp_connect_flag = false;
  1255. MesClient.setMenuStatus("未连接MES服务器",-1);
  1256. return;
  1257. }
  1258. if(MesClient.curPage.equals("A")){
  1259. System.out.println("typeA");
  1260. if(!product_sn.getText().isEmpty() && mesQualityFlagA){
  1261. MesClient.setMenuStatus("A面已存在工件码,勿重复扫码",1);
  1262. return;
  1263. }
  1264. product_sn.setText(scanBarcodeSn);
  1265. }else{
  1266. System.out.println("typeB");
  1267. if(!product_sn2.getText().isEmpty() && mesQualityFlagB){
  1268. MesClient.setMenuStatus("B面已存在工件码,勿重复扫码",1);
  1269. return;
  1270. }
  1271. product_sn2.setText(scanBarcodeSn);
  1272. }
  1273. //刷新界面
  1274. mesClientFrame.repaint();
  1275. System.out.println("123");
  1276. getUser();
  1277. // 查询工件质量
  1278. MesClient.beginQualityCheck(scanBarcodeSn, MesClient.curPage);
  1279. Boolean sendret = DataUtil.checkQuality(nettyClient,scanBarcodeSn,user20,MesClient.curPage);
  1280. if(!sendret){
  1281. if(!tcp_connect_flag){
  1282. MesClient.failPendingQualityCheck("未连接MES服务器");
  1283. }else{
  1284. MesClient.failPendingQualityCheck("消息发送失败,请重试");
  1285. }
  1286. }else{
  1287. MesClient.setMenuStatus("正在校验工件码",0);
  1288. }
  1289. }else if(MesClient.scan_type == 2){ // 前梁压铸码
  1290. if(scanBarcodeSn.isEmpty()){
  1291. MesClient.setMenuStatus("前梁压铸码不能为空",1);
  1292. return;
  1293. }
  1294. String sn = "";
  1295. if(MesClient.curPage.equals("A")){
  1296. sn = product_sn.getText().trim();
  1297. }else{
  1298. sn = product_sn2.getText().trim();
  1299. }
  1300. if(!checkSnAndBatch(sn,scanBarcodeSn)){
  1301. MesClient.setMenuStatus("前梁压铸码与工件不匹配",1);
  1302. return;
  1303. }
  1304. JSONObject retObj = DataUtil.bindWarehouseData(sn,scanBarcodeSn,user_menu.getText().trim(),"400002");
  1305. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  1306. MesClient.setMenuStatus("前梁压铸码扫码绑定成功",0);
  1307. MesClient.formatScanType(1);
  1308. if(MesClient.curPage.equals("A")){
  1309. textField.setText(scanBarcodeSn);
  1310. batch_scan_1.setEnabled(true);
  1311. }else{
  1312. textField_1.setText(scanBarcodeSn);
  1313. batch_scan_2.setEnabled(true);
  1314. }
  1315. PlcUtil.changeEnable(s7PLC,true);
  1316. }else{
  1317. MesClient.formatScanType(2);
  1318. if(retObj.get("result")==null){
  1319. MesClient.setMenuStatus("请求失败,前梁压铸码绑定失败,请重试",-1);
  1320. }else{
  1321. if(retObj.get("result").toString().equalsIgnoreCase("false")){
  1322. MesClient.setMenuStatus(retObj.getString("message"),-1);
  1323. }
  1324. }
  1325. }
  1326. }
  1327. }
  1328. public static void setMenuStatus(String msg,int error){
  1329. lastBusinessStatusTime = System.currentTimeMillis();
  1330. if(error == 0){
  1331. MesClient.status_menu.setForeground(Color.GREEN);
  1332. }else{
  1333. MesClient.status_menu.setForeground(Color.RED);
  1334. }
  1335. MesClient.status_menu.setText(msg);
  1336. }
  1337. public static void getMaterailData(){
  1338. JSONObject retObj = DataUtil.getBindMaterail();
  1339. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  1340. List<BindMaterialResp> arrs = retObj.getList("data",BindMaterialResp.class);
  1341. int i = 0;
  1342. rowData = new Object[arrs.size()][7];
  1343. for (BindMaterialResp bindMaterialResp:arrs){
  1344. rowData[i][0] = bindMaterialResp.getMaterialTitle();
  1345. rowData[i][1] = bindMaterialResp.getBatchSn();
  1346. rowData[i][2] = bindMaterialResp.getLastTimes();
  1347. rowData[i][3] = "";
  1348. rowData[i][4] = bindMaterialResp.getCraft();
  1349. rowData[i][5] = bindMaterialResp.getMaterialId();
  1350. rowData[i][6] = bindMaterialResp.getType();
  1351. i++;
  1352. }
  1353. bindBatchPanel();
  1354. }
  1355. }
  1356. public static void updateMaterailData(){
  1357. JSONObject retObj = DataUtil.getBindMaterail();
  1358. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  1359. List<BindMaterialResp> arrs = retObj.getList("data",BindMaterialResp.class);
  1360. int i = 0;
  1361. for (BindMaterialResp bindMaterialResp:arrs){
  1362. rowData[i][0] = bindMaterialResp.getMaterialTitle();
  1363. rowData[i][1] = bindMaterialResp.getBatchSn();
  1364. rowData[i][2] = bindMaterialResp.getLastTimes();
  1365. rowData[i][3] = "";
  1366. rowData[i][4] = bindMaterialResp.getCraft();
  1367. rowData[i][5] = bindMaterialResp.getMaterialId();
  1368. rowData[i][6] = bindMaterialResp.getType();
  1369. i++;
  1370. }
  1371. MesClient.table.repaint();
  1372. }
  1373. }
  1374. // 绑定物料批次码
  1375. public static void scanBatchSn(BindMaterialResp bindMaterialResp) { // 扫码类型
  1376. //弹窗扫工件码
  1377. String scanBarcodeTitle = "请扫物料:"+bindMaterialResp.getMaterialTitle();
  1378. String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
  1379. if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")) {
  1380. JSONObject retObj = DataUtil.saveBindMaterail(scanBarcode,bindMaterialResp.getCraft(),bindMaterialResp.getMaterialId(),bindMaterialResp.getType());
  1381. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  1382. MesClient.setMenuStatus("扫物料:"+bindMaterialResp.getMaterialTitle()+"成功",0);
  1383. updateMaterailData();
  1384. }else{
  1385. if(retObj.get("result")==null){
  1386. MesClient.setMenuStatus("请求失败,请重试",-1);
  1387. }else{
  1388. if(retObj.get("result").toString().equalsIgnoreCase("false")){
  1389. MesClient.setMenuStatus(retObj.getString("message"),-1);
  1390. }
  1391. }
  1392. }
  1393. }
  1394. }
  1395. public static void bindBatchPanel(){
  1396. JPanel indexPanelBB = new JPanel();
  1397. JPanel panel = new JPanel();
  1398. panel.setBounds(0, 0, 990, 550);
  1399. // panel.setBounds(81, 50, 810, 479);
  1400. indexPanelBB.add(panel);
  1401. panel.setLayout(new GridLayout(0, 1, 0, 0));
  1402. table = new JTable(rowData, columnNames){
  1403. public boolean isCellEditable(int row, int column) {
  1404. if(column == 3){
  1405. return true;
  1406. }
  1407. return false;
  1408. }
  1409. };
  1410. table.setRowHeight(40);
  1411. table.setEnabled(true);
  1412. table.setFont(new Font("微软雅黑", Font.PLAIN, 14));
  1413. table.getColumnModel().getColumn(3).setCellRenderer(new TableCellRendererButton());
  1414. table.getColumnModel().getColumn(3).setCellEditor(new TableCellEditorButton());
  1415. JScrollPane scrollPane = new JScrollPane(table);
  1416. panel.add(scrollPane);
  1417. indexScrollPaneB = new JScrollPane(indexPanelBB);
  1418. indexPanelBB.setLayout(null);
  1419. tabbedPane.addTab("绑定物料", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), indexScrollPaneB, null);
  1420. }
  1421. // 开启发送结果定时任务
  1422. public static void startUpdateQualityTimer(){
  1423. new Timer().schedule(new TimerTask() {
  1424. @Override
  1425. public void run() {
  1426. try {
  1427. JdbcUtils.getConn();
  1428. Statement statement = JdbcUtils.conn.createStatement();
  1429. String selectSql = "SELECT id, bw FROM submit_record\n" +
  1430. "WHERE state = 0 ORDER BY id DESC LIMIT 10";
  1431. String updateSql = "UPDATE submit_record \n" +
  1432. "SET state = '1'\n" +
  1433. "WHERE id = ";
  1434. ResultSet rs = statement.executeQuery(selectSql);
  1435. while(rs.next()){
  1436. int id = rs.getInt("id");
  1437. String bw = rs.getString("bw");
  1438. // 发送请求
  1439. String url = "http://"+MesClient.mes_server_ip+":8980/js/a/mes/mesProductRecord/updateQualityByTiming";
  1440. String s = HttpUtils.sendPostRequestJson(url, bw );
  1441. Boolean result = JSONObject.parseObject(s).getBoolean("result");
  1442. if(result) {
  1443. // 更改状态为 1
  1444. statement.executeUpdate(updateSql + id);
  1445. }
  1446. }
  1447. rs.close();
  1448. statement.close();
  1449. } catch (SQLException | IOException e) {
  1450. // throw new RuntimeException(e);
  1451. e.printStackTrace();
  1452. }
  1453. }
  1454. },1000, 5000);
  1455. }
  1456. public static void formatBatchSn(){
  1457. if((MesClient.batch_status == 1 && MesClient.tjFlaga == 1) || (MesClient.batch_status2 == 1 && MesClient.tjFlagb == 1)){
  1458. PlcUtil.changeEnable(MesClient.s7PLC,true);
  1459. }else{
  1460. PlcUtil.changeEnable(MesClient.s7PLC,false);
  1461. }
  1462. }
  1463. private static String checkSnType(String sn){
  1464. String str = sn.substring(9,12);
  1465. if(str.equals("113")){
  1466. return "MX11-2";
  1467. }else if(str.equals("119")){
  1468. return "MX11-2S";
  1469. }else{
  1470. return "";
  1471. }
  1472. }
  1473. // 检查工件是否匹配
  1474. private static Boolean checkSnAndBatch(String sn,String batchSn){
  1475. String gdStr1 = "151245P000012131001000"; // MX11-2
  1476. String gdStr2 = "151245P000017812001000"; // MX11-2S
  1477. String cate = sn.substring(0,22);
  1478. String ptype = checkSnType(batchSn);
  1479. if(ptype.equals("MX11-2") && cate.equals(gdStr1)){
  1480. return true;
  1481. }
  1482. if(ptype.equals("MX11-2S") && cate.equals(gdStr2)){
  1483. return true;
  1484. }
  1485. return false;
  1486. }
  1487. }