| | |
| | | changed = staMapper.tryReserveInCommon(sta.getId(), qty); |
| | | } |
| | | if (changed < qty) { |
| | | throw new BusinessException("Sta[" + sta.getStaNo() + "] can't reserve IN"); |
| | | throw new BusinessException("站点【" + sta.getStaNo() + "】可入库数量不足"); |
| | | } |
| | | Date now = new Date(); |
| | | |
| | |
| | | |
| | | if (!this.save(reserve)) { |
| | | staMapper.releaseReserveIn(sta.getId(), qty); |
| | | throw new BusinessException("reserve record insert failed"); |
| | | throw new BusinessException("站点【" + sta.getStaNo() + "】入库预约保存失败"); |
| | | } |
| | | |
| | | return reserve; |
| | |
| | | changed = staMapper.tryReserveOutCommon(sta.getId(), qty); |
| | | } |
| | | if (changed < qty) { |
| | | throw new BusinessException("Sta[" + sta.getStaNo() + "] can't reserve OUT"); |
| | | throw new BusinessException("站点【" + sta.getStaNo() + "】可出库数量不足"); |
| | | } |
| | | |
| | | Date now = new Date(); |
| | |
| | | |
| | | if (!this.save(reserve)) { |
| | | staMapper.releaseReserveOut(sta.getId(), qty); |
| | | throw new BusinessException("reserve record insert failed"); |
| | | throw new BusinessException("站点【" + sta.getStaNo() + "】出库预约保存失败"); |
| | | } |
| | | |
| | | return reserve; |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void confirmStaReserve(Sta sta, Task task, Integer qty, StaReserveType type) { |
| | | qty = Optional.ofNullable(qty).orElse(DEFAULT_QTY); |
| | | String reserveType = StaReserveType.IN.equals(type) ? "入库" : "出库"; |
| | | |
| | | // update reserve state to be confirmed |
| | | if (0 == this.baseMapper.updateState(task.getId(), sta.getId(), type.toString(), StaReserveStateType.CONFIRMED.toString())) { |
| | | log.error("failed to confirm sta reserve"); |
| | | log.error("确认站点预约失败:未找到可确认的预约记录,站点【" + sta.getStaNo() + "】,任务【" + task.getSeqNum() + "】,预约方向【" + reserveType + "】"); |
| | | return; |
| | | } |
| | | |
| | |
| | | break; |
| | | } |
| | | if (cntOfDealWithReserve == 0) { |
| | | throw new BusinessException("Sta[" + sta.getStaNo() + "] confirm failed, type=" + type.toString()); |
| | | throw new BusinessException("站点【" + sta.getStaNo() + "】" + reserveType + "预约确认失败"); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void cancelStaReserve(Sta sta, Task task, Integer qty, StaReserveType type) { |
| | | qty = Optional.ofNullable(qty).orElse(DEFAULT_QTY); |
| | | String reserveType = StaReserveType.IN.equals(type) ? "入库" : "出库"; |
| | | |
| | | // update reserve state to be canceled |
| | | if (0 == this.baseMapper.updateState(task.getId(), sta.getId(), type.toString(), StaReserveStateType.CANCELLED.toString())) { |
| | | log.error("failed to cancel sta reserve"); |
| | | log.error("取消站点预约失败:未找到可取消的预约记录,站点【" + sta.getStaNo() + "】,任务【" + task.getSeqNum() + "】,预约方向【" + reserveType + "】"); |
| | | return; |
| | | } |
| | | |
| | |
| | | break; |
| | | } |
| | | if (cntOfDealWithReserve == 0) { |
| | | throw new BusinessException("Sta[" + sta.getStaNo() + "] cancel failed, type=" + type.toString()); |
| | | throw new BusinessException("站点【" + sta.getStaNo() + "】" + reserveType + "预约取消失败"); |
| | | } |
| | | } |
| | | |
| | |
| | | // .gt(StaReserve::getExpireTime, now) |
| | | ); |
| | | if (null == inStaReserve) { |
| | | throw new CoolException("failed to find out sta reserve"); |
| | | throw new CoolException("未找到目标站点入库预约"); |
| | | } |
| | | break; |
| | | case STA_TO_LOC: |
| | |
| | | // .gt(StaReserve::getExpireTime, now) |
| | | ); |
| | | if (null == outStaReserve) { |
| | | throw new CoolException("failed to find out sta reserve"); |
| | | throw new CoolException("未找到起始站点出库预约"); |
| | | } |
| | | break; |
| | | case STA_TO_STA: |
| | |
| | | // .gt(StaReserve::getExpireTime, now) |
| | | ); |
| | | if (null == inStaReserve) { |
| | | throw new CoolException("failed to find out sta reserve"); |
| | | throw new CoolException("未找到目标站点入库预约"); |
| | | } |
| | | if (null == outStaReserve) { |
| | | throw new CoolException("failed to find out sta reserve"); |
| | | throw new CoolException("未找到起始站点出库预约"); |
| | | } |
| | | break; |
| | | default: |
| | |
| | | inStaReserve.setAgvId(agvId); |
| | | inStaReserve.setUpdateTime(now); |
| | | if (!this.updateById(inStaReserve)) { |
| | | throw new CoolException("failed to update sta reserve"); |
| | | throw new CoolException("入库预约绑定车辆失败"); |
| | | } |
| | | } |
| | | if (null != outStaReserve) { |
| | | outStaReserve.setAgvId(agvId); |
| | | outStaReserve.setUpdateTime(now); |
| | | if (!this.updateById(outStaReserve)) { |
| | | throw new CoolException("failed to update sta reserve"); |
| | | throw new CoolException("出库预约绑定车辆失败"); |
| | | } |
| | | } |
| | | } |