소스 검색

fix(data-platform): sync config column mapping and migration script

Add explicit snake_case SugarColumn mappings for MDP sync config entities to
fix TenantId SQL errors on steps/entity APIs. Clean csproj rebase markers,
register UpdateScripts 1.0.158/1.0.159, and drop stale config tables before
1.0.159 DDL when CodeFirst created wrong schema.

chore: bump server 1.0.171
Co-authored-by: Cursor <cursoragent@cursor.com>
skygu 1 주 전
부모
커밋
8c5da5c39e

+ 3 - 6
server/Admin.NET.Web.Entry/Admin.NET.Web.Entry.csproj

@@ -11,9 +11,9 @@
     <GenerateSatelliteAssembliesForCore>true</GenerateSatelliteAssembliesForCore>
     <Copyright>Admin.NET</Copyright>
     <Description>Admin.NET 通用权限开发平台</Description>
-    <AssemblyVersion>1.0.170</AssemblyVersion>
-    <FileVersion>1.0.170</FileVersion>
-    <Version>1.0.170</Version>
+    <AssemblyVersion>1.0.171</AssemblyVersion>
+    <FileVersion>1.0.171</FileVersion>
+    <Version>1.0.171</Version>
   </PropertyGroup>
 
   <ItemGroup>
@@ -115,15 +115,12 @@
     <None Update="UpdateScripts\1.0.157.sql">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </None>
-<<<<<<< HEAD
-=======
     <None Update="UpdateScripts\1.0.158.sql">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </None>
     <None Update="UpdateScripts\1.0.159.sql">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </None>
->>>>>>> f3661a943 (feat(data-platform): sync config center with entity and field mapping CRUD)
   </ItemGroup>
 
   <ItemGroup>

+ 7 - 0
server/Admin.NET.Web.Entry/UpdateScripts/1.0.159.sql

@@ -3,6 +3,13 @@
 
 SET NAMES utf8mb4;
 
