VisaDeleClientRepository.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. using OASystem.Domain;
  2. using OASystem.Domain.Dtos;
  3. using OASystem.Domain.Dtos.CRM;
  4. using OASystem.Domain.Dtos.UserDto;
  5. using OASystem.Domain.Entities.Customer;
  6. using OASystem.Domain.Entities.Groups;
  7. using OASystem.Domain.ViewModels.CRM;
  8. using OASystem.Domain.ViewModels.Groups;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. namespace OASystem.Infrastructure.Repositories.CRM
  15. {
  16. /// <summary>
  17. /// 签证客户 仓库
  18. /// </summary>
  19. public class VisaDeleClientRepository : BaseRepository<Crm_DeleClient, VisaDeleClientView>
  20. {
  21. public VisaDeleClientRepository(SqlSugarClient sqlSugar) :
  22. base(sqlSugar)
  23. { }
  24. /// <summary>
  25. /// 签证客户list
  26. /// </summary>
  27. /// <param name="loginDto"></param>
  28. /// <returns></returns>
  29. public async Task<Result> GetCrmList(DtoBase dto)
  30. {
  31. Result result = new Result() { Code = -2 };
  32. if (dto.PortType == 1 || dto.PortType == 2)
  33. {
  34. string sql = string.Format(@"Select cdc.Id,LastName+FirstName ClientName,ccc.CompanyName,Sex,Marriage,
  35. Phone LandlinePhone,Tel,crmCard1.CertNo IDNo,crmCard2.CertNo PassportNo
  36. From Crm_DeleClient cdc
  37. Left Join Crm_CustomerCompany ccc On cdc.crmCompanyId = ccc.Id
  38. Left Join Crm_CustomerCert crmCard1 On crmCard1.SdId = 773 And cdc.Id = crmCard1.DcId
  39. Left Join Crm_CustomerCert crmCard2 On crmCard2.SdId = 774 And cdc.Id = crmCard2.DcId ");
  40. var clientList = await _sqlSugar.SqlQueryable<VisaDeleClientListView>(sql).ToListAsync();
  41. if (clientList.Count > 0)
  42. {
  43. result.Code = 0;
  44. result.Msg = "成功!";
  45. result.Data = clientList;
  46. }
  47. else
  48. {
  49. result.Msg = "暂无数据!";
  50. }
  51. }
  52. return result;
  53. }
  54. /// <summary>
  55. /// 签证客户操作
  56. /// </summary>
  57. /// <param name="loginDto"></param>
  58. /// <returns></returns>
  59. public async Task<Result> CrmClinetoperation(LoginDto loginDto)
  60. {
  61. Result result = new Result() { Code = -2 };
  62. return result;
  63. }
  64. /// <summary>
  65. /// 签证客户 新增
  66. /// </summary>
  67. /// <param name="loginDto"></param>
  68. /// <returns></returns>
  69. public async Task<int> CrmClinetAdd(Crm_DeleClient client)
  70. {
  71. int addId = -1;
  72. return addId;
  73. }
  74. /// <summary>
  75. /// 根据身份证识别修改ocr添加
  76. /// </summary>
  77. /// <param name="client"></param>
  78. /// <returns></returns>
  79. public async Task<bool> SetCrmUpdPassIdCardOCR(SetCrmUpdPassIdCardOCRDto client)
  80. {
  81. string clientSql = string.Format(@"Select * From Crm_DeleClient Where LastName+FirstName='{0}' And Sex = {1}",
  82. client.ClientName, client.Sex);
  83. var clientInfo = await _sqlSugar.SqlQueryable<VisaDeleClientListView>(clientSql).FirstAsync();
  84. if(clientInfo == null) return false;
  85. string cardSql = string.Format(@"Select * From Crm_CustomerCert Where SdId=773 And DcId={0}", clientInfo.Id);
  86. var cardInfo = await _sqlSugar.SqlQueryable<CustomerCertView>(cardSql).FirstAsync();
  87. if (cardInfo == null) //添加
  88. {
  89. int cerdAdd = await _sqlSugar.Insertable<Crm_CustomerCert>(new Crm_CustomerCert
  90. {
  91. DcId = clientInfo.Id,
  92. SdId = "773",
  93. Country = "中国",
  94. CertNo = client.CerdNo,
  95. TargetCountry = "",
  96. IssueDt = new DateTime(1990, 1, 1),
  97. ExpiryDt = "1990-01-01 00:00:00.000",
  98. CreateUserId = client.UserId,
  99. CreateTime = DateTime.Now,
  100. DeleteUserId = null,
  101. DeleteTime = "1990-01-01 00:00:00.000",
  102. Remark = "",
  103. IsDel = 0
  104. }).ExecuteReturnIdentityAsync();
  105. if (cerdAdd > 0) return true;
  106. }
  107. else //修改
  108. {
  109. var cerdStatus = await _sqlSugar.Updateable<Crm_CustomerCert>()
  110. .Where(c => c.Id == cardInfo.Id)
  111. .SetColumns(c => new Crm_CustomerCert
  112. {
  113. CertNo = cardInfo.CertNo,
  114. IDCardAddress = cardInfo.IDCardAddress
  115. }).ExecuteCommandAsync();
  116. if (cerdStatus > 0) return true;
  117. }
  118. return false;
  119. }
  120. }
  121. }