Index: ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/util/MonthReportHelper.java =================================================================== diff -u --- ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/util/MonthReportHelper.java (revision 0) +++ ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/util/MonthReportHelper.java (revision 35792) @@ -0,0 +1,1211 @@ +package com.forgon.disinfectsystem.jasperreports.util; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; + +import com.forgon.Constants; +import com.forgon.directory.acegi.tools.AcegiHelper; +import com.forgon.directory.model.BrancheOfHospital; +import com.forgon.directory.model.OrgUnit; +import com.forgon.directory.vo.LoginUserData; +import com.forgon.disinfectsystem.basedatamanager.supplyroomconfig.service.SupplyRoomConfigManager; +import com.forgon.disinfectsystem.common.CssdUtils; +import com.forgon.disinfectsystem.entity.assestmanagement.ExpensiveGoods; +import com.forgon.disinfectsystem.entity.basedatamanager.supplyroomconfig.SupplyRoomConfig; +import com.forgon.disinfectsystem.entity.basedatamanager.toussedefinition.TousseDefinition; +import com.forgon.disinfectsystem.entity.invoicemanager.Invoice; +import com.forgon.disinfectsystem.entity.invoicemanager.InvoiceItem; +import com.forgon.disinfectsystem.entity.invoicemanager.InvoicePlan; +import com.forgon.disinfectsystem.entity.materialerrordamage.MaterialErrorDamageDetail; +import com.forgon.disinfectsystem.entity.tousseitem.TousseItem; +import com.forgon.disinfectsystem.jasperreports.javabeansource.MonthReportBean; +import com.forgon.tools.db.DatabaseUtil; +import com.forgon.tools.format.ConvertNumber; +import com.forgon.tools.util.SqlUtils; +/** + * 核算月报 + * + */ +public class MonthReportHelper extends ReportHelper{ + @Autowired + protected SupplyRoomConfigManager supplyRoomConfigManager; + public List getMonthReportData(String startDate,String endDate, + String department,String tousseType,String disposableGoodsType,Boolean showCustonTousseAmount, String patternOfReport, Map departToBrancheOfHospitalMap, boolean filterBrancheOfHospital, boolean hideAmountColumn, boolean showApplicationDepart, String invoicePlanDepartCoding, Map columnConfigOfAccountingInfoMap, boolean queryWhetherToCharge){ +// String handleDeptCode = AcegiHelper.getLoginUser().getOrgUnitCodingFromSupplyRoomConfig(); + Set departments = null; + if(filterBrancheOfHospital && !(departToBrancheOfHospitalMap == null || departToBrancheOfHospitalMap.isEmpty())){ + departments = departToBrancheOfHospitalMap.keySet(); + } + Map nameToBrevityCodeMap = new HashMap(); + if("dgshlyyMode".equals(patternOfReport)){ + String querySql = "select name,brevityCode from "+ OrgUnit.class.getSimpleName() +" where 1=1 " + SqlUtils.getIsNotNullSql(dbConnection, "brevityCode") + " order by status asc "; + nameToBrevityCodeMap = objectDao.getKeyAndValueAreBothStringMap(querySql); + } + //启用排除属于科研项目的一次性物品申请单的发货数据 + boolean excludeSciProjectInfo = CssdUtils.getSystemSetConfigByNameBool("enableExcludeInvoiceItemOfDisposableGoodsApplicationBelongToSciProject", false); + //核算月报中单独显示属于科研项目的一次性物品申请单发货的总金额 + boolean showTotalMoneyOfSciProjectDisposableGoodsInvoiceInAccountingMonthlyReport = CssdUtils.getSystemSetConfigByNameBool("showTotalMoneyOfSciProjectDisposableGoodsInvoiceInAccountingMonthlyReport", false); + String insideAmountShowName = null;//器械包数量显示名 + if(columnConfigOfAccountingInfoMap.containsKey("器械包数量")){ + insideAmountShowName = columnConfigOfAccountingInfoMap.get("器械包数量"); + }else{ + insideAmountShowName = "器械包数量"; + } + String disposableAmountShowName = null;//一次性物品数量显示名 + if(columnConfigOfAccountingInfoMap.containsKey("一次性物品数量")){ + disposableAmountShowName = columnConfigOfAccountingInfoMap.get("一次性物品数量"); + }else{ + disposableAmountShowName = "一次性物品数量"; + } + String errorDamageAmountShowName = null;//丢失报损材料数量显示名 + if(columnConfigOfAccountingInfoMap.containsKey("丢失报损材料数量")){ + errorDamageAmountShowName = columnConfigOfAccountingInfoMap.get("丢失报损材料数量"); + }else{ + errorDamageAmountShowName = "丢失报损材料数量"; + } + String insidePriceShowName = null;//器械包总价显示名 + if(columnConfigOfAccountingInfoMap.containsKey("器械包总价")){ + insidePriceShowName = columnConfigOfAccountingInfoMap.get("器械包总价"); + }else{ + insidePriceShowName = "器械包总价"; + } + String errorDamagePriceShowName = null;//丢失报损材料显示名 + if(columnConfigOfAccountingInfoMap.containsKey("丢失报损材料总价")){ + errorDamagePriceShowName = columnConfigOfAccountingInfoMap.get("丢失报损材料总价"); + }else{ + errorDamagePriceShowName = "丢失报损材料总价"; + } + String disposablePriceShowName = null;//一次性物品总价显示名 + if(columnConfigOfAccountingInfoMap.containsKey("一次性物品总价")){ + disposablePriceShowName = columnConfigOfAccountingInfoMap.get("一次性物品总价"); + }else{ + disposablePriceShowName = "一次性物品总价"; + } + String dgWhetherToChargeSQL = ""; + String invoiceItemLeftJoinDisposableGoodsSQL = ""; + String noQueryWhetherToChargeSQL = ""; + String returnGoodsItemLeftJoinDisposableGoodsSQL = ""; + String receiveRecordItemLeftJoinDisposableGoodsSQL = ""; + String godownEntryDiposableGoodsItemLeftJoinDisposableGoodsSQL = ""; + String diposableGoodsItemLeftJoinDisposableGoodsSQL = ""; + if(queryWhetherToCharge){ + dgWhetherToChargeSQL = ",dg.whetherToCharge "; + invoiceItemLeftJoinDisposableGoodsSQL = " left join DisposableGoods dg on dg.id=ii.disposableGoodsId "; + noQueryWhetherToChargeSQL = ",null whetherToCharge "; + returnGoodsItemLeftJoinDisposableGoodsSQL = " left join DisposableGoods dg on dg.id=i.disposableGoodsID "; + receiveRecordItemLeftJoinDisposableGoodsSQL = " left join DisposableGoods dg on dg.id=i.disposableGoodsId "; + godownEntryDiposableGoodsItemLeftJoinDisposableGoodsSQL = " left join DisposableGoods dg on dg.id=ged.disposableGoodsID "; + diposableGoodsItemLeftJoinDisposableGoodsSQL = " left join DisposableGoods dg on dg.id=dgi.disposableGoodsID "; + } + String iDepartSql = null; + String rDepartSql = null; + String prDepartSql = null; + if(showApplicationDepart){ + iDepartSql = "i.depart,"; + rDepartSql = "r.depart,"; + prDepartSql = "pr.depart,"; + }else{ + iDepartSql = ""; + rDepartSql = ""; + prDepartSql = ""; + } + String iDepartCodingWhereSql = null; + String rDepartCodingWhereSql = null; + String rDepartCodeWhereSql = null; + String iDepartCodeWhereSql = null; + String ogeTargetOrgUnitCodeWhereSql = null; + String prDepartCodingWhereSql = null; + String crOrgUnitCodeWhereSql = null; + if(StringUtils.isNotBlank(invoicePlanDepartCoding)){ + iDepartCodingWhereSql = " and i.departCoding ='" + invoicePlanDepartCoding + "' "; + rDepartCodingWhereSql = " and r.departCoding ='" + invoicePlanDepartCoding + "' "; + rDepartCodeWhereSql = " and r.departCode ='" + invoicePlanDepartCoding + "' "; + iDepartCodeWhereSql = " and i.departCode ='" + invoicePlanDepartCoding + "' "; + ogeTargetOrgUnitCodeWhereSql = " and oge.targetOrgUnitCode ='" + invoicePlanDepartCoding + "' "; + prDepartCodingWhereSql = " and pr.departCoding ='" + invoicePlanDepartCoding + "' "; + crOrgUnitCodeWhereSql = " and cr.orgUnitCode ='" + invoicePlanDepartCoding + "' "; + }else{ + iDepartCodingWhereSql = ""; + rDepartCodingWhereSql = ""; + rDepartCodeWhereSql = ""; + iDepartCodeWhereSql = ""; + ogeTargetOrgUnitCodeWhereSql = ""; + prDepartCodingWhereSql = ""; + crOrgUnitCodeWhereSql = ""; + } + boolean enableMultipleBranchesOfHospital = CssdUtils.getSystemSetConfigByNameBool("enableMultipleBranchesOfHospital", false); + boolean enableDiscountPrice = CssdUtils.getSystemSetConfigByNameBool("enableDiscountPrice"); + boolean enableExpensiveGoods = CssdUtils.getSystemSetConfigByNameBool("enableExpensiveGoods"); + //是否启用包内材料统计列 + boolean monthReportMaterialAmountOfTousse = CssdUtils.getSystemSetConfigByNameBool("monthReportMaterialAmountOfTousse"); + SupplyRoomConfig supplyRoomConfig = supplyRoomConfigManager.getSystemParamsObj(); + final String TYPE_AUTO_DEDUCTION = "自动扣减物品"; + //SupplyRoomConfig firstSupplyRoomConfig = supplyRoomConfigManager.getFirstSupplyRoomConfig(); + //当前用户是否为供应室(包含一二级供应室)用户 + boolean isSupplyRoomUser = supplyRoomConfigManager.isSupplyRoomUser(); + LoginUserData user = AcegiHelper.getLoginUser(); + String orgUnitCoding = null; + if (user != null){ + orgUnitCoding = user.getOrgUnitCodingFromSupplyRoomConfig(); + } + boolean isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser = false; + if (isSupplyRoomUser || supplyRoomConfigManager.isExpensiveGoodsSupplyRoomUser()) { + isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser = true; + } + List list = new ArrayList(); + String invoiceWheresql = "" ; + //高值耗材(新)过滤条件 + String expensiveGoodsWheresql = "" ; + startDate += " 00:00:00"; + endDate += " 23:59:59"; + String betweenSql = "between " + + dateQueryAdapter.dateConverAdapter2(startDate, + "yyyy-mm-dd HH24:MI:SS") + + " and " + dateQueryAdapter.dateConverAdapter2(endDate, + "yyyy-mm-dd HH24:MI:SS") + " "; + if(StringUtils.isNotBlank(startDate) && StringUtils.isNotBlank(endDate)){ + invoiceWheresql = " and i.sendTime " + betweenSql; + expensiveGoodsWheresql = " and egge.time " + betweenSql; + } + String receiveDepartWhereSql = ""; + if(StringUtils.isNotBlank(department)){ + invoiceWheresql += " and i.settleAccountsDepart = '"+department+"'"; + expensiveGoodsWheresql += " and i.settleAccountsDepart = '"+department+"'"; + receiveDepartWhereSql = String.format(" and r.depart='%s'", department); + }else if(!(departments == null || departments.isEmpty())){ + invoiceWheresql += " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("i.settleAccountsDepart", departments); + expensiveGoodsWheresql += " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("i.settleAccountsDepart", departments); + receiveDepartWhereSql += " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("r.depart", departments); + } + String invoiceItemDisposableGoodsTypePredicate = "1=1"; + String disposableGoodsInvoiceAmountPredicate = " ii.diposable='是' "; + String returnGoodsItemPredicate = "1=1"; + String receiveRecordItemPredicate = "1=1"; + String outEntryPredicate = "1=1"; + String packingDisposableGoodsTypePredicate = "1=1"; + List allTousseType = dataIndex.getTousseTypes(tousseType); + String disposableGoodsIdSql = ""; + int dataSoureOfMaterialsCountOfToussesInReports = CssdUtils.getSystemSetConfigByNameInt("dataSoureOfMaterialsCountOfToussesInReports", 3); + //包定义id跟材料数量的临时表 + String tousseDefinitionIdMaterialAmountSql = " (select sum(mi.count) materialAmount,td.id,td.tousseType,td.isApplyEntireTousse from MaterialInstance mi join TousseDefinition td on mi.tousse_id = td.id group by td.id,td.tousseType,isApplyEntireTousse) "; + if(StringUtils.isNotBlank(disposableGoodsType)){ + disposableGoodsIdSql = String.format(" select id from DisposableGoods where type='%s' ", disposableGoodsType); + invoiceItemDisposableGoodsTypePredicate = String.format(" (ii.diposable='否' or ii.disposableGoodsId in(%s)) ", disposableGoodsIdSql); + disposableGoodsInvoiceAmountPredicate = String.format(" (ii.diposable='是' and ii.disposableGoodsId in(%s)) ", disposableGoodsIdSql); + returnGoodsItemPredicate = String.format(" (r.type!='一次性物品' or i.disposableGoodsId in(%s)) ", disposableGoodsIdSql); + outEntryPredicate = String.format(" (ged.disposableGoodsID in(%s)) ", disposableGoodsIdSql); + packingDisposableGoodsTypePredicate = String.format(" (dgi.disposableGoodsID in(%s)) ", disposableGoodsIdSql); + } + String invoiceJoinInvoicePlanSql = null; + String excludeSciProjectSql = null; + String excludeDiposableGoodsItemSql = null; + String queryProjNameSql = null; + String containDiposableGoodsItemSql = null; + if(showTotalMoneyOfSciProjectDisposableGoodsInvoiceInAccountingMonthlyReport){ + invoiceJoinInvoicePlanSql = " left join "+ InvoicePlan.class.getSimpleName() +" ip on i.invoicePlan_ID=ip.id "; + excludeSciProjectSql = ""; + excludeDiposableGoodsItemSql = ""; + containDiposableGoodsItemSql = " and dgi.invoice_id in (select i.id from "+ Invoice.class.getSimpleName() +" i join "+ InvoicePlan.class.getSimpleName() +" ip on ip.id=i.invoicePlan_ID where (ip.projName is not null) and dgi.invoice_id=i.id) "; + queryProjNameSql = ",ip.projName "; + }else if(excludeSciProjectInfo){//排除属于科研项目的一次性物品申请单的发货数据 + invoiceJoinInvoicePlanSql = " left join "+ InvoicePlan.class.getSimpleName() +" ip on i.invoicePlan_ID=ip.id "; + excludeSciProjectSql = " and (ip.projName is null or ip.projName='')"; + excludeDiposableGoodsItemSql = " and dgi.invoice_id in (select i.id from "+ Invoice.class.getSimpleName() +" i left join "+ InvoicePlan.class.getSimpleName() +" ip on ip.id=i.invoicePlan_ID where (ip.projName is null or ip.projName='') and dgi.invoice_id=i.id) "; + queryProjNameSql = ""; + containDiposableGoodsItemSql = ""; + }else{ + invoiceJoinInvoicePlanSql = ""; + excludeSciProjectSql = ""; + excludeDiposableGoodsItemSql = ""; + queryProjNameSql = ""; + containDiposableGoodsItemSql = ""; + } + if(StringUtils.isBlank(tousseType) || !"器械材料".equals(tousseType)){ + //物品类型sql + String tousseTypeInvoiceSql = ""; + String tousseTypeReturnSql = ""; + if(StringUtils.isNotBlank(tousseType)){ + if(TYPE_AUTO_DEDUCTION.equals(tousseType)){ + tousseTypeInvoiceSql = String.format(" and ii.type='%s' ", InvoiceItem.TYPE_AUTO_DEDUCTION); + }else{ + tousseTypeInvoiceSql = String.format(" and %s ", SqlUtils.getStringFieldInLargeCollectionsPredicate("ii.tousseType", allTousseType)); + } + + if(TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType)){ + tousseTypeReturnSql = " and i.disposableGoodsId in (select id from DisposableGoods) "; + }else{ + tousseTypeReturnSql = String.format(" and i.tousseDefinition_id in (select id from TousseDefinition where %s) ", SqlUtils.getStringFieldInLargeCollectionsPredicate("tousseType", allTousseType)); + } + }else{ + tousseTypeInvoiceSql = String.format(" and (ii.type='%s' or ii.diposable='是' or (ii.diposable='否' and %s))", InvoiceItem.TYPE_AUTO_DEDUCTION,SqlUtils.getStringFieldInLargeCollectionsPredicate("ii.tousseType", allTousseType)); + tousseTypeReturnSql = String.format(" and (i.disposableGoodsId in (select id from DisposableGoods) or i.tousseDefinition_id in (select id from TousseDefinition where %s) )",SqlUtils.getStringFieldInLargeCollectionsPredicate("tousseType", allTousseType)); + } + + String invoicePriceSql = "select "+ iDepartSql+"i.settleAccountsDepartCoding as coding,i.settleAccountsDepart " + + queryProjNameSql + + ",sum(ii.settlementPrice) as price,ii.diposable,sum(ii.settlementDiscountPrice) as settlementDiscountPrice,ii.tousseType " + + dgWhetherToChargeSQL + + " from " + Invoice.class.getSimpleName() + " i join " + + InvoiceItem.class.getSimpleName() + " ii on i.id = ii.invoice_id " + + invoiceJoinInvoicePlanSql + + invoiceItemLeftJoinDisposableGoodsSQL + + "where 1=1 and "+invoiceItemDisposableGoodsTypePredicate+" and " + + dataIndex.getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + + " and (i.status ='收货签收' or " + + "i.status = '已发货') " + iDepartCodingWhereSql + invoiceWheresql + tousseTypeInvoiceSql + excludeSciProjectSql + " group by "+ iDepartSql +" i.settleAccountsDepartCoding,i.settleAccountsDepart,ii.diposable,ii.tousseType"+queryProjNameSql + + dgWhetherToChargeSQL; + + //如果为高值耗材处理科室用户,并且启用高值耗材功能,且所选物品类型为全部或高值耗材时,则将高值耗材退货数据也抵冲掉 + if(enableExpensiveGoods && (StringUtils.isBlank(tousseType) || StringUtils.equals(ExpensiveGoods.TYPE_NAME, tousseType))){ + invoicePriceSql += " union all (select "+ iDepartSql +"i.settleAccountsDepartCoding coding,i.settleAccountsDepart settleAccountsDepart,-1 * sum(egi.price) price,'否' as diposable,-1 * sum(egi.price) settlementDiscountPrice,'高值耗材' as tousseType " + + noQueryWhetherToChargeSQL + + " from ExpensiveGoodsGodownEntry egge join ExpensiveGoodsGodownEntryItem eggei on egge.id=eggei.expensiveGoodsGodownEntry_id " + + " join ExpensiveGoodsInstance egi on egi.id=eggei.expensiveGoodsInstanceId join Invoice i on egi.invoiceId=i.id " + + " where "+ dataIndex.getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + + " and egge.type='退库单' " + expensiveGoodsWheresql + + iDepartCodingWhereSql + + " group by "+ iDepartSql + "i.settleAccountsDepartCoding,i.settleAccountsDepart)"; + } + + ResultSet rs = objectDao.executeSql(invoicePriceSql); + try { + while(rs.next()){ + String code = rs.getString("coding"); + String dept = null; + String settleAccountsDepart = rs.getString("settleAccountsDepart"); + if(showApplicationDepart){ + dept = rs.getString("depart"); + }else if(nameToBrevityCodeMap.size() > 0){ + dept = nameToBrevityCodeMap.get(settleAccountsDepart); + } + Double price = rs.getDouble("price"); + String diposable = rs.getString("diposable"); + Double discountPrice = rs.getDouble("settlementDiscountPrice"); + String tType = rs.getString("tousseType"); + String columnName = ""; + String costColumn = ""; + if("是".equals(diposable)){ + String whetherToCharge = null; + if(queryWhetherToCharge){ + whetherToCharge = rs.getString("whetherToCharge"); + } + columnName = getChargeDisposableColumnName(queryWhetherToCharge, whetherToCharge, disposablePriceShowName); + costColumn = "一次性物品记支"; + discountPrice = price;//一次性物品发货项中目前还没有记录折扣价 + }else{ + if(ExpensiveGoods.TYPE_NAME.equals(tType)){ + columnName = "高值耗材总价"; + }else{ + columnName = insidePriceShowName; + costColumn = "器械包记支"; + } + + } + String hospitalDistrict = null; + String projName = null; + if(showTotalMoneyOfSciProjectDisposableGoodsInvoiceInAccountingMonthlyReport){ + projName = rs.getString("projName"); + } + if(StringUtils.isNotBlank(projName) && showTotalMoneyOfSciProjectDisposableGoodsInvoiceInAccountingMonthlyReport){ + dept = "科研物资领用公共部门"; + settleAccountsDepart = "科研物资领用公共部门"; + }else if(enableMultipleBranchesOfHospital){ + hospitalDistrict = departToBrancheOfHospitalMap == null || departToBrancheOfHospitalMap.isEmpty() || departToBrancheOfHospitalMap.get(settleAccountsDepart) == null?null:departToBrancheOfHospitalMap.get(settleAccountsDepart).getName(); + } + newMonthReport(code, dept,settleAccountsDepart,"2", "价格统计",columnName,price, list, hospitalDistrict, enableMultipleBranchesOfHospital); + if(enableDiscountPrice && StringUtils.isNotBlank(costColumn)){ + newMonthReport(code, dept,settleAccountsDepart,"1", "科室记支",costColumn,discountPrice, list, hospitalDistrict, enableMultipleBranchesOfHospital); + } + } + } catch (SQLException e) { + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(rs); + } + if(!TYPE_AUTO_DEDUCTION.equals(tousseType)){ + String queryColumnSql = null; + String leftJoinSqlForReturnSql = null; + if(dataSoureOfMaterialsCountOfToussesInReports == 3){ + queryColumnSql = "td.tousseType,i.materialAmountAtThatTime materialAmount,td.isApplyEntireTousse "; + leftJoinSqlForReturnSql = String.format("left join %s td on td.id=i.tousseDefinition_id", TousseDefinition.class.getSimpleName()); + }else{ + queryColumnSql = "tdm.tousseType,tdm.materialAmount as materialAmount ,tdm.isApplyEntireTousse"; + leftJoinSqlForReturnSql = " left join " + tousseDefinitionIdMaterialAmountSql + " tdm on tdm.id = i.tousseDefinition_id "; + } + String joinSql = ""; + if(showTotalMoneyOfSciProjectDisposableGoodsInvoiceInAccountingMonthlyReport){ + joinSql = " left join "+ InvoicePlan.class.getSimpleName() + " ip on r.invoicePlanId=ip.id "; + } + //退货统计(器械包或一次性物品) + String returnSql = "select "+ rDepartSql +"r.type,(-i.settlementPrice) settlementPrice,-i.amount amount,r.settleAccountsDepartCoding,r.settleAccountsDepart," + + queryColumnSql + + queryProjNameSql + + dgWhetherToChargeSQL + + " from ReturnGoodsRecord r join ReturnGoodsItem i on r.id = i.returnGoodsRecord_ID " + + leftJoinSqlForReturnSql + + returnGoodsItemLeftJoinDisposableGoodsSQL + + joinSql + + " where "+returnGoodsItemPredicate+ tousseTypeReturnSql + rDepartCodingWhereSql + " and " + + dataIndex.getHandleDeptCodeSql("r.handleDepartCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + +" and r.returnTime " + betweenSql; + if(StringUtils.isNotBlank(department)){ + returnSql += " and r.settleAccountsDepart = '" + department + "'"; + }else if(!(departments == null || departments.isEmpty())){ + returnSql += " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("r.settleAccountsDepart", departments); + } + ResultSet rs5 = objectDao.executeSql(returnSql); + try { + while(rs5.next()){ + String type = rs5.getString("type"); + Double price = rs5.getDouble("settlementPrice"); + int amount = rs5.getInt("amount"); + String code = rs5.getString("settleAccountsDepartCoding"); + String dept = null; + String settleAccountsDepart = rs5.getString("settleAccountsDepart"); + if(showApplicationDepart){ + dept = rs5.getString("depart"); + }else if(nameToBrevityCodeMap.size() > 0){ + dept = nameToBrevityCodeMap.get(settleAccountsDepart); + } + String returnTousseType = rs5.getString("tousseType"); + String isApplyEntireTousse = rs5.getString("isApplyEntireTousse"); + int materialAmount = rs5.getInt("materialAmount"); + int totalMaterialAmount = amount * materialAmount; + + // 如果是拆包的消毒物品,用统计数量替换包数量 + if ("消毒物品".equals(returnTousseType) && Constants.STR_NO.equals(isApplyEntireTousse)) { + if (materialAmount > 0) { + amount = totalMaterialAmount; + } + }else if(TousseDefinition.PACKAGE_TYPE_CUSTOM.equals(returnTousseType)&& !showCustonTousseAmount){ + if (materialAmount > 0) { + amount = totalMaterialAmount; + } + } + String hospitalDistrict = null; + String projName = null; + if(showTotalMoneyOfSciProjectDisposableGoodsInvoiceInAccountingMonthlyReport){ + projName = rs5.getString("projName"); + } + if(StringUtils.isNotBlank(projName) && showTotalMoneyOfSciProjectDisposableGoodsInvoiceInAccountingMonthlyReport){ + dept = "科研物资领用公共部门"; + settleAccountsDepart = "科研物资领用公共部门"; + }else if(enableMultipleBranchesOfHospital){ + hospitalDistrict = departToBrancheOfHospitalMap == null || departToBrancheOfHospitalMap.isEmpty() || departToBrancheOfHospitalMap.get(settleAccountsDepart) == null?null:departToBrancheOfHospitalMap.get(settleAccountsDepart).getName(); + } + if("一次性物品".equals(type)){ + String whetherToCharge = null; + if(queryWhetherToCharge){ + whetherToCharge = rs5.getString("whetherToCharge"); + } + newMonthReport(code, dept,settleAccountsDepart, "2", "价格统计", + getChargeDisposableColumnName(queryWhetherToCharge, whetherToCharge, disposablePriceShowName) + , price, list,hospitalDistrict, enableMultipleBranchesOfHospital); + if(enableDiscountPrice){ + newMonthReport(code, dept,settleAccountsDepart,"1", "科室记支","一次性物品记支",price, list,hospitalDistrict, enableMultipleBranchesOfHospital); + } + if(!hideAmountColumn){ + newMonthReport(code, dept,settleAccountsDepart, "3", "数量统计", + getChargeDisposableColumnName(queryWhetherToCharge, whetherToCharge, disposableAmountShowName) + , amount, list,hospitalDistrict, enableMultipleBranchesOfHospital); + } + }else{ + newMonthReport(code, dept,settleAccountsDepart, "2", "价格统计", insidePriceShowName, price, list,hospitalDistrict, enableMultipleBranchesOfHospital); + if(enableDiscountPrice){ + newMonthReport(code, dept,settleAccountsDepart,"1", "科室记支","器械包记支",price, list,hospitalDistrict, enableMultipleBranchesOfHospital); + } + if(!hideAmountColumn){ + newMonthReport(code, dept,settleAccountsDepart, "3", "数量统计", insideAmountShowName, amount, list,hospitalDistrict, enableMultipleBranchesOfHospital); + if(monthReportMaterialAmountOfTousse){ + newMonthReport(code, dept,settleAccountsDepart, "4", "包内材料统计", "包内材料数量", totalMaterialAmount, list,hospitalDistrict, enableMultipleBranchesOfHospital); + } + } + } + } + }catch(Exception e){ + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(rs5); + } + } + } + + if(StringUtils.isBlank(tousseType) || "器械材料".equals(tousseType)){ + // 材料发货价格 + String materialInvoicePriceSql = "select "+ iDepartSql+"i.settleAccountsDepartCoding as coding,i.settleAccountsDepart " + + ",sum(ii.settlementPrice) as price from MaterialInvoice i," + + "MaterialInvoiceItem ii where i.id = ii.materialInvoice_id and " + + dataIndex.getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + + invoiceWheresql + iDepartCodingWhereSql + " group by " + + iDepartSql + +"i.settleAccountsDepartCoding,i.settleAccountsDepart"; + ResultSet materialInvoicePriceResultSet = objectDao.executeSql(materialInvoicePriceSql); + try { + while(materialInvoicePriceResultSet.next()){ + String code = materialInvoicePriceResultSet.getString("coding"); + String dept = null; + String settleAccountsDepart = materialInvoicePriceResultSet.getString("settleAccountsDepart"); + if(showApplicationDepart){ + dept = materialInvoicePriceResultSet.getString("depart"); + }else if(nameToBrevityCodeMap.size() > 0){ + dept = nameToBrevityCodeMap.get(settleAccountsDepart); + } + Double price = materialInvoicePriceResultSet.getDouble("price"); + + String columnName = "发货材料总价"; + String hospitalDistrict = null; + if(enableMultipleBranchesOfHospital){ + hospitalDistrict = departToBrancheOfHospitalMap == null || departToBrancheOfHospitalMap.isEmpty() || departToBrancheOfHospitalMap.get(settleAccountsDepart) == null?null:departToBrancheOfHospitalMap.get(settleAccountsDepart).getName(); + } + newMonthReport(code, dept,settleAccountsDepart,"2", "价格统计",columnName,price, list,hospitalDistrict, enableMultipleBranchesOfHospital); + if(enableDiscountPrice){ + newMonthReport(code, dept,settleAccountsDepart,"1", "科室记支","材料记支",price, list,hospitalDistrict, enableMultipleBranchesOfHospital); + } + } + } catch (SQLException e) { + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(materialInvoicePriceResultSet); + } + if(!hideAmountColumn){ + // 材料发货数量 + String materialInvoiceAmountSql = "select "+ iDepartSql +"i.settleAccountsDepartCoding as coding,i.settleAccountsDepart " + + ",mi.amount from MaterialInvoice i inner join MaterialInvoiceItem mi on i.id=mi.materialInvoice_id " + + "where " + dataIndex.getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + + " and (mi.amount is not null and mi.amount>0) " + + " " + invoiceWheresql + iDepartCodingWhereSql; + + ResultSet materialInvoiceAmountResultSet = objectDao.executeSql(materialInvoiceAmountSql); + try { + while(materialInvoiceAmountResultSet.next()){ + String code = materialInvoiceAmountResultSet.getString("coding"); + String dept = null; + String settleAccountsDepart = materialInvoiceAmountResultSet.getString("settleAccountsDepart"); + if(showApplicationDepart){ + dept = materialInvoiceAmountResultSet.getString("depart"); + }else if(nameToBrevityCodeMap.size() > 0){ + dept = nameToBrevityCodeMap.get(settleAccountsDepart); + } + int tousseAmount = materialInvoiceAmountResultSet.getInt("amount"); + String hospitalDistrict = null; + if(enableMultipleBranchesOfHospital){ + hospitalDistrict = departToBrancheOfHospitalMap == null || departToBrancheOfHospitalMap.isEmpty() || departToBrancheOfHospitalMap.get(settleAccountsDepart) == null?null:departToBrancheOfHospitalMap.get(settleAccountsDepart).getName(); + } + if(tousseAmount > 0){ + newMonthReport(code, dept,settleAccountsDepart,"3","数量统计", "发货材料数量",tousseAmount,list,hospitalDistrict, enableMultipleBranchesOfHospital); + } + } + } catch (SQLException e) { + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(materialInvoiceAmountResultSet); + } + } + String banQuery = " 1 = 0 and "; + String damagedTousseAtCost = supplyRoomConfig.getDamagedTousseAtCost(); + /*if(StringUtils.isBlank(damagedTousseAtCost) || Constants.STR_YES.equals(damagedTousseAtCost)){ + banQuery = ""; + }*/ + if(Constants.STR_YES.equals(damagedTousseAtCost)){ + banQuery = ""; + } + //材料报损统计 + String damageSql = "select "+ iDepartSql +"i.settleAccountsDepartCoding departCode,i.settleAccountsDepart,i.materialName,sum(i.materialCost*i.additionalAmount) money,sum(i.additionalAmount) amount " + + " from MaterialErrorDamageDetail i where " + banQuery + + dataIndex.getHandleDeptCodeSql("i.handleDepartCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + + " and i.type = '" + + MaterialErrorDamageDetail.TYPE_DAMAGE + "' and i.additionalTime " + + betweenSql + iDepartCodeWhereSql; + + if(StringUtils.isNotBlank(department)){ + damageSql += " and i.settleAccountsDepart = '"+department+"' "; + }else if(!(departments == null || departments.isEmpty())){ + damageSql += " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("i.settleAccountsDepart", departments); + } + damageSql += " group by "+ iDepartSql +"i.settleAccountsDepartCoding,i.settleAccountsDepart,i.materialName"; + ResultSet rs33 = objectDao.executeSql(damageSql); + try { + if(rs33 != null){ + while(rs33.next()){ + String code = rs33.getString("departCode"); + String dept = null; + String settleAccountsDepart = rs33.getString("settleAccountsDepart"); + if(showApplicationDepart){ + dept = rs33.getString("depart"); + }else if(nameToBrevityCodeMap.size() > 0){ + dept = nameToBrevityCodeMap.get(settleAccountsDepart); + } + Double money = rs33.getDouble("money"); + String hospitalDistrict = null; + if(enableMultipleBranchesOfHospital){ + hospitalDistrict = departToBrancheOfHospitalMap == null || departToBrancheOfHospitalMap.isEmpty() || departToBrancheOfHospitalMap.get(settleAccountsDepart) == null?null:departToBrancheOfHospitalMap.get(settleAccountsDepart).getName(); + } + if(!hideAmountColumn){ + int amount = rs33.getInt("amount"); + newMonthReport(code, dept,settleAccountsDepart, "3", "数量统计", errorDamageAmountShowName, amount, list,hospitalDistrict, enableMultipleBranchesOfHospital); + } + newMonthReport(code, dept,settleAccountsDepart, "2", "价格统计", errorDamagePriceShowName, money, list,hospitalDistrict, enableMultipleBranchesOfHospital); + if(enableDiscountPrice){ + newMonthReport(code, dept,settleAccountsDepart,"1", "科室记支","材料记支",money, list,hospitalDistrict, enableMultipleBranchesOfHospital); + } + } + } + }catch(Exception e){ + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(rs33); + } + + //材料丢失统计 + String recyclingErrorSql = "select "+ rDepartSql +"r.settleAccountsDepartCoding departCode,r.settleAccountsDepart,r.materialName,sum(r.materialCost*r.additionalAmount) money,sum(r.additionalAmount) amount " + + " from MaterialErrorDamageDetail r where r.errorType = '缺失' and r.type = '"+MaterialErrorDamageDetail.TYPE_ERROR+"' and r.materialName != '器械包标识牌' " + + " and "+ dataIndex.getHandleDeptCodeSql("r.handleDepartCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + + " and r.additionalTime " + betweenSql + rDepartCodeWhereSql; + + if(StringUtils.isNotBlank(department)){ + recyclingErrorSql += " and r.settleAccountsDepart = '"+department+"' "; + }else if(!(departments == null || departments.isEmpty())){ + recyclingErrorSql += " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("r.settleAccountsDepart", departments); + } + recyclingErrorSql += " group by "+ rDepartSql +"r.settleAccountsDepartCoding,r.settleAccountsDepart,r.materialName"; + ResultSet rs3 = objectDao.executeSql(recyclingErrorSql); + try { + if(rs3 != null){ + while(rs3.next()){ + String code = rs3.getString("departCode"); + String dept = null; + String settleAccountsDepart = rs3.getString("settleAccountsDepart"); + if(showApplicationDepart){ + dept = rs3.getString("depart"); + }else if(nameToBrevityCodeMap.size() > 0){ + dept = nameToBrevityCodeMap.get(settleAccountsDepart); + } + Double money = rs3.getDouble("money"); + String hospitalDistrict = null; + if(enableMultipleBranchesOfHospital){ + hospitalDistrict = departToBrancheOfHospitalMap == null || departToBrancheOfHospitalMap.isEmpty() || departToBrancheOfHospitalMap.get(settleAccountsDepart) == null?null:departToBrancheOfHospitalMap.get(settleAccountsDepart).getName(); + } + if(!hideAmountColumn){ + int amount = rs3.getInt("amount"); + newMonthReport(code, dept,settleAccountsDepart,"3", "数量统计",errorDamageAmountShowName,amount, list,hospitalDistrict, enableMultipleBranchesOfHospital); + } + newMonthReport(code, dept,settleAccountsDepart,"2", "价格统计",errorDamagePriceShowName,money, list,hospitalDistrict, enableMultipleBranchesOfHospital); + if(enableDiscountPrice){ + newMonthReport(code, dept,settleAccountsDepart,"1", "科室记支","材料记支",money, list,hospitalDistrict, enableMultipleBranchesOfHospital); + } + } + } + }catch(Exception e){ + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(rs3); + } + + // 材料退货 + String materialReturnSql = "select "+ rDepartSql +"r.settleAccountsDepartCoding departCoding,r.settleAccountsDepart , (-i.settlementPrice) settlementPrice,-i.amount amount " + + "from ReturnMaterialRecord r,ReturnMaterialItem i where r.id = i.returnMaterialRecord_ID" + + " and "+ dataIndex.getHandleDeptCodeSql("r.handleDepartCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + +" and r.returnTime " + betweenSql + rDepartCodingWhereSql; + if(StringUtils.isNotBlank(department)){ + materialReturnSql += " and r.settleAccountsDepart = '" + department + "'"; + }else if(!(departments == null || departments.isEmpty())){ + materialReturnSql += " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("r.settleAccountsDepart", departments); + } + ResultSet materialReturnResultSet = objectDao.executeSql(materialReturnSql); + try { + while(materialReturnResultSet.next()){ + String code = materialReturnResultSet.getString("departCoding"); + String dept = null; + String settleAccountsDepart = materialReturnResultSet.getString("settleAccountsDepart"); + if(showApplicationDepart){ + dept = materialReturnResultSet.getString("depart"); + }else if(nameToBrevityCodeMap.containsKey(settleAccountsDepart)){ + dept = nameToBrevityCodeMap.get(settleAccountsDepart); + } + Double price = materialReturnResultSet.getDouble("settlementPrice"); + String hospitalDistrict = null; + if(enableMultipleBranchesOfHospital){ + hospitalDistrict = departToBrancheOfHospitalMap == null || departToBrancheOfHospitalMap.isEmpty() || departToBrancheOfHospitalMap.get(settleAccountsDepart) == null?null:departToBrancheOfHospitalMap.get(settleAccountsDepart).getName(); + } + newMonthReport(code, dept,settleAccountsDepart, "2", "价格统计", "发货材料总价", price, list,hospitalDistrict, enableMultipleBranchesOfHospital); + if(!hideAmountColumn){ + int amount = materialReturnResultSet.getInt("amount"); + newMonthReport(code, dept,settleAccountsDepart, "3", "数量统计", "发货材料数量", amount, list,hospitalDistrict, enableMultipleBranchesOfHospital); + } + if(enableDiscountPrice){ + newMonthReport(code, dept,settleAccountsDepart,"1", "科室记支","材料记支",price, list,hospitalDistrict, enableMultipleBranchesOfHospital); + } + } + }catch(Exception e){ + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(materialReturnResultSet); + } + } + + if(!hideAmountColumn && (StringUtils.isBlank(tousseType) || TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType) || TYPE_AUTO_DEDUCTION.equals(tousseType))){ + String tousseTypeSql = ""; + if(TYPE_AUTO_DEDUCTION.equals(tousseType)){ + tousseTypeSql = String.format(" and ii.type='%s' ", InvoiceItem.TYPE_AUTO_DEDUCTION); + } + // 一次性发货数量统计 + String disposableGoodsInvoiceAmountSql = "select "+ iDepartSql +"i.settleAccountsDepartCoding as coding,i.settleAccountsDepart " + + queryProjNameSql + + ",ii.amount " + + dgWhetherToChargeSQL + + " from Invoice i inner join InvoiceItem ii on i.id = ii.invoice_id " + + invoiceJoinInvoicePlanSql + + invoiceItemLeftJoinDisposableGoodsSQL + + "where " + + dataIndex.getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + +tousseTypeSql + +" and "+disposableGoodsInvoiceAmountPredicate + + excludeSciProjectSql + + " and (i.status ='收货签收' or i.status = '已发货') " + invoiceWheresql + iDepartCodingWhereSql; + ResultSet disposableGoodsInvoiceAmountResultSet = objectDao.executeSql(disposableGoodsInvoiceAmountSql); + try { + while(disposableGoodsInvoiceAmountResultSet.next()){ + String code = disposableGoodsInvoiceAmountResultSet.getString("coding"); + String dept = null; + String settleAccountsDepart = disposableGoodsInvoiceAmountResultSet.getString("settleAccountsDepart"); + if(showApplicationDepart){ + dept = disposableGoodsInvoiceAmountResultSet.getString("depart"); + }else if(nameToBrevityCodeMap.containsKey(settleAccountsDepart)){ + dept = nameToBrevityCodeMap.get(settleAccountsDepart); + } + int diposableAmount = disposableGoodsInvoiceAmountResultSet.getInt("amount"); + if(diposableAmount > 0){ + String hospitalDistrict = null; + String projName = null; + if(showTotalMoneyOfSciProjectDisposableGoodsInvoiceInAccountingMonthlyReport){ + projName = disposableGoodsInvoiceAmountResultSet.getString("projName"); + } + if(StringUtils.isNotBlank(projName) && showTotalMoneyOfSciProjectDisposableGoodsInvoiceInAccountingMonthlyReport){ + dept = "科研物资领用公共部门"; + settleAccountsDepart = "科研物资领用公共部门"; + }else if(enableMultipleBranchesOfHospital){ + hospitalDistrict = departToBrancheOfHospitalMap == null || departToBrancheOfHospitalMap.isEmpty() || departToBrancheOfHospitalMap.get(settleAccountsDepart) == null?null:departToBrancheOfHospitalMap.get(settleAccountsDepart).getName(); + } + String whetherToCharge = null; + if(queryWhetherToCharge){ + whetherToCharge = disposableGoodsInvoiceAmountResultSet.getString("whetherToCharge"); + } + newMonthReport(code, dept,settleAccountsDepart,"3","数量统计" + , getChargeDisposableColumnName(queryWhetherToCharge, whetherToCharge , disposableAmountShowName) + ,diposableAmount,list,hospitalDistrict, enableMultipleBranchesOfHospital); + } + } + } catch (SQLException e) { + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(disposableGoodsInvoiceAmountResultSet); + } + + } + + if(isSupplyRoomUser && (StringUtils.isBlank(tousseType) || "器械材料".equals(tousseType) || TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType) || TYPE_AUTO_DEDUCTION.equals(tousseType))){ + if("器械材料".equals(tousseType)){ + receiveRecordItemPredicate = String.format(" (i.type!='一次性物品') "); + }else if(TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType)){ + if(StringUtils.isNotBlank(disposableGoodsType)){ + receiveRecordItemPredicate = String.format(" (i.type='一次性物品' and i.disposableGoodsId in(%s)) ", disposableGoodsIdSql); + } + }else{ + if(StringUtils.isNotBlank(disposableGoodsType)){ + receiveRecordItemPredicate = String.format(" (i.type!='一次性物品' or i.disposableGoodsId in(%s)) ", disposableGoodsIdSql); + } + } + String tousseTypeSql = ""; + if(TYPE_AUTO_DEDUCTION.equals(tousseType)){ + tousseTypeSql = String.format(" and r.type='%s' ", InvoiceItem.TYPE_AUTO_DEDUCTION); + } + //供应室领用(器械材料与一次性物品) + String receiveSql = "select "+ rDepartSql +" i.type,(i.amount*i.price) price,i.amount,r.departcoding " + + dgWhetherToChargeSQL + + "from ReceiveRecord r join ReceiveRecordItem i on r.id = i.receiverecord_id " + + receiveRecordItemLeftJoinDisposableGoodsSQL + + "where 1=1 " + +tousseTypeSql + + "and "+receiveRecordItemPredicate + receiveDepartWhereSql + " and r.time " + betweenSql + rDepartCodingWhereSql; + SupplyRoomConfig config = supplyRoomConfigManager.getFirstSupplyRoomConfig(); + ResultSet rs4 = objectDao.executeSql(receiveSql); + try { + while(rs4.next()){ + String type = rs4.getString("type"); + Double price = rs4.getDouble("price"); + int amount = rs4.getInt("amount"); + String code = rs4.getString("departcoding"); + String dept = null; + if(showApplicationDepart){ + dept = rs4.getString("depart"); + }else if(nameToBrevityCodeMap.containsKey(config.getOrgUnitName())){ + dept = nameToBrevityCodeMap.get(config.getOrgUnitName()); + } + String hospitalDistrict = null; + if(enableMultipleBranchesOfHospital){ + hospitalDistrict = departToBrancheOfHospitalMap == null || departToBrancheOfHospitalMap.isEmpty() || departToBrancheOfHospitalMap.get(config.getOrgUnitName()) == null?null:departToBrancheOfHospitalMap.get(config.getOrgUnitName()).getName(); + } + if("一次性物品".equals(type)){ + String whetherToCharge = null; + if(queryWhetherToCharge){ + whetherToCharge = rs4.getString("whetherToCharge"); + } + newMonthReport(code, dept, config.getOrgUnitName(), "2", "价格统计", getChargeDisposableColumnName(queryWhetherToCharge, whetherToCharge, disposablePriceShowName) , price, list,hospitalDistrict, enableMultipleBranchesOfHospital); + if(enableDiscountPrice){ + newMonthReport(code,dept, config.getOrgUnitName(),"1", "科室记支","一次性物品记支",price, list,hospitalDistrict, enableMultipleBranchesOfHospital); + } + if(!hideAmountColumn){ + newMonthReport(code,dept, config.getOrgUnitName(), "3", "数量统计",getChargeDisposableColumnName(queryWhetherToCharge, whetherToCharge, disposableAmountShowName) , amount, list,hospitalDistrict, enableMultipleBranchesOfHospital); + } + }else{ + newMonthReport(code, dept, config.getOrgUnitName(), "2", "价格统计", "发货材料总价", price, list,hospitalDistrict, enableMultipleBranchesOfHospital); + if(enableDiscountPrice){ + newMonthReport(code, dept, config.getOrgUnitName(),"1", "科室记支","材料记支",price, list,hospitalDistrict, enableMultipleBranchesOfHospital); + } + if(!hideAmountColumn){ + newMonthReport(code, dept, config.getOrgUnitName(), "3", "数量统计", "发货材料数量", amount, list,hospitalDistrict, enableMultipleBranchesOfHospital); + } + } + } + }catch(Exception e){ + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(rs4); + } + } + // 一次性物品,调拨出库 + if(isSupplyRoomUser && (StringUtils.isBlank(tousseType) || TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType))){ + //供应室领用(器械材料与一次性物品) + String receiveSql = "select '一次性物品',(ged.amount*ged.price),ged.amount,oge.targetOrgUnitCode,oge.targetOrgUnitName " + + dgWhetherToChargeSQL + + "from GodownEntry oge inner join GodownEntryDiposableGoodsItem ged on oge.id = ged.godownEntryID " + + godownEntryDiposableGoodsItemLeftJoinDisposableGoodsSQL + + " where oge.type ='退库单' and oge.subType='调拨出库' " + + "and "+outEntryPredicate+" and " + + dataIndex.getHandleDeptCodeSql("oge.orgUnitCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + + " and oge.time " + betweenSql + ogeTargetOrgUnitCodeWhereSql; + if(StringUtils.isNotBlank(department)){ + receiveSql += " and oge.targetOrgUnitName = '" + department + "'"; + }else if(!(departments == null || departments.isEmpty())){ + receiveSql += " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("oge.targetOrgUnitName", departments); + } + ResultSet rs4 = objectDao.executeSql(receiveSql); + try { + while(rs4.next()){ + String type = rs4.getString(1); + if("一次性物品".equals(type)){ + Double price = rs4.getDouble(2); + String code = rs4.getString(4); + String orgUnitName = rs4.getString(5); + String depart = null; + if(showApplicationDepart){ + depart = orgUnitName; + }else if(nameToBrevityCodeMap.containsKey(orgUnitName)){ + depart = nameToBrevityCodeMap.get(orgUnitName); + } + String hospitalDistrict = null; + if(enableMultipleBranchesOfHospital){ + hospitalDistrict = departToBrancheOfHospitalMap == null || departToBrancheOfHospitalMap.isEmpty() || departToBrancheOfHospitalMap.get(orgUnitName) == null?null:departToBrancheOfHospitalMap.get(orgUnitName).getName(); + } + String whetherToCharge = null; + if(queryWhetherToCharge){ + whetherToCharge = rs4.getString("whetherToCharge"); + } + newMonthReport(code, depart,orgUnitName, "2", "价格统计", getChargeDisposableColumnName(queryWhetherToCharge, whetherToCharge, disposablePriceShowName) , price, list,hospitalDistrict, enableMultipleBranchesOfHospital); + if(enableDiscountPrice){ + newMonthReport(code, depart,orgUnitName,"1", "科室记支","一次性物品记支",price, list,hospitalDistrict, enableMultipleBranchesOfHospital); + } + if(!hideAmountColumn){ + int amount = rs4.getInt("amount"); + newMonthReport(code, depart,orgUnitName, "3", "数量统计", getChargeDisposableColumnName(queryWhetherToCharge, whetherToCharge, disposableAmountShowName) , amount, list,hospitalDistrict, enableMultipleBranchesOfHospital); + } + } + } + }catch(Exception e){ + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(rs4); + } + } + // 一次性物品,盘亏出库 + if(isSupplyRoomUser && (StringUtils.isBlank(tousseType) || TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType))){ + //供应室领用(器械材料与一次性物品) + String receiveSql = "select '一次性物品',(ged.amount*ged.price),ged.amount,oge.orgUnitCode,oge.orgUnitName " + + dgWhetherToChargeSQL + + "from GodownEntry oge inner join GodownEntryDiposableGoodsItem ged on oge.id = ged.godownEntryID " + + godownEntryDiposableGoodsItemLeftJoinDisposableGoodsSQL + + " where oge.type ='退库单' and oge.subType='盘亏出库' " + + "and "+outEntryPredicate+" and " + + dataIndex.getHandleDeptCodeSql("oge.orgUnitCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + + " and oge.time " + betweenSql + ogeTargetOrgUnitCodeWhereSql; + if(StringUtils.isNotBlank(department)){ + receiveSql += " and oge.orgUnitName = '" + department + "'"; + }else if(!(departments == null || departments.isEmpty())){ + receiveSql += " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("oge.orgUnitName", departments); + } + ResultSet rs4 = objectDao.executeSql(receiveSql); + try { + while(rs4.next()){ + String type = rs4.getString(1); + if("一次性物品".equals(type)){ + Double price = rs4.getDouble(2); + int amount = rs4.getInt("amount"); + String code = rs4.getString(4); + String orgUnitName = rs4.getString(5); + String hospitalDistrict = null; + if(enableMultipleBranchesOfHospital){ + hospitalDistrict = departToBrancheOfHospitalMap == null || departToBrancheOfHospitalMap.isEmpty() || departToBrancheOfHospitalMap.get(orgUnitName) == null?null:departToBrancheOfHospitalMap.get(orgUnitName).getName(); + } + String depart = null; + if(showApplicationDepart){ + depart = orgUnitName; + }else if(nameToBrevityCodeMap.containsKey(orgUnitName)){ + depart = nameToBrevityCodeMap.get(orgUnitName); + } + String whetherToCharge = null; + if(queryWhetherToCharge){ + whetherToCharge = rs4.getString("whetherToCharge"); + } + newMonthReport(code, depart,orgUnitName, "2", "价格统计", getChargeDisposableColumnName(queryWhetherToCharge, whetherToCharge, disposablePriceShowName) , price, list,hospitalDistrict, enableMultipleBranchesOfHospital); + if(enableDiscountPrice){ + newMonthReport(code, depart,orgUnitName,"1", "科室记支","一次性物品记支",price, list,hospitalDistrict, enableMultipleBranchesOfHospital); + } + if(!hideAmountColumn){ + newMonthReport(code, depart,orgUnitName, "3", "数量统计",getChargeDisposableColumnName(queryWhetherToCharge, whetherToCharge, disposableAmountShowName) , amount, list,hospitalDistrict, enableMultipleBranchesOfHospital); + } + } + } + }catch(Exception e){ + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(rs4); + } + } + // 一次性物品装配扣减库存 + { + if(showTotalMoneyOfSciProjectDisposableGoodsInvoiceInAccountingMonthlyReport){ + if(isSupplyRoomUser && (StringUtils.isBlank(tousseType) || TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType))){ + String sql = "select "+ prDepartSql +"'一次性物品' type,(dgi.amount*dgi.fluctuationPrice) price,dgi.amount,pr.orgUnitCoding,pr.orgUnitName " + + dgWhetherToChargeSQL + + "from PackingRecord pr inner join DiposableGoodsItem dgi on pr.id = dgi.packingRecordId " + + diposableGoodsItemLeftJoinDisposableGoodsSQL + + " where " + +packingDisposableGoodsTypePredicate+" and " + + dataIndex.getHandleDeptCodeSql("pr.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + + " and pr.packTime " + betweenSql + prDepartCodingWhereSql + containDiposableGoodsItemSql; + ResultSet rs = objectDao.executeSql(sql); + try { + while(rs.next()){ + String type = rs.getString("type"); + if("一次性物品".equals(type)){ + Double price = rs.getDouble("price"); + int amount = rs.getInt("amount"); + String code = rs.getString("orgUnitCoding"); + String hospitalDistrict = null; + String whetherToCharge = null; + if(queryWhetherToCharge){ + whetherToCharge = rs.getString("whetherToCharge"); + } + newMonthReport(code, "科研物资领用公共部门","科研物资领用公共部门", "2", "价格统计", getChargeDisposableColumnName(queryWhetherToCharge, whetherToCharge, disposablePriceShowName) , price, list,hospitalDistrict, enableMultipleBranchesOfHospital); + if(enableDiscountPrice){ + newMonthReport(code, "科研物资领用公共部门","科研物资领用公共部门","1", "科室记支","一次性物品记支",price, list,hospitalDistrict, enableMultipleBranchesOfHospital); + } + if(!hideAmountColumn){ + newMonthReport(code, "科研物资领用公共部门","科研物资领用公共部门", "3", "数量统计", getChargeDisposableColumnName(queryWhetherToCharge, whetherToCharge, disposableAmountShowName) , amount, list,hospitalDistrict, enableMultipleBranchesOfHospital); + } + } + } + }catch(Exception e){ + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(rs); + } + } + }else{ + if(isSupplyRoomUser && (StringUtils.isBlank(tousseType) || TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType))){ + String sql = "select "+ prDepartSql +"'一次性物品' type,(dgi.amount*dgi.fluctuationPrice) price,dgi.amount,pr.orgUnitCoding,pr.orgUnitName " + + dgWhetherToChargeSQL + + "from PackingRecord pr inner join DiposableGoodsItem dgi on pr.id = dgi.packingRecordId " + + diposableGoodsItemLeftJoinDisposableGoodsSQL + + " where " + +packingDisposableGoodsTypePredicate+" and " + + dataIndex.getHandleDeptCodeSql("pr.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + + " and pr.packTime " + betweenSql + prDepartCodingWhereSql + excludeDiposableGoodsItemSql; + + ResultSet rs = objectDao.executeSql(sql); + try { + while(rs.next()){ + String type = rs.getString("type"); + if("一次性物品".equals(type)){ + Double price = rs.getDouble("price"); + int amount = rs.getInt("amount"); + String code = rs.getString("orgUnitCoding"); + String dept = null; + String orgUnitName = rs.getString("orgUnitName"); + if(showApplicationDepart){ + dept = rs.getString("depart"); + }else if(nameToBrevityCodeMap.containsKey(orgUnitName)){ + dept = nameToBrevityCodeMap.get(orgUnitName); + } + String hospitalDistrict = null; + if(enableMultipleBranchesOfHospital){ + hospitalDistrict = departToBrancheOfHospitalMap == null || departToBrancheOfHospitalMap.isEmpty() || departToBrancheOfHospitalMap.get(orgUnitName) == null ?null:departToBrancheOfHospitalMap.get(orgUnitName).getName(); + } + String whetherToCharge = null; + if(queryWhetherToCharge){ + whetherToCharge = rs.getString("whetherToCharge"); + } + newMonthReport(code, dept,orgUnitName, "2", "价格统计",getChargeDisposableColumnName(queryWhetherToCharge, whetherToCharge, disposablePriceShowName) , price, list,hospitalDistrict, enableMultipleBranchesOfHospital); + if(enableDiscountPrice){ + newMonthReport(code, dept,orgUnitName,"1", "科室记支","一次性物品记支",price, list,hospitalDistrict, enableMultipleBranchesOfHospital); + } + if(!hideAmountColumn){ + newMonthReport(code, dept,orgUnitName, "3", "数量统计",getChargeDisposableColumnName(queryWhetherToCharge, whetherToCharge, disposableAmountShowName) , amount, list,hospitalDistrict, enableMultipleBranchesOfHospital); + } + } + } + }catch(Exception e){ + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(rs); + } + } + } + } + boolean enableToussePointsStatistics = CssdUtils.getSystemSetConfigByNameBool("enableToussePointsStatistics", false); + //器械包(含消毒物品、敷料包等)发货数量统计 + if(!hideAmountColumn && (StringUtils.isBlank(tousseType) || (!"器械材料".equals(tousseType) && !TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType) && !TYPE_AUTO_DEDUCTION.equals(tousseType)))){ + String columnSqlForInvoiceAmountSql = null; + String leftJoinSqlForInvoiceAmountSql = null; + if(dataSoureOfMaterialsCountOfToussesInReports == 3){ + if(enableToussePointsStatistics){ + columnSqlForInvoiceAmountSql = "ii.materialAmount,td.isApplyEntireTousse,td.integral "; + }else{ + columnSqlForInvoiceAmountSql = "ii.materialAmount,td.isApplyEntireTousse"; + } + leftJoinSqlForInvoiceAmountSql = "left join TousseDefinition td on ii.tousseDefinitionId=td.id"; + }else{ + if(enableToussePointsStatistics){ + tousseDefinitionIdMaterialAmountSql = " (select sum(mi.count) materialAmount,td.id,td.tousseType,td.isApplyEntireTousse,td.integral from MaterialInstance mi join TousseDefinition td on mi.tousse_id = td.id group by td.id,td.tousseType,isApplyEntireTousse,td.integral) "; + columnSqlForInvoiceAmountSql = "tdm.materialAmount,tdm.isApplyEntireTousse,tdm.integral "; + }else{ + columnSqlForInvoiceAmountSql = "tdm.materialAmount,tdm.isApplyEntireTousse "; + } + leftJoinSqlForInvoiceAmountSql = " left join " + tousseDefinitionIdMaterialAmountSql + " tdm on tdm.id = ii.tousseDefinitionId "; + } + String invoiceAmountSql = "select "+ iDepartSql +"i.settleAccountsDepartCoding as coding,i.settleAccountsDepart " + + ",ii.amount,ii.tousseType," + + columnSqlForInvoiceAmountSql + + " from Invoice i join InvoiceItem ii on i.id = ii.invoice_id " + + leftJoinSqlForInvoiceAmountSql + + " where " + + dataIndex.getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + + " and (ii.amount is not null and ii.amount>0) "// 限制为只查包含器械包(含消毒物品、敷料包等)数量的 + + " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("ii.tousseType", allTousseType) + + " and (i.status ='收货签收' or i.status = '已发货') " + invoiceWheresql + iDepartCodingWhereSql; + //如果为高值耗材处理科室用户,并且启用高值耗材功能,且所选物品类型为全部或高值耗材时,则将高值耗材退货数据也抵冲掉 + if(enableExpensiveGoods && (StringUtils.isBlank(tousseType) || StringUtils.equals(ExpensiveGoods.TYPE_NAME, tousseType))){ + String queryIntegralSql = enableToussePointsStatistics?",0.0 as integral":""; + invoiceAmountSql += " union all (select "+ iDepartSql+"i.settleAccountsDepartCoding coding,i.settleAccountsDepart,-1 * count(egi.id) as amount,'高值耗材' as tousseType," + + " null as materialAmount,null as isApplyEntireTousse " + + queryIntegralSql + + " from ExpensiveGoodsGodownEntry egge join ExpensiveGoodsGodownEntryItem eggei on egge.id=eggei.expensiveGoodsGodownEntry_id " + + " join ExpensiveGoodsInstance egi on egi.id=eggei.expensiveGoodsInstanceId join Invoice i on egi.invoiceId=i.id " + + " where " + + dataIndex.getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + + " and egge.type='退库单' " + expensiveGoodsWheresql + iDepartCodingWhereSql + + " group by "+ iDepartSql +"i.settleAccountsDepartCoding,i.settleAccountsDepart)"; + } + + ResultSet rs2 = objectDao.executeSql(invoiceAmountSql); + try { + while(rs2.next()){ + String code = rs2.getString("coding"); + String dept = null; + String settleAccountsDepart = rs2.getString("settleAccountsDepart"); + if(showApplicationDepart){ + dept = rs2.getString("depart"); + }else if(nameToBrevityCodeMap.containsKey(settleAccountsDepart)){ + dept = nameToBrevityCodeMap.get(settleAccountsDepart); + } + int tousseAmount = ConvertNumber.getNumberIntValue(rs2.getObject("amount"), 0); + String tousseTypeName = rs2.getString("tousseType"); + int materialAmount = rs2.getInt("materialAmount"); + String isApplyEntireTousse = rs2.getString("isApplyEntireTousse"); + Double integral = null; + if(enableToussePointsStatistics && tousseAmount != 0){ + Number integralNum = (Number)rs2.getObject("integral"); + if(integralNum != null){ + integral = integralNum.doubleValue() * tousseAmount; + } + } + int totalMaterialAmount = tousseAmount * materialAmount; + // 如果是消毒物品,用统计数量替换包数量 + if ("消毒物品".equals(tousseTypeName) && Constants.STR_NO.equals(isApplyEntireTousse)) { + if (materialAmount > 0) { + tousseAmount = totalMaterialAmount; + } + }else if(TousseDefinition.PACKAGE_TYPE_CUSTOM.equals(tousseTypeName)&& !showCustonTousseAmount){ + if (materialAmount > 0) { + tousseAmount = totalMaterialAmount; + } + } + String hospitalDistrict = null; + if(enableMultipleBranchesOfHospital){ + hospitalDistrict = departToBrancheOfHospitalMap == null || departToBrancheOfHospitalMap.isEmpty() || departToBrancheOfHospitalMap.get(settleAccountsDepart) == null?null:departToBrancheOfHospitalMap.get(settleAccountsDepart).getName(); + } + if(ExpensiveGoods.TYPE_NAME.equals(tousseTypeName)){ + newMonthReport(code,dept,settleAccountsDepart,"3","数量统计", "高值耗材数量",tousseAmount,list,integral,hospitalDistrict, enableMultipleBranchesOfHospital); + }else{ + newMonthReport(code,dept,settleAccountsDepart,"3","数量统计", insideAmountShowName,tousseAmount,list,integral,hospitalDistrict, enableMultipleBranchesOfHospital); + if(monthReportMaterialAmountOfTousse){ + newMonthReport(code,dept,settleAccountsDepart, "4", "包内材料统计", "包内材料数量", totalMaterialAmount, list,0.0,hospitalDistrict, enableMultipleBranchesOfHospital); + } + } + } + } catch (SQLException e) { + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(rs2); + } + } + final String TYPE_CHARGE = "收费项目"; + if(StringUtils.isBlank(tousseType) || TYPE_CHARGE.equals(tousseType)){ + String chargeDateSql = String.format(" and chargeTime %s ", betweenSql); + String chargeDepartSql = ""; + if(StringUtils.isNotBlank(department)){ + chargeDepartSql = String.format(" and ci.orgUnitName = '%s' ", department); + }else if(!(departments == null || departments.isEmpty())){ + chargeDepartSql += " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("ci.orgUnitName", departments); + } + String sql = String.format("select ci.orgUnitName,ci.orgUnitCode,sum(price) price from ChargeRecordItem ci " + + " inner join ChargeRecord cr on cr.id=ci.chargeRecord_id where 1=1 %s %s %s group by ci.orgUnitName,ci.orgUnitCode", chargeDateSql,chargeDepartSql, crOrgUnitCodeWhereSql); + ResultSet rs5 = null; + try { + rs5 = objectDao.executeSql(sql); + while(rs5.next()){ + Double price = rs5.getDouble("price"); + String orgUnitName = rs5.getString("orgUnitName"); + String dept = null; + if(showApplicationDepart){ + dept = rs5.getString("depart"); + }else if(nameToBrevityCodeMap.containsKey(orgUnitName)){ + dept = nameToBrevityCodeMap.get(orgUnitName); + } + String orgUnitCode = rs5.getString("orgUnitCode"); + String hospitalDistrict = null; + if(enableMultipleBranchesOfHospital){ + hospitalDistrict = departToBrancheOfHospitalMap == null || departToBrancheOfHospitalMap.isEmpty() || departToBrancheOfHospitalMap.get(orgUnitName) == null?null:departToBrancheOfHospitalMap.get(orgUnitName).getName(); + } + newMonthReport(orgUnitCode, dept,orgUnitName, "2", "价格统计", "收费项目总价", price, list,hospitalDistrict, enableMultipleBranchesOfHospital); + } + }catch(Exception e){ + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(rs5); + } + } + return list; + } + /** + * 查询一次性物品是否收费时 列表后面需显示是否可收费 + * @param queryWhetherToCharge 查询是否收费 + * @param whetherToCharge 是否收费 + * @param oldName 旧列名 + * @return 添加是否收费后的列名 + */ + private String getChargeDisposableColumnName(boolean queryWhetherToCharge, String whetherToCharge, String oldName){ + if(!queryWhetherToCharge){ + return oldName; + } + if("是".equals(whetherToCharge)){ + return oldName + "_可收费"; + }else{ + return oldName + "_不可收费"; + } + } + protected void newMonthReport(String code, String dept, String settleAccountsDepart, + String columnNum, String columnTitle, String columnName, + Double money,List list, String hospitalDistrict , Boolean enableMultipleBranchesOfHospital) { + MonthReportBean bean = new MonthReportBean(); + bean.setRowNum(code); + bean.setApplicationDepart(dept); + bean.setDepartment(settleAccountsDepart); + bean.setColumnNum(columnNum); + bean.setColumnTitle(columnTitle); + bean.setColumnName(columnName); + bean.setMoney(money); + bean.setHospitalDistrict(hospitalDistrict); + if(enableMultipleBranchesOfHospital != null && enableMultipleBranchesOfHospital){ + if(StringUtils.isBlank(hospitalDistrict)){ + newMonthReport(null, null,"合计_", columnNum, columnTitle, columnName, money, list, hospitalDistrict, false); + }else{ + newMonthReport(null, null, "合计_"+ hospitalDistrict, columnNum, columnTitle, columnName, money, list, hospitalDistrict, false); + } + } + list.add(bean); + } + /** + * 数量统计 + * @param code + * @param dept + * @param columnNum + * @param columnTitle + * @param columnName + * @param amount + * @param list + */ + protected void newMonthReport(String code, String dept, String settleAccountsDepart, + String columnNum, String columnTitle, String columnName, + Integer amount, List list, String hospitalDistrict, Boolean enableMultipleBranchesOfHospital) { + MonthReportBean bean = new MonthReportBean(); + bean.setRowNum(code); + bean.setApplicationDepart(dept); + bean.setDepartment(settleAccountsDepart); + bean.setColumnNum(columnNum); + bean.setColumnTitle(columnTitle); + bean.setColumnName(columnName); + bean.setAmount(amount); + bean.setHospitalDistrict(hospitalDistrict); + if(enableMultipleBranchesOfHospital != null && enableMultipleBranchesOfHospital){ + if(StringUtils.isBlank(hospitalDistrict)){ + newMonthReport(null,null,"合计_", columnNum, columnTitle, columnName, amount, list, hospitalDistrict, false); + }else{ + newMonthReport(null,null,"合计_"+ hospitalDistrict, columnNum, columnTitle, columnName, amount, list, hospitalDistrict, false); + } + } + list.add(bean); + } + protected void newMonthReport(String code, String dept,String settleAccountsDepart, + String columnNum, String columnTitle, String columnName, + Integer amount,List list, Double integral, String hospitalDistrict, Boolean enableMultipleBranchesOfHospital) { + MonthReportBean bean = new MonthReportBean(); + bean.setRowNum(code); + bean.setDepartment(settleAccountsDepart); + bean.setApplicationDepart(dept); + bean.setColumnNum(columnNum); + bean.setColumnTitle(columnTitle); + bean.setColumnName(columnName); + bean.setAmount(amount); + if(integral != null){ + bean.setIntegral(integral); + } + bean.setHospitalDistrict(hospitalDistrict); + if(enableMultipleBranchesOfHospital != null && enableMultipleBranchesOfHospital){ + if(StringUtils.isBlank(hospitalDistrict)){ + newMonthReport(null, null,"合计_", columnNum, columnTitle, columnName, amount, list, integral, hospitalDistrict, false); + }else{ + newMonthReport(null, null,"合计_"+ hospitalDistrict, columnNum, columnTitle, columnName, amount, list, integral, hospitalDistrict, false); + } + } + list.add(bean); + } +} Index: ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/service/dataindex/DataIndex.java =================================================================== diff -u -r35581 -r35792 --- ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/service/dataindex/DataIndex.java (.../DataIndex.java) (revision 35581) +++ ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/service/dataindex/DataIndex.java (.../DataIndex.java) (revision 35792) @@ -23,6 +23,8 @@ import com.forgon.Constants; import com.forgon.databaseadapter.service.DateQueryAdapter; import com.forgon.disinfectsystem.basedatamanager.supplyroomconfig.service.SupplyRoomConfigManager; +import com.forgon.disinfectsystem.common.CssdUtils; +import com.forgon.disinfectsystem.entity.assestmanagement.ExpensiveGoods; import com.forgon.disinfectsystem.entity.basedatamanager.toussedefinition.TousseDefinition; import com.forgon.disinfectsystem.entity.goodsstock.GoodsStock; import com.forgon.disinfectsystem.entity.invoicemanager.MaterialInvoice; @@ -3248,4 +3250,56 @@ return sql.toString(); } + /** + * 根据页面传递的物品类型,获取对应的器械包类型 + * @param tousseType 页面传递的物品类型,如果为空,则跟全部器械包一样,返回所有器械包类型的集合 + * @return + */ + public List getTousseTypes(String tousseType){ + List allType = new LinkedList(); + boolean enableExpensiveGoods = CssdUtils.getSystemSetConfigByNameBool("enableExpensiveGoods"); + if("全部器械包".equals(tousseType) || StringTools.isBlank(tousseType)){ + allType.add(TousseDefinition.PACKAGE_TYPE_CUSTOM); + allType.add(TousseDefinition.PACKAGE_TYPE_DISINFECTION); + allType.add(TousseDefinition.PACKAGE_TYPE_DRESSING); + allType.add(TousseDefinition.PACKAGE_TYPE_FOREIGN); + allType.add(TousseDefinition.PACKAGE_TYPE_FOREIGNPROXY); + allType.add(TousseDefinition.PACKAGE_TYPE_INSIDE); + allType.add(TousseDefinition.PACKAGE_TYPE_SPLIT); + allType.add(TousseDefinition.PACKAGE_TYPE_COMBO); + if(StringTools.isBlank(tousseType) && enableExpensiveGoods){ + allType.add(ExpensiveGoods.TYPE_NAME); + } + }else if("外来器械包".equals(tousseType)){ + allType.add(TousseDefinition.PACKAGE_TYPE_FOREIGN); + allType.add(TousseDefinition.PACKAGE_TYPE_SPLIT); + }else if("外部代理灭菌包".equals(tousseType)){ + allType.add(TousseDefinition.PACKAGE_TYPE_FOREIGNPROXY); + }else if(StringTools.isNotBlank(tousseType)){ + if(ExpensiveGoods.TYPE_NAME.equals(tousseType)){ + if(enableExpensiveGoods){ + allType.add(tousseType); + } + }else{ + allType.add(tousseType); + } + } + return allType; + } + /** + * 明细核算月报和核算月报用的过滤供应室的语句 + * @param field 过滤的字段 + * @param isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser 登录用户是否供应室用户 或者 是否是高值耗材处理科室用户 是才过滤供应室 + * @param orgUnitCoding 登录用户所属供应室编码 + * @return + */ + public String getHandleDeptCodeSql(String field, boolean isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, String orgUnitCoding){ + String handleDeptCodeSql = null; + if (isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser) { + handleDeptCodeSql = String.format(" %s='%s' ", field, orgUnitCoding); + } else { + handleDeptCodeSql = " 1=1 "; + } + return handleDeptCodeSql; + } } Index: ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/util/MonthReportGroupBySterilizationModeHelper.java =================================================================== diff -u --- ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/util/MonthReportGroupBySterilizationModeHelper.java (revision 0) +++ ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/util/MonthReportGroupBySterilizationModeHelper.java (revision 35792) @@ -0,0 +1,613 @@ +package com.forgon.disinfectsystem.jasperreports.util; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; + +import com.forgon.Constants; +import com.forgon.directory.acegi.tools.AcegiHelper; +import com.forgon.directory.vo.LoginUserData; +import com.forgon.disinfectsystem.basedatamanager.sterilisation.service.SterilisationManager; +import com.forgon.disinfectsystem.common.CssdUtils; +import com.forgon.disinfectsystem.entity.basedatamanager.supplyroomconfig.SupplyRoomConfig; +import com.forgon.disinfectsystem.entity.basedatamanager.toussedefinition.TousseDefinition; +import com.forgon.disinfectsystem.entity.invoicemanager.Invoice; +import com.forgon.disinfectsystem.entity.invoicemanager.InvoiceItem; +import com.forgon.disinfectsystem.entity.materialerrordamage.MaterialErrorDamageDetail; +import com.forgon.disinfectsystem.entity.tousseitem.TousseItem; +import com.forgon.disinfectsystem.jasperreports.javabeansource.MonthReportBean; +import com.forgon.tools.db.DatabaseUtil; +import com.forgon.tools.util.SqlUtils; +/** + * + * + */ +public class MonthReportGroupBySterilizationModeHelper extends MonthReportHelper{ + @Autowired + private SterilisationManager sterilisationManager; + public List getMonthReportDataGroupBySterilizationMode(String startDate,String endDate, + String department,String tousseType,String disposableGoodsType,Boolean showCustonTousseAmount){ + //是否启用包内材料统计列 + boolean monthReportMaterialAmountOfTousse = CssdUtils.getSystemSetConfigByNameBool("monthReportMaterialAmountOfTousse"); + SupplyRoomConfig supplyRoomConfig = supplyRoomConfigManager.getSystemParamsObj(); + final String TYPE_AUTO_DEDUCTION = "自动扣减物品"; + //SupplyRoomConfig firstSupplyRoomConfig = supplyRoomConfigManager.getFirstSupplyRoomConfig(); + //当前用户是否为供应室(包含一二级供应室)用户 + boolean isSupplyRoomUser = supplyRoomConfigManager.isSupplyRoomUser(); + if(!isSupplyRoomUser){ + department = AcegiHelper.getCurrentOrgUnitName(); + } + LoginUserData user = AcegiHelper.getLoginUser(); + String orgUnitCoding = null; + if (user != null){ + orgUnitCoding = user.getOrgUnitCodingFromSupplyRoomConfig(); + } + boolean isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser = false; + if (isSupplyRoomUser || supplyRoomConfigManager.isExpensiveGoodsSupplyRoomUser()) { + isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser = true; + } + List list = new ArrayList(); + String invoiceWheresql = "" ; + startDate += " 00:00:00"; + endDate += " 23:59:59"; + String betweenSql = "between " + + dateQueryAdapter.dateConverAdapter2(startDate, + "yyyy-mm-dd HH24:MI:SS") + + " and " + dateQueryAdapter.dateConverAdapter2(endDate, + "yyyy-mm-dd HH24:MI:SS") + " "; + if(StringUtils.isNotBlank(startDate) && StringUtils.isNotBlank(endDate)){ + invoiceWheresql = " and i.sendTime " + betweenSql; + } + String receiveDepartWhereSql = ""; + if(StringUtils.isNotBlank(department)){ + invoiceWheresql += " and i.settleAccountsDepart = '"+department+"'"; + receiveDepartWhereSql = String.format(" and r.depart='%s'", department); + } + String invoiceItemDisposableGoodsTypePredicate = "1=1"; + String disposableGoodsInvoiceAmountPredicate = " ii.diposable='是' "; + String returnGoodsItemPredicate = "1=1"; + String receiveRecordItemPredicate = "1=1"; + String outEntryPredicate = "1=1"; + String packingDisposableGoodsTypePredicate = "1=1"; + List allTousseType = dataIndex.getTousseTypes(tousseType); + String disposableGoodsIdSql = ""; + //获取灭菌程序对应灭菌方式的map + Map sterilisationAndSterilizationModeMap = sterilisationManager.getSterilisationAndSterilizationMode(); + for (Entry entry : sterilisationAndSterilizationModeMap.entrySet()) { + entry.setValue(new StringBuffer(15).append("a").append(entry.getValue()).append("物品").toString()); + } + StringBuffer leftJonsTousseDefinition = new StringBuffer(35).append(" left join ") + .append(TousseDefinition.class.getSimpleName()).append(" td on "); + int dataSoureOfMaterialsCountOfToussesInReports = CssdUtils.getSystemSetConfigByNameInt("dataSoureOfMaterialsCountOfToussesInReports", 3); + //包定义id跟材料数量的临时表 + String tousseDefinitionIdMaterialAmountSql = " (select sum(mi.count) materialAmount,td.id,td.tousseType,td.isApplyEntireTousse from MaterialInstance mi join TousseDefinition td on mi.tousse_id = td.id group by td.id,td.tousseType,isApplyEntireTousse) "; + if(StringUtils.isNotBlank(disposableGoodsType)){ + disposableGoodsIdSql = String.format(" select id from DisposableGoods where type='%s' ", disposableGoodsType); + invoiceItemDisposableGoodsTypePredicate = String.format(" (ii.diposable='否' or ii.disposableGoodsId in(%s)) ", disposableGoodsIdSql); + disposableGoodsInvoiceAmountPredicate = String.format(" (ii.diposable='是' and ii.disposableGoodsId in(%s)) ", disposableGoodsIdSql); + returnGoodsItemPredicate = String.format(" (r.type!='一次性物品' or i.disposableGoodsId in(%s)) ", disposableGoodsIdSql); + outEntryPredicate = String.format(" (ged.disposableGoodsID in(%s)) ", disposableGoodsIdSql); + packingDisposableGoodsTypePredicate = String.format(" (dgi.disposableGoodsID in(%s)) ", disposableGoodsIdSql); + } + if(StringUtils.isBlank(tousseType) || !"器械材料".equals(tousseType)){ + //物品类型sql + String tousseTypeInvoiceSql = ""; + String tousseTypeReturnSql = ""; + if(StringUtils.isNotBlank(tousseType)){ + if(TYPE_AUTO_DEDUCTION.equals(tousseType)){ + tousseTypeInvoiceSql = String.format(" and ii.type='%s' ", InvoiceItem.TYPE_AUTO_DEDUCTION); + }else{ + tousseTypeInvoiceSql = String.format(" and %s ", SqlUtils.getStringFieldInLargeCollectionsPredicate("ii.tousseType", allTousseType)); + } + + if(TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType)){ + tousseTypeReturnSql = " and i.disposableGoodsId in (select id from DisposableGoods) "; + }else{ + tousseTypeReturnSql = String.format(" and i.tousseDefinition_id in (select id from TousseDefinition where %s) ", SqlUtils.getStringFieldInLargeCollectionsPredicate("tousseType", allTousseType)); + } + }else{ + tousseTypeInvoiceSql = String.format(" and (ii.type='%s' or ii.diposable='是' or (ii.diposable='否' and %s))", InvoiceItem.TYPE_AUTO_DEDUCTION,SqlUtils.getStringFieldInLargeCollectionsPredicate("ii.tousseType", allTousseType)); + tousseTypeReturnSql = String.format(" and (i.disposableGoodsId in (select id from DisposableGoods) or i.tousseDefinition_id in (select id from TousseDefinition where %s) )",SqlUtils.getStringFieldInLargeCollectionsPredicate("tousseType", allTousseType)); + } + + String invoicePriceSql = "select i.settleAccountsDepartCoding as coding,i.settleAccountsDepart " + + "as depart,sum(ii.settlementPrice) as price,ii.diposable,sum(ii.settlementDiscountPrice) as settlementDiscountPrice,ii.tousseType,td.sterilingMethod from " + Invoice.class.getSimpleName() + " i," + + InvoiceItem.class.getSimpleName() + " ii "+ leftJonsTousseDefinition +" td.id=ii.tousseDefinitionId where i.id = ii.invoice_id and "+invoiceItemDisposableGoodsTypePredicate+" and " + + dataIndex.getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + + " and (i.status ='收货签收' or " + + "i.status = '已发货') " + invoiceWheresql + tousseTypeInvoiceSql + " group by i.settleAccountsDepartCoding,i.settleAccountsDepart,ii.diposable,ii.tousseType,td.sterilingMethod"; + + ResultSet rs = objectDao.executeSql(invoicePriceSql); + try { + while(rs.next()){ + Double price = rs.getDouble("price"); + String code = rs.getString("coding"); + String dept = rs.getString("depart"); + String diposable = rs.getString("diposable"); + String sterilingMethod = rs.getString("sterilingMethod"); + String columnName = ""; + if("是".equals(diposable)){ + newMonthReport(code, null,dept,"3", "价格统计","b一次性物品总价",price, list, null, null); + continue; + } + columnName = getColumnNameBySterilingMethod(sterilisationAndSterilizationModeMap, sterilingMethod); + newMonthReport(code, null,dept,"3", "价格统计",columnName,price, list, null, null); + } + } catch (SQLException e) { + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(rs); + } + if(!TYPE_AUTO_DEDUCTION.equals(tousseType)){ + String queryColumnSql = null; + String leftJoinSqlForReturnSql = null; + if(dataSoureOfMaterialsCountOfToussesInReports == 3){ + queryColumnSql = "td.toussetype,i.materialAmountAtThatTime as materialAmount,td.isApplyEntireTousse"; + leftJoinSqlForReturnSql = ""; + }else{ + queryColumnSql = "tdm.tousseType,tdm.materialAmount as materialAmount,tdm.isApplyEntireTousse"; + leftJoinSqlForReturnSql = " left join " + tousseDefinitionIdMaterialAmountSql + " tdm on tdm.id = i.tousseDefinition_id "; + } + //退货统计(器械包或一次性物品) + String returnSql = "select r.type,(-i.settlementPrice),-i.amount,r.settleAccountsDepartCoding departCoding,r.settleAccountsDepart depart," + + queryColumnSql + + ",td.sterilingMethod from ReturnGoodsRecord r join ReturnGoodsItem i on r.id = i.returnGoodsRecord_ID " + + leftJonsTousseDefinition + + " td.id=i.tousseDefinition_id " + + leftJoinSqlForReturnSql + + " where "+returnGoodsItemPredicate+ tousseTypeReturnSql + " and " + + dataIndex.getHandleDeptCodeSql("r.handleDepartCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + +" and r.returnTime " + betweenSql; + if(StringUtils.isNotBlank(department)){ + returnSql += " and r.settleAccountsDepart = '" + department + "'"; + } + ResultSet rs5 = objectDao.executeSql(returnSql); + try { + while(rs5.next()){ + String type = rs5.getString(1); + Double price = rs5.getDouble(2); + int amount = rs5.getInt(3); + String code = rs5.getString(4); + String dept = rs5.getString(5); + String returnTousseType = rs5.getString("tousseType"); + String isApplyEntireTousse = rs5.getString("isApplyEntireTousse"); + int materialAmount = rs5.getInt("materialAmount"); + int totalMaterialAmount = amount * materialAmount; + String sterilingMethod = rs5.getString("sterilingMethod"); + // 如果是拆包的消毒物品,用统计数量替换包数量 + if ("消毒物品".equals(returnTousseType) && Constants.STR_NO.equals(isApplyEntireTousse)) { + if (materialAmount > 0) { + amount = totalMaterialAmount; + } + }else if(TousseDefinition.PACKAGE_TYPE_CUSTOM.equals(returnTousseType)&& !showCustonTousseAmount){ + if (materialAmount > 0) { + amount = totalMaterialAmount; + } + } + + if("一次性物品".equals(type)){ + newMonthReport(code, null,dept, "3", "价格统计", "b一次性物品总价", price, list, null, null); + newMonthReport(code, null,dept, "2", "数量统计", "b一次性物品数量", amount, list, null, null); + continue; + } + String columnName = getColumnNameBySterilingMethod(sterilisationAndSterilizationModeMap, sterilingMethod); + + newMonthReport(code, null,dept, "3", "价格统计", columnName, price, list, null, null); + newMonthReport(code, null,dept, "2", "数量统计", columnName, amount, list, null, null); + if(monthReportMaterialAmountOfTousse){ + newMonthReport(code, null,dept, "4", "包内材料统计", "b包内材料数量", totalMaterialAmount, list, null, null); + } + } + }catch(Exception e){ + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(rs5); + } + } + } + + if(StringUtils.isBlank(tousseType) || "器械材料".equals(tousseType)){ + // 材料发货价格 + String materialInvoicePriceSql = "select i.settleAccountsDepartCoding as coding,i.settleAccountsDepart " + + "as depart,sum(ii.settlementPrice) as price from MaterialInvoice i," + + "MaterialInvoiceItem ii where i.id = ii.materialInvoice_id and " + + dataIndex.getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + + " " + invoiceWheresql + " group by i.settleAccountsDepartCoding,i.settleAccountsDepart"; + ResultSet materialInvoicePriceResultSet = objectDao.executeSql(materialInvoicePriceSql); + try { + while(materialInvoicePriceResultSet.next()){ + String code = materialInvoicePriceResultSet.getString(1); + String dept = materialInvoicePriceResultSet.getString(2); + Double price = materialInvoicePriceResultSet.getDouble(3); + String columnName = "b发货材料总价"; + + newMonthReport(code, null,dept,"3", "价格统计",columnName,price, list, null, null); + } + } catch (SQLException e) { + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(materialInvoicePriceResultSet); + } + + // 材料发货数量 + String materialInvoiceAmountSql = "select i.settleAccountsDepartCoding as coding,i.settleAccountsDepart " + + "as depart,mi.amount from MaterialInvoice i inner join MaterialInvoiceItem mi on i.id=mi.materialInvoice_id " + + "where " + + dataIndex.getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + + " and (mi.amount is not null and mi.amount>0) " + + " " + invoiceWheresql; + + ResultSet materialInvoiceAmountResultSet = objectDao.executeSql(materialInvoiceAmountSql); + try { + while(materialInvoiceAmountResultSet.next()){ + String code = materialInvoiceAmountResultSet.getString(1); + String dept = materialInvoiceAmountResultSet.getString(2); + int tousseAmount = materialInvoiceAmountResultSet.getInt(3); + if(tousseAmount > 0){ + newMonthReport(code, null,dept,"2","数量统计", "b发货材料数量",tousseAmount,list, null, null); + } + } + } catch (SQLException e) { + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(materialInvoiceAmountResultSet); + } + String banQuery = " 1 = 0 and "; + String damagedTousseAtCost = supplyRoomConfig.getDamagedTousseAtCost(); + if(Constants.STR_YES.equals(damagedTousseAtCost)){ + banQuery = ""; + } + //材料报损统计 + String damageSql = "select i.settleAccountsDepartCoding departCode,i.settleAccountsDepart depart,i.materialName,sum(i.materialCost*i.additionalAmount),sum(i.additionalAmount) " + + " from MaterialErrorDamageDetail i where " + banQuery + + dataIndex.getHandleDeptCodeSql("i.handleDepartCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + + " and i.type = '" + + MaterialErrorDamageDetail.TYPE_DAMAGE + "' and i.additionalTime " + + betweenSql; + + if(StringUtils.isNotBlank(department)){ + damageSql += " and i.settleAccountsDepart = '"+department+"' "; + } + damageSql += " group by i.settleAccountsDepartCoding,i.settleAccountsDepart,i.materialName"; + ResultSet rs33 = objectDao.executeSql(damageSql); + try { + if(rs33 != null){ + while(rs33.next()){ + String code = rs33.getString(1); + String dept = rs33.getString(2); + Double money = rs33.getDouble(4); + int amount = rs33.getInt(5); + + newMonthReport(code, null,dept, "2", "数量统计", "b丢失报损材料数量", amount, list, null, null); + newMonthReport(code, null,dept, "3", "价格统计", "b丢失报损材料总价", money, list, null, null); + } + } + }catch(Exception e){ + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(rs33); + } + + //材料丢失统计 + String recyclingErrorSql = "select r.settleAccountsDepartCoding departCode,r.settleAccountsDepart depart,r.materialName,sum(r.materialCost*r.additionalAmount),sum(r.additionalAmount) " + + " from MaterialErrorDamageDetail r where r.errorType = '缺失' and r.type = '"+MaterialErrorDamageDetail.TYPE_ERROR+"' and r.materialName != '器械包标识牌' " + + " and " + + dataIndex.getHandleDeptCodeSql("r.handleDepartCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + + " and r.additionalTime " + betweenSql; + + if(StringUtils.isNotBlank(department)){ + recyclingErrorSql += " and r.settleAccountsDepart = '"+department+"' "; + } + recyclingErrorSql += " group by r.settleAccountsDepartCoding,r.settleAccountsDepart,r.materialName"; + ResultSet rs3 = objectDao.executeSql(recyclingErrorSql); + try { + if(rs3 != null){ + while(rs3.next()){ + String code = rs3.getString(1); + String dept = rs3.getString(2); + Double money = rs3.getDouble(4); + int amount = rs3.getInt(5); + + newMonthReport(code, null,dept,"2", "数量统计","b丢失报损材料数量",amount, list, null, null); + newMonthReport(code, null,dept,"3", "价格统计","b丢失报损材料总价",money, list, null, null); + } + } + }catch(Exception e){ + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(rs3); + } + + // 材料退货 + String materialReturnSql = "select r.settleAccountsDepartCoding departCoding,r.settleAccountsDepart depart , (-i.settlementPrice),-i.amount " + + "from ReturnMaterialRecord r,ReturnMaterialItem i where r.id = i.returnMaterialRecord_ID" + + " and " + + dataIndex.getHandleDeptCodeSql("r.handleDepartCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + +" and r.returnTime " + betweenSql; + if(StringUtils.isNotBlank(department)){ + materialReturnSql += " and r.settleAccountsDepart = '" + department + "'"; + } + ResultSet materialReturnResultSet = objectDao.executeSql(materialReturnSql); + try { + while(materialReturnResultSet.next()){ + String code = materialReturnResultSet.getString(1); + String dept = materialReturnResultSet.getString(2); + Double price = materialReturnResultSet.getDouble(3); + int amount = materialReturnResultSet.getInt(4); + + newMonthReport(code, null,dept, "3", "价格统计", "b发货材料总价", price, list, null, null); + newMonthReport(code, null,dept, "2", "数量统计", "b发货材料数量", amount, list, null, null); + } + }catch(Exception e){ + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(materialReturnResultSet); + } + } + + if(StringUtils.isBlank(tousseType) || TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType) || TYPE_AUTO_DEDUCTION.equals(tousseType)){ + String tousseTypeSql = ""; + if(TYPE_AUTO_DEDUCTION.equals(tousseType)){ + tousseTypeSql = String.format(" and ii.type='%s' ", InvoiceItem.TYPE_AUTO_DEDUCTION); + } + // 一次性发货数量统计 + String disposableGoodsInvoiceAmountSql = "select i.settleAccountsDepartCoding as coding,i.settleAccountsDepart " + + "as depart,ii.amount from Invoice i inner join InvoiceItem ii on i.id = ii.invoice_id " + + "where " + + dataIndex.getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + +tousseTypeSql + +" and "+disposableGoodsInvoiceAmountPredicate + + " and (i.status ='收货签收' or i.status = '已发货') " + invoiceWheresql; + ResultSet disposableGoodsInvoiceAmountResultSet = objectDao.executeSql(disposableGoodsInvoiceAmountSql); + try { + while(disposableGoodsInvoiceAmountResultSet.next()){ + String code = disposableGoodsInvoiceAmountResultSet.getString(1); + String dept = disposableGoodsInvoiceAmountResultSet.getString(2); + int diposableAmount = disposableGoodsInvoiceAmountResultSet.getInt(3); + if(diposableAmount > 0){ + newMonthReport(code, null,dept,"2","数量统计", "b一次性物品数量",diposableAmount,list, null, null); + } + } + } catch (SQLException e) { + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(disposableGoodsInvoiceAmountResultSet); + } + + } + + if(isSupplyRoomUser && (StringUtils.isBlank(tousseType) || "器械材料".equals(tousseType) || TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType) || TYPE_AUTO_DEDUCTION.equals(tousseType))){ + if("器械材料".equals(tousseType)){ + receiveRecordItemPredicate = String.format(" (i.type!='一次性物品') "); + }else if(TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType)){ + if(StringUtils.isNotBlank(disposableGoodsType)){ + receiveRecordItemPredicate = String.format(" (i.type='一次性物品' and i.disposableGoodsId in(%s)) ", disposableGoodsIdSql); + } + }else{ + if(StringUtils.isNotBlank(disposableGoodsType)){ + receiveRecordItemPredicate = String.format(" (i.type!='一次性物品' or i.disposableGoodsId in(%s)) ", disposableGoodsIdSql); + } + } + String tousseTypeSql = ""; + if(TYPE_AUTO_DEDUCTION.equals(tousseType)){ + tousseTypeSql = String.format(" and r.type='%s' ", InvoiceItem.TYPE_AUTO_DEDUCTION); + } + //供应室领用(器械材料与一次性物品) + String receiveSql = "select i.type,(i.amount*i.price),i.amount,r.departcoding " + + "from ReceiveRecord r,ReceiveRecordItem i where r.id = i.receiverecord_id " + +tousseTypeSql + + "and "+receiveRecordItemPredicate + receiveDepartWhereSql + " and r.time " + betweenSql; + SupplyRoomConfig config = supplyRoomConfigManager.getFirstSupplyRoomConfig(); + ResultSet rs4 = objectDao.executeSql(receiveSql); + try { + while(rs4.next()){ + String type = rs4.getString(1); + Double price = rs4.getDouble(2); + int amount = rs4.getInt(3); + String code = rs4.getString(4); + if("一次性物品".equals(type)){ + newMonthReport(code, null,config.getOrgUnitName(), "3", "价格统计", "b一次性物品总价", price, list, null, null); + newMonthReport(code, null,config.getOrgUnitName(), "2", "数量统计", "b一次性物品数量", amount, list, null, null); + }else{ + newMonthReport(code, null,config.getOrgUnitName(), "3", "价格统计", "b发货材料总价", price, list, null, null); + newMonthReport(code, null,config.getOrgUnitName(), "2", "数量统计", "b发货材料数量", amount, list, null, null); + } + } + }catch(Exception e){ + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(rs4); + } + } + // 一次性物品,调拨出库 + if(isSupplyRoomUser && (StringUtils.isBlank(tousseType) || TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType))){ + //供应室领用(器械材料与一次性物品) + String receiveSql = "select '一次性物品',(ged.amount*ged.price),ged.amount,oge.targetOrgUnitCode,oge.targetOrgUnitName " + + "from GodownEntry oge inner join GodownEntryDiposableGoodsItem ged on oge.id = ged.godownEntryID where oge.type ='退库单' and oge.subType='调拨出库' " + + "and "+outEntryPredicate+" and " + + dataIndex.getHandleDeptCodeSql("oge.orgUnitCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + + SqlUtils.getFiledWhereSql("oge.targetOrgUnitName", department, 40) + " and oge.time " + betweenSql; + + ResultSet rs4 = objectDao.executeSql(receiveSql); + try { + while(rs4.next()){ + String type = rs4.getString(1); + Double price = rs4.getDouble(2); + int amount = rs4.getInt(3); + String code = rs4.getString(4); + String orgUnitName = rs4.getString(5); + if("一次性物品".equals(type)){ + newMonthReport(code, null,orgUnitName, "3", "价格统计", "b一次性物品总价", price, list, null, null); + newMonthReport(code, null,orgUnitName, "2", "数量统计", "b一次性物品数量", amount, list, null, null); + } + } + }catch(Exception e){ + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(rs4); + } + } + // 一次性物品,盘亏出库 + if(isSupplyRoomUser && (StringUtils.isBlank(tousseType) || TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType))){ + //供应室领用(器械材料与一次性物品) + String receiveSql = "select '一次性物品',(ged.amount*ged.price),ged.amount,oge.orgUnitCode,oge.orgUnitName " + + "from GodownEntry oge inner join GodownEntryDiposableGoodsItem ged on oge.id = ged.godownEntryID where oge.type ='退库单' and oge.subType='盘亏出库' " + + "and "+outEntryPredicate+" and " + + dataIndex.getHandleDeptCodeSql("oge.orgUnitCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + + SqlUtils.getFiledWhereSql("oge.orgUnitName", department, 30) + " and oge.time " + betweenSql; + + ResultSet rs4 = objectDao.executeSql(receiveSql); + try { + while(rs4.next()){ + String type = rs4.getString(1); + Double price = rs4.getDouble(2); + int amount = rs4.getInt(3); + String code = rs4.getString(4); + String orgUnitName = rs4.getString(5); + if("一次性物品".equals(type)){ + newMonthReport(code, null,orgUnitName, "3", "价格统计", "b一次性物品总价", price, list, null, null); + newMonthReport(code, null,orgUnitName, "2", "数量统计", "b一次性物品数量", amount, list, null, null); + } + } + }catch(Exception e){ + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(rs4); + } + } + // 一次性物品装配扣减库存 + { + if(isSupplyRoomUser && (StringUtils.isBlank(tousseType) || TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType))){ + String sql = "select '一次性物品',(dgi.amount*dgi.fluctuationPrice),dgi.amount,pr.orgUnitCoding,pr.orgUnitName " + + "from PackingRecord pr inner join DiposableGoodsItem dgi on pr.id = dgi.packingRecordId where " + +packingDisposableGoodsTypePredicate+" and " + + dataIndex.getHandleDeptCodeSql("pr.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + + SqlUtils.getFiledWhereSql("pr.orgUnitName", department, 35) + " and pr.packTime " + betweenSql; + + ResultSet rs = objectDao.executeSql(sql); + try { + while(rs.next()){ + String type = rs.getString(1); + Double price = rs.getDouble(2); + int amount = rs.getInt(3); + String code = rs.getString(4); + String orgUnitName = rs.getString(5); + if("一次性物品".equals(type)){ + newMonthReport(code, null,orgUnitName, "3", "价格统计", "b一次性物品总价", price, list, null, null); + newMonthReport(code, null,orgUnitName, "2", "数量统计", "b一次性物品数量", amount, list, null, null); + } + } + }catch(Exception e){ + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(rs); + } + } + } + + //器械包(含消毒物品、敷料包等)发货数量统计 + if(StringUtils.isBlank(tousseType) || (!"器械材料".equals(tousseType) && !TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType) && !TYPE_AUTO_DEDUCTION.equals(tousseType))){ + String columnSqlForInvoiceAmountSql = null; + String leftJoinSqlForInvoiceAmountSql = null; + if(dataSoureOfMaterialsCountOfToussesInReports == 3){ + columnSqlForInvoiceAmountSql = "ii.materialAmount,td.isApplyEntireTousse"; + leftJoinSqlForInvoiceAmountSql = ""; + }else{ + columnSqlForInvoiceAmountSql = "tdm.materialAmount,tdm.isApplyEntireTousse"; + leftJoinSqlForInvoiceAmountSql = " left join " + tousseDefinitionIdMaterialAmountSql + " tdm on tdm.id = ii.tousseDefinitionId "; + } + String invoiceAmountSql = "select i.settleAccountsDepartCoding as coding,i.settleAccountsDepart " + + "as depart,ii.amount,ii.tousseType," + + columnSqlForInvoiceAmountSql + + ",td.sterilingMethod from Invoice i join InvoiceItem ii on i.id = ii.invoice_id " + + leftJonsTousseDefinition + + " td.id=ii.tousseDefinitionId " + + leftJoinSqlForInvoiceAmountSql + + " where " + + dataIndex.getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + + SqlUtils.getFiledWhereSql("i.settleAccountsDepart", department, 45) + + " and (ii.amount is not null and ii.amount>0) "// 限制为只查包含器械包(含消毒物品、敷料包等)数量的 + + " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("ii.tousseType", allTousseType) + + " and (i.status ='收货签收' or i.status = '已发货') " + invoiceWheresql; + + ResultSet rs2 = objectDao.executeSql(invoiceAmountSql); + try { + while(rs2.next()){ + String code = rs2.getString(1); + String dept = rs2.getString(2); + int tousseAmount = rs2.getInt(3); + String tousseTypeName = rs2.getString(4); + int materialAmount = rs2.getInt("materialAmount"); + String isApplyEntireTousse = rs2.getString("isApplyEntireTousse"); + int totalMaterialAmount = tousseAmount * materialAmount; + String sterilingMethod = rs2.getString("sterilingMethod"); + // 如果是消毒物品,用统计数量替换包数量 + if ("消毒物品".equals(tousseTypeName) && Constants.STR_NO.equals(isApplyEntireTousse)) { + if (materialAmount > 0) { + tousseAmount = totalMaterialAmount; + } + }else if(TousseDefinition.PACKAGE_TYPE_CUSTOM.equals(tousseTypeName)&& !showCustonTousseAmount){ + if (materialAmount > 0) { + tousseAmount = totalMaterialAmount; + } + } + String columnName = getColumnNameBySterilingMethod(sterilisationAndSterilizationModeMap, sterilingMethod); + newMonthReport(code, null,dept,"2","数量统计", columnName,tousseAmount,list, null, null); + if(monthReportMaterialAmountOfTousse){ + newMonthReport(code, null,dept, "4", "包内材料统计", "b包内材料数量", totalMaterialAmount, list, null, null); + } + } + } catch (SQLException e) { + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(rs2); + } + } + final String TYPE_CHARGE = "收费项目"; + if(StringUtils.isBlank(tousseType) || TYPE_CHARGE.equals(tousseType)){ + String chargeDateSql = String.format(" and chargeTime %s ", betweenSql); + String chargeDepartSql = ""; + if(StringUtils.isNotBlank(department)){ + chargeDepartSql = String.format(" and ci.orgUnitName = '%s' ", department); + } + String sql = String.format("select ci.orgUnitName,ci.orgUnitCode,sum(price) price from ChargeRecordItem ci " + + " inner join ChargeRecord cr on cr.id=ci.chargeRecord_id where 1=1 %s %s group by ci.orgUnitName,ci.orgUnitCode", chargeDateSql,chargeDepartSql); + ResultSet rs5 = null; + try { + rs5 = objectDao.executeSql(sql); + while(rs5.next()){ + Double price = rs5.getDouble("price"); + String orgUnitName = rs5.getString("orgUnitName"); + String orgUnitCode = rs5.getString("orgUnitCode"); + newMonthReport(orgUnitCode, null,orgUnitName, "3", "价格统计", "b收费项目总价", price, list, null, null); + } + }catch(Exception e){ + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(rs5); + } + } + return list; + } + /** + * 根据灭菌程序获取物品类型名称 + * @param sterilisationAndSterilizationModeMap <灭菌程序,灭菌程序对应的灭菌方式+"物品"> + * @param sterilingMethod + * @return a灭菌程序对应的灭菌方式+"物品" or c其他物品 + */ + private String getColumnNameBySterilingMethod(Map sterilisationAndSterilizationModeMap, String sterilingMethod){ + String columnName = null; + if(StringUtils.isNotBlank(sterilingMethod) && sterilisationAndSterilizationModeMap.containsKey(sterilingMethod)){ + columnName = sterilisationAndSterilizationModeMap.get(sterilingMethod); + }else{ + columnName = "c其他物品"; + } + return columnName; + } +} Index: ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/service/JasperReportManager.java =================================================================== diff -u -r35689 -r35792 --- ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/service/JasperReportManager.java (.../JasperReportManager.java) (revision 35689) +++ ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/service/JasperReportManager.java (.../JasperReportManager.java) (revision 35792) @@ -344,27 +344,6 @@ String batch,String searchType,boolean disinfection,String disposableGoodsType,String goodsType,Boolean showCustonTousseAmount, String invoicePlanDepart, String departGroupStr ,boolean printByDepart, String urgentLevel, String extendedColumnConfigOfDetailedAccountingMonthlyReport); /** - * 查询单个科室的明细核算月报数据 - * @param whetherToCharge 一次性物品是否收费 - * @param startTime 开始时间 - * @param endTime 结束时间 - * @param depart 科室名称(结算科室) - * @param departCoding 科室编码 - * @param type 类型 - * @param goodsName 物品名称 - * @param batch 批次号 - * @param searchType - * @param disinfection - * @param disposableGoodsType - * @param goodsType - * @param showCustonTousseAmount - * @param invoicePlanDepart 申请科室 - * @return - */ - public List getDepartmentMonthDetailListOfSingleDepart( - String whetherToCharge, String startTime,String endTime, String depart,String departCoding,String type, String goodsName, - String batch,String searchType,boolean disinfection,String disposableGoodsType,String goodsType,Boolean showCustonTousseAmount, String invoicePlanDepart); - /** * 查询器械返消统计报表(按科室与包定义汇总) * @param startDate 查询开始时间 格式'2018-02-02' * @param endDate 查询结束时间 格式'2018-02-02' Index: ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/util/DepartmentMonthDetailHelper.java =================================================================== diff -u --- ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/util/DepartmentMonthDetailHelper.java (revision 0) +++ ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/util/DepartmentMonthDetailHelper.java (revision 35792) @@ -0,0 +1,1647 @@ +package com.forgon.disinfectsystem.jasperreports.util; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.Map.Entry; + +import net.sf.json.JSONArray; + +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.ObjectUtils; +import org.apache.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; + +import com.forgon.Constants; +import com.forgon.directory.acegi.tools.AcegiHelper; +import com.forgon.directory.vo.LoginUserData; +import com.forgon.disinfectsystem.basedatamanager.supplyroomconfig.service.SupplyRoomConfigManager; +import com.forgon.disinfectsystem.common.CssdUtils; +import com.forgon.disinfectsystem.entity.assestmanagement.DisposableGoods; +import com.forgon.disinfectsystem.entity.assestmanagement.DisposableGoodsBatchStock; +import com.forgon.disinfectsystem.entity.assestmanagement.DisposableGoodsStock; +import com.forgon.disinfectsystem.entity.assestmanagement.ExpensiveGoods; +import com.forgon.disinfectsystem.entity.assestmanagement.ExpensiveGoodsInstance; +import com.forgon.disinfectsystem.entity.basedatamanager.materialdefinition.MaterialDefinition; +import com.forgon.disinfectsystem.entity.basedatamanager.supplyroomconfig.SupplyRoomConfig; +import com.forgon.disinfectsystem.entity.basedatamanager.toussedefinition.TousseDefinition; +import com.forgon.disinfectsystem.entity.basedatamanager.toussedefinition.TousseInstance; +import com.forgon.disinfectsystem.entity.invoicemanager.Invoice; +import com.forgon.disinfectsystem.entity.invoicemanager.InvoiceDepartment; +import com.forgon.disinfectsystem.entity.invoicemanager.InvoiceItem; +import com.forgon.disinfectsystem.entity.invoicemanager.InvoicePlan; +import com.forgon.disinfectsystem.entity.materialerrordamage.MaterialErrorDamageDetail; +import com.forgon.disinfectsystem.entity.returngoodsrecord.ReturnGoodsItem; +import com.forgon.disinfectsystem.entity.returngoodsrecord.ReturnGoodsRecord; +import com.forgon.disinfectsystem.jasperreports.javabeansource.DepartmentMonthDetail; +import com.forgon.disinfectsystem.jasperreports.javabeansource.DepartmentMonthDetailItem; +import com.forgon.tools.MathTools; +import com.forgon.tools.StrutsParamUtils; +import com.forgon.tools.db.DatabaseUtil; +import com.forgon.tools.format.ConvertNumber; +import com.forgon.tools.string.StringTools; +import com.forgon.tools.util.ForgonDateUtils; +import com.forgon.tools.util.SqlUtils; +/** + * 明细核算月报 + * + */ +public class DepartmentMonthDetailHelper extends ReportHelper{ + private Logger logger = Logger.getLogger(this.getClass()); + @Autowired + private SupplyRoomConfigManager supplyRoomConfigManager; + /** + * 查询明细核算月报数据 + * @param showSendTime 显示发货时间 + * @param whetherToCharge 一次性物品是否收费 + * @param startTime 开始时间 + * @param endTime 结束时间 + * @param depart 科室名称(结算科室) + * @param departCoding 科室编码 + * @param type 类型 + * @param goodsName 物品名称 + * @param batch 批次号 + * @param searchType + * @param disinfection + * @param disposableGoodsType + * @param goodsType + * @param showCustonTousseAmount + * @param invoicePlanDepart 申请科室 + * @param departGroupStr 科室分组 + * @param printByDepart 按科室打印 + * @param extendedColumnConfigOfDetailedAccountingMonthlyReport 标准模板额外列 + * @return + */ + public List getDepartmentMonthDetailList( + boolean showTime, boolean showSendTime, String whetherToCharge, String startTime,String endTime, String departSearch,String departCoding,String typeSearch, + String goodsNameSearch, String batch,String searchType,boolean disinfection,String disposableGoodsType,String goodsType, + Boolean showCustonTousseAmount, String invoicePlanDepartCoding, String departGroupStr, boolean printByDepart + ,String urgentLevel, String extendedColumnConfigOfDetailedAccountingMonthlyReport) { + boolean filterWhetherToCharge = false; + if(StringUtils.isNotBlank(whetherToCharge) && !whetherToCharge.contains("全部")){ + filterWhetherToCharge = true; + } + String iSendTimeSqlOfShowTime = ""; + String groupByIsendTimeOfShowTime = ""; + + String prPackTimeSqlOfShowTime = ""; + String groupByPrPackTimeOfShowTime = ""; + + String rrReturnTimeSqlOfShowTime = ""; + String groupByRrReturnTimeOfShowTime = ""; + + String iOperationTimeSqlOfShowTime = ""; + String groupByIOperationTimeOfShowTime = ""; + + String rrTimeSqlOfShowTime = ""; + String groupByRrTimeOfShowTime = ""; + + String ogeTimeSqlOfShowTime = ""; + String groupByOgeTimeOfShowTime = ""; + + String crChargeTimeSqlOfShowTime = ""; + String groupByCrChargeTimeOfShowTime = ""; + if(showTime){ + String dateSql = dateQueryAdapter.dateConverAdapter(dateQueryAdapter.stringFieldToDate("i.sendTime"),"yyyy-MM-dd"); + iSendTimeSqlOfShowTime = ","+ dateSql +" showTime "; + groupByIsendTimeOfShowTime = "," + dateSql; + + String packTimeDateSql = dateQueryAdapter.dateConverAdapter(dateQueryAdapter.stringFieldToDate("pr.packTime"),"yyyy-MM-dd"); + prPackTimeSqlOfShowTime = ","+ packTimeDateSql +" showTime "; + groupByPrPackTimeOfShowTime = "," + packTimeDateSql; + + String returnTimeDateSql = dateQueryAdapter.dateConverAdapter(dateQueryAdapter.stringFieldToDate("rr.returnTime"),"yyyy-MM-dd"); + rrReturnTimeSqlOfShowTime = ","+ returnTimeDateSql +" showTime "; + groupByRrReturnTimeOfShowTime = "," + returnTimeDateSql; + + String operationTimeDateSql = dateQueryAdapter.dateConverAdapter(dateQueryAdapter.stringFieldToDate("i.operationTime"),"yyyy-MM-dd"); + iOperationTimeSqlOfShowTime = ","+ operationTimeDateSql +" showTime "; + groupByIOperationTimeOfShowTime = "," + operationTimeDateSql; + + String rrTimeDateSql = dateQueryAdapter.dateConverAdapter(dateQueryAdapter.stringFieldToDate("rr.time"),"yyyy-MM-dd"); + rrTimeSqlOfShowTime = ","+ rrTimeDateSql +" showTime "; + groupByRrTimeOfShowTime = "," + rrTimeDateSql; + + String ogeTimeDateSql = dateQueryAdapter.dateConverAdapter(dateQueryAdapter.stringFieldToDate("oge.time"),"yyyy-MM-dd"); + ogeTimeSqlOfShowTime = ","+ ogeTimeDateSql +" showTime "; + groupByOgeTimeOfShowTime = "," + ogeTimeDateSql; + + String crChargeTimeDateSql = dateQueryAdapter.dateConverAdapter(dateQueryAdapter.stringFieldToDate("cr.chargeTime"),"yyyy-MM-dd"); + crChargeTimeSqlOfShowTime = ","+ crChargeTimeDateSql +" showTime "; + groupByCrChargeTimeOfShowTime = "," + crChargeTimeDateSql; + } + boolean queryUnit = printByDepart; + //数据库拼接符号 + String concatSymbolInDb = DatabaseUtil.isOracle(dbConnection.getDatabase())?"||":"+"; + SupplyRoomConfig config = supplyRoomConfigManager.getSystemParamsObj(); + final String TYPE_AUTO_DEDUCTION = "自动扣减物品"; + final String TYPE_ALL = "全部"; + final String TYPE_CHARGE = "收费项目"; + //是否启用高值耗材(新) + boolean enableExpensiveGoods = CssdUtils.getSystemSetConfigByNameBool("enableExpensiveGoods"); + //启用排除属于科研项目的一次性物品申请单的发货数据 + boolean excludeSciProjectInfo = CssdUtils.getSystemSetConfigByNameBool("enableExcludeInvoiceItemOfDisposableGoodsApplicationBelongToSciProject", false); + boolean showBatch = StrutsParamUtils.getBoolPraramValue("showBatch", true); + //判断当前登录用户是否为匿名用户.如果为匿名用户则只查询一级供应室的数据,否则根据实际情况的条件查询 + LoginUserData user = AcegiHelper.getLoginUser(); + String loginUserFullName = null; + String orgUnitCoding = null; + if (user != null){ + orgUnitCoding = user.getOrgUnitCodingFromSupplyRoomConfig(); + loginUserFullName = user.getUserFullName(); + } + boolean isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser = false; + if (supplyRoomConfigManager.isSupplyRoomUser() || supplyRoomConfigManager.isExpensiveGoodsSupplyRoomUser()) { + isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser = true; + } + if(StringUtils.equals(loginUserFullName, Constants.ANONYMOUS_USERNAME)){ + departCoding = supplyRoomConfigManager.getFirstSupplyRoomConfig().getOrgUnitCoding(); + } + Set departCodingSet = null; + Set departSearchSet = null; + if(StringUtils.isNotBlank(departGroupStr)){ + departSearchSet = new HashSet(); + departCodingSet = new HashSet(); + Set departGroupIds = null; + if(departGroupStr.contains(",")){ + departGroupIds = SqlUtils.splitStringToSet(departGroupStr, ","); + }else{ + departGroupIds = new HashSet(); + departGroupIds.add(departGroupStr); + } + List invoiceDepartments = objectDao.findByHql("select po from " + InvoiceDepartment.class.getSimpleName() + " po where " + SqlUtils.getNonStringFieldInLargeCollectionsPredicate("po.id", departGroupIds)); + for (InvoiceDepartment invoiceDepartment : invoiceDepartments) { + if("全部".equals(invoiceDepartment)){ + departSearch = null; + departCoding = null; + break; + } + Set thisDepartSearchs = SqlUtils.splitStringToSet(invoiceDepartment.getDepartNames(), ";"); + departSearchSet.addAll(thisDepartSearchs); + Set thisDepartCodings = SqlUtils.splitStringToSet(invoiceDepartment.getDepartCodes(), ";"); + departCodingSet.addAll(thisDepartCodings); + } + departCoding = ""; + departSearch = ""; + invoicePlanDepartCoding = ""; + }else{ + departCodingSet = SqlUtils.splitStringToSet(departCoding, ","); + departSearchSet = SqlUtils.splitStringToSet(departSearch, ","); + } + Set invoicePlanDepartCodingSet = SqlUtils.splitStringToSet(invoicePlanDepartCoding, ","); + boolean enableToussePointsStatistics = CssdUtils.getSystemSetConfigByNameBool("enableToussePointsStatistics", false); + boolean showMaterialsAmountColumnOfDetailMonthReport = CssdUtils.getSystemSetConfigByNameBool("showMaterialsAmountColumnOfDetailMonthReport", false); + + List datas = new ArrayList(); + List allTousseType = new ArrayList(); + Set returnGoodType = new HashSet(); + if(StringTools.isBlank(typeSearch) || typeSearch.contains("全部器械包")){ + allTousseType.add(TousseDefinition.PACKAGE_TYPE_CUSTOM); + allTousseType.add(TousseDefinition.PACKAGE_TYPE_DISINFECTION); + allTousseType.add(TousseDefinition.PACKAGE_TYPE_DRESSING); + allTousseType.add(TousseDefinition.PACKAGE_TYPE_FOREIGN); + allTousseType.add(TousseDefinition.PACKAGE_TYPE_FOREIGNPROXY); + allTousseType.add(TousseDefinition.PACKAGE_TYPE_INSIDE); + allTousseType.add(TousseDefinition.PACKAGE_TYPE_SPLIT); + allTousseType.add(TousseDefinition.PACKAGE_TYPE_COMBO); + if(StringTools.isBlank(typeSearch) && enableExpensiveGoods){ + allTousseType.add(ExpensiveGoods.TYPE_NAME); + } + returnGoodType.add("器械包"); + } + Set typeSearchSet = new HashSet(); + if(!StringTools.isBlank(typeSearch)){ + typeSearchSet = SqlUtils.splitStringToSet(typeSearch, ","); + if(!typeSearchSet.contains("全部器械包")){ + if(typeSearchSet.contains("外来器械包")){ + allTousseType.add(TousseDefinition.PACKAGE_TYPE_FOREIGN); + allTousseType.add(TousseDefinition.PACKAGE_TYPE_SPLIT); + returnGoodType.add("器械包"); + } + if(typeSearchSet.contains("外部代理灭菌包")){ + allTousseType.add(TousseDefinition.PACKAGE_TYPE_FOREIGNPROXY); + returnGoodType.add("器械包"); + } + if(typeSearchSet.contains(ExpensiveGoods.TYPE_NAME) && enableExpensiveGoods){ + allTousseType.add(ExpensiveGoods.TYPE_NAME); + } + if(typeSearchSet.contains(TousseDefinition.PACKAGE_TYPE_CUSTOM)){ + allTousseType.add(TousseDefinition.PACKAGE_TYPE_CUSTOM); + returnGoodType.add("器械包"); + } + if(typeSearchSet.contains(TousseDefinition.PACKAGE_TYPE_INSIDE)){ + allTousseType.add(TousseDefinition.PACKAGE_TYPE_INSIDE); + returnGoodType.add("器械包"); + } + if(typeSearchSet.contains(TousseDefinition.PACKAGE_TYPE_DRESSING)){ + allTousseType.add(TousseDefinition.PACKAGE_TYPE_DRESSING); + returnGoodType.add("器械包"); + } + if(typeSearchSet.contains(TousseDefinition.PACKAGE_TYPE_DISINFECTION)){ + allTousseType.add(TousseDefinition.PACKAGE_TYPE_DISINFECTION); + returnGoodType.add("器械包"); + } + } + if(typeSearchSet.contains("一次性物品")){ + returnGoodType.add("一次性物品"); + } + } + // 查看是否配置显示供应商 + Boolean showSupplierNameInDetailedAccountingMonthlyReport = CssdUtils.getSystemSetConfigByNameBool("showSupplierNameInDetailedAccountingMonthlyReport", false); + String tousseDefinitionOfSupplierNameSql = "";//用器械包定义里的供应商拼接的sql语句,主要用于查询供应商和按供应商分组 + String addTousseDefinitionAtWhere = "";//拼接sql,用于添加查询TousseDefinition + String tousseInstanceJoinTousseDefinitionSql = ""; + String dgbsOfSupplierNameSql = "";//用于查询DisposableGoodsBatchStock或DisposableGoodsBatch的供应商名称,主要用于查询供应商和按供应商分组 + String noQuerySupplierName = "";//不需要查询器械包名称的sql,用于连接union all连接表时保持列数不变 + String integralOftousseDefinitionSql = ""; + String noQueryIntegralSql = ""; + String unitSqlOftousseDefinitionSql = ""; + boolean queryUrgent = false; + if(StringUtils.isNotBlank(urgentLevel) && !urgentLevel.contains("全部")){ + queryUrgent = true; + tousseInstanceJoinTousseDefinitionSql = " join TousseDefinition td on td.id=ti.tousseDefinition_id "; + } + + if(enableToussePointsStatistics){ + addTousseDefinitionAtWhere = " left join TousseDefinition td on td.id = ii.tousseDefinitionId "; + integralOftousseDefinitionSql = ",td.integral "; + noQueryIntegralSql = ",0 integral "; + }else if(showSupplierNameInDetailedAccountingMonthlyReport){ + addTousseDefinitionAtWhere = " join TousseDefinition td on td.id = ii.tousseDefinitionId "; + }else if(queryUnit){ + addTousseDefinitionAtWhere = " left join TousseDefinition td on td.id = ii.tousseDefinitionId "; + unitSqlOftousseDefinitionSql = ",td.unit "; + } + + boolean queryTousseGroupName = false;//是否查询器械包分组 + String nullTousseGroupNameSQL = ""; + String tdcTousseGroupNameSQL = ""; + String tdLeftJoinTdcSQL = ""; + if(StringUtils.isNotBlank(extendedColumnConfigOfDetailedAccountingMonthlyReport)){ + JSONArray arr = JSONArray.fromObject(extendedColumnConfigOfDetailedAccountingMonthlyReport); + for (int i = 0; i < arr.size(); i++) { + String extendedColumnName = arr.get(i).toString().trim(); + if(StringUtils.isBlank(extendedColumnName)){ + continue; + } + if("tousseGroupName".equals(extendedColumnName)){ + queryTousseGroupName = true; + tdcTousseGroupNameSQL = ",tdc.tousseGroupName "; + nullTousseGroupNameSQL = ",null tousseGroupName "; + tdLeftJoinTdcSQL = " left join TousseDefinition tdc on tdc.id=td.ancestorID "; + } + } + } + if(queryTousseGroupName){ + if(StringUtils.isBlank(addTousseDefinitionAtWhere)){ + addTousseDefinitionAtWhere += " left join TousseDefinition td on td.id = ii.tousseDefinitionId " + + "left join TousseDefinition tdc on tdc.id=td.ancestorID "; + }else{ + addTousseDefinitionAtWhere += " left join TousseDefinition tdc on tdc.id=td.ancestorID "; + } + if(queryUrgent){ + tousseInstanceJoinTousseDefinitionSql += " join TousseDefinition tdc on tdc.id=td.ancestorID "; + } + } + String noQueryUnitSql = ""; + //通过DiposableGoodsItem查询一次性物品单位的相关sql + String unitDSqlOfDiposableGoodsItem = ""; + String unitDGroupBySqlOfDiposableGoodsItem = ""; + String unitDGISqlOfDiposableGoodsItem = ""; + String unitDGIGroupBySqlOfDiposableGoodsItem = ""; + //通过materialDefinition查询一次性物品单位的相关sql + String unitDSqlOfMd = ""; + String unitMSqlOfMd = ""; + //通过DisposableGoods查询一次性物品单位的相关sql + String unitDGSqlOfDisposableGoods = ""; + if(queryUnit){ + unitDSqlOfDiposableGoodsItem = ",(select unit from DisposableGoods where id=d.disposableGoodsID) unit "; + unitDGroupBySqlOfDiposableGoodsItem = ",d.disposableGoodsID"; + unitDGISqlOfDiposableGoodsItem = ",(select unit from DisposableGoods where id=dgi.disposableGoodsID) unit "; + unitDGIGroupBySqlOfDiposableGoodsItem = ",dgi.disposableGoodsID"; + unitDSqlOfMd = ",d.unit "; + unitMSqlOfMd = ",m.unit"; + unitDGSqlOfDisposableGoods = ",dg.unit"; + noQueryUnitSql = ",null unit"; + } + if(showSupplierNameInDetailedAccountingMonthlyReport){ + tousseDefinitionOfSupplierNameSql = " ,td.supplierName "; + dgbsOfSupplierNameSql = " ,dgbs.supplierName "; + noQuerySupplierName = ",''"; + } + startTime += ":00"; + endTime += ":59"; +// String handleDeptCode = AcegiHelper.getLoginUser().getOrgUnitCodingFromSupplyRoomConfig(); + String monthFilterSql = " "; + String expensiveGoodsMonthFilterSql = " "; + String returnGoodsFilterSql = " "; + String returnGoodsTimeFilterSql = " "; + String packingDisposableGoodsTimeSql = " "; + String returnGoodsDepartFilterSql = " "; + String materialNameFilterSql = " "; + String materialTypeFilterSql = " "; + String lostMaterialFilterSql = " "; + String damageFilterSql = " "; + String supplyRoomDiposableGoodsFilterSql = " "; + String outEntryFilterSql = " "; + + String diposableGoodsItemPredicate = " (1=1) "; + String packingDisposableGoodsTypeSql = " (1=1) "; + String returnGoodsItemPredicate = " (1=1) "; + String receiveRecordItemPredicate = " (1=1) "; + String disposableGoodsIdSql = ""; + String outEntryPredicate = " 1=1 "; + + if(StringUtils.isNotBlank(disposableGoodsType) || filterWhetherToCharge){ + disposableGoodsIdSql = String.format(" select id from DisposableGoods where 1=1 %s %s", StringUtils.isNotBlank(disposableGoodsType)?" and type='"+ disposableGoodsType +"'":"" + , filterWhetherToCharge?" and whetherToCharge='"+ whetherToCharge +"'":""); + diposableGoodsItemPredicate = String.format(" (d.disposableGoodsID in(%s)) ", disposableGoodsIdSql); + packingDisposableGoodsTypeSql = String.format(" (dgi.disposableGoodsID in(%s)) ", disposableGoodsIdSql); +// returnGoodsItemPredicate = String.format(" (rr.type!='一次性物品' or rr.disposableGoodsId in(%s)) ", disposableGoodsIdSql); + returnGoodsItemPredicate = String.format(" (ri.disposableGoodsId in(%s)) ", disposableGoodsIdSql); + receiveRecordItemPredicate = String.format(" (rri.type!='一次性物品' or rri.disposableGoodsId in(%s)) ", disposableGoodsIdSql); + outEntryPredicate = String.format(" (ged.disposableGoodsID in(%s)) ", disposableGoodsIdSql); + } + String betweenSql = ""; + if (StringUtils.isNotBlank(startTime) && StringUtils.isNotBlank(endTime)) { + betweenSql = new StringBuffer(150).append(" between ") + .append(dateQueryAdapter.dateConverAdapter2( startTime, "yyyy-mm-dd HH24:MI:SS")) + .append(" and ") + .append(dateQueryAdapter.dateConverAdapter2( endTime, "yyyy-mm-dd HH24:MI:SS")).toString(); + monthFilterSql = " and i.sendtime" + betweenSql; + expensiveGoodsMonthFilterSql = " and egge.time" + betweenSql; + returnGoodsTimeFilterSql = " and rr.returntime" + betweenSql; + returnGoodsFilterSql = returnGoodsTimeFilterSql; + packingDisposableGoodsTimeSql = " and pr.packTime "+betweenSql; + lostMaterialFilterSql = " and i.additionalTime" + betweenSql; + damageFilterSql = " and i.additionalTime" + betweenSql; + + supplyRoomDiposableGoodsFilterSql = " and rr.time" + betweenSql; + outEntryFilterSql = " and oge.time" + betweenSql; + } else { + monthFilterSql = " and 1=2 "; + returnGoodsFilterSql = " and 1=2 "; + packingDisposableGoodsTimeSql = " and 1=2 "; + lostMaterialFilterSql = " and 1=2 "; + damageFilterSql = " and 1=2 "; + } + String departFilterSql = ""; + String packingDisposableGoodsDepartSql = ""; + String chargeDepartSql = ""; + String prDepartCodingSql = null; + String iDepartCodeSql = null; + String ogeTargetOrgUnitCodeSql = null; + String ogeOrgUnitCodeSql = null; + if(invoicePlanDepartCodingSet.size() > 0){ + returnGoodsFilterSql += " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("rr.departCoding", invoicePlanDepartCodingSet); + prDepartCodingSql = " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("pr.departCoding", invoicePlanDepartCodingSet); + iDepartCodeSql = " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("i.departCode", invoicePlanDepartCodingSet); + ogeTargetOrgUnitCodeSql = " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("oge.targetOrgUnitCode", invoicePlanDepartCodingSet); + ogeOrgUnitCodeSql = " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("oge.orgUnitCode", invoicePlanDepartCodingSet); + }else{ + prDepartCodingSql = ""; + iDepartCodeSql = ""; + ogeTargetOrgUnitCodeSql = ""; + ogeOrgUnitCodeSql = ""; + } + String rrSettleAccountsDepartCodingSql = null; + if (CollectionUtils.isNotEmpty(departSearchSet)) { + departFilterSql = " and "+ SqlUtils.getStringFieldInLargeCollectionsPredicate("i.settleaccountsdepart", departSearchSet); + returnGoodsDepartFilterSql = " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("rr.settleAccountsDepart", departSearchSet); + packingDisposableGoodsDepartSql = " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("pr.orgUnitName", departSearchSet); + lostMaterialFilterSql += " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("i.settleAccountsDepart", departSearchSet); + damageFilterSql += " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("i.settleAccountsDepart", departSearchSet);; + supplyRoomDiposableGoodsFilterSql += " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("rr.departCoding", departCodingSet);; + outEntryFilterSql += " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("oge.orgUnitCode", departCodingSet);; + rrSettleAccountsDepartCodingSql = " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("rr.settleAccountsDepartCoding", departCodingSet); + }else{ + rrSettleAccountsDepartCodingSql = ""; + } + String typeFilterSql = " "; + String tdTypeSql = " "; + String expensiveDisposablegoodsIdSql = ""; + if (StringUtils.isNotBlank(typeSearch)) { + tdTypeSql = String.format(" and (%s)", SqlUtils.getStringFieldInLargeCollectionsPredicate("td.tousseType", allTousseType)); + typeFilterSql = String.format(" and (%s)", SqlUtils.getStringFieldInLargeCollectionsPredicate("ii.tousseType", allTousseType)); + if(typeSearchSet.contains("一次性物品") && typeSearchSet.size() > 1){//不止一次性物品 + returnGoodsItemPredicate += " and (rr.type='一次性物品' or ri.tousseDefinition_id in (select id from TousseDefinition where "+ SqlUtils.getStringFieldInLargeCollectionsPredicate("tousseType", allTousseType) +")) "; + }else if(!typeSearchSet.contains("一次性物品") && typeSearchSet.size() > 0){//不包含一次性物品 + returnGoodsItemPredicate += String.format(" and ri.tousseDefinition_id in (select id from TousseDefinition where %s) ", SqlUtils.getStringFieldInLargeCollectionsPredicate("tousseType", allTousseType)); + } + returnGoodsFilterSql += " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("rr.type", returnGoodType); + if(!typeSearch.contains("一次性物品") && !typeSearch.contains(DisposableGoods.TYPE_EXPENSIVEDIPOSABLEGOODS)){ + outEntryFilterSql += " and 1=2 "; + }else if(!typeSearch.contains("一次性物品") && typeSearch.contains(DisposableGoods.TYPE_EXPENSIVEDIPOSABLEGOODS)){ + outEntryFilterSql += " and dg.goodsType = '" + DisposableGoods.TYPE_EXPENSIVEDIPOSABLEGOODS + "' "; + } + if(typeSearch.contains("器械材料") && typeSearch.contains("一次性物品") ){ + supplyRoomDiposableGoodsFilterSql += " and (rri.type = '一次性物品' or rri.materialDefinition_id in (select id from MaterialDefinition)) "; + }else if(typeSearch.contains("器械材料") && typeSearch.contains(TYPE_AUTO_DEDUCTION)){ + supplyRoomDiposableGoodsFilterSql += " and (rri.materialDefinition_id in (select id from MaterialDefinition) or rr.type='"+ TYPE_AUTO_DEDUCTION +"') "; + }else if(typeSearch.contains(TYPE_AUTO_DEDUCTION)){ + supplyRoomDiposableGoodsFilterSql += " and rr.type='"+ TYPE_AUTO_DEDUCTION +"'"; + }else if(typeSearch.contains("器械材料")){ + supplyRoomDiposableGoodsFilterSql += " and rri.materialDefinition_id in (select id from MaterialDefinition) "; + }else if(typeSearch.contains("一次性物品")){ + supplyRoomDiposableGoodsFilterSql += " and rri.type = '一次性物品' "; + }else if(!typeSearch.contains(TYPE_AUTO_DEDUCTION)){ + supplyRoomDiposableGoodsFilterSql += " and 1=2 "; + } + + if(typeSearch.contains("器械材料") || typeSearch.contains("器械材料") && typeSearch.contains(MaterialDefinition.TYPE_EXPENSIVEMATERIALGOODS)){ + lostMaterialFilterSql += " and 1=1 "; + damageFilterSql += " and 1=1 "; + materialTypeFilterSql = " and 1=1 "; + }else if(typeSearch.contains("高值耗材")){ + if(enableExpensiveGoods){ + lostMaterialFilterSql += " and 1=2 "; + damageFilterSql += " and 1=1 "; + }else{ + lostMaterialFilterSql += " and m.goodsType = '"+MaterialDefinition.TYPE_EXPENSIVEMATERIALGOODS+"' "; + damageFilterSql += " and m.goodsType = '"+MaterialDefinition.TYPE_EXPENSIVEMATERIALGOODS+"' "; + if(StringUtils.isNotBlank(goodsType)){ + if("一次性物品".equals(goodsType)){ + materialTypeFilterSql = " and 1=2 "; + }else{ + materialTypeFilterSql = " and d.goodsType = '"+MaterialDefinition.TYPE_EXPENSIVEMATERIALGOODS+"'"; + expensiveDisposablegoodsIdSql = " and 1=2 "; + } + }else{ + materialTypeFilterSql += " and d.goodsType = '"+MaterialDefinition.TYPE_EXPENSIVEMATERIALGOODS+"'"; + } + } + }else{ + lostMaterialFilterSql += " and 1=2 "; + damageFilterSql += " and 1=2 "; + } + }else{ + if(!enableExpensiveGoods){ + //没有启用高值耗材,就不查询新的高值耗材的数据 + typeFilterSql = " and ii.tousseType <> '" + ExpensiveGoods.TYPE_NAME + "'"; + } + } + String goodsNameFilterSql = " "; + String tdNameFilterSql = ""; + String expensiveGoodsNameFilterSql = " "; + String chargeItemSql = "";//收费项目名称过滤 + if (StringUtils.isNotBlank(goodsNameSearch)) { + if("精确查询".equals(searchType)){ + tdNameFilterSql = " and td.name ='"+ goodsNameSearch +"' "; + goodsNameFilterSql = " and ii.toussename = '" + goodsNameSearch + + "'"; + expensiveGoodsNameFilterSql = " and case when egm.model is null then eg.name else eg.name + '[' + egm.model + ']' end = '%" + goodsNameSearch + + "%'"; + returnGoodsFilterSql += " and ri.toussename = '" + + goodsNameSearch + "'"; + materialNameFilterSql = " and ii.materialName = '" + + goodsNameSearch + "' "; + lostMaterialFilterSql += " and i.materialName = '" + + goodsNameSearch + "'"; + damageFilterSql += " and i.materialName = '" + + goodsNameSearch + "'"; + supplyRoomDiposableGoodsFilterSql += " and rri.goodsName = '"+goodsNameSearch+"'"; + outEntryFilterSql += " and ged.goodsName = '"+goodsNameSearch+"'"; + chargeItemSql = " and chargeItem = '"+goodsNameSearch+"' "; + }else{ + tdNameFilterSql = " and td.name like '%"+ goodsNameSearch +"%' "; + goodsNameFilterSql = " and ii.toussename like '%" + goodsNameSearch + + "%'"; + expensiveGoodsNameFilterSql = " and case when egm.model is null then eg.name else eg.name + '[' + egm.model + ']' end like '%" + goodsNameSearch + + "%'"; + returnGoodsFilterSql += " and ri.toussename like '%" + + goodsNameSearch + "%'"; + materialNameFilterSql = " and ii.materialName like '%" + + goodsNameSearch + "%' "; + lostMaterialFilterSql += " and i.materialName like '%" + + goodsNameSearch + "%'"; + damageFilterSql += " and i.materialName like '%" + + goodsNameSearch + "%'"; + supplyRoomDiposableGoodsFilterSql += " and rri.goodsName like '%"+goodsNameSearch+"%' "; + outEntryFilterSql += " and ged.goodsName like '%"+goodsNameSearch+"%' "; + chargeItemSql = " and chargeItem like '%"+goodsNameSearch+"%' "; + } + //消毒物品需用like查询 + if(disinfection){ + tdNameFilterSql = " and td.name like '%"+ goodsNameSearch +"%' "; + goodsNameFilterSql = " and ii.toussename like '%" + goodsNameSearch + + "%'"; + returnGoodsFilterSql += " and ri.toussename like '%" + + goodsNameSearch + "%'"; + lostMaterialFilterSql += " and i.materialName like '%" + + goodsNameSearch + "%'"; + damageFilterSql += " and i.materialName like '%" + + goodsNameSearch + "%'"; + + supplyRoomDiposableGoodsFilterSql += " and 1=2"; + outEntryFilterSql += " and 1=2"; + } + } + String nameFilterSql = ""; + String packingDisposableGoodsNameSql = ""; + if (StringUtils.isNotBlank(goodsNameSearch)) { + nameFilterSql = " and d.name = '" + goodsNameSearch + "'"; + packingDisposableGoodsNameSql = " and dgi.name = '" + goodsNameSearch + "'"; + } + String iDepartCodingSql = " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("i.departCoding", invoicePlanDepartCodingSet," 1=1 "); + String rrDepartCodingSql = " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("rr.departCoding", invoicePlanDepartCodingSet," 1=1 "); + String ciOrgUnitCodeSql = " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("ci.orgUnitCode", invoicePlanDepartCodingSet," 1=1 "); + String supplyRoomDiposableGoodsFilterSqlOFDgbs = ""; + if (StringUtils.isNotBlank(batch)) { + nameFilterSql += " and d.batch = '" + batch + "'"; + goodsNameFilterSql += " and 1=2 "; + tdNameFilterSql = " and 1=2 "; + returnGoodsFilterSql += " and ri.batchNumber = '"+batch+"' "; + packingDisposableGoodsNameSql += " and dgi.batch = '"+batch+"' "; + lostMaterialFilterSql += " and 1=2 "; + damageFilterSql += " and 1=2 "; + supplyRoomDiposableGoodsFilterSqlOFDgbs = supplyRoomDiposableGoodsFilterSql + " and dgbs.batchNumber = '"+batch+"'"; + supplyRoomDiposableGoodsFilterSql += " and dgbs.batchNumber = '"+batch+"'"; + outEntryFilterSql += " and dgbs.batchNumber = '"+batch+"'"; + } + String tousseMaterialAmountSql = null; + String noMaterialAmountSql = null; + String returnGoodsItemMaterialAmountSql = null; + String sumRriAmountSql = null; + String groupByMaterialAmountAtThatTime = null; + String tousseInstanceMaterialAmountSql = null; + String sumMaterialAmountSql = null; + if(showMaterialsAmountColumnOfDetailMonthReport){ + sumMaterialAmountSql = " sum(materialAmount) materialAmount,"; + tousseInstanceMaterialAmountSql = " sum(ti.materialAmount) materialAmount,"; + tousseMaterialAmountSql = " sum(ii.materialAmount*ii.amount) materialAmount,"; + noMaterialAmountSql = " 0 materialAmount,"; + returnGoodsItemMaterialAmountSql = " case when ri.materialAmountAtThatTime is null then sum(-ri.materialAmount*ri.amount) else sum(-ri.materialAmountAtThatTime*ri.amount) end materialAmount,"; + sumRriAmountSql = "sum(rri.amount) materialAmount,"; + groupByMaterialAmountAtThatTime = ",ri.materialAmountAtThatTime "; + }else{ + sumMaterialAmountSql = ""; + tousseInstanceMaterialAmountSql = ""; + tousseMaterialAmountSql = ""; + noMaterialAmountSql = ""; + returnGoodsItemMaterialAmountSql = ""; + sumRriAmountSql = ""; + groupByMaterialAmountAtThatTime = ""; + } + String iSendTime = ""; + String groupByIsendTime = ""; + String noSendTime = ""; + if(showSendTime){ + String dateSql = dateQueryAdapter.dateConverAdapter(dateQueryAdapter.stringFieldToDate("i.sendTime"),"yyyy-MM-dd"); + iSendTime = ","+ dateSql +" sendTime "; + groupByIsendTime = "," + dateSql; + noSendTime = ",null sendTime "; + } + String returnGoodsTousseType = " CASE rr.type WHEN '一次性物品' THEN (rr.type) WHEN '器械包' THEN (td.toussetype) ELSE rr.type END "; + String returnGoodsTousseDefinitionId = " CASE rr.type WHEN '器械包' THEN ri.tousseDefinition_id ELSE 0 END "; + //器械包 + String tousseSql = null; + String urgentSql = ""; + if(queryUrgent){//加急要过滤到包实例 + 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, ",")) +" )"; + }else{ + urgentSql = " and " + SqlUtils.getNonStringFieldInLargeCollectionsPredicate("ti.urgentLevel_id", SqlUtils.splitStringToSet(urgentLevel, ",")); + } + String showTimeOfT = ""; + if(showTime){ + showTimeOfT = ",showTime "; + } + String sendTimeOfT = ""; + if(showSendTime){ + sendTimeOfT = ",sendTime "; + } + String tousseGroupNameOfT = ""; + if(queryTousseGroupName){ + tousseGroupNameOfT = ",tousseGroupName "; + } + String groupBySql = "group by i.depart" + + tdcTousseGroupNameSQL + + groupByIsendTimeOfShowTime + groupByIsendTime + unitSqlOftousseDefinitionSql + +",i.settleAccountsDepart,td.tousseType,td.name,td.id " + + tousseDefinitionOfSupplierNameSql + integralOftousseDefinitionSql; + String groupBySqlOfT = "group by depart" + + showTimeOfT + + sendTimeOfT + + tousseGroupNameOfT + + getRemovePrefixSql(unitSqlOftousseDefinitionSql) + +",settleAccountsDepart,type,name,tousseDefinitionId " + + getRemovePrefixSql(tousseDefinitionOfSupplierNameSql) + + getRemovePrefixSql(integralOftousseDefinitionSql); + tousseSql = " select "+ sumMaterialAmountSql +"depart,settleAccountsDepart" + + showTimeOfT + + sendTimeOfT + + getRemovePrefixSql(tousseDefinitionOfSupplierNameSql) + + getRemovePrefixSql(integralOftousseDefinitionSql) + + ",name,sum(amount) amount,sum(settlementprice) settlementprice,sum(settlementDiscountPrice) settlementDiscountPrice,type" + + getRemovePrefixSql(unitSqlOftousseDefinitionSql) + + ",'' as batchNumber,null as expDate,tousseDefinitionId" + + tousseGroupNameOfT + + " from ( select " + + tousseInstanceMaterialAmountSql + +" i.depart,i.settleAccountsDepart " + + iSendTimeSqlOfShowTime + + iSendTime + + tousseDefinitionOfSupplierNameSql + + integralOftousseDefinitionSql + +",td.name,count(*) as amount," + +"sum(ti.price) as settlementprice,sum(ti.discountPrice) as settlementDiscountPrice,td.tousseType as type" + + unitSqlOftousseDefinitionSql + + ",'' as batchNumber,null as expDate,td.id as tousseDefinitionId" + + tdcTousseGroupNameSQL + + " from invoice i " + + "join TousseInstance ti on ti.invoice_id=i.id " + + tousseInstanceJoinTousseDefinitionSql + + " where " + + getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + + monthFilterSql + + iDepartCodingSql + + departFilterSql + + tdTypeSql + + tdNameFilterSql + + urgentSql + + " and i.settleaccountsdepart is not null " + + groupBySql; + tousseSql += " union all " + + " select " + + tousseInstanceMaterialAmountSql + +" i.depart,i.settleAccountsDepart " + + iSendTimeSqlOfShowTime + + iSendTime + + tousseDefinitionOfSupplierNameSql + + integralOftousseDefinitionSql + +",td.name,count(*) as amount," + +"sum(ti.price) as settlementprice,sum(ti.discountPrice) as settlementDiscountPrice,td.tousseType as type" + + unitSqlOftousseDefinitionSql + + ",'' as batchNumber,null as expDate,td.id as tousseDefinitionId" + + tdcTousseGroupNameSQL + + " from invoice i " + + "join TousseInstance ti on ti.invoice2_id=i.id " + + tousseInstanceJoinTousseDefinitionSql + + " where " + + getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + + monthFilterSql + + iDepartCodingSql + + departFilterSql + + tdTypeSql + + tdNameFilterSql + + urgentSql + + " and i.settleaccountsdepart is not null " + + groupBySql + + ") t " + + groupBySqlOfT; + }else{ + tousseSql = " (select "+ tousseMaterialAmountSql +" i.depart,i.settleAccountsDepart "+ iSendTimeSqlOfShowTime + iSendTime + tousseDefinitionOfSupplierNameSql + integralOftousseDefinitionSql +",ii.tousseName as name,sum(ii.amount) as amount," + +"sum(ii.settlementPrice) as settlementprice,sum(ii.settlementDiscountPrice) as settlementDiscountPrice,ii.tousseType as type" + + unitSqlOftousseDefinitionSql + + ",'' as batchNumber,null as expDate,ii.tousseDefinitionId as tousseDefinitionId " + + tdcTousseGroupNameSQL + + "from invoice i" + + " join InvoiceItem ii on i.id = ii.invoice_id " + + addTousseDefinitionAtWhere + + " where ii.diposable = '否' and ii.expensiveGoodsInstanceId is null and "+ getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + + monthFilterSql + + iDepartCodingSql + + departFilterSql + + typeFilterSql + + goodsNameFilterSql + + " and i.settleaccountsdepart is not null group by i.depart"+ tdcTousseGroupNameSQL + groupByIsendTimeOfShowTime + groupByIsendTime + unitSqlOftousseDefinitionSql +",i.settleAccountsDepart,ii.tousseType,ii.tousseName,ii.tousseDefinitionId " + tousseDefinitionOfSupplierNameSql + integralOftousseDefinitionSql + ")"; + } + //新的高值耗材(发货) + String selectExpensiveGoodsSql = ""; + //如果有启用高值耗材则查询 + if(enableExpensiveGoods){ + selectExpensiveGoodsSql = " union all (select "+ noMaterialAmountSql +" i.depart,i.settleAccountsDepart"+ iSendTimeSqlOfShowTime + iSendTime + noQuerySupplierName + noQueryIntegralSql +",case when egm.model is null then eg.name else eg.name "+ concatSymbolInDb +" '[' "+ concatSymbolInDb +" egm.model "+ concatSymbolInDb +" ']' end as name,sum(ii.amount) as amount," + +"sum(ii.settlementPrice) as settlementprice,sum(ii.settlementDiscountPrice) as settlementDiscountPrice,ii.tousseType as type" + + noQueryUnitSql + + ",'' as batchNumber,ei.expDate as expDate,0 as tousseDefinitionId" + + nullTousseGroupNameSQL + + " from " + Invoice.class.getSimpleName() + " i join " + + InvoiceItem.class.getSimpleName()+" ii on i.id = ii.invoice_id join " + ExpensiveGoodsInstance.class.getSimpleName() + + " ei on ei.id = ii.expensiveGoodsInstanceId" + + " join ExpensiveGoods eg on ei.expensiveGoods_id=eg.id " + + " left join ExpensiveGoodsModel egm on ei.expensiveGoodsModelId=egm.id" + + " where ii.diposable = '否' and " + + getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + + monthFilterSql + + departFilterSql + + iDepartCodingSql + + typeFilterSql + + goodsNameFilterSql + + " and i.settleaccountsdepart is not null group by i.depart"+ groupByIsendTime +",i.settleAccountsDepart,ii.tousseType,case when egm.model is null then eg.name else eg.name "+ concatSymbolInDb +" '[' "+ concatSymbolInDb +" egm.model "+ concatSymbolInDb +" ']' end,ii.expensiveGoodsInstanceId,ei.expDate)"; + //新的高值耗材(一键退库-即退货),如果所选物品类型为全部或高值耗材时, + String orgUnitCodingSql = departCodingSet.size() > 0?" and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("i.orgUnitCoding", departCodingSet):""; + selectExpensiveGoodsSql += " union all (select "+ noMaterialAmountSql +" i.depart,i.settleAccountsDepart " + iSendTimeSqlOfShowTime + iSendTime + noQuerySupplierName + noQueryIntegralSql +",case when egm.model is null then eg.name else eg.name "+ concatSymbolInDb +" '[' "+ concatSymbolInDb +" egm.model "+ concatSymbolInDb +" ']' end as name,-1 * count(egi.id) as amount,-1 * sum(egi.price) settlementprice,-1 * sum(egi.price) settlementprice,'高值耗材' as type" + + noQueryUnitSql + + ",null as batchNumber,egi.expDate,null as tousseDefinitionId " + + nullTousseGroupNameSQL + + " from ExpensiveGoodsGodownEntry egge join ExpensiveGoodsGodownEntryItem eggei on egge.id=eggei.expensiveGoodsGodownEntry_id " + +" join ExpensiveGoodsInstance egi on egi.id=eggei.expensiveGoodsInstanceId " + +" join Invoice i on egi.invoiceId=i.id " + +" join ExpensiveGoods eg on egi.expensiveGoods_id=eg.id " + +" left join ExpensiveGoodsModel egm on egi.expensiveGoodsModelId=egm.id " + +" where 1=1 and egge.type='退库单' " + + orgUnitCodingSql + + expensiveGoodsMonthFilterSql + + (StringUtils.isBlank(typeSearch) || StringUtils.equals(ExpensiveGoods.TYPE_NAME, typeSearch) ? " " : " and 1=2 ") + + departFilterSql + + iDepartCodingSql + + expensiveGoodsNameFilterSql + + " and i.settleaccountsdepart is not null group by i.depart"+ groupByIsendTimeOfShowTime + groupByIsendTime +",i.settleAccountsDepart,case when egm.model is null then eg.name else eg.name "+ concatSymbolInDb +" '[' "+ concatSymbolInDb +" egm.model "+ concatSymbolInDb +" ']' end,egi.expDate)"; + } + + String diposableGoodsSql = " "; + String invoiceJoinInvoicePlanSql = null; + String excludeSciProjectSql = null; + String excludeDiposableGoodsItemSql = null; + if(excludeSciProjectInfo){//排除属于科研项目的一次性物品申请单的发货数据 + invoiceJoinInvoicePlanSql = " left join "+ InvoicePlan.class.getSimpleName() +" ip on i.invoicePlan_ID=ip.id "; + excludeSciProjectSql = " and (ip.projName is null or ip.projName='')"; + excludeDiposableGoodsItemSql = " and dgi.invoice_id in (select i.id from "+ Invoice.class.getSimpleName() +" i left join "+ InvoicePlan.class.getSimpleName() +" ip on ip.id=i.invoicePlan_ID where (ip.projName is null or ip.projName='') and dgi.invoice_id=i.id) "; + }else{ + invoiceJoinInvoicePlanSql = ""; + excludeSciProjectSql = ""; + excludeDiposableGoodsItemSql = ""; + } + if(StringUtils.isBlank(typeSearch) || typeSearch.contains("一次性物品")){ + diposableGoodsSql += " union all (select "+ noMaterialAmountSql +" i.depart,i.settleaccountsdepart "+ iSendTimeSqlOfShowTime + iSendTime + dgbsOfSupplierNameSql+noQueryIntegralSql +",d.name as name,sum(d.amount) as amount," + +"sum(d.fluctuationPrice*d.amount) as settlementprice,sum(d.fluctuationPrice*d.amount) as settlementDiscountPrice,'一次性物品' as type" + + unitDSqlOfDiposableGoodsItem + + ",d.batch as batchNumber,dgbs.expDate,0 as tousseDefinitionId " + + nullTousseGroupNameSQL + + " from invoice i join DiposableGoodsItem d on d.invoice_id=i.id join " + DisposableGoodsBatchStock.class.getSimpleName() + " dgbs on d.disposableGoodsBatchStockID=dgbs.id " + + invoiceJoinInvoicePlanSql + + " where 1=1 and " + + getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + +" and "+diposableGoodsItemPredicate + + monthFilterSql + + excludeSciProjectSql + + departFilterSql + + iDepartCodingSql + + nameFilterSql + + " group by 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," + +"sum(d.fluctuationPrice*d.amount) as settlementprice,sum(d.fluctuationPrice*d.amount) as settlementDiscountPrice,'一次性物品' as type" + + unitDSqlOfDiposableGoodsItem + + ",d.batch as batchNumber,dgbs.expDate,0 as tousseDefinitionId" + + nullTousseGroupNameSQL + + " from invoice i join DiposableGoodsItem d on d.invoice_id=i.id join " + DisposableGoodsBatchStock.class.getSimpleName() + " dgbs on d.disposableGoodsBatchStockID=dgbs.id " + + invoiceJoinInvoicePlanSql + + " where " + + getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + +" and "+diposableGoodsItemPredicate + + monthFilterSql + + excludeSciProjectSql + + departFilterSql + + iDepartCodingSql + + nameFilterSql + + " and d.expensiveDisposablegoodsId is not null " + + expensiveDisposablegoodsIdSql + + " group by i.depart"+ groupByIsendTimeOfShowTime + groupByIsendTime + unitDGroupBySqlOfDiposableGoodsItem +",i.settleaccountsdepart,d.name,d.batch,dgbs.expDate "+ dgbsOfSupplierNameSql +") "; + } + if(typeSearch.contains(TYPE_AUTO_DEDUCTION)){ + diposableGoodsSql += " union all (select "+ noMaterialAmountSql +" i.depart,i.settleaccountsdepart "+ iSendTimeSqlOfShowTime + iSendTime+ dgbsOfSupplierNameSql+noQueryIntegralSql +",d.name as name,sum(d.amount) as amount," + +"sum(d.fluctuationPrice*d.amount) as settlementprice,sum(d.fluctuationPrice*d.amount) as settlementDiscountPrice,'一次性物品' as type" + + unitDSqlOfDiposableGoodsItem + + ",d.batch as batchNumber,dgbs.expDate,0 as tousseDefinitionId" + + nullTousseGroupNameSQL + + " from invoice i join DiposableGoodsItem d on d.invoice_id=i.id join " + DisposableGoodsBatchStock.class.getSimpleName() + " dgbs on d.disposableGoodsBatchStockID=dgbs.id " + + invoiceJoinInvoicePlanSql + + " where 1=1 and " + + getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + +" and "+diposableGoodsItemPredicate + + String.format(" and d.type='%s' ", InvoiceItem.TYPE_AUTO_DEDUCTION) + + monthFilterSql + + excludeSciProjectSql + + departFilterSql + + iDepartCodingSql + + nameFilterSql + + " group by i.depart"+ groupByIsendTimeOfShowTime + groupByIsendTime + unitDGroupBySqlOfDiposableGoodsItem +",i.settleaccountsdepart,d.name,d.batch,dgbs.expDate "+ dgbsOfSupplierNameSql +") "; + } + } + String packingDisposableGoodsSql = " "; + { + if(StringUtils.isBlank(typeSearch) || "一次性物品".equals(typeSearch)){ + packingDisposableGoodsSql = " union all (select "+ noMaterialAmountSql +" pr.depart,pr.orgUnitName "+ prPackTimeSqlOfShowTime + noSendTime + dgbsOfSupplierNameSql + noQueryIntegralSql +",dgi.name as name,sum(dgi.amount) as amount," + +"sum(dgi.fluctuationPrice*dgi.amount) as settlementprice,sum(dgi.fluctuationPrice*dgi.amount) as settlementDiscountPrice,'一次性物品' as type" + + unitDGISqlOfDiposableGoodsItem + + ",dgi.batch as batchNumber,dgbs.expDate,0 as tousseDefinitionId" + + nullTousseGroupNameSQL + + " from PackingRecord pr inner join DiposableGoodsItem dgi on pr.id = dgi.packingRecordId " + + " inner join " + DisposableGoodsBatchStock.class.getSimpleName() + " dgbs on dgi.disposableGoodsBatchStockID=dgbs.id" + + " where " + + getHandleDeptCodeSql("pr.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + +" and "+packingDisposableGoodsTypeSql + + packingDisposableGoodsTimeSql + + packingDisposableGoodsDepartSql + + prDepartCodingSql + + excludeDiposableGoodsItemSql + + packingDisposableGoodsNameSql +// + expensiveDisposablegoodsSql + + " group by pr.depart"+ groupByPrPackTimeOfShowTime + unitDGIGroupBySqlOfDiposableGoodsItem +",pr.orgUnitName,dgi.name,dgi.batch,dgbs.expDate "+ dgbsOfSupplierNameSql +") "; + } + } + + String materialInvoiceSql = " "; + String materialReturnSql = " "; + String lostMaterial = " "; + String damageMaterial = " "; + //当批次号为空时、且物品类型为空或器械材料或高值耗材时,才查询材料的发货、退货、丢失报损补充等数据 + if(StringUtils.isBlank(batch)){ + if ((StringUtils.isBlank(typeSearch) || typeSearch.contains("器械材料") || typeSearch.contains("高值耗材"))) { + // 材料发货 + materialInvoiceSql = " union all (select "+ noMaterialAmountSql +"i.depart,i.settleAccountsDepart "+ iSendTimeSqlOfShowTime + iSendTime +noQuerySupplierName + noQueryIntegralSql +",case when td.name is null then ii.materialName else ii.materialName "+ concatSymbolInDb +"'('"+ concatSymbolInDb +" td.name "+ concatSymbolInDb +"')' end,sum(ii.amount),sum(ii.settlementPrice)," + +"sum(ii.settlementPrice) as settlementDiscountPrice,'材料' as type" + + unitDSqlOfMd + + ",'' as batchNumber,null as expDate,td.id as tousseDefinitionId " + + tdcTousseGroupNameSQL + + " from MaterialInvoiceItem ii" + + " left join TousseDefinition td on td.id= ii.tousseDefinitionId " + + tdLeftJoinTdcSQL + + " inner join MaterialInvoice i on i.id = ii.materialInvoice_id " + + " inner join materialDefinition d on ii.materialDefinitionId = d.id where " + + getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + + monthFilterSql + + departFilterSql + + iDepartCodingSql + + materialNameFilterSql + + materialTypeFilterSql + + " group by i.depart" + tdcTousseGroupNameSQL + groupByIsendTimeOfShowTime + groupByIsendTime + unitDSqlOfMd +",i.settleaccountsdepart,case when td.name is null then ii.materialName else ii.materialName "+ concatSymbolInDb +" '(' "+ concatSymbolInDb +" td.name "+ concatSymbolInDb +"')' end,td.id) "; + } + if(StringUtils.isBlank(typeSearch) || "全部".equals(typeSearch) || typeSearch.contains("器械材料")){ + // 材料退货 + materialReturnSql = " union all (select "+ noMaterialAmountSql +"rr.depart,rr.settleAccountsDepart " + rrReturnTimeSqlOfShowTime + noSendTime + noQuerySupplierName + noQueryIntegralSql +",ii.materialName,-sum(ii.amount),-sum(ii.settlementPrice)," + +"-sum(ii.settlementPrice) as settlementDiscountPrice,'材料' as type" + + unitDSqlOfMd + + ",'' as batchNumber,null as expDate,0 as tousseDefinitionId " + + nullTousseGroupNameSQL + + " from ReturnMaterialRecord rr,materialDefinition d," + + "ReturnMaterialItem ii where rr.id = ii.returnMaterialRecord_ID " + + " and ii.materialDefinitionId = d.id and " + + getHandleDeptCodeSql("rr.handleDepartCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + + returnGoodsTimeFilterSql + + returnGoodsDepartFilterSql + + rrDepartCodingSql + + materialNameFilterSql + + materialTypeFilterSql + + " group by rr.depart"+ groupByRrReturnTimeOfShowTime + unitDSqlOfMd +",rr.settleAccountsDepart,ii.materialName) "; + } + lostMaterial = " union all (select "+ noMaterialAmountSql +"i.depart, i.settleAccountsDepart " + iOperationTimeSqlOfShowTime + noSendTime +noQuerySupplierName + noQueryIntegralSql +",i.materialName,sum(i.additionalAmount),sum(i.additionalAmount * i.materialCost)," + +"sum(i.additionalAmount * i.materialCost) as settlementDiscountPrice,'材料' as type" + + unitMSqlOfMd + + ",'' as batchNumber,null as expDate,0 as tousseDefinitionId " + + nullTousseGroupNameSQL + + " from MaterialErrorDamageDetail i left join materialDefinition m on i.materialDefinitionId = m.id where 1=1 and i.errorType = '缺失' and i.type = '"+MaterialErrorDamageDetail.TYPE_ERROR+"' and i.materialName != '器械包标识牌' and i.additionalAmount > 0 and " + + getHandleDeptCodeSql("i.handleDepartCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + + lostMaterialFilterSql + + iDepartCodeSql + + "group by i.depart"+ groupByIOperationTimeOfShowTime + unitMSqlOfMd +",i.settleAccountsDepart,i.materialName ) "; + String banQuery = " and 1 = 0 "; + String damagedTousseAtCost = config.getDamagedTousseAtCost(); + /*if(StringUtils.isBlank(damagedTousseAtCost) || Constants.STR_YES.equals(damagedTousseAtCost)){ + banQuery = ""; + }*/ + if(Constants.STR_YES.equals(damagedTousseAtCost)){ + banQuery = ""; + } + damageMaterial = " union all (select "+ noMaterialAmountSql +"i.depart,i.settleAccountsDepart " + iOperationTimeSqlOfShowTime + noSendTime +noQuerySupplierName + noQueryIntegralSql +",i.materialName,sum(i.additionalAmount),sum(i.materialCost*i.additionalAmount)," + +"sum(i.materialCost*i.additionalAmount) as settlementDiscountPrice,'材料' as type" + + unitMSqlOfMd + + ",'' as batchNumber,null as expDate,0 as tousseDefinitionId " + + nullTousseGroupNameSQL + + "from MaterialErrorDamageDetail i left join materialDefinition m on i.materialDefinitionId = m.id where 1=1 " + + banQuery + + " and i.type = '" + MaterialErrorDamageDetail.TYPE_DAMAGE + "' and i.additionalAmount > 0 and " + + getHandleDeptCodeSql("i.handleDepartCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + + damageFilterSql + + iDepartCodeSql + + " group by i.depart" + + groupByIOperationTimeOfShowTime + + unitMSqlOfMd + + ",i.settleAccountsDepart,i.materialName ) "; + } + //退货(一次性物品、器械包) + String returnGoodsSql = null; + if(queryUrgent){ + returnGoodsSql = " union all (select " + + tousseInstanceMaterialAmountSql + +" rr.depart,rr.settleAccountsDepart as settleaccountsdepart " + + rrReturnTimeSqlOfShowTime + + noSendTime + + noQuerySupplierName + + noQueryIntegralSql + +",td.name," + + "-count(*) as amount,-sum(ti.price) as settlementprice,-sum(ti.discountPrice) as settlementDiscountPrice," + +" td.toussetype as type "; + if(queryUnit){ + returnGoodsSql += ",td.unit"; + } + returnGoodsSql += ",null as batchNumber,null expDate,td.id as tousseDefinitionId" + + tdcTousseGroupNameSQL + + " from " + + ReturnGoodsRecord.class.getSimpleName() + " rr inner join " + + ReturnGoodsItem.class.getSimpleName()+ " ri on rr.id = ri.returngoodsrecord_id " + + "join " + + TousseInstance.class.getSimpleName() + +" ti on ti.returnGoodsItem_ID=ri.id " + + " join " + TousseDefinition.class.getSimpleName() + + " td on td.id=ti.tousseDefinition_id" + + tdLeftJoinTdcSQL + + " where " + + getHandleDeptCodeSql("rr.handleDepartCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + + returnGoodsFilterSql + + urgentSql + + rrSettleAccountsDepartCodingSql + +" and "+returnGoodsItemPredicate + + " group by rr.depart" + + tdcTousseGroupNameSQL; + if(queryUnit){ + returnGoodsSql += ",ri.disposableGoodsID,td.unit "; + } + returnGoodsSql += groupByRrReturnTimeOfShowTime + ",rr.settleAccountsDepart,td.name,td.tousseType,td.id) "; + }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," + +returnGoodsTousseType+" as type"; + if(queryUnit){ + returnGoodsSql += ",case when ri.disposableGoodsID is not null THEN (select unit from DisposableGoods where id=ri.disposableGoodsID) else td.unit end unit"; + } + returnGoodsSql += ",ri.batchNumber as batchNumber,dgbs.expDate,"+returnGoodsTousseDefinitionId+" as tousseDefinitionId" + + tdcTousseGroupNameSQL + + " 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" + + tdLeftJoinTdcSQL + + " left join " + DisposableGoodsBatchStock.class.getSimpleName() + " dgbs on ri.disposableGoodsBatchStockID=dgbs.id" + + " where " + + getHandleDeptCodeSql("rr.handleDepartCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + + returnGoodsFilterSql + + rrSettleAccountsDepartCodingSql + +" and "+returnGoodsItemPredicate + + " group by rr.depart" + + tdcTousseGroupNameSQL; + if(queryUnit){ + returnGoodsSql += ",ri.disposableGoodsID,td.unit "; + } + returnGoodsSql += groupByRrReturnTimeOfShowTime + ",rr.settleAccountsDepart,ri.toussename," +returnGoodsTousseType+",ri.batchNumber"+ groupByMaterialAmountAtThatTime +",dgbs.expDate,"+returnGoodsTousseDefinitionId+ dgbsOfSupplierNameSql +") "; + } + + String supplyRoomTousseTypeSql = ""; + /*if(!(StringUtils.isBlank(typeSearch) || typeSearch.contains("一次性物品"))){ + if(typeSearch.contains(TYPE_AUTO_DEDUCTION)){ + supplyRoomTousseTypeSql = String.format(" and rr.type='%s' ", InvoiceItem.TYPE_AUTO_DEDUCTION); + } + }*/ + String supplyRoomDiposableGoodsSql = " union all (select "+ sumRriAmountSql +" rr.depart,rr.depart as settleaccountsdepart "+rrTimeSqlOfShowTime + noSendTime + dgbsOfSupplierNameSql + noQueryIntegralSql +",rri.goodsName,sum(rri.amount)," + +"sum(rri.price*rri.amount) as settlementprice,sum(rri.price*rri.amount) as settlementDiscountPrice,rri.type as type" + + unitDSqlOfMd + + ",dgbs.batchNumber as batchNumber,dgbs.expDate,0 as tousseDefinitionId " + + nullTousseGroupNameSQL + +" from ReceiveRecord rr,ReceiveRecordItem rri left join " + DisposableGoodsBatchStock.class.getSimpleName() + " dgbs " + +" on rri.diposableGoodBatchStock_id = dgbs.id left join DisposableGoods d on d.id = rri.disposableGoodsId where rr.id = rri.receiveRecord_id and " + + getHandleDeptCodeSql("rr.departCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + +supplyRoomDiposableGoodsFilterSqlOFDgbs + +supplyRoomTousseTypeSql + +" and "+receiveRecordItemPredicate + + rrDepartCodingSql + + supplyRoomDiposableGoodsFilterSql + + " group by rr.depart" + + groupByRrTimeOfShowTime + + unitDSqlOfMd + + ",rri.goodsName,rri.amount,rri.type,dgbs.batchNumber,dgbs.expDate "+ unitDSqlOfMd + dgbsOfSupplierNameSql +") "; + // 调拨出库 + String appropriateOutDiposableGoodsSql = " union all (select "+ noMaterialAmountSql +" oge.targetOrgUnitName depart ,oge.targetOrgUnitName as settleaccountsdepart" + ogeTimeSqlOfShowTime + noSendTime +dgbsOfSupplierNameSql+noQueryIntegralSql+",ged.goodsName,sum(ged.amount)," + +"sum(ged.price*ged.amount) as settlementprice,sum(ged.price*ged.amount) as settlementDiscountPrice,'一次性物品' as type" + +unitDGSqlOfDisposableGoods + + ",dgbs.batchNumber as batchNumber,dgbs.expDate,0 as tousseDefinitionId " + + nullTousseGroupNameSQL + +" from GodownEntry oge inner join GodownEntryDiposableGoodsItem ged on oge.id = ged.godownEntryID inner join DisposableGoodsBatch dgbs on ged.disposableGoodsBatchID=dgbs.id inner join DisposableGoods dg on dgbs.diposablegoods_id = dg.id " + +" where oge.type ='退库单' and oge.subType='调拨出库' and " + + getHandleDeptCodeSql("oge.orgUnitCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + +outEntryFilterSql + + ogeTargetOrgUnitCodeSql + +" and "+outEntryPredicate + + " group by oge.targetOrgUnitName, ged.goodsName,dgbs.batchNumber,dgbs.expDate "+ groupByOgeTimeOfShowTime + unitDGSqlOfDisposableGoods + dgbsOfSupplierNameSql +") "; + // 盘亏出库 + String stocktakeOutDiposableGoodsSql = " union all (select "+ noMaterialAmountSql +" oge.orgUnitName depart, oge.orgUnitName" +dgbsOfSupplierNameSql+" as settleaccountsdepart"+ ogeTimeSqlOfShowTime + noSendTime + noQueryIntegralSql +",ged.goodsName,sum(ged.amount)," + +"sum(ged.price*ged.amount) as settlementprice,sum(ged.price*ged.amount) as settlementDiscountPrice,'一次性物品' as type" + +unitDGSqlOfDisposableGoods + + ",dgbs.batchNumber as batchNumber,dgbs.expDate,0 as tousseDefinitionId " + + nullTousseGroupNameSQL + +" from GodownEntry oge inner join GodownEntryDiposableGoodsItem ged on oge.id = ged.godownEntryID inner join DisposableGoodsBatch dgbs on ged.disposableGoodsBatchID=dgbs.id inner join DisposableGoods dg on dgbs.diposablegoods_id = dg.id " + +" where oge.type ='退库单' and oge.subType='盘亏出库' and " + + getHandleDeptCodeSql("oge.orgUnitCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + +outEntryFilterSql + + ogeOrgUnitCodeSql + +" and "+outEntryPredicate + + " group by oge.orgUnitName, ged.goodsName,dgbs.batchNumber,dgbs.expDate" + groupByOgeTimeOfShowTime + unitDGSqlOfDisposableGoods + dgbsOfSupplierNameSql+") "; + + + String sql = tousseSql + selectExpensiveGoodsSql + diposableGoodsSql + supplyRoomDiposableGoodsSql ; + + if(!TYPE_AUTO_DEDUCTION.equals(typeSearch)){ + sql += materialInvoiceSql; + sql += returnGoodsSql; + sql += materialReturnSql; + sql += appropriateOutDiposableGoodsSql; + sql += stocktakeOutDiposableGoodsSql; + sql += packingDisposableGoodsSql; +// sql += materialInvoiceSql; +// sql += materialInvoiceSql; + } + + if (StringUtils.isBlank(typeSearch) || typeSearch.contains("器械包") || typeSearch.contains("器械材料") || typeSearch.contains("全部") || StringUtils.isBlank(typeSearch) || typeSearch.contains("全部器械包") || typeSearch.contains("高值耗材")) { + sql += lostMaterial; + sql += damageMaterial; + } + String chargeDateSql = "";//收费项目时间过滤 + if(!queryUrgent && (StringUtils.isBlank(typeSearch) || typeSearch.contains(TYPE_CHARGE) || typeSearch.contains(TYPE_ALL))){ + if(StringUtils.isNotBlank(startTime) && StringUtils.isNotBlank(endTime)){ + chargeDateSql = String.format(" and chargeTime %s ", betweenSql); + } + if(CollectionUtils.isNotEmpty(departCodingSet)){ + chargeDepartSql = String.format(" and %s ", SqlUtils.getStringFieldInLargeCollectionsPredicate("ci.orgUnitCode", departCodingSet)); + } + } + if(!queryUrgent && StringUtils.isNotBlank(typeSearch) && typeSearch.contains(TYPE_CHARGE)){ + String chargeSql = String.format(" union all select "+ noMaterialAmountSql +"ci.orgUnitName depart, ci.orgUnitName settleAccountsDepart" + crChargeTimeSqlOfShowTime + noSendTime + noQuerySupplierName + noQueryIntegralSql +",chargeItem name,1 amount,price settlementprice,0 settlementDiscountPrice,'收费项目' type "+ noQueryUnitSql +",'' batchNumber,NULL as expDate ,null as tousseDefinitionId " + + nullTousseGroupNameSQL + + " from ChargeRecordItem ci inner join ChargeRecord cr on cr.id=ci.chargeRecord_id where 1=1 %s %s %s %s group by ci.orgUnitName,chargeItem,price,chargeTime " + + groupByCrChargeTimeOfShowTime + , chargeDepartSql,chargeDateSql,chargeItemSql, + ciOrgUnitCodeSql); + sql += chargeSql; + }else if(!queryUrgent && StringUtils.isBlank(typeSearch)){ + sql += String.format(" union all select "+ noMaterialAmountSql +"ci.orgUnitName depart,ci.orgUnitName settleAccountsDepart" + crChargeTimeSqlOfShowTime + noSendTime + noQuerySupplierName + noQueryIntegralSql +",chargeItem name,1 amount,price settlementprice,0 settlementDiscountPrice,'收费项目' type "+ noQueryUnitSql +",'' batchNumber,NULL as expDate ,null as tousseDefinitionId " + + nullTousseGroupNameSQL + + " from ChargeRecordItem ci inner join ChargeRecord cr on cr.id=ci.chargeRecord_id where 1=1 %s %s %s %s group by ci.orgUnitName,chargeItem,price,chargeTime " + + groupByCrChargeTimeOfShowTime + , chargeDepartSql,chargeDateSql,chargeItemSql, + ciOrgUnitCodeSql); + } + if(queryUrgent){ + sql = tousseSql + returnGoodsSql; + } + if (dbConnection.isSqlServer()) { + String orderSql = null; + if(showSendTime){ + orderSql = " order by sendTime desc,settleaccountsdepart,type"; + }else if(showTime){ + orderSql = " order by showTime desc,settleaccountsdepart,type"; + }else{ + orderSql = " order by settleaccountsdepart,type"; + } + sql += orderSql; + } + + logger.debug("明细核算月报执行sql:" + sql); + + Map> detailMap = new HashMap>(); + Map manufacturerMap = getDiposableGoodsManufacturer(); + + Map disposableGoodsExternalCodeMap = disposableGoodsExternalCodeMap(); + Map expensiveExternalCode = expensiveExternalCode(); + Map materialExternalCodeMap = getMaterialExternalCode(); + Map tousseExternalCodeMap = getTousseExternalCode(); + ResultSet rs = null; + + try { + rs = objectDao.executeSql(sql); + Set toussedefinitionIdSet = new HashSet();//需要查询材料实例数量的包定义id + Map itemAndTDid = new HashMap();//,用于给DepartmentMonthDetailItem计算price和totalAmount + while (rs.next()) { + String settleaccountsdepart = rs.getString("settleaccountsdepart"); + if(StringUtils.isBlank(settleaccountsdepart)){ + settleaccountsdepart = ""; + } + String depart = rs.getString("depart"); + if(StringUtils.isBlank(depart)){ + depart = ""; + } + String departKey = settleaccountsdepart + ";_;" + depart; + List itemList = detailMap.get(departKey); + if (itemList == null) { + itemList = new ArrayList(); + detailMap.put(departKey, itemList); + } + String goodsName = rs.getString("name"); + String type = rs.getString("type"); + double settlementPrice = rs.getDouble("settlementprice"); + double settlementDiscountPrice = rs.getDouble("settlementDiscountPrice"); + int amount = rs.getInt("amount"); + Date expDate = null; + if(!TYPE_CHARGE.equals(type)){ + try { + expDate = rs.getTimestamp("expDate"); + } catch (Exception e) { + } + + } + int totalAmount = amount; + DepartmentMonthDetailItem mdi = new DepartmentMonthDetailItem(); + if(queryTousseGroupName){ + mdi.setTousseGroupName(rs.getString("tousseGroupName")); + } + boolean flag = true; + if (TousseDefinition.PACKAGE_TYPE_DISINFECTION.equals(type) + || (TousseDefinition.PACKAGE_TYPE_CUSTOM.equals(type) && !showCustonTousseAmount)) { + Long toussedefinitionId = rs.getLong("tousseDefinitionId"); + if (DatabaseUtil.isPoIdValid(toussedefinitionId)) { + toussedefinitionIdSet.add(toussedefinitionId);//记下id,一次性查询对应的材料实例数量 + mdi.setAmount(totalAmount); + itemAndTDid.put(mdi, toussedefinitionId); + flag = false;//先不计算价格和总数量,批量查询时再计算 + } + } + if(flag){ + Double price = 0D; + if(totalAmount != 0){ + price = MathTools.divide(settlementPrice, totalAmount, 4); + } + mdi.setPrice(price); + mdi.setAmount(totalAmount); + } + if(showSupplierNameInDetailedAccountingMonthlyReport){ + if(TousseDefinition.PACKAGE_TYPE_FOREIGN.equals(type) || TousseDefinition.PACKAGE_TYPE_SPLIT.equals(type) + || DisposableGoods.TYPE_NAME.equals(type)){ + String supplierName = rs.getString("supplierName"); + mdi.setSupplierName(supplierName); + } + } + if(showSendTime){ + mdi.setSendTime(rs.getString("sendTime")); + } + if(showTime){ + mdi.setShowTime(rs.getString("showTime")); + } + mdi.setType(type); + mdi.setSettlementPrice(settlementPrice); + mdi.setSettlementDiscountPrice(settlementDiscountPrice); + mdi.setBatchNumber(rs.getString("batchNumber")); + if(queryUnit){ + mdi.setUnit(rs.getString("unit")); + } + mdi.setExpDate(ForgonDateUtils.safelyFormatDate(expDate, Constants.SIMPLEDATEFORMAT_YYYYMMDD, "")); + if ("一次性物品".equals(type)) { + mdi.setManufacturer(manufacturerMap.get(goodsName + "_" + mdi.getBatchNumber())); + mdi.setExternalCode(disposableGoodsExternalCodeMap.get(goodsName)); + }else if("材料".equals(type)){ + mdi.setExternalCode(materialExternalCodeMap.get(goodsName)); + }else{ + if(enableExpensiveGoods && ExpensiveGoods.TYPE_NAME.equals(type)){ + //新的高值耗材设置外部编码及生产厂家 + mdi.setExternalCode(expensiveExternalCode.get(goodsName)); + }else{ + mdi.setExternalCode(tousseExternalCodeMap.get(goodsName)); + } + } + if(queryUnit && DisposableGoods.TYPE_NAME.equals(type)){ + int beginIndex = goodsName.indexOf("["); + int endIndex = goodsName.lastIndexOf("]"); + if(beginIndex != -1 && endIndex != -1){ + String specification = goodsName.substring(beginIndex + 1, endIndex); + goodsName = goodsName.substring(0, beginIndex); + mdi.setSpecification(specification); + } + } + mdi.setGoodsName(goodsName); + if(showMaterialsAmountColumnOfDetailMonthReport){ + if("一次性物品".equals(type) || "材料".equals(type) || ExpensiveGoods.TYPE_NAME.equals(type) || "收费项目".equals(type) || "高值耗材".equals(type)){ + mdi.setMaterialAmount(totalAmount); + }else{ + mdi.setMaterialAmount(ConvertNumber.getNumberIntValue(rs.getObject("materialAmount"), 0)); + } + } + if(enableToussePointsStatistics){ + Number integralNum = (Number)rs.getObject("integral"); + if(integralNum != null){ + mdi.setIntegral(integralNum.doubleValue() * totalAmount); + } + } + itemList.add(mdi); + } + //统一计算要查询包定义对应的材料实例数量的DepartmentMonthDetailItem的price和totalAmount + calcPriceAndAmout(toussedefinitionIdSet, itemAndTDid); + } catch (SQLException e) { + logger.error("获取明细核算月报数据时出错", e); + }finally { + DatabaseUtil.closeResultSetAndStatement(rs); + } + for(Entry> entry : detailMap.entrySet()){ + String departKey = entry.getKey(); + List list = entry.getValue(); + //消毒物品,自定义器械包,外来器械包,外来器械拆分小包相同名称的合并 + Map tmpMap = new HashMap(); + List removeItems = new ArrayList(); + double totalPrice = 0.0d; + double totalPriceDiscount = 0.0d; + Map disposableGoodsTempMap = new HashMap(); + for (DepartmentMonthDetailItem dmi : list) { + String tousseName = dmi.getGoodsName(); + String sendTime = dmi.getSendTime(); + String dmiShowTime = dmi.getShowTime(); + String key = null; + if(showTime){ + key = dmiShowTime + tousseName; + }else if(showSendTime){ + key = sendTime + tousseName; + } else{ + key = tousseName; + } + 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)) { + DepartmentMonthDetailItem item = tmpMap.get(key); + if(item == null){ + item = new DepartmentMonthDetailItem(); + item.setAmount(0); + item.setPrice(0d); + item.setSettlementPrice(0d); + item.setSettlementDiscountPrice(0d); + item.setMaterialAmount(0); + item.setSendTime(sendTime); + item.setExternalCode(tousseExternalCodeMap.get(tousseName)); + if(showTime){ + item.setShowTime(dmiShowTime); + } + if(queryTousseGroupName){ + item.setTousseGroupName(dmi.getTousseGroupName()); + } + tmpMap.put(key, item); + } + if(dmi.getMaterialAmount() != null){ + item.setMaterialAmount(MathTools.add(item.getMaterialAmount(), dmi.getMaterialAmount()).intValue()); + } + item.setIntegral(MathTools.add(item.getIntegral(), dmi.getIntegral()).doubleValue()); + item.setAmount(item.getAmount()+dmi.getAmount()); + item.setBatchNumber(dmi.getBatchNumber()); + item.setDiposable(dmi.getDiposable()); + item.setExpDate(dmi.getExpDate()); + item.setGoodsName(tousseName); + item.setManufacturer(dmi.getManufacturer()); + item.setSettlementPrice(item.getSettlementPrice() + dmi.getSettlementPrice()); + 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(); + item.setPrice(price); + removeItems.add(dmi); + }else if(!showBatch && DisposableGoods.TYPE_NAME.equals(type)){//一次性物品 + DepartmentMonthDetailItem item = null; + if(disposableGoodsTempMap.containsKey(key)){ + item = disposableGoodsTempMap.get(key); + item.setAmount(item.getAmount()+dmi.getAmount()); + item.setDiposable(dmi.getDiposable()); + item.setGoodsName(tousseName); + if(dmi.getMaterialAmount() != null){ + item.setMaterialAmount(MathTools.add(item.getMaterialAmount(), dmi.getMaterialAmount()).intValue()); + } + item.setManufacturer(dmi.getManufacturer()); + item.setSettlementPrice(item.getSettlementPrice() + dmi.getSettlementPrice()); + 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(); + item.setPrice(price); + removeItems.add(dmi); + }else{ + dmi.setBatchNumber(null); + dmi.setExpDate(null); + dmi.setSendTime(sendTime); + disposableGoodsTempMap.put(key, dmi); + } + } + totalPrice += dmi.getSettlementPrice(); + totalPriceDiscount += dmi.getSettlementDiscountPrice(); + } + list.removeAll(removeItems); + if(tmpMap.size() > 0){ + list.addAll(tmpMap.values()); + } + + if(disposableGoodsTempMap.size() > 0){ + list.addAll(disposableGoodsTempMap.values()); + } + DepartmentMonthDetail detail = new DepartmentMonthDetail(); + String[] departs = departKey.split(";_;"); + for (int i = 0; i < departs.length; i++) { + if(i == 0){ + detail.setDepart(departs[0]); + }else if(i == 1){ + detail.setApplicationDepart(departs[1]); + } + } + detail.setTotalPrice(totalPrice); + detail.setTotalPriceDiscount(totalPriceDiscount); + detail.setItems(list); + sortDetailItems(detail); + datas.add(detail); + } + orderDepartmentMonthDetailList(datas,showSendTime);//数据库里排序无效 + return datas; + } + /** + * 对DepartmentMonthDetailList进行排序(按科室供应室配置的科室申领的顺序科室排序) + * @param list + * @param showSendTime 显示发货 按发货排序 + */ + private void orderDepartmentMonthDetailList(List list , boolean showSendTime){ + Map map = supplyRoomConfigManager.getOrgUnitAndSequenceMap(3); + Collections.sort(list, new Comparator() { + @Override + public int compare(DepartmentMonthDetail o1, DepartmentMonthDetail o2) { + int o1sequence = 99999; + if(map.containsKey(o1.getApplicationDepart())){ + o1sequence = map.get(o1.getApplicationDepart()); + } + int o2sequence = 99999; + if(map.containsKey(o2.getApplicationDepart())){ + o2sequence = map.get(o2.getApplicationDepart()); + } + return o1sequence - o2sequence; + } + }); + for (DepartmentMonthDetail departmentMonthDetail : list) { + List items = departmentMonthDetail.getItems(); + Collections.sort(items, new Comparator() { + @Override + 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; + } + } + } + } + }); + } + } + /** + * 将字段去掉前缀返回 + * @param str 要去前缀的字符 + * @return s.name 返回name;s.name name1 返回 name1; ,td.name 返回,name + */ + private String getRemovePrefixSql(String str){ + if(StringUtils.isBlank(str)){ + return ""; + } + str = str.trim(); + String prefix = null; + if(str.startsWith(",")){ + prefix = ","; + }else{ + prefix = ""; + } + if(str.contains(" ")){ + return prefix + str.substring(str.indexOf(" ")); + }else if(str.contains(".")){ + return prefix + str.substring(str.indexOf(".") + 1); + } + return str; + } + /** + * 明细核算月报和核算月报用的过滤供应室的语句 + * @param field 过滤的字段 + * @param isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser 登录用户是否供应室用户 或者 是否是高值耗材处理科室用户 是才过滤供应室 + * @param orgUnitCoding 登录用户所属供应室编码 + * @return + */ + private String getHandleDeptCodeSql(String field, boolean isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, String orgUnitCoding){ + String handleDeptCodeSql = null; + if (isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser) { + handleDeptCodeSql = String.format(" %s='%s' ", field, orgUnitCoding); + } else { + handleDeptCodeSql = " 1=1 "; + } + return handleDeptCodeSql; + } + public Map getDiposableGoodsManufacturer(){ + String sql = "select dg.name,dg.specification,db.batchNumber,db.manufacturer " + + "from " + DisposableGoodsStock.class.getSimpleName() + " dg," + DisposableGoodsBatchStock.class.getSimpleName() + " db where dg.id = db.diposablegoods_id"; + ResultSet rs = objectDao.executeSql(sql); + Map map = new HashMap(); + try { + while(rs.next()){ + String name = rs.getString(1); + String sp = rs.getString(2); + String batch = rs.getString(3); + String manufacturer = rs.getString(4); + String key = name; + if(StringUtils.isNotBlank(sp)){ + key += "[" + sp + "]"; + } + key += "_" + batch; + map.put(key, manufacturer); + + } + } catch (SQLException e) { + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(rs); + } + return map; + } + private Map disposableGoodsExternalCodeMap(){ + String sql = "select name,specification,externalCode from DisposableGoods where externalCode is not null"; + ResultSet rs = objectDao.executeSql(sql); + Map map = new HashMap(); + try { + while(rs.next()){ + String name = rs.getString(1); + String sp = rs.getString(2); + String externalCode = rs.getString(3); + String key = name; + if(StringUtils.isNotBlank(sp)){ + key += "[" + sp + "]"; + } + map.put(key, externalCode); + + } + } catch (SQLException e) { + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(rs); + } + return map; + } + /** + * 获取新的高值耗材的生产厂家和外部编码 + * @param expensiveManufacture 生产厂家的map,输出参数 + * @param expensiveExternalCode 外部编码的map,输出参数 + */ + private Map expensiveExternalCode() { + String sql = "select eg.externalCode,eg.name,eg.specification from " + + ExpensiveGoods.class.getSimpleName() + " eg "; + ResultSet rs = objectDao.executeSql(sql); + Map expensiveExternalCode = new HashMap<>(); + try { + while(rs.next()){ + String name = rs.getString("name"); + String sp = rs.getString("specification"); + String externalCode = rs.getString("externalCode"); + String key = name; + if(StringUtils.isNotBlank(sp)){ + key += "[" + sp + "]"; + } + expensiveExternalCode.put(key, externalCode); + } + } catch (SQLException e) { + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(rs); + } + return expensiveExternalCode; + } + private Map getMaterialExternalCode(){ + String sql = "select name,specification,externalCode from MaterialDefinition where externalCode is not null"; + ResultSet rs = objectDao.executeSql(sql); + Map map = new HashMap(); + try { + while(rs.next()){ + String name = rs.getString(1); + String sp = rs.getString(2); + String externalCode = rs.getString(3); + String key = name; + if(StringUtils.isNotBlank(sp)){ + key += "[" + sp + "]"; + } + map.put(key, externalCode); + + } + } catch (SQLException e) { + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(rs); + } + return map; + } + private Map getTousseExternalCode(){ + String sql = "select name,externalCode from TousseDefinition where externalCode is not null"; + ResultSet rs = objectDao.executeSql(sql); + Map map = new HashMap(); + try { + while(rs.next()){ + String name = rs.getString(1); + String externalCode = rs.getString(2); + map.put(name, externalCode); + } + } catch (SQLException e) { + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(rs); + } + return map; + } + /** + * 统一计算要查询包定义对应的材料实例数量的DepartmentMonthDetailItem的price和totalAmount + * @param toussedefinitionIdSet 需要查询材料实例数量的包定义id + * @param itemAndTDid ,用于给DepartmentMonthDetailItem计算price和totalAmount + */ + private void calcPriceAndAmout(Set toussedefinitionIdSet, Map itemAndTDid){ + if(toussedefinitionIdSet.size() > 0){ + Map tdIdAndAmountMap = getDisinfectGoodsStatisticAmount(toussedefinitionIdSet); + for (Entry entry : itemAndTDid.entrySet()) { + Long tdId = entry.getValue(); + DepartmentMonthDetailItem item = entry.getKey(); + Integer totalAmount = 0; + if(tdIdAndAmountMap.containsKey(tdId)){ + Integer amount = tdIdAndAmountMap.get(tdId); + if(amount.intValue() != 1 && amount > 0){ + totalAmount = item.getAmount() * amount; + item.setAmount(totalAmount); + } + } + Double price = 0D; + if(totalAmount != 0){ + price = MathTools.divide(item.getSettlementPrice(), totalAmount, 4); + } + item.setPrice(price); + } + } + } + /** + * 获取消毒物品材料数量,没有申请单的可能是自定义装配生成的 + * @param toussedefinitionIdSet 包定义id + * @return 自定义器械包或者是拆包的消毒物品,返回材料数量,其他情况都返回0 + */ + private Map getDisinfectGoodsStatisticAmount(Set toussedefinitionIdSet) { + Map tdIdAndAmountMap = new HashMap(); + if(CollectionUtils.isEmpty(toussedefinitionIdSet)){ + return tdIdAndAmountMap; + } + ResultSet rs = null; + try { + String sql = "select sum(i.count) count,t.id from Toussedefinition t,MaterialInstance i " + + "where t.id = i.tousse_id and " + SqlUtils.getNonStringFieldInLargeCollectionsPredicate("t.id", toussedefinitionIdSet) + + " and ((t.isApplyEntireTousse='" + Constants.STR_NO +"' and t.tousseType='" + + TousseDefinition.PACKAGE_TYPE_DISINFECTION+"') or t.tousseType='"+TousseDefinition.PACKAGE_TYPE_CUSTOM+"') group by t.id"; + rs = objectDao.executeSql(sql); + while(rs.next()){ + Long id = rs.getLong("id"); + Integer count = rs.getInt("count"); + tdIdAndAmountMap.put(id, count); + } + } catch (SQLException e) { + e.printStackTrace(); + } finally { + DatabaseUtil.closeResultSetAndStatement(rs); + } + return tdIdAndAmountMap; + } + // 对科室中的物品明细按类型和名称排序,先按类型排序,然后按名称,器械包排在一起,一次性物品排在一起 + // 按type是否为“一次性物品”分组,因为有部分InvoiceItem的tousseType属性为空 + private void sortDetailItems(DepartmentMonthDetail detail) { + + List items = detail.getItems(); + Collections.sort(items, + new Comparator() { + @Override + public int compare(DepartmentMonthDetailItem o1, + DepartmentMonthDetailItem o2) { + + if ("一次性物品".equals(o1.getType())){ + o1.setDiposable("是"); + } + else{ + o1.setDiposable("否"); + } + if ("一次性物品".equals(o2.getType())){ + o2.setDiposable("是"); + } + else{ + o2.setDiposable("否"); + } + int compareType = o1.getTypeOrder() - o2.getTypeOrder(); + if(compareType == 0){ + int compareName = ObjectUtils.compare(o1.getGoodsName(), o2.getGoodsName()); + return compareName; + } +// int value1 = ObjectUtils.compare(o1.getDiposable(), o2.getDiposable()); +// if (value1 == 0) { +// int value2 = ObjectUtils.compare(o1.getGoodsName(), o2.getGoodsName()); +// return value2; +// } + return compareType; + } + }); + } +} Index: ssts-web/src/main/webapp/WEB-INF/spring/applicationContext-service.xml =================================================================== diff -u -r35788 -r35792 --- ssts-web/src/main/webapp/WEB-INF/spring/applicationContext-service.xml (.../applicationContext-service.xml) (revision 35788) +++ ssts-web/src/main/webapp/WEB-INF/spring/applicationContext-service.xml (.../applicationContext-service.xml) (revision 35792) @@ -776,8 +776,12 @@ - + + + + + \ No newline at end of file Index: ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/service/JasperReportManagerImpl.java =================================================================== diff -u -r35788 -r35792 --- ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/service/JasperReportManagerImpl.java (.../JasperReportManagerImpl.java) (revision 35788) +++ ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/service/JasperReportManagerImpl.java (.../JasperReportManagerImpl.java) (revision 35792) @@ -174,8 +174,12 @@ import com.forgon.disinfectsystem.jasperreports.javabeansource.*; import com.forgon.disinfectsystem.jasperreports.service.dataindex.DataIndex; import com.forgon.disinfectsystem.jasperreports.service.dataindex.WorkQualityCollectionDataIndex; +import com.forgon.disinfectsystem.jasperreports.util.DepartmentMonthDetailHelper; import com.forgon.disinfectsystem.jasperreports.util.ForeignTousseApplicationReportHelper; import com.forgon.disinfectsystem.jasperreports.util.InstrumentRepairReportHelper; +import com.forgon.disinfectsystem.jasperreports.util.MonthReportGroupByDisposableGoodsTypeHelper; +import com.forgon.disinfectsystem.jasperreports.util.MonthReportGroupBySterilizationModeHelper; +import com.forgon.disinfectsystem.jasperreports.util.MonthReportHelper; import com.forgon.disinfectsystem.jasperreports.util.TousseWorkLoadDataForDLZXYYHelper; import com.forgon.disinfectsystem.packing.service.PackingManager; import com.forgon.disinfectsystem.qualitymonitoring.definition.service.QualityMonitoringDefinitionManager; @@ -297,6 +301,14 @@ private ForeignTousseApplicationReportHelper foreignTousseApplicationReportHelper; @Autowired private TousseWorkLoadDataForDLZXYYHelper tousseWorkLoadDataForDLZXYYHelper; + @Autowired + private DepartmentMonthDetailHelper departmentMonthDetailHelper; + @Autowired + private MonthReportHelper monthReportHelper; + @Autowired + private MonthReportGroupByDisposableGoodsTypeHelper monthReportGroupByDisposableGoodsTypeHelper; + @Autowired + private MonthReportGroupBySterilizationModeHelper monthReportGroupBySterilizationModeHelper; public void setPackingManager(PackingManager packingManager) { this.packingManager = packingManager; } @@ -3433,2671 +3445,25 @@ return handleDeptCodeSql; } /** - * 根据页面传递的物品类型,获取对应的器械包类型 - * @param tousseType 页面传递的物品类型,如果为空,则跟全部器械包一样,返回所有器械包类型的集合 - * @return - */ - private List getTousseTypes(String tousseType){ - List allType = new LinkedList(); - boolean enableExpensiveGoods = CssdUtils.getSystemSetConfigByNameBool("enableExpensiveGoods"); - if("全部器械包".equals(tousseType) || StringTools.isBlank(tousseType)){ - allType.add(TousseDefinition.PACKAGE_TYPE_CUSTOM); - allType.add(TousseDefinition.PACKAGE_TYPE_DISINFECTION); - allType.add(TousseDefinition.PACKAGE_TYPE_DRESSING); - allType.add(TousseDefinition.PACKAGE_TYPE_FOREIGN); - allType.add(TousseDefinition.PACKAGE_TYPE_FOREIGNPROXY); - allType.add(TousseDefinition.PACKAGE_TYPE_INSIDE); - allType.add(TousseDefinition.PACKAGE_TYPE_SPLIT); - allType.add(TousseDefinition.PACKAGE_TYPE_COMBO); - if(StringTools.isBlank(tousseType) && enableExpensiveGoods){ - allType.add(ExpensiveGoods.TYPE_NAME); - } - }else if("外来器械包".equals(tousseType)){ - allType.add(TousseDefinition.PACKAGE_TYPE_FOREIGN); - allType.add(TousseDefinition.PACKAGE_TYPE_SPLIT); - }else if("外部代理灭菌包".equals(tousseType)){ - allType.add(TousseDefinition.PACKAGE_TYPE_FOREIGNPROXY); - }else if(StringTools.isNotBlank(tousseType)){ - if(ExpensiveGoods.TYPE_NAME.equals(tousseType)){ - if(enableExpensiveGoods){ - allType.add(tousseType); - } - }else{ - allType.add(tousseType); - } - } - return allType; - } - /** * 核算月报查询 */ @Override public List getMonthReportData(String startDate,String endDate, String department,String tousseType,String disposableGoodsType,Boolean showCustonTousseAmount, String patternOfReport, Map departToBrancheOfHospitalMap, boolean filterBrancheOfHospital, boolean hideAmountColumn, boolean showApplicationDepart, String invoicePlanDepartCoding, Map columnConfigOfAccountingInfoMap, boolean queryWhetherToCharge){ -// String handleDeptCode = AcegiHelper.getLoginUser().getOrgUnitCodingFromSupplyRoomConfig(); - Set departments = null; - if(filterBrancheOfHospital && !(departToBrancheOfHospitalMap == null || departToBrancheOfHospitalMap.isEmpty())){ - departments = departToBrancheOfHospitalMap.keySet(); - } - Map nameToBrevityCodeMap = new HashMap(); - if("dgshlyyMode".equals(patternOfReport)){ - String querySql = "select name,brevityCode from "+ OrgUnit.class.getSimpleName() +" where 1=1 " + SqlUtils.getIsNotNullSql(dbConnection, "brevityCode") + " order by status asc "; - nameToBrevityCodeMap = objectDao.getKeyAndValueAreBothStringMap(querySql); - } - //启用排除属于科研项目的一次性物品申请单的发货数据 - boolean excludeSciProjectInfo = CssdUtils.getSystemSetConfigByNameBool("enableExcludeInvoiceItemOfDisposableGoodsApplicationBelongToSciProject", false); - //核算月报中单独显示属于科研项目的一次性物品申请单发货的总金额 - boolean showTotalMoneyOfSciProjectDisposableGoodsInvoiceInAccountingMonthlyReport = CssdUtils.getSystemSetConfigByNameBool("showTotalMoneyOfSciProjectDisposableGoodsInvoiceInAccountingMonthlyReport", false); - String insideAmountShowName = null;//器械包数量显示名 - if(columnConfigOfAccountingInfoMap.containsKey("器械包数量")){ - insideAmountShowName = columnConfigOfAccountingInfoMap.get("器械包数量"); - }else{ - insideAmountShowName = "器械包数量"; - } - String disposableAmountShowName = null;//一次性物品数量显示名 - if(columnConfigOfAccountingInfoMap.containsKey("一次性物品数量")){ - disposableAmountShowName = columnConfigOfAccountingInfoMap.get("一次性物品数量"); - }else{ - disposableAmountShowName = "一次性物品数量"; - } - String errorDamageAmountShowName = null;//丢失报损材料数量显示名 - if(columnConfigOfAccountingInfoMap.containsKey("丢失报损材料数量")){ - errorDamageAmountShowName = columnConfigOfAccountingInfoMap.get("丢失报损材料数量"); - }else{ - errorDamageAmountShowName = "丢失报损材料数量"; - } - String insidePriceShowName = null;//器械包总价显示名 - if(columnConfigOfAccountingInfoMap.containsKey("器械包总价")){ - insidePriceShowName = columnConfigOfAccountingInfoMap.get("器械包总价"); - }else{ - insidePriceShowName = "器械包总价"; - } - String errorDamagePriceShowName = null;//丢失报损材料显示名 - if(columnConfigOfAccountingInfoMap.containsKey("丢失报损材料总价")){ - errorDamagePriceShowName = columnConfigOfAccountingInfoMap.get("丢失报损材料总价"); - }else{ - errorDamagePriceShowName = "丢失报损材料总价"; - } - String disposablePriceShowName = null;//一次性物品总价显示名 - if(columnConfigOfAccountingInfoMap.containsKey("一次性物品总价")){ - disposablePriceShowName = columnConfigOfAccountingInfoMap.get("一次性物品总价"); - }else{ - disposablePriceShowName = "一次性物品总价"; - } - String dgWhetherToChargeSQL = ""; - String invoiceItemLeftJoinDisposableGoodsSQL = ""; - String noQueryWhetherToChargeSQL = ""; - String returnGoodsItemLeftJoinDisposableGoodsSQL = ""; - String receiveRecordItemLeftJoinDisposableGoodsSQL = ""; - String godownEntryDiposableGoodsItemLeftJoinDisposableGoodsSQL = ""; - String diposableGoodsItemLeftJoinDisposableGoodsSQL = ""; - if(queryWhetherToCharge){ - dgWhetherToChargeSQL = ",dg.whetherToCharge "; - invoiceItemLeftJoinDisposableGoodsSQL = " left join DisposableGoods dg on dg.id=ii.disposableGoodsId "; - noQueryWhetherToChargeSQL = ",null whetherToCharge "; - returnGoodsItemLeftJoinDisposableGoodsSQL = " left join DisposableGoods dg on dg.id=i.disposableGoodsID "; - receiveRecordItemLeftJoinDisposableGoodsSQL = " left join DisposableGoods dg on dg.id=i.disposableGoodsId "; - godownEntryDiposableGoodsItemLeftJoinDisposableGoodsSQL = " left join DisposableGoods dg on dg.id=ged.disposableGoodsID "; - diposableGoodsItemLeftJoinDisposableGoodsSQL = " left join DisposableGoods dg on dg.id=dgi.disposableGoodsID "; - } - String applicationDepartCoding = null; - String iDepartSql = null; - String rrDepartSql = null; - String rDepartSql = null; - String prDepartSql = null; - if(showApplicationDepart){ - iDepartSql = "i.depart,"; - rrDepartSql = "rr.depart,"; - rDepartSql = "r.depart,"; - prDepartSql = "pr.depart,"; - }else{ - iDepartSql = ""; - rrDepartSql = ""; - rDepartSql = ""; - prDepartSql = ""; - } - String iDepartCodingWhereSql = null; - String rDepartCodingWhereSql = null; - String rDepartCodeWhereSql = null; - String iDepartCodeWhereSql = null; - String ogeTargetOrgUnitCodeWhereSql = null; - String prDepartCodingWhereSql = null; - String crOrgUnitCodeWhereSql = null; - if(StringUtils.isNotBlank(invoicePlanDepartCoding)){ - iDepartCodingWhereSql = " and i.departCoding ='" + invoicePlanDepartCoding + "' "; - rDepartCodingWhereSql = " and r.departCoding ='" + invoicePlanDepartCoding + "' "; - rDepartCodeWhereSql = " and r.departCode ='" + invoicePlanDepartCoding + "' "; - iDepartCodeWhereSql = " and i.departCode ='" + invoicePlanDepartCoding + "' "; - ogeTargetOrgUnitCodeWhereSql = " and oge.targetOrgUnitCode ='" + invoicePlanDepartCoding + "' "; - prDepartCodingWhereSql = " and pr.departCoding ='" + invoicePlanDepartCoding + "' "; - crOrgUnitCodeWhereSql = " and cr.orgUnitCode ='" + invoicePlanDepartCoding + "' "; - }else{ - iDepartCodingWhereSql = ""; - rDepartCodingWhereSql = ""; - rDepartCodeWhereSql = ""; - iDepartCodeWhereSql = ""; - ogeTargetOrgUnitCodeWhereSql = ""; - prDepartCodingWhereSql = ""; - crOrgUnitCodeWhereSql = ""; - } - boolean enableMultipleBranchesOfHospital = CssdUtils.getSystemSetConfigByNameBool("enableMultipleBranchesOfHospital", false); - boolean enableDiscountPrice = CssdUtils.getSystemSetConfigByNameBool("enableDiscountPrice"); - boolean enableExpensiveGoods = CssdUtils.getSystemSetConfigByNameBool("enableExpensiveGoods"); - //是否启用包内材料统计列 - boolean monthReportMaterialAmountOfTousse = CssdUtils.getSystemSetConfigByNameBool("monthReportMaterialAmountOfTousse"); - SupplyRoomConfig supplyRoomConfig = supplyRoomConfigManager.getSystemParamsObj(); - final String TYPE_AUTO_DEDUCTION = "自动扣减物品"; - //SupplyRoomConfig firstSupplyRoomConfig = supplyRoomConfigManager.getFirstSupplyRoomConfig(); - //当前用户是否为供应室(包含一二级供应室)用户 - boolean isSupplyRoomUser = supplyRoomConfigManager.isSupplyRoomUser(); - LoginUserData user = AcegiHelper.getLoginUser(); - String orgUnitCoding = null; - if (user != null){ - orgUnitCoding = user.getOrgUnitCodingFromSupplyRoomConfig(); - } - boolean isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser = false; - if (isSupplyRoomUser || supplyRoomConfigManager.isExpensiveGoodsSupplyRoomUser()) { - isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser = true; - } - List list = new ArrayList(); - String invoiceWheresql = "" ; - //高值耗材(新)过滤条件 - String expensiveGoodsWheresql = "" ; - startDate += " 00:00:00"; - endDate += " 23:59:59"; - String betweenSql = "between " - + dateQueryAdapter.dateConverAdapter2(startDate, - "yyyy-mm-dd HH24:MI:SS") - + " and " + dateQueryAdapter.dateConverAdapter2(endDate, - "yyyy-mm-dd HH24:MI:SS") + " "; - if(StringUtils.isNotBlank(startDate) && StringUtils.isNotBlank(endDate)){ - invoiceWheresql = " and i.sendTime " + betweenSql; - expensiveGoodsWheresql = " and egge.time " + betweenSql; - } - String receiveDepartWhereSql = ""; - if(StringUtils.isNotBlank(department)){ - invoiceWheresql += " and i.settleAccountsDepart = '"+department+"'"; - expensiveGoodsWheresql += " and i.settleAccountsDepart = '"+department+"'"; - receiveDepartWhereSql = String.format(" and r.depart='%s'", department); - }else if(!(departments == null || departments.isEmpty())){ - invoiceWheresql += " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("i.settleAccountsDepart", departments); - expensiveGoodsWheresql += " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("i.settleAccountsDepart", departments); - receiveDepartWhereSql += " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("r.depart", departments); - } - String invoiceItemDisposableGoodsTypePredicate = "1=1"; - String disposableGoodsInvoiceAmountPredicate = " ii.diposable='是' "; - String returnGoodsItemPredicate = "1=1"; - String receiveRecordItemPredicate = "1=1"; - String outEntryPredicate = "1=1"; - String packingDisposableGoodsTypePredicate = "1=1"; - List allTousseType = getTousseTypes(tousseType); - String disposableGoodsIdSql = ""; - int dataSoureOfMaterialsCountOfToussesInReports = CssdUtils.getSystemSetConfigByNameInt("dataSoureOfMaterialsCountOfToussesInReports", 3); - //包定义id跟材料数量的临时表 - String tousseDefinitionIdMaterialAmountSql = " (select sum(mi.count) materialAmount,td.id,td.tousseType,td.isApplyEntireTousse from MaterialInstance mi join TousseDefinition td on mi.tousse_id = td.id group by td.id,td.tousseType,isApplyEntireTousse) "; - if(StringUtils.isNotBlank(disposableGoodsType)){ - disposableGoodsIdSql = String.format(" select id from DisposableGoods where type='%s' ", disposableGoodsType); - invoiceItemDisposableGoodsTypePredicate = String.format(" (ii.diposable='否' or ii.disposableGoodsId in(%s)) ", disposableGoodsIdSql); - disposableGoodsInvoiceAmountPredicate = String.format(" (ii.diposable='是' and ii.disposableGoodsId in(%s)) ", disposableGoodsIdSql); - returnGoodsItemPredicate = String.format(" (r.type!='一次性物品' or i.disposableGoodsId in(%s)) ", disposableGoodsIdSql); - outEntryPredicate = String.format(" (ged.disposableGoodsID in(%s)) ", disposableGoodsIdSql); - packingDisposableGoodsTypePredicate = String.format(" (dgi.disposableGoodsID in(%s)) ", disposableGoodsIdSql); - } - String invoiceJoinInvoicePlanSql = null; - String excludeSciProjectSql = null; - String excludeDiposableGoodsItemSql = null; - String queryProjNameSql = null; - String containDiposableGoodsItemSql = null; - if(showTotalMoneyOfSciProjectDisposableGoodsInvoiceInAccountingMonthlyReport){ - invoiceJoinInvoicePlanSql = " left join "+ InvoicePlan.class.getSimpleName() +" ip on i.invoicePlan_ID=ip.id "; - excludeSciProjectSql = ""; - excludeDiposableGoodsItemSql = ""; - containDiposableGoodsItemSql = " and dgi.invoice_id in (select i.id from "+ Invoice.class.getSimpleName() +" i join "+ InvoicePlan.class.getSimpleName() +" ip on ip.id=i.invoicePlan_ID where (ip.projName is not null) and dgi.invoice_id=i.id) "; - queryProjNameSql = ",ip.projName "; - }else if(excludeSciProjectInfo){//排除属于科研项目的一次性物品申请单的发货数据 - invoiceJoinInvoicePlanSql = " left join "+ InvoicePlan.class.getSimpleName() +" ip on i.invoicePlan_ID=ip.id "; - excludeSciProjectSql = " and (ip.projName is null or ip.projName='')"; - excludeDiposableGoodsItemSql = " and dgi.invoice_id in (select i.id from "+ Invoice.class.getSimpleName() +" i left join "+ InvoicePlan.class.getSimpleName() +" ip on ip.id=i.invoicePlan_ID where (ip.projName is null or ip.projName='') and dgi.invoice_id=i.id) "; - queryProjNameSql = ""; - containDiposableGoodsItemSql = ""; - }else{ - invoiceJoinInvoicePlanSql = ""; - excludeSciProjectSql = ""; - excludeDiposableGoodsItemSql = ""; - queryProjNameSql = ""; - containDiposableGoodsItemSql = ""; - } - if(StringUtils.isBlank(tousseType) || !"器械材料".equals(tousseType)){ - //物品类型sql - String tousseTypeInvoiceSql = ""; - String tousseTypeReturnSql = ""; - if(StringUtils.isNotBlank(tousseType)){ - if(TYPE_AUTO_DEDUCTION.equals(tousseType)){ - tousseTypeInvoiceSql = String.format(" and ii.type='%s' ", InvoiceItem.TYPE_AUTO_DEDUCTION); - }else{ - tousseTypeInvoiceSql = String.format(" and %s ", SqlUtils.getStringFieldInLargeCollectionsPredicate("ii.tousseType", allTousseType)); - } - - if(TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType)){ - tousseTypeReturnSql = " and i.disposableGoodsId in (select id from DisposableGoods) "; - }else{ - tousseTypeReturnSql = String.format(" and i.tousseDefinition_id in (select id from TousseDefinition where %s) ", SqlUtils.getStringFieldInLargeCollectionsPredicate("tousseType", allTousseType)); - } - }else{ - tousseTypeInvoiceSql = String.format(" and (ii.type='%s' or ii.diposable='是' or (ii.diposable='否' and %s))", InvoiceItem.TYPE_AUTO_DEDUCTION,SqlUtils.getStringFieldInLargeCollectionsPredicate("ii.tousseType", allTousseType)); - tousseTypeReturnSql = String.format(" and (i.disposableGoodsId in (select id from DisposableGoods) or i.tousseDefinition_id in (select id from TousseDefinition where %s) )",SqlUtils.getStringFieldInLargeCollectionsPredicate("tousseType", allTousseType)); - } - - String invoicePriceSql = "select "+ iDepartSql+"i.settleAccountsDepartCoding as coding,i.settleAccountsDepart " - + queryProjNameSql - + ",sum(ii.settlementPrice) as price,ii.diposable,sum(ii.settlementDiscountPrice) as settlementDiscountPrice,ii.tousseType " - + dgWhetherToChargeSQL - + " from " + Invoice.class.getSimpleName() + " i join " - + InvoiceItem.class.getSimpleName() + " ii on i.id = ii.invoice_id " - + invoiceJoinInvoicePlanSql - + invoiceItemLeftJoinDisposableGoodsSQL - + "where 1=1 and "+invoiceItemDisposableGoodsTypePredicate+" and " - + getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - + " and (i.status ='收货签收' or " - + "i.status = '已发货') " + iDepartCodingWhereSql + invoiceWheresql + tousseTypeInvoiceSql + excludeSciProjectSql + " group by "+ iDepartSql +" i.settleAccountsDepartCoding,i.settleAccountsDepart,ii.diposable,ii.tousseType"+queryProjNameSql - + dgWhetherToChargeSQL; - - //如果为高值耗材处理科室用户,并且启用高值耗材功能,且所选物品类型为全部或高值耗材时,则将高值耗材退货数据也抵冲掉 - if(enableExpensiveGoods && (StringUtils.isBlank(tousseType) || StringUtils.equals(ExpensiveGoods.TYPE_NAME, tousseType))){ - invoicePriceSql += " union all (select "+ iDepartSql +"i.settleAccountsDepartCoding coding,i.settleAccountsDepart settleAccountsDepart,-1 * sum(egi.price) price,'否' as diposable,-1 * sum(egi.price) settlementDiscountPrice,'高值耗材' as tousseType " - + noQueryWhetherToChargeSQL - + " from ExpensiveGoodsGodownEntry egge join ExpensiveGoodsGodownEntryItem eggei on egge.id=eggei.expensiveGoodsGodownEntry_id " - + " join ExpensiveGoodsInstance egi on egi.id=eggei.expensiveGoodsInstanceId join Invoice i on egi.invoiceId=i.id " - + " where "+ getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - + " and egge.type='退库单' " + expensiveGoodsWheresql - + iDepartCodingWhereSql - + " group by "+ iDepartSql + "i.settleAccountsDepartCoding,i.settleAccountsDepart)"; - } - - ResultSet rs = objectDao.executeSql(invoicePriceSql); - try { - while(rs.next()){ - String code = rs.getString("coding"); - String dept = null; - String settleAccountsDepart = rs.getString("settleAccountsDepart"); - if(showApplicationDepart){ - dept = rs.getString("depart"); - }else if(nameToBrevityCodeMap.size() > 0){ - dept = nameToBrevityCodeMap.get(settleAccountsDepart); - } - Double price = rs.getDouble("price"); - String diposable = rs.getString("diposable"); - Double discountPrice = rs.getDouble("settlementDiscountPrice"); - String tType = rs.getString("tousseType"); - String columnName = ""; - String costColumn = ""; - if("是".equals(diposable)){ - String whetherToCharge = null; - if(queryWhetherToCharge){ - whetherToCharge = rs.getString("whetherToCharge"); - } - columnName = getChargeDisposableColumnName(queryWhetherToCharge, whetherToCharge, disposablePriceShowName); - costColumn = "一次性物品记支"; - discountPrice = price;//一次性物品发货项中目前还没有记录折扣价 - }else{ - if(ExpensiveGoods.TYPE_NAME.equals(tType)){ - columnName = "高值耗材总价"; - }else{ - columnName = insidePriceShowName; - costColumn = "器械包记支"; - } - - } - String hospitalDistrict = null; - String projName = null; - if(showTotalMoneyOfSciProjectDisposableGoodsInvoiceInAccountingMonthlyReport){ - projName = rs.getString("projName"); - } - if(StringUtils.isNotBlank(projName) && showTotalMoneyOfSciProjectDisposableGoodsInvoiceInAccountingMonthlyReport){ - dept = "科研物资领用公共部门"; - settleAccountsDepart = "科研物资领用公共部门"; - }else if(enableMultipleBranchesOfHospital){ - hospitalDistrict = departToBrancheOfHospitalMap == null || departToBrancheOfHospitalMap.isEmpty() || departToBrancheOfHospitalMap.get(settleAccountsDepart) == null?null:departToBrancheOfHospitalMap.get(settleAccountsDepart).getName(); - } - newMonthReport(code, dept,settleAccountsDepart,"2", "价格统计",columnName,price, list, hospitalDistrict, enableMultipleBranchesOfHospital); - if(enableDiscountPrice && StringUtils.isNotBlank(costColumn)){ - newMonthReport(code, dept,settleAccountsDepart,"1", "科室记支",costColumn,discountPrice, list, hospitalDistrict, enableMultipleBranchesOfHospital); - } - } - } catch (SQLException e) { - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(rs); - } - if(!TYPE_AUTO_DEDUCTION.equals(tousseType)){ - String queryColumnSql = null; - String leftJoinSqlForReturnSql = null; - if(dataSoureOfMaterialsCountOfToussesInReports == 3){ - queryColumnSql = "td.tousseType,i.materialAmountAtThatTime materialAmount,td.isApplyEntireTousse "; - leftJoinSqlForReturnSql = String.format("left join %s td on td.id=i.tousseDefinition_id", TousseDefinition.class.getSimpleName()); - }else{ - queryColumnSql = "tdm.tousseType,tdm.materialAmount as materialAmount ,tdm.isApplyEntireTousse"; - leftJoinSqlForReturnSql = " left join " + tousseDefinitionIdMaterialAmountSql + " tdm on tdm.id = i.tousseDefinition_id "; - } - String joinSql = ""; - if(showTotalMoneyOfSciProjectDisposableGoodsInvoiceInAccountingMonthlyReport){ - joinSql = " left join "+ InvoicePlan.class.getSimpleName() + " ip on r.invoicePlanId=ip.id "; - } - //退货统计(器械包或一次性物品) - String returnSql = "select "+ rDepartSql +"r.type,(-i.settlementPrice) settlementPrice,-i.amount amount,r.settleAccountsDepartCoding,r.settleAccountsDepart," - + queryColumnSql - + queryProjNameSql - + dgWhetherToChargeSQL - + " from ReturnGoodsRecord r join ReturnGoodsItem i on r.id = i.returnGoodsRecord_ID " - + leftJoinSqlForReturnSql - + returnGoodsItemLeftJoinDisposableGoodsSQL - + joinSql - + " where "+returnGoodsItemPredicate+ tousseTypeReturnSql + rDepartCodingWhereSql + " and " - + getHandleDeptCodeSql("r.handleDepartCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - +" and r.returnTime " + betweenSql; - if(StringUtils.isNotBlank(department)){ - returnSql += " and r.settleAccountsDepart = '" + department + "'"; - }else if(!(departments == null || departments.isEmpty())){ - returnSql += " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("r.settleAccountsDepart", departments); - } - ResultSet rs5 = objectDao.executeSql(returnSql); - try { - while(rs5.next()){ - String type = rs5.getString("type"); - Double price = rs5.getDouble("settlementPrice"); - int amount = rs5.getInt("amount"); - String code = rs5.getString("settleAccountsDepartCoding"); - String dept = null; - String settleAccountsDepart = rs5.getString("settleAccountsDepart"); - if(showApplicationDepart){ - dept = rs5.getString("depart"); - }else if(nameToBrevityCodeMap.size() > 0){ - dept = nameToBrevityCodeMap.get(settleAccountsDepart); - } - String returnTousseType = rs5.getString("tousseType"); - String isApplyEntireTousse = rs5.getString("isApplyEntireTousse"); - int materialAmount = rs5.getInt("materialAmount"); - int totalMaterialAmount = amount * materialAmount; - - // 如果是拆包的消毒物品,用统计数量替换包数量 - if ("消毒物品".equals(returnTousseType) && Constants.STR_NO.equals(isApplyEntireTousse)) { - if (materialAmount > 0) { - amount = totalMaterialAmount; - } - }else if(TousseDefinition.PACKAGE_TYPE_CUSTOM.equals(returnTousseType)&& !showCustonTousseAmount){ - if (materialAmount > 0) { - amount = totalMaterialAmount; - } - } - String hospitalDistrict = null; - String projName = null; - if(showTotalMoneyOfSciProjectDisposableGoodsInvoiceInAccountingMonthlyReport){ - projName = rs5.getString("projName"); - } - if(StringUtils.isNotBlank(projName) && showTotalMoneyOfSciProjectDisposableGoodsInvoiceInAccountingMonthlyReport){ - dept = "科研物资领用公共部门"; - settleAccountsDepart = "科研物资领用公共部门"; - }else if(enableMultipleBranchesOfHospital){ - hospitalDistrict = departToBrancheOfHospitalMap == null || departToBrancheOfHospitalMap.isEmpty() || departToBrancheOfHospitalMap.get(settleAccountsDepart) == null?null:departToBrancheOfHospitalMap.get(settleAccountsDepart).getName(); - } - if("一次性物品".equals(type)){ - String whetherToCharge = null; - if(queryWhetherToCharge){ - whetherToCharge = rs5.getString("whetherToCharge"); - } - newMonthReport(code, dept,settleAccountsDepart, "2", "价格统计", - getChargeDisposableColumnName(queryWhetherToCharge, whetherToCharge, disposablePriceShowName) - , price, list,hospitalDistrict, enableMultipleBranchesOfHospital); - if(enableDiscountPrice){ - newMonthReport(code, dept,settleAccountsDepart,"1", "科室记支","一次性物品记支",price, list,hospitalDistrict, enableMultipleBranchesOfHospital); - } - if(!hideAmountColumn){ - newMonthReport(code, dept,settleAccountsDepart, "3", "数量统计", - getChargeDisposableColumnName(queryWhetherToCharge, whetherToCharge, disposableAmountShowName) - , amount, list,hospitalDistrict, enableMultipleBranchesOfHospital); - } - }else{ - newMonthReport(code, dept,settleAccountsDepart, "2", "价格统计", insidePriceShowName, price, list,hospitalDistrict, enableMultipleBranchesOfHospital); - if(enableDiscountPrice){ - newMonthReport(code, dept,settleAccountsDepart,"1", "科室记支","器械包记支",price, list,hospitalDistrict, enableMultipleBranchesOfHospital); - } - if(!hideAmountColumn){ - newMonthReport(code, dept,settleAccountsDepart, "3", "数量统计", insideAmountShowName, amount, list,hospitalDistrict, enableMultipleBranchesOfHospital); - if(monthReportMaterialAmountOfTousse){ - newMonthReport(code, dept,settleAccountsDepart, "4", "包内材料统计", "包内材料数量", totalMaterialAmount, list,hospitalDistrict, enableMultipleBranchesOfHospital); - } - } - } - } - }catch(Exception e){ - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(rs5); - } - } - } - - if(StringUtils.isBlank(tousseType) || "器械材料".equals(tousseType)){ - // 材料发货价格 - String materialInvoicePriceSql = "select "+ iDepartSql+"i.settleAccountsDepartCoding as coding,i.settleAccountsDepart " - + ",sum(ii.settlementPrice) as price from MaterialInvoice i," - + "MaterialInvoiceItem ii where i.id = ii.materialInvoice_id and " - + getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - + invoiceWheresql + iDepartCodingWhereSql + " group by " - + iDepartSql - +"i.settleAccountsDepartCoding,i.settleAccountsDepart"; - ResultSet materialInvoicePriceResultSet = objectDao.executeSql(materialInvoicePriceSql); - try { - while(materialInvoicePriceResultSet.next()){ - String code = materialInvoicePriceResultSet.getString("coding"); - String dept = null; - String settleAccountsDepart = materialInvoicePriceResultSet.getString("settleAccountsDepart"); - if(showApplicationDepart){ - dept = materialInvoicePriceResultSet.getString("depart"); - }else if(nameToBrevityCodeMap.size() > 0){ - dept = nameToBrevityCodeMap.get(settleAccountsDepart); - } - Double price = materialInvoicePriceResultSet.getDouble("price"); - - String columnName = "发货材料总价"; - String hospitalDistrict = null; - if(enableMultipleBranchesOfHospital){ - hospitalDistrict = departToBrancheOfHospitalMap == null || departToBrancheOfHospitalMap.isEmpty() || departToBrancheOfHospitalMap.get(settleAccountsDepart) == null?null:departToBrancheOfHospitalMap.get(settleAccountsDepart).getName(); - } - newMonthReport(code, dept,settleAccountsDepart,"2", "价格统计",columnName,price, list,hospitalDistrict, enableMultipleBranchesOfHospital); - if(enableDiscountPrice){ - newMonthReport(code, dept,settleAccountsDepart,"1", "科室记支","材料记支",price, list,hospitalDistrict, enableMultipleBranchesOfHospital); - } - } - } catch (SQLException e) { - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(materialInvoicePriceResultSet); - } - if(!hideAmountColumn){ - // 材料发货数量 - String materialInvoiceAmountSql = "select "+ iDepartSql +"i.settleAccountsDepartCoding as coding,i.settleAccountsDepart " - + ",mi.amount from MaterialInvoice i inner join MaterialInvoiceItem mi on i.id=mi.materialInvoice_id " - + "where " + getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - + " and (mi.amount is not null and mi.amount>0) " - + " " + invoiceWheresql + iDepartCodingWhereSql; - - ResultSet materialInvoiceAmountResultSet = objectDao.executeSql(materialInvoiceAmountSql); - try { - while(materialInvoiceAmountResultSet.next()){ - String code = materialInvoiceAmountResultSet.getString("coding"); - String dept = null; - String settleAccountsDepart = materialInvoiceAmountResultSet.getString("settleAccountsDepart"); - if(showApplicationDepart){ - dept = materialInvoiceAmountResultSet.getString("depart"); - }else if(nameToBrevityCodeMap.size() > 0){ - dept = nameToBrevityCodeMap.get(settleAccountsDepart); - } - int tousseAmount = materialInvoiceAmountResultSet.getInt("amount"); - String hospitalDistrict = null; - if(enableMultipleBranchesOfHospital){ - hospitalDistrict = departToBrancheOfHospitalMap == null || departToBrancheOfHospitalMap.isEmpty() || departToBrancheOfHospitalMap.get(settleAccountsDepart) == null?null:departToBrancheOfHospitalMap.get(settleAccountsDepart).getName(); - } - if(tousseAmount > 0){ - newMonthReport(code, dept,settleAccountsDepart,"3","数量统计", "发货材料数量",tousseAmount,list,hospitalDistrict, enableMultipleBranchesOfHospital); - } - } - } catch (SQLException e) { - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(materialInvoiceAmountResultSet); - } - } - String banQuery = " 1 = 0 and "; - String damagedTousseAtCost = supplyRoomConfig.getDamagedTousseAtCost(); - /*if(StringUtils.isBlank(damagedTousseAtCost) || Constants.STR_YES.equals(damagedTousseAtCost)){ - banQuery = ""; - }*/ - if(Constants.STR_YES.equals(damagedTousseAtCost)){ - banQuery = ""; - } - //材料报损统计 - String damageSql = "select "+ iDepartSql +"i.settleAccountsDepartCoding departCode,i.settleAccountsDepart,i.materialName,sum(i.materialCost*i.additionalAmount) money,sum(i.additionalAmount) amount " - + " from MaterialErrorDamageDetail i where " + banQuery - + getHandleDeptCodeSql("i.handleDepartCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - + " and i.type = '" - + MaterialErrorDamageDetail.TYPE_DAMAGE + "' and i.additionalTime " - + betweenSql + iDepartCodeWhereSql; - - if(StringUtils.isNotBlank(department)){ - damageSql += " and i.settleAccountsDepart = '"+department+"' "; - }else if(!(departments == null || departments.isEmpty())){ - damageSql += " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("i.settleAccountsDepart", departments); - } - damageSql += " group by "+ iDepartSql +"i.settleAccountsDepartCoding,i.settleAccountsDepart,i.materialName"; - ResultSet rs33 = objectDao.executeSql(damageSql); - try { - if(rs33 != null){ - while(rs33.next()){ - String code = rs33.getString("departCode"); - String dept = null; - String settleAccountsDepart = rs33.getString("settleAccountsDepart"); - if(showApplicationDepart){ - dept = rs33.getString("depart"); - }else if(nameToBrevityCodeMap.size() > 0){ - dept = nameToBrevityCodeMap.get(settleAccountsDepart); - } - String materialName = rs33.getString("materialName"); - Double money = rs33.getDouble("money"); - String hospitalDistrict = null; - if(enableMultipleBranchesOfHospital){ - hospitalDistrict = departToBrancheOfHospitalMap == null || departToBrancheOfHospitalMap.isEmpty() || departToBrancheOfHospitalMap.get(settleAccountsDepart) == null?null:departToBrancheOfHospitalMap.get(settleAccountsDepart).getName(); - } - if(!hideAmountColumn){ - int amount = rs33.getInt("amount"); - newMonthReport(code, dept,settleAccountsDepart, "3", "数量统计", errorDamageAmountShowName, amount, list,hospitalDistrict, enableMultipleBranchesOfHospital); - } - newMonthReport(code, dept,settleAccountsDepart, "2", "价格统计", errorDamagePriceShowName, money, list,hospitalDistrict, enableMultipleBranchesOfHospital); - if(enableDiscountPrice){ - newMonthReport(code, dept,settleAccountsDepart,"1", "科室记支","材料记支",money, list,hospitalDistrict, enableMultipleBranchesOfHospital); - } - } - } - }catch(Exception e){ - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(rs33); - } - - //材料丢失统计 - String recyclingErrorSql = "select "+ rDepartSql +"r.settleAccountsDepartCoding departCode,r.settleAccountsDepart,r.materialName,sum(r.materialCost*r.additionalAmount) money,sum(r.additionalAmount) amount " - + " from MaterialErrorDamageDetail r where r.errorType = '缺失' and r.type = '"+MaterialErrorDamageDetail.TYPE_ERROR+"' and r.materialName != '器械包标识牌' " - + " and "+ getHandleDeptCodeSql("r.handleDepartCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - + " and r.additionalTime " + betweenSql + rDepartCodeWhereSql; - - if(StringUtils.isNotBlank(department)){ - recyclingErrorSql += " and r.settleAccountsDepart = '"+department+"' "; - }else if(!(departments == null || departments.isEmpty())){ - recyclingErrorSql += " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("r.settleAccountsDepart", departments); - } - recyclingErrorSql += " group by "+ rDepartSql +"r.settleAccountsDepartCoding,r.settleAccountsDepart,r.materialName"; - ResultSet rs3 = objectDao.executeSql(recyclingErrorSql); - try { - if(rs3 != null){ - while(rs3.next()){ - String code = rs3.getString("departCode"); - String dept = null; - String settleAccountsDepart = rs3.getString("settleAccountsDepart"); - if(showApplicationDepart){ - dept = rs3.getString("depart"); - }else if(nameToBrevityCodeMap.size() > 0){ - dept = nameToBrevityCodeMap.get(settleAccountsDepart); - } - String materialName = rs3.getString("materialName"); - Double money = rs3.getDouble("money"); - String hospitalDistrict = null; - if(enableMultipleBranchesOfHospital){ - hospitalDistrict = departToBrancheOfHospitalMap == null || departToBrancheOfHospitalMap.isEmpty() || departToBrancheOfHospitalMap.get(settleAccountsDepart) == null?null:departToBrancheOfHospitalMap.get(settleAccountsDepart).getName(); - } - if(!hideAmountColumn){ - int amount = rs3.getInt("amount"); - newMonthReport(code, dept,settleAccountsDepart,"3", "数量统计",errorDamageAmountShowName,amount, list,hospitalDistrict, enableMultipleBranchesOfHospital); - } - newMonthReport(code, dept,settleAccountsDepart,"2", "价格统计",errorDamagePriceShowName,money, list,hospitalDistrict, enableMultipleBranchesOfHospital); - if(enableDiscountPrice){ - newMonthReport(code, dept,settleAccountsDepart,"1", "科室记支","材料记支",money, list,hospitalDistrict, enableMultipleBranchesOfHospital); - } - } - } - }catch(Exception e){ - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(rs3); - } - - // 材料退货 - String materialReturnSql = "select "+ rDepartSql +"r.settleAccountsDepartCoding departCoding,r.settleAccountsDepart , (-i.settlementPrice) settlementPrice,-i.amount amount " - + "from ReturnMaterialRecord r,ReturnMaterialItem i where r.id = i.returnMaterialRecord_ID" - + " and "+ getHandleDeptCodeSql("r.handleDepartCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - +" and r.returnTime " + betweenSql + rDepartCodingWhereSql; - if(StringUtils.isNotBlank(department)){ - materialReturnSql += " and r.settleAccountsDepart = '" + department + "'"; - }else if(!(departments == null || departments.isEmpty())){ - materialReturnSql += " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("r.settleAccountsDepart", departments); - } - ResultSet materialReturnResultSet = objectDao.executeSql(materialReturnSql); - try { - while(materialReturnResultSet.next()){ - String code = materialReturnResultSet.getString("departCoding"); - String dept = null; - String settleAccountsDepart = materialReturnResultSet.getString("settleAccountsDepart"); - if(showApplicationDepart){ - dept = materialReturnResultSet.getString("depart"); - }else if(nameToBrevityCodeMap.containsKey(settleAccountsDepart)){ - dept = nameToBrevityCodeMap.get(settleAccountsDepart); - } - Double price = materialReturnResultSet.getDouble("settlementPrice"); - String hospitalDistrict = null; - if(enableMultipleBranchesOfHospital){ - hospitalDistrict = departToBrancheOfHospitalMap == null || departToBrancheOfHospitalMap.isEmpty() || departToBrancheOfHospitalMap.get(settleAccountsDepart) == null?null:departToBrancheOfHospitalMap.get(settleAccountsDepart).getName(); - } - newMonthReport(code, dept,settleAccountsDepart, "2", "价格统计", "发货材料总价", price, list,hospitalDistrict, enableMultipleBranchesOfHospital); - if(!hideAmountColumn){ - int amount = materialReturnResultSet.getInt("amount"); - newMonthReport(code, dept,settleAccountsDepart, "3", "数量统计", "发货材料数量", amount, list,hospitalDistrict, enableMultipleBranchesOfHospital); - } - if(enableDiscountPrice){ - newMonthReport(code, dept,settleAccountsDepart,"1", "科室记支","材料记支",price, list,hospitalDistrict, enableMultipleBranchesOfHospital); - } - } - }catch(Exception e){ - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(materialReturnResultSet); - } - } - - if(!hideAmountColumn && (StringUtils.isBlank(tousseType) || TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType) || TYPE_AUTO_DEDUCTION.equals(tousseType))){ - String tousseTypeSql = ""; - if(TYPE_AUTO_DEDUCTION.equals(tousseType)){ - tousseTypeSql = String.format(" and ii.type='%s' ", InvoiceItem.TYPE_AUTO_DEDUCTION); - } - // 一次性发货数量统计 - String disposableGoodsInvoiceAmountSql = "select "+ iDepartSql +"i.settleAccountsDepartCoding as coding,i.settleAccountsDepart " - + queryProjNameSql - + ",ii.amount " - + dgWhetherToChargeSQL - + " from Invoice i inner join InvoiceItem ii on i.id = ii.invoice_id " - + invoiceJoinInvoicePlanSql - + invoiceItemLeftJoinDisposableGoodsSQL - + "where " - + getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - +tousseTypeSql - +" and "+disposableGoodsInvoiceAmountPredicate - + excludeSciProjectSql - + " and (i.status ='收货签收' or i.status = '已发货') " + invoiceWheresql + iDepartCodingWhereSql; - ResultSet disposableGoodsInvoiceAmountResultSet = objectDao.executeSql(disposableGoodsInvoiceAmountSql); - try { - while(disposableGoodsInvoiceAmountResultSet.next()){ - String code = disposableGoodsInvoiceAmountResultSet.getString("coding"); - String dept = null; - String settleAccountsDepart = disposableGoodsInvoiceAmountResultSet.getString("settleAccountsDepart"); - if(showApplicationDepart){ - dept = disposableGoodsInvoiceAmountResultSet.getString("depart"); - }else if(nameToBrevityCodeMap.containsKey(settleAccountsDepart)){ - dept = nameToBrevityCodeMap.get(settleAccountsDepart); - } - int diposableAmount = disposableGoodsInvoiceAmountResultSet.getInt("amount"); - if(diposableAmount > 0){ - String hospitalDistrict = null; - String projName = null; - if(showTotalMoneyOfSciProjectDisposableGoodsInvoiceInAccountingMonthlyReport){ - projName = disposableGoodsInvoiceAmountResultSet.getString("projName"); - } - if(StringUtils.isNotBlank(projName) && showTotalMoneyOfSciProjectDisposableGoodsInvoiceInAccountingMonthlyReport){ - dept = "科研物资领用公共部门"; - settleAccountsDepart = "科研物资领用公共部门"; - }else if(enableMultipleBranchesOfHospital){ - hospitalDistrict = departToBrancheOfHospitalMap == null || departToBrancheOfHospitalMap.isEmpty() || departToBrancheOfHospitalMap.get(settleAccountsDepart) == null?null:departToBrancheOfHospitalMap.get(settleAccountsDepart).getName(); - } - String whetherToCharge = null; - if(queryWhetherToCharge){ - whetherToCharge = disposableGoodsInvoiceAmountResultSet.getString("whetherToCharge"); - } - newMonthReport(code, dept,settleAccountsDepart,"3","数量统计" - , getChargeDisposableColumnName(queryWhetherToCharge, whetherToCharge , disposableAmountShowName) - ,diposableAmount,list,hospitalDistrict, enableMultipleBranchesOfHospital); - } - } - } catch (SQLException e) { - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(disposableGoodsInvoiceAmountResultSet); - } - - } - - if(isSupplyRoomUser && (StringUtils.isBlank(tousseType) || "器械材料".equals(tousseType) || TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType) || TYPE_AUTO_DEDUCTION.equals(tousseType))){ - if("器械材料".equals(tousseType)){ - receiveRecordItemPredicate = String.format(" (i.type!='一次性物品') "); - }else if(TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType)){ - if(StringUtils.isNotBlank(disposableGoodsType)){ - receiveRecordItemPredicate = String.format(" (i.type='一次性物品' and i.disposableGoodsId in(%s)) ", disposableGoodsIdSql); - } - }else{ - if(StringUtils.isNotBlank(disposableGoodsType)){ - receiveRecordItemPredicate = String.format(" (i.type!='一次性物品' or i.disposableGoodsId in(%s)) ", disposableGoodsIdSql); - } - } - String tousseTypeSql = ""; - if(TYPE_AUTO_DEDUCTION.equals(tousseType)){ - tousseTypeSql = String.format(" and r.type='%s' ", InvoiceItem.TYPE_AUTO_DEDUCTION); - } - //供应室领用(器械材料与一次性物品) - String receiveSql = "select "+ rDepartSql +" i.type,(i.amount*i.price) price,i.amount,r.departcoding " - + dgWhetherToChargeSQL - + "from ReceiveRecord r join ReceiveRecordItem i on r.id = i.receiverecord_id " - + receiveRecordItemLeftJoinDisposableGoodsSQL - + "where 1=1 " - +tousseTypeSql - + "and "+receiveRecordItemPredicate + receiveDepartWhereSql + " and r.time " + betweenSql + rDepartCodingWhereSql; - SupplyRoomConfig config = supplyRoomConfigManager.getFirstSupplyRoomConfig(); - ResultSet rs4 = objectDao.executeSql(receiveSql); - try { - while(rs4.next()){ - String type = rs4.getString("type"); - Double price = rs4.getDouble("price"); - int amount = rs4.getInt("amount"); - String code = rs4.getString("departcoding"); - String dept = null; - if(showApplicationDepart){ - dept = rs4.getString("depart"); - }else if(nameToBrevityCodeMap.containsKey(config.getOrgUnitName())){ - dept = nameToBrevityCodeMap.get(config.getOrgUnitName()); - } - String hospitalDistrict = null; - if(enableMultipleBranchesOfHospital){ - hospitalDistrict = departToBrancheOfHospitalMap == null || departToBrancheOfHospitalMap.isEmpty() || departToBrancheOfHospitalMap.get(config.getOrgUnitName()) == null?null:departToBrancheOfHospitalMap.get(config.getOrgUnitName()).getName(); - } - if("一次性物品".equals(type)){ - String whetherToCharge = null; - if(queryWhetherToCharge){ - whetherToCharge = rs4.getString("whetherToCharge"); - } - newMonthReport(code, dept, config.getOrgUnitName(), "2", "价格统计", getChargeDisposableColumnName(queryWhetherToCharge, whetherToCharge, disposablePriceShowName) , price, list,hospitalDistrict, enableMultipleBranchesOfHospital); - if(enableDiscountPrice){ - newMonthReport(code,dept, config.getOrgUnitName(),"1", "科室记支","一次性物品记支",price, list,hospitalDistrict, enableMultipleBranchesOfHospital); - } - if(!hideAmountColumn){ - newMonthReport(code,dept, config.getOrgUnitName(), "3", "数量统计",getChargeDisposableColumnName(queryWhetherToCharge, whetherToCharge, disposableAmountShowName) , amount, list,hospitalDistrict, enableMultipleBranchesOfHospital); - } - }else{ - newMonthReport(code, dept, config.getOrgUnitName(), "2", "价格统计", "发货材料总价", price, list,hospitalDistrict, enableMultipleBranchesOfHospital); - if(enableDiscountPrice){ - newMonthReport(code, dept, config.getOrgUnitName(),"1", "科室记支","材料记支",price, list,hospitalDistrict, enableMultipleBranchesOfHospital); - } - if(!hideAmountColumn){ - newMonthReport(code, dept, config.getOrgUnitName(), "3", "数量统计", "发货材料数量", amount, list,hospitalDistrict, enableMultipleBranchesOfHospital); - } - } - } - }catch(Exception e){ - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(rs4); - } - } - // 一次性物品,调拨出库 - if(isSupplyRoomUser && (StringUtils.isBlank(tousseType) || TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType))){ - //供应室领用(器械材料与一次性物品) - String receiveSql = "select '一次性物品',(ged.amount*ged.price),ged.amount,oge.targetOrgUnitCode,oge.targetOrgUnitName " - + dgWhetherToChargeSQL - + "from GodownEntry oge inner join GodownEntryDiposableGoodsItem ged on oge.id = ged.godownEntryID " - + godownEntryDiposableGoodsItemLeftJoinDisposableGoodsSQL - + " where oge.type ='退库单' and oge.subType='调拨出库' " - + "and "+outEntryPredicate+" and " - + getHandleDeptCodeSql("oge.orgUnitCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - + " and oge.time " + betweenSql + ogeTargetOrgUnitCodeWhereSql; - if(StringUtils.isNotBlank(department)){ - receiveSql += " and oge.targetOrgUnitName = '" + department + "'"; - }else if(!(departments == null || departments.isEmpty())){ - receiveSql += " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("oge.targetOrgUnitName", departments); - } - ResultSet rs4 = objectDao.executeSql(receiveSql); - try { - while(rs4.next()){ - String type = rs4.getString(1); - if("一次性物品".equals(type)){ - Double price = rs4.getDouble(2); - String code = rs4.getString(4); - String orgUnitName = rs4.getString(5); - String depart = null; - if(showApplicationDepart){ - depart = orgUnitName; - }else if(nameToBrevityCodeMap.containsKey(orgUnitName)){ - depart = nameToBrevityCodeMap.get(orgUnitName); - } - String hospitalDistrict = null; - if(enableMultipleBranchesOfHospital){ - hospitalDistrict = departToBrancheOfHospitalMap == null || departToBrancheOfHospitalMap.isEmpty() || departToBrancheOfHospitalMap.get(orgUnitName) == null?null:departToBrancheOfHospitalMap.get(orgUnitName).getName(); - } - String whetherToCharge = null; - if(queryWhetherToCharge){ - whetherToCharge = rs4.getString("whetherToCharge"); - } - newMonthReport(code, depart,orgUnitName, "2", "价格统计", getChargeDisposableColumnName(queryWhetherToCharge, whetherToCharge, disposablePriceShowName) , price, list,hospitalDistrict, enableMultipleBranchesOfHospital); - if(enableDiscountPrice){ - newMonthReport(code, depart,orgUnitName,"1", "科室记支","一次性物品记支",price, list,hospitalDistrict, enableMultipleBranchesOfHospital); - } - if(!hideAmountColumn){ - int amount = rs4.getInt("amount"); - newMonthReport(code, depart,orgUnitName, "3", "数量统计", getChargeDisposableColumnName(queryWhetherToCharge, whetherToCharge, disposableAmountShowName) , amount, list,hospitalDistrict, enableMultipleBranchesOfHospital); - } - } - } - }catch(Exception e){ - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(rs4); - } - } - // 一次性物品,盘亏出库 - if(isSupplyRoomUser && (StringUtils.isBlank(tousseType) || TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType))){ - //供应室领用(器械材料与一次性物品) - String receiveSql = "select '一次性物品',(ged.amount*ged.price),ged.amount,oge.orgUnitCode,oge.orgUnitName " - + dgWhetherToChargeSQL - + "from GodownEntry oge inner join GodownEntryDiposableGoodsItem ged on oge.id = ged.godownEntryID " - + godownEntryDiposableGoodsItemLeftJoinDisposableGoodsSQL - + " where oge.type ='退库单' and oge.subType='盘亏出库' " - + "and "+outEntryPredicate+" and " - + getHandleDeptCodeSql("oge.orgUnitCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - + " and oge.time " + betweenSql + ogeTargetOrgUnitCodeWhereSql; - if(StringUtils.isNotBlank(department)){ - receiveSql += " and oge.orgUnitName = '" + department + "'"; - }else if(!(departments == null || departments.isEmpty())){ - receiveSql += " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("oge.orgUnitName", departments); - } - ResultSet rs4 = objectDao.executeSql(receiveSql); - try { - while(rs4.next()){ - String type = rs4.getString(1); - if("一次性物品".equals(type)){ - Double price = rs4.getDouble(2); - int amount = rs4.getInt("amount"); - String code = rs4.getString(4); - String orgUnitName = rs4.getString(5); - String hospitalDistrict = null; - if(enableMultipleBranchesOfHospital){ - hospitalDistrict = departToBrancheOfHospitalMap == null || departToBrancheOfHospitalMap.isEmpty() || departToBrancheOfHospitalMap.get(orgUnitName) == null?null:departToBrancheOfHospitalMap.get(orgUnitName).getName(); - } - String depart = null; - if(showApplicationDepart){ - depart = orgUnitName; - }else if(nameToBrevityCodeMap.containsKey(orgUnitName)){ - depart = nameToBrevityCodeMap.get(orgUnitName); - } - String whetherToCharge = null; - if(queryWhetherToCharge){ - whetherToCharge = rs4.getString("whetherToCharge"); - } - newMonthReport(code, depart,orgUnitName, "2", "价格统计", getChargeDisposableColumnName(queryWhetherToCharge, whetherToCharge, disposablePriceShowName) , price, list,hospitalDistrict, enableMultipleBranchesOfHospital); - if(enableDiscountPrice){ - newMonthReport(code, depart,orgUnitName,"1", "科室记支","一次性物品记支",price, list,hospitalDistrict, enableMultipleBranchesOfHospital); - } - if(!hideAmountColumn){ - newMonthReport(code, depart,orgUnitName, "3", "数量统计",getChargeDisposableColumnName(queryWhetherToCharge, whetherToCharge, disposableAmountShowName) , amount, list,hospitalDistrict, enableMultipleBranchesOfHospital); - } - } - } - }catch(Exception e){ - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(rs4); - } - } - // 一次性物品装配扣减库存 - { - if(showTotalMoneyOfSciProjectDisposableGoodsInvoiceInAccountingMonthlyReport){ - if(isSupplyRoomUser && (StringUtils.isBlank(tousseType) || TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType))){ - String sql = "select "+ prDepartSql +"'一次性物品' type,(dgi.amount*dgi.fluctuationPrice) price,dgi.amount,pr.orgUnitCoding,pr.orgUnitName " - + dgWhetherToChargeSQL - + "from PackingRecord pr inner join DiposableGoodsItem dgi on pr.id = dgi.packingRecordId " - + diposableGoodsItemLeftJoinDisposableGoodsSQL - + " where " - +packingDisposableGoodsTypePredicate+" and " - + getHandleDeptCodeSql("pr.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - + " and pr.packTime " + betweenSql + prDepartCodingWhereSql + containDiposableGoodsItemSql; - ResultSet rs = objectDao.executeSql(sql); - try { - while(rs.next()){ - String type = rs.getString("type"); - if("一次性物品".equals(type)){ - Double price = rs.getDouble("price"); - int amount = rs.getInt("amount"); - String code = rs.getString("orgUnitCoding"); - String hospitalDistrict = null; - String whetherToCharge = null; - if(queryWhetherToCharge){ - whetherToCharge = rs.getString("whetherToCharge"); - } - newMonthReport(code, "科研物资领用公共部门","科研物资领用公共部门", "2", "价格统计", getChargeDisposableColumnName(queryWhetherToCharge, whetherToCharge, disposablePriceShowName) , price, list,hospitalDistrict, enableMultipleBranchesOfHospital); - if(enableDiscountPrice){ - newMonthReport(code, "科研物资领用公共部门","科研物资领用公共部门","1", "科室记支","一次性物品记支",price, list,hospitalDistrict, enableMultipleBranchesOfHospital); - } - if(!hideAmountColumn){ - newMonthReport(code, "科研物资领用公共部门","科研物资领用公共部门", "3", "数量统计", getChargeDisposableColumnName(queryWhetherToCharge, whetherToCharge, disposableAmountShowName) , amount, list,hospitalDistrict, enableMultipleBranchesOfHospital); - } - } - } - }catch(Exception e){ - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(rs); - } - } - }else{ - if(isSupplyRoomUser && (StringUtils.isBlank(tousseType) || TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType))){ - String sql = "select "+ prDepartSql +"'一次性物品' type,(dgi.amount*dgi.fluctuationPrice) price,dgi.amount,pr.orgUnitCoding,pr.orgUnitName " - + dgWhetherToChargeSQL - + "from PackingRecord pr inner join DiposableGoodsItem dgi on pr.id = dgi.packingRecordId " - + diposableGoodsItemLeftJoinDisposableGoodsSQL - + " where " - +packingDisposableGoodsTypePredicate+" and " - + getHandleDeptCodeSql("pr.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - + " and pr.packTime " + betweenSql + prDepartCodingWhereSql + excludeDiposableGoodsItemSql; - - ResultSet rs = objectDao.executeSql(sql); - try { - while(rs.next()){ - String type = rs.getString("type"); - if("一次性物品".equals(type)){ - Double price = rs.getDouble("price"); - int amount = rs.getInt("amount"); - String code = rs.getString("orgUnitCoding"); - String dept = null; - String orgUnitName = rs.getString("orgUnitName"); - if(showApplicationDepart){ - dept = rs.getString("depart"); - }else if(nameToBrevityCodeMap.containsKey(orgUnitName)){ - dept = nameToBrevityCodeMap.get(orgUnitName); - } - String hospitalDistrict = null; - if(enableMultipleBranchesOfHospital){ - hospitalDistrict = departToBrancheOfHospitalMap == null || departToBrancheOfHospitalMap.isEmpty() || departToBrancheOfHospitalMap.get(orgUnitName) == null ?null:departToBrancheOfHospitalMap.get(orgUnitName).getName(); - } - String whetherToCharge = null; - if(queryWhetherToCharge){ - whetherToCharge = rs.getString("whetherToCharge"); - } - newMonthReport(code, dept,orgUnitName, "2", "价格统计",getChargeDisposableColumnName(queryWhetherToCharge, whetherToCharge, disposablePriceShowName) , price, list,hospitalDistrict, enableMultipleBranchesOfHospital); - if(enableDiscountPrice){ - newMonthReport(code, dept,orgUnitName,"1", "科室记支","一次性物品记支",price, list,hospitalDistrict, enableMultipleBranchesOfHospital); - } - if(!hideAmountColumn){ - newMonthReport(code, dept,orgUnitName, "3", "数量统计",getChargeDisposableColumnName(queryWhetherToCharge, whetherToCharge, disposableAmountShowName) , amount, list,hospitalDistrict, enableMultipleBranchesOfHospital); - } - } - } - }catch(Exception e){ - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(rs); - } - } - } - } - boolean enableToussePointsStatistics = CssdUtils.getSystemSetConfigByNameBool("enableToussePointsStatistics", false); - //器械包(含消毒物品、敷料包等)发货数量统计 - if(!hideAmountColumn && (StringUtils.isBlank(tousseType) || (!"器械材料".equals(tousseType) && !TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType) && !TYPE_AUTO_DEDUCTION.equals(tousseType)))){ - String columnSqlForInvoiceAmountSql = null; - String leftJoinSqlForInvoiceAmountSql = null; - if(dataSoureOfMaterialsCountOfToussesInReports == 3){ - if(enableToussePointsStatistics){ - columnSqlForInvoiceAmountSql = "ii.materialAmount,td.isApplyEntireTousse,td.integral "; - }else{ - columnSqlForInvoiceAmountSql = "ii.materialAmount,td.isApplyEntireTousse"; - } - leftJoinSqlForInvoiceAmountSql = "left join TousseDefinition td on ii.tousseDefinitionId=td.id"; - }else{ - if(enableToussePointsStatistics){ - tousseDefinitionIdMaterialAmountSql = " (select sum(mi.count) materialAmount,td.id,td.tousseType,td.isApplyEntireTousse,td.integral from MaterialInstance mi join TousseDefinition td on mi.tousse_id = td.id group by td.id,td.tousseType,isApplyEntireTousse,td.integral) "; - columnSqlForInvoiceAmountSql = "tdm.materialAmount,tdm.isApplyEntireTousse,tdm.integral "; - }else{ - columnSqlForInvoiceAmountSql = "tdm.materialAmount,tdm.isApplyEntireTousse "; - } - leftJoinSqlForInvoiceAmountSql = " left join " + tousseDefinitionIdMaterialAmountSql + " tdm on tdm.id = ii.tousseDefinitionId "; - } - String invoiceAmountSql = "select "+ iDepartSql +"i.settleAccountsDepartCoding as coding,i.settleAccountsDepart " - + ",ii.amount,ii.tousseType," - + columnSqlForInvoiceAmountSql - + " from Invoice i join InvoiceItem ii on i.id = ii.invoice_id " - + leftJoinSqlForInvoiceAmountSql - + " where " - + getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - + " and (ii.amount is not null and ii.amount>0) "// 限制为只查包含器械包(含消毒物品、敷料包等)数量的 - + " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("ii.tousseType", allTousseType) - + " and (i.status ='收货签收' or i.status = '已发货') " + invoiceWheresql + iDepartCodingWhereSql; - //如果为高值耗材处理科室用户,并且启用高值耗材功能,且所选物品类型为全部或高值耗材时,则将高值耗材退货数据也抵冲掉 - if(enableExpensiveGoods && (StringUtils.isBlank(tousseType) || StringUtils.equals(ExpensiveGoods.TYPE_NAME, tousseType))){ - String queryIntegralSql = enableToussePointsStatistics?",0.0 as integral":""; - invoiceAmountSql += " union all (select "+ iDepartSql+"i.settleAccountsDepartCoding coding,i.settleAccountsDepart,-1 * count(egi.id) as amount,'高值耗材' as tousseType," - + " null as materialAmount,null as isApplyEntireTousse " - + queryIntegralSql - + " from ExpensiveGoodsGodownEntry egge join ExpensiveGoodsGodownEntryItem eggei on egge.id=eggei.expensiveGoodsGodownEntry_id " - + " join ExpensiveGoodsInstance egi on egi.id=eggei.expensiveGoodsInstanceId join Invoice i on egi.invoiceId=i.id " - + " where " - + getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - + " and egge.type='退库单' " + expensiveGoodsWheresql + iDepartCodingWhereSql - + " group by "+ iDepartSql +"i.settleAccountsDepartCoding,i.settleAccountsDepart)"; - } - - ResultSet rs2 = objectDao.executeSql(invoiceAmountSql); - try { - while(rs2.next()){ - String code = rs2.getString("coding"); - String dept = null; - String settleAccountsDepart = rs2.getString("settleAccountsDepart"); - if(showApplicationDepart){ - dept = rs2.getString("depart"); - }else if(nameToBrevityCodeMap.containsKey(settleAccountsDepart)){ - dept = nameToBrevityCodeMap.get(settleAccountsDepart); - } - int tousseAmount = ConvertNumber.getNumberIntValue(rs2.getObject("amount"), 0); - String tousseTypeName = rs2.getString("tousseType"); - int materialAmount = rs2.getInt("materialAmount"); - String isApplyEntireTousse = rs2.getString("isApplyEntireTousse"); - Double integral = null; - if(enableToussePointsStatistics && tousseAmount != 0){ - Number integralNum = (Number)rs2.getObject("integral"); - if(integralNum != null){ - integral = integralNum.doubleValue() * tousseAmount; - } - } - int totalMaterialAmount = tousseAmount * materialAmount; - // 如果是消毒物品,用统计数量替换包数量 - if ("消毒物品".equals(tousseTypeName) && Constants.STR_NO.equals(isApplyEntireTousse)) { - if (materialAmount > 0) { - tousseAmount = totalMaterialAmount; - } - }else if(TousseDefinition.PACKAGE_TYPE_CUSTOM.equals(tousseTypeName)&& !showCustonTousseAmount){ - if (materialAmount > 0) { - tousseAmount = totalMaterialAmount; - } - } - String hospitalDistrict = null; - if(enableMultipleBranchesOfHospital){ - hospitalDistrict = departToBrancheOfHospitalMap == null || departToBrancheOfHospitalMap.isEmpty() || departToBrancheOfHospitalMap.get(settleAccountsDepart) == null?null:departToBrancheOfHospitalMap.get(settleAccountsDepart).getName(); - } - if(ExpensiveGoods.TYPE_NAME.equals(tousseTypeName)){ - newMonthReport(code,dept,settleAccountsDepart,"3","数量统计", "高值耗材数量",tousseAmount,list,integral,hospitalDistrict, enableMultipleBranchesOfHospital); - }else{ - newMonthReport(code,dept,settleAccountsDepart,"3","数量统计", insideAmountShowName,tousseAmount,list,integral,hospitalDistrict, enableMultipleBranchesOfHospital); - if(monthReportMaterialAmountOfTousse){ - newMonthReport(code,dept,settleAccountsDepart, "4", "包内材料统计", "包内材料数量", totalMaterialAmount, list,0.0,hospitalDistrict, enableMultipleBranchesOfHospital); - } - } - } - } catch (SQLException e) { - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(rs2); - } - } - final String TYPE_CHARGE = "收费项目"; - if(StringUtils.isBlank(tousseType) || TYPE_CHARGE.equals(tousseType)){ - String chargeDateSql = String.format(" and chargeTime %s ", betweenSql); - String chargeDepartSql = ""; - if(StringUtils.isNotBlank(department)){ - chargeDepartSql = String.format(" and ci.orgUnitName = '%s' ", department); - }else if(!(departments == null || departments.isEmpty())){ - chargeDepartSql += " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("ci.orgUnitName", departments); - } - String sql = String.format("select ci.orgUnitName,ci.orgUnitCode,sum(price) price from ChargeRecordItem ci " - + " inner join ChargeRecord cr on cr.id=ci.chargeRecord_id where 1=1 %s %s %s group by ci.orgUnitName,ci.orgUnitCode", chargeDateSql,chargeDepartSql, crOrgUnitCodeWhereSql); - ResultSet rs5 = null; - try { - rs5 = objectDao.executeSql(sql); - while(rs5.next()){ - Double price = rs5.getDouble("price"); - String orgUnitName = rs5.getString("orgUnitName"); - String dept = null; - if(showApplicationDepart){ - dept = rs5.getString("depart"); - }else if(nameToBrevityCodeMap.containsKey(orgUnitName)){ - dept = nameToBrevityCodeMap.get(orgUnitName); - } - String orgUnitCode = rs5.getString("orgUnitCode"); - String hospitalDistrict = null; - if(enableMultipleBranchesOfHospital){ - hospitalDistrict = departToBrancheOfHospitalMap == null || departToBrancheOfHospitalMap.isEmpty() || departToBrancheOfHospitalMap.get(orgUnitName) == null?null:departToBrancheOfHospitalMap.get(orgUnitName).getName(); - } - newMonthReport(orgUnitCode, dept,orgUnitName, "2", "价格统计", "收费项目总价", price, list,hospitalDistrict, enableMultipleBranchesOfHospital); - } - }catch(Exception e){ - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(rs5); - } - } - return list; + return monthReportHelper.getMonthReportData(startDate, endDate, department, tousseType, disposableGoodsType, showCustonTousseAmount, patternOfReport, departToBrancheOfHospitalMap, filterBrancheOfHospital, hideAmountColumn, showApplicationDepart, invoicePlanDepartCoding, columnConfigOfAccountingInfoMap, queryWhetherToCharge); } - /** - * 查询一次性物品是否收费时 列表后面需显示是否可收费 - * @param queryWhetherToCharge 查询是否收费 - * @param whetherToCharge 是否收费 - * @param oldName 旧列名 - * @return 添加是否收费后的列名 - */ - private String getChargeDisposableColumnName(boolean queryWhetherToCharge, String whetherToCharge, String oldName){ - if(!queryWhetherToCharge){ - return oldName; - } - if("是".equals(whetherToCharge)){ - return oldName + "_可收费"; - }else{ - return oldName + "_不可收费"; - } - } - //------------------------------------------个性化核算月报(按一次性物品类型拆分一次性物品,添加一次性物品合计)查询 start----------------------------------- @Override public List getMonthReportDataGroupByDisposableGoodsType(String startDate,String endDate, String department,String tousseType,String disposableGoodsType,Boolean showCustonTousseAmount){ - boolean enableDiscountPrice = CssdUtils.getSystemSetConfigByNameBool("enableDiscountPrice"); - //是否启用包内材料统计列 - boolean monthReportMaterialAmountOfTousse = CssdUtils.getSystemSetConfigByNameBool("monthReportMaterialAmountOfTousse"); - SupplyRoomConfig supplyRoomConfig = supplyRoomConfigManager.getSystemParamsObj(); - final String TYPE_AUTO_DEDUCTION = "自动扣减物品"; - //当前用户是否为供应室(包含一二级供应室)用户 - boolean isSupplyRoomUser = supplyRoomConfigManager.isSupplyRoomUser(); - if(!isSupplyRoomUser){ - department = AcegiHelper.getCurrentOrgUnitName(); - } - LoginUserData user = AcegiHelper.getLoginUser(); - String orgUnitCoding = null; - if (user != null){ - orgUnitCoding = user.getOrgUnitCodingFromSupplyRoomConfig(); - } - boolean isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser = false; - if (isSupplyRoomUser || supplyRoomConfigManager.isExpensiveGoodsSupplyRoomUser()) { - isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser = true; - } - List list = new ArrayList(); - String invoiceWheresql = "" ; - startDate += " 00:00:00"; - endDate += " 23:59:59"; - String betweenSql = "between " - + dateQueryAdapter.dateConverAdapter2(startDate, - "yyyy-mm-dd HH24:MI:SS") - + " and " + dateQueryAdapter.dateConverAdapter2(endDate, - "yyyy-mm-dd HH24:MI:SS") + " "; - if(StringUtils.isNotBlank(startDate) && StringUtils.isNotBlank(endDate)){ - invoiceWheresql = " and i.sendTime " + betweenSql; - } - String receiveDepartWhereSql = ""; - if(StringUtils.isNotBlank(department)){ - invoiceWheresql += " and i.settleAccountsDepart = '"+department+"'"; - receiveDepartWhereSql = String.format(" and r.depart='%s'", department); - } - String invoiceItemDisposableGoodsTypePredicate = "1=1"; - String disposableGoodsInvoiceAmountPredicate = " ii.diposable='是' "; - String returnGoodsItemPredicate = "1=1"; - String receiveRecordItemPredicate = "1=1"; - String outEntryPredicate = "1=1"; - String packingDisposableGoodsTypePredicate = "1=1"; - List allTousseType = getTousseTypes(tousseType); - String disposableGoodsIdSql = ""; - StringBuffer leftJoinDisposableGoods = new StringBuffer(50); - leftJoinDisposableGoods.append(" left join ").append(DisposableGoods.class.getSimpleName()); - int dataSoureOfMaterialsCountOfToussesInReports = CssdUtils.getSystemSetConfigByNameInt("dataSoureOfMaterialsCountOfToussesInReports", 3); - //包定义id跟材料数量的临时表 - String tousseDefinitionIdMaterialAmountSql = " (select sum(mi.count) materialAmount,td.id,td.tousseType,td.isApplyEntireTousse from MaterialInstance mi join TousseDefinition td on mi.tousse_id = td.id group by td.id,td.tousseType,isApplyEntireTousse) "; - if(StringUtils.isNotBlank(disposableGoodsType)){ - disposableGoodsIdSql = String.format(" select id from DisposableGoods where type='%s' ", disposableGoodsType); - invoiceItemDisposableGoodsTypePredicate = String.format(" (ii.diposable='否' or ii.disposableGoodsId in(%s)) ", disposableGoodsIdSql); - disposableGoodsInvoiceAmountPredicate = String.format(" (ii.diposable='是' and ii.disposableGoodsId in(%s)) ", disposableGoodsIdSql); - returnGoodsItemPredicate = String.format(" (r.type!='一次性物品' or i.disposableGoodsId in(%s)) ", disposableGoodsIdSql); - outEntryPredicate = String.format(" (ged.disposableGoodsID in(%s)) ", disposableGoodsIdSql); - packingDisposableGoodsTypePredicate = String.format(" (dgi.disposableGoodsID in(%s)) ", disposableGoodsIdSql); - } - if(StringUtils.isBlank(tousseType) || !"器械材料".equals(tousseType)){ - //物品类型sql - String tousseTypeInvoiceSql = ""; - String tousseTypeReturnSql = ""; - if(StringUtils.isNotBlank(tousseType)){ - if(TYPE_AUTO_DEDUCTION.equals(tousseType)){ - tousseTypeInvoiceSql = String.format(" and ii.type='%s' ", InvoiceItem.TYPE_AUTO_DEDUCTION); - }else{ - tousseTypeInvoiceSql = String.format(" and %s ", SqlUtils.getStringFieldInLargeCollectionsPredicate("ii.tousseType", allTousseType)); - } - - if(TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType)){ - tousseTypeReturnSql = " and i.disposableGoodsId in (select id from DisposableGoods) "; - }else{ - tousseTypeReturnSql = String.format(" and i.tousseDefinition_id in (select id from TousseDefinition where %s) ", SqlUtils.getStringFieldInLargeCollectionsPredicate("tousseType", allTousseType)); - } - }else{ - tousseTypeInvoiceSql = String.format(" and (ii.type='%s' or ii.diposable='是' or (ii.diposable='否' and %s))", InvoiceItem.TYPE_AUTO_DEDUCTION,SqlUtils.getStringFieldInLargeCollectionsPredicate("ii.tousseType", allTousseType)); - tousseTypeReturnSql = String.format(" and (i.disposableGoodsId in (select id from DisposableGoods) or i.tousseDefinition_id in (select id from TousseDefinition where %s) )",SqlUtils.getStringFieldInLargeCollectionsPredicate("tousseType", allTousseType)); - } - - String invoicePriceSql = "select i.settleAccountsDepartCoding as coding,i.settleAccountsDepart " - + "as depart,sum(ii.settlementPrice) as price,ii.diposable,sum(ii.settlementDiscountPrice) as settlementDiscountPrice,ii.tousseType,dg.type from " + Invoice.class.getSimpleName() + " i," - + InvoiceItem.class.getSimpleName() + " ii left join "+ DisposableGoods.class.getSimpleName() +" dg on dg.id=ii.disposableGoodsId where i.id = ii.invoice_id and "+invoiceItemDisposableGoodsTypePredicate+" and " - + getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - + " and (i.status ='收货签收' or " - + "i.status = '已发货') " + invoiceWheresql + tousseTypeInvoiceSql + " group by i.settleAccountsDepartCoding,i.settleAccountsDepart,ii.diposable,ii.tousseType,dg.type"; - - ResultSet rs = objectDao.executeSql(invoicePriceSql); - try { - Map codeAndTypeMap = new HashMap(); - while(rs.next()){ - String code = rs.getString("coding"); - String dept = rs.getString("depart"); - Double price = rs.getDouble("price"); - String diposable = rs.getString("diposable"); - Double discountPrice = rs.getDouble("settlementDiscountPrice"); - String tType = rs.getString("tousseType"); - String columnName = ""; - String costColumn = ""; - String type = ""; - if("是".equals(diposable)){ - discountPrice = price;//一次性物品发货项中目前还没有记录折扣价 - String key = new StringBuffer(code).append(",a").append(rs.getString("type")).toString(); - if(codeAndTypeMap.containsKey(key)){ - MonthReportBean mrb = codeAndTypeMap.get(key); - mrb.setMoney(MathTools.add(mrb.getMoney(), price).doubleValue()); - }else{ - MonthReportBean mrb = new MonthReportBean(); - mrb.setRowNum(code); - mrb.setDepartment(dept); - mrb.setMoney(price); - codeAndTypeMap.put(key, mrb); - } - continue; - } - if(ExpensiveGoods.TYPE_NAME.equals(tType)){ - columnName = "c高值耗材总价"; - }else{ - columnName = "c器械包总价"; - } - newMonthReport(code, null,dept,"2", "价格统计",columnName,price, list, null, null); - } - if(codeAndTypeMap.size() > 0){ - Map departSum = new HashMap(); - for (Entry entry : codeAndTypeMap.entrySet()) { - String key = entry.getKey(); - MonthReportBean item = entry.getValue(); - String code = item.getRowNum(); - Double price = item.getMoney(); - newMonthReport(code, null,item.getDepartment(),"2", "价格统计", key.substring(key.indexOf(",") + 1),price, list, null, null); - if(departSum.containsKey(code)){ - MonthReportBean mrb = departSum.get(code); - mrb.setMoney(MathTools.add(mrb.getMoney(), price).doubleValue()); - }else{ - departSum.put(code, item); - } - } - if(departSum.size() > 0){ - for (Entry entry : departSum.entrySet()) { - MonthReportBean item = entry.getValue(); - newMonthReportForGuiGang(item.getRowNum(), item.getDepartment(),"2", "价格统计","b一次性物品合计",item.getMoney(), list); - } - } - } - } catch (SQLException e) { - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(rs); - } - if(!TYPE_AUTO_DEDUCTION.equals(tousseType)){ - String queryColumnSql = null; - String leftJoinSqlForReturnSql = null; - if(dataSoureOfMaterialsCountOfToussesInReports == 3){ - queryColumnSql = "td.tousseType,i.materialAmountAtThatTime materialAmount,td.isApplyEntireTousse "; - leftJoinSqlForReturnSql = String.format("left join %s td on td.id=i.tousseDefinition_id", TousseDefinition.class.getSimpleName()); - }else{ - queryColumnSql = "tdm.tousseType,tdm.materialAmount as materialAmount ,tdm.isApplyEntireTousse"; - leftJoinSqlForReturnSql = " left join " + tousseDefinitionIdMaterialAmountSql + " tdm on tdm.id = i.tousseDefinition_id "; - } - //退货统计(器械包或一次性物品) - String returnSql = "select r.type,(-i.settlementPrice),-i.amount,r.settleAccountsDepartCoding departCoding,r.settleAccountsDepart depart," - + queryColumnSql - + ",dg.type dgType from ReturnGoodsRecord r join ReturnGoodsItem i on r.id = i.returnGoodsRecord_ID " - + leftJoinDisposableGoods - + " dg on dg.id=i.disposableGoodsID " - + leftJoinSqlForReturnSql - + " where "+returnGoodsItemPredicate+ tousseTypeReturnSql + " and " - + getHandleDeptCodeSql("r.handleDepartCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - +" and r.returnTime " + betweenSql; - if(StringUtils.isNotBlank(department)){ - returnSql += " and r.settleAccountsDepart = '" + department + "'"; - } - ResultSet rs5 = objectDao.executeSql(returnSql); - try { - Map codeAndTypeMap = new HashMap(); - while(rs5.next()){ - String type = rs5.getString(1); - Double price = rs5.getDouble(2); - int amount = rs5.getInt(3); - String code = rs5.getString(4); - String dept = rs5.getString(5); - String returnTousseType = rs5.getString("tousseType"); - String isApplyEntireTousse = rs5.getString("isApplyEntireTousse"); - - int materialAmount = rs5.getInt("materialAmount"); - Integer totalMaterialAmount = amount * materialAmount; - - // 如果是拆包的消毒物品,用统计数量替换包数量 - if ("消毒物品".equals(returnTousseType) && Constants.STR_NO.equals(isApplyEntireTousse)) { - if (materialAmount > 0) { - amount = totalMaterialAmount; - } - }else if(TousseDefinition.PACKAGE_TYPE_CUSTOM.equals(returnTousseType)&& !showCustonTousseAmount){ - if (materialAmount > 0) { - amount = totalMaterialAmount; - } - } - - if("一次性物品".equals(type)){ - setCodeAndTypeMapData(codeAndTypeMap, code, dept, rs5.getString("dgType"), amount, price); - continue; - } - newMonthReport(code, null,dept, "2", "价格统计", "c器械包总价", price, list, null, null); - newMonthReport(code, null,dept, "3", "数量统计", "c器械包数量", amount, list, null, null); - if(monthReportMaterialAmountOfTousse){ - newMonthReport(code, null,dept, "4", "包内材料统计", "c包内材料数量", totalMaterialAmount, list, null, null); - } - } - addDisposableGoodsData(codeAndTypeMap, list); - }catch(Exception e){ - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(rs5); - } - } - } - - if(StringUtils.isBlank(tousseType) || "器械材料".equals(tousseType)){ - // 材料发货价格 - String materialInvoicePriceSql = "select i.settleAccountsDepartCoding as coding,i.settleAccountsDepart " - + "as depart,sum(ii.settlementPrice) as price from MaterialInvoice i," - + "MaterialInvoiceItem ii where i.id = ii.materialInvoice_id and " - + getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - + " " + invoiceWheresql + " group by i.settleAccountsDepartCoding,i.settleAccountsDepart"; - ResultSet materialInvoicePriceResultSet = objectDao.executeSql(materialInvoicePriceSql); - try { - while(materialInvoicePriceResultSet.next()){ - String code = materialInvoicePriceResultSet.getString(1); - String dept = materialInvoicePriceResultSet.getString(2); - Double price = materialInvoicePriceResultSet.getDouble(3); - String columnName = "c发货材料总价"; - - newMonthReport(code, null,dept,"2", "价格统计",columnName,price, list, null, null); - } - } catch (SQLException e) { - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(materialInvoicePriceResultSet); - } - - // 材料发货数量 - String materialInvoiceAmountSql = "select i.settleAccountsDepartCoding as coding,i.settleAccountsDepart " - + "as depart,mi.amount from MaterialInvoice i inner join MaterialInvoiceItem mi on i.id=mi.materialInvoice_id " - + "where " - + getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - + " and (mi.amount is not null and mi.amount>0) " - + " " + invoiceWheresql; - - ResultSet materialInvoiceAmountResultSet = objectDao.executeSql(materialInvoiceAmountSql); - try { - while(materialInvoiceAmountResultSet.next()){ - String code = materialInvoiceAmountResultSet.getString(1); - String dept = materialInvoiceAmountResultSet.getString(2); - int tousseAmount = materialInvoiceAmountResultSet.getInt(3); - if(tousseAmount > 0){ - newMonthReport(code, null,dept,"3","数量统计", "c发货材料数量",tousseAmount,list, null, null); - } - } - } catch (SQLException e) { - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(materialInvoiceAmountResultSet); - } - String banQuery = " 1 = 0 and "; - String damagedTousseAtCost = supplyRoomConfig.getDamagedTousseAtCost(); - /*if(StringUtils.isBlank(damagedTousseAtCost) || Constants.STR_YES.equals(damagedTousseAtCost)){ - banQuery = ""; - }*/ - if(Constants.STR_YES.equals(damagedTousseAtCost)){ - banQuery = ""; - } - //材料报损统计 - String damageSql = "select i.settleAccountsDepartCoding departCode,i.settleAccountsDepart depart,i.materialName,sum(i.materialCost*i.additionalAmount),sum(i.additionalAmount) " - + " from MaterialErrorDamageDetail i where " + banQuery - + getHandleDeptCodeSql("i.handleDepartCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - + " and i.type = '" - + MaterialErrorDamageDetail.TYPE_DAMAGE + "' and i.additionalTime " - + betweenSql; - - if(StringUtils.isNotBlank(department)){ - damageSql += " and i.settleAccountsDepart = '"+department+"' "; - } - damageSql += " group by i.settleAccountsDepartCoding,i.settleAccountsDepart,i.materialName"; - ResultSet rs33 = objectDao.executeSql(damageSql); - try { - if(rs33 != null){ - while(rs33.next()){ - String code = rs33.getString(1); - String dept = rs33.getString(2); - String materialName = rs33.getString(3); - Double money = rs33.getDouble(4); - int amount = rs33.getInt(5); - - newMonthReport(code, null,dept, "3", "数量统计", "c丢失报损材料数量", amount, list, null, null); - newMonthReport(code, null,dept, "2", "价格统计", "c丢失报损材料总价", money, list, null, null); - } - } - }catch(Exception e){ - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(rs33); - } - - //材料丢失统计 - String recyclingErrorSql = "select r.settleAccountsDepartCoding departCode,r.settleAccountsDepart depart,r.materialName,sum(r.materialCost*r.additionalAmount),sum(r.additionalAmount) " - + " from MaterialErrorDamageDetail r where r.errorType = '缺失' and r.type = '"+MaterialErrorDamageDetail.TYPE_ERROR+"' and r.materialName != '器械包标识牌' " - + " and " - + getHandleDeptCodeSql("r.handleDepartCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - + " and r.additionalTime " + betweenSql; - - if(StringUtils.isNotBlank(department)){ - recyclingErrorSql += " and r.settleAccountsDepart = '"+department+"' "; - } - recyclingErrorSql += " group by r.settleAccountsDepartCoding,r.settleAccountsDepart,r.materialName"; - ResultSet rs3 = objectDao.executeSql(recyclingErrorSql); - try { - if(rs3 != null){ - while(rs3.next()){ - String code = rs3.getString(1); - String dept = rs3.getString(2); - String materialName = rs3.getString(3); - Double money = rs3.getDouble(4); - int amount = rs3.getInt(5); - - newMonthReport(code, null,dept,"3", "数量统计","c丢失报损材料数量",amount, list, null, null); - newMonthReport(code, null,dept,"2", "价格统计","c丢失报损材料总价",money, list, null, null); - } - } - }catch(Exception e){ - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(rs3); - } - - // 材料退货 - String materialReturnSql = "select r.settleAccountsDepartCoding departCoding,r.settleAccountsDepart depart , (-i.settlementPrice),-i.amount " - + "from ReturnMaterialRecord r,ReturnMaterialItem i where r.id = i.returnMaterialRecord_ID" - + " and " - + getHandleDeptCodeSql("r.handleDepartCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - +" and r.returnTime " + betweenSql; - if(StringUtils.isNotBlank(department)){ - materialReturnSql += " and r.settleAccountsDepart = '" + department + "'"; - } - ResultSet materialReturnResultSet = objectDao.executeSql(materialReturnSql); - try { - while(materialReturnResultSet.next()){ - String code = materialReturnResultSet.getString(1); - String dept = materialReturnResultSet.getString(2); - Double price = materialReturnResultSet.getDouble(3); - int amount = materialReturnResultSet.getInt(4); - - newMonthReport(code, null,dept, "2", "价格统计", "c发货材料总价", price, list, null, null); - newMonthReport(code, null,dept, "3", "数量统计", "c发货材料数量", amount, list, null, null); - } - }catch(Exception e){ - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(materialReturnResultSet); - } - } - - if(StringUtils.isBlank(tousseType) || TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType) || TYPE_AUTO_DEDUCTION.equals(tousseType)){ - String tousseTypeSql = ""; - if(TYPE_AUTO_DEDUCTION.equals(tousseType)){ - tousseTypeSql = String.format(" and ii.type='%s' ", InvoiceItem.TYPE_AUTO_DEDUCTION); - } - // 一次性发货数量统计 - String disposableGoodsInvoiceAmountSql = "select i.settleAccountsDepartCoding as coding,i.settleAccountsDepart " - + "as depart,ii.amount,dg.type from Invoice i inner join InvoiceItem ii on i.id = ii.invoice_id " - + leftJoinDisposableGoods - + " dg on dg.id=ii.disposableGoodsId where " - + getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - +tousseTypeSql - +" and "+disposableGoodsInvoiceAmountPredicate - + " and (i.status ='收货签收' or i.status = '已发货') " + invoiceWheresql; - ResultSet disposableGoodsInvoiceAmountResultSet = objectDao.executeSql(disposableGoodsInvoiceAmountSql); - try { - Map codeAndTypeMap = new HashMap(); - while(disposableGoodsInvoiceAmountResultSet.next()){ - String code = disposableGoodsInvoiceAmountResultSet.getString(1); - String dept = disposableGoodsInvoiceAmountResultSet.getString(2); - int diposableAmount = disposableGoodsInvoiceAmountResultSet.getInt(3); - String type = disposableGoodsInvoiceAmountResultSet.getString("type"); - if(diposableAmount > 0){ - String key = new StringBuffer(code).append(",a").append(type).toString(); - if(codeAndTypeMap.containsKey(key)){ - MonthReportBean mrb = codeAndTypeMap.get(key); - mrb.setAmount(MathTools.add(mrb.getAmount(), diposableAmount).intValue()); - }else{ - MonthReportBean mrb = new MonthReportBean(); - mrb.setRowNum(code); - mrb.setDepartment(dept); - mrb.setAmount(diposableAmount); - codeAndTypeMap.put(key, mrb); - } - } - } - if(codeAndTypeMap.size() > 0){ - Map departSum = new HashMap(); - for (Entry entry : codeAndTypeMap.entrySet()) { - String key = entry.getKey(); - MonthReportBean item = entry.getValue(); - String code = item.getRowNum(); - int amount = item.getAmount(); - newMonthReport(code, null,item.getDepartment(),"3", "数量统计", key.substring(key.indexOf(",") + 1),amount, list, null, null); - if(departSum.containsKey(code)){ - MonthReportBean mrb = departSum.get(code); - mrb.setAmount(MathTools.add(mrb.getAmount(), amount).intValue()); - }else{ - departSum.put(code, item); - } - } - if(departSum.size() > 0){ - for (Entry entry : departSum.entrySet()) { - MonthReportBean item = entry.getValue(); - newMonthReportForGuiGang(item.getRowNum(), item.getDepartment(),"3", "数量统计","b一次性物品合计",item.getAmount(), list); - } - } - } - } catch (SQLException e) { - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(disposableGoodsInvoiceAmountResultSet); - } - - } - SupplyRoomConfig config = supplyRoomConfigManager.getFirstSupplyRoomConfig(); - if(isSupplyRoomUser && (StringUtils.isBlank(tousseType) || "器械材料".equals(tousseType) || TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType) || TYPE_AUTO_DEDUCTION.equals(tousseType))){ - if("器械材料".equals(tousseType)){ - receiveRecordItemPredicate = String.format(" (i.type!='一次性物品') "); - }else if(TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType)){ - if(StringUtils.isNotBlank(disposableGoodsType)){ - receiveRecordItemPredicate = String.format(" (i.type='一次性物品' and i.disposableGoodsId in(%s)) ", disposableGoodsIdSql); - } - }else{ - if(StringUtils.isNotBlank(disposableGoodsType)){ - receiveRecordItemPredicate = String.format(" (i.type!='一次性物品' or i.disposableGoodsId in(%s)) ", disposableGoodsIdSql); - } - } - String tousseTypeSql = ""; - if(TYPE_AUTO_DEDUCTION.equals(tousseType)){ - tousseTypeSql = String.format(" and r.type='%s' ", InvoiceItem.TYPE_AUTO_DEDUCTION); - } - //供应室领用(器械材料与一次性物品) - String receiveSql = "select i.type,(i.amount*i.price) price,i.amount,r.departcoding,dg.type dgType " - + "from ReceiveRecord r,ReceiveRecordItem i" - + leftJoinDisposableGoods - + " dg on dg.id = i.disposableGoodsId where r.id = i.receiverecord_id " - +tousseTypeSql - + "and "+receiveRecordItemPredicate + receiveDepartWhereSql + " and r.time " + betweenSql; - - ResultSet rs4 = objectDao.executeSql(receiveSql); - try { - Map codeAndTypeMap = new HashMap(); - String orgUnitName = config.getOrgUnitName();//为什么要用这个? - while(rs4.next()){ - String type = rs4.getString("type"); - Double price = rs4.getDouble("price"); - int amount = rs4.getInt("amount"); - String code = rs4.getString("departcoding"); - String dgType = rs4.getString("dgType"); - if("一次性物品".equals(type)){ - setCodeAndTypeMapData(codeAndTypeMap, code, orgUnitName, rs4.getString("dgType"), amount, price); - continue; - } - newMonthReport(code, null,config.getOrgUnitName(), "2", "价格统计", "c发货材料总价", price, list, null, null); - newMonthReport(code, null,config.getOrgUnitName(), "3", "数量统计", "c发货材料数量", amount, list, null, null); - } - addDisposableGoodsData(codeAndTypeMap, list); - }catch(Exception e){ - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(rs4); - } - } - // 一次性物品,调拨出库 - if(isSupplyRoomUser && (StringUtils.isBlank(tousseType) || TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType))){ - //供应室领用(器械材料与一次性物品) - String receiveSql = "select '一次性物品' type,(ged.amount*ged.price) price,ged.amount,oge.targetOrgUnitCode,oge.targetOrgUnitName,dg.type dgType " - + "from GodownEntry oge inner join GodownEntryDiposableGoodsItem ged on oge.id = ged.godownEntryID " - + leftJoinDisposableGoods - + " dg on dg.id=ged.disposableGoodsID where oge.type ='退库单' and oge.subType='调拨出库' " - + "and "+outEntryPredicate+" and " - + getHandleDeptCodeSql("oge.orgUnitCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - + SqlUtils.getFiledWhereSql("oge.targetOrgUnitName", department, 40) +" and oge.time " + betweenSql; - - ResultSet rs4 = objectDao.executeSql(receiveSql); - try { - Map codeAndTypeMap = new HashMap(); - while(rs4.next()){ - setCodeAndTypeMapData(codeAndTypeMap, rs4.getString("targetOrgUnitCode"), rs4.getString("targetOrgUnitName"), rs4.getString("dgType"), rs4.getInt("amount"), rs4.getDouble("price")); - } - addDisposableGoodsData(codeAndTypeMap, list); - }catch(Exception e){ - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(rs4); - } - } - // 一次性物品,盘亏出库 - if(isSupplyRoomUser && (StringUtils.isBlank(tousseType) || TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType))){ - //供应室领用(器械材料与一次性物品) - String receiveSql = "select (ged.amount*ged.price) price,ged.amount,oge.orgUnitCode,oge.orgUnitName,dg.type dgType" - + " from GodownEntry oge inner join GodownEntryDiposableGoodsItem ged on oge.id = ged.godownEntryID " - + leftJoinDisposableGoods - + " dg on dg.id=ged.disposableGoodsID where oge.type ='退库单' and oge.subType='盘亏出库' " - + "and "+outEntryPredicate+" and " - + getHandleDeptCodeSql("oge.orgUnitCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - + SqlUtils.getFiledWhereSql("oge.orgUnitName", department, 30)+" and oge.time " + betweenSql; - - ResultSet rs4 = objectDao.executeSql(receiveSql); - try { - Map codeAndTypeMap = new HashMap(); - while(rs4.next()){ - setCodeAndTypeMapData(codeAndTypeMap, rs4.getString("orgUnitCode"), rs4.getString("orgUnitName"), rs4.getString("dgType"), rs4.getInt("amount"), rs4.getDouble("price")); - } - addDisposableGoodsData(codeAndTypeMap, list); - }catch(Exception e){ - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(rs4); - } - } - // 一次性物品装配扣减库存 - { - if(isSupplyRoomUser && (StringUtils.isBlank(tousseType) || TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType))){ - String sql = "select (dgi.amount*dgi.fluctuationPrice) price,dgi.amount,pr.orgUnitCoding,pr.orgUnitName,dg.type dgType " - + "from PackingRecord pr inner join DiposableGoodsItem dgi on pr.id = dgi.packingRecordId " - + leftJoinDisposableGoods - + " dg on dg.id=dgi.disposableGoodsID where " - +packingDisposableGoodsTypePredicate+" and " - + getHandleDeptCodeSql("pr.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - + SqlUtils.getFiledWhereSql("pr.orgUnitName", department, 35) + " and pr.packTime " + betweenSql; - - ResultSet rs = objectDao.executeSql(sql); - try { - Map codeAndTypeMap = new HashMap(); - while(rs.next()){ - setCodeAndTypeMapData(codeAndTypeMap, rs.getString("orgUnitCoding"), rs.getString("orgUnitName"), rs.getString("dgType"), rs.getInt("amount"), rs.getDouble("price")); - } - addDisposableGoodsData(codeAndTypeMap, list); - }catch(Exception e){ - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(rs); - } - } - } - - //器械包(含消毒物品、敷料包等)发货数量统计 - if(StringUtils.isBlank(tousseType) || (!"器械材料".equals(tousseType) && !TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType) && !TYPE_AUTO_DEDUCTION.equals(tousseType))){ - String columnSqlForInvoiceAmountSql = null; - String leftJoinSqlForInvoiceAmountSql = null; - if(dataSoureOfMaterialsCountOfToussesInReports == 3){ - columnSqlForInvoiceAmountSql = "ii.materialAmount,td.isApplyEntireTousse"; - leftJoinSqlForInvoiceAmountSql = String.format("left join %s td on ii.tousseDefinitionId=td.id", TousseDefinition.class.getSimpleName()); - }else{ - columnSqlForInvoiceAmountSql = "tdm.materialAmount,tdm.isApplyEntireTousse "; - leftJoinSqlForInvoiceAmountSql = " left join " + tousseDefinitionIdMaterialAmountSql + " tdm on tdm.id = ii.tousseDefinitionId "; - } - String invoiceAmountSql = "select i.settleAccountsDepartCoding as coding,i.settleAccountsDepart " - + "as depart,ii.amount,ii.tousseType," - + columnSqlForInvoiceAmountSql - + " from Invoice i join InvoiceItem ii on i.id = ii.invoice_id " - + leftJoinSqlForInvoiceAmountSql - + " where " - + getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - + SqlUtils.getFiledWhereSql("i.settleAccountsDepart", department, 45) - + " and (ii.amount is not null and ii.amount>0) "// 限制为只查包含器械包(含消毒物品、敷料包等)数量的 - + " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("ii.tousseType", allTousseType) - + " and (i.status ='收货签收' or i.status = '已发货') " + invoiceWheresql; - - ResultSet rs2 = objectDao.executeSql(invoiceAmountSql); - try { - while(rs2.next()){ - String code = rs2.getString(1); - String dept = rs2.getString(2); - int tousseAmount = rs2.getInt(3); - String tousseTypeName = rs2.getString(4); - int materialAmount = rs2.getInt("materialAmount"); - String isApplyEntireTousse = rs2.getString("isApplyEntireTousse"); - int totalMaterialAmount = tousseAmount * materialAmount; - // 如果是消毒物品,用统计数量替换包数量 - if ("消毒物品".equals(tousseTypeName) && Constants.STR_NO.equals(isApplyEntireTousse)) { - if (materialAmount > 0) { - tousseAmount = totalMaterialAmount; - } - }else if(TousseDefinition.PACKAGE_TYPE_CUSTOM.equals(tousseTypeName)&& !showCustonTousseAmount){ - if (materialAmount > 0) { - tousseAmount = totalMaterialAmount; - } - } - newMonthReport(code, null,dept,"3","数量统计", "c器械包数量",tousseAmount,list, null, null); - if(monthReportMaterialAmountOfTousse){ - newMonthReport(code, null,dept, "4", "包内材料统计", "c包内材料数量", totalMaterialAmount, list, null, null); - } - } - } catch (SQLException e) { - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(rs2); - } - } - final String TYPE_CHARGE = "收费项目"; - if(StringUtils.isBlank(tousseType) || TYPE_CHARGE.equals(tousseType)){ - String chargeDateSql = String.format(" and chargeTime %s ", betweenSql); - String chargeDepartSql = ""; - if(StringUtils.isNotBlank(department)){ - chargeDepartSql = String.format(" and ci.orgUnitName = '%s' ", department); - } - String sql = String.format("select ci.orgUnitName,ci.orgUnitCode,sum(price) price from ChargeRecordItem ci " - + " inner join ChargeRecord cr on cr.id=ci.chargeRecord_id where 1=1 %s %s group by ci.orgUnitName,ci.orgUnitCode", chargeDateSql,chargeDepartSql); - ResultSet rs5 = null; - try { - rs5 = objectDao.executeSql(sql); - while(rs5.next()){ - Double price = rs5.getDouble("price"); - String orgUnitName = rs5.getString("orgUnitName"); - String orgUnitCode = rs5.getString("orgUnitCode"); - newMonthReport(orgUnitCode, null,orgUnitName, "2", "价格统计", "c收费项目总价", price, list, null, null); - } - }catch(Exception e){ - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(rs5); - } - } - return list; + return monthReportGroupByDisposableGoodsTypeHelper.getMonthReportDataGroupByDisposableGoodsType(startDate, endDate, department, tousseType, disposableGoodsType, showCustonTousseAmount); } - /** - * 添加一次性物品数据(包括各类型数量、价格和所有一次性物品的总数量和总价格) - * @param codeAndTypeMap <科室编码 + "," + a +一次物品类型, MonthReportBean> - * @param list List - */ - private void addDisposableGoodsData(Map codeAndTypeMap, List list){ - if(codeAndTypeMap.size() > 0){ - Map departSum = new HashMap();//一次性物品合计数据 - //添加一次性物品各类型数据 - for (Entry entry : codeAndTypeMap.entrySet()) { - String key = entry.getKey();//科室编码 + , + a +一次物品类型(a。b。c用于报表列排序) - MonthReportBean item = entry.getValue(); - String code = item.getRowNum(); - String dept = item.getDepartment(); - Double price = item.getMoney(); - Integer amount = item.getAmount(); - String columnName = key.substring(key.indexOf(",") + 1);//a +一次物品类型 - newMonthReport(code, null,dept, "2", "价格统计", columnName, price, list, null, null); - newMonthReport(code, null,dept,"3", "数量统计", columnName, amount, list, null, null); - if(departSum.containsKey(code)){//计算合计 - MonthReportBean mrb = departSum.get(code); - mrb.setAmount(MathTools.add(mrb.getAmount(), amount).intValue()); - mrb.setMoney(MathTools.add(mrb.getMoney(), price).doubleValue()); - }else{ - departSum.put(code, item); - } - } - //添加一次性物品合计 - if(departSum.size() > 0){ - for (Entry entry : departSum.entrySet()) { - MonthReportBean item = entry.getValue(); - newMonthReportForGuiGang(item.getRowNum(), item.getDepartment(), "2", "价格统计", "b一次性物品合计", item.getMoney(), list); - newMonthReportForGuiGang(item.getRowNum(), item.getDepartment(),"3", "数量统计","b一次性物品合计",item.getAmount(), list); - } - } - } - } - /** - * 贵港专用的创建MonthReport,用于合计时减去一次性物品合计 - * @param code 部门编码 - * @param dept 部门名称 - * @param columnNum 列所属的title位置 - * @param columnTitle 列标题 - * @param columnName 列名 - * @param money 价格 - * @param list list - */ - private void newMonthReportForGuiGang(String code, String dept, - String columnNum, String columnTitle, String columnName, - Double money,List list) { - MonthReportBean bean = new MonthReportBean(); - bean.setSumOfDisposableGoods(money); - bean.setRowNum(code); - bean.setDepartment(dept); - bean.setColumnNum(columnNum); - bean.setColumnTitle(columnTitle); - bean.setColumnName(columnName); - bean.setMoney(money); - list.add(bean); - } - /** - * 贵港专用的创建MonthReport,用于合计时减去一次性物品合计 - * @param code 部门编码 - * @param dept 部门名称 - * @param columnNum 列所属的title位置 - * @param columnTitle 列标题 - * @param columnName 列名 - * @param money 价格 - * @param list list - */ - private void newMonthReportForGuiGang(String code, String dept, - String columnNum, String columnTitle, String columnName, - Integer amount,List list) { - MonthReportBean bean = new MonthReportBean(); - bean.setSumOfDisposableGoodsAmount(amount); - bean.setRowNum(code); - bean.setDepartment(dept); - bean.setColumnNum(columnNum); - bean.setColumnTitle(columnTitle); - bean.setColumnName(columnName); - bean.setAmount(amount); - list.add(bean); - } - //------------------------------------------个性化核算月报(按一次性物品类型拆分一次性物品,添加一次性物品合计)查询 end----------------------------------- - //------------------------------------------按灭菌方式拆分器械包列,个性化核算报表 start----------------------------------- @Override public List getMonthReportDataGroupBySterilizationMode(String startDate,String endDate, String department,String tousseType,String disposableGoodsType,Boolean showCustonTousseAmount){ - boolean enableDiscountPrice = CssdUtils.getSystemSetConfigByNameBool("enableDiscountPrice"); - //是否启用包内材料统计列 - boolean monthReportMaterialAmountOfTousse = CssdUtils.getSystemSetConfigByNameBool("monthReportMaterialAmountOfTousse"); - SupplyRoomConfig supplyRoomConfig = supplyRoomConfigManager.getSystemParamsObj(); - final String TYPE_AUTO_DEDUCTION = "自动扣减物品"; - //SupplyRoomConfig firstSupplyRoomConfig = supplyRoomConfigManager.getFirstSupplyRoomConfig(); - //当前用户是否为供应室(包含一二级供应室)用户 - boolean isSupplyRoomUser = supplyRoomConfigManager.isSupplyRoomUser(); - if(!isSupplyRoomUser){ - department = AcegiHelper.getCurrentOrgUnitName(); - } - LoginUserData user = AcegiHelper.getLoginUser(); - String orgUnitCoding = null; - if (user != null){ - orgUnitCoding = user.getOrgUnitCodingFromSupplyRoomConfig(); - } - boolean isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser = false; - if (isSupplyRoomUser || supplyRoomConfigManager.isExpensiveGoodsSupplyRoomUser()) { - isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser = true; - } - List list = new ArrayList(); - String invoiceWheresql = "" ; - startDate += " 00:00:00"; - endDate += " 23:59:59"; - String betweenSql = "between " - + dateQueryAdapter.dateConverAdapter2(startDate, - "yyyy-mm-dd HH24:MI:SS") - + " and " + dateQueryAdapter.dateConverAdapter2(endDate, - "yyyy-mm-dd HH24:MI:SS") + " "; - if(StringUtils.isNotBlank(startDate) && StringUtils.isNotBlank(endDate)){ - invoiceWheresql = " and i.sendTime " + betweenSql; - } - String receiveDepartWhereSql = ""; - if(StringUtils.isNotBlank(department)){ - invoiceWheresql += " and i.settleAccountsDepart = '"+department+"'"; - receiveDepartWhereSql = String.format(" and r.depart='%s'", department); - } - String invoiceItemDisposableGoodsTypePredicate = "1=1"; - String disposableGoodsInvoiceAmountPredicate = " ii.diposable='是' "; - String returnGoodsItemPredicate = "1=1"; - String receiveRecordItemPredicate = "1=1"; - String outEntryPredicate = "1=1"; - String packingDisposableGoodsTypePredicate = "1=1"; - List allTousseType = getTousseTypes(tousseType); - String disposableGoodsIdSql = ""; - //获取灭菌程序对应灭菌方式的map - Map sterilisationAndSterilizationModeMap = sterilisationManager.getSterilisationAndSterilizationMode(); - for (Entry entry : sterilisationAndSterilizationModeMap.entrySet()) { - entry.setValue(new StringBuffer(15).append("a").append(entry.getValue()).append("物品").toString()); - } - StringBuffer leftJonsTousseDefinition = new StringBuffer(35).append(" left join ") - .append(TousseDefinition.class.getSimpleName()).append(" td on "); - int dataSoureOfMaterialsCountOfToussesInReports = CssdUtils.getSystemSetConfigByNameInt("dataSoureOfMaterialsCountOfToussesInReports", 3); - //包定义id跟材料数量的临时表 - String tousseDefinitionIdMaterialAmountSql = " (select sum(mi.count) materialAmount,td.id,td.tousseType,td.isApplyEntireTousse from MaterialInstance mi join TousseDefinition td on mi.tousse_id = td.id group by td.id,td.tousseType,isApplyEntireTousse) "; - if(StringUtils.isNotBlank(disposableGoodsType)){ - disposableGoodsIdSql = String.format(" select id from DisposableGoods where type='%s' ", disposableGoodsType); - invoiceItemDisposableGoodsTypePredicate = String.format(" (ii.diposable='否' or ii.disposableGoodsId in(%s)) ", disposableGoodsIdSql); - disposableGoodsInvoiceAmountPredicate = String.format(" (ii.diposable='是' and ii.disposableGoodsId in(%s)) ", disposableGoodsIdSql); - returnGoodsItemPredicate = String.format(" (r.type!='一次性物品' or i.disposableGoodsId in(%s)) ", disposableGoodsIdSql); - outEntryPredicate = String.format(" (ged.disposableGoodsID in(%s)) ", disposableGoodsIdSql); - packingDisposableGoodsTypePredicate = String.format(" (dgi.disposableGoodsID in(%s)) ", disposableGoodsIdSql); - } - if(StringUtils.isBlank(tousseType) || !"器械材料".equals(tousseType)){ - //物品类型sql - String tousseTypeInvoiceSql = ""; - String tousseTypeReturnSql = ""; - if(StringUtils.isNotBlank(tousseType)){ - if(TYPE_AUTO_DEDUCTION.equals(tousseType)){ - tousseTypeInvoiceSql = String.format(" and ii.type='%s' ", InvoiceItem.TYPE_AUTO_DEDUCTION); - }else{ - tousseTypeInvoiceSql = String.format(" and %s ", SqlUtils.getStringFieldInLargeCollectionsPredicate("ii.tousseType", allTousseType)); - } - - if(TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType)){ - tousseTypeReturnSql = " and i.disposableGoodsId in (select id from DisposableGoods) "; - }else{ - tousseTypeReturnSql = String.format(" and i.tousseDefinition_id in (select id from TousseDefinition where %s) ", SqlUtils.getStringFieldInLargeCollectionsPredicate("tousseType", allTousseType)); - } - }else{ - tousseTypeInvoiceSql = String.format(" and (ii.type='%s' or ii.diposable='是' or (ii.diposable='否' and %s))", InvoiceItem.TYPE_AUTO_DEDUCTION,SqlUtils.getStringFieldInLargeCollectionsPredicate("ii.tousseType", allTousseType)); - tousseTypeReturnSql = String.format(" and (i.disposableGoodsId in (select id from DisposableGoods) or i.tousseDefinition_id in (select id from TousseDefinition where %s) )",SqlUtils.getStringFieldInLargeCollectionsPredicate("tousseType", allTousseType)); - } - - String invoicePriceSql = "select i.settleAccountsDepartCoding as coding,i.settleAccountsDepart " - + "as depart,sum(ii.settlementPrice) as price,ii.diposable,sum(ii.settlementDiscountPrice) as settlementDiscountPrice,ii.tousseType,td.sterilingMethod from " + Invoice.class.getSimpleName() + " i," - + InvoiceItem.class.getSimpleName() + " ii "+ leftJonsTousseDefinition +" td.id=ii.tousseDefinitionId where i.id = ii.invoice_id and "+invoiceItemDisposableGoodsTypePredicate+" and " - + getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - + " and (i.status ='收货签收' or " - + "i.status = '已发货') " + invoiceWheresql + tousseTypeInvoiceSql + " group by i.settleAccountsDepartCoding,i.settleAccountsDepart,ii.diposable,ii.tousseType,td.sterilingMethod"; - - ResultSet rs = objectDao.executeSql(invoicePriceSql); - try { - while(rs.next()){ - Double price = rs.getDouble("price"); - String code = rs.getString("coding"); - String dept = rs.getString("depart"); - String diposable = rs.getString("diposable"); - Double discountPrice = rs.getDouble("settlementDiscountPrice"); - String tType = rs.getString("tousseType"); - String sterilingMethod = rs.getString("sterilingMethod"); - String columnName = ""; - if("是".equals(diposable)){ - discountPrice = price;//一次性物品发货项中目前还没有记录折扣价 - newMonthReport(code, null,dept,"3", "价格统计","b一次性物品总价",price, list, null, null); - continue; - } - columnName = getColumnNameBySterilingMethod(sterilisationAndSterilizationModeMap, sterilingMethod); - newMonthReport(code, null,dept,"3", "价格统计",columnName,price, list, null, null); - } - } catch (SQLException e) { - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(rs); - } - if(!TYPE_AUTO_DEDUCTION.equals(tousseType)){ - String queryColumnSql = null; - String leftJoinSqlForReturnSql = null; - if(dataSoureOfMaterialsCountOfToussesInReports == 3){ - queryColumnSql = "td.toussetype,i.materialAmountAtThatTime as materialAmount,td.isApplyEntireTousse"; - leftJoinSqlForReturnSql = ""; - }else{ - queryColumnSql = "tdm.tousseType,tdm.materialAmount as materialAmount,tdm.isApplyEntireTousse"; - leftJoinSqlForReturnSql = " left join " + tousseDefinitionIdMaterialAmountSql + " tdm on tdm.id = i.tousseDefinition_id "; - } - //退货统计(器械包或一次性物品) - String returnSql = "select r.type,(-i.settlementPrice),-i.amount,r.settleAccountsDepartCoding departCoding,r.settleAccountsDepart depart," - + queryColumnSql - + ",td.sterilingMethod from ReturnGoodsRecord r join ReturnGoodsItem i on r.id = i.returnGoodsRecord_ID " - + leftJonsTousseDefinition - + " td.id=i.tousseDefinition_id " - + leftJoinSqlForReturnSql - + " where "+returnGoodsItemPredicate+ tousseTypeReturnSql + " and " - + getHandleDeptCodeSql("r.handleDepartCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - +" and r.returnTime " + betweenSql; - if(StringUtils.isNotBlank(department)){ - returnSql += " and r.settleAccountsDepart = '" + department + "'"; - } - ResultSet rs5 = objectDao.executeSql(returnSql); - try { - while(rs5.next()){ - String type = rs5.getString(1); - Double price = rs5.getDouble(2); - int amount = rs5.getInt(3); - String code = rs5.getString(4); - String dept = rs5.getString(5); - String returnTousseType = rs5.getString("tousseType"); - String isApplyEntireTousse = rs5.getString("isApplyEntireTousse"); - int materialAmount = rs5.getInt("materialAmount"); - int totalMaterialAmount = amount * materialAmount; - String sterilingMethod = rs5.getString("sterilingMethod"); - // 如果是拆包的消毒物品,用统计数量替换包数量 - if ("消毒物品".equals(returnTousseType) && Constants.STR_NO.equals(isApplyEntireTousse)) { - if (materialAmount > 0) { - amount = totalMaterialAmount; - } - }else if(TousseDefinition.PACKAGE_TYPE_CUSTOM.equals(returnTousseType)&& !showCustonTousseAmount){ - if (materialAmount > 0) { - amount = totalMaterialAmount; - } - } - - if("一次性物品".equals(type)){ - newMonthReport(code, null,dept, "3", "价格统计", "b一次性物品总价", price, list, null, null); - newMonthReport(code, null,dept, "2", "数量统计", "b一次性物品数量", amount, list, null, null); - continue; - } - String columnName = getColumnNameBySterilingMethod(sterilisationAndSterilizationModeMap, sterilingMethod); - - newMonthReport(code, null,dept, "3", "价格统计", columnName, price, list, null, null); - newMonthReport(code, null,dept, "2", "数量统计", columnName, amount, list, null, null); - if(monthReportMaterialAmountOfTousse){ - newMonthReport(code, null,dept, "4", "包内材料统计", "b包内材料数量", totalMaterialAmount, list, null, null); - } - } - }catch(Exception e){ - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(rs5); - } - } - } - - if(StringUtils.isBlank(tousseType) || "器械材料".equals(tousseType)){ - // 材料发货价格 - String materialInvoicePriceSql = "select i.settleAccountsDepartCoding as coding,i.settleAccountsDepart " - + "as depart,sum(ii.settlementPrice) as price from MaterialInvoice i," - + "MaterialInvoiceItem ii where i.id = ii.materialInvoice_id and " - + getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - + " " + invoiceWheresql + " group by i.settleAccountsDepartCoding,i.settleAccountsDepart"; - ResultSet materialInvoicePriceResultSet = objectDao.executeSql(materialInvoicePriceSql); - try { - while(materialInvoicePriceResultSet.next()){ - String code = materialInvoicePriceResultSet.getString(1); - String dept = materialInvoicePriceResultSet.getString(2); - Double price = materialInvoicePriceResultSet.getDouble(3); - String columnName = "b发货材料总价"; - - newMonthReport(code, null,dept,"3", "价格统计",columnName,price, list, null, null); - } - } catch (SQLException e) { - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(materialInvoicePriceResultSet); - } - - // 材料发货数量 - String materialInvoiceAmountSql = "select i.settleAccountsDepartCoding as coding,i.settleAccountsDepart " - + "as depart,mi.amount from MaterialInvoice i inner join MaterialInvoiceItem mi on i.id=mi.materialInvoice_id " - + "where " - + getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - + " and (mi.amount is not null and mi.amount>0) " - + " " + invoiceWheresql; - - ResultSet materialInvoiceAmountResultSet = objectDao.executeSql(materialInvoiceAmountSql); - try { - while(materialInvoiceAmountResultSet.next()){ - String code = materialInvoiceAmountResultSet.getString(1); - String dept = materialInvoiceAmountResultSet.getString(2); - int tousseAmount = materialInvoiceAmountResultSet.getInt(3); - if(tousseAmount > 0){ - newMonthReport(code, null,dept,"2","数量统计", "b发货材料数量",tousseAmount,list, null, null); - } - } - } catch (SQLException e) { - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(materialInvoiceAmountResultSet); - } - String banQuery = " 1 = 0 and "; - String damagedTousseAtCost = supplyRoomConfig.getDamagedTousseAtCost(); - if(Constants.STR_YES.equals(damagedTousseAtCost)){ - banQuery = ""; - } - //材料报损统计 - String damageSql = "select i.settleAccountsDepartCoding departCode,i.settleAccountsDepart depart,i.materialName,sum(i.materialCost*i.additionalAmount),sum(i.additionalAmount) " - + " from MaterialErrorDamageDetail i where " + banQuery - + getHandleDeptCodeSql("i.handleDepartCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - + " and i.type = '" - + MaterialErrorDamageDetail.TYPE_DAMAGE + "' and i.additionalTime " - + betweenSql; - - if(StringUtils.isNotBlank(department)){ - damageSql += " and i.settleAccountsDepart = '"+department+"' "; - } - damageSql += " group by i.settleAccountsDepartCoding,i.settleAccountsDepart,i.materialName"; - ResultSet rs33 = objectDao.executeSql(damageSql); - try { - if(rs33 != null){ - while(rs33.next()){ - String code = rs33.getString(1); - String dept = rs33.getString(2); - String materialName = rs33.getString(3); - Double money = rs33.getDouble(4); - int amount = rs33.getInt(5); - - newMonthReport(code, null,dept, "2", "数量统计", "b丢失报损材料数量", amount, list, null, null); - newMonthReport(code, null,dept, "3", "价格统计", "b丢失报损材料总价", money, list, null, null); - } - } - }catch(Exception e){ - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(rs33); - } - - //材料丢失统计 - String recyclingErrorSql = "select r.settleAccountsDepartCoding departCode,r.settleAccountsDepart depart,r.materialName,sum(r.materialCost*r.additionalAmount),sum(r.additionalAmount) " - + " from MaterialErrorDamageDetail r where r.errorType = '缺失' and r.type = '"+MaterialErrorDamageDetail.TYPE_ERROR+"' and r.materialName != '器械包标识牌' " - + " and " - + getHandleDeptCodeSql("r.handleDepartCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - + " and r.additionalTime " + betweenSql; - - if(StringUtils.isNotBlank(department)){ - recyclingErrorSql += " and r.settleAccountsDepart = '"+department+"' "; - } - recyclingErrorSql += " group by r.settleAccountsDepartCoding,r.settleAccountsDepart,r.materialName"; - ResultSet rs3 = objectDao.executeSql(recyclingErrorSql); - try { - if(rs3 != null){ - while(rs3.next()){ - String code = rs3.getString(1); - String dept = rs3.getString(2); - String materialName = rs3.getString(3); - Double money = rs3.getDouble(4); - int amount = rs3.getInt(5); - - newMonthReport(code, null,dept,"2", "数量统计","b丢失报损材料数量",amount, list, null, null); - newMonthReport(code, null,dept,"3", "价格统计","b丢失报损材料总价",money, list, null, null); - } - } - }catch(Exception e){ - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(rs3); - } - - // 材料退货 - String materialReturnSql = "select r.settleAccountsDepartCoding departCoding,r.settleAccountsDepart depart , (-i.settlementPrice),-i.amount " - + "from ReturnMaterialRecord r,ReturnMaterialItem i where r.id = i.returnMaterialRecord_ID" - + " and " - + getHandleDeptCodeSql("r.handleDepartCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - +" and r.returnTime " + betweenSql; - if(StringUtils.isNotBlank(department)){ - materialReturnSql += " and r.settleAccountsDepart = '" + department + "'"; - } - ResultSet materialReturnResultSet = objectDao.executeSql(materialReturnSql); - try { - while(materialReturnResultSet.next()){ - String code = materialReturnResultSet.getString(1); - String dept = materialReturnResultSet.getString(2); - Double price = materialReturnResultSet.getDouble(3); - int amount = materialReturnResultSet.getInt(4); - - newMonthReport(code, null,dept, "3", "价格统计", "b发货材料总价", price, list, null, null); - newMonthReport(code, null,dept, "2", "数量统计", "b发货材料数量", amount, list, null, null); - } - }catch(Exception e){ - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(materialReturnResultSet); - } - } - - if(StringUtils.isBlank(tousseType) || TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType) || TYPE_AUTO_DEDUCTION.equals(tousseType)){ - String tousseTypeSql = ""; - if(TYPE_AUTO_DEDUCTION.equals(tousseType)){ - tousseTypeSql = String.format(" and ii.type='%s' ", InvoiceItem.TYPE_AUTO_DEDUCTION); - } - // 一次性发货数量统计 - String disposableGoodsInvoiceAmountSql = "select i.settleAccountsDepartCoding as coding,i.settleAccountsDepart " - + "as depart,ii.amount from Invoice i inner join InvoiceItem ii on i.id = ii.invoice_id " - + "where " - + getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - +tousseTypeSql - +" and "+disposableGoodsInvoiceAmountPredicate - + " and (i.status ='收货签收' or i.status = '已发货') " + invoiceWheresql; - ResultSet disposableGoodsInvoiceAmountResultSet = objectDao.executeSql(disposableGoodsInvoiceAmountSql); - try { - while(disposableGoodsInvoiceAmountResultSet.next()){ - String code = disposableGoodsInvoiceAmountResultSet.getString(1); - String dept = disposableGoodsInvoiceAmountResultSet.getString(2); - int diposableAmount = disposableGoodsInvoiceAmountResultSet.getInt(3); - if(diposableAmount > 0){ - newMonthReport(code, null,dept,"2","数量统计", "b一次性物品数量",diposableAmount,list, null, null); - } - } - } catch (SQLException e) { - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(disposableGoodsInvoiceAmountResultSet); - } - - } - - if(isSupplyRoomUser && (StringUtils.isBlank(tousseType) || "器械材料".equals(tousseType) || TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType) || TYPE_AUTO_DEDUCTION.equals(tousseType))){ - if("器械材料".equals(tousseType)){ - receiveRecordItemPredicate = String.format(" (i.type!='一次性物品') "); - }else if(TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType)){ - if(StringUtils.isNotBlank(disposableGoodsType)){ - receiveRecordItemPredicate = String.format(" (i.type='一次性物品' and i.disposableGoodsId in(%s)) ", disposableGoodsIdSql); - } - }else{ - if(StringUtils.isNotBlank(disposableGoodsType)){ - receiveRecordItemPredicate = String.format(" (i.type!='一次性物品' or i.disposableGoodsId in(%s)) ", disposableGoodsIdSql); - } - } - String tousseTypeSql = ""; - if(TYPE_AUTO_DEDUCTION.equals(tousseType)){ - tousseTypeSql = String.format(" and r.type='%s' ", InvoiceItem.TYPE_AUTO_DEDUCTION); - } - //供应室领用(器械材料与一次性物品) - String receiveSql = "select i.type,(i.amount*i.price),i.amount,r.departcoding " - + "from ReceiveRecord r,ReceiveRecordItem i where r.id = i.receiverecord_id " - +tousseTypeSql - + "and "+receiveRecordItemPredicate + receiveDepartWhereSql + " and r.time " + betweenSql; - SupplyRoomConfig config = supplyRoomConfigManager.getFirstSupplyRoomConfig(); - ResultSet rs4 = objectDao.executeSql(receiveSql); - try { - while(rs4.next()){ - String type = rs4.getString(1); - Double price = rs4.getDouble(2); - int amount = rs4.getInt(3); - String code = rs4.getString(4); - if("一次性物品".equals(type)){ - newMonthReport(code, null,config.getOrgUnitName(), "3", "价格统计", "b一次性物品总价", price, list, null, null); - newMonthReport(code, null,config.getOrgUnitName(), "2", "数量统计", "b一次性物品数量", amount, list, null, null); - }else{ - newMonthReport(code, null,config.getOrgUnitName(), "3", "价格统计", "b发货材料总价", price, list, null, null); - newMonthReport(code, null,config.getOrgUnitName(), "2", "数量统计", "b发货材料数量", amount, list, null, null); - } - } - }catch(Exception e){ - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(rs4); - } - } - // 一次性物品,调拨出库 - if(isSupplyRoomUser && (StringUtils.isBlank(tousseType) || TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType))){ - //供应室领用(器械材料与一次性物品) - String receiveSql = "select '一次性物品',(ged.amount*ged.price),ged.amount,oge.targetOrgUnitCode,oge.targetOrgUnitName " - + "from GodownEntry oge inner join GodownEntryDiposableGoodsItem ged on oge.id = ged.godownEntryID where oge.type ='退库单' and oge.subType='调拨出库' " - + "and "+outEntryPredicate+" and " - + getHandleDeptCodeSql("oge.orgUnitCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - + SqlUtils.getFiledWhereSql("oge.targetOrgUnitName", department, 40) + " and oge.time " + betweenSql; - - ResultSet rs4 = objectDao.executeSql(receiveSql); - try { - while(rs4.next()){ - String type = rs4.getString(1); - Double price = rs4.getDouble(2); - int amount = rs4.getInt(3); - String code = rs4.getString(4); - String orgUnitName = rs4.getString(5); - if("一次性物品".equals(type)){ - newMonthReport(code, null,orgUnitName, "3", "价格统计", "b一次性物品总价", price, list, null, null); - newMonthReport(code, null,orgUnitName, "2", "数量统计", "b一次性物品数量", amount, list, null, null); - } - } - }catch(Exception e){ - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(rs4); - } - } - // 一次性物品,盘亏出库 - if(isSupplyRoomUser && (StringUtils.isBlank(tousseType) || TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType))){ - //供应室领用(器械材料与一次性物品) - String receiveSql = "select '一次性物品',(ged.amount*ged.price),ged.amount,oge.orgUnitCode,oge.orgUnitName " - + "from GodownEntry oge inner join GodownEntryDiposableGoodsItem ged on oge.id = ged.godownEntryID where oge.type ='退库单' and oge.subType='盘亏出库' " - + "and "+outEntryPredicate+" and " - + getHandleDeptCodeSql("oge.orgUnitCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - + SqlUtils.getFiledWhereSql("oge.orgUnitName", department, 30) + " and oge.time " + betweenSql; - - ResultSet rs4 = objectDao.executeSql(receiveSql); - try { - while(rs4.next()){ - String type = rs4.getString(1); - Double price = rs4.getDouble(2); - int amount = rs4.getInt(3); - String code = rs4.getString(4); - String orgUnitName = rs4.getString(5); - if("一次性物品".equals(type)){ - newMonthReport(code, null,orgUnitName, "3", "价格统计", "b一次性物品总价", price, list, null, null); - newMonthReport(code, null,orgUnitName, "2", "数量统计", "b一次性物品数量", amount, list, null, null); - } - } - }catch(Exception e){ - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(rs4); - } - } - // 一次性物品装配扣减库存 - { - if(isSupplyRoomUser && (StringUtils.isBlank(tousseType) || TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType))){ - String sql = "select '一次性物品',(dgi.amount*dgi.fluctuationPrice),dgi.amount,pr.orgUnitCoding,pr.orgUnitName " - + "from PackingRecord pr inner join DiposableGoodsItem dgi on pr.id = dgi.packingRecordId where " - +packingDisposableGoodsTypePredicate+" and " - + getHandleDeptCodeSql("pr.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - + SqlUtils.getFiledWhereSql("pr.orgUnitName", department, 35) + " and pr.packTime " + betweenSql; - - ResultSet rs = objectDao.executeSql(sql); - try { - while(rs.next()){ - String type = rs.getString(1); - Double price = rs.getDouble(2); - int amount = rs.getInt(3); - String code = rs.getString(4); - String orgUnitName = rs.getString(5); - if("一次性物品".equals(type)){ - newMonthReport(code, null,orgUnitName, "3", "价格统计", "b一次性物品总价", price, list, null, null); - newMonthReport(code, null,orgUnitName, "2", "数量统计", "b一次性物品数量", amount, list, null, null); - } - } - }catch(Exception e){ - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(rs); - } - } - } - - //器械包(含消毒物品、敷料包等)发货数量统计 - if(StringUtils.isBlank(tousseType) || (!"器械材料".equals(tousseType) && !TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType) && !TYPE_AUTO_DEDUCTION.equals(tousseType))){ - String columnSqlForInvoiceAmountSql = null; - String leftJoinSqlForInvoiceAmountSql = null; - if(dataSoureOfMaterialsCountOfToussesInReports == 3){ - columnSqlForInvoiceAmountSql = "ii.materialAmount,td.isApplyEntireTousse"; - leftJoinSqlForInvoiceAmountSql = ""; - }else{ - columnSqlForInvoiceAmountSql = "tdm.materialAmount,tdm.isApplyEntireTousse"; - leftJoinSqlForInvoiceAmountSql = " left join " + tousseDefinitionIdMaterialAmountSql + " tdm on tdm.id = ii.tousseDefinitionId "; - } - String invoiceAmountSql = "select i.settleAccountsDepartCoding as coding,i.settleAccountsDepart " - + "as depart,ii.amount,ii.tousseType," - + columnSqlForInvoiceAmountSql - + ",td.sterilingMethod from Invoice i join InvoiceItem ii on i.id = ii.invoice_id " - + leftJonsTousseDefinition - + " td.id=ii.tousseDefinitionId " - + leftJoinSqlForInvoiceAmountSql - + " where " - + getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - + SqlUtils.getFiledWhereSql("i.settleAccountsDepart", department, 45) - + " and (ii.amount is not null and ii.amount>0) "// 限制为只查包含器械包(含消毒物品、敷料包等)数量的 - + " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("ii.tousseType", allTousseType) - + " and (i.status ='收货签收' or i.status = '已发货') " + invoiceWheresql; - - ResultSet rs2 = objectDao.executeSql(invoiceAmountSql); - try { - while(rs2.next()){ - String code = rs2.getString(1); - String dept = rs2.getString(2); - int tousseAmount = rs2.getInt(3); - String tousseTypeName = rs2.getString(4); - int materialAmount = rs2.getInt("materialAmount"); - String isApplyEntireTousse = rs2.getString("isApplyEntireTousse"); - int totalMaterialAmount = tousseAmount * materialAmount; - String sterilingMethod = rs2.getString("sterilingMethod"); - // 如果是消毒物品,用统计数量替换包数量 - if ("消毒物品".equals(tousseTypeName) && Constants.STR_NO.equals(isApplyEntireTousse)) { - if (materialAmount > 0) { - tousseAmount = totalMaterialAmount; - } - }else if(TousseDefinition.PACKAGE_TYPE_CUSTOM.equals(tousseTypeName)&& !showCustonTousseAmount){ - if (materialAmount > 0) { - tousseAmount = totalMaterialAmount; - } - } - String columnName = getColumnNameBySterilingMethod(sterilisationAndSterilizationModeMap, sterilingMethod); - newMonthReport(code, null,dept,"2","数量统计", columnName,tousseAmount,list, null, null); - if(monthReportMaterialAmountOfTousse){ - newMonthReport(code, null,dept, "4", "包内材料统计", "b包内材料数量", totalMaterialAmount, list, null, null); - } - } - } catch (SQLException e) { - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(rs2); - } - } - final String TYPE_CHARGE = "收费项目"; - if(StringUtils.isBlank(tousseType) || TYPE_CHARGE.equals(tousseType)){ - String chargeDateSql = String.format(" and chargeTime %s ", betweenSql); - String chargeDepartSql = ""; - if(StringUtils.isNotBlank(department)){ - chargeDepartSql = String.format(" and ci.orgUnitName = '%s' ", department); - } - String sql = String.format("select ci.orgUnitName,ci.orgUnitCode,sum(price) price from ChargeRecordItem ci " - + " inner join ChargeRecord cr on cr.id=ci.chargeRecord_id where 1=1 %s %s group by ci.orgUnitName,ci.orgUnitCode", chargeDateSql,chargeDepartSql); - ResultSet rs5 = null; - try { - rs5 = objectDao.executeSql(sql); - while(rs5.next()){ - Double price = rs5.getDouble("price"); - String orgUnitName = rs5.getString("orgUnitName"); - String orgUnitCode = rs5.getString("orgUnitCode"); - newMonthReport(orgUnitCode, null,orgUnitName, "3", "价格统计", "b收费项目总价", price, list, null, null); - } - }catch(Exception e){ - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(rs5); - } - } - return list; + return monthReportGroupBySterilizationModeHelper.getMonthReportDataGroupBySterilizationMode(startDate, endDate, department, tousseType, disposableGoodsType, showCustonTousseAmount); } - /** - * 根据灭菌程序获取物品类型名称 - * @param sterilisationAndSterilizationModeMap <灭菌程序,灭菌程序对应的灭菌方式+"物品"> - * @param sterilingMethod - * @return a灭菌程序对应的灭菌方式+"物品" or c其他物品 - */ - private String getColumnNameBySterilingMethod(Map sterilisationAndSterilizationModeMap, String sterilingMethod){ - String columnName = null; - if(StringUtils.isNotBlank(sterilingMethod) && sterilisationAndSterilizationModeMap.containsKey(sterilingMethod)){ - columnName = sterilisationAndSterilizationModeMap.get(sterilingMethod); - }else{ - columnName = "c其他物品"; - } - return columnName; - } - //------------------------------------------按灭菌方式拆分器械包列,个性化核算报表 end----------------------------------- - /** - * 设置一次性物品数据 - * @param codeAndTypeMap <部门编码+","+一次性物品类型,MonthReportBean> - * @param departCode 部门编码 - * @param departName 部门名称 - * @param disposableGoodsType 一次性物品类型 - * @param amount 数量 - * @param price 价格 - */ - private void setCodeAndTypeMapData(Map codeAndTypeMap, String departCode, String departName, String disposableGoodsType, Integer amount, Double price){ - String key = new StringBuffer(20).append(departCode).append(",a").append(disposableGoodsType).toString(); - if(codeAndTypeMap.containsKey(key)){ - MonthReportBean mrb = codeAndTypeMap.get(key); - mrb.setAmount(MathTools.add(mrb.getAmount(), amount).intValue()); - mrb.setMoney(MathTools.add(mrb.getMoney(), price).doubleValue()); - }else{ - MonthReportBean mrb = new MonthReportBean(); - mrb.setRowNum(departCode); - mrb.setMoney(price); - mrb.setDepartment(departName); - mrb.setAmount(amount); - codeAndTypeMap.put(key, mrb); - } - } - private void newMonthReport(String code, String dept, String settleAccountsDepart, - String columnNum, String columnTitle, String columnName, - Double money,List list, String hospitalDistrict , Boolean enableMultipleBranchesOfHospital) { - MonthReportBean bean = new MonthReportBean(); - bean.setRowNum(code); - bean.setApplicationDepart(dept); - bean.setDepartment(settleAccountsDepart); - bean.setColumnNum(columnNum); - bean.setColumnTitle(columnTitle); - bean.setColumnName(columnName); - bean.setMoney(money); - bean.setHospitalDistrict(hospitalDistrict); - if(enableMultipleBranchesOfHospital != null && enableMultipleBranchesOfHospital){ - if(StringUtils.isBlank(hospitalDistrict)){ - newMonthReport(null, null,"合计_", columnNum, columnTitle, columnName, money, list, hospitalDistrict, false); - }else{ - newMonthReport(null, null, "合计_"+ hospitalDistrict, columnNum, columnTitle, columnName, money, list, hospitalDistrict, false); - } - } - list.add(bean); - } - /** - * 数量统计 - * @param code - * @param dept - * @param columnNum - * @param columnTitle - * @param columnName - * @param amount - * @param list - */ - private void newMonthReport(String code, String dept, String settleAccountsDepart, - String columnNum, String columnTitle, String columnName, - Integer amount, List list, String hospitalDistrict, Boolean enableMultipleBranchesOfHospital) { - MonthReportBean bean = new MonthReportBean(); - bean.setRowNum(code); - bean.setApplicationDepart(dept); - bean.setDepartment(settleAccountsDepart); - bean.setColumnNum(columnNum); - bean.setColumnTitle(columnTitle); - bean.setColumnName(columnName); - bean.setAmount(amount); - bean.setHospitalDistrict(hospitalDistrict); - if(enableMultipleBranchesOfHospital != null && enableMultipleBranchesOfHospital){ - if(StringUtils.isBlank(hospitalDistrict)){ - newMonthReport(null,null,"合计_", columnNum, columnTitle, columnName, amount, list, hospitalDistrict, false); - }else{ - newMonthReport(null,null,"合计_"+ hospitalDistrict, columnNum, columnTitle, columnName, amount, list, hospitalDistrict, false); - } - } - list.add(bean); - } - private void newMonthReport(String code, String dept,String settleAccountsDepart, - String columnNum, String columnTitle, String columnName, - Integer amount,List list, Double integral, String hospitalDistrict, Boolean enableMultipleBranchesOfHospital) { - MonthReportBean bean = new MonthReportBean(); - bean.setRowNum(code); - bean.setDepartment(settleAccountsDepart); - bean.setApplicationDepart(dept); - bean.setColumnNum(columnNum); - bean.setColumnTitle(columnTitle); - bean.setColumnName(columnName); - bean.setAmount(amount); - if(integral != null){ - bean.setIntegral(integral); - } - bean.setHospitalDistrict(hospitalDistrict); - if(enableMultipleBranchesOfHospital != null && enableMultipleBranchesOfHospital){ - if(StringUtils.isBlank(hospitalDistrict)){ - newMonthReport(null, null,"合计_", columnNum, columnTitle, columnName, amount, list, integral, hospitalDistrict, false); - }else{ - newMonthReport(null, null,"合计_"+ hospitalDistrict, columnNum, columnTitle, columnName, amount, list, integral, hospitalDistrict, false); - } - } - list.add(bean); - } - public Map getDiposableGoodsManufacturer(){ - String sql = "select dg.name,dg.specification,db.batchNumber,db.manufacturer " - + "from " + DisposableGoodsStock.class.getSimpleName() + " dg," + DisposableGoodsBatchStock.class.getSimpleName() + " db where dg.id = db.diposablegoods_id"; - ResultSet rs = objectDao.executeSql(sql); - Map map = new HashMap(); - try { - while(rs.next()){ - String name = rs.getString(1); - String sp = rs.getString(2); - String batch = rs.getString(3); - String manufacturer = rs.getString(4); - String key = name; - if(StringUtils.isNotBlank(sp)){ - key += "[" + sp + "]"; - } - key += "_" + batch; - map.put(key, manufacturer); - - } - } catch (SQLException e) { - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(rs); - } - return map; - } /** - * 获取新的高值耗材的生产厂家和外部编码 - * @param expensiveManufacture 生产厂家的map,输出参数 - * @param expensiveExternalCode 外部编码的map,输出参数 - */ - private Map expensiveExternalCode() { - String sql = "select eg.externalCode,eg.name,eg.specification from " - + ExpensiveGoods.class.getSimpleName() + " eg "; - ResultSet rs = objectDao.executeSql(sql); - Map expensiveExternalCode = new HashMap<>(); - try { - while(rs.next()){ - String name = rs.getString("name"); - String sp = rs.getString("specification"); - String externalCode = rs.getString("externalCode"); - String key = name; - if(StringUtils.isNotBlank(sp)){ - key += "[" + sp + "]"; - } - expensiveExternalCode.put(key, externalCode); - } - } catch (SQLException e) { - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(rs); - } - return expensiveExternalCode; - } - private Map disposableGoodsExternalCodeMap(){ - String sql = "select name,specification,externalCode from DisposableGoods where externalCode is not null"; - ResultSet rs = objectDao.executeSql(sql); - Map map = new HashMap(); - try { - while(rs.next()){ - String name = rs.getString(1); - String sp = rs.getString(2); - String externalCode = rs.getString(3); - String key = name; - if(StringUtils.isNotBlank(sp)){ - key += "[" + sp + "]"; - } - map.put(key, externalCode); - - } - } catch (SQLException e) { - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(rs); - } - return map; - } - - private Map getMaterialExternalCode(){ - String sql = "select name,specification,externalCode from MaterialDefinition where externalCode is not null"; - ResultSet rs = objectDao.executeSql(sql); - Map map = new HashMap(); - try { - while(rs.next()){ - String name = rs.getString(1); - String sp = rs.getString(2); - String externalCode = rs.getString(3); - String key = name; - if(StringUtils.isNotBlank(sp)){ - key += "[" + sp + "]"; - } - map.put(key, externalCode); - - } - } catch (SQLException e) { - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(rs); - } - return map; - } - - private Map getTousseExternalCode(){ - String sql = "select name,externalCode from TousseDefinition where externalCode is not null"; - ResultSet rs = objectDao.executeSql(sql); - Map map = new HashMap(); - try { - while(rs.next()){ - String name = rs.getString(1); - String externalCode = rs.getString(2); - map.put(name, externalCode); - } - } catch (SQLException e) { - e.printStackTrace(); - }finally { - DatabaseUtil.closeResultSetAndStatement(rs); - } - return map; - } - - /** * 明细核算月报 */ @Override @@ -6106,2193 +3472,8 @@ String goodsNameSearch, String batch,String searchType,boolean disinfection,String disposableGoodsType,String goodsType, Boolean showCustonTousseAmount, String invoicePlanDepartCoding, String departGroupStr, boolean printByDepart ,String urgentLevel, String extendedColumnConfigOfDetailedAccountingMonthlyReport) { - boolean filterWhetherToCharge = false; - if(StringUtils.isNotBlank(whetherToCharge) && !whetherToCharge.contains("全部")){ - filterWhetherToCharge = true; - } - String iSendTimeSqlOfShowTime = ""; - String groupByIsendTimeOfShowTime = ""; - - String prPackTimeSqlOfShowTime = ""; - String groupByPrPackTimeOfShowTime = ""; - - String rrReturnTimeSqlOfShowTime = ""; - String groupByRrReturnTimeOfShowTime = ""; - - String iOperationTimeSqlOfShowTime = ""; - String groupByIOperationTimeOfShowTime = ""; - - String rrTimeSqlOfShowTime = ""; - String groupByRrTimeOfShowTime = ""; - - String ogeTimeSqlOfShowTime = ""; - String groupByOgeTimeOfShowTime = ""; - - String crChargeTimeSqlOfShowTime = ""; - String groupByCrChargeTimeOfShowTime = ""; - if(showTime){ - String dateSql = dateQueryAdapter.dateConverAdapter(dateQueryAdapter.stringFieldToDate("i.sendTime"),"yyyy-MM-dd"); - iSendTimeSqlOfShowTime = ","+ dateSql +" showTime "; - groupByIsendTimeOfShowTime = "," + dateSql; - - String packTimeDateSql = dateQueryAdapter.dateConverAdapter(dateQueryAdapter.stringFieldToDate("pr.packTime"),"yyyy-MM-dd"); - prPackTimeSqlOfShowTime = ","+ packTimeDateSql +" showTime "; - groupByPrPackTimeOfShowTime = "," + packTimeDateSql; - - String returnTimeDateSql = dateQueryAdapter.dateConverAdapter(dateQueryAdapter.stringFieldToDate("rr.returnTime"),"yyyy-MM-dd"); - rrReturnTimeSqlOfShowTime = ","+ returnTimeDateSql +" showTime "; - groupByRrReturnTimeOfShowTime = "," + returnTimeDateSql; - - String operationTimeDateSql = dateQueryAdapter.dateConverAdapter(dateQueryAdapter.stringFieldToDate("i.operationTime"),"yyyy-MM-dd"); - iOperationTimeSqlOfShowTime = ","+ operationTimeDateSql +" showTime "; - groupByIOperationTimeOfShowTime = "," + operationTimeDateSql; - - String rrTimeDateSql = dateQueryAdapter.dateConverAdapter(dateQueryAdapter.stringFieldToDate("rr.time"),"yyyy-MM-dd"); - rrTimeSqlOfShowTime = ","+ rrTimeDateSql +" showTime "; - groupByRrTimeOfShowTime = "," + rrTimeDateSql; - - String ogeTimeDateSql = dateQueryAdapter.dateConverAdapter(dateQueryAdapter.stringFieldToDate("oge.time"),"yyyy-MM-dd"); - ogeTimeSqlOfShowTime = ","+ ogeTimeDateSql +" showTime "; - groupByOgeTimeOfShowTime = "," + ogeTimeDateSql; - - String crChargeTimeDateSql = dateQueryAdapter.dateConverAdapter(dateQueryAdapter.stringFieldToDate("cr.chargeTime"),"yyyy-MM-dd"); - crChargeTimeSqlOfShowTime = ","+ crChargeTimeDateSql +" showTime "; - groupByCrChargeTimeOfShowTime = "," + crChargeTimeDateSql; - } - boolean queryUnit = printByDepart; - //数据库拼接符号 - String concatSymbolInDb = DatabaseUtil.isOracle(dbConnection.getDatabase())?"||":"+"; - SupplyRoomConfig config = supplyRoomConfigManager.getSystemParamsObj(); - final String TYPE_AUTO_DEDUCTION = "自动扣减物品"; - final String TYPE_ALL = "全部"; - final String TYPE_CHARGE = "收费项目"; - //是否启用高值耗材(新) - boolean enableExpensiveGoods = CssdUtils.getSystemSetConfigByNameBool("enableExpensiveGoods"); - //是否启用高值耗材(一次性物品的高值耗材) - boolean enableExpensiveDisposableGoods = CssdUtils.getSystemSetConfigByNameBool("enableExpensiveDisposableGoods"); - //启用排除属于科研项目的一次性物品申请单的发货数据 - boolean excludeSciProjectInfo = CssdUtils.getSystemSetConfigByNameBool("enableExcludeInvoiceItemOfDisposableGoodsApplicationBelongToSciProject", false); - boolean showBatch = StrutsParamUtils.getBoolPraramValue("showBatch", true); - //判断当前登录用户是否为匿名用户.如果为匿名用户则只查询一级供应室的数据,否则根据实际情况的条件查询 - LoginUserData user = AcegiHelper.getLoginUser(); - String loginUserFullName = null; - String orgUnitCoding = null; - if (user != null){ - orgUnitCoding = user.getOrgUnitCodingFromSupplyRoomConfig(); - loginUserFullName = user.getUserFullName(); - } - boolean isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser = false; - if (supplyRoomConfigManager.isSupplyRoomUser() || supplyRoomConfigManager.isExpensiveGoodsSupplyRoomUser()) { - isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser = true; - } - if(StringUtils.equals(loginUserFullName, Constants.ANONYMOUS_USERNAME)){ - departCoding = supplyRoomConfigManager.getFirstSupplyRoomConfig().getOrgUnitCoding(); - } - Set departCodingSet = null; - Set departSearchSet = null; - if(StringUtils.isNotBlank(departGroupStr)){ - departSearchSet = new HashSet(); - departCodingSet = new HashSet(); - Set departGroupIds = null; - if(departGroupStr.contains(",")){ - departGroupIds = SqlUtils.splitStringToSet(departGroupStr, ","); - }else{ - departGroupIds = new HashSet(); - departGroupIds.add(departGroupStr); - } - List invoiceDepartments = objectDao.findByHql("select po from " + InvoiceDepartment.class.getSimpleName() + " po where " + SqlUtils.getNonStringFieldInLargeCollectionsPredicate("po.id", departGroupIds)); - for (InvoiceDepartment invoiceDepartment : invoiceDepartments) { - if("全部".equals(invoiceDepartment)){ - departSearch = null; - departCoding = null; - break; - } - Set thisDepartSearchs = SqlUtils.splitStringToSet(invoiceDepartment.getDepartNames(), ";"); - departSearchSet.addAll(thisDepartSearchs); - Set thisDepartCodings = SqlUtils.splitStringToSet(invoiceDepartment.getDepartCodes(), ";"); - departCodingSet.addAll(thisDepartCodings); - } - departCoding = ""; - departSearch = ""; - invoicePlanDepartCoding = ""; - }else{ - departCodingSet = SqlUtils.splitStringToSet(departCoding, ","); - departSearchSet = SqlUtils.splitStringToSet(departSearch, ","); - } - Set invoicePlanDepartCodingSet = SqlUtils.splitStringToSet(invoicePlanDepartCoding, ","); - boolean enableToussePointsStatistics = CssdUtils.getSystemSetConfigByNameBool("enableToussePointsStatistics", false); - boolean showMaterialsAmountColumnOfDetailMonthReport = CssdUtils.getSystemSetConfigByNameBool("showMaterialsAmountColumnOfDetailMonthReport", false); - - List datas = new ArrayList(); - List allTousseType = new ArrayList(); - Set returnGoodType = new HashSet(); - if(StringTools.isBlank(typeSearch) || typeSearch.contains("全部器械包")){ - allTousseType.add(TousseDefinition.PACKAGE_TYPE_CUSTOM); - allTousseType.add(TousseDefinition.PACKAGE_TYPE_DISINFECTION); - allTousseType.add(TousseDefinition.PACKAGE_TYPE_DRESSING); - allTousseType.add(TousseDefinition.PACKAGE_TYPE_FOREIGN); - allTousseType.add(TousseDefinition.PACKAGE_TYPE_FOREIGNPROXY); - allTousseType.add(TousseDefinition.PACKAGE_TYPE_INSIDE); - allTousseType.add(TousseDefinition.PACKAGE_TYPE_SPLIT); - allTousseType.add(TousseDefinition.PACKAGE_TYPE_COMBO); - if(StringTools.isBlank(typeSearch) && enableExpensiveGoods){ - allTousseType.add(ExpensiveGoods.TYPE_NAME); - } - returnGoodType.add("器械包"); - } - Set typeSearchSet = new HashSet(); - if(!StringTools.isBlank(typeSearch)){ - typeSearchSet = SqlUtils.splitStringToSet(typeSearch, ","); - if(!typeSearchSet.contains("全部器械包")){ - if(typeSearchSet.contains("外来器械包")){ - allTousseType.add(TousseDefinition.PACKAGE_TYPE_FOREIGN); - allTousseType.add(TousseDefinition.PACKAGE_TYPE_SPLIT); - returnGoodType.add("器械包"); - } - if(typeSearchSet.contains("外部代理灭菌包")){ - allTousseType.add(TousseDefinition.PACKAGE_TYPE_FOREIGNPROXY); - returnGoodType.add("器械包"); - } - if(typeSearchSet.contains(ExpensiveGoods.TYPE_NAME) && enableExpensiveGoods){ - allTousseType.add(ExpensiveGoods.TYPE_NAME); - } - if(typeSearchSet.contains(TousseDefinition.PACKAGE_TYPE_CUSTOM)){ - allTousseType.add(TousseDefinition.PACKAGE_TYPE_CUSTOM); - returnGoodType.add("器械包"); - } - if(typeSearchSet.contains(TousseDefinition.PACKAGE_TYPE_INSIDE)){ - allTousseType.add(TousseDefinition.PACKAGE_TYPE_INSIDE); - returnGoodType.add("器械包"); - } - if(typeSearchSet.contains(TousseDefinition.PACKAGE_TYPE_DRESSING)){ - allTousseType.add(TousseDefinition.PACKAGE_TYPE_DRESSING); - returnGoodType.add("器械包"); - } - if(typeSearchSet.contains(TousseDefinition.PACKAGE_TYPE_DISINFECTION)){ - allTousseType.add(TousseDefinition.PACKAGE_TYPE_DISINFECTION); - returnGoodType.add("器械包"); - } - } - if(typeSearchSet.contains("一次性物品")){ - returnGoodType.add("一次性物品"); - } - } - // 查看是否配置显示供应商 - Boolean showSupplierNameInDetailedAccountingMonthlyReport = CssdUtils.getSystemSetConfigByNameBool("showSupplierNameInDetailedAccountingMonthlyReport", false); - String tousseDefinitionOfSupplierNameSql = "";//用器械包定义里的供应商拼接的sql语句,主要用于查询供应商和按供应商分组 - String addTousseDefinitionAtWhere = "";//拼接sql,用于添加查询TousseDefinition - String tousseInstanceJoinTousseDefinitionSql = ""; - String dgbsOfSupplierNameSql = "";//用于查询DisposableGoodsBatchStock或DisposableGoodsBatch的供应商名称,主要用于查询供应商和按供应商分组 - String noQuerySupplierName = "";//不需要查询器械包名称的sql,用于连接union all连接表时保持列数不变 - String integralOftousseDefinitionSql = ""; - String noQueryIntegralSql = ""; - String unitSqlOftousseDefinitionSql = ""; - boolean queryUrgent = false; - if(StringUtils.isNotBlank(urgentLevel) && !urgentLevel.contains("全部")){ - queryUrgent = true; - tousseInstanceJoinTousseDefinitionSql = " join TousseDefinition td on td.id=ti.tousseDefinition_id "; - } - - if(enableToussePointsStatistics){ - addTousseDefinitionAtWhere = " left join TousseDefinition td on td.id = ii.tousseDefinitionId "; - integralOftousseDefinitionSql = ",td.integral "; - noQueryIntegralSql = ",0 integral "; - }else if(showSupplierNameInDetailedAccountingMonthlyReport){ - addTousseDefinitionAtWhere = " join TousseDefinition td on td.id = ii.tousseDefinitionId "; - }else if(queryUnit){ - addTousseDefinitionAtWhere = " left join TousseDefinition td on td.id = ii.tousseDefinitionId "; - unitSqlOftousseDefinitionSql = ",td.unit "; - } - - boolean queryTousseGroupName = false;//是否查询器械包分组 - String nullTousseGroupNameSQL = ""; - String tdcTousseGroupNameSQL = ""; - String tdLeftJoinTdcSQL = ""; - if(StringUtils.isNotBlank(extendedColumnConfigOfDetailedAccountingMonthlyReport)){ - JSONArray arr = JSONArray.fromObject(extendedColumnConfigOfDetailedAccountingMonthlyReport); - for (int i = 0; i < arr.size(); i++) { - String extendedColumnName = arr.get(i).toString().trim(); - if(StringUtils.isBlank(extendedColumnName)){ - continue; - } - if("tousseGroupName".equals(extendedColumnName)){ - queryTousseGroupName = true; - tdcTousseGroupNameSQL = ",tdc.tousseGroupName "; - nullTousseGroupNameSQL = ",null tousseGroupName "; - tdLeftJoinTdcSQL = " left join TousseDefinition tdc on tdc.id=td.ancestorID "; - } - } - } - if(queryTousseGroupName){ - if(StringUtils.isBlank(addTousseDefinitionAtWhere)){ - addTousseDefinitionAtWhere += " left join TousseDefinition td on td.id = ii.tousseDefinitionId " - + "left join TousseDefinition tdc on tdc.id=td.ancestorID "; - }else{ - addTousseDefinitionAtWhere += " left join TousseDefinition tdc on tdc.id=td.ancestorID "; - } - if(queryUrgent){ - tousseInstanceJoinTousseDefinitionSql += " join TousseDefinition tdc on tdc.id=td.ancestorID "; - } - } - String noQueryUnitSql = ""; - //通过DiposableGoodsItem查询一次性物品单位的相关sql - String unitDSqlOfDiposableGoodsItem = ""; - String unitDGroupBySqlOfDiposableGoodsItem = ""; - String unitDGISqlOfDiposableGoodsItem = ""; - String unitDGIGroupBySqlOfDiposableGoodsItem = ""; - //通过materialDefinition查询一次性物品单位的相关sql - String unitDSqlOfMd = ""; - String unitMSqlOfMd = ""; - //通过DisposableGoods查询一次性物品单位的相关sql - String unitDGSqlOfDisposableGoods = ""; - if(queryUnit){ - unitDSqlOfDiposableGoodsItem = ",(select unit from DisposableGoods where id=d.disposableGoodsID) unit "; - unitDGroupBySqlOfDiposableGoodsItem = ",d.disposableGoodsID"; - unitDGISqlOfDiposableGoodsItem = ",(select unit from DisposableGoods where id=dgi.disposableGoodsID) unit "; - unitDGIGroupBySqlOfDiposableGoodsItem = ",dgi.disposableGoodsID"; - unitDSqlOfMd = ",d.unit "; - unitMSqlOfMd = ",m.unit"; - unitDGSqlOfDisposableGoods = ",dg.unit"; - noQueryUnitSql = ",null unit"; - } - if(showSupplierNameInDetailedAccountingMonthlyReport){ - tousseDefinitionOfSupplierNameSql = " ,td.supplierName "; - dgbsOfSupplierNameSql = " ,dgbs.supplierName "; - noQuerySupplierName = ",''"; - } - startTime += ":00"; - endTime += ":59"; -// String handleDeptCode = AcegiHelper.getLoginUser().getOrgUnitCodingFromSupplyRoomConfig(); - String monthFilterSql = " "; - String expensiveGoodsMonthFilterSql = " "; - String returnGoodsFilterSql = " "; - String returnGoodsTimeFilterSql = " "; - String packingDisposableGoodsTimeSql = " "; - String returnGoodsDepartFilterSql = " "; - String materialNameFilterSql = " "; - String materialTypeFilterSql = " "; - String lostMaterialFilterSql = " "; - String damageFilterSql = " "; - String supplyRoomDiposableGoodsFilterSql = " "; - String outEntryFilterSql = " "; - - String invoiceItemDisposableGoodsTypePredicate = " (1=1) "; - String diposableGoodsItemPredicate = " (1=1) "; - String packingDisposableGoodsTypeSql = " (1=1) "; - String disposableGoodsInvoiceAmountPredicate = " (ii.diposable='是') "; - String returnGoodsItemPredicate = " (1=1) "; - String receiveRecordItemPredicate = " (1=1) "; - String disposableGoodsIdSql = ""; - String outEntryPredicate = " 1=1 "; - - if(StringUtils.isNotBlank(disposableGoodsType) || filterWhetherToCharge){ - disposableGoodsIdSql = String.format(" select id from DisposableGoods where 1=1 %s %s", StringUtils.isNotBlank(disposableGoodsType)?" and type='"+ disposableGoodsType +"'":"" - , filterWhetherToCharge?" and whetherToCharge='"+ whetherToCharge +"'":""); - invoiceItemDisposableGoodsTypePredicate = String.format(" (ii.diposable='否' or ii.disposableGoodsId in(%s)) ", disposableGoodsIdSql); - diposableGoodsItemPredicate = String.format(" (d.disposableGoodsID in(%s)) ", disposableGoodsIdSql); - packingDisposableGoodsTypeSql = String.format(" (dgi.disposableGoodsID in(%s)) ", disposableGoodsIdSql); - disposableGoodsInvoiceAmountPredicate = String.format(" (ii.diposable='是' and ii.disposableGoodsId in(%s)) ", disposableGoodsIdSql); -// returnGoodsItemPredicate = String.format(" (rr.type!='一次性物品' or rr.disposableGoodsId in(%s)) ", disposableGoodsIdSql); - returnGoodsItemPredicate = String.format(" (ri.disposableGoodsId in(%s)) ", disposableGoodsIdSql); - receiveRecordItemPredicate = String.format(" (rri.type!='一次性物品' or rri.disposableGoodsId in(%s)) ", disposableGoodsIdSql); - outEntryPredicate = String.format(" (ged.disposableGoodsID in(%s)) ", disposableGoodsIdSql); - } - String betweenSql = ""; - if (StringUtils.isNotBlank(startTime) && StringUtils.isNotBlank(endTime)) { - betweenSql = new StringBuffer(150).append(" between ") - .append(dateQueryAdapter.dateConverAdapter2( startTime, "yyyy-mm-dd HH24:MI:SS")) - .append(" and ") - .append(dateQueryAdapter.dateConverAdapter2( endTime, "yyyy-mm-dd HH24:MI:SS")).toString(); - monthFilterSql = " and i.sendtime" + betweenSql; - expensiveGoodsMonthFilterSql = " and egge.time" + betweenSql; - returnGoodsTimeFilterSql = " and rr.returntime" + betweenSql; - returnGoodsFilterSql = returnGoodsTimeFilterSql; - packingDisposableGoodsTimeSql = " and pr.packTime "+betweenSql; - lostMaterialFilterSql = " and i.additionalTime" + betweenSql; - damageFilterSql = " and i.additionalTime" + betweenSql; - - supplyRoomDiposableGoodsFilterSql = " and rr.time" + betweenSql; - outEntryFilterSql = " and oge.time" + betweenSql; - } else { - monthFilterSql = " and 1=2 "; - returnGoodsFilterSql = " and 1=2 "; - packingDisposableGoodsTimeSql = " and 1=2 "; - lostMaterialFilterSql = " and 1=2 "; - damageFilterSql = " and 1=2 "; - } - String departFilterSql = ""; - String packingDisposableGoodsDepartSql = ""; - String chargeDepartSql = ""; - String prDepartCodingSql = null; - String iDepartCodeSql = null; - String ogeTargetOrgUnitCodeSql = null; - String ogeOrgUnitCodeSql = null; - if(invoicePlanDepartCodingSet.size() > 0){ - returnGoodsFilterSql += " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("rr.departCoding", invoicePlanDepartCodingSet); - prDepartCodingSql = " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("pr.departCoding", invoicePlanDepartCodingSet); - iDepartCodeSql = " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("i.departCode", invoicePlanDepartCodingSet); - ogeTargetOrgUnitCodeSql = " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("oge.targetOrgUnitCode", invoicePlanDepartCodingSet); - ogeOrgUnitCodeSql = " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("oge.orgUnitCode", invoicePlanDepartCodingSet); - }else{ - prDepartCodingSql = ""; - iDepartCodeSql = ""; - ogeTargetOrgUnitCodeSql = ""; - ogeOrgUnitCodeSql = ""; - } - String rrSettleAccountsDepartCodingSql = null; - if (CollectionUtils.isNotEmpty(departSearchSet)) { - departFilterSql = " and "+ SqlUtils.getStringFieldInLargeCollectionsPredicate("i.settleaccountsdepart", departSearchSet); - returnGoodsDepartFilterSql = " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("rr.settleAccountsDepart", departSearchSet); - packingDisposableGoodsDepartSql = " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("pr.orgUnitName", departSearchSet); - lostMaterialFilterSql += " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("i.settleAccountsDepart", departSearchSet); - damageFilterSql += " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("i.settleAccountsDepart", departSearchSet);; - supplyRoomDiposableGoodsFilterSql += " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("rr.departCoding", departCodingSet);; - outEntryFilterSql += " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("oge.orgUnitCode", departCodingSet);; - rrSettleAccountsDepartCodingSql = " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("rr.settleAccountsDepartCoding", departCodingSet); - }else{ - rrSettleAccountsDepartCodingSql = ""; - } - String typeFilterSql = " "; - String tdTypeSql = " "; - String expensiveDisposablegoodsSql = ""; - String expensiveDisposablegoodsIdSql = ""; - if (StringUtils.isNotBlank(typeSearch)) { - tdTypeSql = String.format(" and (%s)", SqlUtils.getStringFieldInLargeCollectionsPredicate("td.tousseType", allTousseType)); - typeFilterSql = String.format(" and (%s)", SqlUtils.getStringFieldInLargeCollectionsPredicate("ii.tousseType", allTousseType)); - if(typeSearchSet.contains("一次性物品") && typeSearchSet.size() > 1){//不止一次性物品 - returnGoodsItemPredicate += " and (rr.type='一次性物品' or ri.tousseDefinition_id in (select id from TousseDefinition where "+ SqlUtils.getStringFieldInLargeCollectionsPredicate("tousseType", allTousseType) +")) "; - }else if(!typeSearchSet.contains("一次性物品") && typeSearchSet.size() > 0){//不包含一次性物品 - returnGoodsItemPredicate += String.format(" and ri.tousseDefinition_id in (select id from TousseDefinition where %s) ", SqlUtils.getStringFieldInLargeCollectionsPredicate("tousseType", allTousseType)); - } - returnGoodsFilterSql += " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("rr.type", returnGoodType); - if(!typeSearch.contains("一次性物品") && !typeSearch.contains(DisposableGoods.TYPE_EXPENSIVEDIPOSABLEGOODS)){ - outEntryFilterSql += " and 1=2 "; - }else if(!typeSearch.contains("一次性物品") && typeSearch.contains(DisposableGoods.TYPE_EXPENSIVEDIPOSABLEGOODS)){ - outEntryFilterSql += " and dg.goodsType = '" + DisposableGoods.TYPE_EXPENSIVEDIPOSABLEGOODS + "' "; - expensiveDisposablegoodsSql = " and d.expensiveDisposablegoodsId is not null "; - } - if(typeSearch.contains("器械材料") && typeSearch.contains("一次性物品") ){ - supplyRoomDiposableGoodsFilterSql += " and (rri.type = '一次性物品' or rri.materialDefinition_id in (select id from MaterialDefinition)) "; - }else if(typeSearch.contains("器械材料") && typeSearch.contains(TYPE_AUTO_DEDUCTION)){ - supplyRoomDiposableGoodsFilterSql += " and (rri.materialDefinition_id in (select id from MaterialDefinition) or rr.type='"+ TYPE_AUTO_DEDUCTION +"') "; - }else if(typeSearch.contains(TYPE_AUTO_DEDUCTION)){ - supplyRoomDiposableGoodsFilterSql += " and rr.type='"+ TYPE_AUTO_DEDUCTION +"'"; - }else if(typeSearch.contains("器械材料")){ - supplyRoomDiposableGoodsFilterSql += " and rri.materialDefinition_id in (select id from MaterialDefinition) "; - }else if(typeSearch.contains("一次性物品")){ - supplyRoomDiposableGoodsFilterSql += " and rri.type = '一次性物品' "; - }else if(!typeSearch.contains(TYPE_AUTO_DEDUCTION)){ - supplyRoomDiposableGoodsFilterSql += " and 1=2 "; - } - - if(typeSearch.contains("器械材料") || typeSearch.contains("器械材料") && typeSearch.contains(MaterialDefinition.TYPE_EXPENSIVEMATERIALGOODS)){ - lostMaterialFilterSql += " and 1=1 "; - damageFilterSql += " and 1=1 "; - materialTypeFilterSql = " and 1=1 "; - }else if(typeSearch.contains("高值耗材")){ - if(enableExpensiveGoods){ - lostMaterialFilterSql += " and 1=2 "; - damageFilterSql += " and 1=1 "; - }else{ - lostMaterialFilterSql += " and m.goodsType = '"+MaterialDefinition.TYPE_EXPENSIVEMATERIALGOODS+"' "; - damageFilterSql += " and m.goodsType = '"+MaterialDefinition.TYPE_EXPENSIVEMATERIALGOODS+"' "; - if(StringUtils.isNotBlank(goodsType)){ - if("一次性物品".equals(goodsType)){ - materialTypeFilterSql = " and 1=2 "; - }else{ - materialTypeFilterSql = " and d.goodsType = '"+MaterialDefinition.TYPE_EXPENSIVEMATERIALGOODS+"'"; - expensiveDisposablegoodsIdSql = " and 1=2 "; - } - }else{ - materialTypeFilterSql += " and d.goodsType = '"+MaterialDefinition.TYPE_EXPENSIVEMATERIALGOODS+"'"; - } - } - }else{ - lostMaterialFilterSql += " and 1=2 "; - damageFilterSql += " and 1=2 "; - } - }else{ - if(!enableExpensiveGoods){ - //没有启用高值耗材,就不查询新的高值耗材的数据 - typeFilterSql = " and ii.tousseType <> '" + ExpensiveGoods.TYPE_NAME + "'"; - } - } - String goodsNameFilterSql = " "; - String tdNameFilterSql = ""; - String expensiveGoodsNameFilterSql = " "; - String chargeItemSql = "";//收费项目名称过滤 - if (StringUtils.isNotBlank(goodsNameSearch)) { - if("精确查询".equals(searchType)){ - tdNameFilterSql = " and td.name ='"+ goodsNameSearch +"' "; - goodsNameFilterSql = " and ii.toussename = '" + goodsNameSearch - + "'"; - expensiveGoodsNameFilterSql = " and case when egm.model is null then eg.name else eg.name + '[' + egm.model + ']' end = '%" + goodsNameSearch - + "%'"; - returnGoodsFilterSql += " and ri.toussename = '" - + goodsNameSearch + "'"; - materialNameFilterSql = " and ii.materialName = '" - + goodsNameSearch + "' "; - lostMaterialFilterSql += " and i.materialName = '" - + goodsNameSearch + "'"; - damageFilterSql += " and i.materialName = '" - + goodsNameSearch + "'"; - supplyRoomDiposableGoodsFilterSql += " and rri.goodsName = '"+goodsNameSearch+"'"; - outEntryFilterSql += " and ged.goodsName = '"+goodsNameSearch+"'"; - chargeItemSql = " and chargeItem = '"+goodsNameSearch+"' "; - }else{ - tdNameFilterSql = " and td.name like '%"+ goodsNameSearch +"%' "; - goodsNameFilterSql = " and ii.toussename like '%" + goodsNameSearch - + "%'"; - expensiveGoodsNameFilterSql = " and case when egm.model is null then eg.name else eg.name + '[' + egm.model + ']' end like '%" + goodsNameSearch - + "%'"; - returnGoodsFilterSql += " and ri.toussename like '%" - + goodsNameSearch + "%'"; - materialNameFilterSql = " and ii.materialName like '%" - + goodsNameSearch + "%' "; - lostMaterialFilterSql += " and i.materialName like '%" - + goodsNameSearch + "%'"; - damageFilterSql += " and i.materialName like '%" - + goodsNameSearch + "%'"; - supplyRoomDiposableGoodsFilterSql += " and rri.goodsName like '%"+goodsNameSearch+"%' "; - outEntryFilterSql += " and ged.goodsName like '%"+goodsNameSearch+"%' "; - chargeItemSql = " and chargeItem like '%"+goodsNameSearch+"%' "; - } - //消毒物品需用like查询 - if(disinfection){ - tdNameFilterSql = " and td.name like '%"+ goodsNameSearch +"%' "; - goodsNameFilterSql = " and ii.toussename like '%" + goodsNameSearch - + "%'"; - returnGoodsFilterSql += " and ri.toussename like '%" - + goodsNameSearch + "%'"; - lostMaterialFilterSql += " and i.materialName like '%" - + goodsNameSearch + "%'"; - damageFilterSql += " and i.materialName like '%" - + goodsNameSearch + "%'"; - - supplyRoomDiposableGoodsFilterSql += " and 1=2"; - outEntryFilterSql += " and 1=2"; - } - } - String nameFilterSql = ""; - String packingDisposableGoodsNameSql = ""; - if (StringUtils.isNotBlank(goodsNameSearch)) { - nameFilterSql = " and d.name = '" + goodsNameSearch + "'"; - packingDisposableGoodsNameSql = " and dgi.name = '" + goodsNameSearch + "'"; - } - String iDepartCodingSql = " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("i.departCoding", invoicePlanDepartCodingSet," 1=1 "); - String rrDepartCodingSql = " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("rr.departCoding", invoicePlanDepartCodingSet," 1=1 "); - String ciOrgUnitCodeSql = " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("ci.orgUnitCode", invoicePlanDepartCodingSet," 1=1 "); - String supplyRoomDiposableGoodsFilterSqlOFDgbs = ""; - if (StringUtils.isNotBlank(batch)) { - nameFilterSql += " and d.batch = '" + batch + "'"; - goodsNameFilterSql += " and 1=2 "; - tdNameFilterSql = " and 1=2 "; - returnGoodsFilterSql += " and ri.batchNumber = '"+batch+"' "; - packingDisposableGoodsNameSql += " and dgi.batch = '"+batch+"' "; - lostMaterialFilterSql += " and 1=2 "; - damageFilterSql += " and 1=2 "; - supplyRoomDiposableGoodsFilterSqlOFDgbs = supplyRoomDiposableGoodsFilterSql + " and dgbs.batchNumber = '"+batch+"'"; - supplyRoomDiposableGoodsFilterSql += " and dgbs.batchNumber = '"+batch+"'"; - outEntryFilterSql += " and dgbs.batchNumber = '"+batch+"'"; - } - String tousseMaterialAmountSql = null; - String noMaterialAmountSql = null; - String returnGoodsItemMaterialAmountSql = null; - String sumRriAmountSql = null; - String groupByMaterialAmountAtThatTime = null; - String tousseInstanceMaterialAmountSql = null; - String sumMaterialAmountSql = null; - if(showMaterialsAmountColumnOfDetailMonthReport){ - sumMaterialAmountSql = " sum(materialAmount) materialAmount,"; - tousseInstanceMaterialAmountSql = " sum(ti.materialAmount) materialAmount,"; - tousseMaterialAmountSql = " sum(ii.materialAmount*ii.amount) materialAmount,"; - noMaterialAmountSql = " 0 materialAmount,"; - returnGoodsItemMaterialAmountSql = " case when ri.materialAmountAtThatTime is null then sum(-ri.materialAmount*ri.amount) else sum(-ri.materialAmountAtThatTime*ri.amount) end materialAmount,"; - sumRriAmountSql = "sum(rri.amount) materialAmount,"; - groupByMaterialAmountAtThatTime = ",ri.materialAmountAtThatTime "; - }else{ - sumMaterialAmountSql = ""; - tousseInstanceMaterialAmountSql = ""; - tousseMaterialAmountSql = ""; - noMaterialAmountSql = ""; - returnGoodsItemMaterialAmountSql = ""; - sumRriAmountSql = ""; - groupByMaterialAmountAtThatTime = ""; - } - String iSendTime = ""; - String groupByIsendTime = ""; - String noSendTime = ""; - if(showSendTime){ - String dateSql = dateQueryAdapter.dateConverAdapter(dateQueryAdapter.stringFieldToDate("i.sendTime"),"yyyy-MM-dd"); - iSendTime = ","+ dateSql +" sendTime "; - groupByIsendTime = "," + dateSql; - noSendTime = ",null sendTime "; - } - String returnGoodsTousseType = " CASE rr.type WHEN '一次性物品' THEN (rr.type) WHEN '器械包' THEN (td.toussetype) ELSE rr.type END "; - String returnGoodsTousseDefinitionId = " CASE rr.type WHEN '器械包' THEN ri.tousseDefinition_id ELSE 0 END "; - //器械包 - String tousseSql = null; - String urgentSql = ""; - if(queryUrgent){//加急要过滤到包实例 - 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, ",")) +" )"; - }else{ - urgentSql = " and " + SqlUtils.getNonStringFieldInLargeCollectionsPredicate("ti.urgentLevel_id", SqlUtils.splitStringToSet(urgentLevel, ",")); - } - String showTimeOfT = ""; - if(showTime){ - showTimeOfT = ",showTime "; - } - String sendTimeOfT = ""; - if(showSendTime){ - sendTimeOfT = ",sendTime "; - } - String tousseGroupNameOfT = ""; - if(queryTousseGroupName){ - tousseGroupNameOfT = ",tousseGroupName "; - } - String groupBySql = "group by i.depart" - + tdcTousseGroupNameSQL - + groupByIsendTimeOfShowTime + groupByIsendTime + unitSqlOftousseDefinitionSql - +",i.settleAccountsDepart,td.tousseType,td.name,td.id " - + tousseDefinitionOfSupplierNameSql + integralOftousseDefinitionSql; - String groupBySqlOfT = "group by depart" - + showTimeOfT - + sendTimeOfT - + tousseGroupNameOfT - + getRemovePrefixSql(unitSqlOftousseDefinitionSql) - +",settleAccountsDepart,type,name,tousseDefinitionId " - + getRemovePrefixSql(tousseDefinitionOfSupplierNameSql) - + getRemovePrefixSql(integralOftousseDefinitionSql); - tousseSql = " select "+ sumMaterialAmountSql +"depart,settleAccountsDepart" - + showTimeOfT - + sendTimeOfT - + getRemovePrefixSql(tousseDefinitionOfSupplierNameSql) - + getRemovePrefixSql(integralOftousseDefinitionSql) - + ",name,sum(amount) amount,sum(settlementprice) settlementprice,sum(settlementDiscountPrice) settlementDiscountPrice,type" - + getRemovePrefixSql(unitSqlOftousseDefinitionSql) - + ",'' as batchNumber,null as expDate,tousseDefinitionId" - + tousseGroupNameOfT - + " from ( select " - + tousseInstanceMaterialAmountSql - +" i.depart,i.settleAccountsDepart " - + iSendTimeSqlOfShowTime - + iSendTime - + tousseDefinitionOfSupplierNameSql - + integralOftousseDefinitionSql - +",td.name,count(*) as amount," - +"sum(ti.price) as settlementprice,sum(ti.discountPrice) as settlementDiscountPrice,td.tousseType as type" - + unitSqlOftousseDefinitionSql - + ",'' as batchNumber,null as expDate,td.id as tousseDefinitionId" - + tdcTousseGroupNameSQL - + " from invoice i " - + "join TousseInstance ti on ti.invoice_id=i.id " - + tousseInstanceJoinTousseDefinitionSql - + " where " - + getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - + monthFilterSql - + iDepartCodingSql - + departFilterSql - + tdTypeSql - + tdNameFilterSql - + urgentSql - + " and i.settleaccountsdepart is not null " - + groupBySql; - tousseSql += " union all " - + " select " - + tousseInstanceMaterialAmountSql - +" i.depart,i.settleAccountsDepart " - + iSendTimeSqlOfShowTime - + iSendTime - + tousseDefinitionOfSupplierNameSql - + integralOftousseDefinitionSql - +",td.name,count(*) as amount," - +"sum(ti.price) as settlementprice,sum(ti.discountPrice) as settlementDiscountPrice,td.tousseType as type" - + unitSqlOftousseDefinitionSql - + ",'' as batchNumber,null as expDate,td.id as tousseDefinitionId" - + tdcTousseGroupNameSQL - + " from invoice i " - + "join TousseInstance ti on ti.invoice2_id=i.id " - + tousseInstanceJoinTousseDefinitionSql - + " where " - + getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - + monthFilterSql - + iDepartCodingSql - + departFilterSql - + tdTypeSql - + tdNameFilterSql - + urgentSql - + " and i.settleaccountsdepart is not null " - + groupBySql - + ") t " - + groupBySqlOfT; - }else{ - tousseSql = " (select "+ tousseMaterialAmountSql +" i.depart,i.settleAccountsDepart "+ iSendTimeSqlOfShowTime + iSendTime + tousseDefinitionOfSupplierNameSql + integralOftousseDefinitionSql +",ii.tousseName as name,sum(ii.amount) as amount," - +"sum(ii.settlementPrice) as settlementprice,sum(ii.settlementDiscountPrice) as settlementDiscountPrice,ii.tousseType as type" - + unitSqlOftousseDefinitionSql - + ",'' as batchNumber,null as expDate,ii.tousseDefinitionId as tousseDefinitionId " - + tdcTousseGroupNameSQL - + "from invoice i" - + " join InvoiceItem ii on i.id = ii.invoice_id " - + addTousseDefinitionAtWhere - + " where ii.diposable = '否' and ii.expensiveGoodsInstanceId is null and "+ getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - + monthFilterSql - + iDepartCodingSql - + departFilterSql - + typeFilterSql - + goodsNameFilterSql - + " and i.settleaccountsdepart is not null group by i.depart"+ tdcTousseGroupNameSQL + groupByIsendTimeOfShowTime + groupByIsendTime + unitSqlOftousseDefinitionSql +",i.settleAccountsDepart,ii.tousseType,ii.tousseName,ii.tousseDefinitionId " + tousseDefinitionOfSupplierNameSql + integralOftousseDefinitionSql + ")"; - } - //新的高值耗材(发货) - String selectExpensiveGoodsSql = ""; - //如果有启用高值耗材则查询 - if(enableExpensiveGoods){ - selectExpensiveGoodsSql = " union all (select "+ noMaterialAmountSql +" i.depart,i.settleAccountsDepart"+ iSendTimeSqlOfShowTime + iSendTime + noQuerySupplierName + noQueryIntegralSql +",case when egm.model is null then eg.name else eg.name "+ concatSymbolInDb +" '[' "+ concatSymbolInDb +" egm.model "+ concatSymbolInDb +" ']' end as name,sum(ii.amount) as amount," - +"sum(ii.settlementPrice) as settlementprice,sum(ii.settlementDiscountPrice) as settlementDiscountPrice,ii.tousseType as type" - + noQueryUnitSql - + ",'' as batchNumber,ei.expDate as expDate,0 as tousseDefinitionId" - + nullTousseGroupNameSQL - + " from " + Invoice.class.getSimpleName() + " i join " - + InvoiceItem.class.getSimpleName()+" ii on i.id = ii.invoice_id join " + ExpensiveGoodsInstance.class.getSimpleName() - + " ei on ei.id = ii.expensiveGoodsInstanceId" - + " join ExpensiveGoods eg on ei.expensiveGoods_id=eg.id " - + " left join ExpensiveGoodsModel egm on ei.expensiveGoodsModelId=egm.id" - + " where ii.diposable = '否' and " - + getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - + monthFilterSql - + departFilterSql - + iDepartCodingSql - + typeFilterSql - + goodsNameFilterSql - + " and i.settleaccountsdepart is not null group by i.depart"+ groupByIsendTime +",i.settleAccountsDepart,ii.tousseType,case when egm.model is null then eg.name else eg.name "+ concatSymbolInDb +" '[' "+ concatSymbolInDb +" egm.model "+ concatSymbolInDb +" ']' end,ii.expensiveGoodsInstanceId,ei.expDate)"; - //新的高值耗材(一键退库-即退货),如果所选物品类型为全部或高值耗材时, - String orgUnitCodingSql = departCodingSet.size() > 0?" and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("i.orgUnitCoding", departCodingSet):""; - selectExpensiveGoodsSql += " union all (select "+ noMaterialAmountSql +" i.depart,i.settleAccountsDepart " + iSendTimeSqlOfShowTime + iSendTime + noQuerySupplierName + noQueryIntegralSql +",case when egm.model is null then eg.name else eg.name "+ concatSymbolInDb +" '[' "+ concatSymbolInDb +" egm.model "+ concatSymbolInDb +" ']' end as name,-1 * count(egi.id) as amount,-1 * sum(egi.price) settlementprice,-1 * sum(egi.price) settlementprice,'高值耗材' as type" - + noQueryUnitSql - + ",null as batchNumber,egi.expDate,null as tousseDefinitionId " - + nullTousseGroupNameSQL - + " from ExpensiveGoodsGodownEntry egge join ExpensiveGoodsGodownEntryItem eggei on egge.id=eggei.expensiveGoodsGodownEntry_id " - +" join ExpensiveGoodsInstance egi on egi.id=eggei.expensiveGoodsInstanceId " - +" join Invoice i on egi.invoiceId=i.id " - +" join ExpensiveGoods eg on egi.expensiveGoods_id=eg.id " - +" left join ExpensiveGoodsModel egm on egi.expensiveGoodsModelId=egm.id " - +" where 1=1 and egge.type='退库单' " - + orgUnitCodingSql - + expensiveGoodsMonthFilterSql - + (StringUtils.isBlank(typeSearch) || StringUtils.equals(ExpensiveGoods.TYPE_NAME, typeSearch) ? " " : " and 1=2 ") - + departFilterSql - + iDepartCodingSql - + expensiveGoodsNameFilterSql - + " and i.settleaccountsdepart is not null group by i.depart"+ groupByIsendTimeOfShowTime + groupByIsendTime +",i.settleAccountsDepart,case when egm.model is null then eg.name else eg.name "+ concatSymbolInDb +" '[' "+ concatSymbolInDb +" egm.model "+ concatSymbolInDb +" ']' end,egi.expDate)"; - } - - String diposableGoodsSql = " "; - String invoiceJoinInvoicePlanSql = null; - String excludeSciProjectSql = null; - String excludeDiposableGoodsItemSql = null; - if(excludeSciProjectInfo){//排除属于科研项目的一次性物品申请单的发货数据 - invoiceJoinInvoicePlanSql = " left join "+ InvoicePlan.class.getSimpleName() +" ip on i.invoicePlan_ID=ip.id "; - excludeSciProjectSql = " and (ip.projName is null or ip.projName='')"; - excludeDiposableGoodsItemSql = " and dgi.invoice_id in (select i.id from "+ Invoice.class.getSimpleName() +" i left join "+ InvoicePlan.class.getSimpleName() +" ip on ip.id=i.invoicePlan_ID where (ip.projName is null or ip.projName='') and dgi.invoice_id=i.id) "; - }else{ - invoiceJoinInvoicePlanSql = ""; - excludeSciProjectSql = ""; - excludeDiposableGoodsItemSql = ""; - } - if(StringUtils.isBlank(typeSearch) || typeSearch.contains("一次性物品")){ - diposableGoodsSql += " union all (select "+ noMaterialAmountSql +" i.depart,i.settleaccountsdepart "+ iSendTimeSqlOfShowTime + iSendTime + dgbsOfSupplierNameSql+noQueryIntegralSql +",d.name as name,sum(d.amount) as amount," - +"sum(d.fluctuationPrice*d.amount) as settlementprice,sum(d.fluctuationPrice*d.amount) as settlementDiscountPrice,'一次性物品' as type" - + unitDSqlOfDiposableGoodsItem - + ",d.batch as batchNumber,dgbs.expDate,0 as tousseDefinitionId " - + nullTousseGroupNameSQL - + " from invoice i join DiposableGoodsItem d on d.invoice_id=i.id join " + DisposableGoodsBatchStock.class.getSimpleName() + " dgbs on d.disposableGoodsBatchStockID=dgbs.id " - + invoiceJoinInvoicePlanSql - + " where 1=1 and " - + getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - +" and "+diposableGoodsItemPredicate - + monthFilterSql - + excludeSciProjectSql - + departFilterSql - + iDepartCodingSql - + nameFilterSql - + " group by 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," - +"sum(d.fluctuationPrice*d.amount) as settlementprice,sum(d.fluctuationPrice*d.amount) as settlementDiscountPrice,'一次性物品' as type" - + unitDSqlOfDiposableGoodsItem - + ",d.batch as batchNumber,dgbs.expDate,0 as tousseDefinitionId" - + nullTousseGroupNameSQL - + " from invoice i join DiposableGoodsItem d on d.invoice_id=i.id join " + DisposableGoodsBatchStock.class.getSimpleName() + " dgbs on d.disposableGoodsBatchStockID=dgbs.id " - + invoiceJoinInvoicePlanSql - + " where " - + getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - +" and "+diposableGoodsItemPredicate - + monthFilterSql - + excludeSciProjectSql - + departFilterSql - + iDepartCodingSql - + nameFilterSql - + " and d.expensiveDisposablegoodsId is not null " - + expensiveDisposablegoodsIdSql - + " group by i.depart"+ groupByIsendTimeOfShowTime + groupByIsendTime + unitDGroupBySqlOfDiposableGoodsItem +",i.settleaccountsdepart,d.name,d.batch,dgbs.expDate "+ dgbsOfSupplierNameSql +") "; - } - if(typeSearch.contains(TYPE_AUTO_DEDUCTION)){ - diposableGoodsSql += " union all (select "+ noMaterialAmountSql +" i.depart,i.settleaccountsdepart "+ iSendTimeSqlOfShowTime + iSendTime+ dgbsOfSupplierNameSql+noQueryIntegralSql +",d.name as name,sum(d.amount) as amount," - +"sum(d.fluctuationPrice*d.amount) as settlementprice,sum(d.fluctuationPrice*d.amount) as settlementDiscountPrice,'一次性物品' as type" - + unitDSqlOfDiposableGoodsItem - + ",d.batch as batchNumber,dgbs.expDate,0 as tousseDefinitionId" - + nullTousseGroupNameSQL - + " from invoice i join DiposableGoodsItem d on d.invoice_id=i.id join " + DisposableGoodsBatchStock.class.getSimpleName() + " dgbs on d.disposableGoodsBatchStockID=dgbs.id " - + invoiceJoinInvoicePlanSql - + " where 1=1 and " - + getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - +" and "+diposableGoodsItemPredicate - + String.format(" and d.type='%s' ", InvoiceItem.TYPE_AUTO_DEDUCTION) - + monthFilterSql - + excludeSciProjectSql - + departFilterSql - + iDepartCodingSql - + nameFilterSql - + " group by i.depart"+ groupByIsendTimeOfShowTime + groupByIsendTime + unitDGroupBySqlOfDiposableGoodsItem +",i.settleaccountsdepart,d.name,d.batch,dgbs.expDate "+ dgbsOfSupplierNameSql +") "; - } - } - String packingDisposableGoodsSql = " "; - { - if(StringUtils.isBlank(typeSearch) || "一次性物品".equals(typeSearch)){ - packingDisposableGoodsSql = " union all (select "+ noMaterialAmountSql +" pr.depart,pr.orgUnitName "+ prPackTimeSqlOfShowTime + noSendTime + dgbsOfSupplierNameSql + noQueryIntegralSql +",dgi.name as name,sum(dgi.amount) as amount," - +"sum(dgi.fluctuationPrice*dgi.amount) as settlementprice,sum(dgi.fluctuationPrice*dgi.amount) as settlementDiscountPrice,'一次性物品' as type" - + unitDGISqlOfDiposableGoodsItem - + ",dgi.batch as batchNumber,dgbs.expDate,0 as tousseDefinitionId" - + nullTousseGroupNameSQL - + " from PackingRecord pr inner join DiposableGoodsItem dgi on pr.id = dgi.packingRecordId " - + " inner join " + DisposableGoodsBatchStock.class.getSimpleName() + " dgbs on dgi.disposableGoodsBatchStockID=dgbs.id" - + " where " - + getHandleDeptCodeSql("pr.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - +" and "+packingDisposableGoodsTypeSql - + packingDisposableGoodsTimeSql - + packingDisposableGoodsDepartSql - + prDepartCodingSql - + excludeDiposableGoodsItemSql - + packingDisposableGoodsNameSql -// + expensiveDisposablegoodsSql - + " group by pr.depart"+ groupByPrPackTimeOfShowTime + unitDGIGroupBySqlOfDiposableGoodsItem +",pr.orgUnitName,dgi.name,dgi.batch,dgbs.expDate "+ dgbsOfSupplierNameSql +") "; - } - } - - String materialInvoiceSql = " "; - String materialReturnSql = " "; - String lostMaterial = " "; - String damageMaterial = " "; - //当批次号为空时、且物品类型为空或器械材料或高值耗材时,才查询材料的发货、退货、丢失报损补充等数据 - if(StringUtils.isBlank(batch)){ - if ((StringUtils.isBlank(typeSearch) || typeSearch.contains("器械材料") || typeSearch.contains("高值耗材"))) { - // 材料发货 - materialInvoiceSql = " union all (select "+ noMaterialAmountSql +"i.depart,i.settleAccountsDepart "+ iSendTimeSqlOfShowTime + iSendTime +noQuerySupplierName + noQueryIntegralSql +",case when td.name is null then ii.materialName else ii.materialName "+ concatSymbolInDb +"'('"+ concatSymbolInDb +" td.name "+ concatSymbolInDb +"')' end,sum(ii.amount),sum(ii.settlementPrice)," - +"sum(ii.settlementPrice) as settlementDiscountPrice,'材料' as type" - + unitDSqlOfMd - + ",'' as batchNumber,null as expDate,td.id as tousseDefinitionId " - + tdcTousseGroupNameSQL - + " from MaterialInvoiceItem ii" - + " left join TousseDefinition td on td.id= ii.tousseDefinitionId " - + tdLeftJoinTdcSQL - + " inner join MaterialInvoice i on i.id = ii.materialInvoice_id " - + " inner join materialDefinition d on ii.materialDefinitionId = d.id where " - + getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - + monthFilterSql - + departFilterSql - + iDepartCodingSql - + materialNameFilterSql - + materialTypeFilterSql - + " group by i.depart" + tdcTousseGroupNameSQL + groupByIsendTimeOfShowTime + groupByIsendTime + unitDSqlOfMd +",i.settleaccountsdepart,case when td.name is null then ii.materialName else ii.materialName "+ concatSymbolInDb +" '(' "+ concatSymbolInDb +" td.name "+ concatSymbolInDb +"')' end,td.id) "; - } - if(StringUtils.isBlank(typeSearch) || "全部".equals(typeSearch) || typeSearch.contains("器械材料")){ - // 材料退货 - materialReturnSql = " union all (select "+ noMaterialAmountSql +"rr.depart,rr.settleAccountsDepart " + rrReturnTimeSqlOfShowTime + noSendTime + noQuerySupplierName + noQueryIntegralSql +",ii.materialName,-sum(ii.amount),-sum(ii.settlementPrice)," - +"-sum(ii.settlementPrice) as settlementDiscountPrice,'材料' as type" - + unitDSqlOfMd - + ",'' as batchNumber,null as expDate,0 as tousseDefinitionId " - + nullTousseGroupNameSQL - + " from ReturnMaterialRecord rr,materialDefinition d," - + "ReturnMaterialItem ii where rr.id = ii.returnMaterialRecord_ID " - + " and ii.materialDefinitionId = d.id and " - + getHandleDeptCodeSql("rr.handleDepartCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - + returnGoodsTimeFilterSql - + returnGoodsDepartFilterSql - + rrDepartCodingSql - + materialNameFilterSql - + materialTypeFilterSql - + " group by rr.depart"+ groupByRrReturnTimeOfShowTime + unitDSqlOfMd +",rr.settleAccountsDepart,ii.materialName) "; - } - lostMaterial = " union all (select "+ noMaterialAmountSql +"i.depart, i.settleAccountsDepart " + iOperationTimeSqlOfShowTime + noSendTime +noQuerySupplierName + noQueryIntegralSql +",i.materialName,sum(i.additionalAmount),sum(i.additionalAmount * i.materialCost)," - +"sum(i.additionalAmount * i.materialCost) as settlementDiscountPrice,'材料' as type" - + unitMSqlOfMd - + ",'' as batchNumber,null as expDate,0 as tousseDefinitionId " - + nullTousseGroupNameSQL - + " from MaterialErrorDamageDetail i left join materialDefinition m on i.materialDefinitionId = m.id where 1=1 and i.errorType = '缺失' and i.type = '"+MaterialErrorDamageDetail.TYPE_ERROR+"' and i.materialName != '器械包标识牌' and i.additionalAmount > 0 and " - + getHandleDeptCodeSql("i.handleDepartCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - + lostMaterialFilterSql - + iDepartCodeSql - + "group by i.depart"+ groupByIOperationTimeOfShowTime + unitMSqlOfMd +",i.settleAccountsDepart,i.materialName ) "; - String banQuery = " and 1 = 0 "; - String damagedTousseAtCost = config.getDamagedTousseAtCost(); - /*if(StringUtils.isBlank(damagedTousseAtCost) || Constants.STR_YES.equals(damagedTousseAtCost)){ - banQuery = ""; - }*/ - if(Constants.STR_YES.equals(damagedTousseAtCost)){ - banQuery = ""; - } - damageMaterial = " union all (select "+ noMaterialAmountSql +"i.depart,i.settleAccountsDepart " + iOperationTimeSqlOfShowTime + noSendTime +noQuerySupplierName + noQueryIntegralSql +",i.materialName,sum(i.additionalAmount),sum(i.materialCost*i.additionalAmount)," - +"sum(i.materialCost*i.additionalAmount) as settlementDiscountPrice,'材料' as type" - + unitMSqlOfMd - + ",'' as batchNumber,null as expDate,0 as tousseDefinitionId " - + nullTousseGroupNameSQL - + "from MaterialErrorDamageDetail i left join materialDefinition m on i.materialDefinitionId = m.id where 1=1 " - + banQuery - + " and i.type = '" + MaterialErrorDamageDetail.TYPE_DAMAGE + "' and i.additionalAmount > 0 and " - + getHandleDeptCodeSql("i.handleDepartCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - + damageFilterSql - + iDepartCodeSql - + " group by i.depart" - + groupByIOperationTimeOfShowTime - + unitMSqlOfMd - + ",i.settleAccountsDepart,i.materialName ) "; - } - //退货(一次性物品、器械包) - String returnGoodsSql = null; - if(queryUrgent){ - returnGoodsSql = " union all (select " - + tousseInstanceMaterialAmountSql - +" rr.depart,rr.settleAccountsDepart as settleaccountsdepart " - + rrReturnTimeSqlOfShowTime - + noSendTime - + noQuerySupplierName - + noQueryIntegralSql - +",td.name," - + "-count(*) as amount,-sum(ti.price) as settlementprice,-sum(ti.discountPrice) as settlementDiscountPrice," - +" td.toussetype as type "; - if(queryUnit){ - returnGoodsSql += ",td.unit"; - } - returnGoodsSql += ",null as batchNumber,null expDate,td.id as tousseDefinitionId" - + tdcTousseGroupNameSQL - + " from " - + ReturnGoodsRecord.class.getSimpleName() + " rr inner join " - + ReturnGoodsItem.class.getSimpleName()+ " ri on rr.id = ri.returngoodsrecord_id " - + "join " - + TousseInstance.class.getSimpleName() - +" ti on ti.returnGoodsItem_ID=ri.id " - + " join " + TousseDefinition.class.getSimpleName() - + " td on td.id=ti.tousseDefinition_id" - + tdLeftJoinTdcSQL - + " where " - + getHandleDeptCodeSql("rr.handleDepartCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - + returnGoodsFilterSql - + urgentSql - + rrSettleAccountsDepartCodingSql - +" and "+returnGoodsItemPredicate - + " group by rr.depart" - + tdcTousseGroupNameSQL; - if(queryUnit){ - returnGoodsSql += ",ri.disposableGoodsID,td.unit "; - } - returnGoodsSql += groupByRrReturnTimeOfShowTime + ",rr.settleAccountsDepart,td.name,td.tousseType,td.id) "; - }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," - +returnGoodsTousseType+" as type"; - if(queryUnit){ - returnGoodsSql += ",case when ri.disposableGoodsID is not null THEN (select unit from DisposableGoods where id=ri.disposableGoodsID) else td.unit end unit"; - } - returnGoodsSql += ",ri.batchNumber as batchNumber,dgbs.expDate,"+returnGoodsTousseDefinitionId+" as tousseDefinitionId" - + tdcTousseGroupNameSQL - + " 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" - + tdLeftJoinTdcSQL - + " left join " + DisposableGoodsBatchStock.class.getSimpleName() + " dgbs on ri.disposableGoodsBatchStockID=dgbs.id" - + " where " - + getHandleDeptCodeSql("rr.handleDepartCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - + returnGoodsFilterSql - + rrSettleAccountsDepartCodingSql - +" and "+returnGoodsItemPredicate - + " group by rr.depart" - + tdcTousseGroupNameSQL; - if(queryUnit){ - returnGoodsSql += ",ri.disposableGoodsID,td.unit "; - } - returnGoodsSql += groupByRrReturnTimeOfShowTime + ",rr.settleAccountsDepart,ri.toussename," +returnGoodsTousseType+",ri.batchNumber"+ groupByMaterialAmountAtThatTime +",dgbs.expDate,"+returnGoodsTousseDefinitionId+ dgbsOfSupplierNameSql +") "; - } - - String supplyRoomTousseTypeSql = ""; - /*if(!(StringUtils.isBlank(typeSearch) || typeSearch.contains("一次性物品"))){ - if(typeSearch.contains(TYPE_AUTO_DEDUCTION)){ - supplyRoomTousseTypeSql = String.format(" and rr.type='%s' ", InvoiceItem.TYPE_AUTO_DEDUCTION); - } - }*/ - String supplyRoomDiposableGoodsSql = " union all (select "+ sumRriAmountSql +" rr.depart,rr.depart as settleaccountsdepart "+rrTimeSqlOfShowTime + noSendTime + dgbsOfSupplierNameSql + noQueryIntegralSql +",rri.goodsName,sum(rri.amount)," - +"sum(rri.price*rri.amount) as settlementprice,sum(rri.price*rri.amount) as settlementDiscountPrice,rri.type as type" - + unitDSqlOfMd - + ",dgbs.batchNumber as batchNumber,dgbs.expDate,0 as tousseDefinitionId " - + nullTousseGroupNameSQL - +" from ReceiveRecord rr,ReceiveRecordItem rri left join " + DisposableGoodsBatchStock.class.getSimpleName() + " dgbs " - +" on rri.diposableGoodBatchStock_id = dgbs.id left join DisposableGoods d on d.id = rri.disposableGoodsId where rr.id = rri.receiveRecord_id and " - + getHandleDeptCodeSql("rr.departCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - +supplyRoomDiposableGoodsFilterSqlOFDgbs - +supplyRoomTousseTypeSql - +" and "+receiveRecordItemPredicate - + rrDepartCodingSql - + supplyRoomDiposableGoodsFilterSql - + " group by rr.depart" - + groupByRrTimeOfShowTime - + unitDSqlOfMd - + ",rri.goodsName,rri.amount,rri.type,dgbs.batchNumber,dgbs.expDate "+ unitDSqlOfMd + dgbsOfSupplierNameSql +") "; - // 调拨出库 - String appropriateOutDiposableGoodsSql = " union all (select "+ noMaterialAmountSql +" oge.targetOrgUnitName depart ,oge.targetOrgUnitName as settleaccountsdepart" + ogeTimeSqlOfShowTime + noSendTime +dgbsOfSupplierNameSql+noQueryIntegralSql+",ged.goodsName,sum(ged.amount)," - +"sum(ged.price*ged.amount) as settlementprice,sum(ged.price*ged.amount) as settlementDiscountPrice,'一次性物品' as type" - +unitDGSqlOfDisposableGoods - + ",dgbs.batchNumber as batchNumber,dgbs.expDate,0 as tousseDefinitionId " - + nullTousseGroupNameSQL - +" from GodownEntry oge inner join GodownEntryDiposableGoodsItem ged on oge.id = ged.godownEntryID inner join DisposableGoodsBatch dgbs on ged.disposableGoodsBatchID=dgbs.id inner join DisposableGoods dg on dgbs.diposablegoods_id = dg.id " - +" where oge.type ='退库单' and oge.subType='调拨出库' and " - + getHandleDeptCodeSql("oge.orgUnitCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - +outEntryFilterSql - + ogeTargetOrgUnitCodeSql - +" and "+outEntryPredicate - + " group by oge.targetOrgUnitName, ged.goodsName,dgbs.batchNumber,dgbs.expDate "+ groupByOgeTimeOfShowTime + unitDGSqlOfDisposableGoods + dgbsOfSupplierNameSql +") "; - // 盘亏出库 - String stocktakeOutDiposableGoodsSql = " union all (select "+ noMaterialAmountSql +" oge.orgUnitName depart, oge.orgUnitName" +dgbsOfSupplierNameSql+" as settleaccountsdepart"+ ogeTimeSqlOfShowTime + noSendTime + noQueryIntegralSql +",ged.goodsName,sum(ged.amount)," - +"sum(ged.price*ged.amount) as settlementprice,sum(ged.price*ged.amount) as settlementDiscountPrice,'一次性物品' as type" - +unitDGSqlOfDisposableGoods - + ",dgbs.batchNumber as batchNumber,dgbs.expDate,0 as tousseDefinitionId " - + nullTousseGroupNameSQL - +" from GodownEntry oge inner join GodownEntryDiposableGoodsItem ged on oge.id = ged.godownEntryID inner join DisposableGoodsBatch dgbs on ged.disposableGoodsBatchID=dgbs.id inner join DisposableGoods dg on dgbs.diposablegoods_id = dg.id " - +" where oge.type ='退库单' and oge.subType='盘亏出库' and " - + getHandleDeptCodeSql("oge.orgUnitCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) - +outEntryFilterSql - + ogeOrgUnitCodeSql - +" and "+outEntryPredicate - + " group by oge.orgUnitName, ged.goodsName,dgbs.batchNumber,dgbs.expDate" + groupByOgeTimeOfShowTime + unitDGSqlOfDisposableGoods + dgbsOfSupplierNameSql+") "; - - - String sql = tousseSql + selectExpensiveGoodsSql + diposableGoodsSql + supplyRoomDiposableGoodsSql ; - - if(!TYPE_AUTO_DEDUCTION.equals(typeSearch)){ - sql += materialInvoiceSql; - sql += returnGoodsSql; - sql += materialReturnSql; - sql += appropriateOutDiposableGoodsSql; - sql += stocktakeOutDiposableGoodsSql; - sql += packingDisposableGoodsSql; -// sql += materialInvoiceSql; -// sql += materialInvoiceSql; - } - - if (StringUtils.isBlank(typeSearch) || typeSearch.contains("器械包") || typeSearch.contains("器械材料") || typeSearch.contains("全部") || StringUtils.isBlank(typeSearch) || typeSearch.contains("全部器械包") || typeSearch.contains("高值耗材")) { - sql += lostMaterial; - sql += damageMaterial; - } - String chargeDateSql = "";//收费项目时间过滤 - if(!queryUrgent && (StringUtils.isBlank(typeSearch) || typeSearch.contains(TYPE_CHARGE) || typeSearch.contains(TYPE_ALL))){ - if(StringUtils.isNotBlank(startTime) && StringUtils.isNotBlank(endTime)){ - chargeDateSql = String.format(" and chargeTime %s ", betweenSql); - } - if(CollectionUtils.isNotEmpty(departCodingSet)){ - chargeDepartSql = String.format(" and %s ", SqlUtils.getStringFieldInLargeCollectionsPredicate("ci.orgUnitCode", departCodingSet)); - } - } - if(!queryUrgent && StringUtils.isNotBlank(typeSearch) && typeSearch.contains(TYPE_CHARGE)){ - String chargeSql = String.format(" union all select "+ noMaterialAmountSql +"ci.orgUnitName depart, ci.orgUnitName settleAccountsDepart" + crChargeTimeSqlOfShowTime + noSendTime + noQuerySupplierName + noQueryIntegralSql +",chargeItem name,1 amount,price settlementprice,0 settlementDiscountPrice,'收费项目' type "+ noQueryUnitSql +",'' batchNumber,NULL as expDate ,null as tousseDefinitionId " - + nullTousseGroupNameSQL - + " from ChargeRecordItem ci inner join ChargeRecord cr on cr.id=ci.chargeRecord_id where 1=1 %s %s %s %s group by ci.orgUnitName,chargeItem,price,chargeTime " - + groupByCrChargeTimeOfShowTime - , chargeDepartSql,chargeDateSql,chargeItemSql, - ciOrgUnitCodeSql); - sql += chargeSql; - }else if(!queryUrgent && StringUtils.isBlank(typeSearch)){ - sql += String.format(" union all select "+ noMaterialAmountSql +"ci.orgUnitName depart,ci.orgUnitName settleAccountsDepart" + crChargeTimeSqlOfShowTime + noSendTime + noQuerySupplierName + noQueryIntegralSql +",chargeItem name,1 amount,price settlementprice,0 settlementDiscountPrice,'收费项目' type "+ noQueryUnitSql +",'' batchNumber,NULL as expDate ,null as tousseDefinitionId " - + nullTousseGroupNameSQL - + " from ChargeRecordItem ci inner join ChargeRecord cr on cr.id=ci.chargeRecord_id where 1=1 %s %s %s %s group by ci.orgUnitName,chargeItem,price,chargeTime " - + groupByCrChargeTimeOfShowTime - , chargeDepartSql,chargeDateSql,chargeItemSql, - ciOrgUnitCodeSql); - } - if(queryUrgent){ - sql = tousseSql + returnGoodsSql; - } - String database = dbConnection.getDatabase(); - if (dbConnection.isSqlServer()) { - String orderSql = null; - if(showSendTime){ - orderSql = " order by sendTime desc,settleaccountsdepart,type"; - }else if(showTime){ - orderSql = " order by showTime desc,settleaccountsdepart,type"; - }else{ - orderSql = " order by settleaccountsdepart,type"; - } - sql += orderSql; - } - - logger.debug("明细核算月报执行sql:" + sql); - - Map> detailMap = new HashMap>(); - Map manufacturerMap = getDiposableGoodsManufacturer(); - - Map disposableGoodsExternalCodeMap = disposableGoodsExternalCodeMap(); - Map expensiveExternalCode = expensiveExternalCode(); - Map materialExternalCodeMap = getMaterialExternalCode(); - Map tousseExternalCodeMap = getTousseExternalCode(); - ResultSet rs = null; - - try { - rs = objectDao.executeSql(sql); - Set toussedefinitionIdSet = new HashSet();//需要查询材料实例数量的包定义id - Map itemAndTDid = new HashMap();//,用于给DepartmentMonthDetailItem计算price和totalAmount - while (rs.next()) { - String settleaccountsdepart = rs.getString("settleaccountsdepart"); - if(StringUtils.isBlank(settleaccountsdepart)){ - settleaccountsdepart = ""; - } - String depart = rs.getString("depart"); - if(StringUtils.isBlank(depart)){ - depart = ""; - } - String departKey = settleaccountsdepart + ";_;" + depart; - List itemList = detailMap.get(departKey); - if (itemList == null) { - itemList = new ArrayList(); - detailMap.put(departKey, itemList); - } - String goodsName = rs.getString("name"); - String type = rs.getString("type"); - double settlementPrice = rs.getDouble("settlementprice"); - double settlementDiscountPrice = rs.getDouble("settlementDiscountPrice"); - int amount = rs.getInt("amount"); - Date expDate = null; - if(!TYPE_CHARGE.equals(type)){ - try { - expDate = rs.getTimestamp("expDate"); - } catch (Exception e) { - } - - } - int disinfectGoodsStatisticAmount = 0; - int totalAmount = amount; - DepartmentMonthDetailItem mdi = new DepartmentMonthDetailItem(); - if(queryTousseGroupName){ - mdi.setTousseGroupName(rs.getString("tousseGroupName")); - } - boolean flag = true; - if (TousseDefinition.PACKAGE_TYPE_DISINFECTION.equals(type) - || (TousseDefinition.PACKAGE_TYPE_CUSTOM.equals(type) && !showCustonTousseAmount)) { - Long toussedefinitionId = rs.getLong("tousseDefinitionId"); - if (DatabaseUtil.isPoIdValid(toussedefinitionId)) { - toussedefinitionIdSet.add(toussedefinitionId);//记下id,一次性查询对应的材料实例数量 - mdi.setAmount(totalAmount); - itemAndTDid.put(mdi, toussedefinitionId); - flag = false;//先不计算价格和总数量,批量查询时再计算 - } - } - if(flag){ - Double price = 0D; - if(totalAmount != 0){ - price = MathTools.divide(settlementPrice, totalAmount, 4); - } - mdi.setPrice(price); - mdi.setAmount(totalAmount); - } -// goodsName = CssdUtils.filterUnderScoreName(goodsName); - - Double price = 0D; - if(totalAmount != 0){ - price = MathTools.divide(settlementPrice, totalAmount, 4); - } - if(showSupplierNameInDetailedAccountingMonthlyReport){ - if(TousseDefinition.PACKAGE_TYPE_FOREIGN.equals(type) || TousseDefinition.PACKAGE_TYPE_SPLIT.equals(type) - || DisposableGoods.TYPE_NAME.equals(type)){ - String supplierName = rs.getString("supplierName"); - mdi.setSupplierName(supplierName); - } - } - if(showSendTime){ - mdi.setSendTime(rs.getString("sendTime")); - } - if(showTime){ - mdi.setShowTime(rs.getString("showTime")); - } - mdi.setType(type); - mdi.setSettlementPrice(settlementPrice); - mdi.setSettlementDiscountPrice(settlementDiscountPrice); - mdi.setBatchNumber(rs.getString("batchNumber")); - if(queryUnit){ - mdi.setUnit(rs.getString("unit")); - } - mdi.setExpDate(ForgonDateUtils.safelyFormatDate(expDate, Constants.SIMPLEDATEFORMAT_YYYYMMDD, "")); - if ("一次性物品".equals(type)) { - mdi.setManufacturer(manufacturerMap.get(goodsName + "_" + mdi.getBatchNumber())); - mdi.setExternalCode(disposableGoodsExternalCodeMap.get(goodsName)); - }else if("材料".equals(type)){ - mdi.setExternalCode(materialExternalCodeMap.get(goodsName)); - }else{ - if(enableExpensiveGoods && ExpensiveGoods.TYPE_NAME.equals(type)){ - //新的高值耗材设置外部编码及生产厂家 - mdi.setExternalCode(expensiveExternalCode.get(goodsName)); - }else{ - mdi.setExternalCode(tousseExternalCodeMap.get(goodsName)); - } - } - if(queryUnit && DisposableGoods.TYPE_NAME.equals(type)){ - int beginIndex = goodsName.indexOf("["); - int endIndex = goodsName.lastIndexOf("]"); - if(beginIndex != -1 && endIndex != -1){ - String specification = goodsName.substring(beginIndex + 1, endIndex); - goodsName = goodsName.substring(0, beginIndex); - mdi.setSpecification(specification); - } - } - mdi.setGoodsName(goodsName); - if(showMaterialsAmountColumnOfDetailMonthReport){ - if("一次性物品".equals(type) || "材料".equals(type) || ExpensiveGoods.TYPE_NAME.equals(type) || "收费项目".equals(type) || "高值耗材".equals(type)){ - mdi.setMaterialAmount(totalAmount); - }else{ - mdi.setMaterialAmount(ConvertNumber.getNumberIntValue(rs.getObject("materialAmount"), 0)); - } - } - if(enableToussePointsStatistics){ - Number integralNum = (Number)rs.getObject("integral"); - if(integralNum != null){ - mdi.setIntegral(integralNum.doubleValue() * totalAmount); - } - } - itemList.add(mdi); - } - //统一计算要查询包定义对应的材料实例数量的DepartmentMonthDetailItem的price和totalAmount - calcPriceAndAmout(toussedefinitionIdSet, itemAndTDid); - } catch (SQLException e) { - logger.error("获取明细核算月报数据时出错", e); - }finally { - DatabaseUtil.closeResultSetAndStatement(rs); - } - for(Entry> entry : detailMap.entrySet()){ - String departKey = entry.getKey(); - List list = entry.getValue(); - //消毒物品,自定义器械包,外来器械包,外来器械拆分小包相同名称的合并 - Map tmpMap = new HashMap(); - List removeItems = new ArrayList(); - double totalPrice = 0.0d; - double totalPriceDiscount = 0.0d; - Map disposableGoodsTempMap = new HashMap(); - for (DepartmentMonthDetailItem dmi : list) { - String tousseName = dmi.getGoodsName(); - String sendTime = dmi.getSendTime(); - String dmiShowTime = dmi.getShowTime(); - String key = null; - if(showTime){ - key = dmiShowTime + tousseName; - }else if(showSendTime){ - key = sendTime + tousseName; - } else{ - key = tousseName; - } - 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)) { - DepartmentMonthDetailItem item = tmpMap.get(key); - if(item == null){ - item = new DepartmentMonthDetailItem(); - item.setAmount(0); - item.setPrice(0d); - item.setSettlementPrice(0d); - item.setSettlementDiscountPrice(0d); - item.setMaterialAmount(0); - item.setSendTime(sendTime); - item.setExternalCode(tousseExternalCodeMap.get(tousseName)); - if(showTime){ - item.setShowTime(dmiShowTime); - } - if(queryTousseGroupName){ - item.setTousseGroupName(dmi.getTousseGroupName()); - } - tmpMap.put(key, item); - } - if(dmi.getMaterialAmount() != null){ - item.setMaterialAmount(MathTools.add(item.getMaterialAmount(), dmi.getMaterialAmount()).intValue()); - } - item.setIntegral(MathTools.add(item.getIntegral(), dmi.getIntegral()).doubleValue()); - item.setAmount(item.getAmount()+dmi.getAmount()); - item.setBatchNumber(dmi.getBatchNumber()); - item.setDiposable(dmi.getDiposable()); - item.setExpDate(dmi.getExpDate()); - item.setGoodsName(tousseName); - item.setManufacturer(dmi.getManufacturer()); - item.setSettlementPrice(item.getSettlementPrice() + dmi.getSettlementPrice()); - 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(); - item.setPrice(price); - removeItems.add(dmi); - }else if(!showBatch && DisposableGoods.TYPE_NAME.equals(type)){//一次性物品 - DepartmentMonthDetailItem item = null; - if(disposableGoodsTempMap.containsKey(key)){ - item = disposableGoodsTempMap.get(key); - item.setAmount(item.getAmount()+dmi.getAmount()); - item.setDiposable(dmi.getDiposable()); - item.setGoodsName(tousseName); - if(dmi.getMaterialAmount() != null){ - item.setMaterialAmount(MathTools.add(item.getMaterialAmount(), dmi.getMaterialAmount()).intValue()); - } - item.setManufacturer(dmi.getManufacturer()); - item.setSettlementPrice(item.getSettlementPrice() + dmi.getSettlementPrice()); - 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(); - item.setPrice(price); - removeItems.add(dmi); - }else{ - dmi.setBatchNumber(null); - dmi.setExpDate(null); - dmi.setSendTime(sendTime); - disposableGoodsTempMap.put(key, dmi); - } - } - totalPrice += dmi.getSettlementPrice(); - totalPriceDiscount += dmi.getSettlementDiscountPrice(); - } - list.removeAll(removeItems); - if(tmpMap.size() > 0){ - list.addAll(tmpMap.values()); - } - - if(disposableGoodsTempMap.size() > 0){ - list.addAll(disposableGoodsTempMap.values()); - } - DepartmentMonthDetail detail = new DepartmentMonthDetail(); - String[] departs = departKey.split(";_;"); - for (int i = 0; i < departs.length; i++) { - if(i == 0){ - detail.setDepart(departs[0]); - }else if(i == 1){ - detail.setApplicationDepart(departs[1]); - } - } - detail.setTotalPrice(totalPrice); - detail.setTotalPriceDiscount(totalPriceDiscount); - detail.setItems(list); - sortDetailItems(detail); - datas.add(detail); - } - orderDepartmentMonthDetailList(datas,showSendTime);//数据库里排序无效 - return datas; + return departmentMonthDetailHelper.getDepartmentMonthDetailList(showTime, showSendTime, whetherToCharge, startTime, endTime, departSearch, departCoding, typeSearch, goodsNameSearch, batch, searchType, disinfection, disposableGoodsType, goodsType, showCustonTousseAmount, invoicePlanDepartCoding, departGroupStr, printByDepart, urgentLevel, extendedColumnConfigOfDetailedAccountingMonthlyReport); } - /** - * 对DepartmentMonthDetailList进行排序(按科室供应室配置的科室申领的顺序科室排序) - * @param list - * @param showSendTime 显示发货 按发货排序 - */ - private void orderDepartmentMonthDetailList(List list , boolean showSendTime){ - Map map = supplyRoomConfigManager.getOrgUnitAndSequenceMap(3); - Collections.sort(list, new Comparator() { - @Override - public int compare(DepartmentMonthDetail o1, DepartmentMonthDetail o2) { - int o1sequence = 99999; - if(map.containsKey(o1.getApplicationDepart())){ - o1sequence = map.get(o1.getApplicationDepart()); - } - int o2sequence = 99999; - if(map.containsKey(o2.getApplicationDepart())){ - o2sequence = map.get(o2.getApplicationDepart()); - } - return o1sequence - o2sequence; - } - }); - for (DepartmentMonthDetail departmentMonthDetail : list) { - List items = departmentMonthDetail.getItems(); - Collections.sort(items, new Comparator() { - @Override - 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; - } - } - } - } - }); - } - } - /** - * 将字段去掉前缀返回 - * @param str 要去前缀的字符 - * @return s.name 返回name;s.name name1 返回 name1; ,td.name 返回,name - */ - private String getRemovePrefixSql(String str){ - if(StringUtils.isBlank(str)){ - return ""; - } - str = str.trim(); - String prefix = null; - if(str.startsWith(",")){ - prefix = ","; - }else{ - prefix = ""; - } - if(str.contains(" ")){ - return prefix + str.substring(str.indexOf(" ")); - }else if(str.contains(".")){ - return prefix + str.substring(str.indexOf(".") + 1); - } - return str; - } - //------------------------单个科室的明细核算月报 start--------------- - /** - * 统一计算要查询包定义对应的材料实例数量的DepartmentMonthDetailItem的price和totalAmount - * @param toussedefinitionIdSet 需要查询材料实例数量的包定义id - * @param itemAndTDid ,用于给DepartmentMonthDetailItem计算price和totalAmount - */ - private void calcPriceAndAmout(Set toussedefinitionIdSet, Map itemAndTDid){ - if(toussedefinitionIdSet.size() > 0){ - Map tdIdAndAmountMap = getDisinfectGoodsStatisticAmount(toussedefinitionIdSet); - for (Entry entry : itemAndTDid.entrySet()) { - Long tdId = entry.getValue(); - DepartmentMonthDetailItem item = entry.getKey(); - Integer totalAmount = 0; - if(tdIdAndAmountMap.containsKey(tdId)){ - Integer amount = tdIdAndAmountMap.get(tdId); - if(amount.intValue() != 1 && amount > 0){ - totalAmount = item.getAmount() * amount; - item.setAmount(totalAmount); - } - } - Double price = 0D; - if(totalAmount != 0){ - price = MathTools.divide(item.getSettlementPrice(), totalAmount, 4); - } - item.setPrice(price); - } - } - } - @Override - public List getDepartmentMonthDetailListOfSingleDepart( - String whetherToCharge, String startTime, String endTime, String departSearch, - String departCoding, String typeSearch, String goodsNameSearch, String batch, - String searchType, boolean disinfection, - String disposableGoodsType, String goodsType, - Boolean showCustonTousseAmount, String invoicePlanDepartCoding) { - boolean filterWhetherToCharge = false; - if(StringUtils.isNotBlank(whetherToCharge) && !whetherToCharge.contains("全部")){ - filterWhetherToCharge = true; - } - //数据库拼接符号 - String concatSymbolInDb = "+"; - if(DatabaseUtil.isOracle(dbConnection.getDatabase())){ - concatSymbolInDb = "||"; - } - SupplyRoomConfig config = supplyRoomConfigManager.getSystemParamsObj(); - final String TYPE_AUTO_DEDUCTION = "自动扣减物品"; - final String TYPE_ALL = "全部"; - final String TYPE_CHARGE = "收费项目"; - //是否启用高值耗材(新) - boolean enableExpensiveGoods = CssdUtils.getSystemSetConfigByNameBool("enableExpensiveGoods"); - //是否启用高值耗材(一次性物品的高值耗材) - boolean enableExpensiveDisposableGoods = CssdUtils.getSystemSetConfigByNameBool("enableExpensiveDisposableGoods"); - //启用排除属于科研项目的一次性物品申请单的发货数据 - boolean excludeSciProjectInfo = CssdUtils.getSystemSetConfigByNameBool("enableExcludeInvoiceItemOfDisposableGoodsApplicationBelongToSciProject", false); - //判断当前登录用户是否为匿名用户.如果为匿名用户则只查询一级供应室的数据,否则根据实际情况的条件查询 - String loginUserFullName = AcegiHelper.getLoginUserFullName(); - if(StringUtils.equals(loginUserFullName, Constants.ANONYMOUS_USERNAME)){ - departCoding = supplyRoomConfigManager.getFirstSupplyRoomConfig().getOrgUnitCoding(); - } - List datas = new ArrayList(); - List allTousseType = getTousseTypes(typeSearch); - // 查看是否配置显示供应商 - Boolean showSupplierNameInDetailedAccountingMonthlyReport = CssdUtils.getSystemSetConfigByNameBool("showSupplierNameInDetailedAccountingMonthlyReport", false); - String tousseDefinitionOfSupplierNameSql = "";//用器械包定义里的供应商拼接的sql语句,主要用于查询供应商和按供应商分组 - String addTousseDefinitionAtWhere = "";//拼接sql,用于添加查询TousseDefinition表 - String addJoinTousseDefinitionSql = "";//用于连接InvoiceItem和TousseDefinition - String dgbsOfSupplierNameSql = "";//用于查询DisposableGoodsBatchStock或DisposableGoodsBatch的供应商名称,主要用于查询供应商和按供应商分组 - String noQuerySupplierName = "";//不需要查询器械包名称的sql,用于连接union all连接表时保持列数不变 - if(showSupplierNameInDetailedAccountingMonthlyReport){ - tousseDefinitionOfSupplierNameSql = " ,td.supplierName "; - addTousseDefinitionAtWhere = " join TousseDefinition td on td.id = ii.tousseDefinitionId "; - addJoinTousseDefinitionSql = " and td.id = ii.tousseDefinitionId "; - dgbsOfSupplierNameSql = " ,dgbs.supplierName "; - noQuerySupplierName = ",''"; - } - startTime += ":00"; - endTime += ":59"; - String monthFilterSql = " "; - String expensiveGoodsMonthFilterSql = " "; - String returnGoodsFilterSql = " "; - String returnGoodsTimeFilterSql = " "; - String packingDisposableGoodsTimeSql = " "; - String returnGoodsDepartFilterSql = " "; - String materialNameFilterSql = " "; - String materialTypeFilterSql = " "; - String lostMaterialFilterSql = " "; - String damageFilterSql = " "; - String supplyRoomDiposableGoodsFilterSql = " "; - String outEntryFilterSql = " "; - - String invoiceItemDisposableGoodsTypePredicate = " (1=1) "; - String diposableGoodsItemPredicate = " (1=1) "; - String packingDisposableGoodsTypeSql = " (1=1) "; - String disposableGoodsInvoiceAmountPredicate = " (ii.diposable='是') "; - String returnGoodsItemPredicate = " (1=1) "; - String receiveRecordItemPredicate = " (1=1) "; - String disposableGoodsIdSql = ""; - String outEntryPredicate = " 1=1 "; - if(StringUtils.isNotBlank(disposableGoodsType) || filterWhetherToCharge){ - disposableGoodsIdSql = String.format(" select id from DisposableGoods where 1=1 %s %s", StringUtils.isNotBlank(disposableGoodsType)?" and type='"+ disposableGoodsType +"'":"" - , filterWhetherToCharge?" and whetherToCharge='"+ whetherToCharge +"'":""); - invoiceItemDisposableGoodsTypePredicate = String.format(" (ii.diposable='否' or ii.disposableGoodsId in(%s)) ", disposableGoodsIdSql); - diposableGoodsItemPredicate = String.format(" (d.disposableGoodsID in(%s)) ", disposableGoodsIdSql); - packingDisposableGoodsTypeSql = String.format(" (dgi.disposableGoodsID in(%s)) ", disposableGoodsIdSql); - disposableGoodsInvoiceAmountPredicate = String.format(" (ii.diposable='是' and ii.disposableGoodsId in(%s)) ", disposableGoodsIdSql); - returnGoodsItemPredicate = String.format(" (ri.disposableGoodsId in(%s)) ", disposableGoodsIdSql); - receiveRecordItemPredicate = String.format(" (rri.type!='一次性物品' or rri.disposableGoodsId in(%s)) ", disposableGoodsIdSql); - outEntryPredicate = String.format(" (ged.disposableGoodsID in(%s)) ", disposableGoodsIdSql); - } - String betweenSql = ""; - if (StringUtils.isNotBlank(startTime) && StringUtils.isNotBlank(endTime)) { - betweenSql = new StringBuffer(150).append(" between ") - .append(dateQueryAdapter.dateConverAdapter2( startTime, "yyyy-mm-dd HH24:MI:SS")) - .append(" and ") - .append(dateQueryAdapter.dateConverAdapter2( endTime, "yyyy-mm-dd HH24:MI:SS")).toString(); - monthFilterSql = " and i.sendtime" + betweenSql; - expensiveGoodsMonthFilterSql = " and egge.time" + betweenSql; - returnGoodsTimeFilterSql = " and rr.returntime" + betweenSql; - returnGoodsFilterSql = returnGoodsTimeFilterSql; - packingDisposableGoodsTimeSql = " and pr.packTime"+betweenSql; - lostMaterialFilterSql = " and r.additionalTime" + betweenSql; - damageFilterSql = " and i.additionalTime" + betweenSql; - - supplyRoomDiposableGoodsFilterSql = " and rr.time" + betweenSql; - outEntryFilterSql = " and oge.time" + betweenSql; - } else { - monthFilterSql = " and 1=2 "; - returnGoodsFilterSql = " and 1=2 "; - packingDisposableGoodsTimeSql = " and 1=2 "; - lostMaterialFilterSql = " and 1=2 "; - damageFilterSql = " and 1=2 "; - } - String departFilterSql = ""; - String packingDisposableGoodsDepartSql = ""; - String chargeDepartSql = ""; - if (StringUtils.isNotBlank(departSearch)) { - departFilterSql = " and i.settleaccountsdepart = '" + departSearch - + "'"; - returnGoodsFilterSql += " and rr.settleAccountsDepart = '" + departSearch - + "'"; - returnGoodsDepartFilterSql = " and rr.settleAccountsDepart = '" + departSearch - + "'"; - packingDisposableGoodsDepartSql = " and pr.orgUnitName = '" + departSearch + "'"; - lostMaterialFilterSql += " and r.settleAccountsDepart = '" - + departSearch + "'"; - damageFilterSql += " and i.settleAccountsDepart = '" - + departSearch + "'"; - - supplyRoomDiposableGoodsFilterSql += " and rr.departCoding = '"+departCoding+"'"; - outEntryFilterSql += " and oge.orgUnitCode = '"+departCoding+"'"; - - } - String typeFilterSql = " "; - materialTypeFilterSql = " "; - String expensiveDisposablegoodsSql = ""; - if (StringUtils.isNotBlank(typeSearch)) { - - if ("全部器械包".equals(typeSearch)) { - typeFilterSql = " and ii.diposable = '否' and ii.tousseType <> '" + ExpensiveGoods.TYPE_NAME + "'"; - returnGoodsFilterSql += " and rr.type = '器械包'"; - supplyRoomDiposableGoodsFilterSql += " and 1=2"; - outEntryFilterSql += " and 1=2"; - lostMaterialFilterSql += " and 1=2 "; - damageFilterSql += " and 1=2 "; - returnGoodsItemPredicate = String.format(" ri.tousseDefinition_id in (select id from TousseDefinition where %s) ", SqlUtils.getStringFieldInLargeCollectionsPredicate("tousseType", allTousseType)); - }else if("器械包".equals(typeSearch)) { - typeFilterSql = " and ii.tousseType = '" - + TousseDefinition.PACKAGE_TYPE_INSIDE - + "'"; - returnGoodsFilterSql += " and rr.type = '器械包'"; - supplyRoomDiposableGoodsFilterSql += " and 1=2"; - outEntryFilterSql += " and 1=2"; - lostMaterialFilterSql += " and 1=2 "; - damageFilterSql += " and 1=2 "; - returnGoodsItemPredicate = String.format(" ri.tousseDefinition_id in (select id from TousseDefinition where %s) ", SqlUtils.getStringFieldInLargeCollectionsPredicate("tousseType", allTousseType)); - }else if("敷料包".equals(typeSearch)){ - typeFilterSql = " and ii.tousseType = '" - + TousseDefinition.PACKAGE_TYPE_DRESSING - + "'"; - returnGoodsFilterSql += " and rr.type = '器械包'"; - supplyRoomDiposableGoodsFilterSql += " and 1=2"; - outEntryFilterSql += " and 1=2"; - lostMaterialFilterSql += " and 1=2 "; - damageFilterSql += " and 1=2 "; - returnGoodsItemPredicate = String.format(" ri.tousseDefinition_id in (select id from TousseDefinition where %s) ", SqlUtils.getStringFieldInLargeCollectionsPredicate("tousseType", allTousseType)); - } else if ("消毒物品".equals(typeSearch)) { - typeFilterSql = " and ii.tousseType = '" - + TousseDefinition.PACKAGE_TYPE_DISINFECTION - + "'"; - returnGoodsFilterSql += " and rr.type = '器械包'"; - supplyRoomDiposableGoodsFilterSql += " and 1=2"; - outEntryFilterSql += " and 1=2"; - lostMaterialFilterSql += " and 1=2 "; - damageFilterSql += " and 1=2 "; - returnGoodsItemPredicate = String.format(" ri.tousseDefinition_id in (select id from TousseDefinition where %s) ", SqlUtils.getStringFieldInLargeCollectionsPredicate("tousseType", allTousseType)); - } else if ("外来器械包".equals(typeSearch)) { - typeFilterSql = " and (ii.tousseType = '" - + TousseDefinition.PACKAGE_TYPE_FOREIGN - + "' or ii.tousseType = '" - + TousseDefinition.PACKAGE_TYPE_SPLIT + "') "; - - returnGoodsFilterSql += " and rr.type = '器械包'"; - supplyRoomDiposableGoodsFilterSql += " and 1=2"; - outEntryFilterSql += " and 1=2"; - lostMaterialFilterSql += " and 1=2 "; - damageFilterSql += " and 1=2 "; - returnGoodsItemPredicate = String.format(" ri.tousseDefinition_id in (select id from TousseDefinition where %s) ", SqlUtils.getStringFieldInLargeCollectionsPredicate("tousseType", allTousseType)); - } else if ("自定义器械包".equals(typeSearch)) { - typeFilterSql = " and ii.tousseType = '" - + TousseDefinition.PACKAGE_TYPE_CUSTOM + "'"; - returnGoodsFilterSql += " and rr.type = '器械包'"; - supplyRoomDiposableGoodsFilterSql += " and 1=2"; - outEntryFilterSql += " and 1=2"; - lostMaterialFilterSql += " and 1=2 "; - damageFilterSql += " and 1=2 "; - returnGoodsItemPredicate = String.format(" ri.tousseDefinition_id in (select id from TousseDefinition where %s) ", SqlUtils.getStringFieldInLargeCollectionsPredicate("tousseType", allTousseType)); - } else if ("外部代理灭菌包".equals(typeSearch)) { - typeFilterSql = " and ii.tousseType = '" - + TousseDefinition.PACKAGE_TYPE_FOREIGNPROXY + "'"; - returnGoodsFilterSql += " and rr.type = '器械包'"; - lostMaterialFilterSql += " and 1=2 "; - damageFilterSql += " and 1=2 "; - damageFilterSql += " and 1=2 "; - supplyRoomDiposableGoodsFilterSql += " and 1=2"; - outEntryFilterSql += " and 1=2"; - returnGoodsItemPredicate = String.format(" ri.tousseDefinition_id in (select id from TousseDefinition where %s) ", SqlUtils.getStringFieldInLargeCollectionsPredicate("tousseType", allTousseType)); - } else if ("一次性物品".equals(typeSearch)) { - typeFilterSql = " and ii.tousseType = '一次性物品'"; - returnGoodsFilterSql += " and rr.type = '一次性物品'"; - lostMaterialFilterSql += " and 1=2 "; - damageFilterSql += " and 1=2 "; - supplyRoomDiposableGoodsFilterSql += " and rri.type = '一次性物品' "; - } else if ("器械材料".equals(typeSearch)) { - typeFilterSql = " and 1=2"; - returnGoodsFilterSql += " and 1=2"; - lostMaterialFilterSql += " and 1=1 "; - damageFilterSql += " and 1=1 "; - supplyRoomDiposableGoodsFilterSql += " and rri.materialDefinition_id in (select id from MaterialDefinition) "; - outEntryFilterSql += " and 1=2"; - } else if ("高值耗材".equals(typeSearch)) { - if(enableExpensiveGoods){ - //新的高值耗材 - typeFilterSql = " and ii.diposable = '否' and ii.tousseType = '" + ExpensiveGoods.TYPE_NAME + "'"; - returnGoodsFilterSql += " and 1=2"; - materialTypeFilterSql = " and 1=2 "; - lostMaterialFilterSql += " and 1=2 "; - damageFilterSql += " and 1=2 "; - outEntryFilterSql += " and 1=2"; - //新的高值耗材还没有供应室领用功能 - supplyRoomDiposableGoodsFilterSql += " and 1=2"; - }else{ - //goodsType是高值耗材类型,值有全部、一次性物品、器械 - if(StringUtils.isNotBlank(goodsType)){ - if("一次性物品".equals(goodsType)){ - returnGoodsFilterSql += " and ri.expensiveDisposablegoodsId is not null and ri.expensiveDisposablegoodsId <> 0"; - materialTypeFilterSql = " and 1=2 "; - supplyRoomDiposableGoodsFilterSql += " and d.goodsType = '"+DisposableGoods.TYPE_EXPENSIVEDIPOSABLEGOODS+"'"; - lostMaterialFilterSql += " and 1=2 "; - damageFilterSql += " and 1=2 "; - expensiveDisposablegoodsSql = " and d.expensiveDisposablegoodsId is not null "; - outEntryFilterSql += " and dg.goodsType = '" + DisposableGoods.TYPE_EXPENSIVEDIPOSABLEGOODS + "' "; - }else{ - returnGoodsFilterSql += " and 1=2 "; - materialTypeFilterSql = " and d.goodsType = '"+MaterialDefinition.TYPE_EXPENSIVEMATERIALGOODS+"'"; - supplyRoomDiposableGoodsFilterSql += " and rri.materialDefinition_id in (select id from MaterialDefinition where goodsType = '" - + MaterialDefinition.TYPE_EXPENSIVEMATERIALGOODS + "') "; - lostMaterialFilterSql += " and m.goodsType = '"+MaterialDefinition.TYPE_EXPENSIVEMATERIALGOODS+"' "; - damageFilterSql += " and m.goodsType = '"+MaterialDefinition.TYPE_EXPENSIVEMATERIALGOODS+"' "; - expensiveDisposablegoodsSql = " and 1=2 "; - outEntryFilterSql += " and 1=2 "; - } - }else{ - returnGoodsFilterSql += " and ri.expensiveDisposablegoodsId is not null and ri.expensiveDisposablegoodsId <> 0"; - materialTypeFilterSql = " and d.goodsType = '"+MaterialDefinition.TYPE_EXPENSIVEMATERIALGOODS+"'"; - supplyRoomDiposableGoodsFilterSql += " and rri.materialDefinition_id in (select id from MaterialDefinition where goodsType = '" - + MaterialDefinition.TYPE_EXPENSIVEMATERIALGOODS + "') "; - lostMaterialFilterSql += " and m.goodsType = '"+MaterialDefinition.TYPE_EXPENSIVEMATERIALGOODS+"' "; - damageFilterSql += " and m.goodsType = '"+MaterialDefinition.TYPE_EXPENSIVEMATERIALGOODS+"' "; - expensiveDisposablegoodsSql = " and d.expensiveDisposablegoodsId is not null "; - outEntryFilterSql += " and dg.goodsType = '" + DisposableGoods.TYPE_EXPENSIVEDIPOSABLEGOODS + "' "; - } - typeFilterSql = " and 1=2 "; - } - }else if (TYPE_AUTO_DEDUCTION.equals(typeSearch)) { - typeFilterSql = " and 1=2 "; - }else if(TYPE_ALL.equals(typeSearch)){ - if(!enableExpensiveGoods){ - //没有启用高值耗材,就不查询新的高值耗材的数据 - typeFilterSql = " and ii.tousseType <> '" + ExpensiveGoods.TYPE_NAME + "'"; - } - } - }else{ - if(!enableExpensiveGoods){ - //没有启用高值耗材,就不查询新的高值耗材的数据 - typeFilterSql = " and ii.tousseType <> '" + ExpensiveGoods.TYPE_NAME + "'"; - } - } - String goodsNameFilterSql = " "; - String expensiveGoodsNameFilterSql = " "; - String chargeItemSql = "";//收费项目名称过滤 - if (StringUtils.isNotBlank(goodsNameSearch)) { - if("精确查询".equals(searchType)){ - goodsNameFilterSql = " and ii.toussename = '" + goodsNameSearch - + "'"; - expensiveGoodsNameFilterSql = " and case when egm.model is null then eg.name else eg.name + '[' + egm.model + ']' end = '%" + goodsNameSearch - + "%'"; - returnGoodsFilterSql += " and ri.toussename = '" - + goodsNameSearch + "'"; - materialNameFilterSql = " and ii.materialName = '" - + goodsNameSearch + "' "; - lostMaterialFilterSql += " and r.materialName = '" - + goodsNameSearch + "'"; - damageFilterSql += " and i.materialName = '" - + goodsNameSearch + "'"; - supplyRoomDiposableGoodsFilterSql += " and rri.goodsName = '"+goodsNameSearch+"'"; - outEntryFilterSql += " and ged.goodsName = '"+goodsNameSearch+"'"; - chargeItemSql = " and chargeItem = '"+goodsNameSearch+"' "; - }else{ - goodsNameFilterSql = " and ii.toussename like '%" + goodsNameSearch - + "%'"; - expensiveGoodsNameFilterSql = " and case when egm.model is null then eg.name else eg.name + '[' + egm.model + ']' end like '%" + goodsNameSearch - + "%'"; - returnGoodsFilterSql += " and ri.toussename like '%" - + goodsNameSearch + "%'"; - materialNameFilterSql = " and ii.materialName like '%" - + goodsNameSearch + "%' "; - lostMaterialFilterSql += " and r.materialName like '%" - + goodsNameSearch + "%'"; - damageFilterSql += " and i.materialName like '%" - + goodsNameSearch + "%'"; - supplyRoomDiposableGoodsFilterSql += " and rri.goodsName like '%"+goodsNameSearch+"%' "; - outEntryFilterSql += " and ged.goodsName like '%"+goodsNameSearch+"%' "; - chargeItemSql = " and chargeItem like '%"+goodsNameSearch+"%' "; - } - //消毒物品需用like查询 - if(disinfection){ - goodsNameFilterSql = " and ii.toussename like '%" + goodsNameSearch - + "%'"; - returnGoodsFilterSql += " and ri.toussename like '%" - + goodsNameSearch + "%'"; - lostMaterialFilterSql += " and r.materialName like '%" - + goodsNameSearch + "%'"; - damageFilterSql += " and i.materialName like '%" - + goodsNameSearch + "%'"; - - supplyRoomDiposableGoodsFilterSql += " and 1=2"; - outEntryFilterSql += " and 1=2"; - } - } - String nameFilterSql = ""; - String packingDisposableGoodsNameSql = ""; - if (StringUtils.isNotBlank(goodsNameSearch)) { - nameFilterSql = " and d.name = '" + goodsNameSearch + "'"; - packingDisposableGoodsNameSql = " and dgi.name = '" + goodsNameSearch + "'"; - - } - String supplyRoomDiposableGoodsFilterSqlOFDgbs = ""; - String iDepartCodingSql = SqlUtils.getWhereSqlByfilterFieldAndStringValue("i.departCoding", invoicePlanDepartCoding); - String rrDepartCodingSql = SqlUtils.getWhereSqlByfilterFieldAndStringValue("rr.departCoding", invoicePlanDepartCoding); - String ciOrgUnitCodeSql = SqlUtils.getWhereSqlByfilterFieldAndStringValue("ci.orgUnitCode", invoicePlanDepartCoding); - if (StringUtils.isNotBlank(batch)) { - nameFilterSql += " and d.batch = '" + batch + "'"; - goodsNameFilterSql += " and 1=2 "; - returnGoodsFilterSql += " and ri.batchNumber = '"+batch+"' "; - packingDisposableGoodsNameSql += " and dgi.batch = '"+batch+"' "; - lostMaterialFilterSql += " and 1=2 "; - damageFilterSql += " and 1=2 "; - supplyRoomDiposableGoodsFilterSqlOFDgbs = supplyRoomDiposableGoodsFilterSql + " and dgbs.batchNumber = '"+batch+"'"; - supplyRoomDiposableGoodsFilterSql += " and dgbs.batchNumber = '"+batch+"'"; - outEntryFilterSql += " and dgbs.batchNumber = '"+batch+"'"; - } - String returnGoodsTousseType = " CASE rr.type WHEN '一次性物品' THEN (rr.type) WHEN '器械包' THEN (td.toussetype) ELSE rr.type END "; - String returnGoodsTousseDefinitionId = " CASE rr.type WHEN '器械包' THEN ri.tousseDefinition_id ELSE 0 END "; - String invoiceJoinInvoicePlanSql = null; - String excludeSciProjectSql = null; - String excludeDiposableGoodsItemSql = null; - if(excludeSciProjectInfo){//排除属于科研项目的一次性物品申请单的发货数据 - invoiceJoinInvoicePlanSql = " left join "+ InvoicePlan.class.getSimpleName() +" ip on i.invoicePlan_ID=ip.id "; - excludeSciProjectSql = " and (ip.projName is null or ip.projName='')"; - excludeDiposableGoodsItemSql = " and dgi.invoice_id in (select i.id from "+ Invoice.class.getSimpleName() +" i left join "+ InvoicePlan.class.getSimpleName() +" ip on ip.id=i.invoicePlan_ID where (ip.projName is null or ip.projName='') and dgi.invoice_id=i.id) "; - }else{ - invoiceJoinInvoicePlanSql = ""; - excludeSciProjectSql = ""; - excludeDiposableGoodsItemSql = ""; - } - //器械包 - String tousseSql = " (select i.settleAccountsDepart "+ tousseDefinitionOfSupplierNameSql +",ii.tousseName as name,sum(ii.amount) as amount," - +"sum(ii.settlementPrice) as settlementprice,sum(ii.settlementDiscountPrice) as settlementDiscountPrice,ii.tousseType as type" - + ",'' as batchNumber,null as expDate,ii.tousseDefinitionId as tousseDefinitionId " - + "from invoice i join InvoiceItem ii on i.id = ii.invoice_id " - + invoiceJoinInvoicePlanSql - + addTousseDefinitionAtWhere - + " where 1=1 " - + addJoinTousseDefinitionSql - + " and ii.diposable = '否' and ii.expensiveGoodsInstanceId is null and "+getHandleDeptCodeSql("i.orgUnitCoding")+" " - + monthFilterSql - + departFilterSql - + iDepartCodingSql - + typeFilterSql - + goodsNameFilterSql - + " and i.settleaccountsdepart is not null group by i.settleAccountsDepart,ii.tousseType,ii.tousseName,ii.tousseDefinitionId " + tousseDefinitionOfSupplierNameSql + ")"; - //新的高值耗材(发货) - String selectExpensiveGoodsSql = ""; - //如果有启用高值耗材则查询 - if(enableExpensiveGoods){ - selectExpensiveGoodsSql = " union all (select i.settleAccountsDepart"+noQuerySupplierName+",case when egm.model is null then eg.name else eg.name "+ concatSymbolInDb +" '[' "+ concatSymbolInDb +" egm.model "+ concatSymbolInDb +" ']' end as name,sum(ii.amount) as amount," - +"sum(ii.settlementPrice) as settlementprice,sum(ii.settlementDiscountPrice) as settlementDiscountPrice,ii.tousseType as type" - + ",'' as batchNumber,ei.expDate as expDate,0 as tousseDefinitionId from " + Invoice.class.getSimpleName() + " i join " - + InvoiceItem.class.getSimpleName()+" ii on i.id = ii.invoice_id join " + ExpensiveGoodsInstance.class.getSimpleName() - + " ei on ei.id = ii.expensiveGoodsInstanceId" - + " join ExpensiveGoods eg on ei.expensiveGoods_id=eg.id " - + " left join ExpensiveGoodsModel egm on ei.expensiveGoodsModelId=egm.id" - + " where ii.diposable = '否' and "+getHandleDeptCodeSql("i.orgUnitCoding")+" " - + monthFilterSql - + departFilterSql - + iDepartCodingSql - + typeFilterSql - + goodsNameFilterSql - + " and i.settleaccountsdepart is not null group by i.settleAccountsDepart,ii.tousseType,case when egm.model is null then eg.name else eg.name "+ concatSymbolInDb +" '[' "+ concatSymbolInDb +" egm.model "+ concatSymbolInDb +" ']' end,ii.expensiveGoodsInstanceId,ei.expDate)"; - //新的高值耗材(一键退库-即退货),如果所选物品类型为全部或高值耗材时, - selectExpensiveGoodsSql += " union all (select i.settleAccountsDepart "+ noQuerySupplierName+",case when egm.model is null then eg.name else eg.name "+ concatSymbolInDb +" '[' "+ concatSymbolInDb +" egm.model "+ concatSymbolInDb +" ']' end as name,-1 * count(egi.id) as amount,-1 * sum(egi.price) settlementprice,-1 * sum(egi.price) settlementprice,'高值耗材' as type,null as batchNumber,egi.expDate,null as tousseDefinitionId " - + " from ExpensiveGoodsGodownEntry egge join ExpensiveGoodsGodownEntryItem eggei on egge.id=eggei.expensiveGoodsGodownEntry_id " - +" join ExpensiveGoodsInstance egi on egi.id=eggei.expensiveGoodsInstanceId " - +" join Invoice i on egi.invoiceId=i.id " - +" join ExpensiveGoods eg on egi.expensiveGoods_id=eg.id " - +" left join ExpensiveGoodsModel egm on egi.expensiveGoodsModelId=egm.id " - +" where 1=1 and egge.type='退库单' and i.orgUnitCoding='" + departCoding + "' " - + expensiveGoodsMonthFilterSql - + (StringUtils.isBlank(typeSearch) || StringUtils.equals(ExpensiveGoods.TYPE_NAME, typeSearch) ? " " : " and 1=2 ") - + departFilterSql - + iDepartCodingSql - + expensiveGoodsNameFilterSql - + " and i.settleaccountsdepart is not null group by i.settleAccountsDepart,case when egm.model is null then eg.name else eg.name "+ concatSymbolInDb +" '[' "+ concatSymbolInDb +" egm.model "+ concatSymbolInDb +" ']' end,egi.expDate)"; - } - - String diposableGoodsSql = " "; - String diposableGoodsTousseTypeSql = ""; - if(TYPE_AUTO_DEDUCTION.equals(typeSearch)){ - diposableGoodsTousseTypeSql = String.format(" and d.type='%s' ", InvoiceItem.TYPE_AUTO_DEDUCTION); - } - if(StringUtils.isBlank(typeSearch) || "一次性物品".equals(typeSearch) || "高值耗材".equals(typeSearch) && !enableExpensiveGoods || TYPE_AUTO_DEDUCTION.equals(typeSearch)){ - diposableGoodsSql = " union all (select i.settleaccountsdepart "+ dgbsOfSupplierNameSql +",d.name as name,sum(d.amount) as amount," - +"sum(d.fluctuationPrice*d.amount) as settlementprice,sum(d.fluctuationPrice*d.amount) as settlementDiscountPrice,'一次性物品' as type" - + ",d.batch as batchNumber,dgbs.expDate,0 as tousseDefinitionId from " - + " invoice i join DiposableGoodsItem d on d.invoice_id=i.id join " + DisposableGoodsBatchStock.class.getSimpleName() + " dgbs on d.disposableGoodsBatchStockID=dgbs.id " - + " where 1=1 and "+getHandleDeptCodeSql("i.orgUnitCoding")+" " - +" and "+diposableGoodsItemPredicate - +diposableGoodsTousseTypeSql - + monthFilterSql - + departFilterSql - + iDepartCodingSql - + excludeSciProjectSql - + nameFilterSql - + expensiveDisposablegoodsSql - + " group by i.settleaccountsdepart,d.name,d.batch,dgbs.expDate "+ dgbsOfSupplierNameSql +") "; - } - String packingDisposableGoodsSql = " "; - { - if(StringUtils.isBlank(typeSearch) || "一次性物品".equals(typeSearch)){ - packingDisposableGoodsSql = " union all (select pr.orgUnitName "+ dgbsOfSupplierNameSql +",dgi.name as name,sum(dgi.amount) as amount," - +"sum(dgi.fluctuationPrice*dgi.amount) as settlementprice,sum(dgi.fluctuationPrice*dgi.amount) as settlementDiscountPrice,'一次性物品' as type" - + ",dgi.batch as batchNumber,dgbs.expDate,0 as tousseDefinitionId from PackingRecord pr inner join DiposableGoodsItem dgi on pr.id = dgi.packingRecordId " - + " inner join " + DisposableGoodsBatchStock.class.getSimpleName() + " dgbs on dgi.disposableGoodsBatchStockID=dgbs.id" - + " where "+getHandleDeptCodeSql("pr.orgUnitCoding")+" " - +" and "+packingDisposableGoodsTypeSql - + packingDisposableGoodsTimeSql - + excludeDiposableGoodsItemSql - + SqlUtils.getWhereSqlByfilterFieldAndStringValue("pr.departCoding", invoicePlanDepartCoding) - + packingDisposableGoodsDepartSql - + packingDisposableGoodsNameSql - + " group by pr.orgUnitName,dgi.name,dgi.batch,dgbs.expDate "+ dgbsOfSupplierNameSql +") "; - } - } - - String materialInvoiceSql = " "; - String materialReturnSql = " "; - String lostMaterial = " "; - String damageMaterial = " "; - //当批次号为空时、且物品类型为空或器械材料或高值耗材时,才查询材料的发货、退货、丢失报损补充等数据 - if(StringUtils.isBlank(batch)){ - if ((StringUtils.isBlank(typeSearch) || "器械材料".equals(typeSearch) || "高值耗材".equals(typeSearch))) { - // 材料发货 - materialInvoiceSql = " union all (select i.settleAccountsDepart "+ noQuerySupplierName +",case when td.name is null then ii.materialName else ii.materialName "+ concatSymbolInDb +"'('"+ concatSymbolInDb +" td.name "+ concatSymbolInDb +"')' end,sum(ii.amount),sum(ii.settlementPrice)," - +"sum(ii.settlementPrice) as settlementDiscountPrice,'材料' as type,'' as batchNumber,null as expDate,td.id as tousseDefinitionId " - + " from MaterialInvoiceItem ii" - + " left join TousseDefinition td on td.id= ii.tousseDefinitionId " - + " inner join MaterialInvoice i on i.id = ii.materialInvoice_id " - + " inner join materialDefinition d on ii.materialDefinitionId = d.id where " - + getHandleDeptCodeSql("i.orgUnitCoding")+" " - + monthFilterSql - + departFilterSql - + iDepartCodingSql - + materialNameFilterSql - + materialTypeFilterSql - + " group by i.settleaccountsdepart,case when td.name is null then ii.materialName else ii.materialName "+ concatSymbolInDb +" '(' "+ concatSymbolInDb +" td.name "+ concatSymbolInDb +"')' end,td.id) "; - } - // 材料退货 - materialReturnSql = " union all (select rr.depart as settleaccountsdepart "+ noQuerySupplierName+",ii.materialName,-sum(ii.amount),-sum(ii.settlementPrice)," - +"-sum(ii.settlementPrice) as settlementDiscountPrice,'材料' as type,'' as batchNumber,null as expDate,0 as tousseDefinitionId " - + " from ReturnMaterialRecord rr,materialDefinition d," - + "ReturnMaterialItem ii where rr.id = ii.returnMaterialRecord_ID " - + " and ii.materialDefinitionId = d.id and "+getHandleDeptCodeSql("rr.handleDepartCode")+" " - + returnGoodsTimeFilterSql - + returnGoodsDepartFilterSql - + rrDepartCodingSql - + materialNameFilterSql - + materialTypeFilterSql - + " group by rr.depart,ii.materialName) "; - - lostMaterial = " union all (select r.depart "+noQuerySupplierName+",r.materialName,sum(r.additionalAmount),sum(r.additionalAmount * r.materialCost)," - +"sum(r.additionalAmount * r.materialCost) as settlementDiscountPrice,'材料' as type,'' as batchNumber,null as expDate,0 as tousseDefinitionId " - + " from MaterialErrorDamageDetail r left join materialDefinition m on r.materialDefinitionId = m.id where 1=1 and r.errorType = '缺失' and r.type = '"+MaterialErrorDamageDetail.TYPE_ERROR+"' and r.materialName != '器械包标识牌' and r.additionalAmount > 0 and "+getHandleDeptCodeSql("r.handleDepartCode")+" " - + lostMaterialFilterSql - + SqlUtils.getWhereSqlByfilterFieldAndStringValue("r.departCode", invoicePlanDepartCoding) - + "group by r.depart,r.materialName ) "; - String banQuery = " and 1 = 0 "; - String damagedTousseAtCost = config.getDamagedTousseAtCost(); - if(Constants.STR_YES.equals(damagedTousseAtCost)){ - banQuery = ""; - } - damageMaterial = " union all (select i.depart"+noQuerySupplierName+",i.materialName,sum(i.additionalAmount),sum(i.materialCost*i.additionalAmount)," - +"sum(i.materialCost*i.additionalAmount) as settlementDiscountPrice,'材料' as type,'' as batchNumber,null as expDate,0 as tousseDefinitionId " - + "from MaterialErrorDamageDetail i left join materialDefinition m on i.materialDefinitionId = m.id where 1=1 " - + banQuery - + " and i.type = '" + MaterialErrorDamageDetail.TYPE_DAMAGE + "' and i.additionalAmount > 0 and "+getHandleDeptCodeSql("i.handleDepartCode")+" " + damageFilterSql - + SqlUtils.getWhereSqlByfilterFieldAndStringValue("i.departCode", invoicePlanDepartCoding) - + " group by i.departCode,i.depart,i.materialName ) "; - } - //退货(一次性物品、器械包) - String returnGoodsSql = " union all (select rr.settleAccountsDepart as settleaccountsdepart"+dgbsOfSupplierNameSql+",ri.toussename as name," - + "-sum(ri.amount) as amount,-sum(ri.settlementPrice) as settlementprice,-sum(ri.settlementPrice) as settlementDiscountPrice," - +returnGoodsTousseType+" as type" - + ",ri.batchNumber as batchNumber,dgbs.expDate,"+returnGoodsTousseDefinitionId+" as tousseDefinitionId 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" - + " left join " + DisposableGoodsBatchStock.class.getSimpleName() + " dgbs on ri.disposableGoodsBatchStockID=dgbs.id" - + " where " + getHandleDeptCodeSql("rr.handleDepartCode")+" " - + returnGoodsFilterSql - + rrDepartCodingSql - +" and "+returnGoodsItemPredicate - + " group by rr.settleAccountsDepart,ri.toussename,"+returnGoodsTousseType+",ri.batchNumber,dgbs.expDate,"+returnGoodsTousseDefinitionId+ dgbsOfSupplierNameSql +") "; - - String supplyRoomTousseTypeSql = ""; - if(TYPE_AUTO_DEDUCTION.equals(typeSearch)){ - supplyRoomTousseTypeSql = String.format(" and rr.type='%s' ", InvoiceItem.TYPE_AUTO_DEDUCTION); - } - String supplyRoomDiposableGoodsSql = " union all (select rr.depart"+ dgbsOfSupplierNameSql +" as settleaccountsdepart,rri.goodsName,sum(rri.amount)," - +"sum(rri.price*rri.amount) as settlementprice,sum(rri.price*rri.amount) as settlementDiscountPrice,rri.type as type,dgbs.batchNumber as batchNumber,dgbs.expDate,0 as tousseDefinitionId " - +" from ReceiveRecord rr,ReceiveRecordItem rri left join " + DisposableGoodsBatchStock.class.getSimpleName() + " dgbs " - +" on rri.diposableGoodBatchStock_id = dgbs.id left join DisposableGoods d on d.id = rri.disposableGoodsId where rr.id = rri.receiveRecord_id and "+getHandleDeptCodeSql("rr.departCoding")+" " - +supplyRoomDiposableGoodsFilterSqlOFDgbs - +supplyRoomTousseTypeSql - +" and "+receiveRecordItemPredicate - + supplyRoomDiposableGoodsFilterSql - + rrDepartCodingSql - + " group by rr.depart,rri.goodsName,rri.amount,rri.type,dgbs.batchNumber,dgbs.expDate "+ dgbsOfSupplierNameSql +") "; - // 调拨出库 - String appropriateOutDiposableGoodsSql = " union all (select oge.targetOrgUnitName as settleaccountsdepart"+dgbsOfSupplierNameSql+",ged.goodsName,sum(ged.amount)," - +"sum(ged.price*ged.amount) as settlementprice,sum(ged.price*ged.amount) as settlementDiscountPrice,'一次性物品' as type,dgbs.batchNumber as batchNumber,dgbs.expDate,0 as tousseDefinitionId " - +" from GodownEntry oge inner join GodownEntryDiposableGoodsItem ged on oge.id = ged.godownEntryID inner join DisposableGoodsBatch dgbs on ged.disposableGoodsBatchID=dgbs.id inner join DisposableGoods dg on dgbs.diposablegoods_id = dg.id " - +" where oge.type ='退库单' and oge.subType='调拨出库' and "+getHandleDeptCodeSql("oge.orgUnitCode")+" " - +outEntryFilterSql - + SqlUtils.getWhereSqlByfilterFieldAndStringValue("oge.targetOrgUnitCode", invoicePlanDepartCoding) - +" and "+outEntryPredicate - + " group by oge.targetOrgUnitName, ged.goodsName,dgbs.batchNumber,dgbs.expDate "+ dgbsOfSupplierNameSql +") "; - // 盘亏出库 - String stocktakeOutDiposableGoodsSql = " union all (select oge.orgUnitName"+dgbsOfSupplierNameSql+" as settleaccountsdepart,ged.goodsName,sum(ged.amount)," - +"sum(ged.price*ged.amount) as settlementprice,sum(ged.price*ged.amount) as settlementDiscountPrice,'一次性物品' as type,dgbs.batchNumber as batchNumber,dgbs.expDate,0 as tousseDefinitionId " - +" from GodownEntry oge inner join GodownEntryDiposableGoodsItem ged on oge.id = ged.godownEntryID inner join DisposableGoodsBatch dgbs on ged.disposableGoodsBatchID=dgbs.id inner join DisposableGoods dg on dgbs.diposablegoods_id = dg.id " - +" where oge.type ='退库单' and oge.subType='盘亏出库' and "+getHandleDeptCodeSql("oge.orgUnitCode")+" " - +outEntryFilterSql - + SqlUtils.getWhereSqlByfilterFieldAndStringValue("oge.orgUnitCode", invoicePlanDepartCoding) - +" and "+outEntryPredicate - + " group by oge.orgUnitName, ged.goodsName,dgbs.batchNumber,dgbs.expDate"+dgbsOfSupplierNameSql+") "; - String sql = tousseSql + selectExpensiveGoodsSql + diposableGoodsSql + supplyRoomDiposableGoodsSql ; - - if(!TYPE_AUTO_DEDUCTION.equals(typeSearch)){ - sql += materialInvoiceSql; - sql += returnGoodsSql; - sql += materialReturnSql; - sql += appropriateOutDiposableGoodsSql; - sql += stocktakeOutDiposableGoodsSql; - sql += packingDisposableGoodsSql; - } - - if ("器械包".equals(typeSearch) || "器械材料".equals(typeSearch) || "全部".equals(typeSearch) || typeSearch == null || "全部器械包".equals(typeSearch) || "高值耗材".equals(typeSearch)) { - sql += lostMaterial; - sql += damageMaterial; - } - String chargeDateSql = "";//收费项目时间过滤 - if(TYPE_CHARGE.equals(typeSearch) || TYPE_ALL.equals(typeSearch) || StringUtils.isBlank(typeSearch)){ - if(StringUtils.isNotBlank(startTime) && StringUtils.isNotBlank(endTime)){ - chargeDateSql = String.format(" and chargeTime %s ", betweenSql); - } - if(StringUtils.isNotBlank(departSearch)){ - chargeDepartSql = String.format(" and ci.orgUnitCode = '%s' ", departCoding); - } - } - if(TYPE_CHARGE.equals(typeSearch)){ - String chargeSql = String.format(" select ci.orgUnitName settleAccountsDepart,chargeItem name,1 amount,price settlementprice,0 settlementDiscountPrice,'收费项目' type ,'' batchNumber,NULL as expDate ,null as tousseDefinitionId " - + " from ChargeRecordItem ci inner join ChargeRecord cr on cr.id=ci.chargeRecord_id where 1=1 %s %s %s %s group by ci.orgUnitName,chargeItem,price,chargeTime " - , chargeDepartSql,chargeDateSql,chargeItemSql,ciOrgUnitCodeSql); - sql = chargeSql; - }else if(TYPE_ALL.equals(typeSearch) || StringUtils.isBlank(typeSearch)){ - sql += String.format(" union all select ci.orgUnitName settleAccountsDepart,chargeItem name,1 amount,price settlementprice,0 settlementDiscountPrice,'收费项目' type ,'' batchNumber,NULL as expDate ,null as tousseDefinitionId " - + " from ChargeRecordItem ci inner join ChargeRecord cr on cr.id=ci.chargeRecord_id where 1=1 %s %s %s %s group by ci.orgUnitName,chargeItem,price,chargeTime " - , chargeDepartSql,chargeDateSql,chargeItemSql,ciOrgUnitCodeSql); - } - String database = dbConnection.getDatabase(); - if (dbConnection.isSqlServer()) { - String orderSql = " order by settleaccountsdepart,type"; - sql += orderSql; - } - - logger.debug("执行sql:" + sql); - - Map> detailMap = new HashMap>(); - Map manufacturerMap = getDiposableGoodsManufacturer(); - - Map disposableGoodsExternalCodeMap = disposableGoodsExternalCodeMap(); - Map expensiveExternalCode = expensiveExternalCode(); - Map materialExternalCodeMap = getMaterialExternalCode(); - Map tousseExternalCodeMap = getTousseExternalCode(); - ResultSet rs = objectDao.executeSql(sql); - if (rs != null) { - try { - Set toussedefinitionIdSet = new HashSet();//需要查询材料实例数量的包定义id - Map itemAndTDid = new HashMap();//,用于给DepartmentMonthDetailItem计算price和totalAmount - while (rs.next()) { - String settleaccountsdepart = rs.getString("settleaccountsdepart"); - List itemList = detailMap.get(settleaccountsdepart); - if (itemList == null) { - itemList = new ArrayList(); - detailMap.put(settleaccountsdepart, itemList); - } - String goodsName = rs.getString("name"); - String type = rs.getString("type"); - double settlementPrice = rs.getDouble("settlementprice"); - double settlementDiscountPrice = rs.getDouble("settlementDiscountPrice"); - int amount = rs.getInt("amount"); - int disinfectGoodsStatisticAmount = 0; - int totalAmount = amount; - DepartmentMonthDetailItem mdi = new DepartmentMonthDetailItem(); - - mdi.setType(type); - mdi.setSettlementPrice(settlementPrice); - mdi.setSettlementDiscountPrice(settlementDiscountPrice); - if(DisposableGoods.TYPE_NAME.equals(type)){ - int beginIndex = goodsName.indexOf("["); - int endIndex = goodsName.lastIndexOf("]"); - if(beginIndex != -1 && endIndex != -1){ - String specification = goodsName.substring(beginIndex + 1, endIndex); - goodsName = goodsName.substring(0, beginIndex); - mdi.setSpecification(specification); - } - } - mdi.setGoodsName(goodsName); - itemList.add(mdi); - boolean flag = true;//是否需要现在计算价格和数量 - if (TousseDefinition.PACKAGE_TYPE_DISINFECTION.equals(type) - || (TousseDefinition.PACKAGE_TYPE_CUSTOM.equals(type) && !showCustonTousseAmount)) { - Long toussedefinitionId = rs.getLong("tousseDefinitionId"); - if (DatabaseUtil.isPoIdValid(toussedefinitionId)) { - toussedefinitionIdSet.add(toussedefinitionId);//记下id,一次性查询对应的材料实例数量 - mdi.setAmount(totalAmount); - itemAndTDid.put(mdi, toussedefinitionId); - flag = false;//先不计算价格和总数量,批量查询时再计算 - } - } - if(flag){ - Double price = 0D; - if(totalAmount != 0){ - price = MathTools.divide(settlementPrice, totalAmount, 4); - } - mdi.setPrice(price); - mdi.setAmount(totalAmount); - } - } - //统一计算要查询包定义对应的材料实例数量的DepartmentMonthDetailItem的price和totalAmount - calcPriceAndAmout(toussedefinitionIdSet, itemAndTDid); - } catch (SQLException e) { - logger.error("获取明细核算月报数据时出错", e); - }finally { - DatabaseUtil.closeResultSetAndStatement(rs); - } - } - for(Entry> entry : detailMap.entrySet()){ - String depart = entry.getKey(); - List list = entry.getValue(); - //消毒物品相同名称的合并 - Map tmpMap = new HashMap(); - List removeItems = new ArrayList(); - double totalPrice = 0.0d; - double totalPriceDiscount = 0.0d; - //消毒物品合并 - Map disposableGoodsTempMap = new HashMap(); - for (DepartmentMonthDetailItem dmi : list) { - String tousseName = dmi.getGoodsName(); - String type = dmi.getType(); - if (TousseDefinition.PACKAGE_TYPE_DISINFECTION.equals(type) - || TousseDefinition.PACKAGE_TYPE_CUSTOM.equals(type)) { - DepartmentMonthDetailItem item = tmpMap.get(tousseName); - if(item == null){ - item = new DepartmentMonthDetailItem(); - item.setAmount(0); - item.setPrice(0d); - item.setSettlementPrice(0d); - item.setSettlementDiscountPrice(0d); - item.setExternalCode(tousseExternalCodeMap.get(tousseName)); - tmpMap.put(tousseName, item); - } - - item.setAmount(item.getAmount()+dmi.getAmount()); - item.setBatchNumber(dmi.getBatchNumber()); - item.setDiposable(dmi.getDiposable()); - item.setExpDate(dmi.getExpDate()); - item.setGoodsName(tousseName); - item.setManufacturer(dmi.getManufacturer()); - item.setSettlementPrice(item.getSettlementPrice() + dmi.getSettlementPrice()); - 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(); - item.setPrice(price); - removeItems.add(dmi); - } - totalPrice += dmi.getSettlementPrice(); - totalPriceDiscount += dmi.getSettlementDiscountPrice(); - } - list.removeAll(removeItems); - if(tmpMap.size() > 0){ - list.addAll(tmpMap.values()); - } - DepartmentMonthDetail detail = new DepartmentMonthDetail(); - detail.setDepart(depart); - detail.setTotalPrice(totalPrice); - detail.setTotalPriceDiscount(totalPriceDiscount); - detail.setItems(list); - sortDetailItems(detail); - datas.add(detail); - } - return datas; - } - //------------------------单个科室的明细核算月报 end----------------- - /** - * 获取消毒物品材料数量,没有申请单的可能是自定义装配生成的 - * @param disinfectGoodsName - * @param invoicePlanID - * @return 自定义器械包或者是拆包的消毒物品,返回材料数量,其他情况都返回0 - */ - private int getDisinfectGoodsStatisticAmount(Long toussedefinitionId) { - int statisticsAmount = 0; - if(toussedefinitionId == null){ - return statisticsAmount; - } - String sql = "select sum(i.count) from Toussedefinition t,MaterialInstance i " - + "where t.id = i.tousse_id and t.id = " + toussedefinitionId - + " and ((t.isApplyEntireTousse='" + Constants.STR_NO +"' and t.tousseType='" - + TousseDefinition.PACKAGE_TYPE_DISINFECTION+"') or t.tousseType='"+TousseDefinition.PACKAGE_TYPE_CUSTOM+"')"; - ResultSet rs = objectDao.executeSql(sql); - if(rs != null){ - try { - if(rs.next()){ - statisticsAmount = rs.getInt(1); - } - } catch (SQLException e) { - e.printStackTrace(); - } finally { - DatabaseUtil.closeResultSetAndStatement(rs); - } - } - return statisticsAmount; - } - /** - * 获取消毒物品材料数量,没有申请单的可能是自定义装配生成的 - * @param toussedefinitionIdSet 包定义id - * @return 自定义器械包或者是拆包的消毒物品,返回材料数量,其他情况都返回0 - */ - private Map getDisinfectGoodsStatisticAmount(Set toussedefinitionIdSet) { - Map tdIdAndAmountMap = new HashMap(); - if(CollectionUtils.isEmpty(toussedefinitionIdSet)){ - return tdIdAndAmountMap; - } - ResultSet rs = null; - try { - String sql = "select sum(i.count) count,t.id from Toussedefinition t,MaterialInstance i " - + "where t.id = i.tousse_id and " + SqlUtils.getNonStringFieldInLargeCollectionsPredicate("t.id", toussedefinitionIdSet) - + " and ((t.isApplyEntireTousse='" + Constants.STR_NO +"' and t.tousseType='" - + TousseDefinition.PACKAGE_TYPE_DISINFECTION+"') or t.tousseType='"+TousseDefinition.PACKAGE_TYPE_CUSTOM+"') group by t.id"; - rs = objectDao.executeSql(sql); - while(rs.next()){ - Long id = rs.getLong("id"); - Integer count = rs.getInt("count"); - tdIdAndAmountMap.put(id, count); - } - } catch (SQLException e) { - e.printStackTrace(); - } finally { - DatabaseUtil.closeResultSetAndStatement(rs); - } - return tdIdAndAmountMap; - } - // 对科室中的物品明细按类型和名称排序,先按类型排序,然后按名称,器械包排在一起,一次性物品排在一起 - // 按type是否为“一次性物品”分组,因为有部分InvoiceItem的tousseType属性为空 - private void sortDetailItems(DepartmentMonthDetail detail) { - - List items = detail.getItems(); - Collections.sort(items, - new Comparator() { - @Override - public int compare(DepartmentMonthDetailItem o1, - DepartmentMonthDetailItem o2) { - - if ("一次性物品".equals(o1.getType())){ - o1.setDiposable("是"); - } - else{ - o1.setDiposable("否"); - } - if ("一次性物品".equals(o2.getType())){ - o2.setDiposable("是"); - } - else{ - o2.setDiposable("否"); - } - int compareType = o1.getTypeOrder() - o2.getTypeOrder(); - if(compareType == 0){ - int compareName = ObjectUtils.compare(o1.getGoodsName(), o2.getGoodsName()); - return compareName; - } -// int value1 = ObjectUtils.compare(o1.getDiposable(), o2.getDiposable()); -// if (value1 == 0) { -// int value2 = ObjectUtils.compare(o1.getGoodsName(), o2.getGoodsName()); -// return value2; -// } - return compareType; - } - }); - } /** * 获取发货物品查询汇总列表数据 @@ -8392,7 +3573,7 @@ } }else if(!StringTools.equals("全部", goodsType)){ //器械包的类型 - tousseTypeSql = SqlUtils.getStringFieldInLargeCollectionsPredicate("td.tousseType", getTousseTypes(goodsType)); + tousseTypeSql = SqlUtils.getStringFieldInLargeCollectionsPredicate("td.tousseType", dataIndex.getTousseTypes(goodsType)); disposableTypeSql = " 1=2 "; materialTypeSql = " 1=2 "; expensiveGoodsSql = " 1=2 "; Index: ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/util/MonthReportGroupByDisposableGoodsTypeHelper.java =================================================================== diff -u --- ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/util/MonthReportGroupByDisposableGoodsTypeHelper.java (revision 0) +++ ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/util/MonthReportGroupByDisposableGoodsTypeHelper.java (revision 35792) @@ -0,0 +1,771 @@ +package com.forgon.disinfectsystem.jasperreports.util; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.apache.commons.lang.StringUtils; + +import com.forgon.Constants; +import com.forgon.directory.acegi.tools.AcegiHelper; +import com.forgon.directory.vo.LoginUserData; +import com.forgon.disinfectsystem.common.CssdUtils; +import com.forgon.disinfectsystem.entity.assestmanagement.DisposableGoods; +import com.forgon.disinfectsystem.entity.assestmanagement.ExpensiveGoods; +import com.forgon.disinfectsystem.entity.basedatamanager.supplyroomconfig.SupplyRoomConfig; +import com.forgon.disinfectsystem.entity.basedatamanager.toussedefinition.TousseDefinition; +import com.forgon.disinfectsystem.entity.invoicemanager.Invoice; +import com.forgon.disinfectsystem.entity.invoicemanager.InvoiceItem; +import com.forgon.disinfectsystem.entity.materialerrordamage.MaterialErrorDamageDetail; +import com.forgon.disinfectsystem.entity.tousseitem.TousseItem; +import com.forgon.disinfectsystem.jasperreports.javabeansource.MonthReportBean; +import com.forgon.tools.MathTools; +import com.forgon.tools.db.DatabaseUtil; +import com.forgon.tools.util.SqlUtils; +/** + * 个性化核算月报 + */ +public class MonthReportGroupByDisposableGoodsTypeHelper extends MonthReportHelper{ + /** + * 个性化核算月报查询(一次性物品拆分,添加一次性物品数量合计、价格合计,现xjjqzyy配置) + * @param startDate 开始时间 + * @param endDate 结束时间 + * @param department 部门 + * @param tousseType 包类型 + * @param disposableGoodsType 一次性物品类型 + * @param showCustonTousseAmount 是否显示自定义器械包数量 + * @return + */ + public List getMonthReportDataGroupByDisposableGoodsType(String startDate,String endDate, + String department,String tousseType,String disposableGoodsType,Boolean showCustonTousseAmount){ + //是否启用包内材料统计列 + boolean monthReportMaterialAmountOfTousse = CssdUtils.getSystemSetConfigByNameBool("monthReportMaterialAmountOfTousse"); + SupplyRoomConfig supplyRoomConfig = supplyRoomConfigManager.getSystemParamsObj(); + final String TYPE_AUTO_DEDUCTION = "自动扣减物品"; + //当前用户是否为供应室(包含一二级供应室)用户 + boolean isSupplyRoomUser = supplyRoomConfigManager.isSupplyRoomUser(); + if(!isSupplyRoomUser){ + department = AcegiHelper.getCurrentOrgUnitName(); + } + LoginUserData user = AcegiHelper.getLoginUser(); + String orgUnitCoding = null; + if (user != null){ + orgUnitCoding = user.getOrgUnitCodingFromSupplyRoomConfig(); + } + boolean isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser = false; + if (isSupplyRoomUser || supplyRoomConfigManager.isExpensiveGoodsSupplyRoomUser()) { + isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser = true; + } + List list = new ArrayList(); + String invoiceWheresql = "" ; + startDate += " 00:00:00"; + endDate += " 23:59:59"; + String betweenSql = "between " + + dateQueryAdapter.dateConverAdapter2(startDate, + "yyyy-mm-dd HH24:MI:SS") + + " and " + dateQueryAdapter.dateConverAdapter2(endDate, + "yyyy-mm-dd HH24:MI:SS") + " "; + if(StringUtils.isNotBlank(startDate) && StringUtils.isNotBlank(endDate)){ + invoiceWheresql = " and i.sendTime " + betweenSql; + } + String receiveDepartWhereSql = ""; + if(StringUtils.isNotBlank(department)){ + invoiceWheresql += " and i.settleAccountsDepart = '"+department+"'"; + receiveDepartWhereSql = String.format(" and r.depart='%s'", department); + } + String invoiceItemDisposableGoodsTypePredicate = "1=1"; + String disposableGoodsInvoiceAmountPredicate = " ii.diposable='是' "; + String returnGoodsItemPredicate = "1=1"; + String receiveRecordItemPredicate = "1=1"; + String outEntryPredicate = "1=1"; + String packingDisposableGoodsTypePredicate = "1=1"; + List allTousseType = dataIndex.getTousseTypes(tousseType); + String disposableGoodsIdSql = ""; + StringBuffer leftJoinDisposableGoods = new StringBuffer(50); + leftJoinDisposableGoods.append(" left join ").append(DisposableGoods.class.getSimpleName()); + int dataSoureOfMaterialsCountOfToussesInReports = CssdUtils.getSystemSetConfigByNameInt("dataSoureOfMaterialsCountOfToussesInReports", 3); + //包定义id跟材料数量的临时表 + String tousseDefinitionIdMaterialAmountSql = " (select sum(mi.count) materialAmount,td.id,td.tousseType,td.isApplyEntireTousse from MaterialInstance mi join TousseDefinition td on mi.tousse_id = td.id group by td.id,td.tousseType,isApplyEntireTousse) "; + if(StringUtils.isNotBlank(disposableGoodsType)){ + disposableGoodsIdSql = String.format(" select id from DisposableGoods where type='%s' ", disposableGoodsType); + invoiceItemDisposableGoodsTypePredicate = String.format(" (ii.diposable='否' or ii.disposableGoodsId in(%s)) ", disposableGoodsIdSql); + disposableGoodsInvoiceAmountPredicate = String.format(" (ii.diposable='是' and ii.disposableGoodsId in(%s)) ", disposableGoodsIdSql); + returnGoodsItemPredicate = String.format(" (r.type!='一次性物品' or i.disposableGoodsId in(%s)) ", disposableGoodsIdSql); + outEntryPredicate = String.format(" (ged.disposableGoodsID in(%s)) ", disposableGoodsIdSql); + packingDisposableGoodsTypePredicate = String.format(" (dgi.disposableGoodsID in(%s)) ", disposableGoodsIdSql); + } + if(StringUtils.isBlank(tousseType) || !"器械材料".equals(tousseType)){ + //物品类型sql + String tousseTypeInvoiceSql = ""; + String tousseTypeReturnSql = ""; + if(StringUtils.isNotBlank(tousseType)){ + if(TYPE_AUTO_DEDUCTION.equals(tousseType)){ + tousseTypeInvoiceSql = String.format(" and ii.type='%s' ", InvoiceItem.TYPE_AUTO_DEDUCTION); + }else{ + tousseTypeInvoiceSql = String.format(" and %s ", SqlUtils.getStringFieldInLargeCollectionsPredicate("ii.tousseType", allTousseType)); + } + + if(TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType)){ + tousseTypeReturnSql = " and i.disposableGoodsId in (select id from DisposableGoods) "; + }else{ + tousseTypeReturnSql = String.format(" and i.tousseDefinition_id in (select id from TousseDefinition where %s) ", SqlUtils.getStringFieldInLargeCollectionsPredicate("tousseType", allTousseType)); + } + }else{ + tousseTypeInvoiceSql = String.format(" and (ii.type='%s' or ii.diposable='是' or (ii.diposable='否' and %s))", InvoiceItem.TYPE_AUTO_DEDUCTION,SqlUtils.getStringFieldInLargeCollectionsPredicate("ii.tousseType", allTousseType)); + tousseTypeReturnSql = String.format(" and (i.disposableGoodsId in (select id from DisposableGoods) or i.tousseDefinition_id in (select id from TousseDefinition where %s) )",SqlUtils.getStringFieldInLargeCollectionsPredicate("tousseType", allTousseType)); + } + + String invoicePriceSql = "select i.settleAccountsDepartCoding as coding,i.settleAccountsDepart " + + "as depart,sum(ii.settlementPrice) as price,ii.diposable,sum(ii.settlementDiscountPrice) as settlementDiscountPrice,ii.tousseType,dg.type from " + Invoice.class.getSimpleName() + " i," + + InvoiceItem.class.getSimpleName() + " ii left join "+ DisposableGoods.class.getSimpleName() +" dg on dg.id=ii.disposableGoodsId where i.id = ii.invoice_id and "+invoiceItemDisposableGoodsTypePredicate+" and " + + dataIndex.getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + + " and (i.status ='收货签收' or " + + "i.status = '已发货') " + invoiceWheresql + tousseTypeInvoiceSql + " group by i.settleAccountsDepartCoding,i.settleAccountsDepart,ii.diposable,ii.tousseType,dg.type"; + + ResultSet rs = objectDao.executeSql(invoicePriceSql); + try { + Map codeAndTypeMap = new HashMap(); + while(rs.next()){ + String code = rs.getString("coding"); + String dept = rs.getString("depart"); + Double price = rs.getDouble("price"); + String diposable = rs.getString("diposable"); + String tType = rs.getString("tousseType"); + String columnName = ""; + if("是".equals(diposable)){ + String key = new StringBuffer(code).append(",a").append(rs.getString("type")).toString(); + if(codeAndTypeMap.containsKey(key)){ + MonthReportBean mrb = codeAndTypeMap.get(key); + mrb.setMoney(MathTools.add(mrb.getMoney(), price).doubleValue()); + }else{ + MonthReportBean mrb = new MonthReportBean(); + mrb.setRowNum(code); + mrb.setDepartment(dept); + mrb.setMoney(price); + codeAndTypeMap.put(key, mrb); + } + continue; + } + if(ExpensiveGoods.TYPE_NAME.equals(tType)){ + columnName = "c高值耗材总价"; + }else{ + columnName = "c器械包总价"; + } + newMonthReport(code, null,dept,"2", "价格统计",columnName,price, list, null, null); + } + if(codeAndTypeMap.size() > 0){ + Map departSum = new HashMap(); + for (Entry entry : codeAndTypeMap.entrySet()) { + String key = entry.getKey(); + MonthReportBean item = entry.getValue(); + String code = item.getRowNum(); + Double price = item.getMoney(); + newMonthReport(code, null,item.getDepartment(),"2", "价格统计", key.substring(key.indexOf(",") + 1),price, list, null, null); + if(departSum.containsKey(code)){ + MonthReportBean mrb = departSum.get(code); + mrb.setMoney(MathTools.add(mrb.getMoney(), price).doubleValue()); + }else{ + departSum.put(code, item); + } + } + if(departSum.size() > 0){ + for (Entry entry : departSum.entrySet()) { + MonthReportBean item = entry.getValue(); + newMonthReportForGuiGang(item.getRowNum(), item.getDepartment(),"2", "价格统计","b一次性物品合计",item.getMoney(), list); + } + } + } + } catch (SQLException e) { + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(rs); + } + if(!TYPE_AUTO_DEDUCTION.equals(tousseType)){ + String queryColumnSql = null; + String leftJoinSqlForReturnSql = null; + if(dataSoureOfMaterialsCountOfToussesInReports == 3){ + queryColumnSql = "td.tousseType,i.materialAmountAtThatTime materialAmount,td.isApplyEntireTousse "; + leftJoinSqlForReturnSql = String.format("left join %s td on td.id=i.tousseDefinition_id", TousseDefinition.class.getSimpleName()); + }else{ + queryColumnSql = "tdm.tousseType,tdm.materialAmount as materialAmount ,tdm.isApplyEntireTousse"; + leftJoinSqlForReturnSql = " left join " + tousseDefinitionIdMaterialAmountSql + " tdm on tdm.id = i.tousseDefinition_id "; + } + //退货统计(器械包或一次性物品) + String returnSql = "select r.type,(-i.settlementPrice),-i.amount,r.settleAccountsDepartCoding departCoding,r.settleAccountsDepart depart," + + queryColumnSql + + ",dg.type dgType from ReturnGoodsRecord r join ReturnGoodsItem i on r.id = i.returnGoodsRecord_ID " + + leftJoinDisposableGoods + + " dg on dg.id=i.disposableGoodsID " + + leftJoinSqlForReturnSql + + " where "+returnGoodsItemPredicate+ tousseTypeReturnSql + " and " + + dataIndex.getHandleDeptCodeSql("r.handleDepartCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + +" and r.returnTime " + betweenSql; + if(StringUtils.isNotBlank(department)){ + returnSql += " and r.settleAccountsDepart = '" + department + "'"; + } + ResultSet rs5 = objectDao.executeSql(returnSql); + try { + Map codeAndTypeMap = new HashMap(); + while(rs5.next()){ + String type = rs5.getString(1); + Double price = rs5.getDouble(2); + int amount = rs5.getInt(3); + String code = rs5.getString(4); + String dept = rs5.getString(5); + String returnTousseType = rs5.getString("tousseType"); + String isApplyEntireTousse = rs5.getString("isApplyEntireTousse"); + + int materialAmount = rs5.getInt("materialAmount"); + Integer totalMaterialAmount = amount * materialAmount; + + // 如果是拆包的消毒物品,用统计数量替换包数量 + if ("消毒物品".equals(returnTousseType) && Constants.STR_NO.equals(isApplyEntireTousse)) { + if (materialAmount > 0) { + amount = totalMaterialAmount; + } + }else if(TousseDefinition.PACKAGE_TYPE_CUSTOM.equals(returnTousseType)&& !showCustonTousseAmount){ + if (materialAmount > 0) { + amount = totalMaterialAmount; + } + } + + if("一次性物品".equals(type)){ + setCodeAndTypeMapData(codeAndTypeMap, code, dept, rs5.getString("dgType"), amount, price); + continue; + } + newMonthReport(code, null,dept, "2", "价格统计", "c器械包总价", price, list, null, null); + newMonthReport(code, null,dept, "3", "数量统计", "c器械包数量", amount, list, null, null); + if(monthReportMaterialAmountOfTousse){ + newMonthReport(code, null,dept, "4", "包内材料统计", "c包内材料数量", totalMaterialAmount, list, null, null); + } + } + addDisposableGoodsData(codeAndTypeMap, list); + }catch(Exception e){ + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(rs5); + } + } + } + + if(StringUtils.isBlank(tousseType) || "器械材料".equals(tousseType)){ + // 材料发货价格 + String materialInvoicePriceSql = "select i.settleAccountsDepartCoding as coding,i.settleAccountsDepart " + + "as depart,sum(ii.settlementPrice) as price from MaterialInvoice i," + + "MaterialInvoiceItem ii where i.id = ii.materialInvoice_id and " + + dataIndex.getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + + " " + invoiceWheresql + " group by i.settleAccountsDepartCoding,i.settleAccountsDepart"; + ResultSet materialInvoicePriceResultSet = objectDao.executeSql(materialInvoicePriceSql); + try { + while(materialInvoicePriceResultSet.next()){ + String code = materialInvoicePriceResultSet.getString(1); + String dept = materialInvoicePriceResultSet.getString(2); + Double price = materialInvoicePriceResultSet.getDouble(3); + String columnName = "c发货材料总价"; + + newMonthReport(code, null,dept,"2", "价格统计",columnName,price, list, null, null); + } + } catch (SQLException e) { + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(materialInvoicePriceResultSet); + } + + // 材料发货数量 + String materialInvoiceAmountSql = "select i.settleAccountsDepartCoding as coding,i.settleAccountsDepart " + + "as depart,mi.amount from MaterialInvoice i inner join MaterialInvoiceItem mi on i.id=mi.materialInvoice_id " + + "where " + + dataIndex.getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + + " and (mi.amount is not null and mi.amount>0) " + + " " + invoiceWheresql; + + ResultSet materialInvoiceAmountResultSet = objectDao.executeSql(materialInvoiceAmountSql); + try { + while(materialInvoiceAmountResultSet.next()){ + String code = materialInvoiceAmountResultSet.getString(1); + String dept = materialInvoiceAmountResultSet.getString(2); + int tousseAmount = materialInvoiceAmountResultSet.getInt(3); + if(tousseAmount > 0){ + newMonthReport(code, null,dept,"3","数量统计", "c发货材料数量",tousseAmount,list, null, null); + } + } + } catch (SQLException e) { + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(materialInvoiceAmountResultSet); + } + String banQuery = " 1 = 0 and "; + String damagedTousseAtCost = supplyRoomConfig.getDamagedTousseAtCost(); + /*if(StringUtils.isBlank(damagedTousseAtCost) || Constants.STR_YES.equals(damagedTousseAtCost)){ + banQuery = ""; + }*/ + if(Constants.STR_YES.equals(damagedTousseAtCost)){ + banQuery = ""; + } + //材料报损统计 + String damageSql = "select i.settleAccountsDepartCoding departCode,i.settleAccountsDepart depart,i.materialName,sum(i.materialCost*i.additionalAmount),sum(i.additionalAmount) " + + " from MaterialErrorDamageDetail i where " + banQuery + + dataIndex.getHandleDeptCodeSql("i.handleDepartCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + + " and i.type = '" + + MaterialErrorDamageDetail.TYPE_DAMAGE + "' and i.additionalTime " + + betweenSql; + + if(StringUtils.isNotBlank(department)){ + damageSql += " and i.settleAccountsDepart = '"+department+"' "; + } + damageSql += " group by i.settleAccountsDepartCoding,i.settleAccountsDepart,i.materialName"; + ResultSet rs33 = objectDao.executeSql(damageSql); + try { + if(rs33 != null){ + while(rs33.next()){ + String code = rs33.getString(1); + String dept = rs33.getString(2); + Double money = rs33.getDouble(4); + int amount = rs33.getInt(5); + + newMonthReport(code, null,dept, "3", "数量统计", "c丢失报损材料数量", amount, list, null, null); + newMonthReport(code, null,dept, "2", "价格统计", "c丢失报损材料总价", money, list, null, null); + } + } + }catch(Exception e){ + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(rs33); + } + + //材料丢失统计 + String recyclingErrorSql = "select r.settleAccountsDepartCoding departCode,r.settleAccountsDepart depart,r.materialName,sum(r.materialCost*r.additionalAmount),sum(r.additionalAmount) " + + " from MaterialErrorDamageDetail r where r.errorType = '缺失' and r.type = '"+MaterialErrorDamageDetail.TYPE_ERROR+"' and r.materialName != '器械包标识牌' " + + " and " + + dataIndex.getHandleDeptCodeSql("r.handleDepartCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + + " and r.additionalTime " + betweenSql; + + if(StringUtils.isNotBlank(department)){ + recyclingErrorSql += " and r.settleAccountsDepart = '"+department+"' "; + } + recyclingErrorSql += " group by r.settleAccountsDepartCoding,r.settleAccountsDepart,r.materialName"; + ResultSet rs3 = objectDao.executeSql(recyclingErrorSql); + try { + if(rs3 != null){ + while(rs3.next()){ + String code = rs3.getString(1); + String dept = rs3.getString(2); + Double money = rs3.getDouble(4); + int amount = rs3.getInt(5); + + newMonthReport(code, null,dept,"3", "数量统计","c丢失报损材料数量",amount, list, null, null); + newMonthReport(code, null,dept,"2", "价格统计","c丢失报损材料总价",money, list, null, null); + } + } + }catch(Exception e){ + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(rs3); + } + + // 材料退货 + String materialReturnSql = "select r.settleAccountsDepartCoding departCoding,r.settleAccountsDepart depart , (-i.settlementPrice),-i.amount " + + "from ReturnMaterialRecord r,ReturnMaterialItem i where r.id = i.returnMaterialRecord_ID" + + " and " + + dataIndex.getHandleDeptCodeSql("r.handleDepartCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + +" and r.returnTime " + betweenSql; + if(StringUtils.isNotBlank(department)){ + materialReturnSql += " and r.settleAccountsDepart = '" + department + "'"; + } + ResultSet materialReturnResultSet = objectDao.executeSql(materialReturnSql); + try { + while(materialReturnResultSet.next()){ + String code = materialReturnResultSet.getString(1); + String dept = materialReturnResultSet.getString(2); + Double price = materialReturnResultSet.getDouble(3); + int amount = materialReturnResultSet.getInt(4); + + newMonthReport(code, null,dept, "2", "价格统计", "c发货材料总价", price, list, null, null); + newMonthReport(code, null,dept, "3", "数量统计", "c发货材料数量", amount, list, null, null); + } + }catch(Exception e){ + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(materialReturnResultSet); + } + } + + if(StringUtils.isBlank(tousseType) || TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType) || TYPE_AUTO_DEDUCTION.equals(tousseType)){ + String tousseTypeSql = ""; + if(TYPE_AUTO_DEDUCTION.equals(tousseType)){ + tousseTypeSql = String.format(" and ii.type='%s' ", InvoiceItem.TYPE_AUTO_DEDUCTION); + } + // 一次性发货数量统计 + String disposableGoodsInvoiceAmountSql = "select i.settleAccountsDepartCoding as coding,i.settleAccountsDepart " + + "as depart,ii.amount,dg.type from Invoice i inner join InvoiceItem ii on i.id = ii.invoice_id " + + leftJoinDisposableGoods + + " dg on dg.id=ii.disposableGoodsId where " + + dataIndex.getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + +tousseTypeSql + +" and "+disposableGoodsInvoiceAmountPredicate + + " and (i.status ='收货签收' or i.status = '已发货') " + invoiceWheresql; + ResultSet disposableGoodsInvoiceAmountResultSet = objectDao.executeSql(disposableGoodsInvoiceAmountSql); + try { + Map codeAndTypeMap = new HashMap(); + while(disposableGoodsInvoiceAmountResultSet.next()){ + String code = disposableGoodsInvoiceAmountResultSet.getString(1); + String dept = disposableGoodsInvoiceAmountResultSet.getString(2); + int diposableAmount = disposableGoodsInvoiceAmountResultSet.getInt(3); + String type = disposableGoodsInvoiceAmountResultSet.getString("type"); + if(diposableAmount > 0){ + String key = new StringBuffer(code).append(",a").append(type).toString(); + if(codeAndTypeMap.containsKey(key)){ + MonthReportBean mrb = codeAndTypeMap.get(key); + mrb.setAmount(MathTools.add(mrb.getAmount(), diposableAmount).intValue()); + }else{ + MonthReportBean mrb = new MonthReportBean(); + mrb.setRowNum(code); + mrb.setDepartment(dept); + mrb.setAmount(diposableAmount); + codeAndTypeMap.put(key, mrb); + } + } + } + if(codeAndTypeMap.size() > 0){ + Map departSum = new HashMap(); + for (Entry entry : codeAndTypeMap.entrySet()) { + String key = entry.getKey(); + MonthReportBean item = entry.getValue(); + String code = item.getRowNum(); + int amount = item.getAmount(); + newMonthReport(code, null,item.getDepartment(),"3", "数量统计", key.substring(key.indexOf(",") + 1),amount, list, null, null); + if(departSum.containsKey(code)){ + MonthReportBean mrb = departSum.get(code); + mrb.setAmount(MathTools.add(mrb.getAmount(), amount).intValue()); + }else{ + departSum.put(code, item); + } + } + if(departSum.size() > 0){ + for (Entry entry : departSum.entrySet()) { + MonthReportBean item = entry.getValue(); + newMonthReportForGuiGang(item.getRowNum(), item.getDepartment(),"3", "数量统计","b一次性物品合计",item.getAmount(), list); + } + } + } + } catch (SQLException e) { + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(disposableGoodsInvoiceAmountResultSet); + } + + } + SupplyRoomConfig config = supplyRoomConfigManager.getFirstSupplyRoomConfig(); + if(isSupplyRoomUser && (StringUtils.isBlank(tousseType) || "器械材料".equals(tousseType) || TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType) || TYPE_AUTO_DEDUCTION.equals(tousseType))){ + if("器械材料".equals(tousseType)){ + receiveRecordItemPredicate = String.format(" (i.type!='一次性物品') "); + }else if(TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType)){ + if(StringUtils.isNotBlank(disposableGoodsType)){ + receiveRecordItemPredicate = String.format(" (i.type='一次性物品' and i.disposableGoodsId in(%s)) ", disposableGoodsIdSql); + } + }else{ + if(StringUtils.isNotBlank(disposableGoodsType)){ + receiveRecordItemPredicate = String.format(" (i.type!='一次性物品' or i.disposableGoodsId in(%s)) ", disposableGoodsIdSql); + } + } + String tousseTypeSql = ""; + if(TYPE_AUTO_DEDUCTION.equals(tousseType)){ + tousseTypeSql = String.format(" and r.type='%s' ", InvoiceItem.TYPE_AUTO_DEDUCTION); + } + //供应室领用(器械材料与一次性物品) + String receiveSql = "select i.type,(i.amount*i.price) price,i.amount,r.departcoding,dg.type dgType " + + "from ReceiveRecord r,ReceiveRecordItem i" + + leftJoinDisposableGoods + + " dg on dg.id = i.disposableGoodsId where r.id = i.receiverecord_id " + +tousseTypeSql + + "and "+receiveRecordItemPredicate + receiveDepartWhereSql + " and r.time " + betweenSql; + + ResultSet rs4 = objectDao.executeSql(receiveSql); + try { + Map codeAndTypeMap = new HashMap(); + String orgUnitName = config.getOrgUnitName();//为什么要用这个? + while(rs4.next()){ + String type = rs4.getString("type"); + Double price = rs4.getDouble("price"); + int amount = rs4.getInt("amount"); + String code = rs4.getString("departcoding"); + if("一次性物品".equals(type)){ + setCodeAndTypeMapData(codeAndTypeMap, code, orgUnitName, rs4.getString("dgType"), amount, price); + continue; + } + newMonthReport(code, null,config.getOrgUnitName(), "2", "价格统计", "c发货材料总价", price, list, null, null); + newMonthReport(code, null,config.getOrgUnitName(), "3", "数量统计", "c发货材料数量", amount, list, null, null); + } + addDisposableGoodsData(codeAndTypeMap, list); + }catch(Exception e){ + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(rs4); + } + } + // 一次性物品,调拨出库 + if(isSupplyRoomUser && (StringUtils.isBlank(tousseType) || TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType))){ + //供应室领用(器械材料与一次性物品) + String receiveSql = "select '一次性物品' type,(ged.amount*ged.price) price,ged.amount,oge.targetOrgUnitCode,oge.targetOrgUnitName,dg.type dgType " + + "from GodownEntry oge inner join GodownEntryDiposableGoodsItem ged on oge.id = ged.godownEntryID " + + leftJoinDisposableGoods + + " dg on dg.id=ged.disposableGoodsID where oge.type ='退库单' and oge.subType='调拨出库' " + + "and "+outEntryPredicate+" and " + + dataIndex.getHandleDeptCodeSql("oge.orgUnitCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + + SqlUtils.getFiledWhereSql("oge.targetOrgUnitName", department, 40) +" and oge.time " + betweenSql; + + ResultSet rs4 = objectDao.executeSql(receiveSql); + try { + Map codeAndTypeMap = new HashMap(); + while(rs4.next()){ + setCodeAndTypeMapData(codeAndTypeMap, rs4.getString("targetOrgUnitCode"), rs4.getString("targetOrgUnitName"), rs4.getString("dgType"), rs4.getInt("amount"), rs4.getDouble("price")); + } + addDisposableGoodsData(codeAndTypeMap, list); + }catch(Exception e){ + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(rs4); + } + } + // 一次性物品,盘亏出库 + if(isSupplyRoomUser && (StringUtils.isBlank(tousseType) || TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType))){ + //供应室领用(器械材料与一次性物品) + String receiveSql = "select (ged.amount*ged.price) price,ged.amount,oge.orgUnitCode,oge.orgUnitName,dg.type dgType" + + " from GodownEntry oge inner join GodownEntryDiposableGoodsItem ged on oge.id = ged.godownEntryID " + + leftJoinDisposableGoods + + " dg on dg.id=ged.disposableGoodsID where oge.type ='退库单' and oge.subType='盘亏出库' " + + "and "+outEntryPredicate+" and " + + dataIndex.getHandleDeptCodeSql("oge.orgUnitCode", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + + SqlUtils.getFiledWhereSql("oge.orgUnitName", department, 30)+" and oge.time " + betweenSql; + + ResultSet rs4 = objectDao.executeSql(receiveSql); + try { + Map codeAndTypeMap = new HashMap(); + while(rs4.next()){ + setCodeAndTypeMapData(codeAndTypeMap, rs4.getString("orgUnitCode"), rs4.getString("orgUnitName"), rs4.getString("dgType"), rs4.getInt("amount"), rs4.getDouble("price")); + } + addDisposableGoodsData(codeAndTypeMap, list); + }catch(Exception e){ + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(rs4); + } + } + // 一次性物品装配扣减库存 + { + if(isSupplyRoomUser && (StringUtils.isBlank(tousseType) || TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType))){ + String sql = "select (dgi.amount*dgi.fluctuationPrice) price,dgi.amount,pr.orgUnitCoding,pr.orgUnitName,dg.type dgType " + + "from PackingRecord pr inner join DiposableGoodsItem dgi on pr.id = dgi.packingRecordId " + + leftJoinDisposableGoods + + " dg on dg.id=dgi.disposableGoodsID where " + +packingDisposableGoodsTypePredicate+" and " + + dataIndex.getHandleDeptCodeSql("pr.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + + SqlUtils.getFiledWhereSql("pr.orgUnitName", department, 35) + " and pr.packTime " + betweenSql; + + ResultSet rs = objectDao.executeSql(sql); + try { + Map codeAndTypeMap = new HashMap(); + while(rs.next()){ + setCodeAndTypeMapData(codeAndTypeMap, rs.getString("orgUnitCoding"), rs.getString("orgUnitName"), rs.getString("dgType"), rs.getInt("amount"), rs.getDouble("price")); + } + addDisposableGoodsData(codeAndTypeMap, list); + }catch(Exception e){ + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(rs); + } + } + } + + //器械包(含消毒物品、敷料包等)发货数量统计 + if(StringUtils.isBlank(tousseType) || (!"器械材料".equals(tousseType) && !TousseItem.TYPE_DIPOSABLE_GOODS.equals(tousseType) && !TYPE_AUTO_DEDUCTION.equals(tousseType))){ + String columnSqlForInvoiceAmountSql = null; + String leftJoinSqlForInvoiceAmountSql = null; + if(dataSoureOfMaterialsCountOfToussesInReports == 3){ + columnSqlForInvoiceAmountSql = "ii.materialAmount,td.isApplyEntireTousse"; + leftJoinSqlForInvoiceAmountSql = String.format("left join %s td on ii.tousseDefinitionId=td.id", TousseDefinition.class.getSimpleName()); + }else{ + columnSqlForInvoiceAmountSql = "tdm.materialAmount,tdm.isApplyEntireTousse "; + leftJoinSqlForInvoiceAmountSql = " left join " + tousseDefinitionIdMaterialAmountSql + " tdm on tdm.id = ii.tousseDefinitionId "; + } + String invoiceAmountSql = "select i.settleAccountsDepartCoding as coding,i.settleAccountsDepart " + + "as depart,ii.amount,ii.tousseType," + + columnSqlForInvoiceAmountSql + + " from Invoice i join InvoiceItem ii on i.id = ii.invoice_id " + + leftJoinSqlForInvoiceAmountSql + + " where " + + dataIndex.getHandleDeptCodeSql("i.orgUnitCoding", isSupplyRoomUserOrIsExpensiveGoodsSupplyRoomUser, orgUnitCoding) + + SqlUtils.getFiledWhereSql("i.settleAccountsDepart", department, 45) + + " and (ii.amount is not null and ii.amount>0) "// 限制为只查包含器械包(含消毒物品、敷料包等)数量的 + + " and " + SqlUtils.getStringFieldInLargeCollectionsPredicate("ii.tousseType", allTousseType) + + " and (i.status ='收货签收' or i.status = '已发货') " + invoiceWheresql; + + ResultSet rs2 = objectDao.executeSql(invoiceAmountSql); + try { + while(rs2.next()){ + String code = rs2.getString(1); + String dept = rs2.getString(2); + int tousseAmount = rs2.getInt(3); + String tousseTypeName = rs2.getString(4); + int materialAmount = rs2.getInt("materialAmount"); + String isApplyEntireTousse = rs2.getString("isApplyEntireTousse"); + int totalMaterialAmount = tousseAmount * materialAmount; + // 如果是消毒物品,用统计数量替换包数量 + if ("消毒物品".equals(tousseTypeName) && Constants.STR_NO.equals(isApplyEntireTousse)) { + if (materialAmount > 0) { + tousseAmount = totalMaterialAmount; + } + }else if(TousseDefinition.PACKAGE_TYPE_CUSTOM.equals(tousseTypeName)&& !showCustonTousseAmount){ + if (materialAmount > 0) { + tousseAmount = totalMaterialAmount; + } + } + newMonthReport(code, null,dept,"3","数量统计", "c器械包数量",tousseAmount,list, null, null); + if(monthReportMaterialAmountOfTousse){ + newMonthReport(code, null,dept, "4", "包内材料统计", "c包内材料数量", totalMaterialAmount, list, null, null); + } + } + } catch (SQLException e) { + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(rs2); + } + } + final String TYPE_CHARGE = "收费项目"; + if(StringUtils.isBlank(tousseType) || TYPE_CHARGE.equals(tousseType)){ + String chargeDateSql = String.format(" and chargeTime %s ", betweenSql); + String chargeDepartSql = ""; + if(StringUtils.isNotBlank(department)){ + chargeDepartSql = String.format(" and ci.orgUnitName = '%s' ", department); + } + String sql = String.format("select ci.orgUnitName,ci.orgUnitCode,sum(price) price from ChargeRecordItem ci " + + " inner join ChargeRecord cr on cr.id=ci.chargeRecord_id where 1=1 %s %s group by ci.orgUnitName,ci.orgUnitCode", chargeDateSql,chargeDepartSql); + ResultSet rs5 = null; + try { + rs5 = objectDao.executeSql(sql); + while(rs5.next()){ + Double price = rs5.getDouble("price"); + String orgUnitName = rs5.getString("orgUnitName"); + String orgUnitCode = rs5.getString("orgUnitCode"); + newMonthReport(orgUnitCode, null,orgUnitName, "2", "价格统计", "c收费项目总价", price, list, null, null); + } + }catch(Exception e){ + e.printStackTrace(); + }finally { + DatabaseUtil.closeResultSetAndStatement(rs5); + } + } + return list; + } + /** + * 贵港专用的创建MonthReport,用于合计时减去一次性物品合计 + * @param code 部门编码 + * @param dept 部门名称 + * @param columnNum 列所属的title位置 + * @param columnTitle 列标题 + * @param columnName 列名 + * @param money 价格 + * @param list list + */ + private void newMonthReportForGuiGang(String code, String dept, + String columnNum, String columnTitle, String columnName, + Double money,List list) { + MonthReportBean bean = new MonthReportBean(); + bean.setSumOfDisposableGoods(money); + bean.setRowNum(code); + bean.setDepartment(dept); + bean.setColumnNum(columnNum); + bean.setColumnTitle(columnTitle); + bean.setColumnName(columnName); + bean.setMoney(money); + list.add(bean); + } + /** + * 添加一次性物品数据(包括各类型数量、价格和所有一次性物品的总数量和总价格) + * @param codeAndTypeMap <科室编码 + "," + a +一次物品类型, MonthReportBean> + * @param list List + */ + private void addDisposableGoodsData(Map codeAndTypeMap, List list){ + if(codeAndTypeMap.size() > 0){ + Map departSum = new HashMap();//一次性物品合计数据 + //添加一次性物品各类型数据 + for (Entry entry : codeAndTypeMap.entrySet()) { + String key = entry.getKey();//科室编码 + , + a +一次物品类型(a。b。c用于报表列排序) + MonthReportBean item = entry.getValue(); + String code = item.getRowNum(); + String dept = item.getDepartment(); + Double price = item.getMoney(); + Integer amount = item.getAmount(); + String columnName = key.substring(key.indexOf(",") + 1);//a +一次物品类型 + newMonthReport(code, null,dept, "2", "价格统计", columnName, price, list, null, null); + newMonthReport(code, null,dept,"3", "数量统计", columnName, amount, list, null, null); + if(departSum.containsKey(code)){//计算合计 + MonthReportBean mrb = departSum.get(code); + mrb.setAmount(MathTools.add(mrb.getAmount(), amount).intValue()); + mrb.setMoney(MathTools.add(mrb.getMoney(), price).doubleValue()); + }else{ + departSum.put(code, item); + } + } + //添加一次性物品合计 + if(departSum.size() > 0){ + for (Entry entry : departSum.entrySet()) { + MonthReportBean item = entry.getValue(); + newMonthReportForGuiGang(item.getRowNum(), item.getDepartment(), "2", "价格统计", "b一次性物品合计", item.getMoney(), list); + newMonthReportForGuiGang(item.getRowNum(), item.getDepartment(),"3", "数量统计","b一次性物品合计",item.getAmount(), list); + } + } + } + } + /** + * 贵港专用的创建MonthReport,用于合计时减去一次性物品合计 + * @param code 部门编码 + * @param dept 部门名称 + * @param columnNum 列所属的title位置 + * @param columnTitle 列标题 + * @param columnName 列名 + * @param money 价格 + * @param list list + */ + private void newMonthReportForGuiGang(String code, String dept, + String columnNum, String columnTitle, String columnName, + Integer amount,List list) { + MonthReportBean bean = new MonthReportBean(); + bean.setSumOfDisposableGoodsAmount(amount); + bean.setRowNum(code); + bean.setDepartment(dept); + bean.setColumnNum(columnNum); + bean.setColumnTitle(columnTitle); + bean.setColumnName(columnName); + bean.setAmount(amount); + list.add(bean); + } + /** + * 设置一次性物品数据 + * @param codeAndTypeMap <部门编码+","+一次性物品类型,MonthReportBean> + * @param departCode 部门编码 + * @param departName 部门名称 + * @param disposableGoodsType 一次性物品类型 + * @param amount 数量 + * @param price 价格 + */ + private void setCodeAndTypeMapData(Map codeAndTypeMap, String departCode, String departName, String disposableGoodsType, Integer amount, Double price){ + String key = new StringBuffer(20).append(departCode).append(",a").append(disposableGoodsType).toString(); + if(codeAndTypeMap.containsKey(key)){ + MonthReportBean mrb = codeAndTypeMap.get(key); + mrb.setAmount(MathTools.add(mrb.getAmount(), amount).intValue()); + mrb.setMoney(MathTools.add(mrb.getMoney(), price).doubleValue()); + }else{ + MonthReportBean mrb = new MonthReportBean(); + mrb.setRowNum(departCode); + mrb.setMoney(price); + mrb.setDepartment(departName); + mrb.setAmount(amount); + codeAndTypeMap.put(key, mrb); + } + } +}