From 80c9e55d9863bad4506599f2538a2eae69b6955e Mon Sep 17 00:00:00 2001 From: wanglei <34475144@qqcom> Date: Tue, 28 Oct 2025 10:33:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=BB=84=E7=BB=87=E6=9E=B6?= =?UTF-8?q?=E6=9E=84=E7=9B=B8=E5=85=B3=E4=B8=9A=E5=8A=A1=E6=96=87=E4=BB=B6?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E4=BF=AE=E6=94=B9=E6=96=87=E4=BB=B6=E4=B8=AD?= =?UTF-8?q?=E9=9C=80=E8=A6=81=E7=9A=84=E6=8E=A5=E5=8F=A3=EF=BC=8C=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E6=9F=A5=E8=AF=A2=E3=80=81=E5=A2=9E=E5=8A=A0=E3=80=81?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=92=8C=E4=BF=AE=E6=94=B9=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E8=A1=A8=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=AF=B9=E5=85=B6=E5=AE=83?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=8D=E6=AD=A3=E7=A1=AE=E7=9A=84=E6=B3=A8?= =?UTF-8?q?=E9=87=8A=E8=BF=9B=E8=A1=8C=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/system/organization.lua | 78 ++++++++++++++++++++++++++ src/model/organization.lua | 12 ++++ src/service/system/account.lua | 24 ++++---- src/service/system/application.lua | 2 +- src/service/system/organization.lua | 87 +++++++++++++++++++++++++++++ src/service/system/permission.lua | 2 +- src/service/system/role.lua | 2 +- src/service/system/user.lua | 2 +- 8 files changed, 193 insertions(+), 16 deletions(-) create mode 100644 src/api/system/organization.lua create mode 100644 src/model/organization.lua create mode 100644 src/service/system/organization.lua diff --git a/src/api/system/organization.lua b/src/api/system/organization.lua new file mode 100644 index 0000000..4680c7e --- /dev/null +++ b/src/api/system/organization.lua @@ -0,0 +1,78 @@ +--- +--- Generated by EmmyLua(https://github.com/EmmyLua) +--- Created by admin. +--- DateTime: 2025/10/28 10:05 +--- + +local _M = {} + +local dao = require("service.system.organization") +local resp = require("util.response") +local validator = require("util.validator") + +--获取所有组织架构信息 +function _M.get_allorganization() + local code,ret = dao.getAllOrganization() + local result = resp:json(code, ret) + resp:send(result) +end + +--根据组织id获取组织架构信息 +function _M.get_organization(m) + local id = m.id + local code,ret = dao.getOrganization(id) + local result = resp:json(code, ret) + resp:send(result) +end + +--根据组织id添加组织架构信息 +function _M.add_organization() + --获取请求头并进行校验 + if validator.checkReqHeader() == false then + local result = resp:json(0x000001) + resp:send(result) + return + end + --读取请求体的数据 + ngx.req.read_body() + --获取请求数据 + local body_data = ngx.req.get_body_data() + --判断请求体数据是否为空 + if body_data == nil then + local result = resp:json(0x000001) + resp:send(result) + return + end + --ngx.say(body_data) + local code, ret = dao.addOrganization(body_data) + local result = resp:json(code, ret) + resp:send(result) +end + +--根据组织id删除组织架构信息 +function _M.delete_organization(m) + local id = m.id + local code, ret = dao.deleteOrganization(id) + local result = resp:json(code, ret) + resp:send(result) +end + +--根据组织id删除组织架构信息 +function _M.update_organization(m) + local id = m.id + --读取请求体的数据 + ngx.req.read_body() + --获取请求数据 + local body_data = ngx.req.get_body_data() + --判断请求体数据是否为空 + if body_data == nil then + local result = resp:json(0x000001) + resp:send(result) + return + end + local code, ret = dao.updateOrganization(id, body_data) + local result = resp:json(code, ret) + resp:send(result) +end + +return _M \ No newline at end of file diff --git a/src/model/organization.lua b/src/model/organization.lua new file mode 100644 index 0000000..324ea70 --- /dev/null +++ b/src/model/organization.lua @@ -0,0 +1,12 @@ +--- +--- Generated by EmmyLua(https://github.com/EmmyLua) +--- Created by admin. +--- DateTime: 2025/10/28 10:14 +--- 数据表模型文件 + +--引用使用的库文件 +local Model = require("util.model") + +--创建一个数据表相关的模型 +local Organization = Model:new('tbl_organization') +return Organization \ No newline at end of file diff --git a/src/service/system/account.lua b/src/service/system/account.lua index 70b7b06..c5f9442 100644 --- a/src/service/system/account.lua +++ b/src/service/system/account.lua @@ -1,25 +1,25 @@ --- --- Generated by EmmyLua(https://github.com/EmmyLua) --- Created by . ---- DateTime: 2025/9/25 08:19 ---- 业务逻辑 对用户数据表进行数据表业务处理 +--- DateTime: 2025/9/25 08:25 +--- 业务逻辑 对账户数据表进行数据表业务处理 local validator = require("util.validator") local helpers = require("util.helpers") local account = require("model.account") local _M = {} --- 查询数据表中的所有账号信息 +-- 查询数据表中的所有账户信息 function _M.getAllAccount() return account:all() end ---根据账号id获取账号信息 +--根据账户id获取账户信息 function _M.getAccount(id) return account.find(id) end ---增加账号信息到数据表 +--增加账户信息到数据表 function _M.addAccount(jsonData) --验证数据的正确性,错误时返回 local success, result = validator.checkJson(jsonData) @@ -31,7 +31,7 @@ function _M.addAccount(jsonData) for key, value in pairs(result) do if key == "name" then name = value end end - --根据账号进行验证是否存在 + --根据账户进行验证是否存在 local code, res = account:where("name", "=", name):get() if code ~= 0 then return 0x000001, res @@ -42,25 +42,25 @@ function _M.addAccount(jsonData) num = num + 1 end end - --账号存在时返回账号已经存在 + --账户存在时返回账户已经存在 if num <= 0 then return 0x01000C, nil end --键值为id产生uuid数据值,增加到json中 result.id = helpers.getUuid() local ret = helpers.convert_json(result) - -- 创建一个账号 + -- 创建一个账户 return account:create('{'..ret..'}') end ---增加账号信息到数据表 +--删除账户信息到数据表 function _M.deleteAccount(id) return account:delete(id) end ---更新账号信息到数据表 +--更新账户信息到数据表 function _M.updateAccount(id, jsonData) - --根据账号id进行验证账号是否存在 + --根据账户id进行验证账户是否存在 local code, res = account:find(id) if code ~= 0 then return 0x000001, res @@ -71,7 +71,7 @@ function _M.updateAccount(id, jsonData) num = num + 1 end end - --账号不存在返回错误 + --账户不存在返回错误 if num <= 0 then return 0x01000C, nil end diff --git a/src/service/system/application.lua b/src/service/system/application.lua index 683ee9d..68a2fe9 100644 --- a/src/service/system/application.lua +++ b/src/service/system/application.lua @@ -65,7 +65,7 @@ function _M.addApplication(jsonData) return application:create('{'..ret..'}') end ---增加应用信息到数据表 +--删除应用信息到数据表 function _M.deleteApplication(id) return application:delete(id) end diff --git a/src/service/system/organization.lua b/src/service/system/organization.lua new file mode 100644 index 0000000..df0d5b3 --- /dev/null +++ b/src/service/system/organization.lua @@ -0,0 +1,87 @@ +--- +--- Generated by EmmyLua(https://github.com/EmmyLua) +--- Created by . +--- DateTime: 2025/9/28 10:22 +--- 业务逻辑 对组织架构数据表进行数据表业务处理 +local validator = require("util.validator") +local helpers = require("util.helpers") +local organization = require("model.organization") + +local _M = {} + +-- 查询数据表中的所有组织架构信息 +function _M.getAllOrganization() + return organization:all() +end + +--根据组织架构id获取组织架构信息 +function _M.getOrganization(id) + return organization.find(id) +end + +--增加组织架构息到数据表 +function _M.addOrganization(jsonData) + --验证数据的正确性,错误时返回 + local success, result = validator.checkJson(jsonData) + if success == false then + return 0x000001, result + end + --解析json中的键和数据值 + local name = "" + for key, value in pairs(result) do + if key == "name" then name = value end + end + --根据组织架构进行验证是否存在 + local code, res = organization:where("name", "=", name):get() + if code ~= 0 then + return 0x000001, res + end + local num = 0 + for _, row in ipairs(res) do + for key, value in pairs(row) do + num = num + 1 + end + end + --组织架构存在时返回组织架构已经存在 + if num <= 0 then + return 0x01000C, nil + end + --键值为id产生uuid数据值,增加到json中 + result.id = helpers.getUuid() + local ret = helpers.convert_json(result) + -- 创建一个组织架构 + return organization:create('{'..ret..'}') +end + +--删除组织架构信息到数据表 +function _M.deleteOrganization(id) + return organization:delete(id) +end + +--更新组织架构信息到数据表 +function _M.updateOrganization(id, jsonData) + --根据组织架构id进行验证组织架构是否存在 + local code, res = organization:find(id) + if code ~= 0 then + return 0x000001, res + end + local num = 0 + for _, row in ipairs(res) do + for key, value in pairs(row) do + num = num + 1 + end + end + --账号不存在返回错误 + if num <= 0 then + return 0x01000C, nil + end + --验证数据的正确性,错误时返回 + local success, result = validator.checkJson(jsonData) + if success == false then + return 0x000001, result + end + --对数据内容进行更新 + return organization:where('id', '=', id):update(jsonData) +end + +return _M diff --git a/src/service/system/permission.lua b/src/service/system/permission.lua index 26e6da3..d6551a3 100644 --- a/src/service/system/permission.lua +++ b/src/service/system/permission.lua @@ -60,7 +60,7 @@ function _M.addPermission(jsonData) return permission:create('{'..ret..'}') end ---增加权限信息到数据表 +--删除权限信息到数据表 function _M.deletePermission(id) return permission:delete(id) end diff --git a/src/service/system/role.lua b/src/service/system/role.lua index b2ba84a..24e9e88 100644 --- a/src/service/system/role.lua +++ b/src/service/system/role.lua @@ -53,7 +53,7 @@ function _M.addRole(jsonData) return role:create('{'..ret..'}') end ---增加角色信息到数据表 +--删除角色信息到数据表 function _M.deleteRole(id) return role:delete(id) end diff --git a/src/service/system/user.lua b/src/service/system/user.lua index c3b69dd..4990ae3 100644 --- a/src/service/system/user.lua +++ b/src/service/system/user.lua @@ -57,7 +57,7 @@ function _M.addUser(jsonData) return user:create('{'..ret..'}') end ---增加用户信息到数据表 +--删除用户信息到数据表 function _M.deleteUser(id) return user:delete(id) end