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
5a531ac9
Commit
5a531ac9
authored
Mar 09, 2020
by
renjie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改shop接口
parent
2b78184d
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
41 additions
and
40 deletions
+41
-40
Shop.java
...in/java/com/edgec/browserbackend/browser/domain/Shop.java
+5
-5
ShopDto.java
...in/java/com/edgec/browserbackend/browser/dto/ShopDto.java
+6
-6
ShopRepository.java
...gec/browserbackend/browser/repository/ShopRepository.java
+4
-4
IpResourceServiceImpl.java
...erbackend/browser/service/Impl/IpResourceServiceImpl.java
+13
-12
ShopServiceImpl.java
.../browserbackend/browser/service/Impl/ShopServiceImpl.java
+13
-13
No files found.
src/main/java/com/edgec/browserbackend/browser/domain/Shop.java
View file @
5a531ac9
...
@@ -10,7 +10,7 @@ import org.springframework.data.mongodb.core.mapping.Document;
...
@@ -10,7 +10,7 @@ import org.springframework.data.mongodb.core.mapping.Document;
public
class
Shop
{
public
class
Shop
{
@Id
@Id
private
String
i
d
;
private
String
shopI
d
;
private
String
shopName
;
private
String
shopName
;
...
@@ -95,8 +95,8 @@ public class Shop {
...
@@ -95,8 +95,8 @@ public class Shop {
return
ip
;
return
ip
;
}
}
public
String
getId
()
{
public
String
get
Shop
Id
()
{
return
i
d
;
return
shopI
d
;
}
}
public
String
getIpId
()
{
public
String
getIpId
()
{
...
@@ -131,8 +131,8 @@ public class Shop {
...
@@ -131,8 +131,8 @@ public class Shop {
this
.
ip
=
ip
;
this
.
ip
=
ip
;
}
}
public
void
set
Id
(
String
i
d
)
{
public
void
set
ShopId
(
String
shopI
d
)
{
this
.
id
=
i
d
;
this
.
shopId
=
shopI
d
;
}
}
public
void
setIpId
(
String
ipId
)
{
public
void
setIpId
(
String
ipId
)
{
...
...
src/main/java/com/edgec/browserbackend/browser/dto/ShopDto.java
View file @
5a531ac9
...
@@ -10,7 +10,7 @@ import java.util.List;
...
@@ -10,7 +10,7 @@ import java.util.List;
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
ShopDto
{
public
class
ShopDto
{
private
String
i
d
;
private
String
shopI
d
;
private
String
shopName
;
private
String
shopName
;
...
@@ -36,7 +36,7 @@ public class ShopDto {
...
@@ -36,7 +36,7 @@ public class ShopDto {
public
static
ShopDto
of
(
Shop
shop
,
IpResource
ipResources
)
{
public
static
ShopDto
of
(
Shop
shop
,
IpResource
ipResources
)
{
ShopDto
shopDto
=
new
ShopDto
();
ShopDto
shopDto
=
new
ShopDto
();
shopDto
.
set
Id
(
shop
.
get
Id
());
shopDto
.
set
ShopId
(
shop
.
getShop
Id
());
if
(
shop
.
getShopName
()
!=
null
)
if
(
shop
.
getShopName
()
!=
null
)
shopDto
.
setShopName
(
shop
.
getShopName
());
shopDto
.
setShopName
(
shop
.
getShopName
());
if
(
shop
.
getShopPlatform
()
!=
null
)
if
(
shop
.
getShopPlatform
()
!=
null
)
...
@@ -97,12 +97,12 @@ public class ShopDto {
...
@@ -97,12 +97,12 @@ public class ShopDto {
this
.
shopName
=
shopName
;
this
.
shopName
=
shopName
;
}
}
public
String
getId
()
{
public
String
get
Shop
Id
()
{
return
i
d
;
return
shopI
d
;
}
}
public
void
set
Id
(
String
i
d
)
{
public
void
set
ShopId
(
String
shopI
d
)
{
this
.
id
=
i
d
;
this
.
shopId
=
shopI
d
;
}
}
public
String
getOwner
()
{
public
String
getOwner
()
{
...
...
src/main/java/com/edgec/browserbackend/browser/repository/ShopRepository.java
View file @
5a531ac9
...
@@ -8,8 +8,8 @@ import org.springframework.data.mongodb.repository.MongoRepository;
...
@@ -8,8 +8,8 @@ import org.springframework.data.mongodb.repository.MongoRepository;
import
java.util.List
;
import
java.util.List
;
public
interface
ShopRepository
extends
MongoRepository
<
Shop
,
String
>
{
public
interface
ShopRepository
extends
MongoRepository
<
Shop
,
String
>
{
Page
<
Shop
>
findByIdInAndIpRegionLike
(
List
<
String
>
shopIds
,
String
ipRegion
,
Pageable
pageable
);
Page
<
Shop
>
findBy
Shop
IdInAndIpRegionLike
(
List
<
String
>
shopIds
,
String
ipRegion
,
Pageable
pageable
);
Page
<
Shop
>
findByIdInAndShopAccountLike
(
List
<
String
>
shopIds
,
String
shopAccount
,
Pageable
pageable
);
Page
<
Shop
>
findBy
Shop
IdInAndShopAccountLike
(
List
<
String
>
shopIds
,
String
shopAccount
,
Pageable
pageable
);
Page
<
Shop
>
findByIdInAndShopNameLike
(
List
<
String
>
shopIds
,
String
shopName
,
Pageable
pageable
);
Page
<
Shop
>
findBy
Shop
IdInAndShopNameLike
(
List
<
String
>
shopIds
,
String
shopName
,
Pageable
pageable
);
Page
<
Shop
>
findByIdIn
(
List
<
String
>
shopIds
,
Pageable
pageable
);
Page
<
Shop
>
findBy
Shop
IdIn
(
List
<
String
>
shopIds
,
Pageable
pageable
);
}
}
src/main/java/com/edgec/browserbackend/browser/service/Impl/IpResourceServiceImpl.java
View file @
5a531ac9
...
@@ -22,6 +22,7 @@ import org.springframework.util.LinkedMultiValueMap;
...
@@ -22,6 +22,7 @@ import org.springframework.util.LinkedMultiValueMap;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.client.RestTemplate
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
@Service
@Service
...
@@ -38,19 +39,13 @@ public class IpResourceServiceImpl implements IpResourceService {
...
@@ -38,19 +39,13 @@ public class IpResourceServiceImpl implements IpResourceService {
@Autowired
@Autowired
private
IpResourceRepository
ipResourceRepository
;
private
IpResourceRepository
ipResourceRepository
;
public
HttpHeaders
buildHeader
(
String
token
)
{
public
HttpHeaders
buildHeader
()
{
HttpHeaders
header
=
new
HttpHeaders
();
HttpHeaders
header
=
new
HttpHeaders
();
header
.
setContentType
(
MediaType
.
APPLICATION_JSON
);
header
.
setContentType
(
MediaType
.
APPLICATION_JSON
);
header
.
setBearerAuth
(
token
);
header
.
setBearerAuth
(
"5aFM6ntBcLDD8e8PGMXBybx1UsWYYWvQ0jKOal28XoMhaz7gJyxX5GtayPcY6vec"
);
return
header
;
return
header
;
}
}
public
MultiValueMap
<
String
,
String
>
buildBody
()
{
MultiValueMap
<
String
,
String
>
map
=
new
LinkedMultiValueMap
<>();
return
map
;
}
@Override
@Override
public
IpResource
getIpResourceByIpAddr
(
String
ipAddr
)
{
public
IpResource
getIpResourceByIpAddr
(
String
ipAddr
)
{
IpResource
ipResource
=
ipResourceRepository
.
findByAddrAndIsDeleted
(
ipAddr
,
false
);
IpResource
ipResource
=
ipResourceRepository
.
findByAddrAndIsDeleted
(
ipAddr
,
false
);
...
@@ -62,11 +57,17 @@ public class IpResourceServiceImpl implements IpResourceService {
...
@@ -62,11 +57,17 @@ public class IpResourceServiceImpl implements IpResourceService {
@Override
@Override
public
IpBuyResultDto
buyIp
(
String
username
,
IpResourceRequestDto
ipResourceRequestDto
)
{
public
IpBuyResultDto
buyIp
(
String
username
,
IpResourceRequestDto
ipResourceRequestDto
)
{
RestTemplate
restTemplate
=
new
RestTemplate
();
RestTemplate
restTemplate
=
new
RestTemplate
();
HttpHeaders
header
=
buildHeader
(
"Basic YnJvd3Nlcjo="
);
HttpHeaders
header
=
buildHeader
();
MultiValueMap
<
String
,
String
>
map
=
buildBody
();
MultiValueMap
<
String
,
String
>
map
=
new
LinkedMultiValueMap
<>();
map
.
add
(
"username"
,
username
);
map
.
add
(
"name"
,
ipResourceRequestDto
.
getName
());
map
.
add
(
"region"
,
ipResourceRequestDto
.
getRegion
());
map
.
add
(
"vendor"
,
ipResourceRequestDto
.
getVendor
());
map
.
add
(
"unit"
,
ipResourceRequestDto
.
getUnit
());
map
.
add
(
"amount"
,
String
.
valueOf
(
ipResourceRequestDto
.
getAmount
()));
HttpEntity
<
MultiValueMap
<
String
,
String
>>
httpEntity
=
new
HttpEntity
<>(
map
,
header
);
HttpEntity
<
MultiValueMap
<
String
,
String
>>
httpEntity
=
new
HttpEntity
<>(
map
,
header
);
IpBuyResultDto
ipBuyResultDto
=
restTemplate
.
postForObject
(
TESTURL
+
"/intelligroup/ipresources"
,
httpEntity
,
IpBuyResultDto
.
class
);
IpBuyResultDto
ipBuyResultDto
=
restTemplate
.
postForObject
(
TESTURL
+
"/intelligroup/ipresources
?accountId={username}
"
,
httpEntity
,
IpBuyResultDto
.
class
);
return
null
;
return
ipBuyResultDto
;
}
}
@Override
@Override
...
...
src/main/java/com/edgec/browserbackend/browser/service/Impl/ShopServiceImpl.java
View file @
5a531ac9
...
@@ -64,7 +64,7 @@ public class ShopServiceImpl implements ShopService {
...
@@ -64,7 +64,7 @@ public class ShopServiceImpl implements ShopService {
if
(
account
.
getPermission
()
<
4
)
{
if
(
account
.
getPermission
()
<
4
)
{
throw
new
ClientRequestException
(
AccountErrorCode
.
NOPERMISSION
);
throw
new
ClientRequestException
(
AccountErrorCode
.
NOPERMISSION
);
}
}
UserShop
us
=
userShopRepository
.
findByUsernameAndShopId
(
username
,
shopDto
.
getId
());
UserShop
us
=
userShopRepository
.
findByUsernameAndShopId
(
username
,
shopDto
.
get
Shop
Id
());
Group
group
=
groupRepository
.
findById
(
shopDto
.
getGroup
()).
orElse
(
null
);
Group
group
=
groupRepository
.
findById
(
shopDto
.
getGroup
()).
orElse
(
null
);
if
(
group
==
null
)
{
if
(
group
==
null
)
{
throw
new
ClientRequestException
(
BrowserErrorCode
.
GROUPNOTEXIST
);
throw
new
ClientRequestException
(
BrowserErrorCode
.
GROUPNOTEXIST
);
...
@@ -73,7 +73,7 @@ public class ShopServiceImpl implements ShopService {
...
@@ -73,7 +73,7 @@ public class ShopServiceImpl implements ShopService {
shopDto
.
setOwner
(
username
);
shopDto
.
setOwner
(
username
);
Shop
shop
=
new
Shop
();
Shop
shop
=
new
Shop
();
shop
.
of
(
shopDto
);
shop
.
of
(
shopDto
);
id
=
shopRepository
.
save
(
shop
).
getId
();
id
=
shopRepository
.
save
(
shop
).
get
Shop
Id
();
UserShop
userShop
=
new
UserShop
();
UserShop
userShop
=
new
UserShop
();
userShop
.
setUsername
(
username
);
userShop
.
setUsername
(
username
);
userShop
.
setShopId
(
id
);
userShop
.
setShopId
(
id
);
...
@@ -98,11 +98,11 @@ public class ShopServiceImpl implements ShopService {
...
@@ -98,11 +98,11 @@ public class ShopServiceImpl implements ShopService {
if
(
account
==
null
)
{
if
(
account
==
null
)
{
throw
new
ClientRequestException
(
AccountErrorCode
.
NAMENOTEXIST
);
throw
new
ClientRequestException
(
AccountErrorCode
.
NAMENOTEXIST
);
}
}
UserShop
userShop
=
userShopRepository
.
findByUsernameAndShopId
(
username
,
shopDto
.
getId
());
UserShop
userShop
=
userShopRepository
.
findByUsernameAndShopId
(
username
,
shopDto
.
get
Shop
Id
());
if
(
account
.
getPermission
()
<
4
||
userShop
==
null
)
{
if
(
account
.
getPermission
()
<
4
||
userShop
==
null
)
{
throw
new
ClientRequestException
(
AccountErrorCode
.
NOPERMISSION
);
throw
new
ClientRequestException
(
AccountErrorCode
.
NOPERMISSION
);
}
}
Shop
shop_old
=
shopRepository
.
findById
(
shopDto
.
getId
()).
orElseGet
(
null
);
Shop
shop_old
=
shopRepository
.
findById
(
shopDto
.
get
Shop
Id
()).
orElseGet
(
null
);
if
(
shop_old
==
null
)
if
(
shop_old
==
null
)
throw
new
ClientRequestException
(
BrowserErrorCode
.
SHOPNOTEXIST
);
throw
new
ClientRequestException
(
BrowserErrorCode
.
SHOPNOTEXIST
);
try
{
try
{
...
@@ -112,7 +112,7 @@ public class ShopServiceImpl implements ShopService {
...
@@ -112,7 +112,7 @@ public class ShopServiceImpl implements ShopService {
logger
.
error
(
"fail to update"
,
e
.
getMessage
());
logger
.
error
(
"fail to update"
,
e
.
getMessage
());
throw
new
ClientRequestException
(
BrowserErrorCode
.
INFORMATIONNOTCOMPELETE
);
throw
new
ClientRequestException
(
BrowserErrorCode
.
INFORMATIONNOTCOMPELETE
);
}
}
return
shop_old
.
getId
();
return
shop_old
.
get
Shop
Id
();
}
}
@Override
@Override
...
@@ -162,7 +162,7 @@ public class ShopServiceImpl implements ShopService {
...
@@ -162,7 +162,7 @@ public class ShopServiceImpl implements ShopService {
shop
.
setIpRegion
(
ipResource
.
getIpRegion
());
shop
.
setIpRegion
(
ipResource
.
getIpRegion
());
shopRepository
.
save
(
shop
);
shopRepository
.
save
(
shop
);
List
<
String
>
history
=
ipResource
.
getBindHistory
();
List
<
String
>
history
=
ipResource
.
getBindHistory
();
history
.
add
(
shop
.
getId
());
history
.
add
(
shop
.
get
Shop
Id
());
ipResource
.
setShopId
(
shopId
);
ipResource
.
setShopId
(
shopId
);
if
(
shop
.
getShopName
()!=
null
)
if
(
shop
.
getShopName
()!=
null
)
ipResource
.
setShopName
(
shop
.
getShopName
());
ipResource
.
setShopName
(
shop
.
getShopName
());
...
@@ -239,7 +239,7 @@ public class ShopServiceImpl implements ShopService {
...
@@ -239,7 +239,7 @@ public class ShopServiceImpl implements ShopService {
throw
new
ClientRequestException
(
AccountErrorCode
.
NOPERMISSION
);
throw
new
ClientRequestException
(
AccountErrorCode
.
NOPERMISSION
);
}
}
Pageable
pageable
=
PageRequest
.
of
(
0
,
100
);
Pageable
pageable
=
PageRequest
.
of
(
0
,
100
);
List
<
Shop
>
shops
=
shopRepository
.
findByIdIn
(
shopIds
,
pageable
).
getContent
();
List
<
Shop
>
shops
=
shopRepository
.
findBy
Shop
IdIn
(
shopIds
,
pageable
).
getContent
();
if
(
shops
==
null
||
shops
.
size
()
<
1
)
if
(
shops
==
null
||
shops
.
size
()
<
1
)
throw
new
ClientRequestException
(
BrowserErrorCode
.
SHOPNOTEXIST
);
throw
new
ClientRequestException
(
BrowserErrorCode
.
SHOPNOTEXIST
);
List
<
Account
>
accounts
=
accountRepository
.
findByNameIn
(
users
);
List
<
Account
>
accounts
=
accountRepository
.
findByNameIn
(
users
);
...
@@ -248,10 +248,10 @@ public class ShopServiceImpl implements ShopService {
...
@@ -248,10 +248,10 @@ public class ShopServiceImpl implements ShopService {
accounts
.
stream
().
forEach
(
x
->
{
accounts
.
stream
().
forEach
(
x
->
{
try
{
try
{
for
(
Shop
shop:
shops
){
for
(
Shop
shop:
shops
){
UserShop
userShop1
=
userShopRepository
.
findByUsernameAndShopId
(
x
.
getName
(),
shop
.
getId
());
UserShop
userShop1
=
userShopRepository
.
findByUsernameAndShopId
(
x
.
getName
(),
shop
.
get
Shop
Id
());
if
(
userShop1
!=
null
)
if
(
userShop1
!=
null
)
return
;
return
;
userShopRepository
.
save
(
new
UserShop
(
x
.
getName
(),
shop
.
getId
()));
userShopRepository
.
save
(
new
UserShop
(
x
.
getName
(),
shop
.
get
Shop
Id
()));
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
logger
.
error
(
"fail to assign"
,
e
.
getMessage
());
logger
.
error
(
"fail to assign"
,
e
.
getMessage
());
...
@@ -282,13 +282,13 @@ public class ShopServiceImpl implements ShopService {
...
@@ -282,13 +282,13 @@ public class ShopServiceImpl implements ShopService {
map
(
x
->
x
.
getShopId
()).
collect
(
Collectors
.
toList
());
map
(
x
->
x
.
getShopId
()).
collect
(
Collectors
.
toList
());
Page
<
Shop
>
shops
;
Page
<
Shop
>
shops
;
if
(
filterDto
!=
null
&&
StringUtils
.
isNotBlank
(
filterDto
.
getIpRegion
()))
if
(
filterDto
!=
null
&&
StringUtils
.
isNotBlank
(
filterDto
.
getIpRegion
()))
shops
=
shopRepository
.
findByIdInAndIpRegionLike
(
shopIds
,
filterDto
.
getIpRegion
(),
pageable
);
shops
=
shopRepository
.
findBy
Shop
IdInAndIpRegionLike
(
shopIds
,
filterDto
.
getIpRegion
(),
pageable
);
else
if
(
filterDto
!=
null
&&
StringUtils
.
isNotBlank
(
filterDto
.
getShopAccount
()))
else
if
(
filterDto
!=
null
&&
StringUtils
.
isNotBlank
(
filterDto
.
getShopAccount
()))
shops
=
shopRepository
.
findByIdInAndShopAccountLike
(
shopIds
,
filterDto
.
getShopAccount
(),
pageable
);
shops
=
shopRepository
.
findBy
Shop
IdInAndShopAccountLike
(
shopIds
,
filterDto
.
getShopAccount
(),
pageable
);
else
if
(
filterDto
!=
null
&&
StringUtils
.
isNotBlank
(
filterDto
.
getShopName
()))
else
if
(
filterDto
!=
null
&&
StringUtils
.
isNotBlank
(
filterDto
.
getShopName
()))
shops
=
shopRepository
.
findByIdInAndShopNameLike
(
shopIds
,
filterDto
.
getShopName
(),
pageable
);
shops
=
shopRepository
.
findBy
Shop
IdInAndShopNameLike
(
shopIds
,
filterDto
.
getShopName
(),
pageable
);
else
else
shops
=
shopRepository
.
findByIdIn
(
shopIds
,
pageable
);
shops
=
shopRepository
.
findBy
Shop
IdIn
(
shopIds
,
pageable
);
if
(
shops
==
null
||
shops
.
getNumberOfElements
()
<
1
)
if
(
shops
==
null
||
shops
.
getNumberOfElements
()
<
1
)
return
new
ShopPageResultDto
();
return
new
ShopPageResultDto
();
List
<
ShopDto
>
shopDtos
=
new
ArrayList
<>();
List
<
ShopDto
>
shopDtos
=
new
ArrayList
<>();
...
...
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