package biz.policy.price;
|
|
import java.math.BigDecimal;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
import biz.policy.price.outline.DomainOnsiteResult;
|
import biz.policy.price.outline.DomainPriceResult;
|
import foundation.data.entity.Entity;
|
import foundation.util.Util;
|
|
public class SKUPolicy {
|
|
private String id;
|
private String spec;
|
private ProductPolicy product;
|
private DomainPolicyBucket domainBucket;
|
private PriceLine basePrice;
|
|
public SKUPolicy(ProductPolicy product) {
|
this.product = product;
|
this.domainBucket = new DomainPolicyBucket();
|
}
|
|
public void load(String id, Entity entity) {
|
this.id = id;
|
spec = entity.getString("spec");
|
}
|
|
public PriceLine loadOneStandardPriceLine(Entity entity) {
|
PriceLine priceLine = new PriceLine(PriceLine.Type_Standard);
|
priceLine.load(entity);
|
|
domainBucket.loadOnePriceListLine(priceLine.getCustomerId(), priceLine);
|
basePrice = priceLine;
|
return priceLine;
|
}
|
|
public PriceLine loadOnePriceListLine(Entity entity) {
|
PriceLine priceLine = new PriceLine(PriceLine.Type_Customer_SKU);
|
priceLine.load(entity);
|
|
domainBucket.loadOnePriceListLine(priceLine.getCustomerId(), priceLine);
|
return priceLine;
|
}
|
|
public OnsiteLine loadOneQtyOnsiteDiscount(Entity entity) {
|
OnsiteLine onsiteLine = new OnsiteLine(OnsiteLine.Type_SKU_Qty);
|
onsiteLine.load(entity);
|
|
domainBucket.loadOneQtyOnsiteDiscount(onsiteLine.getCustomerId(), onsiteLine);
|
return onsiteLine;
|
}
|
|
public OnsiteLine loadOnePriceOnsiteDiscount(Entity entity) {
|
OnsiteLine onsiteLine = new OnsiteLine(OnsiteLine.Type_SKU_Price);
|
onsiteLine.load(entity);
|
|
domainBucket.loadOnePriceOnsiteDiscount(onsiteLine.getCustomerId(), onsiteLine);
|
return onsiteLine;
|
}
|
|
public OnsiteLine loadOnePricePackageDiscount(Entity entity) {
|
OnsiteLine policyLine = new OnsiteLine(PriceLine.Type_Package_SKU);
|
policyLine.load(entity);
|
|
domainBucket.loadOnePriceOnsiteDiscount(policyLine.getCustomerId(), policyLine);
|
return policyLine;
|
}
|
|
public void removeOnePriceListLine(Entity entity) {
|
String customerId = entity.getString("account_id");
|
String policyId = entity.getId();
|
domainBucket.removeOnePriceListLine(customerId, policyId);
|
}
|
|
public void removeOneOnsiteDiscount(Entity entity) {
|
String customerId = entity.getString("account_id");
|
String policyId = entity.getId();
|
domainBucket.removeOneOnsiteDiscount(customerId, policyId);
|
}
|
|
public BigDecimal getOnePrice(String customerId, String skuId) {
|
BigDecimal result = null;
|
PriceSelector selector = new PriceSelector();
|
|
//1. 标准价格
|
selector.loadOne(basePrice);
|
|
//2. SKU客户价格
|
DomainPolicy domainPolicy = domainBucket.get(customerId);
|
|
if (domainPolicy != null) {
|
domainPolicy.getOnePrice(selector);
|
}
|
|
//3. 添加Product、ProductLine客户价格
|
product.getOnePrice(customerId, selector);
|
|
//return
|
result = selector.getLowerPrice();
|
|
if (result == null) {
|
result = BigDecimal.ONE;
|
}
|
else {
|
result = new BigDecimal(result.toString());
|
}
|
|
return result;
|
}
|
|
public void getPriceList(String customerId, PriceResult result) throws Exception {
|
//1. 添加基础价格
|
result.setBasePrice(basePrice);
|
|
//2. 添加SKU客户价格
|
DomainPolicy domainPolicy = domainBucket.get(customerId);
|
|
if (domainPolicy != null) {
|
result.addPriceList(domainPolicy.getPriceList());
|
}
|
|
//3. 添加Product、ProductLine客户价格
|
product.getPrice(customerId, result);
|
|
//4. 添加Package[客户]价格
|
if (Util.isEmpty(result.getSelectId())) {
|
return ;
|
}
|
|
List<OnsiteLine> selected = getSelectedOnsite(customerId, result.getSelectId());
|
result.setSelectedLine(selected);
|
|
selected = getSelectedOnsite(null, result.getSelectId());
|
result.setSelectedLine(selected);
|
|
}
|
|
public void getOnsiteDiscounts(String customerId, OnsitesResult result) {
|
DomainPolicy domainPolicy = domainBucket.get(customerId);
|
|
if (domainPolicy != null) {
|
result.addOnsiteDiscounts(domainPolicy.getOnsiteList());
|
}
|
}
|
|
public String getId() {
|
return id;
|
}
|
|
public String getSpec() {
|
return spec;
|
}
|
|
public void getPriceList(DomainPriceResult result) {
|
domainBucket.getPriceList(result);
|
}
|
|
public void getOnsiteList(DomainOnsiteResult result) {
|
domainBucket.getOnsiteList(result);
|
}
|
|
public List<OnsiteLine> getSelectedOnsite(String customerId, String selectId) {
|
List<OnsiteLine> lines = new ArrayList<OnsiteLine>();
|
DomainPolicy domainPolicy = domainBucket.get(customerId);
|
OnsiteLine selected = domainPolicy.getOneOnsite(selectId);
|
|
if (selected != null) {
|
lines.add(selected);
|
}
|
|
List<OnsiteLine> selectedLines = product.getSelectedOnsite(customerId, selectId);
|
if (selectedLines != null) {
|
lines.addAll(selectedLines);
|
}
|
|
return lines;
|
}
|
|
}
|