Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
ioc_sixiang_license
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zengtianlai3
ioc_sixiang_license
Commits
2d76ca93
Commit
2d76ca93
authored
Jun 14, 2022
by
zengtianlai3
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增终端状态,服务自诊状态
parent
a65e3c83
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
168 additions
and
37 deletions
+168
-37
Consts.java
license/src/main/java/iot/sixiang/license/consts/Consts.java
+7
-3
DeviceController.java
...java/iot/sixiang/license/controller/DeviceController.java
+31
-5
OperateController.java
...ava/iot/sixiang/license/controller/OperateController.java
+13
-0
DeviceManager.java
...c/main/java/iot/sixiang/license/device/DeviceManager.java
+62
-1
DeviceServerHandler.java
.../java/iot/sixiang/license/device/DeviceServerHandler.java
+12
-15
ForwardManager.java
...main/java/iot/sixiang/license/forward/ForwardManager.java
+14
-7
SessionContext.java
...c/main/java/iot/sixiang/license/model/SessionContext.java
+7
-6
DeviceDetailVo.java
...ain/java/iot/sixiang/license/model/vo/DeviceDetailVo.java
+13
-0
ServerStatusVo.java
...ain/java/iot/sixiang/license/model/vo/ServerStatusVo.java
+9
-0
No files found.
license/src/main/java/iot/sixiang/license/consts/Consts.java
View file @
2d76ca93
...
...
@@ -7,9 +7,13 @@ public class Consts {
public
static
final
int
EXECUTOR_THREAD_NUM
=
30
;
public
static
final
int
FORWARD_THREAD_NUM
=
30
;
public
static
final
int
OPERATE_THREAD_NUM
=
5
;
public
static
final
Integer
DEVICE_STATE_ONLINE
=
1
;
// 设备在线
public
static
final
Integer
DEVICE_STATE_OFFLINE
=
0
;
// 设备离线
public
static
final
Integer
DEVICE_STATE_FAILURE
=
-
1
;
// 设备故障
public
static
final
int
DEVICE_STATE_ONLINE
=
1
;
// 设备在线
public
static
final
int
DEVICE_STATE_OFFLINE
=
0
;
// 设备离线
public
static
final
int
SERVICE_DX_THRESHOLD_NORMAL
=
100
;
public
static
final
int
SERVICE_DX_THRESHOLD_BUSY
=
500
;
public
static
final
int
SERVICE_DX_STATUS_FLUENT
=
0
;
//流畅
public
static
final
int
SERVICE_DX_STATUS_NORMAL
=
1
;
//正常
public
static
final
int
SERVICE_DX_STATUS_BUSY
=
2
;
//繁忙
}
license/src/main/java/iot/sixiang/license/controller/DeviceController.java
View file @
2d76ca93
...
...
@@ -5,15 +5,14 @@ import com.alibaba.fastjson.JSONObject;
import
com.github.xiaoymin.knife4j.annotations.ApiOperationSupport
;
import
com.github.xiaoymin.knife4j.annotations.DynamicParameter
;
import
com.github.xiaoymin.knife4j.annotations.DynamicParameters
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.*
;
import
iot.sixiang.license.device.DeviceManager
;
import
iot.sixiang.license.log.BusinessType
;
import
iot.sixiang.license.log.MyLog
;
import
iot.sixiang.license.model.BaseResult
;
import
iot.sixiang.license.model.PageInfoModel
;
import
iot.sixiang.license.model.PageResult
;
import
iot.sixiang.license.model.vo.DeviceDetailVo
;
import
iot.sixiang.license.model.vo.DeviceVo
;
import
iot.sixiang.license.service.DeviceService
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -36,6 +35,8 @@ public class DeviceController {
@Autowired
private
DeviceService
deviceService
;
@Autowired
private
DeviceManager
deviceManager
;
/**
* 添加device
...
...
@@ -61,7 +62,7 @@ public class DeviceController {
}
/**
* 可按条件分页查询所有的
user
* 可按条件分页查询所有的
设备
* @param pageNo
* @param pageSize
* @param appName
...
...
@@ -91,5 +92,30 @@ public class DeviceController {
List
<
DeviceVo
>
pageResult
=
records
.
getResult
();
return
new
PageResult
(
200
,
"查找成功"
,
pageNo
,
pages
,
total
,
pageResult
);
}
@ApiOperation
(
value
=
"获取设备详细信息接口"
,
notes
=
"用于获取设备详细信息列表"
)
@GetMapping
(
"detail/list"
)
@MyLog
(
title
=
"获取设备详细信息接口"
,
optParam
=
"#{pageNo},#{pageSize},#{appName},#{userName}"
,
businessType
=
BusinessType
.
SELECT
)
@ApiImplicitParams
({
@ApiImplicitParam
(
name
=
"pageNo"
,
value
=
"当前在第几页"
,
required
=
true
,
dataType
=
"int"
),
@ApiImplicitParam
(
name
=
"pageSize"
,
value
=
"每页显示多少页"
,
required
=
true
,
dataType
=
"int"
),
@ApiImplicitParam
(
name
=
"appName"
,
value
=
"应用名"
),
@ApiImplicitParam
(
name
=
"userName"
,
value
=
"用户名"
)
})
public
PageResult
getDeviceDetailList
(
@RequestParam
(
value
=
"pageNo"
,
defaultValue
=
"0"
)
int
pageNo
,
@RequestParam
(
value
=
"pageSize"
,
defaultValue
=
"0"
)
int
pageSize
,
@RequestParam
(
value
=
"appName"
,
required
=
false
)
String
appName
,
@RequestParam
(
value
=
"userName"
,
required
=
false
)
String
userName
)
{
PageInfoModel
<
DeviceDetailVo
>
records
=
deviceManager
.
getDeviceDetailList
(
pageNo
,
pageSize
,
appName
,
userName
);
int
total
=
records
.
getTotal
();
int
pages
=
total
/
pageSize
;
//pages为总页数
int
mod
=
total
%
pageSize
;
if
(
mod
!=
0
)
{
pages
=
pages
+
1
;
}
List
<
DeviceDetailVo
>
pageResult
=
records
.
getResult
();
return
new
PageResult
(
200
,
"查找成功"
,
pageNo
,
pages
,
total
,
pageResult
);
}
}
license/src/main/java/iot/sixiang/license/controller/OperateController.java
View file @
2d76ca93
...
...
@@ -3,10 +3,12 @@ package iot.sixiang.license.controller;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiOperation
;
import
iot.sixiang.license.forward.ForwardManager
;
import
iot.sixiang.license.log.BusinessType
;
import
iot.sixiang.license.log.MyLog
;
import
iot.sixiang.license.model.ResResult
;
import
iot.sixiang.license.model.SamMonitor
;
import
iot.sixiang.license.model.vo.ServerStatusVo
;
import
iot.sixiang.license.operate.OperateManager
;
import
iot.sixiang.license.service.MonitorService
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -26,6 +28,8 @@ public class OperateController {
private
OperateManager
operateManager
;
@Autowired
private
MonitorService
monitorService
;
@Autowired
private
ForwardManager
forwardManager
;
@ApiOperation
(
value
=
"服务接口"
,
notes
=
"用于获取服务列表"
)
@GetMapping
(
"monitor/server"
)
...
...
@@ -51,4 +55,13 @@ public class OperateController {
HashMap
<
String
,
List
<
Integer
>>
monitorList
=
monitorService
.
getMonitorList
(
type
);
return
ResResult
.
success
().
record
(
monitorList
);
}
@ApiOperation
(
value
=
"获取服务自诊断信息接口"
,
notes
=
"用于获取服务诊断信息"
)
@GetMapping
(
"diagnosis/server"
)
@MyLog
(
title
=
"获取服务诊断信息"
,
businessType
=
BusinessType
.
SELECT
)
@ApiImplicitParam
()
public
ResResult
getDiagnosisInfo
()
{
ServerStatusVo
serverStatus
=
forwardManager
.
getServerStatus
();
return
ResResult
.
success
().
record
(
serverStatus
);
}
}
license/src/main/java/iot/sixiang/license/device/DeviceManager.java
View file @
2d76ca93
...
...
@@ -3,9 +3,11 @@ package iot.sixiang.license.device;
import
iot.sixiang.license.consts.Consts
;
import
iot.sixiang.license.model.PageInfoModel
;
import
iot.sixiang.license.model.SessionContext
;
import
iot.sixiang.license.model.vo.DeviceDetailVo
;
import
iot.sixiang.license.model.vo.DeviceVo
;
import
iot.sixiang.license.net.TcpServer
;
import
iot.sixiang.license.service.DeviceService
;
import
iot.sixiang.license.util.CommonUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
...
...
@@ -87,6 +89,31 @@ public class DeviceManager {
}
return
session
;
}
public
boolean
getAuthStatusByChannelId
(
String
channelId
)
{
Iterator
<
Map
.
Entry
<
String
,
SessionContext
>>
it
=
sessionContexts
.
entrySet
().
iterator
();
while
(
it
.
hasNext
())
{
Map
.
Entry
<
String
,
SessionContext
>
entry
=
it
.
next
();
SessionContext
targetSession
=
entry
.
getValue
();
if
(
targetSession
.
getChannelId
().
equals
(
channelId
))
{
return
targetSession
.
isAuthStatus
();
}
}
return
false
;
}
public
SessionContext
getSessionBySn
(
String
sn
)
{
Iterator
<
Map
.
Entry
<
String
,
SessionContext
>>
it
=
sessionContexts
.
entrySet
().
iterator
();
while
(
it
.
hasNext
())
{
Map
.
Entry
<
String
,
SessionContext
>
entry
=
it
.
next
();
SessionContext
targetSession
=
entry
.
getValue
();
if
(
targetSession
.
getSn
().
equals
(
sn
))
{
return
targetSession
;
}
}
return
null
;
}
public
synchronized
boolean
removeSessionByChannelId
(
String
channelId
)
{
Iterator
<
Map
.
Entry
<
String
,
SessionContext
>>
it
=
sessionContexts
.
entrySet
().
iterator
();
while
(
it
.
hasNext
())
{
...
...
@@ -109,12 +136,46 @@ public class DeviceManager {
SessionContext
targetSession
=
entry
.
getValue
();
if
(
targetSession
.
getChannelId
().
equals
(
channelId
))
{
targetSession
.
setAuthStatus
(
false
);
targetSession
.
setStatus
(
Consts
.
DEVICE_STATE_OFFLINE
);
targetSession
.
setO
nline
(
new
Dat
e
());
targetSession
.
setO
ffline
(
CommonUtil
.
getSystemTim
e
());
return
true
;
}
}
return
false
;
}
public
PageInfoModel
<
DeviceDetailVo
>
getDeviceDetailList
(
int
pageNo
,
int
pageSize
,
String
appName
,
String
userName
)
{
PageInfoModel
<
DeviceVo
>
records
=
deviceService
.
getDeviceList
(
pageNo
,
pageSize
,
appName
,
userName
);
List
<
DeviceVo
>
deviceVos
=
records
.
getResult
();
PageInfoModel
<
DeviceDetailVo
>
detailVoPageInfoModel
=
new
PageInfoModel
<>();
List
<
DeviceDetailVo
>
detailVos
=
new
ArrayList
<>();
for
(
DeviceVo
vo
:
deviceVos
)
{
DeviceDetailVo
detailVo
=
new
DeviceDetailVo
();
detailVo
.
setDeviceId
(
vo
.
getDeviceId
());
detailVo
.
setAppName
(
vo
.
getAppName
());
detailVo
.
setUserName
(
vo
.
getUserName
());
detailVo
.
setSn
(
vo
.
getSn
());
detailVo
.
setOnline
(
""
);
detailVo
.
setOffline
(
""
);
String
sn
=
vo
.
getSn
();
SessionContext
session
=
this
.
getSessionBySn
(
sn
);
if
(
session
!=
null
)
{
int
status
=
session
.
getStatus
();
String
online
=
session
.
getOnline
();
String
offline
=
session
.
getOffline
();
detailVo
.
setStatus
(
status
);
detailVo
.
setOnline
(
online
);
detailVo
.
setOffline
(
offline
);
}
detailVos
.
add
(
detailVo
);
}
detailVoPageInfoModel
.
setTotal
(
detailVos
.
size
());
detailVoPageInfoModel
.
setResult
(
detailVos
);
return
detailVoPageInfoModel
;
}
}
license/src/main/java/iot/sixiang/license/device/DeviceServerHandler.java
View file @
2d76ca93
...
...
@@ -14,6 +14,7 @@ import iot.sixiang.license.event.EventPublisher;
import
iot.sixiang.license.event.ForwardClientRequestEvent
;
import
iot.sixiang.license.idreader.Safety
;
import
iot.sixiang.license.model.SessionContext
;
import
iot.sixiang.license.util.CommonUtil
;
import
iot.sixiang.license.util.HexUtil
;
import
iot.sixiang.license.util.SpringUtil
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -58,19 +59,19 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
int
cmdInt
=
cmd
&
0xFF
;
log
.
debug
(
"recev msg "
+
HexUtil
.
bytes2hex
(
protocol
.
getContent
()));
boolean
license
=
false
;
boolean
auth
=
false
;
if
(
cmdInt
==
Consts
.
CMD_LICENSE
)
{
license
=
handlerLicense
(
channel
,
remoteIp
,
remotePort
,
protocol
);
auth
=
handlerCheckAuth
(
channel
,
remoteIp
,
remotePort
,
protocol
);
}
else
{
license
=
handlerCheckLicense
(
channel
,
remoteIp
,
remotePort
,
protocol
);
if
(
license
)
{
auth
=
handlerCheckAuthStatus
(
channel
,
remoteIp
,
remotePort
,
protocol
);
if
(
auth
)
{
handlerForward
(
channel
,
remoteIp
,
remotePort
,
protocol
);
}
}
//TODO 以下为正式代码
if
(
license
==
false
)
{
if
(
auth
==
false
)
{
channel
.
close
();
}
}
...
...
@@ -154,7 +155,7 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
log
.
error
(
"client has error,ip:"
+
clientIp
+
",port:"
+
port
);
}
private
boolean
handler
License
(
SocketChannel
channel
,
String
remoteIp
,
int
remotePort
,
DeviceProtocol
protocol
)
{
private
boolean
handler
CheckAuth
(
SocketChannel
channel
,
String
remoteIp
,
int
remotePort
,
DeviceProtocol
protocol
)
{
//TODO 正式代码要放开
...
...
@@ -179,10 +180,12 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
session
.
setRemoteIp
(
remoteIp
);
session
.
setRemotePort
(
remotePort
);
session
.
setAppId
(
appId
);
session
.
setSn
(
sn
);
session
.
setChannelId
(
channelId
);
session
.
setClientChannel
(
channel
);
session
.
setAuthStatus
(
true
);
session
.
setStatus
(
Consts
.
DEVICE_STATE_ONLINE
);
session
.
setOnline
(
new
Dat
e
());
session
.
setOnline
(
CommonUtil
.
getSystemTim
e
());
DeviceManager
deviceManager
=
SpringUtil
.
getBean
(
DeviceManager
.
class
);
deviceManager
.
putSession
(
appId
,
session
);
...
...
@@ -196,16 +199,10 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
return
license
;
}
private
boolean
handlerCheck
License
(
SocketChannel
channel
,
String
remoteIp
,
int
remotePort
,
DeviceProtocol
protocol
)
{
private
boolean
handlerCheck
AuthStatus
(
SocketChannel
channel
,
String
remoteIp
,
int
remotePort
,
DeviceProtocol
protocol
)
{
String
channelId
=
channel
.
id
().
asLongText
();
DeviceManager
deviceManager
=
SpringUtil
.
getBean
(
DeviceManager
.
class
);
SessionContext
session
=
deviceManager
.
getSessionByChannelId
(
channelId
);
if
(
session
!=
null
)
{
return
true
;
}
else
{
return
false
;
}
return
deviceManager
.
getAuthStatusByChannelId
(
channelId
);
}
private
void
handlerForward
(
SocketChannel
channel
,
String
remoteIp
,
int
remotePort
,
DeviceProtocol
protocol
)
{
...
...
license/src/main/java/iot/sixiang/license/forward/ForwardManager.java
View file @
2d76ca93
package
iot
.
sixiang
.
license
.
forward
;
import
iot.sixiang.license.consts.Consts
;
import
iot.sixiang.license.model.SessionContext
;
import
lombok.Getter
;
import
lombok.Setter
;
import
iot.sixiang.license.model.vo.ServerStatusVo
;
import
lombok.extern.slf4j.Slf4j
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
...
...
@@ -67,9 +65,18 @@ public class ForwardManager {
return
false
;
}
public
void
getSession
(){
public
ServerStatusVo
getServerStatus
()
{
ServerStatusVo
vo
=
new
ServerStatusVo
();
int
size
=
sessionContexts
.
size
();
int
statue
=
Consts
.
SERVICE_DX_STATUS_FLUENT
;
if
(
size
>=
Consts
.
SERVICE_DX_THRESHOLD_NORMAL
)
{
statue
=
Consts
.
SERVICE_DX_STATUS_NORMAL
;
}
else
if
(
size
>
Consts
.
SERVICE_DX_THRESHOLD_BUSY
)
{
statue
=
Consts
.
SERVICE_DX_STATUS_BUSY
;
}
vo
.
setCount
(
size
);
vo
.
setStatus
(
statue
);
return
vo
;
}
...
...
license/src/main/java/iot/sixiang/license/model/SessionContext.java
View file @
2d76ca93
...
...
@@ -10,12 +10,13 @@ import java.util.Date;
public
class
SessionContext
{
private
String
remoteIp
;
private
int
remotePort
;
private
String
appId
;
//设备序列号
private
String
appKey
;
//设备key/授权ID
private
String
token
;
//连接标识
private
int
status
;
//0 offline,1 online
private
Date
online
;
//上线时间
private
Date
offline
;
//下线时间
private
String
appId
;
private
String
appKey
;
private
String
sn
;
private
boolean
authStatus
;
//授权验证状态
private
int
status
;
//当前状态,0 offline,1 online
private
String
online
;
//上线时间
private
String
offline
;
//下线时间
private
String
channelId
;
private
SocketChannel
clientChannel
;
...
...
license/src/main/java/iot/sixiang/license/model/vo/DeviceDetailVo.java
0 → 100644
View file @
2d76ca93
package
iot
.
sixiang
.
license
.
model
.
vo
;
import
lombok.Data
;
import
java.util.Date
;
@Data
public
class
DeviceDetailVo
extends
DeviceVo
{
private
int
status
;
//当前状态,0 offline,1 online
private
String
online
;
//上线时间
private
String
offline
;
//下线时间
}
license/src/main/java/iot/sixiang/license/model/vo/ServerStatusVo.java
0 → 100644
View file @
2d76ca93
package
iot
.
sixiang
.
license
.
model
.
vo
;
import
lombok.Data
;
@Data
public
class
ServerStatusVo
{
private
int
count
;
//服务实时工作通道数量
private
int
status
;
//诊断状态,通道数量小于100流畅,100-500正常,500以上拥挤
}
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