相关bug调整
This commit is contained in:
+28
-3
@@ -27,8 +27,12 @@ public class OnboardingEntryConfigService : IOnboardingEntryConfigService
|
||||
/// </summary>
|
||||
public async Task SaveFormField(OnboardingFormFieldSaveInput input)
|
||||
{
|
||||
var fieldCodeExists = await _db.Queryable<ObFormField>()
|
||||
.AnyAsync(x => x.FieldCode == input.FieldCode && x.Id != input.Id);
|
||||
var fieldCodeQuery = _db.Queryable<ObFormField>()
|
||||
.Where(x => x.FieldCode == input.FieldCode);
|
||||
if (input.Id.HasValue)
|
||||
fieldCodeQuery = fieldCodeQuery.Where(x => x.Id != input.Id.Value);
|
||||
|
||||
var fieldCodeExists = await fieldCodeQuery.AnyAsync();
|
||||
if (fieldCodeExists)
|
||||
throw Oops.Bah("字段编码已存在");
|
||||
|
||||
@@ -38,7 +42,7 @@ public class OnboardingEntryConfigService : IOnboardingEntryConfigService
|
||||
FieldCode = input.FieldCode,
|
||||
FieldName = input.FieldName,
|
||||
DataType = input.DataType,
|
||||
OptionsJson = input.OptionsJson,
|
||||
OptionsJson = NormalizeOptionsJson(input.OptionsJson),
|
||||
ValidationRule = input.ValidationRule,
|
||||
Placeholder = input.Placeholder,
|
||||
Status = input.Status
|
||||
@@ -57,6 +61,27 @@ public class OnboardingEntryConfigService : IOnboardingEntryConfigService
|
||||
await _db.Insertable(entity).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将空白的可选项转换为 null,避免 MySQL JSON 字段写入空字符串时报错。
|
||||
/// </summary>
|
||||
private static string NormalizeOptionsJson(string optionsJson)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(optionsJson))
|
||||
return null;
|
||||
|
||||
var normalizedJson = optionsJson.Trim();
|
||||
|
||||
try
|
||||
{
|
||||
using var jsonDocument = global::System.Text.Json.JsonDocument.Parse(normalizedJson);
|
||||
return normalizedJson;
|
||||
}
|
||||
catch (global::System.Text.Json.JsonException)
|
||||
{
|
||||
throw Oops.Bah("可选项不是有效的 JSON 格式");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除未被填写要求引用的动态字段。
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user