fieldList.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package model
  2. import (
  3. "git.getensh.com/common/gopkgsv2/database"
  4. "gorm.io/gorm"
  5. )
  6. type FieldListModel interface {
  7. List(db *gorm.DB, pagination *Pagination) ([]AdmFieldList, error)
  8. Count(db *gorm.DB) (int64, error)
  9. Update(db *gorm.DB, values interface{}) error
  10. Get(db *gorm.DB) (*AdmFieldList, error)
  11. }
  12. type AdmFieldList struct {
  13. Id int64 `gorm:"column:id" json:"id" form:"id"`
  14. Field string `gorm:"column:field" json:"field" form:"field"`
  15. Desc string `gorm:"column:desc" json:"desc" form:"desc"`
  16. }
  17. type defaultFieldList struct {
  18. tableName string
  19. fields string
  20. }
  21. func NewFieldList() FieldListModel {
  22. return &defaultFieldList{
  23. tableName: "t_adm_field_management",
  24. fields: "`id`, `field`, `desc`",
  25. }
  26. }
  27. func (d *defaultFieldList) List(db *gorm.DB, pagination *Pagination) ([]AdmFieldList, error) {
  28. var res []AdmFieldList
  29. err := database.List(db, &res, database.Option{
  30. TableName: d.tableName,
  31. Fields: d.fields,
  32. Limit: pagination.Limit,
  33. OffSet: pagination.Offset,
  34. })
  35. return res, err
  36. }
  37. func (d *defaultFieldList) Count(db *gorm.DB) (int64, error) {
  38. return database.Count(db, database.Option{
  39. TableName: d.tableName,
  40. })
  41. }
  42. func (d *defaultFieldList) Update(db *gorm.DB, values interface{}) error {
  43. return database.Update(db, values, database.Option{
  44. TableName: d.tableName,
  45. })
  46. }
  47. func (d *defaultFieldList) Get(db *gorm.DB) (*AdmFieldList, error) {
  48. var res AdmFieldList
  49. err := database.Get(db, &res, database.Option{
  50. TableName: d.tableName,
  51. Fields: d.fields,
  52. })
  53. return &res, err
  54. }