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
7c9b43e5
authored
Sep 12, 2023
by
李小龙
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
整理代码
parent
90a5d123
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
30 deletions
server-service/src/main/java/com/makeit/service/platform/alarm/alarmStrategy/AlarmStrategy.java
server-service/src/main/java/com/makeit/service/platform/auth/impl/PlatUserServiceImpl.java
server-web/src/main/java/com/makeit/mqtt/PushCallback.java
server-service/src/main/java/com/makeit/service/platform/alarm/alarmStrategy/AlarmStrategy.java
0 → 100644
View file @
7c9b43e5
package
com
.
makeit
.
service
.
platform
.
alarm
.
alarmStrategy
;
public
interface
AlarmStrategy
{
}
server-service/src/main/java/com/makeit/service/platform/auth/impl/PlatUserServiceImpl.java
View file @
7c9b43e5
...
...
@@ -756,7 +756,7 @@ public class PlatUserServiceImpl extends ServiceImpl<PlatUserMapper, PlatUser>
private
void
setRoleList
(
PlatPersonDTOVO
dto
)
{
platUserRoleService
.
remove
(
new
QueryWrapper
<
PlatUserRole
>().
lambda
()
.
eq
(
PlatUserRole:
:
getUserId
,
dto
.
getId
()));
if
(
dto
.
getRoleList
()
!=
null
)
{
if
(
dto
.
getRole
Id
List
()
!=
null
)
{
List
<
PlatUserRole
>
userRoleList
=
StreamUtil
.
map
(
dto
.
getRoleIdList
(),
e
->
{
PlatUserRole
tntUserRole
=
new
PlatUserRole
();
tntUserRole
.
setUserId
(
dto
.
getId
());
...
...
server-web/src/main/java/com/makeit/mqtt/PushCallback.java
View file @
7c9b43e5
...
...
@@ -32,8 +32,6 @@ import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import
org.eclipse.paho.client.mqttv3.MqttCallback
;
import
org.eclipse.paho.client.mqttv3.MqttClient
;
import
org.eclipse.paho.client.mqttv3.MqttMessage
;
import
org.redisson.api.RAtomicLong
;
import
org.redisson.api.RedissonClient
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -108,7 +106,7 @@ public class PushCallback implements MqttCallback {
if
(
CollectionUtils
.
isEmpty
(
deviceAlarmConfigList
))
{
return
;
}
RedissonClient
redissonClient
=
RedisUtil
.
getClient
();
//
RedissonClient redissonClient = RedisUtil.getClient();
for
(
PlatAlarmConfig
config
:
deviceAlarmConfigList
)
{
String
alarmType
=
config
.
getAlarmType
();
String
ruleConfigStr
=
config
.
getRuleConfig
();
...
...
@@ -132,24 +130,21 @@ public class PushCallback implements MqttCallback {
Integer
start
=
ruleConfig
.
getRespiratoryRateStart
();
Integer
end
=
ruleConfig
.
getRespiratoryRateEnd
();
Integer
duration
=
ruleConfig
.
getDuration
();
long
endLong
=
new
Date
().
getTime
();
//计数
RAtomicLong
atomicLong
=
redissonClient
.
getAtomicLong
(
RedisConst
.
ALARM_DEVICE_ID
+
deviceId
);
if
(!
atomicLong
.
isExists
())
{
atomicLong
.
set
(
0
);
}
if
(
StringUtils
.
equals
(
personState
,
"0"
))
{
atomicLong
.
set
(
0
);
Long
startLong
=
RedisUtil
.
get
(
RedisConst
.
ALARM_DEVICE_ID
+
deviceId
);
if
(
StringUtils
.
equals
(
personState
,
"0"
)||
startLong
==
null
)
{
RedisUtil
.
set
(
RedisConst
.
ALARM_DEVICE_ID
+
deviceId
,
endLong
/
1000
);
continue
;
}
long
count
=
endLong
-
startLong
;
if
(
br
>
end
||
br
<
start
)
{
long
count
=
atomicLong
.
incrementAndGet
();
if
(
count
>=
duration
)
{
PlatAlarmRecord
platAlarmRecord
=
createRespiratoryPlatAlarmRecord
(
platDevice
,
config
);
atomicLong
.
set
(
0
);
RedisUtil
.
set
(
RedisConst
.
ALARM_DEVICE_ID
+
deviceId
,
endLong
/
100
0
);
}
}
else
{
atomicLong
.
set
(
0
);
RedisUtil
.
set
(
RedisConst
.
ALARM_DEVICE_ID
+
deviceId
,
endLong
/
100
0
);
}
}
//心率
...
...
@@ -161,24 +156,23 @@ public class PushCallback implements MqttCallback {
Integer
start
=
ruleConfig
.
getHeartRateStart
();
Integer
end
=
ruleConfig
.
getHeartRateEnd
();
Integer
duration
=
ruleConfig
.
getDuration
();
RAtomicLong
atomicLong
=
redissonClient
.
getAtomicLong
(
RedisConst
.
ALARM_DEVICE_ID
+
deviceId
);
if
(!
atomicLong
.
isExists
())
{
atomicLong
.
set
(
0
);
}
if
(
StringUtils
.
equals
(
personState
,
"0"
))
{
atomicLong
.
set
(
0
);
long
endLong
=
new
Date
().
getTime
();
//计数
Long
startLong
=
RedisUtil
.
get
(
RedisConst
.
ALARM_DEVICE_ID
+
deviceId
);
if
(
StringUtils
.
equals
(
personState
,
"0"
)||
startLong
==
null
)
{
RedisUtil
.
set
(
RedisConst
.
ALARM_DEVICE_ID
+
deviceId
,
endLong
/
1000
);
continue
;
}
long
count
=
endLong
-
startLong
;
if
(
hr
>
end
||
hr
<
start
)
{
long
count
=
atomicLong
.
incrementAndGet
();
if
(
count
>=
duration
)
{
PlatAlarmRecord
platAlarmRecord
=
createHeartPlatAlarmRecord
(
platDevice
,
config
);
RedisUtil
.
set
(
RedisConst
.
ALARM_DEVICE_ID
+
deviceId
,
endLong
/
1000
);
}
}
else
{
atomicLong
.
set
(
0
);
RedisUtil
.
set
(
RedisConst
.
ALARM_DEVICE_ID
+
deviceId
,
endLong
/
100
0
);
}
}
RAtomicLong
atomicLong
=
redissonClient
.
getAtomicLong
(
RedisConst
.
ALARM_DEVICE_ID
+
deviceId
);
//行为
if
(
StringUtils
.
equals
(
alarmType
,
PlatAlarmConfigEnum
.
AlarmTypeEnum
.
BEHAVIOR
.
getValue
()))
{
String
personState
=
(
String
)
properties
.
get
(
"personState"
);
...
...
@@ -189,18 +183,21 @@ public class PushCallback implements MqttCallback {
List
<
String
>
personStateList
=
Arrays
.
asList
(
"1"
,
"2"
,
"3"
);
//有人
//计数
if
(!
atomicLong
.
isExists
())
{
atomicLong
.
set
(
0
);
}
long
endLong
=
new
Date
().
getTime
();
Long
startLong
=
RedisUtil
.
get
(
RedisConst
.
ALARM_DEVICE_ID
+
deviceId
);
if
(
personStateList
.
contains
(
personState
))
{
long
count
=
atomicLong
.
incrementAndGet
();
long
count
=
endLong
-
startLong
;
if
(
startLong
==
null
){
RedisUtil
.
set
(
RedisConst
.
ALARM_DEVICE_ID
+
deviceId
,
endLong
);
continue
;
}
if
(
count
>=
duration
)
{
PlatAlarmRecord
platAlarmRecord
=
createBehaviorPlatAlarmRecord
(
platDevice
,
config
);
atomicLong
.
set
(
0
);
RedisUtil
.
set
(
RedisConst
.
ALARM_DEVICE_ID
+
deviceId
,
startLong
);
}
}
else
{
atomicLong
.
set
(
0
);
//
RedisUtil
.
set
(
RedisConst
.
ALARM_DEVICE_ID
+
deviceId
,
null
);
}
}
// else { //没人 更新停留时长
...
...
@@ -337,5 +334,10 @@ public class PushCallback implements MqttCallback {
}
return
result
;
}
public
static
void
main
(
String
[]
args
)
{
Date
date
=
new
Date
();
System
.
out
.
println
(
date
.
toInstant
());
}
}
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