maintain_detail.go 3.2 KB

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