feat: 卡实名时间以上游 archiveTime 为准并记录实名时间历史,新增二次实名批次
Some checks failed
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Has been cancelled

This commit is contained in:
邹进
2026-11-08 19:12:46 +09:00
parent 94f86ab217
commit 4967f4df43
32 changed files with 1885 additions and 47 deletions

View File

@@ -27,7 +27,9 @@ type AssetResolveResponse struct {
ActivationStatus int `json:"activation_status" description:"激活状态:0未激活 1已激活;设备需有生效中主套餐且任意绑定卡已实名"`
ActivationStatusName string `json:"activation_status_name" description:"激活状态名称(中文)"`
RealNameStatus int `json:"real_name_status" description:"实名状态:0未实名 1已实名"`
RealNameAt *time.Time `json:"real_name_at" description:"最近一次完成实名的时间,未实名时为 null"`
RealNameAt *time.Time `json:"real_name_at" description:"实名时间:上游返回的实名时间优先,否则为首次读到已实名的时间;未实名时为 null"`
RealNameAtSource string `json:"real_name_at_source,omitempty" description:"实名时间来源(卡资产):upstream 上游返回 / first_observed 首次读到 / migrated 迁移沿用"`
RealNameAtSourceName string `json:"real_name_at_source_name,omitempty" description:"实名时间来源中文名"`
RealnamePolicy string `json:"realname_policy" description:"实名认证策略 (none:无需实名, before_order:先实名后充值/购买, after_order:先充值/购买后实名)"`
CurrentPackage string `json:"current_package" description:"当前套餐名称(无套餐时为空)"`
CurrentPackageUsageID *uint `json:"current_package_usage_id" description:"当前主套餐的套餐使用记录ID,无主套餐时为 null"`
@@ -116,7 +118,9 @@ type BoundCardInfo struct {
MSISDN string `json:"msisdn,omitempty" description:"手机号"`
NetworkStatus int `json:"network_status" description:"网络状态:0停机 1开机"`
RealNameStatus int `json:"real_name_status" description:"实名状态:0未实名 1已实名"`
RealNameAt *time.Time `json:"real_name_at" description:"该卡最近一次完成实名的时间,未实名时为 null"`
RealNameAt *time.Time `json:"real_name_at" description:"该卡实名时间:上游返回的实名时间优先,否则为首次读到已实名的时间;未实名时为 null"`
RealNameAtSource string `json:"real_name_at_source,omitempty" description:"实名时间来源:upstream 上游返回 / first_observed 首次读到 / migrated 迁移沿用"`
RealNameAtSourceName string `json:"real_name_at_source_name,omitempty" description:"实名时间来源中文名"`
SlotPosition int `json:"slot_position,omitempty" description:"插槽位置"`
IsCurrent bool `json:"is_current" description:"是否为当前使用的卡"`
CarrierID uint `json:"carrier_id,omitempty" description:"运营商ID"`

View File

@@ -0,0 +1,114 @@
package dto
import "time"
// CardRealnameHistoryListRequest 查询单卡实名时间历史。
type CardRealnameHistoryListRequest struct {
ID uint `json:"-" path:"id" description:"IoT卡ID"`
Page int `json:"page" query:"page" validate:"omitempty,min=1" minimum:"1" description:"页码"`
PageSize int `json:"page_size" query:"page_size" validate:"omitempty,min=1,max=100" minimum:"1" maximum:"100" description:"每页数量"`
}
// CardRealnameCurrentResponse 是卡当前实名时间。
type CardRealnameCurrentResponse struct {
CardID uint `json:"card_id" description:"IoT卡ID"`
RealnameAt *time.Time `json:"realname_at" description:"当前实名时间:上游返回的实名时间优先,否则为首次读到已实名的时间"`
RealnameAtSource string `json:"realname_at_source" description:"实名时间来源:upstream 上游返回 / first_observed 首次读到 / migrated 迁移沿用"`
RealnameAtSourceName string `json:"realname_at_source_name" description:"实名时间来源中文名"`
UpstreamRealnameAt *time.Time `json:"upstream_realname_at" description:"上游最近一次返回的实名时间"`
FirstObservedAt *time.Time `json:"first_observed_at" description:"首次读到已实名的时间"`
ResetPending bool `json:"reset_pending" description:"是否等待二次实名(仅后台展示)"`
ResetAt *time.Time `json:"reset_at" description:"二次实名清除时间"`
ResetBaselineAt *time.Time `json:"reset_baseline_at" description:"清除前的上游实名时间(新旧判定基准)"`
ResetBatchID *uint `json:"reset_batch_id" description:"所属二次实名批次 ID"`
}
// CardRealnameHistoryItem 是一条实名时间变化历史。
type CardRealnameHistoryItem struct {
ID uint `json:"id" description:"历史 ID"`
CardID uint `json:"card_id" description:"IoT卡ID"`
ICCID string `json:"iccid" description:"ICCID"`
BeforeAt *time.Time `json:"before_at" description:"原实名时间"`
AfterAt *time.Time `json:"after_at" description:"新实名时间"`
AfterSource string `json:"after_source" description:"新实名时间来源"`
AfterSourceName string `json:"after_source_name" description:"新实名时间来源中文名"`
ChangeType string `json:"change_type" description:"变化类型:first 首次实名 / upstream_fix 上游更正 / reset 二次实名清除 / reset_completed 二次实名完成 / reset_reverted 二次实名撤销 / migrated 迁移补录"`
ChangeTypeName string `json:"change_type_name" description:"变化类型中文名"`
ObservationSource string `json:"observation_source" description:"观测来源:polling 轮询 / manual_sync 手动刷新 / carrier_callback 回调 / business_event 业务观测 / manual_override 人工 / migration 迁移 / package_silence 沉默期判定"`
ObservationSourceName string `json:"observation_source_name" description:"观测来源中文名"`
ResetBatchID *uint `json:"reset_batch_id" description:"关联二次实名批次 ID"`
OperatorID uint `json:"operator_id" description:"操作人账号 ID(人工时)"`
OperatorName string `json:"operator_name" description:"操作人名称"`
ObservedAt time.Time `json:"observed_at" description:"发现时间"`
CreatedAt time.Time `json:"created_at" description:"记录时间"`
}
// CardRealnameHistoryResponse 是单卡实名记录:当前实名时间与历史分页。
type CardRealnameHistoryResponse struct {
Current CardRealnameCurrentResponse `json:"current" description:"当前实名时间"`
Items []CardRealnameHistoryItem `json:"items" description:"实名时间历史(按时间倒序)"`
Total int64 `json:"total" description:"历史总数"`
Page int `json:"page" description:"页码"`
PageSize int `json:"page_size" description:"每页数量"`
}
// RealnameResetImportRequest 导入二次实名名单。
type RealnameResetImportRequest struct {
Identifiers []string `json:"identifiers" validate:"required,min=1,max=1000,dive,required,max=64" required:"true" description:"资产号列表:ICCID / 虚拟号 / IMEI,设备展开为其全部绑定卡,最多 1000 个"`
Reason string `json:"reason" validate:"required,min=1,max=500" required:"true" description:"原因"`
ImportFileKey string `json:"import_file_key" validate:"omitempty,max=500" description:"导入文件对象存储 Key(可选,留档)"`
}
// RealnameResetItem 是二次实名批次的一行结果。
type RealnameResetItem struct {
RowNo int `json:"row_no" description:"行号(从 1 开始)"`
Input string `json:"input" description:"导入的资产号"`
CardID uint `json:"card_id,omitempty" description:"卡 ID"`
ICCID string `json:"iccid,omitempty" description:"ICCID"`
Result string `json:"result" description:"结果:pending 等待二次实名 / completed 已完成 / reverted 已撤销 / skipped 跳过 / failed 失败"`
ResultName string `json:"result_name" description:"结果中文名"`
Reason string `json:"reason,omitempty" description:"跳过或失败原因"`
}
// RealnameResetBatchResponse 是二次实名批次。
type RealnameResetBatchResponse struct {
ID uint `json:"id" description:"批次 ID"`
BatchNo string `json:"batch_no" description:"批次号"`
Reason string `json:"reason" description:"原因"`
ImportFileKey string `json:"import_file_key" description:"导入文件 Key"`
TotalCount int `json:"total_count" description:"处理卡数(含跳过)"`
SucceededCount int `json:"succeeded_count" description:"已清除卡数"`
SkippedCount int `json:"skipped_count" description:"跳过或失败数"`
CompletedCount int `json:"completed_count" description:"已完成二次实名卡数"`
RevertedCount int `json:"reverted_count" description:"已撤销卡数"`
PendingCount int `json:"pending_count" description:"仍在等待二次实名卡数"`
OperatorID uint `json:"operator_id" description:"操作人账号 ID"`
OperatorName string `json:"operator_name" description:"操作人"`
CreatedAt time.Time `json:"created_at" description:"导入时间"`
Items []RealnameResetItem `json:"items,omitempty" description:"逐行结果(详情返回)"`
}
// RealnameResetBatchListRequest 查询二次实名批次。
type RealnameResetBatchListRequest struct {
BatchNo string `json:"batch_no" query:"batch_no" validate:"omitempty,max=40" description:"批次号"`
Page int `json:"page" query:"page" validate:"omitempty,min=1" minimum:"1" description:"页码"`
PageSize int `json:"page_size" query:"page_size" validate:"omitempty,min=1,max=100" minimum:"1" maximum:"100" description:"每页数量"`
}
// RealnameResetBatchIDRequest 是批次路径参数。
type RealnameResetBatchIDRequest struct {
ID uint `json:"-" path:"id" description:"批次 ID"`
}
// RealnameResetRevertRequest 撤销二次实名。
type RealnameResetRevertRequest struct {
ID uint `json:"-" path:"id" description:"批次 ID"`
CardIDs []uint `json:"card_ids" validate:"omitempty,max=1000" description:"只撤销这些卡;为空撤销整批仍在等待的卡"`
}
// RealnameResetRevertResponse 撤销结果。
type RealnameResetRevertResponse struct {
RevertedCount int `json:"reverted_count" description:"撤销成功卡数"`
FailedCount int `json:"failed_count" description:"撤销失败卡数"`
Failures []string `json:"failures,omitempty" description:"失败说明"`
}

View File

@@ -0,0 +1,67 @@
package model
import (
"time"
"gorm.io/datatypes"
)
// IotCardRealname 是卡的当前实名记录(每卡一行)。
// 实名状态 real_name_status 仍在 tb_iot_card;这里只记录实名时间及来源、二次实名状态。
type IotCardRealname struct {
ID uint `gorm:"column:id;primaryKey" json:"id"`
CardID uint `gorm:"column:card_id;not null" json:"card_id"`
RealnameAt *time.Time `gorm:"column:realname_at" json:"realname_at,omitempty"`
RealnameAtSource string `gorm:"column:realname_at_source;type:varchar(20);not null;default:''" json:"realname_at_source"`
UpstreamRealnameAt *time.Time `gorm:"column:upstream_realname_at" json:"upstream_realname_at,omitempty"`
FirstObservedAt *time.Time `gorm:"column:first_observed_at" json:"first_observed_at,omitempty"`
ResetStatus string `gorm:"column:reset_status;type:varchar(20);not null;default:'none'" json:"reset_status"`
ResetAt *time.Time `gorm:"column:reset_at" json:"reset_at,omitempty"`
ResetBaselineAt *time.Time `gorm:"column:reset_baseline_at" json:"reset_baseline_at,omitempty"`
ResetBatchID *uint `gorm:"column:reset_batch_id" json:"reset_batch_id,omitempty"`
CreatedAt time.Time `gorm:"column:created_at;not null;default:CURRENT_TIMESTAMP" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at;not null;default:CURRENT_TIMESTAMP" json:"updated_at"`
}
// TableName 指定表名。
func (IotCardRealname) TableName() string { return "tb_iot_card_realname" }
// IotCardRealnameHistory 是卡实名时间变化历史(只追加)。
type IotCardRealnameHistory struct {
ID uint `gorm:"column:id;primaryKey" json:"id"`
CardID uint `gorm:"column:card_id;not null" json:"card_id"`
ICCID string `gorm:"column:iccid;type:varchar(20);not null;default:''" json:"iccid"`
BeforeAt *time.Time `gorm:"column:before_at" json:"before_at,omitempty"`
AfterAt *time.Time `gorm:"column:after_at" json:"after_at,omitempty"`
AfterSource string `gorm:"column:after_source;type:varchar(20);not null;default:''" json:"after_source"`
ChangeType string `gorm:"column:change_type;type:varchar(30);not null" json:"change_type"`
ObservationSource string `gorm:"column:observation_source;type:varchar(30);not null;default:''" json:"observation_source"`
ResetBatchID *uint `gorm:"column:reset_batch_id" json:"reset_batch_id,omitempty"`
OperatorID uint `gorm:"column:operator_id;not null;default:0" json:"operator_id"`
ObservedAt time.Time `gorm:"column:observed_at;not null" json:"observed_at"`
CreatedAt time.Time `gorm:"column:created_at;not null;default:CURRENT_TIMESTAMP" json:"created_at"`
}
// TableName 指定表名。
func (IotCardRealnameHistory) TableName() string { return "tb_iot_card_realname_history" }
// IotCardRealnameResetBatch 是二次实名导入批次。
type IotCardRealnameResetBatch struct {
ID uint `gorm:"column:id;primaryKey" json:"id"`
BatchNo string `gorm:"column:batch_no;type:varchar(40);not null" json:"batch_no"`
ImportFileKey string `gorm:"column:import_file_key;type:varchar(500);not null;default:''" json:"import_file_key"`
Reason string `gorm:"column:reason;type:varchar(500);not null;default:''" json:"reason"`
TotalCount int `gorm:"column:total_count;not null;default:0" json:"total_count"`
SucceededCount int `gorm:"column:succeeded_count;not null;default:0" json:"succeeded_count"`
SkippedCount int `gorm:"column:skipped_count;not null;default:0" json:"skipped_count"`
RevertedCount int `gorm:"column:reverted_count;not null;default:0" json:"reverted_count"`
CompletedCount int `gorm:"column:completed_count;not null;default:0" json:"completed_count"`
Items datatypes.JSON `gorm:"column:items;type:jsonb;not null;default:'[]'" json:"items"`
OperatorID uint `gorm:"column:operator_id;not null;default:0" json:"operator_id"`
OperatorName string `gorm:"column:operator_name;type:varchar(100);not null;default:''" json:"operator_name"`
CreatedAt time.Time `gorm:"column:created_at;not null;default:CURRENT_TIMESTAMP" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at;not null;default:CURRENT_TIMESTAMP" json:"updated_at"`
}
// TableName 指定表名。
func (IotCardRealnameResetBatch) TableName() string { return "tb_iot_card_realname_reset_batch" }