2023-06-21 06:33:12 +03:00
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
|
|
|
|
namespace RhSolutions.Services;
|
2023-06-20 11:50:11 +03:00
|
|
|
|
|
2023-11-02 23:07:06 +03:00
|
|
|
|
public class SleevesCalculator : IFittingsCalculator
|
2023-06-20 11:50:11 +03:00
|
|
|
|
{
|
2024-10-31 23:31:14 +03:00
|
|
|
|
private const string doublePattern =
|
|
|
|
|
@"((?i)равнопроходная|угольник\s+90|угольник\s+45|Т-образная|Комплект\s+трубок(?i))(.+?\b(?<Sleeve>16|20|25|32|40|50|63)\b)+";
|
|
|
|
|
private const string singlePattern =
|
|
|
|
|
@"((?i)муфта|тройник|переходник|угольник|штуцер|Г-образная|заглушка(?i))(.+?\b(?<Sleeve>16|20|25|32|40|50|63)\b)+";
|
2023-06-21 06:33:12 +03:00
|
|
|
|
|
2024-10-31 23:31:14 +03:00
|
|
|
|
public Dictionary<Product, double> Calculate(Dictionary<Product, double> products)
|
|
|
|
|
{
|
|
|
|
|
Dictionary<string, double> result = new()
|
|
|
|
|
{
|
|
|
|
|
["16"] = 0,
|
|
|
|
|
["20"] = 0,
|
|
|
|
|
["25"] = 0,
|
|
|
|
|
["32"] = 0,
|
|
|
|
|
["40"] = 0,
|
|
|
|
|
["50"] = 0,
|
|
|
|
|
["63"] = 0,
|
|
|
|
|
["16PX"] = 0,
|
|
|
|
|
["20PX"] = 0,
|
|
|
|
|
["25PX"] = 0,
|
|
|
|
|
["32PX"] = 0,
|
|
|
|
|
["40PX"] = 0
|
|
|
|
|
};
|
|
|
|
|
var rautitanProducts = products.Where(kvp => kvp.Key.ProductLines.Contains("RAUTITAN"));
|
2023-06-21 06:33:12 +03:00
|
|
|
|
|
2024-10-31 23:31:14 +03:00
|
|
|
|
foreach (var kvp in rautitanProducts)
|
|
|
|
|
{
|
|
|
|
|
var doubleCollection = Regex.Matches(kvp.Key.Name, doublePattern);
|
|
|
|
|
if (doubleCollection.Count != 0)
|
|
|
|
|
{
|
|
|
|
|
CaptureCollection collection = doubleCollection[0].Groups["Sleeve"].Captures;
|
|
|
|
|
foreach (Capture sleeve in collection)
|
|
|
|
|
{
|
|
|
|
|
if (kvp.Key.Name.Contains("PX"))
|
|
|
|
|
{
|
|
|
|
|
result[$"{sleeve.Value}PX"] += kvp.Value * 2;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result[sleeve.Value] += kvp.Value * 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
var singleCollection = Regex.Matches(kvp.Key.Name, singlePattern);
|
|
|
|
|
if (singleCollection.Count != 0)
|
|
|
|
|
{
|
|
|
|
|
CaptureCollection collection = singleCollection[0].Groups["Sleeve"].Captures;
|
|
|
|
|
foreach (Capture sleeve in collection)
|
|
|
|
|
{
|
|
|
|
|
if (kvp.Key.Name.Contains("PX"))
|
|
|
|
|
{
|
|
|
|
|
result[$"{sleeve.Value}PX"] += kvp.Value;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result[sleeve.Value] += kvp.Value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-06-21 06:33:12 +03:00
|
|
|
|
|
2024-10-31 23:31:14 +03:00
|
|
|
|
return result
|
|
|
|
|
.ToDictionary(kvp =>
|
|
|
|
|
kvp.Key switch
|
|
|
|
|
{
|
|
|
|
|
"16" => new Product("11080011001"),
|
|
|
|
|
"20" => new Product("11080021001"),
|
|
|
|
|
"25" => new Product("11080031001"),
|
|
|
|
|
"32" => new Product("11080041001"),
|
|
|
|
|
"40" => new Product("11080051001"),
|
|
|
|
|
"50" => new Product("11397713002"),
|
|
|
|
|
"63" => new Product("11397813002"),
|
|
|
|
|
"16PX" => new Product("11600011001"),
|
|
|
|
|
"20PX" => new Product("11600021001"),
|
|
|
|
|
"25PX" => new Product("11600031001"),
|
|
|
|
|
"32PX" => new Product("11600041001"),
|
|
|
|
|
"40PX" => new Product("11600051001"),
|
|
|
|
|
_ => throw new Exception($"Неизвестный диаметр {kvp.Key}")
|
|
|
|
|
}, kvp => kvp.Value);
|
|
|
|
|
}
|
2023-06-20 11:50:11 +03:00
|
|
|
|
}
|