Commit 094a48b1 by huluobin

广告!!!!!

parent 4e5c0351
package com.bailuntec.domain.pojo;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
/**
* <p>
*
* </p>
*
* @author robbendev
* @since 2020/8/24 10:29 上午
*/
public class AmazonURI {
public static final URI NA_AMAZON_AD_URL = URI.create("https://advertising-api.amazon.com");
public static final URI EU_AMAZON_AD_URL = URI.create("https://advertising-api-eu.amazon.com");
public static final URI FE_AMAZON_AD_URL = URI.create("https://advertising-api-fe.amazon.com");
public static final Map<String, URI> amazonUriMap = new HashMap<>();
public static URI getAmazonAdSiteUri(String siteEn) {
switch (siteEn.toUpperCase()) {
case "UK":
case "FR":
case "IT":
case "ES":
case "DE":
return EU_AMAZON_AD_URL;
case "AU":
case "JP":
case "IN":
return FE_AMAZON_AD_URL;
case "US":
case "CA":
case "MX":
default:
return NA_AMAZON_AD_URL;
}
}
}
...@@ -8,6 +8,7 @@ import com.bailuntec.domain.example.DcBaseCompanyAccountExample; ...@@ -8,6 +8,7 @@ import com.bailuntec.domain.example.DcBaseCompanyAccountExample;
import com.bailuntec.domain.example.JobAmazonAdLogExample; import com.bailuntec.domain.example.JobAmazonAdLogExample;
import com.bailuntec.domain.pojo.AmazonAdAuth; import com.bailuntec.domain.pojo.AmazonAdAuth;
import com.bailuntec.domain.pojo.AmazonAdSuccessResult; import com.bailuntec.domain.pojo.AmazonAdSuccessResult;
import com.bailuntec.domain.pojo.AmazonURI;
import com.bailuntec.mapper.DcBaseCompanyAccountMapper; import com.bailuntec.mapper.DcBaseCompanyAccountMapper;
import com.bailuntec.mapper.JobAmazonAdLogMapper; import com.bailuntec.mapper.JobAmazonAdLogMapper;
import com.bailuntec.utils.OkHttpUtil; import com.bailuntec.utils.OkHttpUtil;
...@@ -48,7 +49,12 @@ public class AmazonAdGenerateReportIdJob implements SimpleJob { ...@@ -48,7 +49,12 @@ public class AmazonAdGenerateReportIdJob implements SimpleJob {
// .stream() // .stream()
// .filter(dcBaseCompanyAccount -> dcBaseCompanyAccount.getAccountId() == 671) // .filter(dcBaseCompanyAccount -> dcBaseCompanyAccount.getAccountId() == 671)
.forEach(dcBaseCompanyAccount -> { .forEach(dcBaseCompanyAccount -> {
//productAds
try { try {
// LocalDateTime reportDate = LocalDateTime.of(2020, 8, 30, 0, 0);
LocalDateTime reportDate = LocalDateTime.now().minusDays(1).minusHours(12); LocalDateTime reportDate = LocalDateTime.now().minusDays(1).minusHours(12);
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("reportDate", reportDate.format(DateTimeFormatter.ofPattern("yyyyMMdd"))); jsonObject.put("reportDate", reportDate.format(DateTimeFormatter.ofPattern("yyyyMMdd")));
...@@ -78,7 +84,9 @@ public class AmazonAdGenerateReportIdJob implements SimpleJob { ...@@ -78,7 +84,9 @@ public class AmazonAdGenerateReportIdJob implements SimpleJob {
JobAmazonAdLog jobAmazonAdLog = jobAmazonAdLogMapper.selectOneByExample(JobAmazonAdLogExample JobAmazonAdLog jobAmazonAdLog = jobAmazonAdLogMapper.selectOneByExample(JobAmazonAdLogExample
.newAndCreateCriteria() .newAndCreateCriteria()
.andAccountIdEqualTo(dcBaseCompanyAccount.getAccountId()) .andAccountIdEqualTo(dcBaseCompanyAccount.getAccountId())
.andCompanyIdEqualTo(dcBaseCompanyAccount.getCompanyId())
.andReportDateEqualTo(reportDate.toLocalDate()) .andReportDateEqualTo(reportDate.toLocalDate())
.andTypeEqualTo(1)
.example()); .example());
if (jobAmazonAdLog == null) { if (jobAmazonAdLog == null) {
...@@ -113,6 +121,70 @@ public class AmazonAdGenerateReportIdJob implements SimpleJob { ...@@ -113,6 +121,70 @@ public class AmazonAdGenerateReportIdJob implements SimpleJob {
log.error(ex.getMessage(), ex); log.error(ex.getMessage(), ex);
log.error("帐号id :{} 下载报告失败", dcBaseCompanyAccount.getAccountId()); log.error("帐号id :{} 下载报告失败", dcBaseCompanyAccount.getAccountId());
} }
//display
try {
AmazonAdAuth amazonAdAuth = JSON.parseObject(dcBaseCompanyAccount.getAmazonAdAuthJson(), AmazonAdAuth.class);
LocalDateTime reportDate = LocalDateTime.now().minusDays(1).minusHours(12);
JSONObject jsonObject = new JSONObject();
jsonObject.put("reportDate", reportDate.format(DateTimeFormatter.ofPattern("yyyyMMdd")));
jsonObject.put("metrics", "campaignName,campaignId,impressions,adGroupId,adGroupName,asin,sku,adId,clicks,cost,currency,attributedConversions1d,attributedConversions7d,attributedConversions14d,attributedConversions30d,attributedConversions1dSameSKU,attributedConversions7dSameSKU,attributedConversions14dSameSKU,attributedConversions30dSameSKU,attributedUnitsOrdered1d,attributedUnitsOrdered7d,attributedUnitsOrdered14d,attributedUnitsOrdered30d,attributedSales1d,attributedSales7d,attributedSales14d,attributedSales30d,attributedSales1dSameSKU,attributedSales7dSameSKU,attributedSales14dSameSKU,attributedSales30dSameSKU");
;
MediaType mediaType = MediaType.parse("application/json");
Response response;
RequestBody body = RequestBody.create(mediaType, jsonObject.toJSONString());
Request request = new Request.Builder()
.url(AmazonURI.getAmazonAdSiteUri(dcBaseCompanyAccount.getSiteEn()).toString() + "/sd/productAds/report")
.post(body)
.addHeader("Authorization", amazonAdAuth.getAccessToken())
.addHeader("Amazon-Advertising-API-ClientId", amazonAdAuth.getClientId())
.addHeader("Amazon-Advertising-API-Scope", amazonAdAuth.getProfileId())
.addHeader("Content-Type", "application/json")
.build();
response = client.newCall(request).execute();
String string = response.body().string();
if (response.isSuccessful()) {
AmazonAdSuccessResult reportResp = JSON.parseObject(string, AmazonAdSuccessResult.class);
JobAmazonAdLog jobAmazonAdLog = jobAmazonAdLogMapper.selectOneByExample(JobAmazonAdLogExample
.newAndCreateCriteria()
.andAccountIdEqualTo(dcBaseCompanyAccount.getAccountId())
.andCompanyIdEqualTo(dcBaseCompanyAccount.getCompanyId())
.andReportDateEqualTo(reportDate.toLocalDate())
.andTypeEqualTo(4)
.example());
if (jobAmazonAdLog == null) {
jobAmazonAdLog = new JobAmazonAdLog();
jobAmazonAdLog.setAccountId(dcBaseCompanyAccount.getAccountId());
jobAmazonAdLog.setCompanyId(dcBaseCompanyAccount.getCompanyId());
jobAmazonAdLog.setBjCreate(LocalDateTime.now());
jobAmazonAdLog.setBjModified(LocalDateTime.now());
jobAmazonAdLog.setReportDate(reportDate.toLocalDate());
jobAmazonAdLog.setType(4);
jobAmazonAdLog.setSiteEn(dcBaseCompanyAccount.getSiteEn());
jobAmazonAdLog.setReportId(reportResp.getReportId());
jobAmazonAdLog.setStatus(false);
jobAmazonAdLogMapper.insert(jobAmazonAdLog);
} else {
jobAmazonAdLog.setStatus(false);
jobAmazonAdLog.setReportId(reportResp.getReportId());
jobAmazonAdLogMapper.updateByPrimaryKeySelective(jobAmazonAdLog);
}
} else {
log.error(JSON.toJSONString(response));
throw new RuntimeException("生成报告失败");
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}); });
} }
......
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
and (t4.config_id = t5.id or t5.id not in (select config_id and (t4.config_id = t5.id or t5.id not in (select config_id
from dc_auto_sales_forecast_product_code_config from dc_auto_sales_forecast_product_code_config
where product_code = t1.product_code)) where product_code = t1.product_code))
and (t6.warehouse_code = t5.wareListenerContainerhouse_code or length(trim(t5.warehouse_code)) = 0) and (t6.warehouse_code = t5.warehouse_code or length(trim(t5.warehouse_code)) = 0)
and (t6.hq_type = t5.warehouse_type or length(trim(t5.warehouse_type)) = 0) and (t6.hq_type = t5.warehouse_type or length(trim(t5.warehouse_type)) = 0)
and (t2.product_type = t5.category or length(trim(t5.category)) = 0) and (t2.product_type = t5.category or length(trim(t5.category)) = 0)
and (t6.area_id = t5.warehouse_area_id or length(trim(t5.warehouse_area_id)) = 0) and (t6.area_id = t5.warehouse_area_id or length(trim(t5.warehouse_area_id)) = 0)
......
...@@ -6,16 +6,16 @@ ...@@ -6,16 +6,16 @@
WARNING - @mbg.generated WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify. This element is automatically generated by MyBatis Generator, do not modify.
--> -->
<id column="id" jdbcType="INTEGER" property="id" /> <id column="id" jdbcType="INTEGER" property="id"/>
<result column="account_id" jdbcType="INTEGER" property="accountId" /> <result column="account_id" jdbcType="INTEGER" property="accountId"/>
<result column="report_id" jdbcType="VARCHAR" property="reportId" /> <result column="report_id" jdbcType="VARCHAR" property="reportId"/>
<result column="report_date" jdbcType="DATE" property="reportDate" /> <result column="report_date" jdbcType="DATE" property="reportDate"/>
<result column="status" jdbcType="BIT" property="status" /> <result column="status" jdbcType="BIT" property="status"/>
<result column="bj_create" jdbcType="TIMESTAMP" property="bjCreate" /> <result column="bj_create" jdbcType="TIMESTAMP" property="bjCreate"/>
<result column="bj_modified" jdbcType="TIMESTAMP" property="bjModified" /> <result column="bj_modified" jdbcType="TIMESTAMP" property="bjModified"/>
<result column="site_en" jdbcType="VARCHAR" property="siteEn" /> <result column="site_en" jdbcType="VARCHAR" property="siteEn"/>
<result column="company_id" jdbcType="INTEGER" property="companyId" /> <result column="company_id" jdbcType="INTEGER" property="companyId"/>
<result column="type" jdbcType="INTEGER" property="type" /> <result column="type" jdbcType="INTEGER" property="type"/>
</resultMap> </resultMap>
<sql id="Example_Where_Clause"> <sql id="Example_Where_Clause">
<!-- <!--
...@@ -39,7 +39,8 @@ ...@@ -39,7 +39,8 @@
</when> </when>
<when test="criterion.listValue"> <when test="criterion.listValue">
and ${criterion.condition} and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=","> <foreach close=")" collection="criterion.value" item="listItem" open="("
separator=",">
#{listItem} #{listItem}
</foreach> </foreach>
</when> </when>
...@@ -72,7 +73,8 @@ ...@@ -72,7 +73,8 @@
</when> </when>
<when test="criterion.listValue"> <when test="criterion.listValue">
and ${criterion.condition} and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=","> <foreach close=")" collection="criterion.value" item="listItem" open="("
separator=",">
#{listItem} #{listItem}
</foreach> </foreach>
</when> </when>
...@@ -91,7 +93,8 @@ ...@@ -91,7 +93,8 @@
id, account_id, report_id, report_date, status, bj_create, bj_modified, site_en, id, account_id, report_id, report_date, status, bj_create, bj_modified, site_en,
company_id, type company_id, type
</sql> </sql>
<select id="selectByExample" parameterType="com.bailuntec.domain.example.JobAmazonAdLogExample" resultMap="BaseResultMap"> <select id="selectByExample" parameterType="com.bailuntec.domain.example.JobAmazonAdLogExample"
resultMap="BaseResultMap">
<!-- <!--
WARNING - @mbg.generated WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify. This element is automatically generated by MyBatis Generator, do not modify.
...@@ -100,10 +103,10 @@ ...@@ -100,10 +103,10 @@
<if test="distinct"> <if test="distinct">
distinct distinct
</if> </if>
<include refid="Base_Column_List" /> <include refid="Base_Column_List"/>
from job_amazon_ad_log from job_amazon_ad_log
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Example_Where_Clause" /> <include refid="Example_Where_Clause"/>
</if> </if>
<if test="orderByClause != null"> <if test="orderByClause != null">
order by ${orderByClause} order by ${orderByClause}
...@@ -123,7 +126,7 @@ ...@@ -123,7 +126,7 @@
This element is automatically generated by MyBatis Generator, do not modify. This element is automatically generated by MyBatis Generator, do not modify.
--> -->
select select
<include refid="Base_Column_List" /> <include refid="Base_Column_List"/>
from job_amazon_ad_log from job_amazon_ad_log
where id = #{id,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}
</select> </select>
...@@ -142,7 +145,7 @@ ...@@ -142,7 +145,7 @@
--> -->
delete from job_amazon_ad_log delete from job_amazon_ad_log
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Example_Where_Clause" /> <include refid="Example_Where_Clause"/>
</if> </if>
</delete> </delete>
<insert id="insert" parameterType="com.bailuntec.domain.entity.JobAmazonAdLog"> <insert id="insert" parameterType="com.bailuntec.domain.entity.JobAmazonAdLog">
...@@ -230,14 +233,15 @@ ...@@ -230,14 +233,15 @@
</if> </if>
</trim> </trim>
</insert> </insert>
<select id="countByExample" parameterType="com.bailuntec.domain.example.JobAmazonAdLogExample" resultType="java.lang.Long"> <select id="countByExample" parameterType="com.bailuntec.domain.example.JobAmazonAdLogExample"
resultType="java.lang.Long">
<!-- <!--
WARNING - @mbg.generated WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify. This element is automatically generated by MyBatis Generator, do not modify.
--> -->
select count(*) from job_amazon_ad_log select count(*) from job_amazon_ad_log
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Example_Where_Clause" /> <include refid="Example_Where_Clause"/>
</if> </if>
</select> </select>
<update id="updateByExampleSelective" parameterType="map"> <update id="updateByExampleSelective" parameterType="map">
...@@ -279,7 +283,7 @@ ...@@ -279,7 +283,7 @@
</if> </if>
</set> </set>
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" /> <include refid="Update_By_Example_Where_Clause"/>
</if> </if>
</update> </update>
<update id="updateByExample" parameterType="map"> <update id="updateByExample" parameterType="map">
...@@ -299,7 +303,7 @@ ...@@ -299,7 +303,7 @@
company_id = #{record.companyId,jdbcType=INTEGER}, company_id = #{record.companyId,jdbcType=INTEGER},
type = #{record.type,jdbcType=INTEGER} type = #{record.type,jdbcType=INTEGER}
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" /> <include refid="Update_By_Example_Where_Clause"/>
</if> </if>
</update> </update>
<update id="updateByPrimaryKeySelective" parameterType="com.bailuntec.domain.entity.JobAmazonAdLog"> <update id="updateByPrimaryKeySelective" parameterType="com.bailuntec.domain.entity.JobAmazonAdLog">
...@@ -488,17 +492,18 @@ ...@@ -488,17 +492,18 @@
company_id = #{companyId,jdbcType=INTEGER}, company_id = #{companyId,jdbcType=INTEGER},
type = #{type,jdbcType=INTEGER} type = #{type,jdbcType=INTEGER}
</insert> </insert>
<select id="selectOneByExample" parameterType="com.bailuntec.domain.example.JobAmazonAdLogExample" resultMap="BaseResultMap"> <select id="selectOneByExample" parameterType="com.bailuntec.domain.example.JobAmazonAdLogExample"
resultMap="BaseResultMap">
<!-- <!--
WARNING - @mbg.generated WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify. This element is automatically generated by MyBatis Generator, do not modify.
@project https://github.com/itfsw/mybatis-generator-plugin @project https://github.com/itfsw/mybatis-generator-plugin
--> -->
select select
<include refid="Base_Column_List" /> <include refid="Base_Column_List"/>
from job_amazon_ad_log from job_amazon_ad_log
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Example_Where_Clause" /> <include refid="Example_Where_Clause"/>
</if> </if>
<if test="orderByClause != null"> <if test="orderByClause != null">
order by ${orderByClause} order by ${orderByClause}
...@@ -514,6 +519,5 @@ ...@@ -514,6 +519,5 @@
and bj_create &lt; #{localDateTime} and bj_create &lt; #{localDateTime}
and id % #{shardingContext.shardingTotalCount} = #{shardingContext.shardingItem} and id % #{shardingContext.shardingTotalCount} = #{shardingContext.shardingItem}
order by bj_modified desc order by bj_modified desc
limit 60
</select> </select>
</mapper> </mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment