12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- package data_manage
- import (
- "eta/eta_hub/utils"
- "fmt"
- "github.com/beego/beego/v2/client/orm"
- "strings"
- "time"
- )
- // ChartClassify 图表分类表
- type ChartClassify struct {
- ChartClassifyId int `orm:"column(chart_classify_id);pk"`
- ChartClassifyName string `description:"分类名称"`
- ParentId int `description:"父级id"`
- HasData int `description:"是否含有指标数据"`
- SysUserId int `description:"创建人id"`
- SysUserRealName string `description:"创建人姓名"`
- Level int `description:"层级"`
- UniqueCode string `description:"唯一编码"`
- Sort int `description:"排序字段,越小越靠前,默认值:10"`
- Source int `description:"1:ETA图库;2:商品价格曲线"`
- CreateTime time.Time `description:"创建时间"`
- ModifyTime time.Time `description:"修改时间"`
- }
- func (m *ChartClassify) GetItemsByCondition(cond string, pars []interface{}, fieldArr []string, orderRule string) (items []*ChartClassify, 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 chart_classify WHERE 1=1 %s %s`, fields, cond, order)
- _, err = o.Raw(sql, pars).QueryRows(&items)
- return
- }
- // ChartClassifyItem 指标分类信息
- type ChartClassifyItem struct {
- ClassifyId int `description:"分类ID"`
- ClassifyName string `description:"分类名称"`
- UniqueCode string `description:"唯一编码"`
- ParentId int `description:"父级ID"`
- Level int `description:"层级"`
- Sort int `description:"排序字段,越小越靠前,默认值:10"`
- //Source int `description:"1-ETA图库; 2-商品价格曲线"`
- CreateTime string `description:"创建时间"`
- UpdateTime string `description:"修改时间"`
- Child []*ChartClassifyItem `description:"子分类"`
- }
- func FormatChartClassify2Item(origin *ChartClassify) (item *ChartClassifyItem) {
- if origin == nil {
- return
- }
- item = new(ChartClassifyItem)
- item.ClassifyId = origin.ChartClassifyId
- item.ClassifyName = origin.ChartClassifyName
- item.UniqueCode = origin.UniqueCode
- item.ParentId = origin.ParentId
- item.Level = origin.Level
- item.Sort = origin.Sort
- //item.Source = origin.Source
- item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
- item.UpdateTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
- item.Child = make([]*ChartClassifyItem, 0)
- return
- }
- type ChartClassifyView struct {
- ChartClassifyId int `description:"图表分类"`
- ChartClassifyName string `description:"分类名称"`
- ParentId int `description:"父级ID"`
- }
- func GetChartClassifyViewById(classifyId int) (item *ChartClassifyView, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `SELECT * FROM chart_classify WHERE chart_classify_id=? `
- err = o.Raw(sql, classifyId).QueryRow(&item)
- return
- }
|