diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..8eff93d07d844679d46d1b09d454e6027dcb43f5 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 zhanglp + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/bin/www b/bin/www index c424b139cba5ac78bdc1c7f9e98fab3f5abb1489..8e99965ba799d4c853ce962d095eec1bef4650ea 100644 --- a/bin/www +++ b/bin/www @@ -19,6 +19,7 @@ const roleRouter = require("../router/role"); const menuRouter = require("../router/menu"); const dictionaryType = require("../router/dictionaryType"); const dictionary = require("../router/dictionary"); +const dept = require("../router/dept"); app.use(indexRouter); app.use(loginRouter); app.use(userRouter); @@ -26,6 +27,7 @@ app.use(roleRouter); app.use(menuRouter); app.use(dictionaryType); app.use(dictionary); +app.use(dept); const server = app.listen(3002, function () { try { diff --git a/config/db.config.js b/config/db.config.js index fbd88288088e1b16806a794f9ab8ce5a02cd8de8..f7e151f75e817288cbbffa3e82ed25fd282e1af4 100644 --- a/config/db.config.js +++ b/config/db.config.js @@ -2,9 +2,9 @@ module.exports = { debug: false, //开启调试 host: "110.42.130.88", port: "3306", - user: "quick1", + user: "quick", password: "quick", - database: "quick1", + database: "quick", timezone: "08:00", dateStrings:true, stringifyObjects: true, //是否序列化对象 diff --git a/controllers/deptController.js b/controllers/deptController.js new file mode 100644 index 0000000000000000000000000000000000000000..23c6d331b4bd37353403704dbe406ae949ea1eed --- /dev/null +++ b/controllers/deptController.js @@ -0,0 +1,30 @@ +const { + getDeptListByPId, + getDeptList, + addDept, + updateDept, + deleteDept, +} = require("../services/deptServices"); +class DeptController { + constructor() {} + getListByPId(body) { + const {pId}=body + return getDeptListByPId(pId) + } + getList() { + return getDeptList() + } + add(body) { + const dept = body; + return addDept(dept); + } + update(body) { + const dept = body; + return updateDept(dept); + } + remove(body) { + const { id } = body; + return deleteDept(id); + } +} +module.exports = new DeptController(); diff --git a/model/deptModel.js b/model/deptModel.js new file mode 100644 index 0000000000000000000000000000000000000000..058e4bbe2f7b63d5d48f23b3666951fca877d2ae --- /dev/null +++ b/model/deptModel.js @@ -0,0 +1,42 @@ +const db = require("../config/dbPool"); +const { getDate } = require("../utils/index"); + +class DeptModel { + selectWhere(pId) { + const sql = "select * from sys_depts where p_id=?"; + const sqlArr = [pId]; + return db.queryAsync(sql, sqlArr); + } + select() { + const sql = "select * from sys_depts"; + const sqlArr = []; + return db.queryAsync(sql, sqlArr); + } + insert(dept) { + dept.create_time = getDate(); + const sql = + "insert into sys_depts(dept_id,name,p_id) values(?,?,?)"; + const sqlArr = [ + dept.deptId, + dept.name, + dept.pId, + ]; + return db.queryAsync(sql, sqlArr); + } + update(dept) { + const sql = + "update sys_depts set name=?,p_id=? where id=?"; + const sqlArr = [ + dept.name, + dept.pId, + dept.id, + ]; + return db.queryAsync(sql, sqlArr); + } + remove(id) { + const sql = "delete from sys_depts where id=?"; + const sqlArr = [id]; + return db.queryAsync(sql, sqlArr); + } +} +module.exports = new DeptModel(); diff --git a/router/dept.js b/router/dept.js new file mode 100644 index 0000000000000000000000000000000000000000..89a4c8844853fc0da2963d67682d33b1cfac9c32 --- /dev/null +++ b/router/dept.js @@ -0,0 +1,40 @@ +const express = require("express"); +const router = express.Router(); +const { + getListByPId, + getList, + add, + update, + remove, +} = require("../controllers/deptController"); + +router.get("/api/dept/getListByPId", (req, res) => { + const { query } = req; + getListByPId(query).then((data) => { + res.send(data); + }); +}); +router.get("/api/dept/getList", (req, res) => { + getList().then((data) => { + res.send(data); + }); +}); +router.post("/api/dept/add", (req, res) => { + const { body } = req; + add(body).then((data) => { + res.send(data); + }); +}); +router.post("/api/dept/update", (req, res) => { + const { body } = req; + update(body).then((data) => { + res.send(data); + }); +}); +router.post("/api/dept/delete", (req, res) => { + const { body } = req; + remove(body).then((data) => { + res.send(data); + }); +}); +module.exports = router; diff --git a/services/deptServices.js b/services/deptServices.js new file mode 100644 index 0000000000000000000000000000000000000000..1325ef8ee075953d7f721a67055356297e153e09 --- /dev/null +++ b/services/deptServices.js @@ -0,0 +1,59 @@ +const { + selectWhere, + select, + insert, + update, + remove + } = require("../model/deptModel"); + +class DeptServices { + constructor() {} + async getDeptListByPId(pid) { + const deptListResult = await selectWhere(pid); + const deptList = deptListResult.results && deptListResult.results; + const jsonObj = { + status: 0, + msg: "获取父级下的部门列表", + data:deptList + }; + return jsonObj; + } + async getDeptList() { + const deptListResult = await select(); + const deptList = deptListResult.results && deptListResult.results; + const jsonObj = { + status: 0, + msg: "部门列表", + data:deptList + }; + return jsonObj; + } + async addDept(dept) { + await insert(dept); + const jsonObj = { + status: 0, + msg: "添加部门成功", + data: null, + }; + return jsonObj; + } + async updateDept(dept) { + await update(dept); + const jsonObj = { + status: 0, + msg: "修改部门成功", + data: null, + }; + return jsonObj; + } + async deleteDept(id) { + await remove(id); + const jsonObj = { + status: 0, + msg: "删除部门成功", + data: null, + }; + return jsonObj; + } +} +module.exports = new DeptServices();