|  |  |  | 
|---|
|  |  |  | private SlaveProperties slaveProperties; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private WaitPakinService waitPakinService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private InventoryCheckOrderDetlService inventoryCheckOrderDetlService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | 
|---|
|  |  |  | // 检索库位 | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | //        List<String> batchs = param.getList().stream().map(FullStoreParam.MatCodeStore::getBatch).distinct().collect(Collectors.toList()); | 
|---|
|  |  |  | StartupDto dto = commonService.getLocNo(1, param.getDevpNo(), matnrs.get(0), null, null,locTypeDto); | 
|---|
|  |  |  | if (Cools.isEmpty(dto)){ | 
|---|
|  |  |  | throw new CoolException("查询库位失败!!==》startupFullPutStore ==》 commonService.getLocNo"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 生成工作号 | 
|---|
|  |  |  | int workNo = dto.getWorkNo(); | 
|---|
|  |  |  | // 生成工作档 | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!locDetlDtos.isEmpty()) { | 
|---|
|  |  |  | // 启动出库开始 101.出库 | 
|---|
|  |  |  | stockOut(staNo, locDetlDtos, null, userId); | 
|---|
|  |  |  | LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", locDetlDtos.get(0).getLocDetl().getLocNo())); | 
|---|
|  |  |  | if (locMast.getLocSts().equals("F") || locMast.getLocSts().equals("D") ){ | 
|---|
|  |  |  | // 启动出库开始 101.出库 | 
|---|
|  |  |  | stockOut(staNo, locDetlDtos, null, userId); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | throw new CoolException("所选库位存在状态不为F、D的库位,库位号:"+locMast.getLocNo()+" 、当前状态:"+locMast.getLocSts()+"-"+locMast.getLocSts$()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | throw new CoolException("库存不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | LocMast locMast = locMastService.selectById(dto.getLocNo()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Integer outSta = staNo.getDevNo(); | 
|---|
|  |  |  | //2号堆垛机全板出库站指定为204站,拣料站指定为202 | 
|---|
|  |  |  | if(locMast.getCrnNo()==2){ | 
|---|
|  |  |  | outSta = ioType == 101 ? 204 : 202; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //            //2号堆垛机全板出库站指定为204站,拣料站指定为202 | 
|---|
|  |  |  | //            if(locMast.getCrnNo()==2){ | 
|---|
|  |  |  | //                outSta = ioType == 101 ? 204 : 202; | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 获取路径 | 
|---|
|  |  |  | StaDesc staDesc = staDescService.queryCrnStn(ioType, locMast.getCrnNo(), outSta); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 生成工作档明细 | 
|---|
|  |  |  | for (LocDetlDto detlDto : dto.getLocDetlDtos()) { | 
|---|
|  |  |  | if (detlDto.getCount()==null || detlDto.getCount() <= 0.0D) {continue;} | 
|---|
|  |  |  | WrkDetl wrkDetl = new WrkDetl(); | 
|---|
|  |  |  | wrkDetl.sync(detlDto.getLocDetl()); | 
|---|
|  |  |  | wrkDetl.setOrderNo(""); // 手动出库不需要带出库存中的单据编号 | 
|---|
|  |  |  | wrkDetl.setWrkNo(workNo); | 
|---|
|  |  |  | wrkDetl.setIoTime(now); | 
|---|
|  |  |  | Double anfme = ioType==101?detlDto.getLocDetl().getAnfme():detlDto.getCount(); | 
|---|
|  |  |  | wrkDetl.setAnfme(anfme); // 数量 | 
|---|
|  |  |  | wrkDetl.setAppeTime(now); | 
|---|
|  |  |  | wrkDetl.setAppeUser(userId); | 
|---|
|  |  |  | wrkDetl.setModiTime(now); | 
|---|
|  |  |  | wrkDetl.setModiUser(userId); | 
|---|
|  |  |  | if (!wrkDetlService.insert(wrkDetl)) { | 
|---|
|  |  |  | throw new CoolException("保存工作档明细失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 修改库位状态:   F.在库 ====>>> R.出库预约/P.拣料/盘点/并板出库中 | 
|---|
|  |  |  | locMast = locMastService.selectById(dto.getLocNo()); | 
|---|
|  |  |  | if (locMast.getLocSts().equals("F")) { | 
|---|
|  |  |  | locMast.setLocSts(ioType==101?"R":"P"); | 
|---|
|  |  |  | locMast.setModiUser(userId); | 
|---|
|  |  |  | locMast.setModiTime(now); | 
|---|
|  |  |  | if (!locMastService.updateById(locMast)) { | 
|---|
|  |  |  | throw new CoolException("预约库位状态失败,库位号:"+dto.getLocNo()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | throw new CoolException(dto.getLocNo() + "库位不是在库状态"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public void inventoryCheckStockOut(BasDevp staNo, List<LocDetlDto> locDetlDtos, IoWorkType ioWorkType, Long userId,StockOutParam param) { | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  | // 合并同类项 | 
|---|
|  |  |  | Set<String> locNos = new HashSet<>(); | 
|---|
|  |  |  | List<OutLocDto> dtos = new ArrayList<>(); | 
|---|
|  |  |  | for (LocDetlDto locDetlDto : locDetlDtos) { | 
|---|
|  |  |  | String locNo = locDetlDto.getLocDetl().getLocNo(); | 
|---|
|  |  |  | if (locNos.contains(locNo)) { | 
|---|
|  |  |  | for (OutLocDto dto : dtos) { | 
|---|
|  |  |  | if (dto.getLocNo().equals(locNo)) { | 
|---|
|  |  |  | dto.getLocDetlDtos().add(locDetlDto); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | locNos.add(locNo); | 
|---|
|  |  |  | dtos.add(new OutLocDto(locNo, locDetlDto)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Integer ioType = null; | 
|---|
|  |  |  | // 生成工作档 | 
|---|
|  |  |  | for (OutLocDto dto : dtos) { | 
|---|
|  |  |  | // 判断入出库类型:101.全板出库 or 103.拣料出库 | 
|---|
|  |  |  | if (ioWorkType == null) { | 
|---|
|  |  |  | ioType = dto.isAll() ? 101 : 103; | 
|---|
|  |  |  | } else if (ioWorkType.equals(IoWorkType.CHECK_OUT)) { | 
|---|
|  |  |  | ioType = 107; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | assert ioType != null; | 
|---|
|  |  |  | // 获取库位 | 
|---|
|  |  |  | LocMast locMast = locMastService.selectById(dto.getLocNo()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Integer outSta = staNo.getDevNo(); | 
|---|
|  |  |  | //            //2号堆垛机全板出库站指定为204站,拣料站指定为202 | 
|---|
|  |  |  | //            if(locMast.getCrnNo()==2){ | 
|---|
|  |  |  | //                outSta = ioType == 101 ? 204 : 202; | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 获取路径 | 
|---|
|  |  |  | StaDesc staDesc = staDescService.queryCrnStn(ioType, locMast.getCrnNo(), outSta); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 生成工作号 | 
|---|
|  |  |  | int workNo = commonService.getWorkNo(WorkNoType.getWorkNoType(ioType)); | 
|---|
|  |  |  | // 生成工作档 | 
|---|
|  |  |  | WrkMast wrkMast = new WrkMast(); | 
|---|
|  |  |  | wrkMast.setWrkNo(workNo); | 
|---|
|  |  |  | wrkMast.setIoTime(now); | 
|---|
|  |  |  | wrkMast.setWrkSts(11L); // 工作状态:11.生成出库ID | 
|---|
|  |  |  | wrkMast.setIoType(ioType); // 入出库状态 | 
|---|
|  |  |  | wrkMast.setIoPri(13D); // 优先级:13 | 
|---|
|  |  |  | wrkMast.setCrnNo(locMast.getCrnNo()); | 
|---|
|  |  |  | wrkMast.setSourceStaNo(staDesc.getCrnStn()); // 源站 | 
|---|
|  |  |  | wrkMast.setStaNo(staDesc.getStnNo()); // 目标站 | 
|---|
|  |  |  | wrkMast.setSourceLocNo(dto.getLocNo()); // 源库位 | 
|---|
|  |  |  | wrkMast.setFullPlt("Y"); // 满板:Y | 
|---|
|  |  |  | wrkMast.setPicking("N"); // 拣料 | 
|---|
|  |  |  | wrkMast.setExitMk("N"); // 退出 | 
|---|
|  |  |  | wrkMast.setEmptyMk("N"); // 空板 | 
|---|
|  |  |  | wrkMast.setLinkMis("N"); | 
|---|
|  |  |  | wrkMast.setBarcode(locMast.getBarcode()); | 
|---|
|  |  |  | wrkMast.setAppeUser(userId); // 操作人员数据 | 
|---|
|  |  |  | wrkMast.setAppeTime(now); | 
|---|
|  |  |  | wrkMast.setModiUser(userId); | 
|---|
|  |  |  | wrkMast.setModiTime(now); | 
|---|
|  |  |  | if (ioType == 107){ | 
|---|
|  |  |  | wrkMast.setSheetNo(param.getOrderNo()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!wrkMastService.insert(wrkMast)) { | 
|---|
|  |  |  | throw new CoolException("保存工作档失败,出库库位号:"+dto.getLocNo()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 生成工作档明细 | 
|---|
|  |  |  | for (LocDetlDto detlDto : dto.getLocDetlDtos()) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | InventoryCheckOrderDetl inventoryCheckOrderDetl = new InventoryCheckOrderDetl(); | 
|---|
|  |  |  | inventoryCheckOrderDetl.setOrderNo(param.getOrderNo()); | 
|---|
|  |  |  | inventoryCheckOrderDetl.setMatnr(detlDto.getLocDetl().getMatnr()); | 
|---|
|  |  |  | inventoryCheckOrderDetl.setMaktx(detlDto.getLocDetl().getMaktx()); | 
|---|
|  |  |  | inventoryCheckOrderDetl.setBatch(detlDto.getLocDetl().getBatch()); | 
|---|
|  |  |  | inventoryCheckOrderDetl.setLocNo(detlDto.getLocDetl().getLocNo()); | 
|---|
|  |  |  | inventoryCheckOrderDetl.setArea(wrkMast.getCrnNo$()); | 
|---|
|  |  |  | inventoryCheckOrderDetl.setAnfme(detlDto.getLocDetl().getAnfme()); | 
|---|
|  |  |  | inventoryCheckOrderDetl.setIoTime(now); | 
|---|
|  |  |  | inventoryCheckOrderDetl.setStatus("1"); | 
|---|
|  |  |  | if (!inventoryCheckOrderDetlService.insert(inventoryCheckOrderDetl)) { | 
|---|
|  |  |  | throw new CoolException("保存盘点明细失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (detlDto.getCount()==null || detlDto.getCount() <= 0.0D) {continue;} | 
|---|
|  |  |  | WrkDetl wrkDetl = new WrkDetl(); | 
|---|
|  |  |  | wrkDetl.sync(detlDto.getLocDetl()); | 
|---|
|  |  |  | 
|---|
|  |  |  | throw new CoolException("保存工作档明细失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 修改订单明细 | 
|---|
|  |  |  | if (!orderDetlService.increase(orderDetl.getOrderId(), orderDetl.getMatnr(), orderDetl.getBatch(), locDto.getAnfme())) { | 
|---|
|  |  |  | if (!orderDetlService.increaseWorkQty(orderDetl.getOrderId(), orderDetl.getMatnr(), orderDetl.getBatch(), locDto.getAnfme())) { | 
|---|
|  |  |  | throw new CoolException("修改订单明细数量失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | orderService.updateSettle(orderDetl.getOrderId(), 2L, userId); | 
|---|
|  |  |  | 
|---|
|  |  |  | 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( 10, devpNo, null,null,null, locTypeDto); | 
|---|
|  |  |  | int workNo = dto.getWorkNo(); | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  | // 生成工作档 | 
|---|
|  |  |  | 
|---|
|  |  |  | LocMast locMast = locMastService.selectById(locNo); | 
|---|
|  |  |  | if (Cools.isEmpty(locMast)) { | 
|---|
|  |  |  | throw new CoolException(locNo+"库位不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!locMast.getLocSts().equals("D")){ | 
|---|
|  |  |  | throw new CoolException("所选库位存在状态不为D的库位,库位号:"+locMast.getLocNo()+" 、当前状态:"+locMast.getLocSts()+"-"+locMast.getLocSts$()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 获取源站 | 
|---|
|  |  |  | Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>() | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!locDetlDtos.isEmpty()) { | 
|---|
|  |  |  | // 启动出库开始 107.盘点出库 | 
|---|
|  |  |  | stockOut(staNo, locDetlDtos, IoWorkType.CHECK_OUT, userId); | 
|---|
|  |  |  | LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", locDetlDtos.get(0).getLocDetl().getLocNo())); | 
|---|
|  |  |  | if (locMast.getLocSts().equals("F")){ | 
|---|
|  |  |  | // 启动出库开始 107.盘点出库 | 
|---|
|  |  |  | inventoryCheckStockOut(staNo, locDetlDtos, IoWorkType.CHECK_OUT, userId,param); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | throw new CoolException("所选库位存在状态不为F的库位,库位号:"+locMast.getLocNo()+" 、当前状态:"+locMast.getLocSts()+"-"+locMast.getLocSts$()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | throw new CoolException("库位物料不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | LocMast loc = locMastService.selectById(locNo); | 
|---|
|  |  |  | if (Cools.isEmpty(loc)){ | 
|---|
|  |  |  | throw new CoolException("未找到库位"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!loc.getLocSts().equals("O") || (!sourceLoc.getLocSts().equals("F") && !sourceLoc.getLocSts().equals("D"))){ | 
|---|
|  |  |  | throw new CoolException("库位状态已改变"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!sourceLoc.getCrnNo().equals(loc.getCrnNo())) { | 
|---|
|  |  |  | throw new CoolException("移转库位属于不同堆垛机"); | 
|---|
|  |  |  | 
|---|
|  |  |  | throw new CoolException("当前工作档已完成"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 入库 + 库位转移 | 
|---|
|  |  |  | if (wrkMast.getWrkSts() < 4 || (wrkMast.getWrkSts() > 10 && wrkMast.getIoType()==11)) { | 
|---|
|  |  |  | if (wrkMast.getIoType() <100 ) { | 
|---|
|  |  |  | wrkMast.setWrkSts(4L); | 
|---|
|  |  |  | // 出库 | 
|---|
|  |  |  | } else if (wrkMast.getWrkSts() > 10) { | 
|---|
|  |  |  | } else if (wrkMast.getIoType() >100  && wrkMast.getWrkSts() > 10) { | 
|---|
|  |  |  | wrkMast.setWrkSts(14L); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  | 
|---|
|  |  |  | waitPakin.setIoStatus("N"); | 
|---|
|  |  |  | waitPakin.setLocNo(""); | 
|---|
|  |  |  | waitPakinService.update(waitPakin, new EntityWrapper<WaitPakin>() | 
|---|
|  |  |  | .eq("order_no", waitPakin.getOrderNo()) | 
|---|
|  |  |  | //                            .eq("order_no", waitPakin.getOrderNo()) | 
|---|
|  |  |  | .eq("zpallet",waitPakin.getZpallet()) | 
|---|
|  |  |  | .eq("matnr", waitPakin.getMatnr()) | 
|---|
|  |  |  | .eq("batch", waitPakin.getBatch())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | return targetLoc.getLocNo(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public void turnMatLocDetl(EmptyPlateOutParam param, Long userId) { | 
|---|
|  |  |  | Mat mat = matService.selectOne(new EntityWrapper<Mat>().eq("id", param.getMatId())); | 
|---|
|  |  |  | if (Cools.isEmpty(mat)){ | 
|---|
|  |  |  | throw new CoolException("目标库位商品编码有误!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("matnr", param.getLocDetls().get(0).getMatnr())); | 
|---|
|  |  |  | if (Cools.isEmpty(locDetls) || locDetls.size()<1){ | 
|---|
|  |  |  | throw new CoolException("待修改商品无库存,无需修改!  品号:"+param.getLocDetls().get(0).getMatnr()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | locDetlService.updateMatTurn(param.getLocDetls().get(0).getMatnr(),mat.getMatnr()); | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | throw new CoolException("对数据库修改出错!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for (LocDetl locDetl:locDetls){ | 
|---|
|  |  |  | // 保存调整记录 | 
|---|
|  |  |  | AdjDetl adjDetl = new AdjDetl(); | 
|---|
|  |  |  | adjDetl.setLocNo(locDetl.getLocNo()); | 
|---|
|  |  |  | adjDetl.setMatnr(mat.getMatnr()); | 
|---|
|  |  |  | adjDetl.setMatnrOld(param.getLocDetls().get(0).getMatnr()); | 
|---|
|  |  |  | adjDetl.setAdjQty(locDetl.getAnfme()); | 
|---|
|  |  |  | adjDetlService.save(adjDetl, userId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|