/// <inheritdoc /> public IEnumerable <VoucherDetail> SelectVoucherDetails(IVoucherDetailQuery query) { var preF = query.VoucherQuery.Accept(new MongoDbNativeVoucher()); var chk = GetChk(query); var srt = Builders <Voucher> .Sort.Ascending("date"); return(m_Vouchers.Aggregate().Match(preF).Sort(srt).Project(ProjectDetails).Unwind("detail").Match(chk) .Project(ProjectDetail).ToEnumerable().Select(b => BsonSerializer.Deserialize <VoucherDetail>(b))); }
private static FilterDefinition <BsonDocument> GetChk(IVoucherDetailQuery query) { var visitor = new MongoDbNativeDetailUnwinded(); return(query.DetailEmitFilter != null ? query.DetailEmitFilter.DetailFilter.Accept(visitor) : (query.VoucherQuery is IVoucherQueryAtom dQuery ? dQuery.DetailFilter.Accept(visitor) : throw new ArgumentException("不指定细目映射检索式时记账凭证检索式为复合检索式", nameof(query)))); }
private IVoucherDetailQuery Regularize(IVoucherDetailQuery filt) { if (filt.DetailEmitFilter != null) { return(filt); } if (filt.VoucherQuery is IVoucherQueryAtom dQuery) { return(new StmtVoucherDetailQuery(filt.VoucherQuery, dQuery.DetailFilter)); } throw new ArgumentException("不指定细目映射检索式时记账凭证检索式为复合检索式", nameof(filt)); }
private void RunCheck(IVoucherDetailQuery filt, CsvParser parsed, StringBuilder sb) { if (filt.IsDangerous()) { throw new SecurityException("检测到弱检索式"); } var res = Accountant.SelectVouchers(filt.VoucherQuery); var lst = new List <BankItem>(parsed.Items); foreach (var v in res) { foreach (var d in v.Details) { if (!d.IsMatch(filt.DetailEmitFilter.DetailFilter)) { continue; } // ReSharper disable once PossibleInvalidOperationException var obj1 = lst.FirstOrDefault(b => (b.Fund - d.Fund.Value).IsZero() && b.Date == v.Date); if (obj1 != null) { lst.Remove(obj1); continue; } var obj2 = lst // ReSharper disable once PossibleInvalidOperationException .Where(b => (b.Fund - d.Fund.Value).IsZero()) // ReSharper disable once PossibleInvalidOperationException .OrderBy(b => Math.Abs((b.Date - v.Date.Value).TotalDays)) .FirstOrDefault(); if (obj2 != null) { lst.Remove(obj2); continue; } sb.AppendLine($"{v.ID.Quotation('^')} {v.Date.AsDate()} {d.Content} {d.Fund.AsCurrency(d.Currency)}"); } } foreach (var b in lst) { sb.AppendLine(b.Raw); } }
private async IAsyncEnumerable <string> RunCheck(Session session, IVoucherDetailQuery filt, CsvParser parsed) { if (filt.IsDangerous()) { throw new SecurityException("检测到弱检索式"); } var res = session.Accountant.SelectVouchersAsync(filt.VoucherQuery); var lst = new List <BankItem>(parsed.Items); await foreach (var v in res) { foreach (var d in v.Details) { if (!d.IsMatch(filt.ActualDetailFilter())) { continue; } var obj1 = lst.FirstOrDefault(b => (b.Currency == null || d.Currency == b.Currency) && (b.Fund - d.Fund !.Value).IsZero() && b.Date == v.Date); if (obj1 != null) { lst.Remove(obj1); continue; } var obj2 = lst .Where(b => (b.Currency == null || d.Currency == b.Currency) && (b.Fund - d.Fund !.Value).IsZero()) .OrderBy(b => Math.Abs((b.Date - v.Date !.Value).TotalDays)) .FirstOrDefault(); if (obj2 != null) { lst.Remove(obj2); continue; } yield return($"{v.ID.Quotation('^')} {v.Date.AsDate()} {d.Content} {d.Fund.AsCurrency(d.Currency)}\n"); } } foreach (var b in lst) { yield return($"{b.Raw}\n"); } }
private async IAsyncEnumerable <string> RunUnmark(Session session, IVoucherDetailQuery filt) { if (filt.IsDangerous()) { throw new SecurityException("检测到弱检索式"); } var cnt = 0; var cntAll = 0; var res = session.Accountant.SelectVouchersAsync(filt.VoucherQuery); var ops = new List <Voucher>(); await foreach (var v in res) { foreach (var d in v.Details) { if (!d.IsMatch(filt.ActualDetailFilter())) { continue; } cntAll++; if (d.Remark == null) { continue; } d.Remark = null; cnt++; } ops.Add(v); } await session.Accountant.UpsertAsync(ops); yield return($"{cntAll} selected\n"); yield return($"{cnt} unmarked\n"); }
private void RunUnmark(IVoucherDetailQuery filt, StringBuilder sb) { if (filt.IsDangerous()) { throw new SecurityException("检测到弱检索式"); } var cnt = 0; var cntAll = 0; var res = Accountant.SelectVouchers(filt.VoucherQuery); foreach (var v in res) { foreach (var d in v.Details) { if (!d.IsMatch(filt.DetailEmitFilter.DetailFilter)) { continue; } cntAll++; if (d.Remark == null) { continue; } d.Remark = null; cnt++; } Accountant.Upsert(v); } sb.AppendLine($"{cntAll} selected"); sb.AppendLine($"{cnt} unmarked"); }
public IEnumerable <VoucherDetail> SelectVoucherDetails(IVoucherDetailQuery query) => m_Db.SelectVoucherDetails(query);
private void RunMark(IVoucherDetailQuery filt, CsvParser parsed, string marker, StringBuilder sb) { if (filt.IsDangerous()) { throw new SecurityException("检测到弱检索式"); } var marked = 0; var remarked = 0; var converted = 0; var res = Accountant.SelectVouchers(filt.VoucherQuery).ToList(); foreach (var b in parsed.Items) { bool Trial(bool date) { var resx = date ? res.Where(v => v.Date == b.Date) : res.OrderBy(v => v.Date.HasValue ? Math.Abs((v.Date.Value - b.Date).TotalDays) : double.PositiveInfinity); var voucher = resx .FirstOrDefault(v => v.Details.Any(d // ReSharper disable once PossibleInvalidOperationException => (d.Fund.Value - b.Fund).IsZero() && d.IsMatch(filt.DetailEmitFilter.DetailFilter))); if (voucher == null) { return(false); } var o = voucher.Details.First(d // ReSharper disable once PossibleInvalidOperationException => (d.Fund.Value - b.Fund).IsZero() && d.IsMatch(filt.DetailEmitFilter.DetailFilter)); if (o.Remark == null) { marked++; } else if (o.Remark == marker) { remarked++; } else { converted++; } o.Remark = marker; Accountant.Upsert(voucher); return(true); } if (Trial(true) || Trial(false)) { continue; } sb.AppendLine(b.Raw); } sb.AppendLine($"{marked} marked"); sb.AppendLine($"{remarked} remarked"); sb.AppendLine($"{converted} converted"); }
private async IAsyncEnumerable <string> RunMark(Session session, IVoucherDetailQuery filt, CsvParser parsed, string marker) { if (filt.IsDangerous()) { throw new SecurityException("检测到弱检索式"); } var marked = 0; var remarked = 0; var converted = 0; var res = await session.Accountant.SelectVouchersAsync(filt.VoucherQuery).ToListAsync(); var ops = new List <Voucher>(); foreach (var b in parsed.Items) { bool Trial(bool date) { var resx = date ? res.Where(v => v.Date == b.Date) : res.OrderBy(v => v.Date.HasValue ? Math.Abs((v.Date.Value - b.Date).TotalDays) : double.PositiveInfinity); var voucher = resx .FirstOrDefault(v => v.Details.Any(d => (b.Currency == null || d.Currency == b.Currency) && (d.Fund !.Value - b.Fund).IsZero() && d.IsMatch(filt.ActualDetailFilter()))); if (voucher == null) { return(false); } var o = voucher.Details.First(d => (b.Currency == null || d.Currency == b.Currency) && (d.Fund !.Value - b.Fund).IsZero() && d.IsMatch(filt.ActualDetailFilter())); if (o.Remark == null) { marked++; } else if (o.Remark == marker) { remarked++; } else { converted++; } o.Remark = marker; ops.Add(voucher); return(true); } if (Trial(true) || Trial(false)) { continue; } yield return($"{b.Raw}\n"); } await session.Accountant.UpsertAsync(ops); yield return($"{marked} marked\n"); yield return($"{remarked} remarked\n"); yield return($"{converted} converted\n"); }
/// <summary> /// 是否包含弱检索式 /// </summary> /// <param name="query">记账凭证细目映射检索式</param> /// <returns>若包含则为<c>true</c>,否则为<c>false</c></returns> public static bool IsDangerous(this IVoucherDetailQuery query) => query.VoucherQuery.IsDangerous() && (query.DetailEmitFilter?.DetailFilter?.IsDangerous() ?? true);
/// <summary> /// 是否包含弱检索式 /// </summary> /// <param name="query">记账凭证细目映射检索式</param> /// <returns>若包含则为<c>true</c>,否则为<c>false</c></returns> public static bool IsDangerous(this IVoucherDetailQuery query) => query.VoucherQuery.IsDangerous() && query.ActualDetailFilter().IsDangerous();
/// <summary> /// 获取记账凭证细目映射检索式中的实际细目检索式 /// </summary> /// <param name="query">记账凭证细目映射检索式</param> /// <returns>细目检索式</returns> public static IQueryCompounded <IDetailQueryAtom> ActualDetailFilter(this IVoucherDetailQuery query) => query.DetailEmitFilter != null ? query.DetailEmitFilter.DetailFilter : query.VoucherQuery is IVoucherQueryAtom dQuery