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
5fed9d5e
authored
Jan 16, 2024
by
罗志长
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
lock
parent
86c48256
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
104 additions
and
1 deletions
server-common/src/main/java/com/makeit/utils/redis/RedisUtil.java
server-service/src/main/java/com/makeit/task/DayDurationTask.java
server-service/src/main/java/com/makeit/task/IotSyncTask.java
server-service/src/main/java/com/makeit/task/PlatElderReportTask.java
server-common/src/main/java/com/makeit/utils/redis/RedisUtil.java
View file @
5fed9d5e
...
...
@@ -80,6 +80,15 @@ public class RedisUtil {
return
lock
;
}
public
static
boolean
tryLock
(
String
key
,
long
waitTime
,
long
leaseTime
,
TimeUnit
unit
)
{
RLock
lock
=
client
.
getLock
(
getProjectName
()
+
RedisUtil
.
LOCK
+
key
);
try
{
return
lock
.
tryLock
(
waitTime
,
leaseTime
,
unit
);
}
catch
(
InterruptedException
e
)
{
return
false
;
}
}
/**
* 关闭锁
*/
...
...
@@ -87,6 +96,13 @@ public class RedisUtil {
lock
.
unlock
();
}
public
static
void
unlock
(
String
key
)
{
RLock
lock
=
client
.
getLock
(
getProjectName
()
+
RedisUtil
.
LOCK
+
key
);
if
(
lock
.
isHeldByCurrentThread
())
{
unlock
(
lock
);
}
}
public
static
void
lock
(
String
key
,
long
expire
,
Runnable
runnable
)
{
RLock
lock
=
lock
(
key
,
expire
);
try
{
...
...
server-service/src/main/java/com/makeit/task/DayDurationTask.java
View file @
5fed9d5e
package
com
.
makeit
.
task
;
import
com.makeit.utils.DayDurationUtil
;
import
com.makeit.utils.redis.RedisUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
java.util.concurrent.TimeUnit
;
@Component
@Slf4j
@ConditionalOnProperty
(
value
=
{
"iot.sync.enable"
},
havingValue
=
"true"
)
...
...
@@ -17,6 +20,18 @@ public class DayDurationTask {
@Scheduled
(
cron
=
"0 10 * * * ?"
)
public
void
updateDayDuration
()
{
boolean
isSuccess
=
false
;
String
key
=
"update:day:duration"
;
try
{
isSuccess
=
RedisUtil
.
tryLock
(
key
,
0
,
3
,
TimeUnit
.
SECONDS
);
if
(
isSuccess
)
{
dayDurationUtil
.
getAll
();
}
}
finally
{
if
(
isSuccess
)
{
RedisUtil
.
unlock
(
key
);
}
}
}
}
server-service/src/main/java/com/makeit/task/IotSyncTask.java
View file @
5fed9d5e
package
com
.
makeit
.
task
;
import
com.makeit.service.platform.device.PlatDeviceService
;
import
com.makeit.utils.redis.RedisUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
java.util.concurrent.TimeUnit
;
@Component
@Slf4j
@ConditionalOnProperty
(
value
=
{
"iot.sync.enable"
},
havingValue
=
"true"
)
...
...
@@ -17,14 +20,25 @@ public class IotSyncTask {
/**
* 一
小时
同步一次
* 一
分钟
同步一次
* 启用状态的租户才同步
* 新增和更新平台端设备表
*/
@Scheduled
(
cron
=
"0 0/1 * * * ?"
)
public
void
syncEquipmentInfo
()
{
boolean
isSuccess
=
false
;
String
key
=
"sync:equipment:info"
;
try
{
isSuccess
=
RedisUtil
.
tryLock
(
key
,
0
,
3
,
TimeUnit
.
SECONDS
);
if
(
isSuccess
)
{
platDeviceService
.
savePlatDevice
();
}
}
finally
{
if
(
isSuccess
)
{
RedisUtil
.
unlock
(
key
);
}
}
}
}
server-service/src/main/java/com/makeit/task/PlatElderReportTask.java
View file @
5fed9d5e
...
...
@@ -2,12 +2,15 @@ package com.makeit.task;
import
com.makeit.global.aspect.tenant.TenantIdIgnore
;
import
com.makeit.service.platform.elder.*
;
import
com.makeit.utils.redis.RedisUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
java.util.concurrent.TimeUnit
;
@Component
@Slf4j
@ConditionalOnProperty
(
value
=
{
"iot.sync.enable"
},
havingValue
=
"true"
)
...
...
@@ -29,18 +32,40 @@ public class PlatElderReportTask {
@Scheduled
(
cron
=
"0 0 1 * * ?"
)
@TenantIdIgnore
public
void
heartRespiratoryTask
()
{
boolean
isSuccess
=
false
;
String
key
=
"task:heart:respiratory"
;
try
{
isSuccess
=
RedisUtil
.
tryLock
(
key
,
0
,
3
,
TimeUnit
.
SECONDS
);
if
(
isSuccess
)
{
log
.
info
(
"开始生成长者每日呼吸,异常情况"
);
platElderBreatheDayStatService
.
heartRespiratoryTask
();
log
.
info
(
"生成长者每日呼吸,异常情况结束"
);
}
}
finally
{
if
(
isSuccess
)
{
RedisUtil
.
unlock
(
key
);
}
}
}
@Scheduled
(
cron
=
"0 30 1 * * ?"
)
@TenantIdIgnore
public
void
coordinateRecordTask
()
{
boolean
isSuccess
=
false
;
String
key
=
"task:coordinate:record"
;
try
{
isSuccess
=
RedisUtil
.
tryLock
(
key
,
0
,
3
,
TimeUnit
.
SECONDS
);
if
(
isSuccess
)
{
log
.
info
(
"开始生成长者每日实时定位"
);
platElderCoordinateRecordService
.
coordinateRecordTask
();
log
.
info
(
"生成长者每日实时定位结束"
);
}
}
finally
{
if
(
isSuccess
)
{
RedisUtil
.
unlock
(
key
);
}
}
}
/**
...
...
@@ -49,10 +74,21 @@ public class PlatElderReportTask {
@Scheduled
(
cron
=
"0 0 2 * * ?"
)
@TenantIdIgnore
public
void
elderHeartRespiratoryAnalysisTask
()
{
boolean
isSuccess
=
false
;
String
key
=
"task:elder:heart:respiratory:analysis"
;
try
{
isSuccess
=
RedisUtil
.
tryLock
(
key
,
0
,
3
,
TimeUnit
.
SECONDS
);
if
(
isSuccess
)
{
log
.
info
(
"开始定时分析长者呼吸心率"
);
platElderBreatheAnalysisService
.
elderHeartRespiratoryAnalysisTask
(
null
,
null
);
log
.
info
(
"定时分析长者呼吸心率结束"
);
}
}
finally
{
if
(
isSuccess
)
{
RedisUtil
.
unlock
(
key
);
}
}
}
/**
* 生成长者呼吸心率
...
...
@@ -60,10 +96,21 @@ public class PlatElderReportTask {
@Scheduled
(
cron
=
"0 30 2 * * ?"
)
@TenantIdIgnore
public
void
breatheHeartRateRecordTask
()
{
boolean
isSuccess
=
false
;
String
key
=
"task:breathe:heart:rate:record"
;
try
{
isSuccess
=
RedisUtil
.
tryLock
(
key
,
0
,
3
,
TimeUnit
.
SECONDS
);
if
(
isSuccess
)
{
log
.
info
(
"开始生成长者呼吸心率"
);
platElderBreatheHeartRateRecordService
.
breatheHeartRateRecordTask
();
log
.
info
(
"生成长者呼吸心率结束"
);
}
}
finally
{
if
(
isSuccess
)
{
RedisUtil
.
unlock
(
key
);
}
}
}
/**
* 长者睡眠分析
...
...
@@ -71,8 +118,19 @@ public class PlatElderReportTask {
@Scheduled
(
cron
=
"0 0 8 * * ?"
)
@TenantIdIgnore
public
void
elderSleepSleepAnalysisTask
()
{
boolean
isSuccess
=
false
;
String
key
=
"task:elder:sleep:analysis"
;
try
{
isSuccess
=
RedisUtil
.
tryLock
(
key
,
0
,
3
,
TimeUnit
.
SECONDS
);
if
(
isSuccess
)
{
log
.
info
(
"开始定时分析长者睡眠质量"
);
platElderSleepService
.
elderSleepSleepAnalysisTask
(
null
,
null
);
log
.
info
(
"定时分析长者睡眠质量结束"
);
}
}
finally
{
if
(
isSuccess
)
{
RedisUtil
.
unlock
(
key
);
}
}
}
}
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