|
@@ -169,12 +169,8 @@ public class BatchServiceImpl implements IBatchService {
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public JSONObject createUnit(JSONObject requestJson) throws Exception {
|
|
|
- Long accountId = requestJson.getLong("accountId");
|
|
|
- CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
|
|
|
- if (Check.isNull(oauthToken)) {
|
|
|
- throw new Exception("未获取到账户信息");
|
|
|
- }
|
|
|
+ public JSONObject createUnit(JSONObject requestJson, CtopOauthToken oauthToken) throws Exception {
|
|
|
+
|
|
|
|
|
|
JSONObject unitJson = new JSONObject();
|
|
|
|
|
@@ -408,7 +404,7 @@ public class BatchServiceImpl implements IBatchService {
|
|
|
unitJson.put("unit_name", unitName);
|
|
|
}
|
|
|
|
|
|
- Map<String, Object> returnUnitMap = kuaishouInterfaceService.adUnitCreate(oauthToken.getAccessToken(), accountId, unitJson);
|
|
|
+ Map<String, Object> returnUnitMap = kuaishouInterfaceService.adUnitCreate(oauthToken.getAccessToken(), oauthToken.getAccountId(), unitJson);
|
|
|
if (!Check.isNullMap(returnUnitMap)) {
|
|
|
Integer code = (Integer) returnUnitMap.get("code");
|
|
|
if (code == 0) {
|
|
@@ -428,7 +424,7 @@ public class BatchServiceImpl implements IBatchService {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
try {
|
|
|
- copyCreative(accountId, unitId, copyUnitId);
|
|
|
+ copyCreative(oauthToken.getAccountId(), unitId, copyUnitId);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
@@ -465,14 +461,9 @@ public class BatchServiceImpl implements IBatchService {
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public JSONObject copyUnit(KuaiShouGroup group, Long copyToCampaignId) {
|
|
|
+ public JSONObject copyUnit(KuaiShouGroup group, Long copyToCampaignId, CtopOauthToken oauthToken) {
|
|
|
JSONObject returnJson = new JSONObject();
|
|
|
try {
|
|
|
- CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(group.getAccountId());
|
|
|
- if (Check.isNull(oauthToken)) {
|
|
|
- throw new Exception("未获取到token信息");
|
|
|
- }
|
|
|
-
|
|
|
JSONObject unitJson = new JSONObject();
|
|
|
unitJson.put("campaign_id", copyToCampaignId);
|
|
|
|
|
@@ -1002,186 +993,202 @@ public class BatchServiceImpl implements IBatchService {
|
|
|
*/
|
|
|
@Override
|
|
|
public JSONObject updateUnit(JSONObject requestJson, CtopOauthToken token) throws Exception {
|
|
|
+ JSONObject returnJson = new JSONObject();
|
|
|
+ try {
|
|
|
|
|
|
- JSONObject unitJson = new JSONObject();
|
|
|
- unitJson.put("advertiser_id", token.getAccountId());
|
|
|
-
|
|
|
- Long unitId = requestJson.getLong("unitId");
|
|
|
- if (Check.isNull(unitId)) {
|
|
|
- throw new Exception("请选择广告组");
|
|
|
- }
|
|
|
+ JSONObject unitJson = new JSONObject();
|
|
|
+ unitJson.put("advertiser_id", token.getAccountId());
|
|
|
|
|
|
- unitJson.put("unit_id", unitId);
|
|
|
- // 广告组名称
|
|
|
- if (!Check.isNull(requestJson.getString("unitName"))) {
|
|
|
- unitJson.put("unit_name", requestJson.getString("unitName"));
|
|
|
- }
|
|
|
- // 出价
|
|
|
- if (!Check.isNull(requestJson.getLong("bid"))) {
|
|
|
- unitJson.put("bid", requestJson.getLong("bid"));
|
|
|
- }
|
|
|
- // 深度转化出价
|
|
|
- if (!Check.isNull(requestJson.getLong("cpaBid"))) {
|
|
|
- unitJson.put("cpa_bid", requestJson.getLong("cpaBid"));
|
|
|
- }
|
|
|
- // 深度转化目标出价
|
|
|
- if (!Check.isNull(requestJson.getLong("deepConversionBid"))) {
|
|
|
- unitJson.put("deep_conversion_bid", requestJson.getLong("deepConversionBid"));
|
|
|
- }
|
|
|
- //投放开始时间
|
|
|
- if (!Check.isNull(requestJson.getString("beginTime"))) {
|
|
|
+ Long unitId = requestJson.getLong("unitId");
|
|
|
+ if (Check.isNull(unitId)) {
|
|
|
+ throw new Exception("请选择广告组");
|
|
|
+ }
|
|
|
|
|
|
- String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
|
|
|
- boolean beginTimeBoolean = DateUtils.compare(requestJson.getString("beginTime"), nowDate);
|
|
|
- if (beginTimeBoolean) {
|
|
|
- unitJson.put("begin_time", nowDate);
|
|
|
- } else {
|
|
|
- unitJson.put("begin_time", requestJson.getString("beginTime"));
|
|
|
+ unitJson.put("unit_id", unitId);
|
|
|
+ // 广告组名称
|
|
|
+ if (!Check.isNull(requestJson.getString("unitName"))) {
|
|
|
+ unitJson.put("unit_name", requestJson.getString("unitName"));
|
|
|
+ }
|
|
|
+ // 出价
|
|
|
+ if (!Check.isNull(requestJson.getLong("bid"))) {
|
|
|
+ unitJson.put("bid", requestJson.getLong("bid"));
|
|
|
+ }
|
|
|
+ // 深度转化出价
|
|
|
+ if (!Check.isNull(requestJson.getLong("cpaBid"))) {
|
|
|
+ unitJson.put("cpa_bid", requestJson.getLong("cpaBid"));
|
|
|
+ }
|
|
|
+ // 深度转化目标出价
|
|
|
+ if (!Check.isNull(requestJson.getLong("deepConversionBid"))) {
|
|
|
+ unitJson.put("deep_conversion_bid", requestJson.getLong("deepConversionBid"));
|
|
|
}
|
|
|
+ //投放开始时间
|
|
|
+ if (!Check.isNull(requestJson.getString("beginTime"))) {
|
|
|
|
|
|
+ String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
|
|
|
+ boolean beginTimeBoolean = DateUtils.compare(requestJson.getString("beginTime"), nowDate);
|
|
|
+ if (beginTimeBoolean) {
|
|
|
+ unitJson.put("begin_time", nowDate);
|
|
|
+ } else {
|
|
|
+ unitJson.put("begin_time", requestJson.getString("beginTime"));
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
- // 投放结束时间
|
|
|
- if (!Check.isNull(requestJson.getString("endTime"))) {
|
|
|
- unitJson.put("end_time", requestJson.getString("endTime"));
|
|
|
- }
|
|
|
- // 投放时间段
|
|
|
- if (!Check.isNull(requestJson.getString("scheduleTime"))) {
|
|
|
- unitJson.put("schedule_time", requestJson.getString("scheduleTime"));
|
|
|
- }
|
|
|
- // 广告组单日预算
|
|
|
- if (!Check.isNull(requestJson.getLong("dayBudget"))) {
|
|
|
- unitJson.put("day_budget", requestJson.getLong("dayBudget"));
|
|
|
- }
|
|
|
- // url类型
|
|
|
- if (!Check.isNull(requestJson.getInteger("urlType"))) {
|
|
|
- unitJson.put("url_type", requestJson.getInteger("urlType"));
|
|
|
- }
|
|
|
- // url
|
|
|
- if (!Check.isNull(requestJson.getString("url"))) {
|
|
|
- unitJson.put("url", requestJson.getString("url"));
|
|
|
- }
|
|
|
- // appId
|
|
|
- if (!Check.isNull(requestJson.getLong("appId"))) {
|
|
|
- unitJson.put("app_id", requestJson.getLong("appId"));
|
|
|
- }
|
|
|
|
|
|
- // 创意展现方式
|
|
|
- if (!Check.isNull(requestJson.getInteger("showMode"))) {
|
|
|
- unitJson.put("show_mode", requestJson.getInteger("showMode"));
|
|
|
- }
|
|
|
- //投放方式
|
|
|
- if (!Check.isNull(requestJson.getInteger("speed"))) {
|
|
|
- unitJson.put("speed", requestJson.getInteger("speed"));
|
|
|
- }
|
|
|
+ }
|
|
|
+ // 投放结束时间
|
|
|
+ if (!Check.isNull(requestJson.getString("endTime"))) {
|
|
|
+ unitJson.put("end_time", requestJson.getString("endTime"));
|
|
|
+ }
|
|
|
+ // 投放时间段
|
|
|
+ if (!Check.isNull(requestJson.getString("scheduleTime"))) {
|
|
|
+ unitJson.put("schedule_time", requestJson.getString("scheduleTime"));
|
|
|
+ }
|
|
|
+ // 广告组单日预算
|
|
|
+ if (!Check.isNull(requestJson.getLong("dayBudget"))) {
|
|
|
+ unitJson.put("day_budget", requestJson.getLong("dayBudget"));
|
|
|
+ }
|
|
|
+ // url类型
|
|
|
+ if (!Check.isNull(requestJson.getInteger("urlType"))) {
|
|
|
+ unitJson.put("url_type", requestJson.getInteger("urlType"));
|
|
|
+ }
|
|
|
+ // url
|
|
|
+ if (!Check.isNull(requestJson.getString("url"))) {
|
|
|
+ unitJson.put("url", requestJson.getString("url"));
|
|
|
+ }
|
|
|
+ // appId
|
|
|
+ if (!Check.isNull(requestJson.getLong("appId"))) {
|
|
|
+ unitJson.put("app_id", requestJson.getLong("appId"));
|
|
|
+ }
|
|
|
|
|
|
+ // 创意展现方式
|
|
|
+ if (!Check.isNull(requestJson.getInteger("showMode"))) {
|
|
|
+ unitJson.put("show_mode", requestJson.getInteger("showMode"));
|
|
|
+ }
|
|
|
+ //投放方式
|
|
|
+ if (!Check.isNull(requestJson.getInteger("speed"))) {
|
|
|
+ unitJson.put("speed", requestJson.getInteger("speed"));
|
|
|
+ }
|
|
|
|
|
|
- // -----------------用户定向-----------
|
|
|
- JSONObject targetJson = new JSONObject();
|
|
|
+ // 优先从系统应用商店下载
|
|
|
+ if (!Check.isNull(requestJson.getInteger("useAppMarket"))) {
|
|
|
+ unitJson.put("use_app_market", requestJson.getInteger("useAppMarket"));
|
|
|
+ }
|
|
|
+ // 转化目标
|
|
|
+ if (!Check.isNull(requestJson.getInteger("convertId"))) {
|
|
|
+ unitJson.put("convert_id", requestJson.getInteger("convertId"));
|
|
|
+ }
|
|
|
|
|
|
- // 地域
|
|
|
- if (!Check.isNull(requestJson.getJSONArray("region"))) {
|
|
|
- targetJson.put("region", requestJson.getJSONArray("region"));
|
|
|
- }
|
|
|
|
|
|
- // 自定义年龄段
|
|
|
- JSONArray ageArr = requestJson.getJSONArray("age");
|
|
|
- if (!Check.isNull(ageArr)) {
|
|
|
- JSONObject ageJson = new JSONObject();
|
|
|
- ageJson.put("min", ageArr.get(0));
|
|
|
- ageJson.put("max", ageArr.get(1));
|
|
|
- targetJson.put("age", ageJson);
|
|
|
- }
|
|
|
- // 固定年龄段
|
|
|
- if (!Check.isNull(requestJson.getJSONArray("agesRange"))) {
|
|
|
- targetJson.put("ages_range", requestJson.getJSONArray("agesRange"));
|
|
|
- }
|
|
|
- // 性别
|
|
|
- if (!Check.isNull(requestJson.getInteger("gender"))) {
|
|
|
- targetJson.put("gender", requestJson.getInteger("gender"));
|
|
|
- }
|
|
|
- //操作系统
|
|
|
- if (!Check.isNull(requestJson.getInteger("platformOs"))) {
|
|
|
- targetJson.put("platform_os", requestJson.getInteger("platformOs"));
|
|
|
- }
|
|
|
- //Android版本
|
|
|
- if (!Check.isNull(requestJson.getInteger("androidOsv"))) {
|
|
|
- targetJson.put("android_osv", requestJson.getInteger("androidOsv"));
|
|
|
- }
|
|
|
- // iOS版本
|
|
|
- if (!Check.isNull(requestJson.getInteger("iosOsv"))) {
|
|
|
- targetJson.put("ios_osv", requestJson.getInteger("iosOsv"));
|
|
|
- }
|
|
|
- //网络环境
|
|
|
- if (!Check.isNull(requestJson.getInteger("network"))) {
|
|
|
- targetJson.put("network", requestJson.getInteger("network"));
|
|
|
- }
|
|
|
- //设备品牌
|
|
|
- if (!Check.isNull(requestJson.getJSONArray("deviceBrand"))) {
|
|
|
- targetJson.put("device_brand", requestJson.getJSONArray("deviceBrand"));
|
|
|
- }
|
|
|
- //设备价格
|
|
|
- if (!Check.isNull(requestJson.getJSONArray("devicePrice"))) {
|
|
|
- targetJson.put("device_price", requestJson.getJSONArray("devicePrice"));
|
|
|
- }
|
|
|
- //商业兴趣类型
|
|
|
- if (!Check.isNull(requestJson.getInteger("businessInterestType"))) {
|
|
|
- targetJson.put("business_interest_type", requestJson.getInteger("businessInterestType"));
|
|
|
- }
|
|
|
- // 商业兴趣
|
|
|
- if (!Check.isNull(requestJson.getJSONArray("businessInterest"))) {
|
|
|
- targetJson.put("business_interest", requestJson.getJSONArray("businessInterest"));
|
|
|
- }
|
|
|
- //网红粉丝
|
|
|
- if (!Check.isNull(requestJson.getJSONArray("fansStar"))) {
|
|
|
- targetJson.put("fans_star", requestJson.getJSONArray("fansStar"));
|
|
|
- }
|
|
|
- //兴趣视频用户
|
|
|
- if (!Check.isNull(requestJson.getJSONArray("interestVideo"))) {
|
|
|
- targetJson.put("interest_video", requestJson.getJSONArray("interestVideo"));
|
|
|
- }
|
|
|
- // APP行为-按分类
|
|
|
- if (!Check.isNull(requestJson.getJSONArray("appInterest"))) {
|
|
|
- targetJson.put("app_interest", requestJson.getJSONArray("appInterest"));
|
|
|
- }
|
|
|
- // APP行为-按APP名称
|
|
|
- if (!Check.isNull(requestJson.getJSONArray("appIds"))) {
|
|
|
- targetJson.put("app_ids", requestJson.getJSONArray("appIds"));
|
|
|
- }
|
|
|
- // 人群包定向
|
|
|
- if (!Check.isNull(requestJson.getJSONArray("population"))) {
|
|
|
- targetJson.put("population", requestJson.getJSONArray("population"));
|
|
|
- }
|
|
|
- // 人群包排除
|
|
|
- if (!Check.isNull(requestJson.getJSONArray("excludePopulation"))) {
|
|
|
- targetJson.put("exclude_population", requestJson.getJSONArray("excludePopulation"));
|
|
|
- }
|
|
|
+ // -----------------用户定向-----------
|
|
|
+ JSONObject targetJson = new JSONObject();
|
|
|
|
|
|
- JSONObject intelliExtendJson = new JSONObject();
|
|
|
+ // 地域
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("region"))) {
|
|
|
+ targetJson.put("region", requestJson.getJSONArray("region"));
|
|
|
+ }
|
|
|
|
|
|
- // 开启智能扩量
|
|
|
- if (!Check.isNull(requestJson.getInteger("isOpen"))) {
|
|
|
- intelliExtendJson.put("is_open", requestJson.getInteger("isOpen"));
|
|
|
- }
|
|
|
- //不可突破年龄
|
|
|
- if (!Check.isNull(requestJson.getInteger("noAgeBreak"))) {
|
|
|
- intelliExtendJson.put("no_age_break", requestJson.getInteger("noAgeBreak"));
|
|
|
- }
|
|
|
- //不可突破性别
|
|
|
- if (!Check.isNull(requestJson.getInteger("noGenderBreak"))) {
|
|
|
- intelliExtendJson.put("no_gender_break", requestJson.getInteger("noGenderBreak"));
|
|
|
- }
|
|
|
- // 不可突破地域
|
|
|
- if (!Check.isNull(requestJson.getInteger("noAreaBreak"))) {
|
|
|
- intelliExtendJson.put("no_area_break", requestJson.getInteger("noAreaBreak"));
|
|
|
- }
|
|
|
- if (!Check.isNull(intelliExtendJson)) {
|
|
|
- targetJson.put("intelli_extend", intelliExtendJson);
|
|
|
- }
|
|
|
+ // 自定义年龄段
|
|
|
+ JSONArray ageArr = requestJson.getJSONArray("age");
|
|
|
+ if (!Check.isNull(ageArr)) {
|
|
|
+ JSONObject ageJson = new JSONObject();
|
|
|
+ ageJson.put("min", ageArr.get(0));
|
|
|
+ ageJson.put("max", ageArr.get(1));
|
|
|
+ targetJson.put("age", ageJson);
|
|
|
+ }
|
|
|
+ // 固定年龄段
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("agesRange"))) {
|
|
|
+ targetJson.put("ages_range", requestJson.getJSONArray("agesRange"));
|
|
|
+ }
|
|
|
+ // 性别
|
|
|
+ if (!Check.isNull(requestJson.getInteger("gender"))) {
|
|
|
+ targetJson.put("gender", requestJson.getInteger("gender"));
|
|
|
+ }
|
|
|
+ //操作系统
|
|
|
+ if (!Check.isNull(requestJson.getInteger("platformOs"))) {
|
|
|
+ targetJson.put("platform_os", requestJson.getInteger("platformOs"));
|
|
|
+ }
|
|
|
+ //Android版本
|
|
|
+ if (!Check.isNull(requestJson.getInteger("androidOsv"))) {
|
|
|
+ targetJson.put("android_osv", requestJson.getInteger("androidOsv"));
|
|
|
+ }
|
|
|
+ // iOS版本
|
|
|
+ if (!Check.isNull(requestJson.getInteger("iosOsv"))) {
|
|
|
+ targetJson.put("ios_osv", requestJson.getInteger("iosOsv"));
|
|
|
+ }
|
|
|
+ //网络环境
|
|
|
+ if (!Check.isNull(requestJson.getInteger("network"))) {
|
|
|
+ targetJson.put("network", requestJson.getInteger("network"));
|
|
|
+ }
|
|
|
+ //设备品牌
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("deviceBrand"))) {
|
|
|
+ targetJson.put("device_brand", requestJson.getJSONArray("deviceBrand"));
|
|
|
+ }
|
|
|
+ //设备价格
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("devicePrice"))) {
|
|
|
+ targetJson.put("device_price", requestJson.getJSONArray("devicePrice"));
|
|
|
+ }
|
|
|
+ //商业兴趣类型
|
|
|
+ if (!Check.isNull(requestJson.getInteger("businessInterestType"))) {
|
|
|
+ targetJson.put("business_interest_type", requestJson.getInteger("businessInterestType"));
|
|
|
+ }
|
|
|
+ // 商业兴趣
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("businessInterest"))) {
|
|
|
+ targetJson.put("business_interest", requestJson.getJSONArray("businessInterest"));
|
|
|
+ }
|
|
|
+ //网红粉丝
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("fansStar"))) {
|
|
|
+ targetJson.put("fans_star", requestJson.getJSONArray("fansStar"));
|
|
|
+ }
|
|
|
+ //兴趣视频用户
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("interestVideo"))) {
|
|
|
+ targetJson.put("interest_video", requestJson.getJSONArray("interestVideo"));
|
|
|
+ }
|
|
|
+ // APP行为-按分类
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("appInterest"))) {
|
|
|
+ targetJson.put("app_interest", requestJson.getJSONArray("appInterest"));
|
|
|
+ }
|
|
|
+ // APP行为-按APP名称
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("appIds"))) {
|
|
|
+ targetJson.put("app_ids", requestJson.getJSONArray("appIds"));
|
|
|
+ }
|
|
|
+ // 人群包定向
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("population"))) {
|
|
|
+ targetJson.put("population", requestJson.getJSONArray("population"));
|
|
|
+ }
|
|
|
+ // 人群包排除
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("excludePopulation"))) {
|
|
|
+ targetJson.put("exclude_population", requestJson.getJSONArray("excludePopulation"));
|
|
|
+ }
|
|
|
|
|
|
- unitJson.put("target", targetJson);
|
|
|
+ JSONObject intelliExtendJson = new JSONObject();
|
|
|
|
|
|
- JSONObject returnJson = updateService.updateUnit(token.getAccessToken(), unitJson);
|
|
|
+ // 开启智能扩量
|
|
|
+ if (!Check.isNull(requestJson.getInteger("isOpen"))) {
|
|
|
+ intelliExtendJson.put("is_open", requestJson.getInteger("isOpen"));
|
|
|
+ }
|
|
|
+ //不可突破年龄
|
|
|
+ if (!Check.isNull(requestJson.getInteger("noAgeBreak"))) {
|
|
|
+ intelliExtendJson.put("no_age_break", requestJson.getInteger("noAgeBreak"));
|
|
|
+ }
|
|
|
+ //不可突破性别
|
|
|
+ if (!Check.isNull(requestJson.getInteger("noGenderBreak"))) {
|
|
|
+ intelliExtendJson.put("no_gender_break", requestJson.getInteger("noGenderBreak"));
|
|
|
+ }
|
|
|
+ // 不可突破地域
|
|
|
+ if (!Check.isNull(requestJson.getInteger("noAreaBreak"))) {
|
|
|
+ intelliExtendJson.put("no_area_break", requestJson.getInteger("noAreaBreak"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(intelliExtendJson)) {
|
|
|
+ targetJson.put("intelli_extend", intelliExtendJson);
|
|
|
+ }
|
|
|
+
|
|
|
+ unitJson.put("target", targetJson);
|
|
|
+
|
|
|
+ returnJson = updateService.updateUnit(token.getAccessToken(), unitJson);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ returnJson.put("code", -1);
|
|
|
+ returnJson.put("message", e.getMessage());
|
|
|
+ }
|
|
|
return returnJson;
|
|
|
}
|
|
|
|