Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AuditValue 在插入时被重复执行 #1804

Open
infFox opened this issue May 16, 2024 · 2 comments
Open

AuditValue 在插入时被重复执行 #1804

infFox opened this issue May 16, 2024 · 2 comments

Comments

@infFox
Copy link

infFox commented May 16, 2024

问题描述及重现代码:

使用 SomeRepo.InsertAsync(obj) 插入新记录时,实际的 insert 语句执行了一次,但 AuditValue 会被执行两遍,导致字段值被重复处理。

下断点可以发现
第一次显示 AuditValueTypeInsert
image

第二次显示 AuditValueTypeUpdate
image

AuditValue 的代码:

        // 使用 AuditValue 实现对带 [Aes] 的字段自动加密
        fsql.Aop.AuditValue += (_, e) =>
        {
            if (e.Column.CsType == typeof(string))
            {
                var attr = e.Property.GetCustomAttribute<AesAttribute>(false);
                if (attr != null)
                {
                    // 使用 base64 模拟加密过程
                    var newval= Convert.ToBase64String(Encoding.UTF8.GetBytes(e.Value.ToString()));
                    Log.Error("进行加密 {Name} {Old} {New}", attr.KeyName, e.Value, newval);
                    e.Value = newval;
                }
            }
        };

打印的日志:
image

数据库版本

MySQL 5.7.23

安装的Nuget包

  • freesql 3.2.822
  • freesql.provider.mysqlconnector 3.2.822
  • freesql.repository 3.2.822

.net framework/. net core? 及具体版本

.NET 8.0.101

@2881099
Copy link
Collaborator

2881099 commented May 16, 2024

提供一个简易复现的demo

@infFox
Copy link
Author

infFox commented May 16, 2024

demo 里试了一下发现 AuditValue 还是被执行了两次,但是这回 insert 的语句中只使用了第一次处理后的值。

image

然后在原来的项目里重新尝试,虽然还是被执行了两次,也是只使用了第一次处理后的值

image

但是之前测试的时候 insert 语句里的值是被处理了两遍的。。。不过目前复现不出来了,可能是之前眼花了😂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants