processor_factory.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // @Author gmy 2024/8/6 10:48:00
  2. package main
  3. import (
  4. "context"
  5. "eta/eta_crawler/models"
  6. "fmt"
  7. )
  8. type ReportProcessor interface {
  9. Process(ctx context.Context, product string, reportContent string, keywords []string, classifyId int) ([]models.BaseFromLyData, error)
  10. }
  11. func GetProcessor(product string, category string) (ReportProcessor, error) {
  12. if product == "大豆" {
  13. switch category {
  14. case "进口成本":
  15. return &ImportCostProcessor{}, nil
  16. case "加工利润":
  17. return &ProcessingProfitProcessor{}, nil
  18. case "加工报告":
  19. return &ProcessingReportProcessor{}, nil
  20. case "船运费用":
  21. return &ShippingCostProcessor{}, nil
  22. case "供需平衡":
  23. return &SupplyDemandBalanceProcessor{}, nil
  24. case "采购装船":
  25. return &PurchaseShippingProcessor{}, nil
  26. case "库存分析":
  27. return &InventoryAnalysisProcessor{}, nil
  28. default:
  29. return nil, fmt.Errorf("unknown category: %s", category)
  30. }
  31. } else if product == "豆粕" {
  32. switch category {
  33. case "库存分析":
  34. return &InventoryAnalysisProcessor{}, nil
  35. default:
  36. return nil, fmt.Errorf("unknown category: %s", category)
  37. }
  38. } else if product == "大豆油" {
  39. switch category {
  40. case "库存分析":
  41. return &InventoryAnalysisProcessor{}, nil
  42. case "价差套利":
  43. return &PriceSpreadArbitrageProcessor{}, nil
  44. case "每日成交":
  45. return &DailyTransactionProcessor{}, nil
  46. default:
  47. return nil, fmt.Errorf("unknown category: %s", category)
  48. }
  49. } else if product == "棕榈油" {
  50. switch category {
  51. case "库存分析":
  52. return &InventoryAnalysisProcessor{}, nil
  53. case "每日成交":
  54. return &DailyTransactionProcessor{}, nil
  55. default:
  56. return nil, fmt.Errorf("unknown category: %s", category)
  57. }
  58. } else if product == "油菜籽" {
  59. switch category {
  60. case "进口成本":
  61. return &ImportCostProcessor{}, nil
  62. case "库存分析":
  63. return &InventoryAnalysisProcessor{}, nil
  64. default:
  65. return nil, fmt.Errorf("unknown category: %s", category)
  66. }
  67. } else if product == "菜粕" {
  68. switch category {
  69. case "库存分析":
  70. return &InventoryAnalysisProcessor{}, nil
  71. default:
  72. return nil, fmt.Errorf("unknown category: %s", category)
  73. }
  74. } else if product == "菜籽油" {
  75. switch category {
  76. case "库存分析":
  77. return &InventoryAnalysisProcessor{}, nil
  78. default:
  79. return nil, fmt.Errorf("unknown category: %s", category)
  80. }
  81. }
  82. // 可以添加更多的逻辑来处理其他产品和类别
  83. return nil, fmt.Errorf("no processor found for product %s and category %s", product, category)
  84. }