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
9ad2b49b
Commit
9ad2b49b
authored
Jul 16, 2019
by
wutong
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
a40368a1
b1a39d11
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
75 additions
and
8 deletions
+75
-8
Application.java
...nance_amazon/src/main/java/com/bailuntec/Application.java
+2
-1
AdvertAddTaskSyncJob.java
...src/main/java/com/bailuntec/job/AdvertAddTaskSyncJob.java
+57
-7
AdvertSyncJobListener.java
...in/java/com/bailuntec/listener/AdvertSyncJobListener.java
+15
-0
const.properties
...e_sync_finance_amazon/src/main/resources/const.properties
+1
-0
No files found.
data-base/base_sync_finance_amazon/src/main/java/com/bailuntec/Application.java
View file @
9ad2b49b
...
@@ -3,6 +3,7 @@ package com.bailuntec;
...
@@ -3,6 +3,7 @@ package com.bailuntec;
import
com.alibaba.druid.pool.DruidDataSource
;
import
com.alibaba.druid.pool.DruidDataSource
;
import
com.bailuntec.job.AdvertAddTaskSyncJob
;
import
com.bailuntec.job.AdvertAddTaskSyncJob
;
import
com.bailuntec.job.AdvertResultSyncJob
;
import
com.bailuntec.job.AdvertResultSyncJob
;
import
com.bailuntec.listener.AdvertSyncJobListener
;
import
com.bailuntec.utils.PropertiesUtil
;
import
com.bailuntec.utils.PropertiesUtil
;
import
com.dangdang.ddframe.job.config.JobCoreConfiguration
;
import
com.dangdang.ddframe.job.config.JobCoreConfiguration
;
import
com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration
;
import
com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration
;
...
@@ -26,7 +27,7 @@ public class Application {
...
@@ -26,7 +27,7 @@ public class Application {
private
static
final
String
EVENT_RDB_STORAGE_PASSWORD
=
propertiesUtil
.
getPropertyAsString
(
"EVENT_RDB_STORAGE_PASSWORD"
);
private
static
final
String
EVENT_RDB_STORAGE_PASSWORD
=
propertiesUtil
.
getPropertyAsString
(
"EVENT_RDB_STORAGE_PASSWORD"
);
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
new
JobScheduler
(
createRegistryCenter
(),
createJobConfiguration1
()).
init
();
new
JobScheduler
(
createRegistryCenter
(),
createJobConfiguration1
()
,
createJobEventConfiguration
(),
new
AdvertSyncJobListener
()
).
init
();
// new JobScheduler(createRegistryCenter(), createJobConfiguration2()).init();
// new JobScheduler(createRegistryCenter(), createJobConfiguration2()).init();
}
}
...
...
data-base/base_sync_finance_amazon/src/main/java/com/bailuntec/job/AdvertAddTaskSyncJob.java
View file @
9ad2b49b
...
@@ -13,14 +13,14 @@ import com.dangdang.ddframe.job.api.ShardingContext;
...
@@ -13,14 +13,14 @@ import com.dangdang.ddframe.job.api.ShardingContext;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
okhttp3.*
;
import
okhttp3.*
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
java.io.BufferedReader
;
import
java.io.*
;
import
java.io.InputStreamReader
;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
import
java.time.format.DateTimeFormatter
;
import
java.time.format.DateTimeFormatter
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.zip.GZIPInputStream
;
import
java.util.zip.GZIPInputStream
;
import
java.util.zip.ZipException
;
@Slf4j
@Slf4j
public
class
AdvertAddTaskSyncJob
extends
PointJob
{
public
class
AdvertAddTaskSyncJob
extends
PointJob
{
...
@@ -39,13 +39,18 @@ public class AdvertAddTaskSyncJob extends PointJob {
...
@@ -39,13 +39,18 @@ public class AdvertAddTaskSyncJob extends PointJob {
Response
response
=
null
;
Response
response
=
null
;
try
{
try
{
do
{
do
{
List
<
Map
>
list
=
null
;
try
{
Request
request0
=
new
Request
.
Builder
()
Request
request0
=
new
Request
.
Builder
()
.
url
(
propertiesUtil
.
getPropertyAsString
(
"ACCOUNT_API"
))
.
url
(
propertiesUtil
.
getPropertyAsString
(
"ACCOUNT_API"
))
.
addHeader
(
"Content-Type"
,
"application/json"
)
.
addHeader
(
"Content-Type"
,
"application/json"
)
.
build
();
.
build
();
response
=
client
.
newCall
(
request0
).
execute
();
response
=
client
.
newCall
(
request0
).
execute
();
AccountTokenInfo
resultMap0
=
JSON
.
parseObject
(
response
.
body
().
string
(),
AccountTokenInfo
.
class
);
AccountTokenInfo
resultMap0
=
JSON
.
parseObject
(
response
.
body
().
string
(),
AccountTokenInfo
.
class
);
List
<
Map
>
list
=
resultMap0
.
getData
();
list
=
resultMap0
.
getData
();
}
catch
(
IOException
e
){
throw
new
RuntimeException
(
"调用百伦授权接口失败,详情:"
+
transform
(
e
));
}
Map
<
String
,
String
>
authJsonMap
=
new
HashMap
<
String
,
String
>();
Map
<
String
,
String
>
authJsonMap
=
new
HashMap
<
String
,
String
>();
if
(
list
!=
null
&&
list
.
size
()
>
0
)
{
if
(
list
!=
null
&&
list
.
size
()
>
0
)
{
for
(
Map
map0
:
list
)
{
for
(
Map
map0
:
list
)
{
...
@@ -54,7 +59,8 @@ public class AdvertAddTaskSyncJob extends PointJob {
...
@@ -54,7 +59,8 @@ public class AdvertAddTaskSyncJob extends PointJob {
continue
;
continue
;
}
}
authJsonMap
=
JSON
.
parseObject
(
authStr
,
Map
.
class
);
authJsonMap
=
JSON
.
parseObject
(
authStr
,
Map
.
class
);
Map
<
String
,
String
>
resultMap
=
new
HashMap
<>();
try
{
Map
<
String
,
String
>
map
=
new
HashMap
<>();
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"reportDate"
,
localDateTime
.
format
(
DateTimeFormatter
.
ofPattern
(
"yyyyMMdd"
)));
map
.
put
(
"reportDate"
,
localDateTime
.
format
(
DateTimeFormatter
.
ofPattern
(
"yyyyMMdd"
)));
map
.
put
(
"metrics"
,
propertiesUtil
.
getPropertyAsString
(
"METRICS"
));
map
.
put
(
"metrics"
,
propertiesUtil
.
getPropertyAsString
(
"METRICS"
));
...
@@ -68,8 +74,13 @@ public class AdvertAddTaskSyncJob extends PointJob {
...
@@ -68,8 +74,13 @@ public class AdvertAddTaskSyncJob extends PointJob {
.
addHeader
(
"Content-Type"
,
"application/json"
)
.
addHeader
(
"Content-Type"
,
"application/json"
)
.
build
();
.
build
();
response
=
client
.
newCall
(
request
).
execute
();
response
=
client
.
newCall
(
request
).
execute
();
Map
<
String
,
String
>
resultMap
=
JSON
.
parseObject
(
response
.
body
().
string
(),
Map
.
class
);
resultMap
=
JSON
.
parseObject
(
response
.
body
().
string
(),
Map
.
class
);
}
catch
(
IOException
e
){
throw
new
RuntimeException
(
"调用广告费报告任务下发接口失败,错误详情:"
+
transform
(
e
));
}
if
(
"IN_PROGRESS"
.
equals
(
resultMap
.
get
(
"status"
)))
{
if
(
"IN_PROGRESS"
.
equals
(
resultMap
.
get
(
"status"
)))
{
Map
<
String
,
String
>
resultMap2
=
new
HashMap
<>();
try
{
Request
request2
=
new
Request
.
Builder
()
Request
request2
=
new
Request
.
Builder
()
.
url
(
propertiesUtil
.
getPropertyAsString
(
"V2_REPORTS"
)
+
resultMap
.
get
(
"reportId"
))
.
url
(
propertiesUtil
.
getPropertyAsString
(
"V2_REPORTS"
)
+
resultMap
.
get
(
"reportId"
))
.
addHeader
(
"Authorization"
,
"Bearer "
+
authJsonMap
.
get
(
"access_token"
))
.
addHeader
(
"Authorization"
,
"Bearer "
+
authJsonMap
.
get
(
"access_token"
))
...
@@ -78,8 +89,12 @@ public class AdvertAddTaskSyncJob extends PointJob {
...
@@ -78,8 +89,12 @@ public class AdvertAddTaskSyncJob extends PointJob {
.
addHeader
(
"Content-Type"
,
"application/json"
)
.
addHeader
(
"Content-Type"
,
"application/json"
)
.
build
();
.
build
();
response
=
client
.
newCall
(
request2
).
execute
();
response
=
client
.
newCall
(
request2
).
execute
();
Map
<
String
,
String
>
resultMap2
=
JSON
.
parseObject
(
response
.
body
().
string
(),
Map
.
class
);
resultMap2
=
JSON
.
parseObject
(
response
.
body
().
string
(),
Map
.
class
);
}
catch
(
IOException
e
){
throw
new
RuntimeException
(
"调用广告费报告下载路径错误,错误详情:"
+
transform
(
e
));
}
if
(
"SUCCESS"
.
equals
(
resultMap2
.
get
(
"status"
)))
{
if
(
"SUCCESS"
.
equals
(
resultMap2
.
get
(
"status"
)))
{
try
{
String
location
=
resultMap2
.
get
(
"location"
);
String
location
=
resultMap2
.
get
(
"location"
);
Request
request3
=
new
Request
.
Builder
()
Request
request3
=
new
Request
.
Builder
()
.
url
(
location
)
.
url
(
location
)
...
@@ -106,13 +121,37 @@ public class AdvertAddTaskSyncJob extends PointJob {
...
@@ -106,13 +121,37 @@ public class AdvertAddTaskSyncJob extends PointJob {
dcBaseFinanceAmazonMapper
.
upsertSelective
(
amazonAdvert
);
dcBaseFinanceAmazonMapper
.
upsertSelective
(
amazonAdvert
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
throw
new
RuntimeException
(
"Mybatis操作DB插入任务记录失败"
,
e
);
throw
new
RuntimeException
(
"Mybatis操作DB插入任务记录失败,错误详情:"
+
transform
(
e
)
);
}
finally
{
}
finally
{
SessionUtil
.
closeSession
();
SessionUtil
.
closeSession
();
}
}
}
}
gzin
.
close
();
gzin
.
close
();
isr
.
close
();
isr
.
close
();
}
catch
(
ZipException
e
){
log
.
warn
(
"返回数据为非gz压缩格式"
,
response
.
body
().
toString
());
}
catch
(
IOException
e
){
throw
new
RuntimeException
(
"调用广告费报告解析接口报错,错误详情:"
+
transform
(
e
));
}
}
}
else
{
if
(
job
.
getPageIndex
()
==
2
)
{
try
{
Map
errorMap
=
new
HashMap
();
Map
contentMap
=
new
HashMap
();
contentMap
.
put
(
"content"
,
"帐号id:"
+
map0
.
get
(
"Id"
)+
"授权失败,错误详情:"
+
resultMap
);
errorMap
.
put
(
"msgtype"
,
"text"
);
errorMap
.
put
(
"text"
,
contentMap
);
RequestBody
errorBody
=
RequestBody
.
create
(
mediaType
,
JSON
.
toJSONString
(
errorMap
));
Request
request2
=
new
Request
.
Builder
()
.
url
(
propertiesUtil
.
getPropertyAsString
(
"WARN_API"
))
.
post
(
errorBody
)
.
addHeader
(
"Content-Type"
,
"application/json"
)
.
build
();
response
=
client
.
newCall
(
request2
).
execute
();
}
catch
(
Exception
e
){
e
.
printStackTrace
();
}
}
}
}
}
}
}
...
@@ -129,4 +168,15 @@ public class AdvertAddTaskSyncJob extends PointJob {
...
@@ -129,4 +168,15 @@ public class AdvertAddTaskSyncJob extends PointJob {
}
}
}
}
}
}
public
String
transform
(
final
Throwable
cause
)
{
if
(
null
==
cause
)
{
return
""
;
}
StringWriter
result
=
new
StringWriter
();
try
(
PrintWriter
writer
=
new
PrintWriter
(
result
))
{
cause
.
printStackTrace
(
writer
);
}
return
result
.
toString
();
}
}
}
data-base/base_sync_finance_amazon/src/main/java/com/bailuntec/listener/AdvertSyncJobListener.java
0 → 100644
View file @
9ad2b49b
package
com
.
bailuntec
.
listener
;
import
com.dangdang.ddframe.job.executor.ShardingContexts
;
import
com.dangdang.ddframe.job.lite.api.listener.ElasticJobListener
;
public
class
AdvertSyncJobListener
implements
ElasticJobListener
{
@Override
public
void
beforeJobExecuted
(
ShardingContexts
shardingContexts
)
{
}
@Override
public
void
afterJobExecuted
(
ShardingContexts
shardingContexts
)
{
}
}
data-base/base_sync_finance_amazon/src/main/resources/const.properties
View file @
9ad2b49b
...
@@ -3,6 +3,7 @@ GETRESULT_FINANCE_URL=http://10.0.3.5:18321/outer/getresult
...
@@ -3,6 +3,7 @@ GETRESULT_FINANCE_URL=http://10.0.3.5:18321/outer/getresult
ACCOUNT_API
=
http://pams.bailuntec.com/Api/GetAccountToken?platform=Amazon
ACCOUNT_API
=
http://pams.bailuntec.com/Api/GetAccountToken?platform=Amazon
CAMPAIGNS_REPORT
=
https://advertising-api.amazon.com/v2/sp/campaigns/report
CAMPAIGNS_REPORT
=
https://advertising-api.amazon.com/v2/sp/campaigns/report
V2_REPORTS
=
https://advertising-api.amazon.com/v2/reports/
V2_REPORTS
=
https://advertising-api.amazon.com/v2/reports/
WARN_API
=
https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=b4655a50-927a-4c3c-87ad-a900e54dcc8e
#METRICS=campaignName,campaignId,campaignStatus,campaignBudget,attributedConversions1d,attributedUnitsOrdered1d,attributedSales1d,attributedUnitsOrdered7d,attributedSales1d,impressions,clicks,cost,attributedConversions30d,attributedConversions14d,attributedConversions7d,attributedSales30d,attributedSales14d,attributedSales7d
#METRICS=campaignName,campaignId,campaignStatus,campaignBudget,attributedConversions1d,attributedUnitsOrdered1d,attributedSales1d,attributedUnitsOrdered7d,attributedSales1d,impressions,clicks,cost,attributedConversions30d,attributedConversions14d,attributedConversions7d,attributedSales30d,attributedSales14d,attributedSales7d
METRICS
=
campaignName,campaignId,cost,currency,campaignStatus,campaignBudget,cost
METRICS
=
campaignName,campaignId,cost,currency,campaignStatus,campaignBudget,cost
...
...
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