Search in sources :

Example 1 with PageOrder

use of cn.exrick.manager.dto.front.PageOrder in project xmall by Exrick.

the class OrderServiceImpl method getOrderList.

@Override
public PageOrder getOrderList(Long userId, int page, int size) {
    // 分页
    if (page <= 0) {
        page = 1;
    }
    PageHelper.startPage(page, size);
    PageOrder pageOrder = new PageOrder();
    List<Order> list = new ArrayList<>();
    TbOrderExample example = new TbOrderExample();
    TbOrderExample.Criteria criteria = example.createCriteria();
    criteria.andUserIdEqualTo(userId);
    example.setOrderByClause("create_time DESC");
    List<TbOrder> listOrder = tbOrderMapper.selectByExample(example);
    for (TbOrder tbOrder : listOrder) {
        judgeOrder(tbOrder);
        Order order = new Order();
        // orderId
        order.setOrderId(Long.valueOf(tbOrder.getOrderId()));
        // orderStatus
        order.setOrderStatus(String.valueOf(tbOrder.getStatus()));
        // createDate
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        String date = formatter.format(tbOrder.getCreateTime());
        order.setCreateDate(date);
        // address
        TbOrderShipping tbOrderShipping = tbOrderShippingMapper.selectByPrimaryKey(tbOrder.getOrderId());
        TbAddress address = new TbAddress();
        address.setUserName(tbOrderShipping.getReceiverName());
        address.setStreetName(tbOrderShipping.getReceiverAddress());
        address.setTel(tbOrderShipping.getReceiverPhone());
        order.setAddressInfo(address);
        // orderTotal
        if (tbOrder.getPayment() == null) {
            order.setOrderTotal(new BigDecimal(0));
        } else {
            order.setOrderTotal(tbOrder.getPayment());
        }
        // goodsList
        TbOrderItemExample exampleItem = new TbOrderItemExample();
        TbOrderItemExample.Criteria criteriaItem = exampleItem.createCriteria();
        criteriaItem.andOrderIdEqualTo(tbOrder.getOrderId());
        List<TbOrderItem> listItem = tbOrderItemMapper.selectByExample(exampleItem);
        List<CartProduct> listProduct = new ArrayList<>();
        for (TbOrderItem tbOrderItem : listItem) {
            CartProduct cartProduct = DtoUtil.TbOrderItem2CartProduct(tbOrderItem);
            listProduct.add(cartProduct);
        }
        order.setGoodsList(listProduct);
        list.add(order);
    }
    PageInfo<Order> pageInfo = new PageInfo<>(list);
    pageOrder.setTotal(getMemberOrderCount(userId));
    pageOrder.setData(list);
    return pageOrder;
}
Also used : Order(cn.exrick.manager.dto.front.Order) PageOrder(cn.exrick.manager.dto.front.PageOrder) PageOrder(cn.exrick.manager.dto.front.PageOrder) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) PageInfo(com.github.pagehelper.PageInfo) CartProduct(cn.exrick.manager.dto.front.CartProduct) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

CartProduct (cn.exrick.manager.dto.front.CartProduct)1 Order (cn.exrick.manager.dto.front.Order)1 PageOrder (cn.exrick.manager.dto.front.PageOrder)1 PageInfo (com.github.pagehelper.PageInfo)1 BigDecimal (java.math.BigDecimal)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1