package policy.price.outline; import java.util.ArrayList; import java.util.List; import foundation.dao.preload.Bucket; import foundation.json.IJSONProvider; import foundation.json.IJSONWriter; import policy.price.PriceLine; public class DomainPriceResult implements IJSONProvider { private Bucket nationalPriceList; private List customerPriceList; public DomainPriceResult() { customerPriceList = new ArrayList(); } public void setNationalPriceList(Bucket priceList) { nationalPriceList = priceList; } public void addCustomerPriceList(String id, Bucket priceList) { CustomerPriceResult priceResult = new CustomerPriceResult(id, priceList); customerPriceList.add(priceResult); } @Override public void writeJSON(IJSONWriter writer) { //1. 通过价格/政策 writer.beginArray("national"); for (PriceLine priceLine: nationalPriceList) { priceLine.writeJSON(writer); } writer.endArray(); //2. 客户价格/政策 writer.beginArray("customer"); for (CustomerPriceResult priceList: customerPriceList) { writer.beginObject(); writer.write("customer_id", priceList.getCustomerId()); for (PriceLine priceLine: priceList) { priceLine.writeJSON(writer); } writer.endObject(); } writer.endArray(); } }