cmg
2024-06-22 cb38789006b411b29fba27a6a60493dc78946e17
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();