瀏覽代碼

预警规则-增加关停逻辑

zhaoxian 4 年之前
父節點
當前提交
7544574920

+ 6 - 0
module-alarm/pom.xml

@@ -29,6 +29,12 @@
             <artifactId>module-kuaishou</artifactId>
             <version>2.0.2</version>
         </dependency>
+        <dependency>
+            <groupId>cn.com.ctop</groupId>
+            <artifactId>module-toutiao</artifactId>
+            <version>2.0.2</version>
+            <scope>compile</scope>
+        </dependency>
 
     </dependencies>
 

+ 3 - 3
module-alarm/src/main/java/cn/com/ctop/alarm/modules/constant/MatchLogic.java

@@ -186,11 +186,11 @@ public class MatchLogic {
     public static String getMessage(String ruleGroupName, Long accountId, String accountName, String type, String codes, boolean isNull) {
         StringBuffer buf = new StringBuffer();
         buf.append(ruleGroupName).append("预警").append("<br/>").
-                append("所属账户:").append(accountId).append(",授权名称:").append(accountName).append("<br/>");
+                append("预警账户:").append(accountId).append(",授权名称:").append(accountName).append("<br/>");
         if ("plan".equals(type)) {
-            buf.append("预警计划:").append(codes).append("<br/>");
+            buf.append("预警计划:").append(codes).append("<br/>");
         } else if ("creative".equals(type)) {
-            buf.append("预警创意:").append(codes).append("<br/>");
+            buf.append("预警创意:").append(codes).append("<br/>");
         }
         if (isNull) {
             buf.append("该规则未匹配到投放数据").append("<br/>");

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

@@ -27,6 +27,8 @@ import cn.com.ctop.common.module.service.ISendMessageService;
 import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.SendMailUtil;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouUpdateService;
+import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertisePlanService;
+import cn.com.ctop.toutiao.modules.material.service.IByteDanceCreativeService;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -85,6 +87,13 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
     private AlarmEventSendMapper alarmEventSendMapper;
     @Autowired
     private UserAllocationMapper userAllocationMapper;
+    @Autowired
+    private IByteDanceAdvertisePlanService byteDanceAdvertisePlanService;
+    @Autowired
+    private IByteDanceCreativeService byteDanceCreativeService;
+    @Autowired
+    private ICtopOauthTokenService ctopOauthTokenService;
+
     private JSONObject userObj = null;
     private final static String ACCOUNT = "account";
     private final static String PLAN = "plan";
@@ -428,7 +437,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
                         isNullCreativeJoiner.add(obj.getString("creativeId"));
                     } else {
                         String message = MatchLogic.getMessage(ruleGroup.getGroupName(), accountId, accountName, CREATIVE, isNullCreativeJoiner.toString(), isNull);
-                        sendMsg(message, ruleGroup, user, CREATIVE);
+                        sendMsg(message, ruleGroup, user, CREATIVE, isNullCreativeJoiner.toString(), accountId);
                         isNullCreativeJoiner = new StringJoiner(",");
                         isNullCreativeJoiner.add(obj.getString("creativeId"));
                     }
@@ -437,13 +446,13 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
                         isNullPlanJoiner.add(obj.getString("planId"));
                     } else {
                         String msg = MatchLogic.getMessage(ruleGroup.getGroupName(), accountId, accountName, PLAN, isNullPlanJoiner.toString(), isNull);
-                        sendMsg(msg, ruleGroup, user, PLAN);
+                        sendMsg(msg, ruleGroup, user, PLAN, isNullPlanJoiner.toString(), accountId);
                         isNullPlanJoiner = new StringJoiner(",");
                         isNullPlanJoiner.add(obj.getString("planId"));
                     }
                 } else {
                     String msg = MatchLogic.getMessage(ruleGroup.getGroupName(), accountId, accountName, null, null, isNull);
-                    sendMsg(msg, ruleGroup, user, ACCOUNT);
+                    sendMsg(msg, ruleGroup, user, ACCOUNT, null, accountId);
                 }
             } else {
                 if (!Check.isNull(obj.getString("creativeId"))) {
@@ -452,7 +461,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
                         creativeJoiner.add(obj.getString("creativeId"));
                     } else {
                         String message = MatchLogic.getMessage(ruleGroup.getGroupName(), accountId, accountName, CREATIVE, creativeJoiner.toString(), isNull);
-                        sendMsg(message, ruleGroup, user, CREATIVE);
+                        sendMsg(message, ruleGroup, user, CREATIVE, creativeJoiner.toString(), accountId);
                         creativeJoiner = new StringJoiner(",");
                         creativeJoiner.add(obj.getString("creativeId"));
                     }
@@ -461,31 +470,31 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
                         planJoiner.add(obj.getString("planId"));
                     } else {
                         String msg = MatchLogic.getMessage(ruleGroup.getGroupName(), accountId, accountName, PLAN, planJoiner.toString(), isNull);
-                        sendMsg(msg, ruleGroup, user, PLAN);
+                        sendMsg(msg, ruleGroup, user, PLAN, planJoiner.toString(), accountId);
                         planJoiner = new StringJoiner(",");
                         planJoiner.add(obj.getString("planId"));
                     }
                 } else {
                     String msg = MatchLogic.getMessage(ruleGroup.getGroupName(), accountId, accountName, null, null, isNull);
-                    sendMsg(msg, ruleGroup, user, ACCOUNT);
+                    sendMsg(msg, ruleGroup, user, ACCOUNT, null, accountId);
                 }
             }
         }
         if (!Check.isNull(creativeJoiner.toString())) {
             String creativeMsg = MatchLogic.getMessage(ruleGroup.getGroupName(), accountId, accountName, CREATIVE, creativeJoiner.toString(), false);
-            sendMsg(creativeMsg, ruleGroup, user, CREATIVE);
+            sendMsg(creativeMsg, ruleGroup, user, CREATIVE, creativeJoiner.toString(), accountId);
         }
         if (!Check.isNull(planJoiner.toString())) {
             String planMsg = MatchLogic.getMessage(ruleGroup.getGroupName(), accountId, accountName, PLAN, planJoiner.toString(), false);
-            sendMsg(planMsg, ruleGroup, user, PLAN);
+            sendMsg(planMsg, ruleGroup, user, PLAN, planJoiner.toString(), accountId);
         }
         if (!Check.isNull(isNullCreativeJoiner.toString())) {
             String isNullCreativeMsg = MatchLogic.getMessage(ruleGroup.getGroupName(), accountId, accountName, CREATIVE, isNullCreativeJoiner.toString(), true);
-            sendMsg(isNullCreativeMsg, ruleGroup, user, CREATIVE);
+            sendMsg(isNullCreativeMsg, ruleGroup, user, CREATIVE, isNullCreativeJoiner.toString(), accountId);
         }
         if (!Check.isNull(isNullPlanJoiner.toString())) {
             String isNullPlanMsg = MatchLogic.getMessage(ruleGroup.getGroupName(), accountId, accountName, PLAN, isNullPlanJoiner.toString(), true);
-            sendMsg(isNullPlanMsg, ruleGroup, user, PLAN);
+            sendMsg(isNullPlanMsg, ruleGroup, user, PLAN, isNullPlanJoiner.toString(), accountId);
         }
     }
 
