87 lines
2.5 KiB
Lua
87 lines
2.5 KiB
Lua
---
|
|
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
|
--- Created by .
|
|
--- DateTime: 2025/9/27 15:19
|
|
--- 业务逻辑 对用户角色数据表进行数据表业务处理
|
|
local jsonschema = require("jsonschema")
|
|
local resp = require("util.response")
|
|
local roleDao = require("dao.role")
|
|
|
|
local _M = {}
|
|
|
|
-- 定义一个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.getSystemRole(m)
|
|
local code,ret = roleDao.getSystemRole(m.id)
|
|
local result = resp:json(code, ret)
|
|
resp:send(result)
|
|
end
|
|
|
|
--根据角色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
|
|
--ngx.say(body_data)
|
|
local code, ret = roleDao.addSystemRole(body_data)
|
|
local result = resp:json(code, ret)
|
|
resp:send(result)
|
|
end
|
|
|
|
--根据角色id删除角色信息
|
|
function _M.deleteSystemRole(m)
|
|
local code, ret = roleDao.deleteSystemRole(m.id)
|
|
local result = resp:json(code, ret)
|
|
resp:send(result)
|
|
end
|
|
|
|
--根据角色id删除角色信息
|
|
function _M.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 code, ret = roleDao.updateSystemRole(m.id, body_data)
|
|
local result = resp:json(code, ret)
|
|
resp:send(result)
|
|
end
|
|
|
|
return _M
|