week.go 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252
  1. package base_from_yongyi
  2. import (
  3. "eta/eta_data_analysis/models"
  4. "eta/eta_data_analysis/utils"
  5. "fmt"
  6. "github.com/tealeg/xlsx"
  7. "strconv"
  8. "strings"
  9. "time"
  10. )
  11. var YongyiWeeklySheetMap5 map[string]*models.YongyiSheet
  12. var YongyiWeeklySheetMap6 map[string]*models.YongyiSheet
  13. var YongyiWeeklySheetMap9 map[string]*models.YongyiSheet
  14. func init() {
  15. YongyiWeeklySheetMap5 = map[string]*models.YongyiSheet{
  16. "周度-50公斤二元母猪价格": {"50公斤二元母猪价格", "周度-50公斤二元母猪价格", "周度", "元/头"},
  17. "周度-规模场15公斤仔猪出栏价": {"规模场15公斤仔猪出栏价", "周度-规模场15公斤仔猪出栏价", "周度", "元/头"},
  18. "周度-宰后结算价": {"宰后结算价", "周度-宰后结算价", "周度", "元/公斤"},
  19. "周度-冻品库存": {"冻品库存", "周度-冻品库存", "周度", "%"},
  20. "周度-猪肉价(前三等级白条均价)": {"前三等级白条均价", "周度-猪肉价(前三等级白条均价)", "周度", "元/公斤"},
  21. }
  22. YongyiWeeklySheetMap6 = map[string]*models.YongyiSheet{
  23. "周度-冻品库存多样本": {"冻品库存多样本", "周度-冻品库存多样本", "周度", "%"},
  24. "月度出栏完成率": {"出栏完成率", "月度出栏完成率", "旬度", "%"},
  25. }
  26. YongyiWeeklySheetMap9 = map[string]*models.YongyiSheet{
  27. "月度-小猪存栏(2020年5月新增)": {"50kg以下小猪存栏量", "月度-小猪存栏(2020年5月新增)", "月度", "头"},
  28. "月度-中猪存栏(2020年5月新增)": {"中猪存栏量", "月度-中猪存栏(2020年5月新增)", "月度", "头"},
  29. "月度-大猪存栏(2020年5月新增)": {"大猪存栏量", "月度-大猪存栏(2020年5月新增)", "月度", "头"},
  30. }
  31. }
  32. type ExcelDateRecordFirst struct {
  33. Date time.Time `xlsx:"0"`
  34. }
  35. type ExcelDateRecord struct {
  36. Date time.Time `xlsx:"1"`
  37. }
  38. // HandleYongyiExcelWeekly1 周度-商品猪出栏价
  39. func HandleYongyiExcelWeekly1(sheet *xlsx.Sheet) (indexList []*models.YongyiExcelIndex, err error) {
  40. classifyName := "周度-商品猪出栏价"
  41. frequency := "周度"
  42. unit := "元/公斤"
  43. namePrefix := "商品猪出栏价"
  44. namePrefixPingin := "yyzx" + utils.GetFirstPingYin(namePrefix)
  45. // 遍历行读取
  46. indexList = make([]*models.YongyiExcelIndex, 0)
  47. areaMap := make(map[int]string)
  48. provinceMap := make(map[int]string)
  49. maxRow := sheet.MaxRow
  50. sort := 0
  51. fmt.Println("最大行")
  52. fmt.Println(maxRow)
  53. // 指标名称
  54. indexMap := make(map[string]*models.YongyiExcelIndex)
  55. for i := 0; i < maxRow; i++ {
  56. fmt.Printf("当前第%d行 \n", i)
  57. if i == 0 { // 首行,表示时间
  58. row := sheet.Row(i)
  59. cells := row.Cells
  60. for k, cell := range cells {
  61. text := cell.String()
  62. if k > 1 && text != "" {
  63. // 检查单元格是否为合并单元格
  64. if cell.HMerge > 0 {
  65. for j := 1; j <= cell.HMerge; j++ {
  66. areaMap[k+j] = text
  67. }
  68. }
  69. if cell.VMerge > 0 {
  70. provinceMap[k] = text
  71. }
  72. areaMap[k] = text
  73. }
  74. }
  75. } else if i == 1 { //表示表头
  76. // 处理 index指标表
  77. row := sheet.Row(i)
  78. cells := row.Cells
  79. for k, cell := range cells {
  80. text := cell.String()
  81. if text != "" {
  82. provinceMap[k] = text
  83. }
  84. }
  85. } else { //数据列
  86. row := sheet.Row(i)
  87. cells := row.Cells
  88. date := ""
  89. for k, cell := range cells {
  90. fmt.Printf("当前第%d列 \n", k)
  91. text := cell.String()
  92. if k == 0 {
  93. continue
  94. } else if k == 1 {
  95. tmpRow := row
  96. r := &ExcelDateRecord{}
  97. if e := tmpRow.ReadStruct(r); e != nil {
  98. utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 读取行,时间列失败 Err:%s", sheet.Name, i, k, e))
  99. continue
  100. }
  101. date = r.Date.Format(utils.FormatDate)
  102. fmt.Println(date)
  103. continue
  104. } else {
  105. if text == "" {
  106. continue
  107. }
  108. if strings.Contains(text, "%") {
  109. text = strings.Replace(text, "%", "", 1)
  110. }
  111. _, e := strconv.ParseFloat(text, 64)
  112. if e != nil {
  113. utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 strconv.ParseFloat Err:%s", sheet.Name, i, k, e))
  114. continue
  115. }
  116. }
  117. area, ok1 := areaMap[k]
  118. if !ok1 {
  119. err = fmt.Errorf("找不到对应的区域,第%d行,第%d列", i, k)
  120. return
  121. }
  122. province, ok2 := provinceMap[k]
  123. if !ok2 {
  124. err = fmt.Errorf("找不到对应的列名,第%d行,第%d列", i, k)
  125. return
  126. }
  127. fmt.Printf("当前第%d行第%d列, 当前省份%s \n", i, k, province)
  128. // 处理指标名称
  129. fullIndexName := fmt.Sprintf("%s/%s/%s", namePrefix, area, province)
  130. provincePingyin := utils.GetFullPingYin(province)
  131. areaPingin := utils.GetFirstPingYin(area)
  132. fullIndexNamePingyin := namePrefixPingin + areaPingin + provincePingyin
  133. if province == "全 国1" || province == "全 国2" || province == "全国1" || province == "全国2" {
  134. province = strings.ReplaceAll(province, " ", "")
  135. fullIndexName = fmt.Sprintf("%s/%s", namePrefix, province)
  136. fullIndexNamePingyin = namePrefixPingin + provincePingyin
  137. }
  138. indexItem, okIndex := indexMap[fullIndexName]
  139. if !okIndex {
  140. // 新增指标
  141. indexItem = new(models.YongyiExcelIndex)
  142. indexItem.IndexName = fullIndexName
  143. indexItem.ClassifyName = classifyName
  144. indexItem.IndexCode = fullIndexNamePingyin
  145. indexItem.Frequency = frequency
  146. indexItem.Sort = sort
  147. indexItem.Unit = unit
  148. indexItem.ExcelDataMap = make(map[string]string)
  149. sort++
  150. }
  151. fmt.Printf("indexItem%s", indexItem.IndexCode)
  152. indexItem.ExcelDataMap[date] = text
  153. indexMap[fullIndexName] = indexItem
  154. continue
  155. }
  156. }
  157. }
  158. for _, v := range indexMap {
  159. indexList = append(indexList, v)
  160. }
  161. return
  162. }
  163. // HandleYongyiExcelWeekly2 周度-体重
  164. func HandleYongyiExcelWeekly2(sheet *xlsx.Sheet) (indexList []*models.YongyiExcelIndex, err error) {
  165. classifyName := "周度-体重"
  166. frequency := "周度"
  167. unit := "公斤"
  168. namePrefix := "商品猪出栏体重"
  169. namePrefixPingin := "yyzx" + utils.GetFirstPingYin(namePrefix)
  170. // 遍历行读取
  171. indexList = make([]*models.YongyiExcelIndex, 0)
  172. areaMap := make(map[int]string)
  173. provinceMap := make(map[int]string)
  174. maxRow := sheet.MaxRow
  175. sort := 0
  176. fmt.Println("最大行")
  177. fmt.Println(maxRow)
  178. // 指标名称
  179. indexMap := make(map[string]*models.YongyiExcelIndex)
  180. for i := 0; i < maxRow; i++ {
  181. fmt.Printf("当前第%d行 \n", i)
  182. if i == 0 { // 首行,表示时间
  183. row := sheet.Row(i)
  184. cells := row.Cells
  185. for k, cell := range cells {
  186. text := cell.String()
  187. if k > 2 && text != "" {
  188. // 检查单元格是否为合并单元格
  189. if cell.HMerge > 0 {
  190. for j := 1; j <= cell.HMerge; j++ {
  191. areaMap[k+j] = text
  192. }
  193. }
  194. if cell.VMerge > 0 {
  195. provinceMap[k] = text
  196. }
  197. areaMap[k] = text
  198. }
  199. }
  200. } else if i == 1 { //表示表头
  201. // 处理 index指标表
  202. row := sheet.Row(i)
  203. cells := row.Cells
  204. for k, cell := range cells {
  205. text := cell.String()
  206. if text != "" {
  207. provinceMap[k] = text
  208. }
  209. }
  210. } else { //数据列
  211. row := sheet.Row(i)
  212. cells := row.Cells
  213. date := ""
  214. name := ""
  215. for k, cell := range cells {
  216. fmt.Printf("当前第%d列 \n", k)
  217. text := cell.String()
  218. if k == 0 {
  219. continue
  220. } else if k == 1 {
  221. tmpRow := row
  222. r := &ExcelDateRecord{}
  223. if e := tmpRow.ReadStruct(r); e != nil {
  224. utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 读取行,时间列失败 Err:%s", sheet.Name, i, k, e))
  225. continue
  226. }
  227. date = r.Date.Format(utils.FormatDate)
  228. fmt.Println(date)
  229. continue
  230. } else if k == 2 {
  231. name = text
  232. continue
  233. } else {
  234. // 判断出不是字符的,则过滤
  235. if text == "" {
  236. continue
  237. }
  238. if strings.Contains(text, "%") {
  239. text = strings.Replace(text, "%", "", 1)
  240. }
  241. _, e := strconv.ParseFloat(text, 64)
  242. if e != nil {
  243. utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 strconv.ParseFloat Err:%s", sheet.Name, i, k, e))
  244. continue
  245. }
  246. }
  247. area, ok1 := areaMap[k]
  248. if !ok1 {
  249. err = fmt.Errorf("找不到对应的区域,第%d行,第%d列", i, k)
  250. return
  251. }
  252. province, ok2 := provinceMap[k]
  253. if !ok2 {
  254. err = fmt.Errorf("找不到对应的列名,第%d行,第%d列", i, k)
  255. return
  256. }
  257. fmt.Printf("当前第%d行第%d列, 当前省份%s \n", i, k, province)
  258. // 处理指标名称
  259. fullIndexName := fmt.Sprintf("%s/%s/%s/%s", namePrefix, area, province, name)
  260. provincePingyin := utils.GetFullPingYin(province)
  261. areaPingin := utils.GetFirstPingYin(area)
  262. namePingin := utils.GetFirstPingYin(name)
  263. fullIndexNamePingyin := namePrefixPingin + areaPingin + provincePingyin + namePingin
  264. if province == "全 国1" || province == "全 国2" || province == "全国1" || province == "全国2" {
  265. province = strings.ReplaceAll(province, " ", "")
  266. fullIndexName = fmt.Sprintf("%s/%s/%s", namePrefix, province, name)
  267. fullIndexNamePingyin = namePrefixPingin + provincePingyin + namePingin
  268. }
  269. if name == "90kg以下" || name == "150kg以上" {
  270. unit = "%"
  271. }
  272. indexItem, okIndex := indexMap[fullIndexName]
  273. if !okIndex {
  274. // 新增指标
  275. indexItem = new(models.YongyiExcelIndex)
  276. indexItem.IndexName = fullIndexName
  277. indexItem.ClassifyName = classifyName
  278. indexItem.IndexCode = fullIndexNamePingyin
  279. indexItem.Frequency = frequency
  280. indexItem.Sort = sort
  281. indexItem.Unit = unit
  282. indexItem.ExcelDataMap = make(map[string]string)
  283. sort++
  284. }
  285. fmt.Printf("indexItem%s", indexItem.IndexCode)
  286. indexItem.ExcelDataMap[date] = text
  287. indexMap[fullIndexName] = indexItem
  288. continue
  289. }
  290. }
  291. }
  292. for _, v := range indexMap {
  293. indexList = append(indexList, v)
  294. }
  295. return
  296. }
  297. // HandleYongyiExcelWeekly3 周度-屠宰厂宰前活猪重
  298. func HandleYongyiExcelWeekly3(sheet *xlsx.Sheet) (indexList []*models.YongyiExcelIndex, err error) {
  299. classifyName := "周度-屠宰厂宰前活猪重"
  300. frequency := "周度"
  301. unit := "公斤"
  302. namePrefix := "商品猪宰前活猪重"
  303. namePrefixPingin := "yyzx" + utils.GetFirstPingYin(namePrefix)
  304. // 遍历行读取
  305. indexList = make([]*models.YongyiExcelIndex, 0)
  306. provinceMap := make(map[int]string)
  307. maxRow := sheet.MaxRow
  308. sort := 0
  309. fmt.Println("最大行")
  310. fmt.Println(maxRow)
  311. // 指标名称
  312. indexMap := make(map[string]*models.YongyiExcelIndex)
  313. for i := 0; i < maxRow; i++ {
  314. fmt.Printf("当前第%d行 \n", i)
  315. if i < 2 {
  316. continue
  317. }
  318. if i == 2 { // 首行,表示时间
  319. row := sheet.Row(i)
  320. cells := row.Cells
  321. for k, cell := range cells {
  322. text := cell.String()
  323. if k > 2 && text != "" {
  324. // 检查单元格是否为合并单元格
  325. if cell.VMerge > 0 {
  326. provinceMap[k] = text
  327. }
  328. }
  329. }
  330. } else if i == 3 { //表示表头
  331. // 处理 index指标表
  332. row := sheet.Row(i)
  333. cells := row.Cells
  334. for k, cell := range cells {
  335. text := cell.String()
  336. if text != "" {
  337. provinceMap[k] = text
  338. }
  339. }
  340. } else { //数据列
  341. row := sheet.Row(i)
  342. cells := row.Cells
  343. date := ""
  344. for k, cell := range cells {
  345. fmt.Printf("当前第%d列 \n", k)
  346. text := cell.String()
  347. if k == 0 {
  348. continue
  349. } else if k == 1 {
  350. tmpRow := row
  351. r := &ExcelDateRecord{}
  352. if e := tmpRow.ReadStruct(r); e != nil {
  353. utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 读取行,时间列失败 Err:%s", sheet.Name, i, k, e))
  354. continue
  355. }
  356. date = r.Date.Format(utils.FormatDate)
  357. fmt.Println(date)
  358. continue
  359. } else if k == 2 {
  360. continue
  361. } else {
  362. // 判断出不是字符的,则过滤
  363. if text == "" {
  364. continue
  365. }
  366. if strings.Contains(text, "%") {
  367. text = strings.Replace(text, "%", "", 1)
  368. }
  369. _, e := strconv.ParseFloat(text, 64)
  370. if e != nil {
  371. utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 strconv.ParseFloat Err:%s", sheet.Name, i, k, e))
  372. continue
  373. }
  374. }
  375. province, ok2 := provinceMap[k]
  376. if !ok2 {
  377. err = fmt.Errorf("找不到对应的列名,第%d行,第%d列", i, k)
  378. return
  379. }
  380. if province == "较上周" {
  381. continue
  382. } else if province == "全国平均" {
  383. province = "全国"
  384. }
  385. fmt.Printf("当前第%d行第%d列, 当前省份%s \n", i, k, province)
  386. // 处理指标名称
  387. fullIndexName := fmt.Sprintf("%s/%s", namePrefix, province)
  388. provincePingyin := utils.GetFullPingYin(province)
  389. fullIndexNamePingyin := namePrefixPingin + provincePingyin
  390. indexItem, okIndex := indexMap[fullIndexName]
  391. if !okIndex {
  392. // 新增指标
  393. indexItem = new(models.YongyiExcelIndex)
  394. indexItem.IndexName = fullIndexName
  395. indexItem.ClassifyName = classifyName
  396. indexItem.IndexCode = fullIndexNamePingyin
  397. indexItem.Frequency = frequency
  398. indexItem.Sort = sort
  399. indexItem.Unit = unit
  400. indexItem.ExcelDataMap = make(map[string]string)
  401. sort++
  402. }
  403. fmt.Printf("indexItem%s", indexItem.IndexCode)
  404. indexItem.ExcelDataMap[date] = text
  405. indexMap[fullIndexName] = indexItem
  406. continue
  407. }
  408. }
  409. }
  410. for _, v := range indexMap {
  411. indexList = append(indexList, v)
  412. }
  413. return
  414. }
  415. // HandleYongyiExcelWeekly4 周度-各体重段价差
  416. func HandleYongyiExcelWeekly4(sheet *xlsx.Sheet) (indexList []*models.YongyiExcelIndex, err error) {
  417. classifyName := "周度-各体重段价差"
  418. frequency := "周度"
  419. unit := "元/斤"
  420. namePrefixPingin := "yyzx"
  421. // 遍历行读取
  422. indexList = make([]*models.YongyiExcelIndex, 0)
  423. provinceMap := make(map[int]string)
  424. maxRow := sheet.MaxRow
  425. sort := 0
  426. fmt.Println("最大行")
  427. fmt.Println(maxRow)
  428. // 指标名称
  429. indexMap := make(map[string]*models.YongyiExcelIndex)
  430. for i := 0; i < maxRow; i++ {
  431. fmt.Printf("当前第%d行 \n", i)
  432. if i == 0 {
  433. continue
  434. } else if i == 1 { //表示表头
  435. // 处理 index指标表
  436. row := sheet.Row(i)
  437. cells := row.Cells
  438. for k, cell := range cells {
  439. text := cell.String()
  440. if text != "" {
  441. provinceMap[k] = text
  442. }
  443. }
  444. } else { //数据列
  445. row := sheet.Row(i)
  446. cells := row.Cells
  447. date := ""
  448. name := ""
  449. for k, cell := range cells {
  450. fmt.Printf("当前第%d列 \n", k)
  451. text := cell.String()
  452. if k == 0 {
  453. continue
  454. } else if k == 1 {
  455. tmpRow := row
  456. r := &ExcelDateRecord{}
  457. if e := tmpRow.ReadStruct(r); e != nil {
  458. utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 读取行,时间列失败 Err:%s", sheet.Name, i, k, e))
  459. continue
  460. }
  461. date = r.Date.Format(utils.FormatDate)
  462. fmt.Println(date)
  463. continue
  464. } else if k == 2 {
  465. name = text
  466. if name == "标猪" {
  467. name += "价格"
  468. } else {
  469. name += "猪价格"
  470. }
  471. continue
  472. } else {
  473. // 判断出不是字符的,则过滤
  474. if text == "" {
  475. continue
  476. }
  477. if strings.Contains(text, "%") {
  478. text = strings.Replace(text, "%", "", 1)
  479. }
  480. _, e := strconv.ParseFloat(text, 64)
  481. if e != nil {
  482. utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 strconv.ParseFloat Err:%s", sheet.Name, i, k, e))
  483. continue
  484. }
  485. }
  486. province, ok2 := provinceMap[k]
  487. if !ok2 {
  488. err = fmt.Errorf("找不到对应的列名,第%d行,第%d列", i, k)
  489. return
  490. }
  491. if name != "标猪价格" && name != "150kg猪价格" && name != "175kg猪价格" && name != "200kg猪价格" {
  492. continue
  493. }
  494. fmt.Printf("当前第%d行第%d列, 当前省份%s \n", i, k, province)
  495. // 处理指标名称
  496. fullIndexName := fmt.Sprintf("%s/%s", name, province)
  497. provincePingyin := utils.GetFullPingYin(province)
  498. namePingin := utils.GetFirstPingYin(name)
  499. fullIndexNamePingyin := namePrefixPingin + namePingin + provincePingyin
  500. indexItem, okIndex := indexMap[fullIndexName]
  501. if !okIndex {
  502. // 新增指标
  503. indexItem = new(models.YongyiExcelIndex)
  504. indexItem.IndexName = fullIndexName
  505. indexItem.ClassifyName = classifyName
  506. indexItem.IndexCode = fullIndexNamePingyin
  507. indexItem.Frequency = frequency
  508. indexItem.Sort = sort
  509. indexItem.Unit = unit
  510. indexItem.ExcelDataMap = make(map[string]string)
  511. sort++
  512. }
  513. fmt.Printf("IndexCode: %s", indexItem.IndexCode)
  514. indexItem.ExcelDataMap[date] = text
  515. indexMap[fullIndexName] = indexItem
  516. continue
  517. }
  518. }
  519. }
  520. for _, v := range indexMap {
  521. indexList = append(indexList, v)
  522. }
  523. return
  524. }
  525. // HandleYongyiExcelWeekly5 周度-50公斤二元母猪价格
  526. func HandleYongyiExcelWeekly5(sheet *xlsx.Sheet) (indexList []*models.YongyiExcelIndex, err error) {
  527. info, ok := YongyiWeeklySheetMap5[sheet.Name]
  528. if !ok {
  529. return
  530. }
  531. classifyName := info.ClassifyName
  532. frequency := info.Frequency
  533. unit := info.Unit
  534. namePrefix := info.NamePrefix
  535. namePrefixPingin := "yyzx" + utils.GetFirstPingYin(namePrefix)
  536. /*classifyName := "周度-50公斤二元母猪价格"
  537. frequency := "周度"
  538. unit := "元/头"
  539. namePrefix := "50公斤二元母猪价格"
  540. namePrefixPingin := "yyzx50gjeymzjg"*/
  541. /* classifyName := "周度-规模场15公斤仔猪出栏价"
  542. frequency := "周度"
  543. unit := "元/头"
  544. namePrefix := "规模场15公斤仔猪出栏价"
  545. namePrefixPingin := "yyzxgmc15gjzzclj"*/
  546. // 遍历行读取
  547. indexList = make([]*models.YongyiExcelIndex, 0)
  548. provinceMap := make(map[int]string)
  549. maxRow := sheet.MaxRow
  550. sort := 0
  551. fmt.Println("最大行")
  552. fmt.Println(maxRow)
  553. // 指标名称
  554. indexMap := make(map[string]*models.YongyiExcelIndex)
  555. for i := 0; i < maxRow; i++ {
  556. fmt.Printf("当前第%d行 \n", i)
  557. if i == 0 {
  558. row := sheet.Row(i)
  559. cells := row.Cells
  560. for k, cell := range cells {
  561. text := cell.String()
  562. if k > 1 && text != "" {
  563. if cell.VMerge > 0 {
  564. provinceMap[k] = text
  565. }
  566. }
  567. }
  568. continue
  569. } else if i == 1 { //表示表头
  570. // 处理 index指标表
  571. row := sheet.Row(i)
  572. cells := row.Cells
  573. for k, cell := range cells {
  574. text := cell.String()
  575. if text != "" {
  576. provinceMap[k] = text
  577. }
  578. }
  579. } else { //数据列
  580. row := sheet.Row(i)
  581. cells := row.Cells
  582. date := ""
  583. for k, cell := range cells {
  584. fmt.Printf("当前第%d列 \n", k)
  585. text := cell.String()
  586. if k == 0 {
  587. continue
  588. } else if k == 1 {
  589. tmpRow := row
  590. r := &ExcelDateRecord{}
  591. if e := tmpRow.ReadStruct(r); e != nil {
  592. utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 读取行,时间列失败 Err:%s", sheet.Name, i, k, e))
  593. continue
  594. }
  595. date = r.Date.Format(utils.FormatDate)
  596. fmt.Println(date)
  597. continue
  598. } else {
  599. // 判断出不是字符的,则过滤
  600. if text == "" {
  601. continue
  602. }
  603. if strings.Contains(text, "%") {
  604. text = strings.Replace(text, "%", "", 1)
  605. }
  606. _, e := strconv.ParseFloat(text, 64)
  607. if e != nil {
  608. utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 strconv.ParseFloat Err:%s", sheet.Name, i, k, e))
  609. continue
  610. }
  611. }
  612. province, ok2 := provinceMap[k]
  613. if !ok2 {
  614. err = fmt.Errorf("找不到对应的列名,第%d行,第%d列", i, k)
  615. return
  616. }
  617. if province == "全 国1" || province == "全 国2" || province == "全国1" || province == "全国2" {
  618. province = strings.ReplaceAll(province, " ", "")
  619. }
  620. fmt.Printf("当前第%d行第%d列, 当前省份%s \n", i, k, province)
  621. // 处理指标名称
  622. fullIndexName := fmt.Sprintf("%s/%s", namePrefix, province)
  623. provincePingyin := utils.GetFullPingYin(province)
  624. fullIndexNamePingyin := namePrefixPingin + provincePingyin
  625. indexItem, okIndex := indexMap[fullIndexName]
  626. if !okIndex {
  627. // 新增指标
  628. indexItem = new(models.YongyiExcelIndex)
  629. indexItem.IndexName = fullIndexName
  630. indexItem.ClassifyName = classifyName
  631. indexItem.IndexCode = fullIndexNamePingyin
  632. indexItem.Frequency = frequency
  633. indexItem.Sort = sort
  634. indexItem.Unit = unit
  635. indexItem.ExcelDataMap = make(map[string]string)
  636. sort++
  637. }
  638. fmt.Printf("IndexCode: %s", indexItem.IndexCode)
  639. indexItem.ExcelDataMap[date] = text
  640. indexMap[fullIndexName] = indexItem
  641. continue
  642. }
  643. }
  644. }
  645. for _, v := range indexMap {
  646. indexList = append(indexList, v)
  647. }
  648. return
  649. }
  650. // HandleYongyiExcelWeekly6 周度-冻品库存多样本
  651. func HandleYongyiExcelWeekly6(sheet *xlsx.Sheet) (indexList []*models.YongyiExcelIndex, err error) {
  652. info, ok := YongyiWeeklySheetMap6[sheet.Name]
  653. if !ok {
  654. return
  655. }
  656. classifyName := info.ClassifyName
  657. frequency := info.Frequency
  658. unit := info.Unit
  659. namePrefix := info.NamePrefix
  660. namePrefixPingin := "yyzx" + utils.GetFirstPingYin(namePrefix)
  661. /*classifyName := "周度-冻品库存多样本"
  662. frequency := "周度"
  663. unit := "%"
  664. namePrefix := "冻品库存多样本"
  665. namePrefixPingin := "yyzxdpkcdyb"*/
  666. // 遍历行读取
  667. indexList = make([]*models.YongyiExcelIndex, 0)
  668. areaMap := make(map[int]string)
  669. maxRow := sheet.MaxRow
  670. sort := 0
  671. fmt.Println("最大行")
  672. fmt.Println(maxRow)
  673. // 指标名称
  674. indexMap := make(map[string]*models.YongyiExcelIndex)
  675. for i := 0; i < maxRow; i++ {
  676. fmt.Printf("当前第%d行 \n", i)
  677. if i == 0 {
  678. continue
  679. } else if i == 1 { //表示表头
  680. // 处理 index指标表
  681. row := sheet.Row(i)
  682. cells := row.Cells
  683. for k, cell := range cells {
  684. text := cell.String()
  685. if text != "" {
  686. areaMap[k] = text
  687. }
  688. }
  689. } else { //数据列
  690. row := sheet.Row(i)
  691. cells := row.Cells
  692. date := ""
  693. for k, cell := range cells {
  694. fmt.Printf("当前第%d列 \n", k)
  695. text := cell.String()
  696. if k == 0 {
  697. tmpRow := row
  698. r := &ExcelDateRecord{}
  699. if e := tmpRow.ReadStruct(r); e != nil {
  700. utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 读取行,时间列失败 Err:%s", sheet.Name, i, k, e))
  701. continue
  702. }
  703. date = r.Date.Format(utils.FormatDate)
  704. fmt.Println(date)
  705. continue
  706. } else {
  707. // 判断出不是字符的,则过滤
  708. if text == "" {
  709. continue
  710. }
  711. if strings.Contains(text, "%") {
  712. text = strings.Replace(text, "%", "", 1)
  713. }
  714. _, e := strconv.ParseFloat(text, 64)
  715. if e != nil {
  716. utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 strconv.ParseFloat Err:%s", sheet.Name, i, k, e))
  717. continue
  718. }
  719. }
  720. area, ok2 := areaMap[k]
  721. if !ok2 {
  722. err = fmt.Errorf("找不到对应的列名,第%d行,第%d列", i, k)
  723. return
  724. }
  725. fmt.Printf("当前第%d行第%d列, 当前省份%s \n", i, k, area)
  726. // 处理指标名称
  727. fullIndexName := fmt.Sprintf("%s/%s", namePrefix, area)
  728. areaPingyin := utils.GetFirstPingYin(area)
  729. if sheet.Name == "月度出栏完成率" {
  730. areaPingyin = utils.GetFullPingYin(area)
  731. }
  732. fullIndexNamePingyin := namePrefixPingin + areaPingyin
  733. indexItem, okIndex := indexMap[fullIndexName]
  734. if !okIndex {
  735. // 新增指标
  736. indexItem = new(models.YongyiExcelIndex)
  737. indexItem.IndexName = fullIndexName
  738. indexItem.ClassifyName = classifyName
  739. indexItem.IndexCode = fullIndexNamePingyin
  740. indexItem.Frequency = frequency
  741. indexItem.Sort = sort
  742. indexItem.Unit = unit
  743. indexItem.ExcelDataMap = make(map[string]string)
  744. sort++
  745. }
  746. fmt.Printf("IndexCode: %s", indexItem.IndexCode)
  747. indexItem.ExcelDataMap[date] = text
  748. indexMap[fullIndexName] = indexItem
  749. continue
  750. }
  751. }
  752. }
  753. for _, v := range indexMap {
  754. indexList = append(indexList, v)
  755. }
  756. return
  757. }
  758. // HandleYongyiExcelWeekly7 月度计划出栏量
  759. func HandleYongyiExcelWeekly7(sheet *xlsx.Sheet) (indexList []*models.YongyiExcelIndex, err error) {
  760. classifyName := "月度计划出栏量"
  761. frequency := "月度"
  762. unit := "%"
  763. namePrefix := "月度计划出栏量环比"
  764. namePrefixPingin := "yyzx" + utils.GetFirstPingYin(namePrefix)
  765. // 遍历行读取
  766. indexList = make([]*models.YongyiExcelIndex, 0)
  767. provinceMap := make(map[int]string)
  768. firstMap := make(map[int]string)
  769. maxRow := sheet.MaxRow
  770. sort := 0
  771. fmt.Println("最大行")
  772. fmt.Println(maxRow)
  773. // 指标名称
  774. indexMap := make(map[string]*models.YongyiExcelIndex)
  775. for i := 0; i < maxRow; i++ {
  776. fmt.Printf("当前第%d行 \n", i)
  777. if i == 0 {
  778. // 处理 index指标表
  779. row := sheet.Row(i)
  780. cells := row.Cells
  781. for k, cell := range cells {
  782. text := cell.String()
  783. if text != "" {
  784. firstMap[k] = text
  785. }
  786. }
  787. continue
  788. } else if i == 1 { //表示表头
  789. // 处理 index指标表
  790. row := sheet.Row(i)
  791. cells := row.Cells
  792. for k, cell := range cells {
  793. text := cell.String()
  794. if text != "" {
  795. provinceMap[k] = text
  796. }
  797. }
  798. } else { //数据列
  799. row := sheet.Row(i)
  800. cells := row.Cells
  801. date := ""
  802. for k, cell := range cells {
  803. fmt.Printf("当前第%d列 \n", k)
  804. text := cell.String()
  805. if k == 0 {
  806. tmpRow := row
  807. r := &ExcelDateRecordFirst{}
  808. if e := tmpRow.ReadStruct(r); e != nil {
  809. utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 读取行,时间列失败 Err:%s", sheet.Name, i, k, e))
  810. continue
  811. }
  812. // 查询当月的最后一天
  813. monthDate := r.Date.Format(utils.FormatYearMonthDate)
  814. firstDayStr := monthDate + "-01"
  815. tmpT, _ := time.ParseInLocation(utils.FormatDate, firstDayStr, time.Local)
  816. date = tmpT.AddDate(0, 1, -1).Format(utils.FormatDate)
  817. fmt.Println(date)
  818. continue
  819. } else {
  820. // 判断出不是字符的,则过滤
  821. if text == "" {
  822. continue
  823. }
  824. if strings.Contains(text, "%") {
  825. text = strings.Replace(text, "%", "", 1)
  826. }
  827. _, e := strconv.ParseFloat(text, 64)
  828. if e != nil {
  829. utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 strconv.ParseFloat Err:%s", sheet.Name, i, k, e))
  830. continue
  831. }
  832. }
  833. province, ok1 := provinceMap[k]
  834. if !ok1 {
  835. err = fmt.Errorf("找不到对应的列名,第%d行,第%d列", i, k)
  836. return
  837. }
  838. if province == "本月计划较上月实际销售" {
  839. continue
  840. }
  841. fmt.Printf("当前第%d行第%d列, 当前省份: %s \n", i, k, province)
  842. // 处理指标名称
  843. fullIndexName := fmt.Sprintf("%s/%s", namePrefix, province)
  844. provincePingyin := utils.GetFullPingYin(province)
  845. fullIndexNamePingyin := namePrefixPingin + provincePingyin
  846. if province == "数量" {
  847. first, ok2 := firstMap[k]
  848. if !ok2 {
  849. continue
  850. }
  851. fullIndexName = first
  852. firstPingyin := utils.GetFirstPingYin(first)
  853. fullIndexNamePingyin = "yyzx" + firstPingyin
  854. unit = "万头"
  855. }
  856. indexItem, okIndex := indexMap[fullIndexName]
  857. if !okIndex {
  858. // 新增指标
  859. indexItem = new(models.YongyiExcelIndex)
  860. indexItem.IndexName = fullIndexName
  861. indexItem.ClassifyName = classifyName
  862. indexItem.IndexCode = fullIndexNamePingyin
  863. indexItem.Frequency = frequency
  864. indexItem.Sort = sort
  865. indexItem.Unit = unit
  866. indexItem.ExcelDataMap = make(map[string]string)
  867. sort++
  868. }
  869. fmt.Printf("IndexCode: %s\n", indexItem.IndexCode)
  870. indexItem.ExcelDataMap[date] = text
  871. indexMap[fullIndexName] = indexItem
  872. continue
  873. }
  874. }
  875. }
  876. for _, v := range indexMap {
  877. indexList = append(indexList, v)
  878. }
  879. return
  880. }
  881. // HandleYongyiExcelWeekly8 月度-能繁母猪存栏(2020年2月新增)
  882. func HandleYongyiExcelWeekly8(sheet *xlsx.Sheet) (indexList []*models.YongyiExcelIndex, err error) {
  883. classifyName := "月度-能繁母猪存栏(2020年2月新增)"
  884. frequency := "月度"
  885. unit := "头"
  886. namePrefix := "能繁母猪存栏量"
  887. namePrefixPingin := "yyzx" + utils.GetFirstPingYin(namePrefix)
  888. // 遍历行读取
  889. indexList = make([]*models.YongyiExcelIndex, 0)
  890. areaMap := make(map[int]string)
  891. maxRow := sheet.MaxRow
  892. sort := 0
  893. fmt.Println("最大行")
  894. fmt.Println(maxRow)
  895. // 指标名称
  896. indexMap := make(map[string]*models.YongyiExcelIndex)
  897. for i := 0; i < maxRow; i++ {
  898. fmt.Printf("当前第%d行 \n", i)
  899. if i <= 2 {
  900. continue
  901. } else if i == 3 { //表示表头
  902. // 处理 index指标表
  903. row := sheet.Row(i)
  904. cells := row.Cells
  905. for k, cell := range cells {
  906. text := cell.String()
  907. if text != "" {
  908. areaMap[k] = text
  909. }
  910. }
  911. } else { //数据列
  912. row := sheet.Row(i)
  913. cells := row.Cells
  914. date := ""
  915. for k, cell := range cells {
  916. fmt.Printf("当前第%d列 \n", k)
  917. text := cell.String()
  918. if k == 0 {
  919. tmpRow := row
  920. r := &ExcelDateRecordFirst{}
  921. if e := tmpRow.ReadStruct(r); e != nil {
  922. utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 读取行,时间列失败 Err:%s", sheet.Name, i, k, e))
  923. continue
  924. }
  925. // 查询当月的最后一天
  926. monthDate := r.Date.Format(utils.FormatYearMonthDate)
  927. firstDayStr := monthDate + "-01"
  928. tmpT, _ := time.ParseInLocation(utils.FormatDate, firstDayStr, time.Local)
  929. date = tmpT.AddDate(0, 1, -1).Format(utils.FormatDate)
  930. fmt.Println(date)
  931. continue
  932. } else {
  933. // 判断出不是字符的,则过滤
  934. if text == "" {
  935. continue
  936. }
  937. if strings.Contains(text, "%") {
  938. text = strings.Replace(text, "%", "", 1)
  939. }
  940. _, e := strconv.ParseFloat(text, 64)
  941. if e != nil {
  942. utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 strconv.ParseFloat Err:%s", sheet.Name, i, k, e))
  943. continue
  944. }
  945. }
  946. area, ok1 := areaMap[k]
  947. if !ok1 {
  948. err = fmt.Errorf("找不到对应的列名,第%d行,第%d列", i, k)
  949. return
  950. }
  951. if area == "环比" || area == "日期" || area == "同比" {
  952. continue
  953. }
  954. fmt.Printf("当前第%d行第%d列, 当前省份: %s \n", i, k, area)
  955. // 处理指标名称
  956. fullIndexName := fmt.Sprintf("%s/%s", namePrefix, area)
  957. areaPingyin := utils.GetFirstPingYin(area)
  958. fullIndexNamePingyin := namePrefixPingin + areaPingyin
  959. indexItem, okIndex := indexMap[fullIndexName]
  960. if !okIndex {
  961. // 新增指标
  962. indexItem = new(models.YongyiExcelIndex)
  963. indexItem.IndexName = fullIndexName
  964. indexItem.ClassifyName = classifyName
  965. indexItem.IndexCode = fullIndexNamePingyin
  966. indexItem.Frequency = frequency
  967. indexItem.Sort = sort
  968. indexItem.Unit = unit
  969. indexItem.ExcelDataMap = make(map[string]string)
  970. sort++
  971. }
  972. fmt.Printf("IndexCode: %s\n", indexItem.IndexCode)
  973. indexItem.ExcelDataMap[date] = text
  974. indexMap[fullIndexName] = indexItem
  975. continue
  976. }
  977. }
  978. }
  979. for _, v := range indexMap {
  980. indexList = append(indexList, v)
  981. }
  982. return
  983. }
  984. // HandleYongyiExcelWeekly9 月度-小猪存栏(2020年5月新增)
  985. func HandleYongyiExcelWeekly9(sheet *xlsx.Sheet) (indexList []*models.YongyiExcelIndex, err error) {
  986. info, ok := YongyiWeeklySheetMap9[sheet.Name]
  987. if !ok {
  988. return
  989. }
  990. classifyName := info.ClassifyName
  991. frequency := info.Frequency
  992. unit := info.Unit
  993. namePrefix := info.NamePrefix
  994. namePrefixPingin := "yyzx" + utils.GetFirstPingYin(namePrefix)
  995. // 遍历行读取
  996. indexList = make([]*models.YongyiExcelIndex, 0)
  997. areaMap := make(map[int]string)
  998. maxRow := sheet.MaxRow
  999. sort := 0
  1000. fmt.Println("最大行")
  1001. fmt.Println(maxRow)
  1002. // 指标名称
  1003. indexMap := make(map[string]*models.YongyiExcelIndex)
  1004. for i := 0; i < maxRow; i++ {
  1005. fmt.Printf("当前第%d行 \n", i)
  1006. if i <= 1 {
  1007. continue
  1008. } else if i == 2 { //表示表头
  1009. // 处理 index指标表
  1010. row := sheet.Row(i)
  1011. cells := row.Cells
  1012. for k, cell := range cells {
  1013. text := cell.String()
  1014. if text != "" {
  1015. areaMap[k] = text
  1016. }
  1017. }
  1018. } else { //数据列
  1019. row := sheet.Row(i)
  1020. cells := row.Cells
  1021. date := ""
  1022. for k, cell := range cells {
  1023. fmt.Printf("当前第%d列 \n", k)
  1024. text := cell.String()
  1025. if k == 0 {
  1026. tmpRow := row
  1027. r := &ExcelDateRecordFirst{}
  1028. if e := tmpRow.ReadStruct(r); e != nil {
  1029. utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 读取行,时间列失败 Err:%s", sheet.Name, i, k, e))
  1030. continue
  1031. }
  1032. // 查询当月的最后一天
  1033. monthDate := r.Date.Format(utils.FormatYearMonthDate)
  1034. firstDayStr := monthDate + "-01"
  1035. tmpT, _ := time.ParseInLocation(utils.FormatDate, firstDayStr, time.Local)
  1036. date = tmpT.AddDate(0, 1, -1).Format(utils.FormatDate)
  1037. fmt.Println(date)
  1038. continue
  1039. } else {
  1040. // 判断出不是字符的,则过滤
  1041. if text == "" {
  1042. continue
  1043. }
  1044. if strings.Contains(text, "%") {
  1045. text = strings.Replace(text, "%", "", 1)
  1046. }
  1047. _, e := strconv.ParseFloat(text, 64)
  1048. if e != nil {
  1049. utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 strconv.ParseFloat Err:%s", sheet.Name, i, k, e))
  1050. continue
  1051. }
  1052. }
  1053. area, ok1 := areaMap[k]
  1054. if !ok1 {
  1055. err = fmt.Errorf("找不到对应的列名,第%d行,第%d列", i, k)
  1056. return
  1057. }
  1058. if area == "环比" || area == "日期" || area == "同比" {
  1059. continue
  1060. }
  1061. fmt.Printf("当前第%d行第%d列, 当前省份: %s \n", i, k, area)
  1062. // 处理指标名称
  1063. fullIndexName := fmt.Sprintf("%s/%s", namePrefix, area)
  1064. areaPingyin := utils.GetFirstPingYin(area)
  1065. fullIndexNamePingyin := namePrefixPingin + areaPingyin
  1066. indexItem, okIndex := indexMap[fullIndexName]
  1067. if !okIndex {
  1068. // 新增指标
  1069. indexItem = new(models.YongyiExcelIndex)
  1070. indexItem.IndexName = fullIndexName
  1071. indexItem.ClassifyName = classifyName
  1072. indexItem.IndexCode = fullIndexNamePingyin
  1073. indexItem.Frequency = frequency
  1074. indexItem.Sort = sort
  1075. indexItem.Unit = unit
  1076. indexItem.ExcelDataMap = make(map[string]string)
  1077. sort++
  1078. }
  1079. fmt.Printf("IndexCode: %s\n", indexItem.IndexCode)
  1080. indexItem.ExcelDataMap[date] = text
  1081. indexMap[fullIndexName] = indexItem
  1082. continue
  1083. }
  1084. }
  1085. }
  1086. for _, v := range indexMap {
  1087. indexList = append(indexList, v)
  1088. }
  1089. return
  1090. }
  1091. // HandleYongyiExcelWeekly10 月度-商品猪出栏量
  1092. func HandleYongyiExcelWeekly10(sheet *xlsx.Sheet) (indexList []*models.YongyiExcelIndex, err error) {
  1093. classifyName := "月度-商品猪出栏量"
  1094. frequency := "月度"
  1095. unit := "头"
  1096. namePrefix := "商品猪出栏量"
  1097. namePrefixPingin := "yyzx" + utils.GetFirstPingYin(namePrefix)
  1098. // 遍历行读取
  1099. indexList = make([]*models.YongyiExcelIndex, 0)
  1100. areaMap := make(map[int]string)
  1101. maxRow := sheet.MaxRow
  1102. sort := 0
  1103. fmt.Println("最大行")
  1104. fmt.Println(maxRow)
  1105. // 指标名称
  1106. indexMap := make(map[string]*models.YongyiExcelIndex)
  1107. for i := 0; i < maxRow; i++ {
  1108. fmt.Printf("当前第%d行 \n", i)
  1109. if i == 0 {
  1110. continue
  1111. } else if i == 1 { //表示表头
  1112. // 处理 index指标表
  1113. row := sheet.Row(i)
  1114. cells := row.Cells
  1115. for k, cell := range cells {
  1116. text := cell.String()
  1117. if text != "" {
  1118. areaMap[k] = text
  1119. }
  1120. }
  1121. } else { //数据列
  1122. row := sheet.Row(i)
  1123. cells := row.Cells
  1124. date := ""
  1125. for k, cell := range cells {
  1126. fmt.Printf("当前第%d列 \n", k)
  1127. text := cell.String()
  1128. if k == 0 {
  1129. tmpRow := row
  1130. r := &ExcelDateRecordFirst{}
  1131. if e := tmpRow.ReadStruct(r); e != nil {
  1132. utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 读取行,时间列失败 Err:%s", sheet.Name, i, k, e))
  1133. continue
  1134. }
  1135. // 查询当月的最后一天
  1136. monthDate := r.Date.Format(utils.FormatYearMonthDate)
  1137. firstDayStr := monthDate + "-01"
  1138. tmpT, _ := time.ParseInLocation(utils.FormatDate, firstDayStr, time.Local)
  1139. date = tmpT.AddDate(0, 1, -1).Format(utils.FormatDate)
  1140. fmt.Println(date)
  1141. continue
  1142. } else {
  1143. // 判断出不是字符的,则过滤
  1144. if text == "" {
  1145. continue
  1146. }
  1147. if strings.Contains(text, "%") {
  1148. text = strings.Replace(text, "%", "", 1)
  1149. }
  1150. _, e := strconv.ParseFloat(text, 64)
  1151. if e != nil {
  1152. utils.FileLog.Info(fmt.Sprintf("sheet:%s 第%d行, 第%d列 strconv.ParseFloat Err:%s", sheet.Name, i, k, e))
  1153. continue
  1154. }
  1155. }
  1156. area, ok1 := areaMap[k]
  1157. if !ok1 {
  1158. err = fmt.Errorf("找不到对应的列名,第%d行,第%d列", i, k)
  1159. return
  1160. }
  1161. if area == "环比" || area == "日期" || area == "同比" || area == "较非瘟前" {
  1162. continue
  1163. }
  1164. fmt.Printf("当前第%d行第%d列, 当前省份: %s \n", i, k, area)
  1165. // 处理指标名称
  1166. fullIndexName := fmt.Sprintf("%s/%s", namePrefix, area)
  1167. areaPingyin := utils.GetFirstPingYin(area)
  1168. fullIndexNamePingyin := namePrefixPingin + areaPingyin
  1169. indexItem, okIndex := indexMap[fullIndexName]
  1170. if !okIndex {
  1171. // 新增指标
  1172. indexItem = new(models.YongyiExcelIndex)
  1173. indexItem.IndexName = fullIndexName
  1174. indexItem.ClassifyName = classifyName
  1175. indexItem.IndexCode = fullIndexNamePingyin
  1176. indexItem.Frequency = frequency
  1177. indexItem.Sort = sort
  1178. indexItem.Unit = unit
  1179. indexItem.ExcelDataMap = make(map[string]string)
  1180. sort++
  1181. }
  1182. fmt.Printf("IndexCode: %s\n", indexItem.IndexCode)
  1183. indexItem.ExcelDataMap[date] = text
  1184. indexMap[fullIndexName] = indexItem
  1185. continue
  1186. }
  1187. }
  1188. }
  1189. for _, v := range indexMap {
  1190. indexList = append(indexList, v)
  1191. }
  1192. return
  1193. }