using HL_FristAidPlatform_Help; using HL_FristAidPlatform_IDataBase; using HL_FristAidPlatform_Models; using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace HL_FristAidPlatform_DataBase { /// /// 人均费用 /// public class T_Service_Apoplexy_PerCapitaCostDB : BaseDB, IT_Service_Apoplexy_PerCapitaCost { public SqlSugarClient db = GetClient(); /// /// 统计人均费用 /// /// /// /// /// public List StatisticalPerCapitaExpenses(string hospitalGuid, string startTime, string endTime,int type) { List list = new List(); DateTime dt1 = DateTime.Now; DateTime dt2 = DateTime.Now; if (type == 2) { int year = int.Parse(startTime); dt1 = new DateTime(year, 1, 1); dt2 = new DateTime(year, 12, 31); } if (type == 1) { DateTime startdt = Convert.ToDateTime(startTime); dt1 = startdt.AddDays(1 - startdt.Day); DateTime enddt = Convert.ToDateTime(endTime); dt2 = enddt.AddDays(1 - enddt.Day).AddMonths(1).AddDays(-1); } //数据结果集 var oneClass = db.Queryable((a, b) => a.GUID == b.PatientGuid) .Where((a, b) => a.HospitalGuid == hospitalGuid && a.DeleteFlag == 0&& !SqlFunc.IsNullOrEmpty(b.CYTime)&& SqlFunc.ToDate(b.CYTime) >= dt1 && SqlFunc.ToDate(b.CYTime) <= dt2.AddDays(1)) .Select((a, b) => new StatisticalPerCapitaExpensesModel { PatientGuid = b.PatientGuid, CYTime = b.CYTime, AllInCost = b.AllInCost, }).ToList(); //月份集合 List monthList = new List(); int Month = (dt2.Year - dt1.Year) * 12 + (dt2.Month - dt1.Month); for (int i = 0; i < Month + 1; i++) { string res = dt1.AddMonths(i).Year + "-" + GetDateZero(dt1.AddMonths(i).Month) + "-01"; DateTime dt = Convert.ToDateTime(res); monthList.Add(dt.AddDays(1 - dt.Day)); } //填充结果集 if (oneClass != null) { if (monthList.Count > 0) { AverageResultModel model = null; for (int i = 0; i < monthList.Count; i++) { DateTime start = Convert.ToDateTime(monthList[i]); DateTime end = Convert.ToDateTime(monthList[i]).AddMonths(1).AddDays(-1); string timeDate = monthList[i].ToString("yyyy-MM"); model = new AverageResultModel(); model.Key = timeDate; //住院费用(月) float Costsum = (float)oneClass.Where(j => SqlFunc.ToDate(j.CYTime) >= start && SqlFunc.ToDate(j.CYTime) <= end.AddDays(1)&&!string.IsNullOrEmpty(j.AllInCost)).Sum(i => Convert.ToDouble(i.AllInCost)); //每月药物费用(单位:元(人民币)) //每月总人数 int Count = oneClass.Where(j => SqlFunc.ToDate(j.CYTime) >= start && SqlFunc.ToDate(j.CYTime) <= end.AddDays(1)).Count(); if(Count == 0) model.Value = "0.00"; if (Count > 0) //住院平均费用(月) model.Value = ((double)Costsum / Count).ToString("#0.00"); if (Count == 0) model.Value = ((double)Count).ToString("#0.00"); list.Add(model); } } } else { AverageResultModel model = null; for (int i = 0; i < monthList.Count; i++) { string timeDate = monthList[i].ToString("yyyy-MM"); model = new AverageResultModel(); model.Key = timeDate; list.Add(model); } } return list; } public string GetDateZero(int date) { if (date < 10) { return "0" + date; } else { return date.ToString(); } } } }