|
@@ -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,293 @@ 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
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ fmt.Println(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
|
|
|
+ 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
|
|
|
+ tmpIndexName := strings.ReplaceAll(indexName, "/", "")
|
|
|
+ tmpYongyiIndex.IndexCode = namePrefixPingin + utils.GetFirstPingYin(tmpIndexName)
|
|
|
+ tmpYongyiIndex.Frequency = frequency
|
|
|
+ tmpYongyiIndex.Unit = unit
|
|
|
+ tmpYongyiIndex.Sort = 0
|
|
|
+ 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)
|
|
|
+ } else {
|
|
|
+ val, ok := getCellValue(row[2])
|
|
|
+ if !ok {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ indexInfo.ExcelDataMap[dataTime] = val
|
|
|
+ }
|
|
|
+ }
|
|
|
+ fmt.Println(len(indexList))
|
|
|
+ return
|
|
|
+}
|