resource.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. package model
  2. import (
  3. "encoding/json"
  4. "net/url"
  5. "strconv"
  6. "strings"
  7. xtime "go-common/library/time"
  8. )
  9. // Resource .
  10. type Resource struct {
  11. ID int64 `json:"id" gorm:"primary_key" form:"id"`
  12. BusinessID int64 `json:"business_id" gorm:"column:business_id" form:"business_id"`
  13. OID string `json:"oid" gorm:"column:oid" form:"oid"`
  14. MID int64 `json:"mid" gorm:"column:mid" form:"mid"`
  15. Content string `json:"content" gorm:"column:content" form:"content"`
  16. Extra1 int64 `json:"extra1" gorm:"column:extra1" form:"extra1"`
  17. Extra2 int64 `json:"extra2" gorm:"column:extra2" form:"extra2"`
  18. Extra3 int64 `json:"extra3" gorm:"column:extra3" form:"extra3"`
  19. Extra4 int64 `json:"extra4" gorm:"column:extra4" form:"extra4"`
  20. Extra1s string `json:"extra1s" gorm:"column:extra1s" form:"extra1s"`
  21. Extra2s string `json:"extra2s" gorm:"column:extra2s" form:"extra2s"`
  22. MetaData string `json:"metadata" gorm:"column:metadata" form:"metadata"`
  23. Ctime xtime.Time `json:"ctime" gorm:"column:ctime"`
  24. Mtime xtime.Time `json:"mtime" gorm:"column:mtime"`
  25. Extra5 int64 `json:"extra5" gorm:"column:extra5" form:"extra5"`
  26. Extra6 int64 `json:"extra6" gorm:"column:extra6" form:"extra6"`
  27. Extra3s string `json:"extra3s" gorm:"column:extra3s" form:"extra3s"`
  28. Extra4s string `json:"extra4s" gorm:"column:extra4s" form:"extra4s"`
  29. ExtraTime1 string `json:"extratime1" gorm:"column:extratime1" form:"extratime1"`
  30. OCtime string `json:"octime" gorm:"column:octime" form:"octime"`
  31. Ptime string `json:"ptime" gorm:"column:ptime" form:"ptime"`
  32. }
  33. // TableName .
  34. func (t *Resource) TableName() string {
  35. return "resource"
  36. }
  37. //AddOption add option
  38. type AddOption struct {
  39. Resource
  40. State int `form:"state" json:"state"`
  41. NetID int64 `form:"net_id" json:"net_id"`
  42. }
  43. // ToQueryURI convert field to uri.
  44. func (opt AddOption) ToQueryURI() url.Values {
  45. var params = url.Values{}
  46. params.Add("business_id", strconv.Itoa(int(opt.BusinessID)))
  47. params.Add("net_id", strconv.Itoa(int(opt.NetID)))
  48. params.Add("oid", opt.OID)
  49. params.Add("mid", strconv.Itoa(int(opt.MID)))
  50. params.Add("content", opt.Content)
  51. params.Add("extra1", strconv.Itoa(int(opt.Extra1)))
  52. params.Add("extra2", strconv.Itoa(int(opt.Extra2)))
  53. params.Add("extra3", strconv.Itoa(int(opt.Extra3)))
  54. params.Add("extra4", strconv.Itoa(int(opt.Extra4)))
  55. params.Add("extra5", strconv.Itoa(int(opt.Extra5)))
  56. params.Add("extra5", strconv.Itoa(int(opt.Extra6)))
  57. params.Add("extra1s", opt.Extra1s)
  58. params.Add("extra2s", opt.Extra2s)
  59. params.Add("extra3s", opt.Extra3s)
  60. params.Add("extra4s", opt.Extra4s)
  61. params.Add("extratime1", opt.ExtraTime1)
  62. params.Add("octime", opt.OCtime)
  63. params.Add("ptime", opt.Ptime)
  64. params.Add("metadata", opt.MetaData)
  65. return params
  66. }
  67. //UpdateOption update option
  68. type UpdateOption struct {
  69. BusinessID int64 `json:"business_id"`
  70. NetID int64 `json:"net_id"`
  71. OID string `json:"oid"`
  72. Update map[string]interface{} `json:"update"`
  73. }
  74. //ToQueryURI convert field to uri.
  75. func (opt UpdateOption) ToQueryURI() url.Values {
  76. var params = url.Values{}
  77. params.Add("business_id", strconv.Itoa(int(opt.BusinessID)))
  78. params.Add("net_id", strconv.Itoa(int(opt.NetID)))
  79. params.Add("oid", opt.OID)
  80. if bs, err := json.Marshal(opt.Update); err == nil && len(bs) > 0 {
  81. params.Add("update", string(bs))
  82. }
  83. return params
  84. }
  85. //CancelOption .
  86. type CancelOption struct {
  87. BusinessID int64 `json:"business_id"`
  88. Oids []string `json:"oids"`
  89. Reason string `json:"reason"`
  90. }
  91. // ToQueryURI convert field to uri.
  92. func (opt CancelOption) ToQueryURI() url.Values {
  93. var params = url.Values{}
  94. params.Add("business_id", strconv.Itoa(int(opt.BusinessID)))
  95. params.Add("oids", strings.Join(opt.Oids, ","))
  96. params.Add("reason", opt.Reason)
  97. return params
  98. }