Skip to content

Commit

Permalink
feat: deploy dinger 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
AnswerAIL committed Dec 26, 2020
1 parent 9fc1c55 commit 5f155d7
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 93 deletions.
24 changes: 15 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ Dinger一个是以SpringBoot框架为基础开发的消息发送中间件, 对
<dependency>
<groupId>com.github.answerail</groupId>
<artifactId>dinger-spring-boot-starter</artifactId>
<version>1.0.0</version>
<version>${dinger.version}</version>
</dependency>
```
> [dinger.version版本号取值](https://github.com/AnswerAIL/dingtalk-spring-boot-starter/wiki/Dinger-1.1-Upgrade-Log)
### 配置文件配置
**使用钉钉群机器人配置**
Expand Down Expand Up @@ -89,30 +90,35 @@ public class AppInit implements InitializingBean {
}
}
```
更多功能请移步[Github Dinger wiki](https://github.com/AnswerAIL/dingtalk-spring-boot-starter/wiki) OR [Gitee Dinger wiki](https://gitee.com/jaemon/dingtalk-spring-boot-starter/wikis)


&nbsp;

## Documentation, Getting Started and Developer Guides
- [Dinger Wiki](https://github.com/AnswerAIL/dingtalk-spring-boot-starter/wiki)
- [Dinger Wiki-Github](https://github.com/AnswerAIL/dingtalk-spring-boot-starter/wiki)

- [Dinger Wiki-Gitee](https://gitee.com/jaemon/dingtalk-spring-boot-starter/wikis)


&nbsp;


## Upgrade Log
- [版本变更日志](https://github.com/AnswerAIL/dingtalk-spring-boot-starter/wiki/Dinger-Upgrade-Log)
- [版本变更日志-Github](https://github.com/AnswerAIL/dingtalk-spring-boot-starter/wiki/Dinger-1.2-Upgrade-Log)

- [版本变更日志-Gitee](https://gitee.com/jaemon/dingtalk-spring-boot-starter/wikis/Dinger-1.2-Upgrade-Log)


&nbsp;


## Feedback
***
> 有问题欢迎提Issue
>
> [github issues](https://github.com/AnswerAIL/dingtalk-spring-boot-starter/issues)
>
> [gitee issues](https://gitee.com/jaemon/dingtalk-spring-boot-starter/issues)
**有任何建议或问题欢迎提Issue~**

- [Issues-Github](https://github.com/AnswerAIL/dingtalk-spring-boot-starter/issues)

- [Issues-Gitee](https://gitee.com/jaemon/dingtalk-spring-boot-starter/issues)
***

&nbsp;
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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.config;

import com.github.jaemon.dinger.support.client.DingerHttpClient;
import com.github.jaemon.dinger.support.client.DingerHttpTemplate;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* 实例化bean配置
*
* @author Jaemon
* @since 1.0
*/
@Configuration
@AutoConfigureAfter(DingerHttpClientConfig.class)
public class AutoBeanConfiguration {
@Bean
public DingerHttpClient dingerHttpClient() {
return new DingerHttpTemplate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
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;
import com.github.jaemon.dinger.support.client.DingerHttpTemplate;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

import static com.github.jaemon.dinger.constant.DingerConstant.MARKDOWN_MESSAGE;
import static com.github.jaemon.dinger.constant.DingerConstant.TEXT_MESSAGE;
Expand All @@ -35,13 +34,9 @@
* @since 1.0
*/
@Configuration
@Import(AutoBeanConfiguration.class)
public class BeanConfiguration {

@Bean
public DingerHttpClient dingerHttpClient() {
return new DingerHttpTemplate();
}

/**
* 默认Text消息格式配置
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package com.github.jaemon.dinger.config;

import com.github.jaemon.dinger.constant.DingerConstant;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.convert.DurationUnit;
Expand All @@ -40,7 +40,7 @@
@Configuration
@ConditionalOnMissingBean(name = DingerConstant.DINGER_REST_TEMPLATE)
@ConfigurationProperties(prefix = DINGER_PROPERTIES_PREFIX + "http-client")
@AutoConfigureBefore(BeanConfiguration.class)
@AutoConfigureAfter(BeanConfiguration.class)
public class DingerHttpClientConfig {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.github.jaemon.dinger.core.annatations.DingerTokenId;
import com.github.jaemon.dinger.core.annatations.DingerMarkdown;
import com.github.jaemon.dinger.core.annatations.DingerText;
import com.github.jaemon.dinger.core.entity.DingerRequest;
import com.github.jaemon.dinger.core.entity.MsgType;
import com.github.jaemon.dinger.core.entity.enums.*;
import com.github.jaemon.dinger.core.entity.xml.*;
Expand Down Expand Up @@ -63,9 +64,16 @@ protected static DingerDefinition dingerTextHandler(DingerType dingerType, Dinge
dingerDefinition.setDingerType(dingerType);
dingerDefinition.setMessageSubType(MessageSubType.TEXT);

DingerRequest request;

if (dinger.atAll()) {
request = DingerRequest.request(dinger.value(), true);
} else {
request = DingerRequest.request(dinger.value(), Arrays.asList(dinger.phones()));
}

MsgType msgType = dingerDefinition.messageSubType().msgType(
dingerType, dinger.value(), null, Arrays.asList(dinger.phones()), dinger.atAll()
);
dingerType, request);
dingerDefinition.setMessage(msgType);

return dingerDefinition;
Expand All @@ -90,9 +98,8 @@ protected static DingerDefinition dingerMarkdownHandler(DingerType dingerType, D
dingerDefinition.setMessageSubType(MessageSubType.MARKDOWN);

// markdown not support at all members
MsgType msgType = dingerDefinition.messageSubType().msgType(
dingerType, dinger.value(), dinger.title(), Arrays.asList(dinger.phones()), false
);
DingerRequest request = DingerRequest.request(dinger.value(), dinger.title(), Arrays.asList(dinger.phones()));
MsgType msgType = dingerDefinition.messageSubType().msgType(dingerType, request);
dingerDefinition.setMessage(msgType);

return dingerDefinition;
Expand Down Expand Up @@ -153,8 +160,14 @@ protected static DingerDefinition xmlHandler(
String content = contentTag.map(e -> e.getContent()).orElse("");
String title = contentTag.map(e -> e.getTitle()).orElse("Dinger Title");

MsgType message = dingerDefinitionType.messageSubType().msgType(
dingerDefinitionType.dingerType(), content, title, phones, atAll);
DingerRequest request;
if (atAll) {
request = DingerRequest.request(content, title, true);
} else {
request = DingerRequest.request(content, title, phones);
}

MsgType message = dingerDefinitionType.messageSubType().msgType(dingerDefinitionType.dingerType(), request);
dingerDefinition.setMessage(message);

return dingerDefinition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
*/
package com.github.jaemon.dinger.core;

import com.github.jaemon.dinger.core.entity.enums.MessageSubType;
import com.github.jaemon.dinger.support.client.DingerHttpClient;
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;
import com.github.jaemon.dinger.support.DingerIdGenerator;
import com.github.jaemon.dinger.support.client.DingerHttpClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.client.RestTemplate;

import java.util.concurrent.Executor;

Expand All @@ -37,7 +37,8 @@
*/
public class DingerManagerBuilder {
@Autowired
DingerHttpClient dingerHttpClient;
@Qualifier(DINGER_REST_TEMPLATE)
RestTemplate dingerRestTemplate;
@Autowired
DingerExceptionCallback dingerExceptionCallback;
@Autowired
Expand All @@ -55,25 +56,27 @@ public class DingerManagerBuilder {
Executor dingTalkExecutor;
@Autowired
DingerAsyncCallback dingerAsyncCallback;
@Autowired
DingerHttpClient dingerHttpClient;

public DingerManagerBuilder() {
}

/**
* custom http client
* 自定义restTemplate客户端
*
* @param dingerHttpClient dingerHttpClient
* @param dingerRestTemplate restTemplate
* @return this
*/
public DingerManagerBuilder dingerHttpClient(DingerHttpClient dingerHttpClient) {
if (dingerHttpClient != null) {
this.dingerHttpClient = dingerHttpClient;
public DingerManagerBuilder dingerRestTemplate(RestTemplate dingerRestTemplate) {
if (dingerRestTemplate != null) {
this.dingerRestTemplate = dingerRestTemplate;
}
return this;
}

/**
* custom exception callback
* 自定义异常回调
*
* @param dingerExceptionCallback dingerExceptionCallback
* @return this
Expand All @@ -86,7 +89,15 @@ public DingerManagerBuilder dingerExceptionCallback(DingerExceptionCallback ding
}

/**
* custom text message format for {@link MessageSubType#TEXT}
* 自定义text文本消息体-仅限手动发送方式
*
* <pre>
* // 该方式为手动发送消息体方式
* dingerSender.send(...);
*
* // 该方式为统一管理消息体方式
* userDinger.success(...);
* </pre>
*
* @param textMessage textMessage
* @return this
Expand All @@ -99,7 +110,15 @@ public DingerManagerBuilder textMessage(CustomMessage textMessage) {
}

/**
* custom markdown message format for {@link MessageSubType#MARKDOWN}
* 自定义markdown消息体-仅限手动发送方式
*
* <pre>
* // 该方式为手动发送消息体方式
* dingerSender.send(...);
*
* // 该方式为统一管理消息体方式
* userDinger.success(...);
* </pre>
*
* @param markDownMessage markDownMessage
* @return this
Expand All @@ -112,7 +131,7 @@ public DingerManagerBuilder markDownMessage(CustomMessage markDownMessage) {
}

/**
* custom sign algorithm
* 自定义签名算法,仅限钉钉签名算法更改情况下使用
*
* @param dingerSignAlgorithm dingerSignAlgorithm
* @return this
Expand All @@ -125,7 +144,7 @@ public DingerManagerBuilder dingerSignAlgorithm(DingerSignAlgorithm dingerSignAl
}

/**
* custom id generator
* 自定义DingerId生成器,dingerId为每次调用返回体中的logid值
*
* @param dingerIdGenerator dingerIdGenerator
* @return this
Expand All @@ -138,7 +157,7 @@ public DingerManagerBuilder dingerIdGenerator(DingerIdGenerator dingerIdGenerato
}

/**
* custom async executor
* 自定义异步执行线程池
*
* @param dingTalkExecutor dingTalkExecutor
* @return this
Expand All @@ -151,7 +170,7 @@ public DingerManagerBuilder dingTalkExecutor(Executor dingTalkExecutor) {
}

/**
* custom async callback
* 自定义异步回调函数-用于异步发送时
*
* @param dingerAsyncCallback dingerAsyncCallback
* @return this
Expand Down
35 changes: 6 additions & 29 deletions src/main/java/com/github/jaemon/dinger/core/DingerRobot.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,49 +49,25 @@ public DingerRobot(DingerProperties dingerProperties, DingerManagerBuilder dingT

@Override
public DingerResponse send(MessageSubType messageSubType, DingerRequest request) {
return send(dingerProperties.getDefaultDinger(), messageSubType, request.getTitle(), request.getContent(), request.getPhones(), request.isAtAll());
return send(dingerProperties.getDefaultDinger(), messageSubType, request);
}

@Override
public DingerResponse send(DingerType dingerType, MessageSubType messageSubType, DingerRequest request) {
return send(dingerType, messageSubType, request.getTitle(), request.getContent(), request.getPhones(), request.isAtAll());
}

/**
* 发送预警消息到钉钉-艾特所有人
*
* <pre>
* markdown不支持艾特全部
* </pre>
*
* @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<String> phones, boolean atAll) {
CustomMessage customMessage = customMessage(messageSubType);
String msgContent = customMessage.message(
dingerProperties.getProjectId(), title, content, phones
dingerProperties.getProjectId(), request
);
request.setContent(msgContent);

MsgType msgType = messageSubType.msgType(
dingerType, msgContent, title, phones, atAll
dingerType, request
);

return send(msgType);
}


/**
* @param message
* 消息内容
Expand Down Expand Up @@ -121,6 +97,7 @@ protected <T extends MsgType> DingerResponse send(T message) {
if (dingerConfig) {
dinger = new DingerProperties.Dinger();
BeanUtils.copyProperties(localDinger, dinger);
dinger.setAsync(localDinger.getAsyncExecute());
dinger.setRobotUrl(dingers.get(dingerType).getRobotUrl());
} else {
dinger = dingers.get(dingerType);
Expand Down
Loading

0 comments on commit 5f155d7

Please sign in to comment.