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
9355271f
Commit
9355271f
authored
Feb 02, 2023
by
ma
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完善安全报警模块
parent
abd449a7
Changes
15
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
194 additions
and
15 deletions
+194
-15
CorsConfig.java
.../src/main/java/iot/sixiang/license/config/CorsConfig.java
+3
-0
ThreadPoolConfig.java
...ain/java/iot/sixiang/license/config/ThreadPoolConfig.java
+20
-8
DeviceServerHandler.java
.../java/iot/sixiang/license/device/DeviceServerHandler.java
+13
-0
Report.java
license/src/main/java/iot/sixiang/license/entity/Report.java
+2
-0
OperateSAMStatusResponseEventHandler.java
...g/license/event/OperateSAMStatusResponseEventHandler.java
+18
-1
ForwardConnectionListener.java
...ot/sixiang/license/forward/ForwardConnectionListener.java
+13
-1
UserMapper.java
.../src/main/java/iot/sixiang/license/mapper/UserMapper.java
+5
-0
UserInfoVO.java
...rc/main/java/iot/sixiang/license/model/vo/UserInfoVO.java
+19
-0
OperateConnectionListener.java
...ot/sixiang/license/operate/OperateConnectionListener.java
+13
-0
PmsUseService.java
.../main/java/iot/sixiang/license/service/PmsUseService.java
+2
-0
ReportService.java
.../main/java/iot/sixiang/license/service/ReportService.java
+4
-0
PmsUseServiceImpl.java
...a/iot/sixiang/license/service/impl/PmsUseServiceImpl.java
+5
-0
ReportServiceImpl.java
...a/iot/sixiang/license/service/impl/ReportServiceImpl.java
+38
-0
TerminalDeviceServiceImpl.java
...xiang/license/service/impl/TerminalDeviceServiceImpl.java
+28
-5
UserMapper.xml
license/src/main/resources/mapper/UserMapper.xml
+11
-0
No files found.
license/src/main/java/iot/sixiang/license/config/CorsConfig.java
View file @
9355271f
...
@@ -24,6 +24,9 @@ public class CorsConfig implements WebMvcConfigurer {
...
@@ -24,6 +24,9 @@ public class CorsConfig implements WebMvcConfigurer {
@Override
@Override
public
void
addCorsMappings
(
CorsRegistry
registry
)
{
public
void
addCorsMappings
(
CorsRegistry
registry
)
{
registry
.
addMapping
(
"/**"
)
registry
.
addMapping
(
"/**"
)
// 合并到yx需要添加上白名单
// .allowedOrigins(allowedOrigins)
// .allowedMethods(allowedMethods)
.
allowedOrigins
(
"*"
)
.
allowedOrigins
(
"*"
)
.
allowedMethods
(
"*"
)
.
allowedMethods
(
"*"
)
.
allowCredentials
(
true
)
.
allowCredentials
(
true
)
...
...
license/src/main/java/iot/sixiang/license/config/ThreadPoolConfig.java
View file @
9355271f
...
@@ -21,10 +21,22 @@ import java.util.concurrent.ThreadPoolExecutor;
...
@@ -21,10 +21,22 @@ import java.util.concurrent.ThreadPoolExecutor;
@Configuration
@Configuration
@EnableAsync
@EnableAsync
public
class
ThreadPoolConfig
{
public
class
ThreadPoolConfig
{
private
static
final
int
corePoolSize
=
1
;
// 核心线程数(默认线程数)
/**
private
static
final
int
maxPoolSize
=
2
;
// 最大线程数
* 核心线程数(默认线程数)
private
static
final
int
keepAliveTime
=
10
;
// 允许线程空闲时间(单位:默认为秒)
*/
private
static
final
int
queueCapacity
=
2
;
// 缓冲队列数
private
static
final
int
CORE_POOL_SIZE
=
1
;
/**
* 最大线程数
*/
private
static
final
int
MAX_POOL_SIZE
=
2
;
/**
* 允许线程空闲时间(单位:默认为秒)
*/
private
static
final
int
KEEP_ALIVE_TIME
=
10
;
/**
* 缓冲队列数
*/
private
static
final
int
QUEUE_CAPACITY
=
2
;
/**
/**
* 默认异步线程池
* 默认异步线程池
...
@@ -35,10 +47,10 @@ public class ThreadPoolConfig {
...
@@ -35,10 +47,10 @@ public class ThreadPoolConfig {
public
Executor
taskExecutor
()
{
public
Executor
taskExecutor
()
{
ThreadPoolTaskExecutor
pool
=
new
ThreadPoolTaskExecutor
();
ThreadPoolTaskExecutor
pool
=
new
ThreadPoolTaskExecutor
();
pool
.
setThreadNamePrefix
(
"threadPoll-"
);
pool
.
setThreadNamePrefix
(
"threadPoll-"
);
pool
.
setCorePoolSize
(
corePoolSize
);
pool
.
setCorePoolSize
(
CORE_POOL_SIZE
);
pool
.
setMaxPoolSize
(
maxPoolSize
);
pool
.
setMaxPoolSize
(
MAX_POOL_SIZE
);
pool
.
setKeepAliveSeconds
(
keepAliveTime
);
pool
.
setKeepAliveSeconds
(
KEEP_ALIVE_TIME
);
pool
.
setQueueCapacity
(
queueCapacity
);
pool
.
setQueueCapacity
(
QUEUE_CAPACITY
);
pool
.
setRejectedExecutionHandler
(
new
ThreadPoolExecutor
.
CallerRunsPolicy
());
pool
.
setRejectedExecutionHandler
(
new
ThreadPoolExecutor
.
CallerRunsPolicy
());
// 初始化
// 初始化
pool
.
initialize
();
pool
.
initialize
();
...
...
license/src/main/java/iot/sixiang/license/device/DeviceServerHandler.java
View file @
9355271f
...
@@ -9,14 +9,18 @@ import io.netty.channel.SimpleChannelInboundHandler;
...
@@ -9,14 +9,18 @@ import io.netty.channel.SimpleChannelInboundHandler;
import
io.netty.channel.socket.SocketChannel
;
import
io.netty.channel.socket.SocketChannel
;
import
iot.sixiang.license.auth.AuthManager
;
import
iot.sixiang.license.auth.AuthManager
;
import
iot.sixiang.license.consts.Constant
;
import
iot.sixiang.license.consts.Constant
;
import
iot.sixiang.license.entity.Report
;
import
iot.sixiang.license.event.CreateForwardClientEvent
;
import
iot.sixiang.license.event.CreateForwardClientEvent
;
import
iot.sixiang.license.event.DeviceClientInactiveEvent
;
import
iot.sixiang.license.event.DeviceClientInactiveEvent
;
import
iot.sixiang.license.event.DeviceClientLicenseEvent
;
import
iot.sixiang.license.event.DeviceClientLicenseEvent
;
import
iot.sixiang.license.event.EventPublisher
;
import
iot.sixiang.license.event.EventPublisher
;
import
iot.sixiang.license.event.ForwardClientRequestEvent
;
import
iot.sixiang.license.event.ForwardClientRequestEvent
;
import
iot.sixiang.license.mapper.UserMapper
;
import
iot.sixiang.license.model.SessionContext
;
import
iot.sixiang.license.model.SessionContext
;
import
iot.sixiang.license.model.dto.ReportErrorMsgDTO
;
import
iot.sixiang.license.model.dto.ReportErrorMsgDTO
;
import
iot.sixiang.license.model.vo.UserInfoVO
;
import
iot.sixiang.license.service.PmsUseService
;
import
iot.sixiang.license.service.PmsUseService
;
import
iot.sixiang.license.service.ReportService
;
import
iot.sixiang.license.service.TerminalDeviceService
;
import
iot.sixiang.license.service.TerminalDeviceService
;
import
iot.sixiang.license.third_lib.LibHelper
;
import
iot.sixiang.license.third_lib.LibHelper
;
import
iot.sixiang.license.util.CommonUtil
;
import
iot.sixiang.license.util.CommonUtil
;
...
@@ -28,6 +32,7 @@ import org.springframework.stereotype.Component;
...
@@ -28,6 +32,7 @@ import org.springframework.stereotype.Component;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
java.net.InetSocketAddress
;
import
java.net.InetSocketAddress
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
@Component
@Component
...
@@ -41,6 +46,10 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
...
@@ -41,6 +46,10 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
private
PmsUseService
pmsUseService
;
private
PmsUseService
pmsUseService
;
@Resource
@Resource
TerminalDeviceService
terminalDeviceService
;
TerminalDeviceService
terminalDeviceService
;
@Resource
ReportService
reportService
;
@Resource
UserMapper
userMapper
;
public
DeviceServerHandler
()
{
public
DeviceServerHandler
()
{
super
();
super
();
...
@@ -172,6 +181,10 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
...
@@ -172,6 +181,10 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
eventPublisher
.
publishEvent
(
event
);
eventPublisher
.
publishEvent
(
event
);
}
else
{
}
else
{
pmsUseService
.
createFailUseLog
(
sn
,
"鉴权失败"
);
pmsUseService
.
createFailUseLog
(
sn
,
"鉴权失败"
);
UserInfoVO
user
=
userMapper
.
getUserBySn
(
sn
);
Report
report
=
Report
.
builder
().
category
(
0
).
type
(
6
).
sn
(
sn
).
userName
(
user
.
getUserName
())
.
userCompany
(
user
.
getCompany
()).
createTime
(
new
Date
()).
updateTime
(
new
Date
()).
build
();
reportService
.
reportToEmail
(
report
);
}
}
return
license
;
return
license
;
}
}
...
...
license/src/main/java/iot/sixiang/license/entity/Report.java
View file @
9355271f
...
@@ -3,6 +3,7 @@ package iot.sixiang.license.entity;
...
@@ -3,6 +3,7 @@ package iot.sixiang.license.entity;
import
com.baomidou.mybatisplus.annotation.IdType
;
import
com.baomidou.mybatisplus.annotation.IdType
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
io.swagger.annotations.ApiModelProperty
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.Data
;
import
java.util.Date
;
import
java.util.Date
;
...
@@ -13,6 +14,7 @@ import java.util.Date;
...
@@ -13,6 +14,7 @@ import java.util.Date;
* Description
* Description
*/
*/
@Data
@Data
@Builder
public
class
Report
{
public
class
Report
{
@ApiModelProperty
(
"id"
)
@ApiModelProperty
(
"id"
)
@TableId
(
type
=
IdType
.
AUTO
)
@TableId
(
type
=
IdType
.
AUTO
)
...
...
license/src/main/java/iot/sixiang/license/event/OperateSAMStatusResponseEventHandler.java
View file @
9355271f
...
@@ -2,16 +2,22 @@ package iot.sixiang.license.event;
...
@@ -2,16 +2,22 @@ package iot.sixiang.license.event;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
iot.sixiang.license.device.DeviceProtocol
;
import
iot.sixiang.license.device.DeviceProtocol
;
import
iot.sixiang.license.entity.Report
;
import
iot.sixiang.license.mapper.UserMapper
;
import
iot.sixiang.license.model.SamInfo
;
import
iot.sixiang.license.model.SamInfo
;
import
iot.sixiang.license.model.SamMonitor
;
import
iot.sixiang.license.model.SamMonitor
;
import
iot.sixiang.license.model.vo.UserInfoVO
;
import
iot.sixiang.license.operate.OperateManager
;
import
iot.sixiang.license.operate.OperateManager
;
import
iot.sixiang.license.service.AlarmService
;
import
iot.sixiang.license.service.AlarmService
;
import
iot.sixiang.license.service.ReportService
;
import
iot.sixiang.license.util.CommonUtil
;
import
iot.sixiang.license.util.CommonUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.event.EventListener
;
import
org.springframework.context.event.EventListener
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
@@ -23,9 +29,12 @@ import java.util.List;
...
@@ -23,9 +29,12 @@ import java.util.List;
public
class
OperateSAMStatusResponseEventHandler
{
public
class
OperateSAMStatusResponseEventHandler
{
@Autowired
@Autowired
public
OperateManager
operateManager
;
public
OperateManager
operateManager
;
@Autowired
@Autowired
private
AlarmService
alarmService
;
private
AlarmService
alarmService
;
@Resource
UserMapper
userMapper
;
@Resource
ReportService
reportService
;
public
OperateSAMStatusResponseEventHandler
()
{
public
OperateSAMStatusResponseEventHandler
()
{
}
}
...
@@ -51,6 +60,10 @@ public class OperateSAMStatusResponseEventHandler {
...
@@ -51,6 +60,10 @@ public class OperateSAMStatusResponseEventHandler {
String
title
=
"SAM故障"
;
String
title
=
"SAM故障"
;
String
content
=
"index为"
+
index
+
"的SAM发生故障"
;
String
content
=
"index为"
+
index
+
"的SAM发生故障"
;
alarmService
.
addAlarm
(
typeId
,
title
,
content
);
alarmService
.
addAlarm
(
typeId
,
title
,
content
);
UserInfoVO
user
=
userMapper
.
getRootAccount
();
Report
report
=
Report
.
builder
().
category
(
1
).
type
(
1
).
userName
(
user
.
getUserName
())
.
userCompany
(
user
.
getCompany
()).
createTime
(
new
Date
()).
updateTime
(
new
Date
()).
build
();
reportService
.
reportToEmail
(
report
);
}
}
}
}
SamMonitor
samMonitor
=
new
SamMonitor
();
SamMonitor
samMonitor
=
new
SamMonitor
();
...
@@ -63,6 +76,10 @@ public class OperateSAMStatusResponseEventHandler {
...
@@ -63,6 +76,10 @@ public class OperateSAMStatusResponseEventHandler {
String
title
=
"SAM不足"
;
String
title
=
"SAM不足"
;
String
content
=
"当前在线客户端已超过70%"
;
String
content
=
"当前在线客户端已超过70%"
;
alarmService
.
addAlarm
(
typeId
,
title
,
content
);
alarmService
.
addAlarm
(
typeId
,
title
,
content
);
UserInfoVO
user
=
userMapper
.
getRootAccount
();
Report
report
=
Report
.
builder
().
category
(
1
).
type
(
2
).
userName
(
user
.
getUserName
())
.
userCompany
(
user
.
getCompany
()).
createTime
(
new
Date
()).
updateTime
(
new
Date
()).
build
();
reportService
.
reportToEmail
(
report
);
}
}
}
}
}
}
license/src/main/java/iot/sixiang/license/forward/ForwardConnectionListener.java
View file @
9355271f
...
@@ -4,17 +4,23 @@ import io.netty.channel.ChannelFuture;
...
@@ -4,17 +4,23 @@ import io.netty.channel.ChannelFuture;
import
io.netty.channel.socket.SocketChannel
;
import
io.netty.channel.socket.SocketChannel
;
import
iot.sixiang.license.device.DeviceManager
;
import
iot.sixiang.license.device.DeviceManager
;
import
iot.sixiang.license.device.DeviceProtocol
;
import
iot.sixiang.license.device.DeviceProtocol
;
import
iot.sixiang.license.entity.Report
;
import
iot.sixiang.license.event.DeviceClientBeForcedOfflineEvent
;
import
iot.sixiang.license.event.DeviceClientBeForcedOfflineEvent
;
import
iot.sixiang.license.event.DeviceClientLicenseEvent
;
import
iot.sixiang.license.event.DeviceClientLicenseEvent
;
import
iot.sixiang.license.event.EventPublisher
;
import
iot.sixiang.license.event.EventPublisher
;
import
iot.sixiang.license.event.ForwardClientConnectEvent
;
import
iot.sixiang.license.event.ForwardClientConnectEvent
;
import
iot.sixiang.license.mapper.UserMapper
;
import
iot.sixiang.license.model.SessionContext
;
import
iot.sixiang.license.model.SessionContext
;
import
iot.sixiang.license.model.vo.UserInfoVO
;
import
iot.sixiang.license.net.BaseConnectionListener
;
import
iot.sixiang.license.net.BaseConnectionListener
;
import
iot.sixiang.license.operate.OperateManager
;
import
iot.sixiang.license.operate.OperateManager
;
import
iot.sixiang.license.service.AlarmService
;
import
iot.sixiang.license.service.AlarmService
;
import
iot.sixiang.license.service.ReportService
;
import
iot.sixiang.license.util.SpringUtil
;
import
iot.sixiang.license.util.SpringUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
java.util.Date
;
@Slf4j
@Slf4j
public
class
ForwardConnectionListener
extends
BaseConnectionListener
{
public
class
ForwardConnectionListener
extends
BaseConnectionListener
{
private
DeviceManager
deviceManager
;
private
DeviceManager
deviceManager
;
...
@@ -34,7 +40,13 @@ public class ForwardConnectionListener extends BaseConnectionListener {
...
@@ -34,7 +40,13 @@ public class ForwardConnectionListener extends BaseConnectionListener {
String
title
=
"连接服器失败"
;
String
title
=
"连接服器失败"
;
String
content
=
"连接服务器:"
+
this
.
host
+
":"
+
this
.
port
+
"失败"
;
String
content
=
"连接服务器:"
+
this
.
host
+
":"
+
this
.
port
+
"失败"
;
alarmService
.
addAlarm
(
typeId
,
title
,
content
);
alarmService
.
addAlarm
(
typeId
,
title
,
content
);
UserMapper
userMapper
=
SpringUtil
.
getBean
(
UserMapper
.
class
);
ReportService
reportService
=
SpringUtil
.
getBean
(
ReportService
.
class
);
UserInfoVO
user
=
userMapper
.
getRootAccount
();
Report
report
=
Report
.
builder
().
category
(
1
).
type
(
3
).
userName
(
user
.
getUserName
())
.
description
(
"桥接客户端,连接服务器"
+
this
.
host
+
":"
+
this
.
port
+
"失败"
)
.
userCompany
(
user
.
getCompany
()).
createTime
(
new
Date
()).
updateTime
(
new
Date
()).
build
();
reportService
.
reportToEmail
(
report
);
// forward client连接失败,则强制踢掉设备客户端
// forward client连接失败,则强制踢掉设备客户端
DeviceClientBeForcedOfflineEvent
deviceClientBeForcedOfflineEvent
=
new
DeviceClientBeForcedOfflineEvent
();
DeviceClientBeForcedOfflineEvent
deviceClientBeForcedOfflineEvent
=
new
DeviceClientBeForcedOfflineEvent
();
deviceClientBeForcedOfflineEvent
.
setSn
(
this
.
sn
);
deviceClientBeForcedOfflineEvent
.
setSn
(
this
.
sn
);
...
...
license/src/main/java/iot/sixiang/license/mapper/UserMapper.java
View file @
9355271f
...
@@ -3,6 +3,7 @@ package iot.sixiang.license.mapper;
...
@@ -3,6 +3,7 @@ package iot.sixiang.license.mapper;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
iot.sixiang.license.entity.User
;
import
iot.sixiang.license.entity.User
;
import
iot.sixiang.license.model.vo.UserChildIdVO
;
import
iot.sixiang.license.model.vo.UserChildIdVO
;
import
iot.sixiang.license.model.vo.UserInfoVO
;
import
iot.sixiang.license.model.vo.UserVo
;
import
iot.sixiang.license.model.vo.UserVo
;
import
java.util.List
;
import
java.util.List
;
...
@@ -31,4 +32,8 @@ public interface UserMapper extends BaseMapper<User> {
...
@@ -31,4 +32,8 @@ public interface UserMapper extends BaseMapper<User> {
User
getUserById
(
int
userId
);
User
getUserById
(
int
userId
);
List
<
UserChildIdVO
>
getChildUser
(
int
userId
);
List
<
UserChildIdVO
>
getChildUser
(
int
userId
);
UserInfoVO
getRootAccount
();
UserInfoVO
getUserBySn
(
String
sn
);
}
}
license/src/main/java/iot/sixiang/license/model/vo/UserInfoVO.java
0 → 100644
View file @
9355271f
package
iot
.
sixiang
.
license
.
model
.
vo
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
/**
* Created by m33
* Date 2023/2/2 15:03
* Description
*/
@Data
public
class
UserInfoVO
{
@ApiModelProperty
(
"用户号"
)
private
String
userName
;
@ApiModelProperty
(
"公司名"
)
private
String
company
;
}
license/src/main/java/iot/sixiang/license/operate/OperateConnectionListener.java
View file @
9355271f
...
@@ -3,13 +3,19 @@ package iot.sixiang.license.operate;
...
@@ -3,13 +3,19 @@ package iot.sixiang.license.operate;
import
io.netty.channel.ChannelFuture
;
import
io.netty.channel.ChannelFuture
;
import
io.netty.channel.socket.SocketChannel
;
import
io.netty.channel.socket.SocketChannel
;
import
iot.sixiang.license.device.DeviceProtocol
;
import
iot.sixiang.license.device.DeviceProtocol
;
import
iot.sixiang.license.entity.Report
;
import
iot.sixiang.license.event.EventPublisher
;
import
iot.sixiang.license.event.EventPublisher
;
import
iot.sixiang.license.event.OperateSAMStatusRequestEvent
;
import
iot.sixiang.license.event.OperateSAMStatusRequestEvent
;
import
iot.sixiang.license.mapper.UserMapper
;
import
iot.sixiang.license.model.vo.UserInfoVO
;
import
iot.sixiang.license.net.BaseConnectionListener
;
import
iot.sixiang.license.net.BaseConnectionListener
;
import
iot.sixiang.license.service.AlarmService
;
import
iot.sixiang.license.service.AlarmService
;
import
iot.sixiang.license.service.ReportService
;
import
iot.sixiang.license.util.SpringUtil
;
import
iot.sixiang.license.util.SpringUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
java.util.Date
;
@Slf4j
@Slf4j
public
class
OperateConnectionListener
extends
BaseConnectionListener
{
public
class
OperateConnectionListener
extends
BaseConnectionListener
{
...
@@ -25,6 +31,13 @@ public class OperateConnectionListener extends BaseConnectionListener {
...
@@ -25,6 +31,13 @@ public class OperateConnectionListener extends BaseConnectionListener {
String
title
=
"连接服器失败"
;
String
title
=
"连接服器失败"
;
String
content
=
"连接服务器:"
+
this
.
host
+
":"
+
this
.
port
+
"失败"
;
String
content
=
"连接服务器:"
+
this
.
host
+
":"
+
this
.
port
+
"失败"
;
alarmService
.
addAlarm
(
typeId
,
title
,
content
);
alarmService
.
addAlarm
(
typeId
,
title
,
content
);
UserMapper
userMapper
=
SpringUtil
.
getBean
(
UserMapper
.
class
);
ReportService
reportService
=
SpringUtil
.
getBean
(
ReportService
.
class
);
UserInfoVO
user
=
userMapper
.
getRootAccount
();
Report
report
=
Report
.
builder
().
category
(
1
).
type
(
3
).
userName
(
user
.
getUserName
())
.
description
(
"运维客户端,连接服务器"
+
this
.
host
+
":"
+
this
.
port
+
"失败"
)
.
userCompany
(
user
.
getCompany
()).
createTime
(
new
Date
()).
updateTime
(
new
Date
()).
build
();
reportService
.
reportToEmail
(
report
);
}
else
{
}
else
{
log
.
info
(
"运维客户端,连接服务器成功:{},{}"
,
this
.
host
,
this
.
port
);
log
.
info
(
"运维客户端,连接服务器成功:{},{}"
,
this
.
host
,
this
.
port
);
//TODO 查询SAM状态
//TODO 查询SAM状态
...
...
license/src/main/java/iot/sixiang/license/service/PmsUseService.java
View file @
9355271f
...
@@ -21,4 +21,6 @@ public interface PmsUseService {
...
@@ -21,4 +21,6 @@ public interface PmsUseService {
boolean
reportErrorMsg
(
ReportErrorMsgDTO
reportErrorMsgDTO
);
boolean
reportErrorMsg
(
ReportErrorMsgDTO
reportErrorMsgDTO
);
boolean
deletePmsUseLogById
(
Integer
id
);
boolean
deletePmsUseLogById
(
Integer
id
);
PmsUseLog
getPmsUseLogById
(
Integer
id
);
}
}
license/src/main/java/iot/sixiang/license/service/ReportService.java
View file @
9355271f
package
iot
.
sixiang
.
license
.
service
;
package
iot
.
sixiang
.
license
.
service
;
import
iot.sixiang.license.entity.Report
;
import
iot.sixiang.license.model.BaseResult
;
import
iot.sixiang.license.model.PageResult
;
import
iot.sixiang.license.model.PageResult
;
import
iot.sixiang.license.model.dto.ReportDTO
;
import
iot.sixiang.license.model.dto.ReportDTO
;
import
iot.sixiang.license.model.vo.ReportVO
;
import
iot.sixiang.license.model.vo.ReportVO
;
...
@@ -12,4 +14,6 @@ import iot.sixiang.license.model.vo.ReportVO;
...
@@ -12,4 +14,6 @@ import iot.sixiang.license.model.vo.ReportVO;
public
interface
ReportService
{
public
interface
ReportService
{
PageResult
<
ReportVO
>
getReportList
(
ReportDTO
reportDTO
);
PageResult
<
ReportVO
>
getReportList
(
ReportDTO
reportDTO
);
void
reportToEmail
(
Report
report
);
}
}
license/src/main/java/iot/sixiang/license/service/impl/PmsUseServiceImpl.java
View file @
9355271f
...
@@ -107,6 +107,11 @@ public class PmsUseServiceImpl implements PmsUseService {
...
@@ -107,6 +107,11 @@ public class PmsUseServiceImpl implements PmsUseService {
return
res
>
0
;
return
res
>
0
;
}
}
@Override
public
PmsUseLog
getPmsUseLogById
(
Integer
id
)
{
return
pmsUseLogMapper
.
selectById
(
id
);
}
private
PmsUseLog
getPmsUseLog
(
String
sn
)
{
private
PmsUseLog
getPmsUseLog
(
String
sn
)
{
PmsUseLog
pmsUseLog
=
new
PmsUseLog
();
PmsUseLog
pmsUseLog
=
new
PmsUseLog
();
Date
date
=
new
Date
();
Date
date
=
new
Date
();
...
...
license/src/main/java/iot/sixiang/license/service/impl/ReportServiceImpl.java
View file @
9355271f
package
iot
.
sixiang
.
license
.
service
.
impl
;
package
iot
.
sixiang
.
license
.
service
.
impl
;
import
cn.hutool.core.lang.Validator
;
import
iot.sixiang.license.entity.Report
;
import
iot.sixiang.license.entity.ReportType
;
import
iot.sixiang.license.handler.IotLicenseException
;
import
iot.sixiang.license.handler.IotLicenseException
;
import
iot.sixiang.license.jwt.UserUtils
;
import
iot.sixiang.license.jwt.UserUtils
;
import
iot.sixiang.license.mapper.ReportMapper
;
import
iot.sixiang.license.mapper.ReportMapper
;
import
iot.sixiang.license.mapper.ReportTypeMapper
;
import
iot.sixiang.license.model.PageResult
;
import
iot.sixiang.license.model.PageResult
;
import
iot.sixiang.license.model.dto.ReportDTO
;
import
iot.sixiang.license.model.dto.ReportDTO
;
import
iot.sixiang.license.model.vo.ReportVO
;
import
iot.sixiang.license.model.vo.ReportVO
;
import
iot.sixiang.license.service.ReportService
;
import
iot.sixiang.license.service.ReportService
;
import
iot.sixiang.license.util.CommonUtil
;
import
iot.sixiang.license.util.EmailUtils
;
import
iot.sixiang.license.util.TreeUtil
;
import
iot.sixiang.license.util.TreeUtil
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
...
@@ -25,6 +32,10 @@ import java.util.stream.Collectors;
...
@@ -25,6 +32,10 @@ import java.util.stream.Collectors;
public
class
ReportServiceImpl
implements
ReportService
{
public
class
ReportServiceImpl
implements
ReportService
{
@Resource
@Resource
ReportMapper
reportMapper
;
ReportMapper
reportMapper
;
@Resource
EmailUtils
emailUtils
;
@Resource
ReportTypeMapper
reportTypeMapper
;
@Override
@Override
public
PageResult
<
ReportVO
>
getReportList
(
ReportDTO
reportDTO
)
{
public
PageResult
<
ReportVO
>
getReportList
(
ReportDTO
reportDTO
)
{
...
@@ -58,4 +69,31 @@ public class ReportServiceImpl implements ReportService {
...
@@ -58,4 +69,31 @@ public class ReportServiceImpl implements ReportService {
}
}
return
new
PageResult
(
200
,
"查找成功"
,
pageNo
,
pages
,
total
,
result
);
return
new
PageResult
(
200
,
"查找成功"
,
pageNo
,
pages
,
total
,
result
);
}
}
@Async
(
"mailExecutor"
)
@Override
public
void
reportToEmail
(
Report
report
)
{
if
(!
Validator
.
isEmail
(
report
.
getUserName
()))
{
throw
new
IotLicenseException
(
403
,
"报警失败,无效的邮箱账号"
);
}
reportMapper
.
insert
(
report
);
Integer
type
=
report
.
getType
();
ReportType
reportType
=
reportTypeMapper
.
selectById
(
type
);
if
(
reportType
==
null
)
{
throw
new
IotLicenseException
(
403
,
"报警失败,无效的报警类型"
);
}
Integer
category
=
report
.
getCategory
();
String
content
=
""
;
if
(
category
==
1
)
{
content
=
"【实名制身份验证云平台】系统报警!报警时间:"
+
CommonUtil
.
getSystemTime
()
+
",报警事件:"
+
reportType
.
getDescription
()
+
",报警用户:"
+
report
.
getUserName
()
+
",公司名称:"
+
report
.
getUserCompany
()
+
",请核实!"
;
}
else
if
(
category
==
0
)
{
content
=
"【实名制身份验证云平台】设备报警!报警时间:"
+
CommonUtil
.
getSystemTime
()
+
",报警事件:"
+
reportType
.
getDescription
()
+
",设备SN:"
+
report
.
getSn
()
+
",报警用户:"
+
report
.
getUserName
()
+
",公司名称:"
+
report
.
getUserCompany
()
+
",请核实!"
;
}
else
{
throw
new
IotLicenseException
(
403
,
"报警失败,无效的报警大类"
);
}
emailUtils
.
sendSimpleMail
(
report
.
getUserName
(),
"实名制身份验证云平台"
,
content
);
}
}
}
license/src/main/java/iot/sixiang/license/service/impl/TerminalDeviceServiceImpl.java
View file @
9355271f
...
@@ -2,18 +2,19 @@ package iot.sixiang.license.service.impl;
...
@@ -2,18 +2,19 @@ package iot.sixiang.license.service.impl;
import
iot.sixiang.license.auth.AuthManager
;
import
iot.sixiang.license.auth.AuthManager
;
import
iot.sixiang.license.device.DeviceManager
;
import
iot.sixiang.license.device.DeviceManager
;
import
iot.sixiang.license.entity.PmsUseLog
;
import
iot.sixiang.license.entity.Report
;
import
iot.sixiang.license.handler.IotLicenseException
;
import
iot.sixiang.license.handler.IotLicenseException
;
import
iot.sixiang.license.jwt.JwtUtil
;
import
iot.sixiang.license.jwt.JwtUtil
;
import
iot.sixiang.license.jwt.LoginUser
;
import
iot.sixiang.license.jwt.LoginUser
;
import
iot.sixiang.license.mapper.UserMapper
;
import
iot.sixiang.license.model.BaseResult
;
import
iot.sixiang.license.model.BaseResult
;
import
iot.sixiang.license.model.ResResult
;
import
iot.sixiang.license.model.ResResult
;
import
iot.sixiang.license.model.dto.GetTerminalDeviceTokenDTO
;
import
iot.sixiang.license.model.dto.*
;
import
iot.sixiang.license.model.dto.PlatFormBindDTO
;
import
iot.sixiang.license.model.vo.UserInfoVO
;
import
iot.sixiang.license.model.dto.ReportErrorMsgDTO
;
import
iot.sixiang.license.model.dto.TerminalDevieBindDTO
;
import
iot.sixiang.license.model.dto.TerminalDevieUnBindDTO
;
import
iot.sixiang.license.service.DeviceService
;
import
iot.sixiang.license.service.DeviceService
;
import
iot.sixiang.license.service.PmsUseService
;
import
iot.sixiang.license.service.PmsUseService
;
import
iot.sixiang.license.service.ReportService
;
import
iot.sixiang.license.service.TerminalDeviceService
;
import
iot.sixiang.license.service.TerminalDeviceService
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
...
@@ -21,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -21,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
@Slf4j
@Slf4j
...
@@ -34,6 +36,10 @@ public class TerminalDeviceServiceImpl implements TerminalDeviceService {
...
@@ -34,6 +36,10 @@ public class TerminalDeviceServiceImpl implements TerminalDeviceService {
private
PmsUseService
pmsUseService
;
private
PmsUseService
pmsUseService
;
@Resource
@Resource
private
DeviceManager
deviceManager
;
private
DeviceManager
deviceManager
;
@Resource
UserMapper
userMapper
;
@Resource
ReportService
reportService
;
@Override
@Override
public
ResResult
getToken
(
GetTerminalDeviceTokenDTO
getTerminalDeviceTokenDTO
)
{
public
ResResult
getToken
(
GetTerminalDeviceTokenDTO
getTerminalDeviceTokenDTO
)
{
...
@@ -76,6 +82,23 @@ public class TerminalDeviceServiceImpl implements TerminalDeviceService {
...
@@ -76,6 +82,23 @@ public class TerminalDeviceServiceImpl implements TerminalDeviceService {
}
else
if
(
"-1"
.
equals
(
reportErrorMsgDTO
.
getErrorCode
()))
{
}
else
if
(
"-1"
.
equals
(
reportErrorMsgDTO
.
getErrorCode
()))
{
pmsUseService
.
deletePmsUseLogById
(
id
);
pmsUseService
.
deletePmsUseLogById
(
id
);
}
else
{
}
else
{
PmsUseLog
pmsUseLog
=
pmsUseService
.
getPmsUseLogById
(
reportErrorMsgDTO
.
getId
());
if
(
pmsUseLog
==
null
||
StringUtils
.
isEmpty
(
pmsUseLog
.
getSn
()))
{
throw
new
IotLicenseException
(
403
,
"添加报警信息失败:查无SN"
);
}
UserInfoVO
user
=
userMapper
.
getUserBySn
(
pmsUseLog
.
getSn
());
int
code
=
Integer
.
parseInt
(
reportErrorMsgDTO
.
getErrorCode
());
int
type
=
0
;
if
(
code
==
1
)
{
type
=
5
;
}
else
if
(
code
==
2
)
{
type
=
4
;
}
else
if
(
code
==
3
)
{
type
=
7
;
}
Report
report
=
Report
.
builder
().
category
(
0
).
type
(
type
).
sn
(
pmsUseLog
.
getSn
()).
userName
(
user
.
getUserName
())
.
userCompany
(
user
.
getCompany
()).
createTime
(
new
Date
()).
updateTime
(
new
Date
()).
build
();
reportService
.
reportToEmail
(
report
);
boolean
res
=
pmsUseService
.
reportErrorMsg
(
reportErrorMsgDTO
);
boolean
res
=
pmsUseService
.
reportErrorMsg
(
reportErrorMsgDTO
);
if
(!
res
)
{
if
(!
res
)
{
return
BaseResult
.
failed
();
return
BaseResult
.
failed
();
...
...
license/src/main/resources/mapper/UserMapper.xml
View file @
9355271f
...
@@ -52,4 +52,15 @@
...
@@ -52,4 +52,15 @@
select user_id, parent, `level` from `user` where parent = #{userId}
select user_id, parent, `level` from `user` where parent = #{userId}
</select>
</select>
<select
id=
"getUserBySn"
resultType=
"iot.sixiang.license.model.vo.UserInfoVO"
>
SELECT `user`.user_name, `user`.company FROM user
INNER JOIN apply on user.user_id = apply.user_id
INNER JOIN device on device.app_id = apply.app_id
WHERE device.sn = #{sn}
</select>
<select
id=
"getRootAccount"
resultType=
"iot.sixiang.license.model.vo.UserInfoVO"
>
SELECT user_name, company FROM `user` WHERE parent IS NULL AND `level` = 1 LIMIT 1
</select>
</mapper>
</mapper>
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