film/dao/ddf.go

92 lines
1.9 KiB
Go

package dao
import (
"film/global"
"film/model"
"gorm.io/gorm"
)
type DdfDao struct {
}
func NewDdfDao() *DdfDao {
return &DdfDao{}
}
func (d *DdfDao) TableName() string {
return "ddf"
}
func (d *DdfDao) Create(o *model.Ddf) (int64, error) {
res := global.GetDB().Table(d.TableName()).Create(o)
return o.Id, res.Error
}
func (d *DdfDao) Update(o *model.Ddf) error {
tx := global.GetDB().Table(d.TableName())
res := tx.Save(o)
return res.Error
}
func (d *DdfDao) GetStart(shopName, workstation string, startTime int64) (*model.Ddf, error) {
var u model.Ddf
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 *DdfDao) GetBusy(shopName, workstation string) (*model.Ddf, error) {
var u model.Ddf
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 *DdfDao) QueryToday(shopName, workstation, day string) ([]*model.Ddf, error) {
var u []*model.Ddf
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
}