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
c0ae029f
authored
Sep 28, 2023
by
朱淼
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
代码更新
parent
df2b25d9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
18 deletions
server-common/src/main/java/com/makeit/utils/redis/ScheduleLockUtil.java
server-service/src/main/java/com/makeit/service/demo/impl/DemoDeviceServiceImpl.java
server-service/src/main/java/com/makeit/task/DemoDeviceTask.java
server-common/src/main/java/com/makeit/utils/redis/ScheduleLockUtil.java
View file @
c0ae029f
...
...
@@ -36,11 +36,12 @@ public class ScheduleLockUtil {
}
public
static
boolean
lockWithLog
(
String
key
)
{
boolean
b
=
lock
(
key
);
if
(!
b
)
{
logger
.
info
(
"key:{} fail"
,
key
);
}
return
b
;
// boolean b = lock(key);
// if (!b) {
// logger.info("key:{} fail", key);
// }
// return b;
return
true
;
}
public
static
boolean
lockWithLog
(
String
key
,
long
minute
)
{
...
...
server-service/src/main/java/com/makeit/service/demo/impl/DemoDeviceServiceImpl.java
View file @
c0ae029f
...
...
@@ -18,10 +18,13 @@ import com.makeit.vo.platform.elder.realtime.PlatElderRealTimeHeartRespiratoryVO
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.math.BigDecimal
;
import
java.time.Instant
;
import
java.time.LocalDateTime
;
import
java.time.ZoneId
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.Random
;
/**
* <p>
...
...
@@ -59,15 +62,29 @@ public class DemoDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
@Override
public
DemoHeartRespiratoryVO
heartRate
(
DemoDeviceDTO
dto
)
{
List
<
Integer
>
values
=
Arrays
.
asList
(
1
,
3
,-
1
,
2
,
0
,-
2
,-
3
);
Random
rand
=
new
Random
();
int
n
=
rand
.
nextInt
(
values
.
size
());
Integer
value
=
values
.
get
(
n
);
DemoHeartRespiratoryVO
vo
=
new
DemoHeartRespiratoryVO
();
DemoDeviceEntity
demoDeviceEntity
=
demoProductDeviceService
.
queryDeviceDetail
(
dto
.
getEntityCode
(),
true
);
if
(
"3"
.
equals
(
demoDeviceEntity
.
getStatus
())){
for
(
DemoDeviceEntity
.
DeviceShadowDTO
deviceShadowDTO
:
demoDeviceEntity
.
getDeviceShadowDTOList
()){
if
(
deviceShadowDTO
.
getAttribute
()!=
null
&&
"heartRate"
.
equals
(
deviceShadowDTO
.
getAttribute
().
getAttributeCode
())){
vo
.
setHeartRate
(
deviceShadowDTO
.
getValue
());
Instant
instant
=
Instant
.
ofEpochMilli
(
deviceShadowDTO
.
getValueTime
());
ZoneId
zone
=
ZoneId
.
systemDefault
();
vo
.
setTime
(
LocalDateTime
.
ofInstant
(
instant
,
zone
));
// Instant instant = Instant.ofEpochMilli(deviceShadowDTO.getValueTime());
// ZoneId zone = ZoneId.systemDefault();
// vo.setTime(LocalDateTime.ofInstant(instant, zone));
if
(
deviceShadowDTO
.
getValue
()!=
null
&&
Integer
.
valueOf
(
deviceShadowDTO
.
getValue
())>
3
){
// if(LocalDateTime.now().getSecond()%2==0){
// vo.setHeartRate(String.valueOf(Integer.valueOf(vo.getHeartRate())+1));
// }else {
// vo.setHeartRate(String.valueOf(Integer.valueOf(vo.getHeartRate())-1));
// }
vo
.
setHeartRate
(
String
.
valueOf
(
Integer
.
valueOf
(
vo
.
getHeartRate
())+
value
));
}
vo
.
setTime
(
LocalDateTime
.
now
());
}
}
...
...
server-service/src/main/java/com/makeit/task/DemoDeviceTask.java
View file @
c0ae029f
...
...
@@ -32,10 +32,7 @@ import java.time.Instant;
import
java.time.LocalDateTime
;
import
java.time.ZoneId
;
import
java.time.ZoneOffset
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.*
;
import
java.util.stream.Collectors
;
@Component
...
...
@@ -47,9 +44,14 @@ public class DemoDeviceTask {
private
DemoProductDeviceService
demoProductDeviceService
;
@Scheduled
(
cron
=
"
0
/1 * * * * ?"
)
@Scheduled
(
cron
=
"
*
/1 * * * * ?"
)
public
void
syncDemoAlarm
()
{
System
.
err
.
println
(
"开始执行"
);
log
.
info
(
"syncDemoAlarm开始执行"
);
List
<
String
>
names
=
Arrays
.
asList
(
"钟奕轩"
,
"林彦辰"
,
"周子恒"
,
"唐景晨"
);
Random
rand
=
new
Random
();
int
n
=
rand
.
nextInt
(
names
.
size
());
String
name
=
names
.
get
(
n
);
log
.
info
(
"name:"
+
name
);
List
<
PlatAlarmRecord
>
records
=
platAlarmRecordService
.
list
(
new
QueryWrapper
<
PlatAlarmRecord
>().
lambda
().
orderByDesc
(
PlatAlarmRecord:
:
getAlarmDate
)
);
...
...
@@ -62,7 +64,7 @@ public class DemoDeviceTask {
if
(
"1"
.
equals
(
dto
.
getValue
())){
PlatAlarmRecord
alarmRecord
=
new
PlatAlarmRecord
();
alarmRecord
.
setAlarmType
(
PlatAlarmConfigEnum
.
AlarmTypeEnum
.
FALL
.
getValue
());
alarmRecord
.
setContent
(
"张三
在房间内跌倒,请及时处理"
);
alarmRecord
.
setContent
(
name
+
"
在房间内跌倒,请及时处理"
);
alarmRecord
.
setStatus
(
PlatAlarmRecordEnum
.
AlarmRecordStatusEnum
.
UNHANDLED
.
getValue
());
Instant
instant
=
Instant
.
ofEpochMilli
(
dto
.
getValueTime
());
ZoneId
zone
=
ZoneId
.
systemDefault
();
...
...
@@ -82,12 +84,12 @@ public class DemoDeviceTask {
if
(
"1"
.
equals
(
dto
.
getValue
())
&&
!
record
.
getValueTime
().
equals
(
dto
.
getValueTime
())){
PlatAlarmRecord
alarmRecord
=
new
PlatAlarmRecord
();
alarmRecord
.
setAlarmType
(
PlatAlarmConfigEnum
.
AlarmTypeEnum
.
FALL
.
getValue
());
alarmRecord
.
setContent
(
"张三
在房间内跌倒,请及时处理"
);
alarmRecord
.
setContent
(
name
+
"
在房间内跌倒,请及时处理"
);
alarmRecord
.
setStatus
(
PlatAlarmRecordEnum
.
AlarmRecordStatusEnum
.
UNHANDLED
.
getValue
());
Instant
instant
=
Instant
.
ofEpochMilli
(
dto
.
getValueTime
());
ZoneId
zone
=
ZoneId
.
systemDefault
();
alarmRecord
.
setAlarmDate
(
LocalDateTime
.
ofInstant
(
instant
,
zone
));
//
alarmRecord.setAlarmId(dto.getId());
alarmRecord
.
setAlarmId
(
dto
.
getId
());
alarmRecord
.
setValueTime
(
dto
.
getValueTime
());
alarmRecord
.
setTenantId
(
"1705124341248724993"
);
platAlarmRecordService
.
save
(
alarmRecord
);
...
...
@@ -99,7 +101,7 @@ public class DemoDeviceTask {
}
log
.
info
(
"syncDemoAlarm结束执行"
);
}
...
...
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