week10.go 39 KB

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