|
@@ -668,7 +668,6 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- // System.err.println(resultJson);
|
|
|
return resultJson;
|
|
|
}
|
|
|
|
|
@@ -691,6 +690,7 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
|
|
|
return returnJson;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 获取当天api创建创意数
|
|
|
*
|
|
@@ -1050,4 +1050,150 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
|
|
|
}
|
|
|
return captions;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void createUnitAgain(KuaiShouGroupTemplate template) {
|
|
|
+ CtopOauthToken token = tokenService.getTokenByAccountId(template.getAccountId());
|
|
|
+ if (template.getUnitType() == 4) {
|
|
|
+ Thread thread = new Thread() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ createCreativeAgain(token.getAccessToken(), template.getUnitId(), template);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ thread.start();
|
|
|
+ } else {
|
|
|
+ Thread thread = new Thread() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ createProgramCreative(token.getAccessToken(), template.getUnitId(), template);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ thread.start();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void createCreativeAgain(String accessToken, Long unitId, KuaiShouGroupTemplate template) {
|
|
|
+ KuaiShouGroupTemplate updateTemplate = new KuaiShouGroupTemplate();
|
|
|
+ updateTemplate.setId(template.getId());
|
|
|
+ updateTemplate.setCreativeStatus(1);
|
|
|
+ updateTemplate.setCreativeReviewDetail("创意创建中");
|
|
|
+ this.updateById(updateTemplate);
|
|
|
+ JSONObject createJson = new JSONObject();
|
|
|
+ createJson.put("unit_id", unitId);
|
|
|
+ if (!Check.isNull(template.getClickTrackUrl())) {
|
|
|
+ createJson.put("click_track_url", template.getClickTrackUrl());
|
|
|
+ }
|
|
|
+ if (!Check.isNull(template.getActionbarClickUrl())) {
|
|
|
+ createJson.put("actionbar_click_url", template.getActionbarClickUrl());
|
|
|
+ }
|
|
|
+ if (!Check.isNull(template.getCreativeCategory())) {
|
|
|
+ createJson.put("creative_category", template.getCreativeCategory());
|
|
|
+ }
|
|
|
+ if (!Check.isNull(template.getCreativeTag())) {
|
|
|
+ createJson.put("creative_tag", JSONArray.parseArray(template.getCreativeTag()));
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONArray creatives = new JSONArray();
|
|
|
+ Integer createType = template.getCreateType();
|
|
|
+ if (createType == 0) { // 单品
|
|
|
+ Long photoId = template.getPhotoId();
|
|
|
+ JSONObject videoMd5Json = groupTemplateMapper.getMd5ByPhotoId(String.valueOf(photoId));
|
|
|
+ if (Check.isNull(videoMd5Json)) {
|
|
|
+ log.error("未获取到素材详细信息,accountId:{},unitId:{}", template.getAccountId(), unitId);
|
|
|
+ updateTemplate.setCreativeStatus(3);
|
|
|
+ updateTemplate.setCreativeReviewDetail("未获取到素材信息");
|
|
|
+ this.updateById(updateTemplate);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Integer materialType = videoMd5Json.getInteger("materialType");
|
|
|
+ String videoMd5 = videoMd5Json.getString("md5");
|
|
|
+ List<JSONObject> imageList = groupTemplateMapper.getImageListByMd5(videoMd5, template.getImageCount());
|
|
|
+ if (Check.isNull(imageList)) {
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
+ json.put("creative_name", template.getCreativeName());
|
|
|
+ json.put("photo_id", template.getPhotoId());
|
|
|
+ json.put("creative_material_type", materialType);
|
|
|
+ json.put("action_bar_text", template.getActionBarText());
|
|
|
+ json.put("description", template.getDescription());
|
|
|
+ if (!Check.isNull(template.getSiteId())) {
|
|
|
+ json.put("site_id", template.getSiteId());
|
|
|
+ }
|
|
|
+ creatives.add(json);
|
|
|
+ } else {
|
|
|
+ for (int i = 0; i < imageList.size(); i++) {
|
|
|
+ JSONObject imageJson = imageList.get(i);
|
|
|
+ if (Check.isNull(imageJson)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
+ String imageMd5 = imageJson.getString("md5");
|
|
|
+ String imageToken = getImageToken(imageMd5, template.getAccountId(), accessToken, imageJson.getString("url"));
|
|
|
+ if (Check.isNull(imageToken)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ json.put("image_token", imageToken);
|
|
|
+ json.put("creative_name", template.getCreativeName() + "_" + i);
|
|
|
+ json.put("photo_id", template.getPhotoId());
|
|
|
+ json.put("creative_material_type", materialType);
|
|
|
+ json.put("action_bar_text", template.getActionBarText());
|
|
|
+ json.put("description", template.getDescription());
|
|
|
+ if (!Check.isNull(template.getSiteId())) {
|
|
|
+ json.put("site_id", template.getSiteId());
|
|
|
+ }
|
|
|
+ creatives.add(json);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (createType == 1) { // 混搭
|
|
|
+ JSONArray array = JSONArray.parseArray(template.getPhotoIds());
|
|
|
+ if (Check.isNull(array)) {
|
|
|
+ updateTemplate.setCreativeStatus(3);
|
|
|
+ updateTemplate.setCreativeReviewDetail("未获取到混搭素材信息");
|
|
|
+ this.updateById(updateTemplate);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (int i = 0; i < array.size(); i++) {
|
|
|
+ Long photoId = array.getLong(i);
|
|
|
+ JSONObject videoJson = groupTemplateMapper.getMd5ByPhotoId(String.valueOf(photoId));
|
|
|
+ if (Check.isNull(videoJson)) {
|
|
|
+ log.error("未获取到素材详细信息,accountId:{},unitId:{}", template.getAccountId(), unitId);
|
|
|
+ updateTemplate.setCreativeStatus(3);
|
|
|
+ updateTemplate.setCreativeReviewDetail("未获取到素材信息");
|
|
|
+ this.updateById(updateTemplate);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String videoMd5 = videoJson.getString("md5");
|
|
|
+ Integer materialType = videoJson.getInteger("materialType");
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
+ JSONObject imageJson = groupTemplateMapper.getImageJsonByMd5(videoMd5);
|
|
|
+ if (!Check.isNull(imageJson)) {
|
|
|
+ String imageToken = getImageToken(imageJson.getString("md5"), template.getAccountId(), accessToken, imageJson.getString("url"));
|
|
|
+ if (!Check.isNull(imageToken)) {
|
|
|
+ json.put("image_token", imageToken);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ json.put("creative_name", template.getCreativeName() + "_" + i);
|
|
|
+ json.put("photo_id", photoId);
|
|
|
+ json.put("creative_material_type", materialType);
|
|
|
+ json.put("action_bar_text", template.getActionBarText());
|
|
|
+ json.put("description", template.getDescription());
|
|
|
+ if (!Check.isNull(template.getSiteId())) {
|
|
|
+ json.put("site_id", template.getSiteId());
|
|
|
+ }
|
|
|
+ creatives.add(json);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ createJson.put("creatives", creatives);
|
|
|
+ Map<String, Object> creativeMap = iKuaishouInterfaceService.batchCreativeCreate(accessToken, template.getAccountId(), createJson, 1, template.getUserId());
|
|
|
+ Integer code = (Integer) creativeMap.get("code");
|
|
|
+ if (code == 0) {
|
|
|
+ updateTemplate.setCreativeStatus(2);
|
|
|
+ updateTemplate.setCreativeReviewDetail("创意创建成功");
|
|
|
+ updateTemplate.setCreateCreativeCount((Integer) creativeMap.get("count"));
|
|
|
+ } else {
|
|
|
+ updateTemplate.setCreativeStatus(3);
|
|
|
+ updateTemplate.setCreativeReviewDetail((String) creativeMap.get("message"));
|
|
|
+ }
|
|
|
+ this.updateById(updateTemplate);
|
|
|
+ }
|
|
|
}
|