Bläddra i källkod

V1.1.3 自动投放 批量修改出价 获取素材接口兼容app信息

yumeng 4 år sedan
förälder
incheckning
9da90b2a8b
14 ändrade filer med 229 tillägg och 36 borttagningar
  1. 1 0
      jeecg-boot-module-system/src/main/java/org/jeecg/config/ShiroConfig.java
  2. 1 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/controller/AiKuaiShouAppInfoController.java
  3. 80 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/controller/KuaiShouBatchUpdateController.java
  4. 28 5
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/controller/KuaiShouMaterialControer.java
  5. 8 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/IKuaiShouBatchUpdateService.java
  6. 55 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/KuaiShouBatchUpdateServiceImpl.java
  7. 2 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/KuaiShouGroupMapper.java
  8. 3 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/KuaiShouVideoGetMapper.java
  9. 5 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaiShouGroupMapper.xml
  10. 6 2
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaiShouVideoGetMapper.xml
  11. 32 28
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaishouVideoRelateCreativesMapper.xml
  12. 2 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaiShouGroupService.java
  13. 1 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaiShouVideoGetService.java
  14. 5 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouGroupServiceImpl.java

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

@@ -189,6 +189,7 @@ public class ShiroConfig {
         filterChainDefinitionMap.put("/kuaishou/creative/*", "anon");
         filterChainDefinitionMap.put("/ai/aiKuaiShouAppInfo/*", "anon");
         filterChainDefinitionMap.put("/explore/*", "anon");
+        filterChainDefinitionMap.put("/ai/batchUpdate/*", "anon");
 
         // 添加自己的过滤器并且取名为jwt
         Map<String, Filter> filterMap = new HashMap<>(1);

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

@@ -88,6 +88,7 @@ public class AiKuaiShouAppInfoController {
 
 
     @PostMapping(value = "/importAppExcel")
+    @ResponseBody
     public JSONObject importExcel(@RequestParam("file") MultipartFile file,
                                   @RequestParam("accountId") Long accountId,
                                   @RequestParam("platform") Integer platform,

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

@@ -0,0 +1,80 @@
+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.service.IKuaiShouBatchUpdateService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouGroupService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
+import com.alibaba.fastjson.JSONObject;
+import lombok.extern.slf4j.Slf4j;
+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.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+@Slf4j
+@RestController
+@RequestMapping("/ai/batchUpdate/")
+public class KuaiShouBatchUpdateController {
+    @Autowired
+    private ICtopOauthTokenService tokenService;
+    @Autowired
+    private IKuaishouInterfaceService kuaishouInterfaceService;
+    @Autowired
+    private IKuaiShouBatchUpdateService batchUpdateService;
+    @Autowired
+    private IKuaiShouGroupService groupService;
+
+    static ExecutorService executorService = Executors.newFixedThreadPool(5);
+
+    @PostMapping(value = "/updateGroupBid")
+    public JSONObject getAppDetail(@RequestBody JSONObject requestJson) {
+        JSONObject returnJson = new JSONObject();
+        try {
+            Long accountId = requestJson.getLong("accountId");
+            if (Check.isNull(accountId)) {
+                throw new Exception("请输入账户");
+            }
+            CtopOauthToken oauthToken = tokenService.getTokenByAccountId(accountId);
+            if (Check.isNull(oauthToken)) {
+                throw new Exception("未获取到账户信息");
+            }
+            Long bid = requestJson.getLong("bid");
+            if (Check.isNull(bid) || bid == 0) {
+                throw new Exception("请传入需要修改的出价,或出价不能改为0");
+            }
+            executorService.submit(new Runnable() {
+                @Override
+                public void run() {
+                    try {
+                        log.info("开始异步执行修改出价,accountId:{}", accountId);
+                        groupService.deleteByAccountId(accountId);
+                        log.info("历史数据清除完成,accountId:{}", accountId);
+                        kuaishouInterfaceService.getGroupList(oauthToken, null, null);
+                        log.info("最新数据获取完成,accountId:{}", accountId);
+                        Thread.sleep(1000);
+                        batchUpdateService.updateBid(oauthToken, bid);
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    } finally {
+                    }
+                }
+            });
+
+
+            returnJson.put("code", 0);
+            returnJson.put("message", "success");
+
+        } catch (Exception e) {
+            returnJson.put("code", -1);
+            returnJson.put("message", e.getMessage());
+        }
+        return returnJson;
+    }
+
+}

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

@@ -61,9 +61,9 @@ public class KuaiShouMaterialControer {
             if (Check.isNull(token)) {
                 throw new Exception("未获取账号授权信息");
             }
+            String appVersion = requestJson.getString("appVersion");
             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();
@@ -76,6 +76,9 @@ public class KuaiShouMaterialControer {
             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);
+            if (!Check.isNull(appVersion)) {
+                requestMap.put("appVersion", appVersion);
+            }
             List<JSONObject> materialList = videoGetService.getVideoListByMap(requestMap);
             if (!Check.isNull(materialList)) {
                 for (int i = 0; i < materialList.size(); i++) {
@@ -138,12 +141,16 @@ public class KuaiShouMaterialControer {
             if (Check.isNull(num) || num == 0) {
                 throw new Exception("请输入查询条数");
             }
+            String appVersion = requestJson.getString("appVersion");
             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);
+            if (!Check.isNull(appVersion)) {
+                requestMap.put("appVersion", appVersion);
+            }
             List<JSONObject> materialList = relateCreativesService.getVideoListByMap(requestMap);
             if (!Check.isNull(materialList)) {
                 for (int i = 0; i < materialList.size(); i++) {
@@ -155,6 +162,7 @@ public class KuaiShouMaterialControer {
                         materialJson.put("video_url", videoGet.getUrl());
                         materialJson.put("material_type", videoGet.getMaterialType());
                         materialJson.put("channel_type", videoGet.getChannelType());
+                        materialJson.put("photo_name", videoGet.getPhotoName());
                         List<String> imageList = lastTimeService.getImageListByMd5(signature);
                         materialJson.put("imageList", imageList);
                     }
@@ -204,19 +212,29 @@ public class KuaiShouMaterialControer {
             if (Check.isNull(num) || num == 0) {
                 throw new Exception("请输入查询条数");
             }
+            String appVersion = requestJson.getString("appVersion");
             Map<String, Object> requestMap = new HashMap<>();
             requestMap.put("startDate", startDate);
             requestMap.put("endDate", endDate);
             requestMap.put("accountId", accountId);
             requestMap.put("num", num);
+            if (!Check.isNull(appVersion)) {
+                requestMap.put("appVersion", appVersion);
+            }
             List<JSONObject> materialList = relateCreativesService.getHistoryTopVideoList(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);
-
+                    KuaiShouVideoGet videoGet = videoGetService.getVideoByPhotoId(materialJson.getLong("photo_id"));
+                    if (!Check.isNull(videoGet)) {
+                        String signature = videoGet.getSignature();
+                        materialJson.put("video_url", videoGet.getUrl());
+                        materialJson.put("material_type", videoGet.getMaterialType());
+                        materialJson.put("channel_type", videoGet.getChannelType());
+                        materialJson.put("photo_name", videoGet.getPhotoName());
+                        List<String> imageList = lastTimeService.getImageListByMd5(signature);
+                        materialJson.put("imageList", imageList);
+                    }
                 }
                 returnJson.put("code", 0);
                 returnJson.put("message", "SUCCESS");
@@ -264,12 +282,16 @@ public class KuaiShouMaterialControer {
             if (Check.isNull(endTime)) {
                 throw new Exception("请输入查询结束时间");
             }
+            String appVersion = requestJson.getString("appVersion");
             Map<String, Object> requestMap = new HashMap<>();
             requestMap.put("startTime", startTime);
             requestMap.put("endTime", endTime);
             requestMap.put("accountId", accountId);
             requestMap.put("creativeCount", 0);
             requestMap.put("videoCnt", videoCnt);
+            if (!Check.isNull(appVersion)) {
+                requestMap.put("appVersion", appVersion);
+            }
             List<JSONObject> materialList = relateCreativesService.getVideoZeroListByMap(requestMap);
             if (!Check.isNull(materialList)) {
                 for (int i = 0; i < materialList.size(); i++) {
@@ -281,6 +303,7 @@ public class KuaiShouMaterialControer {
                         materialJson.put("video_url", videoGet.getUrl());
                         materialJson.put("channel_type", videoGet.getChannelType());
                         materialJson.put("material_type", videoGet.getMaterialType());
+                        materialJson.put("photo_name", videoGet.getPhotoName());
                         List<String> imageList = lastTimeService.getImageListByMd5(signature);
                         materialJson.put("imageList", imageList);
                     }

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

@@ -0,0 +1,8 @@
+package cn.com.ctop.kuaishou.modules.ai.service;
+
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+
+public interface IKuaiShouBatchUpdateService {
+
+    void updateBid(CtopOauthToken oauthToken, Long bid);
+}

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

@@ -0,0 +1,55 @@
+package cn.com.ctop.kuaishou.modules.ai.service.impl;
+
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.kuaishou.modules.ai.service.IKuaiShouBatchUpdateService;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouGroup;
+import cn.com.ctop.kuaishou.modules.batch.service.IBatchService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouGroupService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouUpdateService;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+@Service
+public class KuaiShouBatchUpdateServiceImpl implements IKuaiShouBatchUpdateService {
+    @Autowired
+    private IKuaiShouGroupService groupService;
+    static ExecutorService executorService = Executors.newFixedThreadPool(40);
+    @Autowired
+    private IBatchService batchService;
+    @Autowired
+    private IKuaiShouUpdateService updateService;
+
+    @Override
+    public void updateBid(CtopOauthToken oauthToken, Long bid) {
+        QueryWrapper<KuaiShouGroup> groupQueryWrapper = new QueryWrapper<>();
+        groupQueryWrapper.eq("account_id", oauthToken.getAccountId());
+        List<KuaiShouGroup> groupList = groupService.list(groupQueryWrapper);
+        if (Check.isNull(groupList)) {
+            return;
+        }
+        for (KuaiShouGroup group : groupList) {
+            executorService.submit(new Runnable() {
+                @Override
+                public void run() {
+                    try {
+                        JSONObject unitJson = new JSONObject();
+                        unitJson.put("advertiser_id", oauthToken.getAccountId());
+                        unitJson.put("unit_id", group.getUnitId());
+                        unitJson.put("cpa_bid", bid);
+                        updateService.updateUnit(oauthToken.getAccessToken(), unitJson);
+                        Thread.sleep(1500);
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+                }
+            });
+        }
+    }
+}

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

@@ -28,4 +28,6 @@ public interface KuaiShouGroupMapper extends BaseMapper<KuaiShouGroup> {
     void delAllGroupByCampaignId(@Param("accountId") Long accountId, @Param("campaignId") Long campaignId);
 
     List<KuaiShouGroup> queryUnitInfoByCampaignId(@Param("accountId") Long accountId, @Param("campaignId") Long campaignId);
+
+    void deleteByAccountId(@Param("accountId") Long accountId);
 }

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

@@ -21,8 +21,10 @@ public interface KuaiShouVideoGetMapper extends BaseMapper<KuaiShouVideoGet> {
 
     List<KuaiShouVideoGetVo> getVideoList(Map<String, Object> requestMap);
 
-    List<KuaiShouVideoGet> getHighQualityVideo(long accountId,int days,int num);
+    List<KuaiShouVideoGet> getHighQualityVideo(long accountId, int days, int num);
+
     List<KuaiShouVideoGet> selectPhotoIdsByAccountId(Long accountId);
+
     List<JSONObject> getVideoListByMap(Map<String, Object> requestMap);
 
     List<KuaiShouVideoGet> getPhotoIdsByParams(Long accountId, String signature);

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

@@ -131,4 +131,9 @@
         AND campaign_id = #{campaignId}
     </delete>
 
+    <delete id="deleteByAccountId">
+        delete from ctop_kuaishou_group
+        where  account_id = #{accountId}
+    </delete>
+
 </mapper>

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

@@ -99,7 +99,8 @@
         stat_date as 'stat_date',
         material_type as 'material_type',
         channel_type as 'channel_type',
-        url as 'video_url'
+        url as 'video_url',
+        photo_name as 'photo_name'
         from ctop_kuaishou_video_get
         where 1 = 1
         <if test="accountId != null and accountId != '' ">
@@ -111,6 +112,9 @@
         <if test="endTime != null and endTime != '' ">
             and stat_date &lt;= #{endTime}
         </if>
+        <if test="appVersion != null and appVersion != '' ">
+            and photo_name like concat(#{appVersion}'%')
+        </if>
         group by signature
         order by stat_date desc
     </select>
@@ -119,7 +123,7 @@
         where account_id = #{accountId}
         and signature = #{signature}
         and status = 0
-    </select>
+    </select
 
 
 </mapper>

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

@@ -23,31 +23,31 @@
 
     <select id="getVideoListByMap" resultType="com.alibaba.fastjson.JSONObject">
         select
-        photo_id as 'photo_id',
-        stat_date as 'stat_date',
-        creative_count as 'creative_count'
+        t1.photo_id as 'photo_id',
+        t1.stat_date as 'stat_date',
+        t1.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
+        WHERE 1 = 1
         <if test="accountId != null and accountId != '' ">
-            and account_id = #{accountId}
+            and t1.account_id = #{accountId}
+        </if>
+        <if test="createCount != null and createCount != '' ">
+            AND t1.creative_count &lt;= #{createCount}
         </if>
         <if test="startTime != null and startTime != '' ">
-            and DATE_FORMAT(stat_date,'%Y-%m-%d') &gt;= #{startTime}
+            and t1.stat_date &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}
+            and t1.stat_date &lt;= #{endTime}
         </if>
-        <if test="createCount != null and createCount != '' ">
-            AND creative_count &lt;= #{createCount}
+        <if test="appVersion != null and appVersion != '' ">
+            and t1.photo_id in (
+            select photo_id from ctop_kuaishou_video_get
+            where account_id = #{accountId}
+            and photo_name like concat(#{appVersion}'%')
+            )
         </if>
-        ORDER BY t1.id ASC LIMIT #{num}
+        LIMIT #{num}
     </select>
 
     <select id="getVideoZeroListByMap" resultType="com.alibaba.fastjson.JSONObject">
@@ -69,22 +69,26 @@
         <if test="endTime != null and endTime != '' ">
             AND stat_date &lt;= #{endTime}
         </if>
+        <if test="appVersion != null and appVersion != '' ">
+            and photo_id in (
+            select photo_id from ctop_kuaishou_video_get
+            where account_id = #{accountId}
+            and photo_name like concat(#{appVersion}'%')
+            )
+        </if>
         ORDER BY stat_date ASC
         LIMIT #{videoCnt}
     </select>
 
     <select id="getHistoryTopVideoList" resultType="com.alibaba.fastjson.JSONObject">
-        SELECT
-        t2.photo_id,
-        t2.signature,
-        t1.charge,
-        t2.channel_type,
-        t2.material_type as 'material_type',
-        t2.url as 'video_url'
+        t1.photo_id,
+        t1.signature,
+        t1.charge
         FROM
         (
         SELECT
         sum(charge) as 'charge',
+        photo_id as 'photo_id',
         signature
         FROM
         ctop_kuaishou_report_daily_material
@@ -98,7 +102,10 @@
         account_id = #{accountId}
         and stat_date &gt;= #{startDate}
         and stat_date &lt;= #{endDate}
-        and signature is  not  null
+        <if test="appVersion != null and appVersion != '' ">
+            and photo_name like concat(#{appVersion}'%')
+        </if>
+        and signature is not null
         )
         GROUP BY
         signature
@@ -106,9 +113,6 @@
         sum(charge) DESC
         LIMIT #{num}
         ) t1
-        LEFT   JOIN ctop_kuaishou_video_get t2 ON t1.signature = t2.signature
-        AND t2.account_id = #{accountId}
-        GROUP BY t2.signature
         ORDER BY t1.charge DESC
     </select>
 </mapper>

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

@@ -36,4 +36,6 @@ public interface IKuaiShouGroupService extends IService<KuaiShouGroup> {
     List<KuaiShouGroup> queryUnitInfoByCampaignId(Long accountId, Long campaignId);
 
     KuaiShouGroup selectGroupByUnitId(Long accountId, Long unitId);
+
+    void deleteByAccountId(Long accountId);
 }

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

@@ -31,6 +31,7 @@ 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);

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

@@ -128,6 +128,11 @@ public class KuaiShouGroupServiceImpl extends ServiceImpl<KuaiShouGroupMapper, K
         return group;
     }
 
+    @Override
+    public void deleteByAccountId(Long accountId) {
+        groupMapper.deleteByAccountId(accountId);
+    }
+
 
     @Override
     public void getGroupByUnitId(String accessToken, Long accountId, Long unitId) {