123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- package services
- import (
- "context"
- "encoding/json"
- "eta/eta_task/models/data_manage"
- "eta/eta_task/utils"
- "fmt"
- "time"
- )
- // 大连商品交易所持单排名
- func SyncRankingFromDalian(cont context.Context) (err error) {
- var startDate string
- maxDate, err := data_manage.GetBaseFromTradeDalianIndexMaxDate()
- if err != nil || maxDate.IsZero() {
- startDate = time.Now().AddDate(0, 0, -1).Format(utils.FormatDate) + " 00:00:00"
- } else {
- startDate = maxDate.AddDate(0, 0, 1).Format(utils.FormatDate) + " 00:00:00"
- }
- method := `index/list`
- data := make(map[string]interface{})
- data["Source"] = utils.DATA_SOURCE_DL
- data["StartDate"] = startDate
- //data["EndDate"] = endDate
- result, err := HttpPost("SyncRankingFromDalian", method, data)
- utils.FileLog.Info(result)
- fmt.Println(result)
- respObj := new(data_manage.DalianIndexResp)
- err = json.Unmarshal([]byte(result), &respObj)
- if err != nil {
- return err
- }
- //获取所有指标信息 某一天的
- allIndex, err := data_manage.GetBaseFromTradeDalianDataList(startDate)
- if err != nil {
- return
- }
- existIndexMap := make(map[int]*data_manage.BaseFromTradeDalianIndex)
- for _, v := range allIndex {
- existIndexMap[v.BaseFromTradeDalianIndexId] = v
- }
- for _, zv := range respObj.Data {
- if _, ok := existIndexMap[zv.BaseFromTradeDalianIndexId]; !ok {
- newID, err := data_manage.AddBaseFromTradeDalianIndex(zv)
- if err != nil {
- fmt.Println("insert error:", err)
- }
- fmt.Println("insert new indexID:", newID)
- }
- }
- return err
- }
|