| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Propagation; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.transaction.interceptor.TransactionAspectSupport; |
| | | |
| | |
| | | @Value("${wms.url}") |
| | | private String wmsUrl; |
| | | |
| | | public Integer wrkNo = 9997; |
| | | @Autowired |
| | | private MainServiceImpl mainService; |
| | | |
| | | public Integer wrkNo = 10000; |
| | | |
| | | /** |
| | | * 组托 |
| | |
| | | back = true; |
| | | } |
| | | // 退回 |
| | | if (back && (staProtocol.getWorkNo() == 9999 || staProtocol.getWorkNo() == 9998) && staProtocol.isInEnable() && staProtocol.isLoading() && staProtocol.isPakMk()) { |
| | | if (back && staProtocol.isInEnable() && staProtocol.isLoading() && staProtocol.isPakMk() && !staProtocol.isEmptyMk() ) { |
| | | MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errMsg)); |
| | | staProtocol.setWorkNo(wrkNo); |
| | | News.info("{}入库回退:{},任务号:{}", inSta.getStaNo(), errMsg,wrkNo); |
| | | News.info("{}入库回退:{},任务号:{}", inSta.getStaNo(), errMsg, staProtocol.getWorkNo()); |
| | | staProtocol.setWorkNo(9999); |
| | | staProtocol.setStaNo(inSta.getBackSta().shortValue()); |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | log.error("输送线下发1:"+wrkNo+","+inSta.getBackSta()); |
| | | log.error("输送线下发1:"+staProtocol.getWorkNo()+","+inSta.getBackSta()); |
| | | return; |
| | | } |
| | | |
| | | // 判断是否满足入库条件 |
| | | if (staProtocol.isAutoing() |
| | | && staProtocol.isLoading() |
| | | && staProtocol.isInEnable() |
| | | && !staProtocol.isEmptyMk() |
| | | && staProtocol.isPakMk() && staProtocol.getWorkNo() == 9999) { |
| | | if (staProtocol.isAutoing() //自动 |
| | | && staProtocol.isLoading() //有物 |
| | | && staProtocol.isInEnable() //可入 |
| | | && !staProtocol.isEmptyMk() // 非空板 |
| | | && staProtocol.isPakMk() //防止重复下发信号 站点无物 无任务号会自动变成true |
| | | ) { |
| | | if(Cools.isEmpty(barcode) || "NG".endsWith(barcode) || "NoRead".equals(barcode) || "00000000".equals(barcode)) { |
| | | News.info("{}条码扫描错误:{}",barcodeThread.getSlave().getId(),barcode); |
| | | continue; |
| | |
| | | ledThread.errorReset(); |
| | | } |
| | | } else { |
| | | staProtocol.setWorkNo(wrkNo); |
| | | staProtocol.setWorkNo(9999); |
| | | staProtocol.setStaNo(inSta.getBackSta().shortValue()); |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | String errorMsg = jsonObject.getString("msg"); |
| | | log.error("全版入库回退,"+staProtocol.getWorkNo()+","+errorMsg); |
| | | if (!Cools.isEmpty(errorMsg)) { |
| | | MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg)); |
| | | } |
| | |
| | | staProtocol = staProtocol.clone(); |
| | | } |
| | | |
| | | if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.isInEnable() && staProtocol.isPakMk() && staProtocol.getWorkNo() == 9999) { |
| | | if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.isInEnable() && staProtocol.isPakMk()) { |
| | | News.warnNoLog(""+mark+" - 0"+" - 开始执行"); |
| | | WrkMast wrkMast = wrkMastMapper.selectPickStep(barcode); |
| | | if (wrkMast == null) { |
| | |
| | | StaDesc staDesc = staDescService.selectOne(wrapper); |
| | | if (Cools.isEmpty(staDesc)) { |
| | | News.error(""+mark+" - 2"+" - 入库路径不存在!type_no={},stn_no={},crn_no={}", wrkMast.getIoType(), pickSta.getStaNo(), wrkMast.getCrnNo()); |
| | | staProtocol.setWorkNo(wrkNo); |
| | | staProtocol.setWorkNo(9999); |
| | | staProtocol.setStaNo((short) (pickSta.getStaNo().shortValue()-(short)1)); |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | log.error("输送线下发4:"+wrkNo+","+(pickSta.getStaNo().shortValue()-(short)1)); |
| | | log.error("输送线下发4:"+staProtocol.getWorkNo()+","+(pickSta.getStaNo().shortValue()-(short)1)); |
| | | //LED |
| | | LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, pickSta.getLed()); |
| | | // led 异常显示 |
| | |
| | | |
| | | // 更新站点信息 且 下发plc命令 |
| | | staProtocol.setWorkNo(wrkMast.getWrkNo()); |
| | | staProtocol.setStaNo(staProtocol.getSiteId().shortValue()); |
| | | staProtocol.setStaNo(staDesc.getCrnStn().shortValue()); |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | log.error("输送线下发5:"+wrkMast.getWrkNo()+","+wrkMast.getStaNo()); |
| | |
| | | News.warnNoLog(""+mark+" - 1"+" - 12"+" - // F、D 库位状态={}",shallowLoc.getLocSts()); |
| | | // 此标记避免多次执行移库任务 |
| | | if (Cools.isEmpty(wrkMast.getUpdMk()) || "N".equals(wrkMast.getUpdMk())) { |
| | | wrkMast.setUpdMk("Y"); |
| | | wrkMast.setIoPri(14D); |
| | | wrkMastMapper.updateById(wrkMast); |
| | | // 生成工作档,将浅库位移转到新的库位中 |
| | | moveLocForDeepLoc(slave, shallowLoc,mark); |
| | | // 生成工作档、改变浅库位的源库/目标库 库位状态、下发堆垛机命令(立马执行) |
| | | // moveLocForDeepLocPakin(slave, shallowLoc, wrkMast); |
| | | if ( moveLocForDeepLoc(slave, shallowLoc,mark)){ |
| | | wrkMast.setUpdMk("Y"); |
| | | wrkMast.setIoPri(14D); |
| | | wrkMastMapper.updateById(wrkMast); |
| | | } |
| | | } |
| | | continue; |
| | | } else if (shallowLoc.getLocSts().equals("Q")) { |
| | |
| | | // continue; |
| | | } |
| | | |
| | | // 判断堆垛机出库站状态 |
| | | if (staProtocol.isAutoing() && !staProtocol.isLoading() && staDetl.getCanouting() != null && staDetl.getCanouting().equals("Y") |
| | | && staProtocol.getWorkNo() == 0 && staProtocol.isOutEnable()) { |
| | | boolean outStationAvailable = true; |
| | | // 是否检查堆垛机出库站状态(true: 检查,false: 不检查) |
| | | if (slaveProperties.isCheckOutStationStatus()) { |
| | | // 检查出库站状态 |
| | | outStationAvailable = |
| | | //自动 |
| | | staProtocol.isAutoing() |
| | | //!有物 |
| | | && !staProtocol.isLoading() |
| | | //能出 |
| | | && staDetl.getCanouting() != null |
| | | && staDetl.getCanouting().equals("Y") |
| | | //工作号 |
| | | && staProtocol.getWorkNo() == 0 |
| | | //可出 |
| | | && staProtocol.isOutEnable(); |
| | | } |
| | | // 出库站可用时继续执行 |
| | | if (outStationAvailable) { |
| | | // 堆垛机控制过滤 |
| | | if (!crnProtocol.getStatusType().equals(CrnStatusType.IDLE) || crnProtocol.getTaskNo() != 0) { |
| | | // continue; |
| | |
| | | // if (Cools.isEmpty(wrkMast.getUpdMk()) || "N".equals(wrkMast.getUpdMk()) |
| | | // || Cools.isEmpty(waitWrkMast)) { |
| | | if (Cools.isEmpty(waitWrkMast)) { |
| | | wrkMast.setUpdMk("Y"); |
| | | wrkMastMapper.updateById(wrkMast); |
| | | // 生成工作档,将浅库位移转到新的库位中 |
| | | moveLocForDeepLoc(slave, shallowLoc,mark); |
| | | if (moveLocForDeepLoc(slave, shallowLoc,mark)){ |
| | | wrkMast.setUpdMk("Y"); |
| | | wrkMastMapper.updateById(wrkMast); |
| | | } |
| | | } |
| | | News.error("{}任务出库失败,浅库位堵塞!浅库位号:{}", wrkMast.getWrkNo(), shallowLocNo); |
| | | break; |
| | |
| | | for (DevpSlave devp : slaveProperties.getDevp()) { |
| | | // 遍历空板入库口 |
| | | for (DevpSlave.Sta emptyInSta : devp.getEmptyInSta()) { |
| | | // 获取条码扫描仪信息 |
| | | BarcodeThread barcodeThread = null; |
| | | if (!Cools.isEmpty(emptyInSta.getBarcode())) { |
| | | barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, emptyInSta.getBarcode()); |
| | | } |
| | | |
| | | // 获取空板入库站信息 |
| | | SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId()); |
| | | StaProtocol staProtocol = devpThread.getStation().get(emptyInSta.getStaNo()); |
| | |
| | | continue; |
| | | } |
| | | |
| | | // 检查条码扫描:如果扫描到条码,则存入,扫描不到,则不存 |
| | | String barcode = null; |
| | | if (barcodeThread != null) { |
| | | barcode = barcodeThread.getBarcode(); |
| | | // 如果条码为空、NG、NoRead或00000000 |
| | | if (Cools.isEmpty(barcode) || barcode.endsWith("NG") || "NoRead".equals(barcode) || "00000000".equals(barcode)) { |
| | | barcode=null; |
| | | } |
| | | } |
| | | |
| | | // 站点条件判断 |
| | | if (staProtocol.isAutoing() |
| | | && staProtocol.isLoading() |
| | | && staProtocol.isInEnable() |
| | | && staProtocol.isEmptyMk() |
| | | && staProtocol.isPakMk() |
| | | && staProtocol.getWorkNo() == 9998 // 9997 回退 9998 空 9999 满 |
| | | ) { |
| | | News.warnNoLog(""+mark+" - 0"+" - 开始执行:空栈板初始化入库,叉车入库站放货"); |
| | | if (staProtocol.isAutoing() //自动 |
| | | && staProtocol.isLoading() //有物 |
| | | && staProtocol.isInEnable() //可入 |
| | | && staProtocol.isEmptyMk()// 空板 |
| | | && staProtocol.isPakMk() //防止重复下发信号 站点无物 无任务号会自动变成true |
| | | |
| | | ) { |
| | | // 判断重复工作档 |
| | | WrkMast wrkMast = null; |
| | | if (!Cools.isEmpty(barcode)) { |
| | | // 有条码时,检查是否有相同站点和条码的空板入库工作档 |
| | | wrkMast = wrkMastMapper.selectPakInStep1(emptyInSta.getStaNo(), barcode); |
| | | } else { |
| | | // 无条码时,检查是否有相同站点且工作状态为2的空板入库工作档 |
| | | wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>() |
| | | .eq("source_sta_no", emptyInSta.getStaNo()) |
| | | .eq("wrk_sts", 2) |
| | | .eq("io_type", 10)); |
| | | } |
| | | if (wrkMast != null) { |
| | | News.info("{}空板入库重复工作档检查:已存在工作档,工作号:{},条码:{}", emptyInSta.getStaNo(), wrkMast.getWrkNo(), barcode); |
| | | continue; |
| | | } |
| | | |
| | | News.warnNoLog(""+mark+" - 0"+" - 开始执行:空栈板初始化入库,叉车入库站放货,条码:{}", barcode); |
| | | |
| | | try { |
| | | LocTypeDto locTypeDto = new LocTypeDto(staProtocol); |
| | |
| | | param.setIoType(10); |
| | | param.setSourceStaNo(emptyInSta.getStaNo()); |
| | | param.setLocType1(locTypeDto.getLocType1()); |
| | | param.setBarcode(barcode); // 设置扫描到的条码 |
| | | String response = new HttpHandler.Builder() |
| | | .setUri(wmsUrl) |
| | | .setPath("/rpc/pakin/loc/v1") |
| | |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | if (jsonObject.getInteger("code").equals(200)) { |
| | | StartupDto dto = jsonObject.getObject("data", StartupDto.class); |
| | | |
| | | // 清空条码 |
| | | if (barcodeThread != null) { |
| | | barcodeThread.setBarcode(""); |
| | | } |
| | | |
| | | // 更新站点信息 且 下发plc命令 |
| | | staProtocol.setWorkNo(dto.getWorkNo()); |
| | |
| | | LedCommand ledCommand = new LedCommand(); |
| | | ledCommand.setWorkNo(dto.getWorkNo()); |
| | | ledCommand.setIoType(1); |
| | | ledCommand.setTitle("全板入库"); |
| | | ledCommand.setTitle("空板入库"); |
| | | ledCommand.setLocNo(dto.getLocNo()); |
| | | ledCommand.setStaNo(dto.getStaNo()); |
| | | commands.add(ledCommand); |
| | |
| | | // ledThread.errorReset(); |
| | | } |
| | | } else { |
| | | staProtocol.setWorkNo(wrkNo); |
| | | String errorMsg = jsonObject.getString("msg"); |
| | | // 如果任务回退,并且站点不是自动状态,则不触发回退 |
| | | if (!staProtocol.isAutoing()) { |
| | | log.error("空板入库回退"+staProtocol.getWorkNo()+","+errorMsg+",站点不是自动状态,不触发回退"); |
| | | continue; |
| | | } |
| | | log.error("空板入库回退"+staProtocol.getWorkNo()+","+errorMsg); |
| | | staProtocol.setWorkNo(9999); |
| | | staProtocol.setStaNo(emptyInSta.getBackSta().shortValue()); |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | |
| | | } |
| | | |
| | | if (ledThread != null) { |
| | | String errorMsg = jsonObject.getString("msg"); |
| | | |
| | | if (!Cools.isEmpty(errorMsg)) { |
| | | MessageQueue.offer(SlaveType.Led, emptyInSta.getLed(), new Task(3, errorMsg)); |
| | | } |
| | |
| | | * 因双深库位阻塞,对浅库位进行移转(立即执行版) |
| | | * tip:同步 |
| | | */ |
| | | private synchronized void moveLocForDeepLoc(CrnSlave crn, LocMast shallowLoc,Integer mark) { |
| | | /** |
| | | * 因双深库位阻塞,对浅库位进行移转(立即执行版) |
| | | * tip:同步 |
| | | */ |
| | | private synchronized boolean moveLocForDeepLoc(CrnSlave crn, LocMast shallowLoc,Integer mark) { |
| | | |
| | | try { |
| | | News.warnNoLog(""+mark+"moveLocForDeepLoc"+" - 0"+" - 开始执行:因双深库位阻塞,对浅库位进行移转(立即执行版)"); |
| | |
| | | if (null == loc) { |
| | | News.error(""+mark+"moveLocForDeepLoc"+" - 1"+" - 双深库位 --- 浅库位阻塞异常! 待移转浅库位:" + shallowLoc.getLocNo()); |
| | | // throw new CoolException("双深库位 --- 浅库位阻塞异常! 待移转浅库位:" + shallowLoc.getLocNo()); |
| | | } else { |
| | | |
| | | return false; |
| | | }else { |
| | | // 获取工作号 |
| | | int workNo = commonService.getWorkNo(0); |
| | | // 保存工作档 |
| | |
| | | wrkMast.setCrnNo(crn.getId()); |
| | | wrkMast.setSourceLocNo(shallowLoc.getLocNo()); // 源库位 |
| | | wrkMast.setLocNo(loc.getLocNo()); // 目标库位 |
| | | wrkMast.setFullPlt(shallowLoc.getFullPlt()); // 满板 |
| | | wrkMast.setFullPlt(shallowLoc.getLocSts().equals("F") ? "Y" : "N"); // 满板:Y |
| | | wrkMast.setPicking("N"); // 拣料 |
| | | wrkMast.setExitMk("N"); // 退出 |
| | | wrkMast.setEmptyMk(shallowLoc.getLocSts().equals("D") ? "Y" : "N"); // 空板 |
| | |
| | | wrkMast.setModiTime(new Date()); |
| | | int res = wrkMastMapper.insert(wrkMast); |
| | | if (res == 0) { |
| | | News.errorNoLog("" + mark + "moveLocForDeepLoc" + " - 2" + " - 保存工作档失败"); |
| | | News.errorNoLog(""+mark+"moveLocForDeepLoc"+" - 2"+" - 保存工作档失败"); |
| | | throw new CoolException("保存工作档失败"); |
| | | } |
| | | // 工作档明细保存 |
| | |
| | | wrkDetl.setAppeTime(new Date()); |
| | | wrkDetl.setModiTime(new Date()); |
| | | if (!wrkDetlService.insert(wrkDetl)) { |
| | | News.errorNoLog("" + mark + "moveLocForDeepLoc" + " - 3" + " - 保存工作档明细失败"); |
| | | News.errorNoLog(""+mark+"moveLocForDeepLoc"+" - 3"+" - 保存工作档明细失败"); |
| | | throw new CoolException("保存工作档明细失败"); |
| | | } |
| | | } |
| | |
| | | shallowLoc.setLocSts("R"); // R.出库预约 |
| | | shallowLoc.setModiTime(new Date()); |
| | | if (!locMastService.updateById(shallowLoc)) { |
| | | News.errorNoLog("" + mark + "moveLocForDeepLoc" + " - 4" + " - 更新源库位状态失败"); |
| | | News.errorNoLog(""+mark+"moveLocForDeepLoc"+" - 4"+" - 更新源库位状态失败"); |
| | | throw new CoolException("更新源库位状态失败"); |
| | | } |
| | | } else { |
| | | News.errorNoLog("" + mark + "moveLocForDeepLoc" + " - 5" + " - 源库位出库失败"); |
| | | News.errorNoLog(""+mark+"moveLocForDeepLoc"+" - 5"+" - 源库位出库失败"); |
| | | throw new CoolException("源库位出库失败"); |
| | | } |
| | | // 修改目标库位状态 |
| | |
| | | loc.setLocSts("S"); // S.入库预约 |
| | | loc.setModiTime(new Date()); |
| | | if (!locMastService.updateById(loc)) { |
| | | News.errorNoLog("" + mark + "moveLocForDeepLoc" + " - 6" + " - 更新目标库位状态失败"); |
| | | News.errorNoLog(""+mark+"moveLocForDeepLoc"+" - 6"+" - 更新目标库位状态失败"); |
| | | throw new CoolException("更新目标库位状态失败"); |
| | | } |
| | | } else { |
| | | News.errorNoLog("" + mark + "moveLocForDeepLoc" + " - 7" + " - 移转失败"); |
| | | News.errorNoLog(""+mark+"moveLocForDeepLoc"+" - 7"+" - 移转失败"); |
| | | throw new CoolException("移转失败"); |
| | | } |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | News.error(""+mark+"moveLocForDeepLoc"+" - 8"+" - 双深库位阻塞,对浅库位进行移转失败", e); |
| | | e.printStackTrace(); |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /** |