Index: ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/util/DepartmentMonthDetailHelper.java =================================================================== diff -u -r37828 -r37835 --- ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/util/DepartmentMonthDetailHelper.java (.../DepartmentMonthDetailHelper.java) (revision 37828) +++ ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/util/DepartmentMonthDetailHelper.java (.../DepartmentMonthDetailHelper.java) (revision 37835) @@ -2,6 +2,7 @@ import java.sql.ResultSet; import java.sql.SQLException; +import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -619,8 +620,19 @@ } String comboTousseSendByWrapperTousse = CssdUtils.getSystemSetConfigByName("comboTousseSendByWrapperTousse"); String priceSql = null; - if(queryUrgent){//加急要过滤到包实例 - if(urgentLevel.equals("0")){//单选无 只查询不加急数据 + boolean enableConsolidateByPriceOfMonthlyReport = CssdUtils.getSystemSetConfigByNameBool("enableConsolidateByPriceOfMonthlyReport", false); + enableConsolidateByPriceOfMonthlyReport = true; + String fluctuationPriceOfTi = null; + if(enableConsolidateByPriceOfMonthlyReport){ + fluctuationPriceOfTi = ",ti.fluctuationPrice "; + } + if(queryUrgent || enableConsolidateByPriceOfMonthlyReport){//加急要过滤到包实例 + if(StringUtils.isBlank(tousseInstanceJoinTousseDefinitionSql)){ + tousseInstanceJoinTousseDefinitionSql = " join TousseDefinition td on td.id=ti.tousseDefinition_id "; + } + if(enableConsolidateByPriceOfMonthlyReport){ + urgentSql = ""; + }else if(urgentLevel.equals("0")){//单选无 只查询不加急数据 urgentSql = " and ti.urgentLevel_id is null "; }else if(urgentLevel.contains("0")){//查询无和其他的加急 urgentSql = " and (ti.urgentLevel_id is null or "+ SqlUtils.getNonStringFieldInLargeCollectionsPredicate("ti.urgentLevel_id", SqlUtils.splitStringToSet(urgentLevel, ",")) +" )"; @@ -643,7 +655,8 @@ + tdcTousseGroupNameSQL + groupByIsendTimeOfShowTime + groupByIsendTime + unitSqlOftousseDefinitionSql +",i.settleAccountsDepart,td.tousseType,td.name,td.id " - + tousseDefinitionOfSupplierNameSql + integralOftousseDefinitionSql; + + tousseDefinitionOfSupplierNameSql + integralOftousseDefinitionSql + + fluctuationPriceOfTi; String groupBySqlOfT = "group by depart" + showTimeOfT + sendTimeOfT @@ -652,6 +665,9 @@ +",settleAccountsDepart,type,name,tousseDefinitionId " + getRemovePrefixSql(tousseDefinitionOfSupplierNameSql) + getRemovePrefixSql(integralOftousseDefinitionSql); + if(enableConsolidateByPriceOfMonthlyReport){ + groupBySqlOfT +=",fluctuationPrice "; + } tousseSql = " select "+ sumMaterialAmountSql +"depart,settleAccountsDepart" + showTimeOfT + sendTimeOfT @@ -673,6 +689,7 @@ + unitSqlOftousseDefinitionSql + ",'' as batchNumber,null as expDate,td.id as tousseDefinitionId" + tdcTousseGroupNameSQL + + fluctuationPriceOfTi + " from invoice i " + "join TousseInstance ti on ti.invoice_id=i.id " + tousseInstanceJoinTousseDefinitionSql @@ -700,6 +717,7 @@ + unitSqlOftousseDefinitionSql + ",'' as batchNumber,null as expDate,td.id as tousseDefinitionId" + tdcTousseGroupNameSQL + + fluctuationPriceOfTi + " from invoice i " + "join TousseInstance ti on ti.invoice2_id=i.id " + tousseInstanceJoinTousseDefinitionSql @@ -818,7 +836,7 @@ + iDepartCodingSql + nameFilterSql + onlyQueryTousse - + " group by i.depart"+ groupByIsendTimeOfShowTime + groupByIsendTime +unitDGroupBySqlOfDiposableGoodsItem +",i.settleaccountsdepart,d.name,d.batch,dgbs.expDate "+ dgbsOfSupplierNameSql +") "; + + " group by "+ (enableConsolidateByPriceOfMonthlyReport?"d.fluctuationPrice,":"") +"i.depart"+ groupByIsendTimeOfShowTime + groupByIsendTime +unitDGroupBySqlOfDiposableGoodsItem +",i.settleaccountsdepart,d.name,d.batch,dgbs.expDate "+ dgbsOfSupplierNameSql +") "; }else{ if(typeSearch.contains("高值耗材")){ diposableGoodsSql += " union all (select "+ noMaterialAmountSql +" i.depart,i.settleaccountsdepart " + iSendTimeSqlOfShowTime + iSendTime + dgbsOfSupplierNameSql+noQueryIntegralSql +",d.name as name,sum(d.amount) as amount," @@ -970,7 +988,7 @@ } //退货(一次性物品、器械包) String returnGoodsSql = null; - if(queryUrgent){ + if(queryUrgent || enableConsolidateByPriceOfMonthlyReport){ returnGoodsSql = " union all (select " + tousseInstanceMaterialAmountSql +" rr.depart,rr.settleAccountsDepart as settleaccountsdepart " @@ -1003,11 +1021,40 @@ + instrumentSetTypesSql +" and "+returnGoodsItemPredicate + " group by rr.depart" - + tdcTousseGroupNameSQL; + + tdcTousseGroupNameSQL + + fluctuationPriceOfTi; if(queryUnit){ returnGoodsSql += ",ri.disposableGoodsID,td.unit "; } returnGoodsSql += groupByRrReturnTimeOfShowTime + ",rr.settleAccountsDepart,td.name,td.tousseType,td.id) "; + if(enableConsolidateByPriceOfMonthlyReport){ + returnGoodsSql += " union all (select "+ returnGoodsItemMaterialAmountSql +"rr.depart,rr.settleAccountsDepart as settleaccountsdepart " + + rrReturnTimeSqlOfShowTime + noSendTime +dgbsOfSupplierNameSql + noQueryIntegralSql+",ri.toussename as name," + + "-sum(ri.amount) as amount,-sum(ri.settlementPrice) as settlementprice,-sum(ri.settlementPrice) as settlementDiscountPrice," + +" rr.type "; + if(queryUnit){ + returnGoodsSql += ",(select unit from DisposableGoods where id=ri.disposableGoodsID) unit"; + } + returnGoodsSql += ",ri.batchNumber as batchNumber,dgbs.expDate,null as tousseDefinitionId" + + nullTousseGroupNameSQL + + " from " + ReturnGoodsRecord.class.getSimpleName() + " rr inner join " + + ReturnGoodsItem.class.getSimpleName()+ " ri on rr.id = ri.returngoodsrecord_id " + + " left join " + TousseDefinition.class.getSimpleName() + " td on td.id = ri.tousseDefinition_id" + + " join " + DisposableGoodsBatchStock.class.getSimpleName() + " dgbs on ri.disposableGoodsBatchStockID=dgbs.id" + + " join " + DisposableGoods.class.getSimpleName() + " d on d.id=dgbs.disposableGoodsId " + + " where ri.tousseDefinition_id is null and " + + getHandleDeptCodeSql("rr.handleDepartCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + + returnGoodsFilterSql + + rrSettleAccountsDepartCodingSql + +" and "+returnGoodsItemPredicate + + instrumentSetTypesSql + + " group by rr.depart, ri.fluctuationPrice"; + if(queryUnit){ + returnGoodsSql += ",ri.disposableGoodsID "; + } + returnGoodsSql += groupByRrReturnTimeOfShowTime + ",rr.settleAccountsDepart,ri.toussename,rr.type,ri.batchNumber"+ groupByMaterialAmountAtThatTime + dgbsOfSupplierNameSql +",dgbs.expDate) "; + + } }else{ returnGoodsSql = " union all (select "+ returnGoodsItemMaterialAmountSql +"rr.depart,rr.settleAccountsDepart as settleaccountsdepart " + rrReturnTimeSqlOfShowTime + noSendTime +dgbsOfSupplierNameSql + noQueryIntegralSql+",ri.toussename as name," + "-sum(ri.amount) as amount,-sum(ri.settlementPrice) as settlementprice,-sum(ri.settlementPrice) as settlementDiscountPrice," @@ -1029,7 +1076,7 @@ +" and "+returnGoodsItemPredicate + instrumentSetTypesSql //按整包发货的聚合包单独查询 - + " and ri.id not in (select ti.returnGoodsItem_ID from "+ InvoiceItem.class.getSimpleName() +" ii join "+ TousseInstance.class.getSimpleName() +" ti on ti.id=ii.comboTousseInstanceId ) " + + " and NOT EXISTS (select 1 from "+ InvoiceItem.class.getSimpleName() +" ii join "+ TousseInstance.class.getSimpleName() +" ti on ti.id=ii.comboTousseInstanceId where ri.id = ti.returnGoodsItem_ID ) " + " group by rr.depart" + tdcTousseGroupNameSQL; if(queryUnit){ @@ -1065,7 +1112,7 @@ +" and "+returnGoodsItemPredicate + instrumentSetTypesSql //聚合包单独查询 - + " and td.tousseType='"+ TousseDefinition.PACKAGE_TYPE_COMBO +"' and ri.id not in (select ti.returnGoodsItem_ID from "+ InvoiceItem.class.getSimpleName() +" ii join "+ TousseInstance.class.getSimpleName() +" ti on ti.id=ii.comboTousseInstanceId ) " + + " and td.tousseType='"+ TousseDefinition.PACKAGE_TYPE_COMBO +"' and NOT EXISTS (select 1 from "+ InvoiceItem.class.getSimpleName() +" ii join "+ TousseInstance.class.getSimpleName() +" ti on ti.id=ii.comboTousseInstanceId where ri.id = ti.returnGoodsItem_ID) " + " group by rr.depart " + tdcTousseGroupNameSQL; if(queryUnit){ @@ -1318,6 +1365,9 @@ }finally { DatabaseUtil.closeResultSetAndStatement(rs); } + //DGSHLYY-33 【明细核算月报】单价不同时根据实际价格合并显示 + + DecimalFormat df = new DecimalFormat("0.0000"); for(Entry> entry : detailMap.entrySet()){ String departKey = entry.getKey(); List list = entry.getValue(); @@ -1339,9 +1389,25 @@ } else{ key = tousseName; } + if(showBatch){ + if(StringUtils.isBlank(key)){ + key = StringUtils.isBlank(dmi.getBatchNumber())?"":dmi.getBatchNumber(); + }else{ + key += StringUtils.isBlank(dmi.getBatchNumber())?"":dmi.getBatchNumber(); + } + } + if(enableConsolidateByPriceOfMonthlyReport){ + if(StringUtils.isBlank(key)){ + key = df.format(dmi.getAmount() == 0?dmi.getPrice(): 100.0000d * dmi.getSettlementPrice() / dmi.getAmount()); + }else{ + key += df.format(dmi.getAmount() == 0?dmi.getPrice(): 100.0000d * dmi.getSettlementPrice() / dmi.getAmount()); + } + } String type = dmi.getType(); if (TousseDefinition.PACKAGE_TYPE_DISINFECTION.equals(type) - || TousseDefinition.PACKAGE_TYPE_CUSTOM.equals(type) || TousseDefinition.PACKAGE_TYPE_FOREIGN.equals(type) || TousseDefinition.PACKAGE_TYPE_SPLIT.equals(type)) { + || TousseDefinition.PACKAGE_TYPE_CUSTOM.equals(type) + || TousseDefinition.PACKAGE_TYPE_FOREIGN.equals(type) + || TousseDefinition.PACKAGE_TYPE_SPLIT.equals(type)) { DepartmentMonthDetailItem item = tmpMap.get(key); if(item == null){ item = new DepartmentMonthDetailItem(); @@ -1374,10 +1440,10 @@ item.setSettlementDiscountPrice(MathTools.add(item.getSettlementDiscountPrice(), dmi.getSettlementDiscountPrice()).doubleValue()); item.setType(type); item.setExternalCode(item.getExternalCode()); - double price = item.getAmount() == 0?dmi.getPrice(): item.getSettlementPrice() / item.getAmount(); + double price = item.getAmount() == 0?dmi.getPrice() : 1.0000d * item.getSettlementPrice() / item.getAmount(); item.setPrice(price); removeItems.add(dmi); - }else if(!showBatch && DisposableGoods.TYPE_NAME.equals(type)){//一次性物品 + }else if(DisposableGoods.TYPE_NAME.equals(type)){//一次性物品 DepartmentMonthDetailItem item = null; if(disposableGoodsTempMap.containsKey(key)){ item = disposableGoodsTempMap.get(key); @@ -1392,15 +1458,14 @@ item.setSettlementDiscountPrice(MathTools.add(item.getSettlementDiscountPrice(), dmi.getSettlementDiscountPrice()).doubleValue()); item.setType(type); item.setExternalCode(item.getExternalCode()); - double price = item.getAmount() == 0?dmi.getPrice(): item.getSettlementPrice() / item.getAmount(); + double price = item.getAmount() == 0?dmi.getPrice(): 1.0000d * item.getSettlementPrice() / item.getAmount(); item.setPrice(price); - removeItems.add(dmi); }else{ - dmi.setBatchNumber(null); dmi.setExpDate(null); dmi.setSendTime(sendTime); disposableGoodsTempMap.put(key, dmi); } + removeItems.add(dmi);//解决不显示一次性物品批次时 查询数据可能重复的问题 } totalPrice += dmi.getSettlementPrice(); totalPriceDiscount += dmi.getSettlementDiscountPrice(); @@ -1459,17 +1524,44 @@ public int compare(DepartmentMonthDetailItem o1, DepartmentMonthDetailItem o2) { if(showSendTime){ return o1.getSendTime().compareTo(o2.getSendTime()); - }else{ - if (o1.getTypeOrder() == o2.getTypeOrder()) { - return (o1.getGoodsName()+o1.getSpecification()).compareTo((o2.getGoodsName()+o2.getSpecification())); - } else { - if(o1.getTypeOrder() > o2.getTypeOrder()){ - return 1; - }else{ - return -1; - } - } } + int typeorder = Integer.compare(o1.getTypeOrder(), o2.getTypeOrder()); + if (typeorder != 0) { + return typeorder; + } + String o1GoodsName = o1.getGoodsName(); + if(StringUtils.isBlank(o1GoodsName)){ + o1GoodsName = ""; + } + String o2GoodsName = o2.getGoodsName(); + if(StringUtils.isBlank(o2GoodsName)){ + o2GoodsName = ""; + } + int departReuslt = o1GoodsName.compareTo(o2GoodsName); + if (departReuslt != 0) { + return departReuslt; + } + String o1Specification = o1.getSpecification(); + if(StringUtils.isBlank(o1Specification)){ + o1Specification = ""; + } + String o2Specification = o2.getSpecification(); + if(StringUtils.isBlank(o2Specification)){ + o2Specification = ""; + } + departReuslt = o1Specification.compareTo(o2Specification); + if (departReuslt != 0) { + return departReuslt; + } + String o1BatchNumber = o1.getBatchNumber(); + if(StringUtils.isBlank(o1BatchNumber)){ + o1BatchNumber = ""; + } + String o2BatchNumber = o2.getBatchNumber(); + if(StringUtils.isBlank(o2BatchNumber)){ + o2BatchNumber = ""; + } + return o1BatchNumber.compareTo(o2BatchNumber); } }); }