mirror of
				https://github.com/nsnail/NetAdmin.git
				synced 2025-11-01 03:35:28 +08:00 
			
		
		
		
	fix: 🐛 version 条件重复指定
This commit is contained in:
		| @@ -3,7 +3,6 @@ using Microsoft.Net.Http.Headers; | |||||||
| using NetAdmin.Application.Repositories; | using NetAdmin.Application.Repositories; | ||||||
| using NetAdmin.Domain; | using NetAdmin.Domain; | ||||||
| using NetAdmin.Domain.DbMaps.Dependency; | using NetAdmin.Domain.DbMaps.Dependency; | ||||||
| using NetAdmin.Domain.DbMaps.Dependency.Fields; |  | ||||||
| using NetAdmin.Domain.Dto.Dependency; | using NetAdmin.Domain.Dto.Dependency; | ||||||
|  |  | ||||||
| namespace NetAdmin.Application.Services; | namespace NetAdmin.Application.Services; | ||||||
| @@ -65,19 +64,17 @@ public abstract class RepositoryService<TEntity, TPrimary, TLogger>(BasicReposit | |||||||
|     /// <param name="excludeFields">排除的属性</param> |     /// <param name="excludeFields">排除的属性</param> | ||||||
|     /// <param name="whereExp">查询表达式</param> |     /// <param name="whereExp">查询表达式</param> | ||||||
|     /// <param name="whereSql">查询sql</param> |     /// <param name="whereSql">查询sql</param> | ||||||
|     /// <param name="ignoreVersion">是否忽略版本锁</param> |  | ||||||
|     /// <returns>更新行数</returns> |     /// <returns>更新行数</returns> | ||||||
|     protected Task<int> UpdateAsync(                         // |     protected Task<int> UpdateAsync(                         // | ||||||
|         TEntity                         newValue             // |         TEntity                         newValue             // | ||||||
|       , IEnumerable<string>             includeFields        // |       , IEnumerable<string>             includeFields        // | ||||||
|       , string[]                        excludeFields = null // |       , string[]                        excludeFields = null // | ||||||
|       , Expression<Func<TEntity, bool>> whereExp      = null // |       , Expression<Func<TEntity, bool>> whereExp      = null // | ||||||
|       , string                          whereSql      = null // |       , string                          whereSql      = null) | ||||||
|       , bool                            ignoreVersion = false) |  | ||||||
|     { |     { | ||||||
|         // 默认匹配主键 |         // 默认匹配主键 | ||||||
|         whereExp ??= a => a.Id.Equals(newValue.Id); |         whereExp ??= a => a.Id.Equals(newValue.Id); | ||||||
|         var update = BuildUpdate(newValue, includeFields, excludeFields, ignoreVersion).Where(whereExp).Where(whereSql); |         var update = BuildUpdate(newValue, includeFields, excludeFields).Where(whereExp).Where(whereSql); | ||||||
|         return update.ExecuteAffrowsAsync(); |         return update.ExecuteAffrowsAsync(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -90,19 +87,17 @@ public abstract class RepositoryService<TEntity, TPrimary, TLogger>(BasicReposit | |||||||
|     /// <param name="excludeFields">排除的属性</param> |     /// <param name="excludeFields">排除的属性</param> | ||||||
|     /// <param name="whereExp">查询表达式</param> |     /// <param name="whereExp">查询表达式</param> | ||||||
|     /// <param name="whereSql">查询sql</param> |     /// <param name="whereSql">查询sql</param> | ||||||
|     /// <param name="ignoreVersion">是否忽略版本锁</param> |  | ||||||
|     /// <returns>更新后的实体列表</returns> |     /// <returns>更新后的实体列表</returns> | ||||||
|     protected Task<List<TEntity>> UpdateReturnListAsync(     // |     protected Task<List<TEntity>> UpdateReturnListAsync(     // | ||||||
|         TEntity                         newValue             // |         TEntity                         newValue             // | ||||||
|       , IEnumerable<string>             includeFields        // |       , IEnumerable<string>             includeFields        // | ||||||
|       , string[]                        excludeFields = null // |       , string[]                        excludeFields = null // | ||||||
|       , Expression<Func<TEntity, bool>> whereExp = null // |       , Expression<Func<TEntity, bool>> whereExp      = null // | ||||||
|       , string                          whereSql = null // |       , string                          whereSql      = null) | ||||||
|       , bool                            ignoreVersion = false) |  | ||||||
|     { |     { | ||||||
|         // 默认匹配主键 |         // 默认匹配主键 | ||||||
|         whereExp ??= a => a.Id.Equals(newValue.Id); |         whereExp ??= a => a.Id.Equals(newValue.Id); | ||||||
|         return BuildUpdate(newValue, includeFields, excludeFields, ignoreVersion).Where(whereExp).Where(whereSql).ExecuteUpdatedAsync(); |         return BuildUpdate(newValue, includeFields, excludeFields).Where(whereExp).Where(whereSql).ExecuteUpdatedAsync(); | ||||||
|     } |     } | ||||||
|     #endif |     #endif | ||||||
|  |  | ||||||
| @@ -132,11 +127,10 @@ public abstract class RepositoryService<TEntity, TPrimary, TLogger>(BasicReposit | |||||||
|         return new FileStreamResult(stream, Chars.FLG_HTTP_HEADER_VALUE_APPLICATION_OCTET_STREAM); |         return new FileStreamResult(stream, Chars.FLG_HTTP_HEADER_VALUE_APPLICATION_OCTET_STREAM); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private IUpdate<TEntity> BuildUpdate(        // |     private IUpdate<TEntity> BuildUpdate( // | ||||||
|         TEntity             entity               // |         TEntity             entity        // | ||||||
|       , IEnumerable<string> includeFields        // |       , IEnumerable<string> includeFields // | ||||||
|       , string[]            excludeFields = null // |       , string[]            excludeFields = null) | ||||||
|       , bool                ignoreVersion = false) |  | ||||||
|     { |     { | ||||||
|         var updateExp = includeFields == null |         var updateExp = includeFields == null | ||||||
|             ? Rpo.UpdateDiy.SetSource(entity) |             ? Rpo.UpdateDiy.SetSource(entity) | ||||||
| @@ -146,10 +140,6 @@ public abstract class RepositoryService<TEntity, TPrimary, TLogger>(BasicReposit | |||||||
|             updateExp = updateExp.IgnoreColumns(excludeFields); |             updateExp = updateExp.IgnoreColumns(excludeFields); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (!ignoreVersion && entity is IFieldVersion ver) { |  | ||||||
|             updateExp = updateExp.Where($"{nameof(IFieldVersion.Version)} = @version", new { version = ver.Version }); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         return updateExp; |         return updateExp; | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @@ -59,10 +59,10 @@ public record Sys_Job : VersionEntity, IFieldEnabled, IFieldSummary | |||||||
|     /// <summary> |     /// <summary> | ||||||
|     ///     上次执行状态 |     ///     上次执行状态 | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     [Column] |     [Column(DbType = Chars.FLG_DB_FIELD_TYPE_SMALL_INT)] | ||||||
|     [CsvIgnore] |     [CsvIgnore] | ||||||
|     [JsonIgnore] |     [JsonIgnore] | ||||||
|     public HttpStatusCode? LastStatusCode { get; init; } |     public int? LastStatusCode { get; init; } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     ///     下次执行时间 |     ///     下次执行时间 | ||||||
|   | |||||||
| @@ -20,13 +20,11 @@ public record QueryJobRsp : Sys_Job | |||||||
|     /// <inheritdoc cref="Sys_Job.LastStatusCode" /> |     /// <inheritdoc cref="Sys_Job.LastStatusCode" /> | ||||||
|     [JsonInclude] |     [JsonInclude] | ||||||
|     public new virtual string LastStatusCode => |     public new virtual string LastStatusCode => | ||||||
|         #pragma warning disable IDE0072 |  | ||||||
|         base.LastStatusCode switch { |         base.LastStatusCode switch { | ||||||
|             #pragma warning restore IDE0072 |  | ||||||
|             null => null |             null => null | ||||||
|           , _ => (int)base.LastStatusCode.Value == Numbers.HTTP_STATUS_BIZ_FAIL |           , _ => base.LastStatusCode.Value == Numbers.HTTP_STATUS_BIZ_FAIL | ||||||
|                 ? nameof(ErrorCodes.Unhandled).ToLowerCamelCase() |                 ? nameof(ErrorCodes.Unhandled).ToLowerCamelCase() | ||||||
|                 : base.LastStatusCode.Value.ToString().ToLowerCamelCase() |                 : ((HttpStatusCode)base.LastStatusCode.Value).ToString().ToLowerCamelCase() | ||||||
|         }; |         }; | ||||||
|  |  | ||||||
|     /// <inheritdoc cref="IFieldCreatedTime.CreatedTime" /> |     /// <inheritdoc cref="IFieldCreatedTime.CreatedTime" /> | ||||||
|   | |||||||
| @@ -277,13 +277,13 @@ public sealed class JobService(BasicRepository<Sys_Job, long> rpo, IJobRecordSer | |||||||
|     { |     { | ||||||
|         var ret1 = await UpdateAsync( // 运行中,运行时间超过超时设定;置为空闲状态 |         var ret1 = await UpdateAsync( // 运行中,运行时间超过超时设定;置为空闲状态 | ||||||
|                 new Sys_Job { Status = JobStatues.Idle }, [nameof(Sys_Job.Status)], null |                 new Sys_Job { Status = JobStatues.Idle }, [nameof(Sys_Job.Status)], null | ||||||
|               , a => a.Status == JobStatues.Running && a.LastExecTime < DateTime.Now.AddSeconds(-Numbers.SECS_TIMEOUT_JOB), null, true) |               , a => a.Status == JobStatues.Running && a.LastExecTime < DateTime.Now.AddSeconds(-Numbers.SECS_TIMEOUT_JOB)) | ||||||
|             .ConfigureAwait(false); |             .ConfigureAwait(false); | ||||||
|  |  | ||||||
|         var ret2 = await UpdateAsync( // 空闲中,下次执行时间在当前时间减去超时时间以前;将下次执行时间调整到现在 |         var ret2 = await UpdateAsync( // 空闲中,下次执行时间在当前时间减去超时时间以前;将下次执行时间调整到现在 | ||||||
|                 new Sys_Job { NextExecTime = DateTime.Now, NextTimeId = DateTime.Now.TimeUnixUtc() } |                 new Sys_Job { NextExecTime = DateTime.Now, NextTimeId = DateTime.Now.TimeUnixUtc() } | ||||||
|               , [nameof(Sys_Job.NextExecTime), nameof(Sys_Job.NextTimeId)],                                              null |               , [nameof(Sys_Job.NextExecTime), nameof(Sys_Job.NextTimeId)], null | ||||||
|               , a => a.Status == JobStatues.Idle && a.NextExecTime < DateTime.Now.AddSeconds(-Numbers.SECS_TIMEOUT_JOB), null, true) |               , a => a.Status == JobStatues.Idle && a.NextExecTime < DateTime.Now.AddSeconds(-Numbers.SECS_TIMEOUT_JOB)) | ||||||
|             .ConfigureAwait(false); |             .ConfigureAwait(false); | ||||||
|         return ret1 + ret2; |         return ret1 + ret2; | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -160,7 +160,7 @@ public sealed class UserProfileService(BasicRepository<Sys_UserProfile, long> rp | |||||||
|             req.AppConfig = BuildAppConfig(App.GetService<ContextUserInfo>().Roles.ToDictionary(x => x.Id, x => x.DashboardLayout)); |             req.AppConfig = BuildAppConfig(App.GetService<ContextUserInfo>().Roles.ToDictionary(x => x.Id, x => x.DashboardLayout)); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return UpdateAsync(req, [nameof(req.AppConfig)], null, a => a.Id == UserToken.Id, null, true); |         return UpdateAsync(req, [nameof(req.AppConfig)], null, a => a.Id == UserToken.Id); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private ISelect<Sys_UserProfile, Sys_DicContent, Sys_DicContent, Sys_DicContent, Sys_DicContent> QueryInternal(QueryReq<QueryUserProfileReq> req) |     private ISelect<Sys_UserProfile, Sys_DicContent, Sys_DicContent, Sys_DicContent, Sys_DicContent> QueryInternal(QueryReq<QueryUserProfileReq> req) | ||||||
|   | |||||||
| @@ -453,8 +453,7 @@ public sealed class UserService( | |||||||
|             throw new NetAdminInvalidOperationException(Ln.请联系管理员激活账号); |             throw new NetAdminInvalidOperationException(Ln.请联系管理员激活账号); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         _ = await UpdateAsync(dbUser with { LastLoginTime = DateTime.Now }, [nameof(Sys_User.LastLoginTime)], ignoreVersion: true) |         _ = await UpdateAsync(dbUser with { LastLoginTime = DateTime.Now }, [nameof(Sys_User.LastLoginTime)]).ConfigureAwait(false); | ||||||
|             .ConfigureAwait(false); |  | ||||||
|  |  | ||||||
|         var tokenPayload = new Dictionary<string, object> { { nameof(ContextUserToken), dbUser.Adapt<ContextUserToken>() } }; |         var tokenPayload = new Dictionary<string, object> { { nameof(ContextUserToken), dbUser.Adapt<ContextUserToken>() } }; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -117,7 +117,7 @@ public sealed class ScheduledJob : WorkBase<ScheduledJob>, IJob | |||||||
|                                    _ = await jobRecordService.CreateAsync(jobRecord).ConfigureAwait(false); |                                    _ = await jobRecordService.CreateAsync(jobRecord).ConfigureAwait(false); | ||||||
|                                    await jobService.FinishJobAsync(job.Adapt<FinishJobReq>() with // |                                    await jobService.FinishJobAsync(job.Adapt<FinishJobReq>() with // | ||||||
|                                                                    { |                                                                    { | ||||||
|                                                                        LastStatusCode = rsp.StatusCode // |                                                                        LastStatusCode = (int?)rsp.StatusCode // | ||||||
|                                                                      , LastDuration = jobRecord.Duration |                                                                      , LastDuration = jobRecord.Duration | ||||||
|                                                                    }) |                                                                    }) | ||||||
|                                                    .ConfigureAwait(false); |                                                    .ConfigureAwait(false); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user