|  |  | 
 |  |  | import com.core.common.SnowflakeIdWorker; | 
 |  |  | import com.core.exception.CoolException; | 
 |  |  | import com.zy.asrs.entity.*; | 
 |  |  | import com.zy.asrs.entity.param.EmptyPlateOutParam; | 
 |  |  | import com.zy.asrs.entity.param.FullStoreParam; | 
 |  |  | import com.zy.asrs.entity.param.LocDetlAdjustParam; | 
 |  |  | import com.zy.asrs.entity.param.StockOutParam; | 
 |  |  | import com.zy.asrs.entity.param.*; | 
 |  |  | import com.zy.asrs.service.*; | 
 |  |  | import com.zy.asrs.utils.Utils; | 
 |  |  | import com.zy.common.model.*; | 
 |  |  | 
 |  |  |         // 检索库位 | 
 |  |  |         LocTypeDto locTypeDto = new LocTypeDto(sourceStaNo); | 
 |  |  |         List<String> matnrs = param.getList().stream().map(FullStoreParam.MatCodeStore::getMatnr).distinct().collect(Collectors.toList()); | 
 |  |  |         StartupDto dto = commonService.getLocNo(DEFAULT_ROW_NO_TYPE, 1, param.getDevpNo(), matnrs, locTypeDto,0); | 
 |  |  |         StartupDto dto = commonService.getLocNo(DEFAULT_ROW_NO_TYPE, 1, param.getDevpNo(), matnrs, locTypeDto, 0); | 
 |  |  |         // 生成工作号 | 
 |  |  |         int workNo = dto.getWorkNo(); | 
 |  |  |         // 生成工作档 | 
 |  |  | 
 |  |  |     public void startupFullTakeStore(StockOutParam param, Long userId) { | 
 |  |  |         List<StockOutParam.LocDetl> locDetls = new ArrayList<>(); | 
 |  |  |         List<String> locs = new ArrayList<>(); | 
 |  |  |         for(StockOutParam.LocDetl one : param.getLocDetls()){ | 
 |  |  |         List<SameMatCount> sameMatCounts = new ArrayList<>(); | 
 |  |  |         for (StockOutParam.LocDetl one : param.getLocDetls()) { | 
 |  |  |             locs.add(one.getLocNo()); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         List<StockOutParam.LocDetl> stockOutParamLocDetlSort = Utils.getStockOutParamLocDetlSort(param.getLocDetls()); | 
 |  |  |         boolean sign = true; | 
 |  |  |         boolean isfull = false; // 是否够数量 | 
 |  |  |         Double isOut = 0.0; | 
 |  |  |         //Double isOut = 0.0; | 
 |  |  |         Map<String, Double> isOuts = new HashMap<>(); | 
 |  |  |         List<String> locNoWeighting = new ArrayList<>(); | 
 |  |  |         log.info("canshu:{}", stockOutParamLocDetlSort); | 
 |  |  |         for (StockOutParam.LocDetl locDetl : stockOutParamLocDetlSort) { | 
 |  |  |             if (Cools.isEmpty(locNoWeighting)){ | 
 |  |  |             if (isOuts.get(locDetl.getMatnr()) == null) { | 
 |  |  |                 isOuts.put(locDetl.getMatnr(), locDetl.getCount()); | 
 |  |  |             } else { | 
 |  |  |                 isOuts.put(locDetl.getMatnr(), isOuts.get(locDetl.getMatnr()) + locDetl.getCount()); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         log.info("canshu:{}", JSON.toJSONString(isOuts)); | 
 |  |  |  | 
 |  |  |         for (StockOutParam.LocDetl locDetl : stockOutParamLocDetlSort) { | 
 |  |  |  | 
 |  |  | //            SameMatCount smc = new SameMatCount(); | 
 |  |  | //            if (Cools.isEmpty(sameMatCounts)) { | 
 |  |  | //                smc.setMatnr(locDetl.getMatnr()); | 
 |  |  | //                smc.setNeedOutCount(locDetl.getCount()); | 
 |  |  | //                sameMatCounts.add(smc); | 
 |  |  | //            } else { | 
 |  |  | //                for (SameMatCount sameMatCount : sameMatCounts) { | 
 |  |  | //                    if (sameMatCount.getMatnr().equals(locDetl.getMatnr())) { | 
 |  |  | //                        sameMatCount.setNeedOutCount(locDetl.getCount() + sameMatCount.getNeedOutCount()); | 
 |  |  | //                        //smc.setMatnr(sameMatCount.getMatnr()); | 
 |  |  | //                        smc.setNeedOutCount(sameMatCount.getNeedOutCount()); | 
 |  |  | //                    } | 
 |  |  | //                } | 
 |  |  | //            } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |             if (Cools.isEmpty(locNoWeighting)) { | 
 |  |  |                 locNoWeighting.add(locDetl.getLocNo()); | 
 |  |  |             }else { | 
 |  |  |                 if (!Utils.getLocNoWeighting(locNoWeighting,locDetl.getLocNo())){ | 
 |  |  |             } else { | 
 |  |  |                 if (!Utils.getLocNoWeighting(locNoWeighting, locDetl.getLocNo())) { | 
 |  |  |                     locNoWeighting.add(locDetl.getLocNo()); | 
 |  |  |                     sign = true; | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |             if (sign){ | 
 |  |  |  | 
 |  |  |             if (sign) { | 
 |  |  |                 LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", locDetl.getLocNo())); | 
 |  |  |                 //获取同一库位组的外侧库位号 | 
 |  |  |                 List<String> groupOuterSingleLoc = Utils.getGroupOuterSingleLoc(locDetl.getLocNo()); | 
 |  |  |                 if (locMast.getLocType2().equals((short)3)){ | 
 |  |  |                 if (locMast.getLocType2().equals((short) 3)) { | 
 |  |  |                     groupOuterSingleLoc = Utils.getGroupOuterSingleLocLowFrequency(locDetl.getLocNo()); | 
 |  |  |                     sign = false; | 
 |  |  |                 } | 
 |  |  |                 for (String locNo : groupOuterSingleLoc) { | 
 |  |  |                     //每个库位的库位明细 | 
 |  |  |                     if(locs.contains(locNo)) continue; | 
 |  |  |                     if (locs.contains(locNo)) continue; | 
 |  |  |                     LocMast mast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", locNo)); | 
 |  |  |                     if (mast.getLocSts().equals("P") || mast.getLocSts().equals("Q")){ | 
 |  |  |                     if (mast.getLocSts().equals("P") || mast.getLocSts().equals("Q")) { | 
 |  |  |                         throw new CoolException("当前库位的浅库位状态为" + mast.getLocSts() + "暂不支持出库!"); | 
 |  |  |                     } | 
 |  |  |                     for (LocDetl detl : locDetlService.selectByLocNo(locNo)) { | 
 |  |  |                         if (!detl.getMatnr().equals(locDetl.getMatnr())) { | 
 |  |  |                             //不是相同物料 | 
 |  |  |                             if (!sign){ | 
 |  |  |                             if (!sign) { | 
 |  |  |                                 locDetls.add(new StockOutParam.LocDetl(detl.getLocNo(), detl.getMatnr(), detl.getBatch(), detl.getAnfme())); | 
 |  |  |                                 System.out.println("1"); | 
 |  |  |                             } | 
 |  |  |                             continue; | 
 |  |  |                         } | 
 |  |  |                         if (!param.getOutSite().equals(214) && !param.getOutSite().equals(114)){ | 
 |  |  |                             if (detl.getAnfme() >= locDetl.getCount()) { | 
 |  |  |                                 locDetls.add(new StockOutParam.LocDetl(detl.getLocNo(), detl.getMatnr(), detl.getBatch(), locDetl.getCount())); | 
 |  |  |                                 isOut = locDetl.getCount(); | 
 |  |  |                         if (!param.getOutSite().equals(214) && !param.getOutSite().equals(114)) { | 
 |  |  |                             if (detl.getAnfme() >= isOuts.get(detl.getMatnr())) { | 
 |  |  |                                 // if (detl.getAnfme() >= locDetl.getCount()) { | 
 |  |  |                                 locDetls.add(new StockOutParam.LocDetl(detl.getLocNo(), detl.getMatnr(), detl.getBatch(), isOuts.get(detl.getMatnr()))); | 
 |  |  |                                 System.out.println("2"); | 
 |  |  |                                 //isOut = locDetl.getCount(); | 
 |  |  |                                 isfull = true; | 
 |  |  |                                 break; | 
 |  |  |                             } else { | 
 |  |  |                                 locDetls.add(new StockOutParam.LocDetl(detl.getLocNo(), detl.getMatnr(), detl.getBatch(), detl.getAnfme())); | 
 |  |  |                                 isOut = detl.getAnfme(); | 
 |  |  |                                 isOuts.put(detl.getMatnr(), isOuts.get(detl.getMatnr()) - detl.getAnfme()); | 
 |  |  |                                 System.out.println(isOuts.get(locDetl.getMatnr())); | 
 |  |  |                             } | 
 |  |  |                         } else { | 
 |  |  |                             //强制不是相同物料 | 
 |  |  |                             locDetls.add(new StockOutParam.LocDetl(detl.getLocNo(), detl.getMatnr(), detl.getBatch(), detl.getAnfme())); | 
 |  |  | //                            System.out.println("4"); | 
 |  |  |                         } | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |             if (!isfull) { | 
 |  |  |             if (!isfull && isOuts.get(locDetl.getMatnr()) != null && isOuts.get(locDetl.getMatnr()) > 0) { | 
 |  |  |                 if (locDetl.getCount() >= isOuts.get(locDetl.getMatnr())) { | 
 |  |  |                     locDetls.add(new StockOutParam.LocDetl(locDetl.getLocNo(), locDetl.getMatnr(), locDetl.getBatch(), isOuts.get(locDetl.getMatnr()))); | 
 |  |  |                     isOuts.put(locDetl.getMatnr(), isOuts.get(locDetl.getMatnr()) - locDetl.getCount()); | 
 |  |  | //                    System.out.println(23); | 
 |  |  |                 } else { | 
 |  |  |                     locDetls.add(new StockOutParam.LocDetl(locDetl.getLocNo(), locDetl.getMatnr(), locDetl.getBatch(), locDetl.getCount())); | 
 |  |  |                     isOuts.put(locDetl.getMatnr(), isOuts.get(locDetl.getMatnr()) - locDetl.getCount()); | 
 |  |  | //                    System.out.println("1222"); | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 locDetls.add(new StockOutParam.LocDetl(locDetl.getLocNo(), locDetl.getMatnr(), locDetl.getBatch(), locDetl.getCount() - isOut)); | 
 |  |  |  | 
 |  |  |                 //locDetls.add(new StockOutParam.LocDetl(locDetl.getLocNo(), locDetl.getMatnr(), locDetl.getBatch(), locDetl.getCount() - isOut)); | 
 |  |  | //                locDetls.add(locDetl); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  | 
 |  |  | //        List<StockOutParam.LocDetl> locDetls = param.getLocDetls(); | 
 |  |  |  | 
 |  |  |  | 
 |  |  |  | 
 |  |  | //        ArrayList<String> locNos = new ArrayList<>(); | 
 |  |  | //        List<StockOutParam.LocDetl> locDetls = new ArrayList<>(); | 
 |  |  | //        ArrayList<String> matnrs = new ArrayList<>();//目的做数据去重 | 
 |  |  | 
 |  |  |                 if (null != one) locDetlDtos.add(new LocDetlDto(one, paramLocDetl.getCount())); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         for (LocDetlDto locDetlDto:locDetlDtos){ | 
 |  |  |             if (locs.contains(locDetlDto.getLocDetl().getLocNo())){ | 
 |  |  |         for (LocDetlDto locDetlDto : locDetlDtos) { | 
 |  |  |             if (locs.contains(locDetlDto.getLocDetl().getLocNo())) { | 
 |  |  |                 locDetlDto.setSign(true); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         if (!locDetlDtos.isEmpty()) { | 
 |  |  |             LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", locDetlDtos.get(0).getLocDetl().getLocNo())); | 
 |  |  |             if (locMast.getLocSts().equals("F") || locMast.getLocSts().equals("D") ){ | 
 |  |  |             if (locMast.getLocSts().equals("F") || locMast.getLocSts().equals("D")) { | 
 |  |  |                 // 启动出库开始 101.出库 | 
 |  |  |                 stockOut2(staNo, locDetlDtos, null, userId); | 
 |  |  |             }else { | 
 |  |  |                 throw new CoolException("所选库位存在状态不为F、D的库位,库位号:"+locMast.getLocNo()+" 、当前状态:"+locMast.getLocSts()+"-"+locMast.getLocSts$()); | 
 |  |  |             } else { | 
 |  |  |                 throw new CoolException("所选库位存在状态不为F、D的库位,库位号:" + locMast.getLocNo() + " 、当前状态:" + locMast.getLocSts() + "-" + locMast.getLocSts$()); | 
 |  |  |             } | 
 |  |  |         } else { | 
 |  |  |             throw new CoolException("库存不存在"); | 
 |  |  | 
 |  |  |                         double realCount = 0;//实际提供数量 | 
 |  |  |                         if (detl.getAnfme() >= lastCount) {//实际数量大于所需数量,按所需数量提供 | 
 |  |  |                             realCount = lastCount; | 
 |  |  |                         }else { | 
 |  |  |                         } else { | 
 |  |  |                             //实际小于所需数量,按实际数量提供 | 
 |  |  |                             realCount = detl.getAnfme(); | 
 |  |  |                         } | 
 |  |  | 
 |  |  |                 double realCount = 0;//实际提供数量 | 
 |  |  |                 if (locDetl0.getAnfme() >= lastCount) {//实际数量大于所需数量,按所需数量提供 | 
 |  |  |                     realCount = lastCount; | 
 |  |  |                 }else { | 
 |  |  |                 } else { | 
 |  |  |                     //实际小于所需数量,按实际数量提供 | 
 |  |  |                     realCount = locDetl0.getAnfme(); | 
 |  |  |                 } | 
 |  |  | 
 |  |  |                 double realCount = 0;//实际提供数量 | 
 |  |  |                 if (locDetl0.getAnfme() >= lastCount) {//实际数量大于所需数量,按所需数量提供 | 
 |  |  |                     realCount = lastCount; | 
 |  |  |                 }else { | 
 |  |  |                 } else { | 
 |  |  |                     //实际小于所需数量,按实际数量提供 | 
 |  |  |                     realCount = locDetl0.getAnfme(); | 
 |  |  |                 } | 
 |  |  | 
 |  |  |             String locNo = locDetlDto.getLocDetl().getLocNo(); | 
 |  |  |             locNos2.add(locNo); | 
 |  |  |             //if (locNos.contains(locNo)) { | 
 |  |  |                 //for (OutLocDto dto : dtos) { | 
 |  |  |                 //    if (dto.getLocNo().equals(locNo)) { | 
 |  |  |                 //        dto.getLocDetlDtos().add(locDetlDto); | 
 |  |  |                 //        break; | 
 |  |  |                 //    } | 
 |  |  |                 //} | 
 |  |  |             //for (OutLocDto dto : dtos) { | 
 |  |  |             //    if (dto.getLocNo().equals(locNo)) { | 
 |  |  |             //        dto.getLocDetlDtos().add(locDetlDto); | 
 |  |  |             //        break; | 
 |  |  |             //    } | 
 |  |  |             //} | 
 |  |  |             //} else { | 
 |  |  |                 //locNos.add(locNo); | 
 |  |  |             //locNos.add(locNo); | 
 |  |  |  | 
 |  |  |                 //dtos.add(new OutLocDto(locNo, locDetlDto)); | 
 |  |  |             //dtos.add(new OutLocDto(locNo, locDetlDto)); | 
 |  |  |             //} | 
 |  |  |         } | 
 |  |  |         List<String> innermostSideLoc = Utils.getInnermostSideLoc(locNos2, true); | 
 |  |  |         System.out.println(innermostSideLoc); | 
 |  |  |         for (LocDetlDto locDetlDto : locDetlDtos) { | 
 |  |  |             String locNo = locDetlDto.getLocDetl().getLocNo(); | 
 |  |  |             if(innermostSideLoc.contains(locNo)) { | 
 |  |  |             if (innermostSideLoc.contains(locNo)) { | 
 |  |  |                 if (locNos.contains(locNo)) { | 
 |  |  |                     for (OutLocDto dto : dtos) { | 
 |  |  |                         if (dto.getLocNo().equals(locNo)) { | 
 |  |  | 
 |  |  |  | 
 |  |  |             List<String> outerLocs = Utils.getGroupOuterSingleLoc(locNo); | 
 |  |  |             LocMast locMast1 = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", dto.getLocNo())); | 
 |  |  |             if (locMast1.getLocType2().equals((short)3)){ | 
 |  |  |             if (locMast1.getLocType2().equals((short) 3)) { | 
 |  |  |                 outerLocs = Utils.getGroupOuterSingleLocLowFrequency(locMast1.getLocNo()); | 
 |  |  |             } | 
 |  |  |             Double wrkPri = 15D; | 
 |  |  | 
 |  |  |                     if (!locDetl.getMatnr().equals(matnr)) { | 
 |  |  |                         flag = true; | 
 |  |  |                         break; | 
 |  |  |                     }else if (!Cools.isEmpty(ioWorkType) && ioWorkType.equals(IoWorkType.CHECK_OUT)){ | 
 |  |  |                     } else if (!Cools.isEmpty(ioWorkType) && ioWorkType.equals(IoWorkType.CHECK_OUT)) { | 
 |  |  |                         flag = true; | 
 |  |  |                         break; | 
 |  |  |                     } | 
 |  |  | 
 |  |  |                 if (flag) { | 
 |  |  |                     //当前巷道存在不同规格的物料,需要进行101全板出库 | 
 |  |  |                     // 获取路径 | 
 |  |  |                     StaDesc staDesc = staDescService.queryCrnStn(101, locMast.getCrnNo(), locMast.getCrnNo()==1? 100:200 , locMast.getRow1()); | 
 |  |  |                     if(staDesc == null){ | 
 |  |  |                     StaDesc staDesc = staDescService.queryCrnStn(101, locMast.getCrnNo(), locMast.getCrnNo() == 1 ? 100 : 200, locMast.getRow1()); | 
 |  |  |                     if (staDesc == null) { | 
 |  |  |                         throw new CoolException("出库路径不存在"); | 
 |  |  |                     } | 
 |  |  |  | 
 |  |  | 
 |  |  |                     wrkMast.setOutMost(0); | 
 |  |  |                     wrkMast.setCrnNo(locMast.getCrnNo()); | 
 |  |  |                     wrkMast.setSourceStaNo(staDesc.getCrnStn()); // 源站 | 
 |  |  |                     wrkMast.setStaNo(locMast.getCrnNo()==1? 100:200); // 目标站 | 
 |  |  |                     wrkMast.setStaNo(locMast.getCrnNo() == 1 ? 100 : 200); // 目标站 | 
 |  |  |                     wrkMast.setSourceLocNo(locMast.getLocNo()); // 源库位 | 
 |  |  |                     wrkMast.setFullPlt("Y"); // 满板:Y | 
 |  |  |                     wrkMast.setPicking("N"); // 拣料 | 
 |  |  | 
 |  |  |                         if (Cools.isEmpty(mat)) { | 
 |  |  |                             throw new CoolException(locDetl.getMatnr() + "商品档案不存在"); | 
 |  |  |                         } | 
 |  |  |                         int zpallet = waitPakinService.selectCount(new EntityWrapper<WaitPakin>().eq("zpallet", locDetl.getZpallet()).ne("loc_no",locDetl.getLocNo())); | 
 |  |  |                         if (zpallet>0) { | 
 |  |  |                         int zpallet = waitPakinService.selectCount(new EntityWrapper<WaitPakin>().eq("zpallet", locDetl.getZpallet()).ne("loc_no", locDetl.getLocNo())); | 
 |  |  |                         if (zpallet > 0) { | 
 |  |  |                             throw new CoolException(locDetl.getZpallet() + "入库通知档中已存在"); | 
 |  |  |                         } | 
 |  |  |                         WaitPakin waitPakin = new WaitPakin(); | 
 |  |  | 
 |  |  |             LocMast locMast = locMastService.selectById(dto.getLocNo()); | 
 |  |  |  | 
 |  |  |             //-----------------2023.6.2出库兼容代码----------------------- | 
 |  |  |             if (ioType!=107){ | 
 |  |  |             if (ioType != 107) { | 
 |  |  |                 List<LocDetl> locDetls = locDetlService.selectByLocNo(locMast.getLocNo()); | 
 |  |  |                 //if (locMast.getLocType2() == 1 && locDetls.size() > 1) { | 
 |  |  |                 //    //单品区域出库物料大于1种,强制变成101全板出库 | 
 |  |  | 
 |  |  |                 //    } | 
 |  |  |                 //} | 
 |  |  |                 if (ioType == 101) { | 
 |  |  |                     if (staNo.getDevNo()==300){ | 
 |  |  |                         if(locMast.getCrnNo() == 1) { | 
 |  |  |                     if (staNo.getDevNo() == 300) { | 
 |  |  |                         if (locMast.getCrnNo() == 1) { | 
 |  |  |                             staNo.setDevNo(100); | 
 |  |  |                         } else { | 
 |  |  |                             staNo.setDevNo(200); | 
 |  |  | 
 |  |  |  | 
 |  |  |             // 获取路径 | 
 |  |  |             StaDesc staDesc = staDescService.queryCrnStn(ioType, locMast.getCrnNo(), staNo.getDevNo(), locMast.getRow1()); | 
 |  |  |             if(staDesc == null){ | 
 |  |  |             if (staDesc == null) { | 
 |  |  |                 throw new CoolException("出库路径不存在"); | 
 |  |  |             } | 
 |  |  |  | 
 |  |  | 
 |  |  |                 for (OutLocDto dto : dtos) { | 
 |  |  |                     if (dto.getLocNo().equals(locNo)) { | 
 |  |  |                         boolean signDto = false; | 
 |  |  |                         for (LocDetlDto locDetlDto1 : dto.getLocDetlDtos()){ | 
 |  |  |                         for (LocDetlDto locDetlDto1 : dto.getLocDetlDtos()) { | 
 |  |  |                             if (locDetlDto1.getLocDetl().getBatch().equals(locDetlDto.getLocDetl().getBatch()) | 
 |  |  |                                     && locDetlDto1.getLocDetl().getMatnr().equals(locDetlDto.getLocDetl().getMatnr()) | 
 |  |  |                                     && locDetlDto1.getLocDetl().getLocNo().equals(locDetlDto.getLocDetl().getLocNo())){ | 
 |  |  |                                     && locDetlDto1.getLocDetl().getLocNo().equals(locDetlDto.getLocDetl().getLocNo())) { | 
 |  |  |                                 signDto = true; | 
 |  |  |                             } | 
 |  |  |                         } | 
 |  |  |                         if (!signDto){ | 
 |  |  |                         if (!signDto) { | 
 |  |  |                             dto.getLocDetlDtos().add(locDetlDto); | 
 |  |  |                             break; | 
 |  |  |                         } | 
 |  |  | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             List<String> outerLocs = new ArrayList<>(); | 
 |  |  |             if (!dto.isSign()){ | 
 |  |  |             if (!dto.isSign()) { | 
 |  |  |                 outerLocs.add(dto.getLocNo()); | 
 |  |  |             } | 
 |  |  |             Double wrkPri = 15D; | 
 |  |  | 
 |  |  |                         if (Cools.isEmpty(mat)) { | 
 |  |  |                             throw new CoolException(locDetl.getMatnr() + "商品档案不存在"); | 
 |  |  |                         } | 
 |  |  |                         int zpallet = waitPakinService.selectCount(new EntityWrapper<WaitPakin>().eq("zpallet", locDetl.getZpallet()).ne("loc_no",locDetl.getLocNo())); | 
 |  |  |                         if (zpallet>0) { | 
 |  |  |                         int zpallet = waitPakinService.selectCount(new EntityWrapper<WaitPakin>().eq("zpallet", locDetl.getZpallet()).ne("loc_no", locDetl.getLocNo())); | 
 |  |  |                         if (zpallet > 0) { | 
 |  |  |                             throw new CoolException(locDetl.getZpallet() + "入库通知档中已存在"); | 
 |  |  |                         } | 
 |  |  |                         WaitPakin waitPakin = new WaitPakin(); | 
 |  |  | 
 |  |  |                 //     throw new CoolException("只能存在一笔盘点任务"); | 
 |  |  |                 // } | 
 |  |  |             } | 
 |  |  |             if (ioType!=101){ | 
 |  |  |                 if (basDevp==114 || basDevp==214){ | 
 |  |  |             if (ioType != 101) { | 
 |  |  |                 if (basDevp == 114 || basDevp == 214) { | 
 |  |  |                     throw new CoolException("2楼只允许全板出库,请选择全部物料"); | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  | 
 |  |  |             LocMast locMast = locMastService.selectById(dto.getLocNo()); | 
 |  |  |  | 
 |  |  |             //-----------------2023.6.2出库兼容代码----------------------- | 
 |  |  |             if (ioType!=107){ | 
 |  |  |             if (ioType != 107) { | 
 |  |  |                 List<LocDetl> locDetls = locDetlService.selectByLocNo(locMast.getLocNo()); | 
 |  |  |                 //if (locMast.getLocType2() == 1 && locDetls.size() > 1) { | 
 |  |  |                 //    //单品区域出库物料大于1种,强制变成101全板出库 | 
 |  |  | 
 |  |  |                 //    } | 
 |  |  |                 //} | 
 |  |  |                 if (ioType == 101) { | 
 |  |  |                     if (basDevp==300){ | 
 |  |  |                         if(locMast.getCrnNo() == 1) { | 
 |  |  |                     if (basDevp == 300) { | 
 |  |  |                         if (locMast.getCrnNo() == 1) { | 
 |  |  |                             staNo.setDevNo(100); | 
 |  |  |                         } else { | 
 |  |  |                             staNo.setDevNo(200); | 
 |  |  |                         } | 
 |  |  |                     } else if (basDevp == 114){ | 
 |  |  |                         if (!dto.isSign()){ | 
 |  |  |                     } else if (basDevp == 114) { | 
 |  |  |                         if (!dto.isSign()) { | 
 |  |  |                             staNo.setDevNo(100); | 
 |  |  |                         } else { | 
 |  |  |                             staNo.setDevNo(basDevp); | 
 |  |  |                         } | 
 |  |  |                     } else if (basDevp == 214){ | 
 |  |  |                         if (!dto.isSign()){ | 
 |  |  |                     } else if (basDevp == 214) { | 
 |  |  |                         if (!dto.isSign()) { | 
 |  |  |                             staNo.setDevNo(200); | 
 |  |  |                         } else { | 
 |  |  |                             staNo.setDevNo(basDevp); | 
 |  |  |                         } | 
 |  |  |                     } else { | 
 |  |  |                         if(locMast.getCrnNo() == 1) { | 
 |  |  |                         if (locMast.getCrnNo() == 1) { | 
 |  |  |                             staNo.setDevNo(100); | 
 |  |  |                         } else { | 
 |  |  |                             staNo.setDevNo(200); | 
 |  |  | 
 |  |  |  | 
 |  |  |             // 获取路径 | 
 |  |  |             StaDesc staDesc = staDescService.queryCrnStn(ioType, locMast.getCrnNo(), staNo.getDevNo(), locMast.getRow1()); | 
 |  |  |             if(staDesc == null){ | 
 |  |  |             if (staDesc == null) { | 
 |  |  |                 throw new CoolException("出库路径不存在"); | 
 |  |  |             } | 
 |  |  |  | 
 |  |  | 
 |  |  |             wrkMast.setModiTime(now); | 
 |  |  |             if (!wrkMastService.insert(wrkMast)) { | 
 |  |  |                 throw new CoolException("保存工作档失败,出库库位号:" + dto.getLocNo()); | 
 |  |  |             } else { | 
 |  |  |                 log.info("出库插入工作主档成功===>>" + JSON.toJSONString(wrkMast)); | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             // 生成工作档明细 | 
 |  |  |  | 
 |  |  |             for (LocDetlDto detlDto : dto.getLocDetlDtos()) { | 
 |  |  |                 log.info("开始插入工作明细===>>工作号:" + workNo + "明细:" + JSON.toJSONString(detlDto)); | 
 |  |  |                 if (detlDto.getCount() == null || detlDto.getCount() <= 0.0D) { | 
 |  |  |                     continue; | 
 |  |  |                 } | 
 |  |  | 
 |  |  |                 wrkDetl.setMatType(detlDto.getLocDetl().getMatType()); | 
 |  |  |                 wrkDetl.setZpallet(locMast.getBarcode()); | 
 |  |  |                 if (!wrkDetlService.insert(wrkDetl)) { | 
 |  |  |                     throw new CoolException("保存工作档明细失败"); | 
 |  |  |                     throw new CoolException("stockOut2:保存工作档明细失败===>>" + JSON.toJSONString(wrkDetl)); | 
 |  |  |                 } else { | 
 |  |  |                     log.info("出库插入工作明细成功===>>" + JSON.toJSONString(wrkDetl)); | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |             // 修改库位状态:   F.在库 ====>>> R.出库预约/P.拣料/盘点/并板出库中 | 
 |  |  | 
 |  |  |     @Transactional | 
 |  |  |     public void stockOut(BasDevp staNo, TaskDto taskDto, Long userId) { | 
 |  |  |         Date now = new Date(); | 
 |  |  |         if (Cools.isEmpty(taskDto.getLocDtos()) || taskDto.getLocDtos().size()==0){ | 
 |  |  |         if (Cools.isEmpty(taskDto.getLocDtos()) || taskDto.getLocDtos().size() == 0) { | 
 |  |  |             // 获取库位 | 
 |  |  |             LocMast locMast = locMastService.selectById(taskDto.getLocNo()); | 
 |  |  |             // 获取路径 | 
 |  |  | 
 |  |  |             wrkMast.setSourceStaNo(staDesc.getCrnStn()); // 源站 | 
 |  |  |             wrkMast.setStaNo(staDesc.getStnNo()); // 目标站 | 
 |  |  |             wrkMast.setSourceLocNo(taskDto.getLocNo()); // 源库位 | 
 |  |  |             wrkMast.setFullPlt(ioType==110? "N":"Y"); // 满板:Y | 
 |  |  |             wrkMast.setFullPlt(ioType == 110 ? "N" : "Y"); // 满板:Y | 
 |  |  |             wrkMast.setPicking("N"); // 拣料 | 
 |  |  |             wrkMast.setExitMk("N"); // 退出 | 
 |  |  |             wrkMast.setEmptyMk(ioType==110? "Y":"N"); // 空板 | 
 |  |  |             wrkMast.setEmptyMk(ioType == 110 ? "Y" : "N"); // 空板 | 
 |  |  |             wrkMast.setLinkMis("N"); | 
 |  |  |             wrkMast.setBarcode(locMast.getBarcode()); | 
 |  |  |             wrkMast.setAppeUser(userId); // 操作人员数据 | 
 |  |  | 
 |  |  |             } | 
 |  |  |             // 修改库位状态:   F、D.在库 ====>>> R.出库预约/P.拣料/盘点/并板出库中 | 
 |  |  |             locMast = locMastService.selectById(taskDto.getLocNo()); | 
 |  |  |             if (locMast.getLocSts().equals("F") || locMast.getLocSts().equals("D") ) { | 
 |  |  |             if (locMast.getLocSts().equals("F") || locMast.getLocSts().equals("D")) { | 
 |  |  |                 locMast.setLocSts("R"); | 
 |  |  |                 locMast.setModiUser(userId); | 
 |  |  |                 locMast.setModiTime(now); | 
 |  |  | 
 |  |  |             if (!wrkDetlService.insert(wrkDetl)) { | 
 |  |  |                 throw new CoolException("保存工作档明细失败"); | 
 |  |  |             } | 
 |  |  |             if (!wrkDetl.getOrderNo().equals("伴生出库")){ | 
 |  |  |             if (!wrkDetl.getOrderNo().equals("伴生出库")) { | 
 |  |  |                 // 修改订单明细 | 
 |  |  |                 if (!BaseController.isJSON(locDto.getOrderNo())) { | 
 |  |  |                     String[] orderNos = GetOrderNo(locDto.getOrderNo()); | 
 |  |  |                     if (!Cools.isEmpty(orderNos) && orderNos.length!=0){ | 
 |  |  |                     if (!Cools.isEmpty(orderNos) && orderNos.length != 0) { | 
 |  |  |                         Double anfme = locDto.getAnfme(); | 
 |  |  |                         for (String orderNo : orderNos) { | 
 |  |  |                             OrderDetl orderDetl = orderDetlService.selectItem(orderNo, locDto.getMatnr(), locDto.getBatch()); | 
 |  |  | 
 |  |  |                             } | 
 |  |  |                             orderService.updateSettle(orderDetl.getOrderId(), 2L, userId); | 
 |  |  |                         } | 
 |  |  |                     }else { | 
 |  |  |                     } else { | 
 |  |  |                         OrderDetl orderDetl = orderDetlService.selectItem(locDto.getOrderNo(), locDto.getMatnr(), locDto.getBatch()); | 
 |  |  |                         if (orderDetl == null) { | 
 |  |  |                             orderDetl = orderDetlService.selectItem(locDto.getOrderNo(), locDto.getMatnr(), null); | 
 |  |  | 
 |  |  |                         orderService.updateSettle(orderDetl.getOrderId(), 2L, userId); | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |             }else {//自动组托 | 
 |  |  |             } else {//自动组托 | 
 |  |  |                 WaitPakin waitPakin = new WaitPakin(); | 
 |  |  |                 waitPakin.sync(mat); | 
 |  |  |                 waitPakin.setBatch(wrkDetl.getBatch()); | 
 |  |  | 
 |  |  |     private String[] GetOrderNo(String orderNo) { | 
 |  |  |         String[] s3 = orderNo.split("\""); | 
 |  |  |         String[] s = new String[(s3.length - 1) / 6]; | 
 |  |  |         if (!Cools.isEmpty(s3)){ | 
 |  |  |         if (!Cools.isEmpty(s3)) { | 
 |  |  |             int i = 0; | 
 |  |  |             int j = 0; | 
 |  |  |             for (String ss : s3) { | 
 |  |  | 
 |  |  |                 } | 
 |  |  |                 j++; | 
 |  |  |             } | 
 |  |  |         }else { | 
 |  |  |             s=null; | 
 |  |  |         } else { | 
 |  |  |             s = null; | 
 |  |  |         } | 
 |  |  |         return s; | 
 |  |  |     } | 
 |  |  | 
 |  |  |         BasDevp sourceStaNo = basDevpService.checkSiteStatus(devpNo, true); | 
 |  |  |         // 检索库位 | 
 |  |  |         LocTypeDto locTypeDto = new LocTypeDto(sourceStaNo); | 
 |  |  |         StartupDto dto = commonService.getLocNo(DEFAULT_ROW_NO_TYPE, 10, devpNo, null, locTypeDto,0); | 
 |  |  |         StartupDto dto = commonService.getLocNo(DEFAULT_ROW_NO_TYPE, 10, devpNo, null, locTypeDto, 0); | 
 |  |  |         int workNo = dto.getWorkNo(); | 
 |  |  |         // 生成工作档 | 
 |  |  |         WrkMast wrkMast = new WrkMast(); | 
 |  |  | 
 |  |  |             if (Cools.isEmpty(locMast)) { | 
 |  |  |                 throw new CoolException(locNo + "库位不存在"); | 
 |  |  |             } | 
 |  |  |             if (!locMast.getLocSts().equals("D")){ | 
 |  |  |                 throw new CoolException("所选库位存在状态不为D的库位,库位号:"+locMast.getLocNo()+" 、当前状态:"+locMast.getLocSts()+"-"+locMast.getLocSts$()); | 
 |  |  |             if (!locMast.getLocSts().equals("D")) { | 
 |  |  |                 throw new CoolException("所选库位存在状态不为D的库位,库位号:" + locMast.getLocNo() + " 、当前状态:" + locMast.getLocSts() + "-" + locMast.getLocSts$()); | 
 |  |  |             } | 
 |  |  |             // 获取源站 | 
 |  |  |             Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>() | 
 |  |  | 
 |  |  |         } | 
 |  |  |         if (!locDetlDtos.isEmpty()) { | 
 |  |  |             LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", locDetlDtos.get(0).getLocDetl().getLocNo())); | 
 |  |  |             if (locMast.getLocSts().equals("F")){ | 
 |  |  |             if (locMast.getLocSts().equals("F")) { | 
 |  |  |                 // 启动出库开始 107.盘点出库 | 
 |  |  |                 stockOut(staNo, locDetlDtos, IoWorkType.CHECK_OUT, userId); | 
 |  |  |             }else { | 
 |  |  |                 throw new CoolException("所选库位存在状态不为F的库位,库位号:"+locMast.getLocNo()+" 、当前状态:"+locMast.getLocSts()+"-"+locMast.getLocSts$()); | 
 |  |  |             } else { | 
 |  |  |                 throw new CoolException("所选库位存在状态不为F的库位,库位号:" + locMast.getLocNo() + " 、当前状态:" + locMast.getLocSts() + "-" + locMast.getLocSts$()); | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |         } else { | 
 |  |  | 
 |  |  |         if (Cools.isEmpty(loc)) { | 
 |  |  |             throw new CoolException("未找到库位"); | 
 |  |  |         } | 
 |  |  |         if (!loc.getLocSts().equals("O")||(!sourceLoc.getLocSts().equals("F") && !sourceLoc.getLocSts().equals("D"))){ | 
 |  |  |         if (!loc.getLocSts().equals("O") || (!sourceLoc.getLocSts().equals("F") && !sourceLoc.getLocSts().equals("D"))) { | 
 |  |  |             throw new CoolException("库位状态已改变"); | 
 |  |  |         } | 
 |  |  |         if (!sourceLoc.getCrnNo().equals(loc.getCrnNo())) { | 
 |  |  | 
 |  |  |                 locSts = "D"; | 
 |  |  |                 // 库位转移 ===>> D.空桶/空栈板 | 
 |  |  |             } else if (wrkMast.getIoType() == 11 || wrkMast.getIoType() == 111) { | 
 |  |  |                 if (wrkMast.getWrkSts() > 11){ | 
 |  |  |                 if (wrkMast.getWrkSts() > 11) { | 
 |  |  |                     throw new CoolException("移库任务已在执行中,不能取消"); | 
 |  |  |                 } | 
 |  |  |                 locSts = wrkMast.getFullPlt().equalsIgnoreCase("N") ? "D" : "F"; | 
 |  |  | 
 |  |  |         // 订单关联 | 
 |  |  |         List<WrkDetl> wrkDetls = wrkDetlService.selectByWrkNo(wrkMast.getWrkNo()); | 
 |  |  |         for (WrkDetl wrkDetl : wrkDetls) { | 
 |  |  |             if (!Cools.isEmpty(wrkDetl.getOrderNo())){ | 
 |  |  |             if (!Cools.isEmpty(wrkDetl.getOrderNo())) { | 
 |  |  |                 String[] orderNos = GetOrderNo(wrkDetl.getOrderNo()); | 
 |  |  |                 if (!Cools.isEmpty(orderNos) && orderNos.length!=0){ | 
 |  |  |                 if (!Cools.isEmpty(orderNos) && orderNos.length != 0) { | 
 |  |  |                     String[] anfmes = GetAnfme(wrkDetl.getOrderNo()); | 
 |  |  |                     int i = 0; | 
 |  |  |                     for (String orderNo : orderNos) { | 
 |  |  | 
 |  |  |                             } | 
 |  |  |                         } | 
 |  |  |                     } | 
 |  |  |                 }else { | 
 |  |  |                 } else { | 
 |  |  |                     if (!BaseController.isJSON(wrkDetl.getOrderNo())) { | 
 |  |  |                         if (!orderDetlService.decrease(wrkDetl.getOrderNo(), wrkDetl.getMatnr(), wrkDetl.getBatch(), wrkDetl.getAnfme())) { | 
 |  |  |                             throw new CoolException("订单数据回滚失败"); |