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