tree.go 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * @description: 视图层 文件夹 models
  3. * @Author: CP
  4. * @Date: 2020-09-11 15:12:43
  5. * @FilePath: \construction_management\web\viewmodels\tree.go
  6. */
  7. package viewmodels
  8. import (
  9. validation "github.com/go-ozzo/ozzo-validation/v3"
  10. )
  11. // Leaf 叶子节点为true 可以显示创建标段
  12. // IsBid为true 目录下已包含标段
  13. type Tree struct {
  14. Id string `form:"id" json:"id" `
  15. Name string `form:"name" json:"name"`
  16. ProjectId string `form:"projectId" json:"projectId"`
  17. BidsectionId string `form:"bidsectionId" json:"bidsectionId"`
  18. ParentId string `form:"parentId" json:"parentId"`
  19. Depth int `form:"depth" json:"depth"`
  20. Serial string `form:"serial" json:"serial"`
  21. Attribution string `form:"attribution" json:"attribution"`
  22. Isfolder int `form:"isfolder" json:"isfolder"`
  23. CreateTime string `form:"createTime" json:"createTime"`
  24. UpdateTime string `form:"updateTime" json:"updateTime"`
  25. TargetFolderId string `form:"targetFolderId" json:"targetFolderId"`
  26. Accounts int `form:"accounts" json:"accounts"`
  27. Csrf string `form:"csrf" json:"csrf"`
  28. // Leaf bool `json:"leaf" `
  29. HasFolder bool `json:"hasFolder" `
  30. IsBid bool `json:"isBid" `
  31. IsEnd bool `json:"isEnd"`
  32. ChildsTotal int `json:"childsTotal"`
  33. Children []*Tree `json:"children"`
  34. }
  35. func (l Tree) Validate() error {
  36. return validation.ValidateStruct(&l,
  37. validation.Field(&l.Id, validation.Required.Error("文件夹ID不能为空")),
  38. validation.Field(&l.Name, validation.Required.Error("文件夹名称不能为空"), validation.Length(1, 60).Error("最多 15 个字符")),
  39. )
  40. }
  41. // func (l Tree) Maketree(Data []*Tree, node *Tree) { //参数为父节点,添加父节点的子节点指针切片
  42. // childs, _ := this.Havechild(Data, node) //判断节点是否有子节点并返回
  43. // if childs != nil {
  44. // // fmt.Printf("\n")
  45. // // fmt.Println(*node)
  46. // // fmt.Println("子节点:")
  47. // for _, v := range childs {
  48. // fmt.Println(*v)
  49. // } //打印
  50. // node.Child = append(node.Child, childs[0:]...) //添加子节点
  51. // for _, v := range childs { //查询子节点的子节点,并添加到子节点
  52. // _, has := Havechild(Data, v)
  53. // if has {
  54. // Maketree(Data, v) //递归添加节点
  55. // }
  56. // }
  57. // }
  58. // }
  59. // func (l Tree) Havechild(Data []*Tree, node *Tree) (child []*Tree, yes bool) {
  60. // for _, v := range Data {
  61. // if v.ParentId == node.Id {
  62. // child = append(child, v)
  63. // }
  64. // }
  65. // if child != nil {
  66. // yes = true
  67. // }
  68. // return
  69. // }
  70. // func transformjson(Data *Tree) { //转为json
  71. // Jsondata, _ := json.Marshal(Data)
  72. // fmt.Println(string(Jsondata))
  73. // }