Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
黄嘉阳
/
iot-platform-server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
19570feb
authored
Dec 21, 2023
by
huangjy
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merge remote-tracking branch 'origin/dev' into dev
parents
bf80128e
23633e85
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
12 deletions
server-common/src/main/java/com/makeit/utils/redis/RedisUtil.java
server-service/src/main/java/com/makeit/utils/DeviceCacheUtil.java
server-web/src/main/java/com/makeit/mqtt/PushCallback.java
server-web/src/test/java/com/makeit/iotapi/IotDeviceInfoContentFall.java
server-common/src/main/java/com/makeit/utils/redis/RedisUtil.java
View file @
19570feb
package
com
.
makeit
.
utils
.
redis
;
import
cn.hutool.core.collection.CollUtil
;
import
com.makeit.utils.ThreadUtil
;
import
com.makeit.utils.data.convert.JsonUtil
;
import
com.makeit.utils.old.StringUtils
;
...
...
@@ -193,6 +194,21 @@ public class RedisUtil {
return
bucket
.
get
();
}
/**
* 获取字符串
*/
public
static
<
T
>
List
<
T
>
getLike
(
String
key
)
{
RKeys
keys
=
client
.
getKeys
();
Iterable
<
String
>
keyList
=
keys
.
getKeysByPattern
(
getProjectName
()
+
key
+
"*"
);
RBatch
rBatch
=
client
.
createBatch
();
if
(
CollUtil
.
isNotEmpty
(
keyList
)){
keyList
.
forEach
(
k
->
rBatch
.
getBucket
(
k
).
getAsync
());
}
List
<?>
dbList
=
rBatch
.
execute
().
getResponses
();
return
dbList
.
stream
().
map
(
e
->
(
T
)
e
).
collect
(
Collectors
.
toList
());
}
public
static
<
T
>
List
<
T
>
get
(
List
<
String
>
key
)
{
RBatch
rBatch
=
client
.
createBatch
();
...
...
server-service/src/main/java/com/makeit/utils/DeviceCacheUtil.java
View file @
19570feb
package
com
.
makeit
.
utils
;
import
cn.hutool.core.collection.CollUtil
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.makeit.entity.platform.device.PlatDevice
;
import
com.makeit.entity.saas.PlatTenant
;
...
...
@@ -57,6 +58,15 @@ public class DeviceCacheUtil implements ApplicationRunner {
}
return
RedisUtil
.
get
(
RedisConst
.
PLAT_IOT_DEVICE_PREFIX
+
oriDeviceIdAndIotOrgId
);
}
public
List
<
PlatDevice
>
getByDeviceId
(
String
oriDeviceId
)
{
List
<
PlatDevice
>
platDevice
=
RedisUtil
.
getLike
(
RedisConst
.
PLAT_IOT_DEVICE_PREFIX
+
oriDeviceId
);
if
(
CollUtil
.
isEmpty
(
platDevice
))
{
getAll
();
}
return
RedisUtil
.
getLike
(
RedisConst
.
PLAT_IOT_DEVICE_PREFIX
+
oriDeviceId
);
}
public
void
putAll
(
Collection
<
PlatDevice
>
platDeviceList
)
{
platDeviceList
.
forEach
(
vo
->
{
put
(
vo
);
...
...
server-web/src/main/java/com/makeit/mqtt/PushCallback.java
View file @
19570feb
...
...
@@ -12,10 +12,10 @@ import com.makeit.entity.platform.alarm.PlatAlarmConfig;
import
com.makeit.entity.platform.device.PlatDevice
;
import
com.makeit.entity.saas.PlatTenant
;
import
com.makeit.entity.saas.analysis.SaasSleepAnalysisModel
;
import
com.makeit.external.strategy.OpenApiBaseStrategy
;
import
com.makeit.external.strategy.OpenApiBaseStrategyFactory
;
import
com.makeit.enums.platform.alarm.PlatAlarmConfigEnum
;
import
com.makeit.enums.redis.RedisConst
;
import
com.makeit.external.strategy.OpenApiBaseStrategy
;
import
com.makeit.external.strategy.OpenApiBaseStrategyFactory
;
import
com.makeit.global.aspect.tenant.TenantIdIgnore
;
import
com.makeit.module.iot.enums.DeviceState
;
import
com.makeit.module.iot.vo.DeviceInfo
;
...
...
@@ -27,7 +27,6 @@ import com.makeit.service.saas.PlatTenantService;
import
com.makeit.service.saas.SaasSleepAnalysisModelService
;
import
com.makeit.utils.AlarmConfigCacheUtil
;
import
com.makeit.utils.DeviceCacheUtil
;
import
com.makeit.utils.data.convert.StreamUtil
;
import
com.makeit.utils.redis.RedisUtil
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.eclipse.paho.client.mqttv3.IMqttDeliveryToken
;
...
...
@@ -44,11 +43,9 @@ import org.springframework.stereotype.Component;
import
javax.annotation.Resource
;
import
java.math.BigDecimal
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Objects
;
import
java.util.concurrent.CompletableFuture
;
import
java.util.concurrent.TimeUnit
;
import
java.util.stream.Collectors
;
@Component
...
...
@@ -261,26 +258,24 @@ public class PushCallback implements MqttCallback {
* @param messageType
*/
private
void
handleOffBed
(
PlatDevice
platDevice
,
JSONObject
properties
,
String
messageType
)
{
List
<
PlatDevice
>
platDeviceList
=
platDeviceService
.
listOffBed
(
platDevice
.
getOriDeviceId
());
List
<
PlatDevice
>
platDeviceList
=
deviceCacheUtil
.
getByDeviceId
(
platDevice
.
getOriDeviceId
());
if
(
CollUtil
.
isEmpty
(
platDeviceList
))
{
return
;
}
List
<
String
>
orgIds
=
platDeviceList
.
stream
().
map
(
PlatDevice:
:
getOrgId
).
collect
(
Collectors
.
toList
());
List
<
PlatAlarmConfig
>
configList
=
alarmConfigService
.
listOfBed
(
orgIds
);
Map
<
String
,
PlatAlarmConfig
>
configMap
=
StreamUtil
.
toMap
(
configList
,
PlatAlarmConfig:
:
getOrgId
);
String
alarmType
=
PlatAlarmConfigEnum
.
AlarmTypeEnum
.
OFF_BED
.
getValue
();
List
<
String
>
type
=
Lists
.
newArrayList
(
"OFFLINE"
,
"DISCONNECT"
);
platDeviceList
.
forEach
(
device
->
{
if
(
StrUtil
.
isBlank
(
messageType
)
||
type
.
contains
(
messageType
)
||
DeviceState
.
offline
.
getValue
().
equals
(
device
.
getStatus
()))
{
logger
.
info
(
"离线清除离床预警缓存!"
);
logger
.
warn
(
"离线清除离床预警缓存!"
);
RedisUtil
.
delete
(
RedisConst
.
ALARM_DEVICE_OFF_BED_ID
+
device
.
getId
());
}
for
(
IAlarm
alarm
:
alarmList
)
{
if
(
alarm
.
support
(
alarmType
))
{
PlatAlarmConfig
config
=
configMap
.
get
(
device
.
getOrgId
()
);
PlatAlarmConfig
config
=
alarmConfigCacheUtil
.
get
(
device
.
getOrgId
(),
alarmType
);
if
(
config
==
null
)
{
logger
.
info
(
"handleOffBed 未找到对应的config"
);
continue
;
}
//防止呼吸心率的数据交叉
...
...
server-web/src/test/java/com/makeit/iotapi/IotDeviceInfoContentFall.java
View file @
19570feb
...
...
@@ -9,10 +9,13 @@ import com.makeit.module.iot.service.IotOrgService;
import
com.makeit.module.iot.service.IotProductDeviceService
;
import
com.makeit.module.iot.service.IotTokenService
;
import
com.makeit.service.platform.alarm.alarmStrategy.OffBedAlarm
;
import
com.makeit.utils.redis.RedisUtil
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
java.util.List
;
@SpringBootTest
public
class
IotDeviceInfoContentFall
{
...
...
@@ -103,4 +106,12 @@ public class IotDeviceInfoContentFall {
}
@Test
void
getRedis
()
{
// iot-plafform:plat:iot:device:1712376790484275200:1701420402262994944
// iot-plafform:plat:iot:device:1712377046877884416:1703950733042053120
List
<
PlatDevice
>
list
=
RedisUtil
.
getLike
(
"plat:iot:device:"
+
"1712377046877884416"
);
System
.
out
.
println
(
list
);
}
}
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