Browse Source

修好创意数据获取

yumeng 5 years ago
parent
commit
27869e5b5e

+ 53 - 9
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouInterfaceServiceImpl.java

@@ -1870,7 +1870,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                     creative.setCreativeId(detailJson.getLong("creative_id"));
                     creative.setCreativeName(detailJson.getString("creative_name"));
                     creative.setCreativeMaterialType(detailJson.getInteger("creative_material_type"));
-                    creative.setPhotoId(detailJson.getString("photo_id"));
+                    //  creative.setPhotoId(detailJson.getString("photo_id"));
                     if (!Check.isNull(detailJson.getJSONArray("material_url"))) {
                         creative.setMaterialUrl(detailJson.getJSONArray("material_url").toJSONString());
                     }
@@ -1900,7 +1900,30 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                     }
                     creative.setCreateTime(new Date());
                     creative.setUpdateTime(new Date());
-                    creatives.add(creative);
+
+
+                    if (detailJson.getLong("photo_id") == 0) {
+                        JSONObject programmed_creative_material = detailJson.getJSONObject("programmed_creative_material");
+                        if (!Check.isNull(programmed_creative_material)) {
+                            JSONArray materials = programmed_creative_material.getJSONArray("materials");
+                            if (!Check.isNull(materials)) {
+                                for (int j = 0; j < materials.size(); j++) {
+                                    JSONObject materialJson = materials.getJSONObject(j);
+                                    if (!Check.isNull(materialJson)) {
+                                        Long photo_id = materialJson.getLong("photo_id");
+                                        creative.setPhotoId(String.valueOf(photo_id));
+                                        creatives.add(creative);
+                                    }
+                                }
+                            }
+                        }
+
+                    } else {
+                        creative.setPhotoId(detailJson.getString("photo_id"));
+                        creatives.add(creative);
+                    }
+
+
                 }
             }
             creativeService.replaceBatch(creatives);
@@ -1955,7 +1978,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                     creative.setCreativeId(detailJson.getLong("creative_id"));
                     creative.setCreativeName(detailJson.getString("creative_name"));
                     creative.setCreativeMaterialType(detailJson.getInteger("creative_material_type"));
-                    creative.setPhotoId(detailJson.getString("photo_id"));
+                    //
                     if (!Check.isNull(detailJson.getJSONArray("material_url"))) {
                         creative.setMaterialUrl(detailJson.getJSONArray("material_url").toJSONString());
                     }
@@ -1978,19 +2001,40 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                     creative.setClickTrackUrl(detailJson.getString("click_track_url"));
                     creative.setImpressionUrl(detailJson.getString("impression_url"));
                     creative.setAdPhotoPlayedT3sUrl(detailJson.getString("ad_photo_played_t3s_url"));
+                    creative.setCreativeCreateTime(detailJson.getDate("create_time"));
+                    creative.setCreativeUpdateTime(detailJson.getDate("update_time"));
+                    creative.setFirstFrameType(detailJson.getInteger("first_frame_type"));
                     JSONObject displayInfoJson = detailJson.getJSONObject("display_info");
                     if (!Check.isNull(displayInfoJson)) {
                         creative.setDescription(displayInfoJson.getString("description"));
                         creative.setActionBarText(displayInfoJson.getString("action_bar_text"));
                     }
-
-                    creative.setFirstFrameType(detailJson.getInteger("first_frame_type"));
-                    creative.setCreativeCreateTime(detailJson.get("create_time") == null ? null : detailJson.getDate("create_time"));
-                    creative.setCreativeUpdateTime(detailJson.get("update_time") == null ? null : detailJson.getDate("update_time"));
-
                     creative.setCreateTime(new Date());
                     creative.setUpdateTime(new Date());
-                    creatives.add(creative);
+
+                    if (detailJson.getLong("photo_id") == 0) {
+                        JSONObject programmed_creative_material = detailJson.getJSONObject("programmed_creative_material");
+                        if (!Check.isNull(programmed_creative_material)) {
+                            JSONArray materials = programmed_creative_material.getJSONArray("materials");
+                            if (!Check.isNull(materials)) {
+                                for (int j = 0; j < materials.size(); j++) {
+                                    JSONObject materialJson = materials.getJSONObject(j);
+                                    if (!Check.isNull(materialJson)) {
+                                        Long photo_id = materialJson.getLong("photo_id");
+                                        creative.setPhotoId(String.valueOf(photo_id));
+                                        creatives.add(creative);
+                                    }
+                                }
+                            }
+                        }
+
+
+                    } else {
+                        creative.setPhotoId(detailJson.getString("photo_id"));
+                        creatives.add(creative);
+                    }
+
+
                 }
             }
             creativeService.replaceBatch(creatives);