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
0b088e72
Commit
0b088e72
authored
Sep 10, 2018
by
王夏晖
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug修改
parent
c0fd2deb
Changes
21
Hide whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
608 additions
and
41 deletions
+608
-41
AdcDaApplication.java
adc-da-main/src/main/java/com/adc/da/AdcDaApplication.java
+7
-0
DeviceController.java
...ain/java/com/adc/da/znks/controller/DeviceController.java
+1
-1
InstructionsController.java
...va/com/adc/da/znks/controller/InstructionsController.java
+188
-18
UserController.java
.../main/java/com/adc/da/znks/controller/UserController.java
+18
-4
DeviceDao.java
adc-da-main/src/main/java/com/adc/da/znks/dao/DeviceDao.java
+3
-0
GatewayDao.java
...da-main/src/main/java/com/adc/da/znks/dao/GatewayDao.java
+6
-0
LockRecordDao.java
...main/src/main/java/com/adc/da/znks/dao/LockRecordDao.java
+22
-0
UserDao.java
adc-da-main/src/main/java/com/adc/da/znks/dao/UserDao.java
+2
-0
LockRecord.java
...main/src/main/java/com/adc/da/znks/entity/LockRecord.java
+63
-0
DeviceService.java
.../src/main/java/com/adc/da/znks/service/DeviceService.java
+5
-0
GatewayService.java
...src/main/java/com/adc/da/znks/service/GatewayService.java
+8
-0
LockRecordService.java
.../main/java/com/adc/da/znks/service/LockRecordService.java
+63
-0
UserService.java
...in/src/main/java/com/adc/da/znks/service/UserService.java
+5
-0
SystemValue.java
...-main/src/main/java/com/adc/da/znks/util/SystemValue.java
+16
-0
Test.java
adc-da-main/src/main/java/com/adc/da/znks/util/Test.java
+20
-0
NettyServer.java
...src/main/java/com/adc/da/znks/util/netty/NettyServer.java
+9
-1
ServerHandler.java
...c/main/java/com/adc/da/znks/util/netty/ServerHandler.java
+120
-13
DeviceMapper.xml
...n/src/main/resources/mybatis/mapper/znks/DeviceMapper.xml
+4
-0
GatewayMapper.xml
.../src/main/resources/mybatis/mapper/znks/GatewayMapper.xml
+4
-0
LockRecordMapper.xml
...c/main/resources/mybatis/mapper/znks/LockRecordMapper.xml
+38
-0
UserEOMapper.xml
...n/src/main/resources/mybatis/mapper/znks/UserEOMapper.xml
+6
-4
No files found.
adc-da-main/src/main/java/com/adc/da/AdcDaApplication.java
View file @
0b088e72
...
...
@@ -2,6 +2,7 @@ package com.adc.da;
import
java.util.concurrent.TimeUnit
;
import
com.adc.da.znks.util.netty.NettyServer
;
import
org.mybatis.spring.annotation.MapperScan
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
...
...
@@ -30,6 +31,12 @@ public class AdcDaApplication {
// 启动Metrics 性能监控报表
// CsvReporter reporter = applicationContext.getBean(CsvReporter.class);
// reporter.start(1, TimeUnit.MINUTES);
try
{
new
NettyServer
(
9999
).
start
();
}
catch
(
Exception
e
){
e
.
printStackTrace
();
}
}
/**
...
...
adc-da-main/src/main/java/com/adc/da/znks/controller/DeviceController.java
View file @
0b088e72
...
...
@@ -54,7 +54,7 @@ public class DeviceController extends BaseController<Device> {
@GetMapping
(
"/delete"
)
public
ResponseEntity
<
Boolean
>
delete
(
String
id
)
{
try
{
deviceService
.
delete
ByPrimaryKey
(
id
);
deviceService
.
delete
DeviceById
(
id
);
return
GenResponse
.
success
();
}
catch
(
Exception
e
)
{
return
GenResponse
.
fail
(
"删除失败"
);
...
...
adc-da-main/src/main/java/com/adc/da/znks/controller/InstructionsController.java
View file @
0b088e72
...
...
@@ -44,7 +44,7 @@ public class InstructionsController {
if
(
ip
==
null
){
return
GenResponse
.
fail
(
"网关ip获取失败"
);
}
String
result
=
SocketUtils
.
connectServerWithTCPSocket
(
login
,
1
,
ip
,
99
99
);
String
result
=
SocketUtils
.
connectServerWithTCPSocket
(
login
,
1
,
ip
,
88
99
);
if
(
"01"
.
equals
(
result
))
{
return
GenResponse
.
success
(
"1"
,
"登录成功"
,
true
);
}
else
if
(
"00"
.
equals
(
result
))
{
...
...
@@ -58,10 +58,7 @@ public class InstructionsController {
}
@GetMapping
(
"/openLockOrLearn"
)
public
ResponseEntity
<
Boolean
>
openLockOrLearn
(
String
phoneNumber
,
String
number
)
{
if
(
number
.
length
()
<
2
)
{
number
=
"0"
+
number
;
}
public
ResponseEntity
<
Boolean
>
openLockOrLearn
(
String
phoneNumber
,
int
number
)
{
User
user
=
userService
.
getByPhoneNumber
(
phoneNumber
);
if
(
user
!=
null
)
{
byte
[]
open
=
new
byte
[
8
];
...
...
@@ -71,13 +68,13 @@ public class InstructionsController {
open
[
3
]
=
0x00
;
open
[
4
]
=
0x01
;
open
[
5
]
=
0x00
;
open
[
6
]
=
0x01
;
open
[
6
]
=
(
byte
)
number
;
open
[
7
]
=
0x2d
;
String
ip
=
getIp
(
phoneNumber
);
if
(
ip
==
null
){
return
GenResponse
.
fail
(
"网关ip获取失败"
);
}
String
result
=
SocketUtils
.
connectServerWithTCPSocket
(
open
,
1
,
ip
,
99
99
);
String
result
=
SocketUtils
.
connectServerWithTCPSocket
(
open
,
1
,
ip
,
88
99
);
if
(
"01"
.
equals
(
result
))
{
return
GenResponse
.
success
(
"1"
,
"开锁成功"
,
true
);
}
else
if
(
"00"
.
equals
(
result
))
{
...
...
@@ -91,11 +88,8 @@ public class InstructionsController {
}
@GetMapping
(
"/securityCodeLearn"
)
public
ResponseEntity
<
Boolean
>
securityCodeLearn
(
String
phoneNumber
,
String
number
)
{
public
ResponseEntity
<
Boolean
>
securityCodeLearn
(
String
phoneNumber
,
int
number
)
{
if
(
number
.
length
()
<
2
)
{
number
=
"0"
+
number
;
}
User
user
=
userService
.
getByPhoneNumber
(
phoneNumber
);
if
(
user
!=
null
)
{
byte
[]
open
=
new
byte
[
8
];
...
...
@@ -105,13 +99,13 @@ public class InstructionsController {
open
[
3
]
=
0x01
;
open
[
4
]
=
0x01
;
open
[
5
]
=
0x00
;
open
[
6
]
=
0x01
;
open
[
6
]
=
(
byte
)
number
;
open
[
7
]
=
0x01
;
String
ip
=
getIp
(
phoneNumber
);
if
(
ip
==
null
){
return
GenResponse
.
fail
(
"网关ip获取失败"
);
}
String
result
=
SocketUtils
.
connectServerWithTCPSocket
(
open
,
1
,
ip
,
99
99
);
String
result
=
SocketUtils
.
connectServerWithTCPSocket
(
open
,
1
,
ip
,
88
99
);
if
(
"01"
.
equals
(
result
))
{
return
GenResponse
.
success
(
"1"
,
"安防码学习成功"
,
true
);
}
else
if
(
"00"
.
equals
(
result
))
{
...
...
@@ -124,12 +118,50 @@ public class InstructionsController {
}
}
@GetMapping
(
"/securityCancel"
)
public
ResponseEntity
<
Boolean
>
securityCancel
(
String
phoneNumber
,
String
number
)
{
/**
* 布防
* @param phoneNumber
* @return
*/
@GetMapping
(
"/securityAdd"
)
public
ResponseEntity
<
Boolean
>
securityAdd
(
String
phoneNumber
)
{
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
]
=
0x30
;
open
[
4
]
=
0x01
;
open
[
5
]
=
0x00
;
open
[
6
]
=
0x00
;
open
[
7
]
=
(
byte
)
0xF0
;
String
ip
=
getIp
(
phoneNumber
);
if
(
ip
==
null
){
return
GenResponse
.
fail
(
"网关ip获取失败"
);
}
String
result
=
SocketUtils
.
connectServerWithTCPSocket
(
open
,
1
,
ip
,
8899
);
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
(
"布防失败"
);
}
}
/**
* 撤防
* @param phoneNumber
* @return
*/
@GetMapping
(
"/securityCancel"
)
public
ResponseEntity
<
Boolean
>
securityCancel
(
String
phoneNumber
)
{
User
user
=
userService
.
getByPhoneNumber
(
phoneNumber
);
if
(
user
!=
null
)
{
byte
[]
open
=
new
byte
[
8
];
...
...
@@ -145,7 +177,7 @@ public class InstructionsController {
if
(
ip
==
null
){
return
GenResponse
.
fail
(
"网关ip获取失败"
);
}
String
result
=
SocketUtils
.
connectServerWithTCPSocket
(
open
,
1
,
ip
,
99
99
);
String
result
=
SocketUtils
.
connectServerWithTCPSocket
(
open
,
1
,
ip
,
88
99
);
if
(
"01"
.
equals
(
result
))
{
return
GenResponse
.
success
(
"1"
,
"撤防成功"
,
true
);
}
else
if
(
"00"
.
equals
(
result
))
{
...
...
@@ -158,6 +190,144 @@ public class InstructionsController {
}
}
/**
* 进入组网
* @param phoneNumber
* @return
*/
@GetMapping
(
"/enterZigbee"
)
public
ResponseEntity
<
Boolean
>
enterZigbee
(
String
phoneNumber
)
{
User
user
=
userService
.
getByPhoneNumber
(
phoneNumber
);
if
(
user
!=
null
)
{
byte
[]
open
=
new
byte
[
6
];
open
[
0
]
=
0x5C
;
open
[
1
]
=
(
byte
)
0xC5
;
open
[
2
]
=
(
byte
)
0xFF
;
open
[
3
]
=
0x01
;
open
[
4
]
=
0x01
;
open
[
5
]
=
0x22
;
String
ip
=
getIp
(
phoneNumber
);
if
(
ip
==
null
){
return
GenResponse
.
fail
(
"网关ip获取失败"
);
}
String
result
=
SocketUtils
.
connectServerWithTCPSocket
(
open
,
1
,
ip
,
8899
);
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
(
"进入组网失败"
);
}
}
/**
* 退出组网
* @param phoneNumber
* @return
*/
@GetMapping
(
"/abortZigbee"
)
public
ResponseEntity
<
Boolean
>
abortZigbee
(
String
phoneNumber
)
{
User
user
=
userService
.
getByPhoneNumber
(
phoneNumber
);
if
(
user
!=
null
)
{
byte
[]
open
=
new
byte
[
6
];
open
[
0
]
=
0x5C
;
open
[
1
]
=
(
byte
)
0xC5
;
open
[
2
]
=
(
byte
)
0xFF
;
open
[
3
]
=
0x01
;
open
[
4
]
=
0x02
;
open
[
5
]
=
0x23
;
String
ip
=
getIp
(
phoneNumber
);
if
(
ip
==
null
){
return
GenResponse
.
fail
(
"网关ip获取失败"
);
}
String
result
=
SocketUtils
.
connectServerWithTCPSocket
(
open
,
1
,
ip
,
8899
);
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
(
"退出组网失败"
);
}
}
/**
* zigBee恢复出厂
* @param phoneNumber
* @return
*/
@GetMapping
(
"/restoreZigbee"
)
public
ResponseEntity
<
Boolean
>
restoreZigbee
(
String
phoneNumber
)
{
User
user
=
userService
.
getByPhoneNumber
(
phoneNumber
);
if
(
user
!=
null
)
{
byte
[]
open
=
new
byte
[
6
];
open
[
0
]
=
0x5C
;
open
[
1
]
=
(
byte
)
0xC5
;
open
[
2
]
=
(
byte
)
0xFF
;
open
[
3
]
=
0x01
;
open
[
4
]
=
0x03
;
open
[
5
]
=
0x24
;
String
ip
=
getIp
(
phoneNumber
);
if
(
ip
==
null
){
return
GenResponse
.
fail
(
"网关ip获取失败"
);
}
String
result
=
SocketUtils
.
connectServerWithTCPSocket
(
open
,
1
,
ip
,
8899
);
if
(
"01"
.
equals
(
result
))
{
return
GenResponse
.
success
(
"1"
,
"zigBee恢复出厂成功"
,
true
);
}
else
if
(
"00"
.
equals
(
result
))
{
return
GenResponse
.
fail
(
"zigBee恢复出厂失败"
);
}
else
{
return
GenResponse
.
fail
(
"zigBee恢复出厂失败"
);
}
}
else
{
return
GenResponse
.
fail
(
"zigBee恢复出厂失败"
);
}
}
/**
* wifi恢复出厂
* @param phoneNumber
* @return
*/
@GetMapping
(
"/restoreWifi"
)
public
ResponseEntity
<
Boolean
>
restoreWifi
(
String
phoneNumber
)
{
User
user
=
userService
.
getByPhoneNumber
(
phoneNumber
);
if
(
user
!=
null
)
{
byte
[]
open
=
new
byte
[
6
];
open
[
0
]
=
0x5C
;
open
[
1
]
=
(
byte
)
0xC5
;
open
[
2
]
=
(
byte
)
0xFF
;
open
[
3
]
=
0x01
;
open
[
4
]
=
0x04
;
open
[
5
]
=
0x25
;
String
ip
=
getIp
(
phoneNumber
);
if
(
ip
==
null
){
return
GenResponse
.
fail
(
"网关ip获取失败"
);
}
String
result
=
SocketUtils
.
connectServerWithTCPSocket
(
open
,
1
,
ip
,
8899
);
if
(
"01"
.
equals
(
result
))
{
return
GenResponse
.
success
(
"1"
,
"wifi恢复出厂成功"
,
true
);
}
else
if
(
"00"
.
equals
(
result
))
{
return
GenResponse
.
fail
(
"wifi恢复出厂失败"
);
}
else
{
return
GenResponse
.
fail
(
"wifi恢复出厂失败"
);
}
}
else
{
return
GenResponse
.
fail
(
"wifi恢复出厂失败"
);
}
}
public
String
getIp
(
String
phone
){
List
<
Map
<
String
,
Object
>>
list
=
userService
.
queryIpByUser
(
phone
);
if
(
list
!=
null
){
...
...
adc-da-main/src/main/java/com/adc/da/znks/controller/UserController.java
View file @
0b088e72
package
com
.
adc
.
da
.
znks
.
controller
;
import
com.adc.da.base.web.BaseController
;
import
com.adc.da.util.http.ResponseMessage
;
import
com.adc.da.util.http.Result
;
import
com.adc.da.znks.entity.ResponseEntity
;
import
com.adc.da.znks.entity.User
;
import
com.adc.da.znks.service.LockRecordService
;
import
com.adc.da.znks.service.UserService
;
import
com.adc.da.znks.util.GenResponse
;
import
io.swagger.annotations.Api
;
...
...
@@ -23,14 +26,15 @@ public class UserController extends BaseController<User> {
@Autowired
private
UserService
userService
;
@Autowired
private
LockRecordService
lockRecordService
;
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
UserController
.
class
);
@ApiOperation
(
value
=
"|User|登录或者注册用户"
)
@PostMapping
(
value
=
{
"/loginOrRegisterUser"
})
public
ResponseEntity
<
Boolean
>
loginOrRegisterUser
(
@RequestBody
User
user
)
{
log
.
info
(
"user: {}"
,
user
);
boolean
flag
=
userService
.
loginOrRegister
(
user
.
getTemphone
(),
user
.
getPlainPassword
());
public
ResponseEntity
<
Boolean
>
loginOrRegisterUser
(
String
phoneNumber
,
String
password
)
{
boolean
flag
=
userService
.
loginOrRegister
(
phoneNumber
,
password
);
if
(
flag
)
{
return
GenResponse
.
success
(
String
.
valueOf
(
HttpStatus
.
OK
.
value
()),
"登录或者注册用户成功"
,
flag
);
}
else
{
...
...
@@ -47,7 +51,10 @@ public class UserController extends BaseController<User> {
@ApiOperation
(
value
=
"|User|更新密码"
)
@PostMapping
(
"/updatePassword"
)
public
ResponseEntity
<
Boolean
>
update
(
@RequestBody
User
user
)
{
public
ResponseEntity
<
Boolean
>
update
(
String
phoneNumber
,
String
password
)
{
User
user
=
new
User
();
user
.
setTemphone
(
phoneNumber
);
user
.
setPlainPassword
(
password
);
boolean
flag
=
userService
.
updatePassword
(
user
);
if
(
flag
)
{
return
GenResponse
.
success
(
String
.
valueOf
(
HttpStatus
.
OK
.
value
()),
"更新密码成功"
,
flag
);
...
...
@@ -62,5 +69,12 @@ public class UserController extends BaseController<User> {
userService
.
updateClientIdByPhoneNumber
(
clientId
,
phoneNumber
);
return
GenResponse
.
success
();
}
//selectLockRecord
@ApiOperation
(
value
=
"开锁日志"
)
@GetMapping
(
"/listLockRecord"
)
public
ResponseMessage
listLockRecord
(
String
phone
,
String
number
)
{
return
Result
.
success
(
lockRecordService
.
selectLockRecord
(
phone
,
number
));
}
}
adc-da-main/src/main/java/com/adc/da/znks/dao/DeviceDao.java
View file @
0b088e72
...
...
@@ -3,6 +3,7 @@ package com.adc.da.znks.dao;
import
com.adc.da.base.dao.BaseDao
;
import
com.adc.da.znks.entity.Device
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
...
...
@@ -19,4 +20,6 @@ public interface DeviceDao extends BaseDao<Device> {
*/
List
<
Device
>
listByPhoneNumber
(
String
phoneNumber
);
void
deleteDeviceById
(
@Param
(
"id"
)
String
id
);
}
adc-da-main/src/main/java/com/adc/da/znks/dao/GatewayDao.java
View file @
0b088e72
...
...
@@ -3,6 +3,10 @@ package com.adc.da.znks.dao;
import
com.adc.da.base.dao.BaseDao
;
import
com.adc.da.znks.entity.Gateway
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
import
java.util.Map
;
@Mapper
public
interface
GatewayDao
extends
BaseDao
<
Gateway
>
{
...
...
@@ -16,4 +20,6 @@ public interface GatewayDao extends BaseDao<Gateway> {
void
updateIpByMac
(
Gateway
gateway
);
List
<
Map
<
String
,
Object
>>
selectIp
(
@Param
(
"ip"
)
String
ip
);
}
adc-da-main/src/main/java/com/adc/da/znks/dao/LockRecordDao.java
0 → 100644
View file @
0b088e72
package
com
.
adc
.
da
.
znks
.
dao
;
import
com.adc.da.base.dao.BaseDao
;
import
com.adc.da.znks.entity.Device
;
import
com.adc.da.znks.entity.LockRecord
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
import
java.util.Map
;
/**
* @author David
*/
@Mapper
public
interface
LockRecordDao
extends
BaseDao
<
LockRecord
>
{
void
insertLockRecord
(
LockRecord
lockRecord
);
List
<
Map
<
String
,
Object
>>
selectLockRecord
(
@Param
(
"phone"
)
String
phone
,
@Param
(
"deviceCode"
)
String
deviceCode
);
}
adc-da-main/src/main/java/com/adc/da/znks/dao/UserDao.java
View file @
0b088e72
...
...
@@ -27,4 +27,6 @@ public interface UserDao extends BaseDao<User> {
@Update
(
"UPDATE tb_user SET client_id = #{clientId} WHERE temphone = #{phoneNumber}"
)
int
updateClientIdByPhoneNumber
(
@Param
(
"clientId"
)
String
clientId
,
@Param
(
"phoneNumber"
)
String
phoneNumber
);
List
<
Map
<
String
,
Object
>>
queryClientByIp
(
@Param
(
"ip"
)
String
ip
);
}
adc-da-main/src/main/java/com/adc/da/znks/entity/LockRecord.java
0 → 100644
View file @
0b088e72
package
com
.
adc
.
da
.
znks
.
entity
;
import
com.adc.da.base.entity.BaseEntity
;
import
java.util.Date
;
/**
* @ClassName LockRecord
* @Descroption TODO
* @Author 王夏晖
* @Date 2018/9/9 0009 10:24
**/
public
class
LockRecord
extends
BaseEntity
{
private
int
id
;
private
Date
time
;
private
int
user
;
private
String
deviceId
;
private
String
lockType
;
public
int
getId
()
{
return
id
;
}
public
void
setId
(
int
id
)
{
this
.
id
=
id
;
}
public
Date
getTime
()
{
return
time
;
}
public
void
setTime
(
Date
time
)
{
this
.
time
=
time
;
}
public
int
getUser
()
{
return
user
;
}
public
void
setUser
(
int
user
)
{
this
.
user
=
user
;
}
public
String
getDeviceId
()
{
return
deviceId
;
}
public
void
setDeviceId
(
String
deviceId
)
{
this
.
deviceId
=
deviceId
;
}
public
String
getLockType
()
{
return
lockType
;
}
public
void
setLockType
(
String
lockType
)
{
this
.
lockType
=
lockType
;
}
}
adc-da-main/src/main/java/com/adc/da/znks/service/DeviceService.java
View file @
0b088e72
...
...
@@ -4,6 +4,7 @@ import com.adc.da.base.dao.BaseDao;
import
com.adc.da.base.service.BaseService
;
import
com.adc.da.znks.dao.DeviceDao
;
import
com.adc.da.znks.entity.Device
;
import
org.apache.ibatis.annotations.Param
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
...
...
@@ -29,4 +30,8 @@ public class DeviceService extends BaseService<Device, String> {
public
List
<
Device
>
listByPhoneNumber
(
String
phoneNumber
)
{
return
dao
.
listByPhoneNumber
(
phoneNumber
);
}
public
void
deleteDeviceById
(
String
id
){
dao
.
deleteDeviceById
(
id
);
}
}
adc-da-main/src/main/java/com/adc/da/znks/service/GatewayService.java
View file @
0b088e72
...
...
@@ -4,6 +4,7 @@ import com.adc.da.base.dao.BaseDao;
import
com.adc.da.base.service.BaseService
;
import
com.adc.da.znks.dao.GatewayDao
;
import
com.adc.da.znks.entity.Gateway
;
import
org.apache.ibatis.annotations.Param
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -11,6 +12,9 @@ import org.springframework.stereotype.Service;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.List
;
import
java.util.Map
;
/**
* @author David
*/
...
...
@@ -40,4 +44,8 @@ public class GatewayService extends BaseService<Gateway, String> {
public
void
updateIpByMac
(
Gateway
gateway
){
dao
.
updateIpByMac
(
gateway
);
}
public
List
<
Map
<
String
,
Object
>>
selectIpByMac
(
String
ip
){
return
dao
.
selectIp
(
ip
);
}
}
adc-da-main/src/main/java/com/adc/da/znks/service/LockRecordService.java
0 → 100644
View file @
0b088e72
package
com
.
adc
.
da
.
znks
.
service
;
import
com.adc.da.base.dao.BaseDao
;
import
com.adc.da.base.service.BaseService
;
import
com.adc.da.znks.dao.DeviceDao
;
import
com.adc.da.znks.dao.LockRecordDao
;
import
com.adc.da.znks.entity.Device
;
import
com.adc.da.znks.entity.LockRecord
;
import
org.apache.ibatis.annotations.Param
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* @author David
*/
@Service
@Transactional
(
value
=
"transactionManager"
,
propagation
=
Propagation
.
REQUIRED
,
rollbackFor
=
Throwable
.
class
)
public
class
LockRecordService
extends
BaseService
<
LockRecord
,
String
>
{
@Autowired
(
required
=
false
)
private
LockRecordDao
dao
;
@Override
public
BaseDao
<
LockRecord
>
getDao
()
{
return
dao
;
}
public
void
insertLockRecord
(
LockRecord
lockRecord
){
dao
.
insertLockRecord
(
lockRecord
);
}
public
List
<
Map
<
String
,
Object
>>
selectLockRecord
(
String
phone
,
String
deviceCode
){
List
<
Map
<
String
,
Object
>>
result
=
new
ArrayList
<>();
List
<
Map
<
String
,
Object
>>
list
=
dao
.
selectLockRecord
(
phone
,
deviceCode
);
List
<
String
>
dayList
=
new
ArrayList
<>();
for
(
Map
<
String
,
Object
>
tmap
:
list
){
if
(!
dayList
.
contains
(
tmap
.
get
(
"day"
))){
dayList
.
add
(
tmap
.
get
(
"day"
).
toString
());
}
}
for
(
String
day
:
dayList
){
Map
<
String
,
Object
>
dayMap
=
new
HashMap
<>();
List
<
Map
<
String
,
Object
>>
dayReList
=
new
ArrayList
<>();
for
(
Map
<
String
,
Object
>
t
:
list
){
if
(
day
.
equals
(
t
.
get
(
"day"
).
toString
())){
dayReList
.
add
(
t
);
}
}
dayMap
.
put
(
"day"
,
day
);
dayMap
.
put
(
"dayList"
,
dayReList
);
result
.
add
(
dayMap
);
}
return
result
;
}
}
adc-da-main/src/main/java/com/adc/da/znks/service/UserService.java
View file @
0b088e72
...
...
@@ -69,6 +69,7 @@ public class UserService extends BaseService<User, String> {
User
updateUser
=
new
User
();
updateUser
.
setPassword
(
encryptList
.
get
(
1
));
updateUser
.
setEncryptkey
(
encryptList
.
get
(
0
));
updateUser
.
setTemphone
(
user
.
getTemphone
());
int
result
=
dao
.
updateByPrimaryKeySelective
(
updateUser
);
if
(
result
!=
0
)
{
return
true
;
...
...
@@ -131,4 +132,8 @@ public class UserService extends BaseService<User, String> {
public
void
updateClientIdByPhoneNumber
(
String
clientId
,
String
phoneNumber
)
{
dao
.
updateClientIdByPhoneNumber
(
clientId
,
phoneNumber
);
}
public
List
<
Map
<
String
,
Object
>>
queryClientByIp
(
@Param
(
"ip"
)
String
ip
){
return
dao
.
queryClientByIp
(
ip
);
}
}
adc-da-main/src/main/java/com/adc/da/znks/util/SystemValue.java
0 → 100644
View file @
0b088e72
package
com
.
adc
.
da
.
znks
.
util
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* @ClassName SystemValue
* @Descroption TODO
* @Author 王夏晖
* @Date 2018/9/10 0010 12:05
**/
public
class
SystemValue
{
public
static
Map
<
String
,
String
>
ipMacMap
=
new
HashMap
<>();
}
adc-da-main/src/main/java/com/adc/da/znks/util/Test.java
View file @
0b088e72
package
com
.
adc
.
da
.
znks
.
util
;
import
java.math.BigInteger
;
/**
* @ClassName Test
* @Descroption TODO
...
...
@@ -51,5 +53,23 @@ public class Test {
}
}
System.out.println(list);*/
byte
[]
b
=
{
0x54
,
0x59
};
System
.
out
.
println
(
SocketUtils
.
bytesToHex
(
b
,
0
,
b
.
length
).
split
(
" "
).
length
);
}
public
static
String
hexString
(
byte
[]
bs
)
{
return
new
BigInteger
(
1
,
bs
).
toString
(
16
);
}
private
static
String
intToHex
(
int
n
)
{
StringBuffer
s
=
new
StringBuffer
();
String
a
;
char
[]
b
=
{
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
'A'
,
'B'
,
'C'
,
'D'
,
'E'
,
'F'
};
while
(
n
!=
0
){
s
=
s
.
append
(
b
[
n
%
16
]);
n
=
n
/
16
;
}
a
=
s
.
reverse
().
toString
();
return
a
;
}
}
adc-da-main/src/main/java/com/adc/da/znks/util/netty/NettyServer.java
View file @
0b088e72
package
com
.
adc
.
da
.
znks
.
util
.
netty
;
import
com.adc.da.znks.service.GatewayService
;
import
com.adc.da.znks.util.SocketUtils
;
import
com.adc.da.znks.util.SystemValue
;
import
io.netty.bootstrap.ServerBootstrap
;
import
io.netty.channel.ChannelFuture
;
import
io.netty.channel.ChannelInitializer
;
...
...
@@ -10,6 +12,10 @@ import io.netty.channel.socket.SocketChannel;
import
io.netty.channel.socket.nio.NioServerSocketChannel
;
import
io.netty.handler.codec.bytes.ByteArrayDecoder
;
import
io.netty.handler.codec.bytes.ByteArrayEncoder
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.PostConstruct
;
public
class
NettyServer
{
private
final
int
port
;
...
...
@@ -31,7 +37,9 @@ public class NettyServer {
protected
void
initChannel
(
SocketChannel
ch
)
throws
Exception
{
System
.
out
.
println
(
"connected...; Client:"
+
ch
.
remoteAddress
().
getHostString
());
//發送請求指令
connectGateway
(
ch
.
remoteAddress
().
getHostString
(),
8899
);
if
(
SystemValue
.
ipMacMap
.
get
(
ch
.
remoteAddress
().
getHostString
())
==
null
){
connectGateway
(
ch
.
remoteAddress
().
getHostString
(),
8899
);
}
ch
.
pipeline
().
addLast
(
new
ByteArrayEncoder
());
ch
.
pipeline
().
addLast
(
new
ByteArrayDecoder
());
ch
.
pipeline
().
addLast
(
new
ServerHandler
());
// 客户端触发操作
...
...
adc-da-main/src/main/java/com/adc/da/znks/util/netty/ServerHandler.java
View file @
0b088e72
package
com
.
adc
.
da
.
znks
.
util
.
netty
;
import
com.adc.da.znks.entity.Gateway
;
import
com.adc.da.znks.entity.LockRecord
;
import
com.adc.da.znks.service.GatewayService
;
import
com.adc.da.znks.service.LockRecordService
;
import
com.adc.da.znks.service.UserService
;
import
com.adc.da.znks.util.AppPushUtils
;
import
com.adc.da.znks.util.SocketUtils
;
import
com.adc.da.znks.util.SystemValue
;
import
io.netty.buffer.ByteBuf
;
import
io.netty.buffer.Unpooled
;
import
io.netty.channel.ChannelFutureListener
;
...
...
@@ -12,8 +16,13 @@ import io.netty.channel.ChannelInboundHandlerAdapter;
import
oracle.jdbc.proxy.annotation.Post
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
sun.java2d.pipe.SpanShapeRenderer
;
import
javax.annotation.PostConstruct
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
/**
* 接收socket请求
...
...
@@ -24,6 +33,10 @@ public class ServerHandler extends ChannelInboundHandlerAdapter {
@Autowired
private
GatewayService
gatewayService
;
@Autowired
private
LockRecordService
lockRecordService
;
@Autowired
private
UserService
userService
;
public
static
ServerHandler
serverHandler
;
...
...
@@ -31,6 +44,8 @@ public class ServerHandler extends ChannelInboundHandlerAdapter {
public
void
init
(){
serverHandler
=
this
;
serverHandler
.
gatewayService
=
this
.
gatewayService
;
serverHandler
.
lockRecordService
=
this
.
lockRecordService
;
serverHandler
.
userService
=
this
.
userService
;
}
@Override
...
...
@@ -42,19 +57,61 @@ public class ServerHandler extends ChannelInboundHandlerAdapter {
byte
[]
result
=
(
byte
[])
msg
;
System
.
out
.
println
(
SocketUtils
.
bytesToHex
(
result
,
0
,
result
.
length
));
// 在此处需要分别解析
// 1.上报MAC地址信息
String
mac
=
SocketUtils
.
bytesToHex
(
result
,
0
,
result
.
length
);
Gateway
gateway
=
new
Gateway
();
gateway
.
setIp
(
host
);
gateway
.
setMacAddress
(
mac
);
serverHandler
.
gatewayService
.
updateIpByMac
(
gateway
);
// 2.开关门信息( 0x54 0x59 0x54 0x01 0x01 0x00 0x01 0x05 0x00 0x01)
// 前6位不用管,第七位是设备编号,第八位是功能码0x05代表开锁,0x06代表关锁,最后两位代表用户ID,1-300
// 3.安防信息,需要根据安防信息做不同的处理,安防信息有 0x60(非法开门警报),0x61(非法尝试开锁警报),0x80(远程开锁触发),0x28(电池低电量警报)
// 1.上报MAC地址信息 6位mac地址+10位的(MAC-UPLOAD)
try
{
int
len
=
SocketUtils
.
bytesToHex
(
result
,
0
,
result
.
length
).
split
(
" "
).
length
;
if
(
len
==
16
){
String
mac
=
SocketUtils
.
bytesToHex
(
result
,
0
,
6
);
Gateway
gateway
=
new
Gateway
();
gateway
.
setIp
(
host
);
gateway
.
setMacAddress
(
mac
);
serverHandler
.
gatewayService
.
updateIpByMac
(
gateway
);
SystemValue
.
ipMacMap
.
put
(
host
,
mac
);
}
else
{
String
title
=
""
;
String
message
=
""
;
String
clientId
=
""
;
List
<
Map
<
String
,
Object
>>
list
=
serverHandler
.
userService
.
queryClientByIp
(
host
);
// 2.开关门信息( 0x54 0x59 0x54 0x01 0x01 0x00 0x01 0x01 0x05 0x00 0x01)
// 前6位不用管,第七位是设备编号,第八位是功能码0x05代表开锁,0x06代表关锁,最后两位代表用户ID,1-300
// 3.安防信息,需要根据安防信息做不同的处理,安防信息有 0x60(非法开门警报),0x61(非法尝试开锁警报),0x80(远程开锁触发),0x28(电池低电量警报)
byte
device
=
result
[
13
];
byte
user
=
0
;
String
device_id
=
String
.
valueOf
(
device
);
byte
instruct
=
0
;
if
(
result
.
length
==
17
){
//开关门信息,6位mac + 11位指令
instruct
=
result
[
14
];
user
=
result
[
16
];
}
else
{
//开关门信息,6位mac + 8位指令
instruct
=
result
[
9
];
}
int
user_id
=
Integer
.
parseInt
(
String
.
valueOf
(
user
));
String
lockType
=
getLockType
(
instruct
);
title
=
getTitle
(
instruct
);
message
=
getMessage
(
instruct
);
LockRecord
lockRecord
=
new
LockRecord
();
lockRecord
.
setTime
(
new
Date
());
lockRecord
.
setUser
(
user_id
);
lockRecord
.
setDeviceId
(
device_id
);
lockRecord
.
setLockType
(
lockType
);
System
.
out
.
println
(
lockType
);
serverHandler
.
lockRecordService
.
insertLockRecord
(
lockRecord
);
if
(
list
!=
null
){
clientId
=
list
.
get
(
0
).
get
(
"client_id"
)!=
null
?
list
.
get
(
0
).
get
(
"client_id"
).
toString
():
""
;
if
(!
""
.
equals
(
clientId
)){
AppPushUtils
.
push
(
title
,
message
,
clientId
);
}
}
else
{
System
.
out
.
println
(
"clientId未获取,消息发送失败"
);
}
}
}
catch
(
Exception
e
){
System
.
out
.
println
(
"数据存储失败"
);
e
.
printStackTrace
();
}
//ctx.write(msg);
...
...
@@ -88,4 +145,54 @@ public class ServerHandler extends ChannelInboundHandlerAdapter {
return
str
;
}
//判断指令是不是mac地址
public
boolean
ifMac
(
byte
[]
b
){
if
(
b
[
6
]
==
0x54
&&
b
[
7
]
==
0x59
&&
b
[
8
]
==
0x54
&&
b
[
9
]
==
0x01
){
return
false
;
}
return
true
;
}
public
String
getLockType
(
byte
b
){
if
(
b
==
0x05
){
return
"开锁"
;}
else
if
(
b
==
0x06
){
return
"关锁"
;}
else
if
(
b
==
0x60
){
return
"非法开门警报"
;}
else
if
(
b
==
0x61
){
return
"非法尝试开锁警报"
;}
else
if
(
b
==
0x80
){
return
"远程开锁触发"
;}
else
if
(
b
==
0x28
){
return
"电池低电量警报"
;}
return
""
;
}
public
String
getTitle
(
byte
b
){
String
title
=
""
;
if
(
b
==
0x05
){
title
=
"开锁"
;}
else
if
(
b
==
0x06
){
title
=
"关锁"
;}
else
if
(
b
==
0x60
){
title
=
"非法开门警报"
;}
else
if
(
b
==
0x61
){
title
=
"非法尝试开锁警报"
;}
else
if
(
b
==
0x80
){
title
=
"远程开锁触发"
;}
else
if
(
b
==
0x28
){
title
=
"电池低电量警报"
;}
return
title
;
}
public
String
getMessage
(
byte
b
){
String
msg
=
""
;
if
(
b
==
0x05
){
msg
=
"开锁"
;}
else
if
(
b
==
0x06
){
msg
=
"关锁"
;}
else
if
(
b
==
0x60
){
msg
=
"非法开门警报"
;}
else
if
(
b
==
0x61
){
msg
=
"非法尝试开锁警报"
;}
else
if
(
b
==
0x80
){
msg
=
"远程开锁触发"
;}
else
if
(
b
==
0x28
){
msg
=
"电池低电量警报"
;}
SimpleDateFormat
simple
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
return
simple
.
format
(
new
Date
())
+
" 触发 "
+
msg
;
}
public
static
int
bytesToInt
(
byte
[]
src
,
int
offset
)
{
int
value
;
value
=
(
int
)
((
src
[
offset
]
&
0xFF
)
|
((
src
[
offset
+
1
]
&
0xFF
)<<
8
)
|
((
src
[
offset
+
2
]
&
0xFF
)<<
16
)
|
((
src
[
offset
+
3
]
&
0xFF
)<<
24
));
return
value
;
}
}
\ No newline at end of file
adc-da-main/src/main/resources/mybatis/mapper/znks/DeviceMapper.xml
View file @
0b088e72
...
...
@@ -42,4 +42,8 @@
</trim>
</insert>
<delete
id=
"deleteDeviceById"
parameterType=
"java.util.Map"
>
delete from tb_device where id = #{id}
</delete>
</mapper>
adc-da-main/src/main/resources/mybatis/mapper/znks/GatewayMapper.xml
View file @
0b088e72
...
...
@@ -44,4 +44,8 @@
update tb_gateway set ip = #{ip} where mac_address = #{macAddress}
</update>
<select
id=
"selectIp"
parameterType =
"java.util.Map"
>
select * from tb_gateway where ip = #{ip}
</select>
</mapper>
adc-da-main/src/main/resources/mybatis/mapper/znks/LockRecordMapper.xml
0 → 100644
View file @
0b088e72
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.adc.da.znks.dao.LockRecordDao"
>
<!-- Result Map-->
<resultMap
id=
"BaseResultMap"
type=
"com.adc.da.znks.entity.Device"
>
<id
column=
"id"
property=
"id"
/>
<result
column=
"name"
property=
"name"
/>
<result
column=
"code"
property=
"code"
/>
<result
column=
"type"
property=
"type"
/>
<result
column=
"user_name"
property=
"userName"
/>
<result
column=
"user_password"
property=
"userPassword"
/>
<result
column=
"uid"
property=
"uid"
/>
</resultMap>
<!-- 查询10天内开锁记录 -->
<select
id=
"selectLockRecord"
resultType=
"java.util.Map"
parameterType=
"java.util.Map"
>
SELECT
loc.*, DATE_FORMAT(loc.time, '%Y-%m-%d') day,
DATE_FORMAT(loc.time,'%Y-%m-%d %h:%i:%s') htime
FROM
tb_lock_record loc,
tb_device dev,
tb_user u
WHERE
u.id = dev.user_id
AND dev.code = loc.device_id
AND u.temphone = #{phone}
AND dev. CODE = #{deviceCode}
AND dev.type = 1
AND DATE_SUB(now(), INTERVAL 10 DAY)
<
= loc.time
order by loc.time desc
</select>
<!-- 动态插入记录 主键是序列 -->
<insert
id=
"insertLockRecord"
parameterType=
"com.adc.da.znks.entity.LockRecord"
>
insert into tb_lock_record(time,user,device_id,lock_type) values(#{time},#{user},#{deviceId},#{lockType})
</insert>
</mapper>
adc-da-main/src/main/resources/mybatis/mapper/znks/UserEOMapper.xml
View file @
0b088e72
...
...
@@ -78,9 +78,6 @@
<update
id=
"updateByPrimaryKeySelective"
parameterType=
"com.adc.da.znks.entity.User"
>
update tb_user
<set>
<if
test=
"temphone != null"
>
temphone = #{temphone},
</if>
<if
test=
"password != null"
>
password = #{password},
</if>
...
...
@@ -88,7 +85,7 @@
encryptkey = #{encryptkey},
</if>
</set>
where
id = #{id
}
where
temphone = #{temphone
}
</update>
<!-- 根据id查询 tb_user -->
...
...
@@ -143,4 +140,9 @@
and ur.temphone = #{phone}
</select>
<select
id=
"queryClientByIp"
resultType=
"java.util.Map"
parameterType=
"java.util.Map"
>
select u.client_id from tb_user u,tb_gateway g where u.id = g.user_id and
g.ip = #{ip}
</select>
</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