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
d5b01f29
Commit
d5b01f29
authored
Jun 16, 2020
by
xuxin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
部分代码添加注释
parent
89b62bef
Hide whitespace changes
Inline
Side-by-side
Showing
43 changed files
with
937 additions
and
1452 deletions
+937
-1452
AccountServicePool.java
...dgec/browserbackend/account/utils/AccountServicePool.java
+10
-7
OAuthResponseExceptionTranslator.java
...backend/auth/config/OAuthResponseExceptionTranslator.java
+3
-4
ResourceServerConfiguration.java
...owserbackend/auth/config/ResourceServerConfiguration.java
+1
-7
AuthErrorHandler.java
...dgec/browserbackend/auth/controller/AuthErrorHandler.java
+1
-0
MongoOAuth2AccessToken.java
...wserbackend/auth/domain/mongo/MongoOAuth2AccessToken.java
+6
-36
MongoOAuth2RefreshToken.java
...serbackend/auth/domain/mongo/MongoOAuth2RefreshToken.java
+6
-22
IpControlloer.java
...dgec/browserbackend/browser/controller/IpControlloer.java
+6
-0
BindHistory.java
.../com/edgec/browserbackend/browser/domain/BindHistory.java
+3
-38
Group.java
...n/java/com/edgec/browserbackend/browser/domain/Group.java
+32
-40
IpCountRecord.java
...om/edgec/browserbackend/browser/domain/IpCountRecord.java
+6
-32
IpOptions.java
...va/com/edgec/browserbackend/browser/domain/IpOptions.java
+6
-31
IpResource.java
...a/com/edgec/browserbackend/browser/domain/IpResource.java
+12
-262
IpSummary.java
...va/com/edgec/browserbackend/browser/domain/IpSummary.java
+19
-31
IpType.java
.../java/com/edgec/browserbackend/browser/domain/IpType.java
+11
-0
OperationHistory.java
...edgec/browserbackend/browser/domain/OperationHistory.java
+21
-73
PlatformOptions.java
.../edgec/browserbackend/browser/domain/PlatformOptions.java
+5
-18
ProxyConfig.java
.../com/edgec/browserbackend/browser/domain/ProxyConfig.java
+4
-16
Shop.java
...in/java/com/edgec/browserbackend/browser/domain/Shop.java
+82
-114
ShopSummary.java
.../com/edgec/browserbackend/browser/domain/ShopSummary.java
+21
-31
SpecialLine.java
.../com/edgec/browserbackend/browser/domain/SpecialLine.java
+27
-49
UserShop.java
...ava/com/edgec/browserbackend/browser/domain/UserShop.java
+9
-46
Vendor.java
.../java/com/edgec/browserbackend/browser/domain/Vendor.java
+21
-3
IpListRequestDto.java
...om/edgec/browserbackend/browser/dto/IpListRequestDto.java
+5
-3
IpResourceServiceImpl.java
...erbackend/browser/service/Impl/IpResourceServiceImpl.java
+310
-253
ShopServiceImpl.java
.../browserbackend/browser/service/Impl/ShopServiceImpl.java
+91
-95
BrowserTask.java
...va/com/edgec/browserbackend/browser/task/BrowserTask.java
+119
-124
PaymentTask.java
...va/com/edgec/browserbackend/browser/task/PaymentTask.java
+1
-1
KafkaUtils.java
...edgec/browserbackend/common/commons/kafka/KafkaUtils.java
+2
-1
CommonStringUtils.java
...rowserbackend/common/commons/utils/CommonStringUtils.java
+9
-8
Pair.java
...a/com/edgec/browserbackend/common/commons/utils/Pair.java
+1
-0
PriorityThreadPoolExecutor.java
...kend/common/commons/utils/PriorityThreadPoolExecutor.java
+1
-0
RemoteShellExecutor.java
...wserbackend/common/commons/utils/RemoteShellExecutor.java
+18
-14
TimestampUtils.java
...c/browserbackend/common/commons/utils/TimestampUtils.java
+1
-0
UUIDGenerator.java
...ec/browserbackend/common/commons/utils/UUIDGenerator.java
+1
-0
InstanceStatus.java
.../edgec/browserbackend/common/constant/InstanceStatus.java
+1
-0
SpecialUsers.java
...om/edgec/browserbackend/common/constant/SpecialUsers.java
+12
-33
BaseResponse.java
...ava/com/edgec/browserbackend/common/dto/BaseResponse.java
+4
-34
Result.java
...main/java/com/edgec/browserbackend/common/dto/Result.java
+1
-0
Aes.java
src/main/java/com/edgec/browserbackend/common/utils/Aes.java
+13
-3
JsonUtils.java
...java/com/edgec/browserbackend/common/utils/JsonUtils.java
+12
-6
PollerUtils.java
...va/com/edgec/browserbackend/common/utils/PollerUtils.java
+2
-1
ThreadPoolUtils.java
...om/edgec/browserbackend/common/utils/ThreadPoolUtils.java
+4
-6
Trans.java
...ain/java/com/edgec/browserbackend/common/utils/Trans.java
+17
-10
No files found.
src/main/java/com/edgec/browserbackend/account/utils/AccountServicePool.java
View file @
d5b01f29
...
@@ -8,13 +8,16 @@ public class AccountServicePool {
...
@@ -8,13 +8,16 @@ public class AccountServicePool {
private
static
final
int
POOL_COUNT
=
10
;
private
static
final
int
POOL_COUNT
=
10
;
public
static
final
ExecutorService
taskPool
=
Executors
.
newFixedThreadPool
(
POOL_COUNT
,
new
ThreadFactory
()
{
public
static
final
ExecutorService
taskPool
=
Executors
.
newFixedThreadPool
(
int
count
=
1
;
POOL_COUNT
,
new
ThreadFactory
()
{
int
count
=
1
;
@Override
@Override
public
Thread
newThread
(
Runnable
runnable
)
{
public
Thread
newThread
(
Runnable
runnable
)
{
return
new
Thread
(
runnable
,
"account-service-pool"
+
count
++);
return
new
Thread
(
runnable
,
"account-service-pool"
+
count
++);
}
}
});
}
);
}
}
src/main/java/com/edgec/browserbackend/auth/config/OAuthResponseExceptionTranslator.java
View file @
d5b01f29
...
@@ -27,7 +27,7 @@ public class OAuthResponseExceptionTranslator extends DefaultWebResponseExceptio
...
@@ -27,7 +27,7 @@ public class OAuthResponseExceptionTranslator extends DefaultWebResponseExceptio
private
ResponseEntity
<
OAuth2Exception
>
handleOAuth2Exception
(
OAuth2Exception
e
,
AuthErrorCode
error
)
throws
IOException
{
private
ResponseEntity
<
OAuth2Exception
>
handleOAuth2Exception
(
OAuth2Exception
e
,
AuthErrorCode
error
)
throws
IOException
{
IntelligroupOauthException
ex
=
new
IntelligroupOauthException
(
error
.
getReason
(),
error
.
getReason
(),
error
.
getCode
());
IntelligroupOauthException
ex
=
new
IntelligroupOauthException
(
error
.
getReason
(),
error
.
getReason
(),
error
.
getCode
());
int
status
=
e
.
getHttpErrorCode
();
int
status
=
e
.
getHttpErrorCode
();
HttpHeaders
headers
=
new
HttpHeaders
();
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
set
(
"Cache-Control"
,
"no-store"
);
headers
.
set
(
"Cache-Control"
,
"no-store"
);
...
@@ -36,8 +36,7 @@ public class OAuthResponseExceptionTranslator extends DefaultWebResponseExceptio
...
@@ -36,8 +36,7 @@ public class OAuthResponseExceptionTranslator extends DefaultWebResponseExceptio
headers
.
set
(
"WWW-Authenticate"
,
String
.
format
(
"%s %s"
,
OAuth2AccessToken
.
BEARER_TYPE
,
e
.
getSummary
()));
headers
.
set
(
"WWW-Authenticate"
,
String
.
format
(
"%s %s"
,
OAuth2AccessToken
.
BEARER_TYPE
,
e
.
getSummary
()));
}
}
ResponseEntity
<
OAuth2Exception
>
response
=
new
ResponseEntity
<
OAuth2Exception
>(
ex
,
headers
,
ResponseEntity
<
OAuth2Exception
>
response
=
new
ResponseEntity
<
OAuth2Exception
>(
ex
,
headers
,
HttpStatus
.
valueOf
(
status
));
HttpStatus
.
valueOf
(
status
));
return
response
;
return
response
;
}
}
...
@@ -47,7 +46,7 @@ public class OAuthResponseExceptionTranslator extends DefaultWebResponseExceptio
...
@@ -47,7 +46,7 @@ public class OAuthResponseExceptionTranslator extends DefaultWebResponseExceptio
// Try to extract a SpringSecurityException from the stacktrace
// Try to extract a SpringSecurityException from the stacktrace
Throwable
[]
causeChain
=
throwableAnalyzer
.
determineCauseChain
(
e
);
Throwable
[]
causeChain
=
throwableAnalyzer
.
determineCauseChain
(
e
);
Exception
ase
=
(
AuthenticationException
)
throwableAnalyzer
.
getFirstThrowableOfType
(
AuthenticationException
.
class
,
Exception
ase
=
(
AuthenticationException
)
throwableAnalyzer
.
getFirstThrowableOfType
(
AuthenticationException
.
class
,
causeChain
);
causeChain
);
if
(
ase
!=
null
)
{
if
(
ase
!=
null
)
{
AuthErrorCode
code
=
AuthErrorCode
.
AUTHENTICATION_ERROR
;
AuthErrorCode
code
=
AuthErrorCode
.
AUTHENTICATION_ERROR
;
...
...
src/main/java/com/edgec/browserbackend/auth/config/ResourceServerConfiguration.java
View file @
d5b01f29
package
com
.
edgec
.
browserbackend
.
auth
.
config
;
package
com
.
edgec
.
browserbackend
.
auth
.
config
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.security.config.annotation.web.builders.HttpSecurity
;
import
org.springframework.security.config.annotation.web.builders.HttpSecurity
;
import
org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer
;
import
org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer
;
...
@@ -13,14 +9,12 @@ import org.springframework.security.oauth2.config.annotation.web.configuration.R
...
@@ -13,14 +9,12 @@ import org.springframework.security.oauth2.config.annotation.web.configuration.R
@EnableResourceServer
@EnableResourceServer
public
class
ResourceServerConfiguration
extends
ResourceServerConfigurerAdapter
{
public
class
ResourceServerConfiguration
extends
ResourceServerConfigurerAdapter
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
ResourceServerConfiguration
.
class
);
@Override
@Override
public
void
configure
(
HttpSecurity
http
)
throws
Exception
{
public
void
configure
(
HttpSecurity
http
)
throws
Exception
{
http
http
.
authorizeRequests
()
.
authorizeRequests
()
.
antMatchers
(
"/oauth/**"
).
permitAll
()
.
antMatchers
(
"/oauth/**"
).
permitAll
()
.
antMatchers
(
"/shop/**"
,
"/ip/**"
,
"/group/**"
,
"/0xadministrator/**"
,
"/user/**"
,
"/history/**"
).
authenticated
()
.
antMatchers
(
"/shop/**"
,
"/ip/**"
,
"/group/**"
,
"/0xadministrator/**"
,
"/user/**"
,
"/history/**"
).
authenticated
()
.
and
()
.
and
()
//关闭跨站请求防护
//关闭跨站请求防护
.
csrf
().
disable
();
.
csrf
().
disable
();
...
...
src/main/java/com/edgec/browserbackend/auth/controller/AuthErrorHandler.java
View file @
d5b01f29
...
@@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
...
@@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
import
org.springframework.web.context.request.WebRequest
;
import
org.springframework.web.context.request.WebRequest
;
import
org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
;
import
org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
;
@Deprecated
@ControllerAdvice
@ControllerAdvice
public
class
AuthErrorHandler
extends
ResponseEntityExceptionHandler
{
public
class
AuthErrorHandler
extends
ResponseEntityExceptionHandler
{
...
...
src/main/java/com/edgec/browserbackend/auth/domain/mongo/MongoOAuth2AccessToken.java
View file @
d5b01f29
package
com
.
edgec
.
browserbackend
.
auth
.
domain
.
mongo
;
package
com
.
edgec
.
browserbackend
.
auth
.
domain
.
mongo
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
import
lombok.Setter
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.annotation.PersistenceConstructor
;
import
org.springframework.data.annotation.PersistenceConstructor
;
import
org.springframework.data.mongodb.core.mapping.Document
;
import
org.springframework.data.mongodb.core.mapping.Document
;
...
@@ -8,6 +11,9 @@ import java.time.Instant;
...
@@ -8,6 +11,9 @@ import java.time.Instant;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.Objects
;
import
java.util.Objects
;
@NoArgsConstructor
@Getter
@Setter
@Document
@Document
public
class
MongoOAuth2AccessToken
{
public
class
MongoOAuth2AccessToken
{
...
@@ -21,8 +27,6 @@ public class MongoOAuth2AccessToken {
...
@@ -21,8 +27,6 @@ public class MongoOAuth2AccessToken {
private
String
refreshToken
;
private
String
refreshToken
;
private
long
createdAt
;
private
long
createdAt
;
public
MongoOAuth2AccessToken
()
{
}
@PersistenceConstructor
@PersistenceConstructor
public
MongoOAuth2AccessToken
(
final
String
tokenId
,
public
MongoOAuth2AccessToken
(
final
String
tokenId
,
...
@@ -42,33 +46,6 @@ public class MongoOAuth2AccessToken {
...
@@ -42,33 +46,6 @@ public class MongoOAuth2AccessToken {
this
.
createdAt
=
Instant
.
now
().
toEpochMilli
();
this
.
createdAt
=
Instant
.
now
().
toEpochMilli
();
}
}
public
String
getTokenId
()
{
return
tokenId
;
}
public
byte
[]
getToken
()
{
return
token
;
}
public
String
getAuthenticationId
()
{
return
authenticationId
;
}
public
String
getUsername
()
{
return
username
;
}
public
String
getClientId
()
{
return
clientId
;
}
public
byte
[]
getAuthentication
()
{
return
authentication
;
}
public
String
getRefreshToken
()
{
return
refreshToken
;
}
@Override
@Override
public
int
hashCode
()
{
public
int
hashCode
()
{
...
@@ -100,11 +77,4 @@ public class MongoOAuth2AccessToken {
...
@@ -100,11 +77,4 @@ public class MongoOAuth2AccessToken {
'}'
;
'}'
;
}
}
public
long
getCreatedAt
()
{
return
createdAt
;
}
public
void
setCreatedAt
(
long
createdAt
)
{
this
.
createdAt
=
createdAt
;
}
}
}
src/main/java/com/edgec/browserbackend/auth/domain/mongo/MongoOAuth2RefreshToken.java
View file @
d5b01f29
package
com
.
edgec
.
browserbackend
.
auth
.
domain
.
mongo
;
package
com
.
edgec
.
browserbackend
.
auth
.
domain
.
mongo
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
import
lombok.Setter
;
import
org.apache.commons.lang3.builder.EqualsBuilder
;
import
org.apache.commons.lang3.builder.EqualsBuilder
;
import
org.apache.commons.lang3.builder.HashCodeBuilder
;
import
org.apache.commons.lang3.builder.HashCodeBuilder
;
import
org.apache.commons.lang3.builder.ToStringBuilder
;
import
org.apache.commons.lang3.builder.ToStringBuilder
;
...
@@ -9,6 +12,9 @@ import org.springframework.data.mongodb.core.mapping.Document;
...
@@ -9,6 +12,9 @@ import org.springframework.data.mongodb.core.mapping.Document;
import
java.time.Instant
;
import
java.time.Instant
;
@Getter
@Setter
@NoArgsConstructor
@Document
@Document
public
class
MongoOAuth2RefreshToken
{
public
class
MongoOAuth2RefreshToken
{
...
@@ -18,8 +24,6 @@ public class MongoOAuth2RefreshToken {
...
@@ -18,8 +24,6 @@ public class MongoOAuth2RefreshToken {
private
byte
[]
authentication
;
private
byte
[]
authentication
;
private
long
createdAt
;
private
long
createdAt
;
public
MongoOAuth2RefreshToken
()
{
}
@PersistenceConstructor
@PersistenceConstructor
public
MongoOAuth2RefreshToken
(
final
String
tokenId
,
public
MongoOAuth2RefreshToken
(
final
String
tokenId
,
...
@@ -31,18 +35,6 @@ public class MongoOAuth2RefreshToken {
...
@@ -31,18 +35,6 @@ public class MongoOAuth2RefreshToken {
this
.
createdAt
=
Instant
.
now
().
toEpochMilli
();
this
.
createdAt
=
Instant
.
now
().
toEpochMilli
();
}
}
public
String
getTokenId
()
{
return
tokenId
;
}
public
byte
[]
getToken
()
{
return
token
;
}
public
byte
[]
getAuthentication
()
{
return
authentication
;
}
@Override
@Override
public
boolean
equals
(
Object
o
)
{
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
return
true
;
if
(
this
==
o
)
return
true
;
...
@@ -75,12 +67,4 @@ public class MongoOAuth2RefreshToken {
...
@@ -75,12 +67,4 @@ public class MongoOAuth2RefreshToken {
.
append
(
"authentication"
,
authentication
)
.
append
(
"authentication"
,
authentication
)
.
toString
();
.
toString
();
}
}
public
long
getCreatedAt
()
{
return
createdAt
;
}
public
void
setCreatedAt
(
long
createdAt
)
{
this
.
createdAt
=
createdAt
;
}
}
}
src/main/java/com/edgec/browserbackend/browser/controller/IpControlloer.java
View file @
d5b01f29
...
@@ -27,6 +27,9 @@ public class IpControlloer {
...
@@ -27,6 +27,9 @@ public class IpControlloer {
@Autowired
@Autowired
private
IpResourceService
ipResourceService
;
private
IpResourceService
ipResourceService
;
/**
* 购买IP资源
*/
@RequestMapping
(
value
=
"/buy"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/buy"
,
method
=
RequestMethod
.
POST
)
public
ResultDto
buyIp
(
Principal
principal
,
@RequestBody
IpResourceRequestDto
ipResourceRequestDto
)
{
public
ResultDto
buyIp
(
Principal
principal
,
@RequestBody
IpResourceRequestDto
ipResourceRequestDto
)
{
ResultDto
resultDto
=
new
ResultDto
();
ResultDto
resultDto
=
new
ResultDto
();
...
@@ -72,6 +75,9 @@ public class IpControlloer {
...
@@ -72,6 +75,9 @@ public class IpControlloer {
return
resultDto
;
return
resultDto
;
}
}
/**
* 删除指定IP资源
*/
@RequestMapping
(
value
=
"/del"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/del"
,
method
=
RequestMethod
.
POST
)
public
ResultDto
deleteIp
(
Principal
principal
,
@RequestBody
IpResourceRequestDto
ipResourceRequestDto
)
{
public
ResultDto
deleteIp
(
Principal
principal
,
@RequestBody
IpResourceRequestDto
ipResourceRequestDto
)
{
ResultDto
resultDto
=
new
ResultDto
();
ResultDto
resultDto
=
new
ResultDto
();
...
...
src/main/java/com/edgec/browserbackend/browser/domain/BindHistory.java
View file @
d5b01f29
package
com
.
edgec
.
browserbackend
.
browser
.
domain
;
package
com
.
edgec
.
browserbackend
.
browser
.
domain
;
import
java.io.Serializable
;
import
lombok.Data
;
import
java.util.StringTokenizer
;
public
class
BindHistory
{
@Data
public
class
BindHistory
{
private
String
shopName
;
private
String
shopName
;
private
String
ip
;
private
String
ip
;
private
String
platform
;
private
String
platform
;
private
String
unbindTime
;
private
String
unbindTime
;
public
BindHistory
(){
}
public
String
getShopName
()
{
return
shopName
;
}
public
void
setShopName
(
String
shopName
)
{
this
.
shopName
=
shopName
;
}
public
String
getIp
()
{
return
ip
;
}
public
void
setPlatform
(
String
platform
)
{
this
.
platform
=
platform
;
}
public
String
getPlatform
()
{
return
platform
;
}
public
void
setIp
(
String
ip
)
{
this
.
ip
=
ip
;
}
public
String
getUnbindTime
()
{
return
unbindTime
;
}
public
void
setUnbindTime
(
String
unbindTime
)
{
this
.
unbindTime
=
unbindTime
;
}
}
}
src/main/java/com/edgec/browserbackend/browser/domain/Group.java
View file @
d5b01f29
package
com
.
edgec
.
browserbackend
.
browser
.
domain
;
package
com
.
edgec
.
browserbackend
.
browser
.
domain
;
import
org.apache.commons.lang3.StringUtils
;
import
lombok.Getter
;
import
lombok.Setter
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.mongodb.core.mapping.Document
;
import
org.springframework.data.mongodb.core.mapping.Document
;
import
org.springframework.util.StringUtils
;
import
java.util.List
;
@Getter
@Setter
@Document
(
collection
=
"groups"
)
@Document
(
collection
=
"groups"
)
public
class
Group
{
public
class
Group
{
/**
* 组 id
*/
@Id
@Id
private
String
id
;
private
String
id
;
/**
* 组名
*/
private
String
name
;
private
String
name
;
/**
* 组创建者
*/
private
String
owner
;
private
String
owner
;
/**
* 组详情
*/
private
String
details
;
private
String
details
;
public
void
of
(
Group
group
){
public
void
of
(
Group
group
)
{
if
(
StringUtils
.
isNotBlank
(
group
.
getId
()))
if
(
!
StringUtils
.
isEmpty
(
group
.
getId
()))
{
this
.
setId
(
group
.
getId
());
this
.
setId
(
group
.
getId
());
if
(
StringUtils
.
isNotBlank
(
group
.
getOwner
()))
}
this
.
setOwner
(
group
.
getOwner
());
if
(
StringUtils
.
isNotBlank
(
group
.
getDetails
()))
this
.
setDetails
(
group
.
getDetails
());
if
(
StringUtils
.
isNotBlank
(
group
.
getName
()))
this
.
setName
(
group
.
getName
());
}
public
String
getId
()
{
return
id
;
}
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
public
String
getOwner
()
{
if
(!
StringUtils
.
isEmpty
(
group
.
getOwner
()))
{
return
owner
;
this
.
setOwner
(
group
.
getOwner
());
}
}
public
void
setOwner
(
String
owner
)
{
this
.
owner
=
owner
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getDetails
(
)
{
if
(!
StringUtils
.
isEmpty
(
group
.
getDetails
())
)
{
return
details
;
this
.
setDetails
(
group
.
getDetails
())
;
}
}
public
void
setDetails
(
String
details
)
{
if
(!
StringUtils
.
isEmpty
(
group
.
getName
()))
{
this
.
details
=
details
;
this
.
setName
(
group
.
getName
());
}
}
}
}
}
src/main/java/com/edgec/browserbackend/browser/domain/IpCountRecord.java
View file @
d5b01f29
package
com
.
edgec
.
browserbackend
.
browser
.
domain
;
package
com
.
edgec
.
browserbackend
.
browser
.
domain
;
import
lombok.Data
;
import
org.springframework.data.mongodb.core.mapping.Document
;
import
org.springframework.data.mongodb.core.mapping.Document
;
@Data
@Document
(
collection
=
"ipcountrecord"
)
@Document
(
collection
=
"ipcountrecord"
)
public
class
IpCountRecord
{
public
class
IpCountRecord
{
private
String
username
;
private
long
timestamp
;
private
long
ip_using
;
private
long
ip_all
;
public
String
getUsername
()
{
return
username
;
}
public
void
setUsername
(
String
username
)
{
this
.
username
=
username
;
}
public
long
getIp_all
()
{
private
String
username
;
return
ip_all
;
}
public
void
setIp_all
(
long
ip_all
)
{
this
.
ip_all
=
ip_all
;
}
public
long
getIp_using
()
{
return
ip_using
;
}
public
void
setIp_using
(
long
ip_using
)
{
private
long
timestamp
;
this
.
ip_using
=
ip_using
;
}
public
long
getTimestamp
()
{
private
long
ip_using
;
return
timestamp
;
}
public
void
setTimestamp
(
long
timestamp
)
{
private
long
ip_all
;
this
.
timestamp
=
timestamp
;
}
}
}
src/main/java/com/edgec/browserbackend/browser/domain/IpOptions.java
View file @
d5b01f29
package
com
.
edgec
.
browserbackend
.
browser
.
domain
;
package
com
.
edgec
.
browserbackend
.
browser
.
domain
;
import
lombok.Getter
;
import
lombok.Setter
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.mongodb.core.mapping.Document
;
import
org.springframework.data.mongodb.core.mapping.Document
;
...
@@ -11,6 +13,9 @@ import java.util.Map;
...
@@ -11,6 +13,9 @@ import java.util.Map;
* @Author jason
* @Author jason
* @CreateTime 2020/3/12 10:30 上午
* @CreateTime 2020/3/12 10:30 上午
**/
**/
@Getter
@Setter
@Document
(
"ipOptions"
)
@Document
(
"ipOptions"
)
public
class
IpOptions
{
public
class
IpOptions
{
...
@@ -21,39 +26,9 @@ public class IpOptions {
...
@@ -21,39 +26,9 @@ public class IpOptions {
private
Map
<
String
,
List
<
String
>>
ipPlatForm
;
private
Map
<
String
,
List
<
String
>>
ipPlatForm
;
private
Map
<
String
,
Map
<
String
,
List
<
String
>>>
supportedPlatForm
;
private
Map
<
String
,
Map
<
String
,
List
<
String
>>>
supportedPlatForm
;
private
List
<
String
>
ipDurations
;
private
List
<
String
>
ipDurations
;
public
List
<
String
>
getIpDurations
()
{
return
ipDurations
;
}
public
void
setIpDurations
(
List
<
String
>
ipDurations
)
{
this
.
ipDurations
=
ipDurations
;
}
public
Map
<
String
,
List
<
String
>>
getIpPlatForm
()
{
return
ipPlatForm
;
}
public
void
setIpPlatForm
(
Map
<
String
,
List
<
String
>>
ipPlatForm
)
{
this
.
ipPlatForm
=
ipPlatForm
;
}
public
Map
<
String
,
List
<
String
>>
getIpRegion
()
{
return
ipRegion
;
}
public
void
setIpRegion
(
Map
<
String
,
List
<
String
>>
ipRegion
)
{
this
.
ipRegion
=
ipRegion
;
}
public
Map
<
String
,
Map
<
String
,
List
<
String
>>>
getSupportedPlatForm
()
{
return
supportedPlatForm
;
}
public
void
setSupportedPlatForm
(
Map
<
String
,
Map
<
String
,
List
<
String
>>>
supportedPlatForm
)
{
this
.
supportedPlatForm
=
supportedPlatForm
;
}
}
}
src/main/java/com/edgec/browserbackend/browser/domain/IpResource.java
View file @
d5b01f29
package
com
.
edgec
.
browserbackend
.
browser
.
domain
;
package
com
.
edgec
.
browserbackend
.
browser
.
domain
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
import
lombok.Setter
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.mongodb.core.mapping.Document
;
import
org.springframework.data.mongodb.core.mapping.Document
;
...
@@ -9,6 +12,9 @@ import java.util.ArrayList;
...
@@ -9,6 +12,9 @@ import java.util.ArrayList;
import
java.util.List
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.Objects
;
@Getter
@Setter
@NoArgsConstructor
@Document
(
collection
=
"ipresource"
)
@Document
(
collection
=
"ipresource"
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
IpResource
implements
Serializable
{
public
class
IpResource
implements
Serializable
{
...
@@ -53,270 +59,14 @@ public class IpResource implements Serializable {
...
@@ -53,270 +59,14 @@ public class IpResource implements Serializable {
private
String
unit
;
private
String
unit
;
private
int
period
;
private
int
period
;
public
IpResource
()
{
}
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
List
<
String
>
getShopIds
()
{
return
shopIds
;
}
public
void
setShopIds
(
List
<
String
>
shopIds
)
{
this
.
shopIds
=
shopIds
;
}
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
String
getShopId
()
{
return
shopId
;
}
public
void
setShopId
(
String
shopId
)
{
this
.
shopId
=
shopId
;
}
@Override
@Override
public
boolean
equals
(
Object
o
)
{
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
return
true
;
if
(
this
==
o
)
{
if
(!(
o
instanceof
IpResource
))
return
false
;
return
true
;
}
if
(!(
o
instanceof
IpResource
))
{
return
false
;
}
IpResource
that
=
(
IpResource
)
o
;
IpResource
that
=
(
IpResource
)
o
;
return
Objects
.
equals
(
getId
(),
that
.
getId
());
return
Objects
.
equals
(
getId
(),
that
.
getId
());
}
}
...
...
src/main/java/com/edgec/browserbackend/browser/domain/IpSummary.java
View file @
d5b01f29
package
com
.
edgec
.
browserbackend
.
browser
.
domain
;
package
com
.
edgec
.
browserbackend
.
browser
.
domain
;
public
class
IpSummary
{
import
lombok.Data
;
private
int
total
;
private
int
unbind
;
private
int
willExpire
;
private
int
expired
;
public
int
getExpired
()
{
return
expired
;
}
public
void
setExpired
(
int
expired
)
{
@Data
this
.
expired
=
expired
;
public
class
IpSummary
{
}
public
int
getTotal
()
{
return
total
;
}
public
void
setTotal
(
int
total
)
{
/**
this
.
total
=
total
;
* ip 总数
}
*/
private
int
total
;
public
int
getUnbind
()
{
/**
return
unbind
;
* 未绑定 ip 数
}
*/
private
int
unbind
;
public
void
setUnbind
(
int
unbind
)
{
/**
this
.
unbind
=
unbind
;
* 将要过期的 ip 数
}
*/
private
int
willExpire
;
public
int
getWillExpire
()
{
/**
return
willExpire
;
* 已过期的 ip 数
}
*/
private
int
expired
;
public
void
setWillExpire
(
int
willExpire
)
{
this
.
willExpire
=
willExpire
;
}
}
}
src/main/java/com/edgec/browserbackend/browser/domain/IpType.java
View file @
d5b01f29
package
com
.
edgec
.
browserbackend
.
browser
.
domain
;
package
com
.
edgec
.
browserbackend
.
browser
.
domain
;
public
enum
IpType
{
public
enum
IpType
{
/**
* 本地ip,即 ip 地址没有设置任何代理
*/
LOCAL
,
LOCAL
,
/**
* ip代理
*/
VENDOR
,
VENDOR
,
/**
* 自有ip,即该ip不是从我们系统购买的
*/
OWN
;
OWN
;
}
}
src/main/java/com/edgec/browserbackend/browser/domain/OperationHistory.java
View file @
d5b01f29
package
com
.
edgec
.
browserbackend
.
browser
.
domain
;
package
com
.
edgec
.
browserbackend
.
browser
.
domain
;
import
com.edgec.browserbackend.browser.dto.OperationHistoryDto
;
import
com.edgec.browserbackend.browser.dto.OperationHistoryDto
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
import
lombok.Setter
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.mongodb.core.mapping.Document
;
import
org.springframework.data.mongodb.core.mapping.Document
;
...
@@ -8,6 +11,9 @@ import java.time.LocalDateTime;
...
@@ -8,6 +11,9 @@ import java.time.LocalDateTime;
import
java.time.ZoneOffset
;
import
java.time.ZoneOffset
;
import
java.time.format.DateTimeFormatter
;
import
java.time.format.DateTimeFormatter
;
@Getter
@Setter
@NoArgsConstructor
@Document
(
collection
=
"operationhistory"
)
@Document
(
collection
=
"operationhistory"
)
public
class
OperationHistory
{
public
class
OperationHistory
{
@Id
@Id
...
@@ -20,89 +26,31 @@ public class OperationHistory {
...
@@ -20,89 +26,31 @@ public class OperationHistory {
private
long
operationTime
;
private
long
operationTime
;
private
String
administrator
;
private
String
administrator
;
public
OperationHistory
()
{
}
public
OperationHistory
(
OperationHistoryDto
operationHistoryDto
)
{
public
OperationHistory
(
OperationHistoryDto
operationHistoryDto
)
{
if
(
operationHistoryDto
.
getAccount
()
!=
null
)
if
(
operationHistoryDto
.
getAccount
()
!=
null
)
{
this
.
username
=
operationHistoryDto
.
getAccount
();
this
.
username
=
operationHistoryDto
.
getAccount
();
if
(
operationHistoryDto
.
getNickname
()
!=
null
)
}
if
(
operationHistoryDto
.
getNickname
()
!=
null
)
{
this
.
nickname
=
operationHistoryDto
.
getNickname
();
this
.
nickname
=
operationHistoryDto
.
getNickname
();
if
(
operationHistoryDto
.
getLoginIp
()
!=
null
)
}
if
(
operationHistoryDto
.
getLoginIp
()
!=
null
)
{
this
.
loginIp
=
operationHistoryDto
.
getLoginIp
();
this
.
loginIp
=
operationHistoryDto
.
getLoginIp
();
if
(
operationHistoryDto
.
getLoginPlace
()
!=
null
)
}
if
(
operationHistoryDto
.
getLoginPlace
()
!=
null
)
{
this
.
loginPlace
=
operationHistoryDto
.
getLoginPlace
();
this
.
loginPlace
=
operationHistoryDto
.
getLoginPlace
();
if
(
operationHistoryDto
.
getOperation
()
!=
null
)
}
if
(
operationHistoryDto
.
getOperation
()
!=
null
)
{
this
.
operation
=
operationHistoryDto
.
getOperation
();
this
.
operation
=
operationHistoryDto
.
getOperation
();
}
if
(
operationHistoryDto
.
getOperationTime
()
!=
null
)
{
if
(
operationHistoryDto
.
getOperationTime
()
!=
null
)
{
DateTimeFormatter
format
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm:ss"
);
DateTimeFormatter
format
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm:ss"
);
LocalDateTime
localDateTime
=
LocalDateTime
.
parse
(
operationHistoryDto
.
getOperationTime
(),
format
);
LocalDateTime
localDateTime
=
LocalDateTime
.
parse
(
operationHistoryDto
.
getOperationTime
(),
format
);
this
.
operationTime
=
localDateTime
.
toInstant
(
ZoneOffset
.
UTC
).
toEpochMilli
();
this
.
operationTime
=
localDateTime
.
toInstant
(
ZoneOffset
.
UTC
).
toEpochMilli
();
}
}
}
}
public
String
getId
()
{
return
id
;
}
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
public
String
getUsername
()
{
return
username
;
}
public
void
setUsername
(
String
username
)
{
this
.
username
=
username
;
}
public
long
getOperationTime
()
{
return
operationTime
;
}
public
void
setOperationTime
(
long
operationTime
)
{
this
.
operationTime
=
operationTime
;
}
public
String
getLoginIp
()
{
return
loginIp
;
}
public
void
setLoginIp
(
String
loginIp
)
{
this
.
loginIp
=
loginIp
;
}
public
String
getLoginPlace
()
{
return
loginPlace
;
}
public
void
setLoginPlace
(
String
loginPlace
)
{
this
.
loginPlace
=
loginPlace
;
}
public
String
getNickname
()
{
return
nickname
;
}
public
void
setNickname
(
String
nickname
)
{
this
.
nickname
=
nickname
;
}
public
String
getOperation
()
{
return
operation
;
}
public
void
setOperation
(
String
operation
)
{
this
.
operation
=
operation
;
}
public
String
getAdministrator
()
{
return
administrator
;
}
public
void
setAdministrator
(
String
administrator
)
{
this
.
administrator
=
administrator
;
}
}
}
src/main/java/com/edgec/browserbackend/browser/domain/PlatformOptions.java
View file @
d5b01f29
package
com
.
edgec
.
browserbackend
.
browser
.
domain
;
package
com
.
edgec
.
browserbackend
.
browser
.
domain
;
import
org.springframework.data.annotation.Id
;
import
lombok.Getter
;
import
lombok.Setter
;
import
org.springframework.data.mongodb.core.mapping.Document
;
import
org.springframework.data.mongodb.core.mapping.Document
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
/**
/**
...
@@ -11,26 +11,13 @@ import java.util.Map;
...
@@ -11,26 +11,13 @@ import java.util.Map;
* @Author jason
* @Author jason
* @CreateTime 2020/3/12 11:44 上午
* @CreateTime 2020/3/12 11:44 上午
**/
**/
@Getter
@Setter
@Document
(
"platformoptions"
)
@Document
(
"platformoptions"
)
public
class
PlatformOptions
{
public
class
PlatformOptions
{
private
String
platform
;
private
String
platform
;
private
Map
<
String
,
String
>
subPlatform
;
private
Map
<
String
,
String
>
subPlatform
;
public
Map
<
String
,
String
>
getSubPlatform
()
{
return
subPlatform
;
}
public
void
setPlatform
(
String
platform
)
{
this
.
platform
=
platform
;
}
public
String
getPlatform
()
{
return
platform
;
}
public
void
setSubPlatform
(
Map
<
String
,
String
>
subPlatform
)
{
this
.
subPlatform
=
subPlatform
;
}
}
}
src/main/java/com/edgec/browserbackend/browser/domain/ProxyConfig.java
View file @
d5b01f29
package
com
.
edgec
.
browserbackend
.
browser
.
domain
;
package
com
.
edgec
.
browserbackend
.
browser
.
domain
;
import
lombok.Getter
;
import
lombok.Setter
;
import
org.springframework.data.mongodb.core.mapping.Document
;
import
org.springframework.data.mongodb.core.mapping.Document
;
@Getter
@Setter
@Document
(
collection
=
"proxyconfig"
)
@Document
(
collection
=
"proxyconfig"
)
public
class
ProxyConfig
{
public
class
ProxyConfig
{
private
long
timestamp
;
private
long
timestamp
;
private
String
configFileId
;
private
String
configFileId
;
public
long
getTimestamp
()
{
return
timestamp
;
}
public
void
setConfigFileId
(
String
configFileId
)
{
this
.
configFileId
=
configFileId
;
}
public
String
getConfigFileId
()
{
return
configFileId
;
}
public
void
setTimestamp
(
long
timestamp
)
{
this
.
timestamp
=
timestamp
;
}
}
}
src/main/java/com/edgec/browserbackend/browser/domain/Shop.java
View file @
d5b01f29
package
com
.
edgec
.
browserbackend
.
browser
.
domain
;
package
com
.
edgec
.
browserbackend
.
browser
.
domain
;
import
com.alibaba.fastjson.JSONObject
;
import
com.edgec.browserbackend.browser.dto.ShopResultDto
;
import
com.edgec.browserbackend.browser.dto.ShopResultDto
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
import
lombok.Setter
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.mongodb.core.mapping.Document
;
import
org.springframework.data.mongodb.core.mapping.Document
;
@Getter
@Setter
@NoArgsConstructor
@Document
(
collection
=
"shop"
)
@Document
(
collection
=
"shop"
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
Shop
{
public
class
Shop
{
/**
* 商铺 id
*/
@Id
@Id
private
String
shopId
;
private
String
shopId
;
/**
* 商铺名称
*/
private
String
shopName
;
private
String
shopName
;
/**
* 商铺拥有者,谁创建谁拥有
*/
private
String
owner
;
private
String
owner
;
/**
* 商铺 id
*/
private
TransferStatus
transferStatus
;
private
TransferStatus
transferStatus
;
/**
* 商铺url
*/
private
String
shopUrl
;
private
String
shopUrl
;
/**
* 商铺所在的平台
*/
private
String
shopPlatform
;
private
String
shopPlatform
;
/**
* 商铺账号
*/
private
String
shopAccount
;
private
String
shopAccount
;
/**
* 商铺密码
*/
private
String
shopPassword
;
private
String
shopPassword
;
/**
* 商铺平台(操作系统 + 浏览器版本)
*/
private
String
shopUA
;
private
String
shopUA
;
/**
* 商铺的 cookie 信息
*/
private
String
shopCookie
;
private
String
shopCookie
;
/**
* 商铺创建时间
*/
private
long
createTime
;
private
long
createTime
;
public
Shop
(){
/**
* 创建店铺使用
*/
public
Shop
of
(
ShopResultDto
shopResultDto
)
{
if
(
shopResultDto
.
getShopUrl
()
!=
null
)
{
this
.
setShopUrl
(
shopResultDto
.
getShopUrl
());
}
}
if
(
shopResultDto
.
getOwner
()
!=
null
)
{
this
.
setOwner
(
shopResultDto
.
getOwner
());
}
if
(
shopResultDto
.
getShopPlatform
()
!=
null
)
{
this
.
setShopPlatform
(
shopResultDto
.
getShopPlatform
());
}
if
(
shopResultDto
.
getShopName
()
!=
null
)
{
this
.
setShopName
(
shopResultDto
.
getShopName
());
}
if
(
shopResultDto
.
getTransferStatus
()
!=
null
)
{
this
.
setTransferStatus
(
shopResultDto
.
getTransferStatus
());
}
if
(
shopResultDto
.
getShopAccount
()
!=
null
)
{
this
.
setShopAccount
(
shopResultDto
.
getShopAccount
());
}
if
(
shopResultDto
.
getShopPassword
()
!=
null
)
{
this
.
setShopPassword
(
shopResultDto
.
getShopPassword
());
}
if
(
shopResultDto
.
getShopUA
()
!=
null
)
{
this
.
setShopUA
(
shopResultDto
.
getShopUA
());
}
if
(
shopResultDto
.
getShopCookie
()
!=
null
)
{
this
.
setShopCookie
(
shopResultDto
.
getShopCookie
());
}
if
(
shopResultDto
.
getCreateTime
()
!=
0
)
{
this
.
setCreateTime
(
shopResultDto
.
getCreateTime
());
}
//创建店铺使用
public
Shop
of
(
ShopResultDto
shop
)
{
if
(
shop
.
getShopUrl
()
!=
null
)
this
.
setShopUrl
(
shop
.
getShopUrl
());
if
(
shop
.
getOwner
()
!=
null
)
this
.
setOwner
(
shop
.
getOwner
());
if
(
shop
.
getShopPlatform
()
!=
null
)
this
.
setShopPlatform
(
shop
.
getShopPlatform
());
if
(
shop
.
getShopName
()
!=
null
)
this
.
setShopName
(
shop
.
getShopName
());
if
(
shop
.
getTransferStatus
()
!=
null
)
this
.
setTransferStatus
(
shop
.
getTransferStatus
());
if
(
shop
.
getShopAccount
()
!=
null
)
this
.
setShopAccount
(
shop
.
getShopAccount
());
if
(
shop
.
getShopPassword
()
!=
null
)
this
.
setShopPassword
(
shop
.
getShopPassword
());
if
(
shop
.
getShopUA
()
!=
null
)
this
.
setShopUA
(
shop
.
getShopUA
());
if
(
shop
.
getShopCookie
()
!=
null
)
this
.
setShopCookie
(
shop
.
getShopCookie
());
if
(
shop
.
getCreateTime
()
!=
0
)
this
.
setCreateTime
(
shop
.
getCreateTime
());
return
this
;
return
this
;
}
}
...
@@ -83,95 +139,7 @@ public class Shop {
...
@@ -83,95 +139,7 @@ public class Shop {
this
.
setShopCookie
(
shop
.
getShopCookie
());
this
.
setShopCookie
(
shop
.
getShopCookie
());
if
(
shop
.
getCreateTime
()
!=
0
)
if
(
shop
.
getCreateTime
()
!=
0
)
this
.
setCreateTime
(
shop
.
getCreateTime
());
this
.
setCreateTime
(
shop
.
getCreateTime
());
return
this
;
}
public
String
getShopId
()
{
return
this
;
return
shopId
;
}
public
String
getShopUrl
()
{
return
shopUrl
;
}
public
String
getOwner
()
{
return
owner
;
}
public
String
getShopPlatform
()
{
return
shopPlatform
;
}
public
String
getShopName
()
{
return
shopName
;
}
public
TransferStatus
getTransferStatus
()
{
return
transferStatus
;
}
public
void
setShopId
(
String
shopId
)
{
this
.
shopId
=
shopId
;
}
public
void
setShopUrl
(
String
shopUrl
)
{
this
.
shopUrl
=
shopUrl
;
}
public
void
setOwner
(
String
owner
)
{
this
.
owner
=
owner
;
}
public
void
setShopPlatform
(
String
shopPlatform
)
{
this
.
shopPlatform
=
shopPlatform
;
}
public
void
setShopName
(
String
shopName
)
{
this
.
shopName
=
shopName
;
}
public
void
setTransferStatus
(
TransferStatus
transferStatus
)
{
this
.
transferStatus
=
transferStatus
;
}
public
String
getShopAccount
()
{
return
shopAccount
;
}
public
void
setShopAccount
(
String
shopAccount
)
{
this
.
shopAccount
=
shopAccount
;
}
public
String
getShopPassword
()
{
return
shopPassword
;
}
public
void
setShopPassword
(
String
shopPassword
)
{
this
.
shopPassword
=
shopPassword
;
}
public
String
getShopCookie
()
{
return
shopCookie
;
}
public
void
setShopCookie
(
String
shopCookie
)
{
this
.
shopCookie
=
shopCookie
;
}
public
String
getShopUA
()
{
return
shopUA
;
}
public
void
setShopUA
(
String
shopUA
)
{
this
.
shopUA
=
shopUA
;
}
public
long
getCreateTime
()
{
return
createTime
;
}
public
void
setCreateTime
(
long
createTime
)
{
this
.
createTime
=
createTime
;
}
}
}
}
src/main/java/com/edgec/browserbackend/browser/domain/ShopSummary.java
View file @
d5b01f29
package
com
.
edgec
.
browserbackend
.
browser
.
domain
;
package
com
.
edgec
.
browserbackend
.
browser
.
domain
;
public
class
ShopSummary
{
private
int
total
;
private
int
unbind
;
private
int
willExpire
;
private
int
expired
;
public
int
getExpired
()
{
return
expired
;
}
public
void
setExpired
(
int
expired
)
{
import
lombok.Getter
;
this
.
expired
=
expired
;
import
lombok.Setter
;
}
public
int
getTotal
()
{
@Getter
return
total
;
@Setter
}
public
class
ShopSummary
{
public
void
setTotal
(
int
total
)
{
this
.
total
=
total
;
}
public
int
getUnbind
()
{
/**
return
unbind
;
* 商铺 总数
}
*/
private
int
total
;
public
void
setUnbind
(
int
unbind
)
{
/**
this
.
unbind
=
unbind
;
* 未绑定商铺数
}
*/
private
int
unbind
;
public
int
getWillExpire
()
{
/**
return
willExpire
;
* 即将过期商铺数
}
*/
private
int
willExpire
;
public
void
setWillExpire
(
int
willExpire
)
{
/**
this
.
willExpire
=
willExpire
;
* 已过期商铺数
}
*/
private
int
expired
;
}
}
src/main/java/com/edgec/browserbackend/browser/domain/SpecialLine.java
View file @
d5b01f29
package
com
.
edgec
.
browserbackend
.
browser
.
domain
;
package
com
.
edgec
.
browserbackend
.
browser
.
domain
;
import
lombok.Getter
;
import
lombok.Setter
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.mongodb.core.mapping.Document
;
import
org.springframework.data.mongodb.core.mapping.Document
;
import
java.util.List
;
import
java.util.List
;
@Getter
@Setter
@Document
(
"specialline"
)
@Document
(
"specialline"
)
public
class
SpecialLine
{
public
class
SpecialLine
{
/**
* 专线 id
*/
@Id
@Id
private
String
Id
;
private
String
Id
;
/**
* 专线 ip
*/
private
String
ip
;
private
String
ip
;
private
List
<
String
>
proxyProtocol
;
//专线使用的协议
/**
private
List
<
String
>
proxyPort
;
//专线使用的端口
* 专线使用的协议
*/
private
String
username
;
//专线代理服务器用户名
private
List
<
String
>
proxyProtocol
;
private
String
password
;
//专线代理服务器密码
public
String
getIp
()
{
return
ip
;
}
public
void
setIp
(
String
ip
)
{
this
.
ip
=
ip
;
}
public
String
getId
()
{
return
Id
;
}
public
void
setId
(
String
id
)
{
Id
=
id
;
}
public
List
<
String
>
getProxyProtocol
()
{
return
proxyProtocol
;
}
public
void
setProxyProtocol
(
List
<
String
>
proxyProtocol
)
{
this
.
proxyProtocol
=
proxyProtocol
;
}
public
List
<
String
>
getProxyPort
()
{
return
proxyPort
;
}
public
void
setProxyPort
(
List
<
String
>
proxyPort
)
{
this
.
proxyPort
=
proxyPort
;
}
public
String
getPassword
()
{
/**
return
password
;
* 专线使用的端口
}
*/
private
List
<
String
>
proxyPort
;
public
void
setPassword
(
String
password
)
{
/**
this
.
password
=
password
;
* 专线代理服务器用户名
}
*/
private
String
username
;
public
String
getUsername
()
{
/**
return
username
;
* 专线代理服务器密码
}
*/
private
String
password
;
public
void
setUsername
(
String
username
)
{
this
.
username
=
username
;
}
}
}
src/main/java/com/edgec/browserbackend/browser/domain/UserShop.java
View file @
d5b01f29
package
com
.
edgec
.
browserbackend
.
browser
.
domain
;
package
com
.
edgec
.
browserbackend
.
browser
.
domain
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
import
lombok.Setter
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.mongodb.core.mapping.Document
;
import
org.springframework.data.mongodb.core.mapping.Document
;
import
java.util.List
;
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Document
(
collection
=
"usershop"
)
@Document
(
collection
=
"usershop"
)
public
class
UserShop
{
public
class
UserShop
{
...
@@ -17,56 +23,13 @@ public class UserShop {
...
@@ -17,56 +23,13 @@ public class UserShop {
private
String
groupId
;
private
String
groupId
;
public
UserShop
(){
}
public
UserShop
(
String
username
,
String
shopId
)
{
public
UserShop
(
String
username
,
String
shopId
)
{
this
.
username
=
username
;
this
.
username
=
username
;
this
.
shopId
=
shopId
;
this
.
shopId
=
shopId
;
}
}
public
UserShop
(
String
username
,
String
shopId
,
String
groupId
)
{
public
UserShop
(
String
username
,
String
shopId
,
String
groupId
)
{
this
.
username
=
username
;
this
(
username
,
shopId
);
this
.
shopId
=
shopId
;
this
.
groupId
=
groupId
;
}
public
UserShop
(
String
username
,
String
shopId
,
String
groupId
,
String
ipId
)
{
this
.
username
=
username
;
this
.
shopId
=
shopId
;
this
.
groupId
=
groupId
;
}
public
String
getId
()
{
return
id
;
}
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
public
String
getUsername
()
{
return
username
;
}
public
void
setUsername
(
String
username
)
{
this
.
username
=
username
;
}
public
String
getShopId
()
{
return
shopId
;
}
public
void
setShopId
(
String
shopId
)
{
this
.
shopId
=
shopId
;
}
public
String
getGroupId
()
{
return
groupId
;
}
public
void
setGroupId
(
String
groupId
)
{
this
.
groupId
=
groupId
;
this
.
groupId
=
groupId
;
}
}
}
}
src/main/java/com/edgec/browserbackend/browser/domain/Vendor.java
View file @
d5b01f29
...
@@ -4,13 +4,31 @@ package com.edgec.browserbackend.browser.domain;
...
@@ -4,13 +4,31 @@ package com.edgec.browserbackend.browser.domain;
* @Desc
* @Desc
* @Author jason
* @Author jason
* @CreateTime 2020/3/12 4:01 下午
* @CreateTime 2020/3/12 4:01 下午
*
*
/
*/
public
enum
Vendor
{
public
enum
Vendor
{
aliyun
(
"阿里云"
),
JDCLOUD
(
"京东云"
),
aws
(
"亚马逊云"
),
awscn
(
"亚马逊中国"
),
tencent
(
"腾讯云"
),
local
(
"本地"
),
own
(
"自有"
);
/**
* 本平台提供的代理ip
*/
aliyun
(
"阿里云"
),
JDCLOUD
(
"京东云"
),
aws
(
"亚马逊云"
),
awscn
(
"亚马逊中国"
),
tencent
(
"腾讯云"
),
/**
* 本地ip,即 ip 地址没有设置任何代理
*/
local
(
"本地"
),
/**
* 用户自己已经拥有的代理ip
*/
own
(
"自有"
);
private
String
value
;
private
String
value
;
private
Vendor
(
String
value
)
{
Vendor
(
String
value
)
{
this
.
value
=
value
;
this
.
value
=
value
;
}
}
...
...
src/main/java/com/edgec/browserbackend/browser/dto/IpListRequestDto.java
View file @
d5b01f29
...
@@ -2,12 +2,14 @@ package com.edgec.browserbackend.browser.dto;
...
@@ -2,12 +2,14 @@ package com.edgec.browserbackend.browser.dto;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
java.util.ArrayList
;
import
java.util.List
;
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
IpListRequestDto
{
public
class
IpListRequestDto
{
/**
* 1: 全部; 2: 即将过期 ; 3: 已过期; 4: 未绑定; 5: 已分配
*/
private
int
groupType
;
private
int
groupType
;
private
int
page
;
private
int
page
;
private
int
amount
;
private
int
amount
;
private
IpFilterDto
filter
;
private
IpFilterDto
filter
;
...
...
src/main/java/com/edgec/browserbackend/browser/service/Impl/IpResourceServiceImpl.java
View file @
d5b01f29
...
@@ -18,6 +18,7 @@ import com.edgec.browserbackend.common.commons.error.ClientRequestException;
...
@@ -18,6 +18,7 @@ import com.edgec.browserbackend.common.commons.error.ClientRequestException;
import
com.edgec.browserbackend.common.commons.utils.NotifyUtils
;
import
com.edgec.browserbackend.common.commons.utils.NotifyUtils
;
import
com.edgec.browserbackend.common.utils.FileUtil
;
import
com.edgec.browserbackend.common.utils.FileUtil
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.jetbrains.annotations.NotNull
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -53,6 +54,54 @@ public class IpResourceServiceImpl implements IpResourceService {
...
@@ -53,6 +54,54 @@ public class IpResourceServiceImpl implements IpResourceService {
"brazil"
,
"virginia"
,
"ohio"
,
"california"
,
"oregon"
,
"ireland"
,
"london"
,
"ireland"
"brazil"
,
"virginia"
,
"ohio"
,
"california"
,
"oregon"
,
"ireland"
,
"london"
,
"ireland"
);
);
public
static
String
genRandom
(
int
srcFlag
,
int
length
)
{
String
retStr
=
""
;
String
strTable
=
""
;
switch
(
srcFlag
)
{
case
1
:
strTable
=
"1234567890"
;
break
;
case
2
:
strTable
=
"1234567890abcdefghijklmnopqrstuvwxyz"
;
break
;
case
3
:
strTable
=
"12345678901234567890abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
;
break
;
case
4
:
strTable
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
;
break
;
case
5
:
strTable
=
"abcdefghijklmnopqrstuvwxyz"
;
break
;
default
:
strTable
=
"1234567890abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
;
break
;
}
int
len
=
strTable
.
length
()
-
3
;
boolean
bDone
=
true
;
do
{
retStr
=
""
;
int
count
=
0
;
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
double
dblR
=
Math
.
random
()
*
len
;
int
intR
=
(
int
)
Math
.
floor
(
dblR
);
char
c
=
strTable
.
charAt
(
intR
);
if
((
'0'
<=
c
)
&&
(
c
<=
'9'
))
{
count
++;
}
retStr
+=
strTable
.
charAt
(
intR
);
}
if
(
count
>=
2
)
{
bDone
=
false
;
}
}
while
(
bDone
);
retStr
+=
"a"
;
retStr
+=
"A"
;
retStr
+=
"1"
;
return
retStr
;
}
private
static
List
<
String
>
port
=
Arrays
.
asList
(
"20000"
,
"20001"
);
private
static
List
<
String
>
port
=
Arrays
.
asList
(
"20000"
,
"20001"
);
private
static
List
<
String
>
protocol
=
Arrays
.
asList
(
"socks5"
,
"proxy"
);
private
static
List
<
String
>
protocol
=
Arrays
.
asList
(
"socks5"
,
"proxy"
);
...
@@ -106,65 +155,6 @@ public class IpResourceServiceImpl implements IpResourceService {
...
@@ -106,65 +155,6 @@ public class IpResourceServiceImpl implements IpResourceService {
return
headers
;
return
headers
;
}
}
public
static
String
genRandom
(
int
srcFlag
,
int
length
)
{
String
retStr
=
""
;
String
strTable
=
""
;
switch
(
srcFlag
)
{
case
1
:
strTable
=
"1234567890"
;
break
;
case
2
:
strTable
=
"1234567890abcdefghijklmnopqrstuvwxyz"
;
break
;
case
3
:
strTable
=
"12345678901234567890abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
;
break
;
case
4
:
strTable
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
;
break
;
case
5
:
strTable
=
"abcdefghijklmnopqrstuvwxyz"
;
break
;
default
:
strTable
=
"1234567890abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
;
break
;
}
int
len
=
strTable
.
length
()
-
3
;
boolean
bDone
=
true
;
do
{
retStr
=
""
;
int
count
=
0
;
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
double
dblR
=
Math
.
random
()
*
len
;
int
intR
=
(
int
)
Math
.
floor
(
dblR
);
char
c
=
strTable
.
charAt
(
intR
);
if
((
'0'
<=
c
)
&&
(
c
<=
'9'
))
{
count
++;
}
retStr
+=
strTable
.
charAt
(
intR
);
}
if
(
count
>=
2
)
{
bDone
=
false
;
}
}
while
(
bDone
);
retStr
+=
"a"
;
retStr
+=
"A"
;
retStr
+=
"1"
;
return
retStr
;
}
private
IpChargeRequestDto
buildIpChargeRequestDto
(
IpResourceRequestDto
request
,
int
chargeType
,
int
payMethod
)
{
IpChargeRequestDto
ipChargeRequestDto
=
new
IpChargeRequestDto
();
ipChargeRequestDto
.
setAmount
(
request
.
getAmount
());
ipChargeRequestDto
.
setChargeType
(
chargeType
);
ipChargeRequestDto
.
setRegion
(
request
.
getRegion
());
ipChargeRequestDto
.
setPeriod
(
request
.
getPeriod
());
ipChargeRequestDto
.
setUnit
(
request
.
getUnit
());
ipChargeRequestDto
.
setPayMethod
(
payMethod
);
return
ipChargeRequestDto
;
}
@Override
@Override
public
List
<
String
>
buyIp
(
String
username
,
IpResourceRequestDto
ipResourceRequestDto
)
throws
Exception
{
public
List
<
String
>
buyIp
(
String
username
,
IpResourceRequestDto
ipResourceRequestDto
)
throws
Exception
{
Account
account
=
accountRepository
.
findByName
(
username
);
Account
account
=
accountRepository
.
findByName
(
username
);
...
@@ -419,106 +409,110 @@ public class IpResourceServiceImpl implements IpResourceService {
...
@@ -419,106 +409,110 @@ public class IpResourceServiceImpl implements IpResourceService {
@Override
@Override
public
IpOperationResultDto
deleteIp
(
String
username
,
IpResourceRequestDto
ipResourceRequestDto
)
{
public
IpOperationResultDto
deleteIp
(
String
username
,
IpResourceRequestDto
ipResourceRequestDto
)
{
String
URL
=
(
profiles
.
equals
(
"dev"
)
||
profiles
.
equals
(
"staging"
))
?
TESTURL
:
CLOUDAMURL
;
Account
account
=
accountRepository
.
findByName
(
username
);
Account
account
=
accountRepository
.
findByName
(
username
);
if
(
account
==
null
)
if
(
account
==
null
)
{
throw
new
ClientRequestException
(
AccountErrorCode
.
NAMENOTEXIST
);
throw
new
ClientRequestException
(
AccountErrorCode
.
NAMENOTEXIST
);
IpOperationResultDto
ipOperationResultDto
=
new
IpOperationResultDto
();
}
String
URL
=
(
profiles
.
equals
(
"dev"
)
||
profiles
.
equals
(
"staging"
))
?
TESTURL
:
CLOUDAMURL
;
RestTemplate
restTemplate
=
new
RestTemplate
();
RestTemplate
restTemplate
=
new
RestTemplate
();
HttpHeaders
headers
=
buildGetHeader
();
HttpHeaders
headers
=
buildGetHeader
();
Map
<
String
,
String
>
params
=
new
HashMap
<
String
,
String
>();
Map
<
String
,
String
>
params
=
new
HashMap
<
String
,
String
>();
HttpEntity
<
Map
<
String
,
String
>>
httpEntity
=
new
HttpEntity
<>(
params
,
headers
);
HttpEntity
<
Map
<
String
,
String
>>
httpEntity
=
new
HttpEntity
<>(
params
,
headers
);
IpOperationResultDto
ipOperationResultDto
=
new
IpOperationResultDto
();
if
(
ipResourceRequestDto
.
getAddr
()
!=
null
&&
ipResourceRequestDto
.
getAddr
().
size
()
>
0
)
{
if
(
ipResourceRequestDto
.
getAddr
()
!=
null
&&
ipResourceRequestDto
.
getAddr
().
size
()
>
0
)
{
ipResourceRequestDto
.
getAddr
().
forEach
(
ipAddr
->
{
ipResourceRequestDto
.
getAddr
().
forEach
(
IpResource
ipResource
=
ipResourceRepository
.
findByAddrAndIsDeletedAndIsLocked
(
ipAddr
,
false
,
false
);
ipAddr
->
{
if
(
ipResource
==
null
)
{
// 1. 查找需要删除的 ip 资源 是否被占用、 是否是当前用户的,若占用或不是当前用户的,则删除失败
ipOperationResultDto
.
getFailList
().
add
(
ipAddr
);
IpResource
ipResource
=
ipResourceRepository
.
findByAddrAndIsDeletedAndIsLocked
(
ipAddr
,
false
,
false
);
return
;
if
(
ipResource
==
null
)
{
}
ipOperationResultDto
.
getFailList
().
add
(
ipAddr
);
UserShop
userShop
=
null
;
// 在 foreach 中 return 的作用 相当于 普通 for循环中 continue 的作用
return
;
if
(
ipResource
.
getShopIds
()
!=
null
)
{
}
List
<
Shop
>
shops
=
shopRepository
.
findByShopIdIn
(
ipResource
.
getShopIds
());
if
(
shops
!=
null
&&
shops
.
size
()
>
0
)
{
// 2. 如果根据 shopId 与 用户名 查不到 用户的商铺,则删除失败
for
(
Shop
shop
:
shops
)
{
if
(
ipResource
.
getShopIds
()
!=
null
)
{
if
(
shop
!=
null
)
{
List
<
Shop
>
shops
=
shopRepository
.
findByShopIdIn
(
ipResource
.
getShopIds
());
userShop
=
userShopRepository
.
findByUsernameAndShopId
(
username
,
shop
.
getShopId
());
for
(
Shop
shop
:
shops
)
{
UserShop
userShop
=
userShopRepository
.
findByUsernameAndShopId
(
username
,
shop
.
getShopId
());
if
(
userShop
==
null
)
{
if
(
userShop
==
null
)
{
ipOperationResultDto
.
getFailList
().
add
(
ipAddr
);
ipOperationResultDto
.
getFailList
().
add
(
ipAddr
);
return
;
return
;
}
}
}
else
if
(!
ipResource
.
getOwner
().
equals
(
username
))
{
ipOperationResultDto
.
getFailList
().
add
(
ipAddr
);
return
;
}
}
}
}
try
{
// 调用 uri删除远程的 IP资源
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
);
if
(
deleteIpResultDto
.
getResult
().
equals
(
"failed"
)
||
StringUtils
.
isNotBlank
(
deleteIpResultDto
.
getErrorCode
()))
{
NotifyUtils
.
sendMessage
(
"防关联浏览器 ip "
+
ipResource
.
getAddr
()
+
" 删除失败"
,
NotifyUtils
.
MsgType
.
WEBHOOK
);
logger
.
error
(
"ip "
+
ipResource
.
getAddr
()
+
" 删除失败"
);
logger
.
error
(
"ErrorCode: "
+
deleteIpResultDto
.
getErrorCode
()
+
" "
+
deleteIpResultDto
.
getResult
());
}
// ip资源为未绑定,则直接删除
if
(
ipResource
.
getStatus
()
==
6
)
{
ipResourceRepository
.
delete
(
ipResource
);
// 其他情况(主要是 ip资源还未创建成功的状态),则将 ip资源的状态改为删除
}
else
{
ipResource
.
setShopIds
(
null
);
ipResource
.
setDeleted
(
true
);
ipResourceRepository
.
save
(
ipResource
);
}
ipOperationResultDto
.
getSuccessList
().
add
(
ipAddr
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"fail to delete ip"
,
e
.
getMessage
());
ipOperationResultDto
.
getFailList
().
add
(
ipAddr
);
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
);
if
(
deleteIpResultDto
.
getResult
().
equals
(
"failed"
)
||
StringUtils
.
isNotBlank
(
deleteIpResultDto
.
getErrorCode
()))
{
NotifyUtils
.
sendMessage
(
"防关联浏览器 ip "
+
ipResource
.
getAddr
()
+
" 删除失败"
,
NotifyUtils
.
MsgType
.
WEBHOOK
);
logger
.
error
(
"ip "
+
ipResource
.
getAddr
()
+
" 删除失败"
);
logger
.
error
(
"ErrorCode: "
+
deleteIpResultDto
.
getErrorCode
()
+
" "
+
deleteIpResultDto
.
getResult
());
}
if
(
ipResource
.
getStatus
()
==
6
)
ipResourceRepository
.
delete
(
ipResource
);
else
{
ipResource
.
setShopIds
(
null
);
ipResource
.
setDeleted
(
true
);
ipResourceRepository
.
save
(
ipResource
);
}
ipOperationResultDto
.
getSuccessList
().
add
(
ipAddr
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"fail to delete ip"
,
e
.
getMessage
());
ipOperationResultDto
.
getFailList
().
add
(
ipAddr
);
return
;
}
});
}
}
if
(
ipResourceRequestDto
.
getIpId
()
!=
null
&&
ipResourceRequestDto
.
getIpId
().
size
()
>
0
)
{
if
(
ipResourceRequestDto
.
getIpId
()
!=
null
&&
ipResourceRequestDto
.
getIpId
().
size
()
>
0
)
{
ipResourceRequestDto
.
getIpId
().
forEach
(
ipId
->
{
ipResourceRequestDto
.
getIpId
().
forEach
(
IpResource
ipResource
=
ipResourceRepository
.
findByIdAndIsDeletedAndIsLocked
(
ipId
,
false
,
false
);
ipId
->
{
if
(
ipResource
==
null
)
{
IpResource
ipResource
=
ipResourceRepository
.
findByIdAndIsDeletedAndIsLocked
(
ipId
,
false
,
false
);
ipOperationResultDto
.
getFailList
().
add
(
ipId
);
if
(
ipResource
==
null
)
{
return
;
ipOperationResultDto
.
getFailList
().
add
(
ipId
);
}
return
;
if
(
ipResource
.
getStatus
()
==
6
)
}
ipResourceRepository
.
delete
(
ipResource
);
if
(
ipResource
.
getStatus
()
==
6
)
{
else
if
(
StringUtils
.
isNotBlank
(
ipResource
.
getAddr
())
&&
ipResource
.
getIpType
()
==
IpType
.
VENDOR
)
{
ipResourceRepository
.
delete
(
ipResource
);
ResponseEntity
<
String
>
result
=
restTemplate
.
exchange
(
URL
+
"/intelligroup/ipresources?accountId=browser&ip={ip}"
,
}
else
if
(
StringUtils
.
isNotBlank
(
ipResource
.
getAddr
())
&&
ipResource
.
getIpType
()
==
IpType
.
VENDOR
)
{
HttpMethod
.
DELETE
,
httpEntity
,
String
.
class
,
ipResource
.
getAddr
());
ResponseEntity
<
String
>
result
=
restTemplate
.
exchange
(
URL
+
"/intelligroup/ipresources?accountId=browser&ip={ip}"
,
DeleteIpResultDto
deleteIpResultDto
=
JSON
.
parseObject
(
result
.
getBody
(),
DeleteIpResultDto
.
class
);
HttpMethod
.
DELETE
,
httpEntity
,
String
.
class
,
ipResource
.
getAddr
());
if
(
deleteIpResultDto
.
getResult
().
equals
(
"failed"
)
||
StringUtils
.
isNotBlank
(
deleteIpResultDto
.
getErrorCode
()))
{
DeleteIpResultDto
deleteIpResultDto
=
JSON
.
parseObject
(
result
.
getBody
(),
DeleteIpResultDto
.
class
);
NotifyUtils
.
sendMessage
(
"防关联浏览器 ip "
+
ipResource
.
getAddr
()
+
" 删除失败"
,
NotifyUtils
.
MsgType
.
WEBHOOK
);
if
(
deleteIpResultDto
.
getResult
().
equals
(
"failed"
)
||
StringUtils
.
isNotBlank
(
deleteIpResultDto
.
getErrorCode
()))
{
logger
.
error
(
"ip "
+
ipResource
.
getAddr
()
+
" 删除失败"
);
NotifyUtils
.
sendMessage
(
"防关联浏览器 ip "
+
ipResource
.
getAddr
()
+
" 删除失败"
,
NotifyUtils
.
MsgType
.
WEBHOOK
);
}
logger
.
error
(
"ip "
+
ipResource
.
getAddr
()
+
" 删除失败"
);
}
}
UserShop
userShop
=
null
;
}
if
(
ipResource
.
getShopIds
()
!=
null
)
{
List
<
Shop
>
shops
=
shopRepository
.
findByShopIdIn
(
ipResource
.
getShopIds
());
if
(
ipResource
.
getShopIds
()
!=
null
)
{
if
(
shops
!=
null
&&
shops
.
size
()
>
0
)
{
List
<
Shop
>
shops
=
shopRepository
.
findByShopIdIn
(
ipResource
.
getShopIds
());
for
(
Shop
shop
:
shops
)
{
if
(
shops
!=
null
&&
shops
.
size
()
>
0
)
{
if
(
shop
!=
null
)
{
for
(
Shop
shop
:
shops
)
{
userShop
=
userShopRepository
.
findByUsernameAndShopId
(
username
,
shop
.
getShopId
());
UserShop
userShop
=
userShopRepository
.
findByUsernameAndShopId
(
username
,
shop
.
getShopId
());
if
(
userShop
==
null
)
{
if
(
userShop
==
null
)
{
ipOperationResultDto
.
getFailList
().
add
(
ipId
);
ipOperationResultDto
.
getFailList
().
add
(
ipId
);
return
;
return
;
}
}
}
}
else
if
(!
ipResource
.
getOwner
().
equals
(
username
))
{
ipOperationResultDto
.
getFailList
().
add
(
ipId
);
return
;
}
}
}
}
ipResource
.
setDeleted
(
true
);
ipResource
.
setShopIds
(
null
);
ipResourceRepository
.
save
(
ipResource
);
ipOperationResultDto
.
getSuccessList
().
add
(
ipId
);
}
}
}
);
ipResource
.
setDeleted
(
true
);
ipResource
.
setShopIds
(
null
);
ipResourceRepository
.
save
(
ipResource
);
ipOperationResultDto
.
getSuccessList
().
add
(
ipId
);
});
}
}
return
ipOperationResultDto
;
return
ipOperationResultDto
;
...
@@ -526,67 +520,29 @@ public class IpResourceServiceImpl implements IpResourceService {
...
@@ -526,67 +520,29 @@ public class IpResourceServiceImpl implements IpResourceService {
@Override
@Override
public
IpPageResultDto
getIpList
(
String
username
,
int
groupType
,
int
page
,
int
amount
,
IpFilterDto
ipFilterDto
)
{
public
IpPageResultDto
getIpList
(
String
username
,
int
groupType
,
int
page
,
int
amount
,
IpFilterDto
ipFilterDto
)
{
if
(
amount
>
100
)
// 获取当前用户的账户
amount
=
100
;
Pageable
pageable
=
PageRequest
.
of
(
page
,
amount
);
Account
account
=
accountRepository
.
findByName
(
username
);
Account
account
=
accountRepository
.
findByName
(
username
);
if
(
account
==
null
)
if
(
account
==
null
)
{
throw
new
ClientRequestException
(
AccountErrorCode
.
NAMENOTEXIST
);
throw
new
ClientRequestException
(
AccountErrorCode
.
NAMENOTEXIST
);
List
<
String
>
shopIds
=
userShopRepository
.
findByUsername
(
username
).
stream
().
map
(
x
->
x
.
getShopId
()).
collect
(
Collectors
.
toList
());
List
<
IpResource
>
ipResources
=
new
ArrayList
<>();
List
<
IpResource
>
notUsed
=
null
;
List
<
String
>
children
=
new
ArrayList
<>();
boolean
isParent
=
false
;
if
(
account
.
getParent
()
==
null
)
{
isParent
=
true
;
children
=
accountRepository
.
findByParent
(
account
.
getName
()).
stream
().
map
(
Account:
:
getName
).
collect
(
Collectors
.
toList
());
}
}
children
.
add
(
account
.
getName
());
List
<
IpResource
>
ipResources
=
new
ArrayList
<>();
List
<
IpResource
>
notUsed
=
new
ArrayList
<>();
// 获取当前用户的 ip 资及未使用的 ip资源
dealIpResourceByGroup
(
ipResources
,
notUsed
,
account
,
username
,
groupType
);
switch
(
groupType
)
{
if
(
notUsed
!=
null
)
{
case
1
:
ipResources
=
ipResourceRepository
.
findShopIdInList
(
shopIds
,
false
);
if
(!
isParent
)
notUsed
=
ipResourceRepository
.
findByOwnerAndIsDeletedAndBind
(
username
,
false
,
false
);
else
notUsed
=
ipResourceRepository
.
findByOwnerInAndIsDeletedAndBind
(
children
,
false
,
false
);
break
;
case
2
:
ipResources
=
ipResourceRepository
.
findShopIdInListAndStatus
(
shopIds
,
false
,
2
);
if
(!
isParent
)
notUsed
=
ipResourceRepository
.
findByOwnerAndStatusAndIsDeletedAndBind
(
username
,
2
,
false
,
false
);
else
notUsed
=
ipResourceRepository
.
findByOwnerInAndStatusAndIsDeletedAndBind
(
children
,
2
,
false
,
false
);
break
;
case
3
:
ipResources
=
ipResourceRepository
.
findShopIdInListAndStatus
(
shopIds
,
false
,
1
);
if
(!
isParent
)
notUsed
=
ipResourceRepository
.
findByOwnerAndStatusAndIsDeletedAndBind
(
username
,
1
,
false
,
false
);
else
notUsed
=
ipResourceRepository
.
findByOwnerInAndStatusAndIsDeletedAndBind
(
children
,
1
,
false
,
false
);
break
;
case
4
:
if
(!
isParent
)
notUsed
=
ipResourceRepository
.
findByOwnerAndStatusIsNotInAndIsDeletedAndBind
(
username
,
Arrays
.
asList
(
3
,
5
,
6
),
false
,
false
);
else
notUsed
=
ipResourceRepository
.
findByOwnerInAndStatusIsNotInAndIsDeletedAndBind
(
children
,
Arrays
.
asList
(
3
,
5
,
6
),
false
,
false
);
break
;
case
5
:
// 已分配
ipResources
=
ipResourceRepository
.
findShopIdInList
(
shopIds
,
false
);
if
(!
isParent
)
notUsed
=
ipResourceRepository
.
findByOwnerAndStatusInAndIsDeletedAndBind
(
username
,
Arrays
.
asList
(
0
,
2
,
4
,
8
),
false
,
false
);
else
notUsed
=
ipResourceRepository
.
findByOwnerInAndStatusInAndIsDeletedAndBind
(
children
,
Arrays
.
asList
(
0
,
2
,
4
,
8
),
false
,
false
);
break
;
}
if
(
notUsed
!=
null
)
ipResources
.
addAll
(
notUsed
);
ipResources
.
addAll
(
notUsed
);
}
List
<
IpResourceDto
>
ipResourceDtos
=
new
ArrayList
<>();
List
<
IpResourceDto
>
ipResourceDtos
=
new
ArrayList
<>();
List
<
String
>
allIpIds
=
ipResources
.
stream
().
distinct
().
map
(
x
->
x
.
getId
()).
collect
(
Collectors
.
toList
());
// 去掉重复 ip
List
<
String
>
allIpIds
=
ipResources
.
stream
().
distinct
().
map
(
IpResource:
:
getId
).
collect
(
Collectors
.
toList
());
// 根据过滤条件来分页获取 ip 资源
amount
=
amount
>
100
?
100
:
amount
;
Pageable
pageable
=
PageRequest
.
of
(
page
,
amount
);
Page
<
IpResource
>
ipResources1
=
null
;
Page
<
IpResource
>
ipResources1
=
null
;
if
(
ipFilterDto
!=
null
&&
StringUtils
.
isNotBlank
(
ipFilterDto
.
getRegion
()))
{
if
(
ipFilterDto
!=
null
&&
StringUtils
.
isNotBlank
(
ipFilterDto
.
getRegion
()))
{
ipResources1
=
ipResourceRepository
.
findByIsDeletedAndIdInAndRegionCnLikeOrderByPurchasedTimeDesc
(
false
,
allIpIds
,
ipFilterDto
.
getRegion
(),
pageable
);
ipResources1
=
ipResourceRepository
.
findByIsDeletedAndIdInAndRegionCnLikeOrderByPurchasedTimeDesc
(
false
,
allIpIds
,
ipFilterDto
.
getRegion
(),
pageable
);
...
@@ -597,60 +553,69 @@ public class IpResourceServiceImpl implements IpResourceService {
...
@@ -597,60 +553,69 @@ public class IpResourceServiceImpl implements IpResourceService {
}
else
{
}
else
{
ipResources1
=
ipResourceRepository
.
findByIdInAndIsDeletedOrderByPurchasedTimeDesc
(
allIpIds
,
false
,
pageable
);
ipResources1
=
ipResourceRepository
.
findByIdInAndIsDeletedOrderByPurchasedTimeDesc
(
allIpIds
,
false
,
pageable
);
}
}
if
(
ipResources1
!=
null
)
{
if
(
ipResources1
!=
null
)
{
ipResources1
.
getContent
().
forEach
(
x
->
{
ipResources1
.
getContent
().
forEach
(
List
<
ShopDto
>
shopDtos
=
new
ArrayList
<>();
x
->
{
List
<
Shop
>
shops
=
null
;
// 1. 如果 ip 资源的 addr 非空
if
(
x
.
getShopIds
()
!=
null
)
if
(
StringUtils
.
isNotBlank
(
x
.
getAddr
()))
{
shops
=
shopRepository
.
findByShopIdIn
(
x
.
getShopIds
());
// 1.1 锁定时间在 2分钟内 且 IpType 为 VENDOR 且 (IP资源状态 为 0:正常 或 2:即将过期)
if
(
shops
==
null
||
shops
.
size
()
==
0
)
{
if
(
x
.
getLockTimestamp
()
>=
Instant
.
now
().
minusSeconds
(
2
*
60
).
toEpochMilli
()
&&
x
.
getIpType
()
==
IpType
.
VENDOR
&&
(
x
.
getStatus
()
==
0
||
x
.
getStatus
()
==
2
))
{
shopDtos
.
add
(
new
ShopDto
());
x
.
setStatus
(
3
);
}
else
{
for
(
Shop
shop
:
shops
)
{
// 1.2 ip资源在未来七天内到期,且 ip 资源的状态不是 3(正在分配)、5(已失效)、6(未分配),则将 ip 资源设置为 2(即将过期)
shopDtos
.
add
(
new
ShopDto
(
shop
));
}
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
)
{
}
ipResourceRepository
.
updateStatus
(
x
.
getId
(),
2
);
if
(
StringUtils
.
isNotBlank
(
x
.
getAddr
()))
{
}
if
(
x
.
getLockTimestamp
()
>=
Instant
.
now
().
minusSeconds
(
120
).
toEpochMilli
()
&&
x
.
getIpType
()
==
IpType
.
VENDOR
&&
(
x
.
getStatus
()
==
0
||
x
.
getStatus
()
==
2
))
{
x
.
setStatus
(
3
);
// 1.3 ip资源在七天前到期,且 ip 资源的状态不是 3(正在分配)、6(未分配),则删除 ip 资源
}
else
if
(
x
.
getValidTime
()
<=
Instant
.
now
().
plusSeconds
(
60
*
60
*
24
*
7
).
toEpochMilli
()
&&
x
.
getValidTime
()
>
Instant
.
now
().
toEpochMilli
())
{
}
else
if
(
x
.
getValidTime
()
<=
Instant
.
now
().
minusSeconds
(
60
*
60
*
24
*
7
).
toEpochMilli
()
&&
x
.
getStatus
()
!=
3
&&
x
.
getStatus
()
!=
6
)
{
if
(
x
.
getStatus
()
!=
5
&&
x
.
getStatus
()
!=
3
&&
x
.
getStatus
()
!=
6
)
{
if
(
x
.
getIpType
()
==
IpType
.
VENDOR
)
{
ipResourceRepository
.
updateStatus
(
x
.
getId
(),
2
);
IpResourceRequestDto
ipResourceRequestDto
=
new
IpResourceRequestDto
();
ipResourceRequestDto
.
setAddr
(
Arrays
.
asList
(
x
.
getAddr
()));
deleteIp
(
username
,
ipResourceRequestDto
);
}
else
{
IpResourceRequestDto
ipResourceRequestDto
=
new
IpResourceRequestDto
();
ipResourceRequestDto
.
setIpId
(
Arrays
.
asList
(
x
.
getId
()));
deleteIp
(
username
,
ipResourceRequestDto
);
}
return
;
// 1.4 ip资源到期,且 ip 资源的状态不是 3(正在分配)、6(未分配),则设置 ip 资源的状态为 1(已过期)
}
else
if
(
x
.
getValidTime
()
<=
Instant
.
now
().
toEpochMilli
()
&&
x
.
getStatus
()
!=
3
&&
x
.
getStatus
()
!=
6
)
{
ipResourceRepository
.
updateStatus
(
x
.
getId
(),
1
);
// 1.5 其他
}
else
{
//
if
((
x
.
getStatus
()
==
0
||
x
.
getStatus
()
==
1
||
x
.
getStatus
()
==
2
)
&&
!
x
.
getVendor
().
equals
(
Vendor
.
local
))
{
ipResourceRepository
.
updateStatus
(
x
.
getId
(),
0
);
}
else
if
(
x
.
getIpType
().
equals
(
IpType
.
LOCAL
)
&&
(
x
.
getStatus
()
==
1
||
x
.
getStatus
()
==
2
)
&&
x
.
getAddr
().
equals
(
"本地Ip未使用"
))
{
ipResourceRepository
.
updateStatus
(
x
.
getId
(),
4
);
}
}
}
}
}
else
if
(
x
.
getValidTime
()
<=
Instant
.
now
().
minusSeconds
(
60
*
60
*
24
*
7
).
toEpochMilli
()
&&
x
.
getStatus
()
!=
3
&&
x
.
getStatus
()
!=
6
)
{
if
(
x
.
getIpType
()
==
IpType
.
VENDOR
)
{
// 2. 如果 ip 资源的 status 为 6(未分配) 或者 ( ip资源为专线 且 purchasedTime(购买IP的时间) 在 14 分钟内)
IpResourceRequestDto
ipResourceRequestDto
=
new
IpResourceRequestDto
();
if
(
x
.
getStatus
()
==
6
||
(
x
.
isSpecialLine
()
&&
x
.
getPurchasedTime
()
>
(
Instant
.
now
().
minusSeconds
(
12
*
60
).
toEpochMilli
())))
{
ipResourceRequestDto
.
setAddr
(
Arrays
.
asList
(
x
.
getAddr
()));
x
.
setStatus
(
3
);
deleteIp
(
username
,
ipResourceRequestDto
);
}
else
{
IpResourceRequestDto
ipResourceRequestDto
=
new
IpResourceRequestDto
();
ipResourceRequestDto
.
setIpId
(
Arrays
.
asList
(
x
.
getId
()));
deleteIp
(
username
,
ipResourceRequestDto
);
}
}
return
;
}
else
if
(
x
.
getValidTime
()
<=
Instant
.
now
().
toEpochMilli
()
&&
x
.
getStatus
()
!=
3
&&
x
.
getStatus
()
!=
6
)
{
// 3. 如果 ip 资源的 status 为 3(正在分配)
ipResourceRepository
.
updateStatus
(
x
.
getId
(),
1
);
if
(
x
.
getStatus
()
==
3
)
{
}
else
{
x
.
setAddr
(
""
);
if
((
x
.
getStatus
()
==
0
||
x
.
getStatus
()
==
1
||
x
.
getStatus
()
==
2
)
&&
!
x
.
getVendor
().
equals
(
Vendor
.
local
))
{
ipResourceRepository
.
updateStatus
(
x
.
getId
(),
0
);
}
else
if
(
x
.
getIpType
().
equals
(
IpType
.
LOCAL
)
&&
(
x
.
getStatus
()
==
1
||
x
.
getStatus
()
==
2
)
&&
x
.
getAddr
().
equals
(
"本地Ip未使用"
))
{
ipResourceRepository
.
updateStatus
(
x
.
getId
(),
4
);
}
}
List
<
ShopDto
>
shopDtos
=
getShopDtos
(
x
);
SpecialLine
specialLine
=
specialLineRepository
.
findAll
().
get
(
0
);
IpResourceDto
ipResourceDto
=
x
.
isSpecialLine
()
?
new
IpResourceDto
(
x
,
shopDtos
,
false
,
specialLine
)
:
new
IpResourceDto
(
x
,
shopDtos
,
false
);
ipResourceDtos
.
add
(
ipResourceDto
);
}
}
}
);
if
(
x
.
getStatus
()
==
6
||
(
x
.
isSpecialLine
()
&&
x
.
getPurchasedTime
()
>
(
Instant
.
now
().
toEpochMilli
()
-
12
*
60
*
1000
)))
x
.
setStatus
(
3
);
if
(
x
.
getStatus
()
==
3
)
{
x
.
setAddr
(
""
);
}
SpecialLine
specialLine
=
specialLineRepository
.
findAll
().
get
(
0
);
if
(
x
.
isSpecialLine
())
ipResourceDtos
.
add
(
new
IpResourceDto
(
x
,
shopDtos
,
false
,
specialLine
));
else
ipResourceDtos
.
add
(
new
IpResourceDto
(
x
,
shopDtos
,
false
));
});
}
}
// 将当前页的数据封装到 Page 中
Page
<
IpResourceDto
>
ipResourceDtoPage
=
new
PageImpl
<>(
ipResourceDtos
,
pageable
,
allIpIds
.
size
());
Page
<
IpResourceDto
>
ipResourceDtoPage
=
new
PageImpl
<>(
ipResourceDtos
,
pageable
,
allIpIds
.
size
());
IpPageResultDto
ipPageResultDto
=
new
IpPageResultDto
();
IpPageResultDto
ipPageResultDto
=
new
IpPageResultDto
();
ipPageResultDto
.
setIpList
(
ipResourceDtoPage
.
getContent
());
ipPageResultDto
.
setIpList
(
ipResourceDtoPage
.
getContent
());
...
@@ -694,8 +659,10 @@ public class IpResourceServiceImpl implements IpResourceService {
...
@@ -694,8 +659,10 @@ public class IpResourceServiceImpl implements IpResourceService {
@Override
@Override
public
IpSummary
getIpSummary
(
String
username
)
{
public
IpSummary
getIpSummary
(
String
username
)
{
Account
account
=
accountRepository
.
findByName
(
username
);
Account
account
=
accountRepository
.
findByName
(
username
);
if
(
account
==
null
)
if
(
account
==
null
)
{
throw
new
ClientRequestException
(
AccountErrorCode
.
NAMENOTEXIST
);
throw
new
ClientRequestException
(
AccountErrorCode
.
NAMENOTEXIST
);
}
IpSummary
ipSummary
=
new
IpSummary
();
IpSummary
ipSummary
=
new
IpSummary
();
List
<
String
>
shopIds
=
userShopRepository
.
findByUsername
(
username
).
stream
().
map
(
x
->
x
.
getShopId
()).
collect
(
Collectors
.
toList
());
List
<
String
>
shopIds
=
userShopRepository
.
findByUsername
(
username
).
stream
().
map
(
x
->
x
.
getShopId
()).
collect
(
Collectors
.
toList
());
List
<
String
>
used
=
ipResourceRepository
.
findShopIdInList
(
shopIds
,
false
).
stream
().
map
(
x
->
x
.
getId
()).
collect
(
Collectors
.
toList
());
List
<
String
>
used
=
ipResourceRepository
.
findShopIdInList
(
shopIds
,
false
).
stream
().
map
(
x
->
x
.
getId
()).
collect
(
Collectors
.
toList
());
...
@@ -736,19 +703,6 @@ public class IpResourceServiceImpl implements IpResourceService {
...
@@ -736,19 +703,6 @@ public class IpResourceServiceImpl implements IpResourceService {
ipResourceRepository
.
save
(
ipResource
);
ipResourceRepository
.
save
(
ipResource
);
}
}
private
void
dealIpResource
(
IpResourceUpdateDto
ipResourceUpdateDto
,
IpResource
ipResource
)
{
if
(
StringUtils
.
isNotBlank
(
ipResourceUpdateDto
.
getAddr
()))
{
ipResource
.
setAddr
(
ipResourceUpdateDto
.
getAddr
());
}
if
(
StringUtils
.
isNotBlank
(
ipResource
.
getRegion
())
&&
region
.
contains
(
ipResource
.
getRegion
()))
{
ipResource
.
setProxyUsername
(
ipResource
.
getAddr
());
ipResource
.
setProxyPassword
(
genRandom
(
3
,
12
));
ipResource
.
setSpecialLine
(
true
);
}
ipResource
.
setStatus
(
ipResourceUpdateDto
.
getStatus
());
}
@Override
@Override
public
boolean
queryIpExist
(
String
username
,
IpResourceUpdateDto
ipResourceUpdateDto
)
{
public
boolean
queryIpExist
(
String
username
,
IpResourceUpdateDto
ipResourceUpdateDto
)
{
Account
account
=
accountRepository
.
findByName
(
username
);
Account
account
=
accountRepository
.
findByName
(
username
);
...
@@ -840,4 +794,107 @@ public class IpResourceServiceImpl implements IpResourceService {
...
@@ -840,4 +794,107 @@ public class IpResourceServiceImpl implements IpResourceService {
ipResourceRepository
.
updateBind
(
ipResource
.
getId
(),
true
);
ipResourceRepository
.
updateBind
(
ipResource
.
getId
(),
true
);
}
}
}
}
private
IpChargeRequestDto
buildIpChargeRequestDto
(
IpResourceRequestDto
request
,
int
chargeType
,
int
payMethod
)
{
IpChargeRequestDto
ipChargeRequestDto
=
new
IpChargeRequestDto
();
ipChargeRequestDto
.
setAmount
(
request
.
getAmount
());
ipChargeRequestDto
.
setChargeType
(
chargeType
);
ipChargeRequestDto
.
setRegion
(
request
.
getRegion
());
ipChargeRequestDto
.
setPeriod
(
request
.
getPeriod
());
ipChargeRequestDto
.
setUnit
(
request
.
getUnit
());
ipChargeRequestDto
.
setPayMethod
(
payMethod
);
return
ipChargeRequestDto
;
}
private
void
dealIpResource
(
IpResourceUpdateDto
ipResourceUpdateDto
,
IpResource
ipResource
)
{
if
(
StringUtils
.
isNotBlank
(
ipResourceUpdateDto
.
getAddr
()))
{
ipResource
.
setAddr
(
ipResourceUpdateDto
.
getAddr
());
}
if
(
StringUtils
.
isNotBlank
(
ipResource
.
getRegion
())
&&
region
.
contains
(
ipResource
.
getRegion
()))
{
ipResource
.
setProxyUsername
(
ipResource
.
getAddr
());
ipResource
.
setProxyPassword
(
genRandom
(
3
,
12
));
ipResource
.
setSpecialLine
(
true
);
}
ipResource
.
setStatus
(
ipResourceUpdateDto
.
getStatus
());
}
private
void
dealIpResourceByGroup
(
List
<
IpResource
>
ipResourceList
,
List
<
IpResource
>
notUsedList
,
Account
account
,
String
username
,
int
groupType
)
{
// 获取当前用户所有的商铺id
List
<
String
>
shopIds
=
userShopRepository
.
findByUsername
(
username
).
stream
().
map
(
UserShop:
:
getShopId
).
collect
(
Collectors
.
toList
());
List
<
String
>
accountNameList
=
new
ArrayList
<>();
accountNameList
.
add
(
account
.
getName
());
boolean
isParent
=
false
;
if
(
account
.
getParent
()
==
null
)
{
isParent
=
true
;
// 获取当前用户的 子账户名
List
<
String
>
children
=
accountRepository
.
findByParent
(
account
.
getName
()).
stream
().
map
(
Account:
:
getName
).
collect
(
Collectors
.
toList
());
accountNameList
.
addAll
(
children
);
}
List
<
IpResource
>
ipResources
=
null
;
List
<
IpResource
>
notUsed
=
null
;
switch
(
groupType
)
{
case
1
:
ipResources
=
ipResourceRepository
.
findShopIdInList
(
shopIds
,
false
);
if
(!
isParent
)
{
notUsed
=
ipResourceRepository
.
findByOwnerAndIsDeletedAndBind
(
username
,
false
,
false
);
}
else
{
notUsed
=
ipResourceRepository
.
findByOwnerInAndIsDeletedAndBind
(
accountNameList
,
false
,
false
);
}
break
;
case
2
:
ipResources
=
ipResourceRepository
.
findShopIdInListAndStatus
(
shopIds
,
false
,
2
);
if
(!
isParent
)
{
notUsed
=
ipResourceRepository
.
findByOwnerAndStatusAndIsDeletedAndBind
(
username
,
2
,
false
,
false
);
}
else
{
notUsed
=
ipResourceRepository
.
findByOwnerInAndStatusAndIsDeletedAndBind
(
accountNameList
,
2
,
false
,
false
);
}
break
;
case
3
:
ipResources
=
ipResourceRepository
.
findShopIdInListAndStatus
(
shopIds
,
false
,
1
);
if
(!
isParent
)
notUsed
=
ipResourceRepository
.
findByOwnerAndStatusAndIsDeletedAndBind
(
username
,
1
,
false
,
false
);
else
notUsed
=
ipResourceRepository
.
findByOwnerInAndStatusAndIsDeletedAndBind
(
accountNameList
,
1
,
false
,
false
);
break
;
case
4
:
if
(!
isParent
)
notUsed
=
ipResourceRepository
.
findByOwnerAndStatusIsNotInAndIsDeletedAndBind
(
username
,
Arrays
.
asList
(
3
,
5
,
6
),
false
,
false
);
else
notUsed
=
ipResourceRepository
.
findByOwnerInAndStatusIsNotInAndIsDeletedAndBind
(
accountNameList
,
Arrays
.
asList
(
3
,
5
,
6
),
false
,
false
);
break
;
case
5
:
// 已分配
ipResources
=
ipResourceRepository
.
findShopIdInList
(
shopIds
,
false
);
if
(!
isParent
)
notUsed
=
ipResourceRepository
.
findByOwnerAndStatusInAndIsDeletedAndBind
(
username
,
Arrays
.
asList
(
0
,
2
,
4
,
8
),
false
,
false
);
else
notUsed
=
ipResourceRepository
.
findByOwnerInAndStatusInAndIsDeletedAndBind
(
accountNameList
,
Arrays
.
asList
(
0
,
2
,
4
,
8
),
false
,
false
);
break
;
}
ipResourceList
.
addAll
(
ipResources
);
notUsedList
.
addAll
(
notUsed
);
}
@NotNull
private
List
<
ShopDto
>
getShopDtos
(
IpResource
x
)
{
List
<
ShopDto
>
shopDtos
=
new
ArrayList
<>();
List
<
Shop
>
shops
=
new
ArrayList
<>();
if
(
x
.
getShopIds
()
!=
null
)
{
shops
=
shopRepository
.
findByShopIdIn
(
x
.
getShopIds
());
}
if
(
shops
.
isEmpty
())
{
shopDtos
.
add
(
new
ShopDto
());
}
else
{
for
(
Shop
shop
:
shops
)
{
shopDtos
.
add
(
new
ShopDto
(
shop
));
}
}
return
shopDtos
;
}
}
}
src/main/java/com/edgec/browserbackend/browser/service/Impl/ShopServiceImpl.java
View file @
d5b01f29
...
@@ -357,54 +357,37 @@ public class ShopServiceImpl implements ShopService {
...
@@ -357,54 +357,37 @@ public class ShopServiceImpl implements ShopService {
throw
new
ClientRequestException
(
AccountErrorCode
.
NOPERMISSION
);
throw
new
ClientRequestException
(
AccountErrorCode
.
NOPERMISSION
);
}
}
List
<
String
>
shopIds
=
new
ArrayList
<>();
// 根据 groupId 与 username 来查询 shopIds
List
<
String
>
allIds
=
null
;
if
(
"-1"
.
equals
(
groupId
))
{
if
(
"-1"
.
equals
(
groupId
))
{
if
(
shopFilterDto
.
getBindIp
()
==
0
)
{
allIds
=
userShopRepository
.
findByUsername
(
username
).
stream
()
// 获取当前用户下所有的商铺id
.
map
(
UserShop:
:
getShopId
).
collect
(
Collectors
.
toList
());
shopIds
=
userShopRepository
.
findByUsername
(
username
).
stream
()
// 如果分组
.
map
(
UserShop:
:
getShopId
).
collect
(
Collectors
.
toList
());
}
else
if
(
shopFilterDto
.
getBindIp
()
==
1
)
{
List
<
String
>
allIds
=
userShopRepository
.
findByUsername
(
username
).
stream
()
.
map
(
UserShop:
:
getShopId
).
collect
(
Collectors
.
toList
());
shopIds
=
ipResourceRepository
.
findShopIdInList
(
allIds
,
false
).
stream
()
.
flatMap
((
x
->
x
.
getShopIds
().
stream
())).
collect
(
Collectors
.
toList
());
}
else
{
List
<
String
>
allIds
=
userShopRepository
.
findByUsername
(
username
).
stream
()
.
map
(
UserShop:
:
getShopId
).
collect
(
Collectors
.
toList
());
for
(
String
id
:
allIds
)
{
IpResource
ipResource
=
ipResourceRepository
.
findFirstByShopIdsIsAndIsDeleted
(
id
,
false
);
if
(
ipResource
==
null
)
{
shopIds
.
add
(
id
);
}
}
}
}
else
{
}
else
{
if
(
shopFilterDto
.
getBindIp
()
==
0
)
{
allIds
=
userShopRepository
.
findByUsernameAndGroupId
(
username
,
groupId
).
stream
()
shopIds
=
userShopRepository
.
findByUsernameAndGroupId
(
username
,
groupId
).
stream
().
.
map
(
UserShop:
:
getShopId
).
collect
(
Collectors
.
toList
());
map
(
UserShop:
:
getShopId
).
collect
(
Collectors
.
toList
());
}
}
else
if
(
shopFilterDto
.
getBindIp
()
==
1
)
{
List
<
String
>
allIds
=
userShopRepository
.
findByUsernameAndGroupId
(
username
,
groupId
).
stream
()
List
<
String
>
shopIds
=
null
;
.
map
(
UserShop:
:
getShopId
).
collect
(
Collectors
.
toList
());
if
(
shopFilterDto
.
getBindIp
()
==
0
)
{
shopIds
=
ipResourceRepository
.
findShopIdInList
(
allIds
,
false
).
stream
()
shopIds
=
allIds
;
.
flatMap
((
x
->
x
.
getShopIds
().
stream
())).
collect
(
Collectors
.
toList
());
}
else
if
(
shopFilterDto
.
getBindIp
()
==
1
)
{
}
else
{
shopIds
=
ipResourceRepository
.
findShopIdInList
(
allIds
,
false
).
stream
()
List
<
String
>
allIds
=
userShopRepository
.
findByUsernameAndGroupId
(
username
,
groupId
).
stream
()
.
flatMap
((
x
->
x
.
getShopIds
().
stream
())).
collect
(
Collectors
.
toList
());
.
map
(
UserShop:
:
getShopId
).
collect
(
Collectors
.
toList
());
}
else
{
for
(
String
id
:
allIds
)
{
for
(
String
id
:
allIds
)
{
IpResource
ipResource
=
ipResourceRepository
.
findFirstByShopIdsIsAndIsDeleted
(
id
,
false
);
IpResource
ipResource
=
ipResourceRepository
.
findFirstByShopIdsIsAndIsDeleted
(
id
,
false
);
if
(
ipResource
==
null
)
{
if
(
ipResource
==
null
)
{
shopIds
.
add
(
id
);
shopIds
.
add
(
id
);
}
}
}
}
}
}
}
if
(
amount
>
100
)
{
amount
=
amount
>
100
?
100
:
amount
;
amount
=
100
;
}
Pageable
pageable
=
PageRequest
.
of
(
pageNum
,
amount
);
Pageable
pageable
=
PageRequest
.
of
(
pageNum
,
amount
);
Page
<
Shop
>
shops
;
Page
<
Shop
>
shops
;
// 根据商铺ids 与 过滤条件 得到商铺
if
(
StringUtils
.
isNotBlank
(
shopFilterDto
.
getIpRegion
()))
{
if
(
StringUtils
.
isNotBlank
(
shopFilterDto
.
getIpRegion
()))
{
List
<
String
>
filter
=
ipResourceRepository
.
findShopIdInListAndRegionLike
(
shopIds
,
false
,
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
());
...
@@ -418,65 +401,62 @@ public class ShopServiceImpl implements ShopService {
...
@@ -418,65 +401,62 @@ public class ShopServiceImpl implements ShopService {
}
}
ShopPageResultDto
<
ShopResultDto
>
shopPageResultDto
=
new
ShopPageResultDto
<>();
ShopPageResultDto
<
ShopResultDto
>
shopPageResultDto
=
new
ShopPageResultDto
<>();
if
(
shops
==
null
||
shops
.
getNumberOfElements
()
<
1
)
{
if
(
shops
!=
null
&&
shops
.
getNumberOfElements
()
>=
1
)
{
return
shopPageResultDto
;
}
else
{
List
<
ShopResultDto
>
shopResultDtos
=
new
ArrayList
<>();
List
<
ShopResultDto
>
shopResultDtos
=
new
ArrayList
<>();
shops
.
getContent
().
stream
().
forEach
(
x
->
{
shops
.
getContent
().
stream
().
forEach
(
IpResource
ipResource
=
ipResourceRepository
.
findFirstByShopIdsIsAndIsDeleted
(
x
.
getShopId
(),
false
);
x
->
{
if
(
ipResource
!=
null
&&
StringUtils
.
isNotBlank
(
ipResource
.
getAddr
()))
{
IpResource
ipResource
=
ipResourceRepository
.
findFirstByShopIdsIsAndIsDeleted
(
x
.
getShopId
(),
false
);
if
(
ipResource
.
getValidTime
()
<=
Instant
.
now
().
plusSeconds
(
60
*
60
*
24
*
7
).
toEpochMilli
()
&&
ipResource
.
getValidTime
()
>
Instant
.
now
().
toEpochMilli
())
{
// 如果 ip资源非空 且 addr 也非空
if
(
ipResource
.
getStatus
()
!=
5
&&
ipResource
.
getStatus
()
!=
3
&&
ipResource
.
getStatus
()
!=
6
)
{
if
(
ipResource
!=
null
&&
StringUtils
.
isNotBlank
(
ipResource
.
getAddr
()))
{
ipResource
.
setStatus
(
2
);
// 1. ip资源在未来七天内到期 且 ip 资源的状态不是 3(正在分配)、5(已失效)、6(未分配),则将 ip 资源设置为 2(即将过期)
ipResourceRepository
.
save
(
ipResource
);
if
(
ipResource
.
getValidTime
()
<=
Instant
.
now
().
plusSeconds
(
60
*
60
*
24
*
7
).
toEpochMilli
()
&&
ipResource
.
getValidTime
()
>
Instant
.
now
().
toEpochMilli
())
{
}
if
(
ipResource
.
getStatus
()
!=
5
&&
ipResource
.
getStatus
()
!=
3
&&
ipResource
.
getStatus
()
!=
6
)
{
}
else
if
(
ipResource
.
getValidTime
()
<=
Instant
.
now
().
minusSeconds
(
60
*
60
*
24
*
7
).
toEpochMilli
()
&&
ipResource
.
getStatus
()
!=
3
&&
ipResource
.
getStatus
()
!=
6
)
{
ipResource
.
setStatus
(
2
);
if
(
ipResource
.
getIpType
()
==
IpType
.
VENDOR
)
{
ipResourceRepository
.
save
(
ipResource
);
IpResourceRequestDto
ipResourceRequestDto1
=
new
IpResourceRequestDto
();
}
ipResourceRequestDto1
.
setAddr
(
Arrays
.
asList
(
ipResource
.
getAddr
()));
try
{
// 2. ip资源在七天前到期,且 ip 资源的状态不是 3(正在分配)、6(未分配),则删除 ip 资源
ipResourceService
.
deleteIp
(
username
,
ipResourceRequestDto1
);
}
else
if
(
ipResource
.
getValidTime
()
<=
Instant
.
now
().
minusSeconds
(
60
*
60
*
24
*
7
).
toEpochMilli
()
&&
ipResource
.
getStatus
()
!=
3
&&
ipResource
.
getStatus
()
!=
6
)
{
}
catch
(
Exception
e
)
{
if
(
ipResource
.
getIpType
()
==
IpType
.
VENDOR
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
IpResourceRequestDto
ipResourceRequestDto1
=
new
IpResourceRequestDto
();
}
ipResourceRequestDto1
.
setAddr
(
Arrays
.
asList
(
ipResource
.
getAddr
()));
}
else
{
try
{
IpResourceRequestDto
ipResourceRequestDto1
=
new
IpResourceRequestDto
();
ipResourceService
.
deleteIp
(
username
,
ipResourceRequestDto1
);
ipResourceRequestDto1
.
setIpId
(
Arrays
.
asList
(
ipResource
.
getId
()));
}
catch
(
Exception
e
)
{
try
{
logger
.
error
(
e
.
getMessage
(),
e
);
ipResourceService
.
deleteIp
(
username
,
ipResourceRequestDto1
);
}
}
catch
(
Exception
e
)
{
}
else
{
logger
.
error
(
e
.
getMessage
(),
e
);
IpResourceRequestDto
ipResourceRequestDto1
=
new
IpResourceRequestDto
();
ipResourceRequestDto1
.
setIpId
(
Arrays
.
asList
(
ipResource
.
getId
()));
try
{
ipResourceService
.
deleteIp
(
username
,
ipResourceRequestDto1
);
}
catch
(
Exception
e
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
}
}
return
;
// 3. ip资源到期,且 ip 资源的状态不是 3(正在分配)、6(未分配),则设置 ip 资源的状态为 1(已过期)
}
else
if
(
ipResource
.
getValidTime
()
<=
Instant
.
now
().
toEpochMilli
()
&&
ipResource
.
getStatus
()
!=
3
&&
ipResource
.
getStatus
()
!=
6
)
{
ipResource
.
setStatus
(
1
);
ipResourceRepository
.
save
(
ipResource
);
// 4. 其他
}
else
{
if
((
ipResource
.
getStatus
()
==
0
||
ipResource
.
getStatus
()
==
1
||
ipResource
.
getStatus
()
==
2
)
&&
ipResource
.
getVendor
()
!=
Vendor
.
local
)
{
ipResource
.
setStatus
(
0
);
}
else
if
(
ipResource
.
getIpType
().
equals
(
IpType
.
LOCAL
)
&&
(
ipResource
.
getStatus
()
==
1
||
ipResource
.
getStatus
()
==
2
)
&&
ipResource
.
getAddr
().
equals
(
"本地Ip未使用"
))
{
ipResource
.
setStatus
(
4
);
}
ipResourceRepository
.
save
(
ipResource
);
}
}
}
}
return
;
}
else
if
(
ipResource
.
getValidTime
()
<=
Instant
.
now
().
toEpochMilli
()
&&
ipResource
.
getStatus
()
!=
3
&&
ipResource
.
getStatus
()
!=
6
)
{
ipResource
.
setStatus
(
1
);
ipResourceRepository
.
save
(
ipResource
);
}
else
{
if
((
ipResource
.
getStatus
()
==
0
||
ipResource
.
getStatus
()
==
1
||
ipResource
.
getStatus
()
==
2
)
&&
ipResource
.
getVendor
()
!=
Vendor
.
local
)
{
ipResource
.
setStatus
(
0
);
ipResourceRepository
.
save
(
ipResource
);
}
else
if
(
ipResource
.
getIpType
().
equals
(
IpType
.
LOCAL
)
&&
(
ipResource
.
getStatus
()
==
1
||
ipResource
.
getStatus
()
==
2
)
&&
ipResource
.
getAddr
().
equals
(
"本地Ip未使用"
))
{
ipResource
.
setStatus
(
4
);
ipResourceRepository
.
save
(
ipResource
);
}
}
}
if
(
ipResource
==
null
)
{
ipResource
=
new
IpResource
();
}
String
group1
=
userShopRepository
.
findByUsernameAndShopId
(
username
,
x
.
getShopId
()).
getGroupId
();
ShopResultDto
shopResultDto
=
getShopResultDto
(
username
,
x
,
ipResource
);
ShopResultDto
shopResultDto
=
null
;
if
(
ipResource
.
isSpecialLine
())
{
SpecialLine
specialLine
=
specialLineRepository
.
findAll
().
get
(
0
);
shopResultDto
=
ShopResultDto
.
of
(
x
,
group1
,
new
IpResourceDto
(
ipResource
,
null
,
false
,
specialLine
));
}
else
{
shopResultDto
=
ShopResultDto
.
of
(
x
,
group1
,
new
IpResourceDto
(
ipResource
,
null
,
false
));
}
shopResultDtos
.
add
(
shopResultDto
);
shopResultDtos
.
add
(
shopResultDto
);
});
}
);
Page
<
ShopResultDto
>
shopDtoPage
=
new
PageImpl
<>(
shopResultDtos
,
pageable
,
shopIds
.
size
());
Page
<
ShopResultDto
>
shopDtoPage
=
new
PageImpl
<>(
shopResultDtos
,
pageable
,
shopIds
.
size
());
shopPageResultDto
.
setShopList
(
shopDtoPage
.
getContent
());
shopPageResultDto
.
setShopList
(
shopDtoPage
.
getContent
());
...
@@ -485,8 +465,24 @@ public class ShopServiceImpl implements ShopService {
...
@@ -485,8 +465,24 @@ public class ShopServiceImpl implements ShopService {
pageInfo
.
setTotalPages
(
shopDtoPage
.
getTotalPages
());
pageInfo
.
setTotalPages
(
shopDtoPage
.
getTotalPages
());
pageInfo
.
setTotalItems
(
shopIds
.
size
());
pageInfo
.
setTotalItems
(
shopIds
.
size
());
shopPageResultDto
.
setShopPage
(
pageInfo
);
shopPageResultDto
.
setShopPage
(
pageInfo
);
return
shopPageResultDto
;
}
}
return
shopPageResultDto
;
}
private
ShopResultDto
getShopResultDto
(
String
username
,
Shop
x
,
IpResource
ipResource
)
{
if
(
ipResource
==
null
)
{
ipResource
=
new
IpResource
();
}
String
group1
=
userShopRepository
.
findByUsernameAndShopId
(
username
,
x
.
getShopId
()).
getGroupId
();
ShopResultDto
shopResultDto
=
null
;
if
(
ipResource
.
isSpecialLine
())
{
SpecialLine
specialLine
=
specialLineRepository
.
findAll
().
get
(
0
);
shopResultDto
=
ShopResultDto
.
of
(
x
,
group1
,
new
IpResourceDto
(
ipResource
,
null
,
false
,
specialLine
));
}
else
{
shopResultDto
=
ShopResultDto
.
of
(
x
,
group1
,
new
IpResourceDto
(
ipResource
,
null
,
false
));
}
return
shopResultDto
;
}
}
@Override
@Override
...
...
src/main/java/com/edgec/browserbackend/browser/task/BrowserTask.java
View file @
d5b01f29
...
@@ -110,79 +110,84 @@ public class BrowserTask {
...
@@ -110,79 +110,84 @@ public class BrowserTask {
List
<
CompletableFuture
>
futureList
=
new
ArrayList
<>();
List
<
CompletableFuture
>
futureList
=
new
ArrayList
<>();
for
(
IpResource
ipResource
:
ipResources
)
{
for
(
IpResource
ipResource
:
ipResources
)
{
long
start
=
System
.
currentTimeMillis
();
long
start
=
System
.
currentTimeMillis
();
CompletableFuture
future
=
CompletableFuture
.
runAsync
(()
->
{
if
(
ipResourceRepository
.
lockTask
(
ipResource
))
{
CompletableFuture
future
=
CompletableFuture
.
runAsync
(
try
{
()
->
{
boolean
result
=
false
;
if
(
ipResourceRepository
.
lockTask
(
ipResource
))
{
Map
<
String
,
String
>
header
=
buildPostHeader
();
try
{
HashMap
<
String
,
Object
>
map
=
new
HashMap
<>();
boolean
result
=
false
;
map
.
put
(
"name"
,
ipResource
.
getUsername
());
Map
<
String
,
String
>
header
=
buildPostHeader
();
map
.
put
(
"region"
,
ipResource
.
getRegion
());
HashMap
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"period"
,
String
.
valueOf
(
ipResource
.
getPeriod
()));
map
.
put
(
"name"
,
ipResource
.
getUsername
());
map
.
put
(
"provider"
,
ipResource
.
getVendor
());
map
.
put
(
"region"
,
ipResource
.
getRegion
());
map
.
put
(
"unit"
,
ipResource
.
getUnit
());
map
.
put
(
"period"
,
String
.
valueOf
(
ipResource
.
getPeriod
()));
map
.
put
(
"amount"
,
1
);
map
.
put
(
"provider"
,
ipResource
.
getVendor
());
map
.
put
(
"loginPassword"
,
ipResource
.
getPassword
());
map
.
put
(
"unit"
,
ipResource
.
getUnit
());
map
.
put
(
"startscript"
,
""
);
map
.
put
(
"amount"
,
1
);
map
.
put
(
"ipkeptperiod"
,
7
);
map
.
put
(
"loginPassword"
,
ipResource
.
getPassword
());
map
.
put
(
"persistSystemDiskOnTermination"
,
false
);
map
.
put
(
"startscript"
,
""
);
map
.
put
(
"ipkeptperiod"
,
7
);
map
.
put
(
"persistSystemDiskOnTermination"
,
false
);
// HttpEntity<Map<String, Object>> httpEntity = new HttpEntity<>(map, header);
// HttpEntity<Map<String, Object>> httpEntity = new HttpEntity<>(map, header);
IpBuyResultDto
ipBuyResultDto
=
null
;
IpBuyResultDto
ipBuyResultDto
=
null
;
try
{
try
{
String
requestResult
=
HttpClientutils
.
doPost
(
URL
+
"/intelligroup/ipresources?accountId=browser"
,
header
,
JSONObject
.
toJSONString
(
map
));
String
requestResult
=
HttpClientutils
.
doPost
(
URL
+
"/intelligroup/ipresources?accountId=browser"
,
header
,
JSONObject
.
toJSONString
(
map
));
ipBuyResultDto
=
JSONObject
.
parseObject
(
requestResult
,
IpBuyResultDto
.
class
);
ipBuyResultDto
=
JSONObject
.
parseObject
(
requestResult
,
IpBuyResultDto
.
class
);
if
(
StringUtils
.
isNotBlank
(
ipBuyResultDto
.
getErrorCode
()))
{
if
(
StringUtils
.
isNotBlank
(
ipBuyResultDto
.
getErrorCode
()))
{
log
.
error
(
"fail to buy ip"
);
log
.
error
(
"fail to buy ip"
);
log
.
error
(
ipBuyResultDto
.
getErrorCode
());
log
.
error
(
ipBuyResultDto
.
getErrorCode
());
}
if
(
ipBuyResultDto
!=
null
&&
ipBuyResultDto
.
getIplist
()
!=
null
&&
ipBuyResultDto
.
getIplist
().
size
()
>=
1
)
{
AtomicInteger
index
=
new
AtomicInteger
();
ipBuyResultDto
.
getIplist
().
forEach
(
x
->
{
if
(
ipResource
!=
null
)
{
ipResource
.
setAddr
(
x
.
getIp
());
ipResource
.
setStatus
(
3
);
ipResource
.
setValidTime
(
Instant
.
parse
(
x
.
getValidTill
()).
toEpochMilli
());
if
(
StringUtils
.
isNotBlank
(
ipResource
.
getRegion
())
&&
region
.
contains
(
ipResource
.
getRegion
()))
{
ipResource
.
setProxyUsername
(
ipResource
.
getAddr
());
ipResource
.
setProxyPassword
(
genRandom
(
3
,
12
));
ipResource
.
setSpecialLine
(
true
);
}
ipResourceRepository
.
save
(
ipResource
);
}
else
{
log
.
error
(
"no ipResource"
);
}
}
index
.
getAndIncrement
();
if
(
ipBuyResultDto
!=
null
&&
ipBuyResultDto
.
getIplist
()
!=
null
&&
ipBuyResultDto
.
getIplist
().
size
()
>=
1
)
{
});
AtomicInteger
index
=
new
AtomicInteger
();
result
=
true
;
ipBuyResultDto
.
getIplist
().
forEach
(
x
->
{
}
if
(
ipResource
!=
null
)
{
}
catch
(
Exception
e
)
{
ipResource
.
setAddr
(
x
.
getIp
());
log
.
error
(
e
.
getMessage
());
ipResource
.
setStatus
(
3
);
result
=
false
;
ipResource
.
setValidTime
(
Instant
.
parse
(
x
.
getValidTill
()).
toEpochMilli
());
}
if
(
StringUtils
.
isNotBlank
(
ipResource
.
getRegion
())
&&
region
.
contains
(
ipResource
.
getRegion
()))
{
if
(
result
==
false
&&
(
ipResource
.
getPurchasedTime
()
<
Instant
.
now
().
minusSeconds
(
7200
).
toEpochMilli
()))
{
ipResource
.
setProxyUsername
(
ipResource
.
getAddr
());
IpChargeRequestDto
ipChargeRequestDto
=
buildIpChargeRequestDto
(
ipResource
,
3
,
0
);
ipResource
.
setProxyPassword
(
genRandom
(
3
,
12
));
accountService
.
chargeByMoney
(
ipResource
.
getUsername
(),
-
ipResource
.
getPrice
(),
ipChargeRequestDto
);
ipResource
.
setSpecialLine
(
true
);
if
(
ipResource
.
getShopIds
()
!=
null
&&
ipResource
.
getShopIds
().
size
()
>
0
)
{
}
ShopRequestDto
shopRequestDto
=
new
ShopRequestDto
();
ipResourceRepository
.
save
(
ipResource
);
shopRequestDto
.
setIpId
(
ipResource
.
getId
());
}
else
{
shopRequestDto
.
setShopIds
(
ipResource
.
getShopIds
());
log
.
error
(
"no ipResource"
);
ipAndShopService
.
unBindShops
(
ipResource
.
getUsername
(),
shopRequestDto
);
}
index
.
getAndIncrement
();
});
result
=
true
;
}
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
());
result
=
false
;
}
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
.
getShopIds
()
!=
null
&&
ipResource
.
getShopIds
().
size
()
>
0
)
{
ShopRequestDto
shopRequestDto
=
new
ShopRequestDto
();
shopRequestDto
.
setIpId
(
ipResource
.
getId
());
shopRequestDto
.
setShopIds
(
ipResource
.
getShopIds
());
ipAndShopService
.
unBindShops
(
ipResource
.
getUsername
(),
shopRequestDto
);
}
ipResourceRepository
.
deleteById
(
ipResource
.
getId
());
}
}
finally
{
long
end
=
System
.
currentTimeMillis
();
log
.
debug
(
"buyIpTask {} execution time is: "
+
(
end
-
start
)
/
1000
+
"s"
,
ipResource
.
getId
());
try
{
ipResourceRepository
.
unLockTask
(
ipResource
.
getId
());
}
catch
(
Throwable
th
)
{
log
.
error
(
"unlock failed"
,
th
);
//try again
ipResourceRepository
.
unLockTask
(
ipResource
.
getId
());
}
}
}
ipResourceRepository
.
deleteById
(
ipResource
.
getId
());
}
}
}
finally
{
},
long
end
=
System
.
currentTimeMillis
();
ThreadPoolUtils
.
buyIpTasksPool
log
.
debug
(
"buyIpTask {} execution time is: "
+
(
end
-
start
)
/
1000
+
"s"
,
ipResource
.
getId
());
);
try
{
ipResourceRepository
.
unLockTask
(
ipResource
.
getId
());
}
catch
(
Throwable
th
)
{
log
.
error
(
"unlock failed"
,
th
);
//try again
ipResourceRepository
.
unLockTask
(
ipResource
.
getId
());
}
}
}
},
ThreadPoolUtils
.
buyIpTasksPool
);
futureList
.
add
(
future
);
futureList
.
add
(
future
);
}
}
CompletableFuture
.
allOf
(
futureList
.
toArray
(
new
CompletableFuture
[
0
])).
join
();
CompletableFuture
.
allOf
(
futureList
.
toArray
(
new
CompletableFuture
[
0
])).
join
();
...
@@ -195,38 +200,41 @@ public class BrowserTask {
...
@@ -195,38 +200,41 @@ public class BrowserTask {
List
<
IpResource
>
ipResources
=
ipResourceRepository
.
sampleTasks
(
3
,
time
);
List
<
IpResource
>
ipResources
=
ipResourceRepository
.
sampleTasks
(
3
,
time
);
for
(
IpResource
ipResource
:
ipResources
)
{
for
(
IpResource
ipResource
:
ipResources
)
{
long
start
=
System
.
currentTimeMillis
();
long
start
=
System
.
currentTimeMillis
();
CompletableFuture
.
runAsync
(()
->
{
CompletableFuture
.
runAsync
(
if
(
ipResourceRepository
.
lockTask
(
ipResource
))
{
()
->
{
try
{
if
(
ipResourceRepository
.
lockTask
(
ipResource
))
{
log
.
error
(
"test"
);
try
{
String
url
=
URL
+
"/ecc/ipinfo?accountId=browser&ip="
+
ipResource
.
getAddr
();
log
.
error
(
"test"
);
Map
<
String
,
String
>
header
=
buildGetHeader
();
String
url
=
URL
+
"/ecc/ipinfo?accountId=browser&ip="
+
ipResource
.
getAddr
();
String
rs
=
HttpClientutils
.
doGet
(
url
,
header
);
Map
<
String
,
String
>
header
=
buildGetHeader
();
IpInfoResultDto
ipInfoResultDto
=
JSONObject
.
parseObject
(
rs
,
IpInfoResultDto
.
class
);
String
rs
=
HttpClientutils
.
doGet
(
url
,
header
);
if
(
ipInfoResultDto
!=
null
&&
StringUtils
.
isBlank
(
ipInfoResultDto
.
getErrorCode
()))
{
IpInfoResultDto
ipInfoResultDto
=
JSONObject
.
parseObject
(
rs
,
IpInfoResultDto
.
class
);
log
.
error
(
ipInfoResultDto
.
getErrorCode
());
if
(
ipInfoResultDto
!=
null
&&
StringUtils
.
isBlank
(
ipInfoResultDto
.
getErrorCode
()))
{
log
.
error
(
ipInfoResultDto
.
getStatus
());
log
.
error
(
ipInfoResultDto
.
getErrorCode
());
log
.
error
(
ipInfoResultDto
.
getEipIPAddr
());
log
.
error
(
ipInfoResultDto
.
getStatus
());
if
(
StringUtils
.
isNotEmpty
(
ipInfoResultDto
.
getStatus
()))
{
log
.
error
(
ipInfoResultDto
.
getEipIPAddr
());
ipResourceRepository
.
updateStatus
(
ipResource
.
getId
(),
0
);
if
(
StringUtils
.
isNotEmpty
(
ipInfoResultDto
.
getStatus
()))
{
ipResourceRepository
.
updateStatus
(
ipResource
.
getId
(),
0
);
}
}
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
NotifyUtils
.
sendMessage
(
"浏览器后端 queryIpTasks() 又炸了,赶紧看啊"
,
e
,
NotifyUtils
.
MsgType
.
WEBHOOK
);
}
finally
{
long
end
=
System
.
currentTimeMillis
();
log
.
debug
(
"queryIpTask {} execution time is: "
+
(
end
-
start
)
/
1000
+
"s"
,
ipResource
.
getId
());
try
{
ipResourceRepository
.
unLockTask
(
ipResource
.
getId
());
}
catch
(
Throwable
th
)
{
log
.
error
(
"unlock failed"
,
th
);
//try again
ipResourceRepository
.
unLockTask
(
ipResource
.
getId
());
}
}
}
}
}
}
catch
(
Exception
e
)
{
},
log
.
error
(
e
.
getMessage
(),
e
);
ThreadPoolUtils
.
queryIpTasksPool
NotifyUtils
.
sendMessage
(
"浏览器后端 queryIpTasks() 又炸了,赶紧看啊"
,
e
,
NotifyUtils
.
MsgType
.
WEBHOOK
);
);
}
finally
{
long
end
=
System
.
currentTimeMillis
();
log
.
debug
(
"queryIpTask {} execution time is: "
+
(
end
-
start
)
/
1000
+
"s"
,
ipResource
.
getId
());
try
{
ipResourceRepository
.
unLockTask
(
ipResource
.
getId
());
}
catch
(
Throwable
th
)
{
log
.
error
(
"unlock failed"
,
th
);
//try again
ipResourceRepository
.
unLockTask
(
ipResource
.
getId
());
}
}
}
},
ThreadPoolUtils
.
queryIpTasksPool
);
}
}
}
}
...
@@ -310,16 +318,18 @@ public class BrowserTask {
...
@@ -310,16 +318,18 @@ public class BrowserTask {
public
void
countIp
()
{
public
void
countIp
()
{
List
<
Account
>
accounts
=
accountRepository
.
findAll
();
List
<
Account
>
accounts
=
accountRepository
.
findAll
();
try
{
try
{
accounts
.
forEach
(
x
->
{
accounts
.
forEach
(
IpCountRecord
ipCountRecord
=
new
IpCountRecord
();
x
->
{
ipCountRecord
.
setUsername
(
x
.
getName
());
IpCountRecord
ipCountRecord
=
new
IpCountRecord
();
ipCountRecord
.
setTimestamp
(
Instant
.
now
().
toEpochMilli
());
ipCountRecord
.
setUsername
(
x
.
getName
());
long
ipcount_using
=
ipResourceRepository
.
countAllByOwnerAndIsDeletedAndValidTimeGreaterThan
(
x
.
getName
(),
false
,
Instant
.
now
().
toEpochMilli
());
ipCountRecord
.
setTimestamp
(
Instant
.
now
().
toEpochMilli
());
long
ipcount_all
=
ipResourceRepository
.
countAllByOwner
(
x
.
getName
());
long
ipcount_using
=
ipResourceRepository
.
countAllByOwnerAndIsDeletedAndValidTimeGreaterThan
(
x
.
getName
(),
false
,
Instant
.
now
().
toEpochMilli
());
ipCountRecord
.
setIp_all
(
ipcount_all
);
long
ipcount_all
=
ipResourceRepository
.
countAllByOwner
(
x
.
getName
());
ipCountRecord
.
setIp_using
(
ipcount_using
);
ipCountRecord
.
setIp_all
(
ipcount_all
);
ipCountRecordRepository
.
save
(
ipCountRecord
);
ipCountRecord
.
setIp_using
(
ipcount_using
);
});
ipCountRecordRepository
.
save
(
ipCountRecord
);
}
);
IpCountRecord
ipCountRecord
=
new
IpCountRecord
();
IpCountRecord
ipCountRecord
=
new
IpCountRecord
();
ipCountRecord
.
setUsername
(
"all"
);
ipCountRecord
.
setUsername
(
"all"
);
ipCountRecord
.
setTimestamp
(
Instant
.
now
().
toEpochMilli
());
ipCountRecord
.
setTimestamp
(
Instant
.
now
().
toEpochMilli
());
...
@@ -369,20 +379,5 @@ public class BrowserTask {
...
@@ -369,20 +379,5 @@ public class BrowserTask {
ResponseBody
responseBody
=
response
.
body
();
ResponseBody
responseBody
=
response
.
body
();
return
responseBody
.
string
();
return
responseBody
.
string
();
}
}
}
}
public
static
void
main
(
String
[]
args
)
throws
IOException
{
List
<
QueryIpUrlList
>
queryIpUrlLists
=
new
ArrayList
<>();
queryIpUrlLists
.
add
(
new
QueryIpUrlList
(
"1"
,
"baidu"
));
queryIpUrlLists
.
add
(
new
QueryIpUrlList
(
"2"
,
"google"
));
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
System
.
out
.
println
(
getNextUrl
(
queryIpUrlLists
,
i
).
getUrl
());
}
}
}
}
src/main/java/com/edgec/browserbackend/browser/task/PaymentTask.java
View file @
d5b01f29
...
@@ -29,7 +29,7 @@ public class PaymentTask {
...
@@ -29,7 +29,7 @@ public class PaymentTask {
@Scheduled
(
fixedDelay
=
60000
)
@Scheduled
(
fixedDelay
=
60000
)
public
void
checkPayments
()
{
public
void
checkPayments
()
{
long
now
=
new
Date
().
getTime
();
long
now
=
System
.
currentTimeMillis
();
Date
date_5min
=
new
Date
(
now
-
5
*
60
*
1000
);
Date
date_5min
=
new
Date
(
now
-
5
*
60
*
1000
);
Date
date_10min
=
new
Date
(
now
-
10
*
60
*
1000
);
Date
date_10min
=
new
Date
(
now
-
10
*
60
*
1000
);
List
<
UserPayment
>
unfinishedPayments
=
userPaymentRepository
.
findAllByPaymentDateBetweenAndSucceed
(
List
<
UserPayment
>
unfinishedPayments
=
userPaymentRepository
.
findAllByPaymentDateBetweenAndSucceed
(
...
...
src/main/java/com/edgec/browserbackend/common/commons/kafka/KafkaUtils.java
View file @
d5b01f29
package
com
.
edgec
.
browserbackend
.
common
.
commons
.
kafka
;
package
com
.
edgec
.
browserbackend
.
common
.
commons
.
kafka
;
@Deprecated
public
final
class
KafkaUtils
{
public
final
class
KafkaUtils
{
public
static
final
String
TOPIC_NAME_C3_MINIONS
=
"tp.minions.c3"
;
public
static
final
String
TOPIC_NAME_C3_MINIONS
=
"tp.minions.c3"
;
public
static
final
String
CONSUMER_GROUP_C3_MINIONS
=
"cg.minions.c3"
;
public
static
final
String
CONSUMER_GROUP_C3_MINIONS
=
"cg.minions.c3"
;
public
static
final
TopicDef
TOPIC_C3_MINIONS
=
new
TopicDef
(
TOPIC_NAME_C3_MINIONS
,
12
,
2
);
public
static
final
TopicDef
TOPIC_C3_MINIONS
=
new
TopicDef
(
TOPIC_NAME_C3_MINIONS
,
12
,
2
);
public
static
class
TopicDef
{
public
static
class
TopicDef
{
...
...
src/main/java/com/edgec/browserbackend/common/commons/utils/CommonStringUtils.java
View file @
d5b01f29
package
com
.
edgec
.
browserbackend
.
common
.
commons
.
utils
;
package
com
.
edgec
.
browserbackend
.
common
.
commons
.
utils
;
@Deprecated
public
class
CommonStringUtils
{
public
class
CommonStringUtils
{
public
static
int
getLongestCommonSubstring
(
String
a
,
String
b
)
{
public
static
int
getLongestCommonSubstring
(
String
a
,
String
b
)
{
...
@@ -10,16 +11,16 @@ public class CommonStringUtils {
...
@@ -10,16 +11,16 @@ public class CommonStringUtils {
int
[][]
dp
=
new
int
[
m
][
n
];
int
[][]
dp
=
new
int
[
m
][
n
];
for
(
int
i
=
0
;
i
<
m
;
i
++)
{
for
(
int
i
=
0
;
i
<
m
;
i
++)
{
for
(
int
j
=
0
;
j
<
n
;
j
++)
{
for
(
int
j
=
0
;
j
<
n
;
j
++)
{
if
(
a
.
charAt
(
i
)
==
b
.
charAt
(
j
))
{
if
(
a
.
charAt
(
i
)
==
b
.
charAt
(
j
))
{
if
(
i
==
0
||
j
==
0
)
{
if
(
i
==
0
||
j
==
0
)
{
dp
[
i
][
j
]
=
1
;
dp
[
i
][
j
]
=
1
;
}
else
{
}
else
{
dp
[
i
][
j
]
=
dp
[
i
-
1
][
j
-
1
]+
1
;
dp
[
i
][
j
]
=
dp
[
i
-
1
][
j
-
1
]
+
1
;
}
}
if
(
max
<
dp
[
i
][
j
])
if
(
max
<
dp
[
i
][
j
])
max
=
dp
[
i
][
j
];
max
=
dp
[
i
][
j
];
}
}
...
...
src/main/java/com/edgec/browserbackend/common/commons/utils/Pair.java
View file @
d5b01f29
package
com
.
edgec
.
browserbackend
.
common
.
commons
.
utils
;
package
com
.
edgec
.
browserbackend
.
common
.
commons
.
utils
;
@Deprecated
public
final
class
Pair
<
S
,
T
>
{
public
final
class
Pair
<
S
,
T
>
{
private
S
first
;
private
S
first
;
...
...
src/main/java/com/edgec/browserbackend/common/commons/utils/PriorityThreadPoolExecutor.java
View file @
d5b01f29
...
@@ -3,6 +3,7 @@ package com.edgec.browserbackend.common.commons.utils;
...
@@ -3,6 +3,7 @@ package com.edgec.browserbackend.common.commons.utils;
import
java.util.Comparator
;
import
java.util.Comparator
;
import
java.util.concurrent.*
;
import
java.util.concurrent.*
;
@Deprecated
public
class
PriorityThreadPoolExecutor
extends
ThreadPoolExecutor
{
public
class
PriorityThreadPoolExecutor
extends
ThreadPoolExecutor
{
private
Comparator
comparator
;
private
Comparator
comparator
;
...
...
src/main/java/com/edgec/browserbackend/common/commons/utils/RemoteShellExecutor.java
View file @
d5b01f29
...
@@ -9,16 +9,23 @@ import java.io.*;
...
@@ -9,16 +9,23 @@ import java.io.*;
import
java.nio.charset.Charset
;
import
java.nio.charset.Charset
;
import
java.nio.charset.StandardCharsets
;
import
java.nio.charset.StandardCharsets
;
@Deprecated
public
class
RemoteShellExecutor
{
public
class
RemoteShellExecutor
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
RemoteShellExecutor
.
class
);
private
Logger
logger
=
LoggerFactory
.
getLogger
(
RemoteShellExecutor
.
class
);
private
Connection
conn
;
private
Connection
conn
;
/** 远程机器IP */
/**
* 远程机器IP
*/
private
String
ip
;
private
String
ip
;
/** 用户名 */
/**
* 用户名
*/
private
String
osUsername
;
private
String
osUsername
;
/** 密码 */
/**
* 密码
*/
private
String
password
;
private
String
password
;
private
String
charset
=
Charset
.
defaultCharset
().
toString
();
private
String
charset
=
Charset
.
defaultCharset
().
toString
();
...
@@ -33,6 +40,7 @@ public class RemoteShellExecutor {
...
@@ -33,6 +40,7 @@ public class RemoteShellExecutor {
/**
/**
* 登录
* 登录
*
* @return
* @return
* @throws IOException
* @throws IOException
*/
*/
...
@@ -182,18 +190,16 @@ public class RemoteShellExecutor {
...
@@ -182,18 +190,16 @@ public class RemoteShellExecutor {
// 6. 关闭输入流
// 6. 关闭输入流
out
.
close
();
out
.
close
();
// 7. 等待,除非1.连接关闭;2.输出数据传送完毕;3.进程状态为退出;4.超时
// 7. 等待,除非1.连接关闭;2.输出数据传送完毕;3.进程状态为退出;4.超时
session
.
waitForCondition
(
ChannelCondition
.
CLOSED
|
ChannelCondition
.
EOF
|
ChannelCondition
.
EXIT_STATUS
,
30000
);
session
.
waitForCondition
(
ChannelCondition
.
CLOSED
|
ChannelCondition
.
EOF
|
ChannelCondition
.
EXIT_STATUS
,
30000
);
logger
.
error
(
"Here is the output from stdout:"
);
logger
.
error
(
"Here is the output from stdout:"
);
while
(
true
)
while
(
true
)
{
{
String
line
=
stdoutReader
.
readLine
();
String
line
=
stdoutReader
.
readLine
();
if
(
line
==
null
)
if
(
line
==
null
)
break
;
break
;
System
.
out
.
println
(
line
);
System
.
out
.
println
(
line
);
}
}
logger
.
error
(
"Here is the output from stderr:"
);
logger
.
error
(
"Here is the output from stderr:"
);
while
(
true
)
while
(
true
)
{
{
String
line
=
stderrReader
.
readLine
();
String
line
=
stderrReader
.
readLine
();
if
(
line
==
null
)
if
(
line
==
null
)
break
;
break
;
...
@@ -253,18 +259,16 @@ public class RemoteShellExecutor {
...
@@ -253,18 +259,16 @@ public class RemoteShellExecutor {
scpOutputStream
.
flush
();
scpOutputStream
.
flush
();
scpOutputStream
.
close
();
scpOutputStream
.
close
();
session
.
waitForCondition
(
ChannelCondition
.
CLOSED
|
ChannelCondition
.
EOF
|
ChannelCondition
.
EXIT_STATUS
,
30000
);
session
.
waitForCondition
(
ChannelCondition
.
CLOSED
|
ChannelCondition
.
EOF
|
ChannelCondition
.
EXIT_STATUS
,
30000
);
logger
.
error
(
"Here is the output from stdout:"
);
logger
.
error
(
"Here is the output from stdout:"
);
while
(
true
)
while
(
true
)
{
{
String
line
=
stdoutReader
.
readLine
();
String
line
=
stdoutReader
.
readLine
();
if
(
line
==
null
)
if
(
line
==
null
)
break
;
break
;
System
.
out
.
println
(
line
);
System
.
out
.
println
(
line
);
}
}
logger
.
error
(
"Here is the output from stderr:"
);
logger
.
error
(
"Here is the output from stderr:"
);
while
(
true
)
while
(
true
)
{
{
String
line
=
stderrReader
.
readLine
();
String
line
=
stderrReader
.
readLine
();
if
(
line
==
null
)
if
(
line
==
null
)
break
;
break
;
...
@@ -278,7 +282,7 @@ public class RemoteShellExecutor {
...
@@ -278,7 +282,7 @@ public class RemoteShellExecutor {
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
logger
.
error
(
e
.
getMessage
());
logger
.
error
(
e
.
getMessage
());
throw
new
Exception
(
"登录远程机器失败"
+
ip
);
throw
new
Exception
(
"登录远程机器失败"
+
ip
);
}
finally
{
}
finally
{
if
(
conn
!=
null
)
{
if
(
conn
!=
null
)
{
conn
.
close
();
conn
.
close
();
}
}
...
...
src/main/java/com/edgec/browserbackend/common/commons/utils/TimestampUtils.java
View file @
d5b01f29
...
@@ -10,6 +10,7 @@ import java.time.ZonedDateTime;
...
@@ -10,6 +10,7 @@ import java.time.ZonedDateTime;
import
java.time.temporal.ChronoUnit
;
import
java.time.temporal.ChronoUnit
;
import
java.util.Iterator
;
import
java.util.Iterator
;
@Deprecated
public
class
TimestampUtils
{
public
class
TimestampUtils
{
...
...
src/main/java/com/edgec/browserbackend/common/commons/utils/UUIDGenerator.java
View file @
d5b01f29
...
@@ -2,6 +2,7 @@ package com.edgec.browserbackend.common.commons.utils;
...
@@ -2,6 +2,7 @@ package com.edgec.browserbackend.common.commons.utils;
import
java.util.UUID
;
import
java.util.UUID
;
@Deprecated
public
class
UUIDGenerator
{
public
class
UUIDGenerator
{
public
static
String
gen
(
Boolean
withoutDashes
)
{
public
static
String
gen
(
Boolean
withoutDashes
)
{
return
withoutDashes
?
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
)
return
withoutDashes
?
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
)
...
...
src/main/java/com/edgec/browserbackend/common/constant/InstanceStatus.java
View file @
d5b01f29
package
com
.
edgec
.
browserbackend
.
common
.
constant
;
package
com
.
edgec
.
browserbackend
.
common
.
constant
;
@Deprecated
public
interface
InstanceStatus
{
public
interface
InstanceStatus
{
String
STOPPING
=
"Stopping"
;
String
STOPPING
=
"Stopping"
;
...
...
src/main/java/com/edgec/browserbackend/common/constant/SpecialUsers.java
View file @
d5b01f29
...
@@ -5,51 +5,31 @@ import java.lang.reflect.Modifier;
...
@@ -5,51 +5,31 @@ import java.lang.reflect.Modifier;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
java.util.Set
;
import
java.util.Set
;
@Deprecated
public
class
SpecialUsers
{
public
class
SpecialUsers
{
public
static
final
Set
<
String
>
CLOUDAM_USERS
=
new
HashSet
<>();
public
static
final
Set
<
String
>
CLOUDAM_USERS
=
new
HashSet
<>();
public
static
final
String
VPS_CLOUD_ACCOUNT_NAME
=
"vpsclient"
;
public
static
final
String
VPS_CLOUD_ACCOUNT_NAME
=
"vpsclient"
;
public
static
final
String
CVM_CLOUD_ACCOUNT_NAME
=
"cvmclient"
;
public
static
final
String
CVM_CLOUD_ACCOUNT_NAME
=
"cvmclient"
;
public
static
final
String
C3_ECC_ACCOUNT_NAME
=
"eccclient"
;
// 电商云集群
/**
* 电商云集群
public
static
final
String
C3_IP_ACCOUNT_NAME
=
"c3ipclient"
;
//c3 ip云
*/
public
static
final
String
C3_ECC_ACCOUNT_NAME
=
"eccclient"
;
public
static
final
String
SUPERBROWSER
=
"superbrowser"
;
public
static
final
String
ECOMMERCEBROWSER
=
"ecommercebrowser"
;
public
static
final
String
JKBROWSER
=
"jkbrowser"
;
/**
* c3 ip云
*/
public
static
final
String
C3_IP_ACCOUNT_NAME
=
"c3ipclient"
;
public
static
final
String
SUPER_BROWSER
=
"superbrowser"
;
public
static
final
String
ECOMMERCE_BROWSER
=
"ecommercebrowser"
;
public
static
final
String
JK_BROWSER
=
"jkbrowser"
;
//新增用户名写在上边
public
static
void
main
(
String
[]
args
)
{
for
(
String
cloudamUser
:
CLOUDAM_USERS
)
{
System
.
out
.
println
(
cloudamUser
);
}
}
static
{
static
{
Field
[]
fields
=
SpecialUsers
.
class
.
getFields
();
Field
[]
fields
=
SpecialUsers
.
class
.
getFields
();
...
@@ -69,5 +49,4 @@ public class SpecialUsers {
...
@@ -69,5 +49,4 @@ public class SpecialUsers {
}
}
}
}
}
}
src/main/java/com/edgec/browserbackend/common/dto/BaseResponse.java
View file @
d5b01f29
package
com
.
edgec
.
browserbackend
.
common
.
dto
;
package
com
.
edgec
.
browserbackend
.
common
.
dto
;
import
lombok.Data
;
@Deprecated
@Data
public
class
BaseResponse
<
T
>
{
public
class
BaseResponse
<
T
>
{
private
String
requestId
;
private
String
requestId
;
...
@@ -7,38 +11,4 @@ public class BaseResponse<T> {
...
@@ -7,38 +11,4 @@ public class BaseResponse<T> {
private
String
message
;
private
String
message
;
private
T
data
;
private
T
data
;
public
String
getRequestId
()
{
return
requestId
;
}
public
void
setRequestId
(
String
requestId
)
{
this
.
requestId
=
requestId
;
}
public
Result
getResult
()
{
return
result
;
}
public
void
setResult
(
Result
result
)
{
this
.
result
=
result
;
}
public
String
getMessage
()
{
return
message
;
}
public
void
setMessage
(
String
message
)
{
this
.
message
=
message
;
}
public
T
getData
()
{
return
data
;
}
public
void
setData
(
T
data
)
{
this
.
data
=
data
;
}
}
}
src/main/java/com/edgec/browserbackend/common/dto/Result.java
View file @
d5b01f29
package
com
.
edgec
.
browserbackend
.
common
.
dto
;
package
com
.
edgec
.
browserbackend
.
common
.
dto
;
@Deprecated
public
enum
Result
{
public
enum
Result
{
SUCCESS
,
SUCCESS
,
...
...
src/main/java/com/edgec/browserbackend/common/utils/Aes.java
View file @
d5b01f29
...
@@ -10,11 +10,20 @@ import javax.crypto.spec.SecretKeySpec;
...
@@ -10,11 +10,20 @@ import javax.crypto.spec.SecretKeySpec;
import
java.math.BigInteger
;
import
java.math.BigInteger
;
import
java.util.Base64
;
import
java.util.Base64
;
/**
* @author cloudam
* aes加解密工具类
*/
public
class
Aes
{
public
class
Aes
{
//密钥 (需要前端和后端保持一致)
/**
* 密钥 (需要前端和后端保持一致)
*/
private
static
final
String
KEY
=
"iefWFOAjfwefnWEI"
;
private
static
final
String
KEY
=
"iefWFOAjfwefnWEI"
;
//算法
/**
* 算法
*/
private
static
final
String
ALGORITHMSTR
=
"AES/ECB/PKCS5Padding"
;
private
static
final
String
ALGORITHMSTR
=
"AES/ECB/PKCS5Padding"
;
/**
/**
...
@@ -144,6 +153,7 @@ public class Aes {
...
@@ -144,6 +153,7 @@ public class Aes {
}
}
private
static
final
BCryptPasswordEncoder
encoder
=
new
BCryptPasswordEncoder
();
private
static
final
BCryptPasswordEncoder
encoder
=
new
BCryptPasswordEncoder
();
/**
/**
* 测试
* 测试
*/
*/
...
...
src/main/java/com/edgec/browserbackend/common/utils/JsonUtils.java
View file @
d5b01f29
...
@@ -16,11 +16,16 @@ import java.beans.PropertyDescriptor;
...
@@ -16,11 +16,16 @@ import java.beans.PropertyDescriptor;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.StringWriter
;
import
java.io.StringWriter
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Method
;
import
java.util.*
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
/**
* Json工具类
* Json工具类
*/
*/
@Deprecated
public
class
JsonUtils
{
public
class
JsonUtils
{
private
static
final
ObjectMapper
mapper
=
new
ObjectMapper
();
private
static
final
ObjectMapper
mapper
=
new
ObjectMapper
();
...
@@ -53,12 +58,12 @@ public class JsonUtils {
...
@@ -53,12 +58,12 @@ public class JsonUtils {
}
}
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
public
static
HashMap
<
String
,
String
>
toBeanStr
(
String
json
)
{
public
static
HashMap
<
String
,
String
>
toBeanStr
(
String
json
)
{
return
toBean
(
json
,
HashMap
.
class
);
return
toBean
(
json
,
HashMap
.
class
);
}
}
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
public
static
<
T
>
T
toBean
(
String
json
,
TypeReference
<
T
>
tr
){
public
static
<
T
>
T
toBean
(
String
json
,
TypeReference
<
T
>
tr
)
{
try
{
try
{
T
bean
=
(
T
)
mapper
.
readValue
(
json
,
tr
);
T
bean
=
(
T
)
mapper
.
readValue
(
json
,
tr
);
return
bean
;
return
bean
;
...
@@ -129,9 +134,9 @@ public class JsonUtils {
...
@@ -129,9 +134,9 @@ public class JsonUtils {
/**
/**
* json字符串转换为List
* json字符串转换为List
*/
*/
public
static
<
T
>
List
<
T
>
json2ListBean
(
String
json
,
Class
<
T
>
cls
)
{
public
static
<
T
>
List
<
T
>
json2ListBean
(
String
json
,
Class
<
T
>
cls
)
{
JSONArray
jArray
=
JSONArray
.
parseArray
(
json
);
JSONArray
jArray
=
JSONArray
.
parseArray
(
json
);
List
<
T
>
collection
=
jArray
.
toJavaList
(
cls
);
List
<
T
>
collection
=
jArray
.
toJavaList
(
cls
);
return
collection
;
return
collection
;
}
}
}
}
\ No newline at end of file
src/main/java/com/edgec/browserbackend/common/utils/PollerUtils.java
View file @
d5b01f29
...
@@ -2,6 +2,7 @@ package com.edgec.browserbackend.common.utils;
...
@@ -2,6 +2,7 @@ package com.edgec.browserbackend.common.utils;
import
java.time.Instant
;
import
java.time.Instant
;
@Deprecated
public
class
PollerUtils
{
public
class
PollerUtils
{
public
static
void
poll
(
int
timeoutInSeconds
,
int
intervalInSeconds
,
Evaluator
evaluator
)
{
public
static
void
poll
(
int
timeoutInSeconds
,
int
intervalInSeconds
,
Evaluator
evaluator
)
{
...
@@ -12,7 +13,7 @@ public class PollerUtils {
...
@@ -12,7 +13,7 @@ public class PollerUtils {
while
(!
result
)
{
while
(!
result
)
{
long
end
=
Instant
.
now
().
toEpochMilli
();
long
end
=
Instant
.
now
().
toEpochMilli
();
if
((
end
-
start
)
>
timeoutInSeconds
*
1000
)
if
((
end
-
start
)
>
timeoutInSeconds
*
1000
)
return
;
return
;
try
{
try
{
Thread
.
sleep
(
intervalInSeconds
*
1000
);
Thread
.
sleep
(
intervalInSeconds
*
1000
);
...
...
src/main/java/com/edgec/browserbackend/common/utils/ThreadPoolUtils.java
View file @
d5b01f29
package
com
.
edgec
.
browserbackend
.
common
.
utils
;
package
com
.
edgec
.
browserbackend
.
common
.
utils
;
import
com.edgec.browserbackend.common.commons.utils.PriorityThreadPoolExecutor
;
import
com.edgec.browserbackend.common.commons.utils.UniquePriorityBlockingQueue
;
import
com.edgec.browserbackend.common.commons.utils.UniquePriorityBlockingQueue
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.concurrent.*
;
import
java.util.concurrent.BlockingQueue
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.ThreadFactory
;
public
abstract
class
ThreadPoolUtils
{
public
abstract
class
ThreadPoolUtils
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
ThreadPoolUtils
.
class
);
public
static
final
BlockingQueue
<
Runnable
>
schedulerQueue
=
new
UniquePriorityBlockingQueue
<>(
50
);
public
static
final
BlockingQueue
<
Runnable
>
schedulerQueue
=
new
UniquePriorityBlockingQueue
<>(
50
);
...
...
src/main/java/com/edgec/browserbackend/common/utils/Trans.java
View file @
d5b01f29
...
@@ -21,11 +21,18 @@ import java.io.IOException;
...
@@ -21,11 +21,18 @@ import java.io.IOException;
public
class
Trans
{
public
class
Trans
{
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
Trans
.
class
);
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
Trans
.
class
);
static
int
timeout
=
10
*
1000
;
// 以秒为单位
private
static
String
specialHost
=
"39.108.183.128"
;
/**
private
static
int
specialPort
=
20008
;
* 以秒为单位
*/
static
int
timeout
=
10
*
1000
;
private
static
final
String
SPECIAL_HOST
=
"39.108.183.128"
;
private
static
final
int
SPECIAL_PORT
=
20008
;
private
String
host
;
private
String
host
;
private
int
port
;
private
int
port
;
private
String
username
;
private
String
username
;
private
String
password
;
private
String
password
;
...
@@ -37,8 +44,8 @@ public class Trans {
...
@@ -37,8 +44,8 @@ public class Trans {
}
}
public
Trans
(
String
username
,
String
password
)
{
public
Trans
(
String
username
,
String
password
)
{
this
.
host
=
specialHost
;
this
.
host
=
SPECIAL_HOST
;
this
.
port
=
specialPort
;
this
.
port
=
SPECIAL_PORT
;
this
.
password
=
password
;
this
.
password
=
password
;
this
.
username
=
username
;
this
.
username
=
username
;
}
}
...
@@ -72,11 +79,11 @@ public class Trans {
...
@@ -72,11 +79,11 @@ public class Trans {
//设置代理IP,设置连接超时时间 、 设置 请求读取数据的超时时间 、 设置从connect Manager获取Connection超时时间、
//设置代理IP,设置连接超时时间 、 设置 请求读取数据的超时时间 、 设置从connect Manager获取Connection超时时间、
RequestConfig
requestConfig
=
RequestConfig
.
custom
()
RequestConfig
requestConfig
=
RequestConfig
.
custom
()
.
setProxy
(
proxy
)
.
setProxy
(
proxy
)
.
setConnectTimeout
(
5000
)
.
setConnectTimeout
(
5000
)
.
setSocketTimeout
(
5000
)
.
setSocketTimeout
(
5000
)
.
setConnectionRequestTimeout
(
5000
)
.
setConnectionRequestTimeout
(
5000
)
.
build
();
.
build
();
httpGet
.
setConfig
(
requestConfig
);
httpGet
.
setConfig
(
requestConfig
);
//执行
//执行
...
...
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