2025-10-23 11:14:19 +08:00
|
|
|
---
|
|
|
|
|
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
|
|
|
|
--- Created by .
|
2025-10-28 10:33:35 +08:00
|
|
|
--- DateTime: 2025/9/25 08:25
|
|
|
|
|
--- 业务逻辑 对账户数据表进行数据表业务处理
|
2025-10-29 23:00:17 +08:00
|
|
|
local jsonschema = require("jsonschema")
|
|
|
|
|
local resp = require("util.response")
|
|
|
|
|
local accountDao = require("dao.account")
|
2025-10-23 11:14:19 +08:00
|
|
|
|
|
|
|
|
local _M = {}
|
|
|
|
|
|
2025-10-29 23:00:17 +08:00
|
|
|
-- 定义一个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"}}
|
|
|
|
|
}
|
2025-10-29 17:29:17 +08:00
|
|
|
|
|
|
|
|
--获取所有账户信息
|
2025-10-29 23:00:17 +08:00
|
|
|
function _M.getSystemAccounts()
|
|
|
|
|
local pageNum = ngx.var.pagenum or 1
|
|
|
|
|
local pageSize = ngx.var.pagesize or 10
|
|
|
|
|
local code,ret = accountDao.getSystemAccounts(pageNum, pageSize)
|
2025-10-29 17:29:17 +08:00
|
|
|
local result = resp:json(code, ret)
|
|
|
|
|
resp:send(result)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--根据账户id获取账户信息
|
2025-10-29 23:00:17 +08:00
|
|
|
function _M.getSystemAccount(m)
|
2025-10-29 17:29:17 +08:00
|
|
|
local id = m.id
|
2025-10-29 23:00:17 +08:00
|
|
|
local code,ret = accountDao.getSystemAccount(id)
|
2025-10-29 17:29:17 +08:00
|
|
|
local result = resp:json(code, ret)
|
|
|
|
|
resp:send(result)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--根据账户id获取账户信息
|
2025-10-29 23:00:17 +08:00
|
|
|
function _M.addSystemAccount()
|
2025-10-29 17:29:17 +08:00
|
|
|
--读取请求体的数据
|
|
|
|
|
ngx.req.read_body()
|
|
|
|
|
--获取请求数据
|
|
|
|
|
local body_data = ngx.req.get_body_data()
|
2025-10-29 23:00:17 +08:00
|
|
|
-- 验证数据是否符合schema
|
|
|
|
|
local ok, err = jsonschema:generate_validator(body_data, schema)
|
|
|
|
|
--验证失败则返回
|
|
|
|
|
if not ok then
|
2025-10-29 17:29:17 +08:00
|
|
|
local result = resp:json(0x000001)
|
|
|
|
|
resp:send(result)
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
--ngx.say(body_data)
|
2025-10-29 23:00:17 +08:00
|
|
|
local code, ret = accountDao.addSystemAccount(body_data)
|
2025-10-29 17:29:17 +08:00
|
|
|
local result = resp:json(code, ret)
|
|
|
|
|
resp:send(result)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--根据账户id删除账户信息
|
2025-10-29 23:00:17 +08:00
|
|
|
function _M.deleteSystemAccount(m)
|
|
|
|
|
local code, ret = accountDao.deleteSystemAccount(m.id)
|
2025-10-29 17:29:17 +08:00
|
|
|
local result = resp:json(code, ret)
|
|
|
|
|
resp:send(result)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--根据账户id删除账户信息
|
2025-10-29 23:00:17 +08:00
|
|
|
function _M.updateSystemAccount(m)
|
2025-10-29 17:29:17 +08:00
|
|
|
--读取请求体的数据
|
|
|
|
|
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
|
2025-10-29 23:00:17 +08:00
|
|
|
local code, ret = accountDao.updateSystemAccount(m.id, body_data)
|
2025-10-29 17:29:17 +08:00
|
|
|
local result = resp:json(code, ret)
|
|
|
|
|
resp:send(result)
|
|
|
|
|
end
|
|
|
|
|
|
2025-10-23 11:14:19 +08:00
|
|
|
return _M
|