import { boolean, jsonb, text, timestamp, integer, uuid, varchar } from "drizzle-orm/pg-core"; import { knoxSchema } from "./employee"; import { users } from '@/db/schema/users'; /** * 결재 관련 테이블 정의 * * 템플릿 관리 * 결재선 관리 * 결재 로그 관리 (히스토리 관리) * */ // 결재 템플릿 히스토리 export const approvalTemplateHistory = knoxSchema.table('approval_template_history', { id: uuid().primaryKey().defaultRandom(), // 히스토리 아이디 UUID templateId: uuid() .references(() => approvalTemplates.id, { onDelete: 'cascade' }) .notNull(), version: integer().notNull(), // 히스토리 버전 subject: text().notNull(), // 템플릿 제목 content: text().notNull(), // 템플릿 내용 changeDescription: text(), // 변경 사항 설명 changedBy: integer() // 변경자 - eVCP 유저 아이디 기반 참조 .notNull() .references(() => users.id, { onDelete: 'set null' }), createdAt: timestamp().defaultNow().notNull(), // 히스토리는 업데이트 없음. 생성 시점만 기록. }); // 실제 결재 상신 로그 export const approvalLogs = knoxSchema.table("approval_logs", { apInfId: text("ap_inf_id").primaryKey(), // 연계ID (결재 ID로 32자리 고유값) contentsType: text("contents_type").notNull().default("HTML"), // 본문종류 (TEXT, HTML, MIME) sbmDt: text("sbm_dt"), // 상신일시 (YYYYMMDDHHMMSS) sbmLang: text("sbm_lang").notNull().default("ko"), // 상신언어 //System-ID: 연계시스템 ID 생략 (eVCP 고정) notifyOption: text("notify_option").notNull().default("0"), // 통보옵션 (0-3) urgYn: text("urg_yn").notNull().default("N"), // 긴급여부 (Y/N) docSecuType: text("doc_secu_type").notNull().default("PERSONAL"), // 보안문서타입 status: text("status").notNull(), // 결재 상태 (0-미결, 1-진행중, 2-완결, 3-반려, 4-상신취소, 5-전결, 6-후완결) timeZone: text("time_zone").notNull().default("GMT+9"), // 타임존 subject: text("subject").notNull(), // 결재 제목 aplns: jsonb("aplns").notNull(), // approval lines = 결재선 opinion: varchar("opinion", { length: 1000 }), // 상신의견 userId: text("knox_user_id"), // knox 이메일 앞부분의 Id epId: text("ep_id").notNull(), // epId - 녹스 고유키 emailAddress: text("email_address").notNull(), // knox 이메일 주소 content: text("content").notNull(), // 결재 본문 // 상신시 결정, 상세조회에서는 조회 안됨 importantYn: varchar("important_yn", { length: 1 }).default("N"), // 중요여부 (Y/N) // docMngSaveCode: text("doc_mng_save_code").notNull().default("0"), // 문서관리저장코드 isDeleted: boolean("is_deleted").notNull().default(false), createdAt: timestamp("created_at").notNull().defaultNow(), updatedAt: timestamp("updated_at").notNull().defaultNow(), }); // 결재 템플릿 export const approvalTemplates = knoxSchema.table('approval_templates', { id: uuid().primaryKey().defaultRandom(), // 템플릿 아이디 UUID name: text().notNull(), // 템플릿 이름 // slug: text('slug').notNull().unique(), // 템플릿 슬러그는 UUID로 대체하기 subject: text().notNull(), // 템플릿 제목 content: text().notNull(), // 템플릿 내용 description: text(), // 템플릿 설명 category: text(), // 템플릿 카테고리 설명 // 선택된 결재선 참조 (nullable, 결재선은 별도에서 관리) approvalLineId: uuid().references(() => approvalLines.id, { onDelete: 'set null' }), // 메타데이터 createdBy: integer() // 템플릿 생성자 - eVCP 유저 아이디 기반 참조 .notNull() .references(() => users.id, { onDelete: 'set null' }), createdAt: timestamp().defaultNow().notNull(), updatedAt: timestamp().defaultNow().notNull(), }); // 결재선 템플릿 export const approvalLines = knoxSchema.table('approval_lines', { id: uuid().primaryKey().defaultRandom(), // 결재선 아이디 UUID name: text().notNull(), // 결재선 이름 description: text(), // 결재선 설명 category: text(), // 핵심 aplns: jsonb().notNull(), // 결재선 구성 // 메타데이터 createdBy: integer() // 결재선 생성자 - eVCP 유저 아이디 기반 참조 .notNull() .references(() => users.id, { onDelete: 'set null' }), createdAt: timestamp().defaultNow().notNull(), updatedAt: timestamp().defaultNow().notNull(), }); // // 결재 템플릿 변수 export const approvalTemplateVariables = knoxSchema.table('approval_template_variables', { id: uuid().primaryKey().defaultRandom(), // 변수 아이디 UUID approvalTemplateId: uuid() .references(() => approvalTemplates.id, { onDelete: 'cascade' }), variableName: text().notNull(), // 변수 이름 variableType: text().notNull(), // 변수 타입 defaultValue: text(), // 변수 기본값 description: text(), // 변수 설명 // 메타데이터 createdBy: integer() // 변수 생성자 - eVCP 유저 아이디 기반 참조 .notNull() .references(() => users.id, { onDelete: 'set null' }), createdAt: timestamp().defaultNow().notNull(), updatedAt: timestamp().defaultNow().notNull(), }); // 결재 템플릿 카테고리 관리 export const approvalTemplateCategories = knoxSchema.table('approval_template_categories', { id: uuid().primaryKey().defaultRandom(), // 카테고리 아이디 UUID name: text().notNull(), // 카테고리 이름 description: text(), // 카테고리 설명 isActive: boolean().default(true).notNull(), // 활성화 여부 sortOrder: integer().default(0).notNull(), // 정렬 순서 createdBy: integer() // 카테고리 생성자 - eVCP 유저 아이디 기반 참조 .notNull() .references(() => users.id, { onDelete: 'set null' }), createdAt: timestamp().defaultNow().notNull(), updatedAt: timestamp().defaultNow().notNull(), updatedBy: integer() // 카테고리 수정자 - eVCP 유저 아이디 기반 참조 .notNull() .references(() => users.id, { onDelete: 'set null' }), });