| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- 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 // 子分类
- }
- // 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
- }
|