{"record":{"id":"ac36422147b127f7","repo":"paascloud/paascloud-master","slug":"mdc10021022","errorCode":"MDC10021022","errorMessage":"MDC10021022","messagePattern":"MDC10021022","errorType":"error_code","errorClass":"MdcBizException","httpStatus":null,"severity":"error","filePath":"paascloud-provider/paascloud-provider-omc/src/main/java/com/paascloud/provider/service/impl/MdcProductServiceImpl.java","lineNumber":82,"sourceCode":"\n\t\tif (wrapper == null) {\n\t\t\tthrow new MdcBizException(ErrorCodeEnum.GL99990002);\n\t\t}\n\t\tif (wrapper.error()) {\n\t\t\tthrow new MdcBizException(ErrorCodeEnum.MDC10021004, productId);\n\t\t}\n\t\treturn wrapper.getResult();\n\t}\n\n\t@Override\n\tpublic int updateProductStockById(ProductDto productDto) {\n\t\tPreconditions.checkArgument(productDto.getId() != null, ErrorCodeEnum.MDC10021021.msg());\n\t\tWrapper<Integer> wrapper = mdcProductFeignApi.updateProductStockById(productDto);\n\t\tif (wrapper == null) {\n\t\t\tthrow new MdcBizException(ErrorCodeEnum.GL99990002);\n\t\t}\n\t\tif (wrapper.error()) {\n\t\t\tthrow new MdcBizException(ErrorCodeEnum.MDC10021022, productDto.getId());\n\t\t}\n\t\treturn wrapper.getResult();\n\t}\n\n\t@Override\n\tpublic String getMainImage(final Long productId) {\n\t\tWrapper<String> wrapper = mdcProductFeignApi.getMainImage(productId);\n\t\tif (wrapper == null) {\n\t\t\tthrow new MdcBizException(ErrorCodeEnum.GL99990002);\n\t\t}\n\t\treturn wrapper.getResult();\n\t}\n}\n","sourceCodeStart":64,"sourceCodeEnd":96,"githubUrl":"https://github.com/paascloud/paascloud-master/blob/781281a9503332ed3cef44ea618349d14230a127/paascloud-provider/paascloud-provider-omc/src/main/java/com/paascloud/provider/service/impl/MdcProductServiceImpl.java#L64-L96","documentation":"MdcProductServiceImpl.updateProductStockById calls mdcProductFeignApi.updateProductStockById(productDto); if the returned wrapper is a failed response (wrapper.error()), it throws MdcBizException with ErrorCodeEnum MDC10021022 (message '更新商品库存失败' — stock update failed), formatted with the product id. The Feign call itself succeeded, but the OMC-side stock update operation reported failure (e.g. affected rows 0).","triggerScenarios":"Calling updateProductStockById with a productDto whose id does not match an existing product, or whose stock delta cannot be applied (e.g. decrementing stock below what the upstream SQL allows, or optimistic-lock/row-count check failing in the OMC provider), so the Feign response wrapper carries error=true.","commonSituations":"Ordering/checkout flow decrementing stock for a product deleted or deactivated in another service; concurrent stock updates causing the conditional UPDATE to match 0 rows; stale product id from a cached cart; Feign misconfiguration pointing at a wrong environment where the product doesn't exist.","solutions":["Verify the product id exists (mdc_product table) and is active before calling updateProductStockById","Inspect the upstream OMC update SQL/mapper — a 0-row update (stock already at limit or record missing) is the usual root cause; add row-count logging","Handle concurrency with a proper optimistic lock or atomic 'UPDATE ... SET stock = stock - ? WHERE stock >= ?' and retry on conflict","Catch MdcBizException in the caller and roll back the order/transaction, returning a 'stock update failed' user message"],"exampleFix":"// before: unchecked failure leaves order inconsistent\nmdcProductService.updateProductStockById(productDto);\n// after: guard and rollback\ntry {\n    mdcProductService.updateProductStockById(productDto);\n} catch (MdcBizException e) {\n    log.error(\"stock update failed for product {}\", productDto.getId(), e);\n    throw new OrderBizException(ErrorCodeEnum.OMC10031004);\n}","handlingStrategy":"try-catch","validationCode":"Preconditions.checkArgument(productDto.getId() != null, \"product id required\");\n// optionally verify existence first:\nMdcProduct product = mdcProductMapper.selectById(productDto.getId());\nPreconditions.checkState(product != null, \"product not found: \" + productDto.getId());","typeGuard":null,"tryCatchPattern":"try {\n  mdcProductService.updateProductStockById(productDto);\n} catch (MdcBizException e) {\n  if (ErrorCodeEnum.MDC10021022.getCode().equals(e.getCode())) {\n    // stock update failed upstream — compensate/rollback order\n    orderService.rollback(orderNo);\n  }\n  throw e;\n}","preventionTips":["Validate the product exists and is on-sale before decrementing stock","Use an atomic conditional UPDATE (stock >= delta) and treat 0 affected rows as an explicit business failure","Wrap order creation + stock update in a saga/TCC flow with compensation so failures roll back cleanly","Watch for stale ids from long-lived carts; re-validate product state at checkout"],"tags":["feign","stock","distributed-transaction","omc"],"backgroundTag":"database-write-failed","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"}