-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
calculating sms count on notification creation and returning exact nu…
…mber for metrics
- Loading branch information
Showing
7 changed files
with
94 additions
and
18 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
src/Altinn.Notifications.Persistence/Migration/v0.27/01-alter-procedure.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
CREATE OR REPLACE PROCEDURE notifications.insertsmsnotification( | ||
_orderid uuid, | ||
_alternateid uuid, | ||
_recipientorgno TEXT, | ||
_recipientnin TEXT, | ||
_mobilenumber TEXT, | ||
_result text, | ||
_smscount integer, | ||
_resulttime timestamptz, | ||
_expirytime timestamptz | ||
) | ||
LANGUAGE 'plpgsql' | ||
AS $BODY$ | ||
DECLARE | ||
__orderid BIGINT := (SELECT _id from notifications.orders | ||
where alternateid = _orderid); | ||
BEGIN | ||
|
||
INSERT INTO notifications.smsnotifications( | ||
_orderid, | ||
alternateid, | ||
recipientorgno, | ||
recipientnin, | ||
mobilenumber, | ||
result, | ||
smscount, | ||
resulttime, | ||
expirytime) | ||
VALUES ( | ||
__orderid, | ||
_alternateid, | ||
_recipientorgno, | ||
_recipientnin, | ||
_mobilenumber, | ||
_result::smsnotificationresulttype, | ||
_smscount, | ||
_resulttime, | ||
_expirytime); | ||
END; | ||
$BODY$; |
30 changes: 30 additions & 0 deletions
30
src/Altinn.Notifications.Persistence/Migration/v0.27/02-alter-functions.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
CREATE OR REPLACE FUNCTION notifications.getmetrics( | ||
month_input int, | ||
year_input int | ||
) | ||
RETURNS TABLE ( | ||
org text, | ||
placed_orders bigint, | ||
sent_emails bigint, | ||
succeeded_emails bigint, | ||
sent_sms bigint, | ||
succeeded_sms bigint | ||
) | ||
AS $$ | ||
BEGIN | ||
RETURN QUERY | ||
SELECT | ||
o.creatorname, | ||
COUNT(DISTINCT o._id) AS placed_orders, | ||
SUM(CASE WHEN e._id IS NOT NULL THEN 1 ELSE 0 END) AS sent_emails, | ||
SUM(CASE WHEN e.result = 'Succeeded' THEN 1 ELSE 0 END) AS succeeded_emails, | ||
SUM(CASE WHEN s._id IS NOT NULL THEN s.smscount ELSE 0 END) AS sent_sms, | ||
SUM(CASE WHEN s.result = 'Accepted' THEN 1 ELSE 0 END) AS succeeded_sms | ||
FROM notifications.orders o | ||
LEFT JOIN notifications.emailnotifications e ON o._id = e._orderid | ||
LEFT JOIN notifications.smsnotifications s ON o._id = s._orderid | ||
WHERE EXTRACT(MONTH FROM o.requestedsendtime) = month_input | ||
AND EXTRACT(YEAR FROM o.requestedsendtime) = year_input | ||
GROUP BY o.creatorname; | ||
END; | ||
$$ LANGUAGE plpgsql; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters