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
e94771ec
Commit
e94771ec
authored
Sep 06, 2018
by
张大伟
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加新功能,删除无用代码
parent
340fc7eb
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
284 additions
and
1 deletion
+284
-1
GatewayController.java
...in/java/com/adc/da/znks/controller/GatewayController.java
+1
-0
InstructionsController.java
...va/com/adc/da/znks/controller/InstructionsController.java
+112
-0
SocketUtils.java
...-main/src/main/java/com/adc/da/znks/util/SocketUtils.java
+125
-0
DeviceMapper.xml
...n/src/main/resources/mybatis/mapper/znks/DeviceMapper.xml
+24
-0
GatewayMapper.xml
.../src/main/resources/mybatis/mapper/znks/GatewayMapper.xml
+22
-1
No files found.
adc-da-main/src/main/java/com/adc/da/znks/controller/GatewayController.java
View file @
e94771ec
...
@@ -43,6 +43,7 @@ public class GatewayController extends BaseController<Gateway> {
...
@@ -43,6 +43,7 @@ public class GatewayController extends BaseController<Gateway> {
return
GenResponse
.
fail
(
"保存失败"
);
return
GenResponse
.
fail
(
"保存失败"
);
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
GenResponse
.
fail
(
"保存失败"
);
return
GenResponse
.
fail
(
"保存失败"
);
}
}
}
}
...
...
adc-da-main/src/main/java/com/adc/da/znks/controller/InstructionsController.java
0 → 100644
View file @
e94771ec
package
com
.
adc
.
da
.
znks
.
controller
;
import
com.adc.da.znks.entity.ResponseEntity
;
import
com.adc.da.znks.entity.User
;
import
com.adc.da.znks.service.UserService
;
import
com.adc.da.znks.util.GenResponse
;
import
com.adc.da.znks.util.SocketUtils
;
import
io.swagger.annotations.Api
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
/**
* 命令操作activity
* @author David
*/
@RestController
@RequestMapping
(
"/api/instructions"
)
@Api
(
description
=
"| Instructions |"
)
public
class
InstructionsController
{
@Autowired
private
UserService
userService
;
@GetMapping
(
"/loginGateway"
)
public
ResponseEntity
<
Boolean
>
loginGateway
(
String
phoneNumber
)
{
User
user
=
userService
.
getByPhoneNumber
(
phoneNumber
);
if
(
user
!=
null
)
{
// 登录码
byte
[]
login
=
new
byte
[
8
];
login
[
0
]
=
0x2a
;
login
[
1
]
=
0x01
;
login
[
2
]
=
0x02
;
login
[
3
]
=
0x03
;
login
[
4
]
=
0x04
;
login
[
5
]
=
0x05
;
login
[
6
]
=
0x06
;
login
[
7
]
=
0x2a
;
String
result
=
SocketUtils
.
connectServerWithTCPSocket
(
login
,
1
);
if
(
"01"
.
equals
(
result
))
{
return
GenResponse
.
success
(
"1"
,
"登录成功"
,
true
);
}
else
if
(
"00"
.
equals
(
result
))
{
return
GenResponse
.
fail
(
"登录失败"
);
}
else
{
return
GenResponse
.
fail
(
"登录异常"
);
}
}
else
{
return
GenResponse
.
fail
(
"登录异常"
);
}
}
@GetMapping
(
"/openLockOrLearn"
)
public
ResponseEntity
<
Boolean
>
openLockOrLearn
(
String
phoneNumber
,
String
number
)
{
if
(
number
.
length
()
<
2
)
{
number
=
"0"
+
number
;
}
User
user
=
userService
.
getByPhoneNumber
(
phoneNumber
);
if
(
user
!=
null
)
{
byte
[]
open
=
new
byte
[
8
];
open
[
0
]
=
0x54
;
open
[
1
]
=
0x59
;
open
[
2
]
=
0x54
;
open
[
3
]
=
0x01
;
open
[
4
]
=
0x01
;
open
[
5
]
=
0x00
;
open
[
6
]
=
Byte
.
valueOf
(
"0x"
+
number
);
open
[
7
]
=
0x2d
;
String
result
=
SocketUtils
.
connectServerWithTCPSocket
(
open
,
1
);
if
(
"01"
.
equals
(
result
))
{
return
GenResponse
.
success
(
"1"
,
"开锁成功"
,
true
);
}
else
if
(
"00"
.
equals
(
result
))
{
return
GenResponse
.
fail
(
"开锁失败"
);
}
else
{
return
GenResponse
.
fail
(
"开锁异常"
);
}
}
else
{
return
GenResponse
.
fail
(
"开锁异常"
);
}
}
@GetMapping
(
"/securityCodeLearn"
)
public
ResponseEntity
<
Boolean
>
securityCodeLearn
(
String
phoneNumber
,
String
number
)
{
if
(
number
.
length
()
<
2
)
{
number
=
"0"
+
number
;
}
User
user
=
userService
.
getByPhoneNumber
(
phoneNumber
);
if
(
user
!=
null
)
{
byte
[]
open
=
new
byte
[
8
];
open
[
0
]
=
0x54
;
open
[
1
]
=
0x59
;
open
[
2
]
=
0x54
;
open
[
3
]
=
0x01
;
open
[
4
]
=
0x01
;
open
[
5
]
=
0x00
;
open
[
6
]
=
Byte
.
valueOf
(
"0x"
+
number
);
open
[
7
]
=
0x01
;
String
result
=
SocketUtils
.
connectServerWithTCPSocket
(
open
,
1
);
if
(
"01"
.
equals
(
result
))
{
return
GenResponse
.
success
(
"1"
,
"安防码学习成功"
,
true
);
}
else
if
(
"00"
.
equals
(
result
))
{
return
GenResponse
.
fail
(
"安防码学习失败"
);
}
else
{
return
GenResponse
.
fail
(
"安防码学习异常"
);
}
}
else
{
return
GenResponse
.
fail
(
"安防码学习异常"
);
}
}
}
adc-da-main/src/main/java/com/adc/da/znks/util/SocketUtils.java
0 → 100644
View file @
e94771ec
package
com
.
adc
.
da
.
znks
.
util
;
import
java.io.DataOutputStream
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.net.Socket
;
import
java.net.UnknownHostException
;
/**
* <pre>
* author : David
* e-mail : 990860210@qq.com
* time : 2018/09/05
* desc :
* version: 1.0
* </pre>
*/
public
class
SocketUtils
{
public
static
String
connectServerWithTCPSocket
(
byte
[]
msg
,
int
resultLength
)
{
String
hex
=
null
;
Socket
socket
=
null
;
//创建socket
try
{
socket
=
new
Socket
(
"127.0.0.1"
,
9999
);
//ip+端口号
//socket = new Socket("10.10.100.254", 8899);//ip+端口号
System
.
out
.
println
(
"socket连接成功"
);
//向服务器端发送消息
OutputStream
socketWriter
=
socket
.
getOutputStream
();
System
.
out
.
println
(
"开始发送"
);
socketWriter
.
write
(
msg
);
socketWriter
.
flush
();
System
.
out
.
println
(
"发送完毕,开始接收信息"
);
//接收来自服务器端的消息
InputStream
socketReader
=
socket
.
getInputStream
();
byte
strRxBuf
[]
=
new
byte
[
resultLength
];
int
len
=
socketReader
.
read
(
strRxBuf
,
0
,
resultLength
);
if
(
len
!=
0
)
{
hex
=
bytesToHex
(
strRxBuf
,
0
,
resultLength
);
System
.
out
.
println
(
"接收到的byte数组的十六进制:"
+
hex
);
System
.
out
.
println
(
"发送成功"
);
//flag = true;
}
else
{
System
.
out
.
println
(
"没有收到消息"
);
//flag = false;
}
//关闭流
socketWriter
.
close
();
socketReader
.
close
();
//关闭Socket
socket
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
hex
;
}
/**
* 将 byte 数组转化为十六进制字符串
*
* @param bytes byte[] 数组
* @param begin 起始位置
* @param end 结束位置
* @return byte 数组的十六进制字符串表示
*/
public
static
String
bytesToHex
(
byte
[]
bytes
,
int
begin
,
int
end
)
{
StringBuilder
hexBuilder
=
new
StringBuilder
(
2
*
(
end
-
begin
));
for
(
int
i
=
begin
;
i
<
end
;
i
++)
{
hexBuilder
.
append
(
Character
.
forDigit
((
bytes
[
i
]
&
0xF0
)
>>
4
,
16
));
// 转化高四位
hexBuilder
.
append
(
Character
.
forDigit
((
bytes
[
i
]
&
0x0F
),
16
));
// 转化低四位
hexBuilder
.
append
(
' '
);
// 加一个空格将每个字节分隔开
}
return
hexBuilder
.
toString
().
toUpperCase
();
}
public
static
void
main
(
String
[]
args
)
{
// 登录码
byte
[]
login
=
new
byte
[
8
];
login
[
0
]
=
0x2a
;
// 头
login
[
1
]
=
0x01
;
// 第1位密码
login
[
2
]
=
0x02
;
// 第2位密码
login
[
3
]
=
0x03
;
// 第3位密码
login
[
4
]
=
0x04
;
// 第4位密码
login
[
5
]
=
0x05
;
// 第5位密码
login
[
6
]
=
0x06
;
// 第6位密码
login
[
7
]
=
0x2a
;
// 尾
//connectServerWithTCPSocket(login);
// 门锁安防码学习
byte
[]
device
=
new
byte
[
8
];
device
[
0
]
=
0x54
;
// 校验码1:t
device
[
1
]
=
0x59
;
// 校验码2:y
device
[
2
]
=
0x54
;
// 校验码3:t
device
[
3
]
=
0x01
;
// 识别码0x01为指纹锁
device
[
4
]
=
0x01
;
// 区域码
device
[
5
]
=
0x00
;
// 房间码
device
[
6
]
=
0x00
;
// 设备编码
device
[
7
]
=
0x01
;
// 功能码 安防码学习默认01
connectServerWithTCPSocket
(
device
,
8
);
// 门锁设备码学习/ 开锁指令
byte
[]
open
=
new
byte
[
8
];
open
[
0
]
=
0x54
;
// 校验码1:t
open
[
1
]
=
0x59
;
// 校验码2:y
open
[
2
]
=
0x54
;
// 校验码3:t
open
[
3
]
=
0x01
;
// 识别码0x01为指纹锁
open
[
4
]
=
0x01
;
// 区域码
open
[
5
]
=
0x00
;
// 房间码
open
[
6
]
=
0x00
;
// 设备编码
open
[
7
]
=
0x2d
;
// 功能码 2d:开指令/ 学习
//connectServerWithTCPSocket(open);
}
}
adc-da-main/src/main/resources/mybatis/mapper/znks/DeviceMapper.xml
View file @
e94771ec
...
@@ -16,4 +16,28 @@
...
@@ -16,4 +16,28 @@
where tb_device.user_id = tb_user.id
where tb_device.user_id = tb_user.id
and tb_user.temphone = #{phoneNumber}
and tb_user.temphone = #{phoneNumber}
</select>
</select>
<!-- 动态插入记录 主键是序列 -->
<insert
id=
"insertSelective"
parameterType=
"com.adc.da.znks.entity.Gateway"
>
insert into tb_device
<trim
prefix=
"("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"id != null"
>
id,
</if>
<if
test=
"name != null"
>
name,
</if>
<if
test=
"code != null"
>
code,
</if>
<if
test=
"type != null"
>
type,
</if>
<if
test=
"userName != null"
>
user_name,
</if>
<if
test=
"userPassword != null"
>
user_password,
</if>
<if
test=
"uid != null"
>
uid,
</if>
</trim>
<trim
prefix=
"values ("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"id != null"
>
#{id, jdbcType=VARCHAR},
</if>
<if
test=
"name != null"
>
#{name, jdbcType=VARCHAR},
</if>
<if
test=
"code != null"
>
#{code, jdbcType=INTEGER},
</if>
<if
test=
"type != null"
>
#{type, jdbcType=INTEGER},
</if>
<if
test=
"userName != null"
>
#{userName, jdbcType=VARCHAR},
</if>
<if
test=
"userPassword != null"
>
#{userPassword, jdbcType=VARCHAR},
</if>
<if
test=
"uid != null"
>
#{uid, jdbcType=VARCHAR},
</if>
</trim>
</insert>
</mapper>
</mapper>
adc-da-main/src/main/resources/mybatis/mapper/znks/GatewayMapper.xml
View file @
e94771ec
...
@@ -7,12 +7,33 @@
...
@@ -7,12 +7,33 @@
<result
column=
"user_id"
property=
"userId"
/>
<result
column=
"user_id"
property=
"userId"
/>
<result
column=
"mac_address"
property=
"macAddress"
/>
<result
column=
"mac_address"
property=
"macAddress"
/>
<result
column=
"ip"
property=
"ip"
/>
<result
column=
"ip"
property=
"ip"
/>
<result
column=
"password"
property=
"password"
/>
</resultMap>
</resultMap>
<!-- tb_position table all fields -->
<!-- tb_position table all fields -->
<sql
id=
"Base_Column_List"
>
<sql
id=
"Base_Column_List"
>
id, user_id, mac_address, ip
id, user_id, mac_address, ip
, password
</sql>
</sql>
<!-- 动态插入记录 主键是序列 -->
<insert
id=
"insertSelective"
parameterType=
"com.adc.da.znks.entity.Gateway"
>
insert into tb_gateway
<trim
prefix=
"("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"id != null"
>
id,
</if>
<if
test=
"userId != null"
>
user_id,
</if>
<if
test=
"macAddress != null"
>
mac_address,
</if>
<if
test=
"ip != null"
>
ip,
</if>
<if
test=
"password != null"
>
password,
</if>
</trim>
<trim
prefix=
"values ("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"id != null"
>
#{id, jdbcType=VARCHAR},
</if>
<if
test=
"userId != null"
>
#{userId, jdbcType=VARCHAR},
</if>
<if
test=
"macAddress != null"
>
#{macAddress, jdbcType=VARCHAR},
</if>
<if
test=
"ip != null"
>
#{ip, jdbcType=VARCHAR},
</if>
<if
test=
"password != null"
>
#{password, jdbcType=VARCHAR},
</if>
</trim>
</insert>
<select
id=
"getByPhoneNumber"
resultType=
"com.adc.da.znks.entity.Gateway"
>
<select
id=
"getByPhoneNumber"
resultType=
"com.adc.da.znks.entity.Gateway"
>
select * from tb_gateway,tb_user
select * from tb_gateway,tb_user
where tb_gateway.user_id = tb_user.id
where tb_gateway.user_id = tb_user.id
...
...
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