Search in sources :

Example 1 with ProductDto

use of com.paascloud.provider.model.dto.ProductDto in project paascloud-master by paascloud.

the class MdcProductQueryFeignClient method selectById.

@Override
@ApiOperation(httpMethod = "POST", value = "根据商品ID查询商品信息")
public Wrapper<ProductDto> selectById(@PathVariable("productId") Long productId) {
    logger.info("根据商品ID查询商品信息. productId={}", productId);
    ProductDto productDto = null;
    MdcProduct mdcProduct = mdcProductService.selectByKey(productId);
    if (PublicUtil.isNotEmpty(mdcProduct)) {
        productDto = new ProductDto();
        BeanUtils.copyProperties(mdcProduct, productDto);
    }
    return WrapMapper.ok(productDto);
}
Also used : ProductDto(com.paascloud.provider.model.dto.ProductDto) MdcProduct(com.paascloud.provider.model.domain.MdcProduct) ApiOperation(io.swagger.annotations.ApiOperation)

Example 2 with ProductDto

use of com.paascloud.provider.model.dto.ProductDto 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 3 with ProductDto

use of com.paascloud.provider.model.dto.ProductDto in project paascloud-master by paascloud.

the class MdcProductCategoryQueryFeignClient method assembleProductListVo.

private ProductDto assembleProductListVo(MdcProduct product) {
    ProductDto productListVo = new ProductDto();
    productListVo.setId(product.getId());
    productListVo.setName(product.getName());
    productListVo.setCategoryId(product.getId());
    productListVo.setImageHost("");
    productListVo.setMainImage(product.getMainImage());
    productListVo.setPrice(product.getPrice());
    productListVo.setSubtitle(product.getSubtitle());
    productListVo.setStatus(product.getStatus());
    return productListVo;
}
Also used : ProductDto(com.paascloud.provider.model.dto.ProductDto)

Example 4 with ProductDto

use of com.paascloud.provider.model.dto.ProductDto in project paascloud-master by paascloud.

the class MdcProductCategoryQueryFeignClient method getProductList.

/**
 * 获取商品列表信息.
 *
 * @param productReqDto the product req dto
 *
 * @return the product list
 */
@Override
@ApiOperation(httpMethod = "POST", value = "获取商品列表信息")
public Wrapper<PageInfo> getProductList(@RequestBody ProductReqDto productReqDto) {
    logger.info("获取商品列表信息. productReqDto={}", productReqDto);
    Long categoryId = productReqDto.getCategoryId();
    String keyword = productReqDto.getKeyword();
    Integer pageNum = productReqDto.getPageNum();
    Integer pageSize = productReqDto.getPageSize();
    String orderBy = productReqDto.getOrderBy();
    if (StringUtils.isBlank(keyword) && null == categoryId) {
        return WrapMapper.ok(new PageInfo());
    }
    List<Long> categoryIdList = Lists.newArrayList();
    if (categoryId != null) {
        MdcProductCategory category = mdcProductCategoryService.selectByKey(categoryId);
        if (category == null && StringUtils.isBlank(keyword)) {
            // 没有该分类,并且还没有关键字,这个时候返回一个空的结果集,不报错
            PageHelper.startPage(pageNum, pageSize);
            return WrapMapper.wrap(Wrapper.SUCCESS_CODE, Wrapper.SUCCESS_MESSAGE, new PageInfo());
        }
        categoryIdList = mdcProductCategoryService.selectCategoryAndChildrenById(categoryId);
    }
    PageHelper.startPage(pageNum, pageSize);
    // 排序处理
    List<MdcProduct> productList = mdcProductService.selectByNameAndCategoryIds(StringUtils.isBlank(keyword) ? null : keyword, PublicUtil.isEmpty(categoryIdList) ? null : categoryIdList, orderBy);
    List<ProductDto> productListVoList = Lists.newArrayList();
    for (MdcProduct product : productList) {
        ProductDto productListVo = assembleProductListVo(product);
        String url = mdcProductService.getMainImage(product.getId());
        productListVo.setMainImage(url);
        productListVoList.add(productListVo);
    }
    return PublicUtil.isNotEmpty(productListVoList) ? WrapMapper.ok(new PageInfo<>(productListVoList)) : WrapMapper.ok();
}
Also used : PageInfo(com.github.pagehelper.PageInfo) MdcProductCategory(com.paascloud.provider.model.domain.MdcProductCategory) MdcProduct(com.paascloud.provider.model.domain.MdcProduct) ProductDto(com.paascloud.provider.model.dto.ProductDto) ApiOperation(io.swagger.annotations.ApiOperation)

Example 5 with ProductDto

use of com.paascloud.provider.model.dto.ProductDto 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)

Aggregations

ProductDto (com.paascloud.provider.model.dto.ProductDto)7 OmcCart (com.paascloud.provider.model.domain.OmcCart)3 MdcBizException (com.paascloud.provider.exceptions.MdcBizException)2 MdcProduct (com.paascloud.provider.model.domain.MdcProduct)2 OmcOrderDetail (com.paascloud.provider.model.domain.OmcOrderDetail)2 CartProductVo (com.paascloud.provider.model.vo.CartProductVo)2 ApiOperation (io.swagger.annotations.ApiOperation)2 PageInfo (com.github.pagehelper.PageInfo)1 LoginAuthDto (com.paascloud.base.dto.LoginAuthDto)1 OmcBizException (com.paascloud.provider.exceptions.OmcBizException)1 MdcProductCategory (com.paascloud.provider.model.domain.MdcProductCategory)1 CartVo (com.paascloud.provider.model.vo.CartVo)1 BigDecimal (java.math.BigDecimal)1