Index: ssts-diposablegoods/src/main/java/com/forgon/disinfectsystem/diposablegoods/service/GodownEntryManagerImpl.java =================================================================== diff -u -r12820 -r12832 --- ssts-diposablegoods/src/main/java/com/forgon/disinfectsystem/diposablegoods/service/GodownEntryManagerImpl.java (.../GodownEntryManagerImpl.java) (revision 12820) +++ ssts-diposablegoods/src/main/java/com/forgon/disinfectsystem/diposablegoods/service/GodownEntryManagerImpl.java (.../GodownEntryManagerImpl.java) (revision 12832) @@ -404,6 +404,8 @@ diposableGoodBatchStockManager.saveOrUpdate(disposableGoodsBatchStock); return disposableGoodsBatchStock; } + + /** * @param entry * @param idToDiposableGoodsMap @@ -417,103 +419,122 @@ save(entry); List itemList = entry.getItemsList(); for (int i = 0; i < itemList.size(); ++i) { - boolean newBatch = false; GodownEntryItem godownEntryItem = itemList.get(i); - Long disposableGoodsID = godownEntryItem.getDisposableGoodsID(); - Long disposableGoodsStockID = godownEntryItem.getDisposableGoodsStockID(); - DisposableGoods disposableGoods = idToDisposableGoodsMap.get(disposableGoodsID); - DisposableGoodsStock disposableGoodsStock = idToDisposableGoodsStockMap.get(disposableGoodsStockID); - String batchNumber = godownEntryItem.getBatchNumber(); - - if(disposableGoods == null){ - throw new RuntimeException("物品未定义!"); - } - if(StringUtils.isBlank(batchNumber)){ - throw new RuntimeException("批次号不能为空!"); - } - // 查找一次性物品库存 - if(disposableGoodsStock == null){ - disposableGoodsStock = disposableGoodsStockManager.getDisposableGoodsStockByDisposableGoodsId(disposableGoodsID.toString(), warehouseID.toString()); - } - if(disposableGoodsStock == null){ - throw new RuntimeException("物品库存对象未找到!"); - } - // 查找批次定义 - DisposableGoodsBatch disposableGoodsBatch = diposableGoodsManager.getDisposableGoodsBatchByBatchNumber(disposableGoodsID, batchNumber); - if(disposableGoodsBatch == null){ - disposableGoodsBatch = newDisposableGoodsBatch(disposableGoods,warehouseID, warehouseName, godownEntryItem); - } - // 查找批次库存 - DisposableGoodsBatchStock disposableGoodsBatchStock = diposableGoodsManager.getDisposableGoodsStockByBatchNumber(warehouseID, disposableGoodsID, batchNumber); - // 保存时,每一项都是新建标识号对象 - Long disposableGoodsBatchID = godownEntryItem.getDisposableGoodsBatchID(); - Long disposableGoodsBatchStockID = godownEntryItem.getDisposableGoodsBatchStockID(); - - if(disposableGoodsBatchStock == null){ - // 新建 批次 - disposableGoodsBatchStock = newDisposableGoodsBatchStock(disposableGoods, disposableGoodsStock, disposableGoodsBatch, warehouseID, warehouseName, godownEntryItem); + godownEntryByItem(entry, warehouseID, warehouseName, + idToDisposableGoodsMap, idToDisposableGoodsStockMap, + idToBatchStockMap, godownEntryItem); + objectDao.update(godownEntryItem);// 更新item + } + } + + private void godownEntryByItem(GodownEntry entry, Long warehouseID, + String warehouseName, + Map idToDisposableGoodsMap, + Map idToDisposableGoodsStockMap, + Map idToDisposableGoodsBatchStockMap, + GodownEntryItem godownEntryItem) { + boolean newBatch = false; + Long disposableGoodsID = godownEntryItem.getDisposableGoodsID(); + Long disposableGoodsStockID = godownEntryItem.getDisposableGoodsStockID(); + DisposableGoods disposableGoods = idToDisposableGoodsMap.get(disposableGoodsID); + DisposableGoodsStock disposableGoodsStock = null; - newBatch = true; - idToBatchStockMap.put(disposableGoodsBatchStock.getId(), disposableGoodsBatchStock); - } - // 更新一次性物品定义 - disposableGoods.setReferencePrice(godownEntryItem.getCost()); - // 更新批次定义 - disposableGoodsBatch.setCost(godownEntryItem.getCost()); - disposableGoodsBatch.setExpDate(godownEntryItem.getExpDate()); - disposableGoodsBatch.setManufacturer(godownEntryItem.getManufacturer()); - disposableGoodsBatch.setSterileBatchNumber(godownEntryItem.getSterileBatchNumber()); - disposableGoodsBatch.setSupplierName(godownEntryItem.getSupplierName()); - disposableGoodsBatch.setProducingArea(godownEntryItem.getProducingArea()); - // 更新批次库存相关信息 + String batchNumber = godownEntryItem.getBatchNumber(); + + if(disposableGoods == null){ + throw new RuntimeException("物品未定义!"); + } + if(StringUtils.isBlank(batchNumber)){ + throw new RuntimeException("批次号不能为空!"); + } + if(disposableGoodsStockID != null){ + disposableGoodsStock = idToDisposableGoodsStockMap.get(disposableGoodsStockID); + } + // 查找一次性物品库存 + if(disposableGoodsStock == null){ + disposableGoodsStock = disposableGoodsStockManager.getDisposableGoodsStockByDisposableGoodsId(disposableGoodsID.toString(), warehouseID.toString()); + } + if(disposableGoodsStock == null){ + throw new RuntimeException("物品库存对象未找到!"); + } + // 校验仓库是否是当前仓库 + if(!warehouseID.equals(disposableGoodsStock.getWarehouseID())){ + throw new RuntimeException("物品库存不是当前仓库的!"); + } + // 查找批次定义 + DisposableGoodsBatch disposableGoodsBatch = diposableGoodsManager.getDisposableGoodsBatchByBatchNumber(disposableGoodsID, batchNumber); + if(disposableGoodsBatch == null){ + disposableGoodsBatch = newDisposableGoodsBatch(disposableGoods,warehouseID, warehouseName, godownEntryItem); + } + // 查找批次库存 + DisposableGoodsBatchStock disposableGoodsBatchStock = diposableGoodsManager.getDisposableGoodsStockByBatchNumber(warehouseID, disposableGoodsID, batchNumber); + // 保存时,每一项都是新建标识号对象 + Long disposableGoodsBatchID = godownEntryItem.getDisposableGoodsBatchID(); + Long disposableGoodsBatchStockID = godownEntryItem.getDisposableGoodsBatchStockID(); + + if(disposableGoodsBatchStock == null){ + // 新建 批次 + disposableGoodsBatchStock = newDisposableGoodsBatchStock(disposableGoods, disposableGoodsStock, disposableGoodsBatch, warehouseID, warehouseName, godownEntryItem); + + newBatch = true; + idToDisposableGoodsBatchStockMap.put(disposableGoodsBatchStock.getId(), disposableGoodsBatchStock); + } + // 更新一次性物品定义 + disposableGoods.setReferencePrice(godownEntryItem.getCost()); + // 更新批次定义 + disposableGoodsBatch.setCost(godownEntryItem.getCost()); + disposableGoodsBatch.setExpDate(godownEntryItem.getExpDate()); + disposableGoodsBatch.setManufacturer(godownEntryItem.getManufacturer()); + disposableGoodsBatch.setSterileBatchNumber(godownEntryItem.getSterileBatchNumber()); + disposableGoodsBatch.setSupplierName(godownEntryItem.getSupplierName()); + disposableGoodsBatch.setProducingArea(godownEntryItem.getProducingArea()); + // 更新批次库存相关信息 // disposableGoodsBatchStock.setDisposableGoodsID(disposableGoodsID); // disposableGoodsBatchStock.setDisposableGoodsBatchID(disposableGoodsBatch.getId()); // disposableGoodsBatchStock.setBatchNumber(godownEntryItem.getBatchNumber()); - disposableGoodsBatchStock.setCost(godownEntryItem.getCost()); - disposableGoodsBatchStock.setExpDate(godownEntryItem.getExpDate()); - disposableGoodsBatchStock.setManufacturer(godownEntryItem.getManufacturer()); - disposableGoodsBatchStock.setSterileBatchNumber(godownEntryItem.getSterileBatchNumber()); - disposableGoodsBatchStock.setSupplierName(godownEntryItem.getSupplierName()); - disposableGoodsBatchStock.setProducingArea(godownEntryItem.getProducingArea()); + disposableGoodsBatchStock.setCost(godownEntryItem.getCost()); + disposableGoodsBatchStock.setExpDate(godownEntryItem.getExpDate()); + disposableGoodsBatchStock.setManufacturer(godownEntryItem.getManufacturer()); + disposableGoodsBatchStock.setSterileBatchNumber(godownEntryItem.getSterileBatchNumber()); + disposableGoodsBatchStock.setSupplierName(godownEntryItem.getSupplierName()); + disposableGoodsBatchStock.setProducingArea(godownEntryItem.getProducingArea()); // disposableGoodsBatchStock.setWarehouseID(entry.getWarehouseID()); // disposableGoodsBatchStock.setWarehouseName(entry.getWarehouseName()); - // 新建标识号对象 - IdentificationOfDisposableGoods identification = new IdentificationOfDisposableGoods(); - - identification.setDisposableGoodsID(disposableGoodsID); - identification.setDisposableGoodsBatchID(disposableGoodsBatch.getId()); - identification.setDisposableGoodsStockID(disposableGoodsStock.getId()); - identification.setBatchStock(disposableGoodsBatchStock); - disposableGoodsBatchStock.getIdentifications().add(identification); - identification.adjustAmount(godownEntryItem.getAmount()); - identification.setBatchStock(disposableGoodsBatchStock); - identification.setConclusion(godownEntryItem.getConclusion()); - identification.setEntryDate(entry.getTime()); - identification.setIdentification("");// 暂时为空,待确定生成规则 - identification.setPrice(godownEntryItem.getCost()); - identification.setWarehouseID(entry.getWarehouseID()); - identification.setWarehouseName(entry.getWarehouseName()); - objectDao.save(identification); - - godownEntryItem.setNewBatch(newBatch); - // 设置godownEntryItem和批次,标识号关联的信息 - godownEntryItem.setDisposableGoodsID(disposableGoodsID); - godownEntryItem.setDisposableGoodsStockID(disposableGoodsStock.getId()); - godownEntryItem.setDisposableGoodsBatchID(disposableGoodsBatch.getId()); - godownEntryItem.setDisposableGoodsBatchStockID(disposableGoodsBatchStock.getId()); - godownEntryItem.setIdentificationID(identification.getId()); - godownEntryItem.setDiposableGoods(disposableGoodsStock); - if(!godownEntryItem.isAssociatedInfoValidForInEntry()){ - throw new RuntimeException("关联信息不正确!"); - } - objectDao.update(godownEntryItem);// 更新关联信息 - // 新建项需要修改一次性物品价格 - disposableGoodsStock.setReferencePrice(godownEntryItem.getCost()); - objectDao.update(disposableGoods); - objectDao.update(disposableGoodsStock); - objectDao.update(disposableGoodsBatch); - objectDao.update(disposableGoodsBatchStock); + // 新建标识号对象 + IdentificationOfDisposableGoods identification = new IdentificationOfDisposableGoods(); + + identification.setDisposableGoodsID(disposableGoodsID); + identification.setDisposableGoodsBatchID(disposableGoodsBatch.getId()); + identification.setDisposableGoodsStockID(disposableGoodsStock.getId()); + identification.setBatchStock(disposableGoodsBatchStock); + disposableGoodsBatchStock.getIdentifications().add(identification); + identification.adjustAmount(godownEntryItem.getAmount()); + identification.setBatchStock(disposableGoodsBatchStock); + identification.setConclusion(godownEntryItem.getConclusion()); + identification.setEntryDate(entry.getTime()); + identification.setIdentification("");// 暂时为空,待确定生成规则 + identification.setPrice(godownEntryItem.getCost()); + identification.setWarehouseID(entry.getWarehouseID()); + identification.setWarehouseName(entry.getWarehouseName()); + objectDao.save(identification); + + godownEntryItem.setNewBatch(newBatch); + // 设置godownEntryItem和批次,标识号关联的信息 + godownEntryItem.setDisposableGoodsID(disposableGoodsID); + godownEntryItem.setDisposableGoodsStockID(disposableGoodsStock.getId()); + godownEntryItem.setDisposableGoodsBatchID(disposableGoodsBatch.getId()); + godownEntryItem.setDisposableGoodsBatchStockID(disposableGoodsBatchStock.getId()); + godownEntryItem.setIdentificationID(identification.getId()); + godownEntryItem.setDiposableGoods(disposableGoodsStock); + if(!godownEntryItem.isAssociatedInfoValidForInEntry()){ + throw new RuntimeException("关联信息不正确!"); } + // 新建项需要修改一次性物品价格 + disposableGoodsStock.setReferencePrice(godownEntryItem.getCost()); + objectDao.update(disposableGoods); + objectDao.update(disposableGoodsStock); + objectDao.update(disposableGoodsBatch); + objectDao.update(disposableGoodsBatchStock); } /** @@ -634,31 +655,46 @@ // 被并发删除了,也不需要处理 continue; } + // 修改时,每一项都应该有ID Long disposableGoodsID = godownEntryItem.getDisposableGoodsID(); - Long diposableGoodsID = godownEntryItem.getDisposableGoodsStockID(); - DisposableGoodsStock diposableGoods = idToDisposableGoodsStockMap.get(diposableGoodsID); - // 保存时,每一项都是新建标识号对象 + Long disposableGoodsStockID = godownEntryItem.getDisposableGoodsStockID(); Long disposableGoodsBatchID = godownEntryItem.getDisposableGoodsBatchID(); - Long batchID = godownEntryItem.getDisposableGoodsBatchStockID(); + Long disposableGoodsBatchStockID = godownEntryItem.getDisposableGoodsBatchStockID(); Long identificationID = godownEntryItem.getIdentificationID(); String batchNumber = godownEntryItem.getBatchNumber(); + if(disposableGoodsID == null){ + throw new RuntimeException("物品定义id不能为空,请升级数据!"); + } + if(disposableGoodsStockID == null){ + throw new RuntimeException("物品库存id不能为空,请升级数据!"); + } + if(disposableGoodsBatchID == null){ + throw new RuntimeException("物品批次id不能为空,请升级数据!"); + } + if(disposableGoodsBatchStockID == null){ + throw new RuntimeException("物品批次库存id不能为空,请升级数据!"); + } if(identificationID == null){ throw new RuntimeException("标识号不能为空,请升级数据!"); } + DisposableGoods disposableGoods = idToDisposableGoodsMap.get(disposableGoodsID); + DisposableGoodsStock disposableGoodsStock = idToDisposableGoodsStockMap.get(disposableGoodsStockID); // 查找批次定义 - DisposableGoodsBatch disposableGoodsBatch = diposableGoodsManager.getDisposableGoodsBatchByBatchNumber(disposableGoodsID, batchNumber); + DisposableGoodsBatch disposableGoodsBatch = idToDisposableGoodsBatchMap.get(disposableGoodsBatchID); + DisposableGoodsBatchStock disposableGoodsBatchStock = idToDisposableGoodsBatchStockMap.get(disposableGoodsBatchStockID); + IdentificationOfDisposableGoods identification = idToIdentificationMap.get(identificationID); + if(disposableGoods == null){ + throw new RuntimeException("物品定义不存在!"); + } + if(disposableGoodsStock == null){ + throw new RuntimeException("物品库存不存在!"); + } if(disposableGoodsBatch == null){ - throw new RuntimeException("批次定义不存在!"); + throw new RuntimeException("物品批次不存在!"); } - DisposableGoodsBatchStock disposableGoodsBatchStock = idToDisposableGoodsBatchStockMap.get(batchID); if(disposableGoodsBatchStock == null){ - disposableGoodsBatchStock = diposableGoodsManager.getDisposableGoodsStockByBatchNumber(warehouseID, disposableGoodsID, batchNumber); - if(disposableGoodsBatchStock == null){ - throw new RuntimeException("批次已被删除!"); - } - + throw new RuntimeException("物品批次库存不存在!"); } - IdentificationOfDisposableGoods identification = idToIdentificationMap.get(identificationID); if(identification == null){ throw new RuntimeException("标识号已被删除!"); } @@ -730,21 +766,18 @@ identification.setPrice(price); disposableGoodsBatchStock.setCost(price); disposableGoodsBatch.setCost(price); + disposableGoods.setReferencePrice(price); curGodownEntryItem.setCost(price); // 同步修改发货和退货记录 synchronizePriceFromIdentificationToInvoiceAndReturnRecord(identification,originalPrice,price); updateBatchStock = true; } } + objectDao.update(identification); + objectDao.update(disposableGoodsBatchStock); + objectDao.update(disposableGoodsStock); objectDao.update(disposableGoodsBatch); - // 是否更新批次 - if(updateBatchStock){ - objectDao.update(disposableGoodsBatchStock); - } - // 是否更新一次性物品对象 - if(updateDiposableGoods){ - objectDao.update(diposableGoods); - } + objectDao.update(disposableGoods); } // 处理新增 for (int i = 0; i < itemList.size(); ++i) { @@ -753,95 +786,8 @@ if(itemID != null){// 有id就不是新增项 continue; } - boolean newBatch = false; - // 可能需要新建批次,一定会新建标识号 - Long disposableGoodsID = godownEntryItem.getDisposableGoodsID(); - Long diposableGoodsID = godownEntryItem.getDisposableGoodsStockID(); - DisposableGoods disposableGoods = idToDisposableGoodsMap.get(disposableGoodsID); - DisposableGoodsStock disposableGoodsStock = idToDisposableGoodsStockMap.get(diposableGoodsID); - String batchNumber = godownEntryItem.getBatchNumber(); - // 保存时,每一项都是新建标识号对象 - Long disposableGoodsBatchID = godownEntryItem.getDisposableGoodsBatchID(); - Long batchID = godownEntryItem.getDisposableGoodsBatchStockID(); + godownEntryByItem(curGodownEntry, warehouseID, warehouseName, idToDisposableGoodsMap, idToDisposableGoodsStockMap, idToDisposableGoodsBatchStockMap, godownEntryItem); - // 查找一次性物品库存 - if(disposableGoodsStock == null){ - disposableGoodsStock = disposableGoodsStockManager.getDisposableGoodsStockByDisposableGoodsId(disposableGoodsID.toString(),warehouseID.toString()); - } - if(disposableGoodsStock == null){ - throw new RuntimeException("物品库存对象未找到!"); - } - // 查找批次定义 - DisposableGoodsBatch disposableGoodsBatch = diposableGoodsManager.getDisposableGoodsBatchByBatchNumber(disposableGoodsID, batchNumber); - if(disposableGoodsBatch == null){ - disposableGoodsBatch = newDisposableGoodsBatch(disposableGoods,warehouseID, warehouseName, godownEntryItem); - } - // 查找批次库存 - DisposableGoodsBatchStock disposableGoodsBatchStock = diposableGoodsManager.getDisposableGoodsStockByBatchNumber(warehouseID, disposableGoodsID, batchNumber); - // 保存时,每一项都是新建标识号对象 - Long disposableGoodsBatchStockID = godownEntryItem.getDisposableGoodsBatchStockID(); - if(disposableGoodsBatchStock == null){ - // 新建 批次 - disposableGoodsBatchStock = newDisposableGoodsBatchStock(disposableGoods, disposableGoodsStock, disposableGoodsBatch, warehouseID, warehouseName, godownEntryItem); - - newBatch = true; - idToDisposableGoodsBatchStockMap.put(disposableGoodsBatchStock.getId(), disposableGoodsBatchStock); - } - // 更新一次性物品定义 - disposableGoods.setReferencePrice(godownEntryItem.getCost()); - // 更新批次定义 - disposableGoodsBatch.setCost(godownEntryItem.getCost()); - disposableGoodsBatch.setExpDate(godownEntryItem.getExpDate()); - disposableGoodsBatch.setManufacturer(godownEntryItem.getManufacturer()); - disposableGoodsBatch.setSterileBatchNumber(godownEntryItem.getSterileBatchNumber()); - disposableGoodsBatch.setSupplierName(godownEntryItem.getSupplierName()); - disposableGoodsBatch.setProducingArea(godownEntryItem.getProducingArea()); - // 更新批次库存相关信息 - disposableGoodsBatchStock.setCost(godownEntryItem.getCost()); - disposableGoodsBatchStock.setExpDate(godownEntryItem.getExpDate()); - disposableGoodsBatchStock.setManufacturer(godownEntryItem.getManufacturer()); - disposableGoodsBatchStock.setSterileBatchNumber(godownEntryItem.getSterileBatchNumber()); - disposableGoodsBatchStock.setSupplierName(godownEntryItem.getSupplierName()); - disposableGoodsBatchStock.setProducingArea(godownEntryItem.getProducingArea()); - // 新建标识号对象 - IdentificationOfDisposableGoods identification = new IdentificationOfDisposableGoods(); - - identification.setDisposableGoodsID(disposableGoodsID); - identification.setDisposableGoodsBatchID(disposableGoodsBatch.getId()); - identification.setDisposableGoodsStockID(disposableGoodsStock.getId()); - identification.setBatchStock(disposableGoodsBatchStock); - disposableGoodsBatchStock.getIdentifications().add(identification); - identification.adjustAmount(godownEntryItem.getAmount()); - identification.setBatchStock(disposableGoodsBatchStock); - identification.setConclusion(godownEntryItem.getConclusion()); - identification.setEntryDate(entry.getTime()); - identification.setIdentification("");// 暂时为空,待确定生成规则 - identification.setPrice(godownEntryItem.getCost()); - identification.setWarehouseID(entry.getWarehouseID()); - identification.setWarehouseName(entry.getWarehouseName()); - objectDao.save(identification); - - // 设置godownEntryItem和批次,标识号关联的信息 - godownEntryItem.setDisposableGoodsID(disposableGoodsID); - godownEntryItem.setDisposableGoodsStockID(disposableGoodsStock.getId()); - godownEntryItem.setDisposableGoodsBatchID(disposableGoodsBatch.getId()); - godownEntryItem.setDisposableGoodsBatchStockID(disposableGoodsBatchStock.getId()); - godownEntryItem.setIdentificationID(identification.getId()); - - godownEntryItem.setNewBatch(newBatch); - godownEntryItem.setDiposableGoods(disposableGoodsStock); - godownEntryItem.setGodownEntry(curGodownEntry); - if(!godownEntryItem.isAssociatedInfoValidForInEntry()){ - throw new RuntimeException("关联信息不正确!"); - } - // 新建项需要修改一次性物品价格 - disposableGoodsStock.setReferencePrice(godownEntryItem.getCost()); - - objectDao.update(disposableGoods); - objectDao.update(disposableGoodsStock); - objectDao.update(disposableGoodsBatch); - objectDao.update(disposableGoodsBatchStock); - // 保存godownEntryItem godownEntryItem.setGodownEntry(curGodownEntry); curItemList.add(godownEntryItem);