package data_stat

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

// EdbInfoDeleteLog 指标删除日志表
type EdbInfoDeleteLog struct {
	Id                 uint64  `orm:"column(id);pk"`
	EdbInfoId          int     `description:"指标ID"`
	EdbInfoType        int     `description:"指标类型，0：普通指标，1：预测指标"`
	SourceName         string  `description:"来源名称"`
	Source             int     `description:"来源id"`
	EdbCode            string  `description:"指标编码"`
	EdbName            string  `description:"指标名称"`
	EdbNameEn          string  `description:"英文指标名称"`
	EdbNameSource      string  `description:"指标名称来源"`
	Frequency          string  `description:"频率"`
	Unit               string  `description:"单位"`
	UnitEn             string  `description:"英文单位"`
	StartDate          string  `description:"起始日期"`
	EndDate            string  `description:"终止日期"`
	SysUserId          int     `description:"创建人ID"`
	SysUserRealName    string  `description:"创建人姓名"`
	UniqueCode         string  `description:"指标唯一编码"`
	EdbCreateTime      string  `description:"指标创建时间"`
	EdbModifyTime      string  `description:"指标修改时间"`
	CreateTime         string  `description:"创建时间即删除时间"`
	MinValue           float64 `description:"指标最小值"`
	MaxValue           float64 `description:"指标最大值"`
	CalculateFormula   string  `description:"计算公式"`
	EdbType            int     `description:"指标类型:1:基础指标,2:计算指标"`
	LatestDate         string  `description:"数据最新日期"`
	LatestValue        float64 `description:"数据最新值"`
	MoveType           int     `description:"移动方式:1:领先(默认),2:滞后"`
	MoveFrequency      string  `description:"移动频度"`
	NoUpdate           int8    `description:"是否停止更新，0：继续更新；1：停止更新"`
	ChartImage         string  `description:"图表图片"`
	Calendar           string  `description:"公历/农历" orm:"default(公历);"`
	DataDateType       string  `orm:"column(data_date_type);size(255);null;default(交易日)"`
	ManualSave         int     `description:"是否有手动保存过上下限: 0-否; 1-是"`
	TerminalCode       string  `description:"终端编码，用于配置在机器上"`
	DelSysUserId       int     `description:"删除人ID"`
	DelSysUserRealName string  `description:"删除人姓名"`
	DataUpdateTime     string  `description:"最近一次数据发生变化的时间"`
	ErDataUpdateDate   string  `description:"本次更新，数据发生变化的最早日期"`
}

type EdbInfoDeleteLogNum struct {
	Source       int    `description:"来源id"`
	TerminalCode string `description:"终端编码，用于配置在机器上"`
	Num          int    `description:"被删除的指标数据总数"`
}

func GetEdbDeleteLogNumByCreateTime(startDate, endDate string) (item []*EdbInfoDeleteLogNum, err error) {
	o := orm.NewOrm()
	sql := ` SELECT source, terminal_code, count(*) as num FROM edb_info_delete_log WHERE create_time >= ? and create_time < ? group by source, terminal_code `
	_, err = o.Raw(sql, startDate, endDate).QueryRows(&item)
	return
}
