package data_manage

import (
	"github.com/beego/beego/v2/client/orm"
	"time"
)

// EdbDataPython python指标数据结构体
type EdbDataPython struct {
	EdbDataId     int `orm:"column(edb_data_id);pk"`
	EdbInfoId     int
	EdbCode       string
	DataTime      string
	Value         float64
	CreateTime    time.Time
	ModifyTime    time.Time
	DataTimestamp int64
}

// GetAllEdbDataPythonByEdbInfoId 根据指标id获取全部的数据
func GetAllEdbDataPythonByEdbInfoId(edbInfoId int) (items []*EdbDataPython, err error) {
	o := orm.NewOrmUsingDB("data")
	sql := ` SELECT * FROM edb_data_python WHERE edb_info_id=? ORDER BY data_time DESC `
	_, err = o.Raw(sql, edbInfoId).QueryRows(&items)
	return
}

// EdbInfoPythonSaveReq 计算（运算）指标请求参数
type EdbInfoPythonSaveReq struct {
	AdminId          int    `description:"添加人id"`
	AdminName        string `description:"添加人名称"`
	EdbName          string `description:"指标名称"`
	Frequency        string `description:"频率"`
	Unit             string `description:"单位"`
	ClassifyId       int    `description:"分类id"`
	CalculateFormula string `description:"计算公式"`
	EdbInfoIdArr     []struct {
		EdbInfoId int    `description:"指标id"`
		FromTag   string `description:"指标对应标签"`
	}
}

// ExecPythonEdbReq 执行python代码运算指标的请求参数
type ExecPythonEdbReq struct {
	PythonCode string `description:"python代码"`
}

// AddPythonEdbReq 添加python代码运算指标的请求参数
type AddPythonEdbReq struct {
	EdbInfoId  int    `description:"指标id"`
	EdbName    string `description:"指标名称"`
	Frequency  string `description:"频度"`
	Unit       string `description:"单位"`
	ClassifyId int    `description:"分类id"`
	PythonCode string `description:"python代码"`
}

// PostAddPythonEdbReq 添加python代码运算指标的请求参数（请求指标服务）
type PostAddPythonEdbReq struct {
	AdminId    int    `description:"添加人id"`
	AdminName  string `description:"添加人名称"`
	EdbInfoId  int    `description:"指标id"`
	EdbName    string `description:"指标名称"`
	Frequency  string `description:"频度"`
	Unit       string `description:"单位"`
	ClassifyId int    `description:"分类id"`
	PythonCode string `description:"python代码"`
}

// PythonEdbDetailResp python指标详情接口
type PythonEdbDetailResp struct {
	EdbInfoDetail *EdbInfo
	PythonCode    string
}

// TableInfoResp 指标数据表结构
type TableInfoResp struct {
	ColumnList  []map[string]string
	TableName   string
	TemplateStr string
}
