mirror of https://github.com/ZhongFuCheng3y/austin
commit
6eb61aea10
@ -1,42 +0,0 @@
|
||||
package com.java3y.austin.handler.script;
|
||||
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
/**
|
||||
* sms发送脚本的抽象类
|
||||
*
|
||||
* @author 3y
|
||||
*/
|
||||
@Slf4j
|
||||
public abstract class BaseSmsScript implements SmsScript {
|
||||
|
||||
@Autowired
|
||||
private SmsScriptHolder smsScriptHolder;
|
||||
|
||||
@PostConstruct
|
||||
public void registerProcessScript() {
|
||||
if (ArrayUtils.isEmpty(this.getClass().getAnnotations())) {
|
||||
log.error("BaseSmsScript can not find annotation!");
|
||||
return;
|
||||
}
|
||||
Annotation handlerAnnotations = null;
|
||||
for (Annotation annotation : this.getClass().getAnnotations()) {
|
||||
if (annotation instanceof SmsScriptHandler) {
|
||||
handlerAnnotations = annotation;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (handlerAnnotations == null) {
|
||||
log.error("handler annotations not declared");
|
||||
return;
|
||||
}
|
||||
//注册handler
|
||||
smsScriptHolder.putHandler(((SmsScriptHandler) handlerAnnotations).value(), this);
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package com.java3y.austin.handler.script;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
|
||||
/**
|
||||
* 标识 短信渠道
|
||||
*
|
||||
* @author 3y
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.TYPE})
|
||||
@Component
|
||||
public @interface SmsScriptHandler {
|
||||
|
||||
/**
|
||||
* 这里输入脚本名
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String value();
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package com.java3y.austin.handler.script;
|
||||
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* sendAccount->SmsScript的映射关系
|
||||
*
|
||||
* @author 3y
|
||||
*/
|
||||
@Component
|
||||
public class SmsScriptHolder {
|
||||
|
||||
private Map<String, SmsScript> handlers = new HashMap<>(8);
|
||||
|
||||
public void putHandler(String scriptName, SmsScript handler) {
|
||||
handlers.put(scriptName, handler);
|
||||
}
|
||||
public SmsScript route(String scriptName) {
|
||||
return handlers.get(scriptName);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue