package policy.rule.action;
|
|
import java.math.BigDecimal;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
import foundation.dao.DataWriter;
|
import policy.OrderEvent;
|
import policy.rule.CheckLevel;
|
import policy.rule.CheckResult;
|
import policy.rule.OrderCalculator;
|
import policy.rule.RuleAction;
|
|
public class DiscountCategorySameTimeCheck extends RuleAction {
|
|
public static String remark = "买赠池、积分池、优惠政策不能同时使用限制";
|
|
public DiscountCategorySameTimeCheck() {
|
super();
|
}
|
|
@Override
|
public void createBoard(OrderCalculator calculator, CheckResult result) {
|
int cnt = 0;
|
|
//1. 买赠池
|
BigDecimal rebateQty = calculator.getRebateQty();
|
if (rebateQty.compareTo(BigDecimal.ZERO) > 0) {
|
result.writeOneRemark("买赠池使用数量:" + rebateQty.toString());
|
cnt++;
|
}
|
|
//2. 积分池(票折)
|
BigDecimal rebateAmt = calculator.getRebateAmt();
|
if (rebateAmt.compareTo(BigDecimal.ZERO) > 0) {
|
result.writeOneRemark("积分池使用金额:" + formatMoney(rebateAmt));
|
cnt++;
|
}
|
|
//3. 即时价格折扣
|
BigDecimal onsitePriceAmt = calculator.getOnsitePriceAmt();
|
if (onsitePriceAmt.compareTo(BigDecimal.ZERO) > 0) {
|
result.writeOneRemark("即时价格折扣:" + formatMoney(onsitePriceAmt));
|
cnt++;
|
}
|
|
//4. 即时买赠
|
BigDecimal onsiteQtyAmt = calculator.getOnsiteQtyAmt();
|
if (onsiteQtyAmt.compareTo(BigDecimal.ZERO) > 0) {
|
result.writeOneRemark("即时买赠金额:" + formatMoney(onsiteQtyAmt));
|
cnt++;
|
}
|
|
//5. 计算结果
|
boolean success = cnt <= 1;
|
result.setSuccess(success);
|
|
if (success) {
|
result.clearRemarks();
|
}
|
}
|
|
@Override
|
public boolean check(OrderCalculator calculator, OrderEvent event, DataWriter dataWriter) {
|
List<String> remarks = new ArrayList<String>();
|
|
//1. 买赠池
|
BigDecimal rebateQty = calculator.getRebateQty();
|
if (rebateQty.compareTo(BigDecimal.ZERO) > 0) {
|
remarks.add("买赠池数量:" + rebateQty.toString());
|
}
|
|
//2. 积分池(票折)
|
BigDecimal rebateAmt = calculator.getRebateAmt();
|
if (rebateAmt.compareTo(BigDecimal.ZERO) > 0) {
|
remarks.add("积分池使用金额:" + formatMoney(rebateAmt));
|
}
|
|
//3. 即时价格折扣
|
BigDecimal onsitePriceAmt = calculator.getOnsitePriceAmt();
|
if (onsitePriceAmt.compareTo(BigDecimal.ZERO) > 0) {
|
remarks.add("即时价格折扣:" + formatMoney(onsitePriceAmt));
|
}
|
|
//4. 即时买赠
|
BigDecimal onsiteQtyAmt = calculator.getOnsiteQtyAmt();
|
if (onsiteQtyAmt.compareTo(BigDecimal.ZERO) > 0) {
|
remarks.add("即时买赠金额:" + formatMoney(onsiteQtyAmt));
|
}
|
|
//5. 计算结果
|
boolean success = remarks.size() <= 1;
|
|
if (!success) {
|
dataWriter.reportOneError("RebateAmtQtySameTimeCheck", "订单检查不通过:" + meta.getTitle());
|
|
for (String remark: remarks) {
|
dataWriter.reportOneError("RebateAmtQtySameTimeCheck", " " + remark);
|
}
|
}
|
|
if (CheckLevel.Info.equals(meta.getLevel())) {
|
success = true;
|
}
|
|
return success;
|
}
|
|
}
|