Search in sources :

Example 1 with Order

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

the class OrderServiceImpl method getOrder.

@Override
public Order getOrder(Long orderId) {
    Order order = new Order();
    TbOrder tbOrder = tbOrderMapper.selectByPrimaryKey(String.valueOf(orderId));
    if (tbOrder == null) {
        throw new XmallException("通过id获取订单失败");
    }
    String validTime = judgeOrder(tbOrder);
    if (validTime != null) {
        order.setFinishDate(validTime);
    }
    // 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 createDate = formatter.format(tbOrder.getCreateTime());
    order.setCreateDate(createDate);
    // closeDate
    if (tbOrder.getCloseTime() != null) {
        String closeDate = formatter.format(tbOrder.getCloseTime());
        order.setCloseDate(closeDate);
    }
    // finishDate
    if (tbOrder.getEndTime() != null && tbOrder.getStatus() == 4) {
        String finishDate = formatter.format(tbOrder.getEndTime());
        order.setFinishDate(finishDate);
    }
    // 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);
    return order;
}
Also used : Order(cn.exrick.manager.dto.front.Order) PageOrder(cn.exrick.manager.dto.front.PageOrder) ArrayList(java.util.ArrayList) XmallException(cn.exrick.common.exception.XmallException) BigDecimal(java.math.BigDecimal) CartProduct(cn.exrick.manager.dto.front.CartProduct) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with Order

use of cn.exrick.manager.dto.front.Order 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)2 Order (cn.exrick.manager.dto.front.Order)2 PageOrder (cn.exrick.manager.dto.front.PageOrder)2 BigDecimal (java.math.BigDecimal)2 SimpleDateFormat (java.text.SimpleDateFormat)2 ArrayList (java.util.ArrayList)2 XmallException (cn.exrick.common.exception.XmallException)1 PageInfo (com.github.pagehelper.PageInfo)1