Search in sources :

Example 6 with OmcBizException

use of com.paascloud.provider.exceptions.OmcBizException 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)

Example 7 with OmcBizException

use of com.paascloud.provider.exceptions.OmcBizException 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 8 with OmcBizException

use of com.paascloud.provider.exceptions.OmcBizException in project paascloud-master by paascloud.

the class OmcOrderServiceImpl method createOrderDoc.

@Override
@Transactional(rollbackFor = Exception.class)
public OrderVo createOrderDoc(LoginAuthDto loginAuthDto, Long shippingId) {
    Long userId = loginAuthDto.getUserId();
    // 从购物车中获取数据
    List<OmcCart> cartList = omcCartMapper.selectCheckedCartByUserId(userId);
    if (CollectionUtils.isEmpty(cartList)) {
        throw new OmcBizException(ErrorCodeEnum.OMC10031001, userId);
    }
    // 计算这个订单的总价
    List<OmcOrderDetail> omcOrderDetailList = omcCartService.getCartOrderItem(userId, cartList);
    if (CollectionUtils.isEmpty(omcOrderDetailList)) {
        throw new OmcBizException(ErrorCodeEnum.OMC10031001, userId);
    }
    BigDecimal payment = this.getOrderTotalPrice(omcOrderDetailList);
    // 生成订单
    OmcOrder order = this.assembleOrder(userId, shippingId, payment);
    if (order == null) {
        logger.error("生成订单失败, userId={}, shippingId={}, payment={}", userId, shippingId, payment);
        throw new OmcBizException(ErrorCodeEnum.OMC10031002);
    }
    order.setUpdateInfo(loginAuthDto);
    for (OmcOrderDetail orderDetail : omcOrderDetailList) {
        orderDetail.setUpdateInfo(loginAuthDto);
        orderDetail.setOrderNo(order.getOrderNo());
        orderDetail.setId(super.generateId());
        orderDetail.setUpdateInfo(loginAuthDto);
    }
    // mybatis 批量插入
    omcOrderDetailService.batchInsertOrderDetail(omcOrderDetailList);
    // 生成成功,我们要减少我们产品的库存
    this.reduceProductStock(omcOrderDetailList);
    // 清空一下购物车
    this.cleanCart(cartList);
    return assembleOrderVo(order, omcOrderDetailList);
}
Also used : OmcOrderDetail(com.paascloud.provider.model.domain.OmcOrderDetail) OmcCart(com.paascloud.provider.model.domain.OmcCart) OmcBizException(com.paascloud.provider.exceptions.OmcBizException) OmcOrder(com.paascloud.provider.model.domain.OmcOrder) BigDecimal(java.math.BigDecimal) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with OmcBizException

use of com.paascloud.provider.exceptions.OmcBizException in project paascloud-master by paascloud.

the class OmcOrderServiceImpl method queryOrderDtoByUserIdAndOrderNo.

@Override
public OrderDto queryOrderDtoByUserIdAndOrderNo(Long userId, String orderNo) {
    OmcOrder omcOrder = this.queryByUserIdAndOrderNo(userId, orderNo);
    if (omcOrder == null) {
        throw new OmcBizException(ErrorCodeEnum.OMC10031005, orderNo);
    }
    ModelMapper modelMapper = new ModelMapper();
    return modelMapper.map(omcOrder, OrderDto.class);
}
Also used : OmcBizException(com.paascloud.provider.exceptions.OmcBizException) OmcOrder(com.paascloud.provider.model.domain.OmcOrder) ModelMapper(org.modelmapper.ModelMapper)

Example 10 with OmcBizException

use of com.paascloud.provider.exceptions.OmcBizException in project paascloud-master by paascloud.

the class OmcOrderServiceImpl method cleanCart.

private void cleanCart(List<OmcCart> cartList) {
    List<Long> idList = Lists.newArrayList();
    for (OmcCart cart : cartList) {
        idList.add(cart.getId());
    }
    int deleteCount = omcCartMapper.batchDeleteCart(idList);
    if (deleteCount < idList.size()) {
        throw new OmcBizException(ErrorCodeEnum.OMC10031006);
    }
}
Also used : OmcCart(com.paascloud.provider.model.domain.OmcCart) OmcBizException(com.paascloud.provider.exceptions.OmcBizException)

Aggregations

OmcBizException (com.paascloud.provider.exceptions.OmcBizException)13 OmcOrder (com.paascloud.provider.model.domain.OmcOrder)7 OmcOrderDetail (com.paascloud.provider.model.domain.OmcOrderDetail)5 OmcCart (com.paascloud.provider.model.domain.OmcCart)4 ModelMapper (org.modelmapper.ModelMapper)3 OmcShipping (com.paascloud.provider.model.domain.OmcShipping)2 OrderDto (com.paascloud.provider.model.dto.OrderDto)2 Transactional (org.springframework.transaction.annotation.Transactional)2 AlipayTradePrecreateResponse (com.alipay.api.response.AlipayTradePrecreateResponse)1 ExtendParams (com.alipay.demo.trade.model.ExtendParams)1 GoodsDetail (com.alipay.demo.trade.model.GoodsDetail)1 AlipayTradePrecreateRequestBuilder (com.alipay.demo.trade.model.builder.AlipayTradePrecreateRequestBuilder)1 AlipayF2FPrecreateResult (com.alipay.demo.trade.model.result.AlipayF2FPrecreateResult)1 MdcBizException (com.paascloud.provider.exceptions.MdcBizException)1 PtcPayInfo (com.paascloud.provider.model.domain.PtcPayInfo)1 ProductDto (com.paascloud.provider.model.dto.ProductDto)1 OptUploadFileByteInfoReqDto (com.paascloud.provider.model.dto.attachment.OptUploadFileByteInfoReqDto)1 OptGetUrlRequest (com.paascloud.provider.model.dto.oss.OptGetUrlRequest)1 OptUploadFileReqDto (com.paascloud.provider.model.dto.oss.OptUploadFileReqDto)1 OptUploadFileRespDto (com.paascloud.provider.model.dto.oss.OptUploadFileRespDto)1