rdluck 4 years ago
parent
commit
1248577cf5
3 changed files with 33 additions and 55 deletions
  1. 21 21
      models/data_source_longzhong.go
  2. 11 33
      services/data_source_longzhong.go
  3. 1 1
      services/task.go

+ 21 - 21
models/data_source_longzhong.go

@@ -266,11 +266,11 @@ func GetLongzhongpriceinfoCount(unitid string) (count int, err error) {
 }
 
 //判断指标数据是否已经录入
-func GetLongzhongpriceinfoByPriceId(unitid string) (item *Longzhongpriceinfo, err error) {
+func GetLongzhongpriceinfo() (items []*Longzhongpriceinfo, err error) {
 	o := orm.NewOrm()
 	o.Using("edb")
-	sql := `SELECT * FROM longzhongpriceinfo WHERE price_id=? `
-	err = o.Raw(sql, unitid).QueryRow(&item)
+	sql := `SELECT * FROM longzhongpriceinfo `
+	err = o.Raw(sql).QueryRow(&items)
 	return
 }
 
@@ -279,15 +279,15 @@ type Longzhongpricedata struct {
 	LongzhongpriceinfoId int
 	PriceDate            string
 	Memo                 string
-	Price                float64
-	CnyPrice             float64
-	ZsyPrice             float64
-	ZshPrice             float64
-	LowPrice             float64
-	HighPrice            float64
-	RisePrice            float64
-	TonPrice             float64
-	PriceType            float64
+	Price                string
+	CnyPrice             string
+	ZsyPrice             string
+	ZshPrice             string
+	LowPrice             string
+	HighPrice            string
+	RisePrice            string
+	TonPrice             string
+	PriceType            string
 	UpdateDate           string
 }
 
@@ -311,15 +311,15 @@ type LzPriceData struct {
 	Id         string  `json:"id"`
 	PriceDate  string  `json:"priceDate"`
 	Memo       string  `json:"memo"`
-	Price      float64 `json:"price"`
-	CnyPrice   float64 `json:"cnyPrice"`
-	ZsyPrice   float64 `json:"zsyPrice"`
-	ZshPrice   float64 `json:"zshPrice"`
-	LowPrice   float64 `json:"lowPrice"`
-	HighPrice  float64 `json:"highPrice"`
-	RisePrice  float64 `json:"risePrice"`
-	TonPrice   float64 `json:"tonPrice"`
-	PriceType  float64 `json:"priceType"`
+	Price      string `json:"price"`
+	CnyPrice   string `json:"cnyPrice"`
+	ZsyPrice   string `json:"zsyPrice"`
+	ZshPrice   string `json:"zshPrice"`
+	LowPrice   string `json:"lowPrice"`
+	HighPrice  string `json:"highPrice"`
+	RisePrice  string `json:"risePrice"`
+	TonPrice   string `json:"tonPrice"`
+	PriceType  string `json:"priceType"`
 	UpdateDate string  `json:"updateDate"`
 }
 

+ 11 - 33
services/data_source_longzhong.go

@@ -227,8 +227,8 @@ func GetLzProductDetail() (err error) {
 		}
 	}()
 
-	startDate := "2020-09-01" //time.Now().AddDate(0, 0, 0).Format(utils.FormatDate)
-	endDate := "2020-09-04"   //time.Now().AddDate(0, 0, 0).Format(utils.FormatDate)
+	startDate := time.Now().AddDate(0, 0, 0).Format(utils.FormatDate)
+	endDate := time.Now().AddDate(0, 0, 0).Format(utils.FormatDate)
 	time.Sleep(5 * time.Second)
 	pageSize := 30
 
@@ -711,20 +711,16 @@ func GetLzProductPriceData() (err error) {
 		}
 	}()
 
-	//chuchang, guonei, guoji, oil ,lingshou,guojioil,base,国内出厂,国内市场,国际市场,国内成品油批发价,国内成品油零售价,国际原油,基准价
-	typeMap := make(map[string]string)
-	//typeMap["chuchang"] = "国内出厂"
-	typeMap["guonei"] = "国内市场"
-	//typeMap["guoji"] = "国际市场"
-	//typeMap["oil"] = "国内成品油批发价"
-	//typeMap["lingshou"] = "国内成品油零售价"
-	//typeMap["guojioil"] = "国际原油"
-	//typeMap["base"] = "基准价"
+	priceInfoList,err:=models.GetLongzhongpriceinfo()
+	if err!=nil {
+		msg="获取价格指标失败,Err:"+err.Error()
+		return
+	}
 	username := "hzmd"
 	password := "HZMD2020"
-	for k, v := range typeMap {
+	for k, v := range priceInfoList {
 		fmt.Println(k, v)
-		getUrl := `https://openapi.oilchem.net/price/getPrice?password=` + password + `&type=` + k + `&username=` + username + `&inStartDate=2020-08-01&inEndDate=2020-08-07`
+		getUrl := `https://openapi.oilchem.net/price/getPrice?password=` + password + `&type=` + v.PriceId + `&username=` + username + `&inStartDate=2020-08-01&inEndDate=2020-08-07`
 		body, err := http.Get(getUrl)
 		if err != nil {
 			msg = "获取隆众价格数据失败:Err" + err.Error()
@@ -743,23 +739,6 @@ func GetLzProductPriceData() (err error) {
 			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 err
-				} else {
-					fmt.Println("获取指标失败:id:" + n.Id)
-					msg = "获取指标失败:id:" + n.Id
-					return err
-				}
-			}
-			if infoItem == nil {
-				fmt.Println("指标不存在:id:" + n.Id)
-				msg = "指标不存在:id:" + n.Id
-				return nil
-			}
 			count, err := models.GetLongzhongpricedataCount(n.Id, n.PriceDate)
 			if err != nil {
 				msg = "获取隆众价格数据失败:err " + err.Error()
@@ -769,7 +748,7 @@ func GetLzProductPriceData() (err error) {
 				fmt.Println("存在", n.PriceDate, n.Id)
 			} else {
 				item := new(models.Longzhongpricedata)
-				item.LongzhongpriceinfoId=infoItem.LongzhongpriceinfoId
+				item.LongzhongpriceinfoId=v.LongzhongpriceinfoId
 				item.PriceDate=n.PriceDate
 				item.Memo=n.Memo
 				item.Price=n.Price
@@ -789,7 +768,6 @@ func GetLzProductPriceData() (err error) {
 				}
 			}
 		}
-
 	}
 	return
-}
+}

+ 1 - 1
services/task.go

@@ -26,7 +26,7 @@ func Task123() {
 	//GetLzPrice()
 	//GetLzProductDetail()
 	//LzExportExcel()
-	//GetLzProductList()
+	//GetLzProductList()GetLzProductDetail
 	fmt.Println("task end")
 }