拼团后端添加对属性的操作
This commit is contained in:
@ -0,0 +1,15 @@
|
||||
package co.yixiang.annotation;
|
||||
|
||||
import co.yixiang.enums.DataSourceType;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface DataSource {
|
||||
/**
|
||||
* 切换数据源名称
|
||||
*/
|
||||
DataSourceType value() default DataSourceType.MASTER;
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package co.yixiang.aspect;
|
||||
|
||||
import co.yixiang.annotation.DataSource;
|
||||
import co.yixiang.config.datasource.DynamicDataSourceContextHolder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@Aspect
|
||||
@Order(1)
|
||||
@Component
|
||||
@Slf4j
|
||||
public class DataSourceAspect {
|
||||
|
||||
@Pointcut("@annotation(co.yixiang.annotation.DataSource)")
|
||||
public void dsPointCut() {
|
||||
|
||||
}
|
||||
|
||||
@Around("dsPointCut()")
|
||||
public Object around(ProceedingJoinPoint point) throws Throwable {
|
||||
MethodSignature signature = (MethodSignature) point.getSignature();
|
||||
Method method = signature.getMethod();
|
||||
DataSource dataSource = method.getAnnotation(DataSource.class);
|
||||
if (dataSource != null) {
|
||||
DynamicDataSourceContextHolder.setDataSourceType(dataSource.value().name());
|
||||
}
|
||||
try {
|
||||
return point.proceed();
|
||||
} finally {
|
||||
// 销毁数据源 在执行方法之后
|
||||
DynamicDataSourceContextHolder.clearDataSourceType();
|
||||
}
|
||||
}
|
||||
}
|
@ -49,4 +49,8 @@ public class SystemConfigConstants {
|
||||
public final static String WX_NATIVE_APP_APPID="wx_native_app_appId";
|
||||
public final static String EXP_APPID = "exp_appId";
|
||||
|
||||
|
||||
//播放状态变化事件,detail = {code}
|
||||
public static final String BINDSTATECHANGE = "bindstatechange";
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user