Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
H
haikang-client
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
杨立
haikang-client
Commits
647b1cab
提交
647b1cab
authored
9月 28, 2021
作者:
wangqiang
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'origin/master'
上级
093aa9c6
a9472749
隐藏空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
65 行增加
和
68 行删除
+65
-68
MqttServiceImpl.java
...java/com/priusis/client/service/core/MqttServiceImpl.java
+2
-13
DeviceInfoController.java
...ain/java/com/priusis/controller/DeviceInfoController.java
+5
-11
ProgramController.java
...c/main/java/com/priusis/controller/ProgramController.java
+5
-13
RemoteControlController.java
.../java/com/priusis/controller/RemoteControlController.java
+5
-16
MacAddrUtil.java
...pc-client/src/main/java/com/priusis/util/MacAddrUtil.java
+21
-0
ApqInfoApplication.java
...pc-info/src/main/java/com/priusis/ApqInfoApplication.java
+3
-8
MacAddrUtil.java
apq-pc-info/src/main/java/com/priusis/util/MacAddrUtil.java
+21
-0
RestTest.java
apq-pc-info/src/test/java/com/priusis/RestTest.java
+3
-7
没有找到文件。
apq-pc-client/src/main/java/com/priusis/client/service/core/MqttServiceImpl.java
浏览文件 @
647b1cab
...
@@ -14,6 +14,7 @@ import com.priusis.client.service.data.*;
...
@@ -14,6 +14,7 @@ import com.priusis.client.service.data.*;
import
com.priusis.client.util.JsonTools
;
import
com.priusis.client.util.JsonTools
;
import
com.priusis.controller.RemoteControlController
;
import
com.priusis.controller.RemoteControlController
;
import
com.priusis.monitor.mqtt.*
;
import
com.priusis.monitor.mqtt.*
;
import
com.priusis.util.MacAddrUtil
;
import
com.priusis.util.SysConfigUtil
;
import
com.priusis.util.SysConfigUtil
;
import
io.netty.buffer.ByteBuf
;
import
io.netty.buffer.ByteBuf
;
import
io.netty.channel.nio.NioEventLoopGroup
;
import
io.netty.channel.nio.NioEventLoopGroup
;
...
@@ -25,15 +26,12 @@ import org.apache.commons.lang3.StringUtils;
...
@@ -25,15 +26,12 @@ import org.apache.commons.lang3.StringUtils;
import
org.eclipse.paho.client.mqttv3.MqttMessage
;
import
org.eclipse.paho.client.mqttv3.MqttMessage
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
oshi.hardware.NetworkIF
;
import
javax.annotation.PostConstruct
;
import
javax.annotation.PostConstruct
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
javax.net.ssl.KeyManagerFactory
;
import
javax.net.ssl.KeyManagerFactory
;
import
javax.net.ssl.TrustManagerFactory
;
import
javax.net.ssl.TrustManagerFactory
;
import
java.io.*
;
import
java.io.*
;
import
java.net.InetAddress
;
import
java.net.NetworkInterface
;
import
java.net.URL
;
import
java.net.URL
;
import
java.nio.charset.StandardCharsets
;
import
java.nio.charset.StandardCharsets
;
import
java.security.KeyStore
;
import
java.security.KeyStore
;
...
@@ -678,9 +676,7 @@ public class MqttServiceImpl implements MqttService, MqttHandler, MqttClientCall
...
@@ -678,9 +676,7 @@ public class MqttServiceImpl implements MqttService, MqttHandler, MqttClientCall
private
MqttClientSecurityConfiguration
getClientSecurityByMac
()
{
private
MqttClientSecurityConfiguration
getClientSecurityByMac
()
{
try
{
try
{
NetworkIF
networkIF
=
new
NetworkIF
();
String
mac
=
MacAddrUtil
.
get
();
networkIF
.
setNetworkInterface
(
NetworkInterface
.
getByInetAddress
(
InetAddress
.
getLocalHost
()));
String
mac
=
networkIF
.
getMacaddr
();
if
(
StrUtil
.
isBlank
(
mac
))
{
if
(
StrUtil
.
isBlank
(
mac
))
{
log
.
warn
(
"未获取到MAC地址"
);
log
.
warn
(
"未获取到MAC地址"
);
return
null
;
return
null
;
...
@@ -701,11 +697,4 @@ public class MqttServiceImpl implements MqttService, MqttHandler, MqttClientCall
...
@@ -701,11 +697,4 @@ public class MqttServiceImpl implements MqttService, MqttHandler, MqttClientCall
//return mqttClientSecurityConfiguration;
//return mqttClientSecurityConfiguration;
return
null
;
return
null
;
}
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
NetworkIF
networkIF
=
new
NetworkIF
();
networkIF
.
setNetworkInterface
(
NetworkInterface
.
getByInetAddress
(
InetAddress
.
getLocalHost
()));
String
mac
=
networkIF
.
getMacaddr
();
System
.
out
.
println
(
mac
);
}
}
}
apq-pc-client/src/main/java/com/priusis/controller/DeviceInfoController.java
浏览文件 @
647b1cab
...
@@ -4,13 +4,12 @@ import cn.hutool.core.io.unit.DataSizeUtil;
...
@@ -4,13 +4,12 @@ import cn.hutool.core.io.unit.DataSizeUtil;
import
cn.hutool.core.map.MapUtil
;
import
cn.hutool.core.map.MapUtil
;
import
cn.hutool.system.oshi.OshiUtil
;
import
cn.hutool.system.oshi.OshiUtil
;
import
com.priusis.lib.R
;
import
com.priusis.lib.R
;
import
com.priusis.util.MacAddrUtil
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
oshi.hardware.NetworkIF
;
import
java.net.InetAddress
;
import
java.net.InetAddress
;
import
java.net.NetworkInterface
;
import
java.net.SocketException
;
import
java.net.SocketException
;
import
java.net.UnknownHostException
;
import
java.net.UnknownHostException
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -26,14 +25,11 @@ public class DeviceInfoController {
...
@@ -26,14 +25,11 @@ public class DeviceInfoController {
@GetMapping
(
value
=
"get"
)
@GetMapping
(
value
=
"get"
)
public
R
<
Map
<
String
,
Object
>>
get
()
throws
UnknownHostException
,
SocketException
{
public
R
<
Map
<
String
,
Object
>>
get
()
throws
UnknownHostException
,
SocketException
{
InetAddress
inetAddress
=
InetAddress
.
getLocalHost
();
NetworkIF
networkIF
=
new
NetworkIF
();
networkIF
.
setNetworkInterface
(
NetworkInterface
.
getByInetAddress
(
inetAddress
));
Map
<
String
,
Object
>
info
=
MapUtil
.<
String
,
Object
>
builder
()
Map
<
String
,
Object
>
info
=
MapUtil
.<
String
,
Object
>
builder
()
.
put
(
"operatingSystem"
,
OshiUtil
.
getOs
().
toString
())
.
put
(
"operatingSystem"
,
OshiUtil
.
getOs
().
toString
())
.
put
(
"mac"
,
networkIF
.
getMacaddr
())
.
put
(
"mac"
,
MacAddrUtil
.
get
())
.
put
(
"baseboard"
,
OshiUtil
.
getSystem
().
getBaseboard
().
getManufacturer
()
+
" "
+
OshiUtil
.
getSystem
().
getBaseboard
().
getVersion
())
.
put
(
"baseboard"
,
OshiUtil
.
getSystem
().
getBaseboard
().
getManufacturer
()
+
" "
+
OshiUtil
.
getSystem
().
getBaseboard
().
getVersion
())
.
put
(
"ip"
,
inetAddress
.
getHostAddress
())
.
put
(
"ip"
,
InetAddress
.
getLocalHost
()
.
getHostAddress
())
.
put
(
"cpuModel"
,
OshiUtil
.
getCpuInfo
(
0
).
getCpuModel
())
.
put
(
"cpuModel"
,
OshiUtil
.
getCpuInfo
(
0
).
getCpuModel
())
.
put
(
"cpuTemp"
,
OshiUtil
.
getSensors
().
getCpuTemperature
())
.
put
(
"cpuTemp"
,
OshiUtil
.
getSensors
().
getCpuTemperature
())
.
put
(
"memoryCap"
,
DataSizeUtil
.
format
(
OshiUtil
.
getMemory
().
getTotal
()))
.
put
(
"memoryCap"
,
DataSizeUtil
.
format
(
OshiUtil
.
getMemory
().
getTotal
()))
...
@@ -43,13 +39,11 @@ public class DeviceInfoController {
...
@@ -43,13 +39,11 @@ public class DeviceInfoController {
return
R
.
success
(
info
);
return
R
.
success
(
info
);
}
}
public
static
void
main
(
String
[]
args
)
throws
SocketException
,
UnknownHostException
{
public
static
void
main
(
String
[]
args
)
throws
UnknownHostException
{
System
.
out
.
println
(
"操作系统"
);
System
.
out
.
println
(
"操作系统"
);
System
.
out
.
println
(
OshiUtil
.
getOs
().
toString
());
System
.
out
.
println
(
OshiUtil
.
getOs
().
toString
());
System
.
out
.
println
(
"MAC地址"
);
System
.
out
.
println
(
"MAC地址"
);
NetworkIF
networkIF
=
new
NetworkIF
();
System
.
out
.
println
(
MacAddrUtil
.
get
());
networkIF
.
setNetworkInterface
(
NetworkInterface
.
getByInetAddress
(
InetAddress
.
getLocalHost
()));
System
.
out
.
println
(
networkIF
.
getMacaddr
());
System
.
out
.
println
(
"主板"
);
System
.
out
.
println
(
"主板"
);
System
.
out
.
println
(
OshiUtil
.
getSystem
().
getBaseboard
().
getManufacturer
()
+
" "
+
OshiUtil
.
getSystem
().
getBaseboard
().
getVersion
());
System
.
out
.
println
(
OshiUtil
.
getSystem
().
getBaseboard
().
getManufacturer
()
+
" "
+
OshiUtil
.
getSystem
().
getBaseboard
().
getVersion
());
System
.
out
.
println
(
"IP"
);
System
.
out
.
println
(
"IP"
);
...
...
apq-pc-client/src/main/java/com/priusis/controller/ProgramController.java
浏览文件 @
647b1cab
...
@@ -13,6 +13,7 @@ import cn.hutool.json.JSONUtil;
...
@@ -13,6 +13,7 @@ import cn.hutool.json.JSONUtil;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.priusis.cache.InstalledProgramCache
;
import
com.priusis.cache.InstalledProgramCache
;
import
com.priusis.lib.R
;
import
com.priusis.lib.R
;
import
com.priusis.util.MacAddrUtil
;
import
com.priusis.util.SysConfigUtil
;
import
com.priusis.util.SysConfigUtil
;
import
lombok.SneakyThrows
;
import
lombok.SneakyThrows
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
...
@@ -20,7 +21,6 @@ import org.springframework.beans.factory.annotation.Value;
...
@@ -20,7 +21,6 @@ import org.springframework.beans.factory.annotation.Value;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
oshi.hardware.NetworkIF
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
...
@@ -28,10 +28,6 @@ import javax.validation.constraints.NotBlank;
...
@@ -28,10 +28,6 @@ import javax.validation.constraints.NotBlank;
import
javax.validation.constraints.Pattern
;
import
javax.validation.constraints.Pattern
;
import
java.io.File
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.net.InetAddress
;
import
java.net.NetworkInterface
;
import
java.net.SocketException
;
import
java.net.UnknownHostException
;
import
java.text.DecimalFormat
;
import
java.text.DecimalFormat
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.List
;
...
@@ -69,7 +65,7 @@ public class ProgramController {
...
@@ -69,7 +65,7 @@ public class ProgramController {
@RequestParam
(
required
=
false
,
defaultValue
=
"1"
)
Integer
current
,
@RequestParam
(
required
=
false
,
defaultValue
=
"1"
)
Integer
current
,
@RequestParam
(
required
=
false
,
defaultValue
=
"10"
)
Integer
size
)
@RequestParam
(
required
=
false
,
defaultValue
=
"10"
)
Integer
size
)
throws
IOException
{
throws
IOException
{
String
mac
=
getMacAddress
();
String
mac
=
MacAddrUtil
.
get
();
if
(
StrUtil
.
isBlank
(
mac
))
return
R
.
error
(
"未获取到MAC地址"
);
if
(
StrUtil
.
isBlank
(
mac
))
return
R
.
error
(
"未获取到MAC地址"
);
String
url
=
gateway
+
StrUtil
.
format
(
type
.
equals
(
"install"
)
?
installUrl
:
upgradeUrl
,
mac
,
current
,
size
);
String
url
=
gateway
+
StrUtil
.
format
(
type
.
equals
(
"install"
)
?
installUrl
:
upgradeUrl
,
mac
,
current
,
size
);
JSONObject
rsp
=
JSONUtil
.
parseObj
(
HttpUtil
.
get
(
url
));
JSONObject
rsp
=
JSONUtil
.
parseObj
(
HttpUtil
.
get
(
url
));
...
@@ -90,11 +86,12 @@ public class ProgramController {
...
@@ -90,11 +86,12 @@ public class ProgramController {
.
build
())
.
build
())
.
peek
(
m
->
programs
.
stream
()
.
peek
(
m
->
programs
.
stream
()
.
collect
(
Collectors
.
toMap
(
p
->
StrUtil
.
similar
(
p
.
get
(
"name"
).
toLowerCase
(),
m
.
get
(
"name"
).
toLowerCase
()),
.
collect
(
Collectors
.
toMap
(
p
->
StrUtil
.
similar
(
p
.
get
(
"name"
).
toLowerCase
(),
m
.
get
(
"name"
).
toLowerCase
()),
p
->
p
.
get
(
"version"
),
(
l
,
r
)
->
r
))
p
->
StrUtil
.
nullToEmpty
(
p
.
get
(
"version"
)
),
(
l
,
r
)
->
r
))
.
entrySet
()
.
entrySet
()
.
stream
()
.
stream
()
.
max
(
Map
.
Entry
.
comparingByKey
())
.
max
(
Map
.
Entry
.
comparingByKey
())
.
filter
(
e
->
e
.
getKey
()
>=
MIN_MATCH
)
.
filter
(
e
->
e
.
getKey
()
>=
MIN_MATCH
)
.
filter
(
e
->
StrUtil
.
isNotBlank
(
e
.
getValue
()))
.
ifPresent
(
e
->
m
.
put
(
"localVersion"
,
e
.
getValue
())))
.
ifPresent
(
e
->
m
.
put
(
"localVersion"
,
e
.
getValue
())))
.
collect
(
Collectors
.
toList
());
.
collect
(
Collectors
.
toList
());
return
R
.
success
(
page
.
setRecords
(
list
));
return
R
.
success
(
page
.
setRecords
(
list
));
...
@@ -152,7 +149,7 @@ public class ProgramController {
...
@@ -152,7 +149,7 @@ public class ProgramController {
@Scheduled
(
fixedDelay
=
60000
)
@Scheduled
(
fixedDelay
=
60000
)
protected
void
addProgram2Platform
()
throws
IOException
{
protected
void
addProgram2Platform
()
throws
IOException
{
String
mac
=
getMacAddress
();
String
mac
=
MacAddrUtil
.
get
();
if
(
StrUtil
.
isBlank
(
mac
))
{
if
(
StrUtil
.
isBlank
(
mac
))
{
log
.
warn
(
"未获取到MAC地址"
);
log
.
warn
(
"未获取到MAC地址"
);
return
;
return
;
...
@@ -163,9 +160,4 @@ public class ProgramController {
...
@@ -163,9 +160,4 @@ public class ProgramController {
JSONUtil
.
createObj
().
set
(
"macAddress"
,
mac
).
set
(
"programList"
,
programNames
).
toString
());
JSONUtil
.
createObj
().
set
(
"macAddress"
,
mac
).
set
(
"programList"
,
programNames
).
toString
());
}
}
private
String
getMacAddress
()
throws
UnknownHostException
,
SocketException
{
NetworkIF
networkIF
=
new
NetworkIF
();
networkIF
.
setNetworkInterface
(
NetworkInterface
.
getByInetAddress
(
InetAddress
.
getLocalHost
()));
return
networkIF
.
getMacaddr
();
}
}
}
apq-pc-client/src/main/java/com/priusis/controller/RemoteControlController.java
浏览文件 @
647b1cab
...
@@ -8,6 +8,7 @@ import cn.hutool.json.JSONObject;
...
@@ -8,6 +8,7 @@ import cn.hutool.json.JSONObject;
import
cn.hutool.json.JSONUtil
;
import
cn.hutool.json.JSONUtil
;
import
com.priusis.cache.InstalledProgramCache
;
import
com.priusis.cache.InstalledProgramCache
;
import
com.priusis.lib.R
;
import
com.priusis.lib.R
;
import
com.priusis.util.MacAddrUtil
;
import
com.priusis.util.SysConfigUtil
;
import
com.priusis.util.SysConfigUtil
;
import
lombok.SneakyThrows
;
import
lombok.SneakyThrows
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
...
@@ -18,16 +19,11 @@ import org.springframework.web.bind.annotation.GetMapping;
...
@@ -18,16 +19,11 @@ import org.springframework.web.bind.annotation.GetMapping;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
oshi.hardware.NetworkIF
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
javax.validation.constraints.NotNull
;
import
javax.validation.constraints.NotNull
;
import
java.io.File
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.net.InetAddress
;
import
java.net.NetworkInterface
;
import
java.net.SocketException
;
import
java.net.UnknownHostException
;
import
java.util.Timer
;
import
java.util.Timer
;
import
java.util.TimerTask
;
import
java.util.TimerTask
;
...
@@ -128,28 +124,21 @@ public class RemoteControlController {
...
@@ -128,28 +124,21 @@ public class RemoteControlController {
}
}
@GetMapping
(
value
=
"send_request"
)
@GetMapping
(
value
=
"send_request"
)
public
R
<
Void
>
sendRequest
(
@RequestParam
@NotNull
Long
minutes
)
public
R
<
Void
>
sendRequest
(
@RequestParam
@NotNull
Long
minutes
)
{
throws
IOException
{
JSONObject
rsp
=
JSONUtil
.
parseObj
(
HttpUtil
.
post
(
gateway
+
sendControlReqUrl
,
JSONObject
rsp
=
JSONUtil
.
parseObj
(
HttpUtil
.
post
(
gateway
+
sendControlReqUrl
,
JSONUtil
.
createObj
().
set
(
"controlDate"
,
minutes
)
JSONUtil
.
createObj
().
set
(
"controlDate"
,
minutes
)
.
set
(
"macAddress"
,
getMacAddress
())
.
set
(
"macAddress"
,
MacAddrUtil
.
get
())
.
set
(
"type"
,
1
).
toString
()));
.
set
(
"type"
,
1
).
toString
()));
if
(
ObjectUtil
.
notEqual
(
rsp
.
getInt
(
"code"
),
0
))
return
R
.
error
(
rsp
.
getStr
(
"msg"
));
if
(
ObjectUtil
.
notEqual
(
rsp
.
getInt
(
"code"
),
0
))
return
R
.
error
(
rsp
.
getStr
(
"msg"
));
return
R
.
success
();
return
R
.
success
();
}
}
private
String
getMacAddress
()
throws
UnknownHostException
,
SocketException
{
NetworkIF
networkIF
=
new
NetworkIF
();
networkIF
.
setNetworkInterface
(
NetworkInterface
.
getByInetAddress
(
InetAddress
.
getLocalHost
()));
return
networkIF
.
getMacaddr
();
}
private
String
remoteId
;
private
String
remoteId
;
private
String
getRemoteId
()
throws
SocketException
,
UnknownHostException
{
private
String
getRemoteId
()
{
if
(
StrUtil
.
isNotBlank
(
remoteId
))
return
remoteId
;
if
(
StrUtil
.
isNotBlank
(
remoteId
))
return
remoteId
;
String
mac
=
getMacAddress
();
String
mac
=
MacAddrUtil
.
get
();
JSONObject
rsp
=
JSONUtil
.
parseObj
(
HttpUtil
.
get
(
gateway
+
StrUtil
.
format
(
deviceInfoUrl
,
mac
)));
JSONObject
rsp
=
JSONUtil
.
parseObj
(
HttpUtil
.
get
(
gateway
+
StrUtil
.
format
(
deviceInfoUrl
,
mac
)));
if
(
ObjectUtil
.
notEqual
(
rsp
.
getInt
(
"code"
),
0
))
{
if
(
ObjectUtil
.
notEqual
(
rsp
.
getInt
(
"code"
),
0
))
{
log
.
warn
(
"查询设备信息失败, msg: {}"
,
rsp
.
getStr
(
"msg"
));
log
.
warn
(
"查询设备信息失败, msg: {}"
,
rsp
.
getStr
(
"msg"
));
...
...
apq-pc-client/src/main/java/com/priusis/util/MacAddrUtil.java
0 → 100644
浏览文件 @
647b1cab
package
com
.
priusis
.
util
;
import
cn.hutool.core.util.ArrayUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.system.oshi.OshiUtil
;
import
oshi.hardware.NetworkIF
;
/**
* @author yangli
* @since 2021/09/28
*/
public
final
class
MacAddrUtil
{
public
static
String
get
()
{
for
(
NetworkIF
networkIF
:
OshiUtil
.
getHardware
().
getNetworkIFs
())
{
if
(
ArrayUtil
.
isEmpty
(
networkIF
.
getIPv4addr
()))
continue
;
if
(
StrUtil
.
containsIgnoreCase
(
networkIF
.
getDisplayName
(),
"Virtual"
))
continue
;
return
networkIF
.
getMacaddr
();
}
return
null
;
}
}
apq-pc-info/src/main/java/com/priusis/ApqInfoApplication.java
浏览文件 @
647b1cab
...
@@ -5,6 +5,7 @@ import cn.hutool.core.map.MapUtil;
...
@@ -5,6 +5,7 @@ import cn.hutool.core.map.MapUtil;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.json.JSONUtil
;
import
cn.hutool.json.JSONUtil
;
import
cn.hutool.system.oshi.OshiUtil
;
import
cn.hutool.system.oshi.OshiUtil
;
import
com.priusis.util.MacAddrUtil
;
import
com.priusis.vo.ApqInfoDataVo
;
import
com.priusis.vo.ApqInfoDataVo
;
import
com.priusis.vo.MqttRpcDataMessage
;
import
com.priusis.vo.MqttRpcDataMessage
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
...
@@ -17,10 +18,8 @@ import org.springframework.http.ResponseEntity;
...
@@ -17,10 +18,8 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.scheduling.annotation.EnableScheduling
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.client.RestTemplate
;
import
oshi.hardware.NetworkIF
;
import
java.net.InetAddress
;
import
java.net.InetAddress
;
import
java.net.NetworkInterface
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
...
@@ -83,15 +82,11 @@ public class ApqInfoApplication {
...
@@ -83,15 +82,11 @@ public class ApqInfoApplication {
try
{
try
{
// 上报PC实时信息
// 上报PC实时信息
InetAddress
inetAddress
=
InetAddress
.
getLocalHost
();
NetworkIF
networkIF
=
new
NetworkIF
();
networkIF
.
setNetworkInterface
(
NetworkInterface
.
getByInetAddress
(
inetAddress
));
Map
<
String
,
Object
>
data
=
MapUtil
.<
String
,
Object
>
builder
()
Map
<
String
,
Object
>
data
=
MapUtil
.<
String
,
Object
>
builder
()
.
put
(
isNeedCollection
(
isNoneEven
,
operatingSystem
,
mapParams
),
operatingSystem
,
OshiUtil
.
getOs
().
toString
())
.
put
(
isNeedCollection
(
isNoneEven
,
operatingSystem
,
mapParams
),
operatingSystem
,
OshiUtil
.
getOs
().
toString
())
.
put
(
isNeedCollection
(
isNoneEven
,
mac
,
mapParams
),
mac
,
networkIF
.
getMacaddr
())
.
put
(
isNeedCollection
(
isNoneEven
,
mac
,
mapParams
),
mac
,
MacAddrUtil
.
get
())
.
put
(
isNeedCollection
(
isNoneEven
,
baseboard
,
mapParams
),
baseboard
,
OshiUtil
.
getSystem
().
getBaseboard
().
getManufacturer
()
+
" "
+
OshiUtil
.
getSystem
().
getBaseboard
().
getVersion
())
.
put
(
isNeedCollection
(
isNoneEven
,
baseboard
,
mapParams
),
baseboard
,
OshiUtil
.
getSystem
().
getBaseboard
().
getManufacturer
()
+
" "
+
OshiUtil
.
getSystem
().
getBaseboard
().
getVersion
())
.
put
(
isNeedCollection
(
isNoneEven
,
ip
,
mapParams
),
ip
,
inetAddress
.
getHostAddress
())
.
put
(
isNeedCollection
(
isNoneEven
,
ip
,
mapParams
),
ip
,
InetAddress
.
getLocalHost
()
.
getHostAddress
())
.
put
(
isNeedCollection
(
isNoneEven
,
cpuModel
,
mapParams
),
cpuModel
,
OshiUtil
.
getCpuInfo
(
0
).
getCpuModel
())
.
put
(
isNeedCollection
(
isNoneEven
,
cpuModel
,
mapParams
),
cpuModel
,
OshiUtil
.
getCpuInfo
(
0
).
getCpuModel
())
.
put
(
isNeedCollection
(
isNoneEven
,
cpuTemp
,
mapParams
),
cpuTemp
,
OshiUtil
.
getSensors
().
getCpuTemperature
())
.
put
(
isNeedCollection
(
isNoneEven
,
cpuTemp
,
mapParams
),
cpuTemp
,
OshiUtil
.
getSensors
().
getCpuTemperature
())
.
put
(
isNeedCollection
(
isNoneEven
,
cpuLoad
,
mapParams
),
cpuTemp
,
OshiUtil
.
getSensors
().
getCpuVoltage
())
.
put
(
isNeedCollection
(
isNoneEven
,
cpuLoad
,
mapParams
),
cpuTemp
,
OshiUtil
.
getSensors
().
getCpuVoltage
())
...
...
apq-pc-info/src/main/java/com/priusis/util/MacAddrUtil.java
0 → 100644
浏览文件 @
647b1cab
package
com
.
priusis
.
util
;
import
cn.hutool.core.util.ArrayUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.system.oshi.OshiUtil
;
import
oshi.hardware.NetworkIF
;
/**
* @author yangli
* @since 2021/09/28
*/
public
final
class
MacAddrUtil
{
public
static
String
get
()
{
for
(
NetworkIF
networkIF
:
OshiUtil
.
getHardware
().
getNetworkIFs
())
{
if
(
ArrayUtil
.
isEmpty
(
networkIF
.
getIPv4addr
()))
continue
;
if
(
StrUtil
.
containsIgnoreCase
(
networkIF
.
getDisplayName
(),
"Virtual"
))
continue
;
return
networkIF
.
getMacaddr
();
}
return
null
;
}
}
apq-pc-info/src/test/java/com/priusis/RestTest.java
浏览文件 @
647b1cab
...
@@ -3,6 +3,7 @@ package com.priusis;
...
@@ -3,6 +3,7 @@ package com.priusis;
import
cn.hutool.core.io.unit.DataSizeUtil
;
import
cn.hutool.core.io.unit.DataSizeUtil
;
import
cn.hutool.core.map.MapUtil
;
import
cn.hutool.core.map.MapUtil
;
import
cn.hutool.system.oshi.OshiUtil
;
import
cn.hutool.system.oshi.OshiUtil
;
import
com.priusis.util.MacAddrUtil
;
import
com.priusis.vo.MqttRpcDataMessage
;
import
com.priusis.vo.MqttRpcDataMessage
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.junit.runner.RunWith
;
...
@@ -11,10 +12,8 @@ import org.springframework.boot.test.context.SpringBootTest;
...
@@ -11,10 +12,8 @@ import org.springframework.boot.test.context.SpringBootTest;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.client.RestTemplate
;
import
oshi.hardware.NetworkIF
;
import
java.net.InetAddress
;
import
java.net.InetAddress
;
import
java.net.NetworkInterface
;
import
java.util.Map
;
import
java.util.Map
;
@RunWith
(
SpringRunner
.
class
)
@RunWith
(
SpringRunner
.
class
)
...
@@ -32,14 +31,11 @@ public class RestTest {
...
@@ -32,14 +31,11 @@ public class RestTest {
System
.
out
.
println
(
forEntity
.
getBody
().
getParams
());
System
.
out
.
println
(
forEntity
.
getBody
().
getParams
());
// 上报PC实时信息
// 上报PC实时信息
InetAddress
inetAddress
=
InetAddress
.
getLocalHost
();
NetworkIF
networkIF
=
new
NetworkIF
();
networkIF
.
setNetworkInterface
(
NetworkInterface
.
getByInetAddress
(
inetAddress
));
Map
<
String
,
Object
>
data
=
MapUtil
.<
String
,
Object
>
builder
()
Map
<
String
,
Object
>
data
=
MapUtil
.<
String
,
Object
>
builder
()
.
put
(
"operatingSystem"
,
OshiUtil
.
getOs
().
toString
())
.
put
(
"operatingSystem"
,
OshiUtil
.
getOs
().
toString
())
.
put
(
"mac"
,
networkIF
.
getMacaddr
())
.
put
(
"mac"
,
MacAddrUtil
.
get
())
.
put
(
"baseboard"
,
OshiUtil
.
getSystem
().
getBaseboard
().
getManufacturer
()
+
" "
+
OshiUtil
.
getSystem
().
getBaseboard
().
getVersion
())
.
put
(
"baseboard"
,
OshiUtil
.
getSystem
().
getBaseboard
().
getManufacturer
()
+
" "
+
OshiUtil
.
getSystem
().
getBaseboard
().
getVersion
())
.
put
(
"ip"
,
inetAddress
.
getHostAddress
())
.
put
(
"ip"
,
InetAddress
.
getLocalHost
()
.
getHostAddress
())
.
put
(
"cpuModel"
,
OshiUtil
.
getCpuInfo
(
0
).
getCpuModel
())
.
put
(
"cpuModel"
,
OshiUtil
.
getCpuInfo
(
0
).
getCpuModel
())
.
put
(
"cpuTemp"
,
OshiUtil
.
getSensors
().
getCpuTemperature
())
.
put
(
"cpuTemp"
,
OshiUtil
.
getSensors
().
getCpuTemperature
())
.
put
(
"memoryCap"
,
DataSizeUtil
.
format
(
OshiUtil
.
getMemory
().
getTotal
()))
.
put
(
"memoryCap"
,
DataSizeUtil
.
format
(
OshiUtil
.
getMemory
().
getTotal
()))
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论