Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
device-new-platform
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
赵啸非
device-new-platform
Commits
9145a8e9
Commit
9145a8e9
authored
Jul 15, 2022
by
赵啸非
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
设备添加站点编码
parent
c19bd4df
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
49 additions
and
22 deletions
+49
-22
device-manager/src/main/java/com/mortals/xhx/busiz/security/filter/ApiSubmitInterceptor.java
...rtals/xhx/busiz/security/filter/ApiSubmitInterceptor.java
+18
-7
device-manager/src/main/java/com/mortals/xhx/busiz/web/DeviceApiController.java
...n/java/com/mortals/xhx/busiz/web/DeviceApiController.java
+23
-12
device-manager/src/main/java/com/mortals/xhx/common/key/ErrorCode.java
...r/src/main/java/com/mortals/xhx/common/key/ErrorCode.java
+3
-0
device-manager/src/main/java/com/mortals/xhx/common/key/RedisKey.java
...er/src/main/java/com/mortals/xhx/common/key/RedisKey.java
+2
-0
device-manager/src/main/java/com/mortals/xhx/daemon/applicationservice/DeviceMsgComsumerStartedService.java
...n/applicationservice/DeviceMsgComsumerStartedService.java
+1
-1
device-manager/src/test/java/com/mortals/httpclient/device/DeviceController.http
.../java/com/mortals/httpclient/device/DeviceController.http
+2
-2
No files found.
device-manager/src/main/java/com/mortals/xhx/busiz/security/filter/ApiSubmitInterceptor.java
View file @
9145a8e9
...
...
@@ -2,6 +2,7 @@ package com.mortals.xhx.busiz.security.filter;
import
com.alibaba.fastjson.JSONObject
;
import
com.mortals.framework.service.IAuthTokenService
;
import
com.mortals.framework.service.ICacheService
;
import
com.mortals.framework.service.IUser
;
import
com.mortals.framework.web.interceptor.BaseInterceptor
;
import
com.mortals.xhx.base.framework.annotation.ApiUserAuth
;
...
...
@@ -16,6 +17,10 @@ import javax.servlet.http.HttpServletRequest;
import
javax.servlet.http.HttpServletResponse
;
import
java.lang.reflect.Method
;
import
static
com
.
mortals
.
xhx
.
common
.
key
.
ErrorCode
.
TOKEN_AUTH_FAIL
;
import
static
com
.
mortals
.
xhx
.
common
.
key
.
ErrorCode
.
TOKEN_AUTH_FAIL_CONTENT
;
import
static
com
.
mortals
.
xhx
.
common
.
key
.
RedisKey
.
KEY_TOKEN_API_CACHE
;
/**
* api接口权限验证
*
...
...
@@ -27,6 +32,8 @@ public class ApiSubmitInterceptor extends BaseInterceptor {
@Autowired
private
IAuthTokenService
authTokenService
;
@Autowired
private
ICacheService
cacheService
;
@Override
public
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
)
throws
Exception
{
...
...
@@ -38,8 +45,8 @@ public class ApiSubmitInterceptor extends BaseInterceptor {
//校验
if
(!
this
.
verifyApiUser
(
request
))
{
JSONObject
ret
=
new
JSONObject
();
ret
.
put
(
"code"
,
ApiRespCodeEnum
.
TOKEN_FAILED
.
getValue
()
);
ret
.
put
(
"msg"
,
ApiRespCodeEnum
.
TOKEN_FAILED
.
getLabel
()
);
ret
.
put
(
"code"
,
TOKEN_AUTH_FAIL
);
ret
.
put
(
"msg"
,
TOKEN_AUTH_FAIL_CONTENT
);
super
.
writeJsonResponse
(
response
,
200
,
JSONObject
.
toJSONString
(
ret
));
return
false
;
}
...
...
@@ -51,12 +58,16 @@ public class ApiSubmitInterceptor extends BaseInterceptor {
}
public
boolean
verifyApiUser
(
HttpServletRequest
request
)
{
IUser
apiUser
=
authTokenService
.
getLoginUser
(
request
);
if
(!
ObjectUtils
.
isEmpty
(
apiUser
)
)
{
// authTokenService.verifyToken(apiUser);
return
true
;
}
String
token
=
authTokenService
.
getToken
(
request
);
if
(
cacheService
.
exists
(
KEY_TOKEN_API_CACHE
+
token
))
return
true
;
return
false
;
// IUser apiUser = authTokenService.getLoginUser(request);
// if (!ObjectUtils.isEmpty(apiUser) ) {
// // authTokenService.verifyToken(apiUser);
// return true;
// }
// return false;
}
}
device-manager/src/main/java/com/mortals/xhx/busiz/web/DeviceApiController.java
View file @
9145a8e9
package
com.mortals.xhx.busiz.web
;
import
cn.hutool.core.date.DateUnit
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.util.IdUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
...
...
@@ -8,6 +10,7 @@ import com.mortals.framework.annotation.UnAuth;
import
com.mortals.framework.common.Rest
;
import
com.mortals.framework.exception.AppException
;
import
com.mortals.framework.service.IAuthTokenService
;
import
com.mortals.framework.service.ICacheService
;
import
com.mortals.framework.util.DateUtils
;
import
com.mortals.xhx.base.framework.annotation.ApiUserAuth
;
import
com.mortals.xhx.base.login.web.LoginForm
;
...
...
@@ -56,6 +59,7 @@ import java.util.stream.Collectors;
import
static
com
.
mortals
.
xhx
.
common
.
key
.
Constant
.
DES_STR
;
import
static
com
.
mortals
.
xhx
.
common
.
key
.
Constant
.
ENCRYPT_STR
;
import
static
com
.
mortals
.
xhx
.
common
.
key
.
ErrorCode
.*;
import
static
com
.
mortals
.
xhx
.
common
.
key
.
RedisKey
.
KEY_TOKEN_API_CACHE
;
/**
* 设备
...
...
@@ -99,6 +103,8 @@ public class DeviceApiController {
private
FirmService
firmService
;
@Autowired
private
DeviceLogService
deviceLogService
;
@Autowired
private
ICacheService
cacheService
;
/**
* 设备注册
...
...
@@ -114,9 +120,6 @@ public class DeviceApiController {
DeviceResp
deviceResp
=
new
DeviceResp
();
try
{
DeviceEntity
deviceEntity
=
checkDeviceExistAndCreate
(
req
);
if
(
deviceEntity
.
getDeviceStatus
()
==
DeviceStatusEnum
.
未激活
.
getValue
())
{
throw
new
AppException
(
DEVICE_UNACTIVE
,
DEVICE_UNACTIVE_CONTENT
);
}
DeviceQueueAuthInfo
authInfo
=
new
DeviceQueueAuthInfo
();
authInfo
.
setHost
(
host
);
authInfo
.
setPort
(
port
);
...
...
@@ -139,6 +142,10 @@ public class DeviceApiController {
throw
new
AppException
(
PLATFORM_IS_EMPTY
,
PLATFORM_IS_EMPTY_CONTENT
);
}
if
(
deviceEntity
.
getDeviceStatus
()
==
DeviceStatusEnum
.
未激活
.
getValue
())
{
throw
new
AppException
(
DEVICE_UNACTIVE
,
DEVICE_UNACTIVE_CONTENT
);
}
authInfo
.
setExchangeName
(
platformEntity
.
getPlatformSn
()
+
Constant
.
EXCHANGE_SPLIT
+
productEntity
.
getProductCode
());
authInfo
.
setUploadTopicFilter
(
Constant
.
UPLOAD_TOPIC
+
deviceEntity
.
getDeviceCode
());
authInfo
.
setDownTopicFilter
(
Constant
.
DOWN_TOPIC
+
deviceEntity
.
getDeviceCode
());
...
...
@@ -146,7 +153,7 @@ public class DeviceApiController {
RegisterResp
registerResp
=
new
RegisterResp
();
registerResp
.
setRabbmitInfo
(
authInfo
);
ServerInfo
serverInfo
=
new
ServerInfo
();
serverInfo
.
setHomeUrl
(
productEntity
.
getHomeUrl
()
==
null
?
""
:
productEntity
.
getHomeUrl
());
serverInfo
.
setHomeUrl
(
productEntity
.
getHomeUrl
()
==
null
?
""
:
productEntity
.
getHomeUrl
());
serverInfo
.
setServerUrl
(
platformEntity
.
getSendUrl
());
registerResp
.
setServiceInfo
(
serverInfo
);
DeviceInfo
deviceInfo
=
new
DeviceInfo
();
...
...
@@ -193,10 +200,15 @@ public class DeviceApiController {
try
{
UserEntity
userEntity
=
userService
.
doLogin
(
loginForm
.
getLoginName
(),
loginForm
.
getPassword
(),
""
);
if
(!
ObjectUtils
.
isEmpty
(
userEntity
))
{
this
.
authTokenService
.
setUser
(
userEntity
);
userEntity
.
setExpireTime
(
DateUtils
.
addCurrDate
(
7
).
getTime
());
userEntity
.
setToken
(
IdUtil
.
fastSimpleUUID
());
String
token
=
authTokenService
.
createToken
(
userEntity
);
// this.authTokenService.setUser(userEntity);
// userEntity.setExpireTime(DateUtils.addCurrDate(7).getTime());
// userEntity.setToken(IdUtil.fastSimpleUUID());
// String token = authTokenService.createToken(userEntity);
String
token
=
IdUtil
.
fastSimpleUUID
();
//long expireTime = DateUtil.between(DateUtil.beginOfWeek(new Date()), DateUtil.endOfWeek(new Date()), DateUnit.SECOND);
cacheService
.
setnx
(
KEY_TOKEN_API_CACHE
+
token
,
""
,
604800
);
rsp
.
setData
(
token
);
}
}
catch
(
AppException
e
)
{
...
...
@@ -219,7 +231,7 @@ public class DeviceApiController {
*
* @return
*/
@
GetMapping
(
"deviceInit"
)
@
RequestMapping
(
value
=
"deviceInit"
,
method
=
{
RequestMethod
.
POST
,
RequestMethod
.
GET
}
)
public
String
deviceInit
()
{
ApiResp
<
DeviceInitResp
>
rsp
=
new
ApiResp
<>();
rsp
.
setCode
(
ApiRespCodeEnum
.
SUCCESS
.
getValue
());
...
...
@@ -292,7 +304,6 @@ public class DeviceApiController {
if
(
ObjectUtils
.
isEmpty
(
req
.
getDeviceCode
()))
{
throw
new
AppException
(
DEVICE_CODE_IS_EMPTY
,
DEVICE_CODE_IS_EMPTY_CONTENT
);
}
if
(
ObjectUtils
.
isEmpty
(
req
.
getSiteId
()))
{
throw
new
AppException
(
SITEID_IS_EMPTY
,
SITEID_IS_EMPTY_CONTENT
);
}
...
...
@@ -467,9 +478,9 @@ public class DeviceApiController {
TbQueueMsgHeaders
header
=
new
DefaultTbQueueMsgHeaders
();
header
.
put
(
MessageHeader
.
MESSAGETYPE
,
Constant
.
MESSAGETYPE_HEARTBEAT
);
header
.
put
(
MessageHeader
.
DEVICECODE
,
deviceEntity
.
getDeviceCode
());
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
for
(
int
i
=
0
;
i
<
10
0
;
i
++)
{
deviceService
.
sendDeviceMessage
(
deviceEntity
,
info
,
header
,
JSON
.
toJSONString
(
req
),
null
);
//
Thread.sleep(50);
Thread
.
sleep
(
50
);
}
//log.info(String.format("sendMsgResp:%s", JSON.toJSONString(sendDeviceMessageResp)));
}
...
...
device-manager/src/main/java/com/mortals/xhx/common/key/ErrorCode.java
View file @
9145a8e9
...
...
@@ -108,4 +108,7 @@ public interface ErrorCode {
public
static
final
int
DEVICE_NOT_EXIST
=
1009
;
public
static
final
String
DEVICE_NOT_EXIST_CONTENT
=
"当前设备不存在!"
;
public
static
final
int
TOKEN_AUTH_FAIL
=
1010
;
public
static
final
String
TOKEN_AUTH_FAIL_CONTENT
=
"token认证失败!"
;
}
device-manager/src/main/java/com/mortals/xhx/common/key/RedisKey.java
View file @
9145a8e9
...
...
@@ -21,4 +21,6 @@ public class RedisKey {
public
static
final
String
KEY_PLATFORM_CACHE
=
"platformDict"
;
public
static
final
String
KEY_PRODUCT_CACHE
=
"productDict"
;
public
static
final
String
KEY_TOKEN_API_CACHE
=
"token:api:"
;
}
device-manager/src/main/java/com/mortals/xhx/daemon/applicationservice/DeviceMsgComsumerStartedService.java
View file @
9145a8e9
...
...
@@ -164,7 +164,7 @@ public class DeviceMsgComsumerStartedService implements IApplicationStartedServi
boolean
bool
=
false
;
DeviceEntity
deviceEntity
=
deviceService
.
getExtCache
(
deviceCode
);
if
(!
ObjectUtils
.
isEmpty
(
deviceEntity
))
{
cacheService
.
setnx
(
RedisKey
.
KEY_DEVICE_ONLINE_CACHE
+
deviceEntity
.
getDeviceCode
(),
""
,
GlobalSysInfo
.
getParamIntValue
(
Constant
.
HEARTBEAT_TIMEOUT
,
1
8
0
));
cacheService
.
setnx
(
RedisKey
.
KEY_DEVICE_ONLINE_CACHE
+
deviceEntity
.
getDeviceCode
(),
""
,
GlobalSysInfo
.
getParamIntValue
(
Constant
.
HEARTBEAT_TIMEOUT
,
1
2
0
));
if
(
deviceEntity
.
getDeviceStatus
()
==
DeviceStatusEnum
.
离线
.
getValue
())
{
bool
=
true
;
}
...
...
device-manager/src/test/java/com/mortals/httpclient/device/DeviceController.http
View file @
9145a8e9
...
...
@@ -118,9 +118,9 @@ Authorization: {{authToken}}
Content-Type: application/json
{
"receiveMethod":
3
,
"receiveMethod":
1
,
"deviceName": "测试接口创建设备3",
"deviceCode": "a12345678",
"deviceCode": "a12345678
99
",
"siteId": 123,
"siteCode": "adfasfdasfdasf",
"siteName": "测试站点",
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment