Pārlūkot izejas kodu

V1.1.4 自动投放联盟广告位 应用修改

yumeng 4 gadi atpakaļ
vecāks
revīzija
11f438620e

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

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

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

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

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