|  |  | 
 |  |  | import com.zy.asrs.entity.*; | 
 |  |  | import com.zy.asrs.enums.LocStsType; | 
 |  |  | import com.zy.asrs.service.*; | 
 |  |  | import com.zy.asrs.service.impl.BasStationServiceImpl; | 
 |  |  | import com.zy.asrs.service.impl.LocCacheServiceImpl; | 
 |  |  | import com.zy.asrs.service.impl.OrderPakinServiceImpl; | 
 |  |  | import com.zy.asrs.service.impl.TaskDetlServiceImpl; | 
 |  |  | import com.zy.asrs.task.AbstractHandler; | 
 |  |  | import com.zy.asrs.task.core.ReturnT; | 
 |  |  | import lombok.extern.slf4j.Slf4j; | 
 |  |  | 
 |  |  |     private OrderPakinService orderPakinService; | 
 |  |  |     @Autowired | 
 |  |  |     private TaskService taskService; | 
 |  |  |     @Autowired | 
 |  |  |     private TaskDetlService taskDetlService; | 
 |  |  |     @Autowired | 
 |  |  |     private BasStationServiceImpl basStationService; | 
 |  |  |  | 
 |  |  |     public ReturnT<String> start(WrkMast wrkMast) { | 
 |  |  |         // 4.入库完成 | 
 |  |  | 
 |  |  |                     } | 
 |  |  |                     // 遍历工作明细,更新库存明细和入库通知档 | 
 |  |  |                     for (WrkDetl wrkDetl : wrkDetls8) { | 
 |  |  |  | 
 |  |  |                         LocDetl locDetl = locDetlService.selectItem(locMast.getLocNo(), wrkDetl.getMatnr(), wrkDetl.getBatch(), wrkDetl.getBrand() | 
 |  |  |                                 , wrkDetl.getStandby1(), wrkDetl.getStandby2(), wrkDetl.getStandby3(), wrkDetl.getBoxType1(), wrkDetl.getBoxType2(), wrkDetl.getBoxType3()); | 
 |  |  |                         if (null != locDetl) { | 
 |  |  | 
 |  |  |                                 if (!orderDetlPakoutService.increaseQtyByOrderNo(wrkDetl.getOrderNo(), wrkDetl.getMatnr(), | 
 |  |  |                                         orderDetlPakout.getBatch(), wrkDetl.getBrand(), wrkDetl.getStandby1(), wrkDetl.getStandby2(), wrkDetl.getStandby3(), | 
 |  |  |                                         wrkDetl.getBoxType1(), wrkDetl.getBoxType2(), wrkDetl.getBoxType3(), wrkDetl.getAnfme())) { | 
 |  |  | //                                    exceptionHandle("全板出库 ===>> 更新订单完成数量失败;[workNo={0}],[locNo={1}]", | 
 |  |  | //                                            wrkMast.getWrkNo(), wrkMast.getLocNo()); | 
 |  |  |                                     TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); | 
 |  |  |                                     return FAIL.setMsg("全板出库 ===>> 更新订单完成数量失败; [workNo=" + wrkMast.getWrkNo() + "],[locNo=" + wrkMast.getSourceLocNo() + "]"); | 
 |  |  |                                 } | 
 |  |  |                             } | 
 |  |  |                         } catch (Exception ignore) { | 
 |  |  |  | 
 |  |  |                         } | 
 |  |  |                     } | 
 |  |  |                     // 删除工作档源库位的库存明细 | 
 |  |  |                     if (!locDetlService.delete(new EntityWrapper<LocDetl>().eq("loc_no", wrkMast.getSourceLocNo()))) { | 
 |  |  | //                        exceptionHandle("全板出库 ===>> 删除库存明细失败;[workNo={0}],[sourceLocNo={1}]", wrkMast.getWrkNo(), wrkMast.getSourceLocNo()); | 
 |  |  |                         TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); | 
 |  |  |                         return FAIL.setMsg("全板出库 ===>> 删除库存明细失败; [workNo=" + wrkMast.getWrkNo() + "],[locNo=" + wrkMast.getSourceLocNo() + "]"); | 
 |  |  |                     } | 
 |  |  | 
 |  |  |                         locMast.setModiTime(now); | 
 |  |  |                         locMast.setIoTime(now); | 
 |  |  |                         if (!locMastService.updateById(locMast)) { | 
 |  |  | //                            exceptionHandle("全板出库 ===>> 修改源库位状态失败;[workNo={0}],[sourceLocNo={1}]", wrkMast.getWrkNo(), wrkMast.getSourceLocNo()); | 
 |  |  |                             TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); | 
 |  |  |                             return FAIL.setMsg("全板出库 ===>> 修改源库位状态失败; [workNo=" + wrkMast.getWrkNo() + "],[locNo=" + wrkMast.getSourceLocNo() + "]"); | 
 |  |  |                         } | 
 |  |  | 
 |  |  |      * @version 1.0 | 
 |  |  |      */ | 
 |  |  |     @Transactional(rollbackFor = Exception.class) | 
 |  |  |     public ReturnT<String> AgvStart(Task wrkMast) { | 
 |  |  |     public ReturnT<String> AgvStart(Task task) { | 
 |  |  |         // 4.入库完成 | 
 |  |  |         if (task.getWrkSts() == 4) { | 
 |  |  |             return agvDoIn(task); | 
 |  |  |             // 14.出库完成 | 
 |  |  |         } else if (task.getWrkSts() == 14) { | 
 |  |  |             return agvDoOut(task); | 
 |  |  |         } | 
 |  |  |         return SUCCESS; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * @author Ryan | 
 |  |  |      * @date 2025/9/25 | 
 |  |  |      * @description: AGV出库任务 | 
 |  |  |      * @version 1.0 | 
 |  |  |      */ | 
 |  |  |     public ReturnT<String> agvDoOut(Task task) { | 
 |  |  |         if (task.getIoType().equals(101)) { | 
 |  |  |             Date now = new Date(); | 
 |  |  |             LocCache locMast = locCacheService.selectOne(new EntityWrapper<LocCache>().eq("loc_no" ,task.getSourceLocNo())); | 
 |  |  |             if (Objects.isNull(locMast)) { | 
 |  |  |                 throw new RuntimeException("数据错误:库位信息不能为空!!"); | 
 |  |  |             } | 
 |  |  |             List<TaskDetl> wrkDetls101 = taskDetlService.selectList(new EntityWrapper<TaskDetl>().eq("wrk_no", task.getWrkNo())); | 
 |  |  |             if (wrkDetls101.isEmpty()) { | 
 |  |  |                 TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); | 
 |  |  |                 return FAIL.setMsg("全板出库 ===>> 工作明细档为空; [workNo=" + task.getWrkNo() + "],[locNo=" + task.getSourceLocNo() + "]"); | 
 |  |  |             } | 
 |  |  |             for (TaskDetl wrkDetl : wrkDetls101) { | 
 |  |  |                 // 更新订单完成数量 | 
 |  |  |                 OrderDetlPakout orderDetlPakout = orderDetlPakoutService.selectItem(wrkDetl.getOrderNo(), wrkDetl.getMatnr(), wrkDetl.getBatch(), wrkDetl.getBrand(), wrkDetl.getStandby1(), wrkDetl.getStandby2(), wrkDetl.getStandby3(), | 
 |  |  |                         wrkDetl.getBoxType1(), wrkDetl.getBoxType2(), wrkDetl.getBoxType3()); | 
 |  |  |                 if (orderDetlPakout == null) { | 
 |  |  |                     orderDetlPakout = orderDetlPakoutService.selectItem(wrkDetl.getOrderNo(), wrkDetl.getMatnr(), wrkDetl.getBatch(), wrkDetl.getBrand(), wrkDetl.getStandby1(), wrkDetl.getStandby2(), wrkDetl.getStandby3(), | 
 |  |  |                             wrkDetl.getBoxType1(), wrkDetl.getBoxType2(), wrkDetl.getBoxType3()); | 
 |  |  |                 } | 
 |  |  |                 try { | 
 |  |  |                     if (!Cools.isEmpty(orderDetlPakout)) { | 
 |  |  |                         if (!orderDetlPakoutService.increaseQtyByOrderNo(wrkDetl.getOrderNo(), wrkDetl.getMatnr(), | 
 |  |  |                                 orderDetlPakout.getBatch(), wrkDetl.getBrand(), wrkDetl.getStandby1(), wrkDetl.getStandby2(), wrkDetl.getStandby3(), | 
 |  |  |                                 wrkDetl.getBoxType1(), wrkDetl.getBoxType2(), wrkDetl.getBoxType3(), wrkDetl.getAnfme())) { | 
 |  |  |                             TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); | 
 |  |  |                             return FAIL.setMsg("全板出库 ===>> 更新订单完成数量失败; [workNo=" + task.getWrkNo() + "],[locNo=" + task.getSourceLocNo() + "]"); | 
 |  |  |                         } | 
 |  |  |                     } | 
 |  |  |                 } catch (Exception ignore) { | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |             // 删除工作档源库位的库存明细 | 
 |  |  |             if (!locDetlService.delete(new EntityWrapper<LocDetl>().eq("loc_no", task.getSourceLocNo()))) { | 
 |  |  |                 TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); | 
 |  |  |                 return FAIL.setMsg("全板出库 ===>> 删除库存明细失败; [workNo=" + task.getWrkNo() + "],[locNo=" + task.getSourceLocNo() + "]"); | 
 |  |  |             } | 
 |  |  |             // 修改源库位状态 R ===>> O | 
 |  |  |             if (locMast.getLocSts().equals(LocStsType.LOC_STS_TYPE_R.type)) { | 
 |  |  |                 locMast.setLocSts(LocStsType.LOC_STS_TYPE_O.type); | 
 |  |  |                 locMast.setBarcode(""); | 
 |  |  |                 locMast.setModiTime(now); | 
 |  |  |                 locMast.setIoTime(now); | 
 |  |  |                 if (!locCacheService.updateById(locMast)) { | 
 |  |  |                     TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); | 
 |  |  |                     return FAIL.setMsg("全板出库 ===>> 修改源库位状态失败; [workNo=" + task.getWrkNo() + "],[locNo=" + task.getSourceLocNo() + "]"); | 
 |  |  |                 } | 
 |  |  |             } else { | 
 |  |  |                 throw new CoolException("当前库位状态" + locMast.getLocSts() + ", 无法执行出库操作!!"); | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             BasStation devNo = basStationService.selectOne(new EntityWrapper<BasStation>().eq("dev_no", task.getStaNo())); | 
 |  |  |             if (Objects.isNull(devNo)) { | 
 |  |  |                 throw new CoolException("站点:" + task.getSourceStaNo() + ", 不存在!!"); | 
 |  |  |             } | 
 |  |  |             devNo.setLocSts(LocStsType.LOC_STS_TYPE_F.type); | 
 |  |  |             devNo.setModiTime(new Date()); | 
 |  |  |             if (!basStationService.updateById(devNo)) { | 
 |  |  |                 throw new CoolException("站点信息修改失败!!"); | 
 |  |  |             } | 
 |  |  |             task.setWrkSts(15L); | 
 |  |  |             if (!taskService.updateById(task)) { | 
 |  |  |                 throw new CoolException("任务状态修改失败!!"); | 
 |  |  |             } | 
 |  |  |         } else { | 
 |  |  |  | 
 |  |  |         } | 
 |  |  |         return SUCCESS; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     @Transactional(rollbackFor = Exception.class) | 
 |  |  |     public ReturnT<String> agvDoIn(Task wrkMast) { | 
 |  |  |         LocCache locCache = locCacheService.selectOne(new EntityWrapper<LocCache>().eq("loc_no", wrkMast.getLocNo())); | 
 |  |  |         if (Objects.isNull(locCache)) { | 
 |  |  |             throw new CoolException("数据错误,库位不存在!!"); | 
 |  |  |         } | 
 |  |  |         if (!locCache.getLocSts().equals(LocStsType.LOC_STS_TYPE_S.type)) { | 
 |  |  |             throw new CoolException("当前库位状态为:" +  LocStsType.LOC_STS_TYPE_S.type +  "." +  LocStsType.LOC_STS_TYPE_S.desc  + ",不是出库预约状态"); | 
 |  |  |             throw new CoolException("当前库位状态为:" + LocStsType.LOC_STS_TYPE_S.type + "." + LocStsType.LOC_STS_TYPE_S.desc + ",不是出库预约状态"); | 
 |  |  |         } | 
 |  |  |         List<WaitPakin> apallet = waitPakinService.selectList(new EntityWrapper<WaitPakin>().eq("zpallet", wrkMast.getBarcode())); | 
 |  |  |         if (Objects.isNull(apallet)) { | 
 |  |  | 
 |  |  |  | 
 |  |  |         locCache.setLocSts(LocStsType.LOC_STS_TYPE_F.type); | 
 |  |  |         locCache.setModiTime(new Date()); | 
 |  |  |         locCache.setBarcode(""); | 
 |  |  |         locCache.setBarcode(wrkMast.getBarcode()); | 
 |  |  |         locCache.setModiTime(new Date()); | 
 |  |  |         locCache.setIoTime(new Date()); | 
 |  |  |         if (!locCacheService.updateById(locCache)) { | 
 |  |  | 
 |  |  |         if (Objects.isNull(pakins) || pakins.isEmpty()) { | 
 |  |  |             throw new CoolException("单据不存在!!"); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  | //        pakins.forEach(orderPakin -> { | 
 |  |  | //            orderPakin.setSettle(4L); | 
 |  |  | //            if (!orderPakinService.updateById(orderPakin)) { | 
 |  |  | //                throw new CoolException("单据修改失败!!"); | 
 |  |  | //            } | 
 |  |  | //            List<OrderDetlPakin> detlPakins = orderDetlPakinService.selectList(new EntityWrapper<OrderDetlPakin>().eq("order_id", orderPakin.getId())); | 
 |  |  | //            if (Objects.isNull(detlPakins) || detlPakins.isEmpty()) { | 
 |  |  | //                throw new CoolException("单据明细不存在!!"); | 
 |  |  | //            } | 
 |  |  | //        }); | 
 |  |  |  | 
 |  |  |         return SUCCESS; | 
 |  |  |     } |