1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297 |
- package base_from_yongyi_v2
- import (
- "eta/eta_data_analysis/models"
- "eta/eta_data_analysis/utils"
- "fmt"
- "github.com/xuri/excelize/v2"
- "strconv"
- "strings"
- "time"
- )
- // HandleYongyiExcelWeekly11 月度-原种场二元后备母猪销量及出栏日龄
- func HandleYongyiExcelWeekly11(f *excelize.File, sheetName string) (indexList []*models.YongyiExcelIndex, err error) {
- defer func() {
- if err != nil {
- fmt.Printf("HandleYongyiExcelWeekly11 月度-原种场二元后备母猪销量及出栏日龄 ErrMsg: %s\n", err.Error())
- utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly11 月度-原种场二元后备母猪销量及出栏日龄 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)
- // 遍历行读取
- indexList = make([]*models.YongyiExcelIndex, 0)
- nameMap := make(map[int]string)
- sort := 0
- // 指标名称
- indexMap := make(map[string]*models.YongyiExcelIndex)
- for i, row := range rows {
- fmt.Printf("当前第%d行 \n", i)
- // 首行,表示时间
- if i == 0 {
- continue
- } else if i == 1 { //表示表头
- // 处理 index指标表
- for k, text := range row {
- fmt.Printf("当前第%d列 \n", k)
- if k >= 7 && text != "" {
- text = strings.TrimSpace(text)
- nameMap[k] = text
- }
- }
- } else { //数据列
- date := ""
- for k, text := range row {
- fmt.Printf("当前第%d列 \n", k)
- if k <= 6 {
- continue
- } else if k == 7 {
- // 日期
- text = strings.TrimSpace(text)
- var dateT time.Time
- dateT, e = time.ParseInLocation("2006年1月", text, time.Local)
- if e != nil {
- utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 读取行,时间列失败 Err:%s", sheetName, i, k, e))
- continue
- }
- date = dateT.Format(utils.FormatDate)
- fmt.Println(date)
- continue
- } else {
- if i <= 6 {
- continue
- }
- if text == "" {
- continue
- }
- if strings.Contains(text, "%") {
- text = strings.Replace(text, "%", "", 1)
- }
- _, 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))
- continue
- }
- }
- name, ok3 := nameMap[k]
- if !ok3 {
- err = fmt.Errorf("找不到对应的指标名称,第%d行,第%d列", i, k)
- return
- }
- if name != "数量" {
- continue
- }
- name = "二元母猪销量"
- fmt.Printf("当前第%d行第%d列, 当前省份%s \n", i, k, name)
- // 处理指标名称
- fullIndexName := fmt.Sprintf("%s/%s", namePrefix, name)
- areaPingin := utils.GetFirstPingYin(name)
- fullIndexNamePingyin := namePrefixPingin + areaPingin
- indexItem, okIndex := indexMap[fullIndexName]
- if !okIndex {
- // 新增指标
- indexItem = new(models.YongyiExcelIndex)
- indexItem.IndexName = fullIndexName
- indexItem.ClassifyName = classifyName
- indexItem.ClassifySort = classifySort
- indexItem.IndexCode = fullIndexNamePingyin
- indexItem.Frequency = frequency
- indexItem.Sort = sort
- indexItem.Unit = unit
- indexItem.ExcelDataMap = make(map[string]string)
- sort++
- }
- fmt.Printf("indexItem%s", indexItem.IndexCode)
- indexItem.ExcelDataMap[date] = text
- indexMap[fullIndexName] = indexItem
- continue
- }
- }
- }
- for _, v := range indexMap {
- indexList = append(indexList, v)
- }
- return
- }
- // HandleYongyiExcelWeekly12 历史猪价
- func HandleYongyiExcelWeekly12(f *excelize.File, sheetName string) (indexList []*models.YongyiExcelIndex, err error) {
- defer func() {
- if err != nil {
- fmt.Printf("HandleYongyiExcelWeekly12 月度-历史猪价 ErrMsg: %s\n", err.Error())
- utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly12 月度-历史猪价 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)
- // 遍历行读取
- indexList = make([]*models.YongyiExcelIndex, 0)
- yearMap := make(map[int]string)
- sort := 0
- // 指标名称
- indexMap := make(map[string]*models.YongyiExcelIndex)
- for i, row := range rows {
- fmt.Printf("当前第%d行 \n", i)
- // 首行,表示时间
- if i == 0 {
- continue
- } else if i == 1 {
- for k, text := range row {
- fmt.Printf("当前第%d列 \n", k)
- if k > 1 && text != "" {
- text = strings.TrimSpace(text)
- yearMap[k] = text
- }
- }
- } else { //数据列
- month := ""
- for k, text := range row {
- fmt.Printf("当前第%d列 \n", k)
- if k == 0 {
- // 日期
- month = strings.TrimSpace(text)
- continue
- } else {
- if text == "" {
- continue
- }
- if strings.Contains(text, "%") {
- text = strings.Replace(text, "%", "", 1)
- }
- _, 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))
- continue
- }
- }
- year, ok := yearMap[k]
- if !ok {
- utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 读取行,时间列失败 Err:%s", sheetName, i, k, "年份不存在"))
- continue
- }
- var dateT time.Time
- dateT, e = time.ParseInLocation("2006年1月", fmt.Sprintf("%s%s", year, month), time.Local)
- if e != nil {
- utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 读取行,时间列失败 Err:%s", sheetName, i, k, e))
- continue
- }
- date := dateT.Format(utils.FormatDate)
- fmt.Println(date)
- // 处理指标名称
- fullIndexName := namePrefix
- fullIndexNamePingyin := namePrefixPingin
- indexItem, okIndex := indexMap[fullIndexName]
- if !okIndex {
- // 新增指标
- indexItem = new(models.YongyiExcelIndex)
- indexItem.IndexName = fullIndexName
- indexItem.ClassifyName = classifyName
- indexItem.ClassifySort = classifySort
- indexItem.IndexCode = fullIndexNamePingyin
- indexItem.Frequency = frequency
- indexItem.Sort = sort
- indexItem.Unit = unit
- indexItem.ExcelDataMap = make(map[string]string)
- sort++
- }
- fmt.Printf("indexItem%s", indexItem.IndexCode)
- indexItem.ExcelDataMap[date] = text
- indexMap[fullIndexName] = indexItem
- continue
- }
- }
- }
- for _, v := range indexMap {
- indexList = append(indexList, v)
- }
- return
- }
- // HandleYongyiExcelWeekly13 二育成本
- func HandleYongyiExcelWeekly13(f *excelize.File, sheetName string) (indexList []*models.YongyiExcelIndex, err error) {
- defer func() {
- if err != nil {
- fmt.Printf("HandleYongyiExcelWeekly13 二育成本 ErrMsg: %s\n", err.Error())
- utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly13 二育成本 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, _, _, namePrefixPingin := GetBaseInfo(sheetName)
- // 遍历行读取
- indexList = make([]*models.YongyiExcelIndex, 0)
- nameMap := make(map[int]string)
- dateMap := make(map[int]string)
- dateNameMap := make(map[string]string)
- finalNameMap := make(map[string]string)
- unitMap := make(map[string]string)
- sort := 0
- // 指标名称
- indexMap := make(map[string]*models.YongyiExcelIndex)
- for i, row := range rows {
- fmt.Printf("当前第%d行 \n", i)
- // 首行,表示时间
- if i == 0 || i == 1 {
- continue
- } else if i == 2 {
- for k, text := range row {
- fmt.Printf("当前第%d列 \n", k)
- if text != "" {
- text = strings.TrimSpace(text)
- nameMap[k] = text
- }
- }
- } else { //数据列
- date := ""
- weight := ""
- for k, text := range row {
- fmt.Printf("当前第%d列 \n", k)
- if k == 0 {
- // 日期
- text = strings.TrimSpace(text)
- var dateT time.Time
- dateT, e = time.ParseInLocation("2006年1月2日", text, time.Local)
- if e != nil {
- utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 读取行,时间列失败 Err:%s", sheetName, i, k, e))
- continue
- }
- date = dateT.Format(utils.FormatDate)
- dateMap[i] = date
- fmt.Println(date)
- continue
- } else {
- if k == 1 {
- // 体重
- weight = strings.TrimSpace(text)
- }
- if text == "" {
- continue
- }
- if strings.Contains(text, "%") {
- text = strings.Replace(text, "%", "", 1)
- }
- _, 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))
- continue
- }
- }
- name, ok := nameMap[k]
- if !ok {
- utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 读取 名称失败 Err:%s", sheetName, i, k, "名称不存在"))
- continue
- }
- dateName := fmt.Sprintf("%s_%s", date, name)
- dateNameWeight := fmt.Sprintf("%s_%s_%s", date, name, weight)
- fmt.Println(dateNameWeight)
- unitMap[dateNameWeight] = GetWeekly13IndexUnit(name)
- if v, ok1 := dateNameMap[dateName]; ok1 {
- vf, _ := strconv.ParseFloat(v, 64)
- wf, _ := strconv.ParseFloat(weight, 64)
- if vf > wf {
- dateNameWeightPrev := fmt.Sprintf("%s_%s_%s", date, name, v)
- finalNameMap[dateNameWeightPrev] = GetWeekly13IndexName(name, "高")
- finalNameMap[dateNameWeight] = GetWeekly13IndexName(name, "低")
- } else {
- finalNameMap[dateNameWeight] = GetWeekly13IndexName(name, "高")
- }
- } else {
- dateNameMap[dateName] = weight
- //默认是低
- finalNameMap[dateNameWeight] = GetWeekly13IndexName(name, "低")
- }
- }
- }
- }
- for i, row := range rows {
- fmt.Printf("当前第%d行 \n", i)
- // 首行,表示时间
- if i == 0 || i == 1 || i == 2 {
- continue
- } else { //数据列
- date := dateMap[i]
- weight := ""
- for k, text := range row {
- fmt.Printf("当前第%d列 \n", k)
- if k == 0 {
- continue
- } else {
- if k == 1 {
- // 体重
- weight = strings.TrimSpace(text)
- }
- if text == "" {
- continue
- }
- if strings.Contains(text, "%") {
- text = strings.Replace(text, "%", "", 1)
- }
- _, 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))
- continue
- }
- }
- name, ok := nameMap[k]
- if !ok {
- utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 读取 名称失败 Err:%s", sheetName, i, k, "名称不存在"))
- continue
- }
- finalName, ok := finalNameMap[fmt.Sprintf("%s_%s_%s", date, name, weight)]
- if !ok {
- utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 读取 名称失败 Err:%s", sheetName, i, k, "最终名称不存在"))
- continue
- }
- unitNew, ok := unitMap[fmt.Sprintf("%s_%s_%s", date, name, weight)]
- if !ok {
- utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 读取 名称失败 Err:%s", sheetName, i, k, "最终名称不存在"))
- continue
- }
- // 处理指标名称
- fullIndexName := finalName
- fullIndexNamePingyin := namePrefixPingin + utils.GetFirstPingYin(fullIndexName)
- indexItem, okIndex := indexMap[fullIndexName]
- if !okIndex {
- // 新增指标
- indexItem = new(models.YongyiExcelIndex)
- indexItem.IndexName = fullIndexName
- indexItem.ClassifyName = classifyName
- indexItem.ClassifySort = classifySort
- indexItem.IndexCode = fullIndexNamePingyin
- indexItem.Frequency = frequency
- indexItem.Sort = sort
- indexItem.Unit = unitNew
- indexItem.ExcelDataMap = make(map[string]string)
- sort++
- }
- fmt.Printf("indexItem%s", indexItem.IndexCode)
- indexItem.ExcelDataMap[date] = text
- indexMap[fullIndexName] = indexItem
- continue
- }
- }
- }
- for _, v := range indexMap {
- fmt.Printf("IndexName:%s\n", v.IndexName)
- fmt.Printf("IndexCode:%s\n", v.IndexCode)
- indexList = append(indexList, v)
- }
- return
- }
- // HandleYongyiExcelWeekly14 二育销量
- func HandleYongyiExcelWeekly14(f *excelize.File, sheetName string) (indexList []*models.YongyiExcelIndex, err error) {
- defer func() {
- if err != nil {
- fmt.Printf("HandleYongyiExcelWeekly14 二育销量 ErrMsg: %s\n", err.Error())
- utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly14 二育销量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)
- // 遍历行读取
- indexList = make([]*models.YongyiExcelIndex, 0)
- sort := 0
- fmt.Println("最大行")
- // 指标名称
- indexMap := make(map[string]*models.YongyiExcelIndex)
- for i, row := range rows {
- fmt.Printf("当前第%d行 \n", i)
- if i <= 2 {
- continue
- } else { //数据列
- date := ""
- for k, text := range row {
- fmt.Printf("当前第%d列 \n", k)
- if k == 0 {
- if text != "" {
- text = strings.TrimSpace(text)
- var dateT time.Time
- dateSlice := strings.Split(text, "-")
- if len(dateSlice) <= 1 {
- utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 读取行,时间列失败 Err:%s", sheetName, i, k, text))
- continue
- }
- dateT, e = time.ParseInLocation("2006年1月2日", dateSlice[0]+"日", time.Local)
- if e != nil {
- utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 读取行,时间列失败 Err:%s", sheetName, i, k, e))
- continue
- }
- date = dateT.Format("2006年1月") + dateSlice[1]
- dateT, e = time.ParseInLocation("2006年1月2日", date, time.Local)
- if e != nil {
- utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 读取行,时间列失败 Err:%s", sheetName, i, k, e))
- continue
- }
- date = dateT.Format(utils.FormatDate)
- fmt.Println("date: " + date)
- }
- continue
- } else {
- // 判断出不是字符的,则过滤
- if text == "" {
- continue
- }
- if strings.Contains(text, "%") {
- text = strings.Replace(text, "%", "", 1)
- }
- _, 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))
- continue
- }
- }
- name := "二育占实际销量(十天)"
- // 处理指标名称
- fullIndexName := fmt.Sprintf("%s/%s", namePrefix, name)
- provincePingyin := utils.GetFirstPingYin(name)
- fullIndexNamePingyin := namePrefixPingin + provincePingyin
- indexItem, okIndex := indexMap[fullIndexName]
- if !okIndex {
- // 新增指标
- indexItem = new(models.YongyiExcelIndex)
- indexItem.IndexName = fullIndexName
- indexItem.ClassifyName = classifyName
- indexItem.ClassifySort = classifySort
- indexItem.IndexCode = fullIndexNamePingyin
- indexItem.Frequency = frequency
- indexItem.Sort = sort
- indexItem.Unit = unit
- indexItem.ExcelDataMap = make(map[string]string)
- sort++
- }
- fmt.Printf("IndexCode: %s", indexItem.IndexCode)
- indexItem.ExcelDataMap[date] = text
- indexMap[fullIndexName] = indexItem
- continue
- }
- }
- }
- for _, v := range indexMap {
- indexList = append(indexList, v)
- }
- return
- }
- // HandleYongyiExcelWeekly15 育肥栏舍利用率
- func HandleYongyiExcelWeekly15(f *excelize.File, sheetName string) (indexList []*models.YongyiExcelIndex, err error) {
- defer func() {
- if err != nil {
- fmt.Printf("HandleYongyiExcelWeekly15 育肥栏舍利用率 ErrMsg: %s\n", err.Error())
- utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly15 育肥栏舍利用率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)
- // 遍历行读取
- indexList = make([]*models.YongyiExcelIndex, 0)
- dateMap := make(map[int]string)
- sort := 0
- fmt.Println("最大行")
- // 指标名称
- indexMap := make(map[string]*models.YongyiExcelIndex)
- for i, row := range rows {
- fmt.Printf("当前第%d行 \n", i)
- if i == 0 {
- continue
- } else if i == 1 { //表示表头
- // 处理 index指标表
- for k, text := range row {
- if text != "" {
- text = strings.TrimSpace(text)
- var dateT time.Time
- dateT, e = time.ParseInLocation("01-2-06", text, time.Local)
- if e != nil {
- utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 读取行,时间列失败 Err:%s", sheetName, i, k, e))
- continue
- }
- dateMap[k] = dateT.Format(utils.FormatDate)
- fmt.Println("date: " + dateMap[k])
- }
- }
- } else { //数据列
- province := ""
- for k, text := range row {
- fmt.Printf("当前第%d列 \n", k)
- if k == 0 {
- continue
- } else if k == 1 {
- province = strings.TrimSpace(text)
- continue
- } else {
- // 判断出不是字符的,则过滤
- if text == "" {
- continue
- }
- if strings.Contains(text, "%") {
- text = strings.Replace(text, "%", "", 1)
- }
- _, 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))
- continue
- }
- }
- date, ok2 := dateMap[k]
- if !ok2 {
- utils.FileLog.Info(fmt.Sprintf("找不到对应的时间,第%d行,第%d列", i, k))
- continue
- }
- fmt.Printf("当前第%d行第%d列, 当前省份%s \n", i, k, province)
- // 处理指标名称
- fullIndexName := fmt.Sprintf("%s/%s", namePrefix, province)
- provincePingyin := utils.GetFullPingYin(province)
- fullIndexNamePingyin := namePrefixPingin + provincePingyin
- indexItem, okIndex := indexMap[fullIndexName]
- if !okIndex {
- // 新增指标
- indexItem = new(models.YongyiExcelIndex)
- indexItem.IndexName = fullIndexName
- indexItem.ClassifyName = classifyName
- indexItem.ClassifySort = classifySort
- indexItem.IndexCode = fullIndexNamePingyin
- indexItem.Frequency = frequency
- indexItem.Sort = sort
- indexItem.Unit = unit
- indexItem.ExcelDataMap = make(map[string]string)
- sort++
- }
- fmt.Printf("IndexCode: %s", indexItem.IndexCode)
- indexItem.ExcelDataMap[date] = text
- indexMap[fullIndexName] = indexItem
- continue
- }
- }
- }
- for _, v := range indexMap {
- indexList = append(indexList, v)
- }
- return
- }
- // HandleYongyiExcelWeekly16 周度-养殖利润最新
- func HandleYongyiExcelWeekly16(f *excelize.File, sheetName string) (indexList []*models.YongyiExcelIndex, err error) {
- defer func() {
- if err != nil {
- fmt.Printf("HandleYongyiExcelWeekly16 周度-养殖利润最新 ErrMsg: %s\n", err.Error())
- utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly16 周度-养殖利润最新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)
- // 遍历行读取
- indexList = make([]*models.YongyiExcelIndex, 0)
- nameMap := make(map[int]string)
- sort := 0
- fmt.Println("最大行")
- // 指标名称
- indexMap := make(map[string]*models.YongyiExcelIndex)
- mergeCellMap, err := GetMergeCells(f, sheetName)
- if err != nil {
- err = fmt.Errorf("获取合并单元格失败, sheetName: %s", sheetName)
- return
- }
- for i, row := range rows {
- fmt.Printf("当前第%d行 \n", i)
- currentMergeCells, mergeOk := mergeCellMap[i]
- if i == 0 {
- continue
- } else if i <= 1 || i == 2 { //表示表头
- // 处理 index指标表
- for k, text := range row {
- if text != "" {
- text = strings.TrimSpace(text)
- if mergeOk {
- for j, v := range currentMergeCells {
- nameMap[j] = v
- }
- }
- nameMap[k] = text
- }
- }
- } else { //数据列
- date := ""
- for k, text := range row {
- fmt.Printf("当前第%d列 \n", k)
- if k == 0 {
- continue
- } else if k == 1 {
- text = strings.TrimSpace(text)
- var dateT time.Time
- dateT, e = time.ParseInLocation("2006/1/2", text, time.Local)
- if e != nil {
- utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 读取行,时间列失败 Err:%s", sheetName, i, k, e))
- continue
- }
- date = dateT.Format(utils.FormatDate)
- fmt.Println(date)
- continue
- } else {
- // 判断出不是字符的,则过滤
- if text == "" {
- continue
- }
- if strings.Contains(text, "%") {
- text = strings.Replace(text, "%", "", 1)
- }
- _, 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))
- continue
- }
- }
- name, ok1 := nameMap[k]
- if !ok1 {
- err = fmt.Errorf("找不到对应的列名,第%d行,第%d列", i, k)
- return
- }
- if name != "外购仔猪育肥" && name != "合同农户\n(放养部分)" {
- if !strings.Contains(name, "母猪") {
- name = fmt.Sprintf("母猪%s", name)
- }
- }
- if name == "合同农户\n(放养部分)" {
- name = "合同农户(放养部分)"
- }
- // 处理指标名称
- fullIndexName := fmt.Sprintf("%s/%s", namePrefix, name)
- areaPingyin := utils.GetFirstPingYin(name)
- fullIndexNamePingyin := namePrefixPingin + areaPingyin
- indexItem, okIndex := indexMap[fullIndexName]
- if !okIndex {
- // 新增指标
- indexItem = new(models.YongyiExcelIndex)
- indexItem.IndexName = fullIndexName
- indexItem.ClassifyName = classifyName
- indexItem.ClassifySort = classifySort
- indexItem.IndexCode = fullIndexNamePingyin
- indexItem.Frequency = frequency
- indexItem.Sort = sort
- indexItem.Unit = unit
- indexItem.ExcelDataMap = make(map[string]string)
- sort++
- }
- fmt.Printf("IndexCode: %s\n", indexItem.IndexCode)
- indexItem.ExcelDataMap[date] = text
- indexMap[fullIndexName] = indexItem
- continue
- }
- }
- }
- for _, v := range indexMap {
- indexList = append(indexList, v)
- }
- return
- }
- // HandleYongyiExcelWeekly17 周度-当期、预期成本
- func HandleYongyiExcelWeekly17(f *excelize.File, sheetName string) (indexList []*models.YongyiExcelIndex, err error) {
- defer func() {
- if err != nil {
- fmt.Printf("HandleYongyiExcelWeekly17 周度-当期、预期成本 ErrMsg: %s\n", err.Error())
- utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly17 周度-当期、预期成本 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)
- // 遍历行读取
- indexList = make([]*models.YongyiExcelIndex, 0)
- dateMap := make(map[int]string)
- sort := 0
- // 指标名称
- indexMap := make(map[string]*models.YongyiExcelIndex)
- for i, row := range rows {
- fmt.Printf("当前第%d行 \n", i)
- if i > 22 {
- break
- }
- if i == 0 {
- namePrefix = "出栏肥猪成本"
- namePrefixPingin = "yyzx" + utils.GetFirstPingYin(namePrefix)
- continue
- } else if i == 11 {
- namePrefix = "断奶仔猪对应育肥至标猪出栏成本"
- namePrefixPingin = "yyzx" + utils.GetFirstPingYin(namePrefix)
- continue
- } else if i == 1 { //表示表头
- // 处理 index指标表
- for k, text := range row {
- if text != "" {
- text = strings.TrimSpace(text) //2024.1.12-2024.1.18
- dateSlice := strings.Split(text, "-")
- if len(dateSlice) <= 1 {
- utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 读取行,时间列失败 Err:%s", sheetName, i, k, e))
- continue
- }
- var dateT time.Time
- dateT, e = time.ParseInLocation("2006.1.2", dateSlice[1], time.Local)
- if e != nil {
- utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 读取行,时间列失败 Err:%s", sheetName, i, k, e))
- continue
- }
- dateMap[k] = dateT.Format(utils.FormatDate)
- fmt.Println("date: " + dateMap[k])
- }
- }
- } else { //数据列
- name := ""
- for k, text := range row {
- fmt.Printf("当前第%d列 \n", k)
- if k == 0 {
- continue
- } else if k == 1 || k == 2 {
- text = strings.TrimSpace(text)
- if text != "" {
- name = text
- }
- continue
- } else {
- // 判断出不是字符的,则过滤
- if text == "" {
- continue
- }
- if strings.Contains(text, "%") {
- text = strings.Replace(text, "%", "", 1)
- }
- _, 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))
- continue
- }
- }
- date, ok2 := dateMap[k]
- if !ok2 {
- utils.FileLog.Info(fmt.Sprintf("找不到对应的时间,第%d行,第%d列", i, k))
- continue
- }
- if name != "外购仔猪育肥" && name != "合同农户(放养部分)" {
- if !strings.Contains(name, "母猪") {
- name = fmt.Sprintf("母猪%s", name)
- }
- }
- // 处理指标名称
- fullIndexName := fmt.Sprintf("%s/%s", namePrefix, name)
- provincePingyin := utils.GetFirstPingYin(name)
- fullIndexNamePingyin := namePrefixPingin + provincePingyin
- indexItem, okIndex := indexMap[fullIndexName]
- if !okIndex {
- // 新增指标
- indexItem = new(models.YongyiExcelIndex)
- indexItem.IndexName = fullIndexName
- indexItem.ClassifyName = classifyName
- indexItem.ClassifySort = classifySort
- indexItem.IndexCode = fullIndexNamePingyin
- indexItem.Frequency = frequency
- indexItem.Sort = sort
- indexItem.Unit = unit
- indexItem.ExcelDataMap = make(map[string]string)
- sort++
- }
- fmt.Printf("IndexCode: %s", indexItem.IndexCode)
- indexItem.ExcelDataMap[date] = text
- indexMap[fullIndexName] = indexItem
- continue
- }
- }
- }
- for _, v := range indexMap {
- indexList = append(indexList, v)
- }
- return
- }
- // HandleYongyiExcelWeekly18 育肥全价料出厂价
- func HandleYongyiExcelWeekly18(f *excelize.File, sheetName string) (indexList []*models.YongyiExcelIndex, err error) {
- defer func() {
- if err != nil {
- fmt.Printf("HandleYongyiExcelWeekly18 育肥全价料出厂价 ErrMsg: %s\n", err.Error())
- utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly18 育肥全价料出厂价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)
- // 遍历行读取
- indexList = make([]*models.YongyiExcelIndex, 0)
- provinceMap := make(map[int]string)
- sort := 0
- // 指标名称
- indexMap := make(map[string]*models.YongyiExcelIndex)
- for i, row := range rows {
- fmt.Printf("当前第%d行 \n", i)
- // 首行,表示时间
- if i <= 2 {
- continue
- } else if i == 3 { //表示表头
- // 处理 index指标表
- for k, text := range row {
- fmt.Printf("当前第%d列 \n", k)
- if text != "" {
- provinceMap[k] = text
- }
- }
- } else { //数据列
- date := ""
- for k, text := range row {
- fmt.Printf("当前第%d列 \n", k)
- if k == 0 {
- // 日期
- text = strings.TrimSpace(text)
- var dateT time.Time
- dateT, e = time.ParseInLocation("01-2-06", text, time.Local)
- if e != nil {
- utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 读取行,时间列失败 Err:%s", sheetName, i, k, e))
- continue
- }
- date = dateT.Format(utils.FormatDate)
- fmt.Println(date)
- continue
- } else {
- if text == "" {
- continue
- }
- if strings.Contains(text, "%") {
- text = strings.Replace(text, "%", "", 1)
- }
- _, 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))
- continue
- }
- }
- province, ok2 := provinceMap[k]
- if !ok2 {
- err = fmt.Errorf("找不到对应的列名,第%d行,第%d列", i, k)
- return
- }
- fmt.Printf("当前第%d行第%d列, 当前省份%s \n", i, k, province)
- // 处理指标名称
- fullIndexName := fmt.Sprintf("%s/%s", namePrefix, province)
- provincePingyin := utils.GetFullPingYin(province)
- fullIndexNamePingyin := namePrefixPingin + provincePingyin
- if province == "均价" {
- province = "全国均价"
- fullIndexName = fmt.Sprintf("%s/%s", namePrefix, province)
- provincePingyin = utils.GetFirstPingYin(province)
- fullIndexNamePingyin = namePrefixPingin + provincePingyin
- }
- indexItem, okIndex := indexMap[fullIndexName]
- if !okIndex {
- // 新增指标
- indexItem = new(models.YongyiExcelIndex)
- indexItem.IndexName = fullIndexName
- indexItem.ClassifyName = classifyName
- indexItem.ClassifySort = classifySort
- indexItem.IndexCode = fullIndexNamePingyin
- indexItem.Frequency = frequency
- indexItem.Sort = sort
- indexItem.Unit = unit
- indexItem.ExcelDataMap = make(map[string]string)
- sort++
- }
- fmt.Printf("indexItem%s", indexItem.IndexCode)
- indexItem.ExcelDataMap[date] = text
- indexMap[fullIndexName] = indexItem
- continue
- }
- }
- }
- for _, v := range indexMap {
- indexList = append(indexList, v)
- }
- return
- }
- // HandleYongyiExcelWeekly19 周度-成本计算附件
- func HandleYongyiExcelWeekly19(f *excelize.File, sheetName string) (indexList []*models.YongyiExcelIndex, err error) {
- defer func() {
- if err != nil {
- fmt.Printf("HandleYongyiExcelWeekly19 周度-成本计算附件 ErrMsg: %s\n", err.Error())
- utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly19 周度-成本计算附件 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, _, namePrefixPingin := GetBaseInfo(sheetName)
- // 遍历行读取
- indexList = make([]*models.YongyiExcelIndex, 0)
- dateMap := make(map[int]string)
- areaMap := make(map[int]string)
- valNameMap := make(map[int]string)
- sort := 0
- mergeCellMap, err := GetMergeCells(f, sheetName)
- if err != nil {
- err = fmt.Errorf("获取合并单元格失败, sheetName: %s", sheetName)
- return
- }
- // 指标名称
- indexMap := make(map[string]*models.YongyiExcelIndex)
- name := ""
- for i, row := range rows {
- fmt.Printf("当前第%d行 \n", i)
- currentMergeCells, mergeOk := mergeCellMap[i]
- if i == 0 { //表示表头
- // 处理 index指标表
- for k, text := range row {
- if k > 9 && text != "" {
- var dateT time.Time
- text = strings.TrimSpace(text) //2024.1.12-2024.1.18
- if mergeOk {
- for j, v := range currentMergeCells {
- dateSlice := strings.Split(v, "-")
- if len(dateSlice) <= 1 {
- utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 读取行,时间列失败 Err:%s", sheetName, i, k, e))
- continue
- }
- dateT, e = time.ParseInLocation("2006.1.2", dateSlice[1], time.Local)
- if e != nil {
- utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 读取行,时间列失败 Err:%s", sheetName, i, k, e))
- continue
- }
- dateMap[j] = dateT.Format(utils.FormatDate)
- }
- }
- dateSlice := strings.Split(text, "-")
- if len(dateSlice) <= 1 {
- utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 读取行,时间列失败 Err:%s", sheetName, i, k, e))
- continue
- }
- dateT, e = time.ParseInLocation("2006.1.2", dateSlice[1], time.Local)
- if e != nil {
- utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 读取行,时间列失败 Err:%s", sheetName, i, k, e))
- continue
- }
- dateMap[k] = dateT.Format(utils.FormatDate)
- fmt.Println("date: " + dateMap[k])
- }
- }
- } else if i == 1 {
- for k, text := range row {
- if text != "" {
- text = strings.TrimSpace(text)
- if mergeOk {
- for j, v := range currentMergeCells {
- areaMap[j] = v
- }
- }
- areaMap[k] = text
- }
- }
- } else if i == 2 {
- for k, text := range row {
- if text != "" {
- text = strings.TrimSpace(text)
- valNameMap[k] = text
- }
- }
- } else { //数据列
- subName := ""
- for k, text := range row {
- fmt.Printf("当前第%d列 \n", k)
- if k == 0 {
- continue
- } else if k == 1 || k == 2 {
- text = strings.TrimSpace(text)
- if text != "" {
- name = text
- }
- fmt.Printf("name: %s \n", name)
- continue
- } else if k == 3 || k == 4 {
- text = strings.TrimSpace(text)
- if text != "" {
- subName = text
- }
- continue
- } else {
- // 判断出不是字符的,则过滤
- if text == "" {
- continue
- }
- if strings.Contains(text, "%") {
- text = strings.Replace(text, "%", "", 1)
- }
- _, 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))
- continue
- }
- }
- valName, ok1 := valNameMap[k]
- if !ok1 {
- utils.FileLog.Info(fmt.Sprintf("找不到对应的时间,第%d行,第%d列", i, k))
- continue
- }
- area, ok2 := areaMap[k]
- if !ok2 {
- utils.FileLog.Info(fmt.Sprintf("找不到对应的时间,第%d行,第%d列", i, k))
- continue
- }
- area = strings.Replace(area, "本周", "", 1)
- date, ok2 := dateMap[k]
- if !ok2 {
- utils.FileLog.Info(fmt.Sprintf("找不到对应的时间,第%d行,第%d列", i, k))
- continue
- }
- if strings.Contains(name, "-") && !strings.Contains(name, "母猪") {
- name = "母猪" + name
- }
- // 处理指标名称
- fullIndexName := fmt.Sprintf("%s/%s", area, name)
- provincePingyin := utils.GetFirstPingYin(area + name)
- fullIndexNamePingyin := namePrefixPingin + provincePingyin
- if strings.Contains(valName, "成本") {
- if strings.Contains(area, "出栏肥猪") || name == "料肉比" || name == "上市均重(公斤)" || name == "育肥成活率(中高水平)" || name == "1周" {
- continue
- } else {
- fullIndexName = fmt.Sprintf("%s/%s/%s", area, name, "成本")
- provincePingyin = utils.GetFirstPingYin(area + name + "成本")
- fullIndexNamePingyin = namePrefixPingin + provincePingyin
- }
- } else {
- if subName != "" {
- fullIndexName = fmt.Sprintf("%s/%s/%s", area, name, subName)
- provincePingyin = utils.GetFirstPingYin(area + name + subName)
- fullIndexNamePingyin = namePrefixPingin + provincePingyin
- }
- }
- indexItem, okIndex := indexMap[fullIndexName]
- if !okIndex {
- // 新增指标
- indexItem = new(models.YongyiExcelIndex)
- indexItem.IndexName = fullIndexName
- indexItem.ClassifyName = classifyName
- indexItem.ClassifySort = classifySort
- indexItem.IndexCode = fullIndexNamePingyin
- indexItem.Frequency = frequency
- indexItem.Sort = sort
- indexItem.Unit = unit
- indexItem.ExcelDataMap = make(map[string]string)
- sort++
- }
- //fmt.Printf("IndexCode: %s", indexItem.IndexCode)
- indexItem.ExcelDataMap[date] = text
- indexMap[fullIndexName] = indexItem
- continue
- }
- }
- }
- for _, v := range indexMap {
- fmt.Printf("IndexName: %s \n", v.IndexName)
- fmt.Printf("IndexCode: %s \n", v.IndexCode)
- indexList = append(indexList, v)
- }
- return
- }
- // HandleYongyiExcelWeekly20 周度-毛白价差
- func HandleYongyiExcelWeekly20(f *excelize.File, sheetName string) (indexList []*models.YongyiExcelIndex, err error) {
- defer func() {
- if err != nil {
- fmt.Printf("HandleYongyiExcelWeekly20 周度-毛白价差 ErrMsg: %s\n", err.Error())
- utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly20 周度-毛白价差 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)
- // 遍历行读取
- indexList = make([]*models.YongyiExcelIndex, 0)
- nameMap := make(map[int]string)
- sort := 0
- // 指标名称
- indexMap := make(map[string]*models.YongyiExcelIndex)
- for i, row := range rows {
- fmt.Printf("当前第%d行 \n", i)
- // 首行,表示时间
- if i == 0 { //表示表头
- // 处理 index指标表
- for k, text := range row {
- fmt.Printf("当前第%d列 \n", k)
- if text != "" {
- nameMap[k] = text
- }
- }
- } else { //数据列
- date := ""
- for k, text := range row {
- fmt.Printf("当前第%d列 \n", k)
- if k == 0 {
- // 日期
- text = strings.TrimSpace(text)
- var dateT time.Time
- dateT, e = time.ParseInLocation("2006/1/2", text, time.Local)
- if e != nil {
- utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 读取行,时间列失败 Err:%s", sheetName, i, k, e))
- continue
- }
- date = dateT.Format(utils.FormatDate)
- fmt.Println(date)
- continue
- } else {
- if text == "" {
- continue
- }
- if strings.Contains(text, "%") {
- text = strings.Replace(text, "%", "", 1)
- }
- _, 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))
- continue
- }
- }
- name, ok2 := nameMap[k]
- if !ok2 {
- err = fmt.Errorf("找不到对应的列名,第%d行,第%d列", i, k)
- return
- }
- if name != "前三级别白条价" && name != "生猪出栏价" {
- continue
- }
- // 处理指标名称
- fullIndexName := fmt.Sprintf("%s/%s", namePrefix, name)
- provincePingyin := utils.GetFirstPingYin(name)
- fullIndexNamePingyin := namePrefixPingin + provincePingyin
- indexItem, okIndex := indexMap[fullIndexName]
- if !okIndex {
- // 新增指标
- indexItem = new(models.YongyiExcelIndex)
- indexItem.IndexName = fullIndexName
- indexItem.ClassifyName = classifyName
- indexItem.ClassifySort = classifySort
- indexItem.IndexCode = fullIndexNamePingyin
- indexItem.Frequency = frequency
- indexItem.Sort = sort
- indexItem.Unit = unit
- indexItem.ExcelDataMap = make(map[string]string)
- sort++
- }
- fmt.Printf("indexItem%s", indexItem.IndexCode)
- indexItem.ExcelDataMap[date] = text
- indexMap[fullIndexName] = indexItem
- continue
- }
- }
- }
- for _, v := range indexMap {
- indexList = append(indexList, v)
- }
- return
- }
|