package data_manage import ( sql2 "database/sql" "eta/eta_task/global" "eta/eta_task/utils" "gorm.io/gorm" "time" ) type BaseFromSmm struct { BaseFromSmmId int `gorm:"column:base_from_smm_id;primaryKey;autoIncrement"` Aid int Name string Interface string ApiUpdate int ApiUpdateType string ApiType int ApiTypeAll string Type1 string `gorm:"column:type_1"` Type2 string `gorm:"column:type_2"` Type3 string `gorm:"column:type_3"` ApiStartTime string ApiUpdateTime string StartTime string FinishTime string AuthModule string AuthLang string ApiLabel string Enable string EditPerson string EditTime string AuthDur int AuthDurType string StartDate string EndDate string } func (m *BaseFromSmm) AfterFind(db *gorm.DB) (err error) { m.StartDate = utils.GormDateStrToDateStr(m.StartDate) m.EndDate = utils.GormDateStrToDateStr(m.EndDate) m.ApiStartTime = utils.GormDateStrToDateStr(m.ApiStartTime) m.ApiUpdateTime = utils.GormDateStrToDateStr(m.ApiUpdateTime) return } func AddBaseFromSmm(item *BaseFromSmm) (lastId int64, err error) { err = global.DbMap[utils.DbNameIndex].Create(item).Error if err != nil { return } lastId = int64(item.BaseFromSmmId) return } func GetBaseFromSmmList() (list []*BaseFromSmm, err error) { o := global.DbMap[utils.DbNameIndex] //sql := `SELECT * FROM base_from_smm WHERE interface='cu_annual_copper_cathode_demand_supply_balance_in_china' ` sql := `SELECT * FROM base_from_smm WHERE end_date IS NOT NULL ` err = o.Raw(sql).Find(&list).Error return } type BaseFromSmmIndex struct { BaseFromSmmIndexId int `gorm:"column:base_from_smm_index_id;primaryKey;autoIncrement"` Interface string Name string IndexCode string IndexName string Type1 string `gorm:"column:type_1"` Type2 string `gorm:"column:type_2"` Type3 string `gorm:"column:type_3"` Frequency string Unit string ApiStartTime string ApiUpdateTime string StartTime string FinishTime string CreateTime time.Time ModifyTime time.Time } func (m *BaseFromSmmIndex) AfterFind(db *gorm.DB) (err error) { m.StartTime = utils.GormDateStrToDateStr(m.StartTime) m.FinishTime = utils.GormDateStrToDateStr(m.FinishTime) m.ApiStartTime = utils.GormDateStrToDateStr(m.ApiStartTime) m.ApiUpdateTime = utils.GormDateStrToDateStr(m.ApiUpdateTime) return } func AddBaseFromSmmIndex(item *BaseFromSmmIndex) (lastId int64, err error) { err = global.DbMap[utils.DbNameIndex].Create(item).Error return } func GetBaseFromSmmIndex() (list []*BaseFromSmmIndex, err error) { o := global.DbMap[utils.DbNameIndex] sql := `SELECT * FROM base_from_smm_index ` err = o.Raw(sql).Find(&list).Error return } type BaseFromSmmData struct { SmmDataId int `gorm:"column:smm_data_id;primaryKey;autoIncrement"` BaseFromSmmIndexId int IndexCode string DataTime string Value string CreateTime time.Time ModifyTime time.Time DataTimestamp int64 } func (m *BaseFromSmmData) AfterFind(db *gorm.DB) (err error) { m.DataTime = utils.GormDateStrToDateStr(m.DataTime) return } func AddBaseFromSmmData(item *BaseFromSmmData) (lastId int64, err error) { err = global.DbMap[utils.DbNameIndex].Create(item).Error return } func GetBaseFromSmmDataAll(indexCode string) (list []*BaseFromSmmData, err error) { o := global.DbMap[utils.DbNameIndex] sql := `SELECT * FROM base_from_smm_data WHERE index_code=?` err = o.Raw(sql, indexCode).Find(&list).Error return } func ModifyBaseFromSmmData(smmDataId int, value string) (err error) { o := global.DbMap[utils.DbNameIndex] sql := `UPDATE base_from_smm_data SET value=?,modify_time=NOW() WHERE smm_data_id=? ` err = o.Exec(sql, value, smmDataId).Error return } func GetBaseFromSmmIndexByCode(smmCode string) (list []*BaseFromSmmIndex, err error) { o := global.DbMap[utils.DbNameIndex] sql := ` SELECT * FROM base_from_smm_index WHERE interface=? ` err = o.Raw(sql, smmCode).Find(&list).Error return } func GetBaseFromSmmMaxOrMinDate(indexCode string) (minDate, maxDate string, err error) { o := global.DbMap[utils.DbNameIndex] sql := ` SELECT MIN(data_time) AS min_date, MAX(data_time) AS max_date FROM base_from_smm_data WHERE index_code=? ` var minNull, maxNull sql2.NullString err = o.Raw(sql, indexCode).Row().Scan(&minNull, &maxNull) if err != nil { return } if minNull.Valid { minDate = minNull.String } if maxNull.Valid { maxDate = maxNull.String } return } func ModifyBaseFromSmmSmmType(baseFromSmmId int, smmType string) (err error) { o := global.DbMap[utils.DbNameIndex] sql := ` UPDATE base_from_smm SET smm_type=? WHERE base_from_smm_id=? ` err = o.Exec(sql, smmType, baseFromSmmId).Error return } func ModifyBaseFromSmmMinDateAndMaxDate(baseFromSmmIndexId, baseFromSmmId int, minDate, maxDate string) (err error) { o := global.DbMap[utils.DbNameIndex] sql := ` UPDATE base_from_smm_index SET start_date=?,end_date=?,modify_time=NOW() WHERE base_from_smm_index_id=? ` err = o.Exec(sql, minDate, maxDate, baseFromSmmIndexId).Error sql = ` UPDATE base_from_smm SET start_date=?,end_date=?,modify_time=NOW() WHERE base_from_smm_id=? ` err = o.Exec(sql, minDate, maxDate, baseFromSmmId).Error return } type BaseFromSmmDataSimple struct { SmmDataId int `gorm:"column:smm_data_id;primaryKey;autoIncrement"` BaseFromSmmIndexId int IndexCode string DataTime string Value float64 } func (m *BaseFromSmmDataSimple) AfterFind(db *gorm.DB) (err error) { m.DataTime = utils.GormDateStrToDateStr(m.DataTime) return } func GetBaseFromSmmDataByCondition(condition string, pars []interface{}) (list []*BaseFromSmmDataSimple, err error) { o := global.DbMap[utils.DbNameIndex] sql := `SELECT * FROM base_from_smm_data WHERE 1=1 ` if condition != "" { sql += condition } err = o.Raw(sql, pars...).Find(&list).Error return }