mm_os 2.1.8 → 2.2.0

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,11 +1,12 @@
1
1
  /**
2
2
  * 主函数, 用于处理订阅内容
3
3
  * @param {String} topic 订阅的主题
4
- * @param {Object} msg 消息
4
+ * @param {Object} body 消息格式
5
+ * @param {Number} index 索引
5
6
  * @return {Object} 返回执行结果
6
7
  */
7
- exports.main = async function(topic, msg) {
8
- $.log.debug('收到消息'topic, msg);
8
+ exports.main = async function(topic, msg, index) {
9
+ $.log.debug('收到消息', topic, msg, index);
9
10
  };
10
11
 
11
12
  /**
@@ -17,17 +18,17 @@ exports.init = async function() {
17
18
  /**
18
19
  * 获取所有方法
19
20
  * @param {Object} params 参数
20
- * @param {Object} ws Websocket服务
21
+ * @param {Object} mqtt MQTT服务
21
22
  */
22
- m.get_method = function(params, ws) {
23
+ m.get_method = function(params, mqtt) {
23
24
  return Object.keys(m);
24
25
  };
25
26
 
26
27
  /**
27
28
  * @param {Object} params 参数
28
- * @param {Object} ws Websocket服务
29
+ * @param {Object} mqtt MQTT服务
29
30
  */
30
- m.test = function(params, ws) {
31
+ m.test = function(params, mqtt) {
31
32
  return "你好"
32
33
  };
33
- };
34
+ };
@@ -9,12 +9,18 @@
9
9
  "description": "描述该插件是做什么用的",
10
10
  // 插件版本号,用于升级迭代
11
11
  "version": "1.0",
12
+ // 作者
13
+ "author": "",
14
+ // 官网
15
+ "web": "",
12
16
  // 插件语言包文件路径
13
17
  "lang_path": "./lang/",
14
18
  // 插件图标
15
19
  "icon": "/{1}/{0}/img/logo.png",
16
20
  // 插件指令,通过指令方式调用插件
17
21
  "cmd": "{2}",
22
+ // 是否中断执行
23
+ "end": true,
18
24
  // 排序,表示多个插件时在应用下执行的先后顺序
19
25
  "sort": 10
20
26
  }
@@ -27,25 +27,29 @@ class Drive extends Item {
27
27
  /* 通用项 */
28
28
  // 配置参数
29
29
  this.config = {
30
+ // 应用域
31
+ "app": "",
30
32
  // 名称, 由中英文和下“_”组成, 用于修改或卸载 例如: demo
31
33
  // 同时也是版本唯一标识,当商城有两个插件名称相同时,可以通过版本号查询和下载
32
34
  "name": "",
33
- // 状态 0未启用,1启用
34
- "state": 1,
35
- // 显示 0不显示,1显示
36
- "show": 0,
37
35
  // 标题, 介绍事件作用
38
36
  "title": "",
39
37
  // 描述, 用于描述该事件有什么用的
40
38
  "description": "",
41
- // 应用域
42
- "app": "",
39
+ // 版本号
40
+ "version": "1.0",
41
+ // 作者
42
+ "author": "",
43
+ // 官网
44
+ "web": "",
45
+ // 状态 0未启用,1启用
46
+ "state": 1,
47
+ // 显示 0不显示,1显示
48
+ "show": 0,
43
49
  // 文件路径, 当调用函数不存在时,会先从文件中加载
44
50
  "func_file": "./index.js",
45
51
  // 回调函数名 用于决定调用脚本的哪个函数
46
52
  "func_name": "",
47
- // 版本号
48
- "version": "1.0",
49
53
  // 语言包路径
50
54
  "lang_path": "./lang/",
51
55
  // 插件图标
@@ -14,5 +14,7 @@
14
14
  // 函数文件, 当事件触发时执行指定的脚本
15
15
  "func_file": "./main.js",
16
16
  // 执行顺序, 数值越小越优先执行
17
- "sort": 100
17
+ "sort": 100,
18
+ // 状态
19
+ "state": 1
18
20
  }]
