admin
2020-05-20 98b1a0affd69bbe63223c21fdd2c404e8bedfccb
fanli/src/main/java/com/yeshi/fanli/service/impl/monitor/BusinessEmergent110ServiceImpl.java
@@ -9,16 +9,16 @@
import org.springframework.stereotype.Service;
import com.yeshi.fanli.exception.SMSException;
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.Constant;
import com.yeshi.fanli.util.TencentSMSUtil;
import com.yeshi.fanli.util.EmergencyUtil;
import com.yeshi.fanli.util.StringUtil;
@Service
public class BusinessEmergent110ServiceImpl implements BusinessEmergent110Service {
   String[] phones = new String[] { "18581318252", "15025351808", "18696787365" };
   String[] phones = new String[] { "18581318252", "15025351808" };
   private static Map<String, List<String>> map = new HashMap<>();
   private static long shareTime = 0L;
@@ -51,7 +51,8 @@
      if (!exist)
         stList.add(identifyCode);
      if (stList.size() >= limitCount) {// 触发报警
         baoJin(key, "返利券【分享赚】");
         if ("1".equalsIgnoreCase(configService.get(ConfigKeyEnum.canSendEmergencyMsg.getKey())))
            EmergencyUtil.baoJin(key, "板栗快省【分享赚】", phones);
      }
   }
@@ -80,27 +81,45 @@
      if (!exist)
         stList.add(identifyCode);
      if (stList.size() >= limitCount) {// 触发报警
         baoJin(key, "返利券【领券返利】");
         if ("1".equalsIgnoreCase(configService.get(ConfigKeyEnum.canSendEmergencyMsg.getKey())))
            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());
         // 发送短信
         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();
               }
            }
   @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);
   }
}