week.go 38 KB

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