feat: 실시간 알림 시스템 (Web Push + 알림 벨 + 서비스간 알림 연동)

- Phase 1: 모든 서비스 헤더에 알림 벨 UI 추가 (notification-bell.js)
- Phase 2: VAPID Web Push 구독/전송 (push-sw.js, pushSubscription API)
- Phase 3: 내부 알림 API + notifyHelper로 서비스간 알림 연동
  - tksafety: 출입 승인/반려, 안전교육 완료, 방문자 체크인
  - tkpurchase: 일용공 신청, 작업보고서 제출
  - system2-report: 신고 접수/확인/처리완료
- Phase 4: 30일 이상 알림 자동 정리 cron, Redis 캐싱
- CORS에 tkuser/tkpurchase/tksafety 서브도메인 추가
- HTML cache busting 버전 갱신

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Hyungi Ahn
2026-03-13 15:01:44 +09:00
parent 1ad82fd52c
commit 7fd646e9ba
102 changed files with 1446 additions and 94 deletions

View File

@@ -130,7 +130,7 @@
</div>
</div>
<script src="/static/js/tkpurchase-core.js?v=20260312"></script>
<script src="/static/js/tkpurchase-core.js?v=20260313b"></script>
<script src="/static/js/tkpurchase-accounts.js?v=20260312"></script>
<script>initAccountsPage();</script>
</body>

View File

@@ -144,7 +144,7 @@
</div>
</div>
<script src="/static/js/tkpurchase-core.js?v=20260312"></script>
<script src="/static/js/tkpurchase-core.js?v=20260313b"></script>
<script src="/static/js/tkpurchase-daylabor.js?v=20260312"></script>
<script>initDayLaborPage();</script>
</body>

View File

@@ -85,7 +85,7 @@
</div>
</div>
<script src="/static/js/tkpurchase-core.js?v=20260312"></script>
<script src="/static/js/tkpurchase-core.js?v=20260313b"></script>
<script src="/static/js/tkpurchase-dashboard.js?v=20260312"></script>
<script>initDashboard();</script>
</body>

View File

@@ -81,7 +81,7 @@
</div>
</div>
<script src="/static/js/tkpurchase-core.js?v=20260313a"></script>
<script src="/static/js/tkpurchase-core.js?v=20260313b"></script>
<script src="/static/js/tkpurchase-partner-portal.js?v=20260313a"></script>
<script>initPartnerPortal();</script>
</body>

View File

@@ -291,7 +291,7 @@
</div>
</div>
<script src="/static/js/tkpurchase-core.js?v=20260312"></script>
<script src="/static/js/tkpurchase-core.js?v=20260313b"></script>
<script src="/static/js/tkpurchase-partner.js?v=20260312"></script>
<script>initPartnerPage();</script>
</body>

41
tkpurchase/web/push-sw.js Normal file
View File

@@ -0,0 +1,41 @@
// Push Notification Service Worker
// 캐싱 없음 — Push 수신 전용
self.addEventListener('push', function(event) {
var data = { title: '알림', body: '새 알림이 있습니다.', url: '/' };
if (event.data) {
try { data = Object.assign(data, event.data.json()); } catch(e) {}
}
event.waitUntil(
self.registration.showNotification(data.title, {
body: data.body,
icon: '/static/img/icon-192.png',
badge: '/static/img/badge-72.png',
data: { url: data.url || '/' },
tag: 'tk-notification-' + Date.now(),
renotify: true
})
);
// 메인 페이지에 뱃지 갱신 신호 전송
self.clients.matchAll({ type: 'window' }).then(function(clients) {
clients.forEach(function(client) {
client.postMessage({ type: 'NOTIFICATION_RECEIVED' });
});
});
});
self.addEventListener('notificationclick', function(event) {
event.notification.close();
var url = (event.notification.data && event.notification.data.url) || '/';
event.waitUntil(
self.clients.matchAll({ type: 'window' }).then(function(clients) {
for (var i = 0; i < clients.length; i++) {
if (clients[i].url.includes(self.location.origin)) {
clients[i].navigate(url);
return clients[i].focus();
}
}
return self.clients.openWindow(url);
})
);
});

View File

@@ -271,7 +271,7 @@
</div>
</div>
<script src="/static/js/tkpurchase-core.js?v=20260313a"></script>
<script src="/static/js/tkpurchase-core.js?v=20260313b"></script>
<script src="/static/js/tkpurchase-schedule.js?v=20260313a"></script>
<script>initSchedulePage();</script>
</body>

View File

@@ -1,6 +1,8 @@
/* ===== 서비스 워커 해제 ===== */
/* ===== 서비스 워커 해제 (push-sw.js 제외) ===== */
if ('serviceWorker' in navigator) {
navigator.serviceWorker.getRegistrations().then(function(regs) { regs.forEach(function(r) { r.unregister(); }); });
navigator.serviceWorker.getRegistrations().then(function(regs) { regs.forEach(function(r) {
if (!r.active || !r.active.scriptURL.includes('push-sw.js')) { r.unregister(); }
}); });
if (typeof caches !== 'undefined') { caches.keys().then(function(ns) { ns.forEach(function(n) { caches.delete(n); }); }); }
}
@@ -143,6 +145,17 @@ function initAuth() {
if (nameEl) nameEl.textContent = dn;
if (avatarEl) avatarEl.textContent = dn.charAt(0).toUpperCase();
renderNavbar();
// 알림 벨 로드
_loadNotificationBell();
setTimeout(() => document.querySelector('.fade-in')?.classList.add('visible'), 50);
return true;
}
/* ===== 알림 벨 ===== */
function _loadNotificationBell() {
const s = document.createElement('script');
s.src = (location.hostname.includes('technicalkorea.net') ? 'https://tkfb.technicalkorea.net' : location.protocol + '//' + location.hostname + ':30000') + '/shared/notification-bell.js?v=1';
document.head.appendChild(s);
}

View File

@@ -109,7 +109,7 @@
</div>
</div>
<script src="/static/js/tkpurchase-core.js?v=20260312"></script>
<script src="/static/js/tkpurchase-core.js?v=20260313b"></script>
<script src="/static/js/tkpurchase-workreport.js?v=20260312"></script>
<script>initWorkReportPage();</script>
</body>