dws20.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package model
  2. import (
  3. "git.getensh.com/common/gopkgsv2/database"
  4. "gorm.io/gorm"
  5. )
  6. type Dws20Model interface {
  7. Get(db *gorm.DB) (*AdmDws20, error)
  8. List(db *gorm.DB, pagination *Pagination) ([]AdmDws20, error)
  9. Count(db *gorm.DB) (int64, error)
  10. Update(db *gorm.DB, values interface{}) error
  11. }
  12. type AdmDws20 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 int `gorm:"column:weight" json:"weight" form:"weight"`
  18. HasImg int `gorm:"column:has_img" json:"has_img" form:"has_img"`
  19. OldBrandName string `gorm:"column:old_brand_name" json:"old_brand_name" form:"old_brand_name"`
  20. Status int `gorm:"column:status" json:"status" form:"status"`
  21. UpdateTime string `gorm:"column:update_time" json:"update_time" form:"update_time"`
  22. }
  23. type defaultDws20 struct {
  24. tableName string
  25. fields string
  26. }
  27. func NewDws20Model() Dws20Model {
  28. return &defaultDws20{
  29. tableName: "t_adm_dws20",
  30. fields: "id, initial, brand_name, brand_id, weight, has_img, old_brand_name, status, update_time",
  31. }
  32. }
  33. func (d *defaultDws20) Get(db *gorm.DB) (*AdmDws20, error) {
  34. var res AdmDws20
  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 *defaultDws20) List(db *gorm.DB, pagination *Pagination) ([]AdmDws20, error) {
  42. var res []AdmDws20
  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 *defaultDws20) Count(db *gorm.DB) (int64, error) {
  52. return database.Count(db, database.Option{
  53. TableName: d.tableName,
  54. })
  55. }
  56. func (d *defaultDws20) Update(db *gorm.DB, values interface{}) error {
  57. return database.Update(db, values, database.Option{
  58. TableName: d.tableName,
  59. })
  60. }