Skip to content

Commit f28b69e

Browse files
author
“jinyuxing”
committed
update gatewayInfoRedis
1 parent 942a2b0 commit f28b69e

File tree

3 files changed

+31
-23
lines changed

3 files changed

+31
-23
lines changed

lib/gatewayHandler/index.js

+25-17
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,38 @@ const { ERROR, consts } = require('../lora-lib');
33
const config = require('../../config');
44

55
class GatewayHandler {
6-
constructor (models, log, mqClient) {
6+
constructor(models, log, mqClient) {
77
this._GatewayInfoMySQL = models.MySQLModel.GatewayInfo;
88
this._GatewayInfoRedis = models.RedisModel.GatewayInfo;
99
this._mqClient = mqClient;
1010
this._log = log;
1111
}
1212

13-
verifyGateway (gatewayId) {
14-
const query = { gatewayId: gatewayId };
15-
return this._GatewayInfoMySQL.existItem(query)
16-
.then((result) => {
17-
if (result) {
18-
return bluebird.resolve(null);
19-
} else {
20-
return bluebird.reject(new ERROR.GatewayNotExistError({
21-
msg: 'The received Gateway is not registered, the whole package is ignored',
22-
receivedGatewayId: gatewayId,
23-
}));
24-
}
25-
26-
});
13+
verifyGateway(gatewayId) {
14+
const query = { gatewayId };
15+
const attributes = ['userID'];
16+
// return this._GatewayInfoMySQL.existItem(query)
17+
return this._GatewayInfoRedis.readUserID(gatewayId)
18+
.then((res) => {
19+
if (res.userID) {
20+
return bluebird.resolve(null);
21+
} else {
22+
return this._GatewayInfoMySQL.readItem(query, attributes)
23+
.then((res) => {
24+
if (res.userID) {
25+
return this._GatewayInfoRedis.updateUserID(gatewayId, res);
26+
}else {
27+
return bluebird.reject(new ERROR.GatewayNotExistError({
28+
msg: 'The received Gateway is not registered, the whole package is ignored',
29+
receivedGatewayId: gatewayId,
30+
}));
31+
}
32+
});
33+
}
34+
});
2735
}
2836

29-
updateGatewayAddress (gatewayConfig) {
37+
updateGatewayAddress(gatewayConfig) {
3038
if (gatewayConfig.identifier.readUInt8() === consts.UDP_ID_PULL_DATA) {
3139
gatewayConfig.pullPort = gatewayConfig.port;
3240
} else {
@@ -38,7 +46,7 @@ class GatewayHandler {
3846
);
3947
}
4048

41-
uploadPushData (pushData) {
49+
uploadPushData(pushData) {
4250
const msgHeader = {
4351
version: pushData.origin.version,
4452
token: pushData.origin.token,

lib/phyHandler/phyParser.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ const MACParser = new MACCmdParser();
1010
function PHYParser(modelIns, joinHandler, log) {
1111
this.MySQLModel = modelIns.MySQLModel;
1212
this.RedisModel = modelIns.RedisModel;
13-
this.DeviceInfo = this.MySQLModel.DeviceInfo;
13+
this.DeviceInfoMysql = this.MySQLModel.DeviceInfo;
1414
this.DeviceConfig = this.MySQLModel.DeviceConfig;
1515
this.DeviceRouting = this.MySQLModel.DeviceRouting;
16-
this.deviceInfo = this.RedisModel.DeviceInfo;
16+
this.DeviceInfoRedis = this.RedisModel.DeviceInfo;
1717
this.joinHandler = joinHandler;
1818
this.log = log;
1919
}
@@ -181,11 +181,11 @@ PHYParser.prototype.parser = function (phyPayloadRaw) {
181181
};
182182

183183
const getAndCacheDeviceInfo = function (queryOpts, queryAttributes) {
184-
return _this.deviceInfo.read(queryOpts.DevAddr, queryAttributes)
184+
return _this.DeviceInfoRedis.read(queryOpts.DevAddr, queryAttributes)
185185
.then((res) => {
186186
if (!res.NwkSKey) {
187187
let devInfo = {};
188-
return _this.DeviceInfo.readItem(queryOpts, consts.DEVICEINFO_CACHE_ATTRIBUTES)
188+
return _this.DeviceInfoMysql.readItem(queryOpts, consts.DEVICEINFO_CACHE_ATTRIBUTES)
189189
.then((res) => {
190190
Object.keys(res).forEach((key) => {
191191
devInfo[key] = res[key];
@@ -202,7 +202,7 @@ PHYParser.prototype.parser = function (phyPayloadRaw) {
202202
Object.keys(res).forEach((key) => {
203203
devInfo[key] = res[key];
204204
});
205-
return _this.deviceInfo.update(queryOpts.DevAddr, devInfo);
205+
return _this.DeviceInfoRedis.update(queryOpts.DevAddr, devInfo);
206206
})
207207
.then(() => {
208208
const res = {

0 commit comments

Comments
 (0)