Quellcode durchsuchen

预警规则匹配逻辑——添加可复制规则逻辑

zhaoxian vor 4 Jahren
Ursprung
Commit
a7c0adfda8

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

@@ -98,10 +98,10 @@ public class MatchLogic {
     /**
      * 整理发送的消息
      */
-    public static String getMsg(RuleGroup ruleGroup, JSONObject user, Long accountId, Long planId, Long creativeId, boolean isPause) {
+    public static String getMsg(RuleGroup ruleGroup, JSONObject user, Long accountId, Long planId, Long creativeId, boolean isPause, String accountName) {
         StringBuffer header = new StringBuffer();
         header.append(ruleGroup.getGroupName()).append("预警").append("<br/>").
-                append("预警账户:").append(accountId).append("<br/>");
+                append("预警账户:").append(accountId).append(",授权名称为:").append(accountName).append("<br/>");
         if (!Check.isNull(planId) && !Check.isNull(creativeId)) {
             header.append("预警计划:").append(planId).append("<br/>").append("预警创意:").append(creativeId).append("<br/>");
         } else if (!Check.isNull(planId) && Check.isNull(creativeId)) {

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

@@ -18,7 +18,9 @@ import cn.com.ctop.alarm.modules.mapper.RuleTemplateMapper;
 import cn.com.ctop.alarm.modules.service.IRuleAccountTemplateService;
 import cn.com.ctop.alarm.modules.service.IRuleGroupService;
 import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.entity.UserAllocation;
 import cn.com.ctop.common.module.mapper.SysUserMapper;
+import cn.com.ctop.common.module.mapper.UserAllocationMapper;
 import cn.com.ctop.common.module.service.ICtopOauthTokenService;
 import cn.com.ctop.common.module.service.IRuleDataAccountService;
 import cn.com.ctop.common.module.service.ISendMessageService;
@@ -77,6 +79,9 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
     private IRuleDataAccountService ruleDataAccountService;
     @Autowired
     private AlarmEventSendMapper alarmEventSendMapper;
+    @Autowired
+    private UserAllocationMapper userAllocationMapper;
+    ;
     private JSONObject userObj = null;
 
     @Override
@@ -137,12 +142,17 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
             isCopythreshold = getThreshold(templates.getAccountId(), isCopy);
         }
         log.info("已获取账户({})的数据,开始匹配规则", templates.getAccountId());
+        UserAllocation userAllocations = userAllocationMapper.getUserAllocation(templates.getAccountId());
+        String accountName = "";
+        if (!Check.isNull(userAllocations)) {
+            accountName = userAllocations.getAuthName();
+        }
         try {
             if (!Check.isNull(notCopyGroups)) {
-                checkRuleGroups(notCopyGroups, notCopythreshold, indicators, matchData, type, false);
+                checkRuleGroups(notCopyGroups, notCopythreshold, indicators, matchData, type, false, accountName);
             }
             if (isCopy && !Check.isNull(isCopythreshold)) {
-                checkRuleGroups(isCopyGroups, isCopythreshold, indicators, matchData, type, isCopy);
+                checkRuleGroups(isCopyGroups, isCopythreshold, indicators, matchData, type, isCopy, accountName);
             }
 
         } catch (Exception e) {
@@ -163,7 +173,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
      * @throws
      * @author ZHAOXA
      */
-    private void checkRuleGroups(List<RuleGroup> ruleGroups, JSONObject thresholdObj, JSONObject indicators, JSONObject matchData, Integer type, boolean isCopy) {
+    private void checkRuleGroups(List<RuleGroup> ruleGroups, JSONObject thresholdObj, JSONObject indicators, JSONObject matchData, Integer type, boolean isCopy,String accountName) {
         for (RuleGroup ruleGroup : ruleGroups) {
             List<RuleBase> ruleBaseList = ruleGroup.getRuleBaseList();
             if (Check.isNull(ruleBaseList)) {
@@ -174,13 +184,13 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
                 JSONObject batchNo = thresholdObj.getJSONObject(ruleGroup.getId().toString());
                 for (Map.Entry<String, Object> entry : batchNo.entrySet()) {
                     JSONObject thresholdMap = (JSONObject) entry.getValue();
-                    CombinationRule(ruleGroup, ruleBaseList, thresholdMap, indicators, matchData, type);
+                    CombinationRule(ruleGroup, ruleBaseList, thresholdMap, indicators, matchData, type,accountName);
                 }
             } else {
                 boolean isGroup = "group".equals(ruleGroup.getRuleType());
                 //匹配组合规则
                 if (isGroup) {
-                    CombinationRule(ruleGroup, ruleBaseList, thresholdObj, indicators, matchData, type);
+                    CombinationRule(ruleGroup, ruleBaseList, thresholdObj, indicators, matchData, type,accountName);
                     //匹配单规则
                 } else {
                     RuleBase ruleBase = ruleBaseList.get(0);
@@ -200,7 +210,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
                             JSONObject obj = dimensionData.getJSONObject(i);
                             String value = obj.getString(ruleBase.getIndicatorCode());
                             if (MatchLogic.matchCondition(indicator.getString("dataType"), ruleBase.getRuleCondition(), threshold, value)) {
-                                sendMsg(ruleGroup, obj, type);
+                                sendMsg(ruleGroup, obj, type,accountName);
                             }
                         }
                     }
@@ -222,7 +232,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
      * @throws
      * @author ZHAOXA
      */
-    private void CombinationRule(RuleGroup ruleGroup, List<RuleBase> ruleBaseList, JSONObject thresholdObj, JSONObject indicators, JSONObject matchData, Integer type) {
+    private void CombinationRule(RuleGroup ruleGroup, List<RuleBase> ruleBaseList, JSONObject thresholdObj, JSONObject indicators, JSONObject matchData, Integer type,String accountName) {
         //符合规则的数据集
         JSONArray targetDatas = new JSONArray();
         JSONArray planDatas = new JSONArray();
@@ -275,7 +285,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
         if (!Check.isNull(sendData)) {
             //执行发送
             for (int i = 0; i < sendData.size(); i++) {
-                sendMsg(ruleGroup, sendData.getJSONObject(i), type);
+                sendMsg(ruleGroup, sendData.getJSONObject(i), type,accountName);
             }
         }
     }
@@ -322,7 +332,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
      * @throws
      * @author ZHAOXA
      */
-    private void sendMsg(RuleGroup ruleGroup, JSONObject obj, Integer type) {
+    private void sendMsg(RuleGroup ruleGroup, JSONObject obj, Integer type,String accountName) {
         Long creativeId = obj.getLong("creativeId");
         Long planId = obj.getLong("planId");
         Long accountId = obj.getLong("accountId");
@@ -336,7 +346,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
             }
             type 1:头条2:快手
         }*/
-        String msg = MatchLogic.getMsg(ruleGroup, user, accountId, planId, creativeId, isPause);
+        String msg = MatchLogic.getMsg(ruleGroup, user, accountId, planId, creativeId, isPause,accountName);
         String sendType = ruleGroup.getSendType();
         if ("SMS".equals(sendType)) {
 
@@ -346,7 +356,9 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
 
         } else {
             ISendMessageService sendMessageService = this.sendMessageService;
-            sendMessageService.sendMessage(user.getString("id"), msg);
+//            sendMessageService.sendMessage(user.getString("id"), msg);
+            sendMessageService.sendMessage("1b3deb8258e84df994f1371a51cfc14a", msg);
+            //113dee46c7df464da78c07a985e92cd1 于蒙
         }
         log.debug("账户{}的{}预警已发送", accountId, ruleGroup.getGroupName());
         if (!Check.isNull(msg)) {

+ 2 - 0
module-common/src/main/java/cn/com/ctop/common/module/mapper/UserAllocationMapper.java

@@ -27,4 +27,6 @@ public interface UserAllocationMapper extends BaseMapper<UserAllocation> {
     List<JSONObject> getAccountIdListByUserId(@Param("userId") Long userId);
 
     Long getProjectIdByAccountId(@Param("accountId") Long accountId);
+
+    UserAllocation getUserAllocation(@Param("accountId") Long accountId);
 }

+ 6 - 0
module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/UserAllocationMapper.xml

@@ -69,5 +69,11 @@
     limit 1
     </select>
 
+    <select id="getUserAllocation" resultType="cn.com.ctop.common.module.entity.UserAllocation">
+    select  *  from  ctop_user_allocation
+    where account_id=#{accountId}
+    limit 1
+    </select>
+
 
 </mapper>