| 1 | = Процедури |
| 2 | |
| 3 | == Процедура за одбивање на 'PENDING' на пријави за корисници постари од 1 месец |
| 4 | |
| 5 | {{{ |
| 6 | |
| 7 | CREATE OR REPLACE PROCEDURE mark_denied_reports_older_than_1month() |
| 8 | LANGUAGE plpgsql |
| 9 | AS $$ |
| 10 | DECLARE |
| 11 | older_reports RECORD; |
| 12 | user_id int; |
| 13 | BEGIN |
| 14 | FOR older_reports IN |
| 15 | SELECT |
| 16 | r.id AS submission_id, |
| 17 | r.thread_id as topic |
| 18 | FROM report r |
| 19 | JOIN submission s ON s.id = r.id |
| 20 | WHERE s.status = 'PENDING' and now() - s.created_at >= INTERVAL '1 month' |
| 21 | LOOP |
| 22 | BEGIN |
| 23 | UPDATE submission |
| 24 | SET status = 'DENIED' |
| 25 | WHERE id = older_reports.submission_id; |
| 26 | |
| 27 | select u.id |
| 28 | into user_id |
| 29 | from thread t |
| 30 | join users u |
| 31 | on t.user_id = u.id |
| 32 | where t.id = older_reports.thread_id; |
| 33 | |
| 34 | |
| 35 | INSERT INTO feedback(description, submission_type, created_at, submission_id, created_by) |
| 36 | VALUES ( |
| 37 | 'Stale report. Closing due to inactivity.', |
| 38 | 'R', |
| 39 | now(), |
| 40 | older_reports.submission_id, |
| 41 | user_id |
| 42 | ); |
| 43 | END; |
| 44 | END LOOP; |
| 45 | END; |
| 46 | $$; |
| 47 | }}} |
| 48 | |
| 49 | {{{ |
| 50 | @Transactional |
| 51 | @Scheduled(cron = "0 0 0 1 * ?") |
| 52 | public void markRejectedPendingReports() { |
| 53 | em |
| 54 | .createNativeQuery("CALL mark_denied_reports_older_than_1month();") |
| 55 | .executeUpdate(); |
| 56 | } |
| 57 | }}} |
| 58 | |
| 59 | == Процедура за одбивање на 'PENDING' за барања за учество во даден проект постари од 1 месец |
| 60 | |
| 61 | {{{ |
| 62 | CREATE OR REPLACE PROCEDURE mark_denied_pr_requests_older_than_1month() |
| 63 | LANGUAGE plpgsql |
| 64 | AS $$ |
| 65 | DECLARE |
| 66 | older_reports RECORD; |
| 67 | user_id int; |
| 68 | BEGIN |
| 69 | FOR older_reports IN |
| 70 | SELECT |
| 71 | pr.id AS submission_id, |
| 72 | pr.project_id as thread_id |
| 73 | FROM project_request pr |
| 74 | JOIN submission s ON s.id = pr.id |
| 75 | WHERE s.status = 'PENDING' and now() - s.created_at >= INTERVAL '1 month' |
| 76 | LOOP |
| 77 | BEGIN |
| 78 | UPDATE submission |
| 79 | SET status = 'DENIED' |
| 80 | WHERE id = older_reports.submission_id; |
| 81 | |
| 82 | select u.id |
| 83 | into user_id |
| 84 | from thread t |
| 85 | join users u |
| 86 | on t.user_id = u.id |
| 87 | where older_reports.thread_id = t.id; |
| 88 | |
| 89 | INSERT INTO feedback(description, submission_type, created_at, submission_id, created_by) |
| 90 | VALUES ( |
| 91 | 'Stale report. Closing due to inactivity.', |
| 92 | 'P', |
| 93 | now(), |
| 94 | older_reports.submission_id, |
| 95 | user_id |
| 96 | ); |
| 97 | END; |
| 98 | END LOOP; |
| 99 | END; |
| 100 | $$; |
| 101 | }}} |
| 102 | |
| 103 | {{{ |
| 104 | @Transactional |
| 105 | @Scheduled(cron = "0 0 0 1 * ?") |
| 106 | public void markRejectedPendingPrRequests() { |
| 107 | em |
| 108 | .createNativeQuery("CALL mark_denied_pr_requests_older_than_1month();") |
| 109 | .executeUpdate(); |
| 110 | } |
| 111 | }}} |