Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
data-server
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
licc
data-server
Commits
af509b2b
Commit
af509b2b
authored
Jun 18, 2021
by
licc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增获取直连树结构
parent
d910a637
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
108 additions
and
3 deletions
+108
-3
UsersMapper.java
...mapper/src/main/java/cn/wisenergy/mapper/UsersMapper.java
+8
-2
UsersMapper.xml
wisenergy-mapper/src/main/resources/mapper/UsersMapper.xml
+11
-0
UserVo.java
...rgy-model/src/main/java/cn/wisenergy/model/vo/UserVo.java
+9
-0
UserService.java
...e/src/main/java/cn/wisenergy/service/app/UserService.java
+7
-0
UserServiceImpl.java
...n/java/cn/wisenergy/service/app/impl/UserServiceImpl.java
+65
-0
UserController.java
...cn/wisenergy/web/admin/controller/app/UserController.java
+7
-0
application.yml
wisenergy-web-admin/src/main/resources/application.yml
+1
-1
No files found.
wisenergy-mapper/src/main/java/cn/wisenergy/mapper/UsersMapper.java
View file @
af509b2b
...
...
@@ -75,12 +75,18 @@ public interface UsersMapper extends BaseMapper<Users> {
* 获取用户 基本数据
*
* @param startNumber 开始编号
* @param endNo 结束编号
* @param endNo
结束编号
* @return 列表
*/
List
<
UserDto
>
getAllUserData
(
@Param
(
"startNo"
)
Integer
startNumber
,
@Param
(
"endNo"
)
Integer
endNo
);
/**
* 获取用户 基本数据
*
* @param list 用户ids
* @return 用户 基本数据列表
*/
List
<
UserVo
>
getUserData
(
@Param
(
"list"
)
List
<
Long
>
list
);
/*************** chenqi****************/
...
...
wisenergy-mapper/src/main/resources/mapper/UsersMapper.xml
View file @
af509b2b
...
...
@@ -243,4 +243,15 @@ GROUP BY user_id
limit #{startNo},#{endNo}
</select>
<select
id=
"getUserData"
resultType=
"cn.wisenergy.model.vo.UserVo"
>
select u.id as userId,u.parent_id as parentId,a.real_name as realName
from users u left join actives a
on u.id=a.user_id
where u.id IN
<foreach
collection=
"list"
index=
"index"
item=
"id"
separator=
","
open=
"("
close=
")"
>
#{id}
</foreach>
order by u.id
</select>
</mapper>
wisenergy-model/src/main/java/cn/wisenergy/model/vo/UserVo.java
View file @
af509b2b
package
cn
.
wisenergy
.
model
.
vo
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
java.util.List
;
/**
* @author 86187
*/
...
...
@@ -12,16 +15,22 @@ public class UserVo {
/**
* 用户id
*/
@ApiModelProperty
(
value
=
"用户id"
,
name
=
"userId"
)
private
Long
userId
;
/**
* 父id
*/
@ApiModelProperty
(
value
=
"父id"
,
name
=
"parentId"
)
private
Integer
parentId
;
/**
* 用户真实名字
*/
@ApiModelProperty
(
value
=
"用户真实名字"
,
name
=
"realName"
)
private
String
realName
;
@ApiModelProperty
(
value
=
"子节点数据"
,
name
=
"childrens"
)
List
<
UserVo
>
children
;
}
wisenergy-service/src/main/java/cn/wisenergy/service/app/UserService.java
View file @
af509b2b
...
...
@@ -41,5 +41,12 @@ public interface UserService {
*/
R
<
UsersInfoDto
>
getByUserInfoById
(
Long
userId
);
/**
* 获取用户直线树结构
* @param userId 用户id
* @return 用户直线树结构
*/
R
<
List
<
UserVo
>>
getLinkTree
(
Long
userId
);
}
wisenergy-service/src/main/java/cn/wisenergy/service/app/impl/UserServiceImpl.java
View file @
af509b2b
package
cn
.
wisenergy
.
service
.
app
.
impl
;
import
cn.wisenergy.common.utils.R
;
import
cn.wisenergy.common.utils.StringUtil
;
import
cn.wisenergy.mapper.*
;
import
cn.wisenergy.model.app.*
;
import
cn.wisenergy.model.dto.UsersInfoDto
;
...
...
@@ -8,6 +9,8 @@ import cn.wisenergy.model.vo.UserVo;
import
cn.wisenergy.service.app.UserService
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
...
...
@@ -94,4 +97,66 @@ public class UserServiceImpl extends ServiceImpl<UsersMapper, Users> implements
return
R
.
ok
(
userDto
);
}
@Override
public
R
<
List
<
UserVo
>>
getLinkTree
(
Long
userId
)
{
if
(
null
==
userId
)
{
return
R
.
error
(
"入参不能为空!"
);
}
List
<
UserVo
>
userVos
=
new
ArrayList
<>();
//获取用户信息
Users
user
=
usersMapper
.
getById
(
userId
);
if
(
null
!=
user
&&
StringUtils
.
isNotBlank
(
user
.
getPath
()))
{
String
path
=
user
.
getPath
();
List
<
Long
>
userIds
=
StringUtil
.
strToLongArray
(
path
);
//获取用户信息列表
List
<
UserVo
>
list
=
usersMapper
.
getUserData
(
userIds
);
//递归生成树结构
if
(
CollectionUtils
.
isNotEmpty
(
list
))
{
userVos
=
getChildren
(
list
);
}
}
return
R
.
ok
(
userVos
);
}
private
List
<
UserVo
>
getChildren
(
List
<
UserVo
>
list
)
{
List
<
UserVo
>
rootList
=
new
ArrayList
<>();
List
<
UserVo
>
childrenList
=
new
ArrayList
<>();
for
(
UserVo
userVo
:
list
)
{
if
(
userVo
.
getParentId
()
==
0
)
{
rootList
.
add
(
userVo
);
}
else
{
childrenList
.
add
(
userVo
);
}
}
//遍历子数组,设置子树
for
(
UserVo
userVo
:
rootList
)
{
List
<
UserVo
>
children
=
setChildren
(
userVo
.
getUserId
(),
childrenList
);
userVo
.
setChildren
(
children
);
}
return
rootList
;
}
private
List
<
UserVo
>
setChildren
(
Long
userId
,
List
<
UserVo
>
list
)
{
List
<
UserVo
>
children
=
new
ArrayList
<>();
for
(
UserVo
userVo
:
list
)
{
Long
parentId
=
userVo
.
getParentId
().
longValue
();
if
(
userId
.
equals
(
parentId
))
{
children
.
add
(
userVo
);
}
}
for
(
int
i
=
0
;
i
<
children
.
size
();
i
++)
{
Long
autoId
=
children
.
get
(
i
).
getUserId
();
List
<
UserVo
>
childrenList
=
setChildren
(
autoId
,
list
);
children
.
get
(
i
).
setChildren
(
childrenList
);
}
return
children
;
}
}
wisenergy-web-admin/src/main/java/cn/wisenergy/web/admin/controller/app/UserController.java
View file @
af509b2b
...
...
@@ -75,4 +75,11 @@ public class UserController extends BaseController {
public
R
<
UsersInfoDto
>
getUserInfo
(
Long
userId
)
{
return
userService
.
getByUserInfoById
(
userId
);
}
@ApiOperation
(
value
=
"获取用户直连树结构"
,
notes
=
"获取用户直连树结构"
,
httpMethod
=
"GET"
)
@ApiImplicitParam
(
name
=
"userId"
,
value
=
"用户id"
,
dataType
=
"int"
)
@GetMapping
(
"/user/getLinkTree"
)
public
R
<
List
<
UserVo
>>
getLinkTree
(
Long
userId
)
{
return
userService
.
getLinkTree
(
userId
);
}
}
wisenergy-web-admin/src/main/resources/application.yml
View file @
af509b2b
...
...
@@ -17,7 +17,7 @@ spring:
allow-bean-definition-overriding
:
true
# 环境 dev|test|prod
profiles
:
active
:
dev
active
:
prod
# jackson时间格式化
jackson
:
time-zone
:
GMT+8
...
...
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