@@ -8,6 +8,7 @@ var sql = $.mysql_admin('sys', __dirname);
8
8
  // sql.setConfig($.config.mysql);
9
9
  // sql.open();
10
10
 
11
+
11
12
  /**
12
13
  * @description 接口主函数
13
14
  * @param {Object} ctx HTTP上下文
@@ -0,0 +1,364 @@
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 = function(clientid, uuid, avatar) {
18
+ return this.push("PullRecordOnlyPic", clientid, {
19
+ "personID": uuid,
20
+ "picinfo": avatar
21
+ });
22
+ }
23
+
24
+ /**
25
+ * 下发二维码(没用到)
26
+ * @param {String} clientid
27
+ * @param {Object} param
28
+ * @param {Number} longtime 超时回馈
29
+ */
30
+ exports.push_qrcode = function(clientid, param) {
31
+ return this.push("ShowQRCode", clientid, param);
32
+ }
33
+
34
+ /**
35
+ * 以图搜人
36
+ * @param {String} clientid 客户端ID
37
+ * @param {Object} avatar 人脸照片
38
+ * @param {Number} longtime 超时回馈
39
+ */
40
+ exports.get_member_pic = function(clientid, avatar) {
41
+ return this.push("GetPictureSearch", clientid, {
42
+ "facesluiceId": clientid,
43
+ "MaxSimilarity": 80,
44
+ "MaxNum": 1,
45
+ "picinfo": avatar
46
+ });
47
+ }
48
+
49
+ /**
50
+ * 远程开门
51
+ * @param {String} clientid 客户端ID
52
+ * @param {String} uuid 用户唯一标识
53
+ * @param {Boolean} pass 是否可通行 true为是
54
+ * @param {String} tip 提示
55
+ */
56
+ exports.unlock = function(clientid, uuid = '0', pass = false, tip = '没有访问权限') {
57
+ return this.push("Unlock", clientid, {
58
+ "uid": uuid,
59
+ // 0不开门,1开门
60
+ "openDoor": pass ? "1" : "0",
61
+ "showInfo": tip
62
+ });
63
+ }
64
+
65
+ /**
66
+ * 删除成员
67
+ * @param {String} clientid 客户端ID
68
+ * @param {String} uuid 用户唯一标识
69
+ * @param {Number} longtime 超时回馈
70
+ */
71
+ exports.del_member = function(clientid, uuid) {
72
+ return this.push("DeletePersons", clientid, {
73
+ "customId": uuid
74
+ });
75
+ }
76
+
77
+ /**
78
+ * 批量删除成员
79
+ * @param {String} clientid 客户端ID
80
+ * @param {Object} arr 成员列表
81
+ * @param {Number} longtime 超时回馈
82
+ */
83
+ exports.del_member_batch = function(clientid, arr, longtime) {
84
+ return this.push("DeletePersons", clientid, {
85
+ DataBegin: "BeginFlag",
86
+ DataEnd: "EndFlag",
87
+ PersonNum: arr.length.toString(),
88
+ customId: arr
89
+ }, longtime);
90
+ }
91
+
92
+ /**
93
+ * 重启设备
94
+ * @param {String} clientid 设备sn
95
+ */
96
+ exports.reboot_device = function(clientid) {
97
+ return this.push("RebootDevice", clientid, {});
98
+ }
99
+
100
+ /**
101
+ * 设置设备时间
102
+ * @param {String} clientid 设备sn
103
+ * @param {String} datetime 日期时间
104
+ */
105
+ exports.set_device_time = function(clientid, datetime) {
106
+ return this.push("SetSysTime", clientid, {
107
+ "SysTime": datetime.replace(" ", "T")
108
+ });
109
+ }
110
+
111
+ /**
112
+ * 恢复出厂设置
113
+ * @param {String} clientid 设备sn
114
+ * @param {Boolean} record 是否恢复控制记录,true为恢复
115
+ * @param {Boolean} member 是否恢复成员,true为恢复
116
+ * @param {Boolean} log 是否恢复请求日志,true为恢复
117
+ */
118
+ exports.reset_device = function(clientid, record = true, member = false, log = true) {
119
+ return this.push("SetFactoryDefault", clientid, {
120
+ DefaltRecord: record ? "1" : "0",
121
+ DefaltPerson: member ? "1" : "0",
122
+ DefaltLog: log ? "1" : "0"
123
+ });
124
+ }
125
+
126
+ /**
127
+ * 查询下发进度
128
+ * @param {String} clientid 设备sn
129
+ */
130
+ exports.get_progress = function(clientid) {
131
+ return this.push("QueryProgress", clientid, {});
132
+ }
133
+
134
+ /**
135
+ * 考勤补卡
136
+ * @param {String} clientid 设备sn
137
+ * @param {Object} param 其他信息
138
+ * @param {Number} longtime 超时回馈
139
+ */
140
+ exports.replacement = function(clientid, param, longtime = 0) {
141
+ return this.push("PullRecordOnlyName", clientid, param, longtime);
142
+ }
143
+
144
+ /**
145
+ * 查询人员名单
146
+ * @param {String} clientid 客户端ID
147
+ * @param {Number} longtime 超时回馈
148
+ */
149
+ exports.get_member = function(clientid, longtime = 0) {
150
+ return this.push("QueryPerson", clientid, longtime);
151
+ }
152
+
153
+ /**
154
+ * 查询人员名单
155
+ * @param {String} clientid 客户端ID
156
+ * @param {String} uuid 用户唯一标识
157
+ * @param {Number} longtime 超时回馈
158
+ */
159
+ exports.get_member_one = function(clientid, uuid, longtime = 0) {
160
+ return this.push("QueryPerson", clientid, {
161
+ "personId": uuid
162
+ }, longtime);
163
+ }
164
+
165
+ /**
166
+ * 成员模型
167
+ * @param {Object} m 原始的成员
168
+ */
169
+ exports.member_model_out = function(m) {
170
+ var nfc = m.nfc || '';
171
+ var obj = {
172
+ "customId": m.customId,
173
+ "name": m.name,
174
+ "native": m.place || '',
175
+ "nation": m.nation || '',
176
+ "address": m.address || '',
177
+ "idCard": m.idcard || '',
178
+ "gender": m.sex - 1,
179
+ "phone": m.phone,
180
+ "birthday": m.birthday,
181
+ "cardType2": 2,
182
+ "cardNum2": nfc,
183
+ "RFCardMode": 0,
184
+ "RFIDCard": nfc,
185
+ "notes": "",
186
+ "personType": m.state == 4 ? 1 : 0,
187
+ "cardType": 0,
188
+ "picURI": this.fullUrl(m.avatar)
189
+ }
190
+ if (m.time_valid_end && m.time_valid_end > date && m.time_valid_end <= endDate) {
191
+ if (typeof(m.time_valid_start) == "object") {
192
+ obj.cardValidBegin = m.time_valid_start.toStr("yyyy-MM-dd hh:mm:ss");
193
+ } else {
194
+ obj.cardValidBegin = m.time_valid_start.toTime().toStr("yyyy-MM-dd hh:mm:ss");
195
+ }
196
+ if (typeof(m.time_valid_end) == "object") {
197
+ obj.cardValidEnd = m.time_valid_end.toStr("yyyy-MM-dd hh:mm:ss");
198
+ } else {
199
+ obj.cardValidEnd = m.time_valid_end.toTime().toStr("yyyy-MM-dd hh:mm:ss");
200
+ }
201
+ obj.tempCardType = 1;
202
+ } else {
203
+ obj.tempCardType = 0;
204
+ }
205
+ return obj
206
+ }
207
+
208
+ /**
209
+ * 批量下发人员名单
210
+ * @param {String} clientid 客户端ID
211
+ * @param {Array} list 人员名单
212
+ * @param {Number} longtime 超时回馈
213
+ */
214
+ exports.update_member_batch = function(clientid, list, longtime = 0) {
215
+ return this.pushS(clientid, {
216
+ "messageId": this.get_msgid('EditPersonsNew'),
217
+ "DataBegin": "BeginFlag",
218
+ "DataEnd": "EndFlag",
219
+ "method": "EditPersonsNew",
220
+ "PersonNum": list.length,
221
+ "info": list.map((o) => {
222
+ return this.member_model_out(o);
223
+ })
224
+ }, longtime);
225
+ }
226
+
227
+ /**
228
+ * 下发人员名单
229
+ * @param {String} clientid 设备ID
230
+ * @param {Object} user 人员信息
231
+ * @param {Number} longtime 超时回馈
232
+ */
233
+ exports.update_member = function(clientid, user, longtime = 0) {
234
+ return this.pushS(clientid, {
235
+ "messageId": this.get_msgid('EditPerson'),
236
+ "DataBegin": "BeginFlag",
237
+ "DataEnd": "EndFlag",
238
+ "method": "EditPerson",
239
+ "info": this.member_model_out(user)
240
+ }, longtime);
241
+ }
242
+
243
+ /**
244
+ * 初始化函数, 用于定义开放给前端的函数
245
+ */
246
+ exports.init = function() {
247
+ var m = this.methods;
248
+ var _this = this;
249
+
250
+ m["HeartBeat"] = function(clientid, params) {
251
+ if (!_this.drives[clientid]) {
252
+ _this.drives[clientid] = {};
253
+ }
254
+ _this.drives[clientid].online = 1;
255
+ console.log("心跳", clientid, _this.drives[clientid]);
256
+ }
257
+
258
+ /**
259
+ * 在线通知
260
+ * @param {String} clientid 设备sn
261
+ * @param {Object} param 其他信息
262
+ */
263
+ m["Offline"] = async function(clientid, params) {
264
+ if (_this.drives[clientid]) {
265
+ _this.drives[clientid].online = 0;
266
+ }
267
+ console.log("离线", clientid, _this.drives[clientid]);
268
+ };
269
+
270
+ /**
271
+ * 在线通知
272
+ * @param {String} clientid 设备sn
273
+ * @param {Object} param 其他信息
274
+ */
275
+ m["Online"] = async function(clientid, params) {
276
+ if (!_this.drives[clientid]) {
277
+ _this.drives[clientid] = {};
278
+ }
279
+ _this.drives[clientid].online = 1;
280
+ };
281
+
282
+ m["RecPush"] = async function(clientid, params, msg, id) {
283
+ var type = 1;
284
+ switch (params.otype) {
285
+ // (1人脸验证|2远程开门|3智码开门|4刷卡验证)
286
+ case "7":
287
+ case "27":
288
+ type = 2;
289
+ break;
290
+ case "47":
291
+ case "48":
292
+ case "55":
293
+ case "56":
294
+ case "57":
295
+ type = 3;
296
+ break;
297
+ case "21":
298
+ case "22":
299
+ case "24":
300
+ case "25":
301
+ type = 4;
302
+ break;
303
+ default:
304
+ break;
305
+ }
306
+ if (type == 2) {
307
+ return;
308
+ }
309
+ // 1白名单|2黑名单
310
+ var person_type = params.PersonType == "1" ? 2 : 1;
311
+ var record_type = params.RecordType ? Number(params.RecordType) + 1 : 1;
312
+
313
+ // 拿到打卡人的姓名
314
+ var name = params.persionName || params.name;
315
+ if (!name) {
316
+ return;
317
+ }
318
+ var customId = params.customId.trim();
319
+ var phone = (params.telnum || "").trim();
320
+ var idcard = (params.idCard || "").trim();
321
+ var nfc = (params.cardNum2 || params.RFIDCard || "").trim();
322
+ var time = params.time;
323
+ var avatar = "";
324
+ if (params.pic) {
325
+ avatar = params.pic;
326
+ }
327
+ var log = {
328
+ customId,
329
+ name,
330
+ phone,
331
+ idcard,
332
+ nfc,
333
+ clientid,
334
+ type,
335
+ person_type,
336
+ record_type,
337
+ time,
338
+ avatar
339
+ }
340
+ $.server.exec_log(clientid, log);
341
+
342
+ _this.send(`mqtt/face/${clientid}`, {
343
+ "messageId": _this.get_msgid('PushAck'),
344
+ "operator": "PushAck",
345
+ "info": {
346
+ "PushAckType": "2",
347
+ "SnapOrRecordID": params.RecordID
348
+ }
349
+ });
350
+ }
351
+
352
+ m["QRCodePush"] = async function(clientid, params, msg, id) {
353
+ var qrcode = params.QRCodeInfo;
354
+ var {
355
+ uuid,
356
+ pass,
357
+ tip,
358
+ device
359
+ } = $.server.exec_qrcode(clientid, qrcode);
360
+ if (device && device.online) {
361
+ await _this.unlock(clientid, uuid, pass, tip);
362
+ }
363
+ }
364
+ };
@@ -0,0 +1,34 @@
1
+ {
2
+ // 名称, 由中英文和下“_”组成, 用于修改或卸载 例如: demo
3
+ "name": "DF",
4
+ // mqtt 服务标题
5
+ "title": "原设备",
6
+ // mqtt 服务介绍
7
+ "description": "",
8
+ // 状态 0未启用,1启用
9
+ "state": 1,
10
+ // 订阅的主题
11
+ "topic": ["mqtt/face/#"],
12
+ // 主题回复
13
+ "topic_receive": ["mqtt/face/${clientid}"],
14
+ // 给客户端推送的主题
15
+ "topic_push": "mqtt/face/${clientid}",
16
+ // 接收方式
17
+ "qos": 1,
18
+ // 保持接收
19
+ "retain": true,
20
+ // 调用的脚本
21
+ "func_file": "./index.js",
22
+ // 客户端ID
23
+ "clientid": "clientid",
24
+ // 消息ID
25
+ "msgid": "messageId",
26
+ // 请求方法
27
+ "method": "operator",
28
+ // 参数
29
+ "params": "info",
30
+ // 结果
31
+ "result": "info",
32
+ // 回复方法
33
+ "method_receive": "${method}-Ack"
34
+ }
@@ -0,0 +1,38 @@
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
+ // };
15
+
16
+ /**
17
+ * 初始化函数, 用于定义开放给前端的函数
18
+ */
19
+ exports.init = async function() {
20
+ var m = this.methods;
21
+
22
+ /**
23
+ * 获取所有方法
24
+ * @param {Object} params 参数
25
+ * @param {Object} mqtt MQTT服务
26
+ */
27
+ m.get_method = function(params, mqtt) {
28
+ return Object.keys(m);
29
+ };
30
+
31
+ /**
32
+ * @param {Object} params 参数
33
+ * @param {Object} mqtt MQTT服务
34
+ */
35
+ m.test = function(params, mqtt) {
36
+ return "你好"
37
+ };
38
+ };
@@ -0,0 +1,24 @@
1
+ {
2
+ // 名称, 由中英文和下“_”组成, 用于修改或卸载 例如: demo
3
+ "name": "test",
4
+ // mqtt 服务标题
5
+ "title": "示例",
6
+ // mqtt 服务介绍
7
+ "description": "",
8
+ // 状态 0未启用,1启用
9
+ "state": 1,
10
+ // 订阅的主题
11
+ "topic": ["mqtt/server/sn/#", "mqtt/face/sn/#"],
12
+ // 调用的脚本
13
+ "func_file": "./index.js",
14
+ // 消息ID
15
+ "client_id": "client_id",
16
+ // 消息ID
17
+ "msg_id": "id",
18
+ // 请求方法
19
+ "method": "cmd",
20
+ // 参数
21
+ "params": "body",
22
+ // 结果
23
+ "result": "result"
24
+ }