week50.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. package base_from_yongyi_v2
  2. import (
  3. "eta/eta_data_analysis/models"
  4. "eta/eta_data_analysis/utils"
  5. "fmt"
  6. "regexp"
  7. "strconv"
  8. "strings"
  9. "time"
  10. "github.com/xuri/excelize/v2"
  11. )
  12. // HandleYongyiExcelWeekly41 月度-小猪(50斤以下)存栏
  13. func HandleYongyiExcelWeekly41(f *excelize.File, sheetName string) (indexList []*models.YongyiExcelIndex, err error) {
  14. defer func() {
  15. if err != nil {
  16. utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly40 国产冻品2-4号肉价格 ErrMsg: %s", err.Error()))
  17. }
  18. }()
  19. cols, err := f.GetCols(sheetName)
  20. if err != nil {
  21. err = fmt.Errorf("f GetCols err: %s", err.Error())
  22. return
  23. }
  24. classifyName, classifySort, frequency, unit, namePrefix, namePrefixPingin := GetBaseInfo(sheetName)
  25. sort := 0
  26. var preIndexName string
  27. dateIndexList := make([]string, 0)
  28. indexInfoMap := make(map[string]*models.YongyiExcelIndex)
  29. indexNamePart2 := map[string]struct{}{"全国": {}, "华北": {}, "东北": {}, "华中": {}, "华东": {}, "华南": {}, "西南": {}}
  30. for i, col := range cols {
  31. if len(col) <= 3 {
  32. continue
  33. }
  34. if i == 0 && col[1] == "日期" {
  35. for _, cell := range col {
  36. tmpDateTime, err := time.Parse("2006年1月", cell)
  37. if err != nil {
  38. dateIndexList = append(dateIndexList, "")
  39. } else {
  40. dateTime := LastDayOfMonth(tmpDateTime.Year(), tmpDateTime.Month())
  41. dateIndexList = append(dateIndexList, dateTime)
  42. }
  43. }
  44. }
  45. if len(dateIndexList) == 0 {
  46. continue
  47. }
  48. if col[1] != "" && col[1] != "日期" {
  49. var indexName, indexNameSuffix string
  50. if _, ok := indexNamePart2[col[1]]; ok {
  51. preIndexName = col[1]
  52. indexName = fmt.Sprintf("%s/%s", namePrefix, col[1])
  53. indexNameSuffix = col[1]
  54. } else if col[1] == "环比" {
  55. indexName = fmt.Sprintf("%s(%s)/%s", namePrefix, col[1], preIndexName)
  56. indexNameSuffix = fmt.Sprintf("(%s)%s", col[1], preIndexName)
  57. } else {
  58. continue
  59. }
  60. for j, cell := range col {
  61. if !isValueValid(cell) {
  62. continue
  63. }
  64. if indexInfo, ok := indexInfoMap[indexName]; !ok {
  65. tmpYongyiIndex := new(models.YongyiExcelIndex)
  66. tmpYongyiIndex.ClassifyName = classifyName
  67. tmpYongyiIndex.ClassifySort = classifySort
  68. tmpYongyiIndex.Frequency = frequency
  69. tmpYongyiIndex.Unit = unit
  70. tmpYongyiIndex.IndexName = indexName
  71. tmpYongyiIndex.IndexCode = namePrefixPingin + utils.GetFirstPingYin(indexNameSuffix)
  72. tmpYongyiIndex.Sort = sort
  73. tmpYongyiIndex.ExcelDataMap = make(map[string]string)
  74. if string(cell[len(cell)-1]) == `%` {
  75. tmpYongyiIndex.Unit = `%`
  76. tmpYongyiIndex.ExcelDataMap[dateIndexList[j]] = cell[:len(cell)-1]
  77. } else {
  78. tmpYongyiIndex.ExcelDataMap[dateIndexList[j]] = cell
  79. }
  80. indexInfoMap[indexName] = tmpYongyiIndex
  81. indexList = append(indexList, tmpYongyiIndex)
  82. sort++
  83. } else {
  84. if string(cell[len(cell)-1]) == `%` {
  85. indexInfo.ExcelDataMap[dateIndexList[j]] = cell[:len(cell)-1]
  86. } else {
  87. indexInfo.ExcelDataMap[dateIndexList[j]] = cell
  88. }
  89. }
  90. }
  91. }
  92. }
  93. utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly41 %s 更新指标数量:%d", sheetName, len(indexList)))
  94. return
  95. }
  96. // HandleYongyiExcelWeekly42 月度猪肉供应占比
  97. func HandleYongyiExcelWeekly42(f *excelize.File, sheetName string) (indexList []*models.YongyiExcelIndex, err error) {
  98. defer func() {
  99. if err != nil {
  100. utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly40 月度猪肉供应占比 ErrMsg: %s", err.Error()))
  101. }
  102. }()
  103. rows, err := f.GetRows(sheetName)
  104. if err != nil {
  105. err = fmt.Errorf("f GetRows err: %s", err.Error())
  106. return
  107. }
  108. classifyName, classifySort, frequency, unit, namePrefix, namePrefixPingin := GetBaseInfo(sheetName)
  109. re := regexp.MustCompile(`[+-]?[0-9]*\.?[0-9]+`)
  110. yearIndexMap := make(map[int]string)
  111. yongyiExcelIndex := new(models.YongyiExcelIndex)
  112. yongyiExcelIndex.ClassifyName = classifyName
  113. yongyiExcelIndex.ClassifySort = classifySort
  114. yongyiExcelIndex.Frequency = frequency
  115. yongyiExcelIndex.Unit = unit
  116. yongyiExcelIndex.IndexName = namePrefix
  117. yongyiExcelIndex.IndexCode = namePrefixPingin
  118. yongyiExcelIndex.Sort = 0
  119. yongyiExcelIndex.ExcelDataMap = make(map[string]string)
  120. indexList = append(indexList, yongyiExcelIndex)
  121. for i, row := range rows {
  122. if i == 0 {
  123. // 记录年份索引
  124. for j, cell := range row {
  125. if isValueValid(cell) {
  126. yearIndexMap[j] = cell
  127. }
  128. }
  129. } else {
  130. var month string
  131. for j, cell := range row {
  132. if j == 0 {
  133. if tmp := re.FindString(cell); tmp != "" {
  134. month = tmp
  135. continue
  136. }
  137. }
  138. if month == "" {
  139. break
  140. }
  141. tmpYear, err := strconv.Atoi(yearIndexMap[j])
  142. if err != nil {
  143. continue
  144. }
  145. tmpMonth, err := strconv.Atoi(month)
  146. if err != nil {
  147. continue
  148. }
  149. dataTime := LastDayOfMonth(tmpYear, time.Month(tmpMonth))
  150. if isValueValid(cell) {
  151. newCell := strings.ReplaceAll(cell, "%", "")
  152. yongyiExcelIndex.ExcelDataMap[dataTime] = newCell
  153. }
  154. }
  155. }
  156. }
  157. utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly42 %s 更新指标数量:%d", sheetName, len(indexList)))
  158. return
  159. }
  160. // HandleYongyiExcelWeekly43 历史出栏体重
  161. func HandleYongyiExcelWeekly43(f *excelize.File, sheetName string) (indexList []*models.YongyiExcelIndex, err error) {
  162. defer func() {
  163. if err != nil {
  164. utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly43 %s ErrMsg: %s", sheetName, err.Error()))
  165. }
  166. }()
  167. rows, err := f.GetRows(sheetName)
  168. if err != nil {
  169. err = fmt.Errorf("f GetRows err: %s", err.Error())
  170. return
  171. }
  172. re := regexp.MustCompile(`\d+`)
  173. classifyName, classifySort, frequency, unit, namePrefix, namePrefixPingin := GetBaseInfo(sheetName)
  174. yongyiExcelIndex := new(models.YongyiExcelIndex)
  175. yongyiExcelIndex.ClassifyName = classifyName
  176. yongyiExcelIndex.ClassifySort = classifySort
  177. yongyiExcelIndex.Frequency = frequency
  178. yongyiExcelIndex.Unit = unit
  179. yongyiExcelIndex.IndexName = namePrefix
  180. yongyiExcelIndex.IndexCode = namePrefixPingin
  181. yongyiExcelIndex.Sort = 0
  182. yongyiExcelIndex.ExcelDataMap = make(map[string]string)
  183. indexList = append(indexList, yongyiExcelIndex)
  184. for i, row := range rows {
  185. if i == 0 {
  186. continue
  187. }
  188. if len(row) < 2 {
  189. continue
  190. }
  191. dateArr := re.FindAllString(row[0], -1)
  192. year, err := strconv.Atoi(dateArr[0])
  193. if err != nil {
  194. continue
  195. }
  196. week, err := strconv.Atoi(dateArr[1])
  197. if err != nil {
  198. continue
  199. }
  200. if !isValueValid(row[1]) {
  201. continue
  202. }
  203. date := getSundayOfWeek(year, week)
  204. yongyiExcelIndex.ExcelDataMap[date] = row[1]
  205. }
  206. utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly43 %s 更新指标数量:%d", sheetName, len(indexList)))
  207. return
  208. }
  209. // HandleYongyiExcelWeekly44 重要部位冻品进口
  210. func HandleYongyiExcelWeekly44(f *excelize.File, sheetName string) (indexList []*models.YongyiExcelIndex, err error) {
  211. defer func() {
  212. if err != nil {
  213. utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly44 %s ErrMsg: %s", sheetName, err.Error()))
  214. }
  215. }()
  216. cols, err := f.GetCols(sheetName)
  217. if err != nil {
  218. err = fmt.Errorf("f GetCols err: %s", err.Error())
  219. return
  220. }
  221. classifyName, classifySort, frequency, _, namePrefix, namePrefixPingin := GetBaseInfo(sheetName)
  222. sort := 0
  223. re := regexp.MustCompile(`\d+`)
  224. dateIndexMap := make(map[int]string)
  225. for i, col := range cols {
  226. if i == 0 {
  227. for j, cell := range col {
  228. dateArr := re.FindAllString(cell, -1)
  229. if len(dateArr) != 2 {
  230. continue
  231. }
  232. year, err := strconv.Atoi(dateArr[0])
  233. if err != nil {
  234. continue
  235. }
  236. month, err := strconv.Atoi(dateArr[1])
  237. if err != nil {
  238. continue
  239. }
  240. dateIndexMap[j] = LastDayOfMonth(year, time.Month(month))
  241. }
  242. } else {
  243. if len(col) < 2 {
  244. continue
  245. }
  246. if col[1] == "" {
  247. continue
  248. }
  249. indexName := fmt.Sprintf("%s/%s", namePrefix, col[1])
  250. yongyiExcelIndex := new(models.YongyiExcelIndex)
  251. yongyiExcelIndex.ClassifyName = classifyName
  252. yongyiExcelIndex.ClassifySort = classifySort
  253. yongyiExcelIndex.Frequency = frequency
  254. yongyiExcelIndex.IndexName = indexName
  255. yongyiExcelIndex.IndexCode = namePrefixPingin + utils.GetFirstPingYin(col[1])
  256. yongyiExcelIndex.Sort = sort
  257. yongyiExcelIndex.ExcelDataMap = make(map[string]string)
  258. if col[1] == "柜数" {
  259. yongyiExcelIndex.Unit = "个"
  260. } else if col[1] == "合计" {
  261. yongyiExcelIndex.Unit = "kg"
  262. } else {
  263. continue
  264. }
  265. for j, cell := range col {
  266. if j == 0 {
  267. continue
  268. }
  269. cell = strings.ReplaceAll(cell, ",", "")
  270. if !isValueValid(cell) {
  271. continue
  272. }
  273. yongyiExcelIndex.ExcelDataMap[dateIndexMap[j]] = cell
  274. }
  275. indexList = append(indexList, yongyiExcelIndex)
  276. sort++
  277. }
  278. }
  279. utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly44 %s 更新指标数量:%d", sheetName, len(indexList)))
  280. return
  281. }
  282. // HandleYongyiExcelWeekly45 各存栏规模
  283. func HandleYongyiExcelWeekly45(f *excelize.File, sheetName string) (indexList []*models.YongyiExcelIndex, err error) {
  284. defer func() {
  285. if err != nil {
  286. utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly45 %s ErrMsg: %s", sheetName, err.Error()))
  287. }
  288. }()
  289. rows, err := f.GetRows(sheetName)
  290. if err != nil {
  291. err = fmt.Errorf("f GetRows err: %s", err.Error())
  292. return
  293. }
  294. classifyName, classifySort, frequency, unit, namePrefix, namePrefixPingin := GetBaseInfo(sheetName)
  295. sort := 0
  296. re := regexp.MustCompile(`\d+`)
  297. indexNamePart3 := make([]string, 0)
  298. indexInfoMap := make(map[string]*models.YongyiExcelIndex)
  299. for i, row := range rows {
  300. if i == 0 {
  301. continue
  302. }
  303. if i == 1 {
  304. for j, cell := range row {
  305. if j >= 2 {
  306. indexNamePart3 = append(indexNamePart3, cell)
  307. } else {
  308. indexNamePart3 = append(indexNamePart3, "")
  309. }
  310. }
  311. }
  312. if len(row) == 0 {
  313. break
  314. }
  315. if i > 1 && len(row) > 2 {
  316. var date string
  317. for j, cell := range row {
  318. if j == 0 {
  319. dateArr := re.FindAllString(cell, -1)
  320. if len(dateArr) != 2 {
  321. break
  322. }
  323. year, err := strconv.Atoi(dateArr[0])
  324. if err != nil {
  325. break
  326. }
  327. month, err := strconv.Atoi(dateArr[1])
  328. if err != nil {
  329. break
  330. }
  331. date = LastDayOfMonth(year, time.Month(month))
  332. }
  333. if !isValueValid(cell) {
  334. continue
  335. }
  336. indexName := fmt.Sprintf("%s/%s/%s", namePrefix, row[1], indexNamePart3[j])
  337. if indexInfo, ok := indexInfoMap[indexName]; !ok {
  338. tmpYongyiIndex := new(models.YongyiExcelIndex)
  339. tmpYongyiIndex.ClassifyName = classifyName
  340. tmpYongyiIndex.ClassifySort = classifySort
  341. tmpYongyiIndex.Frequency = frequency
  342. tmpYongyiIndex.Unit = unit
  343. tmpYongyiIndex.IndexName = indexName
  344. tmpYongyiIndex.IndexCode = namePrefixPingin + utils.GetFirstPingYin(row[1]+indexNamePart3[j])
  345. tmpYongyiIndex.Sort = sort
  346. tmpYongyiIndex.ExcelDataMap = make(map[string]string)
  347. newCell := strings.ReplaceAll(cell, "%", "")
  348. tmpYongyiIndex.ExcelDataMap[date] = newCell
  349. indexInfoMap[indexName] = tmpYongyiIndex
  350. indexList = append(indexList, tmpYongyiIndex)
  351. sort++
  352. } else {
  353. newCell := strings.ReplaceAll(cell, "%", "")
  354. indexInfo.ExcelDataMap[date] = newCell
  355. }
  356. }
  357. }
  358. }
  359. utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly45 %s 更新指标数量:%d", sheetName, len(indexList)))
  360. return
  361. }
  362. // HandleYongyiExcelWeekly46 进口肉
  363. func HandleYongyiExcelWeekly46(f *excelize.File, sheetName string) (indexList []*models.YongyiExcelIndex, err error) {
  364. defer func() {
  365. if err != nil {
  366. utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly46 %s ErrMsg: %s", sheetName, err.Error()))
  367. }
  368. }()
  369. cols, err := f.GetCols(sheetName)
  370. if err != nil {
  371. err = fmt.Errorf("f GetCols err: %s", err.Error())
  372. return
  373. }
  374. classifyName, classifySort, frequency, _, _, namePrefixPingin := GetBaseInfo(sheetName)
  375. sort := 0
  376. var indexName string
  377. re := regexp.MustCompile(`\d+`)
  378. regZr := regexp.MustCompile(`\([^()]*\)`)
  379. zrzuDateMap := make(map[int]string) // 猪肉及杂碎进口量
  380. indexInfoMap := make(map[string]*models.YongyiExcelIndex)
  381. for _, col := range cols {
  382. if indexName == "" {
  383. indexName = col[1]
  384. }
  385. if col[2] == "" && col[3] == "" {
  386. indexName = ""
  387. continue
  388. }
  389. if indexName != "" && strings.Contains(indexName, "猪肉进口量") {
  390. indexName = "猪肉进口量"
  391. var year int
  392. if strings.Contains(col[2], "年") {
  393. year, err = strconv.Atoi(re.FindString(col[2]))
  394. if err != nil {
  395. continue
  396. }
  397. }
  398. for j, cell := range col {
  399. if !isValueValid(cell) {
  400. continue
  401. }
  402. monthArr := strings.Split(cols[0][j], "-")
  403. var month int
  404. switch len(monthArr) {
  405. case 2:
  406. month, err = strconv.Atoi(re.FindString(monthArr[1]))
  407. if err != nil {
  408. continue
  409. }
  410. case 1:
  411. month, err = strconv.Atoi(re.FindString(monthArr[0]))
  412. if err != nil {
  413. continue
  414. }
  415. }
  416. date := LastDayOfMonth(year, time.Month(month))
  417. if date == "" {
  418. continue
  419. }
  420. if indexInfo, ok := indexInfoMap[indexName]; !ok {
  421. tmpYongyiIndex := new(models.YongyiExcelIndex)
  422. tmpYongyiIndex.ClassifyName = classifyName
  423. tmpYongyiIndex.ClassifySort = classifySort
  424. tmpYongyiIndex.Frequency = frequency
  425. tmpYongyiIndex.Unit = "万吨"
  426. tmpYongyiIndex.IndexName = indexName
  427. tmpYongyiIndex.IndexCode = namePrefixPingin + utils.GetFirstPingYin(indexName)
  428. tmpYongyiIndex.Sort = sort
  429. tmpYongyiIndex.ExcelDataMap = make(map[string]string)
  430. tmpYongyiIndex.ExcelDataMap[date] = cell
  431. indexInfoMap[indexName] = tmpYongyiIndex
  432. indexList = append(indexList, tmpYongyiIndex)
  433. sort++
  434. } else {
  435. indexInfo.ExcelDataMap[date] = cell
  436. }
  437. }
  438. } else if indexName != "" && strings.Contains(indexName, "猪肉及杂碎进口量") {
  439. preName := "猪肉及杂碎进口量"
  440. if len(col) <= 3 {
  441. continue
  442. }
  443. colTitleName := col[2]
  444. if colTitleName == `` {
  445. continue
  446. }
  447. if colTitleName == `日期` {
  448. for j, cell := range col {
  449. if cell == "" || j <= 2 {
  450. continue
  451. }
  452. excelDate, err := strconv.ParseFloat(cell, 64)
  453. if err != nil {
  454. continue
  455. }
  456. tmpDate, err := excelize.ExcelDateToTime(excelDate, false)
  457. if err != nil {
  458. continue
  459. }
  460. LastDayDate := LastDayOfMonth(tmpDate.Year(), tmpDate.Month())
  461. zrzuDateMap[j] = LastDayDate
  462. }
  463. } else {
  464. unit := regZr.FindString(colTitleName)
  465. if unit == "" {
  466. unit = "%"
  467. } else {
  468. unit = strings.ReplaceAll(unit, "(", "")
  469. unit = strings.ReplaceAll(unit, ")", "")
  470. }
  471. namePart := regZr.ReplaceAllString(colTitleName, "")
  472. tmpIndexName := fmt.Sprintf("%s/%s", preName, namePart)
  473. if indexInfo, ok := indexInfoMap[tmpIndexName]; !ok {
  474. yongyiIndex := new(models.YongyiExcelIndex)
  475. yongyiIndex.ClassifyName = classifyName
  476. yongyiIndex.ClassifySort = classifySort
  477. yongyiIndex.Frequency = frequency
  478. yongyiIndex.Unit = unit
  479. yongyiIndex.IndexName = tmpIndexName
  480. tmpIndexName = strings.ReplaceAll(tmpIndexName, "/", "")
  481. yongyiIndex.IndexCode = namePrefixPingin + utils.GetFirstPingYin(tmpIndexName)
  482. yongyiIndex.Sort = sort
  483. yongyiIndex.ExcelDataMap = make(map[string]string)
  484. for j, cell := range col {
  485. if j == 0 {
  486. continue
  487. }
  488. cell = strings.ReplaceAll(cell, ",", "")
  489. if unit == "%" {
  490. cell = strings.ReplaceAll(cell, "%", "")
  491. }
  492. if !isValueValid(cell) {
  493. continue
  494. }
  495. yongyiIndex.ExcelDataMap[zrzuDateMap[j]] = cell
  496. }
  497. indexInfoMap[yongyiIndex.IndexName] = yongyiIndex
  498. indexList = append(indexList, yongyiIndex)
  499. sort++
  500. } else {
  501. for j, cell := range col {
  502. if j == 0 {
  503. continue
  504. }
  505. cell = strings.ReplaceAll(cell, ",", "")
  506. if unit == "%" {
  507. cell = strings.ReplaceAll(cell, "%", "")
  508. }
  509. if !isValueValid(cell) {
  510. continue
  511. }
  512. indexInfo.ExcelDataMap[zrzuDateMap[j]] = cell
  513. }
  514. }
  515. }
  516. }
  517. }
  518. utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly46 %s 更新指标数量:%d", sheetName, len(indexList)))
  519. return
  520. }
  521. // HandleYongyiExcelWeekly47 猪料原料占比
  522. func HandleYongyiExcelWeekly47(f *excelize.File, sheetName string) (indexList []*models.YongyiExcelIndex, err error) {
  523. defer func() {
  524. if err != nil {
  525. utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly47 %s ErrMsg: %s", sheetName, err.Error()))
  526. }
  527. }()
  528. rows, err := f.GetRows(sheetName)
  529. if err != nil {
  530. err = fmt.Errorf("f GetRows err: %s", err.Error())
  531. return
  532. }
  533. classifyName, classifySort, frequency, unit, namePrefix, namePrefixPingin := GetBaseInfo(sheetName)
  534. namePart2Map := map[string]int{
  535. "玉米": 0, "小麦": 0, "稻谷、糙米": 0, "豆粕": 0, "棉粕": 0, "菜粕": 0,
  536. }
  537. regionMap := map[string]struct{}{
  538. "东北": {}, "华北": {}, "华中": {}, "华南": {}, "西北": {}, "西南": {}, "全国": {},
  539. }
  540. regionIndexMap := make(map[int]string)
  541. indexInfoMap := make(map[string]*models.YongyiExcelIndex)
  542. sort := 0
  543. for i, row := range rows {
  544. if i == 0 {
  545. continue
  546. }
  547. if len(row) <= 1 {
  548. continue
  549. }
  550. var preName string
  551. for j, cell := range row {
  552. if _, ok := namePart2Map[cell]; ok {
  553. namePart2Map[cell] = j
  554. preName = cell
  555. continue
  556. }
  557. if _, ok := regionMap[cell]; ok {
  558. regionIndexMap[j] = preName + "/" + cell
  559. continue
  560. }
  561. if region, ok := regionIndexMap[j]; ok {
  562. if !isValueValid(cell) {
  563. continue
  564. }
  565. kind := strings.Split(region, "/")[0]
  566. dateIndex := namePart2Map[kind]
  567. excelDate, err := strconv.ParseFloat(row[dateIndex], 64)
  568. if err != nil {
  569. continue
  570. }
  571. curTime, err := excelize.ExcelDateToTime(excelDate, false)
  572. if err != nil {
  573. continue
  574. }
  575. dateTime := LastDayOfMonth(curTime.Year(), curTime.Month())
  576. indexName := fmt.Sprintf("%s/%s", namePrefix, region)
  577. if indexInfo, ok := indexInfoMap[indexName]; !ok {
  578. yongyiIndex := new(models.YongyiExcelIndex)
  579. yongyiIndex.ClassifyName = classifyName
  580. yongyiIndex.ClassifySort = classifySort
  581. yongyiIndex.Frequency = frequency
  582. yongyiIndex.Unit = unit
  583. yongyiIndex.IndexName = indexName
  584. tmpSuffix := strings.ReplaceAll(region, "/", "")
  585. tmpSuffix = strings.ReplaceAll(tmpSuffix, "、", "")
  586. yongyiIndex.IndexCode = namePrefixPingin + utils.GetFirstPingYin(tmpSuffix)
  587. yongyiIndex.Sort = sort
  588. yongyiIndex.ExcelDataMap = make(map[string]string)
  589. cell = strings.ReplaceAll(cell, "%", "")
  590. yongyiIndex.ExcelDataMap[dateTime] = cell
  591. indexInfoMap[indexName] = yongyiIndex
  592. indexList = append(indexList, yongyiIndex)
  593. sort++
  594. } else {
  595. cell = strings.ReplaceAll(cell, "%", "")
  596. indexInfo.ExcelDataMap[dateTime] = cell
  597. }
  598. }
  599. }
  600. }
  601. utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly47 %s 更新指标数量:%d", sheetName, len(indexList)))
  602. return
  603. }
  604. // HandleYongyiExcelWeekly48 MSY
  605. func HandleYongyiExcelWeekly48(f *excelize.File, sheetName string) (indexList []*models.YongyiExcelIndex, err error) {
  606. defer func() {
  607. if err != nil {
  608. utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly48 %s ErrMsg: %s", sheetName, err.Error()))
  609. }
  610. }()
  611. cols, err := f.GetCols(sheetName)
  612. if err != nil {
  613. err = fmt.Errorf("f GetRows err: %s", err.Error())
  614. return
  615. }
  616. classifyName, classifySort, frequency, unit, namePrefix, namePrefixPingin := GetBaseInfo(sheetName)
  617. re := regexp.MustCompile(`\d+`)
  618. dateMap := make(map[int]string)
  619. for _, col := range cols {
  620. if len(col) <= 3 {
  621. continue
  622. }
  623. if col[2] == "时间" {
  624. for j, cell := range col {
  625. year := re.FindString(cell)
  626. if year == "" {
  627. continue
  628. }
  629. dateMap[j] = year + "-12-31"
  630. }
  631. } else if col[2] == "MSY" {
  632. yongyiIndex := new(models.YongyiExcelIndex)
  633. yongyiIndex.ClassifyName = classifyName
  634. yongyiIndex.ClassifySort = classifySort
  635. yongyiIndex.Frequency = frequency
  636. yongyiIndex.Unit = unit
  637. yongyiIndex.IndexName = namePrefix
  638. yongyiIndex.IndexCode = namePrefixPingin
  639. yongyiIndex.Sort = 0
  640. yongyiIndex.ExcelDataMap = make(map[string]string)
  641. for j, cell := range col {
  642. if !isValueValid(cell) {
  643. continue
  644. }
  645. yongyiIndex.ExcelDataMap[dateMap[j]] = cell
  646. }
  647. indexList = append(indexList, yongyiIndex)
  648. }
  649. }
  650. utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly48 %s 更新指标数量:%d", sheetName, len(indexList)))
  651. return
  652. }