@@ -60,17 +60,30 @@ async def create_certificate(certificate_data: dict) -> CertificateResponse:
6060
6161 # ๊ธฐ์กด ์๋ฃ์ฆ ํ์ธ์ด ์ฑ๊ณตํ๊ณ ๊ธฐ์กด ์๋ฃ์ฆ์ด ์๋ ๊ฒฝ์ฐ ์ฌ๋ฐ๊ธ ์ฒ๋ฆฌ
6262 if existing_cert and existing_cert .get ("found" ):
63+ existing_status = existing_cert .get ("status" , "" )
64+ if existing_status in [CertificateStatus .ISSUED , CertificateStatus .REISSUED ]:
65+ logger .info (
66+ "๊ธฐ์กด ์๋ฃ์ฆ ๋ฐ๊ฒฌ (์ฌ๋ฐ๊ธ ์งํ)" ,
67+ extra = {
68+ "certificate_number" : existing_cert .get ("certificate_number" ),
69+ "applicant_name" : certificate_data .get ("applicant_name" ),
70+ "season" : certificate_data .get ("season" ),
71+ "status" : existing_status ,
72+ },
73+ )
74+ return await CertificateService ._reissue_certificate (
75+ certificate_data , existing_cert , notion_client
76+ )
77+
6378 logger .info (
64- "๊ธฐ์กด ์๋ฃ์ฆ ๋ฐ๊ฒฌ " ,
79+ "๊ธฐ์กด ์๋ฃ์ฆ ๋ฐ๊ฒฌํ์ง๋ง ์ํ๊ฐ Issued/Reissued๊ฐ ์๋. ์ ๊ท ๋ฐ๊ธ์ผ๋ก ์งํ " ,
6580 extra = {
6681 "certificate_number" : existing_cert .get ("certificate_number" ),
6782 "applicant_name" : certificate_data .get ("applicant_name" ),
6883 "season" : certificate_data .get ("season" ),
84+ "status" : existing_status ,
6985 },
7086 )
71- return await CertificateService ._reissue_certificate (
72- certificate_data , existing_cert , notion_client
73- )
7487
7588 # 2. ์ ๊ท ์๋ฃ์ฆ ๋ฐ๊ธ ์ฒ๋ฆฌ
7689 return await CertificateService ._create_new_certificate (
@@ -140,6 +153,9 @@ async def _reissue_certificate(
140153 extra = {"certificate_number" : existing_cert_number },
141154 )
142155
156+ # ๋ฐ๊ธ์ผ(์ฌ๋ฐ๊ธ ์์ ๊ธฐ์ค)
157+ issue_date = datetime .now ().strftime ("%Y-%m-%d" )
158+
143159 # PDF ์๋ฃ์ฆ ์ฌ์์ฑ
144160 pdf_generator = PDFGenerator ()
145161 pdf_bytes = pdf_generator .create_certificate (
@@ -148,6 +164,8 @@ async def _reissue_certificate(
148164 course_name = certificate_data ["course_name" ],
149165 role = participation_info ["user_role" ],
150166 period = participation_info ["period" ],
167+ certificate_number = existing_cert_number ,
168+ issue_date = issue_date ,
151169 )
152170
153171 # ์ด๋ฉ์ผ ์ฌ๋ฐ์ก
@@ -160,6 +178,22 @@ async def _reissue_certificate(
160178 role = participation_info ["user_role" ],
161179 certificate_bytes = pdf_bytes
162180 )
181+
182+ # ์ฌ๋ฐ๊ธ ๋ก๊ทธ ๊ธฐ๋ก
183+ reissue_log = await notion_client .log_certificate_reissue (
184+ certificate_data = certificate_data ,
185+ certificate_number = existing_cert_number ,
186+ role = participation_info ["user_role" ],
187+ issue_date = issue_date
188+ )
189+ if not reissue_log :
190+ logger .warning (
191+ "์ฌ๋ฐ๊ธ ๋ก๊ทธ ๊ธฐ๋ก ์คํจ" ,
192+ extra = {
193+ "certificate_number" : existing_cert_number ,
194+ "recipient_email" : certificate_data ["recipient_email" ],
195+ },
196+ )
163197
164198 # ๊ธฐ์กด ์๋ฃ์ฆ ์ํ๋ฅผ ์ฌ๋ฐ๊ธ์ผ๋ก ์
๋ฐ์ดํธ
165199 await notion_client .update_certificate_status (
@@ -185,7 +219,7 @@ async def _reissue_certificate(
185219 name = certificate_data ["applicant_name" ],
186220 recipient_email = certificate_data ["recipient_email" ],
187221 certificate_number = existing_cert_number ,
188- issue_date = datetime . now (). strftime ( "%Y-%m-%d" ) ,
222+ issue_date = issue_date ,
189223 certificate_status = CertificateStatus .ISSUED ,
190224 season = certificate_data ["season" ],
191225 course_name = certificate_data ["course_name" ],
@@ -226,6 +260,7 @@ async def _create_new_certificate(
226260
227261 # TODO: ์์ ๊ฐ, ์ถํ ์์ ํ์
228262 certificate_number = f"CERT-{ datetime .now ().year } { participation_info ['project_code' ]} { str (uuid .uuid4 ())[:2 ].upper ()} "
263+ issue_date = datetime .now ().strftime ("%Y-%m-%d" )
229264
230265 # PDF ์๋ฃ์ฆ ์์ฑ
231266 pdf_generator = PDFGenerator ()
@@ -235,6 +270,8 @@ async def _create_new_certificate(
235270 course_name = certificate_data ["course_name" ],
236271 role = participation_info ["user_role" ],
237272 period = participation_info ["period" ],
273+ certificate_number = certificate_number ,
274+ issue_date = issue_date ,
238275 )
239276 # ์ด๋ฉ์ผ ๋ฐ์ก
240277 email_sender = EmailSender ()
@@ -281,7 +318,7 @@ async def _create_new_certificate(
281318 name = certificate_data ["applicant_name" ],
282319 recipient_email = certificate_data ["recipient_email" ],
283320 certificate_number = certificate_number ,
284- issue_date = datetime . now (). strftime ( "%Y-%m-%d" ) ,
321+ issue_date = issue_date ,
285322 certificate_status = CertificateStatus .ISSUED ,
286323 season = certificate_data ["season" ],
287324 course_name = certificate_data ["course_name" ],
0 commit comments