DailypaymentDto.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using FluentValidation;
  2. using Google.Protobuf;
  3. using OASystem.Domain.ViewModels;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace OASystem.Domain.Dtos.Statistics
  10. {
  11. public class DailypaymentDto
  12. {
  13. }
  14. public class DailypaymentTypeInitDto:PortDtoBase
  15. {
  16. }
  17. public class DailypaymentTypeDataSaveDto : PortDtoBase
  18. {
  19. public List<int> TypeIds { get; set; }
  20. }
  21. public class DailypaymentRangeDto : DtoBase
  22. {
  23. public string BeginDt { get; set; }
  24. public string EndDt { get; set; }
  25. /// <summary>
  26. /// 类型Data
  27. /// 1 数据 2 excel
  28. /// </summary>
  29. public int Type { get; set; }
  30. }
  31. /// <summary>
  32. /// dto验证
  33. /// </summary>
  34. public class DailypaymentRangeDtoValidator : AbstractValidator<DailypaymentRangeDto>
  35. {
  36. public DailypaymentRangeDtoValidator()
  37. {
  38. RuleFor(x => x.PortType).InclusiveBetween(from: 1, to: 3)
  39. .WithMessage(MsgTips.Port);
  40. RuleFor(x => x.PageIndex).Must(x => x > 0)
  41. .WithMessage("PageIndex不能小于1");
  42. RuleFor(x => x.PageSize).Must(x => x > 0)
  43. .WithMessage("PageSize不能小于1");
  44. RuleFor(x => x.BeginDt).NotEmpty()
  45. .WithMessage("开始查询日期不能为空!")
  46. .Must(IsDate)
  47. .WithMessage("日期格式不正确!例如:2024-07-17");
  48. RuleFor(x => x.EndDt).NotEmpty()
  49. .WithMessage("结束查询日期不能为空!")
  50. .Must(IsDate)
  51. .WithMessage("日期格式不正确!例如:2024-12-31")
  52. .Must(ConfirmDt)
  53. .WithMessage("开始日期不能大于结束日期!");
  54. RuleFor(x => x.Type).InclusiveBetween(from: 1, to: 2)
  55. .WithMessage("请输入正确的范围;1 数据View 2 excel!");
  56. }
  57. private bool IsDate(string date)
  58. {
  59. return DateTime.TryParse(date, out _);
  60. }
  61. private bool ConfirmDt(DailypaymentRangeDto dto, string endDt)
  62. {
  63. DateTime _beginDt, _endDt;
  64. if (DateTime.TryParse(dto.BeginDt, out _beginDt))
  65. {
  66. if (DateTime.TryParse(endDt, out _endDt))
  67. {
  68. if (_beginDt < _endDt)
  69. {
  70. return true;
  71. }
  72. }
  73. }
  74. return false;
  75. }
  76. }
  77. }