Procházet zdrojové kódy

批量应用添加通配符

zhaoxian před 2 roky
rodič
revize
2090c47825

+ 35 - 11
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouBatchCampaignPreviewServiceImpl.java

@@ -4,6 +4,7 @@ import cn.com.ctop.common.module.enums.SceneIdEnum;
 import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouAppList;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouCampaign;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouBatchCampaignPreview;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouBatchCreativePreview;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouBatchGroupPreview;
@@ -13,6 +14,7 @@ import cn.com.ctop.kuaishou.modules.batch.mapper.KuaishouBatchCampaignPreviewMap
 import cn.com.ctop.kuaishou.modules.batch.mapper.KuaishouBatchCreativePreviewMapper;
 import cn.com.ctop.kuaishou.modules.batch.mapper.KuaishouBatchGroupPreviewMapper;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouAppListService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouVideoGetService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouBatchCampaignPreviewService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouTemplateService;
 import com.alibaba.excel.util.CollectionUtils;
@@ -56,6 +58,8 @@ public class KuaishouBatchCampaignPreviewServiceImpl extends ServiceImpl<Kuaisho
     private IKuaiShouAppListService kuaiShouAppListService;
     @Resource
     private KuaiShouCampaignMapper kuaiShouCampaignMapper;
