{"id":7918,"date":"2024-11-14T12:43:03","date_gmt":"2024-11-14T04:43:03","guid":{"rendered":"https:\/\/fwq.ai\/blog\/7918\/"},"modified":"2024-11-14T12:43:03","modified_gmt":"2024-11-14T04:43:03","slug":"%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3%e5%b9%b6%e5%8f%91%e6%89%a3%e8%b4%b9%e5%92%8c%e5%85%85%e5%80%bc%e6%93%8d%e4%bd%9c%e5%af%bc%e8%87%b4%e7%9a%84%e9%87%91%e9%a2%9d%e4%b8%8d%e4%b8%80%e8%87%b4%e9%97%ae","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/7918\/","title":{"rendered":"\u5982\u4f55\u89e3\u51b3\u5e76\u53d1\u6263\u8d39\u548c\u5145\u503c\u64cd\u4f5c\u5bfc\u81f4\u7684\u91d1\u989d\u4e0d\u4e00\u81f4\u95ee\u9898\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173133273276845.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u89e3\u51b3\u5e76\u53d1\u6263\u8d39\u548c\u5145\u503c\u64cd\u4f5c\u5bfc\u81f4\u7684\u91d1\u989d\u4e0d\u4e00\u81f4\u95ee\u9898\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u89e3\u51b3\u5e76\u53d1\u6263\u8d39\u548c\u5145\u503c\u64cd\u4f5c\u5bfc\u81f4\u7684\u91d1\u989d\u4e0d\u4e00\u81f4\u95ee\u9898\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5e76\u53d1\u6263\u8d39\u548c\u5145\u503c\u64cd\u4f5c\u51b2\u7a81\u7684\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>\u5f53\u8d26\u6237\u5b58\u5728\u5e76\u53d1\u6263\u8d39\u548c\u5145\u503c\u64cd\u4f5c\u65f6\uff0c\u91d1\u989d\u53ef\u80fd\u4f1a\u51fa\u73b0\u4e0d\u4e00\u81f4\u7684\u60c5\u51b5\u3002\u4e3a\u4e86\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u9700\u8981\u91c7\u53d6\u63aa\u65bd\u9632\u6b62\u5e76\u53d1\u51b2\u7a81\u3002<\/p>\n<p>\u6839\u636e\u4e0d\u540c\u7684\u573a\u666f\uff0c\u6709\u4ee5\u4e0b\u4e24\u79cd\u5e38\u89c1\u89e3\u51b3\u65b9\u6848\uff1a<\/p>\n<p><strong>\u4fdd\u8bc1\u64cd\u4f5c\u539f\u5b50\u6027<\/strong><\/p>\n<ul>\n<li> <strong>\u60b2\u89c2\u9501\uff1a<\/strong>\u4f7f\u7528\u7528\u6237 id \u4f5c\u4e3a\u9501\u6807\u8bc6\u3002\u53d8\u66f4\u8d26\u6237\u4f59\u989d\u65f6\u5c1d\u8bd5\u83b7\u5f97\u9501\u3002\u83b7\u5f97\u9501\u6210\u529f\u5219\u7ee7\u7eed\u64cd\u4f5c\uff0c\u5426\u5219\u963b\u585e\u3002<\/li>\n<li> <strong>\u961f\u5217\uff1a<\/strong>\u5c06\u6263\u8d39\u548c\u5145\u503c\u64cd\u4f5c\u653e\u5165 fifo \u961f\u5217\u4e2d\u3002\u6d88\u8d39\u8005\u4f9d\u6b21\u53d6\u51fa\u961f\u5217\u4e2d\u7684\u64cd\u4f5c\u5e76\u6267\u884c\uff0c\u4fdd\u8bc1\u64cd\u4f5c\u540c\u6b65\u8fdb\u884c\u3002<\/li>\n<\/ul>\n<p><strong>\u63d0\u9ad8\u6027\u80fd<\/strong><\/p>\n<ul>\n<li> <strong>\u4e50\u89c2\u9501\uff1a<\/strong>\u83b7\u53d6\u8d26\u6237\u4f59\u989d\u65f6\u540c\u65f6\u83b7\u5f97\u6570\u636e\u7248\u672c\u3002\u53d8\u66f4\u4f59\u989d\u65f6\u6bd4\u8f83\u7248\u672c\u3002\u7248\u672c\u4e00\u81f4\u8868\u793a\u6570\u636e\u672a\u88ab\u66f4\u65b0\uff0c\u7ee7\u7eed\u64cd\u4f5c\u3002\u5426\u5219\uff0c\u64cd\u4f5c\u5931\u8d25\u3002<\/li>\n<\/ul>\n<p><strong>sql \u793a\u4f8b<\/strong><\/p>\n<p>\u4f7f\u7528\u4e50\u89c2\u9501\u65f6\u7684 sql \u8bed\u53e5\uff1a<\/p>\n<pre>update account_balance \nset balance = balance + :changeNum, version = version + 1\nwhere user_id = :userId and version = :version<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5176\u4e2d\uff0c:changenum \u4e3a\u53d8\u66f4\u91d1\u989d\uff0c:userid \u4e3a\u7528\u6237 id\uff0c:version \u4e3a\u6570\u636e\u7248\u672c\u3002<\/p>\n<p>\u5982\u679c sql \u54cd\u5e94\u884c\u6570\u4e3a 1\uff0c\u8868\u793a\u66f4\u65b0\u6210\u529f\uff1b\u5982\u679c\u4e3a 0\uff0c\u8868\u793a\u66f4\u65b0\u5931\u8d25\uff08\u6570\u636e\u5df2\u88ab\u66f4\u65b0\uff09\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u89e3\u51b3\u5e76\u53d1\u6263\u8d39\u548c\u5145\u503c\u64cd\u4f5c\u5bfc\u81f4\u7684\u91d1\u989d\u4e0d\u4e00\u81f4\u95ee\u9898\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5e76\u53d1\u6263\u8d39\u548c\u5145\u503c\u64cd\u4f5c\u51b2\u7a81\u7684\u89e3\u51b3\u65b9\u6848 \u5f53\u8d26\u6237\u5b58\u5728\u5e76\u53d1\u6263\u8d39\u548c\u5145\u503c\u64cd\u4f5c\u65f6\uff0c\u91d1\u989d\u53ef\u80fd\u4f1a\u51fa\u73b0\u4e0d\u4e00\u81f4\u7684\u60c5\u51b5\u3002\u4e3a\u4e86\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u9700\u8981\u91c7\u53d6\u63aa\u65bd\u9632\u6b62\u5e76\u53d1\u51b2\u7a81\u3002 \u6839\u636e\u4e0d\u540c\u7684\u573a\u666f\uff0c\u6709\u4ee5\u4e0b\u4e24\u79cd\u5e38\u89c1\u89e3\u51b3\u65b9\u6848\uff1a \u4fdd\u8bc1\u64cd\u4f5c\u539f\u5b50\u6027 \u60b2\u89c2\u9501\uff1a\u4f7f\u7528\u7528\u6237 id \u4f5c\u4e3a\u9501\u6807\u8bc6\u3002\u53d8\u66f4\u8d26\u6237\u4f59\u989d\u65f6\u5c1d\u8bd5\u83b7\u5f97\u9501\u3002\u83b7\u5f97\u9501\u6210\u529f\u5219\u7ee7\u7eed\u64cd\u4f5c\uff0c\u5426\u5219\u963b\u585e\u3002 \u961f\u5217\uff1a\u5c06\u6263\u8d39\u548c\u5145\u503c\u64cd\u4f5c\u653e\u5165 fifo \u961f\u5217\u4e2d\u3002\u6d88\u8d39\u8005\u4f9d\u6b21\u53d6\u51fa\u961f\u5217\u4e2d\u7684\u64cd\u4f5c\u5e76\u6267\u884c\uff0c\u4fdd\u8bc1\u64cd\u4f5c\u540c\u6b65\u8fdb\u884c\u3002 \u63d0\u9ad8\u6027\u80fd \u4e50\u89c2\u9501\uff1a\u83b7\u53d6\u8d26\u6237\u4f59\u989d\u65f6\u540c\u65f6\u83b7\u5f97\u6570\u636e\u7248\u672c\u3002\u53d8\u66f4\u4f59\u989d\u65f6\u6bd4\u8f83\u7248\u672c\u3002\u7248\u672c\u4e00\u81f4\u8868\u793a\u6570\u636e\u672a\u88ab\u66f4\u65b0\uff0c\u7ee7\u7eed\u64cd\u4f5c\u3002\u5426\u5219\uff0c\u64cd\u4f5c\u5931\u8d25\u3002 sql \u793a\u4f8b \u4f7f\u7528\u4e50\u89c2\u9501\u65f6\u7684 sql \u8bed\u53e5\uff1a update account_balance set balance = balance + :changeNum, version = version + 1 where user_id = :userId and version = :version \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff0c:changenum \u4e3a\u53d8\u66f4\u91d1\u989d\uff0c:userid \u4e3a\u7528\u6237 id\uff0c:version \u4e3a\u6570\u636e\u7248\u672c\u3002 \u5982\u679c sql \u54cd\u5e94\u884c\u6570\u4e3a 1\uff0c\u8868\u793a\u66f4\u65b0\u6210\u529f\uff1b\u5982\u679c\u4e3a 0\uff0c\u8868\u793a\u66f4\u65b0\u5931\u8d25\uff08\u6570\u636e\u5df2\u88ab\u66f4\u65b0\uff09\u3002 \u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u89e3\u51b3\u5e76\u53d1\u6263\u8d39\u548c\u5145\u503c\u64cd\u4f5c\u5bfc\u81f4\u7684\u91d1\u989d\u4e0d\u4e00\u81f4\u95ee\u9898\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-7918","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7918","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=7918"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7918\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=7918"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=7918"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=7918"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}