summaryrefslogtreecommitdiff
path: root/lib/vendor-pool/enrichment-service.ts
diff options
context:
space:
mode:
Diffstat (limited to 'lib/vendor-pool/enrichment-service.ts')
-rw-r--r--lib/vendor-pool/enrichment-service.ts140
1 files changed, 140 insertions, 0 deletions
diff --git a/lib/vendor-pool/enrichment-service.ts b/lib/vendor-pool/enrichment-service.ts
new file mode 100644
index 00000000..88694227
--- /dev/null
+++ b/lib/vendor-pool/enrichment-service.ts
@@ -0,0 +1,140 @@
+"use server";
+
+import { getDisciplineCodeByCode } from "@/components/common/discipline/discipline-service";
+import { getMaterialGroupByCode } from "@/lib/material/material-group-service";
+import { getVendorByCode } from "@/components/common/vendor/vendor-service";
+import { debugLog, debugWarn, debugSuccess } from "@/lib/debug-utils";
+
+/**
+ * 엑셀에서 가져온 벤더풀 데이터를 enrichment (자동완성)
+ * 코드 필드를 기반으로 나머지 데이터를 자동으로 채웁니다.
+ */
+export interface VendorPoolEnrichmentInput {
+ // 설계기능 관련
+ designCategoryCode?: string;
+ designCategory?: string;
+
+ // 자재그룹 관련
+ materialGroupCode?: string;
+ materialGroupName?: string;
+
+ // 협력업체 관련
+ vendorCode?: string;
+ vendorName?: string;
+
+ // 계약서명주체 관련
+ contractSignerCode?: string;
+ contractSignerName?: string;
+}
+
+export interface VendorPoolEnrichmentResult {
+ enriched: VendorPoolEnrichmentInput;
+ enrichedFields: string[]; // 자동완성된 필드 목록
+ warnings: string[]; // 경고 메시지 (코드는 있지만 데이터를 찾을 수 없는 경우)
+}
+
+/**
+ * 벤더풀 데이터 enrichment
+ */
+export async function enrichVendorPoolData(
+ data: VendorPoolEnrichmentInput
+): Promise<VendorPoolEnrichmentResult> {
+ const enriched = { ...data };
+ const enrichedFields: string[] = [];
+ const warnings: string[] = [];
+
+ debugLog('[Enrichment] 시작:', {
+ designCategoryCode: data.designCategoryCode,
+ materialGroupCode: data.materialGroupCode,
+ vendorCode: data.vendorCode,
+ contractSignerCode: data.contractSignerCode,
+ });
+
+ // 1. 설계기능코드 → 설계기능명 자동완성
+ if (data.designCategoryCode && !data.designCategory) {
+ debugLog('[Enrichment] 설계기능명 조회 시도:', data.designCategoryCode);
+ const discipline = await getDisciplineCodeByCode(data.designCategoryCode);
+ if (discipline) {
+ enriched.designCategory = discipline.USR_DF_CHAR_18;
+ enrichedFields.push('designCategory');
+ debugSuccess('[Enrichment] 설계기능명 자동완성:', {
+ code: data.designCategoryCode,
+ name: discipline.USR_DF_CHAR_18,
+ });
+ } else {
+ debugWarn('[Enrichment] 설계기능코드를 찾을 수 없음:', data.designCategoryCode);
+ warnings.push(
+ `설계기능코드 '${data.designCategoryCode}'에 해당하는 설계기능명을 찾을 수 없습니다.`
+ );
+ }
+ }
+
+ // 2. 자재그룹코드 → 자재그룹명 자동완성
+ if (data.materialGroupCode && !data.materialGroupName) {
+ debugLog('[Enrichment] 자재그룹명 조회 시도:', data.materialGroupCode);
+ const materialGroup = await getMaterialGroupByCode(data.materialGroupCode);
+ if (materialGroup) {
+ enriched.materialGroupName = materialGroup.materialGroupDescription;
+ enrichedFields.push('materialGroupName');
+ debugSuccess('[Enrichment] 자재그룹명 자동완성:', {
+ code: data.materialGroupCode,
+ name: materialGroup.materialGroupDescription,
+ });
+ } else {
+ debugWarn('[Enrichment] 자재그룹코드를 찾을 수 없음:', data.materialGroupCode);
+ warnings.push(
+ `자재그룹코드 '${data.materialGroupCode}'에 해당하는 자재그룹명을 찾을 수 없습니다.`
+ );
+ }
+ }
+
+ // 3. 협력업체코드 → 협력업체명 자동완성
+ if (data.vendorCode && !data.vendorName) {
+ debugLog('[Enrichment] 협력업체명 조회 시도:', data.vendorCode);
+ const vendor = await getVendorByCode(data.vendorCode);
+ if (vendor) {
+ enriched.vendorName = vendor.vendorName;
+ enrichedFields.push('vendorName');
+ debugSuccess('[Enrichment] 협력업체명 자동완성:', {
+ code: data.vendorCode,
+ name: vendor.vendorName,
+ });
+ } else {
+ debugWarn('[Enrichment] 협력업체코드를 찾을 수 없음:', data.vendorCode);
+ warnings.push(
+ `협력업체코드 '${data.vendorCode}'에 해당하는 협력업체명을 찾을 수 없습니다.`
+ );
+ }
+ }
+
+ // 4. 계약서명주체코드 → 계약서명주체명 자동완성
+ if (data.contractSignerCode && !data.contractSignerName) {
+ debugLog('[Enrichment] 계약서명주체명 조회 시도:', data.contractSignerCode);
+ const contractSigner = await getVendorByCode(data.contractSignerCode);
+ if (contractSigner) {
+ enriched.contractSignerName = contractSigner.vendorName;
+ enrichedFields.push('contractSignerName');
+ debugSuccess('[Enrichment] 계약서명주체명 자동완성:', {
+ code: data.contractSignerCode,
+ name: contractSigner.vendorName,
+ });
+ } else {
+ debugWarn('[Enrichment] 계약서명주체코드를 찾을 수 없음:', data.contractSignerCode);
+ warnings.push(
+ `계약서명주체코드 '${data.contractSignerCode}'에 해당하는 계약서명주체명을 찾을 수 없습니다.`
+ );
+ }
+ }
+
+ debugSuccess('[Enrichment] 완료:', {
+ enrichedFieldsCount: enrichedFields.length,
+ warningsCount: warnings.length,
+ });
+
+ return {
+ enriched,
+ enrichedFields,
+ warnings,
+ };
+}
+