package policy.price;
|
|
import java.util.Date;
|
|
import foundation.data.entity.Entity;
|
import foundation.json.IJSONWriter;
|
|
public class Line {
|
|
protected String typeCode;
|
protected String id;
|
protected String code;
|
protected String name;
|
protected String customerId;
|
protected String customerName;
|
protected String stateCode;
|
protected String stateName;
|
protected Date dateFrom;
|
protected Date dateTo;
|
protected boolean alive;
|
protected String remark;
|
protected PricePriority priority;
|
protected DomainPolicy domainPolicy;
|
|
|
public Line(String typeCode) {
|
this.typeCode = typeCode;
|
}
|
|
public void load(Entity entity) {
|
id = entity.getString("id");
|
code = entity.getString("record_no");
|
name = entity.getString("record_name");
|
customerId = entity.getString("account_id");
|
customerName = entity.getString("account_name");
|
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");
|
|
ProductPriceLevel productLevel = ProductPriceLevel.parseTypeCode(typeCode);
|
PolicyLevel policyLevel = PolicyLevel.parse(entity.getString("source"));
|
priority = new PricePriority(policyLevel, productLevel);
|
|
calculateActive();
|
}
|
|
private 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 getCustomerId() {
|
return customerId;
|
}
|
|
public boolean isAlive() {
|
return alive;
|
}
|
|
public DomainPolicy getDomainPolicy() {
|
return domainPolicy;
|
}
|
|
public void setDomainPolicy(DomainPolicy domainPolicy) {
|
this.domainPolicy = domainPolicy;
|
}
|
|
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("code", code);
|
writer.write("name", name);
|
writer.write("date_from", dateFrom);
|
writer.write("date_to", dateTo);
|
writer.write("is_active", alive);
|
writer.write("remark", remark);
|
}
|
}
|