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);
|
}
|
}
|