You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
3.1 KiB
93 lines
3.1 KiB
/**
|
|
* 订单报表生成器,依赖于各种分析策略,生成不同维度的数据统计和报表
|
|
*/
|
|
package com.orderprocessing;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
public class OrderReportGenerator {
|
|
private Map<String, OrderAnalysisStrategy> analysisStrategies;
|
|
private Logger logger;
|
|
|
|
/**
|
|
* 构造方法
|
|
* @param logger 日志记录器
|
|
*/
|
|
public OrderReportGenerator(Logger logger) {
|
|
this.logger = logger;
|
|
this.analysisStrategies = new HashMap<>();
|
|
}
|
|
|
|
/**
|
|
* 添加分析策略
|
|
* @param strategy 分析策略
|
|
*/
|
|
public void addAnalysisStrategy(OrderAnalysisStrategy strategy) {
|
|
analysisStrategies.put(strategy.getStrategyName(), strategy);
|
|
logger.log("添加分析策略: " + strategy.getStrategyName());
|
|
}
|
|
|
|
/**
|
|
* 使用指定策略分析订单数据
|
|
* @param orders 订单列表
|
|
* @param strategyName 策略名称
|
|
* @return 分析结果
|
|
*/
|
|
public Map<String, Object> generateReport(List<Order> orders, String strategyName) {
|
|
logger.log("生成报表,使用策略: " + strategyName);
|
|
|
|
OrderAnalysisStrategy strategy = analysisStrategies.get(strategyName);
|
|
if (strategy == null) {
|
|
logger.log("错误:找不到名为 '" + strategyName + "' 的分析策略");
|
|
return null;
|
|
}
|
|
|
|
Map<String, Object> results = strategy.analyze(orders);
|
|
logger.log("报表生成完成,策略: " + strategyName);
|
|
|
|
return results;
|
|
}
|
|
|
|
/**
|
|
* 使用所有策略分析订单数据并生成综合报表
|
|
* @param orders 订单列表
|
|
* @return 综合分析结果
|
|
*/
|
|
public Map<String, Map<String, Object>> generateComprehensiveReport(List<Order> orders) {
|
|
logger.log("生成综合报表,使用所有可用策略");
|
|
|
|
Map<String, Map<String, Object>> comprehensiveResults = new HashMap<>();
|
|
|
|
for (Map.Entry<String, OrderAnalysisStrategy> entry : analysisStrategies.entrySet()) {
|
|
String strategyName = entry.getKey();
|
|
OrderAnalysisStrategy strategy = entry.getValue();
|
|
|
|
Map<String, Object> results = strategy.analyze(orders);
|
|
comprehensiveResults.put(strategyName, results);
|
|
|
|
logger.log("已完成策略分析: " + strategyName);
|
|
}
|
|
|
|
logger.log("综合报表生成完成,共使用 " + analysisStrategies.size() + " 种策略");
|
|
|
|
return comprehensiveResults;
|
|
}
|
|
|
|
/**
|
|
* 打印分析结果
|
|
* @param results 分析结果
|
|
*/
|
|
public void printReportResults(Map<String, Object> results) {
|
|
if (results != null) {
|
|
System.out.println("=== 报表结果 ===");
|
|
for (Map.Entry<String, Object> entry : results.entrySet()) {
|
|
System.out.println(entry.getKey() + ": " + entry.getValue());
|
|
}
|
|
System.out.println("===============");
|
|
} else {
|
|
System.out.println("无法生成报表或报表为空");
|
|
}
|
|
}
|
|
} |