diff --git a/conf/system/auth.conf b/conf/auth/auth.conf similarity index 100% rename from conf/system/auth.conf rename to conf/auth/auth.conf diff --git a/conf/nginx.conf b/conf/nginx.conf index 4d4ff95..4ae53a5 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -30,9 +30,11 @@ http { access_log off; } + include 'auth/auth.conf'; + include 'system/account.conf'; include 'system/application.conf'; - include 'system/organization.conf'; + include 'system/department.conf'; include 'system/permission.conf'; include 'system/role.conf'; include 'system/user.conf'; diff --git a/src/dao/account.lua b/src/dao/account.lua index 5bc11a0..0a8de22 100644 --- a/src/dao/account.lua +++ b/src/dao/account.lua @@ -4,9 +4,89 @@ --- DateTime: 2025/10/25 16:36 --- 数据表模型文件 +local helpers = require("share.helpers") --引用使用的库文件 local Model = require("share.model") - --创建一个数据表相关的模型 -local Account = Model:new('tbl_account') -return Account \ No newline at end of file +local accountModel = Model:new('sys_account') + +local _M = {} + +--判断账户是否存在 +local function isExistAccount(id) + --根据账户id进行验证账户是否存在 + local code, res = accountModel:find(id) + if code ~= 0 then + return false + end + local num = 0 + if res ~= nil then + num = table.getn(res) + end + --账户不存在返回错误 + if num <= 0 then + return false + end + return true +end + +-- 查询数据表中的所有账户信息 +function _M.getSystemAccounts(pageNum, pageSize) + return accountModel:paginate(pageNum, pageSize) +end + +--根据账户id获取账户信息 +function _M.getSystemAccount(id) + return accountModel:find(id) +end + +--增加账户信息到数据表 +function _M.addSystemAccount(jsonData) + --解析json中的键和数据值 + local name = jsonData['name'] + + --根据账户进行验证账户是否存在 + local code, res = accountModel:where("name", "=", name):get() + if code ~= 0 then + return 0x000001,res + end + local num = 0 + if res ~= nil then + num = table.getn(res) + end + --账户存在时返回账户已经存在 + if num > 0 then + return 0x01000C,nil + end + + --键值为id产生uuid数据值,增加到json中 + jsonData.id = helpers.getUuid() + local ret = helpers.convert_json(jsonData) + -- 创建一个账户 + return accountModel:create('{'..ret..'}') +end + +--删除账户信息到数据表 +function _M:deleteSystemAccount(id) + --根据账户id进行验证账户是否存在 + local ok = isExistAccount(id) + --账户不存在则返回 + if ok == false then + return 0x000001,nil + end + return accountModel:delete(id) +end + +--更新账户信息到数据表 +function _M:updateSystemAccount(id, jsonData) + --根据账户id进行验证账户是否存在 + local ok = isExistAccount(id) + --账户不存在则返回 + if ok == false then + return 0x000001,nil + end + --对数据内容进行更新 + return accountModel:where('id', '=', id):update(jsonData) +end + +return _M diff --git a/src/dao/application.lua b/src/dao/application.lua index a1b5c72..8ffb90c 100644 --- a/src/dao/application.lua +++ b/src/dao/application.lua @@ -4,9 +4,104 @@ --- DateTime: 2025/10/25 16:36 --- 数据表模型文件 +local helpers = require("share.helpers") --引用使用的库文件 -local Model = require("share.model") - +local model = require("share.model") --创建一个数据表相关的模型 -local Application = Model:new('tbl_application') -return Application \ No newline at end of file +local applicationModel = model:new('sys_application') + +local _M = {} + +--判断应用是否存在 +local function isExistApplication(id) + --根据应用id进行验证应用是否存在 + local code, res = applicationModel:find(id) + if code ~= 0 then + return false + end + local num = 0 + if res ~= nil then + num = table.getn(res) + end + --应用不存在返回错误 + if num <= 0 then + return false + end + return true +end + +-- 查询数据表中的所有应用信息 +function _M.getSystemApplications(pageNum, pageSize) + return applicationModel:paginate(pageNum, pageSize) +end + +--根据应用id获取应用信息 +function _M.getSystemApplication(id) + return applicationModel.find(id) +end + +--根据组织id获取应用信息 +function _M.getOrganizationApplication(id) + --todo + return applicationModel.find(id) +end + +--根据用户id获取应用信息 +function _M.getUserApplication(id) + --todo + return applicationModel.find(id) +end + +--增加应用信息到数据表 +function _M.addSystemApplication(jsonData) + --解析json中的键和数据值 + local name = jsonData['name'] + + --根据应用进行验证是否存在 + local code, res = applicationModel:where("name", "=", name):get() + if code ~= 0 then + return 0x000001, res + end + local num = 0 + if res ~= nil then + num = table.getn(res) + end + --用户存在时返回用户已经存在 + if num > 0 then + return 0x01000C,nil + end + --应用存在时返回应用已经存在 + if num > 0 then + return 0x01000C, nil + end + --键值为id产生uuid数据值,增加到json中 + jsonData.id = helpers.getUuid() + local ret = helpers.convert_json(jsonData) + -- 创建一个应用 + return applicationModel:create('{'..ret..'}') +end + +--删除应用信息到数据表 +function _M.deleteApplication(id) + --根据用户id进行验证用户是否存在 + local ok = isExistApplication(id) + --用户不存在则返回 + if ok == false then + return 0x000001,nil + end + return applicationModel:delete(id) +end + +--更新应用信息到数据表 +function _M.updateApplication(id, jsonData) + --根据用户id进行验证用户是否存在 + local ok = isExistApplication(id) + --用户不存在则返回 + if ok == false then + return 0x000001,nil + end + --对数据内容进行更新 + return applicationModel:where('id', '=', id):update(jsonData) +end + +return _M \ No newline at end of file diff --git a/src/dao/department.lua b/src/dao/department.lua index 14af9af..2af2fe7 100644 --- a/src/dao/department.lua +++ b/src/dao/department.lua @@ -4,9 +4,88 @@ --- DateTime: 2025/10/28 10:14 --- 数据表模型文件 +local helpers = require("share.helpers") --引用使用的库文件 -local Model = require("share.model") - +local model = require("share.model") --创建一个数据表相关的模型 -local Organization = Model:new('tbl_organization') -return Organization \ No newline at end of file +local departmentModel = model:new('sys_department') + +local _M = {} + +--判断组织是否存在 +local function isExistDepartment(id) + --根据组织id进行验证组织是否存在 + local code, res = departmentModel:find(id) + if code ~= 0 then + return false + end + local num = 0 + if res ~= nil then + num = table.getn(res) + end + --组织不存在返回错误 + if num <= 0 then + return false + end + return true +end + +-- 查询数据表中的所有组织架构信息 +function _M.getSystemDepartments(pageNum, pageSize) + return departmentModel:paginate(pageNum, pageSize) +end + +--根据组织架构id获取组织架构信息 +function _M.getSystemDepartment(id) + return departmentModel.find(id) +end + +--增加组织架构息到数据表 +function _M.addSystemDepartment(jsonData) + --解析json中的键和数据值 + local name = jsonData['name'] + + --根据组织名称进行验证组织是否存在 + local code, res = departmentModel:where("name", "=", name):get() + if code ~= 0 then + return 0x000001,res + end + local num = 0 + if res ~= nil then + num = table.getn(res) + end + --组织架构存在时返回组织架构已经存在 + if num > 0 then + return 0x01000C, nil + end + --键值为id产生uuid数据值,增加到json中 + jsonData.id = helpers.getUuid() + local ret = helpers.convert_json(jsonData) + -- 创建一个组织架构 + return departmentModel:create('{'..ret..'}') +end + +--删除组织架构信息到数据表 +function _M.deleteSystemDepartment(id) + --根据组织id进行验证组织是否存在 + local ok = isExistDepartment(id) + --组织不存在则返回 + if ok == false then + return 0x000001,nil + end + return departmentModel:delete(id) +end + +--更新组织架构信息到数据表 +function _M.updateSystemDepartment(id, jsonData) + --根据组织id进行验证组织是否存在 + local ok = isExistDepartment(id) + --组织不存在则返回 + if ok == false then + return 0x000001,nil + end + --对数据内容进行更新 + return departmentModel:where('id', '=', id):update(jsonData) +end + +return _M diff --git a/src/dao/permission.lua b/src/dao/permission.lua index 9a8c471..6a043b3 100644 --- a/src/dao/permission.lua +++ b/src/dao/permission.lua @@ -4,9 +4,96 @@ --- DateTime: 2025/10/25 16:36 --- 数据表模型文件 +local helpers = require("share.helpers") --引用使用的库文件 -local Model = require("share.model") - +local model = require("share.model") --创建一个数据表相关的模型 -local Permission = Model:new('tbl_permission') -return Permission \ No newline at end of file +local permissionModel = model:new('sys_permission') + +local _M = {} + +--判断权限是否存在 +local function isExistPermission(id) + --根据权限id进行验证权限是否存在 + local code, res = permissionModel:find(id) + if code ~= 0 then + return false + end + local num = 0 + if res ~= nil then + num = table.getn(res) + end + --权限不存在返回错误 + if num <= 0 then + return false + end + return true +end + +-- 查询数据表中的所有权限信息 +function _M.getSystemPermissions(pageNum, pageSize) + return permissionModel:paginate(pageNum, pageSize) +end + +--根据权限id获取权限信息 +function _M.getSystemPermission(id) + return permissionModel.find(id) +end + +--根据角色id获取角色的权限 +function _M.getSystemPermissionByRole(id) + --权限表与角色表进行表关系查询返回结果 + --todo + return permissionModel.first(id) +end + +--增加权限信息到数据表 +function _M.addSystemPermission(jsonData) + --解析json中的键和数据值 + local name = jsonData['name'] + + --根据权限名称进行验证权限是否存在 + local code, res = permissionModel:where("name", "=", name):get() + if code ~= 0 then + return 0x000001,res + end + local num = 0 + if res ~= nil then + num = table.getn(res) + end + --权限存在时返回权限已经存在 + if num > 0 then + return 0x01000C,nil + end + + --键值为id产生uuid数据值,增加到json中 + jsonData.id = helpers.getUuid() + local ret = helpers.convert_json(jsonData) + -- 创建一个权限 + return permissionModel:create('{'..ret..'}') +end + +--删除权限信息到数据表 +function _M.deleteSystemPermission(id) + --根据权限id进行验证权限是否存在 + local ok = isExistPermission(id) + --权限不存在则返回 + if ok == false then + return 0x000001,nil + end + return permissionModel:delete(id) +end + +--更新权限信息到数据表 +function _M.updateSystemPermission(id, jsonData) + --根据权限id进行验证权限是否存在 + local ok = isExistPermission(id) + --权限不存在则返回 + if ok == false then + return 0x000001,nil + end + --对数据内容进行更新 + return permissionModel:where('id', '=', id):update(jsonData) +end + +return _M diff --git a/src/dao/role.lua b/src/dao/role.lua index eac1493..34bde81 100644 --- a/src/dao/role.lua +++ b/src/dao/role.lua @@ -4,9 +4,89 @@ --- DateTime: 2025/10/25 16:36 --- 数据表模型文件 +local helpers = require("share.helpers") --引用使用的库文件 -local Model = require("share.model") - +local model = require("share.model") --创建一个数据表相关的模型 -local Role = Model:new('tbl_role') -return Role \ No newline at end of file +local roleModel = model:new('sys_role') + +local _M = {} + +--判断角色是否存在 +local function isExistRole(id) + --根据角色id进行验证角色是否存在 + local code, res = roleModel:find(id) + if code ~= 0 then + return false + end + local num = 0 + if res ~= nil then + num = table.getn(res) + end + --角色不存在返回错误 + if num <= 0 then + return false + end + return true +end + +-- 查询数据表中的所有角色信息 +function _M.getSystemRoles(pageNum, pageSize) + return roleModel:paginate(pageNum, pageSize) +end + +--根据角色id获取角色信息 +function _M.getSystemRole(id) + return roleModel:find(id) +end + +--增加角色信息到数据表 +function _M.addSystemRole(jsonData) + --解析json中的键和数据值 + local roleName = jsonData['role_name'] + + --根据角色、手机号、邮箱进行验证角色是否存在 + local code, res = roleModel:where("role_name", "=", roleName):get() + if code ~= 0 then + return 0x000001,res + end + local num = 0 + if res ~= nil then + num = table.getn(res) + end + --角色存在时返回角色已经存在 + if num > 0 then + return 0x01000C,nil + end + + --键值为id产生uuid数据值,增加到json中 + jsonData.id = helpers.getUuid() + local ret = helpers.convert_json(jsonData) + -- 创建一个角色 + return roleModel:create('{'..ret..'}') +end + +--删除角色信息到数据表 +function _M:deleteSystemRole(id) + --根据角色id进行验证角色是否存在 + local ok = isExistRole(id) + --角色不存在则返回 + if ok == false then + return 0x000001,nil + end + return roleModel:delete(id) +end + +--更新角色信息到数据表 +function _M:updateSystemRole(id, jsonData) + --根据角色id进行验证角色是否存在 + local ok = isExistRole(id) + --角色不存在则返回 + if ok == false then + return 0x000001,nil + end + --对数据内容进行更新 + return roleModel:where('id', '=', id):update(jsonData) +end + +return _M \ No newline at end of file diff --git a/src/dao/user.lua b/src/dao/user.lua index 53bcfc6..777cb31 100644 --- a/src/dao/user.lua +++ b/src/dao/user.lua @@ -31,17 +31,17 @@ local function isExistUser(id) end -- 查询数据表中的所有用户信息 -function _M.getAllUser(pageNum, pageSize) +function _M.getSystemUsers(pageNum, pageSize) return userModel:paginate(pageNum, pageSize) end --根据用户id获取用户信息 -function _M.getUser(id) +function _M.getSystemUser(id) return userModel:find(id) end --增加用户信息到数据表 -function _M.addUser(jsonData) +function _M.addSystemUser(jsonData) --解析json中的键和数据值 local userName = jsonData['username'] local phone = jsonData['phone'] @@ -69,7 +69,7 @@ function _M.addUser(jsonData) end --删除用户信息到数据表 -function _M:deleteUser(id) +function _M:deleteSystemUser(id) --根据用户id进行验证用户是否存在 local ok = isExistUser(id) --用户不存在则返回 @@ -80,7 +80,7 @@ function _M:deleteUser(id) end --更新用户信息到数据表 -function _M:updateUser(id, jsonData) +function _M:updateSystemUser(id, jsonData) --根据用户id进行验证用户是否存在 local ok = isExistUser(id) --用户不存在则返回 diff --git a/src/service/system/auth.lua b/src/service/auth/auth.lua similarity index 100% rename from src/service/system/auth.lua rename to src/service/auth/auth.lua diff --git a/src/service/system/account.lua b/src/service/system/account.lua index 1a971a2..8c65ba9 100644 --- a/src/service/system/account.lua +++ b/src/service/system/account.lua @@ -3,65 +3,71 @@ --- Created by . --- DateTime: 2025/9/25 08:25 --- 业务逻辑 对账户数据表进行数据表业务处理 -local validator = require("util.validator") -local helpers = require("share.helpers") -local account = require("model.account") +local jsonschema = require("jsonschema") +local resp = require("util.response") +local accountDao = require("dao.account") local _M = {} -local dao = require("service.system.account") -local resp = require("util.response") +-- 定义一个JSON Schema +local schema = { + {type = "object", properties = { + {name = "name", type = "string"}, + {name = "password", type = "string"}, + {name = "real_name", type = "string"}, + {name = "department", type = "string"}, + {name = "office_phone", type = "string"}, + {name = "telephone", type = "string"}, + {name = "display_name", type = "string"}, + }, required = {"username"}} +} --获取所有账户信息 -function _M.get_allaccount() - local code,ret = dao.getAllAccount() +function _M.getSystemAccounts() + local pageNum = ngx.var.pagenum or 1 + local pageSize = ngx.var.pagesize or 10 + local code,ret = accountDao.getSystemAccounts(pageNum, pageSize) local result = resp:json(code, ret) resp:send(result) end --根据账户id获取账户信息 -function _M.get_account(m) +function _M.getSystemAccount(m) local id = m.id - local code,ret = dao.getAccount(id) + local code,ret = accountDao.getSystemAccount(id) local result = resp:json(code, ret) resp:send(result) end --根据账户id获取账户信息 -function _M.add_account() - --获取请求头并进行校验 - if validator.checkReqHeader() == false then - local result = resp:json(0x000001) - resp:send(result) - return - end +function _M.addSystemAccount() --读取请求体的数据 ngx.req.read_body() --获取请求数据 local body_data = ngx.req.get_body_data() - --判断请求体数据是否为空 - if body_data == nil then + -- 验证数据是否符合schema + local ok, err = jsonschema:generate_validator(body_data, schema) + --验证失败则返回 + if not ok then local result = resp:json(0x000001) resp:send(result) return end --ngx.say(body_data) - local code, ret = dao.addAccount(body_data) + local code, ret = accountDao.addSystemAccount(body_data) local result = resp:json(code, ret) resp:send(result) end --根据账户id删除账户信息 -function _M.delete_account(m) - local id = m.id - local code, ret = dao.deleteAccount(id) +function _M.deleteSystemAccount(m) + local code, ret = accountDao.deleteSystemAccount(m.id) local result = resp:json(code, ret) resp:send(result) end --根据账户id删除账户信息 -function _M.update_account(m) - local id = m.id +function _M.updateSystemAccount(m) --读取请求体的数据 ngx.req.read_body() --获取请求数据 @@ -72,84 +78,9 @@ function _M.update_account(m) resp:send(result) return end - local code, ret = dao.updateAccount(id, body_data) + local code, ret = accountDao.updateSystemAccount(m.id, body_data) local result = resp:json(code, ret) resp:send(result) end --- 查询数据表中的所有账户信息 -function _M.getAllAccount() - return account:all() -end - ---根据账户id获取账户信息 -function _M.getAccount(id) - return account.find(id) -end - ---增加账户信息到数据表 -function _M.addAccount(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 = account: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 account:create('{'..ret..'}') -end - ---删除账户信息到数据表 -function _M.deleteAccount(id) - return account:delete(id) -end - ---更新账户信息到数据表 -function _M.updateAccount(id, jsonData) - --根据账户id进行验证账户是否存在 - local code, res = account: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 account:where('id', '=', id):update(jsonData) -end - return _M diff --git a/src/service/system/application.lua b/src/service/system/application.lua index 970f86e..ea9d755 100644 --- a/src/service/system/application.lua +++ b/src/service/system/application.lua @@ -3,182 +3,102 @@ --- Created by . --- DateTime: 2025/9/27 16:02 --- 业务逻辑 对应用数据表进行数据表业务处理 -local validator = require("util.validator") -local helpers = require("share.helpers") -local application = require("model.application") +local jsonschema = require("jsonschema") +local resp = require("util.response") +local applicationDao = require("dao.application") local _M = {} -local dao = require("service.system.application") -local resp = require("util.response") -local validator = require("util.validator") +-- 定义一个JSON Schema +local schema = { + {type = "object", properties = { + {name = "name", type = "string"}, + {name = "display_name", type = "string"}, + {name = "logo", type = "string"}, + {name = "title", type = "string"}, + {name = "name", type = "string"}, + {name = "favicon", type = "string"}, + {name = "description", type = "string"}, + {name = "homepage_url", type = "string"}, + {name = "redirect_uris", type = "string"}, + }, required = {"name", "redirect_uris"}} +} --获取所有应用程序信息 -function _M.get_allapplication() - local code,ret = dao.getAllApplication() +function _M.getSystemApplications() + --获取页码和请求的数据量 + local pageNum = ngx.var.pagenum or 1 + local pageSize = ngx.var.pagesize or 10 + local code,ret = applicationDao.getSystemApplications() local result = resp:json(code, ret) resp:send(result) end --根据应用id获取应用信息 -function _M.get_application(m) - local id = m.id - local code,ret = dao.getApplication(id) +function _M.getSystemApplication(m) + local code,ret = applicationDao.getSystemApplication(m.id) local result = resp:json(code, ret) resp:send(result) end ---根据组织id获取权限的信息 -function _M.get_organization_application(m) - local id = m.id - local code,ret = dao.getOrganizationApplication(id) +--根据组织id获取应用信息 +function _M.getOrganizationApplication(m) + local code,ret = applicationDao.getOrganizationApplication(m.id) local result = resp:json(code, ret) resp:send(result) end ---根据用户id获取权限的信息 -function _M.get_user_application(m) - local id = m.id - local code,ret = dao.getUserApplication(id) +--根据用户id获取应用的信息 +function _M.getUserApplication(m) + local code,ret = applicationDao.getUserApplication(m.id) local result = resp:json(code, ret) resp:send(result) end --根据应用id获取应用信息 -function _M.add_application() - --获取请求头并进行校验 - if validator.checkReqHeader() == false then - local result = resp:json(0x000001) - resp:send(result) - return - end +function _M.addSystemApplication() --读取请求体的数据 ngx.req.read_body() --获取请求数据 local body_data = ngx.req.get_body_data() - --判断请求体数据是否为空 - if body_data == nil then + -- 验证数据是否符合schema + local ok, err = jsonschema:generate_validator(body_data, schema) + --验证失败则返回 + if not ok then local result = resp:json(0x000001) resp:send(result) return end --ngx.say(body_data) - local code, ret = dao.addApplication(body_data) + local code, ret = applicationDao.addApplication(body_data) local result = resp:json(code, ret) resp:send(result) end --根据应用id删除应用信息 -function _M.delete_application(m) - local id = m.id - local code, ret = dao.deleteApplication(id) +function _M.deleteSystemApplication(m) + local code, ret = applicationDao.deleteApplication(m.id) local result = resp:json(code, ret) resp:send(result) end --根据应用id删除应用信息 -function _M.update_application(m) - local id = m.id +function _M.updateSystemApplication(m) --读取请求体的数据 ngx.req.read_body() --获取请求数据 local body_data = ngx.req.get_body_data() - --判断请求体数据是否为空 - if body_data == nil then + -- 验证数据是否符合schema + local ok, err = jsonschema:generate_validator(body_data, schema) + --验证失败则返回 + if not ok then local result = resp:json(0x000001) resp:send(result) return end - local code, ret = dao.updateApplication(id, body_data) + local code, ret = applicationDao.updateSystemApplication(m.id, body_data) local result = resp:json(code, ret) resp:send(result) end --- 查询数据表中的所有应用信息 -function _M.getAllApplication() - return application:all() -end - ---根据应用id获取应用信息 -function _M.getApplication(id) - return application.find(id) -end - ---根据组织id获取应用信息 -function _M.getOrganizationApplication(id) - --todo - return application.find(id) -end - ---根据用户id获取应用信息 -function _M.getUserApplication(id) - --todo - return application.find(id) -end - ---增加应用信息到数据表 -function _M.addApplication(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 = application: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 application:create('{'..ret..'}') -end - ---删除应用信息到数据表 -function _M.deleteApplication(id) - return application:delete(id) -end - ---更新应用信息到数据表 -function _M.updateApplication(id, jsonData) - --根据应用id进行验证应用是否存在 - local code, res = application: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 application:where('id', '=', id):update(jsonData) -end - return _M diff --git a/src/service/system/department.lua b/src/service/system/department.lua index 8f3d71d..f1fb930 100644 --- a/src/service/system/department.lua +++ b/src/service/system/department.lua @@ -3,154 +3,87 @@ --- Created by . --- DateTime: 2025/9/28 10:22 --- 业务逻辑 对组织架构数据表进行数据表业务处理 -local validator = require("util.validator") -local helpers = require("share.helpers") -local organization = require("model.organization") +local jsonschema = require("jsonschema") +local resp = require("util.response") +local departmentDao = require("dao.department") local _M = {} -local dao = require("service.system.department") -local resp = require("util.response") -local validator = require("util.validator") +-- 定义一个JSON Schema +local schema = { + {type = "object", properties = { + {name = "name", type = "string"}, + {name = "seq", type = "string"}, + {name = "description", type = "string"}, + {name = "create_by", type = "string"}, + {name = "update_by", type = "string"}, + {name = "parent_id", type = "string"}, + {name = "leader", type = "string"}, + {name = "status", type = "string"}, + }, required = {"name"}} +} --获取所有组织架构信息 -function _M.get_allorganization() - local code,ret = dao.getAllOrganization() +function _M.getSystemDepartments() + --获取页码和请求的数据量 + local pageNum = ngx.var.pagenum or 1 + local pageSize = ngx.var.pagesize or 10 + local code,ret = departmentDao.getSystemDepartments(pageNum, pageSize) 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) +function _M.getSystemDepartment(m) + local code,ret = departmentDao.getSystemDepartment(m.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 +function _M.addSystemDepartment() --读取请求体的数据 ngx.req.read_body() --获取请求数据 local body_data = ngx.req.get_body_data() - --判断请求体数据是否为空 - if body_data == nil then + -- 验证数据是否符合schema + local ok, err = jsonschema:generate_validator(body_data, schema) + --验证失败则返回 + if not ok then local result = resp:json(0x000001) resp:send(result) return end --ngx.say(body_data) - local code, ret = dao.addOrganization(body_data) + local code, ret = departmentDao.addSystemDepartment(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) +function _M.deleteSystemDepartment(m) + local code, ret = departmentDao.deleteSystemDepartment(m.id) local result = resp:json(code, ret) resp:send(result) end --根据组织id删除组织架构信息 -function _M.update_organization(m) - local id = m.id +function _M.updateSystemDepartment(m) --读取请求体的数据 ngx.req.read_body() --获取请求数据 local body_data = ngx.req.get_body_data() - --判断请求体数据是否为空 - if body_data == nil then + -- 验证数据是否符合schema + local ok, err = jsonschema:generate_validator(body_data, schema) + --验证失败则返回 + if not ok then local result = resp:json(0x000001) resp:send(result) return end - local code, ret = dao.updateOrganization(id, body_data) + local code, ret = departmentDao.updateSystemDepartment(m.id, body_data) local result = resp:json(code, ret) resp:send(result) end --- 查询数据表中的所有组织架构信息 -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 9504b88..eeb0e44 100644 --- a/src/service/system/permission.lua +++ b/src/service/system/permission.lua @@ -3,169 +3,94 @@ --- Created by . --- DateTime: 2025/9/27 17:06 --- 业务逻辑 对权限数据表进行数据表业务处理 -local validator = require("util.validator") -local helpers = require("share.helpers") -local permission = require("model.permission") +local jsonschema = require("jsonschema") +local resp = require("util.response") +local permissionDao = require("dao.permission") local _M = {} -local dao = require("service.system.permission") -local resp = require("util.response") -local validator = require("util.validator") +-- 定义一个JSON Schema +local schema = { + {type = "object", properties = { + {name = "username", type = "string"}, + {name = "phone", type = "string"}, + {name = "email", type = "string"}, + {name = "idcard", type = "string"}, + {name = "name", type = "string"}, + {name = "office_phone", type = "string"}, + {name = "telephone", type = "string"}, + {name = "display_name", type = "string"}, + }, required = {"username", "phone", "email", "idcard"}} +} --获取所有权限信息 -function _M.get_allpermission() - local code,ret = dao.getAllPermission() +function _M.getSystemPermissions() + --获取页码和请求的数据量 + local pageNum = ngx.var.pagenum or 1 + local pageSize = ngx.var.pagesize or 10 + local code,ret = permissionDao.getSystemPermissions(pageNum, pageSize) local result = resp:json(code, ret) resp:send(result) end --根据权限id获取权限信息 function _M.get_permission(m) - local id = m.id - local code,ret = dao.getPermission(id) + local code,ret = permissionDao.getPermission(m.id) local result = resp:json(code, ret) resp:send(result) end --根据角色id获取使用的权限 -function _M.get_permission_by_role(m) - local id = m.id - local code,ret = dao.getPermissionByRole(id) +function _M.getSystemPermissionByRole(m) + local code,ret = dao.getPermissionByRole(m.id) local result = resp:json(code, ret) resp:send(result) end ---根据账号id获取账号信息 -function _M.add_permission() - --获取请求头并进行校验 - if validator.checkReqHeader() == false then - local result = resp:json(0x000001) - resp:send(result) - return - end +--根据权限id获取账号信息 +function _M.addSystemPermission() --读取请求体的数据 ngx.req.read_body() --获取请求数据 local body_data = ngx.req.get_body_data() - --判断请求体数据是否为空 - if body_data == nil then + -- 验证数据是否符合schema + local ok, err = jsonschema:generate_validator(body_data, schema) + --验证失败则返回 + if not ok then local result = resp:json(0x000001) resp:send(result) return end --ngx.say(body_data) - local code, ret = dao.addPermission(body_data) + local code, ret = permissionDao.addPermission(body_data) local result = resp:json(code, ret) resp:send(result) end --根据账号id删除账号信息 -function _M.delete_permission(m) - local id = m.id - local code, ret = dao.deletePermission(id) +function _M.deleteSystemPermission(m) + local code, ret = permissionDao.deleteSystemPermission(m.id) local result = resp:json(code, ret) resp:send(result) end --根据账号id删除账号信息 -function _M.update_permission(m) - local id = m.id +function _M.updateSystemPermission(m) --读取请求体的数据 ngx.req.read_body() --获取请求数据 local body_data = ngx.req.get_body_data() - --判断请求体数据是否为空 - if body_data == nil then + -- 验证数据是否符合schema + local ok, err = jsonschema:generate_validator(body_data, schema) + --验证失败则返回 + if not ok then local result = resp:json(0x000001) resp:send(result) return end - local code, ret = dao.updatePermission(id, body_data) + local code, ret = permissionDao.updatePermission(m.id, body_data) local result = resp:json(code, ret) resp:send(result) end --- 查询数据表中的所有权限信息 -function _M.getAllPermission() - return permission:all() -end - ---根据权限id获取权限信息 -function _M.getPermission(id) - return permission.find(id) -end - ---根据角色id获取角色的权限 -function _M.getPermissionByRole(id) - --权限表与角色表进行表关系查询返回结果 - --todo - return permission.first(id) -end - ---增加权限信息到数据表 -function _M.addPermission(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 = permission: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 permission:create('{'..ret..'}') -end - ---删除权限信息到数据表 -function _M.deletePermission(id) - return permission:delete(id) -end - ---更新权限信息到数据表 -function _M.updatePermission(id, jsonData) - --根据权限id进行验证权限是否存在 - local code, res = permission: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 permission:where('id', '=', id):update(jsonData) -end - return _M diff --git a/src/service/system/role.lua b/src/service/system/role.lua index 3e7c2bb..1d056a0 100644 --- a/src/service/system/role.lua +++ b/src/service/system/role.lua @@ -3,154 +3,84 @@ --- Created by . --- DateTime: 2025/9/27 15:19 --- 业务逻辑 对用户角色数据表进行数据表业务处理 -local validator = require("util.validator") -local helpers = require("share.helpers") -local role = require("model.role") +local jsonschema = require("jsonschema") +local resp = require("util.response") +local roleDao = require("dao.role") local _M = {} -local dao = require("service.system.role") -local resp = require("util.response") -local validator = require("util.validator") +-- 定义一个JSON Schema +local schema = { + {type = "object", properties = { + {name = "role_name", type = "string"}, + {name = "description", type = "string"}, + {name = "create_by", type = "string"}, + {name = "update_by", type = "string"}, + }, required = {"role_name"}} +} --获取所有角色信息 -function _M.get_allrole() - local code,ret = dao.getAllRole() +function _M.getSystemRoles() + --获取页码和请求的数据量 + --local args = ngx.req.get_uri_args() + local pageNum = ngx.var.pagenum or 1 + local pageSize = ngx.var.pagesize or 10 + local code,ret = roleDao.getSystemRoles(pageNum, pageSize) local result = resp:json(code, ret) resp:send(result) end --根据角色id获取角色信息 -function _M.get_role(m) - local id = m.id - local code,ret = dao.getRole(id) +function _M.getSystemRole(m) + local code,ret = roleDao.getSystemRole(m.id) local result = resp:json(code, ret) resp:send(result) end --根据角色id获取角色信息 -function _M.add_role() - --获取请求头并进行校验 - if validator.checkReqHeader() == false then - local result = resp:json(0x000001) - resp:send(result) - return - end +function _M.addSystemRole() --读取请求体的数据 ngx.req.read_body() --获取请求数据 local body_data = ngx.req.get_body_data() - --判断请求体数据是否为空 - if body_data == nil then + -- 验证数据是否符合schema + local ok, err = jsonschema:generate_validator(body_data, schema) + --验证失败则返回 + if not ok then local result = resp:json(0x000001) resp:send(result) return end --ngx.say(body_data) - local code, ret = dao.addRole(body_data) + local code, ret = roleDao.addSystemRole(body_data) local result = resp:json(code, ret) resp:send(result) end --根据角色id删除角色信息 -function _M.delete_role(m) - local id = m.id - local code, ret = dao.deleteRole(id) +function _M.deleteSystemRole(m) + local code, ret = roleDao.deleteSystemRole(m.id) local result = resp:json(code, ret) resp:send(result) end --根据角色id删除角色信息 -function _M.update_role(m) - local id = m.id +function _M.updateSystemRole(m) --读取请求体的数据 ngx.req.read_body() --获取请求数据 local body_data = ngx.req.get_body_data() - --判断请求体数据是否为空 - if body_data == nil then + -- 验证数据是否符合schema + local ok, err = jsonschema:generate_validator(body_data, schema) + --验证失败则返回 + if not ok then local result = resp:json(0x000001) resp:send(result) return end - local code, ret = dao.updateRole(id, body_data) + local code, ret = roleDao.updateSystemRole(m.id, body_data) local result = resp:json(code, ret) resp:send(result) end --- 查询数据表中的所有角色信息 -function _M.getAllRole() - return role:all() -end - ---根据角色id获取角色信息 -function _M.getRole(id) - return role.find(id) -end - ---增加角色信息到数据表 -function _M.addRole(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 = role: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 role:create('{'..ret..'}') -end - ---删除角色信息到数据表 -function _M.deleteRole(id) - return role:delete(id) -end - ---更新角色信息到数据表 -function _M.updateRole(id, jsonData) - --根据角色id进行验证角色是否存在 - local code, res = role: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 role:where('id', '=', id):update(jsonData) -end - return _M diff --git a/src/service/system/user.lua b/src/service/system/user.lua index fa796d8..a2758c6 100644 --- a/src/service/system/user.lua +++ b/src/service/system/user.lua @@ -29,14 +29,14 @@ function _M.getSystemUsers() --local args = ngx.req.get_uri_args() local pageNum = ngx.var.pagenum or 1 local pageSize = ngx.var.pagesize or 10 - local code,ret = userDao.getAllUser(pageNum, pageSize) + local code,ret = userDao.getSystemUsers(pageNum, pageSize) local result = resp:json(code, ret) resp:send(result) end --根据用户id获取用户信息 function _M.getSystemUser(m) - local code,ret = userDao.getUser(m.id) + local code,ret = userDao.getSystemUser(m.id) local result = resp:json(code, ret) resp:send(result) end @@ -56,14 +56,14 @@ function _M.addSystemUser() return end --ngx.say(body_data) - local code, ret = userDao.addUser(body_data) + local code, ret = userDao.addSystemUser(body_data) local result = resp:json(code, ret) resp:send(result) end --根据用户id删除用户信息 function _M.deleteSystemUser(m) - local code, ret = userDao.deleteUser(m.id) + local code, ret = userDao.deleteSystemUser(m.id) local result = resp:json(code, ret) resp:send(result) end @@ -83,7 +83,7 @@ function _M.updateSystemUser(m) return end --将数据更新到数据表中 - local code, ret = userDao.updateUser(m.id, body_data) + local code, ret = userDao.updateSystemUser(m.id, body_data) local result = resp:json(code, ret) resp:send(result) end