package dao import ( "film/global" "film/model" "gorm.io/gorm" ) type NowCarDao struct { } func NewNowCarDao() *NowCarDao { return &NowCarDao{} } func (d *NowCarDao) TableName() string { return "nowcar" } func (d *NowCarDao) Create(o *model.Nowcar) (int64, error) { res := global.GetDB().Table(d.TableName()).Create(o) return o.Id, res.Error } func (d *NowCarDao) Update(o *model.Nowcar) error { tx := global.GetDB().Table(d.TableName()) res := tx.Save(o) return res.Error } func (d *NowCarDao) GetStart(shopName, workstation string, startTime int64) (*model.Nowcar, error) { var u model.Nowcar tx := global.GetDB().Table(d.TableName()) tx = tx.Where("shop_name = ?", shopName) tx = tx.Where("workstation = ?", workstation) tx = tx.Where("start_time = ?", startTime) tx = tx.Order("start_time DESC") res := tx.First(&u) if res.Error == gorm.ErrRecordNotFound { return nil, nil } if res.Error != nil { return nil, res.Error } return &u, nil } func (d *NowCarDao) GetBusy(shopName, workstation string) (*model.Nowcar, error) { var u model.Nowcar tx := global.GetDB().Table(d.TableName()) tx = tx.Where("shop_name = ?", shopName) tx = tx.Where("workstation = ?", workstation) tx = tx.Where("start_time != 0") tx = tx.Where("end_time = 0") tx = tx.Order("start_time DESC") res := tx.First(&u) if res.Error == gorm.ErrRecordNotFound { return nil, nil } if res.Error != nil { return nil, res.Error } return &u, nil } func (d *NowCarDao) QueryToday(shopName, workstation, day string) ([]*model.Nowcar, error) { var u []*model.Nowcar tx := global.GetDB().Table(d.TableName()) tx = tx.Where("shop_name = ?", shopName) tx = tx.Where("workstation = ?", workstation) tx = tx.Where("day = ?", day) tx = tx.Where("start_time != 0") tx = tx.Where("end_time != 0") tx = tx.Order("start_time DESC") res := tx.Find(&u) if res.Error == gorm.ErrRecordNotFound { return nil, nil } if res.Error != nil { return nil, res.Error } return u, nil }