chenjiahe
2022-06-28 4484acb56810d06ef5c2f78190a93688a61f83a7
src/main/java/com/hx/mybatis/aes/springbean/MySqlInterceptor.java
@@ -62,30 +62,23 @@
        //这里可以进行sql修改
        //获取到原始sql语句
        String sql = boundSql.getSql();
        String sql2 = null;
        //新增
        if(sqlCommandType == SqlCommandType.INSERT){
            sql2 = SqlUtils.insertSql(sql, VariableAesKey.aesKeysTable);
            sql = SqlUtils.insertSql(sql, VariableAesKey.aesKeysTable);
        }else if(sqlCommandType == SqlCommandType.UPDATE){
            sql2 = SqlUtils.updateSql(sql, VariableAesKey.aesKeysTable);
            sql = SqlUtils.updateSql(sql, VariableAesKey.aesKeysTable);
        }else if(sqlCommandType == SqlCommandType.SELECT){
            if(VariableAesKey.isRun == 1){
                sql2 = SqlUtils.selectSql(sql, VariableAesKey.aesKeysTable);
            }else{
                sql2  = sql;
                sql = SqlUtils.selectSql(sql, VariableAesKey.aesKeysTable);
            }
        }else if(sqlCommandType == SqlCommandType.DELETE){
            sql2 = SqlUtils.deleteSql(sql, VariableAesKey.aesKeysTable);
        }else{
            sql2  = sql;
            sql = SqlUtils.deleteSql(sql, VariableAesKey.aesKeysTable);
        }
        if(!"err".equals(sql2)){
            //通过反射修改sql语句
            Field field = boundSql.getClass().getDeclaredField("sql");
            field.setAccessible(true);
            field.set(boundSql, sql2);
        }
        //通过反射修改sql语句
        Field field = boundSql.getClass().getDeclaredField("sql");
        field.setAccessible(true);
        field.set(boundSql, sql);
        return invocation.proceed();