summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--RhSolutions.Api/Services/FlexPipeQueryModifier.cs76
-rw-r--r--RhSolutions.Api/Services/ProductQueryModifierFactory.cs28
-rw-r--r--RhSolutions.Api/Services/StabilPipeQueryModifier.cs16
3 files changed, 108 insertions, 12 deletions
diff --git a/RhSolutions.Api/Services/FlexPipeQueryModifier.cs b/RhSolutions.Api/Services/FlexPipeQueryModifier.cs
new file mode 100644
index 0000000..ef5253f
--- /dev/null
+++ b/RhSolutions.Api/Services/FlexPipeQueryModifier.cs
@@ -0,0 +1,76 @@
+using System.Text;
+using System.Text.RegularExpressions;
+using Microsoft.AspNetCore.Http.Extensions;
+
+namespace RhSolutions.Api.Services
+{
+ public class FlexPipeQueryModifier : IProductQueryModifier
+ {
+ protected virtual string diameterPattern { get; } = @"16|20|25|32|40|50|63";
+ protected virtual string typePattern { get; } = @"(бухт)|(отр)";
+ protected virtual string pipeName { get; } = "Flex";
+ protected virtual Dictionary<string, string> diameterNames { get; } = new()
+ {
+ ["16"] = "16x2,2",
+ ["20"] = "20x2,8",
+ ["25"] = "25x3,5",
+ ["32"] = "32x4,4",
+ ["40"] = "40x5,5",
+ ["50"] = "50x6,9",
+ ["63"] = "63x8,6"
+ };
+
+ public bool TryQueryModify(IQueryCollection collection, out QueryString queryString)
+ {
+ queryString = QueryString.Empty;
+ StringBuilder sb = new();
+
+ string query = collection["query"].ToString();
+ if (string.IsNullOrEmpty(query))
+ {
+ return false;
+ }
+
+ sb.Append($"Труба {pipeName} ");
+ var diameterMatches = Regex.Matches(query, diameterPattern);
+ string diameter;
+ if (diameterMatches.Count > 0)
+ {
+ diameter = diameterMatches.First().Value;
+ sb.Append($"{diameterNames[diameter]} " );
+ }
+ else
+ {
+ return false;
+ }
+ var typeMatches = Regex.Matches(query, typePattern);
+ if (typeMatches.Count > 0)
+ {
+ var type = typeMatches.First().Value;
+ if (type.StartsWith("бухт"))
+ {
+ sb.Append("бухта");
+ }
+ else
+ {
+ sb.Append("прям.отрезки");
+ }
+ }
+ else if (int.Parse(diameter) < 32)
+ {
+ sb.Append("бухта");
+ }
+ else
+ {
+ sb.Append("прям.отрезки");
+ }
+
+ QueryBuilder qb = new()
+ {
+ { "query", sb.ToString() }
+ };
+ queryString = qb.ToQueryString();
+ return true;
+ }
+ }
+}
diff --git a/RhSolutions.Api/Services/ProductQueryModifierFactory.cs b/RhSolutions.Api/Services/ProductQueryModifierFactory.cs
index a62a0c3..46c035b 100644
--- a/RhSolutions.Api/Services/ProductQueryModifierFactory.cs
+++ b/RhSolutions.Api/Services/ProductQueryModifierFactory.cs
@@ -2,16 +2,20 @@
public class ProductQueryModifierFactory
{
- public IProductQueryModifier GetModifier(string productTypeName)
- {
- switch (productTypeName)
- {
- case "Монтажная гильза":
- return new SleeveQueryModifier();
- case "Тройник RAUTITAN":
- return new TPieceQueryModifier();
- default:
- return new BypassQueryModifier();
- }
- }
+ public IProductQueryModifier GetModifier(string productTypeName)
+ {
+ switch (productTypeName)
+ {
+ case "Монтажная гильза":
+ return new SleeveQueryModifier();
+ case "Тройник RAUTITAN":
+ return new TPieceQueryModifier();
+ case "Flex":
+ return new FlexPipeQueryModifier();
+ case "Stabil":
+ return new StabilPipeQueryModifier();
+ default:
+ return new BypassQueryModifier();
+ }
+ }
}
diff --git a/RhSolutions.Api/Services/StabilPipeQueryModifier.cs b/RhSolutions.Api/Services/StabilPipeQueryModifier.cs
new file mode 100644
index 0000000..035b914
--- /dev/null
+++ b/RhSolutions.Api/Services/StabilPipeQueryModifier.cs
@@ -0,0 +1,16 @@
+namespace RhSolutions.Api.Services
+{
+ public class StabilPipeQueryModifier : FlexPipeQueryModifier
+ {
+ protected override string diameterPattern => @"16|20|25|32|40";
+ protected override string pipeName => "Stabil -PLATINUM";
+ protected override Dictionary<string, string> diameterNames => new()
+ {
+ ["16"] = "16,2х2,6",
+ ["20"] = "20х2,9",
+ ["25"] = "25х3,7",
+ ["32"] = "32х4,7",
+ ["40"] = "40х6,0"
+ };
+ }
+}