浏览代码

修改指标数量对不上bug

xyxie 1 年之前
父节点
当前提交
6d44184f5d

+ 32 - 7
services/base_from_yongyi.go

@@ -177,8 +177,8 @@ func YongyiDownloadDaily(cont context.Context) (err error) {
 		now = now.AddDate(0, 0, -offset)
 	}
 
-	filePath := fmt.Sprintf("%s/%s%s", utils.YongyiReadFilePath, now.Format("2006年1月2日"), "涌益咨询日度数据.xlsx")
-
+	filePath := fmt.Sprintf("%s%s", now.Format("2006年1月2日"), "涌益咨询日度数据.xlsx")
+	filePath = filepath.Join(utils.YongyiReadFilePath, filePath)
 	fmt.Println("YongyiDownloadDaily: " + filePath)
 	_, e := os.Stat(filePath)
 	if e == nil { //文件或者目录存在
@@ -217,19 +217,40 @@ func YongyiDownloadWeekyly(cont context.Context) (err error) {
 	fmt.Printf("endDate: %s\n", endDate)
 	dataFileExsit := false
 	chartFileExist := false
-	filePath := fmt.Sprintf("%s/%s-%s%s", utils.YongyiReadFilePath, startDate, endDate, "涌益咨询 周度数据.xlsx")
+	filePath := fmt.Sprintf("%s-%s%s", startDate, endDate, "涌益咨询 周度数据.xlsx")
+	filePath = filepath.Join(utils.YongyiReadFilePath, filePath)
+
 	fmt.Println("YongyiDownloadWeekyly: " + filePath)
 
 	// 从已处理的表格中查询是否已存在,如果已存在,也无需下载
 	_, e := os.Stat(filePath)
 	if e == nil { //文件或者目录存在
 		dataFileExsit = true
+	} else if os.IsNotExist(e) { //文件或者目录不存在
+		filePath = filepath.Join(utils.YongyiFilePath, filePath)
+
+		fmt.Println("YongyiDownloadWeekyly: " + filePath)
+
+		// 从已处理的表格中查询是否已存在,如果已存在,也无需下载
+		_, e = os.Stat(filePath)
+		if e == nil { //文件或者目录存在
+			dataFileExsit = true
+		}
 	}
-	filePath = fmt.Sprintf("%s/%s-%s%s", utils.YongyiReadFilePath, startDate, endDate, "周度图表版图.xlsx")
+	filePath = fmt.Sprintf("%s-%s%s", utils.YongyiReadFilePath, startDate, endDate, "周度图表版图.xlsx")
+	filePath = filepath.Join(utils.YongyiReadFilePath, filePath)
 	fmt.Println("YongyiDownloadWeekyly: " + filePath)
 	_, e = os.Stat(filePath)
 	if e == nil { //文件或者目录存在
 		chartFileExist = true
+	} else if os.IsNotExist(e) { //文件或者目录不存在
+		filePath = filepath.Join(utils.YongyiFilePath, filePath)
+		fmt.Println("YongyiDownloadWeekyly: " + filePath)
+		// 从已处理的表格中查询是否已存在,如果已存在,也无需下载
+		_, e = os.Stat(filePath)
+		if e == nil { //文件或者目录存在
+			chartFileExist = true
+		}
 	}
 
 	if dataFileExsit && chartFileExist {
@@ -296,7 +317,7 @@ func ReadWatchYongyiFile(cont context.Context) (err error) {
 			}
 		}
 		if err != nil {
-			err = fmt.Errorf("handlerYongyi err: %s", err.Error())
+			err = fmt.Errorf("file name: %s, handlerYongyi err: %s", path, err.Error())
 			return err
 		}
 
@@ -403,9 +424,10 @@ func HandleYongyiExcelDailyV2(filePath string) (err error) {
 		if !ok {
 			continue // 如果没有,则跳过当前sheet
 		}
-
+		utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelDailyV2 %s start", sheetName))
 		// 调用处理函数,并处理可能发生的错误
 		indexList, e := handler(f, sheetName)
+		utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelDailyV2 %s end", sheetName))
 		if e != nil {
 			utils.FileLog.Info(fmt.Sprintf("解析sheet:%s 失败, Err: %s", sheetName, err))
 			continue
@@ -463,7 +485,9 @@ func HandleYongyiExcelWeeklyV2(filePath string) (err error) {
 		}
 
 		// 调用处理函数,并处理可能发生的错误
+		utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeeklyV2 %s start", sheetName))
 		indexList, e := handler(f, sheetName)
+		utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeeklyV2 %s end", sheetName))
 		if e != nil {
 			utils.FileLog.Info(fmt.Sprintf("解析sheet:%s 失败, Err: %s", sheetName, err))
 			continue
@@ -519,9 +543,10 @@ func HandleYongyiExcelWeeklyChart(filePath string) (err error) {
 		if !ok {
 			continue // 如果没有,则跳过当前sheet
 		}
-
+		utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeeklyChart %s start", sheetName))
 		// 调用处理函数,并处理可能发生的错误
 		indexList, e := handler(f, sheetName)
+		utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeeklyChart %s end", sheetName))
 		if e != nil {
 			utils.FileLog.Info(fmt.Sprintf("解析sheet:%s 失败, Err: %s", sheetName, err))
 			continue

+ 1 - 1
services/base_from_yongyi_v2/base.go

@@ -116,7 +116,7 @@ func init() {
 		"育肥全价料出厂价":             {"育肥全价料出厂均价参考", "育肥全价料出厂价", "周度", "元/吨"},
 		"周度-成本计算附件":            {"", "周度-成本计算附件", "周度", "元/头"}, //多个单位:元/头,%,kg,元
 		"周度-毛白价差":              {"毛白价差", "周度-毛白价差", "周度", "元/公斤"},
-		"仔猪、母猪":                {"仔猪价", "仔猪、母猪", "周度", "元/头"},             //多个前缀,仔猪价,二元母猪价
+		"仔猪、母猪":                {"", "仔猪、母猪", "周度", "元/头"},                //多个前缀,仔猪价,二元母猪价
 		"周度-河南屠宰白条成本":          {"河南屠宰白条成本", "周度-河南屠宰白条成本", "周度", "元/kg"}, //多个单位:kg,元/kg,元/头
 		"周度-淘汰母猪价格":            {"淘汰母猪价格", "周度-淘汰母猪价格", "周度", "元/斤"},
 		"鲜销率":                  {"鲜销率", "鲜销率", "周度", "%"},

+ 2 - 2
services/base_from_yongyi_v2/chartWeek.go

@@ -73,7 +73,7 @@ func HandleYongyiExcelWeekly36(f *excelize.File, sheetName string) (indexList []
 					}
 					_, e := strconv.ParseFloat(text, 64)
 					if e != nil {
-						utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 strconv.ParseFloat Err:%s", sheetName, i, k, e))
+						//utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 strconv.ParseFloat Err:%s", sheetName, i, k, e))
 						continue
 					}
 				}
@@ -84,7 +84,7 @@ func HandleYongyiExcelWeekly36(f *excelize.File, sheetName string) (indexList []
 					return
 				}
 				fmt.Printf("当前第%d行第%d列, 当前省份%s \n", i, k, name)
-				if strings.Contains(name, "时间") || name == "肉产量(吨)" || name == "肉产量(万吨)" {
+				if strings.Contains(name, "时间") || name == "肉产量(吨)" || name == "肉产量(万吨)" || name == "断奶仔猪量" {
 					continue
 				}
 				switch {

+ 1 - 0
services/base_from_yongyi_v2/week10.go

@@ -118,6 +118,7 @@ func HandleYongyiExcelWeekly1(f *excelize.File, sheetName string) (indexList []*
 				if province == "全  国1" || province == "全  国2" || province == "全国1" || province == "全国2" {
 					province = strings.ReplaceAll(province, " ", "")
 					fullIndexName = fmt.Sprintf("%s/%s", namePrefix, province)
+					provincePingyin = utils.GetFullPingYin(province)
 					fullIndexNamePingyin = namePrefixPingin + provincePingyin
 				}
 

+ 6 - 2
services/base_from_yongyi_v2/week20.go

@@ -67,6 +67,9 @@ func HandleYongyiExcelWeekly11(f *excelize.File, sheetName string) (indexList []
 					fmt.Println(date)
 					continue
 				} else {
+					if i <= 6 {
+						continue
+					}
 					if text == "" {
 						continue
 					}
@@ -243,7 +246,7 @@ func HandleYongyiExcelWeekly13(f *excelize.File, sheetName string) (indexList []
 	}
 
 	// 获取指标分类
-	classifyName, classifySort, frequency, _, _, _ := GetBaseInfo(sheetName)
+	classifyName, classifySort, frequency, _, _, namePrefixPingin := GetBaseInfo(sheetName)
 	// 遍历行读取
 	indexList = make([]*models.YongyiExcelIndex, 0)
 	nameMap := make(map[int]string)
@@ -375,7 +378,7 @@ func HandleYongyiExcelWeekly13(f *excelize.File, sheetName string) (indexList []
 				}
 				// 处理指标名称
 				fullIndexName := finalName
-				fullIndexNamePingyin := utils.GetFullPingYin(fullIndexName)
+				fullIndexNamePingyin := namePrefixPingin + utils.GetFirstPingYin(fullIndexName)
 
 				indexItem, okIndex := indexMap[fullIndexName]
 				if !okIndex {
@@ -960,6 +963,7 @@ func HandleYongyiExcelWeekly18(f *excelize.File, sheetName string) (indexList []
 				if province == "均价" {
 					province = "全国均价"
 					fullIndexName = fmt.Sprintf("%s/%s", namePrefix, province)
+					provincePingyin = utils.GetFirstPingYin(province)
 					fullIndexNamePingyin = namePrefixPingin + provincePingyin
 				}
 				indexItem, okIndex := indexMap[fullIndexName]

+ 9 - 8
services/base_from_yongyi_v2/week30.go

@@ -26,7 +26,7 @@ func HandleYongyiExcelWeekly21(f *excelize.File, sheetName string) (indexList []
 	}
 
 	// 获取指标分类
-	classifyName, classifySort, frequency, unit, namePrefix, namePrefixPingin := GetBaseInfo(sheetName)
+	classifyName, classifySort, frequency, unit, _, namePrefixPingin := GetBaseInfo(sheetName)
 	// 遍历行读取
 	indexList = make([]*models.YongyiExcelIndex, 0)
 	provinceMap := make(map[int]string)
@@ -87,15 +87,13 @@ func HandleYongyiExcelWeekly21(f *excelize.File, sheetName string) (indexList []
 					err = fmt.Errorf("找不到对应的列名,第%d行,第%d列", i, k)
 					return
 				}
-				if strings.Contains(name, "二元母猪价") {
-					continue
-				}
+
 				fmt.Printf("当前第%d行第%d列, 当前省份%s \n", i, k, province)
 				// 处理指标名称
-				fullIndexName := fmt.Sprintf("%s/%s/%s", namePrefix, name, province)
+				fullIndexName := fmt.Sprintf("%s/%s/%s", "仔猪价", name, province)
 				provincePingyin := utils.GetFullPingYin(province)
 				namePingin := utils.GetFirstPingYin(name)
-				fullIndexNamePingyin := namePrefixPingin + namePingin + provincePingyin
+				fullIndexNamePingyin := namePrefixPingin + utils.GetFirstPingYin("仔猪价") + namePingin + provincePingyin
 				if strings.Contains(name, "二元母猪价") {
 					fullIndexName = fmt.Sprintf("%s/%s", name, province)
 					fullIndexNamePingyin = "yyzx" + namePingin + provincePingyin
@@ -200,12 +198,15 @@ func HandleYongyiExcelWeekly22(f *excelize.File, sheetName string) (indexList []
 					err = fmt.Errorf("找不到对应的列名,第%d行,第%d列", i, k)
 					return
 				}
-				nameSlice := strings.Split(name, "\n")
-				nameSlice = strings.Split(name, "(")
+				nameSlice := strings.Split(name, "(")
 				unitNew := unit
 				if len(nameSlice) > 1 {
 					name = nameSlice[0]
 				}
+				nameSlice = strings.Split(name, "\n")
+				if len(nameSlice) > 1 {
+					name = nameSlice[0]
+				}
 				switch name {
 				case "生猪重量", "净白条重":
 					unitNew = "kg"

+ 4 - 1
services/base_from_yongyi_v2/week40.go

@@ -230,7 +230,10 @@ func HandleYongyiExcelWeekly32(f *excelize.File, sheetName string) (indexList []
 					continue
 				}
 				fmt.Printf("当前第%d行第%d列, 当前省份%s \n", i, k, name)
-
+				unit = "头"
+				if strings.Contains(name, "率") {
+					unit = "%"
+				}
 				fullIndexName := fmt.Sprintf("%s/%s/%s", namePrefix, province, name)
 				provincePingyin := utils.GetFullPingYin(province)
 				namePingin := utils.GetFirstPingYin(name)