261023_02_ENH: 일괄 발송 일부 접수 완료 상태 지원 및 결과 알림·건수 표시 개선
This commit is contained in:
58
src/utils/listJobResult.ts
Normal file
58
src/utils/listJobResult.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { listJobLabel } from '@/const/listJobConst'
|
||||
import type { ListJob } from '@/types/list-job'
|
||||
|
||||
/** SID와 수신자 건수는 단위가 다르므로 합산하지 않는다. */
|
||||
export function formatMessageJobResult(progress: ListJob['progress']): string {
|
||||
const p = progress ?? {}
|
||||
const accepted = p.acceptedRecipientCnt
|
||||
const parts = [typeof accepted === 'number' && Number.isSafeInteger(accepted) && accepted >= 0
|
||||
? `${accepted.toLocaleString()}건 접수 완료` : '접수 건수 확인 불가']
|
||||
const fields = [
|
||||
['preparationFailedSidCnt', '준비 실패 SID', '개'],
|
||||
['noDestinationSkippedSidCnt', '수신처 없음 SID', '개 제외'],
|
||||
['failedRecipientCnt', '접수 실패', '건'],
|
||||
['unknownRecipientCnt', '접수 여부 불명', '건'],
|
||||
] as const
|
||||
for (const [field, label, unit] of fields) {
|
||||
const value = p[field]
|
||||
if (typeof value === 'number' && Number.isSafeInteger(value) && value > 0) {
|
||||
parts.push(`${label} ${value.toLocaleString()}${unit}`)
|
||||
}
|
||||
}
|
||||
return parts.join(', ')
|
||||
}
|
||||
|
||||
type JobNotification = {
|
||||
kind: 'success' | 'warning' | 'info' | 'error'
|
||||
message: string
|
||||
description?: string
|
||||
}
|
||||
|
||||
/** errorCode가 있어도 최종 성공 여부는 서버 jobStatus를 따른다. */
|
||||
export function getListJobResultNotification(job: ListJob): JobNotification {
|
||||
const label = listJobLabel(job.jobType, job.operation)
|
||||
const messageJob = job.jobType.endsWith('_BULK')
|
||||
const summary = messageJob ? formatMessageJobResult(job.progress) : undefined
|
||||
switch (job.jobStatus) {
|
||||
case 'SUCCEEDED':
|
||||
return {
|
||||
kind: 'success',
|
||||
message: messageJob ? `${label} 접수 완료` : `${label} 작업이 완료됐습니다.`,
|
||||
description: summary,
|
||||
}
|
||||
case 'PARTIALLY_SUCCEEDED':
|
||||
return {
|
||||
kind: 'warning',
|
||||
message: `${label} 일부 접수 완료`,
|
||||
description: [summary, '접수는 실제 전달 완료가 아닙니다. 전체 재발송 전에 접수 내역을 확인해 주세요.'].filter(Boolean).join('\n'),
|
||||
}
|
||||
case 'CANCELLED':
|
||||
return { kind: 'info', message: `${label} 작업이 중단됐습니다.`, description: summary }
|
||||
default:
|
||||
return {
|
||||
kind: 'error',
|
||||
message: job.jobStatus === 'REJECTED' ? `${label} 접수가 거절됐습니다.` : `${label} 작업이 실패했습니다.`,
|
||||
description: [job.errorMessage, summary].filter(Boolean).join('\n'),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user