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

-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
-- EXEC [dbo].[procedure_test] @CUSTOMERID = '110959'
CREATE PROCEDURE [dbo].[proc_SendPushNotification]
-- Add the parameters for the stored procedure here
@Flag VARCHAR(50) = null,
@country VARCHAR(100) = null,
@gender VARCHAR(10) = null,
@registerToDate VARCHAR(30) = null,
@registerFromDate VARCHAR(30) = null,
@remitToDate VARCHAR(30) = null,
@remitFromDate VARCHAR(30) = null,
@toAmount MONEY =null,
@fromAmount MONEY = null,
@body NVARCHAR(MAX) = null,
@title NVARCHAR(MAX) = null,
@walletNo VARCHAR(100) = null,
@customerId BIGINT =null ,
@imageURL VARCHAR(MAX) = null
AS
SET NOCOUNT ON;
IF @flag = 'RemittSendNotify' -- 송금한 유저들에 대한 Notify 정보
BEGIN
CREATE TABLE #TempTable
(
deviceId NVARCHAR(MAX),
customerId BIGINT,
tranAmount MONEY
)
INSERT INTO #TempTable
SELECT mu.deviceId AS deviceId, cm.customerId as customerId, SUM(rm.tAmt) AS tranAmount
FROM customerMaster cm
INNER JOIN remitTran rm
ON rm.senderName = cm.firstName
INNER JOIN mobile_userRegistration mu
ON mu.customerId = cm.customerId
AND mu.username = cm.email
WHERE cm.createdDate BETWEEN @registerFromDate AND @registerToDate + ' 23:59:59'
AND rm.createdDate BETWEEN @remitFromDate AND @remitToDate + ' 23:59:59'
AND rm.payStatus = 'Paid'
AND cm.nativeCountry = ISNULL(@country, cm.nativeCountry)
AND cm.gender = ISNULL(ISNULL(@gender,cm.gender), '')
GROUP BY cm.customerId, mu.deviceId
SELECT deviceId, customerId
FROM #TempTable
WHERE tranAmount BETWEEN @fromAmount AND @toAmount + 1
RETURN
END
IF @flag ='RemittHistory' -- 송금한 유저에 대한 Notify 정보 저장
BEGIN
CREATE TABLE #TempSearch
(
customerId BIGINT,
tranAmount MONEY
)
INSERT INTO #TempSearch
SELECT mu.customerId AS customerId , SUM(rm.tAmt) AS tranAmount
FROM customerMaster cm
INNER JOIN remitTran rm
ON rm.senderName = cm.firstName
INNER JOIN mobile_userRegistration mu
ON mu.customerId = cm.customerId
AND mu.username = cm.email
WHERE cm.createdDate BETWEEN @registerFromDate AND @registerToDate + ' 23:59:59'
AND rm.createdDate BETWEEN @remitFromDate AND @remitToDate + ' 23:59:59'
AND rm.payStatus = 'Paid'
AND cm.nativeCountry = ISNULL(@country,cm.nativeCountry)
AND cm.gender = ISNULL(ISNULL(@gender,cm.gender), '')
GROUP BY mu.customerId, mu.deviceId
INSERT INTO pushNotificationHistroy (customerId, body, title, imageURL)
SELECT customerId , body = @body , title = @title, imageURL = ISNULL(@imageURL,'')
FROM #TempSearch
WHERE tranAmount BETWEEN @fromAmount AND @toAmount + 1
SELECT ph.customerId, body , title, imageURL
FROM pushNotificationHistroy ph
INNER JOIN #TempSearch ts
ON ph.customerId = ts.customerId
WHERE body = @body
AND title = @title
AND imageURL = ISNULL(@imageURL,'')
END
IF @Flag ='notifyByWalletNo'-- Wallet No 를 갖고 해당 유저에게 Notify 보내는 로직
BEGIN
SELECT mu.customerId AS customerId, mu.deviceId
FROM customerMaster cm
INNER JOIN mobile_userRegistration mu
ON mu.customerId = cm.customerId
AND mu.username = cm.email
WHERE walletAccountNo = @walletNo
RETURN
END
IF @Flag = 'SendNotify' -- 가입자 기준으로 Notify 보내는 로직
BEGIN
SELECT mu.deviceId AS deviceId, cm.customerId AS customerId
FROM customerMaster cm
INNER JOIN mobile_userRegistration mu
ON mu.customerId = cm.customerId
and mu.username = cm.email
WHERE cm.createdDate BETWEEN @registerFromDate AND @registerToDate + ' 23:59:59'
AND cm.nativeCountry = ISNULL(@country, cm.nativeCountry)
GROUP BY cm.customerId, mu.deviceId
RETURN
END
IF @Flag = 'SendNotifyHistory' -- 가입자 기준으로 Notify 정보 저장
BEGIN
INSERT INTO pushNotificationHistroy(customerId,title,body,imageURL)
SELECT cm.customerId, title=@title, body=@body, imageURL=ISNULL(@imageURL,'')
FROM customerMaster cm
INNER JOIN mobile_userRegistration mu
ON mu.customerId = cm.customerId
AND mu.username = cm.email
WHERE cm.createdDate BETWEEN @registerFromDate AND @registerToDate + ' 23:59:59'
AND cm.nativeCountry = ISNULL(@country,cm.nativeCountry)
SELECT cm.customerId, title=@title, body=@body, imageURL=ISNULL(@imageURL,'')
FROM customerMaster cm
INNER JOIN mobile_userRegistration mu
ON mu.customerId = cm.customerId
AND mu.username = cm.email
WHERE cm.createdDate BETWEEN @registerFromDate AND @registerToDate + ' 23:59:59'
AND cm.nativeCountry = ISNULL(@country,cm.nativeCountry)
RETURN
END
IF @Flag = 'SendNotifyHistoryByWalletno' -- Wallet No 기준 Notify 정보 저장
BEGIN
INSERT INTO pushNotificationHistroy(customerId,title,body,imageURL)
VALUES (@customerId,@title,@body,ISNULL(@imageURL,''))
END