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.
yilai/AmountBasedApprovalRule.java

40 lines
1007 B

/**
* 基于金额的审批规则
*/
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;
}
}