watcher/pkg/model/watcher.go

63 lines
1.6 KiB
Go
Raw Normal View History

2024-04-10 17:36:56 +08:00
package model
import (
2024-05-21 16:42:45 +08:00
"fmt"
"gitea.timerzz.com/kedaya_haitao/pusher/kitex_gen/config"
2024-04-10 17:36:56 +08:00
"gorm.io/gorm"
"time"
)
2024-05-21 16:42:45 +08:00
type WatchInfo struct {
2024-04-10 17:36:56 +08:00
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"` //更新出错了
2024-05-21 20:09:14 +08:00
Uid string `json:"uid" gorm:"index;unique;not null"`
Pid string `json:"pid" gorm:"index;not null"` //产品编号
2024-04-10 17:36:56 +08:00
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"`
2024-05-21 16:42:45 +08:00
HasDetail bool `json:"hasDetail"`
2024-04-10 17:36:56 +08:00
AllocationResetDate time.Time `json:"allocationResetDate"` //上次补货时间
2024-05-21 16:42:45 +08:00
Pushers []config.PusherConfig `json:"pushers" gorm:"many2many:watch_pusher;"`
2024-04-10 17:36:56 +08:00
}
type WebsiteType uint
func (t WebsiteType) IsZero() bool {
return t == WebsiteType(0)
}
const (
CoachOutlet WebsiteType = iota + 1
)
2024-05-21 16:42:45 +08:00
func (w *WatchInfo) TableName() string {
return "watch_info"
2024-04-10 17:36:56 +08:00
}
2024-05-21 16:42:45 +08:00
type WatchInfor interface {
WatchInfo() *WatchInfo
}
func (w *WatchInfo) GenUid() {
if w.Uid == "" {
2024-05-21 21:30:18 +08:00
w.Uid = fmt.Sprintf("coachOutlet_%s", w.Pid)
2024-05-21 16:42:45 +08:00
}
}
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
2024-04-10 17:36:56 +08:00
}