{"id":1315,"date":"2025-09-21T00:16:31","date_gmt":"2025-09-20T16:16:31","guid":{"rendered":"https:\/\/eve2333.top\/?p=1315"},"modified":"2025-09-21T00:16:55","modified_gmt":"2025-09-20T16:16:55","slug":"%e7%89%9b%e5%88%b8onecoupon%e7%b3%bb%e7%bb%9f-%e7%ac%ac%e2%91%a3%e7%ab%a0%e8%8a%82%ef%bc%9a%e7%bb%93%e7%ae%97%e6%9c%8d%e5%8a%a1","status":"publish","type":"post","link":"https:\/\/eve2333.top\/?p=1315","title":{"rendered":"\u725b\u5238oneCoupon\u7cfb\u7edf \u7b2c\u2463\u7ae0\u8282\uff1a\u7ed3\u7b97\u670d\u52a1"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u4e1a\u52a1\u80cc\u666f<\/h2>\n\n\n\n<p>\u6211\u4eec\u5728\u4f7f\u7528\u4f18\u60e0\u5238\u8d2d\u7269\u65f6\uff0c\u53ef\u4ee5\u5728\u8ba2\u5355\u7ed3\u7b97\u9875\u9762\u67e5\u770b\u81ea\u5df1\u7684\u53ef\u7528\/\u4e0d\u53ef\u7528\u4f18\u60e0\u5238\u5217\u8868\uff0c\u53ef\u7528\u7684\u4f18\u60e0\u5238\u8fd8\u4f1a\u6839\u636e\u53ef\u6263\u51cf\u8ba2\u5355\u91d1\u989d\u4ece\u5927\u5230\u5c0f\u8fdb\u884c\u6392\u5e8f\u3002<\/p>\n\n\n\n<p>\u4ee5\u4e0b\u4e3a\u7f8e\u56e2\u5916\u5356\u8ba2\u5355\u7ed3\u7b97\u65f6\u4f18\u60e0\u5238\u53ef\u7528\/\u4e0d\u53ef\u7528\u5217\u8868\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/article-images.zsxq.com\/FjrtAHkuSN_gr99LWcw-kwqVPadY\" alt=\"\u56fe\u7247.png\" title=\"\u56fe\u7247.png\"\/><\/figure>\n\n\n\n\n\n<h2 class=\"wp-block-heading\" id=\"git\">Git \u5206\u652f<\/h2>\n\n\n\n<p>\u5148\u4ece main \u5206\u652f\u4e0a\u67e5\u770b\uff0c\u4ee3\u7801\u5165\u53e3\uff1a<code>CouponQueryController#listQueryCouponsBySync<\/code>\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"and\">\u67e5\u8be2\u7528\u6237\u4f18\u60e0\u5238&amp;\u8ba1\u7b97\u6298\u6263\u91d1\u989d<\/h2>\n\n\n\n<p>\u56e0\u4e3a\u67e5\u8be2\u7528\u6237\u53ef\u7528\u4f18\u60e0\u5238\u65f6\uff0c\u9700\u8981\u6839\u636e\u6298\u6263\u91d1\u989d\u8fdb\u884c\u6392\u5e8f\uff0c\u6240\u4ee5\u672c\u8d28\u4e0a\u5728\u67e5\u8be2\u7528\u6237\u53ef\u7528\u4f18\u60e0\u5238\u529f\u80fd\u57fa\u7840\u4e0a\uff0c\u5c31\u628a\u540e\u8005\u5b9e\u73b0\u4e86\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"1-and\">1. \u8bf7\u6c42&amp;\u8fd4\u56de\u53c2\u6570<\/h3>\n\n\n\n<p>\u6211\u4eec\u67e5\u8be2\u7684\u65f6\u5019\uff0c\u9700\u8981\u4f20\u5165\u8ba2\u5355\u91d1\u989d\u3001\u5546\u54c1\u96c6\u5408\u4ee5\u53ca\u5e97\u94fa\u7f16\u53f7\u4fe1\u606f\uff0c\u56e0\u4e3a\u6211\u4eec\u4f18\u60e0\u5238\u670d\u52a1\u8fd9\u4e2a\u63a5\u53e3\u4e0d\u76f4\u63a5\u5bf9\u7528\u6237\uff0c\u6240\u4ee5\u8ba2\u5355\u91d1\u989d\u8fd9\u4e9b\u4fe1\u606f\u4e0d\u9700\u8981\u989d\u5916\u9a8c\u8bc1\u3002\u4e00\u822c\u6765\u8bf4\uff0c\u4f1a\u7531\u805a\u5408\u670d\u52a1\u6216\u8005\u8ba2\u5355\u670d\u52a1\u8fdb\u884c\u9a8c\u8bc1\uff0c\u7136\u540e\u8def\u7531\u5230\u6211\u4eec\u670d\u52a1\u4e2d\u3002<\/p>\n\n\n\n<p>\u54cd\u5e94\u53c2\u6570\u91cc\u91cd\u70b9\u8fd4\u56de\u4f18\u60e0\u5238\u660e\u7ec6\u548c\u4f18\u60e0\u5238\u51cf\u514d\u91d1\u989d\u3002<\/p>\n\n\n\n<p>\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@Data@Schema(description =\"\u67e5\u8be2\u7528\u6237\u4f18\u60e0\u5238\u8bf7\u6c42\u53c2\u6570\")publicclassQueryCouponsReqDTO{\n\u200b\n &nbsp; &nbsp;\/**\n &nbsp; &nbsp; * \u8ba2\u5355\u91d1\u989d\n &nbsp; &nbsp; *\/@Schema(description =\"\u8ba2\u5355\u91d1\u989d\", required =true)privateBigDecimal orderAmount;\n\u200b\n &nbsp; &nbsp;\/**\n &nbsp; &nbsp; * \u5e97\u94fa\u7f16\u53f7\n &nbsp; &nbsp; *\/@Schema(description =\"\u5e97\u94fa\u7f16\u53f7\", example =\"1810714735922956666\", required =true)privateString shopNumber;\n\u200b\n &nbsp; &nbsp;\/**\n &nbsp; &nbsp; * \u5546\u54c1\u96c6\u5408\n &nbsp; &nbsp; *\/@Schema(description =\"\u5546\u54c1\u96c6\u5408\", required =true)privateList&lt;QueryCouponGoodsReqDTO&gt; goodsList;}\n\u200b\n@Data@NoArgsConstructor@AllArgsConstructor@Builder@Schema(description =\"\u67e5\u8be2\u7528\u6237\u4f18\u60e0\u5238\u54cd\u5e94\u53c2\u6570\")publicclassQueryCouponsRespDTO{\n\u200b\n &nbsp; &nbsp;\/**\n &nbsp; &nbsp; * \u53ef\u7528\u4f18\u60e0\u5238\u5217\u8868\n &nbsp; &nbsp; *\/@Schema(description =\"\u53ef\u7528\u4f18\u60e0\u5238\u5217\u8868\")privateList&lt;QueryCouponsDetailRespDTO&gt; availableCouponList;\n\u200b\n &nbsp; &nbsp;\/**\n &nbsp; &nbsp; * \u4e0d\u53ef\u7528\u4f18\u60e0\u5238\u5217\u8868\n &nbsp; &nbsp; *\/@Schema(description =\"\u4e0d\u53ef\u7528\u4f18\u60e0\u5238\u5217\u8868\")privateList&lt;QueryCouponsDetailRespDTO&gt; notAvailableCouponList;}\n\u200b\n@Data@NoArgsConstructor@AllArgsConstructor@Builder@Schema(description =\"\u67e5\u8be2\u7528\u6237\u4f18\u60e0\u5238\u660e\u7ec6\u54cd\u5e94\u53c2\u6570\")publicclassQueryCouponsDetailRespDTO{\n\u200b\n &nbsp; &nbsp;\/**\n &nbsp; &nbsp; * \u4f18\u60e0\u5238id\n &nbsp; &nbsp; *\/@Schema(description =\"\u4f18\u60e0\u5238id\")privateString id;\n\u200b\n &nbsp; &nbsp;\/**\n &nbsp; &nbsp; * \u4f18\u60e0\u5bf9\u8c61 0\uff1a\u5546\u54c1\u4e13\u5c5e 1\uff1a\u5168\u5e97\u901a\u7528\n &nbsp; &nbsp; *\/@Schema(description =\"\u4f18\u60e0\u5bf9\u8c61 0\uff1a\u5546\u54c1\u4e13\u5c5e 1\uff1a\u5168\u5e97\u901a\u7528\")privateInteger target;\n\u200b\n &nbsp; &nbsp;\/**\n &nbsp; &nbsp; * \u4f18\u60e0\u5546\u54c1\u7f16\u7801\n &nbsp; &nbsp; *\/@Schema(description =\"\u4f18\u60e0\u5546\u54c1\u7f16\u7801\")privateString goods;\n\u200b\n &nbsp; &nbsp;\/**\n &nbsp; &nbsp; * \u4f18\u60e0\u7c7b\u578b 0\uff1a\u7acb\u51cf\u5238 1\uff1a\u6ee1\u51cf\u5238 2\uff1a\u6298\u6263\u5238\n &nbsp; &nbsp; *\/@Schema(description =\"\u4f18\u60e0\u7c7b\u578b 0\uff1a\u7acb\u51cf\u5238 1\uff1a\u6ee1\u51cf\u5238 2\uff1a\u6298\u6263\u5238\")privateInteger type;\n\u200b\n &nbsp; &nbsp;\/**\n &nbsp; &nbsp; * \u6d88\u8017\u89c4\u5219\n &nbsp; &nbsp; *\/@Schema(description =\"\u6d88\u8017\u89c4\u5219\")privateString consumeRule;\n\u200b\n &nbsp; &nbsp;\/**\n &nbsp; &nbsp; * \u4f18\u60e0\u5238\u91d1\u989d\n &nbsp; &nbsp; *\/@Schema(description =\"\u4f18\u60e0\u5238\u91d1\u989d\")privateBigDecimal couponAmount;}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"2\">2. \u67e5\u8be2\u7528\u6237\u4f18\u60e0\u5238<\/h3>\n\n\n\n<p>\u9996\u5148\u6211\u4eec\u9700\u8981\u5c06\u7528\u6237\u7684\u4f18\u60e0\u5238\u5217\u8868\u4ece Redis ZSet \u7f13\u5b58\u4e2d\u67e5\u8be2\u51fa\u6765\uff0c\u56e0\u4e3a\u8981\u4ece\u6240\u6709\u4f18\u60e0\u5238\u4e2d\u67e5\u8be2\u53ef\u7528\u4f18\u60e0\u5238\u5e76\u6309\u7167\u51cf\u514d\u91d1\u989d\u8fdb\u884c\u6392\u5e8f\uff0c\u6240\u4ee5\u6211\u4eec\u76f4\u63a5 range \u7684\u8303\u56f4\u662f 0 \u5230 -1\u3002\u53e6\u5916\u4e3a\u4e86\u907f\u514d\u590d\u6742\u8ba1\u7b97\uff0c\u6211\u4eec\u5c06\u73b0\u6709\u4f18\u60e0\u5238\u6309\u7167\u5168\u5e97\u901a\u7528\u4ee5\u53ca\u6307\u5b9a\u5546\u54c1\u53ef\u7528\u62c6\u5206\u4e3a\u4e24\u4e2a\u5206\u7ec4\uff0c\u5bf9\u8fd9\u4e24\u4e2a\u5206\u7ec4\u5206\u522b\u8fdb\u884c\u8ba1\u7b97\u3002<\/p>\n\n\n\n<p>\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>publicQueryCouponsRespDTOlistQueryUserCouponsBySync(QueryCouponsReqDTO requestParam){Set&lt;String&gt; rangeUserCoupons = stringRedisTemplate.opsForZSet().range(String.format(USER_COUPON_TEMPLATE_LIST_KEY,UserContext.getUserId()),0,-1);\n\u200b\n &nbsp; &nbsp;List&lt;String&gt; couponTemplateIds = rangeUserCoupons.stream().map(each -&gt;StrUtil.split(each,\"_\").get(0)).map(each -&gt; redisDistributedProperties.getPrefix()+String.format(COUPON_TEMPLATE_KEY, each)).toList();List&lt;Object&gt; couponTemplateList = stringRedisTemplate.executePipelined((RedisCallback&lt;String&gt;) connection -&gt;{\n &nbsp; &nbsp; &nbsp; &nbsp;couponTemplateIds.forEach(each -&gt; connection.hashCommands().hGetAll(each.getBytes()));returnnull;});\n\u200b\n &nbsp; &nbsp;List&lt;CouponTemplateQueryRespDTO&gt; couponTemplateDTOList =JSON.parseArray(JSON.toJSONString(couponTemplateList),CouponTemplateQueryRespDTO.class);Map&lt;Boolean, List&lt;CouponTemplateQueryRespDTO&gt;&gt; partitioned = couponTemplateDTOList.stream().collect(Collectors.partitioningBy(coupon -&gt;StrUtil.isEmpty(coupon.getGoods())));\n\u200b\n &nbsp; &nbsp;\/\/ \u62c6\u5206\u540e\u7684\u4e24\u4e2a\u5217\u8868List&lt;CouponTemplateQueryRespDTO&gt; goodsEmptyList = partitioned.get(true);\/\/ goods \u4e3a\u7a7a\u7684\u5217\u8868List&lt;CouponTemplateQueryRespDTO&gt; goodsNotEmptyList = partitioned.get(false);\/\/ goods \u4e0d\u4e3a\u7a7a\u7684\u5217\u8868\n\u200b\n &nbsp; &nbsp;\/\/ ......}<\/code><\/pre>\n\n\n\n<p>\u6211\u4eec\u89e3\u6790\u4e0b\u4e0a\u8ff0\u4ee3\u7801\u903b\u8f91\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>1.<strong>\u63d0\u53d6\u4f18\u60e0\u5238\u6a21\u677f ID<\/strong>\uff1a\u901a\u8fc7 <code>StrUtil.split(each, \"_\").get(0)<\/code> \u64cd\u4f5c\uff0c\u63d0\u53d6\u6bcf\u4e2a\u5143\u7d20\u4e2d\u7684 <code>templateId<\/code>\u3002\u5047\u8bbe Redis \u5b58\u50a8\u7684\u683c\u5f0f\u662f <code>templateId_couponId<\/code>\uff0c\u5219 <code>templateId<\/code> \u4e3a\u7b2c\u4e00\u4e2a\u5143\u7d20\u3002<\/li>\n\n\n\n<li>2.<strong>\u6784\u5efa Redis Key<\/strong>\uff1a\u5c06\u63d0\u53d6\u7684 <code>templateId<\/code> \u8f6c\u6362\u4e3a Redis \u4e2d\u5b58\u50a8\u4f18\u60e0\u5238\u6a21\u677f\u6570\u636e\u7684\u5b8c\u6574 Key\uff08\u4f8b\u5982 <code>prefix_couponTemplate_{templateId}<\/code>\uff09\u3002<\/li>\n\n\n\n<li>3.<strong>\u751f\u6210 Redis Key \u5217\u8868<\/strong>\uff1a\u6700\u7ec8\u5f97\u5230\u4e00\u4e2a <code>List&lt;String><\/code> \u7c7b\u578b\u7684 Redis Key \u5217\u8868\uff0c\u51c6\u5907\u4ece Redis \u4e2d\u6279\u91cf\u83b7\u53d6\u4f18\u60e0\u5238\u6a21\u677f\u7684\u8be6\u7ec6\u4fe1\u606f\u3002<\/li>\n\n\n\n<li>4.<strong>\u4f7f\u7528 Redis Pipeline \u6279\u91cf\u83b7\u53d6\u6570\u636e<\/strong>\uff1a\u901a\u8fc7 <code>stringRedisTemplate.executePipelined<\/code> \u65b9\u6cd5\uff0c\u4f7f\u7528 Redis \u7ba1\u9053\uff08Pipeline\uff09\u6280\u672f\u6279\u91cf\u83b7\u53d6 Redis \u4e2d\u7684\u4f18\u60e0\u5238\u6a21\u677f\u4fe1\u606f\u3002\u8fd9\u6837\u505a\u80fd\u591f\u51cf\u5c11\u4e0e Redis \u670d\u52a1\u5668\u7684\u7f51\u7edc\u4ea4\u4e92\u6b21\u6570\uff0c\u63d0\u9ad8\u8bfb\u53d6\u6027\u80fd\u3002<\/li>\n\n\n\n<li>5.<strong>\u6570\u636e\u8f6c\u6362<\/strong>\uff1a\u901a\u8fc7 <code>JSON.parseArray<\/code> \u65b9\u6cd5\uff0c\u5c06 <code>couponTemplateList<\/code> \u8f6c\u6362\u4e3a <code>CouponTemplateQueryRespDTO<\/code> \u5bf9\u8c61\u5217\u8868\u3002<\/li>\n\n\n\n<li>6.<strong>\u6309 <code>goods<\/code> \u5b57\u6bb5\u5206\u533a<\/strong>\uff1a\u4f7f\u7528 <code>Collectors.partitioningBy<\/code> \u65b9\u6cd5\uff0c\u5c06\u4f18\u60e0\u5238\u6a21\u677f\u5217\u8868\u5206\u4e3a\u4e24\u90e8\u5206\uff1a<code>true<\/code>\uff1a<code>goods<\/code> \u5b57\u6bb5\u4e3a\u7a7a\u7684\u4f18\u60e0\u5238\u6a21\u677f\uff0c\u8868\u793a\u8be5\u4f18\u60e0\u5238\u662f\u5e73\u53f0\u5238\u6216\u5e97\u94fa\u5238\uff08\u6ca1\u6709\u7279\u5b9a\u5546\u54c1\u9650\u5236\uff09\u3002<code>false<\/code>\uff1a<code>goods<\/code> \u5b57\u6bb5\u4e0d\u4e3a\u7a7a\u7684\u4f18\u60e0\u5238\u6a21\u677f\uff0c\u8868\u793a\u8be5\u4f18\u60e0\u5238\u662f\u5546\u54c1\u4e13\u5c5e\u5238\uff08\u53ea\u80fd\u7528\u4e8e\u7279\u5b9a\u5546\u54c1\uff09\u3002<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"3\">3. \u8ba1\u7b97\u6298\u6263\u91d1\u989d<\/h3>\n\n\n\n<p>\u63a5\u4e0b\u6765\u5c31\u662f\u901a\u8fc7\u4f18\u60e0\u5238\u7684\u4f7f\u7528\u6761\u4ef6\u4ee5\u53ca\u51cf\u514d\u7c7b\u578b\u7b49\u8ba1\u7b97\u8ba2\u5355\u51cf\u514d\u91d1\u989d\u3002<\/p>\n\n\n\n<p>\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>publicQueryCouponsRespDTOlistQueryUserCouponsBySync(QueryCouponsReqDTO requestParam){\/\/ .....\n\u200b\n &nbsp; &nbsp;\/\/ \u9488\u5bf9\u5f53\u524d\u8ba2\u5355\u53ef\u7528\/\u4e0d\u53ef\u7528\u7684\u4f18\u60e0\u5238\u5217\u8868List&lt;QueryCouponsDetailRespDTO&gt; availableCouponList =newArrayList&lt;&gt;();List&lt;QueryCouponsDetailRespDTO&gt; notAvailableCouponList =newArrayList&lt;&gt;();\n\u200b\n &nbsp; &nbsp;goodsEmptyList.forEach(each -&gt;{JSONObject jsonObject =JSON.parseObject(each.getConsumeRule());QueryCouponsDetailRespDTO resultQueryCouponDetail =BeanUtil.toBean(each,QueryCouponsDetailRespDTO.class);BigDecimal maximumDiscountAmount = jsonObject.getBigDecimal(\"maximumDiscountAmount\");switch(each.getType()){case0:\/\/ \u7acb\u51cf\u5238\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;resultQueryCouponDetail.setCouponAmount(maximumDiscountAmount);\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;availableCouponList.add(resultQueryCouponDetail);break;case1:\/\/ \u6ee1\u51cf\u5238\/\/ orderAmount \u5927\u4e8e\u6216\u7b49\u4e8e termsOfUseif(requestParam.getOrderAmount().compareTo(jsonObject.getBigDecimal(\"termsOfUse\"))&gt;=0){\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;resultQueryCouponDetail.setCouponAmount(maximumDiscountAmount);\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;availableCouponList.add(resultQueryCouponDetail);}else{\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;notAvailableCouponList.add(resultQueryCouponDetail);}break;case2:\/\/ \u6298\u6263\u5238\/\/ orderAmount \u5927\u4e8e\u6216\u7b49\u4e8e termsOfUseif(requestParam.getOrderAmount().compareTo(jsonObject.getBigDecimal(\"termsOfUse\"))&gt;=0){BigDecimal multiply = requestParam.getOrderAmount().multiply(jsonObject.getBigDecimal(\"discountRate\"));if(multiply.compareTo(maximumDiscountAmount)&gt;=0){\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;resultQueryCouponDetail.setCouponAmount(maximumDiscountAmount);}else{\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;resultQueryCouponDetail.setCouponAmount(multiply);}\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;availableCouponList.add(resultQueryCouponDetail);}else{\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;notAvailableCouponList.add(resultQueryCouponDetail);}break;default:thrownewClientException(\"\u65e0\u6548\u7684\u4f18\u60e0\u5238\u7c7b\u578b\");}});\n\u200b\n &nbsp; &nbsp;Map&lt;String, QueryCouponGoodsReqDTO&gt; goodsRequestMap = requestParam.getGoodsList().stream().collect(Collectors.toMap(QueryCouponGoodsReqDTO::getGoodsNumber,Function.identity(),(existing, replacement)-&gt; existing));\n\u200b\n &nbsp; &nbsp;goodsNotEmptyList.forEach(each -&gt;{QueryCouponGoodsReqDTO couponGoods = goodsRequestMap.get(each.getGoods());if(couponGoods ==null){\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;notAvailableCouponList.add(BeanUtil.toBean(each,QueryCouponsDetailRespDTO.class));}JSONObject jsonObject =JSON.parseObject(each.getConsumeRule());QueryCouponsDetailRespDTO resultQueryCouponDetail =BeanUtil.toBean(each,QueryCouponsDetailRespDTO.class);switch(each.getType()){case0:\/\/ \u7acb\u51cf\u5238\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;resultQueryCouponDetail.setCouponAmount(jsonObject.getBigDecimal(\"maximumDiscountAmount\"));\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;availableCouponList.add(resultQueryCouponDetail);break;case1:\/\/ \u6ee1\u51cf\u5238\/\/ goodsAmount \u5927\u4e8e\u6216\u7b49\u4e8e termsOfUseif(couponGoods.getGoodsAmount().compareTo(jsonObject.getBigDecimal(\"termsOfUse\"))&gt;=0){\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;resultQueryCouponDetail.setCouponAmount(jsonObject.getBigDecimal(\"maximumDiscountAmount\"));\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;availableCouponList.add(resultQueryCouponDetail);}else{\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;notAvailableCouponList.add(resultQueryCouponDetail);}break;case2:\/\/ \u6298\u6263\u5238\/\/ goodsAmount \u5927\u4e8e\u6216\u7b49\u4e8e termsOfUseif(couponGoods.getGoodsAmount().compareTo(jsonObject.getBigDecimal(\"termsOfUse\"))&gt;=0){BigDecimal discountRate = jsonObject.getBigDecimal(\"discountRate\");\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;resultQueryCouponDetail.setCouponAmount(couponGoods.getGoodsAmount().multiply(discountRate));\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;availableCouponList.add(resultQueryCouponDetail);}else{\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;notAvailableCouponList.add(resultQueryCouponDetail);}break;default:thrownewClientException(\"\u65e0\u6548\u7684\u4f18\u60e0\u5238\u7c7b\u578b\");}});\n\u200b\n &nbsp; &nbsp;\/\/ \u4e0e\u4e1a\u5185\u6807\u51c6\u4e00\u81f4\uff0c\u6309\u6700\u7ec8\u4f18\u60e0\u529b\u5ea6\u4ece\u5927\u5230\u5c0f\u6392\u5e8f\n &nbsp; &nbsp;availableCouponList.sort((c1, c2)-&gt; c2.getCouponAmount().compareTo(c1.getCouponAmount()));\n\u200b\n &nbsp; &nbsp;returnQueryCouponsRespDTO.builder().availableCouponList(availableCouponList).notAvailableCouponList(notAvailableCouponList).build();}<\/code><\/pre>\n\n\n\n<p><strong>\u5b9a\u4e49\u53ef\u7528\u548c\u4e0d\u53ef\u7528\u7684\u4f18\u60e0\u5238\u5217\u8868<\/strong>\uff0c\u7528\u4e8e\u5b58\u50a8\u5f53\u524d\u8ba2\u5355\u53ef\u7528\u4ee5\u53ca\u4e0d\u53ef\u7528\u7684\u4f18\u60e0\u5238\u5217\u8868\u3002\u7136\u540e\u6211\u4eec\u5206\u4e3a\u4e24\u4e2a\u7c7b\u578b\u903b\u8f91\u89e3\u6790\uff0c\u5206\u522b\u662f\u5168\u5e97\u53ef\u7528\u4ee5\u53ca\u90e8\u5206\u5546\u54c1\u53ef\u7528\u3002<\/p>\n\n\n\n<p>\u5168\u5e97\u53ef\u7528\u7684\u4f18\u60e0\u5238\u8ba1\u7b97\u903b\u8f91\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>1.\u904d\u5386 <code>goodsEmptyList<\/code>\uff0c\u6839\u636e\u8ba2\u5355\u91d1\u989d\u5224\u65ad\u4f18\u60e0\u5238\u662f\u5426\u53ef\u7528\uff1b<\/li>\n\n\n\n<li>2.<strong>\u4f18\u60e0\u5238\u7c7b\u578b\u5224\u65ad<\/strong>\uff1a\u6839\u636e <code>each.getType()<\/code> \u5224\u65ad\u4f18\u60e0\u5238\u7684\u7c7b\u578b\uff0c\u5e76\u6839\u636e\u4e0d\u540c\u7c7b\u578b\u8bbe\u7f6e <code>resultQueryCouponDetail<\/code> \u4e2d\u7684\u4f18\u60e0\u91d1\u989d\uff08<code>couponAmount<\/code>\uff09\uff1b\n<ul class=\"wp-block-list\">\n<li><code>\u7acb\u51cf\u5238\uff08type = 0\uff09<\/code>\uff1a\u76f4\u63a5\u5c06 <code>maximumDiscountAmount<\/code> \u4f5c\u4e3a\u4f18\u60e0\u91d1\u989d\uff1b<\/li>\n\n\n\n<li><code>\u6ee1\u51cf\u5238\uff08type = 1\uff09<\/code>\uff1a\u5982\u679c\u8ba2\u5355\u91d1\u989d\u5927\u4e8e\u7b49\u4e8e <code>termsOfUse<\/code>\uff0c\u5219\u5c06 <code>maximumDiscountAmount<\/code> \u4f5c\u4e3a\u4f18\u60e0\u91d1\u989d\uff0c\u5426\u5219\u52a0\u5165\u4e0d\u53ef\u7528\u5217\u8868\uff1b<\/li>\n\n\n\n<li><code>\u6298\u6263\u5238\uff08type = 2\uff09<\/code>\uff1a\u5982\u679c\u8ba2\u5355\u91d1\u989d\u5927\u4e8e\u7b49\u4e8e <code>termsOfUse<\/code>\uff0c\u5219\u4f7f\u7528\u6298\u6263\u6bd4\u4f8b\u8ba1\u7b97\u4f18\u60e0\u91d1\u989d\uff0c\u5e76\u53d6 <code>maximumDiscountAmount<\/code> \u548c\u8ba1\u7b97\u7ed3\u679c\u4e2d\u7684\u6700\u5c0f\u503c\u4f5c\u4e3a\u6700\u7ec8\u4f18\u60e0\u91d1\u989d\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p>\u90e8\u5206\u5546\u54c1\u53ef\u7528\u7684\u4f18\u60e0\u5238\u8ba1\u7b97\u903b\u8f91\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>1.<strong>\u6784\u5efa\u5546\u54c1\u7f16\u53f7\u5230\u5546\u54c1\u8bf7\u6c42\u5bf9\u8c61\u7684\u6620\u5c04<\/strong>\uff1a\u5c06\u8bf7\u6c42\u53c2\u6570\u4e2d\u7684\u5546\u54c1\u5217\u8868 <code>requestParam.getGoodsList()<\/code> \u8f6c\u6362\u4e3a\u4e00\u4e2a <code>Map&lt;String, QueryCouponGoodsReqDTO><\/code>\uff0c\u5176\u4e2d <code>goodsNumber<\/code> \u4f5c\u4e3a Key\uff0c<code>QueryCouponGoodsReqDTO<\/code> \u5bf9\u8c61\u4f5c\u4e3a Value\uff1b<\/li>\n\n\n\n<li>2.\u904d\u5386 <code>goodsNotEmptyList<\/code>\uff0c\u6839\u636e\u5546\u54c1\u4fe1\u606f\u5224\u65ad\u4f18\u60e0\u5238\u662f\u5426\u53ef\u7528\uff1b<\/li>\n\n\n\n<li>3.<strong>\u89e3\u6790\u4f18\u60e0\u5238\u6d88\u8d39\u89c4\u5219<\/strong>\uff1a\u5c06 <code>each<\/code> \u8f6c\u6362\u4e3a <code>QueryCouponsDetailRespDTO<\/code> \u5bf9\u8c61\uff0c\u5e76\u89e3\u6790 <code>consumeRule<\/code> \u5b57\u6bb5\uff0c\u83b7\u53d6\u4f18\u60e0\u5238\u7684\u8be6\u7ec6\u89c4\u5219\u4fe1\u606f\uff1b<\/li>\n\n\n\n<li>4.<strong>\u4f18\u60e0\u5238\u7c7b\u578b\u5224\u65ad<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li><code>\u7acb\u51cf\u5238\uff08type = 0\uff09<\/code>\uff1a\u76f4\u63a5\u5c06\u6700\u5927\u4f18\u60e0\u91d1\u989d\u8bbe\u7f6e\u4e3a\u4f18\u60e0\u91d1\u989d\u3002<\/li>\n\n\n\n<li><code>\u6ee1\u51cf\u5238\uff08type = 1\uff09<\/code>\uff1a\u5982\u679c\u5546\u54c1\u91d1\u989d\u5927\u4e8e\u7b49\u4e8e <code>termsOfUse<\/code>\uff0c\u5219\u4f18\u60e0\u6709\u6548\uff0c\u5426\u5219\u52a0\u5165\u4e0d\u53ef\u7528\u5217\u8868\u3002<\/li>\n\n\n\n<li><code>\u6298\u6263\u5238\uff08type = 2\uff09<\/code>\uff1a\u5982\u679c\u5546\u54c1\u91d1\u989d\u5927\u4e8e\u7b49\u4e8e <code>termsOfUse<\/code>\uff0c\u5219\u4f7f\u7528\u6298\u6263\u6bd4\u4f8b\u8ba1\u7b97\u4f18\u60e0\u91d1\u989d\uff0c\u5e76\u52a0\u5165\u53ef\u7528\u5217\u8868\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p>\u5c06\u4e0a\u8ff0\u903b\u8f91\u5b8c\u6210\u540e\uff0c\u5bf9 <code>availableCouponList<\/code> \u4e2d\u7684\u6240\u6709\u53ef\u7528\u4f18\u60e0\u5238\u6309 <code>couponAmount<\/code> \u8fdb\u884c\u964d\u5e8f\u6392\u5e8f\uff08\u4f18\u60e0\u529b\u5ea6\u4ece\u5927\u5230\u5c0f\uff09\u3002\u6700\u7ec8\u6784\u5efa\u8fd4\u56de\u5bf9\u8c61\uff0c\u81f3\u6b64\uff0c\u83b7\u53d6\u7528\u6237\u53ef\u7528\/\u4e0d\u53ef\u7528\u4f18\u60e0\u5238\u76f8\u5173\u903b\u8f91\u67e5\u8be2\u5b8c\u6210\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u529f\u80fd\u6d4b\u8bd5<\/h2>\n\n\n\n<p>\u4ee3\u7801\u5176\u5b9e\u7406\u89e3\u8d77\u6765\u5e76\u4e0d\u96be\uff0c\u4f46\u662f\u95ee\u9898\u96be\u5728\u54ea\uff1f\u96be\u5c31\u96be\u5728\u6d4b\u8bd5\u5e76\u4e0d\u597d\u6784\u9020\u6570\u636e\u3002\u4e3a\u6b64\uff0c\u6211\u63d0\u4f9b\u4e86\u5355\u5143\u6d4b\u8bd5\u6784\u9020\u76f8\u5173\u6570\u636e\u4ee5\u53ca\u76f8\u5173\u7684\u8bf7\u6c42\u5165\u53c2\uff0c\u5927\u5bb6\u53ef\u4ee5\u6309\u7167\u6d41\u7a0b\u8fdb\u884c\u6d4b\u8bd5\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"1\">1. \u6267\u884c\u5355\u5143\u6d4b\u8bd5<\/h3>\n\n\n\n<p>\u9996\u5148\u5728\u540e\u7ba1\u670d\u52a1 merchant-admin \u5355\u5143\u6d4b\u8bd5\u4e2d\u641c\u7d22\u8fd9\u4e2a\u65b9\u6cd5\uff0c\u6267\u884c\u4e00\u6b21\u540e\u5e94\u8be5\u662f\u62a5\u9519\u7684\uff0c\u7136\u540e\u4fee\u6539 -ea \u53c2\u6570\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>MockSettlementCouponTemplateDataTests#mockCouponTemplateTest<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/article-images.zsxq.com\/FiTC1Ipr1hoXqR8MHy_0W46edhJT\" alt=\"image.png\" title=\"image.png\"\/><\/figure>\n\n\n\n\n\n<p>\u7136\u540e\u518d\u6267\u884c\u5e94\u8be5\u5c31\u662f\u6210\u529f\u7684\uff0c\u4e3a\u6b64\uff0c\u6211\u4eec\u7684\u4f18\u60e0\u5238\u6a21\u677f\u8bb0\u5f55\u662f\u5df2\u7ecf\u521d\u59cb\u5316\u5b8c\u6210\u4e86\u3002<\/p>\n\n\n\n<p>\u5171\u521d\u59cb\u5316\u4e86 5 \u4e2a\u4f18\u60e0\u5238\u6a21\u677f\uff0c\u5bf9\u5e94\u7684\u89c4\u5219\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u4f18\u60e0\u52381\n\u200b\n- \u4f18\u60e0\u7c7b\u578b\uff1a\u7acb\u51cf\u5238\n- \u4f18\u60e0\u5bf9\u8c61\uff1a\u5e97\u94fa\u5238\n- \u4f18\u60e0\u91d1\u989d\uff1a\u7acb\u51cf 10 \u5143\n\u200b\n\u4f18\u60e0\u52382\n\u200b\n- \u4f18\u60e0\u7c7b\u578b\uff1a\u7acb\u51cf\u5238\n- \u4f18\u60e0\u5bf9\u8c61\uff1a\u5546\u54c1\u5238 001\n- \u4f18\u60e0\u91d1\u989d\uff1a\u7acb\u51cf 3 \u5143\n\u200b\n\u4f18\u60e0\u52383\n\u200b\n- \u4f18\u60e0\u7c7b\u578b\uff1a\u6ee1\u51cf\u5238\n- \u4f18\u60e0\u5bf9\u8c61\uff1a\u5e97\u94fa\u5238\n- \u4f18\u60e0\u91d1\u989d\uff1a\u7acb\u51cf 10 \u5143\n- \u9700\u8981\u6ee1\u8db3\u6761\u4ef6\uff1a\u91d1\u989d\u6ee1\u8db3 100 \u5143\n\u200b\n\u4f18\u60e0\u52384\n\u200b\n- \u4f18\u60e0\u7c7b\u578b\uff1a\u6298\u6263\u5238\n- \u4f18\u60e0\u5bf9\u8c61\uff1a\u5e97\u94fa\u5238\n- \u6298\u6263\uff1a0.6 \u6298\n- \u6700\u5927\u4f18\u60e0\u91d1\u989d\uff1a20 \u5143\n- \u9700\u8981\u6ee1\u8db3\u6761\u4ef6\uff1a\u91d1\u989d\u6ee1\u8db3 100 \u5143\n\u200b\n\u4f18\u60e0\u52385\n\u200b\n- \u4f18\u60e0\u7c7b\u578b\uff1a\u6298\u6263\u5238\n- \u4f18\u60e0\u5bf9\u8c61\uff1a\u5e97\u94fa\u5238\n- \u6298\u6263\uff1a0.6 \u6298\n- \u6700\u5927\u4f18\u60e0\u91d1\u989d\uff1a40 \u5143\n- \u9700\u8981\u6ee1\u8db3\u6761\u4ef6\uff1a\u91d1\u989d\u6ee1\u8db3 300 \u5143<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"2\">2. \u6267\u884c\u7528\u6237\u5151\u6362\u4f18\u60e0\u5238<\/h3>\n\n\n\n<p>\u4f18\u60e0\u5238\u6a21\u677f\u521b\u5efa\u597d\u4e86\uff0c\u6211\u4eec\u8981\u5f00\u59cb\u6267\u884c\u7528\u6237\u5151\u6362\u4f18\u60e0\u5238\u6a21\u677f\u3002\u8bbf\u95ee\u4e0b\u8ff0\u5730\u5740\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"http:\/\/127.0.0.1:10020\/doc.html#\/default\/%E7%94%A8%E6%88%B7%E4%BC%98%E6%83%A0%E5%88%B8%E7%AE%A1%E7%90%86\/redeemUserCoupon\" target=\"_blank\" rel=\"noreferrer noopener\" rel=\"nofollow\" >http:\/\/127.0.0.1:10020\/doc.html#\/default\/%E7%94%A8%E6%88%B7%E4%BC%98%E6%83%A0%E5%88%B8%E7%AE%A1%E7%90%86\/redeemUserCoupon<\/a><\/li>\n<\/ul>\n\n\n\n<p>\u7136\u540e\u5c06\u4e0b\u8ff0\u8bf7\u6c42\u53c2\u6570\u7684 <code>couponTemplateId<\/code> \u66ff\u6362\u4e3a\u521a\u624d\u521b\u5efa\u7684 5 \u4e2a\u4f18\u60e0\u5238\u6a21\u677f ID \u5373\u53ef\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\"source\":0,\"shopNumber\":\"1810714735922956666\",\"couponTemplateId\":\"xxx\"}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"3\">3. \u6267\u884c\u67e5\u8be2\u7528\u6237\u4f18\u60e0\u5238\u63a5\u53e3<\/h3>\n\n\n\n<p>\u8bbf\u95ee\u4e0b\u8ff0\u5730\u5740\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/t.zsxq.com\/pAWgS\" target=\"_blank\" rel=\"noreferrer noopener\" rel=\"nofollow\" >http:\/\/127.0.0.1:10030\/doc.html#\/default\/%E6%9F%A5%E8%AF%A2%E7%94%A8%E6%88%B7%E4%BC%98%E6%83%A0%E5%88%B8%E7%AE%A1%E7%90%86\/listQueryCouponsBySync<\/a><\/li>\n<\/ul>\n\n\n\n<p>\u7136\u540e\u5c06\u4e0b\u8ff0\u53c2\u6570\u5bf9\u5e94\u6570\u636e\u653e\u5165\u8bf7\u6c42\u53c2\u6570\u4e2d\uff0c\u5373\u53ef\u5b8c\u6210\u63a5\u53e3\u8bbf\u95ee\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u8ba2\u5355\u91d1\u989d 226<\/li>\n\n\n\n<li>\u5546\u54c11\u91d1\u989d 80 \u7f16\u7801\uff1a001<\/li>\n\n\n\n<li>\u5546\u54c12\u91d1\u989d 26 \u7f16\u7801\uff1a002<\/li>\n\n\n\n<li>\u5546\u54c13\u91d1\u989d 100 \u7f16\u7801\uff1a003<\/li>\n<\/ul>\n\n\n\n<p>Post \u63a5\u53e3 JSON \u8bf7\u6c42\u6570\u636e\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\"orderAmount\":226,\"shopNumber\":\"1810714735922956666\",\"goodsList\":&#91;{\"goodsNumber\":\"001\",\"goodsAmount\":80},{\"goodsNumber\":\"002\",\"goodsAmount\":26},{\"goodsNumber\":\"003\",\"goodsAmount\":100}]}<\/code><\/pre>\n\n\n\n<p>\u7406\u8bba\u4e0a\uff0c\u6211\u4eec\u53ea\u6709\u4f18\u60e0\u52385\u7684\u6298\u6263\u5238\u4e0d\u80fd\u4f7f\u7528\uff0c\u5176\u4ed6\u90fd\u662f\u53ef\u4f7f\u7528\u7684\u3002\u4e3a\u4e86\u9a8c\u8bc1\u731c\u60f3\uff0c\u6211\u4eec\u8c03\u7528\u4e0b\u83b7\u53d6\u7528\u6237\u4f18\u60e0\u5238\u5217\u8868\u63a5\u53e3\u8fdb\u884c\u6d4b\u8bd5\u3002<\/p>\n\n\n\n<p>\u8fd4\u56de\u6570\u636e\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\"code\":\"0\",\"message\":null,\"data\":{\"availableCouponList\":&#91;{\"id\":\"1843290380169883650\",\"target\":1,\"goods\":null,\"type\":2,\"consumeRule\":\"{\\\"termsOfUse\\\":100,\\\"maximumDiscountAmount\\\":20,\\\"explanationOfUnmetConditions\\\":\\\"3\\\",\\\"discountRate\\\":\\\"0.6\\\",\\\"validityPeriod\\\":48}\",\"couponAmount\":20},{\"id\":\"1843290379737870337\",\"target\":1,\"goods\":null,\"type\":1,\"consumeRule\":\"{\\\"termsOfUse\\\":100,\\\"maximumDiscountAmount\\\":10,\\\"explanationOfUnmetConditions\\\":\\\"3\\\",\\\"validityPeriod\\\":48}\",\"couponAmount\":10},{\"id\":\"1843290372464947202\",\"target\":1,\"goods\":null,\"type\":0,\"consumeRule\":\"{\\\"maximumDiscountAmount\\\":10,\\\"explanationOfUnmetConditions\\\":\\\"3\\\",\\\"validityPeriod\\\":48}\",\"couponAmount\":10},{\"id\":\"1843290379234553857\",\"target\":0,\"goods\":\"001\",\"type\":0,\"consumeRule\":\"{\\\"maximumDiscountAmount\\\":3,\\\"explanationOfUnmetConditions\\\":\\\"3\\\",\\\"validityPeriod\\\":48}\",\"couponAmount\":3}],\"notAvailableCouponList\":&#91;{\"id\":\"1843290380593508353\",\"target\":1,\"goods\":null,\"type\":2,\"consumeRule\":\"{\\\"termsOfUse\\\":300,\\\"maximumDiscountAmount\\\":40,\\\"explanationOfUnmetConditions\\\":\\\"3\\\",\\\"discountRate\\\":\\\"0.6\\\",\\\"validityPeriod\\\":48}\",\"couponAmount\":null}]},\"requestId\":null,\"success\":true,\"fail\":false}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u6587\u672b\u603b\u7ed3<\/h2>\n\n\n\n<p>\u672c\u7ae0\u8282\u901a\u8fc7\u89e3\u6790\u7528\u6237\u7684\u8ba2\u5355\u4fe1\u606f\uff0c\u5b9e\u73b0\u5728\u8ba2\u5355\u7ed3\u7b97\u65f6\u6839\u636e\u4f18\u60e0\u5238\u7684\u4e0d\u540c\u7c7b\u578b\uff08\u7acb\u51cf\u5238\u3001\u6ee1\u51cf\u5238\u3001\u6298\u6263\u5238\uff09\u8fdb\u884c\u5206\u7c7b\u548c\u4f18\u60e0\u91d1\u989d\u8ba1\u7b97\u3002\u6574\u4e2a\u8fc7\u7a0b\u6d89\u53ca\u5230 Redis \u6570\u636e\u83b7\u53d6\u3001\u6570\u636e\u5206\u533a\u3001\u6d88\u8d39\u89c4\u5219\u89e3\u6790\u548c\u91d1\u989d\u8ba1\u7b97\u7b49\u591a\u79cd\u64cd\u4f5c\u3002\u901a\u8fc7\u5355\u5143\u6d4b\u8bd5\uff0c\u6211\u4eec\u9a8c\u8bc1\u4e86\u5404\u79cd\u4f18\u60e0\u5238\u5728\u4e0d\u540c\u8ba2\u5355\u91d1\u989d\u548c\u5546\u54c1\u7ec4\u5408\u4e0b\u7684\u4f7f\u7528\u89c4\u5219\u548c\u4f18\u5148\u7ea7\u3002<\/p>\n\n\n\n<p>\u76ee\u524d\u8fd8\u6709\u4e00\u4e2a\u95ee\u9898\uff0c\u5c31\u662f\u5982\u679c\u7528\u6237\u9886\u53d6\u4f18\u60e0\u5238\u6bd4\u8f83\u591a\u7684\u60c5\u51b5\u4e0b\uff0c\u540c\u6b65\u67e5\u8be2\u53ef\u80fd\u4f1a\u8f83\u6162\u4e00\u4e9b\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u591a\u7ebf\u7a0b\u65b9\u5f0f\u8fdb\u884c\u4f18\u5316\uff0c\u8fd9\u4e2a\u5c06\u5728\u4e0b\u4e00\u7ae0\u8282\u8bf4\u660e\u3002<\/p>\n\n\n\n<p>\u5b8c\u7ed3\uff0c\u6492\u82b1 \ud83c\udf89<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u8fd9\u4e9b\u4ee3\u7801\u662f\u4e0d\u662f\u5e94\u8be5\u653e\u5728else\u91cc\u5440<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"766\" src=\"https:\/\/eve2333.top\/wp-content\/uploads\/2025\/09\/1758384891-image-1024x766.png\" alt=\"\" class=\"wp-image-1319\" srcset=\"https:\/\/eve2333.top\/wp-content\/uploads\/2025\/09\/1758384891-image-1024x766.png 1024w, https:\/\/eve2333.top\/wp-content\/uploads\/2025\/09\/1758384891-image-300x224.png 300w, https:\/\/eve2333.top\/wp-content\/uploads\/2025\/09\/1758384891-image-768x575.png 768w, https:\/\/eve2333.top\/wp-content\/uploads\/2025\/09\/1758384891-image.png 1163w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u8bf7\u95ee\u67e5\u8be2\u51fa\u4f18\u60e0\u5238\u5217\u8868\u7684\u4fe1\u606f\u4ee5\u540e\uff0c\u662f\u5426\u8981\u5148\u5224\u65ad\u4f18\u60e0\u5238\u7684\u5e97\u94fa\u7f16\u53f7\u662f\u5426\u7b49\u4e8e\u5f53\u524d\u7684\u5e97\u94fa\u7f16\u53f7\uff0c\u5982\u679c\u4e0d\u7b49\u4e8e\u76f4\u63a5\u52a0\u5165\u4e0d\u53ef\u7528\u5217\u8868\uff1f<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"461\" src=\"https:\/\/eve2333.top\/wp-content\/uploads\/2025\/09\/1758384907-image-1024x461.png\" alt=\"\" class=\"wp-image-1320\" srcset=\"https:\/\/eve2333.top\/wp-content\/uploads\/2025\/09\/1758384907-image-1024x461.png 1024w, https:\/\/eve2333.top\/wp-content\/uploads\/2025\/09\/1758384907-image-300x135.png 300w, https:\/\/eve2333.top\/wp-content\/uploads\/2025\/09\/1758384907-image-768x346.png 768w, https:\/\/eve2333.top\/wp-content\/uploads\/2025\/09\/1758384907-image.png 1168w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u6211\u7684\u7406\u89e3\u662f\u4e00\u4e2a\u4eba\u7684\u4f18\u60e0\u5238\u5217\u8868\u4f1a\u5217\u51fa\u6240\u6709\u7684\u4f18\u60e0\u5238\uff0c\u5206\u5e97\u94fa\u5c31\u662f\u6709\u6761\u4ef6\u7684\u641c\u7d22\u4e86<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u83b7\u53d6rawCouponDataList\u662f\u4e0d\u662f\u5c11\u4e86\u5224\u7a7a\u903b\u8f91\u5462\uff1f\u53ef\u80fd\u7528\u6237\u9886\u53d6\u7684\u4f18\u60e0\u5238\u4e2d\u6709\u7684\u5df2\u7ecf\u8fc7\u671f\uff0c\u7f13\u5b58\u4e2d\u6ca1\u6709\u5c31\u4f1a\u5bfc\u81f4\u8fd4\u56de\u7a7a\u5b57\u5178{}\uff0c\u90a3\u5728\u540e\u9762\u83b7\u53d6\u6d88\u8d39\u89c4\u5219consumRule\u65f6\u5c31\u662fnull\uff0c\u4f20\u5165handleCouponLogic\u65b9\u6cd5\u83b7\u53d6\"termsOfUse\"\u5c31\u4f1a\u62a5\u9519\u3002<\/p>\n\n\n\n<p>int main()&nbsp;\u56de\u590d&nbsp;\u80cc\u5355\u8bcd\uff1a\u4e0d\u662f\u7f13\u5b58\u6ca1\u6709\uff0c\u662fkey\u9519\u4e86\uff0c\u4f60\u53ef\u4ee5debug\uff0ckey\u591a\u4e86null<\/p>\n\n\n\n<p>\u80cc\u5355\u8bcd&nbsp;\u56de\u590d&nbsp;int main()\uff1a\u6211\u53bb\u8fd8\u771f\u662f\uff0cnullone-coupon_engine:template:1891478133355298818\u3002\u591a\u4e86null<\/p>\n\n\n\n<p>int main()&nbsp;\u56de\u590d&nbsp;\u80cc\u5355\u8bcd\uff1a\u540e\u9762\u8fd8\u6709\u95ee\u9898\u5462\uff0c\u5c31\u662f\u5b58\u5165redis\u91cc\u9762\u7684\u4f18\u60e0\u5238\u6a21\u677f\u7684\u65f6\u95f4\u683c\u5f0f\uff0c\u5f97\u6539\u4e00\u4e0b\uff0c\u8981\u4e0d\u7136\u8fd8\u662f\u4f1a\u62a5\u9519<\/p>\n\n\n\n<p>int main()&nbsp;\u56de\u590d&nbsp;\u80cc\u5355\u8bcd\uff1a\u5176\u5b9e\u63a5\u53e3\u5e42\u7b49\u6ce8\u89e3\u4e5f\u6709\u95ee\u9898\uff0c\u4f60\u7528jmeter\u6d4b\u4e00\u4e0b\uff0c\u4e00\u4e2a\u7ebf\u7a0b\uff0c\u4e00\u79d2\u5faa\u73af10\u6b21\uff0c\u6d4b\u8bd5\u7ed3\u679c\u662f\u5341\u6b21\u90fd\u662f\u6210\u529f\u7684\uff0c\u4f46\u662f\u7406\u8bba\u4e0a\u8fd9\u4e2a\u5c5e\u4e8e\u91cd\u590d\u8bf7\u6c42\uff0c\u5e94\u8be5\u53ea\u6709\u4e00\u6b21\u6210\u529f\u3002<\/p>\n\n\n\n<p>\u82b1\u5f00\u5bcc\u8d35&nbsp;\u56de\u590d&nbsp;\u80cc\u5355\u8bcd\uff1a\u9a6c\u54e5\u4e4b\u524d\u5728\u79d2\u6740\u90a3\u5757\u521b\u5efa\u4e86Redis Key \u5e8f\u5217\u5316\u5668\uff0c\u53ef\u81ea\u5b9a\u4e49 Key Prefix\uff0c\u5982\u679c\u6ca1\u4f7f\u7528\u7684\u8bdd\uff0c\u9700\u8981\u5c06CouponQueryServiceImpl\u7c7b\u4e2d\u4f7f\u7528redisDistributedProperties.getPrefix() \u7684\u5730\u65b9\u7ed9\u6ce8\u6389\uff0c\u5426\u5219couponTemplateIds\u91cc\u9762\u7684key\u90fd\u662f\u4ee5null\u5f00\u5934\u7684<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u9a6c\u54e5\uff0c\u83b7\u53d6\u4f18\u60e0\u5238\u6a21\u7248\u8be6\u60c5\u90fd\u662f\u5728\u7f13\u5b58\u4e2d\u83b7\u53d6\u7684\u3002\u8fd9\u80fd\u4fdd\u8bc1\u6a21\u7248\u4e00\u5b9a\u5728\u7f13\u5b58\u4e2d\u5417\uff1f \u6211\u7684\u7406\u89e3\u662f\u8981redis\u83b7\u53d6\u4e00\u8fb9\uff0c\u7136\u540e\u68c0\u7d22\u54ea\u4e9b\u6ca1\u62ff\u5230\uff0c\u518d\u53bbdb\u62ff\u4e00\u904d<\/p>\n\n\n\n<p>\u7b2c\u2074\u7eaa\u51b0\u5ddd&nbsp;\u56de\u590d&nbsp;X-in\uff1a\u6211\u611f\u89c9\u4e0d\u80fd\u4fdd\u8bc1\uff0c\u4e00\u4e2a\u662f\u5185\u5b58\u6dd8\u6c70\u7b56\u7565\uff0c\u8fd8\u6709\u5c31\u662f\u53ef\u80fd\u4f18\u60e0\u5238\u6a21\u677f\u8fc7\u671f\u4e86\uff0c\u4f46\u662f\u7528\u6237\u4f18\u60e0\u5238\u8fd8\u6ca1\u8fc7\u671f(\u7528\u6237\u9886\u4e86\u5238\u6709\u4e00\u4e2a\u8fc7\u671f\u65f6\u95f4)\uff0c\u4f46\u662f\u8981\u662f\u8003\u8651\u8fd9\u4e2a\u95ee\u9898\uff0c\u5f97\u6539\u5f88\u591a\u4ee3\u7801\uff0c\u56e0\u4e3aRedis\u4e2d\u7528\u6237\u4f18\u60e0\u5238\u5217\u8868\u53ea\u6709\u6a21\u677fid\u548c\u7528\u6237\u5238id\uff0c\u662f\u6ca1\u6709shopNumber\u7684\uff0c\u4f18\u60e0\u5238\u6a21\u677f\u53c8\u662f\u7528shopNumber\u505a\u5206\u7247\u952e\u7684\uff0c\u6211\u611f\u89c9\u54c8\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e1a\u52a1\u80cc\u666f<\/h2>\n\n\n\n<p>\u5728\u65e5\u5e38\u5f00\u53d1\u4e2d\uff0c\u5927\u5bb6\u901a\u5e38\u60f3\u5230\u7684\u6027\u80fd\u4f18\u5316\u65b9\u5f0f\u5c31\u662f\u5f15\u5165\u591a\u7ebf\u7a0b\u8fdb\u884c\u5e76\u884c\u5904\u7406\u3002\u5728\u4e4b\u524d\u7684\u8ba1\u7b97\u903b\u8f91\u4e2d\uff0c\u6211\u4eec\u662f\u4ee5\u5355\u7ebf\u7a0b\u7684\u4e32\u884c\u65b9\u5f0f\u9010\u4e2a\u5904\u7406\u4f18\u60e0\u5238\u7684\u8ba1\u7b97\u3002\u90a3\u662f\u5426\u53ef\u4ee5\u5c1d\u8bd5\u5c06\u6bcf\u4e2a\u4f18\u60e0\u5238\u7684\u8ba1\u7b97\u903b\u8f91\u4ece\u4e32\u884c\u6539\u4e3a\u591a\u7ebf\u7a0b\u5e76\u884c\u5904\u7406\u5462\uff1f<\/p>\n\n\n\n<p>\u7406\u8bba\u4e0a\uff0c\u5982\u679c\u8ba1\u7b97\u4e00\u4e2a\u4f18\u60e0\u5238\u7684\u4f18\u60e0\u91d1\u989d\u9700\u8981 1 \u6beb\u79d2\uff0c\u90a3\u4e48\u5904\u7406 10 \u4e2a\u4f18\u60e0\u5238\u65f6\u4e32\u884c\u6267\u884c\u5c31\u9700\u8981 10 \u6beb\u79d2\uff0c\u4f46\u5982\u679c\u91c7\u7528\u5e76\u884c\u6267\u884c\u65b9\u5f0f\uff0c10 \u4e2a\u4efb\u52a1\u540c\u65f6\u8ba1\u7b97\u5c31\u53ea\u9700\u8981 1 \u6beb\u79d2\u3002\u5e26\u7740\u8fd9\u4e2a\u4f18\u5316\u601d\u8def\uff0c\u6211\u4eec\u7ee7\u7eed\u6df1\u5165\u5206\u6790\u548c\u6539\u8fdb\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"git\">Git \u5206\u652f<\/h2>\n\n\n\n<p>\u5148\u4ece main \u5206\u652f\u4e0a\u67e5\u770b\uff0c\u4ee3\u7801\u5165\u53e3\uff1a<code>CouponQueryController#listQueryCoupons<\/code>\u3002<\/p>\n\n\n\n<p>\u548c\u4e0a\u4e00\u7ae0\u8282\u300a\u67e5\u8be2\u7528\u6237\u53ef\u7528\/\u4e0d\u53ef\u7528\u4f18\u60e0\u5238&amp;\u8ba1\u7b97\u6298\u6263\u91d1\u989d\u300b\u4e1a\u52a1\u5b8c\u5168\u4e00\u81f4\uff0c\u5982\u679c\u5bf9\u4e0b\u9762\u4e1a\u52a1\u4ee3\u7801\u4e0d\u592a\u4e86\u89e3\u7684\u8bdd\uff0c\u53ef\u4ee5\u5148\u53bb\u770b\u4e0b\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u591a\u7ebf\u7a0b\u8ba1\u7b97\u4f18\u60e0\u91d1\u989d<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"1\">1. \u5e76\u884c\u6280\u672f\u9009\u578b<\/h3>\n\n\n\n<p>\u591a\u7ebf\u7a0b\u5e76\u884c\u4f18\u5316\u6709\u591a\u79cd\u5b9e\u73b0\u65b9\u5f0f\uff0c\u4f8b\u5982\u901a\u8fc7\u7ebf\u7a0b\u6c60\u7ed3\u5408 <code>Future<\/code> \u6216\u4f7f\u7528 <code>CompletableFuture<\/code> \u7b49\u3002\u5728\u672c\u573a\u666f\u4e2d\uff0c\u6211\u4eec\u9009\u62e9\u4f7f\u7528 <code>CompletableFuture<\/code> \u6765\u5b9e\u73b0\u591a\u7ebf\u7a0b\u5e76\u884c\u5904\u7406\u3002\u5982\u679c\u5927\u5bb6\u60f3\u6df1\u5165\u4e86\u89e3 <code>CompletableFuture<\/code> \u7684\u673a\u5236\u548c\u4f7f\u7528\u573a\u666f\uff0c\u63a8\u8350\u9605\u8bfb\u4ee5\u4e0b\u4e24\u7bc7\u6587\u7ae0\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/tech.meituan.com\/2022\/05\/12\/principles-and-practices-of-completablefuture.html\" target=\"_blank\" rel=\"noreferrer noopener\" rel=\"nofollow\" >\u7f8e\u56e2\u6280\u672f\u56e2\u961f\uff1aCompletableFuture \u539f\u7406\u4e0e\u5b9e\u8df5 - \u5916\u5356\u5546\u5bb6\u7aef API \u7684\u5f02\u6b65\u5316<\/a>\uff1a\u8be6\u7ec6\u89e3\u6790 <code>CompletableFuture<\/code> \u5728\u5b9e\u9645\u4e1a\u52a1\u573a\u666f\u4e2d\u7684\u5e94\u7528\u548c\u6027\u80fd\u63d0\u5347\u6548\u679c\u3002<\/li>\n\n\n\n<li><a href=\"https:\/\/javaguide.cn\/java\/concurrent\/completablefuture-intro.html\" target=\"_blank\" rel=\"noreferrer noopener\" rel=\"nofollow\" >JavaGuide\uff1aCompletableFuture \u8be6\u89e3<\/a>\uff1a\u7cfb\u7edf\u6027\u8bb2\u89e3 <code>CompletableFuture<\/code> \u7684\u529f\u80fd\u3001\u5e38\u89c1\u4f7f\u7528\u6a21\u5f0f\u53ca\u5176\u5e95\u5c42\u539f\u7406\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u901a\u8fc7\u9605\u8bfb\u8fd9\u4e24\u7bc7\u6587\u7ae0\uff0c\u53ef\u4ee5\u66f4\u597d\u5730\u7406\u89e3 <code>CompletableFuture<\/code> \u7684\u4f5c\u7528\u53ca\u5176\u5728\u63d0\u5347\u7cfb\u7edf\u6027\u80fd\u4e2d\u7684\u5b9e\u9645\u5e94\u7528\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"2\">2. \u5e76\u884c\u4ee3\u7801\u6539\u9020<\/h3>\n\n\n\n<p>\u5728\u4f7f\u7528\u7ebf\u7a0b\u6c60\u7ed3\u5408 <code>CompletableFuture<\/code> \u8fdb\u884c\u5e76\u884c\u6539\u9020\u65f6\uff0c\u6d89\u53ca\u5230\u591a\u4e2a\u5e76\u53d1\u7f16\u7a0b\u7684\u7ec6\u8282\u548c\u4f18\u5316\u70b9\u3002\u6bd4\u5982\uff0c\u5982\u4f55\u5408\u7406\u8bbe\u7f6e\u7ebf\u7a0b\u6c60\u53c2\u6570\u3001\u5904\u7406\u591a\u7ebf\u7a0b\u73af\u5883\u4e0b\u96c6\u5408\u7684\u5e76\u53d1\u5b89\u5168\u95ee\u9898\u3001\u4ee5\u53ca\u5982\u4f55\u5728\u6240\u6709\u5e76\u53d1\u4efb\u52a1\u5b8c\u6210\u540e\u518d\u8fdb\u884c\u540e\u7eed\u5904\u7406\u7b49\u3002<\/p>\n\n\n\n<p>\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u5728\u6211\u4eec\u672c\u6b21\u7684\u4e1a\u52a1\u573a\u666f\u4e2d\uff0c\u5c5e\u4e8e\u662f CPU \u5bc6\u96c6\u578b\u4efb\u52a1\uff0c\u8bbe\u7f6e CPU \u7684\u6838\u5fc3\u6570\u5373\u53efprivatefinalExecutorService executorService =newThreadPoolExecutor(Runtime.getRuntime().availableProcessors(),Runtime.getRuntime().availableProcessors(),9999,TimeUnit.SECONDS,newSynchronousQueue&lt;&gt;(),newThreadPoolExecutor.CallerRunsPolicy());\n\u200b\n@OverridepublicQueryCouponsRespDTOlistQueryUserCoupons(QueryCouponsReqDTO requestParam){\/\/ ......\n\u200b\n &nbsp; &nbsp;\/\/ \u62c6\u5206\u540e\u7684\u4e24\u4e2a\u5217\u8868List&lt;CouponTemplateQueryRespDTO&gt; goodsEmptyList = partitioned.get(true);\/\/ goods \u4e3a\u7a7a\u7684\u5217\u8868List&lt;CouponTemplateQueryRespDTO&gt; goodsNotEmptyList = partitioned.get(false);\/\/ goods \u4e0d\u4e3a\u7a7a\u7684\u5217\u8868\n\u200b\n &nbsp; &nbsp;\/\/ \u9488\u5bf9\u5f53\u524d\u8ba2\u5355\u53ef\u7528\/\u4e0d\u53ef\u7528\u7684\u4f18\u60e0\u5238\u5217\u8868List&lt;QueryCouponsDetailRespDTO&gt; availableCouponList =Collections.synchronizedList(newArrayList&lt;&gt;());List&lt;QueryCouponsDetailRespDTO&gt; notAvailableCouponList =Collections.synchronizedList(newArrayList&lt;&gt;());\n\u200b\n &nbsp; &nbsp;\/\/ Step 2: \u5e76\u884c\u5904\u7406 goodsEmptyList \u548c goodsNotEmptyList \u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20CompletableFuture&lt;Void&gt; emptyGoodsTasks =CompletableFuture.allOf(\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;goodsEmptyList.stream().map(each -&gt;CompletableFuture.runAsync(()-&gt;{QueryCouponsDetailRespDTO resultCouponDetail =BeanUtil.toBean(each,QueryCouponsDetailRespDTO.class);JSONObject jsonObject =JSON.parseObject(each.getConsumeRule());handleCouponLogic(resultCouponDetail, jsonObject, requestParam.getOrderAmount(), availableCouponList, notAvailableCouponList);}, executorService)).toArray(CompletableFuture&#91;]::new));\n\u200b\n &nbsp; &nbsp;Map&lt;String, QueryCouponGoodsReqDTO&gt; goodsRequestMap = requestParam.getGoodsList().stream().collect(Collectors.toMap(QueryCouponGoodsReqDTO::getGoodsNumber,Function.identity()));CompletableFuture&lt;Void&gt; notEmptyGoodsTasks =CompletableFuture.allOf(\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;goodsNotEmptyList.stream().map(each -&gt;CompletableFuture.runAsync(()-&gt;{QueryCouponsDetailRespDTO resultCouponDetail =BeanUtil.toBean(each,QueryCouponsDetailRespDTO.class);QueryCouponGoodsReqDTO couponGoods = goodsRequestMap.get(each.getGoods());if(couponGoods ==null){\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;notAvailableCouponList.add(resultCouponDetail);}else{JSONObject jsonObject =JSON.parseObject(each.getConsumeRule());handleCouponLogic(resultCouponDetail, jsonObject, couponGoods.getGoodsAmount(), availableCouponList, notAvailableCouponList);}}, executorService)).toArray(CompletableFuture&#91;]::new));\n\u200b\n &nbsp; &nbsp;\/\/ Step 3: \u7b49\u5f85\u4e24\u4e2a\u5f02\u6b65\u4efb\u52a1\u96c6\u5408\u5b8c\u6210CompletableFuture.allOf(emptyGoodsTasks, notEmptyGoodsTasks).thenRun(()-&gt;{\/\/ \u4e0e\u4e1a\u5185\u6807\u51c6\u4e00\u81f4\uff0c\u6309\u6700\u7ec8\u4f18\u60e0\u529b\u5ea6\u4ece\u5927\u5230\u5c0f\u6392\u5e8f\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;availableCouponList.sort((c1, c2)-&gt; c2.getCouponAmount().compareTo(c1.getCouponAmount()));}).join();\n\u200b\n &nbsp; &nbsp;\/\/ \u6784\u5efa\u6700\u7ec8\u7ed3\u679c\u5e76\u8fd4\u56dereturnQueryCouponsRespDTO.builder().availableCouponList(availableCouponList).notAvailableCouponList(notAvailableCouponList).build();}\n\u200b\n\/\/ \u4f18\u60e0\u5238\u5224\u65ad\u903b\u8f91\uff0c\u6839\u636e\u6761\u4ef6\u5224\u65ad\u653e\u5165\u53ef\u7528\u6216\u4e0d\u53ef\u7528\u5217\u8868privatevoidhandleCouponLogic(QueryCouponsDetailRespDTO resultCouponDetail,JSONObject jsonObject,BigDecimal amount,List&lt;QueryCouponsDetailRespDTO&gt; availableCouponList,List&lt;QueryCouponsDetailRespDTO&gt; notAvailableCouponList){BigDecimal termsOfUse = jsonObject.getBigDecimal(\"termsOfUse\");BigDecimal maximumDiscountAmount = jsonObject.getBigDecimal(\"maximumDiscountAmount\");\n\u200b\n &nbsp; &nbsp;switch(resultCouponDetail.getType()){case0:\/\/ \u7acb\u51cf\u5238\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;resultCouponDetail.setCouponAmount(maximumDiscountAmount);\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;availableCouponList.add(resultCouponDetail);break;case1:\/\/ \u6ee1\u51cf\u5238if(amount.compareTo(termsOfUse)&gt;=0){\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;resultCouponDetail.setCouponAmount(maximumDiscountAmount);\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;availableCouponList.add(resultCouponDetail);}else{\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;notAvailableCouponList.add(resultCouponDetail);}break;case2:\/\/ \u6298\u6263\u5238if(amount.compareTo(termsOfUse)&gt;=0){BigDecimal discountRate = jsonObject.getBigDecimal(\"discountRate\");BigDecimal multiply = amount.multiply(discountRate);if(multiply.compareTo(maximumDiscountAmount)&gt;=0){\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;resultCouponDetail.setCouponAmount(maximumDiscountAmount);}else{\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;resultCouponDetail.setCouponAmount(multiply);}\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;availableCouponList.add(resultCouponDetail);}else{\n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;notAvailableCouponList.add(resultCouponDetail);}break;default:thrownewClientException(\"\u65e0\u6548\u7684\u4f18\u60e0\u5238\u7c7b\u578b\");}}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"3\">3. \u5e76\u884c\u4ee3\u7801\u903b\u8f91\u89e3\u6790<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"3-1-completable-future-all-of\">3.1 CompletableFuture.allOf<\/h4>\n\n\n\n<p>\u80fd\u591f\u5c06\u591a\u4e2a <code>CompletableFuture<\/code> \u5408\u5e76\u4e3a\u4e00\u4e2a\u65b0\u7684 <code>CompletableFuture&lt;Void&gt;<\/code>\uff0c\u5e76\u4e14\u53ea\u6709\u5f53\u6240\u6709\u4f20\u5165\u7684 <code>CompletableFuture<\/code> \u5168\u90e8\u5b8c\u6210\u65f6\uff08\u65e0\u8bba\u662f\u6210\u529f\u8fd8\u662f\u5931\u8d25\uff09\uff0c\u8fd9\u4e2a\u65b0\u7684 <code>CompletableFuture<\/code> \u624d\u4f1a\u88ab\u6807\u8bb0\u4e3a\u5b8c\u6210\u3002<\/p>\n\n\n\n<p>\u5de5\u4f5c\u539f\u7406\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>CompletableFuture.allOf<\/code> \u8fd4\u56de\u7684 <code>CompletableFuture&lt;Void><\/code> \u672c\u8eab\u4e0d\u5305\u542b\u6bcf\u4e2a\u5355\u72ec\u4efb\u52a1\u7684\u6267\u884c\u7ed3\u679c\uff0c\u5b83\u4ec5\u8868\u793a\u6240\u6709\u4efb\u52a1\u7684\u72b6\u6001\uff1a\u8981\u4e48\u5168\u90e8\u5b8c\u6210\uff0c\u8981\u4e48\u81f3\u5c11\u6709\u4e00\u4e2a\u5f02\u5e38\u3002<\/li>\n\n\n\n<li>\u5982\u679c\u4efb\u610f\u4e00\u4e2a\u4f20\u5165\u7684 <code>CompletableFuture<\/code> \u5f02\u5e38\u5b8c\u6210\uff0c\u5219 <code>allOfFuture<\/code> \u4e5f\u4f1a\u5f02\u5e38\u5b8c\u6210\u3002<\/li>\n\n\n\n<li>\u5982\u679c\u6240\u6709\u7684 <code>CompletableFuture<\/code> \u6210\u529f\u5b8c\u6210\uff0c\u5219 <code>allOfFuture<\/code> \u4e5f\u4f1a\u6210\u529f\u5b8c\u6210\u3002<\/li>\n<\/ul>\n\n\n\n<p><code>CompletableFuture.allOf<\/code> \u901a\u5e38\u7528\u4e8e\u4ee5\u4e0b\u51e0\u79cd\u573a\u666f\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7b49\u5f85\u6240\u6709\u5f02\u6b65\u4efb\u52a1\u5b8c\u6210\u540e\u518d\u6267\u884c\u64cd\u4f5c\uff1a<\/strong> \u5f53\u4f60\u5e0c\u671b\u6240\u6709\u5f02\u6b65\u4efb\u52a1\u90fd\u5b8c\u6210\u540e\uff0c\u518d\u89e6\u53d1\u67d0\u4e2a\u540e\u7eed\u64cd\u4f5c\uff08\u5982\u6c47\u603b\u7ed3\u679c\u3001\u66f4\u65b0\u6570\u636e\u5e93\u72b6\u6001\uff09\u65f6\uff0c\u4f7f\u7528 <code>CompletableFuture.allOf<\/code> \u662f\u4e00\u79cd\u7406\u60f3\u7684\u9009\u62e9\u3002<\/li>\n\n\n\n<li><strong>\u6279\u91cf\u6267\u884c\u4efb\u52a1\uff1a<\/strong> \u6bd4\u5982\u5728\u5fae\u670d\u52a1\u67b6\u6784\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u5411\u591a\u4e2a\u670d\u52a1\u53d1\u9001\u5f02\u6b65\u8bf7\u6c42\uff0c\u5e76\u5728\u6240\u6709\u8bf7\u6c42\u5b8c\u6210\u540e\u8fdb\u884c\u540e\u7eed\u5904\u7406\u3002<\/li>\n\n\n\n<li><strong>\u5e76\u884c\u5904\u7406\uff1a<\/strong> \u5f53\u5bf9\u4e00\u6279\u6570\u636e\u8fdb\u884c\u5e76\u884c\u5904\u7406\u65f6\uff08\u5982\u8ba1\u7b97\u3001\u8fc7\u6ee4\u3001\u8f6c\u5316\u7b49\uff09\uff0c\u53ef\u4ee5\u5229\u7528 <code>CompletableFuture.allOf<\/code> \u5408\u5e76\u6240\u6709\u7684\u5f02\u6b65\u4efb\u52a1\uff0c\u7b49\u6240\u6709\u4efb\u52a1\u5b8c\u6210\u540e\u518d\u7ee7\u7eed\u6267\u884c\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u5bf9\u4e8e <code>CompletableFuture.allOf<\/code> \u8fd4\u56de\u7684 <code>CompletableFuture&lt;Void&gt;<\/code>\uff0c\u901a\u5e38\u4f1a\u8c03\u7528\u4ee5\u4e0b\u65b9\u6cd5\u6765\u7b49\u5f85\u5176\u5b8c\u6210\u5e76\u8fdb\u884c\u540e\u7eed\u64cd\u4f5c\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>1.<strong><code>allOfFuture.join()<\/code> \u6216 <code>allOfFuture.get()<\/code>\uff1a<\/strong> \u963b\u585e\u7b49\u5f85\u6240\u6709\u4efb\u52a1\u5b8c\u6210\u3002<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>CompletableFuture&lt;Void&gt; allOfFuture =CompletableFuture.allOf(future1, future2, future3);\nallOfFuture.join();\/\/ \u963b\u585e\u7b49\u5f85\u6240\u6709\u4efb\u52a1\u5b8c\u6210System.out.println(\"\u6240\u6709\u4efb\u52a1\u5df2\u5b8c\u6210\");<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li>1.<strong><code>allOfFuture.thenRun(...)<\/code> \u6216 <code>allOfFuture.thenAccept(...)<\/code>\uff1a<\/strong> \u6307\u5b9a\u5f53\u6240\u6709\u4efb\u52a1\u5b8c\u6210\u540e\uff0c\u8981\u6267\u884c\u7684\u56de\u8c03\u64cd\u4f5c\u3002<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>CompletableFuture.allOf(future1, future2, future3).thenRun(()-&gt;System.out.println(\"\u6240\u6709\u4efb\u52a1\u5df2\u5b8c\u6210\"));\/\/ \u5f53\u6240\u6709\u4efb\u52a1\u5b8c\u6210\u65f6\u6267\u884c<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li>1.<strong>\u7ec4\u5408\u591a\u4e2a <code>CompletableFuture<\/code> \u7684\u7ed3\u679c\uff1a<\/strong> \u4f7f\u7528 <code>CompletableFuture.allOf<\/code> \u65f6\uff0c\u8fd4\u56de\u7684 <code>CompletableFuture&lt;Void><\/code> \u672c\u8eab\u4e0d\u5305\u542b\u5404\u4e2a\u4efb\u52a1\u7684\u7ed3\u679c\uff0c\u6240\u4ee5\u5982\u679c\u8981\u7ec4\u5408\u7ed3\u679c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u5f0f\uff1a<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>CompletableFuture&lt;String&gt; future1 =CompletableFuture.supplyAsync(()-&gt;\"\u7ed3\u679c1\");CompletableFuture&lt;String&gt; future2 =CompletableFuture.supplyAsync(()-&gt;\"\u7ed3\u679c2\");\n\u200b\nCompletableFuture&lt;Void&gt; allOfFuture =CompletableFuture.allOf(future1, future2);\n\u200b\n\/\/ \u83b7\u53d6\u6240\u6709\u5b50\u4efb\u52a1\u7684\u7ed3\u679c\nallOfFuture.thenRun(()-&gt;{try{String result1 = future1.get();String result2 = future2.get();System.out.println(\"\u6240\u6709\u4efb\u52a1\u7ed3\u679c\uff1a\"+ result1 +\", \"+ result2);}catch(Exception e){\n &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();}}).join();\/\/ \u786e\u4fdd\u6267\u884c\u5b8c\u6210\n\u200b<\/code><\/pre>\n\n\n\n<p>\u50cf\u6211\u4eec\u4e0a\u9762\u7684\u573a\u666f\uff0c\u5c31\u662f\u4f7f\u7528\u4e86\u65b9\u6848\u4e09\uff0c\u4f7f\u7528 <code>allOf<\/code> \u8fdb\u884c\u805a\u5408\uff0c\u6267\u884c\u5b8c\u6240\u6709\u4efb\u52a1\u540e\u6267\u884c <code>thenRun<\/code> \u5bf9\u53ef\u7528\u4f18\u60e0\u5238\u8fdb\u884c\u6392\u5e8f\uff0c\u6700\u7ec8\u7b49\u5f85 <code>thenRun<\/code> \u6267\u884c\u5b8c\u6210\u3002<\/p>\n\n\n\n<p><code>.thenRun(...)<\/code> \u672c\u8d28\u4e0a\u662f\u4e00\u4e2a\u975e\u963b\u585e\u7684\u64cd\u4f5c\uff0c\u5b83\u4f1a\u5728\u524d\u7f6e <code>CompletableFuture<\/code> \u5b8c\u6210\u65f6\u7acb\u5373\u63d0\u4ea4\u56de\u8c03\u4efb\u52a1\uff0c\u800c\u4e0d\u4f1a\u7b49\u5f85\u5b83\u7684\u6267\u884c\u5b8c\u6210\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c<code>.thenRun(...)<\/code> \u53ea\u5b89\u6392\u4e86\u8fd9\u4e2a\u56de\u8c03\u4efb\u52a1\u7684\u6267\u884c\uff0c\u4f46\u5b83\u672c\u8eab\u4e0d\u4f1a\u963b\u585e\u5f53\u524d\u7ebf\u7a0b\u53bb\u7b49\u5f85\u56de\u8c03\u4efb\u52a1\u7684\u5b8c\u6210\u3002\u56e0\u6b64\uff0c\u901a\u5e38\u60c5\u51b5\u4e0b\u5982\u679c\u5e0c\u671b\u786e\u4fdd <code>.thenRun(...)<\/code> \u4e2d\u7684\u903b\u8f91\u6267\u884c\u5b8c\u6210\uff0c\u9700\u8981\u901a\u8fc7 <code>join()<\/code> \u6216 <code>get()<\/code> \u6765\u7b49\u5f85\u6574\u4e2a\u64cd\u4f5c\u94fe\u7684\u5b8c\u6210\u3002<\/p>\n\n\n\n<p><code>thenRun<\/code> \u7684\u5e38\u89c1\u7528\u9014\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>thenRun<\/code> \u4e3b\u8981\u7528\u4e8e <strong>\u5728\u524d\u7f6e\u4efb\u52a1\u5b8c\u6210\u540e\u6267\u884c\u4e00\u4e2a\u4e0d\u4f9d\u8d56\u7ed3\u679c\u7684\u4efb\u52a1<\/strong>\uff0c\u5982\u7b80\u5355\u5730\u8f93\u51fa\u65e5\u5fd7\u6216\u505a\u4e00\u4e9b\u72b6\u6001\u66f4\u65b0\u3002<\/li>\n\n\n\n<li>\u7531\u4e8e <code>thenRun<\/code> \u4e0d\u4f9d\u8d56\u524d\u9762\u7684 <code>CompletableFuture<\/code> \u7684\u6267\u884c\u7ed3\u679c\uff0c\u56e0\u6b64\u4e00\u822c\u7528\u4e8e\u90a3\u4e9b\u4e0d\u9700\u8981\u83b7\u53d6\u7ed3\u679c\u7684\u573a\u666f\u3002\u5982\u679c\u9700\u8981\u5904\u7406\u524d\u7f6e\u4efb\u52a1\u7684\u7ed3\u679c\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>thenApply<\/code> \u6216 <code>thenCompose<\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"3-2-collections-synchronized-list\">3.2 \u4e3a\u4ec0\u4e48\u4f7f\u7528 Collections.synchronizedList<\/h4>\n\n\n\n<p>\u7531\u4e8e\u6211\u4eec\u5c06\u8ba1\u7b97\u91d1\u989d\u548c\u5224\u5b9a\u4f18\u60e0\u5238\u53ef\u7528\u6027\u7684\u903b\u8f91\u8fdb\u884c\u4e86\u62bd\u8c61\u5c01\u88c5\uff0c\u56e0\u6b64\u5728\u5e76\u53d1\u573a\u666f\u4e0b\uff0c\u591a\u4e2a\u7ebf\u7a0b\u53ef\u80fd\u4f1a\u540c\u65f6\u5411\u540c\u4e00\u4e2a\u96c6\u5408\u4e2d\u6dfb\u52a0\u6570\u636e\uff0c\u4ece\u800c\u5f15\u53d1\u7ebf\u7a0b\u5b89\u5168\u95ee\u9898\u3002\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u6211\u4eec\u4f7f\u7528\u4e86 <code>Collections.synchronizedList<\/code> \u65b9\u6cd5\uff0c\u5c06\u96c6\u5408\u5305\u88c5\u4e3a\u7ebf\u7a0b\u5b89\u5168\u7684\u7248\u672c\uff0c\u4ece\u800c\u4fdd\u8bc1\u5728\u5e76\u53d1\u4fee\u6539\u96c6\u5408\u65f6\u4e0d\u4f1a\u53d1\u751f\u6570\u636e\u4e0d\u4e00\u81f4\u6216\u5f02\u5e38\u7684\u60c5\u51b5\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u9488\u5bf9\u5f53\u524d\u8ba2\u5355\u53ef\u7528\/\u4e0d\u53ef\u7528\u7684\u4f18\u60e0\u5238\u5217\u8868List&lt;QueryCouponsDetailRespDTO&gt; availableCouponList =Collections.synchronizedList(newArrayList&lt;&gt;());List&lt;QueryCouponsDetailRespDTO&gt; notAvailableCouponList =Collections.synchronizedList(newArrayList&lt;&gt;());<\/code><\/pre>\n\n\n\n<p>\u4e3a\u4ec0\u4e48 new ArrayList&lt;&gt;() \u4e0d\u80fd\u652f\u6301\u5e76\u53d1\u64cd\u4f5c\uff1f<\/p>\n\n\n\n<p><code>ArrayList<\/code> \u672c\u8d28\u4e0a\u662f\u4e00\u4e2a\u52a8\u6001\u6570\u7ec4\uff0c\u5176\u5185\u90e8\u7ef4\u62a4\u4e86\u4e00\u4e2a <code>Object<\/code> \u7c7b\u578b\u7684\u6570\u7ec4\u6765\u5b58\u50a8\u5143\u7d20\u3002\u5728\u6267\u884c\u5982 <code>add<\/code>, <code>remove<\/code>, <code>set<\/code> \u8fd9\u4e9b\u65b9\u6cd5\u65f6\uff0c<code>ArrayList<\/code> \u4e0d\u4f1a\u5bf9\u5171\u4eab\u8d44\u6e90\u8fdb\u884c\u52a0\u9501\u6216\u540c\u6b65\u64cd\u4f5c\u3002\u7531\u4e8e\u6ca1\u6709\u4efb\u4f55\u540c\u6b65\u673a\u5236\uff0c\u8fd9\u4e9b\u64cd\u4f5c\u5728\u591a\u7ebf\u7a0b\u73af\u5883\u4e0b\u4f1a\u5bfc\u81f4\u6570\u636e\u7ade\u4e89\u548c\u4e0d\u4e00\u81f4\u6027\u3002<\/p>\n\n\n\n<p>\u5728\u591a\u7ebf\u7a0b\u573a\u666f\u4e2d\uff0c\u591a\u4e2a\u7ebf\u7a0b\u53ef\u80fd\u4f1a\u540c\u65f6\u5bf9\u540c\u4e00\u4e2a <code>ArrayList<\/code> \u8fdb\u884c\u4fee\u6539\uff0c\u6bd4\u5982\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6dfb\u52a0\u5143\u7d20\u65f6<\/strong>\uff1a\u591a\u4e2a\u7ebf\u7a0b\u540c\u65f6\u6267\u884c <code>add<\/code> \u64cd\u4f5c\u65f6\uff0c\u5b83\u4eec\u53ef\u80fd\u540c\u65f6\u8bfb\u53d6\u540c\u4e00\u4e2a <code>size<\/code> \u503c\uff0c\u7136\u540e\u5c1d\u8bd5\u5c06\u5143\u7d20\u6dfb\u52a0\u5230\u540c\u4e00\u4e2a\u4f4d\u7f6e\uff0c\u5bfc\u81f4\u6570\u7ec4\u8d8a\u754c\u5f02\u5e38\u6216\u5143\u7d20\u8986\u76d6\u3002<\/li>\n\n\n\n<li><strong>\u5220\u9664\u5143\u7d20\u65f6<\/strong>\uff1a\u591a\u4e2a\u7ebf\u7a0b\u540c\u65f6\u5220\u9664\u65f6\u53ef\u80fd\u4f1a\u5bfc\u81f4 <code>size<\/code> \u548c\u6570\u7ec4\u5185\u5bb9\u4e0d\u4e00\u81f4\uff0c\u629b\u51fa <code>ConcurrentModificationException<\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u4f7f\u7528 <code>Collections.synchronizedList(new ArrayList&lt;&gt;())<\/code> \u65b9\u6cd5\u5c06 <code>ArrayList<\/code> \u8f6c\u6362\u4e3a\u7ebf\u7a0b\u5b89\u5168\u7684\u96c6\u5408\u3002\u8fd9\u79cd\u65b9\u5f0f\u901a\u8fc7\u5728 <code>add<\/code>, <code>remove<\/code> \u7b49\u65b9\u6cd5\u4e0a\u589e\u52a0\u540c\u6b65\u9501\uff0c\u786e\u4fdd\u5728\u591a\u7ebf\u7a0b\u73af\u5883\u4e2d\u53ef\u4ee5\u5b89\u5168\u5730\u64cd\u4f5c\u3002<\/p>\n\n\n\n<p>\u90e8\u5206\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>staticclassSynchronizedList&lt;E&gt;extendsSynchronizedCollection&lt;E&gt;implementsList&lt;E&gt;{@java.io.Serialprivatestaticfinallong serialVersionUID =-7754090372962971524L;\n\u200b\n &nbsp; &nbsp;@SuppressWarnings(\"serial\")\/\/ Conditionally serializablefinalList&lt;E&gt; list;\n\u200b\n &nbsp; &nbsp;SynchronizedList(List&lt;E&gt; list){super(list);this.list = list;}SynchronizedList(List&lt;E&gt; list,Object mutex){super(list, mutex);this.list = list;}\n\u200b\n &nbsp; &nbsp;publicbooleanequals(Object o){if(this== o)returntrue;synchronized(mutex){return list.equals(o);}}publicinthashCode(){synchronized(mutex){return list.hashCode();}}\n\u200b\n &nbsp; &nbsp;publicEget(int index){synchronized(mutex){return list.get(index);}}publicEset(int index,E element){synchronized(mutex){return list.set(index, element);}}\/\/ ......}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"3-3-copy-on-write-array-list\">3.3 \u4e3a\u4ec0\u4e48\u4e0d\u7528 CopyOnWriteArrayList\uff1f<\/h4>\n\n\n\n<p><code>CopyOnWriteArrayList<\/code> \u662f\u4e00\u79cd\u7ebf\u7a0b\u5b89\u5168\u7684 <code>List<\/code> \u5b9e\u73b0\uff0c\u5b83\u901a\u8fc7\u6bcf\u6b21\u5199\u64cd\u4f5c\u65f6\u590d\u5236\u6574\u4e2a\u5e95\u5c42\u6570\u7ec4\u6765\u5b9e\u73b0\u7ebf\u7a0b\u5b89\u5168\uff0c\u975e\u5e38\u9002\u5408\u8bfb\u591a\u5199\u5c11\u7684\u573a\u666f\u3002\u4e3a\u4ec0\u4e48\u6211\u4eec\u7684\u573a\u666f\u4e0d\u4f7f\u7528\u8fd9\u4e2a\u6027\u80fd\u66f4\u9ad8\u7684 List\uff1f<\/p>\n\n\n\n<p><code>CopyOnWriteArrayList<\/code> \u7684\u6838\u5fc3\u673a\u5236\u662f <strong>\u6bcf\u6b21\u5199\u64cd\u4f5c\uff08\u5982 <code>add<\/code>\u3001<code>set<\/code>\u3001<code>remove<\/code>\uff09\u90fd\u4f1a\u521b\u5efa\u6574\u4e2a\u6570\u7ec4\u7684\u526f\u672c<\/strong>\u3002\u8fd9\u79cd\u64cd\u4f5c\u867d\u7136\u53ef\u4ee5\u4fdd\u8bc1\u7ebf\u7a0b\u5b89\u5168\uff0c\u4f46\u6bcf\u6b21\u4fee\u6539\u65f6\u90fd\u9700\u8981\u590d\u5236\u6574\u4e2a\u6570\u7ec4\uff0c\u5f00\u9500\u975e\u5e38\u5927\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5f53\u96c6\u5408\u4e2d\u7684\u5143\u7d20\u8f83\u591a\uff0c\u4e14\u6709\u9891\u7e41\u7684\u5199\u64cd\u4f5c\u65f6\uff0c<code>CopyOnWriteArrayList<\/code> \u4f1a\u663e\u8457\u589e\u52a0\u5185\u5b58\u4f7f\u7528\u548c CPU \u8d44\u6e90\u6d88\u8017\u3002<\/li>\n\n\n\n<li>\u5982\u679c\u6570\u636e\u91cf\u5927\uff0c\u53ef\u80fd\u5bfc\u81f4\u5185\u5b58\u6d88\u8017\u8fc7\u9ad8\uff0c\u751a\u81f3\u4f1a\u5f15\u53d1 <code>OutOfMemoryError<\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u56e0\u6b64\uff0c<strong><code>CopyOnWriteArrayList<\/code> \u66f4\u9002\u7528\u4e8e\u8bfb\u591a\u5199\u5c11\u7684\u573a\u666f<\/strong>\uff0c\u5728\u9ad8\u9891\u5199\u5165\u7684\u573a\u666f\u4e0b\u5e76\u4e0d\u5408\u9002\u3002\u800c\u6211\u4eec\u573a\u666f\u4ec5\u662f\u5199\u5165\u5e76\u4e14\u6392\u5e8f\uff0c\u76f4\u63a5\u5c31\u8fd4\u56de\u524d\u7aef\u4e86\uff0c\u6240\u4ee5\u57fa\u672c\u4e0a\u6ca1\u6709\u8bfb\u573a\u666f\uff0c\u6240\u4ee5\u53ef\u4ee5\u76f4\u63a5\u5ffd\u7565\u6389\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u529f\u80fd\u6d4b\u8bd5<\/h2>\n\n\n\n<p>\u6d4b\u8bd5\u65b9\u6cd5\u548c\u4e0a\u4e00\u7ae0\u8282\u300a\u67e5\u8be2\u7528\u6237\u53ef\u7528\/\u4e0d\u53ef\u7528\u4f18\u60e0\u5238&amp;\u8ba1\u7b97\u6298\u6263\u91d1\u989d\u300b\u4e1a\u52a1\u5b8c\u5168\u4e00\u81f4\uff0c\u53ef\u4ee5\u590d\u7528\u540c\u4e00\u4e2a\u8bf7\u6c42\u53c2\u6570\u3002<\/p>\n\n\n\n<p>\u8bbf\u95ee\u63a5\u53e3\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@RestController@RequiredArgsConstructor@Tag(name =\"\u67e5\u8be2\u7528\u6237\u4f18\u60e0\u5238\u7ba1\u7406\")publicclassCouponQueryController{\n\u200b\n &nbsp; &nbsp;privatefinalCouponQueryService couponQueryService;\n\u200b\n &nbsp; &nbsp;@Operation(summary =\"\u67e5\u8be2\u7528\u6237\u53ef\u7528\/\u4e0d\u53ef\u7528\u4f18\u60e0\u5238\u5217\u8868\")@PostMapping(\"\/api\/settlement\/coupon-query\")publicResult&lt;QueryCouponsRespDTO&gt;listQueryCoupons(@RequestBodyQueryCouponsReqDTO requestParam){returnResults.success(couponQueryService.listQueryUserCoupons(requestParam));}\n\u200b\n &nbsp; &nbsp;\/\/ ......}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u6587\u672b\u603b\u7ed3<\/h2>\n\n\n\n<p>\u5728\u672c\u7ae0\u8282\u4e2d\uff0c\u6211\u4eec\u901a\u8fc7\u591a\u7ebf\u7a0b\u5e76\u884c\u4f18\u5316\u6280\u672f\uff0c\u5c06\u539f\u5148\u4e32\u884c\u5904\u7406\u7684\u4f18\u60e0\u5238\u8ba1\u7b97\u903b\u8f91\u6539\u9020\u4e3a\u57fa\u4e8e <code>CompletableFuture<\/code> \u7684\u591a\u7ebf\u7a0b\u5e76\u884c\u5904\u7406\u65b9\u6848\u3002\u8fd9\u79cd\u65b9\u5f0f\u80fd\u591f\u5728\u5904\u7406\u5927\u91cf\u4f18\u60e0\u5238\u65f6\u6709\u6548\u964d\u4f4e\u8ba1\u7b97\u5ef6\u65f6\uff0c\u63d0\u9ad8\u7cfb\u7edf\u54cd\u5e94\u901f\u5ea6\u3002\u5c24\u5176\u662f\u5728\u6bcf\u4e2a\u4f18\u60e0\u5238\u7684\u8ba1\u7b97\u903b\u8f91\u76f8\u5bf9\u590d\u6742\u65f6\uff0c\u591a\u7ebf\u7a0b\u5e76\u884c\u80fd\u591f\u663e\u8457\u63d0\u5347\u5904\u7406\u6548\u7387\u3002<\/p>\n\n\n\n<p>\u4e3a\u4e86\u786e\u4fdd\u7ebf\u7a0b\u5b89\u5168\uff0c\u6211\u4eec\u4f7f\u7528\u4e86 <code>Collections.synchronizedList<\/code> \u4fdd\u62a4\u5171\u4eab\u96c6\u5408\uff0c\u907f\u514d\u591a\u7ebf\u7a0b\u5199\u5165\u65f6\u51fa\u73b0\u6570\u636e\u4e0d\u4e00\u81f4\u7684\u95ee\u9898\u3002\u540c\u65f6\uff0c\u901a\u8fc7\u5408\u7406\u8bbe\u7f6e\u7ebf\u7a0b\u6c60\u53c2\u6570\uff0c\u4fdd\u8bc1\u7cfb\u7edf\u8d44\u6e90\u7684\u9ad8\u6548\u5229\u7528\u3002<\/p>\n\n\n\n<p>\u901a\u8fc7\u591a\u7ebf\u7a0b\u5e76\u884c\u6267\u884c\uff0c\u539f\u672c\u53ef\u80fd\u9700\u8981\u8f83\u957f\u65f6\u95f4\u7684\u4f18\u60e0\u5238\u8ba1\u7b97\u4efb\u52a1\u5728\u6027\u80fd\u4e0a\u5f97\u5230\u4e86\u663e\u8457\u4f18\u5316\uff0c\u4e3a\u7528\u6237\u63d0\u4f9b\u4e86\u66f4\u5feb\u901f\u7684\u67e5\u8be2\u4f53\u9a8c\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u4e0a\u9762\u7684\u5185\u5bb9\u662f\u7406\u8bba\u5c42\u9762\u7684\u4f18\u5316\u603b\u7ed3\uff0c\u5f88\u591a\u540c\u5b66\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\u5f80\u5f80\u8ba4\u4e3a\u5f15\u5165\u5e76\u53d1\u7f16\u7a0b\u5c31\u4e00\u5b9a\u80fd\u591f\u63d0\u5347\u63a5\u53e3\u7684\u54cd\u5e94\u6027\u80fd\u3002\u7136\u800c\uff0c\u5982\u679c\u4f60\u5c06\u6211\u4eec\u8fd9\u6bb5\u6539\u9020\u540e\u7684\u5e76\u884c\u4ee3\u7801\u548c\u539f\u5148\u7684\u540c\u6b65\u8bf7\u6c42\u903b\u8f91\u8fdb\u884c\u5bf9\u6bd4\uff0c\u5c31\u4f1a\u53d1\u73b0\u6027\u80fd\u63d0\u5347\u5e76\u4e0d\u660e\u663e\u3002\u751a\u81f3\u5728\u4f7f\u7528 JMeter \u8fdb\u884c\u9ad8\u5e76\u53d1\u538b\u6d4b\u65f6\uff0c\u4f60\u53ef\u80fd\u4f1a\u53d1\u73b0\u7cfb\u7edf\u7684\u541e\u5410\u91cf\u53cd\u800c\u6709\u6240\u4e0b\u964d\u3002<\/p>\n\n\n\n<p>\u8fd9\u662f\u56e0\u4e3a\u5e76\u53d1\u7f16\u7a0b\u5e76\u4e0d\u662f\u4e07\u80fd\u7684\u3002\u5f15\u5165\u591a\u7ebf\u7a0b\u540e\uff0cCPU \u7684\u4e0a\u4e0b\u6587\u5207\u6362\u3001\u7ebf\u7a0b\u6c60\u7ba1\u7406\u7684\u5f00\u9500\u4ee5\u53ca\u6570\u636e\u540c\u6b65\u7b49\u95ee\u9898\uff0c\u90fd\u4f1a\u5bfc\u81f4\u7cfb\u7edf\u7684\u6574\u4f53\u6027\u80fd\u672a\u5fc5\u8fbe\u5230\u9884\u671f\u3002\u5173\u4e8e\u8fd9\u4e2a\u7ed3\u679c\u80cc\u540e\u7684\u5177\u4f53\u5206\u6790\uff0c\u6211\u4eec\u4f1a\u5728\u63a5\u4e0b\u6765\u7684\u538b\u6d4b\u7ae0\u8282\u4e2d\u8be6\u7ec6\u63ed\u6653\uff0c\u656c\u8bf7\u671f\u5f85\u3002<\/p>\n\n\n\n<p>\u5b8c\u7ed3\uff0c\u6492\u82b1 \ud83c\udf89<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e1a\u52a1\u80cc\u666f \u6211\u4eec\u5728\u4f7f\u7528\u4f18\u60e0\u5238\u8d2d\u7269\u65f6\uff0c\u53ef\u4ee5\u5728\u8ba2\u5355\u7ed3\u7b97\u9875\u9762\u67e5\u770b\u81ea\u5df1\u7684\u53ef\u7528\/\u4e0d\u53ef\u7528\u4f18\u60e0\u5238\u5217\u8868\uff0c\u53ef\u7528\u7684\u4f18\u60e0\u5238\u8fd8\u4f1a\u6839\u636e\u53ef\u6263\u51cf\u8ba2\u5355\u91d1\u989d\u4ece\u5927\u5230\u5c0f\u8fdb &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[3],"tags":[20],"class_list":["post-1315","post","type-post","status-publish","format-standard","hentry","category-3","tag-20"],"_links":{"self":[{"href":"https:\/\/eve2333.top\/index.php?rest_route=\/wp\/v2\/posts\/1315","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/eve2333.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eve2333.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eve2333.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/eve2333.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1315"}],"version-history":[{"count":3,"href":"https:\/\/eve2333.top\/index.php?rest_route=\/wp\/v2\/posts\/1315\/revisions"}],"predecessor-version":[{"id":1321,"href":"https:\/\/eve2333.top\/index.php?rest_route=\/wp\/v2\/posts\/1315\/revisions\/1321"}],"wp:attachment":[{"href":"https:\/\/eve2333.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1315"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eve2333.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1315"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eve2333.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1315"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}