{"id":147,"date":"2020-03-28T23:19:57","date_gmt":"2020-03-28T15:19:57","guid":{"rendered":"https:\/\/thereisno.top:4430\/?p=147"},"modified":"2024-10-22T16:02:38","modified_gmt":"2024-10-22T08:02:38","slug":"unicloud%e4%ba%91%e5%87%bd%e6%95%b0%e6%93%8d%e4%bd%9c%e6%95%b0%e6%8d%ae%e5%ba%93","status":"publish","type":"post","link":"https:\/\/thereisno.top\/?p=147","title":{"rendered":"unicloud\u4e91\u51fd\u6570\u64cd\u4f5c\u6570\u636e\u5e93"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"\u521b\u5efa\u6570\u636e\u5e93\">\u521b\u5efa\u6570\u636e\u5e93<\/h2>\n\n\n\n<p>db_init.json<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n\t\"temperature\": {\n\t\t\"data\": &#91;]\n\t}\n}<\/code><\/pre>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u6dfb\u52a0\u8bb0\u5f55\">\u6dfb\u52a0\u8bb0\u5f55<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>'use strict';\nexports.main = async (event, context) =&gt; {\n  \/\/event\u4e3a\u5ba2\u6237\u7aef\u4e0a\u4f20\u7684\u53c2\u6570\n  console.log('event : ' + event)\n  const mydb = uniCloud.database();\n  const userCollection = mydb.collection('temperature');\n  let temperature=event.temperature;\n  \n  const currentTime=new Date();\n  \n  \/\/const currentTime = new Date().toISOString();\n  let month=currentTime.getMonth()+1;\n  let riqi=currentTime.getFullYear() + '-' + month + '-' + currentTime.getDate();\n  let hours=currentTime.getHours()+8;\n  let minutes=currentTime.getMinutes();\n  let seconds=currentTime.getSeconds();\n  let currentTimeStr = riqi+\" \"+hours+\":\"+minutes+\":\"+seconds;\n  \n  let AM_PM = \"\" +((hours &gt;= 12) ? \"PM \" : \"AM \" );\n  \n  let checkRecorded = await userCollection.where({\n  \triqi: riqi,\n\tampm:AM_PM\n  }).get();\n  const recordInfo = {\n\t  riqi:riqi,\n\t  ampm:AM_PM,\n\t  time:currentTimeStr,\n\t  temperature:temperature\n  };\n  if (checkRecorded.data &amp;&amp; checkRecorded.data.length &gt; 0) {\n  \treturn {\n  \t\tcode: -1,\n  \t\terrCode: 'Recorded',\n  \t\tmsg: '\u4eca\u5929\u5df2\u7ecf\u8bb0\u5f55'\n  \t}\n  }else{\n\t  let updateResult = await userCollection.add(recordInfo);\n\t  return {\n\t  \tcode: 0,\n\t  \tmsg: '\u8bb0\u5f55\u6dfb\u52a0\u6210\u529f'\n\t  }\n  }\n};<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u83b7\u53d6\u6570\u636e\u5217\u8868\">\u83b7\u53d6\u6570\u636e\u5217\u8868<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>'use strict';\nexports.main = async (event, context) =&gt; {\n  \/\/event\u4e3a\u5ba2\u6237\u7aef\u4e0a\u4f20\u7684\u53c2\u6570\n  console.log('event : ' + event)\n  const mydb = uniCloud.database();\n  const userCollection = mydb.collection('temperature');\n  \n  let res = await userCollection.orderBy(\"riqi\", \"desc\").get();\n  \n  console.log(res);\n  \/\/\u8fd4\u56de\u6570\u636e\u7ed9\u5ba2\u6237\u7aef\n  return res;\n};\n\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u6309\u7167id\u67e5\u8be2\">\u6309\u7167id\u67e5\u8be2<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>'use strict';\nexports.main = async (event, context) =&gt; {\n  \/\/event\u4e3a\u5ba2\u6237\u7aef\u4e0a\u4f20\u7684\u53c2\u6570\n  console.log('event : ' + event)\n  const mydb = uniCloud.database();\n  const userCollection = mydb.collection('temperature');\n  let id=event._id;\n  \n  let res = await userCollection.where({\"_id\":id}).get();\n  \n  console.log(res);\n  \/\/\u8fd4\u56de\u6570\u636e\u7ed9\u5ba2\u6237\u7aef\n  return res;\n};\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u5220\u9664\u6570\u636e\">\u5220\u9664\u6570\u636e<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>'use strict';\nexports.main = async (event, context) =&gt; {\n\t\/\/event\u4e3a\u5ba2\u6237\u7aef\u4e0a\u4f20\u7684\u53c2\u6570\n\tconsole.log('event : ' + event)\n\tconst mydb = uniCloud.database();\n\tconst userCollection = mydb.collection('temperature');\n\tlet id = event._id;\n\tconsole.log(\"-------\"+id)\n\tlet res = await userCollection.where({\"_id\": id}).remove();\n\t\/\/\u8fd4\u56de\u6570\u636e\u7ed9\u5ba2\u6237\u7aef\n\treturn {\n\t\tcode: 0,\n\t\tmsg: '\u8bb0\u5f55\u5220\u9664\u6210\u529f'\n\t};\n};<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u521b\u5efa\u6570\u636e\u5e93 db_init.json<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[44],"tags":[51],"class_list":["post-147","post","type-post","status-publish","format-standard","hentry","category-javascript","tag-unicloud"],"_links":{"self":[{"href":"https:\/\/thereisno.top\/index.php?rest_route=\/wp\/v2\/posts\/147","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thereisno.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thereisno.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thereisno.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thereisno.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=147"}],"version-history":[{"count":2,"href":"https:\/\/thereisno.top\/index.php?rest_route=\/wp\/v2\/posts\/147\/revisions"}],"predecessor-version":[{"id":1362,"href":"https:\/\/thereisno.top\/index.php?rest_route=\/wp\/v2\/posts\/147\/revisions\/1362"}],"wp:attachment":[{"href":"https:\/\/thereisno.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=147"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thereisno.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=147"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thereisno.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=147"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}