--- --- Generated by EmmyLua(https://github.com/EmmyLua) --- Created by . --- DateTime: 2025/9/25 08:19 --- 业务逻辑 对用户数据表进行数据表业务处理 local jsonschema = require("jsonschema") local resp = require("util.response") local userDao = require("dao.user") local _M = {} -- 定义一个JSON Schema local schema = { {type = "object", properties = { {name = "username", type = "string"}, {name = "phone", type = "string"}, {name = "email", type = "string"}, {name = "idcard", type = "string"}, {name = "name", type = "string"}, {name = "office_phone", type = "string"}, {name = "telephone", type = "string"}, {name = "display_name", type = "string"}, }, required = {"username", "phone", "email", "idcard"}} } --获取所有用户信息 function _M.getSystemUsers() --获取页码和请求的数据量 --local args = ngx.req.get_uri_args() local pageNum = ngx.var.pagenum or 1 local pageSize = ngx.var.pagesize or 10 local code,ret = userDao.getAllUser(pageNum, pageSize) local result = resp:json(code, ret) resp:send(result) end --根据用户id获取用户信息 function _M.getSystemUser(m) local code,ret = userDao.getUser(m.id) local result = resp:json(code, ret) resp:send(result) end --根据用户id获取用户信息 function _M.addSystemUser() --读取请求体的数据 ngx.req.read_body() --获取请求数据 local body_data = ngx.req.get_body_data() -- 验证数据是否符合schema local ok, err = jsonschema:generate_validator(body_data, schema) --验证失败则返回 if not ok then local result = resp:json(0x000001) resp:send(result) return end --ngx.say(body_data) local code, ret = userDao.addUser(body_data) local result = resp:json(code, ret) resp:send(result) end --根据用户id删除用户信息 function _M.deleteSystemUser(m) local code, ret = userDao.deleteUser(m.id) local result = resp:json(code, ret) resp:send(result) end --根据用户id删除用户信息 function _M.updateSystemUser(m) --读取请求体的数据 ngx.req.read_body() --获取请求数据 local body_data = ngx.req.get_body_data() -- 验证数据是否符合schema local ok, err = jsonschema:generate_validator(body_data, schema) --验证失败则返回 if not ok then local result = resp:json(0x000001) resp:send(result) return end --将数据更新到数据表中 local code, ret = userDao.updateUser(m.id, body_data) local result = resp:json(code, ret) resp:send(result) end return _M