sy_series.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. package model
  2. import (
  3. "git.getensh.com/common/gopkgsv2/database"
  4. "gorm.io/gorm"
  5. )
  6. type SySeriesModel interface {
  7. MakerList(db *gorm.DB) ([]Maker, error)
  8. Update(db *gorm.DB, values interface{}) error
  9. Count(db *gorm.DB, join bool) (int64, error)
  10. List(db *gorm.DB, pagination *Pagination, join bool) ([]SeriesAndBrandName, error)
  11. Get(db *gorm.DB) (*GdSySeries, error)
  12. SeriesList(db *gorm.DB) ([]GdSySeries, error)
  13. }
  14. type GdSySeries struct {
  15. ID int64 `gorm:"column:id" json:"id" form:"id"`
  16. SeriesId string `gorm:"column:series_id" json:"series_id" form:"series_id"`
  17. BrandId string `gorm:"column:brand_id" json:"brand_id" form:"brand_id"`
  18. SeriesName string `gorm:"column:series_name" json:"series_name" form:"series_name"`
  19. Maker string `gorm:"column:maker" json:"maker" form:"maker"`
  20. MakerId string `gorm:"column:maker_id" json:"maker_id" form:"maker_id"`
  21. LowestPrice string `gorm:"column:lowest_price" json:"lowest_price" form:"lowest_price"`
  22. HighestPrice string `gorm:"column:highest_price" json:"highest_price" form:"highest_price"`
  23. HasImg int64 `gorm:"column:has_img" json:"has_img" form:"has_img"`
  24. UpdateTime string `gorm:"column:update_time" json:"update_time" form:"update_time"`
  25. Status int64 `gorm:"column:status" json:"status"`
  26. }
  27. type SeriesAndBrandName struct {
  28. ID int64 `gorm:"column:id" json:"id" form:"id"`
  29. SeriesId string `gorm:"column:series_id" json:"series_id" form:"series_id"`
  30. SeriesName string `gorm:"column:series_name" json:"series_name" form:"series_name"`
  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. Maker string `gorm:"column:maker" json:"maker" form:"maker"`
  34. HasImg int64 `gorm:"column:has_img" json:"has_img" form:"has_img"`
  35. Status int64 `gorm:"column:status" json:"status"`
  36. OldSeriesName string `gorm:"column:old_series_name" json:"old_series_name" form:"old_series_name"`
  37. }
  38. type Maker struct {
  39. BrandId string `gorm:"column:brand_id" json:"brand_id" form:"brand_id"`
  40. Maker string `gorm:"column:maker" json:"maker" form:"maker"`
  41. MakerId string `gorm:"column:maker_id" json:"maker_id" form:"maker_id"`
  42. }
  43. type defalutSySerieModel struct {
  44. tableName string
  45. fields string
  46. }
  47. func NewSySerieModel() SySeriesModel {
  48. return &defalutSySerieModel{
  49. tableName: "db_adm_dws.t_adm_dws21",
  50. fields: "id, series_id,series_name, brand_id, maker, maker_id, lowest_price, highest_price, has_img,old_series_name, update_time",
  51. }
  52. }
  53. func (d *defalutSySerieModel) MakerList(db *gorm.DB) ([]Maker, error) {
  54. var res []Maker
  55. err := database.List(db, &res, database.Option{
  56. TableName: d.tableName,
  57. Fields: "brand_id, maker, maker_id",
  58. Group: "maker",
  59. })
  60. return res, err
  61. }
  62. func (d *defalutSySerieModel) Update(db *gorm.DB, values interface{}) error {
  63. return database.Update(db, values, database.Option{
  64. TableName: d.tableName,
  65. })
  66. }
  67. func (d *defalutSySerieModel) List(db *gorm.DB, pagination *Pagination, join bool) ([]SeriesAndBrandName, error) {
  68. var res []SeriesAndBrandName
  69. option := database.Option{
  70. TableName: d.tableName + " AS t1",
  71. Joins: []string{"LEFT JOIN db_adm_dws.t_adm_dws20 AS t2 ON t1.brand_id = t2.brand_id"},
  72. Fields: "t1.id, t1.series_id, t1.series_name, t1.maker, t1.status, t1.has_img,t1.old_series_name, t2.brand_name, t1.brand_id",
  73. Limit: pagination.Limit,
  74. OffSet: pagination.Offset,
  75. }
  76. if join {
  77. option.Joins = []string{}
  78. }
  79. err := database.List(db, &res, option)
  80. return res, err
  81. }
  82. func (d *defalutSySerieModel) Count(db *gorm.DB, join bool) (int64, error) {
  83. option := database.Option{
  84. TableName: d.tableName + " AS t1",
  85. }
  86. if join {
  87. option.Joins = []string{"LEFT JOIN db_adm_dws.t_adm_dws20 AS t2 ON t1.brand_id = t2.brand_id"}
  88. }
  89. return database.Count(db, option)
  90. }
  91. func (d *defalutSySerieModel) Get(db *gorm.DB) (*GdSySeries, error) {
  92. var res GdSySeries
  93. err := database.Get(db, &res, database.Option{
  94. TableName: d.tableName,
  95. Fields: d.fields,
  96. })
  97. return &res, err
  98. }
  99. func (d *defalutSySerieModel) SeriesList(db *gorm.DB) ([]GdSySeries, error) {
  100. var res []GdSySeries
  101. err := database.List(db, &res, database.Option{
  102. TableName: d.tableName,
  103. Fields: d.fields,
  104. })
  105. return res, err
  106. }