mm_os 2.4.0 → 2.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,9 @@
1
+ var fs = require("fs");
1
2
  var sql = $.mysql_admin('sys');
2
3
  var dbs = sql.db();
3
4
 
4
- /**
5
- * 服务端类
6
- */
7
5
  class Server {
8
-
6
+
9
7
  }
10
8
 
11
9
  /**
@@ -18,8 +16,8 @@ class Server {
18
16
  * @param {String} idcard 用户身份证号
19
17
  * @returns {Object} 返回用户对象
20
18
  */
21
- Server.prototype.get_user_sub = async function(table, project_id, customId, name, phone, idcard) {
22
- var db1 = dbs.new("face_" + table, "user_id");
19
+ Server.prototype.get_enter_sub = async function(table, project_id, customId, name, phone, idcard) {
20
+ var db1 = dbs.new("face_" + table, table == "enter" ? "user_id" : "visitor_id");
23
21
  var query = {
24
22
  project_id
25
23
  }
@@ -58,15 +56,15 @@ Server.prototype.get_user_sub = async function(table, project_id, customId, name
58
56
  * @param {String} idcard 用户身份证号
59
57
  * @returns {Object} 返回用户对象和用户类型
60
58
  */
61
- Server.prototype.get_user = async function(project_id, customId, name, phone, idcard) {
59
+ Server.prototype.get_enter = async function(project_id, customId, name, phone, idcard) {
62
60
  // 默认为 1内部人员类型
63
61
  var user_type = 1;
64
- var enter = await this.get_user_sub("enter", project_id, customId, name, phone, idcard);
62
+ var enter = await this.get_enter_sub("enter", project_id, customId, name, phone, idcard);
65
63
 
66
64
  if (!enter) {
67
65
  // 2为访客
68
66
  user_type = 2;
69
- enter = await this.get_user_sub("visitor", project_id, customId, name, phone, idcard);
67
+ enter = await this.get_enter_sub("visitor", project_id, customId, name, phone, idcard);
70
68
  }
71
69
 
72
70
  if (enter) {
@@ -92,7 +90,7 @@ Server.prototype.get_user = async function(project_id, customId, name, phone, id
92
90
  qy.project_id = enter.project_id;
93
91
  }
94
92
  await db3.set(qy, by);
95
- enter = Object.assign({}, enter, by);
93
+ enter = await db3.getObj(qy);
96
94
  }
97
95
  } else {
98
96
  // 3为外部人员(非平台成员)
@@ -100,7 +98,7 @@ Server.prototype.get_user = async function(project_id, customId, name, phone, id
100
98
  enter = {
101
99
  department_id: 0,
102
100
  team_id: 0,
103
- name: "",
101
+ name,
104
102
  job: "",
105
103
  phone,
106
104
  idcard
@@ -108,7 +106,7 @@ Server.prototype.get_user = async function(project_id, customId, name, phone, id
108
106
  }
109
107
  return {
110
108
  user_type,
111
- user: Object.assign({}, enter)
109
+ enter
112
110
  }
113
111
  }
114
112
 
@@ -146,13 +144,15 @@ Server.prototype.exec_log = async function(clientid, log) {
146
144
  type,
147
145
  record_type,
148
146
  person_type,
149
- action
147
+ action,
148
+ avatar,
149
+ nfc
150
150
  } = log;
151
151
  // 通过项目id和用户唯一标识获取用户
152
152
  var {
153
- user,
153
+ enter,
154
154
  user_type
155
- } = await this.get_user(project_id, customId, name, phone, idcard);
155
+ } = await this.get_enter(project_id, customId, name, phone, idcard);
156
156
 
157
157
  // 如果不记录外部人员,则终止,不保存记录
158
158
  if (!project.save_outboard && user_type === 3) {
@@ -160,17 +160,16 @@ Server.prototype.exec_log = async function(clientid, log) {
160
160
  }
161
161
 
162
162
  log = {
163
- project_id: 0,
163
+ project_id,
164
164
  user_id: 0,
165
165
  name: "",
166
166
  // 1内部人员|2访客|3非系统名单
167
167
  user_type,
168
- clientid: "",
169
168
  direction: "",
170
- // 1人脸验证|2远程开门|3扫码开门|4刷卡验证
169
+ // 1刷脸验证|2远程开门|3扫码开门|4刷卡验证
171
170
  type,
172
171
  record_type,
173
- action: action || "人脸验证",
172
+ action: action || "刷脸验证",
174
173
  // 1白名单|2黑名单
175
174
  person_type,
176
175
  department_id: 0,
@@ -183,10 +182,17 @@ Server.prototype.exec_log = async function(clientid, log) {
183
182
  time: ""
184
183
  }
185
184
 
186
- $.push(log, user);
185
+ $.push(log, enter);
186
+ log.avatar = avatar;
187
187
  log.time = time;
188
188
  log.clientid = clientid;
189
189
  log.direction = device.direction;
190
+ if (nfc && !log.nfc) {
191
+ log.nfc = nfc;
192
+ }
193
+ if (log.person_type === 0) {
194
+ log.person_type = enter.state == 4 ? 2 : 1;
195
+ }
190
196
  return this.save_log(log, project.upload_pic);
191
197
  }
192
198
 
@@ -197,7 +203,7 @@ Server.prototype.exec_log = async function(clientid, log) {
197
203
  */
198
204
  Server.prototype.check_device = async function(clientid, key) {
199
205
  var tip;
200
- var db2 = dbs.new("face_device");
206
+ var db2 = dbs.new("face_device", "device_id");
201
207
  var device = await db2.getObj({
202
208
  clientid
203
209
  });
@@ -225,7 +231,7 @@ Server.prototype.check_device = async function(clientid, key) {
225
231
  */
226
232
  Server.prototype.check_project = async function(project_id, key) {
227
233
  var tip;
228
- var db2 = dbs.new("sys_project");
234
+ var db2 = dbs.new("sys_project", "project_id");
229
235
  var project = await db2.getObj({
230
236
  project_id
231
237
  });
@@ -261,13 +267,14 @@ Server.prototype.save_log = async function(log, upload_pic) {
261
267
  var time = log.time;
262
268
  var clientid = log.clientid;
263
269
  var count = await db.count({
264
- clientid,
270
+ project_id,
265
271
  user_id,
272
+ clientid,
266
273
  time
267
- });
274
+ }, false);
268
275
 
269
276
  // 如果记录已存在,则不再保存
270
- if (count) {
277
+ if (count > 0) {
271
278
  return
272
279
  }
273
280
 
@@ -275,8 +282,8 @@ Server.prototype.save_log = async function(log, upload_pic) {
275
282
  var direction = log.direction;
276
283
  if (user_id && direction == "通用") {
277
284
  var qy = {
278
- user_id,
279
285
  project_id,
286
+ user_id,
280
287
  type_has: "1,3,4",
281
288
  time_min: time.toTime().toStr('yyyy-MM-dd 00:00:00')
282
289
  };
@@ -292,15 +299,17 @@ Server.prototype.save_log = async function(log, upload_pic) {
292
299
  // 重新定义头像
293
300
  var pic;
294
301
  var fname = time.replace(/[-: ]/g, '_');
295
- var avatar = log.avatar;
302
+ var avatar = log.avatar || '';
303
+ var p = `/file/image/user/${user_id}/${fname}.png`;
296
304
  if (avatar) {
297
305
  if (upload_pic) {
298
306
  pic = avatar;
299
- avatar = `/face/img/user/${user_id}/${fname}.png`;
307
+ avatar = p;
300
308
  } else {
301
309
  avatar = "";
302
310
  }
303
311
  }
312
+ log.avatar = avatar;
304
313
 
305
314
  // 如果是访客则追加备注
306
315
  var visitor_id = log.visitor_id;
@@ -338,8 +347,8 @@ Server.prototype.save_log = async function(log, upload_pic) {
338
347
  if (log.user_type == 1) {
339
348
  var db4 = dbs.new("face_enter", "enter_id");
340
349
  await db4.set({
341
- user_id,
342
- project_id
350
+ project_id,
351
+ user_id
343
352
  }, body);
344
353
  } else if (log.user_type == 2) {
345
354
  var db4 = dbs.new("face_visitor", "visitor_id");
@@ -349,7 +358,7 @@ Server.prototype.save_log = async function(log, upload_pic) {
349
358
  }
350
359
 
351
360
  if (pic) {
352
- var file = (`/static/img/user/${user_id}/${fname}.png`).fullname();
361
+ var file = ('/static' + p).fullname();
353
362
  file.addDir();
354
363
  var po = pic.replace(/^data:image\/\w+;base64,/, "");
355
364
  var bf = Buffer.from(po, 'base64');
@@ -370,10 +379,19 @@ Server.prototype.exec_qrcode = async function(clientid, qrcode = "") {
370
379
  var now = new Date();
371
380
  var time = now.toStr('yyyy-MM-dd hh:mm:ss');
372
381
  var obj = await db.getObj({
373
- qrcode,
374
- time_end_min: time
382
+ qrcode
375
383
  });
384
+
376
385
  if (obj) {
386
+ if (now.getTime() > obj.time_end.getTime()) {
387
+ // 发送开门控制
388
+ return {
389
+ "uuid": obj.user_id,
390
+ // 0不开门,1开门
391
+ "pass": false,
392
+ "tip": "二维码已过期"
393
+ }
394
+ };
377
395
  var {
378
396
  device,
379
397
  tip
@@ -390,12 +408,13 @@ Server.prototype.exec_qrcode = async function(clientid, qrcode = "") {
390
408
  if (obj.count == 0 || obj.num < obj.count) {
391
409
  var db = dbs.new("face_enter");
392
410
  var user = await db.getObj({
393
- user_id: obj.user_id,
394
411
  project_id: obj.project_id,
412
+ user_id: obj.user_id,
395
413
  state: 3
396
414
  });
397
415
  if (user) {
398
- if (user.client && user.client.indexOf(clientid) !== -1) {
416
+ if (user.client && user.client.toLocaleUpperCase().indexOf(clientid.toLocaleUpperCase()) !==
417
+ -1) {
399
418
  obj.num++;
400
419
  // 发送开门控制
401
420
  ret = {
@@ -411,7 +430,7 @@ Server.prototype.exec_qrcode = async function(clientid, qrcode = "") {
411
430
  name: "",
412
431
  // 1内部人员|2访客|3非系统名单
413
432
  user_type: 1,
414
- // 1人脸验证|2远程开门|3扫码开门|4刷卡验证
433
+ // 1刷脸验证|2远程开门|3扫码开门|4刷卡验证
415
434
  type: 3,
416
435
  record_type: 1,
417
436
  action: "智码开门",
@@ -425,11 +444,17 @@ Server.prototype.exec_qrcode = async function(clientid, qrcode = "") {
425
444
  nfc: "",
426
445
  note: ""
427
446
  }
428
- $.push(u, user);
447
+ $.push(log, user);
429
448
  log.direction = device.direction;
430
449
  log.clientid = clientid;
431
450
  log.time = time;
432
451
  await this.save_log(log);
452
+ ret = {
453
+ "uuid": user.customId || user.project_id + "-" + user.user_id,
454
+ "pass": true,
455
+ "tip": "请通行",
456
+ device
457
+ }
433
458
  } else {
434
459
  // 发送开门控制
435
460
  ret = {
package/index.js CHANGED
@@ -239,8 +239,9 @@ OS.prototype.main = async function(state) {
239
239
  }
240
240
 
241
241
  if (cg.sys && cg.sys.task) {
242
- await $.task.update();
243
- $.task.run();
242
+ $.task.update().then(() => {
243
+ $.task.run();
244
+ });
244
245
  }
245
246
  console.log(tip);
246
247
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_os",
3
- "version": "2.4.0",
3
+ "version": "2.4.3",
4
4
  "description": "这是超级美眉服务端框架,用于快速构建应用程序。",
5
5
  "main": "index.js",
6
6
  "scripts": {