processor_factory.go 3.3 KB

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