| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878 |
- package com.mes.ui;
- import com.alibaba.fastjson2.JSONObject;
- import com.fazecast.jSerialComm.SerialPort;
- import com.mes.component.MesRadio;
- import com.mes.component.MesWebView;
- import com.mes.netty.NettyClient;
- import com.mes.util.DateLocalUtils;
- import com.mes.util.HttpUtils;
- import com.mes.util.JdbcUtils;
- import com.mes.util.ModbusRtu;
- 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.*;
- import java.util.List;
- import java.util.Timer;
- 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; // 权限级别 0=无权限 1=操作工人 2=管理员
- public static String mes_gw = ""; // 工位号
- public static String mes_gw_des = ""; // 工位名称
- public static String mes_server_ip = ""; // 服务器IP地址
- public static int mes_tcp_port = 3000; // TCP服务端口
- public static int mes_heart_beat_cycle = 10; // 心跳周期
- public static int mes_heart_icon_cycle = 1;
- public static String mes_line_sn = ""; // 产线编号
- //TCP连接
- public static NettyClient nettyClient;
- //TCP连接状态
- public static boolean tcp_connect_flag = false;
- //TCP连接请求
- 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 searchScrollPane;
- public static JScrollPane searchScrollPaneD;
- public static JScrollPane searchScrollPaneDj;
- public static JScrollPane searchScrollPaneJs;
- public static JPanel indexPanelJs;
- public static MesWebView jfxPanelJs = null;
- public static Boolean check_quality_result = false;
- public static Integer work_status = 0;
- 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 JButton f_scan_data_bt_1;
- public static String user20 = "";
- public static JFrame welcomeWin;
- public static JPanel indexPanelB;
- public static MesWebView jfxPanel = null;
- public static JPanel indexPanelC;
- public static JPanel indexPanelD;
- public static MesWebView jfxPanel2 = null;
- public static MesWebView jfxPanel3 = null;
- public static MesRadio mesRadioHj;
- public static JTable table;
- public static Object[] columnNames = { "物料名称", "绑定批次", "剩余次数", "操作" };
- public static Object[][] rowData = null;
- public static SerialPort serialPort; // 串口对象
- public static void main(String[] args) {
- 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();
- serialPort = ModbusRtu.connect();
- // startJsTimer();
- startUpdateQualityTimer(); // 开启提交结果的定时任务
- }catch (Exception e){
- log.error(e.getMessage());
- }
- }
- });
- }
- //读配置文件
- 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);
- log.info(mes_gw + ";" + mes_gw_des + ";" + mes_server_ip + ";" + mes_tcp_port + ";" + mes_heart_beat_cycle);
- }
- // 初始化TCP
- public static void initTcpConnection() {
- try {
- if(nettyClient==null) {
- //初始化TCP连接
- nettyClient = new NettyClient();
- //TCP连接状态
- tcp_connect_flag = false;
- //设置TCP请求状态
- connect_request_flag = true;
- DataUtil.synrTcp(nettyClient,mes_gw);
- }
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- public static java.util.Timer jsTimer;
- public static Integer jsCount = 0;
- public static Integer jsFlag = 0; // 0=未关闭 1=已关闭
- public static void startJsTimer() { // 定时关闭继电器
- if(jsTimer!=null) {
- jsTimer.cancel();
- }
- jsTimer = new java.util.Timer();
- jsTimer.schedule(new TimerTask() {
- public void run() {
- if(work_status == 1) {
- jsCount++;
- if(jsCount > 2*60 && jsFlag == 0){
- ModbusRtu.closeDevice(serialPort);
- jsFlag = 1;
- }
- }
- }
- }, 100,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){
- System.out.println("TCP已断开");
- //TCP重新同步连接
- if(!connect_request_flag) {
- //System.out.println("TCP重新同步连接");
- //设置TCP请求状态,只重新同步连接一次
- connect_request_flag = true;
- DataUtil.synrTcp(nettyClient,mes_gw);
- }
- }
- }
- }
- }, 100,mes_heart_icon_cycle*1000);
- }
- //启动心跳包程序
- public static java.util.Timer heartBeatTimer;
- public static java.util.Timer heartBeatIconTimer;
- public static boolean iconREDFlag = true;
- 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) {
- //log.info("发送心跳报文");
- 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){
- log.info("TCP已断开");
- //TCP重新同步连接
- if(!connect_request_flag) {
- //log.info("TCP重新同步连接");
- //设置TCP请求状态,只重新同步连接一次
- connect_request_flag = true;
- DataUtil.synrTcp(nettyClient,mes_gw);
- }
- }
- }
- }
- }, 100,mes_heart_icon_cycle*1000);
- }
- //设置tcp连接状态显示
- public static void setTcpStatus() {
- if(tcp_connect_flag) {
- heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
- heart_beat_menu.repaint();
- }else {
- heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
- heart_beat_menu.repaint();
- }
- }
- public static void initWarehouseData(){
- resetScanA();
- }
- public static void resetScanA() {
- work_status = 0;
- check_quality_result = false;
- MesClient.finish_ok_bt.setEnabled(false);
- MesClient.finish_ng_bt.setEnabled(false);
- product_sn.setText("");
- MesClient.f_scan_data_bt_1.setEnabled(true);
- MesClient.setMenuStatus("请扫工件码",0);
- //继电器
- MesClient.jsFlag = 0;
- MesClient.jsCount = 0;
- try {
- ModbusRtu.closeDevice(serialPort);
- } catch (Exception e) {
- e.printStackTrace();
- }
- updateMaterailData();
- // shiftUserCheck();
- }
- public static int userLoginHours;//用户登录所处小时
- //换班用户信息检查
- 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() {
- }
- //获取用户20位
- 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;
- }
- //获取barcode内容36位
- 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 scanBarcode() {
- if(work_status == 1){
- JOptionPane.showMessageDialog(mesClientFrame,"工作中,勿扫码","提示窗口", JOptionPane.INFORMATION_MESSAGE);
- return;
- }
- String scanBarcodeTitle = "";
- switch(scan_type) {
- case 1:
- product_sn.setText("");
- scanBarcodeTitle = "请扫工件码";
- break;
- }
- //弹窗扫工件码
- String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
- if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")) {
- //获取用户
- getUser();
- //获取扫码内容36位
- String barcode36 = getBarcode(scanBarcode);//处理36为码
- //工位号
- String gw = "";
- switch(scan_type) {
- case 1:
- product_sn.setText(scanBarcode);
- break;
- }
- //刷新界面
- mesClientFrame.repaint();
- if(!tcp_connect_flag) {
- JOptionPane.showMessageDialog(mesClientFrame,"设备未连接Mes服务器","提示窗口", JOptionPane.INFORMATION_MESSAGE);
- return;
- }
- // 查询工件质量
- Boolean sendret = DataUtil.checkQuality(nettyClient,barcode36,user20);
- if(!sendret){
- JOptionPane.showMessageDialog(mesClientFrame,"消息发送失败,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
- return;
- }
- }else {
- JOptionPane.showMessageDialog(mesClientFrame,"请扫工件码","提示窗口", JOptionPane.INFORMATION_MESSAGE);
- return;
- }
- }
- public static void logoff() {
- // welcomeWin.setVisible(true);
- mesClientFrame.setVisible(false);
- //退出程序 退出登录
- System.exit(0);
- 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("用户");
- fileMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/user.png")));
- fileMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
- menuBar.add(fileMenu);
- JMenuItem exitMenuItem = new JMenuItem("退出");
- exitMenuItem.setIcon(new ImageIcon(MesClient.class.getResource("/bg/logoff.png")));
- exitMenuItem.setFont(new Font("微软雅黑", Font.PLAIN, 22));
- fileMenu.add(exitMenuItem);
- exitMenuItem.addMouseListener(new MouseAdapter() {
- @Override
- public void mousePressed(MouseEvent e) {//只能检测到mousePressed事件
- 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("微软雅黑", Font.PLAIN, 20));
- menuBar.add(settingMenu);
- JMenuItem resetTcpMenu = new JMenuItem("重连MES");
- resetTcpMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
- resetTcpMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
- resetTcpMenu.addMouseListener(new MouseAdapter() {
- @Override
- public void mousePressed(MouseEvent e) {
- super.mouseClicked(e);
- //重连mes
- nettyClient.future.channel().close();
- }
- });
- settingMenu.add(resetTcpMenu);
- JMenuItem resetTcpMenu_1 = new JMenuItem("刷新工件");
- resetTcpMenu_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
- resetTcpMenu_1.setFont(new Font("微软雅黑", Font.PLAIN, 20));
- resetTcpMenu_1.addMouseListener(new MouseAdapter() {
- @Override
- public void mousePressed(MouseEvent e) {
- super.mouseClicked(e);
- resetScanA();
- }
- });
- settingMenu.add(resetTcpMenu_1);
- JMenuItem reset1 = new JMenuItem("MES屏蔽");
- reset1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
- reset1.setFont(new Font("微软雅黑", Font.PLAIN, 20));
- reset1.addMouseListener(new MouseAdapter() {
- @Override
- public void mousePressed(MouseEvent e) {
- super.mouseClicked(e);
- ModbusRtu.openDevice(MesClient.serialPort);
- setMenuStatus("MES屏蔽成功",0);
- }
- });
- settingMenu.add(reset1);
- 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("状态:");
- equipment_statu_label.setHorizontalAlignment(SwingConstants.CENTER);
- equipment_statu_label.setForeground(Color.BLACK);
- equipment_statu_label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
- equipment_statu_label.setBackground(Color.LIGHT_GRAY);
- toolBar.add(equipment_statu_label);
- status_menu = new JButton("设备未连接MES服务器");
- if(tcp_connect_flag) {
- MesClient.setMenuStatus("已连接MES服务器",0);
- status_menu.setForeground(Color.GREEN);
- }else {
- MesClient.setMenuStatus("未连接MES服务器",-1);
- 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("微软雅黑", 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("心跳:");
- heart_beat_status_label.setHorizontalAlignment(SwingConstants.CENTER);
- heart_beat_status_label.setForeground(Color.BLACK);
- heart_beat_status_label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
- heart_beat_status_label.setBackground(Color.LIGHT_GRAY);
- toolBar.add(heart_beat_status_label);
- heart_beat_menu = new JButton("");
- 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("微软雅黑", 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("登录用户:");
- user_status_label.setHorizontalAlignment(SwingConstants.CENTER);
- user_status_label.setForeground(Color.BLACK);
- user_status_label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
- user_status_label.setBackground(Color.LIGHT_GRAY);
- toolBar.add(user_status_label);
- user_menu = new JButton("");
- user_menu.setForeground(Color.GREEN);
- user_menu.setFont(new Font("微软雅黑", 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("宋体", Font.BOLD, 22));
- contentPane.add(tabbedPane);
- //首页
- JPanel indexPanelA = new JPanel();
- indexScrollPaneA = new JScrollPane(indexPanelA);
- indexPanelA.setLayout(null);
- product_sn = new JTextField();
- product_sn.setHorizontalAlignment(SwingConstants.CENTER);
- product_sn.setEditable(false);
- product_sn.setFont(new Font("微软雅黑", Font.PLAIN, 28));
- product_sn.setBounds(81, 70, 602, 70);
- indexPanelA.add(product_sn);
- product_sn.setColumns(10);
- f_scan_data_bt_1 = new JButton("扫码");
- f_scan_data_bt_1.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- scan_type = 1;
- scanBarcode();
- }
- });
- f_scan_data_bt_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/scan_barcode.png")));
- f_scan_data_bt_1.setFont(new Font("微软雅黑", Font.PLAIN, 32));
- f_scan_data_bt_1.setBounds(693, 70, 198, 70);
- indexPanelA.add(f_scan_data_bt_1);
- finish_ok_bt = new JButton("OK");
- finish_ok_bt.setEnabled(false);
- finish_ok_bt.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- if(work_status == 1 && check_quality_result){
- String sn = getBarcode(product_sn.getText());
- getUser();
- String qret = "OK";
- Boolean result = DataUtil.sendQuality(sn,qret,user20);
- if(result) {
- MesClient.resetScanA();
- MesClient.setMenuStatus("结果提交成功,请扫下一件", 0);
- MesClient.scan_type = 1;
- MesClient.scanBarcode();
- } else {
- MesClient.setMenuStatus("结果提交失败,请重试",-1);
- }
- }
- }
- });
- finish_ok_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
- finish_ok_bt.setFont(new Font("微软雅黑", Font.PLAIN, 32));
- finish_ok_bt.setBounds(185, 291, 240, 80);
- finish_ok_bt.setEnabled(false);
- indexPanelA.add(finish_ok_bt);
- finish_ng_bt = new JButton("NG");
- finish_ng_bt.setEnabled(false);
- finish_ng_bt.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- if(work_status == 1 && check_quality_result){
- String sn = getBarcode(product_sn.getText());
- getUser();
- String qret = "NG";
- Boolean result = DataUtil.sendQuality(sn,qret,user20);
- if(result) {
- MesClient.resetScanA();
- MesClient.setMenuStatus("结果提交成功,请扫下一件", 0);
- MesClient.scan_type = 1;
- MesClient.scanBarcode();
- } else {
- MesClient.setMenuStatus("结果提交失败,请重试",-1);
- }
- }
- }
- });
- finish_ng_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ng_bg.png")));
- finish_ng_bt.setFont(new Font("微软雅黑", Font.PLAIN, 32));
- finish_ng_bt.setBounds(508, 291, 240, 80);
- finish_ng_bt.setEnabled(false);
- indexPanelA.add(finish_ng_bt);
- tabbedPane.addTab("工作面板", new ImageIcon(MesClient.class.getResource("/bg/a_side.png")), indexScrollPaneA, null);
- tabbedPane.setEnabledAt(0, true);
- 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);
- indexPanelJs = new JPanel();
- searchScrollPaneJs = new JScrollPane(indexPanelJs);
- indexPanelJs.setLayout(null);
- // tabbedPane.addTab("胶水寿命", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPaneJs, null);
- indexPanelD = new JPanel();
- searchScrollPaneD = new JScrollPane(indexPanelD);
- indexPanelD.setLayout(null);
- // tabbedPane.addTab("工具寿命", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPaneD, null);
- tabbedPane.addChangeListener(new ChangeListener() {
- @Override
- public void stateChanged(ChangeEvent e) {
- JTabbedPane tabbedPane = (JTabbedPane) e.getSource();
- int selectedIndex = tabbedPane.getSelectedIndex();
- if(selectedIndex == 1){
- }
- }
- });
- }
- 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")) {
- java.util.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);
- JScrollPane indexScrollPaneB = new JScrollPane(indexPanelBB);
- indexPanelBB.setLayout(null);
- tabbedPane.addTab("绑定物料", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), indexScrollPaneB, null);
- }
- // 开启发送结果定时任务
- public static void startUpdateQualityTimer(){
- new Timer().schedule(new TimerTask() {
- @Override
- public void run() {
- try {
- Statement statement = JdbcUtils.conn.createStatement();
- String selectSql = "SELECT id, bw,fail_count FROM submit_record\n" +
- "WHERE state = 0 AND fail_status = 0";
- 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 failCount = rs.getString("fail_count");
- log.info("submit_record表取数据: id: " + id + " bw:" + bw);
- // 发送请求
- String url = "http://"+MesClient.mes_server_ip+":8980/js/a/mes/mesProductRecord/updateQualityByTiming";
- String s = HttpUtils.sendPostRequestJson(url, bw );
- Boolean result = JSONObject.parseObject(s).getBoolean("result");
- if(result) {
- // 更改状态为 1
- statement.executeUpdate(updateSql + id);
- } else {
- log.error("定时任务提交失败, 报文: " + bw);
- int newFailCount = Integer.parseInt(failCount);
- String updateFailSql;
- //当提交次数超过10次,则将状态置为失败,不再进行提交
- if (newFailCount >= 9) {
- updateFailSql = "UPDATE submit_record SET fail_count = fail_count + 1, fail_status = 1 WHERE id = " + id;
- } else {
- updateFailSql = "UPDATE submit_record SET fail_count = fail_count + 1 WHERE id = " + id;
- }
- statement.executeUpdate(updateFailSql);
- }
- }
- rs.close();
- statement.close();
- } catch (SQLException | IOException e) {
- // throw new RuntimeException(e);
- log.info(e.getMessage());
- }
- }
- },1000, 5000);
- }
- }
|