Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
znks
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
王夏晖
znks
Commits
52b8b82a
Commit
52b8b82a
authored
Sep 12, 2018
by
王夏晖
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完善命令发送方式
parent
0b088e72
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
338 additions
and
109 deletions
+338
-109
adc-da-main.iml
adc-da-main/adc-da-main.iml
+213
-0
InstructionsController.java
...va/com/adc/da/znks/controller/InstructionsController.java
+76
-94
UserDao.java
adc-da-main/src/main/java/com/adc/da/znks/dao/UserDao.java
+5
-1
UserService.java
...in/src/main/java/com/adc/da/znks/service/UserService.java
+11
-6
SystemValue.java
...-main/src/main/java/com/adc/da/znks/util/SystemValue.java
+2
-0
NettyServer.java
...src/main/java/com/adc/da/znks/util/netty/NettyServer.java
+5
-3
ServerHandler.java
...c/main/java/com/adc/da/znks/util/netty/ServerHandler.java
+24
-3
UserEOMapper.xml
...n/src/main/resources/mybatis/mapper/znks/UserEOMapper.xml
+2
-2
No files found.
adc-da-main/adc-da-main.iml
View file @
52b8b82a
This diff is collapsed.
Click to expand it.
adc-da-main/src/main/java/com/adc/da/znks/controller/InstructionsController.java
View file @
52b8b82a
This diff is collapsed.
Click to expand it.
adc-da-main/src/main/java/com/adc/da/znks/dao/UserDao.java
View file @
52b8b82a
...
@@ -22,11 +22,15 @@ public interface UserDao extends BaseDao<User> {
...
@@ -22,11 +22,15 @@ public interface UserDao extends BaseDao<User> {
@Select
(
"SELECT * FROM tb_user WHERE temphone = #{phoneNumber}"
)
@Select
(
"SELECT * FROM tb_user WHERE temphone = #{phoneNumber}"
)
User
getUserByPhoneNumber
(
@Param
(
"phoneNumber"
)
String
phoneNumber
);
User
getUserByPhoneNumber
(
@Param
(
"phoneNumber"
)
String
phoneNumber
);
List
<
Map
<
String
,
Object
>>
query
IpByUser
(
@Param
(
"phone"
)
String
phone
);
List
<
Map
<
String
,
Object
>>
query
MacByPhone
(
@Param
(
"phone"
)
String
phone
);
@Update
(
"UPDATE tb_user SET client_id = #{clientId} WHERE temphone = #{phoneNumber}"
)
@Update
(
"UPDATE tb_user SET client_id = #{clientId} WHERE temphone = #{phoneNumber}"
)
int
updateClientIdByPhoneNumber
(
@Param
(
"clientId"
)
String
clientId
,
@Param
(
"phoneNumber"
)
String
phoneNumber
);
int
updateClientIdByPhoneNumber
(
@Param
(
"clientId"
)
String
clientId
,
@Param
(
"phoneNumber"
)
String
phoneNumber
);
List
<
Map
<
String
,
Object
>>
queryClientByIp
(
@Param
(
"ip"
)
String
ip
);
List
<
Map
<
String
,
Object
>>
queryClientByIp
(
@Param
(
"ip"
)
String
ip
);
@Select
(
"select way.mac_address from tb_user ur,tb_gateway way where ur.id = way.user_id\n"
+
" and ur.temphone = #{phoneNumber}"
)
List
<
Map
<
String
,
Object
>>
getGateWayByPhoneNumber
(
@Param
(
"phoneNumber"
)
String
phoneNumber
);
}
}
adc-da-main/src/main/java/com/adc/da/znks/service/UserService.java
View file @
52b8b82a
...
@@ -45,7 +45,11 @@ public class UserService extends BaseService<User, String> {
...
@@ -45,7 +45,11 @@ public class UserService extends BaseService<User, String> {
Boolean
flag
=
false
;
Boolean
flag
=
false
;
User
user
=
dao
.
getUserByPhoneNumber
(
phoneNumber
);
User
user
=
dao
.
getUserByPhoneNumber
(
phoneNumber
);
if
(
user
!=
null
)
{
if
(
user
!=
null
)
{
flag
=
true
;
if
(
user
.
getPassword
()!=
null
&&
!
""
.
equals
(
user
.
getPassword
())){
flag
=
true
;
}
else
{
flag
=
false
;
}
}
}
return
flag
;
return
flag
;
}
}
...
@@ -90,7 +94,7 @@ public class UserService extends BaseService<User, String> {
...
@@ -90,7 +94,7 @@ public class UserService extends BaseService<User, String> {
List
<
String
>
encryptList
=
encryptList
(
plainPassword
);
List
<
String
>
encryptList
=
encryptList
(
plainPassword
);
Asserts
.
notNull
(
encryptList
,
"encrypt list must not be null."
);
Asserts
.
notNull
(
encryptList
,
"encrypt list must not be null."
);
String
id
=
UUID
.
randomUUID
();
String
id
=
UUID
.
randomUUID
();
User
insertUser
=
new
User
(
id
,
temphone
,
encryptList
.
get
(
0
),
encryptList
.
get
(
1
)
);
User
insertUser
=
new
User
(
id
,
temphone
,
""
,
""
);
logger
.
info
(
"insertUser: {}"
,
insertUser
);
logger
.
info
(
"insertUser: {}"
,
insertUser
);
int
result
=
dao
.
insertSelective
(
insertUser
);
int
result
=
dao
.
insertSelective
(
insertUser
);
if
(
result
!=
0
)
{
if
(
result
!=
0
)
{
...
@@ -99,14 +103,15 @@ public class UserService extends BaseService<User, String> {
...
@@ -99,14 +103,15 @@ public class UserService extends BaseService<User, String> {
return
false
;
return
false
;
}
}
}
else
{
}
else
{
User
user
=
users
.
get
(
0
);
/*
User user = users.get(0);
String decryptPassword = SecurityUtils.decrypt(user.getEncryptkey(), user.getPassword());
String decryptPassword = SecurityUtils.decrypt(user.getEncryptkey(), user.getPassword());
Asserts.notNull(plainPassword, "plainPassword must not be null.");
Asserts.notNull(plainPassword, "plainPassword must not be null.");
if (plainPassword.equals(decryptPassword)) {
if (plainPassword.equals(decryptPassword)) {
return true;
return true;
} else {
} else {
return false;
return false;
}
}*/
return
true
;
}
}
}
}
...
@@ -125,8 +130,8 @@ public class UserService extends BaseService<User, String> {
...
@@ -125,8 +130,8 @@ public class UserService extends BaseService<User, String> {
}
}
public
List
<
Map
<
String
,
Object
>>
query
IpByUser
(
String
phone
){
public
List
<
Map
<
String
,
Object
>>
query
MacByPhone
(
String
phone
){
return
dao
.
queryIpByUs
er
(
phone
);
return
dao
.
getGateWayByPhoneNumb
er
(
phone
);
}
}
public
void
updateClientIdByPhoneNumber
(
String
clientId
,
String
phoneNumber
)
{
public
void
updateClientIdByPhoneNumber
(
String
clientId
,
String
phoneNumber
)
{
...
...
adc-da-main/src/main/java/com/adc/da/znks/util/SystemValue.java
View file @
52b8b82a
...
@@ -13,4 +13,6 @@ public class SystemValue {
...
@@ -13,4 +13,6 @@ public class SystemValue {
public
static
Map
<
String
,
String
>
ipMacMap
=
new
HashMap
<>();
public
static
Map
<
String
,
String
>
ipMacMap
=
new
HashMap
<>();
public
static
Map
<
String
,
Object
>
channelMap
=
new
HashMap
<>();
}
}
adc-da-main/src/main/java/com/adc/da/znks/util/netty/NettyServer.java
View file @
52b8b82a
...
@@ -35,11 +35,13 @@ public class NettyServer {
...
@@ -35,11 +35,13 @@ public class NettyServer {
@Override
@Override
protected
void
initChannel
(
SocketChannel
ch
)
throws
Exception
{
protected
void
initChannel
(
SocketChannel
ch
)
throws
Exception
{
System
.
out
.
println
(
"端口号:"
+
ch
.
remoteAddress
().
getPort
());
System
.
out
.
println
(
"connected...; Local:"
+
ch
.
localAddress
().
getHostString
());
System
.
out
.
println
(
"connected...; Client:"
+
ch
.
remoteAddress
().
getHostString
());
System
.
out
.
println
(
"connected...; Client:"
+
ch
.
remoteAddress
().
getHostString
());
//發送請求指令
//發送請求指令
if
(
SystemValue
.
ipMacMap
.
get
(
ch
.
remoteAddress
().
getHostString
())
==
null
){
/*
if( SystemValue.ipMacMap.get(ch.remoteAddress().getHostString()) == null){
connectGateway(ch.remoteAddress().getHostString(),8899);
connectGateway(ch.remoteAddress().getHostString(),8899);
}
}
*/
ch
.
pipeline
().
addLast
(
new
ByteArrayEncoder
());
ch
.
pipeline
().
addLast
(
new
ByteArrayEncoder
());
ch
.
pipeline
().
addLast
(
new
ByteArrayDecoder
());
ch
.
pipeline
().
addLast
(
new
ByteArrayDecoder
());
ch
.
pipeline
().
addLast
(
new
ServerHandler
());
// 客户端触发操作
ch
.
pipeline
().
addLast
(
new
ServerHandler
());
// 客户端触发操作
...
@@ -48,7 +50,7 @@ public class NettyServer {
...
@@ -48,7 +50,7 @@ public class NettyServer {
}
}
});
});
ChannelFuture
cf
=
sb
.
bind
().
sync
();
// 服务器异步创建绑定
ChannelFuture
cf
=
sb
.
bind
(
9999
).
sync
();
// 服务器异步创建绑定
System
.
out
.
println
(
NettyServer
.
class
+
" started and listen on "
+
cf
.
channel
().
localAddress
());
System
.
out
.
println
(
NettyServer
.
class
+
" started and listen on "
+
cf
.
channel
().
localAddress
());
cf
.
channel
().
closeFuture
().
sync
();
// 关闭服务器通道
cf
.
channel
().
closeFuture
().
sync
();
// 关闭服务器通道
}
finally
{
}
finally
{
...
...
adc-da-main/src/main/java/com/adc/da/znks/util/netty/ServerHandler.java
View file @
52b8b82a
...
@@ -13,10 +13,12 @@ import io.netty.buffer.Unpooled;
...
@@ -13,10 +13,12 @@ import io.netty.buffer.Unpooled;
import
io.netty.channel.ChannelFutureListener
;
import
io.netty.channel.ChannelFutureListener
;
import
io.netty.channel.ChannelHandlerContext
;
import
io.netty.channel.ChannelHandlerContext
;
import
io.netty.channel.ChannelInboundHandlerAdapter
;
import
io.netty.channel.ChannelInboundHandlerAdapter
;
import
io.netty.channel.group.ChannelGroup
;
import
oracle.jdbc.proxy.annotation.Post
;
import
oracle.jdbc.proxy.annotation.Post
;
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
sun.java2d.pipe.SpanShapeRenderer
;
import
sun.java2d.pipe.SpanShapeRenderer
;
import
sun.rmi.transport.Channel
;
import
javax.annotation.PostConstruct
;
import
javax.annotation.PostConstruct
;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
...
@@ -60,14 +62,15 @@ public class ServerHandler extends ChannelInboundHandlerAdapter {
...
@@ -60,14 +62,15 @@ public class ServerHandler extends ChannelInboundHandlerAdapter {
// 1.上报MAC地址信息 6位mac地址+10位的(MAC-UPLOAD)
// 1.上报MAC地址信息 6位mac地址+10位的(MAC-UPLOAD)
try
{
try
{
int
len
=
SocketUtils
.
bytesToHex
(
result
,
0
,
result
.
length
).
split
(
" "
).
length
;
int
len
=
SocketUtils
.
bytesToHex
(
result
,
0
,
result
.
length
).
split
(
" "
).
length
;
if
(
len
==
16
){
if
(
String
.
valueOf
(
len
).
equals
(
"16"
)
){
String
mac
=
SocketUtils
.
bytesToHex
(
result
,
0
,
6
);
String
mac
=
SocketUtils
.
bytesToHex
(
result
,
0
,
6
);
Gateway
gateway
=
new
Gateway
();
Gateway
gateway
=
new
Gateway
();
gateway
.
setIp
(
host
);
gateway
.
setIp
(
host
);
gateway
.
setMacAddress
(
mac
);
gateway
.
setMacAddress
(
mac
);
serverHandler
.
gatewayService
.
updateIpByMac
(
gateway
);
serverHandler
.
gatewayService
.
updateIpByMac
(
gateway
);
SystemValue
.
ipMacMap
.
put
(
host
,
mac
);
SystemValue
.
ipMacMap
.
put
(
host
,
mac
);
}
else
{
SystemValue
.
channelMap
.
put
(
mac
,
ctx
.
channel
());
}
else
if
(
String
.
valueOf
(
len
).
equals
(
"17"
)
||
String
.
valueOf
(
len
).
equals
(
"14"
)){
String
title
=
""
;
String
title
=
""
;
String
message
=
""
;
String
message
=
""
;
String
clientId
=
""
;
String
clientId
=
""
;
...
@@ -121,7 +124,25 @@ public class ServerHandler extends ChannelInboundHandlerAdapter {
...
@@ -121,7 +124,25 @@ public class ServerHandler extends ChannelInboundHandlerAdapter {
public
void
channelReadComplete
(
ChannelHandlerContext
ctx
)
throws
Exception
{
public
void
channelReadComplete
(
ChannelHandlerContext
ctx
)
throws
Exception
{
System
.
out
.
println
(
"server channelReadComplete.."
);
System
.
out
.
println
(
"server channelReadComplete.."
);
// 第一种方法:写一个空的buf,并刷新写出区域。完成后关闭sock channel连接。
// 第一种方法:写一个空的buf,并刷新写出区域。完成后关闭sock channel连接。
ctx
.
writeAndFlush
(
Unpooled
.
EMPTY_BUFFER
).
addListener
(
ChannelFutureListener
.
CLOSE
);
//ctx.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE);
}
@Override
public
void
channelActive
(
ChannelHandlerContext
ctx
)
throws
Exception
{
System
.
out
.
println
(
"channelActive"
+
ctx
.
channel
().
remoteAddress
());
byte
[]
request
=
new
byte
[
23
];
request
[
0
]
=
0x4d
;
request
[
1
]
=
0x41
;
request
[
2
]
=
0x43
;
request
[
3
]
=
0x5F
;
request
[
4
]
=
0x52
;
request
[
5
]
=
0x45
;
request
[
6
]
=
0x51
;
request
[
7
]
=
0x55
;
request
[
8
]
=
0x45
;
request
[
9
]
=
0x53
;
request
[
10
]
=
0x54
;
ctx
.
channel
().
writeAndFlush
(
request
);
}
}
@Override
@Override
...
...
adc-da-main/src/main/resources/mybatis/mapper/znks/UserEOMapper.xml
View file @
52b8b82a
...
@@ -135,8 +135,8 @@
...
@@ -135,8 +135,8 @@
</if>
</if>
</select>
</select>
<select
id=
"query
IpByUser
"
resultType=
"java.util.Map"
parameterType=
"java.util.Map"
>
<select
id=
"query
MacByPhone
"
resultType=
"java.util.Map"
parameterType=
"java.util.Map"
>
select way.
ip
from tb_user ur,tb_gateway way where ur.id = way.user_id
select way.
mac_address
from tb_user ur,tb_gateway way where ur.id = way.user_id
and ur.temphone = #{phone}
and ur.temphone = #{phone}
</select>
</select>
...
...
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