|
@@ -655,6 +655,7 @@ func GetLzProductPriceProduct() (err error) {
|
|
|
}
|
|
|
fmt.Println("getUrl:", getUrl)
|
|
|
fmt.Println("body", string(body))
|
|
|
+ utils.FileLog.Info("%s", string(body))
|
|
|
infoList := new(models.LzPriceInfoResp)
|
|
|
err = json.Unmarshal(body, &infoList)
|
|
|
if err != nil {
|
|
@@ -711,16 +712,18 @@ func GetLzProductPriceData() (err error) {
|
|
|
}
|
|
|
}()
|
|
|
|
|
|
- priceInfoList,err:=models.GetLongzhongpriceinfo()
|
|
|
- if err!=nil {
|
|
|
- msg="获取价格指标失败,Err:"+err.Error()
|
|
|
+ priceInfoList, err := models.GetLongzhongpriceinfo()
|
|
|
+ if err != nil {
|
|
|
+ msg = "获取价格指标失败,Err:" + err.Error()
|
|
|
return
|
|
|
}
|
|
|
username := "hzmd"
|
|
|
password := "HZMD2020"
|
|
|
+ startDate := time.Now().AddDate(0, 0, 0).Format(utils.FormatDate)
|
|
|
+ endDate := time.Now().AddDate(0, 0, 0).Format(utils.FormatDate)
|
|
|
for k, v := range priceInfoList {
|
|
|
fmt.Println(k, v)
|
|
|
- getUrl := `https://openapi.oilchem.net/price/getPrice?password=` + password + `&type=` + v.InfoType + `&username=` + username + `&inStartDate=2020-01-01&inEndDate=2020-12-31&id=`+v.PriceId
|
|
|
+ getUrl := `https://openapi.oilchem.net/price/getPrice?password=` + password + `&type=` + v.InfoType + `&username=` + username + `&inStartDate=` + startDate + `&inEndDate=` + endDate + `&id=` + v.PriceId
|
|
|
body, err := http.Get(getUrl)
|
|
|
if err != nil {
|
|
|
msg = "获取隆众价格数据失败:Err" + err.Error()
|
|
@@ -748,19 +751,19 @@ func GetLzProductPriceData() (err error) {
|
|
|
fmt.Println("存在", n.PriceDate, n.Id)
|
|
|
} else {
|
|
|
item := new(models.Longzhongpricedata)
|
|
|
- item.LongzhongpriceinfoId=v.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
|
|
|
+ item.LongzhongpriceinfoId = v.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()
|
|
@@ -770,4 +773,154 @@ func GetLzProductPriceData() (err error) {
|
|
|
}
|
|
|
}
|
|
|
return
|
|
|
-}
|
|
|
+}
|
|
|
+
|
|
|
+func LzPriceExportExcel() {
|
|
|
+ var err error
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("err:" + err.Error())
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ classifyList, err := models.GetLzPriceClassify()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ xlsxFile := xlsx.NewFile()
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("生成文件失败" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ dir, _ := os.Executable()
|
|
|
+ exPath := filepath.Dir(dir)
|
|
|
+ downLoadnFilePath := exPath + "/static/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
|
|
|
+ fmt.Println("downLoadnFilePath")
|
|
|
+ fmt.Println(downLoadnFilePath)
|
|
|
+ for _, v := range classifyList {
|
|
|
+ fmt.Println(v.ProductName)
|
|
|
+ //获取指标
|
|
|
+ secNameList, err := models.GetLongzhongpriceinfoByClassifyName(v.ProductName)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("获取数据失败,Err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(secNameList) <= 0 {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ sheetNew, err := xlsxFile.AddSheet(v.ProductName)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("新增Sheet失败", err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //获取指标数据
|
|
|
+ windRow := sheetNew.AddRow()
|
|
|
+ secNameRow := sheetNew.AddRow()
|
|
|
+ frequencyRow := sheetNew.AddRow()
|
|
|
+ unitRow := sheetNew.AddRow()
|
|
|
+ lastModifyDateRow := sheetNew.AddRow()
|
|
|
+ titleRow := sheetNew.AddRow()
|
|
|
+ //获取分类下指标最大数据量
|
|
|
+ dataMax, err := models.GetLongzhongPriceDataMaxCount(v.ProductName)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("获取指标最大数据量失败", err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, sv := range secNameList {
|
|
|
+ fmt.Println("line 399:", v.ProductName, sv.InfoTypeRemark, sv.AreaName)
|
|
|
+
|
|
|
+ windRow.AddCell().SetString("Wind")
|
|
|
+ secNameRow.AddCell().SetValue("分类")
|
|
|
+ frequencyRow.AddCell().SetValue("价格类型")
|
|
|
+ unitRow.AddCell().SetValue("单位")
|
|
|
+ lastModifyDateRow.AddCell().SetValue("地区")
|
|
|
+
|
|
|
+ secNameRow.AddCell().SetValue(sv.InfoTypeRemark)
|
|
|
+ frequencyRow.AddCell().SetValue(sv.PriceType)
|
|
|
+ unitRow.AddCell().SetValue(sv.Unit)
|
|
|
+ lastModifyDateRow.AddCell().SetValue(sv.AreaName)
|
|
|
+
|
|
|
+ windRow.AddCell()
|
|
|
+ windRow.AddCell()
|
|
|
+ windRow.AddCell()
|
|
|
+ windRow.AddCell()
|
|
|
+
|
|
|
+ secNameRow.AddCell()
|
|
|
+ frequencyRow.AddCell()
|
|
|
+ unitRow.AddCell()
|
|
|
+ lastModifyDateRow.AddCell()
|
|
|
+ secNameRow.AddCell()
|
|
|
+ frequencyRow.AddCell()
|
|
|
+ unitRow.AddCell()
|
|
|
+ lastModifyDateRow.AddCell()
|
|
|
+ secNameRow.AddCell()
|
|
|
+ frequencyRow.AddCell()
|
|
|
+ unitRow.AddCell()
|
|
|
+ lastModifyDateRow.AddCell()
|
|
|
+ titleRow.AddCell().SetValue("价格日期")
|
|
|
+ titleRow.AddCell().SetValue("价格")
|
|
|
+ titleRow.AddCell().SetValue("低端价格")
|
|
|
+ titleRow.AddCell().SetValue("高端价格")
|
|
|
+ titleRow.AddCell()
|
|
|
+ //获取数据
|
|
|
+ dataList, err := models.GetLongzhongPriceDataById(sv.LongzhongpriceinfoId)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("GetLongzhongDataById Err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(dataList) <= 0 {
|
|
|
+ for n := 0; n < dataMax; n++ {
|
|
|
+ rowIndex := 6 + n
|
|
|
+ row, err := sheetNew.Row(rowIndex)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("add row err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ row.AddCell()
|
|
|
+ row.AddCell()
|
|
|
+ row.AddCell()
|
|
|
+ row.AddCell()
|
|
|
+ row.AddCell()
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ endRowIndex := 0
|
|
|
+ for rk, dv := range dataList {
|
|
|
+ rowIndex := 6 + rk
|
|
|
+ row, err := sheetNew.Row(rowIndex)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("add row err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ row.AddCell().SetValue(dv.PriceDate)
|
|
|
+ row.AddCell().SetFloat(dv.Price)
|
|
|
+ row.AddCell().SetFloat(dv.LowPrice)
|
|
|
+ row.AddCell().SetFloat(dv.HighPrice)
|
|
|
+
|
|
|
+ row.AddCell()
|
|
|
+ endRowIndex = rowIndex
|
|
|
+ }
|
|
|
+ if len(dataList) < dataMax {
|
|
|
+ dataLen := dataMax - len(dataList)
|
|
|
+ for n := 0; n < dataLen; n++ {
|
|
|
+ rowIndex := (endRowIndex + 1) + n
|
|
|
+ row, err := sheetNew.Row(rowIndex)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("add row err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ row.AddCell()
|
|
|
+ row.AddCell()
|
|
|
+ row.AddCell()
|
|
|
+ row.AddCell()
|
|
|
+ row.AddCell()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ err = xlsxFile.Save(downLoadnFilePath)
|
|
|
+ fmt.Print("downLoadnFilePath:", downLoadnFilePath)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+}
|