• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

b1f6c1c4 / ProfessionalAccounting / 327

28 Apr 2025 05:37PM UTC coverage: 51.346% (-3.0%) from 54.325%
327

push

appveyor

b1f6c1c4
ci buildx

6620 of 12893 relevant lines covered (51.35%)

126.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/AccountingServer.Shell/Subtotal/StringSubtotalVisitor.cs
1
/* Copyright (C) 2020-2025 b1f6c1c4
2
 *
3
 * This file is part of ProfessionalAccounting.
4
 *
5
 * ProfessionalAccounting is free software: you can redistribute it and/or
6
 * modify it under the terms of the GNU Affero General Public License as
7
 * published by the Free Software Foundation, version 3.
8
 *
9
 * ProfessionalAccounting is distributed in the hope that it will be useful, but
10
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License
12
 * for more details.
13
 *
14
 * You should have received a copy of the GNU Affero General Public License
15
 * along with ProfessionalAccounting.  If not, see
16
 * <https://www.gnu.org/licenses/>.
17
 */
18

19
using System;
20
using System.Collections.Generic;
21
using System.Globalization;
22
using System.Linq;
23
using AccountingServer.BLL;
24
using AccountingServer.BLL.Util;
25
using AccountingServer.Entities;
26
using AccountingServer.Shell.Serializer;
27

28
namespace AccountingServer.Shell.Subtotal;
29

30
/// <summary>
31
///     分类汇总结果处理器
32
/// </summary>
33
internal abstract class StringSubtotalVisitor
34
    : IClientDependable, ISubtotalVisitor<IAsyncEnumerable<string>>, ISubtotalStringify
35
{
36
    protected string Cu;
37
    protected int Depth;
38

39
    protected GatheringType Ga;
40

41
    private ISubtotal m_Par;
42
    protected IEntitiesSerializer Serializer;
43

44
    public Client Client { protected get; set; }
45

46
    /// <inheritdoc />
47
    public async IAsyncEnumerable<string> PresentSubtotal(ISubtotalResult raw, ISubtotal par,
48
        IEntitiesSerializer serializer)
49
    {
×
50
        m_Par = par;
×
51
        Ga = par.GatherType;
×
52
        Cu = par.EquivalentCurrency;
×
53
        Serializer = serializer;
×
54
        Depth = 0;
×
55
        if (raw != null)
×
56
            await foreach (var s in raw.Accept(this))
×
57
                yield return s;
×
58
    }
×
59

60
    public abstract IAsyncEnumerable<string> Visit(ISubtotalRoot sub);
61
    public abstract IAsyncEnumerable<string> Visit(ISubtotalDate sub);
62
    public abstract IAsyncEnumerable<string> Visit(ISubtotalVoucherRemark sub);
63
    public abstract IAsyncEnumerable<string> Visit(ISubtotalVoucherType sub);
64
    public abstract IAsyncEnumerable<string> Visit(ISubtotalTitleKind sub);
65
    public abstract IAsyncEnumerable<string> Visit(ISubtotalUser sub);
66
    public abstract IAsyncEnumerable<string> Visit(ISubtotalCurrency sub);
67
    public abstract IAsyncEnumerable<string> Visit(ISubtotalTitle sub);
68
    public abstract IAsyncEnumerable<string> Visit(ISubtotalSubTitle sub);
69
    public abstract IAsyncEnumerable<string> Visit(ISubtotalContent sub);
70
    public abstract IAsyncEnumerable<string> Visit(ISubtotalRemark sub);
71
    public abstract IAsyncEnumerable<string> Visit(ISubtotalValue sub);
72

73
    protected async IAsyncEnumerable<string> VisitChildren(ISubtotalResult sub)
74
    {
×
75
        if (sub.Items == null)
×
76
            yield break;
×
77

78
        IEnumerable<ISubtotalResult> items;
79
        if (Depth < m_Par.Levels.Count)
×
80
        {
×
81
            var comparer = CultureInfo.GetCultureInfo("zh-CN").CompareInfo
×
82
                .GetStringComparer(CompareOptions.StringSort);
83
            items = (m_Par.Levels[Depth] & SubtotalLevel.Subtotal) switch
×
84
                {
85
                    SubtotalLevel.VoucherRemark => sub.Items.Cast<ISubtotalVoucherRemark>()
×
86
                        .OrderBy(static s => s.VoucherRemark),
×
87
                    SubtotalLevel.VoucherType => sub.Items.Cast<ISubtotalVoucherType>()
×
88
                        .OrderBy(static s => s.Type),
×
89
                    SubtotalLevel.TitleKind => sub.Items.Cast<ISubtotalTitleKind>().OrderBy(static s => s.Kind),
×
90
                    SubtotalLevel.Title => sub.Items.Cast<ISubtotalTitle>().OrderBy(static s => s.Title),
×
91
                    SubtotalLevel.SubTitle => sub.Items.Cast<ISubtotalSubTitle>().OrderBy(static s => s.SubTitle),
×
92
                    SubtotalLevel.Content => sub.Items.Cast<ISubtotalContent>()
×
93
                        .OrderBy(static s => s.Content, comparer),
×
94
                    SubtotalLevel.Remark => sub.Items.Cast<ISubtotalRemark>().OrderBy(static s => s.Remark, comparer),
×
95
                    SubtotalLevel.User => sub.Items.Cast<ISubtotalUser>()
×
96
                        .OrderBy(s => s.User == Client.User ? null : s.User),
×
97
                    SubtotalLevel.Currency => sub.Items.Cast<ISubtotalCurrency>()
×
98
                        .OrderBy(static s => s.Currency == BaseCurrency.Now ? null : s.Currency),
×
99
                    SubtotalLevel.Day => sub.Items.Cast<ISubtotalDate>().OrderBy(static s => s.Date),
×
100
                    SubtotalLevel.Week => sub.Items.Cast<ISubtotalDate>().OrderBy(static s => s.Date),
×
101
                    SubtotalLevel.Month => sub.Items.Cast<ISubtotalDate>().OrderBy(static s => s.Date),
×
102
                    SubtotalLevel.Quarter => sub.Items.Cast<ISubtotalDate>().OrderBy(static s => s.Date),
×
103
                    SubtotalLevel.Year => sub.Items.Cast<ISubtotalDate>().OrderBy(static s => s.Date),
×
104
                    SubtotalLevel.Value => sub.Items.Cast<ISubtotalValue>().OrderBy(static s => s.Value),
×
105
                    _ => throw new ArgumentOutOfRangeException(),
×
106
                };
107
        }
×
108
        else
109
            items = sub.Items;
×
110

111
        Depth++;
×
112
        foreach (var item in items)
×
113
        await foreach (var s in item.Accept(this))
×
114
            yield return s;
×
115

116
        Depth--;
×
117
    }
×
118
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc