Files
opsx-licence/backend/internal/dto/sync.go
T

119 lines
4.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package dto
import "time"
// ============ 互联节点管理(管理后台) ============
// PeerRequest 创建/更新互联节点 // Logan.Li
type PeerRequest struct {
ID uint `json:"id"`
Name string `json:"name" binding:"required"`
BaseURL string `json:"base_url" binding:"required,url"`
SharedKey string `json:"shared_key" binding:"required,min=32"`
}
// PeerResponse 节点响应(不回传密钥明文) // Logan.Li
type PeerResponse struct {
ID uint `json:"id"`
Name string `json:"name"`
BaseURL string `json:"base_url"`
Status string `json:"status"`
RemoteNode string `json:"remote_node"`
KeyTail string `json:"key_tail"` // 密钥尾 4 位,供核对 // Logan.Li
LastSyncAt *time.Time `json:"last_sync_at"`
LastResult string `json:"last_result"`
CreatedAt time.Time `json:"created_at"`
}
// ============ 节点间交换契约(HMAC 认证) ============
// SyncProductPayload 产品载荷(业务键 code) // Logan.Li
type SyncProductPayload struct {
Code string `json:"code"`
Name string `json:"name"`
Version string `json:"version"`
Description string `json:"description"`
Features string `json:"features"`
Price float64 `json:"price"`
PriceModel string `json:"price_model"`
Status int `json:"status"`
UpdatedAt time.Time `json:"updated_at"`
}
// SyncPlanPayload 计划载荷(业务键 产品code+plan_type+duration) // Logan.Li
type SyncPlanPayload struct {
ProductCode string `json:"product_code"`
Name string `json:"name"`
PlanType string `json:"plan_type"`
Price float64 `json:"price"`
Currency string `json:"currency"`
Duration int `json:"duration"`
MaxDevices int `json:"max_devices"`
Features string `json:"features"`
SortOrder int `json:"sort_order"`
Status int `json:"status"`
UpdatedAt time.Time `json:"updated_at"`
}
// SyncCustomerPayload 客户载荷(业务键 email,空邮箱回退 name)。
// 合规最小化:不同步 phone/address/notes,仅同步邮箱场景必需字段 // Logan.Li
type SyncCustomerPayload struct {
Name string `json:"name"`
Company string `json:"company"`
Email string `json:"email"`
Status int `json:"status"`
UpdatedAt time.Time `json:"updated_at"`
}
// SyncLicensePayload 授权载荷(业务键 license_key) // Logan.Li
type SyncLicensePayload struct {
LicenseKey string `json:"license_key"`
ProductCode string `json:"product_code"`
CustomerEmail string `json:"customer_email"`
CustomerName string `json:"customer_name"`
Status string `json:"status"`
StartDate time.Time `json:"start_date"`
EndDate time.Time `json:"end_date"`
Duration int `json:"duration"`
MaxActivations int `json:"max_activations"`
CurrentActivations int `json:"current_activations"`
IsTrial bool `json:"is_trial"`
TrialDays int `json:"trial_days"`
UpdatedAt time.Time `json:"updated_at"`
}
// SyncItems 单次交换的数据集(按依赖顺序应用:产品→计划→客户→授权) // Logan.Li
type SyncItems struct {
Products []SyncProductPayload `json:"products"`
Plans []SyncPlanPayload `json:"plans"`
Customers []SyncCustomerPayload `json:"customers"`
Licenses []SyncLicensePayload `json:"licenses"`
}
// SyncExchangeRequest 交换请求:携带我方增量 + 我方游标 // Logan.Li
type SyncExchangeRequest struct {
Cursor time.Time `json:"cursor"` // 对端上次同步到的时点(我方记录)
Items SyncItems `json:"items"`
}
// SyncExchangeResponse 交换响应:对端增量 + 应用结果 + 对端时钟 // Logan.Li
type SyncExchangeResponse struct {
Items SyncItems `json:"items"`
Applied map[string]int `json:"applied"`
ServerTime time.Time `json:"server_time"`
NodeInfo map[string]string `json:"node_info"`
}
// SyncHandshakeRequest 握手请求(验证互联密钥并互认节点) // Logan.Li
type SyncHandshakeRequest struct {
NodeName string `json:"node_name"`
}
// SyncHandshakeResponse 握手响应 // Logan.Li
type SyncHandshakeResponse struct {
NodeID string `json:"node_id"`
NodeName string `json:"node_name"`
Version string `json:"version"`
ServerTime time.Time `json:"server_time"`
}