WXBindRepository.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using Dapper;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using XYY.Core.Standard.Data.Infrastructure;
  8. namespace XYY.Data.Standard.WX
  9. {
  10. public interface IWXBindRepository
  11. {
  12. Task<IEnumerable<WXUserInfo>> GetWXUserId(int[] xyyUserId);
  13. Task<IEnumerable<WXCustomerInfo>> GetCustomerWXUserId(int[] CustomerId);
  14. }
  15. public class WXCustomerInfo
  16. {
  17. public string NickName
  18. {
  19. get; set;
  20. }
  21. public int UserId
  22. {
  23. get; set;
  24. }
  25. public string WXUserId
  26. {
  27. get; set;
  28. }
  29. }
  30. public class WXUserInfo
  31. {
  32. public string NickName
  33. {
  34. get; set;
  35. }
  36. public int UserId
  37. {
  38. get; set;
  39. }
  40. public string WXUserId
  41. {
  42. get; set;
  43. }
  44. }
  45. public class WXBindRepository : IWXBindRepository
  46. {
  47. public IUnitOfWork _unitOfWork;
  48. public WXBindRepository(IUnitOfWork unitOfWork)
  49. {
  50. _unitOfWork = unitOfWork;
  51. }
  52. public async Task<IEnumerable<WXCustomerInfo>> GetCustomerWXUserId(int[] CustomerId)
  53. {
  54. string sql = @"select a.Id as UserId , isnull( a.Abbreviation, a.CompanyName),b.WXUserId from user_customer(nolock)a left join QWCustomer_Info(nolock)b
  55. on a.id=b.CustomerId
  56. where a.Id in @CustomerId";
  57. var data = await _unitOfWork.QueryBySqlAsync<WXCustomerInfo>(sql, null, new { CustomerId });
  58. if (CustomerId.Count() != data.Count())
  59. {
  60. throw new Exception("客户信息不一致,请核实传入客户ID无误");
  61. }
  62. else
  63. {
  64. string noUsers = string.Join(",", data.Where(x => x.WXUserId == null).Select(x => x.NickName));
  65. if (!string.IsNullOrEmpty(noUsers))
  66. {
  67. throw new Exception($"以下用户未同步微信客户信息,请联系客服/行政人员:{noUsers}");
  68. }
  69. }
  70. return data;
  71. }
  72. public async Task<IEnumerable<WXUserInfo>> GetWXUserId(int[] xyyUserId)
  73. {
  74. string sql = @"select a.Id as UserId ,a.NickName,b.WXUserId from User_Info(nolock)a left join QWUser_Info(nolock)b
  75. on a.id=b.UserId where a.Id in @xyyUserId";
  76. var data = await _unitOfWork.QueryBySqlAsync<WXUserInfo>(sql, null, new { xyyUserId });
  77. if (xyyUserId.Count() != data.Count())
  78. {
  79. throw new Exception("用户信息不一致,请核实传入用户ID无误");
  80. }
  81. else
  82. {
  83. string noUsers = string.Join(",", data.Where(x => x.WXUserId == null).Select(x => x.NickName));
  84. if (!string.IsNullOrEmpty(noUsers))
  85. {
  86. throw new Exception($"以下用户未同步微信用户信息,请联系客服/行政人员:{noUsers}");
  87. }
  88. }
  89. return data;
  90. }
  91. }
  92. }