yujian
2020-01-07 1b3856e8f5431508d944a3b9c7a444dac3536bb6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package com.yeshi.fanli.service.impl.monitor;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import javax.annotation.Resource;
 
import org.springframework.stereotype.Service;
 
import com.yeshi.fanli.entity.system.ConfigKeyEnum;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.monitor.BusinessEmergent110Service;
import com.yeshi.fanli.util.EmergencyUtil;
import com.yeshi.fanli.util.StringUtil;
 
@Service
public class BusinessEmergent110ServiceImpl implements BusinessEmergent110Service {
 
    String[] phones = new String[] { "18581318252", "15025351808" };
 
    private static Map<String, List<String>> map = new HashMap<>();
    private static long shareTime = 0L;
 
    @Resource
    private ConfigService configService;
 
    @Override
    public void shareTaoBaoGoodsError(String identifyCode) {
        String key = "monitor-error-share-tb";
        int timeM = 5;
        int limitCount = 5;
        // 5分钟内错误 5次触发报警
 
        List<String> stList = map.get(key);
        if (stList == null) {
            stList = new ArrayList<>();
            map.put(key, stList);
        }
        if (System.currentTimeMillis() - shareTime > 1000 * 60 * timeM) {
            stList.clear();
            shareTime = System.currentTimeMillis();
        }
        boolean exist = false;
        for (String code : stList)
            if (identifyCode.equalsIgnoreCase(code)) {
                exist = true;
                break;
            }
        if (!exist)
            stList.add(identifyCode);
        if (stList.size() >= limitCount) {// 触发报警
            if ("1".equalsIgnoreCase(configService.get(ConfigKeyEnum.canSendEmergencyMsg.getKey())))
                EmergencyUtil.baoJin(key, "板栗快省【分享赚】", phones);
        }
    }
 
    @Override
    public void buyTaoBaoGoodsError(String identifyCode) {
        // 5分钟内错误 3次触发报警
        String key = "monitor-error-buy-tb";
        int timeM = 5;
        int limitCount = 5;
        // 5分钟内错误 5次触发报警
        List<String> stList = map.get(key);
        if (stList == null) {
            stList = new ArrayList<>();
            map.put(key, stList);
        }
        if (System.currentTimeMillis() - shareTime > 1000 * 60 * timeM) {
            stList.clear();
            shareTime = System.currentTimeMillis();
        }
        boolean exist = false;
        for (String code : stList)
            if (identifyCode.equalsIgnoreCase(code)) {
                exist = true;
                break;
            }
        if (!exist)
            stList.add(identifyCode);
        if (stList.size() >= limitCount) {// 触发报警
            if ("1".equalsIgnoreCase(configService.get(ConfigKeyEnum.canSendEmergencyMsg.getKey())))
                EmergencyUtil.baoJin(key, "板栗快省【领券返利】", phones);
        }
    }
 
    @Override
    public void taoBaoAPPKeyLimitError(String appKey, String identifyCode) {
        // 2分钟内错误 3次触发报警
        String key = "monitor-error-tb-app-limit-" + appKey;
        int timeM = 2;
        int limitCount = 3;
        // 5分钟内错误 5次触发报警
        List<String> stList = map.get(key);
        if (stList == null) {
            stList = new ArrayList<>();
            map.put(key, stList);
        }
        if (System.currentTimeMillis() - shareTime > 1000 * 60 * timeM) {
            stList.clear();
            shareTime = System.currentTimeMillis();
        }
        boolean exist = false;
        for (String code : stList)
            if (identifyCode.equalsIgnoreCase(code)) {
                exist = true;
                break;
            }
        if (!exist)
            stList.add(identifyCode);
        if (stList.size() >= limitCount) {// 触发报警
            if ("1".equalsIgnoreCase(configService.get(ConfigKeyEnum.canSendEmergencyMsg.getKey())))
                EmergencyUtil.baoJin(key, "淘宝APPKey请求限制【" + appKey + "】", phones);
        }
    }
 
    @Override
    public void tljNoMoney(String account) {
        String key = "monitor-error-tlj-no-money-" + StringUtil.Md5(account);
        EmergencyUtil.baoJin(key, String.format("淘礼金账户余额不足【账号:%s】", account), phones);
    }
 
}