1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- package models
- import (
- "fmt"
- "github.com/beego/beego/v2/client/orm"
- "hongze/hongze_edb_lib/services"
- "hongze/hongze_edb_lib/utils"
- "strings"
- "time"
- )
- func AddEdbDataFromThs(edbCode string, item *services.EdbDataFromThs) (err error) {
- var errMsg string
- o := orm.NewOrm()
- defer func() {
- if err != nil {
- go utils.SendEmail(utils.APP_NAME_CN+"【"+utils.RunMode+"】"+"失败提醒", " 同花顺数据获取失败:err:"+errMsg, utils.EmailSendToUsers)
- }
- }()
- if len(item.Tables) > 0 {
- table := item.Tables[0]
- dataLen := len(table.Time)
- var isAdd bool
- addSql := ` INSERT INTO %s(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
- tableName := GetEdbDataTableName(utils.DATA_SOURCE_THS)
- addSql = fmt.Sprintf(addSql, tableName)
- for i := 0; i < dataLen; i++ {
- eDate := table.Time[i]
- sValue := table.Value[i]
- dataTime, err := time.Parse(utils.FormatDate, eDate)
- if err != nil {
- errMsg = " time.Parse :" + err.Error()
- return err
- }
- timestamp := dataTime.UnixNano() / 1e6
- timeStr := fmt.Sprintf("%d", timestamp)
- addSql += GetAddSql("0", edbCode, eDate, timeStr, utils.SubFloatToString(sValue, 20))
- isAdd = true
- }
- if isAdd {
- addSql = strings.TrimRight(addSql, ",")
- _, err = o.Raw(addSql).Exec()
- if err != nil {
- errMsg = " tx.Exec Err :" + err.Error()
- return
- }
- }
- }
- return
- }
- func GetEdbDataByThs(edbCode string, item *services.EdbDataFromThs) (dataList []*EdbInfoSearchData, err error) {
- AddEdbDataFromThs(edbCode, item)
- size := utils.EDB_DATA_LIMIT
- dataList, err = GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_THS, size)
- if err != nil {
- //utils.FileLogData.Info("GetEdbDataThsByCode Err:%s", err.Error())
- return
- }
- if len(dataList) < 0 {
- dataList = make([]*EdbInfoSearchData, 0)
- }
- return
- }
|