yumeng 4 年 前
コミット
dff2bee320

+ 154 - 12
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouGroupTemplateServiceImpl.java

@@ -5,11 +5,9 @@ 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.entity.KuaishouTemplateTarget;
 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 cn.com.ctop.kuaishou.modules.batch.service.*;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -44,10 +42,18 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
     private IKuaiShouImageGetService imageGetService;
     @Autowired
     private IKuaiShouMaterialUploadService uploadService;
+    @Autowired
+    private IKuaishouTemplateTargetService templateTargetService;
 
     static ExecutorService executorService = Executors.newFixedThreadPool(5);
 
-
+    /**
+     * 提交创建任务
+     *
+     * @param requestJson
+     * @return
+     * @throws Exception
+     */
     @Override
     public JSONObject submitUnitTask(JSONObject requestJson) throws Exception {
         Long accountId = requestJson.getLong("accountId");
@@ -220,6 +226,10 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
         return returnJson;
     }
 
+
+    /**
+     * 创建组
+     */
     @Override
     public void createUnit() {
         QueryWrapper<KuaiShouGroupTemplate> queryWrapper = new QueryWrapper<>();
@@ -245,12 +255,39 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
                     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());
+                    JSONArray sceneIdArr = JSONArray.parseArray(template.getSceneId());
+                    if (Check.isNull(sceneIdArr)) {
+                        updateTemplate.setTaskStatus(3);
+                        updateTemplate.setReviewDetail("scene_id不能为空");
+                        updateTemplate.setCreativeStatus(3);
+                        updateTemplate.setCreativeReviewDetail("组创建失败");
+                        updateById(updateTemplate);
+                        return;
+                    }
+                    createUnitJson.put("scene_id", sceneIdArr); //资源位置
+                    Integer sceneId = (Integer) sceneIdArr.get(0);
+                    if (sceneId != 5) {
+                        if (!Check.isNull(template.getTemplateId())) {
+                            createUnitJson.put("template_id", template.getTemplateId());
+                        }
+                    } else {
+                        if (!Check.isNull(template.getTemplateId())) {
+                            JSONObject unionJson = getUnionJson(template.getTemplateId());
+                            if (unionJson.getInteger("code") != 0) {
+                                updateTemplate.setTaskStatus(3);
+                                updateTemplate.setReviewDetail(unionJson.getString("message"));
+                                updateTemplate.setCreativeStatus(3);
+                                updateTemplate.setCreativeReviewDetail("组创建失败");
+                                updateById(updateTemplate);
+                                return;
+                            } else {
+                                createUnitJson.put("target", unionJson.getJSONObject("target"));
+                            }
+                        }
                     }
+                    createUnitJson.put("campaign_id", template.getCampaignId());
+                    createUnitJson.put("unit_name", template.getUnitName());
                     if (!Check.isNull(template.getBidType())) {
                         createUnitJson.put("bid_type", template.getBidType()); // 优化目标类型
                     }
@@ -275,9 +312,6 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
                     if (!Check.isNull(template.getDeepConversionBid())) {
                         createUnitJson.put("deep_conversion_bid", template.getDeepConversionBid()); //深度转化目标出价
                     }
-                    if (!Check.isNull(template.getSceneId())) {
-                        createUnitJson.put("scene_id", JSONArray.parseArray(template.getSceneId())); //资源位置
-                    }
                     if (!Check.isNull(template.getUnitType())) {
                         createUnitJson.put("unit_type", template.getUnitType()); //创意制作方式
                     }
@@ -344,17 +378,125 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
 
     }
 
