P15GEN2\59518
2024-05-29 d4210c7c4b04abde20037ea8aa0f54ef8a2649aa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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;
    }
 
}