{"record":{"id":"ce22a4422d4e8637","repo":"paascloud/paascloud-master","slug":"omc10031001","errorCode":"OMC10031001","errorMessage":"OMC10031001","messagePattern":"OMC10031001","errorType":"error_code","errorClass":"OmcBizException","httpStatus":null,"severity":"error","filePath":"paascloud-provider/paascloud-provider-omc/src/main/java/com/paascloud/provider/service/impl/OmcCartServiceImpl.java","lineNumber":310,"sourceCode":"\t\t}\n\n\t\torderProductVo.setProductTotalPrice(payment);\n\t\torderProductVo.setOrderItemVoList(orderItemVoList);\n\n\t\treturn orderProductVo;\n\t}\n\n\tprivate boolean getAllCheckedStatus(Long userId) {\n\t\tPreconditions.checkArgument(userId != null, ErrorCodeEnum.UAC10011001.msg());\n\t\treturn omcCartMapper.selectUnCheckedCartProductCountByUserId(userId) == 0;\n\n\t}\n\n\t@Override\n\tpublic List<OmcOrderDetail> getCartOrderItem(Long userId, List<OmcCart> cartList) {\n\t\tList<OmcOrderDetail> orderItemList = Lists.newArrayList();\n\t\tif (CollectionUtils.isEmpty(cartList)) {\n\t\t\tthrow new OmcBizException(ErrorCodeEnum.OMC10031001, userId);\n\t\t}\n\n\t\t//校验购物车的数据,包括产品的状态和数量\n\t\tfor (OmcCart cartItem : cartList) {\n\t\t\tOmcOrderDetail orderDetail = new OmcOrderDetail();\n\t\t\tProductDto product = mdcProductService.selectById(cartItem.getProductId());\n\t\t\tif (MdcApiConstant.ProductStatusEnum.ON_SALE.getCode() != product.getStatus()) {\n\t\t\t\tlogger.error(\"商品不是在线售卖状态, productId={}\", product.getId());\n\t\t\t\tthrow new OmcBizException(ErrorCodeEnum.MDC10021015, product.getId());\n\t\t\t}\n\n\t\t\t//校验库存\n\t\t\tif (cartItem.getQuantity() > product.getStock()) {\n\t\t\t\tlogger.error(\"商品库存不足, productId={}\", product.getId());\n\t\t\t\tthrow new OmcBizException(ErrorCodeEnum.MDC10021016, product.getId());\n\t\t\t}\n\n\t\t\torderDetail.setUserId(userId);","sourceCodeStart":292,"sourceCodeEnd":328,"githubUrl":"https://github.com/paascloud/paascloud-master/blob/781281a9503332ed3cef44ea618349d14230a127/paascloud-provider/paascloud-provider-omc/src/main/java/com/paascloud/provider/service/impl/OmcCartServiceImpl.java#L292-L328","documentation":"OMC10031001 means '购物车为空' (cart is empty, userId=%s). getCartOrderItem builds order details from a cart list, and if the caller passes a null/empty list there is nothing to convert into OmcOrderDetail rows, so the service throws OmcBizException instead of silently producing an empty order.","triggerScenarios":"Calling omcCartService.getCartOrderItem(userId, cartList) with an empty or null cartList — e.g. after the user's checked cart items were deleted, or a caller builds the cart list itself and passes it unvalidated.","commonSituations":"User empties their cart in one session/tab then checks out from a stale page; the checked-cart query (selectCheckedCartByUserId) returns nothing because no items are checked; cart records were purged between page load and order creation.","solutions":["Check CollectionUtils.isEmpty(cartList) before calling getCartOrderItem and handle the empty-cart case in the UI (redirect to cart page with a message).","Ensure the cart has checked/selected items before invoking checkout — selectCheckedCartByUserId only returns checked items.","Catch OmcBizException and map code 10031001 to a user-facing 'your cart is empty' response rather than a 500.","If the cart should never be empty, add an earlier guard when items are removed so checkout is disabled client-side."],"exampleFix":"// before\nList<OmcOrderDetail> items = omcCartService.getCartOrderItem(userId, cartList);\n// after\nif (CollectionUtils.isEmpty(cartList)) {\n    return ResultHelper.fail(ErrorCodeEnum.OMC10031001, userId);\n}\nList<OmcOrderDetail> items = omcCartService.getCartOrderItem(userId, cartList);","handlingStrategy":"validation","validationCode":"// Java, before calling the service\nif (cartList == null || cartList.isEmpty()) {\n    throw new OmcBizException(ErrorCodeEnum.OMC10031001, userId); // or return an empty-cart result\n}","typeGuard":"// Java\nprivate static boolean hasItems(List<OmcCart> cartList) {\n    return cartList != null && !cartList.isEmpty();\n}","tryCatchPattern":"try {\n    List<OmcOrderDetail> items = omcCartService.getCartOrderItem(userId, cartList);\n} catch (OmcBizException e) {\n    if (e.getCode() == ErrorCodeEnum.OMC10031001.getCode()) {\n        return ResultHelper.fail(e.getCode(), \"Your cart is empty\");\n    }\n    throw e;\n}","preventionTips":["Validate the cart list is non-empty before invoking order-building APIs.","Treat 'empty cart' as a normal user state, not a server error, in the UI flow.","Re-fetch the cart immediately before checkout to avoid stale data.","Disable checkout UI when the checked-item count is zero."],"tags":["cart","empty-list","order-creation","business-exception"],"backgroundTag":"empty-required-field","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"}