1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
import { pgTable, boolean, integer, timestamp, varchar, uniqueIndex } from "drizzle-orm/pg-core";
import { sql } from 'drizzle-orm';
import { createInsertSchema, createSelectSchema } from "drizzle-zod";
// Vendor Pool 테이블
// 자재그룹코드 + 벤더 복합키 형태로 관리되는 테이블
export const vendorPool = pgTable("vendor_pool", {
// 기본 식별자
id: integer("id").primaryKey().generatedAlwaysAsIdentity(),
// 기본 정보
constructionSector: varchar("construction_sector", { length: 10 }).notNull(), // 조선/해양
htDivision: varchar("ht_division", { length: 10 }).notNull(), // H 또는 T 또는 공통
// 설계 정보
discipline: varchar("discipline", { length: 50 }), // 설계공종 (ARCHITECTURE 등)
equipBulkDivision: varchar("equip_bulk_division", { length: 1 }), // E 또는 B
// 패키지 정보
// 삭제! packageCode: varchar("package_code", { length: 50 }), // 패키지 코드
// 삭제! packageName: varchar("package_name", { length: 100 }), // 패키지 명
// 자재그룹 정보
materialGroupCode: varchar("material_group_code", { length: 50 }), // 자재그룹 코드
materialGroupName: varchar("material_group_name", { length: 100 }), // 자재그룹 명
// 자재 관련 정보
// 삭제! smCode: varchar("sm_code", { length: 50 }),
similarMaterialNamePurchase: varchar("similar_material_name_purchase", { length: 100 }), // 유사자재명 (구매)
// 삭제! similarMaterialNameOther: varchar("similar_material_name_other", { length: 100 }), // 유사자재명 (구매 외)
// 협력업체 정보
vendorCode: varchar("vendor_code", { length: 50 }), // 협력업체 코드
vendorName: varchar("vendor_name", { length: 100 }), // 협력업체 명
// 사업 및 인증 정보
taxId: varchar("tax_id", { length: 50 }), // 사업자번호
faTarget: boolean("fa_target").default(false), // FA대상
faStatus: varchar("fa_status", { length: 50 }), // FA현황
// faRemark: varchar("fa_remark", { length: 200 }), // FA상세
tier: varchar("tier", { length: 20 }), // 등급
// 삭제! isAgent: boolean("is_agent").default(false), // Agent 여부
// 계약 정보
// 삭제! contractSignerCode: varchar("contract_signer_code", { length: 50 }), // 계약서명주체 코드
// 삭제! contractSignerName: varchar("contract_signer_name", { length: 100 }), // 계약서명주체 명
// 위치 정보
headquarterLocation: varchar("headquarter_location", { length: 50 }), // 본사 위치 (국가)
manufacturingLocation: varchar("manufacturing_location", { length: 50 }), // 제작/선적지 (국가)
// AVL 관련 정보
avlVendorName: varchar("avl_vendor_name", { length: 100 }), // AVL 등재업체명
similarVendorName: varchar("similar_vendor_name", { length: 100 }), // 유사업체명(기술영업)
// 삭제! hasAvl: boolean("has_avl").default(false), // AVL 존재여부
// 상태 정보
isBlacklist: boolean("is_blacklist").default(false), // Blacklist
isBcc: boolean("is_bcc").default(false), // BCC
purchaseOpinion: varchar("purchase_opinion", { length: 500 }), // 구매의견
// AVL 적용 선종(조선)
// 삭제! shipTypeCommon: boolean("ship_type_common").default(false), // 공통
// 삭제! shipTypeAmax: boolean("ship_type_amax").default(false), // A-max
// 삭제! shipTypeSmax: boolean("ship_type_smax").default(false), // S-max
// 삭제! shipTypeVlcc: boolean("ship_type_vlcc").default(false), // VLCC
// 삭제! shipTypeLngc: boolean("ship_type_lngc").default(false), // LNGC
// 삭제! shipTypeCont: boolean("ship_type_cont").default(false), // CONT
// AVL 적용 선종(해양)
// 삭제! offshoreTypeCommon: boolean("offshore_type_common").default(false), // 공통
// 삭제! offshoreTypeFpso: boolean("offshore_type_fpso").default(false), // FPSO
// 삭제! offshoreTypeFlng: boolean("offshore_type_flng").default(false), // FLNG
// 삭제! offshoreTypeFpu: boolean("offshore_type_fpu").default(false), // FPU
// 삭제! offshoreTypePlatform: boolean("offshore_type_platform").default(false), // Platform
// 삭제! offshoreTypeWtiv: boolean("offshore_type_wtiv").default(false), // WTIV
// 삭제! offshoreTypeGom: boolean("offshore_type_gom").default(false), // GOM
// eVCP 미등록 정보
// 삭제! picName: varchar("pic_name", { length: 50 }), // PIC(담당자)
// 삭제! picEmail: varchar("pic_email", { length: 100 }), // PIC(E-mail)
// 삭제! picPhone: varchar("pic_phone", { length: 20 }), // PIC(Phone)
// 삭제! agentName: varchar("agent_name", { length: 50 }), // Agent(담당자)
// 삭제! agentEmail: varchar("agent_email", { length: 100 }), // Agent(E-mail)
// 삭제! agentPhone: varchar("agent_phone", { length: 20 }), // Agent(Phone)
// 업체 실적 현황
recentQuoteDate: varchar("recent_quote_date", { length: 10 }), // 최근견적일 (YYYY-MM-DD)
recentQuoteNumber: varchar("recent_quote_number", { length: 50 }), // 최근견적번호
recentOrderDate: varchar("recent_order_date", { length: 10 }), // 최근발주일 (YYYY-MM-DD)
recentOrderNumber: varchar("recent_order_number", { length: 50 }), // 최근발주번호
// 업데이트 히스토리
registrationDate: timestamp("registration_date").defaultNow(), // 등재일
registrant: varchar("registrant", { length: 50 }), // 등재자
lastModifiedDate: timestamp("last_modified_date").defaultNow(), // 최종변경일
lastModifier: varchar("last_modifier", { length: 50 }), // 최종변경자
}, (table) => ({
// 새로운 unique 제약조건: 공사부문 + H/T + 설계공종 + 자재그룹코드 + 협력업체명
uniqueVendorPoolCombination: uniqueIndex("unique_vendor_pool_combination")
.on(table.constructionSector, table.htDivision, table.discipline, table.materialGroupCode, table.vendorName)
.where(sql`${table.discipline} IS NOT NULL AND ${table.materialGroupCode} IS NOT NULL AND ${table.vendorName} IS NOT NULL`)
}));
// 복합키 인덱스 (자재그룹코드 + 벤더코드)
// 구매 의도상은 복합키가 맞는 것 같은데, 요구사항 불명확하므로 별도 제약조건 없이 개발 후 요구 나오면 수정
// Zod 스키마 생성
export const insertVendorPoolSchema = createInsertSchema(vendorPool);
export const selectVendorPoolSchema = createSelectSchema(vendorPool);
// 타입 추론
export type VendorPool = typeof vendorPool.$inferSelect;
export type NewVendorPool = typeof vendorPool.$inferInsert;
|