feat: 대시보드에 조제 이력 뱃지 추가

- PM_BASE.CD_PERSON에서 전화번호로 CUSCODE 매칭
- PS_main에서 조제 기록 유무 확인
- 조제 기록 있으면 녹색 '💊 환자' 뱃지
- 조제 기록 없으면 회색 '일반' 뱃지
This commit is contained in:
thug0bin
2026-02-27 16:42:14 +09:00
parent 04b0f3a8ca
commit d0e7d6bbd2
2 changed files with 36 additions and 2 deletions

View File

@@ -1854,12 +1854,38 @@ def admin():
""")
recent_users_raw = cursor.fetchall()
# 시간을 KST로 변환
# 시간을 KST로 변환 + 조제 이력 확인
recent_users = []
# MSSQL 세션 (조제 이력 확인용)
try:
mssql_session = db_manager.get_session('PM_PRES')
except:
mssql_session = None
for user in recent_users_raw:
user_dict = dict(user)
user_dict['created_at'] = utc_to_kst_str(user['created_at'])
user_dict['kakao_verified_at'] = utc_to_kst_str(user['kakao_verified_at']) if user['kakao_verified_at'] else None
# 조제 이력 확인 (MSSQL)
user_dict['has_prescription'] = False
if mssql_session and user['phone']:
try:
phone_clean = user['phone'].replace('-', '').replace(' ', '')
pres_check = mssql_session.execute(text("""
SELECT TOP 1 p.CusCode
FROM PM_BASE.dbo.CD_PERSON p
INNER JOIN PS_main ps ON p.CUSCODE = ps.CusCode
WHERE REPLACE(REPLACE(p.PHONE, '-', ''), ' ', '') = :phone
OR REPLACE(REPLACE(p.PHONE2, '-', ''), ' ', '') = :phone
OR REPLACE(REPLACE(p.TEL_NO, '-', ''), ' ', '') = :phone
"""), {'phone': phone_clean}).fetchone()
if pres_check:
user_dict['has_prescription'] = True
except Exception as e:
logging.warning(f"조제 이력 확인 실패 (user {user['id']}): {e}")
recent_users.append(user_dict)
# 최근 적립 내역 (50건)