151 lines
5.0 KiB
Lua
151 lines
5.0 KiB
Lua
---
|
|
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
|
--- Created by .
|
|
--- DateTime: 2025/9/27 16:02
|
|
--- 业务逻辑 对应用数据表进行数据表业务处理
|
|
local status = require("util.status")
|
|
local resp = require("util.response")
|
|
local applicationDao = require("dao.system.application")
|
|
local validator = require("validator.system.application")
|
|
local cjson = require("cjson.safe")
|
|
local perm = require("util.permissionfilter")
|
|
|
|
local _M = {}
|
|
|
|
--获取所有应用程序信息
|
|
function _M.getSystemApplications()
|
|
local role = ngx.ctx.role
|
|
--权限数据
|
|
local perms = ngx.ctx.perms
|
|
--判断当前接口用户和角色是否有权限
|
|
if perm:hasPermission(role, perms) == false then
|
|
ngx.exit(ngx.HTTP_FORBIDDEN)
|
|
end
|
|
--获取页码和请求的数据量
|
|
local args = ngx.req.get_uri_args()
|
|
local pageNum = args["pagenum"] or 1
|
|
local pageSize = args["pagesize"] or 10
|
|
local code, ret = applicationDao.getSystemApplications(pageNum, pageSize)
|
|
local state = status.SUCCESS
|
|
if code ~= 0 then state = status.DATA_IS_WRONG end
|
|
resp: response(state, ret)
|
|
end
|
|
|
|
--根据应用id获取应用信息
|
|
function _M.getSystemApplication(m)
|
|
local role = ngx.ctx.role
|
|
--权限数据
|
|
local perms = ngx.ctx.perms
|
|
--判断当前接口用户和角色是否有权限
|
|
if perm:hasPermission(role, perms) == false then
|
|
ngx.exit(ngx.HTTP_FORBIDDEN)
|
|
end
|
|
print("Application id:", m.id)
|
|
local code,ret = applicationDao.getSystemApplication(m.id)
|
|
local state = status.SUCCESS
|
|
if code ~= 0 then state = status.DATA_IS_WRONG end
|
|
|
|
print("Application ret data:", cjson.encode(ret))
|
|
resp: response(state, ret[1])
|
|
end
|
|
|
|
--根据组织id获取应用信息
|
|
function _M.getOrganizationApplication(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 = applicationDao.getOrganizationApplication(m.id)
|
|
local state = status.SUCCESS
|
|
if code ~= 0 then state = status.DATA_IS_WRONG end
|
|
resp: response(state, ret[1])
|
|
end
|
|
|
|
--根据用户id获取应用的信息
|
|
function _M.getUserApplication(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 = applicationDao.getUserApplication(m.id)
|
|
local state = status.SUCCESS
|
|
if code ~= 0 then state = status.DATA_IS_WRONG end
|
|
resp: response(state, ret[1])
|
|
end
|
|
|
|
--根据应用id获取应用信息
|
|
function _M.addSystemApplication()
|
|
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 = validator.validateJson(body_data)
|
|
--验证失败则返回
|
|
if not ok then
|
|
resp:response(status.PARAM_TYPE_BIND_ERROR)
|
|
return
|
|
end
|
|
-- 添加应用程序
|
|
local code, ret = applicationDao.addApplication(cjson.decode(body_data))
|
|
local state = status.SUCCESS
|
|
if code ~= 0 then state = status.DATA_IS_WRONG end
|
|
resp: response(state, ret)
|
|
end
|
|
|
|
--根据应用id删除应用信息
|
|
function _M.deleteSystemApplication(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 = applicationDao.deleteApplication(m.id)
|
|
local state = status.SUCCESS
|
|
if code ~= 0 then state = status.DATA_IS_WRONG end
|
|
resp: response(state, ret)
|
|
end
|
|
|
|
--根据应用id删除应用信息
|
|
function _M.updateSystemApplication(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 = validator.validateJson(body_data)
|
|
--验证失败则返回
|
|
if not ok then
|
|
resp:response(status.PARAM_TYPE_BIND_ERROR)
|
|
return
|
|
end
|
|
local code, ret = applicationDao.updateSystemApplication(m.id, cjson.decode(body_data))
|
|
local state = status.SUCCESS
|
|
if code ~= 0 then state = status.DATA_IS_WRONG end
|
|
resp: response(state, ret)
|
|
end
|
|
|
|
return _M
|