maintain_item.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package model
  2. import (
  3. "git.getensh.com/common/gopkgsv2/database"
  4. "gorm.io/gorm"
  5. )
  6. type MaintainItemModel interface {
  7. Get(db *gorm.DB) (*GdMaintainItem, error)
  8. List(db *gorm.DB, fields string) ([]GdMaintainItem, error)
  9. }
  10. type GdMaintainItem struct {
  11. ID int64 `gorm:"column:id" json:"id"`
  12. ItemId int64 `gorm:"column:item_id" json:"item_id"`
  13. ItemName string `gorm:"column:item_name" json:"item_name"`
  14. ItemType int64 `gorm:"column:item_type" json:"item_type"`
  15. }
  16. type defaultMaintainItem struct {
  17. tableName string
  18. fields string
  19. }
  20. func NewMaintainItemModel() MaintainItemModel {
  21. return &defaultMaintainItem{
  22. tableName: "db_adm_dws.t_adm_ads12",
  23. fields: "id, item_id, item_name, item_type",
  24. }
  25. }
  26. func (d *defaultMaintainItem) Get (db *gorm.DB) (*GdMaintainItem, error) {
  27. var res GdMaintainItem
  28. err := database.Get(db, &res, database.Option{
  29. TableName: d.tableName,
  30. Fields: d.fields,
  31. })
  32. return &res, err
  33. }
  34. func (d *defaultMaintainItem) List (db *gorm.DB, fields string) ([]GdMaintainItem, error) {
  35. if fields == "" {
  36. fields = d.fields
  37. }
  38. var res []GdMaintainItem
  39. err := database.List(db, &res, database.Option{
  40. TableName: d.tableName,
  41. Fields: fields,
  42. })
  43. return res, err
  44. }