ProcessStep.cs
2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
namespace RobotProductionSystem.Api.Domain;
public enum ProcessStep
{
Unknown = 0,
Assembly = 1,
Debug = 2,
Testing = 3,
FinalInspection = 4,
Rework = 5,
Warehousing = 6
}
public static class ProcessStepMapper
{
public static readonly ProcessStep[] SupportedSteps =
[
ProcessStep.Assembly,
ProcessStep.Debug,
ProcessStep.Testing,
ProcessStep.FinalInspection,
ProcessStep.Rework,
ProcessStep.Warehousing
];
public static bool TryParse(string? value, out ProcessStep step)
{
var text = value?.Trim();
if (string.IsNullOrWhiteSpace(text))
{
step = default;
return false;
}
var normalized = text.ToLowerInvariant();
step = normalized switch
{
"装配" or "assembly" => ProcessStep.Assembly,
"调试" or "debug" => ProcessStep.Debug,
"测试" or "test" or "testing" => ProcessStep.Testing,
"终检" or "final_inspection" or "final-inspection" or "finalinspection" => ProcessStep.FinalInspection,
"返修" or "rework" => ProcessStep.Rework,
"入库" or "warehousing" or "warehouse" => ProcessStep.Warehousing,
_ => default
};
return step != ProcessStep.Unknown;
}
public static string ToApiValue(ProcessStep step) => step switch
{
ProcessStep.Assembly => "装配",
ProcessStep.Debug => "调试",
ProcessStep.Testing => "测试",
ProcessStep.FinalInspection => "终检",
ProcessStep.Rework => "返修",
ProcessStep.Warehousing => "入库",
_ => "未知"
};
public static bool MatchesFilter(ProcessStep step, string? keyword)
{
var trimmed = keyword?.Trim();
if (string.IsNullOrWhiteSpace(trimmed))
{
return true;
}
var filter = trimmed.ToLowerInvariant();
var apiValue = ToApiValue(step).ToLowerInvariant();
var enumValue = step.ToString().ToLowerInvariant();
return apiValue.Contains(filter) || enumValue.Contains(filter);
}
}