Browse Source

Merge branch 'bzq/yongyi_new_data_cf' of eta_server/eta_data_analysis into master

鲍自强 6 months ago
parent
commit
f194e1ee9f

+ 63 - 48
services/base_from_yongyi.go

@@ -7,7 +7,6 @@ import (
 	"eta/eta_data_analysis/services/base_from_yongyi_v2"
 	"eta/eta_data_analysis/utils"
 	"fmt"
-	"github.com/xuri/excelize/v2"
 	"io/fs"
 	"os"
 	"path"
@@ -15,6 +14,8 @@ import (
 	"strings"
 	"sync"
 	"time"
+
+	"github.com/xuri/excelize/v2"
 )
 
 /*
@@ -237,8 +238,8 @@ func YongyiDownloadWeekyly(cont context.Context) (err error) {
 			dataFileExsit = true
 		}
 	}
-	fileName = fmt.Sprintf("%s-%s%s", startDate, endDate, "周度图表版图.xlsx")
-	filePath = filepath.Join(utils.YongyiReadFilePath, fileName)
+	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 { //文件或者目录存在
@@ -343,55 +344,69 @@ func ReadWatchYongyiFile(cont context.Context) (err error) {
 }
 
 var YongyiDailyHandlers = map[string]func(f *excelize.File, sheetName string) ([]*models.YongyiExcelIndex, error){
-	"出栏价":             base_from_yongyi_v2.HandleYongyiExcelDaily1,
-	"标肥价差":           base_from_yongyi_v2.HandleYongyiExcelDaily2,
-	"价格+宰量":          base_from_yongyi_v2.HandleYongyiExcelDaily3,
+	"出栏价":       base_from_yongyi_v2.HandleYongyiExcelDaily1,
+	"标肥价差":      base_from_yongyi_v2.HandleYongyiExcelDaily2,
+	"价格+宰量":     base_from_yongyi_v2.HandleYongyiExcelDaily3,
 	"屠宰企业日度屠宰量": base_from_yongyi_v2.HandleYongyiExcelDaily4,
 }
 
 var YongyiWeeklyHandlers = map[string]func(f *excelize.File, sheetName string) ([]*models.YongyiExcelIndex, error){
-	"周度-商品猪出栏价":                     base_from_yongyi_v2.HandleYongyiExcelWeekly1,
-	"周度-体重":                             base_from_yongyi_v2.HandleYongyiExcelWeekly2,
-	"周度-屠宰厂宰前活猪重":                 base_from_yongyi_v2.HandleYongyiExcelWeekly3,
-	"周度-各体重段价差":                     base_from_yongyi_v2.HandleYongyiExcelWeekly4,
-	"周度-50公斤二元母猪价格":               base_from_yongyi_v2.HandleYongyiExcelWeekly5,
-	"周度-规模场15公斤仔猪出栏价":           base_from_yongyi_v2.HandleYongyiExcelWeekly5,
-	"周度-宰后结算价":                       base_from_yongyi_v2.HandleYongyiExcelWeekly5,
-	"周度-冻品库存":                         base_from_yongyi_v2.HandleYongyiExcelWeekly5,
-	"周度-猪肉价(前三等级白条均价)":         base_from_yongyi_v2.HandleYongyiExcelWeekly5,
-	"周度-冻品库存多样本":                   base_from_yongyi_v2.HandleYongyiExcelWeekly6,
-	"月度出栏完成率":                        base_from_yongyi_v2.HandleYongyiExcelWeekly6,
-	"月度计划出栏量":                        base_from_yongyi_v2.HandleYongyiExcelWeekly7,
-	"月度-能繁母猪存栏(2020年2月新增)":      base_from_yongyi_v2.HandleYongyiExcelWeekly8,
-	"月度-小猪存栏(2020年5月新增)":          base_from_yongyi_v2.HandleYongyiExcelWeekly9,
-	"月度-中猪存栏(2020年5月新增)":          base_from_yongyi_v2.HandleYongyiExcelWeekly9,
-	"月度-大猪存栏(2020年5月新增)":          base_from_yongyi_v2.HandleYongyiExcelWeekly9,
-	"月度-商品猪出栏量":                     base_from_yongyi_v2.HandleYongyiExcelWeekly10,
-	"历史猪价":                              base_from_yongyi_v2.HandleYongyiExcelWeekly12,
-	"二育成本":                              base_from_yongyi_v2.HandleYongyiExcelWeekly13,
-	"二育销量":                              base_from_yongyi_v2.HandleYongyiExcelWeekly14,
-	"育肥栏舍利用率":                        base_from_yongyi_v2.HandleYongyiExcelWeekly15,
-	"周度-养殖利润最新":                     base_from_yongyi_v2.HandleYongyiExcelWeekly16,
-	"周度-当期、预期成本":                    base_from_yongyi_v2.HandleYongyiExcelWeekly17,
-	"育肥全价料出厂价":                      base_from_yongyi_v2.HandleYongyiExcelWeekly18,
-	"周度-成本计算附件":                     base_from_yongyi_v2.HandleYongyiExcelWeekly19,
-	"周度-毛白价差":                         base_from_yongyi_v2.HandleYongyiExcelWeekly20,
-	"仔猪、母猪":                             base_from_yongyi_v2.HandleYongyiExcelWeekly21,
-	"周度-河南屠宰白条成本":                 base_from_yongyi_v2.HandleYongyiExcelWeekly22,
-	"周度-淘汰母猪价格":                     base_from_yongyi_v2.HandleYongyiExcelWeekly23, //todo 少两个指标,云南和贵州,数据都不符合规范
-	"鲜销率":                                base_from_yongyi_v2.HandleYongyiExcelWeekly24, //todo 等待解析(正月初六-二月初四)2022.2.6-3.6
-	"周度-猪肉产品价格":                     base_from_yongyi_v2.HandleYongyiExcelWeekly25,
-	"周度-屠宰企业日度屠宰量":               base_from_yongyi_v2.HandleYongyiExcelWeekly26,
-	"周度-屠宰新2022.10.28":                 base_from_yongyi_v2.HandleYongyiExcelWeekly27,
-	"月度-淘汰母猪屠宰厂宰杀量":             base_from_yongyi_v2.HandleYongyiExcelWeekly28,
-	"月度-猪料销量":                         base_from_yongyi_v2.HandleYongyiExcelWeekly29,
-	"月度-屠宰企业开工率":                   base_from_yongyi_v2.HandleYongyiExcelWeekly30,
-	"月度-屠宰厂公母比例":                   base_from_yongyi_v2.HandleYongyiExcelWeekly31,
-	"月度-生产指标(2021.5.7新增)":           base_from_yongyi_v2.HandleYongyiExcelWeekly32,
-	"月度-生产指标2":                        base_from_yongyi_v2.HandleYongyiExcelWeekly33,
-	"月度-二元三元能繁比例":                 base_from_yongyi_v2.HandleYongyiExcelWeekly34, //todo 2019年1-6月
-	"月度-能繁母猪存栏量":                   base_from_yongyi_v2.HandleYongyiExcelWeekly35,
-	"月度-原种场二元后备母猪销量及出栏日龄": base_from_yongyi_v2.HandleYongyiExcelWeekly11,
+	"周度-商品猪出栏价":            base_from_yongyi_v2.HandleYongyiExcelWeekly1,
+	"周度-体重":                base_from_yongyi_v2.HandleYongyiExcelWeekly2,
+	"周度-屠宰厂宰前活猪重":          base_from_yongyi_v2.HandleYongyiExcelWeekly3,
+	"周度-各体重段价差":            base_from_yongyi_v2.HandleYongyiExcelWeekly4,
+	"周度-50公斤二元母猪价格":        base_from_yongyi_v2.HandleYongyiExcelWeekly5,
+	"周度-规模场15公斤仔猪出栏价":      base_from_yongyi_v2.HandleYongyiExcelWeekly5,
+	"周度-宰后结算价":             base_from_yongyi_v2.HandleYongyiExcelWeekly5,
+	"周度-冻品库存":              base_from_yongyi_v2.HandleYongyiExcelWeekly5,
+	"周度-猪肉价(前三等级白条均价)":     base_from_yongyi_v2.HandleYongyiExcelWeekly5,
+	"周度-冻品库存多样本":           base_from_yongyi_v2.HandleYongyiExcelWeekly6,
+	"月度出栏完成率":              base_from_yongyi_v2.HandleYongyiExcelWeekly6,
+	"月度计划出栏量":              base_from_yongyi_v2.HandleYongyiExcelWeekly7,
+	"月度-能繁母猪存栏(2020年2月新增)": base_from_yongyi_v2.HandleYongyiExcelWeekly8,
+	"月度-小猪存栏(2020年5月新增)":   base_from_yongyi_v2.HandleYongyiExcelWeekly9,
+	"月度-中猪存栏(2020年5月新增)":   base_from_yongyi_v2.HandleYongyiExcelWeekly9,
+	"月度-大猪存栏(2020年5月新增)":   base_from_yongyi_v2.HandleYongyiExcelWeekly9,
+	"月度-商品猪出栏量":            base_from_yongyi_v2.HandleYongyiExcelWeekly10,
+	"历史猪价":                 base_from_yongyi_v2.HandleYongyiExcelWeekly12,
+	"二育成本":                 base_from_yongyi_v2.HandleYongyiExcelWeekly13,
+	"二育销量":                 base_from_yongyi_v2.HandleYongyiExcelWeekly14,
+	"育肥栏舍利用率":              base_from_yongyi_v2.HandleYongyiExcelWeekly15,
+	"周度-养殖利润最新":            base_from_yongyi_v2.HandleYongyiExcelWeekly16,
+	"周度-当期、预期成本":           base_from_yongyi_v2.HandleYongyiExcelWeekly17,
+	"育肥全价料出厂价":             base_from_yongyi_v2.HandleYongyiExcelWeekly18,
+	"周度-成本计算附件":            base_from_yongyi_v2.HandleYongyiExcelWeekly19,
+	"周度-毛白价差":              base_from_yongyi_v2.HandleYongyiExcelWeekly20,
+	"仔猪、母猪":                base_from_yongyi_v2.HandleYongyiExcelWeekly21,
+	"周度-河南屠宰白条成本":          base_from_yongyi_v2.HandleYongyiExcelWeekly22,
+	"周度-淘汰母猪价格":            base_from_yongyi_v2.HandleYongyiExcelWeekly23, //todo 少两个指标,云南和贵州,数据都不符合规范
+	"鲜销率":                  base_from_yongyi_v2.HandleYongyiExcelWeekly24, //todo 等待解析(正月初六-二月初四)2022.2.6-3.6
+	"周度-猪肉产品价格":            base_from_yongyi_v2.HandleYongyiExcelWeekly25,
+	"周度-屠宰企业日度屠宰量":         base_from_yongyi_v2.HandleYongyiExcelWeekly26,
+	"周度-屠宰新2022.10.28":     base_from_yongyi_v2.HandleYongyiExcelWeekly27,
+	"月度-淘汰母猪屠宰厂宰杀量":        base_from_yongyi_v2.HandleYongyiExcelWeekly28,
+	"月度-猪料销量":              base_from_yongyi_v2.HandleYongyiExcelWeekly29,
+	"月度-屠宰企业开工率":           base_from_yongyi_v2.HandleYongyiExcelWeekly30,
+	"月度-屠宰厂公母比例":           base_from_yongyi_v2.HandleYongyiExcelWeekly31,
+	"月度-生产指标(2021.5.7新增)":  base_from_yongyi_v2.HandleYongyiExcelWeekly32,
+	"月度-生产指标2":             base_from_yongyi_v2.HandleYongyiExcelWeekly33,
+	"月度-二元三元能繁比例":          base_from_yongyi_v2.HandleYongyiExcelWeekly34, //todo 2019年1-6月
+	"月度-能繁母猪存栏量":           base_from_yongyi_v2.HandleYongyiExcelWeekly35,
+	"月度-原种场二元后备母猪销量及出栏日龄":  base_from_yongyi_v2.HandleYongyiExcelWeekly11,
+	"周度-养殖利润":              base_from_yongyi_v2.HandleYongyiExcelWeekly37,
+	"华东冻品价格":               base_from_yongyi_v2.HandleYongyiExcelWeekly38,
+	"运费":                   base_from_yongyi_v2.HandleYongyiExcelWeekly39,
+	"国产冻品2-4号肉价格":          base_from_yongyi_v2.HandleYongyiExcelWeekly40,
+	"月度-小猪(50公斤以下)存栏":      base_from_yongyi_v2.HandleYongyiExcelWeekly41,
+	"月度-中猪(50-80公斤)存栏":     base_from_yongyi_v2.HandleYongyiExcelWeekly41,
+	"月度-大猪(80公斤以上)月度存栏":    base_from_yongyi_v2.HandleYongyiExcelWeekly41,
+	"月度猪肉供应占比":             base_from_yongyi_v2.HandleYongyiExcelWeekly42,
+	"历史出栏体重":               base_from_yongyi_v2.HandleYongyiExcelWeekly43,
+	"重要部位冻品进口":             base_from_yongyi_v2.HandleYongyiExcelWeekly44,
+	"各存栏规模":                base_from_yongyi_v2.HandleYongyiExcelWeekly45,
+	"进口肉":                  base_from_yongyi_v2.HandleYongyiExcelWeekly46,
+	"猪料原料占比":               base_from_yongyi_v2.HandleYongyiExcelWeekly47,
+	"MSY":                  base_from_yongyi_v2.HandleYongyiExcelWeekly48,
 }
 var YongyiWeeklyChartHandlers = map[string]func(f *excelize.File, sheetName string) ([]*models.YongyiExcelIndex, error){
 	"涌益样本测算": base_from_yongyi_v2.HandleYongyiExcelWeekly36,

+ 109 - 1
services/base_from_yongyi_v2/base.go

@@ -4,8 +4,12 @@ import (
 	"eta/eta_data_analysis/models"
 	"eta/eta_data_analysis/utils"
 	"fmt"
-	"github.com/xuri/excelize/v2"
+	"regexp"
+	"strconv"
 	"strings"
+	"time"
+
+	"github.com/xuri/excelize/v2"
 )
 
 func getClassifySortMap() map[string]int {
@@ -57,6 +61,20 @@ func getClassifySortMap() map[string]int {
 		"月度-能繁母猪存栏量":           45,
 		"月度-原种场二元后备母猪销量及出栏日龄":  46,
 		"涌益样本测算":               47,
+		"周度-养殖利润":              48,
+		"周度-华东冻品价格":            49,
+		"运费":                   50,
+		"国产冻品2-4号肉价格":          51,
+		"小猪(50公斤以下)存栏":         52,
+		"中猪(50-80公斤)存栏":        53,
+		"大猪(80公斤以上)月度存栏":       54,
+		"月度猪肉供应占比":             55,
+		"历史出栏体重":               56,
+		"重要部位冻品进口":             57,
+		"各存栏规模":                58,
+		"进口肉":                  59,
+		"猪料原料占比":               60,
+		"MSY":                  61,
 	}
 	return classifyMap
 }
@@ -133,6 +151,20 @@ func init() {
 		"月度-能繁母猪存栏量":           {"月度能繁母猪存栏量", "月度-能繁母猪存栏量", "月度", "头"},
 		"月度-原种场二元后备母猪销量及出栏日龄":  {"原种场二元后备母猪销量及出栏日龄", "月度-原种场二元后备母猪销量及出栏日龄", "月度", "头"},
 		"涌益样本测算":               {"涌益样本测算", "涌益样本测算", "月度", "窝"}, //多个单位:头,%,窝,公斤,元/公斤
+		"周度-养殖利润":              {"外购育肥", "周度-养殖利润", "周度", "元/头"},
+		"华东冻品价格":               {"华东冻品价格", "周度-华东冻品价格", "周度", "元/公斤"},
+		"运费":                   {"9.6米拉猪车主流运费", "运费", "周度", "元/公里"},
+		"国产冻品2-4号肉价格":          {"", "国产冻品2-4号肉价格", "月度", "元/吨"},
+		"月度-小猪(50公斤以下)存栏":      {"小猪(50公斤以下)月度存栏", "小猪(50公斤以下)存栏", "月度", "头"},
+		"月度-中猪(50-80公斤)存栏":     {"中猪(50-80公斤)月度存栏", "中猪(50-80公斤)存栏", "月度", "头"},
+		"月度-大猪(80公斤以上)月度存栏":    {"大猪(80公斤以上)月度存栏", "大猪(80公斤以上)月度存栏", "月度", "头"},
+		"月度猪肉供应占比":             {"月度猪肉供应占比", "月度猪肉供应占比", "月度", "%"},
+		"历史出栏体重":               {"商品猪历史出栏体重", "历史出栏体重", "周度", "公斤"},
+		"重要部位冻品进口":             {"重要部位冻品进口", "重要部位冻品进口", "月度", "-"},
+		"各存栏规模":                {"半年度各规模存栏", "各存栏规模", "半年度", "%"},
+		"进口肉":                  {"", "进口肉", "月度", ""},
+		"猪料原料占比":               {"猪料育肥全价料中各原料占比", "猪料原料占比", "月度", "%"},
+		"MSY":                  {"MSY", "MSY", "年度", "%"},
 	}
 }
 
@@ -238,3 +270,79 @@ func GetWeekly13IndexUnit(name string) string {
 	}
 	return name
 }
+
+func getSundayOfWeek(year int, week int) string {
+	t := time.Date(year, 1, 1, 0, 0, 0, 0, time.Local)
+	weekday := int(t.Weekday())
+	daysToFirstSunday := (7 - weekday) % 7
+	firstSunday := t.AddDate(0, 0, daysToFirstSunday)
+	daysToDesiredSunday := (week - 1) * 7
+	return firstSunday.AddDate(0, 0, daysToDesiredSunday).Format(utils.FormatDate)
+}
+
+func isValueValid(value string) bool {
+	if value == "" {
+		return false
+	}
+	re := regexp.MustCompile(`^-?(\d+(\.\d+)?|\.\d+)(%)?$`)
+	return re.MatchString(value)
+}
+
+func excelDateToTimeDateStr(excelDate int) string {
+	baseDate := time.Date(1899, 12, 30, 0, 0, 0, 0, time.UTC)
+	return baseDate.AddDate(0, 0, excelDate).Format(utils.FormatDate)
+}
+
+func getMergeCellValMap(f *excelize.File, sheetName string) (mergeIndexDataMap map[string]string, e error) {
+	mergeIndexDataMap = make(map[string]string)
+
+	merges, e := f.GetMergeCells(sheetName)
+	if e != nil {
+		return
+	}
+	for _, merge := range merges {
+		xmin, ymin, e := excelize.CellNameToCoordinates(merge.GetStartAxis())
+		if e != nil {
+			continue
+		}
+		xmax, ymax, e := excelize.CellNameToCoordinates(merge.GetEndAxis())
+		if e != nil {
+			continue
+		}
+		for i := xmin; i <= xmax; i++ {
+			for j := ymin; j <= ymax; j++ {
+				mergeIndexDataMap[fmt.Sprintf("%d:%d", i, j)] = merge.GetCellValue()
+			}
+		}
+	}
+	return
+}
+
+func getCellValue(cell string) (val string, ok bool) {
+	valueArr := strings.Split(cell, "-")
+	switch len(valueArr) {
+	case 1:
+		if !isValueValid(valueArr[0]) {
+			return
+		}
+		return valueArr[0], true
+	case 2:
+		val1, err := strconv.ParseFloat(valueArr[0], 64)
+		if err != nil {
+			return
+		}
+		val2, err := strconv.ParseFloat(valueArr[1], 64)
+		if err != nil {
+			return
+		}
+		mean := (val1 + val2) / 2
+		return fmt.Sprintf("%.2f", mean), true
+	}
+	return "", false
+}
+
+func LastDayOfMonth(year int, month time.Month) string {
+	firstDay := time.Date(year, month, 1, 0, 0, 0, 0, time.Local)
+	nextMonth := firstDay.AddDate(0, 1, 0)
+	return nextMonth.Add(-time.Nanosecond * 1).Format(utils.FormatDate)
+}

+ 376 - 1
services/base_from_yongyi_v2/week40.go

@@ -4,10 +4,12 @@ import (
 	"eta/eta_data_analysis/models"
 	"eta/eta_data_analysis/utils"
 	"fmt"
-	"github.com/xuri/excelize/v2"
+	"regexp"
 	"strconv"
 	"strings"
 	"time"
+
+	"github.com/xuri/excelize/v2"
 )
 
 // HandleYongyiExcelWeekly31 月度-屠宰厂公母比例
@@ -628,3 +630,376 @@ func HandleYongyiExcelWeekly35(f *excelize.File, sheetName string) (indexList []
 	}
 	return
 }
+
+// HandleYongyiExcelWeekly37 周度-养殖利润
+func HandleYongyiExcelWeekly37(f *excelize.File, sheetName string) (indexList []*models.YongyiExcelIndex, err error) {
+	defer func() {
+		if err != nil {
+			//fmt.Printf("HandleYongyiExcelWeekly35 月度-能繁母猪存栏量 ErrMsg: %s\n", err.Error())
+			utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly37 周度-养殖利润 ErrMsg: %s", err.Error()))
+		}
+	}()
+	col, e := f.GetCols(sheetName)
+	if e != nil {
+		err = fmt.Errorf("f GetCols err: %s", e.Error())
+		return
+	}
+	yearReg := regexp.MustCompile(`^\d{4}年$`)
+	// 获取指标信息
+	classifyName, classifySort, frequency, unit, namePrefix, namePrefixPingin := GetBaseInfo(sheetName)
+	// GetBaseInfo(sheetName)
+	indexList = make([]*models.YongyiExcelIndex, 0)
+
+	indexInfoMap := make(map[string]*models.YongyiExcelIndex)
+	var indexName string
+	var weekIndexMap = make(map[int]int)
+	var sort = 0
+	for i, c := range col {
+		if len(c) < 2 {
+			continue
+		}
+		if i == 0 {
+			// 记录周度索引
+			for j, v := range c {
+				vInt, e := strconv.Atoi(v)
+				if e != nil {
+					continue
+				}
+				weekIndexMap[j] = vInt
+			}
+		}
+		if strings.TrimSpace(c[1]) != "" {
+			indexName = strings.TrimSpace(c[1])
+		}
+		if indexName == "" {
+			continue
+		}
+		if len(c) < 4 {
+			continue
+		}
+		// 匹配 2021年 的格式
+		if ok := yearReg.MatchString(c[2]); !ok {
+			continue
+		}
+		yearStr := c[2][:4]
+		year, e := strconv.Atoi(yearStr)
+		if e != nil {
+			continue
+		}
+		if indexInfo, ok := indexInfoMap[indexName]; !ok {
+			tmpYongyiIndex := new(models.YongyiExcelIndex)
+			tmpYongyiIndex.IndexName = namePrefix + "/" + indexName
+			tmpYongyiIndex.ClassifyName = classifyName
+			tmpYongyiIndex.ClassifySort = classifySort
+			tmpYongyiIndex.IndexCode = namePrefixPingin + utils.GetFirstPingYin(indexName)
+			tmpYongyiIndex.Frequency = frequency
+			tmpYongyiIndex.Unit = unit
+			tmpYongyiIndex.Sort = sort
+			tmpYongyiIndex.ExcelDataMap = make(map[string]string)
+			for j, v := range c[3:] {
+				dataTime := getSundayOfWeek(year, weekIndexMap[j+3])
+				if isValueValid(v) {
+					tmpYongyiIndex.ExcelDataMap[dataTime] = v
+				}
+			}
+			indexInfoMap[indexName] = tmpYongyiIndex
+			indexList = append(indexList, tmpYongyiIndex)
+			sort++
+		} else {
+			for j, v := range c[3:] {
+				dataTime := getSundayOfWeek(year, weekIndexMap[j+3])
+				if isValueValid(v) {
+					indexInfo.ExcelDataMap[dataTime] = v
+				}
+			}
+		}
+	}
+	utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly37 周度-养殖利润 指标列表:%v", indexList))
+	return
+}
+
+// HandleYongyiExcelWeekly38 华东冻品价格
+func HandleYongyiExcelWeekly38(f *excelize.File, sheetName string) (indexList []*models.YongyiExcelIndex, err error) {
+	defer func() {
+		if err != nil {
+			//fmt.Printf("HandleYongyiExcelWeekly35 月度-能繁母猪存栏量 ErrMsg: %s\n", err.Error())
+			utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly37 周度-养殖利润 ErrMsg: %s", err.Error()))
+		}
+	}()
+
+	rows, e := f.GetRows(sheetName)
+	if e != nil {
+		err = fmt.Errorf("f GetRows err: %s", e.Error())
+		return
+	}
+
+	classifyName, classifySort, frequency, unit, namePrefix, namePrefixPingin := GetBaseInfo(sheetName)
+	if len(rows) < 2 {
+		err = fmt.Errorf("sheet %s 行数小于2", sheetName)
+		return
+	}
+
+	mergeCellMap, e := getMergeCellValMap(f, sheetName)
+	if e != nil {
+		err = fmt.Errorf("getMergeCellValMap err: %s", e.Error())
+		return
+	}
+	sort := 0
+	var indexNamePart1, indexNamePart2 string
+	indexNamePart3 := make(map[int]string)
+	indexInfoMap := make(map[string]*models.YongyiExcelIndex)
+	dateTimeIndexMap := make(map[int]string)
+	maxLen := 0
+	for _, row := range rows {
+		if len(row) > maxLen {
+			maxLen = len(row)
+		}
+	}
+	for k, v := range mergeCellMap {
+		axis := strings.Split(k, ":")
+		if len(axis) != 2 {
+			continue
+		}
+		x, y := axis[0], axis[1]
+		xInt, e := strconv.Atoi(x)
+		if e != nil {
+			continue
+		}
+		yInt, e := strconv.Atoi(y)
+		if e != nil {
+			continue
+		}
+		tmpList := make([]string, maxLen)
+		copy(tmpList, rows[yInt-1])
+		tmpList[xInt-1] = v
+		rows[yInt-1] = tmpList
+	}
+
+	for i, row := range rows {
+		if i == 0 {
+			continue
+		}
+		// 日期列
+		if i == 1 {
+			for j, cell := range row {
+				if cell == "" {
+					continue
+				}
+				dateInt, err := strconv.Atoi(cell)
+				if err != nil {
+					continue
+				}
+				dateTimeIndexMap[j] = excelDateToTimeDateStr(dateInt)
+			}
+		}
+		// 指标名称列3
+		if i == 2 {
+			for j, cell := range row[2:] {
+				if cell == "" {
+					continue
+				}
+				indexNamePart3[j] = cell
+			}
+		}
+		if i > 2 {
+			for j, cell := range row {
+				if j == 0 && cell != "" {
+					indexNamePart1 = row[0]
+				}
+				if j == 1 && cell != "" {
+					indexNamePart2 = row[1]
+				}
+				if indexNamePart1 == "" || indexNamePart2 == "" {
+					continue
+				}
+				namePart3, ok := indexNamePart3[j-2]
+				if !ok {
+					continue
+				}
+				indexName := fmt.Sprintf("%s/%s/%s", indexNamePart1, indexNamePart2, namePart3)
+				if indexInfo, ok := indexInfoMap[indexName]; !ok {
+					tmpYongyiIndex := new(models.YongyiExcelIndex)
+					tmpYongyiIndex.IndexName = namePrefix + "/" + indexName
+					tmpYongyiIndex.ClassifyName = classifyName
+					tmpYongyiIndex.ClassifySort = classifySort
+					tmpIndexName := strings.ReplaceAll(indexName, "/", "")
+					tmpYongyiIndex.IndexCode = namePrefixPingin + utils.GetFirstPingYin(tmpIndexName)
+					tmpYongyiIndex.Frequency = frequency
+					tmpYongyiIndex.Unit = unit
+					tmpYongyiIndex.Sort = sort
+					tmpYongyiIndex.ExcelDataMap = make(map[string]string)
+					val, ok := getCellValue(cell)
+					if !ok {
+						continue
+					}
+					tmpYongyiIndex.ExcelDataMap[dateTimeIndexMap[j]] = val
+					indexInfoMap[indexName] = tmpYongyiIndex
+					indexList = append(indexList, tmpYongyiIndex)
+					sort++
+				} else {
+					val, ok := getCellValue(cell)
+					if !ok {
+						continue
+					}
+					indexInfo.ExcelDataMap[dateTimeIndexMap[j]] = val
+				}
+			}
+		}
+	}
+	utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly38 华东冻品价格 更新指标数量:%d", len(indexList)))
+	return
+}
+
+// HandleYongyiExcelWeekly39 运费
+func HandleYongyiExcelWeekly39(f *excelize.File, sheetName string) (indexList []*models.YongyiExcelIndex, err error) {
+	defer func() {
+		if err != nil {
+			//fmt.Printf("HandleYongyiExcelWeekly35 月度-能繁母猪存栏量 ErrMsg: %s\n", err.Error())
+			utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly39 月度-能繁母猪存栏量 ErrMsg: %s", err.Error()))
+		}
+	}()
+
+	rows, e := f.GetRows(sheetName)
+	if e != nil {
+		err = fmt.Errorf("f GetRows err: %s", e.Error())
+		return
+	}
+
+	classifyName, classifySort, frequency, unit, namePrefix, namePrefixPingin := GetBaseInfo(sheetName)
+	if len(rows) < 2 {
+		err = fmt.Errorf("sheet %s 行数小于2", sheetName)
+		return
+	}
+	var dataTime string
+	var sort int
+	indexInfoMap := make(map[string]*models.YongyiExcelIndex)
+	for i, row := range rows {
+		if i <= 1 {
+			continue
+		}
+		if len(row) <= 3 {
+			continue
+		}
+		tmpDate, err := time.Parse("01-02-06", row[2])
+		if err == nil {
+			dataTime = tmpDate.Format(utils.FormatDate)
+		}
+		var fromSrc, toDst string
+		if len([]rune(row[0])) == 2 && len([]rune(row[1])) == 2 {
+			fromSrc = row[0]
+			toDst = row[1]
+		}
+		if fromSrc == "" || toDst == "" {
+			continue
+		}
+		indexName := fmt.Sprintf("%s/%s至%s", namePrefix, fromSrc, toDst)
+		if indexInfo, ok := indexInfoMap[indexName]; !ok {
+			tmpYongyiIndex := new(models.YongyiExcelIndex)
+			tmpYongyiIndex.IndexName = indexName
+			tmpYongyiIndex.ClassifyName = classifyName
+			tmpYongyiIndex.ClassifySort = classifySort
+			tmpIndexNameSuffix := fmt.Sprintf("%s至%s", fromSrc, toDst)
+			tmpYongyiIndex.IndexCode = namePrefixPingin + utils.GetFirstPingYin(tmpIndexNameSuffix)
+			tmpYongyiIndex.Frequency = frequency
+			tmpYongyiIndex.Unit = unit
+			tmpYongyiIndex.Sort = sort
+			tmpYongyiIndex.ExcelDataMap = make(map[string]string)
+			val, ok := getCellValue(row[2])
+			if !ok {
+				continue
+			}
+			tmpYongyiIndex.ExcelDataMap[dataTime] = val
+			indexInfoMap[indexName] = tmpYongyiIndex
+			indexList = append(indexList, tmpYongyiIndex)
+			sort++
+		} else {
+			val, ok := getCellValue(row[2])
+			if !ok {
+				continue
+			}
+			indexInfo.ExcelDataMap[dataTime] = val
+		}
+	}
+	utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly39 运费 更新指标数量:%d", len(indexList)))
+	return
+}
+
+// HandleYongyiExcelWeekly40 国产冻品2-4号肉价格
+func HandleYongyiExcelWeekly40(f *excelize.File, sheetName string) (indexList []*models.YongyiExcelIndex, err error) {
+	defer func() {
+		if err != nil {
+			utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly40 国产冻品2-4号肉价格 ErrMsg: %s", err.Error()))
+		}
+	}()
+	rows, err := f.GetRows(sheetName)
+	if err != nil {
+		err = fmt.Errorf("f GetRows err: %s", err.Error())
+		return
+	}
+	className, classSort, frequency, unit, _, namePrefixPingin := GetBaseInfo(sheetName)
+
+	var indexName string
+	var sort int
+	re := regexp.MustCompile(`[+-]?[0-9]*\.?[0-9]+`)
+	indexList = make([]*models.YongyiExcelIndex, 0)
+	monthIndexMap := make(map[int]int)
+	indexInfoMap := make(map[string]*models.YongyiExcelIndex)
+	for _, row := range rows {
+		if len(row) == 0 {
+			indexName = ""
+			continue
+		}
+		if strings.Contains(row[0], "冻猪") {
+			indexName = strings.TrimSpace(row[0])
+		}
+		if indexName == "" {
+			continue
+		}
+		var year int
+		for i, cell := range row {
+			if i == 0 && strings.Contains(cell, "年销价") {
+				if tmp := re.FindString(cell); tmp != "" {
+					year, err = strconv.Atoi("20" + tmp)
+					if err != nil {
+						continue
+					}
+				}
+			} else if strings.Contains(cell, "月") {
+				if month := re.FindString(cell); month != "" {
+					mo, err := strconv.Atoi(month)
+					if err != nil {
+						continue
+					}
+					monthIndexMap[i] = mo
+				}
+			}
+			if re.MatchString(cell) {
+				if indexInfo, ok := indexInfoMap[indexName]; !ok {
+					if isValueValid(cell) {
+						tmpYongyiIndex := new(models.YongyiExcelIndex)
+						tmpYongyiIndex.IndexName = indexName
+						tmpYongyiIndex.ClassifyName = className
+						tmpYongyiIndex.ClassifySort = classSort
+						tmpYongyiIndex.IndexCode = namePrefixPingin + utils.GetFirstPingYin(indexName)
+						tmpYongyiIndex.Frequency = frequency
+						tmpYongyiIndex.Unit = unit
+						tmpYongyiIndex.Sort = sort
+						tmpYongyiIndex.ExcelDataMap = make(map[string]string)
+						date := LastDayOfMonth(year, time.Month(monthIndexMap[i]))
+						tmpYongyiIndex.ExcelDataMap[date] = cell
+						indexInfoMap[indexName] = tmpYongyiIndex
+						indexList = append(indexList, tmpYongyiIndex)
+						sort++
+					}
+				} else {
+					if isValueValid(cell) {
+						date := LastDayOfMonth(year, time.Month(monthIndexMap[i]))
+						indexInfo.ExcelDataMap[date] = cell
+					}
+				}
+			}
+		}
+	}
+	utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly40 国产冻品2-4号肉价格 更新指标数量:%d", len(indexList)))
+	return
+}

+ 680 - 0
services/base_from_yongyi_v2/week50.go

@@ -0,0 +1,680 @@
+package base_from_yongyi_v2
+
+import (
+	"eta/eta_data_analysis/models"
+	"eta/eta_data_analysis/utils"
+	"fmt"
+	"regexp"
+	"strconv"
+	"strings"
+	"time"
+
+	"github.com/xuri/excelize/v2"
+)
+
+// HandleYongyiExcelWeekly41 月度-小猪(50斤以下)存栏
+func HandleYongyiExcelWeekly41(f *excelize.File, sheetName string) (indexList []*models.YongyiExcelIndex, err error) {
+	defer func() {
+		if err != nil {
+			utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly40 国产冻品2-4号肉价格 ErrMsg: %s", err.Error()))
+		}
+	}()
+	cols, err := f.GetCols(sheetName)
+	if err != nil {
+		err = fmt.Errorf("f GetCols err: %s", err.Error())
+		return
+	}
+
+	classifyName, classifySort, frequency, unit, namePrefix, namePrefixPingin := GetBaseInfo(sheetName)
+
+	sort := 0
+	var preIndexName string
+	dateIndexList := make([]string, 0)
+	indexInfoMap := make(map[string]*models.YongyiExcelIndex)
+	indexNamePart2 := map[string]struct{}{"全国": {}, "华北": {}, "东北": {}, "华中": {}, "华东": {}, "华南": {}, "西南": {}}
+
+	for i, col := range cols {
+		if len(col) <= 3 {
+			continue
+		}
+		if i == 0 && col[1] == "日期" {
+			for _, cell := range col {
+				tmpDateTime, err := time.Parse("2006年1月", cell)
+				if err != nil {
+					dateIndexList = append(dateIndexList, "")
+				} else {
+					dateTime := LastDayOfMonth(tmpDateTime.Year(), tmpDateTime.Month())
+					dateIndexList = append(dateIndexList, dateTime)
+				}
+			}
+		}
+		if len(dateIndexList) == 0 {
+			continue
+		}
+		if col[1] != "" && col[1] != "日期" {
+			var indexName, indexNameSuffix string
+			if _, ok := indexNamePart2[col[1]]; ok {
+				preIndexName = col[1]
+				indexName = fmt.Sprintf("%s/%s", namePrefix, col[1])
+				indexNameSuffix = col[1]
+			} else if col[1] == "环比" {
+				indexName = fmt.Sprintf("%s(%s)/%s", namePrefix, col[1], preIndexName)
+				indexNameSuffix = fmt.Sprintf("(%s)%s", col[1], preIndexName)
+			} else {
+				continue
+			}
+			for j, cell := range col {
+				if !isValueValid(cell) {
+					continue
+				}
+				if indexInfo, ok := indexInfoMap[indexName]; !ok {
+					tmpYongyiIndex := new(models.YongyiExcelIndex)
+					tmpYongyiIndex.ClassifyName = classifyName
+					tmpYongyiIndex.ClassifySort = classifySort
+					tmpYongyiIndex.Frequency = frequency
+					tmpYongyiIndex.Unit = unit
+					tmpYongyiIndex.IndexName = indexName
+					tmpYongyiIndex.IndexCode = namePrefixPingin + utils.GetFirstPingYin(indexNameSuffix)
+					tmpYongyiIndex.Sort = sort
+					tmpYongyiIndex.ExcelDataMap = make(map[string]string)
+					if string(cell[len(cell)-1]) == `%` {
+						tmpYongyiIndex.Unit = `%`
+						tmpYongyiIndex.ExcelDataMap[dateIndexList[j]] = cell[:len(cell)-1]
+					} else {
+						tmpYongyiIndex.ExcelDataMap[dateIndexList[j]] = cell
+					}
+					indexInfoMap[indexName] = tmpYongyiIndex
+					indexList = append(indexList, tmpYongyiIndex)
+					sort++
+				} else {
+					if string(cell[len(cell)-1]) == `%` {
+						indexInfo.ExcelDataMap[dateIndexList[j]] = cell[:len(cell)-1]
+					} else {
+						indexInfo.ExcelDataMap[dateIndexList[j]] = cell
+					}
+				}
+			}
+		}
+	}
+	utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly41 %s 更新指标数量:%d", sheetName, len(indexList)))
+	return
+}
+
+// HandleYongyiExcelWeekly42 月度猪肉供应占比
+func HandleYongyiExcelWeekly42(f *excelize.File, sheetName string) (indexList []*models.YongyiExcelIndex, err error) {
+	defer func() {
+		if err != nil {
+			utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly40 月度猪肉供应占比 ErrMsg: %s", err.Error()))
+		}
+	}()
+	rows, err := f.GetRows(sheetName)
+	if err != nil {
+		err = fmt.Errorf("f GetRows err: %s", err.Error())
+		return
+	}
+
+	classifyName, classifySort, frequency, unit, namePrefix, namePrefixPingin := GetBaseInfo(sheetName)
+
+	re := regexp.MustCompile(`[+-]?[0-9]*\.?[0-9]+`)
+	yearIndexMap := make(map[int]string)
+
+	yongyiExcelIndex := new(models.YongyiExcelIndex)
+	yongyiExcelIndex.ClassifyName = classifyName
+	yongyiExcelIndex.ClassifySort = classifySort
+	yongyiExcelIndex.Frequency = frequency
+	yongyiExcelIndex.Unit = unit
+	yongyiExcelIndex.IndexName = namePrefix
+	yongyiExcelIndex.IndexCode = namePrefixPingin
+	yongyiExcelIndex.Sort = 0
+	yongyiExcelIndex.ExcelDataMap = make(map[string]string)
+	indexList = append(indexList, yongyiExcelIndex)
+	for i, row := range rows {
+		if i == 0 {
+			// 记录年份索引
+			for j, cell := range row {
+				if isValueValid(cell) {
+					yearIndexMap[j] = cell
+				}
+			}
+		} else {
+			var month string
+			for j, cell := range row {
+				if j == 0 {
+					if tmp := re.FindString(cell); tmp != "" {
+						month = tmp
+						continue
+					}
+				}
+				if month == "" {
+					break
+				}
+				tmpYear, err := strconv.Atoi(yearIndexMap[j])
+				if err != nil {
+					continue
+				}
+				tmpMonth, err := strconv.Atoi(month)
+				if err != nil {
+					continue
+				}
+				dataTime := LastDayOfMonth(tmpYear, time.Month(tmpMonth))
+				if isValueValid(cell) {
+					newCell := strings.ReplaceAll(cell, "%", "")
+					yongyiExcelIndex.ExcelDataMap[dataTime] = newCell
+				}
+			}
+		}
+	}
+	utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly42 %s 更新指标数量:%d", sheetName, len(indexList)))
+	return
+}
+
+// HandleYongyiExcelWeekly43 历史出栏体重
+func HandleYongyiExcelWeekly43(f *excelize.File, sheetName string) (indexList []*models.YongyiExcelIndex, err error) {
+	defer func() {
+		if err != nil {
+			utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly43 %s ErrMsg: %s", sheetName, err.Error()))
+		}
+	}()
+	rows, err := f.GetRows(sheetName)
+	if err != nil {
+		err = fmt.Errorf("f GetRows err: %s", err.Error())
+		return
+	}
+	re := regexp.MustCompile(`\d+`)
+
+	classifyName, classifySort, frequency, unit, namePrefix, namePrefixPingin := GetBaseInfo(sheetName)
+	yongyiExcelIndex := new(models.YongyiExcelIndex)
+	yongyiExcelIndex.ClassifyName = classifyName
+	yongyiExcelIndex.ClassifySort = classifySort
+	yongyiExcelIndex.Frequency = frequency
+	yongyiExcelIndex.Unit = unit
+	yongyiExcelIndex.IndexName = namePrefix
+	yongyiExcelIndex.IndexCode = namePrefixPingin
+	yongyiExcelIndex.Sort = 0
+	yongyiExcelIndex.ExcelDataMap = make(map[string]string)
+	indexList = append(indexList, yongyiExcelIndex)
+	for i, row := range rows {
+		if i == 0 {
+			continue
+		}
+		if len(row) < 2 {
+			continue
+		}
+		dateArr := re.FindAllString(row[0], -1)
+		year, err := strconv.Atoi(dateArr[0])
+		if err != nil {
+			continue
+		}
+		week, err := strconv.Atoi(dateArr[1])
+		if err != nil {
+			continue
+		}
+		if !isValueValid(row[1]) {
+			continue
+		}
+		date := getSundayOfWeek(year, week)
+		yongyiExcelIndex.ExcelDataMap[date] = row[1]
+	}
+	utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly43 %s 更新指标数量:%d", sheetName, len(indexList)))
+	return
+}
+
+// HandleYongyiExcelWeekly44 重要部位冻品进口
+func HandleYongyiExcelWeekly44(f *excelize.File, sheetName string) (indexList []*models.YongyiExcelIndex, err error) {
+	defer func() {
+		if err != nil {
+			utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly44 %s ErrMsg: %s", sheetName, err.Error()))
+		}
+	}()
+	cols, err := f.GetCols(sheetName)
+	if err != nil {
+		err = fmt.Errorf("f GetCols err: %s", err.Error())
+		return
+	}
+
+	classifyName, classifySort, frequency, _, namePrefix, namePrefixPingin := GetBaseInfo(sheetName)
+
+	sort := 0
+	re := regexp.MustCompile(`\d+`)
+	dateIndexMap := make(map[int]string)
+	for i, col := range cols {
+		if i == 0 {
+			for j, cell := range col {
+				dateArr := re.FindAllString(cell, -1)
+				if len(dateArr) != 2 {
+					continue
+				}
+				year, err := strconv.Atoi(dateArr[0])
+				if err != nil {
+					continue
+				}
+				month, err := strconv.Atoi(dateArr[1])
+				if err != nil {
+					continue
+				}
+				dateIndexMap[j] = LastDayOfMonth(year, time.Month(month))
+			}
+		} else {
+			if len(col) < 2 {
+				continue
+			}
+			if col[1] == "" {
+				continue
+			}
+			indexName := fmt.Sprintf("%s/%s", namePrefix, col[1])
+			yongyiExcelIndex := new(models.YongyiExcelIndex)
+			yongyiExcelIndex.ClassifyName = classifyName
+			yongyiExcelIndex.ClassifySort = classifySort
+			yongyiExcelIndex.Frequency = frequency
+			yongyiExcelIndex.IndexName = indexName
+			yongyiExcelIndex.IndexCode = namePrefixPingin + utils.GetFirstPingYin(col[1])
+			yongyiExcelIndex.Sort = sort
+			yongyiExcelIndex.ExcelDataMap = make(map[string]string)
+			if col[1] == "柜数" {
+				yongyiExcelIndex.Unit = "个"
+			} else if col[1] == "合计" {
+				yongyiExcelIndex.Unit = "kg"
+			} else {
+				continue
+			}
+			for j, cell := range col {
+				if j == 0 {
+					continue
+				}
+				cell = strings.ReplaceAll(cell, ",", "")
+				if !isValueValid(cell) {
+					continue
+				}
+				yongyiExcelIndex.ExcelDataMap[dateIndexMap[j]] = cell
+			}
+			indexList = append(indexList, yongyiExcelIndex)
+			sort++
+		}
+	}
+	utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly44 %s 更新指标数量:%d", sheetName, len(indexList)))
+	return
+}
+
+// HandleYongyiExcelWeekly45 各存栏规模
+func HandleYongyiExcelWeekly45(f *excelize.File, sheetName string) (indexList []*models.YongyiExcelIndex, err error) {
+	defer func() {
+		if err != nil {
+			utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly45 %s ErrMsg: %s", sheetName, err.Error()))
+		}
+	}()
+	rows, err := f.GetRows(sheetName)
+	if err != nil {
+		err = fmt.Errorf("f GetRows err: %s", err.Error())
+		return
+	}
+
+	classifyName, classifySort, frequency, unit, namePrefix, namePrefixPingin := GetBaseInfo(sheetName)
+
+	sort := 0
+	re := regexp.MustCompile(`\d+`)
+	indexNamePart3 := make([]string, 0)
+	indexInfoMap := make(map[string]*models.YongyiExcelIndex)
+	for i, row := range rows {
+		if i == 0 {
+			continue
+		}
+		if i == 1 {
+			for j, cell := range row {
+				if j >= 2 {
+					indexNamePart3 = append(indexNamePart3, cell)
+				} else {
+					indexNamePart3 = append(indexNamePart3, "")
+				}
+			}
+		}
+		if len(row) == 0 {
+			break
+		}
+		if i > 1 && len(row) > 2 {
+			var date string
+			for j, cell := range row {
+				if j == 0 {
+					dateArr := re.FindAllString(cell, -1)
+					if len(dateArr) != 2 {
+						break
+					}
+					year, err := strconv.Atoi(dateArr[0])
+					if err != nil {
+						break
+					}
+					month, err := strconv.Atoi(dateArr[1])
+					if err != nil {
+						break
+					}
+					date = LastDayOfMonth(year, time.Month(month))
+				}
+				if !isValueValid(cell) {
+					continue
+				}
+				indexName := fmt.Sprintf("%s/%s/%s", namePrefix, row[1], indexNamePart3[j])
+				if indexInfo, ok := indexInfoMap[indexName]; !ok {
+					tmpYongyiIndex := new(models.YongyiExcelIndex)
+					tmpYongyiIndex.ClassifyName = classifyName
+					tmpYongyiIndex.ClassifySort = classifySort
+					tmpYongyiIndex.Frequency = frequency
+					tmpYongyiIndex.Unit = unit
+					tmpYongyiIndex.IndexName = indexName
+					tmpYongyiIndex.IndexCode = namePrefixPingin + utils.GetFirstPingYin(row[1]+indexNamePart3[j])
+					tmpYongyiIndex.Sort = sort
+					tmpYongyiIndex.ExcelDataMap = make(map[string]string)
+					newCell := strings.ReplaceAll(cell, "%", "")
+					tmpYongyiIndex.ExcelDataMap[date] = newCell
+					indexInfoMap[indexName] = tmpYongyiIndex
+					indexList = append(indexList, tmpYongyiIndex)
+					sort++
+				} else {
+					newCell := strings.ReplaceAll(cell, "%", "")
+					indexInfo.ExcelDataMap[date] = newCell
+				}
+			}
+		}
+	}
+	utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly45 %s 更新指标数量:%d", sheetName, len(indexList)))
+	return
+}
+
+// HandleYongyiExcelWeekly46 进口肉
+func HandleYongyiExcelWeekly46(f *excelize.File, sheetName string) (indexList []*models.YongyiExcelIndex, err error) {
+	defer func() {
+		if err != nil {
+			utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly46 %s ErrMsg: %s", sheetName, err.Error()))
+		}
+	}()
+	cols, err := f.GetCols(sheetName)
+	if err != nil {
+		err = fmt.Errorf("f GetCols err: %s", err.Error())
+		return
+	}
+
+	classifyName, classifySort, frequency, _, _, namePrefixPingin := GetBaseInfo(sheetName)
+
+	sort := 0
+	var indexName string
+	re := regexp.MustCompile(`\d+`)
+	regZr := regexp.MustCompile(`\([^()]*\)`)
+	zrzuDateMap := make(map[int]string) // 猪肉及杂碎进口量
+	indexInfoMap := make(map[string]*models.YongyiExcelIndex)
+	for _, col := range cols {
+		if indexName == "" {
+			indexName = col[1]
+		}
+		if col[2] == "" && col[3] == "" {
+			indexName = ""
+			continue
+		}
+		if indexName != "" && strings.Contains(indexName, "猪肉进口量") {
+			indexName = "猪肉进口量"
+			var year int
+			if strings.Contains(col[2], "年") {
+				year, err = strconv.Atoi(re.FindString(col[2]))
+				if err != nil {
+					continue
+				}
+			}
+			for j, cell := range col {
+				if !isValueValid(cell) {
+					continue
+				}
+				monthArr := strings.Split(cols[0][j], "-")
+				var month int
+				switch len(monthArr) {
+				case 2:
+					month, err = strconv.Atoi(re.FindString(monthArr[1]))
+					if err != nil {
+						continue
+					}
+				case 1:
+					month, err = strconv.Atoi(re.FindString(monthArr[0]))
+					if err != nil {
+						continue
+					}
+				}
+				date := LastDayOfMonth(year, time.Month(month))
+				if date == "" {
+					continue
+				}
+				if indexInfo, ok := indexInfoMap[indexName]; !ok {
+					tmpYongyiIndex := new(models.YongyiExcelIndex)
+					tmpYongyiIndex.ClassifyName = classifyName
+					tmpYongyiIndex.ClassifySort = classifySort
+					tmpYongyiIndex.Frequency = frequency
+					tmpYongyiIndex.Unit = "万吨"
+					tmpYongyiIndex.IndexName = indexName
+					tmpYongyiIndex.IndexCode = namePrefixPingin + utils.GetFirstPingYin(indexName)
+					tmpYongyiIndex.Sort = sort
+					tmpYongyiIndex.ExcelDataMap = make(map[string]string)
+					tmpYongyiIndex.ExcelDataMap[date] = cell
+					indexInfoMap[indexName] = tmpYongyiIndex
+					indexList = append(indexList, tmpYongyiIndex)
+					sort++
+				} else {
+					indexInfo.ExcelDataMap[date] = cell
+				}
+			}
+		} else if indexName != "" && strings.Contains(indexName, "猪肉及杂碎进口量") {
+			preName := "猪肉及杂碎进口量"
+			if len(col) <= 3 {
+				continue
+			}
+			colTitleName := col[2]
+			if colTitleName == `` {
+				continue
+			}
+			if colTitleName == `日期` {
+				for j, cell := range col {
+					if cell == "" || j <= 2 {
+						continue
+					}
+					excelDate, err := strconv.ParseFloat(cell, 64)
+					if err != nil {
+						continue
+					}
+					tmpDate, err := excelize.ExcelDateToTime(excelDate, false)
+					if err != nil {
+						continue
+					}
+					LastDayDate := LastDayOfMonth(tmpDate.Year(), tmpDate.Month())
+					zrzuDateMap[j] = LastDayDate
+				}
+			} else {
+				unit := regZr.FindString(colTitleName)
+				if unit == "" {
+					unit = "%"
+				} else {
+					unit = strings.ReplaceAll(unit, "(", "")
+					unit = strings.ReplaceAll(unit, ")", "")
+				}
+				namePart := regZr.ReplaceAllString(colTitleName, "")
+				tmpIndexName := fmt.Sprintf("%s/%s", preName, namePart)
+				if indexInfo, ok := indexInfoMap[tmpIndexName]; !ok {
+					yongyiIndex := new(models.YongyiExcelIndex)
+					yongyiIndex.ClassifyName = classifyName
+					yongyiIndex.ClassifySort = classifySort
+					yongyiIndex.Frequency = frequency
+					yongyiIndex.Unit = unit
+					yongyiIndex.IndexName = tmpIndexName
+					tmpIndexName = strings.ReplaceAll(tmpIndexName, "/", "")
+					yongyiIndex.IndexCode = namePrefixPingin + utils.GetFirstPingYin(tmpIndexName)
+					yongyiIndex.Sort = sort
+					yongyiIndex.ExcelDataMap = make(map[string]string)
+					for j, cell := range col {
+						if j == 0 {
+							continue
+						}
+						cell = strings.ReplaceAll(cell, ",", "")
+						if unit == "%" {
+							cell = strings.ReplaceAll(cell, "%", "")
+						}
+						if !isValueValid(cell) {
+							continue
+						}
+						yongyiIndex.ExcelDataMap[zrzuDateMap[j]] = cell
+					}
+					indexInfoMap[yongyiIndex.IndexName] = yongyiIndex
+					indexList = append(indexList, yongyiIndex)
+					sort++
+				} else {
+					for j, cell := range col {
+						if j == 0 {
+							continue
+						}
+						cell = strings.ReplaceAll(cell, ",", "")
+						if unit == "%" {
+							cell = strings.ReplaceAll(cell, "%", "")
+						}
+						if !isValueValid(cell) {
+							continue
+						}
+						indexInfo.ExcelDataMap[zrzuDateMap[j]] = cell
+					}
+				}
+			}
+		}
+	}
+	utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly46 %s 更新指标数量:%d", sheetName, len(indexList)))
+	return
+}
+
+// HandleYongyiExcelWeekly47 猪料原料占比
+func HandleYongyiExcelWeekly47(f *excelize.File, sheetName string) (indexList []*models.YongyiExcelIndex, err error) {
+	defer func() {
+		if err != nil {
+			utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly47 %s ErrMsg: %s", sheetName, err.Error()))
+		}
+	}()
+	rows, err := f.GetRows(sheetName)
+	if err != nil {
+		err = fmt.Errorf("f GetRows err: %s", err.Error())
+		return
+	}
+	classifyName, classifySort, frequency, unit, namePrefix, namePrefixPingin := GetBaseInfo(sheetName)
+
+	namePart2Map := map[string]int{
+		"玉米": 0, "小麦": 0, "稻谷、糙米": 0, "豆粕": 0, "棉粕": 0, "菜粕": 0,
+	}
+	regionMap := map[string]struct{}{
+		"东北": {}, "华北": {}, "华中": {}, "华南": {}, "西北": {}, "西南": {}, "全国": {},
+	}
+	regionIndexMap := make(map[int]string)
+	indexInfoMap := make(map[string]*models.YongyiExcelIndex)
+
+	sort := 0
+	for i, row := range rows {
+		if i == 0 {
+			continue
+		}
+		if len(row) <= 1 {
+			continue
+		}
+		var preName string
+		for j, cell := range row {
+			if _, ok := namePart2Map[cell]; ok {
+				namePart2Map[cell] = j
+				preName = cell
+				continue
+			}
+			if _, ok := regionMap[cell]; ok {
+				regionIndexMap[j] = preName + "/" + cell
+				continue
+			}
+			if region, ok := regionIndexMap[j]; ok {
+				if !isValueValid(cell) {
+					continue
+				}
+				kind := strings.Split(region, "/")[0]
+				dateIndex := namePart2Map[kind]
+				excelDate, err := strconv.ParseFloat(row[dateIndex], 64)
+				if err != nil {
+					continue
+				}
+				curTime, err := excelize.ExcelDateToTime(excelDate, false)
+				if err != nil {
+					continue
+				}
+				dateTime := LastDayOfMonth(curTime.Year(), curTime.Month())
+
+				indexName := fmt.Sprintf("%s/%s", namePrefix, region)
+				if indexInfo, ok := indexInfoMap[indexName]; !ok {
+					yongyiIndex := new(models.YongyiExcelIndex)
+					yongyiIndex.ClassifyName = classifyName
+					yongyiIndex.ClassifySort = classifySort
+					yongyiIndex.Frequency = frequency
+					yongyiIndex.Unit = unit
+					yongyiIndex.IndexName = indexName
+					tmpSuffix := strings.ReplaceAll(region, "/", "")
+					tmpSuffix = strings.ReplaceAll(tmpSuffix, "、", "")
+					yongyiIndex.IndexCode = namePrefixPingin + utils.GetFirstPingYin(tmpSuffix)
+					yongyiIndex.Sort = sort
+					yongyiIndex.ExcelDataMap = make(map[string]string)
+					cell = strings.ReplaceAll(cell, "%", "")
+					yongyiIndex.ExcelDataMap[dateTime] = cell
+					indexInfoMap[indexName] = yongyiIndex
+					indexList = append(indexList, yongyiIndex)
+					sort++
+				} else {
+					cell = strings.ReplaceAll(cell, "%", "")
+					indexInfo.ExcelDataMap[dateTime] = cell
+				}
+			}
+
+		}
+	}
+	utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly47 %s 更新指标数量:%d", sheetName, len(indexList)))
+	return
+}
+
+// HandleYongyiExcelWeekly48 MSY
+func HandleYongyiExcelWeekly48(f *excelize.File, sheetName string) (indexList []*models.YongyiExcelIndex, err error) {
+	defer func() {
+		if err != nil {
+			utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly48 %s ErrMsg: %s", sheetName, err.Error()))
+		}
+	}()
+	cols, err := f.GetCols(sheetName)
+	if err != nil {
+		err = fmt.Errorf("f GetRows err: %s", err.Error())
+		return
+	}
+	classifyName, classifySort, frequency, unit, namePrefix, namePrefixPingin := GetBaseInfo(sheetName)
+
+	re := regexp.MustCompile(`\d+`)
+	dateMap := make(map[int]string)
+	for _, col := range cols {
+		if len(col) <= 3 {
+			continue
+		}
+		if col[2] == "时间" {
+			for j, cell := range col {
+				year := re.FindString(cell)
+				if year == "" {
+					continue
+				}
+				dateMap[j] = year + "-12-31"
+			}
+		} else if col[2] == "MSY" {
+			yongyiIndex := new(models.YongyiExcelIndex)
+			yongyiIndex.ClassifyName = classifyName
+			yongyiIndex.ClassifySort = classifySort
+			yongyiIndex.Frequency = frequency
+			yongyiIndex.Unit = unit
+			yongyiIndex.IndexName = namePrefix
+			yongyiIndex.IndexCode = namePrefixPingin
+			yongyiIndex.Sort = 0
+			yongyiIndex.ExcelDataMap = make(map[string]string)
+			for j, cell := range col {
+				if !isValueValid(cell) {
+					continue
+				}
+				yongyiIndex.ExcelDataMap[dateMap[j]] = cell
+			}
+			indexList = append(indexList, yongyiIndex)
+		}
+	}
+	utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly48 %s 更新指标数量:%d", sheetName, len(indexList)))
+	return
+}

+ 4 - 3
services/task.go

@@ -7,15 +7,16 @@ import (
 	"eta/eta_data_analysis/services/liangyou"
 	"eta/eta_data_analysis/utils"
 	"fmt"
-	"github.com/beego/beego/v2/task"
-	"github.com/patrickmn/go-cache"
-	"github.com/robfig/cron/v3"
 	"io/fs"
 	"os"
 	"path/filepath"
 	"strings"
 	"syscall"
 	"time"
+
+	"github.com/beego/beego/v2/task"
+	"github.com/patrickmn/go-cache"
+	"github.com/robfig/cron/v3"
 )
 
 func Task() {