Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
dc-java
Overview
Overview
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
bltdc
dc-java
Commits
c2ffb8fa
Commit
c2ffb8fa
authored
Jul 25, 2019
by
wutong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
下载报告失败重试3次
parent
3528fbed
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
15 deletions
+25
-15
AmazonAdProductJob.java
...d/src/main/java/com/bailuntec/job/AmazonAdProductJob.java
+25
-15
No files found.
data-base/base-sync-amazon-ad/src/main/java/com/bailuntec/job/AmazonAdProductJob.java
View file @
c2ffb8fa
...
...
@@ -165,7 +165,6 @@ public class AmazonAdProductJob extends PointJob {
private
void
handleReport
(
String
reportLocationUrl
,
JobAccountLog
jobAccountLog
,
AmazonAdAuth
amazonAdAuth
){
Response
response
=
null
;
GZIPInputStream
gzin
=
null
;
try
{
Request
request
=
new
Request
.
Builder
()
.
url
(
reportLocationUrl
)
.
get
()
...
...
@@ -174,10 +173,13 @@ public class AmazonAdProductJob extends PointJob {
.
addHeader
(
"Amazon-Advertising-API-Scope"
,
amazonAdAuth
.
getProfileId
())
.
addHeader
(
"Content-Type"
,
"application/json"
)
.
build
();
for
(
int
i
=
0
;
i
<
3
;
i
++)
{
try
{
response
=
client
.
newCall
(
request
).
execute
();
if
(
response
.
isSuccessful
())
{
gzin
=
new
GZIPInputStream
(
response
.
body
().
byteStream
());
List
<
AmazonAdProduct
>
amazonAdProductList
=
JSON
.
parseObject
(
gzin
,
new
TypeReference
<
List
<
AmazonAdProduct
>>(){}.
getType
());
List
<
AmazonAdProduct
>
amazonAdProductList
=
JSON
.
parseObject
(
gzin
,
new
TypeReference
<
List
<
AmazonAdProduct
>>()
{
}.
getType
());
gzin
.
close
();
response
.
close
();
if
(
amazonAdProductList
!=
null
&&
amazonAdProductList
.
size
()
>
0
)
{
...
...
@@ -193,8 +195,8 @@ public class AmazonAdProductJob extends PointJob {
dcBaseFinanceAmazonAdProduct
.
setExchangeRateUsd
(
CallBailunSystem
.
getExchangeRate
(
dcBaseFinanceAmazonAdProduct
.
getCurrency
(),
CurrencyType
.
USD
.
value
(),
jobAccountLog
.
getStartTime
()));
dcBaseFinanceAmazonAdProduct
.
setBjModifyTime
(
LocalDateTime
.
now
());
DcBaseFinanceAmazonAdProductExample
example
=
DcBaseFinanceAmazonAdProductExample
.
newAndCreateCriteria
().
andCompanyIdEqualTo
(
dcBaseFinanceAmazonAdProduct
.
getCompanyId
()).
andAccountIdEqualTo
(
dcBaseFinanceAmazonAdProduct
.
getAccountId
()).
andCampaignIdEqualTo
(
dcBaseFinanceAmazonAdProduct
.
getCampaignId
()).
andAdGroupIdEqualTo
(
dcBaseFinanceAmazonAdProduct
.
getAdGroupId
()).
andSkuEqualTo
(
dcBaseFinanceAmazonAdProduct
.
getSku
()).
andReportDateEqualTo
(
dcBaseFinanceAmazonAdProduct
.
getReportDate
()).
example
();
int
i
=
mapper
.
updateByExampleSelective
(
dcBaseFinanceAmazonAdProduct
,
example
);
if
(
i
==
0
)
{
int
update
=
mapper
.
updateByExampleSelective
(
dcBaseFinanceAmazonAdProduct
,
example
);
if
(
update
==
0
)
{
mapper
.
insertSelective
(
dcBaseFinanceAmazonAdProduct
);
}
}
...
...
@@ -210,6 +212,7 @@ public class AmazonAdProductJob extends PointJob {
jobAccountLog
.
setStartTime
(
overStartTime
);
jobAccountLog
.
setEndTime
(
jobAccountLog
.
getStartTime
().
plusDays
(
jobAccountLog
.
getIntervalTime
()).
isAfter
(
LocalDateTime
.
now
())
?
LocalDateTime
.
now
()
:
jobAccountLog
.
getEndTime
().
plusDays
(
jobAccountLog
.
getIntervalTime
()));
jobAccountLog
.
setMessage
(
"执行成功"
);
break
;
}
else
{
String
s
=
response
.
body
().
string
();
log
.
warn
(
"下载报告不成功:"
+
s
);
...
...
@@ -218,7 +221,7 @@ public class AmazonAdProductJob extends PointJob {
}
catch
(
Exception
e
){
e
.
printStackTrace
();
log
.
error
(
"调用获取AmazonADReportLocation错误:"
,
e
);
jobAccountLog
.
setMessage
(
reportLocationUrl
+
"
调用获取AmazonADReportLocation错误:"
+
ExceptionUtil
.
transform
(
e
));
jobAccountLog
.
setMessage
(
"第"
+
i
+
"次
调用获取AmazonADReportLocation错误:"
+
ExceptionUtil
.
transform
(
e
));
}
finally
{
if
(
gzin
!=
null
)
{
try
{
...
...
@@ -232,11 +235,18 @@ public class AmazonAdProductJob extends PointJob {
response
.
close
();
}
}
try
{
Thread
.
sleep
(
SLEEP_WAIT
);
}
catch
(
InterruptedException
e
)
{
jobAccountLog
.
setMessage
(
"线程异常"
+
ExceptionUtil
.
transform
(
e
));
e
.
printStackTrace
();
Thread
.
currentThread
().
interrupt
();
}
}
}
private
String
getReportLocation
(
String
reportId
,
JobAccountLog
jobAccountLog
,
AmazonAdAuth
amazonAdAuth
,
String
siteEn
)
{
Response
response
=
null
;
try
{
Request
request
=
new
Request
.
Builder
()
.
url
(
switchSiteUrl
(
siteEn
,
reportId
)
+
reportId
)
.
addHeader
(
"Authorization"
,
amazonAdAuth
.
getAccessToken
())
...
...
@@ -244,20 +254,13 @@ public class AmazonAdProductJob extends PointJob {
.
addHeader
(
"Amazon-Advertising-API-Scope"
,
amazonAdAuth
.
getProfileId
())
.
addHeader
(
"Content-Type"
,
"application/json"
)
.
build
();
try
{
response
=
client
.
newCall
(
request
).
execute
();
if
(
response
.
isSuccessful
())
{
AmazonAdReportLocationResult
reportLocationResult
=
JSON
.
parseObject
(
response
.
body
().
string
(),
AmazonAdReportLocationResult
.
class
);
if
(
reportLocationResult
.
getStatus
().
equals
(
"SUCCESS"
))
{
return
reportLocationResult
.
getLocation
();
}
try
{
Thread
.
sleep
(
60000
);
}
catch
(
InterruptedException
e
)
{
jobAccountLog
.
setMessage
(
"线程异常"
+
ExceptionUtil
.
transform
(
e
));
e
.
printStackTrace
();
Thread
.
currentThread
().
interrupt
();
}
return
getReportLocation
(
reportId
,
jobAccountLog
,
amazonAdAuth
,
siteEn
);
}
else
{
String
s
=
response
.
body
().
string
();
log
.
warn
(
"获取报告下载地址不成功:"
+
s
);
...
...
@@ -271,7 +274,14 @@ public class AmazonAdProductJob extends PointJob {
response
.
close
();
}
}
return
null
;
try
{
Thread
.
sleep
(
60000
);
}
catch
(
InterruptedException
e
)
{
jobAccountLog
.
setMessage
(
"线程异常"
+
ExceptionUtil
.
transform
(
e
));
e
.
printStackTrace
();
Thread
.
currentThread
().
interrupt
();
}
return
getReportLocation
(
reportId
,
jobAccountLog
,
amazonAdAuth
,
siteEn
);
}
private
String
postReportId
(
JobAccountLog
jobAccountLog
,
AmazonAdAuth
amazonAdAuth
,
String
siteEn
)
{
...
...
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