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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
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' }),
});
|