Add 40 sleeves and couplings support
This commit is contained in:
parent
38011f165e
commit
c8a5824add
@ -42,7 +42,7 @@ public class CouplingsCalculator : IFittingsCalculator
|
|||||||
"20" => new Product("11080121001"),
|
"20" => new Product("11080121001"),
|
||||||
"25" => new Product("11080131001"),
|
"25" => new Product("11080131001"),
|
||||||
"32" => new Product("11080141001"),
|
"32" => new Product("11080141001"),
|
||||||
"40" => new Product("11600151001"),
|
"40" => new Product("11080151001"),
|
||||||
"50" => new Product("14563021001"),
|
"50" => new Product("14563021001"),
|
||||||
"63" => new Product("14563031001"),
|
"63" => new Product("14563031001"),
|
||||||
_ => throw new Exception($"Неизвестный диаметр {kvp.Key}")
|
_ => throw new Exception($"Неизвестный диаметр {kvp.Key}")
|
||||||
|
@ -4,82 +4,84 @@ namespace RhSolutions.Services;
|
|||||||
|
|
||||||
public class SleevesCalculator : IFittingsCalculator
|
public class SleevesCalculator : IFittingsCalculator
|
||||||
{
|
{
|
||||||
private const string doublePattern =
|
private const string doublePattern =
|
||||||
@"((?i)равнопроходная|угольник\s+90|угольник\s+45|Т-образная|Комплект\s+трубок(?i))(.+?\b(?<Sleeve>16|20|25|32|40|50|63)\b)+";
|
@"((?i)равнопроходная|угольник\s+90|угольник\s+45|Т-образная|Комплект\s+трубок(?i))(.+?\b(?<Sleeve>16|20|25|32|40|50|63)\b)+";
|
||||||
private const string singlePattern =
|
private const string singlePattern =
|
||||||
@"((?i)муфта|тройник|переходник|угольник|штуцер|Г-образная|заглушка(?i))(.+?\b(?<Sleeve>16|20|25|32|40|50|63)\b)+";
|
@"((?i)муфта|тройник|переходник|угольник|штуцер|Г-образная|заглушка(?i))(.+?\b(?<Sleeve>16|20|25|32|40|50|63)\b)+";
|
||||||
|
|
||||||
public Dictionary<Product, double> Calculate(Dictionary<Product, double> products)
|
public Dictionary<Product, double> Calculate(Dictionary<Product, double> products)
|
||||||
{
|
{
|
||||||
Dictionary<string, double> result = new()
|
Dictionary<string, double> result = new()
|
||||||
{
|
{
|
||||||
["16"] = 0,
|
["16"] = 0,
|
||||||
["20"] = 0,
|
["20"] = 0,
|
||||||
["25"] = 0,
|
["25"] = 0,
|
||||||
["32"] = 0,
|
["32"] = 0,
|
||||||
["16PX"] = 0,
|
["40"] = 0,
|
||||||
["20PX"] = 0,
|
["50"] = 0,
|
||||||
["25PX"] = 0,
|
["63"] = 0,
|
||||||
["32PX"] = 0,
|
["16PX"] = 0,
|
||||||
["40"] = 0,
|
["20PX"] = 0,
|
||||||
["50"] = 0,
|
["25PX"] = 0,
|
||||||
["63"] = 0,
|
["32PX"] = 0,
|
||||||
};
|
["40PX"] = 0
|
||||||
var rautitanProducts = products.Where(kvp => kvp.Key.ProductLines.Contains("RAUTITAN"));
|
};
|
||||||
|
var rautitanProducts = products.Where(kvp => kvp.Key.ProductLines.Contains("RAUTITAN"));
|
||||||
|
|
||||||
foreach (var kvp in rautitanProducts)
|
foreach (var kvp in rautitanProducts)
|
||||||
{
|
{
|
||||||
var doubleCollection = Regex.Matches(kvp.Key.Name, doublePattern);
|
var doubleCollection = Regex.Matches(kvp.Key.Name, doublePattern);
|
||||||
if (doubleCollection.Count != 0)
|
if (doubleCollection.Count != 0)
|
||||||
{
|
{
|
||||||
CaptureCollection collection = doubleCollection[0].Groups["Sleeve"].Captures;
|
CaptureCollection collection = doubleCollection[0].Groups["Sleeve"].Captures;
|
||||||
foreach (Capture sleeve in collection)
|
foreach (Capture sleeve in collection)
|
||||||
{
|
{
|
||||||
if (kvp.Key.Name.Contains("PX") && sleeve.Value != "40")
|
if (kvp.Key.Name.Contains("PX"))
|
||||||
{
|
{
|
||||||
result[$"{sleeve.Value}PX"] += kvp.Value * 2;
|
result[$"{sleeve.Value}PX"] += kvp.Value * 2;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result[sleeve.Value] += kvp.Value * 2;
|
result[sleeve.Value] += kvp.Value * 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var singleCollection = Regex.Matches(kvp.Key.Name, singlePattern);
|
var singleCollection = Regex.Matches(kvp.Key.Name, singlePattern);
|
||||||
if (singleCollection.Count != 0)
|
if (singleCollection.Count != 0)
|
||||||
{
|
{
|
||||||
CaptureCollection collection = singleCollection[0].Groups["Sleeve"].Captures;
|
CaptureCollection collection = singleCollection[0].Groups["Sleeve"].Captures;
|
||||||
foreach (Capture sleeve in collection)
|
foreach (Capture sleeve in collection)
|
||||||
{
|
{
|
||||||
if (kvp.Key.Name.Contains("PX") && sleeve.Value != "40")
|
if (kvp.Key.Name.Contains("PX"))
|
||||||
{
|
{
|
||||||
result[$"{sleeve.Value}PX"] += kvp.Value;
|
result[$"{sleeve.Value}PX"] += kvp.Value;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result[sleeve.Value] += kvp.Value;
|
result[sleeve.Value] += kvp.Value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
.ToDictionary(kvp =>
|
.ToDictionary(kvp =>
|
||||||
kvp.Key switch
|
kvp.Key switch
|
||||||
{
|
{
|
||||||
"16" => new Product("11080011001"),
|
"16" => new Product("11080011001"),
|
||||||
"20" => new Product("11080021001"),
|
"20" => new Product("11080021001"),
|
||||||
"25" => new Product("11080031001"),
|
"25" => new Product("11080031001"),
|
||||||
"32" => new Product("11080041001"),
|
"32" => new Product("11080041001"),
|
||||||
"16PX" => new Product("11600011001"),
|
"40" => new Product("11080051001"),
|
||||||
"20PX" => new Product("11600021001"),
|
"50" => new Product("11397713002"),
|
||||||
"25PX" => new Product("11600031001"),
|
"63" => new Product("11397813002"),
|
||||||
"32PX" => new Product("11600041001"),
|
"16PX" => new Product("11600011001"),
|
||||||
"40" => new Product("11600051001"),
|
"20PX" => new Product("11600021001"),
|
||||||
"50" => new Product("11397713002"),
|
"25PX" => new Product("11600031001"),
|
||||||
"63" => new Product("11397813002"),
|
"32PX" => new Product("11600041001"),
|
||||||
_ => throw new Exception($"Неизвестный диаметр {kvp.Key}")
|
"40PX" => new Product("11600051001"),
|
||||||
}, kvp => kvp.Value);
|
_ => throw new Exception($"Неизвестный диаметр {kvp.Key}")
|
||||||
}
|
}, kvp => kvp.Value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,38 +5,37 @@ namespace RhSolutions.Tests;
|
|||||||
[ExcelTestSettings(OutOfProcess = true)]
|
[ExcelTestSettings(OutOfProcess = true)]
|
||||||
public class CanFillCouplings : IDisposable
|
public class CanFillCouplings : IDisposable
|
||||||
{
|
{
|
||||||
private RhSolutionsAddIn _addIn;
|
private RhSolutionsAddIn _addIn;
|
||||||
private IFittingsCalculator _calculator;
|
private IFittingsCalculator _calculator;
|
||||||
private IReader _reader;
|
private IReader _reader;
|
||||||
private IWriter _writer;
|
private IWriter _writer;
|
||||||
private Worksheet _worksheet;
|
private Worksheet _worksheet;
|
||||||
|
|
||||||
public CanFillCouplings()
|
public CanFillCouplings()
|
||||||
{
|
{
|
||||||
Environment.SetEnvironmentVariable("ISTESTING", "true");
|
Environment.SetEnvironmentVariable("ISTESTING", "true");
|
||||||
_addIn = new();
|
_addIn = new();
|
||||||
_addIn.AutoOpen();
|
_addIn.AutoOpen();
|
||||||
_calculator = new CouplingsCalculator();
|
_calculator = new CouplingsCalculator();
|
||||||
_reader = new ExcelReader(Util.Application, RhSolutionsAddIn.Configuration);
|
_reader = new ExcelReader(Util.Application, RhSolutionsAddIn.Configuration);
|
||||||
_writer = new CurrentPriceWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
_writer = new CurrentPriceWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
||||||
_worksheet = Util.Workbook.Worksheets[1];
|
_worksheet = Util.Workbook.Worksheets[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
[ExcelFact(Workbook = @"..\..\..\TestWorkbooks\TestSpecificationCouplings.xlsx")]
|
[ExcelFact(Workbook = @"..\..\..\TestWorkbooks\TestSpecificationCouplings.xlsx")]
|
||||||
public void CanCalculateSleeves()
|
public void CanCalculateSleeves()
|
||||||
{
|
{
|
||||||
var products = _reader.ReadProducts(new[] { _worksheet });
|
var products = _reader.ReadProducts(new[] { _worksheet });
|
||||||
var couplings = _calculator.Calculate(products.First().Item2);
|
var couplings = _calculator.Calculate(products.First().Item2);
|
||||||
_writer.WriteProducts(couplings);
|
_writer.WriteProducts(couplings);
|
||||||
|
for (int i = 2; i < 14; i++)
|
||||||
|
{
|
||||||
|
Assert.Equal(_worksheet.Range[$"F{i}"].Value, _worksheet.Range[$"E{i}"].Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Assert.Equal(7, _worksheet.Range["E2"].Value);
|
public void Dispose()
|
||||||
Assert.Equal(1, _worksheet.Range["E3"].Value);
|
{
|
||||||
Assert.Equal(1, _worksheet.Range["E5"].Value);
|
_addIn.AutoClose();
|
||||||
Assert.Equal(1, _worksheet.Range["E7"].Value);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
_addIn.AutoClose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -28,18 +28,10 @@ public class CanFillSleeves : IDisposable
|
|||||||
var products = _reader.ReadProducts(new[] { _worksheet });
|
var products = _reader.ReadProducts(new[] { _worksheet });
|
||||||
var sleeves = _calculator.Calculate(products.First().Item2);
|
var sleeves = _calculator.Calculate(products.First().Item2);
|
||||||
_writer.WriteProducts(sleeves);
|
_writer.WriteProducts(sleeves);
|
||||||
|
for (int i = 2; i < 14; i++)
|
||||||
Assert.Equal(22, _worksheet.Range["E2"].Value);
|
{
|
||||||
Assert.Equal(12, _worksheet.Range["E3"].Value);
|
Assert.Equal(_worksheet.Range[$"F{i}"].Value, _worksheet.Range[$"E{i}"].Value);
|
||||||
Assert.Equal(5, _worksheet.Range["E4"].Value);
|
}
|
||||||
Assert.Equal(6, _worksheet.Range["E5"].Value);
|
|
||||||
Assert.Equal(3, _worksheet.Range["E6"].Value);
|
|
||||||
Assert.Equal(3, _worksheet.Range["E7"].Value);
|
|
||||||
Assert.Equal(2, _worksheet.Range["E8"].Value);
|
|
||||||
Assert.Equal(2, _worksheet.Range["E9"].Value);
|
|
||||||
Assert.Equal(1, _worksheet.Range["E10"].Value);
|
|
||||||
Assert.Equal(3, _worksheet.Range["E11"].Value);
|
|
||||||
Assert.Equal(4, _worksheet.Range["E12"].Value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user