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
55925537
Commit
55925537
authored
May 12, 2020
by
renjie
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev-zrj' into 'staging'
子账户续费 See merge request
!80
parents
85087095
eee0fbd5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
69 additions
and
8 deletions
+69
-8
PaymentServiceImpl.java
...owserbackend/account/service/impl/PaymentServiceImpl.java
+4
-4
IpResourceRepositoryCustom.java
...ackend/browser/repository/IpResourceRepositoryCustom.java
+2
-0
IpResourceRepositoryCustomImpl.java
...nd/browser/repository/IpResourceRepositoryCustomImpl.java
+16
-1
BrowserTask.java
...va/com/edgec/browserbackend/browser/task/BrowserTask.java
+40
-0
Trans.java
...ain/java/com/edgec/browserbackend/common/utils/Trans.java
+7
-3
No files found.
src/main/java/com/edgec/browserbackend/account/service/impl/PaymentServiceImpl.java
View file @
55925537
...
@@ -367,8 +367,8 @@ public class PaymentServiceImpl implements PaymentService {
...
@@ -367,8 +367,8 @@ public class PaymentServiceImpl implements PaymentService {
Account
byName
=
accountService
.
findByName
(
username
);
Account
byName
=
accountService
.
findByName
(
username
);
if
(
byName
==
null
)
if
(
byName
==
null
)
throw
new
ClientRequestException
(
AccountErrorCode
.
NAMENOTEXIST
,
"account does not exist: "
+
username
);
throw
new
ClientRequestException
(
AccountErrorCode
.
NAMENOTEXIST
,
"account does not exist: "
+
username
);
if
(
byName
.
getPermission
()
<
8
)
//
if (byName.getPermission() < 8)
throw
new
ClientRequestException
(
AccountErrorCode
.
NOPERMISSION
,
"account does not have permission: "
+
username
);
//
throw new ClientRequestException(AccountErrorCode.NOPERMISSION, "account does not have permission: " + username);
boolean
isVpsClient
=
true
;
boolean
isVpsClient
=
true
;
UserPayment
internalOrder
=
new
UserPayment
();
UserPayment
internalOrder
=
new
UserPayment
();
...
@@ -421,8 +421,8 @@ public class PaymentServiceImpl implements PaymentService {
...
@@ -421,8 +421,8 @@ public class PaymentServiceImpl implements PaymentService {
Account
byName
=
accountService
.
findByName
(
username
);
Account
byName
=
accountService
.
findByName
(
username
);
if
(
byName
==
null
)
if
(
byName
==
null
)
throw
new
ClientRequestException
(
AccountErrorCode
.
NAMENOTEXIST
,
"account does not exist: "
+
username
);
throw
new
ClientRequestException
(
AccountErrorCode
.
NAMENOTEXIST
,
"account does not exist: "
+
username
);
if
(
byName
.
getPermission
()
<
8
)
//
if (byName.getPermission() < 8)
throw
new
ClientRequestException
(
AccountErrorCode
.
NOPERMISSION
,
"account does not have permission: "
+
username
);
//
throw new ClientRequestException(AccountErrorCode.NOPERMISSION, "account does not have permission: " + username);
boolean
isVpsClient
=
true
;
boolean
isVpsClient
=
true
;
...
...
src/main/java/com/edgec/browserbackend/browser/repository/IpResourceRepositoryCustom.java
View file @
55925537
...
@@ -11,4 +11,6 @@ public interface IpResourceRepositoryCustom {
...
@@ -11,4 +11,6 @@ public interface IpResourceRepositoryCustom {
boolean
unLockTask
(
String
id
);
boolean
unLockTask
(
String
id
);
List
<
IpResource
>
sampleTasks
(
int
status
,
long
timestamp
);
List
<
IpResource
>
sampleTasks
(
int
status
,
long
timestamp
);
List
<
IpResource
>
sampleTasks
(
List
<
Integer
>
status
);
}
}
src/main/java/com/edgec/browserbackend/browser/repository/IpResourceRepositoryCustomImpl.java
View file @
55925537
...
@@ -65,7 +65,22 @@ public class IpResourceRepositoryCustomImpl implements IpResourceRepositoryCusto
...
@@ -65,7 +65,22 @@ public class IpResourceRepositoryCustomImpl implements IpResourceRepositoryCusto
public
List
<
IpResource
>
sampleTasks
(
int
status
,
long
timestamp
)
{
public
List
<
IpResource
>
sampleTasks
(
int
status
,
long
timestamp
)
{
Criteria
matchCriteria
=
new
Criteria
();
Criteria
matchCriteria
=
new
Criteria
();
matchCriteria
.
orOperator
(
where
(
"status"
).
is
(
status
).
and
(
"isLocked"
).
is
(
false
).
and
(
"isDeleted"
).
is
(
false
),
matchCriteria
.
orOperator
(
where
(
"status"
).
is
(
status
).
and
(
"isLocked"
).
is
(
false
).
and
(
"isDeleted"
).
is
(
false
),
where
(
"isLocked"
).
is
(
true
).
and
(
"lockTimestamp"
).
lte
(
timestamp
)).
and
(
"isDeleted"
).
is
(
false
);
where
(
"status"
).
is
(
status
).
and
(
"isLocked"
).
is
(
true
).
and
(
"lockTimestamp"
).
lte
(
timestamp
)).
and
(
"isDeleted"
).
is
(
false
);
MatchOperation
match
=
Aggregation
.
match
(
matchCriteria
);
SampleOperation
sample
=
Aggregation
.
sample
(
20
);
AggregationResults
<
IpResource
>
results
=
mongoTemplate
.
aggregate
(
Aggregation
.
newAggregation
(
match
,
sample
),
IpResource
.
class
,
IpResource
.
class
);
List
<
IpResource
>
mappedResults
=
results
.
getMappedResults
();
return
mappedResults
;
}
@Override
public
List
<
IpResource
>
sampleTasks
(
List
<
Integer
>
status
)
{
Criteria
matchCriteria
=
new
Criteria
();
matchCriteria
.
orOperator
(
where
(
"status"
).
in
(
status
).
and
(
"isLocked"
).
is
(
false
).
and
(
"isDeleted"
).
is
(
false
).
and
(
"lockTimestamp"
).
lte
(
Instant
.
now
().
toEpochMilli
()),
where
(
"status"
).
in
(
status
).
and
(
"isLocked"
).
is
(
true
).
and
(
"lockTimestamp"
).
lte
((
Instant
.
now
().
toEpochMilli
())
-
60
*
1000
*
30
)).
and
(
"isDeleted"
).
is
(
false
);
MatchOperation
match
=
Aggregation
.
match
(
matchCriteria
);
MatchOperation
match
=
Aggregation
.
match
(
matchCriteria
);
...
...
src/main/java/com/edgec/browserbackend/browser/task/BrowserTask.java
View file @
55925537
...
@@ -2,6 +2,8 @@ package com.edgec.browserbackend.browser.task;
...
@@ -2,6 +2,8 @@ package com.edgec.browserbackend.browser.task;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.edgec.browserbackend.account.domain.IpChargeRequestDto
;
import
com.edgec.browserbackend.account.domain.IpChargeRequestDto
;
import
com.edgec.browserbackend.account.domain.QueryIpUrlList
;
import
com.edgec.browserbackend.account.repository.QueryIpUrlListRepository
;
import
com.edgec.browserbackend.account.service.AccountService
;
import
com.edgec.browserbackend.account.service.AccountService
;
import
com.edgec.browserbackend.browser.domain.IpResource
;
import
com.edgec.browserbackend.browser.domain.IpResource
;
import
com.edgec.browserbackend.browser.dto.IpBuyResultDto
;
import
com.edgec.browserbackend.browser.dto.IpBuyResultDto
;
...
@@ -11,6 +13,7 @@ import com.edgec.browserbackend.browser.repository.IpResourceRepository;
...
@@ -11,6 +13,7 @@ import com.edgec.browserbackend.browser.repository.IpResourceRepository;
import
com.edgec.browserbackend.browser.service.IpAndShopService
;
import
com.edgec.browserbackend.browser.service.IpAndShopService
;
import
com.edgec.browserbackend.common.commons.utils.NotifyUtils
;
import
com.edgec.browserbackend.common.commons.utils.NotifyUtils
;
import
com.edgec.browserbackend.common.utils.ThreadPoolUtils
;
import
com.edgec.browserbackend.common.utils.ThreadPoolUtils
;
import
com.edgec.browserbackend.common.utils.Trans
;
import
okhttp3.*
;
import
okhttp3.*
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
...
@@ -26,6 +29,7 @@ import org.springframework.web.client.RestTemplate;
...
@@ -26,6 +29,7 @@ import org.springframework.web.client.RestTemplate;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.time.Instant
;
import
java.time.Instant
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -54,6 +58,9 @@ public class BrowserTask {
...
@@ -54,6 +58,9 @@ public class BrowserTask {
@Autowired
@Autowired
private
IpAndShopService
ipAndShopService
;
private
IpAndShopService
ipAndShopService
;
@Autowired
private
QueryIpUrlListRepository
queryIpUrlListRepository
;
@Value
(
"${spring.profiles.active}"
)
@Value
(
"${spring.profiles.active}"
)
private
String
profiles
;
private
String
profiles
;
...
@@ -212,6 +219,39 @@ public class BrowserTask {
...
@@ -212,6 +219,39 @@ public class BrowserTask {
}
}
}
}
// @Scheduled(cron = "0 0/1 * * * ?")
public
void
healthCheck
()
{
String
URL
=
(
profiles
.
equals
(
"dev"
)
||
profiles
.
equals
(
"staging"
))
?
TESTURL
:
CLOUDAMURL
;
List
<
IpResource
>
ipResources
=
ipResourceRepository
.
sampleTasks
(
Arrays
.
asList
(
0
,
2
));
for
(
IpResource
ipResource
:
ipResources
)
{
long
start
=
System
.
currentTimeMillis
();
CompletableFuture
.
runAsync
(()
->
{
if
(
ipResourceRepository
.
lockTask
(
ipResource
))
{
try
{
QueryIpUrlList
queryIpUrlList
=
queryIpUrlListRepository
.
findAll
().
get
(
0
);
Trans
trans
;
if
(
ipResource
.
isSpecialLine
())
{
trans
=
new
Trans
();
}
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
}
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
);
}
}
public
static
class
HttpClientutils
{
public
static
class
HttpClientutils
{
static
OkHttpClient
.
Builder
builder
=
new
OkHttpClient
.
Builder
();
static
OkHttpClient
.
Builder
builder
=
new
OkHttpClient
.
Builder
();
...
...
src/main/java/com/edgec/browserbackend/common/utils/Trans.java
View file @
55925537
package
com
.
edgec
.
browserbackend
.
common
.
utils
;
package
com
.
edgec
.
browserbackend
.
common
.
utils
;
import
com.edgec.browserbackend.common.commons.utils.NotifyUtils
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.HttpHost
;
import
org.apache.http.HttpHost
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.HttpResponse
;
...
@@ -33,6 +34,10 @@ public class Trans {
...
@@ -33,6 +34,10 @@ public class Trans {
this
.
username
=
username
;
this
.
username
=
username
;
}
}
public
Trans
()
{
}
/**
/**
* 主入口方法
* 主入口方法
* @param args
* @param args
...
@@ -41,7 +46,6 @@ public class Trans {
...
@@ -41,7 +46,6 @@ public class Trans {
String
url
=
"http://pv.sohu.com/cityjson"
;
String
url
=
"http://pv.sohu.com/cityjson"
;
Trans
trans
=
new
Trans
(
"120.76.135.212"
,
20001
,
"fangguanlianbrowser"
,
"2rbvtg9GQ1JraA1"
);
Trans
trans
=
new
Trans
(
"120.76.135.212"
,
20001
,
"fangguanlianbrowser"
,
"2rbvtg9GQ1JraA1"
);
String
result
=
trans
.
get
(
url
,
false
);
String
result
=
trans
.
get
(
url
,
false
);
System
.
out
.
println
(
result
);
}
}
public
HttpClient
getHttpClient
()
{
public
HttpClient
getHttpClient
()
{
...
@@ -82,10 +86,10 @@ public class Trans {
...
@@ -82,10 +86,10 @@ public class Trans {
}
}
}
catch
(
ClientProtocolException
e
)
{
}
catch
(
ClientProtocolException
e
)
{
// TODO Auto-generated catch block
NotifyUtils
.
sendMessage
(
"防关联浏览器 ip "
+
host
+
" 代理异常"
,
e
,
NotifyUtils
.
MsgType
.
WEBHOOK
);
logger
.
error
(
e
.
getMessage
(),
e
);
logger
.
error
(
e
.
getMessage
(),
e
);
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
// TODO Auto-generated catch block
NotifyUtils
.
sendMessage
(
"防关联浏览器 ip "
+
host
+
" 代理异常"
,
e
,
NotifyUtils
.
MsgType
.
WEBHOOK
);
logger
.
error
(
e
.
getMessage
(),
e
);
logger
.
error
(
e
.
getMessage
(),
e
);
}
}
System
.
out
.
println
(
sb
.
toString
());
System
.
out
.
println
(
sb
.
toString
());
...
...
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