public void DownloadInfectionStatisticsFile(int year, string templateFile) { var response = this.GetInfectionStatisticsData(year); SheetParameterContainer sheetParameterContainer = new SheetParameterContainer() { SheetName = "统计总表" }; dynamic[] categorys = new dynamic[] { new { category = "001", rowIndex = 7 }, //上呼吸道感染人次 new { category = "002", rowIndex = 9 }, //下呼吸道感染人次 new { category = "003", rowIndex = 14 }, //使用导尿管感染人次 new { category = "004", rowIndex = 17 }, //未使用导尿管感染人次 new { category = "005", rowIndex = 19 }, //疥疮感染人次 // new { category = "usedPipe", rowIndex = 13 }, //使用导尿管人日数 }; List <ElementFormatter> elementFormatters = new List <ElementFormatter>(); // 生成年份参数 sheetParameterContainer.ParameterList.Add(new Parameter() { Name = "year", RowIndex = 0, ColumnIndex = 1 }); elementFormatters.Add(new CellFormatter(sheetParameterContainer["year"], year)); for (int i = 0; i < categorys.Length; i++) { var item = categorys[i]; elementFormatters.Add(NewTableFormatter(response, sheetParameterContainer, item.rowIndex, item.category)); } #region 住民总人日数 int row = 2, col = 0; int queryMonth = 0; IReportManageService reportManageService = IOCContainer.Instance.Resolve <IReportManageService>(); var dbSet = unitOfWork.GetRepository <LTC_IPDREG>().dbSet.Where(o => o.ORGID == orgId && (o.IPDFLAG == "I") && o.INDATE.HasValue && ((DateTime)o.INDATE).Year == year).AsQueryable(); var ipd = (from a in dbSet let Year = SqlFunctions.DatePart("Year", (DateTime)a.INDATE) let Month = SqlFunctions.DatePart("Month", (DateTime)a.INDATE) group a by new { Year, Month } into g where g.Key.Year == year select new StatisticItem { Year = g.Key.Year, Month = g.Key.Month, Total = g.Count() }); var ipdRegList = ipd.ToList(); int maxMonth = 0; if (ipdRegList != null && ipdRegList.Count > 0) { maxMonth = ipdRegList.OrderByDescending(s => s.Month).FirstOrDefault().Month; } for (int j = 1; j <= 12; j++) { decimal leaveHospTotal = 0; decimal unPlanIpdTotal = 0; col = j; if (col > maxMonth) { queryMonth = 0; } else { queryMonth = col; } decimal total = unitOfWork.GetRepository <LTC_IPDREG>() .dbSet.Count( o => o.ORGID == orgId && (o.IPDFLAG == "I") && o.INDATE.HasValue && ((DateTime)o.INDATE).Year == year && ((DateTime)o.INDATE).Month <= queryMonth); decimal ipdRegInTotal = total * DateTime.DaysInMonth(year, j); //当月在院住民总人日数 decimal ipdRegOutTotal = reportManageService.OutLeaveUnPlanTotal(year, col, reportManageService.GetIpdOutTotal(year)); //当月结案的人日次数 if (ipdRegInTotal == 0 && ipdRegOutTotal == 0) { leaveHospTotal = 0; unPlanIpdTotal = 0; } else { leaveHospTotal = reportManageService.OutLeaveUnPlanTotal(year, col, reportManageService.GetLeaveHospTotal(year)); // 当月请假的人日次数 unPlanIpdTotal = reportManageService.OutLeaveUnPlanTotal(year, col, reportManageService.GetUnPlanIpdTotal(year)); //当月非计划住院人日次数 } decimal ipdRegCount = ipdRegInTotal + ipdRegOutTotal - leaveHospTotal - unPlanIpdTotal; //当月住民总人日数 elementFormatters.Add(new CellFormatter(new Parameter() { Name = string.Format("{0}_{1}", row, col), RowIndex = row, ColumnIndex = col }, ipdRegCount)); } #endregion #region 使用导尿管人日数 row = 13; for (int j = 1; j <= 12; j++) { decimal sTotal = 0; col = j; if (col <= maxMonth) { sTotal = reportManageService.OutLeaveUnPlanTotal(year, col, reportManageService.GetUsedPipeDaysTotal(year)); } else { sTotal = 0; } elementFormatters.Add(new CellFormatter(new Parameter() { Name = string.Format("{0}_{1}", row, col), RowIndex = row, ColumnIndex = col }, sTotal)); } #endregion ExportHelper.ExportToWeb(templateFile, Path.GetFileName(templateFile), new SheetFormatter("统计总表", elementFormatters.Where(it => it != null).ToArray())); }