Jelajahi Sumber

组名称加入素材名称、日期通配符,批量2.0加入吊起链接

yumeng 4 tahun lalu
induk
melakukan
a66fce50d9

+ 9 - 2
jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java

@@ -17,6 +17,7 @@ import cn.com.ctop.toutiao.modules.report.service.*;
 import com.csvreader.CsvReader;
 import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.util.DateUtils;
+import org.jeecg.common.util.RedisUtil;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -49,12 +50,18 @@ public class SampleTest {
     private IKuaishouWebInterfaceService kuaishouWebInterfaceService;
     @Autowired
     private IKuaishouInterfaceService kuaishouInterfaceService;
+    @Autowired
+    private RedisUtil redisUtil;
 
     @Test
     public void loadKuaishouCookie() throws ParseException {
 
+        redisUtil.set("11sdfhgjksdhfjksdhfjksdhfkjsjkfhkjsddhfjksdhfkjhsjkfhjkshfjksdhfjksdhfjkshdjkfhsjkdfhkjsd1","hahahaha",5);
+        Object o = redisUtil.get("11sdfhgjksdhfjksdhfjksdhfkjsjkfhkjsddhfjksdhfkjhsjkfhjkshfjksdhfjksdhfjkshdjkfhsjkdfhkjsd1");
+        System.err.println(o);
+
 
-        try {
+        /*try {
             // 用来保存数据
             ArrayList<String[]> csvFileList = new ArrayList<String[]>();
             // 定义一个CSV路径
@@ -78,7 +85,7 @@ public class SampleTest {
             }
         } catch (IOException e) {
             e.printStackTrace();
-        }
+        }*/
 
 
 

+ 56 - 37
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/AiKuaishouCreateCreativeServiceImpl.java

@@ -21,6 +21,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.google.common.collect.Lists;
 import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.util.DateUtils;
+import org.jeecg.common.util.RedisUtil;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -126,8 +127,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                         }
                         unitCnt++;
                         //开始创建组+创意
-                        String timestamp = DateUtils.formatDate(new Date(), "yyyyMMddHHmmss");
-                        String unitName = getName(strategy.getGroupName(), strategy, createType, appInfo, timestamp, unitCnt, videoItem.getPhotoName());
+                        String unitName = getName(strategy.getGroupName(), strategy, createType, appInfo, videoItem.getPhotoName(), "unit", newCampaignId);
                         JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appInfo.getAppId());
                         Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
                         Integer unitCode = (Integer) unitCreateResult.get("code");
@@ -184,8 +184,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                     continue;
                 }
                 unitCnt++;
