在我play framework
應用程序的管理頁面,我需要列出Product
的兩個日期之間的銷售,顯示Product name
,quantity
出售,總price
。我已經仿照這個信息在一個CustomerOrder
model.Still我有一些疑問,我應該使用哪些數據結構來保存上述數據。從CustomerOrder提取數據顯示爲總銷售額數據
管理員應該能夠列出一個表格式的銷售數據如下
Product Name | quantity | total amount received
===================================================
flwr vase#12 | 13 | 1250
---------------------------------------------------
lampshade#3 | 11 | 110
-----------------------------------------
我還以爲寫在Admin
類中的方法,得到兩個日期之間的CustomerOrder
S的,並被困在從CustomerOrder
中提取信息。 每個產品名稱都應該是表格的主鍵,我猜是。因此,我可以創建一個產品名稱爲key的映射。然後應該是什麼值?當我迭代每個CustomerOrder
時,我應該增加每個銷售的產品和收到的總金額應該更新。
總金額是order.cartitem.qty*order.cartitem.product.price + order.tax+ order.shipping
..我認爲這使得循環有點複雜...有人可以告訴我該如何做到這一點?
public void allSalesData(Date start,Date end){
List<CustomerOrder> orders = CustomerOrder.find("select o from CustomerOrder o where o.orderDate between :startdate and :enddate").bind("startdate",start).bind("enddate",end).fetch();
//now how to extract? should I use a map ?
}
import play.db.jpa.Model;
class CustomerOrder extends Model{
...
public Customer customer;
public Date orderDate;
public Set<OrderItem> orderItems;
public BigDecimal tax;
public BigDecimal shipping;
...
}
class OrderItem extends Model {
public Product product;
public int quantity;
}
class Product extends Model{
public String name;
public BigDecimal price;
}
你想要準確顯示什麼?你需要列出每個項目的數量,價格和總數? – emt14
我需要列出每個產品,銷售數量和從中賺得的總金額 –
使用稅和運費查詢更新的答案 – emt14