Jelajahi Sumber

修改代码逻辑

syh 4 tahun lalu
induk
melakukan
a2e25d88ce

+ 11 - 12
jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java

@@ -24,6 +24,7 @@ import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertiserDataServ
 import cn.com.ctop.toutiao.modules.report.service.*;
 import com.alibaba.fastjson.JSONArray;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.catalina.User;
 import org.jeecg.common.util.DateUtils;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -389,20 +390,18 @@ public class SampleTest {
 
     @Test
     public void execute() {
-        String accountIds = "1679063493763085";
-        String[] arrays = accountIds.split(",");
-        for (int i = 0; i < arrays.length; i++) {
-            Long accountId = Long.parseLong(arrays[i]);
-            CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
-            load12Data(token);
-//            load12AccountData(token);
+        List<UserAllocation>  allocations = allocationService.getByMediaId("3");
+        for (UserAllocation allocation:allocations) {
+            CtopOauthToken token = tokenService.getTokenByAccountId(allocation.getAccountId());
+//            load12Data(token);
+            load12AccountData(token);
         }
     }
 
     private void load12AccountData(CtopOauthToken token) {
-        reportService.getAdvertiserReport(token, DateUtils.parseDate("2020-10-01", "yyyy-MM-dd"), DateUtils.parseDate("2020-10-11", "yyyy-MM-dd"), CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
-        reportService.getAdvertiserReport(token, DateUtils.parseDate("2020-10-11", "yyyy-MM-dd"), DateUtils.parseDate("2020-10-21", "yyyy-MM-dd"), CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
-        reportService.getAdvertiserReport(token, DateUtils.parseDate("2020-10-21", "yyyy-MM-dd"), DateUtils.parseDate("2020-10-31", "yyyy-MM-dd"), CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
+        reportService.getAdvertiserReport(token, DateUtils.parseDate("2020-10-01", "yyyy-MM-dd"), DateUtils.parseDate("2020-10-31", "yyyy-MM-dd"), CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
+        reportService.getAdvertiserReport(token, DateUtils.parseDate("2020-11-01", "yyyy-MM-dd"), DateUtils.parseDate("2020-11-30", "yyyy-MM-dd"), CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
+        reportService.getAdvertiserReport(token, DateUtils.parseDate("2020-12-01", "yyyy-MM-dd"), DateUtils.parseDate("2020-12-31", "yyyy-MM-dd"), CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
     }
 
     private void load12Data(CtopOauthToken token) {
@@ -483,10 +482,10 @@ public class SampleTest {
 //            return;
 //        }
         AiKuaishouAccountTargetTemplate accountTargetTemplate1 = aiKuaishouAccountTargetTemplateService.getById(30002);
-        aiKuaishouNewCreateCampaign.kuaishouAiAdsNewMaterialCreativity(accountTargetTemplate1);
+        aiKuaishouNewCreateCampaign.kuaishouAiAddNewMaterialCreativity(accountTargetTemplate1);
 
         AiKuaishouAccountTargetTemplate accountTargetTemplate2 = aiKuaishouAccountTargetTemplateService.getById(30001);
-        aiKuaishouNewCreateCampaign.kuaishouAiAdsNewMaterialCreativity(accountTargetTemplate2);
+        aiKuaishouNewCreateCampaign.kuaishouAiAddNewMaterialCreativity(accountTargetTemplate2);
     }
 
     @Test

+ 1 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/impl/UserAllocationServiceImpl.java

@@ -92,6 +92,7 @@ public class UserAllocationServiceImpl extends ServiceImpl<UserAllocationMapper,
         if ("".equals(mediaId)) {
             queryWrapper.eq("media_id", mediaId);
         }
+        queryWrapper.eq("account_status",0);
         queryWrapper.orderByDesc("id");
         return this.list(queryWrapper);
     }

+ 10 - 0
module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/KuaishouAiAdsNewMaterialCreativityJob.java

@@ -25,6 +25,16 @@ public class KuaishouAiAdsNewMaterialCreativityJob {
         accountTargetTemplates.forEach(targetTemplate -> aiKuaishouNewCreateCampaign.kuaishouAiAdsNewMaterialCreativity(targetTemplate));
     }
 
+
+    @XxlJob("kuaishouAiAddNewMaterialCreativityJob")
+    public void kuaishouAiAddNewMaterialCreativityJob() {
+        List<AiKuaishouAccountTargetTemplate> accountTargetTemplates = aiKuaishouAccountTargetTemplateService.getAllEffectTemplate();
+        if(null==accountTargetTemplates||accountTargetTemplates.isEmpty()){
+            return;
+        }
+        accountTargetTemplates.forEach(targetTemplate -> aiKuaishouNewCreateCampaign.kuaishouAiAddNewMaterialCreativity(targetTemplate));
+    }
+
     @XxlJob("kuaishouAiAdsHotMaterialCreativityJob")
     public void kuaishouAiAdsHotMaterialCreativityJob() {
         List<AiKuaishouAccountTargetTemplate> accountTargetTemplates = aiKuaishouAccountTargetTemplateService.getAllEffectTemplate();

+ 2 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/IAiKuaishouNewCreateCampaign.java

@@ -6,4 +6,6 @@ public interface IAiKuaishouNewCreateCampaign {
     void kuaishouAiAdsNewMaterialCreativity(AiKuaishouAccountTargetTemplate targetTemplate);
 
     void kuaishouAiAdsHotMaterialCreativity(AiKuaishouAccountTargetTemplate targetTemplate);
+
+    void kuaishouAiAddNewMaterialCreativity(AiKuaishouAccountTargetTemplate targetTemplate);
 }

+ 90 - 4
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/AiKuaishouNewCreateCampaignServiceImpl.java

@@ -12,11 +12,9 @@ import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouNewCreateCampaign;
 import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouStrategyMapCreativeService;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouImageGet;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouVideoRelateCreatives;
 import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouVideoGetMapper;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouImageGetService;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouMaterialUploadService;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouVideoGetService;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
+import cn.com.ctop.kuaishou.modules.batch.service.*;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import lombok.extern.slf4j.Slf4j;
@@ -225,6 +223,94 @@ public class AiKuaishouNewCreateCampaignServiceImpl implements IAiKuaishouNewCre
 
     }
 
+    @Autowired
+    private IKuaishouVideoRelateCreativesService relateCreativesService;
+    @Override
+    public void kuaishouAiAddNewMaterialCreativity(AiKuaishouAccountTargetTemplate targetTemplate) {
+        Long accountId = targetTemplate.getAccountId();
+        CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId.toString());
+        if(null == token){
+            log.info("token获取失败=>accountId:{}",accountId);
+            return;
+        }
+        kuaishouInterfaceService.getVideoList(token, DateUtils.date2Str(),DateUtils.date2Str());
+
+        //获取创意关联数为0的素材
+        List<KuaishouVideoRelateCreatives> kuaishouVideoRelateCreatives = relateCreativesService.listByParams(accountId);
+        if(null == kuaishouVideoRelateCreatives||kuaishouVideoRelateCreatives.isEmpty()){
+            log.info("账户:{}, 不存在未创建创意素材",accountId);
+            return;
+        }
+
+        //2、判断该账户下当天有没有“上新”计划,没有则创建一个“上新”计划
+        JSONArray campaignList = kuaishouInterfaceService.getCampaignList(token, new Date(), new Date(),1);
+        boolean isHaveNewCampaign = false;
+        Long newCampaignId = 0L;
+        if (null!=campaignList&&campaignList.size()>0){
+            for(int i = 0;i<campaignList.size();i++){
+                JSONObject jsonObject = campaignList.getJSONObject(i);
+                if (jsonObject.getString("campaign_name").contains("素材上新")){
+                    isHaveNewCampaign = true;
+                    newCampaignId = jsonObject.getLong("campaign_id");
+                    break;
+                }
+            }
+        }
+        // 不存在“上新”计划,则创建一个计划
+        if (!isHaveNewCampaign){
+            Date campaignDate = new Date();
+            String timestamp = DateUtils.formatDate(campaignDate,"yyyyMMddHHmmss");
+            JSONObject campaignParams = new JSONObject();
+            campaignParams.put("advertiser_id",token.getAccountId());
+            String campaignName = targetTemplate.getTitlePrefix() + "素材上新"+ targetTemplate.getTitleMiddle()+ timestamp;
+            campaignParams.put("campaign_name",campaignName);
+            campaignParams.put("type",Integer.parseInt(targetTemplate.getMarketingGoal()));
+            campaignParams.put("day_budget",0L);
+            Map<String, Object> campaignCreateResult = kuaishouInterfaceService.campaignCreate(token.getAccessToken(), token.getAccountId(), campaignParams);
+            Integer code = (Integer) campaignCreateResult.get("code");
+            String message = (String) campaignCreateResult.get("message");
+            if(code != 0 ){
+                log.info("计划创建失败=>message:{}",message);
+                return;
+            }
+            newCampaignId = (Long) campaignCreateResult.get("campaignId");
+        }
+
+        //3、在“上新”计划中新增广告组,一个素材搭配5张封面,组成一个广告组
+        String timestamp = DateUtils.formatDate(new Date(),"yyyyMMddHHmmss");
+        String unitNamePrefix = targetTemplate.getTitlePrefix() + "素材上新"+ targetTemplate.getTitleMiddle()+ timestamp;
+        int unitCnt = 0;
+        for(KuaishouVideoRelateCreatives videoItem: kuaishouVideoRelateCreatives){
+            unitCnt ++;
+            KuaiShouVideoGet videoGet = videoGetService.getVideoByPhotoId(videoItem.getPhotoId());
+            if(null == videoGet){
+                log.info("未获取到视频信息=>photoId:{}",videoItem.getPhotoId());
+                continue;
+            }
+            // 每个组,搭配5个创意
+            List<MaterialCutFrame> cutFrameList = materialCutFrameService.getListByVideoSignature(videoGet.getSignature());
+            List<MaterialImageInfo> orgFrameList = materialImageInfoService.getListByVideoSignature(videoGet.getSignature());
+            if ((null == cutFrameList||cutFrameList.isEmpty())&&(null == orgFrameList|| orgFrameList.isEmpty())){
+                log.info("未获取到视频封面=>videoSignature:{}",videoGet.getSignature());
+                continue;
+            }
+            String unitName = unitNamePrefix + "-" + unitCnt;
+            JSONObject unitParams = createUnitParams(token, newCampaignId, targetTemplate, unitName);
+            Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams,1);
+            Integer unitCode = (Integer) unitCreateResult.get("code");
+            String unitMessage = (String) unitCreateResult.get("message");
+            if(unitCode != 0 ){
+                log.info("组创建失败=>accountId:{};message:{}",accountId,unitMessage);
+                continue;
+            }
+            Long unitId = (Long) unitCreateResult.get("unitId");
+            JSONObject creativeParams = creativeParams(token, unitId, videoGet, targetTemplate);
+            createCreativeByImage(cutFrameList, orgFrameList,token, creativeParams, newCampaignId, unitId, videoGet,targetTemplate.getImageNumber());
+            videoItem.setCreativeCount(5);
+            relateCreativesService.updateById(videoItem);
+        }
+    }
+
 
     private JSONObject creativeParams(CtopOauthToken token,Long unitId,KuaiShouVideoGet videoItem,AiKuaishouAccountTargetTemplate targetTemplate){
         JSONObject creativeParams = new JSONObject();

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

@@ -22,4 +22,6 @@ public interface IKuaishouVideoRelateCreativesService extends IService<KuaishouV
     void videoRelateCreatives(Long accountId, JSONArray photoIds, Map<String, Object> statdateMap);
 
     List<JSONObject> getVideoListByMap(Map<String, Object> requestMap);
+
+    List<KuaishouVideoRelateCreatives> listByParams(Long accountId);
 }

+ 15 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouVideoRelateCreativesServiceImpl.java

@@ -11,12 +11,14 @@ import cn.com.ctop.kuaishou.modules.batch.mapper.KuaishouVideoRelateCreativesMap
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouVideoRelateCreativesService;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.api.vo.Result;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
@@ -35,7 +37,7 @@ import java.util.Map;
 public class KuaishouVideoRelateCreativesServiceImpl extends ServiceImpl<KuaishouVideoRelateCreativesMapper, KuaishouVideoRelateCreatives> implements IKuaishouVideoRelateCreativesService {
     @Autowired
     private ICtopOauthTokenService tokenService;
-    @Autowired
+    @Resource
     private KuaishouVideoRelateCreativesMapper kuaishouVideoRelateCreativesMapper;
 
     /**
@@ -145,4 +147,16 @@ public class KuaishouVideoRelateCreativesServiceImpl extends ServiceImpl<Kuaisho
     public List<JSONObject> getVideoListByMap(Map<String, Object> requestMap) {
         return kuaishouVideoRelateCreativesMapper.getVideoListByMap(requestMap);
     }
+
+    @Override
+    public List<KuaishouVideoRelateCreatives> listByParams(Long accountId) {
+        QueryWrapper<KuaishouVideoRelateCreatives> queryWrapper = new QueryWrapper<>();
+        if(null!=accountId&&accountId!=0){
+            queryWrapper.eq("account_id",accountId);
+        }
+        queryWrapper.eq("creative_count",0);
+        queryWrapper.orderByDesc("stat_date");
+        queryWrapper.last("limit 10");
+        return this.list(queryWrapper);
+    }
 }

+ 0 - 1
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/service/impl/ReportServiceImpl.java

@@ -110,7 +110,6 @@ public class ReportServiceImpl implements IReportService {
                 advertiserDailyReportService.saveOrUpdate(dailyReport);
             }
         }
-        getAdvertiserReportByPage(token, conditions, page + 1);
     }
 
     @Override