package data_manage import ( "eta/eta_task/global" "eta/eta_task/utils" "fmt" "gorm.io/gorm" "time" ) //func GetEdbDataCalculateByCodeAndDate(edbCode string, startDate string) (count int, err error) { // o := global.DbMap[utils.DbNameIndex] // sql := ` SELECT COUNT(1) AS count FROM edb_data_calculate WHERE edb_code=? AND data_time=? ` // err = o.Raw(sql, edbCode, startDate).Scan(&count).Error // return //} //func ModifyEdbDataCalculate(edbInfoId int64, dataTime string, value float64) (err error) { // o := global.DbMap[utils.DbNameIndex] // sql := ` UPDATE edb_data_calculate SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? ` // sql = utils.ReplaceDriverKeywords("", sql) // err = o.Exec(sql, value, edbInfoId, dataTime).Error // return //} //func AddEdbDataCalculateBySql(sqlStr string) (err error) { // o := global.DbMap[utils.DbNameIndex] // err = o.Exec(sqlStr).Error // return //} // DeleteEdbDataCalculateBySql 根据删除sql删除指标数据 //func DeleteEdbDataCalculateBySql(deleteStr string, edbInfoId int) (err error) { // o := global.DbMap[utils.DbNameIndex] // err = o.Exec(deleteStr, edbInfoId).Error // return //} type EdbInfoCalculateDetail struct { EdbInfoCalculateId int `gorm:"column:edb_info_calculate_id;primaryKey;autoIncrement"` EdbInfoId int `description:"指标id"` EdbCode string `description:"指标编码"` FromEdbInfoId int `description:"计算指标id"` FromEdbCode string `description:"计算指标编码"` FromEdbName string `description:"计算指标名称"` FromSource int `description:"计算指标来源"` FromSourceName string `description:"计算指标来源名称"` FromTag string `description:"来源指标标签"` Sort int `description:"计算指标名称排序"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"修改时间"` StartDate string `description:"开始日期"` EndDate string `description:"结束日期"` } func (m *EdbInfoCalculateDetail) AfterFind(db *gorm.DB) (err error) { m.StartDate = utils.GormDateStrToDateStr(m.StartDate) m.EndDate = utils.GormDateStrToDateStr(m.EndDate) return } //func GetEdbInfoCalculateDetail(edbInfoId int) (list []*EdbInfoCalculateDetail, err error) { // o := global.DbMap[utils.DbNameIndex] // sql := ` SELECT a.*,b.start_date,b.end_date FROM edb_info_calculate_mapping AS a // INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id // WHERE a.edb_info_id=? ORDER BY sort ASC ` // err = o.Raw(sql, edbInfoId).Find(&list).Error // return //} func GetEdbInfoCalculateMap(edbInfoId, source int) (list []*EdbInfoCalculateDetail, err error) { o := global.DbMap[utils.DbNameIndex] calculateTableName := GetEdbInfoCalculateTableName(source) sql := ` SELECT a.*,b.start_date,b.end_date,b.edb_type FROM %s AS a INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id WHERE a.edb_info_id=? ORDER BY sort ASC ` sql = fmt.Sprintf(sql, calculateTableName) err = o.Raw(sql, edbInfoId).Find(&list).Error return }