DetectDto.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.ComponentModel.DataAnnotations;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using XdCxRhDW.Dto.Attribute;
  9. namespace XdCxRhDW.Dto
  10. {
  11. /// <summary>
  12. /// 检测计算模型
  13. /// </summary>
  14. public class DetectDto : IValidatableObject
  15. {
  16. /// <summary>
  17. /// 调用Upload接口上传文件后返回的文件名
  18. /// </summary>
  19. [FileMustExist]
  20. public string file1 { get; set; }
  21. /// <summary>
  22. /// 检测类型
  23. /// </summary>
  24. public DmcType dmcType { get; set; }
  25. /// <summary>
  26. /// 采样率 Hz
  27. /// </summary>
  28. [RangeDouble(0, 100e6, IncludeMin = true)]
  29. public double fsHz { get; set; }
  30. /// <summary>
  31. /// 信号带宽(KHz,只对IBS信号有效,默认25KHz)
  32. /// </summary>
  33. [RangeDouble(0, 100)]
  34. public double? band { get; set; } = 25;
  35. public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
  36. {
  37. var fields = typeof(DmcType).GetFields().Where(p => p.FieldType.IsEnum);
  38. bool hasError = true;
  39. foreach (var field in fields)
  40. {
  41. var value = field.GetValue(null);
  42. if (this.dmcType.HasFlag((Enum)value))
  43. {
  44. hasError = false;
  45. break;
  46. }
  47. }
  48. if (hasError)
  49. yield return new ValidationResult("检测类型错误", new[] { nameof(this.dmcType) });
  50. else
  51. {
  52. if (dmcType.HasFlag(DmcType.DAMA) && fsHz != 96000)
  53. {
  54. yield return new ValidationResult("DAMA检测采样率只支持96K", new[] { nameof(this.fsHz) });
  55. }
  56. if (dmcType.HasFlag(DmcType.IBS) && band != 5 && band != 25)
  57. {
  58. yield return new ValidationResult("IBS检测信号带宽只支持5K、25K两种", new[] { nameof(this.band) });
  59. }
  60. }
  61. yield return null;
  62. }
  63. }
  64. /// <summary>
  65. /// 检测类型
  66. /// </summary>
  67. [Flags]
  68. public enum DmcType
  69. {
  70. /// <summary>
  71. /// DAMA检测
  72. /// </summary>
  73. [Display(Name = "DAMA检测")]
  74. DAMA = 1,
  75. /// <summary>
  76. /// IBS检测
  77. /// </summary>
  78. [Display(Name = "IBS检测")]
  79. IBS = 2,
  80. /// <summary>
  81. /// 能量检测
  82. /// </summary>
  83. [Display(Name = "能量检测")]
  84. Ky5758 = 4
  85. }
  86. }