Selaa lähdekoodia

V1.1.4 自动投放 同步人群包接口

yumeng 4 vuotta sitten
vanhempi
commit
ee6a341214

+ 2 - 9
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/BatchController.java

@@ -139,7 +139,7 @@ public class BatchController {
             Thread thread1 = new Thread() {
                 @Override
                 public void run() {
-                    iKuaishouInterfaceService.getPopulationList(accountId, oauthToken.getAccessToken());
+                    iKuaishouInterfaceService.getPopulationList(accountId, oauthToken.getAccessToken(), 1);
                 }
             };
             thread1.start();
@@ -1964,14 +1964,7 @@ public class BatchController {
             if (Check.isNull(oauthToken)) {
                 throw new Exception("未获取到账户信息");
             }
-            Thread thread = new Thread() {
-                @Override
-                public void run() {
-                    iKuaishouInterfaceService.getPopulationList(accountId, oauthToken.getAccessToken());
-                }
-            };
-            thread.start();
-
+            iKuaishouInterfaceService.getPopulationList(accountId, oauthToken.getAccessToken(), 1);
             result.setSuccess(true);
         } catch (Exception e) {
             e.printStackTrace();

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

@@ -2,6 +2,9 @@ package cn.com.ctop.kuaishou.modules.batch.mapper;
 
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouPopulation;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
 
 /**
  * 人群包列表
@@ -12,4 +15,5 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  */
 public interface KuaishouPopulationMapper extends BaseMapper<KuaishouPopulation> {
 
+    void replaceBatch(@Param("addList") List<KuaishouPopulation> addList);
 }

+ 31 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaishouPopulationMapper.xml

@@ -1,5 +1,35 @@
 <?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.batch.mapper.KuaishouPopulationMapper">
-
+    <insert id="replaceBatch">
+        replace into ctop_kuaishou_population(
+        account_id,
+        orientation_id,
+        orientation_name,
+        type,
+        population_type,
+        record_size,
+        match_size,
+        cover_num,
+        status,
+        put_time,
+        third_platform_code
+        )
+        values
+        <foreach collection="addList" item="population" separator=",">
+            (
+            #{population.accountId},
+            #{population.orientationId},
+            #{population.orientationName},
+            #{population.type},
+            #{population.populationType},
+            #{population.recordSize},
+            #{population.matchSize},
+            #{population.coverNum},
+            #{population.status},
+            #{population.putTime},
+            #{population.thirdPlatformCode}
+            )
+        </foreach>
+    </insert>
 </mapper>

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

@@ -422,7 +422,7 @@ public interface IKuaishouInterfaceService {
      * @param accessToken
      * @return
      */
-    void getPopulationList(Long accountId, String accessToken);
+    void getPopulationList(Long accountId, String accessToken, Integer page);
 
 
     /**
@@ -445,8 +445,7 @@ public interface IKuaishouInterfaceService {
     JSONArray getAppSearch(Long accountId, String accessToken, String appName);
 
 
-
-   // void getSuZaoList(String token, Long accountId, int page, String startDate, String endDate);
+    // void getSuZaoList(String token, Long accountId, int page, String startDate, String endDate);
 
     /**
      * 异步获取创意信息

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

@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
 
 import java.io.File;
+import java.util.List;
 
 /**
  * 人群包列表
@@ -101,4 +102,5 @@ public interface IKuaishouPopulationService extends IService<KuaishouPopulation>
      */
     Long predictionPopulation(Long accountId, JSONObject obj, String accessToken);
 
+    void replaceBatch(List<KuaishouPopulation> addList);
 }

+ 29 - 29
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouInterfaceServiceImpl.java

@@ -2771,7 +2771,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
 
 
     @Override
-    public void getPopulationList(Long accountId, String accessToken) {
+    public void getPopulationList(Long accountId, String accessToken, Integer page) {
         try {
             log.info("获取人群包列表,accountId:{}", accountId);
             String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.POPULATION_LIST;
@@ -2781,7 +2781,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
             JSONObject requestJson = new JSONObject();
             requestJson.put("advertiser_id", accountId);
             requestJson.put("status", 4);
-            requestJson.put("page", 1);
+            requestJson.put("page", page);
             requestJson.put("page_size", 500);
             String result = HttpUtils.kuaiShouhttpPostRequest(url, requestJson.toJSONString(), headers);
             JSONObject resultJson = JSONObject.parseObject(result);
@@ -2789,37 +2789,37 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                 Integer code = resultJson.getInteger("code");
                 if (code == 0) {
                     JSONObject dataDetailJson = resultJson.getJSONObject("data");
-                    if (!Check.isNull(dataDetailJson)) {
-                        Map<String, Object> deleteMap = new HashMap<>();
+                    if (Check.isNull(dataDetailJson)) {
+                        return;
+                    }
+                    JSONArray details = dataDetailJson.getJSONArray("details");
+                    if (Check.isNull(details)) {
+                        return;
+                    }
 
-                        JSONArray details = dataDetailJson.getJSONArray("details");
-                        if (Check.isNull(details)) {
-                            return;
-                        }
-                        deleteMap.put("account_id", accountId);
-                        populationService.removeByMap(deleteMap);
-                        for (int i = 0; i < details.size(); i++) {
-                            JSONObject dataJson = details.getJSONObject(i);
-                            if (!Check.isNull(dataJson)) {
-                                KuaishouPopulation population = new KuaishouPopulation();
-                                population.setOrientationId(dataJson.getLong("orientation_id"));
-                                population.setOrientationName(dataJson.getString("orientation_name"));
-                                population.setType(dataJson.getInteger("type"));
-                                population.setPopulationType(dataJson.getInteger("population_type"));
-                                population.setRecordSize(dataJson.getLong("record_size"));
-                                population.setMatchSize(dataJson.getLong("match_size"));
-                                population.setCoverNum(dataJson.getLong("cover_num"));
-                                population.setStatus(dataJson.getInteger("status"));
-                                population.setPutTime(dataJson.getDate("create_time"));
-                                population.setThirdPlatformCode(dataJson.getLong("third_platform_code"));
-                                population.setAccountId(accountId);
-                                populationService.save(population);
+                    List<KuaishouPopulation> addList = new ArrayList<>();
+                    for (int i = 0; i < details.size(); i++) {
+                        JSONObject dataJson = details.getJSONObject(i);
+                        if (!Check.isNull(dataJson)) {
+                            KuaishouPopulation population = new KuaishouPopulation();
+                            population.setOrientationId(dataJson.getLong("orientation_id"));
+                            population.setOrientationName(dataJson.getString("orientation_name"));
+                            population.setType(dataJson.getInteger("type"));
+                            population.setPopulationType(dataJson.getInteger("population_type"));
+                            population.setRecordSize(dataJson.getLong("record_size"));
+                            population.setMatchSize(dataJson.getLong("match_size"));
+                            population.setCoverNum(dataJson.getLong("cover_num"));
+                            population.setStatus(dataJson.getInteger("status"));
+                            population.setPutTime(dataJson.getDate("create_time"));
+                            population.setThirdPlatformCode(dataJson.getLong("third_platform_code"));
+                            population.setAccountId(accountId);
+                            addList.add(population);
+                            // populationService.save(population);
 
-                            }
                         }
-
                     }
-
+                    populationService.replaceBatch(addList);
+                    getPopulationList(accountId, accessToken, page + 1);
                 } else {
                     log.error("获取人群包管理返回数据为空,accountId:{}", accountId);
 

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

@@ -10,10 +10,12 @@ import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouPopulationService;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.io.File;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -27,7 +29,8 @@ import java.util.Map;
 @Service
 public class KuaishouPopulationServiceImpl extends ServiceImpl<KuaishouPopulationMapper, KuaishouPopulation> implements IKuaishouPopulationService {
 
-
+    @Autowired
+    private KuaishouPopulationMapper populationMapper;
     private String urlPath = PropertiesUtils.getConfig("kuaishou_api_url");
 
     /**
@@ -327,4 +330,9 @@ public class KuaishouPopulationServiceImpl extends ServiceImpl<KuaishouPopulatio
         }
         return null;
     }
+
+    @Override
+    public void replaceBatch(List<KuaishouPopulation> addList) {
+        populationMapper.replaceBatch(addList);
+    }
 }