Kaynağa Gözat

Merge branch 'master' of http://git.tjyourong.com.cn/ctop/adsp-boot

zhaoxian 4 yıl önce
ebeveyn
işleme
ad898fa2e7
23 değiştirilmiş dosya ile 677 ekleme ve 87 silme
  1. 19 19
      jeecg-boot-base-common/src/main/java/org/jeecg/common/util/DateUtils.java
  2. 1 0
      jeecg-boot-module-system/src/main/java/org/jeecg/config/ShiroConfig.java
  3. 70 35
      jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java
  4. 10 1
      module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/KuaishouAiAdsNewMaterialCreativityJob.java
  5. 245 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/controller/KuaiShouMaterialControer.java
  6. 2 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/entity/AiKuaishouAccountTargetTemplate.java
  7. 56 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/entity/KuaiShouVideoLastTime.java
  8. 18 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/KuaiShouVideoLastTimeMapper.java
  9. 12 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/xml/KuaiShouVideoLastTimeMapper.xml
  10. 2 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/IAiKuaishouNewCreateCampaign.java
  11. 17 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/IKuaiShouVideoLastTimeService.java
  12. 85 2
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/AiKuaishouNewCreateCampaignServiceImpl.java
  13. 6 6
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/AiStrategyServiceImpl.java
  14. 28 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/KuaiShouVideoLastTimeServiceImpl.java
  15. 3 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/KuaiShouVideoGetMapper.java
  16. 4 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/KuaishouVideoRelateCreativesMapper.java
  17. 22 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaiShouVideoGetMapper.xml
  18. 29 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaishouVideoRelateCreativesMapper.xml
  19. 4 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaiShouVideoGetService.java
  20. 4 2
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaishouVideoRelateCreativesService.java
  21. 2 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouGroupTemplateServiceImpl.java
  22. 33 20
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouVideoGetServiceImpl.java
  23. 5 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouVideoRelateCreativesServiceImpl.java

+ 19 - 19
jeecg-boot-base-common/src/main/java/org/jeecg/common/util/DateUtils.java

@@ -10,14 +10,7 @@ import java.sql.Timestamp;
 import java.text.DateFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
 
 /**
  * 类描述:时间操作定义类
@@ -831,21 +824,28 @@ public class DateUtils extends PropertyEditorSupport {
     }
 
 
-    public static void main(String[] args) throws ParseException {
-        /*Date date = stampToTime(1599458521L);
-        String s = formatDate(date);
-        System.err.println(s);*/
-        Long s1 = timeToStamp("2020-09-23 21:30:00");
-        System.err.println(s1);
+    public static int getdaysOfTwoDate(String minDate, String date) {
+        Date bigDate = parseDate(date, "yyyy-MM-dd");
+        Date smallDate = parseDate(minDate, "yyyy-MM-dd");
+        int days = (int) ((bigDate.getTime() - smallDate.getTime()) / (1000 * 3600 * 24));
+        return days + 1;
     }
 
