|
@@ -1,23 +1,32 @@
|
|
|
package cn.com.ctop.kuaishou.modules.batch.service.impl;
|
|
|
|
|
|
import cn.com.ctop.common.module.entity.CtopOauthToken;
|
|
|
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
|
|
|
import cn.com.ctop.common.module.utils.Check;
|
|
|
import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouImageGet;
|
|
|
import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouStrategy;
|
|
|
import cn.com.ctop.kuaishou.modules.batch.mapper.KuaishouStrategyMapper;
|
|
|
import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouImageGetService;
|
|
|
import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouMaterialUploadService;
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouUpdateService;
|
|
|
import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
|
|
|
import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouStrategyService;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.xxl.job.core.enums.NoEn;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.shiro.SecurityUtils;
|
|
|
+import org.jeecg.common.api.vo.Result;
|
|
|
+import org.jeecg.common.system.vo.LoginUser;
|
|
|
import org.jeecg.common.util.DateUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
@@ -27,6 +36,7 @@ import java.util.Map;
|
|
|
* @version V1.0
|
|
|
* @date 2020-12-10
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class KuaishouStrategyServiceImpl extends ServiceImpl<KuaishouStrategyMapper, KuaishouStrategy> implements IKuaishouStrategyService {
|
|
|
@Autowired
|
|
@@ -35,28 +45,127 @@ public class KuaishouStrategyServiceImpl extends ServiceImpl<KuaishouStrategyMap
|
|
|
private IKuaiShouImageGetService imageGetService;
|
|
|
@Autowired
|
|
|
private IKuaiShouMaterialUploadService uploadService;
|
|
|
+ @Autowired
|
|
|
+ private IKuaiShouUpdateService kuaiShouUpdateService;
|
|
|
+ @Autowired
|
|
|
+ private ICtopOauthTokenService tokenService;
|
|
|
+
|
|
|
+ //TODO
|
|
|
+ @Override
|
|
|
+ public Result<Object> shutDownPlan(JSONArray ids) {
|
|
|
+ LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
+ String userId = sysUser.getId();
|
|
|
+ for (Object id : ids) {
|
|
|
+ List<JSONObject> list = new ArrayList<>();
|
|
|
+ CtopOauthToken token = tokenService.getTokenByAccountId(list.get(0).getLong("accountId"));
|
|
|
+ for (JSONObject object : list) {
|
|
|
+ kuaiShouUpdateService.updateCampaignStatus(token.getAccessToken(), token.getAccountId(), object.getLong("campaignId"), NoEn.NO2.valueInt(), userId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* @param oauthToken token签名
|
|
|
- * @param strategy 策略对象
|
|
|
* @param groupJson 广告计划
|
|
|
* @return void
|
|
|
* @throws
|
|
|
* @author ZHAOXA
|
|
|
*/
|
|
|
- private void createGroupLevelStrategy(CtopOauthToken oauthToken, KuaishouStrategy strategy, JSONObject groupJson) throws Exception {
|
|
|
+ public Map<String, Object> createPlanLevelStrategy(CtopOauthToken oauthToken, JSONObject data) {
|
|
|
+ JSONObject planJson = new JSONObject();
|
|
|
+ /**计划类型
|
|
|
+ * 2: 提升应用安装
|
|
|
+ * 3:获取电商下单
|
|
|
+ * 4:推广品牌活动
|
|
|
+ * 5:收集销售线索
|
|
|
+ * 7:提高应用活跃
|
|
|
+ */
|
|
|
+ if (Check.isNull(data.getInteger("type"))) {
|
|
|
+ return getNullValueResult("广告组必填参数:type,计划类型为空");
|
|
|
+ } else {
|
|
|
+ planJson.put("type", data.getInteger("type"));
|
|
|
+ }
|
|
|
+ //单日预算金额
|
|
|
+ if (!Check.isNull(data.getLong("dayBudget"))) {
|
|
|
+ planJson.put("day_budget", data.getLong("dayBudget"));
|
|
|
+ }
|
|
|
+ //分日预算
|
|
|
+ if (!Check.isNull(data.getJSONArray("dayBudgetSchedule"))) {
|
|
|
+ planJson.put("day_budget_schedule", data.getJSONArray("dayBudgetSchedule"));
|
|
|
+ }
|
|
|
+ return kuaishouInterfaceService.campaignCreate(oauthToken.getAccessToken(), oauthToken.getAccountId(), planJson);
|
|
|
+ }
|
|
|
+
|
|
|
+ public JSONArray createGroupLevelStrategy(CtopOauthToken oauthToken, JSONObject data) {
|
|
|
+ JSONArray resultArr = new JSONArray();
|
|
|
+ JSONArray groupInfo = data.getJSONArray("groupInfo");
|
|
|
+ for (int i = 0; i < groupInfo.size(); i++) {
|
|
|
+ Map<String, Object> resutlGroupMap = new HashMap<>();
|
|
|
+ JSONObject groupJson = groupInfo.getJSONObject(i);
|
|
|
+ try {
|
|
|
+ resutlGroupMap = createGroupLevelAd(oauthToken, groupJson);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("unitName:{},根据策略创建广告组异常", groupJson.get("unitName"), e);
|
|
|
+ }
|
|
|
+ if (!Check.isNull(resutlGroupMap)) {
|
|
|
+ resutlGroupMap.put("unitName", groupJson.getString("unitName"));
|
|
|
+ if ((boolean) resutlGroupMap.get("success")) {
|
|
|
+ JSONArray creativeInfo = groupJson.getJSONArray("creativeInfo");
|
|
|
+ if (Check.isNull(creativeInfo)) {
|
|
|
+ resutlGroupMap.put("desc", "入参数据缺失创意级信息,仅创建计划成功");
|
|
|
+ } else {
|
|
|
+ JSONArray resultCretiveList = new JSONArray();
|
|
|
+ for (int j = 0; j < creativeInfo.size(); j++) {
|
|
|
+ Map<String, Object> creativeMap = new HashMap<>();
|
|
|
+ JSONObject creativeJson = creativeInfo.getJSONObject(i);
|
|
|
+ creativeMap.put("creativeName", creativeJson.getString("creativeName"));
|
|
|
+ creativeJson.put("unitId", resutlGroupMap.get("unitId"));
|
|
|
+ try {
|
|
|
+ creativeMap = createCreativeLevelStrategy(oauthToken, creativeJson);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("unitId:{},根据策略创建广告创意异常", resutlGroupMap.get("unitId"), e);
|
|
|
+ }
|
|
|
+ resultCretiveList.add(creativeMap);
|
|
|
+ }
|
|
|
+ resutlGroupMap.put("resultCretiveList", resultCretiveList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ resultArr.add(resutlGroupMap);
|
|
|
+ }
|
|
|
+ return resultArr;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据策略创建广告组
|
|
|
+ *
|
|
|
+ * @param oauthToken token签名
|
|
|
+ * @param groupJson 广告计划
|
|
|
+ * @return void
|
|
|
+ * @throws
|
|
|
+ * @author ZHAOXA
|
|
|
+ */
|
|
|
+ private Map<String, Object> createGroupLevelAd(CtopOauthToken oauthToken, JSONObject groupJson) throws Exception {
|
|
|
JSONObject unitJson = new JSONObject();
|
|
|
//广告计划ID
|
|
|
- if (!Check.isNull(groupJson.getString("campaignId"))) {
|
|
|
- unitJson.put("campaign_id", groupJson.getString("campaignId"));
|
|
|
+ if (!Check.isNull(groupJson.getLong("campaignId"))) {
|
|
|
+ unitJson.put("campaign_id", groupJson.getLong("campaignId"));
|
|
|
+ } else {
|
|
|
+ return getNullValueResult("广告组必填参数:campaign_id,广告计划ID为空");
|
|
|
}
|
|
|
//广告组名称
|
|
|
if (!Check.isNull(groupJson.getString("unitName"))) {
|
|
|
unitJson.put("unit_name", groupJson.getString("unitName"));
|
|
|
+ } else {
|
|
|
+ return getNullValueResult("广告组必填参数:unit_name,广告组名称为空");
|
|
|
}
|
|
|
// 优化目标出价类型
|
|
|
if (!Check.isNull(groupJson.getInteger("bidType"))) {
|
|
|
unitJson.put("bid_type", groupJson.getInteger("bidType"));
|
|
|
+ } else {
|
|
|
+ return getNullValueResult("广告组必填参数:bid_type,优化目标出价类型为空");
|
|
|
}
|
|
|
/* 资源位置
|
|
|
1:优选广告位
|
|
@@ -68,14 +177,20 @@ public class KuaishouStrategyServiceImpl extends ServiceImpl<KuaishouStrategyMap
|
|
|
Integer sceneId = groupJson.getJSONArray("sceneId").getInteger(0);
|
|
|
if (!Check.isNull(groupJson.getJSONArray("sceneId"))) {
|
|
|
unitJson.put("scene_id", groupJson.getJSONArray("sceneId"));
|
|
|
+ } else {
|
|
|
+ return getNullValueResult("广告组必填参数:scene_id,资源位置为空");
|
|
|
}
|
|
|
// 资源创作方式 4: 自定义;5:程序化创意 7:程序化创意2.0
|
|
|
if (!Check.isNull(groupJson.getInteger("unitType"))) {
|
|
|
unitJson.put("unit_type", groupJson.getInteger("unitType"));
|
|
|
+ } else {
|
|
|
+ return getNullValueResult("广告组必填参数:unit_type,资源创作方式为空");
|
|
|
}
|
|
|
- // 创意展现方式1 - 轮播 2 - 优选
|
|
|
+ // 创意展现方式 1-轮播 2-优选
|
|
|
if (!Check.isNull(groupJson.getInteger("showMode"))) {
|
|
|
unitJson.put("show_mode", groupJson.getInteger("showMode"));
|
|
|
+ } else {
|
|
|
+ return getNullValueResult("广告组必填参数:show_mode,创意展现方式为空");
|
|
|
}
|
|
|
/**
|
|
|
投放方式
|
|
@@ -85,51 +200,52 @@ public class KuaishouStrategyServiceImpl extends ServiceImpl<KuaishouStrategyMap
|
|
|
*/
|
|
|
if (!Check.isNull(groupJson.getInteger("speed"))) {
|
|
|
unitJson.put("speed", groupJson.getInteger("speed"));
|
|
|
+ } else {
|
|
|
+ return getNullValueResult("广告组必填参数:speed,投放方式为空");
|
|
|
}
|
|
|
-
|
|
|
// 封面点击出价
|
|
|
- if (!Check.isNull(strategy.getBid())) {
|
|
|
- unitJson.put("bid", strategy.getBid());
|
|
|
+ if (!Check.isNull(groupJson.getLong("bid"))) {
|
|
|
+ unitJson.put("bid", groupJson.getLong("bid"));
|
|
|
}
|
|
|
-
|
|
|
// 深度转化出价
|
|
|
- if (!Check.isNull(strategy.getCpaBid())) {
|
|
|
- unitJson.put("cpa_bid", strategy.getCpaBid());
|
|
|
+ if (!Check.isNull(groupJson.getLong("cpaBid"))) {
|
|
|
+ unitJson.put("cpa_bid", groupJson.getLong("cpaBid"));
|
|
|
}
|
|
|
// 深度转化目标出价
|
|
|
- if (!Check.isNull(strategy.getDeepConversionBid())) {
|
|
|
- unitJson.put("deep_conversion_bid", strategy.getDeepConversionBid());
|
|
|
+ if (!Check.isNull(groupJson.getLong("deepConversionBid"))) {
|
|
|
+ unitJson.put("deep_conversion_bid", groupJson.getLong("deepConversionBid"));
|
|
|
}
|
|
|
// 深度转化目标
|
|
|
- if (!Check.isNull(strategy.getDeepConversionType())) {
|
|
|
- unitJson.put("deep_conversion_type", strategy.getDeepConversionType());
|
|
|
+ if (!Check.isNull(groupJson.getInteger("deepConversionType"))) {
|
|
|
+ unitJson.put("deep_conversion_type", groupJson.getInteger("deepConversionType"));
|
|
|
}
|
|
|
// 优化目标
|
|
|
- if (!Check.isNull(strategy.getOcpxActionType())) {
|
|
|
- unitJson.put("ocpx_action_type", strategy.getOcpxActionType());
|
|
|
+ if (!Check.isNull(groupJson.getInteger("ocpxActionType"))) {
|
|
|
+ unitJson.put("ocpx_action_type", groupJson.getInteger("ocpxActionType"));
|
|
|
}
|
|
|
//投放开始时间
|
|
|
- if (!Check.isNull(strategy.getBeginTime())) {
|
|
|
+ if (!Check.isNull(groupJson.getString("beginTime"))) {
|
|
|
String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
|
|
|
- boolean beginTimeBoolean = DateUtils.compare(strategy.getBeginTime(), nowDate);
|
|
|
+ boolean beginTimeBoolean = DateUtils.compare(groupJson.getString("beginTime"), nowDate);
|
|
|
if (beginTimeBoolean) {
|
|
|
unitJson.put("begin_time", nowDate);
|
|
|
} else {
|
|
|
- unitJson.put("begin_time", strategy.getBeginTime());
|
|
|
+ unitJson.put("begin_time", groupJson.getString("beginTime"));
|
|
|
}
|
|
|
+ } else {
|
|
|
+ return getNullValueResult("广告组必填参数:begin_time,投放开始时间为空");
|
|
|
}
|
|
|
// 投放结束时间
|
|
|
- if (!Check.isNull(strategy.getEndTime())) {
|
|
|
- unitJson.put("end_time", strategy.getEndTime());
|
|
|
+ if (!Check.isNull(groupJson.getString("endTime"))) {
|
|
|
+ unitJson.put("end_time", groupJson.getString("beginTime"));
|
|
|
}
|
|
|
// 投放时间段
|
|
|
- if (!Check.isNull(strategy.getScheduleTime())) {
|
|
|
- unitJson.put("schedule_time", strategy.getScheduleTime());
|
|
|
+ if (!Check.isNull(groupJson.getString("scheduleTime"))) {
|
|
|
+ unitJson.put("schedule_time", groupJson.getString("scheduleTime"));
|
|
|
}
|
|
|
//定向模板id(选)
|
|
|
- Long templateId = strategy.getTemplateId();
|
|
|
- if (!Check.isNull(templateId)) {
|
|
|
- unitJson.put("template_id", templateId);
|
|
|
+ if (!Check.isNull(groupJson.getLong("templateId"))) {
|
|
|
+ unitJson.put("template_id", groupJson.getLong("templateId"));
|
|
|
}
|
|
|
// 优先从系统应用商店下载 1:优先从系统应用商店下载使用,默认0
|
|
|
if (!Check.isNull(groupJson.getInteger("useAppMarket"))) {
|
|
@@ -180,8 +296,8 @@ public class KuaishouStrategyServiceImpl extends ServiceImpl<KuaishouStrategyMap
|
|
|
// -----------------用户定向-----------
|
|
|
JSONObject targetJson = new JSONObject();
|
|
|
// 地域
|
|
|
- if (!Check.isNull(strategy.getRegion())) {
|
|
|
- targetJson.put("region", strategy.getRegion());
|
|
|
+ if (!Check.isNull(groupJson.getJSONArray("region"))) {
|
|
|
+ targetJson.put("region", groupJson.getJSONArray("region"));
|
|
|
}
|
|
|
// 自定义年龄段
|
|
|
JSONArray ageArr = groupJson.getJSONArray("age");
|
|
@@ -192,16 +308,16 @@ public class KuaishouStrategyServiceImpl extends ServiceImpl<KuaishouStrategyMap
|
|
|
targetJson.put("age", ageJson);
|
|
|
}
|
|
|
// 固定年龄段
|
|
|
- if (!Check.isNull(strategy.getAgesRange())) {
|
|
|
- targetJson.put("ages_range", strategy.getAgesRange());
|
|
|
+ if (!Check.isNull(groupJson.getJSONArray("agesRange"))) {
|
|
|
+ targetJson.put("ages_range", groupJson.getJSONArray("agesRange"));
|
|
|
}
|
|
|
// 性别
|
|
|
- if (!Check.isNull(strategy.getGender())) {
|
|
|
- targetJson.put("gender", strategy.getGender());
|
|
|
+ if (!Check.isNull(groupJson.getInteger("gender"))) {
|
|
|
+ targetJson.put("gender", groupJson.getInteger("gender"));
|
|
|
}
|
|
|
//操作系统
|
|
|
- if (!Check.isNull(strategy.getPlatformOs())) {
|
|
|
- targetJson.put("platform_os", strategy.getPlatformOs());
|
|
|
+ if (!Check.isNull(groupJson.getInteger("platformOs"))) {
|
|
|
+ targetJson.put("platform_os", groupJson.getInteger("platformOs"));
|
|
|
}
|
|
|
//Android版本
|
|
|
if (!Check.isNull(groupJson.getInteger("androidOsv"))) {
|
|
@@ -276,19 +392,19 @@ public class KuaishouStrategyServiceImpl extends ServiceImpl<KuaishouStrategyMap
|
|
|
targetJson.put("app_ids", groupJson.getJSONArray("appIds"));
|
|
|
}
|
|
|
// 人群包定向
|
|
|
- if (!Check.isNull(strategy.getPopulation())) {
|
|
|
- targetJson.put("population", strategy.getPopulation());
|
|
|
+ if (!Check.isNull(groupJson.getJSONArray("population"))) {
|
|
|
+ targetJson.put("population", groupJson.getJSONArray("population"));
|
|
|
}
|
|
|
// 人群包排除
|
|
|
- if (!Check.isNull(strategy.getExcludePopulation())) {
|
|
|
- targetJson.put("exclude_population", strategy.getExcludePopulation());
|
|
|
+ if (!Check.isNull(groupJson.getJSONArray("excludePopulation"))) {
|
|
|
+ targetJson.put("exclude_population", groupJson.getJSONArray("excludePopulation"));
|
|
|
}
|
|
|
|
|
|
if (!Check.isNull(groupJson.getJSONArray("thirdPlatformCode"))) {
|
|
|
targetJson.put("third_platform_code", groupJson.getJSONArray("thirdPlatformCode"));
|
|
|
}
|
|
|
unitJson.put("target", targetJson);
|
|
|
- Map<String, Object> returnUnitMap = kuaishouInterfaceService.adUnitCreate(oauthToken.getAccessToken(), oauthToken.getAccountId(), unitJson, 1);
|
|
|
+ return kuaishouInterfaceService.adUnitCreate(oauthToken.getAccessToken(), oauthToken.getAccountId(), unitJson, 1);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -299,16 +415,20 @@ public class KuaishouStrategyServiceImpl extends ServiceImpl<KuaishouStrategyMap
|
|
|
* @throws
|
|
|
* @author ZHAOXA
|
|
|
*/
|
|
|
- private Map<String, Object> createCreativeLevelStrategy(CtopOauthToken oauthToken, KuaishouStrategy strategy, JSONObject data) {
|
|
|
+ private Map<String, Object> createCreativeLevelStrategy(CtopOauthToken oauthToken, JSONObject data) {
|
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
|
JSONObject creativeJson = new JSONObject();
|
|
|
//广告组ID
|
|
|
if (!Check.isNull(data.get("unitId"))) {
|
|
|
creativeJson.put("unit_id", data.get("unitId"));
|
|
|
+ } else {
|
|
|
+ return getNullValueResult("广告创意必填参数:unit_id,广告组ID为空");
|
|
|
}
|
|
|
//创意名称
|
|
|
if (!Check.isNull(data.get("creativeName"))) {
|
|
|
creativeJson.put("creative_name", data.get("creativeName"));
|
|
|
+ } else {
|
|
|
+ return getNullValueResult("广告创意必填参数:creative_name,创意名称为空");
|
|
|
}
|
|
|
//视频ID
|
|
|
if (!Check.isNull(data.get("photoId"))) {
|
|
@@ -325,14 +445,20 @@ public class KuaishouStrategyServiceImpl extends ServiceImpl<KuaishouStrategyMap
|
|
|
String creativeMaterialType = data.getString("creativeMaterialType");
|
|
|
if (!Check.isNull(creativeMaterialType)) {
|
|
|
creativeJson.put("creative_material_type", creativeMaterialType);
|
|
|
+ } else {
|
|
|
+ return getNullValueResult("广告创意必填参数:creative_material_type,素材类型为空");
|
|
|
}
|
|
|
//行动号召按钮文案
|
|
|
if (!Check.isNull(data.getString("actionBarText"))) {
|
|
|
creativeJson.put("action_bar_text", data.getString("actionBarText"));
|
|
|
+ } else {
|
|
|
+ return getNullValueResult("广告创意必填参数:action_bar_text,行动号召按钮文案为空");
|
|
|
}
|
|
|
//广告语
|
|
|
if (!Check.isNull(data.getString("description"))) {
|
|
|
creativeJson.put("description", data.getString("description"));
|
|
|
+ } else {
|
|
|
+ return getNullValueResult("广告创意必填参数:description,广告语为空");
|
|
|
}
|
|
|
//便利贴创意短广告语
|
|
|
if (!Check.isNull(data.getString("shortSlogan"))) {
|
|
@@ -409,4 +535,14 @@ public class KuaishouStrategyServiceImpl extends ServiceImpl<KuaishouStrategyMap
|
|
|
}
|
|
|
return kuaishouInterfaceService.creativeCreate(oauthToken.getAccessToken(), oauthToken.getAccountId(), creativeJson, 1);
|
|
|
}
|
|
|
+
|
|
|
+ private Map<String, Object> getNullValueResult(String msg) {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("code", -1);
|
|
|
+ map.put("message", "error");
|
|
|
+ map.put("desc", msg);
|
|
|
+ map.put("success", false);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
}
|