diff --git a/conf/nginx.conf b/conf/nginx.conf index 288b411..1b9a0a6 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -63,11 +63,6 @@ http { location /cjson { content_by_lua_file '${APP_PATH}/src/test/test.lua'; } - #jwt验证进行测试 - location /api/test { - access_by_lua_file '${APP_PATH}/src/auth/jwt-auth.lua'; - proxy_pass http://192.168.147.1:3000; - } location = /testSM { content_by_lua_block { cjson = require "cjson.safe" diff --git a/src/api/system/department.lua b/src/api/system/department.lua index 9f5946d..4eba869 100644 --- a/src/api/system/department.lua +++ b/src/api/system/department.lua @@ -7,35 +7,35 @@ --解析url路由过滤库 local radix = require("resty.radixtree") --数据表业务处理 -local systemOrganization = require("service.system.department") +local systemDepartment = require("service.system.department") --定义相关路由,前端接口url地址 local routes = { --用户相关路由接口 { - paths = { "/api/system/organizations" }, + paths = { "/api/system/departments" }, methods = { "GET" }, - handler = systemOrganization.getSystemOrganization, + handler = systemDepartment.getSystemDepartments, }, { - paths = { "/api/system/organizations/:id" }, + paths = { "/api/system/departments/:id" }, methods = { "GET" }, - handler = systemOrganization.getSystemOrganization, + handler = systemDepartment.getSystemDepartment, }, { - paths = { "/api/system/organizations" }, + paths = { "/api/system/departments" }, methods = { "POST" }, - handler = systemOrganization.addSystemOrganization, + handler = systemDepartment.addSystemDepartment, }, { - paths = { "/api/system/organizations/:id" }, + paths = { "/api/system/departments/:id" }, methods = { "DELETE" }, - handler = systemOrganization.deleteSystemOrganization, + handler = systemDepartment.deleteSystemDepartment, }, { - paths = { "/api/system/organizations/:id" }, + paths = { "/api/system/departments/:id" }, methods = { "PUT" }, - handler = systemOrganization.updateSystemOrganization, + handler = systemDepartment.updateSystemDepartment, }, } diff --git a/src/api/system/menu.lua b/src/api/system/menu.lua new file mode 100644 index 0000000..8774a3c --- /dev/null +++ b/src/api/system/menu.lua @@ -0,0 +1,61 @@ +--- +--- Generated by EmmyLua(https://github.com/EmmyLua) +--- Created by admin. +--- DateTime: 2025/11/04 10:45 +--- + +--解析url路由过滤库 +local radix = require("resty.radixtree") +--数据表业务处理 +local systemMenu = require("service.system.menu") + +--定义相关路由,前端接口url地址 +local routes = { + --用户相关路由接口 + { + paths = { "/api/system/menus" }, + methods = { "GET" }, + handler = systemMenu.getSystemMenus, + }, + { + paths = { "/api/system/menus/:id" }, + methods = { "GET" }, + handler = systemMenu.getSystemMenu, + }, + { + paths = { "/api/system/menus" }, + methods = { "POST" }, + handler = systemMenu.addSystemMenu, + }, + { + paths = { "/api/system/menus/:id" }, + methods = { "DELETE" }, + handler = systemMenu.deleteSystemMenu, + }, + { + paths = { "/api/system/menus/:id" }, + methods = { "PUT" }, + handler = systemMenu.updateSystemMenu, + }, +} + +-- 初始化路由 +local rx, err = radix.new(routes) +if not rx then + ngx.say("Not Found") + ngx.exit(ngx.HTTP_NOT_FOUND) +end + +--获取访问的uri地址 +local uri = ngx.var.uri +local opts = { + method = ngx.var.request_method, + matched = {} +} + +-- 进行路由匹配和相关函数调用 +local ok = rx:dispatch(uri, opts, opts.matched) +if not ok then + ngx.say("Not Found") + ngx.exit(ngx.HTTP_NOT_FOUND) +end diff --git a/src/api/system/postion.lua b/src/api/system/postion.lua new file mode 100644 index 0000000..700e244 --- /dev/null +++ b/src/api/system/postion.lua @@ -0,0 +1,61 @@ +--- +--- Generated by EmmyLua(https://github.com/EmmyLua) +--- Created by admin. +--- DateTime: 2025/11/04 10:50 +--- + +--解析url路由过滤库 +local radix = require("resty.radixtree") +--数据表业务处理 +local systemPosition = require("service.system.position") + +--定义相关路由,前端接口url地址 +local routes = { + --用户相关路由接口 + { + paths = { "/api/system/positions" }, + methods = { "GET" }, + handler = systemPosition.getSystemPositions, + }, + { + paths = { "/api/system/positions/:id" }, + methods = { "GET" }, + handler = systemPosition.getSystemPosition, + }, + { + paths = { "/api/system/positions" }, + methods = { "POST" }, + handler = systemPosition.addSystemPosition, + }, + { + paths = { "/api/system/positions/:id" }, + methods = { "DELETE" }, + handler = systemPosition.deleteSystemPosition, + }, + { + paths = { "/api/system/positions/:id" }, + methods = { "PUT" }, + handler = systemPosition.updateSystemPosition, + }, +} + +-- 初始化路由 +local rx, err = radix.new(routes) +if not rx then + ngx.say("Not Found") + ngx.exit(ngx.HTTP_NOT_FOUND) +end + +--获取访问的uri地址 +local uri = ngx.var.uri +local opts = { + method = ngx.var.request_method, + matched = {} +} + +-- 进行路由匹配和相关函数调用 +local ok = rx:dispatch(uri, opts, opts.matched) +if not ok then + ngx.say("Not Found") + ngx.exit(ngx.HTTP_NOT_FOUND) +end diff --git a/src/dao/menu.lua b/src/dao/menu.lua new file mode 100644 index 0000000..703fa2f --- /dev/null +++ b/src/dao/menu.lua @@ -0,0 +1,91 @@ +--- +--- Generated by EmmyLua(https://github.com/EmmyLua) +--- Created by admin. +--- DateTime: 2025/11/04 15:06 +--- 数据表模型文件 + +local helpers = require("share.helpers") +--引用使用的库文件 +local model = require("share.model") +--创建一个数据表相关的模型 +local menuModel = model:new('sys_menu') + +local _M = {} + +--判断菜单是否存在 +local function isExistMenu(id) + --根据菜单id进行验证菜单是否存在 + local code, res = menuModel:find(id) + if code ~= 0 then + return false + end + local num = 0 + if res ~= nil then + num = table.getn(res) + end + --组织不存在返回错误 + if num <= 0 then + return false + end + return true +end + +-- 查询数据表中的所有菜单信息 +function _M.getSystemMenus(pageNum, pageSize) + return menuModel:paginate(pageNum, pageSize) +end + +--根据菜单id获取菜单信息 +function _M.getSystemMenu(id) + return menuModel.find(id) +end + +--增加菜单息到数据表 +function _M.addSystemMenu(jsonData) + --解析json中的键和数据值 + local menuid = jsonData['menu_id'] + + --根据菜单名称进行验证菜单是否存在 + local code, res = menuModel:where("menu_id", "=", menuid):get() + if code ~= 0 then + return 0x000001,res + end + local num = 0 + if res ~= nil then + num = table.getn(res) + end + --菜单存在时返回菜单已经存在 + if num > 0 then + return 0x01000C, nil + end + --键值为id产生uuid数据值,增加到json中 + jsonData.id = helpers.getUuid() + -- 创建一个菜单 + return menuModel:create(jsonData) +end + +--删除菜单信息到数据表 +function _M.deleteSystemDepartment(id) + --根据菜单id进行验证菜单是否存在 + local ok = isExistMenu(id) + --菜单不存在则返回 + if ok == false then + return 0x000001,nil + end + return menuModel:delete(id) +end + +--更新菜单信息到数据表 +function _M.updateSystemMenu(id, jsonData) + --根据菜单id进行验证菜单是否存在 + local ok = isExistMenu(id) + --组织不存在则返回 + if ok == false then + return 0x000001,nil + end + jsonData.update_time = ngx.time() + --对数据内容进行更新 + return menuModel:where('menu_id', '=', id):update(jsonData) +end + +return _M diff --git a/src/dao/position.lua b/src/dao/position.lua new file mode 100644 index 0000000..b20004c --- /dev/null +++ b/src/dao/position.lua @@ -0,0 +1,91 @@ +--- +--- Generated by EmmyLua(https://github.com/EmmyLua) +--- Created by admin. +--- DateTime: 2025/11/04 15:14 +--- 数据表模型文件 + +local helpers = require("share.helpers") +--引用使用的库文件 +local model = require("share.model") +--创建一个数据表相关的模型 +local positionModel = model:new('sys_post') + +local _M = {} + +--判断岗位是否存在 +local function isExistPosition(id) + --根据岗位id进行验证岗位是否存在 + local code, res = positionModel:find(id) + if code ~= 0 then + return false + end + local num = 0 + if res ~= nil then + num = table.getn(res) + end + --岗位不存在返回错误 + if num <= 0 then + return false + end + return true +end + +-- 查询数据表中的所有岗位信息 +function _M.getSystemPositions(pageNum, pageSize) + return positionModel:paginate(pageNum, pageSize) +end + +--根据岗位id获取岗位信息 +function _M.getSystemPosition(id) + return positionModel.find(id) +end + +--增加岗位信息到数据表 +function _M.addSystemPosition(jsonData) + --解析json中的键和数据值 + local post_id = jsonData['post_id'] + + --根据岗位id进行验证岗位是否存在 + local code, res = positionModel:where("post_id", "=", post_id):get() + if code ~= 0 then + return 0x000001,res + end + local num = 0 + if res ~= nil then + num = table.getn(res) + end + --岗位存在时返回岗位已经存在 + if num > 0 then + return 0x01000C, nil + end + --键值为id产生uuid数据值,增加到json中 + jsonData.id = helpers.getUuid() + -- 创建一个岗位 + return positionModel:create(jsonData) +end + +--删除岗位信息到数据表 +function _M.deleteSystemPosition(id) + --根据岗位id进行验证岗位是否存在 + local ok = isExistPosition(id) + --岗位不存在则返回 + if ok == false then + return 0x000001,nil + end + return positionModel:delete(id) +end + +--更新岗位信息到数据表 +function _M.updateSystemPosition(id, jsonData) + --根据岗位id进行验证岗位是否存在 + local ok = isExistPosition(id) + --岗位不存在则返回 + if ok == false then + return 0x000001,nil + end + jsonData.update_time = ngx.time() + --对数据内容进行更新 + return positionModel:where('post_id', '=', id):update(jsonData) +end + +return _M diff --git a/src/service/system/menu.lua b/src/service/system/menu.lua new file mode 100644 index 0000000..15da907 --- /dev/null +++ b/src/service/system/menu.lua @@ -0,0 +1,76 @@ +--- +--- Generated by EmmyLua(https://github.com/EmmyLua) +--- Created by . +--- DateTime: 2025/11/04 14:35 +--- 业务逻辑 对菜单数据表进行数据表业务处理 +local resp = require("util.response") +local menuDao = require("dao.menu") +local validatorJson = require("validator.system.menu") +local cjson = require("cjson.safe") + +local _M = {} + +--获取所有菜单信息 +function _M.getSystemMenus() + --获取页码和请求的数据量 + local pageNum = ngx.var.pagenum or 1 + local pageSize = ngx.var.pagesize or 10 + local code,ret = menuDao.getSystemMenus(pageNum, pageSize) + local result = resp:json(code, ret) + resp:send(result) +end + +--根据菜单id获取菜单信息 +function _M.getSystemMenu(m) + local code,ret = menuDao.getSystemMenu(m.id) + local result = resp:json(code, ret) + resp:send(result) +end + +--根据菜单id添加菜单信息 +function _M.addSystemMenu() + --读取请求体的数据 + ngx.req.read_body() + --获取请求数据 + local body_data = ngx.req.get_body_data() + -- 验证数据是否符合schema + local ok = validatorJson.validatorJson(body_data) + --验证失败则返回 + if not ok then + local result = resp:json(0x000001) + resp:send(result) + return + end + --ngx.say(body_data) + local code, ret = menuDao.addSystemMenu(cjson.decode(body_data)) + local result = resp:json(code, ret) + resp:send(result) +end + +--根据菜单id删除菜单信息 +function _M.deleteSystemMenu(m) + local code, ret = menuDao.deleteSystemMenu(m.id) + local result = resp:json(code, ret) + resp:send(result) +end + +--根据菜单id删除菜单信息 +function _M.updateSystemMenu(m) + --读取请求体的数据 + ngx.req.read_body() + --获取请求数据 + local body_data = ngx.req.get_body_data() + -- 验证数据是否符合schema + local ok = validatorJson.validatorJson(body_data) + --验证失败则返回 + if not ok then + local result = resp:json(0x000001) + resp:send(result) + return + end + local code, ret = menuDao.updateSystemMenu(m.id, cjson.decode(body_data)) + local result = resp:json(code, ret) + resp:send(result) +end + +return _M diff --git a/src/service/system/position.lua b/src/service/system/position.lua new file mode 100644 index 0000000..14966cc --- /dev/null +++ b/src/service/system/position.lua @@ -0,0 +1,76 @@ +--- +--- Generated by EmmyLua(https://github.com/EmmyLua) +--- Created by . +--- DateTime: 2025/11/04 15:01 +--- 业务逻辑 对岗位数据表进行数据表业务处理 +local resp = require("util.response") +local positionDao = require("dao.position") +local validatorJson = require("validator.system.position") +local cjson = require("cjson.safe") + +local _M = {} + +--获取所有岗位信息 +function _M.getSystemPositions() + --获取页码和请求的数据量 + local pageNum = ngx.var.pagenum or 1 + local pageSize = ngx.var.pagesize or 10 + local code,ret = positionDao.getSystemPositions(pageNum, pageSize) + local result = resp:json(code, ret) + resp:send(result) +end + +--根据岗位id获取岗位信息 +function _M.getSystemPosition(m) + local code,ret = positionDao.getSystemPosition(m.id) + local result = resp:json(code, ret) + resp:send(result) +end + +--根据岗位id添加岗位信息 +function _M.addSystemPosition() + --读取请求体的数据 + ngx.req.read_body() + --获取请求数据 + local body_data = ngx.req.get_body_data() + -- 验证数据是否符合schema + local ok = validatorJson.validatorJson(body_data) + --验证失败则返回 + if not ok then + local result = resp:json(0x000001) + resp:send(result) + return + end + --ngx.say(body_data) + local code, ret = positionDao.addSystemPosition(cjson.decode(body_data)) + local result = resp:json(code, ret) + resp:send(result) +end + +--根据岗位id删除岗位信息 +function _M.deleteSystemPosition(m) + local code, ret = positionDao.deleteSystemPosition(m.id) + local result = resp:json(code, ret) + resp:send(result) +end + +--根据岗位id删除岗位信息 +function _M.updateSystemPosition(m) + --读取请求体的数据 + ngx.req.read_body() + --获取请求数据 + local body_data = ngx.req.get_body_data() + -- 验证数据是否符合schema + local ok = validatorJson.validatorJson(body_data) + --验证失败则返回 + if not ok then + local result = resp:json(0x000001) + resp:send(result) + return + end + local code, ret = positionDao.updateSystemPosition(m.id, cjson.decode(body_data)) + local result = resp:json(code, ret) + resp:send(result) +end + +return _M diff --git a/src/validator/system/menu.lua b/src/validator/system/menu.lua new file mode 100644 index 0000000..5e6c55c --- /dev/null +++ b/src/validator/system/menu.lua @@ -0,0 +1,37 @@ +--- +--- Generated by EmmyLua(https://github.com/EmmyLua) +--- Created by . +--- DateTime: 2025/11/04 11:12 +--- 业务逻辑 对菜单数据进行参数数据的验证 +local jsonschema = require("jsonschema") + +local _M = {} + +-- 定义一个JSON Schema +local schema = { + {type = "object", properties = { + {name = "menu_id", type = "string"}, + {name = "menu_name", type = "string"}, + {name = "parent_id", type = "string"}, + {name = "order_num", type = "number"}, + {name = "url", type = "string"}, + {name = "target", type = "string"}, + {name = "menu_type", type = "string"}, + {name = "status", type = "string"}, + {name = "is_refresh", type = "string"}, + {name = "perms", type = "string"}, + {name = "perms", type = "string"}, + {name = "create_by", type = "string"}, + {name = "update_by", type = "string"}, + {name = "remark", type = "string"}, + }, required = {"menu_id", "menu_name"}} +} + +function _M.validatorJson(jsonData) + -- 验证数据是否符合schema + local validator = jsonschema.generate_validator(schema) + local result = validator(jsonData) + return result +end + +return _M diff --git a/src/validator/system/position.lua b/src/validator/system/position.lua new file mode 100644 index 0000000..7d50931 --- /dev/null +++ b/src/validator/system/position.lua @@ -0,0 +1,30 @@ +--- +--- Generated by EmmyLua(https://github.com/EmmyLua) +--- Created by . +--- DateTime: 2025/11/04 11:20 +--- 业务逻辑 对岗位数据进行参数数据的验证 +local jsonschema = require("jsonschema") + +local _M = {} + +-- 定义一个JSON Schema +local schema = { + {type = "object", properties = { + {name = "post_id", type = "string"}, + {name = "post_code", type = "string"}, + {name = "post_name", type = "string"}, + {name = "post_sort", type = "number"}, + {name = "status", type = "string"}, + {name = "create_by", type = "string"}, + {name = "update_by", type = "string"}, + }, required = {"post_id"}} +} + +function _M.validatorJson(jsonData) + -- 验证数据是否符合schema + local validator = jsonschema.generate_validator(schema) + local result = validator(jsonData) + return result +end + +return _M