sunpengfei
2025-08-07 0b49fee10340ea40a6762da657239675d3db22f6
FlexJobApi.Core/Utils/DbUtils/DbUtils.cs
@@ -8,6 +8,7 @@
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using System;
@@ -98,7 +99,7 @@
        /// <param name="query"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static async Task<List<SelectQueryResultOption<TValue, TData>>> GetSelect<TEntity, TValue, TData>(
        public static async Task<List<SelectOption<TValue, TData>>> GetSelect<TEntity, TValue, TData>(
            this SelectQuery<TValue, TData> request,
            Func<TData, TValue> getValue,
            Func<TData, string> getLabel,
@@ -113,10 +114,10 @@
            var models = await q
                .ProjectToType<TData>()
                .ToListAsync(cancellationToken);
            var options = new List<SelectQueryResultOption<TValue, TData>>();
            var options = new List<SelectOption<TValue, TData>>();
            foreach (var model in models)
            {
                var option = new SelectQueryResultOption<TValue, TData>();
                var option = new SelectOption<TValue, TData>();
                option.Data = model;
                option.Value = getValue(model);
                option.Label = getLabel(model);
@@ -348,6 +349,8 @@
        /// <returns></returns>
        public static async Task BuildEntity(ModelBuilder modelBuilder, Type dbContextLocator = null)
        {
            if (App.GetService<IMigrator>() != null)
            {
            var xmlDoc = await XmlDocUtils.GetXmlDocAsync();
            foreach (var entityType in modelBuilder.Model.GetEntityTypes())
            {
@@ -376,7 +379,11 @@
                        entityBuilder.Property(property.Name).HasComment(propComment);
                    }
                }
                }
            }
            foreach (var entityType in modelBuilder.Model.GetEntityTypes())
            {
                if (typeof(CommonEntity).IsAssignableFrom(entityType.ClrType))
                {
                    // 构建筛选条件:IsDeleted == false
@@ -390,8 +397,6 @@
                    modelBuilder.Entity(entityType.ClrType).HasQueryFilter(lambda);
                }
            }
            Console.WriteLine("数据库链接地址:" + App.Configuration.GetConnectionString("FlexJobApi"));
        }
        /// <summary>
@@ -420,6 +425,7 @@
            // 通过请求中获取当前操作人
            var logier = JwtUtils.GetCurrentLogier();
            var traceId = App.GetTraceId();
            // 获取所有已更改的实体
            foreach (var entity in entities)
@@ -453,9 +459,9 @@
                    // 赋值跟踪Id
                    prop = entity.Property(nameof(CommonEntity.TraceId));
                    if (prop != null)
                    if (prop != null && prop.CurrentValue == null && traceId.IsNotNull())
                    {
                        prop.CurrentValue = App.GetTraceId();
                        prop.CurrentValue = traceId;
                    }
                }
                else
@@ -476,9 +482,9 @@
                    // 赋值跟踪Id
                    prop = entity.Property(nameof(CommonEntity.TraceId));
                    if (prop != null)
                    if (prop != null && traceId.IsNotNull())
                    {
                        prop.CurrentValue = App.GetTraceId();
                        prop.CurrentValue = traceId;
                    }
                    // 软删除