Example #1
0
        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);
            }
        }
Example #2
0
    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");
        }
    }
Example #3
0
    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");
    }
Example #4
0
        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");
        }
Example #5
0
        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");
        }
Example #6
0
    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");
    }