ads7.go 2.6 KB

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