| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500 |
- package com.mes.ui;
- import com.alibaba.fastjson2.JSON;
- import com.alibaba.fastjson2.JSONArray;
- import com.alibaba.fastjson2.JSONObject;
- import com.github.xingshuangs.iot.protocol.modbus.service.ModbusTcp;
- import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType;
- import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
- import com.mes.component.MesRadio;
- import com.mes.component.MesWebView;
- import com.mes.component.MyDialog;
- import com.mes.netty.NettyClient;
- import com.mes.util.DateLocalUtils;
- import com.mes.util.HttpUtils;
- import com.mes.util.JdbcUtils;
- import javafx.embed.swing.JFXPanel;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import javax.swing.*;
- import javax.swing.border.EmptyBorder;
- import javax.swing.event.ChangeEvent;
- import javax.swing.event.ChangeListener;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.time.LocalDateTime;
- import java.util.ArrayList;
- import java.util.Properties;
- import java.util.Timer;
- import java.util.TimerTask;
- import java.util.List;
- import java.util.concurrent.ExecutorService;
- import java.util.concurrent.Executors;
- public class MesClient extends JFrame {
- public static final Logger log = LoggerFactory.getLogger(MesClient.class);
- private static String Drivde = "org.sqlite.JDBC";
- public static int mes_auth = 0;
- public static String mes_gw = "";
- public static String mes_gw_des = "";
- public static String mes_server_ip = "";
- public static int mes_tcp_port = 3000;
- public static int mes_heart_beat_cycle = 10;
- public static int mes_heart_icon_cycle = 1;
- public static String mes_line_sn = "";
- public static String mes_gwflag = "";
- public static NettyClient nettyClient;
- public static boolean tcp_connect_flag = false;
- public static boolean connect_request_flag = false;
- //session
- public static String sessionid = "";
- public static JPanel contentPane;
- public static MesClient mesClientFrame;
- public static JTabbedPane tabbedPane;
- public static JScrollPane indexScrollPaneA;
- public static JScrollPane indexScrollPaneB;
- public static JScrollPane searchScrollPane;
- public static JScrollPane searchScrollPaneDj;
- public static JScrollPane searchScrollPaneGz;
- public static Boolean check_quality_result = false;
- public static Integer work_status = 0;
- public static Integer work_status2 = 0;
- public static Boolean check_quality_result2 = false;
- public static JButton heart_beat_menu;
- public static JButton status_menu;
- public static JButton user_menu;
- public static int scan_type = 0;
- public static JButton finish_ok_bt;
- public static JButton finish_ng_bt;
- public static JTextField product_sn;
- public static JLabel pxstatus1;
- public static JLabel pxstatus2;
- public static Integer tjFlag = 0; // 0=未开始 1=已扫码,设备未启动 2=设备运行中 3=设备运行结束
- public static Integer tjFlaga = 0; // 0=未开始 1=已扫码,设备未启动 2=设备运行中 3=设备运行结束
- public static Integer tjFlagb = 0; // 0=未开始 1=已扫码,设备未启动 2=设备运行中 3=设备运行结束
- public static Integer tjStatusa = 0; // 1=提交失败
- public static Integer tjStatusb = 0; // 1=提交失败
- public static String curFlag = ""; // 当前工作的面板
- public static String curSna = "";
- public static String curSnb = "";
- public static Boolean mesQualityFlagA = false; // true=可工作
- public static Boolean mesQualityFlagB = false; // true=可工作
- public static Boolean mesErrorFlagA = false; // true=提交MES失败,手动提交
- public static Boolean mesErrorFlagB = false; // true=提交MES失败,手动提交
- public static String user20 = "";
- public static JFrame welcomeWin;
- public static JPanel indexPanelB;
- public static MesWebView jfxPanel = null;
- public static MesRadio mesRadioHj;
- public static JPanel indexPanelC;
- public static MesWebView jfxPanel2 = null;
- public static JLabel lblNewLabel_5;
- public static Integer lastpage = 0; //标记是否是首次进入设备运行状态,0表示首次进入运行状态,1表示非首次进入运行状态
- public static S7PLC s7PLC = new S7PLC(EPlcType.S1200, "192.168.1.1");
- public static List<String> hjparams = new ArrayList<>();
- public static JTable table;
- public static Object[] columnNames = { "物料名称", "绑定批次", "剩余次数", "操作" };
- public static Object[][] rowData = null;
- public static String[] gzbtns = {
- };
- public static String[] gzbtnss7A = {
- };
- public static String[] gzbtnss7B = {
- };
- public static JButton gzStartBtnA; // 开始点检A
- public static JButton gzStartBtnB; // 开始点检B
- public static JButton gzCancelBtn;
- public static Integer gzStartStatus = 0; // 1=开始点检
- public static String gzCheckType = ""; // A=A面点检
- public static JButton gzFinishBtn; // 提交点检
- public static JPanel gzdjpanel;
- public static String programNoA = "";
- public static String programNoB = "";
- public static void main(String[] args) {
- if (LockUtil.getInstance().isAppActive() == true){
- // JOptionPane.showMessageDialog(null, "已有一个程序在运行,程序退出");
- return;
- }
- EventQueue.invokeLater(new Runnable() {
- @Override
- public void run() {
- try{
- readProperty();
- mesClientFrame = new MesClient();
- mesClientFrame.setVisible(false);
- JdbcUtils.getConn();
- welcomeWin = new LoginFarme();
- welcomeWin.setVisible(true);
- getMaterailData();
- //
- getPlcParam();
- upParams();
- //
- getPlcParams();
- startUpdateQualityTimer();
- textFocus();
- // 预热打印模块(后台异步,不阻塞启动)
- com.mes.print.PrintHelper.warmUpAsync();
- }catch (Exception e){
- e.printStackTrace();
- }
- }
- });
- }
- public static Timer cjTimer3;
- public static void upParams() {
- if(cjTimer3!=null) {
- cjTimer3.cancel();
- }
- cjTimer3 = new Timer();
- cjTimer3.schedule(new TimerTask() {
- public void run() {
- try{
- List<CmtReq> prods = JdbcUtils.getCmtParams();
- System.out.println("prods:"+ JSON.toJSONString(prods));
- if(prods.size() > 0){
- // 定时上传参数
- JSONObject retObj = DataUtil.upParams(JSON.toJSONString(prods));
- if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
- // 更新sqlite已同步
- for(CmtReq prodReq:prods){
- JdbcUtils.updateProdSync(prodReq.getId(),1);
- }
- }
- }
- }catch (Exception e){
- e.printStackTrace();
- }
- }
- }, 1000,30*1000);
- }
- public static Timer cjTimer;
- public static void getPlcParam() {
- if(cjTimer!=null) {
- cjTimer.cancel();
- }
- cjTimer = new Timer();
- cjTimer.schedule(new TimerTask() {
- public void run() {
- try{
- if(!MesClient.sessionid.isEmpty()){
- PlcUtil.getStatusA(s7PLC);
- }
- }catch (Exception e){
- e.printStackTrace();
- }
- try{
- if(!MesClient.sessionid.isEmpty()){
- PlcUtil.getStatusB(s7PLC);
- }
- }catch (Exception e){
- e.printStackTrace();
- }
- }
- }, 1000,1000);
- }
- public static Timer cjTimerText;
- public static String lastDetectedPage = ""; // 记录上次检测到的面
- public static void textFocus() {
- if(cjTimerText!=null) {
- cjTimerText.cancel();
- }
- cjTimerText = new Timer();
- cjTimerText.schedule(new TimerTask() {
- public void run() {
- textField.requestFocusInWindow();
- String page = PlcUtil.getCurAside(s7PLC);
- if(page.equals("A")){
- lblNewLabel_5.setText("当前:A面");
- }else{
- lblNewLabel_5.setText("当前:B面");
- }
-
- // 识别完当前面后,给禁用信号(仅在面切换时执行)
- if(!page.equals(lastDetectedPage)){
- lastDetectedPage = page;
- // Keep reserved start permission; side change only updates display state.
- System.out.println("turntable side changed: " + page + ", keep reserved enable signal");
- }
- }
- }, 1000,1000);
- }
- public static Timer cjTimer2;
- public static void getPlcParams() {
- if(cjTimer2!=null) {
- cjTimer2.cancel();
- }
- cjTimer2 = new Timer();
- cjTimer2.schedule(new TimerTask() {
- public void run() {
- try{
- PlcUtil.getParamDyDl(s7PLC);
- }catch (Exception e){
- e.printStackTrace();
- }
- }
- }, 1000,1000);
- }
- private static void readProperty() throws IOException{
- String enconding = "UTF-8";
- InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
- Properties pro = new Properties();
- BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
- pro.load(br);
- mes_gw = pro.getProperty("mes.gw");
- // mes_gw_des = pro.getProperty("mes.gw_des");
- mes_server_ip = pro.getProperty("mes.server_ip");
- mes_tcp_port = Integer.parseInt(pro.getProperty("mes.tcp_port"));
- mes_heart_beat_cycle = Integer.parseInt(pro.getProperty("mes.heart_beat_cycle"));
- mes_line_sn = pro.getProperty("mes.line_sn");
- mes_gw_des = OprnoUtil.getGwDes(mes_line_sn,mes_gw);
- mes_gwflag = pro.getProperty("mes.gwflag");
- System.out.println(mes_gw + ";" + mes_gw_des + ";" + mes_server_ip + ";" + mes_tcp_port + ";" + mes_heart_beat_cycle);
- }
- // 閸掓繂顫愰崠鏈P
- public static void initTcpConnection() {
- try {
- if(nettyClient==null) {
- nettyClient = new NettyClient();
- tcp_connect_flag = false;
- connect_request_flag = true;
- DataUtil.synrTcp(nettyClient,mes_gw);
- }
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- public static java.util.Timer heartBeatTimer;
- public static java.util.Timer heartBeatIconTimer;
- public static boolean iconREDFlag = true;
- public static JTextField param1;
- public static JTextField param2;
- public static JTextField param3;
- public static JTextField param4;
- public static JTextField param5;
- public static JTextField product_sn2;
- public static JTextField param21;
- public static JTextField param22;
- public static JTextField param23;
- public static JTextField param24;
- public static JTextField param25;
- public static void startHeartBeatTimer() {
- if(heartBeatTimer!=null) {
- heartBeatTimer.cancel();
- }
- heartBeatTimer = new java.util.Timer();
- heartBeatTimer.schedule(new TimerTask() {
- public void run() {
- if(nettyClient!=null&&tcp_connect_flag) {
- DataUtil.heartBeat(nettyClient,mes_gw);
- heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
- }
- }
- }, 100,mes_heart_beat_cycle*1000);
- if(heartBeatIconTimer!=null) {
- heartBeatIconTimer.cancel();
- }
- heartBeatIconTimer = new Timer();
- heartBeatIconTimer.schedule(new TimerTask() {
- public void run() {
- if(tcp_connect_flag) {
- if(iconREDFlag) {
- heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
- iconREDFlag = false;
- }else {
- heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
- iconREDFlag = true;
- }
- heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
- heart_beat_menu.repaint();
- }else {
- heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
- heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
- heart_beat_menu.repaint();
- if(nettyClient!=null&&!tcp_connect_flag){
- if(!connect_request_flag) {
- connect_request_flag = true;
- DataUtil.synrTcp(nettyClient,mes_gw);
- }
- }
- }
- }
- }, 100,mes_heart_icon_cycle*1000);
- }
- public static void setTcpStatus() {
- if(tcp_connect_flag) {
- status_menu.setText("已连接MES服务器");
- heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
- heart_beat_menu.repaint();
- }else {
- status_menu.setText("未连接MES服务器");
- heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
- heart_beat_menu.repaint();
- }
- }
- public static void initWarehouseData(){
- resetScanA();
- resetScanB();
- // PlcUtil.changeEnable(s7PLC,false);
- }
- public static void resetScanA() {
- work_status = 0;
- check_quality_result = false;
- MesClient.finish_ok_bt.setEnabled(true);
- MesClient.mesQualityFlagA = false;
- product_sn.setText("");
- MesClient.pxstatus1.setText("A");
- MesClient.param1.setText("");
- MesClient.param2.setText("");
- MesClient.param3.setText("");
- MesClient.param4.setText("");
- MesClient.param5.setText("");
- MesClient.param21.setText("");
- MesClient.param22.setText("");
- MesClient.param23.setText("");
- MesClient.param24.setText("");
- MesClient.param25.setText("");
- MesClient.curFlag = "";
- MesClient.curSna = "";
- MesClient.tjFlaga = 0;
- PlcUtil.changeEnable(s7PLC, false, "A");
- updateMaterailData(); // 更新物料
- shiftUserCheck();
- }
- public static int userLoginHours;//用户登录所处小时
- public static JTextField textField;
- //换班用户信息检查
- private static void shiftUserCheck() {
- LocalDateTime now = LocalDateTime.now();
- // 判断时间范围
- if (userLoginHours >= 8 && userLoginHours < 20) {
- int hour = now.getHour();
- if (hour >= 20 || hour < 8) {
- logoff();
- }
- } else {
- int hour = now.getHour();
- if (hour >= 8 && hour < 20) {
- logoff();
- }
- }
- }
- public static void resetScanB() {
- work_status2 = 0;
- check_quality_result2 = false;
- MesClient.finish_ng_bt.setEnabled(true);
- MesClient.mesQualityFlagB = false;
- product_sn2.setText("");
- MesClient.pxstatus2.setText("B");
- MesClient.param1.setText("");
- MesClient.param2.setText("");
- MesClient.param3.setText("");
- MesClient.param4.setText("");
- MesClient.param5.setText("");
- MesClient.param21.setText("");
- MesClient.param22.setText("");
- MesClient.param23.setText("");
- MesClient.param24.setText("");
- MesClient.param25.setText("");
- MesClient.curFlag = "";
- MesClient.curSnb = "";
- MesClient.tjFlagb = 0;
- PlcUtil.changeEnable(s7PLC, false, "B");
- updateMaterailData(); // 更新物料
- shiftUserCheck();
- }
- //閼惧嘲褰囬悽銊﹀煕20娴o拷
- public static void getUser() {
- user20 = user_menu.getText().toString();
- String space_tmp1 = "";
- if(user20.length()<20) {
- for(int i=0;i<20-user20.length();i++) {
- space_tmp1 = space_tmp1 + " ";
- }
- }
- user20 = user20 + space_tmp1;
- }
- public static String getBarcode(String barcodeTmp) {
- String barcodeRet = barcodeTmp;
- if(barcodeTmp.equalsIgnoreCase("")) {
- return "";
- }else {
- if(barcodeTmp.length()<36) {
- String space = "";
- for(int i=0;i<36-barcodeTmp.length();i++) {
- space = space + " ";
- }
- barcodeRet = barcodeTmp + space;
- }
- }
- return barcodeRet;
- }
- public static void logoff() {
- welcomeWin.setVisible(true);
- mesClientFrame.setVisible(false);
- nettyClient = null;
- if(heartBeatTimer!=null) {
- heartBeatTimer.cancel();
- }
- if(heartBeatIconTimer!=null) {
- heartBeatIconTimer.cancel();
- }
- tcp_connect_flag = false;
- connect_request_flag = false;
- }
- public MesClient() {
- setIconImage(Toolkit.getDefaultToolkit().getImage(MesClient.class.getResource("/bg/logo.png")));
- setTitle("MES系统客户端:"+mes_gw + "- " + mes_gw_des);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(0, 0, 1024, 768);
- JMenuBar menuBar = new JMenuBar();
- menuBar.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 26));
- setJMenuBar(menuBar);
- JMenu fileMenu = new JMenu("\u7528\u6237");
- fileMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/user.png")));
- fileMenu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
- menuBar.add(fileMenu);
- JMenuItem exitMenuItem = new JMenuItem("退出");
- exitMenuItem.setIcon(new ImageIcon(MesClient.class.getResource("/bg/logoff.png")));
- exitMenuItem.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
- fileMenu.add(exitMenuItem);
- exitMenuItem.addMouseListener(new MouseAdapter() {
- @Override
- public void mousePressed(MouseEvent e) {
- super.mouseClicked(e);
- //dispose();
- logoff();
- }
- });
- JMenu settingMenu = new JMenu("设置");
- //settingMenu.setVisible(false);
- settingMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")));
- settingMenu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
- menuBar.add(settingMenu);
- JMenuItem resetTcpMenu = new JMenuItem("\u91CD\u8FDEMES");
- resetTcpMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
- resetTcpMenu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
- resetTcpMenu.addMouseListener(new MouseAdapter() {
- @Override
- public void mousePressed(MouseEvent e) {
- super.mouseClicked(e);
- nettyClient.future.channel().close();
- }
- });
- settingMenu.add(resetTcpMenu);
- JMenuItem resetTcpMenu_1 = new JMenuItem("\u91CD\u65B0\u626B\u7801-A");
- resetTcpMenu_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
- resetTcpMenu_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
- resetTcpMenu_1.addMouseListener(new MouseAdapter() {
- @Override
- public void mousePressed(MouseEvent e) {
- super.mouseClicked(e);
- resetScanA();
- }
- });
- settingMenu.add(resetTcpMenu_1);
-
- JMenuItem resetTcpMenu_1_1 = new JMenuItem("\u91CD\u65B0\u626B\u7801-B");
- resetTcpMenu_1_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
- resetTcpMenu_1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
- resetTcpMenu_1_1.addMouseListener(new MouseAdapter() {
- @Override
- public void mousePressed(MouseEvent e) {
- super.mouseClicked(e);
- resetScanB();
- }
- });
- settingMenu.add(resetTcpMenu_1_1);
- JMenuItem resetTcpMenu_1sd = new JMenuItem("手动提交-A");
- resetTcpMenu_1sd.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
- resetTcpMenu_1sd.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
- resetTcpMenu_1sd.addMouseListener(new MouseAdapter() {
- @Override
- public void mousePressed(MouseEvent e) {
- super.mouseClicked(e);
- if(mesQualityFlagA == true){
- String sn = getBarcode(product_sn.getText());
- getUser();
- if(!sn.isEmpty()){
- String qret = "OK";
- Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"A");
- if(!sendret){
- MesClient.setMenuStatus("上传MES失败,请重试",-1);
- }
- }
- }
- }
- });
- settingMenu.add(resetTcpMenu_1sd);
- JMenuItem resetTcpMenu_1_1sd = new JMenuItem("手动提交-B");
- resetTcpMenu_1_1sd.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
- resetTcpMenu_1_1sd.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
- resetTcpMenu_1_1sd.addMouseListener(new MouseAdapter() {
- @Override
- public void mousePressed(MouseEvent e) {
- super.mouseClicked(e);
- if(mesQualityFlagB == true){
- String sn = getBarcode(product_sn2.getText());
- getUser();
- if(!sn.isEmpty()){
- String qret = "OK";
- Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"B");
- if(!sendret){
- MesClient.setMenuStatus("上传MES失败,请重试",-1);
- }
- }
- }
- }
- });
- settingMenu.add(resetTcpMenu_1_1sd);
- // 打印机设置菜单
- JMenuItem printerSettingMenu = new JMenuItem("打印机设置");
- printerSettingMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")));
- printerSettingMenu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
- printerSettingMenu.addMouseListener(new MouseAdapter() {
- @Override
- public void mousePressed(MouseEvent e) {
- super.mouseClicked(e);
- try {
- // 调用打印机设置对话框
- com.mes.print.ui.PrinterSettingDialog dialog =
- new com.mes.print.ui.PrinterSettingDialog(MesClient.this);
- dialog.setVisible(true);
- } catch (Exception ex) {
- JOptionPane.showMessageDialog(MesClient.this,
- "打开打印机设置失败: " + ex.getMessage(),
- "错误",
- JOptionPane.ERROR_MESSAGE);
- ex.printStackTrace();
- }
- }
- });
- settingMenu.add(printerSettingMenu);
- contentPane = new JPanel();
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(new BorderLayout(0, 0));
- JToolBar toolBar = new JToolBar();
- contentPane.add(toolBar, BorderLayout.NORTH);
- JLabel equipment_statu_label = new JLabel("\u72B6\u6001\uFF1A");
- equipment_statu_label.setHorizontalAlignment(SwingConstants.CENTER);
- equipment_statu_label.setForeground(Color.BLACK);
- equipment_statu_label.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
- equipment_statu_label.setBackground(Color.LIGHT_GRAY);
- toolBar.add(equipment_statu_label);
- status_menu = new JButton("设备未连接MES服务器");
- if(tcp_connect_flag) {
- status_menu.setText("已连接MES服务器");
- status_menu.setForeground(Color.GREEN);
- }else {
- status_menu.setText("未连接MES服务器");
- status_menu.setForeground(Color.DARK_GRAY);
- }
- status_menu.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- }
- });
- status_menu.setForeground(Color.GREEN);
- status_menu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
- status_menu.setBackground(Color.BLACK);
- toolBar.add(status_menu);
- JLabel space_1 = new JLabel(" ");
- toolBar.add(space_1);
- JLabel heart_beat_status_label = new JLabel("\u5FC3\u8DF3\uFF1A");
- heart_beat_status_label.setHorizontalAlignment(SwingConstants.CENTER);
- heart_beat_status_label.setForeground(Color.BLACK);
- heart_beat_status_label.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
- heart_beat_status_label.setBackground(Color.LIGHT_GRAY);
- toolBar.add(heart_beat_status_label);
- heart_beat_menu = new JButton("2024-02-20 23:20:10");
- heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
- heart_beat_menu.setForeground(Color.GREEN);
- heart_beat_menu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
- heart_beat_menu.setBackground(Color.BLACK);
- toolBar.add(heart_beat_menu);
- JLabel space_2 = new JLabel(" ");
- toolBar.add(space_2);
- JLabel user_status_label = new JLabel("\u767B\u5F55\u7528\u6237\uFF1A");
- user_status_label.setHorizontalAlignment(SwingConstants.CENTER);
- user_status_label.setForeground(Color.BLACK);
- user_status_label.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
- user_status_label.setBackground(Color.LIGHT_GRAY);
- toolBar.add(user_status_label);
- user_menu = new JButton("JinJuShi");
- user_menu.setForeground(Color.GREEN);
- user_menu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
- user_menu.setBackground(Color.BLACK);
- toolBar.add(user_menu);
- JLabel space_3 = new JLabel(" ");
- toolBar.add(space_3);
- JLabel space_4 = new JLabel(" ");
- toolBar.add(space_4);
- tabbedPane = new JTabbedPane(JTabbedPane.TOP);
- tabbedPane.setMinimumSize(new Dimension(400, 50));
- tabbedPane.setFont(new Font("Microsoft YaHei UI", Font.BOLD, 22));
- contentPane.add(tabbedPane);
- JPanel indexPanelA = new JPanel();
- indexScrollPaneA = new JScrollPane(indexPanelA);
- indexPanelA.setLayout(null);
- product_sn = new JTextField();
- product_sn.setText("");
- product_sn.setHorizontalAlignment(SwingConstants.CENTER);
- product_sn.setEditable(false);
- product_sn.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
- product_sn.setBounds(26, 144, 446, 70);
- // 添加鼠标点击事件,点击显示二维码
- product_sn.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent e) {
- String sn = product_sn.getText();
- if(sn != null && !sn.trim().isEmpty()){
- new com.mes.component.QRCodeDialog(mesClientFrame, "A面工件码二维码", sn);
- }
- }
- });
- indexPanelA.add(product_sn);
- product_sn.setColumns(10);
- finish_ok_bt = new JButton("扫码");
- finish_ok_bt.setVisible(false);
- finish_ok_bt.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- scanBarcode();
- // String sn = getBarcode(product_sn.getText());
- // getUser();
- //
- // if(!sn.isEmpty()){
- // String qret = "OK";
- // Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"A");
- // if(!sendret){
- // JOptionPane.showMessageDialog(mesClientFrame,"上传MES失败,请重试","提醒", JOptionPane.INFORMATION_MESSAGE);
- // return;
- // }
- // }
- }
- });
- // finish_ok_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
- finish_ok_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/scan_barcode.png")));
- finish_ok_bt.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 32));
- finish_ok_bt.setBounds(136, 167, 230, 80);
- finish_ok_bt.setEnabled(false);
- indexPanelA.add(finish_ok_bt);
- finish_ng_bt = new JButton("扫码");
- finish_ng_bt.setVisible(false);
- finish_ng_bt.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- scanBarcode();
- // String sn = getBarcode(product_sn2.getText());
- // getUser();
- //
- // if(!sn.isEmpty()){
- // String qret = "OK";
- // Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"B");
- // if(!sendret){
- // JOptionPane.showMessageDialog(mesClientFrame,"上传MES失败,请重试","提醒", JOptionPane.INFORMATION_MESSAGE);
- // return;
- // }
- // }
- }
- });
- // finish_ng_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
- finish_ng_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/scan_barcode.png")));
- finish_ng_bt.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 32));
- finish_ng_bt.setBounds(633, 167, 230, 80);
- finish_ng_bt.setEnabled(false);
- indexPanelA.add(finish_ng_bt);
-
- JLabel lblNewLabel = new JLabel("电压");
- lblNewLabel.setHorizontalAlignment(SwingConstants.RIGHT);
- lblNewLabel.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
- lblNewLabel.setBounds(26, 340, 100, 40);
- indexPanelA.add(lblNewLabel);
-
- JLabel lblNewLabel_1 = new JLabel("电流");
- lblNewLabel_1.setHorizontalAlignment(SwingConstants.RIGHT);
- lblNewLabel_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
- lblNewLabel_1.setBounds(226, 340, 100, 40);
- indexPanelA.add(lblNewLabel_1);
-
- param1 = new JTextField();
- param1.setEnabled(false);
- param1.setEditable(false);
- param1.setHorizontalAlignment(SwingConstants.CENTER);
- param1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
- param1.setBounds(136, 340, 70, 40);
- indexPanelA.add(param1);
- param1.setColumns(10);
-
- param2 = new JTextField();
- param2.setEnabled(false);
- param2.setEditable(false);
- param2.setHorizontalAlignment(SwingConstants.CENTER);
- param2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
- param2.setColumns(10);
- param2.setBounds(345, 340, 70, 40);
- indexPanelA.add(param2);
-
- JLabel lblNewLabel_2 = new JLabel("送丝速度");
- lblNewLabel_2.setHorizontalAlignment(SwingConstants.RIGHT);
- lblNewLabel_2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
- lblNewLabel_2.setBounds(26, 401, 100, 40);
- indexPanelA.add(lblNewLabel_2);
-
- param3 = new JTextField();
- param3.setEnabled(false);
- param3.setEditable(false);
- param3.setHorizontalAlignment(SwingConstants.CENTER);
- param3.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
- param3.setColumns(10);
- param3.setBounds(136, 401, 70, 40);
- indexPanelA.add(param3);
-
- JLabel lblNewLabel_1_1 = new JLabel("错误代码");
- lblNewLabel_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
- lblNewLabel_1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
- lblNewLabel_1_1.setBounds(213, 401, 122, 40);
- indexPanelA.add(lblNewLabel_1_1);
-
- param4 = new JTextField();
- param4.setEnabled(false);
- param4.setEditable(false);
- param4.setHorizontalAlignment(SwingConstants.CENTER);
- param4.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
- param4.setColumns(10);
- param4.setBounds(345, 401, 70, 40);
- indexPanelA.add(param4);
-
- param5 = new JTextField();
- param5.setEnabled(false);
- param5.setEditable(false);
- param5.setHorizontalAlignment(SwingConstants.CENTER);
- param5.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
- param5.setColumns(10);
- param5.setBounds(226, 470, 70, 40);
- indexPanelA.add(param5);
-
- JLabel lblNewLabel_1_1_1 = new JLabel("JOB号");
- lblNewLabel_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
- lblNewLabel_1_1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
- lblNewLabel_1_1_1.setBounds(106, 470, 122, 40);
- indexPanelA.add(lblNewLabel_1_1_1);
-
- product_sn2 = new JTextField();
- product_sn2.setText("");
- product_sn2.setHorizontalAlignment(SwingConstants.CENTER);
- product_sn2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
- product_sn2.setEditable(false);
- product_sn2.setColumns(10);
- product_sn2.setBounds(517, 144, 446, 70);
- // 添加鼠标点击事件,点击显示二维码
- product_sn2.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent e) {
- String sn = product_sn2.getText();
- if(sn != null && !sn.trim().isEmpty()){
- new com.mes.component.QRCodeDialog(mesClientFrame, "B面工件码二维码", sn);
- }
- }
- });
- indexPanelA.add(product_sn2);
-
- JSeparator separator = new JSeparator();
- separator.setBounds(450, 247, 0, 80);
- indexPanelA.add(separator);
-
- JSeparator separator_1 = new JSeparator();
- separator_1.setOrientation(SwingConstants.VERTICAL);
- separator_1.setBounds(495, 77, 23, 177);
- indexPanelA.add(separator_1);
-
- JLabel lblNewLabel_3 = new JLabel("电压");
- lblNewLabel_3.setHorizontalAlignment(SwingConstants.RIGHT);
- lblNewLabel_3.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
- lblNewLabel_3.setBounds(528, 340, 100, 40);
- indexPanelA.add(lblNewLabel_3);
-
- param21 = new JTextField();
- param21.setEnabled(false);
- param21.setEditable(false);
- param21.setHorizontalAlignment(SwingConstants.CENTER);
- param21.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
- param21.setColumns(10);
- param21.setBounds(638, 340, 70, 40);
- indexPanelA.add(param21);
-
- JLabel lblNewLabel_1_2 = new JLabel("电流");
- lblNewLabel_1_2.setHorizontalAlignment(SwingConstants.RIGHT);
- lblNewLabel_1_2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
- lblNewLabel_1_2.setBounds(742, 340, 100, 40);
- indexPanelA.add(lblNewLabel_1_2);
-
- param22 = new JTextField();
- param22.setEnabled(false);
- param22.setEditable(false);
- param22.setHorizontalAlignment(SwingConstants.CENTER);
- param22.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
- param22.setColumns(10);
- param22.setBounds(852, 340, 70, 40);
- indexPanelA.add(param22);
-
- JLabel lblNewLabel_2_1 = new JLabel("送丝速度");
- lblNewLabel_2_1.setHorizontalAlignment(SwingConstants.RIGHT);
- lblNewLabel_2_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
- lblNewLabel_2_1.setBounds(528, 401, 100, 40);
- indexPanelA.add(lblNewLabel_2_1);
-
- param23 = new JTextField();
- param23.setEnabled(false);
- param23.setEditable(false);
- param23.setHorizontalAlignment(SwingConstants.CENTER);
- param23.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
- param23.setColumns(10);
- param23.setBounds(638, 401, 70, 40);
- indexPanelA.add(param23);
-
- JLabel lblNewLabel_1_1_2 = new JLabel("错误代码");
- lblNewLabel_1_1_2.setHorizontalAlignment(SwingConstants.RIGHT);
- lblNewLabel_1_1_2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
- lblNewLabel_1_1_2.setBounds(718, 401, 122, 40);
- indexPanelA.add(lblNewLabel_1_1_2);
-
- param24 = new JTextField();
- param24.setEnabled(false);
- param24.setEditable(false);
- param24.setHorizontalAlignment(SwingConstants.CENTER);
- param24.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
- param24.setColumns(10);
- param24.setBounds(852, 401, 70, 40);
- indexPanelA.add(param24);
-
- JLabel lblNewLabel_1_1_1_1 = new JLabel("JOB号");
- lblNewLabel_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
- lblNewLabel_1_1_1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
- lblNewLabel_1_1_1_1.setBounds(609, 470, 122, 40);
- indexPanelA.add(lblNewLabel_1_1_1_1);
-
- param25 = new JTextField();
- param25.setEnabled(false);
- param25.setEditable(false);
- param25.setHorizontalAlignment(SwingConstants.CENTER);
- param25.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
- param25.setColumns(10);
- param25.setBounds(742, 470, 70, 40);
- indexPanelA.add(param25);
-
- pxstatus1 = new JLabel("A");
- pxstatus1.setForeground(new Color(255, 128, 64));
- pxstatus1.setHorizontalAlignment(SwingConstants.CENTER);
- pxstatus1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
- pxstatus1.setBounds(26, 90, 446, 44);
- indexPanelA.add(pxstatus1);
-
- pxstatus2 = new JLabel("B");
- pxstatus2.setForeground(new Color(255, 128, 64));
- pxstatus2.setHorizontalAlignment(SwingConstants.CENTER);
- pxstatus2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
- pxstatus2.setBounds(517, 90, 446, 44);
- indexPanelA.add(pxstatus2);
-
- JSeparator separator_2 = new JSeparator();
- separator_2.setBounds(10, 264, 973, 13);
- indexPanelA.add(separator_2);
-
- JLabel lblNewLabel_4 = new JLabel("\u710A\u673A1");
- lblNewLabel_4.setHorizontalAlignment(SwingConstants.CENTER);
- lblNewLabel_4.setFont(new Font("微软雅黑", Font.PLAIN, 24));
- lblNewLabel_4.setBounds(170, 290, 156, 40);
- indexPanelA.add(lblNewLabel_4);
-
- JLabel lblNewLabel_4_1 = new JLabel("\u710A\u673A2");
- lblNewLabel_4_1.setHorizontalAlignment(SwingConstants.CENTER);
- lblNewLabel_4_1.setFont(new Font("微软雅黑", Font.PLAIN, 24));
- lblNewLabel_4_1.setBounds(670, 287, 156, 40);
- indexPanelA.add(lblNewLabel_4_1);
-
- textField = new JTextField("");
- textField.setEnabled(true);
- textField.setHorizontalAlignment(SwingConstants.LEFT);
- textField.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
- textField.setColumns(10);
- textField.setBounds(264, 10, 510, 50);
- textField.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- scanBarcode();
- }
- });
- indexPanelA.add(textField);
-
- lblNewLabel_5 = new JLabel("当前:A面");
- lblNewLabel_5.setForeground(new Color(0, 128, 64));
- lblNewLabel_5.setFont(new Font("微软雅黑", Font.PLAIN, 20));
- lblNewLabel_5.setBounds(136, 10, 113, 50);
- indexPanelA.add(lblNewLabel_5);
- tabbedPane.addTab("工作面板", new ImageIcon(MesClient.class.getResource("/bg/a_side.png")), indexScrollPaneA, null);
- tabbedPane.setEnabledAt(0, true);
- JPanel indexPanelGz = new JPanel();
- searchScrollPaneGz = new JScrollPane(indexPanelGz);
- indexPanelGz.setLayout(null);
- gzStartBtnA = new JButton("A面点检");
- gzStartBtnA.setBounds(150,15,160, 70);
- gzStartBtnA.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 28));
- gzStartBtnA.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- gzStartBtnA.setEnabled(false);
- gzStartBtnB.setEnabled(false);
- gzStartStatus = 1;
- gzCheckType = "A";
- }
- });
- indexPanelGz.add(gzStartBtnA);
- gzStartBtnB = new JButton("B面点检");
- gzStartBtnB.setBounds(350,15,160, 70);
- gzStartBtnB.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 28));
- gzStartBtnB.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- gzStartBtnA.setEnabled(false);
- gzStartBtnB.setEnabled(false);
- gzCancelBtn.setEnabled(true);
- gzStartStatus = 1;
- gzCheckType = "B";
- }
- });
- indexPanelGz.add(gzStartBtnB);
- gzCancelBtn = new JButton("取消");
- gzCancelBtn.setEnabled(false);
- gzCancelBtn.setBounds(600,15,160, 70);
- gzCancelBtn.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 28));
- gzCancelBtn.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- gzStartBtnA.setEnabled(false);
- gzStartBtnB.setEnabled(false);
- gzStartStatus = 0;
- gzCheckType = "";
- }
- });
- indexPanelGz.add(gzCancelBtn);
- gzFinishBtn = new JButton("上传结果");
- gzFinishBtn.setEnabled(false);
- gzFinishBtn.setBounds(800,15,160, 70);
- gzFinishBtn.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 28));
- gzFinishBtn.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- String content = String.join(",",gzbtns);
- // 提交点检
- JSONObject retObj = DataUtil.saveGzCheck(content,user_menu.getText());
- if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
- MesClient.setMenuStatus("工装点检提交成功",0);
- resetGzCheck();
- }else{
- MesClient.setMenuStatus("工装点检提交失败",-1);
- }
- }
- });
- indexPanelGz.add(gzFinishBtn);
- gzdjpanel = new JPanel();
- gzdjpanel.setBounds(0,100,990, 450);
- gzdjpanel.setLayout(new GridLayout(0, 9));
- List<Integer> olists = new ArrayList<>();
- // olists.add(9);
- // olists.add(11);
- for (int i = 0; i < 45; i++) {
- if(!olists.contains(i+1)){
- JButton btn = new JButton("检测" + (i + 1));
- btn.putClientProperty("id", i);
- btn.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 24));
- gzdjpanel.add(btn);
- }
- }
- indexPanelGz.add(gzdjpanel);
- formatGzbtns();
- // tabbedPane.addTab("工装点检", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPaneGz, null);
- indexPanelC = new JPanel();
- searchScrollPaneDj = new JScrollPane(indexPanelC);
- indexPanelC.setLayout(null);
- tabbedPane.addTab("开班点检", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPaneDj, null);
- indexPanelB = new JPanel();
- searchScrollPane = new JScrollPane(indexPanelB);
- indexPanelB.setLayout(null);
- tabbedPane.addTab("工作记录", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPane, null);
- // bindBatchPanel();
- tabbedPane.addChangeListener(new ChangeListener() {
- @Override
- public void stateChanged(ChangeEvent e) {
- JTabbedPane tabbedPane = (JTabbedPane) e.getSource();
- int selectedIndex = tabbedPane.getSelectedIndex();
- System.out.println("selectedIndex:"+selectedIndex);
- if(selectedIndex == 1){
- }
- }
- });
- }
- public static void resetGzCheck(){
- MesClient.gzStartStatus = 0;
- MesClient.gzCheckType = "";
- gzFinishBtn.setEnabled(false);
- gzStartBtnA.setEnabled(true);
- gzStartBtnB.setEnabled(true);
- int i = 0;
- for (String str:MesClient.gzbtns){
- MesClient.gzbtns[i] = "UD";
- i++;
- }
- }
- public static void formatGzbtns(){
- int i = 0;
- Boolean flag = true;
- for (String bresult:gzbtns){
- JButton jj = (JButton) gzdjpanel.getComponents()[i];
- if(bresult.equals("OK")){
- jj.setBackground(Color.green);
- jj.setForeground(Color.white);
- }else{
- flag = false;
- jj.setBackground(null);
- jj.setForeground(Color.black);
- }
- i++;
- }
- if(flag){
- MesClient.gzFinishBtn.setEnabled(true);
- }else{
- MesClient.gzFinishBtn.setEnabled(false);
- }
- }
- public static void setMenuStatus(String msg,int error){
- if(error == 0){
- MesClient.status_menu.setForeground(Color.GREEN);
- }else{
- MesClient.status_menu.setForeground(Color.RED);
- }
- MesClient.status_menu.setText(msg);
- }
- public static void getMaterailData(){
- JSONObject retObj = DataUtil.getBindMaterail();
- if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
- List<BindMaterialResp> arrs = retObj.getList("data",BindMaterialResp.class);
- int i = 0;
- rowData = new Object[arrs.size()][7];
- for (BindMaterialResp bindMaterialResp:arrs){
- rowData[i][0] = bindMaterialResp.getMaterialTitle();
- rowData[i][1] = bindMaterialResp.getBatchSn();
- rowData[i][2] = bindMaterialResp.getLastTimes();
- rowData[i][3] = "";
- rowData[i][4] = bindMaterialResp.getCraft();
- rowData[i][5] = bindMaterialResp.getMaterialId();
- rowData[i][6] = bindMaterialResp.getType();
- i++;
- }
- bindBatchPanel();
- }
- }
- public static void updateMaterailData(){
- JSONObject retObj = DataUtil.getBindMaterail();
- if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
- List<BindMaterialResp> arrs = retObj.getList("data",BindMaterialResp.class);
- int i = 0;
- for (BindMaterialResp bindMaterialResp:arrs){
- rowData[i][0] = bindMaterialResp.getMaterialTitle();
- rowData[i][1] = bindMaterialResp.getBatchSn();
- rowData[i][2] = bindMaterialResp.getLastTimes();
- rowData[i][3] = "";
- rowData[i][4] = bindMaterialResp.getCraft();
- rowData[i][5] = bindMaterialResp.getMaterialId();
- rowData[i][6] = bindMaterialResp.getType();
- i++;
- }
- MesClient.table.repaint();
- }
- }
- // 绑定物料批次码
- public static void scanBatchSn(BindMaterialResp bindMaterialResp) { // 扫码类型
- //弹窗扫工件码
- String scanBarcodeTitle = "请扫物料:"+bindMaterialResp.getMaterialTitle();
- String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
- if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")) {
- JSONObject retObj = DataUtil.saveBindMaterail(scanBarcode,bindMaterialResp.getCraft(),bindMaterialResp.getMaterialId(),bindMaterialResp.getType());
- if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
- MesClient.setMenuStatus("扫物料:"+bindMaterialResp.getMaterialTitle()+"成功",0);
- updateMaterailData();
- }else{
- if(retObj.get("result")==null){
- MesClient.setMenuStatus("请求失败,请重试",-1);
- }else{
- if(retObj.get("result").toString().equalsIgnoreCase("false")){
- MesClient.setMenuStatus(retObj.getString("message"),-1);
- }
- }
- }
- }
- }
- public static void bindBatchPanel(){
- JPanel indexPanelBB = new JPanel();
- JPanel panel = new JPanel();
- panel.setBounds(0, 0, 990, 550);
- // panel.setBounds(81, 50, 810, 479);
- indexPanelBB.add(panel);
- panel.setLayout(new GridLayout(0, 1, 0, 0));
- table = new JTable(rowData, columnNames){
- public boolean isCellEditable(int row, int column) {
- if(column == 3){
- return true;
- }
- return false;
- }
- };
- table.setRowHeight(40);
- table.setEnabled(true);
- table.setFont(new Font("微软雅黑", Font.PLAIN, 14));
- table.getColumnModel().getColumn(3).setCellRenderer(new TableCellRendererButton());
- table.getColumnModel().getColumn(3).setCellEditor(new TableCellEditorButton());
- JScrollPane scrollPane = new JScrollPane(table);
- panel.add(scrollPane);
- indexScrollPaneB = new JScrollPane(indexPanelBB);
- indexPanelBB.setLayout(null);
- tabbedPane.addTab("绑定物料", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), indexScrollPaneB, null);
- }
- public static void scanBarcode() {
- String sn = textField.getText().trim();
- textField.setText("");
- //刷新界面
- mesClientFrame.repaint();
- if(sn.isEmpty()){
- MesClient.setMenuStatus("工件码不能为空",1);
- return;
- }
- String page = PlcUtil.getReserveSide(s7PLC);
- if(page.equals("A")){
- if(!product_sn.getText().isEmpty() && mesQualityFlagA){
- MesClient.setMenuStatus("A面已存在工件码,勿重复扫码",1);
- return;
- }
- product_sn.setText(sn);
- }else{
- if(!product_sn2.getText().isEmpty() && mesQualityFlagB){
- MesClient.setMenuStatus("B面已存在工件码,勿重复扫码",1);
- return;
- }
- product_sn2.setText(sn);
- }
- MesClient.setMenuStatus("扫码成功",0);
- //刷新界面
- mesClientFrame.repaint();
- getUser();
- // 查询工件质量
- Boolean sendret = DataUtil.checkQuality(nettyClient,sn,user20,page);
- if(!sendret){
- MesClient.setMenuStatus("消息发送失败,请重试",1);
- }
- }
- public static void scanBarcodeOld() {
- String scanBarcodeTitle = "请扫工件码";
- String page = PlcUtil.getCurAside(s7PLC);
- if(page.equals("A")){
- product_sn.setText("");
- }else{
- product_sn2.setText("");
- }
- //弹窗扫工件码
- String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
- if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")) {
- //获取用户
- getUser();
- //获取扫码内容36位
- String barcode36 = getBarcode(scanBarcode);//处理36为码
- if(page.equals("A")){
- product_sn.setText(scanBarcode);
- }else{
- product_sn2.setText(scanBarcode);
- }
- //刷新界面
- mesClientFrame.repaint();
- if(!tcp_connect_flag) {
- MesClient.setMenuStatus("设备未连接Mes服务器",1);
- return;
- }
- // String ptype = checkSnType(scanBarcode);
- // if(ptype.isEmpty()){
- // MesClient.setMenuStatus("零件码不正确",1);
- // return;
- // }
- // if(ptype.equals("MX11-2")){
- // if(page.equals("A")){
- // PlcUtil.acx2(s7PLC,true);
- // PlcUtil.acx2s(s7PLC,false);
- // }else{
- // PlcUtil.bcx2(s7PLC,true);
- // PlcUtil.bcx2s(s7PLC,false);
- // }
- // }else if(ptype.equals("MX11-2S")){
- // if(page.equals("A")){
- // PlcUtil.acx2s(s7PLC,true);
- // PlcUtil.acx2(s7PLC,false);
- // }else{
- // PlcUtil.bcx2s(s7PLC,true);
- // PlcUtil.bcx2(s7PLC,false);
- // }
- // }
- // 查询工件质量
- Boolean sendret = DataUtil.checkQuality(nettyClient,barcode36,user20,page);
- if(!sendret){
- MesClient.setMenuStatus("消息发送失败,请重试",1);
- return;
- }
- }else {
- JOptionPane.showMessageDialog(mesClientFrame,"请扫工件码","提示窗口", JOptionPane.INFORMATION_MESSAGE);
- return;
- }
- }
- private static String checkSnType(String sn){
- String str = sn.substring(9,12);
- if(str.equals("113")){
- return "MX11-2";
- }else if(str.equals("119")){
- return "MX11-2S";
- }else{
- return "";
- }
- }
- // 开启发送结果定时任务
- // 开启发送结果定时任务
- public static void startUpdateQualityTimer(){
- // 创建异步线程池
- ExecutorService executorService = Executors.newSingleThreadExecutor();
- // 提交任务
- executorService.submit(() -> {
- log.info("异步任务执行中...");
- // 模拟耗时操作
- try {
- while (true){
- try {
- // 确保连接已经打开
- if (JdbcUtils.conn == null || JdbcUtils.conn.isClosed()) {
- JdbcUtils.openConnection();
- }
- Statement statement = JdbcUtils.conn.createStatement();
- String selectSql = "SELECT id, bw FROM submit_record\n" +
- "WHERE state = 0 ORDER BY id DESC LIMIT 10";
- String updateSql = "UPDATE submit_record \n" +
- "SET state = '1'\n" +
- "WHERE id = ";
- ResultSet rs = statement.executeQuery(selectSql);
- while(rs.next()){
- int id = rs.getInt("id");
- String bw = rs.getString("bw");
- // 发送请求
- String url = "http://"+MesClient.mes_server_ip+":8980/js/a/mes/mesProductRecord/updateQualityByTiming";
- log.info("质量:"+bw);
- String s = HttpUtils.sendPostRequestJson(url, bw );
- log.info("结果:"+s);
- Boolean result = JSONObject.parseObject(s).getBoolean("result");
- if(result) {
- // 更改状态为 1
- statement.executeUpdate(updateSql + id);
- }
- }
- rs.close();
- statement.close();
- } catch (Exception e) {
- log.info(e.getMessage());
- }
- try {
- Thread.sleep(2000);
- }catch (Exception e){
- log.info(e.getMessage());
- }
- }
- } catch (Exception e) {
- log.info(e.getMessage());
- }
- log.info("异步任务执行完毕");
- });
- }
- }
|