Kaynağa Gözat

批量2.0添加程序化

zhaoxian 3 yıl önce
ebeveyn
işleme
ed7efb1dee

+ 35 - 1
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/KuaiShouTitleCollectionController.java

@@ -3,6 +3,8 @@ package cn.com.ctop.kuaishou.modules.batch.controller;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouTitleCollection;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouTitleCollectionService;
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -19,7 +21,15 @@ import org.jeecgframework.poi.excel.entity.ExportParams;
 import org.jeecgframework.poi.excel.entity.ImportParams;
 import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.multipart.MultipartHttpServletRequest;
 import org.springframework.web.servlet.ModelAndView;
@@ -97,6 +107,30 @@ public class KuaiShouTitleCollectionController {
     }
 
     /**
+     * 添加
+     *
+     * @param kuaiShouTitleCollection
+     * @return
+     */
+    @PostMapping(value = "/addMore")
+    public Result<KuaiShouTitleCollection> addMore(@RequestBody JSONObject data) {
+        Result<KuaiShouTitleCollection> result = new Result<>();
+        try {
+            JSONArray titles = data.getJSONArray("titles");
+            KuaiShouTitleCollection kuaiShouTitleCollection = JSONObject.parseObject(data.toJSONString(), KuaiShouTitleCollection.class);
+            for (Object title : titles) {
+                kuaiShouTitleCollection.setTitle(title.toString());
+                kuaiShouTitleCollectionService.save(kuaiShouTitleCollection);
+            }
+            result.success("添加成功!");
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            result.error500("操作失败");
+        }
+        return result;
+    }
+
+    /**
      * 编辑
      *
      * @param kuaiShouTitleCollection

+ 40 - 26
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouGroupTemplateServiceImpl.java

@@ -6,7 +6,6 @@ import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.HttpUtils;
 import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
 import cn.com.ctop.common.module.utils.PropertiesUtils;
-import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouAccountAutoVideo;
 import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouLandpagePackageService;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouGroupTemplate;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouImageGet;
@@ -34,6 +33,7 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Random;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
@@ -89,9 +89,11 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
             throw new Exception("请选择需要创建的视频");
         }
 
+        Integer imageCount = requestJson.getInteger("imageCount");
 
         Integer createType = requestJson.getInteger("createType"); // 创建类型 0 单品 1 混搭
         Integer unitType = requestJson.getInteger("unitType"); // 7程序化。4自定义
+        List<List<String>> photoIdsList = null;
         if (unitType == 4) {
             if (Check.isNull(createType)) {
                 throw new Exception("请选择创意创建方式混搭、单品");
@@ -104,6 +106,12 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
             if (createType == 1 && createCount * 15 != photoArr.size()) {
                 throw new Exception("混搭视频数量必须和创建数量保持倍数关系");
             }
+        } else {
+            List<String> photoIds = JSONArray.parseObject(photoArr.toJSONString(), List.class);
+            photoIdsList = Lists.newArrayList(Lists.partition(photoIds, imageCount));
+            if (createCount != photoIdsList.size()) {
+                throw new Exception("程序化视频数量必须和创建数量保持倍数关系");
+            }
         }
         JSONObject returnJson = new JSONObject();
         String userId = requestJson.getString("userId");
@@ -144,7 +152,6 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
                 startNumber = requestJson.getInteger("startNumber");
             }
         }
-        Integer imageCount = requestJson.getInteger("imageCount");
 
         List<KuaiShouGroupTemplate> templates = new ArrayList<>();
         for (int i = 0; i < createCount; i++) {
@@ -160,6 +167,8 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
                     continue;
                 }
                 template.setPhotoIds(photoIds.toJSONString());
+            } else {
+                template.setPhotoIds(photoIdsList.get(i).toString());
             }
             String name = "";
             if (!unitName.contains("{{序号}}")) {
@@ -638,6 +647,14 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
             createJson.put("creative_tag", JSONArray.parseArray(template.getCreativeTag()));
         }
 
+        JSONArray descriptionList = JSONArray.parseArray(template.getDescription());
+        String description = null;
+        if (!Check.isNull(descriptionList)) {
+            int number = new Random().nextInt(descriptionList.size());
+            description = descriptionList.getString(number);
+        }
+
+
         JSONArray creatives = new JSONArray();
         Integer createType = template.getCreateType();
         if (createType == 0) { // 单品
@@ -659,7 +676,7 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
                 json.put("photo_id", template.getPhotoId());
                 json.put("creative_material_type", materialType);
                 json.put("action_bar_text", template.getActionBarText());
-                json.put("description", template.getDescription());
+                json.put("description", description);
                 if (!Check.isNull(template.getSiteId())) {
                     json.put("site_id", template.getSiteId());
                 }
@@ -681,7 +698,7 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
                     json.put("photo_id", template.getPhotoId());
                     json.put("creative_material_type", materialType);
                     json.put("action_bar_text", template.getActionBarText());
-                    json.put("description", template.getDescription());
+                    json.put("description", description);
                     if (!Check.isNull(template.getSiteId())) {
                         json.put("site_id", template.getSiteId());
                     }
@@ -720,7 +737,7 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
                 json.put("photo_id", photoId);
                 json.put("creative_material_type", materialType);
                 json.put("action_bar_text", template.getActionBarText());
-                json.put("description", template.getDescription());
+                json.put("description", description);
                 if (!Check.isNull(template.getSiteId())) {
                     json.put("site_id", template.getSiteId());
                 }
@@ -801,28 +818,25 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
         //作品广告语
         createJson.put("captions", getCaptions(template.getDescription()));
 
-        List<List<KuaiShouVideoGet>> splitVideos = Lists.newArrayList(Lists.partition(videos, imageCount));
-        for (List<KuaiShouVideoGet> splitVideo : splitVideos) {
-            JSONArray photoList = new JSONArray();
-            for (KuaiShouVideoGet video : splitVideo) {
-                JSONObject photo = new JSONObject();
-                photo.put("photo_id", video.getPhotoId());//视频 ID
-                photo.put("cover_image_token", null);//封面图片 token,通过上传图片接口获得,不传值则直接使用视频的首帧作为封面图片
-                photo.put("creative_material_type", video.getMaterialType());//1:竖版视频 2:横版视频
-                photoList.add(photo);
-            }
-            createJson.put("photo_list", photoList);
-            Map<String, Object> creativeMap = this.createProgramCreatives(accountId, accessToken, createJson, 1);
-            Integer code = (Integer) creativeMap.get("code");
-            if (code == 0) {
-                updateTemplate.setCreativeStatus(2);
-                updateTemplate.setCreativeReviewDetail("创建程序化2.0创意成功");
-            } else {
-                updateTemplate.setCreativeStatus(3);
-                updateTemplate.setCreativeReviewDetail((String) creativeMap.get("message"));
-            }
-            this.updateById(updateTemplate);
+        JSONArray photoList = new JSONArray();
+        for (KuaiShouVideoGet video : videos) {
+            JSONObject photo = new JSONObject();
+            photo.put("photo_id", video.getPhotoId());//视频 ID
+            photo.put("cover_image_token", null);//封面图片 token,通过上传图片接口获得,不传值则直接使用视频的首帧作为封面图片
+            photo.put("creative_material_type", video.getMaterialType());//1:竖版视频 2:横版视频
+            photoList.add(photo);
+        }
+        createJson.put("photo_list", photoList);
+        Map<String, Object> creativeMap = this.createProgramCreatives(accountId, accessToken, createJson, 1);
+        Integer code = (Integer) creativeMap.get("code");
+        if (code == 0) {
+            updateTemplate.setCreativeStatus(2);
+            updateTemplate.setCreativeReviewDetail("创建程序化2.0创意成功");
+        } else {
+            updateTemplate.setCreativeStatus(3);
+            updateTemplate.setCreativeReviewDetail((String) creativeMap.get("message"));
         }
+        this.updateById(updateTemplate);
     }
 
     /**