week20.go 38 KB

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