Search in sources :

Example 6 with OmcCart

use of com.paascloud.provider.model.domain.OmcCart in project paascloud-master by paascloud.

the class OmcCartServiceImpl method saveCart.

@Override
public void saveCart(OmcCart omcCart, LoginAuthDto authDto) {
    logger.info("saveCart - 保存购物车记录 omcCart={}, userId={}", omcCart, authDto.getUserId());
    Long productId = omcCart.getProductId();
    Long userId = authDto.getUserId();
    Preconditions.checkArgument(productId != null, "货品ID不能为空");
    Preconditions.checkArgument(userId != null, ErrorCodeEnum.UAC10011001.msg());
    omcCart.setUpdateInfo(authDto);
    OmcCart omcCartExist = omcCartMapper.selectByProductIdAndUserId(productId, userId);
    if (PublicUtil.isEmpty(omcCartExist)) {
        try {
            omcCartMapper.insertSelective(omcCart);
        } catch (Exception e) {
            logger.error("新增购物车, 出现异常={}", e.getMessage(), e);
        }
        return;
    }
    omcCart.setId(omcCartExist.getId());
    omcCart.setQuantity(omcCart.getQuantity() + omcCartExist.getQuantity());
    int updateResult = omcCartMapper.updateByPrimaryKeySelective(omcCart);
    if (updateResult < 1) {
        throw new OmcBizException(ErrorCodeEnum.OMC10031014, omcCartExist.getId());
    }
}
Also used : OmcCart(com.paascloud.provider.model.domain.OmcCart) OmcBizException(com.paascloud.provider.exceptions.OmcBizException) MdcBizException(com.paascloud.provider.exceptions.MdcBizException) OmcBizException(com.paascloud.provider.exceptions.OmcBizException)

Example 7 with OmcCart

use of com.paascloud.provider.model.domain.OmcCart in project paascloud-master by paascloud.

the class OmcCartServiceImpl method getOrderCartProduct.

@Override
public OrderProductVo getOrderCartProduct(Long userId) {
    Preconditions.checkArgument(userId != null, ErrorCodeEnum.UAC10011001.msg());
    OrderProductVo orderProductVo = new OrderProductVo();
    List<OmcCart> omcCartList = omcCartMapper.selectCheckedCartByUserId(userId);
    List<OmcOrderDetail> orderItemList = this.getCartOrderItem(userId, omcCartList);
    List<OrderItemVo> orderItemVoList = Lists.newArrayList();
    BigDecimal payment = new BigDecimal("0");
    for (OmcOrderDetail orderItem : orderItemList) {
        payment = BigDecimalUtil.add(payment.doubleValue(), orderItem.getTotalPrice().doubleValue());
        final OptGetUrlRequest request = new OptGetUrlRequest();
        request.setAttachmentId(Long.valueOf(orderItem.getProductImage()));
        request.setEncrypt(true);
        String fileUrl = opcOssService.getFileUrl(request);
        OrderItemVo orderItemVo = assembleOrderItemVo(orderItem);
        orderItemVo.setProductImage(fileUrl);
        orderItemVoList.add(orderItemVo);
    }
    orderProductVo.setProductTotalPrice(payment);
    orderProductVo.setOrderItemVoList(orderItemVoList);
    return orderProductVo;
}
Also used : OptGetUrlRequest(com.paascloud.provider.model.dto.oss.OptGetUrlRequest) OrderProductVo(com.paascloud.provider.model.vo.OrderProductVo) OmcOrderDetail(com.paascloud.provider.model.domain.OmcOrderDetail) OrderItemVo(com.paascloud.provider.model.vo.OrderItemVo) OmcCart(com.paascloud.provider.model.domain.OmcCart) BigDecimal(java.math.BigDecimal)

Example 8 with OmcCart

use of com.paascloud.provider.model.domain.OmcCart in project paascloud-master by paascloud.

the class OmcCartServiceImpl method selectCartListByUserId.

@Override
public List<OmcCart> selectCartListByUserId(Long userId) {
    logger.info("selectCartListByUserId - 查询购物车记录 userId={}", userId);
    Preconditions.checkArgument(userId != null, ErrorCodeEnum.UAC10011001.msg());
    OmcCart omcCart = new OmcCart();
    omcCart.setUserId(userId);
    return omcCartMapper.select(omcCart);
}
Also used : OmcCart(com.paascloud.provider.model.domain.OmcCart)

Example 9 with OmcCart

use of com.paascloud.provider.model.domain.OmcCart in project paascloud-master by paascloud.

the class OmcCartServiceImpl method updateCartList.

