From 15220b5cee320d2914066a903bcbcad0e92a2729 Mon Sep 17 00:00:00 2001 From: 3y Date: Thu, 20 Jan 2022 22:58:16 +0800 Subject: [PATCH] =?UTF-8?q?0.merge=201.=E9=81=B5=E5=BE=AA=E9=98=BF?= =?UTF-8?q?=E9=87=8C=E6=8F=92=E4=BB=B6=E8=A7=84=E5=88=92=20=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/java3y/austin/enums/ChannelType.java | 2 +- .../com/java3y/austin/enums/MessageType.java | 2 +- .../java3y/austin/handler/BaseHandler.java | 52 +++++++++++++++++++ .../java3y/austin/handler/EmailHandler.java | 2 +- .../com/java3y/austin/handler/Handler.java | 42 ++------------- .../com/java3y/austin/handler/SmsHandler.java | 2 +- .../com/java3y/austin/script/SmsScript.java | 3 +- .../service/AbstractDeduplicationService.java | 2 +- .../austin/utils/GroupIdMappingUtils.java | 6 +-- .../austin/utils/ContentHolderUtil.java | 4 +- .../com/java3y/austin/utils/LogUtils.java | 3 +- .../com/java3y/austin/utils/RedisUtils.java | 2 +- .../java3y/austin/utils/TaskInfoUtils.java | 3 +- .../austin/config/SwaggerConfiguration.java | 4 ++ .../austin/controller/ApolloController.java | 18 ------- .../austin/controller/RedisController.java | 25 --------- 16 files changed, 75 insertions(+), 97 deletions(-) create mode 100644 austin-handler/src/main/java/com/java3y/austin/handler/BaseHandler.java delete mode 100644 austin-web/src/main/java/com/java3y/austin/controller/ApolloController.java delete mode 100644 austin-web/src/main/java/com/java3y/austin/controller/RedisController.java diff --git a/austin-common/src/main/java/com/java3y/austin/enums/ChannelType.java b/austin-common/src/main/java/com/java3y/austin/enums/ChannelType.java index 944f74d..11da1e8 100644 --- a/austin-common/src/main/java/com/java3y/austin/enums/ChannelType.java +++ b/austin-common/src/main/java/com/java3y/austin/enums/ChannelType.java @@ -43,7 +43,7 @@ public enum ChannelType { /** * 英文标识 */ - private String code_en; + private String codeEn; /** * 通过code获取class diff --git a/austin-common/src/main/java/com/java3y/austin/enums/MessageType.java b/austin-common/src/main/java/com/java3y/austin/enums/MessageType.java index ad354f8..f049dc0 100644 --- a/austin-common/src/main/java/com/java3y/austin/enums/MessageType.java +++ b/austin-common/src/main/java/com/java3y/austin/enums/MessageType.java @@ -30,7 +30,7 @@ public enum MessageType { /** * 英文标识 */ - private String code_en; + private String codeEn; /** diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/BaseHandler.java b/austin-handler/src/main/java/com/java3y/austin/handler/BaseHandler.java new file mode 100644 index 0000000..8055cf1 --- /dev/null +++ b/austin-handler/src/main/java/com/java3y/austin/handler/BaseHandler.java @@ -0,0 +1,52 @@ +package com.java3y.austin.handler; + +import com.java3y.austin.domain.AnchorInfo; +import com.java3y.austin.domain.TaskInfo; +import com.java3y.austin.enums.AnchorState; +import com.java3y.austin.utils.LogUtils; +import org.springframework.beans.factory.annotation.Autowired; + +import javax.annotation.PostConstruct; + +/** + * @author 3y + * 发送各个渠道的handler + */ +public abstract class BaseHandler implements Handler { + + /** + * 标识渠道的Code + * 子类初始化的时候指定 + */ + protected Integer channelCode; + + + @Autowired + private HandlerHolder handlerHolder; + + /** + * 初始化渠道与Handler的映射关系 + */ + @PostConstruct + private void init() { + handlerHolder.putHandler(channelCode, this); + } + + @Override + public void doHandler(TaskInfo taskInfo) { + if (handler(taskInfo)) { + LogUtils.print(AnchorInfo.builder().state(AnchorState.SEND_SUCCESS.getCode()).businessId(taskInfo.getBusinessId()).ids(taskInfo.getReceiver()).build()); + return; + } + LogUtils.print(AnchorInfo.builder().state(AnchorState.SEND_FAIL.getCode()).businessId(taskInfo.getBusinessId()).ids(taskInfo.getReceiver()).build()); + } + + /** + * 统一处理的handler接口 + * + * @param taskInfo + * @return + */ + public abstract boolean handler(TaskInfo taskInfo); + +} diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/EmailHandler.java b/austin-handler/src/main/java/com/java3y/austin/handler/EmailHandler.java index f612b42..a97de4d 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/EmailHandler.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/EmailHandler.java @@ -21,7 +21,7 @@ import org.springframework.stereotype.Component; */ @Component @Slf4j -public class EmailHandler extends Handler { +public class EmailHandler extends BaseHandler implements Handler { private static final String EMAIL_ACCOUNT_KEY = "emailAccount"; private static final String PREFIX = "email_"; diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/Handler.java b/austin-handler/src/main/java/com/java3y/austin/handler/Handler.java index ee65871..e149d83 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/Handler.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/Handler.java @@ -1,51 +1,17 @@ package com.java3y.austin.handler; -import com.java3y.austin.domain.AnchorInfo; import com.java3y.austin.domain.TaskInfo; -import com.java3y.austin.enums.AnchorState; -import com.java3y.austin.utils.LogUtils; -import org.springframework.beans.factory.annotation.Autowired; - -import javax.annotation.PostConstruct; /** * @author 3y - * 发送各个渠道的handler + * 消息处理器 */ -public abstract class Handler { - - /** - * 标识渠道的Code - * 子类初始化的时候指定 - */ - protected Integer channelCode; - - - @Autowired - private HandlerHolder handlerHolder; - - /** - * 初始化渠道与Handler的映射关系 - */ - @PostConstruct - private void init() { - handlerHolder.putHandler(channelCode, this); - } - - public void doHandler(TaskInfo taskInfo) { - if (handler(taskInfo)) { - LogUtils.print(AnchorInfo.builder().state(AnchorState.SEND_SUCCESS.getCode()).businessId(taskInfo.getBusinessId()).ids(taskInfo.getReceiver()).build()); - return; - } - LogUtils.print(AnchorInfo.builder().state(AnchorState.SEND_FAIL.getCode()).businessId(taskInfo.getBusinessId()).ids(taskInfo.getReceiver()).build()); - } +public interface Handler { /** - * 统一处理的handler接口 - * + * 处理器 * @param taskInfo - * @return */ - public abstract boolean handler(TaskInfo taskInfo); + void doHandler(TaskInfo taskInfo); } diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/SmsHandler.java b/austin-handler/src/main/java/com/java3y/austin/handler/SmsHandler.java index 88c118c..413c367 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/SmsHandler.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/SmsHandler.java @@ -24,7 +24,7 @@ import java.util.List; */ @Component @Slf4j -public class SmsHandler extends Handler { +public class SmsHandler extends BaseHandler implements Handler { public SmsHandler() { channelCode = ChannelType.SMS.getCode(); diff --git a/austin-handler/src/main/java/com/java3y/austin/script/SmsScript.java b/austin-handler/src/main/java/com/java3y/austin/script/SmsScript.java index cf8ca09..b04b81e 100644 --- a/austin-handler/src/main/java/com/java3y/austin/script/SmsScript.java +++ b/austin-handler/src/main/java/com/java3y/austin/script/SmsScript.java @@ -11,12 +11,11 @@ import java.util.List; */ public interface SmsScript { - /** * 发送短信 - * * @param smsParam * @return 渠道商接口返回值 + * @throws Exception */ List send(SmsParam smsParam) throws Exception; diff --git a/austin-handler/src/main/java/com/java3y/austin/service/deduplication/service/AbstractDeduplicationService.java b/austin-handler/src/main/java/com/java3y/austin/service/deduplication/service/AbstractDeduplicationService.java index 9b311fe..07548fe 100644 --- a/austin-handler/src/main/java/com/java3y/austin/service/deduplication/service/AbstractDeduplicationService.java +++ b/austin-handler/src/main/java/com/java3y/austin/service/deduplication/service/AbstractDeduplicationService.java @@ -94,7 +94,7 @@ public abstract class AbstractDeduplicationService implements DeduplicationServi } } if (CollUtil.isNotEmpty(keyValues)) { - redisUtils.pipelineSetEX(keyValues, param.getDeduplicationTime()); + redisUtils.pipelineSetEx(keyValues, param.getDeduplicationTime()); } } diff --git a/austin-handler/src/main/java/com/java3y/austin/utils/GroupIdMappingUtils.java b/austin-handler/src/main/java/com/java3y/austin/utils/GroupIdMappingUtils.java index 918dfc8..8497339 100644 --- a/austin-handler/src/main/java/com/java3y/austin/utils/GroupIdMappingUtils.java +++ b/austin-handler/src/main/java/com/java3y/austin/utils/GroupIdMappingUtils.java @@ -23,7 +23,7 @@ public class GroupIdMappingUtils { List groupIds = new ArrayList<>(); for (ChannelType channelType : ChannelType.values()) { for (MessageType messageType : MessageType.values()) { - groupIds.add(channelType.getCode_en() + "." + messageType.getCode_en()); + groupIds.add(channelType.getCodeEn() + "." + messageType.getCodeEn()); } } return groupIds; @@ -36,8 +36,8 @@ public class GroupIdMappingUtils { * @return */ public static String getGroupIdByTaskInfo(TaskInfo taskInfo) { - String channelCodeEn = ChannelType.getEnumByCode(taskInfo.getSendChannel()).getCode_en(); - String msgCodeEn = MessageType.getEnumByCode(taskInfo.getMsgType()).getCode_en(); + String channelCodeEn = ChannelType.getEnumByCode(taskInfo.getSendChannel()).getCodeEn(); + String msgCodeEn = MessageType.getEnumByCode(taskInfo.getMsgType()).getCodeEn(); return channelCodeEn + "." + msgCodeEn; } } diff --git a/austin-support/src/main/java/com/java3y/austin/utils/ContentHolderUtil.java b/austin-support/src/main/java/com/java3y/austin/utils/ContentHolderUtil.java index 3ce5d93..ea8718d 100644 --- a/austin-support/src/main/java/com/java3y/austin/utils/ContentHolderUtil.java +++ b/austin-support/src/main/java/com/java3y/austin/utils/ContentHolderUtil.java @@ -27,7 +27,7 @@ public class ContentHolderUtil { private static final StandardEvaluationContext EVALUATION_CONTEXT; - private static final PropertyPlaceholderHelper propertyPlaceholderHelper = new PropertyPlaceholderHelper( + private static final PropertyPlaceholderHelper PROPERTY_PLACEHOLDER_HELPER = new PropertyPlaceholderHelper( PLACE_HOLDER_PREFIX, PLACE_HOLDER_SUFFIX); static { @@ -36,7 +36,7 @@ public class ContentHolderUtil { } public static String replacePlaceHolder(final String template, final Map paramMap) { - String replacedPushContent = propertyPlaceholderHelper.replacePlaceholders(template, + String replacedPushContent = PROPERTY_PLACEHOLDER_HELPER.replacePlaceholders(template, new CustomPlaceholderResolver(paramMap)); return replacedPushContent; } diff --git a/austin-support/src/main/java/com/java3y/austin/utils/LogUtils.java b/austin-support/src/main/java/com/java3y/austin/utils/LogUtils.java index d26bf66..fed49dd 100644 --- a/austin-support/src/main/java/com/java3y/austin/utils/LogUtils.java +++ b/austin-support/src/main/java/com/java3y/austin/utils/LogUtils.java @@ -8,10 +8,9 @@ import com.java3y.austin.domain.LogParam; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; -import java.util.Date; - /** * 所有的日志都存在 + * @author 3y */ @Slf4j @Component diff --git a/austin-support/src/main/java/com/java3y/austin/utils/RedisUtils.java b/austin-support/src/main/java/com/java3y/austin/utils/RedisUtils.java index 050b0eb..ac37fd0 100644 --- a/austin-support/src/main/java/com/java3y/austin/utils/RedisUtils.java +++ b/austin-support/src/main/java/com/java3y/austin/utils/RedisUtils.java @@ -47,7 +47,7 @@ public class RedisUtils { /** * pipeline 设置 key-value 并设置过期时间 */ - public void pipelineSetEX(Map keyValues, Long seconds) { + public void pipelineSetEx(Map keyValues, Long seconds) { try { redisTemplate.executePipelined((RedisCallback) connection -> { for (Map.Entry entry : keyValues.entrySet()) { diff --git a/austin-support/src/main/java/com/java3y/austin/utils/TaskInfoUtils.java b/austin-support/src/main/java/com/java3y/austin/utils/TaskInfoUtils.java index 9d07e7d..046f24c 100644 --- a/austin-support/src/main/java/com/java3y/austin/utils/TaskInfoUtils.java +++ b/austin-support/src/main/java/com/java3y/austin/utils/TaskInfoUtils.java @@ -13,6 +13,7 @@ import java.util.Date; public class TaskInfoUtils { private static final int TYPE_FLAG = 1000000; + private static final char PARAM = '?'; /** * 生成BusinessId @@ -30,7 +31,7 @@ public class TaskInfoUtils { public static String generateUrl(String url, Long templateId, Integer templateType) { url = url.trim(); Long businessId = generateBusinessId(templateId, templateType); - if (url.indexOf('?') == -1) { + if (url.indexOf(PARAM) == -1) { return url + "?track_code_bid=" + businessId; } else { return url + "&track_code_bid=" + businessId; diff --git a/austin-web/src/main/java/com/java3y/austin/config/SwaggerConfiguration.java b/austin-web/src/main/java/com/java3y/austin/config/SwaggerConfiguration.java index 4e00af6..8751c85 100644 --- a/austin-web/src/main/java/com/java3y/austin/config/SwaggerConfiguration.java +++ b/austin-web/src/main/java/com/java3y/austin/config/SwaggerConfiguration.java @@ -12,6 +12,10 @@ import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; +/** + * swagger配置类 + * @author 3y + */ @Component @EnableOpenApi @ApiModel diff --git a/austin-web/src/main/java/com/java3y/austin/controller/ApolloController.java b/austin-web/src/main/java/com/java3y/austin/controller/ApolloController.java deleted file mode 100644 index a54d2f5..0000000 --- a/austin-web/src/main/java/com/java3y/austin/controller/ApolloController.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.java3y.austin.controller; - -import com.ctrip.framework.apollo.Config; -import com.ctrip.framework.apollo.spring.annotation.ApolloConfig; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class ApolloController { - - @ApolloConfig("boss.austin") - private Config config; - - @RequestMapping("/apollo") - public String testApollo() { - return config.getProperty("a", "b"); - } -} diff --git a/austin-web/src/main/java/com/java3y/austin/controller/RedisController.java b/austin-web/src/main/java/com/java3y/austin/controller/RedisController.java deleted file mode 100644 index 4e87038..0000000 --- a/austin-web/src/main/java/com/java3y/austin/controller/RedisController.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.java3y.austin.controller; - -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -/** - * @author 3y - * @date 2021/12/9 - */ -@RestController -@Slf4j -public class RedisController { - - @Autowired - private RedisTemplate redisTemplate; - - - @RequestMapping("/redis") - public void testRedis() { - log.info(redisTemplate.opsForValue().get("1")); - } -}