فهرست منبع

Merge remote-tracking branch 'origin/master'

syh 4 سال پیش
والد
کامیت
dc4a2cbfc5

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

@@ -35,6 +35,8 @@ public class KuaiShouCreateServiceImpl implements IKuaiShouCreateService {
     private IKuaiShouMaterialUploadService uploadService;
     @Autowired
     private IKuaiShouVideoGetService videoGetService;
+    @Autowired
+    private IKuaiShouGroupTemplateService groupTemplateService;
 
     @Value("${ai.callback.callback-unit-url}")
     private String unitUrl;
@@ -90,7 +92,10 @@ public class KuaiShouCreateServiceImpl implements IKuaiShouCreateService {
                 if (!Check.isNull(groupCreateJson.getLong("deep_conversion_bid"))) {
                     createJson.put("deep_conversion_bid", groupCreateJson.getLong("deep_conversion_bid")); //深度转化目标出价
                 }
+
+                Integer sceneId = null;
                 if (!Check.isNull(groupCreateJson.getJSONArray("scene_id"))) {
+                    sceneId = groupCreateJson.getJSONArray("scene_id").getInteger(0);
                     createJson.put("scene_id", groupCreateJson.getJSONArray("scene_id")); //资源位置
                 }
                 Integer unit_type = groupCreateJson.getInteger("unit_type");
@@ -174,9 +179,19 @@ public class KuaiShouCreateServiceImpl implements IKuaiShouCreateService {
                         createJson.put("asset_mining", groupCreateJson.getBoolean("asset_mining")); //程序化创意2.0素材挖掘
                     }
                 }
-
                 if (!Check.isNull(groupCreateJson.getLong("template_id"))) {
-                    createJson.put("template_id", groupCreateJson.getLong("template_id")); //定向模板id
+                    if (sceneId != 5) {
+                        createJson.put("template_id", groupCreateJson.getLong("template_id")); //定向模板id
+                    } else { // 联盟广告位 需要根据模板id 获取定向数据
+                        JSONObject unionJson = groupTemplateService.getUnionJson(groupCreateJson.getLong("template_id"));
+                        Integer code = unionJson.getInteger("code");
+                        if (code == 0) {
+                            JSONObject target = unionJson.getJSONObject("target");
+                            createJson.put("target", target);
+                        }else{
+                            throw new Exception("联盟广告位定向模板错误");
+                        }
+                    }
                 } else {
                     JSONObject target = getTarget(groupCreateJson);
                     if (!Check.isNull(target)) {

+ 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/KuaiShouAppListMapper.java

@@ -2,6 +2,9 @@ package cn.com.ctop.kuaishou.modules.batch.mapper;
 
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouAppList;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
 
 /**
  * @Description: 快手-应用列表
@@ -11,4 +14,5 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  */
 public interface KuaiShouAppListMapper extends BaseMapper<KuaiShouAppList> {
 
+    void replaceBatch(@Param("addList") List<KuaiShouAppList> addList);
 }

+ 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);
 }

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

@@ -1,5 +1,34 @@
 <?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.KuaiShouAppListMapper">
+    <insert id="replaceBatch">
+        replace into ctop_kuaishou_app_list(
+        account_id,
+        app_id,
+        url,
+        app_version,
+        app_name,
+        app_icon_url,
+        image_token,
+        package_name,
+        platform,
+        return_time
+        )
+        values
+        <foreach collection="addList" item="appInfo" separator=",">
+            (
+            #{appInfo.accountId},
+            #{appInfo.appId},
+            #{appInfo.url},
+            #{appInfo.appVersion},
+            #{appInfo.appName},
+            #{appInfo.appIconUrl},
+            #{appInfo.imageToken},
+            #{appInfo.packageName},
+            #{appInfo.platform},
+            #{appInfo.returnTime}
+            )
+        </foreach>
+    </insert>
 
 </mapper>

+ 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>

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

@@ -82,7 +82,7 @@
 
     <select id="getHistoryTopVideoList" resultType="com.alibaba.fastjson.JSONObject">
         select
-        t1.photo_id,
+        t2.photo_id,
         t1.signature,
         t1.charge
         FROM
@@ -115,6 +115,15 @@
         sum(charge) DESC
         LIMIT #{num}
         ) t1
