commodity_coal.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. package services
  2. import (
  3. "encoding/json"
  4. "eta/eta_crawler/models"
  5. "eta/eta_crawler/utils"
  6. "fmt"
  7. "github.com/tealeg/xlsx"
  8. )
  9. func JsmHistory(path string) (err error) {
  10. defer func() {
  11. if err != nil {
  12. fmt.Println("RefreshDataFromCoalCoastal Err:" + err.Error())
  13. utils.FileLog.Info(fmt.Sprintf("RefreshDataFromCoalCoastal, Err: %s", err))
  14. }
  15. }()
  16. var xlFile *xlsx.File
  17. exist, err := PathExists(path)
  18. if err != nil {
  19. fmt.Println(err)
  20. return
  21. }
  22. if exist {
  23. xlFile, err = xlsx.OpenFile(path)
  24. if err != nil {
  25. fmt.Println("OpenFile err:", err)
  26. return
  27. }
  28. } else {
  29. fmt.Println("Not Exist")
  30. return
  31. }
  32. sheetDatas := make([]models.CoalSheetData, 0)
  33. data := *xlFile.Sheets[0]
  34. sheetData := models.CoalSheetData{
  35. Name: data.Name,
  36. MaxRow: data.MaxRow,
  37. MaxCol: data.MaxCol,
  38. Hidden: data.Hidden,
  39. Selected: data.Selected,
  40. }
  41. rows := make([]models.Row, 0)
  42. for _, v := range data.Rows {
  43. cells := make([]models.Cell, 0)
  44. for _, cell := range v.Cells {
  45. cells = append(cells, models.Cell{
  46. Value: cell.String(),
  47. })
  48. }
  49. row := models.Row{
  50. Cells: cells,
  51. }
  52. rows = append(rows, row)
  53. }
  54. sheetData.Rows = rows
  55. sheetDatas = append(sheetDatas, sheetData)
  56. params := make(map[string]interface{})
  57. params["SheetData"] = sheetDatas
  58. result, e := PostEdbLib(params, utils.LIB_ROUTE_COAL_MINE_JSM_HISTORY)
  59. if e != nil {
  60. b, _ := json.Marshal(params)
  61. fmt.Println(e)
  62. utils.FileLog.Info(fmt.Sprintf("PostEdbLib err: %s, params: %s", e.Error(), string(b)))
  63. return
  64. }
  65. resp := new(models.BaseResponse)
  66. if e := json.Unmarshal(result, &resp); e != nil {
  67. utils.FileLog.Info(fmt.Sprintf("json.Unmarshal err: %s", e))
  68. return
  69. }
  70. if resp.Ret != 200 {
  71. utils.FileLog.Info(fmt.Sprintf("Msg: %s, ErrMsg: %s", resp.Msg, resp.ErrMsg))
  72. return
  73. }
  74. return
  75. }
  76. func CoastalHistory(path string) (err error) {
  77. defer func() {
  78. if err != nil {
  79. fmt.Println("RefreshDataFromCoalCoastal Err:" + err.Error())
  80. utils.FileLog.Info(fmt.Sprintf("RefreshDataFromCoalCoastal, Err: %s", err))
  81. }
  82. }()
  83. //path := "/Users/xi/Desktop/瑞茂通-中国煤炭市场网数据/442家晋陕蒙、沿海8省、内陆17省历史数据/CⅢ-8-16 25省市库存和日耗情况(CCTD).xlsx"
  84. //path := "D:\\瑞茂通-中国煤炭市场网数据\\442家晋陕蒙、沿海8省、内陆17省历史数据\\CⅢ-8-16 25省市库存和日耗情况(CCTD).xlsx"
  85. var xlFile *xlsx.File
  86. exist, err := PathExists(path)
  87. if err != nil {
  88. fmt.Println(err)
  89. return
  90. }
  91. if exist {
  92. xlFile, err = xlsx.OpenFile(path)
  93. if err != nil {
  94. fmt.Println("OpenFile err:", err)
  95. return
  96. }
  97. } else {
  98. fmt.Println("Not Exist")
  99. return
  100. }
  101. sheetDatas := make([]models.CoalSheetData, 0)
  102. for i, sheet := range xlFile.Sheets {
  103. if i < 4 {
  104. data := sheet
  105. sheetData := models.CoalSheetData{
  106. Name: data.Name,
  107. MaxRow: data.MaxRow,
  108. MaxCol: data.MaxCol,
  109. Hidden: data.Hidden,
  110. Selected: data.Selected,
  111. }
  112. rows := make([]models.Row, 0)
  113. for _, v := range data.Rows {
  114. cells := make([]models.Cell, 0)
  115. for _, cell := range v.Cells {
  116. cells = append(cells, models.Cell{
  117. Value: cell.String(),
  118. })
  119. }
  120. row := models.Row{
  121. Cells: cells,
  122. }
  123. rows = append(rows, row)
  124. }
  125. sheetData.Rows = rows
  126. sheetDatas = append(sheetDatas, sheetData)
  127. }
  128. }
  129. params := make(map[string]interface{})
  130. params["SheetData"] = sheetDatas
  131. result, e := PostEdbLib(params, utils.LIB_ROUTE_COAL_MINE_COASTAL_HISTORY)
  132. if e != nil {
  133. b, _ := json.Marshal(params)
  134. fmt.Println(e)
  135. utils.FileLog.Info(fmt.Sprintf("PostEdbLib err: %s, params: %s", e.Error(), string(b)))
  136. return
  137. }
  138. resp := new(models.BaseResponse)
  139. if e := json.Unmarshal(result, &resp); e != nil {
  140. utils.FileLog.Info(fmt.Sprintf("json.Unmarshal err: %s", e))
  141. return
  142. }
  143. if resp.Ret != 200 {
  144. utils.FileLog.Info(fmt.Sprintf("Msg: %s, ErrMsg: %s", resp.Msg, resp.ErrMsg))
  145. return
  146. }
  147. return
  148. }
  149. func InlandHistory(path string) (err error) {
  150. defer func() {
  151. if err != nil {
  152. fmt.Println("RefreshDataFromCoalCoastal Err:" + err.Error())
  153. utils.FileLog.Info(fmt.Sprintf("RefreshDataFromCoalCoastal, Err: %s", err))
  154. }
  155. }()
  156. //path := "/Users/xi/Desktop/瑞茂通-中国煤炭市场网数据/442家晋陕蒙、沿海8省、内陆17省历史数据/CⅢ-8-16 25省市库存和日耗情况(CCTD).xlsx"
  157. //path := "D:\\瑞茂通-中国煤炭市场网数据\\442家晋陕蒙、沿海8省、内陆17省历史数据\\CⅢ-8-16 25省市库存和日耗情况(CCTD).xlsx"
  158. var xlFile *xlsx.File
  159. exist, err := PathExists(path)
  160. if err != nil {
  161. fmt.Println(err)
  162. return
  163. }
  164. if exist {
  165. xlFile, err = xlsx.OpenFile(path)
  166. if err != nil {
  167. fmt.Println("OpenFile err:", err)
  168. return
  169. }
  170. } else {
  171. fmt.Println("Not Exist")
  172. return
  173. }
  174. sheetDatas := make([]models.CoalSheetData, 0)
  175. for i, sheet := range xlFile.Sheets {
  176. if i > 3 {
  177. data := sheet
  178. sheetData := models.CoalSheetData{
  179. Name: data.Name,
  180. MaxRow: data.MaxRow,
  181. MaxCol: data.MaxCol,
  182. Hidden: data.Hidden,
  183. Selected: data.Selected,
  184. }
  185. rows := make([]models.Row, 0)
  186. for _, v := range data.Rows {
  187. cells := make([]models.Cell, 0)
  188. for _, cell := range v.Cells {
  189. cells = append(cells, models.Cell{
  190. Value: cell.String(),
  191. })
  192. }
  193. row := models.Row{
  194. Cells: cells,
  195. }
  196. rows = append(rows, row)
  197. }
  198. sheetData.Rows = rows
  199. sheetDatas = append(sheetDatas, sheetData)
  200. }
  201. }
  202. params := make(map[string]interface{})
  203. params["SheetData"] = sheetDatas
  204. result, e := PostEdbLib(params, utils.LIB_ROUTE_COAL_MINE_INLAND_HISTORY)
  205. if e != nil {
  206. b, _ := json.Marshal(params)
  207. fmt.Println(e)
  208. utils.FileLog.Info(fmt.Sprintf("PostEdbLib err: %s, params: %s", e.Error(), string(b)))
  209. return
  210. }
  211. resp := new(models.BaseResponse)
  212. if e := json.Unmarshal(result, &resp); e != nil {
  213. utils.FileLog.Info(fmt.Sprintf("json.Unmarshal err: %s", e))
  214. return
  215. }
  216. if resp.Ret != 200 {
  217. utils.FileLog.Info(fmt.Sprintf("Msg: %s, ErrMsg: %s", resp.Msg, resp.ErrMsg))
  218. return
  219. }
  220. return
  221. }
  222. func Jsm(path string) (err error) {
  223. defer func() {
  224. if err != nil {
  225. fmt.Println("RefreshDataFromCoalCoastal Err:" + err.Error())
  226. utils.FileLog.Info(fmt.Sprintf("RefreshDataFromCoalCoastal, Err: %s", err))
  227. }
  228. }()
  229. //path := "/home/code/python/coal_mail/emailFile/沿海八省动力煤终端用户供耗存数据更新.xlsx"
  230. //path := "/Users/xi/Desktop/瑞茂通-中国煤炭市场网数据/442家晋陕蒙、沿海8省、内陆17省最新数据/442家晋陕蒙煤矿周度产量数据-20231201.xlsx"
  231. //path := "D:\\瑞茂通-中国煤炭市场网数据\\442家晋陕蒙、沿海8省、内陆17省历史数据\\442家晋陕蒙历史数据.xlsx"
  232. var xlFile *xlsx.File
  233. exist, err := PathExists(path)
  234. if err != nil {
  235. fmt.Println(err)
  236. return
  237. }
  238. if exist {
  239. xlFile, err = xlsx.OpenFile(path)
  240. if err != nil {
  241. fmt.Println("OpenFile err:", err)
  242. return
  243. }
  244. } else {
  245. fmt.Println("Not Exist")
  246. return
  247. }
  248. sheetDatas := make([]models.CoalSheetData, 0)
  249. data := *xlFile.Sheets[0]
  250. sheetData := models.CoalSheetData{
  251. Name: data.Name,
  252. MaxRow: data.MaxRow,
  253. MaxCol: data.MaxCol,
  254. Hidden: data.Hidden,
  255. Selected: data.Selected,
  256. }
  257. rows := make([]models.Row, 0)
  258. for _, v := range data.Rows {
  259. cells := make([]models.Cell, 0)
  260. for _, cell := range v.Cells {
  261. cells = append(cells, models.Cell{
  262. Value: cell.String(),
  263. })
  264. }
  265. row := models.Row{
  266. Cells: cells,
  267. }
  268. rows = append(rows, row)
  269. }
  270. sheetData.Rows = rows
  271. sheetDatas = append(sheetDatas, sheetData)
  272. params := make(map[string]interface{})
  273. params["SheetData"] = sheetDatas
  274. result, e := PostEdbLib(params, utils.LIB_ROUTE_COAL_MINE_JSM)
  275. if e != nil {
  276. b, _ := json.Marshal(params)
  277. fmt.Println(e)
  278. utils.FileLog.Info(fmt.Sprintf("PostEdbLib err: %s, params: %s", e.Error(), string(b)))
  279. return
  280. }
  281. resp := new(models.BaseResponse)
  282. if e := json.Unmarshal(result, &resp); e != nil {
  283. utils.FileLog.Info(fmt.Sprintf("json.Unmarshal err: %s", e))
  284. return
  285. }
  286. if resp.Ret != 200 {
  287. utils.FileLog.Info(fmt.Sprintf("Msg: %s, ErrMsg: %s", resp.Msg, resp.ErrMsg))
  288. return
  289. }
  290. return
  291. }
  292. func Coastal(path string) (err error) {
  293. defer func() {
  294. if err != nil {
  295. fmt.Println("RefreshDataFromCoalCoastal Err:" + err.Error())
  296. utils.FileLog.Info(fmt.Sprintf("RefreshDataFromCoalCoastal, Err: %s", err))
  297. }
  298. }()
  299. //path := "/Users/xi/Desktop/瑞茂通-中国煤炭市场网数据/442家晋陕蒙、沿海8省、内陆17省最新数据/内陆17省动力煤终端用户供耗存.xlsx"
  300. //path := "D:\\瑞茂通-中国煤炭市场网数据\\442家晋陕蒙、沿海8省、内陆17省历史数据\\CⅢ-8-16 25省市库存和日耗情况(CCTD).xlsx"
  301. fmt.Println("沿海开始")
  302. var xlFile *xlsx.File
  303. exist, err := PathExists(path)
  304. if err != nil {
  305. fmt.Println(err)
  306. return
  307. }
  308. if exist {
  309. xlFile, err = xlsx.OpenFile(path)
  310. if err != nil {
  311. fmt.Println("OpenFile err:", err)
  312. return
  313. }
  314. } else {
  315. fmt.Println("Not Exist")
  316. return
  317. }
  318. sheetDatas := make([]models.CoalSheetData, 0)
  319. for _, sheet := range xlFile.Sheets {
  320. data := sheet
  321. sheetData := models.CoalSheetData{
  322. Name: data.Name,
  323. MaxRow: data.MaxRow,
  324. MaxCol: data.MaxCol,
  325. Hidden: data.Hidden,
  326. Selected: data.Selected,
  327. }
  328. rows := make([]models.Row, 0)
  329. for _, v := range data.Rows {
  330. cells := make([]models.Cell, 0)
  331. for _, cell := range v.Cells {
  332. cells = append(cells, models.Cell{
  333. Value: cell.String(),
  334. })
  335. }
  336. row := models.Row{
  337. Cells: cells,
  338. }
  339. rows = append(rows, row)
  340. }
  341. sheetData.Rows = rows
  342. fmt.Println("rows:", len(rows))
  343. sheetDatas = append(sheetDatas, sheetData)
  344. }
  345. fmt.Println("sheetDatas:", len(sheetDatas))
  346. params := make(map[string]interface{})
  347. params["SheetData"] = sheetDatas
  348. result, e := PostEdbLib(params, utils.LIB_ROUTE_COAL_MINE_COASTAL)
  349. if e != nil {
  350. b, _ := json.Marshal(params)
  351. fmt.Println(e)
  352. utils.FileLog.Info(fmt.Sprintf("PostEdbLib err: %s, params: %s", e.Error(), string(b)))
  353. return
  354. }
  355. resp := new(models.BaseResponse)
  356. if e := json.Unmarshal(result, &resp); e != nil {
  357. utils.FileLog.Info(fmt.Sprintf("json.Unmarshal err: %s", e))
  358. return
  359. }
  360. if resp.Ret != 200 {
  361. utils.FileLog.Info(fmt.Sprintf("Msg: %s, ErrMsg: %s", resp.Msg, resp.ErrMsg))
  362. return
  363. }
  364. return
  365. }
  366. func Inland(path string) (err error) {
  367. defer func() {
  368. if err != nil {
  369. fmt.Println("RefreshDataFromCoalCoastal Err:" + err.Error())
  370. utils.FileLog.Info(fmt.Sprintf("RefreshDataFromCoalCoastal, Err: %s", err))
  371. }
  372. }()
  373. //path := "/Users/xi/Desktop/瑞茂通-中国煤炭市场网数据/442家晋陕蒙、沿海8省、内陆17省最新数据/内陆17省动力煤终端用户供耗存.xlsx"
  374. //path := "D:\\瑞茂通-中国煤炭市场网数据\\442家晋陕蒙、沿海8省、内陆17省历史数据\\CⅢ-8-16 25省市库存和日耗情况(CCTD).xlsx"
  375. var xlFile *xlsx.File
  376. exist, err := PathExists(path)
  377. if err != nil {
  378. fmt.Println(err)
  379. return
  380. }
  381. if exist {
  382. xlFile, err = xlsx.OpenFile(path)
  383. if err != nil {
  384. fmt.Println("OpenFile err:", err)
  385. return
  386. }
  387. } else {
  388. fmt.Println("Not Exist")
  389. return
  390. }
  391. sheetDatas := make([]models.CoalSheetData, 0)
  392. for _, sheet := range xlFile.Sheets {
  393. data := sheet
  394. sheetData := models.CoalSheetData{
  395. Name: data.Name,
  396. MaxRow: data.MaxRow,
  397. MaxCol: data.MaxCol,
  398. Hidden: data.Hidden,
  399. Selected: data.Selected,
  400. }
  401. rows := make([]models.Row, 0)
  402. for _, v := range data.Rows {
  403. cells := make([]models.Cell, 0)
  404. for _, cell := range v.Cells {
  405. cells = append(cells, models.Cell{
  406. Value: cell.String(),
  407. })
  408. }
  409. row := models.Row{
  410. Cells: cells,
  411. }
  412. rows = append(rows, row)
  413. }
  414. sheetData.Rows = rows
  415. sheetDatas = append(sheetDatas, sheetData)
  416. }
  417. params := make(map[string]interface{})
  418. params["SheetData"] = sheetDatas
  419. result, e := PostEdbLib(params, utils.LIB_ROUTE_COAL_MINE_INLAND)
  420. if e != nil {
  421. b, _ := json.Marshal(params)
  422. fmt.Println(e)
  423. utils.FileLog.Info(fmt.Sprintf("PostEdbLib err: %s, params: %s", e.Error(), string(b)))
  424. return
  425. }
  426. resp := new(models.BaseResponse)
  427. if e := json.Unmarshal(result, &resp); e != nil {
  428. utils.FileLog.Info(fmt.Sprintf("json.Unmarshal err: %s", e))
  429. return
  430. }
  431. if resp.Ret != 200 {
  432. utils.FileLog.Info(fmt.Sprintf("Msg: %s, ErrMsg: %s", resp.Msg, resp.ErrMsg))
  433. return
  434. }
  435. return
  436. }
  437. func Mtjh(path string) (err error) {
  438. defer func() {
  439. if err != nil {
  440. fmt.Println("RefreshDataFromCoalMtjh Err:" + err.Error())
  441. utils.FileLog.Info(fmt.Sprintf("RefreshDataFromCoalMtjh, Err: %s", err))
  442. }
  443. }()
  444. //path = "/Users/xi/Desktop/煤炭江湖数据定制化服务——中国主流港口煤炭库存20231129.xlsx"
  445. var xlFile *xlsx.File
  446. exist, err := PathExists(path)
  447. if err != nil {
  448. fmt.Println(err)
  449. return
  450. }
  451. if exist {
  452. xlFile, err = xlsx.OpenFile(path)
  453. if err != nil {
  454. fmt.Println("OpenFile err:", err)
  455. return
  456. }
  457. } else {
  458. fmt.Println("Not Exist")
  459. return
  460. }
  461. sheetDatas := make([]models.CoalSheetData, 0)
  462. for i, sheet := range xlFile.Sheets {
  463. if i > 0 {
  464. break
  465. }
  466. data := sheet
  467. sheetData := models.CoalSheetData{
  468. Name: data.Name,
  469. MaxRow: data.MaxRow,
  470. MaxCol: data.MaxCol,
  471. Hidden: data.Hidden,
  472. Selected: data.Selected,
  473. }
  474. rows := make([]models.Row, 0)
  475. for _, v := range data.Rows {
  476. cells := make([]models.Cell, 0)
  477. for _, cell := range v.Cells {
  478. cells = append(cells, models.Cell{
  479. Value: cell.String(),
  480. })
  481. }
  482. row := models.Row{
  483. Cells: cells,
  484. }
  485. rows = append(rows, row)
  486. }
  487. sheetData.Rows = rows
  488. sheetDatas = append(sheetDatas, sheetData)
  489. }
  490. params := make(map[string]interface{})
  491. params["SheetData"] = sheetDatas
  492. result, e := PostEdbLib(params, utils.LIB_ROUTE_COAL_MINE_MTJH)
  493. if e != nil {
  494. b, _ := json.Marshal(params)
  495. fmt.Println(e)
  496. utils.FileLog.Info(fmt.Sprintf("PostEdbLib err: %s, params: %s", e.Error(), string(b)))
  497. return
  498. }
  499. resp := new(models.BaseResponse)
  500. if e := json.Unmarshal(result, &resp); e != nil {
  501. utils.FileLog.Info(fmt.Sprintf("json.Unmarshal err: %s", e))
  502. return
  503. }
  504. if resp.Ret != 200 {
  505. utils.FileLog.Info(fmt.Sprintf("Msg: %s, ErrMsg: %s", resp.Msg, resp.ErrMsg))
  506. return
  507. }
  508. return
  509. }
  510. func Firm(path string) (err error) {
  511. defer func() {
  512. if err != nil {
  513. fmt.Println("RefreshDataFromCoalFirm Err:" + err.Error())
  514. utils.FileLog.Info(fmt.Sprintf("RefreshDataFromCoalFirm, Err: %s", err))
  515. }
  516. }()
  517. //path = "/Users/xi/Desktop/煤炭江湖数据定制化服务——中国主流港口煤炭库存20231129.xlsx"
  518. var xlFile *xlsx.File
  519. exist, err := PathExists(path)
  520. if err != nil {
  521. fmt.Println(err)
  522. return
  523. }
  524. if exist {
  525. xlFile, err = xlsx.OpenFile(path)
  526. if err != nil {
  527. fmt.Println("OpenFile err:", err)
  528. return
  529. }
  530. } else {
  531. fmt.Println("Not Exist")
  532. return
  533. }
  534. sheetDatas := make([]models.CoalSheetData, 0)
  535. for _, sheet := range xlFile.Sheets {
  536. data := sheet
  537. sheetData := models.CoalSheetData{
  538. Name: data.Name,
  539. MaxRow: data.MaxRow,
  540. MaxCol: data.MaxCol,
  541. Hidden: data.Hidden,
  542. Selected: data.Selected,
  543. }
  544. rows := make([]models.Row, 0)
  545. for _, v := range data.Rows {
  546. cells := make([]models.Cell, 0)
  547. for _, cell := range v.Cells {
  548. cells = append(cells, models.Cell{
  549. Value: cell.String(),
  550. })
  551. }
  552. row := models.Row{
  553. Cells: cells,
  554. }
  555. rows = append(rows, row)
  556. }
  557. sheetData.Rows = rows
  558. sheetDatas = append(sheetDatas, sheetData)
  559. }
  560. params := make(map[string]interface{})
  561. params["SheetData"] = sheetDatas
  562. result, e := PostEdbLib(params, utils.LIB_ROUTE_COAL_MINE_FIRM)
  563. if e != nil {
  564. b, _ := json.Marshal(params)
  565. fmt.Println(e)
  566. utils.FileLog.Info(fmt.Sprintf("PostEdbLib err: %s, params: %s", e.Error(), string(b)))
  567. return
  568. }
  569. resp := new(models.BaseResponse)
  570. if e := json.Unmarshal(result, &resp); e != nil {
  571. utils.FileLog.Info(fmt.Sprintf("json.Unmarshal err: %s", e))
  572. return
  573. }
  574. if resp.Ret != 200 {
  575. utils.FileLog.Info(fmt.Sprintf("Msg: %s, ErrMsg: %s", resp.Msg, resp.ErrMsg))
  576. return
  577. }
  578. return
  579. }