houxiao
2017-08-17 51147a836955ed6ff7c111bbce89e244f0c3f27f
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/*
Navicat MySQL Data Transfer
 
Source Server         : 192.168.1.51
Source Server Version : 50714
Source Host           : 192.168.1.51:3306
Source Database       : face_discern
 
Target Server Type    : MYSQL
Target Server Version : 50714
File Encoding         : 65001
 
Date: 2017-03-16 10:54:29
*/
 
SET FOREIGN_KEY_CHECKS=0;
 
-- ----------------------------
-- Table structure for calling
-- ----------------------------
DROP TABLE IF EXISTS `calling`;
CREATE TABLE `calling` (
  `id` int(10) NOT NULL AUTO_INCREMENT COMMENT '签到事件主键',
  `call_dt` datetime DEFAULT NULL COMMENT '呼叫时间',
  `caller_person_id` int(10) DEFAULT NULL COMMENT '呼叫人员主键',
  `callee_person_id` int(10) DEFAULT NULL COMMENT '被呼叫人员主键',
  `place_id` int(10) DEFAULT NULL COMMENT '呼叫发生所在设备(地点)',
  PRIMARY KEY (`id`),
  KEY `caller_person_id` (`caller_person_id`),
  KEY `callee_person_id` (`callee_person_id`),
  KEY `calling_ibfk_3` (`place_id`),
  CONSTRAINT `calling_ibfk_1` FOREIGN KEY (`caller_person_id`) REFERENCES `person` (`id`),
  CONSTRAINT `calling_ibfk_2` FOREIGN KEY (`callee_person_id`) REFERENCES `person` (`id`),
  CONSTRAINT `calling_ibfk_3` FOREIGN KEY (`place_id`) REFERENCES `place` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
-- ----------------------------
-- Table structure for checking
-- ----------------------------
DROP TABLE IF EXISTS `checking`;
CREATE TABLE `checking` (
  `id` int(10) NOT NULL AUTO_INCREMENT COMMENT '签到事件主键',
  `status_id` tinyint(2) DEFAULT NULL COMMENT '签到状态',
  `status_dt` datetime DEFAULT NULL COMMENT '签到时间',
  `person_id` int(10) DEFAULT NULL COMMENT '人员主键',
  `place_id` int(10) DEFAULT NULL COMMENT '签到位置',
  PRIMARY KEY (`id`),
  KEY `person_id` (`person_id`),
  KEY `place_id` (`place_id`),
  CONSTRAINT `checking_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `person` (`id`),
  CONSTRAINT `checking_ibfk_2` FOREIGN KEY (`place_id`) REFERENCES `place` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
-- ----------------------------
-- Table structure for checking_company
-- ----------------------------
DROP TABLE IF EXISTS `checking_company`;
CREATE TABLE `checking_company` (
  `person_id` int(10) NOT NULL COMMENT '人员主键',
  `company_id` int(10) NOT NULL COMMENT '公司主键',
  PRIMARY KEY (`person_id`,`company_id`),
  KEY `company_id` (`company_id`),
  CONSTRAINT `checking_company_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `person` (`id`),
  CONSTRAINT `checking_company_ibfk_2` FOREIGN KEY (`company_id`) REFERENCES `company` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
-- ----------------------------
-- Table structure for company
-- ----------------------------
DROP TABLE IF EXISTS `company`;
CREATE TABLE `company` (
  `id` int(10) NOT NULL AUTO_INCREMENT COMMENT '公司主键',
  `name` varchar(50) DEFAULT NULL COMMENT '公司名称',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
-- ----------------------------
-- Table structure for department
-- ----------------------------
DROP TABLE IF EXISTS `department`;
CREATE TABLE `department` (
  `id` int(10) NOT NULL AUTO_INCREMENT COMMENT '部门主键',
  `label` varchar(40) DEFAULT NULL COMMENT '部门名称',
  `label_spell` char(20) DEFAULT NULL COMMENT '部门首字母',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
-- ----------------------------
-- Table structure for face_image
-- ----------------------------
DROP TABLE IF EXISTS `face_image`;
CREATE TABLE `face_image` (
  `face_id` int(10) NOT NULL COMMENT '员工图片主键',
  `register_company_id` int(10) NOT NULL COMMENT '注册公司主键',
  `person_id` int(10) DEFAULT NULL COMMENT '人员主键',
  `image_path` varchar(255) DEFAULT NULL COMMENT '图片地址',
  `image_type_id` int(10) DEFAULT NULL COMMENT '图片类型',
  PRIMARY KEY (`face_id`,`register_company_id`),
  KEY `register_company_id` (`register_company_id`),
  KEY `person_id` (`person_id`),
  CONSTRAINT `face_image_ibfk_1` FOREIGN KEY (`register_company_id`) REFERENCES `company` (`id`),
  CONSTRAINT `face_image_ibfk_2` FOREIGN KEY (`person_id`) REFERENCES `person` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
-- ----------------------------
-- Table structure for image
-- ----------------------------
DROP TABLE IF EXISTS `image`;
CREATE TABLE `image` (
  `person_id` int(10) DEFAULT NULL COMMENT '人员主键',
  `image_type` int(10) DEFAULT NULL COMMENT '图片类型',
  `image_path` varchar(255) DEFAULT NULL COMMENT '图片地址',
  KEY `person_id` (`person_id`),
  CONSTRAINT `image_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `person` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
-- ----------------------------
-- Table structure for person
-- ----------------------------
DROP TABLE IF EXISTS `person`;
CREATE TABLE `person` (
  `id` int(10) NOT NULL AUTO_INCREMENT COMMENT '人员主键',
  `name` varchar(40) DEFAULT NULL COMMENT '人员名字',
  `name_spell` char(2) DEFAULT NULL COMMENT '人员名首字母',
  `gender` tinyint(1) DEFAULT NULL COMMENT '性别',
  `country` char(3) DEFAULT NULL COMMENT '国籍',
  `province` char(20) DEFAULT NULL COMMENT '省',
  `city` char(20) DEFAULT NULL COMMENT '市',
  `birthday` date DEFAULT NULL COMMENT '出生日期',
  `phone` char(12) DEFAULT NULL COMMENT '座机电话',
  `mobile_phone` char(15) DEFAULT NULL COMMENT '移动电话',
  `identity_type` int(10) DEFAULT NULL COMMENT '证件类型',
  `identify` varchar(100) DEFAULT NULL COMMENT '证件编号',
  `company_id` int(10) DEFAULT NULL COMMENT '公司主键',
  `department_id` int(10) DEFAULT NULL COMMENT '部门主键',
  `post_id` int(10) DEFAULT NULL COMMENT '职务主键',
  `remark` varchar(255) DEFAULT NULL COMMENT '人员备注消息',
  `warning` tinyint(1) DEFAULT NULL COMMENT '危险人员警告消息',
  PRIMARY KEY (`id`),
  KEY `company_id` (`company_id`),
  KEY `post_id` (`post_id`),
  KEY `department_id` (`department_id`),
  CONSTRAINT `person_ibfk_1` FOREIGN KEY (`company_id`) REFERENCES `company` (`id`),
  CONSTRAINT `person_ibfk_3` FOREIGN KEY (`post_id`) REFERENCES `post` (`id`),
  CONSTRAINT `person_ibfk_4` FOREIGN KEY (`department_id`) REFERENCES `department` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
-- ----------------------------
-- Table structure for person_ext
-- ----------------------------
DROP TABLE IF EXISTS `person_ext`;
CREATE TABLE `person_ext` (
  `person_id` int(10) DEFAULT NULL COMMENT '人员主键',
  KEY `person_id` (`person_id`),
  CONSTRAINT `person_ext_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `person` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
-- ----------------------------
-- Table structure for place
-- ----------------------------
DROP TABLE IF EXISTS `place`;
CREATE TABLE `place` (
  `id` int(10) NOT NULL AUTO_INCREMENT COMMENT '设备主键',
  `company_id` int(10) DEFAULT NULL COMMENT '公司主键',
  `label` varchar(40) DEFAULT NULL COMMENT '设备地点',
  `authorization_id` varchar(100) NOT NULL COMMENT '设备授权码',
  PRIMARY KEY (`id`),
  KEY `company_id` (`company_id`),
  CONSTRAINT `place_ibfk_1` FOREIGN KEY (`company_id`) REFERENCES `company` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
-- ----------------------------
-- Table structure for post
-- ----------------------------
DROP TABLE IF EXISTS `post`;
CREATE TABLE `post` (
  `id` int(10) NOT NULL AUTO_INCREMENT COMMENT '职位主键',
  `label` varchar(40) DEFAULT NULL COMMENT '职位名称',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
-- ----------------------------
-- Table structure for visit
-- ----------------------------
DROP TABLE IF EXISTS `visit`;
CREATE TABLE `visit` (
  `id` int(10) NOT NULL AUTO_INCREMENT COMMENT '访问事件主键',
  `visitor_person_id` int(10) DEFAULT NULL COMMENT '访问人员主键',
  `visitee_person_id` int(10) DEFAULT NULL COMMENT '被访问人员主键',
  `matter_id` int(10) DEFAULT NULL COMMENT '访问事由主键',
  `remark` varchar(255) DEFAULT NULL COMMENT '访问备注',
  `last_status` int(10) DEFAULT NULL COMMENT '最新的访问状态',
  `start_time` datetime DEFAULT NULL COMMENT '来访时间',
  `last_time` datetime DEFAULT NULL COMMENT '签离时间',
  `visitor_company_id` int(10) DEFAULT NULL,
  `visitee_company_id` int(10) DEFAULT NULL,
  `visitor_type_id` int(10) DEFAULT NULL COMMENT '访客类型',
  `warning` tinyint(1) DEFAULT NULL COMMENT '当前访问的警告状态',
  PRIMARY KEY (`id`),
  KEY `visitor_person_id` (`visitor_person_id`),
  KEY `visitee_person_id` (`visitee_person_id`),
  KEY `matter_id` (`matter_id`),
  KEY `visit_ibfk_4` (`visitor_type_id`),
  KEY `visitor_company_id` (`visitor_company_id`),
  KEY `visitee_company_id` (`visitee_company_id`),
  CONSTRAINT `visit_ibfk_1` FOREIGN KEY (`visitor_person_id`) REFERENCES `person` (`id`),
  CONSTRAINT `visit_ibfk_2` FOREIGN KEY (`visitee_person_id`) REFERENCES `person` (`id`),
  CONSTRAINT `visit_ibfk_3` FOREIGN KEY (`matter_id`) REFERENCES `visit_matter` (`id`),
  CONSTRAINT `visit_ibfk_4` FOREIGN KEY (`visitor_type_id`) REFERENCES `visitor_type` (`id`),
  CONSTRAINT `visit_ibfk_5` FOREIGN KEY (`visitor_company_id`) REFERENCES `company` (`id`),
  CONSTRAINT `visit_ibfk_6` FOREIGN KEY (`visitee_company_id`) REFERENCES `company` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
-- ----------------------------
-- Table structure for visiting
-- ----------------------------
DROP TABLE IF EXISTS `visiting`;
CREATE TABLE `visiting` (
  `id` int(10) NOT NULL AUTO_INCREMENT COMMENT '访问事件流水id',
  `visit_id` int(10) DEFAULT NULL COMMENT '访问事件id',
  `status_id` tinyint(2) DEFAULT NULL COMMENT '当前访问状态',
  `status_dt` datetime DEFAULT NULL COMMENT '更新状态时间',
  `place_id` int(10) DEFAULT NULL COMMENT '设备位置主键',
  PRIMARY KEY (`id`),
  KEY `visit_id` (`visit_id`),
  KEY `place_id` (`place_id`),
  CONSTRAINT `visiting_ibfk_1` FOREIGN KEY (`visit_id`) REFERENCES `visit` (`id`),
  CONSTRAINT `visiting_ibfk_2` FOREIGN KEY (`place_id`) REFERENCES `place` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
-- ----------------------------
-- Table structure for visitor_type
-- ----------------------------
DROP TABLE IF EXISTS `visitor_type`;
CREATE TABLE `visitor_type` (
  `id` int(10) NOT NULL AUTO_INCREMENT COMMENT '访客类型主键',
  `label` varchar(32) DEFAULT NULL COMMENT '访客类型',
  `register_company_id` int(10) DEFAULT NULL COMMENT '注册公司主键',
  `available` tinyint(1) DEFAULT NULL COMMENT '是否是可用',
  PRIMARY KEY (`id`),
  KEY `register_company_id` (`register_company_id`),
  CONSTRAINT `visitor_type_ibfk_1` FOREIGN KEY (`register_company_id`) REFERENCES `company` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
-- ----------------------------
-- Table structure for visit_matter
-- ----------------------------
DROP TABLE IF EXISTS `visit_matter`;
CREATE TABLE `visit_matter` (
  `id` int(10) NOT NULL AUTO_INCREMENT COMMENT '访问事由主键',
  `company_id` int(10) DEFAULT NULL COMMENT '公司主键',
  `label` varchar(40) NOT NULL COMMENT '访问事由',
  `available` tinyint(1) DEFAULT NULL COMMENT '是否是可用',
  PRIMARY KEY (`id`),
  KEY `company_id` (`company_id`),
  CONSTRAINT `visit_matter_ibfk_1` FOREIGN KEY (`company_id`) REFERENCES `company` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
-- ----------------------------
-- Table structure for visit_person_type
-- ----------------------------
DROP TABLE IF EXISTS `visit_person_type`;
CREATE TABLE `visit_person_type` (
  `register_company_id` int(10) NOT NULL,
  `person_id` int(10) NOT NULL,
  `visitor_type_id` int(10) NOT NULL,
  PRIMARY KEY (`register_company_id`,`person_id`,`visitor_type_id`),
  KEY `person_id` (`person_id`) USING BTREE,
  KEY `visitor_type_id` (`visitor_type_id`) USING BTREE,
  CONSTRAINT `visit_person_type_ibfk_1` FOREIGN KEY (`register_company_id`) REFERENCES `company` (`id`),
  CONSTRAINT `visit_person_type_ibfk_2` FOREIGN KEY (`person_id`) REFERENCES `person` (`id`),
  CONSTRAINT `visit_person_type_ibfk_3` FOREIGN KEY (`visitor_type_id`) REFERENCES `visitor_type` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
-- ----------------------------
-- Table structure for visit_stat
-- ----------------------------
DROP TABLE IF EXISTS `visit_stat`;
CREATE TABLE `visit_stat` (
  `person_id` int(10) NOT NULL COMMENT '人员主键',
  `register_company_id` int(10) NOT NULL COMMENT '注册公司主键',
  `total_count` int(10) DEFAULT NULL COMMENT '来访公司次数',
  PRIMARY KEY (`person_id`,`register_company_id`),
  KEY `person_id` (`person_id`),
  KEY `register_company_id` (`register_company_id`),
  CONSTRAINT `visit_stat_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `person` (`id`),
  CONSTRAINT `visit_stat_ibfk_2` FOREIGN KEY (`register_company_id`) REFERENCES `company` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;