row.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. package budget
  2. import (
  3. "zhiyuan/pkg/db"
  4. "zhiyuan/pkg/utils"
  5. "github.com/gin-gonic/gin"
  6. )
  7. type Row struct {
  8. ID int64 `json:"id" prop:"add:false"`
  9. QuoteId int64 `json:"quoteId" type:"int" prop:"add" search:"="`
  10. TableId int64 `json:"tableId" type:"int" prop:"add" search:"="`
  11. ModuleId int64 `json:"moduleId" type:"int" prop:"add" search:"="`
  12. GroupId int64 `json:"groupId" type:"int" prop:"add" search:"="`
  13. ItemId int64 `json:"itemId" type:"int" prop:"edit" search:"="`
  14. Name string `json:"name" label:"名称值" type:"string" prop:"edit" search:"like"`
  15. Property string `json:"property" label:"属性" type:"string" prop:"edit"`
  16. OrderAt int64 `json:"order_at" prop:"add:false select:false"`
  17. DeletedAt int64 `json:"deleted_at" prop:"add:false select:false"`
  18. CreatedAt int64 `json:"created_at" prop:"add:false select:false"`
  19. UpdatedAt int64 `json:"updated_at" prop:"add:false select:false"`
  20. Item *Item `json:"item" prop:"ignore"`
  21. Prop map[string]string `json:"prop" prop:"ignore"`
  22. db.BaseModel
  23. }
  24. func (Row) TableName() string {
  25. return "zy_budget_row"
  26. }
  27. func (Row) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  28. return true
  29. }
  30. func (Row) OnePrivilege(c *gin.Context, id int64) bool {
  31. return true
  32. }
  33. func (Row) AddPrivilege(c *gin.Context, data map[string]interface{}, post map[string]interface{}) error {
  34. return nil
  35. }
  36. func (Row) EditPrivilege(c *gin.Context, id int64, data map[string]interface{}, post map[string]interface{}) error {
  37. return nil
  38. }
  39. func (Row) DelPrivilege(c *gin.Context, id int64) error {
  40. return nil
  41. }
  42. func (Row) OrderField() string {
  43. return "order_at"
  44. }
  45. func (Row) Page() bool {
  46. return false
  47. }
  48. func (Row) Count() bool {
  49. return false
  50. }
  51. func (model Row) GetProperty() map[string]string {
  52. props := make(map[string]string)
  53. utils.JsonDecode(model.Property).To(&props)
  54. return props
  55. }
  56. func (model Row) GetID() int64 {
  57. return model.ID
  58. }
  59. func (model Row) GetProp(name string) (expression string, ok bool) {
  60. expression, ok = model.Prop[name]
  61. return
  62. }
  63. func (model Row) GetSubs() *[]QuoteData {
  64. return nil
  65. }
  66. func (model Row) GetName() string {
  67. return model.Name
  68. }
  69. func (model Row) GetHeaders() *[]QuoteData {
  70. return nil
  71. }
  72. func (model Row) GetItem() *Item {
  73. return model.Item
  74. }
  75. func (model Row) GetValue() string {
  76. return ""
  77. }
  78. func (model Row) GetQuote() *Quote {
  79. return nil
  80. }
  81. func (model Row) GetTable() *Table {
  82. return nil
  83. }
  84. func (model Row) GetHeader() *Header {
  85. return nil
  86. }
  87. func (model Row) GetModule() *Module {
  88. return nil
  89. }
  90. func (model Row) GetGroup() *Group {
  91. return nil
  92. }
  93. func (model Row) GetRow() *Row {
  94. return &model
  95. }
  96. func (model Row) GetMyItem() *Item {
  97. return nil
  98. }
  99. func CopyRows(datas []QuoteData, quoteId int64, tableId int64, moduleId int64, groupId int64, order int64) error {
  100. for i, data := range datas {
  101. _, err := data.GetRow().Copy(quoteId, tableId, moduleId, groupId, order+int64(len(datas)-i))
  102. if err != nil {
  103. return err
  104. }
  105. }
  106. return nil
  107. }
  108. func findRows(groupId int64, list []Row, items []Item) []QuoteData {
  109. rows := make([]QuoteData, 0)
  110. for _, v := range list {
  111. if v.GroupId == groupId {
  112. for _, item := range items {
  113. if item.ID == v.ItemId {
  114. v.Item = &item
  115. break
  116. }
  117. }
  118. v.Prop = v.GetProperty()
  119. rows = append(rows, v)
  120. }
  121. }
  122. return rows
  123. }
  124. func (model Row) Copy(quoteId int64, tableId int64, moduleId int64, groupId int64, order int64) (int64, error) {
  125. id, err := db.InsertModel(db.Type(model), map[string]interface{}{
  126. "quoteId": quoteId,
  127. "tableId": tableId,
  128. "moduleId": moduleId,
  129. "groupId": groupId,
  130. "itemId": model.ItemId,
  131. "name": model.Name,
  132. "property": model.Property,
  133. "order_at": order,
  134. })
  135. if err != nil {
  136. return 0, err
  137. }
  138. return id, nil
  139. }