Files

163 lines
9.5 KiB
Go

package models
import "time"
const (
SYBInnerCodePending = "pending"
SYBInnerCodeMatching = "matching"
SYBInnerCodeReady = "ready"
SYBInnerCodeAlreadyFilled = "already_filled"
SYBInnerCodeSkipped = "skipped"
SYBInnerCodeFailed = "failed"
SYBInnerCodeQueued = "queued"
SYBInnerCodeApplying = "applying"
SYBInnerCodeUpdated = "updated"
SYBInnerCodeNeedsCheck = "needs_check"
)
// SYBInnerCodeRecord is one Excel business identity. Individual inbound codes
// live in SYBInnerCodeItem so order and uniqueness do not depend on CSV text.
type SYBInnerCodeRecord struct {
ID uint64 `json:"id" gorm:"primaryKey;autoIncrement"`
BusinessDate string `json:"businessDate" gorm:"size:10;not null;index;uniqueIndex:ux_syb_inner_code_business,priority:1"`
OrderNumber string `json:"orderNumber" gorm:"size:64;not null;index;uniqueIndex:ux_syb_inner_code_business,priority:2"`
Stall string `json:"stall" gorm:"size:191;not null;uniqueIndex:ux_syb_inner_code_business,priority:3"`
SpecKey string `json:"specKey" gorm:"size:500;not null;uniqueIndex:ux_syb_inner_code_business,priority:4"`
SpecRaw string `json:"specRaw" gorm:"size:500;not null"`
SourceSKURaw string `json:"sourceSkuRaw" gorm:"size:500;not null"`
ShopName string `json:"shopName" gorm:"size:191;not null"`
SourceRow int `json:"sourceRow" gorm:"not null"`
PrintSequence int `json:"printSequence" gorm:"not null;default:0"`
Status string `json:"status" gorm:"size:24;not null;index"`
ResultMessage string `json:"resultMessage" gorm:"size:1000;not null;default:''"`
CreatedBy uint64 `json:"createdBy" gorm:"not null"`
ImportRequestID string `json:"-" gorm:"size:36;not null;index"`
LastDeleteRequestID *string `json:"-" gorm:"size:36;index"`
ApplyBatchID *string `json:"applyBatchId" gorm:"size:36;index"`
ApplyStartedAt *time.Time `json:"applyStartedAt"`
AppliedAt *time.Time `json:"appliedAt"`
Items []SYBInnerCodeItem `json:"items" gorm:"foreignKey:RecordID;references:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
Plan *SYBInnerCodePlan `json:"plan,omitempty" gorm:"foreignKey:RecordID;references:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
func (SYBInnerCodeRecord) TableName() string { return "syb_inner_code_record" }
type SYBInnerCodeItem struct {
ID uint64 `json:"id" gorm:"primaryKey;autoIncrement"`
RecordID uint64 `json:"recordId" gorm:"not null;index;uniqueIndex:ux_syb_inner_code_record_ordinal,priority:1"`
BusinessDate string `json:"-" gorm:"size:10;not null;uniqueIndex:ux_syb_inner_code_date_code,priority:1"`
Code string `json:"code" gorm:"size:128;not null;uniqueIndex:ux_syb_inner_code_date_code,priority:2"`
Ordinal int `json:"ordinal" gorm:"not null;uniqueIndex:ux_syb_inner_code_record_ordinal,priority:2"`
SourceRow int `json:"sourceRow" gorm:"not null"`
CreatedAt time.Time `json:"createdAt"`
}
func (SYBInnerCodeItem) TableName() string { return "syb_inner_code_item" }
// SYBInnerCodeApplyBatch is introduced with the import contract so later
// writeback migrations never need to reshape imported records.
type SYBInnerCodeApplyBatch struct {
ID string `json:"id" gorm:"size:36;primaryKey"`
RequestID string `json:"-" gorm:"size:36;not null;uniqueIndex:ux_syb_inner_code_apply_request"`
Status string `json:"status" gorm:"size:24;not null;index"`
Requested int `json:"requested" gorm:"not null"`
Processed int `json:"processed" gorm:"not null;default:0"`
CreatedBy uint64 `json:"createdBy" gorm:"not null"`
StartedAt *time.Time `json:"startedAt"`
FinishedAt *time.Time `json:"finishedAt"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
func (SYBInnerCodeApplyBatch) TableName() string { return "syb_inner_code_apply_batch" }
type SYBInnerCodeApplyItem struct {
ID uint64 `json:"id" gorm:"primaryKey;autoIncrement"`
BatchID string `json:"batchId" gorm:"size:36;not null;index;uniqueIndex:ux_syb_inner_code_apply_item,priority:1"`
Batch SYBInnerCodeApplyBatch `json:"-" gorm:"foreignKey:BatchID;references:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
RecordID uint64 `json:"recordId" gorm:"not null;index;uniqueIndex:ux_syb_inner_code_apply_item,priority:2"`
Record SYBInnerCodeRecord `json:"-" gorm:"foreignKey:RecordID;references:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
Status string `json:"status" gorm:"size:24;not null;index"`
Message string `json:"message" gorm:"size:1000;not null;default:''"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
func (SYBInnerCodeApplyItem) TableName() string { return "syb_inner_code_apply_item" }
type SYBInnerCodeCheckpoint struct {
ID uint64 `json:"id" gorm:"primaryKey;autoIncrement"`
RecordID uint64 `json:"recordId" gorm:"not null;index;uniqueIndex:ux_syb_inner_code_checkpoint_seq,priority:1"`
Record SYBInnerCodeRecord `json:"-" gorm:"foreignKey:RecordID;references:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
Sequence int `json:"sequence" gorm:"not null;uniqueIndex:ux_syb_inner_code_checkpoint_seq,priority:2"`
Phase string `json:"phase" gorm:"size:32;not null"`
Action string `json:"action" gorm:"size:32;not null"`
StateJSON string `json:"state" gorm:"type:text;not null"`
CreatedAt time.Time `json:"createdAt"`
}
func (SYBInnerCodeCheckpoint) TableName() string { return "syb_inner_code_checkpoint" }
type SYBInnerCodeWorkerLease struct {
ID uint8 `json:"-" gorm:"primaryKey;autoIncrement:false"`
OwnerID string `json:"-" gorm:"size:36;not null"`
ExpiresAt time.Time `json:"-" gorm:"not null;index"`
Version uint64 `json:"-" gorm:"not null;default:0"`
UpdatedAt time.Time `json:"-"`
}
func (SYBInnerCodeWorkerLease) TableName() string { return "syb_inner_code_worker_lease" }
// SYBInnerCodeMutation records idempotent import/delete request results.
type SYBInnerCodeMutation struct {
RequestID string `json:"-" gorm:"size:36;primaryKey"`
Action string `json:"-" gorm:"size:16;not null"`
ResultJSON string `json:"-" gorm:"type:text;not null"`
CreatedAt time.Time `json:"-"`
}
func (SYBInnerCodeMutation) TableName() string { return "syb_inner_code_mutation" }
type SYBInnerCodeMatchJob struct {
ID string `json:"id" gorm:"size:36;primaryKey"`
WorkKey string `json:"-" gorm:"size:128;not null;uniqueIndex:ux_syb_inner_code_match_work"`
BusinessDate string `json:"businessDate" gorm:"size:10;not null;index"`
RecordIDsJSON string `json:"-" gorm:"type:text;not null"`
Status string `json:"status" gorm:"size:24;not null;index"`
Total int `json:"total" gorm:"not null;default:0"`
Processed int `json:"processed" gorm:"not null;default:0"`
Ready int `json:"ready" gorm:"not null;default:0"`
Failed int `json:"failed" gorm:"not null;default:0"`
ErrorMessage string `json:"errorMessage" gorm:"size:1000;not null;default:''"`
StartedAt *time.Time `json:"startedAt"`
FinishedAt *time.Time `json:"finishedAt"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
func (SYBInnerCodeMatchJob) TableName() string { return "syb_inner_code_match_job" }
type SYBInnerCodePlan struct {
ID uint64 `json:"id" gorm:"primaryKey;autoIncrement"`
RecordID uint64 `json:"recordId" gorm:"not null;uniqueIndex:ux_syb_inner_code_plan_record"`
Record SYBInnerCodeRecord `json:"-" gorm:"foreignKey:RecordID;references:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
MatchJobID string `json:"matchJobId" gorm:"size:36;not null;index"`
StockID int64 `json:"stockId" gorm:"not null"`
DetailID int64 `json:"detailId" gorm:"not null"`
SYBSpec string `json:"sybSpec" gorm:"size:500;not null"`
SYBSKU string `json:"sybSku" gorm:"size:500;not null"`
SYBVariationSKU string `json:"sybVariationSku" gorm:"size:500;not null"`
PurchasePlatform string `json:"purchasePlatform" gorm:"size:255;not null"`
PurchaseCode string `json:"purchaseCode" gorm:"size:255;not null"`
RemoteInnerCode string `json:"remoteInnerCode" gorm:"size:128;not null"`
RemoteItemsJSON string `json:"remoteItems" gorm:"type:text;not null"`
PlaceholderCount int `json:"placeholderCount" gorm:"not null;default:0"`
ReplaceOldCodeCount int `json:"replaceOldCodeCount" gorm:"not null;default:0"`
EvidenceHash string `json:"evidenceHash" gorm:"size:64;not null"`
PlannedAt time.Time `json:"plannedAt" gorm:"not null"`
}
func (SYBInnerCodePlan) TableName() string { return "syb_inner_code_plan" }