feat ast => ats
feat 添加trace ats字段
This commit is contained in:
parent
cd385c31e7
commit
6c981e119c
@ -69,6 +69,7 @@ type FindArticleQuery struct {
|
||||
Pid string `query:"pid"`
|
||||
Available *bool `query:"available"` //可购买
|
||||
RateSort string `query:"rate_sort,omitempty"` // 收益率排序
|
||||
Ban *bool `query:"ban"`
|
||||
}
|
||||
|
||||
func NewFindArticleQuery() *FindArticleQuery {
|
||||
@ -95,6 +96,12 @@ func (f *FindArticleQuery) SetAvailable(available bool) *FindArticleQuery {
|
||||
return f
|
||||
}
|
||||
|
||||
// 设置是否被ban
|
||||
func (f *FindArticleQuery) SetBan(ban bool) *FindArticleQuery {
|
||||
f.Ban = &ban
|
||||
return f
|
||||
}
|
||||
|
||||
func (f *FindArticleQuery) Scope(db *gorm.DB) *gorm.DB {
|
||||
if f.ID != 0 {
|
||||
db = db.Where("id=?", f.ID)
|
||||
@ -111,6 +118,9 @@ func (f *FindArticleQuery) Scope(db *gorm.DB) *gorm.DB {
|
||||
if f.Available != nil {
|
||||
db = db.Where("available=?", *f.Available)
|
||||
}
|
||||
if f.Ban != nil {
|
||||
db = db.Where("ban=?", *f.Ban)
|
||||
}
|
||||
return db
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func GetDevDB() (*gorm.DB, error) {
|
||||
dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%s sslmode=disable TimeZone=Asia/Shanghai", "192.168.31.55", "timerzz", "zhhg1997", "kedaya_dev", "5432")
|
||||
dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%s sslmode=disable TimeZone=Asia/Shanghai", "192.168.31.55", "timerzz", "zhhg1997", "kedaya", "5432")
|
||||
return gorm.Open(postgres.Open(dsn), &gorm.Config{})
|
||||
}
|
||||
|
||||
|
@ -31,14 +31,16 @@ func NewProviderArticleApi(db *gorm.DB) ProviderArticleApi {
|
||||
// ******************GET
|
||||
|
||||
type GetProviderArticleQuery struct {
|
||||
ID uint `query:"id"`
|
||||
Brand v2.Brand `query:"brand"`
|
||||
Pid string `query:"pid"`
|
||||
ProviderId v2.ProviderId `query:"providerId"`
|
||||
SkuId string `query:"skuId"`
|
||||
WatchNotNull bool `query:"watchNotNull"`
|
||||
Watch *bool `query:"watch"`
|
||||
Keyword string `query:"keyword"`
|
||||
ID uint `query:"id"`
|
||||
Brand v2.Brand `query:"brand"`
|
||||
Pid string `query:"pid"`
|
||||
ProviderId v2.ProviderId `query:"providerId"`
|
||||
SkuId string `query:"skuId"`
|
||||
WatchNotNull bool `query:"watchNotNull"`
|
||||
Watch *bool `query:"watch"`
|
||||
TraceAtsNotNull bool `query:"traceAtsNotNull"`
|
||||
TraceAts *bool `query:"traceAts"`
|
||||
Keyword string `query:"keyword"`
|
||||
}
|
||||
|
||||
func NewGetProviderArticleQuery() *GetProviderArticleQuery {
|
||||
@ -83,6 +85,16 @@ func (g *GetProviderArticleQuery) SetKeyword(keyword string) *GetProviderArticle
|
||||
return g
|
||||
}
|
||||
|
||||
func (g *GetProviderArticleQuery) SetTraceAts(traceAts bool) *GetProviderArticleQuery {
|
||||
g.TraceAts = &traceAts
|
||||
return g
|
||||
}
|
||||
|
||||
func (g *GetProviderArticleQuery) SetTraceAtsNotNull(traceAtsNotNull bool) *GetProviderArticleQuery {
|
||||
g.TraceAtsNotNull = traceAtsNotNull
|
||||
return g
|
||||
}
|
||||
|
||||
func (g *GetProviderArticleQuery) Scope(db *gorm.DB) *gorm.DB {
|
||||
if g.ID > 0 {
|
||||
db = db.Where("id=?", g.ID)
|
||||
@ -105,6 +117,12 @@ func (g *GetProviderArticleQuery) Scope(db *gorm.DB) *gorm.DB {
|
||||
if g.Watch != nil {
|
||||
db = db.Where("watch=?", *g.Watch)
|
||||
}
|
||||
if g.TraceAtsNotNull {
|
||||
db = db.Not("trace_ats", nil)
|
||||
}
|
||||
if g.TraceAts != nil {
|
||||
db = db.Where("trace_ats=?", *g.TraceAts)
|
||||
}
|
||||
if g.Keyword != "" {
|
||||
db = db.Where("(name ilike ? or sku_id ilike ?)", "%"+g.Keyword+"%", "%"+g.Keyword+"%")
|
||||
}
|
||||
@ -119,7 +137,7 @@ func (p *providerArticleApi) Get(query *GetProviderArticleQuery) (article v2.Pro
|
||||
func (p *providerArticleApi) Upsert(article v2.ProviderArticle) error {
|
||||
if err := p.db.Clauses(clause.OnConflict{
|
||||
Columns: []clause.Column{{Name: "provider_id"}, {Name: "sku_id"}},
|
||||
DoUpdates: clause.AssignmentColumns([]string{"cost", "available", "updated_at", "ast"}),
|
||||
DoUpdates: clause.AssignmentColumns([]string{"cost", "available", "updated_at", "ats"}),
|
||||
}).Create(&article).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -52,3 +52,37 @@ func TestProviderArticleApi_FindInBatches(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFullImage(t *testing.T) {
|
||||
db, err := GetDevDB()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var articles []*v2.ProviderArticle
|
||||
articles, err = NewStorage(db).ProviderArticle().Find(
|
||||
NewGetProviderArticleQuery().
|
||||
SetProviderId("us-coach-outlet").
|
||||
SetWatch(true),
|
||||
)
|
||||
fmt.Println(articles)
|
||||
//var pids []string
|
||||
//db.Table("watch_info").Select("pid").Not("pid", nil).Not("pid", "").Where("has_detail=?", true).Where("deleted_at", nil).Find(&pids)
|
||||
//nots := []string{}
|
||||
//for _, pid := range pids {
|
||||
// var p v2.ProviderArticle
|
||||
// err = db.Where("pid=?", pid).First(&p).Error
|
||||
// if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
// nots = append(nots, pid)
|
||||
// } else if err != nil {
|
||||
// fmt.Printf("%s 查询失败: %v", pid, err)
|
||||
// } else {
|
||||
// p.SetWatch(true)
|
||||
// p.Available = false
|
||||
// err = db.Select("watch", "available").Updates(&p).Error
|
||||
// if err != nil {
|
||||
// fmt.Printf("%s 更新失败: %v", pid, err)
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//fmt.Printf("以下共%d个pid未找到: %s", len(nots), nots)
|
||||
}
|
||||
|
@ -31,6 +31,8 @@ type Article struct {
|
||||
Available bool `json:"available"`
|
||||
// 排除
|
||||
Exclude bool `json:"exclude"`
|
||||
// 屏蔽 如果一个商品被屏蔽,那么所有供应商和销售商都不会继续抓取,而且页面上也不会继续显示
|
||||
Ban bool `json:"ban"`
|
||||
// 最低成本价
|
||||
CostPrice float64 `json:"costPrice"`
|
||||
// 供应商报价列表
|
||||
@ -44,3 +46,16 @@ type Article struct {
|
||||
//备注
|
||||
Remark string `json:"remark"`
|
||||
}
|
||||
|
||||
func (a *Article) SetBan(ban bool) *Article {
|
||||
a.Ban = ban
|
||||
for _, provider := range a.Providers {
|
||||
provider.Exclude = a.Ban
|
||||
provider.Watch = nil
|
||||
}
|
||||
|
||||
for _, seller := range a.Sellers {
|
||||
seller.Exclude = a.Ban
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
@ -69,7 +69,9 @@ type ProviderArticle struct {
|
||||
// 当前成本价
|
||||
Cost ProviderPrice `json:"cost" gorm:"type:json;serializer:json"`
|
||||
// 库存数量
|
||||
Ast int `json:"ast"`
|
||||
Ats int `json:"ats"`
|
||||
// 监控库存
|
||||
TraceAts *bool `json:"traceAts"`
|
||||
// 能否购买
|
||||
Available bool `json:"available"`
|
||||
// 是否蹲货
|
||||
@ -80,6 +82,8 @@ type ProviderArticle struct {
|
||||
Exclude bool `json:"exclude"`
|
||||
// 历史成本价格
|
||||
HistoryPrice []ProviderPrice `json:"historyPrice"`
|
||||
// 历史库存
|
||||
HistoryAts []ProviderAts `json:"historyAts"`
|
||||
// 计算过程
|
||||
CalculateProcess []CalculateProcess `json:"calculateProcess" gorm:"polymorphicType:Kind;polymorphicId:OwnerID;polymorphicValue:providerArticle"`
|
||||
}
|
||||
@ -89,6 +93,12 @@ func (p *ProviderArticle) SetWatch(watch bool) *ProviderArticle {
|
||||
return p
|
||||
}
|
||||
|
||||
// 设置是否追踪库存
|
||||
func (p *ProviderArticle) SetTraceAts(traceAts bool) *ProviderArticle {
|
||||
p.TraceAts = &traceAts
|
||||
return p
|
||||
}
|
||||
|
||||
// ProviderPrice 供应商成本价格
|
||||
type ProviderPrice struct {
|
||||
ID uint `gorm:"primary_key" json:"id"`
|
||||
@ -101,3 +111,13 @@ type ProviderPrice struct {
|
||||
FinalPrice float64 `json:"finalPrice"` // 计算完优惠的最终的价格
|
||||
CalMark string `json:"calMark"` //计算优惠的过程
|
||||
}
|
||||
|
||||
// ProviderAts 供应商库存
|
||||
type ProviderAts struct {
|
||||
ID uint `gorm:"primary_key" json:"id"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
|
||||
ProviderArticleID uint `gorm:"index"`
|
||||
// 供应商库存
|
||||
Ats int `json:"ats"`
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user