package model import ( "time" "git.getensh.com/common/gopkgsv2/database" "gorm.io/gorm" ) type MaintainDetailModel interface { MaintainDetailList(db *gorm.DB) ([]MaintainDetailItem, error) List(db *gorm.DB) ([]GdMaintainDetail, error) Update(db *gorm.DB, values interface{}) error Insert(db *gorm.DB, data interface{}) error Delete(db *gorm.DB) error Get(db *gorm.DB) (*GdMaintainDetail, error) } type GdMaintainDetail 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 MaintainDetailItem 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 defaultGdMaintain struct { tableName string fields string } func NewMaintainDetailModel() MaintainDetailModel { return &defaultGdMaintain{ tableName: "db_adm_dws.t_adm_ads7", fields: "id, style_id, item_id, start_mile, mile_cycle, start_date, date_cycle, created_at, updated_at", } } func (d *defaultGdMaintain) MaintainDetailList(db *gorm.DB) ([]MaintainDetailItem, error) { var res []MaintainDetailItem 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 db_adm_dws.t_adm_ads12 AS t2 ON t1.item_id = t2.item_id"}, }) return res, err } func (d *defaultGdMaintain) List(db *gorm.DB) ([]GdMaintainDetail, error) { var res []GdMaintainDetail err := database.List(db, &res, database.Option{ TableName: d.tableName, Fields: d.fields, }) return res, err } func (d *defaultGdMaintain) Update(db *gorm.DB, values interface{}) error { return database.Update(db, values, database.Option{ TableName: d.tableName, }) } func (d *defaultGdMaintain) Insert(db *gorm.DB, data interface{}) error { return database.Create(db, data, database.Option{ TableName: d.tableName, }) } func (d *defaultGdMaintain) Delete(db *gorm.DB) error { m := GdMaintainDetail{} return db.Table(d.tableName).Delete(&m).Error } func (d *defaultGdMaintain) Get(db *gorm.DB) (*GdMaintainDetail, error) { var res GdMaintainDetail err := database.Get(db, &res, database.Option{ TableName: d.tableName, Fields: d.fields, }) return &res, err }