You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

151 lines
5.4 KiB

1 year ago
  1. -- =============================================
  2. -- Author: <Author,,Name>
  3. -- Create date: <Create Date,,>
  4. -- Description: <Description,,>
  5. -- =============================================
  6. -- EXEC [dbo].[procedure_test] @CUSTOMERID = '110959'
  7. CREATE PROCEDURE [dbo].[proc_SendPushNotification]
  8. -- Add the parameters for the stored procedure here
  9. @Flag VARCHAR(50) = null,
  10. @country VARCHAR(100) = null,
  11. @gender VARCHAR(10) = null,
  12. @registerToDate VARCHAR(30) = null,
  13. @registerFromDate VARCHAR(30) = null,
  14. @remitToDate VARCHAR(30) = null,
  15. @remitFromDate VARCHAR(30) = null,
  16. @toAmount MONEY =null,
  17. @fromAmount MONEY = null,
  18. @body NVARCHAR(MAX) = null,
  19. @title NVARCHAR(MAX) = null,
  20. @walletNo VARCHAR(100) = null,
  21. @customerId BIGINT =null ,
  22. @imageURL VARCHAR(MAX) = null
  23. AS
  24. SET NOCOUNT ON;
  25. IF @flag = 'RemittSendNotify' -- �۱��� �����鿡 ���� Notify ����
  26. BEGIN
  27. CREATE TABLE #TempTable
  28. (
  29. deviceId NVARCHAR(MAX),
  30. customerId BIGINT,
  31. tranAmount MONEY
  32. )
  33. INSERT INTO #TempTable
  34. SELECT mu.deviceId AS deviceId, cm.customerId as customerId, SUM(rm.tAmt) AS tranAmount
  35. FROM customerMaster cm
  36. INNER JOIN remitTran rm
  37. ON rm.senderName = cm.firstName
  38. INNER JOIN mobile_userRegistration mu
  39. ON mu.customerId = cm.customerId
  40. AND mu.username = cm.email
  41. WHERE cm.createdDate BETWEEN @registerFromDate AND @registerToDate + ' 23:59:59'
  42. AND rm.createdDate BETWEEN @remitFromDate AND @remitToDate + ' 23:59:59'
  43. AND rm.payStatus = 'Paid'
  44. AND cm.nativeCountry = ISNULL(@country, cm.nativeCountry)
  45. AND cm.gender = ISNULL(ISNULL(@gender,cm.gender), '')
  46. GROUP BY cm.customerId, mu.deviceId
  47. SELECT deviceId, customerId
  48. FROM #TempTable
  49. WHERE tranAmount BETWEEN @fromAmount AND @toAmount + 1
  50. RETURN
  51. END
  52. IF @flag ='RemittHistory' -- �۱��� ������ ���� Notify ���� ����
  53. BEGIN
  54. CREATE TABLE #TempSearch
  55. (
  56. customerId BIGINT,
  57. tranAmount MONEY
  58. )
  59. INSERT INTO #TempSearch
  60. SELECT mu.customerId AS customerId , SUM(rm.tAmt) AS tranAmount
  61. FROM customerMaster cm
  62. INNER JOIN remitTran rm
  63. ON rm.senderName = cm.firstName
  64. INNER JOIN mobile_userRegistration mu
  65. ON mu.customerId = cm.customerId
  66. AND mu.username = cm.email
  67. WHERE cm.createdDate BETWEEN @registerFromDate AND @registerToDate + ' 23:59:59'
  68. AND rm.createdDate BETWEEN @remitFromDate AND @remitToDate + ' 23:59:59'
  69. AND rm.payStatus = 'Paid'
  70. AND cm.nativeCountry = ISNULL(@country,cm.nativeCountry)
  71. AND cm.gender = ISNULL(ISNULL(@gender,cm.gender), '')
  72. GROUP BY mu.customerId, mu.deviceId
  73. INSERT INTO pushNotificationHistroy (customerId, body, title, imageURL)
  74. SELECT customerId , body = @body , title = @title, imageURL = ISNULL(@imageURL,'')
  75. FROM #TempSearch
  76. WHERE tranAmount BETWEEN @fromAmount AND @toAmount + 1
  77. SELECT ph.customerId, body , title, imageURL
  78. FROM pushNotificationHistroy ph
  79. INNER JOIN #TempSearch ts
  80. ON ph.customerId = ts.customerId
  81. WHERE body = @body
  82. AND title = @title
  83. AND imageURL = ISNULL(@imageURL,'')
  84. END
  85. IF @Flag ='notifyByWalletNo'-- Wallet No �� ���� �ش� �������� Notify ������ ����
  86. BEGIN
  87. SELECT mu.customerId AS customerId, mu.deviceId
  88. FROM customerMaster cm
  89. INNER JOIN mobile_userRegistration mu
  90. ON mu.customerId = cm.customerId
  91. AND mu.username = cm.email
  92. WHERE walletAccountNo = @walletNo
  93. RETURN
  94. END
  95. IF @Flag = 'SendNotify' -- ������ �������� Notify ������ ����
  96. BEGIN
  97. SELECT mu.deviceId AS deviceId, cm.customerId AS customerId
  98. FROM customerMaster cm
  99. INNER JOIN mobile_userRegistration mu
  100. ON mu.customerId = cm.customerId
  101. and mu.username = cm.email
  102. WHERE cm.createdDate BETWEEN @registerFromDate AND @registerToDate + ' 23:59:59'
  103. AND cm.nativeCountry = ISNULL(@country, cm.nativeCountry)
  104. GROUP BY cm.customerId, mu.deviceId
  105. RETURN
  106. END
  107. IF @Flag = 'SendNotifyHistory' -- ������ �������� Notify ���� ����
  108. BEGIN
  109. INSERT INTO pushNotificationHistroy(customerId,title,body,imageURL)
  110. SELECT cm.customerId, title=@title, body=@body, imageURL=ISNULL(@imageURL,'')
  111. FROM customerMaster cm
  112. INNER JOIN mobile_userRegistration mu
  113. ON mu.customerId = cm.customerId
  114. AND mu.username = cm.email
  115. WHERE cm.createdDate BETWEEN @registerFromDate AND @registerToDate + ' 23:59:59'
  116. AND cm.nativeCountry = ISNULL(@country,cm.nativeCountry)
  117. SELECT cm.customerId, title=@title, body=@body, imageURL=ISNULL(@imageURL,'')
  118. FROM customerMaster cm
  119. INNER JOIN mobile_userRegistration mu
  120. ON mu.customerId = cm.customerId
  121. AND mu.username = cm.email
  122. WHERE cm.createdDate BETWEEN @registerFromDate AND @registerToDate + ' 23:59:59'
  123. AND cm.nativeCountry = ISNULL(@country,cm.nativeCountry)
  124. RETURN
  125. END
  126. IF @Flag = 'SendNotifyHistoryByWalletno' -- Wallet No ���� Notify ���� ����
  127. BEGIN
  128. INSERT INTO pushNotificationHistroy(customerId,title,body,imageURL)
  129. VALUES (@customerId,@title,@body,ISNULL(@imageURL,''))
  130. END