{"id":53575,"date":"2024-12-03T12:21:25","date_gmt":"2024-12-03T04:21:25","guid":{"rendered":"https:\/\/fwq.ai\/blog\/53575\/"},"modified":"2024-12-03T12:21:25","modified_gmt":"2024-12-03T04:21:25","slug":"%e5%ba%95%e5%b1%82%e8%ae%be%e8%ae%a1%ef%bc%9a%e8%bd%ae%e8%af%a2%e7%b3%bb%e7%bb%9f-%e8%be%b9%e7%bc%98%e6%83%85%e5%86%b5","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/53575\/","title":{"rendered":"\u5e95\u5c42\u8bbe\u8ba1\uff1a\u8f6e\u8be2\u7cfb\u7edf &#8211; \u8fb9\u7f18\u60c5\u51b5"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5e95\u5c42\u8bbe\u8ba1\uff1a\u8f6e\u8be2\u7cfb\u7edf &#8211; \u8fb9\u7f18\u60c5\u51b5<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span>    <\/p>\n<p>\u4eca\u65e5\u4e0d\u80af\u57cb\u5934\uff0c\u660e\u65e5\u4f55\u4ee5\u62ac\u5934\uff01\u6bcf\u65e5\u4e00\u53e5\u52aa\u529b\u81ea\u5df1\u7684\u8bdd\u54c8\u54c8~\u54c8\u55bd\uff0c\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u7bc7<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5e95\u5c42\u8bbe\u8ba1\uff1a\u8f6e\u8be2\u7cfb\u7edf &#8211; \u8fb9\u7f18\u60c5\u51b5\u300b<\/span>\uff0c\u4e3b\u8981\u5185\u5bb9\u662f\u8bb2\u89e3<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u53ef\u4ee5\u6536\u85cf\u6216\u8005\u6709\u66f4\u597d\u7684\u5efa\u8bae\u5728\u8bc4\u8bba\u63d0\u51fa\uff0c\u6211\u90fd\u4f1a\u8ba4\u771f\u770b\u7684\uff01\u5927\u5bb6\u4e00\u8d77\u8fdb\u6b65\uff0c\u4e00\u8d77\u5b66\u4e60\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241202\/1733110807674d2c17411ab.jpg\" class=\"aligncenter\" title=\"\u5e95\u5c42\u8bbe\u8ba1\uff1a\u8f6e\u8be2\u7cfb\u7edf &#8211; \u8fb9\u7f18\u60c5\u51b5\u63d2\u56fe\" alt=\"\u5e95\u5c42\u8bbe\u8ba1\uff1a\u8f6e\u8be2\u7cfb\u7edf &#8211; \u8fb9\u7f18\u60c5\u51b5\u63d2\u56fe\" \/><\/p>\n<p><strong>\u76ee\u5f55<\/strong><\/p>\n<p>\u6848\u4f8b 1 &#8211; \u5904\u7406\u66f4\u65b0\u7684\u7248\u672c\u63a7\u5236<br \/> \u60c5\u51b5 2 &#8211; pollid \u4f5c\u4e3a uuid \u800c\u4e0d\u662f\u4e3b\u952e<br \/> \u60c5\u51b5 3 &#8211; \u9009\u9879\u4e3a\u7a7a\u6216\u65e0\u6548<br \/> \u6848\u4f8b 4 &#8211; \u91cd\u590d\u9009\u9879<br \/> \u6848\u4f8b 5 &#8211; \u95ee\u9898\u957f\u5ea6\u9650\u5236<br \/> \u6848\u4f8b 6 &#8211; \u6295\u7968\u8fc7\u671f<\/p>\n<p>\u8bf7\u5148\u53c2\u8003\u4ee5\u4e0b\u6587\u7ae0\uff1a<\/p>\n<ol>\n<li>\n<p>\u5e95\u5c42\u8bbe\u8ba1\uff1a\u6295\u7968\u7cfb\u7edf\uff1a\u57fa\u672c<\/p>\n<\/li>\n<li>\n<p>\u5e95\u5c42\u8bbe\u8ba1\uff1a\u8f6e\u8be2\u7cfb\u7edf &#8211; \u4f7f\u7528 node.js \u548c sql<\/p>\n<\/li>\n<\/ol>\n<h2> \u8fb9\u7f18\u60c5\u51b5\u5904\u7406 <\/h2>\n<h2> \u6848\u4f8b1 <\/h2>\n<p><strong>\u8981\u7ba1\u7406\u6295\u7968\u95ee\u9898\u548c\u9009\u9879\u7684\u66f4\u65b0\uff0c\u540c\u65f6\u4fdd\u7559\u4e0e\u540c\u4e00\u6295\u7968 id \u5173\u8054\u7684\u5148\u524d\u8be6\u7ec6\u4fe1\u606f\uff0c\u60a8\u53ef\u4ee5\u5b9e\u73b0\u7248\u672c\u63a7\u5236\u7cfb\u7edf\u3002\u8fd9\u79cd\u65b9\u6cd5\u5141\u8bb8\u60a8\u8ddf\u8e2a\u6bcf\u6b21\u6c11\u610f\u8c03\u67e5\u7684\u5386\u53f2\u6570\u636e\uff0c\u786e\u4fdd\u5373\u4f7f\u5728\u66f4\u65b0\u540e\u4e5f\u4fdd\u7559\u65e7\u7684\u8be6\u7ec6\u4fe1\u606f\u3002<\/strong><\/p>\n<h3> \u7b2c 1 \u6b65\uff1a\u6570\u636e\u5e93\u67b6\u6784\u66f4\u6539 <\/h3>\n<ol>\n<li>\n<p><strong>\u66f4\u65b0\u6295\u7968\u8868<\/strong><\/p>\n<ul>\n<li>\u5c06 current_version_id \u5217\u6dfb\u52a0\u5230 polls \u8868\u4e2d\u4ee5\u8ddf\u8e2a\u6295\u7968\u7684\u6700\u65b0\u7248\u672c\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u521b\u5efa\u6295\u7968\u7248\u672c\u8868<\/strong><\/p>\n<ul>\n<li>\u521b\u5efa\u4e00\u4e2a\u65b0\u8868\u6765\u5b58\u50a8\u6c11\u610f\u8c03\u67e5\u7684\u5386\u53f2\u7248\u672c\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h4> \u66f4\u65b0\u7684\u6570\u636e\u5e93\u67b6\u6784 <\/h4>\n<pre>create database polling_system;\n\nuse polling_system;\n\ncreate table polls (\n    poll_id int auto_increment primary key,\n    current_version_id int,\n    created_at timestamp default current_timestamp,\n    foreign key (current_version_id) references poll_versions(version_id) on delete set null\n);\n\ncreate table poll_versions (\n    version_id int auto_increment primary key,\n    poll_id int,\n    question varchar(255) not null,\n    created_at timestamp default current_timestamp,\n    foreign key (poll_id) references polls(poll_id) on delete cascade\n);\n\ncreate table options (\n    option_id int auto_increment primary key,\n    poll_id int,\n    option_text varchar(255) not null,\n    foreign key (poll_id) references polls(poll_id) on delete cascade\n);\n\ncreate table votes (\n    vote_id int auto_increment primary key,\n    poll_id int,\n    user_id varchar(255) not null,\n    option_id int,\n    created_at timestamp default current_timestamp,\n    foreign key (poll_id) references polls(poll_id) on delete cascade,\n    foreign key (option_id) references options(option_id) on delete cascade\n);\n<\/pre>\n<h3> \u7b2c 2 \u6b65\uff1aapi \u5b9e\u65bd\u53d8\u66f4 <\/h3>\n<h4> \u66f4\u65b0\u8f6e\u8be2\u63a7\u5236\u5668 <\/h4>\n<p>\u4fee\u6539 updatepoll \u65b9\u6cd5\uff0c\u5728\u521b\u5efa\u65b0\u7248\u672c\u4e4b\u524d\u68c0\u67e5\u95ee\u9898\u662f\u5426\u53d1\u751f\u53d8\u5316\u3002<\/p>\n<h5> \u6587\u4ef6\uff1acontrollers\/pollcontroller.js <\/h5>\n<pre>const pool = require('..\/db\/db');\n\n\/\/ create poll\nexports.createpoll = async (req, res) =&gt; {\n    const { question, options } = req.body;\n\n    if (!question || !options || !array.isarray(options) || options.length &lt; 2) {\n        return res.status(400).json({ message: \"invalid input data. question and at least two options are required.\" });\n    }\n\n    try {\n        const connection = await pool.getconnection();\n        await connection.begintransaction();\n\n        const [result] = await connection.execute(\n            'insert into polls (current_version_id) values (null)'\n        );\n\n        const pollid = result.insertid;\n\n        const [versionresult] = await connection.execute(\n            'insert into poll_versions (poll_id, question) values (?, ?)',\n            [pollid, question]\n        );\n\n        const versionid = versionresult.insertid;\n\n        \/\/ update the current version in the polls table\n        await connection.execute(\n            'update polls set current_version_id = ? where poll_id = ?',\n            [versionid, pollid]\n        );\n\n        const optionqueries = options.map(option =&gt; {\n            return connection.execute(\n                'insert into options (poll_id, option_text) values (?, ?)',\n                [pollid, option]\n            );\n        });\n\n        await promise.all(optionqueries);\n\n        await connection.commit();\n        connection.release();\n\n        res.status(201).json({ pollid, message: \"poll created successfully.\" });\n\n    } catch (error) {\n        console.error(\"error creating poll:\", error.message);\n        res.status(500).json({ message: \"error creating poll.\" });\n    }\n};\n\n\/\/ update poll\nexports.updatepoll = async (req, res) =&gt; {\n    const { pollid } = req.params;\n    const { question, options } = req.body;\n\n    if (!pollid || !options || !array.isarray(options) || options.length &lt; 2) {\n        return res.status(400).json({ message: \"invalid input data. at least two options are required.\" });\n    }\n\n    try {\n        const connection = await pool.getconnection();\n        await connection.begintransaction();\n\n        \/\/ fetch the existing poll\n        const [existingpoll] = await connection.execute(\n            'select question from poll_versions where poll_id = (select current_version_id from polls where poll_id = ?)',\n            [pollid]\n        );\n\n        if (existingpoll.length === 0) {\n            await connection.rollback();\n            connection.release();\n            return res.status(404).json({ message: \"poll not found.\" });\n        }\n\n        const currentquestion = existingpoll[0].question;\n\n        \/\/ check if the question has changed\n        if (currentquestion !== question) {\n            \/\/ create a new version since the question has changed\n            const [versionresult] = await connection.execute(\n                'insert into poll_versions (poll_id, question) values (?, ?)',\n                [pollid, question]\n            );\n\n            const versionid = versionresult.insertid;\n\n            \/\/ update the current version in the polls table\n            await connection.execute(\n                'update polls set current_version_id = ? where poll_id = ?',\n                [versionid, pollid]\n            );\n        }\n\n        \/\/ remove old options and insert new ones\n        await connection.execute('delete from options where poll_id = ?', [pollid]);\n\n        const optionqueries = options.map(option =&gt; {\n            return connection.execute(\n                'insert into options (poll_id, option_text) values (?, ?)',\n                [pollid, option]\n            );\n        });\n\n        await promise.all(optionqueries);\n\n        await connection.commit();\n        connection.release();\n\n        res.status(200).json({ message: \"poll updated successfully.\" });\n\n    } catch (error) {\n        console.error(\"error updating poll:\", error.message);\n        await connection.rollback();\n        res.status(500).json({ message: \"error updating poll.\" });\n    }\n};\n\n\/\/ delete poll\nexports.deletepoll = async (req, res) =&gt; {\n    const { pollid } = req.params;\n\n    try {\n        const connection = await pool.getconnection();\n\n        const [result] = await connection.execute(\n            'delete from polls where poll_id = ?',\n            [pollid]\n        );\n\n        connection.release();\n\n        if (result.affectedrows === 0) {\n            return res.status(404).json({ message: \"poll not found.\" });\n        }\n\n        res.status(200).json({ message: \"poll deleted successfully.\" });\n\n    } catch (error) {\n        console.error(\"error deleting poll:\", error.message);\n        res.status(500).json({ message: \"error deleting poll.\" });\n    }\n};\n\n\/\/ vote in poll\nexports.voteinpoll = async (req, res) =&gt; {\n    const { pollid } = req.params;\n    const { userid, option } = req.body;\n\n    if (!userid || !option) {\n        return res.status(400).json({ message: \"user id and option are required.\" });\n    }\n\n    try {\n        const connection = await pool.getconnection();\n\n        const [uservote] = await connection.execute(\n            'select * from votes where poll_id = ? and user_id = ?',\n            [pollid, userid]\n        );\n\n        if (uservote.length &gt; 0) {\n            connection.release();\n            return res.status(400).json({ message: \"user has already voted.\" });\n        }\n\n        const [optionresult] = await connection.execute(\n            'select option_id from options where poll_id = ? and option_text = ?',\n            [pollid, option]\n        );\n\n        if (optionresult.length === 0) {\n            connection.release();\n            return res.status(404).json({ message: \"option not found.\" });\n        }\n\n        const optionid = optionresult[0].option_id;\n\n        await connection.execute(\n            'insert into votes (poll_id, user_id, option_id) values (?, ?, ?)',\n            [pollid, userid, optionid]\n        );\n\n        connection.release();\n\n        res.status(200).json({ message: \"vote cast successfully.\" });\n\n    } catch (error) {\n        console.error(\"error casting vote:\", error.message);\n        res.status(500).json({ message: \"error casting vote.\" });\n    }\n};\n\n\/\/ view poll results\nexports.viewpollresults = async (req, res) =&gt; {\n    const { pollid } = req.params;\n\n    try {\n        const connection = await pool.getconnection();\n\n        const [poll] = await connection.execute(\n            'select * from polls where poll_id = ?',\n            [pollid]\n        );\n\n        if (poll.length === 0) {\n            connection.release();\n            return res.status(404).json({ message: \"poll not found.\" });\n        }\n\n        const [options] = await connection.execute(\n            'select option_text, count(votes.option_id) as vote_count from options ' +\n            'left join votes on options.option_id = votes.option_id ' +\n            'where options.poll_id = ? group by options.option_id',\n            [pollid]\n        );\n\n        connection.release();\n\n        res.status(200).json({\n            pollid: poll[0].poll_id,\n            question: poll[0].question,\n            results: options.reduce((acc, option) =&gt; {\n                acc[option.option_text] = option.vote_count;\n                return acc;\n            }, {})\n        });\n\n    } catch (error) {\n        console.error(\"error viewing poll results:\", error.message);\n        res.status(500).json({ message: \"error viewing poll results.\" });\n    }\n};\n<\/pre>\n<h3> \u7b2c 3 \u6b65\uff1a\u66f4\u65b0\u6295\u7968\u8def\u7ebf <\/h3>\n<p>\u786e\u4fdd\u5728 pollroutes.js \u4e2d\u6b63\u786e\u5b9a\u4e49\u8def\u7531\u3002<\/p>\n<h5> \u6587\u4ef6\uff1aroutes\/pollroutes.js <\/h5>\n<pre>const express = require('express');\nconst router = express.Router();\nconst pollController = require('..\/controllers\/pollController');\n\n\/\/ Routes\nrouter.post('\/polls', pollController.createPoll);\nrouter.put('\/polls\/:pollId', pollController.updatePoll);\nrouter.delete('\/polls\/:pollId', pollController.deletePoll);\nrouter.post('\/polls\/:pollId\/vote', pollController.voteInPoll);\nrouter.get('\/polls\/:pollId\/results', pollController.viewPollResults);\n\nmodule.exports = router;\n<\/pre>\n<h3> \u53d8\u66f4\u6458\u8981 <\/h3>\n<ol>\n<li>\n<p><strong>\u6570\u636e\u5e93\uff1a<\/strong><\/p>\n<ul>\n<li>\u66f4\u65b0\u4e86\u6295\u7968\u8868\u4ee5\u5305\u542b current_version_id\u3002<\/li>\n<li>\u521b\u5efa\u4e86 poll_versions \u8868\u6765\u8ddf\u8e2a\u95ee\u9898\u7248\u672c\u3002<\/li>\n<li>\u9009\u9879\u548c\u6295\u7968\u8868\u4fdd\u6301\u4e0d\u53d8\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>api\uff1a<\/strong><\/p>\n<ul>\n<li>\u521b\u5efa\u4e86\u4e00\u4e2a\u65b0\u7684 createpoll \u65b9\u6cd5\u6765\u521d\u59cb\u5316\u6c11\u610f\u8c03\u67e5\u548c\u7248\u672c\u3002<\/li>\n<li>\u66f4\u65b0\u4e86 updatepoll \u65b9\u6cd5\u4ee5\u5728\u521b\u5efa\u65b0\u7248\u672c\u4e4b\u524d\u68c0\u67e5\u95ee\u9898\u66f4\u6539\u3002<\/li>\n<li>\u6dfb\u52a0\u4e86\u6295\u7968\u548c\u67e5\u770b\u6295\u7968\u7ed3\u679c\u7684\u65b9\u6cd5\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u8def\u7ebf\uff1a<\/strong><\/p>\n<ul>\n<li>\u786e\u4fdd\u5b9a\u4e49\u6240\u6709\u5fc5\u8981\u7684\u8def\u7531\u6765\u5904\u7406\u6c11\u610f\u8c03\u67e5\u521b\u5efa\u3001\u66f4\u65b0\u3001\u6295\u7968\u548c\u7ed3\u679c\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<hr>\n<h2> \u6848\u4f8b2 <\/h2>\n<p><strong>\u5904\u7406 pollid \u9700\u8981\u662f uuid\uff08\u901a\u7528\u552f\u4e00\u6807\u8bc6\u7b26\uff09\u7684\u573a\u666f\u3002<\/strong><\/p>\n<p>\u4ee5\u4e0b\u662f\u5728\u8f6e\u8be2\u7cfb\u7edf\u4e2d\u4e3a thepollid \u5b9e\u73b0 uuid \u7684\u6b65\u9aa4\uff0c\u65e0\u9700\u63d0\u4f9b\u4ee3\u7801\uff1a<\/p>\n<h3> \u4e3a\u6295\u7968 id \u5b9e\u65bd uuid \u7684\u6b65\u9aa4 <\/h3>\n<ol>\n<li>\n<p>** \u6570\u636e\u5e93\u67b6\u6784\u66f4\u65b0\uff1a**<\/p>\n<ul>\n<li>\u4fee\u6539 polls\u3001poll_versions\u3001options \u548c votes \u8868\uff0c\u4ee5\u4f7f\u7528 char(36) \u4f5c\u4e3a poll_id \u800c\u4e0d\u662f\u6574\u6570\u3002<\/li>\n<li>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684 poll_versions \u8868\u6765\u5b58\u50a8\u7531 uuid \u94fe\u63a5\u7684\u6295\u7968\u95ee\u9898\u548c\u9009\u9879\u7684\u5386\u53f2\u7248\u672c\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>** uuid \u751f\u6210\uff1a**<\/p>\n<ul>\n<li>\u51b3\u5b9a\u751f\u6210uuid\u7684\u65b9\u6cd5\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u5e94\u7528\u7a0b\u5e8f\u73af\u5883\u4e2d\u7684\u5e93\u6216\u5185\u7f6e\u51fd\u6570\u6765\u521b\u5efauuid\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>** \u521b\u5efa\u6295\u7968\u903b\u8f91\uff1a**<\/p>\n<ul>\n<li>\u521b\u5efa\u65b0\u6295\u7968\u65f6\uff0c\u751f\u6210\u4e00\u4e2a uuid \u5e76\u5c06\u5176\u7528\u4f5c poll_id\u3002<\/li>\n<li>\u5c06\u65b0\u7684\u6295\u7968\u8bb0\u5f55\u63d2\u5165\u6295\u7968\u8868\u4e2d\u3002<\/li>\n<li>\u5c06\u521d\u59cb\u95ee\u9898\u63d2\u5165 poll_versions \u8868\u5e76\u5c06\u5176\u4e0e\u751f\u6210\u7684 uuid \u94fe\u63a5\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>** \u66f4\u65b0\u6295\u7968\u903b\u8f91\uff1a**<\/p>\n<ul>\n<li>\u66f4\u65b0\u6295\u7968\u65f6\uff1a<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u68c0\u67e5\u95ee\u9898\u662f\u5426\u5df2\u66f4\u6539\u3002<\/p>\n<ul>\n<li>\u5982\u679c\u95ee\u9898\u5df2\u66f4\u6539\uff0c\u8bf7\u5728poll_versions \u8868\u4e2d\u521b\u5efa\u4e00\u4e2a\u65b0\u7248\u672c\u6761\u76ee\u6765\u5b58\u50a8\u65e7\u95ee\u9898\u548c\u9009\u9879\u3002<\/li>\n<li>\u6839\u636e\u9700\u8981\u4f7f\u7528\u65b0\u95ee\u9898\u548c\u9009\u9879\u66f4\u65b0\u6295\u7968\u8868\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>** \u6295\u7968\u903b\u8f91\uff1a**<\/p>\n<ul>\n<li>\u66f4\u65b0\u6295\u7968\u673a\u5236\uff0c\u786e\u4fdd\u4f7f\u7528uuid\u4f5c\u4e3apoll_id\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u9a8c\u8bc1\u6295\u7968\u8bf7\u6c42\u4e2d\u63d0\u4f9b\u7684 uuid \u662f\u5426\u5b58\u5728\u4e8e polls \u8868\u4e2d\u3002<\/p>\n<\/li>\n<li>\n<p>** api \u66f4\u65b0\uff1a**<\/p>\n<ul>\n<li>\u4fee\u6539 api \u7aef\u70b9\u4ee5\u63a5\u53d7\u5e76\u8fd4\u56de poll_id \u7684 uuid\u3002<\/li>\n<li>\u786e\u4fdd\u6240\u6709 api \u64cd\u4f5c\uff08\u521b\u5efa\u3001\u66f4\u65b0\u3001\u5220\u9664\u3001\u6295\u7968\uff09\u4e00\u81f4\u5f15\u7528 uuid \u683c\u5f0f\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>** \u6d4b\u8bd5\uff1a**<\/p>\n<ul>\n<li>\u5f7b\u5e95\u6d4b\u8bd5\u5e94\u7528\u7a0b\u5e8f\uff0c\u786e\u4fdd\u5728\u6240\u6709\u573a\u666f\uff08\u521b\u5efa\u3001\u66f4\u65b0\u3001\u6295\u7968\u548c\u68c0\u7d22\u6295\u7968\u7ed3\u679c\uff09\u4e2d\u6b63\u786e\u5904\u7406 uuid\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>** \u6587\u6863\uff1a**<\/p>\n<ul>\n<li>\u66f4\u65b0\u60a8\u7684 api \u6587\u6863\u4ee5\u53cd\u6620 poll_id \u683c\u5f0f\u7684\u66f4\u6539\u4ee5\u53ca\u4e0e\u7248\u672c\u63a7\u5236\u548c uuid \u4f7f\u7528\u76f8\u5173\u7684\u4efb\u4f55\u65b0\u884c\u4e3a\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\uff0c\u60a8\u53ef\u4ee5\u5728\u8f6e\u8be2\u7cfb\u7edf\u4e2d\u6210\u529f\u5b9e\u73b0 pollid \u7684 uuid\uff0c\u540c\u65f6\u786e\u4fdd\u6570\u636e\u5b8c\u6574\u6027\u548c\u5386\u53f2\u8ddf\u8e2a\u3002<\/p>\n<hr>\n<h2> \u6848\u4f8b3 <\/h2>\n<p><strong>\u7a7a\u6216\u65e0\u6548\u9009\u9879<\/strong><\/p>\n<p><strong>\u9a8c\u8bc1\u65b9\u6cd5\uff1a<\/strong><\/p>\n<ul>\n<li> <strong>api \u8f93\u5165\u9a8c\u8bc1\uff1a<\/strong> \u5728 api \u7aef\u70b9\u4e2d\u5b9e\u65bd\u68c0\u67e5\uff0c\u4ee5\u9a8c\u8bc1\u8bf7\u6c42\u6b63\u6587\u4e2d\u63d0\u4f9b\u7684\u9009\u9879\u4e0d\u4e3a\u7a7a\u5e76\u6ee1\u8db3\u7279\u5b9a\u6761\u4ef6\uff08\u4f8b\u5982\uff0c\u5982\u679c\u4e0d\u5141\u8bb8\uff0c\u5219\u4e0d\u5f97\u4f7f\u7528\u7279\u6b8a\u5b57\u7b26\uff09\u3002<\/li>\n<li> <strong>\u53cd\u9988\u673a\u5236\uff1a<\/strong>\u5982\u679c\u9009\u9879\u65e0\u6548\u6216\u4e3a\u7a7a\uff0c\u5411\u7528\u6237\u63d0\u4f9b\u6e05\u6670\u7684\u9519\u8bef\u6d88\u606f\uff0c\u6307\u5bfc\u4ed6\u4eec\u7ea0\u6b63\u8f93\u5165\u3002<\/li>\n<\/ul>\n<hr>\n<h2> \u6848\u4f8b4 <\/h2>\n<p><strong>\u91cd\u590d\u9009\u9879<\/strong><\/p>\n<p><strong>\u552f\u4e00\u6027\u68c0\u67e5\uff1a<\/strong><\/p>\n<ul>\n<li> <strong>\u9884\u63d2\u5165\u9a8c\u8bc1\uff1a<\/strong> \u5728\u5c06\u9009\u9879\u6dfb\u52a0\u5230\u6295\u7968\u4e4b\u524d\uff0c\u68c0\u67e5\u6570\u636e\u5e93\u4e2d\u73b0\u6709\u9009\u9879\u662f\u5426\u6709\u91cd\u590d\u9879\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u8f6e\u8be2 id \u67e5\u8be2\u9009\u9879\u8868\u5e76\u5c06\u5176\u4e0e\u65b0\u9009\u9879\u8fdb\u884c\u6bd4\u8f83\u6765\u5b8c\u6210\u3002<\/li>\n<li> <strong>\u7528\u6237\u53cd\u9988\uff1a<\/strong>\u5982\u679c\u68c0\u6d4b\u5230\u91cd\u590d\u9009\u9879\uff0c\u5219\u8fd4\u56de\u4e00\u6761\u6709\u610f\u4e49\u7684\u9519\u8bef\u6d88\u606f\uff0c\u901a\u77e5\u7528\u6237\u54ea\u4e9b\u9009\u9879\u662f\u91cd\u590d\u7684\uff0c\u4ece\u800c\u5141\u8bb8\u4ed6\u4eec\u76f8\u5e94\u5730\u4fee\u6539\u5176\u8f93\u5165\u3002<\/li>\n<\/ul>\n<hr>\n<h2> \u6848\u4f8b5 <\/h2>\n<p><strong>\u95ee\u9898\u957f\u5ea6\u9650\u5236<\/strong><\/p>\n<p><strong>\u5b57\u7b26\u9650\u5236\uff1a<\/strong><\/p>\n<ul>\n<li> <strong>api \u9a8c\u8bc1\uff1a<\/strong> \u8bbe\u7f6e api \u4e2d\u6295\u7968\u95ee\u9898\u548c\u9009\u9879\u7684\u6700\u5927\u5b57\u7b26\u9650\u5236\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u5728\u521b\u5efa\u548c\u66f4\u65b0\u8fc7\u7a0b\u4e2d\u68c0\u67e5\u95ee\u9898\u7684\u957f\u5ea6\u548c\u6bcf\u4e2a\u9009\u9879\u6765\u5b8c\u6210\u3002<\/li>\n<li> <strong>\u7528\u6237\u754c\u9762\u53cd\u9988\uff1a<\/strong>\u5b9e\u65bd\u5ba2\u6237\u7aef\u9a8c\u8bc1\uff0c\u4ee5\u4fbf\u5728\u7528\u6237\u8f93\u5165\u65f6\u8d85\u51fa\u5b57\u7b26\u9650\u5236\u65f6\u5411\u7528\u6237\u63d0\u4f9b\u5373\u65f6\u53cd\u9988\uff0c\u589e\u5f3a\u7528\u6237\u4f53\u9a8c\u3002<\/li>\n<\/ul>\n<hr>\n<h2> \u6848\u4f8b6 <\/h2>\n<p><strong>\u6295\u7968\u8fc7\u671f<\/strong><\/p>\n<p><strong>\u8fc7\u671f\u673a\u5236\uff1a<\/strong><\/p>\n<ul>\n<li> <strong>\u65f6\u95f4\u6233\u7ba1\u7406\uff1a<\/strong> \u5c06\u65f6\u95f4\u6233\u5b57\u6bb5\u6dfb\u52a0\u5230\u6295\u7968\u8868\u4e2d\uff0c\u4ee5\u8bb0\u5f55\u6bcf\u4e2a\u6295\u7968\u7684\u521b\u5efa\u65f6\u95f4\uff0c\u8fd8\u53ef\u4ee5\u9009\u62e9\u53e6\u4e00\u4e2a\u5b57\u6bb5\u6765\u8bb0\u5f55\u5230\u671f\u65e5\u671f\u3002<\/li>\n<li> <strong>\u8ba1\u5212\u68c0\u67e5\uff1a<\/strong> \u5b9e\u65bd\u540e\u53f0\u4f5c\u4e1a\u6216 cron \u4efb\u52a1\uff0c\u5b9a\u671f\u68c0\u67e5\u8fc7\u671f\u7684\u8f6e\u8be2\u5e76\u5c06\u5176\u5728\u6570\u636e\u5e93\u4e2d\u6807\u8bb0\u4e3a\u975e\u6d3b\u52a8\u72b6\u6001\u3002\u8fd9\u8fd8\u53ef\u4ee5\u5305\u62ec\u963b\u6b62\u5bf9\u8fc7\u671f\u6c11\u610f\u8c03\u67e5\u8fdb\u884c\u6295\u7968\u3002<\/li>\n<li> <strong>\u7528\u6237\u901a\u77e5\uff1a<\/strong>\uff08\u53ef\u9009\uff09\u901a\u77e5\u6295\u7968\u521b\u5efa\u8005\u548c\u53c2\u4e0e\u8005\u5373\u5c06\u5230\u671f\u7684\u65e5\u671f\uff0c\u4ee5\u4fbf\u4ed6\u4eec\u5728\u6295\u7968\u53d8\u4e3a\u975e\u6d3b\u52a8\u72b6\u6001\u4e4b\u524d\u53c2\u4e0e\u6295\u7968\u3002<\/li>\n<\/ul>\n<hr>\n<p>\u8bf7\u5148\u53c2\u8003\u4ee5\u4e0b\u6587\u7ae0\uff1a<\/p>\n<ol>\n<li>\n<p>\u5e95\u5c42\u8bbe\u8ba1\uff1a\u6295\u7968\u7cfb\u7edf\uff1a\u57fa\u672c<\/p>\n<\/li>\n<li>\n<p>\u5e95\u5c42\u8bbe\u8ba1\uff1a\u8f6e\u8be2\u7cfb\u7edf &#8211; \u4f7f\u7528 node.js \u548c sql<\/p>\n<\/li>\n<\/ol>\n<p>\u66f4\u591a\u8be6\u60c5\uff1a<\/p>\n<p>\u83b7\u53d6\u6240\u6709\u4e0e\u7cfb\u7edf\u8bbe\u8ba1\u76f8\u5173\u7684\u6587\u7ae0<br \/> \u6807\u7b7e\uff1asystemdesignwithzeeshanali<\/p>\n<p>\u7cfb\u7edf\u8bbe\u8ba1\u4e0ezeeshanali<\/p>\n<p>git\uff1ahttps:\/\/github.com\/zeeshanali-0704\/systemdesignwithzeeshanali<\/p>\n<p>\u4eca\u5929\u5173\u4e8e\u300a\u5e95\u5c42\u8bbe\u8ba1\uff1a\u8f6e\u8be2\u7cfb\u7edf &#8211; \u8fb9\u7f18\u60c5\u51b5\u300b\u7684\u5185\u5bb9\u5c31\u4ecb\u7ecd\u5230\u8fd9\u91cc\u4e86\uff0c\u662f\u4e0d\u662f\u5b66\u8d77\u6765\u4e00\u76ee\u4e86\u7136\uff01\u60f3\u8981\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u5185\u5bb9\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n<p>      \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1adev.to \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb\u5220\u9664    <\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   GORM \u5b57\u6bb5\u6807\u7b7e\uff1aGo \u8bed\u6cd5\u6269\u5c55\u8fd8\u662f GORM \u72ec\u6709\u529f\u80fd\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u5e95\u5c42\u8bbe\u8ba1\uff1a\u8f6e\u8be2\u7cfb\u7edf &#8211; \u8fb9\u7f18\u60c5\u51b5 \u6536\u85cf \u4eca\u65e5\u4e0d\u80af\u57cb\u5934\uff0c\u660e\u65e5\u4f55\u4ee5\u62ac\u5934\uff01\u6bcf\u65e5\u4e00\u53e5\u52aa\u529b\u81ea\u5df1\u7684\u8bdd\u54c8\u54c8~\u54c8\u55bd\uff0c\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u7bc7\u300a\u5e95\u5c42\u8bbe\u8ba1\uff1a\u8f6e\u8be2\u7cfb\u7edf &#8211; \u8fb9\u7f18\u60c5\u51b5\u300b\uff0c\u4e3b\u8981\u5185\u5bb9\u662f\u8bb2\u89e3\u7b49\u7b49\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u53ef\u4ee5\u6536\u85cf\u6216\u8005\u6709\u66f4\u597d\u7684\u5efa\u8bae\u5728\u8bc4\u8bba\u63d0\u51fa\uff0c\u6211\u90fd\u4f1a\u8ba4\u771f\u770b\u7684\uff01\u5927\u5bb6\u4e00\u8d77\u8fdb\u6b65\uff0c\u4e00\u8d77\u5b66\u4e60\uff01 \u76ee\u5f55 \u6848\u4f8b 1 &#8211; \u5904\u7406\u66f4\u65b0\u7684\u7248\u672c\u63a7\u5236 \u60c5\u51b5 2 &#8211; pollid \u4f5c\u4e3a uuid \u800c\u4e0d\u662f\u4e3b\u952e \u60c5\u51b5 3 &#8211; \u9009\u9879\u4e3a\u7a7a\u6216\u65e0\u6548 \u6848\u4f8b 4 &#8211; \u91cd\u590d\u9009\u9879 \u6848\u4f8b 5 &#8211; \u95ee\u9898\u957f\u5ea6\u9650\u5236 \u6848\u4f8b 6 &#8211; \u6295\u7968\u8fc7\u671f \u8bf7\u5148\u53c2\u8003\u4ee5\u4e0b\u6587\u7ae0\uff1a \u5e95\u5c42\u8bbe\u8ba1\uff1a\u6295\u7968\u7cfb\u7edf\uff1a\u57fa\u672c \u5e95\u5c42\u8bbe\u8ba1\uff1a\u8f6e\u8be2\u7cfb\u7edf &#8211; \u4f7f\u7528 node.js \u548c sql \u8fb9\u7f18\u60c5\u51b5\u5904\u7406 \u6848\u4f8b1 \u8981\u7ba1\u7406\u6295\u7968\u95ee\u9898\u548c\u9009\u9879\u7684\u66f4\u65b0\uff0c\u540c\u65f6\u4fdd\u7559\u4e0e\u540c\u4e00\u6295\u7968 id \u5173\u8054\u7684\u5148\u524d\u8be6\u7ec6\u4fe1\u606f\uff0c\u60a8\u53ef\u4ee5\u5b9e\u73b0\u7248\u672c\u63a7\u5236\u7cfb\u7edf\u3002\u8fd9\u79cd\u65b9\u6cd5\u5141\u8bb8\u60a8\u8ddf\u8e2a\u6bcf\u6b21\u6c11\u610f\u8c03\u67e5\u7684\u5386\u53f2\u6570\u636e\uff0c\u786e\u4fdd\u5373\u4f7f\u5728\u66f4\u65b0\u540e\u4e5f\u4fdd\u7559\u65e7\u7684\u8be6\u7ec6\u4fe1\u606f\u3002 \u7b2c 1 \u6b65\uff1a\u6570\u636e\u5e93\u67b6\u6784\u66f4\u6539 \u66f4\u65b0\u6295\u7968\u8868 \u5c06 current_version_id \u5217\u6dfb\u52a0\u5230 [&hellip;]<\/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-53575","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53575","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=53575"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53575\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=53575"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=53575"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=53575"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}