| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.transaction.interceptor.TransactionAspectSupport; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | |
| | | // todo 盘点记录、保存调整记录 |
| | | // 修改明细 |
| | | if (!wrkDetlService.updateAnfme(wrkDetl1.getAnfme(), wrkMast.getWrkNo(), wrkDetl.getMatnr(), |
| | | wrkDetl.getBatch())) { |
| | | wrkDetl.getSuppCode())) { |
| | | throw new CoolException(wrkMast.getWrkNo() + "盘点任务," + wrkDetl.getMatnr() + "商品," |
| | | + wrkDetl.getBatch() + "批号修改数量失败"); |
| | | + wrkDetl.getSuppCode() + "批号修改数量失败"); |
| | | } |
| | | } |
| | | iterator.remove(); |
| | |
| | | // 删除明细 |
| | | for (WrkDetl wrkDetl : wrkDetls) { |
| | | // todo 盘点记录、保存调整记录 |
| | | if (!wrkDetlService.updateAnfme(-1.0D, wrkMast.getWrkNo(), wrkDetl.getMatnr(), wrkDetl.getBatch())) { |
| | | if (!wrkDetlService.updateAnfme(-1.0D, wrkMast.getWrkNo(), wrkDetl.getMatnr(), wrkDetl.getSuppCode())) { |
| | | throw new CoolException("删除" + wrkMast.getWrkNo() + "盘点任务," + wrkDetl.getMatnr() + "商品," |
| | | + wrkDetl.getBatch() + "批号任务明细失败"); |
| | | } |
| | |
| | | generateCacheOutTask(station, locCache, userId); |
| | | |
| | | /**生成立库出库任务*/ |
| | | // generateCRNOutTask(station, locCache, userId); |
| | | generateCRNOutTask(station, locCache, userId); |
| | | |
| | | return R.ok(); |
| | | } |
| | |
| | | if (Objects.isNull(param.getBarcode())) { |
| | | throw new CoolException("托盘码不能为空!!"); |
| | | } |
| | | |
| | | if (Objects.isNull(param.getCombMats()) || param.getCombMats().isEmpty()) { |
| | | throw new CoolException("组托明细不能为空!!"); |
| | | } |
| | | // 判断是否有相同条码的数据 |
| | | if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>().eq("zpallet", param.getBarcode()) |
| | | .eq("io_status", "N")) > 0) { |
| | | throw new CoolException(param.getBarcode() + "数据正在进行入库"); |
| | | WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>() |
| | | .eq("wrk_sts", 14) |
| | | .eq("io_type", 104) |
| | | .eq("barcode", param.getBarcode())); |
| | | if (Objects.isNull(wrkMast)) { |
| | | throw new CoolException("任务档信息不存在!!"); |
| | | } |
| | | |
| | | int countLoc = locDetlService.selectCount(new EntityWrapper<LocDetl>().eq("zpallet", param.getBarcode())); |
| | | int countWrk = wrkDetlService.selectCount(new EntityWrapper<WrkDetl>().eq("zpallet", param.getBarcode())); |
| | | if (countWrk > 0 || countLoc > 0) { |
| | | WrkMast wrkDetl = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("barcode", param.getBarcode())); |
| | | if (!wrkDetl.getIoType().equals(TaskIOType.MERGE_OUT.type)) { |
| | | throw new CoolException("组托档/工作档/库存条码数据已存在===>>" + param.getBarcode()); |
| | | } |
| | | } |
| | | int countwait = waitPakinService.selectCount(new EntityWrapper<WaitPakin>().eq("zpallet", param.getBarcode())); |
| | | if (countwait > 0) { |
| | | throw new CoolException("组托档/工作档/库存条码数据已存在===>>" + param.getBarcode()); |
| | | } |
| | | |
| | | // 生成入库通知档 |
| | | List<DetlDto> detlDtos = new ArrayList<>(); |
| | | param.getCombMats().forEach(elem -> { |
| | | DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getBrand(), elem.getStandby1(), |
| | | elem.getStandby2(), elem.getStandby3(), |
| | | elem.getBoxType1(), elem.getBoxType2(), elem.getBoxType3(), elem.getAnfme(), elem.getThreeCode()); |
| | | if (DetlDto.has(detlDtos, detlDto)) { |
| | | DetlDto one = DetlDto.findDto(detlDtos, detlDto); |
| | | assert one != null; |
| | | one.setAnfme(one.getAnfme() + detlDto.getAnfme()); |
| | | } else { |
| | | detlDtos.add(detlDto); |
| | | } |
| | | }); |
| | | BasContainer container = basContainerService |
| | | .selectOne(new EntityWrapper<BasContainer>().eq("barcode", param.getBarcode())); |
| | | if (Objects.isNull(container)) { |
| | | throw new CoolException("数据错误:容器码不存在!!"); |
| | | } |
| | | if (container.getMixMax() < detlDtos.size()) { |
| | | throw new CoolException("超出容器最大混装数量,当前容器最大数量为:" + container.getMixMax() + "!!"); |
| | | } |
| | | List<Mat> tempMats = new ArrayList<>(); |
| | | for (DetlDto detlDto : detlDtos) { |
| | | Mat mat = matService.selectOne(new EntityWrapper<Mat>().eq("matnr", detlDto.getMatnr()) |
| | | .eq("supp_code", detlDto.getStandby1())); |
| | | tempMats.add(mat); |
| | | } |
| | | Set<Long> tagIds = tempMats.stream().map(Mat::getTagId).collect(Collectors.toSet()); |
| | | if (tagIds.size() > 1) { |
| | | throw new CoolException("组托物料类型不一致,只有相同的物料分类才可以组托!!"); |
| | | } |
| | | // 还可以放入多少种物料 |
| | | Double suplus = container.getMixMax(); |
| | | Date now = new Date(); |
| | | for (DetlDto detlDto : detlDtos) { |
| | | Mat mat = matService.selectByMatnr(detlDto.getMatnr()); |
| | | if (Cools.isEmpty(mat)) { |
| | | throw new CoolException(detlDto.getMatnr() + "商品档案不存在"); |
| | | } |
| | | // 最多可放数量 |
| | | Double singleMax = mat.getUpQty() * suplus; |
| | | if (singleMax.compareTo(detlDto.getAnfme()) < 0) { |
| | | throw new CoolException("物料:" + detlDto.getMatnr() + "单次组托上限为:" + mat.getUpQty() + ",当前总量超出托盘装载上限!!"); |
| | | } |
| | | BigDecimal decimal = new BigDecimal(detlDto.getAnfme() / mat.getUpQty()); |
| | | // 当前物料需要占用料箱格数 |
| | | Integer curr = decimal.setScale(0, RoundingMode.CEILING).intValue(); |
| | | suplus = suplus - curr; |
| | | if (suplus < 0) { |
| | | throw new CoolException("物料:" + detlDto.getMatnr() + ", 超出当前托盘装载上限!!"); |
| | | } |
| | | |
| | | for (CombParam.CombMat combMat : param.getCombMats()) { |
| | | BasStationDetl stationDetl = basStationDetlService.selectOne(new EntityWrapper<BasStationDetl>() |
| | | .eq("zpallet", param.getCarBarcode()) |
| | | .eq("three_code", detlDto.getThreeCode())); |
| | | .eq("three_code", combMat.getThreeCode())); |
| | | if (Objects.isNull(stationDetl)) { |
| | | throw new CoolException("明细内容不存在!!"); |
| | | } |
| | | WrkDetl wrkDetl = wrkDetlService.selectOne(new EntityWrapper<WrkDetl>() |
| | | .eq("matnr", stationDetl.getMatnr()) |
| | | .eq("wrk_no", wrkMast.getWrkNo()) |
| | | .eq("suppCode", combMat.getSuppCode())); |
| | | |
| | | Double v = Math.round((stationDetl.getAnfme() - stationDetl.getWorkQty()) * 10000) / 10000.0; |
| | | if (detlDto.getAnfme().compareTo(v) > 0) { |
| | | throw new CoolException("组托上限为:" + stationDetl.getAnfme() + ", 已组托:" + stationDetl.getWorkQty() + ", 还可组托:" + v); |
| | | } |
| | | if (Objects.isNull(wrkDetl)) { |
| | | //TODO 新插入 |
| | | Mat mat = matService.selectOne(new EntityWrapper<Mat>().eq("matnr", stationDetl.getMatnr()) |
| | | .eq("supp_code", combMat.getSuppCode())); |
| | | if (Objects.isNull(mat)) { |
| | | throw new CoolException("物料基础信息已不存在!!"); |
| | | } |
| | | WrkDetl detl = new WrkDetl(); |
| | | BeanUtils.copyProperties(stationDetl, detl); |
| | | detl.setAnfme(combMat.getAnfme()); |
| | | detl.setBarcode(wrkMast.getBarcode()); |
| | | detl.setBoxType1(combMat.getBoxType1()); |
| | | detl.setStandby1(combMat.getSuppCode()); |
| | | detl.setWrkNo(wrkMast.getWrkNo()); |
| | | |
| | | WaitPakin waitPakin = new WaitPakin(); |
| | | BeanUtils.copyProperties(mat, waitPakin); |
| | | waitPakin.setBatch(detlDto.getBatch()); |
| | | waitPakin.setType(param.getType()); |
| | | waitPakin.setZpallet(param.getBarcode()); |
| | | // 设置组托类型 |
| | | waitPakin.setType(param.getType()); |
| | | waitPakin.setIoStatus("N"); |
| | | waitPakin.setAnfme(detlDto.getAnfme()); |
| | | waitPakin.setThreeCode(detlDto.getThreeCode()); |
| | | waitPakin.setStatus("Y"); |
| | | waitPakin.setSuppCode(detlDto.getStandby1()); |
| | | waitPakin.setStandby1(detlDto.getStandby1()); |
| | | waitPakin.setStandby2(detlDto.getStandby2()); |
| | | waitPakin.setStandby3(detlDto.getStandby3()); |
| | | waitPakin.setBoxType1(detlDto.getBoxType1()); |
| | | waitPakin.setBoxType2(detlDto.getBoxType2()); |
| | | waitPakin.setBoxType3(detlDto.getBoxType3()); |
| | | waitPakin.setAppeUser(userId); |
| | | waitPakin.setAppeTime(now); |
| | | waitPakin.setModiUser(userId); |
| | | waitPakin.setModiTime(now); |
| | | if (!waitPakinService.insert(waitPakin)) { |
| | | throw new CoolException("保存入库通知档失败"); |
| | | } |
| | | |
| | | Double v1 = Math.round((stationDetl.getWorkQty() + detlDto.getAnfme()) * 10000) / 10000.0; |
| | | stationDetl.setWorkQty(v1); |
| | | |
| | | if (!basStationDetlService.updateById(stationDetl)) { |
| | | throw new CoolException("站点明细修改失败"); |
| | | } |
| | | |
| | | if (v1.compareTo(stationDetl.getAnfme()) >= 0) { |
| | | if (!basStationDetlService.deleteById(stationDetl)) { |
| | | throw new CoolException("原始数据移除失败!"); |
| | | if (!wrkDetlService.insert(detl)) { |
| | | throw new CoolException("任务明细保存失败!!"); |
| | | } |
| | | } else { |
| | | double val = Math.round((combMat.getAnfme() + wrkDetl.getAnfme()) * 10000) / 10000.0; |
| | | if (!wrkDetlService.updateAnfme(val, wrkMast.getWrkNo(), wrkDetl.getMatnr(), |
| | | wrkDetl.getSuppCode())) { |
| | | throw new CoolException(wrkMast.getWrkNo() + "盘点任务," + wrkDetl.getMatnr() + "商品," |
| | | + wrkDetl.getBatch() + "批号修改数量失败"); |
| | | } |
| | | } |
| | | |
| | | List<BasStationDetl> stas = basStationDetlService.selectList(new EntityWrapper<BasStationDetl>() |
| | | .eq("dev_no", stationDetl.getDevNo())); |
| | | if (Objects.isNull(stas) || stas.isEmpty()) { |
| | | BasStation station = basStationService.selectOne(new EntityWrapper<BasStation>().eq("dev_no", stationDetl.getDevNo())); |
| | | if (Objects.isNull(station)) { |
| | | throw new CoolException("数据错误,站点不存在!!"); |
| | | } |
| | | station.setLocSts(LocStsType.LOC_STS_TYPE_O.type); |
| | | station.setBarcode(""); |
| | | if (!basStationService.updateById(station)) { |
| | | throw new CoolException("站点状态更新失败!!"); |
| | | } |
| | | } |
| | | } |
| | | // // 判断是否有相同条码的数据 |
| | | // if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>().eq("zpallet", param.getBarcode()) |
| | | // .eq("io_status", "N")) > 0) { |
| | | // throw new CoolException(param.getBarcode() + "数据正在进行入库"); |
| | | // } |
| | | // |
| | | // int countLoc = locDetlService.selectCount(new EntityWrapper<LocDetl>().eq("zpallet", param.getBarcode())); |
| | | // int countWrk = wrkDetlService.selectCount(new EntityWrapper<WrkDetl>().eq("zpallet", param.getBarcode())); |
| | | // if (countWrk > 0 || countLoc > 0) { |
| | | // WrkMast wrkDetl = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("barcode", param.getBarcode())); |
| | | // if (!wrkDetl.getIoType().equals(TaskIOType.MERGE_OUT.type)) { |
| | | // throw new CoolException("组托档/工作档/库存条码数据已存在===>>" + param.getBarcode()); |
| | | // } |
| | | // } |
| | | // int countwait = waitPakinService.selectCount(new EntityWrapper<WaitPakin>().eq("zpallet", param.getBarcode())); |
| | | // if (countwait > 0) { |
| | | // throw new CoolException("组托档/工作档/库存条码数据已存在===>>" + param.getBarcode()); |
| | | // } |
| | | // |
| | | // // 生成入库通知档 |
| | | // List<DetlDto> detlDtos = new ArrayList<>(); |
| | | // param.getCombMats().forEach(elem -> { |
| | | // DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getBrand(), elem.getStandby1(), |
| | | // elem.getStandby2(), elem.getStandby3(), |
| | | // elem.getBoxType1(), elem.getBoxType2(), elem.getBoxType3(), elem.getAnfme(), elem.getThreeCode()); |
| | | // if (DetlDto.has(detlDtos, detlDto)) { |
| | | // DetlDto one = DetlDto.findDto(detlDtos, detlDto); |
| | | // assert one != null; |
| | | // one.setAnfme(one.getAnfme() + detlDto.getAnfme()); |
| | | // } else { |
| | | // detlDtos.add(detlDto); |
| | | // } |
| | | // }); |
| | | // BasContainer container = basContainerService |
| | | // .selectOne(new EntityWrapper<BasContainer>().eq("barcode", param.getBarcode())); |
| | | // if (Objects.isNull(container)) { |
| | | // throw new CoolException("数据错误:容器码不存在!!"); |
| | | // } |
| | | // if (container.getMixMax() < detlDtos.size()) { |
| | | // throw new CoolException("超出容器最大混装数量,当前容器最大数量为:" + container.getMixMax() + "!!"); |
| | | // } |
| | | // List<Mat> tempMats = new ArrayList<>(); |
| | | // for (DetlDto detlDto : detlDtos) { |
| | | // Mat mat = matService.selectOne(new EntityWrapper<Mat>().eq("matnr", detlDto.getMatnr()) |
| | | // .eq("supp_code", detlDto.getStandby1())); |
| | | // tempMats.add(mat); |
| | | // } |
| | | // Set<Long> tagIds = tempMats.stream().map(Mat::getTagId).collect(Collectors.toSet()); |
| | | // if (tagIds.size() > 1) { |
| | | // throw new CoolException("组托物料类型不一致,只有相同的物料分类才可以组托!!"); |
| | | // } |
| | | // // 还可以放入多少种物料 |
| | | // Double suplus = container.getMixMax(); |
| | | // Date now = new Date(); |
| | | // for (DetlDto detlDto : detlDtos) { |
| | | // Mat mat = matService.selectByMatnr(detlDto.getMatnr()); |
| | | // if (Cools.isEmpty(mat)) { |
| | | // throw new CoolException(detlDto.getMatnr() + "商品档案不存在"); |
| | | // } |
| | | // // 最多可放数量 |
| | | // Double singleMax = mat.getUpQty() * suplus; |
| | | // if (singleMax.compareTo(detlDto.getAnfme()) < 0) { |
| | | // throw new CoolException("物料:" + detlDto.getMatnr() + "单次组托上限为:" + mat.getUpQty() + ",当前总量超出托盘装载上限!!"); |
| | | // } |
| | | // BigDecimal decimal = new BigDecimal(detlDto.getAnfme() / mat.getUpQty()); |
| | | // // 当前物料需要占用料箱格数 |
| | | // Integer curr = decimal.setScale(0, RoundingMode.CEILING).intValue(); |
| | | // suplus = suplus - curr; |
| | | // if (suplus < 0) { |
| | | // throw new CoolException("物料:" + detlDto.getMatnr() + ", 超出当前托盘装载上限!!"); |
| | | // } |
| | | // |
| | | // BasStationDetl stationDetl = basStationDetlService.selectOne(new EntityWrapper<BasStationDetl>() |
| | | // .eq("zpallet", param.getCarBarcode()) |
| | | // .eq("three_code", detlDto.getThreeCode())); |
| | | // if (Objects.isNull(stationDetl)) { |
| | | // throw new CoolException("明细内容不存在!!"); |
| | | // } |
| | | // |
| | | // Double v = Math.round((stationDetl.getAnfme() - stationDetl.getWorkQty()) * 10000) / 10000.0; |
| | | // if (detlDto.getAnfme().compareTo(v) > 0) { |
| | | // throw new CoolException("组托上限为:" + stationDetl.getAnfme() + ", 已组托:" + stationDetl.getWorkQty() + ", 还可组托:" + v); |
| | | // } |
| | | // |
| | | // WaitPakin waitPakin = new WaitPakin(); |
| | | // BeanUtils.copyProperties(mat, waitPakin); |
| | | // waitPakin.setBatch(detlDto.getBatch()); |
| | | // waitPakin.setType(param.getType()); |
| | | // waitPakin.setZpallet(param.getBarcode()); |
| | | // // 设置组托类型 |
| | | // waitPakin.setType(param.getType()); |
| | | // waitPakin.setIoStatus("N"); |
| | | // waitPakin.setAnfme(detlDto.getAnfme()); |
| | | // waitPakin.setThreeCode(detlDto.getThreeCode()); |
| | | // waitPakin.setStatus("Y"); |
| | | // waitPakin.setSuppCode(detlDto.getStandby1()); |
| | | // waitPakin.setStandby1(detlDto.getStandby1()); |
| | | // waitPakin.setStandby2(detlDto.getStandby2()); |
| | | // waitPakin.setStandby3(detlDto.getStandby3()); |
| | | // waitPakin.setBoxType1(detlDto.getBoxType1()); |
| | | // waitPakin.setBoxType2(detlDto.getBoxType2()); |
| | | // waitPakin.setBoxType3(detlDto.getBoxType3()); |
| | | // waitPakin.setAppeUser(userId); |
| | | // waitPakin.setAppeTime(now); |
| | | // waitPakin.setModiUser(userId); |
| | | // waitPakin.setModiTime(now); |
| | | // if (!waitPakinService.insert(waitPakin)) { |
| | | // throw new CoolException("保存入库通知档失败"); |
| | | // } |
| | | // |
| | | // Double v1 = Math.round((stationDetl.getWorkQty() + detlDto.getAnfme()) * 10000) / 10000.0; |
| | | // stationDetl.setWorkQty(v1); |
| | | // |
| | | // if (!basStationDetlService.updateById(stationDetl)) { |
| | | // throw new CoolException("站点明细修改失败"); |
| | | // } |
| | | // |
| | | // if (v1.compareTo(stationDetl.getAnfme()) >= 0) { |
| | | // if (!basStationDetlService.deleteById(stationDetl)) { |
| | | // throw new CoolException("原始数据移除失败!"); |
| | | // } |
| | | // } |
| | | // |
| | | // List<BasStationDetl> stas = basStationDetlService.selectList(new EntityWrapper<BasStationDetl>() |
| | | // .eq("dev_no", stationDetl.getDevNo())); |
| | | // if (Objects.isNull(stas) || stas.isEmpty()) { |
| | | // BasStation station = basStationService.selectOne(new EntityWrapper<BasStation>().eq("dev_no", stationDetl.getDevNo())); |
| | | // if (Objects.isNull(station)) { |
| | | // throw new CoolException("数据错误,站点不存在!!"); |
| | | // } |
| | | // station.setLocSts(LocStsType.LOC_STS_TYPE_O.type); |
| | | // station.setBarcode(""); |
| | | // if (!basStationService.updateById(station)) { |
| | | // throw new CoolException("站点状态更新失败!!"); |
| | | // } |
| | | // } |
| | | // } |
| | | } |
| | | |
| | | /** |
| | |
| | | if (!Objects.isNull(mast)) { |
| | | if (mast.getIoType().equals(TaskIOType.MERGE_OUT.type) || mast.getIoType().equals(TaskIOType.PICK_OUT.type) || mast.getIoType().equals(TaskIOType.CHECK_OUT.type)) { |
| | | int ioType = mast.getIoType() - 50; |
| | | |
| | | List<WrkDetl> wrkDetls103 = wrkDetlService |
| | | .selectList(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkMast.getWrkNo())); |
| | | if (wrkDetls103.isEmpty()) { |
| | | ioType = 10; |
| | | } |
| | | List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", wrkMast.getSourceLocNo())); |
| | | if (!Objects.isNull(locDetls) && !locDetls.isEmpty()) { |
| | | Double sum = wrkDetls103.stream().mapToDouble(WrkDetl::getAnfme).sum(); |
| | | Double summed = locDetls.stream().mapToDouble(LocDetl::getAnfme).sum(); |
| | | if (summed.compareTo(sum) <= 0) { |
| | | ioType = 10; |
| | | } |
| | | } |
| | | mast.setIoType(ioType); |
| | | mast.setWrkSts(2L); |
| | | mast.setSourceStaNo(mast.getSourceStaNo()); |
| | |
| | | // 生成工作号 |
| | | int workNo = commonService.getWorkNo(WorkNoType.getWorkNoType(ioType)); |
| | | if (Cools.isEmpty(wrkMast1)) { |
| | | Integer outSta = devp.getDevNo(); |
| | | // Integer outSta = devp.getDevNo(); |
| | | // 获取路径 |
| | | StaDesc staDesc = staDescService.queryCrnStn(ioType, locMast.getCrnNo(), outSta); |
| | | // StaDesc staDesc = staDescService.queryCrnStn(ioType, locMast.getCrnNo(), outSta); |
| | | |
| | | // 生成工作档 |
| | | WrkMast wrkMast = new WrkMast(); |
| | |
| | | wrkMast.setIoType(ioType); // 入出库类型 |
| | | wrkMast.setIoPri(13D); // 优先级:13 |
| | | wrkMast.setCrnNo(locMast.getCrnNo()); |
| | | wrkMast.setSourceStaNo(staDesc.getCrnStn() + ""); // 源站 |
| | | wrkMast.setStaNo(staDesc.getStnNo() + ""); // 目标站 |
| | | // wrkMast.setSourceStaNo(staDesc.getCrnStn() + ""); // 源站 |
| | | // wrkMast.setStaNo(staDesc.getStnNo() + ""); // 目标站 |
| | | wrkMast.setSourceLocNo(locMast.getLocNo()); // 源库位 |
| | | //小松项目,缓存出库AGV站点,用于清空缓存区库存 |
| | | wrkMast.setPauseMk(station.getDevNo()); |