Index: ssts-invoice/src/main/java/com/forgon/disinfectsystem/invoicemanager/service/InvoiceManagerImpl.java =================================================================== diff -u -r28039 -r28257 --- ssts-invoice/src/main/java/com/forgon/disinfectsystem/invoicemanager/service/InvoiceManagerImpl.java (.../InvoiceManagerImpl.java) (revision 28039) +++ ssts-invoice/src/main/java/com/forgon/disinfectsystem/invoicemanager/service/InvoiceManagerImpl.java (.../InvoiceManagerImpl.java) (revision 28257) @@ -6738,14 +6738,109 @@ return result; } + /** + * 获取消毒物品包实例的数量 + * @param invoicePlans 待发货申请单数量 + * @param tousseDefinition 固定条码包实例所属的包定义id(通常是消毒物品的祖先包定义) + * @return + */ private long getDisinfectionTousseInstanceAmount( List invoicePlans, TousseDefinition tousseDefinition) { - String sql = getDisinfectionTousseInstanceSql(invoicePlans, + if(CollectionUtils.isEmpty(invoicePlans)){ + return 0; + } + SupplyRoomConfig supplyRoomConfig = supplyRoomConfigManager.getSystemParamsObj(); + //1.查询该消毒物品待发货申请项的包定义的材料md5及待发数量 + String queryTousseItemSql = String.format("select ip.type,td.materialsMD5,td.tousseType,po.invoiceAmountMode," + + "po.amount,po.recyclingAmount,po.tallyAmount,po.tallyAmount,po.sendOutAmount from %s po " + + "join %s ip on po.recyclingApplication_ID=ip.id " + + "join %s td on po.tousseDefinitionId=td.id " + + "where td.ancestorId=%s and %s",TousseItem.class.getSimpleName(),InvoicePlan.class.getSimpleName(), + TousseDefinition.class.getSimpleName(),tousseDefinition.getId(), + SqlUtils.getNonStringFieldInLargeCollectionsPredicate("ip.id", + invoicePlans.stream().map(InvoicePlan::getId).collect(Collectors.toList()))); + Map restWaitSendAmountGroupByMaterialsMD5Map = new HashMap(); + ResultSet rs = null; + try{ + rs = objectDao.executeSql(queryTousseItemSql); + while(rs.next()){ + String invoicePlanType = rs.getString("type"); + String materialsMD5 = rs.getString("materialsMD5"); + String tousseType = rs.getString("tousseType"); + Integer invoiceAmountMode = (Integer)rs.getObject("invoiceAmountMode"); + Integer amount = (Integer)rs.getObject("amount"); + Integer recyclingAmount = (Integer)rs.getObject("recyclingAmount"); + Integer tallyAmount = (Integer)rs.getObject("tallyAmount"); + Integer sendOutAmount = (Integer)rs.getObject("sendOutAmount"); + boolean isBorrowTousseOrProxyDisinfectionOrGoodsReservationApplication = + StringUtils.equals(invoicePlanType, InvoicePlan.TYPE_BORROWINGSINGLE) + || StringUtils.equals(invoicePlanType, InvoicePlan.TYPE_PROXYDISINFECTION) + || StringUtils.equals(invoicePlanType, InvoicePlan.TYPE_GOODS_RESERVATION_FORM); + //该申请所剩待发的数量 + int shouldSendAmount = CssdUtils.getShouldDeliverAmountByTousseItemField(supplyRoomConfig.getInvoiceOrigin(), + supplyRoomConfig.getAfterRecyclingTousseDeliver(), isBorrowTousseOrProxyDisinfectionOrGoodsReservationApplication, + tousseType, invoiceAmountMode, amount, recyclingAmount, tousseDefinition.getIsRecycling(), tallyAmount); + int restWaitSendAmount = MathTools.sub(shouldSendAmount, sendOutAmount).intValue(); + if(restWaitSendAmount <= 0){ + continue; + } + Integer waitSendAmount = restWaitSendAmountGroupByMaterialsMD5Map.get(materialsMD5); + if(waitSendAmount != null){ + restWaitSendAmountGroupByMaterialsMD5Map.put(materialsMD5, MathTools.add(waitSendAmount, restWaitSendAmount).intValue()); + }else{ + restWaitSendAmountGroupByMaterialsMD5Map.put(materialsMD5, restWaitSendAmount); + } + } + }catch(Exception e){ + e.printStackTrace(); + }finally{ + DatabaseUtil.closeResultSetAndStatement(rs); + } + if(MapUtils.isEmpty(restWaitSendAmountGroupByMaterialsMD5Map)){ + return 0; + } + + /* + * 之前的逻辑由于没有按材料md5进行数量统计汇总,所以先注释不用 + * String sql = getDisinfectionTousseInstanceSql(invoicePlans, tousseDefinition); if(sql == null){ return 0; } - return objectDao.countObjectBySql(TousseInstance.class.getSimpleName(),sql); + return objectDao.countObjectBySql(TousseInstance.class.getSimpleName(),sql);*/ + + /* + * 2.查找该消毒物品可发货的包实例数量(根据材料md5进行分组统计) + * 包实例的几个查询过滤条件:包实例对应包定义的祖先id、包实例状态、失效期、包实例对应包定义的材料md5、限制发货科室 + */ + String queryTousseInstanceSql = String.format("select td.materialsMD5,count(0) cnt from %s po " + + "join %s td on po.tousseDefinition_id=td.id " + + "where td.ancestorId=%s and %s and %s and %s and %s group by td.materialsMD5",TousseInstance.class.getSimpleName(), + TousseDefinition.class.getSimpleName(),tousseDefinition.getId(), + SqlUtils.getStringFieldInLargeCollectionsPredicate("po.status", + Arrays.asList(TousseInstance.STATUS_DISINFECTED,TousseInstance.STATUS_STERILED)), + getValidUntilPredicate(dateQueryAdapter, "po.validUntil"), + SqlUtils.getStringFieldInLargeCollectionsPredicate("td.materialsMD5", + restWaitSendAmountGroupByMaterialsMD5Map.keySet()), + StringUtils.equals(Constants.STR_YES, tousseDefinition.getLimitInvoiceDepart()) ? String.format("po.departCoding='%s'",invoicePlans.get(0).getDepartCoding()) : "1=1"); + + int returnResult = 0; + rs = null; + try{ + rs = objectDao.executeSql(queryTousseInstanceSql); + while(rs.next()){ + String materialsMD5 = rs.getString("materialsMD5"); + Number cnt = (Number)rs.getObject("cnt"); + if(cnt != null && cnt.intValue() > 0){ + returnResult = MathTools.add(returnResult, Math.min(restWaitSendAmountGroupByMaterialsMD5Map.get(materialsMD5), cnt.intValue())).intValue(); + } + } + }catch(Exception e){ + e.printStackTrace(); + }finally{ + DatabaseUtil.closeResultSetAndStatement(rs); + } + return returnResult; } /** @@ -6758,7 +6853,8 @@ TousseDefinition tousseDefinition) { SupplyRoomConfig supplyRoomConfig = supplyRoomConfigManager.getSystemParamsObj(); Set invoicePlanIDSet = new HashSet(); - if (invoicePlans != null) { + if (CollectionUtils.isNotEmpty(invoicePlans)) { + String departCoding = invoicePlans.get(0).getDepartCoding(); for (InvoicePlan invoicePlan : invoicePlans) { List items = invoicePlan.getApplicationItems(); if(items == null || items.isEmpty()){ @@ -6793,31 +6889,30 @@ invoicePlanIDSet.add(invoicePlan.getId()); } } + String sql = null; + String sql2 = String.format("select t.materialsMD5 from %s t where t.materialsMD5 is not null and %s and %s", TousseDefinition.class + .getSimpleName(), SqlUtils + .getNonStringFieldPredicate("t.ancestorID",String.valueOf(tousseDefinition.getAncestorID())), SqlUtils + .getNonStringFieldInLargeCollectionsPredicate( + "t.invoicePlanID", invoicePlanIDSet)); + List materialsMD5List = objectDao.findByHql(sql2); + Set materialsMD5Set = new HashSet(); + if(materialsMD5List != null){ + materialsMD5Set.addAll(materialsMD5List); + } + sql = String + .format(" where %s and %s and (%s and po.tousseFixedBarcode=false and %s and %s)", + SqlUtils.getStringFieldInLargeCollectionsPredicate("po.status", + Arrays.asList(TousseInstance.STATUS_DISINFECTED,TousseInstance.STATUS_STERILED)), + getValidUntilPredicate(dateQueryAdapter, "po.validUntil"), + SqlUtils.getNonStringFieldPredicate("po.tousseDefinition.ancestorID", + String.valueOf(tousseDefinition.getAncestorID())), + SqlUtils.getStringFieldInLargeCollectionsPredicate( + "po.tousseDefinition.materialsMD5", materialsMD5Set), + StringUtils.equals(Constants.STR_YES, tousseDefinition.getLimitInvoiceDepart()) ? String.format("po.departCoding='%s'",departCoding) : "1=1"); + return sql; } - if (invoicePlanIDSet.isEmpty()) { - return null; - } - String sql = null; - String sql2 = String.format("select t.materialsMD5 from %s t where t.materialsMD5 is not null and %s and %s", TousseDefinition.class - .getSimpleName(), SqlUtils - .getNonStringFieldPredicate("t.ancestorID",String.valueOf(tousseDefinition.getAncestorID())), SqlUtils - .getNonStringFieldInLargeCollectionsPredicate( - "t.invoicePlanID", invoicePlanIDSet)); - List materialsMD5List = objectDao.findByHql(sql2); - Set materialsMD5Set = new HashSet(); - if(materialsMD5List != null){ - materialsMD5Set.addAll(materialsMD5List); - } - sql = String - .format(" where %s and %s and (%s and po.tousseFixedBarcode=false and %s )", - SqlUtils.getStringFieldInLargeCollectionsPredicate("po.status", - Arrays.asList(TousseInstance.STATUS_DISINFECTED,TousseInstance.STATUS_STERILED)), - getValidUntilPredicate(dateQueryAdapter, "po.validUntil"), - SqlUtils.getNonStringFieldPredicate("po.tousseDefinition.ancestorID", - String.valueOf(tousseDefinition.getAncestorID())), - SqlUtils.getStringFieldInLargeCollectionsPredicate( - "po.tousseDefinition.materialsMD5", materialsMD5Set)); - return sql; + return null; } // 重新排序待发货物品(排序顺序一次性物品,器械包,消毒物品)