+-- CodeFirst 可能已创建不完整/错误结构的配置表,重建前先清理(本阶段无业务数据)
+DROP TABLE IF EXISTS mdp_sync_task_step;
+DROP TABLE IF EXISTS mdp_sync_task_param;
+DROP TABLE IF EXISTS mdp_sync_task_formula;
+DROP TABLE IF EXISTS mdp_sync_task_schedule;
+DROP TABLE IF EXISTS mdp_sync_task;
+
 CREATE TABLE IF NOT EXISTS mdp_sync_task (
     id BIGINT AUTO_INCREMENT PRIMARY KEY,
     tenant_id BIGINT NOT NULL DEFAULT 0,

+ 64 - 2
server/Plugins/Admin.NET.Plugin.AiDOP/Entity/DataPlatform/MdpEntity.cs

@@ -3,47 +3,109 @@ namespace Admin.NET.Plugin.AiDOP.Entity.DataPlatform;
 [SugarTable("mdp_entity", "MDP同步实体配置")]
 public class MdpEntity
 {
-    [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
+    [SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsIdentity = true)]
     public long Id { get; set; }
 
+    [SugarColumn(ColumnName = "tenant_id")]
     public long TenantId { get; set; }
+
+    [SugarColumn(ColumnName = "source_id")]
     public long SourceId { get; set; }
+
+    [SugarColumn(ColumnName = "entity_code", Length = 100)]
     public string EntityCode { get; set; } = string.Empty;
+
+    [SugarColumn(ColumnName = "entity_name", Length = 200)]
     public string EntityName { get; set; } = string.Empty;
+
+    [SugarColumn(ColumnName = "entity_type", Length = 40)]
     public string EntityType { get; set; } = "TABLE";
+
+    [SugarColumn(ColumnName = "source_table_name", Length = 200, IsNullable = true)]
     public string? SourceTableName { get; set; }
+
+    [SugarColumn(ColumnName = "source_api_path", Length = 500, IsNullable = true)]
     public string? SourceApiPath { get; set; }
+
+    [SugarColumn(ColumnName = "api_config_id", IsNullable = true)]
     public long? ApiConfigId { get; set; }
+
+    [SugarColumn(ColumnName = "target_table_name", Length = 200, IsNullable = true)]
     public string? TargetTableName { get; set; }
+
+    [SugarColumn(ColumnName = "sync_mode", Length = 40)]
     public string SyncMode { get; set; } = "INCR";
+
+    [SugarColumn(ColumnName = "incr_column", Length = 100, IsNullable = true)]
     public string? IncrColumn { get; set; }
+
+    [SugarColumn(ColumnName = "batch_size")]
     public int BatchSize { get; set; } = 5000;
+
+    [SugarColumn(ColumnName = "response_data_path", Length = 200, IsNullable = true)]
     public string? ResponseDataPath { get; set; }
+
+    [SugarColumn(ColumnName = "dedup_key_path", Length = 200, IsNullable = true)]
     public string? DedupKeyPath { get; set; }
+
+    [SugarColumn(ColumnName = "last_cursor", Length = 500, IsNullable = true)]
     public string? LastCursor { get; set; }
+
+    [SugarColumn(ColumnName = "last_sync_to", IsNullable = true)]
     public DateTime? LastSyncTo { get; set; }
+
+    [SugarColumn(ColumnName = "job_id", Length = 100, IsNullable = true)]
     public string? JobId { get; set; }
+
+    [SugarColumn(ColumnName = "status")]
     public int Status { get; set; } = 1;
+
+    [SugarColumn(ColumnName = "remark", Length = 500, IsNullable = true)]
     public string? Remark { get; set; }
+
+    [SugarColumn(ColumnName = "create_time")]
     public DateTime CreateTime { get; set; }
+
+    [SugarColumn(ColumnName = "update_time")]
     public DateTime UpdateTime { get; set; }
 }
 
 [SugarTable("mdp_field_mapping", "MDP字段映射配置")]
 public class MdpFieldMapping
 {
-    [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
+    [SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsIdentity = true)]
     public long Id { get; set; }
 
+    [SugarColumn(ColumnName = "entity_id")]
     public long EntityId { get; set; }
+
+    [SugarColumn(ColumnName = "source_field", Length = 200)]
     public string SourceField { get; set; } = string.Empty;
+
+    [SugarColumn(ColumnName = "target_field", Length = 200)]
     public string TargetField { get; set; } = string.Empty;
+
+    [SugarColumn(ColumnName = "field_type", Length = 40)]
     public string FieldType { get; set; } = "DIRECT";
+
+    [SugarColumn(ColumnName = "transform_script", ColumnDataType = "text", IsNullable = true)]
     public string? TransformScript { get; set; }
+
+    [SugarColumn(ColumnName = "const_value", Length = 500, IsNullable = true)]
     public string? ConstValue { get; set; }
+
+    [SugarColumn(ColumnName = "lookup_table", Length = 200, IsNullable = true)]
     public string? LookupTable { get; set; }
+
+    [SugarColumn(ColumnName = "is_required")]
     public int IsRequired { get; set; }
+
+    [SugarColumn(ColumnName = "default_value", Length = 500, IsNullable = true)]
     public string? DefaultValue { get; set; }
+
+    [SugarColumn(ColumnName = "sort_order")]
     public int SortOrder { get; set; }
+
+    [SugarColumn(ColumnName = "create_time")]
     public DateTime CreateTime { get; set; }
 }

+ 100 - 3
server/Plugins/Admin.NET.Plugin.AiDOP/Entity/DataPlatform/MdpSyncConfigEntities.cs

@@ -3,73 +3,170 @@ namespace Admin.NET.Plugin.AiDOP.Entity.DataPlatform;
 [SugarTable("mdp_sync_task", "MDP同步任务业务配置")]
 public class MdpSyncTask
 {
-    [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
+    [SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsIdentity = true)]
     public long Id { get; set; }
 
+    [SugarColumn(ColumnName = "tenant_id")]
     public long TenantId { get; set; }
+
+    [SugarColumn(ColumnName = "task_code", Length = 100)]
     public string TaskCode { get; set; } = string.Empty;
+
+    [SugarColumn(ColumnName = "task_name", Length = 200)]
     public string TaskName { get; set; } = string.Empty;
+
+    [SugarColumn(ColumnName = "task_type", Length = 40)]
     public string TaskType { get; set; } = "SERVICE_SYNC";
+
+    [SugarColumn(ColumnName = "business_domain_code", Length = 100, IsNullable = true)]
     public string? BusinessDomainCode { get; set; }
+
+    [SugarColumn(ColumnName = "business_domain_name", Length = 200, IsNullable = true)]
     public string? BusinessDomainName { get; set; }
+
+    [SugarColumn(ColumnName = "consumer_modules", Length = 500, IsNullable = true)]
     public string? ConsumerModules { get; set; }
+
+    [SugarColumn(ColumnName = "source_system_code", Length = 100, IsNullable = true)]
     public string? SourceSystemCode { get; set; }
+
+    [SugarColumn(ColumnName = "service_key", Length = 100, IsNullable = true)]
     public string? ServiceKey { get; set; }
+
+    [SugarColumn(ColumnName = "job_code", Length = 100, IsNullable = true)]
     public string? JobCode { get; set; }
+
+    [SugarColumn(ColumnName = "schedule_job_id", Length = 100, IsNullable = true)]
     public string? ScheduleJobId { get; set; }
+
+    [SugarColumn(ColumnName = "status")]
     public int Status { get; set; } = 1;
+
+    [SugarColumn(ColumnName = "owner_role", Length = 100, IsNullable = true)]
     public string? OwnerRole { get; set; }
+
+    [SugarColumn(ColumnName = "config_version")]
     public int ConfigVersion { get; set; } = 1;
+
+    [SugarColumn(ColumnName = "description", Length = 1000, IsNullable = true)]
     public string? Description { get; set; }
+
+    [SugarColumn(ColumnName = "create_time")]
     public DateTime CreateTime { get; set; }
+
+    [SugarColumn(ColumnName = "update_time")]
     public DateTime UpdateTime { get; set; }
 }
 
 [SugarTable("mdp_sync_task_step", "MDP同步任务步骤配置")]
 public class MdpSyncTaskStep
 {
-    [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
+    [SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsIdentity = true)]
     public long Id { get; set; }
 
+    [SugarColumn(ColumnName = "tenant_id")]
     public long TenantId { get; set; }
+
+    [SugarColumn(ColumnName = "task_code", Length = 100)]
     public string TaskCode { get; set; } = string.Empty;
+
+    [SugarColumn(ColumnName = "step_code", Length = 100)]
     public string StepCode { get; set; } = string.Empty;
+
+    [SugarColumn(ColumnName = "step_name", Length = 200)]
     public string StepName { get; set; } = string.Empty;
+
+    [SugarColumn(ColumnName = "stage_type", Length = 40)]
     public string StageType { get; set; } = string.Empty;
+
+    [SugarColumn(ColumnName = "service_method_key", Length = 100, IsNullable = true)]
     public string? ServiceMethodKey { get; set; }
+
+    [SugarColumn(ColumnName = "enabled")]
     public int Enabled { get; set; } = 1;
+
+    [SugarColumn(ColumnName = "sort_order")]
     public int SortOrder { get; set; }
+
+    [SugarColumn(ColumnName = "description", Length = 1000, IsNullable = true)]
     public string? Description { get; set; }
+
+    [SugarColumn(ColumnName = "create_time")]
     public DateTime CreateTime { get; set; }
+
+    [SugarColumn(ColumnName = "update_time")]
     public DateTime UpdateTime { get; set; }
 }
 
 [SugarTable("mdp_sync_task_schedule", "MDP同步任务调度业务配置")]
 public class MdpSyncTaskSchedule
 {
-    [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
+    [SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsIdentity = true)]
     public long Id { get; set; }
 
+    [SugarColumn(ColumnName = "tenant_id")]
     public long TenantId { get; set; }
+
+    [SugarColumn(ColumnName = "task_code", Length = 100)]
     public string TaskCode { get; set; } = string.Empty;
+
+    [SugarColumn(ColumnName = "schedule_job_id", Length = 100, IsNullable = true)]
     public string? ScheduleJobId { get; set; }
+
+    [SugarColumn(ColumnName = "schedule_mode", Length = 40)]
     public string ScheduleMode { get; set; } = "CRON";
+
+    [SugarColumn(ColumnName = "cron_expr", Length = 200, IsNullable = true)]
     public string? CronExpr { get; set; }
+
+    [SugarColumn(ColumnName = "cron_desc", Length = 500, IsNullable = true)]
     public string? CronDesc { get; set; }
+
+    [SugarColumn(ColumnName = "timezone", Length = 100)]
     public string Timezone { get; set; } = "Asia/Shanghai";
+
+    [SugarColumn(ColumnName = "auto_enabled")]
     public int AutoEnabled { get; set; } = 1;
+
+    [SugarColumn(ColumnName = "manual_enabled")]
     public int ManualEnabled { get; set; } = 1;
+
+    [SugarColumn(ColumnName = "retry_enabled")]
     public int RetryEnabled { get; set; } = 1;
+
+    [SugarColumn(ColumnName = "max_retry_count")]
     public int MaxRetryCount { get; set; } = 3;
+
+    [SugarColumn(ColumnName = "retry_interval_seconds")]
     public int RetryIntervalSeconds { get; set; } = 300;
+
+    [SugarColumn(ColumnName = "timeout_seconds")]
     public int TimeoutSeconds { get; set; } = 3600;
+
+    [SugarColumn(ColumnName = "misfire_policy", Length = 40, IsNullable = true)]
     public string? MisfirePolicy { get; set; }
+
+    [SugarColumn(ColumnName = "sync_window_type", Length = 40)]
     public string SyncWindowType { get; set; } = "FULL";
+
+    [SugarColumn(ColumnName = "sync_window_value", Length = 200, IsNullable = true)]
     public string? SyncWindowValue { get; set; }
+
+    [SugarColumn(ColumnName = "last_schedule_time", IsNullable = true)]
     public DateTime? LastScheduleTime { get; set; }
+
+    [SugarColumn(ColumnName = "next_schedule_time", IsNullable = true)]
     public DateTime? NextScheduleTime { get; set; }
+
+    [SugarColumn(ColumnName = "admin_job_config_json", ColumnDataType = "text", IsNullable = true)]
     public string? AdminJobConfigJson { get; set; }
+
+    [SugarColumn(ColumnName = "description", Length = 1000, IsNullable = true)]
     public string? Description { get; set; }
+
+    [SugarColumn(ColumnName = "create_time")]
     public DateTime CreateTime { get; set; }
+
+    [SugarColumn(ColumnName = "update_time")]
     public DateTime UpdateTime { get; set; }
 }