zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java
@@ -177,29 +177,15 @@ throw new BusinessException("oriLoc:" + task.getOriLoc$() + " failed to update"); } // reserver station inbound, qty: 1 destSta = staService.getById(task.getDestSta()); if (null == staReserveService.reserveStaIn(destSta, task, 1)) { throw new BusinessException("destSta:" + task.getDestSta$() + " failed to reserve"); } // if (!destSta.getStaSts().equals(StaStsType.IDLE.val())) { // throw new BusinessException("destSta:" + task.getDestSta$() + " is not in IDLE status"); // } // destSta.setStaSts(StaStsType.READY_RELEASE.val()); // destSta.setUpdateTime(now); // if (!staService.updateById(destSta)) { // throw new BusinessException("destSta:" + task.getDestSta$() + " failed to update"); // } break; case STA_TO_LOC: oriSta = staService.getById(task.getOriSta()); if (!oriSta.getStaSts().equals(StaStsType.STOCK.val())) { throw new BusinessException("oriSta:" + task.getOriSta$() + " is not in STOCK status"); } oriSta.setStaSts(StaStsType.READY_TAKE.val()); oriSta.setUpdateTime(now); if (!staService.updateById(oriSta)) { throw new BusinessException("oriSta:" + task.getOriSta$() + " failed to update"); if (null == staReserveService.reserveStaOut(oriSta, task, 1)) { throw new BusinessException("oriSta:" + task.getOriSta$() + " failed to reserve"); } destLoc = locService.getById(task.getDestLoc()); @@ -214,23 +200,13 @@ break; case STA_TO_STA: oriSta = staService.getById(task.getOriSta()); if (!oriSta.getStaSts().equals(StaStsType.STOCK.val())) { throw new BusinessException("oriSta:" + task.getOriSta$() + " is not in STOCK status"); } oriSta.setStaSts(StaStsType.READY_TAKE.val()); oriSta.setUpdateTime(now); if (!staService.updateById(oriSta)) { throw new BusinessException("oriSta:" + task.getOriSta$() + " failed to update"); if (null == staReserveService.reserveStaOut(oriSta, task, 1)) { throw new BusinessException("oriSta:" + task.getOriSta$() + " failed to reserve"); } destSta = staService.getById(task.getDestSta()); if (!destSta.getStaSts().equals(StaStsType.IDLE.val())) { throw new BusinessException("destSta:" + task.getDestSta$() + " is not in IDLE status"); } destSta.setStaSts(StaStsType.READY_RELEASE.val()); destSta.setUpdateTime(now); if (!staService.updateById(destSta)) { throw new BusinessException("destSta:" + task.getDestSta$() + " failed to update"); if (null == staReserveService.reserveStaIn(destSta, task, 1)) { throw new BusinessException("destSta:" + task.getDestSta$() + " failed to reserve"); } break; default: zy-acs-manager/src/main/java/com/zy/acs/manager/manager/mapper/StaMapper.java
@@ -10,4 +10,8 @@ int releaseReserveIn(@Param("staId") Long staId, @Param("qty") Integer qty); int tryReserveOut(@Param("staId") Long staId, @Param("qty") Integer qty); int releaseReserveOut(@Param("staId") Long staId, @Param("qty") Integer qty); } zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/StaReserveService.java
@@ -9,4 +9,6 @@ StaReserve reserveStaIn(Sta sta, Task task, Integer qty); StaReserve reserveStaOut(Sta sta, Task task, Integer qty); } zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/impl/StaReserveServiceImpl.java
@@ -35,7 +35,7 @@ qty = Optional.ofNullable(qty).orElse(1); // reserve sta in if (qty < staMapper.tryReserveIn(sta.getId(), qty)) { if (staMapper.tryReserveIn(sta.getId(), qty) < qty) { throw new BusinessException("Sta[" + sta.getStaNo() + "] can't reserve IN"); } Date now = new Date(); @@ -48,7 +48,7 @@ reserve.setQty(qty); reserve.setState(StaReserveStateType.RESERVED.toString()); reserve.setUniqKey(this.generateReserveUniqKey(sta.getId(), task.getId())); reserve.setUniqKey(this.generateReserveUniqKey(sta.getId(), task.getId(), StaReserveType.IN)); reserve.setExpireTime(new Date(now.getTime() + RESERVE_EXPIRE_TIME)); reserve.setStatus(StatusType.ENABLE.val); @@ -63,9 +63,44 @@ return reserve; } @Override @Transactional(rollbackFor = Exception.class) public StaReserve reserveStaOut(Sta sta, Task task, Integer qty) { qty = Optional.ofNullable(qty).orElse(1); private String generateReserveUniqKey(Long staId, Long taskId) { return "STA:" + staId + "-TASK:" + taskId + "-T"; // reserve sta out if (staMapper.tryReserveOut(sta.getId(), qty) < qty) { throw new BusinessException("Sta[" + sta.getStaNo() + "] can't reserve OUT"); } Date now = new Date(); // save staReserve StaReserve reserve = new StaReserve(); reserve.setStaId(sta.getId()); reserve.setTaskId(task.getId()); reserve.setType(StaReserveType.OUT.toString()); reserve.setQty(qty); reserve.setState(StaReserveStateType.RESERVED.toString()); reserve.setUniqKey(this.generateReserveUniqKey(sta.getId(), task.getId(), StaReserveType.OUT)); reserve.setExpireTime(new Date(now.getTime() + RESERVE_EXPIRE_TIME)); reserve.setStatus(StatusType.ENABLE.val); reserve.setCreateTime(now); reserve.setUpdateTime(now); if (!this.save(reserve)) { staMapper.releaseReserveOut(sta.getId(), qty); throw new BusinessException("reserve record insert failed"); } return reserve; } private String generateReserveUniqKey(Long staId, Long taskId, StaReserveType type) { return "STA:" + staId + "-TASK:" + taskId + "-T:" + type.toString(); } } zy-acs-manager/src/main/resources/mapper/manager/StaMapper.xml
@@ -7,9 +7,9 @@ SET rsv_in_cnt = rsv_in_cnt + #{qty}, update_time = NOW() WHERE id = #{staId} AND deleted = 0 AND status = 1 AND (capacity - occ_cnt - rsv_in_cnt) >= #{qty} AND deleted = 0 AND status = 1 AND (capacity - occ_cnt - rsv_in_cnt) >= #{qty} </update> <update id="releaseReserveIn"> @@ -17,9 +17,29 @@ SET rsv_in_cnt = rsv_in_cnt - #{qty}, update_time = NOW() WHERE id = #{staId} AND deleted = 0 AND status = 1 AND rsv_in_cnt > #{qty} AND deleted = 0 AND status = 1 AND rsv_in_cnt >= #{qty} </update> <update id="tryReserveOut"> UPDATE man_sta SET rsv_out_cnt = rsv_out_cnt + #{qty}, update_time = NOW() WHERE id = #{staId} AND deleted = 0 AND status = 1 AND (occ_cnt - rsv_out_cnt) >= #{qty} </update> <update id="releaseReserveOut"> UPDATE man_sta SET rsv_out_cnt = rsv_out_cnt - #{qty}, update_time = NOW() WHERE id = #{staId} AND deleted = 0 AND status = 1 AND rsv_out_cnt >= #{qty} </update> <!-- 关联查询sql -->