/** * 将消费信息初始化到对应的购买项中 * * @param items 订单购买项 * @param orderTickets 实际消费项 */ private void initOrderConsumptionInfo(List<OrderItem> items, List<OrderTickets> orderTickets) { for (OrderItem item : items) { // 没有消费记录就设为0 item.setConsumptionQuantity(0); item.setConsumptionSubtotal(0.0); item.setConsumptionSavings(0.0); if (orderTickets == null || orderTickets.isEmpty()) { continue; } for (OrderTickets ticket : orderTickets) { if (!StringUtils.equals(item.getMid(), ticket.getMid())) { continue; } // 初始化消费信息 ticket.setMid(item.getMid()); ticket.setName(item.getName()); ticket.setSellingPrice(item.getSellingPrice()); // 初始化购买信息 Integer q = ticket.getStatflag(); BigDecimal quantity = new BigDecimal(q + ""); BigDecimal price = new BigDecimal(item.getSellingPrice() + ""); price = price.setScale(2, RoundingMode.HALF_UP); // 精确到小数点2位,四舍五入 BigDecimal subtotal = price.multiply(quantity); item.setConsumptionQuantity(q); item.setConsumptionSubtotal(subtotal.doubleValue()); item.setConsumptionSavings(null); break; } } }
/** * @param orderNumber * @return 得到购买的活动包含的商品 */ private List<OrderItem> getOrderItemByOrderNumber(String orderNumber) { List<OrderItem> items = orderManageMapper.getOrderItemByOrderNumber(orderNumber); Map<String, String> query = new HashMap<String, String>(); query.put("orderNumber", orderNumber); for (OrderItem item : items) { String mid = item.getMid(); // 商品编号第二位为活动编码 if (StringUtils.indexOf(mid, CategoryId.ACTIVITY.getAbbreviation()) == 1) { String id = item.getId(); query.put("aid", id); List<OrderItem> containItems = orderManageMapper.getOrderItemByActivityItemId(query); item.setContainItems(containItems); } } return items; }