--- --- Generated by EmmyLua(https://github.com/EmmyLua) --- Created by . --- DateTime: 2025/9/25 08:25 --- 业务逻辑 对账户数据表进行数据表业务处理 local resp = require("util.response") local accountDao = require("dao.account") local validatorJson = require("validator.system.account") local cjson = require("cjson.safe") local perm = require("util.permissionfilter") local _M = {} --获取所有账户信息 function _M.getSystemAccounts() 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 = accountDao.getSystemAccounts(pageNum, pageSize) local result = resp:json(code, ret) resp:send(result) end --根据账户id获取账户信息 function _M.getSystemAccount(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 id = m.id local code,ret = accountDao.getSystemAccount(id) local result = resp:json(code, ret) resp:send(result) end --根据账户id获取账户信息 function _M.addSystemAccount() 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 = accountDao.addSystemAccount(cjson.decode(body_data)) local result = resp:json(code, ret) resp:send(result) end --根据账户id删除账户信息 function _M.deleteSystemAccount(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 = accountDao.deleteSystemAccount(m.id) local result = resp:json(code, ret) resp:send(result) end --根据账户id删除账户信息 function _M.updateSystemAccount(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 = accountDao.updateSystemAccount(m.id, cjson.decode(body_data)) local result = resp:json(code, ret) resp:send(result) end return _M