week20.go 38 KB

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