Ejemplo n.º 1
0
        /// <summary>
        /// 按借还者统计借还信息
        /// </summary>
        /// <param name="req">条件</param>
        /// <returns></returns>
        public async Task <List <SumListInfo <string> > > SumBorrowRepayTargetAsync(BorrowRepaySumReq req)
        {
            //统计
            var list = await ReportDAL.Inst.SumBorrowRepayTargetAsync(this.LoginInfo.FamilyID);

            //是否显示金额为0的记录
            if (req.IsShowZero == false)
            {
                list = list.Where(m => m.value != 0).ToList();
            }

            //按金额绝对值降序排序
            list = list.OrderByDescending(m => Math.Abs(m.value)).ToList();
            return(list);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 按年度统计
        /// </summary>
        /// <param name="familyID">家庭ID</param>
        /// <param name="req">条件</param>
        /// <returns></returns>
        public async Task <List <BorrowRepaySumListInfo <string> > > SumBorrowRepayYearAsync(int familyID, BorrowRepaySumReq req)
        {
            using (IOSysContext db = new IOSysContext())
            {
                //条件
                var q = this.GetSumBorrowRepayWhere(db, familyID, req.StartDate, req.EndDate, req.LstBRType);

                //统计
                var list = await(from m in q
                                 group m by new { m.BRDate.Year, m.BRType } into g
                                 select new BorrowRepaySumListInfo <string>()
                {
                    name   = CvtHelper.ToStr(g.Key.Year),
                    BRType = g.Key.BRType,
                    value  = g.Sum(m => m.Amount)
                }).ToListAsync();

                return(list);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 按类型统计
        /// </summary>
        /// <param name="familyID">家庭ID</param>
        /// <param name="req">条件</param>
        /// <returns></returns>
        public async Task <List <BorrowRepaySumListInfo <int> > > SumBorrowRepayBRTypeAsync(int familyID, BorrowRepaySumReq req)
        {
            using (IOSysContext db = new IOSysContext())
            {
                //条件
                var q = this.GetSumBorrowRepayWhere(db, familyID, req.StartDate, req.EndDate, req.LstBRType);

                //统计
                var list = await(from m in q
                                 group m by m.BRType into g
                                 select new BorrowRepaySumListInfo <int>
                {
                    name   = g.Key,
                    BRType = g.Key,
                    value  = g.Sum(m => m.Amount)
                }).ToListAsync();

                return(list);
            }
        }
Ejemplo n.º 4
0
        public async Task <ResultList <SumListInfo <string> > > SumBorrowRepayTargetAsync([FromQuery] BorrowRepaySumReq req)
        {
            var list = await this.bll.SumBorrowRepayTargetAsync(req);

            return(new ResultList <SumListInfo <string> >(true, this.bll.Res.Gen.OK, list));
        }
Ejemplo n.º 5
0
        /// <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);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 用户收支统计
        /// </summary>
        /// <returns></returns>
        public async Task <UserTotalInfo> SumUserTotal()
        {
            //用户信息
            var taskUser = AccountDAL.Inst.GetUserAsync(this.LoginInfo.FamilyID, this.LoginInfo.UserID);

            // 获取家庭信息
            var taskFamily = BasicDAL.Inst.GetFamilyAsync(this.LoginInfo.FamilyID);

            //账户信息
            var taskLstAccount = BasicDAL.Inst.QueryAmountAccountAsync(this.LoginInfo.FamilyID);

            //当前年开始
            DateTime curYearStart = new DateTime(DateTime.Today.Year, 1, 1);
            //当前年结束
            DateTime curYearEnd = curYearStart.AddYears(1).AddMilliseconds(-1);
            //当前月开始
            DateTime curMonthStart = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
            //当前月结束
            DateTime curMonthEnd = curMonthStart.AddMonths(1).AddMilliseconds(-1);

            //统计年收入
            var taskSumInYear = ReportDAL.Inst.SumInComeAsync(this.LoginInfo.FamilyID, curYearStart, curYearEnd);
            //统计月收入
            var taskSumInMonth = ReportDAL.Inst.SumInComeAsync(this.LoginInfo.FamilyID, curMonthStart, curMonthEnd);

            //统计年支出
            var taskSumOutYear = ReportDAL.Inst.SumOutPutAsync(this.LoginInfo.FamilyID, curYearStart, curYearEnd);
            //统计月支出
            var taskSumOutMonth = ReportDAL.Inst.SumOutPutAsync(this.LoginInfo.FamilyID, curMonthStart, curMonthEnd);

            //统计年借还
            var reqBRYear = new BorrowRepaySumReq();

            reqBRYear.StartDate = curYearStart;
            reqBRYear.EndDate   = curYearEnd;
            var taskSumBRYear = ReportDAL.Inst.SumBorrowRepayBRTypeAsync(this.LoginInfo.FamilyID, reqBRYear);

            //统计月借还
            var reqBRMonth = new BorrowRepaySumReq();

            reqBRMonth.StartDate = curMonthStart;
            reqBRMonth.EndDate   = curMonthEnd;
            var taskSumBRMonth = ReportDAL.Inst.SumBorrowRepayBRTypeAsync(this.LoginInfo.FamilyID, reqBRMonth);

            var info = new UserTotalInfo();

            info.NickName         = (await taskUser).NickName;
            info.FamilyName       = (await taskFamily).Name;
            info.TotalAmount      = (await taskLstAccount).Sum(m => m.Amount);
            info.Year             = curYearStart.Year;
            info.TotalInCurYear   = await taskSumInYear;
            info.TotalOutCurYear  = await taskSumOutYear;
            info.Month            = curMonthStart.Month;
            info.TotalInCurMonth  = await taskSumInMonth;
            info.TotalOutCurMonth = await taskSumOutMonth;

            var lstSumBRYear = await taskSumBRYear;

            info.TotalBRInCurYear = lstSumBRYear
                                    .Where(m => m.BRType == (int)EnmBorrowRepayType.BorrowIn || m.BRType == (int)EnmBorrowRepayType.RepayIn).Sum(m => m.value);
            info.TotalBROutCurYear = lstSumBRYear
                                     .Where(m => m.BRType == (int)EnmBorrowRepayType.BorrowOut || m.BRType == (int)EnmBorrowRepayType.RepayOut).Sum(m => m.value);

            var lstSumBTMonth = await taskSumBRMonth;

            info.TotalBRInCurMonth = lstSumBTMonth
                                     .Where(m => m.BRType == (int)EnmBorrowRepayType.BorrowIn || m.BRType == (int)EnmBorrowRepayType.RepayIn).Sum(m => m.value);
            info.TotalBROutCurMonth = lstSumBTMonth
                                      .Where(m => m.BRType == (int)EnmBorrowRepayType.BorrowOut || m.BRType == (int)EnmBorrowRepayType.RepayOut).Sum(m => m.value);

            return(info);
        }
Ejemplo n.º 7
0
        /// <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> >());
        }