Index: ssts-basedata/src/main/java/com/forgon/disinfectsystem/invoice/service/SubmitInvoiceContext.java =================================================================== diff -u -r25121 -r25141 --- ssts-basedata/src/main/java/com/forgon/disinfectsystem/invoice/service/SubmitInvoiceContext.java (.../SubmitInvoiceContext.java) (revision 25121) +++ ssts-basedata/src/main/java/com/forgon/disinfectsystem/invoice/service/SubmitInvoiceContext.java (.../SubmitInvoiceContext.java) (revision 25141) @@ -364,6 +364,13 @@ return targetIdToWareHouseMap; } + public String getTargetWareHouseId() { + if(targetWareHouse != null){ + return targetWareHouse.getId().toString(); + } + return null; + } + public WareHouse getTargetWareHouse() { return targetWareHouse; } Index: ssts-diposablegoods/src/main/java/com/forgon/disinfectsystem/diposablegoods/service/DiposableGoodsManagerImpl.java =================================================================== diff -u -r25121 -r25141 --- ssts-diposablegoods/src/main/java/com/forgon/disinfectsystem/diposablegoods/service/DiposableGoodsManagerImpl.java (.../DiposableGoodsManagerImpl.java) (revision 25121) +++ ssts-diposablegoods/src/main/java/com/forgon/disinfectsystem/diposablegoods/service/DiposableGoodsManagerImpl.java (.../DiposableGoodsManagerImpl.java) (revision 25141) @@ -41,6 +41,8 @@ import com.forgon.attachfile.service.AttachFileManager; import com.forgon.databaseadapter.service.DateQueryAdapter; +import com.forgon.db.async.adder.model.DGBatchStockAmountAdder; +import com.forgon.db.async.adder.model.DGStockAmountAdder; import com.forgon.directory.acegi.tools.AcegiHelper; import com.forgon.directory.model.BarcodeDevice; import com.forgon.directory.model.OrgUnit; @@ -2620,19 +2622,90 @@ } return expensiveDiposablegoodsList; } - @Override + public void addAutoDeductionDisposableGoods(DisposableGoodsServiceContext disposableGoodsServiceContext,Set disposableGoodsIDsSet){ + String warehouseId = disposableGoodsServiceContext.getWarehouseId(); + if(StringUtils.isBlank(warehouseId)){ + throw new RuntimeException("仓库id不能为空!"); + } + + Set disposableGoodsBatchIDsSet = new HashSet(); + Map idToDiposableGoodsMap = disposableGoodsServiceContext.getIdToDisposableGoodsMap(); + Map barcodeToDisposableGoodsMap = disposableGoodsServiceContext.getBarcodeToDisposableGoodsMap(); + Map disposableGoodsIDToDisposableGoodsStockMap = disposableGoodsServiceContext.getDisposableGoodsIDToDisposableGoodsStockMap(); + Map idToDisposableGoodsStockMap = disposableGoodsServiceContext.getIdToDisposableGoodsStockMap(); + Map idToDisposableGoodsBatchMap = disposableGoodsServiceContext.getIdToDisposableGoodsBatchMap(); + Map barcodeToDisposableGoodsBatchMap = disposableGoodsServiceContext.getBarcodeToDisposableGoodsBatchMap(); + Map idToDisposableGoodsBatchStockMap = disposableGoodsServiceContext.getIdToDisposableGoodsBatchStockMap(); + Map barcodeToDisposableGoodsBatchStockMap = disposableGoodsServiceContext.getBarcodeToDisposableGoodsBatchStockMap(); + Map idToIdentificationMap = disposableGoodsServiceContext.getIdToIdentificationMap(); + + // 锁定一次性物品 + List disposableGoodsList = getDisposableGoodsByDisposableGoodsIDs_ForUpdate(disposableGoodsIDsSet); + if (disposableGoodsList == null + || disposableGoodsList.size() != disposableGoodsIDsSet.size()) { + throw new RuntimeException("某些物品已被删除!"); + } + for (DisposableGoods disposableGoods : disposableGoodsList) { + idToDiposableGoodsMap.put(disposableGoods.getId(), disposableGoods); + if(StringUtils.isNotBlank(disposableGoods.getBarcode())){ + barcodeToDisposableGoodsMap.put(disposableGoods.getBarcode(), disposableGoods); + } + } + disposableGoodsServiceContext.getDisposableGoodsIdsSet().addAll(disposableGoodsIDsSet); + // 发货自动扣减库存,根据物品定义id和仓库来获取物品库存 + Date validUntil = new Date(); + String validUntilSql = " " + + dateQueryAdapter.dateConverAdapter2(com.forgon.Constants.SIMPLEDATEFORMAT_YYYYMMDDHHMMSS.format(validUntil), + "yyyy-mm-dd HH24:MI:SS"); + + String validUntilStr = String.format(" ( %s > %s) ", "b.expDate", validUntilSql); + String queryString = String + .format("select distinct po from %s po inner join fetch po.goodsBatchs b inner join fetch b.identifications i where %s and i.amount>0 and po.warehouseID=%s and (%s) ", + DisposableGoodsStock.class.getSimpleName(),validUntilStr,warehouseId,SqlUtils.getStringFieldInLargeCollectionsPredicate("po.disposableGoodsID", disposableGoodsIDsSet)); + List disposableGoodsStockList = objectDao.findByHql(queryString); + + addDisposableGoodsStocks(disposableGoodsBatchIDsSet, + disposableGoodsIDToDisposableGoodsStockMap, + idToDisposableGoodsStockMap, + idToDisposableGoodsBatchStockMap, + barcodeToDisposableGoodsBatchStockMap, + idToIdentificationMap, disposableGoodsStockList); + Set oldDisposableGoodsBatchIDsSet = disposableGoodsServiceContext.getDisposableGoodsBatchIdsSet(); + + disposableGoodsBatchIDsSet.removeAll(oldDisposableGoodsBatchIDsSet); + oldDisposableGoodsBatchIDsSet.addAll(disposableGoodsBatchIDsSet); + if(!disposableGoodsBatchIDsSet.isEmpty()){ + String getDisposableGoodsBatchSql = String.format(" where %s ", + SqlUtils.getNonStringFieldInLargeCollectionsPredicate("po.id", disposableGoodsBatchIDsSet)); + List disposableGoodsBatchs = objectDao.findBySql(DisposableGoodsBatch.class.getSimpleName(), getDisposableGoodsBatchSql); + if (disposableGoodsBatchs == null + || disposableGoodsBatchs.size() != disposableGoodsBatchIDsSet + .size()) { + throw new RuntimeException("某些批次定义已被删除!"); + } + if (disposableGoodsBatchs != null) { + for (DisposableGoodsBatch disposableGoodsBatch : disposableGoodsBatchs) { + idToDisposableGoodsBatchMap.put(disposableGoodsBatch.getId(), disposableGoodsBatch); + barcodeToDisposableGoodsBatchMap.put(disposableGoodsBatch.getBarcode(), disposableGoodsBatch); + } + } + } + } + @Override public void lockAndGetDisposableGoodsResources( DisposableGoodsServiceContext disposableGoodsServiceContext) { disposableGoodsServiceContext.validateParams(); String warehouseId = disposableGoodsServiceContext.getWarehouseId(); + String targetWarehouseId = disposableGoodsServiceContext.getTargetWarehouseId(); Set disposableGoodsIDsSet = disposableGoodsServiceContext.getDisposableGoodsIdsSet(); Set diposableGoodsStockIDsSet = disposableGoodsServiceContext.getDisposableGoodsStockIdsSet(); Set expensiveDisposablegoodsIdsSet = disposableGoodsServiceContext.getExpensiveDisposableGoodsIdsSet(); Set disposableGoodsBatchIDsSet = disposableGoodsServiceContext.getDisposableGoodsBatchIdsSet(); Set disposableGoodsBatchStockIDsSet = disposableGoodsServiceContext.getDisposableGoodsBatchStockIdsSet(); Set identificationIdsSet = disposableGoodsServiceContext.getIdentificationIdsSet(); Map idToDiposableGoodsMap = disposableGoodsServiceContext.getIdToDisposableGoodsMap(); + Map barcodeToDisposableGoodsMap = disposableGoodsServiceContext.getBarcodeToDisposableGoodsMap(); Map disposableGoodsIDToDisposableGoodsStockMap = disposableGoodsServiceContext.getDisposableGoodsIDToDisposableGoodsStockMap(); Map idToDisposableGoodsStockMap = disposableGoodsServiceContext.getIdToDisposableGoodsStockMap(); Map idToExpensiveDisposablegoodsMap = disposableGoodsServiceContext.getIdToExpensiveDisposableGoodsMap(); @@ -2651,10 +2724,16 @@ } for (DisposableGoods disposableGoods : disposableGoodsList) { idToDiposableGoodsMap.put(disposableGoods.getId(), disposableGoods); + if(StringUtils.isNotBlank(disposableGoods.getBarcode())){ + barcodeToDisposableGoodsMap.put(disposableGoods.getBarcode(), disposableGoods); + } } // 获取物品库存 List disposableGoodsStockList = null; - if(disposableGoodsServiceContext.sceneInvoiceAutoDeduction()){ + if(disposableGoodsServiceContext.sceneInvoice()){ + if(StringUtils.isBlank(warehouseId)){ + throw new RuntimeException("仓库id不能为空!"); + } // 发货自动扣减库存,根据物品定义id和仓库来获取物品库存 Date validUntil = new Date(); String validUntilSql = " " @@ -2666,6 +2745,13 @@ .format("select distinct po from %s po inner join fetch po.goodsBatchs b inner join fetch b.identifications i where %s and i.amount>0 and po.warehouseID=%s and (%s) ", DisposableGoodsStock.class.getSimpleName(),validUntilStr,warehouseId,SqlUtils.getStringFieldInLargeCollectionsPredicate("po.disposableGoodsID", disposableGoodsIDsSet)); disposableGoodsStockList = objectDao.findByHql(queryString); + + addDisposableGoodsStocks(disposableGoodsBatchIDsSet, + disposableGoodsIDToDisposableGoodsStockMap, + idToDisposableGoodsStockMap, + idToDisposableGoodsBatchStockMap, + barcodeToDisposableGoodsBatchStockMap, + idToIdentificationMap, disposableGoodsStockList); }else{ if (!diposableGoodsStockIDsSet.isEmpty()) { disposableGoodsStockList = getDisposableGoodsStockByDisposableGoodsStockIDs(diposableGoodsStockIDsSet); @@ -2676,6 +2762,22 @@ } } } + // 获取目标仓库库存 +// if(disposableGoodsServiceContext.sceneInvoice() || disposableGoodsServiceContext.sceneInvoiceAutoDeduction()){ +// if(StringUtils.isBlank(targetWarehouseId)){ +// throw new RuntimeException("目标仓库id不能为空!"); +// } +// String queryString = String +// .format("select distinct po from %s po inner join fetch po.goodsBatchs b inner join fetch b.identifications i where i.amount>0 and po.warehouseID=%s and (%s) ", +// DisposableGoodsStock.class.getSimpleName(),targetWarehouseId,SqlUtils.getStringFieldInLargeCollectionsPredicate("po.disposableGoodsID", disposableGoodsIDsSet)); +// List targetDisposableGoodsStockList = objectDao.findByHql(queryString); +// addDisposableGoodsStocks(disposableGoodsBatchIDsSet, +// disposableGoodsIDToDisposableGoodsStockMap, +// idToDisposableGoodsStockMap, +// idToDisposableGoodsBatchStockMap, +// barcodeToDisposableGoodsBatchStockMap, +// idToIdentificationMap, targetDisposableGoodsStockList); +// } // 设置物品库存到map if(disposableGoodsStockList != null){ disposableGoodsServiceContext.setDisposableGoodsStockList(disposableGoodsStockList); @@ -2758,6 +2860,48 @@ } } } + + /** + * @param disposableGoodsBatchIDsSet + * @param disposableGoodsIDToDisposableGoodsStockMap + * @param idToDisposableGoodsStockMap + * @param idToDisposableGoodsBatchStockMap + * @param barcodeToDisposableGoodsBatchStockMap + * @param idToIdentificationMap + * @param targetDisposableGoodsStockList + */ + private void addDisposableGoodsStocks( + Set disposableGoodsBatchIDsSet, + Map disposableGoodsIDToDisposableGoodsStockMap, + Map idToDisposableGoodsStockMap, + Map idToDisposableGoodsBatchStockMap, + Map barcodeToDisposableGoodsBatchStockMap, + Map idToIdentificationMap, + List targetDisposableGoodsStockList) { + if(CollectionUtils.isNotEmpty(targetDisposableGoodsStockList) ){ + for (DisposableGoodsStock disposableGoodsStock : targetDisposableGoodsStockList) { + idToDisposableGoodsStockMap.put(disposableGoodsStock.getId(), disposableGoodsStock); + disposableGoodsIDToDisposableGoodsStockMap.put(disposableGoodsStock.getDisposableGoodsID(), disposableGoodsStock); + + Set goodsBatchs = disposableGoodsStock.getGoodsBatchs(); + if(CollectionUtils.isNotEmpty(goodsBatchs)){ + for (DisposableGoodsBatchStock disposableGoodsBatchStock : goodsBatchs) { + idToDisposableGoodsBatchStockMap.put(disposableGoodsBatchStock.getId(), disposableGoodsBatchStock); + barcodeToDisposableGoodsBatchStockMap.put(disposableGoodsBatchStock.getBarcode(), disposableGoodsBatchStock); + disposableGoodsBatchIDsSet.add(disposableGoodsBatchStock.getDisposableGoodsBatchId()); + + List identifications = disposableGoodsBatchStock.getIdentifications(); + if(CollectionUtils.isNotEmpty(identifications)){ + for (DisposableGoodsIdentification disposableGoodsIdentification : identifications) { + idToIdentificationMap.put(disposableGoodsIdentification.getId(), disposableGoodsIdentification); + } + } + } + } + + } + } + } @Override public void loadStockAndIdentification(Long wareHouseId, DisposableGoodsServiceContext disposableGoodsServiceContext){ @@ -3039,4 +3183,29 @@ public void adjustAmount(DisposableGoodsIdentification identification,long amountChange){ identificationOfDiposableGoodsManager.adjustAmount(identification, amountChange); } + + public void waitAsyncAdditionComplete(){ + while(true){ + int count = objectDao.countObject(DGBatchStockAmountAdder.class.getSimpleName()); + if(count == 0){ + break; + } + try { + Thread.sleep(30); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + while(true){ + int count = objectDao.countObject(DGStockAmountAdder.class.getSimpleName()); + if(count == 0){ + break; + } + try { + Thread.sleep(30); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } } Index: ssts-invoice/src/main/java/com/forgon/disinfectsystem/invoicemanager/service/InvoiceManagerImpl.java =================================================================== diff -u -r25121 -r25141 --- ssts-invoice/src/main/java/com/forgon/disinfectsystem/invoicemanager/service/InvoiceManagerImpl.java (.../InvoiceManagerImpl.java) (revision 25121) +++ ssts-invoice/src/main/java/com/forgon/disinfectsystem/invoicemanager/service/InvoiceManagerImpl.java (.../InvoiceManagerImpl.java) (revision 25141) @@ -1288,7 +1288,7 @@ JSONObject jsonInvoiceItem, String tousseType) { String diposable = JSONUtil.optString(jsonInvoiceItem, "diposable", DisposableGoods.CONSTANT_NO); // 类型相关的处理 - if(StringUtils.equals(diposable,Constants.STR_YES) && (StringUtils.equals(tousseType,DisposableGoods.TYPE_NAME) || StringUtils.equals(tousseType,DisposableGoods.TYPE_EXPENSIVEDIPOSABLEGOODS))){ + if(StringUtils.equals(diposable,Constants.STR_YES) && (StringUtils.equals(tousseType,DisposableGoods.TYPE_NAME) || StringUtils.equals(tousseType,DisposableGoods.TYPE_NAME_DEFINITION) ||StringUtils.equals(tousseType,DisposableGoods.TYPE_EXPENSIVEDIPOSABLEGOODS))){ String typeInfoOnScanned = JSONUtil.optString(jsonInvoiceItem, "typeInfoOnScanned", null); if(typeInfoOnScanned == null){ throw new RuntimeException("缺少类型参数!"); @@ -1305,16 +1305,25 @@ if(disposableGoodsStockId == null){ throw new RuntimeException("缺少物品库存id参数!"); } - if(disposableGoodsBatchId == null){ - throw new RuntimeException("缺少物品批次定义id参数!"); + + if(!StringUtils.equals(tousseType,DisposableGoods.TYPE_NAME_DEFINITION)){ + if(disposableGoodsBatchId == null){ + throw new RuntimeException("缺少物品批次定义id参数!"); + } + if(disposableGoodsBatchStockId == null){ + throw new RuntimeException("缺少物品批次库存id参数!"); + } } - if(disposableGoodsBatchStockId == null){ - throw new RuntimeException("缺少物品批次库存id参数!"); - } + disposableGoodsServiceContext.getDisposableGoodsIdsSet().add(disposableGoodsId); + if(disposableGoodsBatchId != null){ + disposableGoodsServiceContext.getDisposableGoodsBatchIdsSet().add(disposableGoodsBatchId); + } disposableGoodsServiceContext.getDisposableGoodsStockIdsSet().add(disposableGoodsStockId); - disposableGoodsServiceContext.getDisposableGoodsBatchIdsSet().add(disposableGoodsBatchId); - disposableGoodsServiceContext.getDisposableGoodsBatchStockIdsSet().add(disposableGoodsBatchStockId); + if(disposableGoodsBatchStockId != null){ + disposableGoodsServiceContext.getDisposableGoodsBatchStockIdsSet().add(disposableGoodsBatchStockId); + } + if(StringUtils.equals(tousseType,DisposableGoods.TYPE_EXPENSIVEDIPOSABLEGOODS)){ Long expensiveDisposablegoodsId = JSONUtil.optLong(typeInfoOnScannedObj, "expensiveDisposablegoodsId", null); if(expensiveDisposablegoodsId == null){ @@ -1455,6 +1464,7 @@ Map barcodeObjMap = submitInvoiceContext.getBarcodeToBarcodeDeviceMap(); DisposableGoodsServiceContext disposableGoodsServiceContext = submitInvoiceContext.getDisposableGoodsServiceContext(); ExpensiveGoodsServiceContext expensiveGoodsServiceContext = submitInvoiceContext.getExpensiveGoodsServiceContext(); + Map barcodeToDisposableGoodsMap = disposableGoodsServiceContext.getBarcodeToDisposableGoodsMap(); Map barcodeToExpensiveDisposablegoodsMap = disposableGoodsServiceContext.getBarcodeToExpensiveDisposablegoodsMap(); Map barcodeToExpensiveGoodsInstanceMap = expensiveGoodsServiceContext.getBarcodeToExpensiveGoodsInstanceMap(); Map barcodeDiposableGoodBatchMap = disposableGoodsServiceContext.getBarcodeToDisposableGoodsBatchMap(); @@ -1487,6 +1497,9 @@ barcodeDevice = barcodeToExpensiveGoodsInstanceMap.get(barcode); } if(barcodeDevice == null){ + barcodeDevice = barcodeToDisposableGoodsMap.get(barcode); + } + if(barcodeDevice == null){ throw new RuntimeException("条码" +barcode+ "已不存在!"); } @@ -1835,6 +1848,9 @@ SubmitInvoiceContext submitInvoiceContext) { String sourceWarehouseId = submitInvoiceContext.getSourceWarehouseId(); DisposableGoodsServiceContext disposableGoodsServiceContext = submitInvoiceContext.getDisposableGoodsServiceContext(); + disposableGoodsServiceContext.setScene(DisposableGoodsServiceContext.SCENE_INVOICE); + disposableGoodsServiceContext.setWarehouseId(submitInvoiceContext.getSourceWarehouseId()); + disposableGoodsServiceContext.setTargetWarehouseId(submitInvoiceContext.getTargetWareHouseId()); diposableGoodsManager.lockAndGetDisposableGoodsResources(disposableGoodsServiceContext); // 校验仓库 List expensiveDisposablegoodsList = disposableGoodsServiceContext.getExpensiveDisposablegoodsList(); @@ -2546,12 +2562,7 @@ // 锁定库存记录 lockGoodsStocks(submitInvoiceContext); // 自动扣减的一次性物品id - Set disposableGoodsIds = TousseInstanceUtils.getDisposableGoodsIds(objectDao, submitInvoiceContext.getScannedTousseInstances()); - DisposableGoodsServiceContext autoDeductionDisposableGoodsServiceContext = submitInvoiceContext.getAutoDeductionDisposableGoodsServiceContext(); - autoDeductionDisposableGoodsServiceContext.setScene(DisposableGoodsServiceContext.SCENE_INVOICE_AUTO_DEDUCTION); - autoDeductionDisposableGoodsServiceContext.setWarehouseId(submitInvoiceContext.getSourceWarehouseId()); - autoDeductionDisposableGoodsServiceContext.getDisposableGoodsIdsSet().addAll(disposableGoodsIds); - diposableGoodsManager.lockAndGetDisposableGoodsResources(autoDeductionDisposableGoodsServiceContext); + addAutoDeductionAndTargetDisposableGoods(submitInvoiceContext); // 统计发货数据 summarySendOutInfo(submitInvoiceItems, submitInvoiceContext); @@ -2839,12 +2850,7 @@ // 锁定库存记录 lockGoodsStocks(submitInvoiceContext); // 自动扣减的一次性物品id - Set disposableGoodsIds = TousseInstanceUtils.getDisposableGoodsIds(objectDao, submitInvoiceContext.getScannedTousseInstances()); - DisposableGoodsServiceContext autoDeductionDisposableGoodsServiceContext = submitInvoiceContext.getAutoDeductionDisposableGoodsServiceContext(); - autoDeductionDisposableGoodsServiceContext.setScene(DisposableGoodsServiceContext.SCENE_INVOICE_AUTO_DEDUCTION); - autoDeductionDisposableGoodsServiceContext.setWarehouseId(submitInvoiceContext.getSourceWarehouseId()); - autoDeductionDisposableGoodsServiceContext.getDisposableGoodsIdsSet().addAll(disposableGoodsIds); - diposableGoodsManager.lockAndGetDisposableGoodsResources(autoDeductionDisposableGoodsServiceContext); + addAutoDeductionAndTargetDisposableGoods(submitInvoiceContext); // 统计发货数据 summarySendOutInfo(submitInvoiceItems, submitInvoiceContext); @@ -2875,7 +2881,9 @@ //回写接口调用 writebackForWriteBackInventoryDao(Collections.singletonList(invoice) , disposableGoodsStorageAdjustVoTotalList); -// throw new RuntimeException("发货速度测试!"); +// if(true){ +// throw new RuntimeException("发货速度测试!"); +// } return submitInvoiceContext; } @@ -2981,18 +2989,13 @@ loadTargetWareHouse(submitInvoiceContext); // 锁定一次性物品 lockDiposableGoods2(submitInvoiceContext); - addSupplyRoomDisposableGoodsInfo(submitInvoiceContext); + // 锁定高值耗材 lockExpensiveGoods(submitInvoiceContext); // 锁定库存记录 lockGoodsStocks(submitInvoiceContext); // 自动扣减的一次性物品id - Set disposableGoodsIds = TousseInstanceUtils.getDisposableGoodsIds(objectDao, submitInvoiceContext.getScannedTousseInstances()); - DisposableGoodsServiceContext autoDeductionDisposableGoodsServiceContext = submitInvoiceContext.getAutoDeductionDisposableGoodsServiceContext(); - autoDeductionDisposableGoodsServiceContext.setScene(DisposableGoodsServiceContext.SCENE_INVOICE_AUTO_DEDUCTION); - autoDeductionDisposableGoodsServiceContext.setWarehouseId(submitInvoiceContext.getSourceWarehouseId()); - autoDeductionDisposableGoodsServiceContext.getDisposableGoodsIdsSet().addAll(disposableGoodsIds); - diposableGoodsManager.lockAndGetDisposableGoodsResources(autoDeductionDisposableGoodsServiceContext); + addAutoDeductionAndTargetDisposableGoods(submitInvoiceContext); // 统计发货数据 summarySendOutInfo(submitInvoiceItems, submitInvoiceContext); @@ -3068,22 +3071,39 @@ return submitInvoiceContext; } + + /** + * @param submitInvoiceContext + */ + private void addAutoDeductionAndTargetDisposableGoods(SubmitInvoiceContext submitInvoiceContext) { + Set disposableGoodsIds = TousseInstanceUtils.getDisposableGoodsIds(objectDao, submitInvoiceContext.getScannedTousseInstances()); +// DisposableGoodsServiceContext autoDeductionDisposableGoodsServiceContext = submitInvoiceContext.getAutoDeductionDisposableGoodsServiceContext(); +// autoDeductionDisposableGoodsServiceContext.setScene(DisposableGoodsServiceContext.SCENE_INVOICE_AUTO_DEDUCTION); +// autoDeductionDisposableGoodsServiceContext.setWarehouseId(submitInvoiceContext.getSourceWarehouseId()); +// autoDeductionDisposableGoodsServiceContext.getDisposableGoodsIdsSet().addAll(disposableGoodsIds); +// diposableGoodsManager.lockAndGetDisposableGoodsResources(autoDeductionDisposableGoodsServiceContext); + submitInvoiceContext.getDisposableGoodsServiceContext().setWarehouseId(submitInvoiceContext.getSourceWarehouseId()); + diposableGoodsManager.addAutoDeductionDisposableGoods(submitInvoiceContext.getDisposableGoodsServiceContext(), disposableGoodsIds); + addTargetDepartDisposableGoodsInfo(submitInvoiceContext); + } // 供应室科室的一次性物品信息 - private void addSupplyRoomDisposableGoodsInfo(SubmitInvoiceContext submitInvoiceContext ){ + private void addTargetDepartDisposableGoodsInfo(SubmitInvoiceContext submitInvoiceContext){ String departCode = submitInvoiceContext.getDepartCode(); - if(!supplyRoomConfigManager.isFirstOrSecondSupplyRoomOrgUnit(submitInvoiceContext.getDepartCode())){ - return; - } +// if(!supplyRoomConfigManager.isFirstOrSecondSupplyRoomOrgUnit(submitInvoiceContext.getDepartCode())){ +// return; +// } WareHouse wareHouse = submitInvoiceContext.getTargetWareHouseMap().get(departCode); if(wareHouse == null){ throw new RuntimeException(String.format("编码为%s的科室默认仓库为空", departCode)); } + if(wareHouse.getId().equals(submitInvoiceContext.getSourceWarehouseId())){ + throw new RuntimeException(String.format("源仓库和目标仓库不能相同!")); + } submitInvoiceContext.setTargetWareHouse(wareHouse); submitInvoiceContext.setTargetDepartIsSupplyRoom(true); - DisposableGoodsServiceContext disposableGoodsServiceContext = submitInvoiceContext.getDisposableGoodsServiceContext(); - diposableGoodsManager.loadStockAndIdentification(wareHouse.getId(), disposableGoodsServiceContext); + diposableGoodsManager.loadStockAndIdentification(wareHouse.getId(), submitInvoiceContext.getDisposableGoodsServiceContext()); } /** @@ -3302,7 +3322,8 @@ autoDeductionDisposableGoodsItems.clear(); autoDeductionDisposableGoodsInvoiceItems.clear(); DisposableGoodsServiceContext autoDeductionDisposableGoodsServiceContext = submitInvoiceContext - .getAutoDeductionDisposableGoodsServiceContext(); + .getDisposableGoodsServiceContext(); + Map idToDisposableGoodsBatchMap = autoDeductionDisposableGoodsServiceContext.getIdToDisposableGoodsBatchMap(); Map disposableGoodsIDToDisposableGoodsStockMap = autoDeductionDisposableGoodsServiceContext .getDisposableGoodsIDToDisposableGoodsStockMap(); for (TousseInstance tousseInstance : tousseInstances) { @@ -3481,6 +3502,12 @@ objectDao.update(disposableGoodsBatchStock); objectDao.update(disposableGoodsBatchStock .getDiposableGoods()); + + DisposableGoodsBatch diposableGoodBatch = idToDisposableGoodsBatchMap.get(identification.getDisposableGoodsBatchID()); + // 增加目标库存 + addTargetWarehouseAmount(submitInvoiceContext, + identification, diposableGoodBatch, + disposableGoodsBatchStock, amountChange); // 发货物品单项总价 BigDecimal itemPrice = MathTools.mul(fluctuationPrice, diposableGoodsItem.getAmount()); totalPrice = MathTools.add(totalPrice, itemPrice); @@ -3848,6 +3875,8 @@ Map barcodeToDisposableGoodsBatchStockMap = submitInvoiceContext .getDisposableGoodsServiceContext() .getBarcodeToDisposableGoodsBatchStockMap(); + Map idToDisposableGoodsBatchMap = submitInvoiceContext + .getDisposableGoodsServiceContext().getIdToDisposableGoodsBatchMap(); Map> fixedBarcodeTousseIdToAffiliatedTousseInstanceMap = submitInvoiceContext.getFixedBarcodeTousseIdToAffiliatedTousseInstanceMap(); Invoice invoice = new Invoice(); List diposableGoodsItems = new ArrayList(); @@ -3991,22 +4020,17 @@ String barcode = invoiceItem.getBarcode(); Object barcodeDevice = barcodeObjMap.get(invoiceItem .getBarcode()); + if (!(barcodeDevice instanceof DisposableGoodsBatch) && !(barcodeDevice instanceof DisposableGoods)) { throw new RuntimeException(String.format( "申请单[%s]上物品[%s]的类型与条码[%s]不匹配!", invoicePlan.getSerialNumber(), invoiceItem.getTousseName(), barcode)); } - DisposableGoodsBatch diposableGoodBatch = (DisposableGoodsBatch) barcodeDevice; - DisposableGoodsBatchStock disposableGoodsBatchStock = barcodeToDisposableGoodsBatchStockMap - .get(barcode); - if (disposableGoodsBatchStock == null) { - throw new RuntimeException(String.format( - "数据异常,物品[%s]在仓库[%s]中的批次库存[条码为 %s]不存在!", - invoiceItem.getTousseName(), - sourceWarehouseName, barcode)); - } + Set disposableGoodsStockSet = new HashSet(); + + // 获得价格 List identifications = getIdentificationByObj(submitInvoiceContext, barcode, barcodeDevice, invoiceItem, sourceWarehouseName); if(CollectionUtils.isEmpty(identifications)){ @@ -4023,6 +4047,20 @@ if (amountAwaitingSent <= 0) { break; } + DisposableGoodsBatch diposableGoodBatch = idToDisposableGoodsBatchMap.get(identification.getDisposableGoodsBatchID()); + if(diposableGoodBatch == null){ + throw new RuntimeException(String.format( + "数据异常,物品[%s]批次定义不存在!", + invoiceItem.getTousseName())); + } + DisposableGoodsBatchStock disposableGoodsBatchStock = identification.getBatchStock(); + if (disposableGoodsBatchStock == null) { + throw new RuntimeException(String.format( + "数据异常,物品[%s]在仓库[%s]中的批次库存[条码为 %s]不存在!", + invoiceItem.getTousseName(), + sourceWarehouseName, barcode)); + } + disposableGoodsStockSet.add(disposableGoodsBatchStock.getDiposableGoods()); if (identification.getAmount() < amountAwaitingSent) { diposableGoodsItem = new DiposableGoodsItem(); diposableGoodsItem.setAmount(Integer @@ -4079,19 +4117,9 @@ disposableGoodsStorageAdjustVoTotalList.add(vo); // 增加目标仓库库存,省医需求,发货到一二级供应室时需要增加库存 - if(submitInvoiceContext.isTargetDepartIsSupplyRoom()){ - WareHouse targetWareHouse = submitInvoiceContext.getTargetWareHouse(); - Long disposableGoodsId = disposableGoodsBatchStock.getDisposableGoodsId(); - DisposableGoodsStock targetDisposableGoodsStock = getOrCreateDisposableGoodsStock(submitInvoiceContext, disposableGoodsId, targetWareHouse); - DisposableGoodsBatchStock targetDisposableGoodsBatchStock = getOrCreateDisposableGoodsBatchStock(submitInvoiceContext, disposableGoodsId, targetDisposableGoodsStock, diposableGoodBatch, disposableGoodsBatchStock, targetWareHouse); - DisposableGoodsIdentification targetDisposableGoodsIdentification = getOrCreateIdentificationOfDisposableGoods(submitInvoiceContext, disposableGoodsId, targetDisposableGoodsStock, diposableGoodBatch, targetDisposableGoodsBatchStock, identification, targetWareHouse); - - identificationOfDiposableGoodsManager.adjustAmount(targetDisposableGoodsIdentification, amountChange); - objectDao.update(targetDisposableGoodsIdentification); - objectDao.update(targetDisposableGoodsBatchStock); - objectDao.update(targetDisposableGoodsStock); - - } + addTargetWarehouseAmount(submitInvoiceContext, + identification, diposableGoodBatch, + disposableGoodsBatchStock, amountChange); // 发货物品单项总价 BigDecimal itemPrice = MathTools.mul(fluctuationPrice, diposableGoodsItem.getAmount()); @@ -4100,17 +4128,38 @@ .getSettlementPrice() + itemPrice.doubleValue(); invoiceItem.setSettlementPrice(tmpSettlementPrice); } - invoiceItem.setDisposableGoodsId(disposableGoodsBatchStock - .getDisposableGoodsId()); - invoiceItem - .setDisposableGoodsStockId(disposableGoodsBatchStock - .getDisposableGoodsStockId()); - invoiceItem - .setDisposableGoodsBatchId(disposableGoodsBatchStock - .getDisposableGoodsBatchId()); - invoiceItem - .setDisposableGoodsBatchStockId(disposableGoodsBatchStock - .getId()); + if ((barcodeDevice instanceof DisposableGoodsBatch)) { + DisposableGoodsBatchStock disposableGoodsBatchStock = barcodeToDisposableGoodsBatchStockMap + .get(barcode); + if (disposableGoodsBatchStock == null) { + throw new RuntimeException(String.format( + "数据异常,物品[%s]在仓库[%s]中的批次库存[条码为 %s]不存在!", + invoiceItem.getTousseName(), + sourceWarehouseName, barcode)); + } + invoiceItem.setDisposableGoodsId(disposableGoodsBatchStock + .getDisposableGoodsId()); + invoiceItem + .setDisposableGoodsStockId(disposableGoodsBatchStock + .getDisposableGoodsStockId()); + invoiceItem + .setDisposableGoodsBatchId(disposableGoodsBatchStock + .getDisposableGoodsBatchId()); + invoiceItem + .setDisposableGoodsBatchStockId(disposableGoodsBatchStock + .getId()); + }else{ + if (disposableGoodsStockSet.size() == 1) { + DisposableGoodsStock DisposableGoodsStock = disposableGoodsStockSet.iterator().next(); + invoiceItem.setDisposableGoodsId(DisposableGoodsStock.getDisposableGoodsID()); + invoiceItem + .setDisposableGoodsStockId(DisposableGoodsStock.getId()); + }else{ + throw new RuntimeException(String.format( + "物品[%s]库存对象异常!", + invoiceItem.getTousseName())); + } + } } // 器械包 @@ -4380,7 +4429,37 @@ submitInvoiceContext.getTousseInstancesToUpdate()); return invoice; } + + /** + * @param submitInvoiceContext + * @param identification + * @param diposableGoodBatch + * @param disposableGoodsBatchStock + * @param amountChange + */ + private void addTargetWarehouseAmount( + SubmitInvoiceContext submitInvoiceContext, + DisposableGoodsIdentification identification, + DisposableGoodsBatch diposableGoodBatch, + DisposableGoodsBatchStock disposableGoodsBatchStock, + long amountChange) { + if(diposableGoodBatch == null){ + throw new SystemException("目标批次定义不能为空!"); + } + + WareHouse targetWareHouse = submitInvoiceContext.getTargetWareHouse(); + Long disposableGoodsId = disposableGoodsBatchStock.getDisposableGoodsId(); + DisposableGoodsStock targetDisposableGoodsStock = getOrCreateDisposableGoodsStock(submitInvoiceContext, disposableGoodsId, targetWareHouse); + DisposableGoodsBatchStock targetDisposableGoodsBatchStock = getOrCreateDisposableGoodsBatchStock(submitInvoiceContext, disposableGoodsId, targetDisposableGoodsStock, diposableGoodBatch, disposableGoodsBatchStock, targetWareHouse); + DisposableGoodsIdentification targetDisposableGoodsIdentification = getOrCreateIdentificationOfDisposableGoods(submitInvoiceContext, disposableGoodsId, targetDisposableGoodsStock, diposableGoodBatch, targetDisposableGoodsBatchStock, identification, targetWareHouse); + + identificationOfDiposableGoodsManager.adjustAmount(targetDisposableGoodsIdentification, amountChange); + objectDao.update(targetDisposableGoodsIdentification); + objectDao.update(targetDisposableGoodsBatchStock); + objectDao.update(targetDisposableGoodsStock); + } + private Invoice createComboTousseInvoice( Set invoicePlans, Set invoiceItems, Index: ssts-basedata/src/main/java/com/forgon/disinfectsystem/entity/assestmanagement/DisposableGoods.java =================================================================== diff -u -r25105 -r25141 --- ssts-basedata/src/main/java/com/forgon/disinfectsystem/entity/assestmanagement/DisposableGoods.java (.../DisposableGoods.java) (revision 25105) +++ ssts-basedata/src/main/java/com/forgon/disinfectsystem/entity/assestmanagement/DisposableGoods.java (.../DisposableGoods.java) (revision 25141) @@ -9,10 +9,6 @@ import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; - -import org.hibernate.annotations.DynamicInsert; -import org.hibernate.annotations.DynamicUpdate; - import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; @@ -22,18 +18,19 @@ import javax.persistence.ManyToMany; import javax.persistence.Transient; -import com.forgon.disinfectsystem.disposablegoods.helper.DisposableGoodHelper; -import com.forgon.disinfectsystem.entity.basedatamanager.supplier.AuthorizationRecord; -import com.forgon.disinfectsystem.entity.basedatamanager.supplier.Certificate; -import com.forgon.disinfectsystem.entity.basedatamanager.toussedefinition.TousseDefinition; - import org.apache.commons.lang.StringUtils; import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; +import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.DynamicUpdate; import com.fasterxml.jackson.annotation.JsonIgnore; import com.forgon.Constants; import com.forgon.directory.acegi.tools.AcegiHelper; +import com.forgon.disinfectsystem.disposablegoods.helper.DisposableGoodHelper; +import com.forgon.disinfectsystem.entity.basedatamanager.supplier.AuthorizationRecord; +import com.forgon.disinfectsystem.entity.basedatamanager.supplier.Certificate; +import com.forgon.disinfectsystem.entity.basedatamanager.toussedefinition.TousseDefinition; import com.forgon.tools.string.StringTools; import com.forgon.tools.util.ForgonIntegerUtils; @@ -56,6 +53,7 @@ public static final String TYPE_EXPENSIVEDIPOSABLEGOODS = "高值耗材"; public final static String TYPE_NAME = "一次性物品"; + public final static String TYPE_NAME_DEFINITION = "一次性物品定义"; public static String GRADE_FIRST = "一类"; public static String GRADE_SECOND = "二类"; Index: ssts-basedata/src/main/java/com/forgon/disinfectsystem/entity/assestmanagement/DisposableGoodsStock.java =================================================================== diff -u -r25131 -r25141 --- ssts-basedata/src/main/java/com/forgon/disinfectsystem/entity/assestmanagement/DisposableGoodsStock.java (.../DisposableGoodsStock.java) (revision 25131) +++ ssts-basedata/src/main/java/com/forgon/disinfectsystem/entity/assestmanagement/DisposableGoodsStock.java (.../DisposableGoodsStock.java) (revision 25141) @@ -14,7 +14,9 @@ import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.OneToMany; +import javax.persistence.Table; import javax.persistence.Transient; +import javax.persistence.UniqueConstraint; import org.apache.commons.lang.StringUtils; import org.hibernate.annotations.Cache; @@ -34,6 +36,7 @@ @DynamicInsert(false) @DynamicUpdate(true) @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) +@Table(uniqueConstraints = { @UniqueConstraint(name="UC_dgs_dgId_whId",columnNames = { "disposableGoodsID","warehouseID" }) }) public class DisposableGoodsStock { public final static SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd"); Index: ssts-basedata/src/main/java/com/forgon/disinfectsystem/disposablegoods/service/DisposableGoodsServiceContext.java =================================================================== diff -u -r20513 -r25141 --- ssts-basedata/src/main/java/com/forgon/disinfectsystem/disposablegoods/service/DisposableGoodsServiceContext.java (.../DisposableGoodsServiceContext.java) (revision 20513) +++ ssts-basedata/src/main/java/com/forgon/disinfectsystem/disposablegoods/service/DisposableGoodsServiceContext.java (.../DisposableGoodsServiceContext.java) (revision 25141) @@ -23,6 +23,7 @@ */ public class DisposableGoodsServiceContext { public static final String SCENE_DEFAULT = "通用"; + public static final String SCENE_INVOICE = "发货"; public static final String SCENE_INVOICE_AUTO_DEDUCTION = "发货自动扣减库存"; private String scene = SCENE_DEFAULT; @@ -36,6 +37,8 @@ */ private String warehouseId; + private String targetWarehouseId; + /** * 一次性物品id集合 */ @@ -88,6 +91,8 @@ */ private Map idToDisposableGoodsMap = new HashMap(); + private Map barcodeToDisposableGoodsMap = new HashMap(); + /** * 一次性物品库存集合 */ @@ -182,6 +187,14 @@ this.warehouseId = warehouseId; } + public String getTargetWarehouseId() { + return targetWarehouseId; + } + + public void setTargetWarehouseId(String targetWarehouseId) { + this.targetWarehouseId = targetWarehouseId; + } + public Set getDisposableGoodsIdsSet() { return disposableGoodsIdsSet; } @@ -260,6 +273,15 @@ this.idToDisposableGoodsMap = idToDisposableGoodsMap; } + public Map getBarcodeToDisposableGoodsMap() { + return barcodeToDisposableGoodsMap; + } + + public void setBarcodeToDisposableGoodsMap( + Map barcodeToDisposableGoodsMap) { + this.barcodeToDisposableGoodsMap = barcodeToDisposableGoodsMap; + } + public List getDisposableGoodsStockList() { return disposableGoodsStockList; } @@ -372,6 +394,16 @@ * 发货自动减库存 * @return */ + public boolean sceneInvoice(){ + if(StringUtils.equals(scene, SCENE_INVOICE)){ + return true; + } + return false; + } + /** + * 发货自动减库存 + * @return + */ public boolean sceneInvoiceAutoDeduction(){ if(StringUtils.equals(scene, SCENE_INVOICE_AUTO_DEDUCTION)){ return true; Index: ssts-diposablegoods/src/main/java/com/forgon/disinfectsystem/diposablegoods/service/DiposableGoodsManager.java =================================================================== diff -u -r25121 -r25141 --- ssts-diposablegoods/src/main/java/com/forgon/disinfectsystem/diposablegoods/service/DiposableGoodsManager.java (.../DiposableGoodsManager.java) (revision 25121) +++ ssts-diposablegoods/src/main/java/com/forgon/disinfectsystem/diposablegoods/service/DiposableGoodsManager.java (.../DiposableGoodsManager.java) (revision 25141) @@ -4,6 +4,7 @@ import java.util.Date; import java.util.List; import java.util.Map; +import java.util.Set; import javax.servlet.http.HttpServletRequest; @@ -253,6 +254,7 @@ DisposableGoodsBatchStock disposableGoodsBatchStock, Long storage,Double price, String conclusion, Date entryDate, String identification,Long godownEntryId,Long godownEntryItemId , Long batchIdFromHisSync); + public void addAutoDeductionDisposableGoods(DisposableGoodsServiceContext disposableGoodsServiceContext,Set disposableGoodsIDsSet); /** * 获取并锁定一次性物品相关资源. * @param disposableGoodsServiceContext 发货的一次性物品上下文 @@ -318,5 +320,5 @@ public String isInventoryGoods(Long warehouseID,DisposableGoods disposableGoods); public void adjustAmount(DisposableGoodsIdentification identification,long amountChange); - + public void waitAsyncAdditionComplete(); } Index: ssts-basedata/src/main/java/com/forgon/disinfectsystem/entity/assestmanagement/DisposableGoodsBatchStock.java =================================================================== diff -u -r25131 -r25141 --- ssts-basedata/src/main/java/com/forgon/disinfectsystem/entity/assestmanagement/DisposableGoodsBatchStock.java (.../DisposableGoodsBatchStock.java) (revision 25131) +++ ssts-basedata/src/main/java/com/forgon/disinfectsystem/entity/assestmanagement/DisposableGoodsBatchStock.java (.../DisposableGoodsBatchStock.java) (revision 25141) @@ -14,7 +14,9 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; +import javax.persistence.Table; import javax.persistence.Transient; +import javax.persistence.UniqueConstraint; import org.hibernate.annotations.Cascade; import org.hibernate.annotations.DynamicInsert; @@ -33,6 +35,7 @@ @Entity @DynamicInsert(false) @DynamicUpdate(true) +@Table(uniqueConstraints = { @UniqueConstraint(name="UC_dgbs_dgbId_whId",columnNames = { "disposableGoodsBatchId","warehouseID" }) }) public class DisposableGoodsBatchStock { private Long id;