| | |
| | | //间隔判断 |
| | | if (config.getMinSpaceTime() != null) { |
| | | List<GoldCornGetRecord> list = goldCornGetRecordService.list(query, 1, 1); |
| | | if (list != null && list.size() > 0 && System.currentTimeMillis() - list.get(0).getCreateTime().getTime() < config.getMinSpaceTime() * 1000L) { |
| | | if (list != null && list.size() > 0 && time.getTime() - list.get(0).getCreateTime().getTime() < config.getMinSpaceTime() * 1000L) { |
| | | String msg = String.format("需要间隔%s秒以上", config.getMinSpaceTime()); |
| | | throw new GoldCornMakeException(GoldCornMakeException.CODE_GET_FREQUENCY_LIMIT, msg); |
| | | throw new GoldCornMakeException(GoldCornMakeException.CODE_GET_FREQUENCY_TIME_LIMIT, msg); |
| | | } |
| | | } |
| | | |
| | |
| | | Map<GoldCornGetType, Long> countMap = goldCornGetRecordService.sumEventCount(query); |
| | | if (countMap.get(type) != null && (countMap.get(type) >= config.getLimitCount())) { |
| | | String msg = String.format("超出%s次/%s的限制", config.getLimitCount(), config.getTimeUnit().getName()); |
| | | throw new GoldCornMakeException(GoldCornMakeException.CODE_GET_FREQUENCY_LIMIT, msg); |
| | | throw new GoldCornMakeException(GoldCornMakeException.CODE_GET_FREQUENCY_COUNT_LIMIT, msg); |
| | | } |
| | | return config.getLimitCount() - (countMap.get(type) != null ? countMap.get(type) : 0); |
| | | } |