| | |
| | | */ |
| | | @Slf4j |
| | | @Service("mainService") |
| | | @Transactional |
| | | public class MainServiceImpl { |
| | | |
| | | @Value("${wms.url}") |
| | |
| | | private NavigateMapUtils navigateMapUtils; |
| | | @Autowired |
| | | private WrkDetlLogService wrkDetlLogService; |
| | | @Autowired |
| | | private MatService matService; |
| | | |
| | | |
| | | /** |
| | |
| | | * 入库站,根据条码扫描生成入库工作档,工作状态 2 |
| | | */ |
| | | public void generateStoreWrkFile() { |
| | | // 根据输送线plc遍历 |
| | | for (DevpSlave devp : slaveProperties.getDevp()) { |
| | | // 遍历入库口 |
| | | for (DevpSlave.Sta inSta : devp.getInSta()) { |
| | | // 获取入库站信息 |
| | | DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId()); |
| | | StaProtocol staProtocol = devpThread.getStation().get(inSta.getStaNo()); |
| | | if (staProtocol == null) { |
| | | continue; |
| | | } else { |
| | | staProtocol = staProtocol.clone(); |
| | | } |
| | | Short workNo = staProtocol.getWorkNo(); |
| | | // 尺寸检测异常 |
| | | boolean back = false; |
| | | String errMsg = "异常:"; |
| | | if (staProtocol.isFrontErr()) { |
| | | errMsg = errMsg+"前超限;"; |
| | | back = true; |
| | | } |
| | | if (staProtocol.isBackErr()) { |
| | | errMsg = errMsg+"后超限"; |
| | | back = true; |
| | | } |
| | | if (staProtocol.isHighErr()) { |
| | | errMsg = errMsg+"高超限"; |
| | | back = true; |
| | | } |
| | | if (staProtocol.isLeftErr()) { |
| | | errMsg = errMsg+"左超限"; |
| | | back = true; |
| | | } |
| | | if (staProtocol.isRightErr()) { |
| | | errMsg = errMsg+"右超限"; |
| | | back = true; |
| | | } |
| | | if (staProtocol.isWeightErr()) { |
| | | errMsg = errMsg+"超重"; |
| | | back = true; |
| | | } |
| | | if (staProtocol.isBarcodeErr()) { |
| | | errMsg = errMsg+"扫码失败"; |
| | | back = true; |
| | | } |
| | | // 退回 |
| | | if (back) { |
| | | // led 异常显示 |
| | | LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed()); |
| | | if (ledThread != null) { |
| | | MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errMsg)); |
| | | try { |
| | | // 根据输送线plc遍历 |
| | | for (DevpSlave devp : slaveProperties.getDevp()) { |
| | | // 遍历入库口 |
| | | for (DevpSlave.Sta inSta : devp.getInSta()) { |
| | | // 获取入库站信息 |
| | | DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId()); |
| | | StaProtocol staProtocol = devpThread.getStation().get(inSta.getStaNo()); |
| | | if (staProtocol == null) { |
| | | continue; |
| | | } else { |
| | | staProtocol = staProtocol.clone(); |
| | | } |
| | | continue; |
| | | } |
| | | |
| | | // 判断是否满足入库条件 |
| | | if (staProtocol.isAutoing() && staProtocol.isLoading() |
| | | && staProtocol.isInEnable() |
| | | && !staProtocol.isEmptyMk() && (workNo == 0 || (workNo >= 9990 && workNo <= 9999)) |
| | | ) { |
| | | |
| | | // 获取条码扫描仪信息 |
| | | BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, inSta.getBarcode()); |
| | | if (barcodeThread == null) { |
| | | Short workNo = staProtocol.getWorkNo(); |
| | | // 尺寸检测异常 |
| | | boolean back = false; |
| | | String errMsg = "异常:"; |
| | | if (staProtocol.isFrontErr()) { |
| | | errMsg = errMsg + "前超限;"; |
| | | back = true; |
| | | } |
| | | if (staProtocol.isBackErr()) { |
| | | errMsg = errMsg + "后超限"; |
| | | back = true; |
| | | } |
| | | if (staProtocol.isHighErr()) { |
| | | errMsg = errMsg + "高超限"; |
| | | back = true; |
| | | } |
| | | if (staProtocol.isLeftErr()) { |
| | | errMsg = errMsg + "左超限"; |
| | | back = true; |
| | | } |
| | | if (staProtocol.isRightErr()) { |
| | | errMsg = errMsg + "右超限"; |
| | | back = true; |
| | | } |
| | | if (staProtocol.isWeightErr()) { |
| | | errMsg = errMsg + "超重"; |
| | | back = true; |
| | | } |
| | | if (staProtocol.isBarcodeErr()) { |
| | | errMsg = errMsg + "扫码失败"; |
| | | back = true; |
| | | } |
| | | // 退回 |
| | | if (back) { |
| | | // led 异常显示 |
| | | LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed()); |
| | | if (ledThread != null) { |
| | | MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errMsg)); |
| | | } |
| | | continue; |
| | | } |
| | | String barcode = barcodeThread.getBarcode(); |
| | | if(!Cools.isEmpty(barcode)) { |
| | | |
| | | // 判断是否满足入库条件 |
| | | if (staProtocol.isAutoing() && staProtocol.isLoading() |
| | | && staProtocol.isInEnable() |
| | | && !staProtocol.isEmptyMk() && (workNo == 0 || (workNo >= 9990 && workNo <= 9999)) |
| | | ) { |
| | | |
| | | // 获取条码扫描仪信息 |
| | | BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, inSta.getBarcode()); |
| | | if (barcodeThread == null) { |
| | | continue; |
| | | } |
| | | String barcode = barcodeThread.getBarcode(); |
| | | if (!Cools.isEmpty(barcode)) { |
| | | // News.info("{}号条码扫描器检测条码信息:{}", inSta.getBarcode(), barcode); |
| | | if("NG".endsWith(barcode) || "NoRead".equals(barcode) || "empty".equals(barcode)|| "00000000".equals(barcode)) { |
| | | if ("NG".endsWith(barcode) || "NoRead".equals(barcode) || "empty".equals(barcode) || "00000000".equals(barcode)) { |
| | | // staProtocol.setWorkNo((short) 32002); |
| | | // staProtocol.setStaNo(inSta.getBackSta().shortValue()); |
| | | // devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | // MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | |
| | | // led 异常显示 |
| | | LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed()); |
| | | if (ledThread != null) { |
| | | String errorMsg = "扫码失败,请重试"; |
| | | MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg)); |
| | | // led 异常显示 |
| | | LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed()); |
| | | if (ledThread != null) { |
| | | String errorMsg = "扫码失败,请重试"; |
| | | MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg)); |
| | | } |
| | | continue; |
| | | } |
| | | continue; |
| | | } |
| | | } else { |
| | | } else { |
| | | // staProtocol.setWorkNo((short) 32002); |
| | | // staProtocol.setStaNo(inSta.getBackSta().shortValue()); |
| | | // devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | |
| | | // String errorMsg = "扫码失败,请重试"; |
| | | // MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg)); |
| | | // } |
| | | continue; |
| | | } |
| | | continue; |
| | | } |
| | | |
| | | // 过滤盘点/拣料/并板任务 |
| | | WrkMast wrkMast1 = wrkMastMapper.selectPickStepByBarcode(barcode); |
| | | if (null != wrkMast1) { |
| | | continue; |
| | | } |
| | | // 过滤盘点/拣料/并板任务 |
| | | WrkMast wrkMast1 = wrkMastMapper.selectPickStepByBarcode(barcode); |
| | | if (null != wrkMast1) { |
| | | continue; |
| | | } |
| | | |
| | | // 判断重复工作档 |
| | | WrkMast wrkMast2 = wrkMastMapper.selectPakInStep1(inSta.getStaNo(), barcode); |
| | | if (wrkMast2 != null) { |
| | | News.error("工作档中已存在该站状态为( 2.设备上走 )的数据,工作号={}", wrkMast2.getWrkNo()); |
| | | continue; |
| | | } |
| | | // 判断重复工作档 |
| | | WrkMast wrkMast2 = wrkMastMapper.selectPakInStep1(inSta.getStaNo(), barcode); |
| | | if (wrkMast2 != null) { |
| | | News.error("工作档中已存在该站状态为( 2.设备上走 )的数据,工作号={}", wrkMast2.getWrkNo()); |
| | | continue; |
| | | } |
| | | |
| | | try { |
| | | LocTypeDto locTypeDto = new LocTypeDto(staProtocol); |
| | | SearchLocParam param = new SearchLocParam(); |
| | | param.setBarcode(barcode); |
| | | param.setIoType(1); |
| | | param.setSourceStaNo(inSta.getStaNo()); |
| | | param.setLocType1(locTypeDto.getLocType1()); |
| | | String response = new HttpHandler.Builder() |
| | | .setUri(wmsUrl) |
| | | .setPath("/rpc/pakin/loc/v2") |
| | | .setJson(JSON.toJSONString(param)) |
| | | .build() |
| | | .doPost(); |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed()); |
| | | Integer code = jsonObject.getInteger("code"); |
| | | if (code.equals(200)) { |
| | | StartupDto dto = jsonObject.getObject("data", StartupDto.class); |
| | | // plc 处理 |
| | | barcodeThread.setBarcode(""); |
| | | try { |
| | | LocTypeDto locTypeDto = new LocTypeDto(staProtocol); |
| | | SearchLocParam param = new SearchLocParam(); |
| | | param.setBarcode(barcode); |
| | | param.setIoType(1); |
| | | param.setSourceStaNo(inSta.getStaNo()); |
| | | param.setLocType1(locTypeDto.getLocType1()); |
| | | String response = new HttpHandler.Builder() |
| | | .setUri(wmsUrl) |
| | | .setPath("/rpc/pakin/loc/v2") |
| | | .setJson(JSON.toJSONString(param)) |
| | | .build() |
| | | .doPost(); |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed()); |
| | | Integer code = jsonObject.getInteger("code"); |
| | | if (code.equals(200)) { |
| | | StartupDto dto = jsonObject.getObject("data", StartupDto.class); |
| | | // plc 处理 |
| | | barcodeThread.setBarcode(""); |
| | | // staProtocol.setWorkNo(dto.getWorkNo().shortValue()); |
| | | // staProtocol.setStaNo(dto.getStaNo().shortValue()); |
| | | // devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | |
| | | // throw new CoolException("更新plc站点信息失败"); |
| | | // } |
| | | |
| | | // 判断重复工作档 |
| | | WrkMast wrkMast = wrkMastMapper.selectPakInStep11(inSta.getStaNo()); |
| | | if (wrkMast == null) { continue; } |
| | | |
| | | // 更新工作主档 |
| | | wrkMast.setWrkSts(2L); // 工作状态:2.设备上走 |
| | | wrkMast.setModiTime(new Date()); |
| | | if (wrkMastMapper.updateById(wrkMast) == 0) { |
| | | News.error("更新工作档失败!!! [工作号:{}]", wrkMast.getWrkNo()); |
| | | } |
| | | |
| | | } else if (code == 500){ |
| | | if (ledThread != null) { |
| | | String errorMsg = jsonObject.getString("msg"); |
| | | if (!Cools.isEmpty(errorMsg)) { |
| | | MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg)); |
| | | ledThread.setLedMk(false); |
| | | // 判断重复工作档 |
| | | WrkMast wrkMast = wrkMastMapper.selectPakInStep11(inSta.getStaNo()); |
| | | if (wrkMast == null) { |
| | | continue; |
| | | } |
| | | } |
| | | News.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v2", JSON.toJSONString(param), response); |
| | | } else if (code == 700) { |
| | | |
| | | // 更新工作主档 |
| | | wrkMast.setWrkSts(2L); // 工作状态:2.设备上走 |
| | | wrkMast.setModiTime(new Date()); |
| | | if (wrkMastMapper.updateById(wrkMast) == 0) { |
| | | News.error("更新工作档失败!!! [工作号:{}]", wrkMast.getWrkNo()); |
| | | } |
| | | |
| | | } else if (code == 500) { |
| | | if (ledThread != null) { |
| | | String errorMsg = jsonObject.getString("msg"); |
| | | if (!Cools.isEmpty(errorMsg)) { |
| | | MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg)); |
| | | ledThread.setLedMk(false); |
| | | } |
| | | } |
| | | News.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v2", JSON.toJSONString(param), response); |
| | | } else if (code == 700) { |
| | | // staProtocol.setWorkNo((short) 32002); |
| | | // staProtocol.setRollback102(1);//102站回退信号 |
| | | // devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | // MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(5, staProtocol)); |
| | | |
| | | // led 异常显示 |
| | | if (ledThread != null) { |
| | | String errorMsg = barcode + "托盘识别异常,请先进行组托!"; |
| | | MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg)); |
| | | ledThread.setLedMk(false); |
| | | // led 异常显示 |
| | | if (ledThread != null) { |
| | | String errorMsg = barcode + "托盘识别异常,请先进行组托!"; |
| | | MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg)); |
| | | ledThread.setLedMk(false); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | |
| | | /** |
| | | * AGV补货 => 生成入库通知档 |
| | | */ |
| | | public void robotGenerateAgvTask() { |
| | | public synchronized void robotGenerateAgvTask() { |
| | | try { |
| | | //检测300站是否自动、有物、工作号 |
| | | for (DevpSlave devp : slaveProperties.getDevp()) { |
| | |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | // e.printStackTrace(); |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | // e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * AGV补货 => 机械臂拣料 |
| | | */ |
| | | public void agvRestockByRobot() { |
| | | public synchronized void agvRestockByRobot() { |
| | | try { |
| | | //检测300站是否自动、有物、工作号 |
| | | for (DevpSlave devp : slaveProperties.getDevp()) { |
| | |
| | | /** |
| | | * AGV补货(通知AGV取货) |
| | | */ |
| | | public void agvRestockInto() { |
| | | public synchronized void agvRestockInto() { |
| | | try { |
| | | //检测309和312站是否自动、有物 |
| | | for (DevpSlave devp : slaveProperties.getDevp()) { |
| | |
| | | /** |
| | | * AGV补货(悬挂线通知AGV取货) |
| | | */ |
| | | public void agvRestockIntoByHangingWire() { |
| | | public synchronized void agvRestockIntoByHangingWire() { |
| | | try { |
| | | //检测350和351扫码器 |
| | | int[] barcodeStaNo = {11, 12,14,16,18,20};//11 => 350站扫码器,12 => 351站扫码器 |
| | |
| | | /** |
| | | * AGV拣料站点信息 |
| | | */ |
| | | public void agvCurrentContainerCodeInfoWire() { |
| | | public synchronized void agvCurrentContainerCodeInfoWire() { |
| | | try { |
| | | //检测350和351扫码器 |
| | | int[] barcodeStaNo = {13, 15,17,19};//11 => 350站扫码器,12 => 351站扫码器 |
| | |
| | | StaProtocol staProtocol = devpThread.getStation().get(300); |
| | | if (staProtocol == null) { |
| | | continue; |
| | | }else { |
| | | staProtocol = staProtocol.clone(); |
| | | } |
| | | |
| | | if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.getWorkNo() != 0) { |
| | | //查询是否有工作档 |
| | | WrkMast wrkMast = wrkMastMapper.selectByWorkNo(staProtocol.getWorkNo().intValue()); |
| | |
| | | ledCommand.setBarcode(barcode); |
| | | if (ioType != 110 && ioType != 10) { |
| | | List<WrkDetl> wrkDetls = wrkDetlService.selectList(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkNo)); |
| | | wrkDetls.forEach(wrkDetl -> { |
| | | ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getAnfme(), (wrkDetl.getStock() - wrkDetl.getAnfme()), wrkDetl.getSpecs(), wrkDetl.getSuppCode(), wrkDetl.getOrderNo())); |
| | | }); |
| | | if (!wrkDetls.isEmpty()) { |
| | | wrkDetls.forEach(wrkDetl -> { |
| | | double remainNum = wrkDetl.getStock() - wrkDetl.getAnfme();//剩余数量 |
| | | if (remainNum < 0) { |
| | | remainNum = 0; |
| | | } |
| | | String matnr = wrkDetl.getMatnr(); |
| | | Mat mat = matService.selectByMatnr(wrkDetl.getMatnr()); |
| | | if (mat != null) { |
| | | if (!mat.getMatnr().equals(mat.getMatnr2())) { |
| | | matnr += " - " + mat.getMatnr2(); |
| | | } |
| | | } |
| | | ledCommand.getMatDtos().add(new MatDto(matnr, wrkDetl.getMaktx(), wrkDetl.getAnfme(), remainNum, wrkDetl.getSpecs(), wrkDetl.getSuppCode(), wrkDetl.getOrderNo())); |
| | | }); |
| | | }else { |
| | | List<WrkDetlLog> wrkDetlLogs = wrkDetlLogService.selectLatestByWorkNo(wrkNo, barcode); |
| | | for (WrkDetlLog wrkDetlLog : wrkDetlLogs) { |
| | | double remainNum = wrkDetlLog.getStock() - wrkDetlLog.getAnfme();//剩余数量 |
| | | if (remainNum < 0) { |
| | | remainNum = 0; |
| | | } |
| | | String matnr = wrkDetlLog.getMatnr(); |
| | | Mat mat = matService.selectByMatnr(wrkDetlLog.getMatnr()); |
| | | if (mat != null) { |
| | | if (!mat.getMatnr().equals(mat.getMatnr2())) { |
| | | matnr += " - " + mat.getMatnr2(); |
| | | } |
| | | } |
| | | ledCommand.getMatDtos().add(new MatDto(matnr, wrkDetlLog.getMaktx(), wrkDetlLog.getAnfme(), remainNum, wrkDetlLog.getSpecs(), wrkDetlLog.getSuppCode())); |
| | | } |
| | | } |
| | | |
| | | // List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", sourceLocNo)); |
| | | // if (ioType == 101) { |