@Override
public int updateCartList(List<CartProductVo> cartProductVoList) {
    logger.info("updateCartList - 更新购物车集合 cartProductVoList={}", cartProductVoList);
    LoginAuthDto loginUser = new LoginAuthDto();
    loginUser.setLoginName(GlobalConstant.Sys.SUPER_MANAGER_LOGIN_NAME);
    loginUser.setUserId(1L);
    for (CartProductVo cartProductVo : cartProductVoList) {
        Integer quantity = cartProductVo.getQuantity();
        Integer productChecked = cartProductVo.getChecked();
        Long productId = cartProductVo.getProductId();
        ProductDto productDto = mdcProductService.selectById(productId);
        if (PublicUtil.isEmpty(productDto)) {
            throw new MdcBizException(ErrorCodeEnum.MDC10021004, productId);
        }
        OmcCart omcCart = new OmcCart();
        omcCart.setUserId(loginUser.getUserId());
        omcCart.setQuantity(quantity);
        omcCart.setChecked(productChecked);
        omcCart.setProductId(productId);
        omcCart.setQuantity(quantity);
        this.saveCart(omcCart, loginUser);
    }
    return 1;
}
Also used : CartProductVo(com.paascloud.provider.model.vo.CartProductVo) MdcBizException(com.paascloud.provider.exceptions.MdcBizException) LoginAuthDto(com.paascloud.base.dto.LoginAuthDto) OmcCart(com.paascloud.provider.model.domain.OmcCart) ProductDto(com.paascloud.provider.model.dto.ProductDto)

Example 10 with OmcCart

use of com.paascloud.provider.model.domain.OmcCart in project paascloud-master by paascloud.

the class OmcCartServiceImpl method getCartOrderItem.

@Override
public List<OmcOrderDetail> getCartOrderItem(Long userId, List<OmcCart> cartList) {
    List<OmcOrderDetail> orderItemList = Lists.newArrayList();
    if (CollectionUtils.isEmpty(cartList)) {
        throw new OmcBizException(ErrorCodeEnum.OMC10031001, userId);
    }
    // 校验购物车的数据,包括产品的状态和数量
    for (OmcCart cartItem : cartList) {
        OmcOrderDetail orderDetail = new OmcOrderDetail();
        ProductDto product = mdcProductService.selectById(cartItem.getProductId());
        if (MdcApiConstant.ProductStatusEnum.ON_SALE.getCode() != product.getStatus()) {
            logger.error("商品不是在线售卖状态, productId={}", product.getId());
            throw new OmcBizException(ErrorCodeEnum.MDC10021015, product.getId());
        }
        // 校验库存
        if (cartItem.getQuantity() > product.getStock()) {
            logger.error("商品库存不足, productId={}", product.getId());
            throw new OmcBizException(ErrorCodeEnum.MDC10021016, product.getId());
        }
        orderDetail.setUserId(userId);
        orderDetail.setProductId(product.getId());
        orderDetail.setProductName(product.getName());
        orderDetail.setProductImage(product.getMainImage());
        orderDetail.setCurrentUnitPrice(product.getPrice());
        orderDetail.setQuantity(cartItem.getQuantity());
        orderDetail.setTotalPrice(BigDecimalUtil.mul(product.getPrice().doubleValue(), cartItem.getQuantity()));
        orderItemList.add(orderDetail);
    }
    return orderItemList;
}
Also used : OmcOrderDetail(com.paascloud.provider.model.domain.OmcOrderDetail) OmcBizException(com.paascloud.provider.exceptions.OmcBizException) OmcCart(com.paascloud.provider.model.domain.OmcCart) ProductDto(com.paascloud.provider.model.dto.ProductDto)

Aggregations

OmcCart (com.paascloud.provider.model.domain.OmcCart)10 MdcBizException (com.paascloud.provider.exceptions.MdcBizException)4 OmcBizException (com.paascloud.provider.exceptions.OmcBizException)4 OmcOrderDetail (com.paascloud.provider.model.domain.OmcOrderDetail)3 ProductDto (com.paascloud.provider.model.dto.ProductDto)3 BigDecimal (java.math.BigDecimal)3 CartProductVo (com.paascloud.provider.model.vo.CartProductVo)2 LoginAuthDto (com.paascloud.base.dto.LoginAuthDto)1 OmcOrder (com.paascloud.provider.model.domain.OmcOrder)1 OptGetUrlRequest (com.paascloud.provider.model.dto.oss.OptGetUrlRequest)1 CartVo (com.paascloud.provider.model.vo.CartVo)1 OrderItemVo (com.paascloud.provider.model.vo.OrderItemVo)1 OrderProductVo (com.paascloud.provider.model.vo.OrderProductVo)1 Transactional (org.springframework.transaction.annotation.Transactional)1