Search in sources :

Example 1 with MdcBizException

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);
}
Also used : MdcBizException(com.paascloud.provider.exceptions.MdcBizException) MdcProduct(com.paascloud.provider.model.domain.MdcProduct)

Example 2 with MdcBizException

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;
}
Also used : MdcBizException(com.paascloud.provider.exceptions.MdcBizException) OmcCart(com.paascloud.provider.model.domain.OmcCart)

Example 3 with MdcBizException

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;
}
Also used : CartProductVo(com.paascloud.provider.model.vo.CartProductVo) MdcBizException(com.paascloud.provider.exceptions.MdcBizException) CartVo(com.paascloud.provider.model.vo.CartVo) OmcCart(com.paascloud.provider.model.domain.OmcCart) BigDecimal(java.math.BigDecimal) ProductDto(com.paascloud.provider.model.dto.ProductDto)

Example 4 with MdcBizException

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());
        }
    }
}
Also used : MdcBizException(com.paascloud.provider.exceptions.MdcBizException) MdcDict(com.paascloud.provider.model.domain.MdcDict)

Example 5 with MdcBizException

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;
}
Also used : MdcBizException(com.paascloud.provider.exceptions.MdcBizException) MdcDictVo(com.paascloud.provider.model.vo.MdcDictVo) MdcDict(com.paascloud.provider.model.domain.MdcDict) ModelMapper(org.modelmapper.ModelMapper) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

MdcBizException (com.paascloud.provider.exceptions.MdcBizException)11 MdcDict (com.paascloud.provider.model.domain.MdcDict)3 MdcProductCategory (com.paascloud.provider.model.domain.MdcProductCategory)3 OmcCart (com.paascloud.provider.model.domain.OmcCart)3 ProductDto (com.paascloud.provider.model.dto.ProductDto)2 CartProductVo (com.paascloud.provider.model.vo.CartProductVo)2 ModelMapper (org.modelmapper.ModelMapper)2 LoginAuthDto (com.paascloud.base.dto.LoginAuthDto)1 MdcProduct (com.paascloud.provider.model.domain.MdcProduct)1 GaodeLocation (com.paascloud.provider.model.dto.gaode.GaodeLocation)1 CartVo (com.paascloud.provider.model.vo.CartVo)1 MdcCategoryVo (com.paascloud.provider.model.vo.MdcCategoryVo)1 MdcDictVo (com.paascloud.provider.model.vo.MdcDictVo)1 BigDecimal (java.math.BigDecimal)1 Transactional (org.springframework.transaction.annotation.Transactional)1