Index: ssts-invoice/src/main/java/com/forgon/disinfectsystem/invoicemanager/service/InvoiceManagerImpl.java =================================================================== diff -u -r13262 -r13331 --- ssts-invoice/src/main/java/com/forgon/disinfectsystem/invoicemanager/service/InvoiceManagerImpl.java (.../InvoiceManagerImpl.java) (revision 13262) +++ ssts-invoice/src/main/java/com/forgon/disinfectsystem/invoicemanager/service/InvoiceManagerImpl.java (.../InvoiceManagerImpl.java) (revision 13331) @@ -1660,6 +1660,7 @@ Map barcodeToDisposableGoodsBatchStockMap, String assistantSender, Set tousseInstancesToUpdate,JSONObject params) { + String sourceWarehouseName = JSONUtil.optString(params, "sourceWarehouseName", ""); if (CollectionUtils.isEmpty(invoiceItems)) { return null; } @@ -1676,61 +1677,44 @@ for (InvoiceItem invoiceItem : invoiceItems) { // 先保存invoiceItem,以后需要invoiceItemID objectDao.save(invoiceItem); + int amountAwaitingSent = invoiceItem.getAmount(); // 一次性物品 if (InvoiceItem.DIPOSABLE_YES.equals(invoiceItem.getDiposable())) { - Integer appAmount = invoiceItem.getAmount(); String barcode = invoiceItem.getBarcode(); - Integer sendOutAmount = sendOutBarcodeAmount.get(barcode); BarcodeDevice barcodeDevice = barcodeObjMap.get(invoiceItem .getBarcode()); if (!(barcodeDevice instanceof DisposableGoodsBatch)) { - continue; + throw new RuntimeException(String.format("申请单[%s]上物品[%s]的类型与条码[%s]不匹配!",invoicePlan.getSerialNumber(), invoiceItem.getTousseName(),barcode)); } DisposableGoodsBatch diposableGoodBatch = (DisposableGoodsBatch) barcodeDevice; DisposableGoodsBatchStock disposableGoodsBatchStock = barcodeToDisposableGoodsBatchStockMap.get(barcode); - String instanceName = diposableGoodBatch - .getDiposableGoods().getShowName(); - if (!instanceName.equals(invoiceItem.getTousseName()) - || sendOutAmount <= 0) { - continue; + if(disposableGoodsBatchStock == null){ + throw new RuntimeException(String.format("数据异常,物品[%s]在仓库[%s]中的批次库存[条码为 %s]不存在!", invoiceItem.getTousseName(),sourceWarehouseName,barcode)); } + // 获得价格 List identifications = disposableGoodsBatchStock .getIdentifications(); // TODO:排序问题 Collections.sort(identifications); - Integer thisBarcodeSendAmount = 0; - // 申请数量小于等于发货数量 - if (appAmount <= sendOutAmount) { - sendOutBarcodeAmount - .put(barcode, sendOutAmount - appAmount); - thisBarcodeSendAmount = appAmount; - appAmount = 0; - // 同一物品多个批次发货 - } else { - appAmount -= sendOutAmount; - thisBarcodeSendAmount = sendOutAmount; - sendOutBarcodeAmount.put(barcode, 0); - } DiposableGoodsItem diposableGoodsItem = null; // 处理同一批次多个标识号是否够减 for (IdentificationOfDisposableGoods identification : identifications) { if (identification.getAmount() <= 0) { continue; } - if (thisBarcodeSendAmount <= 0) { + if (amountAwaitingSent <= 0) { break; } - if (identification.getAmount() < thisBarcodeSendAmount) { + if (identification.getAmount() < amountAwaitingSent) { diposableGoodsItem = new DiposableGoodsItem(); - diposableGoodsItem.setAmount(Integer.parseInt("" - + identification.getAmount())); + diposableGoodsItem.setAmount(Integer.valueOf(identification.getAmount().intValue())); } else { diposableGoodsItem = new DiposableGoodsItem(); - diposableGoodsItem.setAmount(thisBarcodeSendAmount); + diposableGoodsItem.setAmount(amountAwaitingSent); } - thisBarcodeSendAmount -= diposableGoodsItem.getAmount(); + amountAwaitingSent -= diposableGoodsItem.getAmount(); BigDecimal fluctuationPrice = MathTools.mul( identification.getPrice(), floatPercent).setScale( 4, BigDecimal.ROUND_HALF_UP); @@ -1779,11 +1763,11 @@ // 器械包 } else { // 关联器械包实体 - int appAmount = invoiceItem.getAmount(); - int sentAmount = appAmount; + + int sentAmount = amountAwaitingSent; for (Entry sendOutBarcodeAmountEntry : sendOutBarcodeAmount .entrySet()) { - if (appAmount <= 0) { + if (amountAwaitingSent <= 0) { break; } String barcode = sendOutBarcodeAmountEntry.getKey(); @@ -1832,7 +1816,7 @@ } if(tousseInstanceList != null){ for (TousseInstance disinfectionTousseInstance : tousseInstanceList) { - if (appAmount <= 0) { + if (amountAwaitingSent <= 0) { break; } if(!disinfectionTousseInstance.canInvoice()){ @@ -1841,10 +1825,10 @@ itemPrice = addItemPriceToTotal(disinfectionTousseInstance.getPrice(), 1, itemPrice); totalPrice = addItemPriceToTotal(disinfectionTousseInstance.getPrice(), 1, totalPrice); tousseInstancesToUpdate.add(disinfectionTousseInstance); - appAmount--; + amountAwaitingSent--; } } - if(appAmount > 0 ){ + if(amountAwaitingSent > 0 ){ throw new RuntimeException(String.format("固定条码物品%s库存不足!", invoiceItem.getTousseName())); } sendOutBarcodeAmount.put(barcode, amountAwaitSend - sentAmount); @@ -1858,17 +1842,17 @@ totalPrice = addItemPriceToTotal(tousseInstance.getPrice(), amount, totalPrice); sendOutBarcodeAmount.put(barcode, 0); tousseInstancesToUpdate.add(tousseInstance); - appAmount--; + amountAwaitingSent--; } invoiceItem.setSettlementPrice(invoiceItem .getSettlementPrice() + itemPrice.doubleValue()); } - // 如果appAmount大于0,证明未完全发货,属于异常情况 - if(appAmount > 0){ - throw new RuntimeException(String.format("%s的库存不足,不能发货,请检查!", invoiceItem.getTousseName())); - } } + // 如果appAmount大于0,证明未完全发货,属于异常情况 + if(amountAwaitingSent > 0){ + throw new RuntimeException(String.format("%s的库存不足,不能发货,请检查!", invoiceItem.getTousseName())); + } } String personInCharge = JSONUtil.optString(params, "personInCharge", ""); String personInChargeCode = JSONUtil.optString(params, "personInChargeCode", ""); @@ -4229,9 +4213,7 @@ Entry next = iterator.next(); String barcode = next.getKey(); Integer batchAmount = next.getValue(); - if (batchAmount == 0 - || (amount <= applicationItem - .getSendOutAmount())) { + if (batchAmount == 0) { continue; } BarcodeDevice barcodeDevice = barcodeObjMap @@ -4265,6 +4247,7 @@ notSendAmount = notSendAmount - batchAmount; sendOutGoods.put(applicationGoodsName, sendOutAmount); + sendOutBarcodeAmountMap.put(barcode, batchAmount - invoiceItem.getAmount()); } } }