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
bd12c285
authored
Jan 19, 2024
by
罗志长
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merge branch 'dev'
parents
39dc5c78
14be8b10
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
175 additions
and
39 deletions
server-common/src/main/java/com/makeit/enums/CodeMessageEnum.java
server-common/src/main/java/com/makeit/enums/redis/RedisConst.java
server-common/src/main/java/com/makeit/exception/GlobalExceptionHandler.java
server-common/src/main/java/com/makeit/utils/redis/RedisUtil.java
server-module/src/main/java/com/makeit/module/controller/wechat/device/PlatDeviceWechatController.java
server-service/src/main/java/com/makeit/external/strategy/HuiNengStrategy.java
server-service/src/main/java/com/makeit/service/platform/alarm/alarmStrategy/FallAlarm.java
server-service/src/main/java/com/makeit/service/platform/elder/impl/PlatElderBreatheAnalysisServiceImpl.java
server-service/src/main/java/com/makeit/service/saas/impl/PlatTenantServiceImpl.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-service/src/main/java/com/makeit/utils/DeviceCacheUtil.java
server-web/src/main/java/com/makeit/mqtt/MqttPushClient.java
server-web/src/main/java/com/makeit/mqtt/PushCallback.java
server-web/src/main/resources/logback-spring-prod.xml
server-common/src/main/java/com/makeit/enums/CodeMessageEnum.java
View file @
bd12c285
...
@@ -109,11 +109,11 @@ public enum CodeMessageEnum {
...
@@ -109,11 +109,11 @@ public enum CodeMessageEnum {
PLATFORM_ERROR_SPACE_OVER_LEVEL
(
500
,
"PLATFORM.ERROR.SPACE.OVER.LEVEL"
),
PLATFORM_ERROR_SPACE_OVER_LEVEL
(
500
,
"PLATFORM.ERROR.SPACE.OVER.LEVEL"
),
PLATFORM_ERROR_SPACE_USER_NOT_ADD
(
500
,
"PLATFORM.ERROR.SPACE.USER.NOT.ADD"
),
PLATFORM_ERROR_SPACE_USER_NOT_ADD
(
500
,
"PLATFORM.ERROR.SPACE.USER.NOT.ADD"
),
PLATFORM_ERROR_SPACE_ROOM_NOT_ADD
(
500
,
"PLATFORM.ERROR.SPACE.ROOM.NOT.ADD"
),
PLATFORM_ERROR_SPACE_ROOM_NOT_ADD
(
500
,
"PLATFORM.ERROR.SPACE.ROOM.NOT.ADD"
),
PLATFORM_ERROR_ROOM_EXIT_BAD
(
5
00
,
"PLATFORM.ERROR.ROOM.EXIT.BED"
),
PLATFORM_ERROR_ROOM_EXIT_BAD
(
5
55
,
"PLATFORM.ERROR.ROOM.EXIT.BED"
),
PLATFORM_ERROR_ROOM_BAD_NUMBER_NOT_AUTH
(
5
00
,
"PLATFORM.ERROR.ROOM.BED.NUMBER.NOT.AUTH"
),
PLATFORM_ERROR_ROOM_BAD_NUMBER_NOT_AUTH
(
5
55
,
"PLATFORM.ERROR.ROOM.BED.NUMBER.NOT.AUTH"
),
PLATFORM_ERROR_ROOM_NAME_EXIT
(
5
00
,
"PLATFORM.ERROR.ROOM.NAME.EXIT"
),
PLATFORM_ERROR_ROOM_NAME_EXIT
(
5
55
,
"PLATFORM.ERROR.ROOM.NAME.EXIT"
),
PLATFORM_ERROR_BAD_NAME_EXIT
(
5
00
,
"PLATFORM.ERROR.BED.NAME.EXIT"
),
PLATFORM_ERROR_BAD_NAME_EXIT
(
5
55
,
"PLATFORM.ERROR.BED.NAME.EXIT"
),
PLATFORM_ERROR_BAD_NOT_DEL
(
5
00
,
"PLATFORM.ERROR.BED.NOT.DEL"
),
PLATFORM_ERROR_BAD_NOT_DEL
(
5
55
,
"PLATFORM.ERROR.BED.NOT.DEL"
),
PLATFORM_ERROR_BED_NOT_BIND_ELDER
(
500
,
"PLATFORM.ERROR.BED.NOT.BIND.ELDER"
),
PLATFORM_ERROR_BED_NOT_BIND_ELDER
(
500
,
"PLATFORM.ERROR.BED.NOT.BIND.ELDER"
),
PLATFORM_ERROR_ROOM_OTHER_USED_NOT_DEL
(
500
,
"PLATFORM.ERROR.ROOM.OTHER.USED.NOT.DEL"
),
PLATFORM_ERROR_ROOM_OTHER_USED_NOT_DEL
(
500
,
"PLATFORM.ERROR.ROOM.OTHER.USED.NOT.DEL"
),
PLATFORM_ERROR_BED_BIND_DEVICE_NOT_AUTH
(
500
,
"PLATFORM.ERROR.BED.BIND.DEVICE.NOT.AUTH"
),
PLATFORM_ERROR_BED_BIND_DEVICE_NOT_AUTH
(
500
,
"PLATFORM.ERROR.BED.BIND.DEVICE.NOT.AUTH"
),
...
...
server-common/src/main/java/com/makeit/enums/redis/RedisConst.java
View file @
bd12c285
...
@@ -101,6 +101,8 @@ public class RedisConst {
...
@@ -101,6 +101,8 @@ public class RedisConst {
public
static
final
String
ALARM_CONFIG_ORG_ID
=
"alarm:config:org:id:"
;
public
static
final
String
ALARM_CONFIG_ORG_ID
=
"alarm:config:org:id:"
;
public
static
final
String
PLAT_IOT_DEVICE_PREFIX
=
"plat:iot:device:"
;
public
static
final
String
PLAT_IOT_DEVICE_PREFIX
=
"plat:iot:device:"
;
public
static
final
String
PLAT_OWN_IOT_DEVICE_ID
=
"plat:own:iot:device:id:"
;
public
static
final
String
ELDER_DAY_DURATION_PREFIX
=
"plat:day:duration:device:"
;
public
static
final
String
ELDER_DAY_DURATION_PREFIX
=
"plat:day:duration:device:"
;
public
static
final
String
LOCK_ALARM
=
"lock:alarm:device:id:"
;
public
static
final
String
LOCK_ALARM
=
"lock:alarm:device:id:"
;
...
...
server-common/src/main/java/com/makeit/exception/GlobalExceptionHandler.java
View file @
bd12c285
...
@@ -285,7 +285,7 @@ public class GlobalExceptionHandler {
...
@@ -285,7 +285,7 @@ public class GlobalExceptionHandler {
logger
.
error
(
"业务异常{}\n{}\n{}"
,
ExceptionResponseUtil
.
prefix
(
b
),
LocaleUtil
.
getMessage
(
b
.
getMessage
()),
ExceptionPrintUtil
.
getStackTraceByPn
(
b
,
PackageConst
.
TOP
));
logger
.
error
(
"业务异常{}\n{}\n{}"
,
ExceptionResponseUtil
.
prefix
(
b
),
LocaleUtil
.
getMessage
(
b
.
getMessage
()),
ExceptionPrintUtil
.
getStackTraceByPn
(
b
,
PackageConst
.
TOP
));
return
ApiResponseUtils
.
fail
(
b
.
getCode
(),
ExceptionResponseUtil
.
prefix
(
b
)
+
LocaleUtil
.
getMessage
(
b
.
getMessage
()),
ExceptionResponseUtil
.
body
(
b
));
return
ApiResponseUtils
.
fail
(
b
.
getCode
(),
LocaleUtil
.
getMessage
(
b
.
getMessage
()),
ExceptionResponseUtil
.
body
(
b
));
}
}
// private ApiResponseEntity<Object> getApiResponse(GlobalException b, String message) {
// private ApiResponseEntity<Object> getApiResponse(GlobalException b, String message) {
...
...
server-common/src/main/java/com/makeit/utils/redis/RedisUtil.java
View file @
bd12c285
...
@@ -80,6 +80,15 @@ public class RedisUtil {
...
@@ -80,6 +80,15 @@ public class RedisUtil {
return
lock
;
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 {
...
@@ -87,6 +96,13 @@ public class RedisUtil {
lock
.
unlock
();
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
)
{
public
static
void
lock
(
String
key
,
long
expire
,
Runnable
runnable
)
{
RLock
lock
=
lock
(
key
,
expire
);
RLock
lock
=
lock
(
key
,
expire
);
try
{
try
{
...
...
server-module/src/main/java/com/makeit/module/controller/wechat/device/PlatDeviceWechatController.java
View file @
bd12c285
package
com
.
makeit
.
module
.
controller
.
wechat
.
device
;
package
com
.
makeit
.
module
.
controller
.
wechat
.
device
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Lists
;
import
com.makeit.common.dto.BaseIdDTO
;
import
com.makeit.common.dto.BaseIdDTO
;
import
com.makeit.common.page.PageReqDTO
;
import
com.makeit.common.page.PageReqDTO
;
...
@@ -14,6 +15,7 @@ import com.makeit.dto.wechat.device.PlatDeviceNetAttrWechatDTO;
...
@@ -14,6 +15,7 @@ import com.makeit.dto.wechat.device.PlatDeviceNetAttrWechatDTO;
import
com.makeit.dto.wechat.device.PlatDeviceSetupDTO
;
import
com.makeit.dto.wechat.device.PlatDeviceSetupDTO
;
import
com.makeit.entity.platform.auth.PlatOrg
;
import
com.makeit.entity.platform.auth.PlatOrg
;
import
com.makeit.entity.platform.auth.PlatRole
;
import
com.makeit.entity.platform.auth.PlatRole
;
import
com.makeit.entity.platform.device.PlatDevice
;
import
com.makeit.enums.HeaderConst
;
import
com.makeit.enums.HeaderConst
;
import
com.makeit.global.annotation.AuthIgnore
;
import
com.makeit.global.annotation.AuthIgnore
;
import
com.makeit.module.iot.vo.DeviceProperties
;
import
com.makeit.module.iot.vo.DeviceProperties
;
...
@@ -29,10 +31,7 @@ import io.swagger.annotations.Api;
...
@@ -29,10 +31,7 @@ import io.swagger.annotations.Api;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.List
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
...
@@ -80,6 +79,15 @@ public class PlatDeviceWechatController {
...
@@ -80,6 +79,15 @@ public class PlatDeviceWechatController {
return
ApiResponseUtils
.
success
(
platDeviceService
.
viewByDeviceId
(
baseIdDTO
.
getId
()));
return
ApiResponseUtils
.
success
(
platDeviceService
.
viewByDeviceId
(
baseIdDTO
.
getId
()));
}
}
@ApiOperation
(
"配网前校验"
)
@PostMapping
(
"setUpCheck"
)
public
ApiResponseEntity
<?>
setUpCheck
(
@RequestBody
BaseIdDTO
baseIdDTO
)
{
PlatDevice
platDevice
=
platDeviceService
.
getOne
(
new
QueryWrapper
<
PlatDevice
>().
lambda
()
.
eq
(
PlatDevice:
:
getOriDeviceId
,
baseIdDTO
.
getId
())
.
last
(
"limit 1"
));
return
ApiResponseUtils
.
success
(
platDevice
!=
null
);
}
@ApiOperation
(
"配网"
)
@ApiOperation
(
"配网"
)
@PostMapping
(
"setUp"
)
@PostMapping
(
"setUp"
)
public
ApiResponseEntity
<?>
setup
(
@Validated
@RequestBody
PlatDeviceSetupDTO
dto
)
{
public
ApiResponseEntity
<?>
setup
(
@Validated
@RequestBody
PlatDeviceSetupDTO
dto
)
{
...
...
server-service/src/main/java/com/makeit/external/strategy/HuiNengStrategy.java
View file @
bd12c285
...
@@ -22,6 +22,7 @@ import org.springframework.stereotype.Service;
...
@@ -22,6 +22,7 @@ import org.springframework.stereotype.Service;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
import
java.time.format.DateTimeFormatter
;
import
java.time.format.DateTimeFormatter
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.List
;
@Service
@Service
...
@@ -42,6 +43,9 @@ public class HuiNengStrategy implements OpenApiBaseStrategy {
...
@@ -42,6 +43,9 @@ public class HuiNengStrategy implements OpenApiBaseStrategy {
if
(
platDevice
==
null
)
{
if
(
platDevice
==
null
)
{
return
;
return
;
}
}
if
(!
isSupportAlarm
(
platTenant
,
platDevice
))
{
return
;
}
if
(
StringUtils
.
isEmpty
(
platTenant
.
getUrl
()))
{
if
(
StringUtils
.
isEmpty
(
platTenant
.
getUrl
()))
{
log
.
info
(
"当前租户为配置openapi地址"
);
log
.
info
(
"当前租户为配置openapi地址"
);
return
;
return
;
...
@@ -97,6 +101,15 @@ public class HuiNengStrategy implements OpenApiBaseStrategy {
...
@@ -97,6 +101,15 @@ public class HuiNengStrategy implements OpenApiBaseStrategy {
log
.
info
(
"接口:{},返回信息:{}"
,
url
,
JSON
.
toJSONString
(
responseMessage
));
log
.
info
(
"接口:{},返回信息:{}"
,
url
,
JSON
.
toJSONString
(
responseMessage
));
}
}
private
boolean
isSupportAlarm
(
PlatTenant
platTenant
,
PlatDevice
platDevice
)
{
String
reportOrgIds
=
platTenant
.
getReportOrgIds
();
if
(
StringUtils
.
isBlank
(
reportOrgIds
))
{
return
false
;
}
List
<
String
>
orgIds
=
Arrays
.
asList
(
StringUtils
.
split
(
reportOrgIds
,
","
));
return
orgIds
.
contains
(
platDevice
.
getOrgId
());
}
@Override
@Override
@TenantIdIgnore
@TenantIdIgnore
public
void
alarm
(
PlatTenant
platTenant
,
String
deviceId
,
JSONObject
jsonObject
)
{
public
void
alarm
(
PlatTenant
platTenant
,
String
deviceId
,
JSONObject
jsonObject
)
{
...
...
server-service/src/main/java/com/makeit/service/platform/alarm/alarmStrategy/FallAlarm.java
View file @
bd12c285
...
@@ -135,7 +135,7 @@ public class FallAlarm implements IAlarm {
...
@@ -135,7 +135,7 @@ public class FallAlarm implements IAlarm {
PlatDevice
platDevice
=
platAlarmCheckDTO
.
getPlatDevice
();
PlatDevice
platDevice
=
platAlarmCheckDTO
.
getPlatDevice
();
PlatAlarmConfig
config
=
alarmConfigCacheUtil
.
get
(
platDevice
.
getOrgId
(),
PlatAlarmConfigEnum
.
AlarmTypeEnum
.
BEHAVIOR
.
getValue
());
PlatAlarmConfig
config
=
alarmConfigCacheUtil
.
get
(
platDevice
.
getOrgId
(),
PlatAlarmConfigEnum
.
AlarmTypeEnum
.
BEHAVIOR
.
getValue
());
if
(
config
==
null
||
StringUtils
.
isBlank
(
config
.
getRuleConfig
()))
{
if
(
config
==
null
||
StringUtils
.
isBlank
(
config
.
getRuleConfig
()))
{
log
.
error
(
"行为告警配置未配置,
告警配置id:"
+
config
.
get
Id
());
log
.
error
(
"行为告警配置未配置,
orgId:"
+
platDevice
.
getOrg
Id
());
return
;
return
;
}
}
String
ruleConfigStr
=
config
.
getRuleConfig
();
String
ruleConfigStr
=
config
.
getRuleConfig
();
...
...
server-service/src/main/java/com/makeit/service/platform/elder/impl/PlatElderBreatheAnalysisServiceImpl.java
View file @
bd12c285
...
@@ -239,7 +239,7 @@ public class PlatElderBreatheAnalysisServiceImpl extends ServiceImpl<PlatElderBr
...
@@ -239,7 +239,7 @@ public class PlatElderBreatheAnalysisServiceImpl extends ServiceImpl<PlatElderBr
existBrFast
.
set
(
false
);
existBrFast
.
set
(
false
);
existBrStop
.
set
(
false
);
existBrStop
.
set
(
false
);
existBrSlow
.
set
(
false
);
existBrSlow
.
set
(
false
);
log
.
info
(
"呼吸正常:{},min:{},max:{},的时间:{}"
,
br
,
breatheThresholdMin
,
breatheThresholdMax
,
longToTime
(
timestamp
));
//
log.info("呼吸正常:{},min:{},max:{},的时间:{}", br, breatheThresholdMin, breatheThresholdMax, longToTime(timestamp));
}
}
// 心率过快
// 心率过快
...
@@ -279,7 +279,7 @@ public class PlatElderBreatheAnalysisServiceImpl extends ServiceImpl<PlatElderBr
...
@@ -279,7 +279,7 @@ public class PlatElderBreatheAnalysisServiceImpl extends ServiceImpl<PlatElderBr
existHrSlow
.
set
(
false
);
existHrSlow
.
set
(
false
);
hrFastSecond
.
set
(
0
);
hrFastSecond
.
set
(
0
);
existHrFast
.
set
(
false
);
existHrFast
.
set
(
false
);
log
.
info
(
"心率正常:{},min:{},max:{},的时间:{}"
,
hr
,
heartThresholdMin
,
heartThresholdMax
,
longToTime
(
timestamp
));
//
log.info("心率正常:{},min:{},max:{},的时间:{}", hr, heartThresholdMin, heartThresholdMax, longToTime(timestamp));
}
}
});
});
...
...
server-service/src/main/java/com/makeit/service/saas/impl/PlatTenantServiceImpl.java
View file @
bd12c285
...
@@ -265,7 +265,7 @@ public class PlatTenantServiceImpl extends ServiceImpl<PlatTenantMapper, PlatTen
...
@@ -265,7 +265,7 @@ public class PlatTenantServiceImpl extends ServiceImpl<PlatTenantMapper, PlatTen
tntTenant
.
setAppid
(
wxConfig
.
getAppId
());
tntTenant
.
setAppid
(
wxConfig
.
getAppId
());
}
}
if
(
StringUtils
.
isEmpty
(
tntTenant
.
getSecret
()))
{
if
(
StringUtils
.
isEmpty
(
tntTenant
.
getSecret
()))
{
tntTenant
.
setSecret
(
wxConfig
.
get
M
pSecret
());
tntTenant
.
setSecret
(
wxConfig
.
get
Ap
pSecret
());
}
}
//新租户同步到iot
//新租户同步到iot
...
...
server-service/src/main/java/com/makeit/task/DayDurationTask.java
View file @
bd12c285
package
com
.
makeit
.
task
;
package
com
.
makeit
.
task
;
import
com.makeit.utils.DayDurationUtil
;
import
com.makeit.utils.DayDurationUtil
;
import
com.makeit.utils.redis.RedisUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
java.util.concurrent.TimeUnit
;
@Component
@Component
@Slf4j
@Slf4j
@ConditionalOnProperty
(
value
=
{
"iot.sync.enable"
},
havingValue
=
"true"
)
@ConditionalOnProperty
(
value
=
{
"iot.sync.enable"
},
havingValue
=
"true"
)
...
@@ -17,6 +20,18 @@ public class DayDurationTask {
...
@@ -17,6 +20,18 @@ public class DayDurationTask {
@Scheduled
(
cron
=
"0 10 * * * ?"
)
@Scheduled
(
cron
=
"0 10 * * * ?"
)
public
void
updateDayDuration
()
{
public
void
updateDayDuration
()
{
dayDurationUtil
.
getAll
();
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 @
bd12c285
package
com
.
makeit
.
task
;
package
com
.
makeit
.
task
;
import
com.makeit.service.platform.device.PlatDeviceService
;
import
com.makeit.service.platform.device.PlatDeviceService
;
import
com.makeit.utils.redis.RedisUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
java.util.concurrent.TimeUnit
;
@Component
@Component
@Slf4j
@Slf4j
@ConditionalOnProperty
(
value
=
{
"iot.sync.enable"
},
havingValue
=
"true"
)
@ConditionalOnProperty
(
value
=
{
"iot.sync.enable"
},
havingValue
=
"true"
)
...
@@ -17,13 +20,24 @@ public class IotSyncTask {
...
@@ -17,13 +20,24 @@ public class IotSyncTask {
/**
/**
* 一
小时
同步一次
* 一
分钟
同步一次
* 启用状态的租户才同步
* 启用状态的租户才同步
* 新增和更新平台端设备表
* 新增和更新平台端设备表
*/
*/
@Scheduled
(
cron
=
"0 0/1 * * * ?"
)
@Scheduled
(
cron
=
"0 0/1 * * * ?"
)
public
void
syncEquipmentInfo
()
{
public
void
syncEquipmentInfo
()
{
platDeviceService
.
savePlatDevice
();
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 @
bd12c285
...
@@ -2,12 +2,15 @@ package com.makeit.task;
...
@@ -2,12 +2,15 @@ package com.makeit.task;
import
com.makeit.global.aspect.tenant.TenantIdIgnore
;
import
com.makeit.global.aspect.tenant.TenantIdIgnore
;
import
com.makeit.service.platform.elder.*
;
import
com.makeit.service.platform.elder.*
;
import
com.makeit.utils.redis.RedisUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
java.util.concurrent.TimeUnit
;
@Component
@Component
@Slf4j
@Slf4j
@ConditionalOnProperty
(
value
=
{
"iot.sync.enable"
},
havingValue
=
"true"
)
@ConditionalOnProperty
(
value
=
{
"iot.sync.enable"
},
havingValue
=
"true"
)
...
@@ -29,17 +32,39 @@ public class PlatElderReportTask {
...
@@ -29,17 +32,39 @@ public class PlatElderReportTask {
@Scheduled
(
cron
=
"0 0 1 * * ?"
)
@Scheduled
(
cron
=
"0 0 1 * * ?"
)
@TenantIdIgnore
@TenantIdIgnore
public
void
heartRespiratoryTask
()
{
public
void
heartRespiratoryTask
()
{
log
.
info
(
"开始生成长者每日呼吸,异常情况"
);
boolean
isSuccess
=
false
;
platElderBreatheDayStatService
.
heartRespiratoryTask
();
String
key
=
"task:heart:respiratory"
;
log
.
info
(
"生成长者每日呼吸,异常情况结束"
);
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 * * ?"
)
@Scheduled
(
cron
=
"0 30 1 * * ?"
)
@TenantIdIgnore
@TenantIdIgnore
public
void
coordinateRecordTask
()
{
public
void
coordinateRecordTask
()
{
log
.
info
(
"开始生成长者每日实时定位"
);
boolean
isSuccess
=
false
;
platElderCoordinateRecordService
.
coordinateRecordTask
();
String
key
=
"task:coordinate:record"
;
log
.
info
(
"生成长者每日实时定位结束"
);
try
{
isSuccess
=
RedisUtil
.
tryLock
(
key
,
0
,
3
,
TimeUnit
.
SECONDS
);
if
(
isSuccess
)
{
log
.
info
(
"开始生成长者每日实时定位"
);
platElderCoordinateRecordService
.
coordinateRecordTask
();
log
.
info
(
"生成长者每日实时定位结束"
);
}
}
finally
{
if
(
isSuccess
)
{
RedisUtil
.
unlock
(
key
);
}
}
}
}
...
@@ -49,9 +74,20 @@ public class PlatElderReportTask {
...
@@ -49,9 +74,20 @@ public class PlatElderReportTask {
@Scheduled
(
cron
=
"0 0 2 * * ?"
)
@Scheduled
(
cron
=
"0 0 2 * * ?"
)
@TenantIdIgnore
@TenantIdIgnore
public
void
elderHeartRespiratoryAnalysisTask
()
{
public
void
elderHeartRespiratoryAnalysisTask
()
{
log
.
info
(
"开始定时分析长者呼吸心率"
);
boolean
isSuccess
=
false
;
platElderBreatheAnalysisService
.
elderHeartRespiratoryAnalysisTask
(
null
,
null
);
String
key
=
"task:elder:heart:respiratory:analysis"
;
log
.
info
(
"定时分析长者呼吸心率结束"
);
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,9 +96,20 @@ public class PlatElderReportTask {
...
@@ -60,9 +96,20 @@ public class PlatElderReportTask {
@Scheduled
(
cron
=
"0 30 2 * * ?"
)
@Scheduled
(
cron
=
"0 30 2 * * ?"
)
@TenantIdIgnore
@TenantIdIgnore
public
void
breatheHeartRateRecordTask
()
{
public
void
breatheHeartRateRecordTask
()
{
log
.
info
(
"开始生成长者呼吸心率"
);
boolean
isSuccess
=
false
;
platElderBreatheHeartRateRecordService
.
breatheHeartRateRecordTask
();
String
key
=
"task:breathe:heart:rate:record"
;
log
.
info
(
"生成长者呼吸心率结束"
);
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 {
...
@@ -71,8 +118,19 @@ public class PlatElderReportTask {
@Scheduled
(
cron
=
"0 0 8 * * ?"
)
@Scheduled
(
cron
=
"0 0 8 * * ?"
)
@TenantIdIgnore
@TenantIdIgnore
public
void
elderSleepSleepAnalysisTask
()
{
public
void
elderSleepSleepAnalysisTask
()
{
log
.
info
(
"开始定时分析长者睡眠质量"
);
boolean
isSuccess
=
false
;
platElderSleepService
.
elderSleepSleepAnalysisTask
(
null
,
null
);
String
key
=
"task:elder:sleep:analysis"
;
log
.
info
(
"定时分析长者睡眠质量结束"
);
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
);
}
}
}
}
}
}
server-service/src/main/java/com/makeit/utils/DeviceCacheUtil.java
View file @
bd12c285
...
@@ -43,11 +43,16 @@ public class DeviceCacheUtil implements ApplicationRunner {
...
@@ -43,11 +43,16 @@ public class DeviceCacheUtil implements ApplicationRunner {
PlatTenant
platTenant
=
platTenantService
.
getById
(
platDevice
.
getTenantId
());
PlatTenant
platTenant
=
platTenantService
.
getById
(
platDevice
.
getTenantId
());
if
(
StringUtils
.
equals
(
platDevice
.
getStatus
(),
DeviceState
.
online
.
getValue
()))
{
if
(
StringUtils
.
equals
(
platDevice
.
getStatus
(),
DeviceState
.
online
.
getValue
()))
{
RedisUtil
.
set
(
RedisConst
.
PLAT_IOT_DEVICE_PREFIX
+
platDevice
.
getOriDeviceId
()+
":"
+
platTenant
.
getIotOrgId
(),
platDevice
);
RedisUtil
.
set
(
RedisConst
.
PLAT_IOT_DEVICE_PREFIX
+
platDevice
.
getOriDeviceId
()+
":"
+
platTenant
.
getIotOrgId
(),
platDevice
);
RedisUtil
.
set
(
RedisConst
.
PLAT_OWN_IOT_DEVICE_ID
+
platDevice
.
getOriDeviceId
(),
platDevice
);
}
else
{
}
else
{
String
key
=
RedisConst
.
PLAT_IOT_DEVICE_PREFIX
+
platDevice
.
getOriDeviceId
()+
":"
+
platTenant
.
getIotOrgId
();
String
key
=
RedisConst
.
PLAT_IOT_DEVICE_PREFIX
+
platDevice
.
getOriDeviceId
()+
":"
+
platTenant
.
getIotOrgId
();
if
(
RedisUtil
.
exist
(
key
)){
if
(
RedisUtil
.
exist
(
key
)){
RedisUtil
.
delete
(
RedisConst
.
PLAT_IOT_DEVICE_PREFIX
+
platDevice
.
getOriDeviceId
()+
":"
+
platTenant
.
getIotOrgId
());
RedisUtil
.
delete
(
RedisConst
.
PLAT_IOT_DEVICE_PREFIX
+
platDevice
.
getOriDeviceId
()+
":"
+
platTenant
.
getIotOrgId
());
}
}
String
key1
=
RedisConst
.
PLAT_OWN_IOT_DEVICE_ID
+
platDevice
.
getOriDeviceId
();
if
(
RedisUtil
.
exist
(
key1
)){
RedisUtil
.
delete
(
key1
);
}
}
}
}
}
...
...
server-web/src/main/java/com/makeit/mqtt/MqttPushClient.java
View file @
bd12c285
...
@@ -54,10 +54,12 @@ public class MqttPushClient {
...
@@ -54,10 +54,12 @@ public class MqttPushClient {
client
.
setCallback
(
pushCallback
);
client
.
setCallback
(
pushCallback
);
client
.
connect
(
options
);
client
.
connect
(
options
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
logger
.
error
(
"mqtt连接失败"
,
e
);
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
logger
.
error
(
"mqtt连接失败"
,
e
);
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
}
}
...
...
server-web/src/main/java/com/makeit/mqtt/PushCallback.java
View file @
bd12c285
...
@@ -43,7 +43,6 @@ import javax.annotation.Resource;
...
@@ -43,7 +43,6 @@ import javax.annotation.Resource;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.Objects
;
import
java.util.concurrent.CompletableFuture
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
...
@@ -104,6 +103,7 @@ public class PushCallback implements MqttCallbackExtended {
...
@@ -104,6 +103,7 @@ public class PushCallback implements MqttCallbackExtended {
}
}
@Override
@Override
@Async
public
void
messageArrived
(
String
topic
,
MqttMessage
message
)
{
public
void
messageArrived
(
String
topic
,
MqttMessage
message
)
{
try
{
try
{
// 收到消息并设置返回字符串格式
// 收到消息并设置返回字符串格式
...
@@ -114,6 +114,12 @@ public class PushCallback implements MqttCallbackExtended {
...
@@ -114,6 +114,12 @@ public class PushCallback implements MqttCallbackExtended {
// 解析数据
// 解析数据
DeviceInfo
device
=
JSON
.
parseObject
(
payload
,
DeviceInfo
.
class
);
DeviceInfo
device
=
JSON
.
parseObject
(
payload
,
DeviceInfo
.
class
);
// 独立部署的服务过滤出平台自己的设备消息
String
key
=
RedisConst
.
PLAT_OWN_IOT_DEVICE_ID
+
device
.
getDeviceId
();
if
(!
RedisUtil
.
exist
(
key
))
{
return
;
}
syncProperties
(
device
);
syncProperties
(
device
);
checkAlarm
(
device
);
checkAlarm
(
device
);
...
@@ -161,10 +167,8 @@ public class PushCallback implements MqttCallbackExtended {
...
@@ -161,10 +167,8 @@ public class PushCallback implements MqttCallbackExtended {
if
(!
"0"
.
equals
(
success
))
{
if
(!
"0"
.
equals
(
success
))
{
return
;
return
;
}
}
CompletableFuture
.
runAsync
(()
->
{
platDeviceService
.
syncIotProperties
(
device
.
getDeviceId
(),
properties
);
platDeviceService
.
syncIotProperties
(
device
.
getDeviceId
(),
properties
);
RedisUtil
.
delete
(
redisKey
);
RedisUtil
.
delete
(
redisKey
);
});
// 要加线程池
}
}
}
}
...
@@ -174,7 +178,6 @@ public class PushCallback implements MqttCallbackExtended {
...
@@ -174,7 +178,6 @@ public class PushCallback implements MqttCallbackExtended {
* @param device
* @param device
*/
*/
@TenantIdIgnore
@TenantIdIgnore
@Async
public
void
checkAlarm
(
DeviceInfo
device
)
{
public
void
checkAlarm
(
DeviceInfo
device
)
{
HeaderInfo
headers
=
device
.
getHeaders
();
HeaderInfo
headers
=
device
.
getHeaders
();
List
<
HeaderInfo
.
Bind
>
bindings
=
headers
.
getBindings
();
List
<
HeaderInfo
.
Bind
>
bindings
=
headers
.
getBindings
();
...
...
server-web/src/main/resources/logback-spring-prod.xml
View file @
bd12c285
...
@@ -39,7 +39,7 @@
...
@@ -39,7 +39,7 @@
</FileNamePattern>
</FileNamePattern>
<maxHistory>
10
</maxHistory>
<maxHistory>
10
</maxHistory>
<timeBasedFileNamingAndTriggeringPolicy
class=
"ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"
>
<timeBasedFileNamingAndTriggeringPolicy
class=
"ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"
>
<maxFileSize>
20MB
</maxFileSize>
<maxFileSize>
20
48
MB
</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</rollingPolicy>
...
...
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