wr.go 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package models
  2. // 仓单服务
  3. import (
  4. "mtp2_if/db"
  5. "time"
  6. )
  7. // Wrcategory 现货分类表
  8. type Wrcategory struct {
  9. Categoryid int32 `json:"categoryid" xorm:"'CATEGORYID'" binding:"required"` // 类别ID(SEQ_WRCATEGORY)
  10. Categoryname string `json:"categoryname" xorm:"'CATEGORYNAME'"` // 类别名称
  11. Parentcategoryid int32 `json:"parentcategoryid" xorm:"'PARENTCATEGORYID'"` // 父类别ID
  12. Categorydesc string `json:"categorydesc" xorm:"'CATEGORYDESC'"` // 类别描述
  13. Isvalid int32 `json:"isvalid" xorm:"'ISVALID'"` // 是否有效 - 0:无效 1:有效
  14. Iconurl string `json:"iconurl" xorm:"'ICONURL'"` // 图标地址
  15. Creatorid int64 `json:"creatorid" xorm:"'CREATORID'"` // 创建人
  16. Createtime time.Time `json:"createtime" xorm:"'CREATETIME'"` // 创建时间
  17. Updatorid int64 `json:"updatorid" xorm:"'UPDATORID'"` // 更新人
  18. Updatetime time.Time `json:"updatetime" xorm:"'UPDATETIME'"` // 更新时间
  19. Orderindex int32 `json:"orderindex" xorm:"'ORDERINDEX'"` // 顺序
  20. Areauserid int64 `json:"areauserid" xorm:"'AREAUSERID'"` // 所属机构
  21. }
  22. // TableName is WRCATEGORY
  23. func (Wrcategory) TableName() string {
  24. return "WRCATEGORY"
  25. }
  26. // WRCategoryTree 现货分类
  27. type WRCategoryTree struct {
  28. Categoryid int32 `json:"categoryid" xorm:"'CATEGORYID'" binding:"required"` // 类别ID(SEQ_WRCATEGORY)
  29. Categoryname string `json:"categoryname" xorm:"'CATEGORYNAME'"` // 类别名称
  30. Parentcategoryid int32 `json:"parentcategoryid" xorm:"'PARENTCATEGORYID'"` // 父类别ID
  31. Categorydesc string `json:"categorydesc" xorm:"'CATEGORYDESC'"` // 类别描述
  32. Iconurl string `json:"iconurl" xorm:"'ICONURL'"` // 图标地址
  33. Orderindex int32 `json:"orderindex" xorm:"'ORDERINDEX'"` // 顺序
  34. Areauserid int64 `json:"areauserid" xorm:"'AREAUSERID'"` // 所属机构
  35. SubCategory []WRCategoryTree // 子分类
  36. }
  37. // CreateCategoryTree 生成现货分类信息
  38. func CreateCategoryTree(parentCategoryID int) ([]WRCategoryTree, error) {
  39. engine := db.GetEngine()
  40. wrCategoryTrees := make([]WRCategoryTree, 0)
  41. if err := engine.Table("WRCATEGORY WR").
  42. Where("WR.PARENTCATEGORYID = ?", parentCategoryID).
  43. Asc("WR.ORDERINDEX").
  44. Find(&wrCategoryTrees); err != nil {
  45. return nil, err
  46. }
  47. for i := range wrCategoryTrees {
  48. category := &wrCategoryTrees[i]
  49. // 递归生成子分类
  50. subs, err := CreateCategoryTree(int(category.Parentcategoryid))
  51. if err != nil {
  52. return nil, err
  53. }
  54. category.SubCategory = subs
  55. }
  56. return wrCategoryTrees, nil
  57. }