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