diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-07-07 08:24:16 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-07-07 08:24:16 +0000 |
| commit | 44bdb81a60d3a44ba7e379f3c20fe6d8fb284339 (patch) | |
| tree | b5c916a1c7ea37573f9bba7fefcef60a3b8aec20 /lib/evaluation-target-list | |
| parent | 90f79a7a691943a496f67f01c1e493256070e4de (diff) | |
(대표님) 변경사항 20250707 12시 30분
Diffstat (limited to 'lib/evaluation-target-list')
| -rw-r--r-- | lib/evaluation-target-list/service.ts | 57 |
1 files changed, 42 insertions, 15 deletions
diff --git a/lib/evaluation-target-list/service.ts b/lib/evaluation-target-list/service.ts index 0e209aa2..d134b54e 100644 --- a/lib/evaluation-target-list/service.ts +++ b/lib/evaluation-target-list/service.ts @@ -774,6 +774,7 @@ export async function confirmEvaluationTargets( updatedAt: new Date() }) } + console.log("periodicEvaluationsToCreate", periodicEvaluationsToCreate) } // 3. periodicEvaluations 레코드들 일괄 생성 @@ -786,7 +787,7 @@ export async function confirmEvaluationTargets( createdEvaluationsCount = createdEvaluations.length } - + console.log("createdEvaluationsCount", createdEvaluationsCount) // 4. 평가 항목 수 조회 (evaluationSubmissions 생성을 위해) const [generalItemsCount, esgItemsCount] = await Promise.all([ // 활성화된 일반평가 항목 수 @@ -846,6 +847,29 @@ export async function confirmEvaluationTargets( // 6. 벤더별 evaluationSubmissions 레코드 생성 const evaluationSubmissionsToCreate = [] + // 생성된 periodicEvaluations의 ID를 매핑하기 위한 맵 생성 + const periodicEvaluationIdMap = new Map() + if (createdEvaluationsCount > 0) { + const createdEvaluations = await tx + .select({ + id: periodicEvaluations.id, + evaluationTargetId: periodicEvaluations.evaluationTargetId + }) + .from(periodicEvaluations) + .where( + and( + inArray(periodicEvaluations.evaluationTargetId, confirmedTargetIds), + eq(periodicEvaluations.evaluationPeriod, currentPeriod) + ) + ) + + // evaluationTargetId를 키로 하는 맵 생성 + createdEvaluations.forEach(periodicEval => { + periodicEvaluationIdMap.set(periodicEval.evaluationTargetId, periodicEval.id) + }) + } + console.log("periodicEvaluationIdMap", periodicEvaluationIdMap) + for (const target of eligibleTargets) { // 이미 해당 년도/기간에 제출 레코드가 있는지 확인 const existingSubmission = await tx @@ -862,22 +886,25 @@ export async function confirmEvaluationTargets( // 없으면 생성 목록에 추가 if (existingSubmission.length === 0) { - evaluationSubmissionsToCreate.push({ - companyId: target.vendorId, - evaluationYear: target.evaluationYear, - evaluationRound: currentPeriod, - submissionStatus: "draft" as const, - totalGeneralItems: totalGeneralItems, - completedGeneralItems: 0, - totalEsgItems: totalEsgItems, - completedEsgItems: 0, - isActive: true, - createdAt: new Date(), - updatedAt: new Date() - }) + const periodicEvaluationId = periodicEvaluationIdMap.get(target.id) + if (periodicEvaluationId) { + evaluationSubmissionsToCreate.push({ + companyId: target.vendorId, + periodicEvaluationId: periodicEvaluationId, + evaluationYear: target.evaluationYear, + evaluationRound: currentPeriod, + submissionStatus: "draft" as const, + totalGeneralItems: totalGeneralItems, + completedGeneralItems: 0, + totalEsgItems: totalEsgItems, + completedEsgItems: 0, + isActive: true, + createdAt: new Date(), + updatedAt: new Date() + }) + } } } - // 7. evaluationSubmissions 레코드들 일괄 생성 let createdSubmissionsCount = 0 if (evaluationSubmissionsToCreate.length > 0) { |
