1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- package data_manage
- import (
- "eta/eta_hub/utils"
- "fmt"
- "github.com/beego/beego/v2/client/orm"
- "strings"
- "time"
- )
- // EdbClassify 指标分类
- type EdbClassify struct {
- ClassifyId int `orm:"column(classify_id);pk"`
- ClassifyType uint8 `description:"分类类型,0:普通指标分类,1:预测指标分类"`
- ClassifyName string `description:"分类名称"`
- ParentId int `description:"父级id"`
- RootId int `description:"顶级id"`
- HasData int `description:"是否含有指标数据"`
- SysUserId int `description:"创建人id"`
- SysUserRealName string `description:"创建人姓名"`
- Level int `description:"层级"`
- UniqueCode string `description:"唯一编码"`
- Sort int `description:"排序字段,越小越靠前,默认值:10"`
- CreateTime time.Time `description:"创建时间"`
- ModifyTime time.Time `description:"修改时间"`
- }
- func (m *EdbClassify) GetItemsByCondition(cond string, pars []interface{}, fieldArr []string, orderRule string) (items []*EdbClassify, err error) {
- o := orm.NewOrmUsingDB("data")
- fields := strings.Join(fieldArr, ",")
- if len(fieldArr) == 0 {
- fields = `*`
- }
- order := `ORDER BY create_time DESC`
- if orderRule != "" {
- order = ` ORDER BY ` + orderRule
- }
- sql := fmt.Sprintf(`SELECT %s FROM edb_classify WHERE 1=1 %s %s`, fields, cond, order)
- _, err = o.Raw(sql, pars).QueryRows(&items)
- return
- }
- // EdbClassifyItem 指标分类信息
- type EdbClassifyItem struct {
- ClassifyId int `description:"分类ID"`
- ClassifyName string `description:"分类名称"`
- UniqueCode string `description:"分类唯一编码"`
- ParentId int `description:"父级id"`
- Level int `description:"层级"`
- Sort int `description:"排序"`
- CreateTime string `description:"创建时间"`
- UpdateTime string `description:"更新时间"`
- Child []*EdbClassifyItem `description:"子分类"`
- }
- func FormatEdbClassify2Item(origin *EdbClassify) (item *EdbClassifyItem) {
- if origin == nil {
- return
- }
- item = new(EdbClassifyItem)
- item.ClassifyId = origin.ClassifyId
- item.ClassifyName = origin.ClassifyName
- item.UniqueCode = origin.UniqueCode
- item.ParentId = origin.ParentId
- item.Level = origin.Level
- item.Sort = origin.Sort
- item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
- item.UpdateTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
- item.Child = make([]*EdbClassifyItem, 0)
- return
- }
|