yumeng 4 năm trước cách đây
mục cha
commit
87ac864e31

+ 2 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/KuaiShouGroupTemplate.java

@@ -214,7 +214,8 @@ public class KuaiShouGroupTemplate {
     private Integer createCreativeCount;
     private Integer creativeStatus;
     private String creativeReviewDetail;
-
+    private Integer createType;
+    private String photoIds;
 
     /**
      * 创建时间

+ 2 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/KuaiShouGroupTemplateMapper.java

@@ -23,4 +23,6 @@ public interface KuaiShouGroupTemplateMapper extends BaseMapper<KuaiShouGroupTem
     Integer getApiCreateCount(@Param("accountId") Long accountId, @Param("date") String date);
 
     JSONObject getUrlByPhotoId(@Param("photoId") Long photoId);
+
+    JSONObject getImageJsonByMd5(String md5);
 }

+ 11 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaiShouGroupTemplateMapper.xml

@@ -18,8 +18,18 @@
       url as 'url'
       from ctop_material_cut_frame
       where video_signature = #{md5}
-      limit 6
+       ORDER BY RAND() LIMIT 6
     </select>
+    <select id="getImageJsonByMd5" resultType="com.alibaba.fastjson.JSONObject">
+      select
+      signature as 'md5',
+      url as 'url'
+      from ctop_material_cut_frame
+      where video_signature = #{md5}
+       ORDER BY RAND() LIMIT 1
+    </select>
+
+
     <select id="getApiCreateCount" resultType="java.lang.Integer">
     select count(1)
     from

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

@@ -72,11 +72,21 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
         if (Check.isNull(photoArr)) {
             throw new Exception("请选择需要创建的视频");
         }
-        if (createCount != photoArr.size()) {
-            throw new Exception("视频数量必须和创建数量保持一致");
+
+        Integer createType = requestJson.getInteger("createType"); // 创建类型 0 单品 1 混搭
+        if (Check.isNull(createType)) {
+            throw new Exception("请选择创意创建方式混搭、单品");
+        }
+
+        if (createType == 0 && createCount != photoArr.size()) {
+            throw new Exception("单品视频数量必须和创建数量保持一致");
         }
-        JSONObject returnJson = new JSONObject();
 
+        if (createType == 1 && createCount * 15 != 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");
@@ -109,16 +119,27 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
         String description = requestJson.getString("description");
         Long site_id = requestJson.getLong("siteId");
 
+
         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.setCreateType(createType);
+            if (createType == 0) { // 创建方式为单品
+                Long photoId = photoArr.getLong(i);
+                template.setPhotoId(photoId);
+            } else if (createType == 1) { // 创建方式为混搭
+                JSONArray photoIds = getPhotoIds(photoArr, i);
+                if (Check.isNull(photoIds)) {
+                    log.error("根据下标未获取到详细信息");
+                    continue;
+                }
+                template.setPhotoIds(photoIds.toJSONString());
+            }
+            String name = unitName + "_" + i;
             template.setAccountId(accountId);
             template.setUserId(userId);
             template.setCampaignId(campaignId);
             template.setUnitName(name);
-            template.setPhotoId(photoId);
             if (!Check.isNull(template_id)) {
                 template.setTemplateId(template_id);
             }
@@ -227,6 +248,29 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
     }
 
 
+    private JSONArray getPhotoIds(JSONArray photoArr, Integer index) {
+        JSONArray array = new JSONArray();
+        Integer minIndex;
+        Integer maxIndex;
+        if (index == 0) {
+            maxIndex = (index + 1) * 15 - 1;
+            minIndex = index;
+        } else {
+            maxIndex = (index + 1) * 15 - 1;
+            minIndex = index * 15;
+        }
+        for (int i = 0; i < photoArr.size(); i++) {
+            if (minIndex > maxIndex) {
+                break;
+            }
+            Long photoId = photoArr.getLong(minIndex);
+            array.add(photoId);
+            minIndex++;
+        }
+        return array;
+    }
+
+
     /**
      * 创建组
      */
@@ -489,7 +533,6 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
         return groupTemplateMapper.getUrlByPhotoId(photoId);
     }
 
-
     /**
      * 创建创意
      *
@@ -504,17 +547,6 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
         updateTemplate.setCreativeStatus(1);
         updateTemplate.setCreativeReviewDetail("创意创建中");
         this.updateById(updateTemplate);
-        Long photoId = template.getPhotoId();
-        JSONObject md5Json = groupTemplateMapper.getMd5ByPhotoId(photoId);
-        if (Check.isNull(md5Json)) {
-            log.error("未获取到素材详细信息,accountId:{},unitId:{}", template.getAccountId(), unitId);
-            updateTemplate.setCreativeStatus(3);
-            updateTemplate.setCreativeReviewDetail("未获取到素材信息");
-            this.updateById(updateTemplate);
-            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())) {
@@ -529,51 +561,91 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
         if (!Check.isNull(template.getCreativeTag())) {
             createJson.put("creative_tag", JSONArray.parseArray(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;
-                }
+        Integer createType = template.getCreateType();
+        if (createType == 0) { // 单品
+            Long photoId = template.getPhotoId();
+            JSONObject videoMd5Json = groupTemplateMapper.getMd5ByPhotoId(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);
+            if (Check.isNull(imageList)) {
                 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);
+                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);
+                    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);
                 }
-                if (Check.isNull(imageToken)) {
-                    continue;
+            }
+        } 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(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);
+                    if (!Check.isNull(imageToken)) {
+                        json.put("image_token", imageToken);
+                    }
                 }
-                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())) {
+                if (!Check.isNull(template.getSiteId())) {
                     json.put("site_id", template.getSiteId());
                 }
                 creatives.add(json);
@@ -592,4 +664,29 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
         }
         this.updateById(updateTemplate);
     }
+
+
+    private String getImageToken(String md5, Long accountId, String accessToken) {
+        JSONObject imageJson = groupTemplateMapper.getImageJsonByMd5(md5);
+        String imageToken = null;
+        if (!Check.isNull(imageJson)) {
+            String signature = imageJson.getString("md5");
+            if (!Check.isNull(signature)) {
+                QueryWrapper<KuaiShouImageGet> queryWrapper = new QueryWrapper<>();
+                queryWrapper.eq("account_id", accountId);
+                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, accountId, accessToken);
+                }
+            }
+        }
+
+        return imageToken;
+
+    }
 }