diff --git a/pom.xml b/pom.xml index 0f0e9ea..c71481c 100644 --- a/pom.xml +++ b/pom.xml @@ -51,7 +51,7 @@ com.fasterxml.jackson.core jackson-databind ${jackson.version} - provided + test diff --git a/src/main/java/com/github/jaemon/dinger/DingerSender.java b/src/main/java/com/github/jaemon/dinger/DingerSender.java index 5e9328f..eced17e 100644 --- a/src/main/java/com/github/jaemon/dinger/DingerSender.java +++ b/src/main/java/com/github/jaemon/dinger/DingerSender.java @@ -15,12 +15,10 @@ */ package com.github.jaemon.dinger; -import com.github.jaemon.dinger.core.entity.MsgType; +import com.github.jaemon.dinger.core.entity.DingerRequest; import com.github.jaemon.dinger.core.entity.enums.DingerType; import com.github.jaemon.dinger.core.entity.enums.MessageSubType; -import com.github.jaemon.dinger.entity.DingerResult; - -import java.util.List; +import com.github.jaemon.dinger.core.entity.DingerResponse; /** * DingTalk Sender @@ -36,16 +34,12 @@ public interface DingerSender { * * @param messageSubType * 消息类型{@link MessageSubType} - * @param keyword - * 关键词(方便定位日志) - * @param title - * 标题(dingtalk-markdown) - * @param content - * 消息内容 + * @param request + * 请求体 {@link DingerRequest} * @return * 响应报文 * */ - DingerResult send(MessageSubType messageSubType, String keyword, String title, String content); + DingerResponse send(MessageSubType messageSubType, DingerRequest request); /** * 发送预警消息到钉钉 @@ -54,134 +48,11 @@ public interface DingerSender { * Dinger类型 {@link DingerType} * @param messageSubType * 消息类型{@link MessageSubType} - * @param keyword - * 关键词(方便定位日志) - * @param title - * 标题(dingtalk-markdown) - * @param content - * 消息内容 + * @param request + * 请求体 {@link DingerRequest} * @return * 响应报文 * */ - DingerResult send(DingerType dingerType, MessageSubType messageSubType, String keyword, String title, String content); - + DingerResponse send(DingerType dingerType, MessageSubType messageSubType, DingerRequest request); - /** - * 发送预警消息到钉钉-消息指定艾特人电话信息 - * - * @param messageSubType - * 消息类型{@link MessageSubType} - * @param keyword - * 关键词(方便定位日志) - * @param title - * 副标题(dingtalk-markdown) - * @param content - * 消息内容 - * @param phones - * 艾特人电话集 - * @return - * 响应报文 - * */ - DingerResult send(MessageSubType messageSubType, String keyword, String title, String content, List phones); - - /** - * 发送预警消息到钉钉-消息指定艾特人电话信息 - * - * @param dingerType - * Dinger类型 {@link DingerType} - * @param messageSubType - * 消息类型{@link MessageSubType} - * @param keyword - * 关键词(方便定位日志) - * @param title - * 副标题(dingtalk-markdown) - * @param content - * 消息内容 - * @param phones - * 艾特人电话集 - * @return - * 响应报文 - * */ - DingerResult send(DingerType dingerType, MessageSubType messageSubType, String keyword, String title, String content, List phones); - - - /** - * 发送预警消息到钉钉-艾特所有人(仅限{@link MessageSubType#TEXT}) - * - *
-     *     markdown不支持艾特全部
-     * 
- * - * @param keyword - * 关键词(方便定位日志) - * @param title - * 副标题(dingtalk-markdown) - * @param content - * 消息内容 - * @return - * 响应报文 - * */ - DingerResult sendAll(String keyword, String title, String content); - - /** - * 发送预警消息到钉钉-艾特所有人(仅限{@link MessageSubType#TEXT}) - * - *
-     *     markdown不支持艾特全部
-     * 
- * - * @param dingerType - * Dinger类型 {@link DingerType} - * @param keyword - * 关键词(方便定位日志) - * @param title - * 副标题(dingtalk-markdown) - * @param content - * 消息内容 - * @return - * 响应报文 - * */ - DingerResult sendAll(DingerType dingerType, String keyword, String title, String content); - - /** - * 发送完全自定义消息-对象方式 - * - *
- * 具体报文体格式参见: https://ding-doc.dingtalk.com/doc#/serverapi3/iydd5h/e9d991e2 - *
- * - * @param keyword - * 关键词(方便定位日志) - * @param message - * 消息内容 - * @param - * T extends {@link MsgType} - * @return - * 响应报文 - */ - DingerResult send(String keyword, T message); - - /** - * 发送完全自定义消息-json字符串方式 - * - *
- * 具体报文体格式参见: - *
    - *
  • DingTalk: https://ding-doc.dingtalk.com/doc#/serverapi3/iydd5h/e9d991e2
  • - *
  • WeTalk: https://work.weixin.qq.com/api/doc/90000/90136/91770
  • - *
- *
- * - * @param keyword - * 关键词(方便定位日志) - * @param dingerType - * 机器人类型 {@link DingerType} - * @param message - * 消息内容 - * @param - * 消息类型 - * @return - * 响应报文 - */ - DingerResult send(String keyword, DingerType dingerType, T message); } \ No newline at end of file diff --git a/src/main/java/com/github/jaemon/dinger/config/BeanConfiguration.java b/src/main/java/com/github/jaemon/dinger/config/BeanConfiguration.java index e1694e9..24504bc 100644 --- a/src/main/java/com/github/jaemon/dinger/config/BeanConfiguration.java +++ b/src/main/java/com/github/jaemon/dinger/config/BeanConfiguration.java @@ -15,9 +15,8 @@ */ package com.github.jaemon.dinger.config; -import com.github.jaemon.dinger.sign.DingTalkSignAlgorithm; -import com.github.jaemon.dinger.sign.DingerSignAlgorithm; -import com.dingerframework.support.*; +import com.github.jaemon.dinger.support.sign.DingTalkSignAlgorithm; +import com.github.jaemon.dinger.support.sign.DingerSignAlgorithm; import com.github.jaemon.dinger.multi.MultiDingerAlgorithmInjectRegister; import com.github.jaemon.dinger.support.*; import com.github.jaemon.dinger.support.client.DingerHttpClient; @@ -106,17 +105,6 @@ public DingerExceptionCallback dingerExceptionCallback() { return new DefaultDingerExceptionCallback(); } - /** - * 自定义监控事件 - * - * @return notification instance - */ - @Bean - @ConditionalOnMissingBean(MonitorEventNotification.class) - public MonitorEventNotification monitorEventNotification() { - return new DefaultApplicationEventNotification(); - } - @Bean public static MultiDingerAlgorithmInjectRegister multiDingerAlgorithmInjectRegister() { return new MultiDingerAlgorithmInjectRegister(); diff --git a/src/main/java/com/github/jaemon/dinger/config/DingerConfiguration.java b/src/main/java/com/github/jaemon/dinger/config/DingerConfiguration.java index d0aac00..ce1bece 100644 --- a/src/main/java/com/github/jaemon/dinger/config/DingerConfiguration.java +++ b/src/main/java/com/github/jaemon/dinger/config/DingerConfiguration.java @@ -15,12 +15,11 @@ */ package com.github.jaemon.dinger.config; -import com.github.jaemon.dinger.DingerManagerBuilder; -import com.github.jaemon.dinger.DingerRobot; +import com.github.jaemon.dinger.core.DingerManagerBuilder; +import com.github.jaemon.dinger.core.DingerRobot; import com.github.jaemon.dinger.core.DingerConfigurerAdapter; import com.github.jaemon.dinger.core.entity.DingerProperties; import com.github.jaemon.dinger.exception.ConfigurationException; -import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -44,24 +43,24 @@ public class DingerConfiguration { @Bean @ConditionalOnMissingBean(DingerConfigurerAdapter.class) - public DingerConfigurerAdapter dingTalkConfigurerAdapter() { + public DingerConfigurerAdapter dingerConfigurerAdapter() { return new DingerConfigurerAdapter(); } @Bean - public DingerManagerBuilder dingTalkManagerBuilder() { + public DingerManagerBuilder dingerManagerBuilder() { return new DingerManagerBuilder(); } @Bean - public DingerRobot dingerSender(DingerConfigurerAdapter dingTalkConfigurerAdapter, DingerManagerBuilder dingTalkManagerBuilder, ObjectMapper objectMapper){ + public DingerRobot dingerSender(DingerConfigurerAdapter dingerConfigurerAdapter, DingerManagerBuilder dingerManagerBuilder){ try { - dingTalkConfigurerAdapter.configure(dingTalkManagerBuilder); + dingerConfigurerAdapter.configure(dingerManagerBuilder); } catch (Exception ex) { throw new ConfigurationException(ex); } - return new DingerRobot(dingerProperties, dingTalkManagerBuilder, objectMapper); + return new DingerRobot(dingerProperties, dingerManagerBuilder); } } \ No newline at end of file diff --git a/src/main/java/com/github/jaemon/dinger/config/DingerThreadPoolConfig.java b/src/main/java/com/github/jaemon/dinger/config/DingerThreadPoolConfig.java index 1101a55..bc83aca 100644 --- a/src/main/java/com/github/jaemon/dinger/config/DingerThreadPoolConfig.java +++ b/src/main/java/com/github/jaemon/dinger/config/DingerThreadPoolConfig.java @@ -15,9 +15,8 @@ */ package com.github.jaemon.dinger.config; -import com.github.jaemon.dinger.DingerRobot; +import com.github.jaemon.dinger.core.DingerRobot; import com.github.jaemon.dinger.constant.DingerConstant; -import com.github.jaemon.dinger.entity.DkThreadPoolProperties; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -45,23 +44,23 @@ @ConditionalOnBean(DingerRobot.class) //@Conditional(AsyncCondition.class) @ConditionalOnMissingBean(name = DingerConstant.DINGER_EXECUTOR) -@EnableConfigurationProperties({DkThreadPoolProperties.class}) +@EnableConfigurationProperties({DingerThreadPoolProperties.class}) public class DingerThreadPoolConfig { @Bean(name = DingerConstant.DINGER_EXECUTOR) - public Executor dingTalkExecutor(DkThreadPoolProperties threadPoolProperties) { + public Executor dingTalkExecutor(DingerThreadPoolProperties dingerThreadPoolProperties) { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); // 核心线程数 - executor.setCorePoolSize(threadPoolProperties.getCoreSize()); + executor.setCorePoolSize(dingerThreadPoolProperties.getCoreSize()); // 最大线程数 - executor.setMaxPoolSize(threadPoolProperties.getMaxSize()); + executor.setMaxPoolSize(dingerThreadPoolProperties.getMaxSize()); // 线程最大空闲时间 - executor.setKeepAliveSeconds(threadPoolProperties.getKeepAliveSeconds()); + executor.setKeepAliveSeconds(dingerThreadPoolProperties.getKeepAliveSeconds()); // 队列大小 - executor.setQueueCapacity(threadPoolProperties.getQueueCapacity()); + executor.setQueueCapacity(dingerThreadPoolProperties.getQueueCapacity()); // 指定用于新创建的线程名称的前缀 - executor.setThreadNamePrefix(threadPoolProperties.getThreadNamePrefix()); + executor.setThreadNamePrefix(dingerThreadPoolProperties.getThreadNamePrefix()); // 使用自定义拒绝策略, 直接抛出异常 executor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy()); diff --git a/src/main/java/com/github/jaemon/dinger/entity/DkThreadPoolProperties.java b/src/main/java/com/github/jaemon/dinger/config/DingerThreadPoolProperties.java similarity index 96% rename from src/main/java/com/github/jaemon/dinger/entity/DkThreadPoolProperties.java rename to src/main/java/com/github/jaemon/dinger/config/DingerThreadPoolProperties.java index bc02a3f..591aa35 100644 --- a/src/main/java/com/github/jaemon/dinger/entity/DkThreadPoolProperties.java +++ b/src/main/java/com/github/jaemon/dinger/config/DingerThreadPoolProperties.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.github.jaemon.dinger.entity; +package com.github.jaemon.dinger.config; import com.github.jaemon.dinger.constant.DingerConstant; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -25,7 +25,7 @@ * @since 1.0 */ @ConfigurationProperties(prefix = DingerConstant.DINGER_PROPERTIES_PREFIX + "executor-pool") -public class DkThreadPoolProperties { +public class DingerThreadPoolProperties { private static final int DEFAULT_CORE_SIZE = Runtime.getRuntime().availableProcessors() + 1; /** * 线程池维护线程的最小数量 diff --git a/src/main/java/com/github/jaemon/dinger/constant/DingerConstant.java b/src/main/java/com/github/jaemon/dinger/constant/DingerConstant.java index 80f1878..504d129 100644 --- a/src/main/java/com/github/jaemon/dinger/constant/DingerConstant.java +++ b/src/main/java/com/github/jaemon/dinger/constant/DingerConstant.java @@ -45,10 +45,6 @@ public interface DingerConstant { /** 自定义restTemplate名称 */ String DINGER_REST_TEMPLATE = "dingerRestTemplate"; - String SUCCESS_KEYWORD = "_SUCCESS"; - String FAILED_KEYWORD = "_FAILED"; - String EXIT_KEYWORD = "_EXIT"; - String NEW_LINE = "\r\n"; String SPOT_SEPERATOR = "."; diff --git a/src/main/java/com/github/jaemon/dinger/core/AbstractDingerDefinitionResolver.java b/src/main/java/com/github/jaemon/dinger/core/AbstractDingerDefinitionResolver.java index ccd0523..f1e4869 100644 --- a/src/main/java/com/github/jaemon/dinger/core/AbstractDingerDefinitionResolver.java +++ b/src/main/java/com/github/jaemon/dinger/core/AbstractDingerDefinitionResolver.java @@ -19,13 +19,10 @@ import com.github.jaemon.dinger.core.annatations.DingerScan; import com.github.jaemon.dinger.core.entity.enums.DingerDefinitionType; import com.github.jaemon.dinger.core.entity.enums.DingerType; -import com.github.jaemon.dinger.entity.enums.ExceptionEnum; +import com.github.jaemon.dinger.core.entity.enums.ExceptionEnum; import com.github.jaemon.dinger.exception.DingerException; -import com.github.jaemon.dinger.listeners.ApplicationEventTimeTable; import com.github.jaemon.dinger.listeners.DingerListenersProperty; import com.github.jaemon.dinger.utils.PackageUtils; -import com.github.jaemon.dinger.exception.DingerConfigRepeatedException; -import com.github.jaemon.dinger.exception.DingerScanRepeatedException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.io.Resource; @@ -36,12 +33,14 @@ import java.util.List; import static com.github.jaemon.dinger.core.AbstractDingerDefinitionResolver.Container.INSTANCE; +import static com.github.jaemon.dinger.core.entity.enums.ExceptionEnum.DINGER_REPEATED_EXCEPTION; +import static com.github.jaemon.dinger.core.entity.enums.ExceptionEnum.MULTI_DINGER_SCAN_ERROR; /** * AbstractDingerDefinitionResolver * * @author Jaemon - * @since 2.0 + * @since 1.0 */ public abstract class AbstractDingerDefinitionResolver extends DingerListenersProperty { @@ -129,7 +128,7 @@ protected List> dingerAnnotationResolver() throws Exception { DingerScan dingerScan = null; List> dingerClasses = new ArrayList<>(); // 获取启动类下所有Dinger标注的类信息 - for (Class primarySource : ApplicationEventTimeTable.primarySources()) { + for (Class primarySource : DingerListenersProperty.primarySources()) { if (debugEnabled) { log.debug("ready to analysis primarySource[{}].", primarySource.getName()); } @@ -139,7 +138,7 @@ protected List> dingerAnnotationResolver() throws Exception { if (dingerScan == null) { dingerScan = primarySource.getAnnotation(DingerScan.class); } else { - throw new DingerScanRepeatedException(); + throw new DingerException(MULTI_DINGER_SCAN_ERROR); } } } @@ -201,7 +200,7 @@ void registerDingerDefinition( Class dingerDefinitionGeneratorClass = dingerDefinitionGeneratorMap.get(key); if (dingerDefinitionGeneratorClass == null) { - throw new DingerException(key + "无效.", ExceptionEnum.REGISTER_DINGERDEFINITION_ERROR); + throw new DingerException(ExceptionEnum.DINGERDEFINITIONTYPE_UNDEFINED_KEY, key); } DingerDefinitionGenerator dingerDefinitionGenerator = DingerDefinitionGeneratorFactory.get( @@ -218,7 +217,7 @@ void registerDingerDefinition( continue; } if (INSTANCE.contains(keyName)) { - throw new DingerConfigRepeatedException("Dinger[" + keyName + "]消息对象重复定义了."); + throw new DingerException(DINGER_REPEATED_EXCEPTION, keyName); } // DingerConfig Priority: `@DingerText | @DingerMarkdown | XML` > `@DingerConfiguration` > `***.yml | ***.properties` diff --git a/src/main/java/com/github/jaemon/dinger/AbstractDingerSender.java b/src/main/java/com/github/jaemon/dinger/core/AbstractDingerSender.java similarity index 71% rename from src/main/java/com/github/jaemon/dinger/AbstractDingerSender.java rename to src/main/java/com/github/jaemon/dinger/core/AbstractDingerSender.java index b424eda..53d1377 100644 --- a/src/main/java/com/github/jaemon/dinger/AbstractDingerSender.java +++ b/src/main/java/com/github/jaemon/dinger/core/AbstractDingerSender.java @@ -13,14 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.github.jaemon.dinger; +package com.github.jaemon.dinger.core; -import com.github.jaemon.dinger.core.DingerHelper; +import com.github.jaemon.dinger.DingerSender; import com.github.jaemon.dinger.core.entity.DingerProperties; import com.github.jaemon.dinger.core.entity.enums.MessageSubType; import com.github.jaemon.dinger.exception.DingerException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.github.jaemon.dinger.entity.DingerCallback; +import com.github.jaemon.dinger.core.entity.DingerCallback; import com.github.jaemon.dinger.support.CustomMessage; /** @@ -33,14 +32,12 @@ public abstract class AbstractDingerSender extends DingerHelper implements DingerSender { - DingerProperties dingerProperties; - DingerManagerBuilder dingTalkManagerBuilder; - ObjectMapper objectMapper; + protected DingerProperties dingerProperties; + protected DingerManagerBuilder dingTalkManagerBuilder; - public AbstractDingerSender(DingerProperties dingerProperties, DingerManagerBuilder dingTalkManagerBuilder, ObjectMapper objectMapper) { + public AbstractDingerSender(DingerProperties dingerProperties, DingerManagerBuilder dingTalkManagerBuilder) { this.dingerProperties = dingerProperties; this.dingTalkManagerBuilder = dingTalkManagerBuilder; - this.objectMapper = objectMapper; } /** @@ -51,19 +48,24 @@ public AbstractDingerSender(DingerProperties dingerProperties, DingerManagerBuil * @return * 消息生成器 */ - CustomMessage customMessage(MessageSubType messageSubType) { + protected CustomMessage customMessage(MessageSubType messageSubType) { return messageSubType == MessageSubType.TEXT ? dingTalkManagerBuilder.textMessage : dingTalkManagerBuilder.markDownMessage; } /** * 异常回调 * - * @param keyword keyword - * @param message message - * @param ex ex + * @param dingerId + * dingerId + * @param message + * message + * @param ex + * ex + * @param + * T */ - void exceptionCallback(String dingerId, String keyword, T message, DingerException ex) { - DingerCallback dkExCallable = new DingerCallback(dingerId, keyword, message, ex); + protected void exceptionCallback(String dingerId, T message, DingerException ex) { + DingerCallback dkExCallable = new DingerCallback(dingerId, message, ex); dingTalkManagerBuilder.dingerExceptionCallback.execute(dkExCallable); } } \ No newline at end of file diff --git a/src/main/java/com/github/jaemon/dinger/core/DefaultDingerDefinition.java b/src/main/java/com/github/jaemon/dinger/core/DefaultDingerDefinition.java index f81d8ba..65fa430 100644 --- a/src/main/java/com/github/jaemon/dinger/core/DefaultDingerDefinition.java +++ b/src/main/java/com/github/jaemon/dinger/core/DefaultDingerDefinition.java @@ -25,7 +25,7 @@ * DefaultDingerDefinition * * @author Jaemon - * @since 2.0 + * @since 1.0 */ public class DefaultDingerDefinition implements DingerDefinition { private String dingerName; diff --git a/src/main/java/com/github/jaemon/dinger/core/DingerConfig.java b/src/main/java/com/github/jaemon/dinger/core/DingerConfig.java index d97ce55..9670b64 100644 --- a/src/main/java/com/github/jaemon/dinger/core/DingerConfig.java +++ b/src/main/java/com/github/jaemon/dinger/core/DingerConfig.java @@ -23,17 +23,17 @@ * DingerConfig * * @author Jaemon - * @since 2.0 + * @since 1.0 */ public class DingerConfig { /** - * dinger类型 {@link DingerType} + * dinger类型 {@link DingerType},不指定默认使用默认的 */ - private DingerType dingerType = DingerType.DINGTALK; + private DingerType dingerType; private String tokenId; /** 内部解密秘钥 */ private String decryptKey; - /** dingtalk签名秘钥 */ + /** dinger签名秘钥 */ private String secret; /** 异步执行 */ private Boolean asyncExecute; @@ -41,48 +41,98 @@ public class DingerConfig { protected DingerConfig() { } - public DingerConfig(String tokenId) { + private DingerConfig(String tokenId) { this.tokenId = tokenId; } - public DingerConfig(DingerType dingerType, String tokenId) { + private DingerConfig(DingerType dingerType, String tokenId) { this(tokenId); this.dingerType = dingerType; } - public DingerConfig(String tokenId, String secret) { + private DingerConfig(String tokenId, String secret) { this.tokenId = tokenId; this.secret = secret; } - public DingerConfig(DingerType dingerType, String tokenId, String secret) { + private DingerConfig(DingerType dingerType, String tokenId, String secret) { this(tokenId, secret); this.dingerType = dingerType; } - public DingerConfig(String tokenId, String secret, String decryptKey) { + private DingerConfig(String tokenId, boolean async) { + this.tokenId = tokenId; + this.asyncExecute = async; + } + + private DingerConfig(DingerType dingerType, String tokenId, boolean async) { + this(tokenId, async); + this.dingerType = dingerType; + } + + private DingerConfig(String tokenId, String secret, String decryptKey) { this.tokenId = tokenId; this.decryptKey = decryptKey; this.secret = secret; } - public DingerConfig(DingerType dingerType, String tokenId, String secret, String decryptKey) { + private DingerConfig(DingerType dingerType, String tokenId, String secret, String decryptKey) { this(tokenId, secret, decryptKey); this.dingerType = dingerType; } - public DingerConfig(String tokenId, String secret, String decryptKey, boolean asyncExecute) { + private DingerConfig(String tokenId, String secret, String decryptKey, boolean asyncExecute) { this.tokenId = tokenId; this.decryptKey = decryptKey; this.secret = secret; this.asyncExecute = asyncExecute; } - public DingerConfig(DingerType dingerType, String tokenId, String secret, String decryptKey, boolean asyncExecute) { + private DingerConfig(DingerType dingerType, String tokenId, String secret, String decryptKey, boolean asyncExecute) { this(tokenId, secret, decryptKey, asyncExecute); this.dingerType = dingerType; } + public static DingerConfig instance(String tokenId) { + return new DingerConfig(tokenId); + } + + public static DingerConfig instance(DingerType dingerType, String tokenId) { + return new DingerConfig(dingerType, tokenId); + } + + public static DingerConfig instance(String tokenId, String secret) { + return new DingerConfig(tokenId, secret); + } + + public static DingerConfig instance(DingerType dingerType, String tokenId, String secret) { + return new DingerConfig(dingerType, tokenId, secret); + } + + public static DingerConfig instance(String tokenId, boolean asyncExecute) { + return new DingerConfig(tokenId, asyncExecute); + } + + public static DingerConfig instance(DingerType dingerType, String tokenId, boolean asyncExecute) { + return new DingerConfig(dingerType, tokenId, asyncExecute); + } + + public static DingerConfig instance(String tokenId, String secret, String decryptKey) { + return new DingerConfig(tokenId, secret, decryptKey); + } + + public static DingerConfig instance(DingerType dingerType, String tokenId, String secret, String decryptKey) { + return new DingerConfig(dingerType, tokenId, secret, decryptKey); + } + + public static DingerConfig instance(String tokenId, String secret, String decryptKey, boolean asyncExecute) { + return new DingerConfig(tokenId, secret, decryptKey, asyncExecute); + } + + public static DingerConfig instance(DingerType dingerType, String tokenId, String secret, String decryptKey, boolean asyncExecute) { + return new DingerConfig(dingerType, tokenId, secret, decryptKey, asyncExecute); + } + /** * do check dinger config */ diff --git a/src/main/java/com/github/jaemon/dinger/core/DingerConfigurerAdapter.java b/src/main/java/com/github/jaemon/dinger/core/DingerConfigurerAdapter.java index ba4b3b8..b8fe7c6 100644 --- a/src/main/java/com/github/jaemon/dinger/core/DingerConfigurerAdapter.java +++ b/src/main/java/com/github/jaemon/dinger/core/DingerConfigurerAdapter.java @@ -15,8 +15,6 @@ */ package com.github.jaemon.dinger.core; -import com.github.jaemon.dinger.DingerManagerBuilder; - /** * DingTalk Configurer Adapter * diff --git a/src/main/java/com/github/jaemon/dinger/core/DingerDefinition.java b/src/main/java/com/github/jaemon/dinger/core/DingerDefinition.java index 77ca374..62237ec 100644 --- a/src/main/java/com/github/jaemon/dinger/core/DingerDefinition.java +++ b/src/main/java/com/github/jaemon/dinger/core/DingerDefinition.java @@ -25,7 +25,7 @@ * DingerDefinition * * @author Jaemon - * @since 2.0 + * @since 1.0 */ public interface DingerDefinition { diff --git a/src/main/java/com/github/jaemon/dinger/core/DingerDefinitionGenerator.java b/src/main/java/com/github/jaemon/dinger/core/DingerDefinitionGenerator.java index a2e3f26..4b424c2 100644 --- a/src/main/java/com/github/jaemon/dinger/core/DingerDefinitionGenerator.java +++ b/src/main/java/com/github/jaemon/dinger/core/DingerDefinitionGenerator.java @@ -20,7 +20,7 @@ * Diner消息体定义生成 * * @author Jaemon - * @since 4.0 + * @since 1.0 */ public abstract class DingerDefinitionGenerator { diff --git a/src/main/java/com/github/jaemon/dinger/core/DingerDefinitionGeneratorContext.java b/src/main/java/com/github/jaemon/dinger/core/DingerDefinitionGeneratorContext.java index 68ab499..e85352a 100644 --- a/src/main/java/com/github/jaemon/dinger/core/DingerDefinitionGeneratorContext.java +++ b/src/main/java/com/github/jaemon/dinger/core/DingerDefinitionGeneratorContext.java @@ -19,7 +19,7 @@ * DingerDefinitionGeneratorContext * * @author Jaemon - * @since 4.0 + * @since 1.0 */ public class DingerDefinitionGeneratorContext { private String keyName; diff --git a/src/main/java/com/github/jaemon/dinger/core/DingerDefinitionGeneratorFactory.java b/src/main/java/com/github/jaemon/dinger/core/DingerDefinitionGeneratorFactory.java index 18245ed..407ee00 100644 --- a/src/main/java/com/github/jaemon/dinger/core/DingerDefinitionGeneratorFactory.java +++ b/src/main/java/com/github/jaemon/dinger/core/DingerDefinitionGeneratorFactory.java @@ -20,13 +20,13 @@ import java.util.HashMap; import java.util.Map; -import static com.github.jaemon.dinger.entity.enums.ExceptionEnum.DINGERDEFINITION_ERROR; +import static com.github.jaemon.dinger.core.entity.enums.ExceptionEnum.DINGERDEFINITION_ERROR; /** * Dinger Definition工厂类 * * @author Jaemon - * @since 4.0 + * @since 1.0 */ public class DingerDefinitionGeneratorFactory { /** dingerDefinition生成器 */ diff --git a/src/main/java/com/github/jaemon/dinger/core/DingerDefinitionHandler.java b/src/main/java/com/github/jaemon/dinger/core/DingerDefinitionHandler.java index 186dcb6..f40a1fc 100644 --- a/src/main/java/com/github/jaemon/dinger/core/DingerDefinitionHandler.java +++ b/src/main/java/com/github/jaemon/dinger/core/DingerDefinitionHandler.java @@ -16,11 +16,9 @@ package com.github.jaemon.dinger.core; import com.github.jaemon.dinger.core.annatations.DingerTokenId; -import com.dingerframework.core.entity.enums.*; import com.github.jaemon.dinger.core.annatations.DingerMarkdown; import com.github.jaemon.dinger.core.annatations.DingerText; import com.github.jaemon.dinger.core.entity.MsgType; -import com.dingerframework.core.entity.xml.*; import com.github.jaemon.dinger.core.entity.enums.*; import com.github.jaemon.dinger.core.entity.xml.*; import com.github.jaemon.dinger.exception.DingerException; @@ -33,13 +31,13 @@ import java.util.Optional; import java.util.stream.Collectors; -import static com.github.jaemon.dinger.entity.enums.ExceptionEnum.DINGERDEFINITIONTYPE_ERROR; +import static com.github.jaemon.dinger.core.entity.enums.ExceptionEnum.DINGERDEFINITIONTYPE_ERROR; /** * DefinitionGenerator * * @author Jaemon - * @since 4.0 + * @since 1.0 */ public class DingerDefinitionHandler { private static final Logger log = LoggerFactory.getLogger(DingerDefinitionHandler.class); diff --git a/src/main/java/com/github/jaemon/dinger/core/DingerDefinitionResolver.java b/src/main/java/com/github/jaemon/dinger/core/DingerDefinitionResolver.java index 6bb1249..e5afa59 100644 --- a/src/main/java/com/github/jaemon/dinger/core/DingerDefinitionResolver.java +++ b/src/main/java/com/github/jaemon/dinger/core/DingerDefinitionResolver.java @@ -40,13 +40,13 @@ import java.util.*; import static com.github.jaemon.dinger.constant.DingerConstant.SPOT_SEPERATOR; -import static com.github.jaemon.dinger.entity.enums.ExceptionEnum.DINER_XML_ANALYSIS_EXCEPTION; +import static com.github.jaemon.dinger.core.entity.enums.ExceptionEnum.*; /** * DingerDefinitionResolver * * @author Jaemon - * @since 2.0 + * @since 1.0 */ public class DingerDefinitionResolver extends AbstractDingerDefinitionResolver { private static final Logger log = LoggerFactory.getLogger(DingerDefinitionResolver.class); @@ -99,7 +99,7 @@ void analysisDingerXml(Resource[] resources) throws Exception { String namespace = dingerBean.getNamespace(); Class dingerClass = Class.forName(namespace); if (dingerClass == null) { - throw new DingerException(DINER_XML_ANALYSIS_EXCEPTION); + throw new DingerException(namespace, DINER_XML_NAMESPACE_INVALID); } DingerConfig dingerConfiguration = dingerConfiguration(dingerClass); @@ -109,7 +109,7 @@ void analysisDingerXml(Resource[] resources) throws Exception { String dingerName = namespace + SPOT_SEPERATOR + message.getIdentityId(); String messageSubType = message.getDingerType(); if (!MessageSubType.contains(messageSubType)) { - throw new DingerException(dingerName + "中定义了无效的messageType" + messageSubType, DINER_XML_ANALYSIS_EXCEPTION); + throw new DingerException(dingerName + "-" + messageSubType, DINER_XML_MSGTYPE_INVALID); } String dingerDefinitionKey = MessageMainType.XML + SPOT_SEPERATOR + message.getDingerType(); diff --git a/src/main/java/com/github/jaemon/dinger/core/DingerHandleProxy.java b/src/main/java/com/github/jaemon/dinger/core/DingerHandleProxy.java index 3470def..f2225dc 100644 --- a/src/main/java/com/github/jaemon/dinger/core/DingerHandleProxy.java +++ b/src/main/java/com/github/jaemon/dinger/core/DingerHandleProxy.java @@ -15,12 +15,11 @@ */ package com.github.jaemon.dinger.core; -import com.github.jaemon.dinger.DingerSender; import com.github.jaemon.dinger.core.annatations.DingerClose; import com.github.jaemon.dinger.core.entity.DingerProperties; import com.github.jaemon.dinger.core.entity.MsgType; import com.github.jaemon.dinger.core.entity.enums.DingerType; -import com.github.jaemon.dinger.entity.DingerResult; +import com.github.jaemon.dinger.core.entity.DingerResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,14 +33,14 @@ * Dinger Handle Proxy * * @author Jaemon - * @since 2.0 + * @since 1.0 */ public class DingerHandleProxy extends DingerMessageHandler implements InvocationHandler { private static final Logger log = LoggerFactory.getLogger(DingerHandleProxy.class); private static final String DEFAULT_STRING_METHOD = "java.lang.Object.toString"; - public DingerHandleProxy(DingerSender dingerSender, DingerProperties dingerProperties) { - this.dingerSender = dingerSender; + public DingerHandleProxy(DingerRobot dingerRobot, DingerProperties dingerProperties) { + this.dingerRobot = dingerRobot; this.dingerProperties = dingerProperties; } @@ -68,7 +67,7 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl try { // method params map - Map params = paramsHandle(method.getParameters(), args); + Map params = paramsHandler(method.getParameters(), args); DingerType useDinger = dingerType(method); DingerDefinition dingerDefinition = dingerDefinition( @@ -80,17 +79,10 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl MsgType message = transfer(dingerDefinition, params); - // when keyword is null, use methodName + timestamps - String keyword = params.getOrDefault( - KEYWORD, - keyName + CONNECTOR + System.currentTimeMillis() - ).toString(); - DingerResult dingerResult = dingerSender.send( - keyword, message - ); + DingerResponse dingerResponse = dingerRobot.send(message); // return... - return resultHandle(method.getReturnType(), dingerResult); + return resultHandler(method.getReturnType(), dingerResponse); } finally { DingerHelper.clearDinger(); } diff --git a/src/main/java/com/github/jaemon/dinger/core/DingerHelper.java b/src/main/java/com/github/jaemon/dinger/core/DingerHelper.java index e87c70d..0c4ad59 100644 --- a/src/main/java/com/github/jaemon/dinger/core/DingerHelper.java +++ b/src/main/java/com/github/jaemon/dinger/core/DingerHelper.java @@ -21,7 +21,7 @@ * DingerHelper * * @author Jaemon - * @since 2.0 + * @since 1.0 */ public abstract class DingerHelper { protected static final ThreadLocal LOCAL_DINGER = new ThreadLocal<>(); @@ -31,18 +31,22 @@ public abstract class DingerHelper { * * @param dingerConfig * dingerConfig {@link DingerConfig} + * @return + * dingerConfig {@link DingerConfig} */ - public static void assignDinger(DingerConfig dingerConfig) { + public static DingerConfig assignDinger(DingerConfig dingerConfig) { dingerConfig.check(); if (dingerConfig.checkEmpty()) { // use default - return; + return null; } setLocalDinger(dingerConfig); + + return dingerConfig; } /** - * assignDinger for dingtalk + * assignDinger for dingtalk(使用原有dingerType) * * @param tokenId * dingtalk tokenId @@ -50,7 +54,8 @@ public static void assignDinger(DingerConfig dingerConfig) { * dingerConfig {@link DingerConfig} */ public static DingerConfig assignDinger(String tokenId) { - return assignDinger(tokenId, false); + DingerConfig dingerConfig = DingerConfig.instance(tokenId); + return assignDinger(dingerConfig); } /** @@ -64,7 +69,8 @@ public static DingerConfig assignDinger(String tokenId) { * dingerConfig {@link DingerConfig} */ public static DingerConfig assignDinger(DingerType dingerType, String tokenId) { - return assignDinger(dingerType, tokenId, false); + DingerConfig dingerConfig = DingerConfig.instance(dingerType, tokenId); + return assignDinger(dingerConfig); } /** @@ -78,7 +84,8 @@ public static DingerConfig assignDinger(DingerType dingerType, String tokenId) { * dingerConfig {@link DingerConfig} */ public static DingerConfig assignDinger(String tokenId, boolean asyncExecute) { - return assignDinger(tokenId, null, asyncExecute); + DingerConfig dingerConfig = DingerConfig.instance(tokenId, asyncExecute); + return assignDinger(dingerConfig); } /** @@ -94,7 +101,8 @@ public static DingerConfig assignDinger(String tokenId, boolean asyncExecute) { * dingerConfig {@link DingerConfig} */ public static DingerConfig assignDinger(DingerType dingerType, String tokenId, boolean asyncExecute) { - return assignDinger(dingerType, tokenId, null, asyncExecute); + DingerConfig dingerConfig = DingerConfig.instance(dingerType, tokenId, asyncExecute); + return assignDinger(dingerConfig); } /** @@ -109,7 +117,26 @@ public static DingerConfig assignDinger(DingerType dingerType, String tokenId, b * dingerConfig {@link DingerConfig} */ public static DingerConfig assignDinger(String tokenId, String secret) { - return assignDinger(DingerType.DINGTALK, tokenId, null, secret, false); + DingerConfig dingerConfig = DingerConfig.instance(tokenId, secret); + return assignDinger(dingerConfig); + } + + /** + * assignDinger for dingtalk + * + * @param dingerType + * dingerType + * @param tokenId + * dingtalk tokenId + * @param secret + * dingtalk secret + * + * @return + * dingerConfig {@link DingerConfig} + */ + public static DingerConfig assignDinger(DingerType dingerType, String tokenId, String secret) { + DingerConfig dingerConfig = DingerConfig.instance(dingerType, tokenId, secret); + return assignDinger(dingerConfig); } /** @@ -125,7 +152,9 @@ public static DingerConfig assignDinger(String tokenId, String secret) { * dingerConfig {@link DingerConfig} */ public static DingerConfig assignDinger(String tokenId, String decryptKey, boolean asyncExecute) { - return assignDinger(DingerType.DINGTALK, tokenId, decryptKey, null, asyncExecute); + DingerConfig dingerConfig = DingerConfig.instance(tokenId, asyncExecute); + dingerConfig.setDecryptKey(decryptKey); + return assignDinger(dingerConfig); } /** @@ -143,7 +172,10 @@ public static DingerConfig assignDinger(String tokenId, String decryptKey, boole * dingerConfig {@link DingerConfig} */ public static DingerConfig assignDinger(DingerType dingerType, String tokenId, String decryptKey, boolean asyncExecute) { - return assignDinger(dingerType, tokenId, decryptKey, null, asyncExecute); + DingerConfig dingerConfig = DingerConfig.instance(dingerType, tokenId); + dingerConfig.setDecryptKey(decryptKey); + dingerConfig.setAsyncExecute(asyncExecute); + return assignDinger(dingerConfig); } /** @@ -159,7 +191,27 @@ public static DingerConfig assignDinger(DingerType dingerType, String tokenId, S * dingerConfig {@link DingerConfig} */ public static DingerConfig assignDinger(String tokenId, String decryptKey, String secret) { - return assignDinger(DingerType.DINGTALK, tokenId, decryptKey, secret, false); + DingerConfig dingerConfig = DingerConfig.instance(tokenId, secret, decryptKey); + return assignDinger(dingerConfig); + } + + /** + * assignDinger for dingtalk + * + * @param dingerType + * dingerType + * @param tokenId + * dingtalk tokenId + * @param decryptKey + * tokenId decrypt key + * @param secret + * dingtalk secret + * @return + * dingerConfig {@link DingerConfig} + */ + public static DingerConfig assignDinger(DingerType dingerType, String tokenId, String decryptKey, String secret) { + DingerConfig dingerConfig = DingerConfig.instance(dingerType, tokenId, secret, decryptKey); + return assignDinger(dingerConfig); } /** @@ -179,17 +231,10 @@ public static DingerConfig assignDinger(String tokenId, String decryptKey, Strin * dingerConfig {@link DingerConfig} */ public static DingerConfig assignDinger(DingerType dingerType, String tokenId, String decryptKey, String secret, boolean asyncExecute) { - DingerConfig dingerConfig = new DingerConfig(); - if (dingerType != null) { - dingerConfig.setDingerType(dingerType); - } - dingerConfig.setTokenId(tokenId); - dingerConfig.setDecryptKey(decryptKey); - dingerConfig.setSecret(secret); - dingerConfig.setAsyncExecute(asyncExecute); - - assignDinger(dingerConfig); - return dingerConfig; + DingerConfig dingerConfig = DingerConfig.instance( + dingerType, tokenId, decryptKey, secret, asyncExecute + ); + return assignDinger(dingerConfig); } diff --git a/src/main/java/com/github/jaemon/dinger/DingerManagerBuilder.java b/src/main/java/com/github/jaemon/dinger/core/DingerManagerBuilder.java similarity index 97% rename from src/main/java/com/github/jaemon/dinger/DingerManagerBuilder.java rename to src/main/java/com/github/jaemon/dinger/core/DingerManagerBuilder.java index 531a017..080aa87 100644 --- a/src/main/java/com/github/jaemon/dinger/DingerManagerBuilder.java +++ b/src/main/java/com/github/jaemon/dinger/core/DingerManagerBuilder.java @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.github.jaemon.dinger; +package com.github.jaemon.dinger.core; import com.github.jaemon.dinger.core.entity.enums.MessageSubType; -import com.github.jaemon.dinger.sign.DingerSignAlgorithm; +import com.github.jaemon.dinger.support.sign.DingerSignAlgorithm; import com.github.jaemon.dinger.support.DingerExceptionCallback; import com.github.jaemon.dinger.support.CustomMessage; import com.github.jaemon.dinger.support.DingerAsyncCallback; diff --git a/src/main/java/com/github/jaemon/dinger/core/DingerMessageHandler.java b/src/main/java/com/github/jaemon/dinger/core/DingerMessageHandler.java index 3f33aa9..fb10d37 100644 --- a/src/main/java/com/github/jaemon/dinger/core/DingerMessageHandler.java +++ b/src/main/java/com/github/jaemon/dinger/core/DingerMessageHandler.java @@ -15,13 +15,11 @@ */ package com.github.jaemon.dinger.core; -import com.github.jaemon.dinger.DingerSender; import com.github.jaemon.dinger.core.annatations.Dinger; -import com.github.jaemon.dinger.core.annatations.Keyword; import com.github.jaemon.dinger.core.entity.DingerProperties; import com.github.jaemon.dinger.core.entity.MsgType; import com.github.jaemon.dinger.core.entity.enums.DingerType; -import com.github.jaemon.dinger.entity.DingerResult; +import com.github.jaemon.dinger.core.entity.DingerResponse; import com.github.jaemon.dinger.listeners.DingerXmlPreparedEvent; import com.github.jaemon.dinger.multi.MultiDingerConfigContainer; import com.github.jaemon.dinger.multi.MultiDingerProperty; @@ -45,47 +43,35 @@ * DingerMessageHandler * * @author Jaemon - * @since 2.0 + * @since 1.0 */ public class DingerMessageHandler extends MultiDingerProperty - implements ParamHandle, MessageTransfer, ResultHandle { + implements ParamHandler, MessageTransfer, ResultHandler { private static final Logger log = LoggerFactory.getLogger(DingerMessageHandler.class); - protected static final String KEYWORD = "DINGTALK_DINGER_METHOD_SENDER_KEYWORD"; - protected static final String CONNECTOR = "_"; - protected DingerSender dingerSender; + protected DingerRobot dingerRobot; protected DingerProperties dingerProperties; @Override - public Map paramsHandle(Parameter[] parameters, Object[] values) { + public Map paramsHandler(Parameter[] parameters, Object[] values) { Map params = new HashMap<>(); if (parameters.length == 0) { return params; } - int keyWordIndex = -1; - String keywordValue = null; for (int i = 0; i < parameters.length; i++) { Parameter parameter = parameters[i]; String paramName = parameter.getName(); com.github.jaemon.dinger.core.annatations.Parameter[] panno = parameter.getDeclaredAnnotationsByType(com.github.jaemon.dinger.core.annatations.Parameter.class); - Keyword[] kanno = parameter.getDeclaredAnnotationsByType(Keyword.class); +// Keyword[] kanno = parameter.getDeclaredAnnotationsByType(Keyword.class); if (panno != null && panno.length > 0) { paramName = panno[0].value(); - } else if (kanno != null && kanno.length > 0) { - keyWordIndex = i; - keywordValue = values[i].toString(); - continue; } params.put(paramName, values[i]); } - if (keyWordIndex != -1) { - params.put(KEYWORD, keywordValue); - } - return params; } @@ -99,12 +85,12 @@ public MsgType transfer(DingerDefinition dingerDefinition, Map p @Override - public Object resultHandle(Class resultType, DingerResult dingerResult) { + public Object resultHandler(Class resultType, DingerResponse dingerResponse) { String name = resultType.getName(); if (String.class.getName().equals(name)) { - return Optional.ofNullable(dingerResult).map(e -> e.getData()).orElse(null); - } else if (DingerResult.class.getName().equals(name)) { - return dingerResult; + return Optional.ofNullable(dingerResponse).map(e -> e.getData()).orElse(null); + } else if (DingerResponse.class.getName().equals(name)) { + return dingerResponse; } return null; } @@ -160,20 +146,24 @@ DingerType dingerType(Method method) { /** * 获取Dinger定义 * - * @param defaultDinger - * 代理方法默认Dinger + *
+     *     优先级: local(dinger为空使用默认 {@link DingerMessageHandler#dingerType}) > multi > default
+     * 
+ * + * @param useDinger + * 代理方法使用的Dinger * @param keyName * keyName * @return * dingerDefinition {@link DingerDefinition} */ - DingerDefinition dingerDefinition(DingerType defaultDinger, String keyName) { + DingerDefinition dingerDefinition(DingerType useDinger, String keyName) { DingerDefinition dingerDefinition; DingerConfig localDinger = DingerHelper.getLocalDinger(); // 优先使用用户设定 dingerConfig if (localDinger == null) { - keyName = defaultDinger + SPOT_SEPERATOR + keyName; + keyName = useDinger + SPOT_SEPERATOR + keyName; dingerDefinition = DingerXmlPreparedEvent .Container.INSTANCE.get(keyName); @@ -208,7 +198,11 @@ DingerDefinition dingerDefinition(DingerType defaultDinger, String keyName) { } } else { - keyName = localDinger.getDingerType() + SPOT_SEPERATOR + keyName; + DingerType dingerType = localDinger.getDingerType(); + if (dingerType == null) { + dingerType = useDinger; + } + keyName = dingerType + SPOT_SEPERATOR + keyName; dingerDefinition = DingerXmlPreparedEvent .Container.INSTANCE.get(keyName); diff --git a/src/main/java/com/github/jaemon/dinger/core/DingerRefresh.java b/src/main/java/com/github/jaemon/dinger/core/DingerRefresh.java index 618ed7b..9e1a756 100644 --- a/src/main/java/com/github/jaemon/dinger/core/DingerRefresh.java +++ b/src/main/java/com/github/jaemon/dinger/core/DingerRefresh.java @@ -19,7 +19,7 @@ * DingerRefresh * * @author Jaemon - * @since 3.0 + * @since 1.0 */ public class DingerRefresh { diff --git a/src/main/java/com/github/jaemon/dinger/DingerRobot.java b/src/main/java/com/github/jaemon/dinger/core/DingerRobot.java similarity index 60% rename from src/main/java/com/github/jaemon/dinger/DingerRobot.java rename to src/main/java/com/github/jaemon/dinger/core/DingerRobot.java index 80757f5..6e5cbed 100644 --- a/src/main/java/com/github/jaemon/dinger/DingerRobot.java +++ b/src/main/java/com/github/jaemon/dinger/core/DingerRobot.java @@ -13,18 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.github.jaemon.dinger; +package com.github.jaemon.dinger.core; -import com.github.jaemon.dinger.entity.DingerResult; -import com.github.jaemon.dinger.entity.SignBase; +import com.github.jaemon.dinger.core.entity.DingerRequest; +import com.github.jaemon.dinger.core.entity.DingerResponse; +import com.github.jaemon.dinger.support.sign.SignBase; import com.github.jaemon.dinger.support.client.MediaTypeEnum; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.github.jaemon.dinger.core.DingerConfig; import com.github.jaemon.dinger.core.entity.DingerProperties; import com.github.jaemon.dinger.core.entity.enums.DingerType; import com.github.jaemon.dinger.core.entity.enums.MessageSubType; -import com.github.jaemon.dinger.entity.enums.ResultCode; +import com.github.jaemon.dinger.core.entity.enums.DingerResponseCodeEnum; import com.github.jaemon.dinger.core.entity.MsgType; import com.github.jaemon.dinger.exception.AsyncCallException; import com.github.jaemon.dinger.exception.SendMsgException; @@ -45,54 +43,65 @@ */ public class DingerRobot extends AbstractDingerSender { - public DingerRobot(DingerProperties dingerProperties, DingerManagerBuilder dingTalkManagerBuilder, ObjectMapper objectMapper) { - super(dingerProperties, dingTalkManagerBuilder, objectMapper); + public DingerRobot(DingerProperties dingerProperties, DingerManagerBuilder dingTalkManagerBuilder) { + super(dingerProperties, dingTalkManagerBuilder); } @Override - public DingerResult send(MessageSubType messageSubType, String keyword, String title, String content) { - return send(dingerProperties.getDefaultDinger(), messageSubType, keyword, title, content); + public DingerResponse send(MessageSubType messageSubType, DingerRequest request) { + return send(dingerProperties.getDefaultDinger(), messageSubType, request.getTitle(), request.getContent(), request.getPhones(), request.isAtAll()); } @Override - public DingerResult send(DingerType dingerType, MessageSubType messageSubType, String keyword, String title, String content) { - return send(dingerType, messageSubType, keyword, title, content, null, false); + public DingerResponse send(DingerType dingerType, MessageSubType messageSubType, DingerRequest request) { + return send(dingerType, messageSubType, request.getTitle(), request.getContent(), request.getPhones(), request.isAtAll()); } - @Override - public DingerResult send(MessageSubType messageSubType, String keyword, String title, String content, List phones) { - return send(dingerProperties.getDefaultDinger(), messageSubType, keyword, title, content, phones); - } - - - @Override - public DingerResult send(DingerType dingerType, MessageSubType messageSubType, String keyword, String title, String content, List phones) { - return send(dingerType, messageSubType, keyword, title, content, phones, false); - } - - @Override - public DingerResult sendAll(String keyword, String title, String content) { - return sendAll(dingerProperties.getDefaultDinger(), keyword, title, content); - } + /** + * 发送预警消息到钉钉-艾特所有人 + * + *
+     *     markdown不支持艾特全部
+     * 
+ * + * @param dingerType + * Dinger类型 {@link DingerType} + * @param messageSubType + * 消息类型{@link MessageSubType} + * @param title + * 副标题 + * @param content + * 消息内容 + * @param phones + * 艾特成员 + * @param atAll + * 是否艾特所有人 + * @return + * 响应报文 + * */ + private DingerResponse send(DingerType dingerType, MessageSubType messageSubType, String title, String content, List phones, boolean atAll) { + CustomMessage customMessage = customMessage(messageSubType); + String msgContent = customMessage.message( + dingerProperties.getProjectId(), title, content, phones + ); + MsgType msgType = messageSubType.msgType( + dingerType, msgContent, title, phones, atAll + ); - @Override - public DingerResult sendAll(DingerType dingerType, String keyword, String title, String content) { - return send(dingerType, MessageSubType.MARKDOWN, keyword, title, content, null, true); + return send(msgType); } - - @Override - public DingerResult send(String keyword, T message) { - try { - return send(keyword, message.getDingerType(), objectMapper.writeValueAsString(message)); - } catch (JsonProcessingException e) { - return DingerResult.failed(ResultCode.MESSAGE_PROCESSING_FAILED, dingTalkManagerBuilder.dingerIdGenerator.dingerId()); - } - } - - @Override - public DingerResult send(String keyword, DingerType dingerType, T message) { + /** + * @param message + * 消息内容 + * @param + * T + * @return + * 响应内容 {@link DingerResponse} + */ + protected DingerResponse send(T message) { + DingerType dingerType = message.getDingerType(); String dkid = dingTalkManagerBuilder.dingerIdGenerator.dingerId(); Map dingers = dingerProperties.getDingers(); if (! @@ -101,7 +110,7 @@ public DingerResult send(String keyword, DingerType dingerType, T message) { dingers.containsKey(dingerType) ) ) { - return DingerResult.failed(ResultCode.DINGER_DISABLED, dkid); + return DingerResponse.failed(DingerResponseCodeEnum.DINGER_DISABLED, dkid); } DingerConfig localDinger = getLocalDinger(); @@ -139,59 +148,20 @@ public DingerResult send(String keyword, DingerType dingerType, T message) { ); dingTalkManagerBuilder.dingerAsyncCallback.execute(dkid, result); } catch (Exception e) { - exceptionCallback(dkid, keyword, message, new AsyncCallException(e)); + exceptionCallback(dkid, message, new AsyncCallException(e)); } }); - return DingerResult.success(dkid, dkid); + return DingerResponse.success(dkid, dkid); } String response = dingTalkManagerBuilder.dingerHttpClient.post( webhook.toString(), headers, message, MediaTypeEnum.JSON ); - return DingerResult.success(dkid, response); + return DingerResponse.success(dkid, response); } catch (Exception e) { - exceptionCallback(dkid, keyword, message, new SendMsgException(e)); - return DingerResult.failed(ResultCode.SEND_MESSAGE_FAILED, dkid); + exceptionCallback(dkid, message, new SendMsgException(e)); + return DingerResponse.failed(DingerResponseCodeEnum.SEND_MESSAGE_FAILED, dkid); } } - - /** - * 发送预警消息到钉钉-艾特所有人 - * - *
-     *     markdown不支持艾特全部
-     * 
- * - * @param dingerType - * Dinger类型 {@link DingerType} - * @param messageSubType - * 消息类型{@link MessageSubType} - * @param keyword - * 关键词(方便定位日志) - * @param title - * 副标题 - * @param content - * 消息内容 - * @param phones - * 艾特成员 - * @param atAll - * 是否艾特所有人 - * @return - * 响应报文 - * */ - private DingerResult send(DingerType dingerType, MessageSubType messageSubType, String keyword, String title, String content, List phones, boolean atAll) { - CustomMessage customMessage = customMessage(messageSubType); - String msgContent = customMessage.message( - dingerProperties.getProjectId(), title, keyword, content, phones - ); - - MsgType msgType = messageSubType.msgType( - dingerType, msgContent, title, phones, atAll - ); - - return send(keyword, msgType); - - } - } \ No newline at end of file diff --git a/src/main/java/com/github/jaemon/dinger/core/DingerSession.java b/src/main/java/com/github/jaemon/dinger/core/DingerSession.java index 400bb82..9cad719 100644 --- a/src/main/java/com/github/jaemon/dinger/core/DingerSession.java +++ b/src/main/java/com/github/jaemon/dinger/core/DingerSession.java @@ -15,7 +15,6 @@ */ package com.github.jaemon.dinger.core; -import com.github.jaemon.dinger.DingerSender; import com.github.jaemon.dinger.core.entity.DingerProperties; import java.lang.reflect.Proxy; @@ -24,14 +23,14 @@ * DingerSession * * @author Jaemon - * @since 2.0 + * @since 1.0 */ public class DingerSession { - private DingerSender dingerSender; + private DingerRobot dingerRobot; private DingerProperties dingerProperties; - public DingerSession(DingerSender dingerSender, DingerProperties dingerProperties) { - this.dingerSender = dingerSender; + public DingerSession(DingerRobot dingerRobot, DingerProperties dingerProperties) { + this.dingerRobot = dingerRobot; this.dingerProperties = dingerProperties; } @@ -40,7 +39,7 @@ public T getDinger(Class type) { // bugfix gitee#I29N15 Thread.currentThread().getContextClassLoader(), new Class[]{type}, - new DingerHandleProxy(dingerSender, dingerProperties) + new DingerHandleProxy(dingerRobot, dingerProperties) ); } diff --git a/src/main/java/com/github/jaemon/dinger/core/MessageTransfer.java b/src/main/java/com/github/jaemon/dinger/core/MessageTransfer.java index 966a594..58a88da 100644 --- a/src/main/java/com/github/jaemon/dinger/core/MessageTransfer.java +++ b/src/main/java/com/github/jaemon/dinger/core/MessageTransfer.java @@ -23,7 +23,7 @@ * MessageTransfer * * @author Jaemon - * @since 2.0 + * @since 1.0 */ public interface MessageTransfer { diff --git a/src/main/java/com/github/jaemon/dinger/core/ParamHandle.java b/src/main/java/com/github/jaemon/dinger/core/ParamHandler.java similarity index 84% rename from src/main/java/com/github/jaemon/dinger/core/ParamHandle.java rename to src/main/java/com/github/jaemon/dinger/core/ParamHandler.java index 6c7aade..373b129 100644 --- a/src/main/java/com/github/jaemon/dinger/core/ParamHandle.java +++ b/src/main/java/com/github/jaemon/dinger/core/ParamHandler.java @@ -19,20 +19,20 @@ import java.util.Map; /** - * ParamHandle + * ParamHandler * * @author Jaemon - * @since 2.0 + * @since 1.0 */ -public interface ParamHandle { +public interface ParamHandler { /** - * paramsHandle + * paramsHandler * * @param parameters parameters * @param values values * @return params map */ - Map paramsHandle(Parameter[] parameters, Object[] values); + Map paramsHandler(Parameter[] parameters, Object[] values); } \ No newline at end of file diff --git a/src/main/java/com/github/jaemon/dinger/core/ResultHandle.java b/src/main/java/com/github/jaemon/dinger/core/ResultHandler.java similarity index 84% rename from src/main/java/com/github/jaemon/dinger/core/ResultHandle.java rename to src/main/java/com/github/jaemon/dinger/core/ResultHandler.java index eeeb25a..24fa109 100644 --- a/src/main/java/com/github/jaemon/dinger/core/ResultHandle.java +++ b/src/main/java/com/github/jaemon/dinger/core/ResultHandler.java @@ -16,18 +16,18 @@ package com.github.jaemon.dinger.core; /** - * ResultHandle + * ResultHandler * * @author Jaemon - * @since 2.0 + * @since 1.0 */ -public interface ResultHandle { +public interface ResultHandler { /** - * resultHandle + * resultHandler * * @param resultType resultType * @param t T * @return object */ - Object resultHandle(Class resultType, T t); + Object resultHandler(Class resultType, T t); } \ No newline at end of file diff --git a/src/main/java/com/github/jaemon/dinger/core/annatations/AsyncExecute.java b/src/main/java/com/github/jaemon/dinger/core/annatations/AsyncExecute.java index bcdf392..6f1e75d 100644 --- a/src/main/java/com/github/jaemon/dinger/core/annatations/AsyncExecute.java +++ b/src/main/java/com/github/jaemon/dinger/core/annatations/AsyncExecute.java @@ -21,7 +21,7 @@ * AsyncExecute(xml and annotation) * * @author Jaemon - * @since 2.0 + * @since 1.0 */ @Documented @Retention(RetentionPolicy.RUNTIME) diff --git a/src/main/java/com/github/jaemon/dinger/core/annatations/Dinger.java b/src/main/java/com/github/jaemon/dinger/core/annatations/Dinger.java index 43cd86c..bb582d5 100644 --- a/src/main/java/com/github/jaemon/dinger/core/annatations/Dinger.java +++ b/src/main/java/com/github/jaemon/dinger/core/annatations/Dinger.java @@ -20,13 +20,13 @@ import java.lang.annotation.*; /** - * Dinger + * 指定当前 ***Dinger 使用的 Dinger 类型 * * @author Jaemon - * @since 2.0 + * @since 1.0 */ @Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE, ElementType.METHOD}) +@Target(ElementType.TYPE) @Documented public @interface Dinger { /** diff --git a/src/main/java/com/github/jaemon/dinger/core/annatations/DingerClose.java b/src/main/java/com/github/jaemon/dinger/core/annatations/DingerClose.java index 6381995..f1fb66a 100644 --- a/src/main/java/com/github/jaemon/dinger/core/annatations/DingerClose.java +++ b/src/main/java/com/github/jaemon/dinger/core/annatations/DingerClose.java @@ -21,7 +21,7 @@ * DingerClose * * @author Jaemon - * @since 2.0 + * @since 1.0 */ @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE, ElementType.METHOD}) diff --git a/src/main/java/com/github/jaemon/dinger/core/annatations/DingerConfiguration.java b/src/main/java/com/github/jaemon/dinger/core/annatations/DingerConfiguration.java index 73d7ee7..d1b201c 100644 --- a/src/main/java/com/github/jaemon/dinger/core/annatations/DingerConfiguration.java +++ b/src/main/java/com/github/jaemon/dinger/core/annatations/DingerConfiguration.java @@ -21,14 +21,14 @@ * DingerConfiguration(xml and annotation) * * @author Jaemon - * @since 2.0 + * @since 1.0 */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) @Documented public @interface DingerConfiguration { /** - * dingtalk tokenId + * dinger tokenId * * @return tokenId */ @@ -42,7 +42,7 @@ String decryptKey() default ""; /** - * dingtalk secret + * dinger secret * * @return secret */ diff --git a/src/main/java/com/github/jaemon/dinger/core/annatations/DingerMarkdown.java b/src/main/java/com/github/jaemon/dinger/core/annatations/DingerMarkdown.java index 9323d73..1f0c942 100644 --- a/src/main/java/com/github/jaemon/dinger/core/annatations/DingerMarkdown.java +++ b/src/main/java/com/github/jaemon/dinger/core/annatations/DingerMarkdown.java @@ -35,7 +35,7 @@ * * * @author Jaemon - * @since 2.0 + * @since 1.0 */ @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD}) diff --git a/src/main/java/com/github/jaemon/dinger/core/annatations/DingerScan.java b/src/main/java/com/github/jaemon/dinger/core/annatations/DingerScan.java index 153721c..8f32a07 100644 --- a/src/main/java/com/github/jaemon/dinger/core/annatations/DingerScan.java +++ b/src/main/java/com/github/jaemon/dinger/core/annatations/DingerScan.java @@ -24,7 +24,7 @@ * DingerScan * * @author Jaemon - * @since 2.0 + * @since 1.0 */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) diff --git a/src/main/java/com/github/jaemon/dinger/core/annatations/DingerText.java b/src/main/java/com/github/jaemon/dinger/core/annatations/DingerText.java index a7dbce2..78f8de0 100644 --- a/src/main/java/com/github/jaemon/dinger/core/annatations/DingerText.java +++ b/src/main/java/com/github/jaemon/dinger/core/annatations/DingerText.java @@ -28,7 +28,7 @@ * * * @author Jaemon - * @since 2.0 + * @since 1.0 */ @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD}) diff --git a/src/main/java/com/github/jaemon/dinger/core/annatations/DingerTokenId.java b/src/main/java/com/github/jaemon/dinger/core/annatations/DingerTokenId.java index fcbb6f2..74ef72c 100644 --- a/src/main/java/com/github/jaemon/dinger/core/annatations/DingerTokenId.java +++ b/src/main/java/com/github/jaemon/dinger/core/annatations/DingerTokenId.java @@ -21,7 +21,7 @@ * DingerTokenId * * @author Jaemon - * @since 2.0 + * @since 1.0 */ @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.ANNOTATION_TYPE}) @@ -33,7 +33,7 @@ String value(); /** - * @return dingtalk sign key + * @return dinger sign key */ String secret() default ""; diff --git a/src/main/java/com/github/jaemon/dinger/core/annatations/Keyword.java b/src/main/java/com/github/jaemon/dinger/core/annatations/Keyword.java index c83a9b1..7a4567c 100644 --- a/src/main/java/com/github/jaemon/dinger/core/annatations/Keyword.java +++ b/src/main/java/com/github/jaemon/dinger/core/annatations/Keyword.java @@ -21,11 +21,12 @@ * Keyword(quick locate to servive log) * * @author Jaemon - * @since 2.0 + * @since 1.0 */ @Documented @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.PARAMETER) +@Deprecated public @interface Keyword { boolean keyword() default true; } \ No newline at end of file diff --git a/src/main/java/com/github/jaemon/dinger/core/annatations/Parameter.java b/src/main/java/com/github/jaemon/dinger/core/annatations/Parameter.java index d88b799..fac53a1 100644 --- a/src/main/java/com/github/jaemon/dinger/core/annatations/Parameter.java +++ b/src/main/java/com/github/jaemon/dinger/core/annatations/Parameter.java @@ -21,7 +21,7 @@ * Parameter * * @author Jaemon - * @since 2.0 + * @since 1.0 */ @Documented @Retention(RetentionPolicy.RUNTIME) diff --git a/src/main/java/com/github/jaemon/dinger/entity/DingerCallback.java b/src/main/java/com/github/jaemon/dinger/core/entity/DingerCallback.java similarity index 79% rename from src/main/java/com/github/jaemon/dinger/entity/DingerCallback.java rename to src/main/java/com/github/jaemon/dinger/core/entity/DingerCallback.java index 8f70ac3..3a34952 100644 --- a/src/main/java/com/github/jaemon/dinger/entity/DingerCallback.java +++ b/src/main/java/com/github/jaemon/dinger/core/entity/DingerCallback.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.github.jaemon.dinger.entity; +package com.github.jaemon.dinger.core.entity; import com.github.jaemon.dinger.exception.DingerException; @@ -29,10 +29,6 @@ public class DingerCallback { * 处理唯一id */ private String dkid; - /** - * 检索关键字(方便日志查询) - */ - private String keyword; /** * 通知信息 */ @@ -45,9 +41,8 @@ public class DingerCallback { public DingerCallback() { } - public DingerCallback(String dkid, String keyword, T message, DingerException ex) { + public DingerCallback(String dkid, T message, DingerException ex) { this.dkid = dkid; - this.keyword = keyword; this.message = message; this.ex = ex; } @@ -60,14 +55,6 @@ public void setDkid(String dkid) { this.dkid = dkid; } - public String getKeyword() { - return keyword; - } - - public void setKeyword(String keyword) { - this.keyword = keyword; - } - public T getMessage() { return message; } diff --git a/src/main/java/com/github/jaemon/dinger/core/entity/DingerProperties.java b/src/main/java/com/github/jaemon/dinger/core/entity/DingerProperties.java index 94f3700..5e9e177 100644 --- a/src/main/java/com/github/jaemon/dinger/core/entity/DingerProperties.java +++ b/src/main/java/com/github/jaemon/dinger/core/entity/DingerProperties.java @@ -55,11 +55,6 @@ public class DingerProperties implements InitializingBean { * */ private String projectId; - /** - * 可选, 应用程序状态监控 - */ - private MonitorStatus monitor = new MonitorStatus(); - /** * 使用dinger时, 对应的 xml配置路径. * @@ -97,14 +92,6 @@ public void setProjectId(String projectId) { this.projectId = projectId; } - public MonitorStatus getMonitor() { - return monitor; - } - - public void setMonitor(MonitorStatus monitor) { - this.monitor = monitor; - } - public String getDingerLocations() { return dingerLocations; } @@ -159,7 +146,7 @@ public static class Dinger { * * 解密密钥获取方式 *
    - *
  • java -jar dingtalk-spring-boot-starter-[4.0.0].jar [tokenId]
  • + *
  • java -jar dinger-spring-boot-starter-[1.0.0].jar [tokenId]
  • *
  • ConfigTools.encrypt(tokenId)
  • *
*/ @@ -219,53 +206,14 @@ public void setAsync(boolean async) { } } - public static class MonitorStatus { - /** - * 应用启动成功是否通知 - */ - private boolean success = false; - /** - * 应用启动失败是否通知 - */ - private boolean falied = false; - /** - * 应用退出是否通知 - */ - private boolean exit = false; - - public boolean isSuccess() { - return success; - } - - public void setSuccess(boolean success) { - this.success = success; - } - - public boolean isFalied() { - return falied; - } - - public void setFalied(boolean falied) { - this.falied = falied; - } - - public boolean isExit() { - return exit; - } - - public void setExit(boolean exit) { - this.exit = exit; - } - } - @Override public void afterPropertiesSet() throws Exception { for (Map.Entry entry : dingers.entrySet()) { DingerType dingerType = entry.getKey(); if (!dingerType.isEnabled()) { - log.warn("dinger={} is disabled.", dingerType); - dingers.remove(dingerType); - continue; + throw new InvalidPropertiesFormatException( + String.format("dinger=%s is disabled", dingerType) + ); } Dinger dinger = entry.getValue(); diff --git a/src/main/java/com/github/jaemon/dinger/core/entity/DingerRequest.java b/src/main/java/com/github/jaemon/dinger/core/entity/DingerRequest.java new file mode 100644 index 0000000..ab946eb --- /dev/null +++ b/src/main/java/com/github/jaemon/dinger/core/entity/DingerRequest.java @@ -0,0 +1,122 @@ +/* + * Copyright ©2015-2020 Jaemon. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.github.jaemon.dinger.core.entity; + +import java.util.List; + +/** + * Dinger请求体 + * + * @author Jaemon + * @since 1.0 + */ +public class DingerRequest { + /** 消息内容 */ + private String content; + /** 标题(dingtalk-markdown) */ + private String title; + /** 艾特成员信息 */ + private List phones; + /** 艾特成员 */ + private boolean atAll = false; + + private DingerRequest(String content) { + this.content = content; + } + + private DingerRequest(String content, String title) { + this(content); + this.title = title; + } + + private DingerRequest(String content, List phones) { + this.content = content; + this.phones = phones; + } + + private DingerRequest(String content, boolean atAll) { + this.content = content; + this.atAll = atAll; + } + + private DingerRequest(String content, String title, List phones) { + this(content, title); + this.phones = phones; + } + + private DingerRequest(String content, String title, boolean atAll) { + this(content, atAll); + this.title = title; + } + + + public static DingerRequest request(String content) { + return new DingerRequest(content); + } + + public static DingerRequest request(String content, String title) { + return new DingerRequest(content, title); + } + + public static DingerRequest request(String content, List phones) { + return new DingerRequest(content, phones); + } + + public static DingerRequest request(String content, boolean atAll) { + return new DingerRequest(content, atAll); + } + + public static DingerRequest request(String content, String title, List phones) { + return new DingerRequest(content, title, phones); + } + + public static DingerRequest request(String content, String title, boolean atAll) { + return new DingerRequest(content, title, atAll); + } + + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public List getPhones() { + return phones; + } + + public void setPhones(List phones) { + this.phones = phones; + } + + public boolean isAtAll() { + return atAll; + } + + public void setAtAll(boolean atAll) { + this.atAll = atAll; + } +} \ No newline at end of file diff --git a/src/main/java/com/github/jaemon/dinger/entity/DingerResult.java b/src/main/java/com/github/jaemon/dinger/core/entity/DingerResponse.java similarity index 67% rename from src/main/java/com/github/jaemon/dinger/entity/DingerResult.java rename to src/main/java/com/github/jaemon/dinger/core/entity/DingerResponse.java index 176edb8..3a4e3f0 100644 --- a/src/main/java/com/github/jaemon/dinger/entity/DingerResult.java +++ b/src/main/java/com/github/jaemon/dinger/core/entity/DingerResponse.java @@ -13,17 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.github.jaemon.dinger.entity; +package com.github.jaemon.dinger.core.entity; -import com.github.jaemon.dinger.entity.enums.ResultCode; +import com.github.jaemon.dinger.core.entity.enums.DingerResponseCodeEnum; /** - * DingTalk Result + * Dinger响应体 * * @author Jaemon * @since 1.0 */ -public class DingerResult { +public class DingerResponse { /** * 响应码 */ @@ -41,33 +41,33 @@ public class DingerResult { */ private String data; - private DingerResult(ResultCode resultCode, String logid) { + private DingerResponse(DingerResponseCodeEnum resultCode, String logid) { this.code = resultCode.code(); this.message = resultCode.message(); this.logid = logid; } - private DingerResult(ResultCode resultCode, String logid, String data) { + private DingerResponse(DingerResponseCodeEnum resultCode, String logid, String data) { this.code = resultCode.code(); this.message = resultCode.message(); this.logid = logid; this.data = data; } - public static DingerResult success(String logId, String data) { - return new DingerResult(ResultCode.SUCCESS, logId, data); + public static DingerResponse success(String logId, String data) { + return new DingerResponse(DingerResponseCodeEnum.SUCCESS, logId, data); } - public static DingerResult success(ResultCode resultCode, String logId, String data) { - return new DingerResult(resultCode, logId, data); + public static DingerResponse success(DingerResponseCodeEnum resultCode, String logId, String data) { + return new DingerResponse(resultCode, logId, data); } - public static DingerResult failed(String logid) { - return new DingerResult(ResultCode.FAILED, logid); + public static DingerResponse failed(String logid) { + return new DingerResponse(DingerResponseCodeEnum.FAILED, logid); } - public static DingerResult failed(ResultCode resultCode, String logid) { - return new DingerResult(resultCode, logid); + public static DingerResponse failed(DingerResponseCodeEnum resultCode, String logid) { + return new DingerResponse(resultCode, logid); } public String getCode() { diff --git a/src/main/java/com/github/jaemon/dinger/entity/enums/Pairs.java b/src/main/java/com/github/jaemon/dinger/core/entity/Pairs.java similarity index 94% rename from src/main/java/com/github/jaemon/dinger/entity/enums/Pairs.java rename to src/main/java/com/github/jaemon/dinger/core/entity/Pairs.java index 441f1ee..92b377e 100644 --- a/src/main/java/com/github/jaemon/dinger/entity/enums/Pairs.java +++ b/src/main/java/com/github/jaemon/dinger/core/entity/Pairs.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.github.jaemon.dinger.entity.enums; +package com.github.jaemon.dinger.core.entity; /** * K-V对 diff --git a/src/main/java/com/github/jaemon/dinger/core/entity/enums/AsyncExecuteType.java b/src/main/java/com/github/jaemon/dinger/core/entity/enums/AsyncExecuteType.java index 90f04fd..43ff461 100644 --- a/src/main/java/com/github/jaemon/dinger/core/entity/enums/AsyncExecuteType.java +++ b/src/main/java/com/github/jaemon/dinger/core/entity/enums/AsyncExecuteType.java @@ -19,7 +19,7 @@ * AsyncExecuteType * * @author Jaemon - * @since 2.0 + * @since 1.0 */ public enum AsyncExecuteType { TRUE(true), diff --git a/src/main/java/com/github/jaemon/dinger/core/entity/enums/DingerDefinitionType.java b/src/main/java/com/github/jaemon/dinger/core/entity/enums/DingerDefinitionType.java index 9e28683..51c30d7 100644 --- a/src/main/java/com/github/jaemon/dinger/core/entity/enums/DingerDefinitionType.java +++ b/src/main/java/com/github/jaemon/dinger/core/entity/enums/DingerDefinitionType.java @@ -25,7 +25,7 @@ * Dinger消息体定义类型 * * @author Jaemon - * @since 4.0 + * @since 1.0 */ public enum DingerDefinitionType { diff --git a/src/main/java/com/github/jaemon/dinger/entity/enums/ResultCode.java b/src/main/java/com/github/jaemon/dinger/core/entity/enums/DingerResponseCodeEnum.java similarity index 87% rename from src/main/java/com/github/jaemon/dinger/entity/enums/ResultCode.java rename to src/main/java/com/github/jaemon/dinger/core/entity/enums/DingerResponseCodeEnum.java index 954a28b..47a373e 100644 --- a/src/main/java/com/github/jaemon/dinger/entity/enums/ResultCode.java +++ b/src/main/java/com/github/jaemon/dinger/core/entity/enums/DingerResponseCodeEnum.java @@ -13,15 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.github.jaemon.dinger.entity.enums; +package com.github.jaemon.dinger.core.entity.enums; /** - * Result Code + * Dinger响应码 * * @author Jaemon * @since 1.0 */ -public enum ResultCode { +public enum DingerResponseCodeEnum { SUCCESS("D000", "success"), DINGER_DISABLED("D101", "Dinger未启用"), @@ -36,7 +36,7 @@ public enum ResultCode { private String code; private String message; - ResultCode(String code, String message) { + DingerResponseCodeEnum(String code, String message) { this.code = code; this.message = message; } diff --git a/src/main/java/com/github/jaemon/dinger/core/entity/enums/DingerType.java b/src/main/java/com/github/jaemon/dinger/core/entity/enums/DingerType.java index 7168fe7..dd5bb0f 100644 --- a/src/main/java/com/github/jaemon/dinger/core/entity/enums/DingerType.java +++ b/src/main/java/com/github/jaemon/dinger/core/entity/enums/DingerType.java @@ -23,7 +23,7 @@ * Dinger类型 * * @author Jaemon - * @since 4.0 + * @since 1.0 */ public enum DingerType { DINGTALK("钉钉", "https://oapi.dingtalk.com/robot/send?access_token", true), diff --git a/src/main/java/com/github/jaemon/dinger/core/entity/enums/ExceptionEnum.java b/src/main/java/com/github/jaemon/dinger/core/entity/enums/ExceptionEnum.java new file mode 100644 index 0000000..e9d69f5 --- /dev/null +++ b/src/main/java/com/github/jaemon/dinger/core/entity/enums/ExceptionEnum.java @@ -0,0 +1,119 @@ +/* + * Copyright ©2015-2020 Jaemon. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.github.jaemon.dinger.core.entity.enums; + +import com.github.jaemon.dinger.core.entity.Pairs; + +/** + * 异常枚举 + * + * @author Jaemon + * @since 1.0 + */ +public enum ExceptionEnum implements Pairs { + /** 发送异常, 1XXX, {@link com.github.jaemon.dinger.exception.SendMsgException} */ + SEND_MSG(1000, "发送消息异常"), + + + + + + /** 消息类型异常, {@link com.github.jaemon.dinger.exception.MsgTypeException} */ + MSG_TYPE_CHECK(2000, "消息类型异常"), + + + + + + /** 异步调用相关异常, {@link com.github.jaemon.dinger.exception.AsyncCallException} */ + ASYNC_CALL(3000, "异步调用异常"), + + + + + + /** + * dingTalkManagerBuilder 配置异常 + */ + MULTI_DINGER_SCAN_ERROR(4000, "配置了多个DingerScan注解"), + /** {@link com.github.jaemon.dinger.exception.ConfigurationException} */ + CONFIG_ERROR(4001, "配置异常"), + + + + + + /** 配置文件相关异常, 5XXX, {@link com.github.jaemon.dinger.exception.InvalidPropertiesFormatException} */ + PROPERTIES_ERROR(5000, "配置文件异常"), + + + + + + /** Dinger解析XML相关异常, 60XX */ + DINER_XML_NAMESPACE_INVALID(6000, "xml文件namespace=%s无效"), + DINER_XML_MSGTYPE_INVALID(6001, "xml文件message type=%s无效"), + + // TODO + DINGERDEFINITION_ERROR(6004, "dingerDefinition异常"), + DINGERDEFINITIONTYPE_ERROR(6005, "DingerDefinitionType异常"), + + + /** Dinger解析注解相关异常, 63XX */ + + + /** Dinger解析公共相关异常, 65XX */ + /** 注定DingerText和Dinger xml重复配置也会抛出该异常 */ + DINGER_REPEATED_EXCEPTION(6500, "重复的DingerId=%s对象"), + DINGERDEFINITIONTYPE_UNDEFINED_KEY(6501, "当前key=%s在DingerDefinitionType中没定义"), + + + + + + /** Multi Dinger解析相关异常, 70XX */ + DINGER_CONFIG_HANDLER_EXCEPTION(7000, "DingerConfigHandler=%s中指定的dingerconfigs[%d]数据异常"), + MULTIDINGER_ALGORITHM_EXCEPTION(7001, "DingerConfigHandler=%s中算法为空"), + + /** Multi Dinger属性注入相关异常, 75XX */ + ALGORITHM_FIELD_INSTANCE_NOT_EXISTS(7500, "算法[%s]中属性字段[%s]实例不存在"), + ALGORITHM_FIELD_INSTANCE_NOT_MATCH(7501, "算法[%s]中属性字段[%s]实例不匹配"), + ALGORITHM_FIELD_INJECT_FAILED(7502, "算法[%s]中属性字段[%s]注入失败"), + + + /** 未知异常 */ + UNKNOWN(9999, "未知异常") + ; + + + private int code; + private String message; + + ExceptionEnum(int code, String message) { + this.code = code; + this.message = message; + } + + @Override + public Integer code() { + return code; + } + + @Override + public String desc() { + return message; + } +} \ No newline at end of file diff --git a/src/main/java/com/github/jaemon/dinger/core/entity/enums/MessageMainType.java b/src/main/java/com/github/jaemon/dinger/core/entity/enums/MessageMainType.java index b853458..6876f1f 100644 --- a/src/main/java/com/github/jaemon/dinger/core/entity/enums/MessageMainType.java +++ b/src/main/java/com/github/jaemon/dinger/core/entity/enums/MessageMainType.java @@ -19,7 +19,7 @@ * 消息体定义主类型(消息体xml定义和注解定义) * * @author Jaemon - * @since 2.0 + * @since 1.0 */ public enum MessageMainType { /** xml dinger msg */ diff --git a/src/main/java/com/github/jaemon/dinger/core/entity/enums/MessageSubType.java b/src/main/java/com/github/jaemon/dinger/core/entity/enums/MessageSubType.java index efc7259..dcb72e0 100644 --- a/src/main/java/com/github/jaemon/dinger/core/entity/enums/MessageSubType.java +++ b/src/main/java/com/github/jaemon/dinger/core/entity/enums/MessageSubType.java @@ -32,7 +32,7 @@ * 消息体定义子类型 * * @author Jaemon - * @since 4.0 + * @since 1.0 */ public enum MessageSubType { TEXT { diff --git a/src/main/java/com/github/jaemon/dinger/core/entity/xml/BeanTag.java b/src/main/java/com/github/jaemon/dinger/core/entity/xml/BeanTag.java index fc6738e..802c883 100644 --- a/src/main/java/com/github/jaemon/dinger/core/entity/xml/BeanTag.java +++ b/src/main/java/com/github/jaemon/dinger/core/entity/xml/BeanTag.java @@ -25,7 +25,7 @@ * BeanTag * * @author Jaemon - * @since 2.0 + * @since 1.0 */ @XmlRootElement(name="dinger") public class BeanTag { diff --git a/src/main/java/com/github/jaemon/dinger/core/entity/xml/BodyTag.java b/src/main/java/com/github/jaemon/dinger/core/entity/xml/BodyTag.java index dd0ccdb..d59ff0a 100644 --- a/src/main/java/com/github/jaemon/dinger/core/entity/xml/BodyTag.java +++ b/src/main/java/com/github/jaemon/dinger/core/entity/xml/BodyTag.java @@ -25,7 +25,7 @@ * BodyTag * * @author Jaemon - * @since 2.0 + * @since 1.0 */ @XmlRootElement(name="body") public class BodyTag { diff --git a/src/main/java/com/github/jaemon/dinger/core/entity/xml/ConfigurationTag.java b/src/main/java/com/github/jaemon/dinger/core/entity/xml/ConfigurationTag.java index ef0c101..a0e59e8 100644 --- a/src/main/java/com/github/jaemon/dinger/core/entity/xml/ConfigurationTag.java +++ b/src/main/java/com/github/jaemon/dinger/core/entity/xml/ConfigurationTag.java @@ -25,7 +25,7 @@ * ConfigurationTag * * @author Jaemon - * @since 2.0 + * @since 1.0 */ @XmlRootElement(name = "configuration") public class ConfigurationTag { diff --git a/src/main/java/com/github/jaemon/dinger/core/entity/xml/MessageTag.java b/src/main/java/com/github/jaemon/dinger/core/entity/xml/MessageTag.java index 6232960..3f681b2 100644 --- a/src/main/java/com/github/jaemon/dinger/core/entity/xml/MessageTag.java +++ b/src/main/java/com/github/jaemon/dinger/core/entity/xml/MessageTag.java @@ -24,7 +24,7 @@ * MessageTag * * @author Jaemon - * @since 2.0 + * @since 1.0 */ @XmlRootElement(name = "message") public class MessageTag { diff --git a/src/main/java/com/github/jaemon/dinger/core/entity/xml/PhoneTag.java b/src/main/java/com/github/jaemon/dinger/core/entity/xml/PhoneTag.java index 08bed92..4c087c2 100644 --- a/src/main/java/com/github/jaemon/dinger/core/entity/xml/PhoneTag.java +++ b/src/main/java/com/github/jaemon/dinger/core/entity/xml/PhoneTag.java @@ -22,7 +22,7 @@ * PhoneTag * * @author Jaemon - * @since 2.0 + * @since 1.0 */ @XmlRootElement(name = "phone") public class PhoneTag { diff --git a/src/main/java/com/github/jaemon/dinger/core/entity/xml/PhonesTag.java b/src/main/java/com/github/jaemon/dinger/core/entity/xml/PhonesTag.java index dc0d1f9..b1e244e 100644 --- a/src/main/java/com/github/jaemon/dinger/core/entity/xml/PhonesTag.java +++ b/src/main/java/com/github/jaemon/dinger/core/entity/xml/PhonesTag.java @@ -25,7 +25,7 @@ * PhonesTag * * @author Jaemon - * @since 2.0 + * @since 1.0 */ @XmlRootElement(name = "phones") public class PhonesTag { diff --git a/src/main/java/com/github/jaemon/dinger/core/entity/xml/TokenId.java b/src/main/java/com/github/jaemon/dinger/core/entity/xml/TokenId.java index 3aaf248..4c37b9c 100644 --- a/src/main/java/com/github/jaemon/dinger/core/entity/xml/TokenId.java +++ b/src/main/java/com/github/jaemon/dinger/core/entity/xml/TokenId.java @@ -25,7 +25,7 @@ * TokenId * * @author Jaemon - * @since 2.0 + * @since 1.0 */ @XmlRootElement(name = "token-id") public class TokenId { diff --git a/src/main/java/com/github/jaemon/dinger/core/package-info.java b/src/main/java/com/github/jaemon/dinger/core/package-info.java index d6db2c6..7471422 100644 --- a/src/main/java/com/github/jaemon/dinger/core/package-info.java +++ b/src/main/java/com/github/jaemon/dinger/core/package-info.java @@ -18,6 +18,6 @@ * Dinger框架核心包 * * @author Jaemon - * @since 4.0 + * @since 1.0 */ package com.github.jaemon.dinger.core; \ No newline at end of file diff --git a/src/main/java/com/github/jaemon/dinger/core/spring/DingerFactoryBean.java b/src/main/java/com/github/jaemon/dinger/core/spring/DingerFactoryBean.java index ccb7754..2fd263d 100644 --- a/src/main/java/com/github/jaemon/dinger/core/spring/DingerFactoryBean.java +++ b/src/main/java/com/github/jaemon/dinger/core/spring/DingerFactoryBean.java @@ -15,7 +15,7 @@ */ package com.github.jaemon.dinger.core.spring; -import com.github.jaemon.dinger.DingerSender; +import com.github.jaemon.dinger.core.DingerRobot; import com.github.jaemon.dinger.core.DingerSession; import com.github.jaemon.dinger.core.entity.DingerProperties; import org.springframework.beans.factory.FactoryBean; @@ -25,13 +25,13 @@ * DingerFactoryBean * * @author Jaemon - * @since 2.0 + * @since 1.0 */ public class DingerFactoryBean implements FactoryBean { private Class dingerInterface; @Autowired - private DingerSender dingerSender; + private DingerRobot dingerRobot; @Autowired private DingerProperties dingerProperties; @@ -41,7 +41,7 @@ public DingerFactoryBean(Class dingerInterface) { @Override public T getObject() throws Exception { - return new DingerSession(dingerSender, dingerProperties).getDinger(this.dingerInterface); + return new DingerSession(dingerRobot, dingerProperties).getDinger(this.dingerInterface); } @Override diff --git a/src/main/java/com/github/jaemon/dinger/core/spring/DingerScannerRegistrar.java b/src/main/java/com/github/jaemon/dinger/core/spring/DingerScannerRegistrar.java index f1c4e07..864dee7 100644 --- a/src/main/java/com/github/jaemon/dinger/core/spring/DingerScannerRegistrar.java +++ b/src/main/java/com/github/jaemon/dinger/core/spring/DingerScannerRegistrar.java @@ -16,9 +16,8 @@ package com.github.jaemon.dinger.core.spring; import com.github.jaemon.dinger.core.annatations.DingerScan; -import com.github.jaemon.dinger.entity.enums.ExceptionEnum; +import com.github.jaemon.dinger.core.entity.enums.ExceptionEnum; import com.github.jaemon.dinger.exception.DingerException; -import com.github.jaemon.dinger.listeners.ApplicationEventTimeTable; import com.github.jaemon.dinger.listeners.DingerListenersProperty; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,7 +38,7 @@ * DingerScannerRegistrar * * @author Jaemon - * @since 2.0 + * @since 1.0 */ public class DingerScannerRegistrar extends DingerListenersProperty @@ -53,7 +52,7 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, B boolean isDebugEnabled = log.isDebugEnabled(); log.info("ready to execute dingerScanner..."); try { - List> dingerClasses = ApplicationEventTimeTable.dingerClasses(); + List> dingerClasses = DingerListenersProperty.dingerClasses(); if (!dingerClasses.isEmpty()) { registerBeanDefinition(registry, dingerClasses); diff --git a/src/main/java/com/github/jaemon/dinger/dingtalk/DingTalkDefinitionGenerator.java b/src/main/java/com/github/jaemon/dinger/dingtalk/DingTalkDefinitionGenerator.java index cca3c55..1f64bd8 100644 --- a/src/main/java/com/github/jaemon/dinger/dingtalk/DingTalkDefinitionGenerator.java +++ b/src/main/java/com/github/jaemon/dinger/dingtalk/DingTalkDefinitionGenerator.java @@ -31,7 +31,7 @@ * 钉钉消息体定义生成类 * * @author Jaemon - * @since 4.0 + * @since 1.0 */ public class DingTalkDefinitionGenerator extends DingerDefinitionHandler { private static final Logger log = LoggerFactory.getLogger(DingerDefinitionGenerator.class); diff --git a/src/main/java/com/github/jaemon/dinger/dingtalk/entity/DingTalkMessage.java b/src/main/java/com/github/jaemon/dinger/dingtalk/entity/DingTalkMessage.java index 457d9e4..332b0dc 100644 --- a/src/main/java/com/github/jaemon/dinger/dingtalk/entity/DingTalkMessage.java +++ b/src/main/java/com/github/jaemon/dinger/dingtalk/entity/DingTalkMessage.java @@ -22,7 +22,7 @@ * DingTalk请求体 * * @author Jaemon - * @since 4.0 + * @since 1.0 */ public class DingTalkMessage extends MsgType { public DingTalkMessage() { diff --git a/src/main/java/com/github/jaemon/dinger/dingtalk/entity/enums/DingTalkMsgType.java b/src/main/java/com/github/jaemon/dinger/dingtalk/entity/enums/DingTalkMsgType.java index aa69606..4decf4d 100644 --- a/src/main/java/com/github/jaemon/dinger/dingtalk/entity/enums/DingTalkMsgType.java +++ b/src/main/java/com/github/jaemon/dinger/dingtalk/entity/enums/DingTalkMsgType.java @@ -19,7 +19,7 @@ * DingTalk支持的消息类型 * * @author Jaemon - * @since 4.0 + * @since 1.0 */ public enum DingTalkMsgType { /** diff --git a/src/main/java/com/github/jaemon/dinger/dingtalk/package-info.java b/src/main/java/com/github/jaemon/dinger/dingtalk/package-info.java index 53f13bd..f3c2d63 100644 --- a/src/main/java/com/github/jaemon/dinger/dingtalk/package-info.java +++ b/src/main/java/com/github/jaemon/dinger/dingtalk/package-info.java @@ -15,9 +15,9 @@ */ /** - * DingTalk适配包 + * 支持DingTalk包 * * @author Jaemon - * @since 4.0 + * @since 1.0 */ package com.github.jaemon.dinger.dingtalk; \ No newline at end of file diff --git a/src/main/java/com/github/jaemon/dinger/entity/enums/ExceptionEnum.java b/src/main/java/com/github/jaemon/dinger/entity/enums/ExceptionEnum.java deleted file mode 100644 index d2ce35c..0000000 --- a/src/main/java/com/github/jaemon/dinger/entity/enums/ExceptionEnum.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright ©2015-2020 Jaemon. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.github.jaemon.dinger.entity.enums; - -/** - * 异常枚举 - * - * @author Jaemon - * @since 1.0 - */ -public enum ExceptionEnum implements Pairs { - SEND_MSG(1000, "发送消息异常"), - MSG_TYPE_CHECK(2000, "消息类型异常"), - ASYNC_CALL(3000, "异步调用异常"), - /** - * dingTalkManagerBuilder 配置异常 - */ - CONFIG_ERROR(4000, "配置异常"), - /** - * - */ - PROPERTIES_ERROR(5000, "配置文件异常"), - - DINER_XML_ANALYSIS_EXCEPTION(6000, "Dinger xml解析异常"), - DINGERSCAN_REPEATED_EXCEPTION(6001, "DingerScan注解重复配置"), - /** 注定DingerText和Dinger xml重复配置也会抛出该异常 */ - DINGER_CONFIG_REPEATED_EXCEPTION(6002, "重复的DingerId对象"), - GLOBAL_MULTIDINGER_CONFIG_EXCEPTION(6003, "全局多Dinger配置错误"), - MULTIDINGER_ALGORITHM_EXCEPTION(6004, "多Dinger配置处理器算法不可为空"), - MULTI_DINGERCONFIGS_EXCEPTION(6005, "多Dinger配置DingerConfig异常"), - - REGISTER_DINGERDEFINITION_ERROR(6006, "注册dingerDefinition异常"), - DINGERDEFINITION_ERROR(6007, "dingerDefinition异常"), - DINGERDEFINITIONTYPE_ERROR(6008, "DingerDefinitionType异常"), - - UNKNOWN(9999, "未知异常") - ; - - - private int code; - private String message; - - ExceptionEnum(int code, String message) { - this.code = code; - this.message = message; - } - - @Override - public Integer code() { - return code; - } - - @Override - public String desc() { - return message; - } -} \ No newline at end of file diff --git a/src/main/java/com/github/jaemon/dinger/exception/AsyncCallException.java b/src/main/java/com/github/jaemon/dinger/exception/AsyncCallException.java index b5b2876..6fcb741 100644 --- a/src/main/java/com/github/jaemon/dinger/exception/AsyncCallException.java +++ b/src/main/java/com/github/jaemon/dinger/exception/AsyncCallException.java @@ -15,7 +15,7 @@ */ package com.github.jaemon.dinger.exception; -import com.github.jaemon.dinger.entity.enums.ExceptionEnum; +import com.github.jaemon.dinger.core.entity.enums.ExceptionEnum; /** * 异步调用异常 diff --git a/src/main/java/com/github/jaemon/dinger/exception/ConfigurationException.java b/src/main/java/com/github/jaemon/dinger/exception/ConfigurationException.java index 74d0a39..edff41c 100644 --- a/src/main/java/com/github/jaemon/dinger/exception/ConfigurationException.java +++ b/src/main/java/com/github/jaemon/dinger/exception/ConfigurationException.java @@ -15,7 +15,7 @@ */ package com.github.jaemon.dinger.exception; -import com.github.jaemon.dinger.entity.enums.ExceptionEnum; +import com.github.jaemon.dinger.core.entity.enums.ExceptionEnum; /** * 配置异常 diff --git a/src/main/java/com/github/jaemon/dinger/exception/DingerXmlAnalysisException.java b/src/main/java/com/github/jaemon/dinger/exception/DingerAnalysisException.java similarity index 64% rename from src/main/java/com/github/jaemon/dinger/exception/DingerXmlAnalysisException.java rename to src/main/java/com/github/jaemon/dinger/exception/DingerAnalysisException.java index 48b3fa1..67188fc 100644 --- a/src/main/java/com/github/jaemon/dinger/exception/DingerXmlAnalysisException.java +++ b/src/main/java/com/github/jaemon/dinger/exception/DingerAnalysisException.java @@ -15,20 +15,20 @@ */ package com.github.jaemon.dinger.exception; -import com.github.jaemon.dinger.entity.enums.ExceptionEnum; +import com.github.jaemon.dinger.core.entity.Pairs; /** - * DingerXmlAnalysisException + * Dinger解析异常 * * @author Jaemon * @since 1.0 */ -public class DingerXmlAnalysisException extends DingerException { - public DingerXmlAnalysisException(String msg) { - super(msg, ExceptionEnum.DINER_XML_ANALYSIS_EXCEPTION); +public class DingerAnalysisException extends DingerException { + public DingerAnalysisException(Pairs pairs) { + super(pairs); } - public DingerXmlAnalysisException(Throwable cause) { - super(cause, ExceptionEnum.DINER_XML_ANALYSIS_EXCEPTION); + public DingerAnalysisException(Pairs pairs, String message) { + super(message, pairs); } } \ No newline at end of file diff --git a/src/main/java/com/github/jaemon/dinger/exception/DingerException.java b/src/main/java/com/github/jaemon/dinger/exception/DingerException.java index 61eb180..d65d11e 100644 --- a/src/main/java/com/github/jaemon/dinger/exception/DingerException.java +++ b/src/main/java/com/github/jaemon/dinger/exception/DingerException.java @@ -15,7 +15,7 @@ */ package com.github.jaemon.dinger.exception; -import com.github.jaemon.dinger.entity.enums.Pairs; +import com.github.jaemon.dinger.core.entity.Pairs; /** * 异常类 @@ -26,17 +26,22 @@ public class DingerException extends RuntimeException { private Pairs pairs; - public DingerException(Pairs pairs) { - super(pairs.desc().toString()); + public DingerException(Pairs pairs) { + super(pairs.desc()); this.pairs = pairs; } - public DingerException(String msg, Pairs pairs) { + public DingerException(String msg, Pairs pairs) { super(msg); this.pairs = pairs; } - public DingerException(Throwable cause, Pairs pairs) { + public DingerException(Pairs pairs, Object... msgArgs) { + super(String.format(pairs.desc(), msgArgs)); + this.pairs = pairs; + } + + public DingerException(Throwable cause, Pairs pairs) { super(cause); this.pairs = pairs; } diff --git a/src/main/java/com/github/jaemon/dinger/exception/InvalidPropertiesFormatException.java b/src/main/java/com/github/jaemon/dinger/exception/InvalidPropertiesFormatException.java index 1da4681..9159abb 100644 --- a/src/main/java/com/github/jaemon/dinger/exception/InvalidPropertiesFormatException.java +++ b/src/main/java/com/github/jaemon/dinger/exception/InvalidPropertiesFormatException.java @@ -15,7 +15,7 @@ */ package com.github.jaemon.dinger.exception; -import com.github.jaemon.dinger.entity.enums.ExceptionEnum; +import com.github.jaemon.dinger.core.entity.enums.ExceptionEnum; /** * Invalid Properties Format Exception diff --git a/src/main/java/com/github/jaemon/dinger/exception/MsgTypeException.java b/src/main/java/com/github/jaemon/dinger/exception/MsgTypeException.java index f75021c..407d14d 100644 --- a/src/main/java/com/github/jaemon/dinger/exception/MsgTypeException.java +++ b/src/main/java/com/github/jaemon/dinger/exception/MsgTypeException.java @@ -15,7 +15,7 @@ */ package com.github.jaemon.dinger.exception; -import com.github.jaemon.dinger.entity.enums.ExceptionEnum; +import com.github.jaemon.dinger.core.entity.enums.ExceptionEnum; /** * 类型异常 diff --git a/src/main/java/com/github/jaemon/dinger/exception/DingerScanRepeatedException.java b/src/main/java/com/github/jaemon/dinger/exception/MultiDingerRegisterException.java similarity index 58% rename from src/main/java/com/github/jaemon/dinger/exception/DingerScanRepeatedException.java rename to src/main/java/com/github/jaemon/dinger/exception/MultiDingerRegisterException.java index 7a79ad2..aeeb5bb 100644 --- a/src/main/java/com/github/jaemon/dinger/exception/DingerScanRepeatedException.java +++ b/src/main/java/com/github/jaemon/dinger/exception/MultiDingerRegisterException.java @@ -15,24 +15,21 @@ */ package com.github.jaemon.dinger.exception; -import com.github.jaemon.dinger.entity.enums.ExceptionEnum; +import com.github.jaemon.dinger.core.entity.Pairs; /** - * DingerScanRepeatedException + * 多Dinger配置注册异常 * * @author Jaemon * @since 1.0 */ -public class DingerScanRepeatedException extends DingerException { - public DingerScanRepeatedException() { - super(ExceptionEnum.DINGERSCAN_REPEATED_EXCEPTION); +public class MultiDingerRegisterException extends DingerException { + public MultiDingerRegisterException(Pairs pairs) { + super(pairs); } - public DingerScanRepeatedException(String msg) { - super(msg, ExceptionEnum.DINGERSCAN_REPEATED_EXCEPTION); + public MultiDingerRegisterException(Pairs pairs, String message) { + super(message, pairs); } - public DingerScanRepeatedException(Throwable cause) { - super(cause, ExceptionEnum.DINGERSCAN_REPEATED_EXCEPTION); - } } \ No newline at end of file diff --git a/src/main/java/com/github/jaemon/dinger/exception/SendMsgException.java b/src/main/java/com/github/jaemon/dinger/exception/SendMsgException.java index afe1eeb..6ab4421 100644 --- a/src/main/java/com/github/jaemon/dinger/exception/SendMsgException.java +++ b/src/main/java/com/github/jaemon/dinger/exception/SendMsgException.java @@ -15,7 +15,7 @@ */ package com.github.jaemon.dinger.exception; -import com.github.jaemon.dinger.entity.enums.ExceptionEnum; +import com.github.jaemon.dinger.core.entity.enums.ExceptionEnum; /** * 发送消息异常 diff --git a/src/main/java/com/github/jaemon/dinger/listeners/ApplicationEventTimeTable.java b/src/main/java/com/github/jaemon/dinger/listeners/ApplicationEventTimeTable.java deleted file mode 100644 index 96b6716..0000000 --- a/src/main/java/com/github/jaemon/dinger/listeners/ApplicationEventTimeTable.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright ©2015-2020 Jaemon. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.github.jaemon.dinger.listeners; - - -import java.util.ArrayList; -import java.util.HashSet; - -/** - * ApplicationEventTimeTable - * - * @author Jaemon - * @since 1.0 - */ -public final class ApplicationEventTimeTable extends DingerListenersProperty { - /** - * 禁用dinger监控功能 - * - * -Ddinger.monitor.disabled=true - * */ - static final String DISABLED_DINTALK_MONITOR = "dinger.monitor.disabled"; - /** - * startTime - */ - static long startTime = 0; - /** - * successTime - */ - static long successTime = 0; - /** - * failedTime - */ - static long failedTime = 0; - /** - * exitTime - */ - static long exitTime = 0; - - private ApplicationEventTimeTable() { - } - - public static long startTime() { - return startTime; - } - - public static long successTime() { - return successTime; - } - - public static long failedTime() { - return failedTime; - } - - public static long exitTime() { - return exitTime; - } - - - protected static void clear() { - ApplicationEventTimeTable.startTime = 0; - ApplicationEventTimeTable.successTime = 0; - ApplicationEventTimeTable.failedTime = 0; - ApplicationEventTimeTable.exitTime = 0; - primarySources = new HashSet<>(); - dingerClasses = new ArrayList<>(); - } - -} \ No newline at end of file diff --git a/src/main/java/com/github/jaemon/dinger/listeners/DingerListenersProperty.java b/src/main/java/com/github/jaemon/dinger/listeners/DingerListenersProperty.java index 5a92ef3..a454b09 100644 --- a/src/main/java/com/github/jaemon/dinger/listeners/DingerListenersProperty.java +++ b/src/main/java/com/github/jaemon/dinger/listeners/DingerListenersProperty.java @@ -24,7 +24,7 @@ * ApplicationEventTimeTable * * @author Jaemon - * @since 4.0 + * @since 1.0 */ public class DingerListenersProperty { /** @@ -55,4 +55,9 @@ protected static void emptyDingerClasses() { enabledDingerTypes = Arrays.stream(DingerType.values()).filter(e -> e.isEnabled()).collect(Collectors.toList()); } + protected static void clear() { + DingerListenersProperty.primarySources().clear(); + DingerListenersProperty.dingerClasses().clear(); + } + } \ No newline at end of file diff --git a/src/main/java/com/github/jaemon/dinger/listeners/DingerXmlPreparedEvent.java b/src/main/java/com/github/jaemon/dinger/listeners/DingerXmlPreparedEvent.java index b0ef336..e54602e 100644 --- a/src/main/java/com/github/jaemon/dinger/listeners/DingerXmlPreparedEvent.java +++ b/src/main/java/com/github/jaemon/dinger/listeners/DingerXmlPreparedEvent.java @@ -17,7 +17,8 @@ import com.github.jaemon.dinger.core.DingerDefinitionResolver; import com.github.jaemon.dinger.core.entity.enums.DingerType; -import com.github.jaemon.dinger.entity.enums.ExceptionEnum; +import com.github.jaemon.dinger.core.entity.enums.ExceptionEnum; +import com.github.jaemon.dinger.exception.DingerAnalysisException; import com.github.jaemon.dinger.exception.DingerException; import com.github.jaemon.dinger.utils.DingerUtils; import com.github.jaemon.dinger.core.DingerConfig; @@ -33,7 +34,7 @@ * DingerXmlPreparedEvent * * @author Jaemon - * @since 2.0 + * @since 1.0 */ public class DingerXmlPreparedEvent extends DingerDefinitionResolver @@ -47,7 +48,9 @@ public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) { registerDefaultDingerConfig(event.getEnvironment()); try { - ApplicationEventTimeTable.dingerClasses = doAnalysis(event); + DingerListenersProperty.dingerClasses = doAnalysis(event); + } catch (DingerException ex) { + throw new DingerAnalysisException(ex.getPairs(), ex.getMessage()); } catch (Exception ex) { throw new DingerException(ex, ExceptionEnum.UNKNOWN); } @@ -78,7 +81,7 @@ private void registerDefaultDingerConfig(Environment environment) { String secret = environment.getProperty(secretProp); boolean decrypt = getProperty(environment, decryptProp); boolean async = getProperty(environment, asyncExecuteProp); - DingerConfig defaultDingerConfig = new DingerConfig(tokenId); + DingerConfig defaultDingerConfig = DingerConfig.instance(tokenId); defaultDingerConfig.setDingerType(dingerType); defaultDingerConfig.setSecret(secret); if (decrypt) { diff --git a/src/main/java/com/github/jaemon/dinger/listeners/ExitEventListener.java b/src/main/java/com/github/jaemon/dinger/listeners/ExitEventListener.java index bac34e2..f777cf8 100644 --- a/src/main/java/com/github/jaemon/dinger/listeners/ExitEventListener.java +++ b/src/main/java/com/github/jaemon/dinger/listeners/ExitEventListener.java @@ -16,22 +16,11 @@ package com.github.jaemon.dinger.listeners; import com.github.jaemon.dinger.multi.MultiDingerRefresh; -import com.github.jaemon.dinger.DingerSender; -import com.github.jaemon.dinger.core.entity.DingerProperties; -import com.github.jaemon.dinger.entity.DingerResult; -import com.github.jaemon.dinger.core.entity.MsgType; -import com.github.jaemon.dinger.support.MonitorEventNotification; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext; -import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationListener; import org.springframework.context.event.ContextClosedEvent; -import static com.github.jaemon.dinger.constant.DingerConstant.DINGER_PREFIX; -import static com.github.jaemon.dinger.constant.DingerConstant.EXIT_KEYWORD; -import static com.github.jaemon.dinger.listeners.ApplicationEventTimeTable.DISABLED_DINTALK_MONITOR; - /** * Exit Listener * @@ -45,50 +34,12 @@ public class ExitEventListener @Override public void onApplicationEvent(ContextClosedEvent event) { - boolean debugEnabled = log.isDebugEnabled(); - - try { - String monitor = System.getProperty(DISABLED_DINTALK_MONITOR); - if (monitor != null && "true".equals(monitor.trim())) { - return; - } - - ApplicationContext applicationContext = event.getApplicationContext(); - - if (AnnotationConfigServletWebServerApplicationContext.class.isInstance(applicationContext) - && ApplicationEventTimeTable.exitTime == 0) { - if (debugEnabled) { - log.debug("ready to execute ContextClosedEvent."); - } - ApplicationEventTimeTable.exitTime = event.getTimestamp(); - DingerProperties properties = applicationContext.getBean(DingerProperties.class); - - if (properties.isEnabled() - && properties.getMonitor().isExit() - // exclude start-up failed - && ApplicationEventTimeTable.successTime() > 0) { - DingerSender dingTalkRobot = applicationContext.getBean(DingerSender.class); - MonitorEventNotification monitorEventNotification = applicationContext.getBean(MonitorEventNotification.class); - String projectId = properties.getProjectId(); - projectId = projectId == null ? DINGER_PREFIX : projectId; - - MsgType message = monitorEventNotification.exit(event, projectId); - String keyword = projectId + EXIT_KEYWORD; - DingerResult result = dingTalkRobot.send(keyword, message); - if (debugEnabled) { - log.debug("keyword={}, result={}.", keyword, result.toString()); - } - } - } - } finally { - // support devtools - refresh(); - } - + // support devtools + refresh(); } private void refresh() { multiDingerRefresh(); - ApplicationEventTimeTable.clear(); + DingerListenersProperty.clear(); } } \ No newline at end of file diff --git a/src/main/java/com/github/jaemon/dinger/listeners/FailedEventListener.java b/src/main/java/com/github/jaemon/dinger/listeners/FailedEventListener.java deleted file mode 100644 index a8c8fd3..0000000 --- a/src/main/java/com/github/jaemon/dinger/listeners/FailedEventListener.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright ©2015-2020 Jaemon. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.github.jaemon.dinger.listeners; - -import com.github.jaemon.dinger.DingerSender; -import com.github.jaemon.dinger.constant.DingerConstant; -import com.github.jaemon.dinger.core.entity.DingerProperties; -import com.github.jaemon.dinger.core.entity.MsgType; -import com.github.jaemon.dinger.entity.DingerResult; -import com.github.jaemon.dinger.support.MonitorEventNotification; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.boot.context.event.ApplicationFailedEvent; -import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationListener; - -/** - * Failed Listener - * - * @author Jaemon - * @since 1.0 - */ -public class FailedEventListener implements ApplicationListener { - private static final Logger log = LoggerFactory.getLogger(FailedEventListener.class); - - @Override - public void onApplicationEvent(ApplicationFailedEvent event) { - boolean debugEnabled = log.isDebugEnabled(); - - String monitor = System.getProperty(ApplicationEventTimeTable.DISABLED_DINTALK_MONITOR); - if (monitor != null && "true".equals(monitor.trim())) { - return; - } - - ApplicationContext applicationContext = event.getApplicationContext(); - if (applicationContext == null) { - return; - } - - if (AnnotationConfigServletWebServerApplicationContext.class.isInstance(applicationContext) - && ApplicationEventTimeTable.failedTime == 0) { - if (debugEnabled) { - log.debug("ready to execute ApplicationFailedEvent."); - } - ApplicationEventTimeTable.failedTime = event.getTimestamp(); - DingerProperties properties = applicationContext.getBean(DingerProperties.class); - - if (properties.isEnabled() - && properties.getMonitor().isFalied()) { - DingerSender dingTalkRobot = applicationContext.getBean(DingerSender.class); - MonitorEventNotification monitorEventNotification = applicationContext.getBean(MonitorEventNotification.class); - String projectId = properties.getProjectId(); - projectId = projectId == null ? DingerConstant.DINGER_PREFIX : projectId; - - MsgType message = monitorEventNotification.failed(event, projectId); - String keyword = projectId + DingerConstant.FAILED_KEYWORD; - DingerResult result = dingTalkRobot.send(keyword, message); - if (debugEnabled) { - log.debug("keyword={}, result={}.", keyword, result.toString()); - } - } - } - - } - -} \ No newline at end of file diff --git a/src/main/java/com/github/jaemon/dinger/listeners/StartEventListener.java b/src/main/java/com/github/jaemon/dinger/listeners/StartEventListener.java index 6a04795..926fc74 100644 --- a/src/main/java/com/github/jaemon/dinger/listeners/StartEventListener.java +++ b/src/main/java/com/github/jaemon/dinger/listeners/StartEventListener.java @@ -35,15 +35,6 @@ public class StartEventListener implements ApplicationListener 0) { - log.info("dingtalk has already been initialized."); - return; - } - if (log.isDebugEnabled()) { - log.debug("ready to execute ApplicationStartingEvent."); - } - ApplicationEventTimeTable.startTime = event.getTimestamp(); - Set allSources = event.getSpringApplication().getAllSources(); Set> primarySources = new HashSet<>(); for (Object source : allSources) { @@ -54,6 +45,6 @@ public void onApplicationEvent(ApplicationStartingEvent event) { } } } - ApplicationEventTimeTable.primarySources = primarySources; + DingerListenersProperty.primarySources = primarySources; } } \ No newline at end of file diff --git a/src/main/java/com/github/jaemon/dinger/listeners/SuccessEventListener.java b/src/main/java/com/github/jaemon/dinger/listeners/SuccessEventListener.java deleted file mode 100644 index 60ca244..0000000 --- a/src/main/java/com/github/jaemon/dinger/listeners/SuccessEventListener.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright ©2015-2020 Jaemon. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.github.jaemon.dinger.listeners; - -import com.github.jaemon.dinger.DingerSender; -import com.github.jaemon.dinger.constant.DingerConstant; -import com.github.jaemon.dinger.core.entity.DingerProperties; -import com.github.jaemon.dinger.core.entity.MsgType; -import com.github.jaemon.dinger.support.MonitorEventNotification; -import com.github.jaemon.dinger.entity.DingerResult; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.boot.context.event.ApplicationReadyEvent; -import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext; -import org.springframework.context.ApplicationListener; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.core.Ordered; - -/** - * Success Listener - * - * @author Jaemon - * @since 1.0 - */ -public class SuccessEventListener implements ApplicationListener, Ordered { - private static final Logger log = LoggerFactory.getLogger(SuccessEventListener.class); - - @Override - public void onApplicationEvent(ApplicationReadyEvent event) { - boolean debugEnabled = log.isDebugEnabled(); - - String monitor = System.getProperty(ApplicationEventTimeTable.DISABLED_DINTALK_MONITOR); - if (monitor != null && "true".equals(monitor.trim())) { - return; - } - - ConfigurableApplicationContext applicationContext = event.getApplicationContext(); - // fixed #3 - if (/*applicationContext.getParent() == null - && */AnnotationConfigServletWebServerApplicationContext.class.isInstance(applicationContext) - && ApplicationEventTimeTable.successTime == 0) { - if (debugEnabled) { - log.debug("ready to execute ApplicationReadyEvent."); - } - ApplicationEventTimeTable.successTime = event.getTimestamp(); - - DingerProperties properties = applicationContext.getBean(DingerProperties.class); - - if (properties.isEnabled() - && properties.getMonitor().isSuccess()) { - DingerSender dingTalkRobot = applicationContext.getBean(DingerSender.class); - MonitorEventNotification monitorEventNotification = applicationContext.getBean(MonitorEventNotification.class); - String projectId = properties.getProjectId(); - projectId = projectId == null ? DingerConstant.DINGER_PREFIX : projectId; - - MsgType message = monitorEventNotification.success(event, projectId); - String keyword = projectId + DingerConstant.SUCCESS_KEYWORD; - DingerResult result = dingTalkRobot.send(keyword, message); - if (debugEnabled) { - log.debug("keyword={}, result={}.", keyword, result.toString()); - } - } - - } else { - if (debugEnabled) { - log.debug("dingtalk success listener skip, context={}.", applicationContext.getClass().getName()); - } - } - - } - - @Override - public int getOrder() { - return Ordered.LOWEST_PRECEDENCE; - } -} \ No newline at end of file diff --git a/src/main/java/com/github/jaemon/dinger/listeners/package-info.java b/src/main/java/com/github/jaemon/dinger/listeners/package-info.java index 0f6a7b3..6fe5956 100644 --- a/src/main/java/com/github/jaemon/dinger/listeners/package-info.java +++ b/src/main/java/com/github/jaemon/dinger/listeners/package-info.java @@ -18,6 +18,6 @@ * Dinger事件监听包 * * @author Jaemon - * @since 4.0 + * @since 1.0 */ package com.github.jaemon.dinger.listeners; \ No newline at end of file diff --git a/src/main/java/com/github/jaemon/dinger/multi/DingerConfigHandler.java b/src/main/java/com/github/jaemon/dinger/multi/DingerConfigHandler.java index e2fb40a..d750532 100644 --- a/src/main/java/com/github/jaemon/dinger/multi/DingerConfigHandler.java +++ b/src/main/java/com/github/jaemon/dinger/multi/DingerConfigHandler.java @@ -16,7 +16,6 @@ package com.github.jaemon.dinger.multi; import com.github.jaemon.dinger.core.DingerConfig; -import com.github.jaemon.dinger.core.entity.enums.DingerType; import com.github.jaemon.dinger.multi.algorithm.AlgorithmHandler; import com.github.jaemon.dinger.multi.algorithm.DefaultHandler; import com.github.jaemon.dinger.multi.algorithm.DingerHandler; @@ -27,18 +26,10 @@ * DingerConfigHandler * * @author Jaemon - * @since 3.0 + * @since 1.0 */ public interface DingerConfigHandler { - /** - * 指定当前handler处理的dinger - * - * @return - * dinger {@link DingerType} - */ - DingerType dinger(); - /** * 多钉钉机器人配置 * diff --git a/src/main/java/com/github/jaemon/dinger/multi/MultiDingerAlgorithmInjectRegister.java b/src/main/java/com/github/jaemon/dinger/multi/MultiDingerAlgorithmInjectRegister.java index 1d79cb7..3ea2982 100644 --- a/src/main/java/com/github/jaemon/dinger/multi/MultiDingerAlgorithmInjectRegister.java +++ b/src/main/java/com/github/jaemon/dinger/multi/MultiDingerAlgorithmInjectRegister.java @@ -16,8 +16,9 @@ package com.github.jaemon.dinger.multi; import com.github.jaemon.dinger.core.DingerConfig; -import com.github.jaemon.dinger.entity.enums.ExceptionEnum; +import com.github.jaemon.dinger.core.entity.enums.ExceptionEnum; import com.github.jaemon.dinger.exception.DingerException; +import com.github.jaemon.dinger.exception.MultiDingerRegisterException; import com.github.jaemon.dinger.multi.algorithm.AlgorithmHandler; import com.github.jaemon.dinger.multi.entity.MultiDingerAlgorithmDefinition; import com.github.jaemon.dinger.multi.entity.MultiDingerConfig; @@ -34,6 +35,9 @@ import java.lang.reflect.Field; import java.util.*; +import static com.github.jaemon.dinger.constant.DingerConstant.SPOT_SEPERATOR; +import static com.github.jaemon.dinger.core.entity.enums.ExceptionEnum.ALGORITHM_FIELD_INJECT_FAILED; + /** * MultiDingerAlgorithmInjuctRegister * @@ -51,7 +55,7 @@ * * * @author Jaemon - * @since 3.0 + * @since 1.0 */ public class MultiDingerAlgorithmInjectRegister implements ApplicationContextAware, InitializingBean { private static final Logger log = LoggerFactory.getLogger(MultiDingerAlgorithmInjectRegister.class); @@ -74,7 +78,13 @@ public void afterPropertiesSet() throws Exception { return; } - multiDingerWithInjectAttributeHandler(); + try { + multiDingerWithInjectAttributeHandler(); + } catch (DingerException ex) { + throw new MultiDingerRegisterException(ex.getPairs(), ex.getMessage()); + } catch (Exception ex) { + throw new DingerException(ex, ExceptionEnum.UNKNOWN); + } } /** @@ -87,7 +97,7 @@ private void multiDingerWithInjectAttributeHandler() { MultiDingerScannerRegistrar.MULTIDINGER_ALGORITHM_DEFINITION_MAP.entrySet(); for (Map.Entry entry : entries) { - // v.key + SPOT_SEPERATOR + AlgorithmHandler.getSimpleName + // v.key(dinger) + SPOT_SEPERATOR + AlgorithmHandler.getSimpleName String beanName = entry.getKey(); MultiDingerAlgorithmDefinition v = entry.getValue(); Class algorithm = v.getAlgorithm(); @@ -97,13 +107,7 @@ private void multiDingerWithInjectAttributeHandler() { algorithmFieldInjection(algorithm, algorithmHandler); List dingerConfigs = v.getDingerConfigs(); - // check dingerConfig is valid - dingerConfigs.forEach(e -> { - e.check(); - if (e.checkEmpty()) { - throw new DingerException(algorithm.getSimpleName() + " dingerConfigs配置异常", ExceptionEnum.MULTI_DINGERCONFIGS_EXCEPTION); - } - }); + // v.getKey() is dingerClassName or MultiDingerConfigContainer#GLOABL_KEY MultiDingerConfigContainer.INSTANCE.put( v.getKey(), new MultiDingerConfig(algorithmHandler, dingerConfigs) @@ -127,7 +131,7 @@ private void multiDingerWithInjectAttributeHandler() { * algorithmHandler */ private void algorithmFieldInjection(Class algorithm, AlgorithmHandler algorithmHandler) { - boolean debugEnabled = log.isDebugEnabled(); + String algorithmSimpleName = algorithm.getSimpleName(); OK: for (Field declaredField : algorithm.getDeclaredFields()) { if (declaredField.isAnnotationPresent(Autowired.class)) { @@ -142,35 +146,29 @@ private void algorithmFieldInjection(Class algorithm // 从spring容器上下文中获取属性对应的实例 String[] actualBeanNames = applicationContext.getBeanNamesForType(declaredField.getType()); int length = actualBeanNames.length; - if (length == 0) { - // throw exception - if (debugEnabled) { - log.debug("algorithm={}'s field object {} can't be found from spring container.", - algorithm.getSimpleName(), fieldBeanName); - } - continue; - } else if (length == 1) { + if (length == 1) { fieldBeanName = actualBeanNames[0]; - } else { + } else if (length > 1) { final String fbn = fieldBeanName; long count = Arrays.stream(actualBeanNames).filter(e -> Objects.equals(e, fbn)).count(); - // throw exception if (count == 0) { - if (debugEnabled) { - log.debug("algorithm={}'s field object {} can't find a match from objects {}.", - algorithm.getSimpleName(), fieldBeanName, Arrays.asList(actualBeanNames)); - } - continue OK; + throw new DingerException( + ExceptionEnum.ALGORITHM_FIELD_INSTANCE_NOT_MATCH, algorithmSimpleName, fieldBeanName + ); } + } else { + throw new DingerException( + ExceptionEnum.ALGORITHM_FIELD_INSTANCE_NOT_EXISTS, algorithmSimpleName, fieldBeanName + ); } try { declaredField.setAccessible(true); declaredField.set(algorithmHandler, applicationContext.getBean(fieldBeanName)); } catch (IllegalAccessException e) { - log.warn("algorithm={}'s field={} injection failed, because of {}.", - algorithm.getSimpleName(), fieldBeanName, e.getMessage()); - continue OK; + throw new DingerException( + ALGORITHM_FIELD_INJECT_FAILED, algorithmSimpleName, fieldBeanName + ); } } diff --git a/src/main/java/com/github/jaemon/dinger/multi/MultiDingerConfigContainer.java b/src/main/java/com/github/jaemon/dinger/multi/MultiDingerConfigContainer.java index 6834392..24661a3 100644 --- a/src/main/java/com/github/jaemon/dinger/multi/MultiDingerConfigContainer.java +++ b/src/main/java/com/github/jaemon/dinger/multi/MultiDingerConfigContainer.java @@ -24,7 +24,7 @@ * MultiDingerConfigContainer * * @author Jaemon - * @since 3.0 + * @since 1.0 */ public enum MultiDingerConfigContainer { /** diff --git a/src/main/java/com/github/jaemon/dinger/multi/MultiDingerProperty.java b/src/main/java/com/github/jaemon/dinger/multi/MultiDingerProperty.java index ae99a99..9042312 100644 --- a/src/main/java/com/github/jaemon/dinger/multi/MultiDingerProperty.java +++ b/src/main/java/com/github/jaemon/dinger/multi/MultiDingerProperty.java @@ -19,7 +19,7 @@ * MultiDingerProperty * * @author Jaemon - * @since 3.0 + * @since 1.0 */ public class MultiDingerProperty { /** app start at multiDinger */ diff --git a/src/main/java/com/github/jaemon/dinger/multi/MultiDingerRefresh.java b/src/main/java/com/github/jaemon/dinger/multi/MultiDingerRefresh.java index 6d11dcd..503e171 100644 --- a/src/main/java/com/github/jaemon/dinger/multi/MultiDingerRefresh.java +++ b/src/main/java/com/github/jaemon/dinger/multi/MultiDingerRefresh.java @@ -21,7 +21,7 @@ * MultiDingerRefresh * * @author Jaemon - * @since 3.0 + * @since 1.0 */ public class MultiDingerRefresh extends DingerRefresh { diff --git a/src/main/java/com/github/jaemon/dinger/multi/MultiDingerScannerRegistrar.java b/src/main/java/com/github/jaemon/dinger/multi/MultiDingerScannerRegistrar.java index d440b79..7dd42fd 100644 --- a/src/main/java/com/github/jaemon/dinger/multi/MultiDingerScannerRegistrar.java +++ b/src/main/java/com/github/jaemon/dinger/multi/MultiDingerScannerRegistrar.java @@ -17,8 +17,10 @@ import com.github.jaemon.dinger.constant.DingerConstant; import com.github.jaemon.dinger.core.entity.enums.DingerType; -import com.github.jaemon.dinger.entity.enums.ExceptionEnum; +import com.github.jaemon.dinger.core.entity.enums.ExceptionEnum; +import com.github.jaemon.dinger.exception.MultiDingerRegisterException; import com.github.jaemon.dinger.listeners.DingerListenersProperty; +import com.github.jaemon.dinger.multi.annotations.MultiDinger; import com.github.jaemon.dinger.multi.entity.MultiDingerAlgorithmDefinition; import com.github.jaemon.dinger.core.DingerConfig; import com.github.jaemon.dinger.exception.DingerException; @@ -47,15 +49,14 @@ import java.util.Map; import static com.github.jaemon.dinger.constant.DingerConstant.SPOT_SEPERATOR; -import static com.github.jaemon.dinger.entity.enums.ExceptionEnum.GLOBAL_MULTIDINGER_CONFIG_EXCEPTION; -import static com.github.jaemon.dinger.entity.enums.ExceptionEnum.MULTIDINGER_ALGORITHM_EXCEPTION; +import static com.github.jaemon.dinger.core.entity.enums.ExceptionEnum.MULTIDINGER_ALGORITHM_EXCEPTION; import static com.github.jaemon.dinger.multi.MultiDingerConfigContainer.GLOABL_KEY; /** * MultiDingerScannerRegistrar * * @author Jaemon - * @since 3.0 + * @since 1.0 */ public class MultiDingerScannerRegistrar extends DingerListenersProperty @@ -76,53 +77,64 @@ public class MultiDingerScannerRegistrar @Override public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) { - boolean debugEnabled = log.isDebugEnabled(); log.info("ready to execute multiDingerScanner..."); try { - if (!importingClassMetadata.hasAnnotation(EnableMultiDinger.class.getName())) { - log.warn("import class can't find EnableMultiDinger annotation."); + doScanAndRegister(importingClassMetadata, registry); + } catch (DingerException ex) { + throw new MultiDingerRegisterException(ex.getPairs(), ex.getMessage()); + } catch (Exception ex) { + throw new DingerException(ex, ExceptionEnum.UNKNOWN); + } finally { + emptyDingerClasses(); + } + + } + + + private void doScanAndRegister(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) { + boolean debugEnabled = log.isDebugEnabled(); + if (!importingClassMetadata.hasAnnotation(EnableMultiDinger.class.getName())) { + log.warn("import class can't find EnableMultiDinger annotation."); + return; + } + + AnnotationAttributes annotationAttributes = AnnotationAttributes.fromMap( + importingClassMetadata.getAnnotationAttributes(EnableMultiDinger.class.getName()) + ); + + AnnotationAttributes[] value = annotationAttributes.getAnnotationArray("value"); + boolean aloneMulti = value.length == 0; + log.info("multi dinger register and is it global register? {}.", !aloneMulti); + // 指定多机器人配置处理逻辑 + if (aloneMulti) { + // 处理需要执行MultiDinger逻辑的dingerClass + List> dingerClasses = dingerClasses(); + if (dingerClasses.isEmpty()) { + log.warn("dinger class is empty, so no need to deal with multiDinger."); return; } - AnnotationAttributes annotationAttributes = AnnotationAttributes.fromMap( - importingClassMetadata.getAnnotationAttributes(EnableMultiDinger.class.getName()) - ); + multiDingerHandler(registry, dingerClasses); - Class value = annotationAttributes.getClass("value"); - log.info("multi dinger register and is it global register? {}-{}.", !value.isInterface(), value.getName()); - // 指定多机器人配置处理逻辑 - if (value.isInterface()) { - if (DingerConfigHandler.class.equals(value)) { - // 处理需要执行MultiDinger逻辑的dingerClass - List> dingerClasses = dingerClasses(); - if (dingerClasses.isEmpty()) { - log.warn("dinger class is empty, so no need to deal with multiDinger."); - return; - } - - multiDingerHandler(registry, dingerClasses); - - if (!MultiDingerConfigContainer.INSTANCE.isEmpty()) { - MultiDingerProperty.multiDinger = true; - } - } else { - throw new DingerException(GLOBAL_MULTIDINGER_CONFIG_EXCEPTION); - } + if (!MultiDingerConfigContainer.INSTANCE.isEmpty()) { + MultiDingerProperty.multiDinger = true; + } // 全局多机器人配置处理逻辑 - } else { + } else { + for (AnnotationAttributes attributes : value) { + DingerType dinger = attributes.getEnum("dinger"); + Class handler = attributes.getClass("handler"); + if (debugEnabled) { - log.debug("enable global multi dinger, and multiDinger handler class={}.", value.getName()); + log.debug("enable {} global multi dinger, and multiDinger handler class={}.", + dinger, handler.getName()); } - DingerConfigHandler dingerConfigHandler = BeanUtils.instantiateClass(value); - registerHandler(registry, GLOABL_KEY, dingerConfigHandler); + DingerConfigHandler dingerConfigHandler = BeanUtils.instantiateClass(handler); + registerHandler(registry, dinger, dinger + DingerConstant.SPOT_SEPERATOR + GLOABL_KEY, dingerConfigHandler); MultiDingerProperty.multiDinger = true; } - - } finally { - emptyDingerClasses(); } - } @@ -140,7 +152,8 @@ private void multiDingerHandler(BeanDefinitionRegistry registry, List> for (Class dingerClass : dingerClasses) { if (dingerClass.isAnnotationPresent(MultiHandler.class)) { MultiHandler multiDinger = dingerClass.getAnnotation(MultiHandler.class); - Class dingerConfigHandler = multiDinger.value(); + MultiDinger value = multiDinger.value(); + Class dingerConfigHandler = value.handler(); String beanName = dingerConfigHandler.getSimpleName(); // 如果DingerClass指定的MultiHandler对应的处理器为接口,则直接跳过 if (dingerConfigHandler.isInterface()) { @@ -150,9 +163,9 @@ private void multiDingerHandler(BeanDefinitionRegistry registry, List> } String key = dingerClass.getName(); DingerConfigHandler handler = ClassUtils.newInstance(dingerConfigHandler); - DingerType dinger = handler.dinger(); + DingerType dinger = value.dinger(); - registerHandler(registry, dinger + DingerConstant.SPOT_SEPERATOR + key, handler); + registerHandler(registry, dinger, dinger + DingerConstant.SPOT_SEPERATOR + key, handler); if (debugEnabled) { log.debug("regiseter multi dinger for dingerClass={} and dingerConfigHandler={}.", @@ -168,20 +181,22 @@ private void multiDingerHandler(BeanDefinitionRegistry registry, List> * * @param registry * 注册器 + * @param dinger + * Dinger类型 * @param key * 当前dingerClass类名 * @param dingerConfigHandler * dingerClass指定的multiHandler处理器 */ - private void registerHandler(BeanDefinitionRegistry registry, String key, DingerConfigHandler dingerConfigHandler) { - DingerType dinger = dingerConfigHandler.dinger(); + private void registerHandler(BeanDefinitionRegistry registry, DingerType dinger, String key, DingerConfigHandler dingerConfigHandler) { + String dingerConfigHandlerClassName = dingerConfigHandler.getClass().getSimpleName(); // 获取当前指定算法类名, 默认四种,或使用自定义 Class algorithm = dingerConfigHandler.algorithmHandler(); // if empty? use default dinger config List dingerConfigs = dingerConfigHandler.dingerConfigs(); if (algorithm == null) { - throw new DingerException(MULTIDINGER_ALGORITHM_EXCEPTION); + throw new DingerException(MULTIDINGER_ALGORITHM_EXCEPTION, dingerConfigHandlerClassName); } dingerConfigs.stream().forEach(e -> { @@ -189,9 +204,10 @@ private void registerHandler(BeanDefinitionRegistry registry, String key, Dinger }); for (int i = 0; i < dingerConfigs.size(); i++) { DingerConfig dingerConfig = dingerConfigs.get(i); - if (DingerUtils.isEmpty(dingerConfig.getTokenId()) || dinger != dingerConfig.getDingerType()) { - throw new DingerException(algorithm.getSimpleName() + "第" + i + "个dingerConfig配置异常", - ExceptionEnum.MULTI_DINGERCONFIGS_EXCEPTION); + if (DingerUtils.isEmpty(dingerConfig.getTokenId()) || ( + dingerConfig.getDingerType() != null && dinger != dingerConfig.getDingerType()) + ) { + throw new DingerException(ExceptionEnum.DINGER_CONFIG_HANDLER_EXCEPTION, dingerConfigHandlerClassName, i); } } @@ -216,7 +232,7 @@ key, new MultiDingerConfig(algorithmHandler, dingerConfigs) String beanName = key + SPOT_SEPERATOR + algorithm.getSimpleName(); registry.registerBeanDefinition(beanName, beanDefinition); MULTIDINGER_ALGORITHM_DEFINITION_MAP.put( - beanName, new MultiDingerAlgorithmDefinition(key, algorithm, dingerConfigs) + beanName, new MultiDingerAlgorithmDefinition(key, algorithm, dingerConfigs, dingerConfigHandlerClassName) ); mode = AnalysisEnum.SPRING_CONTAINER; } diff --git a/src/main/java/com/github/jaemon/dinger/multi/algorithm/AlgorithmHandler.java b/src/main/java/com/github/jaemon/dinger/multi/algorithm/AlgorithmHandler.java index c12a031..39d5f4f 100644 --- a/src/main/java/com/github/jaemon/dinger/multi/algorithm/AlgorithmHandler.java +++ b/src/main/java/com/github/jaemon/dinger/multi/algorithm/AlgorithmHandler.java @@ -24,7 +24,7 @@ * AlgorithmHandler * * @author Jaemon - * @since 3.0 + * @since 1.0 */ public interface AlgorithmHandler { /** 默认索引号从0开始 */ diff --git a/src/main/java/com/github/jaemon/dinger/multi/algorithm/DefaultHandler.java b/src/main/java/com/github/jaemon/dinger/multi/algorithm/DefaultHandler.java index 6817c5e..e0d1b80 100644 --- a/src/main/java/com/github/jaemon/dinger/multi/algorithm/DefaultHandler.java +++ b/src/main/java/com/github/jaemon/dinger/multi/algorithm/DefaultHandler.java @@ -28,7 +28,7 @@ * * * @author Jaemon - * @since 3.0 + * @since 1.0 */ public class DefaultHandler implements AlgorithmHandler { @Override diff --git a/src/main/java/com/github/jaemon/dinger/multi/algorithm/DingerHandler.java b/src/main/java/com/github/jaemon/dinger/multi/algorithm/DingerHandler.java index f723554..4267982 100644 --- a/src/main/java/com/github/jaemon/dinger/multi/algorithm/DingerHandler.java +++ b/src/main/java/com/github/jaemon/dinger/multi/algorithm/DingerHandler.java @@ -40,7 +40,7 @@ * * * @author Jaemon - * @since 3.0 + * @since 1.0 */ public class DingerHandler implements AlgorithmHandler { private static final Logger log = LoggerFactory.getLogger(DingerHandler.class); diff --git a/src/main/java/com/github/jaemon/dinger/multi/algorithm/RandomHandler.java b/src/main/java/com/github/jaemon/dinger/multi/algorithm/RandomHandler.java index 5618a18..e48189b 100644 --- a/src/main/java/com/github/jaemon/dinger/multi/algorithm/RandomHandler.java +++ b/src/main/java/com/github/jaemon/dinger/multi/algorithm/RandomHandler.java @@ -24,7 +24,7 @@ * 随机选择算法 * * @author Jaemon - * @since 3.0 + * @since 1.0 */ public class RandomHandler implements AlgorithmHandler { @Override diff --git a/src/main/java/com/github/jaemon/dinger/multi/algorithm/RoundRobinHandler.java b/src/main/java/com/github/jaemon/dinger/multi/algorithm/RoundRobinHandler.java index 9553472..d165dca 100644 --- a/src/main/java/com/github/jaemon/dinger/multi/algorithm/RoundRobinHandler.java +++ b/src/main/java/com/github/jaemon/dinger/multi/algorithm/RoundRobinHandler.java @@ -25,7 +25,7 @@ * 轮询算法 * * @author Jaemon - * @since 3.0 + * @since 1.0 */ public class RoundRobinHandler implements AlgorithmHandler { private static final Logger log = LoggerFactory.getLogger(RoundRobinHandler.class); diff --git a/src/main/java/com/github/jaemon/dinger/multi/annotations/EnableMultiDinger.java b/src/main/java/com/github/jaemon/dinger/multi/annotations/EnableMultiDinger.java index cf9b376..91cabef 100644 --- a/src/main/java/com/github/jaemon/dinger/multi/annotations/EnableMultiDinger.java +++ b/src/main/java/com/github/jaemon/dinger/multi/annotations/EnableMultiDinger.java @@ -15,6 +15,7 @@ */ package com.github.jaemon.dinger.multi.annotations; +import com.github.jaemon.dinger.core.entity.enums.DingerType; import com.github.jaemon.dinger.multi.DingerConfigHandler; import com.github.jaemon.dinger.multi.MultiDingerScannerRegistrar; import org.springframework.context.annotation.Import; @@ -25,7 +26,7 @@ * EnableMultiDinger * * @author Jaemon - * @since 3.0 + * @since 1.0 */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @@ -33,10 +34,6 @@ @Import(MultiDingerScannerRegistrar.class) public @interface EnableMultiDinger { - /** - * global dingerHandler - * - * @return {@link DingerConfigHandler} - */ - Class value() default DingerConfigHandler.class; + MultiDinger[] value() default {}; + } \ No newline at end of file diff --git a/src/main/java/com/github/jaemon/dinger/exception/DingerConfigRepeatedException.java b/src/main/java/com/github/jaemon/dinger/multi/annotations/MultiDinger.java similarity index 52% rename from src/main/java/com/github/jaemon/dinger/exception/DingerConfigRepeatedException.java rename to src/main/java/com/github/jaemon/dinger/multi/annotations/MultiDinger.java index 8aad881..bbc5eae 100644 --- a/src/main/java/com/github/jaemon/dinger/exception/DingerConfigRepeatedException.java +++ b/src/main/java/com/github/jaemon/dinger/multi/annotations/MultiDinger.java @@ -13,26 +13,34 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.github.jaemon.dinger.exception; +package com.github.jaemon.dinger.multi.annotations; -import com.github.jaemon.dinger.entity.enums.ExceptionEnum; +import com.github.jaemon.dinger.core.entity.enums.DingerType; +import com.github.jaemon.dinger.multi.DingerConfigHandler; + +import java.lang.annotation.*; /** - * DingerConfigRepeatedException + * MultiDinger * * @author Jaemon * @since 1.0 */ -public class DingerConfigRepeatedException extends DingerException { - public DingerConfigRepeatedException() { - super(ExceptionEnum.DINGER_CONFIG_REPEATED_EXCEPTION); - } - - public DingerConfigRepeatedException(String msg) { - super(msg, ExceptionEnum.DINGER_CONFIG_REPEATED_EXCEPTION); - } - - public DingerConfigRepeatedException(Throwable cause) { - super(cause, ExceptionEnum.DINGER_CONFIG_REPEATED_EXCEPTION); - } +@Target(ElementType.ANNOTATION_TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface MultiDinger { + /** + * 指定Dinger类型 + * + * @return + * dinger {@link DingerType} + */ + DingerType dinger(); + /** + * global dingerHandler + * + * @return {@link DingerConfigHandler} + */ + Class handler(); } \ No newline at end of file diff --git a/src/main/java/com/github/jaemon/dinger/multi/annotations/MultiHandler.java b/src/main/java/com/github/jaemon/dinger/multi/annotations/MultiHandler.java index 2ed47a3..0c3753e 100644 --- a/src/main/java/com/github/jaemon/dinger/multi/annotations/MultiHandler.java +++ b/src/main/java/com/github/jaemon/dinger/multi/annotations/MultiHandler.java @@ -15,20 +15,18 @@ */ package com.github.jaemon.dinger.multi.annotations; -import com.github.jaemon.dinger.multi.DingerConfigHandler; - import java.lang.annotation.*; /** * MultiHandler, 作用于 XXXDinger层,标识当前Dinger为多Dinger接口 * * @author Jaemon - * @since 3.0 + * @since 1.0 */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface MultiHandler { - Class value(); + MultiDinger value(); } \ No newline at end of file diff --git a/src/main/java/com/github/jaemon/dinger/multi/entity/MultiDinger.java b/src/main/java/com/github/jaemon/dinger/multi/entity/MultiDinger.java index b3453d1..eaa50d4 100644 --- a/src/main/java/com/github/jaemon/dinger/multi/entity/MultiDinger.java +++ b/src/main/java/com/github/jaemon/dinger/multi/entity/MultiDinger.java @@ -21,7 +21,7 @@ * MultiDinger * * @author Jaemon - * @since 3.0 + * @since 1.0 */ public class MultiDinger { private String key; diff --git a/src/main/java/com/github/jaemon/dinger/multi/entity/MultiDingerAlgorithmDefinition.java b/src/main/java/com/github/jaemon/dinger/multi/entity/MultiDingerAlgorithmDefinition.java index efd02ae..5703118 100644 --- a/src/main/java/com/github/jaemon/dinger/multi/entity/MultiDingerAlgorithmDefinition.java +++ b/src/main/java/com/github/jaemon/dinger/multi/entity/MultiDingerAlgorithmDefinition.java @@ -25,7 +25,7 @@ * MultiDingerAlgorithmDefinition * * @author Jaemon - * @since 3.0 + * @since 1.0 */ public class MultiDingerAlgorithmDefinition { /** @@ -46,11 +46,17 @@ public class MultiDingerAlgorithmDefinition { * 有效的钉钉机器人配置集合 */ private List dingerConfigs; + /** handler name */ + private String dingerConfigHandlerClassName; - public MultiDingerAlgorithmDefinition(String key, Class algorithm, List dingerConfigs) { + public MultiDingerAlgorithmDefinition( + String key, Class algorithm, + List dingerConfigs, String dingerConfigHandlerClassName + ) { this.key = key; this.algorithm = algorithm; this.dingerConfigs = dingerConfigs; + this.dingerConfigHandlerClassName = dingerConfigHandlerClassName; } public String getKey() { @@ -76,4 +82,12 @@ public List getDingerConfigs() { public void setDingerConfigs(List dingerConfigs) { this.dingerConfigs = dingerConfigs; } + + public String getDingerConfigHandlerClassName() { + return dingerConfigHandlerClassName; + } + + public void setDingerConfigHandlerClassName(String dingerConfigHandlerClassName) { + this.dingerConfigHandlerClassName = dingerConfigHandlerClassName; + } } \ No newline at end of file diff --git a/src/main/java/com/github/jaemon/dinger/multi/entity/MultiDingerConfig.java b/src/main/java/com/github/jaemon/dinger/multi/entity/MultiDingerConfig.java index db0bf1b..6fb5412 100644 --- a/src/main/java/com/github/jaemon/dinger/multi/entity/MultiDingerConfig.java +++ b/src/main/java/com/github/jaemon/dinger/multi/entity/MultiDingerConfig.java @@ -24,7 +24,7 @@ * MultiDingerConfig * * @author Jaemon - * @since 3.0 + * @since 1.0 */ public class MultiDingerConfig { private AlgorithmHandler algorithmHandler; diff --git a/src/main/java/com/github/jaemon/dinger/multi/package-info.java b/src/main/java/com/github/jaemon/dinger/multi/package-info.java index ce9893b..f24ac89 100644 --- a/src/main/java/com/github/jaemon/dinger/multi/package-info.java +++ b/src/main/java/com/github/jaemon/dinger/multi/package-info.java @@ -18,6 +18,6 @@ * 多DingerConfig配置 * * @author Jaemon - * @since 4.0 + * @since 1.0 */ package com.github.jaemon.dinger.multi; \ No newline at end of file diff --git a/src/main/java/com/github/jaemon/dinger/support/CustomMessage.java b/src/main/java/com/github/jaemon/dinger/support/CustomMessage.java index e7972d0..7098bfd 100644 --- a/src/main/java/com/github/jaemon/dinger/support/CustomMessage.java +++ b/src/main/java/com/github/jaemon/dinger/support/CustomMessage.java @@ -34,8 +34,6 @@ public interface CustomMessage { * projectId * @param title * 标题-{@link DingerType#DINGTALK}Markdown使用 - * @param keyword - * 关键字(方便日志检索) * @param content * 内容 * @param phones @@ -43,6 +41,6 @@ public interface CustomMessage { * @return * 消息内容字符串 */ - String message(String projectId, String title, String keyword, String content, List phones); + String message(String projectId, String title, String content, List phones); } \ No newline at end of file diff --git a/src/main/java/com/github/jaemon/dinger/support/DefaultApplicationEventNotification.java b/src/main/java/com/github/jaemon/dinger/support/DefaultApplicationEventNotification.java deleted file mode 100644 index 39317d1..0000000 --- a/src/main/java/com/github/jaemon/dinger/support/DefaultApplicationEventNotification.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright ©2015-2020 Jaemon. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.github.jaemon.dinger.support; - -import com.github.jaemon.dinger.listeners.ApplicationEventTimeTable; -import org.springframework.boot.context.event.ApplicationFailedEvent; -import org.springframework.boot.context.event.ApplicationReadyEvent; -import org.springframework.context.event.ContextClosedEvent; - -import java.text.MessageFormat; -import java.util.Optional; - -/** - * Default Application Event Notification - * - * @author Jaemon - * @since 1.0 - */ -public class DefaultApplicationEventNotification extends MonitorEventNotification { - @Override - public String successMessage(ApplicationReadyEvent event, String projectId) { - long startUpTime = (event.getTimestamp() - ApplicationEventTimeTable.startTime()) / 1000; - String message = MessageFormat.format( - "服务[{0}]启动成功, 整个启动过程共历时{1}秒.", - projectId, - startUpTime); - return message; - } - - @Override - public String failedMessage(ApplicationFailedEvent event, String projectId) { - String message = MessageFormat.format( - "服务[{0}]启动失败, 失败原因为[{1}].", - projectId, - Optional - .ofNullable(event) - .map(ApplicationFailedEvent::getException) - .map(Throwable::getCause) - .map(Throwable::getMessage) - .orElse(event.getException().getMessage())); - return message; - } - - @Override - public String exitMessage(ContextClosedEvent event, String projectId) { - long runningTime = 0; - if (ApplicationEventTimeTable.successTime() > 0) { - runningTime = (event.getTimestamp() - ApplicationEventTimeTable.successTime()) / 1000; - } - String message = MessageFormat.format( - "服务[{0}]已退出, 服务稳定运行时长为{1}秒.", - projectId, - runningTime); - return message; - } - -} \ No newline at end of file diff --git a/src/main/java/com/github/jaemon/dinger/support/DefaultDingerExceptionCallback.java b/src/main/java/com/github/jaemon/dinger/support/DefaultDingerExceptionCallback.java index 48594f3..e0c14ea 100644 --- a/src/main/java/com/github/jaemon/dinger/support/DefaultDingerExceptionCallback.java +++ b/src/main/java/com/github/jaemon/dinger/support/DefaultDingerExceptionCallback.java @@ -15,7 +15,7 @@ */ package com.github.jaemon.dinger.support; -import com.github.jaemon.dinger.entity.DingerCallback; +import com.github.jaemon.dinger.core.entity.DingerCallback; import com.github.jaemon.dinger.exception.DingerException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/com/github/jaemon/dinger/support/DingerExceptionCallback.java b/src/main/java/com/github/jaemon/dinger/support/DingerExceptionCallback.java index 606af90..5d5800e 100644 --- a/src/main/java/com/github/jaemon/dinger/support/DingerExceptionCallback.java +++ b/src/main/java/com/github/jaemon/dinger/support/DingerExceptionCallback.java @@ -15,7 +15,7 @@ */ package com.github.jaemon.dinger.support; -import com.github.jaemon.dinger.entity.DingerCallback; +import com.github.jaemon.dinger.core.entity.DingerCallback; /** * 发送异常回调接口 diff --git a/src/main/java/com/github/jaemon/dinger/support/MarkDownMessage.java b/src/main/java/com/github/jaemon/dinger/support/MarkDownMessage.java index 76d3815..ce48587 100644 --- a/src/main/java/com/github/jaemon/dinger/support/MarkDownMessage.java +++ b/src/main/java/com/github/jaemon/dinger/support/MarkDownMessage.java @@ -27,7 +27,7 @@ public class MarkDownMessage implements CustomMessage { @Override - public String message(String projectId, String title, String keyword, String content, List phones) { + public String message(String projectId, String title, String content, List phones) { // markdown在text内容里需要有@手机号 StringBuilder text = new StringBuilder(title); if (phones != null && !phones.isEmpty()) { @@ -36,7 +36,7 @@ public String message(String projectId, String title, String keyword, String con } } return MessageFormat.format( - "#### 【Dinger通知】 {0} \n - 项目名称: {1}\n- 检索关键字: {2}\n- 内容: {3}", - text, projectId, keyword, content); + "#### 【Dinger通知】 {0} \n - 项目名称: {1}\n- 内容: {2}", + text, projectId, content); } } \ No newline at end of file diff --git a/src/main/java/com/github/jaemon/dinger/support/MonitorEventNotification.java b/src/main/java/com/github/jaemon/dinger/support/MonitorEventNotification.java deleted file mode 100644 index e1db62b..0000000 --- a/src/main/java/com/github/jaemon/dinger/support/MonitorEventNotification.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright ©2015-2020 Jaemon. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.github.jaemon.dinger.support; - -import com.github.jaemon.dinger.core.entity.MsgType; -import com.github.jaemon.dinger.dingtalk.entity.DingText; -import org.springframework.boot.context.event.ApplicationFailedEvent; -import org.springframework.boot.context.event.ApplicationReadyEvent; -import org.springframework.context.event.ContextClosedEvent; - -/** - * Notification - * - * @author Jaemon - * @since 1.0 - */ -public abstract class MonitorEventNotification { - - /** - * success Message - * - * @param event {@link ApplicationReadyEvent} - * @param projectId DingTalkProperties#projectId - * @return message - */ - public abstract String successMessage(ApplicationReadyEvent event, String projectId); - - /** - * notification of success - * - * @param event {@link ApplicationReadyEvent} - * @param projectId DingTalkProperties#projectId - * @return message obj - */ - public MsgType success(ApplicationReadyEvent event, String projectId) { - String message = successMessage(event, projectId); - return message(message); - }; - - - /** - * failed Message - * - * @param event {@link ApplicationFailedEvent} - * @param projectId DingTalkProperties#projectId - * @return message - */ - public abstract String failedMessage(ApplicationFailedEvent event, String projectId); - - /** - * notification of failed - * - * @param event {@link ApplicationFailedEvent} - * @param projectId DingTalkProperties#projectId - * @return message obj - */ - public MsgType failed(ApplicationFailedEvent event, String projectId) { - String message = failedMessage(event, projectId); - return message(message); - } - - /** - * exit Message - * - * @param event {@link ContextClosedEvent} - * @param projectId DingTalkProperties#projectId - * @return message - */ - public abstract String exitMessage(ContextClosedEvent event, String projectId); - - /** - * notification of exit - * - * @param event {@link ContextClosedEvent} - * @param projectId DingTalkProperties#projectId - * @return message obj - */ - public MsgType exit(ContextClosedEvent event, String projectId) { - String message = exitMessage(event, projectId); - return message(message); - } - - /** - * message(default) - * - * @param text - * 消息内容 - * @return - * 具体消息对象 - */ - public MsgType message(String text) { - return new DingText(new DingText.Text(text)); - } -} \ No newline at end of file diff --git a/src/main/java/com/github/jaemon/dinger/support/TextMessage.java b/src/main/java/com/github/jaemon/dinger/support/TextMessage.java index 8fe6c31..3236002 100644 --- a/src/main/java/com/github/jaemon/dinger/support/TextMessage.java +++ b/src/main/java/com/github/jaemon/dinger/support/TextMessage.java @@ -27,9 +27,9 @@ public class TextMessage implements CustomMessage { @Override - public String message(String projectId, String title, String keyword, String content, List phones) { + public String message(String projectId, String title, String content, List phones) { return MessageFormat.format( - "【Dinger通知】 {0}\n- 项目名称: {1}\n- 检索关键字: {2}\n- 内容: {3}.", - title, projectId, keyword, content); + "【Dinger通知】 {0}\n- 项目名称: {1}\n- 内容: {2}.", + title, projectId, content); } } \ No newline at end of file diff --git a/src/main/java/com/github/jaemon/dinger/support/client/DingerHttpClient.java b/src/main/java/com/github/jaemon/dinger/support/client/DingerHttpClient.java index e53d4d0..50a0f34 100644 --- a/src/main/java/com/github/jaemon/dinger/support/client/DingerHttpClient.java +++ b/src/main/java/com/github/jaemon/dinger/support/client/DingerHttpClient.java @@ -23,7 +23,7 @@ * DingerHttpClient * * @author Jaemon - * @since 4.0 + * @since 1.0 */ public interface DingerHttpClient { diff --git a/src/main/java/com/github/jaemon/dinger/support/client/DingerHttpTemplate.java b/src/main/java/com/github/jaemon/dinger/support/client/DingerHttpTemplate.java index df1047f..9c3415a 100644 --- a/src/main/java/com/github/jaemon/dinger/support/client/DingerHttpTemplate.java +++ b/src/main/java/com/github/jaemon/dinger/support/client/DingerHttpTemplate.java @@ -30,7 +30,7 @@ * Dinger默认Http客户端 * * @author Jaemon - * @since 4.0 + * @since 1.0 */ public class DingerHttpTemplate extends AbstractDingerHttpClient { @Autowired diff --git a/src/main/java/com/github/jaemon/dinger/support/client/MediaTypeEnum.java b/src/main/java/com/github/jaemon/dinger/support/client/MediaTypeEnum.java index 911a24f..73b09a9 100644 --- a/src/main/java/com/github/jaemon/dinger/support/client/MediaTypeEnum.java +++ b/src/main/java/com/github/jaemon/dinger/support/client/MediaTypeEnum.java @@ -19,7 +19,7 @@ * 内容类型枚举 * * @author Jaemon - * @since 4.0 + * @since 1.0 */ public enum MediaTypeEnum { /** html */ diff --git a/src/main/java/com/github/jaemon/dinger/sign/DingTalkSignAlgorithm.java b/src/main/java/com/github/jaemon/dinger/support/sign/DingTalkSignAlgorithm.java similarity index 92% rename from src/main/java/com/github/jaemon/dinger/sign/DingTalkSignAlgorithm.java rename to src/main/java/com/github/jaemon/dinger/support/sign/DingTalkSignAlgorithm.java index cea80f6..ee4bb1e 100644 --- a/src/main/java/com/github/jaemon/dinger/sign/DingTalkSignAlgorithm.java +++ b/src/main/java/com/github/jaemon/dinger/support/sign/DingTalkSignAlgorithm.java @@ -13,10 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.github.jaemon.dinger.sign; +package com.github.jaemon.dinger.support.sign; import com.github.jaemon.dinger.core.entity.enums.DingerType; -import com.github.jaemon.dinger.entity.SignResult; /** * 默认签名算法 {@link DingerType#DINGTALK} diff --git a/src/main/java/com/github/jaemon/dinger/sign/DingerSignAlgorithm.java b/src/main/java/com/github/jaemon/dinger/support/sign/DingerSignAlgorithm.java similarity index 95% rename from src/main/java/com/github/jaemon/dinger/sign/DingerSignAlgorithm.java rename to src/main/java/com/github/jaemon/dinger/support/sign/DingerSignAlgorithm.java index 5117b0c..021ec08 100644 --- a/src/main/java/com/github/jaemon/dinger/sign/DingerSignAlgorithm.java +++ b/src/main/java/com/github/jaemon/dinger/support/sign/DingerSignAlgorithm.java @@ -13,9 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.github.jaemon.dinger.sign; - -import com.github.jaemon.dinger.entity.SignBase; +package com.github.jaemon.dinger.support.sign; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; diff --git a/src/main/java/com/github/jaemon/dinger/entity/SignBase.java b/src/main/java/com/github/jaemon/dinger/support/sign/SignBase.java similarity index 95% rename from src/main/java/com/github/jaemon/dinger/entity/SignBase.java rename to src/main/java/com/github/jaemon/dinger/support/sign/SignBase.java index c5c77c8..dd13f6b 100644 --- a/src/main/java/com/github/jaemon/dinger/entity/SignBase.java +++ b/src/main/java/com/github/jaemon/dinger/support/sign/SignBase.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.github.jaemon.dinger.entity; +package com.github.jaemon.dinger.support.sign; /** * 签名返回体基础类 diff --git a/src/main/java/com/github/jaemon/dinger/entity/SignResult.java b/src/main/java/com/github/jaemon/dinger/support/sign/SignResult.java similarity index 97% rename from src/main/java/com/github/jaemon/dinger/entity/SignResult.java rename to src/main/java/com/github/jaemon/dinger/support/sign/SignResult.java index c00989b..017ba81 100644 --- a/src/main/java/com/github/jaemon/dinger/entity/SignResult.java +++ b/src/main/java/com/github/jaemon/dinger/support/sign/SignResult.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.github.jaemon.dinger.entity; +package com.github.jaemon.dinger.support.sign; /** diff --git a/src/main/java/com/github/jaemon/dinger/utils/JVMRandom.java b/src/main/java/com/github/jaemon/dinger/utils/JVMRandom.java index c6abdbc..f0c5994 100644 --- a/src/main/java/com/github/jaemon/dinger/utils/JVMRandom.java +++ b/src/main/java/com/github/jaemon/dinger/utils/JVMRandom.java @@ -22,7 +22,7 @@ * Random methods via the {@link java.lang.Math#random()} method * and its system-wide {@link Random} object.

* - * @since 2.0 + * @since 1.0 * @version $Id: JVMRandom.java 471626 2006-11-06 04:02:09Z bayard $ */ public final class JVMRandom extends Random { diff --git a/src/main/java/com/github/jaemon/dinger/utils/PackageUtils.java b/src/main/java/com/github/jaemon/dinger/utils/PackageUtils.java index 763e82f..a719fbb 100644 --- a/src/main/java/com/github/jaemon/dinger/utils/PackageUtils.java +++ b/src/main/java/com/github/jaemon/dinger/utils/PackageUtils.java @@ -37,7 +37,7 @@ * PackageUtils * * @author Jaemon - * @since 2.0 + * @since 1.0 */ public class PackageUtils { private static final Logger log = LoggerFactory.getLogger(PackageUtils.class); diff --git a/src/main/java/com/github/jaemon/dinger/utils/RandomUtils.java b/src/main/java/com/github/jaemon/dinger/utils/RandomUtils.java index 627e96d..2a82eb2 100644 --- a/src/main/java/com/github/jaemon/dinger/utils/RandomUtils.java +++ b/src/main/java/com/github/jaemon/dinger/utils/RandomUtils.java @@ -23,7 +23,7 @@ * method and its system-wide Random object. * * @author Gary D. Gregory - * @since 2.0 + * @since 1.0 * @version $Id: RandomUtils.java 471626 2006-11-06 04:02:09Z bayard $ */ public class RandomUtils { diff --git a/src/main/java/com/github/jaemon/dinger/utils/XmlUtils.java b/src/main/java/com/github/jaemon/dinger/utils/XmlUtils.java index 1c9f8d0..1483705 100644 --- a/src/main/java/com/github/jaemon/dinger/utils/XmlUtils.java +++ b/src/main/java/com/github/jaemon/dinger/utils/XmlUtils.java @@ -27,7 +27,7 @@ * XML字符串JavaBean对象互转工具类 * * @author Jaemon - * @since 2.0 + * @since 1.0 */ public class XmlUtils { diff --git a/src/main/java/com/github/jaemon/dinger/wetalk/WeTalkDefinitionGenerator.java b/src/main/java/com/github/jaemon/dinger/wetalk/WeTalkDefinitionGenerator.java index f4622c8..ae82051 100644 --- a/src/main/java/com/github/jaemon/dinger/wetalk/WeTalkDefinitionGenerator.java +++ b/src/main/java/com/github/jaemon/dinger/wetalk/WeTalkDefinitionGenerator.java @@ -29,7 +29,7 @@ * 企业微信消息体定义生成类 * * @author Jaemon - * @since 4.0 + * @since 1.0 */ public class WeTalkDefinitionGenerator extends DingerDefinitionHandler { /** diff --git a/src/main/java/com/github/jaemon/dinger/wetalk/entity/WeImage.java b/src/main/java/com/github/jaemon/dinger/wetalk/entity/WeImage.java index cde45a5..8ad13b4 100644 --- a/src/main/java/com/github/jaemon/dinger/wetalk/entity/WeImage.java +++ b/src/main/java/com/github/jaemon/dinger/wetalk/entity/WeImage.java @@ -23,7 +23,7 @@ * 企业微信-消息类型-图片类型 * * @author Jaemon - * @since 4.0 + * @since 1.0 */ public class WeImage extends WeTalkMessage { diff --git a/src/main/java/com/github/jaemon/dinger/wetalk/entity/WeMarkdown.java b/src/main/java/com/github/jaemon/dinger/wetalk/entity/WeMarkdown.java index 1a973e8..bdc760c 100644 --- a/src/main/java/com/github/jaemon/dinger/wetalk/entity/WeMarkdown.java +++ b/src/main/java/com/github/jaemon/dinger/wetalk/entity/WeMarkdown.java @@ -24,7 +24,7 @@ * 企业微信-消息类型-markdown类型 * * @author Jaemon - * @since 4.0 + * @since 1.0 */ public class WeMarkdown extends WeTalkMessage { private Markdown markdown; diff --git a/src/main/java/com/github/jaemon/dinger/wetalk/entity/WeNews.java b/src/main/java/com/github/jaemon/dinger/wetalk/entity/WeNews.java index 5eeda6e..97da27f 100644 --- a/src/main/java/com/github/jaemon/dinger/wetalk/entity/WeNews.java +++ b/src/main/java/com/github/jaemon/dinger/wetalk/entity/WeNews.java @@ -24,7 +24,7 @@ * 企业微信-消息类型-图文类型 * * @author Jaemon - * @since 4.0 + * @since 1.0 */ public class WeNews extends WeTalkMessage { /** 图文类型 */ diff --git a/src/main/java/com/github/jaemon/dinger/wetalk/entity/WeTalkMessage.java b/src/main/java/com/github/jaemon/dinger/wetalk/entity/WeTalkMessage.java index af3dfee..041f131 100644 --- a/src/main/java/com/github/jaemon/dinger/wetalk/entity/WeTalkMessage.java +++ b/src/main/java/com/github/jaemon/dinger/wetalk/entity/WeTalkMessage.java @@ -22,7 +22,7 @@ * WeTalk请求体 * * @author Jaemon - * @since 4.0 + * @since 1.0 */ public class WeTalkMessage extends MsgType { public WeTalkMessage() { diff --git a/src/main/java/com/github/jaemon/dinger/wetalk/entity/WeText.java b/src/main/java/com/github/jaemon/dinger/wetalk/entity/WeText.java index 612adad..400772d 100644 --- a/src/main/java/com/github/jaemon/dinger/wetalk/entity/WeText.java +++ b/src/main/java/com/github/jaemon/dinger/wetalk/entity/WeText.java @@ -25,7 +25,7 @@ * 企业微信-消息类型-文本类型 * * @author Jaemon - * @since 4.0 + * @since 1.0 */ public class WeText extends WeTalkMessage { private Text text; diff --git a/src/main/java/com/github/jaemon/dinger/wetalk/entity/enums/WeTalkMsgType.java b/src/main/java/com/github/jaemon/dinger/wetalk/entity/enums/WeTalkMsgType.java index a0cce50..f08388c 100644 --- a/src/main/java/com/github/jaemon/dinger/wetalk/entity/enums/WeTalkMsgType.java +++ b/src/main/java/com/github/jaemon/dinger/wetalk/entity/enums/WeTalkMsgType.java @@ -19,7 +19,7 @@ * WeTalk支持的消息类型 * * @author Jaemon - * @since 4.0 + * @since 1.0 */ public enum WeTalkMsgType { /** diff --git a/src/main/java/com/github/jaemon/dinger/wetalk/package-info.java b/src/main/java/com/github/jaemon/dinger/wetalk/package-info.java index 214e7fd..e6571c9 100644 --- a/src/main/java/com/github/jaemon/dinger/wetalk/package-info.java +++ b/src/main/java/com/github/jaemon/dinger/wetalk/package-info.java @@ -15,9 +15,9 @@ */ /** - * WeTalk适配包 + * 支持WeTalk包 * * @author Jaemon - * @since 4.0 + * @since 1.0 */ package com.github.jaemon.dinger.wetalk; \ No newline at end of file diff --git a/src/main/resources/META-INF/spring.factories b/src/main/resources/META-INF/spring.factories index 6cc3128..30d5c78 100644 --- a/src/main/resources/META-INF/spring.factories +++ b/src/main/resources/META-INF/spring.factories @@ -8,7 +8,5 @@ com.github.jaemon.dinger.config.DingerThreadPoolConfig # Application Listeners org.springframework.context.ApplicationListener=\ com.github.jaemon.dinger.listeners.StartEventListener,\ -com.github.jaemon.dinger.listeners.SuccessEventListener,\ -com.github.jaemon.dinger.listeners.FailedEventListener,\ com.github.jaemon.dinger.listeners.ExitEventListener,\ com.github.jaemon.dinger.listeners.DingerXmlPreparedEvent \ No newline at end of file diff --git a/src/test/java/com/github/jaemon/dinger/core/OrderDinger.java b/src/test/java/com/github/jaemon/dinger/core/OrderDinger.java index e5f673d..9f789f3 100644 --- a/src/test/java/com/github/jaemon/dinger/core/OrderDinger.java +++ b/src/test/java/com/github/jaemon/dinger/core/OrderDinger.java @@ -17,7 +17,7 @@ import com.dingerframework.core.annatations.*; import com.github.jaemon.dinger.core.annatations.*; -import com.github.jaemon.dinger.entity.DingerResult; +import com.github.jaemon.dinger.core.entity.DingerResponse; import java.math.BigDecimal; @@ -25,14 +25,14 @@ * OrderDinger template * * @author Jaemon - * @since 2.0 + * @since 1.0 */ //@Dinger //@@DingerClose public interface OrderDinger { @DingerText(value = "订单号${orderNum}下单成功啦, 下单金额${amt}", phones = {"13520200906"}) - DingerResult orderSuccess( + DingerResponse orderSuccess( @Keyword String keyword, @Parameter("orderNum") String orderNo, @Parameter("amt") BigDecimal amt); @@ -47,7 +47,7 @@ DingerResult orderSuccess( value = "87dbeb7bc28894c3bdcc3d12457228ad590164327b5f427cd85f9025ebb350cf", secret = "SAQ23a9039bb01f2dcd017b90ab8e9dda1355f97c9016f37ff371ec8124327c7f09") ) - DingerResult orderFailed( + DingerResponse orderFailed( String orderNo, int num, boolean flag); diff --git a/src/test/java/com/github/jaemon/dinger/core/UserDinger.java b/src/test/java/com/github/jaemon/dinger/core/UserDinger.java index 56197ab..6fa4008 100644 --- a/src/test/java/com/github/jaemon/dinger/core/UserDinger.java +++ b/src/test/java/com/github/jaemon/dinger/core/UserDinger.java @@ -19,14 +19,14 @@ import com.github.jaemon.dinger.multi.annotations.MultiHandler; import com.github.jaemon.dinger.core.annatations.DingerMarkdown; import com.github.jaemon.dinger.core.annatations.DingerText; -import com.github.jaemon.dinger.entity.DingerResult; +import com.github.jaemon.dinger.core.entity.DingerResponse; import com.github.jaemon.dinger.multi.handler.UserDingerConfigHandler; /** * UserDinger * * @author Jaemon - * @since 3.0 + * @since 1.0 */ // 标识对应的处理器 @MultiHandler(UserDingerConfigHandler.class) @@ -40,7 +40,7 @@ public interface UserDinger { * result */ @DingerText(value = "恭喜用户${userName}注册成功!", phones = {"13520200906"}) - DingerResult userRegister(String userName); + DingerResponse userRegister(String userName); /** * 用户注销通知 @@ -57,5 +57,5 @@ public interface UserDinger { title = "用户注销反馈", phones = {"13520200906"} ) - DingerResult userLogout(@Parameter("userId") Long id, String userName); + DingerResponse userLogout(@Parameter("userId") Long id, String userName); } \ No newline at end of file diff --git a/src/test/java/com/github/jaemon/dinger/httpclient/HttpClientTemplate.java b/src/test/java/com/github/jaemon/dinger/httpclient/HttpClientTemplate.java index 81e8f45..ec3c524 100644 --- a/src/test/java/com/github/jaemon/dinger/httpclient/HttpClientTemplate.java +++ b/src/test/java/com/github/jaemon/dinger/httpclient/HttpClientTemplate.java @@ -28,7 +28,7 @@ * HttpClientTemplate * * @author Jaemon - * @since 4.0 + * @since 1.0 */ public class HttpClientTemplate { public static void main(String[] args) { diff --git a/src/test/java/com/github/jaemon/dinger/multi/DingerHandlerTest.java b/src/test/java/com/github/jaemon/dinger/multi/DingerHandlerTest.java index 788c364..7412eb6 100644 --- a/src/test/java/com/github/jaemon/dinger/multi/DingerHandlerTest.java +++ b/src/test/java/com/github/jaemon/dinger/multi/DingerHandlerTest.java @@ -33,7 +33,7 @@ * Dinger钉钉机器人算法-测试用例 {@link DingerHandler} * * @author Jaemon - * @since 3.0 + * @since 1.0 */ public class DingerHandlerTest { @@ -45,7 +45,7 @@ public static void main(String[] args) throws Exception { List dingerConfigs = new ArrayList<>(); for (int i = 0; i < 5; i++) { - DingerConfig dingerConfig = new DingerConfig(uuid()); + DingerConfig dingerConfig = DingerConfig.instance(uuid()); dingerConfigs.add(dingerConfig); } System.out.println(objectMapper.writeValueAsString( diff --git a/src/test/java/com/github/jaemon/dinger/multi/RoundRobinHandlerTest.java b/src/test/java/com/github/jaemon/dinger/multi/RoundRobinHandlerTest.java index d30311e..ad6cb84 100644 --- a/src/test/java/com/github/jaemon/dinger/multi/RoundRobinHandlerTest.java +++ b/src/test/java/com/github/jaemon/dinger/multi/RoundRobinHandlerTest.java @@ -35,7 +35,7 @@ * 轮询算法-测试用例 {@link RoundRobinHandler} * * @author Jaemon - * @since 3.0 + * @since 1.0 */ public class RoundRobinHandlerTest { @@ -47,7 +47,7 @@ public static void main(String[] args) throws Exception { List dingerConfigs = new ArrayList<>(); for (int i = 0; i < 5; i++) { - DingerConfig dingerConfig = new DingerConfig(uuid()); + DingerConfig dingerConfig = DingerConfig.instance(uuid()); dingerConfigs.add(dingerConfig); } System.out.println(objectMapper.writeValueAsString( diff --git a/src/test/java/com/github/jaemon/dinger/multi/handler/UserDingerConfigHandler.java b/src/test/java/com/github/jaemon/dinger/multi/handler/UserDingerConfigHandler.java index 93ed6e7..3ed7460 100644 --- a/src/test/java/com/github/jaemon/dinger/multi/handler/UserDingerConfigHandler.java +++ b/src/test/java/com/github/jaemon/dinger/multi/handler/UserDingerConfigHandler.java @@ -15,7 +15,6 @@ */ package com.github.jaemon.dinger.multi.handler; -import com.github.jaemon.dinger.core.entity.enums.DingerType; import com.github.jaemon.dinger.multi.DingerConfigHandler; import com.github.jaemon.dinger.multi.algorithm.AlgorithmHandler; import com.github.jaemon.dinger.multi.algorithm.DingerHandler; @@ -28,19 +27,14 @@ * UserDingerConfigHandler * * @author Jaemon - * @since 3.0 + * @since 1.0 */ public class UserDingerConfigHandler implements DingerConfigHandler { - @Override - public DingerType dinger() { - return DingerType.DINGTALK; - } - @Override public List dingerConfigs() { ArrayList dingerConfigs = new ArrayList<>(); - dingerConfigs.add(new DingerConfig("tokenId1", "secret1")); - dingerConfigs.add(new DingerConfig("tokenId2", "secret2")); + dingerConfigs.add(DingerConfig.instance("tokenId1", "secret1")); + dingerConfigs.add(DingerConfig.instance("tokenId2", "secret2")); // 如需配置更多机器人信息,可继续添加... return dingerConfigs; }