package model import ( "git.getensh.com/common/gopkgsv2/database" "gorm.io/gorm" ) type StyleItemModel interface { List(db *gorm.DB) ([]StyleItem, error) Update(db *gorm.DB, values interface{}) error Insert(db *gorm.DB, datab []GdStyleItem) error Delete(db *gorm.DB) error } type GdStyleItem 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 int64 `gorm:"column:created_at" json:"created_at"` UpdatedAt int64 `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 defaultStyleItemModel struct { tableName string fields string } func NewStyleItemModel() StyleItemModel { return &defaultStyleItemModel{ tableName: "db_adm_dws.t_adm_ads14", fields: "id, style_id, c2_id, attribute_rule, useage, detail, created_at, updated_at", } } func (d *defaultStyleItemModel) 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_dws.t_adm_ads6 AS t2 ON t1.c2_id = t2.id"}, }) return res, err } func (d *defaultStyleItemModel) Update(db *gorm.DB, values interface{}) error { return database.Update(db, values, database.Option{ TableName: d.tableName, }) } func (d *defaultStyleItemModel) Insert(db *gorm.DB, data []GdStyleItem) error { return database.Create(db, data, database.Option{ TableName: d.tableName, }) } func (d *defaultStyleItemModel) Delete(db *gorm.DB) error { m := GdStyleItem{} return db.Table(d.tableName).Delete(&m).Error }