Index: ssts-invoice/src/main/java/com/forgon/disinfectsystem/invoicemanager/service/InvoiceManagerImpl.java =================================================================== diff -u -r16096 -r16112 --- ssts-invoice/src/main/java/com/forgon/disinfectsystem/invoicemanager/service/InvoiceManagerImpl.java (.../InvoiceManagerImpl.java) (revision 16096) +++ ssts-invoice/src/main/java/com/forgon/disinfectsystem/invoicemanager/service/InvoiceManagerImpl.java (.../InvoiceManagerImpl.java) (revision 16112) @@ -6270,7 +6270,7 @@ mergeTousseRuleForInvoiceBatchPrint = supplyRoomConfig.getMergeTousseRuleForInvoiceBatchPrint(); } - List recycleAmountInfo = getTousseRecyclingAmount(invoices); + Map recycleAmountInfo = getTousseRecyclingAmount(invoices); for (Invoice invoice : invoices) { List tousseList = invoiceTousseInstances.get(invoice.getId());//invoice.getTousseInstances(objectDao); @@ -6326,13 +6326,7 @@ tempVo = new InvoicePrintVo(); tempVo.setAmount(1); - if(invoice.isCustomInvoice() || invoice.isOperationReservationInvoice()){ - //自定义发货与手术预约发货,实收数量为0 - tempVo.setRecyclingAmount(0); - }else{ - tempVo.setRecyclingAmount(getTousseActualRecycleAmount(recycleAmountInfo, tousseDefinition.getAncestorID())); - } - + tempVo.setRecyclingAmount(getTousseActualRecycleAmount(recycleAmountInfo, tousseDefinition)); tempVo.setSendDate(invoice.getSendTime()); tempVo.setFrequency(frequency); tempVo.setName(tousseInstance.getTousseName()); @@ -6358,18 +6352,18 @@ * @param invoices * @return */ - private List getTousseRecyclingAmount(Collection invoices){ - List temp = new ArrayList(); + private Map getTousseRecyclingAmount(Collection invoices){ + Map temp = new HashMap(); if(CollectionUtils.isNotEmpty(invoices)){ List invoiceIds = invoices.stream().map(i->i.getId()).collect(Collectors.toList()); if(CollectionUtils.isNotEmpty(invoiceIds)){ - String idpredicate = SqlUtils.getNonStringFieldInCollectionsPredicate("i.id", invoiceIds); - String sql = "select m.ancestorID,m.isRecycling,m.tousseType,m.type,sum(m.recyclingAmount) as recyclingAmount,sum(m.amount) as amount from ( " + - " select td.ancestorID,td.isRecycling,td.tousseType,ti.recyclingAmount,ti.amount,ti.recyclingApplication_ID,ip.type from " + TousseItem.class.getSimpleName() - + " ti inner join " + TousseDefinition.class.getSimpleName() + " td on td.id = ti.tousseDefinitionId" - + " inner join " + InvoicePlan.class.getSimpleName() + " ip on ip.id = ti.recyclingApplication_ID" - + " ) m where m.recyclingApplication_ID in (select i.invoicePlan_ID from " + Invoice.class.getSimpleName() - + " i where "+idpredicate+") group by m.ancestorID,m.isRecycling,m.tousseType,m.type"; + String idpredicate = SqlUtils.getNonStringFieldInCollectionsPredicate("m.invoiceId", invoiceIds); + String sql = "select m.ancestorID,m.isRecycling,m.tousseType,m.invoicePlanType,sum(m.recyclingAmount) as recyclingAmount,sum(m.amount) as amount from ( " + + " select i.id as invoiceId,td.ancestorID,td.isRecycling,td.tousseType,ti.recyclingAmount,ti.amount,ti.recyclingApplication_ID,i.invoicePlanType from " + Invoice.class.getSimpleName() + + " i left join " + TousseItem.class.getSimpleName() + " ti on ti.recyclingApplication_ID=i.invoicePlan_ID " + + " left join " + TousseDefinition.class.getSimpleName() + " td on td.id = ti.tousseDefinitionId" + +") m where " +idpredicate + + " group by m.ancestorID,m.isRecycling,m.tousseType,m.invoicePlanType"; logger.debug("实收数量sql:" + sql); ResultSet rs = objectDao.executeSql(sql); if(rs != null){ @@ -6380,16 +6374,32 @@ int amount = rs.getInt("amount"); String tousseType = rs.getString("tousseType"); String isRecycling = rs.getString("isRecycling"); - String invoicePlanType = rs.getString("type"); + String invoicePlanType = rs.getString("invoicePlanType"); - TousseActualRecyclingAmount tara = new TousseActualRecyclingAmount(); - tara.setAmount(amount); - tara.setAncestorID(tousseDefinitionId); - tara.setRecyclingAmount(recyclingAmount); - tara.setTousseType(tousseType); - tara.setIsRecycling(isRecycling); - tara.setInvoicePlanType(invoicePlanType); - temp.add(tara); + int addAmount = 0; + + if(StringTools.equals(invoicePlanType, InvoicePlan.TYPE_BORROWINGSINGLE) + || StringTools.equals(invoicePlanType, Invoice.TYPE_CUSTOM) + || StringTools.equals(invoicePlanType, InvoicePlan.TYPE_OPERATION_RESERVATION_APPLICATION)){ + addAmount = 0; + }else if(StringTools.equals(tousseType, TousseDefinition.PACKAGE_TYPE_SPLIT) + || StringTools.equals(invoicePlanType, InvoicePlan.TYPE_FOREIGNPROXYDISINFECTION)){ + //外来器械拆分小包,或者外部代理灭菌申请单,数量为发货数量。值为-1由调用者重新设置 + addAmount = -1; + }else if(TousseDefinition.PACKAGE_TYPE_DRESSING.equals(tousseType) + || TousseDefinition.STR_NO.equals(isRecycling)){ + addAmount = amount; + }else{ + addAmount = recyclingAmount; + } + + if(DatabaseUtil.isPoIdValid(tousseDefinitionId)){ + if(addAmount == -1){ + temp.put(tousseDefinitionId, addAmount); + }else{ + temp.put(tousseDefinitionId, MathTools.add(temp.get(tousseDefinitionId), addAmount).intValue()); + } + } } } catch (SQLException e) { e.printStackTrace(); @@ -6399,26 +6409,7 @@ } } } - //因为有可能一次打印中有多张类型的单,需要把不同类型的单的数量合并,最终为根据包定义id获取实际数量 - List mergeAmount = new ArrayList(); - for(TousseActualRecyclingAmount tara : temp){ - TousseActualRecyclingAmount find = CollectionUtils.find(mergeAmount, new Predicate(){ - @Override - public boolean evaluate(TousseActualRecyclingAmount object) { - if(tara.getAncestorID()!=null && object.getAncestorID()!=null - && tara.getAncestorID().longValue() == object.getAncestorID().longValue()){ - return true; - } - return false; - } - }); - if(find == null){ - mergeAmount.add(tara); - }else{ - find.merge(tara); - } - } - return mergeAmount; + return temp; } /** @@ -6476,7 +6467,7 @@ if(supplyRoomConfig != null){ mergeTousseRuleForInvoiceBatchPrint = supplyRoomConfig.getMergeTousseRuleForInvoiceBatchPrint(); } - List recycleAmountInfo = getTousseRecyclingAmount(invoices); + Map recycleAmountInfo = getTousseRecyclingAmount(invoices); List voList = new ArrayList(); for (Invoice invoice : invoices) { List tousseList = invoice.getTousseInstances(objectDao); @@ -6490,7 +6481,7 @@ String frequency = tousseInstance.getSterileFrequency();// 炉次 String tousseName = tousseInstance.getTousseName(); - InvoicePrintVo tempVo = findInvoicePrintVoForTousseMerge(voList, tousseInstance, 1); + InvoicePrintVo tempVo = findInvoicePrintVoForTousseMerge(voList, tousseInstance, mergeTousseRuleForInvoiceBatchPrint); if (tempVo != null) { tempVo.setAmount(tempVo.getAmount() + 1); @@ -6502,12 +6493,7 @@ tempVo = new InvoicePrintVo(); tempVo.setAmount(1); - if(invoice.isCustomInvoice() || invoice.isOperationReservationInvoice()){ - //自定义发货与手术预约发货,实收数量为0 - tempVo.setRecyclingAmount(0); - }else{ - tempVo.setRecyclingAmount(getTousseActualRecycleAmount(recycleAmountInfo, tousseDefinition.getAncestorID())); - } + tempVo.setRecyclingAmount(getTousseActualRecycleAmount(recycleAmountInfo,tousseDefinition)); tempVo.setSendDate(invoice.getSendTime()); tempVo.setFrequency(frequency); tempVo.setName(tousseInstance.getTousseName()); @@ -6637,21 +6623,19 @@ } return null; } - private Integer getTousseActualRecycleAmount(List recycleAmountInfo, - Long ancestorID){ - if(CollectionUtils.isNotEmpty(recycleAmountInfo) && ancestorID != null){ - for(TousseActualRecyclingAmount tara : recycleAmountInfo){ - if(tara != null){ - if(tara.getAncestorID().longValue() == ancestorID.longValue()){ - return tara.getActualRecyclingAmount(); - } + private Integer getTousseActualRecycleAmount(Map recycleAmountInfo, + TousseDefinition td){ + if(td != null && DatabaseUtil.isPoIdValid(td.getAncestorID())){ + Integer amount = recycleAmountInfo.get(td.getAncestorID()); + if(amount == null){ + if(td.isSplit()){ + return -1; } + }else{ + return amount; } } - /** - * 返回-1,最终会由调用方设置为发货数量 - */ - return -1; + return 0; } /** * 消毒物品发货单打印数据 @@ -6664,7 +6648,7 @@ if(CollectionUtils.isEmpty(invoices) || invoiceTousseInstances == null || invoiceTousseInstances.size() <=0) return CollectionUtils.emptyCollection(); - List recycleAmountInfo = getTousseRecyclingAmount(invoices); + Map recycleAmountInfo = getTousseRecyclingAmount(invoices); Map map = new HashMap(); for (Invoice invoice : invoices) { List tousseList = invoiceTousseInstances.get(invoice.getId()); @@ -6717,16 +6701,11 @@ invoicePrintVo.setSterilizerName(tousseInstance.getSterilizerName()); invoicePrintVo.setFrequency(tousseInstance.getSterileFrequency()); - if(invoice.isCustomInvoice() || invoice.isOperationReservationInvoice()){ - //自定义发货与手术预约发货,实收数量为0 - invoicePrintVo.setRecyclingAmount(0); - }else{ - Integer recyclingAmount = getTousseActualRecycleAmount(recycleAmountInfo,tousseDefinition.getAncestorID()); - if(!tousseDefinition.applyEntireTousse()){ - recyclingAmount = MathTools.mul(materialJson.getInt("totalAmout"), recyclingAmount).intValue(); - } - invoicePrintVo.setRecyclingAmount(recyclingAmount); + Integer recyclingAmount = getTousseActualRecycleAmount(recycleAmountInfo,tousseDefinition); + if(!tousseDefinition.applyEntireTousse()){ + recyclingAmount = MathTools.mul(materialJson.getInt("totalAmout"), recyclingAmount).intValue(); } + invoicePrintVo.setRecyclingAmount(recyclingAmount); invoicePrintVo.setSendDate(invoice.getSendTime()); if(tousseDefinition.applyEntireTousse()){