拼团后端添加对属性的操作

This commit is contained in:
xuwenbo
2020-08-19 17:11:37 +08:00
parent ec5c3e1e7c
commit b4932501fc
15 changed files with 485 additions and 34 deletions

View File

@ -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;
}

View File

@ -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();
}
}
}

View File

@ -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";
}