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
7c6bee8c
Commit
7c6bee8c
authored
Feb 15, 2023
by
赵啸非
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加批量激活设备
parent
ef89d1f6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
35 deletions
+62
-35
device-manager/src/main/java/com/mortals/xhx/busiz/web/DeviceApiController.java
...n/java/com/mortals/xhx/busiz/web/DeviceApiController.java
+62
-35
No files found.
device-manager/src/main/java/com/mortals/xhx/busiz/web/DeviceApiController.java
View file @
7c6bee8c
package
com.mortals.xhx.busiz.web
;
import
cn.hutool.core.io.FileUtil
;
import
cn.hutool.core.lang.Validator
;
import
cn.hutool.core.net.URLDecoder
;
import
cn.hutool.core.net.url.UrlBuilder
;
import
cn.hutool.core.util.IdUtil
;
...
...
@@ -63,12 +64,10 @@ import org.springframework.util.ObjectUtils;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletRequest
;
import
java.net.URI
;
import
java.net.URL
;
import
java.nio.charset.Charset
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.*
;
import
java.util.stream.Collectors
;
import
static
com
.
mortals
.
xhx
.
common
.
key
.
Constant
.*;
...
...
@@ -139,14 +138,11 @@ public class DeviceApiController {
* @return
*/
@PostMapping
(
"register"
)
public
String
register
(
HttpServletRequest
request
,
@RequestBody
DeviceReq
req
)
{
public
String
register
(
HttpServletRequest
request
,
@RequestBody
DeviceReq
req
)
{
log
.
info
(
"【设备注册】【请求体】--> "
+
JSONObject
.
toJSONString
(
req
));
log
.
info
(
"request uri:{},request url:{},serverName:{}"
,
request
.
getRequestURI
(),
request
.
getRequestURL
(),
request
.
getServerName
());
//ServletUtil.
//ServletUtil.getClientIP()
String
serverName
=
request
.
getServerName
();
Integer
serverPort
=
request
.
getServerPort
();
log
.
info
(
"request uri:{},request url:{},serverName:{},serverPort:{}"
,
request
.
getRequestURI
(),
request
.
getRequestURL
(),
serverName
,
serverPort
);
ApiResp
<
DeviceResp
>
rsp
=
new
ApiResp
<>();
rsp
.
setCode
(
ApiRespCodeEnum
.
SUCCESS
.
getValue
());
DeviceResp
deviceResp
=
new
DeviceResp
();
...
...
@@ -156,7 +152,14 @@ public class DeviceApiController {
DeviceEntity
deviceEntity
=
checkDeviceExistAndCreate
(
req
);
DeviceQueueAuthInfo
authInfo
=
new
DeviceQueueAuthInfo
();
//authInfo.setHost(masterhost);
//设备地址修改为客户端访问服务端的ip地址
// authInfo.setHost(url.getHost());
if
(
Validator
.
isIpv4
(
serverName
)){
authInfo
.
setHost
(
serverName
);
}
else
{
log
.
info
(
"设置后台定义的参数地址!{}"
,
url
.
toString
());
authInfo
.
setHost
(
url
.
getHost
());
}
authInfo
.
setPort
(
port
);
authInfo
.
setUsername
(
username
);
authInfo
.
setPassword
(
password
);
...
...
@@ -177,7 +180,7 @@ public class DeviceApiController {
throw
new
AppException
(
PLATFORM_IS_EMPTY
,
PLATFORM_IS_EMPTY_CONTENT
);
}
if
(
deviceEntity
.
getDeviceStatus
()
==
DeviceStatusEnum
.
未激活
.
getValue
(
))
{
if
(
Objects
.
equals
(
deviceEntity
.
getDeviceStatus
(),
DeviceStatusEnum
.
未激活
.
getValue
()
))
{
throw
new
AppException
(
DEVICE_UNACTIVE
,
DEVICE_UNACTIVE_CONTENT
);
}
...
...
@@ -189,9 +192,17 @@ public class DeviceApiController {
registerResp
.
setRabbmitInfo
(
authInfo
);
ServerInfo
serverInfo
=
new
ServerInfo
();
//判断设备是否设置了url 如果设置了,则用设备的 否则用产品的
buildHomeUrl
(
deviceEntity
,
productEntity
,
serverInfo
);
//对外
buildHomeUrl
(
deviceEntity
,
productEntity
,
serverInfo
,
serverName
,
serverPort
);
//对外地址,访问ip+端口 端口号由platformEntity.getSendUrl()获取
URI
uri
=
new
URI
(
platformEntity
.
getSendUrl
());
int
port
=
uri
.
getPort
();
if
(
port
!=
-
1
&&
Validator
.
isIpv4
(
serverName
))
{
String
serverUrl
=
UrlBuilder
.
ofHttp
(
serverName
).
setPort
(
port
).
build
();
serverInfo
.
setServerUrl
(
serverUrl
);
}
else
{
serverInfo
.
setServerUrl
(
platformEntity
.
getSendUrl
());
}
//serverInfo.setServerUrl(platformEntity.getSendUrl());
//String phpUrl=GlobalSysInfo.getParamValue(PARAM_SERVER_PHP_HTTP_URL, "http://10.12.185.213:8090");
//serverInfo.setServerUrl(phpUrl);
registerResp
.
setServiceInfo
(
serverInfo
);
...
...
@@ -350,8 +361,10 @@ public class DeviceApiController {
* @return
*/
@PostMapping
(
"deviceUpdate"
)
public
String
deviceUpdateApi
(
@RequestBody
DeviceReq
req
)
{
log
.
info
(
"【设备前端新增或更新】【请求体】--> "
+
JSONObject
.
toJSONString
(
req
));
public
String
deviceUpdateApi
(
HttpServletRequest
request
,
@RequestBody
DeviceReq
req
)
{
String
serverName
=
request
.
getServerName
();
int
serverPort
=
request
.
getServerPort
();
log
.
info
(
"【设备前端新增或更新】【请求体】-->{} ,serverName:{}"
,
JSONObject
.
toJSONString
(
req
),
serverName
);
ApiResp
<
DeviceResp
>
rsp
=
new
ApiResp
<>();
rsp
.
setCode
(
ApiRespCodeEnum
.
SUCCESS
.
getValue
());
DeviceResp
deviceResp
=
new
DeviceResp
();
...
...
@@ -417,7 +430,7 @@ public class DeviceApiController {
registerResp
.
setRabbmitInfo
(
authInfo
);
ServerInfo
serverInfo
=
new
ServerInfo
();
buildHomeUrl
(
deviceEntity
,
productEntity
,
serverInfo
);
buildHomeUrl
(
deviceEntity
,
productEntity
,
serverInfo
,
serverName
,
serverPort
);
serverInfo
.
setServerUrl
(
platformEntity
.
getSendUrl
());
//String phpUrl=GlobalSysInfo.getParamValue(PARAM_SERVER_PHP_HTTP_URL, "http://10.12.185.213:8090");
//serverInfo.setServerUrl(phpUrl);
...
...
@@ -433,6 +446,7 @@ public class DeviceApiController {
deviceInfo
.
setEnabled
(
deviceEntity
.
getEnabled
());
deviceInfo
.
setSource
(
deviceEntity
.
getSource
());
registerResp
.
setDeviceInfo
(
deviceInfo
);
log
.
info
(
"响应【设备前端新增或更新】【响应体】--> "
+
JSONObject
.
toJSONString
(
registerResp
));
String
content
=
EncryptUtil
.
myEnscrt
(
JSON
.
toJSONString
(
registerResp
),
9
,
DES_STR
,
ENCRYPT_STR
);
deviceResp
.
setContent
(
content
);
rsp
.
setData
(
deviceResp
);
...
...
@@ -447,7 +461,6 @@ public class DeviceApiController {
rsp
.
setMsg
(
e
.
getMessage
());
return
JSON
.
toJSONString
(
rsp
);
}
//log.info("响应【设备前端新增或更新】【响应体】--> " + JSONObject.toJSONString(rsp));
return
JSON
.
toJSONString
(
rsp
);
}
...
...
@@ -459,7 +472,9 @@ public class DeviceApiController {
* @return
*/
@PostMapping
(
"checkVersion"
)
public
String
checkVersion
(
@RequestBody
DeviceReq
req
)
{
public
String
checkVersion
(
HttpServletRequest
request
,
@RequestBody
DeviceReq
req
)
{
String
serverName
=
request
.
getServerName
();
int
serverPort
=
request
.
getServerPort
();
log
.
info
(
"【检查设备最新版本信息】【请求体】--> "
+
JSONObject
.
toJSONString
(
req
));
ApiResp
<
DeviceResp
>
rsp
=
new
ApiResp
<>();
rsp
.
setCode
(
ApiRespCodeEnum
.
SUCCESS
.
getValue
());
...
...
@@ -480,8 +495,9 @@ public class DeviceApiController {
ProductVersionInfo
productVersionInfo
=
new
ProductVersionInfo
();
BeanUtils
.
copyProperties
(
productVersionEntity
,
productVersionInfo
,
BeanUtil
.
getNullPropertyNames
(
productVersionEntity
));
buildDownloadUrl
(
productVersionEntity
,
productVersionInfo
);
buildDownloadUrl
(
productVersionEntity
,
productVersionInfo
,
serverName
,
serverPort
);
String
content
=
EncryptUtil
.
myEnscrt
(
JSON
.
toJSONString
(
productVersionInfo
),
9
,
DES_STR
,
ENCRYPT_STR
);
log
.
info
(
"响应【设备版本检查】【响应体】--> "
+
JSONObject
.
toJSONString
(
productVersionInfo
));
deviceResp
.
setContent
(
content
);
rsp
.
setData
(
deviceResp
);
}
catch
(
AppException
e
)
{
...
...
@@ -494,7 +510,6 @@ public class DeviceApiController {
rsp
.
setMsg
(
e
.
getMessage
());
return
JSON
.
toJSONString
(
rsp
);
}
log
.
info
(
"响应【设备版本检查】【响应体】--> "
+
JSONObject
.
toJSONString
(
rsp
));
return
JSON
.
toJSONString
(
rsp
);
}
...
...
@@ -897,7 +912,7 @@ public class DeviceApiController {
}
}
private
void
buildHomeUrl
(
DeviceEntity
deviceEntity
,
ProductEntity
productEntity
,
ServerInfo
serverInfo
)
{
private
void
buildHomeUrl
(
DeviceEntity
deviceEntity
,
ProductEntity
productEntity
,
ServerInfo
serverInfo
,
String
serverName
,
Integer
serverPort
)
{
String
homeUrl
=
""
;
if
(!
ObjectUtils
.
isEmpty
(
productEntity
.
getHomeUrl
()))
{
homeUrl
=
productEntity
.
getHomeUrl
();
...
...
@@ -908,16 +923,21 @@ public class DeviceApiController {
}
//log.info("domain:" + GlobalSysInfo.getParamValue(PARAM_SERVER_HTTP_URL, ""));
String
domain
=
GlobalSysInfo
.
getParamValue
(
PARAM_SERVER_HTTP_URL
,
"http://192.168.3.24:11078"
);
//domain+homeUrl;
if
(
Validator
.
isIpv4
(
serverName
)){
String
str
=
UrlBuilder
.
ofHttp
(
serverName
).
setPort
(
serverPort
>
0
?
serverPort:
11078
).
addPath
(
homeUrl
).
build
();
String
decodeStr
=
URLDecoder
.
decode
(
str
,
Charset
.
defaultCharset
());
serverInfo
.
setHomeUrl
(
decodeStr
);
serverInfo
.
setEventUrl
(
productEntity
.
getEventUrl
());
}
else
{
String
str
=
UrlBuilder
.
of
(
domain
.
trim
()).
addPath
(
homeUrl
).
build
();
String
decodeStr
=
URLDecoder
.
decode
(
str
,
Charset
.
defaultCharset
());
serverInfo
.
setHomeUrl
(
decodeStr
);
//serverInfo.setHomeUrl(domain + "/" + homeUrl);
//log.info("homeurl:" + serverInfo.getHomeUrl());
serverInfo
.
setEventUrl
(
productEntity
.
getEventUrl
());
}
}
private
void
buildDownloadUrl
(
ProductVersionEntity
productVersionEntity
,
ProductVersionInfo
productVersionInfo
)
{
private
void
buildDownloadUrl
(
ProductVersionEntity
productVersionEntity
,
ProductVersionInfo
productVersionInfo
,
String
serverName
,
Integer
serverPort
)
{
String
download
=
""
;
if
(!
ObjectUtils
.
isEmpty
(
productVersionEntity
.
getFilePath
()))
{
String
fileType
=
FileUtil
.
extName
(
productVersionEntity
.
getFilePath
());
...
...
@@ -932,9 +952,16 @@ public class DeviceApiController {
}
}
String
domain
=
GlobalSysInfo
.
getParamValue
(
PARAM_SERVER_HTTP_URL
,
"http://192.168.0.98:11091"
);
//String temp = domain + "/" + download;
productVersionInfo
.
setDownloadUrl
(
UrlBuilder
.
of
(
domain
).
addPath
(
download
).
build
());
//productVersionInfo.setDownloadUrl(temp);
if
(
Validator
.
isIpv4
(
serverName
)){
String
str
=
UrlBuilder
.
ofHttp
(
serverName
).
setPort
(
serverPort
>
0
?
serverPort:
11078
).
addPath
(
download
).
build
();
String
decodeStr
=
URLDecoder
.
decode
(
str
,
Charset
.
defaultCharset
());
productVersionInfo
.
setDownloadUrl
(
decodeStr
);
}
else
{
String
str
=
UrlBuilder
.
of
(
domain
.
trim
()).
addPath
(
download
).
build
();
String
decodeStr
=
URLDecoder
.
decode
(
str
,
Charset
.
defaultCharset
());
productVersionInfo
.
setDownloadUrl
(
decodeStr
);
}
log
.
info
(
"downurl:"
+
productVersionInfo
.
getDownloadUrl
());
}
...
...
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