Skip to content

Commit e99cb2a

Browse files
tknsnail
authored andcommitted
feat: ✨ 框架代码同步
1 parent 4f6d465 commit e99cb2a

File tree

40 files changed

+437
-265
lines changed

40 files changed

+437
-265
lines changed

assets/res/NetAdmin.Statements.ln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ XML注释文件不存在
6868
消息内容不能为空
6969
父节点不存在
7070
用户不存在
71+
用户名不符合要求
7172
用户名不能为空
7273
用户名不能是手机号码
7374
用户名或密码错误

build/code.quality.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<PrivateAssets>all</PrivateAssets>
2424
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2525
</PackageReference>
26-
<PackageReference Include="SonarAnalyzer.CSharp" Version="10.13.0.120203">
26+
<PackageReference Include="SonarAnalyzer.CSharp" Version="10.14.0.120626">
2727
<PrivateAssets>all</PrivateAssets>
2828
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2929
</PackageReference>

src/backend/NetAdmin/NetAdmin.Application/Extensions/ISelectExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ public static ISelect<T> AppendOtherFilters<T, TQuery>(this ISelect<T> me, Query
1515
where TQuery : DataAbstraction, new()
1616
{
1717
if (req.IgnoreOwner) {
18-
me = me.DisableGlobalFilter(Chars.FLG_FREE_SQL_GLOBAL_FILTER_DATA);
18+
me = me.DisableGlobalFilter(Chars.FLG_FREE_SQL_GLOBAL_FILTER_SELF, Chars.FLG_FREE_SQL_GLOBAL_FILTER_DEPT
19+
, Chars.FLG_FREE_SQL_GLOBAL_FILTER_DEPT_WITH_CHILD);
1920
}
2021

2122
return me;

src/backend/NetAdmin/NetAdmin.Application/Services/RepositoryService.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,23 @@ protected static async Task<IActionResult> ExportAsync<TQuery, TExport>( //
6262
return await GetExportFileStreamAsync<TExport>(fileName, list).ConfigureAwait(false);
6363
}
6464

65+
/// <summary>
66+
/// 唯一索引冲突处理
67+
/// </summary>
68+
protected static async Task OnUniqueIndexConflictAsync(Func<Task> actionTry, Func<Task> actionCatch = null)
69+
{
70+
try {
71+
await actionTry().ConfigureAwait(false);
72+
}
73+
catch (Exception ex) when (ex.Message.Contains(Chars.FLG_DB_EXCEPTION_PRIMARY_KEY_CONFLICT) ||
74+
ex.Message.Contains(Chars.FLG_DB_EXCEPTION_UNIQUE_CONSTRAINT_CONFLICT) ||
75+
ex.Message.Contains(Chars.FLG_DB_EXCEPTION_IDX)) {
76+
if (actionCatch != null) {
77+
await actionCatch().ConfigureAwait(false);
78+
}
79+
}
80+
}
81+
6582
/// <summary>
6683
/// 更新实体
6784
/// </summary>
@@ -85,7 +102,8 @@ TEntity newValue //
85102
whereExp ??= a => a.Id.Equals(newValue.Id);
86103
var update = BuildUpdate(newValue, includeFields, excludeFields, ignoreVersion).Where(whereExp).Where(whereSql);
87104
if (disableGlobalDataFilter) {
88-
update = update.DisableGlobalFilter(nameof(Chars.FLG_FREE_SQL_GLOBAL_FILTER_DATA));
105+
update = update.DisableGlobalFilter(Chars.FLG_FREE_SQL_GLOBAL_FILTER_SELF, Chars.FLG_FREE_SQL_GLOBAL_FILTER_DEPT
106+
, Chars.FLG_FREE_SQL_GLOBAL_FILTER_DEPT_WITH_CHILD);
89107
}
90108

91109
return update.ExecuteEffectsAsync();
@@ -106,8 +124,8 @@ protected Task<List<TEntity>> UpdateReturnListAsync( //
106124
TEntity newValue //
107125
, List<string> includeFields = null //
108126
, List<string> excludeFields = null //
109-
, Expression<Func<TEntity, bool>> whereExp = null //
110-
, string whereSql = null //
127+
, Expression<Func<TEntity, bool>> whereExp = null //
128+
, string whereSql = null //
111129
, bool ignoreVersion = false)
112130
{
113131
// 默认匹配主键

src/backend/NetAdmin/NetAdmin.Domain/Attributes/DataValidation/UserNameAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public UserNameAttribute() //
1919
public override bool IsValid(object value)
2020
{
2121
if (!base.IsValid(value)) {
22-
ErrorMessageResourceName = nameof(Ln.用户名长度4位以上);
22+
ErrorMessageResourceName = nameof(Ln.用户名不符合要求);
2323
return false;
2424
}
2525

src/backend/NetAdmin/NetAdmin.Domain/DataAbstraction.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,23 @@ namespace NetAdmin.Domain;
33
/// <summary>
44
/// 数据基类
55
/// </summary>
6-
public abstract record DataAbstraction
6+
public abstract record DataAbstraction : IValidatableObject
77
{
8+
/// <summary>
9+
/// 是否已验证
10+
/// </summary>
11+
protected bool HasValidated { get; set; }
12+
813
/// <summary>
914
/// 如果数据校验失败,抛出异常
1015
/// </summary>
1116
/// <exception cref="NetAdminValidateException">NetAdminValidateException</exception>
1217
public void ThrowIfInvalid()
1318
{
19+
if (HasValidated) {
20+
return;
21+
}
22+
1423
var validationResult = this.TryValidate();
1524
if (!validationResult.IsValid) {
1625
throw new NetAdminValidateException(validationResult.ValidationResults.ToDictionary( //
@@ -45,4 +54,19 @@ public void TruncateStrings()
4554
property.SetValue(this, s);
4655
}
4756
}
57+
58+
/// <inheritdoc />
59+
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
60+
{
61+
HasValidated = true;
62+
return ValidateInternal(validationContext);
63+
}
64+
65+
/// <summary>
66+
/// 内部验证
67+
/// </summary>
68+
protected virtual IEnumerable<ValidationResult> ValidateInternal(ValidationContext validationContext)
69+
{
70+
yield return ValidationResult.Success;
71+
}
4872
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace NetAdmin.Domain.Dto.Dependency;
2+
3+
/// <summary>
4+
/// 工作批请求
5+
/// </summary>
6+
public record JobReq : DataAbstraction
7+
{
8+
/// <summary>
9+
/// 处理数量
10+
/// </summary>
11+
public int? Count { get; init; }
12+
13+
/// <summary>
14+
/// n秒以前
15+
/// </summary>
16+
public int? SecondsAgo { get; init; }
17+
18+
/// <summary>
19+
/// 直到n秒前
20+
/// </summary>
21+
public int? UntilSecondsAgo { get; init; }
22+
}

src/backend/NetAdmin/NetAdmin.Domain/Dto/Sys/DepositOrder/CreateDepositOrderReq.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ namespace NetAdmin.Domain.Dto.Sys.DepositOrder;
33
/// <summary>
44
/// 请求:创建充值订单
55
/// </summary>
6-
public record CreateDepositOrderReq : Sys_DepositOrder, IValidatableObject
6+
public record CreateDepositOrderReq : Sys_DepositOrder
77
{
88
/// <inheritdoc cref="Sys_DepositOrder.ActualPayAmount" />
99
public override long ActualPayAmount { get; init; }
@@ -25,7 +25,7 @@ public record CreateDepositOrderReq : Sys_DepositOrder, IValidatableObject
2525
public override int ToPointRate { get; init; }
2626

2727
/// <inheritdoc />
28-
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
28+
protected override IEnumerable<ValidationResult> ValidateInternal(ValidationContext validationContext)
2929
{
3030
if (PaymentMode != PaymentModes.USDT) {
3131
yield return new ValidationResult(Ln.支付方式不正确, [nameof(PaymentMode)]);

src/backend/NetAdmin/NetAdmin.Domain/Dto/Sys/DepositOrder/ReceivedConfirmationReq.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/backend/NetAdmin/NetAdmin.Domain/Dto/Sys/Dept/CreateDeptReq.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ namespace NetAdmin.Domain.Dto.Sys.Dept;
55
/// </summary>
66
public record CreateDeptReq : Sys_Dept
77
{
8-
/// <inheritdoc cref="IFieldEnabled.Enabled" />
9-
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
10-
public override bool Enabled { get; init; }
8+
/// <inheritdoc />
9+
public override bool Enabled { get; init; } = true;
1110

1211
/// <inheritdoc cref="Sys_Dept.Name" />
1312
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]

0 commit comments

Comments
 (0)