{"record":{"id":"adc5bef9693dcd1b","repo":"paascloud/paascloud-master","slug":"mdc10021004","errorCode":"MDC10021004","errorMessage":"MDC10021004","messagePattern":"MDC10021004","errorType":"error_code","errorClass":"MdcBizException","httpStatus":null,"severity":"error","filePath":"paascloud-provider/paascloud-provider-omc/src/main/java/com/paascloud/provider/service/impl/OmcCartServiceImpl.java","lineNumber":80,"sourceCode":"\tpublic CartVo getCarVo(Long userId) {\n\t\tlogger.info(\"getCarVo -  获取购物车列表 -- userId={}\", userId);\n\t\tCartVo cartVo = new CartVo();\n\t\tList<OmcCart> cartList = this.selectCartListByUserId(userId);\n\t\tList<CartProductVo> cartProductVoList = Lists.newArrayList();\n\n\t\tBigDecimal cartTotalPrice = new BigDecimal(\"0\");\n\n\t\tif (PublicUtil.isNotEmpty(cartList)) {\n\t\t\tfor (OmcCart cartItem : cartList) {\n\t\t\t\tCartProductVo cartProductVo = new CartProductVo();\n\t\t\t\tcartProductVo.setId(cartItem.getId());\n\t\t\t\tcartProductVo.setUserId(userId);\n\t\t\t\tcartProductVo.setProductId(cartItem.getProductId());\n\n\t\t\t\tProductDto product = mdcProductService.selectById(cartItem.getProductId());\n\n\t\t\t\tif (product == null) {\n\t\t\t\t\tthrow new MdcBizException(ErrorCodeEnum.MDC10021004, cartItem.getProductId());\n\t\t\t\t}\n\n\t\t\t\tcartProductVo.setProductMainImage(product.getMainImage());\n\t\t\t\tcartProductVo.setProductName(product.getName());\n\t\t\t\tcartProductVo.setProductSubtitle(product.getSubtitle());\n\t\t\t\tcartProductVo.setProductStatus(product.getStatus());\n\t\t\t\tcartProductVo.setProductPrice(product.getPrice());\n\t\t\t\tcartProductVo.setProductStock(product.getStock());\n\n\t\t\t\t//判断库存\n\t\t\t\tint buyLimitCount;\n\t\t\t\tif (product.getStock() >= cartItem.getQuantity()) {\n\t\t\t\t\t//库存充足的时候\n\t\t\t\t\tbuyLimitCount = cartItem.getQuantity();\n\t\t\t\t\tcartProductVo.setLimitQuantity(OmcApiConstant.Cart.LIMIT_NUM_SUCCESS);\n\t\t\t\t} else {\n\t\t\t\t\tbuyLimitCount = product.getStock();\n\t\t\t\t\tcartProductVo.setLimitQuantity(OmcApiConstant.Cart.LIMIT_NUM_FAIL);","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/paascloud/paascloud-master/blob/781281a9503332ed3cef44ea618349d14230a127/paascloud-provider/paascloud-provider-omc/src/main/java/com/paascloud/provider/service/impl/OmcCartServiceImpl.java#L62-L98","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nProductDto product = mdcProductService.selectById(cartItem.getProductId());\nif (product == null) {\n    throw new MdcBizException(ErrorCodeEnum.MDC10021004, cartItem.getProductId());\n}\n// after\nProductDto product = mdcProductService.selectById(cartItem.getProductId());\nif (product == null) {\n    logger.warn(\"商品不存在, 移除失效购物车项, productId={}\", cartItem.getProductId());\n    omcCartMapper.deleteByUserIdProductIds(userId, Lists.newArrayList(cartItem.getProductId().toString()));\n    continue;\n}","handlingStrategy":"validation","validationCode":"ProductDto product = mdcProductService.selectById(productId);\nif (product == null) {\n    logger.warn(\"Skipping cart item, product missing, productId={}\", productId);\n    return null; // or remove the cart item upstream\n}","typeGuard":"boolean productExists(Long productId) { return productId != null && mdcProductService.selectById(productId) != null; }","tryCatchPattern":"try {\n    return cartService.getCarVo(userId);\n} catch (MdcBizException e) {\n    if (String.valueOf(e.getMessage()).contains(\"找不到该商品信息\")) {\n        // refresh cart / prune stale items and retry once\n    } else { throw e; }\n}","preventionTips":["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."],"tags":["cart","product-not-found","data-consistency","java","shopping-cart"],"backgroundTag":"record-not-found","analyzedSha":"781281a9503332ed3cef44ea618349d14230a127","analyzedAt":"2026-09-10T10:59:02.070Z","contentChangedAt":"2026-09-10T10:59:02.070Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}