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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
package biz.policy.price;
 
import java.util.Date;
 
import foundation.data.entity.Entity;
import foundation.json.IJSONWriter;
 
public class Line implements Cloneable{
 
    protected String typeCode;
    protected String id;
    protected String code;
    protected String name;
    protected String parentId;
    protected String customerId;
    protected String customerName;
    protected String stateCode;
    protected String stateName;
    protected Date dateFrom;
    protected Date dateTo;
    protected boolean alive;
    protected boolean discount;
    protected String remark;
    protected PricePriority priority;
    protected DomainPolicy domainPolicy;
    
    
    public Line(String typeCode) {
        this.typeCode = typeCode;
    }
    
    public void load(Entity entity) {
        ProductPriceLevel productLevel = ProductPriceLevel.parseTypeCode(typeCode);
        PolicyLevel policyLevel = PolicyLevel.parse(entity.getString("source"));
        priority = new PricePriority(policyLevel, productLevel);
        
        if (policyLevel == PolicyLevel.Record) {
            id = entity.getString("md_prod_price_detail__id");
            code = entity.getString("md_prod_price_detail__record_no");
            name = entity.getString("md_prod_price_detail__record_name");
            customerId = entity.getString("md_prod_price_detail__account_id");
            customerName = entity.getString("md_prod_price_detail__account_name");
            remark = entity.getString("md_prod_price_detail__remark");
            stateCode = entity.getString("md_prod_price_detail__state_code");
            stateName = entity.getString("md_prod_price_detail__state_name");
            dateFrom = entity.getDate("md_prod_price_detail__date_from", null);
            dateTo = entity.getDate("md_prod_price_detail__date_to", null);
            discount = entity.getBoolean("md_prod_price_detail__is_discount", false);
        }
        else {
            id = entity.getString("id");
            code = entity.getString("record_no");
            name = entity.getString("record_name");
            customerId = entity.getString("account_id");
            customerName = entity.getString("account_name");
            remark = entity.getString("remark");
            stateCode = entity.getString("state_code");
            stateName = entity.getString("state_name");
            dateFrom = entity.getDate("date_from", null);
            dateTo = entity.getDate("date_to", null);
            discount = entity.getBoolean("is_discount", false);
        }
 
        calculateActive();
    }
    
    public void load(Line line) {
        id = line.getId();
        parentId = line.getParentId();
        code = line.getCode();
        name = line.getName();
        stateCode = line.getStateCode();
        stateName =  line.getStateName();
        dateFrom =  line.getDateFrom();
        dateTo = line.getDateTo();
        remark =  line.getRemark();
        
        ProductPriceLevel productLevel = ProductPriceLevel.parseTypeCode(typeCode);
        PolicyLevel policyLevel = PolicyLevel.Standard;
        priority = new PricePriority(policyLevel, productLevel);
 
        calculateActive();
    }
    
    protected void calculateActive() {
        if (!"Open".equalsIgnoreCase(stateCode)) {
            alive = false;
            remark = stateName;
            return;
        }
        
        if (dateFrom == null) {
            alive = false;
            remark = "未生效";
            return;
        }
        
        if (dateFrom.compareTo(PolicyBucket.Now) < 0) {
            if (dateTo == null) {
                alive = true;
                remark = "生效中";
            }
            else {
                alive = dateTo.compareTo(PolicyBucket.Now) >= 0;
                
                if (alive) {
                    remark = "生效中";
                }
                else {
                    remark = "已失效";
                }
            }
        }
        else {
            alive = false;
            remark = "未生效";
        }
    }
 
    public int getPriorityNo() {
        if (priority == null) {
            return 0;
        }
        
        return priority.getLevelNo();
    }
    
    public String getId() {
        return id;
    }
 
    public String getCode() {
        return code;
    }
 
    public String getName() {
        return name;
    }
 
    public String getParentId() {
        return parentId;
    }
 
    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 String getCustomerId() {
        return customerId;
    }
 
    public boolean isAlive() {
        return alive;
    }
 
    public DomainPolicy getDomainPolicy() {
        return domainPolicy;
    }
 
    public void setDomainPolicy(DomainPolicy domainPolicy) {
        this.domainPolicy = domainPolicy;
    }
    
    public String getTypeCode() {
        return typeCode;
    }
    
    public void writeJSONBody(IJSONWriter writer) {
        writer.write("type_code", typeCode);
        writer.write("customer_id", customerId);
        writer.write("customer_name", customerName);
        writer.write("id", id);
        writer.write("parent_id", parentId);
        writer.write("code", code);
        writer.write("name", name);
        writer.write("date_from", dateFrom);
        writer.write("date_to", dateTo);
        writer.write("is_active", alive);
        writer.write("is_discount", discount);
        writer.write("remark", remark);
    }
}