| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- package models
- // 仓单服务
- import (
- "mtp2_if/db"
- "time"
- )
- // Wrcategory 现货分类表
- type Wrcategory 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'"` // 类别描述
- Isvalid int32 `json:"isvalid" xorm:"'ISVALID'"` // 是否有效 - 0:无效 1:有效
- Iconurl string `json:"iconurl" xorm:"'ICONURL'"` // 图标地址
- Creatorid int64 `json:"creatorid" xorm:"'CREATORID'"` // 创建人
- Createtime time.Time `json:"createtime" xorm:"'CREATETIME'"` // 创建时间
- Updatorid int64 `json:"updatorid" xorm:"'UPDATORID'"` // 更新人
- Updatetime time.Time `json:"updatetime" xorm:"'UPDATETIME'"` // 更新时间
- Orderindex int32 `json:"orderindex" xorm:"'ORDERINDEX'"` // 顺序
- Areauserid int64 `json:"areauserid" xorm:"'AREAUSERID'"` // 所属机构
- }
- // TableName is WRCATEGORY
- 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 `json:"subcategory" xorm:"-"` // 子分类
- }
- // CreateCategoryTree 生成现货分类信息
- func CreateCategoryTree(parentCategoryID int) ([]WRCategoryTree, error) {
- engine := db.GetEngine()
- wrCategoryTrees := make([]WRCategoryTree, 0)
- session := engine.Table("WRCATEGORY WR")
- if parentCategoryID != 0 {
- session = session.Where("WR.PARENTCATEGORYID = ?", parentCategoryID)
- } else {
- session = session.Where("WR.PARENTCATEGORYID is null")
- }
- session = session.Asc("WR.ORDERINDEX")
- if err := session.Find(&wrCategoryTrees); err != nil {
- return nil, err
- }
- for i := range wrCategoryTrees {
- category := &wrCategoryTrees[i]
- // 递归生成子分类
- subs, err := CreateCategoryTree(int(category.Categoryid))
- if err != nil {
- return nil, err
- }
- category.SubCategory = subs
- }
- return wrCategoryTrees, nil
- }
|