+
+    /**
+     * 根据模板id 获取联盟定向
+     *
+     * @return
+     */
+    private JSONObject getUnionJson(Long templateId) {
+        JSONObject returnJson = new JSONObject();
+        QueryWrapper<KuaishouTemplateTarget> targetQueryWrapper = new QueryWrapper<>();
+        targetQueryWrapper.eq("template_id", templateId);
+        targetQueryWrapper.last("limit 1");
+        KuaishouTemplateTarget templateTarget = templateTargetService.getOne(targetQueryWrapper);
+        if (Check.isNull(templateTarget)) {
+            returnJson.put("code", -1);
+            returnJson.put("message", "根据模板id未获取到模板详情");
+            return returnJson;
+        }
+        JSONObject target = new JSONObject();
+        if (!Check.isNull(templateTarget.getRegion())) {
+            target.put("region", JSONArray.parseArray(templateTarget.getRegion()));
+        }
+
+        if (!Check.isNull(templateTarget.getMax()) && !Check.isNull(templateTarget.getMin())) {
+            JSONObject ageJson = new JSONObject();
+            if (!Check.isNull(templateTarget.getMax())) {
+                ageJson.put("max", templateTarget.getMax());
+            }
+            if (!Check.isNull(templateTarget.getMin())) {
+                ageJson.put("min", templateTarget.getMin());
+            }
+            target.put("age", ageJson);
+        }
+        if (!Check.isNull(templateTarget.getAgesRange())) {
+            target.put("ages_range", JSONArray.parseArray(templateTarget.getAgesRange()));
+        }
+
+        if (!Check.isNull(templateTarget.getGender())) {
+            target.put("gender", templateTarget.getGender());
+        }
+
+        if (!Check.isNull(templateTarget.getPlatformOs())) {
+            target.put("platform_os", templateTarget.getPlatformOs());
+        }
+
+        if (!Check.isNull(templateTarget.getAndroidOsv())) {
+            target.put("android_osv", templateTarget.getAndroidOsv());
+        }
+
+        if (!Check.isNull(templateTarget.getIosOsv())) {
+            target.put("ios_osv", templateTarget.getIosOsv());
+        }
+
+        if (!Check.isNull(templateTarget.getNetwork())) {
+            target.put("network", templateTarget.getNetwork());
+        }
+
+        if (!Check.isNull(templateTarget.getDeviceBrand())) {
+            target.put("device_brand", JSONArray.parseArray(templateTarget.getDeviceBrand()));
+        }
+
+        if (!Check.isNull(templateTarget.getDevicePrice())) {
+            target.put("device_price", JSONArray.parseArray(templateTarget.getDevicePrice()));
+        }
+
+        if (!Check.isNull(templateTarget.getAppInterest())) {
+            target.put("app_interest", JSONArray.parseArray(templateTarget.getAppInterest()));
+        }
+
+        if (!Check.isNull(templateTarget.getAppIds())) {
+            target.put("app_ids", JSONArray.parseArray(templateTarget.getAppIds()));
+        }
+
+        if (!Check.isNull(templateTarget.getPopulation())) {
+            target.put("population", templateTarget.getPopulation());
+        }
+
+        if (!Check.isNull(templateTarget.getExcludePopulation())) {
+            target.put("exclude_population", templateTarget.getExcludePopulation());
+        }
+
+        if (!Check.isNull(templateTarget.getPaidAudience())) {
+            target.put("paid_audience", templateTarget.getPaidAudience());
+        }
+        returnJson.put("target", target);
+        returnJson.put("code", 0);
+        return returnJson;
+    }
+
+    /**
+     * 获取当天api创建创意数
+     *
+     * @param accountId
+     * @param date
+     * @return
+     */
     @Override
     public Integer getApiCreateCount(Long accountId, String date) {
         return groupTemplateMapper.getApiCreateCount(accountId, date);
     }
 
+    /**
+     * 根据photoId 获取视频、封面链接
+     *
+     * @param photoId
+     * @return
+     */
     @Override
     public JSONObject getUrlByPhotoId(Long photoId) {
         return groupTemplateMapper.getUrlByPhotoId(photoId);
     }
 
 
+    /**
+     * 创建创意
+     *
+     * @param accessToken
+     * @param unitId
+     * @param template
+     */
     @Override
     public void createCreative(String accessToken, Long unitId, KuaiShouGroupTemplate template) {
         KuaiShouGroupTemplate updateTemplate = new KuaiShouGroupTemplate();