From c42614978ff12013a1eabebd0289b27169a5784f Mon Sep 17 00:00:00 2001 From: liurunyu <lry9898@163.com> Date: 星期二, 06 五月 2025 17:25:56 +0800 Subject: [PATCH] 1、实现万功能token(0000-0000-1234-9876-5); 2、web端单独实现命令结果等待器,并相应修改相关部分; 3、web端实现透传命令; 4、修改一些不当注释; 5、优化一些代码。 --- pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/multiDataSource/DataSourceAspect.java | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 60 insertions(+), 0 deletions(-) diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/multiDataSource/DataSourceAspect.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/multiDataSource/DataSourceAspect.java new file mode 100644 index 0000000..2d1a8c7 --- /dev/null +++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/multiDataSource/DataSourceAspect.java @@ -0,0 +1,60 @@ +package com.dy.common.multiDataSource; + +import com.dy.common.contant.Constant; +import com.mysql.cj.util.StringUtils; +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; +import java.util.Objects; + +/** + * 澶氭暟鎹簮搴旂敤涓紝閫氳繃娉ㄨВ纭畾鏌愪釜鏁版嵁婧� + * 渚嬪鍦⊿ervices灞傛柟娉曚笂娉ㄨВ锛� + * @DataSource("test") + * 琛ㄧず搴旂敤鏁版嵁婧恡est + */ +@Slf4j +@Aspect +@Order(Constant.AspectOrderDataSource) +@Component +public class DataSourceAspect { + + @Pointcut("@annotation(com.dy.common.multiDataSource.DataSource)") + public void dataSourcePointCut() { + } + + @Around("dataSourcePointCut()") + public Object around(ProceedingJoinPoint point) throws Throwable { + MethodSignature signature = (MethodSignature) point.getSignature(); + Method method = signature.getMethod(); + DataSource dataSource = method.getAnnotation(DataSource.class); + + if (Objects.nonNull(dataSource) && !StringUtils.isNullOrEmpty(dataSource.value())) { + //log.info("鍒囨崲鏁版嵁婧愪负" + dataSource.value()); + //寮哄埗杞垚鏂规硶涓婇厤缃殑鏁版嵁婧愶紝鏇挎崲鎺塂ataSourceContext涓繚瀛樼殑鏁版嵁婧� + DataSourceContext.set(dataSource.value()); + }else{ + String dataSourceName = DataSourceContext.get() ; + if(!StringUtils.isNullOrEmpty(dataSourceName)){ + log.info("褰撳墠鏁版嵁婧愪负" + dataSourceName); + } + } + + try { + log.info("鏁版嵁搴撴搷浣滃紑濮�" + dataSource.value()); + return point.proceed(); + } finally { + // 閿�姣佹暟鎹簮 鍦ㄦ墽琛屾柟娉曚箣鍚� + log.info("鏁版嵁婧愭搷浣滃畬姣�" + dataSource.value()); + DataSourceContext.remove(); + } + } + +} \ No newline at end of file -- Gitblit v1.8.0