Index: ssts-userecord/src/main/java/com/forgon/disinfectsystem/useRecord/service/UseRecordManagerImpl.java =================================================================== diff -u -r27531 -r27786 --- ssts-userecord/src/main/java/com/forgon/disinfectsystem/useRecord/service/UseRecordManagerImpl.java (.../UseRecordManagerImpl.java) (revision 27531) +++ ssts-userecord/src/main/java/com/forgon/disinfectsystem/useRecord/service/UseRecordManagerImpl.java (.../UseRecordManagerImpl.java) (revision 27786) @@ -55,6 +55,7 @@ import com.forgon.disinfectsystem.entity.assestmanagement.DiposableGoodsInstance; import com.forgon.disinfectsystem.entity.assestmanagement.DisposableGoods; import com.forgon.disinfectsystem.entity.assestmanagement.DisposableGoodsBatch; +import com.forgon.disinfectsystem.entity.assestmanagement.DisposableGoodsBatchStock; import com.forgon.disinfectsystem.entity.assestmanagement.DisposableGoodsIdentification; import com.forgon.disinfectsystem.entity.assestmanagement.ExpensiveDisposablegoods; import com.forgon.disinfectsystem.entity.assestmanagement.ExpensiveGoods; @@ -2871,7 +2872,8 @@ @SuppressWarnings("unchecked") private void mintRecyclingApplication( boolean isAutomaticlyMergeApplications, - boolean isSecondSupplyRoomNeedRecycle,Boolean isDgConvertApplication,Boolean isTousseDgMergeConvert, + boolean isSecondSupplyRoomNeedRecycle, + Boolean isDgConvertApplication,Boolean isTousseDgMergeConvert, Map useRecordsMap, String applicant, String depart, String departCoding, String operationRoom,String patientName,Date applicationCreateDate,double dpf,String applicationFormType) { String hospitalNumbers = ""; @@ -7009,8 +7011,30 @@ list = objectDao.findByHql(sql, 0, batchCount); return list; } - + /** + * 获取可以录使用记录的高值耗材发货明细 + * @param departCoding 科室编码 + * @param expensiveDisposableGoodsId 高值耗材定义id + * @return + */ + private List getDiposableGoodsItemCanUseForExpensiveDisposableGoods(String departCoding, Long expensiveDisposableGoodsId){ + List list = null; + // 按发货日期时间降序,即优先从最近的发货物品里面录入使用记录 + + String isNullFunction = DatabaseUtil.getSqlIsNullFunctionName(dbConnection); + + String sql = String + .format(" select d from %s i,%s d where i.id = d.invoice.id and i.settleAccountsDepartCoding = '%s' " + + "and (d.amount > (%s(d.returnedAmount,0) + %s(d.useAmount,0))) " + + "and d.expensiveDisposablegoodsId = %s order by i.applicationTime desc", + Invoice.class.getSimpleName(),DiposableGoodsItem.class.getSimpleName(), + departCoding,isNullFunction, isNullFunction,expensiveDisposableGoodsId); + list = objectDao.findByHql(sql); + return list; + } + + /** * 获取可以录使用记录的一次性物品发货明细 * @param useRecord 使用记录数量 * @param disposableGoodsBatchID 一次性物品批次id @@ -7037,7 +7061,7 @@ } /** - * 获取可以录使用记录的一次性物品发货明细 + * 获取已经录入使用记录的一次性物品(普通物品)发货明细 * @param useRecord 使用记录数量 * @param disposableGoodsBatchID 一次性物品批次id * @return @@ -7075,6 +7099,42 @@ } /** + * 获取已经录入使用记录的高值耗材(一次性物品)发货明细 + * @param useRecord 使用记录数量 + * @param expensiveDisposableGoodsId 高值耗材id + * @return + */ + private List getUsedDiposableGoodsItemByExpensiveDisposableGoodsId( + UseRecord useRecord, Long expensiveDisposableGoodsId){ + //高值耗材业务项 + List diposableGoodsItemListOfEdg = null; + List useDiposableGoodsItemList = useRecord.getDiposableGoodsItems(); + if(CollectionUtils.isNotEmpty(useDiposableGoodsItemList)){ + ExpensiveDisposablegoods expensiveDisposableGoods = + (ExpensiveDisposablegoods)objectDao.getById(ExpensiveDisposablegoods.class.getSimpleName(), + expensiveDisposableGoodsId); + for (UseDiposableGoodsItem useDiposableGoodsItem : useDiposableGoodsItemList) { + if(!StringUtils.equals(useDiposableGoodsItem.getBarcode(), expensiveDisposableGoods.getBarcode())){ + continue; + } + String condition = String.format(" where useAmount > 0 and id in (select diposableGoodsItemId from "+ + ItemOfUseDisposableGoodsItem.class.getSimpleName() +" iudgi where iudgi.useDiposableGoodsItemId=%s)" , + useDiposableGoodsItem.getId()); + @SuppressWarnings("unchecked") + List diposableGoodsItemList = + objectDao.findBySql(DiposableGoodsItem.class.getSimpleName(), condition); + if(CollectionUtils.isNotEmpty(diposableGoodsItemList)){ + if(diposableGoodsItemListOfEdg == null){ + diposableGoodsItemListOfEdg = new ArrayList(); + } + diposableGoodsItemListOfEdg.addAll(diposableGoodsItemList); + } + } + } + return diposableGoodsItemListOfEdg; + } + + /** * 从一次性物品使用记录数据集中获取 * @param departCoding 科室编码 * @param idToDisposableGoodsMap @@ -7200,106 +7260,151 @@ } } }else{ - //批次条码 - String batchBarcode = useDiposableGoodsItemJsonObject.optString("barcode"); + //批次条码(或高值耗材条件) + String batchBarcodeOrEdgBarcode = useDiposableGoodsItemJsonObject.optString("barcode"); //UseDiposableGoodsItem useDiposableGoodsItem = JSONUtil.fromJson(useDiposableGoodsItemJsonObject.toString(), UseDiposableGoodsItem.class); - //判断该批次的库存是否够 - DisposableGoodsBatch disposableGoodsBatch = - diposableGoodsManager.getDisposableGoodsBatchByBatchNumber(disposableGoodsId, - useDiposableGoodsItemJsonObject.optString("batchNo")); - if(disposableGoodsBatch == null){ - // - throw new SystemException("未找到批次号为" + useDiposableGoodsItemJsonObject.optString("batchNo") + "定义"); + if(StringUtils.isBlank(batchBarcodeOrEdgBarcode)){ + //抛异常 } - if(!StringUtils.equals(batchBarcode, disposableGoodsBatch.getBarcode())){ - // - throw new SystemException(String.format("扫描的批次条码为%s,批次号%s对应的条码为%s,两个条码不一致" , batchBarcode, - useDiposableGoodsItemJsonObject.optString("batchNo"), disposableGoodsBatch.getBarcode())); + BarcodeDevice bd = barcodeManager.getBarcodeByBarcode(batchBarcodeOrEdgBarcode); + if(bd == null){ + //抛异常 } - //可以被录入使用记录的发货项id及可录入使用数据 - Map sendOutDiposableGoodsItemAmountMap = new HashMap(); - while(true){ - List list = null; - // 一次取10个发货明细用于录入使用记录 - list = getDiposableGoodsItemCanUse(useRecord.getDepartCoding(), disposableGoodsId , disposableGoodsBatch.getId() , 10); - if(list == null || list.size() == 0){ - String err = String.format("该物品(%s)的使用数量大于发货数量!", disposableGoods.getShowName()); - throw new RuntimeException(err); + DisposableGoodsBatch disposableGoodsBatch = null; + if(bd instanceof DisposableGoodsBatch){ + //判断该批次的库存是否够 + disposableGoodsBatch = + diposableGoodsManager.getDisposableGoodsBatchByBatchNumber(disposableGoodsId, + useDiposableGoodsItemJsonObject.optString("batchNo")); + if(disposableGoodsBatch == null){ + // + throw new SystemException("未找到批次号为" + useDiposableGoodsItemJsonObject.optString("batchNo") + "定义"); } - for(int i=0;i sendOutDiposableGoodsItemAmountMap = new HashMap(); + while(true){ + List list = null; + // 一次取10个发货明细用于录入使用记录 + list = getDiposableGoodsItemCanUse(useRecord.getDepartCoding(), disposableGoodsId , disposableGoodsBatch.getId() , 10); + if(list == null || list.size() == 0){ + String err = String.format("该物品(%s)的使用数量大于发货数量!", disposableGoods.getShowName()); + throw new RuntimeException(err); } - if(useAmount == null){ - useAmount = 0L; + for(int i=0;i 0){ - Map disposableGoodsBatchAmountMap = new HashMap(); - for (DiposableGoodsItem sendOutDiposableGoodsItem : sendOutDiposableGoodsItemAmountMap.keySet()) { - Long disposableGoodsBatchId = sendOutDiposableGoodsItem.getDisposableGoodsBatchID(); - DisposableGoodsBatch batch = diposableGoodsManager.getDisposableGoodsBatchById(sendOutDiposableGoodsItem.getDisposableGoodsBatchID()); - if(batch == null){ - //抛出异常 - } - UseDiposableGoodsItem useDiposableGoodsItem = null; - //如果不为修改,则新创建UseDiposableGoodsItem - if(disposableGoodsBatchAmountMap.containsKey(disposableGoodsBatchId)){ - useDiposableGoodsItem = disposableGoodsBatchAmountMap.get(disposableGoodsBatchId); - }else{ - useDiposableGoodsItem = new UseDiposableGoodsItem(); - useDiposableGoodsItem.setDisposableGoodsId(batch.getDiposableGoods().getId()); - useDiposableGoodsItem.setBatchNo(batch.getBatchNumber()); - useDiposableGoodsItem.setBarcode(batch.getBarcode()); - if(useDiposableGoodsItem.getAmount() == null){ - useDiposableGoodsItem.setAmount(sendOutDiposableGoodsItemAmountMap.get(sendOutDiposableGoodsItem).intValue()); + if(sendOutDiposableGoodsItemAmountMap.size() > 0){ + Map disposableGoodsBatchAmountMap = new HashMap(); + for (DiposableGoodsItem sendOutDiposableGoodsItem : sendOutDiposableGoodsItemAmountMap.keySet()) { + Long disposableGoodsBatchId = sendOutDiposableGoodsItem.getDisposableGoodsBatchID(); + DisposableGoodsBatch batch = diposableGoodsManager.getDisposableGoodsBatchById(sendOutDiposableGoodsItem.getDisposableGoodsBatchID()); + if(batch == null){ + //抛出异常 + } + UseDiposableGoodsItem useDiposableGoodsItem = null; + //如果不为修改,则新创建UseDiposableGoodsItem + if(disposableGoodsBatchAmountMap.containsKey(disposableGoodsBatchId)){ + useDiposableGoodsItem = disposableGoodsBatchAmountMap.get(disposableGoodsBatchId); }else{ - useDiposableGoodsItem.setAmount(useDiposableGoodsItem.getAmount() + sendOutDiposableGoodsItemAmountMap.get(sendOutDiposableGoodsItem).intValue()); + useDiposableGoodsItem = new UseDiposableGoodsItem(); + useDiposableGoodsItem.setDisposableGoodsId(batch.getDiposableGoods().getId()); + useDiposableGoodsItem.setBatchNo(batch.getBatchNumber()); + useDiposableGoodsItem.setBarcode(batch.getBarcode()); + if(useDiposableGoodsItem.getAmount() == null){ + useDiposableGoodsItem.setAmount(sendOutDiposableGoodsItemAmountMap.get(sendOutDiposableGoodsItem).intValue()); + }else{ + useDiposableGoodsItem.setAmount(useDiposableGoodsItem.getAmount() + sendOutDiposableGoodsItemAmountMap.get(sendOutDiposableGoodsItem).intValue()); + } + useDiposableGoodsItem.setName(disposableGoods.getShowName()); + useDiposableGoodsItem.setValidUntil(batch.getExpDateStr()); + disposableGoodsBatchAmountMap.put(disposableGoodsBatchId, useDiposableGoodsItem); + if(useRecord.getDiposableGoodsItems() == null){ + useRecord.setDiposableGoodsItems(new ArrayList()); + } + useRecord.getDiposableGoodsItems().add(useDiposableGoodsItem); + objectDao.saveOrUpdate(useRecord); } - useDiposableGoodsItem.setName(disposableGoods.getShowName()); - useDiposableGoodsItem.setValidUntil(batch.getExpDateStr()); - disposableGoodsBatchAmountMap.put(disposableGoodsBatchId, useDiposableGoodsItem); - if(useRecord.getDiposableGoodsItems() == null){ - useRecord.setDiposableGoodsItems(new ArrayList()); - } - useRecord.getDiposableGoodsItems().add(useDiposableGoodsItem); - objectDao.saveOrUpdate(useRecord); + updateItemOfUseDiposableGoodsData(useDiposableGoodsItem , sendOutDiposableGoodsItem , sendOutDiposableGoodsItemAmountMap.get(sendOutDiposableGoodsItem)); } - updateItemOfUseDiposableGoodsData(useDiposableGoodsItem , sendOutDiposableGoodsItem , sendOutDiposableGoodsItemAmountMap.get(sendOutDiposableGoodsItem)); } + }else if(bd instanceof ExpensiveDisposablegoods){ + ExpensiveDisposablegoods edg = (ExpensiveDisposablegoods)bd; + //高值耗材的逻辑 + disposableGoodsBatch = + diposableGoodsManager.getDisposableGoodsBatchById(((ExpensiveDisposablegoods)bd).getDisposableGoodsBatchID()); + // 取第1个发货明细用于录入使用记录 + List list = getDiposableGoodsItemCanUseForExpensiveDisposableGoods(useRecord.getDepartCoding(), bd.getId()); + if(CollectionUtils.isEmpty(list)){ + String err = String.format("该物品(%s)的使用数量大于发货数量!", disposableGoods.getShowName()); + throw new RuntimeException(err); + } + DiposableGoodsItem sendOutDiposableGoodsItem = list.get(0);// 发货明细 + //设置该业务项的使用数量为1 + sendOutDiposableGoodsItem.setUseAmount(1L);// 设置发货明细的已使用数量 + + objectDao.update(sendOutDiposableGoodsItem); + //录入使用记录后调整库存 + updateDisposableStockAmount(useRecord.getDepartCoding(),sendOutDiposableGoodsItem.getId() , -1L); + + UseDiposableGoodsItem useDiposableGoodsItem = new UseDiposableGoodsItem(); + useDiposableGoodsItem.setDisposableGoodsId(disposableGoods.getId()); + useDiposableGoodsItem.setBatchNo(disposableGoodsBatch.getBatchNumber()); + useDiposableGoodsItem.setBarcode(edg.getBarcode()); + useDiposableGoodsItem.setAmount(1); + useDiposableGoodsItem.setName(disposableGoods.getShowName()); + useDiposableGoodsItem.setValidUntil(disposableGoodsBatch.getExpDateStr()); + objectDao.saveOrUpdate(useDiposableGoodsItem); + if(useRecord.getDiposableGoodsItems() == null){ + useRecord.setDiposableGoodsItems(new ArrayList()); + } + useRecord.getDiposableGoodsItems().add(useDiposableGoodsItem); + objectDao.saveOrUpdate(useRecord); + updateItemOfUseDiposableGoodsData(useDiposableGoodsItem , sendOutDiposableGoodsItem , 1L); + }else{ + //非批次定义且非高值耗材时,抛异常 } } return result; @@ -7414,222 +7519,379 @@ } } }else{ - //批次条码 - String batchBarcode = useDiposableGoodsItemJsonObject.optString("barcode"); + //批次条码(或高值耗材条件) + String batchBarcodeOrEdgBarcode = useDiposableGoodsItemJsonObject.optString("barcode"); //UseDiposableGoodsItem useDiposableGoodsItem = JSONUtil.fromJson(useDiposableGoodsItemJsonObject.toString(), UseDiposableGoodsItem.class); - //判断该批次的库存是否够 - DisposableGoodsBatch disposableGoodsBatch = - diposableGoodsManager.getDisposableGoodsBatchByBatchNumber(disposableGoodsId, - useDiposableGoodsItemJsonObject.optString("batchNo")); - if(disposableGoodsBatch == null){ - // - throw new SystemException("未找到批次号为" + useDiposableGoodsItemJsonObject.optString("batchNo") + "定义"); + if(StringUtils.isBlank(batchBarcodeOrEdgBarcode)){ + //抛异常 } - if(!StringUtils.equals(batchBarcode, disposableGoodsBatch.getBarcode())){ - // - throw new SystemException(String.format("扫描的批次条码为%s,批次号%s对应的条码为%s,两个条码不一致" , batchBarcode, - useDiposableGoodsItemJsonObject.optString("batchNo"), disposableGoodsBatch.getBarcode())); + BarcodeDevice bd = barcodeManager.getBarcodeByBarcode(batchBarcodeOrEdgBarcode); + if(bd == null){ + //抛异常 } - //如果该批次物品为修改,且数量为减小,则执行数量减小的处理(UseDiposableGoodsItem数量调小、DiposableGoodsItem表使用数量调小、ItemOfUseDisposableGoodsItem数量调小、库存增大) - /*if(amountToUse < 0){ - Long useDiposableGoodsItemId = useDiposableGoodsItemJsonObject.optLong("id"); - if(!DatabaseUtil.isPoIdValid(useDiposableGoodsItemId)){ - throw new SystemException("数据有误,未找到一次性物品使用明细id"); + DisposableGoodsBatch disposableGoodsBatch = null; + if(bd instanceof DisposableGoodsBatch){ + //判断该批次的库存是否够 + disposableGoodsBatch = + diposableGoodsManager.getDisposableGoodsBatchByBatchNumber(disposableGoodsId, + useDiposableGoodsItemJsonObject.optString("batchNo")); + if(disposableGoodsBatch == null){ + // + throw new SystemException("未找到批次号为" + useDiposableGoodsItemJsonObject.optString("batchNo") + "定义"); } - UseDiposableGoodsItem useDiposableGoodsItem = - (UseDiposableGoodsItem)objectDao.getById(UseDiposableGoodsItem.class.getSimpleName(), useDiposableGoodsItemId); - if(useDiposableGoodsItem == null){ - throw new SystemException("数据有误,未找到id为" + useDiposableGoodsItemId + "的一次性物品使用明细数据"); + if(!StringUtils.equals(batchBarcodeOrEdgBarcode, disposableGoodsBatch.getBarcode())){ + // + throw new SystemException(String.format("扫描的批次条码为%s,批次号%s对应的条码为%s,两个条码不一致" , batchBarcodeOrEdgBarcode, + useDiposableGoodsItemJsonObject.optString("batchNo"), disposableGoodsBatch.getBarcode())); } - objectDao.excuteSQL(String.format("update %s set amount=amount + %s where id=%s" , - UseDiposableGoodsItem.class.getSimpleName(), amountToUse, useDiposableGoodsItemId)); - //剩余需调整的使用数量 - long restAdjastAmount = Math.abs(amountToUse); - //循环减完为止(每次取出一条) - while(restAdjastAmount > 0){ - ItemOfUseDisposableGoodsItem itemOfUseDisposableGoodsItem = - (ItemOfUseDisposableGoodsItem)objectDao.getBySql(ItemOfUseDisposableGoodsItem.class.getSimpleName(), - " where useAmount > 0 and useDiposableGoodsItemId=" + useDiposableGoodsItemId); - if(itemOfUseDisposableGoodsItem == null){ - //已经找不到可以调整的数据,退出循环 - - break; + //如果该批次物品为修改,且数量为减小,则执行数量减小的处理(UseDiposableGoodsItem数量调小、DiposableGoodsItem表使用数量调小、ItemOfUseDisposableGoodsItem数量调小、库存增大) + /*if(amountToUse < 0){ + Long useDiposableGoodsItemId = useDiposableGoodsItemJsonObject.optLong("id"); + if(!DatabaseUtil.isPoIdValid(useDiposableGoodsItemId)){ + throw new SystemException("数据有误,未找到一次性物品使用明细id"); } - long useAmount = itemOfUseDisposableGoodsItem.getUseAmount(); - if(useAmount > restAdjastAmount){ - restAdjastAmount = 0; - itemOfUseDisposableGoodsItem.setUseAmount(useAmount - restAdjastAmount); - objectDao.saveOrUpdate(itemOfUseDisposableGoodsItem); - objectDao.excuteSQL(String.format("update %s set useAmount=useAmount + %s where id=%s" , - DiposableGoodsItem.class.getSimpleName(), restAdjastAmount, itemOfUseDisposableGoodsItem.getDiposableGoodsItemId())); - }else if(useAmount == restAdjastAmount){ - restAdjastAmount = 0; - objectDao.delete(itemOfUseDisposableGoodsItem); - objectDao.excuteSQL(String.format("update %s set useAmount=useAmount + %s where id=%s" , - DiposableGoodsItem.class.getSimpleName(), restAdjastAmount, itemOfUseDisposableGoodsItem.getDiposableGoodsItemId())); - }else{ - restAdjastAmount = restAdjastAmount - useAmount; - objectDao.delete(itemOfUseDisposableGoodsItem); - objectDao.excuteSQL(String.format("update %s set useAmount=useAmount + %s where id=%s" , - DiposableGoodsItem.class.getSimpleName(), useAmount, itemOfUseDisposableGoodsItem.getDiposableGoodsItemId())); + UseDiposableGoodsItem useDiposableGoodsItem = + (UseDiposableGoodsItem)objectDao.getById(UseDiposableGoodsItem.class.getSimpleName(), useDiposableGoodsItemId); + if(useDiposableGoodsItem == null){ + throw new SystemException("数据有误,未找到id为" + useDiposableGoodsItemId + "的一次性物品使用明细数据"); } - } - return null; - }*/ - //可以被录入使用记录的发货项id及可录入使用数据 - Map sendOutDiposableGoodsItemAmountMap = new HashMap(); - //是否为调小使用数量 - if(amountToUse < 0){ - long restUseAmountToAdjust = Math.abs(amountToUse); - List list = null; - // 查出录入了使用记录且使用数量小于发货数量-退货数量的发货明细 - list = getUsedDiposableGoodsItem(useRecord, disposableGoodsBatch.getId()); - if(list == null || list.size() == 0){ - //String err = String.format("该物品(%s)的使用数量大于发货数量!", disposableGoods.getShowName()); - //throw new RuntimeException(err); - } - for(int i=0;i 0){ + ItemOfUseDisposableGoodsItem itemOfUseDisposableGoodsItem = + (ItemOfUseDisposableGoodsItem)objectDao.getBySql(ItemOfUseDisposableGoodsItem.class.getSimpleName(), + " where useAmount > 0 and useDiposableGoodsItemId=" + useDiposableGoodsItemId); + if(itemOfUseDisposableGoodsItem == null){ + //已经找不到可以调整的数据,退出循环 + + break; + } + long useAmount = itemOfUseDisposableGoodsItem.getUseAmount(); + if(useAmount > restAdjastAmount){ + restAdjastAmount = 0; + itemOfUseDisposableGoodsItem.setUseAmount(useAmount - restAdjastAmount); + objectDao.saveOrUpdate(itemOfUseDisposableGoodsItem); + objectDao.excuteSQL(String.format("update %s set useAmount=useAmount + %s where id=%s" , + DiposableGoodsItem.class.getSimpleName(), restAdjastAmount, itemOfUseDisposableGoodsItem.getDiposableGoodsItemId())); + }else if(useAmount == restAdjastAmount){ + restAdjastAmount = 0; + objectDao.delete(itemOfUseDisposableGoodsItem); + objectDao.excuteSQL(String.format("update %s set useAmount=useAmount + %s where id=%s" , + DiposableGoodsItem.class.getSimpleName(), restAdjastAmount, itemOfUseDisposableGoodsItem.getDiposableGoodsItemId())); + }else{ + restAdjastAmount = restAdjastAmount - useAmount; + objectDao.delete(itemOfUseDisposableGoodsItem); + objectDao.excuteSQL(String.format("update %s set useAmount=useAmount + %s where id=%s" , + DiposableGoodsItem.class.getSimpleName(), useAmount, itemOfUseDisposableGoodsItem.getDiposableGoodsItemId())); + } } - - // 一次性物品库存修改 - /*String identificationIDStr = sendOutDiposableGoodsItem.getIdentificationID().toString(); - DisposableGoodsIdentification identification = - (DisposableGoodsIdentification)objectDao.getByProperty(DisposableGoodsIdentification.class.getSimpleName(), "id", Long.valueOf(identificationIDStr)); - if(identification == null){ - throw new RuntimeException("标识号已被删除!"); - } - - Long amountChange = curAmountCanUse; - diposableGoodsManager.adjustAmount(identification, amountChange); - - // 减少发货时的目标标识库存 - addTargetWarehouseAmount(sendOutDiposableGoodsItem, -amountChange); - objectDao.update(identification); - objectDao.update(identification.getBatchStock()); - objectDao.update(identification.getBatchStock().getDiposableGoods()); - - DisposableGoodsStorageAdjustVo vo = new DisposableGoodsStorageAdjustVo(); - vo.setDisposableGoodsIdentificationId(identification.getId()); - vo.setAdjustAmount(amountChange); - result.add(vo);*/ - - //本次循环的调整数量(调小则为负数) - Long ajdustAmount = null; - if(useAmount > restUseAmountToAdjust){ - ajdustAmount = restUseAmountToAdjust * -1; - sendOutDiposableGoodsItem.setUseAmount(useAmount - restUseAmountToAdjust);// 设置发货明细的已使用数量为0 - restUseAmountToAdjust = 0; - }else if(useAmount == restUseAmountToAdjust){ - ajdustAmount = useAmount * -1; - sendOutDiposableGoodsItem.setUseAmount(0L);// 设置发货明细的已使用数量为0 - restUseAmountToAdjust = 0; - }else if(useAmount < restUseAmountToAdjust){ - ajdustAmount = useAmount * -1; - sendOutDiposableGoodsItem.setUseAmount(0L);// 设置发货明细的已使用数量为0 - restUseAmountToAdjust = restUseAmountToAdjust - useAmount; - } - objectDao.update(sendOutDiposableGoodsItem); - //修改临床科室该条标识记录的库存数量 - updateDisposableStockAmount(useRecord.getDepartCoding() , sendOutDiposableGoodsItem.getId() , -1 * ajdustAmount); - - //可录入使用记录的发货项id - Long sendOutDiposableGoodsItemID = sendOutDiposableGoodsItem.getId(); - if(sendOutDiposableGoodsItemAmountMap.containsKey(sendOutDiposableGoodsItemID)){ - sendOutDiposableGoodsItemAmountMap.put(sendOutDiposableGoodsItem, sendOutDiposableGoodsItemAmountMap.get(sendOutDiposableGoodsItemID) + ajdustAmount); - }else{ - sendOutDiposableGoodsItemAmountMap.put(sendOutDiposableGoodsItem, ajdustAmount); - } - - if(restUseAmountToAdjust <= 0){// 待调整使用数量已经等于0,使用完成 - break; - } - } - }else{ - while(true){ + return null; + }*/ + //可以被录入使用记录的发货项id及可录入使用数据 + Map sendOutDiposableGoodsItemAmountMap = new HashMap(); + //是否为调小使用数量 + if(amountToUse < 0){ + long restUseAmountToAdjust = Math.abs(amountToUse); List list = null; - // 一次取10个发货明细用于录入使用记录 - list = getDiposableGoodsItemCanUse(useRecord.getDepartCoding(), disposableGoodsId , disposableGoodsBatch.getId() , 10); + // 查出录入了使用记录且使用数量小于发货数量-退货数量的发货明细 + list = getUsedDiposableGoodsItem(useRecord, disposableGoodsBatch.getId()); if(list == null || list.size() == 0){ - String err = String.format("该物品(%s)的使用数量大于发货数量!", disposableGoods.getShowName()); - throw new RuntimeException(err); + //String err = String.format("该物品(%s)的使用数量大于发货数量!", disposableGoods.getShowName()); + //throw new RuntimeException(err); } for(int i=0;i restUseAmountToAdjust){ + ajdustAmount = restUseAmountToAdjust * -1; + sendOutDiposableGoodsItem.setUseAmount(useAmount - restUseAmountToAdjust);// 设置发货明细的已使用数量为0 + restUseAmountToAdjust = 0; + }else if(useAmount == restUseAmountToAdjust){ + ajdustAmount = useAmount * -1; + sendOutDiposableGoodsItem.setUseAmount(0L);// 设置发货明细的已使用数量为0 + restUseAmountToAdjust = 0; + }else if(useAmount < restUseAmountToAdjust){ + ajdustAmount = useAmount * -1; + sendOutDiposableGoodsItem.setUseAmount(0L);// 设置发货明细的已使用数量为0 + restUseAmountToAdjust = restUseAmountToAdjust - useAmount; + } + objectDao.update(sendOutDiposableGoodsItem); //修改临床科室该条标识记录的库存数量 - updateDisposableStockAmount(useRecord.getDepartCoding(),sendOutDiposableGoodsItem.getId() , -1 * curAmountCanUse); - + updateDisposableStockAmount(useRecord.getDepartCoding() , sendOutDiposableGoodsItem.getId() , -1 * ajdustAmount); + //可录入使用记录的发货项id Long sendOutDiposableGoodsItemID = sendOutDiposableGoodsItem.getId(); if(sendOutDiposableGoodsItemAmountMap.containsKey(sendOutDiposableGoodsItemID)){ - sendOutDiposableGoodsItemAmountMap.put(sendOutDiposableGoodsItem, sendOutDiposableGoodsItemAmountMap.get(sendOutDiposableGoodsItemID) + curAmountCanUse); + sendOutDiposableGoodsItemAmountMap.put(sendOutDiposableGoodsItem, sendOutDiposableGoodsItemAmountMap.get(sendOutDiposableGoodsItemID) + ajdustAmount); }else{ - sendOutDiposableGoodsItemAmountMap.put(sendOutDiposableGoodsItem, curAmountCanUse); + sendOutDiposableGoodsItemAmountMap.put(sendOutDiposableGoodsItem, ajdustAmount); } - amountToUse -= curAmountCanUse; + if(restUseAmountToAdjust <= 0){// 待调整使用数量已经等于0,使用完成 + break; + } + } + }else{ + while(true){ + List list = null; + // 一次取10个发货明细用于录入使用记录 + list = getDiposableGoodsItemCanUse(useRecord.getDepartCoding(), disposableGoodsId , disposableGoodsBatch.getId() , 10); + if(list == null || list.size() == 0){ + String err = String.format("该物品(%s)的使用数量大于发货数量!", disposableGoods.getShowName()); + throw new RuntimeException(err); + } + for(int i=0;i 0){ - for (DiposableGoodsItem sendOutDiposableGoodsItem : sendOutDiposableGoodsItemAmountMap.keySet()) { - Long disposableGoodsBatchId = sendOutDiposableGoodsItem.getDisposableGoodsBatchID(); - DisposableGoodsBatch batch = diposableGoodsManager.getDisposableGoodsBatchById(disposableGoodsBatchId); - if(batch == null){ - //抛出异常 - } - UseDiposableGoodsItem useDiposableGoodsItem = null; - {//如果为修改,则根据批次条码找到对应的UseDiposableGoodsItem - Long useDiposableGoodsItemId = useDiposableGoodsItemJsonObject.optLong("id"); - if(!DatabaseUtil.isPoIdValid(useDiposableGoodsItemId)){ - throw new SystemException("数据有误,未找到一次性物品使用明细id"); + if(sendOutDiposableGoodsItemAmountMap.size() > 0){ + for (DiposableGoodsItem sendOutDiposableGoodsItem : sendOutDiposableGoodsItemAmountMap.keySet()) { + Long disposableGoodsBatchId = sendOutDiposableGoodsItem.getDisposableGoodsBatchID(); + DisposableGoodsBatch batch = diposableGoodsManager.getDisposableGoodsBatchById(disposableGoodsBatchId); + if(batch == null){ + //抛出异常 } - useDiposableGoodsItem = - (UseDiposableGoodsItem)objectDao.getById(UseDiposableGoodsItem.class.getSimpleName(), useDiposableGoodsItemId); - if(useDiposableGoodsItem == null){ - throw new SystemException("数据有误,未找到id为" + useDiposableGoodsItemId + "的一次性物品使用明细数据"); + Long useAmount = sendOutDiposableGoodsItemAmountMap.get(sendOutDiposableGoodsItem); + UseDiposableGoodsItem useDiposableGoodsItem = null; + {//如果为修改,则根据批次条码找到对应的UseDiposableGoodsItem + Long useDiposableGoodsItemId = useDiposableGoodsItemJsonObject.optLong("id"); + //如果使用明细的id不为有效的po对象id时,则新增使用明细 + if(DatabaseUtil.isPoIdValid(useDiposableGoodsItemId)){ + useDiposableGoodsItem = + (UseDiposableGoodsItem)objectDao.getById(UseDiposableGoodsItem.class.getSimpleName(), useDiposableGoodsItemId); + if(useDiposableGoodsItem == null){ + throw new SystemException("数据有误,未找到id为" + useDiposableGoodsItemId + "的一次性物品使用明细数据"); + } + if(useDiposableGoodsItem.getAmount() == null){ + useDiposableGoodsItem.setAmount(useAmount.intValue()); + }else{ + useDiposableGoodsItem.setAmount(useDiposableGoodsItem.getAmount() + useAmount.intValue()); + } + if(useRecord.getDiposableGoodsItems() == null){ + useRecord.setDiposableGoodsItems(new ArrayList()); + } + }else{ + DisposableGoods dg = batch.getDiposableGoods(); + useDiposableGoodsItem = new UseDiposableGoodsItem(); + useDiposableGoodsItem.setAmount(useAmount.intValue()); + useDiposableGoodsItem.setBarcode(batchBarcodeOrEdgBarcode); + useDiposableGoodsItem.setBatchNo(batch.getBatchNumber()); + useDiposableGoodsItem.setDisposableGoodsId(disposableGoodsId); + useDiposableGoodsItem.setName(dg.getShowName()); + useDiposableGoodsItem.setValidUntil(batch.getExpDateStr()); + objectDao.save(useDiposableGoodsItem); + } + useRecord.getDiposableGoodsItems().add(useDiposableGoodsItem); } - if(useDiposableGoodsItem.getAmount() == null){ - useDiposableGoodsItem.setAmount(sendOutDiposableGoodsItemAmountMap.get(sendOutDiposableGoodsItem).intValue()); - }else{ - useDiposableGoodsItem.setAmount(useDiposableGoodsItem.getAmount() + sendOutDiposableGoodsItemAmountMap.get(sendOutDiposableGoodsItem).intValue()); + updateItemOfUseDiposableGoodsData(useDiposableGoodsItem , sendOutDiposableGoodsItem , useAmount); + } + } + }else if(bd instanceof ExpensiveDisposablegoods){ + ExpensiveDisposablegoods edg = (ExpensiveDisposablegoods)bd; + //高值耗材的逻辑 + disposableGoodsBatch = + diposableGoodsManager.getDisposableGoodsBatchById(edg.getDisposableGoodsBatchID()); + if(disposableGoodsBatch == null){ + throw new SystemException("未找到条码为"+ batchBarcodeOrEdgBarcode +"的" + edg.getName() + "的批次定义"); + } + //可以被录入使用记录的发货项id及可录入使用数据map(key为业务项、value为调整数量(新扫描物品或数量变大时,数量为正数;删掉物品或数量调小时,数量为负数)) + Map sendOutDiposableGoodsItemAmountMap = new HashMap(); + //是否为调小使用数量 + if(amountToUse < 0){ + long restUseAmountToAdjust = Math.abs(amountToUse); + List list = null; + // 查出录入了使用记录且使用数量小于(发货数量-退货数量)的发货明细(通常只会有一条) + list = getUsedDiposableGoodsItemByExpensiveDisposableGoodsId(useRecord, edg.getId()); + if(CollectionUtils.isNotEmpty(list)){ + for(int i=0;i restUseAmountToAdjust){ + ajdustAmount = restUseAmountToAdjust * -1; + sendOutDiposableGoodsItem.setUseAmount(useAmount - restUseAmountToAdjust);// 设置发货明细的已使用数量为0 + restUseAmountToAdjust = 0; + }else if(useAmount == restUseAmountToAdjust){ + ajdustAmount = useAmount * -1; + sendOutDiposableGoodsItem.setUseAmount(0L);// 设置发货明细的已使用数量为0 + restUseAmountToAdjust = 0; + }else if(useAmount < restUseAmountToAdjust){ + ajdustAmount = useAmount * -1; + sendOutDiposableGoodsItem.setUseAmount(0L);// 设置发货明细的已使用数量为0 + restUseAmountToAdjust = restUseAmountToAdjust - useAmount; + } + objectDao.update(sendOutDiposableGoodsItem); + //修改临床科室该条标识记录的库存数量 + updateDisposableStockAmount(useRecord.getDepartCoding() , sendOutDiposableGoodsItem.getId() , -1 * ajdustAmount); + + //可录入使用记录的发货项id + Long sendOutDiposableGoodsItemID = sendOutDiposableGoodsItem.getId(); + if(sendOutDiposableGoodsItemAmountMap.containsKey(sendOutDiposableGoodsItemID)){ + sendOutDiposableGoodsItemAmountMap.put(sendOutDiposableGoodsItem, sendOutDiposableGoodsItemAmountMap.get(sendOutDiposableGoodsItemID) + ajdustAmount); + }else{ + sendOutDiposableGoodsItemAmountMap.put(sendOutDiposableGoodsItem, ajdustAmount); + } + + if(restUseAmountToAdjust <= 0){// 待调整使用数量已经等于0,使用完成 + break; + } } - if(useRecord.getDiposableGoodsItems() == null){ - useRecord.setDiposableGoodsItems(new ArrayList()); + } + }else{ + // 查询该高值耗材的发货明细用于录入使用记录 + List list = + getDiposableGoodsItemCanUseForExpensiveDisposableGoods(useRecord.getDepartCoding(), edg.getId()); + if(list == null || list.size() == 0){ + String err = String.format("该物品(%s)的使用数量大于发货数量!", disposableGoods.getShowName()); + throw new RuntimeException(err); + } + + DiposableGoodsItem sendOutDiposableGoodsItem = list.get(0);// 发货明细 + + Integer amount = sendOutDiposableGoodsItem.getAmount(); + Long returnedAmount = sendOutDiposableGoodsItem.getReturnedAmount(); + Long useAmount = sendOutDiposableGoodsItem.getUseAmount(); + if(returnedAmount == null){ + returnedAmount = 0L;// 兼容旧数据 + } + if(useAmount == null){ + useAmount = 0L; + } + Long sendOutItemAmountCanUse = amount - (returnedAmount + useAmount);// 发货项可使用的数量 + Long curAmountCanUse = Math.min(sendOutItemAmountCanUse, amountToUse);// 当前可使用数量 + + sendOutDiposableGoodsItem.setUseAmount(useAmount + curAmountCanUse);// 设置发货明细的已使用数量 + + objectDao.update(sendOutDiposableGoodsItem); + + //修改临床科室该条标识记录的库存数量 + updateDisposableStockAmount(useRecord.getDepartCoding(),sendOutDiposableGoodsItem.getId() , -1 * curAmountCanUse); + + //可录入使用记录的发货项id + Long sendOutDiposableGoodsItemID = sendOutDiposableGoodsItem.getId(); + if(sendOutDiposableGoodsItemAmountMap.containsKey(sendOutDiposableGoodsItemID)){ + sendOutDiposableGoodsItemAmountMap.put(sendOutDiposableGoodsItem, sendOutDiposableGoodsItemAmountMap.get(sendOutDiposableGoodsItemID) + curAmountCanUse); + }else{ + sendOutDiposableGoodsItemAmountMap.put(sendOutDiposableGoodsItem, curAmountCanUse); + } + } + // + if(sendOutDiposableGoodsItemAmountMap.size() > 0){ + for (DiposableGoodsItem sendOutDiposableGoodsItem : sendOutDiposableGoodsItemAmountMap.keySet()) { + Long disposableGoodsBatchId = sendOutDiposableGoodsItem.getDisposableGoodsBatchID(); + DisposableGoodsBatch batch = diposableGoodsManager.getDisposableGoodsBatchById(disposableGoodsBatchId); + if(batch == null){ + //抛出异常 } - useRecord.getDiposableGoodsItems().add(useDiposableGoodsItem); + //业务项对应要调整的使用数量(调大,则数量为正,调小则数量为负) + Long adjustAmount = sendOutDiposableGoodsItemAmountMap.get(sendOutDiposableGoodsItem); + UseDiposableGoodsItem useDiposableGoodsItem = null; + {//如果为修改,则根据批次条码找到对应的UseDiposableGoodsItem + Long useDiposableGoodsItemId = useDiposableGoodsItemJsonObject.optLong("id"); + if(DatabaseUtil.isPoIdValid(useDiposableGoodsItemId)){ + useDiposableGoodsItem = + (UseDiposableGoodsItem)objectDao.getById(UseDiposableGoodsItem.class.getSimpleName(), useDiposableGoodsItemId); + if(useDiposableGoodsItem.getAmount() == null){ + useDiposableGoodsItem.setAmount(adjustAmount.intValue()); + }else{ + useDiposableGoodsItem.setAmount(useDiposableGoodsItem.getAmount() + adjustAmount.intValue()); + } + }else{ + useDiposableGoodsItem = new UseDiposableGoodsItem(); + useDiposableGoodsItem.setAmount(adjustAmount.intValue()); + useDiposableGoodsItem.setBarcode(edg.getBarcode()); + useDiposableGoodsItem.setBatchNo(batch.getBatchNumber()); + useDiposableGoodsItem.setDisposableGoodsId(disposableGoodsId); + useDiposableGoodsItem.setName(batch.getDiposableGoods().getShowName()); + useDiposableGoodsItem.setValidUntil(batch.getExpDateStr()); + objectDao.saveOrUpdate(useDiposableGoodsItem); + } + + if(useRecord.getDiposableGoodsItems() == null){ + useRecord.setDiposableGoodsItems(new ArrayList()); + } + useRecord.getDiposableGoodsItems().add(useDiposableGoodsItem); + } + updateItemOfUseDiposableGoodsData(useDiposableGoodsItem , sendOutDiposableGoodsItem , adjustAmount); } - updateItemOfUseDiposableGoodsData(useDiposableGoodsItem , sendOutDiposableGoodsItem , sendOutDiposableGoodsItemAmountMap.get(sendOutDiposableGoodsItem)); } + }else{ + //非批次定义且非高值耗材时,抛异常 } } return result; @@ -7676,47 +7938,68 @@ } DiposableGoodsItem di = (DiposableGoodsItem)objectDao.getByProperty(DiposableGoodsItem.class.getSimpleName(), "id", sendoutDiposableGoodsItemId); - if(di == null || !DatabaseUtil.isPoIdValid(di.getIdentificationID())){ + if(di == null){ logger.debug("未找到sendoutDiposableGoodsItemId为"+ sendoutDiposableGoodsItemId +"的发货项数据"); return; } - // 一次性物品库存修改 - @SuppressWarnings("unchecked") - List identificationList = - objectDao.findBySql(DisposableGoodsIdentification.class.getSimpleName(), - " where warehouseID in (select id from "+ WareHouse.class.getSimpleName() +" where orgUnitCode='"+ orgUnitCode +"') " - + " and ancestorId=" + di.getIdentificationID() + " and id <> " + di.getIdentificationID()); - if(CollectionUtils.isNotEmpty(identificationList)){ - Long restAdjustUseAmountAbs = Math.abs(adjustUseAmount); - for (DisposableGoodsIdentification disposableGoodsIdentification : identificationList) { - //如果为调大,则将第一个标识的数量加上即可 - if(adjustUseAmount > 0){ - diposableGoodsManager.adjustAmount(disposableGoodsIdentification, adjustUseAmount); - objectDao.update(disposableGoodsIdentification); - objectDao.update(disposableGoodsIdentification.getBatchStock()); - objectDao.update(disposableGoodsIdentification.getBatchStock().getDiposableGoods()); - break; + //标识id + Long identificationID = di.getIdentificationID(); + if(DatabaseUtil.isPoIdValid(identificationID)){ + // 一次性物品库存修改 + @SuppressWarnings("unchecked") + List identificationList = + objectDao.findBySql(DisposableGoodsIdentification.class.getSimpleName(), + " where warehouseID in (select id from "+ WareHouse.class.getSimpleName() +" where orgUnitCode='"+ orgUnitCode +"') " + + " and ancestorId=" + di.getIdentificationID() + " and id <> " + di.getIdentificationID()); + if(CollectionUtils.isNotEmpty(identificationList)){ + Long restAdjustUseAmountAbs = Math.abs(adjustUseAmount); + for (DisposableGoodsIdentification disposableGoodsIdentification : identificationList) { + //如果为调大,则将第一个标识的数量加上即可 + if(adjustUseAmount > 0){ + diposableGoodsManager.adjustAmount(disposableGoodsIdentification, adjustUseAmount); + objectDao.update(disposableGoodsIdentification); + objectDao.update(disposableGoodsIdentification.getBatchStock()); + objectDao.update(disposableGoodsIdentification.getBatchStock().getDiposableGoods()); + break; + } + Long amount = disposableGoodsIdentification.getAmount(); + if(amount >= restAdjustUseAmountAbs){ + //否则逐个减小,每个最多只能减到0,减到没有可减为止 + diposableGoodsManager.adjustAmount(disposableGoodsIdentification, adjustUseAmount); + objectDao.update(disposableGoodsIdentification); + objectDao.update(disposableGoodsIdentification.getBatchStock()); + objectDao.update(disposableGoodsIdentification.getBatchStock().getDiposableGoods()); + restAdjustUseAmountAbs = 0L; + break; + }else{ + //否则逐个减小,每个最多只能减到0,减到没有可减为止 + diposableGoodsManager.adjustAmount(disposableGoodsIdentification, amount * -1); + objectDao.update(disposableGoodsIdentification); + objectDao.update(disposableGoodsIdentification.getBatchStock()); + objectDao.update(disposableGoodsIdentification.getBatchStock().getDiposableGoods()); + restAdjustUseAmountAbs = restAdjustUseAmountAbs - amount; + } } - Long amount = disposableGoodsIdentification.getAmount(); - if(amount >= restAdjustUseAmountAbs){ - //否则逐个减小,每个最多只能减到0,减到没有可减为止 - diposableGoodsManager.adjustAmount(disposableGoodsIdentification, adjustUseAmount); - objectDao.update(disposableGoodsIdentification); - objectDao.update(disposableGoodsIdentification.getBatchStock()); - objectDao.update(disposableGoodsIdentification.getBatchStock().getDiposableGoods()); - restAdjustUseAmountAbs = 0L; - break; + }else{ + + } + }else{ + //高值耗材id + Long edgId = di.getExpensiveDisposablegoodsId(); + if(DatabaseUtil.isPoIdValid(edgId)){ + // 一次性物品库存修改 + ExpensiveDisposablegoods edg = + (ExpensiveDisposablegoods)objectDao.getById(ExpensiveDisposablegoods.class.getSimpleName(), edgId); + if(edg != null){ + //如果为调大,则将第一个标识的数量加上即可 + DisposableGoodsBatchStock batchStock = edg.getDisposableGoodsBatchStock(); + batchStock.adjustAmount(adjustUseAmount * -1); + objectDao.update(batchStock); + objectDao.update(batchStock.getDiposableGoods()); }else{ - //否则逐个减小,每个最多只能减到0,减到没有可减为止 - diposableGoodsManager.adjustAmount(disposableGoodsIdentification, amount * -1); - objectDao.update(disposableGoodsIdentification); - objectDao.update(disposableGoodsIdentification.getBatchStock()); - objectDao.update(disposableGoodsIdentification.getBatchStock().getDiposableGoods()); - restAdjustUseAmountAbs = restAdjustUseAmountAbs - amount; + } } - }else{ - } }