mm_os 2.3.9 → 2.4.1
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.
- package/core/com/mqtt/script.js +194 -39
- package/demo/app/test/mqtt/df/index.js +106 -24
- package/demo/app/test/mqtt/zs/index.js +221 -146
- package/demo/app/test/task/demo_task/index.js +37 -0
- package/demo/app/test/task/demo_task/task.json +26 -0
- package/demo/com/server/index.js +63 -43
- package/demo/config/development.json +1 -1
- package/index.js +1 -1
- package/package.json +1 -1
package/demo/com/server/index.js
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
|
+
var fs = require("fs");
|
|
2
|
+
var Server = require("../../../com/server/com.js");
|
|
1
3
|
var sql = $.mysql_admin('sys');
|
|
2
4
|
var dbs = sql.db();
|
|
3
5
|
|
|
4
|
-
/**
|
|
5
|
-
* 服务端类
|
|
6
|
-
*/
|
|
7
|
-
class Server {
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
6
|
/**
|
|
12
7
|
* 获取用户
|
|
13
8
|
* @param {String} table 数据表
|
|
@@ -18,8 +13,8 @@ class Server {
|
|
|
18
13
|
* @param {String} idcard 用户身份证号
|
|
19
14
|
* @returns {Object} 返回用户对象
|
|
20
15
|
*/
|
|
21
|
-
Server.prototype.
|
|
22
|
-
var db1 = dbs.new("face_" + table, "user_id");
|
|
16
|
+
Server.prototype.get_enter_sub = async function(table, project_id, customId, name, phone, idcard) {
|
|
17
|
+
var db1 = dbs.new("face_" + table, table == "enter" ? "user_id" : "visitor_id");
|
|
23
18
|
var query = {
|
|
24
19
|
project_id
|
|
25
20
|
}
|
|
@@ -58,15 +53,15 @@ Server.prototype.get_user_sub = async function(table, project_id, customId, name
|
|
|
58
53
|
* @param {String} idcard 用户身份证号
|
|
59
54
|
* @returns {Object} 返回用户对象和用户类型
|
|
60
55
|
*/
|
|
61
|
-
Server.prototype.
|
|
56
|
+
Server.prototype.get_enter = async function(project_id, customId, name, phone, idcard) {
|
|
62
57
|
// 默认为 1内部人员类型
|
|
63
58
|
var user_type = 1;
|
|
64
|
-
var enter = await this.
|
|
59
|
+
var enter = await this.get_enter_sub("enter", project_id, customId, name, phone, idcard);
|
|
65
60
|
|
|
66
61
|
if (!enter) {
|
|
67
62
|
// 2为访客
|
|
68
63
|
user_type = 2;
|
|
69
|
-
enter = await this.
|
|
64
|
+
enter = await this.get_enter_sub("visitor", project_id, customId, name, phone, idcard);
|
|
70
65
|
}
|
|
71
66
|
|
|
72
67
|
if (enter) {
|
|
@@ -92,7 +87,7 @@ Server.prototype.get_user = async function(project_id, customId, name, phone, id
|
|
|
92
87
|
qy.project_id = enter.project_id;
|
|
93
88
|
}
|
|
94
89
|
await db3.set(qy, by);
|
|
95
|
-
enter =
|
|
90
|
+
enter = await db3.getObj(qy);
|
|
96
91
|
}
|
|
97
92
|
} else {
|
|
98
93
|
// 3为外部人员(非平台成员)
|
|
@@ -100,7 +95,7 @@ Server.prototype.get_user = async function(project_id, customId, name, phone, id
|
|
|
100
95
|
enter = {
|
|
101
96
|
department_id: 0,
|
|
102
97
|
team_id: 0,
|
|
103
|
-
name
|
|
98
|
+
name,
|
|
104
99
|
job: "",
|
|
105
100
|
phone,
|
|
106
101
|
idcard
|
|
@@ -108,7 +103,7 @@ Server.prototype.get_user = async function(project_id, customId, name, phone, id
|
|
|
108
103
|
}
|
|
109
104
|
return {
|
|
110
105
|
user_type,
|
|
111
|
-
|
|
106
|
+
enter
|
|
112
107
|
}
|
|
113
108
|
}
|
|
114
109
|
|
|
@@ -146,13 +141,15 @@ Server.prototype.exec_log = async function(clientid, log) {
|
|
|
146
141
|
type,
|
|
147
142
|
record_type,
|
|
148
143
|
person_type,
|
|
149
|
-
action
|
|
144
|
+
action,
|
|
145
|
+
avatar,
|
|
146
|
+
nfc
|
|
150
147
|
} = log;
|
|
151
148
|
// 通过项目id和用户唯一标识获取用户
|
|
152
149
|
var {
|
|
153
|
-
|
|
150
|
+
enter,
|
|
154
151
|
user_type
|
|
155
|
-
} = await this.
|
|
152
|
+
} = await this.get_enter(project_id, customId, name, phone, idcard);
|
|
156
153
|
|
|
157
154
|
// 如果不记录外部人员,则终止,不保存记录
|
|
158
155
|
if (!project.save_outboard && user_type === 3) {
|
|
@@ -160,17 +157,16 @@ Server.prototype.exec_log = async function(clientid, log) {
|
|
|
160
157
|
}
|
|
161
158
|
|
|
162
159
|
log = {
|
|
163
|
-
project_id
|
|
160
|
+
project_id,
|
|
164
161
|
user_id: 0,
|
|
165
162
|
name: "",
|
|
166
163
|
// 1内部人员|2访客|3非系统名单
|
|
167
164
|
user_type,
|
|
168
|
-
clientid: "",
|
|
169
165
|
direction: "",
|
|
170
|
-
// 1
|
|
166
|
+
// 1刷脸验证|2远程开门|3扫码开门|4刷卡验证
|
|
171
167
|
type,
|
|
172
168
|
record_type,
|
|
173
|
-
action: action || "
|
|
169
|
+
action: action || "刷脸验证",
|
|
174
170
|
// 1白名单|2黑名单
|
|
175
171
|
person_type,
|
|
176
172
|
department_id: 0,
|
|
@@ -183,10 +179,17 @@ Server.prototype.exec_log = async function(clientid, log) {
|
|
|
183
179
|
time: ""
|
|
184
180
|
}
|
|
185
181
|
|
|
186
|
-
$.push(log,
|
|
182
|
+
$.push(log, enter);
|
|
183
|
+
log.avatar = avatar;
|
|
187
184
|
log.time = time;
|
|
188
185
|
log.clientid = clientid;
|
|
189
186
|
log.direction = device.direction;
|
|
187
|
+
if (nfc && !log.nfc) {
|
|
188
|
+
log.nfc = nfc;
|
|
189
|
+
}
|
|
190
|
+
if (log.person_type === 0) {
|
|
191
|
+
log.person_type = enter.state == 4 ? 2 : 1;
|
|
192
|
+
}
|
|
190
193
|
return this.save_log(log, project.upload_pic);
|
|
191
194
|
}
|
|
192
195
|
|
|
@@ -197,7 +200,7 @@ Server.prototype.exec_log = async function(clientid, log) {
|
|
|
197
200
|
*/
|
|
198
201
|
Server.prototype.check_device = async function(clientid, key) {
|
|
199
202
|
var tip;
|
|
200
|
-
var db2 = dbs.new("face_device");
|
|
203
|
+
var db2 = dbs.new("face_device", "device_id");
|
|
201
204
|
var device = await db2.getObj({
|
|
202
205
|
clientid
|
|
203
206
|
});
|
|
@@ -225,7 +228,7 @@ Server.prototype.check_device = async function(clientid, key) {
|
|
|
225
228
|
*/
|
|
226
229
|
Server.prototype.check_project = async function(project_id, key) {
|
|
227
230
|
var tip;
|
|
228
|
-
var db2 = dbs.new("sys_project");
|
|
231
|
+
var db2 = dbs.new("sys_project", "project_id");
|
|
229
232
|
var project = await db2.getObj({
|
|
230
233
|
project_id
|
|
231
234
|
});
|
|
@@ -261,13 +264,14 @@ Server.prototype.save_log = async function(log, upload_pic) {
|
|
|
261
264
|
var time = log.time;
|
|
262
265
|
var clientid = log.clientid;
|
|
263
266
|
var count = await db.count({
|
|
264
|
-
|
|
267
|
+
project_id,
|
|
265
268
|
user_id,
|
|
269
|
+
clientid,
|
|
266
270
|
time
|
|
267
|
-
});
|
|
271
|
+
}, false);
|
|
268
272
|
|
|
269
273
|
// 如果记录已存在,则不再保存
|
|
270
|
-
if (count) {
|
|
274
|
+
if (count > 0) {
|
|
271
275
|
return
|
|
272
276
|
}
|
|
273
277
|
|
|
@@ -275,8 +279,8 @@ Server.prototype.save_log = async function(log, upload_pic) {
|
|
|
275
279
|
var direction = log.direction;
|
|
276
280
|
if (user_id && direction == "通用") {
|
|
277
281
|
var qy = {
|
|
278
|
-
user_id,
|
|
279
282
|
project_id,
|
|
283
|
+
user_id,
|
|
280
284
|
type_has: "1,3,4",
|
|
281
285
|
time_min: time.toTime().toStr('yyyy-MM-dd 00:00:00')
|
|
282
286
|
};
|
|
@@ -292,15 +296,17 @@ Server.prototype.save_log = async function(log, upload_pic) {
|
|
|
292
296
|
// 重新定义头像
|
|
293
297
|
var pic;
|
|
294
298
|
var fname = time.replace(/[-: ]/g, '_');
|
|
295
|
-
var avatar = log.avatar;
|
|
299
|
+
var avatar = log.avatar || '';
|
|
300
|
+
var p = `/file/image/user/${user_id}/${fname}.png`;
|
|
296
301
|
if (avatar) {
|
|
297
302
|
if (upload_pic) {
|
|
298
303
|
pic = avatar;
|
|
299
|
-
avatar =
|
|
304
|
+
avatar = p;
|
|
300
305
|
} else {
|
|
301
306
|
avatar = "";
|
|
302
307
|
}
|
|
303
308
|
}
|
|
309
|
+
log.avatar = avatar;
|
|
304
310
|
|
|
305
311
|
// 如果是访客则追加备注
|
|
306
312
|
var visitor_id = log.visitor_id;
|
|
@@ -338,8 +344,8 @@ Server.prototype.save_log = async function(log, upload_pic) {
|
|
|
338
344
|
if (log.user_type == 1) {
|
|
339
345
|
var db4 = dbs.new("face_enter", "enter_id");
|
|
340
346
|
await db4.set({
|
|
341
|
-
|
|
342
|
-
|
|
347
|
+
project_id,
|
|
348
|
+
user_id
|
|
343
349
|
}, body);
|
|
344
350
|
} else if (log.user_type == 2) {
|
|
345
351
|
var db4 = dbs.new("face_visitor", "visitor_id");
|
|
@@ -349,7 +355,7 @@ Server.prototype.save_log = async function(log, upload_pic) {
|
|
|
349
355
|
}
|
|
350
356
|
|
|
351
357
|
if (pic) {
|
|
352
|
-
var file = (
|
|
358
|
+
var file = ('/static' + p).fullname();
|
|
353
359
|
file.addDir();
|
|
354
360
|
var po = pic.replace(/^data:image\/\w+;base64,/, "");
|
|
355
361
|
var bf = Buffer.from(po, 'base64');
|
|
@@ -370,10 +376,19 @@ Server.prototype.exec_qrcode = async function(clientid, qrcode = "") {
|
|
|
370
376
|
var now = new Date();
|
|
371
377
|
var time = now.toStr('yyyy-MM-dd hh:mm:ss');
|
|
372
378
|
var obj = await db.getObj({
|
|
373
|
-
qrcode
|
|
374
|
-
time_end_min: time
|
|
379
|
+
qrcode
|
|
375
380
|
});
|
|
381
|
+
|
|
376
382
|
if (obj) {
|
|
383
|
+
if (now.getTime() > obj.time_end.getTime()) {
|
|
384
|
+
// 发送开门控制
|
|
385
|
+
return {
|
|
386
|
+
"uuid": obj.user_id,
|
|
387
|
+
// 0不开门,1开门
|
|
388
|
+
"pass": false,
|
|
389
|
+
"tip": "二维码已过期"
|
|
390
|
+
}
|
|
391
|
+
};
|
|
377
392
|
var {
|
|
378
393
|
device,
|
|
379
394
|
tip
|
|
@@ -390,12 +405,13 @@ Server.prototype.exec_qrcode = async function(clientid, qrcode = "") {
|
|
|
390
405
|
if (obj.count == 0 || obj.num < obj.count) {
|
|
391
406
|
var db = dbs.new("face_enter");
|
|
392
407
|
var user = await db.getObj({
|
|
393
|
-
user_id: obj.user_id,
|
|
394
408
|
project_id: obj.project_id,
|
|
409
|
+
user_id: obj.user_id,
|
|
395
410
|
state: 3
|
|
396
411
|
});
|
|
397
412
|
if (user) {
|
|
398
|
-
if (user.client && user.client.indexOf(clientid) !==
|
|
413
|
+
if (user.client && user.client.toLocaleUpperCase().indexOf(clientid.toLocaleUpperCase()) !==
|
|
414
|
+
-1) {
|
|
399
415
|
obj.num++;
|
|
400
416
|
// 发送开门控制
|
|
401
417
|
ret = {
|
|
@@ -411,7 +427,7 @@ Server.prototype.exec_qrcode = async function(clientid, qrcode = "") {
|
|
|
411
427
|
name: "",
|
|
412
428
|
// 1内部人员|2访客|3非系统名单
|
|
413
429
|
user_type: 1,
|
|
414
|
-
// 1
|
|
430
|
+
// 1刷脸验证|2远程开门|3扫码开门|4刷卡验证
|
|
415
431
|
type: 3,
|
|
416
432
|
record_type: 1,
|
|
417
433
|
action: "智码开门",
|
|
@@ -425,11 +441,17 @@ Server.prototype.exec_qrcode = async function(clientid, qrcode = "") {
|
|
|
425
441
|
nfc: "",
|
|
426
442
|
note: ""
|
|
427
443
|
}
|
|
428
|
-
$.push(
|
|
444
|
+
$.push(log, user);
|
|
429
445
|
log.direction = device.direction;
|
|
430
446
|
log.clientid = clientid;
|
|
431
447
|
log.time = time;
|
|
432
448
|
await this.save_log(log);
|
|
449
|
+
ret = {
|
|
450
|
+
"uuid": user.customId || user.project_id + "-" + user.user_id,
|
|
451
|
+
"pass": true,
|
|
452
|
+
"tip": "请通行",
|
|
453
|
+
device
|
|
454
|
+
}
|
|
433
455
|
} else {
|
|
434
456
|
// 发送开门控制
|
|
435
457
|
ret = {
|
|
@@ -469,6 +491,4 @@ Server.prototype.exec_qrcode = async function(clientid, qrcode = "") {
|
|
|
469
491
|
}
|
|
470
492
|
|
|
471
493
|
return ret;
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
$.server = new Server();
|
|
494
|
+
}
|
package/index.js
CHANGED