/// <summary> /// 月份统计 /// </summary> /// <param name="req"></param> /// <returns></returns> public async Task <List <MonthSumListInfo <string> > > SumMonthAsync(MonthSumReq req) { //收入 var reqIn = new InSumReq(); reqIn.GroupType = EnmInGroupType.Month; reqIn.IsContainBorrowRepay = req.IsContainBorrowRepay; var taskIn = this.SumInComeAsync(reqIn); //支出 var reqOut = new OutSumReq(); reqOut.GroupType = EnmOutGroupType.Month; reqOut.IsContainBorrowRepay = req.IsContainBorrowRepay; var taskOut = this.SumOutPutAsync(reqOut); //结果 var list = new List <MonthSumListInfo <string> >(); //收入 var lstIn = await taskIn; foreach (var income in lstIn) { list.Add(new MonthSumListInfo <string>() { name = income.name, value = income.value, DataType = EnmDataType.In, DataTypeName = this.Res.Cst.DT.In }); } //支出 var lstOut = await taskOut; foreach (var output in lstOut) { list.Add(new MonthSumListInfo <string>() { name = output.name, value = -output.value, DataType = EnmDataType.Out, DataTypeName = this.Res.Cst.DT.Out }); } //排序 list = list.OrderByDescending(m => m.name).ThenByDescending(m => m.value).ToList(); return(list); }
/// <summary> /// 按年度统计 /// </summary> /// <param name="familyID">家庭ID</param> /// <param name="req">条件</param> /// <returns></returns> public async Task <List <SumListInfo <string> > > SumOutPutYearAsync(int familyID, OutSumReq req) { using (IOSysContext db = new IOSysContext()) { //条件 var q = this.GetSumOutPutWhere(db, familyID, req.StartDate, req.EndDate); //统计 var list = await(from m in q group m by m.OutDate.Year into g select new SumListInfo <string>() { name = CvtHelper.ToStr(g.Key), value = g.Sum(m => m.Amount) }).ToListAsync(); return(list); } }
/// <summary> /// 按账户统计 /// </summary> /// <param name="familyID">家庭ID</param> /// <param name="req">条件</param> /// <returns></returns> public async Task <List <SumListInfo <int> > > SumOutPutAmountAccountAsync(int familyID, OutSumReq req) { using (IOSysContext db = new IOSysContext()) { //条件 var q = this.GetSumOutPutWhere(db, familyID, req.StartDate, req.EndDate); //统计 var list = await(from m in q group m by m.AmountAccountID into g select new SumListInfo <int> { name = g.Key, value = g.Sum(m => m.Amount) }).ToListAsync(); return(list); } }
/// <summary> /// 按分类统计 /// </summary> /// <param name="familyID">家庭ID</param> /// <param name="req">条件</param> /// <returns></returns> public async Task <List <SumListInfo <int> > > SumOutPutOutCategoryAsync(int familyID, OutSumReq req) { using (IOSysContext db = new IOSysContext()) { //条件 var q = this.GetSumOutPutWhere(db, familyID, req.StartDate, req.EndDate); //统计 var list = await(from op in q join otTemp in db.OutTypes on op.OutTypeID equals otTemp.ID into otJoin from ot in otJoin group op by ot.OutCategoryID into g select new SumListInfo <int> { name = g.Key, value = g.Sum(m => m.Amount) }).ToListAsync(); return(list); } }
public async Task <ResultList <SumListInfo <string> > > SumOutPutAsync([FromQuery] OutSumReq req) { var list = await this.bll.SumOutPutAsync(req); return(new ResultList <SumListInfo <string> >(true, this.bll.Res.Gen.OK, list)); }
/// <summary> /// 月份支出统计 /// </summary> /// <param name="req">条件</param> /// <returns></returns> public async Task <List <MonthOutCategorySumListInfo> > SumMonthOutAsync(MonthOutSumReq req) { //开始日期 var startDate = new DateTime(req.Month.Year, req.Month.Month, 1); //截止日期 var endDate = startDate.AddMonths(1).AddMilliseconds(-1); //类型 var taskOutType = BasicDAL.Inst.QueryOutTypeAsync(this.LoginInfo.FamilyID); //分类 var taskOutCategory = BasicDAL.Inst.QueryOutCategoryAsync(this.LoginInfo.FamilyID); //统计借还 Task <List <BorrowRepaySumListInfo <int> > > taskSumBR = null; //是否包含借还 if (req.IsContainBorrowRepay) { //借还统计条件 var reqBR = new BorrowRepaySumReq(); reqBR.StartDate = startDate; reqBR.EndDate = endDate; reqBR.LstBRType.Add((int)EnmBorrowRepayType.BorrowOut); reqBR.LstBRType.Add((int)EnmBorrowRepayType.RepayOut); reqBR.GroupType = EnmBorrowRepayGroupType.BRType; //借还统计 taskSumBR = ReportDAL.Inst.SumBorrowRepayBRTypeAsync(this.LoginInfo.FamilyID, reqBR); } //支出统计条件 var reqOut = new OutSumReq(); reqOut.StartDate = startDate; reqOut.EndDate = endDate; reqOut.GroupType = EnmOutGroupType.OutType; reqOut.IsContainBorrowRepay = req.IsContainBorrowRepay; //统计支出 var taskSumOut = ReportDAL.Inst.SumOutPutOutTypeAsync(this.LoginInfo.FamilyID, reqOut); //等待查询完成 var lstOutCategory = await taskOutCategory; var lstOutType = await taskOutType; var lstOutPut = await taskSumOut; var list = new List <MonthOutCategorySumListInfo>(); foreach (var output in lstOutPut) { //支出类型 var outType = lstOutType.Find(m => m.ID == output.name); //支出分类 var outCategory = lstOutCategory.Find(m => m.ID == outType.OutCategoryID); //列表中如果没有此支出分类 if (list.Exists(m => m.ID == outCategory.ID) == false) { var itemOC = new MonthOutCategorySumListInfo(); list.Add(itemOC); itemOC.ID = outCategory.ID; itemOC.Name = outCategory.Name; itemOC.DataType = EnmDataType.Out; itemOC.LstSumOutType = new List <MonthOutTypeSumListInfo>(); } //支出分类统计 var ocSum = list.Find(m => m.ID == outCategory.ID); //支出类型统计 var otSum = new MonthOutTypeSumListInfo(); ocSum.LstSumOutType.Add(otSum); otSum.ID = outType.ID; otSum.Name = outType.Name; otSum.Amount = output.value; } //借还 if (req.IsContainBorrowRepay) { var itemBR = new MonthOutCategorySumListInfo(); list.Add(itemBR); itemBR.ID = 0; itemBR.Name = this.Res.Cst.DT.BorrowRepay; itemBR.DataType = EnmDataType.BorrowRepay; itemBR.LstSumOutType = new List <MonthOutTypeSumListInfo>(); var lstSumBR = await taskSumBR; foreach (var sumBR in lstSumBR) { //借还统计 var brSum = new MonthOutTypeSumListInfo(); itemBR.LstSumOutType.Add(brSum); brSum.ID = sumBR.name; brSum.Name = this.GetBorrowRepayTypeName(sumBR.BRType); brSum.Amount = sumBR.value; } } //排序 list = list.OrderByDescending(m => m.Amount).ToList(); return(list); }
/// <summary> /// 支出统计 /// </summary> /// <param name="req">条件</param> /// <returns></returns> public async Task <List <SumListInfo <string> > > SumOutPutAsync(OutSumReq req) { //借还统计条件 var reqSumBR = new BorrowRepaySumReq(); reqSumBR.StartDate = req.StartDate; reqSumBR.EndDate = req.EndDate; reqSumBR.LstBRType.Add((int)EnmBorrowRepayType.BorrowOut); reqSumBR.LstBRType.Add((int)EnmBorrowRepayType.RepayOut); //统计类型 switch (req.GroupType) { case EnmOutGroupType.OutCategory: #region 分类 { //分类 var taskOutCategory = BasicDAL.Inst.QueryOutCategoryAsync(this.LoginInfo.FamilyID); //统计 var taskSum = ReportDAL.Inst.SumOutPutOutCategoryAsync(this.LoginInfo.FamilyID, req); //统计借还 Task <List <BorrowRepaySumListInfo <int> > > taskSumBR = null; //是否包含借还 if (req.IsContainBorrowRepay) { reqSumBR.GroupType = EnmBorrowRepayGroupType.BRType; taskSumBR = ReportDAL.Inst.SumBorrowRepayBRTypeAsync(this.LoginInfo.FamilyID, reqSumBR); } //等待查询完成 var lstOutCategory = await taskOutCategory; var lstSum = await taskSum; //返回值 var list = new List <SumListInfo <string> >(); foreach (var temp in lstSum) { var item = new SumListInfo <string>(); list.Add(item); var outCategory = lstOutCategory.Find(m => m.ID == temp.name); item.name = outCategory != null ? outCategory.Name : string.Empty; item.value = temp.value; } //是否包含借还 if (req.IsContainBorrowRepay) { var lstSumBR = await taskSumBR; foreach (var sumBR in lstSumBR) { var item = new SumListInfo <string>(); list.Add(item); item.name = this.GetBorrowRepayTypeName(sumBR.BRType); item.value = sumBR.value; } } list = list.OrderByDescending(m => m.value).ToList(); return(list); } #endregion case EnmOutGroupType.OutType: #region 类型 { //类型 var taskOutType = BasicDAL.Inst.QueryOutTypeAsync(this.LoginInfo.FamilyID); //统计 var taskSum = ReportDAL.Inst.SumOutPutOutTypeAsync(this.LoginInfo.FamilyID, req); //统计借还 Task <List <BorrowRepaySumListInfo <int> > > taskSumBR = null; //是否包含借还 if (req.IsContainBorrowRepay) { reqSumBR.GroupType = EnmBorrowRepayGroupType.BRType; taskSumBR = ReportDAL.Inst.SumBorrowRepayBRTypeAsync(this.LoginInfo.FamilyID, reqSumBR); } //等待查询完成 var lstOutType = await taskOutType; var lstSum = await taskSum; //返回值 var list = new List <SumListInfo <string> >(); foreach (var temp in lstSum) { var item = new SumListInfo <string>(); list.Add(item); var outType = lstOutType.Find(m => m.ID == temp.name); item.name = outType != null ? outType.Name : string.Empty; item.value = temp.value; } //是否包含借还 if (req.IsContainBorrowRepay) { var lstSumBR = await taskSumBR; foreach (var sumBR in lstSumBR) { var item = new SumListInfo <string>(); list.Add(item); item.name = this.GetBorrowRepayTypeName(sumBR.BRType); item.value = sumBR.value; } } list = list.OrderByDescending(m => m.value).ToList(); return(list); } #endregion case EnmOutGroupType.AmountAccount: #region 账户 { //账户 var taskAmountAccount = BasicDAL.Inst.QueryAmountAccountAsync(this.LoginInfo.FamilyID); //统计 var taskSum = ReportDAL.Inst.SumOutPutAmountAccountAsync(this.LoginInfo.FamilyID, req); //统计借还 Task <List <BorrowRepaySumListInfo <int> > > taskSumBR = null; //是否包含借还 if (req.IsContainBorrowRepay) { reqSumBR.GroupType = EnmBorrowRepayGroupType.AmountAccount; taskSumBR = ReportDAL.Inst.SumBorrowRepayAmountAccountAsync(this.LoginInfo.FamilyID, reqSumBR); } //等待查询完成 var lstAmountAccount = await taskAmountAccount; var lstSum = await taskSum; //是否包含借还 if (req.IsContainBorrowRepay) { var lstSumBR = await taskSumBR; lstSum.AddRange(lstSumBR); lstSum = (from m in lstSum group m by m.name into g select new SumListInfo <int>() { name = g.Key, value = g.Sum(m => m.value) }).ToList(); } //返回值 var list = new List <SumListInfo <string> >(); foreach (var temp in lstSum) { var item = new SumListInfo <string>(); list.Add(item); var amountAccount = lstAmountAccount.Find(m => m.ID == temp.name); item.name = amountAccount != null ? amountAccount.Name : string.Empty; item.value = temp.value; } list = list.OrderByDescending(m => m.value).ToList(); return(list); } #endregion case EnmOutGroupType.Month: #region 月份 { //统计 var taskSum = ReportDAL.Inst.SumOutPutMonthAsync(this.LoginInfo.FamilyID, req); //统计借还 Task <List <BorrowRepaySumListInfo <string> > > taskSumBR = null; //是否包含借还 if (req.IsContainBorrowRepay) { reqSumBR.GroupType = EnmBorrowRepayGroupType.Month; taskSumBR = ReportDAL.Inst.SumBorrowRepayMonthAsync(this.LoginInfo.FamilyID, reqSumBR); } //等待查询完成 var lstSum = await taskSum; //是否包含借还 if (req.IsContainBorrowRepay) { var lstSumBR = await taskSumBR; lstSum.AddRange(lstSumBR); lstSum = (from m in lstSum group m by m.name into g select new SumListInfo <string>() { name = g.Key, value = g.Sum(m => m.value) }).ToList(); } lstSum = lstSum.OrderByDescending(m => m.name).ToList(); return(lstSum); } #endregion case EnmOutGroupType.Year: #region 年度 { //统计 var taskSum = ReportDAL.Inst.SumOutPutYearAsync(this.LoginInfo.FamilyID, req); //统计借还 Task <List <BorrowRepaySumListInfo <string> > > taskSumBR = null; //是否包含借还 if (req.IsContainBorrowRepay) { reqSumBR.GroupType = EnmBorrowRepayGroupType.Year; taskSumBR = ReportDAL.Inst.SumBorrowRepayYearAsync(this.LoginInfo.FamilyID, reqSumBR); } //等待查询完成 var lstSum = await taskSum; //是否包含借还 if (req.IsContainBorrowRepay) { var lstSumBR = await taskSumBR; lstSum.AddRange(lstSumBR); lstSum = (from m in lstSum group m by m.name into g select new SumListInfo <string>() { name = g.Key, value = g.Sum(m => m.value) }).ToList(); } lstSum = lstSum.OrderByDescending(m => m.name).ToList(); return(lstSum); } #endregion } return(new List <SumListInfo <string> >()); }