-    public static int getdaysOfTwoDate(String minDate, String date) {
-        Date bigDate = parseDate(date,"yyyy-MM-dd");
-        Date smallDate = parseDate(minDate,"yyyy-MM-dd");
-        int days = (int) ((bigDate.getTime() - smallDate.getTime()) / (1000*3600*24));
-        return days+1;
+
+    /**
+     * 当前时间前推
+     *
+     * @param endDate
+     * @param i
+     * @return
+     */
+    public static Date addTime(Date endDate, int i) {
+        Long time = Long.valueOf(i * 1000 * 60);
+        Long time1 = endDate.getTime() - time;
+        return new Date(time1);
     }
 
+
     /**
      * String类型 转换为Date, 如果参数长度为10 转换格式”yyyy-MM-dd“ 如果参数长度为19 转换格式”yyyy-MM-dd
      * HH:mm:ss“ * @param text String类型的时间值

+ 1 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/config/ShiroConfig.java

@@ -181,6 +181,7 @@ public class ShiroConfig {
         filterChainDefinitionMap.put("/shiwan/shiwanFileUpload/*", "anon");
         filterChainDefinitionMap.put("/oa/wechatNoList/*", "anon");
         filterChainDefinitionMap.put("/ruleGroup/*", "anon");
+        filterChainDefinitionMap.put("/kuaishou/Ai/*", "anon");
 
         // 添加自己的过滤器并且取名为jwt
         Map<String, Filter> filterMap = new HashMap<>(1);

+ 70 - 35
jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java

@@ -6,14 +6,13 @@ import cn.com.ctop.common.module.entity.UserAllocation;
 import cn.com.ctop.common.module.service.IBindAccountLoginService;
 import cn.com.ctop.common.module.service.ICtopOauthTokenService;
 import cn.com.ctop.common.module.service.IUserAllocationService;
+import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.CtopAdConstant;
 import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouAccountTargetTemplate;
 import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouAccountTargetTemplateService;
 import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouNewCreateCampaign;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouCommentService;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouDailyReportTaskService;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouHistoryReportTaskService;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet;
+import cn.com.ctop.kuaishou.modules.batch.service.*;
 import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
 import cn.com.ctop.kuaishou.modules.report.service.IKuaishouReportDailyAgentService;
 import cn.com.ctop.kuaishou.modules.report.service.IKuaishouVideoEtlInfoService;
@@ -23,6 +22,7 @@ import cn.com.ctop.oa.modules.service.IWechatNoListService;
 import cn.com.ctop.oa.modules.service.IWechatUserListService;
 import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertiserDataService;
 import cn.com.ctop.toutiao.modules.report.service.*;
+import com.alibaba.fastjson.JSONArray;
 import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.util.DateUtils;
 import org.junit.Test;
@@ -37,6 +37,7 @@ import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
@@ -60,14 +61,37 @@ public class SampleTest {
     private ICtopOauthTokenService tokenService;
     @Autowired
     private IKuaishouInterfaceService iKuaishouInterfaceService;
+    @Autowired
+    private IKuaiShouVideoGetService videoGetService;
+    @Autowired
+    private IKuaishouVideoRelateCreativesService kuaishouVideoRelateCreativesService;
 
     @Test
     public void loadBytedanceCreativeData() throws ParseException {
 
-        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
-        Date parse = simpleDateFormat.parse("2020-12-11");
-        CtopOauthToken tokenByAccountId = oauthTokenService.getTokenByAccountId(5982133L);
-        iKuaishouInterfaceService.getAdvertiserGroupReportDaily(tokenByAccountId, parse, parse);
+        List<KuaiShouVideoGet> KuaiShouVideoGets = videoGetService.selectPhotoIdsByAccountId(9743746L);
+        if (!Check.isNull(KuaiShouVideoGets)) {
+            JSONArray dateList = new JSONArray();
+            JSONArray photoIds = new JSONArray();
+            Map<String, Object> statdateMap = new HashMap<>();
+            int count = 0;
+            for (KuaiShouVideoGet video : KuaiShouVideoGets) {
+                count++;
+                if (count < 10) {
+                    photoIds.add(video.getPhotoId());
+                    statdateMap.put(video.getPhotoId(), video.getStatDate());
+                } else {
+                    photoIds.add(video.getPhotoId());
+                    statdateMap.put(video.getPhotoId(), video.getStatDate());
+                    dateList.add(photoIds);
+                    photoIds = new JSONArray();
+                    count = 0;
+                }
+            }
+            dateList.add(photoIds);
+            kuaishouVideoRelateCreativesService.videoRelateCreatives(9743746L, dateList, statdateMap);
+        }
+
 
       /*  QueryWrapper<CtopOauthToken> queryWrapper = new QueryWrapper<>();
         queryWrapper.eq("media_id", 2);
@@ -247,12 +271,12 @@ public class SampleTest {
     }
 
     @Test
-    public void testData11(){
-        CtopOauthToken token =tokenService.getTokenByAccountId(9556344L);
+    public void testData11() {
+        CtopOauthToken token = tokenService.getTokenByAccountId(9556344L);
         int dimeDiff = 5;
         Date now = new Date();
         String startTime = DateUtils.formatDate("2021-01-11 18:25:00");
-        String endTime = DateUtils.formatDate(now,"2021-01-11 18:35:00");
+        String endTime = DateUtils.formatDate(now, "2021-01-11 18:35:00");
         kuaishouInterfaceService.getSuZaoList(token.getAccessToken(), token.getAccountId(), 1, startTime, endTime);
     }
 
@@ -379,7 +403,7 @@ public class SampleTest {
     public void execute() {
         String accountIds = "1675239584963662,1676540490482759,1675237415468045";
         String[] arrays = accountIds.split(",");
-        for(int i=0;i<arrays.length;i++){
+        for (int i = 0; i < arrays.length; i++) {
             Long accountId = Long.parseLong(arrays[i]);
             CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
             load12Data(token);
@@ -388,35 +412,37 @@ public class SampleTest {
     }
 
     @Test
-    public void loadBytedanceData(){
+    public void loadBytedanceData() {
         String accountIds = "1676540490482759";
         String[] arrays = accountIds.split(",");
-        for(int i=0;i<arrays.length;i++){
+        for (int i = 0; i < arrays.length; i++) {
             Long accountId = Long.parseLong(arrays[i]);
             CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
             load12Data(token);
         }
     }
 
-    private void load12AccountData(CtopOauthToken token){
-        reportService.getAdvertiserReport(token, DateUtils.parseDate("2020-12-01","yyyy-MM-dd"), DateUtils.parseDate("2020-12-11","yyyy-MM-dd"),CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
-        reportService.getAdvertiserReport(token, DateUtils.parseDate("2020-12-11","yyyy-MM-dd"), DateUtils.parseDate("2020-12-21","yyyy-MM-dd"),CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
-        reportService.getAdvertiserReport(token, DateUtils.parseDate("2020-12-21","yyyy-MM-dd"), DateUtils.parseDate("2020-12-31","yyyy-MM-dd"),CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
+    private void load12AccountData(CtopOauthToken token) {
+        reportService.getAdvertiserReport(token, DateUtils.parseDate("2020-12-01", "yyyy-MM-dd"), DateUtils.parseDate("2020-12-11", "yyyy-MM-dd"), CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
+        reportService.getAdvertiserReport(token, DateUtils.parseDate("2020-12-11", "yyyy-MM-dd"), DateUtils.parseDate("2020-12-21", "yyyy-MM-dd"), CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
+        reportService.getAdvertiserReport(token, DateUtils.parseDate("2020-12-21", "yyyy-MM-dd"), DateUtils.parseDate("2020-12-31", "yyyy-MM-dd"), CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
     }
 
-    private void load12Data(CtopOauthToken token){
+    private void load12Data(CtopOauthToken token) {
         bytedanceReportService.bytedanceMaterialReport(token, "2020-12-01", "2020-12-11");
         bytedanceReportService.bytedanceMaterialReport(token, "2020-12-11", "2020-12-21");
         bytedanceReportService.bytedanceMaterialReport(token, "2020-12-21", "2020-12-31");
     }
+
     @Autowired
     private IKuaishouVideoEtlInfoService kuaishouVideoEtlInfoService;
+
     @Test
-    public void etlKuaishouData(){
+    public void etlKuaishouData() {
         String dateString = "2021-01-05";
-        Date startDate = DateUtils.parseDate(dateString,"yyyy-MM-dd");
-        for(int i=0;i<=10;i++){
-            Date getDate = DateUtils.addDay(startDate,i);
+        Date startDate = DateUtils.parseDate(dateString, "yyyy-MM-dd");
+        for (int i = 0; i <= 10; i++) {
+            Date getDate = DateUtils.addDay(startDate, i);
             kuaishouVideoEtlInfoService.etlKuaishouVideoInfo(getDate);
             bytedanceVideoEtlInfoService.etlBytedanceVideoInfo(getDate);
         }
@@ -426,34 +452,32 @@ public class SampleTest {
     private IBytedanceVideoEtlInfoService bytedanceVideoEtlInfoService;
 
     @Test
-    public void loadBytedanceVideo(){
+    public void loadBytedanceVideo() {
         CtopOauthToken token = tokenService.getTokenByAccountId(1673731601820686L);
-        for(int i=15;i<60;i++){
-            reportService.getAdvertiserReport(token,DateUtils.addDay(new Date(),-i),DateUtils.addDay(new Date(),-i),CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
+        for (int i = 15; i < 60; i++) {
+            reportService.getAdvertiserReport(token, DateUtils.addDay(new Date(), -i), DateUtils.addDay(new Date(), -i), CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
         }
     }
 
     @Test
-    public void loadKuaishouVideo(){
+    public void loadKuaishouVideo() {
         Date date = new Date();
         CtopOauthToken token = tokenService.getTokenByAccountId(9556344L);
 //        kuaishouInterfaceService.getAdvertiserCreativeReportDaily(token, new Date(), new Date(), null, null);
-        kuaishouInterfaceService.getVideoList(token, DateUtils.formatDate(DateUtils.addDay(date,-5)), DateUtils.formatDate(date));
+        kuaishouInterfaceService.getVideoList(token, DateUtils.formatDate(DateUtils.addDay(date, -5)), DateUtils.formatDate(date));
         // 获取图片信息数据
 //        kuaishouInterfaceService.getImageList(token, DateUtils.getNowDate("yyyy-MM-dd"));
     }
 
 
-
-
     @Autowired
     IRuleByteDanceAccountService ruleByteDanceAccountService;
 
     @Test
-    public void cleanRuleDataAccount(){
+    public void cleanRuleDataAccount() {
         List<CtopOauthToken> tokens = oauthTokenService.selectKuaiShouToken();
-        for(CtopOauthToken oauthToken:tokens){
-            ruleKuaiShouPlanService.cleanRuleDataTarget(oauthToken.getAccountId(),1);
+        for (CtopOauthToken oauthToken : tokens) {
+            ruleKuaiShouPlanService.cleanRuleDataTarget(oauthToken.getAccountId(), 1);
         }
     }
 
@@ -461,12 +485,23 @@ public class SampleTest {
     IAiKuaishouNewCreateCampaign aiKuaishouNewCreateCampaign;
     @Autowired
     private IAiKuaishouAccountTargetTemplateService aiKuaishouAccountTargetTemplateService;
+
     @Test
-    public void createPlan(){
+    public void createPlan() {
         List<AiKuaishouAccountTargetTemplate> accountTargetTemplates = aiKuaishouAccountTargetTemplateService.getAllEffectTemplate();
-        if(null==accountTargetTemplates||accountTargetTemplates.isEmpty()){
+        if (null == accountTargetTemplates || accountTargetTemplates.isEmpty()) {
             return;
         }
         accountTargetTemplates.forEach(targetTemplate -> aiKuaishouNewCreateCampaign.kuaishouAiAdsNewMaterialCreativity(targetTemplate));
     }
+
+    @Test
+    public void etlKuaishouProjectData(){
+        String dateString = "2020-03-17";
+        Date startDate = DateUtils.parseDate(dateString,"yyyy-MM-dd");
+        for(int i=0;i<=365;i++){
+            Date getDate = DateUtils.addDay(startDate,i);
+            kuaishouVideoEtlInfoService.etlKuaishouVideoInfoGroupByProjectId(getDate);
+        }
+    }
 }

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

@@ -17,11 +17,20 @@ public class KuaishouAiAdsNewMaterialCreativityJob {
     @Autowired
     private IAiKuaishouAccountTargetTemplateService aiKuaishouAccountTargetTemplateService;
     @XxlJob("kuaishouAiAdsNewMaterialCreativityJob")
-    public void execute() {
+    public void kuaishouAiAdsNewMaterialCreativityJob() {
         List<AiKuaishouAccountTargetTemplate> accountTargetTemplates = aiKuaishouAccountTargetTemplateService.getAllEffectTemplate();
         if(null==accountTargetTemplates||accountTargetTemplates.isEmpty()){
             return;
         }
         accountTargetTemplates.forEach(targetTemplate -> aiKuaishouNewCreateCampaign.kuaishouAiAdsNewMaterialCreativity(targetTemplate));
     }
+
+    @XxlJob("kuaishouAiAdsHotMaterialCreativityJob")
+    public void kuaishouAiAdsHotMaterialCreativityJob() {
+        List<AiKuaishouAccountTargetTemplate> accountTargetTemplates = aiKuaishouAccountTargetTemplateService.getAllEffectTemplate();
+        if(null==accountTargetTemplates||accountTargetTemplates.isEmpty()){
+            return;
+        }
+        accountTargetTemplates.forEach(targetTemplate -> aiKuaishouNewCreateCampaign.kuaishouAiAdsHotMaterialCreativity(targetTemplate));
+    }
 }

+ 245 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/controller/KuaiShouMaterialControer.java

@@ -0,0 +1,245 @@
+package cn.com.ctop.kuaishou.modules.ai.controller;
+
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.kuaishou.modules.ai.entity.KuaiShouVideoLastTime;
+import cn.com.ctop.kuaishou.modules.ai.service.IKuaiShouVideoLastTimeService;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet;
+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.IKuaishouVideoRelateCreativesService;
+import com.alibaba.fastjson.JSONObject;
+import io.swagger.annotations.Api;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.util.DateUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Slf4j
+@Api(tags = "快手-批量工具")
+@RestController
+@RequestMapping("/kuaishou/Ai")
+public class KuaiShouMaterialControer {
+    @Autowired
+    private ICtopOauthTokenService tokenService;
+    @Autowired
+    private IKuaishouInterfaceService iKuaishouInterfaceService;
+    @Autowired
+    private IKuaiShouVideoLastTimeService lastTimeService;
+    @Autowired
+    private IKuaiShouVideoGetService videoGetService;
+    @Autowired
+    private IKuaishouVideoRelateCreativesService relateCreativesService;
+
+    /**
+     * 查询上新素材
+     *
+     * @param requestJson
+     * @return
+     */
+    @PostMapping(value = "/getNewVideoList")
+    public JSONObject getNewVideo(@RequestBody JSONObject requestJson) {
+        JSONObject returnJson = new JSONObject();
+        try {
+            if (Check.isNull(requestJson)) {
+                throw new Exception("入参不能为空");
+            }
+            Long accountId = requestJson.getLong("accountId");
+            if (Check.isNull(accountId)) {
+                throw new Exception("账户id不能为空");
+            }
+            CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
+            if (Check.isNull(token)) {
+                throw new Exception("未获取账号授权信息");
+            }
+            String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
+            iKuaishouInterfaceService.getVideoList(token, nowDate, nowDate);
+            iKuaishouInterfaceService.getSuZaoList(token.getAccessToken(), accountId, 1, nowDate, nowDate);
+            KuaiShouVideoLastTime videoLastTime = lastTimeService.getById(accountId);
+            Date startTime;
+            Date endDate = new Date();
+            if (!Check.isNull(videoLastTime)) {
+                startTime = videoLastTime.getLastTime();
+            } else {
+                startTime = DateUtils.addTime(endDate, 5);
+            }
+            Map<String, Object> requestMap = new HashMap<>();
+            requestMap.put("startTime", DateUtils.formatDate(startTime, "yyyy-MM-dd HH:mm:ss"));
+            requestMap.put("endTime", DateUtils.formatDate(endDate, "yyyy-MM-dd HH:mm:ss"));
+            requestMap.put("accountId", accountId);
+            List<JSONObject> materialList = videoGetService.getVideoListByMap(requestMap);
+            if (!Check.isNull(materialList)) {
+                for (int i = 0; i < materialList.size(); i++) {
+                    JSONObject materialJson = materialList.get(i);
+                    String signature = materialJson.getString("signature");
+                    List<String> imageList = lastTimeService.getImageListByMd5(signature);
+                    materialJson.put("imageList", imageList);
+                }
+                KuaiShouVideoLastTime lastTime = new KuaiShouVideoLastTime();
+                lastTime.setId(accountId);
+                lastTime.setLastTime(endDate);
+                lastTimeService.saveOrUpdate(lastTime);
+                returnJson.put("code", 0);
+                returnJson.put("message", "SUCCESS");
+                returnJson.put("data", materialList);
+            } else {
+                returnJson.put("code", -1);
+                returnJson.put("message", "暂未新上素材");
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            returnJson.put("code", -1);
+            returnJson.put("message", e.getMessage());
+        }
+        return returnJson;
+    }
+
+
+    @PostMapping(value = "/getHistoryVideoList")
+    public JSONObject getHistoryVideoList(@RequestBody JSONObject requestJson) {
+        JSONObject returnJson = new JSONObject();
+        try {
+            if (Check.isNull(requestJson)) {
+                throw new Exception("入参不能为空");
+            }
+            Long accountId = requestJson.getLong("accountId");
+            if (Check.isNull(accountId)) {
+                throw new Exception("账户id不能为空");
+            }
+
+
+            String startDate = requestJson.getString("startDate");
+            if (Check.isNull(startDate)) {
+                throw new Exception("请输入开始查询时间");
+            }
+
+            String endDate = requestJson.getString("endDate");
+            if (Check.isNull(endDate)) {
+                throw new Exception("请输入结束查询时间");
+            }
+
+            Integer createCount = requestJson.getInteger("createCount");
+            if (Check.isNull(createCount) || createCount == 0) {
+                throw new Exception("请输入最小关联数");
+            }
+
+            Integer num = requestJson.getInteger("num");
+            if (Check.isNull(num) || num == 0) {
+                throw new Exception("请输入查询条数");
+            }
+
+            Map<String, Object> requestMap = new HashMap<>();
+            requestMap.put("startTime", startDate);
+            requestMap.put("endTime", endDate);
+            requestMap.put("accountId", accountId);
+            requestMap.put("num", num);
+            requestMap.put("createCount", createCount);
+            List<JSONObject> materialList = relateCreativesService.getVideoListByMap(requestMap);
+            if (!Check.isNull(materialList)) {
+                for (int i = 0; i < materialList.size(); i++) {
+                    JSONObject materialJson = materialList.get(i);
+                    KuaiShouVideoGet videoGet = videoGetService.getVideoByPhotoId(materialJson.getLong("photo_id"));
+                    if (!Check.isNull(videoGet)) {
+                        String signature = videoGet.getSignature();
+                        materialJson.put("signature", signature);
+                        materialJson.put("video_url", videoGet.getUrl());
+                        materialJson.put("channel_type", videoGet.getChannelType());
+                        List<String> imageList = lastTimeService.getImageListByMd5(signature);
+                        materialJson.put("imageList", imageList);
+                    }
+                }
+                returnJson.put("code", 0);
+                returnJson.put("message", "SUCCESS");
+                returnJson.put("data", materialList);
+            } else {
+                returnJson.put("code", -1);
+                returnJson.put("message", "暂未新上素材");
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            returnJson.put("code", -1);
+            returnJson.put("message", e.getMessage());
+        }
+        return returnJson;
+    }
+
+
+    @PostMapping(value = "/getHistoryTopVideoList")
+    public JSONObject getHistoryTopVideoList(@RequestBody JSONObject requestJson) {
+        JSONObject returnJson = new JSONObject();
+        try {
+            if (Check.isNull(requestJson)) {
+                throw new Exception("入参不能为空");
+            }
+            Long accountId = requestJson.getLong("accountId");
+            if (Check.isNull(accountId)) {
+                throw new Exception("账户id不能为空");
+            }
+
+
+            String startDate = requestJson.getString("startDate");
+            if (Check.isNull(startDate)) {
+                throw new Exception("请输入开始查询时间");
+            }
+
+            String endDate = requestJson.getString("endDate");
+            if (Check.isNull(endDate)) {
+                throw new Exception("请输入结束查询时间");
+            }
+
+            Integer createCount = requestJson.getInteger("createCount");
+            if (Check.isNull(createCount) || createCount == 0) {
+                throw new Exception("请输入最小关联数");
+            }
+
+            Integer num = requestJson.getInteger("num");
+            if (Check.isNull(num) || num == 0) {
+                throw new Exception("请输入查询条数");
+            }
+
+            Map<String, Object> requestMap = new HashMap<>();
+            requestMap.put("startTime", startDate);
+            requestMap.put("endTime", endDate);
+            requestMap.put("accountId", accountId);
+            requestMap.put("num", num);
+            requestMap.put("createCount", createCount);
+            List<JSONObject> materialList = relateCreativesService.getVideoListByMap(requestMap);
+            if (!Check.isNull(materialList)) {
+                for (int i = 0; i < materialList.size(); i++) {
+                    JSONObject materialJson = materialList.get(i);
+                    KuaiShouVideoGet videoGet = videoGetService.getVideoByPhotoId(materialJson.getLong("photo_id"));
+                    if (!Check.isNull(videoGet)) {
+                        String signature = videoGet.getSignature();
+                        materialJson.put("signature", signature);
+                        materialJson.put("video_url", videoGet.getUrl());
+                        materialJson.put("channel_type", videoGet.getChannelType());
+                        List<String> imageList = lastTimeService.getImageListByMd5(signature);
+                        materialJson.put("imageList", imageList);
+                    }
+                }
+                returnJson.put("code", 0);
+                returnJson.put("message", "SUCCESS");
+                returnJson.put("data", materialList);
+            } else {
+                returnJson.put("code", -1);
+                returnJson.put("message", "暂未新上素材");
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            returnJson.put("code", -1);
+            returnJson.put("message", e.getMessage());
+        }
+        return returnJson;
+    }
+
+
+}

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

@@ -72,4 +72,6 @@ public class AiKuaishouAccountTargetTemplate {
 	private Date createTime;
 	/**updateTime*/
 	private Date updateTime;
+	private String titlePrefix;
+	private String titleMiddle;
 }

+ 56 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/entity/KuaiShouVideoLastTime.java

@@ -0,0 +1,56 @@
+package cn.com.ctop.kuaishou.modules.ai.entity;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import org.jeecgframework.poi.excel.annotation.Excel;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.util.Date;
+
+/**
+ * ai获取素材上次截止日期
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2021-01-11
+ */
+@Data
+@TableName("ctop_kuaishou_video_last_time")
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value = "ctop_kuaishou_video_last_time对象", description = "ai获取素材上次截止日期")
+public class KuaiShouVideoLastTime {
+
+    /**
+     * 账户ID
+     */
+    @Excel(name = "账户ID", width = 15)
+    @ApiModelProperty(value = "账户ID")
+    private Long Id;
+    /**
+     * 素材最后上新时间
+     */
+    @ApiModelProperty(value = "素材最后上新时间")
+    private Date lastTime;
+    /**
+     * 创建时间
+     */
+    @Excel(name = "创建时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "创建时间")
+    private Date createTime;
+    /**
+     * 修改时间
+     */
+    @Excel(name = "修改时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "修改时间")
+    private Date updateTime;
+}

+ 18 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/KuaiShouVideoLastTimeMapper.java

@@ -0,0 +1,18 @@
+package cn.com.ctop.kuaishou.modules.ai.mapper;
+
+import cn.com.ctop.kuaishou.modules.ai.entity.KuaiShouVideoLastTime;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+import java.util.List;
+
+/**
+ * ai获取素材上次截止日期
+ *
+ * @author: jeecg-boot
+ * @date: 2021-01-11
+ * @cersion: V1.0
+ */
+public interface KuaiShouVideoLastTimeMapper extends BaseMapper<KuaiShouVideoLastTime> {
+
+    List<String> getImageListByMd5(String signature);
+}

+ 12 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/xml/KuaiShouVideoLastTimeMapper.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="cn.com.ctop.kuaishou.modules.ai.mapper.KuaiShouVideoLastTimeMapper">
+    <select id="getImageListByMd5" resultType="java.lang.String">
+      select
+      signature
+      from ctop_material_cut_frame
+      where video_signature = #{md5}
+      limit 15
+    </select>
+
+</mapper>

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

@@ -4,4 +4,6 @@ import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouAccountTargetTemplate;
 
 public interface IAiKuaishouNewCreateCampaign {
     void kuaishouAiAdsNewMaterialCreativity(AiKuaishouAccountTargetTemplate targetTemplate);
+
+    void kuaishouAiAdsHotMaterialCreativity(AiKuaishouAccountTargetTemplate targetTemplate);
 }

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

@@ -0,0 +1,17 @@
+package cn.com.ctop.kuaishou.modules.ai.service;
+
+import cn.com.ctop.kuaishou.modules.ai.entity.KuaiShouVideoLastTime;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+import java.util.List;
+
+/**
+ * @Description: ai获取素材上次截止日期
+ * @Author: jeecg-boot
+ * @Date: 2021-01-11
+ * @Version: V1.0
+ */
+public interface IKuaiShouVideoLastTimeService extends IService<KuaiShouVideoLastTime> {
+
+    List<String> getImageListByMd5(String signature);
+}

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

@@ -12,6 +12,7 @@ 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.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;
@@ -48,6 +49,9 @@ public class AiKuaishouNewCreateCampaignServiceImpl implements IAiKuaishouNewCre
     private IKuaiShouImageGetService imageGetService;
     @Autowired
     private IKuaiShouMaterialUploadService materialUploadService;
+    @Autowired
+    private KuaiShouVideoGetMapper videoGetMapper;
+
 
     @Override
     public void kuaishouAiAdsNewMaterialCreativity(AiKuaishouAccountTargetTemplate targetTemplate) {
@@ -101,7 +105,7 @@ public class AiKuaishouNewCreateCampaignServiceImpl implements IAiKuaishouNewCre
             String timestamp = DateUtils.formatDate(campaignDate,"yyyyMMddHHmmss");
             JSONObject campaignParams = new JSONObject();
             campaignParams.put("advertiser_id",token.getAccountId());
-            String campaignName = "户14-上下滑&信息流" + "-素材上新-"+ "剪辑-低价-低价包邮-活动-年龄18岁以上-单出价-"+ timestamp;
+            String campaignName = targetTemplate.getTitlePrefix() + "素材上新"+ targetTemplate.getTitleMiddle()+ timestamp;
             campaignParams.put("campaign_name",campaignName);
             campaignParams.put("type",Integer.parseInt(targetTemplate.getMarketingGoal()));
             campaignParams.put("day_budget",0L);
@@ -117,7 +121,7 @@ public class AiKuaishouNewCreateCampaignServiceImpl implements IAiKuaishouNewCre
 
         //3、在“上新”计划中新增广告组,一个素材搭配5张封面,组成一个广告组
         String timestamp = DateUtils.formatDate(new Date(),"yyyyMMddHHmmss");
-        String unitNamePrefix = "户14-上下滑&信息流" + "-素材上新-"+ "剪辑-低价-低价包邮-活动-年龄18岁以上-单出价-"+ timestamp;
+        String unitNamePrefix = targetTemplate.getTitlePrefix() + "素材上新"+ targetTemplate.getTitleMiddle()+ timestamp;
         int unitCnt = 0;
         for(KuaiShouVideoGet videoItem: newVideos){
             unitCnt ++;
@@ -144,6 +148,85 @@ public class AiKuaishouNewCreateCampaignServiceImpl implements IAiKuaishouNewCre
         }
     }
 
+    @Override
+    public void kuaishouAiAdsHotMaterialCreativity(AiKuaishouAccountTargetTemplate targetTemplate) {
+        Long accountId = targetTemplate.getAccountId();
+        CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId.toString());
+        if(null == token){
+            log.info("token获取失败=>accountId:{}",accountId);
+            return;
+        }
+
+        int days = 14;
+        int highQualityVideoCnt = 100;
+        List<KuaiShouVideoGet>highQualityVideos = videoGetMapper.getHighQualityVideo(accountId,days,highQualityVideoCnt);
+        if (null == highQualityVideos||highQualityVideos.isEmpty()){
+            log.info("此项目下无视频");
+            return;
+        }
+
+        JSONArray campaignList = kuaishouInterfaceService.getCampaignList(token, new Date(), new Date(),1);
+        boolean isHaveHotCampaign = 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("爆量素材")){
+                    isHaveHotCampaign = true;
+                    newCampaignId = jsonObject.getLong("campaign_id");
+                    break;
+                }
+            }
+        }
+
+        if (!isHaveHotCampaign){
+            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(KuaiShouVideoGet videoItem: highQualityVideos){
+            unitCnt ++;
+            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");
+
+            // 每个组,搭配5个创意
+            List<MaterialCutFrame> cutFrameList = materialCutFrameService.getListByVideoSignature(videoItem.getSignature());
+            List<MaterialImageInfo> orgFrameList = materialImageInfoService.getListByVideoSignature(videoItem.getSignature());
+            if ((null == cutFrameList||cutFrameList.isEmpty())&&(null == orgFrameList|| orgFrameList.isEmpty())){
+                log.info("未获取到视频封面=>videoSignature:{}",videoItem.getSignature());
+                continue;
+            }
+            JSONObject creativeParams = creativeParams(token, unitId, videoItem, targetTemplate);
+            createCreativeByImage(cutFrameList, orgFrameList,token, creativeParams, newCampaignId, unitId, videoItem,targetTemplate.getImageNumber());
+        }
+
+    }
 
 
     private JSONObject creativeParams(CtopOauthToken token,Long unitId,KuaiShouVideoGet videoItem,AiKuaishouAccountTargetTemplate targetTemplate){

+ 6 - 6
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/AiStrategyServiceImpl.java

@@ -97,17 +97,17 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
         String endDate = DateUtils.formatDate(new Date(now.getTime() - dimeDiff*60*1000),"yyyy-MM-dd HH:mm:ss");
         kuaishouInterfaceService.getSuZaoList(token.getAccessToken(), token.getAccountId(), 1, startDate, endDate)));*/
 
