Selaa lähdekoodia

预警规则-增加关停逻辑

zhaoxian 4 vuotta sitten
vanhempi
commit
f97990a2de

+ 51 - 11
module-alarm/src/main/java/cn/com/ctop/alarm/modules/service/impl/RuleGroupServiceImpl.java

@@ -612,23 +612,63 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
         return msg;
     }
 
-
+    /**
+     * 头条关停
+     *
+     * @param
+     * @return boolean
+     * @throws
+     * @author ZHAOXA
+     */
     private boolean touTiaoshutDown(Long accountId, String ids, String type) {
         Boolean flag = false;
-        if (!Check.isNull(ids)) {
+        try {
             Map<String, Object> result = new HashMap<>();
-            if (PLAN.equals(type)) {
-                JSONArray planId = new JSONArray();
+            if (!Check.isNull(ids)) {
                 String[] split = ids.split(",");
-                for (String id : split) {
-                    planId.add(id);
+                JSONArray planId = new JSONArray();
+                //最大更新100条数据,做拆分
+                if (split.length > 100) {
+                    JSONArray planId2 = new JSONArray();
+                    StringJoiner str = new StringJoiner(",");
+                    StringJoiner str2 = new StringJoiner(",");
+                    for (int i = 0; i < split.length; i++) {
+                        if (i > 99) {
+                            str2.add(split[i]);
+                            planId2.add(split[i]);
+                        } else {
+                            str.add(split[i]);
+                            planId.add(split[i]);
+                        }
+                    }
+                    if (PLAN.equals(type)) {
+                        CtopOauthToken token = ctopOauthTokenService.getTokenByAccountId(accountId);
+                        result = byteDanceAdvertisePlanService.updateAdvertiserPlanStatus(token, planId, "AD_STATUS_DISABLE");
+                        if (planId2.size() > 0) {
+                            result = byteDanceAdvertisePlanService.updateAdvertiserPlanStatus(token, planId2, "AD_STATUS_DISABLE");
+                        }
+                    } else {
+                        result = byteDanceCreativeService.advertiserCreativeUpdateStatus(accountId, str.toString(), "disable");
+                        if (str2.length() > 0) {
+                            result = byteDanceCreativeService.advertiserCreativeUpdateStatus(accountId, str2.toString(), "disable");
+                        }
+                    }
+                    //低于100条数据,直接执行
+                } else {
+                    if (PLAN.equals(type)) {
+                        for (String id : split) {
+                            planId.add(id);
+                        }
+                        CtopOauthToken token = ctopOauthTokenService.getTokenByAccountId(accountId);
+                        result = byteDanceAdvertisePlanService.updateAdvertiserPlanStatus(token, planId, "AD_STATUS_DISABLE");
+                    } else {
+                        result = byteDanceCreativeService.advertiserCreativeUpdateStatus(accountId, ids.replace(",", ","), "disable");
+                    }
                 }
-                CtopOauthToken token = ctopOauthTokenService.getTokenByAccountId(accountId);
-                result = byteDanceAdvertisePlanService.updateAdvertiserPlanStatus(token, planId, "AD_STATUS_DISABLE");
-            } else {
-                result = byteDanceCreativeService.advertiserCreativeUpdateStatus(accountId, ids.replace(",", ","), "disable");
+                flag = !Check.isNull(result.get("code")) && (int) result.get("code") == 0;
             }
-            flag = !Check.isNull(result.get("code")) && (int) result.get("code") == 0;
+        } catch (Exception e) {
+            log.error("头条账户:{},关停{}失败", accountId, type, e);
         }
         return flag;
     }