package model import ( "time" "git.getensh.com/common/gopkgsv2/database" "gorm.io/gorm" ) type Ads7Model interface { List(db *gorm.DB) ([]Ads7Item, error) Update(db *gorm.DB, values interface{}) error Insert(db *gorm.DB, datab []Ads7) error Delete(db *gorm.DB) error } type Ads7 struct { ID int64 `gorm:"column:id" json:"id"` StyleId string `gorm:"column:style_id" json:"style_id"` ItemId int64 `gorm:"column:item_id" json:"item_id"` StartMile int64 `gorm:"column:start_mile" json:"start_mile"` MileCycle int64 `gorm:"column:mile_cycle" json:"mile_cycle"` StartDate int64 `gorm:"column:start_date" json:"start_date"` DateCycle int64 `gorm:"column:date_cycle" json:"date_cycle"` CreatedAt time.Time `gorm:"column:created_at" json:"created_at"` UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"` } type Ads7Item struct { ID int64 `gorm:"column:id" json:"id"` StyleId string `gorm:"column:style_id" json:"style_id"` StartMile int64 `gorm:"column:start_mile" json:"start_mile"` MileCycle int64 `gorm:"column:mile_cycle" json:"mile_cycle"` StartDate int64 `gorm:"column:start_date" json:"start_date"` DateCycle int64 `gorm:"column:date_cycle" json:"date_cycle"` ItemName string `gorm:"column:item_name" json:"item_name"` ItemType int8 `gorm:"column:item_type" json:"item_type"` ItemId int64 `gorm:"column:item_id" json:"item_id"` } type defaultAds7Model struct { tableName string fields string } func NewAds7Model() Ads7Model { return &defaultAds7Model{ tableName: "t_adm_ads7", fields: "id, style_id, item_id, start_mile, mile_cycle, start_date, date_cycle, created_at, updated_at", } } func (d *defaultAds7Model) List(db *gorm.DB) ([]Ads7Item, error) { var res []Ads7Item err := database.List(db, &res, database.Option{ TableName: d.tableName + " AS t1", Fields: "t1.id, style_id, t1.start_mile, mile_cycle, start_date, date_cycle, t2.item_name, t2.item_type, t1.item_id", Joins: []string{"LEFT JOIN t_adm_ads12 AS t2 ON t1.item_id = t2.item_id"}, OrderBy: "t1.item_id", }) return res, err } func (d *defaultAds7Model) Update(db *gorm.DB, values interface{}) error { return database.Update(db, values, database.Option{ TableName: d.tableName, }) } func (d *defaultAds7Model) Insert(db *gorm.DB, data []Ads7) error { return database.Create(db, data, database.Option{ TableName: d.tableName, }) } func (d *defaultAds7Model) Delete(db *gorm.DB) error { m := Ads7{} return db.Table(d.tableName).Delete(&m).Error }