Пример #1
0
        /// <summary>
        /// 查询账户流水
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public async Task <PageMonthAmountList <AccountTurnoverListInfo> > QueryAccountTurnoverAsync(AccountTurnoverListReq req)
        {
            //开始日期
            DateTime startDate = new DateTime(req.Month.Year, req.Month.Month, 1);
            //结束日期
            DateTime endDate = startDate.AddMonths(1).AddMilliseconds(-1);

            #region 查询

            //查询收入明细
            var reqIn = new InRecordReq()
            {
                StartDate          = startDate,
                EndDate            = endDate,
                LstAmountAccountID = req.LstAmountAccountID
            };
            var taskIn = this.QueryInRecordAsync(reqIn);

            //查询支出明细
            var reqOut = new OutRecordReq()
            {
                StartDate          = startDate,
                EndDate            = endDate,
                LstAmountAccountID = req.LstAmountAccountID
            };
            var taskOut = this.QueryOutRecordAsync(reqOut);

            //查询转账转出明细
            var reqTransferFrom = new TransferRecordReq()
            {
                StartDate = startDate,
                EndDate   = endDate,
                LstFromAmountAccountID = req.LstAmountAccountID
            };
            var taskTransferFrom = this.QueryTransferRecordAsync(reqTransferFrom);

            //查询转账转入明细
            var reqTransferTo = new TransferRecordReq()
            {
                StartDate            = startDate,
                EndDate              = endDate,
                LstToAmountAccountID = req.LstAmountAccountID
            };
            var taskTransferTo = this.QueryTransferRecordAsync(reqTransferTo);

            //查询借还明细
            var reqBR = new BorrowRepayRecordReq()
            {
                StartDate          = startDate,
                EndDate            = endDate,
                LstAmountAccountID = req.LstAmountAccountID
            };
            var taskBR = this.QueryBorrowRepayRecordAsync(reqBR);

            #endregion

            #region 结果类型转换

            //返回结果
            var list = new List <AccountTurnoverListInfo>();

            //收入
            var lstIn = await taskIn;
            foreach (var record in lstIn)
            {
                var item = new AccountTurnoverListInfo();
                list.Add(item);

                item.DataType          = EnmDataType.In;
                item.ID                = record.ID;
                item.Date              = record.InDate;
                item.AmountAccountName = record.AmountAccountName;
                item.TypeName          = record.InTypeName;
                item.Amount            = record.Amount;
            }

            //支出
            var lstOut = await taskOut;
            foreach (var record in lstOut)
            {
                var item = new AccountTurnoverListInfo();
                list.Add(item);

                item.DataType          = EnmDataType.Out;
                item.ID                = record.ID;
                item.Date              = record.OutDate;
                item.AmountAccountName = record.AmountAccountName;
                item.TypeName          = record.OutTypeName;
                item.Amount            = -record.Amount;
            }

            //转账转出
            var lstTransferFrom = await taskTransferFrom;
            foreach (var record in lstTransferFrom)
            {
                var item = new AccountTurnoverListInfo();
                list.Add(item);

                item.DataType          = EnmDataType.Transfer;
                item.ID                = record.ID;
                item.Date              = record.TransferDate;
                item.AmountAccountName = record.FromAmountAccountName;
                item.TypeName          = this.Res.Cst.TranDir.TransferOut;
                item.Amount            = -record.Amount;
            }

            //转账转入
            var lstTransferTo = await taskTransferTo;
            foreach (var record in lstTransferTo)
            {
                var item = new AccountTurnoverListInfo();
                list.Add(item);

                item.DataType          = EnmDataType.Transfer;
                item.ID                = record.ID;
                item.Date              = record.TransferDate;
                item.AmountAccountName = record.ToAmountAccountName;
                item.TypeName          = this.Res.Cst.TranDir.TransferIn;
                item.Amount            = record.Amount;
            }

            //借还
            var lstBR = await taskBR;
            foreach (var record in lstBR)
            {
                var item = new AccountTurnoverListInfo();
                list.Add(item);

                item.DataType          = EnmDataType.BorrowRepay;
                item.ID                = record.ID;
                item.Date              = record.BRDate;
                item.AmountAccountName = record.AmountAccountName;

                switch ((EnmBorrowRepayType)record.BRType)
                {
                case EnmBorrowRepayType.BorrowIn:
                    item.TypeName = this.Res.Cst.BRT.BorrowIn;
                    item.Amount   = record.Amount;
                    break;

                case EnmBorrowRepayType.RepayIn:
                    item.TypeName = this.Res.Cst.BRT.RepayIn;
                    item.Amount   = record.Amount;
                    break;

                case EnmBorrowRepayType.BorrowOut:
                    item.TypeName = this.Res.Cst.BRT.BorrowOut;
                    item.Amount   = -record.Amount;
                    break;

                case EnmBorrowRepayType.RepayOut:
                    item.TypeName = this.Res.Cst.BRT.RepayOut;
                    item.Amount   = -record.Amount;
                    break;
                }
            }

            //总金额
            var totalAmount = list.Sum(m => m.Amount);

            #endregion

            //排序
            list = list.OrderByDescending(m => m.Date).ThenByDescending(m => m.ID).ThenBy(m => m.Amount).ToList();

            //是否还有前一个月的数据
            var hasPreMonth = startDate > (await InOutDAL.Inst.GetMinTurnoverDate(this.LoginInfo.FamilyID));

            return(new PageMonthAmountList <AccountTurnoverListInfo>(list, req.Month, totalAmount, hasPreMonth));
        }