@@ -500,17 +509,20 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
      * @throws
      * @author ZHAOXA
      */
-    private void sendMsg(String msg, RuleGroup ruleGroup, JSONObject user, String type) {
+    private void sendMsg(String msg, RuleGroup ruleGroup, JSONObject user, String type, String ids, Long accountId) {
         try {
-            //TODO 关停操作
-            boolean isPause = false;
-          /*      "PAUSE".equals(ruleGroup.getOperate());
-        if (isPause) {
-            if (shutDown(accountId, planId, creativeId, user.getString("id"))) {
-                isPause = true;
+            boolean isPause = "PAUSE".equals(ruleGroup.getOperate());
+            if (isPause) {
+                //type 1:头条2:快手
+                if (NoEn.NO1.valueStr().equals(type)) {
+                    isPause = touTiaoshutDown(accountId, ids, type);
+                } else {
+                    msg = kuaiShoushutDown(accountId, ids, type, user.getString("id"), msg);
+                    if (msg.getBytes().length >= 2048) {
+                        msg = msg.replace(",", ",");
+                    }
+                }
             }
-            type 1:头条2:快手
-        }*/
             if (isPause) {
                 msg += "现已被关停,请您及时查看并调整!";
             } else {
@@ -578,21 +590,50 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
      * @throws
      * @author ZHAOXA
      */
-    private boolean shutDown(Long accountId, Long planId, Long creativeId, String userId) {
+    private String kuaiShoushutDown(Long accountId, String ids, String type, String userId, String msg) {
         CtopOauthToken token = oauthTokenService.getTokenByAccountId(accountId);
         Map<String, Object> updateMap = new HashMap<>();
-        if (!Check.isNull(token)) {
-            if (!Check.isNull(creativeId)) {
-                updateMap = kuaiShouUpdateService.updateCreativeStatus(token.getAccessToken(), accountId, creativeId, NoEn.NO2.valueInt(), userId);
-                log.info("---------规则关停创意:{}", creativeId);
-            } else if (!Check.isNull(planId) && Check.isNull(creativeId)) {
-                updateMap = kuaiShouUpdateService.updateCampaignStatus(token.getAccessToken(), accountId, planId, NoEn.NO2.valueInt(), userId);
-                log.info("---------规则关停计划:{}", planId);
+        if (!Check.isNull(token) && !Check.isNull(ids)) {
+            String[] idSplit = ids.split(",");
+            for (String id : idSplit) {
+                if (CREATIVE.equals(type)) {
+                    updateMap = kuaiShouUpdateService.updateCreativeStatus(token.getAccessToken(), accountId, Long.valueOf(id), NoEn.NO2.valueInt(), userId);
+                    if (!(boolean) updateMap.get("success")) {
+                        msg = msg.replace(id, id + "(F)");
+                    }
+                } else {
+                    updateMap = kuaiShouUpdateService.updateCampaignStatus(token.getAccessToken(), accountId, Long.valueOf(id), NoEn.NO2.valueInt(), userId);
+                    if (!(boolean) updateMap.get("success")) {
+                        msg = msg.replace(id, id + "(F)");
+                    }
+                }
+            }
+        }
+        return msg;
+    }
+
+
+    private boolean touTiaoshutDown(Long accountId, String ids, String type) {
+        Boolean flag = false;
+        if (!Check.isNull(ids)) {
+            Map<String, Object> result = new HashMap<>();
+            if (PLAN.equals(type)) {
+                JSONArray planId = new JSONArray();
+                String[] split = ids.split(",");
+                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");
             }
+            flag = !Check.isNull(result.get("code")) && (int) result.get("code") == 0;
         }
-        return (boolean) updateMap.get("success");
+        return flag;
     }
 
+
     //整理阈值数据
     public JSONObject getThreshold(Long accountId, boolean isCopy) {
         JSONObject obj = new JSONObject();