property.go 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package calc
  2. import (
  3. "zhiyuan/pkg/db"
  4. "github.com/gin-gonic/gin"
  5. )
  6. type Property struct {
  7. ID int64 `json:"id" prop:"add:false"`
  8. CalcId int64 `json:"calcId" type:"int" prop:"add" search:"="`
  9. ItemId int64 `json:"itemId" type:"int" prop:"add" search:"="`
  10. Name string `json:"name" label:"属性名称" type:"string" prop:"add edit" search:"like"`
  11. Type int64 `json:"type" label:"属性类型" type:"int" prop:"add edit" search:"="`
  12. DataType string `json:"data_type" label:"数据类型" type:"string" prop:"add edit" search:"="`
  13. Value string `json:"value" label:"属性值" type:"string" prop:"edit" search:"="`
  14. Unit string `json:"unit" label:"单位" type:"string" prop:"edit" search:"="`
  15. State int64 `json:"state" label:"状态" type:"int" prop:"edit" default:"0"`
  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. db.BaseModel
  21. }
  22. func (Property) TableName() string {
  23. return "zy_calc_property"
  24. }
  25. func (Property) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  26. return true
  27. }
  28. func (Property) OnePrivilege(c *gin.Context, id int64) bool {
  29. return true
  30. }
  31. func (Property) AddPrivilege(c *gin.Context, data map[string]interface{}, post map[string]interface{}) error {
  32. return nil
  33. }
  34. func (Property) EditPrivilege(c *gin.Context, id int64, data map[string]interface{}, post map[string]interface{}) error {
  35. return nil
  36. }
  37. func (Property) DelPrivilege(c *gin.Context, id int64) error {
  38. return nil
  39. }
  40. func (Property) OrderField() string {
  41. return "order_at"
  42. }
  43. func (Property) Page() bool {
  44. return true
  45. }
  46. func (Property) Count() bool {
  47. return true
  48. }
  49. func findProps(itemId int64, list []Property) []Property {
  50. props := make([]Property, 0)
  51. for _, v := range list {
  52. if v.ItemId == itemId {
  53. props = append(props, v)
  54. }
  55. }
  56. return props
  57. }
  58. func CopyPropertys(props []Property, calcId int64, itemId int64, order int64) error {
  59. for i, prop := range props {
  60. _, err := prop.Copy(prop.Name, calcId, itemId, order+int64(len(props)-i))
  61. if err != nil {
  62. return err
  63. }
  64. }
  65. return nil
  66. }
  67. func (model Property) Copy(name string, calcId int64, itemId int64, order int64) (int64, error) {
  68. id, err := db.InsertModel(db.Type(model), map[string]interface{}{
  69. "calcId": calcId,
  70. "itemId": itemId,
  71. "name": name,
  72. "type": model.Type,
  73. "data_type": model.DataType,
  74. "value": model.Value,
  75. "unit": model.Unit,
  76. "state": model.State,
  77. "order_at": order,
  78. })
  79. if err != nil {
  80. return 0, err
  81. }
  82. return id, nil
  83. }