diff --git a/src/backend/NetAdmin/NetAdmin.Application/Services/RepositoryService.cs b/src/backend/NetAdmin/NetAdmin.Application/Services/RepositoryService.cs index 686fccdc..5984c6cb 100644 --- a/src/backend/NetAdmin/NetAdmin.Application/Services/RepositoryService.cs +++ b/src/backend/NetAdmin/NetAdmin.Application/Services/RepositoryService.cs @@ -3,7 +3,6 @@ using Microsoft.Net.Http.Headers; using NetAdmin.Application.Repositories; using NetAdmin.Domain; using NetAdmin.Domain.DbMaps.Dependency; -using NetAdmin.Domain.DbMaps.Dependency.Fields; using NetAdmin.Domain.Dto.Dependency; namespace NetAdmin.Application.Services; @@ -65,19 +64,17 @@ public abstract class RepositoryService(BasicReposit /// 排除的属性 /// 查询表达式 /// 查询sql - /// 是否忽略版本锁 /// 更新行数 protected Task UpdateAsync( // TEntity newValue // , IEnumerable includeFields // , string[] excludeFields = null // , Expression> whereExp = null // - , string whereSql = null // - , bool ignoreVersion = false) + , string whereSql = null) { // 默认匹配主键 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(); } @@ -90,19 +87,17 @@ public abstract class RepositoryService(BasicReposit /// 排除的属性 /// 查询表达式 /// 查询sql - /// 是否忽略版本锁 /// 更新后的实体列表 protected Task> UpdateReturnListAsync( // TEntity newValue // , IEnumerable includeFields // , string[] excludeFields = null // - , Expression> whereExp = null // - , string whereSql = null // - , bool ignoreVersion = false) + , Expression> whereExp = null // + , string whereSql = null) { // 默认匹配主键 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 @@ -132,11 +127,10 @@ public abstract class RepositoryService(BasicReposit return new FileStreamResult(stream, Chars.FLG_HTTP_HEADER_VALUE_APPLICATION_OCTET_STREAM); } - private IUpdate BuildUpdate( // - TEntity entity // - , IEnumerable includeFields // - , string[] excludeFields = null // - , bool ignoreVersion = false) + private IUpdate BuildUpdate( // + TEntity entity // + , IEnumerable includeFields // + , string[] excludeFields = null) { var updateExp = includeFields == null ? Rpo.UpdateDiy.SetSource(entity) @@ -146,10 +140,6 @@ public abstract class RepositoryService(BasicReposit updateExp = updateExp.IgnoreColumns(excludeFields); } - if (!ignoreVersion && entity is IFieldVersion ver) { - updateExp = updateExp.Where($"{nameof(IFieldVersion.Version)} = @version", new { version = ver.Version }); - } - return updateExp; } } \ No newline at end of file diff --git a/src/backend/NetAdmin/NetAdmin.Domain/DbMaps/Sys/Sys_Job.cs b/src/backend/NetAdmin/NetAdmin.Domain/DbMaps/Sys/Sys_Job.cs index 65a7e34c..2dbb25c4 100644 --- a/src/backend/NetAdmin/NetAdmin.Domain/DbMaps/Sys/Sys_Job.cs +++ b/src/backend/NetAdmin/NetAdmin.Domain/DbMaps/Sys/Sys_Job.cs @@ -59,10 +59,10 @@ public record Sys_Job : VersionEntity, IFieldEnabled, IFieldSummary /// /// 上次执行状态 /// - [Column] + [Column(DbType = Chars.FLG_DB_FIELD_TYPE_SMALL_INT)] [CsvIgnore] [JsonIgnore] - public HttpStatusCode? LastStatusCode { get; init; } + public int? LastStatusCode { get; init; } /// /// 下次执行时间 diff --git a/src/backend/NetAdmin/NetAdmin.Domain/Dto/Sys/Job/QueryJobRsp.cs b/src/backend/NetAdmin/NetAdmin.Domain/Dto/Sys/Job/QueryJobRsp.cs index 22e46348..871d7908 100644 --- a/src/backend/NetAdmin/NetAdmin.Domain/Dto/Sys/Job/QueryJobRsp.cs +++ b/src/backend/NetAdmin/NetAdmin.Domain/Dto/Sys/Job/QueryJobRsp.cs @@ -20,13 +20,11 @@ public record QueryJobRsp : Sys_Job /// [JsonInclude] public new virtual string LastStatusCode => - #pragma warning disable IDE0072 base.LastStatusCode switch { - #pragma warning restore IDE0072 null => null - , _ => (int)base.LastStatusCode.Value == Numbers.HTTP_STATUS_BIZ_FAIL + , _ => base.LastStatusCode.Value == Numbers.HTTP_STATUS_BIZ_FAIL ? nameof(ErrorCodes.Unhandled).ToLowerCamelCase() - : base.LastStatusCode.Value.ToString().ToLowerCamelCase() + : ((HttpStatusCode)base.LastStatusCode.Value).ToString().ToLowerCamelCase() }; /// diff --git a/src/backend/NetAdmin/NetAdmin.SysComponent.Application/Services/Sys/JobService.cs b/src/backend/NetAdmin/NetAdmin.SysComponent.Application/Services/Sys/JobService.cs index 0e1a8d5c..06f3b323 100644 --- a/src/backend/NetAdmin/NetAdmin.SysComponent.Application/Services/Sys/JobService.cs +++ b/src/backend/NetAdmin/NetAdmin.SysComponent.Application/Services/Sys/JobService.cs @@ -277,13 +277,13 @@ public sealed class JobService(BasicRepository rpo, IJobRecordSer { var ret1 = await UpdateAsync( // 运行中,运行时间超过超时设定;置为空闲状态 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); var ret2 = await UpdateAsync( // 空闲中,下次执行时间在当前时间减去超时时间以前;将下次执行时间调整到现在 new Sys_Job { NextExecTime = DateTime.Now, NextTimeId = DateTime.Now.TimeUnixUtc() } - , [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) + , [nameof(Sys_Job.NextExecTime), nameof(Sys_Job.NextTimeId)], null + , a => a.Status == JobStatues.Idle && a.NextExecTime < DateTime.Now.AddSeconds(-Numbers.SECS_TIMEOUT_JOB)) .ConfigureAwait(false); return ret1 + ret2; } diff --git a/src/backend/NetAdmin/NetAdmin.SysComponent.Application/Services/Sys/UserProfileService.cs b/src/backend/NetAdmin/NetAdmin.SysComponent.Application/Services/Sys/UserProfileService.cs index d9ab21cb..1cfbca86 100644 --- a/src/backend/NetAdmin/NetAdmin.SysComponent.Application/Services/Sys/UserProfileService.cs +++ b/src/backend/NetAdmin/NetAdmin.SysComponent.Application/Services/Sys/UserProfileService.cs @@ -160,7 +160,7 @@ public sealed class UserProfileService(BasicRepository rp req.AppConfig = BuildAppConfig(App.GetService().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 QueryInternal(QueryReq req) diff --git a/src/backend/NetAdmin/NetAdmin.SysComponent.Application/Services/Sys/UserService.cs b/src/backend/NetAdmin/NetAdmin.SysComponent.Application/Services/Sys/UserService.cs index cb04053e..592c04ec 100644 --- a/src/backend/NetAdmin/NetAdmin.SysComponent.Application/Services/Sys/UserService.cs +++ b/src/backend/NetAdmin/NetAdmin.SysComponent.Application/Services/Sys/UserService.cs @@ -453,8 +453,7 @@ public sealed class UserService( throw new NetAdminInvalidOperationException(Ln.请联系管理员激活账号); } - _ = await UpdateAsync(dbUser with { LastLoginTime = DateTime.Now }, [nameof(Sys_User.LastLoginTime)], ignoreVersion: true) - .ConfigureAwait(false); + _ = await UpdateAsync(dbUser with { LastLoginTime = DateTime.Now }, [nameof(Sys_User.LastLoginTime)]).ConfigureAwait(false); var tokenPayload = new Dictionary { { nameof(ContextUserToken), dbUser.Adapt() } }; diff --git a/src/backend/NetAdmin/NetAdmin.SysComponent.Host/Jobs/ScheduledJob.cs b/src/backend/NetAdmin/NetAdmin.SysComponent.Host/Jobs/ScheduledJob.cs index 9020da91..59433522 100644 --- a/src/backend/NetAdmin/NetAdmin.SysComponent.Host/Jobs/ScheduledJob.cs +++ b/src/backend/NetAdmin/NetAdmin.SysComponent.Host/Jobs/ScheduledJob.cs @@ -117,7 +117,7 @@ public sealed class ScheduledJob : WorkBase, IJob _ = await jobRecordService.CreateAsync(jobRecord).ConfigureAwait(false); await jobService.FinishJobAsync(job.Adapt() with // { - LastStatusCode = rsp.StatusCode // + LastStatusCode = (int?)rsp.StatusCode // , LastDuration = jobRecord.Duration }) .ConfigureAwait(false);