AuthPlatform/src/service/system/position.lua

113 lines
3.5 KiB
Lua

---
--- Generated by EmmyLua(https://github.com/EmmyLua)
--- Created by .
--- DateTime: 2025/11/04 15:01
--- 业务逻辑 对岗位数据表进行数据表业务处理
local resp = require("util.response")
local positionDao = require("dao.position")
local validatorJson = require("validator.system.position")
local cjson = require("cjson.safe")
local perm = require("util.permissionfilter")
local _M = {}
--获取所有岗位信息
function _M.getSystemPositions()
local role = ngx.ctx.role
--权限数据
local perms = ngx.ctx.perms
--判断当前接口用户和角色是否有权限
if perm:hasPermission(role, perms) == false then
ngx.exit(ngx.HTTP_FORBIDDEN)
end
--获取页码和请求的数据量
local pageNum = ngx.var.pagenum or 1
local pageSize = ngx.var.pagesize or 10
local code,ret = positionDao.getSystemPositions(pageNum, pageSize)
local result = resp:json(code, ret)
resp:send(result)
end
--根据岗位id获取岗位信息
function _M.getSystemPosition(m)
local role = ngx.ctx.role
--权限数据
local perms = ngx.ctx.perms
--判断当前接口用户和角色是否有权限
if perm:hasPermission(role, perms) == false then
ngx.exit(ngx.HTTP_FORBIDDEN)
end
local code,ret = positionDao.getSystemPosition(m.id)
local result = resp:json(code, ret)
resp:send(result)
end
--根据岗位id添加岗位信息
function _M.addSystemPosition()
local role = ngx.ctx.role
--权限数据
local perms = ngx.ctx.perms
--判断当前接口用户和角色是否有权限
if perm:hasPermission(role, perms) == false then
ngx.exit(ngx.HTTP_FORBIDDEN)
end
--读取请求体的数据
ngx.req.read_body()
--获取请求数据
local body_data = ngx.req.get_body_data()
-- 验证数据是否符合schema
local ok = validatorJson.validatorJson(body_data)
--验证失败则返回
if not ok then
local result = resp:json(0x000001)
resp:send(result)
return
end
--ngx.say(body_data)
local code, ret = positionDao.addSystemPosition(cjson.decode(body_data))
local result = resp:json(code, ret)
resp:send(result)
end
--根据岗位id删除岗位信息
function _M.deleteSystemPosition(m)
local role = ngx.ctx.role
--权限数据
local perms = ngx.ctx.perms
--判断当前接口用户和角色是否有权限
if perm:hasPermission(role, perms) == false then
ngx.exit(ngx.HTTP_FORBIDDEN)
end
local code, ret = positionDao.deleteSystemPosition(m.id)
local result = resp:json(code, ret)
resp:send(result)
end
--根据岗位id删除岗位信息
function _M.updateSystemPosition(m)
local role = ngx.ctx.role
--权限数据
local perms = ngx.ctx.perms
--判断当前接口用户和角色是否有权限
if perm:hasPermission(role, perms) == false then
ngx.exit(ngx.HTTP_FORBIDDEN)
end
--读取请求体的数据
ngx.req.read_body()
--获取请求数据
local body_data = ngx.req.get_body_data()
-- 验证数据是否符合schema
local ok = validatorJson.validatorJson(body_data)
--验证失败则返回
if not ok then
local result = resp:json(0x000001)
resp:send(result)
return
end
local code, ret = positionDao.updateSystemPosition(m.id, cjson.decode(body_data))
local result = resp:json(code, ret)
resp:send(result)
end
return _M