123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- package data_manage
- import (
- "eta/eta_api/utils"
- "github.com/beego/beego/v2/client/orm"
- "time"
- )
- type EdbDataWind 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 AddEdbDataWindBySql(sqlStr string) (err error) {
- o := orm.NewOrmUsingDB("data")
- _, err = o.Raw(sqlStr).Exec()
- return
- }
- func DeleteEdbDataWind(edbCode string) (err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `DELETE FROM edb_data_wind WHERE edb_code=? `
- _, err = o.Raw(sql, edbCode).Exec()
- return
- }
- func ModifyEdbDataWind(edbInfoId int64, dataTime string, value float64) (err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` UPDATE edb_data_wind SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
- _, err = o.Raw(sql, value, edbInfoId, dataTime).Exec()
- return
- }
- func GetEdbDataWindByCode(edbCode string, size int) (items []*EdbInfoSearchData, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT * FROM edb_data_wind WHERE edb_code=? ORDER BY data_time DESC LIMIT ? `
- _, err = o.Raw(sql, edbCode, size).QueryRows(&items)
- return
- }
- func GetEdbDataWindMaxOrMinDate(edbCode string) (min_date, max_date string, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT MIN(data_time) AS min_date,MAX(data_time) AS max_date FROM edb_data_wind WHERE edb_code=? `
- err = o.Raw(sql, edbCode).QueryRow(&min_date, &max_date)
- return
- }
- func GetEdbDataWindByCodeAndDate(edbCode string, startDate string) (count int, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT COUNT(1) AS count FROM edb_data_wind WHERE edb_code=? AND data_time=? `
- err = o.Raw(sql, edbCode, startDate).QueryRow(&count)
- return
- }
- type EdbDataFromWind struct {
- Close map[string]float64 `json:"CLOSE"`
- Dt map[string]int64 `json:"DT"`
- ErrMsg string
- }
- func EdbInfoUpdateStatusByEdbInfoId(edbInfoIds []int, isStop int, calculateEdbInfoIds []int) (err error) {
- o, err := orm.NewOrmUsingDB("data").Begin()
- if err != nil {
- return
- }
- defer func() {
- if err != nil {
- _ = o.Rollback()
- return
- }
- _ = o.Commit()
- }()
- // 更改指标的更新状态
- if len(edbInfoIds) == 1 {
- sql := ` UPDATE edb_info SET no_update = ?, set_update_time=? WHERE edb_info_id=? `
- _, err = o.Raw(sql, isStop, time.Now(), edbInfoIds[0]).Exec()
- if err != nil {
- return
- }
- } else {
- sql := ` UPDATE edb_info SET no_update = ?, set_update_time=? WHERE edb_info_id IN (` + utils.GetOrmInReplace(len(edbInfoIds)) + `) `
- _, err = o.Raw(sql, isStop, time.Now(), edbInfoIds).Exec()
- if err != nil {
- return
- }
- }
- if len(calculateEdbInfoIds) > 0 {
- // 批量更新相关联的指标ID
- sql := ` UPDATE edb_info SET no_update = ?, set_update_time=? WHERE edb_info_id IN (` + utils.GetOrmInReplace(len(calculateEdbInfoIds)) + `) `
- _, err = o.Raw(sql, isStop, time.Now(), calculateEdbInfoIds).Exec()
- if err != nil {
- return
- }
- }
- return
- }
|