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
e79929a9
Commit
e79929a9
authored
Nov 25, 2022
by
马33
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增终端设备模块
parent
74c76e21
Changes
12
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
170 additions
and
11 deletions
+170
-11
TerminalDeviceController.java
.../sixiang/license/controller/TerminalDeviceController.java
+16
-3
Device.java
license/src/main/java/iot/sixiang/license/entity/Device.java
+4
-1
JwtFilter.java
license/src/main/java/iot/sixiang/license/jwt/JwtFilter.java
+9
-2
ReportErrorMsgDTO.java
...java/iot/sixiang/license/model/dto/ReportErrorMsgDTO.java
+16
-0
TerminalDevieBindDTO.java
...a/iot/sixiang/license/model/dto/TerminalDevieBindDTO.java
+14
-0
DeviceService.java
.../main/java/iot/sixiang/license/service/DeviceService.java
+3
-0
PmsUseService.java
.../main/java/iot/sixiang/license/service/PmsUseService.java
+3
-0
TerminalDeviceService.java
...va/iot/sixiang/license/service/TerminalDeviceService.java
+7
-1
DeviceServiceImpl.java
...a/iot/sixiang/license/service/impl/DeviceServiceImpl.java
+24
-0
PmsUseServiceImpl.java
...a/iot/sixiang/license/service/impl/PmsUseServiceImpl.java
+20
-2
TerminalDeviceServiceImpl.java
...xiang/license/service/impl/TerminalDeviceServiceImpl.java
+37
-2
DeviceControllerTest.java
.../iot/sixiang/license/controller/DeviceControllerTest.java
+17
-0
No files found.
license/src/main/java/iot/sixiang/license/controller/TerminalDeviceController.java
View file @
e79929a9
...
...
@@ -2,13 +2,14 @@ package iot.sixiang.license.controller;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
iot.sixiang.license.model.BaseResult
;
import
iot.sixiang.license.model.ResResult
;
import
iot.sixiang.license.model.dto.GetTerminalDeviceTokenDTO
;
import
iot.sixiang.license.model.dto.ReportErrorMsgDTO
;
import
iot.sixiang.license.model.dto.TerminalDevieBindDTO
;
import
iot.sixiang.license.service.TerminalDeviceService
;
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
;
import
org.springframework.web.bind.annotation.*
;
@RestController
@RequestMapping
(
"/iot_license/terminal_device"
)
...
...
@@ -22,4 +23,16 @@ public class TerminalDeviceController {
public
ResResult
getToken
(
GetTerminalDeviceTokenDTO
getTerminalDeviceTokenDTO
)
{
return
terminalDeviceService
.
getToken
(
getTerminalDeviceTokenDTO
);
}
@PostMapping
(
"/report_error_msg"
)
@ApiOperation
(
value
=
"终端设备上报错误信息"
,
notes
=
"终端设备上报错误信息"
)
public
BaseResult
reportErrorMsg
(
@RequestBody
ReportErrorMsgDTO
reportErrorMsgDTO
)
{
return
terminalDeviceService
.
reportErrorMsg
(
reportErrorMsgDTO
);
}
@PostMapping
(
"/bind"
)
@ApiOperation
(
value
=
"终端设备绑定接口"
,
notes
=
"终端设备绑定接口"
)
public
BaseResult
terminalDevieBind
(
@RequestBody
TerminalDevieBindDTO
terminalDevieBindDTO
)
{
return
terminalDeviceService
.
terminalDevieBind
(
terminalDevieBindDTO
);
}
}
license/src/main/java/iot/sixiang/license/entity/Device.java
View file @
e79929a9
...
...
@@ -34,10 +34,13 @@ public class Device implements Serializable {
@ApiModelProperty
(
"设备编号"
)
private
String
sn
;
@ApiModelProperty
(
"绑定的SN"
)
private
String
snBind
;
@ApiModelProperty
(
"应用Id"
)
private
String
appId
;
@ApiModelProperty
(
"
应用Id
"
)
@ApiModelProperty
(
"
状态 0:未使用,1:已使用,2:失效
"
)
private
Integer
status
;
@ApiModelProperty
(
"创建时间"
)
...
...
license/src/main/java/iot/sixiang/license/jwt/JwtFilter.java
View file @
e79929a9
...
...
@@ -27,7 +27,9 @@ public class JwtFilter implements Filter {
private
static
final
String
url7
=
"/swagger-resources"
;
private
static
final
String
url8
=
"/webjars/"
;
private
static
final
String
url9
=
"/log/get"
;
private
static
final
String
url10
=
"/terminal_device/get_token"
;
private
static
final
String
url11
=
"/get_token"
;
private
static
final
String
url12
=
"/report_error_msg"
;
private
static
final
String
url13
=
"/bind"
;
@Override
public
void
init
(
FilterConfig
filterConfig
)
{
...
...
@@ -49,7 +51,7 @@ public class JwtFilter implements Filter {
boolean
check
=
true
;
String
uri
=
request
.
getRequestURI
();
if
(
uri
.
contains
(
url1
)
||
uri
.
contains
(
url2
)
||
uri
.
contains
(
url3
)
||
uri
.
contains
(
url4
)
||
uri
.
contains
(
url7
)
||
uri
.
contains
(
url8
)
||
uri
.
contains
(
url9
)
||
uri
.
contains
(
url1
0
))
{
if
(
uri
.
contains
(
url1
)
||
uri
.
contains
(
url2
)
||
uri
.
contains
(
url3
)
||
uri
.
contains
(
url4
)
||
uri
.
contains
(
url7
)
||
uri
.
contains
(
url8
)
||
uri
.
contains
(
url9
)
||
uri
.
contains
(
url1
1
))
{
if
(
uri
.
contains
(
url1
)
||
uri
.
contains
(
url2
))
{
UserUtils
.
setUri
(
uri
);
}
...
...
@@ -77,6 +79,11 @@ public class JwtFilter implements Filter {
request
.
getRequestDispatcher
(
"/fail"
).
forward
(
request
,
response
);
return
;
}
// 终端设备放行
if
(
uri
.
contains
(
url12
)
||
uri
.
contains
(
url13
))
{
filterChain
.
doFilter
(
request
,
response
);
return
;
}
String
userId
=
userData
.
get
(
"userId"
).
asString
();
String
userName
=
userData
.
get
(
"userName"
).
asString
();
String
password
=
userData
.
get
(
"password"
).
asString
();
...
...
license/src/main/java/iot/sixiang/license/model/dto/ReportErrorMsgDTO.java
0 → 100644
View file @
e79929a9
package
iot
.
sixiang
.
license
.
model
.
dto
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
@Data
public
class
ReportErrorMsgDTO
{
@ApiModelProperty
(
"错误标识id"
)
private
Integer
id
;
@ApiModelProperty
(
"错误码"
)
private
String
errorCode
;
@ApiModelProperty
(
"错误信息"
)
private
String
errorMsg
;
}
license/src/main/java/iot/sixiang/license/model/dto/TerminalDevieBindDTO.java
0 → 100644
View file @
e79929a9
package
iot
.
sixiang
.
license
.
model
.
dto
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
@Data
public
class
TerminalDevieBindDTO
{
@ApiModelProperty
(
"设备编码"
)
private
String
sn
;
@ApiModelProperty
(
"绑定的SN"
)
private
String
snBind
;
}
license/src/main/java/iot/sixiang/license/service/DeviceService.java
View file @
e79929a9
...
...
@@ -3,6 +3,7 @@ package iot.sixiang.license.service;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
iot.sixiang.license.entity.Device
;
import
iot.sixiang.license.model.PageInfoModel
;
import
iot.sixiang.license.model.dto.TerminalDevieBindDTO
;
import
iot.sixiang.license.model.vo.DeviceVo
;
/**
...
...
@@ -15,4 +16,6 @@ public interface DeviceService extends IService<Device> {
PageInfoModel
<
DeviceVo
>
getDeviceList
(
int
pageNo
,
int
pageSize
,
String
appName
,
String
userName
,
Integer
status
);
boolean
addDevice
(
String
appId
,
int
count
);
Boolean
terminalDevieBind
(
TerminalDevieBindDTO
terminalDevieBindDTO
);
}
license/src/main/java/iot/sixiang/license/service/PmsUseService.java
View file @
e79929a9
...
...
@@ -2,6 +2,7 @@ package iot.sixiang.license.service;
import
iot.sixiang.license.entity.PmsUseLog
;
import
iot.sixiang.license.model.PageInfoModel
;
import
iot.sixiang.license.model.dto.ReportErrorMsgDTO
;
/**
* Created by M=54G
...
...
@@ -16,4 +17,6 @@ public interface PmsUseService {
void
success
(
int
useLogId
);
PageInfoModel
<
PmsUseLog
>
getPmsUseLogList
(
int
pageNo
,
int
pageSize
,
String
sn
,
Integer
status
);
boolean
reportErrorMsg
(
ReportErrorMsgDTO
reportErrorMsgDTO
);
}
license/src/main/java/iot/sixiang/license/service/TerminalDeviceService.java
View file @
e79929a9
package
iot
.
sixiang
.
license
.
service
;
import
iot.sixiang.license.model.BaseResult
;
import
iot.sixiang.license.model.ResResult
;
import
iot.sixiang.license.model.dto.GetTerminalDeviceTokenDTO
;
import
iot.sixiang.license.model.vo.GetTerminalDeviceTokenVO
;
import
iot.sixiang.license.model.dto.ReportErrorMsgDTO
;
import
iot.sixiang.license.model.dto.TerminalDevieBindDTO
;
public
interface
TerminalDeviceService
{
ResResult
getToken
(
GetTerminalDeviceTokenDTO
getTerminalDeviceTokenDTO
);
BaseResult
reportErrorMsg
(
ReportErrorMsgDTO
reportErrorMsgDTO
);
BaseResult
terminalDevieBind
(
TerminalDevieBindDTO
terminalDevieBindDTO
);
}
license/src/main/java/iot/sixiang/license/service/impl/DeviceServiceImpl.java
View file @
e79929a9
package
iot
.
sixiang
.
license
.
service
.
impl
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
iot.sixiang.license.consts.ResultCode
;
import
iot.sixiang.license.device.DeviceManager
;
...
...
@@ -7,6 +8,7 @@ import iot.sixiang.license.entity.Device;
import
iot.sixiang.license.handler.IotLicenseException
;
import
iot.sixiang.license.mapper.DeviceMapper
;
import
iot.sixiang.license.model.PageInfoModel
;
import
iot.sixiang.license.model.dto.TerminalDevieBindDTO
;
import
iot.sixiang.license.model.vo.DeviceVo
;
import
iot.sixiang.license.service.DeviceService
;
import
iot.sixiang.license.util.CommonUtil
;
...
...
@@ -17,6 +19,7 @@ import org.springframework.stereotype.Service;
import
javax.annotation.Resource
;
import
java.util.ArrayList
;
import
java.util.Comparator
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.stream.Collectors
;
...
...
@@ -65,4 +68,25 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
deviceManager
.
initDevices
();
return
true
;
}
@Override
public
Boolean
terminalDevieBind
(
TerminalDevieBindDTO
terminalDevieBindDTO
)
{
String
sn
=
terminalDevieBindDTO
.
getSn
();
String
snBind
=
terminalDevieBindDTO
.
getSnBind
();
LambdaQueryWrapper
<
Device
>
queryWrapper
=
new
LambdaQueryWrapper
<>();
queryWrapper
.
eq
(
Device:
:
getSn
,
sn
).
last
(
"limit 1"
);
Device
device
=
deviceMapper
.
selectOne
(
queryWrapper
);
if
(
device
!=
null
)
{
device
.
setSnBind
(
snBind
);
device
.
setStatus
(
1
);
device
.
setUpdateTime
(
new
Date
());
int
res
=
deviceMapper
.
updateById
(
device
);
if
(
res
>=
0
)
{
return
true
;
}
else
{
return
false
;
}
}
return
false
;
}
}
license/src/main/java/iot/sixiang/license/service/impl/PmsUseServiceImpl.java
View file @
e79929a9
...
...
@@ -5,13 +5,12 @@ import iot.sixiang.license.entity.PmsUseLog;
import
iot.sixiang.license.handler.IotLicenseException
;
import
iot.sixiang.license.mapper.PmsUseLogMapper
;
import
iot.sixiang.license.model.PageInfoModel
;
import
iot.sixiang.license.model.
vo.DeviceVo
;
import
iot.sixiang.license.model.
dto.ReportErrorMsgDTO
;
import
iot.sixiang.license.service.PmsUseService
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.util.ArrayList
;
import
java.util.Comparator
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.stream.Collectors
;
...
...
@@ -65,6 +64,25 @@ public class PmsUseServiceImpl implements PmsUseService {
return
pmsUseLogPageInfoModel
;
}
@Override
public
boolean
reportErrorMsg
(
ReportErrorMsgDTO
reportErrorMsgDTO
)
{
Integer
id
=
reportErrorMsgDTO
.
getId
();
String
errorCode
=
reportErrorMsgDTO
.
getErrorCode
();
String
errorMsg
=
reportErrorMsgDTO
.
getErrorMsg
();
PmsUseLog
pmsUseLog
=
new
PmsUseLog
();
pmsUseLog
.
setId
(
id
);
pmsUseLog
.
setStatus
(
0
);
pmsUseLog
.
setErrorCode
(
errorCode
);
pmsUseLog
.
setMessage
(
errorMsg
);
pmsUseLog
.
setUpdateTime
(
new
Date
());
int
res
=
pmsUseLogMapper
.
updateById
(
pmsUseLog
);
if
(
res
>=
0
)
{
return
true
;
}
else
{
return
false
;
}
}
private
PmsUseLog
getPmsUseLog
(
String
sn
)
{
PmsUseLog
pmsUseLog
=
new
PmsUseLog
();
Date
date
=
new
Date
();
...
...
license/src/main/java/iot/sixiang/license/service/impl/TerminalDeviceServiceImpl.java
View file @
e79929a9
package
iot
.
sixiang
.
license
.
service
.
impl
;
import
iot.sixiang.license.auth.AuthManager
;
import
iot.sixiang.license.device.DeviceManager
;
import
iot.sixiang.license.handler.IotLicenseException
;
import
iot.sixiang.license.jwt.JwtUtil
;
import
iot.sixiang.license.jwt.LoginUser
;
import
iot.sixiang.license.model.BaseResult
;
import
iot.sixiang.license.model.ResResult
;
import
iot.sixiang.license.model.dto.GetTerminalDeviceTokenDTO
;
import
iot.sixiang.license.model.dto.ReportErrorMsgDTO
;
import
iot.sixiang.license.model.dto.TerminalDevieBindDTO
;
import
iot.sixiang.license.service.DeviceService
;
import
iot.sixiang.license.service.PmsUseService
;
import
iot.sixiang.license.service.TerminalDeviceService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
...
...
@@ -19,7 +23,9 @@ public class TerminalDeviceServiceImpl implements TerminalDeviceService {
@Autowired
private
AuthManager
authManager
;
@Autowired
private
DeviceManager
deviceManager
;
private
DeviceService
deviceService
;
@Autowired
private
PmsUseService
pmsUseService
;
@Override
public
ResResult
getToken
(
GetTerminalDeviceTokenDTO
getTerminalDeviceTokenDTO
)
{
...
...
@@ -46,4 +52,33 @@ public class TerminalDeviceServiceImpl implements TerminalDeviceService {
return
ResResult
.
validate_failed
();
}
}
@Override
public
BaseResult
reportErrorMsg
(
ReportErrorMsgDTO
reportErrorMsgDTO
)
{
Integer
id
=
reportErrorMsgDTO
.
getId
();
if
(
id
==
null
||
id
==
0
)
{
return
BaseResult
.
validate_failed
();
}
boolean
res
=
pmsUseService
.
reportErrorMsg
(
reportErrorMsgDTO
);
if
(
res
)
{
return
BaseResult
.
success
();
}
else
{
return
BaseResult
.
failed
();
}
}
@Override
public
BaseResult
terminalDevieBind
(
TerminalDevieBindDTO
terminalDevieBindDTO
)
{
String
sn
=
terminalDevieBindDTO
.
getSn
();
String
snBind
=
terminalDevieBindDTO
.
getSnBind
();
if
(
StringUtils
.
isEmpty
(
sn
)
||
StringUtils
.
isEmpty
(
snBind
))
{
return
BaseResult
.
validate_failed
();
}
Boolean
res
=
deviceService
.
terminalDevieBind
(
terminalDevieBindDTO
);
if
(
res
)
{
return
BaseResult
.
success
();
}
else
{
return
BaseResult
.
failed
();
}
}
}
license/src/test/java/iot/sixiang/license/controller/DeviceControllerTest.java
View file @
e79929a9
...
...
@@ -22,6 +22,23 @@ import java.util.Random;
*/
public
class
DeviceControllerTest
{
@Test
void
terminalDeviceSign
()
{
String
appId
=
"7j26zr7en9fiyoyvjz"
;
String
sn
=
"8HOE8JH4EFSEV28534"
;
// String snBind = "snabcd";
String
appKey
=
"2"
;
String
string
=
"app_id="
+
appId
+
"&sn="
+
sn
;
String
sign
=
HmacUtil
.
encrypt
(
string
,
appKey
,
HmacUtil
.
HMAC_SHA1
);
System
.
out
.
println
(
"token appId:"
+
appId
);
System
.
out
.
println
(
"token sn:"
+
sn
);
System
.
out
.
println
(
"token sign:"
+
sign
);
}
@Test
void
tokenSign
()
{
String
appId
=
"ebsh71dp5t1ck948l5"
;
...
...
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