package model import ( "time" "git.getensh.com/common/gopkgsv2/database" "gorm.io/gorm" ) type ExportStyleTaskModel interface { Insert(db *gorm.DB, data interface{}) error Update(db *gorm.DB, values interface{}) error List(db *gorm.DB) ([]ExportStyleTask, error) Delete(db *gorm.DB) error Get(db *gorm.DB) (*ExportStyleTask, error) } type ExportStyleTask struct { ID int64 `gorm:"column:id" json:"id"` ExportId string `gorm:"column:export_id" json:"export_id" form:"export_id"` TaskName string `gorm:"column:task_name" json:"task_name"` Path string `gorm:"column:path" json:"path"` Status int8 `gorm:"column:status" json:"status"` CreatedAt time.Time `gorm:"column:created_at" json:"created_at"` } type defaultExportStyleTaskModel struct { tableName string fields string } func NewExportStyleTaskModel() ExportStyleTaskModel { return &defaultExportStyleTaskModel{ tableName: "db_adm_management.t_export_style_task", fields: "id, export_id, task_name, path, status, created_at", } } func (d *defaultExportStyleTaskModel) Insert(db *gorm.DB, data interface{}) error { return database.Create(db, data, database.Option{ TableName: d.tableName, }) } func (d *defaultExportStyleTaskModel) Update(db *gorm.DB, values interface{}) error { return database.Update(db, values, database.Option{ TableName: d.tableName, }) } func (d *defaultExportStyleTaskModel) List(db *gorm.DB) ([]ExportStyleTask, error) { var res []ExportStyleTask err := database.List(db, &res, database.Option{ TableName: d.tableName, Fields: d.fields, OrderBy: "id DESC", }) return res, err } func (d *defaultExportStyleTaskModel) Delete(db *gorm.DB) error { m := ExportStyleTask{} return db.Table(d.tableName).Delete(&m).Error } func (d *defaultExportStyleTaskModel) Get(db *gorm.DB) (*ExportStyleTask, error) { var res ExportStyleTask err := database.Get(db, &res, database.Option{ TableName: d.tableName, Fields: d.fields, }) return &res, err }