package data_manage import ( "eta_gn/eta_api/global" "eta_gn/eta_api/utils" "fmt" "strings" "time" ) // ChartFrameworkNode 图库框架节点表 type ChartFrameworkNode struct { ChartFrameworkNodeId int `orm:"column(chart_framework_node_id);pk" gorm:"primaryKey" ` ChartFrameworkId int `description:"框架ID"` FrameworkName string `description:"框架名称"` NodeId string `description:"节点ID"` NodeName string `description:"节点名称"` MyChartClassifyId int `description:"我的图表分类ID"` CreateTime time.Time `description:"创建时间"` } func (m *ChartFrameworkNode) TableName() string { return "chart_framework_node" } func (m *ChartFrameworkNode) PrimaryId() string { return "chart_framework_node_id" } func (m *ChartFrameworkNode) Create() (err error) { err = global.DmSQL["data"].Create(m).Error return } func (m *ChartFrameworkNode) CreateMulti(items []*ChartFrameworkNode) (err error) { if len(items) == 0 { return } err = global.DmSQL["data"].CreateInBatches(items, utils.MultiAddNum).Error return } func (m *ChartFrameworkNode) Update(cols []string) (err error) { o := global.DmSQL["data"] err = o.Select(cols).Updates(m).Error return } func (m *ChartFrameworkNode) Del() (err error) { o := global.DmSQL["data"] sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId()) err = o.Exec(sql, m.ChartFrameworkNodeId).Error return } func (m *ChartFrameworkNode) GetItemById(id int) (item *ChartFrameworkNode, err error) { o := global.DmSQL["data"] sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId()) err = o.Raw(sql, id).First(&item).Error return } func (m *ChartFrameworkNode) GetItemByCondition(condition string, pars []interface{}) (item *ChartFrameworkNode, err error) { o := global.DmSQL["data"] sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s LIMIT 1`, m.TableName(), condition) err = o.Raw(sql, pars...).First(&item).Error return } func (m *ChartFrameworkNode) GetCountByCondition(condition string, pars []interface{}) (count int, err error) { o := global.DmSQL["data"] sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition) err = o.Raw(sql, pars...).Scan(&count).Error return } func (m *ChartFrameworkNode) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*ChartFrameworkNode, err error) { o := global.DmSQL["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 %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order) err = o.Raw(sql, pars...).Scan(&items).Error return } func (m *ChartFrameworkNode) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*ChartFrameworkNode, err error) { o := global.DmSQL["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 %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order) pars = append(pars, startSize) pars = append(pars, pageSize) err = o.Raw(sql, pars...).Scan(&items).Error return } // ChartFrameworkNodeItem 图库框架节点信息 type ChartFrameworkNodeItem struct { ChartFrameworkNodeId int ChartFrameworkId int `description:"框架ID"` FrameworkName string `description:"框架名称"` NodeId string `description:"节点ID"` NodeName string `description:"节点名称"` MyChartClassifyId int `description:"我的图表分类ID"` ChartNum int `description:"分类下的图表数"` CreateTime string `description:"创建时间"` } // FormatChartFrameworkNode2Item 格式化框架节点信息 func FormatChartFrameworkNode2Item(origin *ChartFrameworkNode, chartNum int) (item *ChartFrameworkNodeItem) { if origin == nil { return } item = new(ChartFrameworkNodeItem) item.ChartFrameworkNodeId = origin.ChartFrameworkNodeId item.ChartFrameworkId = origin.ChartFrameworkId item.FrameworkName = origin.FrameworkName item.NodeId = origin.NodeId item.NodeName = origin.NodeName item.MyChartClassifyId = origin.MyChartClassifyId item.ChartNum = chartNum item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime) return }