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;
}
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());
}
}
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);
}
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);
}
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);
}
}
Aggregations