Compare commits
9 Commits
b0f3421082
...
96245e79a7
| Author | SHA1 | Date | |
|---|---|---|---|
| 96245e79a7 | |||
|
|
33e03e3258 | ||
|
|
1f2a27fe13 | ||
| 771c35d8ec | |||
|
|
009e7dc201 | ||
|
|
2bfb2693ad | ||
|
|
795a60d78d | ||
|
|
9b3712e7fa | ||
|
|
4b9c6ee202 |
4
conf/auth/auth.conf
Normal file
4
conf/auth/auth.conf
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#API接口文件
|
||||
location /api/system/auth {
|
||||
content_by_lua_file '/home/frankly/work/AuthPlatform/src/api/system/auth.lua';
|
||||
}
|
||||
|
|
@ -30,8 +30,22 @@ http {
|
|||
access_log off;
|
||||
}
|
||||
|
||||
include 'auth/auth.conf';
|
||||
|
||||
include 'system/account.conf';
|
||||
include 'system/application.conf';
|
||||
include 'system/department.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';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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';
|
||||
}
|
||||
4
conf/system/application.conf
Normal file
4
conf/system/application.conf
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#API接口文件
|
||||
location /api/system/applications {
|
||||
content_by_lua_file '/home/frankly/work/AuthPlatform/src/api/system/application.lua';
|
||||
}
|
||||
4
conf/system/organization.conf
Normal file
4
conf/system/organization.conf
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#API接口文件
|
||||
location /api/system/organizations {
|
||||
content_by_lua_file '/home/frankly/work/AuthPlatform/src/api/system/organization.lua';
|
||||
}
|
||||
4
conf/system/permission.conf
Normal file
4
conf/system/permission.conf
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#API接口文件
|
||||
location /api/system/permissions {
|
||||
content_by_lua_file '/home/frankly/work/AuthPlatform/src/api/system/permission.lua';
|
||||
}
|
||||
4
conf/system/role.conf
Normal file
4
conf/system/role.conf
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#API接口文件
|
||||
location /api/system/roles {
|
||||
content_by_lua_file '/home/frankly/work/AuthPlatform/src/api/system/role.lua';
|
||||
}
|
||||
|
|
@ -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';
|
||||
}
|
||||
|
|
@ -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';
|
||||
}
|
||||
263
src/api/api.lua
263
src/api/api.lua
|
|
@ -1,263 +0,0 @@
|
|||
---
|
||||
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
||||
--- Created by admin.
|
||||
--- DateTime: 2025/9/24 15:29
|
||||
---
|
||||
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.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
|
||||
49
src/api/auth/auth.lua
Normal file
49
src/api/auth/auth.lua
Normal 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
|
||||
|
|
@ -1,28 +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 _M = {}
|
||||
|
||||
--用户登录业务逻辑处理
|
||||
function _M.login(id)
|
||||
local code = 0
|
||||
local ret = "{}"
|
||||
local result = resp:json(code, ret)
|
||||
resp:send(result)
|
||||
end
|
||||
|
||||
--用户登出业务逻辑处理
|
||||
function _M.logout(id)
|
||||
local code = 0
|
||||
local ret = "{}"
|
||||
local result = resp:json(code, ret)
|
||||
resp:send(result)
|
||||
end
|
||||
|
||||
return _M
|
||||
|
|
@ -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)
|
||||
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
|
||||
-- 进行路由匹配和相关函数调用
|
||||
local ok = rx:dispatch(uri, opts, opts.matched)
|
||||
if not ok then
|
||||
ngx.say("Not Found")
|
||||
ngx.exit(ngx.HTTP_NOT_FOUND)
|
||||
end
|
||||
|
|
@ -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
|
||||
61
src/api/system/department.lua
Normal file
61
src/api/system/department.lua
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
---
|
||||
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
||||
--- Created by admin.
|
||||
--- DateTime: 2025/10/28 10:05
|
||||
---
|
||||
|
||||
--解析url路由过滤库
|
||||
local radix = require("resty.radixtree")
|
||||
--数据表业务处理
|
||||
local systemOrganization = require("service.system.department")
|
||||
|
||||
--定义相关路由,前端接口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,
|
||||
},
|
||||
}
|
||||
|
||||
-- 初始化路由
|
||||
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
|
||||
|
|
@ -1,78 +0,0 @@
|
|||
---
|
||||
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
||||
--- Created by admin.
|
||||
--- DateTime: 2025/10/28 10:05
|
||||
---
|
||||
|
||||
local _M = {}
|
||||
|
||||
local dao = require("service.system.organization")
|
||||
local resp = require("util.response")
|
||||
local validator = require("util.validator")
|
||||
|
||||
--获取所有组织架构信息
|
||||
function _M.get_allorganization()
|
||||
local code,ret = dao.getAllOrganization()
|
||||
local result = resp:json(code, ret)
|
||||
resp:send(result)
|
||||
end
|
||||
|
||||
--根据组织id获取组织架构信息
|
||||
function _M.get_organization(m)
|
||||
local id = m.id
|
||||
local code,ret = dao.getOrganization(id)
|
||||
local result = resp:json(code, ret)
|
||||
resp:send(result)
|
||||
end
|
||||
|
||||
--根据组织id添加组织架构信息
|
||||
function _M.add_organization()
|
||||
--获取请求头并进行校验
|
||||
if validator.checkReqHeader() == false then
|
||||
local result = resp:json(0x000001)
|
||||
resp:send(result)
|
||||
return
|
||||
end
|
||||
--读取请求体的数据
|
||||
ngx.req.read_body()
|
||||
--获取请求数据
|
||||
local body_data = ngx.req.get_body_data()
|
||||
--判断请求体数据是否为空
|
||||
if body_data == nil then
|
||||
local result = resp:json(0x000001)
|
||||
resp:send(result)
|
||||
return
|
||||
end
|
||||
--ngx.say(body_data)
|
||||
local code, ret = dao.addOrganization(body_data)
|
||||
local result = resp:json(code, ret)
|
||||
resp:send(result)
|
||||
end
|
||||
|
||||
--根据组织id删除组织架构信息
|
||||
function _M.delete_organization(m)
|
||||
local id = m.id
|
||||
local code, ret = dao.deleteOrganization(id)
|
||||
local result = resp:json(code, ret)
|
||||
resp:send(result)
|
||||
end
|
||||
|
||||
--根据组织id删除组织架构信息
|
||||
function _M.update_organization(m)
|
||||
local id = m.id
|
||||
--读取请求体的数据
|
||||
ngx.req.read_body()
|
||||
--获取请求数据
|
||||
local body_data = ngx.req.get_body_data()
|
||||
--判断请求体数据是否为空
|
||||
if body_data == nil then
|
||||
local result = resp:json(0x000001)
|
||||
resp:send(result)
|
||||
return
|
||||
end
|
||||
local code, ret = dao.updateOrganization(id, body_data)
|
||||
local result = resp:json(code, ret)
|
||||
resp:send(result)
|
||||
end
|
||||
|
||||
return _M
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -11,6 +11,7 @@ return {
|
|||
|
||||
time_zone = "+8:00", -- UTC + 8
|
||||
|
||||
REDIS_PREFIX = 'Auth:',
|
||||
-- 配置redis数据库连接
|
||||
REDIS = {
|
||||
HOST = "127.0.0.1", -- redis host
|
||||
|
|
@ -25,5 +26,10 @@ return {
|
|||
USERNAME = "postgres",
|
||||
PASSWORD = "1qaz2wsx", -- postgres password
|
||||
DATABASE = "postgres",
|
||||
|
||||
CHARSET = 'utf8',
|
||||
POOL_TIMEOUT = 1000, -- postgresql pool timeout
|
||||
POOL_SIZE = 100, -- postgresql pool size
|
||||
TIMEOUT = 1000, -- postgresql timeout
|
||||
}
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
local env = require('config.config')
|
||||
|
||||
return {
|
||||
redis_prefix = 'Auth:',
|
||||
redis = {
|
||||
host = env.REDIS.HOST,
|
||||
port = env.REDIS.PORT,
|
||||
password = env.REDIS.PASSWORD
|
||||
},
|
||||
|
||||
postgres = {
|
||||
host = env.POSTGRES.HOST,
|
||||
port = env.POSTGRES.PORT,
|
||||
user = env.POSTGRES.USERNAME,
|
||||
password = env.POSTGRES.PASSWORD,
|
||||
database = env.POSTGRES.DATABASE,
|
||||
|
||||
write = { -- postgresql write database
|
||||
host = env.POSTGRES.HOST,
|
||||
port = env.POSTGRES.PORT,
|
||||
user = env.POSTGRES.USERNAME,
|
||||
password = env.POSTGRES.PASSWORD,
|
||||
database = env.POSTGRES.DATABASE
|
||||
},
|
||||
read = { -- postgresql read database
|
||||
host = env.POSTGRES.HOST,
|
||||
port = env.POSTGRES.PORT,
|
||||
user = env.POSTGRES.USERNAME,
|
||||
password = env.POSTGRES.PASSWORD,
|
||||
database = env.POSTGRES.DATABASE
|
||||
},
|
||||
charset = 'utf8',
|
||||
pool_timeout = 1000, -- postgresql pool timeout
|
||||
pool_size = 100, -- postgresql pool size
|
||||
timeout = 1000, -- postgresql timeout
|
||||
},
|
||||
}
|
||||
92
src/dao/account.lua
Normal file
92
src/dao/account.lua
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
---
|
||||
--- 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 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
|
||||
107
src/dao/application.lua
Normal file
107
src/dao/application.lua
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
---
|
||||
--- 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 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
|
||||
91
src/dao/department.lua
Normal file
91
src/dao/department.lua
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
---
|
||||
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
||||
--- Created by admin.
|
||||
--- DateTime: 2025/10/28 10:14
|
||||
--- 数据表模型文件
|
||||
|
||||
local helpers = require("share.helpers")
|
||||
--引用使用的库文件
|
||||
local model = require("share.model")
|
||||
--创建一个数据表相关的模型
|
||||
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
|
||||
99
src/dao/permission.lua
Normal file
99
src/dao/permission.lua
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
---
|
||||
--- 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 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
|
||||
92
src/dao/role.lua
Normal file
92
src/dao/role.lua
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
---
|
||||
--- 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 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
|
||||
94
src/dao/user.lua
Normal file
94
src/dao/user.lua
Normal 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.getSystemUsers(pageNum, pageSize)
|
||||
return userModel:paginate(pageNum, pageSize)
|
||||
end
|
||||
|
||||
--根据用户id获取用户信息
|
||||
function _M.getSystemUser(id)
|
||||
return userModel:find(id)
|
||||
end
|
||||
|
||||
--增加用户信息到数据表
|
||||
function _M.addSystemUser(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:deleteSystemUser(id)
|
||||
--根据用户id进行验证用户是否存在
|
||||
local ok = isExistUser(id)
|
||||
--用户不存在则返回
|
||||
if ok == false then
|
||||
return 0x000001,nil
|
||||
end
|
||||
return userModel:delete(id)
|
||||
end
|
||||
|
||||
--更新用户信息到数据表
|
||||
function _M:updateSystemUser(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
|
||||
|
|
@ -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 Account = Model:new('tbl_account')
|
||||
return Account
|
||||
|
|
@ -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 Application = Model:new('tbl_application')
|
||||
return Application
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
---
|
||||
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
||||
--- Created by admin.
|
||||
--- DateTime: 2025/10/28 10:14
|
||||
--- 数据表模型文件
|
||||
|
||||
--引用使用的库文件
|
||||
local Model = require("util.model")
|
||||
|
||||
--创建一个数据表相关的模型
|
||||
local Organization = Model:new('tbl_organization')
|
||||
return Organization
|
||||
|
|
@ -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 Permission = Model:new('tbl_permission')
|
||||
return Permission
|
||||
|
|
@ -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 Role = Model:new('tbl_role')
|
||||
return Role
|
||||
|
|
@ -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
|
||||
|
|
@ -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()
|
||||
|
|
|
|||
137
src/service/auth/auth.lua
Normal file
137
src/service/auth/auth.lua
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
---
|
||||
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
||||
--- Created by admin.
|
||||
--- DateTime: 2025/10/28 11:09
|
||||
---
|
||||
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)
|
||||
--验证用户名是否为空
|
||||
if name == "" then
|
||||
return 0x010003, nil
|
||||
end
|
||||
--验证密码是否为空
|
||||
if passwd == "" then
|
||||
return 0x010002, nil
|
||||
end
|
||||
--根据用户进行验证用户是否存在
|
||||
local code, res = user:where("name", "=", name):where("password", "=", passwd):get()
|
||||
if code == 0 and res ~= nil then
|
||||
return code, res
|
||||
end
|
||||
--根据手机号进行验证用户是否存在
|
||||
code, res = user:where("phone", "=", name):where("password", "=", passwd):get()
|
||||
if code == 0 and res ~= nil then
|
||||
return code, res
|
||||
end
|
||||
--根据邮箱进行验证用户是否存在
|
||||
code, res = user:where("email", "=", name):where("password", "=", passwd):get()
|
||||
if code == 0 and res ~= nil then
|
||||
return code, res
|
||||
end
|
||||
--查询不到用户信息
|
||||
return 0x010003, nil
|
||||
end
|
||||
|
||||
--用户登录业务逻辑处理
|
||||
function _M.login(jsonData)
|
||||
--验证数据的正确性,错误时返回
|
||||
local success, result = validator.checkJson(jsonData)
|
||||
if success == false then
|
||||
return 0x000001,result
|
||||
end
|
||||
--解析json中的键和数据值
|
||||
local name = ""
|
||||
local passwd = ""
|
||||
local captcha = ""
|
||||
local checkKey = ""
|
||||
for key, value in pairs(result) do
|
||||
if key == "username" then name = value end
|
||||
if key == "password" then passwd = value end
|
||||
if key == "captcha" then captcha = value end
|
||||
if key == "checkKey" then checkKey = value end
|
||||
end
|
||||
--验证用户名是否为空
|
||||
local code, res = authenticate(name, passwd)
|
||||
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 result = resp:json(code, res)
|
||||
resp:send(result)
|
||||
end
|
||||
|
||||
--用户登出业务逻辑处理
|
||||
function _M.logout(jsonData)
|
||||
local code = 0
|
||||
local ret = "{}"
|
||||
local result = resp:json(code, ret)
|
||||
resp:send(result)
|
||||
end
|
||||
|
||||
return _M
|
||||
|
|
@ -3,85 +3,84 @@
|
|||
--- Created by .
|
||||
--- DateTime: 2025/9/25 08:25
|
||||
--- 业务逻辑 对账户数据表进行数据表业务处理
|
||||
local validator = require("util.validator")
|
||||
local helpers = require("util.helpers")
|
||||
local account = require("model.account")
|
||||
local jsonschema = require("jsonschema")
|
||||
local resp = require("util.response")
|
||||
local accountDao = require("dao.account")
|
||||
|
||||
local _M = {}
|
||||
|
||||
-- 查询数据表中的所有账户信息
|
||||
function _M.getAllAccount()
|
||||
return account:all()
|
||||
-- 定义一个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.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.getAccount(id)
|
||||
return account.find(id)
|
||||
function _M.getSystemAccount(m)
|
||||
local id = m.id
|
||||
local code,ret = accountDao.getSystemAccount(id)
|
||||
local result = resp:json(code, ret)
|
||||
resp:send(result)
|
||||
end
|
||||
|
||||
--增加账户信息到数据表
|
||||
function _M.addAccount(jsonData)
|
||||
--验证数据的正确性,错误时返回
|
||||
local success, result = validator.checkJson(jsonData)
|
||||
if success == false then
|
||||
return 0x000001, result
|
||||
--根据账户id获取账户信息
|
||||
function _M.addSystemAccount()
|
||||
--读取请求体的数据
|
||||
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 = ""
|
||||
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..'}')
|
||||
--ngx.say(body_data)
|
||||
local code, ret = accountDao.addSystemAccount(body_data)
|
||||
local result = resp:json(code, ret)
|
||||
resp:send(result)
|
||||
end
|
||||
|
||||
--删除账户信息到数据表
|
||||
function _M.deleteAccount(id)
|
||||
return account:delete(id)
|
||||
--根据账户id删除账户信息
|
||||
function _M.deleteSystemAccount(m)
|
||||
local code, ret = accountDao.deleteSystemAccount(m.id)
|
||||
local result = resp:json(code, ret)
|
||||
resp:send(result)
|
||||
end
|
||||
|
||||
--更新账户信息到数据表
|
||||
function _M.updateAccount(id, jsonData)
|
||||
--根据账户id进行验证账户是否存在
|
||||
local code, res = account:find(id)
|
||||
if code ~= 0 then
|
||||
return 0x000001, res
|
||||
--根据账户id删除账户信息
|
||||
function _M.updateSystemAccount(m)
|
||||
--读取请求体的数据
|
||||
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 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)
|
||||
local code, ret = accountDao.updateSystemAccount(m.id, body_data)
|
||||
local result = resp:json(code, ret)
|
||||
resp:send(result)
|
||||
end
|
||||
|
||||
return _M
|
||||
|
|
|
|||
|
|
@ -3,97 +3,102 @@
|
|||
--- Created by .
|
||||
--- DateTime: 2025/9/27 16:02
|
||||
--- 业务逻辑 对应用数据表进行数据表业务处理
|
||||
local validator = require("util.validator")
|
||||
local helpers = require("util.helpers")
|
||||
local application = require("model.application")
|
||||
local jsonschema = require("jsonschema")
|
||||
local resp = require("util.response")
|
||||
local applicationDao = require("dao.application")
|
||||
|
||||
local _M = {}
|
||||
|
||||
-- 查询数据表中的所有应用信息
|
||||
function _M.getAllApplication()
|
||||
return application:all()
|
||||
-- 定义一个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.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.getApplication(id)
|
||||
return application.find(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.getOrganizationApplication(id)
|
||||
--todo
|
||||
return application.find(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.getUserApplication(id)
|
||||
--todo
|
||||
return application.find(id)
|
||||
--根据用户id获取应用的信息
|
||||
function _M.getUserApplication(m)
|
||||
local code,ret = applicationDao.getUserApplication(m.id)
|
||||
local result = resp:json(code, ret)
|
||||
resp:send(result)
|
||||
end
|
||||
|
||||
--增加应用信息到数据表
|
||||
function _M.addApplication(jsonData)
|
||||
--验证数据的正确性,错误时返回
|
||||
local success, result = validator.checkJson(jsonData)
|
||||
if success == false then
|
||||
return 0x000001, result
|
||||
--根据应用id获取应用信息
|
||||
function _M.addSystemApplication()
|
||||
--读取请求体的数据
|
||||
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 = ""
|
||||
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..'}')
|
||||
--ngx.say(body_data)
|
||||
local code, ret = applicationDao.addApplication(body_data)
|
||||
local result = resp:json(code, ret)
|
||||
resp:send(result)
|
||||
end
|
||||
|
||||
--删除应用信息到数据表
|
||||
function _M.deleteApplication(id)
|
||||
return application:delete(id)
|
||||
--根据应用id删除应用信息
|
||||
function _M.deleteSystemApplication(m)
|
||||
local code, ret = applicationDao.deleteApplication(m.id)
|
||||
local result = resp:json(code, ret)
|
||||
resp:send(result)
|
||||
end
|
||||
|
||||
--更新应用信息到数据表
|
||||
function _M.updateApplication(id, jsonData)
|
||||
--根据应用id进行验证应用是否存在
|
||||
local code, res = application:find(id)
|
||||
if code ~= 0 then
|
||||
return 0x000001, res
|
||||
--根据应用id删除应用信息
|
||||
function _M.updateSystemApplication(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 application:where('id', '=', id):update(jsonData)
|
||||
local code, ret = applicationDao.updateSystemApplication(m.id, body_data)
|
||||
local result = resp:json(code, ret)
|
||||
resp:send(result)
|
||||
end
|
||||
|
||||
return _M
|
||||
|
|
|
|||
89
src/service/system/department.lua
Normal file
89
src/service/system/department.lua
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
---
|
||||
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
||||
--- Created by .
|
||||
--- DateTime: 2025/9/28 10:22
|
||||
--- 业务逻辑 对组织架构数据表进行数据表业务处理
|
||||
local jsonschema = require("jsonschema")
|
||||
local resp = require("util.response")
|
||||
local departmentDao = require("dao.department")
|
||||
|
||||
local _M = {}
|
||||
|
||||
-- 定义一个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.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.getSystemDepartment(m)
|
||||
local code,ret = departmentDao.getSystemDepartment(m.id)
|
||||
local result = resp:json(code, ret)
|
||||
resp:send(result)
|
||||
end
|
||||
|
||||
--根据组织id添加组织架构信息
|
||||
function _M.addSystemDepartment()
|
||||
--读取请求体的数据
|
||||
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
|
||||
--ngx.say(body_data)
|
||||
local code, ret = departmentDao.addSystemDepartment(body_data)
|
||||
local result = resp:json(code, ret)
|
||||
resp:send(result)
|
||||
end
|
||||
|
||||
--根据组织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.updateSystemDepartment(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 code, ret = departmentDao.updateSystemDepartment(m.id, body_data)
|
||||
local result = resp:json(code, ret)
|
||||
resp:send(result)
|
||||
end
|
||||
|
||||
return _M
|
||||
|
|
@ -1,87 +0,0 @@
|
|||
---
|
||||
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
||||
--- Created by .
|
||||
--- DateTime: 2025/9/28 10:22
|
||||
--- 业务逻辑 对组织架构数据表进行数据表业务处理
|
||||
local validator = require("util.validator")
|
||||
local helpers = require("util.helpers")
|
||||
local organization = require("model.organization")
|
||||
|
||||
local _M = {}
|
||||
|
||||
-- 查询数据表中的所有组织架构信息
|
||||
function _M.getAllOrganization()
|
||||
return organization:all()
|
||||
end
|
||||
|
||||
--根据组织架构id获取组织架构信息
|
||||
function _M.getOrganization(id)
|
||||
return organization.find(id)
|
||||
end
|
||||
|
||||
--增加组织架构息到数据表
|
||||
function _M.addOrganization(jsonData)
|
||||
--验证数据的正确性,错误时返回
|
||||
local success, result = validator.checkJson(jsonData)
|
||||
if success == false then
|
||||
return 0x000001, result
|
||||
end
|
||||
--解析json中的键和数据值
|
||||
local name = ""
|
||||
for key, value in pairs(result) do
|
||||
if key == "name" then name = value end
|
||||
end
|
||||
--根据组织架构进行验证是否存在
|
||||
local code, res = organization:where("name", "=", name):get()
|
||||
if code ~= 0 then
|
||||
return 0x000001, res
|
||||
end
|
||||
local num = 0
|
||||
for _, row in ipairs(res) do
|
||||
for key, value in pairs(row) do
|
||||
num = num + 1
|
||||
end
|
||||
end
|
||||
--组织架构存在时返回组织架构已经存在
|
||||
if num <= 0 then
|
||||
return 0x01000C, nil
|
||||
end
|
||||
--键值为id产生uuid数据值,增加到json中
|
||||
result.id = helpers.getUuid()
|
||||
local ret = helpers.convert_json(result)
|
||||
-- 创建一个组织架构
|
||||
return organization:create('{'..ret..'}')
|
||||
end
|
||||
|
||||
--删除组织架构信息到数据表
|
||||
function _M.deleteOrganization(id)
|
||||
return organization:delete(id)
|
||||
end
|
||||
|
||||
--更新组织架构信息到数据表
|
||||
function _M.updateOrganization(id, jsonData)
|
||||
--根据组织架构id进行验证组织架构是否存在
|
||||
local code, res = organization:find(id)
|
||||
if code ~= 0 then
|
||||
return 0x000001, res
|
||||
end
|
||||
local num = 0
|
||||
for _, row in ipairs(res) do
|
||||
for key, value in pairs(row) do
|
||||
num = num + 1
|
||||
end
|
||||
end
|
||||
--账号不存在返回错误
|
||||
if num <= 0 then
|
||||
return 0x01000C, nil
|
||||
end
|
||||
--验证数据的正确性,错误时返回
|
||||
local success, result = validator.checkJson(jsonData)
|
||||
if success == false then
|
||||
return 0x000001, result
|
||||
end
|
||||
--对数据内容进行更新
|
||||
return organization:where('id', '=', id):update(jsonData)
|
||||
end
|
||||
|
||||
return _M
|
||||
|
|
@ -3,92 +3,94 @@
|
|||
--- Created by .
|
||||
--- DateTime: 2025/9/27 17:06
|
||||
--- 业务逻辑 对权限数据表进行数据表业务处理
|
||||
local validator = require("util.validator")
|
||||
local helpers = require("util.helpers")
|
||||
local permission = require("model.permission")
|
||||
local jsonschema = require("jsonschema")
|
||||
local resp = require("util.response")
|
||||
local permissionDao = require("dao.permission")
|
||||
|
||||
local _M = {}
|
||||
|
||||
-- 查询数据表中的所有权限信息
|
||||
function _M.getAllPermission()
|
||||
return permission: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.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.getPermission(id)
|
||||
return permission.find(id)
|
||||
function _M.get_permission(m)
|
||||
local code,ret = permissionDao.getPermission(m.id)
|
||||
local result = resp:json(code, ret)
|
||||
resp:send(result)
|
||||
end
|
||||
|
||||
--根据角色id获取角色的权限
|
||||
function _M.getPermissionByRole(id)
|
||||
--权限表与角色表进行表关系查询返回结果
|
||||
--todo
|
||||
return permission.first(id)
|
||||
--根据角色id获取使用的权限
|
||||
function _M.getSystemPermissionByRole(m)
|
||||
local code,ret = dao.getPermissionByRole(m.id)
|
||||
local result = resp:json(code, ret)
|
||||
resp:send(result)
|
||||
end
|
||||
|
||||
--增加权限信息到数据表
|
||||
function _M.addPermission(jsonData)
|
||||
--验证数据的正确性,错误时返回
|
||||
local success, result = validator.checkJson(jsonData)
|
||||
if success == false then
|
||||
return 0x000001, result
|
||||
--根据权限id获取账号信息
|
||||
function _M.addSystemPermission()
|
||||
--读取请求体的数据
|
||||
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 = ""
|
||||
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..'}')
|
||||
--ngx.say(body_data)
|
||||
local code, ret = permissionDao.addPermission(body_data)
|
||||
local result = resp:json(code, ret)
|
||||
resp:send(result)
|
||||
end
|
||||
|
||||
--删除权限信息到数据表
|
||||
function _M.deletePermission(id)
|
||||
return permission:delete(id)
|
||||
--根据账号id删除账号信息
|
||||
function _M.deleteSystemPermission(m)
|
||||
local code, ret = permissionDao.deleteSystemPermission(m.id)
|
||||
local result = resp:json(code, ret)
|
||||
resp:send(result)
|
||||
end
|
||||
|
||||
--更新权限信息到数据表
|
||||
function _M.updatePermission(id, jsonData)
|
||||
--根据权限id进行验证权限是否存在
|
||||
local code, res = permission:find(id)
|
||||
if code ~= 0 then
|
||||
return 0x000001, res
|
||||
--根据账号id删除账号信息
|
||||
function _M.updateSystemPermission(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 permission:where('id', '=', id):update(jsonData)
|
||||
local code, ret = permissionDao.updatePermission(m.id, body_data)
|
||||
local result = resp:json(code, ret)
|
||||
resp:send(result)
|
||||
end
|
||||
|
||||
return _M
|
||||
|
|
|
|||
|
|
@ -3,85 +3,84 @@
|
|||
--- Created by .
|
||||
--- DateTime: 2025/9/27 15:19
|
||||
--- 业务逻辑 对用户角色数据表进行数据表业务处理
|
||||
local validator = require("util.validator")
|
||||
local helpers = require("util.helpers")
|
||||
local role = require("model.role")
|
||||
local jsonschema = require("jsonschema")
|
||||
local resp = require("util.response")
|
||||
local roleDao = require("dao.role")
|
||||
|
||||
local _M = {}
|
||||
|
||||
-- 查询数据表中的所有角色信息
|
||||
function _M.getAllRole()
|
||||
return role:all()
|
||||
-- 定义一个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.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.getRole(id)
|
||||
return role.find(id)
|
||||
function _M.getSystemRole(m)
|
||||
local code,ret = roleDao.getSystemRole(m.id)
|
||||
local result = resp:json(code, ret)
|
||||
resp:send(result)
|
||||
end
|
||||
|
||||
--增加角色信息到数据表
|
||||
function _M.addRole(jsonData)
|
||||
--验证数据的正确性,错误时返回
|
||||
local success, result = validator.checkJson(jsonData)
|
||||
if success == false then
|
||||
return 0x000001, result
|
||||
--根据角色id获取角色信息
|
||||
function _M.addSystemRole()
|
||||
--读取请求体的数据
|
||||
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 = ""
|
||||
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..'}')
|
||||
--ngx.say(body_data)
|
||||
local code, ret = roleDao.addSystemRole(body_data)
|
||||
local result = resp:json(code, ret)
|
||||
resp:send(result)
|
||||
end
|
||||
|
||||
--删除角色信息到数据表
|
||||
function _M.deleteRole(id)
|
||||
return role:delete(id)
|
||||
--根据角色id删除角色信息
|
||||
function _M.deleteSystemRole(m)
|
||||
local code, ret = roleDao.deleteSystemRole(m.id)
|
||||
local result = resp:json(code, ret)
|
||||
resp:send(result)
|
||||
end
|
||||
|
||||
--更新角色信息到数据表
|
||||
function _M.updateRole(id, jsonData)
|
||||
--根据角色id进行验证角色是否存在
|
||||
local code, res = role:find(id)
|
||||
if code ~= 0 then
|
||||
return 0x000001, res
|
||||
--根据角色id删除角色信息
|
||||
function _M.updateSystemRole(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 role:where('id', '=', id):update(jsonData)
|
||||
local code, ret = roleDao.updateSystemRole(m.id, body_data)
|
||||
local result = resp:json(code, ret)
|
||||
resp:send(result)
|
||||
end
|
||||
|
||||
return _M
|
||||
|
|
|
|||
|
|
@ -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.getSystemUsers(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.getSystemUser(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.addSystemUser(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.deleteSystemUser(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.updateSystemUser(m.id, body_data)
|
||||
local result = resp:json(code, ret)
|
||||
resp:send(result)
|
||||
end
|
||||
|
||||
return _M
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
@ -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
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
---
|
||||
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
||||
--- Created by .
|
||||
--- DateTime:
|
||||
---
|
||||
|
||||
--[[
|
||||
公共包引用的范围为http块;项目用到的非配置类都可以在此处配置;
|
||||
日志级别:
|
||||
ngx.STDERR
|
||||
ngx.EMERG
|
||||
ngx.ALERT
|
||||
ngx.CRIT
|
||||
ngx.ERR
|
||||
ngx.WARN
|
||||
ngx.NOTICE
|
||||
ngx.INFO
|
||||
ngx.DEBUG
|
||||
]]
|
||||
-- 加载cjson
|
||||
cjson = require("cjson");
|
||||
-- 加载string
|
||||
string = require("string");
|
||||
|
||||
--[[
|
||||
项目内公共包配置
|
||||
]]
|
||||
-- 加载resty.core
|
||||
require("resty.core");
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,7 +1,7 @@
|
|||
local Database = require('util.database')
|
||||
local dbconf = require("config.database")
|
||||
local Database = require('share.database')
|
||||
local conf = require("config")
|
||||
|
||||
local helpers = require('util.helpers')
|
||||
local helpers = require('share.helpers')
|
||||
local implode = helpers.implode
|
||||
local unique = helpers.unique
|
||||
local table_remove = helpers.table_remove
|
||||
|
|
@ -12,28 +12,28 @@ local WRITE = 'WRITE'
|
|||
local READ = 'READ'
|
||||
|
||||
local database_write = Database:new({
|
||||
host = dbconf.postgres.write.host,
|
||||
port = dbconf.postgres.write.port,
|
||||
user = dbconf.postgres.write.user,
|
||||
password = dbconf.postgres.write.password,
|
||||
database = dbconf.postgres.write.database,
|
||||
--charset = dbconf.postgres.charset,
|
||||
--timeout = dbconf.postgres.timeout,
|
||||
db_pool_timeout = dbconf.postgres.pool_timeout,
|
||||
db_pool_size = dbconf.postgres.pool_size,
|
||||
host = conf.POSTGRES.host,
|
||||
port = conf.POSTGRES.port,
|
||||
user = conf.POSTGRES.user,
|
||||
password = conf.POSTGRES.password,
|
||||
database = conf.POSTGRES.database,
|
||||
--charset = conf.POSTGRES.charset,
|
||||
--timeout = conf.POSTGRES.timeout,
|
||||
db_pool_timeout = conf.POSTGRES.pool_timeout,
|
||||
db_pool_size = conf.POSTGRES.pool_size,
|
||||
db_type = WRITE
|
||||
})
|
||||
|
||||
local database_read = Database:new({
|
||||
host = dbconf.postgres.read.host,
|
||||
port = dbconf.postgres.read.port,
|
||||
user = dbconf.postgres.read.user,
|
||||
password = dbconf.postgres.read.password,
|
||||
database = dbconf.postgres.read.database,
|
||||
--charset = dbconf.postgres.charset,
|
||||
--timeout = dbconf.postgres.timeout,
|
||||
db_pool_timeout = dbconf.postgres.pool_timeout,
|
||||
db_pool_size = dbconf.postgres.pool_size,
|
||||
host = conf.POSTGRES.host,
|
||||
port = conf.POSTGRES.port,
|
||||
user = conf.POSTGRES.user,
|
||||
password = conf.POSTGRES.password,
|
||||
database = conf.POSTGRES.database,
|
||||
--charset = conf.POSTGRES.charset,
|
||||
--timeout = conf.POSTGRES.timeout,
|
||||
db_pool_timeout = conf.POSTGRES.pool_timeout,
|
||||
db_pool_size = conf.POSTGRES.pool_size,
|
||||
db_type = READ
|
||||
})
|
||||
|
||||
|
|
@ -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)
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
local redis = require("loadlib.resty_redis")
|
||||
local db_config = require('config.database')
|
||||
|
||||
local _M = setmetatable({}, {__index=function(self, key)
|
||||
local red = redis:new()
|
||||
local ok,err = red:connect(db_config.redis.host, db_config.redis.port)
|
||||
if not ok then
|
||||
ngx.log(ngx.ERR, err)
|
||||
end
|
||||
if key == 'red' then
|
||||
return red
|
||||
end
|
||||
end})
|
||||
|
||||
function _M:set(key, value, time)
|
||||
local ok, err = self.red:set(key, value)
|
||||
if not ok then
|
||||
return false, "redis failed to set data: " .. err
|
||||
end
|
||||
if time then
|
||||
ok,err = self.red:expire(key, time) -- default expire time is seconds
|
||||
if not ok then
|
||||
return false,err
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function _M:get(key)
|
||||
local value = self.red:get(key)
|
||||
if value == ngx.null then
|
||||
return nil
|
||||
else
|
||||
return value
|
||||
end
|
||||
end
|
||||
|
||||
function _M:del(key)
|
||||
return self.red:del(key)
|
||||
end
|
||||
|
||||
function _M:expire(key, time)
|
||||
local ok,err = self.red:expire(key, time) -- default time is seconds
|
||||
if not ok then
|
||||
return false,err
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function _M:incr(key)
|
||||
local ok,err = self.red:incr(key)
|
||||
if not ok then
|
||||
return false, err
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function _M:ttl(key)
|
||||
return self.red:ttl(key)
|
||||
end
|
||||
|
||||
return _M
|
||||
|
|
@ -1,410 +0,0 @@
|
|||
-- Copyright (C)
|
||||
|
||||
local sub = string.sub
|
||||
local byte = string.byte
|
||||
local tcp = ngx.socket.tcp
|
||||
local null = ngx.null
|
||||
local type = type
|
||||
local pairs = pairs
|
||||
local unpack = unpack
|
||||
local setmetatable = setmetatable
|
||||
local tonumber = tonumber
|
||||
local tostring = tostring
|
||||
local rawget = rawget
|
||||
--local error = error
|
||||
|
||||
local ok, new_tab = pcall(require, "table.new")
|
||||
if not ok or type(new_tab) ~= "function" then
|
||||
new_tab = function (narr, nrec) return {} end
|
||||
end
|
||||
|
||||
local _M = new_tab(0, 54)
|
||||
|
||||
_M._VERSION = '0.26'
|
||||
|
||||
local common_cmds = {
|
||||
"get", "set", "mget", "mset",
|
||||
"del", "incr", "decr", -- Strings
|
||||
"llen", "lindex", "lpop", "lpush",
|
||||
"lrange", "linsert", -- Lists
|
||||
"hexists", "hget", "hset", "hmget",
|
||||
--[[ "hmset", ]] "hdel", -- Hashes
|
||||
"smembers", "sismember", "sadd", "srem",
|
||||
"sdiff", "sinter", "sunion", -- Sets
|
||||
"zrange", "zrangebyscore", "zrank", "zadd",
|
||||
"zrem", "zincrby", -- Sorted Sets
|
||||
"auth", "eval", "expire", "script",
|
||||
"sort" -- Others
|
||||
}
|
||||
|
||||
local sub_commands = {
|
||||
"subscribe", "psubscribe"
|
||||
}
|
||||
|
||||
local unsub_commands = {
|
||||
"unsubscribe", "punsubscribe"
|
||||
}
|
||||
|
||||
local mt = { __index = _M }
|
||||
|
||||
function _M.new(self)
|
||||
local sock, err = tcp()
|
||||
if not sock then
|
||||
return nil, err
|
||||
end
|
||||
return setmetatable({ _sock = sock, _subscribed = false }, mt)
|
||||
end
|
||||
|
||||
function _M.set_timeout(self, timeout)
|
||||
local sock = rawget(self, "_sock")
|
||||
if not sock then
|
||||
return nil, "not initialized"
|
||||
end
|
||||
|
||||
return sock:settimeout(timeout)
|
||||
end
|
||||
|
||||
function _M.connect(self, ...)
|
||||
local sock = rawget(self, "_sock")
|
||||
if not sock then
|
||||
return nil, "not initialized"
|
||||
end
|
||||
|
||||
self._subscribed = false
|
||||
|
||||
return sock:connect(...)
|
||||
end
|
||||
|
||||
function _M.set_keepalive(self, ...)
|
||||
local sock = rawget(self, "_sock")
|
||||
if not sock then
|
||||
return nil, "not initialized"
|
||||
end
|
||||
|
||||
if rawget(self, "_subscribed") then
|
||||
return nil, "subscribed state"
|
||||
end
|
||||
|
||||
return sock:setkeepalive(...)
|
||||
end
|
||||
|
||||
function _M.get_reused_times(self)
|
||||
local sock = rawget(self, "_sock")
|
||||
if not sock then
|
||||
return nil, "not initialized"
|
||||
end
|
||||
|
||||
return sock:getreusedtimes()
|
||||
end
|
||||
|
||||
local function close(self)
|
||||
local sock = rawget(self, "_sock")
|
||||
if not sock then
|
||||
return nil, "not initialized"
|
||||
end
|
||||
|
||||
return sock:close()
|
||||
end
|
||||
_M.close = close
|
||||
|
||||
local function _read_reply(self, sock)
|
||||
local line, err = sock:receive()
|
||||
if not line then
|
||||
if err == "timeout" and not rawget(self, "_subscribed") then
|
||||
sock:close()
|
||||
end
|
||||
return nil, err
|
||||
end
|
||||
|
||||
local prefix = byte(line)
|
||||
|
||||
if prefix == 36 then -- char '$'
|
||||
-- print("bulk reply")
|
||||
|
||||
local size = tonumber(sub(line, 2))
|
||||
if size < 0 then
|
||||
return null
|
||||
end
|
||||
|
||||
local data, err = sock:receive(size)
|
||||
if not data then
|
||||
if err == "timeout" then
|
||||
sock:close()
|
||||
end
|
||||
return nil, err
|
||||
end
|
||||
|
||||
local dummy, err = sock:receive(2) -- ignore CRLF
|
||||
if not dummy then
|
||||
return nil, err
|
||||
end
|
||||
|
||||
return data
|
||||
|
||||
elseif prefix == 43 then -- char '+'
|
||||
-- print("status reply")
|
||||
|
||||
return sub(line, 2)
|
||||
|
||||
elseif prefix == 42 then -- char '*'
|
||||
local n = tonumber(sub(line, 2))
|
||||
|
||||
-- print("multi-bulk reply: ", n)
|
||||
if n < 0 then
|
||||
return null
|
||||
end
|
||||
|
||||
local vals = new_tab(n, 0)
|
||||
local nvals = 0
|
||||
for i = 1, n do
|
||||
local res, err = _read_reply(self, sock)
|
||||
if res then
|
||||
nvals = nvals + 1
|
||||
vals[nvals] = res
|
||||
|
||||
elseif res == nil then
|
||||
return nil, err
|
||||
|
||||
else
|
||||
-- be a valid redis error value
|
||||
nvals = nvals + 1
|
||||
vals[nvals] = {false, err}
|
||||
end
|
||||
end
|
||||
|
||||
return vals
|
||||
|
||||
elseif prefix == 58 then -- char ':'
|
||||
-- print("integer reply")
|
||||
return tonumber(sub(line, 2))
|
||||
|
||||
elseif prefix == 45 then -- char '-'
|
||||
-- print("error reply: ", n)
|
||||
|
||||
return false, sub(line, 2)
|
||||
|
||||
else
|
||||
-- when `line` is an empty string, `prefix` will be equal to nil.
|
||||
return nil, "unknown prefix: \"" .. tostring(prefix) .. "\""
|
||||
end
|
||||
end
|
||||
|
||||
local function _gen_req(args)
|
||||
local nargs = #args
|
||||
|
||||
local req = new_tab(nargs * 5 + 1, 0)
|
||||
req[1] = "*" .. nargs .. "\r\n"
|
||||
local nbits = 2
|
||||
|
||||
for i = 1, nargs do
|
||||
local arg = args[i]
|
||||
if type(arg) ~= "string" then
|
||||
arg = tostring(arg)
|
||||
end
|
||||
|
||||
req[nbits] = "$"
|
||||
req[nbits + 1] = #arg
|
||||
req[nbits + 2] = "\r\n"
|
||||
req[nbits + 3] = arg
|
||||
req[nbits + 4] = "\r\n"
|
||||
|
||||
nbits = nbits + 5
|
||||
end
|
||||
|
||||
-- it is much faster to do string concatenation on the C land
|
||||
-- in real world (large number of strings in the Lua VM)
|
||||
return req
|
||||
end
|
||||
|
||||
local function _do_cmd(self, ...)
|
||||
local args = {...}
|
||||
|
||||
local sock = rawget(self, "_sock")
|
||||
if not sock then
|
||||
return nil, "not initialized"
|
||||
end
|
||||
|
||||
local req = _gen_req(args)
|
||||
|
||||
local reqs = rawget(self, "_reqs")
|
||||
if reqs then
|
||||
reqs[#reqs + 1] = req
|
||||
return
|
||||
end
|
||||
|
||||
-- print("request: ", table.concat(req))
|
||||
|
||||
local bytes, err = sock:send(req)
|
||||
if not bytes then
|
||||
return nil, err
|
||||
end
|
||||
|
||||
return _read_reply(self, sock)
|
||||
end
|
||||
|
||||
local function _check_subscribed(self, res)
|
||||
if type(res) == "table"
|
||||
and (res[1] == "unsubscribe" or res[1] == "punsubscribe")
|
||||
and res[3] == 0
|
||||
then
|
||||
self._subscribed = false
|
||||
end
|
||||
end
|
||||
|
||||
function _M.read_reply(self)
|
||||
local sock = rawget(self, "_sock")
|
||||
if not sock then
|
||||
return nil, "not initialized"
|
||||
end
|
||||
|
||||
if not rawget(self, "_subscribed") then
|
||||
return nil, "not subscribed"
|
||||
end
|
||||
|
||||
local res, err = _read_reply(self, sock)
|
||||
_check_subscribed(self, res)
|
||||
|
||||
return res, err
|
||||
end
|
||||
|
||||
for i = 1, #common_cmds do
|
||||
local cmd = common_cmds[i]
|
||||
|
||||
_M[cmd] =
|
||||
function (self, ...)
|
||||
return _do_cmd(self, cmd, ...)
|
||||
end
|
||||
end
|
||||
|
||||
for i = 1, #sub_commands do
|
||||
local cmd = sub_commands[i]
|
||||
|
||||
_M[cmd] =
|
||||
function (self, ...)
|
||||
self._subscribed = true
|
||||
return _do_cmd(self, cmd, ...)
|
||||
end
|
||||
end
|
||||
|
||||
for i = 1, #unsub_commands do
|
||||
local cmd = unsub_commands[i]
|
||||
|
||||
_M[cmd] =
|
||||
function (self, ...)
|
||||
local res, err = _do_cmd(self, cmd, ...)
|
||||
_check_subscribed(self, res)
|
||||
return res, err
|
||||
end
|
||||
end
|
||||
|
||||
function _M.hmset(self, hashname, ...)
|
||||
if select('#', ...) == 1 then
|
||||
local t = select(1, ...)
|
||||
|
||||
local n = 0
|
||||
for k, v in pairs(t) do
|
||||
n = n + 2
|
||||
end
|
||||
|
||||
local array = new_tab(n, 0)
|
||||
|
||||
local i = 0
|
||||
for k, v in pairs(t) do
|
||||
array[i + 1] = k
|
||||
array[i + 2] = v
|
||||
i = i + 2
|
||||
end
|
||||
-- print("key", hashname)
|
||||
return _do_cmd(self, "hmset", hashname, unpack(array))
|
||||
end
|
||||
|
||||
-- backwards compatibility
|
||||
return _do_cmd(self, "hmset", hashname, ...)
|
||||
end
|
||||
|
||||
function _M.init_pipeline(self, n)
|
||||
self._reqs = new_tab(n or 4, 0)
|
||||
end
|
||||
|
||||
function _M.cancel_pipeline(self)
|
||||
self._reqs = nil
|
||||
end
|
||||
|
||||
function _M.commit_pipeline(self)
|
||||
local reqs = rawget(self, "_reqs")
|
||||
if not reqs then
|
||||
return nil, "no pipeline"
|
||||
end
|
||||
|
||||
self._reqs = nil
|
||||
|
||||
local sock = rawget(self, "_sock")
|
||||
if not sock then
|
||||
return nil, "not initialized"
|
||||
end
|
||||
|
||||
local bytes, err = sock:send(reqs)
|
||||
if not bytes then
|
||||
return nil, err
|
||||
end
|
||||
|
||||
local nvals = 0
|
||||
local nreqs = #reqs
|
||||
local vals = new_tab(nreqs, 0)
|
||||
for i = 1, nreqs do
|
||||
local res, err = _read_reply(self, sock)
|
||||
if res then
|
||||
nvals = nvals + 1
|
||||
vals[nvals] = res
|
||||
|
||||
elseif res == nil then
|
||||
if err == "timeout" then
|
||||
close(self)
|
||||
end
|
||||
return nil, err
|
||||
|
||||
else
|
||||
-- be a valid redis error value
|
||||
nvals = nvals + 1
|
||||
vals[nvals] = {false, err}
|
||||
end
|
||||
end
|
||||
|
||||
return vals
|
||||
end
|
||||
|
||||
function _M.array_to_hash(self, t)
|
||||
local n = #t
|
||||
-- print("n = ", n)
|
||||
local h = new_tab(0, n / 2)
|
||||
for i = 1, n, 2 do
|
||||
h[t[i]] = t[i + 1]
|
||||
end
|
||||
return h
|
||||
end
|
||||
|
||||
-- this method is deperate since we already do lazy method generation.
|
||||
function _M.add_commands(...)
|
||||
local cmds = {...}
|
||||
for i = 1, #cmds do
|
||||
local cmd = cmds[i]
|
||||
_M[cmd] =
|
||||
function (self, ...)
|
||||
return _do_cmd(self, cmd, ...)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
setmetatable(_M, {__index = function(self, cmd)
|
||||
local method =
|
||||
function (self, ...)
|
||||
return _do_cmd(self, cmd, ...)
|
||||
end
|
||||
|
||||
-- cache the lazily generated method in our
|
||||
-- module table
|
||||
_M[cmd] = method
|
||||
return method
|
||||
end})
|
||||
|
||||
return _M
|
||||
|
|
@ -1,165 +1,303 @@
|
|||
---
|
||||
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
||||
--- Created by admin.
|
||||
--- DateTime: 2025/10/15 09:12
|
||||
---
|
||||
--local snowflake = require("util.snowflake")
|
||||
local helpers = require("util.helpers")
|
||||
--
|
||||
--local workerId = 0 -- 假设当前机器的ID是1,范围在[0, 31]之间
|
||||
--local datacenterId = 0 -- 数据中心ID,范围在[0, 31]之间
|
||||
--local snow = snowflake.new(workerId, datacenterId)
|
||||
--local id = snow:generateUniqueId()-- 生成ID
|
||||
--ngx.say("Generated ID:"..snow.int64_to_string(id))
|
||||
|
||||
--max =a and b or c--a?b:c
|
||||
|
||||
--[[
|
||||
local User = require("model.user")
|
||||
|
||||
--获取数据表中的记录数
|
||||
local code, res = User:count()
|
||||
--ngx.say(res)
|
||||
|
||||
--查询表中id为1的数据记录
|
||||
code, res = User:find("1")
|
||||
|
||||
--查询表中的所有记录
|
||||
code, res = User:all()
|
||||
--显示查询到的数据记录
|
||||
--for _, row in ipairs(res) do
|
||||
-- for key, value in pairs(row) do
|
||||
-- ngx.say(key .. ":" .. tostring(value))
|
||||
-- end
|
||||
--end
|
||||
|
||||
--ngx.say("----begin where and query---")
|
||||
-- 返回 users 表中 username 字段的值是 `cgreen` 的,`password` 字段的值是 `xxxxxx` 的多条数据,注意此处返回是 table 数组,`first()` 方法返回的是单条数据
|
||||
code, res = User:where('name','=','zhangsan'):where('password','=','111111'):get()
|
||||
--for _, row in ipairs(res) do
|
||||
-- for key, value in pairs(row) do
|
||||
-- ngx.say(key .. ":" .. tostring(value))
|
||||
-- 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)
|
||||
local count = data.total
|
||||
ngx.say("data total:", count)
|
||||
for _, row in ipairs(data.data) do
|
||||
ngx.say("begin show data:")
|
||||
for key, value in pairs(row) do
|
||||
ngx.say(key .. ":" .. tostring(value))
|
||||
end
|
||||
end
|
||||
--]]
|
||||
|
||||
--获取请求参数的键值和数据值
|
||||
local cjson = require("cjson")
|
||||
|
||||
--读取请求体的数据
|
||||
ngx.req.read_body()
|
||||
--获取请求数据
|
||||
local body_data = ngx.req.get_body_data()
|
||||
--ngx.say(body_data)
|
||||
|
||||
local data = cjson.decode(body_data)
|
||||
--键值为id产生uuid数据值,增加到json中
|
||||
data.id = helpers.getUuid()
|
||||
local ret = helpers.convert_json(data)
|
||||
ngx.say(ret)
|
||||
|
||||
--local header = ngx.req.get_headers()
|
||||
--for k,v in pairs(header) do
|
||||
-- ngx.say("[header] name:", k, "value:", v)
|
||||
--end
|
||||
|
||||
--local payloads = ngx.req.get_uri_args()
|
||||
--for k,v in pairs(payloads) do
|
||||
-- ngx.say("[params] name:", k, " value:", v)
|
||||
--end
|
||||
|
||||
--去掉组装最后一位逗号(,)
|
||||
--local newKeys = keys:sub(1, #keys -1)
|
||||
--local newValues = values:sub(1, #values -1)
|
||||
|
||||
--[[
|
||||
--读取请求体的数据
|
||||
--ngx.req.read_body()
|
||||
|
||||
--获取请求数据
|
||||
local body_data = ngx.req.get_body_data()
|
||||
|
||||
if not body_data then
|
||||
ngx.say("read file error:", err)
|
||||
return ngx.exit(400)
|
||||
end
|
||||
local len = #body_data
|
||||
|
||||
local file_name = ngx.req.get_body_file()
|
||||
ngx.say("file length:", len)
|
||||
|
||||
ngx.req.read_body_in_buffer(ngx.var.request_body_file)
|
||||
|
||||
ngx.say(body_data)
|
||||
--]]
|
||||
|
||||
--[[
|
||||
local cjson = require("cjson")
|
||||
local file_path = "/home/frankly/work/test.dat"
|
||||
local file_length = 1024 * 1024 * 400
|
||||
local f, err = io.input(file_path, "r")
|
||||
if not f then
|
||||
ngx.say("read file error:"..err)
|
||||
return
|
||||
end
|
||||
local content = f:read(file_length) --读取文件内容
|
||||
f:close() --关闭文件
|
||||
--ngx.say(content)
|
||||
local res = {
|
||||
key = "data",
|
||||
value = content
|
||||
}
|
||||
--ngx.header["Length"] = #content
|
||||
ngx.header["Content-Type"] = 'application/json; charset=UTF-8'
|
||||
ngx.say(cjson.encode(res))
|
||||
ngx.log(ngx.INFO, "send data success")
|
||||
---
|
||||
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
||||
--- Created by admin.
|
||||
--- DateTime: 2025/10/15 09:12
|
||||
---
|
||||
--local snowflake = require("util.snowflake")
|
||||
local helpers = require("share.helpers")
|
||||
--
|
||||
--local workerId = 0 -- 假设当前机器的ID是1,范围在[0, 31]之间
|
||||
--local datacenterId = 0 -- 数据中心ID,范围在[0, 31]之间
|
||||
--local snow = snowflake.new(workerId, datacenterId)
|
||||
--local id = snow:generateUniqueId()-- 生成ID
|
||||
--ngx.say("Generated ID:"..snow.int64_to_string(id))
|
||||
|
||||
--max =a and b or c--a?b:c
|
||||
|
||||
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 args = ngx.req.get_uri_args()
|
||||
local pageNum = args["pagenum"] or 1
|
||||
local pageSize = args["pagesize"] or 10
|
||||
ngx.say("pageNum:", pageNum, " pageSize:", pageSize)
|
||||
--]]
|
||||
|
||||
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
|
||||
|
||||
--[[
|
||||
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
|
||||
|
||||
--分页 获取数据表中的记录
|
||||
local data = nil
|
||||
code, data = userModel:paginate(1, 10)
|
||||
local count = data.total
|
||||
ngx.say("data total:", count)
|
||||
for _, row in ipairs(data.data) do
|
||||
ngx.say("begin show data:")
|
||||
for key, value in pairs(row) 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)
|
||||
--]]
|
||||
|
||||
--[[
|
||||
--读取请求体的数据
|
||||
ngx.req.read_body()
|
||||
--获取请求数据
|
||||
local body_data = ngx.req.get_body_data()
|
||||
ngx.say(body_data)
|
||||
|
||||
local data = cjson.decode(body_data)
|
||||
--键值为id产生uuid数据值,增加到json中
|
||||
data.id = helpers.getUuid()
|
||||
local ret = helpers.convert_json(data)
|
||||
ngx.say(ret)
|
||||
--]]
|
||||
|
||||
--local header = ngx.req.get_headers()
|
||||
--for k,v in pairs(header) do
|
||||
-- ngx.say("[header] name:", k, "value:", v)
|
||||
--end
|
||||
|
||||
--local payloads = ngx.req.get_uri_args()
|
||||
--for k,v in pairs(payloads) do
|
||||
-- ngx.say("[params] name:", k, " value:", v)
|
||||
--end
|
||||
|
||||
--去掉组装最后一位逗号(,)
|
||||
--local newKeys = keys:sub(1, #keys -1)
|
||||
--local newValues = values:sub(1, #values -1)
|
||||
|
||||
--[[
|
||||
--读取请求体的数据
|
||||
--ngx.req.read_body()
|
||||
|
||||
--获取请求数据
|
||||
local body_data = ngx.req.get_body_data()
|
||||
|
||||
if not body_data then
|
||||
ngx.say("read file error:", err)
|
||||
return ngx.exit(400)
|
||||
end
|
||||
local len = #body_data
|
||||
|
||||
local file_name = ngx.req.get_body_file()
|
||||
ngx.say("file length:", len)
|
||||
|
||||
ngx.req.read_body_in_buffer(ngx.var.request_body_file)
|
||||
|
||||
ngx.say(body_data)
|
||||
--]]
|
||||
|
||||
--[[
|
||||
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")
|
||||
if not f then
|
||||
ngx.say("read file error:"..err)
|
||||
return
|
||||
end
|
||||
local content = f:read(file_length) --读取文件内容
|
||||
f:close() --关闭文件
|
||||
--ngx.say(content)
|
||||
local res = {
|
||||
key = "data",
|
||||
value = content
|
||||
}
|
||||
--ngx.header["Length"] = #content
|
||||
ngx.header["Content-Type"] = 'application/json; charset=UTF-8'
|
||||
ngx.say(cjson.encode(res))
|
||||
ngx.log(ngx.INFO, "send data success")
|
||||
--]]
|
||||
|
|
@ -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
|
||||
|
|
@ -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 = {}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
--ngx.HTTP_METHOD_NOT_IMPLEMENTED (501)
|
||||
--ngx.HTTP_SERVICE_UNAVAILABLE (503)
|
||||
--ngx.HTTP_GATEWAY_TIMEOUT (504)
|
||||
|
||||
return {
|
||||
-- 系统状态码
|
||||
[0x000000] = 'ok',
|
||||
|
|
@ -39,4 +38,4 @@ return {
|
|||
[0x01000A] = '获取用户信息失败,用户未登录',
|
||||
[0x01000B] = '获取用户信息失败,用户不存在',
|
||||
[0x01000C] = '修改用户信息失败,用户不存在',
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
Loading…
Reference in New Issue
Block a user