对整体框架进行修改,删除暂时不使用的lua文件

This commit is contained in:
wanglei 2025-10-29 17:29:17 +08:00
parent 9b3712e7fa
commit 795a60d78d
40 changed files with 1299 additions and 1307 deletions

View File

@ -30,8 +30,20 @@ http {
access_log off;
}
include 'system/account.conf';
include 'system/application.conf';
include 'system/organization.conf';
include 'system/permission.conf';
include 'system/role.conf';
include 'system/user.conf';
include 'system/test.conf';
#测试接口文件
location /testSQL {
content_by_lua_file '/home/frankly/work/AuthPlatform/src/test/testPostgres.lua';
}
location /cjson {
content_by_lua_file '/home/frankly/work/AuthPlatform/src/test/test.lua';
}
}
}

View File

@ -1,4 +1,4 @@
#API接口文件
location /api {
content_by_lua_file '/home/frankly/work/AuthPlatform/src/api/api.lua';
location /api/system/accounts {
content_by_lua_file '/home/frankly/work/AuthPlatform/src/api/system/account.lua';
}

View File

@ -1,8 +0,0 @@
#测试接口文件
location /testSQL {
content_by_lua_file '/home/frankly/work/AuthPlatform/src/test/testPostgres.lua';
}
location /cjson {
content_by_lua_file '/home/frankly/work/AuthPlatform/src/test/test.lua';
}

View File

@ -1,4 +1,4 @@
#API接口文件
location /api {
content_by_lua_file '/home/frankly/work/AuthPlatform/src/api/api.lua';
location /api/system/users {
content_by_lua_file '/home/frankly/work/AuthPlatform/src/api/system/user.lua';
}

View File

@ -1,265 +0,0 @@
---
--- Generated by EmmyLua(https://github.com/EmmyLua)
--- Created by admin.
--- DateTime: 2025/9/24 15:29
---
--解析url路由过滤库
local radix = require("resty.radixtree")
--数据表业务处理
local userApi = require("api.system.user")
local accountApi = require("api.system.account")
local roleApi = require("api.system.role")
local permissionApi = require("api.system.permission")
local applicationApi = require("api.system.application")
local organizationApi = require("api.system.organization")
--业务接口控制
local controllerApi = require("api.system.controller")
--定义相关路由前端接口url地址
local routes = {
--------------------------------------------
-----------数据表操作相关路由配置--------------
--------------------------------------------
--用户相关路由接口
{
paths = { "/api/get-user" },
metadata = { "metadata get-user" },
methods = { "GET" },
handler = userApi.get_alluser,
},
{
paths = { "/api/get-user/:id" },
metadata = { "metadata /api/get-user/id" },
methods = { "GET" },
handler = userApi.get_user,
},
{
paths = { "/api/delete-user/:id" },
metadata = { "metadata /api/delete-user/id" },
methods = { "DELETE" },
handler = userApi.delete_user,
},
{
paths = { "/api/add-user" },
metadata = { "metadata /api/add-user" },
methods = { "POST" },
handler = userApi.add_user,
},
{
paths = { "/api/update-user/:id" },
metadata = { "metadata /api/update-user/id" },
methods = { "PUT" },
handler = userApi.update_user,
},
--账户相关路由接口
{
paths = { "/api/get-account" },
metadata = { "metadata get-account" },
methods = { "GET" },
handler = accountApi.get_allaccount,
},
{
paths = { "/api/get-account/:id" },
metadata = { "metadata /api/get-account/id" },
methods = { "GET" },
handler = accountApi.get_account,
},
{
paths = { "/api/delete-account/:id" },
metadata = { "metadata /api/delete-account/id" },
methods = { "DELETE" },
handler = accountApi.delete_account,
},
{
paths = { "/api/add-account" },
metadata = { "metadata /api/add-account" },
methods = { "POST" },
handler = accountApi.add_account,
},
{
paths = { "/api/update-account/:id" },
metadata = { "metadata /api/update-account/id" },
methods = { "PUT" },
handler = accountApi.update_account,
},
--权限相关路由接口
{
paths = { "/api/get-permission" },
metadata = { "metadata get-permission" },
methods = { "GET" },
handler = permissionApi.get_allpermission,
},
{
paths = { "/api/get-permission/:id" },
metadata = { "metadata /api/get-permission/id" },
methods = { "GET" },
handler = permissionApi.get_permission,
},
{
paths = { "/api/delete-permission/:id" },
metadata = { "metadata /api/delete-permission/id" },
methods = { "DELETE" },
handler = permissionApi.delete_permission,
},
{
paths = { "/api/add-permission" },
metadata = { "metadata /api/add-permission" },
methods = { "POST" },
handler = permissionApi.add_permission,
},
{
paths = { "/api/update-permission/:id" },
metadata = { "metadata /api/update-permission/id" },
methods = { "PUT" },
handler = permissionApi.update_permission,
},
{
paths = { "/api/get-permission-by-role/:id" },
metadata = { "metadata /api/get-permission-by-role/id" },
methods = { "PUT" },
handler = permissionApi.get_permission_by_role,
},
--角色相关路由接口
{
paths = { "/api/get-role" },
metadata = { "metadata get-role" },
methods = { "GET" },
handler = roleApi.get_allrole,
},
{
paths = { "/api/get-role/:id" },
metadata = { "metadata /api/get-role/id" },
methods = { "GET" },
handler = roleApi.get_role,
},
{
paths = { "/api/delete-role/:id" },
metadata = { "metadata /api/delete-role/id" },
methods = { "DELETE" },
handler = roleApi.delete_role,
},
{
paths = { "/api/add-role" },
metadata = { "metadata /api/add-role" },
methods = { "POST" },
handler = roleApi.add_role,
},
{
paths = { "/api/update-role/:id" },
metadata = { "metadata /api/update-role/id" },
methods = { "PUT" },
handler = roleApi.update_role,
},
--应用相关路由接口
{
paths = { "/api/get-application" },
metadata = { "metadata get-application" },
methods = { "GET" },
handler = applicationApi.get_allapplication,
},
{
paths = { "/api/get-application/:id" },
metadata = { "metadata /api/get-application/id" },
methods = { "GET" },
handler = applicationApi.get_application,
},
{
paths = { "/api/get-organization-application/:id" },
metadata = { "metadata /api/get-organization-application/id" },
methods = { "GET" },
handler = applicationApi.get_organization_application,
},
{
paths = { "/api/get-user-application/:id" },
metadata = { "metadata /api/get-user-application/id" },
methods = { "GET" },
handler = applicationApi.get_user_application,
},
{
paths = { "/api/delete-application/:id" },
metadata = { "metadata /api/delete-application/id" },
methods = { "DELETE" },
handler = applicationApi.delete_application,
},
{
paths = { "/api/add-application" },
metadata = { "metadata /api/add-application" },
methods = { "POST" },
handler = applicationApi.add_application,
},
{
paths = { "/api/update-application/:id" },
metadata = { "metadata /api/update-application/id" },
methods = { "PUT" },
handler = applicationApi.update_application,
},
--组织架构相关路由接口
{
paths = { "/api/get-organization" },
metadata = { "metadata get-organization" },
methods = { "GET" },
handler = organizationApi.get_allorganization,
},
{
paths = { "/api/get-organization/:id" },
metadata = { "metadata /api/get-organization/id" },
methods = { "GET" },
handler = organizationApi.get_organization,
},
{
paths = { "/api/delete-organization/:id" },
metadata = { "metadata /api/delete-organization/id" },
methods = { "DELETE" },
handler = organizationApi.delete_organization,
},
{
paths = { "/api/add-organization" },
metadata = { "metadata /api/add-organization" },
methods = { "POST" },
handler = organizationApi.add_organization,
},
{
paths = { "/api/update-organization/:id" },
metadata = { "metadata /api/update-organization/id" },
methods = { "PUT" },
handler = organizationApi.update_organization,
},
--------------------------------------------
-------------用户登录相关路由配置--------------
--------------------------------------------
--用户登录路由接口
{
paths = { "/api/login" },
metadata = { "metadata /api/login" },
methods = { "POST" },
handler = controllerApi.login,
},
--用户退出路由接口
{
paths = { "/api/logout/:id" },
metadata = { "metadata /api/logout/id" },
methods = { "POST" },
handler = controllerApi.logout,
},
}
-- 初始化路由
local rx, err = radix.new(routes)
if not rx then
ngx.say("Not Found")
ngx.exit(ngx.HTTP_NOT_FOUND)
end
--获取访问的uri地址
local uri = ngx.var.uri
local opts = {
method = ngx.var.request_method,
matched = {}
}
-- 进行路由匹配和相关函数调用
local ok = rx:dispatch(uri, opts, opts.matched)
if not ok then
ngx.say("Not Found")
ngx.exit(ngx.HTTP_NOT_FOUND)
end

View File

@ -4,75 +4,58 @@
--- DateTime: 2025/9/25 08:19
---
local _M = {}
--解析url路由过滤库
local radix = require("resty.radixtree")
--数据表业务处理
local systemAccount = require("service.system.account")
local dao = require("service.system.account")
local resp = require("util.response")
local validator = require("util.validator")
--定义相关路由前端接口url地址
local routes = {
--用户相关路由接口
{
paths = { "/api/system/accounts" },
methods = { "GET" },
handler = systemAccount.getSystemAccounts,
},
{
paths = { "/api/system/accounts/:id" },
methods = { "GET" },
handler = systemAccount.getSystemAccount,
},
{
paths = { "/api/system/accounts" },
methods = { "POST" },
handler = systemAccount.addSystemAccount,
},
{
paths = { "/api/system/accounts/:id" },
methods = { "DELETE" },
handler = systemAccount.deleteSystemAccount,
},
{
paths = { "/api/system/accounts/:id" },
methods = { "PUT" },
handler = systemAccount.updateSystemAccount,
},
}
--获取所有账户信息
function _M.get_allaccount()
local code,ret = dao.getAllAccount()
local result = resp:json(code, ret)
resp:send(result)
-- 初始化路由
local rx, err = radix.new(routes)
if not rx then
ngx.say("Not Found")
ngx.exit(ngx.HTTP_NOT_FOUND)
end
--根据账户id获取账户信息
function _M.get_account(m)
local id = m.id
local code,ret = dao.getAccount(id)
local result = resp:json(code, ret)
resp:send(result)
end
--获取访问的uri地址
local uri = ngx.var.uri
local opts = {
method = ngx.var.request_method,
matched = {}
}
--根据账户id获取账户信息
function _M.add_account()
--获取请求头并进行校验
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.addAccount(body_data)
local result = resp:json(code, ret)
resp:send(result)
-- 进行路由匹配和相关函数调用
local ok = rx:dispatch(uri, opts, opts.matched)
if not ok then
ngx.say("Not Found")
ngx.exit(ngx.HTTP_NOT_FOUND)
end
--根据账户id删除账户信息
function _M.delete_account(m)
local id = m.id
local code, ret = dao.deleteAccount(id)
local result = resp:json(code, ret)
resp:send(result)
end
--根据账户id删除账户信息
function _M.update_account(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.updateAccount(id, body_data)
local result = resp:json(code, ret)
resp:send(result)
end
return _M

View File

@ -4,91 +4,58 @@
--- DateTime: 2025/9/25 08:19
---
local _M = {}
--解析url路由过滤库
local radix = require("resty.radixtree")
--数据表业务处理
local systemApplication = require("service.system.application")
local dao = require("service.system.application")
local resp = require("util.response")
local validator = require("util.validator")
--定义相关路由前端接口url地址
local routes = {
--用户相关路由接口
{
paths = { "/api/system/applications" },
methods = { "GET" },
handler = systemApplication.getSystemApplications,
},
{
paths = { "/api/system/applications/:id" },
methods = { "GET" },
handler = systemApplication.getSystemApplication,
},
{
paths = { "/api/system/applications" },
methods = { "POST" },
handler = systemApplication.addSystemApplication,
},
{
paths = { "/api/system/applications/:id" },
methods = { "DELETE" },
handler = systemApplication.deleteSystemApplication,
},
{
paths = { "/api/system/applications/:id" },
methods = { "PUT" },
handler = systemApplication.updateSystemApplication,
},
}
--获取所有应用程序信息
function _M.get_allapplication()
local code,ret = dao.getAllApplication()
local result = resp:json(code, ret)
resp:send(result)
-- 初始化路由
local rx, err = radix.new(routes)
if not rx then
ngx.say("Not Found")
ngx.exit(ngx.HTTP_NOT_FOUND)
end
--根据应用id获取应用信息
function _M.get_application(m)
local id = m.id
local code,ret = dao.getApplication(id)
local result = resp:json(code, ret)
resp:send(result)
end
--获取访问的uri地址
local uri = ngx.var.uri
local opts = {
method = ngx.var.request_method,
matched = {}
}
--根据组织id获取权限的信息
function _M.get_organization_application(m)
local id = m.id
local code,ret = dao.getOrganizationApplication(id)
local result = resp:json(code, ret)
resp:send(result)
-- 进行路由匹配和相关函数调用
local ok = rx:dispatch(uri, opts, opts.matched)
if not ok then
ngx.say("Not Found")
ngx.exit(ngx.HTTP_NOT_FOUND)
end
--根据用户id获取权限的信息
function _M.get_user_application(m)
local id = m.id
local code,ret = dao.getUserApplication(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
--读取请求体的数据
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.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)
local result = resp:json(code, ret)
resp:send(result)
end
--根据应用id删除应用信息
function _M.update_application(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.updateApplication(id, body_data)
local result = resp:json(code, ret)
resp:send(result)
end
return _M

49
src/api/system/auth.lua Normal file
View File

@ -0,0 +1,49 @@
---
--- Generated by EmmyLua(https://github.com/EmmyLua)
--- Created by admin.
--- DateTime: 2025/10/28 11:09
---
--解析url路由过滤库
local radix = require("resty.radixtree")
--数据表业务处理
local systemAuth = require("service.system.auth")
--定义相关路由前端接口url地址
local routes = {
--------------------------------------------
-------------用户登录相关路由配置--------------
--------------------------------------------
--用户登录路由接口
{
paths = { "/api/login" },
methods = { "POST" },
handler = systemAuth.login,
},
--用户退出路由接口
{
paths = { "/api/logout/:id" },
methods = { "POST" },
handler = systemAuth.logout,
},
}
-- 初始化路由
local rx, err = radix.new(routes)
if not rx then
ngx.say("Not Found")
ngx.exit(ngx.HTTP_NOT_FOUND)
end
--获取访问的uri地址
local uri = ngx.var.uri
local opts = {
method = ngx.var.request_method,
matched = {}
}
-- 进行路由匹配和相关函数调用
local ok = rx:dispatch(uri, opts, opts.matched)
if not ok then
ngx.say("Not Found")
ngx.exit(ngx.HTTP_NOT_FOUND)
end

View File

@ -1,61 +0,0 @@
---
--- Generated by EmmyLua(https://github.com/EmmyLua)
--- Created by admin.
--- DateTime: 2025/10/28 11:09
---
local validator = require("util.validator")
local helpers = require("util.helpers")
local resp = require("util.response")
local dao = require("service.system.controller")
local _M = {}
--用户登录业务逻辑处理
function _M.login()
--获取请求头并进行校验
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.login(body_data)
local result = resp:json(code, ret)
resp:send(result)
end
--用户登出业务逻辑处理
function _M.logout()
--获取请求头并进行校验
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.logout(body_data)
local result = resp:json(code, ret)
resp:send(result)
end
return _M

View File

@ -4,75 +4,58 @@
--- DateTime: 2025/10/28 10:05
---
local _M = {}
--解析url路由过滤库
local radix = require("resty.radixtree")
--数据表业务处理
local systemOrganization = require("service.system.organization")
local dao = require("service.system.organization")
local resp = require("util.response")
local validator = require("util.validator")
--定义相关路由前端接口url地址
local routes = {
--用户相关路由接口
{
paths = { "/api/system/organizations" },
methods = { "GET" },
handler = systemOrganization.getSystemOrganization,
},
{
paths = { "/api/system/organizations/:id" },
methods = { "GET" },
handler = systemOrganization.getSystemOrganization,
},
{
paths = { "/api/system/organizations" },
methods = { "POST" },
handler = systemOrganization.addSystemOrganization,
},
{
paths = { "/api/system/organizations/:id" },
methods = { "DELETE" },
handler = systemOrganization.deleteSystemOrganization,
},
{
paths = { "/api/system/organizations/:id" },
methods = { "PUT" },
handler = systemOrganization.updateSystemOrganization,
},
}
--获取所有组织架构信息
function _M.get_allorganization()
local code,ret = dao.getAllOrganization()
local result = resp:json(code, ret)
resp:send(result)
-- 初始化路由
local rx, err = radix.new(routes)
if not rx then
ngx.say("Not Found")
ngx.exit(ngx.HTTP_NOT_FOUND)
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
--获取访问的uri地址
local uri = ngx.var.uri
local opts = {
method = ngx.var.request_method,
matched = {}
}
--根据组织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)
-- 进行路由匹配和相关函数调用
local ok = rx:dispatch(uri, opts, opts.matched)
if not ok then
ngx.say("Not Found")
ngx.exit(ngx.HTTP_NOT_FOUND)
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

View File

@ -4,83 +4,58 @@
--- DateTime: 2025/9/25 08:19
---
local _M = {}
--解析url路由过滤库
local radix = require("resty.radixtree")
--数据表业务处理
local systemPermission = require("service.system.permission")
local dao = require("service.system.permission")
local resp = require("util.response")
local validator = require("util.validator")
--定义相关路由前端接口url地址
local routes = {
--用户相关路由接口
{
paths = { "/api/system/permissions" },
methods = { "GET" },
handler = systemPermission.getSystemPermissions,
},
{
paths = { "/api/system/permissions/:id" },
methods = { "GET" },
handler = systemPermission.getSystemPermission,
},
{
paths = { "/api/system/permissions" },
methods = { "POST" },
handler = systemPermission.addSystemPermission,
},
{
paths = { "/api/system/permissions/:id" },
methods = { "DELETE" },
handler = systemPermission.deleteSystemPermission,
},
{
paths = { "/api/system/permission/:id" },
methods = { "PUT" },
handler = systemPermission.updateSystemPermission,
},
}
--获取所有权限信息
function _M.get_allpermission()
local code,ret = dao.getAllPermission()
local result = resp:json(code, ret)
resp:send(result)
-- 初始化路由
local rx, err = radix.new(routes)
if not rx then
ngx.say("Not Found")
ngx.exit(ngx.HTTP_NOT_FOUND)
end
--根据权限id获取权限信息
function _M.get_permission(m)
local id = m.id
local code,ret = dao.getPermission(id)
local result = resp:json(code, ret)
resp:send(result)
end
--获取访问的uri地址
local uri = ngx.var.uri
local opts = {
method = ngx.var.request_method,
matched = {}
}
--根据角色id获取使用的权限
function _M.get_permission_by_role(m)
local id = m.id
local code,ret = dao.getPermissionByRole(id)
local result = resp:json(code, ret)
resp:send(result)
-- 进行路由匹配和相关函数调用
local ok = rx:dispatch(uri, opts, opts.matched)
if not ok then
ngx.say("Not Found")
ngx.exit(ngx.HTTP_NOT_FOUND)
end
--根据账号id获取账号信息
function _M.add_permission()
--获取请求头并进行校验
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.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)
local result = resp:json(code, ret)
resp:send(result)
end
--根据账号id删除账号信息
function _M.update_permission(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.updatePermission(id, body_data)
local result = resp:json(code, ret)
resp:send(result)
end
return _M

View File

@ -4,75 +4,58 @@
--- DateTime: 2025/9/25 08:19
---
local _M = {}
--解析url路由过滤库
local radix = require("resty.radixtree")
--数据表业务处理
local systemRole = require("service.system.role")
local dao = require("service.system.role")
local resp = require("util.response")
local validator = require("util.validator")
--定义相关路由前端接口url地址
local routes = {
--用户相关路由接口
{
paths = { "/api/system/roles" },
methods = { "GET" },
handler = systemRole.getSystemRoles,
},
{
paths = { "/api/system/roles/:id" },
methods = { "GET" },
handler = systemRole.getSystemRole,
},
{
paths = { "/api/system/roles" },
methods = { "POST" },
handler = systemRole.addSystemRole,
},
{
paths = { "/api/system/roles/:id" },
methods = { "DELETE" },
handler = systemRole.deleteSystemRole,
},
{
paths = { "/api/system/roles/:id" },
methods = { "PUT" },
handler = systemRole.updateSystemRole,
},
}
--获取所有角色信息
function _M.get_allrole()
local code,ret = dao.getAllRole()
local result = resp:json(code, ret)
resp:send(result)
-- 初始化路由
local rx, err = radix.new(routes)
if not rx then
ngx.say("Not Found")
ngx.exit(ngx.HTTP_NOT_FOUND)
end
--根据角色id获取角色信息
function _M.get_role(m)
local id = m.id
local code,ret = dao.getRole(id)
local result = resp:json(code, ret)
resp:send(result)
end
--获取访问的uri地址
local uri = ngx.var.uri
local opts = {
method = ngx.var.request_method,
matched = {}
}
--根据角色id获取角色信息
function _M.add_role()
--获取请求头并进行校验
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.addRole(body_data)
local result = resp:json(code, ret)
resp:send(result)
-- 进行路由匹配和相关函数调用
local ok = rx:dispatch(uri, opts, opts.matched)
if not ok then
ngx.say("Not Found")
ngx.exit(ngx.HTTP_NOT_FOUND)
end
--根据角色id删除角色信息
function _M.delete_role(m)
local id = m.id
local code, ret = dao.deleteRole(id)
local result = resp:json(code, ret)
resp:send(result)
end
--根据角色id删除角色信息
function _M.update_role(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.updateRole(id, body_data)
local result = resp:json(code, ret)
resp:send(result)
end
return _M

View File

@ -3,85 +3,58 @@
--- Created by admin.
--- DateTime: 2025/9/25 08:19
---
--解析url路由过滤库
local radix = require("resty.radixtree")
--数据表业务处理
local systemUser = require("service.system.user")
local _M = {}
--定义相关路由前端接口url地址
local routes = {
--用户相关路由接口
{
paths = { "/api/system/users" },
methods = { "GET" },
handler = systemUser.getSystemUsers,
},
{
paths = { "/api/system/users/:id" },
methods = { "GET" },
handler = systemUser.getSystemUser,
},
{
paths = { "/api/system/users" },
methods = { "POST" },
handler = systemUser.addSystemUser,
},
{
paths = { "/api/system/users/:id" },
methods = { "DELETE" },
handler = systemUser.deleteSystemUser,
},
{
paths = { "/api/system/user/:id" },
methods = { "PUT" },
handler = systemUser.updateSystemUser,
},
}
local dao = require("service.system.user")
local resp = require("util.response")
local validator = require("util.validator")
--获取所有用户信息
function _M.get_alluser()
--获取页码和请求的数据量
local page = 0
local pagesize = 0
local payloads = ngx.req.get_uri_args()
for k,v in pairs(payloads) do
if k == "page" then page = v end
if k == "pagesize" then pagesize = v end
end
--ngx.say("page:", page, " pagesize:", pagesize)
local code,ret = dao.getAllUser()
local result = resp:json(code, ret)
resp:send(result)
-- 初始化路由
local rx, err = radix.new(routes)
if not rx then
ngx.say("Not Found")
ngx.exit(ngx.HTTP_NOT_FOUND)
end
--根据用户id获取用户信息
function _M.get_user(m)
local id = m.id
local code,ret = dao.getUser(id)
local result = resp:json(code, ret)
resp:send(result)
end
--获取访问的uri地址
local uri = ngx.var.uri
local opts = {
method = ngx.var.request_method,
matched = {}
}
--根据用户id获取用户信息
function _M.add_user()
--获取请求头并进行校验
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.addUser(body_data)
local result = resp:json(code, ret)
resp:send(result)
-- 进行路由匹配和相关函数调用
local ok = rx:dispatch(uri, opts, opts.matched)
if not ok then
ngx.say("Not Found")
ngx.exit(ngx.HTTP_NOT_FOUND)
end
--根据用户id删除用户信息
function _M.delete_user(m)
local id = m.id
local code, ret = dao.deleteUser(id)
local result = resp:json(code, ret)
resp:send(result)
end
--根据用户id删除用户信息
function _M.update_user(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.updateUser(id, body_data)
local result = resp:json(code, ret)
resp:send(result)
end
return _M

View File

@ -1,4 +1,4 @@
local env = require('config.config')
local env = require('config')
return {
redis_prefix = 'Auth:',

View File

@ -5,7 +5,7 @@
--- 数据表模型文件
--引用使用的库文件
local Model = require("util.model")
local Model = require("share.model")
--创建一个数据表相关的模型
local Account = Model:new('tbl_account')

View File

@ -5,7 +5,7 @@
--- 数据表模型文件
--引用使用的库文件
local Model = require("util.model")
local Model = require("share.model")
--创建一个数据表相关的模型
local Application = Model:new('tbl_application')

View File

@ -5,7 +5,7 @@
--- 数据表模型文件
--引用使用的库文件
local Model = require("util.model")
local Model = require("share.model")
--创建一个数据表相关的模型
local Organization = Model:new('tbl_organization')

View File

@ -5,7 +5,7 @@
--- 数据表模型文件
--引用使用的库文件
local Model = require("util.model")
local Model = require("share.model")
--创建一个数据表相关的模型
local Permission = Model:new('tbl_permission')

View File

@ -5,7 +5,7 @@
--- 数据表模型文件
--引用使用的库文件
local Model = require("util.model")
local Model = require("share.model")
--创建一个数据表相关的模型
local Role = Model:new('tbl_role')

94
src/dao/user.lua Normal file
View File

@ -0,0 +1,94 @@
---
--- Generated by EmmyLua(https://github.com/EmmyLua)
--- Created by admin.
--- DateTime: 2025/10/25 16:36
--- 数据表模型文件
local helpers = require("share.helpers")
--引用使用的库文件
local model = require("share.model")
--创建一个数据表相关的模型
local userModel = model:new('sys_user')
local _M = {}
--判断用户是否存在
local function isExistUser(id)
--根据用户id进行验证用户是否存在
local code, res = userModel: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.getAllUser(pageNum, pageSize)
return userModel:paginate(pageNum, pageSize)
end
--根据用户id获取用户信息
function _M.getUser(id)
return userModel:find(id)
end
--增加用户信息到数据表
function _M.addUser(jsonData)
--解析json中的键和数据值
local userName = jsonData['username']
local phone = jsonData['phone']
local email = jsonData['email']
--根据用户、手机号、邮箱进行验证用户是否存在
local code, res = userModel:where("username", "=", userName):where("phone", "=", phone):where("email", "=", email):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 userModel:create('{'..ret..'}')
end
--删除用户信息到数据表
function _M:deleteUser(id)
--根据用户id进行验证用户是否存在
local ok = isExistUser(id)
--用户不存在则返回
if ok == false then
return 0x000001,nil
end
return userModel:delete(id)
end
--更新用户信息到数据表
function _M:updateUser(id, jsonData)
--根据用户id进行验证用户是否存在
local ok = isExistUser(id)
--用户不存在则返回
if ok == false then
return 0x000001,nil
end
--对数据内容进行更新
return userModel:where('id', '=', id):update(jsonData)
end
return _M

View File

@ -1,12 +0,0 @@
---
--- Generated by EmmyLua(https://github.com/EmmyLua)
--- Created by admin.
--- DateTime: 2025/10/25 16:36
--- 数据表模型文件
--引用使用的库文件
local Model = require("util.model")
--创建一个数据表相关的模型
local User = Model:new('tbl_user')
return User

View File

@ -4,7 +4,7 @@
--- DateTime: 2025/9/24 18:14
---
local cjson = require("cjson")
local cjson = require("cjson.safe")
local dict = ngx.shared.routes_cache
ngx.req.read_body()
local body = ngx.req.get_body_data()

View File

@ -4,11 +4,79 @@
--- DateTime: 2025/9/25 08:25
--- 业务逻辑 对账户数据表进行数据表业务处理
local validator = require("util.validator")
local helpers = require("util.helpers")
local helpers = require("share.helpers")
local account = require("model.account")
local _M = {}
local dao = require("service.system.account")
local resp = require("util.response")
--获取所有账户信息
function _M.get_allaccount()
local code,ret = dao.getAllAccount()
local result = resp:json(code, ret)
resp:send(result)
end
--根据账户id获取账户信息
function _M.get_account(m)
local id = m.id
local code,ret = dao.getAccount(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
--读取请求体的数据
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.addAccount(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)
local result = resp:json(code, ret)
resp:send(result)
end
--根据账户id删除账户信息
function _M.update_account(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.updateAccount(id, body_data)
local result = resp:json(code, ret)
resp:send(result)
end
-- 查询数据表中的所有账户信息
function _M.getAllAccount()
return account:all()

View File

@ -4,11 +4,96 @@
--- DateTime: 2025/9/27 16:02
--- 业务逻辑 对应用数据表进行数据表业务处理
local validator = require("util.validator")
local helpers = require("util.helpers")
local helpers = require("share.helpers")
local application = require("model.application")
local _M = {}
local dao = require("service.system.application")
local resp = require("util.response")
local validator = require("util.validator")
--获取所有应用程序信息
function _M.get_allapplication()
local code,ret = dao.getAllApplication()
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)
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)
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)
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
--读取请求体的数据
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.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)
local result = resp:json(code, ret)
resp:send(result)
end
--根据应用id删除应用信息
function _M.update_application(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.updateApplication(id, body_data)
local result = resp:json(code, ret)
resp:send(result)
end
-- 查询数据表中的所有应用信息
function _M.getAllApplication()
return application:all()

View File

@ -3,13 +3,62 @@
--- Created by admin.
--- DateTime: 2025/10/28 11:09
---
local validator = require("util.validator")
local helpers = require("util.helpers")
local helpers = require("share.helpers")
local resp = require("util.response")
local user = require("model.user")
local _M = {}
local dao = require("service.system.auth")
--用户登录业务逻辑处理
function _M.login()
--获取请求头并进行校验
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.login(body_data)
local result = resp:json(code, ret)
resp:send(result)
end
--用户登出业务逻辑处理
function _M.logout()
--获取请求头并进行校验
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.logout(body_data)
local result = resp:json(code, ret)
resp:send(result)
end
--认证用户返回用户数据信息
local function authenticate(name, passwd)
--验证用户名是否为空

View File

@ -4,11 +4,80 @@
--- DateTime: 2025/9/28 10:22
--- 业务逻辑 对组织架构数据表进行数据表业务处理
local validator = require("util.validator")
local helpers = require("util.helpers")
local helpers = require("share.helpers")
local organization = require("model.organization")
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
-- 查询数据表中的所有组织架构信息
function _M.getAllOrganization()
return organization:all()

View File

@ -4,11 +4,88 @@
--- DateTime: 2025/9/27 17:06
--- 业务逻辑 对权限数据表进行数据表业务处理
local validator = require("util.validator")
local helpers = require("util.helpers")
local helpers = require("share.helpers")
local permission = require("model.permission")
local _M = {}
local dao = require("service.system.permission")
local resp = require("util.response")
local validator = require("util.validator")
--获取所有权限信息
function _M.get_allpermission()
local code,ret = dao.getAllPermission()
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 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)
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
--读取请求体的数据
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.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)
local result = resp:json(code, ret)
resp:send(result)
end
--根据账号id删除账号信息
function _M.update_permission(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.updatePermission(id, body_data)
local result = resp:json(code, ret)
resp:send(result)
end
-- 查询数据表中的所有权限信息
function _M.getAllPermission()
return permission:all()

View File

@ -4,11 +4,80 @@
--- DateTime: 2025/9/27 15:19
--- 业务逻辑 对用户角色数据表进行数据表业务处理
local validator = require("util.validator")
local helpers = require("util.helpers")
local helpers = require("share.helpers")
local role = require("model.role")
local _M = {}
local dao = require("service.system.role")
local resp = require("util.response")
local validator = require("util.validator")
--获取所有角色信息
function _M.get_allrole()
local code,ret = dao.getAllRole()
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)
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
--读取请求体的数据
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.addRole(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)
local result = resp:json(code, ret)
resp:send(result)
end
--根据角色id删除角色信息
function _M.update_role(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.updateRole(id, body_data)
local result = resp:json(code, ret)
resp:send(result)
end
-- 查询数据表中的所有角色信息
function _M.getAllRole()
return role:all()

View File

@ -3,89 +3,89 @@
--- Created by .
--- DateTime: 2025/9/25 08:19
--- 业务逻辑 对用户数据表进行数据表业务处理
local validator = require("util.validator")
local helpers = require("util.helpers")
local user = require("model.user")
local jsonschema = require("jsonschema")
local resp = require("util.response")
local userDao = require("dao.user")
local _M = {}
-- 查询数据表中的所有用户信息
function _M.getAllUser()
return user:all()
-- 定义一个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.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 result = resp:json(code, ret)
resp:send(result)
end
--根据用户id获取用户信息
function _M.getUser(id)
return user:find(id)
function _M.getSystemUser(m)
local code,ret = userDao.getUser(m.id)
local result = resp:json(code, ret)
resp:send(result)
end
--增加用户信息到数据表
function _M.addUser(jsonData)
--验证数据的正确性,错误时返回
local success, result = validator.checkJson(jsonData)
if success == false then
return 0x000001,result
--根据用户id获取用户信息
function _M.addSystemUser()
--读取请求体的数据
ngx.req.read_body()
--获取请求数据
local body_data = ngx.req.get_body_data()
-- 验证数据是否符合schema
local ok, err = jsonschema:generate_validator(body_data, schema)
--验证失败则返回
if not ok then
local result = resp:json(0x000001)
resp:send(result)
return
end
--解析json中的键和数据值
local name, phone, email
for key, value in pairs(result) do
if key == "username" then name = value end
if key == "phone" then phone = value end
if key == "email" then email = value end
end
--根据用户、手机号、邮箱进行验证用户是否存在
local code, res = user:where("name", "=", name):where("phone", "=", phone):where("email", "=", phone):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 user:create('{'..ret..'}')
--ngx.say(body_data)
local code, ret = userDao.addUser(body_data)
local result = resp:json(code, ret)
resp:send(result)
end
--删除用户信息到数据表
function _M.deleteUser(id)
return user:delete(id)
--根据用户id删除用户信息
function _M.deleteSystemUser(m)
local code, ret = userDao.deleteUser(m.id)
local result = resp:json(code, ret)
resp:send(result)
end
--更新用户信息到数据表
function _M.updateUser(id, jsonData)
--根据用户id进行验证用户是否存在
local code, res = user:find(id)
if code ~= 0 then
return 0x000001,res
--根据用户id删除用户信息
function _M.updateSystemUser(m)
--读取请求体的数据
ngx.req.read_body()
--获取请求数据
local body_data = ngx.req.get_body_data()
-- 验证数据是否符合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 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 user:where('id', '=', id):update(jsonData)
--将数据更新到数据表中
local code, ret = userDao.updateUser(m.id, body_data)
local result = resp:json(code, ret)
resp:send(result)
end
return _M

View File

@ -13,6 +13,9 @@ local mt = { __index = _M }
--]]
function _M:get_connection()
local code = 0
-- modify by wanglei : 修改添加支持postgresql连接
if ngx.ctx[self.db_type] then
-- if write before read, make sure write read connection the same
if ngx.ctx[WRITE] then
@ -77,6 +80,11 @@ function _M.db_query(self, sql)
return 0, res
end
--[[
@param
@return
--]]
function _M.new(self, opts)
return setmetatable({
host = opts.host or '127.0.0.1',

View File

@ -3,8 +3,8 @@
--- Created by admin.
--- DateTime: 2025/10/24 11:36
---
local snowflake = require("util.snowflake")
local cjson = require("cjson")
local snowflake = require("share.snowflake")
local cjson = require("cjson.safe")
local _M = {}
@ -127,7 +127,7 @@ local function get_cookie(key)
end
local function get_local_time()
local config = require("config.config")
local config = require("config")
local time_zone = ngx.re.match(config.time_zone, "[0-9]+")
if time_zone == nil then
local err = "not set time zone or format error, time zone should look like `+8:00` current is: " .. config.time_zone

View File

@ -18,7 +18,7 @@
ngx.DEBUG
]]
-- 加载cjson
cjson = require("cjson");
cjson = require("cjson.safe");
-- 加载string
string = require("string");

View File

@ -1,7 +1,7 @@
local Database = require('util.database')
local Database = require('share.database')
local dbconf = require("config.database")
local helpers = require('util.helpers')
local helpers = require('share.helpers')
local implode = helpers.implode
local unique = helpers.unique
local table_remove = helpers.table_remove
@ -121,21 +121,23 @@ end
-- end
function _M:find(id,column)
if self.query_sql ~= nil then
ngx.log(ngx.ERR, 'cannot use find() with other query sql')
return 1, nil
end
column = column or 'id'
id = transform_value(id)
if self.query_sql ~= nil then
ngx.log(ngx.ERR, 'cannot use find() with other query sql')
return 1, nil
end
column = column or 'id'
id = transform_value(id)
ngx.log(ngx.INFO, 'table name :' .. self.table)
local sql = 'select * from \"'..self.table..'\" where '..column..'='..id..' limit 1'
local sql = 'select * from \"'..self.table..'\" where '..column..'='..id..' limit 1'
ngx.log(ngx.INFO, 'query sql:', sql)
local code, res = self:query(sql, READ)
if table.getn(res) > 0 then
ngx.log(ngx.INFO, 'query record count:', table.getn(res))
res = self:make_relations(res)
return code, res
end
local code, res = self:query(sql, READ)
if code == 0 then
if table.getn(res) > 0 then
ngx.log(ngx.INFO, 'query record count:', table.getn(res))
res = self:make_relations(res)
return code, res
end
end
return code, nil
end
@ -194,8 +196,10 @@ function _M:count()
sql = 'select count(*) from \"'..self.table.."\""
end
local code, res = self:query(sql, READ)
if table.getn(res) > 0 then
return code, tonumber(res[1]['count'])
if code == 0 then
if table.getn(res) > 0 then
return code, tonumber(res[1]['count'])
end
end
return code, nil
end
@ -221,19 +225,20 @@ function _M:get(num)
end
--根据数据模型中的
function _M:paginate(page_num, page_size)
page_num = page_num or 1
page_size = page_size or 10
function _M:paginate(pageNum, pageSize)
ngx.log(ngx.INFO, "pageNum:", tostring(pageNum), " pageSize:", tostring(pageSize))
pageNum = pageNum or 1
pageSize = pageSize or 10
local sql, count_sql, total, code, res
local data={
data = {},
total = 0
}
if not self.query_sql then
sql = 'select * from \"'..self.table..'\" limit '..page_size..' offset '..(page_num - 1) * page_size
sql = 'select * from \"'..self.table..'\" limit '..tostring(pageSize)..' offset '..tostring((pageNum - 1) * pageSize)
count_sql = 'select count(*) from \"'..self.table..'\"'
else
sql = 'select * from \"'..self.table .. '\" '..self.query_sql .. ' limit '..page_size..' offset '..(page_num - 1) * page_size
sql = 'select * from \"'..self.table .. '\" '..self.query_sql .. ' limit '..tostring(pageSize)..' offset '..tostring((pageNum - 1) * pageSize)
count_sql = 'select count(*) from \"'..self.table..'\" '..self.query_sql
end
code, total = self:query(count_sql, READ)

View File

@ -4,7 +4,7 @@
--- DateTime: 2025/10/15 09:12
---
--local snowflake = require("util.snowflake")
local helpers = require("util.helpers")
local helpers = require("share.helpers")
--
--local workerId = 0 -- 假设当前机器的ID是1范围在[0, 31]之间
--local datacenterId = 0 -- 数据中心ID范围在[0, 31]之间
@ -14,77 +14,162 @@ local helpers = require("util.helpers")
--max =a and b or c--a?b:c
local cjson = require("cjson")
local User = require("model.user")
local cjson = require("cjson.safe")
--[[
local uuid = require("resty.jit-uuid")
uuid.seed()
local val = uuid()
local uid = uuid.generate_v4() ---> v4 UUID
local uid1 = uuid.generate_v3() ---> v3 UUID (name-based with MD5)
local uid2 = uuid.generate_v5() ---> v5 UUID (name-based with SHA-1)
uuid.is_valid() ---> true/false (automatic JIT PCRE or Lua patterns)
--ngx.say(val.." "..uid)
--获取数据表中的记录数
local code, res = User:count()
--ngx.say(res)
--查询表中id为1的数据记录
code, res = User:find("1")
local args = ngx.req.get_uri_args()
local pageNum = args["pagenum"] or 1
local pageSize = args["pagesize"] or 10
ngx.say("pageNum:", pageNum, " pageSize:", pageSize)
--]]
--查询表中的所有记录
code, res = User:all()
--显示查询到的数据记录
for _, row in ipairs(res) do
for key, value in pairs(row) do
ngx.say(key .. ":" .. tostring(value))
end
local jsonschema = require("jsonschema")
-- 定义一个JSON Schema
-- 定义一个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"}}
}
-- 待验证的JSON数据
--local json_data = '{"name": "Alice", "age": 30}'
--local data, pos, err = cjson.decode(json_data)
--if err then
-- error("JSON decoding error: " .. err)
--end
--读取请求体的数据
ngx.req.read_body()
--获取请求数据
local body_data = ngx.req.get_body_data()
-- 验证数据是否符合schema
local ok, err = jsonschema:generate_validator(body_data, schema)
if not ok then
error("Validation failed: " .. err)
else
print("Validation succeeded!")
end
ngx.say("----begin where and query---")
-- 返回 users 表中 username 字段的值是 `cgreen` 的,`password` 字段的值是 `xxxxxx` 的多条数据,注意此处返回是 table 数组,`first()` 方法返回的是单条数据
code, res = User:where('name','=','zhangsan'):where('password','=','111111'):get()
ngx.say(code)
--[[
local jwt = require("resty.jwt")
local secret_key = "!@#$5412$#@!" -- 确保这个密钥足够安全并保密
--设置JWT的有效载荷
local obj = {
header = {typ="JWT", alg="HS256"},
payload = { -- 自定义数据
username = "admin",
role = "admin",
iss = "your_issuer", -- 签发者
sub = "1234567890", -- 主题
exp = os.time() + 3600, -- 过期时间(例如:当前时间+1小时
iat = os.time() -- 签发时间
}
}
local jwt_token = jwt:sign(secret_key, obj)
ngx.say(jwt_token)
local jwt_obj = jwt:verify(secret_key, jwt_token)
local param = cjson.encode(jwt_obj)
ngx.say(param)
local ok, claims = jwt:verify(jwt_token) -- 使用之前生成的token
if ok then
print("Token is valid")
for k, v in pairs(claims) do
print(k, v)
end
else
print("Token is invalid:", claims) -- claims将包含错误信息
end
--]]
--[[
--创建新的JWT对象
--local jwt_obj = jwt:new()
--设置密钥
local secret_key = "!@#$5412$#@!" -- 确保这个密钥足够安全并保密
--jwt_obj:set_secret(secret_key)
--设置JWT的有效载荷
local payload = {
iss = "your_issuer", -- 签发者
exp = os.time() + 3600, -- 过期时间(例如:当前时间+1小时
iat = os.time(), -- 签发时间
sub = "1234567890", -- 主题
data = { -- 自定义数据
username = "admin",
role = "admin"
}
}
-- 生成JWT token
local jwt_token, err = jwt:sign(secret_key, payload)
if err then
error("Failed to generate JWT token: " .. err)
end
print("Generated JWT Token:", jwt_token)
local ok, claims = jwt:verify(jwt_token) -- 使用之前生成的token
if ok then
print("Token is valid")
for k, v in pairs(claims) do
print(k, v)
end
else
print("Token is invalid:", claims) -- claims将包含错误信息
end
--]]
--[[
--引用使用的库文件
local Model = require("share.model")
--创建一个数据表相关的模型
local userModel = Model:new('sys_user')
--获取数据表中的记录数
local code, res = userModel:count()
ngx.say(res)
--查询表中id为1的数据记录
code, res = userModel:find("1")
if res ~= nil then
ngx.say(table.getn(res))
end
--查询表中的所有记录
code, res = userModel:all()
--显示查询到的数据记录
if code == 0 then
for _, row in ipairs(res) do
for key, value in pairs(row) do
ngx.say(key .. ":" .. tostring(value))
end
end
end
--[[
--ngx.say("----begin where or query---")
-- 返回 `name` 为 `xxx` 或者 `yyy` 的所有用户 table 数组
code, res = User:where('name','=','zhangsan'):orwhere('name','=','admin'):get()
--for _, row in ipairs(res) do
-- for key, value in pairs(row) do
-- ngx.say(key .. ":" .. tostring(value))
-- end
--end
--orderby(column, option)方法第一个参数传入排序的列名第二个参数默认为ASC 也可以传入 ASC 正序 或 DESC 倒序(不区分大小写)
code, res = User:orderby('created_time'):get()
--for _, row in ipairs(res) do
-- for key, value in pairs(row) do
-- ngx.say(key .. ":" .. tostring(value))
-- end
--end
-- 创建一个用户
code, res = User:create({
id='3',
password='22222',
name='lisi',
email='lisi@gmail.com',
})
-- 更新 id = 1 的 user 的 name 为 test, avatar 为 NULL
code, res = User:where('id', '=', '3'):update({
phone='666666',
email='zhangsan@qq.com'
})
--输出更新后影响的行总数
ngx.say("update affected_rows: ", res.affected_rows)
-- 删除 id = 1 的用户
code, res = User:where('id','=','3'):delete()
ngx.say("delete affected_rows: ", res.affected_rows)
--分页 获取数据表中的记录
local data = nil
code, data = User:paginate(1)
code, data = userModel:paginate(1, 10)
local count = data.total
ngx.say("data total:", count)
for _, row in ipairs(data.data) do
@ -93,6 +178,57 @@ for _, row in ipairs(data.data) do
ngx.say(key .. ":" .. tostring(value))
end
end
ngx.say("----begin where and query---")
-- 返回 users 表中 username 字段的值是 `cgreen` 的,`password` 字段的值是 `xxxxxx` 的多条数据,注意此处返回是 table 数组,`first()` 方法返回的是单条数据
code, res = userModel:where('name','=','zhangsan'):where('password','=','111111'):get()
--ngx.say(code)
--if res ~= nil then
-- for _, row in ipairs(res) do
-- for key, value in pairs(row) do
-- ngx.say(key .. ":" .. tostring(value))
-- end
-- end
--end
--]]
--[[
--ngx.say("----begin where or query---")
-- 返回 `name` 为 `xxx` 或者 `yyy` 的所有用户 table 数组
code, res = userModel:where('name','=','zhangsan'):orwhere('name','=','admin'):get()
--for _, row in ipairs(res) do
-- for key, value in pairs(row) do
-- ngx.say(key .. ":" .. tostring(value))
-- end
--end
--orderby(column, option)方法第一个参数传入排序的列名第二个参数默认为ASC 也可以传入 ASC 正序 或 DESC 倒序(不区分大小写)
code, res = userModel:orderby('created_time'):get()
--for _, row in ipairs(res) do
-- for key, value in pairs(row) do
-- ngx.say(key .. ":" .. tostring(value))
-- end
--end
-- 创建一个用户
code, res = userModel:create({
id='3',
password='22222',
name='lisi',
email='lisi@gmail.com',
})
-- 更新 id = 1 的 user 的 name 为 test, avatar 为 NULL
code, res = userModel:where('id', '=', '3'):update({
phone='666666',
email='zhangsan@qq.com'
})
--输出更新后影响的行总数
ngx.say("update affected_rows: ", res.affected_rows)
-- 删除 id = 1 的用户
code, res = userModel:where('id','=','3'):delete()
ngx.say("delete affected_rows: ", res.affected_rows)
--]]
--[[
@ -100,7 +236,7 @@ end
ngx.req.read_body()
--获取请求数据
local body_data = ngx.req.get_body_data()
--ngx.say(body_data)
ngx.say(body_data)
local data = cjson.decode(body_data)
--键值为id产生uuid数据值增加到json中
@ -145,7 +281,7 @@ ngx.say(body_data)
--]]
--[[
local cjson = require("cjson")
local cjson = require("cjson.safe")
local file_path = "/home/frankly/work/test.dat"
local file_length = 1024 * 1024 * 400
local f, err = io.input(file_path, "r")

View File

@ -1,213 +0,0 @@
-- Copyright (C) 2013-2016 Jiale Zhi (calio), CloudFlare Inc.
-- See RFC6265 http://tools.ietf.org/search/rfc6265
-- require "luacov"
local type = type
local byte = string.byte
local sub = string.sub
local format = string.format
local log = ngx.log
local ERR = ngx.ERR
local WARN = ngx.WARN
local ngx_header = ngx.header
local EQUAL = byte("=")
local SEMICOLON = byte(";")
local SPACE = byte(" ")
local HTAB = byte("\t")
-- table.new(narr, nrec)
local ok, new_tab = pcall(require, "table.new")
if not ok then
new_tab = function () return {} end
end
local ok, clear_tab = pcall(require, "table.clear")
if not ok then
clear_tab = function(tab) for k, _ in pairs(tab) do tab[k] = nil end end
end
local _M = new_tab(0, 2)
_M._VERSION = '0.01'
local function get_cookie_table(text_cookie)
if type(text_cookie) ~= "string" then
log(ERR, format("expect text_cookie to be \"string\" but found %s",
type(text_cookie)))
return {}
end
local EXPECT_KEY = 1
local EXPECT_VALUE = 2
local EXPECT_SP = 3
local n = 0
local len = #text_cookie
for i=1, len do
if byte(text_cookie, i) == SEMICOLON then
n = n + 1
end
end
local cookie_table = new_tab(0, n + 1)
local state = EXPECT_SP
local i = 1
local j = 1
local key, value
while j <= len do
if state == EXPECT_KEY then
if byte(text_cookie, j) == EQUAL then
key = sub(text_cookie, i, j - 1)
state = EXPECT_VALUE
i = j + 1
end
elseif state == EXPECT_VALUE then
if byte(text_cookie, j) == SEMICOLON
or byte(text_cookie, j) == SPACE
or byte(text_cookie, j) == HTAB
then
value = sub(text_cookie, i, j - 1)
cookie_table[key] = value
key, value = nil, nil
state = EXPECT_SP
i = j + 1
end
elseif state == EXPECT_SP then
if byte(text_cookie, j) ~= SPACE
and byte(text_cookie, j) ~= HTAB
then
state = EXPECT_KEY
i = j
j = j - 1
end
end
j = j + 1
end
if key ~= nil and value == nil then
cookie_table[key] = sub(text_cookie, i)
end
return cookie_table
end
function _M.new(self)
local _cookie = ngx.var.http_cookie
--if not _cookie then
--return nil, "no cookie found in current request"
--end
return setmetatable({ _cookie = _cookie, set_cookie_table = new_tab(4, 0) },
{ __index = self })
end
function _M.get(self, key)
if not self._cookie then
return nil, "no cookie found in the current request"
end
if self.cookie_table == nil then
self.cookie_table = get_cookie_table(self._cookie)
end
return self.cookie_table[key]
end
function _M.get_all(self)
if not self._cookie then
return nil, "no cookie found in the current request"
end
if self.cookie_table == nil then
self.cookie_table = get_cookie_table(self._cookie)
end
return self.cookie_table
end
function _M.get_cookie_size(self)
if not self._cookie then
return 0
end
return string.len(self._cookie)
end
local function bake(cookie)
if not cookie.key or not cookie.value then
return nil, 'missing cookie field "key" or "value"'
end
if cookie["max-age"] then
cookie.max_age = cookie["max-age"]
end
if (cookie.samesite) then
local samesite = cookie.samesite
-- if we don't have a valid-looking attribute, ignore the attribute
if (samesite ~= "Strict" and samesite ~= "Lax" and samesite ~= "None") then
log(WARN, "SameSite value must be 'Strict', 'Lax' or 'None'")
cookie.samesite = nil
end
end
local str = cookie.key .. "=" .. cookie.value
.. (cookie.expires and "; Expires=" .. cookie.expires or "")
.. (cookie.max_age and "; Max-Age=" .. cookie.max_age or "")
.. (cookie.domain and "; Domain=" .. cookie.domain or "")
.. (cookie.path and "; Path=" .. cookie.path or "")
.. (cookie.secure and "; Secure" or "")
.. (cookie.httponly and "; HttpOnly" or "")
.. (cookie.samesite and "; SameSite=" .. cookie.samesite or "")
.. (cookie.extension and "; " .. cookie.extension or "")
return str
end
function _M.set(self, cookie)
local cookie_str, err = bake(cookie)
if not cookie_str then
return nil, err
end
local set_cookie = ngx_header['Set-Cookie']
local set_cookie_type = type(set_cookie)
local t = self.set_cookie_table
clear_tab(t)
if set_cookie_type == "string" then
-- only one cookie has been setted
if set_cookie ~= cookie_str then
t[1] = set_cookie
t[2] = cookie_str
ngx_header['Set-Cookie'] = t
end
elseif set_cookie_type == "table" then
-- more than one cookies has been setted
local size = #set_cookie
-- we can not set cookie like ngx.header['Set-Cookie'][3] = val
-- so create a new table, copy all the values, and then set it back
for i=1, size do
t[i] = ngx_header['Set-Cookie'][i]
if t[i] == cookie_str then
-- new cookie is duplicated
return true
end
end
t[size + 1] = cookie_str
ngx_header['Set-Cookie'] = t
else
-- no cookie has been setted
ngx_header['Set-Cookie'] = cookie_str
end
return true
end
_M.get_cookie_string = bake
return _M

View File

@ -1,6 +1,6 @@
local cjson = require('cjson')
local conf = require('config.config')
local error_code = require('config.status')
local conf = require('config')
local error_code = require('util.status')
local ngx = ngx
local _M = {}

View File

@ -16,7 +16,6 @@
--ngx.HTTP_METHOD_NOT_IMPLEMENTED (501)
--ngx.HTTP_SERVICE_UNAVAILABLE (503)
--ngx.HTTP_GATEWAY_TIMEOUT (504)
return {
-- 系统状态码
[0x000000] = 'ok',

View File

@ -1,33 +0,0 @@
---
--- Generated by EmmyLua(https://github.com/EmmyLua)
--- Created by admin.
--- DateTime: 2025/10/24 11:01
--- 提供公共需要的验证接口等功能
local cjson = require('cjson')
local _M = {}
--验证请求头是否正确
function _M.checkReqHeader()
local headers = ngx.req.get_headers()
if headers["content-type"] ~= "application/json" then
return false
end
return true
end
--校验json数据的正确性并返回json解析后的数据
function _M.checkJson(jsonData)
--ngx.say(jsonData)
local success, result = pcall(function()
return cjson.decode(jsonData)
end)
if success == true then
return true, result
end
local res = nil
return false,res
end
return _M