-                String timestamp = DateUtils.formatDate(new Date(), "yyyyMMddHHmmss");
-                String unitName = getName(strategy.getGroupName(), strategy, createType, null, timestamp, unitCnt, videoItem.getPhotoName());
+                String unitName = getName(strategy.getGroupName(), strategy, createType, null, videoItem.getPhotoName(), "unit", newCampaignId);
 
                 Long appId = null;
                 if (strategy.getCampaignType() == 2 || strategy.getCampaignType() == 7) {
@@ -300,8 +299,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                     List<List<KuaiShouVideoGet>> splitVideos = Lists.partition(allVideos, 5);
                     for (int j = 1; j < splitVideos.size() + 1; j++) {
                         //创建组
-                        String timestamp = DateUtils.formatDate(new Date(), "yyyyMMddHHmmss");
-                        String unitName = getName(strategy.getGroupName(), strategy, createType, appInfo, timestamp, null, null);
+                        String unitName = getName(strategy.getGroupName(), strategy, createType, appInfo, null, "unit", newCampaignId);
                         JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appInfo.getAppId());
                         Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
                         Integer unitCode = (Integer) unitCreateResult.get("code");
@@ -343,8 +341,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
             List<List<KuaiShouVideoGet>> splitVideos = Lists.partition(allVideos, 5);
             for (int j = 1; j < splitVideos.size() + 1; j++) {
                 //创建组
-                String timestamp = DateUtils.formatDate(new Date(), "yyyyMMddHHmmss");
-                String unitName = getName(strategy.getGroupName(), strategy, createType, null, timestamp, null, null);
+                String unitName = getName(strategy.getGroupName(), strategy, createType, null, null, "unit", newCampaignId);
                 String appIdString = strategy.getAppIdArray();
                 Long appId = null;
                 if (strategy.getCampaignType() == 2 || strategy.getCampaignType() == 7) {
@@ -619,23 +616,6 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
 
 
     private Long getCampaignId(AiKuaishouAdvertiserStrategy strategy, CtopOauthToken token, String replaceString, String checkType, Integer createType, AiKuaiShouAppInfo appInfo, String uuid) {
-        //  JSONArray campaignList;
-        String timestamp = DateUtils.formatDate(new Date(), "yyyyMMddHHmmss");
-        /*if ("ALL_CAMPAIGN".equals(checkType)) {
-            campaignList = kuaishouInterfaceService.getCampaignList(token, null, null, 1);
-        } else {
-            timestamp = DateUtils.formatDate(new Date(), "yyyyMMddHHmmss");
-            campaignList = kuaishouInterfaceService.getCampaignList(token, new Date(), new Date(), 1);
-        }*/
-
-       /* if (!Check.isNull(campaignList)){
-            for (int i = 0; i < campaignList.size(); i++) {
-                JSONObject jsonObject = campaignList.getJSONObject(i);
-                if (jsonObject.getString("campaign_name").contains(replaceString)) {
-                    return jsonObject.getLong("campaign_id");
-                }
-            }
-        }*/
         Long campaignId = null;
         if ("ALL_CAMPAIGN".equals(checkType)) {
             campaignId = campaignService.getCampaignIdByAccountAndName(strategy.getAccountId(), replaceString);
@@ -650,7 +630,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         // 不存在“上新”计划,则创建一个计划
         JSONObject campaignParams = new JSONObject();
         campaignParams.put("advertiser_id", token.getAccountId());
-        String campaignName = getName(strategy.getCampaignName(), strategy, createType, appInfo, timestamp, null, null);
+        String campaignName = getName(strategy.getCampaignName(), strategy, createType, appInfo, null, "plan", null);
         campaignParams.put("campaign_name", campaignName);
         campaignParams.put("type", strategy.getCampaignType());
         if (null != strategy.getCampaignDayBudget() && strategy.getCampaignDayBudget() != 0) {
@@ -694,9 +674,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
             unitParams.put("day_budget", 0);
         }
         //应用商店列表
-
         unitParams.put("ocpx_action_type", strategy.getOcpxActionType());
-
         //出价
         if (null != strategy.getBid() && strategy.getBid() != 0) {
             unitParams.put("bid", strategy.getBid());
@@ -1204,7 +1182,10 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
      * @param strategy 账户id
      * @return
      */
-    private String getName(String wildcard, AiKuaishouAdvertiserStrategy strategy, Integer createType, AiKuaiShouAppInfo appInfo, String timestamp, Integer cnt, String materialName) {
+    @Autowired
+    private RedisUtil redisUtil;
+
+    private String getName(String wildcard, AiKuaishouAdvertiserStrategy strategy, Integer createType, AiKuaiShouAppInfo appInfo, String materialName, String type, Long campaignId) {
         if (wildcard.contains("{{应用包名}}")) {
             String appName = "";
             if (null != appInfo) {
@@ -1213,8 +1194,6 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
             wildcard = wildcard.replace("{{应用包名}}", appName);
         }
         if (wildcard.contains("{{创意制作方式}}")) {
-//            String creatype = KuaishouCreativeCreateTypeEnum.getNameByType(strategy.getOpenProgramCreate());
-//            wildcard = wildcard.replace("{{创意制作方式}}",creatype);
             if (strategy.getUnitType() == 4) {
                 wildcard = wildcard.replace("{{创意制作方式}}", "自定义");
             } else if (strategy.getUnitType() == 7) {
@@ -1232,22 +1211,52 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
             } else {
                 wildcard = wildcard.replace("{{素材名称}}", materialName);
             }
-
         }
         if (!wildcard.contains("{{自定义}}")) {
             wildcard = wildcard + "{{自定义}}";
         }
+        Date date = new Date();
+        String nowDate = DateUtils.formatDate(date, "yy-MMdd");
+        if (type.equals("plan")) {
+            if (wildcard.contains("{{日期}}")) {
+                wildcard = wildcard.replace("{{日期}}", nowDate);
+            } else {
+                wildcard = wildcard + "-" + nowDate;
+            }
+        } else if ("unit".equals(type)) {
+            wildcard = wildcard.replace("{{日期}}", nowDate);
+        }
+
         String targetName = KuaishouCreativeMatTypeEnum.getNameByType(strategy.getUnitType().toString() + createType.toString());
         if (null != appInfo) {
             targetName = appInfo.getAppVersion() + "-" + targetName;
         }
         wildcard = wildcard.replace("{{自定义}}", targetName);
 
-        if (null != timestamp && !"".equals(timestamp.trim())) {
-            wildcard = wildcard + "-" + timestamp;
-        }
-        if (null != cnt) {
-            wildcard = wildcard + "-" + cnt.toString();
+        if (!Check.isNull(campaignId)) {
+            Integer count = null;
+            if (null != strategy.getSingleAppid() && strategy.getSingleAppid() == 0) {
+                String redisKey = strategy.getAccountId() + "_" + campaignId;
+                Object redisValue = redisUtil.get(redisKey);
+                if (Check.isNull(redisValue)) {
+                    count = 1;
+                    redisUtil.set(redisKey, count);
+                } else {
+                    count = (Integer) redisValue + 1;
+                    redisUtil.set(redisKey, count);
+                }
+            } else {
+                String redisKey = strategy.getAccountId() + "_" + campaignId + nowDate;
+                Object redisValue = redisUtil.get(redisKey);
+                if (Check.isNull(redisValue)) {
+                    count = 1;
+                    redisUtil.set(redisKey, count, 100000L);
+                } else {
+                    count = (Integer) redisValue + 1;
+                    redisUtil.set(redisKey, count, 100000L);
+                }
+            }
+            wildcard = wildcard + "-" + count;
         }
         wildcard = wildcard.replace("--", "-");
         if (wildcard.startsWith("-")) {
@@ -1273,4 +1282,14 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         }
         return adsence.substring(0, adsence.length() - 1);
     }
+
+
+    public static void main(String[] args) {
+        Date date = new Date();
+        String s = DateUtils.formatDate(date, "yy-MMdd");
+        String timestamp = DateUtils.formatDate(new Date(), "HHmmss");
+        System.err.println(timestamp);
+    }
+
+
 }

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

@@ -216,6 +216,7 @@ public class KuaiShouGroupTemplate {
     private String creativeReviewDetail;
     private Integer createType;
     private String photoIds;
+    private String schemaUri;
 
     /**
      * 创建时间

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

@@ -118,6 +118,7 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
         String action_bar_text = requestJson.getString("actionBarText");
         String description = requestJson.getString("description");
         Long site_id = requestJson.getLong("siteId");
+        String schema_uri = requestJson.getString("schemaUri");
 
 
         List<KuaiShouGroupTemplate> templates = new ArrayList<>();
@@ -194,6 +195,9 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
             if (!Check.isNull(url)) {
                 template.setUrl(url);
             }
+            if (!Check.isNull(schema_uri)) {
+                template.setSchemaUri(schema_uri);
+            }
             if (!Check.isNull(app_id)) {
                 template.setAppId(app_id);
             }
@@ -368,6 +372,10 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
         if (!Check.isNull(template.getUrl())) {
             createUnitJson.put("url", template.getUrl()); // 投放链接
         }
+        if (!Check.isNull(template.getSchemaUri())) {
+            createUnitJson.put("schema_uri", template.getSchemaUri()); // 吊起链接
+        }
+
         if (!Check.isNull(template.getAppId())) {
             createUnitJson.put("app_id", template.getAppId()); // 应用ID
         }