package model import ( "time" "git.getensh.com/common/gopkgsv2/database" "gorm.io/gorm" ) type Ads14Model interface { List(db *gorm.DB) ([]StyleItem, error) Update(db *gorm.DB, values interface{}) error Insert(db *gorm.DB, datab []Ads14) error Delete(db *gorm.DB) error } type Ads14 struct { ID int64 `gorm:"column:id" json:"id"` StyleId string `gorm:"column:style_id" json:"style_id"` C2Id int64 `gorm:"column:c2_id" json:"c2_id"` AttributeRule string `gorm:"column:attribute_rule" json:"attribute_rule"` Useage string `gorm:"column:useage" json:"useage"` Detail string `gorm:"column:detail" json:"detail"` CreatedAt time.Time `gorm:"column:created_at" json:"created_at"` UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"` } type StyleItem struct { ID int64 `gorm:"column:id" json:"id"` StyleId string `gorm:"column:style_id" json:"style_id"` C2Id int64 `gorm:"column:c2_id" json:"c2_id"` C2Name string `gorm:"column:c2_name" json:"c2_name"` AttributeRule string `gorm:"column:attribute_rule" json:"attribute_rule"` Useage string `gorm:"column:useage" json:"useage"` Detail string `gorm:"column:detail" json:"detail"` } type defaultAds14Model struct { tableName string fields string } func NewAds14Model() Ads14Model { return &defaultAds14Model{ tableName: "db_adm_ads.t_adm_ads14", fields: "id, style_id, c2_id, attribute_rule, useage, detail, created_at, updated_at", } } func (d *defaultAds14Model) List(db *gorm.DB) ([]StyleItem, error) { var res []StyleItem err := database.List(db, &res, database.Option{ TableName: d.tableName + " AS t1", Fields: "t1.id, style_id, c2_id, useage, attribute_rule, detail, t2.name AS c2_name", Joins: []string{"LEFT JOIN db_adm_ads.t_adm_ads6 AS t2 ON t1.c2_id = t2.id"}, }) return res, err } func (d *defaultAds14Model) Update(db *gorm.DB, values interface{}) error { return database.Update(db, values, database.Option{ TableName: d.tableName, }) } func (d *defaultAds14Model) Insert(db *gorm.DB, data []Ads14) error { return database.Create(db, data, database.Option{ TableName: d.tableName, }) } func (d *defaultAds14Model) Delete(db *gorm.DB) error { m := Ads14{} return db.Table(d.tableName).Delete(&m).Error }