We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1.除了通过注解上获取biz,userCase,sence, 也可以通过重载getBizScenario 方法来获取 , 代码改造如下 public void doRegistration(ExtensionPointI extensionObject) { Class<?> extensionClz = extensionObject.getClass(); if (AopUtils.isAopProxy(extensionObject)) { extensionClz = AopUtils.getTargetClass(extensionObject); } Extension extensionAnn = AnnotatedElementUtils.findMergedAnnotation(extensionClz, Extension.class);
BizScenario bizScenario = BizScenario.valueOf(extensionAnn.bizId(), extensionAnn.useCase(), extensionAnn.scenario()); if (Objects.nonNull(extensionObject.getBizScenario())) { bizScenario=extensionObject.getBizScenario(); } ExtensionCoordinate extensionCoordinate = new ExtensionCoordinate(calculateExtensionPoint(extensionClz), bizScenario.getUniqueIdentity()); ExtensionPointI preVal = extensionRepository.getExtensionRepo().put(extensionCoordinate, extensionObject); if (preVal != null) { String errMessage = "Duplicate registration is not allowed for :" + extensionCoordinate; throw new ExtensionException(EXTENSION_DEFINE_DUPLICATE, errMessage); } }
public interface ExtensionPointI { default BizScenario getBizScenario(){ return null; } }
2.定义抽象BaseScenario,通过枚举类实现 BaseScenario,实现枚举场景类绑定扩展点,调用方代码如下,调用逻辑更加清晰哪个场景调用哪个方法 VerfiyServiceFeeRateScenarioEnum verfiyServiceFeeRateScenarioEnum =VerfiyServiceFeeRateScenarioEnum.fromCode(qry.getBusinessType() .getCode()); verfiyServiceFeeRateScenarioEnum.executeVoid(vt -> vt.verifyAccountServiceFeeRate(qry));
public interface BaseScenario {
String BIZ = "extension-biz"; /** * 业务标识 * @return */ default String getBizId(){ return LBIZ; } /** * 获取泛型实际的类型 * @return */ default Class<T> getActualType() { ParameterizedType parameterizedType = (ParameterizedType) this.getClass().getGenericInterfaces()[0]; return (Class<T>) parameterizedType.getActualTypeArguments()[0]; } /** * 自动根据枚举类生成场景 * @return */ default BizScenario bizScenarioOf() { BizScenario bizScenario = BizScenario.valueOf(getBizId(),this.getClass().getName(), this.toString()); return bizScenario; } /** * 执行没有返回值的方法 * @param exeFunction */ default void executeVoid(Consumer<T> exeFunction) { ExtensionExecutor extensionExecutor = SpringContextUtil.getBean(ExtensionExecutor.class); BizScenario bizScenario = this.bizScenarioOf(); ExtensionCoordinate extensionCoordinate = ExtensionCoordinate.valueOf(getActualType(), bizScenario); extensionExecutor.executeVoid(extensionCoordinate, exeFunction); } /**
public enum VerfiyServiceFeeRateScenarioEnum implements BaseScenario {
CITY_CARRIER(3, "test"), BUSINESS(4, "tes2"), SECONDARY_CARRIER(5, "test3"); private Integer code; private String desc; VerfiyServiceFeeRateScenarioEnum(Integer code, String desc) { this.code = code; this.desc = desc; } public static VerfiyServiceFeeRateScenarioEnum fromCode(Integer code) { return Arrays.stream(values()) .filter(o -> Objects.equals(code, o.getCode())) .findFirst() .orElseThrow(ExceptionHelper.supplyIllegalArgumentException("Illegal Value of JobListTabEnum: %s", code)); }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
1.除了通过注解上获取biz,userCase,sence, 也可以通过重载getBizScenario 方法来获取 ,
代码改造如下
public void doRegistration(ExtensionPointI extensionObject) {
Class<?> extensionClz = extensionObject.getClass();
if (AopUtils.isAopProxy(extensionObject)) {
extensionClz = AopUtils.getTargetClass(extensionObject);
}
Extension extensionAnn = AnnotatedElementUtils.findMergedAnnotation(extensionClz, Extension.class);
public interface ExtensionPointI {
default BizScenario getBizScenario(){
return null;
}
}
2.定义抽象BaseScenario,通过枚举类实现 BaseScenario,实现枚举场景类绑定扩展点,调用方代码如下,调用逻辑更加清晰哪个场景调用哪个方法
VerfiyServiceFeeRateScenarioEnum verfiyServiceFeeRateScenarioEnum =VerfiyServiceFeeRateScenarioEnum.fromCode(qry.getBusinessType()
.getCode());
verfiyServiceFeeRateScenarioEnum.executeVoid(vt -> vt.verifyAccountServiceFeeRate(qry));
public interface BaseScenario {
public enum VerfiyServiceFeeRateScenarioEnum implements BaseScenario {
The text was updated successfully, but these errors were encountered: