|  |  | 
 |  |  | import com.zy.common.service.CommonService; | 
 |  |  | import com.zy.common.utils.CollectionUtils; | 
 |  |  | import com.zy.common.utils.HttpHandler; | 
 |  |  | import com.zy.common.utils.News; | 
 |  |  | import com.zy.core.CrnThread; | 
 |  |  | import com.zy.core.DevpThread; | 
 |  |  | import com.zy.core.cache.MessageQueue; | 
 |  |  | 
 |  |  |  | 
 |  |  |                     String barcode = barcodeThread.getBarcode(); | 
 |  |  |                     if(!Cools.isEmpty(barcode)) { | 
 |  |  |                         log.info("{}号条码扫描器检测条码信息:{}", inSta.getBarcode(), barcode); | 
 |  |  |                         News.info("{}号条码扫描器检测条码信息:{}", inSta.getBarcode(), barcode); | 
 |  |  |                         if("NG".endsWith(barcode) || "NoRead".equals(barcode) || "empty".equals(barcode)) { | 
 |  |  |                             staProtocol.setWorkNo((short) 9999); | 
 |  |  |                             staProtocol.setStaNo(inSta.getBackSta().shortValue()); | 
 |  |  |                             devpThread.setPakMk(staProtocol.getSiteId(), false); | 
 |  |  |                             MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); | 
 |  |  |  | 
 |  |  |                             log.info("扫码失败1 ===>> {}号条码扫描器检测条码信息:{},站点:{}", inSta.getBarcode(), barcode, inSta.getStaNo()); | 
 |  |  |                             News.info("扫码失败1 ===>> {}号条码扫描器检测条码信息:{},站点:{}", inSta.getBarcode(), barcode, inSta.getStaNo()); | 
 |  |  |                             // led 异常显示 | 
 |  |  |                             if (ledThread != null) { | 
 |  |  |                                 String errorMsg = "扫码失败,请重试"; | 
 |  |  | 
 |  |  |                         devpThread.setPakMk(staProtocol.getSiteId(), false); | 
 |  |  |                         MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); | 
 |  |  |  | 
 |  |  |                         log.info("扫码失败2 ===>> {}号条码扫描器检测条码信息:{},站点:{}", inSta.getBarcode(), barcode, inSta.getStaNo()); | 
 |  |  |                         News.info("扫码失败2 ===>> {}号条码扫描器检测条码信息:{},站点:{}", inSta.getBarcode(), barcode, inSta.getStaNo()); | 
 |  |  |                         // led 异常显示 | 
 |  |  |                         if (ledThread != null) { | 
 |  |  |                             String errorMsg = "扫码失败,请重试"; | 
 |  |  | 
 |  |  |                 } | 
 |  |  |                 String barcode = barcodeThread.getBarcode(); | 
 |  |  |                 if(!Cools.isEmpty(barcode)) { | 
 |  |  |                     log.info("{}号条码扫描器检测条码信息:{}", pickSta.getBarcode(), barcode); | 
 |  |  |                     News.info("{}号条码扫描器检测条码信息:{}", pickSta.getBarcode(), barcode); | 
 |  |  |                     if("NG".endsWith(barcode) || "NoRead".equals(barcode)) { | 
 |  |  |                         continue; | 
 |  |  |                     } | 
 |  |  | 
 |  |  |             if (wrkMastMapper.selectDevWorking(crnProtocol.getCrnNo()) == null) { | 
 |  |  |                 return; | 
 |  |  |             } | 
 |  |  |             log.info("堆垛机召回原点==>>" + crnProtocol.getCrnNo() + "号堆垛机有入库任务,召回原点"); | 
 |  |  |             News.info("堆垛机召回原点==>>" + crnProtocol.getCrnNo() + "号堆垛机有入库任务,召回原点"); | 
 |  |  |             // 命令下发区 -------------------------------------------------------------------------- | 
 |  |  |             CrnCommand crnCommand = new CrnCommand(); | 
 |  |  |             crnCommand.setCrnNo(crnProtocol.getCrnNo()); // 堆垛机编号 | 
 |  |  | 
 |  |  |                 JSONObject jsonObject = JSON.parseObject(response); | 
 |  |  |                 if (jsonObject.getInteger("code").equals(200)) { | 
 |  |  |                     JSONObject data = (JSONObject) jsonObject.get("data"); | 
 |  |  |                     log.info((String) data.get("msg")); | 
 |  |  |                     News.info((String) data.get("msg")); | 
 |  |  |                 } else { | 
 |  |  |                     log.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/auto/emptyOut/v1","", response); | 
 |  |  |                 } | 
 |  |  | 
 |  |  |                         .doPost(); | 
 |  |  |                 JSONObject jsonObject = JSON.parseObject(response); | 
 |  |  |                 if (jsonObject.getInteger("code").equals(200)) { | 
 |  |  |                     log.info((String) jsonObject.get("msg")); | 
 |  |  |                     News.info((String) jsonObject.get("msg")); | 
 |  |  |                 } else { | 
 |  |  |                     log.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/auto/emptyIn/v1", JSON.toJSONString(locTypeDto), response); | 
 |  |  |                 } | 
 
 |  |  | 
 |  |  | package com.zy.core; | 
 |  |  |  | 
 |  |  | import com.zy.common.utils.News; | 
 |  |  | import com.zy.core.cache.MessageQueue; | 
 |  |  | import com.zy.core.cache.SlaveConnection; | 
 |  |  | import com.zy.core.enums.SlaveType; | 
 |  |  | 
 |  |  |     @PostConstruct | 
 |  |  |     @Async | 
 |  |  |     public void init() throws InterruptedException { | 
 |  |  |         log.info("核心控制层开始初始化..............................................."); | 
 |  |  |         News.info("核心控制层开始初始化..............................................."); | 
 |  |  |         Thread.sleep(2000); | 
 |  |  |         // 初始化消息队列 | 
 |  |  |         initMq(); | 
 |  |  | 
 |  |  |         initThread(); | 
 |  |  |         // 开始主流程进程 | 
 |  |  |         mainProcess.start(); | 
 |  |  |         log.info("核心控制层已启动..............................................."); | 
 |  |  |         News.info("核心控制层已启动..............................................."); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private void initMq(){ | 
 |  |  | 
 |  |  |             SlaveConnection.put(SlaveType.Crn, crn.getId(), crnThread); | 
 |  |  |         } | 
 |  |  |         // 初始化输送线线程 | 
 |  |  |         log.info("初始化输送线线程..................................................."); | 
 |  |  |         News.info("初始化输送线线程..................................................."); | 
 |  |  |         for (DevpSlave devp : slaveProperties.getDevp()) { | 
 |  |  |             DevpThread devpThread = new SiemensDevpThread(devp); | 
 |  |  |             new Thread((Runnable) devpThread).start(); | 
 |  |  |             SlaveConnection.put(SlaveType.Devp, devp.getId(), devpThread); | 
 |  |  |         } | 
 |  |  |         // 初始化条码扫描仪线程 | 
 |  |  |         log.info("初始化条码扫描仪线程..................................................."); | 
 |  |  |         News.info("初始化条码扫描仪线程..................................................."); | 
 |  |  |         for (Slave barcode : slaveProperties.getBarcode()) { | 
 |  |  |             BarcodeThread barcodeThread = new BarcodeThread(barcode); | 
 |  |  | //            new Thread(barcodeThread).start(); | 
 |  |  |             SlaveConnection.put(SlaveType.Barcode, barcode.getId(), barcodeThread); | 
 |  |  |         } | 
 |  |  |         // 初始化LED线程 | 
 |  |  |         log.info("初始化LED线程..................................................."); | 
 |  |  |         News.info("初始化LED线程..................................................."); | 
 |  |  |         for (LedSlave led : slaveProperties.getLed()) { | 
 |  |  |             LedThread ledThread = new LedThread(led); | 
 |  |  |             new Thread(ledThread).start(); | 
 |  |  |             SlaveConnection.put(SlaveType.Led, led.getId(), ledThread); | 
 |  |  |         } | 
 |  |  |         // 初始化磅秤线程 | 
 |  |  | //        log.info("初始化磅秤线程..................................................."); | 
 |  |  | //        News.info("初始化磅秤线程..................................................."); | 
 |  |  | //        for (Slave scale : slaveProperties.getScale()) { | 
 |  |  | //            ScaleThread barcodeThread = new ScaleThread(scale); | 
 |  |  | //            new Thread(barcodeThread).start(); | 
 
 |  |  | 
 |  |  | package com.zy.core.netty; | 
 |  |  |  | 
 |  |  |  | 
 |  |  | import com.zy.common.utils.News; | 
 |  |  | import com.zy.core.netty.properties.TcpProperties; | 
 |  |  | import io.netty.bootstrap.ServerBootstrap; | 
 |  |  | import io.netty.buffer.PooledByteBufAllocator; | 
 |  |  | 
 |  |  |  | 
 |  |  |         ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.ADVANCED); | 
 |  |  |  | 
 |  |  |         log.info("TCP server started successfully, port:{}", tcpProperties.getPort()); | 
 |  |  |         News.info("TCP server started successfully, port:{}", tcpProperties.getPort()); | 
 |  |  |  | 
 |  |  |         channel = bootstrap.bind(tcpProperties.getPort()).sync().channel(); | 
 |  |  |     } | 
 |  |  | 
 |  |  |         if (workerGroup != null) { | 
 |  |  |             workerGroup.shutdownGracefully(); | 
 |  |  |         } | 
 |  |  |         log.info("TCP server stopped successfully, port: {}", tcpProperties.getPort()); | 
 |  |  |         News.info("TCP server stopped successfully, port: {}", tcpProperties.getPort()); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | } | 
 
 |  |  | 
 |  |  | package com.zy.core.netty.handle; | 
 |  |  |  | 
 |  |  | import com.core.common.Cools; | 
 |  |  | import com.zy.common.utils.News; | 
 |  |  | import com.zy.core.netty.AbstractInboundHandler; | 
 |  |  | import com.zy.core.netty.cache.ChannelCache; | 
 |  |  | import com.zy.core.netty.domain.ChPackage; | 
 |  |  | 
 |  |  |                 String uuid = ChannelCache.removeChannel(ctx.channel()); | 
 |  |  |                 ctx.close(); | 
 |  |  |                 if (!Cools.isEmpty(uuid)){ | 
 |  |  |                     log.info("uuid={} 空闲剔除", uuid); | 
 |  |  |                     News.info("uuid={} 空闲剔除", uuid); | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  | 
 |  |  |         String uuid = ChannelCache.removeChannel(ctx.channel()); | 
 |  |  |         ctx.close(); | 
 |  |  |         if (!Cools.isEmpty(uuid)){ | 
 |  |  |             log.info("通道 uuid={} 失去连接", uuid); | 
 |  |  |             News.info("通道 uuid={} 失去连接", uuid); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 
 |  |  | 
 |  |  | import com.core.common.Cools; | 
 |  |  | import com.zy.common.entity.Parameter; | 
 |  |  | import com.zy.common.model.MatDto; | 
 |  |  | import com.zy.common.utils.News; | 
 |  |  | import com.zy.core.Slave; | 
 |  |  | import com.zy.core.ThreadHandler; | 
 |  |  | import com.zy.core.cache.MessageQueue; | 
 |  |  | 
 |  |  | //            screen = new Bx5GScreenClient("my"); | 
 |  |  |         } catch (Exception e) { | 
 |  |  |             e.printStackTrace(); | 
 |  |  |             log.info("led连接构造器错误 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); | 
 |  |  |             News.info("led连接构造器错误 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | 
 |  |  |         area.addPage(page); | 
 |  |  |         pf.addArea(area); | 
 |  |  |         if (pf.validate() != null) { | 
 |  |  |             log.info("pf out of range"); | 
 |  |  |             News.info("pf out of range"); | 
 |  |  |         } else { | 
 |  |  |             // 更新节目 | 
 |  |  |             screen.writeProgram(pf); | 
 |  |  | 
 |  |  |         pf.addArea(area); | 
 |  |  |         // 更新节目 | 
 |  |  |         if (pf.validate() != null) { | 
 |  |  |             log.info("pf out of range"); | 
 |  |  |             News.info("pf out of range"); | 
 |  |  |         } else { | 
 |  |  |             // 更新节目 | 
 |  |  |             screen.writeProgram(pf); | 
 |  |  | 
 |  |  |         } catch (Exception ignore) { | 
 |  |  |         } | 
 |  |  |         if (connRes) { | 
 |  |  |             log.info("led连接成功 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); | 
 |  |  |             News.info("led连接成功 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); | 
 |  |  |         } else { | 
 |  |  |             log.error("led连接失败!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); | 
 |  |  |         } | 
 |  |  | 
 |  |  |             // 更新节目 | 
 |  |  |             if (pf.validate() != null) { | 
 |  |  |                 System.out.println("pf out of range"); | 
 |  |  |                 log.info("pf out of range"); | 
 |  |  |                 News.info("pf out of range"); | 
 |  |  |             } else { | 
 |  |  |                 // 更新节目 | 
 |  |  |                 screen.writeProgram(pf); | 
 
 |  |  | 
 |  |  | import com.zy.asrs.entity.BasCrnp; | 
 |  |  | import com.zy.asrs.service.BasCrnOptService; | 
 |  |  | import com.zy.asrs.service.BasCrnpService; | 
 |  |  | import com.zy.common.utils.News; | 
 |  |  | import com.zy.core.CrnThread; | 
 |  |  | import com.zy.core.ThreadHandler; | 
 |  |  | import com.zy.core.cache.MessageQueue; | 
 |  |  | 
 |  |  |         if(connect.IsSuccess){ | 
 |  |  |             result = true; | 
 |  |  |             OutputQueue.CRN.offer(MessageFormat.format( "【{0}】堆垛机plc连接成功 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); | 
 |  |  |             log.info("堆垛机plc连接成功 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); | 
 |  |  |             News.info("堆垛机plc连接成功 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); | 
 |  |  |         } else { | 
 |  |  |             OutputQueue.CRN.offer(MessageFormat.format("【{0}】堆垛机plc连接失败!!! ===>> [id:{1}] [ip:{2}] [port:{3}] ", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); | 
 |  |  |             log.error("堆垛机plc连接失败!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); | 
 |  |  |             News.error("堆垛机plc连接失败!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); | 
 |  |  |             initCrn(); | 
 |  |  |         } | 
 |  |  | //        melsecMcNet.ConnectClose(); | 
 |  |  | 
 |  |  |         } catch (Exception ignore) {} | 
 |  |  |  | 
 |  |  |         if (result != null && result.IsSuccess) { | 
 |  |  |             log.info("堆垛机命令下发[id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command)); | 
 |  |  |             News.info("堆垛机命令下发[id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command)); | 
 |  |  |             OutputQueue.CRN.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command))); | 
 |  |  |             return true; | 
 |  |  |         } else { | 
 |  |  | 
 |  |  | //        OperateResult write9 = melsecMcNet.Write("D1009", (short) 0); | 
 |  |  | //        OperateResult write10 = melsecMcNet.Write("D1010", (short) 0); | 
 |  |  |         if (!write.IsSuccess) { | 
 |  |  |             log.error("堆垛机plc心跳通讯失败 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); | 
 |  |  |             News.error("堆垛机plc心跳通讯失败 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 
 |  |  | 
 |  |  | import com.zy.asrs.entity.BasCrnp; | 
 |  |  | import com.zy.asrs.service.BasCrnOptService; | 
 |  |  | import com.zy.asrs.service.BasCrnpService; | 
 |  |  | import com.zy.common.utils.News; | 
 |  |  | import com.zy.core.CrnThread; | 
 |  |  | import com.zy.core.cache.MessageQueue; | 
 |  |  | import com.zy.core.cache.OutputQueue; | 
 |  |  | 
 |  |  |         if(connect.IsSuccess){ | 
 |  |  |             result = true; | 
 |  |  |             OutputQueue.CRN.offer(MessageFormat.format( "【{0}】堆垛机plc连接成功 ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot())); | 
 |  |  |             log.info("堆垛机plc连接成功 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()); | 
 |  |  |             News.info("堆垛机plc连接成功 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()); | 
 |  |  |         } else { | 
 |  |  |             OutputQueue.CRN.offer(MessageFormat.format("【{0}】堆垛机plc连接失败!!! ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot())); | 
 |  |  |             log.error("堆垛机plc连接失败!!! ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()); | 
 |  |  |             News.error("堆垛机plc连接失败!!! ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()); | 
 |  |  |             initCrn(); | 
 |  |  |         } | 
 |  |  | //        siemensNet.ConnectClose(); | 
 |  |  | 
 |  |  |         if (result != null && result.IsSuccess) { | 
 |  |  |             Thread.sleep(200); | 
 |  |  |             this.readStatus(); | 
 |  |  |             log.info("堆垛机命令下发[id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command)); | 
 |  |  |             News.info("堆垛机命令下发[id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command)); | 
 |  |  |             OutputQueue.CRN.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command))); | 
 |  |  |             return true; | 
 |  |  |         } else { | 
 
 |  |  | 
 |  |  | import com.core.exception.CoolException; | 
 |  |  | import com.zy.asrs.entity.BasDevp; | 
 |  |  | import com.zy.asrs.service.BasDevpService; | 
 |  |  | import com.zy.common.utils.News; | 
 |  |  | import com.zy.core.DevpThread; | 
 |  |  | import com.zy.core.cache.MessageQueue; | 
 |  |  | import com.zy.core.cache.OutputQueue; | 
 |  |  | 
 |  |  |         if(connect.IsSuccess){ | 
 |  |  |             result = true; | 
 |  |  |             OutputQueue.DEVP.offer(MessageFormat.format( "【{0}】输送线plc连接成功 ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot())); | 
 |  |  |             log.info("输送线plc连接成功 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); | 
 |  |  |             News.info("输送线plc连接成功 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); | 
 |  |  |         } else { | 
 |  |  |             OutputQueue.DEVP.offer(MessageFormat.format( "【{0}】输送线plc连接失败!!! ===>> [id:{1}] [ip:{2}] [port:{3}]  [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot())); | 
 |  |  |             log.error("输送线plc连接失败!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); | 
 |  |  | 
 |  |  | //                    if(barcodeThread!=null){ | 
 |  |  | //                        //lfd入库印记  当stamp>=2时才入库 | 
 |  |  | //                        staProtocol.setStamp(staProtocol.getStamp()+1); | 
 |  |  | //                        log.info("{}站有可入信号时,条码值为{}", siteId, barcodeThread.getBarcode()); | 
 |  |  | //                        News.info("{}站有可入信号时,条码值为{}", siteId, barcodeThread.getBarcode()); | 
 |  |  | //                        if(Cools.isEmpty(barcodeThread.getBarcode())){ | 
 |  |  | //                            staProtocol.setInEnable(false);//条码数据为空时,先清一次内存的站点可入信号,等待下一次获取可入信号 | 
 |  |  | //                        } | 
 |  |  | 
 |  |  |             log.error("写入输送线站点数据失败。输送线plc编号={},站点数据={}", slave.getId(), JSON.toJSON(staProtocol)); | 
 |  |  |         } else { | 
 |  |  |             OutputQueue.DEVP.offer(MessageFormat.format("【{0}】 输送线命令下发 [id:{1}] >>>>> {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(staProtocol))); | 
 |  |  |             log.info("输送线命令下发 [id:{}] >>>>> 命令下发: {}",  slave.getId(), JSON.toJSON(staProtocol)); | 
 |  |  |             News.info("输送线命令下发 [id:{}] >>>>> 命令下发: {}",  slave.getId(), JSON.toJSON(staProtocol)); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  |