From cba02db8e82417519a7b7ea7621612a866c28930 Mon Sep 17 00:00:00 2001 From: timerzz Date: Fri, 30 Aug 2024 13:59:01 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E6=B7=BB=E5=8A=A0=E4=BE=9B=E5=BA=94?= =?UTF-8?q?=E5=95=86=E5=92=8C=E9=94=80=E5=94=AE=E5=95=86=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- structs/storage/provider.go | 8 ++++++++ structs/storage/seller.go | 8 ++++++++ structs/v2/provider.go | 16 ++++++++++++++++ structs/v2/seller.go | 16 ++++++++++++++++ 4 files changed, 48 insertions(+) diff --git a/structs/storage/provider.go b/structs/storage/provider.go index 34c1567..c1e9b2e 100644 --- a/structs/storage/provider.go +++ b/structs/storage/provider.go @@ -16,6 +16,7 @@ type ProviderApi interface { List(query PageListQuery) (providers []v2.Provider, total int64, err error) Create(provider v2.Provider) error Update(provider v2.Provider) error + UpdateStatus(provider v2.Provider) error Delete(id uint) (provider v2.Provider, err error) AutoMigrate() error } @@ -97,6 +98,13 @@ func (p *providerApi) Update(provider v2.Provider) error { }) } +func (p *providerApi) UpdateStatus(provider v2.Provider) error { + if provider.ID == 0 { + return fmt.Errorf("id为空") + } + return p.db.Model(&provider).Where("id = ?", provider.ID).Select("status", "msg", "pull_at").Updates(&provider).Error +} + func (p *providerApi) Delete(id uint) (provider v2.Provider, err error) { err = p.db.Transaction(func(tx *gorm.DB) error { if err = tx.Where("owner_id = ? AND kind = ?", id, "provider").Delete(&v2.CalculateProcess{}).Error; err != nil { diff --git a/structs/storage/seller.go b/structs/storage/seller.go index 0b95730..d9f168f 100644 --- a/structs/storage/seller.go +++ b/structs/storage/seller.go @@ -16,6 +16,7 @@ type SellerApi interface { List(query PageListQuery) (sellers []v2.Seller, total int64, err error) Create(seller v2.Seller) error Update(seller v2.Seller) error + UpdateStatus(seller v2.Seller) error Delete(id uint) (seller v2.Seller, err error) AutoMigrate() error } @@ -97,6 +98,13 @@ func (p *sellerApi) Update(seller v2.Seller) error { }) } +func (p *sellerApi) UpdateStatus(seller v2.Seller) error { + if seller.ID == 0 { + return fmt.Errorf("id为空") + } + return p.db.Model(&seller).Where("id = ?", seller.ID).Select("status", "msg", "pull_at").Updates(&seller).Error +} + func (p *sellerApi) Delete(id uint) (seller v2.Seller, err error) { err = p.db.Transaction(func(tx *gorm.DB) error { if err = tx.Where("owner_id = ? AND kind = ?", id, "seller").Delete(&v2.CalculateProcess{}).Error; err != nil { diff --git a/structs/v2/provider.go b/structs/v2/provider.go index a1f464d..0ad9410 100644 --- a/structs/v2/provider.go +++ b/structs/v2/provider.go @@ -4,6 +4,16 @@ import ( "time" ) +type ProviderStatus int + +const ( + ProviderStatus_Normal = iota + // 正在拉取供应商商品信息 + ProviderStatus_Pulling + // 出错 + ProviderStatus_Error +) + type ProviderId string type Provider struct { @@ -14,6 +24,12 @@ type Provider struct { ProviderId ProviderId `gorm:"unique" json:"providerId"` // 供应商的名称 Name string `json:"name"` + // 供应商状态 + Status ProviderStatus `json:"status"` + // 错误信息 + Msg string `json:"msg"` + // 拉取时间 + PullAt time.Time `json:"pullAt"` // 供应商配置 Config ProviderOption `gorm:"type:json;serializer:json" json:"config"` //计算过程 diff --git a/structs/v2/seller.go b/structs/v2/seller.go index 8873a98..972e39a 100644 --- a/structs/v2/seller.go +++ b/structs/v2/seller.go @@ -4,6 +4,16 @@ import ( "time" ) +type SellerStatus int + +const ( + SellerStatus_Normal = iota + // 正在拉取销售商商品信息 + SellerStatus_Pulling + // 出错 + SellerStatus_Error +) + type SellerId string // Seller 出货商 @@ -15,6 +25,12 @@ type Seller struct { SellerId SellerId `gorm:"unique" json:"sellerId"` // 出货商的名称 Name string `json:"name"` + // 供应商状态 + Status SellerStatus `json:"status"` + // 错误信息 + Msg string `json:"msg"` + // 拉取时间 + PullAt time.Time `json:"pullAt"` // 出货商配置 Config SellerOption `gorm:"type:json;serializer:json" json:"config"` //计算过程