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.
@@ -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
- return this.push("GetRecordsByPicOrID", clientid, param);
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
- return this.push("PullRecordOnlyPic", clientid, {
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
- return this.push("DeletePersons", clientid, {
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
- return this.push("DeletePersons", clientid, {
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
- return this.push("RebootDevice", clientid, {});
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
- return this.push("PullRecordOnlyName", clientid, {
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
- }, longtime);
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
- return res;
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
- if (_this.drives[clientid]) {
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 this.update_online(clientid);
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
- // console.log("上线", clientid, _this.drives[clientid]);
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人脸验证|2远程开门|3智码开门|4刷卡验证)
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
- return this.push("PullRecordOnlyPic", clientid, {
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
- return this.push("DeletePersons", clientid, {
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
- return this.push("DeletePersons", clientid, {
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
- return this.push("RebootDevice", clientid, {});
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
- return this.push("PullRecordOnlyName", clientid, {
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
- }, longtime);
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
- return res;
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人脸验证|2远程开门|3智码开门|4刷卡验证)
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) {