package models

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

// EdbDataInsertConfig 指标数据插入配置表
type EdbDataInsertConfig struct {
	EdbInfoId  int       `orm:"column(edb_info_id);pk" description:"指标id"`
	Date       time.Time `description:"插入的日期"`
	Value      string    `description:"插入的值"`
	RealDate   time.Time `description:"实际数据的日期"`
	ModifyTime time.Time `description:"数据更新时间"`
	CreateTime time.Time `description:"数据插入的时间"`
}

// GetEdbDataInsertConfigByEdbId 根据指标id 获取数据插入配置详情
func GetEdbDataInsertConfigByEdbId(edbInfoId int) (item *EdbDataInsertConfig, err error) {
	o := orm.NewOrm()
	sql := ` SELECT * FROM edb_data_insert_config WHERE edb_info_id=? `
	err = o.Raw(sql, edbInfoId).QueryRow(&item)
	return
}

// DeleteEdbDataInsertConfigByEdbId 根据指标id 删除数据插入配置详情
func DeleteEdbDataInsertConfigByEdbId(edbInfoId int) (err error) {
	o := orm.NewOrm()
	sql := ` DELETE FROM edb_data_insert_config WHERE edb_info_id=? `
	_, err = o.Raw(sql, edbInfoId).Exec()
	return
}

// GetEdbDataInsertConfigByEdbIdWithTo 根据指标id 获取数据插入配置详情
func GetEdbDataInsertConfigByEdbIdWithTo(to orm.TxOrmer, edbInfoId int) (item *EdbDataInsertConfig, err error) {
	sql := ` SELECT * FROM edb_data_insert_config WHERE edb_info_id=? `
	err = to.Raw(sql, edbInfoId).QueryRow(&item)
	return
}
