resource.go 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. package resource
  2. import (
  3. "encoding/json"
  4. "go-common/library/log"
  5. xtime "go-common/library/time"
  6. )
  7. //Resource .
  8. type Resource struct {
  9. ID int64 `json:"id" gorm:"primary_key" form:"id"`
  10. BusinessID int64 `json:"business_id" gorm:"column:business_id" form:"business_id"`
  11. OID string `json:"oid" gorm:"column:oid" form:"oid"`
  12. MID int64 `json:"mid" gorm:"column:mid" form:"mid"`
  13. Content string `json:"content" gorm:"column:content" form:"content"`
  14. Extra1 int64 `json:"extra1" gorm:"column:extra1" form:"extra1"`
  15. Extra2 int64 `json:"extra2" gorm:"column:extra2" form:"extra2"`
  16. Extra3 int64 `json:"extra3" gorm:"column:extra3" form:"extra3"`
  17. Extra4 int64 `json:"extra4" gorm:"column:extra4" form:"extra4"`
  18. Extra1s string `json:"extra1s" gorm:"column:extra1s" form:"extra1s"`
  19. Extra2s string `json:"extra2s" gorm:"column:extra2s" form:"extra2s"`
  20. MetaData string `json:"metadata" gorm:"column:metadata" form:"metadata"`
  21. Ctime xtime.Time `json:"ctime" gorm:"column:ctime"`
  22. Mtime xtime.Time `json:"mtime" gorm:"column:mtime"`
  23. Extra5 int64 `json:"extra5" gorm:"column:extra5" form:"extra5"`
  24. Extra6 int64 `json:"extra6" gorm:"column:extra6" form:"extra6"`
  25. Extra3s string `json:"extra3s" gorm:"column:extra3s" form:"extra3s"`
  26. Extra4s string `json:"extra4s" gorm:"column:extra4s" form:"extra4s"`
  27. ExtraTime1 string `json:"extratime1" gorm:"column:extratime1" form:"extratime1"`
  28. OCtime string `json:"octime" gorm:"column:octime" form:"octime"`
  29. Ptime string `json:"ptime" gorm:"column:ptime" form:"ptime"`
  30. }
  31. // Result .
  32. type Result struct {
  33. ID int64 `json:"id" gorm:"primary_key" form:"id"`
  34. RID int64 `json:"rid" gorm:"column:rid" form:"rid"`
  35. Attribute int64 `json:"attribute" gorm:"column:attribute" form:"attribute" default:"-1"`
  36. Note string `json:"note" gorm:"column:note" form:"note" submit:"string"`
  37. RejectReason string `json:"reject_reason" gorm:"column:reject_reason" form:"reject_reason" submit:"string"`
  38. ReasonID int64 `json:"reason_id" gorm:"column:reason_id" form:"reason_id" default:"0" submit:"int"`
  39. State int `json:"state" gorm:"column:state" form:"state"`
  40. PubTime xtime.Time `json:"pubtime" gorm:"column:pubtime"`
  41. DelTime xtime.Time `json:"deltime" gorm:"column:deltime"`
  42. Ctime xtime.Time `json:"ctime" gorm:"column:ctime"`
  43. Mtime xtime.Time `json:"mtime" gorm:"column:mtime"`
  44. AttributeList map[string]int8 `json:"attribute_list" gorm:"-" submit:"map"`
  45. }
  46. // AttrParse 属性值解析为属性展开结果
  47. func (r *Result) AttrParse(cfg map[string]uint) {
  48. r.AttributeList = make(map[string]int8)
  49. for name, bit := range cfg {
  50. r.AttributeList[name] = int8((r.Attribute >> bit) & int64(1))
  51. }
  52. }
  53. // AttrSet 展开结果计算回属性值
  54. func (r *Result) AttrSet(cfg map[string]uint) {
  55. var attr int64
  56. for name, bit := range cfg {
  57. if val, ok := r.AttributeList[name]; ok {
  58. attr += int64(val) << bit
  59. }
  60. }
  61. r.Attribute = attr
  62. }
  63. // MetaData 资源扩展数据项目
  64. type MetaData struct {
  65. Name string `json:"name"`
  66. CNDesc string `json:"cndesc"` // 中文描述
  67. Value interface{} `json:"value"`
  68. }
  69. // Res .
  70. type Res struct {
  71. ID int64 `json:"id" gorm:"primary_key" form:"id"`
  72. BusinessID int64 `json:"business_id" gorm:"column:business_id" form:"business_id"`
  73. OID string `json:"oid" gorm:"column:oid" form:"oid"`
  74. MID int64 `json:"mid" gorm:"column:mid" form:"mid"`
  75. Content string `json:"content" gorm:"column:content" form:"content"`
  76. Extra1 int64 `json:"extra1" gorm:"column:extra1" form:"extra1"`
  77. Extra2 int64 `json:"extra2" gorm:"column:extra2" form:"extra2"`
  78. Extra3 int64 `json:"extra3" gorm:"column:extra3" form:"extra3"`
  79. Extra4 int64 `json:"extra4" gorm:"column:extra4" form:"extra4"`
  80. Extra1s string `json:"extra1s,omitempty" gorm:"column:extra1s" form:"extra1s"`
  81. Extra2s string `json:"extra2s,omitempty" gorm:"column:extra2s" form:"extra2s"`
  82. MetaData string `json:"metadata,omitempty" gorm:"column:metadata" form:"metadata"`
  83. Attribute int64 `json:"attribute" gorm:"column:attribute" form:"attribute"`
  84. Note string `json:"note,omitempty" gorm:"column:note" form:"note"`
  85. RejectReason string `json:"reject_reason,omitempty" gorm:"column:reject_reason" form:"reject_reason"`
  86. ReasonID int64 `json:"reason_id,omitempty" gorm:"column:reason_id" form:"reason_id"`
  87. State int64 `json:"state" gorm:"column:state" form:"state"`
  88. Pubtime xtime.Time `json:"pubtime,omitempty" gorm:"column:pubtime"`
  89. Deltime xtime.Time `json:"deltime,omitempty" gorm:"column:deltime"`
  90. Ctime string `json:"ctime"`
  91. Mtime xtime.Time `json:"mtime" gorm:"column:mtime"`
  92. AttributeList map[string]int8 `json:"attribute_list,omitempty"`
  93. Metas map[string]interface{} `json:"metas"`
  94. Extra5 int64 `json:"extra5"`
  95. Extra6 int64 `json:"extra6"`
  96. Extra3s string `json:"extra3s,omitempty"`
  97. Extra4s string `json:"extra4s,omitempty"`
  98. ExtraTime1 string `json:"extratime1,omitempty"`
  99. OCtime string `json:"octime,omitempty"`
  100. Ptime string `json:"ptime,omitempty"`
  101. }
  102. // AttrParse 属性值解析为属性展开结果
  103. func (r *Res) AttrParse(cfg map[string]uint) {
  104. r.AttributeList = make(map[string]int8)
  105. for name, bit := range cfg {
  106. r.AttributeList[name] = int8((r.Attribute >> bit) & int64(1))
  107. }
  108. }
  109. //MetaParse .
  110. func (r *Res) MetaParse() {
  111. if len(r.MetaData) > 0 {
  112. meta := make(map[string]interface{})
  113. if err := json.Unmarshal([]byte(r.MetaData), &meta); err != nil {
  114. log.Error("MetaParse error(%v)", err)
  115. }
  116. r.Metas = meta
  117. }
  118. }
  119. // Args .
  120. type Args struct {
  121. RID int64 `json:"id" form:"rid"`
  122. BusinessID int64 `json:"business_id" form:"business_id"`
  123. OID int64 `json:"oid" form:"oid"`
  124. Changes map[string]interface{} `json:"changes"`
  125. }
  126. // TableName .
  127. func (r *Resource) TableName() string {
  128. return "resource"
  129. }
  130. //TableName .
  131. func (r *Result) TableName() string {
  132. return "resource_result"
  133. }