|
@@ -1,5 +1,8 @@
|
|
|
package com.dgtly.apiframework.interceptor;
|
|
|
|
|
|
+import com.dgtly.common.annotation.SwitchEn;
|
|
|
+import com.dgtly.common.utils.ServletUtils;
|
|
|
+import com.dgtly.common.utils.StringUtils;
|
|
|
import org.apache.ibatis.cache.CacheKey;
|
|
|
import org.apache.ibatis.executor.Executor;
|
|
|
import org.apache.ibatis.mapping.BoundSql;
|
|
@@ -11,6 +14,8 @@ import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.lang.reflect.Method;
|
|
|
import java.util.Properties;
|
|
|
|
|
|
@Component
|
|
@@ -34,13 +39,37 @@ public class SwitchEnSqlInterceptor implements Interceptor {
|
|
|
Object parameter = invocation.getArgs()[1];
|
|
|
BoundSql boundSql = mappedStatement.getBoundSql(parameter);
|
|
|
String oldsql = boundSql.getSql();
|
|
|
- // log.info("old:"+oldsql);
|
|
|
- oldsql = oldsql.replaceAll("gi.name","gi.id name");
|
|
|
+ //oldsql = oldsql.replaceAll("gi.name","gi.name_en name");
|
|
|
+
|
|
|
+ //@TODO 获取前端标识是否切换获取中英文切换
|
|
|
+ HttpServletRequest request = ServletUtils.getRequest();
|
|
|
+
|
|
|
+ // 方法中含有获取注解
|
|
|
+ Class<?> classType = Class.forName(mappedStatement.getId().substring(0,mappedStatement.getId().lastIndexOf(".")));
|
|
|
+ String mName = mappedStatement.getId().substring(mappedStatement.getId().lastIndexOf(".") + 1 ,mappedStatement.getId().length());
|
|
|
+ for(Method method : classType.getDeclaredMethods()){
|
|
|
+ if(method!=null && mName.equals(method.getName()))
|
|
|
+ {
|
|
|
+ SwitchEn switchEn = method.getAnnotation(SwitchEn.class);
|
|
|
+ String[] oldfiles = switchEn.oldfiles();
|
|
|
+ String[] newfiles = switchEn.newfiles();
|
|
|
+ //旧字段和替换字段长度相同
|
|
|
+ if(newfiles.length==oldfiles.length){
|
|
|
+ for(int i = 0;i<oldfiles.length;i++){
|
|
|
+ oldsql = oldsql.replaceAll(oldfiles[i],newfiles[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // log.info("old:"+oldsql);
|
|
|
+
|
|
|
// 改变sql语句
|
|
|
BoundSql newBoundSql = new BoundSql(mappedStatement.getConfiguration(), oldsql ,
|
|
|
boundSql.getParameterMappings(), boundSql.getParameterObject());
|
|
|
invocation.getArgs()[5] = newBoundSql;
|
|
|
- // 注解invocation.method.annotations()
|
|
|
+
|
|
|
+
|
|
|
// 继续执行
|
|
|
Object result = invocation.proceed();
|
|
|
return result;
|