소스 검색

批量修改

yumeng 5 년 전
부모
커밋
1fa512f920

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

@@ -1805,63 +1805,67 @@ public class BatchController {
      * @param requestJson
      * @return
      */
-/*    @PostMapping(value = "/copyUnitUpdate")
+    @PostMapping(value = "/copyUnitUpdate")
     public Result<JSONObject> copyUnitUpdate(@RequestBody JSONObject requestJson) {
         Result<JSONObject> result = new Result<>();
         try {
+            Integer totalCount = null;
             Long accountId = requestJson.getLong("accountId");
             CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
             if (Check.isNull(oauthToken)) {
                 throw new Exception("未获取到账户信息");
             }
             JSONObject returnJson = new JSONObject();
-
-            Long unitId = requestJson.getLong("unitId");
-            kuaiShouGroupService.getGroupByUnitId(oauthToken.getAccessToken(), oauthToken.getAccountId(), unitId);
-            Long copyToCampaignId = requestJson.getLong("copyToCampaignId");
+            JSONObject groupJson = requestJson.getJSONObject("groupArr");
+            requestJson.remove("groupArr");
+            requestJson.remove("groupArr");
             JSONArray failArr = new JSONArray();
-            //  Integer createCount = requestJson.getInteger("createCount");
-
-
             Integer createType = requestJson.getInteger("createType");
             if (createType == 1) { //系统生成
                 // 需要获取创建条数
+                String unitName = groupJson.getString("unitName");
                 Integer createCount = requestJson.getInteger("createCount");
-                String unitName = requestJson.getString("unitName");
+                totalCount = createCount;
                 if (unitName.contains("#")) {
                     int lastIndexOf = unitName.lastIndexOf("#");
                     unitName = unitName.substring(0, lastIndexOf);
                 }
-                requestJson.remove("unitName");
                 for (int i = 0; i < createCount; i++) {
-                    String randomName = unitName + RandomUtil.verifyCodeV2() + i;
-                    requestJson.put("unitName", randomName);
-                    JSONObject createJson = batchService.createUnit(requestJson, oauthToken);
+                    String randomName = unitName + RandomUtil.verifyCode() + "_" + i;
+                    groupJson.put("unitName", randomName);
+                    requestJson.put("groupArr", groupJson);
+                    JSONObject createJson = batchService.copyUpdateUnit(requestJson, oauthToken);
                     if (createJson.getInteger("code") != 0) {
                         JSONObject errJson = new JSONObject();
                         errJson.put("message", createJson.getString("message"));
-                        returnJson.put("unitName", randomName);
+                        errJson.put("unitName", randomName);
                         failArr.add(errJson);
                     }
                 }
 
             } else if (createType == 2) { // 自定义
-                JSONArray unitNames = requestJson.getJSONArray("unitNames");
+                JSONArray unitNames = groupJson.getJSONArray("unitName");
+                groupJson.remove("unitName");
+                totalCount = unitNames.size();
                 for (int i = 0; i < unitNames.size(); i++) {
-                    String unitName = unitNames.getString(i);
-                    requestJson.put("unitName", unitName);
-                    JSONObject createJson = batchService.createUnit(requestJson, oauthToken);
+                    JSONObject nameJson = unitNames.getJSONObject(i);
+                    if (Check.isNull(nameJson)) {
+                        continue;
+                    }
+                    groupJson.put("unitName", nameJson.getString("unitName"));
+                    requestJson.put("groupArr", groupJson);
+                    JSONObject createJson = batchService.copyUpdateUnit(requestJson, oauthToken);
                     if (createJson.getInteger("code") != 0) {
                         JSONObject errJson = new JSONObject();
                         errJson.put("message", createJson.getString("message"));
-                        returnJson.put("unitName", unitName);
+                        errJson.put("unitName", nameJson.getString("unitName"));
                         failArr.add(errJson);
                     }
 
                 }
             }
 
-
+            returnJson.put("totalCount", totalCount);
             returnJson.put("failCount", failArr.size());
             returnJson.put("failInfo", failArr);
             result.setResult(returnJson);
@@ -1873,7 +1877,7 @@ public class BatchController {
             result.setMessage(e.getMessage());
         }
         return result;
-    }*/
+    }
 
 
     /**

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

@@ -60,6 +60,15 @@ public interface IBatchService {
      */
     JSONObject createUnit(JSONObject requestJson,CtopOauthToken oauthToken) throws Exception;
 
