week20.go 39 KB

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