MesClient.java 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500
  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.xingshuangs.iot.protocol.modbus.service.ModbusTcp;
  6. import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType;
  7. import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
  8. import com.mes.component.MesRadio;
  9. import com.mes.component.MesWebView;
  10. import com.mes.component.MyDialog;
  11. import com.mes.netty.NettyClient;
  12. import com.mes.util.DateLocalUtils;
  13. import com.mes.util.HttpUtils;
  14. import com.mes.util.JdbcUtils;
  15. import javafx.embed.swing.JFXPanel;
  16. import org.slf4j.Logger;
  17. import org.slf4j.LoggerFactory;
  18. import javax.swing.*;
  19. import javax.swing.border.EmptyBorder;
  20. import javax.swing.event.ChangeEvent;
  21. import javax.swing.event.ChangeListener;
  22. import java.awt.*;
  23. import java.awt.event.ActionEvent;
  24. import java.awt.event.ActionListener;
  25. import java.awt.event.MouseAdapter;
  26. import java.awt.event.MouseEvent;
  27. import java.io.BufferedReader;
  28. import java.io.IOException;
  29. import java.io.InputStream;
  30. import java.io.InputStreamReader;
  31. import java.sql.ResultSet;
  32. import java.sql.SQLException;
  33. import java.sql.Statement;
  34. import java.time.LocalDateTime;
  35. import java.util.ArrayList;
  36. import java.util.Properties;
  37. import java.util.Timer;
  38. import java.util.TimerTask;
  39. import java.util.List;
  40. import java.util.concurrent.ExecutorService;
  41. import java.util.concurrent.Executors;
  42. public class MesClient extends JFrame {
  43. public static final Logger log = LoggerFactory.getLogger(MesClient.class);
  44. private static String Drivde = "org.sqlite.JDBC";
  45. public static int mes_auth = 0;
  46. public static String mes_gw = "";
  47. public static String mes_gw_des = "";
  48. public static String mes_server_ip = "";
  49. public static int mes_tcp_port = 3000;
  50. public static int mes_heart_beat_cycle = 10;
  51. public static int mes_heart_icon_cycle = 1;
  52. public static String mes_line_sn = "";
  53. public static String mes_gwflag = "";
  54. public static NettyClient nettyClient;
  55. public static boolean tcp_connect_flag = false;
  56. public static boolean connect_request_flag = false;
  57. //session
  58. public static String sessionid = "";
  59. public static JPanel contentPane;
  60. public static MesClient mesClientFrame;
  61. public static JTabbedPane tabbedPane;
  62. public static JScrollPane indexScrollPaneA;
  63. public static JScrollPane indexScrollPaneB;
  64. public static JScrollPane searchScrollPane;
  65. public static JScrollPane searchScrollPaneDj;
  66. public static JScrollPane searchScrollPaneGz;
  67. public static Boolean check_quality_result = false;
  68. public static Integer work_status = 0;
  69. public static Integer work_status2 = 0;
  70. public static Boolean check_quality_result2 = false;
  71. public static JButton heart_beat_menu;
  72. public static JButton status_menu;
  73. public static JButton user_menu;
  74. public static int scan_type = 0;
  75. public static JButton finish_ok_bt;
  76. public static JButton finish_ng_bt;
  77. public static JTextField product_sn;
  78. public static JLabel pxstatus1;
  79. public static JLabel pxstatus2;
  80. public static Integer tjFlag = 0; // 0=未开始 1=已扫码,设备未启动 2=设备运行中 3=设备运行结束
  81. public static Integer tjFlaga = 0; // 0=未开始 1=已扫码,设备未启动 2=设备运行中 3=设备运行结束
  82. public static Integer tjFlagb = 0; // 0=未开始 1=已扫码,设备未启动 2=设备运行中 3=设备运行结束
  83. public static Integer tjStatusa = 0; // 1=提交失败
  84. public static Integer tjStatusb = 0; // 1=提交失败
  85. public static String curFlag = ""; // 当前工作的面板
  86. public static String curSna = "";
  87. public static String curSnb = "";
  88. public static Boolean mesQualityFlagA = false; // true=可工作
  89. public static Boolean mesQualityFlagB = false; // true=可工作
  90. public static Boolean mesErrorFlagA = false; // true=提交MES失败,手动提交
  91. public static Boolean mesErrorFlagB = false; // true=提交MES失败,手动提交
  92. public static String user20 = "";
  93. public static JFrame welcomeWin;
  94. public static JPanel indexPanelB;
  95. public static MesWebView jfxPanel = null;
  96. public static MesRadio mesRadioHj;
  97. public static JPanel indexPanelC;
  98. public static MesWebView jfxPanel2 = null;
  99. public static JLabel lblNewLabel_5;
  100. public static Integer lastpage = 0; //标记是否是首次进入设备运行状态,0表示首次进入运行状态,1表示非首次进入运行状态
  101. public static S7PLC s7PLC = new S7PLC(EPlcType.S1200, "192.168.1.1");
  102. public static List<String> hjparams = new ArrayList<>();
  103. public static JTable table;
  104. public static Object[] columnNames = { "物料名称", "绑定批次", "剩余次数", "操作" };
  105. public static Object[][] rowData = null;
  106. public static String[] gzbtns = {
  107. };
  108. public static String[] gzbtnss7A = {
  109. };
  110. public static String[] gzbtnss7B = {
  111. };
  112. public static JButton gzStartBtnA; // 开始点检A
  113. public static JButton gzStartBtnB; // 开始点检B
  114. public static JButton gzCancelBtn;
  115. public static Integer gzStartStatus = 0; // 1=开始点检
  116. public static String gzCheckType = ""; // A=A面点检
  117. public static JButton gzFinishBtn; // 提交点检
  118. public static JPanel gzdjpanel;
  119. public static String programNoA = "";
  120. public static String programNoB = "";
  121. public static void main(String[] args) {
  122. if (LockUtil.getInstance().isAppActive() == true){
  123. // JOptionPane.showMessageDialog(null, "已有一个程序在运行,程序退出");
  124. return;
  125. }
  126. EventQueue.invokeLater(new Runnable() {
  127. @Override
  128. public void run() {
  129. try{
  130. readProperty();
  131. mesClientFrame = new MesClient();
  132. mesClientFrame.setVisible(false);
  133. JdbcUtils.getConn();
  134. welcomeWin = new LoginFarme();
  135. welcomeWin.setVisible(true);
  136. getMaterailData();
  137. //
  138. getPlcParam();
  139. upParams();
  140. //
  141. getPlcParams();
  142. startUpdateQualityTimer();
  143. textFocus();
  144. // 预热打印模块(后台异步,不阻塞启动)
  145. com.mes.print.PrintHelper.warmUpAsync();
  146. }catch (Exception e){
  147. e.printStackTrace();
  148. }
  149. }
  150. });
  151. }
  152. public static Timer cjTimer3;
  153. public static void upParams() {
  154. if(cjTimer3!=null) {
  155. cjTimer3.cancel();
  156. }
  157. cjTimer3 = new Timer();
  158. cjTimer3.schedule(new TimerTask() {
  159. public void run() {
  160. try{
  161. List<CmtReq> prods = JdbcUtils.getCmtParams();
  162. System.out.println("prods:"+ JSON.toJSONString(prods));
  163. if(prods.size() > 0){
  164. // 定时上传参数
  165. JSONObject retObj = DataUtil.upParams(JSON.toJSONString(prods));
  166. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  167. // 更新sqlite已同步
  168. for(CmtReq prodReq:prods){
  169. JdbcUtils.updateProdSync(prodReq.getId(),1);
  170. }
  171. }
  172. }
  173. }catch (Exception e){
  174. e.printStackTrace();
  175. }
  176. }
  177. }, 1000,30*1000);
  178. }
  179. public static Timer cjTimer;
  180. public static void getPlcParam() {
  181. if(cjTimer!=null) {
  182. cjTimer.cancel();
  183. }
  184. cjTimer = new Timer();
  185. cjTimer.schedule(new TimerTask() {
  186. public void run() {
  187. try{
  188. if(!MesClient.sessionid.isEmpty()){
  189. PlcUtil.getStatusA(s7PLC);
  190. }
  191. }catch (Exception e){
  192. e.printStackTrace();
  193. }
  194. try{
  195. if(!MesClient.sessionid.isEmpty()){
  196. PlcUtil.getStatusB(s7PLC);
  197. }
  198. }catch (Exception e){
  199. e.printStackTrace();
  200. }
  201. }
  202. }, 1000,1000);
  203. }
  204. public static Timer cjTimerText;
  205. public static String lastDetectedPage = ""; // 记录上次检测到的面
  206. public static void textFocus() {
  207. if(cjTimerText!=null) {
  208. cjTimerText.cancel();
  209. }
  210. cjTimerText = new Timer();
  211. cjTimerText.schedule(new TimerTask() {
  212. public void run() {
  213. textField.requestFocusInWindow();
  214. String page = PlcUtil.getCurAside(s7PLC);
  215. if(page.equals("A")){
  216. lblNewLabel_5.setText("当前:A面");
  217. }else{
  218. lblNewLabel_5.setText("当前:B面");
  219. }
  220. // 识别完当前面后,给禁用信号(仅在面切换时执行)
  221. if(!page.equals(lastDetectedPage)){
  222. lastDetectedPage = page;
  223. // Keep reserved start permission; side change only updates display state.
  224. System.out.println("turntable side changed: " + page + ", keep reserved enable signal");
  225. }
  226. }
  227. }, 1000,1000);
  228. }
  229. public static Timer cjTimer2;
  230. public static void getPlcParams() {
  231. if(cjTimer2!=null) {
  232. cjTimer2.cancel();
  233. }
  234. cjTimer2 = new Timer();
  235. cjTimer2.schedule(new TimerTask() {
  236. public void run() {
  237. try{
  238. PlcUtil.getParamDyDl(s7PLC);
  239. }catch (Exception e){
  240. e.printStackTrace();
  241. }
  242. }
  243. }, 1000,1000);
  244. }
  245. private static void readProperty() throws IOException{
  246. String enconding = "UTF-8";
  247. InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
  248. Properties pro = new Properties();
  249. BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
  250. pro.load(br);
  251. mes_gw = pro.getProperty("mes.gw");
  252. // mes_gw_des = pro.getProperty("mes.gw_des");
  253. mes_server_ip = pro.getProperty("mes.server_ip");
  254. mes_tcp_port = Integer.parseInt(pro.getProperty("mes.tcp_port"));
  255. mes_heart_beat_cycle = Integer.parseInt(pro.getProperty("mes.heart_beat_cycle"));
  256. mes_line_sn = pro.getProperty("mes.line_sn");
  257. mes_gw_des = OprnoUtil.getGwDes(mes_line_sn,mes_gw);
  258. mes_gwflag = pro.getProperty("mes.gwflag");
  259. System.out.println(mes_gw + ";" + mes_gw_des + ";" + mes_server_ip + ";" + mes_tcp_port + ";" + mes_heart_beat_cycle);
  260. }
  261. // 閸掓繂顫愰崠鏈P
  262. public static void initTcpConnection() {
  263. try {
  264. if(nettyClient==null) {
  265. nettyClient = new NettyClient();
  266. tcp_connect_flag = false;
  267. connect_request_flag = true;
  268. DataUtil.synrTcp(nettyClient,mes_gw);
  269. }
  270. } catch (Exception e) {
  271. // TODO Auto-generated catch block
  272. e.printStackTrace();
  273. }
  274. }
  275. public static java.util.Timer heartBeatTimer;
  276. public static java.util.Timer heartBeatIconTimer;
  277. public static boolean iconREDFlag = true;
  278. public static JTextField param1;
  279. public static JTextField param2;
  280. public static JTextField param3;
  281. public static JTextField param4;
  282. public static JTextField param5;
  283. public static JTextField product_sn2;
  284. public static JTextField param21;
  285. public static JTextField param22;
  286. public static JTextField param23;
  287. public static JTextField param24;
  288. public static JTextField param25;
  289. public static void startHeartBeatTimer() {
  290. if(heartBeatTimer!=null) {
  291. heartBeatTimer.cancel();
  292. }
  293. heartBeatTimer = new java.util.Timer();
  294. heartBeatTimer.schedule(new TimerTask() {
  295. public void run() {
  296. if(nettyClient!=null&&tcp_connect_flag) {
  297. DataUtil.heartBeat(nettyClient,mes_gw);
  298. heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
  299. }
  300. }
  301. }, 100,mes_heart_beat_cycle*1000);
  302. if(heartBeatIconTimer!=null) {
  303. heartBeatIconTimer.cancel();
  304. }
  305. heartBeatIconTimer = new Timer();
  306. heartBeatIconTimer.schedule(new TimerTask() {
  307. public void run() {
  308. if(tcp_connect_flag) {
  309. if(iconREDFlag) {
  310. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  311. iconREDFlag = false;
  312. }else {
  313. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
  314. iconREDFlag = true;
  315. }
  316. heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
  317. heart_beat_menu.repaint();
  318. }else {
  319. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  320. heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
  321. heart_beat_menu.repaint();
  322. if(nettyClient!=null&&!tcp_connect_flag){
  323. if(!connect_request_flag) {
  324. connect_request_flag = true;
  325. DataUtil.synrTcp(nettyClient,mes_gw);
  326. }
  327. }
  328. }
  329. }
  330. }, 100,mes_heart_icon_cycle*1000);
  331. }
  332. public static void setTcpStatus() {
  333. if(tcp_connect_flag) {
  334. status_menu.setText("已连接MES服务器");
  335. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  336. heart_beat_menu.repaint();
  337. }else {
  338. status_menu.setText("未连接MES服务器");
  339. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  340. heart_beat_menu.repaint();
  341. }
  342. }
  343. public static void initWarehouseData(){
  344. resetScanA();
  345. resetScanB();
  346. // PlcUtil.changeEnable(s7PLC,false);
  347. }
  348. public static void resetScanA() {
  349. work_status = 0;
  350. check_quality_result = false;
  351. MesClient.finish_ok_bt.setEnabled(true);
  352. MesClient.mesQualityFlagA = false;
  353. product_sn.setText("");
  354. MesClient.pxstatus1.setText("A");
  355. MesClient.param1.setText("");
  356. MesClient.param2.setText("");
  357. MesClient.param3.setText("");
  358. MesClient.param4.setText("");
  359. MesClient.param5.setText("");
  360. MesClient.param21.setText("");
  361. MesClient.param22.setText("");
  362. MesClient.param23.setText("");
  363. MesClient.param24.setText("");
  364. MesClient.param25.setText("");
  365. MesClient.curFlag = "";
  366. MesClient.curSna = "";
  367. MesClient.tjFlaga = 0;
  368. PlcUtil.changeEnable(s7PLC, false, "A");
  369. updateMaterailData(); // 更新物料
  370. shiftUserCheck();
  371. }
  372. public static int userLoginHours;//用户登录所处小时
  373. public static JTextField textField;
  374. //换班用户信息检查
  375. private static void shiftUserCheck() {
  376. LocalDateTime now = LocalDateTime.now();
  377. // 判断时间范围
  378. if (userLoginHours >= 8 && userLoginHours < 20) {
  379. int hour = now.getHour();
  380. if (hour >= 20 || hour < 8) {
  381. logoff();
  382. }
  383. } else {
  384. int hour = now.getHour();
  385. if (hour >= 8 && hour < 20) {
  386. logoff();
  387. }
  388. }
  389. }
  390. public static void resetScanB() {
  391. work_status2 = 0;
  392. check_quality_result2 = false;
  393. MesClient.finish_ng_bt.setEnabled(true);
  394. MesClient.mesQualityFlagB = false;
  395. product_sn2.setText("");
  396. MesClient.pxstatus2.setText("B");
  397. MesClient.param1.setText("");
  398. MesClient.param2.setText("");
  399. MesClient.param3.setText("");
  400. MesClient.param4.setText("");
  401. MesClient.param5.setText("");
  402. MesClient.param21.setText("");
  403. MesClient.param22.setText("");
  404. MesClient.param23.setText("");
  405. MesClient.param24.setText("");
  406. MesClient.param25.setText("");
  407. MesClient.curFlag = "";
  408. MesClient.curSnb = "";
  409. MesClient.tjFlagb = 0;
  410. PlcUtil.changeEnable(s7PLC, false, "B");
  411. updateMaterailData(); // 更新物料
  412. shiftUserCheck();
  413. }
  414. //閼惧嘲褰囬悽銊﹀煕20娴o拷
  415. public static void getUser() {
  416. user20 = user_menu.getText().toString();
  417. String space_tmp1 = "";
  418. if(user20.length()<20) {
  419. for(int i=0;i<20-user20.length();i++) {
  420. space_tmp1 = space_tmp1 + " ";
  421. }
  422. }
  423. user20 = user20 + space_tmp1;
  424. }
  425. public static String getBarcode(String barcodeTmp) {
  426. String barcodeRet = barcodeTmp;
  427. if(barcodeTmp.equalsIgnoreCase("")) {
  428. return "";
  429. }else {
  430. if(barcodeTmp.length()<36) {
  431. String space = "";
  432. for(int i=0;i<36-barcodeTmp.length();i++) {
  433. space = space + " ";
  434. }
  435. barcodeRet = barcodeTmp + space;
  436. }
  437. }
  438. return barcodeRet;
  439. }
  440. public static void logoff() {
  441. welcomeWin.setVisible(true);
  442. mesClientFrame.setVisible(false);
  443. nettyClient = null;
  444. if(heartBeatTimer!=null) {
  445. heartBeatTimer.cancel();
  446. }
  447. if(heartBeatIconTimer!=null) {
  448. heartBeatIconTimer.cancel();
  449. }
  450. tcp_connect_flag = false;
  451. connect_request_flag = false;
  452. }
  453. public MesClient() {
  454. setIconImage(Toolkit.getDefaultToolkit().getImage(MesClient.class.getResource("/bg/logo.png")));
  455. setTitle("MES系统客户端:"+mes_gw + "- " + mes_gw_des);
  456. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  457. setBounds(0, 0, 1024, 768);
  458. JMenuBar menuBar = new JMenuBar();
  459. menuBar.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 26));
  460. setJMenuBar(menuBar);
  461. JMenu fileMenu = new JMenu("\u7528\u6237");
  462. fileMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/user.png")));
  463. fileMenu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  464. menuBar.add(fileMenu);
  465. JMenuItem exitMenuItem = new JMenuItem("退出");
  466. exitMenuItem.setIcon(new ImageIcon(MesClient.class.getResource("/bg/logoff.png")));
  467. exitMenuItem.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
  468. fileMenu.add(exitMenuItem);
  469. exitMenuItem.addMouseListener(new MouseAdapter() {
  470. @Override
  471. public void mousePressed(MouseEvent e) {
  472. super.mouseClicked(e);
  473. //dispose();
  474. logoff();
  475. }
  476. });
  477. JMenu settingMenu = new JMenu("设置");
  478. //settingMenu.setVisible(false);
  479. settingMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")));
  480. settingMenu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  481. menuBar.add(settingMenu);
  482. JMenuItem resetTcpMenu = new JMenuItem("\u91CD\u8FDEMES");
  483. resetTcpMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  484. resetTcpMenu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  485. resetTcpMenu.addMouseListener(new MouseAdapter() {
  486. @Override
  487. public void mousePressed(MouseEvent e) {
  488. super.mouseClicked(e);
  489. nettyClient.future.channel().close();
  490. }
  491. });
  492. settingMenu.add(resetTcpMenu);
  493. JMenuItem resetTcpMenu_1 = new JMenuItem("\u91CD\u65B0\u626B\u7801-A");
  494. resetTcpMenu_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  495. resetTcpMenu_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  496. resetTcpMenu_1.addMouseListener(new MouseAdapter() {
  497. @Override
  498. public void mousePressed(MouseEvent e) {
  499. super.mouseClicked(e);
  500. resetScanA();
  501. }
  502. });
  503. settingMenu.add(resetTcpMenu_1);
  504. JMenuItem resetTcpMenu_1_1 = new JMenuItem("\u91CD\u65B0\u626B\u7801-B");
  505. resetTcpMenu_1_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  506. resetTcpMenu_1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  507. resetTcpMenu_1_1.addMouseListener(new MouseAdapter() {
  508. @Override
  509. public void mousePressed(MouseEvent e) {
  510. super.mouseClicked(e);
  511. resetScanB();
  512. }
  513. });
  514. settingMenu.add(resetTcpMenu_1_1);
  515. JMenuItem resetTcpMenu_1sd = new JMenuItem("手动提交-A");
  516. resetTcpMenu_1sd.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  517. resetTcpMenu_1sd.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  518. resetTcpMenu_1sd.addMouseListener(new MouseAdapter() {
  519. @Override
  520. public void mousePressed(MouseEvent e) {
  521. super.mouseClicked(e);
  522. if(mesQualityFlagA == true){
  523. String sn = getBarcode(product_sn.getText());
  524. getUser();
  525. if(!sn.isEmpty()){
  526. String qret = "OK";
  527. Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"A");
  528. if(!sendret){
  529. MesClient.setMenuStatus("上传MES失败,请重试",-1);
  530. }
  531. }
  532. }
  533. }
  534. });
  535. settingMenu.add(resetTcpMenu_1sd);
  536. JMenuItem resetTcpMenu_1_1sd = new JMenuItem("手动提交-B");
  537. resetTcpMenu_1_1sd.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  538. resetTcpMenu_1_1sd.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  539. resetTcpMenu_1_1sd.addMouseListener(new MouseAdapter() {
  540. @Override
  541. public void mousePressed(MouseEvent e) {
  542. super.mouseClicked(e);
  543. if(mesQualityFlagB == true){
  544. String sn = getBarcode(product_sn2.getText());
  545. getUser();
  546. if(!sn.isEmpty()){
  547. String qret = "OK";
  548. Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"B");
  549. if(!sendret){
  550. MesClient.setMenuStatus("上传MES失败,请重试",-1);
  551. }
  552. }
  553. }
  554. }
  555. });
  556. settingMenu.add(resetTcpMenu_1_1sd);
  557. // 打印机设置菜单
  558. JMenuItem printerSettingMenu = new JMenuItem("打印机设置");
  559. printerSettingMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")));
  560. printerSettingMenu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  561. printerSettingMenu.addMouseListener(new MouseAdapter() {
  562. @Override
  563. public void mousePressed(MouseEvent e) {
  564. super.mouseClicked(e);
  565. try {
  566. // 调用打印机设置对话框
  567. com.mes.print.ui.PrinterSettingDialog dialog =
  568. new com.mes.print.ui.PrinterSettingDialog(MesClient.this);
  569. dialog.setVisible(true);
  570. } catch (Exception ex) {
  571. JOptionPane.showMessageDialog(MesClient.this,
  572. "打开打印机设置失败: " + ex.getMessage(),
  573. "错误",
  574. JOptionPane.ERROR_MESSAGE);
  575. ex.printStackTrace();
  576. }
  577. }
  578. });
  579. settingMenu.add(printerSettingMenu);
  580. contentPane = new JPanel();
  581. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  582. setContentPane(contentPane);
  583. contentPane.setLayout(new BorderLayout(0, 0));
  584. JToolBar toolBar = new JToolBar();
  585. contentPane.add(toolBar, BorderLayout.NORTH);
  586. JLabel equipment_statu_label = new JLabel("\u72B6\u6001\uFF1A");
  587. equipment_statu_label.setHorizontalAlignment(SwingConstants.CENTER);
  588. equipment_statu_label.setForeground(Color.BLACK);
  589. equipment_statu_label.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  590. equipment_statu_label.setBackground(Color.LIGHT_GRAY);
  591. toolBar.add(equipment_statu_label);
  592. status_menu = new JButton("设备未连接MES服务器");
  593. if(tcp_connect_flag) {
  594. status_menu.setText("已连接MES服务器");
  595. status_menu.setForeground(Color.GREEN);
  596. }else {
  597. status_menu.setText("未连接MES服务器");
  598. status_menu.setForeground(Color.DARK_GRAY);
  599. }
  600. status_menu.addActionListener(new ActionListener() {
  601. public void actionPerformed(ActionEvent e) {
  602. }
  603. });
  604. status_menu.setForeground(Color.GREEN);
  605. status_menu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  606. status_menu.setBackground(Color.BLACK);
  607. toolBar.add(status_menu);
  608. JLabel space_1 = new JLabel(" ");
  609. toolBar.add(space_1);
  610. JLabel heart_beat_status_label = new JLabel("\u5FC3\u8DF3\uFF1A");
  611. heart_beat_status_label.setHorizontalAlignment(SwingConstants.CENTER);
  612. heart_beat_status_label.setForeground(Color.BLACK);
  613. heart_beat_status_label.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  614. heart_beat_status_label.setBackground(Color.LIGHT_GRAY);
  615. toolBar.add(heart_beat_status_label);
  616. heart_beat_menu = new JButton("2024-02-20 23:20:10");
  617. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
  618. heart_beat_menu.setForeground(Color.GREEN);
  619. heart_beat_menu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  620. heart_beat_menu.setBackground(Color.BLACK);
  621. toolBar.add(heart_beat_menu);
  622. JLabel space_2 = new JLabel(" ");
  623. toolBar.add(space_2);
  624. JLabel user_status_label = new JLabel("\u767B\u5F55\u7528\u6237\uFF1A");
  625. user_status_label.setHorizontalAlignment(SwingConstants.CENTER);
  626. user_status_label.setForeground(Color.BLACK);
  627. user_status_label.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  628. user_status_label.setBackground(Color.LIGHT_GRAY);
  629. toolBar.add(user_status_label);
  630. user_menu = new JButton("JinJuShi");
  631. user_menu.setForeground(Color.GREEN);
  632. user_menu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
  633. user_menu.setBackground(Color.BLACK);
  634. toolBar.add(user_menu);
  635. JLabel space_3 = new JLabel(" ");
  636. toolBar.add(space_3);
  637. JLabel space_4 = new JLabel(" ");
  638. toolBar.add(space_4);
  639. tabbedPane = new JTabbedPane(JTabbedPane.TOP);
  640. tabbedPane.setMinimumSize(new Dimension(400, 50));
  641. tabbedPane.setFont(new Font("Microsoft YaHei UI", Font.BOLD, 22));
  642. contentPane.add(tabbedPane);
  643. JPanel indexPanelA = new JPanel();
  644. indexScrollPaneA = new JScrollPane(indexPanelA);
  645. indexPanelA.setLayout(null);
  646. product_sn = new JTextField();
  647. product_sn.setText("");
  648. product_sn.setHorizontalAlignment(SwingConstants.CENTER);
  649. product_sn.setEditable(false);
  650. product_sn.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
  651. product_sn.setBounds(26, 144, 446, 70);
  652. // 添加鼠标点击事件,点击显示二维码
  653. product_sn.addMouseListener(new MouseAdapter() {
  654. @Override
  655. public void mouseClicked(MouseEvent e) {
  656. String sn = product_sn.getText();
  657. if(sn != null && !sn.trim().isEmpty()){
  658. new com.mes.component.QRCodeDialog(mesClientFrame, "A面工件码二维码", sn);
  659. }
  660. }
  661. });
  662. indexPanelA.add(product_sn);
  663. product_sn.setColumns(10);
  664. finish_ok_bt = new JButton("扫码");
  665. finish_ok_bt.setVisible(false);
  666. finish_ok_bt.addActionListener(new ActionListener() {
  667. public void actionPerformed(ActionEvent e) {
  668. scanBarcode();
  669. // String sn = getBarcode(product_sn.getText());
  670. // getUser();
  671. //
  672. // if(!sn.isEmpty()){
  673. // String qret = "OK";
  674. // Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"A");
  675. // if(!sendret){
  676. // JOptionPane.showMessageDialog(mesClientFrame,"上传MES失败,请重试","提醒", JOptionPane.INFORMATION_MESSAGE);
  677. // return;
  678. // }
  679. // }
  680. }
  681. });
  682. // finish_ok_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
  683. finish_ok_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/scan_barcode.png")));
  684. finish_ok_bt.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 32));
  685. finish_ok_bt.setBounds(136, 167, 230, 80);
  686. finish_ok_bt.setEnabled(false);
  687. indexPanelA.add(finish_ok_bt);
  688. finish_ng_bt = new JButton("扫码");
  689. finish_ng_bt.setVisible(false);
  690. finish_ng_bt.addActionListener(new ActionListener() {
  691. public void actionPerformed(ActionEvent e) {
  692. scanBarcode();
  693. // String sn = getBarcode(product_sn2.getText());
  694. // getUser();
  695. //
  696. // if(!sn.isEmpty()){
  697. // String qret = "OK";
  698. // Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"B");
  699. // if(!sendret){
  700. // JOptionPane.showMessageDialog(mesClientFrame,"上传MES失败,请重试","提醒", JOptionPane.INFORMATION_MESSAGE);
  701. // return;
  702. // }
  703. // }
  704. }
  705. });
  706. // finish_ng_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
  707. finish_ng_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/scan_barcode.png")));
  708. finish_ng_bt.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 32));
  709. finish_ng_bt.setBounds(633, 167, 230, 80);
  710. finish_ng_bt.setEnabled(false);
  711. indexPanelA.add(finish_ng_bt);
  712. JLabel lblNewLabel = new JLabel("电压");
  713. lblNewLabel.setHorizontalAlignment(SwingConstants.RIGHT);
  714. lblNewLabel.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  715. lblNewLabel.setBounds(26, 340, 100, 40);
  716. indexPanelA.add(lblNewLabel);
  717. JLabel lblNewLabel_1 = new JLabel("电流");
  718. lblNewLabel_1.setHorizontalAlignment(SwingConstants.RIGHT);
  719. lblNewLabel_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  720. lblNewLabel_1.setBounds(226, 340, 100, 40);
  721. indexPanelA.add(lblNewLabel_1);
  722. param1 = new JTextField();
  723. param1.setEnabled(false);
  724. param1.setEditable(false);
  725. param1.setHorizontalAlignment(SwingConstants.CENTER);
  726. param1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  727. param1.setBounds(136, 340, 70, 40);
  728. indexPanelA.add(param1);
  729. param1.setColumns(10);
  730. param2 = new JTextField();
  731. param2.setEnabled(false);
  732. param2.setEditable(false);
  733. param2.setHorizontalAlignment(SwingConstants.CENTER);
  734. param2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  735. param2.setColumns(10);
  736. param2.setBounds(345, 340, 70, 40);
  737. indexPanelA.add(param2);
  738. JLabel lblNewLabel_2 = new JLabel("送丝速度");
  739. lblNewLabel_2.setHorizontalAlignment(SwingConstants.RIGHT);
  740. lblNewLabel_2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  741. lblNewLabel_2.setBounds(26, 401, 100, 40);
  742. indexPanelA.add(lblNewLabel_2);
  743. param3 = new JTextField();
  744. param3.setEnabled(false);
  745. param3.setEditable(false);
  746. param3.setHorizontalAlignment(SwingConstants.CENTER);
  747. param3.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  748. param3.setColumns(10);
  749. param3.setBounds(136, 401, 70, 40);
  750. indexPanelA.add(param3);
  751. JLabel lblNewLabel_1_1 = new JLabel("错误代码");
  752. lblNewLabel_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
  753. lblNewLabel_1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  754. lblNewLabel_1_1.setBounds(213, 401, 122, 40);
  755. indexPanelA.add(lblNewLabel_1_1);
  756. param4 = new JTextField();
  757. param4.setEnabled(false);
  758. param4.setEditable(false);
  759. param4.setHorizontalAlignment(SwingConstants.CENTER);
  760. param4.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  761. param4.setColumns(10);
  762. param4.setBounds(345, 401, 70, 40);
  763. indexPanelA.add(param4);
  764. param5 = new JTextField();
  765. param5.setEnabled(false);
  766. param5.setEditable(false);
  767. param5.setHorizontalAlignment(SwingConstants.CENTER);
  768. param5.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  769. param5.setColumns(10);
  770. param5.setBounds(226, 470, 70, 40);
  771. indexPanelA.add(param5);
  772. JLabel lblNewLabel_1_1_1 = new JLabel("JOB号");
  773. lblNewLabel_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
  774. lblNewLabel_1_1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  775. lblNewLabel_1_1_1.setBounds(106, 470, 122, 40);
  776. indexPanelA.add(lblNewLabel_1_1_1);
  777. product_sn2 = new JTextField();
  778. product_sn2.setText("");
  779. product_sn2.setHorizontalAlignment(SwingConstants.CENTER);
  780. product_sn2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
  781. product_sn2.setEditable(false);
  782. product_sn2.setColumns(10);
  783. product_sn2.setBounds(517, 144, 446, 70);
  784. // 添加鼠标点击事件,点击显示二维码
  785. product_sn2.addMouseListener(new MouseAdapter() {
  786. @Override
  787. public void mouseClicked(MouseEvent e) {
  788. String sn = product_sn2.getText();
  789. if(sn != null && !sn.trim().isEmpty()){
  790. new com.mes.component.QRCodeDialog(mesClientFrame, "B面工件码二维码", sn);
  791. }
  792. }
  793. });
  794. indexPanelA.add(product_sn2);
  795. JSeparator separator = new JSeparator();
  796. separator.setBounds(450, 247, 0, 80);
  797. indexPanelA.add(separator);
  798. JSeparator separator_1 = new JSeparator();
  799. separator_1.setOrientation(SwingConstants.VERTICAL);
  800. separator_1.setBounds(495, 77, 23, 177);
  801. indexPanelA.add(separator_1);
  802. JLabel lblNewLabel_3 = new JLabel("电压");
  803. lblNewLabel_3.setHorizontalAlignment(SwingConstants.RIGHT);
  804. lblNewLabel_3.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  805. lblNewLabel_3.setBounds(528, 340, 100, 40);
  806. indexPanelA.add(lblNewLabel_3);
  807. param21 = new JTextField();
  808. param21.setEnabled(false);
  809. param21.setEditable(false);
  810. param21.setHorizontalAlignment(SwingConstants.CENTER);
  811. param21.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  812. param21.setColumns(10);
  813. param21.setBounds(638, 340, 70, 40);
  814. indexPanelA.add(param21);
  815. JLabel lblNewLabel_1_2 = new JLabel("电流");
  816. lblNewLabel_1_2.setHorizontalAlignment(SwingConstants.RIGHT);
  817. lblNewLabel_1_2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  818. lblNewLabel_1_2.setBounds(742, 340, 100, 40);
  819. indexPanelA.add(lblNewLabel_1_2);
  820. param22 = new JTextField();
  821. param22.setEnabled(false);
  822. param22.setEditable(false);
  823. param22.setHorizontalAlignment(SwingConstants.CENTER);
  824. param22.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  825. param22.setColumns(10);
  826. param22.setBounds(852, 340, 70, 40);
  827. indexPanelA.add(param22);
  828. JLabel lblNewLabel_2_1 = new JLabel("送丝速度");
  829. lblNewLabel_2_1.setHorizontalAlignment(SwingConstants.RIGHT);
  830. lblNewLabel_2_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  831. lblNewLabel_2_1.setBounds(528, 401, 100, 40);
  832. indexPanelA.add(lblNewLabel_2_1);
  833. param23 = new JTextField();
  834. param23.setEnabled(false);
  835. param23.setEditable(false);
  836. param23.setHorizontalAlignment(SwingConstants.CENTER);
  837. param23.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  838. param23.setColumns(10);
  839. param23.setBounds(638, 401, 70, 40);
  840. indexPanelA.add(param23);
  841. JLabel lblNewLabel_1_1_2 = new JLabel("错误代码");
  842. lblNewLabel_1_1_2.setHorizontalAlignment(SwingConstants.RIGHT);
  843. lblNewLabel_1_1_2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  844. lblNewLabel_1_1_2.setBounds(718, 401, 122, 40);
  845. indexPanelA.add(lblNewLabel_1_1_2);
  846. param24 = new JTextField();
  847. param24.setEnabled(false);
  848. param24.setEditable(false);
  849. param24.setHorizontalAlignment(SwingConstants.CENTER);
  850. param24.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  851. param24.setColumns(10);
  852. param24.setBounds(852, 401, 70, 40);
  853. indexPanelA.add(param24);
  854. JLabel lblNewLabel_1_1_1_1 = new JLabel("JOB号");
  855. lblNewLabel_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
  856. lblNewLabel_1_1_1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  857. lblNewLabel_1_1_1_1.setBounds(609, 470, 122, 40);
  858. indexPanelA.add(lblNewLabel_1_1_1_1);
  859. param25 = new JTextField();
  860. param25.setEnabled(false);
  861. param25.setEditable(false);
  862. param25.setHorizontalAlignment(SwingConstants.CENTER);
  863. param25.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  864. param25.setColumns(10);
  865. param25.setBounds(742, 470, 70, 40);
  866. indexPanelA.add(param25);
  867. pxstatus1 = new JLabel("A");
  868. pxstatus1.setForeground(new Color(255, 128, 64));
  869. pxstatus1.setHorizontalAlignment(SwingConstants.CENTER);
  870. pxstatus1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  871. pxstatus1.setBounds(26, 90, 446, 44);
  872. indexPanelA.add(pxstatus1);
  873. pxstatus2 = new JLabel("B");
  874. pxstatus2.setForeground(new Color(255, 128, 64));
  875. pxstatus2.setHorizontalAlignment(SwingConstants.CENTER);
  876. pxstatus2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  877. pxstatus2.setBounds(517, 90, 446, 44);
  878. indexPanelA.add(pxstatus2);
  879. JSeparator separator_2 = new JSeparator();
  880. separator_2.setBounds(10, 264, 973, 13);
  881. indexPanelA.add(separator_2);
  882. JLabel lblNewLabel_4 = new JLabel("\u710A\u673A1");
  883. lblNewLabel_4.setHorizontalAlignment(SwingConstants.CENTER);
  884. lblNewLabel_4.setFont(new Font("微软雅黑", Font.PLAIN, 24));
  885. lblNewLabel_4.setBounds(170, 290, 156, 40);
  886. indexPanelA.add(lblNewLabel_4);
  887. JLabel lblNewLabel_4_1 = new JLabel("\u710A\u673A2");
  888. lblNewLabel_4_1.setHorizontalAlignment(SwingConstants.CENTER);
  889. lblNewLabel_4_1.setFont(new Font("微软雅黑", Font.PLAIN, 24));
  890. lblNewLabel_4_1.setBounds(670, 287, 156, 40);
  891. indexPanelA.add(lblNewLabel_4_1);
  892. textField = new JTextField("");
  893. textField.setEnabled(true);
  894. textField.setHorizontalAlignment(SwingConstants.LEFT);
  895. textField.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
  896. textField.setColumns(10);
  897. textField.setBounds(264, 10, 510, 50);
  898. textField.addActionListener(new ActionListener() {
  899. public void actionPerformed(ActionEvent e) {
  900. scanBarcode();
  901. }
  902. });
  903. indexPanelA.add(textField);
  904. lblNewLabel_5 = new JLabel("当前:A面");
  905. lblNewLabel_5.setForeground(new Color(0, 128, 64));
  906. lblNewLabel_5.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  907. lblNewLabel_5.setBounds(136, 10, 113, 50);
  908. indexPanelA.add(lblNewLabel_5);
  909. tabbedPane.addTab("工作面板", new ImageIcon(MesClient.class.getResource("/bg/a_side.png")), indexScrollPaneA, null);
  910. tabbedPane.setEnabledAt(0, true);
  911. JPanel indexPanelGz = new JPanel();
  912. searchScrollPaneGz = new JScrollPane(indexPanelGz);
  913. indexPanelGz.setLayout(null);
  914. gzStartBtnA = new JButton("A面点检");
  915. gzStartBtnA.setBounds(150,15,160, 70);
  916. gzStartBtnA.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 28));
  917. gzStartBtnA.addActionListener(new ActionListener() {
  918. public void actionPerformed(ActionEvent e) {
  919. gzStartBtnA.setEnabled(false);
  920. gzStartBtnB.setEnabled(false);
  921. gzStartStatus = 1;
  922. gzCheckType = "A";
  923. }
  924. });
  925. indexPanelGz.add(gzStartBtnA);
  926. gzStartBtnB = new JButton("B面点检");
  927. gzStartBtnB.setBounds(350,15,160, 70);
  928. gzStartBtnB.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 28));
  929. gzStartBtnB.addActionListener(new ActionListener() {
  930. public void actionPerformed(ActionEvent e) {
  931. gzStartBtnA.setEnabled(false);
  932. gzStartBtnB.setEnabled(false);
  933. gzCancelBtn.setEnabled(true);
  934. gzStartStatus = 1;
  935. gzCheckType = "B";
  936. }
  937. });
  938. indexPanelGz.add(gzStartBtnB);
  939. gzCancelBtn = new JButton("取消");
  940. gzCancelBtn.setEnabled(false);
  941. gzCancelBtn.setBounds(600,15,160, 70);
  942. gzCancelBtn.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 28));
  943. gzCancelBtn.addActionListener(new ActionListener() {
  944. public void actionPerformed(ActionEvent e) {
  945. gzStartBtnA.setEnabled(false);
  946. gzStartBtnB.setEnabled(false);
  947. gzStartStatus = 0;
  948. gzCheckType = "";
  949. }
  950. });
  951. indexPanelGz.add(gzCancelBtn);
  952. gzFinishBtn = new JButton("上传结果");
  953. gzFinishBtn.setEnabled(false);
  954. gzFinishBtn.setBounds(800,15,160, 70);
  955. gzFinishBtn.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 28));
  956. gzFinishBtn.addActionListener(new ActionListener() {
  957. public void actionPerformed(ActionEvent e) {
  958. String content = String.join(",",gzbtns);
  959. // 提交点检
  960. JSONObject retObj = DataUtil.saveGzCheck(content,user_menu.getText());
  961. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  962. MesClient.setMenuStatus("工装点检提交成功",0);
  963. resetGzCheck();
  964. }else{
  965. MesClient.setMenuStatus("工装点检提交失败",-1);
  966. }
  967. }
  968. });
  969. indexPanelGz.add(gzFinishBtn);
  970. gzdjpanel = new JPanel();
  971. gzdjpanel.setBounds(0,100,990, 450);
  972. gzdjpanel.setLayout(new GridLayout(0, 9));
  973. List<Integer> olists = new ArrayList<>();
  974. // olists.add(9);
  975. // olists.add(11);
  976. for (int i = 0; i < 45; i++) {
  977. if(!olists.contains(i+1)){
  978. JButton btn = new JButton("检测" + (i + 1));
  979. btn.putClientProperty("id", i);
  980. btn.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 24));
  981. gzdjpanel.add(btn);
  982. }
  983. }
  984. indexPanelGz.add(gzdjpanel);
  985. formatGzbtns();
  986. // tabbedPane.addTab("工装点检", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPaneGz, null);
  987. indexPanelC = new JPanel();
  988. searchScrollPaneDj = new JScrollPane(indexPanelC);
  989. indexPanelC.setLayout(null);
  990. tabbedPane.addTab("开班点检", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPaneDj, null);
  991. indexPanelB = new JPanel();
  992. searchScrollPane = new JScrollPane(indexPanelB);
  993. indexPanelB.setLayout(null);
  994. tabbedPane.addTab("工作记录", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPane, null);
  995. // bindBatchPanel();
  996. tabbedPane.addChangeListener(new ChangeListener() {
  997. @Override
  998. public void stateChanged(ChangeEvent e) {
  999. JTabbedPane tabbedPane = (JTabbedPane) e.getSource();
  1000. int selectedIndex = tabbedPane.getSelectedIndex();
  1001. System.out.println("selectedIndex:"+selectedIndex);
  1002. if(selectedIndex == 1){
  1003. }
  1004. }
  1005. });
  1006. }
  1007. public static void resetGzCheck(){
  1008. MesClient.gzStartStatus = 0;
  1009. MesClient.gzCheckType = "";
  1010. gzFinishBtn.setEnabled(false);
  1011. gzStartBtnA.setEnabled(true);
  1012. gzStartBtnB.setEnabled(true);
  1013. int i = 0;
  1014. for (String str:MesClient.gzbtns){
  1015. MesClient.gzbtns[i] = "UD";
  1016. i++;
  1017. }
  1018. }
  1019. public static void formatGzbtns(){
  1020. int i = 0;
  1021. Boolean flag = true;
  1022. for (String bresult:gzbtns){
  1023. JButton jj = (JButton) gzdjpanel.getComponents()[i];
  1024. if(bresult.equals("OK")){
  1025. jj.setBackground(Color.green);
  1026. jj.setForeground(Color.white);
  1027. }else{
  1028. flag = false;
  1029. jj.setBackground(null);
  1030. jj.setForeground(Color.black);
  1031. }
  1032. i++;
  1033. }
  1034. if(flag){
  1035. MesClient.gzFinishBtn.setEnabled(true);
  1036. }else{
  1037. MesClient.gzFinishBtn.setEnabled(false);
  1038. }
  1039. }
  1040. public static void setMenuStatus(String msg,int error){
  1041. if(error == 0){
  1042. MesClient.status_menu.setForeground(Color.GREEN);
  1043. }else{
  1044. MesClient.status_menu.setForeground(Color.RED);
  1045. }
  1046. MesClient.status_menu.setText(msg);
  1047. }
  1048. public static void getMaterailData(){
  1049. JSONObject retObj = DataUtil.getBindMaterail();
  1050. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  1051. List<BindMaterialResp> arrs = retObj.getList("data",BindMaterialResp.class);
  1052. int i = 0;
  1053. rowData = new Object[arrs.size()][7];
  1054. for (BindMaterialResp bindMaterialResp:arrs){
  1055. rowData[i][0] = bindMaterialResp.getMaterialTitle();
  1056. rowData[i][1] = bindMaterialResp.getBatchSn();
  1057. rowData[i][2] = bindMaterialResp.getLastTimes();
  1058. rowData[i][3] = "";
  1059. rowData[i][4] = bindMaterialResp.getCraft();
  1060. rowData[i][5] = bindMaterialResp.getMaterialId();
  1061. rowData[i][6] = bindMaterialResp.getType();
  1062. i++;
  1063. }
  1064. bindBatchPanel();
  1065. }
  1066. }
  1067. public static void updateMaterailData(){
  1068. JSONObject retObj = DataUtil.getBindMaterail();
  1069. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  1070. List<BindMaterialResp> arrs = retObj.getList("data",BindMaterialResp.class);
  1071. int i = 0;
  1072. for (BindMaterialResp bindMaterialResp:arrs){
  1073. rowData[i][0] = bindMaterialResp.getMaterialTitle();
  1074. rowData[i][1] = bindMaterialResp.getBatchSn();
  1075. rowData[i][2] = bindMaterialResp.getLastTimes();
  1076. rowData[i][3] = "";
  1077. rowData[i][4] = bindMaterialResp.getCraft();
  1078. rowData[i][5] = bindMaterialResp.getMaterialId();
  1079. rowData[i][6] = bindMaterialResp.getType();
  1080. i++;
  1081. }
  1082. MesClient.table.repaint();
  1083. }
  1084. }
  1085. // 绑定物料批次码
  1086. public static void scanBatchSn(BindMaterialResp bindMaterialResp) { // 扫码类型
  1087. //弹窗扫工件码
  1088. String scanBarcodeTitle = "请扫物料:"+bindMaterialResp.getMaterialTitle();
  1089. String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
  1090. if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")) {
  1091. JSONObject retObj = DataUtil.saveBindMaterail(scanBarcode,bindMaterialResp.getCraft(),bindMaterialResp.getMaterialId(),bindMaterialResp.getType());
  1092. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  1093. MesClient.setMenuStatus("扫物料:"+bindMaterialResp.getMaterialTitle()+"成功",0);
  1094. updateMaterailData();
  1095. }else{
  1096. if(retObj.get("result")==null){
  1097. MesClient.setMenuStatus("请求失败,请重试",-1);
  1098. }else{
  1099. if(retObj.get("result").toString().equalsIgnoreCase("false")){
  1100. MesClient.setMenuStatus(retObj.getString("message"),-1);
  1101. }
  1102. }
  1103. }
  1104. }
  1105. }
  1106. public static void bindBatchPanel(){
  1107. JPanel indexPanelBB = new JPanel();
  1108. JPanel panel = new JPanel();
  1109. panel.setBounds(0, 0, 990, 550);
  1110. // panel.setBounds(81, 50, 810, 479);
  1111. indexPanelBB.add(panel);
  1112. panel.setLayout(new GridLayout(0, 1, 0, 0));
  1113. table = new JTable(rowData, columnNames){
  1114. public boolean isCellEditable(int row, int column) {
  1115. if(column == 3){
  1116. return true;
  1117. }
  1118. return false;
  1119. }
  1120. };
  1121. table.setRowHeight(40);
  1122. table.setEnabled(true);
  1123. table.setFont(new Font("微软雅黑", Font.PLAIN, 14));
  1124. table.getColumnModel().getColumn(3).setCellRenderer(new TableCellRendererButton());
  1125. table.getColumnModel().getColumn(3).setCellEditor(new TableCellEditorButton());
  1126. JScrollPane scrollPane = new JScrollPane(table);
  1127. panel.add(scrollPane);
  1128. indexScrollPaneB = new JScrollPane(indexPanelBB);
  1129. indexPanelBB.setLayout(null);
  1130. tabbedPane.addTab("绑定物料", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), indexScrollPaneB, null);
  1131. }
  1132. public static void scanBarcode() {
  1133. String sn = textField.getText().trim();
  1134. textField.setText("");
  1135. //刷新界面
  1136. mesClientFrame.repaint();
  1137. if(sn.isEmpty()){
  1138. MesClient.setMenuStatus("工件码不能为空",1);
  1139. return;
  1140. }
  1141. String page = PlcUtil.getReserveSide(s7PLC);
  1142. if(page.equals("A")){
  1143. if(!product_sn.getText().isEmpty() && mesQualityFlagA){
  1144. MesClient.setMenuStatus("A面已存在工件码,勿重复扫码",1);
  1145. return;
  1146. }
  1147. product_sn.setText(sn);
  1148. }else{
  1149. if(!product_sn2.getText().isEmpty() && mesQualityFlagB){
  1150. MesClient.setMenuStatus("B面已存在工件码,勿重复扫码",1);
  1151. return;
  1152. }
  1153. product_sn2.setText(sn);
  1154. }
  1155. MesClient.setMenuStatus("扫码成功",0);
  1156. //刷新界面
  1157. mesClientFrame.repaint();
  1158. getUser();
  1159. // 查询工件质量
  1160. Boolean sendret = DataUtil.checkQuality(nettyClient,sn,user20,page);
  1161. if(!sendret){
  1162. MesClient.setMenuStatus("消息发送失败,请重试",1);
  1163. }
  1164. }
  1165. public static void scanBarcodeOld() {
  1166. String scanBarcodeTitle = "请扫工件码";
  1167. String page = PlcUtil.getCurAside(s7PLC);
  1168. if(page.equals("A")){
  1169. product_sn.setText("");
  1170. }else{
  1171. product_sn2.setText("");
  1172. }
  1173. //弹窗扫工件码
  1174. String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
  1175. if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")) {
  1176. //获取用户
  1177. getUser();
  1178. //获取扫码内容36位
  1179. String barcode36 = getBarcode(scanBarcode);//处理36为码
  1180. if(page.equals("A")){
  1181. product_sn.setText(scanBarcode);
  1182. }else{
  1183. product_sn2.setText(scanBarcode);
  1184. }
  1185. //刷新界面
  1186. mesClientFrame.repaint();
  1187. if(!tcp_connect_flag) {
  1188. MesClient.setMenuStatus("设备未连接Mes服务器",1);
  1189. return;
  1190. }
  1191. // String ptype = checkSnType(scanBarcode);
  1192. // if(ptype.isEmpty()){
  1193. // MesClient.setMenuStatus("零件码不正确",1);
  1194. // return;
  1195. // }
  1196. // if(ptype.equals("MX11-2")){
  1197. // if(page.equals("A")){
  1198. // PlcUtil.acx2(s7PLC,true);
  1199. // PlcUtil.acx2s(s7PLC,false);
  1200. // }else{
  1201. // PlcUtil.bcx2(s7PLC,true);
  1202. // PlcUtil.bcx2s(s7PLC,false);
  1203. // }
  1204. // }else if(ptype.equals("MX11-2S")){
  1205. // if(page.equals("A")){
  1206. // PlcUtil.acx2s(s7PLC,true);
  1207. // PlcUtil.acx2(s7PLC,false);
  1208. // }else{
  1209. // PlcUtil.bcx2s(s7PLC,true);
  1210. // PlcUtil.bcx2(s7PLC,false);
  1211. // }
  1212. // }
  1213. // 查询工件质量
  1214. Boolean sendret = DataUtil.checkQuality(nettyClient,barcode36,user20,page);
  1215. if(!sendret){
  1216. MesClient.setMenuStatus("消息发送失败,请重试",1);
  1217. return;
  1218. }
  1219. }else {
  1220. JOptionPane.showMessageDialog(mesClientFrame,"请扫工件码","提示窗口", JOptionPane.INFORMATION_MESSAGE);
  1221. return;
  1222. }
  1223. }
  1224. private static String checkSnType(String sn){
  1225. String str = sn.substring(9,12);
  1226. if(str.equals("113")){
  1227. return "MX11-2";
  1228. }else if(str.equals("119")){
  1229. return "MX11-2S";
  1230. }else{
  1231. return "";
  1232. }
  1233. }
  1234. // 开启发送结果定时任务
  1235. // 开启发送结果定时任务
  1236. public static void startUpdateQualityTimer(){
  1237. // 创建异步线程池
  1238. ExecutorService executorService = Executors.newSingleThreadExecutor();
  1239. // 提交任务
  1240. executorService.submit(() -> {
  1241. log.info("异步任务执行中...");
  1242. // 模拟耗时操作
  1243. try {
  1244. while (true){
  1245. try {
  1246. // 确保连接已经打开
  1247. if (JdbcUtils.conn == null || JdbcUtils.conn.isClosed()) {
  1248. JdbcUtils.openConnection();
  1249. }
  1250. Statement statement = JdbcUtils.conn.createStatement();
  1251. String selectSql = "SELECT id, bw FROM submit_record\n" +
  1252. "WHERE state = 0 ORDER BY id DESC LIMIT 10";
  1253. String updateSql = "UPDATE submit_record \n" +
  1254. "SET state = '1'\n" +
  1255. "WHERE id = ";
  1256. ResultSet rs = statement.executeQuery(selectSql);
  1257. while(rs.next()){
  1258. int id = rs.getInt("id");
  1259. String bw = rs.getString("bw");
  1260. // 发送请求
  1261. String url = "http://"+MesClient.mes_server_ip+":8980/js/a/mes/mesProductRecord/updateQualityByTiming";
  1262. log.info("质量:"+bw);
  1263. String s = HttpUtils.sendPostRequestJson(url, bw );
  1264. log.info("结果:"+s);
  1265. Boolean result = JSONObject.parseObject(s).getBoolean("result");
  1266. if(result) {
  1267. // 更改状态为 1
  1268. statement.executeUpdate(updateSql + id);
  1269. }
  1270. }
  1271. rs.close();
  1272. statement.close();
  1273. } catch (Exception e) {
  1274. log.info(e.getMessage());
  1275. }
  1276. try {
  1277. Thread.sleep(2000);
  1278. }catch (Exception e){
  1279. log.info(e.getMessage());
  1280. }
  1281. }
  1282. } catch (Exception e) {
  1283. log.info(e.getMessage());
  1284. }
  1285. log.info("异步任务执行完毕");
  1286. });
  1287. }
  1288. }