123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- package data_manage
- import (
- "eta/eta_hub/utils"
- "fmt"
- "time"
- "github.com/beego/beego/v2/client/orm"
- "github.com/rdlucklib/rdluck_tools/paging"
- )
- // EtaBusinessChartPermission 商家图表权限表
- type EtaBusinessChartPermission struct {
- EtaBusinessChartPermissionId int64 `orm:"column(eta_business_chart_permission_id);pk;auto"`
- ChartInfoId int `orm:"column(chart_info_id)" description:"图表id"`
- Source int `orm:"column(source)" description:"分类来源: 1-图库; 2-商品价格曲线; 3-相关性图表; 6-拟合方程图表; 7-统计特征"`
- BusinessCode string `orm:"column(business_code)" description:"客户编码"`
- EtaBusinessId int `orm:"column(eta_business_id)" description:"商家ID"`
- ModifyTime time.Time `orm:"column(modify_time);type(datetime);null" description:"变更时间"`
- CreateTime time.Time `orm:"column(create_time);type(datetime);null" description:"关系建立时间"`
- }
- // TableName 设置表名
- func (m *EtaBusinessChartPermission) TableName() string {
- return "eta_business_chart_permission"
- }
- type BusinessChartInfoView struct {
- ChartInfoId int
- ChartName string
- UniqueCode string
- Description []string
- EdbInfoList []*BusinessChartEdbListItem
- }
-
- // GetChartListByBusinessCode 根据商家编码获取图表列表
- func (m *EtaBusinessChartPermission) GetChartListByBusinessCode(businessCode string, startSize int, pageSize int) ([]*BusinessChartInfoView, error) {
- if businessCode == "" {
- return nil, fmt.Errorf("business code cannot be empty")
- }
- var chartList []*BusinessChartInfoView
- o := orm.NewOrmUsingDB("data")
- // 构建SQL查询
- sql := `
- SELECT
- c.chart_info_id, c.chart_name, c.unique_code
- FROM
- eta_business_chart_permission p
- JOIN
- chart_info c ON p.chart_info_id = c.chart_info_id
- WHERE
- p.business_code = ?
- ORDER BY
- c.sort ASC, c.chart_info_id DESC
- LIMIT ?, ?
- `
- _, err := o.Raw(sql, businessCode, startSize, pageSize).QueryRows(&chartList)
- if err != nil {
- return nil, fmt.Errorf("failed to get chart list: %v", err)
- }
- return chartList, nil
- }
- func (m *EtaBusinessChartPermission) GetChartListByBusinessCodeTotal(businessCode string) (int64, error) {
- o := orm.NewOrmUsingDB("data")
- sql := `
- SELECT COUNT(*) FROM eta_business_chart_permission p
- JOIN
- chart_info c ON p.chart_info_id = c.chart_info_id
- WHERE
- p.business_code = ?
- `
- var total int64
- err := o.Raw(sql, businessCode).QueryRow(&total)
- if err != nil {
- return 0, fmt.Errorf("failed to get chart list total: %v", err)
- }
- return total, nil
- }
- // GetChartInfoByUniqueCode 根据唯一编码获取图表信息
- func (m *EtaBusinessChartPermission) GetChartInfoByUniqueCode(businessCode string, uniqueCode string) (chartInfo *BusinessChartInfoView, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `
- SELECT
- c.chart_info_id, c.chart_name, c.unique_code
- FROM
- eta_business_chart_permission p
- JOIN
- chart_info c ON p.chart_info_id = c.chart_info_id
- WHERE
- p.business_code = ? AND c.unique_code = ?
- `
- err = o.Raw(sql, businessCode, uniqueCode).QueryRow(&chartInfo)
- return
- }
- // Init 初始化表结构
- func init() {
- orm.RegisterModel(new(EtaBusinessChartPermission))
- }
- type BusinessChartInfoResp struct {
- List []*BusinessChartInfoView
- Paging *paging.PagingItem
- }
- type BusinessChartEdbListResp struct {
- List []*BusinessChartEdbListItem
- }
- type BusinessChartEdbListItem struct {
- EdbInfoId int
- EdbCode string
- EdbName string
- EdbInfoType int
- Frequency string
- Unit string
- EndDate string
- EndValue float64
- LatestDate string
- LatestValue float64
- UniqueCode string
- }
- type ChartDescription struct {
- ChartInfoId int
- Description string
- }
- // 查询图表描述列表
- func (m *EtaBusinessChartPermission) GetChartDescriptionListByChartInfoIds(chartInfoIds []int) (list []*ChartDescription, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `
- SELECT * FROM chart_description WHERE chart_info_id IN (`+utils.GetOrmInReplace(len(chartInfoIds))+`) ORDER BY id DESC
- `
- _, err = o.Raw(sql, chartInfoIds).QueryRows(&list)
- return list, err
- }
- func (m *EtaBusinessChartPermission) GetChartDescriptionListByChartInfoId(chartInfoId int) (list []*ChartDescription, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `
- SELECT * FROM chart_description WHERE chart_info_id = ? ORDER BY id DESC
- `
- _, err = o.Raw(sql, chartInfoId).QueryRows(&list)
- return
- }
- type BusinessChartDetailResp struct {
- ChartInfoId int
- ChartName string
- UniqueCode string
- Description []string
- EdbInfoList []TraceEdbInfoMoreResp
- }
- // GetChartListByBusinessCode 根据商家编码获取图表列表
- func (m *EtaBusinessChartPermission) GetChartCountByBusinessCodeAndEdbInfoId(businessCode string, edbInfoId int) (count int64, err error) {
- if businessCode == "" {
- return 0, fmt.Errorf("business code cannot be empty")
- }
- o := orm.NewOrmUsingDB("data")
- // 构建SQL查询
- sql := `
- SELECT
- COUNT(DISTINCT p.chart_info_id)
- FROM
- eta_business_chart_permission p
- JOIN
- chart_edb_mapping c ON p.chart_info_id = c.chart_info_id
- WHERE
- p.business_code = ? AND c.edb_info_id = ?
- `
- err = o.Raw(sql, businessCode, edbInfoId).QueryRow(&count)
- return
- }
|