SfisModels.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace TeamAAS_VP.Core.Sfis
  5. {
  6. public static class SfisDelimiters
  7. {
  8. public const char Field = (char)127;
  9. }
  10. public class SfisResponse
  11. {
  12. public string Raw { get; set; }
  13. public string[] Fields { get; set; } = new string[0];
  14. public int ReturnCode { get; set; }
  15. public string Message { get; set; }
  16. public bool IsSuccess => ReturnCode == 1;
  17. public string GetField(int index)
  18. {
  19. if (Fields == null || index < 0 || index >= Fields.Length)
  20. return null;
  21. return Fields[index];
  22. }
  23. public static SfisResponse Parse(string raw)
  24. {
  25. var response = new SfisResponse { Raw = raw ?? string.Empty };
  26. if (string.IsNullOrWhiteSpace(raw))
  27. {
  28. response.ReturnCode = 0;
  29. response.Message = "SFIS 返回为空";
  30. return response;
  31. }
  32. response.Fields = raw.Split(SfisDelimiters.Field);
  33. if (response.Fields.Length > 0 && int.TryParse(response.Fields[0], out int code))
  34. response.ReturnCode = code;
  35. else
  36. response.ReturnCode = 0;
  37. response.Message = response.Fields.Length > 1 ? response.Fields[1] : raw;
  38. return response;
  39. }
  40. }
  41. public class SfisUnitContext
  42. {
  43. public string Isn { get; set; }
  44. public string ReelIdSn { get; set; }
  45. public string MoNumber { get; set; }
  46. public string PassType { get; set; }
  47. public string AoiLocTag { get; set; }
  48. public bool TestPassed { get; set; } = true;
  49. public string ErrorCode { get; set; }
  50. public IList<SfisTestRecord> TestRecords { get; set; } = new List<SfisTestRecord>();
  51. }
  52. public class SfisTestRecord
  53. {
  54. public string TestName { get; set; }
  55. public bool Passed { get; set; }
  56. public string Value { get; set; }
  57. }
  58. public class SfisWorkflowStepResult
  59. {
  60. public string StepName { get; set; }
  61. public SfisResponse Response { get; set; }
  62. }
  63. public class SfisWorkflowResult
  64. {
  65. public bool Success { get; set; }
  66. public string Isn { get; set; }
  67. public IList<SfisWorkflowStepResult> Steps { get; set; } = new List<SfisWorkflowStepResult>();
  68. public string ErrorMessage { get; set; }
  69. public SfisWorkflowStepResult GetStep(string stepName)
  70. {
  71. return Steps.FirstOrDefault(s => s.StepName == stepName);
  72. }
  73. }
  74. public class SfisInputDataPayload
  75. {
  76. public string PassType { get; set; }
  77. public string MoNumber { get; set; }
  78. public string ReelIdSn { get; set; }
  79. public string AoiLocTag { get; set; }
  80. public string Isn { get; set; }
  81. public string BuildDataString()
  82. {
  83. return string.Join(
  84. SfisDelimiters.Field.ToString(),
  85. PassType ?? string.Empty,
  86. MoNumber ?? string.Empty,
  87. ReelIdSn ?? string.Empty,
  88. AoiLocTag ?? string.Empty,
  89. Isn ?? string.Empty);
  90. }
  91. }
  92. }