+    @Autowired
+    private IKuaiShouVideoGetService videoGetService;
 
     @Override
     public JSONObject queryByBatchId(String batchId, String accountId) {
@@ -337,7 +341,7 @@ public class KuaishouBatchCampaignPreviewServiceImpl extends ServiceImpl<Kuaisho
                 }
                 if (Check.isNull(campaignId)) {
                     campaignPreview.setId(null);
-                    campaignPreview.setCampaignName(getName(campaignPreview.getCampaignNameFormat(), targetIds.getLong(i), null, appId, null) + i);
+                    campaignPreview.setCampaignName(getName(campaignPreview.getCampaignNameFormat(), targetIds.getLong(i), groupPreview.getSceneId(), appId, groupPreview.getUnitType(), i, getRandomFromArr(materialList.getJSONObject(0).getJSONArray("photoArr")), creativePreview.getCreativeCategory()));
                     campaignPreviewMapper.insert(campaignPreview);
                 }
                 for (int j = 0; j < materialList.size(); j++) {
@@ -366,11 +370,15 @@ public class KuaishouBatchCampaignPreviewServiceImpl extends ServiceImpl<Kuaisho
                     if (playableAllocation == 3 && !Check.isNull(playableIds)) {
                         groupPreview.setPlayableId(getPlayableId(playableIds, j + 1));
                     }
+
+                    JSONObject material = materialList.getJSONObject(j);
+                    JSONArray photoArr = material.getJSONArray("photoArr");
+
                     groupPreview.setId(null);
                     groupPreview.setAppId(appId);
                     groupPreview.setPlanId(campaignPreview.getId());
                     groupPreview.setTemplateId(targetIds.getLong(i));
-                    groupPreview.setUnitName(getName(groupPreview.getUnitNameFormat(), targetIds.getLong(i), groupPreview.getSceneId(), appId, groupPreview.getUnitType()) + j);
+                    groupPreview.setUnitName(getName(groupPreview.getUnitNameFormat(), targetIds.getLong(i), groupPreview.getSceneId(), appId, groupPreview.getUnitType(), j, getRandomFromArr(photoArr), creativePreview.getCreativeCategory()));
                     groupPreview.setUrl(url);
                     groupPreview.setSchemaUri(schemaUri);
                     if (!Check.isNull(groupPreview.getBidMax()) && !Check.isNull(groupPreview.getBidMin())) {
@@ -383,8 +391,7 @@ public class KuaishouBatchCampaignPreviewServiceImpl extends ServiceImpl<Kuaisho
                     }
                     groupPreview.setPlayButton(appList.getString("playButton"));
                     groupPreviewMapper.insert(groupPreview);
-                    JSONObject material = materialList.getJSONObject(j);
-                    JSONArray photoArr = material.getJSONArray("photoArr");
+
                     if (groupPreview.getUnitType() == 4) {
                         if (matchingMethod == 2) {
                             //创意匹配
@@ -487,12 +494,13 @@ public class KuaishouBatchCampaignPreviewServiceImpl extends ServiceImpl<Kuaisho
                 if (playableAllocation == 2 && !Check.isNull(playableIds)) {
                     groupPreview.setPlayableId(getPlayableId(playableIds, i + 1));
                 }
+                JSONObject material = materialList.getJSONObject(i);
+                JSONArray photoArr = material.getJSONArray("photoArr");
 
                 campaignPreview.setId(null);
-                campaignPreview.setCampaignName(getName(campaignPreview.getCampaignNameFormat(), null, null, appId, null) + i);
+                campaignPreview.setCampaignName(getName(campaignPreview.getCampaignNameFormat(), getRandomFromArr(targetIds), groupPreview.getSceneId(), appId, groupPreview.getUnitType(), i, getRandomFromArr(photoArr), creativePreview.getCreativeCategory()));
                 campaignPreviewMapper.insert(campaignPreview);
-                JSONObject material = materialList.getJSONObject(i);
-                JSONArray photoArr = material.getJSONArray("photoArr");
+
                 if (matchingMethod == 2) {
                     //创意匹配
                     descriptionList = advertisingSlogan(descriptionList, photoArr);
@@ -527,7 +535,7 @@ public class KuaishouBatchCampaignPreviewServiceImpl extends ServiceImpl<Kuaisho
                     groupPreview.setAppId(appId);
                     groupPreview.setPlanId(campaignPreview.getId());
                     groupPreview.setTemplateId(targetIds.getLong(j));
-                    groupPreview.setUnitName(getName(groupPreview.getUnitNameFormat(), targetIds.getLong(j), groupPreview.getSceneId(), appId, groupPreview.getUnitType()) + j);
+                    groupPreview.setUnitName(getName(groupPreview.getUnitNameFormat(), targetIds.getLong(j), groupPreview.getSceneId(), appId, groupPreview.getUnitType(), j, getRandomFromArr(photoArr), creativePreview.getCreativeCategory()));
                     groupPreview.setUrl(url);
                     groupPreview.setSchemaUri(schemaUri);
                     if (!Check.isNull(groupPreview.getBidMax()) && !Check.isNull(groupPreview.getBidMin())) {
@@ -771,6 +779,11 @@ public class KuaishouBatchCampaignPreviewServiceImpl extends ServiceImpl<Kuaisho
         }
     }
 
+    private static Long getRandomFromArr(JSONArray list) {
+        int i = new Random().nextInt(list.size());
+        return list.getLong(i);
+    }
+
     /**
      * 整理通用创意数据
      *
@@ -800,9 +813,12 @@ public class KuaishouBatchCampaignPreviewServiceImpl extends ServiceImpl<Kuaisho
      * @param sceneId    广告位置ID
      * @param appId      应用包id、渠道号
      * @param unitType   创意制作方式
+     *                   应用名称+定向包+日期+渠道号(应用标记)
+     *                   日期、序号、应用标记、素材命名、定向包名称、创意分类
      * @return
      */
-    private String getName(String content, Long templateId, String sceneId, Integer appId, Integer unitType) {
+    private String getName(String content, Long templateId, String sceneId, Integer appId, Integer unitType
+            , Integer number, Long photoId, Integer creativeCategory) {
         String reg = "\\{\\{(.+?)\\}\\}";
         List<String> params = getParams(reg, content);
         if (Check.isNull(params)) {
@@ -851,10 +867,18 @@ public class KuaishouBatchCampaignPreviewServiceImpl extends ServiceImpl<Kuaisho
                 if (!Check.isNull(unitType)) {
                     data.put(regName, unitType == 4 ? "自定义" : "程序化创意2.0");
                 }
+            } else if ("序号".equals(regName)) {
+                data.put(regName, number + "");
+            } else if ("素材命名".equals(photoId)) {
+                KuaiShouVideoGet video = videoGetService.getVideoByPhotoId(photoId);
+                if (!Check.isNull(video)) {
+                    data.put(regName, video.getPhotoName());
+                }
+            } else if ("创意分类".equals(regName)) {
+                data.put(regName, creativeCategory + "");
             }
         }
-        String text = parse(reg, content, data);
-        return text;
+        return parse(reg, content, data);
     }