Search in sources :

Example 1 with CartProduct

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

the class CartServiceImpl method addCart.

@Override
public int addCart(long userId, long itemId, int num) {
    // hash: "key:用户id" field:"商品id" value:"商品信息"
    Boolean hexists = jedisClient.hexists(CART_PRE + ":" + userId, itemId + "");
    // 如果存在数量相加
    if (hexists) {
        String json = jedisClient.hget(CART_PRE + ":" + userId, itemId + "");
        if (json != null) {
            CartProduct cartProduct = new Gson().fromJson(json, CartProduct.class);
            cartProduct.setProductNum(cartProduct.getProductNum() + num);
            jedisClient.hset(CART_PRE + ":" + userId, itemId + "", new Gson().toJson(cartProduct));
        } else {
            return 0;
        }
        return 1;
    }
    // 如果不存在,根据商品id取商品信息
    TbItem item = itemMapper.selectByPrimaryKey(itemId);
    if (item == null) {
        return 0;
    }
    CartProduct cartProduct = DtoUtil.TbItem2CartProduct(item);
    cartProduct.setProductNum((long) num);
    cartProduct.setChecked("1");
    jedisClient.hset(CART_PRE + ":" + userId, itemId + "", new Gson().toJson(cartProduct));
    return 1;
}
Also used : CartProduct(cn.exrick.manager.dto.front.CartProduct) Gson(com.google.gson.Gson) TbItem(cn.exrick.manager.pojo.TbItem)

Example 2 with CartProduct

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

the class CartServiceImpl method updateCartNum.

@Override
public int updateCartNum(long userId, long itemId, int num, String checked) {
    String json = jedisClient.hget(CART_PRE + ":" + userId, itemId + "");
    if (json == null) {
        return 0;
    }
    CartProduct cartProduct = new Gson().fromJson(json, CartProduct.class);
    cartProduct.setProductNum((long) num);
    cartProduct.setChecked(checked);
    jedisClient.hset(CART_PRE + ":" + userId, itemId + "", new Gson().toJson(cartProduct));
    return 1;
}
Also used : CartProduct(cn.exrick.manager.dto.front.CartProduct) Gson(com.google.gson.Gson)

Example 3 with CartProduct

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

the class CartServiceImpl method checkAll.

@Override
public int checkAll(long userId, String checked) {
    List<String> jsonList = jedisClient.hvals(CART_PRE + ":" + userId);
    for (String json : jsonList) {
        CartProduct cartProduct = new Gson().fromJson(json, CartProduct.class);
        if ("true".equals(checked)) {
            cartProduct.setChecked("1");
        } else if ("false".equals(checked)) {
            cartProduct.setChecked("0");
        } else {
            return 0;
        }
        jedisClient.hset(CART_PRE + ":" + userId, cartProduct.getProductId() + "", new Gson().toJson(cartProduct));
    }
    return 1;
}
Also used : CartProduct(cn.exrick.manager.dto.front.CartProduct) Gson(com.google.gson.Gson)

Example 4 with CartProduct

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

the class CartServiceImpl method getCartList.

@Override
public List<CartProduct> getCartList(long userId) {
    List<String> jsonList = jedisClient.hvals(CART_PRE + ":" + userId);
    List<CartProduct> list = new ArrayList<>();
    for (String json : jsonList) {
        CartProduct cartProduct = new Gson().fromJson(json, CartProduct.class);
        list.add(cartProduct);
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) CartProduct(cn.exrick.manager.dto.front.CartProduct) Gson(com.google.gson.Gson)

Example 5 with CartProduct

use of cn.exrick.manager.dto.front.CartProduct 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)

Aggregations

CartProduct (cn.exrick.manager.dto.front.CartProduct)9 Gson (com.google.gson.Gson)5 ArrayList (java.util.ArrayList)3 XmallException (cn.exrick.common.exception.XmallException)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 TbItem (cn.exrick.manager.pojo.TbItem)1 PageInfo (com.github.pagehelper.PageInfo)1 Date (java.util.Date)1