Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
manager
Project
Overview
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
reyun
manager
Commits
9e50ac7b
Commit
9e50ac7b
authored
Jan 22, 2018
by
manxiaoqiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
合同
parent
97caee98
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
178 additions
and
3 deletions
+178
-3
workspace.xml
.idea/workspace.xml
+0
-0
UserController.java
src/main/java/common/controller/UserController.java
+9
-0
User.java
src/main/java/common/model/User.java
+13
-0
AuthRepository.java
src/main/java/common/repository/AuthRepository.java
+4
-0
UserRepository.java
src/main/java/common/repository/UserRepository.java
+22
-2
UserService.java
src/main/java/common/service/UserService.java
+6
-0
UserServiceImpl.java
src/main/java/common/service/impl/UserServiceImpl.java
+124
-1
No files found.
.idea/workspace.xml
View file @
9e50ac7b
This diff is collapsed.
Click to expand it.
src/main/java/common/controller/UserController.java
View file @
9e50ac7b
...
...
@@ -172,4 +172,13 @@ public class UserController {
public
ResultModel
validCode
(
@RequestParam
String
email
,
@RequestParam
String
code
,
@RequestParam
String
pwd
)
{
return
ResultModel
.
OK
(
userService
.
validCode
(
email
,
code
,
pwd
));
}
@RequestMapping
(
value
=
"/find/{role}"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
public
ResultModel
findByRole
(
@PathVariable
Long
role
)
{
return
ResultModel
.
OK
(
userService
.
findbyRole
(
role
));
}
}
src/main/java/common/model/User.java
View file @
9e50ac7b
...
...
@@ -20,6 +20,7 @@ public class User {
private
String
roleTypeName
;
private
String
auth
;
private
Boolean
status
;
private
Long
parent
;
private
Long
modifyAccount
;
private
Long
createAccount
;
...
...
@@ -152,6 +153,14 @@ public class User {
this
.
roleName
=
roleName
;
}
public
Long
getParent
()
{
return
parent
;
}
public
void
setParent
(
Long
parent
)
{
this
.
parent
=
parent
;
}
@Override
public
String
toString
()
{
return
"User{"
+
...
...
@@ -160,8 +169,12 @@ public class User {
", password='"
+
password
+
'\''
+
", name='"
+
name
+
'\''
+
", role="
+
role
+
", roleName='"
+
roleName
+
'\''
+
", roleType="
+
roleType
+
", roleTypeName='"
+
roleTypeName
+
'\''
+
", auth='"
+
auth
+
'\''
+
", status="
+
status
+
", parent="
+
parent
+
", modifyAccount="
+
modifyAccount
+
", createAccount="
+
createAccount
+
", modifyTime="
+
modifyTime
+
...
...
src/main/java/common/repository/AuthRepository.java
View file @
9e50ac7b
...
...
@@ -2,6 +2,7 @@ package common.repository;
import
common.model.Auth
;
import
common.model.Menu
;
import
common.model.User
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.transaction.annotation.Transactional
;
...
...
@@ -12,4 +13,7 @@ import java.util.List;
public
interface
AuthRepository
extends
JpaRepository
<
Auth
,
Long
>
{
Auth
findByUser
(
Long
user
);
@Query
(
value
=
"SELECT * from `auth` where user in ?1"
,
nativeQuery
=
true
)
List
<
Auth
>
findAllByUsers
(
List
<
Long
>
ids
);
}
src/main/java/common/repository/UserRepository.java
View file @
9e50ac7b
...
...
@@ -26,7 +26,27 @@ public interface UserRepository extends JpaRepository<User, Long> {
@Query
(
value
=
"select * from user where del_flag is not true and (role = 2 or role = 3)"
,
nativeQuery
=
true
)
List
<
User
>
findSales
();
@Query
(
value
=
"
select * from user where role = 2 or role = 3
"
,
nativeQuery
=
true
)
List
<
User
>
findAll
Sales
(
);
@Query
(
value
=
"
SELECT * from `user` where del_flag is not true and role = ?1 ORDER BY role_type
"
,
nativeQuery
=
true
)
List
<
User
>
findAll
ByRole
(
Long
role
);
@Query
(
value
=
"SELECT * from `user` where role = ?1 ORDER BY role_type"
,
nativeQuery
=
true
)
List
<
User
>
findAllUserByRole
(
Long
role
);
@Query
(
value
=
"SELECT * from `user` where del_flag is not true and parent = ?1"
,
nativeQuery
=
true
)
List
<
User
>
findAllByParent
(
Long
id
);
@Query
(
value
=
"SELECT * from `user` where parent = ?1"
,
nativeQuery
=
true
)
List
<
User
>
findByParent
(
Long
id
);
@Query
(
value
=
"SELECT * from `user` where del_flag is not true and id in ?1"
,
nativeQuery
=
true
)
List
<
User
>
findAllByIds
(
List
<
Long
>
ids
);
@Query
(
value
=
"SELECT * from `user` where id in ?1"
,
nativeQuery
=
true
)
List
<
User
>
findByIds
(
List
<
Long
>
ids
);
@Query
(
value
=
"SELECT * from `user` where del_flag is not true and parent in ?1"
,
nativeQuery
=
true
)
List
<
User
>
findAllByParents
(
List
<
Long
>
ids
);
@Query
(
value
=
"SELECT * from `user` where parent in ?1"
,
nativeQuery
=
true
)
List
<
User
>
findByParents
(
List
<
Long
>
ids
);
}
src/main/java/common/service/UserService.java
View file @
9e50ac7b
...
...
@@ -33,4 +33,10 @@ public interface UserService {
Boolean
sendCode
(
String
email
);
Boolean
validCode
(
String
email
,
String
code
,
String
pwd
);
List
<
User
>
findbyRole
(
Long
role
);
List
<
User
>
findSonsAlive
(
Long
user
);
List
<
User
>
findAllSons
(
Long
user
);
}
src/main/java/common/service/impl/UserServiceImpl.java
View file @
9e50ac7b
...
...
@@ -9,6 +9,8 @@ import common.repository.UserRepository;
import
common.service.UserService
;
import
dic.RoleEnum
;
import
dic.RoleTypeEnum
;
import
net.sf.json.JSONArray
;
import
net.sf.json.JSONObject
;
import
office.service.BussinussManService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
...
...
@@ -101,7 +103,45 @@ public class UserServiceImpl implements UserService {
auth
.
setModifyAccount
(
login
.
getId
());
auth
.
setAuth
(
resource
.
getAuth
());
auth
.
setUser
(
save
.
getId
());
authRepository
.
save
(
auth
);
Auth
authSave
=
authRepository
.
save
(
auth
);
if
(
save
.
getRoleType
().
equals
(
RoleTypeEnum
.
COMMON
.
getKey
())){
JSONArray
rootArr
=
JSONArray
.
fromObject
(
authSave
.
getAuth
());
List
<
String
>
authList
=
new
ArrayList
<>();
if
(
ValidateUtil
.
isValid
(
rootArr
)){
for
(
int
i
=
0
;
i
<
rootArr
.
size
();
i
++)
{
JSONObject
obj
=
rootArr
.
getJSONObject
(
i
);
authList
.
add
(
obj
.
getString
(
"id"
));
}
}
List
<
User
>
userList
=
findSonsAlive
(
save
.
getId
());
if
(
ValidateUtil
.
isValid
(
userList
)){
List
<
Long
>
ids
=
new
ArrayList
<>();
for
(
User
u
:
userList
){
ids
.
add
(
u
.
getId
());
}
List
<
Auth
>
list
=
authRepository
.
findAllByUsers
(
ids
);
if
(
ValidateUtil
.
isValid
(
list
)){
List
<
Auth
>
authListSave
=
new
ArrayList
<>();
for
(
Auth
a
:
list
){
String
authStr
=
a
.
getAuth
();
JSONArray
arrSave
=
new
JSONArray
();
JSONArray
arr
=
JSONArray
.
fromObject
(
authStr
);
if
(
ValidateUtil
.
isValid
(
arr
)){
for
(
int
i
=
0
;
i
<
arr
.
size
();
i
++)
{
JSONObject
obj
=
arr
.
getJSONObject
(
i
);
if
(
authList
.
contains
(
obj
.
getString
(
"id"
))){
arrSave
.
add
(
obj
);
}
}
}
a
.
setAuth
(
arrSave
.
toString
());
authListSave
.
add
(
a
);
}
authRepository
.
save
(
authSave
);
}
}
}
return
save
;
}
...
...
@@ -120,6 +160,8 @@ public class UserServiceImpl implements UserService {
userList
=
userRepository
.
findList
();
}
else
if
(
RoleTypeEnum
.
MANAGER
.
getKey
().
equals
(
login
.
getRoleType
())){
userList
=
userRepository
.
findOneDepartment
(
login
.
getRole
());
}
else
{
userList
=
findSonsAlive
(
login
.
getId
());
}
if
(
ValidateUtil
.
isValid
(
userList
)){
for
(
User
u
:
userList
){
...
...
@@ -226,4 +268,85 @@ public class UserServiceImpl implements UserService {
}
return
false
;
}
@Override
public
List
<
User
>
findbyRole
(
Long
role
)
{
List
<
Auth
>
authList
=
authRepository
.
findAll
();
Map
<
Long
,
String
>
map
=
new
HashMap
<>();
if
(
ValidateUtil
.
isValid
(
authList
)){
for
(
Auth
a
:
authList
){
map
.
put
(
a
.
getUser
(),
a
.
getAuth
());
}
}
List
<
User
>
result
=
new
ArrayList
<>();
List
<
User
>
userList
=
userRepository
.
findAllByRole
(
role
);
if
(
ValidateUtil
.
isValid
(
userList
)){
for
(
User
u
:
userList
){
if
(
map
.
containsKey
(
u
.
getId
())){
u
.
setAuth
(
map
.
get
(
u
.
getId
()));
}
result
.
add
(
u
);
}
}
return
result
;
}
@Override
public
List
<
User
>
findSonsAlive
(
Long
user
)
{
List
<
User
>
result
=
new
ArrayList
<>();
User
one
=
userRepository
.
findOne
(
user
);
if
(
one
.
getRole
().
equals
(
RoleEnum
.
MANAGER
.
getKey
())){
List
<
User
>
list
=
userRepository
.
findList
();
if
(
ValidateUtil
.
isValid
(
list
)){
result
.
addAll
(
list
);
}
}
else
if
(
one
.
getRoleType
().
equals
(
RoleTypeEnum
.
MANAGER
.
getKey
())){
List
<
User
>
list
=
userRepository
.
findAllByRole
(
one
.
getRole
());
if
(
ValidateUtil
.
isValid
(
list
)){
result
.
addAll
(
list
);
}
}
else
{
List
<
User
>
list
=
userRepository
.
findAllByParent
(
user
);
while
(
ValidateUtil
.
isValid
(
list
)){
result
.
addAll
(
list
);
List
<
Long
>
ids
=
new
ArrayList
<>();
for
(
User
u
:
list
){
ids
.
add
(
u
.
getId
());
}
list
=
userRepository
.
findAllByParents
(
ids
);
}
}
return
result
;
}
@Override
public
List
<
User
>
findAllSons
(
Long
user
)
{
List
<
User
>
result
=
new
ArrayList
<>();
User
one
=
userRepository
.
findOne
(
user
);
if
(
one
.
getRole
().
equals
(
RoleEnum
.
MANAGER
.
getKey
())){
List
<
User
>
list
=
userRepository
.
findAll
();
if
(
ValidateUtil
.
isValid
(
list
)){
result
.
addAll
(
list
);
}
}
else
if
(
one
.
getRoleType
().
equals
(
RoleTypeEnum
.
MANAGER
.
getKey
())){
List
<
User
>
list
=
userRepository
.
findAllUserByRole
(
one
.
getRole
());
if
(
ValidateUtil
.
isValid
(
list
)){
result
.
addAll
(
list
);
}
}
else
{
List
<
User
>
list
=
userRepository
.
findByParent
(
user
);
while
(
ValidateUtil
.
isValid
(
list
)){
result
.
addAll
(
list
);
List
<
Long
>
ids
=
new
ArrayList
<>();
for
(
User
u
:
list
){
ids
.
add
(
u
.
getId
());
}
list
=
userRepository
.
findByParents
(
ids
);
}
}
return
result
;
}
}
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