相关bug调整

This commit is contained in:
fuenmao
2026-08-24 16:36:47 +08:00
parent 22a7df5bec
commit 0931e1f343
6 changed files with 57 additions and 9 deletions
@@ -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>