week40.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. package base_from_yongyi_v2
  2. import (
  3. "eta/eta_data_analysis/models"
  4. "eta/eta_data_analysis/utils"
  5. "fmt"
  6. "github.com/xuri/excelize/v2"
  7. "strconv"
  8. "strings"
  9. "time"
  10. )
  11. // HandleYongyiExcelWeekly31 月度-屠宰厂公母比例
  12. func HandleYongyiExcelWeekly31(f *excelize.File, sheetName string) (indexList []*models.YongyiExcelIndex, err error) {
  13. defer func() {
  14. if err != nil {
  15. //fmt.Printf("HandleYongyiExcelWeekly31 月度-屠宰厂公母比例 ErrMsg: %s\n", err.Error())
  16. utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly31 月度-屠宰厂公母比例 ErrMsg: %s", err.Error()))
  17. }
  18. }()
  19. rows, e := f.GetRows(sheetName)
  20. if e != nil {
  21. err = fmt.Errorf("f GetRows err: %s", e.Error())
  22. return
  23. }
  24. // 获取指标分类
  25. classifyName, classifySort, frequency, unit, namePrefix, namePrefixPingin := GetBaseInfo(sheetName)
  26. // 遍历行读取
  27. indexList = make([]*models.YongyiExcelIndex, 0)
  28. sort := 0
  29. nameMap := make(map[int]string)
  30. // 指标名称
  31. indexMap := make(map[string]*models.YongyiExcelIndex)
  32. for i, row := range rows {
  33. //fmt.Printf("当前第%d行 \n", i)
  34. if i == 0 {
  35. for k, text := range row {
  36. if text != "" {
  37. text = strings.TrimSpace(text)
  38. nameMap[k] = text
  39. }
  40. }
  41. } else { //数据列
  42. date := ""
  43. for k, text := range row {
  44. //fmt.Printf("当前第%d列 \n", k)
  45. if k == 0 {
  46. text = strings.TrimSpace(text)
  47. var dateT time.Time
  48. dateT, e = time.ParseInLocation("2006年1月", text, time.Local)
  49. if e != nil {
  50. text = strings.TrimSpace(text)
  51. dateSlice := strings.Split(text, "-")
  52. if len(dateSlice) <= 1 {
  53. utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 读取行,时间列失败 Err:%s", sheetName, i, k, text))
  54. continue
  55. }
  56. dateT, e = time.ParseInLocation("2006年1月2日", dateSlice[0], time.Local)
  57. if e != nil {
  58. utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 读取行,时间列失败 Err:%s", sheetName, i, k, e))
  59. continue
  60. }
  61. date = dateT.Format("2006年1月") + dateSlice[1]
  62. dateT, e = time.ParseInLocation("2006年1月2日", date, time.Local)
  63. if e != nil {
  64. utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 读取行,时间列失败 Err:%s", sheetName, i, k, e))
  65. continue
  66. }
  67. date = dateT.Format(utils.FormatDate)
  68. } else {
  69. // 查询当月的最后一天
  70. monthDate := dateT.Format(utils.FormatYearMonthDate)
  71. firstDayStr := monthDate + "-01"
  72. tmpT, _ := time.ParseInLocation(utils.FormatDate, firstDayStr, time.Local)
  73. date = tmpT.AddDate(0, 1, -1).Format(utils.FormatDate)
  74. }
  75. continue
  76. } else {
  77. // 判断出不是字符的,则过滤
  78. if text == "" {
  79. continue
  80. }
  81. if strings.Contains(text, "%") {
  82. text = strings.Replace(text, "%", "", 1)
  83. }
  84. _, e := strconv.ParseFloat(text, 64)
  85. if e != nil {
  86. utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 strconv.ParseFloat Err:%s", sheetName, i, k, e))
  87. continue
  88. }
  89. }
  90. name, ok2 := nameMap[k]
  91. if !ok2 {
  92. err = fmt.Errorf("找不到对应的列名,第%d行,第%d列", i, k)
  93. return
  94. }
  95. //fmt.Printf("当前第%d行第%d列, 当前省份%s \n", i, k, name)
  96. unit = "头"
  97. if strings.Contains(name, "占比") {
  98. unit = "%"
  99. }
  100. fullIndexName := fmt.Sprintf("%s%s", namePrefix, name)
  101. namePingin := utils.GetFirstPingYin(name)
  102. fullIndexNamePingyin := namePrefixPingin + namePingin
  103. indexItem, okIndex := indexMap[fullIndexName]
  104. if !okIndex {
  105. // 新增指标
  106. indexItem = new(models.YongyiExcelIndex)
  107. indexItem.IndexName = fullIndexName
  108. indexItem.ClassifyName = classifyName
  109. indexItem.ClassifySort = classifySort
  110. indexItem.IndexCode = fullIndexNamePingyin
  111. indexItem.Frequency = frequency
  112. indexItem.Sort = sort
  113. indexItem.Unit = unit
  114. indexItem.ExcelDataMap = make(map[string]string)
  115. sort++
  116. }
  117. //fmt.Printf("IndexCode: %s", indexItem.IndexCode)
  118. indexItem.ExcelDataMap[date] = text
  119. indexMap[fullIndexName] = indexItem
  120. continue
  121. }
  122. }
  123. }
  124. for _, v := range indexMap {
  125. indexList = append(indexList, v)
  126. }
  127. return
  128. }
  129. // HandleYongyiExcelWeekly32 月度-生产指标(2021.5.7新增)
  130. func HandleYongyiExcelWeekly32(f *excelize.File, sheetName string) (indexList []*models.YongyiExcelIndex, err error) {
  131. defer func() {
  132. if err != nil {
  133. //fmt.Printf("HandleYongyiExcelWeekly32 月度-生产指标(2021.5.7新增) ErrMsg: %s\n", err.Error())
  134. utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly32 月度-生产指标(2021.5.7新增) ErrMsg: %s", err.Error()))
  135. }
  136. }()
  137. rows, e := f.GetRows(sheetName)
  138. if e != nil {
  139. err = fmt.Errorf("f GetRows err: %s", e.Error())
  140. return
  141. }
  142. // 获取指标分类
  143. classifyName, classifySort, frequency, unit, namePrefix, namePrefixPingin := GetBaseInfo(sheetName)
  144. // 遍历行读取
  145. indexList = make([]*models.YongyiExcelIndex, 0)
  146. sort := 0
  147. nameMap := make(map[int]string)
  148. provinceMap := make(map[int]string)
  149. mergeCellMap, err := GetMergeCells(f, sheetName)
  150. if err != nil {
  151. err = fmt.Errorf("获取合并单元格失败, sheetName: %s", sheetName)
  152. return
  153. }
  154. // 指标名称
  155. indexMap := make(map[string]*models.YongyiExcelIndex)
  156. for i, row := range rows {
  157. //fmt.Printf("当前第%d行 \n", i)
  158. currentMergeCells, mergeOk := mergeCellMap[i]
  159. if i == 0 {
  160. for k, text := range row {
  161. if text != "" {
  162. if mergeOk {
  163. for j, v := range currentMergeCells {
  164. provinceMap[j] = v
  165. }
  166. }
  167. provinceMap[k] = text
  168. }
  169. }
  170. } else if i == 1 {
  171. for k, text := range row {
  172. if text != "" {
  173. nameMap[k] = text
  174. }
  175. }
  176. } else { //数据列
  177. date := ""
  178. for k, text := range row {
  179. //fmt.Printf("当前第%d列 \n", k)
  180. if k == 0 {
  181. text = strings.TrimSpace(text)
  182. var dateT time.Time
  183. dateT, e = time.ParseInLocation("2006年1月", text, time.Local)
  184. if e != nil {
  185. utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 读取行,时间列失败 Err:%s", sheetName, i, k, e))
  186. continue
  187. }
  188. // 查询当月的最后一天
  189. monthDate := dateT.Format(utils.FormatYearMonthDate)
  190. firstDayStr := monthDate + "-01"
  191. tmpT, _ := time.ParseInLocation(utils.FormatDate, firstDayStr, time.Local)
  192. date = tmpT.AddDate(0, 1, -1).Format(utils.FormatDate)
  193. fmt.Println(date)
  194. continue
  195. } else {
  196. // 判断出不是字符的,则过滤
  197. if text == "" {
  198. continue
  199. }
  200. if strings.Contains(text, "%") {
  201. text = strings.Replace(text, "%", "", 1)
  202. }
  203. _, e := strconv.ParseFloat(text, 64)
  204. if e != nil {
  205. utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 strconv.ParseFloat Err:%s", sheetName, i, k, e))
  206. continue
  207. }
  208. }
  209. province, ok1 := provinceMap[k]
  210. if !ok1 {
  211. err = fmt.Errorf("找不到对应的列名,第%d行,第%d列", i, k)
  212. return
  213. }
  214. name, ok2 := nameMap[k]
  215. if !ok2 {
  216. err = fmt.Errorf("找不到对应的列名,第%d行,第%d列", i, k)
  217. return
  218. }
  219. if strings.Contains(name, "环比") {
  220. continue
  221. }
  222. //fmt.Printf("当前第%d行第%d列, 当前省份%s \n", i, k, name)
  223. unit = "头"
  224. if strings.Contains(name, "率") {
  225. unit = "%"
  226. }
  227. fullIndexName := fmt.Sprintf("%s/%s/%s", namePrefix, province, name)
  228. provincePingyin := utils.GetFullPingYin(province)
  229. namePingin := utils.GetFirstPingYin(name)
  230. fullIndexNamePingyin := namePrefixPingin + provincePingyin + namePingin
  231. if province == "五省合计数量" || province == "五省平均水平" {
  232. provincePingyin = utils.GetFirstPingYin(province)
  233. fullIndexNamePingyin = namePrefixPingin + provincePingyin + namePingin
  234. }
  235. indexItem, okIndex := indexMap[fullIndexName]
  236. if !okIndex {
  237. // 新增指标
  238. indexItem = new(models.YongyiExcelIndex)
  239. indexItem.IndexName = fullIndexName
  240. indexItem.ClassifyName = classifyName
  241. indexItem.ClassifySort = classifySort
  242. indexItem.IndexCode = fullIndexNamePingyin
  243. indexItem.Frequency = frequency
  244. indexItem.Sort = sort
  245. indexItem.Unit = unit
  246. indexItem.ExcelDataMap = make(map[string]string)
  247. sort++
  248. }
  249. //fmt.Printf("IndexCode: %s", indexItem.IndexCode)
  250. indexItem.ExcelDataMap[date] = text
  251. indexMap[fullIndexName] = indexItem
  252. continue
  253. }
  254. }
  255. }
  256. for _, v := range indexMap {
  257. indexList = append(indexList, v)
  258. }
  259. return
  260. }
  261. // HandleYongyiExcelWeekly33 月度-生产指标2
  262. func HandleYongyiExcelWeekly33(f *excelize.File, sheetName string) (indexList []*models.YongyiExcelIndex, err error) {
  263. defer func() {
  264. if err != nil {
  265. //fmt.Printf("HandleYongyiExcelWeekly33 月度-生产指标2ErrMsg: %s\n", err.Error())
  266. utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly33 月度-生产指标2 ErrMsg: %s", err.Error()))
  267. }
  268. }()
  269. rows, e := f.GetRows(sheetName)
  270. if e != nil {
  271. err = fmt.Errorf("f GetRows err: %s", e.Error())
  272. return
  273. }
  274. // 获取指标分类
  275. classifyName, classifySort, frequency, unit, namePrefix, namePrefixPingin := GetBaseInfo(sheetName)
  276. // 遍历行读取
  277. indexList = make([]*models.YongyiExcelIndex, 0)
  278. sort := 0
  279. nameMap := make(map[int]string)
  280. // 指标名称
  281. indexMap := make(map[string]*models.YongyiExcelIndex)
  282. for i, row := range rows {
  283. //fmt.Printf("当前第%d行 \n", i)
  284. if i == 0 {
  285. continue
  286. } else if i == 1 {
  287. for k, text := range row {
  288. if text != "" {
  289. text = strings.TrimSpace(text)
  290. nameMap[k] = text
  291. }
  292. }
  293. } else { //数据列
  294. date := ""
  295. for k, text := range row {
  296. //fmt.Printf("当前第%d列 \n", k)
  297. if k == 0 {
  298. text = strings.TrimSpace(text)
  299. var dateT time.Time
  300. dateT, e = time.ParseInLocation("2006年1月", text, time.Local)
  301. if e != nil {
  302. utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 读取行,时间列失败 Err:%s", sheetName, i, k, e))
  303. continue
  304. }
  305. // 查询当月的最后一天
  306. monthDate := dateT.Format(utils.FormatYearMonthDate)
  307. firstDayStr := monthDate + "-01"
  308. tmpT, _ := time.ParseInLocation(utils.FormatDate, firstDayStr, time.Local)
  309. date = tmpT.AddDate(0, 1, -1).Format(utils.FormatDate)
  310. fmt.Println(date)
  311. continue
  312. } else {
  313. // 判断出不是字符的,则过滤
  314. if text == "" {
  315. continue
  316. }
  317. if strings.Contains(text, "%") {
  318. text = strings.Replace(text, "%", "", 1)
  319. }
  320. _, e := strconv.ParseFloat(text, 64)
  321. if e != nil {
  322. utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 strconv.ParseFloat Err:%s", sheetName, i, k, e))
  323. continue
  324. }
  325. }
  326. name, ok2 := nameMap[k]
  327. if !ok2 {
  328. err = fmt.Errorf("找不到对应的列名,第%d行,第%d列", i, k)
  329. return
  330. }
  331. //fmt.Printf("当前第%d行第%d列, 当前省份%s \n", i, k, name)
  332. fullIndexName := fmt.Sprintf("%s/%s", namePrefix, name)
  333. namePingin := utils.GetFirstPingYin(name)
  334. fullIndexNamePingyin := namePrefixPingin + namePingin
  335. unit = "头"
  336. if strings.Contains(name, "率") {
  337. unit = "%"
  338. }
  339. indexItem, okIndex := indexMap[fullIndexName]
  340. if !okIndex {
  341. // 新增指标
  342. indexItem = new(models.YongyiExcelIndex)
  343. indexItem.IndexName = fullIndexName
  344. indexItem.ClassifyName = classifyName
  345. indexItem.ClassifySort = classifySort
  346. indexItem.IndexCode = fullIndexNamePingyin
  347. indexItem.Frequency = frequency
  348. indexItem.Sort = sort
  349. indexItem.Unit = unit
  350. indexItem.ExcelDataMap = make(map[string]string)
  351. sort++
  352. }
  353. //fmt.Printf("IndexCode: %s", indexItem.IndexCode)
  354. indexItem.ExcelDataMap[date] = text
  355. indexMap[fullIndexName] = indexItem
  356. continue
  357. }
  358. }
  359. }
  360. for _, v := range indexMap {
  361. indexList = append(indexList, v)
  362. }
  363. return
  364. }
  365. // HandleYongyiExcelWeekly34 月度-二元三元能繁比例
  366. func HandleYongyiExcelWeekly34(f *excelize.File, sheetName string) (indexList []*models.YongyiExcelIndex, err error) {
  367. defer func() {
  368. if err != nil {
  369. //fmt.Printf("HandleYongyiExcelWeekly34 月度-二元三元能繁比例ErrMsg: %s\n", err.Error())
  370. utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly34 月度-二元三元能繁比例 ErrMsg: %s", err.Error()))
  371. }
  372. }()
  373. rows, e := f.GetRows(sheetName)
  374. if e != nil {
  375. err = fmt.Errorf("f GetRows err: %s", e.Error())
  376. return
  377. }
  378. // 获取指标分类
  379. classifyName, classifySort, frequency, unit, namePrefix, namePrefixPingin := GetBaseInfo(sheetName)
  380. // 遍历行读取
  381. indexList = make([]*models.YongyiExcelIndex, 0)
  382. sort := 0
  383. year := ""
  384. nameMap := make(map[int]string)
  385. // 指标名称
  386. indexMap := make(map[string]*models.YongyiExcelIndex)
  387. for i, row := range rows {
  388. //fmt.Printf("当前第%d行 \n", i)
  389. if i == 0 {
  390. for k, text := range row {
  391. if k > 3 && text != "" {
  392. text = strings.TrimSpace(text)
  393. nameMap[k] = text
  394. }
  395. }
  396. } else { //数据列
  397. date := ""
  398. for k, text := range row {
  399. //fmt.Printf("当前第%d列 \n", k)
  400. if k <= 3 || k > 8 {
  401. continue
  402. } else if k == 4 {
  403. text = strings.TrimSpace(text)
  404. var dateT time.Time
  405. //判断是否是数字,如果是数字,另外单独处理
  406. if dateFloat, e := strconv.ParseFloat(text, 64); e == nil {
  407. dateT, e = excelize.ExcelDateToTime(dateFloat, false)
  408. if e != nil {
  409. utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 读取行,时间列失败 Err:%s", sheetName, i, k, e))
  410. continue
  411. }
  412. } else {
  413. dateSlice := strings.Split(text, "年")
  414. if len(dateSlice) >= 2 {
  415. year = dateSlice[0]
  416. } else {
  417. text = fmt.Sprintf("%s年%s", year, text)
  418. }
  419. fmt.Println(text)
  420. dateT, e = time.ParseInLocation("2006年1月", text, time.Local)
  421. if e != nil {
  422. utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 读取行,时间列失败 Err:%s", sheetName, i, k, e))
  423. continue
  424. }
  425. }
  426. // 查询当月的最后一天
  427. monthDate := dateT.Format(utils.FormatYearMonthDate)
  428. firstDayStr := monthDate + "-01"
  429. tmpT, _ := time.ParseInLocation(utils.FormatDate, firstDayStr, time.Local)
  430. date = tmpT.AddDate(0, 1, -1).Format(utils.FormatDate)
  431. fmt.Println(date)
  432. continue
  433. } else {
  434. // 判断出不是字符的,则过滤
  435. if text == "" {
  436. continue
  437. }
  438. if strings.Contains(text, "%") {
  439. text = strings.Replace(text, "%", "", 1)
  440. }
  441. _, e := strconv.ParseFloat(text, 64)
  442. if e != nil {
  443. utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 strconv.ParseFloat Err:%s", sheetName, i, k, e))
  444. continue
  445. }
  446. }
  447. if date == "" {
  448. continue
  449. }
  450. name, ok2 := nameMap[k]
  451. if !ok2 {
  452. err = fmt.Errorf("找不到对应的列名,第%d行,第%d列", i, k)
  453. return
  454. }
  455. //fmt.Printf("当前第%d行第%d列, 当前省份%s \n", i, k, name)
  456. name += "比例"
  457. fullIndexName := fmt.Sprintf("%s/%s", namePrefix, name)
  458. namePingin := utils.GetFirstPingYin(name)
  459. fullIndexNamePingyin := namePrefixPingin + namePingin
  460. indexItem, okIndex := indexMap[fullIndexName]
  461. if !okIndex {
  462. // 新增指标
  463. indexItem = new(models.YongyiExcelIndex)
  464. indexItem.IndexName = fullIndexName
  465. indexItem.ClassifyName = classifyName
  466. indexItem.ClassifySort = classifySort
  467. indexItem.IndexCode = fullIndexNamePingyin
  468. indexItem.Frequency = frequency
  469. indexItem.Sort = sort
  470. indexItem.Unit = unit
  471. indexItem.ExcelDataMap = make(map[string]string)
  472. sort++
  473. }
  474. //fmt.Printf("IndexCode: %s", indexItem.IndexCode)
  475. indexItem.ExcelDataMap[date] = text
  476. indexMap[fullIndexName] = indexItem
  477. continue
  478. }
  479. }
  480. }
  481. for _, v := range indexMap {
  482. indexList = append(indexList, v)
  483. }
  484. return
  485. }
  486. // HandleYongyiExcelWeekly35 月度-能繁母猪存栏量
  487. func HandleYongyiExcelWeekly35(f *excelize.File, sheetName string) (indexList []*models.YongyiExcelIndex, err error) {
  488. defer func() {
  489. if err != nil {
  490. //fmt.Printf("HandleYongyiExcelWeekly35 月度-能繁母猪存栏量 ErrMsg: %s\n", err.Error())
  491. utils.FileLog.Info(fmt.Sprintf("HandleYongyiExcelWeekly35 月度-能繁母猪存栏量 ErrMsg: %s", err.Error()))
  492. }
  493. }()
  494. rows, e := f.GetRows(sheetName)
  495. if e != nil {
  496. err = fmt.Errorf("f GetRows err: %s", e.Error())
  497. return
  498. }
  499. // 获取指标分类
  500. classifyName, classifySort, frequency, unit, namePrefix, namePrefixPingin := GetBaseInfo(sheetName)
  501. // 遍历行读取
  502. indexList = make([]*models.YongyiExcelIndex, 0)
  503. sort := 0
  504. nameMap := make(map[int]string)
  505. // 指标名称
  506. indexMap := make(map[string]*models.YongyiExcelIndex)
  507. for i, row := range rows {
  508. //fmt.Printf("当前第%d行 \n", i)
  509. if i == 0 {
  510. continue
  511. } else if i == 1 {
  512. for k, text := range row {
  513. if text != "" {
  514. nameMap[k] = text
  515. }
  516. }
  517. } else { //数据列
  518. date := ""
  519. for k, text := range row {
  520. //fmt.Printf("当前第%d列 \n", k)
  521. if k == 0 {
  522. text = strings.TrimSpace(text)
  523. var dateT time.Time
  524. dateT, e = time.ParseInLocation("2006年1月", text, time.Local)
  525. if e != nil {
  526. utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 读取行,时间列失败 Err:%s", sheetName, i, k, e))
  527. continue
  528. }
  529. // 查询当月的最后一天
  530. monthDate := dateT.Format(utils.FormatYearMonthDate)
  531. firstDayStr := monthDate + "-01"
  532. tmpT, _ := time.ParseInLocation(utils.FormatDate, firstDayStr, time.Local)
  533. date = tmpT.AddDate(0, 1, -1).Format(utils.FormatDate)
  534. fmt.Println(date)
  535. continue
  536. } else {
  537. // 判断出不是字符的,则过滤
  538. if text == "" {
  539. continue
  540. }
  541. if strings.Contains(text, "%") {
  542. text = strings.Replace(text, "%", "", 1)
  543. }
  544. _, e := strconv.ParseFloat(text, 64)
  545. if e != nil {
  546. //utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 strconv.ParseFloat Err:%s", sheetName, i, k, e))
  547. continue
  548. }
  549. }
  550. name, ok2 := nameMap[k]
  551. if !ok2 {
  552. err = fmt.Errorf("找不到对应的列名,第%d行,第%d列", i, k)
  553. return
  554. }
  555. if strings.Contains(name, "环比") || strings.Contains(name, "同比") || strings.Contains(name, "日期") {
  556. continue
  557. }
  558. //fmt.Printf("当前第%d行第%d列, 当前省份%s \n", i, k, name)
  559. fullIndexName := fmt.Sprintf("%s/%s", namePrefix, name)
  560. namePingin := utils.GetFirstPingYin(name)
  561. fullIndexNamePingyin := namePrefixPingin + namePingin
  562. unit = "头"
  563. if name == "较非瘟前" {
  564. area, ok3 := nameMap[k-3]
  565. if !ok3 {
  566. err = fmt.Errorf("找不到对应的列名,第%d行,第%d列", i, k-3)
  567. return
  568. }
  569. fullIndexName = fmt.Sprintf("%s/%s%s", namePrefix, area, name)
  570. namePingin = utils.GetFirstPingYin(area + name)
  571. fullIndexNamePingyin = namePrefixPingin + namePingin
  572. unit = "%"
  573. }
  574. indexItem, okIndex := indexMap[fullIndexName]
  575. if !okIndex {
  576. // 新增指标
  577. indexItem = new(models.YongyiExcelIndex)
  578. indexItem.IndexName = fullIndexName
  579. indexItem.ClassifyName = classifyName
  580. indexItem.ClassifySort = classifySort
  581. indexItem.IndexCode = fullIndexNamePingyin
  582. indexItem.Frequency = frequency
  583. indexItem.Sort = sort
  584. indexItem.Unit = unit
  585. indexItem.ExcelDataMap = make(map[string]string)
  586. sort++
  587. }
  588. //fmt.Printf("IndexCode: %s", indexItem.IndexCode)
  589. indexItem.ExcelDataMap[date] = text
  590. indexMap[fullIndexName] = indexItem
  591. continue
  592. }
  593. }
  594. }
  595. for _, v := range indexMap {
  596. indexList = append(indexList, v)
  597. }
  598. return
  599. }