package data_manage import ( "eta/eta_api/utils" "github.com/beego/beego/v2/client/orm" "time" ) // BaseFromFenweiClassify 汾渭原始数据分类表 type BaseFromFenweiClassify struct { ClassifyId int `orm:"column(classify_id);pk"` ClassifyName string `description:"分类名称"` ParentId int `description:"父级id"` SysUserId int `description:"创建人id"` SysUserRealName string `description:"创建人姓名"` Level int `description:"层级"` Sort int `description:"排序字段,越小越靠前,默认值:10"` ModifyTime time.Time `description:"修改时间"` CreateTime time.Time `description:"创建时间"` } // GetBaseFromFenweiClassify 获取所有分类 func GetBaseFromFenweiClassify() (items []*BaseFromFenweiClassify, err error) { o := orm.NewOrmUsingDB("data") sql := ` SELECT * FROM base_from_fenwei_classify ORDER BY parent_id ASC, sort ASC, classify_id ASC` _, err = o.Raw(sql).QueryRows(&items) return } // BaseFromFenweiClassifyItem 汾渭数据分类信息 type BaseFromFenweiClassifyItem struct { ClassifyId int `description:"分类ID"` ClassifyName string `description:"分类名称"` ParentId int `description:"父级id"` Level int `description:"层级"` Sort int `description:"排序字段"` CreateTime string `description:"创建时间"` ModifyTime string `description:"修改时间"` Child []*BaseFromFenweiClassifyItem `description:"子分类"` } func (y *BaseFromFenweiClassify) Format2Item(origin *BaseFromFenweiClassify) (item *BaseFromFenweiClassifyItem) { if origin == nil { return } item = new(BaseFromFenweiClassifyItem) item.ClassifyId = origin.ClassifyId item.ClassifyName = origin.ClassifyName item.ParentId = origin.ParentId item.Level = origin.Level item.Sort = origin.Sort item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime) item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime) return } // GetFenweiClassifyItemByClassifyId 根据分类id查询分类信息 func GetFenweiClassifyItemByClassifyId(classifyId int) (item *BaseFromFenweiClassifyItem, err error) { o := orm.NewOrmUsingDB("data") sql := ` SELECT * FROM base_from_fenwei_classify WHERE classify_id = ?` var origin BaseFromFenweiClassify err = o.Raw(sql, classifyId).QueryRow(&origin) if err != nil { return } item = origin.Format2Item(&origin) return }