index_queue.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package services
  2. import (
  3. "fmt"
  4. "hongze/hongtao3_watch/global"
  5. "hongze/hongtao3_watch/utils"
  6. "path/filepath"
  7. "strings"
  8. )
  9. // HandleFileUpdate 处理文件变化
  10. func HandleFileUpdate() {
  11. defer func() {
  12. if err := recover(); err != nil {
  13. fmt.Println("[AutoHandle]", err)
  14. }
  15. }()
  16. for {
  17. global.Rc.Brpop(utils.HANDLE_HONGTAO_EXCEL, func(b []byte) {
  18. updateFilePath := string(b)
  19. // 移除多余的双引号
  20. updateFilePath = strings.Replace(updateFilePath, `"`, "", -1)
  21. fileExt := filepath.Ext(updateFilePath)
  22. //fmt.Println("fileExt:", fileExt)
  23. if fileExt != ".xlsx" && fileExt != ".xls" {
  24. //fmt.Println("不是excel文件")
  25. return
  26. }
  27. // 读取excel内容并操作入库
  28. ReadExcel(updateFilePath)
  29. })
  30. }
  31. }
  32. // HandleRefreshExcel 处理excel刷新(实际去调用刷新)
  33. func HandleRefreshExcel() {
  34. defer func() {
  35. if err := recover(); err != nil {
  36. fmt.Println("[AutoRefresh]", err)
  37. }
  38. }()
  39. for {
  40. global.Rc.Brpop(utils.REFRESH_HONGTAO_EXCEL, func(b []byte) {
  41. updateFilePath := string(b)
  42. // 移除多余的双引号
  43. updateFilePath = strings.Replace(updateFilePath, `"`, "", -1)
  44. fileExt := filepath.Ext(updateFilePath)
  45. //fmt.Println("fileExt:", fileExt)
  46. if fileExt != ".xlsx" && fileExt != ".xls" {
  47. //fmt.Println("不是excel文件")
  48. return
  49. }
  50. // 读取excel内容并操作入库
  51. InvokeRefreshServer(updateFilePath)
  52. })
  53. }
  54. }