mm_os 2.4.1 → 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.
@@ -54,9 +54,15 @@ Api.prototype.run = async function(ctx, db) {
54
54
 
55
55
  for (var i = 0, o; o = lt[i++];) {
56
56
  if (o.config.state === 1 && path.has(o.config.path)) {
57
- var ret = await o.run(ctx, db);
58
- if (this.mode) {
59
- o.load(o.filename);
57
+ var ret;
58
+ try {
59
+ ret = await o.run(ctx, db);
60
+ if (this.mode) {
61
+ o.load(o.filename);
62
+ }
63
+ } catch (error) {
64
+ $.log.error("接口错误", ctx.path, error);
65
+ //TODO handle the exception
60
66
  }
61
67
  if (ret) {
62
68
  db.ret = ret;
@@ -77,7 +77,11 @@ Cmd.prototype.run = async function(msg, db, table) {
77
77
  var lt = this.list_before;
78
78
  for (var i = 0, o; o = lt[i++];) {
79
79
  if (o.onOff) {
80
- ret = await o.run_cmd(msg, db);
80
+ try {
81
+ ret = await o.run_cmd(msg, db);
82
+ } catch (error) {
83
+ $.log.error("指令错误", o.config.name, error);
84
+ }
81
85
  if (ret) {
82
86
  break;
83
87
  }
@@ -120,7 +124,11 @@ Cmd.prototype.run = async function(msg, db, table) {
120
124
  var lt = this.list_main;
121
125
  for (var i = 0, o; o = lt[i++];) {
122
126
  if (o.onOff) {
123
- ret = await o.run_first(msg, db);
127
+ try {
128
+ ret = await o.run_first(msg, db);
129
+ } catch (error) {
130
+ $.log.error("指令错误", o.config.name, error);
131
+ }
124
132
  if (ret) {
125
133
  break;
126
134
  }
@@ -131,7 +139,12 @@ Cmd.prototype.run = async function(msg, db, table) {
131
139
  var lt = this.list_after;
132
140
  for (var i = 0, o; o = lt[i++];) {
133
141
  if (o.onOff) {
134
- ret = await o.run_first(msg, db);
142
+ try {
143
+ ret = await o.run_first(msg, db);
144
+ } catch (error) {
145
+ $.log.error("指令错误", o.config.name, error);
146
+ }
147
+
135
148
  if (ret) {
136
149
  break;
137
150
  }
@@ -210,4 +223,4 @@ function cmd_admin(scope, title) {
210
223
  /**
211
224
  * @module 导出Cmd管理器
212
225
  */
213
- $.cmd_admin = cmd_admin;
226
+ $.cmd_admin = cmd_admin;
@@ -171,9 +171,14 @@ Event.prototype.doing = async function(o, ctx, db) {
171
171
  Event.prototype.run_sub = async function(list, target, ctx, db) {
172
172
  for (var i = 0, o; o = list[i++];) {
173
173
  if (o.config.state === 1 && target.has(o.config.target)) {
174
- var ret = await o.run(ctx, db);
175
- if (this.mode) {
176
- o.load(o.filename);
174
+ var ret;
175
+ try {
176
+ ret = await o.run(ctx, db);
177
+ if (this.mode) {
178
+ o.load(o.filename);
179
+ }
180
+ } catch (error) {
181
+ $.log.error("事件执行错误", o.config.name, error);
177
182
  }
178
183
  if (ret) {
179
184
  db.ret = ret;
@@ -132,7 +132,11 @@ MQTT.prototype.update_after = function() {
132
132
  }
133
133
  };
134
134
 
135
- o.run('init');
135
+ try {
136
+ o.run('init');
137
+ } catch (error) {
138
+ $.log.error("MQTT类初始化失败", o.config.name, error);
139
+ }
136
140
  var topics = o.config.topic;
137
141
  if (topics) {
138
142
  for (var i = 0; i < topics.length; i++) {
@@ -276,8 +280,7 @@ MQTT.prototype.receive = async function(push_topic, msg) {
276
280
  try {
277
281
  ret = await o.run("main", push_topic, msg, topic, i);
278
282
  } catch (error) {
279
- $.log.error("mqtt处理程序错误", error);
280
- return
283
+ $.log.error("MQTT执行失败", o.config.name, error);
281
284
  }
282
285
  }
283
286
  }
@@ -459,8 +462,7 @@ MQTT.prototype.update_online = async function() {
459
462
  } else {
460
463
  list_online.push(clientid);
461
464
  }
462
- }
463
- else {
465
+ } else {
464
466
  list_online.push(clientid);
465
467
  }
466
468
  }
@@ -454,6 +454,8 @@ exports.init = function() {
454
454
  step: 0,
455
455
  // 压力
456
456
  pressure: 0,
457
+ // 时间戳
458
+ timestamp: 0,
457
459
  // GPS横坐标,保留生命体脱下设备时的最后位置
458
460
  gps_x: 0,
459
461
  // GPS纵坐标,保留生命体脱下设备时的最后位置
@@ -482,7 +484,19 @@ exports.init = function() {
482
484
  // 烟雾浓度
483
485
  smoke: 0,
484
486
  // 压力
485
- pressure: 0,
487
+ pressure: 0,,
488
+ // 光敏
489
+ photosensitive: 0,
490
+ // 声波
491
+ acoustic_wave: 0,
492
+ // 磁力
493
+ magnetism: 0,
494
+ // 火焰
495
+ flame: 0,
496
+ // 震动
497
+ vibrate: 0,
498
+ // 时间戳
499
+ timestamp: 0,
486
500
  // GPS横坐标
487
501
  gps_x: 0,
488
502
  // GPS纵坐标
@@ -32,10 +32,15 @@ Plugin.prototype.run = function(param1, param2) {
32
32
  var lt = this.list;
33
33
  for (var i = 0, o; o = lt[i++];) {
34
34
  if (o.config.state === 1) {
35
- ret = o.run(param1, param2);
36
- if (this.mode) {
37
- o.load(o.filename);
35
+ try {
36
+ ret = o.run(param1, param2);
37
+ if (this.mode) {
38
+ o.load(o.filename);
39
+ }
40
+ } catch (error) {
41
+ $.log.error("运行插件错误", o.config.name, error);
38
42
  }
43
+
39
44
  if (ret && o.end) {
40
45
  break;
41
46
  }
@@ -40,7 +40,12 @@ class Static extends Index {
40
40
  if (path.indexOf('.') !== -1) {
41
41
  for (var i = 0; i < len; i++) {
42
42
  var o = list[i];
43
- done = await o.run(ctx, path, next);
43
+ try {
44
+ done = await o.run(ctx, path, next);
45
+ } catch (error) {
46
+ $.log.error("静态文件执行错误", o.config.name, error);
47
+ }
48
+
44
49
  if (done) {
45
50
  break;
46
51
  }
@@ -63,7 +68,11 @@ class Static extends Index {
63
68
  }
64
69
  break;
65
70
  } else {
66
- done = await o.run(ctx, path, next);
71
+ try {
72
+ done = await o.run(ctx, path, next);
73
+ } catch (error) {
74
+ $.log.error("静态文件执行错误", o.config.name, error);
75
+ }
67
76
  if (done) {
68
77
  break;
69
78
  }
@@ -27,17 +27,24 @@ class Task extends Index {
27
27
  */
28
28
  Task.prototype.run = async function(name) {
29
29
  var lt = this.list;
30
- if(name){
30
+ if (name) {
31
31
  for (var i = 0, o; o = lt[i++];) {
32
- if(o.name === name){
33
- o.run();
32
+ if (o.name === name) {
33
+ try {
34
+ o.run();
35
+ } catch (error) {
36
+ $.log.error("定时任务错误", o.name, error);
37
+ }
34
38
  break;
35
39
  }
36
40
  }
37
- }
38
- else {
41
+ } else {
39
42
  for (var i = 0, o; o = lt[i++];) {
40
- o.run();
43
+ try {
44
+ o.run();
45
+ } catch (error) {
46
+ $.log.error("定时任务错误", o.name, error);
47
+ }
41
48
  }
42
49
  }
43
50
  };
@@ -115,4 +122,4 @@ function task_admin(scope, title) {
115
122
  /**
116
123
  * @module 导出Task管理器
117
124
  */
118
- $.task_admin = task_admin;
125
+ $.task_admin = task_admin;
@@ -388,7 +388,7 @@ exports.init = function() {
388
388
  }
389
389
  _this.drives[clientid].online = 1;
390
390
  _this.drives[clientid].time_last = new Date().getTime();
391
- // console.log("心跳", clientid, _this.drives[clientid]);
391
+ console.log("心跳", clientid, _this.drives[clientid]);
392
392
  }
393
393
 
394
394
  /**
@@ -1,38 +1,604 @@
1
- // /**
2
- // * 主函数, 用于处理订阅内容
3
- // * @param {String} topic 订阅的主题
4
- // * @param {Object} body 消息格式
5
- // * @param {Number} index 索引
6
- // * @return {Object} 返回执行结果
7
- // */
8
- // exports.main = async function(topic, msg, index) {
9
- // if (topic) {
10
-
11
- // }
12
- // console.log('收到主题', topic);
13
- // console.log('收到消息', msg);
14
- // };
1
+ /**
2
+ * 查询个人记录
3
+ * @param {String} clientid 客户端ID
4
+ * @param {Object} param
5
+ */
6
+ exports.get_log = async function(clientid, param) {
7
+ var res = await this.push("GetRecordsByPicOrID", clientid, param);
8
+ return res;
9
+ }
10
+
11
+ /**
12
+ * 考勤打卡
13
+ * @param {String} clientid 客户端ID
14
+ * @param {Object} uuid 用户唯一标识
15
+ * @param {String} avatar base64头像
16
+ * @param {Number} longtime 超时回馈
17
+ */
18
+ exports.sign_in = async function(clientid, uuid, avatar) {
19
+ var res = await this.push("PullRecordOnlyPic", clientid, {
20
+ "personID": uuid,
21
+ "picinfo": avatar
22
+ });
23
+
24
+ if (!res || res.result == "fail") {
25
+ return "打卡失败!";
26
+ }
27
+ }
28
+
29
+ /**
30
+ * 下发二维码(没用到)
31
+ * @param {String} clientid
32
+ * @param {Object} param
33
+ * @param {Number} longtime 超时回馈
34
+ */
35
+ exports.push_qrcode = function(clientid, param) {
36
+ return this.push("ShowQRCode", clientid, param);
37
+ }
38
+
39
+ /**
40
+ * 以图搜人
41
+ * @param {String} clientid 客户端ID
42
+ * @param {Object} avatar 人脸照片
43
+ * @param {Number} longtime 超时回馈
44
+ */
45
+ exports.get_member_pic = async function(clientid, avatar) {
46
+ var res = await this.push("GetPictureSearch", clientid, {
47
+ "facesluiceId": clientid,
48
+ "MaxSimilarity": 80,
49
+ "MaxNum": 1,
50
+ "picinfo": avatar
51
+ });
52
+ var user;
53
+ if (res) {
54
+ if (res.result == "fail") {
55
+
56
+ } else {
57
+ var u = res.SearchInfo[0];
58
+ var name = u.name || u.persionName;
59
+ var customId = u.customId.trim();
60
+ var phone = (u.telnum || "").trim();
61
+ var idcard = (u.idCard || "").trim();
62
+ user = {
63
+ name,
64
+ customId,
65
+ phone,
66
+ idcard
67
+ }
68
+ }
69
+ }
70
+ return user
71
+ }
72
+
73
+ /**
74
+ * 远程开门
75
+ * @param {String} clientid 客户端ID
76
+ * @param {String} uuid 用户唯一标识
77
+ * @param {Boolean} pass 是否可通行 true为是
78
+ * @param {String} tip 提示
79
+ */
80
+ exports.unlock = async function(clientid, uuid = '0', pass = false, tip = '没有访问权限') {
81
+ var res = await this.push("Unlock", clientid, {
82
+ "uid": uuid,
83
+ // 0不开门,1开门
84
+ "openDoor": pass ? "1" : "0",
85
+ "showInfo": tip
86
+ });
87
+
88
+ if (!res || res.result == "fail") {
89
+ return "非内部人员!";
90
+ }
91
+ }
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
+
112
+ /**
113
+ * 删除成员
114
+ * @param {String} clientid 客户端ID
115
+ * @param {String} uuid 用户唯一标识
116
+ * @param {Number} longtime 超时回馈
117
+ */
118
+ exports.delete_member = async function(clientid, uuid) {
119
+ var res = await this.push("DeletePersons", clientid, {
120
+ "customId": uuid
121
+ });
122
+
123
+ return
124
+ }
125
+
126
+ /**
127
+ * 批量删除成员
128
+ * @param {String} clientid 客户端ID
129
+ * @param {Object} arr 成员列表
130
+ * @param {Number} longtime 超时回馈
131
+ */
132
+ exports.delete_member_batch = async function(clientid, arr, longtime) {
133
+ var res = await this.push("DeletePersons", clientid, {
134
+ DataBegin: "BeginFlag",
135
+ DataEnd: "EndFlag",
136
+ PersonNum: arr.length.toString(),
137
+ customId: arr
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
173
+ }
174
+
175
+ /**
176
+ * 重启设备
177
+ * @param {String} clientid 设备sn
178
+ */
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 "重启设备失败"
185
+ }
186
+
187
+ /**
188
+ * 设置设备时间
189
+ * @param {String} clientid 设备sn
190
+ * @param {String} datetime 日期时间
191
+ */
192
+ exports.set_device_time = async function(clientid, datetime) {
193
+ var res = await this.push("SetSysTime", clientid, {
194
+ "SysTime": datetime.replace(" ", "T")
195
+ });
196
+ if (!res || res.result == "ok") {
197
+ return
198
+ }
199
+ return "重置时间失败"
200
+ }
201
+
202
+ /**
203
+ * 恢复出厂设置
204
+ * @param {String} clientid 设备sn
205
+ * @param {Boolean} record 是否恢复控制记录,true为恢复
206
+ * @param {Boolean} member 是否恢复成员,true为恢复
207
+ * @param {Boolean} log 是否恢复请求日志,true为恢复
208
+ */
209
+ exports.reset_device = async function(clientid, record = true, member = false, log = true) {
210
+ var res = await this.push("SetFactoryDefault", clientid, {
211
+ DefaltRecord: record ? "1" : "0",
212
+ DefaltPerson: member ? "1" : "0",
213
+ DefaltLog: log ? "1" : "0"
214
+ });
215
+
216
+ if (!res || res.result == "ok") {
217
+ return
218
+ }
219
+ return "恢复出厂设置失败"
220
+ }
221
+
222
+ /**
223
+ * 查询下发进度
224
+ * @param {String} clientid 设备sn
225
+ * @param {String} mode 查询方式 默认为更新
226
+ */
227
+ exports.get_progress = async function(clientid, mode = 'update') {
228
+ var type = "";
229
+ if (mode == 'update') {
230
+ type = "EditPersonsNew";
231
+ } else {
232
+ type = "DeletePersons";
233
+ }
234
+ var res = await this.push("QueryProgress", clientid, {
235
+ "QueryType": type
236
+ });
237
+ if (res) {
238
+ if (res.Status !== "0") {
239
+ return 1;
240
+ } else {
241
+ return 0;
242
+ }
243
+ }
244
+ return -1;
245
+ }
246
+
247
+ /**
248
+ * 考勤补卡
249
+ * @param {String} clientid 设备sn
250
+ * @param {Object} param 其他信息
251
+ * @param {Number} longtime 超时回馈
252
+ */
253
+ exports.replacement = async function(clientid, uuid, time, avatar) {
254
+ var res = await this.push("PullRecordOnlyPic", clientid, {
255
+ "personID": uuid,
256
+ "time": time,
257
+ "picinfo": avatar
258
+ });
259
+
260
+ if (!res || res.result == "fail") {
261
+ return "补卡失败!";
262
+ }
263
+ return
264
+ }
265
+
266
+ /**
267
+ * 查询人员名单
268
+ * @param {String} clientid 客户端ID
269
+ * @param {Number} longtime 超时回馈
270
+ */
271
+ exports.get_member = function(clientid, longtime = 0) {
272
+ return this.push("QueryPerson", clientid, longtime);
273
+ }
274
+
275
+ /**
276
+ * 查询人员名单
277
+ * @param {String} clientid 客户端ID
278
+ * @param {String} uuid 用户唯一标识
279
+ * @param {Number} longtime 超时回馈
280
+ */
281
+ exports.get_member_one = function(clientid, uuid, longtime = 0) {
282
+ return this.push("QueryPerson", clientid, {
283
+ "personId": uuid
284
+ }, longtime);
285
+ }
286
+
287
+ /**
288
+ * 成员模型
289
+ * @param {Object} m 原始的成员
290
+ */
291
+ exports.member_model_out = function(m) {
292
+ var nfc = m.nfc || '';
293
+ var obj = {
294
+ "customId": m.customId,
295
+ "name": m.name,
296
+ "native": m.place || '',
297
+ "nation": m.nation || '',
298
+ "address": m.address || '',
299
+ "idCard": m.idcard || '',
300
+ "gender": m.sex - 1,
301
+ "phone": m.phone,
302
+ "birthday": m.birthday,
303
+ "cardType2": 2,
304
+ "cardNum2": nfc,
305
+ "RFCardMode": 0,
306
+ "RFIDCard": nfc,
307
+ "notes": "",
308
+ "personType": m.state == 4 ? 1 : 0,
309
+ "cardType": 0,
310
+ "picURI": this.fullUrl(m.avatar)
311
+ }
312
+
313
+ if (m.time_valid_end && m.time_valid_end.toTime() > "2021-01-01 00:00:00".toTime() && m.time_valid_end
314
+ .toTime() <=
315
+ "2038-01-01 00:00:00".toTime()) {
316
+ if (typeof(m.time_valid_start) == "object") {
317
+ obj.cardValidBegin = m.time_valid_start.toStr("yyyy-MM-dd hh:mm:ss");
318
+ } else {
319
+ obj.cardValidBegin = m.time_valid_start.toTime().toStr("yyyy-MM-dd hh:mm:ss");
320
+ }
321
+ if (typeof(m.time_valid_end) == "object") {
322
+ obj.cardValidEnd = m.time_valid_end.toStr("yyyy-MM-dd hh:mm:ss");
323
+ } else {
324
+ obj.cardValidEnd = m.time_valid_end.toTime().toStr("yyyy-MM-dd hh:mm:ss");
325
+ }
326
+ obj.tempCardType = 1;
327
+ } else {
328
+ obj.tempCardType = 0;
329
+ }
330
+ return obj
331
+ }
332
+
333
+ /**
334
+ * 批量下发人员名单
335
+ * @param {String} clientid 客户端ID
336
+ * @param {Array} list 人员名单
337
+ * @param {Number} longtime 超时回馈
338
+ */
339
+ exports.update_member_batch = async function(clientid, list, longtime = 180) {
340
+ var res = await this.pushS(clientid, {
341
+ "messageId": this.get_msgid('EditPersonsNew'),
342
+ "DataBegin": "BeginFlag",
343
+ "DataEnd": "EndFlag",
344
+ "operator": "EditPersonsNew",
345
+ "PersonNum": list.length,
346
+ "info": list.map((o) => {
347
+ return this.member_model_out(o);
348
+ })
349
+ }, longtime);
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
+ };
381
+ }
382
+
383
+ /**
384
+ * 下发人员名单
385
+ * @param {String} clientid 设备ID
386
+ * @param {Object} user 人员信息
387
+ * @param {Number} longtime 超时回馈
388
+ */
389
+ exports.update_member = function(clientid, user, longtime = 0) {
390
+ return this.pushS(clientid, {
391
+ "messageId": this.get_msgid('EditPerson'),
392
+ "DataBegin": "BeginFlag",
393
+ "DataEnd": "EndFlag",
394
+ "method": "EditPerson",
395
+ "info": this.member_model_out(user)
396
+ }, longtime);
397
+ }
15
398
 
16
399
  /**
17
400
  * 初始化函数, 用于定义开放给前端的函数
18
401
  */
19
- exports.init = async function() {
402
+ exports.init = function() {
20
403
  var m = this.methods;
404
+ var _this = this;
405
+
406
+ m["HeartBeat"] = function(clientid, params) {
407
+ if (!_this.drives[clientid]) {
408
+ _this.drives[clientid] = {};
409
+ }
410
+ _this.drives[clientid].online = 1;
411
+ _this.drives[clientid].time_last = new Date().getTime();
412
+ // console.log("心跳", clientid, _this.drives[clientid]);
413
+ }
414
+
415
+ /**
416
+ * 离线通知
417
+ * @param {String} clientid 设备sn
418
+ * @param {Object} param 其他信息
419
+ */
420
+ m["Offline"] = async function(clientid, params) {
421
+ _this.update_online(clientid, 0);
422
+ // console.log("离线", clientid, _this.drives[clientid]);
423
+ };
21
424
 
22
425
  /**
23
- * 获取所有方法
24
- * @param {Object} params 参数
25
- * @param {Object} mqtt MQTT服务
426
+ * 在线通知
427
+ * @param {String} clientid 设备sn
428
+ * @param {Object} param 其他信息
26
429
  */
27
- m.get_method = function(params, mqtt) {
28
- return Object.keys(m);
430
+ m["Online"] = async function(clientid, params) {
431
+ await _this.update_online(clientid, 1, params.ip);
432
+ return {
433
+ "facesluiceId": clientid,
434
+ "result": "ok",
435
+ "detail": ""
436
+ };
437
+ console.log("上线", clientid, _this.drives[clientid]);
29
438
  };
30
439
 
31
440
  /**
32
- * @param {Object} params 参数
33
- * @param {Object} mqtt MQTT服务
441
+ * 更新人体生命体征,如温度、湿度、位置、
442
+ * @param {String} clientid 设备sn
443
+ * @param {Object} param 其他信息
34
444
  */
35
- m.test = function(params, mqtt) {
36
- return "你好"
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
+ // 时间戳
458
+ timestamp: 0,
459
+ // GPS横坐标,保留生命体脱下设备时的最后位置
460
+ gps_x: 0,
461
+ // GPS纵坐标,保留生命体脱下设备时的最后位置
462
+ gps_y: 0
463
+ });
464
+ // console.log("离线", clientid, _this.drives[clientid]);
37
465
  };
466
+
467
+ /**
468
+ * 更新设备信息,如温度、湿度、位置
469
+ * @param {String} clientid 设备sn
470
+ * @param {Object} param 其他信息
471
+ */
472
+ m["info"] = async function(clientid, params) {
473
+ _this.update_device_info(clientid, {
474
+ // 温度
475
+ temperature: 0,
476
+ // 湿度
477
+ humidity: 0,
478
+ // 氧气
479
+ oxygen: 0,
480
+ // 二氧化碳
481
+ carbon_dioxide: 0,
482
+ // 光照强度
483
+ light: 0,
484
+ // 烟雾浓度
485
+ smoke: 0,
486
+ // 压力
487
+ pressure: 0,
488
+ // 光敏
489
+ photosensitive: 0,
490
+ // 声波
491
+ acoustic_wave: 0,
492
+ // 磁力
493
+ magnetism: 0,
494
+ // 火焰
495
+ flame: 0,
496
+ // 震动
497
+ vibrate: 0,
498
+ // 时间戳
499
+ timestamp: 0,
500
+ // GPS横坐标
501
+ gps_x: 0,
502
+ // GPS纵坐标
503
+ gps_y: 0
504
+ });
505
+ // console.log("离线", clientid, _this.drives[clientid]);
506
+ };
507
+
508
+
509
+ /**
510
+ * 上报
511
+ * @param {String} clientid 设备sn
512
+ * @param {Object} param 其他信息
513
+ */
514
+ m["RecPush"] = async function(clientid, params, msg, id) {
515
+ _this.send(`mqtt/face/${clientid}`, {
516
+ "messageId": _this.get_msgid('PushAck'),
517
+ "operator": "PushAck",
518
+ "info": {
519
+ "PushAckType": "2",
520
+ "SnapOrRecordID": params.RecordID
521
+ }
522
+ });
523
+ var type = 1;
524
+ switch (params.otype) {
525
+ // (1刷脸验证|2远程开门|3智码开门|4刷卡验证)
526
+ case "7":
527
+ case "27":
528
+ type = 2;
529
+ break;
530
+ case "47":
531
+ case "48":
532
+ case "55":
533
+ case "56":
534
+ case "57":
535
+ type = 3;
536
+ break;
537
+ case "21":
538
+ case "22":
539
+ case "24":
540
+ case "25":
541
+ type = 4;
542
+ break;
543
+ default:
544
+ break;
545
+ }
546
+ if (type == 2) {
547
+ return;
548
+ }
549
+ // 1白名单|2黑名单
550
+ var person_type = params.PersonType == "1" ? 2 : 1;
551
+ var record_type = params.RecordType ? Number(params.RecordType) + 1 : 1;
552
+
553
+ // 拿到打卡人的姓名
554
+ var name = params.persionName || params.name;
555
+ if (!name) {
556
+ return;
557
+ }
558
+ var customId = params.customId.trim();
559
+ var phone = (params.telnum || "").trim();
560
+ var idcard = (params.idCard || "").trim();
561
+ var nfc = (params.cardNum2 || params.RFIDCard || "").trim();
562
+ if (nfc == "0") {
563
+ ncf = ""
564
+ }
565
+ var time = params.time;
566
+ var avatar = "";
567
+ if (params.pic) {
568
+ avatar = params.pic;
569
+ }
570
+ if (typeof(time) == "object") {
571
+ time = time.toStr("yyyy-MM-dd hh:mm:ss");
572
+ } else {
573
+ time = time.toTime().toStr("yyyy-MM-dd hh:mm:ss");
574
+ }
575
+ var log = {
576
+ customId,
577
+ name,
578
+ phone,
579
+ idcard,
580
+ nfc,
581
+ clientid,
582
+ type,
583
+ person_type,
584
+ record_type,
585
+ action: "刷脸验证",
586
+ time,
587
+ avatar
588
+ }
589
+ $.server.exec_log(clientid, log);
590
+ }
591
+
592
+ m["QRCodePush"] = async function(clientid, params, msg, id) {
593
+ var qrcode = params.QRCodeInfo;
594
+ var {
595
+ uuid,
596
+ pass,
597
+ tip,
598
+ device
599
+ } = await $.server.exec_qrcode(clientid, qrcode);
600
+ if (device && device.online) {
601
+ await _this.unlock(clientid, uuid, pass, tip);
602
+ }
603
+ }
38
604
  };
@@ -1,8 +1,11 @@
1
1
  var fs = require("fs");
2
- var Server = require("../../../com/server/com.js");
3
2
  var sql = $.mysql_admin('sys');
4
3
  var dbs = sql.db();
5
4
 
5
+ class Server {
6
+
7
+ }
8
+
6
9
  /**
7
10
  * 获取用户
8
11
  * @param {String} table 数据表
@@ -491,4 +494,6 @@ Server.prototype.exec_qrcode = async function(clientid, qrcode = "") {
491
494
  }
492
495
 
493
496
  return ret;
494
- }
497
+ }
498
+
499
+ $.server = new Server();
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.1",
3
+ "version": "2.4.3",
4
4
  "description": "这是超级美眉服务端框架,用于快速构建应用程序。",
5
5
  "main": "index.js",
6
6
  "scripts": {