+        LEFT JOIN (
+        SELECT
+        photo_id,
+        signature
+        FROM
+        ctop_kuaishou_video_get
+        WHERE
+        account_id = #{accountId}
+        ) t2 ON t1.signature = t2.signature
         ORDER BY t1.charge DESC
     </select>
 </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);
 }

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

@@ -183,7 +183,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
 
     private void getVideoListByPage(CtopOauthToken token, String startDate, String endDate, int page) {
         try {
-            log.info("获取视频数据,accountId:{}", token.getAccountId());
+          //  log.info("获取视频数据,accountId:{}", token.getAccountId());
             String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.VIDEO_LIST;
             Map<String, String> headers = new HashMap<>();
             headers.put("Content-Type", "application/json");
@@ -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);
 
@@ -3340,37 +3340,34 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
             if (!Check.isNull(resultJson)) {
                 Integer code = resultJson.getInteger("code");
                 if (code == 0) {
-                    if (page == 1) { //分页保存数据,如果页数为1,删除之前的数据重新入库
-                        Map<String, Object> deleteMap = new HashMap<>();
-                        deleteMap.put("account_id", advertiserId);
-                        appListMapper.deleteByMap(deleteMap);
-                    }
                     JSONObject data = resultJson.getJSONObject("data");
-                    if (!Check.isNull(data)) {
-                        Integer totalCount = data.getInteger("total_count");
-                        JSONArray dataArr = data.getJSONArray("details");
-                        for (int i = 0; i < dataArr.size(); i++) {
-                            JSONObject dataJson = JSONObject.parseObject(dataArr.get(i).toString());
-                            if (!Check.isNull(dataJson)) {
-                                KuaiShouAppList appList = new KuaiShouAppList();
-                                appList.setAccountId(advertiserId);
-                                appList.setPlatform(dataJson.getInteger("platform"));
-                                appList.setUrl(dataJson.getString("url"));
-                                appList.setAppId(dataJson.getLong("app_id"));
-                                appList.setAppVersion(dataJson.getString("app_version"));
-                                appList.setAppName(dataJson.getString("app_name"));
-                                appList.setAppIconUrl(dataJson.getString("app_icon_url"));
-                                appList.setImageToken(dataJson.getString("image_token"));
-                                appList.setPackageName(dataJson.getString("package_name"));
-                                appList.setReturnTime(DateUtils.timeStamp2Date(dataJson.getTimestamp("update_time")));
-                                appListMapper.insert(appList);
-                            }
-                        }
-                        Integer totalPage = (totalCount - 1) / pageSize + 1;
-                        if (page < totalPage) {
-                            getAppList2ByPage(advertiserId, accessToken, page + 1, pageSize);
+                    if (Check.isNull(data)) {
+                        return;
+                    }
+                    JSONArray dataArr = data.getJSONArray("details");
+                    if (Check.isNull(dataArr)) {
+                        return;
+                    }
+                    List<KuaiShouAppList> addList = new ArrayList<>();
+                    for (int i = 0; i < dataArr.size(); i++) {
+                        JSONObject dataJson = JSONObject.parseObject(dataArr.get(i).toString());
+                        if (!Check.isNull(dataJson)) {
+                            KuaiShouAppList appList = new KuaiShouAppList();
+                            appList.setAccountId(advertiserId);
+                            appList.setPlatform(dataJson.getInteger("platform"));
+                            appList.setUrl(dataJson.getString("url"));
+                            appList.setAppId(dataJson.getLong("app_id"));
+                            appList.setAppVersion(dataJson.getString("app_version"));
+                            appList.setAppName(dataJson.getString("app_name"));
+                            appList.setAppIconUrl(dataJson.getString("app_icon_url"));
+                            appList.setImageToken(dataJson.getString("image_token"));
+                            appList.setPackageName(dataJson.getString("package_name"));
+                            appList.setReturnTime(DateUtils.timeStamp2Date(dataJson.getTimestamp("update_time")));
+                            addList.add(appList);
                         }
                     }
+                    appListMapper.replaceBatch(addList);
+                    getAppList2ByPage(advertiserId, accessToken, page + 1, pageSize);
                 } else {
                     log.error("获取应用列表失败,返回信息:{}", resultJson);
                 }

+ 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);
+    }
 }