2025-10-22 08:46:41 +08:00
|
|
|
---
|
|
|
|
|
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
|
|
|
|
--- Created by .
|
|
|
|
|
--- DateTime: 2025/9/25 08:19
|
|
|
|
|
--- 业务逻辑 对用户数据表进行数据表业务处理
|
2025-10-29 17:29:17 +08:00
|
|
|
local resp = require("util.response")
|
|
|
|
|
local userDao = require("dao.user")
|
2025-10-30 09:03:44 +08:00
|
|
|
local validatorJson = require("validator.system.user")
|
2025-10-30 11:30:42 +08:00
|
|
|
local cjson = require("cjson.safe")
|
2025-10-22 08:46:41 +08:00
|
|
|
|
|
|
|
|
local _M = {}
|
|
|
|
|
|
2025-10-29 17:29:17 +08:00
|
|
|
--获取所有用户信息
|
|
|
|
|
function _M.getSystemUsers()
|
|
|
|
|
--获取页码和请求的数据量
|
|
|
|
|
--local args = ngx.req.get_uri_args()
|
|
|
|
|
local pageNum = ngx.var.pagenum or 1
|
|
|
|
|
local pageSize = ngx.var.pagesize or 10
|
2025-10-29 23:00:17 +08:00
|
|
|
local code,ret = userDao.getSystemUsers(pageNum, pageSize)
|
2025-10-29 17:29:17 +08:00
|
|
|
local result = resp:json(code, ret)
|
|
|
|
|
resp:send(result)
|
2025-10-22 14:35:41 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--根据用户id获取用户信息
|
2025-10-29 17:29:17 +08:00
|
|
|
function _M.getSystemUser(m)
|
2025-10-29 23:00:17 +08:00
|
|
|
local code,ret = userDao.getSystemUser(m.id)
|
2025-10-29 17:29:17 +08:00
|
|
|
local result = resp:json(code, ret)
|
|
|
|
|
resp:send(result)
|
2025-10-22 14:35:41 +08:00
|
|
|
end
|
|
|
|
|
|
2025-10-29 17:29:17 +08:00
|
|
|
--根据用户id获取用户信息
|
|
|
|
|
function _M.addSystemUser()
|
|
|
|
|
--读取请求体的数据
|
|
|
|
|
ngx.req.read_body()
|
|
|
|
|
--获取请求数据
|
|
|
|
|
local body_data = ngx.req.get_body_data()
|
2025-10-30 09:03:44 +08:00
|
|
|
-- 验证数据是否符合json
|
|
|
|
|
local ok = validatorJson.validatorJson(body_data)
|
2025-10-29 17:29:17 +08:00
|
|
|
--验证失败则返回
|
|
|
|
|
if not ok then
|
|
|
|
|
local result = resp:json(0x000001)
|
|
|
|
|
resp:send(result)
|
|
|
|
|
return
|
2025-10-22 08:46:41 +08:00
|
|
|
end
|
2025-10-29 17:29:17 +08:00
|
|
|
--ngx.say(body_data)
|
2025-10-31 21:32:39 +08:00
|
|
|
local jsonData = cjson.decode(body_data)
|
|
|
|
|
--ngx.say(jsonData)
|
|
|
|
|
local code, ret = userDao.addSystemUser(jsonData)
|
2025-10-29 17:29:17 +08:00
|
|
|
local result = resp:json(code, ret)
|
|
|
|
|
resp:send(result)
|
2025-10-22 08:46:41 +08:00
|
|
|
end
|
|
|
|
|
|
2025-10-29 17:29:17 +08:00
|
|
|
--根据用户id删除用户信息
|
|
|
|
|
function _M.deleteSystemUser(m)
|
2025-10-29 23:00:17 +08:00
|
|
|
local code, ret = userDao.deleteSystemUser(m.id)
|
2025-10-29 17:29:17 +08:00
|
|
|
local result = resp:json(code, ret)
|
|
|
|
|
resp:send(result)
|
2025-10-22 08:46:41 +08:00
|
|
|
end
|
|
|
|
|
|
2025-10-29 17:29:17 +08:00
|
|
|
--根据用户id删除用户信息
|
|
|
|
|
function _M.updateSystemUser(m)
|
|
|
|
|
--读取请求体的数据
|
|
|
|
|
ngx.req.read_body()
|
|
|
|
|
--获取请求数据
|
|
|
|
|
local body_data = ngx.req.get_body_data()
|
2025-10-30 09:03:44 +08:00
|
|
|
-- 验证数据是否符合json
|
|
|
|
|
local ok = validatorJson.validatorJson(body_data)
|
2025-10-29 17:29:17 +08:00
|
|
|
--验证失败则返回
|
|
|
|
|
if not ok then
|
|
|
|
|
local result = resp:json(0x000001)
|
|
|
|
|
resp:send(result)
|
|
|
|
|
return
|
2025-10-23 17:46:02 +08:00
|
|
|
end
|
2025-10-29 17:29:17 +08:00
|
|
|
--将数据更新到数据表中
|
2025-10-30 11:30:42 +08:00
|
|
|
local code, ret = userDao.updateSystemUser(m.id, cjson.decode(body_data))
|
2025-10-29 17:29:17 +08:00
|
|
|
local result = resp:json(code, ret)
|
|
|
|
|
resp:send(result)
|
2025-10-23 17:46:02 +08:00
|
|
|
end
|
|
|
|
|
|
2025-10-22 08:46:41 +08:00
|
|
|
return _M
|