-        JSONObject MaterialSelectMethod = JSONObject.parseObject(strategyTemplate.getMaterialSelectMethod());
+        JSONObject materialSelectMethod = JSONObject.parseObject(strategyTemplate.getMaterialSelectMethod());
         List<KuaiShouVideoGet> newVideos = new ArrayList<KuaiShouVideoGet>();
         List<KuaiShouVideoGet> highQualityVideos = new ArrayList<KuaiShouVideoGet>();
 
-        if (MaterialSelectMethod.containsKey("newMaterialNum")){
-            int newVideoCnt = (int) MaterialSelectMethod.get("newMaterialNum");
+        if (materialSelectMethod.containsKey("newMaterialNum")){
+            int newVideoCnt = (int) materialSelectMethod.get("newMaterialNum");
             newVideos = videoGetService.getNewVideoDescDate(accountId,newVideoCnt);
         }
-        if(MaterialSelectMethod.containsKey("highQualityMaterial")){
-            int days = MaterialSelectMethod.getJSONObject("highQualityMaterial").getInteger("days");
-            int highQualityVideoCnt = MaterialSelectMethod.getJSONObject("highQualityMaterial").getInteger("num");
+        if(materialSelectMethod.containsKey("highQualityMaterial")){
+            int days = materialSelectMethod.getJSONObject("highQualityMaterial").getInteger("days");
+            int highQualityVideoCnt = materialSelectMethod.getJSONObject("highQualityMaterial").getInteger("num");
             highQualityVideos = videoGetMapper.getHighQualityVideo(accountId,days,highQualityVideoCnt);
         }
 

+ 28 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/KuaiShouVideoLastTimeServiceImpl.java

@@ -0,0 +1,28 @@
+package cn.com.ctop.kuaishou.modules.ai.service.impl;
+
+import cn.com.ctop.kuaishou.modules.ai.entity.KuaiShouVideoLastTime;
+import cn.com.ctop.kuaishou.modules.ai.mapper.KuaiShouVideoLastTimeMapper;
+import cn.com.ctop.kuaishou.modules.ai.service.IKuaiShouVideoLastTimeService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * ai获取素材上次截止日期
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2021-01-11
+ */
+@Service
+public class KuaiShouVideoLastTimeServiceImpl extends ServiceImpl<KuaiShouVideoLastTimeMapper, KuaiShouVideoLastTime> implements IKuaiShouVideoLastTimeService {
+    @Autowired
+    private KuaiShouVideoLastTimeMapper videoLastTimeMapper;
+
+    @Override
+    public List<String> getImageListByMd5(String signature) {
+        return videoLastTimeMapper.getImageListByMd5(signature);
+    }
+}

+ 3 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/KuaiShouVideoGetMapper.java

@@ -2,6 +2,7 @@ package cn.com.ctop.kuaishou.modules.batch.mapper;
 
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet;
 import cn.com.ctop.kuaishou.modules.batch.entity.vo.KuaiShouVideoGetVo;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Param;
 
@@ -21,6 +22,7 @@ public interface KuaiShouVideoGetMapper extends BaseMapper<KuaiShouVideoGet> {
     List<KuaiShouVideoGetVo> getVideoList(Map<String, Object> requestMap);
 
     List<KuaiShouVideoGet> getHighQualityVideo(long accountId,int days,int num);
-
     List<KuaiShouVideoGet> selectPhotoIdsByAccountId(Long accountId);
+    List<JSONObject> getVideoListByMap(Map<String, Object> requestMap);
+
 }

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

@@ -1,10 +1,12 @@
 package cn.com.ctop.kuaishou.modules.batch.mapper;
 
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouVideoRelateCreatives;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * 频库-视频关联创意数查询
@@ -16,4 +18,6 @@ import java.util.List;
 public interface KuaishouVideoRelateCreativesMapper extends BaseMapper<KuaishouVideoRelateCreatives> {
 
     void insertBatch(@Param(value = "videolist") List<KuaishouVideoRelateCreatives> videolist);
+
+    List<JSONObject> getVideoListByMap(Map<String, Object> requestMap);
 }

+ 22 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaiShouVideoGetMapper.xml

@@ -87,5 +87,27 @@
         and status = 0
     </select>
 
+    <select id="getVideoListByMap" resultType="com.alibaba.fastjson.JSONObject">
+        select
+        photo_id as 'photo_id',
+        signature as 'signature',
+        stat_date as 'stat_date',
+        channel_type as 'channel_type',
+        url as 'video_url'
+        from ctop_kuaishou_video_get
+        where 1 = 1
+        <if test="accountId != null and accountId != '' ">
+            and account_id = #{accountId}
+        </if>
+        <if test="startTime != null and startTime != '' ">
+            and stat_date &gt;= #{startTime}
+        </if>
+        <if test="endTime != null and endTime != '' ">
+            and stat_date &lt;= #{endTime}
+        </if>
+        group by signature
+        order by stat_date desc
+    </select>
+
 
 </mapper>

+ 29 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaishouVideoRelateCreativesMapper.xml

@@ -20,4 +20,33 @@
         </foreach>
     </insert>
 
+
+    <select id="getVideoListByMap" resultType="com.alibaba.fastjson.JSONObject">
+        select
+        photo_id as 'photo_id',
+        stat_date as 'stat_date',
+        creative_count as 'creative_count'
+        FROM ctop_kuaishou_video_relate_creatives AS t1
+        JOIN (SELECT ROUND(RAND() * (SELECT MAX(id) FROM
+        ctop_kuaishou_video_relate_creatives
+        where 1 = 1
+        <if test="accountId != null and accountId != '' ">
+            and account_id = #{accountId}
+        </if>
+        <if test="startTime != null and startTime != '' ">
+            and DATE_FORMAT(stat_date,'%Y-%m-%d') &gt;= #{startTime}
+        </if>
+        <if test="endTime != null and endTime != '' ">
+            and DATE_FORMAT(stat_date,'%Y-%m-%d') &lt;= #{endTime}
+        </if>
+        )) AS id) AS t2
+        WHERE t1.id >= t2.id
+        <if test="accountId != null and accountId != '' ">
+            and account_id = #{accountId}
+        </if>
+        <if test="createCount != null and createCount != '' ">
+            AND creative_count &lt;= #{createCount}
+        </if>
+        ORDER BY t1.id ASC LIMIT #{num}
+    </select>
 </mapper>

+ 4 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaiShouVideoGetService.java

@@ -2,7 +2,7 @@ package cn.com.ctop.kuaishou.modules.batch.service;
 
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet;
 import cn.com.ctop.kuaishou.modules.batch.entity.vo.KuaiShouVideoGetVo;
-import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouVideoGetMapper;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
 
 import java.util.List;
@@ -30,5 +30,8 @@ public interface IKuaiShouVideoGetService extends IService<KuaiShouVideoGet> {
 
     List<KuaiShouVideoGet> getNewVideoBetweenTime(Long accountId,String startTime, String endTime);
 
+    List<JSONObject> getVideoListByMap(Map<String, Object> requestMap);
     List<KuaiShouVideoGet> selectPhotoIdsByAccountId(Long accountId);
+
+    KuaiShouVideoGet getVideoByPhotoId(Long photo_id);
 }

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

@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
 import org.jeecg.common.api.vo.Result;
 
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -16,8 +17,9 @@ import java.util.Map;
  */
 public interface IKuaishouVideoRelateCreativesService extends IService<KuaishouVideoRelateCreatives> {
 
-    public Result pushVideo(JSONObject data);
+    Result pushVideo(JSONObject data);
 
-    public void videoRelateCreatives(Long accountId, JSONArray photoIds, Map<String,Object> statdateMap);
+    void videoRelateCreatives(Long accountId, JSONArray photoIds, Map<String, Object> statdateMap);
 
+    List<JSONObject> getVideoListByMap(Map<String, Object> requestMap);
 }

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

@@ -289,6 +289,7 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
             executorService.submit(new Runnable() {
                 @Override
                 public void run() {
+
                     Long accountId = template.getAccountId();
                     CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
                     if (Check.isNull(token)) {
@@ -416,6 +417,7 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
                     } catch (InterruptedException e) {
                         e.printStackTrace();
                     }
+
                 }
             });
         }

+ 33 - 20
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouVideoGetServiceImpl.java

@@ -22,8 +22,6 @@ import java.io.IOException;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
 
 /**
  * @Description: 快手-获取视频接口
@@ -122,13 +120,13 @@ public class KuaiShouVideoGetServiceImpl extends ServiceImpl<KuaiShouVideoGetMap
     }
 
     @Override
-    public List<KuaiShouVideoGet> getNewVideoByAccountId(Long accountId,Integer aiStatus) {
-        QueryWrapper<KuaiShouVideoGet>queryWrapper = new QueryWrapper<>();
-        if(null!=accountId&&accountId!=0){
-            queryWrapper.eq("account_id",accountId);
+    public List<KuaiShouVideoGet> getNewVideoByAccountId(Long accountId, Integer aiStatus) {
+        QueryWrapper<KuaiShouVideoGet> queryWrapper = new QueryWrapper<>();
+        if (null != accountId && accountId != 0) {
+            queryWrapper.eq("account_id", accountId);
         }
-        if(null!=aiStatus&&aiStatus!=0){
-            queryWrapper.eq("ai_status",aiStatus);
+        if (null != aiStatus && aiStatus != 0) {
+            queryWrapper.eq("ai_status", aiStatus);
         }
         queryWrapper.orderByDesc("stat_date");
         return this.list(queryWrapper);
@@ -136,12 +134,12 @@ public class KuaiShouVideoGetServiceImpl extends ServiceImpl<KuaiShouVideoGetMap
 
 
     @Override
-    public List<KuaiShouVideoGet>getNewVideoDescDate(Long accountId,Integer newVideoCnt){
-        QueryWrapper<KuaiShouVideoGet>queryWrapper = new QueryWrapper<>();
-        if(null!=accountId&&accountId!=0){
-            queryWrapper.eq("account_id",accountId);
+    public List<KuaiShouVideoGet> getNewVideoDescDate(Long accountId, Integer newVideoCnt) {
+        QueryWrapper<KuaiShouVideoGet> queryWrapper = new QueryWrapper<>();
+        if (null != accountId && accountId != 0) {
+            queryWrapper.eq("account_id", accountId);
         }
-        if(null!=newVideoCnt && newVideoCnt>0){
+        if (null != newVideoCnt && newVideoCnt > 0) {
             queryWrapper.orderByDesc("stat_date");
             queryWrapper.last("limit " + newVideoCnt);
         }
@@ -150,21 +148,36 @@ public class KuaiShouVideoGetServiceImpl extends ServiceImpl<KuaiShouVideoGetMap
 
 
     @Override
-    public List<KuaiShouVideoGet>getNewVideoBetweenTime(Long accountId,String startTime, String endTime){
-        QueryWrapper<KuaiShouVideoGet>queryWrapper = new QueryWrapper<>();
-        if(null!=accountId&&accountId!=0){
-            queryWrapper.eq("account_id",accountId);
+    public List<KuaiShouVideoGet> getNewVideoBetweenTime(Long accountId, String startTime, String endTime) {
+        QueryWrapper<KuaiShouVideoGet> queryWrapper = new QueryWrapper<>();
+        if (null != accountId && accountId != 0) {
+            queryWrapper.eq("account_id", accountId);
         }
-        if(null != startTime && null != endTime){
-            queryWrapper.le("stat_date",endTime);
-            queryWrapper.gt("stat_date",startTime);
+        if (null != startTime && null != endTime) {
+            queryWrapper.le("stat_date", endTime);
+            queryWrapper.gt("stat_date", startTime);
         }
         return this.list(queryWrapper);
     }
 
     @Override
+    public List<JSONObject> getVideoListByMap(Map<String, Object> requestMap) {
+        return videoGetMapper.getVideoListByMap(requestMap);
+    }
+
+
+    @Override
     public List<KuaiShouVideoGet> selectPhotoIdsByAccountId(Long accountId) {
         return videoGetMapper.selectPhotoIdsByAccountId(accountId);
     }
 
+    @Override
+    public KuaiShouVideoGet getVideoByPhotoId(Long photo_id) {
+        QueryWrapper<KuaiShouVideoGet> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("photo_id", photo_id);
+        queryWrapper.last("limit 1");
+        KuaiShouVideoGet videoGet = videoGetMapper.selectOne(queryWrapper);
+        return videoGet;
+    }
+
 }

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

@@ -140,4 +140,9 @@ public class KuaishouVideoRelateCreativesServiceImpl extends ServiceImpl<Kuaisho
             log.error("频库-视频关联创意数查询失败", e);
         }
     }
+
+    @Override
+    public List<JSONObject> getVideoListByMap(Map<String, Object> requestMap) {
+        return kuaishouVideoRelateCreativesMapper.getVideoListByMap(requestMap);
+    }
 }