|
@@ -60,62 +60,63 @@ public class MybatisSqlIntercept implements Interceptor {
|
|
|
@SneakyThrows
|
|
@SneakyThrows
|
|
|
@Override
|
|
@Override
|
|
|
public Object intercept(Invocation invocation) {
|
|
public Object intercept(Invocation invocation) {
|
|
|
|
|
+ try {
|
|
|
|
|
|
|
|
- Integer cpId = 0;
|
|
|
|
|
- if(httpServletRequest==null){
|
|
|
|
|
- log.info("mybatis查询拦截器=>请求头为空");
|
|
|
|
|
- return new Invocation(invocation.getTarget(), invocation.getMethod(), invocation.getArgs()).proceed();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ Integer cpId = 0;
|
|
|
|
|
+ if(httpServletRequest==null){
|
|
|
|
|
+ log.info("mybatis查询拦截器=>请求头为空");
|
|
|
|
|
+ return new Invocation(invocation.getTarget(), invocation.getMethod(), invocation.getArgs()).proceed();
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- String authorization = httpServletRequest.getHeader("Authorization");
|
|
|
|
|
|
|
+ String authorization = httpServletRequest.getHeader("Authorization");
|
|
|
|
|
|
|
|
- if(authorization != null) {
|
|
|
|
|
|
|
+ if(authorization != null) {
|
|
|
|
|
|
|
|
- String[] tokens = authorization.split(" ");
|
|
|
|
|
- String decrypt = AESSecurityUtil.decrypt(AESKey, tokens[1]);
|
|
|
|
|
- String cpIdString = JwtUtil.getCpId(decrypt);
|
|
|
|
|
- if (cpIdString != null) {
|
|
|
|
|
- //设置企业Id
|
|
|
|
|
- cpId = Integer.valueOf(cpIdString);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ String[] tokens = authorization.split(" ");
|
|
|
|
|
+ String decrypt = AESSecurityUtil.decrypt(AESKey, tokens[1]);
|
|
|
|
|
+ String cpIdString = JwtUtil.getCpId(decrypt);
|
|
|
|
|
+ if (cpIdString != null) {
|
|
|
|
|
+ //设置企业Id
|
|
|
|
|
+ cpId = Integer.valueOf(cpIdString);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- Object[] args = invocation.getArgs();
|
|
|
|
|
- Object[] args2 = new Object[4];
|
|
|
|
|
- args2[3] = args[3];
|
|
|
|
|
- args2[2] = args[2];
|
|
|
|
|
- if ((args[1] instanceof Map || args[1] instanceof Object) && checkType(args)) {
|
|
|
|
|
- Object argsNo2 = args[1];
|
|
|
|
|
- //map类型,对于数字的转换,如果直接转,Long给转成了Integer
|
|
|
|
|
- Map<String, Object> argsNo2Map = null;
|
|
|
|
|
- if (args[1] instanceof Map) {
|
|
|
|
|
- argsNo2Map = new HashMap<>();
|
|
|
|
|
- for (String key : ((Map<String, Object>) args[1]).keySet()) {
|
|
|
|
|
- argsNo2Map.put(key, ((Map<String, Object>) args[1]).get(key));
|
|
|
|
|
|
|
+ Object[] args = invocation.getArgs();
|
|
|
|
|
+ Object[] args2 = new Object[4];
|
|
|
|
|
+ args2[3] = args[3];
|
|
|
|
|
+ args2[2] = args[2];
|
|
|
|
|
+ if ((args[1] instanceof Map || args[1] instanceof Object) && checkType(args)) {
|
|
|
|
|
+ Object argsNo2 = args[1];
|
|
|
|
|
+ //map类型,对于数字的转换,如果直接转,Long给转成了Integer
|
|
|
|
|
+ Map<String, Object> argsNo2Map = null;
|
|
|
|
|
+ if (args[1] instanceof Map) {
|
|
|
|
|
+ argsNo2Map = new HashMap<>();
|
|
|
|
|
+ for (String key : ((Map<String, Object>) args[1]).keySet()) {
|
|
|
|
|
+ argsNo2Map.put(key, ((Map<String, Object>) args[1]).get(key));
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ try {
|
|
|
|
|
+ argsNo2Map = convertBeanToMap(args[1]);
|
|
|
|
|
+ } catch (Exception ignored) {
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- } else {
|
|
|
|
|
- try {
|
|
|
|
|
- argsNo2Map = convertBeanToMap(args[1]);
|
|
|
|
|
- } catch (Exception ignored) {
|
|
|
|
|
|
|
+ if (argsNo2Map != null) {
|
|
|
|
|
+ argsNo2Map.put("i18n", I18N);
|
|
|
|
|
+ if (cpId != 0 && argsNo2Map.get("cpId") == null) {
|
|
|
|
|
+ argsNo2Map.put("cpId", cpId);
|
|
|
|
|
+ }
|
|
|
|
|
+ args2[1] = argsNo2Map;
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
- if (argsNo2Map != null) {
|
|
|
|
|
|
|
+ } else {
|
|
|
|
|
+ Map<String, Object> argsNo2Map = new HashMap<>();
|
|
|
|
|
+ // 默认叫id
|
|
|
|
|
+ argsNo2Map.put("id", args[1]);
|
|
|
argsNo2Map.put("i18n", I18N);
|
|
argsNo2Map.put("i18n", I18N);
|
|
|
- if (cpId != 0 && argsNo2Map.get("cpId") == null) {
|
|
|
|
|
|
|
+ if (cpId != 0) {
|
|
|
argsNo2Map.put("cpId", cpId);
|
|
argsNo2Map.put("cpId", cpId);
|
|
|
}
|
|
}
|
|
|
args2[1] = argsNo2Map;
|
|
args2[1] = argsNo2Map;
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- Map<String, Object> argsNo2Map = new HashMap<>();
|
|
|
|
|
- // 默认叫id
|
|
|
|
|
- argsNo2Map.put("id", args[1]);
|
|
|
|
|
- argsNo2Map.put("i18n", I18N);
|
|
|
|
|
- if (cpId != 0) {
|
|
|
|
|
- argsNo2Map.put("cpId", cpId);
|
|
|
|
|
- }
|
|
|
|
|
- args2[1] = argsNo2Map;
|
|
|
|
|
// if(primaryKey != null ){
|
|
// if(primaryKey != null ){
|
|
|
// Map<String, Object> argsNo2Map = new HashMap<>();
|
|
// Map<String, Object> argsNo2Map = new HashMap<>();
|
|
|
// // 默认叫id
|
|
// // 默认叫id
|
|
@@ -128,18 +129,22 @@ public class MybatisSqlIntercept implements Interceptor {
|
|
|
// }else{
|
|
// }else{
|
|
|
// args2[1] = args[1];
|
|
// args2[1] = args[1];
|
|
|
// }
|
|
// }
|
|
|
- //TODO 在此添加单参数的逻辑 做法是获取父类的方法的参数名 然后把单参数转成Map传给xml
|
|
|
|
|
- }
|
|
|
|
|
- args2[0] = args[0];
|
|
|
|
|
- Invocation newInvocation = new Invocation(
|
|
|
|
|
- invocation.getTarget(), invocation.getMethod(), args2
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ //TODO 在此添加单参数的逻辑 做法是获取父类的方法的参数名 然后把单参数转成Map传给xml
|
|
|
|
|
+ }
|
|
|
|
|
+ args2[0] = args[0];
|
|
|
|
|
+ Invocation newInvocation = new Invocation(
|
|
|
|
|
+ invocation.getTarget(), invocation.getMethod(), args2
|
|
|
|
|
+ );
|
|
|
// MappedStatement mappedStatement = (MappedStatement) args[0];
|
|
// MappedStatement mappedStatement = (MappedStatement) args[0];
|
|
|
// String cmdType = mappedStatement.getSqlCommandType().name();
|
|
// String cmdType = mappedStatement.getSqlCommandType().name();
|
|
|
// if ("update".equalsIgnoreCase(cmdType)) {
|
|
// if ("update".equalsIgnoreCase(cmdType)) {
|
|
|
// List<Map<String,Object>> objList = SpringUtils.getBean(PlugMapper.class)
|
|
// List<Map<String,Object>> objList = SpringUtils.getBean(PlugMapper.class)
|
|
|
// }
|
|
// }
|
|
|
- return newInvocation.proceed();
|
|
|
|
|
|
|
+ return newInvocation.proceed();
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
|
+ log.error("mybatis查询拦截器获取参数异常=>{}",e);
|
|
|
|
|
+ return new Invocation(invocation.getTarget(), invocation.getMethod(), invocation.getArgs()).proceed();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private boolean checkType(Object[] args) {
|
|
private boolean checkType(Object[] args) {
|