From 9bd1d60e85bd15fbc672f328a657d60dad03b13f Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 17 Apr 2026 17:26:20 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=9B=9B=E4=B8=AA=20Model=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=20realname=5Fpolicy=20=E5=AD=97=E6=AE=B5=EF=BC=88?= =?UTF-8?q?=E5=90=AB=20gorm=20=E6=A0=87=E7=AD=BE=E5=92=8C=E4=B8=AD?= =?UTF-8?q?=E6=96=87=E6=B3=A8=E9=87=8A=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- internal/model/device.go | 1 + internal/model/device_import_task.go | 35 ++++++++++---------- internal/model/iot_card.go | 1 + internal/model/iot_card_import_task.go | 45 +++++++++++++------------- 4 files changed, 43 insertions(+), 39 deletions(-) diff --git a/internal/model/device.go b/internal/model/device.go index ab808fb..1da6f85 100644 --- a/internal/model/device.go +++ b/internal/model/device.go @@ -43,6 +43,7 @@ type Device struct { SoftwareVersion string `gorm:"column:software_version;type:varchar(100);not null;default:'';comment:固件版本号" json:"software_version"` SwitchMode string `gorm:"column:switch_mode;type:varchar(10);not null;default:'0';comment:切卡模式:0=自动 1=手动" json:"switch_mode"` LastGatewaySyncAt *time.Time `gorm:"column:last_gateway_sync_at;comment:最后一次 sync-info 同步时间" json:"last_gateway_sync_at,omitempty"` + RealnamePolicy string `gorm:"column:realname_policy;type:varchar(20);default:'none';not null;comment:实名认证策略(none=无需实名,before_order=先实名后充值/购买,after_order=先充值/购买后实名)" json:"realname_policy"` } // TableName 指定表名 diff --git a/internal/model/device_import_task.go b/internal/model/device_import_task.go index a7ffa63..e6d1f63 100644 --- a/internal/model/device_import_task.go +++ b/internal/model/device_import_task.go @@ -11,23 +11,24 @@ import ( // 通过异步任务处理 CSV 文件导入设备并绑定卡 type DeviceImportTask struct { gorm.Model - BaseModel `gorm:"embedded"` - TaskNo string `gorm:"column:task_no;type:varchar(50);uniqueIndex:idx_device_import_task_no,where:deleted_at IS NULL;not null;comment:任务编号(唯一)" json:"task_no"` - BatchNo string `gorm:"column:batch_no;type:varchar(100);comment:批次号" json:"batch_no"` - StorageKey string `gorm:"column:storage_key;type:varchar(500);comment:对象存储文件路径" json:"storage_key"` - FileName string `gorm:"column:file_name;type:varchar(255);comment:原始文件名" json:"file_name"` - Status int `gorm:"column:status;type:int;default:1;not null;comment:任务状态 1-待处理 2-处理中 3-已完成 4-失败" json:"status"` - TotalCount int `gorm:"column:total_count;type:int;default:0;comment:总记录数" json:"total_count"` - SuccessCount int `gorm:"column:success_count;type:int;default:0;comment:成功数" json:"success_count"` - SkipCount int `gorm:"column:skip_count;type:int;default:0;comment:跳过数" json:"skip_count"` - FailCount int `gorm:"column:fail_count;type:int;default:0;comment:失败数" json:"fail_count"` - SkippedItems ImportResultItems `gorm:"column:skipped_items;type:jsonb;comment:跳过记录详情" json:"skipped_items"` - FailedItems ImportResultItems `gorm:"column:failed_items;type:jsonb;comment:失败记录详情" json:"failed_items"` - WarningCount int `gorm:"column:warning_count;default:0;comment:警告数量(部分成功的设备)" json:"warning_count"` - WarningItems ImportResultItems `gorm:"column:warning_items;type:jsonb;comment:警告记录详情" json:"warning_items"` - ErrorMessage string `gorm:"column:error_message;type:text;comment:错误信息" json:"error_message"` - StartedAt *time.Time `gorm:"column:started_at;comment:开始处理时间" json:"started_at"` - CompletedAt *time.Time `gorm:"column:completed_at;comment:完成时间" json:"completed_at"` + BaseModel `gorm:"embedded"` + TaskNo string `gorm:"column:task_no;type:varchar(50);uniqueIndex:idx_device_import_task_no,where:deleted_at IS NULL;not null;comment:任务编号(唯一)" json:"task_no"` + BatchNo string `gorm:"column:batch_no;type:varchar(100);comment:批次号" json:"batch_no"` + StorageKey string `gorm:"column:storage_key;type:varchar(500);comment:对象存储文件路径" json:"storage_key"` + FileName string `gorm:"column:file_name;type:varchar(255);comment:原始文件名" json:"file_name"` + Status int `gorm:"column:status;type:int;default:1;not null;comment:任务状态 1-待处理 2-处理中 3-已完成 4-失败" json:"status"` + TotalCount int `gorm:"column:total_count;type:int;default:0;comment:总记录数" json:"total_count"` + SuccessCount int `gorm:"column:success_count;type:int;default:0;comment:成功数" json:"success_count"` + SkipCount int `gorm:"column:skip_count;type:int;default:0;comment:跳过数" json:"skip_count"` + FailCount int `gorm:"column:fail_count;type:int;default:0;comment:失败数" json:"fail_count"` + SkippedItems ImportResultItems `gorm:"column:skipped_items;type:jsonb;comment:跳过记录详情" json:"skipped_items"` + FailedItems ImportResultItems `gorm:"column:failed_items;type:jsonb;comment:失败记录详情" json:"failed_items"` + WarningCount int `gorm:"column:warning_count;default:0;comment:警告数量(部分成功的设备)" json:"warning_count"` + WarningItems ImportResultItems `gorm:"column:warning_items;type:jsonb;comment:警告记录详情" json:"warning_items"` + ErrorMessage string `gorm:"column:error_message;type:text;comment:错误信息" json:"error_message"` + StartedAt *time.Time `gorm:"column:started_at;comment:开始处理时间" json:"started_at"` + CompletedAt *time.Time `gorm:"column:completed_at;comment:完成时间" json:"completed_at"` + RealnamePolicy string `gorm:"column:realname_policy;type:varchar(20);default:'none';not null;comment:导入批次实名策略(none=无需实名,before_order=先实名后充值/购买,after_order=先充值/购买后实名)" json:"realname_policy"` } // TableName 指定表名 diff --git a/internal/model/iot_card.go b/internal/model/iot_card.go index ccbb64b..70038b6 100644 --- a/internal/model/iot_card.go +++ b/internal/model/iot_card.go @@ -54,6 +54,7 @@ type IotCard struct { VirtualNo string `gorm:"column:virtual_no;type:varchar(50);uniqueIndex:idx_iot_card_virtual_no,where:deleted_at IS NULL AND virtual_no IS NOT NULL AND virtual_no <> '';comment:虚拟号(可选,非空时全局唯一)" json:"virtual_no,omitempty"` DeviceVirtualNo string `gorm:"column:device_virtual_no;type:varchar(100);not null;default:'';comment:绑定设备的虚拟号快照(未绑定时为空字符串)" json:"device_virtual_no"` LastGatewayReadingMB float64 `gorm:"column:last_gateway_reading_mb;type:float;not null;default:0;comment:上次轮询时网关返回的流量读数(MB)" json:"last_gateway_reading_mb"` + RealnamePolicy string `gorm:"column:realname_policy;type:varchar(20);default:'none';not null;comment:实名认证策略(none=无需实名,before_order=先实名后充值/购买,after_order=先充值/购买后实名)" json:"realname_policy"` } // TableName 指定表名 diff --git a/internal/model/iot_card_import_task.go b/internal/model/iot_card_import_task.go index f9b2ea1..3dc85ba 100644 --- a/internal/model/iot_card_import_task.go +++ b/internal/model/iot_card_import_task.go @@ -10,28 +10,29 @@ import ( type IotCardImportTask struct { gorm.Model - BaseModel `gorm:"embedded"` - TaskNo string `gorm:"column:task_no;type:varchar(50);uniqueIndex:idx_import_task_no,where:deleted_at IS NULL;not null;comment:任务编号(IMP-YYYYMMDD-XXXXXX)" json:"task_no"` - Status int `gorm:"column:status;type:int;default:1;not null;comment:任务状态 1-待处理 2-处理中 3-已完成 4-失败" json:"status"` - CarrierID uint `gorm:"column:carrier_id;index;not null;comment:运营商ID" json:"carrier_id"` - CarrierType string `gorm:"column:carrier_type;type:varchar(20);not null;comment:运营商类型(CMCC/CUCC/CTCC/CBN)" json:"carrier_type"` - CarrierName string `gorm:"column:carrier_name;type:varchar(100);comment:运营商名称,创建任务时快照" json:"carrier_name"` - BatchNo string `gorm:"column:batch_no;type:varchar(100);comment:批次号" json:"batch_no"` - FileName string `gorm:"column:file_name;type:varchar(255);comment:原始文件名" json:"file_name"` - TotalCount int `gorm:"column:total_count;type:int;default:0;not null;comment:总数" json:"total_count"` - SuccessCount int `gorm:"column:success_count;type:int;default:0;not null;comment:成功数" json:"success_count"` - SkipCount int `gorm:"column:skip_count;type:int;default:0;not null;comment:跳过数" json:"skip_count"` - FailCount int `gorm:"column:fail_count;type:int;default:0;not null;comment:失败数" json:"fail_count"` - SkippedItems ImportResultItems `gorm:"column:skipped_items;type:jsonb;comment:跳过记录详情" json:"skipped_items"` - FailedItems ImportResultItems `gorm:"column:failed_items;type:jsonb;comment:失败记录详情" json:"failed_items"` - StartedAt *time.Time `gorm:"column:started_at;comment:开始处理时间" json:"started_at"` - CompletedAt *time.Time `gorm:"column:completed_at;comment:完成时间" json:"completed_at"` - ErrorMessage string `gorm:"column:error_message;type:text;comment:任务级错误信息" json:"error_message"` - ShopID *uint `gorm:"column:shop_id;index;comment:店铺ID(发起导入的店铺)" json:"shop_id,omitempty"` - CardList CardListJSON `gorm:"column:card_list;type:jsonb;comment:待导入卡列表[{iccid,msisdn}]" json:"-"` - StorageBucket string `gorm:"column:storage_bucket;type:varchar(100);comment:对象存储桶名" json:"storage_bucket,omitempty"` - StorageKey string `gorm:"column:storage_key;type:varchar(500);comment:对象存储文件路径" json:"storage_key,omitempty"` - CardCategory string `gorm:"column:card_category;type:varchar(20);default:normal;not null;comment:卡业务类型(normal/industry)" json:"card_category"` + BaseModel `gorm:"embedded"` + TaskNo string `gorm:"column:task_no;type:varchar(50);uniqueIndex:idx_import_task_no,where:deleted_at IS NULL;not null;comment:任务编号(IMP-YYYYMMDD-XXXXXX)" json:"task_no"` + Status int `gorm:"column:status;type:int;default:1;not null;comment:任务状态 1-待处理 2-处理中 3-已完成 4-失败" json:"status"` + CarrierID uint `gorm:"column:carrier_id;index;not null;comment:运营商ID" json:"carrier_id"` + CarrierType string `gorm:"column:carrier_type;type:varchar(20);not null;comment:运营商类型(CMCC/CUCC/CTCC/CBN)" json:"carrier_type"` + CarrierName string `gorm:"column:carrier_name;type:varchar(100);comment:运营商名称,创建任务时快照" json:"carrier_name"` + BatchNo string `gorm:"column:batch_no;type:varchar(100);comment:批次号" json:"batch_no"` + FileName string `gorm:"column:file_name;type:varchar(255);comment:原始文件名" json:"file_name"` + TotalCount int `gorm:"column:total_count;type:int;default:0;not null;comment:总数" json:"total_count"` + SuccessCount int `gorm:"column:success_count;type:int;default:0;not null;comment:成功数" json:"success_count"` + SkipCount int `gorm:"column:skip_count;type:int;default:0;not null;comment:跳过数" json:"skip_count"` + FailCount int `gorm:"column:fail_count;type:int;default:0;not null;comment:失败数" json:"fail_count"` + SkippedItems ImportResultItems `gorm:"column:skipped_items;type:jsonb;comment:跳过记录详情" json:"skipped_items"` + FailedItems ImportResultItems `gorm:"column:failed_items;type:jsonb;comment:失败记录详情" json:"failed_items"` + StartedAt *time.Time `gorm:"column:started_at;comment:开始处理时间" json:"started_at"` + CompletedAt *time.Time `gorm:"column:completed_at;comment:完成时间" json:"completed_at"` + ErrorMessage string `gorm:"column:error_message;type:text;comment:任务级错误信息" json:"error_message"` + ShopID *uint `gorm:"column:shop_id;index;comment:店铺ID(发起导入的店铺)" json:"shop_id,omitempty"` + CardList CardListJSON `gorm:"column:card_list;type:jsonb;comment:待导入卡列表[{iccid,msisdn}]" json:"-"` + StorageBucket string `gorm:"column:storage_bucket;type:varchar(100);comment:对象存储桶名" json:"storage_bucket,omitempty"` + StorageKey string `gorm:"column:storage_key;type:varchar(500);comment:对象存储文件路径" json:"storage_key,omitempty"` + CardCategory string `gorm:"column:card_category;type:varchar(20);default:normal;not null;comment:卡业务类型(normal/industry)" json:"card_category"` + RealnamePolicy string `gorm:"column:realname_policy;type:varchar(20);default:'none';not null;comment:导入批次实名策略(none=无需实名,before_order=先实名后充值/购买,after_order=先充值/购买后实名)" json:"realname_policy"` } // CardItem 卡信息(ICCID + MSISDN + VirtualNo)