mm_os 2.7.7 → 2.7.9

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,509 +0,0 @@
1
- /**
2
- * 查询个人记录
3
- * @param {String} clientid 客户端ID
4
- * @param {Object} param
5
- */
6
- exports.get_log = function(clientid, param) {
7
- return this.push("GetRecordsByPicOrID", clientid, param);
8
- }
9
-
10
- /**
11
- * 考勤打卡
12
- * @param {String} clientid 客户端ID
13
- * @param {Object} uuid 用户唯一标识
14
- * @param {String} avatar base64头像
15
- * @param {Number} longtime 超时回馈
16
- */
17
- exports.sign_in = async function(clientid, uuid, avatar) {
18
- var res = await this.push("PullRecordOnlyPic", clientid, {
19
- "personID": uuid,
20
- "picinfo": avatar
21
- });
22
-
23
- if (!res || res.result == "fail") {
24
- return "打卡失败!";
25
- }
26
- }
27
-
28
- /**
29
- * 下发二维码(没用到)
30
- * @param {String} clientid
31
- * @param {Object} param
32
- * @param {Number} longtime 超时回馈
33
- */
34
- exports.push_qrcode = function(clientid, param) {
35
- return this.push("ShowQRCode", clientid, param);
36
- }
37
-
38
- /**
39
- * 以图搜人
40
- * @param {String} clientid 客户端ID
41
- * @param {Object} avatar 人脸照片
42
- * @param {Number} longtime 超时回馈
43
- */
44
- exports.get_member_pic = async function(clientid, avatar) {
45
- var res = await this.push("GetPictureSearch", clientid, {
46
- "facesluiceId": clientid,
47
- "MaxSimilarity": 80,
48
- "MaxNum": 1,
49
- "picinfo": avatar
50
- });
51
- var user;
52
- if (res) {
53
- if (res.result == "fail") {
54
-
55
- } else {
56
- var u = res.SearchInfo[0];
57
- var name = u.name || u.persionName;
58
- var customId = u.customId.trim();
59
- var phone = (u.telnum || "").trim();
60
- var idcard = (u.idCard || "").trim();
61
- user = {
62
- name,
63
- customId,
64
- phone,
65
- idcard
66
- }
67
- }
68
- }
69
- return user
70
- }
71
-
72
- /**
73
- * 远程开门
74
- * @param {String} clientid 客户端ID
75
- * @param {String} uuid 用户唯一标识
76
- * @param {Boolean} pass 是否可通行 true为是
77
- * @param {String} tip 提示
78
- */
79
- exports.unlock = async function(clientid, uuid = '0', pass = false, tip = '没有访问权限') {
80
- var res = await this.push("Unlock", clientid, {
81
- "uid": uuid,
82
- // 0不开门,1开门
83
- "openDoor": pass ? "1" : "0",
84
- "showInfo": tip
85
- });
86
-
87
- if (!res || res.result == "fail") {
88
- return "非内部人员!";
89
- }
90
- }
91
-
92
- /**
93
- * 删除成员
94
- * @param {String} clientid 客户端ID
95
- * @param {String} uuid 用户唯一标识
96
- * @param {Number} longtime 超时回馈
97
- */
98
- exports.delete_member = async function(clientid, uuid) {
99
- var res = await this.push("DeletePersons", clientid, {
100
- "customId": uuid
101
- });
102
-
103
- return
104
- }
105
-
106
- /**
107
- * 批量删除成员
108
- * @param {String} clientid 客户端ID
109
- * @param {Object} arr 成员列表
110
- * @param {Number} longtime 超时回馈
111
- */
112
- exports.delete_member_batch = async function(clientid, arr, longtime) {
113
- var res = await this.push("DeletePersons", clientid, {
114
- DataBegin: "BeginFlag",
115
- DataEnd: "EndFlag",
116
- PersonNum: arr.length.toString(),
117
- customId: arr
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
153
- }
154
-
155
- /**
156
- * 重启设备
157
- * @param {String} clientid 设备sn
158
- */
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 "重启设备失败"
165
- }
166
-
167
- /**
168
- * 设置设备时间
169
- * @param {String} clientid 设备sn
170
- * @param {String} datetime 日期时间
171
- */
172
- exports.set_device_time = async function(clientid, datetime) {
173
- var res = await this.push("SetSysTime", clientid, {
174
- "SysTime": datetime.replace(" ", "T")
175
- });
176
- if (!res || res.result == "ok") {
177
- return
178
- }
179
- return "重置时间失败"
180
- }
181
-
182
- /**
183
- * 恢复出厂设置
184
- * @param {String} clientid 设备sn
185
- * @param {Boolean} record 是否恢复控制记录,true为恢复
186
- * @param {Boolean} member 是否恢复成员,true为恢复
187
- * @param {Boolean} log 是否恢复请求日志,true为恢复
188
- */
189
- exports.reset_device = async function(clientid, record = true, member = false, log = true) {
190
- var res = await this.push("SetFactoryDefault", clientid, {
191
- DefaltRecord: record ? "1" : "0",
192
- DefaltPerson: member ? "1" : "0",
193
- DefaltLog: log ? "1" : "0"
194
- });
195
-
196
- if (!res || res.result == "ok") {
197
- return
198
- }
199
- return "恢复出厂设置失败"
200
- }
201
-
202
- /**
203
- * 查询下发进度
204
- * @param {String} clientid 设备sn
205
- * @param {String} mode 查询方式 默认为更新
206
- */
207
- exports.get_progress = async function(clientid, mode = 'update') {
208
- var type = "";
209
- if (mode == 'update') {
210
- type = "EditPersonsNew";
211
- } else {
212
- type = "DeletePersons";
213
- }
214
- var res = await this.push("QueryProgress", clientid, {
215
- "QueryType": type
216
- });
217
- if (res) {
218
- if (res.Status !== "0") {
219
- return 1;
220
- } else {
221
- return 0;
222
- }
223
- }
224
- return -1;
225
- }
226
-
227
- /**
228
- * 考勤补卡
229
- * @param {String} clientid 设备sn
230
- * @param {Object} param 其他信息
231
- * @param {Number} longtime 超时回馈
232
- */
233
- exports.replacement = async function(clientid, uuid, time, avatar) {
234
- var res = await this.push("PullRecordOnlyPic", clientid, {
235
- "personID": uuid,
236
- "time": time,
237
- "picinfo": avatar
238
- });
239
-
240
- if (!res || res.result == "fail") {
241
- return "补卡失败!";
242
- }
243
- return
244
- }
245
-
246
- /**
247
- * 查询人员名单
248
- * @param {String} clientid 客户端ID
249
- * @param {Number} longtime 超时回馈
250
- */
251
- exports.get_member = function(clientid, longtime = 0) {
252
- return this.push("QueryPerson", clientid, longtime);
253
- }
254
-
255
- /**
256
- * 查询人员名单
257
- * @param {String} clientid 客户端ID
258
- * @param {String} uuid 用户唯一标识
259
- * @param {Number} longtime 超时回馈
260
- */
261
- exports.get_member_one = function(clientid, uuid, longtime = 0) {
262
- return this.push("QueryPerson", clientid, {
263
- "personId": uuid
264
- }, longtime);
265
- }
266
-
267
- /**
268
- * 成员模型
269
- * @param {Object} m 原始的成员
270
- */
271
- exports.member_model_out = function(m) {
272
- var nfc = m.nfc || '';
273
- var obj = {
274
- "customId": m.customId,
275
- "name": m.name,
276
- "native": m.place || '',
277
- "nation": m.nation || '',
278
- "address": m.address || '',
279
- "idCard": m.idcard || '',
280
- "gender": m.sex - 1,
281
- "phone": m.phone,
282
- "birthday": m.birthday,
283
- "cardType2": 2,
284
- "cardNum2": nfc,
285
- "RFCardMode": 0,
286
- "RFIDCard": nfc,
287
- "notes": "",
288
- "personType": m.state == 4 ? 1 : 0,
289
- "cardType": 0,
290
- "picURI": this.fullUrl(m.avatar)
291
- }
292
-
293
- if (m.time_valid_end && m.time_valid_end.toTime() > "2021-01-01 00:00:00".toTime() && m.time_valid_end.toTime() <=
294
- "2038-01-01 00:00:00".toTime()) {
295
- if (typeof(m.time_valid_start) == "object") {
296
- obj.cardValidBegin = m.time_valid_start.toStr("yyyy-MM-dd hh:mm:ss");
297
- } else {
298
- obj.cardValidBegin = m.time_valid_start.toTime().toStr("yyyy-MM-dd hh:mm:ss");
299
- }
300
- if (typeof(m.time_valid_end) == "object") {
301
- obj.cardValidEnd = m.time_valid_end.toStr("yyyy-MM-dd hh:mm:ss");
302
- } else {
303
- obj.cardValidEnd = m.time_valid_end.toTime().toStr("yyyy-MM-dd hh:mm:ss");
304
- }
305
- obj.tempCardType = 1;
306
- } else {
307
- obj.tempCardType = 0;
308
- }
309
- return obj
310
- }
311
-
312
- /**
313
- * 批量下发人员名单
314
- * @param {String} clientid 客户端ID
315
- * @param {Array} list 人员名单
316
- * @param {Number} longtime 超时回馈
317
- */
318
- exports.update_member_batch = async function(clientid, list, longtime = 180) {
319
- var res = await this.pushS(clientid, {
320
- "messageId": this.get_msgid('EditPersonsNew'),
321
- "DataBegin": "BeginFlag",
322
- "DataEnd": "EndFlag",
323
- "operator": "EditPersonsNew",
324
- "PersonNum": list.length,
325
- "info": list.map((o) => {
326
- return this.member_model_out(o);
327
- })
328
- }, longtime);
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
- };
360
- }
361
-
362
- /**
363
- * 下发人员名单
364
- * @param {String} clientid 设备ID
365
- * @param {Object} user 人员信息
366
- * @param {Number} longtime 超时回馈
367
- */
368
- exports.update_member = function(clientid, user, longtime = 0) {
369
- return this.pushS(clientid, {
370
- "messageId": this.get_msgid('EditPerson'),
371
- "DataBegin": "BeginFlag",
372
- "DataEnd": "EndFlag",
373
- "method": "EditPerson",
374
- "info": this.member_model_out(user)
375
- }, longtime);
376
- }
377
-
378
- /**
379
- * 初始化函数, 用于定义开放给前端的函数
380
- */
381
- exports.init = function() {
382
- var m = this.methods;
383
- var _this = this;
384
-
385
- m["HeartBeat"] = function(clientid, params) {
386
- if (!_this.drives[clientid]) {
387
- _this.drives[clientid] = {};
388
- }
389
- _this.drives[clientid].online = 1;
390
- _this.drives[clientid].time_last = new Date().getTime();
391
- // console.log("心跳", clientid, _this.drives[clientid]);
392
- }
393
-
394
- /**
395
- * 在线通知
396
- * @param {String} clientid 设备sn
397
- * @param {Object} param 其他信息
398
- */
399
- m["Offline"] = async function(clientid, params) {
400
- _this.update_online(clientid, 0);
401
- // console.log("离线", clientid, _this.drives[clientid]);
402
- };
403
-
404
- /**
405
- * 在线通知
406
- * @param {String} clientid 设备sn
407
- * @param {Object} param 其他信息
408
- */
409
- m["Online"] = async function(clientid, params) {
410
- await _this.update_online(clientid, 1, params.ip);
411
- return {
412
- "facesluiceId": clientid,
413
- "result": "ok",
414
- "detail": ""
415
- };
416
- console.log("上线", clientid, _this.drives[clientid]);
417
- };
418
-
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
- });
428
- var type = 1;
429
- switch (params.otype) {
430
- // (1刷脸验证|2远程开门|3智码开门|4刷卡验证)
431
- case "7":
432
- case "27":
433
- type = 2;
434
- break;
435
- case "47":
436
- case "48":
437
- case "55":
438
- case "56":
439
- case "57":
440
- type = 3;
441
- break;
442
- case "21":
443
- case "22":
444
- case "24":
445
- case "25":
446
- type = 4;
447
- break;
448
- default:
449
- break;
450
- }
451
- if (type == 2) {
452
- return;
453
- }
454
- // 1白名单|2黑名单
455
- var person_type = params.PersonType == "1" ? 2 : 1;
456
- var record_type = params.RecordType ? Number(params.RecordType) + 1 : 1;
457
-
458
- // 拿到打卡人的姓名
459
- var name = params.persionName || params.name;
460
- if (!name) {
461
- return;
462
- }
463
- var customId = params.customId.trim();
464
- var phone = (params.telnum || "").trim();
465
- var idcard = (params.idCard || "").trim();
466
- var nfc = (params.cardNum2 || params.RFIDCard || "").trim();
467
- if (nfc == "0") {
468
- ncf = ""
469
- }
470
- var time = params.time;
471
- var avatar = "";
472
- if (params.pic) {
473
- avatar = params.pic;
474
- }
475
- if (typeof(time) == "object") {
476
- time = time.toStr("yyyy-MM-dd hh:mm:ss");
477
- } else {
478
- time = time.toTime().toStr("yyyy-MM-dd hh:mm:ss");
479
- }
480
- var log = {
481
- customId,
482
- name,
483
- phone,
484
- idcard,
485
- nfc,
486
- clientid,
487
- type,
488
- person_type,
489
- record_type,
490
- action: "刷脸验证",
491
- time,
492
- avatar
493
- }
494
- $.server.exec_log(clientid, log);
495
- }
496
-
497
- m["QRCodePush"] = async function(clientid, params, msg, id) {
498
- var qrcode = params.QRCodeInfo;
499
- var {
500
- uuid,
501
- pass,
502
- tip,
503
- device
504
- } = await $.server.exec_qrcode(clientid, qrcode);
505
- if (device && device.online) {
506
- await _this.unlock(clientid, uuid, pass, tip);
507
- }
508
- }
509
- };
@@ -1,24 +0,0 @@
1
- {
2
- "name": "DF",
3
- "title": "原设备",
4
- "description": "",
5
- "state": 1,
6
- "topic": [
7
- "mqtt/face/#"
8
- ],
9
- "topic_receive": [
10
- "mqtt/face/${clientid}"
11
- ],
12
- "topic_push": "mqtt/face/${clientid}",
13
- "qos": 1,
14
- "qos_push": 0,
15
- "retain": true,
16
- "longtime": 10000,
17
- "func_file": "./index.js",
18
- "clientid": "facesluiceId",
19
- "msgid": "messageId",
20
- "method": "operator",
21
- "params": "info",
22
- "result": "info",
23
- "method_receive": "${method}-Ack"
24
- }