CertificateRepository.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System.Diagnostics.Eventing.Reader;
  2. using System.Linq.Expressions;
  3. using Furion.DataEncryption;
  4. using PTCMS.API.Domain.Entities;
  5. using PTCMS.API.Domain.Repositories;
  6. using PTCMS.API.Infrastructure.Dtos;
  7. using PTCMS.API.Infrastructure.Utils.Consts;
  8. namespace PTCMS.API.Infrastructure.Repositories
  9. {
  10. /// <summary>
  11. /// 证书信息仓储实现
  12. /// </summary>
  13. public class CertificateRepository : ICertificateRepository
  14. {
  15. private readonly IFreeSql _freeSql;
  16. /// <summary>
  17. /// 注入服务
  18. /// </summary>
  19. /// <param name="freeSql"></param>
  20. public CertificateRepository(IFreeSql freeSql)
  21. {
  22. _freeSql = freeSql;
  23. }
  24. /// <summary>
  25. /// 根据姓名+身份证号或者姓名+证书编码进行查询
  26. /// </summary>
  27. /// <param name="input"></param>
  28. /// <returns></returns>
  29. public async Task<Certificate> GetCertificateAsync(CertificateSearchDto input)
  30. {
  31. Expression<Func<Certificate, bool>> expression = null;
  32. if (!string.IsNullOrWhiteSpace(input.Name) && !string.IsNullOrWhiteSpace(input.IdNumber) && !string.IsNullOrWhiteSpace(input.CertificateNumber))
  33. {
  34. expression = expression.And(x => x.Name == input.Name && x.IdNumber == input.IdNumber && x.CertificateNumber == input.CertificateNumber);
  35. }
  36. else if (!string.IsNullOrWhiteSpace(input.Name) && !string.IsNullOrWhiteSpace(input.IdNumber))
  37. {
  38. expression = expression.And(x => x.Name == input.Name && x.IdNumber == input.IdNumber);
  39. }
  40. else if (!string.IsNullOrWhiteSpace(input.Name) && !string.IsNullOrWhiteSpace(input.CertificateNumber))
  41. {
  42. expression = expression.And(x => x.Name == input.Name && x.CertificateNumber == input.CertificateNumber);
  43. }
  44. else
  45. {
  46. throw new Exception("请输入姓名、身份证号、证书编号中的两项进行查询");
  47. }
  48. if (expression == null)
  49. {
  50. return null;
  51. }
  52. var data = await _freeSql.Select<Certificate>().Where(expression).FirstAsync();
  53. return data;
  54. }
  55. }
  56. }