sunpengfei
2025-08-08 32288af3e5f12bc48d8360114c872fde5d9ff4a8
FlexJobApi.Core/Utils/DbUtils/DbUtils.cs
@@ -305,12 +305,14 @@
        /// <typeparam name="TEntity"></typeparam>
        /// <typeparam name="TRequest"></typeparam>
        /// <param name="request"></param>
        /// <param name="query"></param>
        /// <param name="checkExist"></param>
        /// <param name="update"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static async Task<Guid> SaveData<TEntity, TRequest>(
            this TRequest request,
            Func<IQueryable<TEntity>, IQueryable<TEntity>> query = null,
            Expression<Func<TEntity, bool>> checkExist = null,
            Action<TEntity> update = null,
            CancellationToken cancellationToken = default)
@@ -324,7 +326,9 @@
                throw Oops.Oh(EnumErrorCodeType.s405, $"该{summary ?? "信息"}");
            if (request.Id.HasValue)
            {
                var entity = await rep.AsQueryable().FirstOrDefaultAsync(it => it.Id == request.Id, cancellationToken);
                var q = rep.AsQueryable();
                if (query != null) q = query(q);
                var entity = await q.FirstOrDefaultAsync(it => it.Id == request.Id, cancellationToken);
                if (entity == null) throw Oops.Oh(EnumErrorCodeType.s404, $"该{summary ?? "信息"}");
                if (update != null) update(entity);
                else request.Adapt(entity);
@@ -451,10 +455,17 @@
                    }
                    // 赋值用户信息Id
                    prop = entity.Property(nameof(CommonEntity.CreatedUserInfoId));
                    prop = entity.Property(nameof(CommonEntity.CreatedUserId));
                    if (prop != null && prop.CurrentValue == null)
                    {
                        prop.CurrentValue = logier?.UserInfoId;
                        prop.CurrentValue = logier?.Id;
                    }
                    // 赋值企业Id
                    prop = entity.Property(nameof(CommonEntity.CreatedEnterpriseId));
                    if (prop != null && prop.CurrentValue == null)
                    {
                        prop.CurrentValue = logier?.EnterpriseId;
                    }
                    // 赋值跟踪Id
@@ -474,10 +485,10 @@
                    }
                    // 赋值用户信息Id
                    prop = entity.Property(nameof(CommonEntity.UpdatedUserInfoId));
                    prop = entity.Property(nameof(CommonEntity.UpdatedUserId));
                    if (prop != null)
                    {
                        prop.CurrentValue = logier?.UserInfoId;
                        prop.CurrentValue = logier?.Id;
                    }
                    // 赋值跟踪Id
@@ -523,7 +534,8 @@
                        : EnumDbAuditOperate.Deleted,
                    TraceId = App.GetTraceId(),
                    CreatedTime = DateTime.Now,
                    CreatedUserInfoId = logier?.UserInfoId,
                    CreatedUserId = logier?.Id,
                    CreatedEnterpriseId = logier?.EnterpriseId
                });
            }
        }