|
|
@@ -2,7 +2,10 @@ package models
|
|
|
|
|
|
// 仓单服务
|
|
|
|
|
|
-import "time"
|
|
|
+import (
|
|
|
+ "mtp2_if/db"
|
|
|
+ "time"
|
|
|
+)
|
|
|
|
|
|
// Wrcategory 现货分类表
|
|
|
type Wrcategory struct {
|
|
|
@@ -24,3 +27,41 @@ type Wrcategory struct {
|
|
|
func (Wrcategory) TableName() string {
|
|
|
return "WRCATEGORY"
|
|
|
}
|
|
|
+
|
|
|
+// WRCategoryTree 现货分类
|
|
|
+type WRCategoryTree struct {
|
|
|
+ Categoryid int32 `json:"categoryid" xorm:"'CATEGORYID'" binding:"required"` // 类别ID(SEQ_WRCATEGORY)
|
|
|
+ Categoryname string `json:"categoryname" xorm:"'CATEGORYNAME'"` // 类别名称
|
|
|
+ Parentcategoryid int32 `json:"parentcategoryid" xorm:"'PARENTCATEGORYID'"` // 父类别ID
|
|
|
+ Categorydesc string `json:"categorydesc" xorm:"'CATEGORYDESC'"` // 类别描述
|
|
|
+ Iconurl string `json:"iconurl" xorm:"'ICONURL'"` // 图标地址
|
|
|
+ Orderindex int32 `json:"orderindex" xorm:"'ORDERINDEX'"` // 顺序
|
|
|
+ Areauserid int64 `json:"areauserid" xorm:"'AREAUSERID'"` // 所属机构
|
|
|
+
|
|
|
+ SubCategory []WRCategoryTree // 子分类
|
|
|
+}
|
|
|
+
|
|
|
+// CreateCategoryTree 生成现货分类信息
|
|
|
+func CreateCategoryTree(parentCategoryID int) ([]WRCategoryTree, error) {
|
|
|
+ engine := db.GetEngine()
|
|
|
+
|
|
|
+ wrCategoryTrees := make([]WRCategoryTree, 0)
|
|
|
+ if err := engine.Table("WRCATEGORY WR").
|
|
|
+ Where("WR.PARENTCATEGORYID = ?", parentCategoryID).
|
|
|
+ Asc("WR.ORDERINDEX").
|
|
|
+ Find(&wrCategoryTrees); err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ for i := range wrCategoryTrees {
|
|
|
+ category := &wrCategoryTrees[i]
|
|
|
+
|
|
|
+ // 递归生成子分类
|
|
|
+ subs, err := CreateCategoryTree(int(category.Parentcategoryid))
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ category.SubCategory = subs
|
|
|
+ }
|
|
|
+
|
|
|
+ return wrCategoryTrees, nil
|
|
|
+}
|