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 resp = require("util.response")
|
2025-11-10 19:34:43 +08:00
|
|
|
local departmentDao = require("dao.system.department")
|
2025-11-15 16:07:07 +08:00
|
|
|
local validator = require("validator.system.department")
|
2025-10-30 11:30:42 +08:00
|
|
|
local cjson = require("cjson.safe")
|
2025-11-08 16:10:04 +08:00
|
|
|
local perm = require("util.permissionfilter")
|
2025-10-28 10:33:35 +08:00
|
|
|
|
|
|
|
|
local _M = {}
|
|
|
|
|
|
2025-10-29 17:29:17 +08:00
|
|
|
--获取所有组织架构信息
|
2025-10-29 23:00:17 +08:00
|
|
|
function _M.getSystemDepartments()
|
2025-11-08 16:10:04 +08:00
|
|
|
local role = ngx.ctx.role
|
|
|
|
|
--权限数据
|
|
|
|
|
local perms = ngx.ctx.perms
|
|
|
|
|
--判断当前接口用户和角色是否有权限
|
|
|
|
|
if perm:hasPermission(role, perms) == false then
|
|
|
|
|
ngx.exit(ngx.HTTP_FORBIDDEN)
|
|
|
|
|
end
|
2025-11-17 15:32:40 +08:00
|
|
|
local code, ret = departmentDao.getSystemDepartments()
|
|
|
|
|
resp:response(code, ret)
|
2025-10-29 17:29:17 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--根据组织id获取组织架构信息
|
2025-10-29 23:00:17 +08:00
|
|
|
function _M.getSystemDepartment(m)
|
2025-11-08 16:10:04 +08:00
|
|
|
local role = ngx.ctx.role
|
|
|
|
|
--权限数据
|
|
|
|
|
local perms = ngx.ctx.perms
|
|
|
|
|
--判断当前接口用户和角色是否有权限
|
|
|
|
|
if perm:hasPermission(role, perms) == false then
|
|
|
|
|
ngx.exit(ngx.HTTP_FORBIDDEN)
|
|
|
|
|
end
|
2025-11-17 15:32:40 +08:00
|
|
|
local code, ret = departmentDao.getSystemDepartment(m.id)
|
|
|
|
|
resp:response(code, ret)
|
2025-10-29 17:29:17 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--根据组织id添加组织架构信息
|
2025-10-29 23:00:17 +08:00
|
|
|
function _M.addSystemDepartment()
|
2025-11-08 16:10:04 +08:00
|
|
|
local role = ngx.ctx.role
|
|
|
|
|
--权限数据
|
|
|
|
|
local perms = ngx.ctx.perms
|
|
|
|
|
--判断当前接口用户和角色是否有权限
|
|
|
|
|
if perm:hasPermission(role, perms) == false then
|
|
|
|
|
ngx.exit(ngx.HTTP_FORBIDDEN)
|
|
|
|
|
end
|
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
|
2025-11-15 16:07:07 +08:00
|
|
|
local ok = validator.validateJson(body_data)
|
2025-10-29 23:00:17 +08:00
|
|
|
--验证失败则返回
|
|
|
|
|
if not ok then
|
2025-11-17 15:32:40 +08:00
|
|
|
resp:response(0x000001)
|
2025-10-29 17:29:17 +08:00
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
--ngx.say(body_data)
|
2025-10-30 11:30:42 +08:00
|
|
|
local code, ret = departmentDao.addSystemDepartment(cjson.decode(body_data))
|
2025-11-17 15:32:40 +08:00
|
|
|
resp:response(code, ret)
|
2025-10-29 17:29:17 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--根据组织id删除组织架构信息
|
2025-10-29 23:00:17 +08:00
|
|
|
function _M.deleteSystemDepartment(m)
|
2025-11-08 16:10:04 +08:00
|
|
|
local role = ngx.ctx.role
|
|
|
|
|
--权限数据
|
|
|
|
|
local perms = ngx.ctx.perms
|
|
|
|
|
--判断当前接口用户和角色是否有权限
|
|
|
|
|
if perm:hasPermission(role, perms) == false then
|
|
|
|
|
ngx.exit(ngx.HTTP_FORBIDDEN)
|
|
|
|
|
end
|
|
|
|
|
--删除部门数据
|
2025-10-29 23:00:17 +08:00
|
|
|
local code, ret = departmentDao.deleteSystemDepartment(m.id)
|
2025-11-17 15:32:40 +08:00
|
|
|
resp:response(code, ret)
|
2025-10-29 17:29:17 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--根据组织id删除组织架构信息
|
2025-10-29 23:00:17 +08:00
|
|
|
function _M.updateSystemDepartment(m)
|
2025-11-08 16:10:04 +08:00
|
|
|
local role = ngx.ctx.role
|
|
|
|
|
--权限数据
|
|
|
|
|
local perms = ngx.ctx.perms
|
|
|
|
|
--判断当前接口用户和角色是否有权限
|
|
|
|
|
if perm:hasPermission(role, perms) == false then
|
|
|
|
|
ngx.exit(ngx.HTTP_FORBIDDEN)
|
|
|
|
|
end
|
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
|
2025-11-15 16:07:07 +08:00
|
|
|
local ok = validator.validateJson(body_data)
|
2025-10-29 23:00:17 +08:00
|
|
|
--验证失败则返回
|
|
|
|
|
if not ok then
|
2025-11-17 15:32:40 +08:00
|
|
|
resp:response(0x000001)
|
2025-10-29 17:29:17 +08:00
|
|
|
return
|
|
|
|
|
end
|
2025-10-30 11:30:42 +08:00
|
|
|
local code, ret = departmentDao.updateSystemDepartment(m.id, cjson.decode(body_data))
|
2025-11-17 15:32:40 +08:00
|
|
|
resp:response(code, ret)
|
2025-10-29 17:29:17 +08:00
|
|
|
end
|
|
|
|
|
|
2025-10-28 10:33:35 +08:00
|
|
|
return _M
|