123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- package model
- import (
- "time"
- "git.getensh.com/common/gopkgsv2/database"
- "gorm.io/gorm"
- )
- type MaintainDetailTemplateModel interface {
- Insert(db *gorm.DB, data interface{}) error
- List(db *gorm.DB) ([]MaintenanceDetailTemplate, error)
- ListByItem(db *gorm.DB) ([]MaintenanceDetailTemplateItem, error)
- Get(db *gorm.DB) (*MaintenanceDetailTemplate, error)
- Update(db *gorm.DB, values interface{}) error
- }
- type MaintenanceDetailTemplate struct {
- ID int64 `gorm:"column:id" json:"id"`
- Tid int64 `gorm:"column:tid" json:"tid"`
- 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 MaintenanceDetailTemplateItem 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 defaultMaintainDetailTemplateModel struct {
- tableName string
- fields string
- }
- func NewMaintainDetailTemplateModel() MaintainDetailTemplateModel {
- return &defaultMaintainDetailTemplateModel{
- "db_adm_management.t_adm_maintenance_detail_template",
- "id, tid, item_id, start_mile, mile_cycle, start_date, date_cycle, created_at, updated_at",
- }
- }
- func (d *defaultMaintainDetailTemplateModel) Insert(db *gorm.DB, data interface{}) error {
- return database.Create(db, data, database.Option{
- TableName: d.tableName,
- })
- }
- func (d *defaultMaintainDetailTemplateModel) List(db *gorm.DB) ([]MaintenanceDetailTemplate, error) {
- var res []MaintenanceDetailTemplate
- err := database.List(db, &res, database.Option{
- TableName: d.tableName,
- Fields: d.fields,
- })
- return res, err
- }
- func (d *defaultMaintainDetailTemplateModel) ListByItem(db *gorm.DB) ([]MaintenanceDetailTemplateItem, error) {
- var res []MaintenanceDetailTemplateItem
- err := database.List(db, &res, database.Option{
- TableName: d.tableName + " AS t1",
- Fields: "t1.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"},
- OrderBy: "t1.item_id",
- })
- return res, err
- }
- func (d *defaultMaintainDetailTemplateModel) Get(db *gorm.DB) (*MaintenanceDetailTemplate, error) {
- var res MaintenanceDetailTemplate
- err := database.Get(db, &res, database.Option{
- TableName: d.tableName,
- Fields: d.fields,
- })
- return &res, err
- }
- func (d *defaultMaintainDetailTemplateModel) Update(db *gorm.DB, values interface{}) error {
- return database.Update(db, values, database.Option{
- TableName: d.tableName,
- })
- }
|