From 97142f08bae7d08be57df9e65d03ed50830730e2 Mon Sep 17 00:00:00 2001 From: 3y Date: Thu, 26 May 2022 21:08:34 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E7=AC=A6=E5=90=88=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E7=9A=84=E8=A7=84=E8=8C=83=E7=BC=96=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../limit/SlideWindowLimitService.java | 5 +- .../austin/handler/domain/push/PushParam.java | 6 +- .../handler/domain/sms/YunPianSendResult.java | 5 + .../handler/handler/impl/SmsHandler.java | 3 +- .../handler/script/impl/YunPianSmsScript.java | 2 +- .../support/utils/SnowFlakeIdUtils.java | 108 ------------------ 6 files changed, 14 insertions(+), 115 deletions(-) delete mode 100644 austin-support/src/main/java/com/java3y/austin/support/utils/SnowFlakeIdUtils.java diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/deduplication/limit/SlideWindowLimitService.java b/austin-handler/src/main/java/com/java3y/austin/handler/deduplication/limit/SlideWindowLimitService.java index 392462d..f727faa 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/deduplication/limit/SlideWindowLimitService.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/deduplication/limit/SlideWindowLimitService.java @@ -1,10 +1,10 @@ package com.java3y.austin.handler.deduplication.limit; +import cn.hutool.core.util.IdUtil; import com.java3y.austin.common.domain.TaskInfo; import com.java3y.austin.handler.deduplication.DeduplicationParam; import com.java3y.austin.handler.deduplication.service.AbstractDeduplicationService; import com.java3y.austin.support.utils.RedisUtils; -import com.java3y.austin.support.utils.SnowFlakeIdUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ClassPathResource; import org.springframework.data.redis.core.script.DefaultRedisScript; @@ -29,7 +29,6 @@ public class SlideWindowLimitService extends AbstractLimitService { @Autowired private RedisUtils redisUtils; - private SnowFlakeIdUtils snowFlakeIdUtils = new SnowFlakeIdUtils(1, 1); private DefaultRedisScript redisScript; @@ -55,7 +54,7 @@ public class SlideWindowLimitService extends AbstractLimitService { long nowTime = System.currentTimeMillis(); for (String receiver : taskInfo.getReceiver()) { String key = LIMIT_TAG + deduplicationSingleKey(service, taskInfo, receiver); - String scoreValue = String.valueOf(snowFlakeIdUtils.nextId()); + String scoreValue = String.valueOf(IdUtil.getSnowflake().nextId()); String score = String.valueOf(nowTime); if (redisUtils.execLimitLua(redisScript, Arrays.asList(key), String.valueOf(param.getDeduplicationTime() * 1000), score, String.valueOf(param.getCountNum()), scoreValue)) { filterReceiver.add(receiver); diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/domain/push/PushParam.java b/austin-handler/src/main/java/com/java3y/austin/handler/domain/push/PushParam.java index 5ab85ca..31d1c3c 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/domain/push/PushParam.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/domain/push/PushParam.java @@ -7,8 +7,10 @@ import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; -import java.util.Set; - +/** + * @author 3y + * push的参数 + */ @NoArgsConstructor @AllArgsConstructor @Data diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/domain/sms/YunPianSendResult.java b/austin-handler/src/main/java/com/java3y/austin/handler/domain/sms/YunPianSendResult.java index 61c5bcf..8a02a47 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/domain/sms/YunPianSendResult.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/domain/sms/YunPianSendResult.java @@ -6,6 +6,11 @@ import lombok.NoArgsConstructor; import java.util.List; + +/** + * 云片网短信调用发送接口返回值 + * @author 3y + */ @NoArgsConstructor @Data public class YunPianSendResult { diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/SmsHandler.java b/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/SmsHandler.java index a3fb691..46a2d90 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/SmsHandler.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/SmsHandler.java @@ -98,7 +98,8 @@ public class SmsHandler extends BaseHandler implements Handler { if (index <= messageTypeSmsConfigs.get(i).getWeights()) { supplier = messageTypeSmsConfigs.get(i); - int j = (i + 1) % messageTypeSmsConfigs.size(); // 取下一个供应商 + // 取下一个供应商 + int j = (i + 1) % messageTypeSmsConfigs.size(); if (i == j) { return new MessageTypeSmsConfig[]{supplier}; } diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/script/impl/YunPianSmsScript.java b/austin-handler/src/main/java/com/java3y/austin/handler/script/impl/YunPianSmsScript.java index d3df125..c4ac233 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/script/impl/YunPianSmsScript.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/script/impl/YunPianSmsScript.java @@ -65,7 +65,7 @@ public class YunPianSmsScript extends BaseSmsScript implements SmsScript { * @return */ private Map assembleParam(SmsParam smsParam, YunPianSmsAccount account) { - Map params = new HashMap<>(); + Map params = new HashMap<>(8); params.put("apikey", account.getApikey()); params.put("mobile", StringUtils.join(smsParam.getPhones(), StrUtil.C_COMMA)); params.put("tpl_id", account.getTplId()); diff --git a/austin-support/src/main/java/com/java3y/austin/support/utils/SnowFlakeIdUtils.java b/austin-support/src/main/java/com/java3y/austin/support/utils/SnowFlakeIdUtils.java deleted file mode 100644 index 925ea8b..0000000 --- a/austin-support/src/main/java/com/java3y/austin/support/utils/SnowFlakeIdUtils.java +++ /dev/null @@ -1,108 +0,0 @@ -package com.java3y.austin.support.utils; - -/** - * 雪花算法生成唯一id工具类 - * - * @author cao - * @date 2022-04-20 13:12 - */ -public class SnowFlakeIdUtils { - - /** - * 初始时间截 (2017-01-01) - */ - private final static long START_TIMESTAMP = 1483200000000L; - - /** - * 每一部分占用的位数 - */ - private final static long SEQUENCE_BIT = 12; //***占用的位数 - private final static long MACHINE_BIT = 5; //机器标识占用的位数 - private final static long DATA_CENTER_BIT = 5; //数据中心占用的位数 - - /** - * 每一部分的最大值 - */ - private final static long MAX_SEQUENCE = -1L ^ (-1L << SEQUENCE_BIT); - private final static long MAX_MACHINE_NUM = -1L ^ (-1L << MACHINE_BIT); - private final static long MAX_DATA_CENTER_NUM = -1L ^ (-1L << DATA_CENTER_BIT); - - /** - * 每一部分向左的位移 - */ - private final static long MACHINE_LEFT = SEQUENCE_BIT; - private final static long DATA_CENTER_LEFT = SEQUENCE_BIT + MACHINE_BIT; - private final static long TIMESTAMP_LEFT = DATA_CENTER_LEFT + DATA_CENTER_BIT; - - private long dataCenterId; //数据中心 - private long machineId; //机器标识 - private long sequence = 0L; //*** - private long lastTimeStamp = -1L; //上一次时间戳 - - - /** - * 根据指定的数据中心ID和机器标志ID生成指定的*** - * - * @param dataCenterId 数据中心ID - * @param machineId 机器标志ID - */ - public SnowFlakeIdUtils(long dataCenterId, long machineId) { - if (dataCenterId > MAX_DATA_CENTER_NUM || dataCenterId < 0) { - throw new IllegalArgumentException(String.format("DtaCenterId 不能大于 %d 或小于 0", MAX_DATA_CENTER_NUM)); - } - if (machineId > MAX_MACHINE_NUM || machineId < 0) { - throw new IllegalArgumentException(String.format("MachineId 不能大于 %d 或小于 0", MAX_MACHINE_NUM)); - } - this.dataCenterId = dataCenterId; - this.machineId = machineId; - } - - - /** - * 产生下一个ID - * - * @return - */ - public synchronized long nextId() { - long currTimeStamp = System.currentTimeMillis(); - if (currTimeStamp < lastTimeStamp) { - throw new RuntimeException("当前时间小于上一次记录的时间戳!"); - } - - if (currTimeStamp == lastTimeStamp) { - //相同毫秒内,***自增 - sequence = (sequence + 1) & MAX_SEQUENCE; - //同一毫秒的序列数已经达到最大 - if (sequence == 0L) { - currTimeStamp = getNextMill(); - } - } else { - //不同毫秒内,***置为0 - sequence = 0L; - } - - lastTimeStamp = currTimeStamp; - - return (currTimeStamp - START_TIMESTAMP) << TIMESTAMP_LEFT //时间戳部分 - | dataCenterId << DATA_CENTER_LEFT //数据中心部分 - | machineId << MACHINE_LEFT //机器标识部分 - | sequence; //***部分 - } - - - /** - * 阻塞到下一个毫秒,直到获得新的时间戳 - * - * @return 当前时间戳 - */ - private long getNextMill() { - - long mill = System.currentTimeMillis(); - while (mill <= lastTimeStamp) { - mill = System.currentTimeMillis(); - } - return mill; - - } - -} From 8969f96bfcaaa8ae016c8bee66526bf6359294cf Mon Sep 17 00:00:00 2001 From: 3y Date: Thu, 26 May 2022 21:14:56 +0800 Subject: [PATCH 2/4] update README.md --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e2121ba..2e02f25 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ -![](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/2ccd794db76e482680f72d60959cf368~tplv-k3u1fbpfcp-zoom-1.image) + +![](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/108bca55a5364a73b3fd50b8bde304d1~tplv-k3u1fbpfcp-watermark.image?)

作者 @@ -8,9 +9,14 @@ 作者 项目交流 + Bilibili 对线面试官

+最近我已经在**bilibili**更新Austin的视频了哟,**求关注和三连**!这是我更新的动力!! + +[https://space.bilibili.com/198434865/channel/collectiondetail?sid=435119](https://space.bilibili.com/198434865/channel/collectiondetail?sid=435119) + ## 项目介绍 From 3cb7cdb1fdc02810a95fdb1c3f4d26a8abb1f720 Mon Sep 17 00:00:00 2001 From: 3y Date: Tue, 31 May 2022 08:41:55 +0800 Subject: [PATCH 3/4] fix email regex --- .../austin/service/api/impl/action/AfterParamCheckAction.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/austin-service-api-impl/src/main/java/com/java3y/austin/service/api/impl/action/AfterParamCheckAction.java b/austin-service-api-impl/src/main/java/com/java3y/austin/service/api/impl/action/AfterParamCheckAction.java index ee44492..2bdffa1 100644 --- a/austin-service-api-impl/src/main/java/com/java3y/austin/service/api/impl/action/AfterParamCheckAction.java +++ b/austin-service-api-impl/src/main/java/com/java3y/austin/service/api/impl/action/AfterParamCheckAction.java @@ -5,7 +5,6 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ReUtil; import com.alibaba.fastjson.JSON; import com.java3y.austin.common.domain.TaskInfo; -import com.java3y.austin.common.enums.ChannelType; import com.java3y.austin.common.enums.IdType; import com.java3y.austin.common.enums.RespStatusEnum; import com.java3y.austin.common.vo.BasicResultVO; @@ -31,7 +30,7 @@ import java.util.stream.Collectors; public class AfterParamCheckAction implements BusinessProcess { public static final String PHONE_REGEX_EXP = "^((13[0-9])|(14[5,7,9])|(15[0-3,5-9])|(166)|(17[0-9])|(18[0-9])|(19[1,8,9]))\\d{8}$"; - public static final String EMAIL_REGEX_EXP = "[a-zA-Z0-9]+@[a-zA-Z0-9]+\\\\.[a-zA-Z0-9]+"; + public static final String EMAIL_REGEX_EXP = "^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\\\.[A-Z]{2,6}$"; public static final HashMap CHANNEL_REGEX_EXP = new HashMap<>(); static { From cc32c55d4a1ee36dfb4ec1d4d64bffeb2fdf0d92 Mon Sep 17 00:00:00 2001 From: 3y Date: Tue, 31 May 2022 08:42:30 +0800 Subject: [PATCH 4/4] fix email regex --- .../austin/service/api/impl/action/AfterParamCheckAction.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/austin-service-api-impl/src/main/java/com/java3y/austin/service/api/impl/action/AfterParamCheckAction.java b/austin-service-api-impl/src/main/java/com/java3y/austin/service/api/impl/action/AfterParamCheckAction.java index 2bdffa1..f86ea5e 100644 --- a/austin-service-api-impl/src/main/java/com/java3y/austin/service/api/impl/action/AfterParamCheckAction.java +++ b/austin-service-api-impl/src/main/java/com/java3y/austin/service/api/impl/action/AfterParamCheckAction.java @@ -30,7 +30,7 @@ import java.util.stream.Collectors; public class AfterParamCheckAction implements BusinessProcess { public static final String PHONE_REGEX_EXP = "^((13[0-9])|(14[5,7,9])|(15[0-3,5-9])|(166)|(17[0-9])|(18[0-9])|(19[1,8,9]))\\d{8}$"; - public static final String EMAIL_REGEX_EXP = "^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\\\.[A-Z]{2,6}$"; + public static final String EMAIL_REGEX_EXP = "^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$"; public static final HashMap CHANNEL_REGEX_EXP = new HashMap<>(); static {