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
97f624fa
authored
Feb 26, 2024
by
罗志长
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
feat: 进入设备详情获取属性
parent
02be4f91
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
80 additions
and
22 deletions
iot-platforn-server.iml
server-common/src/main/java/com/makeit/module/iot/service/IotDevicePropertiesOperateService.java
server-service/src/main/java/com/makeit/service/platform/device/impl/PlatDeviceServiceImpl.java
iot-platforn-server.iml
deleted
100644 → 0
View file @
02be4f91
<?xml version="1.0" encoding="UTF-8"?>
<module
org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule=
"true"
type=
"JAVA_MODULE"
version=
"4"
>
<component
name=
"NewModuleRootManager"
LANGUAGE_LEVEL=
"JDK_1_8"
>
<output
url=
"file://$MODULE_DIR$/target/classes"
/>
<output-test
url=
"file://$MODULE_DIR$/target/test-classes"
/>
<content
url=
"file://$MODULE_DIR$"
>
<excludeFolder
url=
"file://$MODULE_DIR$/target"
/>
</content>
<orderEntry
type=
"inheritedJdk"
/>
<orderEntry
type=
"sourceFolder"
forTests=
"false"
/>
</component>
</module>
\ No newline at end of file
server-common/src/main/java/com/makeit/module/iot/service/IotDevicePropertiesOperateService.java
View file @
97f624fa
package
com
.
makeit
.
module
.
iot
.
service
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Maps
;
import
com.makeit.module.iot.dto.UserServerInfo
;
...
...
@@ -11,13 +12,16 @@ import com.makeit.module.iot.vo.DeviceProperties;
import
com.makeit.module.iot.vo.ResponseMessage
;
import
com.makeit.utils.data.convert.JsonUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.stereotype.Component
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
/**
* iot产品设备相关接口
...
...
@@ -45,6 +49,30 @@ public class IotDevicePropertiesOperateService extends IotCommonService {
return
null
;
}
public
List
<
DeviceProperties
>
deviceRead
(
String
deviceId
,
List
<
String
>
propertiesName
)
{
String
url
=
iotUrl
+
DEVICE_PREFIX_URL
+
deviceId
+
"/properties/_read"
;
if
(
CollectionUtils
.
isEmpty
(
propertiesName
))
{
return
new
ArrayList
<>();
}
String
body
=
JsonUtil
.
toJson
(
propertiesName
);
HttpRequest
request
=
buildRequest
(
url
,
body
);
try
{
ResponseMessage
responseMessage
=
sendPost
(
url
,
request
);
if
(
responseMessage
.
getStatus
()
==
200
)
{
JSONObject
jsonObject
=
JSON
.
parseObject
(
responseMessage
.
getResult
().
toString
());
return
jsonObject
.
keySet
().
stream
().
map
(
key
->
{
DeviceProperties
properties
=
new
DeviceProperties
();
properties
.
setProperty
(
key
);
properties
.
setValue
(
jsonObject
.
get
(
key
));
return
properties
;
}).
collect
(
Collectors
.
toList
());
}
}
catch
(
IOException
e
)
{
log
.
error
(
"调用:{}接口异常:{}"
,
url
,
e
.
getMessage
());
}
return
new
ArrayList
<>();
}
/**
* 把设备写入属性
*/
...
...
server-service/src/main/java/com/makeit/service/platform/device/impl/PlatDeviceServiceImpl.java
View file @
97f624fa
...
...
@@ -394,8 +394,21 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
PlatDeviceOther
other
=
platDeviceOtherService
.
getOne
(
new
QueryWrapper
<
PlatDeviceOther
>().
lambda
()
.
eq
(
PlatDeviceOther:
:
getDeviceId
,
id
).
last
(
"limit 1"
));
PlatDeviceBaseAttrDTO
iotAttr
=
getDeviceBaseAttrDTO
(
db
);
if
(
other
!=
null
)
{
String
oldAttr
=
other
.
getAttribute
();
if
(
StringUtils
.
isBlank
(
other
.
getAttribute
()))
{
PlatDeviceBaseAttrDTO
defaultAttr
=
getDefaultAttr
(
db
);
String
attr
=
defaultAttr
!=
null
?
JSON
.
toJSONString
(
defaultAttr
)
:
null
;
other
.
setAttribute
(
attr
);
}
BeanUtils
.
copyProperties
(
other
,
vo
);
String
attr
=
getAfterComparisonAttr
(
iotAttr
,
other
.
getAttribute
());
vo
.
setAttribute
(
attr
);
if
(!
StringUtils
.
equals
(
oldAttr
,
attr
))
{
other
.
setAttribute
(
attr
);
platDeviceOtherService
.
updateById
(
other
);
}
}
vo
.
setId
(
db
.
getId
());
...
...
@@ -414,6 +427,40 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
}
private
String
getAfterComparisonAttr
(
PlatDeviceBaseAttrDTO
iotAttr
,
String
localAttr
)
{
PlatDeviceBaseAttrDTO
platDeviceBaseAttrDTO
=
JSON
.
parseObject
(
localAttr
,
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
());
}
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
());
}
return
JSON
.
toJSONString
(
platDeviceBaseAttrDTO
);
}
@Override
public
PlatDeviceViewVO
viewByDeviceId
(
String
id
)
{
PlatDevice
platDevice
=
getOne
(
new
QueryWrapper
<
PlatDevice
>().
lambda
().
eq
(
PlatDevice:
:
getOriDeviceId
,
id
)
...
...
@@ -1179,22 +1226,18 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
if
(!(
PlatDeviceEnum
.
CategoryEnum
.
FALL
.
getValue
().
equals
(
category
)
||
PlatDeviceEnum
.
CategoryEnum
.
SPACE
.
getValue
().
equals
(
category
)))
{
return
new
PlatDeviceBaseAttrDTO
();
}
String
propertiesName
=
""
;
List
<
String
>
properties
=
null
;
// 跌倒
if
(
PlatDeviceEnum
.
CategoryEnum
.
FALL
.
getValue
().
equals
(
category
))
{
properties
Name
=
"radarMount,radarHight,radarSence,radarSPL"
;
properties
=
Lists
.
newArrayList
(
"radarMount,radarHight,radarSence,radarSPL"
)
;
}
// 空间人体
if
(
PlatDeviceEnum
.
CategoryEnum
.
SPACE
.
getValue
().
equals
(
category
))
{
properties
Name
=
"radarMount,radarMode,radarDistance,radarAngle,radarDelay"
;
properties
=
Lists
.
newArrayList
(
"radarMount,radarMode,radarDistance,radarAngle,radarDelay"
)
;
}
PlatDeviceAttrWechatDTO
dto
=
new
PlatDeviceAttrWechatDTO
();
dto
.
setDeviceId
(
platDevice
.
getOriDeviceId
());
dto
.
setReadProperties
(
propertiesName
);
List
<
DeviceProperties
>
data
=
this
.
readDeviceProperties
(
dto
);
List
<
DeviceProperties
>
data
=
devicePropertiesOperateService
.
deviceRead
(
platDevice
.
getOriDeviceId
(),
properties
);
Map
<
String
,
Object
>
attrMap
=
data
.
stream
().
filter
(
p
->
!
Objects
.
isNull
(
p
.
getValue
())).
collect
(
Collectors
.
toMap
(
DeviceProperties:
:
getProperty
,
DeviceProperties:
:
getValue
));
PlatDeviceBaseAttrDTO
platDeviceBaseAttrDTO
=
JsonUtil
.
mapToBean
(
attrMap
,
PlatDeviceBaseAttrDTO
.
class
);
return
platDeviceBaseAttrDTO
;
return
JsonUtil
.
mapToBean
(
attrMap
,
PlatDeviceBaseAttrDTO
.
class
);
}
@Override
...
...
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