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
77292d07
Commit
77292d07
authored
Jun 15, 2022
by
zengtianlai3
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'm33' into 'master'
添加设备黑名单功能 See merge request
!30
parents
e777f499
d712f93f
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
279 additions
and
2 deletions
+279
-2
AuthManager.java
...e/src/main/java/iot/sixiang/license/auth/AuthManager.java
+28
-1
DeviceController.java
...java/iot/sixiang/license/controller/DeviceController.java
+72
-0
DeviceManager.java
...c/main/java/iot/sixiang/license/device/DeviceManager.java
+4
-0
DeviceBlack.java
...src/main/java/iot/sixiang/license/entity/DeviceBlack.java
+31
-0
DeviceBlackMapper.java
...in/java/iot/sixiang/license/mapper/DeviceBlackMapper.java
+23
-0
DeviceVo.java
.../src/main/java/iot/sixiang/license/model/vo/DeviceVo.java
+3
-0
DeviceBlackService.java
.../java/iot/sixiang/license/service/DeviceBlackService.java
+22
-0
DeviceBlackServiceImpl.java
.../sixiang/license/service/impl/DeviceBlackServiceImpl.java
+79
-0
DeviceBlackMapper.xml
license/src/main/resources/mapper/DeviceBlackMapper.xml
+16
-0
DeviceMapper.xml
license/src/main/resources/mapper/DeviceMapper.xml
+1
-1
No files found.
license/src/main/java/iot/sixiang/license/auth/AuthManager.java
View file @
77292d07
...
...
@@ -2,9 +2,12 @@ package iot.sixiang.license.auth;
import
iot.sixiang.license.device.DeviceManager
;
import
iot.sixiang.license.entity.Apply
;
import
iot.sixiang.license.entity.DeviceBlack
;
import
iot.sixiang.license.model.PageInfoModel
;
import
iot.sixiang.license.model.vo.AppVo
;
import
iot.sixiang.license.model.vo.DeviceVo
;
import
iot.sixiang.license.service.ApplyService
;
import
iot.sixiang.license.service.DeviceBlackService
;
import
iot.sixiang.license.util.HmacUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -22,16 +25,22 @@ public class AuthManager {
private
ApplyService
applyService
;
@Autowired
private
DeviceManager
deviceManager
;
@Autowired
private
DeviceBlackService
deviceBlackService
;
private
Map
<
String
,
Apply
>
allApply
=
null
;
private
Map
<
String
,
DeviceBlack
>
deviceBlackMap
=
null
;
public
AuthManager
()
{
allApply
=
new
HashMap
<>();
deviceBlackMap
=
new
HashMap
<>();
}
@PostConstruct
public
void
init
()
{
initApps
();
initDeviceBlacks
();
}
public
void
initApps
()
{
...
...
@@ -44,6 +53,15 @@ public class AuthManager {
}
}
public
void
initDeviceBlacks
()
{
deviceBlackMap
=
new
HashMap
<>();
PageInfoModel
<
DeviceBlack
>
records
=
deviceBlackService
.
getDeviceBlackList
(
1
,
10000
);
List
<
DeviceBlack
>
deviceBlackList
=
records
.
getResult
();
for
(
DeviceBlack
deviceBlack
:
deviceBlackList
)
{
String
deviceId
=
deviceBlack
.
getDeviceId
().
toString
();
deviceBlackMap
.
put
(
deviceId
,
deviceBlack
);
}
}
public
boolean
auth
(
String
appId
,
String
sn
,
String
sign
)
{
...
...
@@ -54,7 +72,11 @@ public class AuthManager {
if
(!
deviceManager
.
getContainSn
(
sn
))
{
return
false
;
}
DeviceVo
device
=
deviceManager
.
getDevice
(
sn
);
int
deviceId
=
device
.
getDeviceId
();
if
(
deviceBlackMap
.
containsKey
(
deviceId
)){
return
false
;
}
Apply
apply
=
allApply
.
get
(
appId
);
String
appKey
=
apply
.
getAppKey
();
String
input
=
"app_id="
+
appId
+
"&sn="
+
sn
;
...
...
@@ -65,4 +87,9 @@ public class AuthManager {
return
false
;
}
}
public
synchronized
Map
<
String
,
DeviceBlack
>
getDeviceBlack
()
{
return
deviceBlackMap
;
}
}
license/src/main/java/iot/sixiang/license/controller/DeviceController.java
View file @
77292d07
...
...
@@ -7,6 +7,7 @@ import com.github.xiaoymin.knife4j.annotations.DynamicParameter;
import
com.github.xiaoymin.knife4j.annotations.DynamicParameters
;
import
io.swagger.annotations.*
;
import
iot.sixiang.license.device.DeviceManager
;
import
iot.sixiang.license.entity.DeviceBlack
;
import
iot.sixiang.license.log.BusinessType
;
import
iot.sixiang.license.log.MyLog
;
import
iot.sixiang.license.model.BaseResult
;
...
...
@@ -14,6 +15,7 @@ import iot.sixiang.license.model.PageInfoModel;
import
iot.sixiang.license.model.PageResult
;
import
iot.sixiang.license.model.vo.DeviceDetailVo
;
import
iot.sixiang.license.model.vo.DeviceVo
;
import
iot.sixiang.license.service.DeviceBlackService
;
import
iot.sixiang.license.service.DeviceService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -38,6 +40,9 @@ public class DeviceController {
@Autowired
private
DeviceManager
deviceManager
;
@Autowired
private
DeviceBlackService
deviceBlackService
;
/**
* 添加device
* @param jsonObject
...
...
@@ -117,5 +122,72 @@ public class DeviceController {
List
<
DeviceDetailVo
>
pageResult
=
records
.
getResult
();
return
new
PageResult
(
200
,
"查找成功"
,
pageNo
,
pages
,
total
,
pageResult
);
}
/**
* 添加device_black
* @param jsonObject
* @return
*/
@ApiOperation
(
value
=
"添加设备黑名单接口"
,
notes
=
"用于添加设备黑名单"
)
@PostMapping
(
"device_black/add"
)
@ApiOperationSupport
(
params
=
@DynamicParameters
(
name
=
"jsonObject"
,
properties
=
{
@DynamicParameter
(
name
=
"deviceId"
,
value
=
"设备Id"
,
required
=
true
,
dataTypeClass
=
Integer
.
class
)
}))
@MyLog
(
title
=
"添加设备黑名单"
,
optParam
=
"#{jsonObject}"
,
businessType
=
BusinessType
.
INSERT
)
public
BaseResult
addDeviceBlack
(
@RequestBody
JSONObject
jsonObject
)
{
int
deviceId
=
jsonObject
.
getIntValue
(
"deviceId"
);
boolean
res
=
deviceBlackService
.
addDeviceBlack
(
deviceId
);
if
(
res
)
{
return
BaseResult
.
success
();
}
else
{
return
BaseResult
.
failed
();
}
}
/**
* 删除device_black
* @param jsonObject
* @return
*/
@ApiOperation
(
value
=
"设备黑名单删除接口"
,
notes
=
"删除设备黑名单"
)
@PostMapping
(
"device_black/delete"
)
@ApiOperationSupport
(
params
=
@DynamicParameters
(
name
=
"jsonObject"
,
properties
=
{
@DynamicParameter
(
name
=
"deviceId"
,
value
=
"设备Id"
,
required
=
true
,
dataTypeClass
=
Integer
.
class
)
}))
@MyLog
(
title
=
"删除设备黑名单"
,
optParam
=
"#{deviceId}"
,
businessType
=
BusinessType
.
DELETE
)
public
BaseResult
deleteDeviceBlack
(
@RequestBody
JSONObject
jsonObject
)
{
int
deviceId
=
jsonObject
.
getIntValue
(
"deviceId"
);
boolean
res
=
deviceBlackService
.
deleteDeviceBlack
(
deviceId
);
if
(
res
)
{
return
BaseResult
.
success
();
}
else
{
return
BaseResult
.
failed
();
}
}
/**
* 分页查询所有黑名单设备
* @param pageNo
* @param pageSize
* @return
*/
@ApiOperation
(
value
=
"获取设备黑名单列表接口"
,
notes
=
"用于获取设备黑名单列表"
)
@GetMapping
(
"device_black/list"
)
@MyLog
(
title
=
"获取设备黑名单列表"
,
optParam
=
"#{pageNo},#{pageSize}"
,
businessType
=
BusinessType
.
SELECT
)
@ApiImplicitParams
({
@ApiImplicitParam
(
name
=
"pageNo"
,
value
=
"当前在第几页"
,
required
=
true
,
dataType
=
"int"
),
@ApiImplicitParam
(
name
=
"pageSize"
,
value
=
"每页显示多少页"
,
required
=
true
,
dataType
=
"int"
)
})
public
PageResult
<
DeviceBlack
>
getDeviceBlackList
(
@RequestParam
(
value
=
"pageNo"
,
defaultValue
=
"0"
)
int
pageNo
,
@RequestParam
(
value
=
"pageSize"
,
defaultValue
=
"0"
)
int
pageSize
){
PageInfoModel
<
DeviceBlack
>
records
=
deviceBlackService
.
getDeviceBlackList
(
pageNo
,
pageSize
);
int
total
=
records
.
getTotal
();
int
pages
=
total
/
pageSize
;
//pages为总页数
int
mod
=
total
%
pageSize
;
if
(
mod
!=
0
){
pages
=
pages
+
1
;
}
List
<
DeviceBlack
>
pageResult
=
records
.
getResult
();
return
new
PageResult
(
200
,
"查找成功"
,
pageNo
,
pages
,
total
,
pageResult
);
}
}
license/src/main/java/iot/sixiang/license/device/DeviceManager.java
View file @
77292d07
...
...
@@ -178,4 +178,8 @@ public class DeviceManager {
return
detailVoPageInfoModel
;
}
public
DeviceVo
getDevice
(
String
sn
)
{
DeviceVo
deviceVo
=
allDevice
.
get
(
sn
);
return
deviceVo
;
}
}
license/src/main/java/iot/sixiang/license/entity/DeviceBlack.java
0 → 100644
View file @
77292d07
package
iot
.
sixiang
.
license
.
entity
;
import
com.baomidou.mybatisplus.annotation.IdType
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
java.io.Serializable
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
import
lombok.experimental.Accessors
;
/**
* <p>
*
* </p>
*
* @author m33
* @since 2022-06-15
*/
@Data
@EqualsAndHashCode
(
callSuper
=
false
)
@Accessors
(
chain
=
true
)
public
class
DeviceBlack
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
@TableId
(
value
=
"id"
,
type
=
IdType
.
AUTO
)
private
Integer
id
;
private
Integer
deviceId
;
}
license/src/main/java/iot/sixiang/license/mapper/DeviceBlackMapper.java
0 → 100644
View file @
77292d07
package
iot
.
sixiang
.
license
.
mapper
;
import
iot.sixiang.license.entity.DeviceBlack
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
java.util.List
;
/**
* <p>
* Mapper 接口
* </p>
*
* @author m33
* @since 2022-06-15
*/
public
interface
DeviceBlackMapper
extends
BaseMapper
<
DeviceBlack
>
{
boolean
addDeviceBlack
(
int
deviceId
);
boolean
deleteDeviceBlack
(
int
deviceId
);
List
<
DeviceBlack
>
getDeviceBlackList
();
}
license/src/main/java/iot/sixiang/license/model/vo/DeviceVo.java
View file @
77292d07
...
...
@@ -25,4 +25,7 @@ public class DeviceVo implements Serializable {
@ApiModelProperty
(
"设备编号"
)
private
String
sn
;
@ApiModelProperty
(
"设备状态 0:正常 1:禁用"
)
private
int
blackFlag
;
}
license/src/main/java/iot/sixiang/license/service/DeviceBlackService.java
0 → 100644
View file @
77292d07
package
iot
.
sixiang
.
license
.
service
;
import
iot.sixiang.license.entity.DeviceBlack
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
iot.sixiang.license.model.PageInfoModel
;
/**
* <p>
* 服务类
* </p>
*
* @author m33
* @since 2022-06-15
*/
public
interface
DeviceBlackService
extends
IService
<
DeviceBlack
>
{
boolean
addDeviceBlack
(
int
deviceId
);
boolean
deleteDeviceBlack
(
int
deviceId
);
PageInfoModel
<
DeviceBlack
>
getDeviceBlackList
(
int
pageNo
,
int
pageSize
);
}
license/src/main/java/iot/sixiang/license/service/impl/DeviceBlackServiceImpl.java
0 → 100644
View file @
77292d07
package
iot
.
sixiang
.
license
.
service
.
impl
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
iot.sixiang.license.auth.AuthManager
;
import
iot.sixiang.license.consts.ResultCode
;
import
iot.sixiang.license.entity.DeviceBlack
;
import
iot.sixiang.license.handler.IotLicenseException
;
import
iot.sixiang.license.mapper.DeviceBlackMapper
;
import
iot.sixiang.license.model.PageInfoModel
;
import
iot.sixiang.license.service.DeviceBlackService
;
import
iot.sixiang.license.util.SpringUtil
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.util.ArrayList
;
import
java.util.Comparator
;
import
java.util.List
;
import
java.util.stream.Collectors
;
/**
* <p>
* 服务实现类
* </p>
*
* @author m33
* @since 2022-06-15
*/
@Service
public
class
DeviceBlackServiceImpl
extends
ServiceImpl
<
DeviceBlackMapper
,
DeviceBlack
>
implements
DeviceBlackService
{
@Resource
private
DeviceBlackMapper
deviceBlackMapper
;
@Override
public
boolean
addDeviceBlack
(
int
deviceId
)
{
if
(
deviceId
==
0
)
{
throw
new
IotLicenseException
(
ResultCode
.
VALIDATE_FAILED
.
getCode
(),
ResultCode
.
VALIDATE_FAILED
.
getMsg
());
}
AuthManager
authManager
=
SpringUtil
.
getBean
(
AuthManager
.
class
);
if
(
authManager
.
getDeviceBlack
().
containsKey
(
deviceId
))
{
throw
new
IotLicenseException
(
ResultCode
.
FAILED
.
getCode
(),
ResultCode
.
FAILED
.
getMsg
());
}
boolean
res
=
deviceBlackMapper
.
addDeviceBlack
(
deviceId
);
if
(
res
)
{
authManager
.
initDeviceBlacks
();
return
true
;
}
return
false
;
}
@Override
public
boolean
deleteDeviceBlack
(
int
deviceId
)
{
boolean
res
=
deviceBlackMapper
.
deleteDeviceBlack
(
deviceId
);
if
(
res
)
{
AuthManager
authManager
=
SpringUtil
.
getBean
(
AuthManager
.
class
);
authManager
.
initDeviceBlacks
();
return
true
;
}
return
false
;
}
@Override
public
PageInfoModel
<
DeviceBlack
>
getDeviceBlackList
(
int
pageNo
,
int
pageSize
)
{
if
(
pageNo
==
0
||
pageSize
==
0
)
{
throw
new
IotLicenseException
(
ResultCode
.
VALIDATE_FAILED
.
getCode
(),
ResultCode
.
VALIDATE_FAILED
.
getMsg
());
}
List
<
DeviceBlack
>
records
=
deviceBlackMapper
.
getDeviceBlackList
();
records
=
records
.
stream
().
sorted
(
Comparator
.
comparing
(
DeviceBlack:
:
getId
)).
collect
(
Collectors
.
toList
());
List
<
DeviceBlack
>
result
=
new
ArrayList
<>();
int
begin
=
(
pageNo
-
1
)
*
pageSize
;
if
(
begin
>=
0
&&
records
.
size
()
>
0
)
{
result
=
records
.
stream
().
skip
(
begin
).
limit
(
pageSize
).
collect
(
Collectors
.
toList
());
}
PageInfoModel
<
DeviceBlack
>
objectPageInfoModel
=
new
PageInfoModel
<>();
objectPageInfoModel
.
setTotal
(
records
.
size
());
objectPageInfoModel
.
setResult
(
result
);
return
objectPageInfoModel
;
}
}
license/src/main/resources/mapper/DeviceBlackMapper.xml
0 → 100644
View file @
77292d07
<?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=
"iot.sixiang.license.mapper.DeviceBlackMapper"
>
<insert
id=
"addDeviceBlack"
parameterType=
"iot.sixiang.license.entity.DeviceBlack"
>
insert into device_black(device_id) values (#{deviceId})
</insert>
<delete
id=
"deleteDeviceBlack"
parameterType=
"iot.sixiang.license.entity.DeviceBlack"
>
delete from device_black where device_id = #{deviceId}
</delete>
<select
id=
"getDeviceBlackList"
resultType=
"iot.sixiang.license.entity.DeviceBlack"
>
select id, device_id from device_black
</select>
</mapper>
license/src/main/resources/mapper/DeviceMapper.xml
View file @
77292d07
...
...
@@ -3,7 +3,7 @@
<mapper
namespace=
"iot.sixiang.license.mapper.DeviceMapper"
>
<select
id=
"getDeviceList"
resultType=
"iot.sixiang.license.model.vo.DeviceVo"
>
SELECT de.device_id,app_name,user_name,sn FROM device AS de
SELECT de.device_id,app_name,user_name,sn
,de.device_id IN (select device_id from device_black) AS blackFlag
FROM device AS de
JOIN apply AS app ON de.app_id = app.app_id
JOIN USER AS us ON us.user_id = app.user_id
where 1=1
...
...
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