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
8f2eacc9
Commit
8f2eacc9
authored
Nov 23, 2022
by
AfirSraftGarrier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改使用记录
parent
2a9f05b3
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
36 additions
and
14 deletions
+36
-14
ForwardMessageResponseEventHandler.java
...ang/license/event/ForwardMessageResponseEventHandler.java
+14
-5
ForwardChannelInitializer.java
...ot/sixiang/license/forward/ForwardChannelInitializer.java
+0
-3
ForwardClientHandler.java
...ava/iot/sixiang/license/forward/ForwardClientHandler.java
+4
-0
ForwardConnectionListener.java
...ot/sixiang/license/forward/ForwardConnectionListener.java
+2
-1
ForwardDecoder.java
...main/java/iot/sixiang/license/forward/ForwardDecoder.java
+1
-3
ForwardEncoder.java
...main/java/iot/sixiang/license/forward/ForwardEncoder.java
+0
-2
PmsUseService.java
.../main/java/iot/sixiang/license/service/PmsUseService.java
+2
-0
PmsUseServiceImpl.java
...a/iot/sixiang/license/service/impl/PmsUseServiceImpl.java
+8
-0
PmsUseServiceTest.java
...t/java/iot/sixiang/license/service/PmsUseServiceTest.java
+5
-0
No files found.
license/src/main/java/iot/sixiang/license/event/ForwardMessageResponseEventHandler.java
View file @
8f2eacc9
...
@@ -5,11 +5,14 @@ import iot.sixiang.license.device.DeviceManager;
...
@@ -5,11 +5,14 @@ import iot.sixiang.license.device.DeviceManager;
import
iot.sixiang.license.device.DeviceProtocol
;
import
iot.sixiang.license.device.DeviceProtocol
;
import
iot.sixiang.license.forward.ForwardManager
;
import
iot.sixiang.license.forward.ForwardManager
;
import
iot.sixiang.license.model.SessionContext
;
import
iot.sixiang.license.model.SessionContext
;
import
iot.sixiang.license.service.PmsUseService
;
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
;
@Component
@Component
@Slf4j
@Slf4j
public
class
ForwardMessageResponseEventHandler
{
public
class
ForwardMessageResponseEventHandler
{
...
@@ -19,7 +22,8 @@ public class ForwardMessageResponseEventHandler {
...
@@ -19,7 +22,8 @@ public class ForwardMessageResponseEventHandler {
ForwardManager
forwardManager
;
ForwardManager
forwardManager
;
@Autowired
@Autowired
EventPublisher
eventPublisher
;
EventPublisher
eventPublisher
;
@Resource
private
PmsUseService
pmsUseService
;
public
ForwardMessageResponseEventHandler
()
{
public
ForwardMessageResponseEventHandler
()
{
}
}
...
@@ -31,15 +35,20 @@ public class ForwardMessageResponseEventHandler {
...
@@ -31,15 +35,20 @@ public class ForwardMessageResponseEventHandler {
DeviceProtocol
protocol
=
event
.
getProtocol
();
DeviceProtocol
protocol
=
event
.
getProtocol
();
SessionContext
forwardSessionContext
=
forwardManager
.
getSessionByChannelId
(
channelId
);
SessionContext
forwardSessionContext
=
forwardManager
.
getSessionByChannelId
(
channelId
);
String
appId
=
forwardSessionContext
.
getAppId
();
String
sn
=
forwardSessionContext
.
getSn
();
SessionContext
deviceSessionContext
=
deviceManager
.
getSessionContextBySN
(
appId
);
SessionContext
deviceSessionContext
=
deviceManager
.
getSessionContextBySN
(
sn
);
if
(
deviceSessionContext
!=
null
)
{
if
(
deviceSessionContext
!=
null
)
{
SocketChannel
deviceClientChannel
=
deviceSessionContext
.
getClientChannel
();
SocketChannel
deviceClientChannel
=
deviceSessionContext
.
getClientChannel
();
log
.
info
(
"forward client response..."
+
appId
+
",forward session:"
+
deviceSessionContext
);
log
.
info
(
"forward client response..."
+
sn
+
",forward session:"
+
deviceSessionContext
);
deviceClientChannel
.
writeAndFlush
(
protocol
);
deviceClientChannel
.
writeAndFlush
(
protocol
);
}
else
{
}
else
{
log
.
info
(
"forward client response undo ..."
+
appId
);
log
.
info
(
"forward client response undo ..."
+
sn
);
}
// 说明已经成功
if
(
protocol
.
getCmd
()
==
0xF2
)
{
pmsUseService
.
success
(
deviceSessionContext
.
getUseLogId
());
}
}
}
}
}
}
license/src/main/java/iot/sixiang/license/forward/ForwardChannelInitializer.java
View file @
8f2eacc9
...
@@ -7,7 +7,6 @@ import iot.sixiang.license.consts.Consts;
...
@@ -7,7 +7,6 @@ import iot.sixiang.license.consts.Consts;
import
iot.sixiang.license.net.BaseChannelInitializer
;
import
iot.sixiang.license.net.BaseChannelInitializer
;
public
class
ForwardChannelInitializer
extends
BaseChannelInitializer
{
public
class
ForwardChannelInitializer
extends
BaseChannelInitializer
{
private
ForwardClientHandler
handler
;
private
ForwardClientHandler
handler
;
static
final
EventExecutorGroup
workGroup
=
new
DefaultEventExecutorGroup
(
Consts
.
FORWARD_THREAD_NUM
);
static
final
EventExecutorGroup
workGroup
=
new
DefaultEventExecutorGroup
(
Consts
.
FORWARD_THREAD_NUM
);
...
@@ -18,10 +17,8 @@ public class ForwardChannelInitializer extends BaseChannelInitializer {
...
@@ -18,10 +17,8 @@ public class ForwardChannelInitializer extends BaseChannelInitializer {
@Override
@Override
protected
void
initChannel
(
SocketChannel
ch
)
throws
Exception
{
protected
void
initChannel
(
SocketChannel
ch
)
throws
Exception
{
ch
.
pipeline
().
addLast
(
"decoder"
,
new
ForwardDecoder
());
ch
.
pipeline
().
addLast
(
"decoder"
,
new
ForwardDecoder
());
ch
.
pipeline
().
addLast
(
"encoder"
,
new
ForwardEncoder
());
ch
.
pipeline
().
addLast
(
"encoder"
,
new
ForwardEncoder
());
ch
.
pipeline
().
addLast
(
workGroup
,
"handler"
,
handler
);
ch
.
pipeline
().
addLast
(
workGroup
,
"handler"
,
handler
);
}
}
}
}
license/src/main/java/iot/sixiang/license/forward/ForwardClientHandler.java
View file @
8f2eacc9
...
@@ -8,11 +8,14 @@ import iot.sixiang.license.device.DeviceProtocol;
...
@@ -8,11 +8,14 @@ import iot.sixiang.license.device.DeviceProtocol;
import
iot.sixiang.license.event.EventPublisher
;
import
iot.sixiang.license.event.EventPublisher
;
import
iot.sixiang.license.event.ForwardClientInactiveEvent
;
import
iot.sixiang.license.event.ForwardClientInactiveEvent
;
import
iot.sixiang.license.event.ForwardMessageResponseEvent
;
import
iot.sixiang.license.event.ForwardMessageResponseEvent
;
import
iot.sixiang.license.service.PmsUseService
;
import
iot.sixiang.license.util.HexUtil
;
import
iot.sixiang.license.util.HexUtil
;
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.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
@Component
@Component
@ChannelHandler
.
Sharable
@ChannelHandler
.
Sharable
@Slf4j
@Slf4j
...
@@ -33,6 +36,7 @@ public class ForwardClientHandler extends SimpleChannelInboundHandler<Object> {
...
@@ -33,6 +36,7 @@ public class ForwardClientHandler extends SimpleChannelInboundHandler<Object> {
//String serverIp = socketAddr.getHostString();
//String serverIp = socketAddr.getHostString();
//int serverPort = socketAddr.getPort();
//int serverPort = socketAddr.getPort();
DeviceProtocol
protocol
=
(
DeviceProtocol
)
msg
;
DeviceProtocol
protocol
=
(
DeviceProtocol
)
msg
;
String
channelId
=
channel
.
id
().
asLongText
();
String
channelId
=
channel
.
id
().
asLongText
();
log
.
info
(
"桥接客户端,channelRead0:{},{}"
,
channelId
,
HexUtil
.
bytes2hex
(
protocol
.
getContent
()));
log
.
info
(
"桥接客户端,channelRead0:{},{}"
,
channelId
,
HexUtil
.
bytes2hex
(
protocol
.
getContent
()));
...
...
license/src/main/java/iot/sixiang/license/forward/ForwardConnectionListener.java
View file @
8f2eacc9
...
@@ -55,12 +55,13 @@ public class ForwardConnectionListener extends BaseConnectionListener {
...
@@ -55,12 +55,13 @@ public class ForwardConnectionListener extends BaseConnectionListener {
EventPublisher
eventPublisher
=
SpringUtil
.
getBean
(
EventPublisher
.
class
);
EventPublisher
eventPublisher
=
SpringUtil
.
getBean
(
EventPublisher
.
class
);
eventPublisher
.
publishEvent
(
forwardClientConnectEvent
);
eventPublisher
.
publishEvent
(
forwardClientConnectEvent
);
// 将日志记录数据返回
SessionContext
deviceSessionContext
=
deviceManager
.
getSessionContextBySN
(
this
.
sn
);
SessionContext
deviceSessionContext
=
deviceManager
.
getSessionContextBySN
(
this
.
sn
);
int
useLogId
=
deviceSessionContext
.
getUseLogId
();
int
useLogId
=
deviceSessionContext
.
getUseLogId
();
short
stx
=
21930
;
short
stx
=
21930
;
byte
ack
=
0x0
;
byte
ack
=
0x0
;
int
len
=
3
;
int
len
=
6
;
byte
cmd
=
0x1
;
byte
cmd
=
0x1
;
byte
[]
content
=
new
byte
[
4
];
byte
[]
content
=
new
byte
[
4
];
content
[
0
]
=
0x7e
;
content
[
0
]
=
0x7e
;
...
...
license/src/main/java/iot/sixiang/license/forward/ForwardDecoder.java
View file @
8f2eacc9
...
@@ -43,7 +43,7 @@ public class ForwardDecoder extends ByteToMessageDecoder {
...
@@ -43,7 +43,7 @@ public class ForwardDecoder extends ByteToMessageDecoder {
return
;
return
;
}
}
// buffer.resetReaderIndex();//复位
// buffer.resetReaderIndex();//复位
// 读取data数据
// 读取data数据
byte
[]
content
=
new
byte
[
real_len
-
cmd_ack_len
];
byte
[]
content
=
new
byte
[
real_len
-
cmd_ack_len
];
...
@@ -55,6 +55,4 @@ public class ForwardDecoder extends ByteToMessageDecoder {
...
@@ -55,6 +55,4 @@ public class ForwardDecoder extends ByteToMessageDecoder {
DeviceProtocol
protocol
=
new
DeviceProtocol
(
stx
,
real_len
,
cmd
,
ack
,
content
,
end
);
DeviceProtocol
protocol
=
new
DeviceProtocol
(
stx
,
real_len
,
cmd
,
ack
,
content
,
end
);
out
.
add
(
protocol
);
out
.
add
(
protocol
);
}
}
}
}
\ No newline at end of file
license/src/main/java/iot/sixiang/license/forward/ForwardEncoder.java
View file @
8f2eacc9
...
@@ -8,10 +8,8 @@ import lombok.extern.slf4j.Slf4j;
...
@@ -8,10 +8,8 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
@Slf4j
public
class
ForwardEncoder
extends
MessageToByteEncoder
<
DeviceProtocol
>
{
public
class
ForwardEncoder
extends
MessageToByteEncoder
<
DeviceProtocol
>
{
@Override
@Override
protected
void
encode
(
ChannelHandlerContext
tcx
,
DeviceProtocol
msg
,
ByteBuf
out
)
{
protected
void
encode
(
ChannelHandlerContext
tcx
,
DeviceProtocol
msg
,
ByteBuf
out
)
{
out
.
writeShort
(
msg
.
getStx
());
out
.
writeShort
(
msg
.
getStx
());
out
.
writeShortLE
(
msg
.
getLen
());
out
.
writeShortLE
(
msg
.
getLen
());
out
.
writeByte
(
msg
.
getCmd
());
out
.
writeByte
(
msg
.
getCmd
());
...
...
license/src/main/java/iot/sixiang/license/service/PmsUseService.java
View file @
8f2eacc9
...
@@ -9,4 +9,6 @@ public interface PmsUseService {
...
@@ -9,4 +9,6 @@ public interface PmsUseService {
int
createUseLog
(
String
sn
);
int
createUseLog
(
String
sn
);
void
createFailUseLog
(
String
sn
,
String
message
);
void
createFailUseLog
(
String
sn
,
String
message
);
void
success
(
int
useLogId
);
}
}
license/src/main/java/iot/sixiang/license/service/impl/PmsUseServiceImpl.java
View file @
8f2eacc9
...
@@ -31,6 +31,14 @@ public class PmsUseServiceImpl implements PmsUseService {
...
@@ -31,6 +31,14 @@ public class PmsUseServiceImpl implements PmsUseService {
pmsUseLogMapper
.
insert
(
pmsUseLog
);
pmsUseLogMapper
.
insert
(
pmsUseLog
);
}
}
@Override
public
void
success
(
int
useLogId
)
{
PmsUseLog
pmsUseLog
=
new
PmsUseLog
();
pmsUseLog
.
setId
(
useLogId
);
pmsUseLog
.
setStatus
(
1
);
pmsUseLogMapper
.
updateById
(
pmsUseLog
);
}
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/test/java/iot/sixiang/license/service/PmsUseServiceTest.java
View file @
8f2eacc9
...
@@ -18,4 +18,9 @@ public class PmsUseServiceTest extends BaseTest {
...
@@ -18,4 +18,9 @@ public class PmsUseServiceTest extends BaseTest {
void
addLog
()
{
void
addLog
()
{
log
(
pmsUseService
.
createUseLog
(
"abcd"
));
log
(
pmsUseService
.
createUseLog
(
"abcd"
));
}
}
@Test
void
updateLog
()
{
pmsUseService
.
success
(
1
);
}
}
}
\ No newline at end of file
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