P15GEN2\59518
2025-10-10 9f6890646993d16260d4201d613c092132856127
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package biz.policy.price;
 
import java.math.BigDecimal;
import java.util.Date;
 
import foundation.data.entity.Entity;
import foundation.util.MapList;
 
public class PackagePolicy {
    private String id;
    private String code;
    private String name;
    private String stateCode;
    private String stateName;
    private Date dateFrom;
    private Date dateTo;
    private String remark;
    private int packageQty;
    private int maxQty;
    private BigDecimal discountRate;
    private MapList<String, PackageLine> lines;
 
    public void load(Entity entity) {
        // 政策加载
        id = entity.getString("id");
        code = entity.getString("record_no");
        name = entity.getString("record_name");
        packageQty = entity.getInteger("emption_qty", 0);
        discountRate = entity.getBigDecimal("discount_rate", BigDecimal.ONE);
        stateCode = entity.getString("state_code");
        stateName = entity.getString("state_name");
        dateFrom = entity.getDate("date_from", null);
        dateTo = entity.getDate("date_to", null);
        remark = entity.getString("remark");
    }
    
    public void loadOnePackageLine(Entity entity) {
        PackageLine packageLine = new PackageLine(this);
        packageLine.load(entity);
        
        lines.add(packageLine.getId(), packageLine);
    }
 
    public PackagePolicy(String id) {
        this.id = id;
        this.lines = new MapList<String, PackageLine>();
    }
    
    public PackageLine loadOnePackageLine(String lineId, int qty) {
        PackageLine packageLine = lines.get(lineId);
        
        if (packageLine == null) {
            packageLine = new PackageLine(lineId, this);
        }
        
        packageLine.addQty(qty);
        lines.add(packageLine.getId(), packageLine);
        return packageLine;
    }
 
    public void calculateQty() {
        PolicyBucket policyBucket = PolicyBucket.getInstance();
        PackagePolicy policy = policyBucket.getPackagePolicy(id);
        
        if (policy == null) {
            stateCode = "Closed";
            stateName = "失效";
            return ;
        }
        
        MapList<String, PackageLine> policyLines = policy.getLines();
        PackageLine line;
        
        if (policyLines != null) {
            packageQty = 999999;
        }
        
        for (PackageLine policyLine : policyLines){
            line = lines.get(policyLine.getId());
            
            if (line == null) {
                packageQty = 0;
                continue;
            }
            
            int actuallyQty = line.getQty();
            packageQty = Math.min(actuallyQty/policyLine.getQty(), packageQty);
            maxQty = Math.max(actuallyQty/policyLine.getQty(), maxQty);
        }
    }
    
    public String getId() {
        return id;
    }
    
    public String getCode() {
        return code;
    }
    
    public String getName() {
        return name;
    }
 
    public int getPackageQty() {
        return packageQty;
    }
 
    public BigDecimal getDiscountRate() {
        return discountRate;
    }
 
    public BigDecimal getOnePrice(BigDecimal price) {
        return price.multiply(discountRate);
    }
 
    public MapList<String, PackageLine> getLines() {
        return lines;
    }
 
    public String getStateCode() {
        return stateCode;
    }
 
    public String getStateName() {
        return stateName;
    }
 
    public Date getDateFrom() {
        return dateFrom;
    }
 
    public Date getDateTo() {
        return dateTo;
    }
 
    public String getRemark() {
        return remark;
    }
 
    public int getMaxQty() {
        return maxQty;
    }
}