diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-07-03 01:59:36 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-07-03 01:59:36 +0000 |
| commit | de4c8a6a6b7c918a7a16fc34423d1143209c295f (patch) | |
| tree | 9fbf0b93e5cbe9c3a8ca18c8bcd4dda5bf9640c5 /lib/tech-vendors/service.ts | |
| parent | deb2d31dba913a3b831523f41b9bf2e286c53af1 (diff) | |
(최겸) 기술영업 벤더 공종 조회 기능 추가
Diffstat (limited to 'lib/tech-vendors/service.ts')
| -rw-r--r-- | lib/tech-vendors/service.ts | 88 |
1 files changed, 55 insertions, 33 deletions
diff --git a/lib/tech-vendors/service.ts b/lib/tech-vendors/service.ts index 5fd5ef02..15e7331b 100644 --- a/lib/tech-vendors/service.ts +++ b/lib/tech-vendors/service.ts @@ -40,6 +40,7 @@ import fs from "fs/promises"; import { randomUUID } from "crypto"; import { sql } from "drizzle-orm"; import { users } from "@/db/schema/users"; +import { decryptWithServerAction } from "@/components/drm/drmUtils"; /* ----------------------------------------------------- 1) 조회 관련 @@ -56,10 +57,14 @@ export async function getTechVendors(input: GetTechVendorsSchema) { try { const offset = (input.page - 1) * input.perPage; - // 1) 고급 필터 + // 1) 고급 필터 (workTypes와 techVendorType 제외 - 별도 처리) + const filteredFilters = input.filters.filter( + filter => filter.id !== "workTypes" && filter.id !== "techVendorType" + ); + const advancedWhere = filterColumns({ table: techVendors, - filters: input.filters, + filters: filteredFilters, joinOperator: input.joinOperator, }); @@ -108,8 +113,47 @@ export async function getTechVendors(input: GetTechVendorsSchema) { : undefined ); - // 실제 사용될 where (vendorType 필터링 추가) - const where = and(finalWhere, vendorTypeWhere); + // TechVendorType 필터링 로직 추가 (고급 필터에서) + let techVendorTypeWhere; + const techVendorTypeFilters = input.filters.filter(filter => filter.id === "techVendorType"); + if (techVendorTypeFilters.length > 0) { + const typeFilter = techVendorTypeFilters[0]; + if (Array.isArray(typeFilter.value) && typeFilter.value.length > 0) { + // 각 타입에 대해 LIKE 조건으로 OR 연결 + const typeConditions = typeFilter.value.map(type => + ilike(techVendors.techVendorType, `%${type}%`) + ); + techVendorTypeWhere = or(...typeConditions); + } + } + + // WorkTypes 필터링 로직 추가 + let workTypesWhere; + const workTypesFilters = input.filters.filter(filter => filter.id === "workTypes"); + if (workTypesFilters.length > 0) { + const workTypeFilter = workTypesFilters[0]; + if (Array.isArray(workTypeFilter.value) && workTypeFilter.value.length > 0) { + // workTypes에 해당하는 벤더 ID들을 서브쿼리로 찾음 + const vendorIdsWithWorkTypes = db + .selectDistinct({ vendorId: techVendorPossibleItems.vendorId }) + .from(techVendorPossibleItems) + .leftJoin(itemShipbuilding, eq(techVendorPossibleItems.itemCode, itemShipbuilding.itemCode)) + .leftJoin(itemOffshoreTop, eq(techVendorPossibleItems.itemCode, itemOffshoreTop.itemCode)) + .leftJoin(itemOffshoreHull, eq(techVendorPossibleItems.itemCode, itemOffshoreHull.itemCode)) + .where( + or( + inArray(itemShipbuilding.workType, workTypeFilter.value), + inArray(itemOffshoreTop.workType, workTypeFilter.value), + inArray(itemOffshoreHull.workType, workTypeFilter.value) + ) + ); + + workTypesWhere = inArray(techVendors.id, vendorIdsWithWorkTypes); + } + } + + // 실제 사용될 where (vendorType, techVendorType, workTypes 필터링 추가) + const where = and(finalWhere, vendorTypeWhere, techVendorTypeWhere, workTypesWhere); // 정렬 const orderBy = @@ -160,6 +204,7 @@ export async function getTechVendorStatusCounts() { async () => { try { const initial: Record<TechVendor["status"], number> = { + "PENDING_REVIEW": 0, "ACTIVE": 0, "INACTIVE": 0, "BLACKLISTED": 0, @@ -231,8 +276,10 @@ async function storeTechVendorFiles( for (const file of files) { // Convert file to buffer - const ab = await file.arrayBuffer(); - const buffer = Buffer.from(ab); + // DRM 복호화 시도 및 버퍼 변환 + const decryptedData = await decryptWithServerAction(file); + const buffer = Buffer.from(decryptedData); + // Generate a unique filename const uniqueName = `${randomUUID()}-${file.name}`; @@ -518,8 +565,7 @@ export async function getTechVendorItems(input: GetTechVendorItemsSchema, id: nu if (input.search) { const s = `%${input.search}%`; globalWhere = or( - ilike(techVendorItemsView.itemCode, s), - ilike(techVendorItemsView.itemName, s) + ilike(techVendorItemsView.itemCode, s) ); } @@ -863,7 +909,7 @@ export async function getVendorItemsByType(vendorId: number, vendorType: string) } } -export async function createTechVendorItem(input: CreateTechVendorItemSchema & { itemName: string }) { +export async function createTechVendorItem(input: CreateTechVendorItemSchema) { unstable_noStore(); try { // DB에 이미 존재하는지 확인 @@ -889,7 +935,6 @@ export async function createTechVendorItem(input: CreateTechVendorItemSchema & { .values({ vendorId: input.vendorId, itemCode: input.itemCode, - itemName: input.itemName || "기술영업", }) .returning(); return newItem; @@ -1009,14 +1054,12 @@ export async function exportTechVendorItems(vendorId: number) { .select({ id: techVendorItemsView.vendorItemId, vendorId: techVendorItemsView.vendorId, - itemName: techVendorItemsView.itemName, itemCode: techVendorItemsView.itemCode, createdAt: techVendorItemsView.createdAt, updatedAt: techVendorItemsView.updatedAt, }) .from(techVendorItemsView) .where(eq(techVendorItemsView.vendorId, vendorId)) - .orderBy(techVendorItemsView.itemName); return items; } catch (err) { @@ -1308,27 +1351,6 @@ export async function importTechVendorsFromExcel( } } - // // 3. 아이템 등록 - // if (vendor.items) { - // console.log("아이템 등록 시도:", vendor.items); - // const itemCodes = vendor.items.split(',').map(code => code.trim()); - - // for (const itemCode of itemCodes) { - // // 아이템 정보 조회 - // const [item] = await tx.select().from(items).where(eq(items.itemCode, itemCode)); - // if (item && item.itemCode && item.itemName) { - // await tx.insert(techVendorPossibleItems).values({ - // vendorId: newVendor.id, - // itemCode: item.itemCode, - // itemName: item.itemName, - // }); - // console.log("아이템 등록 성공:", itemCode); - // } else { - // console.log("아이템을 찾을 수 없음:", itemCode); - // } - // } - // } - createdVendors.push(newVendor); console.log("벤더 처리 완료:", vendor.vendorName); } catch (error) { |