+
+    /**
+     * 批量复制修改广告组
+     *
+     * @param requestJson
+     * @return
+     */
+    JSONObject copyUpdateUnit(JSONObject requestJson, CtopOauthToken oauthToken);
+
     /**
      * 批量复制广告组
      *

+ 290 - 8
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/BatchServiceImpl.java

@@ -170,16 +170,12 @@ public class BatchServiceImpl implements IBatchService {
      */
     @Override
     public JSONObject createUnit(JSONObject requestJson, CtopOauthToken oauthToken) throws Exception {
-
-
         JSONObject unitJson = new JSONObject();
-
         Long campaignId = requestJson.getLong("campaignId");
         if (Check.isNull(campaignId)) {
             throw new Exception("请选择广告计划");
         }
 
-
         String type = requestJson.getString("type");
         if ("copy".equals(type) && !Check.isNull(type)) {
             unitJson.put("campaign_id", requestJson.getLong("copyToCampaignId"));
@@ -404,7 +400,7 @@ public class BatchServiceImpl implements IBatchService {
                     unitJson.put("unit_name", unitName);
                 }
 
-                Map<String, Object> returnUnitMap = kuaishouInterfaceService.adUnitCreate(oauthToken.getAccessToken(), oauthToken.getAccountId(), unitJson,1);
+                Map<String, Object> returnUnitMap = kuaishouInterfaceService.adUnitCreate(oauthToken.getAccessToken(), oauthToken.getAccountId(), unitJson, 1);
                 if (!Check.isNullMap(returnUnitMap)) {
                     Integer code = (Integer) returnUnitMap.get("code");
                     if (code == 0) {
@@ -453,6 +449,292 @@ public class BatchServiceImpl implements IBatchService {
 
 
     /**
+     * 批量创建广告组
+     *
+     * @param requestJson
+     * @return
+     */
+    @Override
+    public JSONObject copyUpdateUnit(JSONObject requestJson, CtopOauthToken oauthToken) {
+
+        JSONObject returnJson = new JSONObject();
+
+        try {
+
+
+            JSONObject unitJson = new JSONObject();
+            Long campaignId = requestJson.getLong("campaignId");
+            if (Check.isNull(campaignId)) {
+                throw new Exception("请选择广告计划");
+            }
+
+            String type = requestJson.getString("type");
+            if ("copy".equals(type) && !Check.isNull(type)) {
+                unitJson.put("campaign_id", requestJson.getLong("copyToCampaignId"));
+            } else {
+                unitJson.put("campaign_id", campaignId);
+            }
+
+
+            // 资源位置
+            JSONArray scene_id = requestJson.getJSONArray("sceneId");
+            if (!Check.isNull(scene_id)) {
+                unitJson.put("scene_id", scene_id);
+            }
+
+            // 资源创作方式
+            if (!Check.isNull(requestJson.getInteger("unitType"))) {
+                unitJson.put("unit_type", requestJson.getInteger("unitType"));
+            }
+
+            // 转化目标id
+            if (!Check.isNull(requestJson.getInteger("convertId"))) {
+                unitJson.put("convert_id", requestJson.getInteger("convertId"));
+            }
+
+            // 优先从系统应用商店下载
+            if (!Check.isNull(requestJson.getInteger("useAppMarket"))) {
+                unitJson.put("use_app_market", requestJson.getInteger("useAppMarket"));
+            }
+
+            //投放开始时间
+            if (!Check.isNull(requestJson.getString("beginTime"))) {
+                String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
+                boolean beginTimeBoolean = DateUtils.compare(requestJson.getString("beginTime"), nowDate);
+                if (beginTimeBoolean) {
+                    unitJson.put("begin_time", nowDate);
+                } else {
+                    unitJson.put("begin_time", requestJson.getString("beginTime"));
+                }
+            }
+            // 投放结束时间
+            if (!Check.isNull(requestJson.getString("endTime"))) {
+                unitJson.put("end_time", requestJson.getString("endTime"));
+            }
+            // 投放时间段
+            if (!Check.isNull(requestJson.getString("scheduleTime"))) {
+                unitJson.put("schedule_time", requestJson.getString("scheduleTime"));
+            }
+            // 广告组单日预算
+            if (!Check.isNull(requestJson.getLong("dayBudget"))) {
+                unitJson.put("day_budget", requestJson.getLong("dayBudget"));
+            }
+            // url类型
+            if (!Check.isNull(requestJson.getInteger("urlType"))) {
+                unitJson.put("url_type", requestJson.getInteger("urlType"));
+            }
+            // url
+            if (!Check.isNull(requestJson.getString("url"))) {
+                unitJson.put("url", requestJson.getString("url"));
+            }
+            // appId
+            if (!Check.isNull(requestJson.getLong("appId"))) {
+                unitJson.put("app_id", requestJson.getLong("appId"));
+            }
+            // 创意展现方式
+            if (!Check.isNull(requestJson.getInteger("showMode"))) {
+                unitJson.put("show_mode", requestJson.getInteger("showMode"));
+            }
+            if (!Check.isNull(requestJson.getInteger("speed"))) {
+                unitJson.put("speed", requestJson.getInteger("speed"));
+            }
+
+
+            // -----------------用户定向-----------
+            JSONObject targetJson = new JSONObject();
+
+            // 地域
+            if (!Check.isNull(requestJson.getJSONArray("region"))) {
+                targetJson.put("region", requestJson.getJSONArray("region"));
+            }
+
+            // 自定义年龄段
+            JSONArray ageArr = requestJson.getJSONArray("age");
+            if (!Check.isNull(ageArr)) {
+                JSONObject ageJson = new JSONObject();
+                ageJson.put("min", ageArr.get(0));
+                ageJson.put("max", ageArr.get(1));
+                targetJson.put("age", ageJson);
+            }
+            // 固定年龄段
+            if (!Check.isNull(requestJson.getJSONArray("agesRange"))) {
+                targetJson.put("ages_range", requestJson.getJSONArray("agesRange"));
+            }
+            // 性别
+            if (!Check.isNull(requestJson.getInteger("gender"))) {
+                targetJson.put("gender", requestJson.getInteger("gender"));
+            }
+            //操作系统
+            if (!Check.isNull(requestJson.getInteger("platformOs"))) {
+                targetJson.put("platform_os", requestJson.getInteger("platformOs"));
+            }
+            //Android版本
+            if (!Check.isNull(requestJson.getInteger("androidOsv"))) {
+                targetJson.put("android_osv", requestJson.getInteger("androidOsv"));
+            }
+            // iOS版本
+            if (!Check.isNull(requestJson.getInteger("iosOsv"))) {
+                targetJson.put("ios_osv", requestJson.getInteger("iosOsv"));
+            }
+            //网络环境
+            if (!Check.isNull(requestJson.getInteger("network"))) {
+                targetJson.put("network", requestJson.getInteger("network"));
+            }
+            //设备品牌
+            if (!Check.isNull(requestJson.getJSONArray("deviceBrand"))) {
+                targetJson.put("device_brand", requestJson.getJSONArray("deviceBrand"));
+            }
+            //设备价格
+            if (!Check.isNull(requestJson.getJSONArray("devicePrice"))) {
+                targetJson.put("device_price", requestJson.getJSONArray("devicePrice"));
+            }
+            //商业兴趣类型
+            if (!Check.isNull(requestJson.getInteger("businessInterestType"))) {
+                targetJson.put("business_interest_type", requestJson.getInteger("businessInterestType"));
+            }
+            // 商业兴趣
+            if (!Check.isNull(requestJson.getJSONArray("businessInterest"))) {
+                targetJson.put("business_interest", requestJson.getJSONArray("businessInterest"));
+            }
+            //网红粉丝
+            if (!Check.isNull(requestJson.getJSONArray("fansStar"))) {
+                targetJson.put("fans_star", requestJson.getJSONArray("fansStar"));
+            }
+            //兴趣视频用户
+            if (!Check.isNull(requestJson.getJSONArray("interestVideo"))) {
+                targetJson.put("interest_video", requestJson.getJSONArray("interestVideo"));
+            }
+            // APP行为-按分类
+            if (!Check.isNull(requestJson.getJSONArray("appInterest"))) {
+                targetJson.put("app_interest", requestJson.getJSONArray("appInterest"));
+            }
+            // APP行为-按APP名称
+            if (!Check.isNull(requestJson.getJSONArray("appIds"))) {
+                targetJson.put("app_ids", requestJson.getJSONArray("appIds"));
+            }
+            // 人群包定向
+            if (!Check.isNull(requestJson.getJSONArray("population"))) {
+                targetJson.put("population", requestJson.getJSONArray("population"));
+            }
+            // 人群包排除
+            if (!Check.isNull(requestJson.getJSONArray("excludePopulation"))) {
+                targetJson.put("exclude_population", requestJson.getJSONArray("excludePopulation"));
+            }
+
+            JSONObject intelliExtendJson = new JSONObject();
+
+            // 开启智能扩量
+            if (!Check.isNull(requestJson.getInteger("isOpen"))) {
+                intelliExtendJson.put("is_open", requestJson.getInteger("isOpen"));
+            }
+            //不可突破年龄
+            if (!Check.isNull(requestJson.getInteger("noAgeBreak"))) {
+                intelliExtendJson.put("no_age_break", requestJson.getInteger("noAgeBreak"));
+            }
+            //不可突破性别
+            if (!Check.isNull(requestJson.getInteger("noGenderBreak"))) {
+                intelliExtendJson.put("no_gender_break", requestJson.getInteger("noGenderBreak"));
+            }
+            // 不可突破地域
+            if (!Check.isNull(requestJson.getInteger("noAreaBreak"))) {
+                intelliExtendJson.put("no_area_break", requestJson.getInteger("noAreaBreak"));
+            }
+            if (!Check.isNull(intelliExtendJson)) {
+                targetJson.put("intelli_extend", intelliExtendJson);
+            }
+
+            unitJson.put("target", targetJson);
+            JSONObject groupJson = requestJson.getJSONObject("groupArr");
+            if (Check.isNull(groupJson)) {
+                throw new Exception("请输入需要创建的广告组");
+            }
+
+
+            // 创建条数
+
+            JSONArray successArr = new JSONArray();
+            JSONArray failArr = new JSONArray();
+
+            if (!Check.isNull(groupJson)) {
+
+                // 出价
+                if (!Check.isNull(groupJson.getLong("bid"))) {
+                    unitJson.put("bid", groupJson.getLong("bid"));
+                }
+                // 出价类型
+                Integer bidType = groupJson.getInteger("bidType");
+                if (!Check.isNull(bidType)) {
+                    unitJson.put("bid_type", bidType);
+                }
+                // 深度转化出价
+                if (!Check.isNull(groupJson.getLong("cpaBid"))) {
+                    unitJson.put("cpa_bid", groupJson.getLong("cpaBid"));
+                }
+                // 深度转化目标出价
+                if (!Check.isNull(groupJson.getLong("deepConversionBid"))) {
+                    unitJson.put("deep_conversion_bid", groupJson.getLong("deepConversionBid"));
+                }
+                // 深度转化目标
+                if (!Check.isNull(groupJson.getInteger("deepConversionType"))) {
+                    unitJson.put("deep_conversion_type", groupJson.getInteger("deepConversionType"));
+                }
+                // 优化目标
+                Integer ocpx_action_type = groupJson.getInteger("ocpxActionType");
+                if (!Check.isNull(ocpx_action_type)) {
+                    unitJson.put("ocpx_action_type", ocpx_action_type);
+                }
+                String unitName = groupJson.getString("unitName");
+                if (!Check.isNull(unitName)) {
+                    unitJson.put("unit_name", unitName);
+                }
+
+                Map<String, Object> returnUnitMap = kuaishouInterfaceService.adUnitCreate(oauthToken.getAccessToken(), oauthToken.getAccountId(), unitJson, 1);
+
+                if (!Check.isNullMap(returnUnitMap)) {
+                    Integer code = (Integer) returnUnitMap.get("code");
+                    if (code == 0) {
+
+                        Long unitId = (Long) returnUnitMap.get("unitId");
+                        returnJson.put("code", 0);
+                        returnJson.put("unitId", unitId);
+
+                        if (!Check.isNull(type) && "copy".equals(type)) {
+                            Long copyUnitId = requestJson.getLong("copyUnitId");
+                            if (!Check.isNull(unitId) && !Check.isNull(copyUnitId)) {
+                                Thread thread = new Thread() {
+                                    @Override
+                                    public void run() {
+                                        try {
+                                            copyCreative(oauthToken.getAccountId(), unitId, copyUnitId);
+                                        } catch (Exception e) {
+                                            e.printStackTrace();
+                                        }
+                                    }
+                                };
+                                thread.start();
+                            }
+                        }
+                    } else {
+                        returnJson.put("code", -1);
+                        returnJson.put("unitName", unitName);
+                        returnJson.put("message", returnUnitMap.get("message"));
+                    }
+
+                }
+
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            returnJson.put("code", -1);
+            returnJson.put("message", "系统异常");
+        }
+
+
+        return returnJson;
+    }
+
+
+    /**
      * 复制组
      *
      * @param
@@ -683,7 +965,7 @@ public class BatchServiceImpl implements IBatchService {
                     unitJson.put("unit_name", unitName);
                 }
 
-                Map<String, Object> returnUnitMap = kuaishouInterfaceService.adUnitCreate(oauthToken.getAccessToken(), group.getAccountId(), unitJson,1);
+                Map<String, Object> returnUnitMap = kuaishouInterfaceService.adUnitCreate(oauthToken.getAccessToken(), group.getAccountId(), unitJson, 1);
                 if (!Check.isNullMap(returnUnitMap)) {
                     Integer code = (Integer) returnUnitMap.get("code");
                     if (code == 0) {
@@ -786,7 +1068,7 @@ public class BatchServiceImpl implements IBatchService {
                 }*/
 
 
-                Map<String, Object> returnCreativeMap = kuaishouInterfaceService.creativeCreate(oauthToken.getAccessToken(), accountId, creativeJson,1);
+                Map<String, Object> returnCreativeMap = kuaishouInterfaceService.creativeCreate(oauthToken.getAccessToken(), accountId, creativeJson, 1);
                 if (!Check.isNullMap(returnCreativeMap)) {
                     Integer code = (Integer) returnCreativeMap.get("code");
                     if (code == 0) {
@@ -908,7 +1190,7 @@ public class BatchServiceImpl implements IBatchService {
                                     }
                                 }
                                 creativeJson.put("image_token", imageToken);
-                                Map<String, Object> returnUnitMap = kuaishouInterfaceService.creativeCreate(oauthToken.getAccessToken(), accountId, creativeJson,1);
+                                Map<String, Object> returnUnitMap = kuaishouInterfaceService.creativeCreate(oauthToken.getAccessToken(), accountId, creativeJson, 1);
                                 if (!Check.isNullMap(returnUnitMap)) {
                                     Integer code = (Integer) returnUnitMap.get("code");
                                     if (code == 0) {

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

@@ -1041,7 +1041,6 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                 } else {
 
                     if (code == 500000 && count <= 4) {
-
                         adUnitCreate(accessToken, advertiserId, requestJson, count + 1);
                     }
                     log.error("创建广告信息失败,advertiser_id:{},返回信息:{},入参:{}", advertiserId, resultJson, requestJson);
@@ -2907,10 +2906,11 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                     continue;
                 }
                 var kuaiShouVideoGet = JSONObject.toJavaObject(detailJson, KuaiShouVideoGet.class);
-                Date videoTime = videoTimeService.getVideoTime(kuaiShouVideoGet.getPhotoId(), accountId);
+               /* Date videoTime = videoTimeService.getVideoTime(kuaiShouVideoGet.getPhotoId(), accountId);
                 if (!Check.isNull(videoTime)) {
                     kuaiShouVideoGet.setUploadDate(videoTime);
-                }
+                }*/
+                kuaiShouVideoGet.setStatDate(new Date());
                 kuaiShouVideoGet.setAccountId(accountId);
                 kuaiShouVideoGet.setId(accountId + kuaiShouVideoGet.getPhotoId());
                 kuaiShouVideoGet.setCreateTime(new Date());