mm_os 2.4.0 → 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/com/server/index.js +63 -43
- package/package.json +1 -1
package/core/com/mqtt/script.js
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
* @param {String} clientid 客户端ID
|
|
4
4
|
* @param {Object} param
|
|
5
5
|
*/
|
|
6
|
-
exports.get_log = function(clientid, param) {
|
|
7
|
-
|
|
6
|
+
exports.get_log = async function(clientid, param) {
|
|
7
|
+
var res = await this.push("GetRecordsByPicOrID", clientid, param);
|
|
8
|
+
return res;
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
/**
|
|
@@ -14,11 +15,15 @@ exports.get_log = function(clientid, param) {
|
|
|
14
15
|
* @param {String} avatar base64头像
|
|
15
16
|
* @param {Number} longtime 超时回馈
|
|
16
17
|
*/
|
|
17
|
-
exports.sign_in = function(clientid, uuid, avatar) {
|
|
18
|
-
|
|
18
|
+
exports.sign_in = async function(clientid, uuid, avatar) {
|
|
19
|
+
var res = await this.push("PullRecordOnlyPic", clientid, {
|
|
19
20
|
"personID": uuid,
|
|
20
21
|
"picinfo": avatar
|
|
21
22
|
});
|
|
23
|
+
|
|
24
|
+
if (!res || res.result == "fail") {
|
|
25
|
+
return "打卡失败!";
|
|
26
|
+
}
|
|
22
27
|
}
|
|
23
28
|
|
|
24
29
|
/**
|
|
@@ -85,16 +90,37 @@ exports.unlock = async function(clientid, uuid = '0', pass = false, tip = '没
|
|
|
85
90
|
}
|
|
86
91
|
}
|
|
87
92
|
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* 远程锁门(没用到)
|
|
96
|
+
* @param {String} clientid 客户端ID
|
|
97
|
+
* @param {String} uuid 用户唯一标识
|
|
98
|
+
* @param {Boolean} pass 是否可通行 true为是
|
|
99
|
+
* @param {String} tip 提示
|
|
100
|
+
*/
|
|
101
|
+
exports.lock = async function(clientid, uuid = '0', pass = false, tip = '没有访问权限') {
|
|
102
|
+
var res = await this.push("Lock", clientid, {
|
|
103
|
+
"uid": uuid,
|
|
104
|
+
"showInfo": tip
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
if (!res || res.result == "fail") {
|
|
108
|
+
return "已锁门!";
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
88
112
|
/**
|
|
89
113
|
* 删除成员
|
|
90
114
|
* @param {String} clientid 客户端ID
|
|
91
115
|
* @param {String} uuid 用户唯一标识
|
|
92
116
|
* @param {Number} longtime 超时回馈
|
|
93
117
|
*/
|
|
94
|
-
exports.delete_member = function(clientid, uuid) {
|
|
95
|
-
|
|
118
|
+
exports.delete_member = async function(clientid, uuid) {
|
|
119
|
+
var res = await this.push("DeletePersons", clientid, {
|
|
96
120
|
"customId": uuid
|
|
97
121
|
});
|
|
122
|
+
|
|
123
|
+
return
|
|
98
124
|
}
|
|
99
125
|
|
|
100
126
|
/**
|
|
@@ -103,21 +129,59 @@ exports.delete_member = function(clientid, uuid) {
|
|
|
103
129
|
* @param {Object} arr 成员列表
|
|
104
130
|
* @param {Number} longtime 超时回馈
|
|
105
131
|
*/
|
|
106
|
-
exports.delete_member_batch = function(clientid, arr, longtime) {
|
|
107
|
-
|
|
132
|
+
exports.delete_member_batch = async function(clientid, arr, longtime) {
|
|
133
|
+
var res = await this.push("DeletePersons", clientid, {
|
|
108
134
|
DataBegin: "BeginFlag",
|
|
109
135
|
DataEnd: "EndFlag",
|
|
110
136
|
PersonNum: arr.length.toString(),
|
|
111
137
|
customId: arr
|
|
112
138
|
}, longtime);
|
|
139
|
+
|
|
140
|
+
var result;
|
|
141
|
+
var error = 0;
|
|
142
|
+
var success = 0;
|
|
143
|
+
var error_info = [];
|
|
144
|
+
var success_info = [];
|
|
145
|
+
|
|
146
|
+
if (res) {
|
|
147
|
+
if (res.result == 'ok') {
|
|
148
|
+
var now = new Date().toStr("yyyy-MM-dd hh:mm:ss");
|
|
149
|
+
error = Number(res.DelErrNum);
|
|
150
|
+
success = Number(res.DelSucNum);
|
|
151
|
+
error_info = res.DelErrInfo.map((o) => {
|
|
152
|
+
o.time_create = now;
|
|
153
|
+
return o
|
|
154
|
+
});
|
|
155
|
+
success_info = res.DelSucInfo.map((o) => {
|
|
156
|
+
o.time_create = now;
|
|
157
|
+
return o
|
|
158
|
+
});
|
|
159
|
+
result = res.result;
|
|
160
|
+
} else if (res.detail && res.detail.indexOf('busy') === -1) {
|
|
161
|
+
result = 'fail';
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return {
|
|
165
|
+
error,
|
|
166
|
+
success,
|
|
167
|
+
error_info,
|
|
168
|
+
success_info,
|
|
169
|
+
result
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
return
|
|
113
173
|
}
|
|
114
174
|
|
|
115
175
|
/**
|
|
116
176
|
* 重启设备
|
|
117
177
|
* @param {String} clientid 设备sn
|
|
118
178
|
*/
|
|
119
|
-
exports.reboot_device = function(clientid) {
|
|
120
|
-
|
|
179
|
+
exports.reboot_device = async function(clientid) {
|
|
180
|
+
var res = await this.push("RebootDevice", clientid, {});
|
|
181
|
+
if (!res || res.result == "ok") {
|
|
182
|
+
return
|
|
183
|
+
}
|
|
184
|
+
return "重启设备失败"
|
|
121
185
|
}
|
|
122
186
|
|
|
123
187
|
/**
|
|
@@ -186,12 +250,17 @@ exports.get_progress = async function(clientid, mode = 'update') {
|
|
|
186
250
|
* @param {Object} param 其他信息
|
|
187
251
|
* @param {Number} longtime 超时回馈
|
|
188
252
|
*/
|
|
189
|
-
exports.replacement = function(clientid, uuid, time, avatar) {
|
|
190
|
-
|
|
253
|
+
exports.replacement = async function(clientid, uuid, time, avatar) {
|
|
254
|
+
var res = await this.push("PullRecordOnlyPic", clientid, {
|
|
191
255
|
"personID": uuid,
|
|
192
256
|
"time": time,
|
|
193
257
|
"picinfo": avatar
|
|
194
|
-
}
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
if (!res || res.result == "fail") {
|
|
261
|
+
return "补卡失败!";
|
|
262
|
+
}
|
|
263
|
+
return
|
|
195
264
|
}
|
|
196
265
|
|
|
197
266
|
/**
|
|
@@ -241,7 +310,8 @@ exports.member_model_out = function(m) {
|
|
|
241
310
|
"picURI": this.fullUrl(m.avatar)
|
|
242
311
|
}
|
|
243
312
|
|
|
244
|
-
if (m.time_valid_end && m.time_valid_end > "2021-01-01 00:00:00".toTime() && m.time_valid_end
|
|
313
|
+
if (m.time_valid_end && m.time_valid_end.toTime() > "2021-01-01 00:00:00".toTime() && m.time_valid_end
|
|
314
|
+
.toTime() <=
|
|
245
315
|
"2038-01-01 00:00:00".toTime()) {
|
|
246
316
|
if (typeof(m.time_valid_start) == "object") {
|
|
247
317
|
obj.cardValidBegin = m.time_valid_start.toStr("yyyy-MM-dd hh:mm:ss");
|
|
@@ -277,7 +347,37 @@ exports.update_member_batch = async function(clientid, list, longtime = 180) {
|
|
|
277
347
|
return this.member_model_out(o);
|
|
278
348
|
})
|
|
279
349
|
}, longtime);
|
|
280
|
-
|
|
350
|
+
|
|
351
|
+
var result;
|
|
352
|
+
var error = 0;
|
|
353
|
+
var success = 0;
|
|
354
|
+
var error_info = [];
|
|
355
|
+
var success_info = [];
|
|
356
|
+
if (res) {
|
|
357
|
+
if (res.result == 'ok') {
|
|
358
|
+
var now = new Date().toStr("yyyy-MM-dd hh:mm:ss");
|
|
359
|
+
error = Number(res.AddErrNum);
|
|
360
|
+
success = Number(res.AddSucNum);
|
|
361
|
+
error_info = res.AddErrInfo.map((o) => {
|
|
362
|
+
o.time_create = now;
|
|
363
|
+
return o
|
|
364
|
+
});
|
|
365
|
+
success_info = res.AddSucInfo.map((o) => {
|
|
366
|
+
o.time_create = now;
|
|
367
|
+
return o
|
|
368
|
+
});
|
|
369
|
+
result = res.result;
|
|
370
|
+
} else if (res.detail && res.detail.indexOf('busy') === -1) {
|
|
371
|
+
result = 'fail';
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
return {
|
|
375
|
+
error,
|
|
376
|
+
success,
|
|
377
|
+
error_info,
|
|
378
|
+
success_info,
|
|
379
|
+
result
|
|
380
|
+
};
|
|
281
381
|
}
|
|
282
382
|
|
|
283
383
|
/**
|
|
@@ -309,24 +409,16 @@ exports.init = function() {
|
|
|
309
409
|
}
|
|
310
410
|
_this.drives[clientid].online = 1;
|
|
311
411
|
_this.drives[clientid].time_last = new Date().getTime();
|
|
412
|
+
// console.log("心跳", clientid, _this.drives[clientid]);
|
|
312
413
|
}
|
|
313
414
|
|
|
314
415
|
/**
|
|
315
|
-
*
|
|
416
|
+
* 离线通知
|
|
316
417
|
* @param {String} clientid 设备sn
|
|
317
418
|
* @param {Object} param 其他信息
|
|
318
419
|
*/
|
|
319
420
|
m["Offline"] = async function(clientid, params) {
|
|
320
|
-
|
|
321
|
-
_this.drives[clientid].online = 0;
|
|
322
|
-
}
|
|
323
|
-
var {
|
|
324
|
-
tip,
|
|
325
|
-
device
|
|
326
|
-
} = await $.server.check_device(clientid);
|
|
327
|
-
if (device) {
|
|
328
|
-
device.online = 0;
|
|
329
|
-
}
|
|
421
|
+
_this.update_online(clientid, 0);
|
|
330
422
|
// console.log("离线", clientid, _this.drives[clientid]);
|
|
331
423
|
};
|
|
332
424
|
|
|
@@ -336,19 +428,87 @@ exports.init = function() {
|
|
|
336
428
|
* @param {Object} param 其他信息
|
|
337
429
|
*/
|
|
338
430
|
m["Online"] = async function(clientid, params) {
|
|
339
|
-
await
|
|
431
|
+
await _this.update_online(clientid, 1, params.ip);
|
|
340
432
|
return {
|
|
341
433
|
"facesluiceId": clientid,
|
|
342
434
|
"result": "ok",
|
|
343
435
|
"detail": ""
|
|
344
436
|
};
|
|
345
|
-
|
|
437
|
+
console.log("上线", clientid, _this.drives[clientid]);
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* 更新人体生命体征,如温度、湿度、位置、
|
|
442
|
+
* @param {String} clientid 设备sn
|
|
443
|
+
* @param {Object} param 其他信息
|
|
444
|
+
*/
|
|
445
|
+
m["life"] = async function(clientid, params) {
|
|
446
|
+
_this.update_life(clientid, {
|
|
447
|
+
// 心率
|
|
448
|
+
heart_rate: 0,
|
|
449
|
+
// 睡眠状态 是深度睡眠还是浅睡眠
|
|
450
|
+
sleep: 0,
|
|
451
|
+
// 血氧饱和度
|
|
452
|
+
oxygen: 0,
|
|
453
|
+
// 行走步数
|
|
454
|
+
step: 0,
|
|
455
|
+
// 压力
|
|
456
|
+
pressure: 0,
|
|
457
|
+
// GPS横坐标,保留生命体脱下设备时的最后位置
|
|
458
|
+
gps_x: 0,
|
|
459
|
+
// GPS纵坐标,保留生命体脱下设备时的最后位置
|
|
460
|
+
gps_y: 0
|
|
461
|
+
});
|
|
462
|
+
// console.log("离线", clientid, _this.drives[clientid]);
|
|
346
463
|
};
|
|
347
464
|
|
|
465
|
+
/**
|
|
466
|
+
* 更新设备信息,如温度、湿度、位置
|
|
467
|
+
* @param {String} clientid 设备sn
|
|
468
|
+
* @param {Object} param 其他信息
|
|
469
|
+
*/
|
|
470
|
+
m["info"] = async function(clientid, params) {
|
|
471
|
+
_this.update_device_info(clientid, {
|
|
472
|
+
// 温度
|
|
473
|
+
temperature: 0,
|
|
474
|
+
// 湿度
|
|
475
|
+
humidity: 0,
|
|
476
|
+
// 氧气
|
|
477
|
+
oxygen: 0,
|
|
478
|
+
// 二氧化碳
|
|
479
|
+
carbon_dioxide: 0,
|
|
480
|
+
// 光照强度
|
|
481
|
+
light: 0,
|
|
482
|
+
// 烟雾浓度
|
|
483
|
+
smoke: 0,
|
|
484
|
+
// 压力
|
|
485
|
+
pressure: 0,
|
|
486
|
+
// GPS横坐标
|
|
487
|
+
gps_x: 0,
|
|
488
|
+
// GPS纵坐标
|
|
489
|
+
gps_y: 0
|
|
490
|
+
});
|
|
491
|
+
// console.log("离线", clientid, _this.drives[clientid]);
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* 上报
|
|
497
|
+
* @param {String} clientid 设备sn
|
|
498
|
+
* @param {Object} param 其他信息
|
|
499
|
+
*/
|
|
348
500
|
m["RecPush"] = async function(clientid, params, msg, id) {
|
|
501
|
+
_this.send(`mqtt/face/${clientid}`, {
|
|
502
|
+
"messageId": _this.get_msgid('PushAck'),
|
|
503
|
+
"operator": "PushAck",
|
|
504
|
+
"info": {
|
|
505
|
+
"PushAckType": "2",
|
|
506
|
+
"SnapOrRecordID": params.RecordID
|
|
507
|
+
}
|
|
508
|
+
});
|
|
349
509
|
var type = 1;
|
|
350
510
|
switch (params.otype) {
|
|
351
|
-
// (1
|
|
511
|
+
// (1刷脸验证|2远程开门|3智码开门|4刷卡验证)
|
|
352
512
|
case "7":
|
|
353
513
|
case "27":
|
|
354
514
|
type = 2;
|
|
@@ -385,6 +545,9 @@ exports.init = function() {
|
|
|
385
545
|
var phone = (params.telnum || "").trim();
|
|
386
546
|
var idcard = (params.idCard || "").trim();
|
|
387
547
|
var nfc = (params.cardNum2 || params.RFIDCard || "").trim();
|
|
548
|
+
if (nfc == "0") {
|
|
549
|
+
ncf = ""
|
|
550
|
+
}
|
|
388
551
|
var time = params.time;
|
|
389
552
|
var avatar = "";
|
|
390
553
|
if (params.pic) {
|
|
@@ -405,19 +568,11 @@ exports.init = function() {
|
|
|
405
568
|
type,
|
|
406
569
|
person_type,
|
|
407
570
|
record_type,
|
|
571
|
+
action: "刷脸验证",
|
|
408
572
|
time,
|
|
409
573
|
avatar
|
|
410
574
|
}
|
|
411
575
|
$.server.exec_log(clientid, log);
|
|
412
|
-
|
|
413
|
-
_this.send(`mqtt/face/${clientid}`, {
|
|
414
|
-
"messageId": _this.get_msgid('PushAck'),
|
|
415
|
-
"operator": "PushAck",
|
|
416
|
-
"info": {
|
|
417
|
-
"PushAckType": "2",
|
|
418
|
-
"SnapOrRecordID": params.RecordID
|
|
419
|
-
}
|
|
420
|
-
});
|
|
421
576
|
}
|
|
422
577
|
|
|
423
578
|
m["QRCodePush"] = async function(clientid, params, msg, id) {
|
|
@@ -427,7 +582,7 @@ exports.init = function() {
|
|
|
427
582
|
pass,
|
|
428
583
|
tip,
|
|
429
584
|
device
|
|
430
|
-
} = $.server.exec_qrcode(clientid, qrcode);
|
|
585
|
+
} = await $.server.exec_qrcode(clientid, qrcode);
|
|
431
586
|
if (device && device.online) {
|
|
432
587
|
await _this.unlock(clientid, uuid, pass, tip);
|
|
433
588
|
}
|
|
@@ -14,11 +14,15 @@ exports.get_log = function(clientid, param) {
|
|
|
14
14
|
* @param {String} avatar base64头像
|
|
15
15
|
* @param {Number} longtime 超时回馈
|
|
16
16
|
*/
|
|
17
|
-
exports.sign_in = function(clientid, uuid, avatar) {
|
|
18
|
-
|
|
17
|
+
exports.sign_in = async function(clientid, uuid, avatar) {
|
|
18
|
+
var res = await this.push("PullRecordOnlyPic", clientid, {
|
|
19
19
|
"personID": uuid,
|
|
20
20
|
"picinfo": avatar
|
|
21
21
|
});
|
|
22
|
+
|
|
23
|
+
if (!res || res.result == "fail") {
|
|
24
|
+
return "打卡失败!";
|
|
25
|
+
}
|
|
22
26
|
}
|
|
23
27
|
|
|
24
28
|
/**
|
|
@@ -91,10 +95,12 @@ exports.unlock = async function(clientid, uuid = '0', pass = false, tip = '没
|
|
|
91
95
|
* @param {String} uuid 用户唯一标识
|
|
92
96
|
* @param {Number} longtime 超时回馈
|
|
93
97
|
*/
|
|
94
|
-
exports.delete_member = function(clientid, uuid) {
|
|
95
|
-
|
|
98
|
+
exports.delete_member = async function(clientid, uuid) {
|
|
99
|
+
var res = await this.push("DeletePersons", clientid, {
|
|
96
100
|
"customId": uuid
|
|
97
101
|
});
|
|
102
|
+
|
|
103
|
+
return
|
|
98
104
|
}
|
|
99
105
|
|
|
100
106
|
/**
|
|
@@ -103,21 +109,59 @@ exports.delete_member = function(clientid, uuid) {
|
|
|
103
109
|
* @param {Object} arr 成员列表
|
|
104
110
|
* @param {Number} longtime 超时回馈
|
|
105
111
|
*/
|
|
106
|
-
exports.delete_member_batch = function(clientid, arr, longtime) {
|
|
107
|
-
|
|
112
|
+
exports.delete_member_batch = async function(clientid, arr, longtime) {
|
|
113
|
+
var res = await this.push("DeletePersons", clientid, {
|
|
108
114
|
DataBegin: "BeginFlag",
|
|
109
115
|
DataEnd: "EndFlag",
|
|
110
116
|
PersonNum: arr.length.toString(),
|
|
111
117
|
customId: arr
|
|
112
118
|
}, longtime);
|
|
119
|
+
|
|
120
|
+
var result;
|
|
121
|
+
var error = 0;
|
|
122
|
+
var success = 0;
|
|
123
|
+
var error_info = [];
|
|
124
|
+
var success_info = [];
|
|
125
|
+
|
|
126
|
+
if (res) {
|
|
127
|
+
if (res.result == 'ok') {
|
|
128
|
+
var now = new Date().toStr("yyyy-MM-dd hh:mm:ss");
|
|
129
|
+
error = Number(res.DelErrNum);
|
|
130
|
+
success = Number(res.DelSucNum);
|
|
131
|
+
error_info = res.DelErrInfo.map((o) => {
|
|
132
|
+
o.time_create = now;
|
|
133
|
+
return o
|
|
134
|
+
});
|
|
135
|
+
success_info = res.DelSucInfo.map((o) => {
|
|
136
|
+
o.time_create = now;
|
|
137
|
+
return o
|
|
138
|
+
});
|
|
139
|
+
result = res.result;
|
|
140
|
+
} else if (res.detail && res.detail.indexOf('busy') === -1) {
|
|
141
|
+
result = 'fail';
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return {
|
|
145
|
+
error,
|
|
146
|
+
success,
|
|
147
|
+
error_info,
|
|
148
|
+
success_info,
|
|
149
|
+
result
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
return
|
|
113
153
|
}
|
|
114
154
|
|
|
115
155
|
/**
|
|
116
156
|
* 重启设备
|
|
117
157
|
* @param {String} clientid 设备sn
|
|
118
158
|
*/
|
|
119
|
-
exports.reboot_device = function(clientid) {
|
|
120
|
-
|
|
159
|
+
exports.reboot_device = async function(clientid) {
|
|
160
|
+
var res = await this.push("RebootDevice", clientid, {});
|
|
161
|
+
if (!res || res.result == "ok") {
|
|
162
|
+
return
|
|
163
|
+
}
|
|
164
|
+
return "重启设备失败"
|
|
121
165
|
}
|
|
122
166
|
|
|
123
167
|
/**
|
|
@@ -186,12 +230,17 @@ exports.get_progress = async function(clientid, mode = 'update') {
|
|
|
186
230
|
* @param {Object} param 其他信息
|
|
187
231
|
* @param {Number} longtime 超时回馈
|
|
188
232
|
*/
|
|
189
|
-
exports.replacement = function(clientid, uuid, time, avatar) {
|
|
190
|
-
|
|
233
|
+
exports.replacement = async function(clientid, uuid, time, avatar) {
|
|
234
|
+
var res = await this.push("PullRecordOnlyPic", clientid, {
|
|
191
235
|
"personID": uuid,
|
|
192
236
|
"time": time,
|
|
193
237
|
"picinfo": avatar
|
|
194
|
-
}
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
if (!res || res.result == "fail") {
|
|
241
|
+
return "补卡失败!";
|
|
242
|
+
}
|
|
243
|
+
return
|
|
195
244
|
}
|
|
196
245
|
|
|
197
246
|
/**
|
|
@@ -240,8 +289,8 @@ exports.member_model_out = function(m) {
|
|
|
240
289
|
"cardType": 0,
|
|
241
290
|
"picURI": this.fullUrl(m.avatar)
|
|
242
291
|
}
|
|
243
|
-
|
|
244
|
-
if (m.time_valid_end && m.time_valid_end > "2021-01-01 00:00:00".toTime() && m.time_valid_end <=
|
|
292
|
+
|
|
293
|
+
if (m.time_valid_end && m.time_valid_end.toTime() > "2021-01-01 00:00:00".toTime() && m.time_valid_end.toTime() <=
|
|
245
294
|
"2038-01-01 00:00:00".toTime()) {
|
|
246
295
|
if (typeof(m.time_valid_start) == "object") {
|
|
247
296
|
obj.cardValidBegin = m.time_valid_start.toStr("yyyy-MM-dd hh:mm:ss");
|
|
@@ -277,7 +326,37 @@ exports.update_member_batch = async function(clientid, list, longtime = 180) {
|
|
|
277
326
|
return this.member_model_out(o);
|
|
278
327
|
})
|
|
279
328
|
}, longtime);
|
|
280
|
-
|
|
329
|
+
|
|
330
|
+
var result;
|
|
331
|
+
var error = 0;
|
|
332
|
+
var success = 0;
|
|
333
|
+
var error_info = [];
|
|
334
|
+
var success_info = [];
|
|
335
|
+
if (res) {
|
|
336
|
+
if (res.result == 'ok') {
|
|
337
|
+
var now = new Date().toStr("yyyy-MM-dd hh:mm:ss");
|
|
338
|
+
error = Number(res.AddErrNum);
|
|
339
|
+
success = Number(res.AddSucNum);
|
|
340
|
+
error_info = res.AddErrInfo.map((o) => {
|
|
341
|
+
o.time_create = now;
|
|
342
|
+
return o
|
|
343
|
+
});
|
|
344
|
+
success_info = res.AddSucInfo.map((o) => {
|
|
345
|
+
o.time_create = now;
|
|
346
|
+
return o
|
|
347
|
+
});
|
|
348
|
+
result = res.result;
|
|
349
|
+
} else if (res.detail && res.detail.indexOf('busy') === -1) {
|
|
350
|
+
result = 'fail';
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
return {
|
|
354
|
+
error,
|
|
355
|
+
success,
|
|
356
|
+
error_info,
|
|
357
|
+
success_info,
|
|
358
|
+
result
|
|
359
|
+
};
|
|
281
360
|
}
|
|
282
361
|
|
|
283
362
|
/**
|
|
@@ -338,9 +417,17 @@ exports.init = function() {
|
|
|
338
417
|
};
|
|
339
418
|
|
|
340
419
|
m["RecPush"] = async function(clientid, params, msg, id) {
|
|
420
|
+
_this.send(`mqtt/face/${clientid}`, {
|
|
421
|
+
"messageId": _this.get_msgid('PushAck'),
|
|
422
|
+
"operator": "PushAck",
|
|
423
|
+
"info": {
|
|
424
|
+
"PushAckType": "2",
|
|
425
|
+
"SnapOrRecordID": params.RecordID
|
|
426
|
+
}
|
|
427
|
+
});
|
|
341
428
|
var type = 1;
|
|
342
429
|
switch (params.otype) {
|
|
343
|
-
// (1
|
|
430
|
+
// (1刷脸验证|2远程开门|3智码开门|4刷卡验证)
|
|
344
431
|
case "7":
|
|
345
432
|
case "27":
|
|
346
433
|
type = 2;
|
|
@@ -377,6 +464,9 @@ exports.init = function() {
|
|
|
377
464
|
var phone = (params.telnum || "").trim();
|
|
378
465
|
var idcard = (params.idCard || "").trim();
|
|
379
466
|
var nfc = (params.cardNum2 || params.RFIDCard || "").trim();
|
|
467
|
+
if (nfc == "0") {
|
|
468
|
+
ncf = ""
|
|
469
|
+
}
|
|
380
470
|
var time = params.time;
|
|
381
471
|
var avatar = "";
|
|
382
472
|
if (params.pic) {
|
|
@@ -397,19 +487,11 @@ exports.init = function() {
|
|
|
397
487
|
type,
|
|
398
488
|
person_type,
|
|
399
489
|
record_type,
|
|
490
|
+
action: "刷脸验证",
|
|
400
491
|
time,
|
|
401
492
|
avatar
|
|
402
493
|
}
|
|
403
494
|
$.server.exec_log(clientid, log);
|
|
404
|
-
|
|
405
|
-
_this.send(`mqtt/face/${clientid}`, {
|
|
406
|
-
"messageId": _this.get_msgid('PushAck'),
|
|
407
|
-
"operator": "PushAck",
|
|
408
|
-
"info": {
|
|
409
|
-
"PushAckType": "2",
|
|
410
|
-
"SnapOrRecordID": params.RecordID
|
|
411
|
-
}
|
|
412
|
-
});
|
|
413
495
|
}
|
|
414
496
|
|
|
415
497
|
m["QRCodePush"] = async function(clientid, params, msg, id) {
|
|
@@ -58,7 +58,10 @@ exports.unlock = async function(clientid, uuid = '0', pass = false, tip = '没
|
|
|
58
58
|
// 0不开门,1开门
|
|
59
59
|
"ctrl_type": pass ? "on" : "off"
|
|
60
60
|
});
|
|
61
|
-
|
|
61
|
+
if (res.message !== "ACK") {
|
|
62
|
+
return res.code;
|
|
63
|
+
}
|
|
64
|
+
return
|
|
62
65
|
}
|
|
63
66
|
|
|
64
67
|
/**
|
|
@@ -67,13 +70,15 @@ exports.unlock = async function(clientid, uuid = '0', pass = false, tip = '没
|
|
|
67
70
|
* @param {String} uuid 用户唯一标识
|
|
68
71
|
* @param {Number} longtime 超时回馈
|
|
69
72
|
*/
|
|
70
|
-
exports.
|
|
71
|
-
var res = this.push("delete_face", clientid, {
|
|
73
|
+
exports.delete_member = async function(clientid, uuid) {
|
|
74
|
+
var res = await this.push("delete_face", clientid, {
|
|
72
75
|
"per_id": uuid,
|
|
73
76
|
"type": 0
|
|
74
77
|
});
|
|
75
|
-
|
|
76
|
-
|
|
78
|
+
if (res.message !== "ACK") {
|
|
79
|
+
return res.code;
|
|
80
|
+
}
|
|
81
|
+
return
|
|
77
82
|
}
|
|
78
83
|
|
|
79
84
|
/**
|
|
@@ -82,33 +87,73 @@ exports.del_member = function(clientid, uuid) {
|
|
|
82
87
|
* @param {Object} arr 成员列表
|
|
83
88
|
* @param {Number} longtime 超时回馈
|
|
84
89
|
*/
|
|
85
|
-
exports.
|
|
86
|
-
|
|
90
|
+
exports.delete_member_batch = async function(clientid, arr, longtime) {
|
|
91
|
+
if (!this.drives[clientid]) {
|
|
92
|
+
this.drives[clientid] = {};
|
|
93
|
+
}
|
|
94
|
+
if (this.drives[clientid].pushing == 1) {
|
|
95
|
+
return {
|
|
96
|
+
detail: "busy"
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
this.drives[clientid].pushing = 1;
|
|
100
|
+
this.drives[clientid].mode = "update";
|
|
101
|
+
|
|
102
|
+
var result;
|
|
103
|
+
var error = 0;
|
|
104
|
+
var success = 0;
|
|
105
|
+
var error_info = [];
|
|
106
|
+
var success_info = [];
|
|
107
|
+
|
|
108
|
+
var now = new Date().toStr("yyyy-MM-dd hh:mm:ss");
|
|
87
109
|
for (var i = 0; i < arr.length; i++) {
|
|
88
|
-
var
|
|
110
|
+
var customId = arr[i];
|
|
89
111
|
var res = await this.push("delete_face", clientid, {
|
|
90
|
-
"per_id":
|
|
112
|
+
"per_id": customId,
|
|
91
113
|
"type": 0
|
|
92
114
|
});
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
115
|
+
if (res.message == "ACK") {
|
|
116
|
+
success++;
|
|
117
|
+
success_info.push({
|
|
118
|
+
customId,
|
|
119
|
+
time_create: now
|
|
120
|
+
});
|
|
121
|
+
} else {
|
|
122
|
+
error++;
|
|
123
|
+
// 407 人脸像素太大(大于 1072)
|
|
124
|
+
// 408 图片格式错误
|
|
125
|
+
// 410 获取到的特征数据为空
|
|
126
|
+
// 412 相似人脸禁止录入
|
|
127
|
+
// 419 缓存初始化中
|
|
128
|
+
// 420 图片长度小于 112
|
|
129
|
+
error_info.push({
|
|
130
|
+
customId,
|
|
131
|
+
errcode: res.code.toString(),
|
|
132
|
+
time_create: now
|
|
133
|
+
});
|
|
96
134
|
}
|
|
97
|
-
list.push({
|
|
98
|
-
uuid,
|
|
99
|
-
bl,
|
|
100
|
-
tip: res.reply || "删除成功"
|
|
101
|
-
});
|
|
102
135
|
}
|
|
103
|
-
|
|
136
|
+
this.drives[clientid].pushing = 0;
|
|
137
|
+
this.drives[clientid].mode = "";
|
|
138
|
+
|
|
139
|
+
return {
|
|
140
|
+
error,
|
|
141
|
+
success,
|
|
142
|
+
error_info,
|
|
143
|
+
success_info,
|
|
144
|
+
result: 'ok'
|
|
145
|
+
};
|
|
104
146
|
}
|
|
105
147
|
|
|
106
148
|
/**
|
|
107
149
|
* 重启设备
|
|
108
150
|
* @param {String} clientid 设备sn
|
|
109
151
|
*/
|
|
110
|
-
exports.reboot_device = function(clientid) {
|
|
111
|
-
|
|
152
|
+
exports.reboot_device = async function(clientid) {
|
|
153
|
+
var res = await this.push("reboot_cam", clientid, {});
|
|
154
|
+
if (res.message !== "ACK") {
|
|
155
|
+
return res.code;
|
|
156
|
+
}
|
|
112
157
|
}
|
|
113
158
|
|
|
114
159
|
/**
|
|
@@ -122,7 +167,10 @@ exports.set_device_time = async function(clientid, datetime) {
|
|
|
122
167
|
"datetime": datetime
|
|
123
168
|
}
|
|
124
169
|
});
|
|
125
|
-
|
|
170
|
+
|
|
171
|
+
if (res.message !== "ACK") {
|
|
172
|
+
return res.code;
|
|
173
|
+
}
|
|
126
174
|
}
|
|
127
175
|
|
|
128
176
|
/**
|
|
@@ -151,7 +199,10 @@ exports.reset_device = function(clientid, record = true, member = false, log = t
|
|
|
151
199
|
* @param {String} clientid 设备sn
|
|
152
200
|
*/
|
|
153
201
|
exports.get_progress = function(clientid) {
|
|
154
|
-
|
|
202
|
+
if (!this.drives[clientid]) {
|
|
203
|
+
this.drives[clientid] = {};
|
|
204
|
+
}
|
|
205
|
+
return this.drives[clientid].pushing || 0;
|
|
155
206
|
}
|
|
156
207
|
|
|
157
208
|
/**
|
|
@@ -163,6 +214,11 @@ exports.get_progress = function(clientid) {
|
|
|
163
214
|
exports.convert_in = function(push_topic, msg, topic) {
|
|
164
215
|
var cg = this.config;
|
|
165
216
|
var method = msg[cg.method];
|
|
217
|
+
if (push_topic.indexOf("heartbeat") !== -1) {
|
|
218
|
+
method = "mqtt_heartbeat";
|
|
219
|
+
} else if (push_topic.indexOf("face/response") !== -1) {
|
|
220
|
+
method = "push_face";
|
|
221
|
+
}
|
|
166
222
|
var json = {
|
|
167
223
|
clientid: "",
|
|
168
224
|
id: msg[cg.msgid] || this.get_msgid(method, 'client'),
|
|
@@ -172,13 +228,15 @@ exports.convert_in = function(push_topic, msg, topic) {
|
|
|
172
228
|
json.params = msg[cg.params];
|
|
173
229
|
}
|
|
174
230
|
if (msg[cg.result]) {
|
|
175
|
-
json.result =
|
|
231
|
+
json.result = {
|
|
232
|
+
code: msg.code,
|
|
233
|
+
message: msg[cg.result]
|
|
234
|
+
};
|
|
176
235
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
if (push_topic.indexOf("heartbeat") !== -1) {
|
|
180
|
-
json.method = "mqtt_heartbeat";
|
|
236
|
+
if (!json.params && !json.result) {
|
|
237
|
+
json.result = msg;
|
|
181
238
|
}
|
|
239
|
+
json.clientid = this.get_clientid(push_topic, json.params || json.result || {}, msg, topic).toLocaleUpperCase();
|
|
182
240
|
return json;
|
|
183
241
|
}
|
|
184
242
|
|
|
@@ -251,25 +309,24 @@ exports.member_model_out = function(m) {
|
|
|
251
309
|
"per_id": m.customId,
|
|
252
310
|
"per_name": m.name,
|
|
253
311
|
"idcardNum": m.nfc || '',
|
|
254
|
-
"img_url": m.avatar,
|
|
312
|
+
"img_url": this.fullUrl(m.avatar),
|
|
255
313
|
"idcardper": m.idcard,
|
|
256
|
-
|
|
257
|
-
|
|
314
|
+
"auth_type": 0,
|
|
315
|
+
// 1 待审核 | 2 已拒绝 | 3 已通过 | 4 黑名单 , 设备0为白名单,2为黑名单
|
|
316
|
+
"per_type": m.state == 4 ? 2 : 0,
|
|
258
317
|
"usr_type": m.gm,
|
|
259
318
|
"gender": m.sex == 1 ? '男' : '女'
|
|
260
319
|
}
|
|
261
320
|
|
|
262
|
-
if (m.
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
obj.e_time = m.time_valid_end.toTime().toStr("yyyy-MM-dd hh:mm:ss");
|
|
272
|
-
}
|
|
321
|
+
if (typeof(m.time_valid_start) == "object") {
|
|
322
|
+
obj.s_time = m.time_valid_start.stamp();
|
|
323
|
+
} else {
|
|
324
|
+
obj.s_time = m.time_valid_start.toTime().stamp();
|
|
325
|
+
}
|
|
326
|
+
if (typeof(m.time_valid_end) == "object") {
|
|
327
|
+
obj.e_time = m.time_valid_end.stamp();
|
|
328
|
+
} else {
|
|
329
|
+
obj.e_time = m.time_valid_end.toTime().stamp();
|
|
273
330
|
}
|
|
274
331
|
return obj
|
|
275
332
|
}
|
|
@@ -279,37 +336,80 @@ exports.member_model_out = function(m) {
|
|
|
279
336
|
* @param {String} clientid 设备ID
|
|
280
337
|
* @param {Object} user 人员信息
|
|
281
338
|
*/
|
|
282
|
-
exports.update_member = function(clientid, user) {
|
|
339
|
+
exports.update_member = async function(clientid, user) {
|
|
283
340
|
var member = this.member_model_out(user);
|
|
284
|
-
|
|
341
|
+
var res = await this.push("update_face_ex", clientid, member);
|
|
342
|
+
if (res.message !== "ACK") {
|
|
343
|
+
return res.code;
|
|
344
|
+
}
|
|
345
|
+
return
|
|
285
346
|
}
|
|
286
347
|
|
|
287
348
|
/**
|
|
288
|
-
* 批量下发人员名单
|
|
349
|
+
* 批量下发人员名单(模拟) 设备本身没有批量下发,因此需要自己设计一个来模拟
|
|
289
350
|
* @param {String} clientid 客户端ID
|
|
290
351
|
* @param {Array} list 人员名单
|
|
291
352
|
* @param {Number} longtime 超时回馈
|
|
292
353
|
*/
|
|
293
354
|
exports.update_member_batch = async function(clientid, list, longtime = 0) {
|
|
294
|
-
|
|
295
|
-
|
|
355
|
+
if (!this.drives[clientid]) {
|
|
356
|
+
this.drives[clientid] = {};
|
|
357
|
+
}
|
|
358
|
+
if (this.drives[clientid].pushing == 1) {
|
|
359
|
+
return {
|
|
360
|
+
detail: "busy"
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
this.drives[clientid].pushing = 1;
|
|
364
|
+
this.drives[clientid].mode = "delete";
|
|
365
|
+
|
|
366
|
+
var result;
|
|
367
|
+
var error = 0;
|
|
368
|
+
var success = 0;
|
|
369
|
+
var error_info = [];
|
|
370
|
+
var success_info = [];
|
|
371
|
+
|
|
372
|
+
var now = new Date().toStr("yyyy-MM-dd hh:mm:ss");
|
|
373
|
+
for (var i = 0; i < list.length; i++) {
|
|
296
374
|
var user = list[i];
|
|
297
|
-
var res = await this.push(clientid, this.member_model_out(user));
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
375
|
+
var res = await this.push("update_face_ex", clientid, this.member_model_out(user));
|
|
376
|
+
if (res.message == "ACK") {
|
|
377
|
+
success++;
|
|
378
|
+
success_info.push({
|
|
379
|
+
customId: user.customId,
|
|
380
|
+
time_create: now
|
|
381
|
+
});
|
|
382
|
+
} else {
|
|
383
|
+
error++;
|
|
384
|
+
// 407 人脸像素太大(大于 1072)
|
|
385
|
+
// 408 图片格式错误
|
|
386
|
+
// 410 获取到的特征数据为空
|
|
387
|
+
// 412 相似人脸禁止录入
|
|
388
|
+
// 419 缓存初始化中
|
|
389
|
+
// 420 图片长度小于 112
|
|
390
|
+
error_info.push({
|
|
391
|
+
customId: user.customId,
|
|
392
|
+
errcode: res.code.toString(),
|
|
393
|
+
time_create: now
|
|
394
|
+
});
|
|
301
395
|
}
|
|
302
|
-
list.push({
|
|
303
|
-
uuid: user.customId,
|
|
304
|
-
bl,
|
|
305
|
-
tip: res.reply || "删除成功"
|
|
306
|
-
});
|
|
307
396
|
}
|
|
308
|
-
|
|
397
|
+
this.drives[clientid].pushing = 0;
|
|
398
|
+
this.drives[clientid].mode = "";
|
|
399
|
+
|
|
400
|
+
return {
|
|
401
|
+
error,
|
|
402
|
+
success,
|
|
403
|
+
error_info,
|
|
404
|
+
success_info,
|
|
405
|
+
result: 'ok'
|
|
406
|
+
};
|
|
309
407
|
}
|
|
310
408
|
|
|
311
409
|
/**
|
|
312
410
|
* 播放语音
|
|
411
|
+
* @param {String} clientid 客户端ID
|
|
412
|
+
* @param {Number} type 语音类型 1为没有权限,2为鉴权失败,3为鉴权成功
|
|
313
413
|
*/
|
|
314
414
|
exports.play_audio = async function(clientid, type = 3) {
|
|
315
415
|
var body = {};
|
|
@@ -333,11 +433,48 @@ exports.play_audio = async function(clientid, type = 3) {
|
|
|
333
433
|
var res = await this.push("trylisten_wav", clientid, {
|
|
334
434
|
body
|
|
335
435
|
});
|
|
436
|
+
|
|
437
|
+
if (res.message !== "ACK") {
|
|
438
|
+
return res.code;
|
|
439
|
+
}
|
|
440
|
+
return
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* 设置扫描二维码模式
|
|
445
|
+
* @param {String} clientid 客户端ID
|
|
446
|
+
* @param {Number} mode 模式
|
|
447
|
+
*/
|
|
448
|
+
exports.set_qrcode_mode = async function(clientid, mode = 1) {
|
|
449
|
+
var res = await this.push("set_qrcode_mode", clientid, {
|
|
450
|
+
body: {
|
|
451
|
+
"enable": 0,
|
|
452
|
+
mode
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
if (res.message !== "ACK") {
|
|
456
|
+
return res.code;
|
|
457
|
+
}
|
|
458
|
+
return
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* 发送灯光
|
|
463
|
+
* @param {String} clientid 客户端ID
|
|
464
|
+
* @param {Number} color 颜色选项
|
|
465
|
+
*/
|
|
466
|
+
exports.send_led = async function(clientid, color = 1) {
|
|
467
|
+
var res = await this.push("set_led_color_test", clientid, {
|
|
468
|
+
"body": {
|
|
469
|
+
color
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
if (res.message !== "ACK") {
|
|
473
|
+
return res.code;
|
|
474
|
+
}
|
|
475
|
+
return
|
|
336
476
|
}
|
|
337
477
|
|
|
338
|
-
// exports.convert_in = function(push_topic, msg, topic, index) {
|
|
339
|
-
// console.log("收到", push_topic, msg, topic, index);
|
|
340
|
-
// }
|
|
341
478
|
|
|
342
479
|
/**
|
|
343
480
|
* 初始化函数, 用于定义开放给前端的函数
|
|
@@ -352,7 +489,7 @@ exports.init = function() {
|
|
|
352
489
|
}
|
|
353
490
|
_this.drives[clientid].online = 1;
|
|
354
491
|
_this.drives[clientid].time_last = new Date().getTime();
|
|
355
|
-
console.log("心跳", clientid, _this.drives[clientid]);
|
|
492
|
+
// console.log("心跳", clientid, _this.drives[clientid]);
|
|
356
493
|
}
|
|
357
494
|
|
|
358
495
|
/**
|
|
@@ -362,100 +499,41 @@ exports.init = function() {
|
|
|
362
499
|
*/
|
|
363
500
|
m["mqtt_online"] = async function(clientid, params) {
|
|
364
501
|
_this.update_online(clientid, 1);
|
|
502
|
+
_this.set_qrcode_mode(clientid);
|
|
365
503
|
console.log("上线", clientid, _this.drives[clientid]);
|
|
366
504
|
};
|
|
367
505
|
|
|
368
|
-
m["
|
|
369
|
-
var info = msg.body;
|
|
370
|
-
// "body": {
|
|
371
|
-
// "e_imgsize": 13485,
|
|
372
|
-
// "ext_sec": 1709089205,
|
|
373
|
-
// "hat": -1,
|
|
374
|
-
// "hcode_status": 0,
|
|
375
|
-
// "idcard": "",
|
|
376
|
-
// "img_data": "/9j/4AAQSkZJRgABAQIAdgB2AAD/7wAPAAAAAAAAAAAAAAAAAP",
|
|
377
|
-
// "isRealtimeData": 601,
|
|
378
|
-
// "isurl": false,
|
|
379
|
-
// "mask": -1,
|
|
380
|
-
// "matched": 93,
|
|
381
|
-
// "name": "schmidt",
|
|
382
|
-
// "name_base64": "c2NobWlkdA==",
|
|
383
|
-
// "per_id": "1706099386778",
|
|
384
|
-
// "per_id_base64": "MTcwNjA5OTM4Njc3OA==",
|
|
385
|
-
// "role": 0,
|
|
386
|
-
// "sequence": 27307,
|
|
387
|
-
// "sn": "7560d2db-fd20feb7",
|
|
388
|
-
// "tep": 0,
|
|
389
|
-
// "usec": 1709118005
|
|
390
|
-
// }
|
|
391
|
-
|
|
506
|
+
m["push_face"] = async function(clientid, params, msg, id) {
|
|
392
507
|
var type = 1;
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
case "
|
|
396
|
-
|
|
397
|
-
type = 2;
|
|
508
|
+
var action;
|
|
509
|
+
switch (msg.type) {
|
|
510
|
+
case "face_result":
|
|
511
|
+
type = 1;
|
|
398
512
|
break;
|
|
399
|
-
case "
|
|
400
|
-
case "48":
|
|
401
|
-
case "55":
|
|
402
|
-
case "56":
|
|
403
|
-
case "57":
|
|
404
|
-
type = 3;
|
|
405
|
-
break;
|
|
406
|
-
case "21":
|
|
407
|
-
case "22":
|
|
408
|
-
case "24":
|
|
409
|
-
case "25":
|
|
513
|
+
case "wgin_read":
|
|
410
514
|
type = 4;
|
|
411
515
|
break;
|
|
412
516
|
default:
|
|
413
517
|
break;
|
|
414
518
|
}
|
|
415
|
-
if (type == 2) {
|
|
416
|
-
return;
|
|
417
|
-
}
|
|
418
|
-
// 1白名单|2黑名单
|
|
419
|
-
var person_type = params.PersonType == "1" ? 2 : 1;
|
|
420
|
-
var record_type = params.RecordType ? Number(params.RecordType) + 1 : 1;
|
|
421
|
-
|
|
422
|
-
// 拿到打卡人的姓名
|
|
423
|
-
var name = params.persionName || params.name;
|
|
424
|
-
if (!name) {
|
|
425
|
-
return;
|
|
426
|
-
}
|
|
427
|
-
var customId = params.customId.trim();
|
|
428
|
-
var phone = (params.telnum || "").trim();
|
|
429
|
-
var idcard = (params.idCard || "").trim();
|
|
430
|
-
var nfc = (params.cardNum2 || params.RFIDCard || "").trim();
|
|
431
|
-
var time = params.time;
|
|
432
|
-
var avatar = "";
|
|
433
|
-
if (params.pic) {
|
|
434
|
-
avatar = params.pic;
|
|
435
|
-
}
|
|
436
519
|
var log = {
|
|
437
|
-
customId,
|
|
438
|
-
name,
|
|
439
|
-
|
|
440
|
-
idcard,
|
|
441
|
-
nfc,
|
|
520
|
+
customId: params.per_id,
|
|
521
|
+
name: params.name,
|
|
522
|
+
idcard: params.idcard,
|
|
442
523
|
clientid,
|
|
524
|
+
// (1刷脸验证|2远程开门|3智码开门|4刷卡验证)
|
|
443
525
|
type,
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
526
|
+
// 1白名单|2黑名单
|
|
527
|
+
person_type: params.matchRole || params.role || 0,
|
|
528
|
+
record_type: 1,
|
|
529
|
+
action,
|
|
530
|
+
nfc: params.wg_num,
|
|
531
|
+
// usec / ext_sec
|
|
532
|
+
time: params.ext_sec.toTime().toStr("yyyy-MM-dd hh:mm:ss"),
|
|
533
|
+
avatar: params.img_data,
|
|
534
|
+
sex: params.gender == '男' ? 1 : 2
|
|
448
535
|
}
|
|
449
536
|
$.server.exec_log(clientid, log);
|
|
450
|
-
|
|
451
|
-
_this.send(`mqtt/face/${clientid}`, {
|
|
452
|
-
"messageId": _this.get_msgid('PushAck'),
|
|
453
|
-
"operator": "PushAck",
|
|
454
|
-
"info": {
|
|
455
|
-
"PushAckType": "2",
|
|
456
|
-
"SnapOrRecordID": params.RecordID
|
|
457
|
-
}
|
|
458
|
-
});
|
|
459
537
|
}
|
|
460
538
|
|
|
461
539
|
m["send_qr_msg"] = async function(clientid, params, msg, id) {
|
|
@@ -466,21 +544,18 @@ exports.init = function() {
|
|
|
466
544
|
tip,
|
|
467
545
|
device
|
|
468
546
|
} = await $.server.exec_qrcode(clientid, qrcode);
|
|
469
|
-
console.log('扫码', qrcode, uuid,
|
|
470
|
-
pass,
|
|
471
|
-
tip,
|
|
472
|
-
device)
|
|
473
547
|
if (device && device.online) {
|
|
474
|
-
|
|
475
|
-
await _this.unlock(clientid.toLocaleUpperCase(), uuid, pass, tip);
|
|
548
|
+
await _this.unlock(clientid, uuid, pass, tip);
|
|
476
549
|
}
|
|
477
550
|
if (tip) {
|
|
478
|
-
if (tip.indexOf("过期") !== -1) {
|
|
551
|
+
if (tip.indexOf("过期") !== -1 || tip.indexOf("超限") !== -1) {
|
|
479
552
|
_this.play_audio(clientid, 1);
|
|
553
|
+
_this.send_led(clientid);
|
|
480
554
|
} else if (tip.indexOf("通行") !== -1) {
|
|
481
555
|
// _this.play_audio(clientid, 3);
|
|
482
556
|
} else {
|
|
483
557
|
_this.play_audio(clientid, 2);
|
|
558
|
+
_this.send_led(clientid);
|
|
484
559
|
}
|
|
485
560
|
}
|
|
486
561
|
}
|
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
|
+
}
|