week10.go 39 KB

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