CreditCardBillDTO.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using FluentValidation;
  2. using Microsoft.AspNetCore.Http;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace OASystem.Domain.ViewModels.Financial
  9. {
  10. /// <summary>
  11. /// 信用卡账单对账 DTO
  12. /// </summary>
  13. public class CreditCardBillDTO
  14. {
  15. ///// <summary>
  16. ///// 文件名称
  17. ///// </summary>
  18. //public IFormFile file { get; set; }
  19. /// <summary>
  20. /// 卡类型
  21. /// </summary>
  22. public int cardType { get; set; }
  23. public string beginDt { get; set; }
  24. public string endDt { get; set; }
  25. }
  26. public class CreditCardBillDTOFoaValidator : AbstractValidator<CreditCardBillDTO>
  27. {
  28. public CreditCardBillDTOFoaValidator()
  29. {
  30. //RuleFor(it => it.file)
  31. // .NotNull()
  32. // .NotEmpty()
  33. // .WithMessage("请上传文件!")
  34. // .Must(it => IsExcelFile(it.FileName))
  35. // .WithMessage("请上传Excel文件");
  36. RuleFor(it => it.cardType)
  37. .GreaterThan(0)
  38. .WithMessage("请传入有效的卡类型!");
  39. RuleFor(it => it.beginDt)
  40. .NotNull()
  41. .NotEmpty()
  42. .WithMessage("请输入开始日期!")
  43. .Must(IsValidDate)
  44. .WithMessage("请输入正确的日期格式!");
  45. RuleFor(it => it.endDt)
  46. .NotNull()
  47. .NotEmpty()
  48. .WithMessage("请输入结束日期!")
  49. .Must(IsValidDate)
  50. .WithMessage("请输入正确的日期格式!");
  51. }
  52. private bool IsValidDate(string dateString)
  53. {
  54. return DateTime.TryParse(dateString, out _);
  55. }
  56. private bool IsExcelFile(string fileName)
  57. {
  58. if (!fileName.EndsWith(".xlsx") && !fileName.EndsWith(".xls"))
  59. {
  60. return false;
  61. }
  62. return true;
  63. }
  64. }
  65. }