diff --git a/app.js b/app.js index 2467e394330fa6dc683e56c34cce12dec26579fb..3c44dba89be583f62aa54e5b5c0c7d25df736415 100644 --- a/app.js +++ b/app.js @@ -20,12 +20,8 @@ app.use(express.urlencoded({ extended: false })); app.use(cookieParser()); app.use(express.static(path.join(__dirname, "public"))); -<<<<<<< HEAD mount(app, path.join(__dirname, '/routes'), true); // app.use('/api', require('./routes/lx')); -======= -mount(app, path.join(__dirname, "/routes"), true); ->>>>>>> 2bcad5652efdaeb163929fe15e3ce00c8558d383 // mount(app, path.join(__dirname, '/'), true); // catch 404 and forward to error handler diff --git a/node_modules/debug/package.json b/node_modules/debug/package.json index dc787ba76781de4c1d4721b69aa881a548365a90..606ff226171fe74b986c04c21801a50965cca16a 100644 --- a/node_modules/debug/package.json +++ b/node_modules/debug/package.json @@ -45,5 +45,8 @@ "debug/index.js": "browser.js", "debug/debug.js": "debug.js" } - } + }, + "__npminstall_done": true, + "_from": "debug@2.6.9", + "_resolved": "https://registry.npmmirror.com/debug/-/debug-2.6.9.tgz" } diff --git a/package.json b/package.json index d16923eb4adc3160d916aa6cdf9e2d43c26e13eb..dd586b87b8c654152464047b29279447640861c5 100644 --- a/package.json +++ b/package.json @@ -6,11 +6,12 @@ "start": "nodemon ./bin/www" }, "dependencies": { -<<<<<<< HEAD + "alipay-sdk": "^3.1.5", -======= + "@alicloud/sms-sdk": "^1.1.6", ->>>>>>> 2bcad5652efdaeb163929fe15e3ce00c8558d383 + + "@baiducloud/qianfan": "^0.2.0", "cookie-parser": "~1.4.4", "cors": "^2.8.5", "debug": "~2.6.9", diff --git a/routes/jwh.js b/routes/jwh.js index 50b7efb88933d60ad2ce8d50cbe971681b88de0e..bf362f98461686559b7d2e5dcaf09c5d957aff06 100644 --- a/routes/jwh.js +++ b/routes/jwh.js @@ -1,55 +1,80 @@ const express = require("express"); const router = express.Router(); -let { myroomModel, maint_jdModel, maintModel } = require("../models/model"); +let { myroomModel, maint_jdModel, maintModel } = require('../models/model') + //获取租住信息 -router.get("/getMyRoom", async (req, res) => { - let myRooms = await myroomModel.find(); - res.send({ - code: 200, - myRooms, - }); -}); +router.get('/getMyRoom', async (req, res) => { + let myRooms = await myroomModel.find(); + res.send({ + code: 200, + myRooms + }) +}) //设置默认信息 -router.post("/setDefault", async (req, res) => { - let { _id } = req.body; - console.log(_id); - await myroomModel.updateMany({}, { def_Status: 0 }); - - await myroomModel.findByIdAndUpdate(_id, { def_Status: 1 }); - res.send({ - code: 200, - msg: "设置成功", - }); -}); +router.post('/setDefault', async (req, res) => { + let { _id } = req.body; + console.log(_id) + await myroomModel.updateMany({}, { def_Status: 0 }); + + await myroomModel.findByIdAndUpdate(_id, { def_Status: 1 }); + res.send({ + code: 200, + msg: '设置成功' + }) +}) //添加住户信息 -router.post("/addMyRoom", async (req, res) => { - let { isObj } = req.body; - console.log(isObj); - await myroomModel.create(isObj); - res.send({ - code: 200, - msg: "添加成功", - }); -}); +router.post('/addMyRoom', async (req, res) => { + let { isObj } = req.body; + console.log(isObj) + await myroomModel.create(isObj); + res.send({ + code: 200, + msg: '添加成功' + }) +}) + //获取维修信息 -router.get("/getMaint", async (req, res) => { - let maints = await maintModel.find(); - res.send({ - code: 200, - maints, - }); -}); +router.get('/getMaint', async (req, res) => { + let maints = await maintModel.find(); + res.send({ + code: 200, + maints + }) +}) //添加维修信息 -router.post("/addMaint", async (req, res) => { - let { MaintInfo } = req.body; - console.log(MaintInfo); - await maintModel.create(MaintInfo); - res.send({ - code: 200, - msg: "添加成功", - }); +router.post('/addMaint', async (req, res) => { + let { MaintInfo } = req.body; + console.log(MaintInfo) + await maintModel.create(MaintInfo); + res.send({ + code: 200, + msg: '添加成功' + }) +}) + +const {ChatCompletion, setEnvVariable} = require("@baiducloud/qianfan"); + +// 设置百度云千帆的 API Key 和 Secret Key +setEnvVariable('QIANFAN_AK', '9lFqOXYm08vIooie9OpaiUIO'); +setEnvVariable('QIANFAN_SK', 'ZW4BlEcjgHhTZDOxXtmsbiNVzB5irdxV'); + +const client = new ChatCompletion({Endpoint: 'completions_pro'}); + +// 处理聊天请求的路由 +router.post('/chat', async (req, res) => { + try { + const { messages } = req.body; + const resp = await client.chat({ + messages + }); + res.json({ result: resp.result }); + } catch (error) { + console.error('Error in chat:', error); + res.status(500).json({ error: 'Internal Server Error' }); + } }); + module.exports = router;