admin
2019-07-11 3824cbcaec6e6c67418d5280a53e9c2fedeef6f9
fanli/src/main/java/com/yeshi/fanli/service/impl/monitor/BusinessEmergent110ServiceImpl.java
@@ -9,11 +9,9 @@
import org.springframework.stereotype.Service;
import com.yeshi.fanli.exception.SMSException;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.monitor.BusinessEmergent110Service;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.TencentSMSUtil;
import com.yeshi.fanli.util.EmergencyUtil;
@Service
public class BusinessEmergent110ServiceImpl implements BusinessEmergent110Service {
@@ -51,7 +49,8 @@
      if (!exist)
         stList.add(identifyCode);
      if (stList.size() >= limitCount) {// 触发报警
         baoJin(key, "返利券【分享赚】");
         if ("1".equalsIgnoreCase(configService.get("can_send_emergency_msg")))
            EmergencyUtil.baoJin(key, "返利券【分享赚】", phones);
      }
   }
@@ -80,26 +79,38 @@
      if (!exist)
         stList.add(identifyCode);
      if (stList.size() >= limitCount) {// 触发报警
         baoJin(key, "返利券【领券返利】");
         if ("1".equalsIgnoreCase(configService.get("can_send_emergency_msg")))
            EmergencyUtil.baoJin(key, "返利券【领券返利】", phones);
      }
   }
   static Map<String, Long> emergentTimeMap = new HashMap<>();
   private void baoJin(String key, String name) {
      if (emergentTimeMap.get(key) == null || System.currentTimeMillis() - emergentTimeMap.get(key) > 1000 * 60 * 2)// 2分钟报警一次
      {
         emergentTimeMap.put(key, System.currentTimeMillis());
         // 发送短信
   @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("can_send_emergency_msg")))
            for (String phone : phones) {
               try {
                  TencentSMSUtil.sendSingleMsg(phone, Constant.smsConfig.getServiceEmergency()
                        .replace("[签名]", Constant.smsConfig.getSmsSign()).replace("[服务名字]", name));
               } catch (SMSException e) {
                  e.printStackTrace();
               }
            }
            EmergencyUtil.baoJin(key, "淘宝APPKey请求限制【" + appKey + "】", phones);
      }
   }