12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- package services
- import (
- "encoding/json"
- "eta/eta_task/models/data_manage"
- "eta/eta_task/utils"
- "fmt"
- "time"
- )
- // 郑州商品交易所持单排名
- func SyncRankingFromZhengzhou() (err error) {
- var startDate string
- maxDate, err := data_manage.GetBaseFromTradeZhengzhouIndexMaxDate()
- 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_DL
- data["Source"] = utils.DATA_SOURCE_ZZ
- data["StartDate"] = startDate
- //data["EndDate"] = endDate
- result, err := HttpPost("SyncRankingFromZhengzhou", method, data)
- if err != nil {
- fmt.Println("SyncRankingFromZhengzhou HttpPost Err:", err.Error())
- }
- utils.FileLog.Info(result)
- fmt.Println("SyncRankingFromZhengzhou result:", result)
- respObj := new(data_manage.ZhengzhouIndexResp)
- err = json.Unmarshal([]byte(result), &respObj)
- if err != nil {
- return err
- }
- //获取所有指标信息 某一天的
- allIndex, err := data_manage.GetBaseFromTradeZhengzhouIndexAll(startDate)
- if err != nil {
- return
- }
- existIndexMap := make(map[int]*data_manage.BaseFromTradeZhengzhouIndex)
- for _, v := range allIndex {
- existIndexMap[v.BaseFromTradeZhengzhouIndexId] = v
- }
- for _, zv := range respObj.Data {
- if _, ok := existIndexMap[zv.BaseFromTradeZhengzhouIndexId]; !ok {
- newID, err := data_manage.AddBaseFromTradeZhengzhouIndex(zv)
- if err != nil {
- fmt.Println("insert error:", err)
- }
- fmt.Println("insert new indexID:", newID)
- }
- }
- return err
- }
|