/** * 基于金额的审批规则 */ package com.orderprocessing; public class AmountBasedApprovalRule implements ApprovalRule { private double threshold; private int approvalLevel; private String description; /** * 构造方法 * @param threshold 审批阈值 * @param approvalLevel 审批级别 */ public AmountBasedApprovalRule(double threshold, int approvalLevel) { this.threshold = threshold; this.approvalLevel = approvalLevel; this.description = "订单金额超过" + threshold + "元需要" + approvalLevel + "级审批"; } @Override public boolean requiresApproval(Order order) { return order != null && order.getTotalAmount() > threshold; } @Override public int getApprovalLevel() { return approvalLevel; } @Override public String getDescription() { return description; } public double getThreshold() { return threshold; } }