sy_brand.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package model
  2. import (
  3. "git.getensh.com/common/gopkgsv2/database"
  4. "gorm.io/gorm"
  5. )
  6. type SyBrandModel interface {
  7. Get(db *gorm.DB) (*GdSyBrand, error)
  8. List(db *gorm.DB, pagination *Pagination) ([]GdSyBrand, error)
  9. Count(db *gorm.DB) (int64, error)
  10. Update(db *gorm.DB, values interface{}) error
  11. }
  12. type GdSyBrand struct {
  13. ID int64 `gorm:"column:id" json:"id" form:"id"`
  14. Initial string `gorm:"column:initial" json:"initial" form:"initial"`
  15. BrandName string `gorm:"column:brand_name" json:"brand_name" form:"brand_name"`
  16. BrandId string `gorm:"column:brand_id" json:"brand_id" form:"brand_id"`
  17. Weight int64 `gorm:"column:weight" json:"weight" form:"weight"`
  18. HasImg int64 `gorm:"column:has_img" json:"has_img" form:"has_img"`
  19. Status int64 `gorm:"column:status" json:"status" form:"status"`
  20. OldBrandName string `gorm:"old_brand_name" json:"old_brand_name" form:"old_brand_name"`
  21. UpdateTime string `gorm:"column:update_time" json:"update_time" form:"update_time"`
  22. }
  23. type defaultSyBrand struct {
  24. tableName string
  25. fields string
  26. }
  27. func NewSyBrand() SyBrandModel {
  28. return &defaultSyBrand{
  29. tableName: "db_adm_dws.t_adm_dws20",
  30. fields: "id, initial, brand_name, brand_id, weight, has_img, status,old_brand_name, update_time",
  31. }
  32. }
  33. func(d *defaultSyBrand) Get(db *gorm.DB) (*GdSyBrand, error) {
  34. var res GdSyBrand
  35. err := database.Get(db, &res, database.Option{
  36. TableName: d.tableName,
  37. Fields: d.fields,
  38. })
  39. return &res, err
  40. }
  41. func (d *defaultSyBrand) List(db *gorm.DB, pagination *Pagination) ([]GdSyBrand, error) {
  42. var res []GdSyBrand
  43. err := database.List(db, &res, database.Option{
  44. TableName: d.tableName,
  45. Fields: d.fields,
  46. Limit: pagination.Limit,
  47. OffSet: pagination.Offset,
  48. })
  49. return res, err
  50. }
  51. func (d *defaultSyBrand) Count(db *gorm.DB) (int64, error) {
  52. return database.Count(db, database.Option{
  53. TableName: d.tableName,
  54. })
  55. }
  56. func (d *defaultSyBrand) Update(db *gorm.DB, values interface{}) error {
  57. return database.Update(db, values, database.Option{
  58. TableName: d.tableName,
  59. })
  60. }