{"record":{"id":"2ae06a369d87f4e9","repo":"paascloud/paascloud-master","slug":"omc10031001-2ae06a","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/OmcOrderServiceImpl.java","lineNumber":84,"sourceCode":"\tprivate OmcCartMapper omcCartMapper;\n\t@Resource\n\tprivate OmcShippingMapper omcShippingMapper;\n\t@Resource\n\tprivate OmcCartService omcCartService;\n\t@Resource\n\tprivate OmcOrderDetailService omcOrderDetailService;\n\n\t@Resource\n\tprivate MdcProductService mdcProductService;\n\n\t@Override\n\t@Transactional(rollbackFor = Exception.class)\n\tpublic OrderVo createOrderDoc(LoginAuthDto loginAuthDto, Long shippingId) {\n\t\tLong userId = loginAuthDto.getUserId();\n\t\t//从购物车中获取数据\n\t\tList<OmcCart> cartList = omcCartMapper.selectCheckedCartByUserId(userId);\n\t\tif (CollectionUtils.isEmpty(cartList)) {\n\t\t\tthrow new OmcBizException(ErrorCodeEnum.OMC10031001, userId);\n\t\t}\n\t\t//计算这个订单的总价\n\t\tList<OmcOrderDetail> omcOrderDetailList = omcCartService.getCartOrderItem(userId, cartList);\n\n\t\tif (CollectionUtils.isEmpty(omcOrderDetailList)) {\n\t\t\tthrow new OmcBizException(ErrorCodeEnum.OMC10031001, userId);\n\t\t}\n\n\t\tBigDecimal payment = this.getOrderTotalPrice(omcOrderDetailList);\n\n\n\t\t//生成订单\n\t\tOmcOrder order = this.assembleOrder(userId, shippingId, payment);\n\t\tif (order == null) {\n\t\t\tlogger.error(\"生成订单失败, userId={}, shippingId={}, payment={}\", userId, shippingId, payment);\n\t\t\tthrow new OmcBizException(ErrorCodeEnum.OMC10031002);\n\t\t}\n\t\torder.setUpdateInfo(loginAuthDto);","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/paascloud/paascloud-master/blob/781281a9503332ed3cef44ea618349d14230a127/paascloud-provider/paascloud-provider-omc/src/main/java/com/paascloud/provider/service/impl/OmcOrderServiceImpl.java#L66-L102","documentation":"OMC10031001 means '购物车为空' (cart is empty, userId=%s). createOrderDoc loads the user's checked cart items via omcCartMapper.selectCheckedCartByUserId and throws when the list is empty (or when the computed order-detail list comes back empty), because an order cannot be created without any cart items.","triggerScenarios":"Calling createOrderDoc(loginAuthDto, shippingId) for a user whose cart has no checked items (or no cart items at all), or where getCartOrderItem filtered everything out so omcOrderDetailList is empty.","commonSituations":"User submits checkout from a stale page after unchecking/removing all items; checkout endpoint hit twice and items were already consumed; no items were ever checked (checkbox not set); cart data purged by a scheduled cleanup job.","solutions":["Before checkout, verify the user has checked cart items (selectCheckedCartByUserId) and redirect to the cart page with a message if empty.","Catch OmcBizException code 10031001 and return a friendly 'your cart is empty' response instead of a 500.","Ensure the client sends the checked flags correctly when adding/updating cart items so selectCheckedCartByUserId returns them.","Disable the checkout button server-validated-side when the checked cart is empty to prevent duplicate/stale submissions."],"exampleFix":"// before\nOrderVo vo = orderService.createOrderDoc(loginAuthDto, shippingId);\n// after\nList<OmcCart> checked = omcCartMapper.selectCheckedCartByUserId(userId);\nif (CollectionUtils.isEmpty(checked)) {\n    return ResultHelper.fail(ErrorCodeEnum.OMC10031001, userId);\n}\nOrderVo vo = orderService.createOrderDoc(loginAuthDto, shippingId);","handlingStrategy":"validation","validationCode":"// Java, before invoking checkout\nList<OmcCart> checked = omcCartMapper.selectCheckedCartByUserId(userId);\nif (checked == null || checked.isEmpty()) {\n    return ResultHelper.fail(ErrorCodeEnum.OMC10031001, userId);\n}","typeGuard":"// Java\nprivate static boolean hasCheckedItems(List<OmcCart> cartList) {\n    return cartList != null && cartList.stream().anyMatch(OmcCart::getChecked);\n}","tryCatchPattern":"try {\n    OrderVo vo = orderService.createOrderDoc(loginAuthDto, shippingId);\n} catch (OmcBizException e) {\n    if (e.getCode() == ErrorCodeEnum.OMC10031001.getCode()) {\n        return ResultHelper.fail(e.getCode(), \"Your cart is empty or no items are selected\");\n    }\n    throw e;\n}","preventionTips":["Check the checked cart immediately before creating the order and degrade gracefully.","Make the checkout UI reflect the server-side checked-item state.","Guard against double-submission of the checkout endpoint (idempotency token).","Ensure cart add/update flows set the checked flag as users expect."],"tags":["cart","empty-list","checkout","order-creation"],"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"}