2025-10-28 10:33:35 +08:00
|
|
|
---
|
|
|
|
|
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
|
|
|
|
--- Created by .
|
|
|
|
|
--- DateTime: 2025/9/28 10:22
|
|
|
|
|
--- 业务逻辑 对组织架构数据表进行数据表业务处理
|
2025-10-29 23:00:17 +08:00
|
|
|
local jsonschema = require("jsonschema")
|
|
|
|
|
local resp = require("util.response")
|
|
|
|
|
local departmentDao = require("dao.department")
|
2025-10-28 10:33:35 +08:00
|
|
|
|
|
|
|
|
local _M = {}
|
|
|
|
|
|
2025-10-29 23:00:17 +08:00
|
|
|
-- 定义一个JSON Schema
|
|
|
|
|
local schema = {
|
|
|
|
|
{type = "object", properties = {
|
|
|
|
|
{name = "name", type = "string"},
|
|
|
|
|
{name = "seq", type = "string"},
|
|
|
|
|
{name = "description", type = "string"},
|
|
|
|
|
{name = "create_by", type = "string"},
|
|
|
|
|
{name = "update_by", type = "string"},
|
|
|
|
|
{name = "parent_id", type = "string"},
|
|
|
|
|
{name = "leader", type = "string"},
|
|
|
|
|
{name = "status", type = "string"},
|
|
|
|
|
}, required = {"name"}}
|
|
|
|
|
}
|
2025-10-29 17:29:17 +08:00
|
|
|
|
|
|
|
|
--获取所有组织架构信息
|
2025-10-29 23:00:17 +08:00
|
|
|
function _M.getSystemDepartments()
|
|
|
|
|
--获取页码和请求的数据量
|
|
|
|
|
local pageNum = ngx.var.pagenum or 1
|
|
|
|
|
local pageSize = ngx.var.pagesize or 10
|
|
|
|
|
local code,ret = departmentDao.getSystemDepartments(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.getSystemDepartment(m)
|
|
|
|
|
local code,ret = departmentDao.getSystemDepartment(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.addSystemDepartment()
|
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 = departmentDao.addSystemDepartment(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.deleteSystemDepartment(m)
|
|
|
|
|
local code, ret = departmentDao.deleteSystemDepartment(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.updateSystemDepartment(m)
|
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
|
2025-10-29 23:00:17 +08:00
|
|
|
local code, ret = departmentDao.updateSystemDepartment(m.id, body_data)
|
2025-10-29 17:29:17 +08:00
|
|
|
local result = resp:json(code, ret)
|
|
|
|
|
resp:send(result)
|
|
|
|
|
end
|
|
|
|
|
|
2025-10-28 10:33:35 +08:00
|
|
|
return _M
|