@@ -3,30 +3,38 @@ const { ERROR, consts } = require('../lora-lib');
3
3
const config = require ( '../../config' ) ;
4
4
5
5
class GatewayHandler {
6
- constructor ( models , log , mqClient ) {
6
+ constructor ( models , log , mqClient ) {
7
7
this . _GatewayInfoMySQL = models . MySQLModel . GatewayInfo ;
8
8
this . _GatewayInfoRedis = models . RedisModel . GatewayInfo ;
9
9
this . _mqClient = mqClient ;
10
10
this . _log = log ;
11
11
}
12
12
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
+ } ) ;
27
35
}
28
36
29
- updateGatewayAddress ( gatewayConfig ) {
37
+ updateGatewayAddress ( gatewayConfig ) {
30
38
if ( gatewayConfig . identifier . readUInt8 ( ) === consts . UDP_ID_PULL_DATA ) {
31
39
gatewayConfig . pullPort = gatewayConfig . port ;
32
40
} else {
@@ -38,7 +46,7 @@ class GatewayHandler {
38
46
) ;
39
47
}
40
48
41
- uploadPushData ( pushData ) {
49
+ uploadPushData ( pushData ) {
42
50
const msgHeader = {
43
51
version : pushData . origin . version ,
44
52
token : pushData . origin . token ,
0 commit comments