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