paascloud/paascloud-master · error · MdcBizException
MDC10021004
MDC10021004
Error message
MDC10021004
What it means
MDC10021004 maps to ErrorCodeEnum MDC10021004 ("找不到该商品信息,productId=%s" — product not found for the given productId). In OmcCartServiceImpl.getCarVo, when building the cart view each cart item's product is loaded via mdcProductService.selectById(productId); if the product no longer exists (deleted from the mdc_product table or not visible), an MdcBizException is thrown with the offending productId. It is a data-consistency issue: the cart references a product that no longer exists.
Solutions
- Confirm the productId exists in the mdc_product table (SELECT ... WHERE id = <productId>); if missing, remove the stale cart item instead of failing the whole cart.
- Clean up orphaned cart entries: delete omc_cart rows whose productId no longer exists before building the cart view.
- Soft-delete products instead of hard-deleting so existing cart items remain resolvable (or keep tombstone rows for order/cart history).
- If productId is wrong because of a data bug, fix the source data or the migration that produced the mismatch.
- Wrap per-item loading so one missing product is skipped/logged rather than aborting the entire cart response.
Example fix
// before
ProductDto product = mdcProductService.selectById(cartItem.getProductId());
if (product == null) {
throw new MdcBizException(ErrorCodeEnum.MDC10021004, cartItem.getProductId());
}
// after
ProductDto product = mdcProductService.selectById(cartItem.getProductId());
if (product == null) {
logger.warn("商品不存在, 移除失效购物车项, productId={}", cartItem.getProductId());
omcCartMapper.deleteByUserIdProductIds(userId, Lists.newArrayList(cartItem.getProductId().toString()));
continue;
} Defensive patterns
Strategy: validation
Validate before calling
ProductDto product = mdcProductService.selectById(productId);
if (product == null) {
logger.warn("Skipping cart item, product missing, productId={}", productId);
return null; // or remove the cart item upstream
} Type guard
boolean productExists(Long productId) { return productId != null && mdcProductService.selectById(productId) != null; } Try / catch
try {
return cartService.getCarVo(userId);
} catch (MdcBizException e) {
if (String.valueOf(e.getMessage()).contains("找不到该商品信息")) {
// refresh cart / prune stale items and retry once
} else { throw e; }
} Prevention
- Use soft-delete for products referenced by open carts.
- Periodically prune omc_cart rows whose productId no longer exists.
- Refresh cart state on the client before submitting updates.
- Keep cart and product services pointed at consistent data in each environment.
When it happens
Trigger: Rendering/updating the shopping cart when a cart item references a productId that selectById cannot resolve — typically the product was deleted or unpublished in the MDC service after being added to the cart.
Common situations: Products removed by an admin while still sitting in users' carts; test/staging carts pointing at a different database than the product service; orphaned cart rows from data migration; stale carts after a data reset.
Understand the failure class
Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.
Related errors
AI-assisted analysis of paascloud/paascloud-master@781281a950 (2026-09-10).
Data as JSON: /api/errors/adc5bef9693dcd1b.
Report an issue: GitHub.
Appendix: source
Thrown at paascloud-provider/paascloud-provider-omc/src/main/java/com/paascloud/provider/service/impl/OmcCartServiceImpl.java:80
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);View on GitHub (pinned to 781281a950)