package data_manage import ( "eta_gn/eta_task/global" "eta_gn/eta_task/utils" "time" ) type EdbDataThs struct { EdbDataId int `orm:"column(edb_data_id);pk"` EdbInfoId int EdbCode string DataTime string Value float64 Status int CreateTime time.Time ModifyTime time.Time DataTimestamp int64 } func AddEdbDataThs(items []*EdbDataThs) (err error) { //o := orm.NewOrm() //_, err = o.InsertMulti(1, items) err = global.DEFAULT_DmSQL.CreateInBatches(items, utils.MultiAddNum).Error return } func ModifyEdbDataThs(edbInfoId int64, edbCode, dataTime string, value float64) (err error) { //o := orm.NewOrm() sql := ` UPDATE edb_data_ths SET edb_info_id=?,value=?,status=1,modify_time=NOW() WHERE edb_code=? AND data_time=? ` //_, err = o.Raw(sql, edbInfoId, value, edbCode, dataTime).Exec() err = global.DEFAULT_DmSQL.Exec(sql, edbInfoId, value, edbCode, dataTime).Error return } func GetEdbDataThsCount(ebdCode, dataTime string) (count int, err error) { //o := orm.NewOrm() sql := ` SELECT COUNT(1) AS count FROM edb_data_ths WHERE edb_code=? AND data_time=? ` //err = o.Raw(sql, ebdCode, dataTime).QueryRow(&count) err = global.DEFAULT_DmSQL.Raw(sql, ebdCode, dataTime).Scan(&count).Error return } func GetEdbDataThsMaxOrMinDate(edbInfoId int) (min_date, max_date string, err error) { //o := orm.NewOrm() sql := ` SELECT MIN(data_time) AS min_date,MAX(data_time) AS max_date FROM edb_data_ths WHERE edb_info_id=? ` //err = o.Raw(sql, edbInfoId).QueryRow(&min_date, &max_date) err = global.DEFAULT_DmSQL.Raw(sql, edbInfoId).First(&min_date, &max_date).Error return }