|
@@ -707,6 +707,7 @@ func GetLzProductPriceData() (err error) {
|
|
|
if msg != "" {
|
|
|
fmt.Println("msg:", msg)
|
|
|
go utils.SendEmail("获取隆众价格指标失败"+time.Now().Format("2006-01-02 15:04:05"), ";msg:"+msg, utils.EmailSendToUsers)
|
|
|
+ utils.FileLog.Info("%s", msg)
|
|
|
}
|
|
|
}()
|
|
|
|
|
@@ -723,13 +724,72 @@ func GetLzProductPriceData() (err error) {
|
|
|
password := "HZMD2020"
|
|
|
for k, v := range typeMap {
|
|
|
fmt.Println(k, v)
|
|
|
- getUrl := `https://openapi.oilchem.net/price/getPrice?password=` + password + `&type=` + k + `&username=` + username + `&inStartDate=2020-08-31&inEndDate=2020-09-02`
|
|
|
+ getUrl := `https://openapi.oilchem.net/price/getPrice?password=` + password + `&type=` + k + `&username=` + username + `&inStartDate=2017-01-01&inEndDate=2017-01-07`
|
|
|
body, err := http.Get(getUrl)
|
|
|
- fmt.Println("body")
|
|
|
- fmt.Println(err)
|
|
|
- fmt.Println(string(body))
|
|
|
- fmt.Println("sleep:")
|
|
|
- time.Sleep(31 * time.Second)
|
|
|
+ if err != nil {
|
|
|
+ msg = "获取隆众价格数据失败:Err" + err.Error()
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ fmt.Println("getUrl:", getUrl)
|
|
|
+ fmt.Println("body", string(body))
|
|
|
+ infoList := new(models.LzPriceDataResp)
|
|
|
+ err = json.Unmarshal(body, &infoList)
|
|
|
+ if err != nil {
|
|
|
+ msg = "获取隆众价格数据失败:Unmarshal Err " + err.Error() + " ;body:" + string(body)
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ if infoList.Code != 1 {
|
|
|
+ msg = "获取隆众价格数据失败:body " + string(body)
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ for _, n := range infoList.Data {
|
|
|
+ infoItem, err := models.GetLongzhongpriceinfoByPriceId(n.Id)
|
|
|
+ if err != nil {
|
|
|
+ if err.Error() == utils.ErrNoRow() {
|
|
|
+ fmt.Println("指标不存在:id:" + n.Id)
|
|
|
+ msg = "指标不存在:id:" + n.Id
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ fmt.Println("获取指标失败:id:" + n.Id)
|
|
|
+ msg = "获取指标失败:id:" + n.Id
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if infoItem == nil {
|
|
|
+ fmt.Println("指标不存在:id:" + n.Id)
|
|
|
+ msg = "指标不存在:id:" + n.Id
|
|
|
+ return
|
|
|
+ }
|
|
|
+ count, err := models.GetLongzhongpricedataCount(n.Id, n.PriceDate)
|
|
|
+ if err != nil {
|
|
|
+ msg = "获取隆众价格数据失败:err " + err.Error()
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ if count > 0 {
|
|
|
+ fmt.Println("存在", n.PriceDate, n.Id)
|
|
|
+ } else {
|
|
|
+ item := new(models.Longzhongpricedata)
|
|
|
+ item.LongzhongpriceinfoId=infoItem.LongzhongpriceinfoId
|
|
|
+ item.PriceDate=n.PriceDate
|
|
|
+ item.Memo=n.Memo
|
|
|
+ item.Price=n.Price
|
|
|
+ item.CnyPrice=n.CnyPrice
|
|
|
+ item.ZsyPrice=n.ZsyPrice
|
|
|
+ item.ZshPrice=n.ZshPrice
|
|
|
+ item.LowPrice=n.LowPrice
|
|
|
+ item.HighPrice=n.HighPrice
|
|
|
+ item.RisePrice=n.RisePrice
|
|
|
+ item.TonPrice=n.TonPrice
|
|
|
+ item.PriceType=n.PriceType
|
|
|
+ item.UpdateDate=n.UpdateDate
|
|
|
+ _, err = models.AddLongzhongpricedata(item)
|
|
|
+ if err != nil {
|
|
|
+ msg = "新增隆众价格数据失败:err " + err.Error()
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
return
|
|
|
}
|