12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- 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 WindEdbInfoUpdateStatusByEdbInfoId(edbInfoId, isStop, subSource 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()
- }()
- // 更改指标的更新状态
- sql := ` UPDATE edb_info SET no_update = ? WHERE source = ? AND sub_source= ? AND edb_info_id=? `
- _, err = o.Raw(sql, isStop, utils.DATA_SOURCE_WIND, subSource, edbInfoId).Exec()
- if err != nil {
- return
- }
- if len(calculateEdbInfoIds) > 0 {
- // 批量更新相关联的指标ID
- sql = ` UPDATE edb_info SET no_update = ? WHERE edb_info_id IN (` + utils.GetOrmInReplace(len(calculateEdbInfoIds)) + `) `
- _, err = o.Raw(sql, isStop, calculateEdbInfoIds).Exec()
- if err != nil {
- return
- }
- }
- return
- }
|