film/dao/nowcar.go

91 lines
2.0 KiB
Go
Raw Permalink Normal View History

2024-04-27 23:12:44 +08:00
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
}
2024-04-30 22:36:41 +08:00
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
}