diff options
Diffstat (limited to 'lib/rfq-last')
| -rw-r--r-- | lib/rfq-last/attachment/vendor-response-table.tsx | 1 | ||||
| -rw-r--r-- | lib/rfq-last/service.ts | 87 | ||||
| -rw-r--r-- | lib/rfq-last/validations.ts | 2 | ||||
| -rw-r--r-- | lib/rfq-last/vendor/rfq-vendor-table.tsx | 8 |
4 files changed, 82 insertions, 16 deletions
diff --git a/lib/rfq-last/attachment/vendor-response-table.tsx b/lib/rfq-last/attachment/vendor-response-table.tsx index 8be5210f..076fb153 100644 --- a/lib/rfq-last/attachment/vendor-response-table.tsx +++ b/lib/rfq-last/attachment/vendor-response-table.tsx @@ -159,7 +159,6 @@ export function VendorResponseTable({ const [isUpdating, setIsUpdating] = React.useState(false); const [showTypeDialog, setShowTypeDialog] = React.useState(false); const [selectedType, setSelectedType] = React.useState<"구매" | "설계" | "">(""); - console.log(data,"data") const [selectedVendor, setSelectedVendor] = React.useState<string | null>(null); diff --git a/lib/rfq-last/service.ts b/lib/rfq-last/service.ts index 8eed9bee..09d707d7 100644 --- a/lib/rfq-last/service.ts +++ b/lib/rfq-last/service.ts @@ -3643,7 +3643,7 @@ async function handleTbeSession({ sessionCode: sessionCode, sessionTitle: `${rfqData.rfqCode} - ${vendor.vendorName} 기술검토`, sessionType: "initial", - status: "준비중", + status: "생성중", evaluationResult: null, plannedStartDate: rfqData.dueDate ? addDays(new Date(rfqData.dueDate), 1) @@ -4738,13 +4738,12 @@ export async function updateShortList( // 트랜잭션으로 처리 const result = await db.transaction(async (tx) => { - // 해당 RFQ의 모든 벤더들의 shortList를 먼저 false로 설정 (선택적) - // 만약 선택된 것만 true로 하고 나머지는 그대로 두려면 이 부분 제거 + // 1. 해당 RFQ의 모든 벤더들의 shortList를 먼저 false로 설정 await tx .update(rfqLastDetails) .set({ shortList: false, - updatedBy: session.user.id, + updatedBy: Number(session.user.id), updatedAt: new Date() }) .where( @@ -4754,15 +4753,16 @@ export async function updateShortList( ) ); - // 선택된 벤더들의 shortList를 true로 설정 + // 2. 선택된 벤더들 처리 if (vendorIds.length > 0) { - const updates = await Promise.all( + // 2-1. 선택된 벤더들의 shortList를 true로 설정 + const updatedDetails = await Promise.all( vendorIds.map(vendorId => tx .update(rfqLastDetails) .set({ shortList: shortListStatus, - updatedBy: session.user.id, + updatedBy: Number(session.user.id), updatedAt: new Date() }) .where( @@ -4776,17 +4776,84 @@ export async function updateShortList( ) ); + // 2-2. TBE 세션 처리 (shortList가 true인 경우에만) + if (shortListStatus) { + // 각 벤더에 대한 rfqLastDetailsId 추출 + const detailsMap = new Map( + updatedDetails.flat().map(detail => [detail.vendorsId, detail.id]) + ); + + // TBE 세션 생성 또는 업데이트 + await Promise.all( + vendorIds.map(async (vendorId) => { + const rfqLastDetailsId = detailsMap.get(vendorId); + + if (!rfqLastDetailsId) { + console.warn(`rfqLastDetailsId not found for vendorId: ${vendorId}`); + return; + } + + // 기존 활성 TBE 세션이 있는지 확인 + const existingSession = await tx + .select() + .from(rfqLastTbeSessions) + .where( + and( + eq(rfqLastTbeSessions.rfqsLastId, rfqId), + eq(rfqLastTbeSessions.vendorId, vendorId), + inArray(rfqLastTbeSessions.status, ["생성중", "준비중", "진행중", "검토중", "보류"]) + ) + ) + .limit(1); + + if (existingSession.length > 0) { + // 기존 세션이 있으면 상태 업데이트 + await tx + .update(rfqLastTbeSessions) + .set({ + status: "준비중", + updatedBy: session.user.id, + updatedAt: new Date() + }) + .where(eq(rfqLastTbeSessions.id, existingSession[0].id)); + } + }) + ); + } else { + // shortList가 false인 경우, 해당 벤더들의 활성 TBE 세션을 취소 상태로 변경 + await Promise.all( + vendorIds.map(vendorId => + tx + .update(rfqLastTbeSessions) + .set({ + status: "취소", + updatedBy: Number(session.user.id), + updatedAt: new Date() + }) + .where( + and( + eq(rfqLastTbeSessions.rfqsLastId, rfqId), + eq(rfqLastTbeSessions.vendorId, vendorId), + inArray(rfqLastTbeSessions.status, ["생성중", "준비중", "진행중", "검토중", "보류"]) + ) + ) + ) + ); + } + return { success: true, - updatedCount: updates.length, - vendorIds + updatedCount: updatedDetails.length, + vendorIds, + tbeSessionsUpdated: shortListStatus }; } return { success: true, updatedCount: 0, - vendorIds: [] + vendorIds: [], + tbeSessionsUpdated: false }; }); diff --git a/lib/rfq-last/validations.ts b/lib/rfq-last/validations.ts index 5615db7a..6a5816d4 100644 --- a/lib/rfq-last/validations.ts +++ b/lib/rfq-last/validations.ts @@ -56,7 +56,7 @@ import { RfqLastAttachments } from "@/db/schema"; search: parseAsString.withDefault(""), // RFQ 카테고리 (전체/일반견적/ITB/RFQ) - rfqCategory: parseAsStringEnum(["all", "general", "itb", "rfq"]).withDefault("all"), + rfqCategory: parseAsStringEnum(["all", "general", "itb", "rfq"]), }); // ============= 타입 정의 ============= diff --git a/lib/rfq-last/vendor/rfq-vendor-table.tsx b/lib/rfq-last/vendor/rfq-vendor-table.tsx index 89a42602..17433773 100644 --- a/lib/rfq-last/vendor/rfq-vendor-table.tsx +++ b/lib/rfq-last/vendor/rfq-vendor-table.tsx @@ -360,7 +360,7 @@ export function RfqVendorTable({ // 선택된 벤더 ID들 추출 const selectedVendorIds = rfqCode?.startsWith("I") ? selectedRows - .filter(v => v.shortList) + // .filter(v => v.shortList) .map(row => row.vendorId) .filter(id => id != null) : selectedRows @@ -1218,7 +1218,7 @@ export function RfqVendorTable({ }, size: 80, }, - ...(rfqCode?.startsWith("I") ? [{ + ...(!rfqCode?.startsWith("F") ? [{ accessorKey: "shortList", filterFn: createFilterFn("boolean"), // boolean으로 변경 header: ({ column }) => <ClientDataTableColumnHeaderSimple column={column} title="Short List" />, @@ -1482,7 +1482,7 @@ export function RfqVendorTable({ label: "스페어파트", type: "boolean" }, - ...(rfqCode?.startsWith("I") ? [{ + ...(!rfqCode?.startsWith("I") ? [{ id: "shortList", label: "Short List", type: "select", @@ -1577,7 +1577,7 @@ export function RfqVendorTable({ </Button> {/* Short List 확정 버튼 */} - {rfqCode?.startsWith("I") && + {!rfqCode?.startsWith("F") && <Button variant="outline" size="sm" |
