|
@@ -0,0 +1,445 @@
|
|
|
|
+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.KuaiShouGroupTemplate;
|
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouImageGet;
|
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouGroupTemplateMapper;
|
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouGroupTemplateService;
|
|
|
|
+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.IKuaishouInterfaceService;
|
|
|
|
+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 lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
|
+import java.util.concurrent.Executors;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 创建组模板
|
|
|
|
+ *
|
|
|
|
+ * @author jeecg-boot
|
|
|
|
+ * @version V1.0
|
|
|
|
+ * @date 2020-12-15
|
|
|
|
+ */
|
|
|
|
+@Service
|
|
|
|
+@Slf4j
|
|
|
|
+public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupTemplateMapper, KuaiShouGroupTemplate> implements IKuaiShouGroupTemplateService {
|
|
|
|
+ @Autowired
|
|
|
|
+ private ICtopOauthTokenService tokenService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IKuaishouInterfaceService iKuaishouInterfaceService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private KuaiShouGroupTemplateMapper groupTemplateMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IKuaiShouImageGetService imageGetService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IKuaiShouMaterialUploadService uploadService;
|
|
|
|
+
|
|
|
|
+ static ExecutorService executorService = Executors.newFixedThreadPool(10);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public JSONObject submitUnitTask(JSONObject requestJson) throws Exception {
|
|
|
|
+ Long accountId = requestJson.getLong("accountId");
|
|
|
|
+ if (Check.isNull(accountId)) {
|
|
|
|
+ throw new Exception("accountId不能为空");
|
|
|
|
+ }
|
|
|
|
+ Long campaignId = requestJson.getLong("campaignId");
|
|
|
|
+ if (Check.isNull(campaignId)) {
|
|
|
|
+ throw new Exception("campaignId不能为空");
|
|
|
|
+ }
|
|
|
|
+ Integer createCount = requestJson.getInteger("createCount");
|
|
|
|
+ if (Check.isNull(createCount)) {
|
|
|
|
+ throw new Exception("创建数不能为空不能为空");
|
|
|
|
+ }
|
|
|
|
+ JSONArray photoArr = requestJson.getJSONArray("photoArr");
|
|
|
|
+ if (Check.isNull(photoArr)) {
|
|
|
|
+ throw new Exception("请选择需要创建的视频");
|
|
|
|
+ }
|
|
|
|
+ if (createCount != photoArr.size()) {
|
|
|
|
+ throw new Exception("视频数量必须和创建数量保持一致");
|
|
|
|
+ }
|
|
|
|
+ JSONObject returnJson = new JSONObject();
|
|
|
|
+
|
|
|
|
+ String userId = requestJson.getString("userId");
|
|
|
|
+ String unitName = requestJson.getString("unitName");
|
|
|
|
+ Long template_id = requestJson.getLong("templateId");
|
|
|
|
+ Integer bid_type = requestJson.getInteger("bidType");
|
|
|
|
+ Integer use_app_market = requestJson.getInteger("useAppMarket");
|
|
|
|
+ JSONArray app_store = requestJson.getJSONArray("appStore");
|
|
|
|
+ Long bid = requestJson.getLong("bid");
|
|
|
|
+ Long cpa_bid = requestJson.getLong("cpaBid");
|
|
|
|
+ Integer ocpx_action_type = requestJson.getInteger("ocpxActionType");
|
|
|
|
+ Integer deep_conversion_type = requestJson.getInteger("deepConversionType");
|
|
|
|
+ Long deep_conversion_bid = requestJson.getLong("deepConversionBid");
|
|
|
|
+ JSONArray scene_id = requestJson.getJSONArray("sceneId");
|
|
|
|
+ Integer unit_type = requestJson.getInteger("unitType");
|
|
|
|
+ String begin_time = requestJson.getString("beginTime");
|
|
|
|
+ String end_time = requestJson.getString("endTime");
|
|
|
|
+ String schedule_time = requestJson.getString("scheduleTime");
|
|
|
|
+ Long day_budget = requestJson.getLong("dayBudget");
|
|
|
|
+ Long convert_id = requestJson.getLong("convertId");
|
|
|
|
+ Integer url_type = requestJson.getInteger("urlType");
|
|
|
|
+ String url = requestJson.getString("url");
|
|
|
|
+ Long app_id = requestJson.getLong("appId");
|
|
|
|
+ Integer show_mode = requestJson.getInteger("showMode");
|
|
|
|
+ Integer speed = requestJson.getInteger("speed");
|
|
|
|
+ String click_track_url = requestJson.getString("click_track_url");
|
|
|
|
+ String actionbar_click_url = requestJson.getString("actionbar_click_url");
|
|
|
|
+ Integer creative_category = requestJson.getInteger("creative_category");
|
|
|
|
+ JSONArray creative_tag = requestJson.getJSONArray("creative_tag");
|
|
|
|
+ String creative_name = requestJson.getString("creative_name");
|
|
|
|
+ String action_bar_text = requestJson.getString("action_bar_text");
|
|
|
|
+ String description = requestJson.getString("description");
|
|
|
|
+ Long site_id = requestJson.getLong("site_id");
|
|
|
|
+
|
|
|
|
+ List<KuaiShouGroupTemplate> templates = new ArrayList<>();
|
|
|
|
+ for (int i = 0; i < createCount; i++) {
|
|
|
|
+ Long photoId = photoArr.getLong(i);
|
|
|
|
+ String name = unitName + "_" + i;
|
|
|
|
+ KuaiShouGroupTemplate template = new KuaiShouGroupTemplate();
|
|
|
|
+ template.setAccountId(accountId);
|
|
|
|
+ template.setUserId(userId);
|
|
|
|
+ template.setCampaignId(campaignId);
|
|
|
|
+ template.setUnitName(name);
|
|
|
|
+ template.setPhotoId(photoId);
|
|
|
|
+ if (!Check.isNull(template_id)) {
|
|
|
|
+ template.setTemplateId(template_id);
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(bid_type)) {
|
|
|
|
+ template.setBidType(bid_type);
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(use_app_market)) {
|
|
|
|
+ template.setUseAppMarket(use_app_market);
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(app_store)) {
|
|
|
|
+ template.setAppStore(app_store.toJSONString());
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(bid)) {
|
|
|
|
+ template.setBid(bid);
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(cpa_bid)) {
|
|
|
|
+ template.setCpaBid(cpa_bid);
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(ocpx_action_type)) {
|
|
|
|
+ template.setOcpxActionType(ocpx_action_type);
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(deep_conversion_type)) {
|
|
|
|
+ template.setDeepConversionType(deep_conversion_type);
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(deep_conversion_bid)) {
|
|
|
|
+ template.setDeepConversionBid(deep_conversion_bid);
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(scene_id)) {
|
|
|
|
+ template.setSceneId(scene_id.toJSONString());
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(unit_type)) {
|
|
|
|
+ template.setUrlType(unit_type);
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(begin_time)) {
|
|
|
|
+ template.setBeginTime(begin_time);
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(end_time)) {
|
|
|
|
+ template.setEndTime(end_time);
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(schedule_time)) {
|
|
|
|
+ template.setScheduleTime(schedule_time);
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(day_budget)) {
|
|
|
|
+ template.setDayBudget(day_budget);
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(convert_id)) {
|
|
|
|
+ template.setConvertId(convert_id);
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(url_type)) {
|
|
|
|
+ template.setUrlType(url_type);
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(url)) {
|
|
|
|
+ template.setUrl(url);
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(app_id)) {
|
|
|
|
+ template.setAppId(app_id);
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(show_mode)) {
|
|
|
|
+ template.setShowMode(show_mode);
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(speed)) {
|
|
|
|
+ template.setSpeed(speed);
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(click_track_url)) {
|
|
|
|
+ template.setClickTrackUrl(click_track_url);
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(actionbar_click_url)) {
|
|
|
|
+ template.setActionbarClickUrl(actionbar_click_url);
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(creative_category)) {
|
|
|
|
+ template.setCreativeCategory(creative_category);
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(creative_tag)) {
|
|
|
|
+ template.setCreativeTag(creative_tag.toJSONString());
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(creative_name)) {
|
|
|
|
+ template.setCreativeName(creative_name);
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(action_bar_text)) {
|
|
|
|
+ template.setActionBarText(action_bar_text);
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(description)) {
|
|
|
|
+ template.setDescription(description);
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(description)) {
|
|
|
|
+ template.setDescription(description);
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(site_id)) {
|
|
|
|
+ template.setSiteId(site_id);
|
|
|
|
+ }
|
|
|
|
+ template.setTaskStatus(0);
|
|
|
|
+ templates.add(template);
|
|
|
|
+ }
|
|
|
|
+ boolean b = this.saveBatch(templates);
|
|
|
|
+ if (b) {
|
|
|
|
+ returnJson.put("code", 0);
|
|
|
|
+ returnJson.put("size", templates.size());
|
|
|
|
+ } else {
|
|
|
|
+ returnJson.put("code", -1);
|
|
|
|
+ returnJson.put("message", "提交任务失败");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return returnJson;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void createUnit() {
|
|
|
|
+ QueryWrapper<KuaiShouGroupTemplate> queryWrapper = new QueryWrapper<>();
|
|
|
|
+ queryWrapper.eq("task_status", 0);
|
|
|
|
+ queryWrapper.orderByDesc("create_time");
|
|
|
|
+ queryWrapper.last("limit 30");
|
|
|
|
+ List<KuaiShouGroupTemplate> list = this.list(queryWrapper);
|
|
|
|
+ if (Check.isNull(list)) {
|
|
|
|
+ log.error("暂未未创建的组");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ for (KuaiShouGroupTemplate template : list) {
|
|
|
|
+ executorService.submit(new Runnable() {
|
|
|
|
+ @Override
|
|
|
|
+ public void run() {
|
|
|
|
+ Long accountId = template.getAccountId();
|
|
|
|
+ CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
|
|
|
|
+ if (Check.isNull(token)) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ KuaiShouGroupTemplate updateTemplate = new KuaiShouGroupTemplate();
|
|
|
|
+ updateTemplate.setId(template.getId());
|
|
|
|
+ updateTemplate.setTaskStatus(1);
|
|
|
|
+ updateById(updateTemplate); // 修改状态为创建中
|
|
|
|
+ JSONObject createUnitJson = new JSONObject();
|
|
|
|
+ createUnitJson.put("campaign_id", template.getCampaignId());
|
|
|
|
+ createUnitJson.put("unit_name", template.getUnitName());
|
|
|
|
+
|
|
|
|
+ if (!Check.isNull(template.getTemplateId())) {
|
|
|
|
+ createUnitJson.put("template_id", template.getTemplateId());
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(template.getBidType())) {
|
|
|
|
+ createUnitJson.put("bid_type", template.getBidType()); // 优化目标类型
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(template.getUseAppMarket())) {
|
|
|
|
+ createUnitJson.put("use_app_market", template.getUseAppMarket()); //优先从系统应用商店下载
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(template.getAppStore())) {
|
|
|
|
+ createUnitJson.put("app_store", template.getAppStore()); //应用商店列表
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(template.getBid())) {
|
|
|
|
+ createUnitJson.put("bid", template.getBid()); //出价
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(template.getCpaBid())) {
|
|
|
|
+ createUnitJson.put("cpa_bid", template.getCpaBid()); //出价
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(template.getOcpxActionType())) {
|
|
|
|
+ createUnitJson.put("ocpx_action_type", template.getOcpxActionType()); //优化目标
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(template.getDeepConversionType())) {
|
|
|
|
+ createUnitJson.put("deep_conversion_type", template.getDeepConversionType()); //深度转化目标
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(template.getDeepConversionBid())) {
|
|
|
|
+ createUnitJson.put("deep_conversion_bid", template.getDeepConversionBid()); //深度转化目标出价
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(template.getSceneId())) {
|
|
|
|
+ createUnitJson.put("scene_id", template.getSceneId()); //资源位置
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(template.getUnitType())) {
|
|
|
|
+ createUnitJson.put("unit_type", template.getUnitType()); //创意制作方式
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(template.getBeginTime())) {
|
|
|
|
+ createUnitJson.put("begin_time", template.getBeginTime()); //投放开始时间
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(template.getEndTime())) {
|
|
|
|
+ createUnitJson.put("end_time", template.getEndTime()); //投放结束时间
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(template.getScheduleTime())) {
|
|
|
|
+ createUnitJson.put("schedule_time", template.getScheduleTime()); //投放时间段
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(template.getDayBudget())) {
|
|
|
|
+ createUnitJson.put("day_budget", template.getDayBudget()); //单日预算金额
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(template.getConvertId())) {
|
|
|
|
+ createUnitJson.put("convert_id", template.getConvertId()); //转化目标ID
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(template.getUnitType())) {
|
|
|
|
+ createUnitJson.put("url_type", template.getUnitType()); //url类型
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(template.getUrl())) {
|
|
|
|
+ createUnitJson.put("url", template.getUrl()); // 投放链接
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(template.getAppId())) {
|
|
|
|
+ createUnitJson.put("app_id", template.getAppId()); // 应用ID
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(template.getShowMode())) {
|
|
|
|
+ createUnitJson.put("show_mode", template.getShowMode()); // 创意展现方式
|
|
|
|
+ }
|
|
|
|
+ if (!Check.isNull(template.getSpeed())) {
|
|
|
|
+ createUnitJson.put("speed", template.getSpeed()); // 投放方式
|
|
|
|
+ }
|
|
|
|
+ Map<String, Object> groupMap = iKuaishouInterfaceService.adUnitCreate(token.getAccessToken(), accountId, createUnitJson, 1);
|
|
|
|
+ updateTemplate = new KuaiShouGroupTemplate();
|
|
|
|
+ updateTemplate.setId(template.getId());
|
|
|
|
+ Integer code = (Integer) groupMap.get("code");
|
|
|
|
+ if (code == 0) {
|
|
|
|
+ updateTemplate.setTaskStatus(2);
|
|
|
|
+ updateTemplate.setCreativeReviewDetail("创意待创建");
|
|
|
|
+ Long unit = (Long) groupMap.get("unitId");
|
|
|
|
+ updateTemplate.setUnitId((unit));
|
|
|
|
+ Thread thread = new Thread() {
|
|
|
|
+ @Override
|
|
|
|
+ public void run() {
|
|
|
|
+ createCreative(token.getAccessToken(), unit, template);
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ thread.start();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+ updateTemplate.setTaskStatus(3);
|
|
|
|
+ updateTemplate.setReviewDetail((String) groupMap.get("message"));
|
|
|
|
+ }
|
|
|
|
+ updateById(updateTemplate);
|
|
|
|
+ try {
|
|
|
|
+ Thread.sleep(1 * 1000);
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Integer getApiCreateCount(Long accountId, String date) {
|
|
|
|
+ return groupTemplateMapper.getApiCreateCount(accountId, date);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public JSONObject getUrlByPhotoId(Long photoId) {
|
|
|
|
+ return groupTemplateMapper.getUrlByPhotoId(photoId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private void createCreative(String accessToken, Long unitId, KuaiShouGroupTemplate template) {
|
|
|
|
+ Long photoId = template.getPhotoId();
|
|
|
|
+ JSONObject md5Json = groupTemplateMapper.getMd5ByPhotoId(photoId);
|
|
|
|
+ if (Check.isNull(md5Json)) {
|
|
|
|
+ log.error("未获取到素材详细信息,accountId:{},unitId:{}", template.getAccountId(), unitId);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ String md5 = md5Json.getString("md5");
|
|
|
|
+ List<JSONObject> imageList = groupTemplateMapper.getImageListByMd5(md5);
|
|
|
|
+ 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", template.getCreativeTag());
|
|
|
|
+ }
|
|
|
|
+ Integer materialType = md5Json.getInteger("materialType");
|
|
|
|
+ JSONArray creatives = new JSONArray();
|
|
|
|
+ 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 signature = imageJson.getString("md5");
|
|
|
|
+ String imageToken = null;
|
|
|
|
+ if (!Check.isNull(signature)) {
|
|
|
|
+ QueryWrapper<KuaiShouImageGet> queryWrapper = new QueryWrapper<>();
|
|
|
|
+ queryWrapper.eq("account_id", template.getAccountId());
|
|
|
|
+ queryWrapper.eq("signature", signature);
|
|
|
|
+ queryWrapper.last("limit 1");
|
|
|
|
+ KuaiShouImageGet imageGet = imageGetService.getOne(queryWrapper);
|
|
|
|
+ if (!Check.isNull(imageGet)) {
|
|
|
|
+ imageToken = imageGet.getImageToken();
|
|
|
|
+ } else {
|
|
|
|
+ String url = imageJson.getString("url");
|
|
|
|
+ imageToken = uploadService.kuauiShouImageUpload(url, signature, template.getAccountId(), accessToken);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ createJson.put("creatives", creatives);
|
|
|
|
+ Map<String, Object> creativeMap = iKuaishouInterfaceService.batchCreativeCreate(accessToken, template.getAccountId(), createJson, 1, template.getUserId());
|
|
|
|
+ KuaiShouGroupTemplate updateTemplate = new KuaiShouGroupTemplate();
|
|
|
|
+ updateTemplate.setId(template.getId());
|
|
|
|
+ Integer code = (Integer) creativeMap.get("code");
|
|
|
|
+ if (code == 0) {
|
|
|
|
+ updateTemplate.setCreativeReviewDetail("创意创建成功");
|
|
|
|
+ updateTemplate.setCreateCreativeCount((Integer) creativeMap.get("count"));
|
|
|
|
+ } else {
|
|
|
|
+ updateTemplate.setCreativeReviewDetail("创意创建失败:" + creativeMap.get("message"));
|
|
|
|
+ }
|
|
|
|
+ this.updateById(updateTemplate);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|