watcher/pkg/model/watcher.go
timerzz 99ea10b74f
Some checks failed
Build image / build (push) Failing after 13s
feat 分离pusher
2024-05-21 16:42:45 +08:00

66 lines
1.7 KiB
Go

package model
import (
"fmt"
"gitea.timerzz.com/kedaya_haitao/pusher/kitex_gen/config"
"gorm.io/gorm"
"time"
)
type WatchInfo struct {
ID uint `gorm:"primaryKey" json:"id"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt gorm.DeletedAt `gorm:"index"`
UpdateErr bool `json:"updateErr"` //更新出错了
Uid string `json:"uid" gorm:"index:,unique"`
Pid string `json:"pid" gorm:"index:,not null"` //产品编号
Name string `json:"name"`
Brand string `json:"brand"`
Website WebsiteType `json:"website"` //是什么网站
Watch bool `json:"watch"`
Orderable bool `json:"orderable"`
Link string `json:"link"`
Remark string `json:"remark,omitempty"`
HasDetail bool `json:"hasDetail"`
AllocationResetDate time.Time `json:"allocationResetDate"` //上次补货时间
Pushers []config.PusherConfig `json:"pushers" gorm:"many2many:watch_pusher;"`
}
type WebsiteType uint
func (t WebsiteType) IsZero() bool {
return t == WebsiteType(0)
}
const (
CoachOutlet WebsiteType = iota + 1
)
func (w *WatchInfo) TableName() string {
return "watch_info"
}
type WatchInfor interface {
WatchInfo() *WatchInfo
}
func (w *WatchInfo) GenUid() {
if w.Uid == "" {
switch w.Website {
case CoachOutlet:
w.Uid = fmt.Sprintf("coachOutlet_%s", w.Pid)
}
}
}
func (w *WatchInfo) ToPusherIds() []int64 {
var ids = make([]int64, 0, len(w.Pushers))
for _, pusher := range w.Pushers {
ids = append(ids, pusher.Id)
}
return ids
}