maintain_detail_template.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package model
  2. import (
  3. "time"
  4. "git.getensh.com/common/gopkgsv2/database"
  5. "gorm.io/gorm"
  6. )
  7. type MaintainDetailTemplateModel interface {
  8. Insert(db *gorm.DB, data interface{}) error
  9. List(db *gorm.DB) ([]MaintenanceDetailTemplate, error)
  10. ListByItem(db *gorm.DB) ([]MaintenanceDetailTemplateItem, error)
  11. Get(db *gorm.DB) (*MaintenanceDetailTemplate, error)
  12. Update(db *gorm.DB, values interface{}) error
  13. }
  14. type MaintenanceDetailTemplate struct {
  15. ID int64 `gorm:"column:id" json:"id"`
  16. Tid int64 `gorm:"column:tid" json:"tid"`
  17. ItemId int64 `gorm:"column:item_id" json:"item_id"`
  18. StartMile int64 `gorm:"column:start_mile" json:"start_mile"`
  19. MileCycle int64 `gorm:"column:mile_cycle" json:"mile_cycle"`
  20. StartDate int64 `gorm:"column:start_date" json:"start_date"`
  21. DateCycle int64 `gorm:"column:date_cycle" json:"date_cycle"`
  22. CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
  23. UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"`
  24. }
  25. type MaintenanceDetailTemplateItem struct {
  26. ID int64 `gorm:"column:id" json:"id"`
  27. StyleId string `gorm:"column:style_id" json:"style_id"`
  28. StartMile int64 `gorm:"column:start_mile" json:"start_mile"`
  29. MileCycle int64 `gorm:"column:mile_cycle" json:"mile_cycle"`
  30. StartDate int64 `gorm:"column:start_date" json:"start_date"`
  31. DateCycle int64 `gorm:"column:date_cycle" json:"date_cycle"`
  32. ItemName string `gorm:"column:item_name" json:"item_name"`
  33. ItemType int8 `gorm:"column:item_type" json:"item_type"`
  34. ItemId int64 `gorm:"column:item_id" json:"item_id"`
  35. }
  36. type defaultMaintainDetailTemplateModel struct {
  37. tableName string
  38. fields string
  39. }
  40. func NewMaintainDetailTemplateModel() MaintainDetailTemplateModel {
  41. return &defaultMaintainDetailTemplateModel{
  42. "db_adm_management.t_adm_maintenance_detail_template",
  43. "id, tid, item_id, start_mile, mile_cycle, start_date, date_cycle, created_at, updated_at",
  44. }
  45. }
  46. func (d *defaultMaintainDetailTemplateModel) Insert(db *gorm.DB, data interface{}) error {
  47. return database.Create(db, data, database.Option{
  48. TableName: d.tableName,
  49. })
  50. }
  51. func (d *defaultMaintainDetailTemplateModel) List(db *gorm.DB) ([]MaintenanceDetailTemplate, error) {
  52. var res []MaintenanceDetailTemplate
  53. err := database.List(db, &res, database.Option{
  54. TableName: d.tableName,
  55. Fields: d.fields,
  56. })
  57. return res, err
  58. }
  59. func (d *defaultMaintainDetailTemplateModel) ListByItem(db *gorm.DB) ([]MaintenanceDetailTemplateItem, error) {
  60. var res []MaintenanceDetailTemplateItem
  61. err := database.List(db, &res, database.Option{
  62. TableName: d.tableName + " AS t1",
  63. Fields: "t1.id, t1.start_mile, mile_cycle, start_date, date_cycle, t2.item_name, t2.item_type, t1.item_id",
  64. Joins: []string{"LEFT JOIN db_adm_dws.t_adm_ads12 AS t2 ON t1.item_id = t2.item_id"},
  65. OrderBy: "t1.item_id",
  66. })
  67. return res, err
  68. }
  69. func (d *defaultMaintainDetailTemplateModel) Get(db *gorm.DB) (*MaintenanceDetailTemplate, error) {
  70. var res MaintenanceDetailTemplate
  71. err := database.Get(db, &res, database.Option{
  72. TableName: d.tableName,
  73. Fields: d.fields,
  74. })
  75. return &res, err
  76. }
  77. func (d *defaultMaintainDetailTemplateModel) Update(db *gorm.DB, values interface{}) error {
  78. return database.Update(db, values, database.Option{
  79. TableName: d.tableName,
  80. })
  81. }