< Summary

Information
Class: Services.AiAssistant.BitrixStockSyncUiMapper
Assembly: Services
File(s): /home/runner/work/Studio2Prod/Studio2Prod/AppRepository/AiAssistant/BitrixStockSyncUiMapper.cs
Line coverage
100%
Covered lines: 80
Uncovered lines: 0
Coverable lines: 80
Total lines: 119
Line coverage: 100%
Branch coverage
98%
Covered branches: 55
Total branches: 56
Branch coverage: 98.2%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Map(...)100%1212100%
MapRow(...)100%2424100%
MapIndex(...)100%44100%
ApplyTone(...)100%66100%
ToneFromCss(...)83.33%66100%
ShortId(...)100%44100%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/AppRepository/AiAssistant/BitrixStockSyncUiMapper.cs

#LineLine coverage
 1using Services.BitrixStockServices;
 2
 3namespace Services.AiAssistant;
 4
 5public static class BitrixStockSyncUiMapper
 6{
 7    public static AiBitrixSyncUiDto? Map(BitrixStockArticleHistoryPageDto? page)
 8    {
 809        if (page == null || string.IsNullOrWhiteSpace(page.Article) || page.Reports.Count == 0)
 1910            return null;
 11
 6112        return new AiBitrixSyncUiDto
 6113        {
 6114            Article          = page.Article!,
 6115            TotalReportCount = page.TotalReportCount,
 6216            Reports = page.Reports.Select(r => new AiBitrixSyncReportUiDto
 6217            {
 6218                ReportIdShort  = ShortId(r.ReportId),
 6219                GeneratedAtMsk = BitrixStockMskDateTime.Format(r.GeneratedAtUtc),
 6220                ClientName     = r.IsMultiClient
 6221                    ? string.Join(", ", r.MultiClientNames.Values.DefaultIfEmpty(r.OzonClientName).Distinct())
 6222                    : r.OzonClientName ?? "",
 6523                Rows = r.Rows.Select(row => MapRow(row, page.HasPrices, page.HasPushes)).ToList()
 6224            }).ToList()
 6125        };
 26    }
 27
 28    private static AiBitrixSyncRowUiDto MapRow(
 29        BitrixStockArticleHistoryRowDto row,
 30        bool hasPrices,
 31        bool hasPushes)
 32    {
 6533        var w  = row.Line;
 6534        var pi = row.Price;
 6535        BitrixStockSyncReportRowPresenter.FormatDeltaItog(w, out var deltaCss);
 36
 6537        var ui = new AiBitrixSyncRowUiDto
 6538        {
 6539            OneCStore     = w.OneCStore ?? string.Empty,
 6540            OzonWarehouse = w.OzonWarehouseName ?? string.Empty,
 6541            OneCQty       = w.OneCQty,
 6542            OzonQty       = w.OzonQty,
 6543            TargetQty     = BitrixStockSyncReportRowPresenter.GetTargetQty(w),
 6544            OzonQtyAfter  = w.OzonQtyAfter,
 6545            DeltaItog     = BitrixStockSyncReportRowPresenter.FormatDeltaItog(w, out _),
 6546            DeltaItogTone = ToneFromCss(deltaCss),
 6547            ActionLabel   = w.ActionLabel ?? string.Empty,
 6548            ActionIcon    = w.ActionIcon ?? string.Empty,
 6549            ApplyStatus   = BitrixStockSyncReportRowPresenter.FormatOzonApplyStatus(w),
 6550            ApplyTone     = ApplyTone(w),
 6551            OneCPrice     = w.OneCPrice,
 6552            DeltaC0       = BitrixStockSyncReportRowPresenter.FormatDeltaC0(w.OneCPrice, w.PrevOneCPrice),
 6553            DeltaC0Tone   = ToneFromCss(
 6554                BitrixStockSyncReportRowPresenter.DeltaC0CssClass(w.OneCPrice, w.PrevOneCPrice))
 6555        };
 56
 6557        if (hasPrices && pi != null)
 58        {
 1259            ui.OzonPrice    = pi.TruePrice;
 1260            ui.SellingPrice = pi.SellingPrice;
 1261            ui.PriceIndex   = MapIndex(pi.ColorIndex);
 62        }
 63
 6564        if (hasPushes && pi != null &&
 6565            (pi.PricePushedNew.HasValue || pi.PricePushedOld.HasValue || !string.IsNullOrEmpty(pi.PricePushStatus)))
 66        {
 667            ui.PricePush = new AiPricePushUiDto
 668            {
 669                OldPrice    = pi.PricePushedOld,
 670                NewPrice    = pi.PricePushedNew,
 671                Status      = pi.PricePushStatus,
 672                Tone        = ToneFromCss(BitrixStockSyncReportRowPresenter.PushedNewCssClass(pi)),
 673                IndexBefore = MapIndex(pi.PushedColorIndexBefore),
 674                IndexAfter  = MapIndex(pi.PushedColorIndexAfter),
 675                MarkupPct   = pi.PushedMarkupPct,
 676                PushedAtMsk = pi.PricePushedAtUtc.HasValue
 677                    ? BitrixStockMskDateTime.Format(pi.PricePushedAtUtc.Value)
 678                    : null
 679            };
 80        }
 81
 6582        return ui;
 83    }
 84
 85    private static AiPriceIndexUiDto? MapIndex(string? colorIndex)
 86    {
 3687        if (string.IsNullOrWhiteSpace(colorIndex)) return null;
 1288        if (!BitrixStockSyncReportRowPresenter.IndexStyles.TryGetValue(colorIndex, out var s))
 289            return null;
 90
 1091        return new AiPriceIndexUiDto
 1092        {
 1093            Key   = colorIndex,
 1094            Label = s.Label,
 1095            Bg    = s.BgHex,
 1096            Fg    = s.FgHex
 1097        };
 98    }
 99
 100    private static string ApplyTone(BitrixStockSyncReportWarehouseLineDto w) =>
 65101        w.OzonApplyStatus switch
 65102        {
 58103            "Success" => "success",
 3104            "Failed"  => "danger",
 1105            "Pending" => "warn",
 3106            _         => "muted"
 65107        };
 108
 109    private static string ToneFromCss(string css)
 110    {
 141111        if (css.Contains("text-success", StringComparison.Ordinal)) return "success";
 134112        if (css.Contains("text-danger", StringComparison.Ordinal)) return "danger";
 128113        if (css.Contains("text-warning", StringComparison.Ordinal)) return "warn";
 128114        return "muted";
 115    }
 116
 117    private static string ShortId(string? id) =>
 62118        string.IsNullOrEmpty(id) ? "" : id.Length > 8 ? id[..8] : id;
 119}