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
d29fc189
authored
Dec 21, 2023
by
huangjy
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merge remote-tracking branch 'origin/dev' into dev
parents
89cc73e3
b1a0a64a
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
84 additions
and
16 deletions
server-module/src/main/java/com/makeit/module/controller/space/PlatSpaceController.java
server-service/src/main/java/com/makeit/service/platform/device/impl/PlatDeviceServiceImpl.java
server-service/src/main/java/com/makeit/service/platform/space/PlatSpaceService.java
server-service/src/main/java/com/makeit/service/platform/space/impl/PlatSpaceServiceImpl.java
server-module/src/main/java/com/makeit/module/controller/space/PlatSpaceController.java
View file @
d29fc189
...
...
@@ -123,4 +123,11 @@ public class PlatSpaceController {
return
ApiResponseUtils
.
success
(
data
);
}
@ApiOperation
(
"修复空间层级数据"
)
@GetMapping
(
"fixPlacePath"
)
public
ApiResponseEntity
<
String
>
fixPlacePath
(
@RequestParam
String
spaceId
)
{
spaceService
.
fixPlacePath
(
spaceId
);
return
ApiResponseUtils
.
success
();
}
}
server-service/src/main/java/com/makeit/service/platform/device/impl/PlatDeviceServiceImpl.java
View file @
d29fc189
...
...
@@ -3,6 +3,7 @@ package com.makeit.service.platform.device.impl;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.date.DatePattern
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.thread.ThreadUtil
;
import
cn.hutool.crypto.SecureUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
...
...
@@ -682,21 +683,34 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
String
deviceId
=
dto
.
getDeviceId
();
UserServerInfo
usrServerInfo
=
dto
.
getUsrServerInfo
();
log
.
info
(
"写入设备属性请求参数:{}"
,
JSON
.
toJSONString
(
dto
));
String
value
=
JSON
.
toJSONString
(
usrServerInfo
);
boolean
needWrite
=
true
;
List
<
PlatDeviceOther
>
platDeviceOtherList
=
platDeviceOtherService
.
list
(
new
QueryWrapper
<
PlatDeviceOther
>().
lambda
()
.
eq
(
PlatDeviceOther:
:
getOriDeviceId
,
deviceId
));
if
(
CollectionUtils
.
isNotEmpty
(
platDeviceOtherList
))
{
PlatDeviceOther
platDeviceOther
=
platDeviceOtherList
.
get
(
0
);
UserServerInfo
existInfo
=
new
UserServerInfo
();
existInfo
.
setAddr
(
platDeviceOther
.
getProtocolAddress
());
existInfo
.
setPort
(
platDeviceOther
.
getProtocolPort
()
!=
null
?
Integer
.
valueOf
(
platDeviceOther
.
getProtocolPort
())
:
null
);
existInfo
.
setUsername
(
platDeviceOther
.
getProtocolAccount
());
existInfo
.
setPassword
(
platDeviceOther
.
getProtocolPassword
());
String
jsonString
=
JSON
.
toJSONString
(
existInfo
);
needWrite
=
!
value
.
equals
(
jsonString
);
}
if
(
needWrite
)
{
ThreadUtil
.
sleep
(
200
);
// 受限于设备不支持同时写入 稍微延迟一点执行(前端先修改属性再修改网络信息)
Map
<
String
,
Object
>
map
=
Maps
.
newHashMap
();
map
.
put
(
"usrServerInfo"
,
JSON
.
toJSONString
(
usrServerInfo
)
);
/*
String result = devicePropertiesOperateService.deviceWriteAttr(deviceId, map);
map
.
put
(
"usrServerInfo"
,
value
);
String
result
=
devicePropertiesOperateService
.
deviceWriteAttr
(
deviceId
,
map
);
if
(
StringUtils
.
isNotEmpty
(
result
))
{
throw
new
RuntimeException
(
"设备写入失败:"
+
result
);
}*/
List
<
PlatDeviceOther
>
platDeviceOtherList
=
platDeviceOtherService
.
list
(
new
QueryWrapper
<
PlatDeviceOther
>().
lambda
()
.
eq
(
PlatDeviceOther:
:
getOriDeviceId
,
deviceId
));
}
}
for
(
PlatDeviceOther
platDeviceOther
:
platDeviceOtherList
)
{
platDeviceOther
.
setProtocolAccount
(
usrServerInfo
.
getUsername
());
platDeviceOther
.
setProtocolPassword
(
usrServerInfo
.
getPassword
());
platDeviceOther
.
setProtocolAddress
(
usrServerInfo
.
getAddr
());
platDeviceOther
.
setProtocolPort
(
usrServerInfo
.
getPort
()
==
null
?
""
:
usrServerInfo
.
getPort
().
toString
());
platDeviceOther
.
setSecureId
(
usrServerInfo
.
getSecureId
());
platDeviceOther
.
setSecureKey
(
usrServerInfo
.
getSecureKey
());
platDeviceOtherService
.
updateById
(
platDeviceOther
);
}
}
...
...
server-service/src/main/java/com/makeit/service/platform/space/PlatSpaceService.java
View file @
d29fc189
...
...
@@ -96,4 +96,6 @@ public interface PlatSpaceService extends IService<PlatSpace> {
List
<
PlatSpace
>
listChildAndOrgIds
(
List
<
String
>
spaceIds
,
List
<
String
>
orgIds
);
void
fixPlacePath
(
String
spaceId
);
}
server-service/src/main/java/com/makeit/service/platform/space/impl/PlatSpaceServiceImpl.java
View file @
d29fc189
...
...
@@ -70,7 +70,7 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
private
void
check
(
PlatSpaceAddDTO
dto
)
{
if
(
StrUtil
.
isNotBlank
(
dto
.
getParentPath
())
&&
dto
.
getParentPath
().
split
(
","
).
length
>
=
4
)
{
&&
dto
.
getParentPath
().
split
(
","
).
length
>
4
)
{
throw
new
BusinessException
(
CodeMessageEnum
.
PLATFORM_ERROR_SPACE_OVER_LEVEL
);
}
...
...
@@ -224,8 +224,8 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
private
void
checkAndUpdateSonSpace
(
PlatSpace
space
)
{
String
parentPath
=
space
.
getParentPath
();
int
level
=
StrUtil
.
isBlank
(
parentPath
)
?
0
:
parentPath
.
split
(
","
).
length
;
if
(
level
>
3
)
{
int
level
=
StrUtil
.
isBlank
(
parentPath
)
?
1
:
parentPath
.
split
(
","
).
length
+
1
;
if
(
level
>
4
)
{
throw
new
BusinessException
(
CodeMessageEnum
.
PLATFORM_ERROR_SPACE_OVER_LEVEL
);
}
String
spaceId
=
space
.
getId
();
...
...
@@ -238,16 +238,14 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
if
(
StrUtil
.
isBlank
(
s
.
getParentPath
()))
{
return
;
}
List
<
String
>
parentSpaceIds
=
Lists
.
newArrayList
(
s
.
getParentPath
().
split
(
","
));
parentSpaceIds
.
remove
(
space
.
getId
());
if
(
parentSpaceIds
.
size
()
>
maxLength
.
get
())
{
maxLength
.
set
(
parentSpaceIds
.
size
());
int
maxSpacePath
=
getMaxSpacePath
(
s
.
getParentPath
(),
spaceId
);
if
(
maxSpacePath
>
maxLength
.
get
())
{
maxLength
.
set
(
maxSpacePath
);
}
maxLength
.
set
(
parentSpaceIds
.
size
());
});
sonLevel
=
maxLength
.
get
();
}
if
(
level
+
sonLevel
>
3
)
{
if
(
level
+
sonLevel
>
4
)
{
throw
new
BusinessException
(
CodeMessageEnum
.
PLATFORM_ERROR_SPACE_OVER_LEVEL
);
}
// 更新下级空间的parentPath
...
...
@@ -268,6 +266,12 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
}
private
Integer
getMaxSpacePath
(
String
path
,
String
splitSpace
)
{
List
<
String
>
pathList
=
Arrays
.
asList
(
path
.
split
(
","
));
return
pathList
.
size
()
-
pathList
.
indexOf
(
splitSpace
);
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
del
(
String
id
)
{
...
...
@@ -1093,7 +1097,48 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
return
data
;
}
@Override
public
void
fixPlacePath
(
String
spaceId
)
{
PlatSpace
space
=
getById
(
spaceId
);
if
(
space
==
null
||
StrUtil
.
isNotBlank
(
space
.
getParentId
()))
{
return
;
}
List
<
PlatSpace
>
allList
=
new
ArrayList
<>();
recursionSetParentPath
(
spaceId
,
space
.
getParentPath
(),
allList
);
if
(
CollUtil
.
isNotEmpty
(
allList
))
{
updateBatchById
(
allList
);
}
// fixAllSpacePath();
}
private
void
fixAllSpacePath
()
{
List
<
PlatSpace
>
allData
=
list
();
List
<
PlatSpace
>
firstSpaceList
=
allData
.
stream
().
filter
(
f
->
StrUtil
.
isBlank
(
f
.
getParentId
())
&&
StrUtil
.
isBlank
(
f
.
getParentPath
())).
collect
(
Collectors
.
toList
());
if
(
CollUtil
.
isEmpty
(
firstSpaceList
))
{
return
;
}
firstSpaceList
.
forEach
(
f
->
{
List
<
PlatSpace
>
allList
=
new
ArrayList
<>();
recursionSetParentPath
(
f
.
getId
(),
f
.
getParentPath
(),
allList
);
if
(
CollUtil
.
isNotEmpty
(
allList
))
{
updateBatchById
(
allList
);
}
});
}
private
void
recursionSetParentPath
(
String
spaceId
,
String
parentPath
,
List
<
PlatSpace
>
allList
)
{
List
<
PlatSpace
>
firstSonList
=
list
(
Wrappers
.<
PlatSpace
>
lambdaQuery
().
eq
(
PlatSpace:
:
getParentId
,
spaceId
));
if
(
CollUtil
.
isEmpty
(
firstSonList
))
{
return
;
}
firstSonList
.
forEach
(
s
->
{
s
.
setParentPath
(
StrUtil
.
isNotBlank
(
parentPath
)
?
parentPath
+
","
+
s
.
getParentId
()
:
spaceId
);
allList
.
add
(
s
);
recursionSetParentPath
(
s
.
getId
(),
s
.
getParentPath
(),
allList
);
});
}
}
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