ads11.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package model
  2. import (
  3. "git.getensh.com/common/gopkgsv2/database"
  4. "gorm.io/gorm"
  5. )
  6. type Ads11Model interface {
  7. Get(db *gorm.DB) (*Ads11, error)
  8. List(db *gorm.DB) ([]P07Table, error)
  9. List1(db *gorm.DB) ([]Ads11, error)
  10. Count(db *gorm.DB) (int64, error)
  11. Update(db *gorm.DB, values interface{}) error
  12. Insert(db *gorm.DB, datab []Ads11) error
  13. }
  14. type Ads11 struct {
  15. ID int64 `gorm:"column:id" json:"id"`
  16. Source string `gorm:"column:source" json:"source"`
  17. ThirdBrandId string `gorm:"column:third_brand_id" json:"third_brand_id"`
  18. ThirdBrandName string `gorm:"column:third_brand_name" json:"third_brand_name"`
  19. ThirdSeriesId string `gorm:"column:third_series_id" json:"third_series_id"`
  20. ThirdSeriesName string `gorm:"column:third_series_name" json:"third_series_name"`
  21. ThirdStyleId string `gorm:"column:third_style_id" json:"third_style_id"`
  22. ThirdStyleName string `gorm:"column:third_style_name" json:"third_style_name"`
  23. ThirdMaker string `gorm:"column:third_maker" json:"third_maker"`
  24. ModelYear string `gorm:"column:model_year" json:"model_year"`
  25. StyleId string `gorm:"column:style_id" json:"style_id"`
  26. CreatedAt int64 `gorm:"column:created_at" json:"created_at"`
  27. UpdatedAt int64 `gorm:"column:updated_at" json:"updated_at"`
  28. }
  29. type P07Table struct {
  30. Price string `gorm:"column:price" json:"price" form:"price"`
  31. BrandId string `gorm:"column:brand_id" json:"brand_id" form:"brand_id"`
  32. BrandName string `gorm:"column:brand_name" json:"brand_name" form:"brand_name"`
  33. ModelYear string `gorm:"column:model_year" json:"model_year" form:"model_year"`
  34. SeriesId string `gorm:"column:series_id" json:"series_id" form:"series_id"`
  35. MakerId string `gorm:"column:maker_id" json:"maker_id" form:"maker_id"`
  36. Maker string `gorm:"column:maker" json:"maker" form:"maker"`
  37. SeriesImg string `gorm:"column:series_img" json:"series_img" form:"series_img"`
  38. SeriesName string `gorm:"column:series_name" json:"series_name" form:"series_name"`
  39. StyleId string `gorm:"column:style_id" json:"style_id" form:"style_id"`
  40. StyleName string `gorm:"column:style_name" json:"style_name" form:"style_name"`
  41. }
  42. type defaultAds11Model struct {
  43. tableName string
  44. fields string
  45. }
  46. func NewAds11Model() Ads11Model {
  47. return &defaultAds11Model{
  48. tableName: "db_adm_ads.t_adm_ads11",
  49. fields: "id, source, third_brand_id, third_brand_name, third_series_id, third_series_name, third_style_id, third_style_name, third_maker, model_year, style_id, created_at, updated_at",
  50. }
  51. }
  52. func (d *defaultAds11Model) Get(db *gorm.DB) (*Ads11, error) {
  53. var res Ads11
  54. err := database.Get(db, &res, database.Option{
  55. TableName: d.tableName,
  56. Fields: d.fields,
  57. })
  58. return &res, err
  59. }
  60. func (d *defaultAds11Model) List1(db *gorm.DB) ([]Ads11, error) {
  61. var res []Ads11
  62. err := database.List(db, &res, database.Option{
  63. TableName: d.tableName,
  64. Fields: d.fields,
  65. })
  66. return res, err
  67. }
  68. func (d *defaultAds11Model) List(db *gorm.DB) ([]P07Table, error) {
  69. var res []P07Table
  70. err := database.List(db, &res, database.Option{
  71. TableName: d.tableName + " AS t1",
  72. Fields: "price,brand_id,brand_name,t1.model_year,series_id,maker_id,maker,series_name,t1.style_id,style_name",
  73. Joins: []string{"left join db_adm_ads.t_adm_ads5 as t2 on t1.style_id = t2.style_id"},
  74. })
  75. return res, err
  76. }
  77. func (d *defaultAds11Model) Count(db *gorm.DB) (int64, error) {
  78. return database.Count(db, database.Option{
  79. TableName: d.tableName,
  80. })
  81. }
  82. func (d *defaultAds11Model) Update(db *gorm.DB, values interface{}) error {
  83. return database.Update(db, values, database.Option{
  84. TableName: d.tableName,
  85. })
  86. }
  87. func (d *defaultAds11Model) Insert(db *gorm.DB, data []Ads11) error {
  88. return database.Create(db, data, database.Option{
  89. TableName: d.tableName,
  90. })
  91. }