use of com.paascloud.provider.exceptions.MdcBizException in project paascloud-master by paascloud.
the class MdcProductServiceImpl method getProductDetail.
@Override
public ProductDetailVo getProductDetail(Long productId) {
logger.info("获取商品明细信息, productId={}", productId);
Preconditions.checkArgument(productId != null, ErrorCodeEnum.MDC10021021.msg());
MdcProduct product = mdcProductMapper.selectByPrimaryKey(productId);
if (product == null) {
throw new MdcBizException(ErrorCodeEnum.MDC10021017, productId);
}
if (product.getStatus() != MallConstant.ProductStatusEnum.ON_SALE.getCode()) {
throw new MdcBizException(ErrorCodeEnum.MDC10021017, productId);
}
return assembleProductDetailVo(product);
}
use of com.paascloud.provider.exceptions.MdcBizException in project paascloud-master by paascloud.
the class OmcCartServiceImpl method updateCart.
@Override
public int updateCart(Long userId, Long productId, int count) {
logger.info("updateCart - 更新货品数量 userId={}, productId={}, count={}", userId, productId, count);
Preconditions.checkArgument(userId != null, ErrorCodeEnum.UAC10011001.msg());
Preconditions.checkArgument(productId != null, ErrorCodeEnum.MDC10021021.msg());
int resultInt;
OmcCart cart = this.getCartByUserIdAndProductId(userId, productId);
if (cart == null) {
logger.error("找不到商品信息, userId={}, productId={}", userId, productId);
throw new MdcBizException(ErrorCodeEnum.MDC10021004, productId);
}
if (count == 0) {
List<String> productList = Lists.newArrayList();
productList.add(productId.toString());
resultInt = omcCartMapper.deleteByUserIdProductIds(userId, productList);
} else {
cart.setQuantity(count);
resultInt = omcCartMapper.updateByPrimaryKeySelective(cart);
}
return resultInt;
}
use of com.paascloud.provider.exceptions.MdcBizException in project paascloud-master by paascloud.
the class OmcCartServiceImpl method getCarVo.
@Override
public CartVo getCarVo(Long userId) {
logger.info("getCarVo - 获取购物车列表 -- userId={}", userId);
CartVo cartVo = new CartVo();
List<OmcCart> cartList = this.selectCartListByUserId(userId);
List<CartProductVo> cartProductVoList = Lists.newArrayList();
BigDecimal cartTotalPrice = new BigDecimal("0");
if (PublicUtil.isNotEmpty(cartList)) {
for (OmcCart cartItem : cartList) {
CartProductVo cartProductVo = new CartProductVo();
cartProductVo.setId(cartItem.getId());
cartProductVo.setUserId(userId);
cartProductVo.setProductId(cartItem.getProductId());
ProductDto product = mdcProductService.selectById(cartItem.getProductId());
if (product == null) {
throw new MdcBizException(ErrorCodeEnum.MDC10021004, cartItem.getProductId());
}
cartProductVo.setProductMainImage(product.getMainImage());
cartProductVo.setProductName(product.getName());
cartProductVo.setProductSubtitle(product.getSubtitle());
cartProductVo.setProductStatus(product.getStatus());
cartProductVo.setProductPrice(product.getPrice());
cartProductVo.setProductStock(product.getStock());
// 判断库存
int buyLimitCount;
if (product.getStock() >= cartItem.getQuantity()) {
// 库存充足的时候
buyLimitCount = cartItem.getQuantity();
cartProductVo.setLimitQuantity(OmcApiConstant.Cart.LIMIT_NUM_SUCCESS);
} else {
buyLimitCount = product.getStock();
cartProductVo.setLimitQuantity(OmcApiConstant.Cart.LIMIT_NUM_FAIL);
// 购物车中更新有效库存
OmcCart cartForQuantity = new OmcCart();
cartForQuantity.setId(cartItem.getId());
cartForQuantity.setQuantity(buyLimitCount);
omcCartMapper.updateByPrimaryKeySelective(cartForQuantity);
}
cartProductVo.setQuantity(buyLimitCount);
// 计算总价
cartProductVo.setProductTotalPrice(BigDecimalUtil.mul(product.getPrice().doubleValue(), cartProductVo.getQuantity()));
cartProductVo.setChecked(cartItem.getChecked());
if (cartItem.getChecked() == OmcApiConstant.Cart.CHECKED) {
// 如果已经勾选,增加到整个的购物车总价中
cartTotalPrice = BigDecimalUtil.add(cartTotalPrice.doubleValue(), cartProductVo.getProductTotalPrice().doubleValue());
}
cartProductVoList.add(cartProductVo);
}
}
cartVo.setCartTotalPrice(cartTotalPrice);
cartVo.setCartProductVoList(cartProductVoList);
cartVo.setAllChecked(this.getAllCheckedStatus(userId));
return cartVo;
}
use of com.paascloud.provider.exceptions.MdcBizException in project paascloud-master by paascloud.
the class MdcDictServiceImpl method updateDictStatus.
private void updateDictStatus(List<MdcDict> mdcDictList, LoginAuthDto loginAuthDto, int status) {
MdcDict update = new MdcDict();
for (MdcDict dict : mdcDictList) {
update.setId(dict.getId());
update.setVersion(dict.getVersion() + 1);
update.setStatus(status);
update.setUpdateInfo(loginAuthDto);
int result = mapper.updateByPrimaryKeySelective(update);
if (result < 1) {
throw new MdcBizException(ErrorCodeEnum.MDC10021019, dict.getId());
}
}
}
use of com.paascloud.provider.exceptions.MdcBizException in project paascloud-master by paascloud.
the class MdcDictServiceImpl method getMdcDictVoById.
@Override
@Transactional(readOnly = true, rollbackFor = Exception.class)
public MdcDictVo getMdcDictVoById(Long dictId) {
MdcDict dict = mdcDictMapper.selectByPrimaryKey(dictId);
if (dict == null) {
logger.error("找不到数据字典信息id={}", dictId);
throw new MdcBizException(ErrorCodeEnum.MDC10021018, dictId);
}
// 获取父级菜单信息
MdcDict parentDict = mdcDictMapper.selectByPrimaryKey(dict.getPid());
ModelMapper modelMapper = new ModelMapper();
MdcDictVo dictVo = modelMapper.map(dict, MdcDictVo.class);
if (parentDict != null) {
dictVo.setParentDictName(parentDict.getDictName());
}
return dictVo;
}
Aggregations