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
3017be2f
authored
Dec 13, 2023
by
罗志长
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
feat: iot设备属性同步
parent
8b3efe9f
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
91 additions
and
1 deletions
server-service/src/main/java/com/makeit/service/platform/device/PlatDeviceService.java
server-service/src/main/java/com/makeit/service/platform/device/impl/PlatDeviceServiceImpl.java
server-web/src/main/java/com/makeit/mqtt/PushCallback.java
server-service/src/main/java/com/makeit/service/platform/device/PlatDeviceService.java
View file @
3017be2f
package
com
.
makeit
.
service
.
platform
.
device
;
package
com
.
makeit
.
service
.
platform
.
device
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.makeit.common.dto.BaseIdDTO
;
import
com.makeit.common.dto.BaseIdDTO
;
...
@@ -92,4 +93,6 @@ public interface PlatDeviceService extends IService<PlatDevice> {
...
@@ -92,4 +93,6 @@ public interface PlatDeviceService extends IService<PlatDevice> {
PlatAlarmCallDeviceVO
callingDevice
(
PlatCallingDeviceDTO
dto
);
PlatAlarmCallDeviceVO
callingDevice
(
PlatCallingDeviceDTO
dto
);
void
devicePushLog
(
MultipartFile
multipartFile
,
String
deviceId
)
throws
IOException
;
void
devicePushLog
(
MultipartFile
multipartFile
,
String
deviceId
)
throws
IOException
;
void
receiveIotProperties
(
String
deviceId
,
JSONObject
iotProperties
);
}
}
server-service/src/main/java/com/makeit/service/platform/device/impl/PlatDeviceServiceImpl.java
View file @
3017be2f
...
@@ -5,6 +5,7 @@ import cn.hutool.core.date.DatePattern;
...
@@ -5,6 +5,7 @@ import cn.hutool.core.date.DatePattern;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.crypto.SecureUtil
;
import
cn.hutool.crypto.SecureUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper
;
import
com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper
;
...
@@ -909,4 +910,57 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
...
@@ -909,4 +910,57 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
platDeviceLog
.
setFileName
(
name
);
platDeviceLog
.
setFileName
(
name
);
platDeviceLogService
.
save
(
platDeviceLog
);
platDeviceLogService
.
save
(
platDeviceLog
);
}
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
receiveIotProperties
(
String
deviceId
,
JSONObject
iotProperties
)
{
PlatDeviceOther
deviceOther
=
platDeviceOtherService
.
getOne
(
new
QueryWrapper
<
PlatDeviceOther
>().
lambda
()
.
eq
(
PlatDeviceOther:
:
getOriDeviceId
,
deviceId
)
.
last
(
"limit 1"
));
if
(
deviceOther
==
null
)
{
log
.
warn
(
"iot修改属性回复,设备其他信息不存在,设备id:{}"
,
deviceId
);
return
;
}
PlatDeviceBaseAttrDTO
platDeviceBaseAttrDTO
=
JSON
.
parseObject
(
deviceOther
.
getAttribute
(),
PlatDeviceBaseAttrDTO
.
class
);
if
(
platDeviceBaseAttrDTO
==
null
)
{
platDeviceBaseAttrDTO
=
new
PlatDeviceBaseAttrDTO
();
}
PlatDeviceBaseAttrDTO
iotAttr
=
iotProperties
.
toJavaObject
(
PlatDeviceBaseAttrDTO
.
class
);
if
(!
Objects
.
equals
(
platDeviceBaseAttrDTO
.
getRadarMode
(),
iotAttr
.
getRadarMode
()))
{
platDeviceBaseAttrDTO
.
setRadarMode
(
iotAttr
.
getRadarMode
());
}
if
(!
Objects
.
equals
(
platDeviceBaseAttrDTO
.
getRadarMount
(),
iotAttr
.
getRadarMount
()))
{
platDeviceBaseAttrDTO
.
setRadarMount
(
iotAttr
.
getRadarMount
());
}
if
(!
Objects
.
equals
(
platDeviceBaseAttrDTO
.
getRadarHight
(),
iotAttr
.
getRadarHight
()))
{
platDeviceBaseAttrDTO
.
setRadarHight
(
iotAttr
.
getRadarHight
());
}
if
(!
Objects
.
equals
(
platDeviceBaseAttrDTO
.
getRadarDelay
(),
iotAttr
.
getRadarDelay
()))
{
platDeviceBaseAttrDTO
.
setRadarDelay
(
iotAttr
.
getRadarDelay
());
}
PlatDeviceBaseAttrDTO
.
DeviceAttrRange
radarDistance
=
platDeviceBaseAttrDTO
.
getRadarDistance
();
if
(!
Objects
.
equals
(
radarDistance
,
iotAttr
.
getRadarDistance
()))
{
if
(
radarDistance
!=
null
&&
radarDistance
.
getMax
()
!=
null
&&
radarDistance
.
getMin
()
!=
null
)
{
platDeviceBaseAttrDTO
.
setRadarDistance
(
iotAttr
.
getRadarDistance
());
}
}
PlatDeviceBaseAttrDTO
.
DeviceAttrRange
radarAngle
=
platDeviceBaseAttrDTO
.
getRadarAngle
();
if
(!
Objects
.
equals
(
radarAngle
,
iotAttr
.
getRadarAngle
()))
{
if
(
radarAngle
!=
null
&&
radarAngle
.
getMax
()
!=
null
&&
radarAngle
.
getMin
()
!=
null
)
{
platDeviceBaseAttrDTO
.
setRadarAngle
(
iotAttr
.
getRadarAngle
());
}
}
String
attr
=
JSON
.
toJSONString
(
platDeviceBaseAttrDTO
);
platDeviceOtherService
.
update
(
new
UpdateWrapper
<
PlatDeviceOther
>().
lambda
()
.
set
(
PlatDeviceOther:
:
getAttribute
,
attr
)
.
eq
(
PlatDeviceOther:
:
getOriDeviceId
,
deviceId
));
if
(
platDeviceBaseAttrDTO
.
getRadarMount
()
!=
null
)
{
List
<
PlatDevice
>
platDeviceList
=
list
(
new
QueryWrapper
<
PlatDevice
>().
lambda
().
eq
(
PlatDevice:
:
getOriDeviceId
,
deviceId
));
//更新区域设置设备安装方式
platRegionSettingService
.
update
(
new
UpdateWrapper
<
PlatRegionSetting
>().
lambda
()
.
set
(
PlatRegionSetting:
:
getInstallType
,
platDeviceBaseAttrDTO
.
getRadarMount
())
.
in
(
CollectionUtils
.
isNotEmpty
(
platDeviceList
),
PlatRegionSetting:
:
getDeviceId
,
StreamUtil
.
map
(
platDeviceList
,
BaseEntity:
:
getId
)));
}
}
}
}
server-web/src/main/java/com/makeit/mqtt/PushCallback.java
View file @
3017be2f
...
@@ -18,6 +18,7 @@ import com.makeit.service.platform.device.PlatDeviceService;
...
@@ -18,6 +18,7 @@ import com.makeit.service.platform.device.PlatDeviceService;
import
com.makeit.service.saas.SaasSleepAnalysisModelService
;
import
com.makeit.service.saas.SaasSleepAnalysisModelService
;
import
com.makeit.utils.AlarmConfigCacheUtil
;
import
com.makeit.utils.AlarmConfigCacheUtil
;
import
com.makeit.utils.DeviceCacheUtil
;
import
com.makeit.utils.DeviceCacheUtil
;
import
com.makeit.utils.redis.RedisUtil
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.eclipse.paho.client.mqttv3.IMqttDeliveryToken
;
import
org.eclipse.paho.client.mqttv3.IMqttDeliveryToken
;
import
org.eclipse.paho.client.mqttv3.MqttCallback
;
import
org.eclipse.paho.client.mqttv3.MqttCallback
;
...
@@ -53,8 +54,14 @@ public class PushCallback implements MqttCallback {
...
@@ -53,8 +54,14 @@ public class PushCallback implements MqttCallback {
public
static
final
String
DEVICE_SPACE_TEMP_DATA
=
"device:space:tempData:"
;
public
static
final
String
DEVICE_SPACE_TEMP_DATA
=
"device:space:tempData:"
;
public
static
final
String
DEVICE_FALL_TEMP_DATA
=
"device:fall:tempData:"
;
public
static
final
String
DEVICE_FALL_TEMP_DATA
=
"device:fall:tempData:"
;
public
static
final
String
DEVICE_OFF_BED_TEMP_DATA
=
"device:off_bed:tempData:"
;
public
static
final
String
DEVICE_OFF_BED_TEMP_DATA
=
"device:off_bed:tempData:"
;
public
static
final
String
DEVICE_WRITE_PROPERTY_KEY
=
"device:write_property:"
;
public
static
final
String
REPORT_PROPERTY
=
"REPORT_PROPERTY"
;
public
static
final
String
REPORT_PROPERTY
=
"REPORT_PROPERTY"
;
public
static
final
String
WRITE_PROPERTY
=
"WRITE_PROPERTY"
;
public
static
final
String
WRITE_PROPERTY_REPLY
=
"WRITE_PROPERTY_REPLY"
;
@Autowired
@Autowired
private
MqttConfig
mqttConfig
;
private
MqttConfig
mqttConfig
;
...
@@ -97,6 +104,7 @@ public class PushCallback implements MqttCallback {
...
@@ -97,6 +104,7 @@ public class PushCallback implements MqttCallback {
DeviceInfo
device
=
JSON
.
parseObject
(
payload
,
DeviceInfo
.
class
);
DeviceInfo
device
=
JSON
.
parseObject
(
payload
,
DeviceInfo
.
class
);
// todo
// todo
syncProperties
(
device
);
checkAlarm
(
device
);
checkAlarm
(
device
);
}
}
...
@@ -107,6 +115,32 @@ public class PushCallback implements MqttCallback {
...
@@ -107,6 +115,32 @@ public class PushCallback implements MqttCallback {
}
}
/**
/**
* IOT端设备属性修改后同步
* @param device
*/
@TenantIdIgnore
@Async
public
void
syncProperties
(
DeviceInfo
device
)
{
if
(!(
WRITE_PROPERTY
.
equals
(
device
.
getMessageType
())
||
WRITE_PROPERTY_REPLY
.
equals
(
device
.
getMessageType
())))
{
return
;
}
// 记录修改的属性
String
key
=
DEVICE_WRITE_PROPERTY_KEY
+
device
.
getDeviceId
();
if
(
WRITE_PROPERTY
.
equals
(
device
.
getMessageType
()))
{
RedisUtil
.
set
(
key
,
device
.
getProperties
(),
10
,
TimeUnit
.
SECONDS
);
}
// 收到修改属性回复
if
(
WRITE_PROPERTY_REPLY
.
equals
(
device
.
getMessageType
()))
{
JSONObject
properties
=
RedisUtil
.
get
(
key
);
if
(
properties
==
null
)
{
return
;
}
platDeviceService
.
receiveIotProperties
(
device
.
getDeviceId
(),
properties
);
RedisUtil
.
delete
(
key
);
}
}
/**
* 触发告警耗时 3.07s
* 触发告警耗时 3.07s
* 未触发告警耗时 0.08s
* 未触发告警耗时 0.08s
* @param device
* @param device
...
@@ -233,6 +267,5 @@ public class PushCallback implements MqttCallback {
...
@@ -233,6 +267,5 @@ public class PushCallback implements MqttCallback {
return
s
.
longValue
();
return
s
.
longValue
();
}
}
}
}
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