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
a821879d
authored
Dec 15, 2023
by
罗志长
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
fix: iot属性同步
parent
6d3dacde
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
58 additions
and
25 deletions
server-common/src/main/java/com/makeit/module/iot/vo/DeviceInfo.java
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-common/src/main/java/com/makeit/module/iot/vo/DeviceInfo.java
View file @
a821879d
...
...
@@ -14,6 +14,8 @@ public class DeviceInfo {
private
Long
timestamp
;
private
String
messageId
;
private
String
messageType
;
private
HeaderInfo
headers
;
...
...
server-service/src/main/java/com/makeit/service/platform/device/PlatDeviceService.java
View file @
a821879d
package
com
.
makeit
.
service
.
platform
.
device
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.makeit.common.dto.BaseIdDTO
;
...
...
@@ -93,5 +94,5 @@ public interface PlatDeviceService extends IService<PlatDevice> {
void
devicePushLog
(
MultipartFile
multipartFile
,
String
deviceId
)
throws
IOException
;
void
syncIotProperties
(
String
deviceId
);
void
syncIotProperties
(
String
deviceId
,
JSONObject
iotProperties
);
}
server-service/src/main/java/com/makeit/service/platform/device/impl/PlatDeviceServiceImpl.java
View file @
a821879d
...
...
@@ -382,7 +382,6 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
for
(
PlatDeviceOther
platDeviceOther
:
platDeviceOtherList
)
{
BeanUtils
.
copyProperties
(
dto
,
platDeviceOther
,
"id"
);
platDeviceOther
.
setDeviceId
(
id
);
platDeviceOther
.
setAttribute
(
JSON
.
toJSONString
(
getDeviceBaseAttrDTO
(
db
)));
platDeviceOther
.
setOriDeviceId
(
db
.
getOriDeviceId
());
platDeviceOtherService
.
saveOrUpdate
(
platDeviceOther
);
}
...
...
@@ -766,6 +765,7 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
platDeviceOther
=
new
PlatDeviceOther
();
platDeviceOther
.
setDeviceId
(
platDevice
.
getId
());
platDeviceOther
.
setOriDeviceId
(
platDevice
.
getOriDeviceId
());
platDeviceOther
.
setAttribute
(
JSON
.
toJSONString
(
getDeviceBaseAttrDTO
(
platDevice
)));
platDeviceOther
.
setTenantId
(
platDevice
.
getTenantId
());
platDeviceOtherService
.
save
(
platDeviceOther
);
}
...
...
@@ -942,23 +942,53 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
@Override
@TenantIdIgnore
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
syncIotProperties
(
String
deviceId
)
{
PlatDevice
device
=
getOne
(
new
QueryWrapper
<
PlatDevice
>().
lambda
()
.
eq
(
PlatDevice:
:
getOriDeviceId
,
deviceId
));
if
(
device
==
null
)
{
log
.
warn
(
"iot属性同步,设备不存在,设备id:{}"
,
deviceId
);
return
;
}
PlatDeviceBaseAttrDTO
platDeviceBaseAttrDTO
=
getDeviceBaseAttrDTO
(
device
);
String
attr
=
JSON
.
toJSONString
(
platDeviceBaseAttrDTO
);
platDeviceOtherService
.
update
(
new
UpdateWrapper
<
PlatDeviceOther
>().
lambda
()
.
set
(
PlatDeviceOther:
:
getAttribute
,
attr
)
public
void
syncIotProperties
(
String
deviceId
,
JSONObject
iotProperties
)
{
PlatDeviceBaseAttrDTO
iotAttr
=
iotProperties
.
toJavaObject
(
PlatDeviceBaseAttrDTO
.
class
);
List
<
PlatDeviceOther
>
deviceOthers
=
platDeviceOtherService
.
list
(
new
QueryWrapper
<
PlatDeviceOther
>().
lambda
()
.
eq
(
PlatDeviceOther:
:
getOriDeviceId
,
deviceId
));
if
(
platDeviceBaseAttrDTO
.
getRadarMount
()
!=
null
)
{
Integer
radarMount
=
null
;
for
(
PlatDeviceOther
deviceOther
:
deviceOthers
)
{
PlatDeviceBaseAttrDTO
platDeviceBaseAttrDTO
=
JSON
.
parseObject
(
deviceOther
.
getAttribute
(),
PlatDeviceBaseAttrDTO
.
class
);
if
(
platDeviceBaseAttrDTO
==
null
)
{
platDeviceBaseAttrDTO
=
new
PlatDeviceBaseAttrDTO
();
}
if
(
iotAttr
.
getRadarMode
()
!=
null
&&
!
Objects
.
equals
(
platDeviceBaseAttrDTO
.
getRadarMode
(),
iotAttr
.
getRadarMode
()))
{
platDeviceBaseAttrDTO
.
setRadarMode
(
iotAttr
.
getRadarMode
());
}
if
(
iotAttr
.
getRadarMount
()
!=
null
&&
!
Objects
.
equals
(
platDeviceBaseAttrDTO
.
getRadarMount
(),
iotAttr
.
getRadarMount
()))
{
platDeviceBaseAttrDTO
.
setRadarMount
(
iotAttr
.
getRadarMount
());
radarMount
=
platDeviceBaseAttrDTO
.
getRadarMount
();
}
if
(
iotAttr
.
getRadarHight
()
!=
null
&&
!
Objects
.
equals
(
platDeviceBaseAttrDTO
.
getRadarHight
(),
iotAttr
.
getRadarHight
()))
{
platDeviceBaseAttrDTO
.
setRadarHight
(
iotAttr
.
getRadarHight
());
}
if
(
iotAttr
.
getRadarDelay
()
!=
null
&&
!
Objects
.
equals
(
platDeviceBaseAttrDTO
.
getRadarDelay
(),
iotAttr
.
getRadarDelay
()))
{
platDeviceBaseAttrDTO
.
setRadarDelay
(
iotAttr
.
getRadarDelay
());
}
PlatDeviceBaseAttrDTO
.
DeviceAttrRange
radarDistance
=
platDeviceBaseAttrDTO
.
getRadarDistance
();
if
(
iotAttr
.
getRadarDistance
()
!=
null
&&
!
Objects
.
equals
(
radarDistance
,
iotAttr
.
getRadarDistance
()))
{
platDeviceBaseAttrDTO
.
setRadarDistance
(
iotAttr
.
getRadarDistance
());
}
PlatDeviceBaseAttrDTO
.
DeviceAttrRange
radarAngle
=
platDeviceBaseAttrDTO
.
getRadarAngle
();
if
(
iotAttr
.
getRadarAngle
()
!=
null
&&
!
Objects
.
equals
(
radarAngle
,
iotAttr
.
getRadarAngle
()))
{
platDeviceBaseAttrDTO
.
setRadarAngle
(
iotAttr
.
getRadarAngle
());
}
if
(
iotAttr
.
getRadarSence
()
!=
null
&&
!
Objects
.
equals
(
platDeviceBaseAttrDTO
.
getRadarSence
(),
iotAttr
.
getRadarSence
()))
{
platDeviceBaseAttrDTO
.
setRadarSence
(
iotAttr
.
getRadarSence
());
}
if
(
iotAttr
.
getRadarSPL
()
!=
null
&&
!
Objects
.
equals
(
platDeviceBaseAttrDTO
.
getRadarSPL
(),
iotAttr
.
getRadarSPL
()))
{
platDeviceBaseAttrDTO
.
setRadarSPL
(
iotAttr
.
getRadarSPL
());
}
String
attr
=
JSON
.
toJSONString
(
platDeviceBaseAttrDTO
);
platDeviceOtherService
.
update
(
new
UpdateWrapper
<
PlatDeviceOther
>().
lambda
()
.
set
(
PlatDeviceOther:
:
getAttribute
,
attr
)
.
eq
(
PlatDeviceOther:
:
getId
,
deviceOther
.
getId
()));
}
if
(
radarMount
!=
null
)
{
List
<
PlatDevice
>
platDeviceList
=
list
(
new
QueryWrapper
<
PlatDevice
>().
lambda
().
eq
(
PlatDevice:
:
getOriDeviceId
,
deviceId
));
//更新区域设置设备安装方式
platRegionSettingService
.
update
(
new
UpdateWrapper
<
PlatRegionSetting
>().
lambda
()
.
set
(
PlatRegionSetting:
:
getInstallType
,
platDeviceBaseAttrDTO
.
getRadarMount
()
)
.
set
(
PlatRegionSetting:
:
getInstallType
,
radarMount
)
.
in
(
CollectionUtils
.
isNotEmpty
(
platDeviceList
),
PlatRegionSetting:
:
getDeviceId
,
StreamUtil
.
map
(
platDeviceList
,
BaseEntity:
:
getId
)));
}
}
...
...
server-web/src/main/java/com/makeit/mqtt/PushCallback.java
View file @
a821879d
...
...
@@ -125,26 +125,26 @@ public class PushCallback implements MqttCallback {
return
;
}
// 记录修改的属性
String
key
=
DEVICE_WRITE_PROPERTY_KEY
+
device
.
getDevic
eId
();
String
redisKey
=
DEVICE_WRITE_PROPERTY_KEY
+
device
.
getMessag
eId
();
if
(
WRITE_PROPERTY
.
equals
(
device
.
getMessageType
()))
{
JSONObject
properties
=
device
.
getProperties
();
String
value
=
properties
.
keySet
().
stream
().
findFirst
().
orElse
(
"value"
);
RedisUtil
.
set
(
key
,
value
,
10
,
TimeUnit
.
SECONDS
);
RedisUtil
.
set
(
redisKey
,
properties
,
10
,
TimeUnit
.
SECONDS
);
}
// 收到修改属性回复
if
(
WRITE_PROPERTY_REPLY
.
equals
(
device
.
getMessageType
()))
{
String
value
=
RedisUtil
.
get
(
k
ey
);
if
(
StringUtils
.
isBlank
(
value
)
)
{
JSONObject
properties
=
RedisUtil
.
get
(
redisK
ey
);
if
(
properties
==
null
)
{
return
;
}
JSONObject
properties
=
device
.
getProperties
();
int
success
=
properties
.
getIntValue
(
value
);
if
(
success
!=
0
)
{
String
key
=
properties
.
keySet
().
stream
().
findFirst
().
orElse
(
"key"
);
JSONObject
replayProperties
=
device
.
getProperties
();
String
success
=
replayProperties
.
getString
(
key
);
if
(!
"0"
.
equals
(
success
))
{
return
;
}
CompletableFuture
.
runAsync
(()
->
{
platDeviceService
.
syncIotProperties
(
device
.
getDeviceId
());
RedisUtil
.
delete
(
k
ey
);
platDeviceService
.
syncIotProperties
(
device
.
getDeviceId
()
,
properties
);
RedisUtil
.
delete
(
redisK
ey
);
});
// 要加线程池
}
}
...
...
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