mm_os 2.2.3 → 2.2.5
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/drive.js +11 -8
- package/core/com/mqtt/index.js +23 -14
- package/demo/app/test/mqtt/df/index.js +5 -0
- package/demo/app/test/mqtt/df/mqtt.json +1 -1
- package/demo/com/server/index.js +53 -26
- package/demo/config/development.json +5 -4
- package/demo/index.js +1 -1
- package/package.json +1 -1
package/core/com/mqtt/drive.js
CHANGED
|
@@ -369,10 +369,13 @@ Drive.prototype.exec = async function(clientid, key, json) {
|
|
|
369
369
|
* @param {Object} msg 消息
|
|
370
370
|
* @param {String} topic 订阅的主题
|
|
371
371
|
*/
|
|
372
|
-
Drive.prototype.get_clientid = function(push_topic, msg, topic) {
|
|
372
|
+
Drive.prototype.get_clientid = function(push_topic, body, msg, topic) {
|
|
373
373
|
var cg = this.config;
|
|
374
|
-
var
|
|
375
|
-
|
|
374
|
+
var clientid = body[cg.clientid] || msg[cg.clientid];
|
|
375
|
+
if (!clientid) {
|
|
376
|
+
var str = topic.left("#");
|
|
377
|
+
clientid = push_topic.between(str, "/");
|
|
378
|
+
}
|
|
376
379
|
return clientid;
|
|
377
380
|
}
|
|
378
381
|
|
|
@@ -385,19 +388,19 @@ Drive.prototype.get_clientid = function(push_topic, msg, topic) {
|
|
|
385
388
|
*/
|
|
386
389
|
Drive.prototype.convert_in = function(push_topic, msg, topic, index) {
|
|
387
390
|
var cg = this.config;
|
|
388
|
-
var clientid = msg[cg.clientid] || this.get_clientid(push_topic, msg, topic);
|
|
389
391
|
var method = msg[cg.method];
|
|
390
392
|
var json = {
|
|
391
|
-
clientid,
|
|
393
|
+
clientid: "",
|
|
392
394
|
id: msg[cg.msgid] || this.get_msgid(method, 'client'),
|
|
393
395
|
method
|
|
394
396
|
};
|
|
395
|
-
|
|
396
397
|
if (msg[cg.params]) {
|
|
397
|
-
json.params = msg[cg.params]
|
|
398
|
+
json.params = msg[cg.params];
|
|
399
|
+
json.clientid = this.get_clientid(push_topic, json.params, msg, topic);
|
|
398
400
|
}
|
|
399
401
|
if (msg[cg.result]) {
|
|
400
402
|
json.result = msg[cg.result]
|
|
403
|
+
json.clientid = this.get_clientid(push_topic, json.result, msg, topic);
|
|
401
404
|
}
|
|
402
405
|
return json;
|
|
403
406
|
}
|
|
@@ -494,7 +497,7 @@ Drive.prototype.handle = async function(push_topic, msg, topic, index) {
|
|
|
494
497
|
* @param {Number} index 索引
|
|
495
498
|
* @return {Object} 返回执行结果
|
|
496
499
|
*/
|
|
497
|
-
Drive.prototype.main = async function(push_topic, msg,
|
|
500
|
+
Drive.prototype.main = async function(push_topic, msg, topic, index) {
|
|
498
501
|
return this.handle(push_topic, msg, topic, index);
|
|
499
502
|
}
|
|
500
503
|
|
package/core/com/mqtt/index.js
CHANGED
|
@@ -29,16 +29,18 @@ class MQTT extends Index {
|
|
|
29
29
|
hostname: "127.0.0.1",
|
|
30
30
|
port: "1883",
|
|
31
31
|
protocol: "mqtt",
|
|
32
|
-
clientId: "
|
|
32
|
+
clientId: "de",
|
|
33
33
|
subscribe_qos: 0,
|
|
34
34
|
publish_qos: 1,
|
|
35
|
-
username: "
|
|
35
|
+
username: "de",
|
|
36
36
|
password: "asd123",
|
|
37
37
|
clean: false,
|
|
38
38
|
longtime: 15000,
|
|
39
|
+
connectTimeout: 4000,
|
|
39
40
|
// maxInflight: 20,
|
|
40
41
|
// 重连间隔
|
|
41
|
-
interval: 6000
|
|
42
|
+
// interval: 6000,
|
|
43
|
+
reconnectPeriod: 6000 // 重连间隔1秒
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
// mqtt客户端服务器
|
|
@@ -83,6 +85,14 @@ class MQTT extends Index {
|
|
|
83
85
|
}
|
|
84
86
|
}
|
|
85
87
|
|
|
88
|
+
/**
|
|
89
|
+
* 设置配置
|
|
90
|
+
* @param {Object} config 配置
|
|
91
|
+
*/
|
|
92
|
+
MQTT.prototype.set_config = function(config) {
|
|
93
|
+
Object.assign(this.config, config);
|
|
94
|
+
}
|
|
95
|
+
|
|
86
96
|
/**
|
|
87
97
|
* 主题匹配
|
|
88
98
|
* @param {String} topic 接收到的主题
|
|
@@ -133,21 +143,20 @@ MQTT.prototype.update_after = function() {
|
|
|
133
143
|
}
|
|
134
144
|
}
|
|
135
145
|
|
|
136
|
-
|
|
137
146
|
/**
|
|
138
147
|
* 重新连接
|
|
139
148
|
*/
|
|
140
149
|
MQTT.prototype.reconnect = function() {
|
|
141
|
-
$.sleep(this.config.interval);
|
|
142
|
-
this.retryTimes += 1;
|
|
143
|
-
if (this.retryTimes > 5) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
150
|
+
// $.sleep(this.config.interval);
|
|
151
|
+
// this.retryTimes += 1;
|
|
152
|
+
// if (this.retryTimes > 5) {
|
|
153
|
+
// try {
|
|
154
|
+
// this.client.end();
|
|
155
|
+
// this.init();
|
|
156
|
+
// } catch (error) {
|
|
157
|
+
// this.$message.error(error.toString());
|
|
158
|
+
// }
|
|
159
|
+
// }
|
|
151
160
|
}
|
|
152
161
|
|
|
153
162
|
/**
|
|
@@ -324,6 +324,11 @@ exports.init = function() {
|
|
|
324
324
|
if (params.pic) {
|
|
325
325
|
avatar = params.pic;
|
|
326
326
|
}
|
|
327
|
+
if (typeof(time) == "object") {
|
|
328
|
+
time = time.toStr("yyyy-MM-dd hh:mm:ss");
|
|
329
|
+
} else {
|
|
330
|
+
time = time.toTime().toStr("yyyy-MM-dd hh:mm:ss");
|
|
331
|
+
}
|
|
327
332
|
var log = {
|
|
328
333
|
customId,
|
|
329
334
|
name,
|
package/demo/com/server/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
var sql = $.mysql_admin('sys');
|
|
2
|
-
var dbs = sql.
|
|
2
|
+
var dbs = sql.db();
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* 服务端类
|
|
@@ -33,16 +33,16 @@ Server.prototype.get_user_sub = async function(table, project_id, customId, name
|
|
|
33
33
|
query.idcard = idcard;
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
// 先查询1
|
|
37
|
-
var enter = await
|
|
36
|
+
// 先查询1次,看人员是否存在
|
|
37
|
+
var enter = await db1.getObj(query, "", "*", false);
|
|
38
38
|
|
|
39
39
|
if (!enter) {
|
|
40
|
-
//
|
|
40
|
+
// 如果不存在,则用名字再查一次
|
|
41
41
|
query = {
|
|
42
42
|
project_id,
|
|
43
43
|
name
|
|
44
44
|
};
|
|
45
|
-
enter = await
|
|
45
|
+
enter = await db1.getObj(query, "`time_create` desc", "*", false);
|
|
46
46
|
}
|
|
47
47
|
return enter;
|
|
48
48
|
}
|
|
@@ -100,20 +100,15 @@ Server.prototype.get_user = async function(project_id, customId, name, phone, id
|
|
|
100
100
|
enter = {
|
|
101
101
|
department_id: 0,
|
|
102
102
|
team_id: 0,
|
|
103
|
-
|
|
103
|
+
name: "",
|
|
104
|
+
job: "",
|
|
104
105
|
phone,
|
|
105
106
|
idcard
|
|
106
107
|
};
|
|
107
108
|
}
|
|
108
|
-
var user = Object.assign({}, enter, {
|
|
109
|
-
customId,
|
|
110
|
-
name,
|
|
111
|
-
phone,
|
|
112
|
-
idcard
|
|
113
|
-
})
|
|
114
109
|
return {
|
|
115
110
|
user_type,
|
|
116
|
-
user
|
|
111
|
+
user: Object.assign({}, enter)
|
|
117
112
|
}
|
|
118
113
|
}
|
|
119
114
|
|
|
@@ -136,7 +131,7 @@ Server.prototype.exec_log = async function(clientid, log) {
|
|
|
136
131
|
var {
|
|
137
132
|
project,
|
|
138
133
|
tip
|
|
139
|
-
} = check_project(project_id);
|
|
134
|
+
} = await this.check_project(project_id);
|
|
140
135
|
|
|
141
136
|
if (tip) {
|
|
142
137
|
return tip
|
|
@@ -146,7 +141,12 @@ Server.prototype.exec_log = async function(clientid, log) {
|
|
|
146
141
|
customId,
|
|
147
142
|
name,
|
|
148
143
|
phone,
|
|
149
|
-
idcard
|
|
144
|
+
idcard,
|
|
145
|
+
time,
|
|
146
|
+
type,
|
|
147
|
+
record_type,
|
|
148
|
+
person_type,
|
|
149
|
+
action
|
|
150
150
|
} = log;
|
|
151
151
|
// 通过项目id和用户唯一标识获取用户
|
|
152
152
|
var {
|
|
@@ -158,10 +158,36 @@ Server.prototype.exec_log = async function(clientid, log) {
|
|
|
158
158
|
if (!project.save_outboard && user_type === 3) {
|
|
159
159
|
return
|
|
160
160
|
}
|
|
161
|
-
|
|
161
|
+
|
|
162
|
+
log = {
|
|
163
|
+
project_id: 0,
|
|
164
|
+
user_id: 0,
|
|
165
|
+
name: "",
|
|
166
|
+
// 1内部人员|2访客|3非系统名单
|
|
167
|
+
user_type,
|
|
168
|
+
clientid: "",
|
|
169
|
+
direction: "",
|
|
170
|
+
// 1人脸验证|2远程开门|3扫码开门|4刷卡验证
|
|
171
|
+
type,
|
|
172
|
+
record_type,
|
|
173
|
+
action: action || "人脸验证",
|
|
174
|
+
// 1白名单|2黑名单
|
|
175
|
+
person_type,
|
|
176
|
+
department_id: 0,
|
|
177
|
+
team_id: 0,
|
|
178
|
+
job: "",
|
|
179
|
+
phone: "",
|
|
180
|
+
idcard: "",
|
|
181
|
+
nfc: "",
|
|
182
|
+
note: "",
|
|
183
|
+
time: ""
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
$.push(log, user);
|
|
187
|
+
log.time = time;
|
|
162
188
|
log.clientid = clientid;
|
|
163
189
|
log.direction = device.direction;
|
|
164
|
-
return this.save_log(log);
|
|
190
|
+
return this.save_log(log, project.upload_pic);
|
|
165
191
|
}
|
|
166
192
|
|
|
167
193
|
/**
|
|
@@ -192,7 +218,6 @@ Server.prototype.check_device = async function(clientid, key) {
|
|
|
192
218
|
};
|
|
193
219
|
}
|
|
194
220
|
|
|
195
|
-
|
|
196
221
|
/**
|
|
197
222
|
* 检查项目
|
|
198
223
|
* @param {String} project_id 项目ID
|
|
@@ -200,7 +225,7 @@ Server.prototype.check_device = async function(clientid, key) {
|
|
|
200
225
|
*/
|
|
201
226
|
Server.prototype.check_project = async function(project_id, key) {
|
|
202
227
|
var tip;
|
|
203
|
-
var db2 = dbs.new("
|
|
228
|
+
var db2 = dbs.new("sys_project");
|
|
204
229
|
var project = await db2.getObj({
|
|
205
230
|
project_id
|
|
206
231
|
});
|
|
@@ -227,14 +252,16 @@ Server.prototype.check_project = async function(project_id, key) {
|
|
|
227
252
|
/**
|
|
228
253
|
* 保存记录
|
|
229
254
|
* @param {Object} log 记录
|
|
255
|
+
* @param {Boolean} upload_pic 上传头像
|
|
230
256
|
*/
|
|
231
|
-
Server.prototype.save_log = async function(log) {
|
|
257
|
+
Server.prototype.save_log = async function(log, upload_pic) {
|
|
232
258
|
var db = dbs.new("face_log", "user_id");
|
|
233
259
|
var project_id = log.project_id;
|
|
234
260
|
var user_id = log.user_id || 0;
|
|
235
261
|
var time = log.time;
|
|
262
|
+
var clientid = log.clientid;
|
|
236
263
|
var count = await db.count({
|
|
237
|
-
|
|
264
|
+
clientid,
|
|
238
265
|
user_id,
|
|
239
266
|
time
|
|
240
267
|
});
|
|
@@ -251,7 +278,7 @@ Server.prototype.save_log = async function(log) {
|
|
|
251
278
|
user_id,
|
|
252
279
|
project_id,
|
|
253
280
|
type_has: "1,3,4",
|
|
254
|
-
time_min:
|
|
281
|
+
time_min: time.toTime().toStr('yyyy-MM-dd 00:00:00')
|
|
255
282
|
};
|
|
256
283
|
var obj = await db.getObj(qy, '`time` desc');
|
|
257
284
|
if (obj) {
|
|
@@ -267,7 +294,7 @@ Server.prototype.save_log = async function(log) {
|
|
|
267
294
|
var fname = time.replace(/[-: ]/g, '_');
|
|
268
295
|
var avatar = log.avatar;
|
|
269
296
|
if (avatar) {
|
|
270
|
-
if (
|
|
297
|
+
if (upload_pic) {
|
|
271
298
|
pic = avatar;
|
|
272
299
|
avatar = `/face/img/user/${user_id}/${fname}.png`;
|
|
273
300
|
} else {
|
|
@@ -304,7 +331,7 @@ Server.prototype.save_log = async function(log) {
|
|
|
304
331
|
if (bl) {
|
|
305
332
|
// 更新用户状态
|
|
306
333
|
var body = {
|
|
307
|
-
clientid
|
|
334
|
+
clientid,
|
|
308
335
|
direction,
|
|
309
336
|
time
|
|
310
337
|
};
|
|
@@ -314,7 +341,7 @@ Server.prototype.save_log = async function(log) {
|
|
|
314
341
|
user_id,
|
|
315
342
|
project_id
|
|
316
343
|
}, body);
|
|
317
|
-
} else if (user_type == 2) {
|
|
344
|
+
} else if (log.user_type == 2) {
|
|
318
345
|
var db4 = dbs.new("face_visitor", "visitor_id");
|
|
319
346
|
await db4.set({
|
|
320
347
|
visitor_id
|
|
@@ -322,7 +349,7 @@ Server.prototype.save_log = async function(log) {
|
|
|
322
349
|
}
|
|
323
350
|
|
|
324
351
|
if (pic) {
|
|
325
|
-
var file = (`/
|
|
352
|
+
var file = (`/static/img/user/${user_id}/${fname}.png`).fullname();
|
|
326
353
|
file.addDir();
|
|
327
354
|
var po = pic.replace(/^data:image\/\w+;base64,/, "");
|
|
328
355
|
var bf = Buffer.from(po, 'base64');
|
|
@@ -50,23 +50,24 @@
|
|
|
50
50
|
},
|
|
51
51
|
"mqtt": {
|
|
52
52
|
// 是否启用MQTT
|
|
53
|
-
"state":
|
|
53
|
+
"state": false,
|
|
54
54
|
// mqtt访问端口号
|
|
55
55
|
"socket_port": 1883,
|
|
56
56
|
// websocket 访问端口
|
|
57
57
|
"http_port": 8083,
|
|
58
58
|
// 缓存方式 memory、mongodb、redis
|
|
59
|
-
"cache": "
|
|
59
|
+
"cache": "redis",
|
|
60
60
|
// 缓存服务器地址
|
|
61
61
|
"cache_host": "mongodb://localhost:27017/mosca",
|
|
62
62
|
// MQTT订阅方式
|
|
63
|
-
"subscribe_qos":
|
|
63
|
+
"subscribe_qos": 0,
|
|
64
64
|
// 清除历史
|
|
65
65
|
"clean": true,
|
|
66
66
|
// 协议头
|
|
67
67
|
"protocol": "mqtt",
|
|
68
68
|
// MQTT服务器地址
|
|
69
|
-
"hostname": "
|
|
69
|
+
"hostname": "mqtt.laieliantong.com",
|
|
70
|
+
// "hostname": "127.0.0.1",
|
|
70
71
|
// MQTT服务器用户名
|
|
71
72
|
"username": "developer",
|
|
72
73
|
// MQTT服务器密码
|
package/demo/index.js
CHANGED