|
@@ -3,15 +3,21 @@ package org.jeecg.modules.ctop.service.impl;
|
|
|
import cn.com.ctop.common.module.entity.BindAccountLogin;
|
|
|
import cn.com.ctop.common.module.entity.CtopOauthToken;
|
|
|
import cn.com.ctop.common.module.mapper.BindAccountLoginMapper;
|
|
|
+import cn.com.ctop.common.module.service.IBindAccountLoginService;
|
|
|
import cn.com.ctop.common.module.service.ICtopOauthTokenService;
|
|
|
+import cn.com.ctop.common.module.service.IFileInfoService;
|
|
|
import cn.com.ctop.common.module.utils.*;
|
|
|
import cn.com.ctop.crawler.modules.core.util.FateadmHttpUtil;
|
|
|
import cn.com.ctop.crawler.modules.core.util.FateadmUtil;
|
|
|
import cn.com.ctop.toutiao.entity.ByteDanceUserOrientationTemplate;
|
|
|
+import cn.com.ctop.toutiao.entity.BytedanceCreativeLaunchTemplate;
|
|
|
import cn.com.ctop.toutiao.entity.BytedanceUrlInfo;
|
|
|
import cn.com.ctop.toutiao.mapper.ByteDanceUserOrientationTemplateMapper;
|
|
|
+import cn.com.ctop.toutiao.mapper.BytedanceCreativeLaunchTemplateMapper;
|
|
|
import cn.com.ctop.toutiao.mapper.BytedanceUrlInfoMapper;
|
|
|
import cn.com.ctop.toutiao.service.IByteDanceAdvertiserDataService;
|
|
|
+import cn.com.ctop.toutiao.service.IByteDanceCreativeService;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
@@ -40,6 +46,8 @@ public class CreateInternalServiceImpl implements ICreateInternalService {
|
|
|
@Value("${jeecg.path.chrome-driver}")
|
|
|
private String chromeDriver;
|
|
|
@Autowired
|
|
|
+ private IBindAccountLoginService bindAccountLoginService;
|
|
|
+ @Autowired
|
|
|
private BindAccountLoginMapper bindAccountLoginMapper;
|
|
|
|
|
|
@Autowired
|
|
@@ -144,7 +152,6 @@ public class CreateInternalServiceImpl implements ICreateInternalService {
|
|
|
param.put("captcha", resp.pred_resl);
|
|
|
orderId = resp.req_id;
|
|
|
res = HttpUtils2.httpPostParamRequest("https://sso.toutiao.com/account_login/", param, header);
|
|
|
- System.out.println("res:" + res);
|
|
|
jsonNode = mapper.readTree(res);
|
|
|
errorCode = jsonNode.get("error_code").asInt();
|
|
|
}
|
|
@@ -190,11 +197,16 @@ public class CreateInternalServiceImpl implements ICreateInternalService {
|
|
|
Long accountId = requestJson.getLong("accountId");
|
|
|
System.out.println(accountId);
|
|
|
Long userOrientationId = requestJson.getLong("userOrientationId");
|
|
|
- BindAccountLogin bindAccountLogin = bindAccountLoginMapper.selectById(accountId);
|
|
|
+ BindAccountLogin bindAccountLogin = bindAccountLoginService.selectByAccountId(accountId + "");
|
|
|
if (null == bindAccountLogin) {
|
|
|
ResultMapUtils.setResultMap(resultMap, StatusCode.ACCOUNT_HAS_NOT_EXIST.getCode());
|
|
|
return resultMap;
|
|
|
}
|
|
|
+ CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId + "");
|
|
|
+ if (null == token) {
|
|
|
+ ResultMapUtils.setResultMap(resultMap, StatusCode.ACCOUNT_HAS_NOT_EXIST.getCode());
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
String url = "https://ad.oceanengine.com/pages/login/index.html";
|
|
|
System.getProperties().setProperty("webdriver.chrome.driver", chromeDriver);
|
|
|
ChromeOptions chromeOptions = new ChromeOptions();
|
|
@@ -308,6 +320,7 @@ public class CreateInternalServiceImpl implements ICreateInternalService {
|
|
|
res = HttpUtils2.httpPostRequest("https://ad.oceanengine.com/overture/campaign/create/", campaignParam, header);// 创建广告组返回信息
|
|
|
System.out.println(res);
|
|
|
Integer itratorNum = requestJson.getInteger("itratorNum");
|
|
|
+ JSONObject data = new JSONObject();
|
|
|
if (null != itratorNum && itratorNum > 0) {
|
|
|
//循环创建广告计划
|
|
|
for (int i = 0; i < itratorNum; i++) {
|
|
@@ -412,20 +425,120 @@ public class CreateInternalServiceImpl implements ICreateInternalService {
|
|
|
resultMap.put("success", false);
|
|
|
return resultMap;
|
|
|
}
|
|
|
+ //广告计划id
|
|
|
Long adId = result.getJSONObject("data").getLong("ad_id");
|
|
|
-
|
|
|
//修改用户定向
|
|
|
ByteDanceUserOrientationTemplate template = userOrientationTemplateMapper.selectById(userOrientationId);
|
|
|
if (null != template) {
|
|
|
- CtopOauthToken token = tokenService.getOauthTokenByAccountId(bindAccountLogin.getAccountId());
|
|
|
- if (null != token) {
|
|
|
- //获取modify_time
|
|
|
- Thread.sleep(5000L);
|
|
|
- advertiserDataService.getAdvertiserPlan(bindAccountLogin.getAccountId(), adId + "");
|
|
|
+ //获取modify_time
|
|
|
+ Thread.sleep(5000L);
|
|
|
+ advertiserDataService.getAdvertiserPlan(bindAccountLogin.getAccountId(), adId + "");
|
|
|
+ advertiserDataService.updateAd(token, adId, template);
|
|
|
+ }
|
|
|
+ Long creativeTemplateId = requestJson.getLong("creativeTemplateId");
|
|
|
+
|
|
|
+ //创建广告创意
|
|
|
+ String name = requestJson.getString("name");
|
|
|
+ data.put("title", name + "_" + System.currentTimeMillis() + "_" + "汇创广告创意");
|
|
|
+ if (i == 0) {
|
|
|
+ BytedanceCreativeLaunchTemplate launchTemplate = launchTemplateMapper.selectById(creativeTemplateId);
|
|
|
+ data.put("ad_id", adId);
|
|
|
+ String advertiseLoaction = launchTemplate.getAdvertiseLocation();
|
|
|
+ //优选广告位
|
|
|
+ if (null != advertiseLoaction && advertiseLoaction.equals("great") && null != launchTemplate.getSmartInventory() && !"".equals(launchTemplate.getSmartInventory())) {
|
|
|
+ data.put("smart_inventory", launchTemplate.getSmartInventory());
|
|
|
+ }
|
|
|
+ //按媒体指定位置
|
|
|
+ if (null != advertiseLoaction && "media".equals(advertiseLoaction)) {
|
|
|
+ String inventoryTypeStr = launchTemplate.getInventoryType();
|
|
|
+ JSONArray inventoryType = JSONArray.parseArray(inventoryTypeStr);
|
|
|
+ data.put("inventory_type", inventoryType);
|
|
|
+ }
|
|
|
+ //按场景指定位置
|
|
|
+ if (null != advertiseLoaction && "sence".equals(advertiseLoaction)) {
|
|
|
+ data.put("scene_inventory", launchTemplate.getSceneInventory());
|
|
|
+ }
|
|
|
+
|
|
|
+ //广告评论
|
|
|
+ data.put("is_comment_disable ", launchTemplate.getCommentDisable());
|
|
|
+ //创意展现方式
|
|
|
+ data.put("creative_display_mode ", launchTemplate.getCreativeDisplayMode());
|
|
|
+ //创意分类
|
|
|
+ JSONArray categorys = JSONArray.parseArray(launchTemplate.getThirdIndustryId());
|
|
|
+ String thirdIndustryId = categorys.getString(2);
|
|
|
+ data.put("third_industry_id", thirdIndustryId);
|
|
|
+ //创意标签
|
|
|
+ data.put("ad_keywords", JSONArray.parseObject(launchTemplate.getAdKeywords()));
|
|
|
+ //创意标题
|
|
|
+ data.put("title", name + "_" + System.currentTimeMillis() + "_" + "汇创广告创意");
|
|
|
|
|
|
- System.out.println(111);
|
|
|
- advertiserDataService.updateAd(token, adId, template);
|
|
|
+ //创意方式
|
|
|
+ String creativeType = requestJson.getString("creativeType");
|
|
|
+ if (null != creativeType && creativeType.equals("customize")) {
|
|
|
+ //自定义创意
|
|
|
+ //拼装creative参数
|
|
|
+ JSONArray creatives = new JSONArray();
|
|
|
+ JSONArray getCreatives = requestJson.getJSONArray("creatives");
|
|
|
+ if (null != getCreatives && getCreatives.size() > 0) {
|
|
|
+ getCreatives.forEach(k -> {
|
|
|
+ JSONObject createtive = (JSONObject) k;
|
|
|
+ JSONObject setCreatetive = new JSONObject();
|
|
|
+ String imageMode = createtive.getString("typeCode");
|
|
|
+ setCreatetive.put("image_mode", imageMode);
|
|
|
+ setCreatetive.put("title", createtive.getString("text"));
|
|
|
+ //TODO 添加动态词包id
|
|
|
+ if ("CREATIVE_IMAGE_MODE_VIDEO".equals(imageMode) || "CREATIVE_IMAGE_MODE_VIDEO_VERTICAL".equals(imageMode)) {
|
|
|
+ //视频创意
|
|
|
+ String videoUrl = createtive.getString("vadioUrl");
|
|
|
+ String imageUrl = createtive.getString("imageUrl");
|
|
|
+ if (null != videoUrl) {
|
|
|
+ Map<String, Object> getImageResult = fileInfoService.uploadImageToBytedance(token.getAccountId() + "", imageUrl);
|
|
|
+ JSONArray horizonVideoCoverImageArray = (JSONArray) getImageResult.get("imageIds");
|
|
|
+ String imageId = horizonVideoCoverImageArray.getString(0);
|
|
|
+ Map<String, Object> getVideoResult = fileInfoService.uploadVideoToBytedance(token.getAccountId() + "", videoUrl);
|
|
|
+ String videoId = (String) getVideoResult.get("videoId");
|
|
|
+ setCreatetive.put("image_id", imageId);
|
|
|
+ setCreatetive.put("video_id", videoId);
|
|
|
+ creatives.add(setCreatetive);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //图片创意
|
|
|
+ String imageUrl = requestJson.getString("imageUrl");
|
|
|
+ if (null != imageUrl && !"".equals(imageUrl.trim())) {
|
|
|
+ Map<String, Object> getImageResult = fileInfoService.uploadImageToBytedance(token.getAccountId() + "", imageUrl);
|
|
|
+ JSONArray imageArray = (JSONArray) getImageResult.get("imageIds");
|
|
|
+ setCreatetive.put("image_ids", imageArray);
|
|
|
+ creatives.add(setCreatetive);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ data.put("creatives", creatives);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //程序化创意
|
|
|
+ JSONArray titleArray = requestJson.getJSONArray("titles");
|
|
|
+ if (null != titleArray && titleArray.size() > 0) {
|
|
|
+ JSONArray setTitleArray = new JSONArray();
|
|
|
+ titleArray.forEach(v -> {
|
|
|
+ JSONObject getTitleObject = (JSONObject) v;
|
|
|
+ JSONObject titleObject = new JSONObject();
|
|
|
+ String getTitle = getTitleObject.getString("text");
|
|
|
+ titleObject.put("title", getTitle);
|
|
|
+ ArrayList<String> wordsString = StringUtils.stringCutFromBrace(getTitle);
|
|
|
+ fileInfoService.getCreativeWords(accountId);
|
|
|
+ titleArray.add(titleObject);
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
+ //应用下载详情页
|
|
|
+ data.put("web_url", requestJson.getString("webUrl"));
|
|
|
+ //应用名
|
|
|
+ data.put("app_name", requestJson.getString("appName"));
|
|
|
+ }
|
|
|
+ resultMap = byteDanceCreativeService.creativeCreate(token.getAccountId() + "", adId, data.toJSONString());
|
|
|
+ Boolean createSuccess = (Boolean) resultMap.get("success");
|
|
|
+ if (null != createSuccess && !createSuccess) {
|
|
|
+ return resultMap;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -443,6 +556,15 @@ public class CreateInternalServiceImpl implements ICreateInternalService {
|
|
|
return resultMap;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BytedanceCreativeLaunchTemplateMapper launchTemplateMapper;
|
|
|
+ @Autowired
|
|
|
+ private IByteDanceCreativeService byteDanceCreativeService;
|
|
|
+ @Autowired
|
|
|
+ private IFileInfoService fileInfoService;
|
|
|
+
|
|
|
+
|
|
|
@Autowired
|
|
|
private ByteDanceUserOrientationTemplateMapper userOrientationTemplateMapper;
|
|
|
@Autowired
|