diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-11-27 09:43:55 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-11-27 09:43:55 +0000 |
| commit | daabc02e9ae54f216ada77aa826b349f37c3281a (patch) | |
| tree | 74c6f94e0c66ee31dfeac2f355c5156431cd42e3 /lib/bidding/service.ts | |
| parent | 5870b73785715d1585531e655c06d8c068eb64ac (diff) | |
(최겸) 구매 입찰 피드백 반영(80%완)
Diffstat (limited to 'lib/bidding/service.ts')
| -rw-r--r-- | lib/bidding/service.ts | 87 |
1 files changed, 71 insertions, 16 deletions
diff --git a/lib/bidding/service.ts b/lib/bidding/service.ts index 489268c6..8fd1d368 100644 --- a/lib/bidding/service.ts +++ b/lib/bidding/service.ts @@ -797,6 +797,22 @@ export async function createBidding(input: CreateBiddingInput, userId: string) { return null } } + + // 담당자 정보 준비 + let bidPicId = input.bidPicId ? parseInt(input.bidPicId.toString()) : null + let bidPicName = input.bidPicName || null + + if (!bidPicId && input.bidPicCode) { + try { + const userInfo = await findUserInfoByEKGRP(input.bidPicCode) + if (userInfo) { + bidPicId = userInfo.userId + bidPicName = userInfo.userName + } + } catch (e) { + console.error('Failed to find user info by EKGRP:', e) + } + } // 1. 입찰 생성 const [newBidding] = await tx @@ -849,8 +865,8 @@ export async function createBidding(input: CreateBiddingInput, userId: string) { purchasingOrganization: input.purchasingOrganization, // 담당자 정보 (user FK) - bidPicId: input.bidPicId ? parseInt(input.bidPicId.toString()) : null, - bidPicName: input.bidPicName || null, + bidPicId, + bidPicName, bidPicCode: input.bidPicCode || null, supplyPicId: input.supplyPicId ? parseInt(input.supplyPicId.toString()) : null, supplyPicName: input.supplyPicName || null, @@ -1234,6 +1250,24 @@ export async function updateBidding(input: UpdateBiddingInput, userId: string) { // 담당자 정보 (user FK) if (input.bidPicId !== undefined) updateData.bidPicId = input.bidPicId if (input.bidPicName !== undefined) updateData.bidPicName = input.bidPicName + + // bidPicCode가 있으면 담당자 정보 자동 조회 및 업데이트 + if (input.bidPicCode !== undefined) { + updateData.bidPicCode = input.bidPicCode + // bidPicId가 명시적으로 제공되지 않았고 코드가 있는 경우 자동 조회 + if (!input.bidPicId && input.bidPicCode) { + try { + const userInfo = await findUserInfoByEKGRP(input.bidPicCode) + if (userInfo) { + updateData.bidPicId = userInfo.userId + updateData.bidPicName = userInfo.userName + } + } catch (e) { + console.error('Failed to find user info by EKGRP:', e) + } + } + } + if (input.supplyPicId !== undefined) updateData.supplyPicId = input.supplyPicId if (input.supplyPicName !== undefined) updateData.supplyPicName = input.supplyPicName @@ -1927,22 +1961,12 @@ export async function updateBiddingSchedule( try { const userName = await getUserNameById(userId) - // 날짜 문자열을 Date 객체로 수동 변환 + // 날짜 문자열을 Date 객체로 변환 (KST 기준) const parseDate = (dateStr?: string) => { if (!dateStr) return undefined - // 'YYYY-MM-DDTHH:mm' 또는 'YYYY-MM-DD HH:mm' 등을 허용 - // 잘못된 포맷이면 undefined 반환 - const m = dateStr.match( - /^(\d{4})-(\d{2})-(\d{2})[T ]?(\d{2}):(\d{2})(?::(\d{2}))?$/ - ) - if (!m) return undefined - const year = parseInt(m[1], 10) - const month = parseInt(m[2], 10) - 1 // JS month는 0부터 - const day = parseInt(m[3], 10) - const hour = parseInt(m[4], 10) - const min = parseInt(m[5], 10) - const sec = m[6] ? parseInt(m[6], 10) : 0 - return new Date(Date.UTC(year, month, day, hour, min, sec)) + // 'YYYY-MM-DDTHH:mm' 형식을 가정하고 KST(+09:00) 오프셋을 붙여서 파싱 + // 초(:00)를 추가하여 ISO 8601 호환성 확보 + return new Date(`${dateStr}:00+09:00`) } return await db.transaction(async (tx) => { @@ -2178,6 +2202,34 @@ export async function removeBiddingItem(itemId: number) { } } +// 입찰의 첫 번째 PR 아이템 프로젝트 정보로 bidding 업데이트 +export async function updateBiddingProjectInfo(biddingId: number) { + try { + const firstItem = await db + .select({ + projectInfo: prItemsForBidding.projectInfo + }) + .from(prItemsForBidding) + .where(eq(prItemsForBidding.biddingId, biddingId)) + .orderBy(prItemsForBidding.id) + .limit(1) + + if (firstItem.length > 0 && firstItem[0].projectInfo) { + await db + .update(biddings) + .set({ + projectName: firstItem[0].projectInfo, + updatedAt: new Date() + }) + .where(eq(biddings.id, biddingId)) + + console.log(`Bidding ${biddingId} project info updated to: ${firstItem[0].projectInfo}`) + } + } catch (error) { + console.error('Failed to update bidding project info:', error) + } +} + // 입찰의 PR 아이템 금액 합산하여 bidding 업데이트 async function updateBiddingAmounts(biddingId: number) { try { @@ -2289,6 +2341,9 @@ export async function addPRItemForBidding( // PR 아이템 금액 합산하여 bidding 업데이트 await updateBiddingAmounts(biddingId) + // 프로젝트 정보 업데이트 + await updateBiddingProjectInfo(biddingId) + revalidatePath(`/evcp/bid/${biddingId}/info`) revalidatePath(`/evcp/bid/${biddingId}`) |
