Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
browser-backend
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
Administrator
browser-backend
Commits
e01ba82d
Commit
e01ba82d
authored
Jun 29, 2020
by
jim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
null
parent
aa9ad17b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
28 deletions
+26
-28
ShopServiceImpl.java
.../browserbackend/browser/service/Impl/ShopServiceImpl.java
+26
-28
No files found.
src/main/java/com/edgec/browserbackend/browser/service/Impl/ShopServiceImpl.java
View file @
e01ba82d
...
...
@@ -67,12 +67,12 @@ public class ShopServiceImpl implements ShopService {
}
if
(
shopResultDto
.
getGroup
()
!=
null
)
{
Group
group
=
groupRepository
.
findById
(
shopResultDto
.
getGroup
())
.
orElseThrow
(()
->
new
ClientRequestException
(
BrowserErrorCode
.
GROUPNOTEXIST
));
.
orElseThrow
(()
->
new
ClientRequestException
(
BrowserErrorCode
.
GROUPNOTEXIST
));
}
// 2. 对当前用户的 account 信息进行校验
Account
account
=
accountRepository
.
findByName
(
username
)
.
orElseThrow
(()
->
new
ClientRequestException
(
AccountErrorCode
.
NAMENOTEXIST
));
.
orElseThrow
(()
->
new
ClientRequestException
(
AccountErrorCode
.
NAMENOTEXIST
));
if
(
account
.
getPermission
()
<
4
)
{
throw
new
ClientRequestException
(
AccountErrorCode
.
NOPERMISSION
);
}
...
...
@@ -100,7 +100,7 @@ public class ShopServiceImpl implements ShopService {
userShopRepository
.
save
(
userShop1
);
Account
parentAccount
=
accountRepository
.
findByName
(
account
.
getParent
())
.
orElseThrow
(()
->
new
ClientRequestException
(
AccountErrorCode
.
NAMENOTEXIST
));
.
orElseThrow
(()
->
new
ClientRequestException
(
AccountErrorCode
.
NAMENOTEXIST
));
account
.
setShopCount
(
parentAccount
.
getShopCount
()
+
1
);
accountRepository
.
save
(
parentAccount
);
}
...
...
@@ -159,7 +159,7 @@ public class ShopServiceImpl implements ShopService {
userShopRepository
.
save
(
userShop1
);
Account
parentAccount
=
accountRepository
.
findByName
(
account
.
getParent
())
.
orElseThrow
(()
->
new
ClientRequestException
(
AccountErrorCode
.
NAMENOTEXIST
));
.
orElseThrow
(()
->
new
ClientRequestException
(
AccountErrorCode
.
NAMENOTEXIST
));
account
.
setShopCount
(
parentAccount
.
getShopCount
()
+
1
);
accountRepository
.
save
(
parentAccount
);
}
...
...
@@ -169,7 +169,7 @@ public class ShopServiceImpl implements ShopService {
ids
.
add
(
id
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"fail to add shops"
,
e
.
getMessage
()
);
logger
.
error
(
"fail to add shops"
,
e
);
throw
new
ClientRequestException
(
BrowserErrorCode
.
INFORMATIONNOTCOMPELETE
);
}
}
...
...
@@ -201,7 +201,7 @@ public class ShopServiceImpl implements ShopService {
// 4. 更新店铺信息
shopRepository
.
save
(
shop_old
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"fail to update"
,
e
.
getMessage
()
);
logger
.
error
(
"fail to update"
,
e
);
throw
new
ClientRequestException
(
BrowserErrorCode
.
INFORMATIONNOTCOMPELETE
);
}
return
shop_old
.
getShopId
();
...
...
@@ -276,7 +276,7 @@ public class ShopServiceImpl implements ShopService {
userShop
.
setGroupId
(
groupId
);
userShopRepository
.
save
(
userShop
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"fail to unbind"
,
e
.
getMessage
()
);
logger
.
error
(
"fail to unbind"
,
e
);
throw
new
ClientRequestException
(
BrowserErrorCode
.
UNKNOWN
);
}
...
...
@@ -344,7 +344,7 @@ public class ShopServiceImpl implements ShopService {
);
}
}
catch
(
Exception
e
)
{
logger
.
error
(
"fail to assign"
,
e
.
getMessage
()
);
logger
.
error
(
"fail to assign"
,
e
);
throw
new
ClientRequestException
(
BrowserErrorCode
.
UNKNOWN
);
}
}
...
...
@@ -396,15 +396,15 @@ public class ShopServiceImpl implements ShopService {
List
<
String
>
allIds
=
null
;
if
(
"-1"
.
equals
(
groupId
))
{
allIds
=
userShopRepository
.
findByUsername
(
username
).
stream
()
.
map
(
UserShop:
:
getShopId
).
collect
(
Collectors
.
toList
());
.
map
(
UserShop:
:
getShopId
).
collect
(
Collectors
.
toList
());
// 如果分组
}
else
{
allIds
=
userShopRepository
.
findByUsernameAndGroupId
(
username
,
groupId
).
stream
()
.
map
(
UserShop:
:
getShopId
).
collect
(
Collectors
.
toList
());
.
map
(
UserShop:
:
getShopId
).
collect
(
Collectors
.
toList
());
}
// 4. 根据传入的过滤条件得到 shopIds
List
<
String
>
shopIds
=
n
ull
;
List
<
String
>
shopIds
=
n
ew
ArrayList
<>()
;
if
(
shopFilterDto
.
getBindIp
()
==
0
)
{
shopIds
=
allIds
;
...
...
@@ -412,7 +412,7 @@ public class ShopServiceImpl implements ShopService {
}
else
if
(
shopFilterDto
.
getBindIp
()
==
1
)
{
// ip资源已经分配了 的店铺
shopIds
=
ipResourceRepository
.
findShopIdInList
(
allIds
,
false
).
stream
()
.
flatMap
((
x
->
x
.
getShopIds
().
stream
())).
collect
(
Collectors
.
toList
());
.
flatMap
((
x
->
x
.
getShopIds
().
stream
())).
collect
(
Collectors
.
toList
());
// 这个地方的其他情况是指什么情况
}
else
{
...
...
@@ -425,7 +425,7 @@ public class ShopServiceImpl implements ShopService {
}
}
amount
=
amount
>
100
?
100
:
amount
;
amount
=
Math
.
min
(
amount
,
100
)
;
Pageable
pageable
=
PageRequest
.
of
(
pageNum
,
amount
);
// 5. 根据过滤后的商铺ids 与 其他过滤条件 得到商铺信息并分页
Page
<
Shop
>
shops
=
getShopsByFilter
(
shopFilterDto
,
shopIds
,
pageable
);
...
...
@@ -434,7 +434,7 @@ public class ShopServiceImpl implements ShopService {
ShopPageResultDto
<
ShopResultDto
>
shopPageResultDto
=
new
ShopPageResultDto
<>();
if
(
shops
!=
null
&&
shops
.
getNumberOfElements
()
>=
1
)
{
List
<
ShopResultDto
>
shopResultDtos
=
new
ArrayList
<>();
shops
.
getContent
().
stream
().
forEach
(
shops
.
getContent
().
forEach
(
// 设置ip资源状态 并 封装 shopResultDto信息
x
->
{
IpResource
ipResource
=
ipResourceRepository
.
findFirstByShopIdsIsAndIsDeleted
(
x
.
getShopId
(),
false
);
...
...
@@ -506,7 +506,7 @@ public class ShopServiceImpl implements ShopService {
ShopSummary
shopSummary
=
new
ShopSummary
();
List
<
String
>
allShopIds
=
userShopRepository
.
findByUsername
(
username
).
stream
()
.
map
(
UserShop:
:
getShopId
).
collect
(
Collectors
.
toList
());
.
map
(
UserShop:
:
getShopId
).
collect
(
Collectors
.
toList
());
List
<
String
>
unbind
=
new
ArrayList
<>();
if
(!
allShopIds
.
isEmpty
())
{
for
(
String
id
:
allShopIds
)
{
...
...
@@ -519,9 +519,9 @@ public class ShopServiceImpl implements ShopService {
shopSummary
.
setUnbind
(
unbind
.
size
());
List
<
String
>
shopIds
=
userShopRepository
.
findByUsername
(
username
).
stream
()
.
map
(
UserShop:
:
getShopId
).
collect
(
Collectors
.
toList
());
.
map
(
UserShop:
:
getShopId
).
collect
(
Collectors
.
toList
());
List
<
String
>
bind
=
ipResourceRepository
.
findShopIdInList
(
shopIds
,
false
).
stream
()
.
map
(
IpResource:
:
getId
).
collect
(
Collectors
.
toList
());
.
map
(
IpResource:
:
getId
).
collect
(
Collectors
.
toList
());
int
expired
=
ipResourceRepository
.
countByStatusAndIdInAndIsDeleted
(
1
,
bind
,
false
);
int
willexpired
=
ipResourceRepository
.
countByStatusAndIdInAndIsDeleted
(
2
,
bind
,
false
);
shopSummary
.
setExpired
(
expired
);
...
...
@@ -539,9 +539,9 @@ public class ShopServiceImpl implements ShopService {
// 获取当前登录用户绑定了当前商铺的 所有子用户名
List
<
String
>
shopUsers
=
userShopRepository
.
findByShopId
(
shopId
).
stream
()
.
map
(
x
->
x
.
getUsername
()
)
.
filter
(
x
->
!
x
.
equals
(
username
))
.
collect
(
Collectors
.
toList
());
.
map
(
UserShop:
:
getUsername
)
.
filter
(
x
->
!
x
.
equals
(
username
))
.
collect
(
Collectors
.
toList
());
return
shopUsers
;
}
...
...
@@ -567,7 +567,7 @@ public class ShopServiceImpl implements ShopService {
return
shopUsers
;
}
List
<
String
>
users
=
userShopRepository
.
findByShopId
(
maxShopId
).
stream
().
map
(
x
->
x
.
getUsername
()
).
filter
(
x
->
!
x
.
equals
(
username
)).
collect
(
Collectors
.
toList
());
List
<
String
>
users
=
userShopRepository
.
findByShopId
(
maxShopId
).
stream
().
map
(
UserShop:
:
getUsername
).
filter
(
x
->
!
x
.
equals
(
username
)).
collect
(
Collectors
.
toList
());
for
(
String
user
:
users
)
{
int
shopCount
=
userShopRepository
.
countByUsernameAndShopIdIn
(
user
,
shopIds
);
if
(
shopCount
<
shopIds
.
size
())
{
...
...
@@ -602,21 +602,19 @@ public class ShopServiceImpl implements ShopService {
}
}
Integer
result
=
0
;
Iterator
<
Map
.
Entry
<
Account
,
List
<
Account
>>>
entries
=
map
.
entrySet
().
iterator
();
while
(
entries
.
hasNext
())
{
Map
.
Entry
<
Account
,
List
<
Account
>>
entry
=
entries
.
next
();
int
result
=
0
;
for
(
Map
.
Entry
<
Account
,
List
<
Account
>>
entry
:
map
.
entrySet
())
{
List
<
Account
>
children
=
entry
.
getValue
();
// 查找子类所拥有的店铺
List
<
Shop
>
childrenShop
=
shopRepository
.
findByOwnerIn
(
children
.
stream
().
map
(
Account:
:
getName
).
collect
(
Collectors
.
toList
()));
if
(
childrenShop
.
size
()
==
0
)
{
continue
;
}
List
<
String
>
ids
=
childrenShop
.
stream
().
map
(
x
->
x
.
getShopId
()
).
collect
(
Collectors
.
toList
());
List
<
String
>
ids
=
childrenShop
.
stream
().
map
(
Shop:
:
getShopId
).
collect
(
Collectors
.
toList
());
// 查出来 父账户已有的 usershop信息
List
<
UserShop
>
parentUserShops
=
userShopRepository
.
findByUsernameAndShopIdIn
(
entry
.
getKey
().
getName
(),
ids
);
List
<
String
>
parentShopIds
=
parentUserShops
.
stream
().
map
(
x
->
x
.
getShopId
()
).
collect
(
Collectors
.
toList
());
List
<
String
>
parentShopIds
=
parentUserShops
.
stream
().
map
(
UserShop:
:
getShopId
).
collect
(
Collectors
.
toList
());
// 剩下的就是 父账户的 usershop 缺失的信息
ids
.
removeAll
(
parentShopIds
);
...
...
@@ -656,7 +654,7 @@ public class ShopServiceImpl implements ShopService {
Page
<
Shop
>
shops
=
null
;
if
(!
StringUtils
.
isEmpty
(
shopFilterDto
.
getIpRegion
()))
{
List
<
String
>
filter
=
ipResourceRepository
.
findShopIdInListAndRegionLike
(
shopIds
,
false
,
shopFilterDto
.
getIpRegion
())
.
stream
().
flatMap
((
x
->
x
.
getShopIds
().
stream
())).
collect
(
Collectors
.
toList
());
.
stream
().
flatMap
((
x
->
x
.
getShopIds
().
stream
())).
collect
(
Collectors
.
toList
());
shops
=
shopRepository
.
findByShopIdInOrderByCreateTimeDesc
(
filter
,
pageable
);
}
if
(!
StringUtils
.
isEmpty
(
shopFilterDto
.
getShopAccount
()))
{
...
...
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