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
0e7986d5
Commit
0e7986d5
authored
Jun 04, 2020
by
Administrator
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'staging' into 'master'
Staging See merge request
!144
parents
49ced3a0
96eb9360
Show whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
877 additions
and
128 deletions
+877
-128
Promotion.java
...va/com/edgec/browserbackend/account/domain/Promotion.java
+3
-0
IpControlloer.java
...dgec/browserbackend/browser/controller/IpControlloer.java
+19
-0
IpResource.java
...a/com/edgec/browserbackend/browser/domain/IpResource.java
+22
-13
IpResourceDto.java
...a/com/edgec/browserbackend/browser/dto/IpResourceDto.java
+26
-10
IpResourceUnwindResultDto.java
...browserbackend/browser/dto/IpResourceUnwindResultDto.java
+347
-0
ShopResultDto.java
...a/com/edgec/browserbackend/browser/dto/ShopResultDto.java
+7
-2
IpResourceRepository.java
...owserbackend/browser/repository/IpResourceRepository.java
+9
-10
IpResourceRepositoryCustom.java
...ackend/browser/repository/IpResourceRepositoryCustom.java
+15
-0
IpResourceRepositoryCustomImpl.java
...nd/browser/repository/IpResourceRepositoryCustomImpl.java
+143
-6
ShopRepository.java
...gec/browserbackend/browser/repository/ShopRepository.java
+1
-0
IpAndShopServiceImpl.java
...serbackend/browser/service/Impl/IpAndShopServiceImpl.java
+52
-13
IpResourceServiceImpl.java
...erbackend/browser/service/Impl/IpResourceServiceImpl.java
+64
-52
ShopServiceImpl.java
.../browserbackend/browser/service/Impl/ShopServiceImpl.java
+19
-17
IpAndShopService.java
...dgec/browserbackend/browser/service/IpAndShopService.java
+2
-0
IpResourceService.java
...gec/browserbackend/browser/service/IpResourceService.java
+2
-0
BrowserTask.java
...va/com/edgec/browserbackend/browser/task/BrowserTask.java
+8
-5
JsonUtils.java
...java/com/edgec/browserbackend/common/utils/JsonUtils.java
+138
-0
No files found.
src/main/java/com/edgec/browserbackend/account/domain/Promotion.java
View file @
0e7986d5
...
...
@@ -10,6 +10,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
Promotion
{
private
String
code
;
//邀请人数
private
int
invitedUsers
;
//好友本月以前总消费
private
int
totalCommission
;
...
...
@@ -17,7 +18,9 @@ public class Promotion {
private
int
commission
;
//好友上月总消费
private
int
commissionLastMonth
;
//是否是本公司的销售
private
boolean
isSale
;
//当月礼金
private
double
gift
;
//所有未提现金额
private
double
allGift
;
...
...
src/main/java/com/edgec/browserbackend/browser/controller/IpControlloer.java
View file @
0e7986d5
...
...
@@ -3,8 +3,10 @@ package com.edgec.browserbackend.browser.controller;
import
com.edgec.browserbackend.account.dto.ResultDto
;
import
com.edgec.browserbackend.browser.dto.*
;
import
com.edgec.browserbackend.browser.service.IpResourceService
;
import
com.edgec.browserbackend.common.auth.Securitys
;
import
com.edgec.browserbackend.common.commons.error.ClientRequestException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
...
...
@@ -183,4 +185,21 @@ public class IpControlloer {
}
return
resultDto
;
}
@RequestMapping
(
value
=
"/transferbindshops"
,
method
=
RequestMethod
.
PUT
)
@PreAuthorize
(
Securitys
.
ADMIN_EL
)
public
ResultDto
transferBindShops
(
Principal
principal
)
{
ResultDto
resultDto
=
new
ResultDto
();
try
{
ipResourceService
.
transferBindShops
();
resultDto
.
setStatus
(
0
);
}
catch
(
Exception
e
)
{
resultDto
.
setStatus
(-
1
);
Map
<
String
,
Object
>
statusInfo
=
new
HashMap
<>();
statusInfo
.
put
(
"code"
,
80001
);
statusInfo
.
put
(
"message"
,
e
.
getMessage
());
resultDto
.
setStatusInfo
(
statusInfo
);
}
return
resultDto
;
}
}
src/main/java/com/edgec/browserbackend/browser/domain/IpResource.java
View file @
0e7986d5
...
...
@@ -43,7 +43,8 @@ public class IpResource implements Serializable {
private
String
proxyPassword
;
//专线的代理密码
private
String
shopId
;
private
String
shopName
;
private
List
<
String
>
shopIds
=
new
ArrayList
<>();
private
boolean
bind
;
private
boolean
isLocked
;
private
long
lockTimestamp
;
...
...
@@ -239,20 +240,12 @@ public class IpResource implements Serializable {
this
.
price
=
price
;
}
public
String
getShopId
()
{
return
shopId
;
}
public
void
setShopId
(
String
shopId
)
{
this
.
shopId
=
shopId
;
}
public
String
getShopName
()
{
return
shopName
;
public
List
<
String
>
getShopIds
()
{
return
shopIds
;
}
public
void
setShop
Name
(
String
shopName
)
{
this
.
shop
Name
=
shopName
;
public
void
setShop
Ids
(
List
<
String
>
shopIds
)
{
this
.
shop
Ids
=
shopIds
;
}
public
String
getVendorCn
()
{
...
...
@@ -302,4 +295,20 @@ public class IpResource implements Serializable {
public
void
setUsingSpecialLine
(
boolean
usingSpecialLine
)
{
this
.
usingSpecialLine
=
usingSpecialLine
;
}
public
boolean
isBind
()
{
return
bind
;
}
public
void
setBind
(
boolean
bind
)
{
this
.
bind
=
bind
;
}
public
String
getShopId
()
{
return
shopId
;
}
public
void
setShopId
(
String
shopId
)
{
this
.
shopId
=
shopId
;
}
}
src/main/java/com/edgec/browserbackend/browser/dto/IpResourceDto.java
View file @
0e7986d5
...
...
@@ -21,7 +21,8 @@ public class IpResourceDto {
private
String
details
;
private
String
password
;
private
List
<
String
>
protocol
;
ShopDto
bindShop
;
List
<
ShopDto
>
bindShops
;
private
ShopDto
bindShop
;
private
List
<
BindHistory
>
bindHistories
;
private
boolean
specialLine
;
...
...
@@ -36,7 +37,7 @@ public class IpResourceDto {
public
IpResourceDto
(){
}
public
IpResourceDto
(
IpResource
ipResource
,
ShopDto
shopDto
,
boolean
useHistory
){
public
IpResourceDto
(
IpResource
ipResource
,
List
<
ShopDto
>
shopDtos
,
boolean
useHistory
){
this
.
id
=
ipResource
.
getId
();
this
.
addr
=
ipResource
.
getAddr
();
this
.
vendor
=
ipResource
.
getVendor
();
...
...
@@ -50,15 +51,18 @@ public class IpResourceDto {
this
.
password
=
ipResource
.
getPassword
();
this
.
protocol
=
ipResource
.
getProtocol
();
this
.
specialLine
=
ipResource
.
isSpecialLine
();
if
(
shopDto
!=
null
)
this
.
bindShop
=
shopDto
;
if
(
shopDtos
!=
null
)
this
.
bindShops
=
shopDtos
;
else
this
.
bindShops
=
new
ArrayList
<>();
if
(
useHistory
)
this
.
bindHistories
=
ipResource
.
getBindHistory
();
else
this
.
bindHistories
=
new
ArrayList
<>();
this
.
bindShop
=
new
ShopDto
();
}
public
IpResourceDto
(
IpResource
ipResource
,
ShopDto
shopDto
,
boolean
useHistory
,
SpecialLine
specialLine1
){
public
IpResourceDto
(
IpResource
ipResource
,
List
<
ShopDto
>
shopDtos
,
boolean
useHistory
,
SpecialLine
specialLine1
){
this
.
id
=
ipResource
.
getId
();
this
.
addr
=
ipResource
.
getAddr
();
this
.
vendor
=
ipResource
.
getVendor
();
...
...
@@ -76,12 +80,16 @@ public class IpResourceDto {
this
.
proxyPort
=
specialLine1
.
getProxyPort
();
this
.
proxyProtocol
=
specialLine1
.
getProxyProtocol
();
this
.
specialLine
=
ipResource
.
isSpecialLine
();
this
.
bindShop
=
shopDto
;
if
(
shopDtos
!=
null
)
this
.
bindShops
=
shopDtos
;
else
this
.
bindShops
=
new
ArrayList
<>();
this
.
specialLineIp
=
specialLine1
.
getIp
();
if
(
useHistory
)
this
.
bindHistories
=
ipResource
.
getBindHistory
();
else
this
.
bindHistories
=
new
ArrayList
<>();
this
.
bindShop
=
new
ShopDto
();
}
public
String
getId
()
{
...
...
@@ -172,12 +180,12 @@ public class IpResourceDto {
this
.
password
=
password
;
}
public
ShopDto
getBindShop
()
{
return
bindShop
;
public
List
<
ShopDto
>
getBindShops
()
{
return
bindShop
s
;
}
public
void
setBindShop
(
ShopDto
bindShop
)
{
this
.
bindShop
=
bindShop
;
public
void
setBindShop
s
(
List
<
ShopDto
>
bindShops
)
{
this
.
bindShop
s
=
bindShops
;
}
public
List
<
String
>
getProtocol
()
{
...
...
@@ -243,4 +251,12 @@ public class IpResourceDto {
public
void
setProxyPort
(
List
<
String
>
proxyPort
)
{
this
.
proxyPort
=
proxyPort
;
}
public
ShopDto
getBindShop
()
{
return
bindShop
;
}
public
void
setBindShop
(
ShopDto
bindShop
)
{
this
.
bindShop
=
bindShop
;
}
}
src/main/java/com/edgec/browserbackend/browser/dto/IpResourceUnwindResultDto.java
0 → 100644
View file @
0e7986d5
package
com
.
edgec
.
browserbackend
.
browser
.
dto
;
import
com.edgec.browserbackend.browser.domain.BindHistory
;
import
com.edgec.browserbackend.browser.domain.IpResource
;
import
com.edgec.browserbackend.browser.domain.IpType
;
import
com.edgec.browserbackend.browser.domain.Vendor
;
import
org.springframework.data.annotation.Id
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
IpResourceUnwindResultDto
{
private
String
id
;
private
String
addr
;
private
IpType
ipType
=
IpType
.
VENDOR
;
private
Vendor
vendor
;
private
String
vendorCn
;
private
String
region
;
private
String
regionCn
;
//0:正常, 1:已过期, 2:即将过期, 3:正在分配, 4:未使用, 5:已失效, 6:未分配, 7:未缴费, 8:分配成功
private
int
status
;
private
List
<
String
>
port
;
private
long
purchasedTime
;
private
long
validTime
;
private
String
details
;
private
List
<
BindHistory
>
bindHistory
=
new
ArrayList
<>();
private
boolean
isDeleted
;
private
String
username
;
private
String
owner
;
private
String
userParent
;
private
List
<
String
>
protocol
;
private
String
password
;
private
double
price
;
private
boolean
specialLine
;
//是否使用专线
private
boolean
usingSpecialLine
;
//是否正在使用专线
//专线数据
private
String
proxyUsername
;
//专线的代理用户名
private
String
proxyPassword
;
//专线的代理密码
private
String
shopId
;
private
boolean
bind
;
private
boolean
isLocked
;
private
long
lockTimestamp
;
private
long
healthLockTimestamp
;
private
String
unit
;
private
int
period
;
public
String
getDetails
()
{
return
details
;
}
public
void
setDetails
(
String
details
)
{
this
.
details
=
details
;
}
public
String
getId
()
{
return
id
;
}
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
public
String
getRegion
()
{
return
region
;
}
public
void
setRegion
(
String
region
)
{
this
.
region
=
region
;
}
public
String
getRegionCn
()
{
return
regionCn
;
}
public
void
setRegionCn
(
String
regionCn
)
{
this
.
regionCn
=
regionCn
;
}
public
int
getStatus
()
{
return
status
;
}
public
void
setStatus
(
int
status
)
{
this
.
status
=
status
;
}
public
IpType
getIpType
()
{
return
ipType
;
}
public
void
setIpType
(
IpType
ipType
)
{
this
.
ipType
=
ipType
;
}
public
List
<
BindHistory
>
getBindHistory
()
{
return
bindHistory
;
}
public
void
setBindHistory
(
List
<
BindHistory
>
bindHistory
)
{
this
.
bindHistory
=
bindHistory
;
}
public
long
getPurchasedTime
()
{
return
purchasedTime
;
}
public
void
setPurchasedTime
(
long
purchasedTime
)
{
this
.
purchasedTime
=
purchasedTime
;
}
public
long
getValidTime
()
{
return
validTime
;
}
public
void
setValidTime
(
long
validTime
)
{
this
.
validTime
=
validTime
;
}
public
Vendor
getVendor
()
{
return
vendor
;
}
public
void
setVendor
(
Vendor
vendor
)
{
this
.
vendor
=
vendor
;
}
public
boolean
isDeleted
()
{
return
isDeleted
;
}
public
void
setDeleted
(
boolean
deleted
)
{
isDeleted
=
deleted
;
}
public
String
getUsername
()
{
return
username
;
}
public
void
setUsername
(
String
username
)
{
this
.
username
=
username
;
}
public
List
<
String
>
getPort
()
{
return
port
;
}
public
void
setPort
(
List
<
String
>
port
)
{
this
.
port
=
port
;
}
public
String
getAddr
()
{
return
addr
;
}
public
void
setAddr
(
String
addr
)
{
this
.
addr
=
addr
;
}
public
String
getUserParent
()
{
return
userParent
;
}
public
void
setUserParent
(
String
userParent
)
{
this
.
userParent
=
userParent
;
}
public
List
<
String
>
getProtocol
()
{
return
protocol
;
}
public
void
setProtocol
(
List
<
String
>
protocol
)
{
this
.
protocol
=
protocol
;
}
public
String
getPassword
()
{
return
password
;
}
public
void
setPassword
(
String
password
)
{
this
.
password
=
password
;
}
public
String
getOwner
()
{
return
owner
;
}
public
void
setOwner
(
String
owner
)
{
this
.
owner
=
owner
;
}
public
boolean
isLocked
()
{
return
isLocked
;
}
public
void
setLocked
(
boolean
locked
)
{
isLocked
=
locked
;
}
public
long
getLockTimestamp
()
{
return
lockTimestamp
;
}
public
void
setLockTimestamp
(
long
lockTimestamp
)
{
this
.
lockTimestamp
=
lockTimestamp
;
}
public
String
getUnit
()
{
return
unit
;
}
public
void
setUnit
(
String
unit
)
{
this
.
unit
=
unit
;
}
public
int
getPeriod
()
{
return
period
;
}
public
void
setPeriod
(
int
period
)
{
this
.
period
=
period
;
}
public
double
getPrice
()
{
return
price
;
}
public
void
setPrice
(
double
price
)
{
this
.
price
=
price
;
}
public
String
getShopId
()
{
return
shopId
;
}
public
void
setShopId
(
String
shopId
)
{
this
.
shopId
=
shopId
;
}
public
String
getVendorCn
()
{
return
vendorCn
;
}
public
void
setVendorCn
(
String
vendorCn
)
{
this
.
vendorCn
=
vendorCn
;
}
public
String
getProxyPassword
()
{
return
proxyPassword
;
}
public
void
setProxyPassword
(
String
proxyPassword
)
{
this
.
proxyPassword
=
proxyPassword
;
}
public
String
getProxyUsername
()
{
return
proxyUsername
;
}
public
void
setProxyUsername
(
String
proxyUsername
)
{
this
.
proxyUsername
=
proxyUsername
;
}
public
boolean
isSpecialLine
()
{
return
specialLine
;
}
public
void
setSpecialLine
(
boolean
specialLine
)
{
this
.
specialLine
=
specialLine
;
}
public
long
getHealthLockTimestamp
()
{
return
healthLockTimestamp
;
}
public
void
setHealthLockTimestamp
(
long
healthLockTimestamp
)
{
this
.
healthLockTimestamp
=
healthLockTimestamp
;
}
public
boolean
isUsingSpecialLine
()
{
return
usingSpecialLine
;
}
public
void
setUsingSpecialLine
(
boolean
usingSpecialLine
)
{
this
.
usingSpecialLine
=
usingSpecialLine
;
}
public
boolean
isBind
()
{
return
bind
;
}
public
void
setBind
(
boolean
bind
)
{
this
.
bind
=
bind
;
}
public
IpResource
toResource
()
{
IpResource
ipResource
=
new
IpResource
();
ipResource
.
setId
(
getId
());
if
(
shopId
!=
null
)
ipResource
.
getShopIds
().
add
(
getShopId
());
ipResource
.
setHealthLockTimestamp
(
getHealthLockTimestamp
());
ipResource
.
setUsingSpecialLine
(
isUsingSpecialLine
());
ipResource
.
setPeriod
(
getPeriod
());
ipResource
.
setSpecialLine
(
isSpecialLine
());
if
(
addr
!=
null
)
ipResource
.
setAddr
(
getAddr
());
ipResource
.
setStatus
(
getStatus
());
if
(
proxyPassword
!=
null
)
ipResource
.
setProxyPassword
(
getProxyPassword
());
if
(
proxyUsername
!=
null
)
ipResource
.
setProxyUsername
(
getProxyUsername
());
ipResource
.
setLockTimestamp
(
getLockTimestamp
());
if
(
username
!=
null
)
ipResource
.
setUsername
(
getUsername
());
if
(
regionCn
!=
null
)
ipResource
.
setRegionCn
(
getRegionCn
());
if
(
vendorCn
!=
null
)
ipResource
.
setVendorCn
(
getVendorCn
());
if
(
password
!=
null
)
ipResource
.
setPassword
(
getPassword
());
if
(
unit
!=
null
)
ipResource
.
setUnit
(
getUnit
());
ipResource
.
setLocked
(
isLocked
());
ipResource
.
setValidTime
(
getValidTime
());
if
(
bindHistory
!=
null
)
ipResource
.
setBindHistory
(
getBindHistory
());
ipResource
.
setDeleted
(
isDeleted
());
if
(
owner
!=
null
)
ipResource
.
setOwner
(
getOwner
());
if
(
protocol
!=
null
)
ipResource
.
setProtocol
(
getProtocol
());
if
(
userParent
!=
null
)
ipResource
.
setUserParent
(
getUserParent
());
ipResource
.
setPurchasedTime
(
getPurchasedTime
());
ipResource
.
setIpType
(
getIpType
());
if
(
port
!=
null
)
ipResource
.
setPort
(
getPort
());
ipResource
.
setPrice
(
getPrice
());
if
(
details
!=
null
)
ipResource
.
setDetails
(
getDetails
());
return
ipResource
;
}
}
src/main/java/com/edgec/browserbackend/browser/dto/ShopResultDto.java
View file @
0e7986d5
...
...
@@ -6,6 +6,11 @@ import com.edgec.browserbackend.browser.domain.Shop;
import
com.edgec.browserbackend.browser.domain.TransferStatus
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
com.google.gson.JsonObject
;
import
org.elasticsearch.client.license.LicensesStatus
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Stack
;
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
ShopResultDto
{
...
...
@@ -36,7 +41,7 @@ public class ShopResultDto {
private
long
createTime
;
public
static
ShopResultDto
of
(
Shop
shop
,
String
group
,
IpResourceDto
ipResource
s
)
{
public
static
ShopResultDto
of
(
Shop
shop
,
String
group
,
IpResourceDto
ipResource
)
{
ShopResultDto
shopResultDto
=
new
ShopResultDto
();
shopResultDto
.
setShopId
(
shop
.
getShopId
());
if
(
shop
.
getShopName
()
!=
null
)
...
...
@@ -58,7 +63,7 @@ public class ShopResultDto {
if
(
shop
.
getShopAccount
()
!=
null
)
shopResultDto
.
setShopAccount
(
shop
.
getShopAccount
());
shopResultDto
.
setGroup
(
group
);
shopResultDto
.
setBindIp
(
ipResource
s
);
shopResultDto
.
setBindIp
(
ipResource
);
shopResultDto
.
setCreateTime
(
shop
.
getCreateTime
());
return
shopResultDto
;
}
...
...
src/main/java/com/edgec/browserbackend/browser/repository/IpResourceRepository.java
View file @
0e7986d5
...
...
@@ -17,20 +17,19 @@ public interface IpResourceRepository extends MongoRepository<IpResource, String
IpResource
findByAddrAndIsDeleted
(
String
addr
,
boolean
isDeleted
);
IpResource
findByIdAndIsDeletedAndIsLocked
(
String
id
,
boolean
isDeleted
,
boolean
isLocked
);
IpResource
findByIdAndIsDeleted
(
String
id
,
boolean
isDeleted
);
List
<
IpResource
>
findByShopIdInAndIsDeleted
(
List
<
String
>
ipIds
,
boolean
isDeleted
);
Page
<
IpResource
>
findByIdInAndIsDeletedOrderByPurchasedTimeDesc
(
List
<
String
>
ipIds
,
boolean
isDeleted
,
Pageable
pageable
);
List
<
IpResource
>
findByOwnerAndIsDeletedAnd
ShopIdIsNull
(
String
owner
,
boolean
isDelete
d
);
List
<
IpResource
>
findByOwnerAndStatusIsNotInAndIsDeletedAnd
ShopIdIsNull
(
String
owner
,
List
<
Integer
>
status
,
boolean
isDelete
d
);
List
<
IpResource
>
findByOwnerAndStatusAndIsDeletedAnd
ShopIdIsNull
(
String
owner
,
int
status
,
boolean
isDelete
d
);
List
<
IpResource
>
findByOwnerInAndIsDeletedAnd
ShopIdIsNull
(
List
<
String
>
owner
,
boolean
isDelete
d
);
List
<
IpResource
>
findByOwnerInAndStatusIsNotInAndIsDeletedAnd
ShopIdIsNull
(
List
<
String
>
owner
,
List
<
Integer
>
status
,
boolean
isDelete
d
);
List
<
IpResource
>
findByOwnerInAndStatusAndIsDeletedAnd
ShopIdIsNull
(
List
<
String
>
owner
,
int
status
,
boolean
isDelete
d
);
List
<
IpResource
>
findByStatusAndShopIdInAndIsDeleted
(
int
status
,
List
<
String
>
ipIds
,
boolean
isDeleted
);
List
<
IpResource
>
findByOwnerAndIsDeletedAnd
Bind
(
String
owner
,
boolean
isDeleted
,
boolean
bin
d
);
List
<
IpResource
>
findByOwnerAndStatusIsNotInAndIsDeletedAnd
Bind
(
String
owner
,
List
<
Integer
>
status
,
boolean
isDeleted
,
boolean
bin
d
);
List
<
IpResource
>
findByOwnerAndStatusAndIsDeletedAnd
Bind
(
String
owner
,
int
status
,
boolean
isDeleted
,
boolean
bin
d
);
List
<
IpResource
>
findByOwnerInAndIsDeletedAnd
Bind
(
List
<
String
>
owner
,
boolean
isDeleted
,
boolean
bin
d
);
List
<
IpResource
>
findByOwnerInAndStatusIsNotInAndIsDeletedAnd
Bind
(
List
<
String
>
owner
,
List
<
Integer
>
status
,
boolean
isDeleted
,
boolean
bin
d
);
List
<
IpResource
>
findByOwnerInAndStatusAndIsDeletedAnd
Bind
(
List
<
String
>
owner
,
int
status
,
boolean
isDeleted
,
boolean
bin
d
);
Page
<
IpResource
>
findByIsDeletedAndIdInAndAddrLikeOrderByPurchasedTimeDesc
(
boolean
isDeleted
,
List
<
String
>
ipIds
,
String
addr
,
Pageable
pageable
);
Page
<
IpResource
>
findByIsDeletedAndIdInAndVendorCnLikeOrderByPurchasedTimeDesc
(
boolean
isDeleted
,
List
<
String
>
ipIds
,
String
vendorCn
,
Pageable
pageable
);
Page
<
IpResource
>
findByIsDeletedAndIdInAndVendorLikeOrderByPurchasedTimeDesc
(
boolean
isDeleted
,
List
<
String
>
ipIds
,
String
vendor
,
Pageable
pageable
);
Page
<
IpResource
>
findByIsDeletedAndIdInAndRegionCnLikeOrderByPurchasedTimeDesc
(
boolean
isDeleted
,
List
<
String
>
ipIds
,
String
region
,
Pageable
pageable
);
List
<
IpResource
>
findByIsDeletedAndShopIdInAndRegionCnLike
(
boolean
isDeleted
,
List
<
String
>
shopIds
,
String
regionCn
);
List
<
IpResource
>
findByIsDeleted
(
boolean
isDeleted
);
...
...
@@ -43,7 +42,7 @@ public interface IpResourceRepository extends MongoRepository<IpResource, String
List
<
IpResource
>
findByValidTimeBetweenAndIsDeleted
(
long
beginTime
,
long
endTime
,
boolean
isDeleted
);
IpResource
findFirstByShopIdAndIsDeleted
(
String
shopId
,
boolean
isDeleted
);
IpResource
findFirstByShopId
sIs
AndIsDeleted
(
String
shopId
,
boolean
isDeleted
);
int
countByStatusAndIdInAndIsDeleted
(
int
status
,
List
<
String
>
ipIds
,
boolean
isDeleted
);
...
...
src/main/java/com/edgec/browserbackend/browser/repository/IpResourceRepositoryCustom.java
View file @
0e7986d5
package
com
.
edgec
.
browserbackend
.
browser
.
repository
;
import
com.edgec.browserbackend.browser.domain.BindHistory
;
import
com.edgec.browserbackend.browser.domain.IpResource
;
import
java.util.List
;
...
...
@@ -17,4 +18,18 @@ public interface IpResourceRepositoryCustom {
List
<
IpResource
>
sampleTasks
(
int
status
,
long
timestamp
);
List
<
IpResource
>
sampleTasks
(
List
<
Integer
>
status
);
boolean
addShopId
(
String
ipId
,
String
shopId
);
boolean
deleteShopId
(
String
ipId
,
String
shopId
,
BindHistory
bindHistory
);
boolean
updateStatus
(
String
id
,
int
status
);
boolean
updateBind
(
String
id
,
boolean
isbind
);
List
<
IpResource
>
findShopIdInList
(
List
<
String
>
shopIds
,
boolean
isDeleted
);
List
<
IpResource
>
findShopIdInListAndStatus
(
List
<
String
>
shopIds
,
boolean
isDeleted
,
int
status
);
List
<
IpResource
>
findShopIdInListAndRegionLike
(
List
<
String
>
shopIds
,
boolean
isDeleted
,
String
region
);
}
src/main/java/com/edgec/browserbackend/browser/repository/IpResourceRepositoryCustomImpl.java
View file @
0e7986d5
package
com
.
edgec
.
browserbackend
.
browser
.
repository
;
import
com.edgec.browserbackend.browser.domain.BindHistory
;
import
com.edgec.browserbackend.browser.domain.IpResource
;
import
com.edgec.browserbackend.browser.dto.IpResourceUnwindResultDto
;
import
com.edgec.browserbackend.common.utils.JsonUtils
;
import
com.mongodb.client.result.UpdateResult
;
import
org.apache.commons.lang3.StringUtils
;
import
org.bson.Document
;
import
org.elasticsearch.common.recycler.Recycler
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.mongodb.core.MongoTemplate
;
import
org.springframework.data.mongodb.core.aggregation.Aggregation
;
import
org.springframework.data.mongodb.core.aggregation.AggregationResults
;
import
org.springframework.data.mongodb.core.aggregation.MatchOperation
;
import
org.springframework.data.mongodb.core.aggregation.SampleOperation
;
import
org.springframework.data.mongodb.core.aggregation.*
;
import
org.springframework.data.mongodb.core.query.BasicQuery
;
import
org.springframework.data.mongodb.core.query.Criteria
;
import
org.springframework.data.mongodb.core.query.CriteriaDefinition
;
import
org.springframework.data.mongodb.core.query.Update
;
import
java.time.Instant
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.*
;
import
static
org
.
springframework
.
data
.
mongodb
.
core
.
query
.
Criteria
.
where
;
...
...
@@ -124,4 +123,142 @@ public class IpResourceRepositoryCustomImpl implements IpResourceRepositoryCusto
return
mappedResults
;
}
@Override
public
boolean
addShopId
(
String
ipId
,
String
shopId
)
{
Document
doc
=
new
Document
();
BasicQuery
basicQuery
=
new
BasicQuery
(
doc
);
basicQuery
.
addCriteria
(
where
(
"id"
).
is
(
ipId
).
and
(
"isDeleted"
).
is
(
false
));
Update
update
=
new
Update
();
update
.
push
(
"shopIds"
,
shopId
);
update
.
set
(
"bind"
,
true
);
UpdateResult
result
=
mongoTemplate
.
updateFirst
(
basicQuery
,
update
,
IpResource
.
class
);
if
(
result
.
getModifiedCount
()
<
1
)
return
false
;
else
return
true
;
}
@Override
public
boolean
deleteShopId
(
String
ipId
,
String
shopId
,
BindHistory
bindHistory
)
{
Document
doc
=
new
Document
();
BasicQuery
basicQuery
=
new
BasicQuery
(
doc
);
basicQuery
.
addCriteria
(
where
(
"id"
).
is
(
ipId
).
and
(
"isDeleted"
).
is
(
false
));
Update
update
=
new
Update
();
update
.
pull
(
"shopIds"
,
shopId
).
push
(
"bindhistory"
,
bindHistory
);
UpdateResult
result
=
mongoTemplate
.
updateFirst
(
basicQuery
,
update
,
IpResource
.
class
);
if
(
result
.
getModifiedCount
()
<
1
)
return
false
;
else
return
true
;
}
@Override
public
boolean
updateStatus
(
String
id
,
int
status
)
{
Document
doc
=
new
Document
();
BasicQuery
basicQuery
=
new
BasicQuery
(
doc
);
basicQuery
.
addCriteria
(
where
(
"id"
).
is
(
id
).
and
(
"isDeleted"
).
is
(
false
));
Update
update
=
new
Update
();
update
.
set
(
"status"
,
status
);
UpdateResult
result
=
mongoTemplate
.
updateFirst
(
basicQuery
,
update
,
IpResource
.
class
);
if
(
result
.
getModifiedCount
()
<
1
)
return
false
;
else
return
true
;
}
@Override
public
boolean
updateBind
(
String
id
,
boolean
isbind
)
{
Document
doc
=
new
Document
();
BasicQuery
basicQuery
=
new
BasicQuery
(
doc
);
basicQuery
.
addCriteria
(
where
(
"id"
).
is
(
id
).
and
(
"isDeleted"
).
is
(
false
));
Update
update
=
new
Update
();
update
.
set
(
"bind"
,
isbind
);
UpdateResult
result
=
mongoTemplate
.
updateFirst
(
basicQuery
,
update
,
IpResource
.
class
);
if
(
result
.
getModifiedCount
()
<
1
)
return
false
;
else
return
true
;
}
@Override
public
List
<
IpResource
>
findShopIdInList
(
List
<
String
>
shopIds
,
boolean
isDeleted
)
{
MatchOperation
matchOperation
=
Aggregation
.
match
(
where
(
"isDeleted"
).
is
(
isDeleted
));
UnwindOperation
unwind
=
Aggregation
.
unwind
(
"shopIds"
);
MatchOperation
matchshopId
=
Aggregation
.
match
(
where
(
"shopIds"
).
in
(
shopIds
));
List
<
IpResourceUnwindResultDto
>
ipResourceUnwindResultDtos
=
mongoTemplate
.
aggregate
(
Aggregation
.
newAggregation
(
matchOperation
,
unwind
,
matchshopId
),
IpResource
.
class
,
IpResourceUnwindResultDto
.
class
).
getMappedResults
();
if
(
ipResourceUnwindResultDtos
.
isEmpty
())
{
return
new
ArrayList
<>();
}
HashMap
<
String
,
IpResource
>
ipResourceHashMap
=
new
HashMap
<>();
ipResourceUnwindResultDtos
.
forEach
(
x
->
{
if
(
ipResourceHashMap
.
containsKey
(
x
.
getId
()))
{
ipResourceHashMap
.
get
(
x
.
getId
()).
getShopIds
().
add
(
x
.
getShopId
());
}
else
{
ipResourceHashMap
.
put
(
x
.
getId
(),
x
.
toResource
());
}
});
List
<
IpResource
>
result
=
new
ArrayList
<>();
Set
<
Map
.
Entry
<
String
,
IpResource
>>
entry
=
ipResourceHashMap
.
entrySet
();
for
(
Map
.
Entry
<
String
,
IpResource
>
e:
entry
){
result
.
add
(
e
.
getValue
());
}
return
result
;
}
@Override
public
List
<
IpResource
>
findShopIdInListAndStatus
(
List
<
String
>
shopIds
,
boolean
isDeleted
,
int
status
)
{
MatchOperation
matchOperation
=
Aggregation
.
match
(
where
(
"isDeleted"
).
is
(
isDeleted
).
and
(
"status"
).
is
(
status
));
UnwindOperation
unwind
=
Aggregation
.
unwind
(
"shopIds"
);
MatchOperation
matchshopId
=
Aggregation
.
match
(
where
(
"shopIds"
).
in
(
shopIds
));
List
<
IpResourceUnwindResultDto
>
ipResourceUnwindResultDtos
=
mongoTemplate
.
aggregate
(
Aggregation
.
newAggregation
(
matchOperation
,
unwind
,
matchshopId
),
IpResource
.
class
,
IpResourceUnwindResultDto
.
class
).
getMappedResults
();
if
(
ipResourceUnwindResultDtos
.
isEmpty
())
{
return
new
ArrayList
<>();
}
HashMap
<
String
,
IpResource
>
ipResourceHashMap
=
new
HashMap
<>();
ipResourceUnwindResultDtos
.
forEach
(
x
->
{
if
(
ipResourceHashMap
.
containsKey
(
x
.
getId
()))
{
ipResourceHashMap
.
get
(
x
.
getId
()).
getShopIds
().
add
(
x
.
getShopId
());
}
else
{
ipResourceHashMap
.
put
(
x
.
getId
(),
x
.
toResource
());
}
});
List
<
IpResource
>
result
=
new
ArrayList
<>();
Set
<
Map
.
Entry
<
String
,
IpResource
>>
entry
=
ipResourceHashMap
.
entrySet
();
for
(
Map
.
Entry
<
String
,
IpResource
>
e:
entry
){
result
.
add
(
e
.
getValue
());
}
return
result
;
}
@Override
public
List
<
IpResource
>
findShopIdInListAndRegionLike
(
List
<
String
>
shopIds
,
boolean
isDeleted
,
String
region
)
{
MatchOperation
matchOperation
=
Aggregation
.
match
(
where
(
"isDeleted"
).
is
(
isDeleted
).
and
(
"regionCn"
).
regex
(
".*?\\"
+
region
+
".*"
));
UnwindOperation
unwind
=
Aggregation
.
unwind
(
"shopIds"
);
MatchOperation
matchshopId
=
Aggregation
.
match
(
where
(
"shopIds"
).
in
(
shopIds
));
List
<
IpResourceUnwindResultDto
>
ipResourceUnwindResultDtos
=
mongoTemplate
.
aggregate
(
Aggregation
.
newAggregation
(
matchOperation
,
unwind
,
matchshopId
),
IpResource
.
class
,
IpResourceUnwindResultDto
.
class
).
getMappedResults
();
if
(
ipResourceUnwindResultDtos
.
isEmpty
())
{
return
new
ArrayList
<>();
}
HashMap
<
String
,
IpResource
>
ipResourceHashMap
=
new
HashMap
<>();
ipResourceUnwindResultDtos
.
forEach
(
x
->
{
if
(
ipResourceHashMap
.
containsKey
(
x
.
getId
()))
{
ipResourceHashMap
.
get
(
x
.
getId
()).
getShopIds
().
add
(
x
.
getShopId
());
}
else
{
ipResourceHashMap
.
put
(
x
.
getId
(),
x
.
toResource
());
}
});
List
<
IpResource
>
result
=
new
ArrayList
<>();
Set
<
Map
.
Entry
<
String
,
IpResource
>>
entry
=
ipResourceHashMap
.
entrySet
();
for
(
Map
.
Entry
<
String
,
IpResource
>
e:
entry
){
result
.
add
(
e
.
getValue
());
}
return
result
;
}
}
src/main/java/com/edgec/browserbackend/browser/repository/ShopRepository.java
View file @
0e7986d5
...
...
@@ -11,4 +11,5 @@ public interface ShopRepository extends MongoRepository<Shop, String> {
Page
<
Shop
>
findByShopIdInAndShopAccountLikeOrderByCreateTimeDesc
(
List
<
String
>
shopIds
,
String
shopAccount
,
Pageable
pageable
);
Page
<
Shop
>
findByShopIdInAndShopNameLikeOrderByCreateTimeDesc
(
List
<
String
>
shopIds
,
String
shopName
,
Pageable
pageable
);
Page
<
Shop
>
findByShopIdInOrderByCreateTimeDesc
(
List
<
String
>
shopIds
,
Pageable
pageable
);
List
<
Shop
>
findByShopIdIn
(
List
<
String
>
shopIds
);
}
src/main/java/com/edgec/browserbackend/browser/service/Impl/IpAndShopServiceImpl.java
View file @
0e7986d5
...
...
@@ -65,16 +65,12 @@ public class IpAndShopServiceImpl implements IpAndShopService {
if
(
ipResource
==
null
)
throw
new
ClientRequestException
(
BrowserErrorCode
.
IPNOTEXIST
);
IpResource
bind
=
ipResourceRepository
.
findFirstByShopIdAndIsDeleted
(
shopId
,
false
);
IpResource
bind
=
ipResourceRepository
.
findFirstByShopId
sIs
AndIsDeleted
(
shopId
,
false
);
if
(
bind
!=
null
)
{
shopRequestDto
.
setShopId
(
shopId
);
shopRequestDto
.
setIpId
(
ipResource
.
getId
());
unBindShop
(
username
,
shopRequestDto
);
return
;
}
try
{
ipResource
.
setShopId
(
shop
.
getShopId
());
ipResource
.
setShopName
(
shop
.
getShopName
());
ipResourceRepository
.
save
(
ipResource
);
ipResourceRepository
.
addShopId
(
ipResource
.
getId
(),
shopId
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"fail to bind shop and ip"
,
e
.
getMessage
());
throw
new
ClientRequestException
(
BrowserErrorCode
.
UNKNOWN
);
...
...
@@ -105,22 +101,65 @@ public class IpAndShopServiceImpl implements IpAndShopService {
}
if
(
ipResource
==
null
)
throw
new
ClientRequestException
(
BrowserErrorCode
.
IPNOTEXIST
);
if
(
ipResource
.
getShopId
()
==
null
&&
!
ipResource
.
getShopId
().
equal
s
(
shop
.
getShopId
()))
if
(
ipResource
.
getShopId
s
()
==
null
&&
!
ipResource
.
getShopIds
().
contain
s
(
shop
.
getShopId
()))
throw
new
ClientRequestException
(
BrowserErrorCode
.
IPNOTBINDTOSHOP
);
try
{
List
<
BindHistory
>
history
=
ipResource
.
getBindHistory
();
BindHistory
bindHistory
=
new
BindHistory
();
bindHistory
.
setIp
(
ipResource
.
getAddr
());
bindHistory
.
setPlatform
(
shop
.
getShopPlatform
());
bindHistory
.
setShopName
(
shop
.
getShopName
());
bindHistory
.
setUnbindTime
(
ZonedDateTime
.
now
().
format
(
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm:ss"
)));
history
.
add
(
bindHistory
);
ipResource
.
setShopId
(
null
);
i
pResource
.
setShopName
(
null
);
ipResourceRepository
.
save
(
ipResourc
e
);
ipResourceRepository
.
deleteShopId
(
ipResource
.
getId
(),
shopId
,
bindHistory
);
IpResource
newIp
=
ipResourceRepository
.
findById
(
ipResource
.
getId
()).
orElse
(
null
);
i
f
(
newIp
.
getShopIds
()
==
null
||
newIp
.
getShopIds
().
size
()
==
0
)
ipResourceRepository
.
updateBind
(
ipResource
.
getId
(),
fals
e
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"fail to unbind"
,
e
.
getMessage
());
throw
new
ClientRequestException
(
BrowserErrorCode
.
UNKNOWN
);
}
}
@Override
public
void
unBindShops
(
String
username
,
ShopRequestDto
shopRequestDto
)
{
List
<
String
>
shopIds
=
null
;
if
(
shopRequestDto
.
getShopIds
()
!=
null
&&
shopRequestDto
.
getShopIds
().
size
()
>
0
)
shopIds
=
shopRequestDto
.
getShopIds
();
Account
account
=
accountRepository
.
findByName
(
username
);
if
(
account
==
null
)
{
throw
new
ClientRequestException
(
AccountErrorCode
.
NAMENOTEXIST
);
}
IpResource
ipResource
=
null
;
if
(
StringUtils
.
isNotBlank
(
shopRequestDto
.
getIpAddr
()))
{
ipResource
=
ipResourceRepository
.
findByAddrAndIsDeleted
(
shopRequestDto
.
getIpAddr
(),
false
);
}
else
if
(
StringUtils
.
isNotBlank
(
shopRequestDto
.
getIpId
()))
{
ipResource
=
ipResourceRepository
.
findByIdAndIsDeleted
(
shopRequestDto
.
getIpId
(),
false
);
}
if
(
ipResource
==
null
)
throw
new
ClientRequestException
(
BrowserErrorCode
.
IPNOTEXIST
);
for
(
String
shopId
:
shopIds
)
{
UserShop
userShop
=
userShopRepository
.
findByUsernameAndShopId
(
username
,
shopId
);
if
(
account
.
getPermission
()
<
4
||
userShop
==
null
)
{
continue
;
}
Shop
shop
=
shopRepository
.
findById
(
shopId
).
orElse
(
null
);
if
(
shop
==
null
)
continue
;
if
(
ipResource
.
getShopIds
()
==
null
&&
!
ipResource
.
getShopIds
().
contains
(
shop
.
getShopId
()))
continue
;
try
{
BindHistory
bindHistory
=
new
BindHistory
();
bindHistory
.
setIp
(
ipResource
.
getAddr
());
bindHistory
.
setPlatform
(
shop
.
getShopPlatform
());
bindHistory
.
setShopName
(
shop
.
getShopName
());
bindHistory
.
setUnbindTime
(
ZonedDateTime
.
now
().
format
(
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm:ss"
)));
ipResourceRepository
.
deleteShopId
(
ipResource
.
getId
(),
shopId
,
bindHistory
);
IpResource
newIp
=
ipResourceRepository
.
findById
(
ipResource
.
getId
()).
orElse
(
null
);
if
(
newIp
.
getShopIds
()
==
null
||
newIp
.
getShopIds
().
size
()
==
0
)
ipResourceRepository
.
updateBind
(
ipResource
.
getId
(),
false
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"fail to unbind"
,
e
.
getMessage
());
throw
new
ClientRequestException
(
BrowserErrorCode
.
UNKNOWN
);
}
}
}
}
src/main/java/com/edgec/browserbackend/browser/service/Impl/IpResourceServiceImpl.java
View file @
0e7986d5
...
...
@@ -466,8 +466,10 @@ public class IpResourceServiceImpl implements IpResourceService {
}
UserShop
userShop
=
null
;
if
(
ipResource
.
getShopId
()
!=
null
)
{
Shop
shop
=
shopRepository
.
findById
(
ipResource
.
getShopId
()).
orElse
(
null
);
if
(
ipResource
.
getShopIds
()
!=
null
)
{
List
<
Shop
>
shops
=
shopRepository
.
findByShopIdIn
(
ipResource
.
getShopIds
());
if
(
shops
!=
null
&&
shops
.
size
()
>
0
)
{
for
(
Shop
shop
:
shops
)
{
if
(
shop
!=
null
)
{
userShop
=
userShopRepository
.
findByUsernameAndShopId
(
username
,
shop
.
getShopId
());
if
(
userShop
==
null
)
{
...
...
@@ -479,6 +481,8 @@ public class IpResourceServiceImpl implements IpResourceService {
return
;
}
}
}
}
try
{
ResponseEntity
<
String
>
result
=
restTemplate
.
exchange
(
URL
+
"/intelligroup/ipresources?accountId=browser&ip={ip}"
,
HttpMethod
.
DELETE
,
httpEntity
,
String
.
class
,
ipAddr
);
DeleteIpResultDto
deleteIpResultDto
=
JSON
.
parseObject
(
result
.
getBody
(),
DeleteIpResultDto
.
class
);
...
...
@@ -490,8 +494,7 @@ public class IpResourceServiceImpl implements IpResourceService {
if
(
ipResource
.
getStatus
()
==
6
)
ipResourceRepository
.
delete
(
ipResource
);
else
{
ipResource
.
setShopId
(
null
);
ipResource
.
setShopName
(
null
);
ipResource
.
setShopIds
(
null
);
ipResource
.
setDeleted
(
true
);
ipResourceRepository
.
save
(
ipResource
);
}
...
...
@@ -522,8 +525,10 @@ public class IpResourceServiceImpl implements IpResourceService {
}
}
UserShop
userShop
=
null
;
if
(
ipResource
.
getShopId
()
!=
null
)
{
Shop
shop
=
shopRepository
.
findById
(
ipResource
.
getShopId
()).
orElse
(
null
);
if
(
ipResource
.
getShopIds
()
!=
null
)
{
List
<
Shop
>
shops
=
shopRepository
.
findByShopIdIn
(
ipResource
.
getShopIds
());
if
(
shops
!=
null
&&
shops
.
size
()
>
0
)
{
for
(
Shop
shop
:
shops
)
{
if
(
shop
!=
null
)
{
userShop
=
userShopRepository
.
findByUsernameAndShopId
(
username
,
shop
.
getShopId
());
if
(
userShop
==
null
)
{
...
...
@@ -535,9 +540,10 @@ public class IpResourceServiceImpl implements IpResourceService {
return
;
}
}
}
}
ipResource
.
setDeleted
(
true
);
ipResource
.
setShopId
(
null
);
ipResource
.
setShopName
(
null
);
ipResource
.
setShopIds
(
null
);
ipResourceRepository
.
save
(
ipResource
);
ipOperationResultDto
.
getSuccessList
().
add
(
ipId
);
});
...
...
@@ -570,31 +576,31 @@ public class IpResourceServiceImpl implements IpResourceService {
switch
(
groupType
)
{
case
1
:
ipResources
=
ipResourceRepository
.
find
ByShopIdInAndIsDeleted
(
shopIds
,
false
);
ipResources
=
ipResourceRepository
.
find
ShopIdInList
(
shopIds
,
false
);
if
(!
isParent
)
notUsed
=
ipResourceRepository
.
findByOwnerAndIsDeletedAnd
ShopIdIsNull
(
usernam
e
,
false
);
notUsed
=
ipResourceRepository
.
findByOwnerAndIsDeletedAnd
Bind
(
username
,
fals
e
,
false
);
else
notUsed
=
ipResourceRepository
.
findByOwnerInAndIsDeletedAnd
ShopIdIsNull
(
children
,
false
);
notUsed
=
ipResourceRepository
.
findByOwnerInAndIsDeletedAnd
Bind
(
children
,
false
,
false
);
break
;
case
2
:
ipResources
=
ipResourceRepository
.
find
ByStatusAndShopIdInAndIsDeleted
(
2
,
shopIds
,
false
);
ipResources
=
ipResourceRepository
.
find
ShopIdInListAndStatus
(
shopIds
,
false
,
2
);
if
(!
isParent
)
notUsed
=
ipResourceRepository
.
findByOwnerAndStatusAndIsDeletedAnd
ShopIdIsNull
(
username
,
2
,
false
);
notUsed
=
ipResourceRepository
.
findByOwnerAndStatusAndIsDeletedAnd
Bind
(
username
,
2
,
false
,
false
);
else
notUsed
=
ipResourceRepository
.
findByOwnerInAndStatusAndIsDeletedAnd
ShopIdIsNull
(
children
,
2
,
false
);
notUsed
=
ipResourceRepository
.
findByOwnerInAndStatusAndIsDeletedAnd
Bind
(
children
,
2
,
false
,
false
);
break
;
case
3
:
ipResources
=
ipResourceRepository
.
find
ByStatusAndShopIdInAndIsDeleted
(
1
,
shopIds
,
false
);
ipResources
=
ipResourceRepository
.
find
ShopIdInListAndStatus
(
shopIds
,
false
,
1
);
if
(!
isParent
)
notUsed
=
ipResourceRepository
.
findByOwnerAndStatusAndIsDeletedAnd
ShopIdIsNull
(
username
,
1
,
false
);
notUsed
=
ipResourceRepository
.
findByOwnerAndStatusAndIsDeletedAnd
Bind
(
username
,
1
,
false
,
false
);
else
notUsed
=
ipResourceRepository
.
findByOwnerInAndStatusAndIsDeletedAnd
ShopIdIsNull
(
children
,
1
,
false
);
notUsed
=
ipResourceRepository
.
findByOwnerInAndStatusAndIsDeletedAnd
Bind
(
children
,
1
,
false
,
false
);
break
;
case
4
:
if
(!
isParent
)
notUsed
=
ipResourceRepository
.
findByOwnerAndStatusIsNotInAndIsDeletedAnd
ShopIdIsNull
(
username
,
Arrays
.
asList
(
3
,
5
,
6
),
false
);
notUsed
=
ipResourceRepository
.
findByOwnerAndStatusIsNotInAndIsDeletedAnd
Bind
(
username
,
Arrays
.
asList
(
3
,
5
,
6
),
false
,
false
);
else
notUsed
=
ipResourceRepository
.
findByOwnerInAndStatusIsNotInAndIsDeletedAnd
ShopIdIsNull
(
children
,
Arrays
.
asList
(
3
,
5
,
6
)
,
false
);
notUsed
=
ipResourceRepository
.
findByOwnerInAndStatusIsNotInAndIsDeletedAnd
Bind
(
children
,
Arrays
.
asList
(
3
,
5
,
6
),
false
,
false
);
break
;
}
if
(
notUsed
!=
null
)
...
...
@@ -615,14 +621,16 @@ public class IpResourceServiceImpl implements IpResourceService {
}
if
(
ipResources1
!=
null
)
{
ipResources1
.
getContent
().
forEach
(
x
->
{
ShopDto
shopDto
;
Shop
shop
=
null
;
if
(
x
.
getShopId
()
!=
null
)
shop
=
shopRepository
.
findById
(
x
.
getShopId
()).
orElse
(
null
);
if
(
shop
==
null
)
{
shopDto
=
new
ShopDto
(
);
List
<
ShopDto
>
shopDtos
=
new
ArrayList
<>()
;
List
<
Shop
>
shops
=
null
;
if
(
x
.
getShopId
s
()
!=
null
)
shop
s
=
shopRepository
.
findByShopIdIn
(
x
.
getShopIds
()
);
if
(
shop
s
==
null
||
shops
.
size
()
==
0
)
{
shopDto
s
.
add
(
new
ShopDto
()
);
}
else
{
shopDto
=
new
ShopDto
(
shop
);
for
(
Shop
shop
:
shops
)
{
shopDtos
.
add
(
new
ShopDto
(
shop
));
}
}
if
(
StringUtils
.
isNotBlank
(
x
.
getAddr
()))
{
if
(
x
.
getLockTimestamp
()
>=
Instant
.
now
().
minusSeconds
(
120
).
toEpochMilli
()
&&
x
.
getIpType
()
==
IpType
.
VENDOR
&&
(
x
.
getStatus
()
==
0
||
x
.
getStatus
()
==
2
))
{
...
...
@@ -630,8 +638,7 @@ public class IpResourceServiceImpl implements IpResourceService {
}
else
if
(
x
.
getValidTime
()
<=
Instant
.
now
().
plusSeconds
(
60
*
60
*
24
*
7
).
toEpochMilli
()
&&
x
.
getValidTime
()
>
Instant
.
now
().
toEpochMilli
())
{
if
(
x
.
getStatus
()
!=
5
&&
x
.
getStatus
()
!=
3
&&
x
.
getStatus
()
!=
6
)
{
x
.
setStatus
(
2
);
ipResourceRepository
.
save
(
x
);
ipResourceRepository
.
updateStatus
(
x
.
getId
(),
2
);
}
}
else
if
(
x
.
getValidTime
()
<=
Instant
.
now
().
minusSeconds
(
60
*
60
*
24
*
7
).
toEpochMilli
()
&&
x
.
getStatus
()
!=
3
&&
x
.
getStatus
()
!=
6
)
{
...
...
@@ -647,16 +654,13 @@ public class IpResourceServiceImpl implements IpResourceService {
return
;
}
else
if
(
x
.
getValidTime
()
<=
Instant
.
now
().
toEpochMilli
()
&&
x
.
getStatus
()
!=
3
&&
x
.
getStatus
()
!=
6
)
{
x
.
setStatus
(
1
);
ipResourceRepository
.
save
(
x
);
ipResourceRepository
.
updateStatus
(
x
.
getId
(),
1
);
}
else
{
if
((
x
.
getStatus
()
==
0
||
x
.
getStatus
()
==
1
||
x
.
getStatus
()
==
2
)
&&
!
x
.
getVendor
().
equals
(
Vendor
.
local
))
{
x
.
setStatus
(
0
);
ipResourceRepository
.
save
(
x
);
ipResourceRepository
.
updateStatus
(
x
.
getId
(),
0
);
}
else
if
(
x
.
getIpType
().
equals
(
IpType
.
LOCAL
)
&&
(
x
.
getStatus
()
==
1
||
x
.
getStatus
()
==
2
)
&&
x
.
getAddr
().
equals
(
"本地Ip未使用"
)
)
{
x
.
setStatus
(
4
);
ipResourceRepository
.
save
(
x
);
ipResourceRepository
.
updateStatus
(
x
.
getId
(),
4
);
}
}
}
...
...
@@ -667,9 +671,9 @@ public class IpResourceServiceImpl implements IpResourceService {
}
SpecialLine
specialLine
=
specialLineRepository
.
findAll
().
get
(
0
);
if
(
x
.
isSpecialLine
())
ipResourceDtos
.
add
(
new
IpResourceDto
(
x
,
shopDto
,
false
,
specialLine
));
ipResourceDtos
.
add
(
new
IpResourceDto
(
x
,
shopDto
s
,
false
,
specialLine
));
else
ipResourceDtos
.
add
(
new
IpResourceDto
(
x
,
shopDto
,
false
));
ipResourceDtos
.
add
(
new
IpResourceDto
(
x
,
shopDto
s
,
false
));
});
}
...
...
@@ -720,8 +724,8 @@ public class IpResourceServiceImpl implements IpResourceService {
throw
new
ClientRequestException
(
AccountErrorCode
.
NAMENOTEXIST
);
IpSummary
ipSummary
=
new
IpSummary
();
List
<
String
>
shopIds
=
userShopRepository
.
findByUsername
(
username
).
stream
().
map
(
x
->
x
.
getShopId
()).
collect
(
Collectors
.
toList
());
List
<
String
>
used
=
ipResourceRepository
.
find
ByShopIdInAndIsDeleted
(
shopIds
,
false
).
stream
().
map
(
x
->
x
.
getId
()).
collect
(
Collectors
.
toList
());
List
<
String
>
unbind
=
ipResourceRepository
.
findByOwnerAndIsDeletedAnd
ShopIdIsNull
(
usernam
e
,
false
).
stream
().
map
(
x
->
x
.
getId
()).
collect
(
Collectors
.
toList
());
List
<
String
>
used
=
ipResourceRepository
.
find
ShopIdInList
(
shopIds
,
false
).
stream
().
map
(
x
->
x
.
getId
()).
collect
(
Collectors
.
toList
());
List
<
String
>
unbind
=
ipResourceRepository
.
findByOwnerAndIsDeletedAnd
Bind
(
username
,
fals
e
,
false
).
stream
().
map
(
x
->
x
.
getId
()).
collect
(
Collectors
.
toList
());
ipSummary
.
setUnbind
(
unbind
.
size
());
unbind
.
addAll
(
used
);
int
expired
=
ipResourceRepository
.
countByStatusAndIdInAndIsDeleted
(
1
,
unbind
,
false
);
...
...
@@ -783,32 +787,31 @@ public class IpResourceServiceImpl implements IpResourceService {
if
(
ipResource
==
null
)
throw
new
ClientRequestException
(
BrowserErrorCode
.
IPNOTEXIST
);
ShopDto
shopDto
;
Shop
shop
=
null
;
if
(
ipResource
.
getShopId
()
!=
null
)
shop
=
shopRepository
.
findById
(
ipResource
.
getShopId
()).
orElse
(
null
);
if
(
shop
==
null
)
{
shopDto
=
new
ShopDto
(
);
List
<
ShopDto
>
shopDtos
=
new
ArrayList
<>()
;
List
<
Shop
>
shops
=
null
;
if
(
ipResource
.
getShopId
s
()
!=
null
)
shop
s
=
shopRepository
.
findByShopIdIn
(
ipResource
.
getShopIds
()
);
if
(
shop
s
==
null
||
shops
.
size
()
>
0
)
{
shopDto
s
.
add
(
new
ShopDto
()
);
}
else
{
shopDto
=
new
ShopDto
(
shop
);
for
(
Shop
shop
:
shops
)
{
shopDtos
.
add
(
new
ShopDto
(
shop
));
}
}
if
(
StringUtils
.
isNotBlank
(
ipResource
.
getAddr
()))
{
if
(
ipResource
.
getValidTime
()
<=
Instant
.
now
().
plusSeconds
(
60
*
60
*
24
*
7
).
toEpochMilli
()
&&
ipResource
.
getValidTime
()
>
Instant
.
now
().
toEpochMilli
())
{
ipResource
.
setStatus
(
2
);
ipResourceRepository
.
save
(
ipResource
);
ipResourceRepository
.
updateStatus
(
ipResource
.
getId
(),
2
);
}
else
if
(
ipResource
.
getValidTime
()
<=
Instant
.
now
().
minusSeconds
(
60
*
60
*
24
*
7
).
toEpochMilli
())
{
deleteIp
(
username
,
ipResourceRequestDto
);
}
else
if
(
ipResource
.
getValidTime
()
<=
Instant
.
now
().
toEpochMilli
())
{
ipResource
.
setStatus
(
1
);
ipResourceRepository
.
save
(
ipResource
);
ipResourceRepository
.
updateStatus
(
ipResource
.
getId
(),
1
);
}
else
{
if
(
ipResource
.
getStatus
()
!=
4
&&
ipResource
.
getStatus
()
!=
5
)
{
ipResource
.
setStatus
(
0
);
ipResourceRepository
.
save
(
ipResource
);
ipResourceRepository
.
updateStatus
(
ipResource
.
getId
(),
0
);
}
}
}
IpResourceDto
ipResourceDto
=
new
IpResourceDto
(
ipResource
,
shopDto
,
true
);
IpResourceDto
ipResourceDto
=
new
IpResourceDto
(
ipResource
,
shopDto
s
,
true
);
return
ipResourceDto
;
}
...
...
@@ -837,4 +840,13 @@ public class IpResourceServiceImpl implements IpResourceService {
DeleteIpResultDto
deleteIpResultDto
=
JSON
.
parseObject
(
result
.
getBody
(),
DeleteIpResultDto
.
class
);
});
}
@Override
public
void
transferBindShops
()
{
List
<
IpResource
>
ipResources
=
ipResourceRepository
.
findByIsDeleted
(
false
);
for
(
IpResource
ipResource
:
ipResources
)
{
ipResourceRepository
.
addShopId
(
ipResource
.
getId
(),
ipResource
.
getShopId
());
ipResourceRepository
.
updateBind
(
ipResource
.
getId
(),
true
);
}
}
}
src/main/java/com/edgec/browserbackend/browser/service/Impl/ShopServiceImpl.java
View file @
0e7986d5
...
...
@@ -228,11 +228,12 @@ public class ShopServiceImpl implements ShopService {
Shop
shop
=
shopRepository
.
findById
(
shopId
).
orElse
(
null
);
if
(
shop
==
null
)
throw
new
ClientRequestException
(
BrowserErrorCode
.
SHOPNOTEXIST
);
IpResource
ipResource
=
ipResourceRepository
.
findFirstByShopIdAndIsDeleted
(
shop
.
getShopId
(),
false
);
IpResource
ipResource
=
ipResourceRepository
.
findFirstByShopId
sIs
AndIsDeleted
(
shop
.
getShopId
(),
false
);
if
(
ipResource
!=
null
)
{
ipResource
.
setShopName
(
null
);
ipResource
.
setShopId
(
null
);
ipResourceRepository
.
save
(
ipResource
);
ShopRequestDto
shopRequestDto
=
new
ShopRequestDto
();
shopRequestDto
.
setIpId
(
ipResource
.
getId
());
shopRequestDto
.
setShopId
(
shopId
);
ipAndShopService
.
unBindShop
(
username
,
shopRequestDto
);
}
boolean
result
=
userShopRepository
.
deleteByShopId
(
shopId
);
if
(
result
)
{
...
...
@@ -335,7 +336,7 @@ public class ShopServiceImpl implements ShopService {
if
(
shop
==
null
)
{
throw
new
ClientRequestException
(
BrowserErrorCode
.
SHOPNOTEXIST
);
}
IpResource
ipResource
=
ipResourceRepository
.
findFirstByShopIdAndIsDeleted
(
shopId
,
false
);
IpResource
ipResource
=
ipResourceRepository
.
findFirstByShopId
sIs
AndIsDeleted
(
shopId
,
false
);
if
(
ipResource
==
null
)
throw
new
ClientRequestException
(
BrowserErrorCode
.
IPNOTEXIST
);
String
group
=
userShopRepository
.
findByUsernameAndShopId
(
username
,
shop
.
getShopId
()).
getGroupId
();
...
...
@@ -374,18 +375,19 @@ public class ShopServiceImpl implements ShopService {
else
if
(
shopFilterDto
.
getBindIp
()
==
1
)
{
List
<
String
>
allIds
=
userShopRepository
.
findByUsername
(
username
).
stream
()
.
map
(
x
->
x
.
getShopId
()).
collect
(
Collectors
.
toList
());
shopIds
=
ipResourceRepository
.
find
ByShopIdInAndIsDeleted
(
allIds
,
false
)
.
stream
().
map
(
x
->
x
.
getShopId
(
)).
collect
(
Collectors
.
toList
());
shopIds
=
ipResourceRepository
.
find
ShopIdInList
(
allIds
,
false
)
.
stream
().
flatMap
((
x
->
x
.
getShopIds
().
stream
()
)).
collect
(
Collectors
.
toList
());
}
else
{
List
<
String
>
allIds
=
userShopRepository
.
findByUsername
(
username
).
stream
()
.
map
(
x
->
x
.
getShopId
()).
collect
(
Collectors
.
toList
());
for
(
String
id:
allIds
)
{
IpResource
ipResource
=
ipResourceRepository
.
findFirstByShopIdAndIsDeleted
(
id
,
false
);
if
(
ipResource
==
null
)
IpResource
ipResource
=
ipResourceRepository
.
findFirstByShopId
sIs
AndIsDeleted
(
id
,
false
);
if
(
ipResource
==
null
)
{
shopIds
.
add
(
id
);
}
}
}
}
else
{
if
(
shopFilterDto
.
getBindIp
()
==
0
)
shopIds
=
userShopRepository
.
findByUsernameAndGroupId
(
username
,
groupId
).
stream
().
...
...
@@ -393,14 +395,14 @@ public class ShopServiceImpl implements ShopService {
else
if
(
shopFilterDto
.
getBindIp
()
==
1
)
{
List
<
String
>
allIds
=
userShopRepository
.
findByUsernameAndGroupId
(
username
,
groupId
).
stream
().
map
(
x
->
x
.
getShopId
()).
collect
(
Collectors
.
toList
());
shopIds
=
ipResourceRepository
.
find
ByShopIdInAndIsDeleted
(
allIds
,
false
)
.
stream
().
map
(
x
->
x
.
getShopId
(
)).
collect
(
Collectors
.
toList
());
shopIds
=
ipResourceRepository
.
find
ShopIdInList
(
allIds
,
false
)
.
stream
().
flatMap
((
x
->
x
.
getShopIds
().
stream
()
)).
collect
(
Collectors
.
toList
());
}
else
{
List
<
String
>
allIds
=
userShopRepository
.
findByUsernameAndGroupId
(
username
,
groupId
).
stream
()
.
map
(
x
->
x
.
getShopId
()).
collect
(
Collectors
.
toList
());
for
(
String
id:
allIds
)
{
IpResource
ipResource
=
ipResourceRepository
.
findFirstByShopIdAndIsDeleted
(
id
,
false
);
IpResource
ipResource
=
ipResourceRepository
.
findFirstByShopId
sIs
AndIsDeleted
(
id
,
false
);
if
(
ipResource
==
null
)
shopIds
.
add
(
id
);
}
...
...
@@ -408,8 +410,8 @@ public class ShopServiceImpl implements ShopService {
}
Page
<
Shop
>
shops
;
if
(
shopFilterDto
!=
null
&&
StringUtils
.
isNotBlank
(
shopFilterDto
.
getIpRegion
()))
{
List
<
String
>
filter
=
ipResourceRepository
.
find
ByIsDeletedAndShopIdInAndRegionCnLike
(
false
,
shopIds
,
shopFilterDto
.
getIpRegion
())
.
stream
().
map
(
x
->
x
.
getShopId
(
)).
collect
(
Collectors
.
toList
());
List
<
String
>
filter
=
ipResourceRepository
.
find
ShopIdInListAndRegionLike
(
shopIds
,
false
,
shopFilterDto
.
getIpRegion
())
.
stream
().
flatMap
((
x
->
x
.
getShopIds
().
stream
()
)).
collect
(
Collectors
.
toList
());
shops
=
shopRepository
.
findByShopIdInOrderByCreateTimeDesc
(
filter
,
pageable
);
}
else
if
(
shopFilterDto
!=
null
&&
StringUtils
.
isNotBlank
(
shopFilterDto
.
getShopAccount
()))
...
...
@@ -422,7 +424,7 @@ public class ShopServiceImpl implements ShopService {
return
new
ShopPageResultDto
();
List
<
ShopResultDto
>
shopResultDtos
=
new
ArrayList
<>();
shops
.
getContent
().
stream
().
forEach
(
x
->
{
IpResource
ipResource
=
ipResourceRepository
.
findFirstByShopIdAndIsDeleted
(
x
.
getShopId
(),
false
);
IpResource
ipResource
=
ipResourceRepository
.
findFirstByShopId
sIs
AndIsDeleted
(
x
.
getShopId
(),
false
);
if
(
ipResource
!=
null
)
{
if
(
StringUtils
.
isNotBlank
(
ipResource
.
getAddr
()))
{
if
(
ipResource
.
getValidTime
()
<=
Instant
.
now
().
plusSeconds
(
60
*
60
*
24
*
7
).
toEpochMilli
()
&&
ipResource
.
getValidTime
()
>
Instant
.
now
().
toEpochMilli
())
{
...
...
@@ -496,7 +498,7 @@ public class ShopServiceImpl implements ShopService {
List
<
String
>
unbind
=
new
ArrayList
<>();
if
(
allShopIds
!=
null
&&
allShopIds
.
size
()
>
0
)
{
for
(
String
id:
allShopIds
)
{
IpResource
ipResource
=
ipResourceRepository
.
findFirstByShopIdAndIsDeleted
(
id
,
false
);
IpResource
ipResource
=
ipResourceRepository
.
findFirstByShopId
sIs
AndIsDeleted
(
id
,
false
);
if
(
ipResource
==
null
)
{
unbind
.
add
(
id
);
}
...
...
@@ -504,7 +506,7 @@ public class ShopServiceImpl implements ShopService {
}
shopSummary
.
setUnbind
(
unbind
.
size
());
List
<
String
>
shopIds
=
userShopRepository
.
findByUsername
(
username
).
stream
().
map
(
x
->
x
.
getShopId
()).
collect
(
Collectors
.
toList
());
List
<
String
>
bind
=
ipResourceRepository
.
find
ByShopIdInAndIsDeleted
(
shopIds
,
false
).
stream
().
map
(
x
->
x
.
getId
()).
collect
(
Collectors
.
toList
());
List
<
String
>
bind
=
ipResourceRepository
.
find
ShopIdInList
(
shopIds
,
false
).
stream
().
map
(
x
->
x
.
getId
()).
collect
(
Collectors
.
toList
());
int
expired
=
ipResourceRepository
.
countByStatusAndIdInAndIsDeleted
(
1
,
bind
,
false
);
int
willexpired
=
ipResourceRepository
.
countByStatusAndIdInAndIsDeleted
(
2
,
bind
,
false
);
shopSummary
.
setExpired
(
expired
);
...
...
src/main/java/com/edgec/browserbackend/browser/service/IpAndShopService.java
View file @
0e7986d5
...
...
@@ -7,4 +7,6 @@ public interface IpAndShopService {
void
bindShop
(
String
username
,
ShopRequestDto
shopRequestDto
);
void
unBindShop
(
String
username
,
ShopRequestDto
shopRequestDto
);
void
unBindShops
(
String
username
,
ShopRequestDto
shopRequestDto
);
}
src/main/java/com/edgec/browserbackend/browser/service/IpResourceService.java
View file @
0e7986d5
...
...
@@ -32,4 +32,6 @@ public interface IpResourceService {
void
setSpecialLine
();
void
releaseDeletedIp
();
void
transferBindShops
();
}
src/main/java/com/edgec/browserbackend/browser/task/BrowserTask.java
View file @
0e7986d5
...
...
@@ -165,11 +165,11 @@ public class BrowserTask {
if
(
result
==
false
&&
(
ipResource
.
getPurchasedTime
()
<
Instant
.
now
().
minusSeconds
(
7200
).
toEpochMilli
()))
{
IpChargeRequestDto
ipChargeRequestDto
=
buildIpChargeRequestDto
(
ipResource
,
3
,
0
);
accountService
.
chargeByMoney
(
ipResource
.
getUsername
(),
-
ipResource
.
getPrice
(),
ipChargeRequestDto
);
if
(
ipResource
.
getShopId
()
!=
null
)
{
if
(
ipResource
.
getShopId
s
()
!=
null
&&
ipResource
.
getShopIds
().
size
()
>
0
)
{
ShopRequestDto
shopRequestDto
=
new
ShopRequestDto
();
shopRequestDto
.
setIpId
(
ipResource
.
getId
());
shopRequestDto
.
setShopId
(
ipResource
.
getShopId
());
ipAndShopService
.
unBindShop
(
ipResource
.
getUsername
(),
shopRequestDto
);
shopRequestDto
.
setShopId
s
(
ipResource
.
getShopIds
());
ipAndShopService
.
unBindShop
s
(
ipResource
.
getUsername
(),
shopRequestDto
);
}
ipResourceRepository
.
deleteById
(
ipResource
.
getId
());
}
...
...
@@ -199,14 +199,17 @@ public class BrowserTask {
CompletableFuture
.
runAsync
(()
->
{
if
(
ipResourceRepository
.
lockTask
(
ipResource
))
{
try
{
log
.
error
(
"test"
);
String
url
=
URL
+
"/ecc/ipinfo?accountId=browser&ip="
+
ipResource
.
getAddr
();
Map
<
String
,
String
>
header
=
buildGetHeader
();
String
rs
=
HttpClientutils
.
doGet
(
url
,
header
);
IpInfoResultDto
ipInfoResultDto
=
JSONObject
.
parseObject
(
rs
,
IpInfoResultDto
.
class
);
if
(
ipInfoResultDto
!=
null
&&
StringUtils
.
isBlank
(
ipInfoResultDto
.
getErrorCode
()))
{
log
.
error
(
ipInfoResultDto
.
getErrorCode
());
log
.
error
(
ipInfoResultDto
.
getStatus
());
log
.
error
(
ipInfoResultDto
.
getEipIPAddr
());
if
(
StringUtils
.
isNotEmpty
(
ipInfoResultDto
.
getStatus
()))
{
ipResource
.
setStatus
(
0
);
ipResourceRepository
.
save
(
ipResource
);
ipResourceRepository
.
updateStatus
(
ipResource
.
getId
(),
0
);
}
}
}
catch
(
Exception
e
)
{
...
...
src/main/java/com/edgec/browserbackend/common/utils/JsonUtils.java
0 → 100644
View file @
0e7986d5
package
com
.
edgec
.
browserbackend
.
common
.
utils
;
import
com.alibaba.fastjson.JSONArray
;
import
com.edgec.browserbackend.account.exception.AccountErrorCode
;
import
com.edgec.browserbackend.common.commons.error.ClientRequestException
;
import
com.fasterxml.jackson.annotation.JsonInclude.Include
;
import
com.fasterxml.jackson.core.JsonFactory
;
import
com.fasterxml.jackson.core.JsonGenerator
;
import
com.fasterxml.jackson.core.JsonParser.Feature
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
java.beans.BeanInfo
;
import
java.beans.Introspector
;
import
java.beans.PropertyDescriptor
;
import
java.io.IOException
;
import
java.io.StringWriter
;
import
java.lang.reflect.Method
;
import
java.util.*
;
/**
* Json工具类
*/
public
class
JsonUtils
{
private
static
final
ObjectMapper
mapper
=
new
ObjectMapper
();
static
{
mapper
.
configure
(
Feature
.
ALLOW_UNQUOTED_FIELD_NAMES
,
true
);
mapper
.
configure
(
Feature
.
ALLOW_UNQUOTED_CONTROL_CHARS
,
true
);
mapper
.
setSerializationInclusion
(
Include
.
NON_NULL
);
}
private
JsonUtils
()
{
}
/**
* json字符串转换为类
*/
public
static
<
T
>
T
toBean
(
String
json
,
Class
<
T
>
clazz
)
{
try
{
T
bean
=
(
T
)
mapper
.
readValue
(
json
,
clazz
);
return
bean
;
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
@SuppressWarnings
(
"unchecked"
)
public
static
HashMap
<
String
,
Object
>
toBean
(
String
json
)
{
return
toBean
(
json
,
HashMap
.
class
);
}
@SuppressWarnings
(
"unchecked"
)
public
static
HashMap
<
String
,
String
>
toBeanStr
(
String
json
)
{
return
toBean
(
json
,
HashMap
.
class
);
}
@SuppressWarnings
(
"unchecked"
)
public
static
<
T
>
T
toBean
(
String
json
,
TypeReference
<
T
>
tr
){
try
{
T
bean
=
(
T
)
mapper
.
readValue
(
json
,
tr
);
return
bean
;
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
/**
* 对象转换为json字符串
*/
public
static
String
toJson
(
Object
bean
)
{
String
json
=
null
;
JsonGenerator
gen
=
null
;
StringWriter
sw
=
new
StringWriter
();
try
{
gen
=
new
JsonFactory
().
createGenerator
(
sw
);
mapper
.
writeValue
(
gen
,
bean
);
json
=
sw
.
toString
();
}
catch
(
IOException
e
)
{
throw
new
ClientRequestException
(
AccountErrorCode
.
UNKNOWN
);
}
finally
{
try
{
if
(
gen
!=
null
)
{
gen
.
close
();
}
if
(
sw
!=
null
)
{
sw
.
close
();
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
return
json
;
}
@SuppressWarnings
(
"unchecked"
)
public
static
List
<
Object
>
toList
(
String
json
)
{
return
toBean
(
json
,
ArrayList
.
class
);
}
/**
* 对象转换为Map
*/
public
static
Map
<
String
,
Object
>
transBean2Map
(
Object
obj
)
{
if
(
obj
==
null
)
{
return
null
;
}
Map
<
String
,
Object
>
map
=
new
HashMap
<
String
,
Object
>();
try
{
BeanInfo
beanInfo
=
Introspector
.
getBeanInfo
(
obj
.
getClass
());
PropertyDescriptor
[]
propertyDescriptors
=
beanInfo
.
getPropertyDescriptors
();
for
(
PropertyDescriptor
property
:
propertyDescriptors
)
{
String
key
=
property
.
getName
();
if
(!
key
.
equals
(
"class"
))
{
Method
getter
=
property
.
getReadMethod
();
Object
value
=
getter
.
invoke
(
obj
);
map
.
put
(
key
,
value
);
}
}
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"transBean2Map Error "
+
e
);
}
return
map
;
}
/**
* json字符串转换为List
*/
public
static
<
T
>
List
<
T
>
json2ListBean
(
String
json
,
Class
<
T
>
cls
){
JSONArray
jArray
=
JSONArray
.
parseArray
(
json
);
List
<
T
>
collection
=
jArray
.
toJavaList
(
cls
);
return
collection
;
}
}
\ No newline at end of file
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