DetectDto.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 EnumSigCheckTypeDto 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. /// <summary>
  36. ///
  37. /// </summary>
  38. /// <param name="validationContext"></param>
  39. /// <returns></returns>
  40. public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
  41. {
  42. var fields = typeof(EnumSigCheckTypeDto).GetFields().Where(p => p.FieldType.IsEnum);
  43. bool hasError = true;
  44. foreach (var field in fields)
  45. {
  46. var value = field.GetValue(null);
  47. if (this.dmcType.HasFlag((Enum)value))
  48. {
  49. hasError = false;
  50. break;
  51. }
  52. }
  53. if (hasError)
  54. yield return new ValidationResult("检测类型错误", new[] { nameof(this.dmcType) });
  55. else
  56. {
  57. if (dmcType.HasFlag(EnumSigCheckTypeDto.Normal))
  58. {
  59. yield return new ValidationResult("常规信号不需要检测", new[] { nameof(this.dmcType) });
  60. }
  61. if (dmcType.HasFlag(EnumSigCheckTypeDto.DAMA) && fsHz != 96000)
  62. {
  63. yield return new ValidationResult("DAMA检测采样率只支持96K", new[] { nameof(this.fsHz) });
  64. }
  65. if (dmcType.HasFlag(EnumSigCheckTypeDto.IBS) && band != 5 && band != 25)
  66. {
  67. yield return new ValidationResult("IBS检测信号带宽只支持5K、25K两种", new[] { nameof(this.band) });
  68. }
  69. }
  70. yield return null;
  71. }
  72. }
  73. }